// ===== 键盘弹出适配(visualViewport)=====
(function () {
const dock = document.getElementById('dock');
const vv = window.visualViewport;
if (!vv || !dock) return;
let raf = 0;
function adapt() {
if (raf) return;
raf = requestAnimationFrame(function () {
raf = 0;
// 被浏览器 UI(地址栏/键盘)吃掉的底部空间 = 输入区需要抬升的高度
const eaten = Math.max(0, Math.round(window.innerHeight - vv.height - vv.offsetTop));
dock.style.bottom = eaten + 'px';
});
}
adapt(); // 加载立即校准一次(首屏地址栏已占位的情况)
vv.addEventListener('resize', adapt);
vv.addEventListener('scroll', adapt);
window.addEventListener('orientationchange', function () { setTimeout(adapt, 200); });
// 输入框聚焦兜底:确保输入条滚进可视区
const ti = document.getElementById('textInput');
if (ti) ti.addEventListener('focus', function () { setTimeout(function () { adapt(); ti.scrollIntoView({ block: 'nearest' }); }, 300); });
})();