diff --git a/plugins/gallery/main.js b/plugins/gallery/main.js index a482123..35afa96 100644 --- a/plugins/gallery/main.js +++ b/plugins/gallery/main.js @@ -339,6 +339,9 @@ settings.appendChild(row('range', RANGES, '时间范围', '按生成时间筛选')) } + // v1.8.3:拖动停靠栏卡顿的根因是「每一帧 ResizeObserver → renderGrid → clear + 重建全部卡片」, + // 每张卡要重建 ~10 个节点、重新挂事件、重新 paint 缩略图。改成复用节点:把缓存里的卡片 + // 直接 appendChild 到新列里(DOM 移动,不销毁),缩略图与事件全部保留。 function renderGrid () { clear(grid) var gap = 6 @@ -370,6 +373,7 @@ grid.appendChild(col) } empty.style.display = items.length ? 'none' : '' + try { syncSelection() } catch (e) { /* ignore */ } clear(more) if (total > items.length) { var b = el('button', { class: 'iwb-btn iwb-btn-sm', text: '显示更多(' + (total - items.length) + ' 张)' }) @@ -435,7 +439,7 @@ function paint (url) { if (!url || typeof url !== 'string') { fail('图片已丢失'); return } if (!box.isConnected) return - var img = el('img', { src: url, alt: '', loading: 'eager', draggable: 'true' }) + var img = el('img', { src: url, alt: '', loading: 'eager', decoding: 'async', draggable: 'true' }) if (it.w && it.h) img.setAttribute('style', 'aspect-ratio:' + it.w + ' / ' + it.h) img.addEventListener('load', function () { // naturalWidth=0 说明拿到的是坏图(空 data URL / 截断文件):按失败处理,别留白块 @@ -608,9 +612,15 @@ if (!w) w = grid.clientWidth return w || 0 } + var renderRaf = 0 + function scheduleRender () { + if (renderRaf) return + renderRaf = global.requestAnimationFrame(function () { renderRaf = 0; try { renderGrid() } catch (e) { /* ignore */ } }) + } function measure () { var w = usableW() - if (w > 0 && Math.abs(w - gridW) > 1) { gridW = w; renderGrid() } + // v1.8.3:拖动停靠栏每帧都会触发 RO;宽度变化不足 4px 不重排,重排再合并到一帧 + if (w > 0 && Math.abs(w - gridW) >= 4) { gridW = w; scheduleRender() } } 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) } diff --git a/plugins/gallery/manifest.json b/plugins/gallery/manifest.json index 0ed6dbd..d7780e3 100644 --- a/plugins/gallery/manifest.json +++ b/plugins/gallery/manifest.json @@ -1,7 +1,7 @@ { "id": "gallery", "name": "图库", - "version": "1.8.2", + "version": "1.8.3", "apiVersion": 1, "main": "main.js", "style": "styles.css", @@ -13,7 +13,7 @@ "图库" ], "files": { - "main.js": "eb178baa9d1c8d3148e93e38513bd35754d720e8af8f02c53c041d7e1322dac3", - "styles.css": "14d374b5d0e1461cb1ca2b125865e9c27df7c3bd79c11caa0afc52152c7d0aef" + "main.js": "949841c238fd506a3f4ccde5739eadc198ca7492be221cf5d396a2892edfbd70", + "styles.css": "945fd547278cf0388035b22660dfe9401dc0c8d25919fe6204471432e5797cde" } } diff --git a/plugins/gallery/styles.css b/plugins/gallery/styles.css index 898a699..5103fbd 100644 --- a/plugins/gallery/styles.css +++ b/plugins/gallery/styles.css @@ -65,7 +65,7 @@ /* ---- 图片墙 ---- */ .iwb-history-grid { overscroll-behavior: contain; } -.iwb-history-embedded .iwb-history-item { position: relative; flex: none; width: 100%; } +.iwb-history-embedded .iwb-history-item { position: relative; flex: none; width: 100%; contain: layout style; } .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; diff --git a/plugins/index.json b/plugins/index.json index 122dee3..0a525bc 100644 --- a/plugins/index.json +++ b/plugins/index.json @@ -33,11 +33,11 @@ "dir": "gallery", "main": "main.js", "style": "styles.css", - "version": "1.8.2", + "version": "1.8.3", "files": { - "manifest.json": "d54679889ab43e54408f6ff5731a557a9816ad5872ea86a341f98f3dfec30eb3", - "main.js": "eb178baa9d1c8d3148e93e38513bd35754d720e8af8f02c53c041d7e1322dac3", - "styles.css": "14d374b5d0e1461cb1ca2b125865e9c27df7c3bd79c11caa0afc52152c7d0aef" + "manifest.json": "f7c87b3514933243aa2e8ef7221c01606774f088d06f7a17edcce8c34a1a1ad4", + "main.js": "949841c238fd506a3f4ccde5739eadc198ca7492be221cf5d396a2892edfbd70", + "styles.css": "945fd547278cf0388035b22660dfe9401dc0c8d25919fe6204471432e5797cde" } }, {