const cameraScales = new WeakMap();
export function isMobileViewport() {
return globalThis.matchMedia?.( '(pointer: coarse)' ).matches === true
|| globalThis.matchMedia?.( '(max-width: 767px)' ).matches === true;
}
export function portraitCameraScale( aspect ) {
return Math.max( 1, Math.min( 1.6, 0.8 / Math.max( Number( aspect ) || 1, 0.5 ) ) );
}
export function portraitWidthScale( aspect ) {
const value = Number( aspect ) || 1;
return value < 1 ? Math.max( 0.375, value / ( 16 / 9 ) * 1.5 ) : 1;
}
export function frameCameraForAspect( camera, target, reset = false ) {
const scale = portraitCameraScale( camera.aspect );
const previousScale = reset ? 1 : cameraScales.get( camera ) ?? 1;
if ( scale === previousScale ) {
if ( reset ) cameraScales.set( camera, scale );
return;
}
camera.position.sub( target ).multiplyScalar( scale / previousScale ).add( target );
camera.updateMatrixWorld();
cameraScales.set( camera, scale );
}