UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

91 lines (90 loc) • 3.71 kB
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(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var SafeAreaView_exports = {}; __export(SafeAreaView_exports, { SafeAreaView: () => SafeAreaView }); module.exports = __toCommonJS(SafeAreaView_exports); var React = __toESM(require("react"), 1); var import_SafeAreaContext = require("./SafeAreaContext.cjs"); var import_jsx_runtime = require("react/jsx-runtime"); const TOP = 8; const RIGHT = 4; const BOTTOM = 2; const LEFT = 1; const ALL = 15; const edgeBitmaskMap = { top: TOP, right: RIGHT, bottom: BOTTOM, left: LEFT }; const SafeAreaView = React.forwardRef(({ style = {}, mode, edges, ...rest }, ref) => { const insets = (0, import_SafeAreaContext.useSafeAreaInsets)(); const edgeBitmask = edges != null ? Array.isArray(edges) ? edges.reduce((acc, edge) => acc | edgeBitmaskMap[edge], 0) : Object.keys(edges).reduce((acc, edge) => acc | edgeBitmaskMap[edge], 0) : ALL; const appliedStyle = React.useMemo(() => { const insetTop = edgeBitmask & TOP ? insets.top : 0; const insetRight = edgeBitmask & RIGHT ? insets.right : 0; const insetBottom = edgeBitmask & BOTTOM ? insets.bottom : 0; const insetLeft = edgeBitmask & LEFT ? insets.left : 0; const flatStyle = (Array.isArray(style) ? style.flat(Number.POSITIVE_INFINITY) : [style]).reduce((result, value) => value ? Object.assign(result, value) : result, {}); if (mode === "margin") { const { margin = 0, marginVertical = margin, marginHorizontal = margin, marginTop = marginVertical, marginRight = marginHorizontal, marginBottom = marginVertical, marginLeft = marginHorizontal } = flatStyle; const marginStyle = { marginTop: marginTop + insetTop, marginRight: marginRight + insetRight, marginBottom: marginBottom + insetBottom, marginLeft: marginLeft + insetLeft }; const { marginVertical: _marginVertical, marginHorizontal: _marginHorizontal, ...domStyle2 } = flatStyle; return { ...domStyle2, ...marginStyle }; } const { padding = 0, paddingVertical = padding, paddingHorizontal = padding, paddingTop = paddingVertical, paddingRight = paddingHorizontal, paddingBottom = paddingVertical, paddingLeft = paddingHorizontal } = flatStyle; const paddingStyle = { paddingTop: paddingTop + insetTop, paddingRight: paddingRight + insetRight, paddingBottom: paddingBottom + insetBottom, paddingLeft: paddingLeft + insetLeft }; const { paddingVertical: _paddingVertical, paddingHorizontal: _paddingHorizontal, ...domStyle } = flatStyle; return { ...domStyle, ...paddingStyle }; }, [ style, insets, mode, edgeBitmask ]); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ...rest, style: appliedStyle, ref }); });