diff --git a/plugins/album/main.js b/plugins/album/main.js index 2b34116..f0e4efe 100644 --- a/plugins/album/main.js +++ b/plugins/album/main.js @@ -149,8 +149,6 @@ 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)) @@ -191,16 +189,13 @@ ]) 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]) + // 节点内 hover 预览层已于 1.1.1 移除(用户实测:鼠标移到放大镜上时预览层盖住图标,反而点不到)。 + // 现在只看大图走「点击放大镜 → 宿主全屏预览(props.onPreview)」,点图片外或 Esc 自动退出。 host.textContent = '' - const root = el('div', { className: 'iwb-album' }, [bar, tools, hint, grid, empty, pager, onepage, preview]) + const root = el('div', { className: 'iwb-album' }, [bar, tools, hint, grid, empty, pager, onepage]) host.appendChild(root) - Object.assign(st, { root, bar, track, count, btnClear, btnAdd, btnDir, btnSettle, segs, grid, empty, pager, onepage, hint, preview, previewImg, previewName }) + Object.assign(st, { root, bar, track, count, btnClear, btnAdd, btnDir, btnSettle, segs, grid, empty, pager, onepage, hint }) // 按钮绑定(用闭包里的当前 node/props:每次 sync 会更新 st.node/st.props) btnAdd.addEventListener('pointerdown', (e) => e.stopPropagation()) @@ -379,15 +374,13 @@ 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()) + // 放大镜(右下角):点击 → 宿主全屏预览。1.1.1 去掉了 hover 预览(会盖住放大镜导致点不到, + // 用户实测),只留「点一下看大图」这一条路径:宿主预览点图片外的空白或按 Esc 自动退出。 + const zoom = el('span', { className: 'iwb-album-zoom', title: '查看大图(点击空白处或按 Esc 关闭)' }, 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()) @@ -482,50 +475,21 @@ 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 是宿主给的,节点体里拿得到) + // ── 看大图:只走宿主全屏预览(1.1.1 定了唯一交互)──────────── + // 历史:1.1.0 曾做「hover 放大镜 → 节点框内浮大图(pointer-events:none)+ 点击全屏」两套。 + // 实测否决:hover 一进就把整块节点压暗(预览层 z-index 9),放大镜本身被盖在下面 ⇒ + // 用户看到的是「滑过去就不能点了」。现在删掉 A,只保留 B: + // 点放大镜 → props.onPreview 打开宿主预览层(铺满窗口); + // 点图片外的空白 / 按 Esc → 宿主自己 onClose(见 src/ui-canvas-view.js 的 ImagePreview)。 + // 代价是「看一眼」也要点两下,但少一层状态,点到哪就是哪,不会再互相打架。 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) } } @@ -535,9 +499,7 @@ 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) @@ -702,7 +664,7 @@ global.IWBPluginHost.register({ id: 'album', name: '相册', - version: '1.1.0', + version: '1.1.1', apiVersion: 1, capabilities: ['nodeTypes', 'images', 'files'], settings: { diff --git a/plugins/album/manifest.json b/plugins/album/manifest.json index aea827c..fe3997f 100644 --- a/plugins/album/manifest.json +++ b/plugins/album/manifest.json @@ -1,7 +1,7 @@ { "id": "album", "name": "相册", - "version": "1.1.0", + "version": "1.1.1", "apiVersion": 1, "main": "main.js", "style": "styles.css", @@ -14,7 +14,7 @@ "出图" ], "files": { - "main.js": "7d98527ad1854e72afdea2f36a067402f4a0d7337f2160c5a3bd86966663a735", - "styles.css": "7847e742ea27688743b97cb289d373deb44c2cd800f4c1f60f2b5df929b70283" + "main.js": "7504415606e494d7f9c3dafc67aff032fb7f5a18b7851ab897fcf303567b04c0", + "styles.css": "02ffd5a87281c955aa10f323b0f36487dc8e2a8dd394bc500273cb4e6f5db509" } } diff --git a/plugins/album/styles.css b/plugins/album/styles.css index 1be212f..49646ba 100644 --- a/plugins/album/styles.css +++ b/plugins/album/styles.css @@ -44,17 +44,13 @@ .iwb-album-del { position: absolute; right: var(--iwb-space-2); top: var(--iwb-space-2); width: 15px; height: 15px; border-radius: 50%; background: var(--iwb-panel); color: var(--iwb-node-text2); font-size: 11px; line-height: 1; display: flex; align-items: center; justify-content: center; opacity: 0; cursor: pointer; } .iwb-album-cell:hover .iwb-album-del { opacity: 1; } /* 放大镜:右下角,hover 才出现(静息态不抢视觉,和 × 一致)。 - 18px 圆 / 12px 图标:10px 时镜片只有 5px,缩到小截图里就成一团白点了。 */ -.iwb-album-zoom { position: absolute; right: var(--iwb-space-2); bottom: var(--iwb-space-2); width: 17px; height: 17px; border-radius: 50%; background: var(--iwb-panel); color: var(--iwb-node-text2); display: flex; align-items: center; justify-content: center; opacity: 0; cursor: zoom-in; transition: opacity .12s; } -.iwb-album-cell:hover .iwb-album-zoom { opacity: 1; } + 17px 圆 / 12px 图标:再小镜片就缩成一团白点。 + z-index 高于图与角标:1.1.0 时它被节点内预览层(z-index 9)盖住 ⇒ 用户反馈「滑过去就点不到」, + 那层已在 1.1.1 删除;这里仍显式抬一层,避免以后再加浮层时重犯。 */ +.iwb-album-zoom { position: absolute; right: var(--iwb-space-2); bottom: var(--iwb-space-2); z-index: 3; width: 17px; height: 17px; border-radius: 50%; background: var(--iwb-panel); color: var(--iwb-node-text2); display: flex; align-items: center; justify-content: center; opacity: 0; cursor: zoom-in; transition: opacity .12s; } +.iwb-album-cell:hover .iwb-album-zoom, .iwb-album-cell:focus-within .iwb-album-zoom { opacity: 1; } .iwb-album-zoom:hover { color: var(--iwb-brand); } .iwb-album-zoom svg { width: 12px; height: 12px; display: block; } -/* 节点内预览层:铺满节点框(用户要求「大图显示范围控制在节点框内」),绝不溢出到画布。 - 点放大镜后出现的浮层 —— pointer-events:none 所以不会挡住下面格子的点击(点穿到底层格子 = 切换选中,符合预期)。*/ -.iwb-album-preview { position: absolute; inset: 0; z-index: 9; display: none; align-items: center; justify-content: center; background: rgba(12,16,22,.82); pointer-events: none; } -.iwb-album-preview.on { display: flex; } -.iwb-album-preview img { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; display: block; } -.iwb-album-preview-name { position: absolute; left: var(--iwb-space-8); bottom: var(--iwb-space-6); right: var(--iwb-space-8); color: #fff; font-size: var(--iwb-font-2xs); opacity: .82; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .iwb-album-add { border: 1px dashed var(--iwb-border); background: transparent; color: var(--iwb-node-text2); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--iwb-space-2); font-size: var(--iwb-font-2xs); border-radius: var(--iwb-radius-chip); cursor: pointer; } .iwb-album-add b { font-size: 15px; line-height: 1; font-weight: 600; } .iwb-album-pager { border-top: 1px solid color-mix(in srgb, var(--iwb-border) 55%, transparent); height: 26px; } diff --git a/plugins/index.json b/plugins/index.json index 92fc759..0463d5e 100644 --- a/plugins/index.json +++ b/plugins/index.json @@ -4,10 +4,10 @@ "dir": "album", "main": "main.js", "style": "styles.css", - "version": "1.1.0", + "version": "1.1.1", "files": { - "main.js": "7d98527ad1854e72afdea2f36a067402f4a0d7337f2160c5a3bd86966663a735", - "styles.css": "7847e742ea27688743b97cb289d373deb44c2cd800f4c1f60f2b5df929b70283" + "main.js": "7504415606e494d7f9c3dafc67aff032fb7f5a18b7851ab897fcf303567b04c0", + "styles.css": "02ffd5a87281c955aa10f323b0f36487dc8e2a8dd394bc500273cb4e6f5db509" } }, { diff --git a/site/dev/index.html b/site/dev/index.html index 60950b6..a4f2975 100644 --- a/site/dev/index.html +++ b/site/dev/index.html @@ -3,7 +3,7 @@