Feat: Extract keyboard layout resizing helpers

This commit is contained in:
2026-03-19 15:50:54 -07:00
parent ffb40d5c05
commit 21c8fdc906

24
src/keyboard.js Normal file
View File

@@ -0,0 +1,24 @@
import { el } from './dom.js';
export function kbUpdate() {
const vv = window.visualViewport;
const overlap = vv ? Math.max(0, (window.innerHeight - (vv.height + vv.offsetTop))) : 0;
document.documentElement.style.setProperty('--kb', overlap + 'px');
const fh = el.footer.getBoundingClientRect().height;
document.documentElement.style.setProperty('--footer-h', fh + 'px');
el.footer.style.transform = 'translateY(' + (-overlap) + 'px)';
el.chat.style.scrollPaddingBottom = (fh + overlap + 16) + 'px';
}
export function kbBind() {
if (window.visualViewport) {
['resize', 'scroll'].forEach(ev => window.visualViewport.addEventListener(ev, () => kbUpdate(), { passive: true }));
}
window.$(window).on('resize orientationchange', () => setTimeout(kbUpdate, 50));
window.$(el.input).on('focus click', () => {
setTimeout(() => {
kbUpdate();
el.input.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
}, 0);
});
}