Files
DAO_DE_JING/.vitepress/theme/tablet-landscape.ts
T
dekun bb4f0c265d Add tablet landscape layout and allow PWA horizontal orientation.
Split mobile and tablet breakpoints, restore desktop-style reading on landscape tablets, and lock Android tablet apps to landscape.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-16 14:47:50 +08:00

26 lines
798 B
TypeScript

/** Android 平板 PWA 安装后默认锁定横屏 */
export function initTabletLandscape() {
if (typeof window === 'undefined') return
function tryLockLandscape() {
const isStandalone =
window.matchMedia('(display-mode: standalone)').matches ||
(window.navigator as Navigator & { standalone?: boolean }).standalone
if (!isStandalone || !/Android/i.test(navigator.userAgent)) return
const shortestSide = Math.min(window.screen.width, window.screen.height)
if (shortestSide < 600) return
const lock = screen.orientation?.lock?.bind(screen.orientation)
if (!lock) return
lock('landscape-primary').catch(() => {
lock('landscape').catch(() => {})
})
}
tryLockLandscape()
window.addEventListener('orientationchange', tryLockLandscape)
}