UNPKG

@tamagui/react-native-web-lite

Version:
57 lines 1.94 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: !0 }); }, __copyProps = (to, from, except, desc) => { if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); return to; }; var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod); var PixelRatio_exports = {}; __export(PixelRatio_exports, { PixelRatio: () => PixelRatio }); module.exports = __toCommonJS(PixelRatio_exports); var import_Dimensions = require("../Dimensions/index.cjs"); class PixelRatio { /** * Returns the device pixel density. */ static get() { return import_Dimensions.Dimensions.get("window").scale; } /** * No equivalent for Web */ static getFontScale() { return import_Dimensions.Dimensions.get("window").fontScale || PixelRatio.get(); } /** * Converts a layout size (dp) to pixel size (px). * Guaranteed to return an integer number. */ static getPixelSizeForLayoutSize(layoutSize) { return Math.round(layoutSize * PixelRatio.get()); } /** * Rounds a layout size (dp) to the nearest layout size that corresponds to * an integer number of pixels. For example, on a device with a PixelRatio * of 3, `PixelRatio.roundToNearestPixel(8.4) = 8.33`, which corresponds to * exactly (8.33 * 3) = 25 pixels. */ static roundToNearestPixel(layoutSize) { const ratio = PixelRatio.get(); return Math.round(layoutSize * ratio) / ratio; } }