diff --git a/app.js b/app.js
index 81b12dd..7b1b050 100644
--- a/app.js
+++ b/app.js
@@ -1029,8 +1029,8 @@ try { if (window.IWBMiniMapFit && typeof window.IWBMiniMapFit.install === 'funct
}
function wResolveImg(v) {
if (v && typeof v === 'object') {
- // C3:引用直出 —— 有 objectURL 就用;否则异步解析一次,__cache 首帧先挂 SW 虚拟路径
- if (wIsBlobRef(v) || wIsCacheRef(v)) {
+ // C3 引用直出(有 objectURL 就用,否则异步解析一次);2026-11-25 补 __file:相册只存路径,漏这个分支会让对象被 String 成 "[object Object]" ⇒ 相册的图在组合节点 / 参考图 / 图片节点里全空(生成不受影响,wImgRefDataUrl 早已支持读盘)
+ if (wIsBlobRef(v) || wIsCacheRef(v) || wIsFileRef(v)) {
const hit = wImgUrlByRef.get(wImgRefKey(v))
if (hit) return hit
wEnsureImgUrl(v)
diff --git a/package.json b/package.json
index 55a24f1..a138b28 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "image-workbench-web",
"private": true,
- "version": "3.26.68",
+ "version": "3.26.69",
"description": "Browser-based node canvas image workbench",
"scripts": {
"build": "node scripts/build.js && node scripts/copy-plugins.js",
@@ -10,7 +10,7 @@
"app:build": "tauri build",
"lint": "eslint src app.js",
"test": "node tests/relay-task-graph-fixture-test.js && node tests/plugin-style-node-test.js && node tests/inherit-text-test.js",
- "test:unit": "node tests/plugin-files-policy-test.js && node tests/theme-plugin-tokens-test.js && node tests/design-tokens-component-doc-test.js && node tests/theme-static-snapshot-test.js && node tests/overlay-layer-test.js && node tests/settings-scope-test.js && node tests/node-scope-test.js && node tests/appearance-v2-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/album-task-graph-test.js && node tests/generation-endpoint-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/gallery-sync-test.js && node tests/image-blob-store-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 && node tests/plugin-scale-contract-test.js && node tests/design-token-ratchet-test.js && node tests/theme-contrast-test.js",
+ "test:unit": "node tests/plugin-files-policy-test.js && node tests/theme-plugin-tokens-test.js && node tests/design-tokens-component-doc-test.js && node tests/theme-static-snapshot-test.js && node tests/overlay-layer-test.js && node tests/settings-scope-test.js && node tests/node-scope-test.js && node tests/appearance-v2-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/album-task-graph-test.js && node tests/generation-endpoint-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/gallery-sync-test.js && node tests/image-blob-store-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 && node tests/plugin-scale-contract-test.js && node tests/design-token-ratchet-test.js && node tests/theme-contrast-test.js && node tests/image-file-ref-preview-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",
diff --git a/plugins/album/main.js b/plugins/album/main.js
index 4477153..2b34116 100644
--- a/plugins/album/main.js
+++ b/plugins/album/main.js
@@ -12,14 +12,18 @@
'use strict'
if (!global.IWBPluginHost) return
- const DENSITY = { S: 64, M: 48, L: 100 }
- const GAP = 5
- const PAD_X = 16 // 宫格左右 padding 合计(与 styles.css 对齐)
- const PAD_Y = 8 // 上下 padding 合计
+ // 密度档位 = 目标单元格边长(px)。1.1.0 修正:旧值 {S:64, M:48, L:100} 里 M 比 S 还小,
+ // 于是「中格」每页装 30 张(比小格的 20 张还多),档位语义是反的。现在 S < M < L 严格递增。
+ const DENSITY = { S: 64, M: 80, L: 104 }
+ // ⚠ 下面这一组必须与 styles.css 逐个对齐(换了 box-sizing / padding 就会算错容量 ⇒ 最后一行被裁)。
+ // 宿主全局 * { box-sizing: border-box },所以 CSS 里写的 height 已含 padding。
+ const GAP = 4 // .iwb-album-grid 的 gap = --iwb-space-4
+ const PAD_X = 16 // 宫格左右 padding 合计(.iwb-album-grid 左右各 --iwb-space-8)
+ const PAD_Y = 8 // 上下 padding 合计(.iwb-album-grid 2px + 6px)
const BAR_H = 26 // 状态栏
- const TOOLS_H = 27 // 工具条
+ const TOOLS_H = 25 // 工具条(padding 2+2 + 按钮 21)
const PAGER_H = 26 // 分页条 / 一页提示条
- const HINT_H = 24 // 批量模式提示行
+ const HINT_H = 28 // 批量模式提示行(含 margin-bottom 4)
const DEFAULT_H = 470 // 注册时声明的默认高度(与 height 字段保持一致)
const THUMB_EDGE = 256
const THUMB_Q = 0.8
@@ -67,6 +71,25 @@
// ── 缩略图(插件私有缓存,几十 KB/张,不碰画布存储)────────────
const thumbNameOf = (key) => 't-' + hash32(key) + '.jpg'
+ // 缩略图缓存键(1.1.0 修「串味」):旧实现是 `fileRefOf(src) || it.name`,一旦固化(src 变成
+ // {__blob})或从别处导入,路径就没了 ⇒ 键退化成纯文件名 ⇒ 不同目录下的 1.png 共用同一张缩略图。
+ // 现在按引用本身取键:路径 → 路径;blob/cache → 各自 id;dataURL → 内容哈希;只有都没有才退回文件名。
+ function thumbKeyOf (it) {
+ const src = (it && it.src) != null ? it.src : it
+ const path = fileRefOf(src)
+ if (path) return 'f:' + path
+ if (src && typeof src === 'object') {
+ if (typeof src.__blob === 'string' && src.__blob) return 'b:' + src.__blob
+ if (typeof src.__cache === 'string' && src.__cache) return 'c:' + src.__cache
+ }
+ if (typeof src === 'string' && src) {
+ if (src.length > 4096) return 'd:' + hash32(src.slice(0, 2048) + src.slice(-2048) + ':' + src.length)
+ return 'd:' + hash32(src)
+ }
+ const n = (it && (it.name || it.size)) || ''
+ return 'n:' + str(n)
+ }
+
function makeThumb (dataUrl) {
return new Promise((resolve) => {
try {
@@ -120,10 +143,14 @@
const st = {
nodeId: node.id,
thumbs: new Map(), // key → dataURL(内存缓存)
+ pending: new Map(), // key → Promise(并发去重:格子挂载和预生成会同时要同一张)
missing: new Set(), // 失联文件的 key
busy: '',
checkedMissing: false,
sig: '',
+ cap: null, // 最近一次容量计算(拖拽排序换算页码要用)
+ lastFull: { key: '', url: '' }, // 原图只保留最近一张(节点内预览用,不做 LRU:多存几张大图就是几十 MB)
+ previewToken: 0,
}
const bar = el('div', { className: 'iwb-album-bar' })
const track = el('span', { className: 'iwb-album-track' }, el('i', null))
@@ -139,7 +166,10 @@
update(st.props || props, cur, { albumMode: next })
})
const count = el('span', { className: 'iwb-album-count' })
- bar.appendChild(modeLabel); bar.appendChild(count)
+ // 一键清空(2026-11-26 用户需求):只清本节点持有的 items,删源文件与画布存储一概不碰。
+ // 走 snapshot:true ⇒ ⌘Z 能整批恢复,所以不加二次确认弹窗(多一步点击反而更烦)。
+ const btnClear = el('button', { className: 'iwb-album-btn iwb-album-clear', title: '清空相册(⌘Z 可撤销;不会删除磁盘上的原文件)' }, '清空')
+ bar.appendChild(modeLabel); bar.appendChild(count); bar.appendChild(btnClear)
const btnAdd = el('button', { className: 'iwb-album-btn', title: '选择本地图片(桌面端只引用,不复制字节)' }, '+ 添加图片')
const btnDir = el('button', { className: 'iwb-album-btn', title: '按文件夹批量添加' }, '文件夹')
@@ -161,11 +191,16 @@
])
const pager = el('div', { className: 'iwb-album-pager' })
const onepage = el('div', { className: 'iwb-album-onepage' }, '全部图片一页展示')
+ // 节点内预览层(放大镜 hover 时出现):铺满整个节点框,绝不越界到画布。
+ // pointer-events:none ⇒ 底下的格子仍然能点(点穿 = 切换选中,不会「卡住」在预览里)。
+ const previewImg = el('img', { alt: '', draggable: 'false' })
+ const previewName = el('span', { className: 'iwb-album-preview-name' })
+ const preview = el('div', { className: 'iwb-album-preview' }, [previewImg, previewName])
host.textContent = ''
- const root = el('div', { className: 'iwb-album' }, [bar, tools, hint, grid, empty, pager, onepage])
+ const root = el('div', { className: 'iwb-album' }, [bar, tools, hint, grid, empty, pager, onepage, preview])
host.appendChild(root)
- Object.assign(st, { root, bar, track, count, btnAdd, btnDir, btnSettle, segs, grid, empty, pager, onepage, hint })
+ Object.assign(st, { root, bar, track, count, btnClear, btnAdd, btnDir, btnSettle, segs, grid, empty, pager, onepage, hint, preview, previewImg, previewName })
// 按钮绑定(用闭包里的当前 node/props:每次 sync 会更新 st.node/st.props)
btnAdd.addEventListener('pointerdown', (e) => e.stopPropagation())
@@ -174,6 +209,8 @@
btnDir.addEventListener('click', (e) => { e.stopPropagation(); pickFiles(ctx, st, host, true) })
btnSettle.addEventListener('pointerdown', (e) => e.stopPropagation())
btnSettle.addEventListener('click', (e) => { e.stopPropagation(); settleAll(ctx, st) })
+ btnClear.addEventListener('pointerdown', (e) => e.stopPropagation())
+ btnClear.addEventListener('click', (e) => { e.stopPropagation(); clearAll(ctx, st) })
// 拖拽入图:桌面端拿不到绝对路径 ⇒ 按「方案 1」复制进画布存储
host.addEventListener('dragover', (e) => { e.preventDefault(); e.stopPropagation() })
@@ -202,6 +239,7 @@
const wantH = Math.max(120, Math.round(cardH) - 4) + 'px'
if (st.root.style.height !== wantH) st.root.style.height = wantH
const cap = capacityOf(cardW, cardH, density, mode === 'batch')
+ st.cap = cap // 拖拽排序换算「本页第 i 格 → 全局第几格」要用(旧代码用格子数,把「+添加」也算进去了)
const pages = Math.max(1, Math.ceil(items.length / cap.capacity))
const page = Math.max(0, Math.min(pages - 1, Number(d.page) || 0))
const from = page * cap.capacity
@@ -217,7 +255,11 @@
for (const k in st.segs) st.segs[k].className = (density === k ? 'on' : '')
const hasFileRef = items.some((it) => fileRefOf(it && it.src))
st.btnSettle.style.display = hasFileRef ? '' : 'none'
- st.btnDir.style.display = (ctx.images && ctx.images.canReference()) || true ? '' : 'none'
+ // 「文件夹」只在能做路径引用的宿主里有意义(桌面端)。旧写法 `canReference() || true` 恒真,
+ // 于是在网页版点它永远没反应。网页版仍可用「+ 添加图片」走文件选择器。
+ const canRef = !!(ctx.images && typeof ctx.images.canReference === 'function' && ctx.images.canReference())
+ st.btnDir.style.display = canRef ? '' : 'none'
+ st.btnClear.style.display = items.length ? '' : 'none'
if (st.busy) { st.btnAdd.textContent = st.busy } else { st.btnAdd.textContent = '+ 添加图片' }
// 批量模式提示:N 张 → M 个任务(每组 ≤ 12)
@@ -230,10 +272,12 @@
} else st.hint.style.display = 'none'
// 分页条 / 一页展示
+ // 空节点不再显示「全部 0 张一页展示」那条灰条(2026-11-26):它压着空态提示,说的还是废话。
const showPager = pages > 1
+ const showOne = !showPager && items.length > 0
st.pager.style.display = showPager ? '' : 'none'
- st.onepage.style.display = showPager ? 'none' : ''
- if (!showPager) st.onepage.textContent = '全部 ' + items.length + ' 张一页展示 · 无需翻页'
+ st.onepage.style.display = showOne ? '' : 'none'
+ if (showOne) st.onepage.textContent = '全部 ' + items.length + ' 张一页展示 · 无需翻页'
if (showPager) {
st.pager.innerHTML = ''
const pg = el('span', { className: 'iwb-album-pg' })
@@ -263,7 +307,7 @@
// 宫格(签名不变就不重建:避免每帧重排导致闪烁/丢拖拽态)
const sig = [node.id, density, page, cap.capacity, mode, items.length, d.onlyPage === true ? 1 : 0,
- items.map((it) => (it && (fileRefOf(it.src) || it.name) + (it && it.on === false ? ':0' : ':1')) || '').join(','), Array.from(st.missing).join(',')].join('|')
+ items.map((it) => thumbKeyOf(it) + (it && it.on === false ? ':0' : ':1')).join(','), Array.from(st.missing).join(',')].join('|')
if (sig !== st.sig) {
st.sig = sig
st.grid.innerHTML = ''
@@ -291,10 +335,23 @@
}
// ── 单元格 ──────────────────────────────────────────────
+ // 放大镜图标(内联 SVG,CSP 禁外部资源):圆 + 手柄,10px 下仍看得清
+ function zoomIcon () {
+ const NS = 'http://www.w3.org/2000/svg'
+ const mk = (tag, attrs) => {
+ const n = document.createElementNS(NS, tag)
+ for (const k in attrs) n.setAttribute(k, attrs[k])
+ return n
+ }
+ const svg = mk('svg', { viewBox: '0 0 24 24', 'aria-hidden': 'true' })
+ svg.appendChild(mk('circle', { cx: 10, cy: 10, r: 7, fill: 'none', stroke: 'currentColor', 'stroke-width': 2.4 }))
+ svg.appendChild(mk('path', { d: 'M15.2 15.2 21 21', fill: 'none', stroke: 'currentColor', 'stroke-width': 2.4, 'stroke-linecap': 'round' }))
+ return svg
+ }
function cellOf (ctx, st, it, index, mode) {
const src = it && it.src
const path = fileRefOf(src)
- const key = path || str(it && it.name) || String(index)
+ const key = thumbKeyOf(it)
const on = !(it && it.on === false)
const missing = path && st.missing.has(path)
const btn = el('button', {
@@ -304,22 +361,35 @@
const img = el('img', { alt: '', draggable: 'false' })
const cached = st.thumbs.get(key)
if (cached) img.src = cached
- else {
- img.src = ''
- loadThumb(ctx, st, it, key).then((url) => { if (url) img.src = url })
- }
+ // 不设 img.src = '':空字符串会向页面 URL 发一次请求(控制台 ERR_UNKNOWN_URL_SCHEME)。
+ // 不设 src 属性时
什么都不做,缩略图到了再赋上即可。
+ else loadThumb(ctx, st, it, key).then((url) => { if (url && img.isConnected !== false) img.src = url })
btn.appendChild(img)
btn.appendChild(el('span', { className: 'iwb-album-idx' }, String(index + 1)))
- if (mode === 'batch' && on) btn.appendChild(el('span', { className: 'iwb-album-batch' }, String(Math.floor(index / 12) + 1)))
- const del = el('span', { className: 'iwb-album-del', title: '移除' }, '×')
+ // 批次角标(右上角那个「1」)已删除:顶栏「N 张 → M 个任务」已经说清楚,角标是重复信息,
+ // 还会和删除按钮抢同一个角。位置让给了 ×。
+ const del = el('span', { className: 'iwb-album-del', title: '移除(不删除磁盘上的原文件)' }, '×')
del.addEventListener('pointerdown', (e) => e.stopPropagation())
del.addEventListener('click', (e) => {
e.stopPropagation()
const items = itemsOf(st.node).slice()
items.splice(index, 1)
- update(st.props, st.node, { items, page: 0 }, true)
+ // 删除后留在当前页(旧实现硬编码 page:0,第 2 页删一张直接跳回第 1 页)。
+ // 只做「页数变少时往回收」,正常情况 page 不动。
+ const capNow = st.cap || { capacity: 20 }
+ const pagesNow = Math.max(1, Math.ceil(items.length / capNow.capacity))
+ const pageNow = Math.max(0, Number((st.node.data || {}).page) || 0)
+ hidePreview(st, true)
+ update(st.props, st.node, { items: items, page: Math.min(pageNow, pagesNow - 1) }, true)
})
btn.appendChild(del)
+ // 放大镜(右下角):hover 在节点框内预览,点一下进宿主全屏预览
+ const zoom = el('span', { className: 'iwb-album-zoom', title: '预览大图(点一下全屏)' }, zoomIcon())
+ zoom.addEventListener('pointerdown', (e) => e.stopPropagation())
+ zoom.addEventListener('pointerenter', () => showPreview(ctx, st, it, key))
+ zoom.addEventListener('pointerleave', () => hidePreview(st, false))
+ zoom.addEventListener('click', (e) => { e.stopPropagation(); openFull(ctx, st, it) })
+ btn.appendChild(zoom)
btn.addEventListener('pointerdown', (e) => e.stopPropagation())
btn.addEventListener('click', (e) => {
e.stopPropagation()
@@ -356,16 +426,19 @@
Array.from(st.grid.querySelectorAll('.dropbefore')).forEach((c) => c.classList.remove('dropbefore'))
if (!moved) return
const items = itemsOf(st.node).slice()
- const cellCount = st.grid.querySelectorAll('.iwb-album-cell').length
- const pageStart = (Number((st.node.data || {}).page) || 0) * cellCount
- const from = pageStart
+ // 1.1.0 修跨页错位:本页起点 = page × **每页容量**(旧代码乘的是「本页格子数」,而格子数里
+ // 还含末尾那个「+添加」格 ⇒ 第 2 页永远算少一格,把 21 号拖到第 2 位会插到全局第 13 位)。
+ const capNow = st.cap || { capacity: 20 }
+ const pageNow = Math.max(0, Number((st.node.data || {}).page) || 0)
+ const pageStart = pageNow * capNow.capacity
+ const realCount = Math.min(capNow.capacity, Math.max(0, items.length - pageStart))
const srcIndex = index
- let dest = from + target.index
+ let dest = pageStart + Math.min(target.index, realCount)
if (dest === srcIndex || dest < 0) return
const [movedItem] = items.splice(srcIndex, 1)
if (dest > srcIndex) dest -= 1
items.splice(Math.max(0, Math.min(items.length, dest)), 0, movedItem)
- update(st.props, st.node, { items }, true)
+ update(st.props, st.node, { items: items }, true)
}
document.addEventListener('pointermove', onMove)
document.addEventListener('pointerup', onUp)
@@ -374,7 +447,17 @@
}
// ── 缩略图取用:内存 → 插件文件 → 现做 ───────────────────
+ // 并发去重(1.1.0):格子一挂载就各自要缩略图,而 addPaths 又顺序预热一遍 ⇒ 同一张图会被读两次盘。
+ // 用 pending 表把同 key 的请求合成一个 Promise(否则导入 30 张会解 60 次原图,内存直接翻倍)。
async function loadThumb (ctx, st, it, key) {
+ if (st.thumbs.has(key)) return st.thumbs.get(key)
+ const flight = st.pending && st.pending.get(key)
+ if (flight) return flight
+ const p = loadThumbInner(ctx, st, it, key).finally(() => { if (st.pending) st.pending.delete(key) })
+ if (st.pending) st.pending.set(key, p)
+ return p
+ }
+ async function loadThumbInner (ctx, st, it, key) {
if (st.thumbs.has(key)) return st.thumbs.get(key)
const name = thumbNameOf(key)
try {
@@ -394,10 +477,72 @@
const thumb = await makeThumb(dataUrl)
if (!thumb) return ''
st.thumbs.set(key, thumb)
- try { if (ctx.files) await ctx.files.put(name, thumb) } catch (e) { /* 配额满就只留内存 */ }
+ // 内存里已经有一张就够本会话用了;写盘失败(配额满)不影响显示
+ try { if (ctx.files) await ctx.files.put(name, thumb) } catch (e) { /* ignore */ }
return thumb
}
+ // ── 节点内预览(放大镜 hover)──────────────────────────────
+ // 用户定的交互:鼠标移到格子右下角放大镜 → 节点框内浮出大图;再点一下 → 宿主全屏预览。
+ // 预览层铺满节点(position:absolute; inset:0),所以「大图」永不出节点框,也不挡画布别处。
+ function hidePreview (st, now) {
+ if (!st || !st.preview) return
+ if (st.hideTimer) { clearTimeout(st.hideTimer); st.hideTimer = null }
+ if (now) { st.preview.classList.remove('on'); st.previewToken++; return }
+ // 140ms 宽限:从放大镜边缘滑出去时不会闪一下就没(也不必让用户精准停在圆点上)
+ st.hideTimer = setTimeout(() => {
+ st.hideTimer = null
+ st.preview.classList.remove('on')
+ st.previewToken++
+ }, 140)
+ }
+ function showPreview (ctx, st, it, key) {
+ if (!st || !st.preview) return
+ if (st.hideTimer) { clearTimeout(st.hideTimer); st.hideTimer = null }
+ const cached = st.thumbs.get(key) || ''
+ if (cached) st.previewImg.src = cached
+ else st.previewImg.removeAttribute('src') // 绝不设 src='':那会向页面 URL 发一次请求
+ st.previewName.textContent = (it && it.name) || ''
+ st.preview.classList.add('on')
+ const token = ++st.previewToken
+ // 原图只留最近一张:节点内预览要看得清(缩略图 256px 拉宽到 600 就糊),但多存几张 4K dataURL
+ // 就是几十 MB 常驻内存。留一张,来回 hover 同一张不重复读盘。
+ if (st.lastFull.key === key && st.lastFull.url) { st.previewImg.src = st.lastFull.url; return }
+ if (!ctx.images || typeof ctx.images.dataUrl !== 'function') return
+ try {
+ Promise.resolve(ctx.images.dataUrl(it && it.src)).then((url) => {
+ if (!url) return
+ st.lastFull = { key: key, url: url }
+ if (token === st.previewToken && st.preview.classList.contains('on')) st.previewImg.src = url
+ }).catch(() => { /* 读盘失败就用缩略图 */ })
+ } catch (e) { /* ignore */ }
+ }
+ // 点放大镜 → 宿主全屏预览(props.onPreview 是宿主给的,节点体里拿得到)
+ function openFull (ctx, st, it) {
+ hidePreview(st, true)
+ const props = st.props || {}
+ if (typeof props.onPreview !== 'function') return
+ const fallback = st.thumbs.get(thumbKeyOf(it)) || ''
+ const run = (url) => { try { props.onPreview(url || fallback) } catch (e) { /* ignore */ } }
+ if (!ctx.images || typeof ctx.images.dataUrl !== 'function') { run(fallback); return }
+ try {
+ Promise.resolve(ctx.images.dataUrl(it && it.src)).then((u) => run(u)).catch(() => run(''))
+ } catch (e) { run(fallback) }
+ }
+
+ // ── 一键清空 ────────────────────────────────────────────
+ function clearAll (ctx, st) {
+ const items = itemsOf(st.node)
+ if (!items.length) return
+ st.thumbs.clear(); st.pending.clear(); st.missing.clear()
+ st.lastFull = { key: '', url: '' }
+ st.checkedMissing = false // 清空后再导入要重新做一次失联检测
+ hidePreview(st, true)
+ update(st.props, st.node, { items: [], page: 0, pageRange: null }, true)
+ st.sig = ''
+ sync(ctx, st, st.node, st.props)
+ }
+
// ── 导入:选择器 / 文件夹 / 拖入 / 固化 / 重新定位 ──────────
async function pickFiles (ctx, st, host, directory) {
if (st.busy) return
@@ -437,7 +582,6 @@
async function addPaths (ctx, st, paths) {
const list = paths.filter(isImagePath)
const items = itemsOf(st.node).slice()
- const keep = (st.node.data && st.node.data.keepOriginal !== false)
for (let i = 0; i < list.length; i++) {
st.busy = '导入 ' + (i + 1) + '/' + list.length; st.sig = ''; sync(ctx, st, st.node, st.props)
const ref = await ctx.images.reference(list[i])
@@ -445,14 +589,23 @@
items.push({ src: { __file: ref.item.path }, name: ref.item.name, size: ref.item.size, mtime: ref.item.mtime, on: true })
}
st.busy = ''
+ st.checkedMissing = false // 新图要重新做一次失联检测(否则清空后再导入,检测永远不再跑)
update(st.props, st.node, { items }, true)
st.sig = ''
sync(ctx, st, st.node, st.props)
- // 顺序生成缩略图(避免一次读几十张原图造成内存尖峰)
- for (const it of items) {
- const key = fileRefOf(it.src) || it.name
- if (key) await loadThumb(ctx, st, it, key)
+ // 顺序预生成缩略图(避免一次读几十张原图造成内存尖峰)。
+ // 1.1.0:进度写进「+ 添加图片」按钮(旧实现 busy 在这里已经清空 ⇒ 导入 500 张时界面像卡死);
+ // 只改按钮文字、不重置 sig ⇒ 不触发整块宫格重建(重建 500 次比读盘本身还慢)。
+ for (let i = 0; i < items.length; i++) {
+ const it = items[i]
+ const key = thumbKeyOf(it)
+ if (!key || st.thumbs.has(key)) continue
+ st.busy = '缩略图 ' + (i + 1) + '/' + items.length
+ st.btnAdd.textContent = st.busy
+ await loadThumb(ctx, st, it, key)
}
+ st.busy = ''
+ st.btnAdd.textContent = '+ 添加图片'
st.sig = ''
sync(ctx, st, st.node, st.props)
}
@@ -473,11 +626,17 @@
const src = res.ref || res.data
if (!src) continue
const name = f.name || ('图 ' + (items.length + 1))
- items.push({ src, name, size: f.size || 0, on: true })
+ items.push({ src, name: name, size: f.size || 0, on: true })
const thumb = await makeThumb(dataUrl)
- if (thumb) { st.thumbs.set(name, thumb); try { if (ctx.files) await ctx.files.put(thumbNameOf(name), thumb) } catch (e) { /* ignore */ } }
+ // 键必须和 cellOf / loadThumb 完全一致(thumbKeyOf),否则写进缓存也命中不到
+ if (thumb) {
+ const key = thumbKeyOf(items[items.length - 1])
+ st.thumbs.set(key, thumb)
+ try { if (ctx.files) await ctx.files.put(thumbNameOf(key), thumb) } catch (e) { /* ignore */ }
+ }
}
st.busy = ''
+ st.checkedMissing = false
update(st.props, st.node, { items }, true)
st.sig = ''
sync(ctx, st, st.node, st.props)
@@ -534,7 +693,7 @@
update(st.props, st.node, { items }, true)
st.sig = ''
sync(ctx, st, st.node, st.props)
- loadThumb(ctx, st, items[index], fileRefOf(items[index].src)).then(() => { st.sig = ''; try { sync(ctx, st, st.node, st.props) } catch (e) { /* ignore */ } })
+ loadThumb(ctx, st, items[index], thumbKeyOf(items[index])).then(() => { st.sig = ''; try { sync(ctx, st, st.node, st.props) } catch (e) { /* ignore */ } })
}
@@ -543,7 +702,7 @@
global.IWBPluginHost.register({
id: 'album',
name: '相册',
- version: '1.0.4',
+ version: '1.1.0',
apiVersion: 1,
capabilities: ['nodeTypes', 'images', 'files'],
settings: {
diff --git a/plugins/album/manifest.json b/plugins/album/manifest.json
index 98de4f2..aea827c 100644
--- a/plugins/album/manifest.json
+++ b/plugins/album/manifest.json
@@ -1,7 +1,7 @@
{
"id": "album",
"name": "相册",
- "version": "1.0.4",
+ "version": "1.1.0",
"apiVersion": 1,
"main": "main.js",
"style": "styles.css",
@@ -14,7 +14,7 @@
"出图"
],
"files": {
- "main.js": "c359d25928f93bbbaac07dd12500226405b21918f3488fcb40bb79d5c45fe01d",
- "styles.css": "ada02ea71832d63c8ebe9e07d03dfb7d71f6d1471366f1f4e6c7eeab736dc573"
+ "main.js": "7d98527ad1854e72afdea2f36a067402f4a0d7337f2160c5a3bd86966663a735",
+ "styles.css": "7847e742ea27688743b97cb289d373deb44c2cd800f4c1f60f2b5df929b70283"
}
}
diff --git a/plugins/album/styles.css b/plugins/album/styles.css
index fd6d496..1be212f 100644
--- a/plugins/album/styles.css
+++ b/plugins/album/styles.css
@@ -2,7 +2,7 @@
* 宿主只给一块空容器(.iwb-plugin-node-body),所有排版由这里决定。
* 尺寸全部用像素而不是 rem:节点宽度是可拖拽的(264~600),rem 会跟着宿主字号漂移。
*/
-.iwb-album { display: flex; flex-direction: column; height: 100%; overflow: hidden; font-size: 11px; color: var(--iwb-node-text); }
+.iwb-album { position: relative; display: flex; flex-direction: column; height: 100%; overflow: hidden; font-size: 11px; color: var(--iwb-node-text); }
.iwb-album-bar, .iwb-album-tools, .iwb-album-pager, .iwb-album-onepage {
display: flex; align-items: center; gap: var(--iwb-space-6); padding: var(--iwb-space-4) var(--iwb-space-8); flex: 0 0 auto;
}
@@ -13,27 +13,48 @@
.iwb-album-track i { position: absolute; top: 1.5px; left: 1.5px; width: 9px; height: 9px; border-radius: 50%; background: var(--iwb-panel); transition: left .15s; }
.iwb-album-track.on { background: var(--iwb-brand); }
.iwb-album-track.on i { left: 11.5px; }
-.iwb-album-count { margin-left: auto; font-size: var(--iwb-font-2xs); color: var(--iwb-node-text2); white-space: nowrap; }
+.iwb-album-count { margin-left: auto; font-size: var(--iwb-font-2xs); color: var(--iwb-node-text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iwb-album-count b { color: var(--iwb-node-text); font-weight: 600; }
.iwb-album-btn { height: 21px; padding: 0 var(--iwb-space-8); border: 1px solid var(--iwb-border); border-radius: var(--iwb-radius-chip); background: var(--iwb-panel); color: var(--iwb-node-text2); font-size: var(--iwb-font-2xs); display: inline-flex; align-items: center; gap: var(--iwb-space-4); cursor: pointer; white-space: nowrap; }
.iwb-album-btn:hover { border-color: var(--iwb-brand); color: var(--iwb-node-text); }
.iwb-album-btn.on { border-color: var(--iwb-brand); color: var(--iwb-node-text); }
+/* 清空:常驻在顶栏最右,只有相册里有图时才出现。hover 转红是为了和「添加」一类中性操作区分开。 */
+.iwb-album-clear { flex: 0 0 auto; padding: 0 var(--iwb-space-6); }
+.iwb-album-clear:hover { border-color: #c0392b; color: #c0392b; }
.iwb-album-seg { margin-left: auto; display: inline-flex; border: 1px solid var(--iwb-border); border-radius: var(--iwb-radius-chip); overflow: hidden; }
.iwb-album-seg span { width: 21px; height: 21px; display: inline-flex; align-items: center; justify-content: center; font-size: var(--iwb-font-2xs); color: var(--iwb-node-text2); background: var(--iwb-panel); cursor: pointer; }
.iwb-album-seg span.on { background: var(--iwb-brand); color: var(--iwb-on-brand); }
.iwb-album-grid { display: grid; gap: var(--iwb-space-4); padding: var(--iwb-space-2) var(--iwb-space-8) var(--iwb-space-6); overflow: hidden; align-content: start; flex: 1 1 auto; min-height: 0; }
-.iwb-album-cell { position: relative; border-radius: var(--iwb-radius-chip); overflow: hidden; background: color-mix(in srgb, var(--iwb-border) 55%, transparent); border: 1px solid var(--iwb-border); cursor: grab; }
+/* 格子固定正方形(2026-11-26):此前高度由图片比例决定 —— 4 张 16:9 宽图会变成 22px 细条、
+ 竖图撑到 167px,和 capacityOf() 按方形算的容量是两套账(最后一行常被裁一半)。
+ aspect-ratio 让每一格高 = 宽,容量因此可精确预测,宫格也终于整齐。
+ padding:0 必须显式写: