feat(canvas): 小地图与工具栏同排 + 挤压自动隐藏 v3.26.18
Verify (Gitea) / gate (build · unit · facts) (push) Canceled after 1m40s
Verify (Gitea) / gate (build · unit · facts) (push) Canceled after 1m40s
This commit is contained in:
1 parent
93deea4f5e
commit
2c94401d45
17 files changed
+117
-26
No files matched your search
@@ -0,0 +1,51 @@
|
||||
/* ui-minimap-fit.js —— 小地图与底部工具栏的避让(v3.26.18)
|
||||
*
|
||||
* 小地图与悬浮工具栏同一排(都在底部)。右栏拉宽会压缩画布可用宽度,
|
||||
* 当两者横向重叠时,把小地图淡出隐藏(而不是硬挤或改布局)。
|
||||
* 触发:窗口 resize / 工具栏或小地图尺寸变化 / 停靠栏拖宽(iwb:dock-resizing)。
|
||||
*/
|
||||
;(function (global) {
|
||||
'use strict'
|
||||
var GAP = 8
|
||||
function install () {
|
||||
try {
|
||||
var doc = global.document
|
||||
if (!doc || global.IWBMiniMapFitInstalled) return
|
||||
global.IWBMiniMapFitInstalled = true
|
||||
var raf = 0
|
||||
function fit () {
|
||||
raf = 0
|
||||
try {
|
||||
var bar = doc.querySelector('.iwb-toolbar-wrap .iwb-toolbar')
|
||||
var mm = doc.querySelector('.iwb-minimap')
|
||||
if (!bar || !mm) return
|
||||
var a = bar.getBoundingClientRect()
|
||||
var b = mm.getBoundingClientRect()
|
||||
var tight = b.left < a.right + GAP
|
||||
if (mm.classList.contains('iwb-minimap-tight') !== tight) mm.classList.toggle('iwb-minimap-tight', tight)
|
||||
} catch (e) { /* ignore */ }
|
||||
}
|
||||
function schedule () { if (!raf) raf = global.requestAnimationFrame(fit) }
|
||||
var ro = null
|
||||
try {
|
||||
if (typeof global.ResizeObserver === 'function') {
|
||||
ro = new global.ResizeObserver(schedule)
|
||||
var observe = function () {
|
||||
try {
|
||||
var nodes = doc.querySelectorAll('.iwb-toolbar-wrap, .iwb-toolbar, .iwb-minimap')
|
||||
for (var i = 0; i < nodes.length; i++) ro.observe(nodes[i])
|
||||
} catch (e) { /* ignore */ }
|
||||
}
|
||||
observe()
|
||||
try {
|
||||
new global.MutationObserver(function () { observe(); schedule() }).observe(doc.body, { childList: true, subtree: true })
|
||||
} catch (e) { /* ignore */ }
|
||||
}
|
||||
} catch (e) { /* ignore */ }
|
||||
global.addEventListener('resize', schedule)
|
||||
global.addEventListener('iwb:dock-resizing', schedule)
|
||||
schedule()
|
||||
} catch (e) { /* ignore */ }
|
||||
}
|
||||
global.IWBMiniMapFit = { install: install }
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
Reference in new issue
Block a user