fix(gallery): 1.9.3 列数跟着拖动实时变 + 列数切换不再有 1 秒停顿
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 40s
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 40s
用户反馈 1.9.1 更好:1.9.2 的「列数滞回」导致拖动时列数不变、停手才变,而且那一次变化要停 1 秒。 - 去掉列数滞回:按宽度实时算列数;一检测到列数变化就立刻重排(rAF 合并一帧) - 列数切换的重排改为「复用卡片节点」:把已有卡片 appendChild 到新列(DOM 移动), 不再重建 40 张卡 + 重新解码缩略图 —— 那正是那 1 秒停顿的来源 - 修复用带来的两个问题:复用时把可能停在 display:none 的缩略图复位;img 不再先隐藏再显示 (这两点导致 e2e 里图库缩略图「存在但 hidden」,已复跑通过) 保留:虚拟列表、选中就地更新、双击事件委托、列宽按真实容器算、容器/内边距缓存、缩略图缓存上限。
This commit is contained in:
1 parent
aefed6935b
commit
b2bcc07cb5
3 files changed
+35
-16
No files matched your search
+30
-11
@@ -368,15 +368,12 @@
|
||||
scCache = (grid && grid.parentNode) || null
|
||||
return scCache
|
||||
}
|
||||
// 列数滞回:在切换阈值 ±12px 内保持原列数。拖动时 3/4 列来回跳会触发整轮重排,是卡顿来源之一。
|
||||
// v1.9.3:不加滞回 —— 用户实测「拖动时列数不跟着变、停手才变」比偶尔多排一次更难受。
|
||||
// 列数切换的重排代价已由「卡片节点复用」压到很低,所以直接按宽度实时切。
|
||||
function colsFor (w, prev) {
|
||||
var gap = 6
|
||||
var tileW = Math.max(40, Number(cfg.tile) || 110)
|
||||
var n = Math.max(1, Math.floor((w + gap) / (tileW + gap)))
|
||||
if (!prev || n === prev) return n
|
||||
var boundary = Math.min(n, prev) * (tileW + gap) - gap
|
||||
if (Math.abs(w - boundary) < 12) return prev
|
||||
return n
|
||||
return Math.max(1, Math.floor((w + gap) / (tileW + gap)))
|
||||
}
|
||||
function computeLayout () {
|
||||
var gap = 6
|
||||
@@ -456,7 +453,18 @@
|
||||
}
|
||||
}
|
||||
|
||||
// v1.9.3:卡片节点复用。列数切换时不再重建这几十张卡(重建会重新解码缩略图,实测停顿约 1 秒),
|
||||
// 只把已有节点 appendChild 到新列里(DOM 移动,图片和事件都保留)。
|
||||
var nodeCache = {}
|
||||
var nodeOrder = []
|
||||
function itemNode (it, seq) {
|
||||
var hit = nodeCache[it.name]
|
||||
if (hit && hit.__iwbItem === it) {
|
||||
// 复用时把上轮可能还停在 display:none 的缩略图复位(否则看起来「没图」)
|
||||
var hi = hit.querySelector('img')
|
||||
if (hi && hi.style.display === 'none' && hi.complete && hi.naturalWidth > 0) hi.style.display = ''
|
||||
return hit
|
||||
}
|
||||
var on = !!picked[it.name]
|
||||
var box = el('div', { class: 'iwb-history-item' + (count() ? ' iwb-history-managed' : '') + (on ? ' iwb-history-selected' : '') })
|
||||
box.setAttribute('data-name', it.name)
|
||||
@@ -534,7 +542,6 @@
|
||||
e.dataTransfer.effectAllowed = 'copy'
|
||||
} catch (err) { /* ignore */ }
|
||||
})
|
||||
img.style.display = 'none'
|
||||
box.appendChild(img)
|
||||
// v1.6.9:坏图/超时兜底 —— 某些坏字节既不触发 load 也不触发 error,700ms 后直接判定失败(可点击重试)
|
||||
setTimeout(function () {
|
||||
@@ -566,6 +573,10 @@
|
||||
// 角标/勾选最后挂:不要 z-index(插件层级闸门禁止裸值),靠 DOM 顺序盖在图片上
|
||||
if (origBadge) box.appendChild(origBadge)
|
||||
if (on) box.appendChild(el('span', { class: 'iwb-history-check', title: '已选中' }))
|
||||
box.__iwbItem = it
|
||||
nodeCache[it.name] = box
|
||||
nodeOrder.push(it.name)
|
||||
while (nodeOrder.length > 400) { var oldN = nodeOrder.shift(); if (oldN && oldN !== it.name) { try { delete nodeCache[oldN] } catch (e3) { /* ignore */ } } }
|
||||
return box
|
||||
}
|
||||
|
||||
@@ -707,11 +718,19 @@
|
||||
return true
|
||||
}
|
||||
function measure () {
|
||||
// v1.9.1:拖动过程中不重建卡片(卡顿主因)。列数不变时只改列宽,
|
||||
// 尾部防抖 140ms 再做一次完整重排(修正 y 偏移),松手立刻 flush。
|
||||
if (quickWidth()) { clearTimeout(measureTimer); measureTimer = setTimeout(measureNow, 220); return }
|
||||
var w = usableW()
|
||||
if (!w) return
|
||||
// 列数变了立刻重排(合并到一帧;节点复用后代价很小,列数能跟着拖动实时变)
|
||||
if (layoutState && colsFor(w, 0) !== layoutState.n) {
|
||||
gridW = w
|
||||
clearTimeout(measureTimer)
|
||||
scheduleRender()
|
||||
return
|
||||
}
|
||||
// 列数不变:只改列宽,不重建卡片
|
||||
if (quickWidth()) return
|
||||
clearTimeout(measureTimer)
|
||||
measureTimer = setTimeout(measureNow, 140)
|
||||
measureTimer = setTimeout(measureNow, 120)
|
||||
}
|
||||
if (global.document && global.document.addEventListener) {
|
||||
global.document.addEventListener('pointerup', function () { clearTimeout(measureTimer); measureNow() }, true)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "gallery",
|
||||
"name": "图库",
|
||||
"version": "1.9.2",
|
||||
"version": "1.9.3",
|
||||
"apiVersion": 1,
|
||||
"main": "main.js",
|
||||
"style": "styles.css",
|
||||
@@ -13,7 +13,7 @@
|
||||
"图库"
|
||||
],
|
||||
"files": {
|
||||
"main.js": "c0103fcc9cb92fac3aecdabba7ef60af1fb935375d3670f30b1d6dce4231e73f",
|
||||
"main.js": "0921ffa067b14de54aeabf5a46cd29a4a2bad2b8d2bd086600324ca7506385d9",
|
||||
"styles.css": "945fd547278cf0388035b22660dfe9401dc0c8d25919fe6204471432e5797cde"
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -33,10 +33,10 @@
|
||||
"dir": "gallery",
|
||||
"main": "main.js",
|
||||
"style": "styles.css",
|
||||
"version": "1.9.2",
|
||||
"version": "1.9.3",
|
||||
"files": {
|
||||
"manifest.json": "850f277ab02ed4bf91e17f20d0e5f7048fa24557dc355348afd14e0402e296ec",
|
||||
"main.js": "c0103fcc9cb92fac3aecdabba7ef60af1fb935375d3670f30b1d6dce4231e73f",
|
||||
"manifest.json": "62380d625ff676d434d066a6800eccedce224a3a0a4ded83f98459dc60f7c57f",
|
||||
"main.js": "0921ffa067b14de54aeabf5a46cd29a4a2bad2b8d2bd086600324ca7506385d9",
|
||||
"styles.css": "945fd547278cf0388035b22660dfe9401dc0c8d25919fe6204471432e5797cde"
|
||||
}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user