getDevicePixelRatio

Category Sensors

Returns the ratio of the resolution in physical pixels to the resolution in CSS pixels for the current display device.

Demo

{
  "isSupported": false,
  "current": 1
}

Usage

<script>
	import { getDevicePixelRatio } from '@sv-use/core';
 
	const devicePixelRatio = getDevicePixelRatio();
</script>
Type definitions
import type { CleanupFunction } from '../../__internal__/types.js';
type GetDevicePixelRatioOptions = {
    /**
     * Whether to auto-cleanup the event listener or not.
     *
     * If set to `true`, it must run in the component initialization lifecycle.
     * @default true
     */
    autoCleanup?: boolean;
};
type GetDevicePixelRatioReturn = {
    /** Whether the {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio | devicePixelRatio property} is supported or not. */
    readonly isSupported: boolean;
    /** The current device pixel ratio. */
    readonly current: number;
    /**
     * Cleans up the event listener.
     * @note Is called automatically if `options.autoCleanup` is set to `true`.
     */
    cleanup: CleanupFunction;
};
/**
 * Returns the ratio of the resolution in physical pixels to the resolution in CSS pixels for the current display device.
 * @see https://svelte-librarian.github.io/sv-use/docs/core/sensors/get-device-pixel-ratio
 */
export declare function getDevicePixelRatio(options?: GetDevicePixelRatioOptions): GetDevicePixelRatioReturn;
export {};

Sources