UNPKG

@tamagui/react-native-web-lite

Version:
61 lines (60 loc) 2.52 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf, __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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target, mod )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod); var PixelRatio_exports = {}; __export(PixelRatio_exports, { default: () => PixelRatio }); module.exports = __toCommonJS(PixelRatio_exports); var import_Dimensions = __toESM(require("../Dimensions/index")); class PixelRatio { /** * Returns the device pixel density. */ static get() { return import_Dimensions.default.get("window").scale; } /** * No equivalent for Web */ static getFontScale() { return import_Dimensions.default.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; } } //# sourceMappingURL=index.js.map