/** * 手机/平板双指与手势缩放锁(头像裁剪、图片灯箱区域放行 pinch)。 * * 只监听用户手势事件,而手势必然发生在页面加载与客户端 bundle 执行之后, * 因此无需像主题脚本那样内联在 中,在客户端入口安装即可。 */ export function installZoomGuard(): void { if (typeof document === 'undefined') return; const inZoomAllowArea = (target: EventTarget | null): boolean => !!target && target instanceof Element && typeof target.closest === 'function' && !!target.closest('.avatar-crop-stage, .image-lightbox'); const blockGesture = (e: Event) => { if (inZoomAllowArea(e.target)) return; if (e.cancelable) e.preventDefault(); }; const blockMultiTouch = (e: TouchEvent) => { if (e.touches && e.touches.length > 1) { if (inZoomAllowArea(e.target)) return; if (e.cancelable) e.preventDefault(); } }; document.addEventListener('gesturestart', blockGesture, { passive: false }); document.addEventListener('gesturechange', blockGesture, { passive: false }); document.addEventListener('gestureend', blockGesture, { passive: false }); document.addEventListener('touchstart', blockMultiTouch, { passive: false }); document.addEventListener('touchmove', blockMultiTouch, { passive: false }); }