@tamagui/react-native-web-lite
Version:
React Native for Web
65 lines (63 loc) • 2.1 kB
JavaScript
import Dimensions from "../Dimensions/index.native.js";
function _class_call_check(instance, Constructor) {
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _create_class(Constructor, protoProps, staticProps) {
return protoProps && _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Constructor;
}
var PixelRatio = /* @__PURE__ */function () {
"use strict";
function PixelRatio2() {
_class_call_check(this, PixelRatio2);
}
return _create_class(PixelRatio2, null, [{
key: "get",
value: (
/**
* Returns the device pixel density.
*/
function () {
return Dimensions.get("window").scale;
})
}, {
key: "getFontScale",
value: (
/**
* No equivalent for Web
*/
function () {
return Dimensions.get("window").fontScale || PixelRatio2.get();
})
}, {
key: "getPixelSizeForLayoutSize",
value: (
/**
* Converts a layout size (dp) to pixel size (px).
* Guaranteed to return an integer number.
*/
function (layoutSize) {
return Math.round(layoutSize * PixelRatio2.get());
})
}, {
key: "roundToNearestPixel",
value: (
/**
* 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.
*/
function (layoutSize) {
var ratio = PixelRatio2.get();
return Math.round(layoutSize * ratio) / ratio;
})
}]), PixelRatio2;
}();
export { PixelRatio as default };
//# sourceMappingURL=index.native.js.map