// 小地图与底部工具栏避让(v3.26.21):重叠时加 iwb-minimap-tight,腾出空间后移除 const assert = require('assert') const fs = require('fs') const path = require('path') const { JSDOM } = require('jsdom') const dom = new JSDOM('
') const { window } = dom window.requestAnimationFrame = (fn) => setTimeout(() => fn(Date.now()), 0) window.cancelAnimationFrame = (id) => clearTimeout(id) const bar = window.document.querySelector('.iwb-toolbar') const mm = window.document.querySelector('.iwb-minimap') let barRight = 900 let mmLeft = 950 bar.getBoundingClientRect = () => ({ left: 300, right: barRight, top: 800, bottom: 860, width: barRight - 300, height: 60 }) mm.getBoundingClientRect = () => ({ left: mmLeft, right: mmLeft + 132, top: 800, bottom: 888, width: 132, height: 88 }) const src = fs.readFileSync(path.join(__dirname, '..', 'src', 'ui-minimap-fit.js'), 'utf8') new Function('window', src)(window) window.IWBMiniMapFit.install() const wait = (ms) => new Promise((r) => setTimeout(r, ms)) async function check (label, expectTight) { window.dispatchEvent(new window.Event('resize')) await wait(30) const tight = mm.classList.contains('iwb-minimap-tight') assert.strictEqual(tight, expectTight, label + ':期望 tight=' + expectTight + ',实际 ' + tight) } ;(async () => { await check('间距充足(950 > 900+8)不应隐藏', false) mmLeft = 890 await check('即将重叠(890 < 908)应隐藏', true) mmLeft = 1200 await check('空间回来(1200 > 908)应恢复', false) console.log('ui-minimap-fit checks passed(不重叠显示 / 临界隐藏 / 回位恢复)') })()