Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7fdae8877 | ||
|
|
bc77f007a0 | ||
|
|
d2bef9f348 | ||
|
|
06d2a8bc5b | ||
|
|
d9e3d84c0c | ||
|
|
af3a9cdf8f | ||
|
|
92a8b6af0d | ||
|
|
f6c66fcd89 | ||
|
|
262bcc037b | ||
|
|
2cc5126f70 | ||
|
|
5d68e0249a | ||
|
|
bb0b3f3e8f | ||
|
|
204f9103aa | ||
|
|
8e40ba2870 | ||
|
|
d45065101b | ||
|
|
702fbf5132 | ||
|
|
8944f2a78f | ||
|
|
7335f59288 | ||
|
|
16109a39f4 | ||
|
|
b25ba45872 | ||
|
|
b8f5d4d8eb | ||
|
|
fb69d17615 | ||
|
|
98f7f8e6d4 | ||
|
|
0e80c55adf | ||
|
|
dd58e4a7b5 | ||
|
|
e9435a5cfe | ||
|
|
054aec958e | ||
|
|
96c786e8ca | ||
|
|
3792081ddd | ||
|
|
b1e3fea494 | ||
|
|
81c520fe52 | ||
|
|
1277a4398a | ||
|
|
a0a696a2e6 | ||
|
|
5e2f9dd876 | ||
|
|
9739764d2f | ||
|
|
3483cc4174 | ||
|
|
61dbd0abe8 | ||
|
|
95ccb8ec29 | ||
|
|
843291cd66 | ||
|
|
e2b7c9919a | ||
|
|
de85aff6df | ||
|
|
10d97e74d8 | ||
|
|
cce51e6ccd | ||
|
|
3565b5aec2 | ||
|
|
a4550d5654 | ||
|
|
76115bcce8 | ||
|
|
ea219d92c4 | ||
|
|
84df19fb59 | ||
|
|
af1070ec78 | ||
|
|
f2be2a7a9f | ||
|
|
b597ee4d69 | ||
|
|
e60c2798db | ||
|
|
0bd85f24cc | ||
|
|
7700a4a26a | ||
|
|
a40c038785 | ||
|
|
64d40b7ac6 | ||
|
|
c9c07e340c | ||
|
|
3b304b3e3c | ||
|
|
8e19e7322f | ||
|
|
61597deb2b | ||
|
|
35c8e725c4 | ||
|
|
3cb25875b3 | ||
|
|
404aa08cc6 | ||
|
|
4bdf6d0313 | ||
|
|
0c11b45af5 | ||
|
|
3e28796a15 | ||
|
|
39f123c5f3 | ||
|
|
636582bba6 | ||
|
|
5ccc6c879e | ||
|
|
a46d874d33 | ||
|
|
c9b8bdf27c | ||
|
|
be982e4027 | ||
|
|
412b907126 | ||
|
|
0489d94461 | ||
|
|
d6271cde14 | ||
|
|
eda67df9bf | ||
|
|
f55f9403f5 | ||
|
|
23df59188e | ||
|
|
e5d0b5171b | ||
|
|
fca7b856d4 | ||
|
|
df3de3ce91 | ||
|
|
b3cbfe82f8 | ||
|
|
4b70e4029f | ||
|
|
5830dda6ad | ||
|
|
83d42969f0 | ||
|
|
ef7cdf424f | ||
|
|
9d6cda9cf4 | ||
|
|
7a2199c09f | ||
|
|
2f6047d9eb | ||
|
|
77170a987a | ||
|
|
d4fde0dbb5 | ||
|
|
2e4a7aa720 | ||
|
|
ebb8467590 | ||
|
|
67b3a6c557 | ||
|
|
b6865fb703 | ||
|
|
c3bf8357b0 | ||
|
|
b801198d36 | ||
|
|
b3bf16f52e | ||
|
|
6b3ba48d08 | ||
|
|
0e69ead075 | ||
|
|
dd38d7b663 | ||
|
|
72f0bb2aec | ||
|
|
dd498a1cf7 | ||
|
|
49a91991be | ||
|
|
e827f47d04 | ||
|
|
9847373964 | ||
|
|
178cda830a | ||
|
|
38ec7465bf | ||
|
|
1ddf89d2c3 | ||
|
|
4491b71abf | ||
|
|
b1d8f4e080 | ||
|
|
540eed04cc | ||
|
|
96e8cc2d7d | ||
|
|
2082ced720 | ||
|
|
2c94401d45 | ||
|
|
93deea4f5e | ||
|
|
f35ecb1790 | ||
|
|
6435d9e4c3 | ||
|
|
0d42ebb9ae | ||
|
|
a26fb2d64d | ||
|
|
1d0b6d2168 | ||
|
|
202f7b81de | ||
|
|
d16f3434dd | ||
|
|
9c0d3b1221 | ||
|
|
5f8f4d229f | ||
|
|
a3edc81f55 | ||
|
|
774b980f69 | ||
|
|
a993d44f4e | ||
|
|
a8a416fa7a | ||
|
|
9db4c15e7a | ||
|
|
2fb0a6941f | ||
|
|
0b20c5597c | ||
|
|
9f69f73443 | ||
|
|
f8635d4e19 | ||
|
|
8aac499e11 | ||
|
|
6ee5a37d68 | ||
|
|
1342613ab9 | ||
|
|
754c0a39da | ||
|
|
97ed57714a | ||
|
|
036b2926ed | ||
|
|
0439e8b743 | ||
|
|
ad4c177e55 | ||
|
|
22f4d7adb0 | ||
|
|
ad1bb6016e | ||
|
|
8dc01708dc | ||
|
|
f4e4ca5649 | ||
|
|
35ac37fb45 | ||
|
|
2a1fa03132 | ||
|
|
78519b56d8 | ||
|
|
19c95ef6b1 | ||
|
|
bbb763c2cf | ||
|
|
611cd8f1b9 | ||
|
|
73a7126e30 | ||
|
|
34269f9770 | ||
|
|
7a4204d0a9 | ||
|
|
2860faacbb | ||
|
|
f02b3dcec2 | ||
|
|
f6d104fd95 | ||
|
|
94680fd127 | ||
|
|
b37a1ffe78 | ||
|
|
17fbbd284d | ||
|
|
fb3a3f3623 | ||
|
|
7e544b9e10 | ||
|
|
e79095e848 | ||
|
|
0baeda2abd | ||
|
|
1b1bcbb2cd | ||
|
|
e7de1ab415 | ||
|
|
675239f6d1 | ||
|
|
efb885ef91 | ||
|
|
7b2f07bdad | ||
|
|
6db5a143a8 | ||
|
|
c2c208f5ce | ||
|
|
411a7c9572 | ||
|
|
1738027da6 | ||
|
|
99496a530e | ||
|
|
318a7a2980 | ||
|
|
440c4d6590 | ||
|
|
f8ecb2cfba | ||
|
|
999dbf7fd9 | ||
|
|
b955812658 | ||
|
|
bd138b7a7e | ||
|
|
1d308377a5 | ||
|
|
cc9b4d8a09 | ||
|
|
72043e4df4 | ||
|
|
d8153f24d2 | ||
|
|
23f82dc728 | ||
|
|
a4aaa547a7 | ||
|
|
f02f18863a | ||
|
|
1ddfa7f601 | ||
|
|
03c79bf5e8 | ||
|
|
59a90325a3 | ||
|
|
393d83550c | ||
|
|
fb654844bf | ||
|
|
c7dd2c3763 | ||
|
|
d5449e8b71 | ||
|
|
5c378c3d73 | ||
|
|
163e62f5a3 | ||
|
|
9d92059aac | ||
|
|
9ad6f7230f | ||
|
|
2e5ac0d144 | ||
|
|
744d109da3 | ||
|
|
e8d782b4da | ||
|
|
2594623c09 | ||
|
|
502b85d8b1 | ||
|
|
9b9ad5cc37 | ||
|
|
210d6c5290 | ||
|
|
4d1d05aaa0 | ||
|
|
03347ef7e4 | ||
|
|
a21a73b370 | ||
|
|
fb8d13bf5c | ||
|
|
94820d4d7f | ||
|
|
e4bd818e15 | ||
|
|
ac6e59982c | ||
|
|
e08fdb6271 | ||
|
|
56e64decd3 | ||
|
|
d98580065f | ||
|
|
496e4b8562 | ||
|
|
3211beb706 | ||
|
|
f6e4441504 | ||
|
|
f69b7e5a85 | ||
|
|
14fb0f489a | ||
|
|
7b1164febb | ||
|
|
07d1715993 | ||
|
|
7ed3ba6738 | ||
|
|
8dbc0c0603 | ||
|
|
8fe29f21c4 | ||
|
|
64d42d1a56 | ||
|
|
de5c175c5e | ||
|
|
7b34a1c0f6 | ||
|
|
cbafd38780 | ||
|
|
db066f8769 | ||
|
|
540da6deba | ||
|
|
1d44e04d96 | ||
|
|
6d66b260e0 | ||
|
|
3cfe9cb128 | ||
|
|
9425c74b2f | ||
|
|
d42752c0f4 | ||
|
|
6e7c22123d | ||
|
|
640591fda3 | ||
|
|
fe34a881fa | ||
|
|
b4a3e947b1 | ||
|
|
7b8d755cac | ||
|
|
92370c9254 | ||
|
|
7b18451022 | ||
|
|
5d0a838ded | ||
|
|
b4bc52b177 | ||
|
|
41ed7f5e0b | ||
|
|
2db8123dc2 | ||
|
|
13c741e460 | ||
|
|
ddf06fd9dc | ||
|
|
c81f83edf0 | ||
|
|
ce44a40f5f | ||
|
|
0851c22574 | ||
|
|
79201e6166 | ||
|
|
e13ed7490a | ||
|
|
cf9a8fe801 | ||
|
|
297050cddf | ||
|
|
b08cb00072 | ||
|
|
dd0e604d80 | ||
|
|
bff5ccd3e9 | ||
|
|
98bde5f0c5 | ||
|
|
2b1ad60e39 | ||
|
|
e1120ec52b | ||
|
|
c60ecc7366 | ||
|
|
3c58e2b07f | ||
|
|
1851f6cf04 | ||
|
|
b736389d1c | ||
|
|
9321356f59 | ||
|
|
0d14728224 | ||
|
|
67472f3019 | ||
|
|
0a3c3188fc | ||
|
|
596d5fdf82 | ||
|
|
dc7c1cc65a | ||
|
|
158ce77ad8 | ||
|
|
eca46fee54 | ||
|
|
383b28cc77 | ||
|
|
63a48047a3 | ||
|
|
a3417e9315 | ||
|
|
dce8aac1f3 | ||
|
|
a642e7f286 | ||
|
|
f9c700304b | ||
|
|
e6645f6e29 | ||
|
|
42435a0d39 | ||
|
|
77574b00b9 | ||
|
|
0b7c1b30f0 | ||
|
|
92dad3abad | ||
|
|
48052c96fb | ||
|
|
05dd343155 | ||
|
|
c078626a5c | ||
|
|
69da8059fc | ||
|
|
642a42c242 | ||
|
|
318d320ded | ||
|
|
1961488b57 | ||
|
|
82885a7733 | ||
|
|
a4a899f424 | ||
|
|
9891e819b4 | ||
|
|
017a71f43b | ||
|
|
759e097971 | ||
|
|
a742fea2db | ||
|
|
cad17e0aef | ||
|
|
0bf83c96b2 | ||
|
|
6f3eb0a06c | ||
|
|
1f833c5222 | ||
|
|
f136601869 | ||
|
|
3ecd07ef3c | ||
|
|
3eed42d43d | ||
|
|
dbbd558160 | ||
|
|
eec99144f3 | ||
|
|
3a4ebc2eb3 | ||
|
|
84c2c10c0c | ||
|
|
cb6dcd1813 | ||
|
|
3fcc003738 | ||
|
|
856e34a3f0 | ||
|
|
1a0998b1d4 | ||
|
|
cf93080d17 | ||
|
|
1ffe067e12 | ||
|
|
58d8d9c43a | ||
|
|
0e15e29c18 | ||
|
|
d8c8717826 | ||
|
|
9e400e2348 | ||
|
|
2f9a326159 | ||
|
|
56b5f49646 | ||
|
|
49b419251e | ||
|
|
57fc63dc10 | ||
|
|
36276455ea | ||
|
|
1afd5d7521 | ||
|
|
22ecd268cf | ||
|
|
0c39873a1a | ||
|
|
fa7c866457 | ||
|
|
fc199776d9 | ||
|
|
91ab3511ea | ||
|
|
576d24f163 | ||
|
|
9283e76f1a | ||
|
|
13a34073bd | ||
|
|
aff77cef75 | ||
|
|
ac62c3bfbc | ||
|
|
8e0697d4cd | ||
|
|
2fb9511f8b | ||
|
|
fbdaf48377 | ||
|
|
99480bf9c5 | ||
|
|
2ad699b64d | ||
|
|
fabe8d7aa1 | ||
|
|
2eacf5a81d | ||
|
|
fb20c97996 | ||
|
|
67a46dd03d | ||
|
|
fe4a64f98b | ||
|
|
78f8057384 | ||
|
|
ea5aa77b9c | ||
|
|
f2c634ff38 | ||
|
|
9623d932f7 | ||
|
|
b7eb9f8c28 | ||
|
|
5dba56363a | ||
|
|
d83f7f5eef | ||
|
|
9b24749481 | ||
|
|
371f114d69 | ||
|
|
06d8551107 | ||
|
|
0bc49d4eab | ||
|
|
39d7c9e086 | ||
|
|
5aeb354043 | ||
|
|
9fa45ff7b0 | ||
|
|
1ac0877f30 | ||
|
|
398500b952 | ||
|
|
e2253e56c2 | ||
|
|
67c6128d61 | ||
|
|
3bd6b4d9ff | ||
|
|
56a159486b | ||
|
|
4aa0e6affe | ||
|
|
3f2eb03fe3 | ||
|
|
3bbf1ea85d | ||
|
|
e9a6402373 | ||
|
|
ce575d2640 | ||
|
|
0ec11bfca8 | ||
|
|
942d4068ea | ||
|
|
9d0e57c29e | ||
|
|
2e19d89df2 | ||
|
|
4b5f14141b | ||
|
|
49b8cb3abd | ||
|
|
1008370733 | ||
|
|
dd15a7d45f | ||
|
|
a625faab17 | ||
|
|
b433653944 | ||
|
|
499d29a8a0 | ||
|
|
3aa8b77d2c | ||
|
|
6426b9db37 | ||
|
|
6d2ccce1ba | ||
|
|
8d57c26fe5 | ||
|
|
59b79d54a3 | ||
|
|
09d4284d81 | ||
|
|
51bc9c581a | ||
|
|
c1b9328978 | ||
|
|
5da4f255d8 | ||
|
|
2626c663c3 | ||
|
|
10741accdb | ||
|
|
8b834f915e | ||
|
|
6ea4ff6678 | ||
|
|
f2f22249bb | ||
|
|
3389bc4f17 | ||
|
|
7ba5b830f2 | ||
|
|
945fcf0dff | ||
|
|
888c6d3dfc | ||
|
|
43fd803291 | ||
|
|
f443dc64d6 | ||
|
|
927b725373 | ||
|
|
d0c3edf352 | ||
|
|
b3a30c7ad7 | ||
|
|
d0d2d9587c | ||
|
|
ade1bbfda7 | ||
|
|
857acd30d3 | ||
|
|
ada8916fd6 | ||
|
|
8725e65fcd | ||
|
|
b193dc38ff | ||
|
|
88428ca5ff | ||
|
|
99f676f460 | ||
|
|
a0f88bf306 | ||
|
|
5025a70ff9 | ||
|
|
b20dbc9ad7 | ||
|
|
21a32c0fe3 | ||
|
|
2b8bcbb74c | ||
|
|
f0ee2c1c61 | ||
|
|
586b5aaf9b | ||
|
|
135589cd6f | ||
|
|
eadd5f3d65 | ||
|
|
90c29920c0 | ||
|
|
8a5d846617 | ||
|
|
883cb11ba4 | ||
|
|
cddbd1f8eb | ||
|
|
4709ec05f2 | ||
|
|
10da67fa1e | ||
|
|
80a1e3b48c | ||
|
|
ed3234b277 | ||
|
|
0138b4b534 |
No files matched your search
@@ -0,0 +1,29 @@
|
||||
name: Verify (Gitea)
|
||||
# Gitea Actions(自托管 NAS runner)用的门禁:只跑构建/单测/事实守门,
|
||||
# 与 GitHub 版 .github/workflows/verify.yml 等价,但用 runner 自有 node:22 镜像,不装 setup-node。
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths-ignore:
|
||||
- '**/*.md'
|
||||
- 'docs/**'
|
||||
- '.gitea/**'
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: verify-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
gate:
|
||||
name: gate (build · unit · facts)
|
||||
runs-on: linux
|
||||
timeout-minutes: 20
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- run: node -v && npm -v
|
||||
- run: npm ci
|
||||
- run: npm run build
|
||||
- run: npm run verify:ci
|
||||
@@ -14,3 +14,15 @@ coverage/
|
||||
|
||||
# 其他 agent 的本地记忆目录(不入库)
|
||||
.workbuddy/
|
||||
|
||||
# 桌面版本地构建缓存(sandbox 内 npm cache 只能落在仓库里)
|
||||
.npm-cache/
|
||||
.cargo-home/
|
||||
release/
|
||||
|
||||
# 插件市场产物(由 scripts/gen-market.js 生成,发布时 scp 上传)
|
||||
market/
|
||||
|
||||
# 临时截图/调试产物(不入库)
|
||||
_*.png
|
||||
_tray-preview/
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"nodes": [],
|
||||
"edges": [],
|
||||
"groups": []
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"activeCanvas": "Main"
|
||||
}
|
||||
|
After Width: | Height: | Size: 1.0 MiB |
|
After Width: | Height: | Size: 151 KiB |
|
After Width: | Height: | Size: 152 KiB |
|
After Width: | Height: | Size: 8.4 KiB |
|
After Width: | Height: | Size: 2.7 MiB |
|
After Width: | Height: | Size: 1.6 MiB |
|
After Width: | Height: | Size: 4.7 KiB |
|
After Width: | Height: | Size: 242 KiB |
|
After Width: | Height: | Size: 119 KiB |
|
After Width: | Height: | Size: 178 KiB |
|
After Width: | Height: | Size: 702 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 748 KiB |
|
After Width: | Height: | Size: 542 KiB |
|
After Width: | Height: | Size: 566 KiB |
|
After Width: | Height: | Size: 1.6 MiB |
|
After Width: | Height: | Size: 130 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 286 KiB |
|
After Width: | Height: | Size: 116 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 307 KiB |
|
After Width: | Height: | Size: 107 KiB |
|
After Width: | Height: | Size: 155 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 6.3 KiB |
|
After Width: | Height: | Size: 347 KiB |
|
After Width: | Height: | Size: 141 KiB |
|
After Width: | Height: | Size: 2.4 MiB |
|
After Width: | Height: | Size: 174 KiB |
|
After Width: | Height: | Size: 393 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 3.9 MiB |
|
After Width: | Height: | Size: 185 KiB |
|
After Width: | Height: | Size: 247 KiB |
|
After Width: | Height: | Size: 316 KiB |
|
After Width: | Height: | Size: 863 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 32 KiB |
@@ -0,0 +1 @@
|
||||
d5f99457be773e1ababd4048814ac1c224f4f629
|
||||
@@ -447,7 +447,7 @@
|
||||
| 拆 `app.js` 但不处理钉点 | 一次红几百条,无法定位问题 |
|
||||
| 重排 529 个 tag | 代价大、收益小;已用 CHANGELOG 说明缓解 |
|
||||
| 用 `c8` / `nyc` 量本仓覆盖率 | **实测不可用**:src 模块用 `window.eval()` 加载(无脚本名),V8 无从归属。见规则库 §13.42 |
|
||||
| 删除生产 CSP 里的 `127.0.0.1:30092` | **不是残留**,是 2026-10-17 有意为「本地服务插件」做的安全边界调整(`CHANGELOG:226`、事实基线 §265-267) |
|
||||
| 删除生产 CSP 里的 `127.0.0.1:30092` | **不是残留**,是 2026-10-17 有意为「本地服务插件」做的安全边界调整(`CHANGELOG:226`、事实基线 §265-267)。**桌面客户端的 CSP 以 `tauri.conf.json` 为准**(本项目是桌面客户端,`_headers` 属旧网页部署、不约束桌面);v3.25.11 误删导致插件挂,见 `tests/desktop-csp-loopback-test.js` |
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|---|---|
|
||||
| Node | **22**(CI 用 22,本地同版本最省事) |
|
||||
| 安装 | `npm ci` |
|
||||
| 运行时依赖 | **无**(`dependencies` 为空)—— 只有 devDependencies |
|
||||
| 运行时依赖 | 桌面版有 3 个 Tauri 插件(`@tauri-apps/plugin-dialog` / `-fs` / `-http`);Web 版仍无运行时依赖 |
|
||||
| 浏览器测试 | Playwright Chromium:`npx playwright install --with-deps chromium` |
|
||||
|
||||
---
|
||||
@@ -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 100 个单测文件(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` → 正式站
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
# 构建与打包(桌面版)
|
||||
|
||||
## 一、依赖
|
||||
|
||||
| 项 | 版本 | 说明 |
|
||||
|---|---|---|
|
||||
| Node.js | ≥ 20 | 前端构建(esbuild 逐文件压缩 + 拼接) |
|
||||
| Rust | ≥ 1.90 | Tauri 后端;macOS 用默认 toolchain,Windows 必须 **MSVC** |
|
||||
| Xcode CLT | — | 仅 macOS:`xcode-select --install` |
|
||||
| VS Build Tools | 2019/2022 + 「使用 C++ 的桌面开发」 | 仅 Windows |
|
||||
| WebView2 Runtime | — | Windows 10 需安装;Win11 自带 |
|
||||
|
||||
## 二、日常命令
|
||||
|
||||
```bash
|
||||
npm ci # 首次
|
||||
npm run build # 只出前端 dist/(含运行时插件)
|
||||
npm run app:dev # 开发(启动前自动 build,改完源码需手动再 build)
|
||||
npm run app:build # 打包当前平台(mac:.app + .dmg;Win:.exe + .msi)
|
||||
```
|
||||
|
||||
首次 `app:build` 要编译 ~250 个 Rust crate,约 2–5 分钟;之后增量很快。
|
||||
|
||||
> 本机(沙箱)里 cargo/npm 的缓存目录被限制在仓库内,所以 build 时用
|
||||
> `CARGO_HOME=$PWD/.cargo-home npm_config_cache=$PWD/.npm-cache`;
|
||||
> 在你自己的机器上不需要,直接用默认缓存即可。
|
||||
|
||||
## 三、产物位置
|
||||
|
||||
| 平台 | 路径 |
|
||||
|---|---|
|
||||
| macOS | `src-tauri/target/release/bundle/macos/image-workbench.app` |
|
||||
| macOS dmg | `src-tauri/target/release/bundle/dmg/image-workbench_3.24.85_*.dmg` |
|
||||
| Windows msi | `src-tauri/target/release/bundle/msi/*.msi` |
|
||||
| Windows exe(setup) | `src-tauri/target/release/bundle/nsis/*-setup.exe` |
|
||||
|
||||
## 四、Windows 打包(只能在 Windows 上做)
|
||||
|
||||
Tauri 不支持从 macOS 交叉编译 Windows 产物,必须在 Windows 机器上跑:
|
||||
|
||||
```powershell
|
||||
# 1) 一次性环境(有 winget 的话)
|
||||
winget install OpenJS.NodeJS.LTS
|
||||
winget install Rustlang.Rustup
|
||||
winget install Microsoft.VisualStudio.2022.BuildTools --override "--quiet --add Microsoft.VisualStudio.Workload.VCTools"
|
||||
winget install Microsoft.EdgeWebView2Runtime
|
||||
|
||||
# 2) 确认 Rust 走的是 MSVC
|
||||
rustup default stable-msvc
|
||||
rustc -V
|
||||
|
||||
# 3) 构建
|
||||
git clone <本仓库地址> image-workbench-desktop
|
||||
cd image-workbench-desktop
|
||||
npm ci
|
||||
npm run app:build
|
||||
```
|
||||
|
||||
产物在 `src-tauri\target\release\bundle\` 下的 `msi\` 与 `nsis` 目录。
|
||||
|
||||
常见坑:
|
||||
- `link.exe not found` → VS Build Tools 没装「使用 C++ 的桌面开发」工作负载
|
||||
- 中文路径 / 空格路径可能让 NSIS 失败 → 仓库放在 `C:\work\` 这类纯英文路径
|
||||
- 没签名 → SmartScreen 会提示「未知发布者」,点「更多信息 → 仍要运行」
|
||||
|
||||
## 五、签名与分发(本次不做)
|
||||
|
||||
macOS 未签名:首次打开要 **右键 → 打开**(或在「系统设置 → 隐私与安全性」里放行)。
|
||||
Windows 未签名:SmartScreen 提示,仅影响首次运行体验。
|
||||
要正式分发再考虑 Apple Developer ID / Windows 代码签名证书,与本次迁移无关。
|
||||
|
||||
## 六、插件资源的来路
|
||||
|
||||
网页版插件由 Cloudflare KV 在 `/plugins/*` 提供;桌面版没有服务端,所以把
|
||||
**发布产物**(`plugins/runtime/*.js`,文件名带内容哈希)随仓库带走,构建后由
|
||||
`scripts/copy-plugins.js` 拷进 `dist/plugins/`。每个文件的 SHA-256 与
|
||||
`plugins/index.json` 里的 `integrity` 一致(已校验)。
|
||||
|
||||
升级插件时:换掉 `plugins/runtime/` 里的文件 + 同步 `plugins/index.json` 即可,代码不用动。
|
||||
|
||||
## 七、本机实测记录(2026-11-16,macOS arm64)
|
||||
|
||||
构建产物:`image-workbench.app` 16.1 MB,已在 macOS 启动并渲染出完整界面。
|
||||
|
||||
在打包产物里注入一次性探针(用完即删,未进最终包)读到的运行时事实:
|
||||
|
||||
| 检查项 | 实测值 | 含义 |
|
||||
|---|---|---|
|
||||
| 页面 origin | `tauri://localhost` | 与网页版 `https://` 不同,所以 `/api/*` 这类同源后端全部不存在 |
|
||||
| `window.__TAURI__` | 存在,keys 含 app/core/event/window… | withGlobalTauri 生效 |
|
||||
| `dialog` / `fs` / `http` | true / true / true | 三个插件的前端 API 都挂上了 ⇒ 另存为链路可用 |
|
||||
| `__TAURI_INTERNALS__.invoke` | true | IPC 通道正常(CSP 没拦) |
|
||||
| `isSecureContext` | true | crypto.subtle、clipboard 这类安全上下文 API 不会降级 |
|
||||
| `/plugins/index.json` | HTTP 200,1283 B | 插件静态化成功,桌面端有插件清单 |
|
||||
| 插件 SRI 加载实测 | `blank-canvas` 加载 OK、已注册 yes | 用 `integrity` + `crossOrigin` 的真实注入方式验证通过 |
|
||||
|
||||
未能在本机自动验证的一项:**点「保存图片」弹系统另存为**。原因是要点开画布里的输出节点才能触发,
|
||||
属于 GUI 交互,自动化会打断你当前桌面。这段逻辑本身已具备(三个 API 都在),请手工点一次确认。
|
||||
|
||||
|
||||
## 八、桌面壳层新增能力(2026-11-16 后)
|
||||
|
||||
| 能力 | 行为 | 实现 |
|
||||
|---|---|---|
|
||||
| 系统托盘 | 菜单栏/托盘出现图标;点「关闭」不再退出,收进托盘,后台生图继续跑 | `src-tauri/src/lib.rs` 的 `build_tray` + `on_window_event`(`tray-icon` feature) |
|
||||
| 托盘菜单 | 显示主窗口 / 隐藏到托盘 / 退出 | 同上(「退出」才真正结束进程) |
|
||||
| 窗口记忆 | 退出或收进托盘时记住大小与位置,下次启动恢复;换过显示器则只恢复尺寸 | `window-geom.json` 存在 app config 目录 |
|
||||
| 打开数据目录 | 设置 → 通用 → 「打开数据目录」 | 一个极简 Rust 命令 `open_app_data_dir`(不改任何权限) |
|
||||
| 主题跟随系统 | 设置 → 通用 → 主题 → 「跟随系统」,系统切换实时生效 | `matchMedia('(prefers-color-scheme: dark)')` |
|
||||
|
||||
Rust 侧一共只有一个自定义命令(打开数据目录),其余全部是官方插件 + 框架能力,权限没有放宽。
|
||||
|
||||
## 九、回归状态
|
||||
|
||||
- `npm run test:unit`:全绿(含 architecture-boundary-guard 的冻结快照,已按规矩重生成)
|
||||
- 桌面端桥统一走 `src/runtime-desktop-bridge.js`(src 不反向引用 app.js 的全局,边界守卫不报红)
|
||||
|
||||
|
||||
## 十、资料目录(数据落盘)
|
||||
|
||||
```
|
||||
~/Documents/ImageWorkbench/
|
||||
├── data.json 所有 localStorage 键(设置/提示词/画布/分组/图库索引),原子写(.tmp → rename)
|
||||
├── images/ 所有图片字节,内容寻址 images/<sha256前16>.<ext>,同图只存一份
|
||||
├── migrated.flag 旧 IndexedDB 图片迁移完成标记
|
||||
└── _boot.log 启动/迁移日志(排障用)
|
||||
```
|
||||
|
||||
- 启动:`grant_dir` 重新授权目录 → 读 data.json 进内存 → 之后同步读写内存、800ms 防抖异步落盘
|
||||
- 图片:`{__blob}` 引用指向 `images/`,不再有 base64(唯一残留是设置里的形状模板缩略图 ~8KB)
|
||||
- 换机器:设置 → 通用 → 资料目录 → 切换… → 指到旧目录,窗口重载后即接管
|
||||
- 注意:Tauri fs 默认禁止 dotfile,标记/锁文件不能用 `.xxx` 命名
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
# 桌面版(Tauri v2)与上游网页版的关系
|
||||
|
||||
本仓库是 **image-workbench-web 的独立 fork**:代码完整复制一份,长期独立维护,
|
||||
不跟随上游自动更新,但**保留同步上游 bug 修复的能力**。
|
||||
|
||||
## 一、溯源(重要,别删)
|
||||
|
||||
| 项 | 值 |
|
||||
|---|---|
|
||||
| 上游仓库 | https://github.com/malongan/image-workbench-web |
|
||||
| fork 基线 commit | `d5f9945` |
|
||||
| fork 基线树哈希 | `72e37a2a2726569648a6b5e1ae5de37835b5258d` |
|
||||
| 复制方式 | `git archive HEAD \| tar -x`(只含被 git 跟踪的文件,不含 .git/node_modules/dist) |
|
||||
| 一致性验证 | 本仓库首个提交 `0c7850c` 的树哈希与上游 `d5f9945` **完全相同** ⇒ 复制零丢失、零改动 |
|
||||
|
||||
这两个哈希就是「同步」的锚点:第一个提交 = 上游原样,之后的提交 = 桌面侧差异。
|
||||
|
||||
## 二、桌面侧差异清单(同步时唯一需要人工关注的部分)
|
||||
|
||||
除 `src-tauri/`(纯新增,不会冲突)外,业务代码只改了这些地方:
|
||||
|
||||
| # | 文件 | 位置 | 改了什么 |
|
||||
|---|---|---|---|
|
||||
| P1 | `app.js` | 文件顶部 | 新增「桌面端适配层」:`wIsTauri()` / `wSaveBlobNative()` / `window.__IWB_SAVE_BLOB__` |
|
||||
| P2 | `app.js` | 输出缩略图归档 | 桌面端用 `plugin-http` 取字节,替代 `/api/img` 代理 |
|
||||
| P3 | `app.js` | `downloadUrl` 内 `downloadBlob` | 桌面端弹系统「另存为」,`fs.writeFile` 写 Uint8Array |
|
||||
| P4 | `app.js` | `downloadUrl` 的 `data:`/`blob:` 分支 | 桌面端先取 Blob 再走原生保存(`<a download>` 在桌面无效) |
|
||||
| P5 | `app.js` | `downloadUrl` 第③段代理兜底 | 桌面端换 `plugin-http` 直连 |
|
||||
| P6 | `app.js` | 预览派生 `viaUrl` | 桌面端不拼代理地址,直连(失败则负缓存回退原图) |
|
||||
| P7 | `app.js` | 显示缩略图 `img.src` | 桌面端直接用原地址 |
|
||||
| P8 | `app.js` | `wDownloadBlob`(备份 zip 等) | 统一走 `__IWB_SAVE_BLOB__` |
|
||||
| P9 | `app.js` | 运行诊断导出 | 同上 |
|
||||
| P10 | `app.js` | 节点组导出 | 同上 |
|
||||
| P11 | `src/runtime-workbench-logic.js` | 画布导出 `.iwb.json` | 同上 |
|
||||
| P12 | `src/runtime-workbench-logic.js` | `startCanvasZoomAndSize` | **修 bug**:resize 监听绑在 `<div>` 上永不触发 ⇒ 改 ResizeObserver,画布随窗口/侧栏变化重算 |
|
||||
| P13 | `app.js` + `src/ui-settings-sections.js` | 保存链路 / 通用设置 | 新增「默认下载文件夹」设置(仅桌面端渲染,网页版自动隐藏) |
|
||||
| P14 | `src-tauri/src/lib.rs` | Rust 壳层 | 系统托盘(关闭=收进托盘)、窗口大小位置记忆、`open_app_data_dir` 一个极简命令 |
|
||||
| P15 | `app.js` | 主题 | 增加「跟随系统」,系统外观切换实时生效 |
|
||||
| P16 | `app.js` | 自动保存生成的图片 | 桌面端没有 File System Access API ⇒ 改为写入默认下载文件夹(plugin-http 取字节) |
|
||||
| P17 | `app.js` + 设置面板 | 保存链路 | 「批量保存不再逐个弹框」(互斥:会话内授权失效时自动回退对话框) |
|
||||
| P18 | 设置面板各页 | 文案 | 去掉浏览器语义(localStorage 5MB / CORS / KV / 标签页 / 刷新),桌面端显示对应真实含义 |
|
||||
| P19 | 新增 `src/storage-file.js` | 存储底座 | 资料目录:data.json(全部 localStorage 键)+ images/<sha16>.<ext>(图片字节);启动装载 → 内存 → 异步原子落盘;IndexedDB 旧图片一次性迁移 |
|
||||
| P20 | `src-tauri/src/lib.rs` | 命令 | `grant_dir`:把资料目录加进本次运行的 fs scope(fs 授权是会话级,重启由此补授权) |
|
||||
| P21 | `app.js` | 保存阈值 | 内联图片阈值 16384 → 3000(>3KB 的 dataURL 一律转 `{__blob}` 引用);并加一次性迁移 `wMigrateInlineImages` |
|
||||
| P22 | `src/storage-file.js` + 设置面板 | 目录管理 | 首启向导(默认目录 / 选已有目录)+ 设置里「资料目录 → 切换…」(切换前刷盘,之后重载窗口) |
|
||||
|
||||
新增的配套文件(都不碰业务逻辑):
|
||||
|
||||
| 路径 | 作用 |
|
||||
|---|---|
|
||||
| `src-tauri/` | 壳层:conf / capabilities / lib.rs(只注册 dialog、fs、http 三个官方插件,零自定义命令) |
|
||||
| `plugins/runtime/*.js` | 7 个运行时插件的发布产物(从线上抓取,SHA-256 与 `plugins/index.json` 逐一校验通过) |
|
||||
| `scripts/copy-plugins.js` | 构建后把插件拷进 `dist/plugins/`(网页版由 KV 提供,桌面端只能随包) |
|
||||
| `scripts/sync-upstream.sh` + `.upstream-base` | 同步机制 |
|
||||
| `package.json` | 加 `@tauri-apps/*` 依赖、`tauri`/`app:dev`/`app:build` 脚本,`build` 链上 copy-plugins |
|
||||
|
||||
**红线:除上表外不要再改业务代码。** 差异每多一处,以后同步冲突的概率就高一分。
|
||||
|
||||
## 三、日常怎么同步上游的 bug 修复
|
||||
|
||||
因为 fork 时没有带 git 历史(`git archive`),两边的提交历史**没有共同祖先**,
|
||||
此时 `git merge upstream/main` 不可用(会被当成两棵无关的树硬拼,冲突满天飞)。
|
||||
所以第一次用「差异重放」:把桌面侧差异做成补丁,贴到新的上游版本上。
|
||||
**同步成功一次之后,本仓库就与上游共享历史了,之后可以直接 `git merge upstream/main`。**
|
||||
|
||||
```bash
|
||||
# 0) 一次性:确认 upstream remote 指向上游(也可以指向飞牛 Gitea 的镜像)
|
||||
git remote add upstream https://github.com/malongan/image-workbench-web.git
|
||||
|
||||
# 1) 先看上游有什么新东西(只读,不改任何文件)
|
||||
./scripts/sync-upstream.sh
|
||||
|
||||
# 2) 真同步:自动开 sync/<日期> 分支,把桌面侧差异贴到最新上游上
|
||||
./scripts/sync-upstream.sh --apply
|
||||
|
||||
# 3) 看结果;有冲突就手工改(冲突只会出现在上表那几个位置)
|
||||
git diff # 核对上游修复是否进来、桌面改动是否还在
|
||||
git status
|
||||
|
||||
# 4) 确认无误:并入 main,并把基线前移(下次只差增量)
|
||||
./scripts/sync-upstream.sh --finish
|
||||
```
|
||||
|
||||
脚本行为说明:
|
||||
|
||||
- `--apply` 会新建 `sync/<日期>` 分支,**不动 main**,可以反复试。
|
||||
- `--finish` 把 main 前移到这个分支,并自动留下回滚点 `backup/pre-sync-<日期>`。
|
||||
- `--finish` 之后 `upstream-base` 指向上游那个 commit,所以 `git diff upstream-base..HEAD` 永远只剩桌面侧改动。
|
||||
- 有冲突时脚本不会硬来:留冲突标记 + 列出文件,人工改完再 `--finish`。
|
||||
- 演练证据(2026-11-16):模拟上游两次 bugfix,一次走脚本、一次走原生 `git merge`,
|
||||
上游修复都进来了,`src-tauri/` 与 package.json 改动都保留,零冲突。
|
||||
|
||||
同步后的验证要点:
|
||||
```bash
|
||||
git log --oneline upstream-base..HEAD # 应只剩桌面侧提交
|
||||
npm run build && npm run test:unit # 业务回归
|
||||
npm run tauri dev # 另存为功能回归
|
||||
```
|
||||
|
||||
## 四、也可以走「只拿某几个提交」的路子
|
||||
|
||||
上游某个 bug 修复很急、但整体版本不想跟:
|
||||
|
||||
```bash
|
||||
git fetch upstream main
|
||||
git log --oneline upstream/main -- app.js | head # 找到那条修复
|
||||
git cherry-pick <sha> # 会失败:无共同祖先时 cherry-pick 也依赖 base
|
||||
# ⇒ 更可靠的做法:手工看 `git show <sha> -- app.js` 的内容,照抄那几行
|
||||
```
|
||||
|
||||
结论:**按文件抄单点修复永远可行**(这正是保留上游 remote 的意义);
|
||||
整版本升级走上面的 `sync-upstream.sh`。
|
||||
|
||||
## 五、如果哪天想彻底断开
|
||||
|
||||
删掉 `upstream` remote、`upstream-base` tag、`.upstream-base` 文件、`scripts/sync-upstream.sh` 即可,
|
||||
仓库本身不会因此坏掉——它已经是一份完整、可独立构建的源码。
|
||||
|
||||
## 六、桌面版与网页版的已知行为差异
|
||||
|
||||
| 项 | 网页版 | 桌面版 |
|
||||
|---|---|---|
|
||||
| 保存图片 | `<a download>` 落到浏览器下载目录 | 弹系统「另存为」对话框,用户选路径 |
|
||||
| 批量下载 | 连续 N 个文件静默落盘 | 连续弹 N 次另存为对话框 |
|
||||
| 跨域图床取图 | 走服务端 `/api/img` 同源代理 | 走 `plugin-http`(Rust 侧请求,不受 CORS 限制) |
|
||||
| 运行时插件 | 从 `/plugins/*` 拉取(KV 托管) | 同上,需本地静态化或后续另做方案 |
|
||||
| Service Worker / PWA | 有 | 无(不注册) |
|
||||
| 数据存储 | 浏览器 localStorage + IndexedDB | 桌面端独立空库,可用备份 zip 导入 |
|
||||
@@ -1,9 +1,6 @@
|
||||
# 🎨 生图工作台 Web 版(Cloudflare Pages 免费部署)
|
||||
# 🎨 生图工作台(桌面客户端)
|
||||
|
||||
**在线访问:https://iwb.maqiart.eu.org**(自定义域名,Cloudflare 免费 HTTPS)
|
||||
|
||||
|
||||
基于 **OpenAI 兼容生图 API** 的节点式图形化生图工作台,纯前端实现(Cloudflare Pages 免费托管)。
|
||||
基于 **OpenAI 兼容生图 API** 的节点式图形化生图工作台。**Tauri v2 桌面客户端**(macOS / Windows),数据全部落在本机资料目录。
|
||||
|
||||
- **零后端**:数据保存在浏览器(localStorage + IndexedDB),图片生成直连兼容 API;Tuzi 生图固定使用 generations、要求 URL 响应,参考图允许公网 URL 与本地 Base64,且不自动重试
|
||||
- 与独立版功能一致:无限画布、节点连线、文生图/图生图、参数设置(比例/分辨率对齐接口)、提示词库、节点组收藏、图库、右键菜单、双击聚焦/适应视图、标注节点等
|
||||
@@ -13,7 +10,7 @@
|
||||
- 稳定性边界:保存失败会保留恢复快照并支持重试,离页前执行本地兜底;启动时检查 localStorage/IndexedDB 可用性并显示异常。
|
||||
- 构建:`npm run build` 用 **esbuild 压缩打包**(单 `dist/app.js` = `src/` 模块按序拼接 + `app.js`,另有压缩 `style.css`;`dist/` 不再有 `src/`),并生成带 Git commit 元数据的 `dist/version.json`。
|
||||
- 测试:`npm test` 运行 jsdom 契约测试,`npm run test:e2e` 构建后启动本地静态服务器并运行 Playwright Chromium 测试;`npm run verify` 执行完整验证。
|
||||
- 发布:`npm run deploy` 仅在完整验证通过后,将 `dist/` 上传到 Cloudflare Pages。
|
||||
- 发布:`./scripts/publish-update.sh <版本>` 构建 macOS 双架构并写更新清单;Windows 用 `./scripts/publish-windows-update.sh <setup.exe>` 重签并写独立清单(`latest-windows.json`)。
|
||||
|
||||
## 第三方许可
|
||||
|
||||
@@ -29,27 +26,24 @@
|
||||
|
||||
**想知道「这个项目还有什么待办」** → [`BACKLOG.md`](BACKLOG.md)(唯一入口:优先级 + 证据链接 + 明确不做的项)。
|
||||
|
||||
## 部署到 Cloudflare Pages(免费)
|
||||
## 构建与发布(桌面客户端)
|
||||
|
||||
### 本地手动发布(本仓库方式)
|
||||
> 已从网页版迁移为桌面客户端,**不再部署 Cloudflare Pages**(`_headers` / `functions/` / `wrangler.toml` 已删除)。
|
||||
|
||||
```bash
|
||||
npm ci
|
||||
npm run deploy # 正式站(--branch main)
|
||||
npm run deploy:test # 测试站(--branch test)
|
||||
npm run build # 前端产物 dist/(esbuild 压缩)
|
||||
npx tauri build # 桌面安装包(macOS: .app + dmg / Windows: nsis)
|
||||
```
|
||||
|
||||
`npm run deploy` 会先跑完整 `verify`,通过后再把 `dist/` 上传到 Cloudflare Pages。
|
||||
| 平台 | 命令 | 产物 |
|
||||
| --- | --- | --- |
|
||||
| macOS | `./scripts/publish-update.sh <版本>` | `updates/latest.json` + 双架构 dmg / app.tar.gz |
|
||||
| Windows | `./scripts/publish-windows-update.sh <setup.exe>` | `updates/latest-windows.json`(平台独立) |
|
||||
|
||||
### CI(只验证,不部署)
|
||||
两个平台的更新清单**完全解耦**:mac 发版不影响 Windows 版本号,反之亦然。
|
||||
|
||||
`.github/workflows/verify.yml` 在**推送到 `main` 与向 `main` 开 PR** 时执行验证门禁,分两个 job:`gate`(`npm ci` + `npm run verify:ci` = 构建 + 校验 + lint + 单测 + 事实守卫)与 `e2e`(Playwright + `npm run test:e2e`),**不自动部署**。
|
||||
|
||||
发布配置位于 `wrangler.toml`,Cloudflare Pages 输出目录固定为 `dist/`。部署前生成的 `version.json` 可用于确认线上版本和 Git commit。
|
||||
|
||||
### 绑定自定义域名(可选)
|
||||
|
||||
Pages 项目 → **Custom domains** → 添加域名(免费 HTTPS 自动签发)。
|
||||
CI:`.github/workflows/verify.yml` 在推送 `main` 与向 `main` 开 PR 时执行 `npm run verify:ci`。
|
||||
|
||||
## 使用前配置
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
/*
|
||||
X-Content-Type-Options: nosniff
|
||||
Referrer-Policy: no-referrer
|
||||
Permissions-Policy: camera=(), microphone=(), geolocation=()
|
||||
Content-Security-Policy: default-src 'self'; script-src 'self'; worker-src 'self' blob:; style-src 'self' 'unsafe-inline'; img-src 'self' https: data: blob:; connect-src 'self' https: http://127.0.0.1:30092 http://localhost:30092 http://127.0.0.1:3425 http://localhost:3425; object-src 'none'; base-uri 'none'; frame-ancestors 'none'
|
||||
|
||||
/sw.js
|
||||
Cache-Control: no-cache, no-store, must-revalidate
|
||||
Service-Worker-Allowed: /
|
||||
@@ -0,0 +1,122 @@
|
||||
# 给 Windows 端 AI 的协作说明(Image Workbench 桌面版)
|
||||
|
||||
> 这份文档是给 **Windows 构建端的 AI agent** 读的。读完你应理解:项目架构、为什么 Windows 之前开不了网页、发布链路、你的职责边界、这次踩过的坑。
|
||||
> 详细打包步骤见仓库 `docs/WIN_BUILD_SPEC.md`(gitea/main)。本文是「认知 + 边界」,那份是「操作清单」。
|
||||
|
||||
---
|
||||
|
||||
## 1. 项目是什么
|
||||
|
||||
- Image Workbench:Tauri v2 桌面应用(本地优先的 AI 生图无限画布)。
|
||||
- 仓库:`/Users/qiqi/open/github/image-workbench-desktop`(mac 端),git remote 名为 `gitea`。
|
||||
- 分发:自建 NAS,公网 `https://download.maqiart.eu.org`,根目录 `/vol8/web/iwb-download`。
|
||||
- 版本线:现行 `3.25.x`。**注意**:仓库里最高的 git tag `v3.87.65` 是历史遗留线,semver 更大但**不是**最新——判断最新版看 `package.json` / `CHANGELOG.md` 顶条 / `tauri.conf.json`,永远别按最高 tag。
|
||||
|
||||
---
|
||||
|
||||
## 2. 为什么 Windows 之前「开网页没反应」(核心技术根因)
|
||||
|
||||
应用里有**两条**开网页的路,实现完全不同:
|
||||
|
||||
| 路径 | Rust API | 平台 | 之前 Windows |
|
||||
|---|---|---|---|
|
||||
| 独立浏览器窗口 `open_browser_window` | `WebviewWindowBuilder` + `WebviewUrl::External`,**`async fn`** | 跨平台 | 正常 |
|
||||
| 画布内嵌网页节点 `canvas_webview_*` | `Window::add_child`(子 webview,需 tauri `unstable` feature),**原来是同步 `fn`** | — | **死锁** |
|
||||
|
||||
**根因**(Tauri 2 官方文档 Known issues 原文):
|
||||
> `Window::add_child` / `Window::builder` / `Webview::cookies` 在 **Windows 同步 command 里会 deadlock**(WebView2 限制),必须用 `async` command。
|
||||
|
||||
全工程 `add_child` 只有 1 处调用(`canvas_webview_ensure`),原来是同步 `fn` → 一点画布网页整个 IPC 主线程卡死。
|
||||
|
||||
**修法(v3.25.31 已做)**:把 8 个相关 command 签名 `fn` → `async fn`。这是**跨平台**修法,**不需要任何 `#[cfg(target_os)]` 分支**。JS 端本来就用 Promise 调用,IPC 协议透明,前端零改动。
|
||||
|
||||
**给你的关键认知**:以后看到「Windows 上某个原生能力没反应/卡死,mac 正常」,先怀疑是不是同步 command 里调了 Tauri 的 Windows 限制 API(add_child / cookies 等),而不是 win 环境坏了。
|
||||
|
||||
---
|
||||
|
||||
## 3. 发布链路(mac ↔ win 协作契约)
|
||||
|
||||
```
|
||||
mac 改源码 → mac commit → mac `RELEASE=1 git push gitea main`
|
||||
→ win `git fetch gitea && git reset --hard gitea/main`
|
||||
→ win 构建 setup.exe(npm ci && npm run app:build)
|
||||
→ win 自测矩阵通过
|
||||
→ win 把 setup.exe 放到 NAS `_inbox/`(权限700,公网403)
|
||||
→ 通知 mac:版本 + size + sha256
|
||||
→ mac 签名 + 上传 + 登记 releases.json + 合并 latest.json + push
|
||||
→ win 用户可更新
|
||||
```
|
||||
|
||||
**铁律:源码只在 mac 改,win 只负责构建 + 实测 + 交付。** 不要反向(win 改 → mac 拉),会引入 CRLF 整文件 diff、rustfmt 风格 diff、win-only 死分支。
|
||||
|
||||
---
|
||||
|
||||
## 4. 你的职责边界(AI 必须遵守)
|
||||
|
||||
✅ 你该做:
|
||||
- `git reset --hard gitea\main` 到最新
|
||||
- 核对三处版本一致(package.json / tauri.conf.json / Cargo.toml)+ 确认 lib.rs 里 6 个 `async fn canvas_webview_*` 都在
|
||||
- `npm ci && npm run app:build`
|
||||
- 跑自测矩阵(尤其第 2 项:画布网页节点能打开、不卡死)
|
||||
- 把 `image-workbench_<version>_x64-setup.exe` 放 NAS `_inbox/`
|
||||
- 记录 size + SHA256,通知 mac 端
|
||||
|
||||
❌ 你绝不能做:
|
||||
- **自己签名 / 生成 .sig** —— 更新私钥只在 mac(`~/.config/iwb-updater.key`),win 签出来的 key ID 与项目公钥 `17ae57d0ac9f15f1` 不配对,客户端会拒绝安装(这次 win 放上来的临时 .sig 就被 mac 忽略重签了)
|
||||
- 改 `src-tauri\src\lib.rs` / `Cargo.toml` / `tauri.conf.json` 等任何源码
|
||||
- 跑 `cargo fmt` 或让 IDE 保存即格式化
|
||||
- `git add -A` / `git push gitea main`(push 是 mac 端 `RELEASE=1` 的单独动作)
|
||||
- 把 `target\`、`node_modules\`、`.msi`、`.sig` 提交进 git
|
||||
|
||||
---
|
||||
|
||||
## 5. 这次踩过的坑(让你少走弯路)
|
||||
|
||||
1. **win 自签 .sig 无效**:win 端没有正式私钥,签出来的 sig keyid 对不上,白签。只交 setup.exe,签名交给 mac。
|
||||
2. **`latest.json` 平台解耦 bug**:项目想做 mac/win 独立更新清单(mac→`latest.json`,win→`latest-windows.json`),但**应用的 `tauri.conf.json` endpoints 只配了 `latest.json`**,且 mac 发布脚本 `publish-update.sh` 写清单时**只硬编码 darwin 两平台、丢弃 windows 条目**。结果:win 用户的应用拉 `latest.json` 找不到 `windows-x86_64` → 更新无结果。**临时修**:mac 端把 windows 条目合并回 `latest.json`。**已修(v3.25.32)**:`publish-update.sh` 现从 `latest-windows.json` 合并 windows 条目,且**仅当 win version == 本次 mac version(同批)才合并**,否则拒绝并警告(防"声明新版、实际旧包"导致 updater 反复提示同一旧包的死循环)。
|
||||
3. **v3.25.30 旧 win 包 updater 卡「正在检查…」**:那是旧包的 updater 行为/网络,不是发布错。诊断法:浏览器打开 `https://download.maqiart.eu.org/updates/latest.json`,能看到 `windows-x86_64` 即发布侧没问题;旧包用户**直接用网页下载 setup.exe 手动升级**最稳,装上 v3.25.31 后以后就能应用内更新。
|
||||
4. **Windows 画布网页节点无圆角**:`cwv_round` 非 macOS 分支是空 stub,网页节点直角贴卡片。cosmetic,已知缺失,另排 backlog,不影响交付。
|
||||
|
||||
---
|
||||
|
||||
## 6. Windows 应用内更新链路 + 前提
|
||||
|
||||
**结论**:win 客户端**支持在程序里「检查更新」自动升级**,机制和 mac 一样,但**依赖 mac 端配合签名 + 合并更新清单**,win 端自己做不到完整闭环。
|
||||
|
||||
**更新怎么触发**
|
||||
- win 客户端 `tauri.conf.json` 的更新源写死指向 `https://download.maqiart.eu.org/updates/latest.json`(和 mac 共用一个源,**不是** `latest-windows.json`)。
|
||||
- 点「检查更新」→ 读 `latest.json` → 找 **`windows-x86_64`** 条目 → 下载它指向的 `setup.exe` → 用项目公钥校验签名 → 通过则运行安装、重启。
|
||||
- 能否更新取决于两点:① `latest.json` 里有没有 `windows-x86_64` 条目;② 那个包是不是 mac 正式私钥签的。
|
||||
|
||||
**每次 win 发版的完整链路**
|
||||
1. win 端:拉最新 main → `npm ci && npm run app:build` → 得 `image-workbench_<版本>_x64-setup.exe` → 自测矩阵 → 放 NAS `_inbox/`(**只放 setup.exe,不放 .sig**)。
|
||||
2. mac 端:`publish-windows-update.sh <setup.exe>`(正式私钥签名 + 上传 `updates/windows-x86_64/` + 写 `latest-windows.json`)。
|
||||
3. mac 端:重跑 `publish-update.sh`,把 win 条目合并进 `latest.json`(合并条件:win 版本 == mac 本次版本)。
|
||||
4. 完成后 win 用户即可在程序里检查更新到新版。
|
||||
|
||||
**硬性前提 / 规则**
|
||||
- **win 端绝不自己签名**:私钥只在 mac,win 自签 sig keyid 与公钥 `17AE57D0AC9F15F1` 不配对 → 客户端拒装。
|
||||
- **win 与 mac 同批同版本**:版本不一致时 mac 的 `publish-update.sh` 会拒绝合并落后的 win 条目(防 updater 死循环)。
|
||||
- **更新不是完全静默**:Windows 是 NSIS `setup.exe`,点更新会弹安装进度、装完自动重启(Tauri 在 win 的正常行为,非 bug)。
|
||||
- **win 只构建、不改源码、不 push**。
|
||||
|
||||
**win 端一句话**:把 setup.exe 放进 NAS `_inbox/`、通知 mac 端;剩下签名 + 合并由 mac 完成,之后 win 用户就能在程序里更新。
|
||||
|
||||
---
|
||||
|
||||
## 7. 验证发布是否到位(win 用户/你都能查)
|
||||
|
||||
```
|
||||
浏览器打开 https://download.maqiart.eu.org/updates/latest.json
|
||||
→ version 应是目标版本,platforms 应含 darwin-aarch64 / darwin-x86_64 / windows-x86_64
|
||||
浏览器打开 https://download.maqiart.eu.org/
|
||||
→ 三平台都应是「下载」按钮,不是「暂未提供」
|
||||
```
|
||||
|
||||
`latest.json` 是 `cf-cache-status: DYNAMIC`(CF 不缓存),改完即时生效,不用等。
|
||||
|
||||
---
|
||||
|
||||
## 8. 一句话给 win AI
|
||||
|
||||
> 你是构建机,不是发布机。拉最新 main → 核对版本和 async 修复 → 构建 → 自测 → 把 setup.exe 丢进 `_inbox` → 报 size/sha256 给 mac。**不签名、不改码、不格式化、不 push。** 网页下载能打开 latest.json 就说明发布没问题,剩下的是 mac 端的事。
|
||||
@@ -0,0 +1,129 @@
|
||||
# 桌面端存储改造:踩坑与铁律(2026-11-17)
|
||||
|
||||
> 本文记录把「浏览器存储」改成「本地资料目录」过程中真实发生过的故障。
|
||||
> **每一条都写清:症状 → 根因 → 修法 → 铁律**。以后动存储相关代码前先读这篇。
|
||||
|
||||
---
|
||||
|
||||
## 一、故障清单(按严重度)
|
||||
|
||||
### P1 画布节点全部显示为空(最严重,数据"看起来"丢了)
|
||||
|
||||
- **症状**:画布卡片显示「0 个节点」,打开画布空白;`canvases/` 里出现 413 个畸形文件名(`01`、`0141` …)
|
||||
- **根因**:拆分画布文件时用 `k.slice(9)` 取文件名,但 `'iwb_ws_'` 长度是 **7**,不是 9 ⇒ 文件名少了开头 2 个字符(`ws`)
|
||||
- 装载时用「`iwb_ws_` + 文件名」还原键 ⇒ 和真实键对不上 ⇒ 读不到数据
|
||||
- 更糟:**每次启动都会再截断 2 个字符并覆盖原文件**(读错→按错键写回),越开越乱
|
||||
- **修法**:前缀长度用常量 `WS_PREFIX.length`;一次性按文件内容里的 `id` 字段把文件名改回 `<id>.json`;再从 WebView 的 localStorage 捞回节点更多的版本(957 → 1337 节点,空画布归零)
|
||||
- **铁律**:
|
||||
1. **禁止魔法数字**取 key 前缀,统一 `k.slice(PREFIX.length)`
|
||||
2. 拆文件/改布局后**必须读回校验**(键对得上、节点数一致),对不上不许继续
|
||||
|
||||
### P2 迁移「先删后写」导致图库清单丢失
|
||||
|
||||
- **症状**:图库 7 张全显示「图片已丢失」
|
||||
- **根因**:把 `library/gallery.json` 迁到 `library/gallery/index.json` 时,代码是**先删旧文件、后写新文件**;新版本第一次启动删掉旧的、还没写新的,清单就没了
|
||||
- **修法**:改成「先写新位置 → 写成功后才删旧」;并加自愈(清单缺失时从 `assets` 的 `out_*` 键反推重建);再把缩略图回填进 `data` 字段
|
||||
- **铁律**:**迁移永远是"复制 → 校验 → 删旧",任何"先删"都是事故**
|
||||
|
||||
### P3 复用带副作用的命令,覆盖了配置
|
||||
|
||||
- **症状**:设置里「数据库目录」显示成下载目录 `/Users/qiqi/Documents/image`,「打开」也跳错地方
|
||||
- **根因**:启动时给下载目录补授权,复用了 `grant_dir`;而 `grant_dir` 会把传入路径写进 `data-dir.txt`(记录资料目录用)⇒ 下载目录的路径把记录覆盖了
|
||||
- **修法**:`grant_dir` 加 `record: Option<bool>`,下载目录传 `false`;界面路径不再被「打开」的返回值覆盖
|
||||
- **铁律**:**复用命令前先确认它的副作用**;"记录状态"和"执行动作"要分开
|
||||
|
||||
### P4 把异步 `join()` 当路径用
|
||||
|
||||
- **症状**:`data.json.tmp` 写出了 762KB,但 `data.json` 永远不存在;无报错
|
||||
- **根因**:`const target = join(dir, DATA_FILE)` 拿到的是 **Promise**,被当成路径传给 `writeTextFile` / `rename`,两边都抛错且被 catch 吞掉
|
||||
- **修法**:`await join(...)`;catch 里补日志
|
||||
- **铁律**:**路径拼接一律 await**;写盘失败必须留痕,不许静默
|
||||
|
||||
### P5 Tauri fs 权限是「命令级」,不是「路径级」
|
||||
|
||||
- **症状**:目录已授权,但写文件一律 `forbidden path`
|
||||
- **根因**:`fs:allow-write-file` 不覆盖 `writeTextFile`;`writeTextFile` / `readTextFile` 各有独立权限(`fs:allow-write-text-file` / `fs:allow-read-text-file`)
|
||||
- **修法**:capabilities 里补齐实际用到的每个命令
|
||||
- **铁律**:**用什么 API 就加什么权限**;`fs` 的每个命令是一个独立开关
|
||||
|
||||
### P6 dotfile 默认被拒
|
||||
|
||||
- **症状**:`.migrated` 标记读不到,迁移每次重跑
|
||||
- **根因**:Tauri fs 默认禁止访问点文件/点目录(防误操作 `.ssh` 之类)
|
||||
- **修法**:标记文件改名 `migrated.flag`(不含点)
|
||||
- **铁律**:**资料目录里不放点文件**;需要标记就用 `xxx.flag`
|
||||
|
||||
### P7 惰性注入的 `__TAURI__` 判断过早
|
||||
|
||||
- **症状**:文件存储的初始化根本没跑,数据一个都没落盘
|
||||
- **根因**:`enabled()` 里判断的是模块内变量 `tauri`,而它要等 `init()` 才赋值 ⇒ 入口条件恒为 false
|
||||
- **修法**:`tk()` 惰性读取 `global.__TAURI__`,所有判断都经过它
|
||||
- **铁律**:**全局注入对象一律惰性读取**,不要在模块加载期就断言存在
|
||||
|
||||
### P8 同步 API 遇异步 IO(架构约束)
|
||||
|
||||
- **症状**:把存储底座换成文件后,全部同步读写代码无法直接迁移
|
||||
- **根因**:localStorage 是同步的,文件 IO 是异步的;业务层 63 处同步调用不能改
|
||||
- **修法**:**启动时全量读入内存 → 运行时同步读写内存 → 800ms 防抖异步落盘**(关窗/隐藏/失焦时强制 flush)
|
||||
- **铁律**:**同步契约 + 异步持久化**用"内存镜像"桥接,不要把异步往下传导
|
||||
|
||||
### P9 图库清单重建时没带缩略图
|
||||
|
||||
- **症状**:图库 7 张全「图片已丢失」
|
||||
- **根因**:渲染条件是 `f.data || f.url`;重建清单只填了 `name/时间/idb/origIdb`,两个都是空
|
||||
- **修法**:一次性回填——按 `idb` 读 `images/thumbs/<hash>.jpg` 写进 `data`(限制 96KB 以内防清单膨胀)
|
||||
- **铁律**:**重建清单必须同时重建"渲染所依赖的字段"**,否则等于没修
|
||||
|
||||
### P10 语义变化没同步:从"出图就下载"改成"点下载才下载"
|
||||
|
||||
- **症状**:用户目录堆满不想要的图
|
||||
- **根因**:网页版的「自动保存生成的图片」语义是"出图即下载",桌面端沿用
|
||||
- **修法**:桌面端关闭自动下载;下载目录改为「用户点下载才写入、不弹窗」;自动下载开关在桌面端隐藏
|
||||
- **铁律**:**改环境时必须重审"自动化动作"**,桌面端的默认行为应更保守
|
||||
|
||||
---
|
||||
|
||||
## 二、数据恢复的关键做法(这次救了 12 个画布)
|
||||
|
||||
> 迁移时**只复制、不清源**。WebView 的 localStorage 一直留着迁移前的原始数据,
|
||||
> 所以出事后可以按「文件节点数 vs localStorage 节点数,谁多取谁」恢复。
|
||||
|
||||
**铁律:任何一次数据搬迁,源数据至少保留到"用户确认新位置一切正常"为止。**
|
||||
|
||||
---
|
||||
|
||||
## 三、以后动存储的强制检查清单
|
||||
|
||||
改动前:
|
||||
|
||||
1. 记录基线:画布数 / 节点总数 / assets 条数 / `images/` 四类文件数 / `library` 文件数
|
||||
|
||||
改动后(每次):
|
||||
|
||||
2. 启动 → **读回**:`data.json` 里的画布数、每个画布文件的节点数、`assets` 与文件的对应
|
||||
3. 对账:与基线逐项比对,**数量只许增不许减**
|
||||
4. 抽查:打开 1 个画布看节点、图库看 7 张、点一次下载看是否落盘
|
||||
5. 检查目录结构:`canvases/` `library/gallery/` `images/{canvas,gallery,thumbs,legacy}`
|
||||
6. 检查 flag:`migrated.flag` `migrated-v2.flag` `canvases-fixed.flag` `gallery-thumbs.flag` `recovered-from-browser.flag`
|
||||
7. 对不上 → **立即回滚**(保留旧目录/旧文件),不许继续往下做
|
||||
|
||||
---
|
||||
|
||||
## 四、目前已实现的数据结构(供对照)
|
||||
|
||||
```
|
||||
ImageWorkbench/
|
||||
├── data.json 设置(含 Key)/主题/杂项 + assets 映射 + 旧格式 keys
|
||||
├── canvases/<id>.json 一画布一文件(内容是画布 JSON,含 id 字段)
|
||||
├── library/
|
||||
│ ├── prompts.json
|
||||
│ ├── groups.json
|
||||
│ ├── group-groups.json
|
||||
│ └── gallery/index.json 图库清单(含 data 缩略图)
|
||||
├── images/
|
||||
│ ├── canvas/ imgblob_* 画布节点图
|
||||
│ ├── gallery/ out_orig_* 图库原图
|
||||
│ ├── thumbs/ out_* 缩略图(可再生)
|
||||
│ └── legacy/ 旧 __cache__ 绝对 URL 键
|
||||
└── *.flag 一次性迁移标记
|
||||
```
|
||||
@@ -0,0 +1,66 @@
|
||||
# 在线更新(Tauri Updater)
|
||||
|
||||
> 目标:用户装过一次之后,以后新版本在应用内点「检查更新」即可升级,不用再手动下载 dmg。
|
||||
|
||||
## 一、已经配好的东西
|
||||
|
||||
| 组件 | 位置 | 说明 |
|
||||
|---|---|---|
|
||||
| 更新插件 | `src-tauri/Cargo.toml` → `tauri-plugin-updater` | Rust 侧用 `UpdaterExt` |
|
||||
| 更新源 | `src-tauri/tauri.conf.json` → `plugins.updater.endpoints` | `https://download.maqiart.eu.org/updates/latest.json` |
|
||||
| 签名公钥 | 同上 `plugins.updater.pubkey` | 私钥在 `~/.config/iwb-updater.key`(**务必备份**) |
|
||||
| 产物开关 | `bundle.createUpdaterArtifacts: true` | 构建 app 时额外产出 `.app.tar.gz` + `.sig` |
|
||||
| Rust 命令 | `check_update` / `install_update` | 前端通过 `__TAURI__.core.invoke` 调用 |
|
||||
| 前端入口 | 设置 → 通用 → 版本与更新 | 「检查更新」→「立即更新」→ 自动重启 |
|
||||
|
||||
## 二、发新版本(一条命令)
|
||||
|
||||
```bash
|
||||
./scripts/publish-update.sh 3.25.3 # 改版本 + 双架构签名构建 + 上传 + 生成 latest.json
|
||||
```
|
||||
|
||||
脚本会做四件事:
|
||||
|
||||
1. `npx tauri build --bundles app,dmg`(arm64,带签名)
|
||||
2. `npx tauri build --target x86_64-apple-darwin --bundles app,dmg`(Intel,带签名)
|
||||
3. 上传 `*.app.tar.gz` / `.sig` / `.dmg` 到 NAS `updates/darwin-{aarch64,x86_64}/`
|
||||
4. 生成并上传 `updates/latest.json`(两个平台各自带 signature + url)
|
||||
|
||||
## 三、latest.json 格式(脚本自动生成)
|
||||
|
||||
```json
|
||||
{
|
||||
"version": "3.25.2",
|
||||
"notes": "更新说明",
|
||||
"pub_date": "2026-11-17T09:43:08.117Z",
|
||||
"platforms": {
|
||||
"darwin-aarch64": { "signature": "<.sig 内容>", "url": "https://.../image-workbench_3.25.2_aarch64.app.tar.gz" },
|
||||
"darwin-x86_64": { "signature": "<.sig 内容>", "url": "https://.../image-workbench_3.25.2_x64.app.tar.gz" }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
⚠️ **两个平台都要有**:缺哪个平台,那个平台的用户就永远「已是最新」。
|
||||
|
||||
## 四、用户侧流程
|
||||
|
||||
1. 装过任一 3.25.2+ 版本(这是第一个带更新器的版本)
|
||||
2. 设置 → 通用 → 版本与更新 → **检查更新**
|
||||
3. 有新版本 → 显示版本号与说明 → 点「立即更新」
|
||||
4. 自动下载、校验签名、替换、重启(数据目录不受影响)
|
||||
|
||||
## 五、注意
|
||||
|
||||
- **私钥丢了就不能再发更新**(签名对不上,所有旧客户端会拒绝安装)。备份 `~/.config/iwb-updater.key`
|
||||
- 公钥写在 `tauri.conf.json` 里进了仓库;私钥**绝不能**进仓库
|
||||
- macOS 未做 notarization:更新替换后仍是未签名 app,首次打开可能仍要右键→打开
|
||||
- Windows 将来出包时,在 latest.json 里加 `windows-x86_64`,并在 `bundle.targets` 里用 `nsis`(msi 不支持 updater)
|
||||
- Cloudflare 会缓存 404:新文件名第一次访问可能短暂 404,换文件名(内容变即哈希变)即可绕过
|
||||
|
||||
## 六、首次接入清单(已完成 2026-11-17)
|
||||
|
||||
- [x] 生成密钥对(`tauri signer generate`),公钥进 config,私钥留本机
|
||||
- [x] 加 `tauri-plugin-updater`,注册 `check_update` / `install_update`
|
||||
- [x] `createUpdaterArtifacts: true`
|
||||
- [x] 构建 3.25.2(arm + Intel)并发布 latest.json
|
||||
- [ ] 用户实测:装 3.25.2 后,3.25.3 发布时能一键更新(待验证)
|
||||
@@ -0,0 +1,127 @@
|
||||
# Windows 出包步骤(手把手)
|
||||
|
||||
> **本版要打的版本:3.25.1**(仓库里已经是这个号,直接构建,不要再改)
|
||||
>
|
||||
> 确认命令:node -e "console.log(require('./package.json').version)" → 应输出 3.25.1
|
||||
>
|
||||
> 产物名:image-workbench_3.25.1_x64-setup.exe / image-workbench_3.25.1_x64_en-US.msi
|
||||
|
||||
> 目标:在一台 Windows 机器上,从 Gitea 拉代码 → 打出安装包 → 自测 → 把产物回传到 NAS。
|
||||
|
||||
## 0. 前置检查
|
||||
|
||||
- Windows 10 1803+ 或 Windows 11,**x64**
|
||||
- 磁盘 ≥ 5 GB 空闲(Rust 编译产物较大)
|
||||
- 有本地管理员权限(装 Visual Studio Build Tools 需要)
|
||||
|
||||
## 1. 安装工具链(一次性)
|
||||
|
||||
| 工具 | 命令 / 说明 |
|
||||
|---|---|
|
||||
| Git | `winget install Git.Git` |
|
||||
| Node.js LTS(22) | `winget install OpenJS.NodeJS.LTS` |
|
||||
| Rust | `winget install Rustlang.Rustup` 然后 `rustup default stable-x86_64-pc-windows-msvc` |
|
||||
| **VS Build Tools 2022** | 勾选「**使用 C++ 的桌面开发**」(MSVC v143 + Windows SDK)——**最容易漏** |
|
||||
| WebView2 Runtime | Win11 自带;Win10 没有就装 Evergreen |
|
||||
|
||||
自检:
|
||||
|
||||
```powershell
|
||||
cd image-workbench-desktop
|
||||
powershell -ExecutionPolicy Bypass -File scripts\windows-check.ps1
|
||||
```
|
||||
|
||||
全部 `[OK]` 再做下一步。Rust 那行不能出现 `gnu`(必须 msvc)。
|
||||
|
||||
## 2. 取代码
|
||||
|
||||
```powershell
|
||||
git clone https://git.maqiart.eu.org/malongan/image-workbench-desktop.git # 公网(公开库)
|
||||
# 或内网/Tailscale:git clone http://192.168.100.185:3000/malongan/image-workbench-desktop.git
|
||||
```
|
||||
|
||||
建议放 `C:\work\image-workbench-desktop`(避开长路径/中文路径)。
|
||||
|
||||
## 3. 安装依赖
|
||||
|
||||
```powershell
|
||||
cd C:\work\image-workbench-desktop
|
||||
npm ci
|
||||
```
|
||||
|
||||
用 `npm ci`,不要 `npm install`。卡住就换 registry 或配代理。
|
||||
|
||||
## 4. 设版本号(三处必须一致)
|
||||
|
||||
```powershell
|
||||
node scripts/set-version.js 3.25.0
|
||||
```
|
||||
|
||||
同时改 `package.json` / `src-tauri/tauri.conf.json` / `src-tauri/Cargo.toml`。
|
||||
版本必须比线上大,否则以后接自动更新时客户端不认。
|
||||
|
||||
## 5. 出包
|
||||
|
||||
```powershell
|
||||
npm run app:build
|
||||
```
|
||||
|
||||
内部顺序:`lint → build → 剥离内置插件 → tauri build`(lint 不过就不出包,故意的)。
|
||||
|
||||
产物:
|
||||
|
||||
| 文件 | 用途 |
|
||||
|---|---|
|
||||
| `src-tauri\target\release\bundle\nsis\image-workbench_3.25.0_x64-setup.exe` | **主推**(当前用户安装,免管理员) |
|
||||
| `src-tauri\target\release\bundle\msi\image-workbench_3.25.0_x64_en-US.msi` | 企业环境用 |
|
||||
| `src-tauri\target\release\image-workbench.exe` | 免安装单文件(目标机需 WebView2) |
|
||||
|
||||
首次构建 5~15 分钟,之后增量 1~2 分钟。
|
||||
|
||||
## 6. 自测(必须过)
|
||||
|
||||
1. 安装 → 启动
|
||||
2. 数据目录生成:`%USERPROFILE%\Documents\ImageWorkbench`(data.json / canvases / library / images)
|
||||
3. 设置→通用:「数据库目录」路径正确,「打开」能弹资源管理器
|
||||
4. 关窗进程留托盘;左键托盘唤窗口;右键有菜单
|
||||
5. 设置→插件:**无内置插件**;市场列 7 个;装一个 → 重启后可用
|
||||
6. 画布新建/拖拽/缩放正常;导入图片正常
|
||||
7. 点「下载」→ 直接落到导出目录,不弹另存为
|
||||
|
||||
## 7. 把产物传回来
|
||||
|
||||
**A. 传 NAS(局域网/Tailscale)**
|
||||
|
||||
```powershell
|
||||
scp "src-tauri\target\release\bundle\nsis\image-workbench_3.25.0_x64-setup.exe" malongan@192.168.100.185:/vol8/web/iwb-download/updates/windows-x86_64/
|
||||
```
|
||||
|
||||
**B. 传 Gitea Releases**(公开库匿名可下载)
|
||||
|
||||
**C. 发我**:我上传 NAS 并更新 `releases.json` 与下载页
|
||||
|
||||
## 8. 常见错误
|
||||
|
||||
| 报错 | 原因 | 解决 |
|
||||
|---|---|---|
|
||||
| `link.exe not found` | 没装 VS Build Tools C++ 工作负载 | 重装并勾「使用 C++ 的桌面开发」 |
|
||||
| rustc 显示 `gnu` | 默认工具链错 | `rustup default stable-x86_64-pc-windows-msvc` |
|
||||
| `Windows SDK is not installed` | SDK 缺失 | Build Tools 勾 Windows SDK |
|
||||
| 启动报 WebView2 错误 | 缺运行时 | 装 Evergreen Runtime |
|
||||
| `npm ci` 超时/证书 | 网络 | 换 registry / 配 proxy |
|
||||
| 编译文件被占用 | 杀软扫描 target | 排除 `src-tauri\target` |
|
||||
| 路径过长 | 目录太深 | 放 `C:\work\`;`git config --system core.longpaths true` |
|
||||
| beforeBuildCommand lint 失败 | 代码有未定义变量 | 修代码,别绕过门禁 |
|
||||
|
||||
## 9. 当前状态
|
||||
|
||||
- **自动更新未启用**(updater 未装)⇒ Windows 包只能手动下载安装
|
||||
- 下载页 Windows 位置现在显示「暂未提供」;传回后我加一条 `windows-x86_64` 就自动出现
|
||||
- 插件不随包:新机器是零插件,需从市场装
|
||||
|
||||
## 10. 一句话流程
|
||||
|
||||
```
|
||||
装工具 → git clone → npm ci → node scripts/set-version.js x.y.z
|
||||
→ npm run app:build → 自测 7 条 → 传回 NAS/Gitea → 我更新下载页
|
||||
```
|
||||
@@ -0,0 +1,364 @@
|
||||
# 插件目录化 + 三个库插件化 · 完整方案
|
||||
|
||||
> v2(2026-11-20)· 已并入「桌面端定位」「展示页例外」「不做分类」三项裁定
|
||||
> 范围:插件从「单文件」改为「文件夹」;随后把 **图库 / 提示词库 / 节点组库** 改为插件
|
||||
> 非目标:分类插件(画布分类维持现状);插件安全沙箱;画布内核重构
|
||||
>
|
||||
> **重要前提(2026-11-20 实测纠正)**:桌面包**不随包发布任何插件** —— `beforeBuildCommand` 里的
|
||||
> `scripts/strip-plugins.js` 会在打包前把 `dist/plugins` 移走,插件一律从市场装到 `<资料目录>/plugins/`。
|
||||
> 因此本仓的 `plugins/`(index.json + runtime + 目录插件)是**市场构建输入**,不是应用内置资源;
|
||||
> 「内置插件」在桌面上并不存在。目录插件要真正可用,必须先有 M3 的 zip 安装能力。
|
||||
|
||||
---
|
||||
|
||||
## 0. 决策摘要(本方案按这 10 条执行)
|
||||
|
||||
| # | 决策 | 状态 |
|
||||
|---|---|---|
|
||||
| 1 | 应用本体 = 独立桌面端(Tauri);产品代码不加浏览器降级分支 | 已定 |
|
||||
| 2 | **例外**:插件展示页 / 市场页 / 下载页仍是静态网页,继续维护 | 已定 |
|
||||
| 3 | 插件格式 = 目录(`manifest.json + main.js + styles.css + data.json + assets/`) | 本方案 |
|
||||
| 4 | 插件数据落 `<资料目录>/plugin-data/<id>.json`(与代码目录分离,卸载默认保留) | 建议默认 |
|
||||
| 5 | 市场安装 = zip 整包 + 逐文件 sha256;安装仅桌面 | 建议默认 |
|
||||
| 6 | 旧单文件插件保留一个版本周期的双轨兼容 | 本方案 |
|
||||
| 7 | **不做**分类插件(`iwb_home_cats` + `workspace.category` 维持现状) | 已定 |
|
||||
| 8 | 插件不得直接改画布:插入/实例化一律走宿主 capability | 本方案 |
|
||||
| 9 | 市场包用 **ZIP STORE(不压缩)**,绕开旧 WebView 无 `DecompressionStream` 的兼容坑 | 复查新增 |
|
||||
| 10 | 图库/提示词/节点组插件化后,**保留宿主面板一个版本周期**可一键退回(`iwb_panels_mode`) | 复查新增 |
|
||||
|
||||
---
|
||||
|
||||
## 1. 现状(代码核对过的事实)
|
||||
|
||||
| 环节 | 现状 | 位置 |
|
||||
|---|---|---|
|
||||
| 插件产物 | 单个 IIFE `<id>.<hash>.js`,内容寻址 | `plugins/runtime/` |
|
||||
| 清单 | `index.json`:`{id,file,version,integrity}`;展示信息在 `meta.json` | `plugins/index.json` |
|
||||
| 注册契约 | 插件自注册 `IWBPluginHost.register(manifest, factory)` | 各插件末尾 |
|
||||
| 内置加载 | `<script src="/plugins/x.js" integrity=…>`(SRI) | `runtime-plugin-loader.js:54` |
|
||||
| 外部加载 | 读文本 → sha256 → blob 注入 | `:71` |
|
||||
| 开发模式 | **已是目录**:`<资料目录>/plugins/local/<id>/plugin.js` | `storage-file.js:441` |
|
||||
| 市场安装 | 下载单文件 → sha256 → 写盘 → 重启 | `runtime-plugin-market.js:65` |
|
||||
| 插件数据 | `ctx.storage.namespace(ns)` → 全量落 `localStorage['iwb_plugins']`(≈5MB) | `plugin-host.js:100` |
|
||||
| 能力面 | panels/commands/nodeTypes/generationHooks/providers/canvas/canvasWrite/nodeActions | `plugin-host.js:8` |
|
||||
| CSP | `script-src 'self' blob:`;`style-src 'self' 'unsafe-inline'` | `tauri.conf.json` |
|
||||
| 图库规模 | 上限 500 张 | `runtime-constants.js:6` |
|
||||
| 展示页 | `site/plugins/index.html` ← `gen-site.js` ← `market/index.json` | 静态站 |
|
||||
|
||||
三条判断:
|
||||
|
||||
1. **目录形态已有先例**(dev 模式),只是没推广到正式插件 → 改动可控。
|
||||
2. **瓶颈是数据不是形态**:所有插件共用一个 localStorage 键,图库/提示词一大就爆。
|
||||
3. **展示页与桌面端共享 `market/index.json`**:新字段只能加、不能改,原有 `name/desc/tags/version/icon/author` 必须保留。
|
||||
|
||||
---
|
||||
|
||||
## 2. 目标形态
|
||||
|
||||
### 2.1 目录结构
|
||||
|
||||
```
|
||||
<插件根>/<id>/
|
||||
manifest.json 唯一真源
|
||||
main.js IIFE,自注册(沿用现有 register)
|
||||
styles.css 可选,注入 <style data-plugin="<id>">
|
||||
data.json 可选,插件数据(由宿主代理读写,见 2.3)
|
||||
assets/ 可选,图标/图片(ctx.asset → data URL)
|
||||
```
|
||||
|
||||
与 Obsidian 完全同构(`manifest.json/main.js/styles.css/data.json`),差异只有 `minAppVersion→apiVersion` 与可选 `assets/`。
|
||||
|
||||
### 2.2 manifest 字段
|
||||
|
||||
```jsonc
|
||||
{
|
||||
"id": "gallery", "name": "图库", "version": "1.0.0", "apiVersion": 1,
|
||||
"main": "main.js", "style": "styles.css",
|
||||
"description": "…", "author": "official", "icon": "🖼️", "tags": ["资源"],
|
||||
"capabilities": ["panels", "gallery"],
|
||||
"permissions": ["gallery.read", "gallery.delete", "canvas.insertRef"],
|
||||
"settings": {},
|
||||
"data": { "schemaVersion": 1, "maxBytes": 2097152 }
|
||||
}
|
||||
```
|
||||
|
||||
- `description/author/icon/tags` 接管原 `meta.json`,展示页从构建期汇总读取。
|
||||
- 旧单文件插件的内嵌清单继续有效;同 id 时**目录优先**。
|
||||
|
||||
### 2.3 数据层(核心)
|
||||
|
||||
| 层 | 用途 | 落点 | API |
|
||||
|---|---|---|---|
|
||||
| settings | 少量配置 | `localStorage['iwb_plugins'][id].settings`(现状) | `ctx.settings`(同步,不变) |
|
||||
| **data** | 业务数据 | `<资料目录>/plugin-data/<id>.json` | **`ctx.data`(异步,新增)** |
|
||||
| assets | 图标/图片 | `<插件目录>/assets/` | `ctx.asset(name)` → data URL |
|
||||
|
||||
```js
|
||||
ctx.data.read() // → object(不存在返回 {})
|
||||
ctx.data.write(obj) // 全量覆盖;原子写:<id>.json.tmp → rename
|
||||
ctx.data.patch(fn|obj) // 读-改-写,内部串行队列
|
||||
ctx.data.remove() // 清空
|
||||
ctx.data.size() // 字节数(设置页展示占用)
|
||||
ctx.data.schemaVersion
|
||||
```
|
||||
|
||||
约束:单文件上限 `maxBytes`(默认 2MiB,最高 16MiB),超限写失败并提示,不静默截断;同一插件的写串行化;**图片字节不进 data.json**(图库图仍在宿主 `images/`,data.json 只存元数据)。
|
||||
|
||||
三件必须同时做的事(复查补充):
|
||||
|
||||
- **备份/还原**:`plugin-data/` 纳入备份(新增 `items.pluginData`,体积小、默认勾选);同时改造 `runtime-plugin-backup.js`——它现在只备份单文件插件的 `code`,目录插件会丢。
|
||||
- **存储审计**:`wStorageAudit` 增加「插件数据」占用,设置页可见、可清空。
|
||||
- **双写禁令**:`ctx.storage`(同步、落 localStorage)从 M2 起只允许存 settings 级小值;业务数据一律 `ctx.data`。迁移后把 `iwb_plugins[id].data` 清空只留 `migratedAt`,避免两份真源。
|
||||
|
||||
> 唯一例外:jsdom / playwright 测试在非 Tauri 环境跑应用,`ctx.data` 保留内存兜底,标注"仅供测试",不得据此在产品代码加浏览器分支。
|
||||
|
||||
### 2.4 加载流程
|
||||
|
||||
```
|
||||
内置: /plugins/index.json(构建生成的目录索引,含逐文件 sha256) + /plugins/<id>/manifest.json
|
||||
外部: <资料目录>/plugins/index.json + <资料目录>/plugins/<id>/manifest.json
|
||||
扫描: 桌面额外扫描 <资料目录>/plugins/*/manifest.json(手工放入、无索引也能识别)
|
||||
开发: <资料目录>/plugins/local/<id>/plugin.js(免签名)
|
||||
```
|
||||
|
||||
`loadFolder(record)`:读 manifest → 校验(apiVersion/capabilities/permissions)→ 读 main.js 并校验 hash → 注入 `__IWB_PLUGIN_MANIFEST__` → blob 注入 → 注入 styles.css → 等自注册。
|
||||
|
||||
> Tauri 资源协议**不能列目录** ⇒ 内置索引必须构建期生成;外部目录才可扫描。
|
||||
|
||||
复查补充的 4 条硬规则:
|
||||
|
||||
1. **信任模型**:内置插件只信**随包的** `plugins/index.json`(里面的逐文件 sha256 写死在包里);manifest 里的 hash 只用于"外部/市场安装"校验,不能拿它自证。
|
||||
2. **确定性顺序**:两路合并后按 `id` 升序加载;不依赖文件系统返回顺序。
|
||||
3. **失败隔离**:单个插件 manifest 损坏 / 脚本抛错 → 记 `record.error` 并跳过,**不得中断整轮加载**。
|
||||
4. **注册去重**:`registerPanel/registerNodeType` 按 `pluginId + 自身 id` 去重,防止热启停导致面板重复。
|
||||
|
||||
### 2.5 安装(仅桌面)
|
||||
|
||||
市场条目:
|
||||
|
||||
```jsonc
|
||||
{ "id":"gallery","version":"1.0.0","minApiVersion":1,
|
||||
"bundle":"gallery-1.0.0.zip",
|
||||
"files":[{"path":"manifest.json","sha256":"…","size":812}, …] }
|
||||
```
|
||||
|
||||
流程:下载 zip(30s 超时)→ `wZipParseEntries` 解析 → 校验 path(禁 `../`/绝对路径)+ sha256 + size → 解到 `plugins/.staging/<id>/` → 校验 manifest 可解析且 id 匹配 → 替换目录 → 更新 index.json → 提示重启。
|
||||
|
||||
复查补充:
|
||||
|
||||
- **压缩方式固定 STORE**:`wZipReadEntry` 对 DEFLATE 依赖 `DecompressionStream('deflate-raw')`,而项目未设 `minimumSystemVersion`(默认 10.13),旧 macOS 的 WKWebView 没有该 API ⇒ 安装直接失败。插件包只有几十 KB,用 STORE 不压缩,顺带消除这个依赖。
|
||||
- **Windows 覆盖替换**:`fs().rename` 在 Windows 对"已存在的目标目录"会报错。改为 `<id>.new` 就位 → 旧目录改名 `<id>.old` → rename `<id>.new` → 成功后删 `<id>.old`;失败则把 `<id>.old` 改回,保证可回滚。
|
||||
- **安装限额**:解压后 ≤ 10MB、文件数 ≤ 200、单文件 ≤ 2MB;超限拒装(防 zip 炸弹与超大 assets)。
|
||||
卸载:删目录 + **询问是否连数据一起删**(默认保留 `plugin-data/<id>.json`)。
|
||||
|
||||
### 2.6 展示页(唯一保留的网页)
|
||||
|
||||
`site/plugins/index.html` 与 `site/plugins-index.json` 由 `gen-site.js` 从 `market/index.json` 生成,部署在 `download.maqiart.eu.org/plugins/`。
|
||||
|
||||
- 页面只渲染卡片(图标/名称/版本/作者/描述/标签)+ 安装说明,**不直接读插件目录**(静态站没有文件系统)。
|
||||
- 目录化后无需改页面结构;只需保证 `market/index.json` 字段可加性。
|
||||
|
||||
### 2.7 权限(advisory)
|
||||
|
||||
`permissions` 在 manifest 声明,宿主按声明放行 capability(无 `gallery.read` 就拿不到 `ctx.gallery`)。
|
||||
诚实边界:插件仍运行在主页面上下文,**不是安全沙箱**;权限只是 API 门禁 + 安装时展示。
|
||||
|
||||
---
|
||||
|
||||
## 3. 里程碑
|
||||
|
||||
每阶段可独立发布/回滚。
|
||||
|
||||
### M1 目录插件加载(兼容旧单文件)
|
||||
|
||||
> 实施状态(2026-11-20):加载器与数据层已完成并入库;但**生产插件暂不目录化** ——
|
||||
> 桌面包不内置插件、市场只支持单文件,目录插件无处可装。`image-annotate` 试点已回退为单文件,
|
||||
> 等 M3 落地后再切回目录。
|
||||
|
||||
| 改动 | 文件 | 关键点 |
|
||||
|---|---|---|
|
||||
| 目录读写 API | `src/storage-file.js` | `listDirs/readFile/writeFile/writeBinary/mkdir/removeDir`;路径按段校验,禁 `..` |
|
||||
| `loadFolder()` | `src/runtime-plugin-loader.js` | 见 2.4 |
|
||||
| 三路合并 | `app.js` `wLoadRuntimePlugins` | 索引 + 扫描 + dev;目录优先 |
|
||||
| 清单校验 | `src/plugin-host.js` `validate()` | 增 `main/style/permissions/data` |
|
||||
| 构建产物 | `scripts/sync-plugins-from-repo.js` | 产出 `plugins/<id>/` + 升级版 index.json;单文件产物保留一版用于回滚 |
|
||||
|
||||
**验收**:`image-annotate` 转目录形态后台可加载、面板正常;其余 7 个单文件插件行为零变化。
|
||||
|
||||
### M2 数据层 `ctx.data`
|
||||
|
||||
| 改动 | 文件 |
|
||||
|---|---|
|
||||
| 数据适配器(Tauri 文件;非桌面内存兜底) | 新 `src/plugin-data.js` |
|
||||
| `ctx.data` 注入 + 串行队列 | `src/plugin-host.js` |
|
||||
| `iwb_plugins[id].data` 一次性迁移 | `app.js`(幂等,带 migrated 标记) |
|
||||
| 设置页显示占用 + 清空 | `src/ui-settings-sections.js` |
|
||||
|
||||
**验收**:annotate 记住笔刷/颜色,重启仍在;旧数据迁移后保留一版原值。
|
||||
|
||||
### M3 市场 zip 安装
|
||||
|
||||
| 改动 | 文件 |
|
||||
|---|---|
|
||||
| 安装/卸载/校验/原子替换 | `src/runtime-plugin-market.js` |
|
||||
| zip 读取复用 | `src/storage-zip.js`(现有 `wZipParseEntries`) |
|
||||
| 市场索引生成(bundle + files)+ **Node 侧 STORE zip 打包** | `scripts/gen-market.js` + 发布脚本(复用 STORE 写法,勿引入压缩) |
|
||||
|
||||
**验收**:装到 `<资料目录>/plugins/<id>/` 且逐文件 hash 全对;改坏一个文件即拒装、旧版本不受影响;**Windows 上覆盖升级成功**、旧 macOS(无 DecompressionStream)也能装(因为包是 STORE)。
|
||||
|
||||
### M4 插件源仓构建目录化
|
||||
|
||||
| 改动 | 文件(iwb-plugins-desktop) |
|
||||
|---|---|
|
||||
| 产物改为目录(`manifest.json` + `main.js`),**CSS 仍内联** | `scripts/build-plugin.mjs` |
|
||||
| 校验 manifest 完整性 | `scripts/validate.mjs` |
|
||||
| 脚手架 | `template/` |
|
||||
|
||||
**验收**:任一插件 build + validate 后产出的目录可被 M1 直接消费;8 个插件迁移后功能一致。
|
||||
|
||||
> 复查修正:现有 8 个插件都是**运行时 `createElement('style')` 注入 CSS**(已实测 annotate),
|
||||
> 因此 `styles.css` 只作为「手写插件」的可选项,**不改 esbuild 的 CSS 处理**,省掉一轮构建改造。
|
||||
|
||||
### M5 图库插件(第一个业务插件)
|
||||
|
||||
宿主新增 `gallery` capability(新 `src/plugin-api-gallery.js`):
|
||||
|
||||
```js
|
||||
ctx.gallery = {
|
||||
list({query, range, limit, offset}), thumb(name), original(name),
|
||||
remove(names), download(names), insertToCanvas(names, {sizeK}),
|
||||
on('changed', fn)
|
||||
}
|
||||
```
|
||||
|
||||
插件侧搬迁:`src/ui-gallery-head.js` + 图库网格 JSX(约 200 行)→ `gallery/main.js`;`app.js` 只留 `dockPanels` 一行注册。
|
||||
|
||||
**验收**:滚动/选中/全选反选/下载/插入/删除/双击预览/拖入画布 全一致;宿主删掉图库 JSX(app.js 行数下降)。
|
||||
|
||||
### M6 提示词库插件
|
||||
|
||||
宿主新增 `ctx.library.prompts`:
|
||||
|
||||
```js
|
||||
list(), save({prompts, groups}), canvasPrompts(), insert(text, name)
|
||||
```
|
||||
|
||||
数据搬进 `plugins/prompts/data.json`;插入画布走 `canvas.insertPrompt`(宿主实现,插件不碰画布状态)。
|
||||
|
||||
**验收**:增删改/分组/搜索/插入/导入导出全通;迁移前备份 `iwb_prompts`。
|
||||
|
||||
### M7 节点组库插件
|
||||
|
||||
宿主补齐 `canvasWrite`:
|
||||
|
||||
```js
|
||||
saveSelectionAsGroup(name), instantiateGroup(snapshot), previewGroup(id)
|
||||
```
|
||||
|
||||
**验收**:保存/应用/预览/删除全通;应用后位置不重叠、连线正确、可撤销。
|
||||
|
||||
---
|
||||
|
||||
## 4. 三个库的边界(插件化后)
|
||||
|
||||
| 关注点 | 归属 |
|
||||
|---|---|
|
||||
| 面板 UI、列表/筛选/按钮 | 插件 |
|
||||
| 提示词/分组/节点组快照数据 | 插件 `data.json` |
|
||||
| 图片字节 | **宿主** `images/`(不搬) |
|
||||
| 图库索引 | 宿主(`out_*` + IDB),插件只读 |
|
||||
| 画布插入/实例化 | 宿主 capability |
|
||||
|
||||
好处:卸载「图库插件」不删用户图片;卸载「提示词插件」可选连带数据。
|
||||
|
||||
---
|
||||
|
||||
## 5. 迁移与兼容
|
||||
|
||||
| 对象 | 策略 |
|
||||
|---|---|
|
||||
| 旧单文件插件 | 继续加载,给一个版本周期的双轨期 |
|
||||
| 老市场单文件包 | 仍可安装(索引同时保留 `file` 与 `bundle`) |
|
||||
| `localStorage['iwb_plugins']` | 一次性迁到新数据层,原值保留一版 |
|
||||
| 提示词/分组 | 迁到插件 data.json,先写 `iwb_prompts_backup_<date>` |
|
||||
| 图库 | **不迁移**,仍走宿主存储 |
|
||||
| 测试快照 | 插件顺序/边界守门/市场测试同步;快照重生成须写理由 |
|
||||
|
||||
---
|
||||
|
||||
## 6. 回归清单(每个里程碑都跑)
|
||||
|
||||
1. 8 个内置插件全部加载,面板/节点/命令可用;设置页开关生效。
|
||||
2. 开发者模式 `local/<id>/plugin.js` 仍可覆盖内置。
|
||||
3. 同 id 的目录插件与单文件插件共存时,目录优先且只有一个实例。
|
||||
4. 卸载后:面板/命令/节点类型/CSS 全部消失,无残留。
|
||||
5. 数据:写→重启→读一致;并发两次写不丢(串行队列)。
|
||||
6. 非桌面测试环境:插件可加载、`ctx.data` 内存兜底不抛错。
|
||||
7. 桌面手工放 `<资料目录>/plugins/<id>/` 可被识别(无索引)。
|
||||
8. `lint / typecheck / test:unit / test:facts` 全绿。
|
||||
|
||||
---
|
||||
|
||||
## 7. 风险
|
||||
|
||||
| 风险 | 缓解 |
|
||||
|---|---|
|
||||
| 插件无沙箱,权限只是门禁 | 安装时展示 permissions;只从官方市场安装;文档明确声明 |
|
||||
| 目录形态失去 SRI | 逐文件 sha256 写进 index/manifest,加载前校验,不符拒载 |
|
||||
| **桌面包无内置插件** | 删掉资料目录 `plugins/` 后所有插件消失(2026-11-20 真实反馈);目录化必须等 M3 | 文档/设置页文案明确「插件来自市场」;M3 前不发布目录插件 |
|
||||
| 双后端(文件/内存兜底)行为差异 | 同一套契约测试跑两遍;兜底只在无 Tauri 时启用 |
|
||||
| UI 搬迁期宿主与插件双份代码 | 每个里程碑"搬完即删",不留双轨 |
|
||||
| 画布写入 API 设计不当 | capability 内部复用 `commitCanvas` + 历史栈,插件只提交声明式快照 |
|
||||
| 展示页与安装器共用索引,字段冲突 | 新字段可加性;`gen-site.js` 只读已知字段 |
|
||||
|
||||
---
|
||||
|
||||
## 8. 顺序
|
||||
|
||||
```
|
||||
M1 目录加载 ──┬─→ M2 数据层 ──→ M5 图库插件 ──→ M6 提示词插件 ──→ M7 节点组插件
|
||||
└─→ M4 源仓构建
|
||||
M3 市场 zip ←(依赖 M1 的文件写入)
|
||||
```
|
||||
|
||||
M1 与 M4 可并行;M3 与 M2 可并行;M5 之后每步都复用同一种 capability 模式。
|
||||
|
||||
---
|
||||
|
||||
## 9. 复查修订(2026-11-20 · 逐项核对代码后)
|
||||
|
||||
复查方法:把方案里每个"技术依赖"回到代码验证(zip 解压、fs 能力、备份范围、插件 CSS 注入方式、CSP、系统版本)。
|
||||
|
||||
| # | 复查发现 | 影响 | 处置 | 落点 |
|
||||
|---|---|---|---|---|
|
||||
| R1 | `wZipReadEntry` 的 DEFLATE 依赖 `DecompressionStream`,而 `tauri.conf` 未设 `minimumSystemVersion`(默认 10.13) | 旧 macOS 市场安装直接失败 | 市场包固定 **ZIP STORE** | M3 |
|
||||
| R2 | `fs().rename` 在 Windows 覆盖已存在目录会报错 | 升级安装失败、无法回滚 | `<id>.new` → 旧目录改 `<id>.old` → rename → 删 old;失败回滚 | M3 |
|
||||
| R3 | `runtime-plugin-backup.js` 只 collect 单文件 `code` | 目录插件**备份后恢复不回来** | collect/restore 改为按目录收集(不含 `data.json`) | M2/M3 |
|
||||
| R4 | 备份 `items` 与 `wStorageAudit` 都不含插件数据 | 换机丢插件数据、占用看不见 | 备份加 `pluginData`;审计加「插件数据」项 | M2 |
|
||||
| R5 | `ctx.storage`(localStorage)与 `ctx.data` 并存 → 双真源 | 迁移后同一数据两份、互相覆盖 | storage 只留 settings;迁移后清空 `iwb_plugins[id].data` 只留 `migratedAt` | M2 |
|
||||
| R6 | 方案原要求构建产出 `styles.css`,但现有插件是运行时 `createElement('style')` 注入(annotate 实测) | 白改一轮 esbuild 管线 | `styles.css` 降为**手写插件可选项**,不改 CSS 构建 | M4 |
|
||||
| R7 | 注入的 `<style>` 是全局的,停用/卸载不清理 | 插件 CSS 污染宿主 UI | 注入打 `data-plugin`,deactivate 时移除;手写插件强制 `.iwb-p-<id>-` 前缀(validate 校验) | M1 |
|
||||
| R8 | 目录插件若只靠 manifest 自带的 hash 校验,等于自证 | 篡改可绕过 | 内置只信随包 `index.json`;manifest hash 只用于外部/市场 | 2.4 |
|
||||
| R9 | 目录扫描顺序由文件系统决定;单插件异常可能中断整轮 | 加载不稳定 | 按 id 排序 + 单插件失败隔离 | M1 |
|
||||
| R10 | 每次启动对 8 个插件做 sha256 + 读盘 | 冷启动变慢 | 内置按 `mtime+size` 缓存校验结果;外部每次校验 | M1 |
|
||||
| R11 | 无解压体积/文件数限制 | zip 炸弹、超大 assets | 解压后 ≤10MB、≤200 文件、单文件 ≤2MB | M3 |
|
||||
| R12 | 热启停可能重复注册面板/节点类型 | 面板出现两份 | `pluginId + id` 去重 | M1 |
|
||||
| R13 | `ctx.asset` 每次读字节转 data URL | 图标频繁 IO | 内置走 `/plugins/<id>/assets/…` URL;外部读一次进缓存,停用清空 | M1 |
|
||||
| R14 | 图库 500 张每次全量 `list` | 面板卡顿 | 分页 + `on('changed')` 节流 + 宿主侧索引缓存 | M5 |
|
||||
| R15 | 插件化后若出问题只能发版回退 | 风险高 | 保留宿主面板一版,`iwb_panels_mode = legacy \| plugin` 开关 | M5–M7 |
|
||||
| R16 | 第三方缺开发文档 | 只有你能写插件 | 产出 `docs/PLUGIN-DEV-GUIDE.md`(manifest/ctx/样式前缀/调试) | M4 |
|
||||
|
||||
### 顺带的 4 个优化(不改结构,但省事)
|
||||
|
||||
1. **先空跑**:M1 只把 annotate 转目录、行为零变化,用来验证加载链;不动任何业务面板。
|
||||
2. **内置不扫描**:内置只读随包索引(快且安全),只有外部目录才扫描——省掉每次启动的文件系统遍历。
|
||||
3. **图库插件首版只读**:先做「列表 + 预览 + 下载 + 插入」,删除/批量操作放到第二版,缩小首个业务插件的爆炸半径。
|
||||
4. **双轨只保留一个版本**:目录插件稳定后,一次性删掉单文件产物与旧市场包,避免长期两套产物。
|
||||
|
||||
---
|
||||
|
||||
## 10. 明确不做
|
||||
|
||||
- 分类插件(画布分类维持 `iwb_home_cats` + `workspace.category`)。
|
||||
- 插件沙箱、跨插件依赖声明、热重载(安装后仍要求重启)。
|
||||
- 网页版应用:只有展示页/市场页/下载页是网页。
|
||||
@@ -0,0 +1,91 @@
|
||||
# 插件 SDK(P3)
|
||||
|
||||
> 桌面版插件**全部从市场安装**,不再随应用发布。本文写给"想自己写插件"的人。
|
||||
|
||||
## 1. 两种插件来源
|
||||
|
||||
| 来源 | 位置 | 要求 |
|
||||
|---|---|---|
|
||||
| 市场(官方/社区) | `<资料目录>/plugins/*.js` + `plugins/index.json` | 清单带 `integrity`(sha256),加载时校验 |
|
||||
| 本地开发(开发者模式) | `<资料目录>/plugins/local/<id>/plugin.js` | **不校验签名**,需在设置里打开「开发者模式」 |
|
||||
|
||||
资料目录默认 `~/Documents/ImageWorkbench`(macOS)。
|
||||
|
||||
## 2. 最小插件
|
||||
|
||||
一个文件即可,格式为 IIFE,向 `window.IWBPluginHost` 注册:
|
||||
|
||||
```js
|
||||
;(function (global) {
|
||||
'use strict'
|
||||
global.IWBPluginHost.register({
|
||||
id: 'hello-world', // 唯一 id(小写字母/数字/连字符)
|
||||
name: '示例插件',
|
||||
version: '0.1.0',
|
||||
apiVersion: 1, // 宿主 API 版本,当前为 1
|
||||
capabilities: ['nodeActions', 'canvas'],
|
||||
}, function (ctx) {
|
||||
ctx.nodeActions.register({
|
||||
id: 'hello-world-count',
|
||||
title: '示例:数一下节点',
|
||||
icon: 'sparkles',
|
||||
appliesTo: function (node) { return !!(node && node.type === 'ref') },
|
||||
run: function () { console.log('节点数', ctx.canvas.getNodes().length); return true },
|
||||
})
|
||||
return { dispose: function () {} }
|
||||
})
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
```
|
||||
|
||||
完整可运行版本见仓库 `examples/plugin-hello/plugin.js`。
|
||||
|
||||
## 3. 能力(capabilities)
|
||||
|
||||
| 能力 | 作用 |
|
||||
|---|---|
|
||||
| `nodeActions` | 给节点右键/工具条加自定义动作 |
|
||||
| `canvas` | 只读访问画布(`getNodes` 等) |
|
||||
| `canvasWrite` | 写画布(`setNodeImage` 等),**必须同时声明** |
|
||||
| `events` | 订阅宿主事件 |
|
||||
| `storage` | 插件私有持久化(按插件 id 隔离) |
|
||||
|
||||
未声明的能力在 `ctx` 上是 undefined,调用会抛错。
|
||||
|
||||
## 4. 本地开发流程
|
||||
|
||||
1. 建目录:`<资料目录>/plugins/local/<你的插件 id>/plugin.js`
|
||||
2. 设置 → 插件 → 勾选「**开发者模式**」
|
||||
3. 重启应用(插件在启动时加载)
|
||||
4. 改完代码后再重启一次即可重新加载
|
||||
|
||||
> 开发者模式关闭时,`plugins/local/` 下的插件**不会被加载**(避免误执行未签名代码)。
|
||||
|
||||
## 5. 发布到市场
|
||||
|
||||
1. 把插件文件放进插件源仓 `iwb-plugins-desktop/<id>/src/index.js`
|
||||
2. 在桌面仓跑同步:`node scripts/sync-plugins-from-repo.js`
|
||||
3. 生成市场:`node scripts/gen-market.js`
|
||||
4. 把 `market/` 上传到 NAS `/vol8/web/iwb-market/`(`market.maqiart.eu.org` 的站点根目录)
|
||||
|
||||
```bash
|
||||
# 只有索引和新增的插件文件会变;index.html 是手写页面,没改动就不用传
|
||||
ssh [email protected] "rm -f /vol8/web/iwb-market/index.json"
|
||||
scp market/index.json [email protected]:/vol8/web/iwb-market/index.json
|
||||
scp market/plugins/plugin-<id>.<sha12>.js [email protected]:/vol8/web/iwb-market/plugins/
|
||||
ssh [email protected] "chmod -R a+rX /vol8/web/iwb-market"
|
||||
|
||||
# 回读核验(不能只看命令退出码):索引条数 + 下载字节 sha256 与索引一致
|
||||
curl -s "https://market.maqiart.eu.org/index.json?t=$(date +%s)" | head -c 200
|
||||
```
|
||||
|
||||
> 上传前先 `ls /vol8/web/iwb-market/plugins` 对比本地:内容寻址命名下,同名文件必然同内容,只传新增的那个即可。
|
||||
> NAS 上的文件是只读位(`-r-xr-xr-x`),覆盖前要先 `rm`,否则 `scp` 会报 Permission denied。
|
||||
> **客户端二进制不含新命令时**(旧版本安装包):`open_browser_window` 等命令 invoke 会失败,
|
||||
> 插件降级 `window.open` —— 表现为"点了跳系统浏览器"。新增宿主命令必须重新打包客户端才生效。
|
||||
|
||||
## 6. 注意事项
|
||||
|
||||
- **不要用 `alert` / `confirm` / `prompt`**:桌面端会阻塞 WebView(宿主已全部改页内确认)
|
||||
- 插件与宿主同源,能读到画布数据 ⇒ 只装可信插件
|
||||
- 插件 id 冲突会被拒绝注册(先注册者生效)
|
||||
- `dispose` 里清理你自己加的 DOM/定时器/监听器
|
||||
@@ -0,0 +1,108 @@
|
||||
# 任务:在 Windows 上为 image-workbench-desktop 构建 v3.25.15 安装包
|
||||
|
||||
你是这台 Windows 机器上的打包执行者。只做打包与自测,**不改业务代码**。
|
||||
|
||||
> ⚠️ v3.25.15 起的变化:项目已**彻底转桌面客户端**(`_headers` / `functions/` / `wrangler.toml` 已删除,`npm run deploy` 脚本已移除);
|
||||
> 更新清单**平台解耦**(Windows 用 `updates/latest-windows.json`,**由 Mac 侧用正式私钥生成,你不写**)。
|
||||
|
||||
## 硬性约束
|
||||
|
||||
1. 不改 `app.js` / `src/**` / `src-tauri/src/**` / `style.css` 的业务逻辑
|
||||
2. 不绕过 lint 门禁;报错就停下报告
|
||||
3. 不用 `npm install`,只用 `npm ci`;版本已定 **3.25.15**,不要改
|
||||
4. 不 commit / 不 push / 不打 tag / 不跑任何 `scripts/publish-*.sh`
|
||||
5. 不改 `src-tauri/tauri.windows.conf.json`(产物已锁 `nsis`,不要 msi)
|
||||
|
||||
## 第零步:拉代码
|
||||
|
||||
```powershell
|
||||
git fetch --all --tags; git checkout main; git pull --ff-only
|
||||
git rev-parse --short HEAD # 必须是 84c2c10 或其后代
|
||||
node -e "console.log(require('./package.json').version)" # 必须 3.25.15
|
||||
```
|
||||
|
||||
## 第一步:环境检查
|
||||
|
||||
```powershell
|
||||
node -v; npm -v; rustc -V; rustup show active-toolchain
|
||||
powershell -ExecutionPolicy Bypass -File scripts\windows-check.ps1
|
||||
```
|
||||
|
||||
全部 `[OK]` 才继续;出现 `[缺失]` 停止报告(不要自行安装)。
|
||||
|
||||
## 第二步:依赖
|
||||
|
||||
```powershell
|
||||
npm ci
|
||||
```
|
||||
|
||||
本次新增两个 Rust 插件依赖(single-instance / notification),首次构建会多拉一些 crate。
|
||||
|
||||
## 第三步:构建(用一次性临时密钥签名)
|
||||
|
||||
```powershell
|
||||
npx tauri signer generate -w "$env:TEMP\iwb-tmp.key" --password ""
|
||||
$env:TAURI_SIGNING_PRIVATE_KEY = Get-Content "$env:TEMP\iwb-tmp.key" -Raw
|
||||
$env:TAURI_SIGNING_PRIVATE_KEY_PASSWORD = ""
|
||||
npx tauri build
|
||||
Remove-Item "$env:TEMP\iwb-tmp.key" -Force
|
||||
```
|
||||
|
||||
> 产出的 `.sig` 是临时密钥签的,**我会在 Mac 上用正式私钥重签**,你附上即可。
|
||||
|
||||
## 第四步:确认产物
|
||||
|
||||
```powershell
|
||||
Get-ChildItem src-tauri\target\release\bundle -Recurse -Include *.exe,*.sig | Select FullName,Length
|
||||
Get-FileHash "src-tauri\target\release\bundle\nsis\image-workbench_3.25.15_x64-setup.exe" -Algorithm SHA256
|
||||
Test-Path dist\plugins # 期望 False
|
||||
Test-Path _headers # 期望 False
|
||||
Test-Path functions # 期望 False
|
||||
```
|
||||
|
||||
## 第五步:自测清单(逐条报通过/失败)
|
||||
|
||||
**基础**
|
||||
1. 安装并启动;数据目录 `%USERPROFILE%\Documents\ImageWorkbench` 生成 `data.json`/`canvases`/`library`/`images`
|
||||
2. **`images\` 下必须有 `canvas` 文件夹**(v3.25.12 之前只有 `thumbs`,这是丢图根因)
|
||||
3. 设置 → 通用:数据库目录正确;「打开」能弹资源管理器
|
||||
4. 关窗口进程仍在托盘;左键唤出;右键有菜单
|
||||
|
||||
**图片持久化(历史 bug 复现点)**
|
||||
5. `Ctrl+V` 粘贴新图 → 出现图片节点
|
||||
6. **正常退出**(托盘右键退出,非强杀)→ 重开 → 图仍在、显示正常
|
||||
7. 从资源管理器拖图进画布 → 退出重开 → 图还在
|
||||
|
||||
**桌面壳(本次新增)**
|
||||
8. 单实例:连续双击两次 → 只有一个窗口,第二次聚焦已有
|
||||
9. 外链:点「项目主页」→ 用系统浏览器打开,应用不变(不能被导航成网页)
|
||||
10. 跑一次生图,完成后弹系统通知
|
||||
|
||||
**插件与 CSP(本次修复)**
|
||||
11. 设置 → 插件:无内置插件;市场能列 7 个;装一个 → 重启后可用
|
||||
12. **鲜艺抠图**:启用后对图片节点执行抠图 → **不应出现 `Failed to fetch`**(3.25.11 回归,3.25.14 已修)
|
||||
13. 若本机有 `XianyiAiRmbg` 监听 `0.0.0.0:30092` → 抠图出透明底;没装则注明跳过
|
||||
|
||||
**外观(本次新增)**
|
||||
14. 设置 → 外观:改画布底色(亮/暗)与主题色 → 立即生效,重启保持
|
||||
15. 亮暗切换时画布底色分别用两套值
|
||||
|
||||
任何一条失败:记录现象 + 截图后停止报告,**不要改代码**。
|
||||
|
||||
## 第六步:交付格式
|
||||
|
||||
```
|
||||
结论:成功 / 失败(卡在第 N 步)
|
||||
版本:3.25.15 commit=<sha>
|
||||
安装包:<路径> <大小> SHA256=<hex>
|
||||
环境:node= rust= VS= WebView2=
|
||||
自测:1✅ … 15✅(失败写 ❌ + 现象)
|
||||
耗时:
|
||||
```
|
||||
|
||||
产物留在本机;**不要**上传 NAS、**不要**写 `latest-windows.json`(我在 Mac 侧做)。
|
||||
|
||||
## 停止条件
|
||||
|
||||
commit 不对 / 环境缺件 / 构建报错一次重试无效 / 自测有失败 / 需要改业务代码 —— 遇到即停,
|
||||
报告「卡在哪一步 + 完整报错 + 已尝试过什么」。
|
||||
@@ -278,7 +278,7 @@ npm run deploy # 部署到正式站
|
||||
IWB_VERIFY_STRICT=1 node scripts/verify-release.js
|
||||
```
|
||||
|
||||
> ⚠️ `npm run deploy` = `verify` + `wrangler pages deploy`,**不含 git push**。
|
||||
> ⚠️ 本项目已转桌面客户端:**不再用 `wrangler pages deploy`**,发版走 `./scripts/publish-update.sh`(macOS)/ `./scripts/publish-windows-update.sh`(Windows)。
|
||||
> 回滚时**不要**把旧代码 push 到 main(会污染历史);用 `checkout` 部署即可,
|
||||
> 部署完 `git checkout main` 回到主干。
|
||||
|
||||
@@ -408,7 +408,7 @@ git checkout refactor-step-3
|
||||
git checkout stable-v3.24.5 && npm ci && npm run verify:ci && npm run deploy
|
||||
|
||||
# 层 4:看部署历史,用 dashboard 或 API 切回旧 deployment
|
||||
npx wrangler pages deployment list --project-name image-workbench-web
|
||||
# 桌面端没有「线上部署列表」:版本清单在 NAS 的 /vol8/web/iwb-download/updates/
|
||||
```
|
||||
|
||||
### 7.2 铁律
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
# Image Workbench 桌面版 · Windows 打包与交付规范
|
||||
|
||||
> 适用:Windows 构建机。本规范只负责「构建 + 自测 + 交付安装包」,**签名与发布在 mac 端完成**(更新私钥不外传)。
|
||||
> 对应版本:v3.25.31 及以后。
|
||||
|
||||
---
|
||||
|
||||
## 0. 一句话流程
|
||||
|
||||
win 构建 setup.exe → win 自测通过 → 把 setup.exe 放到 NAS `_inbox/` → 通知 mac 端 → mac 签名 + 上传 + 登记 → win 用户可更新。
|
||||
|
||||
**win 端永远不要自己签名。** 私钥只在 mac 的 `~/.config/iwb-updater.key`。win 自己签出来的 `.sig` key ID 与项目公钥不配对,客户端会拒绝安装(v3.25.31 发布时已踩过一次,win 放上来的临时 `.sig` 被 mac 端忽略重签)。
|
||||
|
||||
---
|
||||
|
||||
## 1. 环境(一次性,DESKTOP_BUILD.md 第四章)
|
||||
|
||||
```powershell
|
||||
# 有 winget 的话
|
||||
winget install OpenJS.NodeJS.LTS
|
||||
winget install Rustlang.Rustup
|
||||
winget install Microsoft.VisualStudio.2022.BuildTools --override "--quiet --add Microsoft.VisualStudio.Workload.VCTools"
|
||||
winget install Microsoft.EdgeWebView2Runtime
|
||||
|
||||
# 确认 Rust 走 MSVC(不是 GNU)
|
||||
rustup default stable-msvc
|
||||
rustc -V # 期望 >= 1.90
|
||||
```
|
||||
|
||||
要点:
|
||||
- 仓库放**纯英文、无空格**路径(例:`C:\work\image-workbench-desktop`),否则 NSIS 打包易失败。
|
||||
- Windows 10 需装 WebView2 Runtime;Win11 自带。
|
||||
|
||||
---
|
||||
|
||||
## 2. 取代码(必须是最新 main)
|
||||
|
||||
```powershell
|
||||
git fetch gitea
|
||||
git checkout main
|
||||
git reset --hard gitea\main
|
||||
```
|
||||
|
||||
**校验基线**(构建前必查,缺一不可):
|
||||
|
||||
```powershell
|
||||
# 2.1 三处版本号必须完全一致,且 = 目标版本(如 3.25.31)
|
||||
node -e "console.log(require('./package.json').version)"
|
||||
node -e "console.log(require('./src-tauri/tauri.conf.json').version)"
|
||||
node -e "console.log(require('./src-tauri/Cargo.toml').version)"
|
||||
|
||||
# 2.2 确认含 Windows 死锁修复(v3.25.31 的关键改动)
|
||||
# 这 6 个命令必须是 async fn,不是同步 fn
|
||||
findstr /C:"async fn canvas_webview_ensure" src-tauri\src\lib.rs
|
||||
findstr /C:"async fn canvas_webview_bounds" src-tauri\src\lib.rs
|
||||
findstr /C:"async fn canvas_webview_navigate" src-tauri\src\lib.rs
|
||||
findstr /C:"async fn canvas_webview_action" src-tauri\src\lib.rs
|
||||
findstr /C:"async fn canvas_webview_metrics" src-tauri\src\lib.rs
|
||||
findstr /C:"async fn canvas_webview_close_all" src-tauri\src\lib.rs
|
||||
```
|
||||
|
||||
任何一处对不上 → **不要构建**,先找 mac 端确认 main 是否已包含修复。
|
||||
|
||||
---
|
||||
|
||||
## 3. 构建
|
||||
|
||||
```powershell
|
||||
npm ci
|
||||
npm run app:build
|
||||
```
|
||||
|
||||
- 首次会编译约 250 个 crate,2–5 分钟;之后增量很快。
|
||||
- 产物:
|
||||
- `src-tauri\target\release\bundle\nsis\image-workbench_<version>_x64-setup.exe` ← **交付这个**
|
||||
- `src-tauri\target\release\bundle\msi\*.msi`(可选,备用)
|
||||
|
||||
---
|
||||
|
||||
## 4. 产物命名规范(硬性)
|
||||
|
||||
交付文件名必须是:
|
||||
|
||||
```
|
||||
image-workbench_<version>_x64-setup.exe
|
||||
```
|
||||
|
||||
例:`image-workbench_3.25.31_x64-setup.exe`
|
||||
|
||||
- `<version>` 必须与 `package.json` 一致。
|
||||
- 后缀必须是 `-setup.exe`(NSIS),不是 `.msi`。
|
||||
- mac 端 `publish-windows-update.sh` 会按 `package.json` 的版本重命名并签名,所以**文件名里的版本号要和 mac 端 `package.json` 对齐**,否则签名产物与登记名不符。
|
||||
|
||||
记录交付信息(发给 mac 端):
|
||||
|
||||
```powershell
|
||||
# 文件大小 + SHA256(mac 端登记 releases.json 要用)
|
||||
certutil -hashfile src-tauri\target\release\bundle\nsis\image-workbench_3.25.31_x64-setup.exe SHA256
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. 自测矩阵(全过才能交付)
|
||||
|
||||
装 setup.exe 后逐项验证:
|
||||
|
||||
| # | 项目 | 期望 |
|
||||
|---|---|---|
|
||||
| 1 | 主窗口启动 + 渲染 | 正常出界面,能生图(回归 async 改动没破坏通用功能)|
|
||||
| 2 | **画布网页节点**(浏览器插件「网页」节点 / ↗ 放到画布)| 输入 URL 回车 → **能加载、不卡死、不阻塞整个应用**(这是 v3.25.31 要修的,修前一点就没反应)|
|
||||
| 3 | 画布网页节点交互 | 拖动 / 缩放 / 平移 / 框选 → 跟手、不白屏 |
|
||||
| 4 | 节点 ✕ / 切工作区 / 退出应用 | cwv-* 子 webview 正常回收,不留残余进程 |
|
||||
| 5 | 独立浏览器窗口(插件「↗ 独立窗口」)| 能打开(这条本来就跨平台可用)|
|
||||
|
||||
第 2 项不过 → 别交付,把 `_%APPDATA%\com.malongan.imageworkbench\_cwv.log` 发回 mac 端排查。
|
||||
|
||||
已知缺失(不影响交付,但告知用户):Windows 画布网页节点**没有圆角**(直角贴卡片),属 cosmetic,另排 backlog。
|
||||
|
||||
---
|
||||
|
||||
## 6. 交付到 NAS _inbox
|
||||
|
||||
```powershell
|
||||
# 用 scp(或任意 SFTP 客户端)把 setup.exe 放到 mac 端约定的中转目录
|
||||
scp src-tauri\target\release\bundle\nsis\image-workbench_3.25.31_x64-setup.exe `
|
||||
malongan@192.168.100.185:/vol8/web/iwb-download/_inbox/
|
||||
```
|
||||
|
||||
- `_inbox/` 权限 700、公网 403,放这里不会被外部下载。
|
||||
- **只放 setup.exe,不要放 .sig**(签名 mac 端做)。
|
||||
- 放好后通知 mac 端:「v3.25.31 win 包已放 _inbox,sha256=…,size=…」。
|
||||
|
||||
---
|
||||
|
||||
## 7. mac 端会做的事(win 同事了解即可,不用操作)
|
||||
|
||||
mac 端收到通知后执行:
|
||||
|
||||
1. 从 `_inbox` 拉回 setup.exe
|
||||
2. `./scripts/publish-windows-update.sh <setup.exe>` —— 本机正式私钥签名 + 上传 `updates/windows-x86_64/` + 写 `latest-windows.json`
|
||||
3. `node scripts/update-releases.js --platform windows-x86_64 …` 登记网页下载
|
||||
4. `gen-release-page.js` + `gen-site.js` 重生成页面 + scp 元数据
|
||||
5. 合并 windows 条目进 `latest.json`(应用内更新源)
|
||||
6. commit + `RELEASE=1 git push gitea main`
|
||||
|
||||
---
|
||||
|
||||
## 8. 红线(禁止)
|
||||
|
||||
- ❌ win 端自己签名 / 生成 .sig(私钥不外传,签了也不配对)
|
||||
- ❌ 改 `src-tauri\src\lib.rs`、`Cargo.toml`、`tauri.conf.json` 等源码(源码只在 mac 改,win 只构建)
|
||||
- ❌ 在 win 上跑 `cargo fmt` / IDE 保存即格式化(会引入整文件 diff,污染 mac 端同步)
|
||||
- ❌ 把 `target\`、`node_modules\`、`.cargo`、`.msi` 提交进 git
|
||||
- ❌ 用 `git add -A`(只精确提交需要入库的文件)
|
||||
- ❌ 直接 `git push gitea main`(push 需 mac 端 `RELEASE=1` 口令,win 端不 push)
|
||||
|
||||
---
|
||||
|
||||
## 9. 快速核对清单(交付前打勾)
|
||||
|
||||
- [ ] `git reset --hard gitea\main` 到最新
|
||||
- [ ] package.json / tauri.conf / Cargo.toml 三处版本一致 = 目标版本
|
||||
- [ ] lib.rs 里 6 个 `async fn canvas_webview_*` 都在
|
||||
- [ ] `npm ci && npm run app:build` 成功
|
||||
- [ ] 产物名 = `image-workbench_<version>_x64-setup.exe`
|
||||
- [ ] 记下 size + SHA256
|
||||
- [ ] 自测矩阵 5 项全过(尤其第 2 项画布网页不卡死)
|
||||
- [ ] setup.exe 放 `_inbox/`(**不放 .sig**)
|
||||
- [ ] 通知 mac 端:版本 + size + sha256
|
||||
@@ -1,7 +1,7 @@
|
||||
# 现状架构与性能事实基线(image-workbench-web)
|
||||
|
||||
> **本文档是什么**:现状**事实快照**,不是规范。用途:任何性能 / 内存 / 存储相关改动,先对齐这里的现实,避免把已经调好的东西改坏。
|
||||
> 日期 **2026-10-20**(**2026-11-16 复算 · v3.24.85**)| 基线(**最近一次 bump 版本的提交**,不是主干 HEAD)`main = 4be78c0`(线上 `v3.24.85+7df9dc4` —— 线上实际运行提交是 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 = d9e3d84`(线上 `v3.26.40+d9e3d84` —— **未上线**(本地测试中):左右停靠栏配色对齐主色调(新增 `--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`(现 **78** 个模块 / 14,607 行,`sourceModules` 78 项;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. 门禁与环境现状
|
||||
@@ -30,8 +30,8 @@
|
||||
| 项 | 现值 | 依据 |
|
||||
|---|---|---|
|
||||
| 单测基线 | **658 通过 / 0 新增失败 / 2 已知环境差异**(2026-11-12 v3.24.76 实测;660 −2 = 94-5~7 三条钉点换成一条消费方契约) | (A) `npm test` 实测(`tests/iwb-v32-web-test.js`) |
|
||||
| e2e | spec 文件 **59** 个(**55** 个进门禁 + 4 个 dev 探针 `_perf-baseline` / `_plugin-host-probe` / `_probe-drag` / `_probe-tab-switch`) | (A) `tests/` 计数 + `scripts/list-e2e-specs.js` |
|
||||
| e2e 用例数 | **200 条**(2026-11-16 实测:55 个进门禁 spec 内 `test()` 总数)(历史:115 → v3.24.18 **143** → v3.24.19 **147** → v3.24.21 **151** → F2 改名 1 条 **152** → 抓手工具 2 条 **154** → v3.24.44 输出顺序 2 条 **166** → v3.24.47 同步去重 `iwb-sync-dedupe` 1 条 **167** → v3.24.67 **179** → v3.24.68 **183** → v3.24.69 **184** → v3.24.70 **186** → v3.24.74 **187**(新增「拖入 PDF 给提示 + MIME 空 PNG 仍能导入」)→ v3.24.75 **188**(新增「同一张图连粘两次只建一个节点」)→ v3.24.76 **191**(新增 `iwb-tabs-release` 3 条:回首页不降级 / 关标签先保存再关 / 彻底删除连带关标签)→ v3.24.77 **194**(新增 `iwb-lod` 3 条:fit 大画布必须全 LOD / 放大后必须恢复 / 常规画布不 LOD)→ v3.24.78 **196**(`iwb-lod` 3 → 5 条:新增「lite 档必须画出代表图/首行文字」与「缩到 15% 以下才退成 plain」)→ v3.24.82 **197**(新增 `iwb-inherit-text` 1 条:提示词/文本节点显示上游继承文本、改字接管、恢复跟随)→ v3.24.83 **198**(新增 `iwb-plugin-node-coldstart` 1 条:插件脚本晚到 1.2s,存档里的插件节点必须自动切回插件节点体,且类型不被降级成 `plugin`)→ v3.24.79 **196 不变**(测速修复的守门落在 jsdom 单测 `provider-ping-test.js`,e2e 无新增)→ v3.24.85 **200**(新增 `iwb-multi-tab` 2 条:A 页 flush 落盘后 B 页必须靠 rev 轮询看到改动;B 页持锁期间 A 页图库归档必须挂起);早期 99 → 115 的逐版链条见 `docs/history/coverage-baseline-2026-10-27.md`) | (A) `tests/*.spec.js` 计数 + `scripts/list-e2e-specs.js` |
|
||||
| e2e | spec 文件 **58** 个(**52** 个进门禁 + 4 个 dev 探针 `_perf-baseline` / `_plugin-host-probe` / `_probe-drag` / `_probe-tab-switch`) | (A) `tests/` 计数 + `scripts/list-e2e-specs.js` |
|
||||
| e2e 用例数 | **200 条**(2026-11-16 实测:55 个进门禁 spec 内 `test()` 总数;v3.25.15 删除网页版部署面后为 **53** 个进门禁;v3.25.56 节点组库改插件 `grouplib`(宿主侧栏组件删除)后为 **52** 个进门禁 —— `iwb-csp-gate` / `iwb-functions-headers` 随 `_headers`、`functions/` 一起移除)(历史:115 → v3.24.18 **143** → v3.24.19 **147** → v3.24.21 **151** → F2 改名 1 条 **152** → 抓手工具 2 条 **154** → v3.24.44 输出顺序 2 条 **166** → v3.24.47 同步去重 `iwb-sync-dedupe` 1 条 **167** → v3.24.67 **179** → v3.24.68 **183** → v3.24.69 **184** → v3.24.70 **186** → v3.24.74 **187**(新增「拖入 PDF 给提示 + MIME 空 PNG 仍能导入」)→ v3.24.75 **188**(新增「同一张图连粘两次只建一个节点」)→ v3.24.76 **191**(新增 `iwb-tabs-release` 3 条:回首页不降级 / 关标签先保存再关 / 彻底删除连带关标签)→ v3.24.77 **194**(新增 `iwb-lod` 3 条:fit 大画布必须全 LOD / 放大后必须恢复 / 常规画布不 LOD)→ v3.24.78 **196**(`iwb-lod` 3 → 5 条:新增「lite 档必须画出代表图/首行文字」与「缩到 15% 以下才退成 plain」)→ v3.24.82 **197**(新增 `iwb-inherit-text` 1 条:提示词/文本节点显示上游继承文本、改字接管、恢复跟随)→ v3.24.83 **198**(新增 `iwb-plugin-node-coldstart` 1 条:插件脚本晚到 1.2s,存档里的插件节点必须自动切回插件节点体,且类型不被降级成 `plugin`)→ v3.24.79 **196 不变**(测速修复的守门落在 jsdom 单测 `provider-ping-test.js`,e2e 无新增)→ v3.24.85 **200**(新增 `iwb-multi-tab` 2 条:A 页 flush 落盘后 B 页必须靠 rev 轮询看到改动;B 页持锁期间 A 页图库归档必须挂起);早期 99 → 115 的逐版链条见 `docs/history/coverage-baseline-2026-10-27.md`) | (A) `tests/*.spec.js` 计数 + `scripts/list-e2e-specs.js` |
|
||||
| CI | `.github/workflows/verify.yml`:**push(main) + PR(→main) + 手动** 触发,两个 job(`gate` = `verify:ci`;`e2e` = `test:e2e`),只验证不部署 | (A) |
|
||||
| 部署 | `npm run deploy` = `verify` + `wrangler pages deploy dist --branch main`;**内含全量 verify,不得绕过** | (A) `package.json:16` |
|
||||
| 部署环境 | 本机 wrangler 为 OAuth 登录 → **不能设 `CI=true`**(用 `unset CI` + `WRANGLER_SEND_METRICS=false`) | (A) 本轮发布实测 |
|
||||
@@ -58,7 +58,7 @@
|
||||
|---|---|---|
|
||||
| objectURL 缓存 | `W_OBJURL_MAX = 50`(FIFO,驱逐即 revoke) | (A) `app.js:4105` |
|
||||
| blob 引用缓存 | `W_BLOBREF_MAX = 50` | (A) `app.js:4111` |
|
||||
| 显示缩略图缓存 | `DISPLAY_THUMB_CACHE_MAX = 300`;`DISPLAY_THUMB_MAX = 768` | (A) `app.js:4573 / 4572` |
|
||||
| 显示缩略图缓存 | `DISPLAY_THUMB_CACHE_MAX = 300`;`DISPLAY_THUMB_MAX = 640` | (A) `app.js:4573 / 4572` |
|
||||
| 预览派生缓存 | `PREVIEW_CACHE_MAX = 200`(FIFO,**淘汰即 revoke**);`PREVIEW_MAX_EDGE = 1024` | (A) `app.js:4592 / 4591`;淘汰 revoke `4595-4599` |
|
||||
| 图库缩略图缓存 | `outThumbCacheMax = 400` | (A) `app.js:1980` |
|
||||
| Blob 仓库内存 LRU | `DEFAULT_BLOB_CACHE_MAX = 200` | (A) `src/image-blob-store.js:51` |
|
||||
@@ -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` 不引用模块全局)。**78 个模块中 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 耦合面(**68** 项)与 `sourceModules` 顺序(**78** 项);命名例外由第 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 耦合面」(**68** 项)与 `sourceModules` 顺序(**78** 项);新增模块、新增耦合、新增 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 规则三的同一失败模式)。
|
||||
|
||||
@@ -270,6 +270,10 @@
|
||||
**CSP 最小放宽(2026-10-17,为本地服务插件)**:`_headers` 的 `connect-src` 由 `'self' https:` 扩为 `'self' https: http://127.0.0.1:30092 http://localhost:30092`。
|
||||
- **动机**:页面内插件(非浏览器扩展)受页面 CSP 约束;调用本机服务必须放行 loopback。**只放行这一个固定端口**,不放宽到任意 `http:`、不放开脚本域、不引入 `unsafe-eval`。
|
||||
- **边界**:插件若把服务地址改到别的 host/端口会被 CSP 拦(属预期)。页面因此可以向本机 30092 发请求 —— 这是**有意的安全边界调整**,与"插件是可信代码"的模型一致。
|
||||
- **桌面客户端 CSP 的唯一定义处是 `src-tauri/tauri.conf.json` 的 `app.security.csp`**(v3.25.14 补记)。
|
||||
本项目是桌面客户端,`_headers` 属于旧的网页部署、不参与桌面行为,**两者不做一致性约束**。
|
||||
v3.25.11 的「CSP 清理」误判 30092 为遗留端口删掉 ⇒ 桌面版鲜艺抠图插件 `Failed to fetch`。
|
||||
现由 `tests/desktop-csp-loopback-test.js` 钉住(只断言桌面 CSP 的运行时值,避免源码钉点棘轮)。
|
||||
|
||||
**鲜艺抠图插件(2026-10-17 起改为 A2 运行时插件,`dist` 不再内置)**:源码已迁出主仓到独立插件仓(`iwb-plugins`),经 Cloudflare Function `functions/plugins/[[path]].js` + KV(binding `PLUGINS`)**同源运行时加载**(同源 ⇒ CSP 零改动);主包**已不含** `src/plugin-xianyi-cutout.js`。功能:右键命令「抠图:选中节点」→ `POST {apiUrl}/rmbg?crop=`(`application/octet-stream` + 原始字节)→ 结果 PNG 写回为新的参考图节点(`<原名>_cutout.png`)。契约对齐 `iwb-plaus` v3.1.3 的 `background.js`(二进制进 / PNG 字节出;无 token、无 JSON),但**补齐了原版缺失的超时**(`AbortController` + 可配 `timeoutMs`)。设置项:`apiUrl` / `crop` / `timeoutMs`。尚未提供的能力面(若日后需要):插件只读「选中节点」与按 id 取节点图(`canvas` 目前只有 `getNodes` / `listNodeTypes`)。
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
# 原生浮层(子 WebView)的生命周期规范
|
||||
|
||||
> 适用:`src/canvas-webview.js` 以及任何“原生层永远在 DOM 之上”的视图(面板内嵌浏览器、画布网页节点、未来的原生覆盖层)。
|
||||
> 触发这份规范的事故:v3.26.33 —— 切换停靠栏面板后,旧网页画面滞留约 1 秒,盖住新面板。
|
||||
|
||||
## 1. 事故根因(一句话)
|
||||
|
||||
**DOM 锚点被移除后,宿主只安排了“900ms 后 close”,却没有先把原生层隐藏**;原生层始终在 DOM 之上,于是旧画面继续可见,直到 close 生效。
|
||||
|
||||
## 2. 三条硬规则
|
||||
|
||||
### R1 可见性跟着锚点走,当帧生效
|
||||
|
||||
- 锚点从 DOM 消失(组件卸载、面板切换、React 重建)⇒ **立即 park**(`visible:false`),不等任何定时器。
|
||||
- 锚点仍在但落在视口/画布/面板之外 ⇒ 同样 park(现有 tick 已覆盖)。
|
||||
|
||||
### R2 先隐藏,再延迟销毁
|
||||
|
||||
```
|
||||
锚点消失 → ① 立即 park(≤1 帧)
|
||||
→ ② 900ms 宽限后 close(仅在锚点确实没回来时)
|
||||
```
|
||||
|
||||
**禁止**把 ① 也放进定时器里。宽限期只用于避免“节点体短暂重建导致网页重载/丢滚动位置”,不能用于可见性。
|
||||
|
||||
### R3 视图/面板切换要整体 park
|
||||
|
||||
离开画布、切停靠栏面板、隐藏停靠栏、打开全屏遮罩时,都应对**所有**已打开视图调用 `parkAll()`。
|
||||
|
||||
## 3. 新增原生层时的检查清单
|
||||
|
||||
| 检查项 | 说明 |
|
||||
|---|---|
|
||||
| park on detach | 锚点移除路径里有**同步** park(不是 setTimeout 内) |
|
||||
| park on view change | 视图/面板切换时有整体 park |
|
||||
| park on overlay | 全屏遮罩/弹窗打开时 park |
|
||||
| close on unload | `beforeunload` 调 `close_all` |
|
||||
| 恢复不重载 | 宽限期内的重建复用同一视图 |
|
||||
| 坐标裁剪 | 面板/画布 overflow 对原生层无效,必须按矩形裁剪 |
|
||||
|
||||
## 4. 守门测试
|
||||
|
||||
`tests/native-overlay-park-test.js` 静态校验:
|
||||
|
||||
1. `detach()` 在 `setTimeout(... close ...)` **之前**存在 `push(..., false, ...)`;
|
||||
2. `setSuspended(true)` 会调用 `parkAll()`;
|
||||
3. 视图变化(离开 canvas)的 MutationObserver 里调用 `parkAll()`。
|
||||
|
||||
任何一条被破坏,`npm run verify:ci` 直接失败。
|
||||
|
||||
## 5. 自检话术(review 时问自己)
|
||||
|
||||
> “如果此刻锚点被移除,下一帧用户看到的会是什么?”
|
||||
> 答案必须是“立刻看不到”。
|
||||
@@ -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 → 只能中继,无法直连生图。
|
||||
@@ -0,0 +1,151 @@
|
||||
# 插件样式 / 停靠栏 / 图库:2026-11-21 事故复盘与经验
|
||||
|
||||
> 适用版本:v3.25.9x → v3.26.20;涉及插件:promptlib / gallery / grouplib / style-source。
|
||||
> 这份文档记录「为什么会坏、怎么定位、怎么修、回滚要注意什么」,下次遇到同类现象先读它。
|
||||
|
||||
## 1. 事故时间线(浓缩)
|
||||
|
||||
| 版本 | 做了什么 | 结果 |
|
||||
|---|---|---|
|
||||
| 3.25.97 | 提示词封面改用 `{__blob}` 引用 | 编辑里能看到、列表看不到,重启可能丢 |
|
||||
| 3.26.0 | 封面改为内联压缩 dataURL | 封面可见了,`prompts.json` 涨到 1.7MB |
|
||||
| 3.26.5 | 清理死代码 + 删失效 CSS | 误删 `.iwb-lib-cards` 瀑布流列规则(单列化) |
|
||||
| 3.26.6~3.26.9 | 市场缓存、启动层、键盘可达、CSP nonce 兜底 | **插件样式全丢**(提示词库/风格库/图库变裸 HTML) |
|
||||
| 3.26.10 | **整体回滚到 v3.26.5** + promptlib 回 1.4.0 内容(版本号 1.4.6) | 功能恢复,但回滚带回了 1.4.0 的单列 bug |
|
||||
| 3.26.11~3.26.14 | 面板去重、拖宽跟手、底色调平、图库铺满 | 逐步收敛 |
|
||||
| 3.26.15~3.26.20 | 选中态收敛、小地图避让、图库缩略图缓存、插件灰跟随主题 | 稳定 |
|
||||
|
||||
## 2. 五个真实根因(都验证过)
|
||||
|
||||
### 2.1 CSP nonce 会整段丢弃动态 `<style>`
|
||||
|
||||
- 桌面端 CSP 带 nonce;CSP3 下 `unsafe-inline` 被忽略。
|
||||
- 宿主/插件用 `document.createElement('style')` 注入样式时**没有 nonce** → `style.sheet === null`,`document.styleSheets` 里也没有它。
|
||||
- 症状极具迷惑性:插件 DOM 正常、宿主外链 CSS 正常,唯独插件样式全丢(卡片塌成色条、图片按原始尺寸铺满)。
|
||||
- 判定方法:页面里执行
|
||||
```js
|
||||
const s = document.createElement('style'); s.textContent = '.x{color:red}'; document.head.appendChild(s);
|
||||
s.sheet === null // true ⇒ 被 CSP 丢弃
|
||||
```
|
||||
- 修复:给动态 `<style>` 复制页面上已有 nonce:`node.setAttribute('nonce', document.querySelector('style[nonce],link[nonce]').nonce)`。
|
||||
- **注意**:后来 3.26.10 回滚后,用 v3.26.5 那套样式注入在 1.4.7 插件下显示正常——说明**并非所有注入路径都会触发**,与注入时机/上下文有关。结论:不要依赖单一假设,先用上面的判定法验证。
|
||||
|
||||
### 2.2 插件样式注入与激活存在竞态
|
||||
|
||||
- 宿主在 load 时把 CSS 暂存到 `pendingStyles[id]`,**激活插件时**才 `applyStyleFor(id)`。
|
||||
- 若插件已处于激活状态(热更新、切面板、拖拽重载),`applyStyleFor` 不会再执行 → 有 DOM 无样式。
|
||||
- 修复方向(二选一,最终都用了):
|
||||
1. 插件**自带样式**(把 CSS 内联进 bundle,脚本执行时注入);
|
||||
2. 宿主在激活时若 `pendingStyles` 为空,从磁盘补读一次再注入。
|
||||
|
||||
### 2.3 `registerPanel` 只 push 不替换 → 面板图标越拖越多
|
||||
|
||||
- 插件每次重新加载都会注册一次面板,宿主直接 `wPluginPanels.push(entry)`。
|
||||
- 重复 id 进入停靠栏状态 `iwb.dock.v1` 后,**重启也还在**;把右侧那份拖到左侧只会移动其中一份,所以“右边的不会消失”。
|
||||
- 修复(两层都要做,缺一不可):
|
||||
- 注册层:同 `pluginId + id` 先删除旧条目再插入;
|
||||
- 持久层:打开时同侧去重;同一 id 同时出现在左右两侧时只保留左侧;默认面板回填时跳过另一侧已存在的 id。
|
||||
|
||||
### 2.4 图库“要拖一下窗口才显示图片”
|
||||
|
||||
- 图库列宽由测得的面板宽度算出,而 `grid` 自身宽度又由列宽决定(`flex-start` + 内容宽度)。
|
||||
- 于是 `grid.clientWidth` 首帧为 0,之后**永远不会变化** → `ResizeObserver` 不触发 → 一直空白。
|
||||
- 修复:量**会随面板拉伸的外层容器**(`wrap` / 父节点),并加三重兜底:
|
||||
- 挂载后 rAF 连续重试(最多 40 帧);
|
||||
- 可见后(IntersectionObserver 命中)重测重排;
|
||||
- 120/400/900ms 各补一次。
|
||||
- 副作用:重排会重建 DOM,导致缩略图重复请求(每张图请求 N 次、部分一直“加载中”)。**必须配缩略图缓存 + 进行中 Promise 共享**(gallery 1.6.9)。
|
||||
|
||||
### 2.5 封面:引用 vs 内联
|
||||
|
||||
- `{__blob}`(IndexedDB 引用)跨会话/跨解析时序不可靠:编辑弹窗能看到(自己刚写的),列表与重启后丢失。
|
||||
- 内联 dataURL 可靠但撑大 `prompts.json`(33 条 1.7MB)。
|
||||
- 取舍:先用内联(≤448px WebP)保证“任何时候都看得见”,体积问题单独做迁移/文件型 ref 解决——**不要一次改动同时解决“可靠性 + 体积”**。
|
||||
|
||||
## 3. 回滚细节(最容易踩)
|
||||
|
||||
这次最终靠“回滚到 v3.26.5”才恢复,过程中有 4 个坑:
|
||||
|
||||
1. `git checkout v3.26.5 -- .` **只覆盖已存在的文件,不会删除新增文件**。必须补:
|
||||
```bash
|
||||
comm -13 <(git ls-tree -r --name-only v3.26.5 | sort) <(git ls-tree -r --name-only HEAD | sort) | xargs rm -f
|
||||
```
|
||||
2. **插件版本号必须大于线上版本**,否则市场“检查更新”不会降级。做法:内容回退到 1.4.0,但版本号标 **1.4.6**。
|
||||
3. **回滚会带回旧 bug**:1.4.0 清理 CSS 时误删过 `.iwb-lib-cards` 瀑布流规则,回滚后列表变单列。回滚后必须跑一遍 UI 冒烟(列表/图库/面板图标)。
|
||||
4. **回滚也要走完整发布仪式**:CHANGELOG 条目、`docs/standards/architecture-current-state.md` 的 `main = <sha>` 与 `线上 vX.Y.Z+<sha>` 锚点,否则 `verify:ci` 直接挂。
|
||||
|
||||
## 4. 定位工具(可复用)
|
||||
|
||||
宿主写一行探针,外部用 sqlite 读,不依赖 devtools:
|
||||
|
||||
```js
|
||||
// app.js 临时 effect(排查完必须删)
|
||||
localStorage.setItem('iwb_dbg', JSON.stringify({
|
||||
cards: document.querySelectorAll('.iwb-plp-card').length,
|
||||
sheets: document.styleSheets.length,
|
||||
styles: [...document.querySelectorAll('style')].map(n => (n.getAttribute('data-plugin') || 'host') + '|sheet=' + !!n.sheet),
|
||||
computed: (() => { const el = document.querySelector('.iwb-plp-card'); const st = el && getComputedStyle(el)
|
||||
return st ? { display: st.display, aspect: st.aspectRatio, border: st.borderTopWidth, w: el.getBoundingClientRect().width } : null })(),
|
||||
}))
|
||||
```
|
||||
|
||||
```bash
|
||||
python3 - <<'PY'
|
||||
import sqlite3, glob
|
||||
for d in glob.glob('/Users/qiqi/Library/WebKit/com.malongan.imageworkbench/WebsiteData/Default/*/*/LocalStorage/localstorage.sqlite3'):
|
||||
con = sqlite3.connect(d)
|
||||
for k, v in con.execute("select key,value from ItemTable where key='iwb_dbg'"):
|
||||
print(bytes(v).decode('utf-16-le','ignore'))
|
||||
PY
|
||||
```
|
||||
|
||||
关键判据:`sheet=false` ⇒ 样式没参与计算;`computed` 里 `display/aspect/border` 与预期不符 ⇒ 规则未命中;`w` 为 0 或明显大于容器 ⇒ 宽度测量问题。
|
||||
|
||||
## 5. 发布纪律(这次最大的教训)
|
||||
|
||||
| 规则 | 原因 |
|
||||
|---|---|
|
||||
| **一次发布只改一件事** | 3.26.6~3.26.9 把 5 个改动塞进连续 4 个版本,坏掉后无法二分定位,只能整体回滚 |
|
||||
| 改插件样式/布局后**先本机截图自检**,再请用户确认 | 很多问题在截图里一眼可见(单列、色条、白块) |
|
||||
| 改完跑 `npm run verify:ci`(exit 0 才算完) | ratchet / 耦合快照 / 文档锚点 / 插件主题契约都在里面 |
|
||||
| 保底手段是“小步回滚”,不是“继续叠加修复” | 连续 2 次猜错就停手回滚,别再加变量 |
|
||||
|
||||
## 6. 守门与快照清单(新增代码时容易忘)
|
||||
|
||||
- `MAX_APP_JS_LINES`:app.js 行数棘轮,新逻辑放 `src/<domain>-*.js`;确需增长要同步上调并写明理由。
|
||||
- `MAX_WORKBENCH_LINES`:`Workbench()` 行数上限。
|
||||
- 耦合面快照:新增 `window.IWB*` 导出后要 `IWB_WRITE_BOUNDARY_SNAPSHOT=1 node tests/architecture-boundary-guard-test.js`,并同步文档里的“耦合面 N 项”。
|
||||
- 插件主题契约:插件里禁止写死颜色;`color: #fff`(压在图片/渐变上的白字)已列入例外。
|
||||
- 文档锚点:每次 bump 版本后更新 `main = <sha>` 与 `线上 vX.Y.Z+<sha>`。
|
||||
|
||||
## 7. 一句话结论
|
||||
|
||||
> 插件样式出问题,先分清「CSS 没生效」还是「规则写错了」——用 `style.sheet` + `getComputedStyle` 两个判据,一次就能定位;
|
||||
> 发布时一次只动一件事,坏了好回滚;回滚后必须跑 UI 冒烟,因为回滚会带回旧 bug。
|
||||
|
||||
## 8. 第二批问题(3.26.21 – 3.26.27)
|
||||
|
||||
| # | 现象 | 根因 | 修法 |
|
||||
|---|---|---|---|
|
||||
| 1 | 封面单张 300KB,`prompts.json` 1.1MB | WebP 编码不可用时回退成 448px PNG | putCover 增加 JPEG 兜底(webp→jpeg→原图取小);实测 261KB |
|
||||
| 2 | 每次切面板都弹「已压缩 N 张封面」 | 迁移阈值按体积 60KB,JPEG 封面 75KB 永远命中 | 条件改为 PNG 或 >150KB,且只有内容变化才保存/提示 |
|
||||
| 3 | 更新/重启后左右栏摆放被打回默认 | 启动瞬间 panels 为空,整理逻辑删掉未注册 id 并写盘 | 不丢未注册 id;active 在 list 内则保持;面板为空不写盘 |
|
||||
| 4 | 重启后当前面板从提示词库变浏览器 | active 在未加载时被回退成 list[0] | 同上(保持 active) |
|
||||
| 5 | 图库部分格子永远“加载中…” | 重测会重建 DOM,缩略图被重复请求 | 缓存 URL + 共享 Promise + 微任务绘制 + 700ms 坏图快速失败 |
|
||||
| 6 | 插件主题契约“看起来全,实际只查 2 个文件” | 只扫 .js 且只统计含颜色声明的文件 | 扫 .js + .css 全量(8 个),补白字例外 |
|
||||
|
||||
### 8.1 停靠栏持久化的通用教训
|
||||
|
||||
持久化状态 + 异步依赖(插件/面板注册)组合时:
|
||||
|
||||
1. 清理只作用于渲染,不回写存储;未注册的 id 必须保留,等它加载。
|
||||
2. 写盘要有「依赖就绪」守卫,否则会用空集合覆盖用户数据。
|
||||
3. 变更检测用内容比较而不是长度比较——去重(-1) 与回填(+1) 同时发生时长度不变,旧实现会漏检。
|
||||
|
||||
### 8.2 插件市场设计约束(用户裁定)
|
||||
|
||||
- 卡片:淡描边可,不要位移/上浮;只允许颜色变化。
|
||||
- 已安装:名字后徽标;不要绿底、不要绿点。
|
||||
- 按钮:浅色底;已安装只保留移除,不要重装。
|
||||
- 管理页:横线分隔,不要块面卡片与浮动。
|
||||
- 设置页不要限宽,网格随窗口自适应。
|
||||
@@ -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。
|
||||
@@ -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'`;新增语义(如图片、分组)需先在宿主补规则并写测试。
|
||||
- 声明缺失时行为保持旧状(只能中继),不会破坏已有画布。
|
||||
@@ -0,0 +1,68 @@
|
||||
# 插件主题契约(plugin-theme)
|
||||
|
||||
> 版本:v3.25.89 起。宿主与插件的**唯一**配色接口。
|
||||
> 目的:插件不再自己决定颜色,改一处(种子/滑块)全部插件跟着变。
|
||||
|
||||
## 1. 四层语义(插件面板必须分层)
|
||||
|
||||
| 语义 | Token | 亮色默认 | 用在哪 |
|
||||
|---|---|---|---|
|
||||
| 结构层 | `--iwb-dock-bg` | `#E2E4E6` | 停靠栏 / 标签条 / 状态栏(宿主自己的层) |
|
||||
| 插件面板 | `--iwb-plugin-surface` | `#FAFAFB` | 面板根容器(**不要用纯白**) |
|
||||
| 卡片 | `--iwb-plugin-card` | `#FFFFFF` | 面板里的卡片 / 列表项 |
|
||||
| 内嵌 | `--iwb-plugin-inset` | `#F6F7F8` | 输入框底 / 分组底 / 斑马纹 |
|
||||
| 悬停 | `--iwb-plugin-hover` | `#EEF1F4` | 行 / 卡片 hover |
|
||||
|
||||
## 2. 规则
|
||||
|
||||
1. **只用变量**:`--iwb-plugin-*` 或 `--iwb-*`,禁止写死 `#hex` / `rgba()`。
|
||||
(守门测试 `tests/plugin-theme-contract-test.js` 会卡)
|
||||
2. **面板根不画底色**:宿主已给 `--iwb-plugin-surface`;插件根容器只写 `background: var(--iwb-plugin-surface)`。
|
||||
3. **卡片才用 card**:列表项/卡片用 `--iwb-plugin-card`,这样「浅灰底 + 白卡片」的层次才成立。
|
||||
4. **文字层级**:主文字 `--iwb-plugin-text`,次要 `--iwb-plugin-text2`,品牌 `--iwb-plugin-brand`(底色上的字用 `--iwb-plugin-on-brand`,宿主按对比度自动黑/白)。
|
||||
5. **语义色**:错误 `--iwb-plugin-err`、成功 `--iwb-plugin-ok`、警告 `--iwb-plugin-warn`。
|
||||
|
||||
## 3. 作用域重映射(为什么插件不用改代码)
|
||||
|
||||
宿主在插件容器内把旧变量重指到插件层:
|
||||
|
||||
```css
|
||||
.iwb-dock-body, .iwb-node-body .iwb-plugin-body, .iwb-cwv-panel-body {
|
||||
--iwb-panel: var(--iwb-plugin-surface);
|
||||
--iwb-layer2: var(--iwb-plugin-card);
|
||||
--iwb-layer: var(--iwb-plugin-inset);
|
||||
--iwb-hover: var(--iwb-plugin-hover);
|
||||
}
|
||||
```
|
||||
|
||||
所以插件里已有的 `background: var(--iwb-layer2, #fff)` 会自动变成「卡片白」,
|
||||
`var(--iwb-layer, #f5f6f8)` 自动变成「内嵌灰」——**不需要重新打包插件**。
|
||||
|
||||
## 4. 批量调节
|
||||
|
||||
- 外观 → **插件面板 → 底色深浅**(0~30,默认 12)
|
||||
- 该值进入 `theme-tokens.js` 的 `pluginTint`,与 4 个种子一起派生
|
||||
- 改这一个滑块 = 所有插件面板同时变化
|
||||
|
||||
## 5. 新增插件时的自查
|
||||
|
||||
- [ ] 面板根:`background: var(--iwb-plugin-surface)`
|
||||
- [ ] 卡片:`background: var(--iwb-plugin-card)`
|
||||
- [ ] 输入框/内嵌块:`background: var(--iwb-plugin-inset)`
|
||||
- [ ] hover:`background: var(--iwb-plugin-hover)`
|
||||
- [ ] 没有任何 `#` 开头的颜色字面量(`var(--x, #hex)` 的兜底除外)
|
||||
|
||||
## 事故复盘(必读)
|
||||
|
||||
插件“有 DOM 没样式”、面板重复、图库首屏空白这一类问题的完整根因与定位方法见:`docs/standards/plugin-dock-incident-2026-11.md`。
|
||||
|
||||
- 先判断「CSS 没生效」还是「规则写错」:`style.sheet === null` ⇒ 没生效(CSP nonce / 注入时机)。
|
||||
- 插件只引用 `--iwb-plugin-*`,这些 token 由 `theme-tokens` 按主题派生(亮/暗自动切换)。
|
||||
|
||||
## 相关规范
|
||||
|
||||
- 原生浮层(面板内嵌浏览器 / 画布网页节点)的生命周期见 `docs/standards/native-overlay-lifecycle.md`(先 park 再 close,禁止把隐藏放进定时器)。
|
||||
|
||||
## 相关规范
|
||||
|
||||
- 插件节点要直连下游(生图/润色/文本…)需声明 `data.outKind = 'prompt'`,见 `docs/standards/plugin-node-outkind.md`。
|
||||
@@ -0,0 +1,53 @@
|
||||
# promptlib 迭代复盘(2026-11-22)
|
||||
|
||||
> 记录本轮提示词库 1.6.6 → 1.8.8 迭代中遇到的问题、根因与必须遵守的做法。
|
||||
|
||||
## 1. 发布纪律(最大教训)
|
||||
|
||||
- 每次改动同时做三件事:插件 package.json version、入口 version、市场发布(gen-market + 上传 NAS)。
|
||||
- 只在本机手工替换 manifest 不上市场,用户端永远是旧版本。
|
||||
- 发布前必须 node --check;1.8.5 曾因转义把正则写成真实换行,语法损坏。
|
||||
- 上市场后让用户「刷新市场 → 更新」,必要时重启。
|
||||
|
||||
## 2. 拖入画布(不要用原生 HTML5 DnD)
|
||||
|
||||
- 原生 drag&drop 在 WKWebView 吞掉 pointerup,落点节点带焦点残留。
|
||||
- 用 pointerdown → pointermove(>5px) 幽灵 → pointerup → canvas.screenToWorld → canvasWrite.createNode。
|
||||
- 落点 = 鼠标位置 = 节点左上角(对齐风格库),不要居中偏移。
|
||||
- 拖拽期间 body 加 user-select:none。
|
||||
|
||||
## 3. 详情插入:两步放置
|
||||
|
||||
- 点插入后关闭详情 → 跟手灰色小方框(112×112,左上角对齐鼠标)→ 点击画布落点;Esc 取消。
|
||||
|
||||
## 4. 编辑面板
|
||||
|
||||
- 三栏:左 236 固定 / 中自适应 / 右可变(默认 300,190–460),分割条 6px。
|
||||
- 正文 flex:1 到底;变量区独立滚动。
|
||||
- 变量 = 单个输入框,与正文双向同步;重名阻止并回退。
|
||||
- i 按钮展开说明,可多开、各自收起;说明透明背景 + 虚线框。
|
||||
- 正文变量高亮覆盖层与 textarea 的字体/行高/内边距必须一致,否则光标错位;程序改 value 后手动重绘。
|
||||
- 标签用输入框 + 加号生成 chips,可删除。
|
||||
|
||||
## 5. 详情面板
|
||||
|
||||
- 左卡片:封面 contain 完整展示 → 标题 14px → 分割线 → 分组/标签/字数(去底色、带冒号、行间浅线)。
|
||||
- 右卡片:标题 + 正文独立滚动(flex + min-height:0 + overflow:auto)。
|
||||
- 左右卡片等距等高,align-items: stretch,否则右侧没有滚动条。
|
||||
- 右上角编辑 + 关闭;底部插入沿用两步放置;编辑取消回到详情。
|
||||
|
||||
## 6. 节点与输出
|
||||
|
||||
- 变量输入框 placeholder = 说明文字。
|
||||
- 节点保存 tpl(含变量,供编辑)与 text(填值后剔除未填占位,供下游/生图)。
|
||||
- 旧节点 render 时自愈 text。
|
||||
|
||||
## 7. 样式
|
||||
|
||||
- 输入框比底色更亮 + 极浅描边,聚焦纯白 + 淡紫光圈;不要深灰条。
|
||||
- 变量行不要套边框;说明透明 + 虚线。
|
||||
- 插件样式自包含;参考 docs/standards/plugin-development.md 与 plugin-node-drag.md。
|
||||
|
||||
## 8. 版本记录
|
||||
|
||||
1.6.6 封面文件化 / 1.6.7 outKind / 1.6.15 指针拖拽 / 1.6.18–19 落点 / 1.6.20 封面插入 / 1.6.21 两步放置 / 1.6.22–23 放置框 / 1.7.0 三栏编辑 / 1.7.1 视觉精修 / 1.7.2 变量黑粗 / 1.7.3 正文显示 / 1.7.4 名称可拖高 / 1.7.5–1.7.6 封面 contain + 取消回详情 / 1.7.7 字体度量 / 1.7.8 重绘 / 1.7.9 滚动 / 1.8.0 标题下移 + 标签编辑器 / 1.8.1 元信息 / 1.8.2 卡片化 / 1.8.3–1.8.4 布局 / 1.8.5–1.8.6 输出剔除变量 / 1.8.7–1.8.8 细节。
|
||||
@@ -0,0 +1,40 @@
|
||||
// 示例插件(P3 SDK 模板):把本文件放到
|
||||
// <资料目录>/plugins/local/hello-world/plugin.js
|
||||
// 然后在 设置 → 插件 → 打开「开发者模式」,重启应用即可生效。
|
||||
//
|
||||
// 契约:调用 window.IWBPluginHost.register(manifest, factory)
|
||||
// manifest: { id, name, version, apiVersion, capabilities }
|
||||
// factory(ctx): 注册入口;返回 { dispose } 供停用/卸载时清理
|
||||
;(function (global) {
|
||||
'use strict'
|
||||
|
||||
global.IWBPluginHost.register({
|
||||
id: 'hello-world',
|
||||
name: '示例插件',
|
||||
version: '0.1.0',
|
||||
apiVersion: 1,
|
||||
capabilities: ['nodeActions', 'canvas'],
|
||||
}, function (ctx) {
|
||||
// 读取当前画布节点(只读)
|
||||
function countNodes () {
|
||||
try {
|
||||
return (ctx.canvas && typeof ctx.canvas.getNodes === 'function') ? ctx.canvas.getNodes().length : 0
|
||||
} catch (e) { return -1 }
|
||||
}
|
||||
|
||||
// 注册一个节点右键动作:只在参考图/输出节点上出现
|
||||
ctx.nodeActions.register({
|
||||
id: 'hello-world-count',
|
||||
title: '示例:数一下节点',
|
||||
icon: 'sparkles',
|
||||
appliesTo: function (node) { return !!(node && (node.type === 'ref' || node.type === 'out')) },
|
||||
run: function () {
|
||||
// 注意:桌面端不要用 alert/confirm(会阻塞 WebView),用 console 或宿主提供的 UI
|
||||
console.log('[hello-world] 当前画布节点数:' + countNodes())
|
||||
return true
|
||||
},
|
||||
})
|
||||
|
||||
return { dispose: function () { /* 清理定时器/监听器 */ } }
|
||||
})
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
@@ -1,108 +0,0 @@
|
||||
// Cloudflare Pages Function:**第一方**图片代理(同源 /api/img)。
|
||||
// 目的:豆包(火山 TOS)等图床**不返回 CORS 头**,浏览器无法 fetch ⇒ 下载、缩略图归档、
|
||||
// 本地原图备份全部拿不到字节。经本站代理转发后由本站给出 CORS 头,前端即可正常读取。
|
||||
// 用法:GET /api/img?url=<encodeURIComponent(https 图片地址)>
|
||||
//
|
||||
// 安全边界(H2 加固):
|
||||
// - 仅接受**同源**调用:若请求带 Origin 头,其 host 必须与本站一致。
|
||||
// - 仅 https、仅允许常见图片/对象存储域名(避免成为开放代理/SSRF),仅透传 image/* 响应。
|
||||
// - **手动跟随重定向**:每一跳都对目标 host 重新做白名单校验(原实现 redirect:'follow' 只校验初始
|
||||
// host,可被 302 逃逸到任意主机),并限制跳数。
|
||||
// - **响应大小上限**:先看 content-length,超限即拒;无 content-length 时按流裁剪(防超大响应耗尽配额)。
|
||||
// - 不再返回 Access-Control-Allow-Origin: *(同源调用本就不需要 CORS)。
|
||||
export function onRequest(context) {
|
||||
return handle(context.request)
|
||||
}
|
||||
|
||||
const ALLOW_HOSTS = [
|
||||
/(^|\.)volces\.com$/i, // 火山引擎 / TOS(豆包 Seedream 图床)
|
||||
/(^|\.)aliyuncs\.com$/i, // 阿里云 OSS(tuzi 文档示例图床)
|
||||
/(^|\.)myqcloud\.com$/i, // 腾讯云 COS
|
||||
/(^|\.)qiniucdn\.com$/i,
|
||||
/(^|\.)cloudfront\.net$/i,
|
||||
/(^|\.)googleusercontent\.com$/i,
|
||||
/(^|\.)openai\.org$/i,
|
||||
/(^|\.)oaistatic\.com$/i,
|
||||
/(^|\.)blob\.core\.windows\.net$/i,
|
||||
]
|
||||
const MAX_BYTES = 25 * 1024 * 1024 // 单张图片上限 25MB(生成图远小于此;防超大响应)
|
||||
const MAX_REDIRECTS = 3
|
||||
|
||||
// 安全头(2026-10-20 加,H1):Cloudflare Pages 的 `_headers` **不作用于 Functions 响应**
|
||||
// (https://developers.cloudflare.com/pages/configuration/headers/)⇒ 静态资源有 CSP/nosniff,
|
||||
// 而本函数(及 plugins 函数)原本**一个安全头都没有**。这不是可利用漏洞(每个响应都显式
|
||||
// 设了 Content-Type),但属于纵深防御缺口:将来若有端点返回用户影响的内容且漏设 Content-Type,
|
||||
// 浏览器会自行嗅探类型 ⇒ 可能演变成 XSS。故在**每个** Response 显式补齐 nosniff + Referrer-Policy。
|
||||
const SECURITY_HEADERS = {
|
||||
'X-Content-Type-Options': 'nosniff',
|
||||
'Referrer-Policy': 'no-referrer',
|
||||
}
|
||||
|
||||
function hdr() {
|
||||
return Object.assign({ 'Content-Type': 'text/plain; charset=utf-8' }, SECURITY_HEADERS)
|
||||
}
|
||||
function plain(msg, status) {
|
||||
return new Response(msg, { status, headers: hdr() })
|
||||
}
|
||||
function sameOrigin(request) {
|
||||
const origin = request.headers.get('Origin')
|
||||
if (!origin || origin === 'null') return true
|
||||
try { return new URL(origin).host === new URL(request.url).host } catch (e) { return false }
|
||||
}
|
||||
function hostAllowed(u) {
|
||||
return ALLOW_HOSTS.some((re) => re.test(u.hostname))
|
||||
}
|
||||
function capStream(stream, max) {
|
||||
let seen = 0
|
||||
return stream.pipeThrough(new TransformStream({
|
||||
transform(chunk, controller) {
|
||||
seen += chunk && chunk.byteLength ? chunk.byteLength : 0
|
||||
if (seen > max) { controller.error(new Error('response too large')); return }
|
||||
controller.enqueue(chunk)
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
async function handle(request) {
|
||||
if (request.method === 'OPTIONS') return new Response(null, { status: 204, headers: hdr() })
|
||||
if (request.method !== 'GET') return plain('仅支持 GET', 405)
|
||||
if (!sameOrigin(request)) return plain('仅允许同源调用', 403)
|
||||
let target
|
||||
try {
|
||||
const raw = String(new URL(request.url).searchParams.get('url') || '')
|
||||
target = new URL(raw)
|
||||
} catch (e) { return plain('缺少或非法的 url 参数', 400) }
|
||||
if (target.protocol !== 'https:') return plain('仅支持 https 图片地址', 400)
|
||||
if (!hostAllowed(target)) return plain('该图床未在允许列表中:' + target.hostname, 403)
|
||||
try {
|
||||
// 手动跟随重定向:每一跳都对 host 重新校验,逃逸即拒。
|
||||
let upstream = null
|
||||
for (let hop = 0; hop <= MAX_REDIRECTS; hop++) {
|
||||
upstream = await fetch(target.toString(), { headers: { Accept: 'image/*' }, redirect: 'manual' })
|
||||
const status = upstream.status
|
||||
const isRedirect = status >= 300 && status < 400
|
||||
if (!isRedirect) break
|
||||
const location = upstream.headers.get('Location')
|
||||
if (!location) return plain('上游重定向缺少 Location', 502)
|
||||
if (hop === MAX_REDIRECTS) return plain('重定向次数过多', 508)
|
||||
let next
|
||||
try { next = new URL(location, target) } catch (e) { return plain('上游重定向地址非法', 502) }
|
||||
if (next.protocol !== 'https:') return plain('重定向目标非 https', 403)
|
||||
if (!hostAllowed(next)) return plain('重定向目标未在允许列表中:' + next.hostname, 403)
|
||||
target = next
|
||||
}
|
||||
if (!upstream || !upstream.ok) return plain('上游返回 ' + (upstream ? upstream.status : '0'), 502)
|
||||
const ct = String(upstream.headers.get('content-type') || '')
|
||||
if (ct && ct.toLowerCase().indexOf('image/') !== 0) return plain('上游不是图片(' + ct + ')', 415)
|
||||
const len = Number(upstream.headers.get('content-length'))
|
||||
if (Number.isFinite(len) && len > MAX_BYTES) return plain('图片过大(超过 ' + MAX_BYTES + ' 字节)', 413)
|
||||
const headers = new Headers()
|
||||
headers.set('Content-Type', ct || 'image/png')
|
||||
headers.set('Cache-Control', 'private, max-age=600')
|
||||
for (const [k, v] of Object.entries(SECURITY_HEADERS)) headers.set(k, v)
|
||||
const body = upstream.body && !(Number.isFinite(len) && len <= MAX_BYTES) ? capStream(upstream.body, MAX_BYTES) : upstream.body
|
||||
return new Response(body, { status: 200, headers })
|
||||
} catch (e) {
|
||||
return plain('代理失败:' + ((e && e.message) || 'unknown'), 502)
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
// /plugins/* → 从 KV(binding: PLUGINS)以**同源**方式提供插件文件。
|
||||
// 同源脚本本就被页面 CSP(script-src 'self')允许 ⇒ 无需放宽 CSP、无需 unsafe-eval、无需重新部署 app.js。
|
||||
// KV 键约定:plugins/index.json(清单)+ plugins/<file>(每个插件一个文件)。
|
||||
//
|
||||
// 缓存策略(按 basename 分流):
|
||||
// - plugin-<id>.<hash12>.js(内容寻址,发布脚本生成)→ public, max-age=31536000, immutable(字节永不变 ⇒ 可永久缓存)
|
||||
// - 其他 .js(历史遗留未哈希文件)→ no-cache + ETag(安全网:绝不许被永久缓存)
|
||||
// - .json(清单)→ no-cache + ETag;if-none-match 命中 → 304 空 body
|
||||
// - 其他扩展名 / 404 / 500 → no-store
|
||||
// ETag 为 (value, basename) 的确定性纯函数:FNV-1a 32bit(同步、廉价),hex 后加双引号。
|
||||
|
||||
const JS_CT = 'application/javascript; charset=utf-8'
|
||||
const JSON_CT = 'application/json; charset=utf-8'
|
||||
|
||||
// 安全头(2026-10-20 加,H1):Cloudflare Pages 的 `_headers` **不作用于 Functions 响应**
|
||||
// (https://developers.cloudflare.com/pages/configuration/headers/)⇒ 静态资源有 CSP/nosniff,
|
||||
// 而本函数原本**一个安全头都没有**。插件字节虽同源且有 SRI 校验,但缺 nosniff 意味着
|
||||
// 万一将来 KV 里的内容类型异常,浏览器可能自行嗅探 ⇒ 补齐纵深防御。
|
||||
const SECURITY_HEADERS = { 'x-content-type-options': 'nosniff', 'referrer-policy': 'no-referrer' }
|
||||
|
||||
const ERROR_HEADERS = Object.assign({ 'content-type': JSON_CT, 'cache-control': 'no-store' }, SECURITY_HEADERS)
|
||||
const NO_STORE_HEADERS = Object.assign({ 'content-type': JS_CT, 'cache-control': 'no-store' }, SECURITY_HEADERS)
|
||||
|
||||
const IMMUTABLE_JS_RE = /^plugin-[a-z0-9-]+\.[0-9a-f]{12}\.js$/
|
||||
|
||||
// FNV-1a 32-bit(对 UTF-16 code unit 序列):同步、确定、够用于 ETag 指纹
|
||||
const fnv1a32 = (s) => {
|
||||
let h = 0x811c9dc5
|
||||
for (let i = 0; i < s.length; i++) {
|
||||
h ^= s.charCodeAt(i)
|
||||
h = Math.imul(h, 0x01000193)
|
||||
}
|
||||
return (h >>> 0).toString(16).padStart(8, '0')
|
||||
}
|
||||
|
||||
const etagOf = (value, base) => '"' + fnv1a32(base + '\n' + value) + '"'
|
||||
|
||||
export async function onRequestGet(context) {
|
||||
const { params, env } = context
|
||||
const parts = Array.isArray(params.path) ? params.path : [params.path].filter(Boolean)
|
||||
const tail = parts.join('/') || 'index.json'
|
||||
const key = 'plugins/' + tail
|
||||
const base = tail.slice(tail.lastIndexOf('/') + 1)
|
||||
|
||||
if (!env || !env.PLUGINS) {
|
||||
return new Response(JSON.stringify({ error: 'PLUGINS KV 未绑定' }), { status: 500, headers: ERROR_HEADERS })
|
||||
}
|
||||
|
||||
const value = await env.PLUGINS.get(key)
|
||||
if (value === null) return new Response('not found', { status: 404, headers: Object.assign({ 'cache-control': 'no-store' }, SECURITY_HEADERS) })
|
||||
|
||||
// A) 内容寻址的插件 JS:内容变 ⇒ 文件名变 ⇒ 可 immutable 永久缓存
|
||||
if (IMMUTABLE_JS_RE.test(base)) {
|
||||
return new Response(value, {
|
||||
headers: Object.assign({ 'content-type': JS_CT, 'cache-control': 'public, max-age=31536000, immutable' }, SECURITY_HEADERS),
|
||||
})
|
||||
}
|
||||
|
||||
// B) 未哈希 .js 与 .json(清单):no-cache + ETag,每次回源校验,命中即 304
|
||||
if (base.endsWith('.js') || base.endsWith('.json')) {
|
||||
const etag = etagOf(value, base)
|
||||
const headers = Object.assign({
|
||||
'content-type': base.endsWith('.json') ? JSON_CT : JS_CT,
|
||||
'cache-control': 'no-cache',
|
||||
etag,
|
||||
}, SECURITY_HEADERS)
|
||||
const inm = context.request && context.request.headers && context.request.headers.get('if-none-match')
|
||||
if (inm === etag) return new Response(null, { status: 304, headers })
|
||||
return new Response(value, { headers })
|
||||
}
|
||||
|
||||
// 其他扩展名:保持 no-store
|
||||
return new Response(value, { headers: NO_STORE_HEADERS })
|
||||
}
|
||||
@@ -7,8 +7,14 @@
|
||||
"": {
|
||||
"name": "image-workbench-web",
|
||||
"version": "3.24.85",
|
||||
"dependencies": {
|
||||
"@tauri-apps/plugin-dialog": "^2.8.4",
|
||||
"@tauri-apps/plugin-fs": "^2.7.1",
|
||||
"@tauri-apps/plugin-http": "^2.9.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.64.1",
|
||||
"@tauri-apps/cli": "^2.12.4",
|
||||
"esbuild": "0.28.2",
|
||||
"eslint": "^10.13.0",
|
||||
"globals": "^17.13.0",
|
||||
@@ -825,6 +831,275 @@
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/api": {
|
||||
"version": "2.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-2.12.4.tgz",
|
||||
"integrity": "sha512-pVmfis+4zT8H0Qhp3xPZx9Ju7kpzvA6rr/PSJPyuwfvucTQ8sVt61NYU9KMkK703UFlYadFmjKA4HhybOtN0gg==",
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/tauri"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli": {
|
||||
"version": "2.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli/-/cli-2.12.4.tgz",
|
||||
"integrity": "sha512-JI9bHfudSRJikGOrjbXEm6RjzzvmKuLc+JixB1NE8hNzQkNlCCIC3pTES3uypkR9lxHrsbxzcnSwhI2IxBQphw==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"bin": {
|
||||
"tauri": "tauri.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/tauri"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@tauri-apps/cli-darwin-arm64": "2.12.4",
|
||||
"@tauri-apps/cli-darwin-x64": "2.12.4",
|
||||
"@tauri-apps/cli-linux-arm-gnueabihf": "2.12.4",
|
||||
"@tauri-apps/cli-linux-arm64-gnu": "2.12.4",
|
||||
"@tauri-apps/cli-linux-arm64-musl": "2.12.4",
|
||||
"@tauri-apps/cli-linux-riscv64-gnu": "2.12.4",
|
||||
"@tauri-apps/cli-linux-x64-gnu": "2.12.4",
|
||||
"@tauri-apps/cli-linux-x64-musl": "2.12.4",
|
||||
"@tauri-apps/cli-win32-arm64-msvc": "2.12.4",
|
||||
"@tauri-apps/cli-win32-ia32-msvc": "2.12.4",
|
||||
"@tauri-apps/cli-win32-x64-msvc": "2.12.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-darwin-arm64": {
|
||||
"version": "2.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-darwin-arm64/-/cli-darwin-arm64-2.12.4.tgz",
|
||||
"integrity": "sha512-OxqKSckIkoJ6vX2AjifIJpTasFC0Hbdoo7gEiCmAjauABO3U8m2MRsLWe+QTiBwDx1mIrvgA+rvI7tvDnbnHVg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-darwin-x64": {
|
||||
"version": "2.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-darwin-x64/-/cli-darwin-x64-2.12.4.tgz",
|
||||
"integrity": "sha512-fz76/77wMMJOaaUN6n3CybRG0P/MTEjjqYk81mGPyhi9m6Ue5T+LWBnJP/AkPooNatBPI2vtulGqomyMJ44lCQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-linux-arm-gnueabihf": {
|
||||
"version": "2.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm-gnueabihf/-/cli-linux-arm-gnueabihf-2.12.4.tgz",
|
||||
"integrity": "sha512-K0w8Bof6Lt8QKLAYhRy0yy36ZH5iA/35VuSOvnxyjvCUZ+A3JKsUTlALviH/sVgAlisaPzzmeJSH8XOn4Q2HBA==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-linux-arm64-gnu": {
|
||||
"version": "2.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm64-gnu/-/cli-linux-arm64-gnu-2.12.4.tgz",
|
||||
"integrity": "sha512-j5rOnjmRUwWrm1oosf0zBYl4D+fqydgUROFCk0hvKZxvbTT8SOERes0QB7rBV/XWNy+kM6pCKzb3oSm2sRglzg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-linux-arm64-musl": {
|
||||
"version": "2.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm64-musl/-/cli-linux-arm64-musl-2.12.4.tgz",
|
||||
"integrity": "sha512-aOue3Fy6Jb7+oWcfAVUsVHfeTybSCt2CZoU06aO4jv4d2Ks/KnaTPwMAK3CLEduGOvBLY1lbBBrIyomqLLH5Sg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-linux-riscv64-gnu": {
|
||||
"version": "2.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-riscv64-gnu/-/cli-linux-riscv64-gnu-2.12.4.tgz",
|
||||
"integrity": "sha512-Fx6GShY/RvST+t6LMlTHAwd66+1tEaAAGrnU7cysVfaiRP1BKng5Vl6rVmO6rSLOA1Sp1dRzNYM4f0OWQGb7qA==",
|
||||
"cpu": [
|
||||
"riscv64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-linux-x64-gnu": {
|
||||
"version": "2.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-x64-gnu/-/cli-linux-x64-gnu-2.12.4.tgz",
|
||||
"integrity": "sha512-tNzZSa79Z1nRpHxEpQ38lsAFpKlFlYvoXzjTV+lRRn/zSf3wrdUC3wnLcq2XEadchPu4ttK0zivhYzr+XGD19Q==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-linux-x64-musl": {
|
||||
"version": "2.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-x64-musl/-/cli-linux-x64-musl-2.12.4.tgz",
|
||||
"integrity": "sha512-jmZ1pr0xEqUhuEusWtt9Yt+GF6lCnGHUmIL+KIknpbjK/XQ2qkhDBhaxK/JMHM2A8dAacVXCxXJk2EXpwhQUfA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-win32-arm64-msvc": {
|
||||
"version": "2.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-arm64-msvc/-/cli-win32-arm64-msvc-2.12.4.tgz",
|
||||
"integrity": "sha512-fGo8pgEHZxdSYgZ/J98m1usJ7NHKmKbq7k6uT0x1rpOq6Bg2YVzzpaAblWk710f5LHYBJIL5QIFS5IrD+4gmTg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-win32-ia32-msvc": {
|
||||
"version": "2.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-ia32-msvc/-/cli-win32-ia32-msvc-2.12.4.tgz",
|
||||
"integrity": "sha512-ezl8sQIcjYsye3TUnTH5VcWmWzccZASlQm7hlZt0dYyj1XD0qpVW47u2xYVrIKui0F8uQv/7QGZixdWiClBsbg==",
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-win32-x64-msvc": {
|
||||
"version": "2.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-x64-msvc/-/cli-win32-x64-msvc-2.12.4.tgz",
|
||||
"integrity": "sha512-DJhDeCqjLDNMWYFy7ZS8cfeAHX2RK0RbQMLiA3bMVVkXRDJ4NBYiHriGqsUhsr9iG41aTb+dJGkFPmPw1gWwVw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-dialog": {
|
||||
"version": "2.8.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-dialog/-/plugin-dialog-2.8.4.tgz",
|
||||
"integrity": "sha512-+6ZOiXenOaxXwb8qCbBPdT2jX2cFPaVVHGIskrpmJLpmWj+qKRTD6X/z9x7hTdSQn7NedcoXCkWGej4a7dC4lw==",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.12.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-fs": {
|
||||
"version": "2.7.1",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-fs/-/plugin-fs-2.7.1.tgz",
|
||||
"integrity": "sha512-4TBVjpi/q8PuNzjpkAc2iBGXMTLjOrAyfTiiOL8ORaJCZJRG3tjzmQ4sqs2CMG75FvLyRkOkERfP7AyY4iBNwQ==",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.12.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-http": {
|
||||
"version": "2.9.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-http/-/plugin-http-2.9.0.tgz",
|
||||
"integrity": "sha512-q3HTsbyFk3E9H4slJr+egd6KdRF2Fn4BoZFGI3ZHb7PBT9snlsOOlZC5L4Q1+AlDDd6OHdf/KTM6DNUJ0RNMEQ==",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.12.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/esrecurse": {
|
||||
"version": "4.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/esrecurse/-/esrecurse-4.3.1.tgz",
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
{
|
||||
"name": "image-workbench-web",
|
||||
"private": true,
|
||||
"version": "3.24.85",
|
||||
"version": "3.26.40",
|
||||
"description": "Browser-based node canvas image workbench",
|
||||
"scripts": {
|
||||
"build": "node scripts/build.js",
|
||||
"build": "node scripts/build.js && node scripts/copy-plugins.js",
|
||||
"tauri": "tauri",
|
||||
"app:dev": "tauri dev",
|
||||
"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 && node tests/iwb-v32-web-test.js",
|
||||
"test:unit": "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-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/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/architecture-boundary-guard-test.js && node tests/plugin-host-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/ui-groups-sidebar-test.js && node tests/ui-lib-sidebar-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/functions-api-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/ui-workbench-hooks-test.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/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",
|
||||
@@ -17,21 +20,26 @@
|
||||
"test:e2e:local": "node scripts/serve-test.js",
|
||||
"verify:ci": "npm run build && node --check app.js && node --check dist/app.js && node scripts/check-dist.js && npm run lint && npm run typecheck && npm run test:unit && npm test && npm run test:facts",
|
||||
"verify": "npm run verify:ci && npm run test:e2e",
|
||||
"deploy": "npm run verify && npx --yes wrangler@4 pages deploy dist --project-name image-workbench-web --branch main",
|
||||
"deploy:test": "npm run verify && npx --yes wrangler@4 pages deploy dist --project-name image-workbench-web --branch test",
|
||||
"verify:release": "node scripts/verify-release.js",
|
||||
"coverage:e2e": "node scripts/coverage-e2e.js",
|
||||
"sync:facts": "node scripts/sync-facts.js",
|
||||
"sync:facts:write": "node scripts/sync-facts.js --write",
|
||||
"typecheck": "tsc -p tsconfig.json"
|
||||
"typecheck": "tsc -p tsconfig.json",
|
||||
"release:desktop": "bash scripts/release.sh"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.64.1",
|
||||
"@tauri-apps/cli": "^2.12.4",
|
||||
"esbuild": "0.28.2",
|
||||
"eslint": "^10.13.0",
|
||||
"globals": "^17.13.0",
|
||||
"jsdom": "^24.1.3",
|
||||
"playwright": "^1.64.1",
|
||||
"typescript": "^5.9.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tauri-apps/plugin-dialog": "^2.8.4",
|
||||
"@tauri-apps/plugin-fs": "^2.7.1",
|
||||
"@tauri-apps/plugin-http": "^2.9.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,554 @@
|
||||
// iwb-plugin: 图库 —— 右栏「图库」面板(宿主只提供 ctx.gallery 数据能力,界面全部在插件里)
|
||||
//
|
||||
// 依赖客户端能力:gallery(list/thumb/preview/download/insert/remove)+ panels。
|
||||
// 数据:插件自己的配置(插入尺寸/图幅/时间筛选)存 ctx.data,不塞 settings。
|
||||
// 视觉:复用宿主的 .iwb-gal-* / .iwb-history-* 类名(宿主 style.css 保留这些样式)。
|
||||
;(function (global) {
|
||||
'use strict'
|
||||
if (!global.IWBPluginHost) return
|
||||
|
||||
var PANEL_ID = 'gallery-panel'
|
||||
var DEF = { insertK: '1k', tile: 110, range: '' }
|
||||
// v1.6.2:图幅=**实际显示宽度上限**(此前只当「算列数」用,独列时会被拉到撑满面板,选「小」也很大)
|
||||
// v1.6.3:新增「极小」64px 档(面板窄时想一行看更多图)
|
||||
var TILES = [[64, '极小'], [80, '小'], [110, '中'], [150, '大'], [200, '特大']]
|
||||
var KS = [['orig', '原图'], ['2k', '2K'], ['1k', '1K'], ['0.5k', '0.5K']]
|
||||
var RANGES = [['', '全部'], ['today', '今天'], ['7d', '7 天'], ['30d', '30 天']]
|
||||
|
||||
function el (tag, attrs) {
|
||||
var node = document.createElement(tag)
|
||||
if (attrs) {
|
||||
for (var k in attrs) {
|
||||
if (!Object.prototype.hasOwnProperty.call(attrs, k)) continue
|
||||
var v = attrs[k]
|
||||
if (v === null || v === undefined) continue
|
||||
if (k === 'class') node.className = v
|
||||
else if (k === 'text') node.textContent = v
|
||||
else if (k === 'style') node.setAttribute('style', v)
|
||||
else node.setAttribute(k, v)
|
||||
}
|
||||
}
|
||||
// 变参子节点(第三位起),支持数组与字符串
|
||||
for (var i = 2; i < arguments.length; i++) append(node, arguments[i])
|
||||
return node
|
||||
}
|
||||
function append (node, v) {
|
||||
if (v === null || v === undefined || v === false) return
|
||||
if (Array.isArray(v)) { for (var i = 0; i < v.length; i++) append(node, v[i]); return }
|
||||
node.appendChild(typeof v === 'string' ? document.createTextNode(v) : v)
|
||||
}
|
||||
function clear (node) { while (node.firstChild) node.removeChild(node.firstChild) }
|
||||
|
||||
// v1.4.1:底栏按钮改用图标(窄栏里「刷新/设置」会被挤成竖排两行)
|
||||
var SVG_NS = 'http://www.w3.org/2000/svg'
|
||||
function iconBtn (label, build, title) {
|
||||
var b = el('button', { class: 'iwb-btn iwb-btn-sm iwb-gal-icobtn', title: title || label, 'aria-label': label })
|
||||
var svg = document.createElementNS(SVG_NS, 'svg')
|
||||
svg.setAttribute('viewBox', '0 0 16 16')
|
||||
svg.setAttribute('width', '14')
|
||||
svg.setAttribute('height', '14')
|
||||
svg.setAttribute('fill', 'none')
|
||||
svg.setAttribute('stroke', 'currentColor')
|
||||
svg.setAttribute('stroke-width', '1.5')
|
||||
svg.setAttribute('stroke-linecap', 'round')
|
||||
svg.setAttribute('stroke-linejoin', 'round')
|
||||
svg.setAttribute('aria-hidden', 'true')
|
||||
build(svg)
|
||||
b.appendChild(svg)
|
||||
return b
|
||||
}
|
||||
function svgPath (svg, d) {
|
||||
var p = document.createElementNS(SVG_NS, 'path')
|
||||
p.setAttribute('d', d)
|
||||
svg.appendChild(p)
|
||||
return p
|
||||
}
|
||||
function sel (options, value) {
|
||||
var s = el('select', { class: 'iwb-input iwb-select-compact' })
|
||||
for (var i = 0; i < options.length; i++) {
|
||||
var o = el('option', { value: String(options[i][0]), text: options[i][1] })
|
||||
if (String(options[i][0]) === String(value)) o.selected = true
|
||||
s.appendChild(o)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
function mount (host, ctx) {
|
||||
clear(host)
|
||||
host.classList.add('iwb-plugin-node-body')
|
||||
host.style.minHeight = '0'
|
||||
|
||||
var cfg = Object.assign({}, DEF)
|
||||
var items = []
|
||||
var thumbCache = {}
|
||||
var thumbPending = {} // 进行中的缩略图请求(v1.6.9)
|
||||
var total = 0
|
||||
var limit = 100
|
||||
var picked = {}
|
||||
var gridW = 320
|
||||
var raf = 0
|
||||
var failed = {} // v1.6.0:缩略图仍失败的 name 集合(据此显示「N 张失败」+ 全部重试)
|
||||
|
||||
var head = el('div', { class: 'iwb-gal-head' })
|
||||
var actions = el('div', { class: 'iwb-gal-actions' })
|
||||
head.appendChild(actions)
|
||||
|
||||
var grid = el('div', { class: 'iwb-history-grid' })
|
||||
var empty = el('div', { class: 'iwb-hint', text: '暂无图片 · 运行生图后会出现在这里' })
|
||||
var more = el('div', { class: 'iwb-history-more' })
|
||||
// v1.1.0:底部横栏 —— 左边张数/已选,右边三个设定(右对齐)
|
||||
var countEl = el('span', { class: 'iwb-gal-count', text: '0 / 0 张' })
|
||||
var pickedEl = el('span', { class: 'iwb-gal-sel', text: '' })
|
||||
var statusEl = el('span', { class: 'iwb-gal-status', text: '' })
|
||||
var failEl = el('span', { class: 'iwb-gal-fail', text: '' })
|
||||
failEl.style.display = 'none'
|
||||
failEl.addEventListener('click', function () { retryAll() })
|
||||
var refreshBtn = iconBtn('刷新', function (svg) {
|
||||
svgPath(svg, 'M13.2 6.4A5.4 5.4 0 1 0 13.4 9.4')
|
||||
svgPath(svg, 'M13.2 2.6v3.8H9.4')
|
||||
}, '刷新:重新向宿主拉取图库(图床恢复/外部改动后点这里)')
|
||||
refreshBtn.addEventListener('click', function () { load(true) })
|
||||
// v1.4.0:三个下拉不再占用前台(窄栏放不下、也显乱)——收进「设置」浮层,点按钮才展开。
|
||||
var setBtn = iconBtn('设置', function (svg) {
|
||||
var c1 = document.createElementNS(SVG_NS, 'circle')
|
||||
c1.setAttribute('cx', '8'); c1.setAttribute('cy', '8'); c1.setAttribute('r', '4.2')
|
||||
svg.appendChild(c1)
|
||||
var c2 = document.createElementNS(SVG_NS, 'circle')
|
||||
c2.setAttribute('cx', '8'); c2.setAttribute('cy', '8'); c2.setAttribute('r', '1.6')
|
||||
svg.appendChild(c2)
|
||||
for (var i = 0; i < 8; i++) {
|
||||
var a = i * Math.PI / 4
|
||||
var x1 = (8 + Math.cos(a) * 4.2).toFixed(2)
|
||||
var y1 = (8 + Math.sin(a) * 4.2).toFixed(2)
|
||||
var x2 = (8 + Math.cos(a) * 5.6).toFixed(2)
|
||||
var y2 = (8 + Math.sin(a) * 5.6).toFixed(2)
|
||||
svgPath(svg, 'M' + x1 + ' ' + y1 + 'L' + x2 + ' ' + y2)
|
||||
}
|
||||
}, '图库设置:插入尺寸 / 图幅 / 时间范围')
|
||||
setBtn.classList.add('iwb-gal-setbtn')
|
||||
setBtn.setAttribute('aria-expanded', 'false')
|
||||
var settings = el('div', { class: 'iwb-gal-settings', role: 'dialog', 'aria-label': '图库设置' })
|
||||
settings.style.display = 'none'
|
||||
// v1.4.2:刷新与设置同放右侧工具组(此前刷新在左侧信息区,空间不足时会向右溢出、压住设置图标)
|
||||
var tools = el('div', { class: 'iwb-gal-tools' }, refreshBtn, setBtn)
|
||||
var foot = el('div', { class: 'iwb-gal-foot' },
|
||||
el('div', { class: 'iwb-gal-foot-left' }, countEl, pickedEl, failEl, statusEl), tools)
|
||||
var wrap = el('div', { class: 'iwb-history-embedded' }, [head, grid, more, empty, foot, settings])
|
||||
|
||||
function setOpen (open) {
|
||||
settings.style.display = open ? '' : 'none'
|
||||
setBtn.setAttribute('aria-expanded', open ? 'true' : 'false')
|
||||
setBtn.classList.toggle('iwb-gal-setbtn-on', !!open)
|
||||
if (open) document.addEventListener('pointerdown', onDocDown, true)
|
||||
else document.removeEventListener('pointerdown', onDocDown, true)
|
||||
}
|
||||
function onDocDown (e) {
|
||||
if (settings.contains(e.target) || setBtn.contains(e.target)) return
|
||||
setOpen(false)
|
||||
}
|
||||
setBtn.addEventListener('click', function (e) { e.stopPropagation(); setOpen(settings.style.display === 'none') })
|
||||
host.appendChild(wrap)
|
||||
|
||||
function count () { return Object.keys(picked).length }
|
||||
|
||||
// ---- v1.6.0 右键菜单:单张操作(插入 / 下载 / 预览 / 复制文件名 / 删除)----
|
||||
var menuEl = null
|
||||
function closeMenu () {
|
||||
if (menuEl && menuEl.parentNode) menuEl.parentNode.removeChild(menuEl)
|
||||
menuEl = null
|
||||
document.removeEventListener('pointerdown', onMenuDown, true)
|
||||
document.removeEventListener('keydown', onMenuKey, true)
|
||||
}
|
||||
function onMenuDown (e) { if (menuEl && !menuEl.contains(e.target)) closeMenu() }
|
||||
function onMenuKey (e) { if (e.key === 'Escape') closeMenu() }
|
||||
function openMenu (e, it) {
|
||||
e.preventDefault(); e.stopPropagation()
|
||||
closeMenu()
|
||||
var menu = el('div', { class: 'iwb-ctxmenu iwb-gal-menu', style: 'left:' + e.clientX + 'px;top:' + e.clientY + 'px' })
|
||||
menu.appendChild(el('div', { class: 'iwb-ctx-title', text: it.name }))
|
||||
function item (label, fn) {
|
||||
var b = el('button', { class: 'iwb-ctx-item', text: label })
|
||||
b.addEventListener('click', function (ev) { ev.stopPropagation(); closeMenu(); fn() })
|
||||
menu.appendChild(b)
|
||||
}
|
||||
item('插入画布', function () {
|
||||
Promise.resolve(ctx.gallery.insert([it.name], { insertK: cfg.insertK || '1k' }))
|
||||
.then(function () { setStatus('已插入:' + it.name) })
|
||||
.catch(function () { setStatus('插入失败') })
|
||||
})
|
||||
item('下载', function () { doDownload([it.name]) })
|
||||
item('预览大图', function () { try { ctx.gallery.preview(it.name) } catch (err) { /* ignore */ } })
|
||||
item('复制文件名', function () {
|
||||
try {
|
||||
var p = global.navigator && global.navigator.clipboard && global.navigator.clipboard.writeText(it.name)
|
||||
if (p && p.then) p.then(function () { setStatus('已复制文件名') }).catch(function () { setStatus('复制失败(剪贴板不可用)') })
|
||||
else setStatus('复制失败(剪贴板不可用)')
|
||||
} catch (err) { setStatus('复制失败(剪贴板不可用)') }
|
||||
})
|
||||
item('删除这张', function () {
|
||||
var C = global.IWBUIConfirm
|
||||
var ask = (C && C.askOrNative) ? C.askOrNative('删除「' + it.name + '」?不可恢复。', { title: '删除图片', okText: '删除' }) : Promise.resolve(global.confirm('删除「' + it.name + '」?'))
|
||||
ask.then(function (ok) {
|
||||
if (!ok) return
|
||||
items = items.filter(function (x) { return x.name !== it.name })
|
||||
total = Math.max(0, total - 1)
|
||||
delete picked[it.name]
|
||||
render()
|
||||
Promise.resolve(ctx.gallery.remove([it.name])).then(function () { setTimeout(load, 250) }).catch(function () {})
|
||||
}).catch(function () {})
|
||||
})
|
||||
document.body.appendChild(menu)
|
||||
menuEl = menu
|
||||
setTimeout(function () {
|
||||
document.addEventListener('pointerdown', onMenuDown, true)
|
||||
document.addEventListener('keydown', onMenuKey, true)
|
||||
}, 0)
|
||||
}
|
||||
|
||||
// ---- v1.6.0 多选拖入画布:宿主 drop 只认单张,这里在捕获阶段接管整批 ----
|
||||
// 仅当 dataTransfer 带 application/x-iwb-gallery-batch 时生效,其余拖放行为完全不变。
|
||||
function onDocDrop (e) {
|
||||
var raw = ''
|
||||
try { raw = (e.dataTransfer && e.dataTransfer.getData('application/x-iwb-gallery-batch')) || '' } catch (err) { return }
|
||||
if (!raw) return
|
||||
var names = []
|
||||
try { names = JSON.parse(raw) } catch (err) { return }
|
||||
if (!names || names.length < 2) return
|
||||
e.preventDefault(); e.stopPropagation()
|
||||
Promise.resolve(ctx.gallery.insert(names, { insertK: cfg.insertK || '1k' })).then(function (r) {
|
||||
if (r && r.ok === false) { setStatus('批量插入失败'); return }
|
||||
setStatus('已插入 ' + names.length + ' 张')
|
||||
}).catch(function () { setStatus('批量插入失败') })
|
||||
}
|
||||
document.addEventListener('drop', onDocDrop, true)
|
||||
// v1.6.0:失败计数集中在底栏;点它 = 全部重试(整墙重挂,重新向宿主取缩略图)
|
||||
function updateFail () {
|
||||
var n = Object.keys(failed).length
|
||||
if (!n) { failEl.style.display = 'none'; failEl.textContent = ''; return }
|
||||
failEl.style.display = ''
|
||||
failEl.textContent = n + ' 张失败 · 重试'
|
||||
failEl.title = '点击重新加载这 ' + n + ' 张的缩略图'
|
||||
}
|
||||
function retryAll () {
|
||||
failed = {}
|
||||
updateFail()
|
||||
setStatus('重试中…')
|
||||
render()
|
||||
}
|
||||
function pickedNames () { return Object.keys(picked) }
|
||||
|
||||
function renderHead () {
|
||||
clear(actions)
|
||||
countEl.textContent = items.length + ' / ' + total + ' 张'
|
||||
pickedEl.textContent = count() ? ('已选 ' + count()) : ''
|
||||
var n = count()
|
||||
function btn (label, title0, fn, need, danger) {
|
||||
var b = el('button', { class: 'iwb-btn iwb-btn-sm' + (danger ? ' iwb-btn-danger' : '') + (need && !n ? ' iwb-gal-off' : ''), text: label, title: need && !n ? '先选中图片' : title0 })
|
||||
b.addEventListener('click', function () { if (need && !n) return; fn() })
|
||||
return b
|
||||
}
|
||||
actions.appendChild(btn('全选', '全选当前筛选结果', function () { for (var i = 0; i < items.length; i++) picked[items[i].name] = 1; render() }))
|
||||
actions.appendChild(btn('反选', '反选当前筛选结果', function () { for (var i = 0; i < items.length; i++) { var k = items[i].name; if (picked[k]) delete picked[k]; else picked[k] = 1 } render() }))
|
||||
actions.appendChild(btn('插入', '把选中的图片插入画布(尺寸按「设置 → 插入尺寸」)', function () {
|
||||
var names = pickedNames()
|
||||
var k = cfg.insertK || '1k'
|
||||
Promise.resolve(ctx.gallery.insert(names, { insertK: k })).then(function (r) {
|
||||
if (r && r.ok === false) { setStatus('插入失败'); return }
|
||||
setStatus('已插入 ' + names.length + ' 张(' + String(k).toUpperCase() + ')')
|
||||
}).catch(function () { setStatus('插入失败') })
|
||||
}, true))
|
||||
actions.appendChild(btn('下载', '下载选中的图片', function () { doDownload(pickedNames()) }, true))
|
||||
actions.appendChild(btn('删除', '删除选中的图片(不可恢复)', function () {
|
||||
var C = global.IWBUIConfirm
|
||||
var ask = C && C.askOrNative ? C.askOrNative('删除选中的 ' + n + ' 张图片?不可恢复。', { title: '删除图片', okText: '删除' }) : Promise.resolve(global.confirm('删除选中的 ' + n + ' 张图片?'))
|
||||
var names = pickedNames()
|
||||
ask.then(function (ok) {
|
||||
if (!ok) return
|
||||
// 先本地摘掉,避免删除后还渲染一格「图片已丢失」;随后再向宿主重拉(等它删完+刷新)
|
||||
items = items.filter(function (x) { return names.indexOf(x.name) < 0 })
|
||||
total = Math.max(0, total - names.length)
|
||||
picked = {}
|
||||
render()
|
||||
return Promise.resolve(ctx.gallery.remove(names)).then(function () {
|
||||
setTimeout(load, 250)
|
||||
})
|
||||
}).catch(function () {})
|
||||
}, true, true))
|
||||
|
||||
}
|
||||
|
||||
// 设置浮层内容只建一次(不随每次 render 重建,避免下拉被重置)
|
||||
function buildSettings () {
|
||||
clear(settings)
|
||||
settings.appendChild(el('div', { class: 'iwb-gal-settings-title', text: '图库设置' }))
|
||||
function row (key, options, label, hint) {
|
||||
var s = sel(options, cfg[key])
|
||||
s.title = hint || label
|
||||
s.setAttribute('aria-label', label)
|
||||
s.addEventListener('change', function () {
|
||||
cfg[key] = s.value
|
||||
saveCfg()
|
||||
if (key === 'range') { limit = 100; load() } else if (key === 'tile') render()
|
||||
})
|
||||
return el('label', { class: 'iwb-gal-setrow' }, el('span', { class: 'iwb-gal-setlabel', text: label }), s)
|
||||
}
|
||||
settings.appendChild(row('insertK', KS, '插入尺寸', '插入画布时的图片尺寸'))
|
||||
settings.appendChild(row('tile', TILES, '图幅', '图库图片显示宽度'))
|
||||
settings.appendChild(row('range', RANGES, '时间范围', '按生成时间筛选'))
|
||||
}
|
||||
|
||||
function renderGrid () {
|
||||
clear(grid)
|
||||
var gap = 6
|
||||
var tileW = Math.max(40, Number(cfg.tile) || 110)
|
||||
var n = Math.max(1, Math.floor((gridW + gap) / (tileW + gap)))
|
||||
// v1.6.6:列宽 = 均分宽度(铺满面板),图幅只决定「列数」——
|
||||
// 以前 min(图幅, 均分) 会留下右侧空白,看起来像没补齐。
|
||||
var colW = Math.max(40, (gridW - gap * (n - 1)) / n)
|
||||
var cols = []
|
||||
var heights = []
|
||||
for (var c = 0; c < n; c++) { cols.push([]); heights.push(0) }
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var it = items[i]
|
||||
var ratio = (it.w && it.h) ? (it.h / it.w) : 1
|
||||
var min = 0
|
||||
for (var j = 1; j < n; j++) if (heights[j] < heights[min]) min = j
|
||||
cols[min].push(it)
|
||||
heights[min] += colW * ratio + gap
|
||||
}
|
||||
for (var ci = 0; ci < cols.length; ci++) {
|
||||
var col = el('div', { class: 'iwb-history-col', style: 'width:' + Math.round(colW) + 'px;flex:0 0 auto' })
|
||||
for (var k = 0; k < cols[ci].length; k++) col.appendChild(itemNode(cols[ci][k]))
|
||||
grid.appendChild(col)
|
||||
}
|
||||
empty.style.display = items.length ? 'none' : ''
|
||||
clear(more)
|
||||
if (total > items.length) {
|
||||
var b = el('button', { class: 'iwb-btn iwb-btn-sm', text: '显示更多(' + (total - items.length) + ' 张)' })
|
||||
b.addEventListener('click', function () { limit += 100; load() })
|
||||
more.appendChild(b)
|
||||
}
|
||||
}
|
||||
|
||||
function itemNode (it) {
|
||||
var on = !!picked[it.name]
|
||||
var box = el('div', { class: 'iwb-history-item' + (count() ? ' iwb-history-managed' : '') + (on ? ' iwb-history-selected' : '') })
|
||||
// 缩略图是**异步**的(ctx.gallery.thumb 返回 Promise):先占位,拿到地址再挂 img。
|
||||
// v1.2.0:加载失败自动重试 2 次(图片还没落盘/临时不可读),仍失败才显示可点击重试的占位。
|
||||
box.title = it.name + '(单击单选 · Shift+单击多选 · 双击放大 · 拖到画布=参考图节点)'
|
||||
var holder = el('div', { class: 'iwb-history-missing', text: '加载中…' })
|
||||
box.appendChild(holder)
|
||||
var tries = 0
|
||||
function fail (text) {
|
||||
tries = 999
|
||||
holder.textContent = text || '缩略图加载失败(点击重试)'
|
||||
holder.style.cursor = 'pointer'
|
||||
holder.onclick = function () { failed[it.name] = 1; tries = 0; boot() }
|
||||
failed[it.name] = 1
|
||||
updateFail()
|
||||
}
|
||||
function boot () {
|
||||
if (tries >= 999) return
|
||||
holder.style.cursor = ''
|
||||
holder.onclick = null
|
||||
holder.textContent = '加载中…'
|
||||
// v1.6.9:缩略图地址按名字缓存,且进行中的请求共享同一 Promise ——
|
||||
// 重排/重测会重建 DOM,不共享就会对同一张图重复取 N 次。
|
||||
var key = it.name
|
||||
if (thumbCache[key]) { var u0 = thumbCache[key]; Promise.resolve().then(function () { paint(u0) }).catch(function () { /* ignore */ }); return }
|
||||
if (!thumbPending[key]) {
|
||||
thumbPending[key] = Promise.resolve(ctx.gallery.thumb(key)).then(function (url) {
|
||||
if (url && typeof url === 'string') thumbCache[key] = url
|
||||
delete thumbPending[key]
|
||||
return url
|
||||
}, function (e) { delete thumbPending[key]; throw e })
|
||||
}
|
||||
thumbPending[key].then(paint).catch(function () { fail('缩略图加载失败(点击重试)') })
|
||||
}
|
||||
function paint (url) {
|
||||
if (!url || typeof url !== 'string') { fail('图片已丢失'); return }
|
||||
if (!box.isConnected) return
|
||||
var img = el('img', { src: url, alt: '', loading: 'lazy', draggable: 'true' })
|
||||
if (it.w && it.h) img.setAttribute('style', 'aspect-ratio:' + it.w + ' / ' + it.h)
|
||||
img.addEventListener('load', function () {
|
||||
// naturalWidth=0 说明拿到的是坏图(空 data URL / 截断文件):按失败处理,别留白块
|
||||
if (!img.naturalWidth) { tries++; if (tries <= 2) { setTimeout(boot, 400 * tries); return } if (img.parentNode === box) box.replaceChild(holder, img); fail('缩略图加载失败(点击重试)'); return }
|
||||
if (holder.parentNode === box) box.replaceChild(img, holder)
|
||||
if (failed[it.name]) { delete failed[it.name]; updateFail() }
|
||||
})
|
||||
img.addEventListener('error', function () {
|
||||
tries++
|
||||
if (tries <= 2) { setTimeout(boot, 400 * tries); return }
|
||||
if (img.parentNode === box) box.replaceChild(holder, img)
|
||||
fail('缩略图加载失败(点击重试)')
|
||||
})
|
||||
img.addEventListener('click', function (e) { pick(it.name, !!(e && e.shiftKey)) })
|
||||
img.addEventListener('dblclick', function () { ctx.gallery.preview(it.name) })
|
||||
img.addEventListener('dragstart', function (e) {
|
||||
try {
|
||||
var names = (picked[it.name] && count() > 1) ? pickedNames() : [it.name]
|
||||
e.dataTransfer.setData('application/x-iwb-localref', names[0])
|
||||
e.dataTransfer.setData('application/x-iwb-gallery-orig', names[0])
|
||||
// 多选:额外带一批名字,由本插件在 document 捕获阶段接管(宿主 drop 只认单张)
|
||||
if (names.length > 1) {
|
||||
e.dataTransfer.setData('application/x-iwb-gallery-batch', JSON.stringify(names))
|
||||
setStatus('拖动 ' + names.length + ' 张')
|
||||
}
|
||||
e.dataTransfer.effectAllowed = 'copy'
|
||||
} catch (err) { /* ignore */ }
|
||||
})
|
||||
img.style.display = 'none'
|
||||
box.appendChild(img)
|
||||
// v1.6.9:坏图/超时兜底 —— 某些坏字节既不触发 load 也不触发 error,700ms 后直接判定失败(可点击重试)
|
||||
setTimeout(function () {
|
||||
try {
|
||||
if (!img.parentNode) return
|
||||
if (img.naturalWidth > 0) return
|
||||
if (img.parentNode === box) box.replaceChild(holder, img)
|
||||
fail('缩略图加载失败(点击重试)')
|
||||
} catch (e) { /* ignore */ }
|
||||
}, 700)
|
||||
// 加载成功后再替换占位(避免破图标 + 长 title 占满格子)
|
||||
if (img.complete && img.naturalWidth > 0) { img.style.display = ''; if (holder.parentNode === box) box.replaceChild(img, holder) }
|
||||
else if (img.complete && !img.naturalWidth) { /* 立即失败(坏图)*/ tries++; if (tries <= 2) setTimeout(boot, 400 * tries); else { if (img.parentNode === box) box.replaceChild(holder, img); fail('缩略图加载失败(点击重试)') } }
|
||||
}
|
||||
boot()
|
||||
box.addEventListener('contextmenu', function (e) { openMenu(e, it) })
|
||||
var acts = el('div', { class: 'iwb-history-actions' })
|
||||
function act (label, title, fn) {
|
||||
var b = el('button', { class: 'iwb-btn iwb-btn-sm', text: label, title: title })
|
||||
b.addEventListener('click', function (e) { e.stopPropagation(); fn() })
|
||||
return b
|
||||
}
|
||||
acts.appendChild(act('插入', '插入到画布(参考图节点)', function () { ctx.gallery.insert([it.name]).catch(function () {}) }))
|
||||
acts.appendChild(act('下载', '下载到本地', function () { doDownload([it.name]) }))
|
||||
box.appendChild(acts)
|
||||
return box
|
||||
}
|
||||
|
||||
var statusTimer = 0
|
||||
function setStatus (text) {
|
||||
statusEl.textContent = text || ''
|
||||
clearTimeout(statusTimer)
|
||||
if (text) statusTimer = setTimeout(function () { statusEl.textContent = '' }, 4000)
|
||||
}
|
||||
function doDownload (names) {
|
||||
setStatus('下载中…')
|
||||
return Promise.resolve(ctx.gallery.download(names)).then(function (r) {
|
||||
var failed = (r && r.failed) || []
|
||||
var ok = (r && r.count) || 0
|
||||
if (failed.length) setStatus(failed.length + ' 张下载失败,可再点一次重试')
|
||||
else setStatus(ok ? ('已下载 ' + ok + ' 张') : '没有可下载的图片')
|
||||
}).catch(function () { setStatus('下载失败,可再点一次重试') })
|
||||
}
|
||||
|
||||
function pick (name, shift) {
|
||||
if (shift) { if (picked[name]) delete picked[name]; else picked[name] = 1 } else { picked = {}; picked[name] = 1 }
|
||||
render()
|
||||
}
|
||||
|
||||
function render () { renderHead(); renderGrid() }
|
||||
|
||||
function load (force) {
|
||||
if (force) setStatus('刷新中…')
|
||||
return Promise.resolve(ctx.gallery.list({ range: cfg.range, limit: limit })).then(function (r) {
|
||||
items = (r && r.items) || []
|
||||
total = (r && r.total) || items.length
|
||||
lastLoadAt = Date.now()
|
||||
failed = {}
|
||||
render()
|
||||
}).catch(function () { items = []; total = 0; render() })
|
||||
}
|
||||
|
||||
var saveTimer = 0
|
||||
function saveCfg () {
|
||||
clearTimeout(saveTimer)
|
||||
saveTimer = setTimeout(function () {
|
||||
try { var p = ctx.data && ctx.data.patch({ cfg: cfg }); if (p && p.catch) p.catch(function () {}) } catch (e) { /* 配置存不下不影响使用 */ }
|
||||
}, 200)
|
||||
}
|
||||
|
||||
// 宽度测量:列数只由「面板宽 / 图幅」决定
|
||||
// v1.6.5:面板刚挂载时 grid 宽度可能是 0,而 grid 宽度又取决于列宽 → RO 不会触发,图库一直空白。
|
||||
function availableW () {
|
||||
// v1.6.6:优先量「会随面板拉伸的外层容器」,而不是 grid 自身
|
||||
// (grid 现在是 flex-start + 内容宽度,面板变宽它不会变宽 → RO 不触发 → 列数永不补齐)
|
||||
var w = wrap ? wrap.clientWidth : 0
|
||||
if (!w && wrap && wrap.parentNode) w = wrap.parentNode.clientWidth
|
||||
if (!w) w = grid.clientWidth
|
||||
return w || 0
|
||||
}
|
||||
function measure () {
|
||||
var w = availableW()
|
||||
if (w > 0 && Math.abs(w - gridW) > 1) { gridW = w; renderGrid() }
|
||||
}
|
||||
var ro = typeof ResizeObserver === 'function' ? new ResizeObserver(function () { measure() }) : null
|
||||
if (ro) { if (wrap) ro.observe(wrap); if (wrap && wrap.parentNode) ro.observe(wrap.parentNode); ro.observe(grid) }
|
||||
measure()
|
||||
var tries = 0
|
||||
function retry () {
|
||||
if (gridW > 0 || tries++ > 40) { if (gridW <= 0) { gridW = Math.max(160, Number(cfg.tile) || 110) * 2; renderGrid() } return }
|
||||
measure()
|
||||
if (gridW <= 0) global.requestAnimationFrame(retry)
|
||||
}
|
||||
global.requestAnimationFrame(retry)
|
||||
// v1.6.7:再补几次延时重测(停靠栏展开动画、首帧布局未完成时能在 1s 内自愈)
|
||||
;[120, 400, 900].forEach(function (ms) { setTimeout(function () { try { measure(); if (gridW > 0) renderGrid() } catch (e) { /* ignore */ } }, ms) })
|
||||
|
||||
// v1.3.0:自动恢复 —— 面板重新可见(切回 tab / 窗口聚焦 / 后台回来)且距上次拉取 >5s 时重拉一次,
|
||||
// 这样图床恢复、后台补图后不必手动刷新;同时保留底部「刷新」按钮做即时重试。
|
||||
var lastLoadAt = 0
|
||||
var autoRefresh = function () {
|
||||
if (Date.now() - lastLoadAt < 5000) return
|
||||
load()
|
||||
}
|
||||
try {
|
||||
if (typeof IntersectionObserver === 'function') {
|
||||
var io = new IntersectionObserver(function (entries) {
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
if (entries[i].isIntersecting) {
|
||||
// v1.6.7:面板真正可见后再量一次宽度并重排(首帧可能还是 0 宽)
|
||||
try { measure(); renderGrid() } catch (e) { /* ignore */ }
|
||||
autoRefresh()
|
||||
}
|
||||
}
|
||||
}, { threshold: 0.15 })
|
||||
io.observe(wrap)
|
||||
}
|
||||
document.addEventListener('visibilitychange', function () { if (!document.hidden) autoRefresh() })
|
||||
window.addEventListener('focus', autoRefresh)
|
||||
} catch (e) { /* 环境不支持则只保留手动刷新 */ }
|
||||
|
||||
// 先读配置,再拉列表
|
||||
Promise.resolve(ctx.data && ctx.data.read ? ctx.data.read() : {}).then(function (d) {
|
||||
if (d && d.cfg) cfg = Object.assign({}, DEF, d.cfg)
|
||||
buildSettings() // 设置浮层里的下拉要反映读到的配置
|
||||
return load()
|
||||
}).catch(function () { buildSettings(); load() })
|
||||
|
||||
return function dispose () {
|
||||
if (ro) { try { ro.disconnect() } catch (e) { /* ignore */ } }
|
||||
try { document.removeEventListener('pointerdown', onMenuDown, true) } catch (e) { /* ignore */ }
|
||||
try { document.removeEventListener('keydown', onMenuKey, true) } catch (e) { /* ignore */ }
|
||||
try { document.removeEventListener('drop', onDocDrop, true) } catch (e) { /* ignore */ }
|
||||
closeMenu()
|
||||
}
|
||||
}
|
||||
|
||||
global.IWBPluginHost.register({
|
||||
id: 'gallery',
|
||||
name: '图库',
|
||||
version: '1.6.9',
|
||||
apiVersion: 1,
|
||||
capabilities: ['panels', 'gallery'],
|
||||
data: { schemaVersion: 1, maxBytes: 65536 },
|
||||
}, function (ctx) {
|
||||
ctx.ui.registerPanel({
|
||||
id: PANEL_ID,
|
||||
title: '图库',
|
||||
icon: 'ref',
|
||||
mount: function (host) { return mount(host, ctx) },
|
||||
})
|
||||
return {}
|
||||
})
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"id": "gallery",
|
||||
"name": "图库",
|
||||
"version": "1.6.9",
|
||||
"apiVersion": 1,
|
||||
"main": "main.js",
|
||||
"style": "styles.css",
|
||||
"description": "右栏图片墙:筛选/多选/双击预览/插入画布/下载/删除(数据由客户端提供)",
|
||||
"author": "official",
|
||||
"icon": "🖼️",
|
||||
"tags": [
|
||||
"资源",
|
||||
"图库"
|
||||
],
|
||||
"files": {
|
||||
"main.js": "26c7e64b3a0021c6b9514dfb84d4d2580276698222b4791cfa99f22ead66ff52",
|
||||
"styles.css": "9d5b4ab1343761e51ef0c479cab96a94d3d6eaa27f0fdb500bff789ec81d70e0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/* 图库插件样式(v1.5.0)
|
||||
* 为什么放插件里:宿主 style.css 只在客户端发版时更新,而这里是「设置浮层/图标按钮/紧凑间距」这类
|
||||
* 高频视觉调整——随插件更新即可生效,不必重发桌面端。选择器均带 .iwb-gal-* / .iwb-history-* 前缀,
|
||||
* 且比宿主同名规则更具体(.iwb-gal-foot .iwb-gal-icobtn),宿主旧样式不会盖回来。
|
||||
*/
|
||||
|
||||
/* ---- 面板留白:边缘收小,避免窄栏里浪费空间 ---- */
|
||||
.iwb-history-embedded { padding: 6px 6px 4px; gap: 6px; }
|
||||
.iwb-history-embedded .iwb-history-grid { gap: 6px; padding: 0 0 2px; justify-content: flex-start; }
|
||||
/* 列宽由插件按「图幅」写死(style width),这里禁用宿主的 flex:1 拉伸 */
|
||||
.iwb-history-embedded .iwb-history-col { flex: 0 0 auto; gap: 6px; }
|
||||
|
||||
/* ---- 顶栏 ---- */
|
||||
.iwb-gal-head { display: flex; align-items: center; gap: 6px; min-height: 0; }
|
||||
.iwb-gal-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
|
||||
.iwb-gal-actions .iwb-btn-sm { padding: 2px 7px; }
|
||||
|
||||
/* ---- 底栏:左信息 / 右工具组 ---- */
|
||||
.iwb-gal-foot {
|
||||
display: flex; align-items: center; justify-content: space-between; gap: 6px;
|
||||
min-width: 0; padding-top: 6px; border-top: 1px solid var(--iwb-border);
|
||||
}
|
||||
.iwb-gal-foot-left { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 0 1 auto; overflow: hidden; }
|
||||
.iwb-gal-count { font-size: 11px; color: var(--iwb-text2); white-space: nowrap; }
|
||||
.iwb-gal-sel { font-size: 11px; color: var(--iwb-brand); white-space: nowrap; }
|
||||
.iwb-gal-status { font-size: 11px; color: var(--iwb-text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; max-width: none; }
|
||||
.iwb-gal-tools { display: flex; align-items: center; gap: 0; flex: 0 0 auto; margin-left: auto; }
|
||||
|
||||
/* ---- 图标按钮:无外框、无底色,只在悬停时给一点反馈 ---- */
|
||||
.iwb-gal-foot .iwb-gal-icobtn,
|
||||
.iwb-gal-foot .iwb-gal-icobtn:hover,
|
||||
.iwb-gal-foot .iwb-gal-icobtn:active {
|
||||
width: 20px; height: 20px; min-width: 20px; padding: 0; box-sizing: border-box;
|
||||
display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
|
||||
border: 0; box-shadow: none; background: transparent; border-radius: 4px;
|
||||
color: var(--iwb-text2); line-height: 1; transform: none;
|
||||
}
|
||||
.iwb-gal-foot .iwb-gal-icobtn svg { display: block; pointer-events: none; }
|
||||
.iwb-gal-foot .iwb-gal-icobtn:hover { background: var(--iwb-layer2); color: var(--iwb-text); }
|
||||
.iwb-gal-foot .iwb-gal-icobtn:focus-visible { outline: 2px solid color-mix(in srgb, var(--iwb-brand) 60%, transparent); outline-offset: 1px; }
|
||||
.iwb-gal-setbtn-on { color: var(--iwb-brand); background: var(--iwb-layer2); }
|
||||
|
||||
/* ---- 设置浮层(三个下拉不占前台) ---- */
|
||||
.iwb-gal-settings {
|
||||
position: absolute; right: 8px; bottom: 34px; z-index: 30; width: 176px; max-width: calc(100% - 16px);
|
||||
display: flex; flex-direction: column; gap: 8px; padding: 9px 10px;
|
||||
background: var(--iwb-layer); border: 1px solid var(--iwb-border); border-radius: 8px;
|
||||
box-shadow: 0 6px 18px rgba(0, 0, 0, .14);
|
||||
}
|
||||
.iwb-gal-settings-title { font-size: 11px; font-weight: 600; color: var(--iwb-text2); }
|
||||
.iwb-gal-setrow { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--iwb-text2); }
|
||||
.iwb-gal-setlabel { flex: 0 0 auto; }
|
||||
.iwb-gal-setrow select { flex: 1 1 auto; width: auto; min-width: 58px; max-width: 92px; height: 22px; font-size: 11px; padding: 0 2px 0 4px; }
|
||||
|
||||
/* ---- 图片墙 ---- */
|
||||
.iwb-history-grid { overscroll-behavior: contain; }
|
||||
.iwb-history-embedded .iwb-history-item { position: relative; flex: none; width: 100%; }
|
||||
.iwb-history-embedded .iwb-history-item img {
|
||||
width: 100%; height: auto; display: block; object-fit: contain; margin: 0 auto;
|
||||
border-radius: 6px; border: 1px solid var(--iwb-border); background: var(--iwb-layer2); cursor: pointer;
|
||||
}
|
||||
.iwb-history-missing {
|
||||
display: flex; align-items: center; justify-content: center; text-align: center;
|
||||
min-height: 84px; padding: 8px; border-radius: 6px; border: 1px dashed var(--iwb-border);
|
||||
font-size: 11px; color: var(--iwb-text2); background: var(--iwb-layer2); word-break: break-all;
|
||||
}
|
||||
.iwb-history-actions { display: flex; gap: 4px; padding: 4px 2px 0; }
|
||||
.iwb-history-actions .iwb-btn-sm { padding: 1px 6px; font-size: 10px; }
|
||||
.iwb-history-more { display: flex; justify-content: center; padding: 4px 0 2px; }
|
||||
/* 只作用于图库自己的空态提示:不加前缀会泄漏到设置页等使用 .iwb-hint 的地方(文字被居中) */
|
||||
.iwb-history-embedded .iwb-hint { font-size: 11px; color: var(--iwb-text2); text-align: center; padding: 12px 6px; }
|
||||
/* ---- v1.6.0:失败统计 / 右键菜单标题(v1.6.1 去掉搜索框)---- */
|
||||
.iwb-gal-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
|
||||
.iwb-gal-fail {
|
||||
font-size: 11px; color: var(--iwb-err); cursor: pointer; white-space: nowrap;
|
||||
text-decoration: underline dotted; text-underline-offset: 2px;
|
||||
}
|
||||
.iwb-gal-fail:hover { color: var(--iwb-err); opacity: .85; }
|
||||
.iwb-gal-menu .iwb-ctx-title { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
@@ -0,0 +1,455 @@
|
||||
// iwb-plugin: 节点组库 —— 左侧「节点组」面板(宿主只提供 ctx.grouplib 数据能力,界面全部在插件里)
|
||||
//
|
||||
// 依赖客户端能力:grouplib(list/save/remove/instantiate/notify/onChanged)+ panels。
|
||||
// 数据仍在宿主持有(收藏的节点组快照 + 分组),插件不存副本,避免两份真相。
|
||||
// 视觉:复用宿主 .iwb-lib-* / .iwb-pcard / .iwb-chip / .iwb-gmgr-* 类名(style.css 已有)。
|
||||
;(function (global) {
|
||||
'use strict'
|
||||
if (!global.IWBPluginHost) return
|
||||
|
||||
var PANEL_ID = 'grouplib-panel'
|
||||
|
||||
function el (tag, attrs) {
|
||||
var node = document.createElement(tag)
|
||||
if (attrs) {
|
||||
for (var k in attrs) {
|
||||
if (!Object.prototype.hasOwnProperty.call(attrs, k)) continue
|
||||
var v = attrs[k]
|
||||
if (v === null || v === undefined) continue
|
||||
if (k === 'class') node.className = v
|
||||
else if (k === 'text') node.textContent = v
|
||||
else if (k === 'style') node.setAttribute('style', v)
|
||||
else node.setAttribute(k, v)
|
||||
}
|
||||
}
|
||||
for (var i = 2; i < arguments.length; i++) append(node, arguments[i])
|
||||
return node
|
||||
}
|
||||
function append (node, v) {
|
||||
if (v === null || v === undefined || v === false) return
|
||||
if (Array.isArray(v)) { for (var i = 0; i < v.length; i++) append(node, v[i]); return }
|
||||
node.appendChild(typeof v === 'string' ? document.createTextNode(v) : v)
|
||||
}
|
||||
function clear (node) { while (node.firstChild) node.removeChild(node.firstChild) }
|
||||
|
||||
function ask (text, opts) {
|
||||
var C = global.IWBUIConfirm
|
||||
if (C && typeof C.askOrNative === 'function') return C.askOrNative(text, opts)
|
||||
return Promise.resolve(global.confirm(String(text)))
|
||||
}
|
||||
|
||||
function mount (host, ctx) {
|
||||
clear(host)
|
||||
host.classList.add('iwb-plugin-node-body')
|
||||
host.style.minHeight = '0'
|
||||
|
||||
var list = [] // [{id, name, group, ...snapshot}]
|
||||
var ggroups = [] // [{id, name}]
|
||||
var filter = 'all'
|
||||
var manage = false
|
||||
var picked = {} // id -> 1(管理模式多选)
|
||||
var editing = '' // 正在改名的 id
|
||||
var newOpen = false
|
||||
var managerOpen = false
|
||||
|
||||
var api = ctx.grouplib || {}
|
||||
|
||||
function notify (text, type) { try { api.notify && api.notify(text, type || 'ok') } catch (e) { /* ignore */ } }
|
||||
function groupsOf () {
|
||||
if (ggroups && ggroups.length) return ggroups
|
||||
var seen = []
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
var g = String((list[i] && list[i].group) || '').trim()
|
||||
if (g && !seen.some(function (x) { return x.name === g })) seen.push({ id: g, name: g })
|
||||
}
|
||||
return seen
|
||||
}
|
||||
function save (next, nextGroups) {
|
||||
var groups = next || list
|
||||
var gs = nextGroups || groupsOf()
|
||||
list = groups
|
||||
ggroups = gs
|
||||
render()
|
||||
return Promise.resolve(api.save({ groups: groups, groupGroups: gs })).then(function (r) {
|
||||
if (r && r.ok === false) { notify(r.error || '节点组保存失败,请重试', 'err'); return r }
|
||||
return r || { ok: true }
|
||||
}).catch(function () { notify('节点组保存失败,请重试', 'err') })
|
||||
}
|
||||
|
||||
var body = el('div', { class: 'iwb-lib-body' })
|
||||
var fixed = el('div', { class: 'iwb-lib-fixed' })
|
||||
var scrollBox = el('div', { class: 'iwb-lib-scroll' })
|
||||
var wrap = el('div', { class: 'iwb-groups-embedded' }, body)
|
||||
body.appendChild(fixed)
|
||||
body.appendChild(scrollBox)
|
||||
host.appendChild(wrap)
|
||||
|
||||
var loadError = '' // '' = 正常;否则是给用户看的原因(据此区分「真没收藏」和「能力没拿到」)
|
||||
function load () {
|
||||
if (typeof api.list !== 'function') {
|
||||
loadError = '节点组能力未就绪(客户端需 ≥ 3.25.56)'
|
||||
list = []; ggroups = []
|
||||
render()
|
||||
return Promise.resolve(false)
|
||||
}
|
||||
return Promise.resolve(api.list()).then(function (r) {
|
||||
loadError = ''
|
||||
list = (r && r.groups) || []
|
||||
ggroups = (r && r.groupGroups) || []
|
||||
render()
|
||||
return true
|
||||
}).catch(function (e) {
|
||||
loadError = '读取失败:' + ((e && e.message) || e || '未知错误')
|
||||
list = []; ggroups = []
|
||||
render()
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
function countOf (name) {
|
||||
if (name === 'all') return list.length
|
||||
if (name === '__none__') return list.filter(function (g) { return !String((g && g.group) || '').trim() }).length
|
||||
return list.filter(function (g) { return (g && g.group) === name }).length
|
||||
}
|
||||
function visible () {
|
||||
if (filter === '__none__') return list.filter(function (g) { return !String((g && g.group) || '').trim() })
|
||||
if (filter !== 'all') return list.filter(function (g) { return (g && g.group) === filter })
|
||||
return list.slice()
|
||||
}
|
||||
|
||||
function assignGroup (ids, group) {
|
||||
return save(list.map(function (x) { return ids.indexOf(x.id) >= 0 ? Object.assign({}, x, { group: group || '' }) : x }))
|
||||
.then(function () { notify('已移动到' + (group || '未分组')) })
|
||||
}
|
||||
|
||||
function openMenu (e, g) {
|
||||
e.preventDefault(); e.stopPropagation()
|
||||
closeMenu()
|
||||
var menu = el('div', { class: 'iwb-ctxmenu iwb-lib-group-menu', style: 'left:' + e.clientX + 'px;top:' + e.clientY + 'px' })
|
||||
menu.appendChild(el('div', { class: 'iwb-ctx-title', text: '移动到分组' }))
|
||||
var mk = function (label, value) {
|
||||
var b = el('button', { class: 'iwb-ctx-item', text: label })
|
||||
b.addEventListener('click', function () { closeMenu(); assignGroup([g.id], value) })
|
||||
menu.appendChild(b)
|
||||
}
|
||||
mk('未分组', '')
|
||||
groupsOf().forEach(function (gr) { mk(gr.name, gr.name) })
|
||||
document.body.appendChild(menu)
|
||||
menu._iwbOwner = wrap
|
||||
setTimeout(function () { document.addEventListener('pointerdown', onDocDown, true) }, 0)
|
||||
}
|
||||
var openMenuEl = null
|
||||
function closeMenu () {
|
||||
if (openMenuEl && openMenuEl.parentNode) openMenuEl.parentNode.removeChild(openMenuEl)
|
||||
openMenuEl = null
|
||||
document.removeEventListener('pointerdown', onDocDown, true)
|
||||
var old = document.querySelector('.iwb-lib-group-menu')
|
||||
if (old && old.parentNode) old.parentNode.removeChild(old)
|
||||
}
|
||||
function onDocDown (e) {
|
||||
var m = document.querySelector('.iwb-lib-group-menu')
|
||||
if (m && m.contains(e.target)) return
|
||||
closeMenu()
|
||||
}
|
||||
|
||||
// ---- 分组管理弹窗 ----
|
||||
var modalHost = null
|
||||
function openManager () {
|
||||
closeManager()
|
||||
managerOpen = true
|
||||
var mask = el('div', { class: 'iwb-modal-mask' })
|
||||
var modal = el('div', { class: 'iwb-modal iwb-modal-sm' })
|
||||
var head = el('div', { class: 'iwb-modal-head' })
|
||||
var title = el('span', { class: 'iwb-toolbar-title' })
|
||||
var closeBtn = el('button', { class: 'iwb-btn iwb-btn-sm', title: '关闭', text: '✕' })
|
||||
closeBtn.addEventListener('click', closeManager)
|
||||
head.appendChild(title); head.appendChild(closeBtn)
|
||||
var bodyEl = el('div', { class: 'iwb-modal-body' })
|
||||
modal.appendChild(head); modal.appendChild(bodyEl)
|
||||
mask.appendChild(modal)
|
||||
mask.addEventListener('wheel', function (e) { e.stopPropagation() })
|
||||
mask.addEventListener('pointerdown', function (e) { if (e.target === mask) closeManager() })
|
||||
document.body.appendChild(mask)
|
||||
modalHost = mask
|
||||
renderManager(title, bodyEl)
|
||||
}
|
||||
function closeManager () {
|
||||
managerOpen = false
|
||||
if (modalHost && modalHost.parentNode) modalHost.parentNode.removeChild(modalHost)
|
||||
modalHost = null
|
||||
render()
|
||||
}
|
||||
function renderManager (title, bodyEl) {
|
||||
var gs = groupsOf()
|
||||
title.textContent = '管理节点组分组(' + gs.length + ')'
|
||||
clear(bodyEl)
|
||||
if (!gs.length) bodyEl.appendChild(el('div', { class: 'iwb-hint', text: '暂无分组。可在下方新建。' }))
|
||||
gs.forEach(function (g, i) {
|
||||
var row = el('div', { class: 'iwb-gmgr-row' })
|
||||
var nameEl = el('span', { class: 'iwb-gmgr-name', text: g.name })
|
||||
row.appendChild(nameEl)
|
||||
row.appendChild(el('span', { class: 'iwb-gmgr-count', text: countOf(g.name) + ' 组' }))
|
||||
var rn = el('button', { class: 'iwb-btn iwb-btn-sm', title: '重命名', text: '重命名' })
|
||||
rn.addEventListener('click', function () {
|
||||
var input = el('input', { class: 'iwb-input iwb-grow', value: g.name })
|
||||
row.replaceChild(input, nameEl)
|
||||
input.focus(); input.select()
|
||||
var commit = function () {
|
||||
var n = String(input.value || '').trim()
|
||||
if (!n || n === g.name) { renderManager(title, bodyEl); return }
|
||||
if (groupsOf().some(function (x) { return x.name === n })) { renderManager(title, bodyEl); return }
|
||||
var ng = groupsOf().map(function (x) { return x.name === g.name ? { id: n, name: n } : x })
|
||||
var nl = list.map(function (x) { return x.group === g.name ? Object.assign({}, x, { group: n }) : x })
|
||||
if (filter === g.name) filter = n
|
||||
save(nl, ng).then(function () { if (managerOpen) openManager() })
|
||||
}
|
||||
input.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Enter') { e.preventDefault(); commit() }
|
||||
if (e.key === 'Escape') renderManager(title, bodyEl)
|
||||
})
|
||||
input.addEventListener('blur', commit)
|
||||
})
|
||||
row.appendChild(rn)
|
||||
var up = el('button', { class: 'iwb-btn iwb-btn-sm', title: '上移', text: '↑' })
|
||||
up.disabled = i === 0
|
||||
up.addEventListener('click', function () { swap(i, -1) })
|
||||
row.appendChild(up)
|
||||
var down = el('button', { class: 'iwb-btn iwb-btn-sm', title: '下移', text: '↓' })
|
||||
down.disabled = i === gs.length - 1
|
||||
down.addEventListener('click', function () { swap(i, 1) })
|
||||
row.appendChild(down)
|
||||
var del = el('button', { class: 'iwb-btn iwb-btn-sm iwb-btn-danger', title: '删除分组(组内节点组移至未分组)', text: '删除' })
|
||||
del.addEventListener('click', function () {
|
||||
ask('删除节点组分组「' + g.name + '」?组内节点组将移至「未分组」(不删除节点组)。', { title: '删除分组', okText: '删除' }).then(function (ok) {
|
||||
if (!ok) return
|
||||
var ng = groupsOf().filter(function (x) { return x.name !== g.name })
|
||||
var nl = list.map(function (x) { return x.group === g.name ? Object.assign({}, x, { group: '' }) : x })
|
||||
if (filter === g.name) filter = 'all'
|
||||
save(nl, ng).then(function () { if (managerOpen) openManager() })
|
||||
})
|
||||
})
|
||||
row.appendChild(del)
|
||||
bodyEl.appendChild(row)
|
||||
})
|
||||
var addRow = el('div', { class: 'iwb-row' })
|
||||
var input = el('input', { class: 'iwb-input iwb-grow', placeholder: '新分组名称' })
|
||||
var addBtn = el('button', { class: 'iwb-btn', text: '+ 添加' })
|
||||
var doAdd = function () {
|
||||
var n = String(input.value || '').trim()
|
||||
if (!n) return
|
||||
if (groupsOf().some(function (x) { return x.name === n })) { input.value = ''; return }
|
||||
input.value = ''
|
||||
save(list, groupsOf().concat([{ id: n, name: n }])).then(function () { if (managerOpen) openManager() })
|
||||
}
|
||||
input.addEventListener('keydown', function (e) { if (e.key === 'Enter') doAdd() })
|
||||
addBtn.addEventListener('click', doAdd)
|
||||
addRow.appendChild(input); addRow.appendChild(addBtn)
|
||||
bodyEl.appendChild(addRow)
|
||||
}
|
||||
function swap (i, dir) {
|
||||
var gs = groupsOf().slice()
|
||||
var ni = i + dir
|
||||
if (ni < 0 || ni >= gs.length) return
|
||||
var t = gs[i]; gs[i] = gs[ni]; gs[ni] = t
|
||||
save(list, gs).then(function () { if (managerOpen) openManager() })
|
||||
}
|
||||
|
||||
// ---- 渲染 ----
|
||||
function render () {
|
||||
clear(fixed); clear(scrollBox)
|
||||
var gs = groupsOf()
|
||||
|
||||
var topRow = el('div', { class: 'iwb-row' })
|
||||
var mgBtn = el('button', { class: 'iwb-btn iwb-btn-sm' + (manage ? ' iwb-btn-primary' : ''), text: manage ? '退出管理' : '管理' })
|
||||
mgBtn.addEventListener('click', function () { manage = !manage; picked = {}; render() })
|
||||
topRow.appendChild(mgBtn)
|
||||
var refresh = el('button', { class: 'iwb-btn iwb-btn-sm', title: '重新向宿主拉取节点组', text: '↻' })
|
||||
refresh.addEventListener('click', function () { load() })
|
||||
topRow.appendChild(refresh)
|
||||
if (manage && Object.keys(picked).length) {
|
||||
var mv = el('select', { class: 'iwb-input' })
|
||||
mv.appendChild(el('option', { value: '__move__', text: '移动到分组…' }))
|
||||
mv.appendChild(el('option', { value: '', text: '未分组' }))
|
||||
gs.forEach(function (g) { mv.appendChild(el('option', { value: g.name, text: g.name })) })
|
||||
mv.addEventListener('change', function () {
|
||||
if (mv.value === '__move__') return
|
||||
var ids = Object.keys(picked)
|
||||
picked = {}
|
||||
assignGroup(ids, mv.value)
|
||||
})
|
||||
topRow.appendChild(mv)
|
||||
}
|
||||
fixed.appendChild(topRow)
|
||||
|
||||
// 分类胶囊:宿主 .iwb-lib-chips 是 nowrap(配 .iwb-lib-chips-scroll 才单行滚动),
|
||||
// 分组多时右侧胶囊会被面板宽度裁掉看不见 ⇒ 这里改成「适应面板宽度自动换行」,
|
||||
// 换行规则在插件自带 styles.css 的 .iwb-glp-chips 里(样式随插件发,不用等客户端发版)
|
||||
var chips = el('div', { class: 'iwb-lib-chips iwb-glp-chips' })
|
||||
function chip (label, value, count, extra) {
|
||||
var b = el('button', { class: 'iwb-chip' + (filter === value ? ' iwb-chip-active' : '') + (extra || ''), title: value === '__none__' ? '未分组;拖拽节点组卡片到此 = 移出分组' : (value === 'all' ? '' : '拖拽节点组卡片到此 = 移动到该分组') })
|
||||
b.appendChild(document.createTextNode(label))
|
||||
b.appendChild(el('span', { class: 'iwb-chip-count', text: String(count) }))
|
||||
b.addEventListener('click', function () { newOpen = false; filter = value; render() })
|
||||
b.addEventListener('dragover', function (e) { e.preventDefault(); e.stopPropagation() })
|
||||
b.addEventListener('drop', function (e) {
|
||||
e.preventDefault(); e.stopPropagation()
|
||||
var gid = e.dataTransfer && e.dataTransfer.getData('application/x-iwb-groupid')
|
||||
if (!gid) return
|
||||
assignGroup([gid], value === 'all' || value === '__none__' ? '' : value)
|
||||
})
|
||||
return b
|
||||
}
|
||||
chips.appendChild(chip('全部', 'all', list.length))
|
||||
chips.appendChild(chip('未分组', '__none__', countOf('__none__'), ' iwb-chip-drop'))
|
||||
gs.forEach(function (g) { chips.appendChild(chip(g.name, g.name, countOf(g.name), ' iwb-chip-drop')) })
|
||||
var addChip = el('button', { class: 'iwb-chip iwb-glp-add iwb-chip-add', title: '新建分组', text: '+' })
|
||||
addChip.addEventListener('click', function () { newOpen = !newOpen; render() })
|
||||
chips.appendChild(addChip)
|
||||
var mgChip = el('button', { class: 'iwb-chip iwb-glp-add iwb-chip-add', title: '管理分组(重命名 / 排序 / 删除)', text: '⚙' })
|
||||
mgChip.addEventListener('click', openManager)
|
||||
chips.appendChild(mgChip)
|
||||
fixed.appendChild(chips)
|
||||
|
||||
if (newOpen) {
|
||||
var row = el('div', { class: 'iwb-row' })
|
||||
var inp = el('input', { class: 'iwb-input iwb-grow', placeholder: '新分组名称' })
|
||||
var ok = el('button', { class: 'iwb-btn iwb-btn-primary', text: '确定' })
|
||||
var no = el('button', { class: 'iwb-btn', text: '取消' })
|
||||
ok.addEventListener('click', function () {
|
||||
var n = String(inp.value || '').trim()
|
||||
if (n && !groupsOf().some(function (x) { return x.name === n })) save(list, groupsOf().concat([{ id: n, name: n }]))
|
||||
filter = n || filter
|
||||
newOpen = false
|
||||
render()
|
||||
})
|
||||
no.addEventListener('click', function () { newOpen = false; render() })
|
||||
inp.addEventListener('keydown', function (e) { if (e.key === 'Enter') ok.click() })
|
||||
row.appendChild(inp); row.appendChild(ok); row.appendChild(no)
|
||||
fixed.appendChild(row)
|
||||
setTimeout(function () { try { inp.focus() } catch (e) { /* ignore */ } }, 0)
|
||||
}
|
||||
|
||||
// 卡片
|
||||
var cards = el('div', { class: 'iwb-lib-cards' })
|
||||
var items = visible()
|
||||
items.forEach(function (g) {
|
||||
var isEditing = editing === g.id
|
||||
var card = el('div', {
|
||||
class: 'iwb-glp-card iwb-pcard' + (isEditing ? ' iwb-pcard-editing' : '') + (manage && picked[g.id] ? ' iwb-pcard-selected' : ''),
|
||||
'data-manage': manage ? '1' : '0',
|
||||
draggable: isEditing ? 'false' : 'true',
|
||||
title: manage ? '单击选中 · 右上「移动到分组」' : '双击改名 · 拖到画布实例化 · 右键移动到分组',
|
||||
})
|
||||
card.addEventListener('dragstart', function (e) {
|
||||
if (isEditing) return
|
||||
try { card.classList.add('iwb-glp-dragging') } catch (err) { /* ignore */ }
|
||||
try {
|
||||
e.stopPropagation()
|
||||
e.dataTransfer.setData('application/x-iwb-group', JSON.stringify(g.id))
|
||||
e.dataTransfer.setData('application/x-iwb-groupid', g.id)
|
||||
e.dataTransfer.effectAllowed = 'copy'
|
||||
} catch (err) { /* ignore */ }
|
||||
})
|
||||
card.addEventListener('dragend', function () {
|
||||
try { card.classList.remove('iwb-glp-dragging') } catch (err) { /* ignore */ }
|
||||
})
|
||||
card.addEventListener('contextmenu', function (e) {
|
||||
if (manage) { e.preventDefault(); picked[g.id] = picked[g.id] ? 0 : 1; render(); return }
|
||||
openMenu(e, g)
|
||||
})
|
||||
card.addEventListener('dblclick', function (e) {
|
||||
e.stopPropagation()
|
||||
if (manage) return
|
||||
editing = g.id
|
||||
render()
|
||||
})
|
||||
|
||||
var rowEl = el('div', { class: 'iwb-row' })
|
||||
if (isEditing) {
|
||||
var input = el('input', { class: 'iwb-input iwb-grow iwb-pname-input', value: g.name || '', placeholder: '组名' })
|
||||
var cancel = false
|
||||
var commit = function () {
|
||||
if (cancel) return
|
||||
editing = ''
|
||||
var n = String(input.value || '').trim() || g.name
|
||||
if (n !== g.name) save(list.map(function (x) { return x.id === g.id ? Object.assign({}, x, { name: n }) : x }))
|
||||
else render()
|
||||
}
|
||||
input.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Enter') { e.stopPropagation(); commit() }
|
||||
if (e.key === 'Escape') { e.stopPropagation(); cancel = true; editing = ''; render() }
|
||||
})
|
||||
input.addEventListener('blur', commit)
|
||||
rowEl.appendChild(input)
|
||||
setTimeout(function () { try { input.focus(); input.select() } catch (e) { /* ignore */ } }, 0)
|
||||
} else {
|
||||
var nameEl = el('span', { class: 'iwb-pname', title: '双击改名', text: g.name || '分组' })
|
||||
rowEl.appendChild(nameEl)
|
||||
var btns = el('span', { class: 'iwb-pbtns' })
|
||||
var del = el('button', { class: 'iwb-btn iwb-btn-sm iwb-btn-danger', title: '删除节点组', text: '✕' })
|
||||
del.addEventListener('click', function (e) {
|
||||
e.stopPropagation()
|
||||
ask('删除节点组「' + (g.name || '') + '」?', { title: '删除节点组', okText: '删除' }).then(function (ok) {
|
||||
if (!ok) return
|
||||
list = list.filter(function (x) { return x.id !== g.id })
|
||||
render()
|
||||
Promise.resolve(api.remove(g.id)).catch(function () {})
|
||||
})
|
||||
})
|
||||
btns.appendChild(del)
|
||||
rowEl.appendChild(btns)
|
||||
}
|
||||
card.appendChild(rowEl)
|
||||
if (manage) {
|
||||
card.addEventListener('click', function () {
|
||||
picked[g.id] = picked[g.id] ? 0 : 1
|
||||
if (!picked[g.id]) delete picked[g.id]
|
||||
render()
|
||||
})
|
||||
} else {
|
||||
card.addEventListener('click', function (e) { e.stopPropagation() })
|
||||
}
|
||||
cards.appendChild(card)
|
||||
})
|
||||
scrollBox.appendChild(cards)
|
||||
if (!items.length) {
|
||||
var hint = loadError
|
||||
? loadError
|
||||
: (list.length
|
||||
? '当前分组下没有节点组(共 ' + list.length + ' 个,切到「全部」查看)'
|
||||
: '宿主返回 0 个收藏节点组。画布编组后点组右上角「收藏」,或用右键菜单「收藏选中节点」。')
|
||||
scrollBox.appendChild(el('div', { class: 'iwb-hint iwb-glp-empty', text: hint }))
|
||||
}
|
||||
}
|
||||
|
||||
// 宿主侧变化(画布收藏节点组 / 其它标签页同步)→ 重拉
|
||||
var off = null
|
||||
try { off = api.onChanged && api.onChanged(function () { load() }) } catch (e) { /* ignore */ }
|
||||
|
||||
load()
|
||||
|
||||
return function dispose () {
|
||||
try { if (typeof off === 'function') off() } catch (e) { /* ignore */ }
|
||||
closeMenu()
|
||||
if (modalHost && modalHost.parentNode) modalHost.parentNode.removeChild(modalHost)
|
||||
modalHost = null
|
||||
}
|
||||
}
|
||||
|
||||
global.IWBPluginHost.register({
|
||||
id: 'grouplib',
|
||||
name: '节点组',
|
||||
version: '1.0.4',
|
||||
apiVersion: 1,
|
||||
capabilities: ['panels', 'grouplib'],
|
||||
data: { schemaVersion: 1, maxBytes: 65536 },
|
||||
}, function (ctx) {
|
||||
ctx.ui.registerPanel({
|
||||
id: PANEL_ID,
|
||||
title: '节点组',
|
||||
icon: 'group',
|
||||
// 宿主只调用 mount(node)(一个参数):必须在这里把工厂 ctx 注入,否则面板里 ctx 是 undefined ⇒ 首渲染抛异常 ⇒ 整块空白
|
||||
mount: function (host) { return mount(host, ctx) },
|
||||
})
|
||||
})
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"id": "grouplib",
|
||||
"name": "节点组",
|
||||
"version": "1.0.4",
|
||||
"apiVersion": 1,
|
||||
"main": "main.js",
|
||||
"style": "styles.css",
|
||||
"description": "左栏收藏的节点组:分组/改名/删除,拖到画布实例化(数据由客户端提供)",
|
||||
"author": "official",
|
||||
"icon": "📦",
|
||||
"tags": [
|
||||
"资源",
|
||||
"节点组"
|
||||
],
|
||||
"files": {
|
||||
"main.js": "8cb2e39f9880d49c9b9c15a1f7d62d9772170c8d0eac0faaa237bb7056af34ff",
|
||||
"styles.css": "ee6e292ffebdcc1351651bf7937399128ae06e0b364624792f34111866f9355b"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/* grouplib(节点组)自带样式
|
||||
作用域全部带 .iwb-glp-*,不影响宿主与其他插件;样式随插件发布,不必等客户端发版。 */
|
||||
|
||||
/* 分类胶囊「适应面板宽度」自动换行。
|
||||
宿主的 .iwb-lib-chips 是 flex-wrap: nowrap(配合 .iwb-lib-chips-scroll 才做单行横向滚动),
|
||||
分组多时右侧胶囊会被面板宽度裁掉、看不见也用不了。
|
||||
这里用双类选择器提高优先级(不依赖样式注入顺序),让它按宽度折行。 */
|
||||
.iwb-lib-chips.iwb-glp-chips {
|
||||
flex-wrap: wrap;
|
||||
row-gap: 6px;
|
||||
}
|
||||
|
||||
/* + / ⚙ 是动作按钮,不是分组名:不参与压缩,并与最后一个分组稍作分隔 */
|
||||
.iwb-glp-chips .iwb-glp-add {
|
||||
flex: 0 0 auto;
|
||||
margin-left: 2px;
|
||||
}
|
||||
|
||||
/* v1.0.4(2026-11-21):卡片交互态 + 空态 + 拖拽反馈。
|
||||
颜色只走宿主 token(--iwb-plugin-* / --iwb-*),不写死。 */
|
||||
.iwb-glp-card { transition: background .12s ease, border-color .12s ease; }
|
||||
.iwb-glp-card .iwb-pname { font-weight: 600; }
|
||||
/* 删除按钮:平时隐藏,悬停/键盘聚焦才出现,减少视觉噪音 */
|
||||
.iwb-glp-card .iwb-pbtns { opacity: 0; transition: opacity .12s ease; }
|
||||
.iwb-glp-card:hover .iwb-pbtns,
|
||||
.iwb-glp-card:focus-within .iwb-pbtns { opacity: 1; }
|
||||
/* 管理模式的选中标记:右上角圆点 */
|
||||
.iwb-glp-card[data-manage="1"]::after {
|
||||
content: ''; position: absolute; right: 8px; top: 8px; width: 12px; height: 12px;
|
||||
border-radius: 50%; border: 1.5px solid var(--iwb-border2, #b9bfca); background: transparent;
|
||||
}
|
||||
.iwb-glp-card[data-manage="1"].iwb-pcard-selected::after {
|
||||
background: var(--iwb-brand, #6b7280); border-color: var(--iwb-brand, #6b7280);
|
||||
}
|
||||
/* 拖拽中:半透明 + 轻微缩放,明确"正在搬运" */
|
||||
.iwb-glp-dragging { opacity: .55; }
|
||||
/* 空态:虚线框 */
|
||||
.iwb-glp-empty {
|
||||
margin: 4px 0; padding: 14px 12px; border-radius: 10px; text-align: center;
|
||||
border: 1px dashed var(--iwb-border2, #b9bfca); color: var(--iwb-text2, #4d5668);
|
||||
font-size: 12px; line-height: 1.7;
|
||||
}
|
||||
@@ -11,23 +11,62 @@
|
||||
"version": "1.0.0",
|
||||
"integrity": "sha256-Z3Y4k/qZyP4di89kBCb1u8V2q9NbzchMkQt7CPeZZPk="
|
||||
},
|
||||
{
|
||||
"id": "browser",
|
||||
"file": "plugin-browser.8161a82890d9.js",
|
||||
"version": "1.7.0",
|
||||
"integrity": "sha256-gWGoKJDZZyTZCirpyJSdN6+S+UuUTNUlrcB7ZbXqtPQ="
|
||||
},
|
||||
{
|
||||
"id": "gallery",
|
||||
"dir": "gallery",
|
||||
"main": "main.js",
|
||||
"style": "styles.css",
|
||||
"version": "1.6.9",
|
||||
"files": {
|
||||
"main.js": "26c7e64b3a0021c6b9514dfb84d4d2580276698222b4791cfa99f22ead66ff52",
|
||||
"styles.css": "9d5b4ab1343761e51ef0c479cab96a94d3d6eaa27f0fdb500bff789ec81d70e0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "grouplib",
|
||||
"dir": "grouplib",
|
||||
"main": "main.js",
|
||||
"style": "styles.css",
|
||||
"version": "1.0.4",
|
||||
"files": {
|
||||
"main.js": "8cb2e39f9880d49c9b9c15a1f7d62d9772170c8d0eac0faaa237bb7056af34ff",
|
||||
"styles.css": "ee6e292ffebdcc1351651bf7937399128ae06e0b364624792f34111866f9355b"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "promptlib",
|
||||
"dir": "promptlib",
|
||||
"main": "main.js",
|
||||
"style": "styles.css",
|
||||
"version": "1.8.8",
|
||||
"files": {
|
||||
"main.js": "91fde4bcfa888b04ee2b0e79a05d951a56247bc76ecd11b5d9500131df11d542",
|
||||
"styles.css": "70cc02f98bed580f70ef9c71009dde29e01a92684c28d69016438d49c1e0a95b"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "image-annotate",
|
||||
"file": "plugin-image-annotate.86ccc161901c.js",
|
||||
"version": "1.20.1",
|
||||
"integrity": "sha256-hszBYZAc1qcloGHrWhXG9Z3Zc/qq0emOnlMNPUar3Pc="
|
||||
"file": "plugin-image-annotate.7a865c7c353c.js",
|
||||
"version": "1.20.6",
|
||||
"integrity": "sha256-eoZcfDU8P7yqxVGorrWs0b9iTKJfEE25b85JPDCEsk8="
|
||||
},
|
||||
{
|
||||
"id": "image-vectorize",
|
||||
"file": "plugin-image-vectorize.03b5fc850c34.js",
|
||||
"version": "0.4.2",
|
||||
"integrity": "sha256-A7X8hQw03cCZa6/DZ3mPtgrsybsjuSmQ3VzMWe10v8k="
|
||||
"file": "plugin-image-vectorize.7014982f60e6.js",
|
||||
"version": "0.6.0",
|
||||
"integrity": "sha256-cBSYL2DmBeNJCZhqwMNyGV5hMBKeKakn1tQaFAVXnp8="
|
||||
},
|
||||
{
|
||||
"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",
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
{
|
||||
"batch-export": {
|
||||
"name": "批量出图",
|
||||
"desc": "资源中心勾选节点,串行批量生成并打包 ZIP 下载",
|
||||
"author": "official",
|
||||
"icon": "🗂️",
|
||||
"color": "#e8f0fe",
|
||||
"tags": [
|
||||
"出图",
|
||||
"批处理"
|
||||
]
|
||||
},
|
||||
"blank-canvas": {
|
||||
"name": "空白画布",
|
||||
"desc": "新建空白画布节点,用于分区分组",
|
||||
"author": "official",
|
||||
"icon": "⬜",
|
||||
"color": "#eef2f6",
|
||||
"tags": [
|
||||
"画布",
|
||||
"效率"
|
||||
]
|
||||
},
|
||||
"image-annotate": {
|
||||
"name": "标注 / 修图",
|
||||
"desc": "在画布内标注、涂抹、局部重绘",
|
||||
"author": "official",
|
||||
"icon": "🖌️",
|
||||
"color": "#fdeaea",
|
||||
"tags": [
|
||||
"修图",
|
||||
"标注"
|
||||
]
|
||||
},
|
||||
"image-vectorize": {
|
||||
"name": "位图转矢量",
|
||||
"desc": "把位图转成 SVG 矢量路径",
|
||||
"author": "official",
|
||||
"icon": "✒️",
|
||||
"color": "#eaf3ea",
|
||||
"tags": [
|
||||
"转换",
|
||||
"矢量"
|
||||
]
|
||||
},
|
||||
"style-source": {
|
||||
"name": "风格库",
|
||||
"desc": "风格提示词库与一键套用",
|
||||
"author": "official",
|
||||
"icon": "🎨",
|
||||
"color": "#fdf0e6",
|
||||
"tags": [
|
||||
"提示词",
|
||||
"风格"
|
||||
]
|
||||
},
|
||||
"white-bg-800": {
|
||||
"name": "白底图",
|
||||
"desc": "批量生成电商白底图(800px)",
|
||||
"author": "official",
|
||||
"icon": "🧾",
|
||||
"color": "#eef7fb",
|
||||
"tags": [
|
||||
"电商",
|
||||
"出图"
|
||||
]
|
||||
},
|
||||
"xianyi-cutout": {
|
||||
"name": "鲜艺抠图",
|
||||
"desc": "接入鲜艺抠图模型的一键去背景",
|
||||
"author": "official",
|
||||
"icon": "✂️",
|
||||
"color": "#f3eafd",
|
||||
"tags": [
|
||||
"抠图",
|
||||
"去背景"
|
||||
]
|
||||
},
|
||||
"browser": {
|
||||
"name": "应用内浏览器",
|
||||
"desc": "库面板内置真实浏览器:书签按分组管理、拖动排序;地址栏 ↗ 可把当前页放到画布节点",
|
||||
"author": "official",
|
||||
"icon": "🌐",
|
||||
"color": "#eaf1fb",
|
||||
"tags": [
|
||||
"浏览器",
|
||||
"效率"
|
||||
]
|
||||
},
|
||||
"gallery": {
|
||||
"name": "图库",
|
||||
"desc": "右栏图片墙:筛选/多选/双击预览/插入画布/下载/删除(数据由客户端提供)",
|
||||
"author": "official",
|
||||
"icon": "🖼️",
|
||||
"color": "#eef2f6",
|
||||
"tags": [
|
||||
"资源",
|
||||
"图库"
|
||||
]
|
||||
},
|
||||
"grouplib": {
|
||||
"name": "节点组",
|
||||
"desc": "左栏收藏的节点组:分组/改名/删除,拖到画布实例化(数据由客户端提供)",
|
||||
"author": "official",
|
||||
"icon": "📦",
|
||||
"tags": [
|
||||
"资源",
|
||||
"节点组"
|
||||
]
|
||||
},
|
||||
"promptlib": {
|
||||
"name": "提示词库",
|
||||
"desc": "右栏提示词列表:搜索/分组/收藏/新建编辑/插入画布/复制(数据由客户端提供)",
|
||||
"author": "official",
|
||||
"icon": "📖",
|
||||
"tags": [
|
||||
"资源",
|
||||
"提示词"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"id": "promptlib",
|
||||
"name": "提示词库",
|
||||
"version": "1.8.8",
|
||||
"apiVersion": 1,
|
||||
"main": "main.js",
|
||||
"style": "styles.css",
|
||||
"description": "右栏提示词列表:搜索/分组/收藏/新建编辑/插入画布/复制(数据由客户端提供)",
|
||||
"author": "official",
|
||||
"icon": "📖",
|
||||
"tags": [
|
||||
"资源",
|
||||
"提示词"
|
||||
],
|
||||
"files": {
|
||||
"main.js": "91fde4bcfa888b04ee2b0e79a05d951a56247bc76ecd11b5d9500131df11d542",
|
||||
"styles.css": "70cc02f98bed580f70ef9c71009dde29e01a92684c28d69016438d49c1e0a95b"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,554 @@
|
||||
/* promptlib(提示词库)自带样式
|
||||
作用域全部带 .iwb-plp-*,不影响宿主与其他插件;样式随插件发布,不必等客户端发版。 */
|
||||
|
||||
/* 分组胶囊「适应面板宽度」自动换行。
|
||||
宿主的 .iwb-lib-chips 是 flex-wrap: nowrap(配 .iwb-lib-chips-scroll 做单行横向滚动 + 右侧渐隐),
|
||||
分组多时靠后的分类看不见也点不到。双类选择器提高优先级(不依赖样式注入顺序)。 */
|
||||
.iwb-lib-chips.iwb-plp-chips {
|
||||
flex-wrap: wrap;
|
||||
row-gap: 6px;
|
||||
}
|
||||
|
||||
/* + / ⚙ 是动作按钮,不是分组名:不参与压缩,并与最后一个分组稍作分隔 */
|
||||
.iwb-plp-chips .iwb-plp-add {
|
||||
flex: 0 0 auto;
|
||||
margin-left: 2px;
|
||||
}
|
||||
|
||||
/* v1.0.2(2026-11-21):卡片化 —— 白卡 + 悬停 + 文本三行截断。
|
||||
颜色一律走宿主 --iwb-plugin-* / --iwb-* token,不在插件里写死。 */
|
||||
.iwb-promptlib .iwb-pname { font-weight: 600; }
|
||||
.iwb-promptlib .iwb-ptext {
|
||||
display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3;
|
||||
overflow: hidden; color: var(--iwb-text2, #4d5668);
|
||||
}
|
||||
.iwb-promptlib .iwb-lib-cards { gap: 8px; }
|
||||
|
||||
/* v1.1.0(2026-11-21):封面网格 + 长文详情 + 宽编辑弹窗。
|
||||
颜色全部走宿主 token,不写死。 */
|
||||
.iwb-plp-card {
|
||||
position: relative; border-radius: 10px; overflow: hidden; cursor: pointer;
|
||||
aspect-ratio: 1 / 1; border: 1px solid var(--iwb-border, #d5d9e0);
|
||||
transition: border-color .12s ease, transform .12s ease;
|
||||
}
|
||||
.iwb-plp-card:hover { border-color: var(--iwb-border2, #b9bfca); }
|
||||
.iwb-plp-cover { width: 100%; height: 100%; object-fit: cover; display: block; }
|
||||
.iwb-plp-t {
|
||||
position: absolute; left: 0; right: 0; bottom: 0; padding: 16px 7px 6px;
|
||||
background: linear-gradient(to bottom, rgba(0,0,0,0), rgba(0,0,0,.66));
|
||||
color: var(--iwb-text, #fff); font-size: 10.5px; line-height: 1.35; max-height: 48%;;
|
||||
display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden;
|
||||
text-shadow: 0 1px 2px rgba(0,0,0,.35);
|
||||
}
|
||||
/* 详情:长文阅读 */
|
||||
.iwb-plp-dhead { display: flex; align-items: center; gap: 6px; padding: 2px 0 8px; position: sticky; top: 0; z-index: 2; background: var(--iwb-plugin-surface, #fafafb); }
|
||||
.iwb-plp-dtop { align-items: flex-start; gap: 10px; margin-bottom: 8px; }
|
||||
.iwb-plp-dthumb { flex: 0 0 84px; width: 84px; height: 84px; border-radius: 8px; overflow: hidden; border: 1px solid var(--iwb-border, #d5d9e0); }
|
||||
.iwb-plp-dmeta { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
|
||||
.iwb-plp-dtitle { font-size: 13px; font-weight: 600; color: var(--iwb-text, #1c2333); line-height: 1.45; }
|
||||
.iwb-plp-dtext {
|
||||
font-size: 12px; line-height: 1.75; color: var(--iwb-text2, #4d5668);
|
||||
white-space: pre-wrap; word-break: break-word; padding: 4px 0 12px;
|
||||
}
|
||||
.iwb-plp-dfoot { display: flex; align-items: center; gap: 6px; padding: 8px 0 2px; position: sticky; bottom: 0; background: var(--iwb-plugin-surface, #fafafb); }
|
||||
/* 编辑弹窗:760 宽 + 大文本框 */
|
||||
.iwb-promptlib-editor { width: 760px; max-width: 94vw; }
|
||||
.iwb-promptlib-editor .iwb-modal-body { max-height: 78vh; }
|
||||
.iwb-promptlib-text { min-height: 360px; height: 44vh; font-size: 12.5px; line-height: 1.9; resize: vertical; }
|
||||
.iwb-plp-editor-cover { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
|
||||
.iwb-plp-editor-thumb { flex: 0 0 96px; width: 96px; height: 128px; border-radius: 8px; overflow: hidden; border: 1px solid var(--iwb-border, #d5d9e0); }
|
||||
.iwb-plp-editor-coverops { display: flex; flex-direction: column; gap: 8px; }
|
||||
|
||||
/* v1.2.0:可拖动 / 可缩放的详情与编辑弹窗(同宽 880×640,最小 640×420) */
|
||||
.iwb-plp-mask { background: transparent; display: block; }
|
||||
.iwb-plp-dialog { display: flex; flex-direction: column; overflow: hidden; border-radius: 16px;
|
||||
box-shadow: 0 24px 60px rgba(0,0,0,.28); }
|
||||
.iwb-plp-dhead { display: flex; align-items: center; gap: 6px; padding: 10px 14px;
|
||||
border-bottom: 1px solid var(--iwb-border, #d5d9e0); cursor: move; user-select: none; }
|
||||
.iwb-plp-grip { display: grid; grid-template-columns: repeat(3, 3px); gap: 2px; margin-right: 6px; }
|
||||
.iwb-plp-grip i { width: 3px; height: 3px; border-radius: 50%; background: var(--iwb-border2, #b9bfca); display: block; }
|
||||
.iwb-plp-dbody { flex: 1 1 auto; min-height: 0; display: flex; gap: 14px; padding: 14px; }
|
||||
.iwb-plp-dcov { flex: 0 0 210px; width: 210px; height: 280px; border-radius: 10px; overflow: hidden;
|
||||
border: 1px solid var(--iwb-border, #d5d9e0); background: var(--iwb-plugin-inset, #f5f6f7); }
|
||||
.iwb-plp-dright { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
|
||||
.iwb-plp-dtext { flex: 1 1 auto; min-height: 0; overflow: auto; white-space: pre-wrap; word-break: break-word;
|
||||
font-size: 12px; line-height: 1.9; color: var(--iwb-text2, #4d5668); }
|
||||
.iwb-plp-dfooter { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 10px 14px;
|
||||
border-top: 1px solid var(--iwb-border, #d5d9e0); }
|
||||
.iwb-plp-resize { position: absolute; right: 0; bottom: 0; width: 18px; height: 18px; cursor: nwse-resize;
|
||||
background: linear-gradient(135deg, transparent 0 45%, var(--iwb-border2, #b9bfca) 45% 50%, transparent 50% 62%, var(--iwb-border2, #b9bfca) 62% 67%, transparent 67%); }
|
||||
/* 编辑:左栏固定 240,右栏大文本框 */
|
||||
.iwb-plp-eleft { flex: 0 0 240px; width: 240px; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
|
||||
.iwb-plp-ecov { width: 240px; height: 300px; border-radius: 10px; overflow: hidden;
|
||||
border: 1px solid var(--iwb-border, #d5d9e0); background: var(--iwb-plugin-inset, #f5f6f7); }
|
||||
.iwb-plp-lrow { display: flex; flex-direction: column; gap: 4px; font-size: 10px; color: var(--iwb-text2, #4d5668); }
|
||||
.iwb-plp-etext { flex: 1 1 auto; min-height: 0; height: auto; resize: none; font-size: 12px; line-height: 1.9; }
|
||||
/* 输入框边框柔化(用户反馈现在的边框太深) */
|
||||
.iwb-plp-dialog .iwb-input { border-color: color-mix(in srgb, var(--iwb-border, #d5d9e0) 72%, transparent); }
|
||||
.iwb-plp-dialog .iwb-input:focus { border-color: var(--iwb-brand, #6b7280); box-shadow: 0 0 0 2px color-mix(in srgb, var(--iwb-brand, #6b7280) 14%, transparent); }
|
||||
|
||||
/* v1.2.1:去掉弹窗里多余的线框(用户反馈“线框太多、太明显”) */
|
||||
.iwb-plp-dialog .iwb-plp-dcov,
|
||||
.iwb-plp-dialog .iwb-plp-ecov { border-color: transparent; }
|
||||
.iwb-plp-dialog .iwb-plp-dhead { border-bottom-color: color-mix(in srgb, var(--iwb-border, #d5d9e0) 45%, transparent); }
|
||||
.iwb-plp-dialog .iwb-plp-dfooter { border-top-color: color-mix(in srgb, var(--iwb-border, #d5d9e0) 45%, transparent); }
|
||||
/* 输入框:默认无边框,用浅底区分;聚焦才出现细描边 */
|
||||
.iwb-plp-dialog .iwb-input {
|
||||
border-color: transparent;
|
||||
background: var(--iwb-plugin-inset, #f5f6f7);
|
||||
box-shadow: none;
|
||||
}
|
||||
.iwb-plp-dialog .iwb-input:hover { background: var(--iwb-plugin-hover, #eef1f4); }
|
||||
.iwb-plp-dialog .iwb-input:focus {
|
||||
background: var(--iwb-panel, #fff);
|
||||
border-color: color-mix(in srgb, var(--iwb-brand, #6b7280) 55%, transparent);
|
||||
box-shadow: 0 0 0 2px color-mix(in srgb, var(--iwb-brand, #6b7280) 12%, transparent);
|
||||
}
|
||||
/* 正文编辑区:无边框、无底色,像一张纸 */
|
||||
.iwb-plp-dialog .iwb-plp-etext { border-color: transparent; background: transparent; box-shadow: none; }
|
||||
.iwb-plp-dialog .iwb-plp-etext:focus { border-color: transparent; box-shadow: none; background: transparent; }
|
||||
/* 左侧封面区的两个按钮:去掉按钮描边,弱化成文字按钮 */
|
||||
.iwb-plp-dialog .iwb-plp-eleft .iwb-btn { border-color: transparent; background: var(--iwb-plugin-inset, #f5f6f7); }
|
||||
.iwb-plp-dialog .iwb-plp-eleft .iwb-btn:hover { background: var(--iwb-plugin-hover, #eef1f4); }
|
||||
|
||||
/* v1.3.3:封面比例不定 —— 详情/编辑里完整显示(contain,不裁切);列表保持方形裁切(网格整齐) */
|
||||
.iwb-plp-dialog .iwb-plp-dcov img,
|
||||
.iwb-plp-dialog .iwb-plp-ecov img { object-fit: contain; background: var(--iwb-plugin-inset, #f5f6f7); }
|
||||
.iwb-plp-dialog .iwb-plp-dcov,
|
||||
.iwb-plp-dialog .iwb-plp-ecov { background: var(--iwb-plugin-inset, #f5f6f7); }
|
||||
.iwb-plp-card .iwb-plp-cover { object-fit: cover; object-position: center; }
|
||||
|
||||
/* v1.3.4:瀑布流(列式)+ 卡片定宽不随面板拉伸;面板底色统一走 --iwb-plugin-surface */
|
||||
.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-plugin-surface,这里只留兜底) */
|
||||
.iwb-promptlib { background: transparent; }
|
||||
|
||||
/* v1.3.5:无封面的提示词也给一个方形占位(否则瀑布流里会塌成一条线) */
|
||||
.iwb-promptlib .iwb-plp-card.no-cover { aspect-ratio: 1 / 1; }
|
||||
.iwb-promptlib .iwb-plp-card.no-cover .iwb-plp-t { max-height: 60%; }
|
||||
|
||||
/* v1.4.7:恢复瀑布流列规则(1.4.0 清理 CSS 时把这组规则一起删掉了,列表退化成单列、卡片被拉满宽) */
|
||||
.iwb-promptlib .iwb-lib-cards { display: block; column-width: 122px; column-gap: 8px; grid-template-columns: none; }
|
||||
.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}
|
||||
.iwb-plp-placeghost{border-style:dashed!important;pointer-events:none}
|
||||
.iwb-plp-placehint{font-size:10.5px;color:var(--iwb-plp-accent,#5a4bd0);margin-top:2px}
|
||||
.iwb-plp-placebox{position:fixed;left:-9999px;top:0;z-index:99999;pointer-events:none;border:2px dashed var(--iwb-plp-accent,#6b4dff);border-radius:12px;background:color-mix(in srgb,var(--iwb-plp-accent,#6b4dff) 9%,transparent);display:flex;align-items:center;justify-content:center;box-shadow:0 10px 26px rgba(30,20,80,.10)}
|
||||
.iwb-plp-placebox-t{font-size:12px;color:var(--iwb-plp-accent,#5a3fd0);background:rgba(255,255,255,.82);border-radius:999px;padding:3px 10px}
|
||||
/* v1.6.23:放置指示改为灰色小方框 */
|
||||
.iwb-plp-placebox{border: 2px dashed var(--iwb-plugin-border, #9aa3ad);border-radius:10px;background:rgba(122,130,142,.10);box-shadow:none};
|
||||
.iwb-plp-placebox-t{font-size: 11px;color:var(--iwb-plugin-border, #6b7280);background:rgba(255,255,255,.75);padding:2px 8px};
|
||||
/* v1.7.0:编辑面板三栏 + 可拖宽;详情封面放大、变量高亮 */
|
||||
.iwb-plp-eleft{flex:0 0 236px;width:236px}
|
||||
.iwb-plp-emid{flex:1 1 auto;min-width:220px;display:flex;flex-direction:column;min-height:0}
|
||||
.iwb-plp-emid .iwb-plp-etext{flex:1 1 auto;min-height:0;resize:none}
|
||||
.iwb-plp-esplit{flex:0 0 10px;cursor:col-resize;display:flex;align-items:center;justify-content:center;border-radius:6px;background:var(--iwb-plugin-inset,#f3f4f7)}
|
||||
.iwb-plp-esplit:hover{background:var(--iwb-plugin-hover,#e9ecf1)}
|
||||
.iwb-plp-eright{flex:0 0 auto;width:300px;min-width:190px;max-width:460px;display:flex;flex-direction:column;min-height:0;background:var(--iwb-plugin-surface,#fafbfc);border:1px solid var(--iwb-border,#e6e8ec);border-radius:10px;padding:8px}
|
||||
.iwb-plp-vars{flex:1 1 auto;min-height:0;display:flex;flex-direction:column}
|
||||
.iwb-plp-vrows{flex:1 1 auto;min-height:0;overflow:auto}
|
||||
.iwb-plp-vitem{padding:4px 0;border-bottom:1px dashed var(--iwb-border,#eceef2)}
|
||||
.iwb-plp-vrow2{display:flex;align-items:center;gap:6px}
|
||||
.iwb-plp-vname{flex:1 1 auto;min-width:0;height:32px}
|
||||
.iwb-plp-vi{flex:0 0 auto;width:24px;height:24px;padding:0;border-radius:50%;border:1px solid var(--iwb-border,#dfe3e9);background:var(--iwb-plugin-surface, #fff);color:var(--iwb-text, #9aa1ac);font-size:11px;line-height:22px;text-align:center}
|
||||
.iwb-plp-vi.is-open{background: var(--iwb-plugin-border, #f1ecff);border-color:var(--iwb-plugin-border, #d8cbff);color:var(--iwb-plugin-border, #5a3fd0)};
|
||||
.iwb-plp-vdesc{width: 100%;height:28px;margin-top:5px;border-style:dashed;background:var(--iwb-plugin-border, #fbfcfd);font-size:11.5px;color:var(--iwb-plugin-border, #6b7280)};
|
||||
.iwb-plp-dcov{flex:0 0 auto;width:180px;height:180px;border-radius:12px;overflow:hidden}
|
||||
.iwb-plp-dvar{background: var(--iwb-plugin-border, #f1ecff);color:var(--iwb-plugin-border, #5a3fd0);border-radius:4px;padding:0 4px;font-weight:500};
|
||||
/* v1.7.1:编辑面板视觉精修——输入框比底色更亮、去多余边框、细分隔线 */
|
||||
.iwb-plp-dialog .iwb-plp-dbody{gap: 10px;padding:12px;background:var(--iwb-plugin-border, #f4f5f7)};
|
||||
.iwb-plp-dialog .iwb-plp-eleft{flex: 0 0 236px;width:236px;background:var(--iwb-plugin-border, #fff);border:1px solid var(--iwb-plugin-border, #e6e8ec);border-radius:12px;padding:12px};
|
||||
.iwb-plp-dialog .iwb-plp-emid{background: var(--iwb-plugin-border, #fff);border:1px solid var(--iwb-plugin-border, #e6e8ec);border-radius:12px;padding:10px 12px 12px};
|
||||
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-etext{border: 1px solid var(--iwb-plugin-border, #eef0f3);background:var(--iwb-plugin-border, #fbfcfd);border-radius:9px;padding:10px 12px};
|
||||
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-etext: focus{background:var(--iwb-plugin-border, #fff);border-color:var(--iwb-plugin-border, #cfc3ff);box-shadow:0 0 0 3px rgba(107,77,255,.08)};
|
||||
.iwb-plp-dialog .iwb-plp-esplit{flex:0 0 6px;background:transparent;border-radius:4px}
|
||||
.iwb-plp-dialog .iwb-plp-esplit: hover{background:var(--iwb-plugin-border, #e7e9ee)};
|
||||
.iwb-plp-dialog .iwb-plp-esplit: :before{content:'';display:block;width:2px;height:30px;border-radius:2px;background:var(--iwb-plugin-border, #d7dbe2)};
|
||||
.iwb-plp-dialog .iwb-plp-eright{background:transparent;border:0;padding:2px 0 0}
|
||||
.iwb-plp-dialog .iwb-plp-vitem{border:0;padding:2px 0}
|
||||
.iwb-plp-dialog .iwb-plp-vrow2{gap:6px}
|
||||
.iwb-plp-dialog .iwb-plp-vname{background: var(--iwb-plugin-border, #fbfcfd);border:1px solid var(--iwb-plugin-border, #eceef2);border-radius:8px;height:32px;padding:0 10px;font-size:12.5px;color:var(--iwb-plugin-border, #33383f)};
|
||||
.iwb-plp-dialog .iwb-plp-vname: focus{background:var(--iwb-plugin-border, #fff);border-color:var(--iwb-plugin-border, #cfc3ff);box-shadow:0 0 0 3px rgba(107,77,255,.08)};
|
||||
.iwb-plp-dialog .iwb-plp-vi{background: transparent;border:0;color:var(--iwb-plugin-border, #aab0ba);width:22px;height:22px;line-height:20px};
|
||||
.iwb-plp-dialog .iwb-plp-vi: hover{background:var(--iwb-plugin-border, #eef0f4);color:var(--iwb-plugin-border, #6b7280)};
|
||||
.iwb-plp-dialog .iwb-plp-vi.is-open{background: var(--iwb-plugin-border, #f1ecff);color:var(--iwb-plugin-border, #5a3fd0)};
|
||||
.iwb-plp-dialog .iwb-plp-vdesc{background: var(--iwb-plugin-border, #fbfcfd);border:1px dashed var(--iwb-plugin-border, #e2e6ec);border-radius:7px;height:28px;margin-top:4px};
|
||||
.iwb-plp-dialog .iwb-plp-lrow span{color: var(--iwb-plugin-border, #8a919c);font-size:11.5px};
|
||||
.iwb-plp-dialog .iwb-plp-lrow .iwb-input{background: var(--iwb-plugin-border, #fbfcfd);border:1px solid var(--iwb-plugin-border, #eceef2);border-radius:8px;height:32px};
|
||||
.iwb-plp-dialog .iwb-plp-lrow .iwb-input: focus{background:var(--iwb-plugin-border, #fff);border-color:var(--iwb-plugin-border, #cfc3ff)};
|
||||
/* v1.7.2:正文变量高亮(黑粗)+ 说明灰按钮 + 说明背景回归面板底 */
|
||||
.iwb-plp-ewrap{position: relative;flex:1 1 auto;min-height:0;display:flex;border-radius:9px;background:var(--iwb-plugin-border, #fbfcfd);border:1px solid var(--iwb-plugin-border, #eef0f3)};
|
||||
.iwb-plp-ewrap: focus-within{background:var(--iwb-plugin-border, #fff);border-color:var(--iwb-plugin-border, #cfc3ff);box-shadow:0 0 0 3px rgba(107,77,255,.08)};
|
||||
.iwb-plp-ewrap .iwb-plp-etext{flex: 1 1 auto;min-height:0;border:0;background:transparent;box-shadow:none;color:transparent;caret-color:var(--iwb-plugin-border, #1d2129);position:relative;z-index:1;resize:none};
|
||||
.iwb-plp-ewrap .iwb-plp-etext:focus{background:transparent;border:0;box-shadow:none}
|
||||
.iwb-plp-hl{position: absolute;inset:0;padding:10px 12px;overflow:hidden;white-space:pre-wrap;word-wrap:break-word;font-size:13px;line-height:1.9;color:var(--iwb-plugin-border, #5b6472);pointer-events:none;z-index:0};
|
||||
.iwb-plp-hlvar{color: var(--iwb-plugin-border, #1d2129);font-weight:600};
|
||||
.iwb-plp-dialog .iwb-plp-vi.is-open{background: var(--iwb-plugin-border, #eef0f3);color:var(--iwb-plugin-border, #5b6472)};
|
||||
.iwb-plp-dialog .iwb-plp-vdesc{background: transparent;border:1px dashed var(--iwb-plugin-border, #dfe3e9)};
|
||||
.iwb-plp-dvar{background: transparent;color:var(--iwb-plugin-border, #1d2129);font-weight:600;padding:0};
|
||||
.iwb-plp-hres{height:6px;margin:-3px 0 0;cursor:ns-resize;flex:0 0 auto;border-radius:3px}
|
||||
.iwb-plp-hres: hover{background:var(--iwb-plugin-border, #e7e9ee)};
|
||||
/* 正文可见性:textarea 透明,显示下方高亮层 */
|
||||
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-ewrap{flex: 1 1 auto;min-height:0;position:relative;display:flex;background:var(--iwb-plugin-border, #fbfcfd);border:1px solid var(--iwb-plugin-border, #eef0f3);border-radius:9px};
|
||||
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-ewrap .iwb-plp-etext{background:transparent!important;color:transparent!important;border:0!important;box-shadow:none!important;padding:10px 12px}
|
||||
.iwb-plp-dialog .iwb-plp-hl{padding:10px 12px;font-size:13px;line-height:1.9}
|
||||
.iwb-plp-namebox{min-height:34px;height:34px;line-height:1.45;padding:7px 10px;resize:vertical;overflow:auto;font-size:12.5px}
|
||||
.iwb-plp-insvar{color: var(--iwb-plugin-border, #1d2129)!important;background:var(--iwb-plugin-border, #fff)!important;border-color:var(--iwb-plugin-border, #e2e6ec)!important};
|
||||
.iwb-plp-insvar: hover{background:var(--iwb-plugin-border, #f4f6f9)!important};
|
||||
/* v1.7.5:编辑封面卡在框内;详情封面放大 */
|
||||
.iwb-plp-dialog .iwb-plp-ecov{width:100%;height:250px;overflow:hidden;border-radius:12px;background:var(--iwb-plugin-inset,#f3f4f7)}
|
||||
.iwb-plp-dialog .iwb-plp-ecov .iwb-plp-cover{width:100%;height:100%;object-fit:cover;object-position:center;display:block;border-radius:12px}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dbody{align-items:flex-start}
|
||||
.iwb-plp-dialog .iwb-plp-dcov{width:264px;height:264px;flex:0 0 auto;overflow:hidden;border-radius:12px;background:var(--iwb-plugin-inset,#f3f4f7)}
|
||||
.iwb-plp-dialog .iwb-plp-dcov .iwb-plp-cover{width:100%;height:100%;object-fit:cover;object-position:center;display:block;border-radius:12px}
|
||||
/* v1.7.6:封面完整展示(contain),不裁剪 */
|
||||
.iwb-plp-dialog .iwb-plp-ecov .iwb-plp-cover{object-fit:contain;background:transparent}
|
||||
.iwb-plp-dialog .iwb-plp-dcov .iwb-plp-cover{object-fit:contain;background:transparent}
|
||||
.iwb-plp-dialog .iwb-plp-ecov{background:var(--iwb-plugin-inset,#f3f4f7)}
|
||||
.iwb-plp-dialog .iwb-plp-dcov{background:var(--iwb-plugin-inset,#f3f4f7)}
|
||||
/* v1.7.7:编辑区文字层与高亮层使用完全一致的字体度量,修复光标/选区错位 */
|
||||
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-ewrap .iwb-plp-etext,
|
||||
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-hl{
|
||||
font-family:-apple-system,BlinkMacSystemFont,'PingFang SC','Helvetica Neue',system-ui,sans-serif!important;
|
||||
font-size:13px!important;
|
||||
line-height:1.85!important;
|
||||
letter-spacing:0!important;
|
||||
padding:10px 12px!important;
|
||||
margin:0!important;
|
||||
border:0!important;
|
||||
box-sizing:border-box!important;
|
||||
white-space:pre-wrap!important;
|
||||
overflow-wrap:break-word!important;
|
||||
word-break:break-word!important;
|
||||
tab-size:4!important;
|
||||
}
|
||||
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-ewrap .iwb-plp-etext{overflow-y:auto!important;scrollbar-gutter:stable}
|
||||
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-hl{overflow:hidden!important}
|
||||
/* v1.7.9:详情正文独立滚动,长文不再压到底部按钮 */
|
||||
.iwb-plp-dialog-detail .iwb-plp-dbody{overflow:hidden;align-items:stretch}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dright{flex:1 1 auto;min-width:0;min-height:0;display:flex;flex-direction:column;overflow:hidden}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dtext{flex:1 1 auto;min-height:0;overflow:auto;padding-right:10px;margin-bottom:6px}
|
||||
/* v1.8.0:详情标题/分组/标签移到封面下方;编辑标签改为输入+加号 */
|
||||
.iwb-plp-dialog-detail .iwb-plp-dbody{align-items:flex-start}
|
||||
.iwb-plp-dleftcol{flex:0 0 264px;width:264px;display:flex;flex-direction:column;min-width:0}
|
||||
.iwb-plp-dtitle{font-size:18px;font-weight:650;line-height:1.35;margin-top:14px;color:var(--iwb-text,#1d2129)}
|
||||
.iwb-plp-dmeta{display:flex;flex-wrap:wrap;align-items:center;gap:6px;margin-top:8px}
|
||||
.iwb-plp-dgroup{font-size: 11.5px;background:var(--iwb-plugin-border, #eef0f4);color:var(--iwb-plugin-border, #5b6472);border-radius:999px;padding:2px 9px};
|
||||
.iwb-plp-dtag{font-size: 11.5px;background:var(--iwb-plugin-border, #f4f0ff);color:var(--iwb-plugin-border, #5a3fd0);border-radius:999px;padding:2px 9px};
|
||||
.iwb-plp-dlen{font-size: 11.5px;color:var(--iwb-plugin-border, #9aa1ac)};
|
||||
.iwb-plp-tagwrap{display:flex;flex-direction:column;gap:6px;flex:1;min-width:0}
|
||||
.iwb-plp-tagchips{display:flex;flex-wrap:wrap;gap:5px}
|
||||
.iwb-plp-tagchip{display: inline-flex;align-items:center;gap:4px;font-size:11.5px;background:var(--iwb-plugin-border, #eef0f4);border-radius:999px;padding:2px 8px;color:var(--iwb-plugin-border, #3f4450)};
|
||||
.iwb-plp-tagx{cursor: pointer;color:var(--iwb-plugin-border, #9aa1ac);font-style:normal};
|
||||
.iwb-plp-tagx: hover{color:var(--iwb-plugin-border, #c0392b)};
|
||||
.iwb-plp-tagrow{display:flex;gap:6px}
|
||||
.iwb-plp-tagin{flex:1;min-width:0;height:30px}
|
||||
.iwb-plp-lrow-tags{align-items:flex-start}
|
||||
.iwb-plp-tagadd{flex:0 0 auto;width:30px;height:30px;padding:0;font-size:15px;line-height:28px}
|
||||
/* v1.8.1:详情标题/分组/标签左对齐并带标题;标签加号对齐修复 */
|
||||
.iwb-plp-dtitle{font-size:20px;font-weight:650;line-height:1.35;margin-top:16px;color:var(--iwb-text,#1d2129)}
|
||||
.iwb-plp-dmeta{display:flex;flex-direction:column;gap:7px;margin-top:12px;align-items:flex-start}
|
||||
.iwb-plp-dmrow{display:flex;align-items:center;gap:10px;width:100%}
|
||||
.iwb-plp-dmk{flex: 0 0 30px;width:30px;font-size:11.5px;color:var(--iwb-plugin-border, #9aa1ac)};
|
||||
.iwb-plp-dmv{display:flex;flex-wrap:wrap;align-items:center;gap:5px;min-width:0}
|
||||
.iwb-plp-dgroup{font-size: 12px;color:var(--iwb-plugin-border, #3f4450);background:var(--iwb-plugin-border, #f2f4f7);border-radius:6px;padding:2px 9px};
|
||||
.iwb-plp-dtag{font-size: 11.5px;color:var(--iwb-plugin-border, #5a3fd0);background:var(--iwb-plugin-border, #f4f0ff);border-radius:6px;padding:2px 9px};
|
||||
.iwb-plp-dempty{font-size: 12px;color:var(--iwb-plugin-border, #b3b9c2)};
|
||||
.iwb-plp-dlen{font-size: 12px;color:var(--iwb-plugin-border, #8a919c)};
|
||||
.iwb-plp-tagrow{display:flex;align-items:center;gap:6px}
|
||||
.iwb-plp-tagin{height:30px;border-radius:8px}
|
||||
.iwb-plp-tagadd{flex: 0 0 auto;width:30px;height:30px;padding:0;border-radius:8px;background:var(--iwb-plugin-border, #f2f4f7);border:1px solid var(--iwb-plugin-border, #e2e6ec);color:var(--iwb-plugin-border, #5b6472);font-size:16px;line-height:1;display:inline-flex;align-items:center;justify-content:center};
|
||||
.iwb-plp-tagadd: hover{background:var(--iwb-plugin-border, #e9ecf1)};
|
||||
/* v1.8.2:详情左右两栏卡片化 + 分割线 */
|
||||
.iwb-plp-dialog-detail .iwb-plp-dbody{gap: 14px;padding:16px;background:var(--iwb-plugin-border, #f4f5f7)};
|
||||
.iwb-plp-dialog-detail .iwb-plp-dleftcol{flex: 0 0 300px;width:300px;padding:12px;border:1px solid var(--iwb-plugin-border, #e8eaee);border-radius:14px;background:var(--iwb-plugin-border, #fff);align-self:flex-start};
|
||||
.iwb-plp-dialog-detail .iwb-plp-dcov{width:100%;height:270px;border-radius:10px}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dtitle{font-size:20px;font-weight:650;line-height:1.35;margin-top:14px;color:var(--iwb-text,#1d2129)}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dmeta{margin-top: 12px;padding-top:12px;border-top:1px solid var(--iwb-plugin-border, #eef0f3);gap:8px};
|
||||
.iwb-plp-dialog-detail .iwb-plp-dright{flex: 1 1 auto;min-width:0;min-height:0;display:flex;flex-direction:column;padding:14px 16px;border:1px solid var(--iwb-plugin-border, #e8eaee);border-radius:14px;background:var(--iwb-plugin-border, #fff);overflow:hidden};
|
||||
.iwb-plp-dsec{font-size: 11.5px;font-weight:600;color:var(--iwb-plugin-border, #8a919c);letter-spacing:.04em;padding-bottom:8px;margin-bottom:8px;border-bottom:1px solid var(--iwb-plugin-border, #eef0f3);flex:0 0 auto};
|
||||
.iwb-plp-dialog-detail .iwb-plp-dtext{flex: 1 1 auto;min-height:0;overflow:auto;padding-right:10px;font-size:13.5px;line-height:2;color:var(--iwb-plugin-border, #3a4048)};
|
||||
/* v1.8.3:详情左卡片撑到底、四边等距;正文恢复滚动不被底部遮挡 */
|
||||
.iwb-plp-dialog-detail{display:flex;flex-direction:column;overflow:hidden}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dbody{display: flex;flex:1 1 auto;min-height:0;overflow:hidden;gap:14px;padding:16px;background:var(--iwb-plugin-border, #f4f5f7)};
|
||||
.iwb-plp-dialog-detail .iwb-plp-dleftcol{align-self: stretch;display:flex;flex-direction:column;overflow:auto;padding:12px;border:1px solid var(--iwb-plugin-border, #e8eaee);border-radius:14px;background:var(--iwb-plugin-border, #fff)};
|
||||
.iwb-plp-dialog-detail .iwb-plp-dright{flex: 1 1 auto;min-width:0;min-height:0;overflow:hidden;display:flex;flex-direction:column;padding:14px 16px;border:1px solid var(--iwb-plugin-border, #e8eaee);border-radius:14px;background:var(--iwb-plugin-border, #fff)};
|
||||
.iwb-plp-dialog-detail .iwb-plp-dtext{flex:1 1 auto;min-height:0;overflow-y:auto;overflow-x:hidden;scrollbar-width:thin;padding-right:8px}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dfooter{flex:0 0 auto}
|
||||
/* v1.8.4:右卡片纵向拉伸填满,正文出现滚动条 */
|
||||
.iwb-plp-dialog-detail .iwb-plp-dbody{align-items:stretch!important}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dright{align-self:stretch!important;height:100%;max-height:100%;overflow:hidden!important}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dtext{flex:1 1 0;min-height:0;overflow-y:auto!important;overflow-x:hidden}
|
||||
/* v1.8.7:详情标题缩小;分组/标签去底色;元信息加分割线与行高 */
|
||||
.iwb-plp-dialog-detail .iwb-plp-dtitle{font-size:17px!important;font-weight:650;margin-top:12px}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dmeta{margin-top: 12px;padding-top:14px;border-top:1px solid var(--iwb-plugin-border, #eef0f3);gap:10px};
|
||||
.iwb-plp-dialog-detail .iwb-plp-dmrow{gap:6px}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dmk{flex: 0 0 auto;width:auto;font-size:12px;line-height:1.6;color:var(--iwb-plugin-border, #9aa1ac)};
|
||||
.iwb-plp-dialog-detail .iwb-plp-dgroup,.iwb-plp-dialog-detail .iwb-plp-dtag{background: transparent!important;padding:0!important;border-radius:0!important;font-size:12.5px;line-height:1.6;color:var(--iwb-plugin-border, #2f3540)};
|
||||
.iwb-plp-dialog-detail .iwb-plp-dtag{color: var(--iwb-plugin-border, #5a3fd0);};
|
||||
.iwb-plp-dialog-detail .iwb-plp-dlen{font-size: 12.5px;line-height:1.6;color:var(--iwb-plugin-border, #2f3540)};
|
||||
/* v1.8.8:详情标题 14px;元信息行间浅分割线;封面底色更接近白色(编辑/详情统一) */
|
||||
.iwb-plp-dialog-detail .iwb-plp-dtitle{font-size:14px!important;font-weight:650;line-height:1.5;margin-top:12px}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dmeta{gap:0}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dmrow{padding: 7px 0;border-bottom:1px solid var(--iwb-plugin-border, #f3f5f8)};
|
||||
.iwb-plp-dialog-detail .iwb-plp-dmrow:last-child{border-bottom:0}
|
||||
.iwb-plp-dialog .iwb-plp-dcov,.iwb-plp-dialog .iwb-plp-ecov{background: var(--iwb-plugin-border, #fcfcfd)!important};
|
||||
.iwb-plp-dialog .iwb-plp-dcov .iwb-plp-cover,.iwb-plp-dialog .iwb-plp-ecov .iwb-plp-cover{background:transparent!important}
|
||||
@@ -0,0 +1,137 @@
|
||||
// iwb-plugin: 空白画布 —— 给「空白的参考图节点」填入指定尺寸(1K)的纯白图片,作为插图/标注的起点。
|
||||
// 移植自 iwb-plaus 仓库 iwb-cutout-extension:src/content.js 的 BLANK_RATIOS / performBlankCanvas / showBlankMenu。
|
||||
// 有意差异:只保留 1K 档(上游菜单实际也只用 1K);只填当前节点(不新建);不联动编辑器。
|
||||
;(function (global) {
|
||||
'use strict'
|
||||
|
||||
// 与宿主 app.js 的 RATIOS 表 1K 档逐字一致。插件不能 import 宿主内部,故照抄数值;
|
||||
// 上游扩展也是这么做的(BLANK_RATIOS 抄自宿主)。
|
||||
var SIZES = [
|
||||
{ label: '1:1 方形', w: 1024, h: 1024 },
|
||||
{ label: '2:3 竖版', w: 832, h: 1248 },
|
||||
{ label: '3:2 横版', w: 1248, h: 832 },
|
||||
{ label: '3:4 竖版', w: 880, h: 1168 },
|
||||
{ label: '4:3 横版', w: 1184, h: 880 },
|
||||
{ label: '4:5 竖版', w: 912, h: 1136 },
|
||||
{ label: '5:4 横版', w: 1136, h: 896 },
|
||||
{ label: '9:16 竖版', w: 768, h: 1360 },
|
||||
{ label: '16:9 横版', w: 1360, h: 752 },
|
||||
{ label: '21:9 超宽', w: 1552, h: 656 },
|
||||
{ label: '9:21 超宽竖版', w: 656, h: 1520 },
|
||||
]
|
||||
|
||||
var CSS = [
|
||||
'.iwb-blankcanvas-menu{position:fixed;left:50%;top:64px;transform:translateX(-50%);z-index:2147483000;',
|
||||
'width:312px;padding:10px;border-radius:10px;box-sizing:border-box;',
|
||||
'background:var(--iwb-panel,#fff);color:var(--iwb-text,#1c2333);',
|
||||
'border:1px solid var(--iwb-border,#d5d9e0);box-shadow:0 12px 32px rgba(0,0,0,.28);',
|
||||
'font:12px/1.4 system-ui,-apple-system,"PingFang SC",sans-serif}',
|
||||
'.iwb-blankcanvas-title{font-weight:600;margin:2px 2px 8px}',
|
||||
'.iwb-blankcanvas-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:6px}',
|
||||
'.iwb-blankcanvas-item{display:flex;flex-direction:column;align-items:center;gap:2px;padding:8px 4px;',
|
||||
'border-radius:8px;border:1px solid var(--iwb-border,#d5d9e0);background:var(--iwb-layer,#f0f1f4);',
|
||||
'color:inherit;font:inherit;cursor:pointer}',
|
||||
'.iwb-blankcanvas-item:hover{background:var(--iwb-layer2,#fff)}',
|
||||
'.iwb-blankcanvas-item b{font-weight:600}',
|
||||
'.iwb-blankcanvas-item i{font-style:normal;font-size:11px;color:var(--iwb-text2,#4d5668)}',
|
||||
].join('')
|
||||
|
||||
global.IWBPluginHost.register({
|
||||
id: 'blank-canvas',
|
||||
name: '空白画布',
|
||||
version: '1.0.0',
|
||||
apiVersion: 1,
|
||||
capabilities: ['nodeActions', 'canvas', 'canvasWrite'],
|
||||
}, function (ctx) {
|
||||
var STYLE_ID = 'iwb-blankcanvas-style'
|
||||
var menuEl = null
|
||||
var outsideHandler = null
|
||||
|
||||
function injectStyle() {
|
||||
if (document.getElementById(STYLE_ID)) return
|
||||
var style = document.createElement('style')
|
||||
style.id = STYLE_ID
|
||||
style.textContent = CSS
|
||||
;(document.head || document.documentElement).appendChild(style)
|
||||
}
|
||||
|
||||
// 与上游 isEmptyRefNode 等价:ref 节点且既无本地数据也无 URL({__blob}/{__cache} 引用是对象,天然为真)
|
||||
function isEmptyImageNode(node) {
|
||||
if (!node || node.type !== 'ref') return false
|
||||
var d = node.data || {}
|
||||
return !d.data && !d.url
|
||||
}
|
||||
|
||||
function whitePng(w, h) {
|
||||
var canvas = document.createElement('canvas')
|
||||
canvas.width = w
|
||||
canvas.height = h
|
||||
var ctx2d = canvas.getContext('2d')
|
||||
ctx2d.fillStyle = '#ffffff'
|
||||
ctx2d.fillRect(0, 0, w, h)
|
||||
return canvas.toDataURL('image/png')
|
||||
}
|
||||
|
||||
function closeMenu() {
|
||||
if (menuEl && menuEl.parentNode) menuEl.parentNode.removeChild(menuEl)
|
||||
menuEl = null
|
||||
if (outsideHandler) { document.removeEventListener('pointerdown', outsideHandler, true); outsideHandler = null }
|
||||
document.removeEventListener('keydown', onKeyDown, true)
|
||||
}
|
||||
|
||||
function onKeyDown(e) { if (e.key === 'Escape') closeMenu() }
|
||||
|
||||
function apply(nodeId, w, h) {
|
||||
var nodes = (ctx.canvas && typeof ctx.canvas.getNodes === 'function') ? ctx.canvas.getNodes() : []
|
||||
var target = null
|
||||
for (var i = 0; i < nodes.length; i++) if (nodes[i] && nodes[i].id === nodeId) target = nodes[i]
|
||||
if (!target || !isEmptyImageNode(target)) throw new Error('该节点不是空白的图片节点')
|
||||
// 宿主把 canvasWrite 的 API 合并进 ctx.canvas(plugin-host.js 的 CAPABILITY_API_KEYS)⇒ 写接口在 ctx.canvas 上
|
||||
if (!ctx.canvas.setNodeImage(nodeId, whitePng(w, h))) throw new Error('写入节点失败')
|
||||
}
|
||||
|
||||
function openMenu(nodeId) {
|
||||
injectStyle()
|
||||
closeMenu()
|
||||
var menu = document.createElement('div')
|
||||
menu.className = 'iwb-blankcanvas-menu'
|
||||
var title = document.createElement('div')
|
||||
title.className = 'iwb-blankcanvas-title'
|
||||
title.textContent = '创建空白画布(1K)'
|
||||
menu.appendChild(title)
|
||||
var grid = document.createElement('div')
|
||||
grid.className = 'iwb-blankcanvas-grid'
|
||||
SIZES.forEach(function (size) {
|
||||
var btn = document.createElement('button')
|
||||
btn.type = 'button'
|
||||
btn.className = 'iwb-blankcanvas-item'
|
||||
btn.setAttribute('data-size', size.w + 'x' + size.h)
|
||||
btn.innerHTML = '<b>' + size.label + '</b><i>' + size.w + '×' + size.h + '</i>'
|
||||
btn.addEventListener('pointerdown', function (e) { e.stopPropagation() })
|
||||
btn.addEventListener('click', function (e) {
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
closeMenu()
|
||||
apply(nodeId, size.w, size.h)
|
||||
})
|
||||
grid.appendChild(btn)
|
||||
})
|
||||
menu.appendChild(grid)
|
||||
document.body.appendChild(menu)
|
||||
menuEl = menu
|
||||
outsideHandler = function (e) { if (!menuEl || !menuEl.contains(e.target)) closeMenu() }
|
||||
document.addEventListener('pointerdown', outsideHandler, true)
|
||||
document.addEventListener('keydown', onKeyDown, true)
|
||||
}
|
||||
|
||||
ctx.nodeActions.register({
|
||||
id: 'blank-canvas-open',
|
||||
title: '空白画布',
|
||||
icon: 'plus',
|
||||
appliesTo: function (node) { return isEmptyImageNode(node) },
|
||||
run: function (node) { openMenu(node.id); return true },
|
||||
})
|
||||
|
||||
return { dispose: closeMenu }
|
||||
})
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
@@ -0,0 +1,313 @@
|
||||
// iwb-plugin: 白底图 —— 把选中节点的图等比缩放、居中合成到正方形画布,按设置的格式/质量/体积上限编码,
|
||||
// 输出 <name>_<size>x<size>.<ext>(默认 800×800 白底 jpeg,≤500KB;可开双版本一次出透明 PNG + 白底 JPG)。
|
||||
// 移植自 iwb-plaus 仓库 iwb-cutout-extension:src/shared/image-math.js 的 fitRect + src/content.js 的 makeWhiteBgImage / performWhiteBg;
|
||||
// 几何与合成算法逐字对齐上游,只有宿主胶水(IWBPluginHost 注册 / ctx 调用)与导出编码是新写的。
|
||||
;(function (global) {
|
||||
'use strict'
|
||||
|
||||
// 上游 shared/image-math.js 的 clamp
|
||||
function clamp(v, min, max) {
|
||||
return Math.max(min, Math.min(max, v))
|
||||
}
|
||||
|
||||
// 上游 shared/image-math.js 的 fitRect:内容最长边 = min(boxW, boxH) * ratio,等比缩放并居中(不裁剪)
|
||||
function fitRect(srcW, srcH, boxW, boxH, ratio) {
|
||||
if (!(srcW > 0) || !(srcH > 0) || !(boxW > 0) || !(boxH > 0)) {
|
||||
return { x: 0, y: 0, w: 0, h: 0, scale: 0 }
|
||||
}
|
||||
var r = Math.max(0.01, Math.min(1, ratio))
|
||||
var maxLen = Math.min(boxW, boxH) * r
|
||||
var scale = Math.min(maxLen / srcW, maxLen / srcH)
|
||||
var w = srcW * scale
|
||||
var h = srcH * scale
|
||||
return { x: (boxW - w) / 2, y: (boxH - h) / 2, w: w, h: h, scale: scale }
|
||||
}
|
||||
|
||||
function loadImage(src) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var img = new Image()
|
||||
img.onload = function () { resolve(img) }
|
||||
img.onerror = function () { reject(new Error('图片解码失败')) }
|
||||
img.src = src
|
||||
})
|
||||
}
|
||||
|
||||
// ---------- 编码 ----------
|
||||
|
||||
// png 无损(无质量参数);jpeg/webp 有损且有质量参数;webp 另外保留 alpha。
|
||||
var FORMATS = {
|
||||
png: { mime: 'image/png', ext: 'png', lossy: false, alpha: true },
|
||||
jpeg: { mime: 'image/jpeg', ext: 'jpg', lossy: true, alpha: false },
|
||||
webp: { mime: 'image/webp', ext: 'webp', lossy: true, alpha: true },
|
||||
}
|
||||
// toBlob 的 blob.type 才是真实产出格式(浏览器不支持 webp 时会静默回退 png),命名按它走。
|
||||
var TYPE_EXT = { 'image/png': 'png', 'image/jpeg': 'jpg', 'image/webp': 'webp' }
|
||||
|
||||
// 双版本固定产出:透明 PNG(无损、保 alpha)+ 白底 JPG(有损、体积可控)—— 电商平台两种图都要。
|
||||
// png 那种允许超上限(透明图是必需产物,PNG 无压缩参数,压不下去只能照常输出并记日志)。
|
||||
var DUAL_TARGETS = [
|
||||
{ format: 'png', transparent: true, allowOversize: true },
|
||||
{ format: 'jpeg', transparent: false, allowOversize: false },
|
||||
]
|
||||
|
||||
// 导出格式设置是 text 输入框(宿主设置面板只有 text/number/boolean),这里做容错归一化。
|
||||
function normalizeFormat(raw) {
|
||||
var s = String(raw === undefined || raw === null ? '' : raw).trim().toLowerCase().replace(/^\./, '')
|
||||
if (s === 'jpg' || s === 'jpeg' || s === 'jpe') return 'jpeg'
|
||||
if (s === 'png' || s === 'webp') return s
|
||||
return ''
|
||||
}
|
||||
|
||||
// dataURL 的字节数(仅在 canvas.toBlob 缺失时的退路;正常路径用 blob.size,精确且无 base64 开销)
|
||||
function dataUrlBytes(url) {
|
||||
var s = String(url || '')
|
||||
var comma = s.indexOf(',')
|
||||
if (comma < 0) return 0
|
||||
var body = s.length - comma - 1
|
||||
var pad = s.charAt(s.length - 1) === '=' ? (s.charAt(s.length - 2) === '=' ? 2 : 1) : 0
|
||||
return Math.max(0, Math.floor(body * 3 / 4) - pad)
|
||||
}
|
||||
|
||||
function blobToDataUrl(blob) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var reader = new FileReader()
|
||||
reader.onload = function () { resolve(String(reader.result || '')) }
|
||||
reader.onerror = function () { reject(reader.error || new Error('读取编码结果失败')) }
|
||||
reader.readAsDataURL(blob)
|
||||
})
|
||||
}
|
||||
|
||||
// 编码一次,产出 { dataUrl, size, type }
|
||||
function encodeOnce(canvas, mime, quality) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (typeof canvas.toBlob !== 'function') {
|
||||
var url = canvas.toDataURL(mime, quality)
|
||||
resolve({ dataUrl: url, size: dataUrlBytes(url), type: mime })
|
||||
return
|
||||
}
|
||||
try {
|
||||
canvas.toBlob(function (blob) {
|
||||
if (!blob) { reject(new Error('图片编码失败')); return }
|
||||
blobToDataUrl(blob).then(function (dataUrl) {
|
||||
resolve({ dataUrl: dataUrl, size: blob.size, type: String(blob.type || mime) })
|
||||
}, reject)
|
||||
}, mime, quality)
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function kb(bytes) {
|
||||
return (Math.round(bytes / 1024 * 10) / 10) + 'KB'
|
||||
}
|
||||
|
||||
// 体积上限:先按用户质量编码;超限就有损格式向下二分找「能进上限的最高质量」。
|
||||
// 有损质量下限固定 0.2:再低画质不可用,此时报错而不是偷偷改边长(800×800 是硬规范)。
|
||||
var MIN_QUALITY = 0.2
|
||||
|
||||
async function encodeWithLimit(canvas, format, quality, maxBytes) {
|
||||
var spec = FORMATS[format]
|
||||
var first = await encodeOnce(canvas, spec.mime, quality)
|
||||
if (!maxBytes || first.size <= maxBytes) return first
|
||||
|
||||
if (!spec.lossy) {
|
||||
throw new Error(
|
||||
'PNG 体积 ' + kb(first.size) + ' 超过上限 ' + kb(maxBytes) +
|
||||
':浏览器导出 PNG 无法调压缩级别 —— 请把「导出格式」改成 jpeg / webp,或调大「体积上限」'
|
||||
)
|
||||
}
|
||||
|
||||
var floor = await encodeOnce(canvas, spec.mime, MIN_QUALITY)
|
||||
if (floor.size > maxBytes) {
|
||||
throw new Error(
|
||||
'已压到质量 20 仍有 ' + kb(floor.size) + ',超过上限 ' + kb(maxBytes) +
|
||||
':请调小「大图边长」或调大「体积上限」'
|
||||
)
|
||||
}
|
||||
|
||||
var lo = MIN_QUALITY
|
||||
var hi = quality
|
||||
var pick = floor
|
||||
for (var i = 0; i < 6 && hi - lo > 0.01; i++) {
|
||||
var mid = (lo + hi) / 2
|
||||
var cur = await encodeOnce(canvas, spec.mime, mid)
|
||||
if (cur.size <= maxBytes) {
|
||||
pick = cur
|
||||
lo = mid
|
||||
} else {
|
||||
hi = mid
|
||||
}
|
||||
}
|
||||
return pick
|
||||
}
|
||||
|
||||
global.IWBPluginHost.register({
|
||||
id: 'white-bg-800',
|
||||
name: '白底图',
|
||||
version: '1.2.1',
|
||||
apiVersion: 1,
|
||||
capabilities: ['commands', 'canvas', 'canvasWrite', 'nodeActions'],
|
||||
settings: {
|
||||
bgSize: { type: 'number', label: '大图边长(像素)', desc: '默认 800;允许 64–4096,越界自动夹取。', default: 800 },
|
||||
ratioPct: { type: 'number', label: '内容占比(%)', desc: '内容等比缩放后占边长的百分比,默认 80(=640/800,电商主图规范);允许 10–100。', default: 80 },
|
||||
dual: { type: 'boolean', label: '双版本(透明 PNG + 白底 JPG)', desc: '开启=一次生成两个节点:透明底 PNG + 白底 JPG,各一份。此时「导出格式」「透明底」不生效,「覆盖原节点」被忽略(双版本总是新建)。', default: false },
|
||||
format: { type: 'text', label: '导出格式(单版本)', desc: '填 png / jpeg / webp(jpg 也认),默认 jpeg。png 无损但无压缩参数,体积可能超限。双版本开启时此项不生效。', default: 'jpeg' },
|
||||
quality: { type: 'number', label: '压缩质量(1–100)', desc: '仅 jpeg / webp 生效,默认 82;超过体积上限时自动向下调(最低 20)。', default: 82 },
|
||||
maxKB: { type: 'number', label: '体积上限(KB)', desc: '默认 500;填 0 或负数=不限制。按编码后的文件字节数判定。', default: 500 },
|
||||
transparent: { type: 'boolean', label: '透明底(单版本)', desc: '关闭(默认)=填白底;开启=保留透明通道(jpeg 不支持,会自动改填白底)。双版本开启时此项不生效。', default: false },
|
||||
replace: { type: 'boolean', label: '覆盖原节点', desc: '关闭(默认)=新建参考图节点;开启=覆盖当前节点。双版本开启时忽略此项。', default: false },
|
||||
},
|
||||
}, function (ctx) {
|
||||
const NO_IMAGE = '该节点没有可编码的图片(请选中带图的参考图或输出节点)'
|
||||
const REMOTE_FAIL = '远程图片无法读取(可能被跨域限制):请先转存为本地位图'
|
||||
|
||||
// 取图:dataUrl 直接赋给 img.src(img-src 放行 data:,不污染画布);
|
||||
// 绝不对 data: URL 发网络请求 —— 宿主 CSP connect-src 不含 data:,必被拦(姊妹插件 image-annotate 踩过并修掉的坑)。
|
||||
// 远程 url 才走 fetch,转成 blob: URL 再解码(blob: 同样不污染画布)。
|
||||
async function resolveImage(nodeId) {
|
||||
const image = await ctx.canvas.getNodeImage(nodeId)
|
||||
if (!image) throw new Error(NO_IMAGE)
|
||||
|
||||
if (image.dataUrl) return loadImage(image.dataUrl)
|
||||
if (!image.url) throw new Error(NO_IMAGE)
|
||||
|
||||
let resp
|
||||
try {
|
||||
resp = await global.fetch(image.url)
|
||||
} catch (e) {
|
||||
throw new Error(REMOTE_FAIL)
|
||||
}
|
||||
if (!resp.ok) throw new Error(REMOTE_FAIL)
|
||||
const objUrl = URL.createObjectURL(await resp.blob())
|
||||
try {
|
||||
return await loadImage(objUrl)
|
||||
} catch (e) {
|
||||
throw new Error(REMOTE_FAIL)
|
||||
} finally {
|
||||
URL.revokeObjectURL(objUrl)
|
||||
}
|
||||
}
|
||||
|
||||
// 合成(对齐上游 makeWhiteBgImage):正方形画布,白底或透明底,fitRect 等比缩放居中、不裁剪
|
||||
function composeCanvas(img, size, ratio, transparent) {
|
||||
const canvas = document.createElement('canvas')
|
||||
canvas.width = size
|
||||
canvas.height = size
|
||||
const ctx2d = canvas.getContext('2d')
|
||||
if (!transparent) {
|
||||
ctx2d.fillStyle = '#ffffff'
|
||||
ctx2d.fillRect(0, 0, size, size)
|
||||
}
|
||||
const rect = fitRect(img.naturalWidth || img.width, img.naturalHeight || img.height, size, size, ratio)
|
||||
ctx2d.drawImage(img, rect.x, rect.y, rect.w, rect.h)
|
||||
return canvas
|
||||
}
|
||||
|
||||
// allowOversize 只给双版本的透明 PNG 用:透明图是必需产物,PNG 又无压缩参数,
|
||||
// 超限也只能照常输出(记日志),不能因为一个版本超限就让另一个版本也出不来。
|
||||
async function encodeTarget(canvas, format, quality, maxBytes, allowOversize) {
|
||||
if (allowOversize && !FORMATS[format].lossy) {
|
||||
const res = await encodeOnce(canvas, FORMATS[format].mime, 1)
|
||||
if (maxBytes && res.size > maxBytes) {
|
||||
ctx.log('white-bg: 透明 PNG 为 ' + kb(res.size) + ',超过上限 ' + kb(maxBytes) + '(PNG 无压缩参数,已照常输出)')
|
||||
}
|
||||
return res
|
||||
}
|
||||
return encodeWithLimit(canvas, format, quality, maxBytes)
|
||||
}
|
||||
|
||||
// 命名用真实边长与真实编码格式(上游 autoWhiteBg 分支硬编码 _800x800 是 bug,这里按夹取后的实际边长命名;
|
||||
// 扩展名同理取 blob.type —— 浏览器不支持 webp 时会回退 png,不能照抄设置值)
|
||||
function outName(base, size, encoded, format) {
|
||||
const ext = TYPE_EXT[encoded.type] || FORMATS[format].ext
|
||||
return base + '_' + size + 'x' + size + '.' + ext
|
||||
}
|
||||
|
||||
function readNumeric(key, fallback, min, max) {
|
||||
return clamp(Number(ctx.settings.get(key)) || fallback, min, max)
|
||||
}
|
||||
|
||||
async function runOne(nodeId, nodeName) {
|
||||
const img = await resolveImage(nodeId)
|
||||
|
||||
// 宿主可能把数值设置存成字符串,统一强转再夹取
|
||||
const size = Math.round(readNumeric('bgSize', 800, 64, 4096))
|
||||
const ratio = readNumeric('ratioPct', 80, 10, 100) / 100
|
||||
const quality = readNumeric('quality', 82, 1, 100) / 100
|
||||
const maxKB = Number(ctx.settings.get('maxKB'))
|
||||
const maxBytes = Number.isFinite(maxKB) && maxKB > 0 ? Math.round(maxKB * 1024) : 0
|
||||
const dual = Boolean(ctx.settings.get('dual'))
|
||||
const replace = Boolean(ctx.settings.get('replace'))
|
||||
const base = String(nodeName || 'image').replace(/\.[^.]+$/, '') || 'image'
|
||||
|
||||
let targets
|
||||
if (dual) {
|
||||
// 双版本下「覆盖原节点」没意义(两个版本只能覆盖一个位置),按文档忽略并留痕
|
||||
if (replace) ctx.log('white-bg: 双版本模式总是新建节点,「覆盖原节点」已忽略')
|
||||
targets = DUAL_TARGETS
|
||||
} else {
|
||||
const rawFormat = ctx.settings.get('format')
|
||||
let format = normalizeFormat(rawFormat)
|
||||
if (!format) {
|
||||
ctx.log('white-bg: 未知导出格式 ' + JSON.stringify(String(rawFormat)) + ',回退 jpeg(可选 png / jpeg / webp)')
|
||||
format = 'jpeg'
|
||||
}
|
||||
// 透明底与不支持的格式冲突:jpeg 没有 alpha 通道,用它画透明底会变成黑块 —— 强制填白并留痕。
|
||||
const wantsTransparent = Boolean(ctx.settings.get('transparent'))
|
||||
const transparent = wantsTransparent && FORMATS[format].alpha
|
||||
if (wantsTransparent && !FORMATS[format].alpha) {
|
||||
ctx.log('white-bg: ' + format + ' 不支持透明通道,已自动改填白底')
|
||||
}
|
||||
targets = [{ format: format, transparent: transparent, allowOversize: false }]
|
||||
}
|
||||
|
||||
const made = []
|
||||
const errors = []
|
||||
for (const target of targets) {
|
||||
try {
|
||||
const canvas = composeCanvas(img, size, ratio, target.transparent)
|
||||
const encoded = await encodeTarget(canvas, target.format, quality, maxBytes, target.allowOversize)
|
||||
const name = outName(base, size, encoded, target.format)
|
||||
if (replace && !dual) {
|
||||
if (!ctx.canvas.setNodeImage(nodeId, encoded.dataUrl)) throw new Error('写回画布失败')
|
||||
made.push('覆盖当前节点')
|
||||
} else {
|
||||
const created = ctx.canvas.createImageNode({ dataUrl: encoded.dataUrl, name: name })
|
||||
if (!created) throw new Error('写回画布失败')
|
||||
made.push(name)
|
||||
}
|
||||
ctx.log('white-bg: ' + name + ' ' + kb(encoded.size))
|
||||
} catch (error) {
|
||||
errors.push(error && error.message ? error.message : String(error))
|
||||
}
|
||||
}
|
||||
|
||||
if (!made.length && errors.length) throw new Error(errors[0])
|
||||
// 部分成功:节点已经建好了,但要把失败原因说清楚(宿主只把 throw 显示成红色提示,这是唯一通道)
|
||||
if (errors.length) throw new Error(errors.join(';') + '(已生成:' + made.join('、') + ')')
|
||||
return dual ? made : (replace ? true : made[0])
|
||||
}
|
||||
|
||||
ctx.nodeActions.register({
|
||||
id: 'white-bg-node',
|
||||
title: '白底图',
|
||||
icon: 'vector-square',
|
||||
appliesTo: function (node) { return Boolean(node) && node.type === 'ref' },
|
||||
run: function (node) { return runOne(node.id, node.name) },
|
||||
})
|
||||
|
||||
ctx.commands.register({
|
||||
id: 'white-bg-selected',
|
||||
title: '白底图:选中节点',
|
||||
icon: 'vector-square',
|
||||
run: function () {
|
||||
const selected = ctx.canvas.getSelectedNode()
|
||||
if (!selected) return Promise.reject(new Error('请先选中一个带图的节点'))
|
||||
return runOne(selected.id, selected.name)
|
||||
},
|
||||
})
|
||||
|
||||
return {}
|
||||
})
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
@@ -0,0 +1,107 @@
|
||||
// iwb-plugin: 鲜艺抠图 —— 调用本机抠图服务(POST {apiUrl}/rmbg?crop=)把选中节点的图抠成透明底,写回为新的参考图节点。
|
||||
// 契约来源:iwb-plaus v3.1.3 的 background.js(二进制进、PNG 字节出,无 token/无 JSON)。
|
||||
;(function (global) {
|
||||
'use strict'
|
||||
|
||||
var DEFAULT_API = 'http://localhost:30092'
|
||||
var DEFAULT_TIMEOUT = 120000
|
||||
|
||||
function toPositive(v, fallback) {
|
||||
var n = Number(v)
|
||||
return Number.isFinite(n) && n > 0 ? n : fallback
|
||||
}
|
||||
|
||||
function trimUrl(v) {
|
||||
return String(v || DEFAULT_API).trim().replace(/\/+$/, '') || DEFAULT_API
|
||||
}
|
||||
|
||||
function base64ToBytes(dataUrl) {
|
||||
var s = String(dataUrl || '')
|
||||
var comma = s.indexOf(',')
|
||||
var bin = global.atob(comma >= 0 ? s.slice(comma + 1) : s)
|
||||
var out = new Uint8Array(bin.length)
|
||||
for (var i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i)
|
||||
return out
|
||||
}
|
||||
|
||||
function bytesToDataUrl(buffer) {
|
||||
var bytes = new Uint8Array(buffer)
|
||||
var chunk = 0x8000
|
||||
var text = ''
|
||||
for (var i = 0; i < bytes.length; i += chunk) {
|
||||
text += String.fromCharCode.apply(null, bytes.subarray(i, i + chunk))
|
||||
}
|
||||
return 'data:image/png;base64,' + global.btoa(text)
|
||||
}
|
||||
|
||||
global.IWBPluginHost.register({
|
||||
id: 'xianyi-cutout',
|
||||
name: '鲜艺抠图',
|
||||
version: '1.0.3',
|
||||
apiVersion: 1,
|
||||
capabilities: ['commands', 'canvas', 'canvasWrite', 'nodeActions'],
|
||||
settings: {
|
||||
apiUrl: { type: 'text', label: '本地服务地址', desc: 'CSP 仅放行 127.0.0.1 / localhost 的 30092 端口;改到别的 host 或端口会被拦。', default: DEFAULT_API },
|
||||
crop: { type: 'boolean', label: '抠图后裁掉多余透明像素', desc: '对应接口的 crop 参数,默认开启。', default: true },
|
||||
timeoutMs: { type: 'number', label: '超时(毫秒)', desc: '原扩展没有超时;这里补上,避免服务无响应时永久挂起。', default: DEFAULT_TIMEOUT },
|
||||
},
|
||||
}, function (ctx) {
|
||||
async function cutoutOne(nodeId) {
|
||||
const image = await ctx.canvas.getNodeImage(nodeId)
|
||||
if (!image || !image.dataUrl) throw new Error('该节点没有可编码的图片(请选中带图的参考图或输出节点)')
|
||||
|
||||
const apiUrl = trimUrl(ctx.settings.get('apiUrl'))
|
||||
const crop = ctx.settings.get('crop') ? 'true' : 'false'
|
||||
const timeoutMs = toPositive(ctx.settings.get('timeoutMs'), DEFAULT_TIMEOUT)
|
||||
|
||||
const controller = typeof global.AbortController === 'function' ? new global.AbortController() : null
|
||||
const timer = controller ? global.setTimeout(function () { try { controller.abort() } catch (e) { /* ignore */ } }, timeoutMs) : null
|
||||
let response
|
||||
try {
|
||||
response = await global.fetch(apiUrl + '/rmbg?crop=' + crop, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/octet-stream' },
|
||||
body: base64ToBytes(image.dataUrl),
|
||||
signal: controller ? controller.signal : undefined,
|
||||
})
|
||||
} catch (e) {
|
||||
throw new Error('连不上本地抠图服务(' + apiUrl + '):' + String((e && e.message) || e))
|
||||
} finally {
|
||||
if (timer) global.clearTimeout(timer)
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
const detail = await response.text().catch(function () { return '' })
|
||||
throw new Error('抠图服务返回 ' + response.status + (detail ? ':' + String(detail).slice(0, 120) : ''))
|
||||
}
|
||||
|
||||
const dataUrl = bytesToDataUrl(await response.arrayBuffer())
|
||||
const selected = ctx.canvas.getSelectedNode()
|
||||
const base = String((selected && selected.name) || 'image').replace(/\.[^.]+$/, '') || 'image'
|
||||
const created = ctx.canvas.createImageNode({ dataUrl: dataUrl, name: base + '_cutout.png' })
|
||||
if (!created) throw new Error('写回画布失败')
|
||||
return created
|
||||
}
|
||||
|
||||
ctx.commands.register({
|
||||
id: 'cutout-selected',
|
||||
title: '抠图:选中节点',
|
||||
icon: 'scissors',
|
||||
run: function () {
|
||||
const selected = ctx.canvas.getSelectedNode()
|
||||
if (!selected) return Promise.reject(new Error('请先选中一个带图的节点'))
|
||||
return cutoutOne(selected.id)
|
||||
},
|
||||
})
|
||||
|
||||
ctx.nodeActions.register({
|
||||
id: 'cutout-node',
|
||||
title: '抠图',
|
||||
icon: 'scissors',
|
||||
appliesTo: function (node) { return Boolean(node) && node.type === 'ref' },
|
||||
run: function (node) { return cutoutOne(node.id) },
|
||||
})
|
||||
|
||||
return {}
|
||||
})
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
@@ -27,6 +27,7 @@ fs.mkdirSync(path.join(dist, 'vendor'), { recursive: true })
|
||||
|
||||
// 顺序即加载序(各模块通过 window.IWB* 在运行时互相依赖),切勿排序/改动
|
||||
const sourceModules = [
|
||||
'runtime-desktop-bridge.js',
|
||||
'image-format.js',
|
||||
'image-admit.js',
|
||||
'image-dedupe.js',
|
||||
@@ -35,12 +36,14 @@ const sourceModules = [
|
||||
'clipboard-paste.js',
|
||||
'clipboard-copy.js',
|
||||
'clipboard-paste-once.js',
|
||||
'clipboard-native.js',
|
||||
'generation-size-policy.js',
|
||||
'generation-request-shape.js',
|
||||
'image-preview-derive.js',
|
||||
'canvas-actions.js',
|
||||
'canvas-node-factory.js',
|
||||
'storage-contract.js',
|
||||
'storage-file.js',
|
||||
'storage-runtime.js',
|
||||
'storage-migrations.js',
|
||||
'storage-result.js',
|
||||
@@ -66,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',
|
||||
@@ -74,6 +79,10 @@ const sourceModules = [
|
||||
'gallery-query.js',
|
||||
'gallery-hydration.js',
|
||||
'ui-components.js',
|
||||
'plugin-data.js',
|
||||
'plugin-api-gallery.js',
|
||||
'plugin-api-grouplib.js',
|
||||
'plugin-api-promptlib.js',
|
||||
'plugin-host.js',
|
||||
'image-compress.js',
|
||||
'storage-fallback-indexeddb.js',
|
||||
@@ -84,8 +93,22 @@ const sourceModules = [
|
||||
'canvas-text.js',
|
||||
'generation-task-graph.js',
|
||||
'generation-results-store.js',
|
||||
'ui-groups-sidebar.js',
|
||||
'ui-lib-sidebar.js',
|
||||
'ui-dock-sanitize.js',
|
||||
'ui-dock.js',
|
||||
'ui-minimap-fit.js',
|
||||
'ui-dock-panels.js',
|
||||
'theme-tokens.js',
|
||||
'canvas-grid.js',
|
||||
'image-display-thumb.js',
|
||||
'image-remote-cache.js',
|
||||
'image-thumb-pick.js',
|
||||
'ui-modal-drag.js',
|
||||
'ui-nav-rail.js',
|
||||
'ui-plugin-page.js',
|
||||
'ui-hotkey-help.js',
|
||||
'ui-desktop-shell.js',
|
||||
'ui-appearance.js',
|
||||
'runtime-download-auto.js',
|
||||
'ui-workspace-tabs.js',
|
||||
'ui-app-chrome.js',
|
||||
'ui-workbench-hooks.js',
|
||||
@@ -95,7 +118,11 @@ const sourceModules = [
|
||||
'workspace-list.js',
|
||||
'workspace-purge.js',
|
||||
'generation-provider-ping.js',
|
||||
'runtime-plugin-loader.js',
|
||||
'runtime-plugin-market.js',
|
||||
'runtime-plugin-backup.js',
|
||||
'ui-canvas-view.js',
|
||||
'ui-confirm.js',
|
||||
'ui-settings-sections.js',
|
||||
'ui-settings-tab-diag.js',
|
||||
'ui-settings-modal.js',
|
||||
@@ -105,6 +132,9 @@ const sourceModules = [
|
||||
'ui-backup-modal.js',
|
||||
'ui-connect-menu.js',
|
||||
'ui-gen-config-panel.js',
|
||||
'canvas-webview.js',
|
||||
'plugin-files-policy.js',
|
||||
'image-prompt-cover.js',
|
||||
]
|
||||
|
||||
// 插件自动发现(2026-10-17):src/plugin-*.js 中**未被上面显式登记**的,按文件名排序追加到末尾。
|
||||
@@ -161,7 +191,6 @@ const minifiedCss = transformSync(fs.readFileSync(path.join(root, 'style.css'),
|
||||
fs.writeFileSync(path.join(dist, 'style.css'), minifiedCss)
|
||||
|
||||
fs.copyFileSync(path.join(root, 'favicon.svg'), path.join(dist, 'favicon.svg'))
|
||||
fs.copyFileSync(path.join(root, '_headers'), path.join(dist, '_headers'))
|
||||
// PWA(2026-11-07):可安装 —— manifest + 图标(iOS 额外要 apple-touch-icon 的 PNG)
|
||||
for (const f of ['manifest.webmanifest', 'icon-192.png', 'icon-512.png', 'apple-touch-icon.png']) {
|
||||
fs.copyFileSync(path.join(root, f), path.join(dist, f))
|
||||
@@ -201,6 +230,8 @@ const html = `<!DOCTYPE html>
|
||||
`
|
||||
fs.writeFileSync(path.join(dist, 'index.html'), html)
|
||||
fs.writeFileSync(path.join(dist, 'version.json'), JSON.stringify({ version, packageVersion: pkg.version, commit: gitSha }, null, 2) + '\n')
|
||||
// 导航 logo 用真实应用图标(v3.25.61;缺失不阻塞构建)
|
||||
try { fs.copyFileSync(path.join(root, 'src-tauri', 'icons', 'icon.png'), path.join(dist, 'nav-logo.png')) } catch (e) { /* ignore */ }
|
||||
|
||||
const appBytes = fs.statSync(path.join(dist, 'app.js')).size
|
||||
const cssBytes = fs.statSync(path.join(dist, 'style.css')).size
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict'
|
||||
// 桌面版专用:把 plugins/runtime/ 下的运行时插件拷进 dist/plugins/。
|
||||
// 网页版插件由 Cloudflare KV 在 /plugins/* 提供;桌面端没有服务端,只能随包发布。
|
||||
// 刻意不改 scripts/build.js(上游文件),单独一步执行,保持桌面侧差异最小。
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const root = path.resolve(__dirname, '..')
|
||||
const src = path.join(root, 'plugins', 'runtime')
|
||||
const dst = path.join(root, 'dist', 'plugins')
|
||||
|
||||
if (!fs.existsSync(src)) {
|
||||
console.error('[copy-plugins] 缺少 plugins/runtime,无法打包运行时插件')
|
||||
process.exit(1)
|
||||
}
|
||||
fs.mkdirSync(dst, { recursive: true })
|
||||
|
||||
let count = 0
|
||||
for (const name of fs.readdirSync(src)) {
|
||||
fs.copyFileSync(path.join(src, name), path.join(dst, name))
|
||||
count++
|
||||
}
|
||||
// v3.25.41(M1):目录插件 <plugins>/<id>/{manifest.json,main.js} 一并进包(应用按 /plugins/<id>/… 取)
|
||||
let folders = 0
|
||||
const pluginsRoot = path.join(root, 'plugins')
|
||||
for (const name of fs.readdirSync(pluginsRoot)) {
|
||||
const abs = path.join(pluginsRoot, name)
|
||||
if (!fs.statSync(abs).isDirectory()) continue
|
||||
if (name === 'runtime' || name === 'local') continue
|
||||
if (!fs.existsSync(path.join(abs, 'manifest.json'))) continue
|
||||
fs.cpSync(abs, path.join(dst, name), { recursive: true })
|
||||
folders++
|
||||
}
|
||||
// 索引与插件文件必须同源同包:应用按 index.json 里的 filename / dir 去 /plugins/ 取
|
||||
fs.copyFileSync(path.join(root, 'plugins', 'index.json'), path.join(dst, 'index.json'))
|
||||
console.log('[copy-plugins] 已拷入 ' + count + ' 个文件 + ' + folders + ' 个目录插件 → dist/plugins/')
|
||||
@@ -0,0 +1,122 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict'
|
||||
// 生成插件市场展示页:market/index.json → market.html(纯静态,无后端)
|
||||
// 设计目标:与下载页同一套视觉;卡片墙 + 搜索 + 标签筛选;「安装」只在应用内做,这里只展示。
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const root = path.resolve(__dirname, '..')
|
||||
const index = JSON.parse(fs.readFileSync(path.join(root, 'market', 'index.json'), 'utf8'))
|
||||
const list = Array.isArray(index.plugins) ? index.plugins : []
|
||||
|
||||
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]))
|
||||
const tags = []
|
||||
for (const p of list) for (const t of (p.tags || [])) if (tags.indexOf(t) < 0) tags.push(t)
|
||||
|
||||
const kb = (n) => n >= 1024 * 1024 ? (n / 1048576).toFixed(1) + ' MB' : Math.max(1, Math.round(n / 1024)) + ' KB'
|
||||
|
||||
const card = (p) => `
|
||||
<article class="card" data-name="${esc((p.name + ' ' + p.id + ' ' + p.desc + ' ' + (p.tags || []).join(' ')).toLowerCase())}" data-tags="${esc((p.tags || []).join(','))}">
|
||||
<div class="card-head">
|
||||
<span class="avatar" style="background:${esc(p.color || '#eef2f6')}">${esc(p.icon || '◻')}</span>
|
||||
<div class="card-title">
|
||||
<h3>${esc(p.name)}</h3>
|
||||
<div class="sub">${esc(p.author === 'official' ? '官方' : p.author)} · v${esc(p.version)} · ${kb(p.size || 0)}</div>
|
||||
</div>
|
||||
</div>
|
||||
<p class="desc">${esc(p.desc)}</p>
|
||||
<div class="tags">${(p.tags || []).map((t) => `<span class="tag">${esc(t)}</span>`).join('')}</div>
|
||||
</article>`
|
||||
|
||||
const html = `<!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>
|
||||
<style>
|
||||
:root { --fg:#1a1a1a; --fg2:#6b6b6b; --line:#ececec; --bg:#fff; --chip:#f4f4f4; }
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root { --fg:#f2f2f2; --fg2:#9a9a9a; --line:#2a2a2a; --bg:#111; --chip:#1d1d1d; }
|
||||
}
|
||||
* { box-sizing:border-box; }
|
||||
body { margin:0; background:var(--bg); color:var(--fg); font:15px/1.65 -apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif; }
|
||||
.wrap { max-width:1080px; margin:0 auto; padding:56px 24px 80px; }
|
||||
header h1 { font-size:28px; margin:0 0 6px; letter-spacing:-.02em; }
|
||||
header p { margin:0; color:var(--fg2); font-size:14px; }
|
||||
.toolbar { display:flex; gap:12px; margin:28px 0 18px; flex-wrap:wrap; align-items:center; }
|
||||
input[type=search] { flex:1 1 260px; min-width:220px; padding:10px 14px; border:1px solid var(--line); border-radius:10px; background:var(--bg); color:var(--fg); font-size:14px; outline:none; }
|
||||
input[type=search]:focus { border-color:#111; }
|
||||
.chips { display:flex; gap:8px; flex-wrap:wrap; }
|
||||
.chip { padding:6px 12px; border:1px solid var(--line); border-radius:999px; background:transparent; color:var(--fg2); font-size:13px; cursor:pointer; }
|
||||
.chip.on { background:#111; color:#fff; border-color:#111; }
|
||||
@media (prefers-color-scheme: dark) { .chip.on { background:#f2f2f2; color:#111; border-color:#f2f2f2; } }
|
||||
.grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(300px,1fr)); gap:16px; }
|
||||
.card { border:1px solid var(--line); border-radius:14px; padding:18px; display:flex; flex-direction:column; gap:12px; }
|
||||
.card-head { display:flex; gap:12px; align-items:center; }
|
||||
.avatar { width:44px; height:44px; border-radius:12px; display:flex; align-items:center; justify-content:center; font-size:22px; flex:0 0 44px; }
|
||||
.card-title h3 { margin:0; font-size:16px; font-weight:600; }
|
||||
.card-title .sub { color:var(--fg2); font-size:12.5px; margin-top:2px; }
|
||||
.desc { margin:0; color:var(--fg2); font-size:13.5px; min-height:42px; }
|
||||
.tags { display:flex; gap:6px; flex-wrap:wrap; margin-top:auto; }
|
||||
.tag { padding:2px 9px; border-radius:999px; background:var(--chip); color:var(--fg2); font-size:12px; }
|
||||
.empty { color:var(--fg2); padding:40px 0; text-align:center; }
|
||||
footer { margin-top:40px; color:var(--fg2); font-size:13px; border-top:1px solid var(--line); padding-top:18px; }
|
||||
code { background:var(--chip); padding:1px 6px; border-radius:6px; font-size:12.5px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="wrap">
|
||||
<header>
|
||||
<h1>插件市场</h1>
|
||||
<p>Image Workbench 插件 · 共 <b>${list.length}</b> 个 · 在应用内「设置 → 插件」安装</p>
|
||||
</header>
|
||||
|
||||
<div class="toolbar">
|
||||
<input id="q" type="search" placeholder="搜索插件,例如:出图、抠图、矢量…" autocomplete="off">
|
||||
<div class="chips" id="chips">
|
||||
<button class="chip on" data-tag="">全部</button>
|
||||
${tags.map((t) => `<button class="chip" data-tag="${esc(t)}">${esc(t)}</button>`).join('')}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid" id="grid">${list.map(card).join('')}</div>
|
||||
<div class="empty" id="empty" hidden>没有匹配的插件</div>
|
||||
|
||||
<footer>
|
||||
安装方式:应用内 <code>设置 → 插件 → 可安装(市场)</code> 点「安装」,重启后生效。<br>
|
||||
插件目录:<code>~/Documents/ImageWorkbench/plugins/</code>(Windows:<code>%USERPROFILE%\\Documents\\ImageWorkbench\\plugins\\</code>)
|
||||
</footer>
|
||||
</div>
|
||||
<script>
|
||||
var q = document.getElementById('q')
|
||||
var grid = document.getElementById('grid')
|
||||
var empty = document.getElementById('empty')
|
||||
var chips = document.getElementById('chips')
|
||||
var activeTag = ''
|
||||
function apply () {
|
||||
var kw = (q.value || '').trim().toLowerCase()
|
||||
var shown = 0
|
||||
Array.prototype.forEach.call(grid.children, function (el) {
|
||||
var okKw = !kw || el.dataset.name.indexOf(kw) >= 0
|
||||
var okTag = !activeTag || (',' + el.dataset.tags + ',').indexOf(',' + activeTag + ',') >= 0
|
||||
var ok = okKw && okTag
|
||||
el.hidden = !ok
|
||||
if (ok) shown++
|
||||
})
|
||||
empty.hidden = shown > 0
|
||||
}
|
||||
q.addEventListener('input', apply)
|
||||
chips.addEventListener('click', function (e) {
|
||||
var b = e.target.closest('.chip')
|
||||
if (!b) return
|
||||
Array.prototype.forEach.call(chips.children, function (x) { x.classList.remove('on') })
|
||||
b.classList.add('on')
|
||||
activeTag = b.dataset.tag || ''
|
||||
apply()
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
fs.writeFileSync(path.join(root, 'market', 'index.html'), html)
|
||||
console.log('market/index.html 已生成(' + list.length + ' 个插件 / ' + tags.length + ' 个标签)')
|
||||
@@ -0,0 +1,108 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict'
|
||||
// 生成插件市场索引(M3):plugins/index.json + plugins/meta.json(+ 目录插件)→ market/
|
||||
//
|
||||
// 产物(纯静态,供 market.maqiart.eu.org 与桌面端安装器共用):
|
||||
// market/index.json 市场条目:bundle(zip) + files[逐文件 sha256] + 兼容字段 file
|
||||
// market/plugins/<id>-<version>.zip 目录插件包:manifest.json + main.js [+ styles.css / assets]
|
||||
// market/plugins/plugin-<id>.<hash>.js 单文件产物(旧客户端仍可安装,保持向后兼容)
|
||||
//
|
||||
// 包里统一用 STORE(不压缩):客户端 src/storage-zip.js 对 DEFLATE 依赖 DecompressionStream,
|
||||
// 旧 macOS 的 WKWebView 没有该 API;插件包只有几十 KB,不压缩没有实际损失。
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const crypto = require('crypto')
|
||||
const { zipStore } = require('./plugin-zip')
|
||||
|
||||
const root = path.resolve(__dirname, '..')
|
||||
const man = JSON.parse(fs.readFileSync(path.join(root, 'plugins', 'index.json'), 'utf8'))
|
||||
const meta = JSON.parse(fs.readFileSync(path.join(root, 'plugins', 'meta.json'), 'utf8'))
|
||||
const out = path.join(root, 'market')
|
||||
fs.mkdirSync(path.join(out, 'plugins'), { recursive: true })
|
||||
const sha = (buf) => crypto.createHash('sha256').update(buf)
|
||||
const shaHex = (buf) => sha(buf).digest('hex')
|
||||
|
||||
function readFolderFiles (id) {
|
||||
// 目录插件:manifest.json + main.js + 可选 styles.css + assets/**(限两级)
|
||||
const dir = path.join(root, 'plugins', id)
|
||||
const files = []
|
||||
const manifestPath = path.join(dir, 'manifest.json')
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'))
|
||||
files.push({ name: 'manifest.json', data: fs.readFileSync(manifestPath) })
|
||||
const main = String(manifest.main || 'main.js')
|
||||
files.push({ name: main, data: fs.readFileSync(path.join(dir, main)) })
|
||||
if (manifest.style && fs.existsSync(path.join(dir, manifest.style))) files.push({ name: String(manifest.style), data: fs.readFileSync(path.join(dir, String(manifest.style))) })
|
||||
const assetsDir = path.join(dir, 'assets')
|
||||
if (fs.existsSync(assetsDir)) {
|
||||
for (const name of fs.readdirSync(assetsDir)) {
|
||||
const abs = path.join(assetsDir, name)
|
||||
if (fs.statSync(abs).isFile()) files.push({ name: 'assets/' + name, data: fs.readFileSync(abs) })
|
||||
}
|
||||
}
|
||||
return { files, manifest }
|
||||
}
|
||||
|
||||
const plugins = []
|
||||
let zipped = 0
|
||||
for (const e of man) {
|
||||
const m = meta[e.id] || {}
|
||||
const base = {
|
||||
id: e.id, name: m.name || e.id, desc: m.desc || '', author: m.author || 'official',
|
||||
icon: m.icon || '', color: m.color || '', tags: Array.isArray(m.tags) ? m.tags : [],
|
||||
version: e.version, apiVersion: 1,
|
||||
}
|
||||
|
||||
// ---- 目录形态:打包 manifest + main(+style/assets) ----
|
||||
let files = null
|
||||
if (e.dir) {
|
||||
const got = readFolderFiles(e.dir)
|
||||
files = got.files
|
||||
} else {
|
||||
const src = path.join(root, 'plugins', 'runtime', e.file)
|
||||
if (!fs.existsSync(src)) { console.warn('缺少产物:' + e.file); continue }
|
||||
const js = fs.readFileSync(src)
|
||||
// 单文件插件也打成目录包:manifest.json 由市场索引生成,main.js 就是原产物
|
||||
// manifest 里带 files(main.js 的 sha256):手工把 zip 解到 <plugins>/<id>/ 时,
|
||||
// 加载器扫描目录也能校验入口文件(manifest 自身不参与,避免自引用)。
|
||||
const manifestJson = {
|
||||
id: e.id, name: base.name, version: e.version, apiVersion: 1, main: 'main.js',
|
||||
description: base.desc, author: base.author, icon: base.icon, tags: base.tags,
|
||||
files: { 'main.js': shaHex(js) },
|
||||
}
|
||||
files = [
|
||||
{ name: 'manifest.json', data: Buffer.from(JSON.stringify(manifestJson, null, 2) + '\n', 'utf8') },
|
||||
{ name: 'main.js', data: js },
|
||||
]
|
||||
}
|
||||
|
||||
const fileList = files.map((f) => ({ path: f.name, sha256: shaHex(f.data), size: f.data.length }))
|
||||
const zip = zipStore(files)
|
||||
const zipName = e.id + '-' + e.version + '.zip'
|
||||
fs.writeFileSync(path.join(out, 'plugins', zipName), zip)
|
||||
zipped++
|
||||
|
||||
const item = Object.assign({}, base, {
|
||||
bundle: 'plugins/' + zipName,
|
||||
bundleSize: zip.length,
|
||||
bundleSha256: shaHex(zip),
|
||||
files: fileList,
|
||||
})
|
||||
|
||||
// 兼容:单文件插件继续提供裸 .js(旧客户端 install 只认 file/integrity)
|
||||
if (!e.dir) {
|
||||
const src = path.join(root, 'plugins', 'runtime', e.file)
|
||||
const buf = fs.readFileSync(src)
|
||||
fs.writeFileSync(path.join(out, 'plugins', e.file), buf)
|
||||
item.file = 'plugins/' + e.file
|
||||
item.size = buf.length
|
||||
item.sha256 = shaHex(buf)
|
||||
item.integrity = 'sha256-' + sha(buf).digest('base64')
|
||||
}
|
||||
|
||||
plugins.push(item)
|
||||
}
|
||||
|
||||
const index = { version: 2, updatedAt: new Date().toISOString(), plugins: plugins }
|
||||
fs.writeFileSync(path.join(out, 'index.json'), JSON.stringify(index, null, 2) + '\n')
|
||||
console.log('market/index.json:' + plugins.length + ' 个插件 / ' + zipped + ' 个 zip 包')
|
||||
for (const p of plugins) console.log(' ' + p.id.padEnd(16) + String(p.version).padEnd(8) + (p.bundleSize + ' B zip'))
|
||||