@kietpt2003/react-native-core-ui
Version:
React Native Core UI components by KietPT
216 lines (205 loc) • 7.07 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__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: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/utils/index.ts
var utils_exports = {};
__export(utils_exports, {
IPHONE_12_HEIGTH: () => IPHONE_12_HEIGTH,
IPHONE_12_WIDTH: () => IPHONE_12_WIDTH,
StylePlatform: () => StylePlatform,
cleanTagHTML: () => cleanTagHTML_default,
convertNumber: () => convertNumber,
convertSeconds: () => convertSeconds,
convertString: () => convertString,
debounce: () => debounce_default,
filterAllowedTextStyle: () => filterAllowedTextStyle,
fixedDistance: () => fixedDistance_default,
formatHour: () => formatHour,
formatMoney: () => formatMoney_default,
getPaddingBottom: () => getPaddingBottom,
getPaddingTop: () => getPaddingTop,
height: () => height,
isTablet: () => isTablet,
limitedString: () => limitedString_default,
moderateHeightScale: () => moderateHeightScale,
moderateScale: () => moderateScale,
scale: () => scale,
scaleFont: () => scaleFont,
scaleH: () => scaleH,
statusBarHeight: () => statusBarHeight,
width: () => width
});
module.exports = __toCommonJS(utils_exports);
// src/utils/resolutions.ts
var import_react_native = require("react-native");
var import_react_native_iphone_x_helper = require("react-native-iphone-x-helper");
var import_react_native_device_info = __toESM(require("react-native-device-info"));
var getPaddingTop = () => {
let sbHeight = (0, import_react_native_iphone_x_helper.getStatusBarHeight)();
return sbHeight >= 26 && sbHeight < 28 || sbHeight === 30 ? sbHeight : 0;
};
var getPaddingBottom = () => {
let paddingBottom = (0, import_react_native_iphone_x_helper.getBottomSpace)() / 2;
return paddingBottom;
};
var isTablet = import_react_native_device_info.default.isTablet();
var StylePlatform = (styles) => {
if (isTablet) {
return styles.tablet || {};
}
return styles.phone || {};
};
var statusBarHeight = import_react_native.Platform.OS == "android" && import_react_native.StatusBar.currentHeight ? import_react_native.StatusBar.currentHeight : 0;
// src/utils/filters.ts
var ALLOWED_STYLE_KEYS = ["color", "fontFamily", "fontWeight"];
var filterAllowedTextStyle = (style) => {
const filtered = {};
for (const key of ALLOWED_STYLE_KEYS) {
if (key in style) {
filtered[key] = style[key];
}
}
return filtered;
};
// src/utils/scale.ts
var import_react_native2 = require("react-native");
var { width, height } = import_react_native2.Dimensions.get("window");
var IPHONE_12_WIDTH = 375;
var IPHONE_12_HEIGTH = 812;
var scaleWidth = width / IPHONE_12_WIDTH;
var scaleHeight = height / IPHONE_12_HEIGTH;
var scaleAvg = (scaleWidth + scaleHeight) / 2;
var scaleFont = (size) => Math.round(import_react_native2.PixelRatio.roundToNearestPixel(size * scaleAvg));
var scale = (size) => Math.round(import_react_native2.PixelRatio.roundToNearestPixel(size * scaleWidth));
var scaleH = (size) => Math.round(import_react_native2.PixelRatio.roundToNearestPixel(size * scaleHeight));
var moderateScale = (size, factor = 0.5) => size + (scale(size) - size) * factor;
var moderateHeightScale = (size, factor = 0.5) => size + (scaleH(size) - size) * factor;
// src/utils/cleanTagHTML.ts
var cleanTagHTML_default = (str = "") => {
if (str && str.trim().length) {
let data = [];
let arr = str.replace(/<\/?[^>]+(>|$)/g, "").split(" ");
for (let i = 0; i < arr.length; i++) {
if (arr[i] && arr[i].trim()) {
data.push(arr[i]);
} else if (arr[i - 1] && arr[i - 1].trim()) {
data.push("\n");
}
}
return data.join("");
}
return "";
};
// src/utils/converter.ts
var convertString = (value) => {
return String(value);
};
var convertNumber = (value) => {
return isNaN(parseFloat(value)) ? 0 : parseFloat(value);
};
var convertSeconds = (seconds = 0) => {
return new Date(Math.max(seconds, 0) * 1e3).toISOString().substr(14, 5);
};
var formatHour = (seconds = 0) => {
return new Date(Math.max(seconds, 0) * 1e3).toISOString().substr(11, 8);
};
// src/utils/debounce.ts
var debounce = (func, delay) => {
let timeoutId = null;
const debounced = (...args) => {
if (timeoutId) {
clearTimeout(timeoutId);
}
timeoutId = setTimeout(() => {
func(...args);
}, delay);
};
debounced.cancel = () => {
if (timeoutId) {
clearTimeout(timeoutId);
timeoutId = null;
}
};
debounced.flush = () => {
if (timeoutId) {
clearTimeout(timeoutId);
func();
timeoutId = null;
}
};
return debounced;
};
var debounce_default = debounce;
// src/utils/fixedDistance.ts
var fixedDistance_default = (distance = 0, toFixed = 2) => {
const toFixedVal = toFixed < 1 || toFixed > 5 ? 2 : toFixed;
return Number.isInteger(Number(distance)) ? distance : distance?.toFixed(toFixedVal);
};
// src/utils/formatMoney.ts
var formatMoney_default = (num = 0, maximumFractionDigits = 0, lang = "en-US") => {
if (!num) {
return 0;
}
return new Intl.NumberFormat(lang, { maximumFractionDigits }).format(num);
};
// src/utils/limitedString.ts
var limitedString_default = (str = "", maxLength = 5) => {
let arr = str.split(" ");
if (arr.length > maxLength) {
return arr.slice(0, maxLength).join(" ") + "...";
}
return str;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
IPHONE_12_HEIGTH,
IPHONE_12_WIDTH,
StylePlatform,
cleanTagHTML,
convertNumber,
convertSeconds,
convertString,
debounce,
filterAllowedTextStyle,
fixedDistance,
formatHour,
formatMoney,
getPaddingBottom,
getPaddingTop,
height,
isTablet,
limitedString,
moderateHeightScale,
moderateScale,
scale,
scaleFont,
scaleH,
statusBarHeight,
width
});
//# sourceMappingURL=index.js.map