fix(gallery): 1.8.2 列宽按「真正滚动容器」的可用宽度算,最右一列不再被裁
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 1m34s

现象:图库 4 列排布时最右一列被窗口裁掉(用户截图)。
原因:renderGrid 用 wrap.clientWidth(面板全宽)当可用宽度,而实际滚动容器右侧还有滚动条与内边距,
列宽按全宽均分后总宽超出可视区,最右一列被裁。

改动(plugins/gallery/main.js):
- 新增 usableW():沿 scrollerOf() 找到真正滚动的容器,取其 clientWidth 减去左右 padding 与 4px 余量
- renderGrid / measure 都改用 usableW(),并且每次都采用实测值(不再因为差值 ≤1 而沿旧值)
- colW 改为 floor,避免四舍五入后 n 列总宽超出容器
This commit is contained in:
qiqi committed 2026-11-28 01:44:12 +08:00
1 parent 6c598e3898
commit 89d8f5ddef
3 files changed
+24 -9

No files matched your search

+19 -4
View File
@@ -344,14 +344,14 @@
var gap = 6
// 每次重排都重新量一次宽度:面板显隐/停靠栏展开时 gridW 可能是旧值,
// 只靠 ResizeObserver 会在「变成 0 再回来」期间漏掉,导致必须拖宽度才出图。
var liveW = availableW()
if (liveW > 0 && Math.abs(liveW - gridW) > 1) gridW = liveW
var liveW = usableW()
if (liveW > 0) 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:列宽 = 均分宽度(铺满面板),图幅只决定「列数」——
// 以前 min(图幅, 均分) 会留下右侧空白,看起来像没补齐。
var colW = Math.max(40, (gridW - gap * (n - 1)) / n)
var colW = Math.max(40, Math.floor((gridW - gap * (n - 1)) / n)) // floor:避免四舍五入后总宽超出容器
var cols = []
var heights = []
for (var c = 0; c < n; c++) { cols.push([]); heights.push(0) }
@@ -585,6 +585,21 @@
// 宽度测量:列数只由「面板宽 / 图幅」决定
// v1.6.5:面板刚挂载时 grid 宽度可能是 0,而 grid 宽度又取决于列宽 → RO 不会触发,图库一直空白。
// v1.8.2:可用宽度按「真正滚动的容器」算,扣掉内边距和滚动条余量。
// 原来用 wrap.clientWidth(面板全宽),右侧有滚动条/内边距时 4 列总宽会超出,最右一列被裁掉。
function usableW () {
var sc = scrollerOf()
var w = 0
if (sc) {
var cs = null
try { cs = global.getComputedStyle ? global.getComputedStyle(sc) : null } catch (e) { cs = null }
var padL = cs ? (parseFloat(cs.paddingLeft) || 0) : 0
var padR = cs ? (parseFloat(cs.paddingRight) || 0) : 0
w = sc.clientWidth - padL - padR
}
if (!w || w < 80) w = availableW()
return Math.max(80, Math.floor(w) - 4)
}
function availableW () {
// v1.6.6:优先量「会随面板拉伸的外层容器」,而不是 grid 自身
// (grid 现在是 flex-start + 内容宽度,面板变宽它不会变宽 → RO 不触发 → 列数永不补齐)
@@ -594,7 +609,7 @@
return w || 0
}
function measure () {
var w = availableW()
var w = usableW()
if (w > 0 && Math.abs(w - gridW) > 1) { gridW = w; renderGrid() }
}
var ro = typeof ResizeObserver === 'function' ? new ResizeObserver(function () { measure() }) : null
+2 -2
View File
@@ -1,7 +1,7 @@
{
"id": "gallery",
"name": "图库",
"version": "1.8.1",
"version": "1.8.2",
"apiVersion": 1,
"main": "main.js",
"style": "styles.css",
@@ -13,7 +13,7 @@
"图库"
],
"files": {
"main.js": "6dd3bf43dce74236d4904c4e33639772ef03bd4cd80d6e5a4532ff7ca7ed085a",
"main.js": "eb178baa9d1c8d3148e93e38513bd35754d720e8af8f02c53c041d7e1322dac3",
"styles.css": "14d374b5d0e1461cb1ca2b125865e9c27df7c3bd79c11caa0afc52152c7d0aef"
}
}
+3 -3
View File
@@ -33,10 +33,10 @@
"dir": "gallery",
"main": "main.js",
"style": "styles.css",
"version": "1.8.1",
"version": "1.8.2",
"files": {
"manifest.json": "8e1235f0f0d89d81c9aafe8e4eac4a4dc3521c1b583c845b15595ddeecc7c0c2",
"main.js": "6dd3bf43dce74236d4904c4e33639772ef03bd4cd80d6e5a4532ff7ca7ed085a",
"manifest.json": "d54679889ab43e54408f6ff5731a557a9816ad5872ea86a341f98f3dfec30eb3",
"main.js": "eb178baa9d1c8d3148e93e38513bd35754d720e8af8f02c53c041d7e1322dac3",
"styles.css": "14d374b5d0e1461cb1ca2b125865e9c27df7c3bd79c11caa0afc52152c7d0aef"
}
},