diff --git a/gallery/package.json b/gallery/package.json index 57579e0..a71ddf8 100644 --- a/gallery/package.json +++ b/gallery/package.json @@ -1,7 +1,7 @@ { "name": "@iwb-plugin/gallery", "private": true, - "version": "1.6.10", + "version": "1.6.11", "description": "图库:右栏图片墙(筛选/多选/预览/插入画布/下载/删除),数据由宿主 gallery 能力提供", "ibwPlugin": { "id": "gallery", diff --git a/gallery/src/index.js b/gallery/src/index.js index ee56dc9..8e5fafe 100644 --- a/gallery/src/index.js +++ b/gallery/src/index.js @@ -300,6 +300,11 @@ function renderGrid () { clear(grid) var gap = 6 + // 每次重排都重新量一次宽度:面板显隐/停靠栏展开时 gridW 可能是旧值, + // 只靠 ResizeObserver 会在「变成 0 再回来」期间漏掉,导致必须拖宽度才出图。 + var liveW = availableW() + if (liveW > 0 && Math.abs(liveW - gridW) > 1) gridW = liveW + if (!gridW) gridW = 320 var tileW = Math.max(40, Number(cfg.tile) || 110) var n = Math.max(1, Math.floor((gridW + gap) / (tileW + gap))) // v1.6.6:列宽 = 均分宽度(铺满面板),图幅只决定「列数」—— @@ -368,7 +373,7 @@ 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' }) + var img = el('img', { src: url, alt: '', loading: 'eager', draggable: 'true' }) if (it.w && it.h) img.setAttribute('style', 'aspect-ratio:' + it.w + ' / ' + it.h) img.addEventListener('load', function () { // naturalWidth=0 说明拿到的是坏图(空 data URL / 截断文件):按失败处理,别留白块 @@ -407,7 +412,7 @@ if (img.parentNode === box) box.replaceChild(holder, img) fail('缩略图加载失败(点击重试)') } catch (e) { /* ignore */ } - }, 700) + }, 2000) // 加载成功后再替换占位(避免破图标 + 长 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('缩略图加载失败(点击重试)') } } @@ -447,7 +452,7 @@ render() } - function render () { renderHead(); renderGrid() } + function render () { renderHead(); renderGrid(); global.requestAnimationFrame(function () { try { measure() } catch (e) {} }); setTimeout(function () { try { measure() } catch (e) {} }, 150) } function load (force) { if (force) setStatus('刷新中…') @@ -538,7 +543,7 @@ global.IWBPluginHost.register({ id: 'gallery', name: '图库', - version: '1.6.10', + version: '1.6.11', apiVersion: 1, capabilities: ['panels', 'gallery'], data: { schemaVersion: 1, maxBytes: 65536 },