one
Version:
One is a React framework for web, iOS, and Android apps.
169 lines (167 loc) • 5.91 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(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var EdgeFade_native_exports = {};
__export(EdgeFade_native_exports, { EdgeFade: () => EdgeFade });
module.exports = __toCommonJS(EdgeFade_native_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_react_native = require("react-native");
var import_OneNativeEdgeFadeNativeComponent = __toESM(require("../specs/OneNativeEdgeFadeNativeComponent.native.js"), 1);
var import_curves = require("./curves.native.js");
var import_nativeProps = require("./nativeProps.native.js");
var import_normalize = require("./normalize.native.js");
var BACKGROUND_IMAGE_KEY = "backgroundImage";
var STRIP_DIRECTIONS = {
top: "to bottom",
bottom: "to top",
left: "to right",
right: "to left"
};
function stripLayout(edge, size) {
var clamped = Math.max(0, size);
switch (edge) {
case "top": return {
position: "absolute",
top: 0,
left: 0,
right: 0,
height: clamped
};
case "bottom": return {
position: "absolute",
bottom: 0,
left: 0,
right: 0,
height: clamped
};
case "left": return {
position: "absolute",
top: 0,
bottom: 0,
left: 0,
width: clamped
};
case "right": return {
position: "absolute",
top: 0,
bottom: 0,
right: 0,
width: clamped
};
}
}
function stripGradient(edge, resolved, fallback) {
var _resolved_color;
var processed = (0, import_react_native.processColor)((_resolved_color = resolved.color) !== null && _resolved_color !== void 0 ? _resolved_color : fallback);
var argb = typeof processed === "number" ? processed : 4278190080;
var red = argb >> 16 & 255;
var green = argb >> 8 & 255;
var blue = argb & 255;
var ceiling = (argb >>> 24 & 255) / 255;
var alphas = (0, import_curves.sampleCurve)(resolved.curve);
var last = alphas.length - 1;
return {
type: "linear-gradient",
direction: STRIP_DIRECTIONS[edge],
colorStops: alphas.map(function(_, index) {
var _alphas_;
var alpha = (_alphas_ = alphas[last - index]) !== null && _alphas_ !== void 0 ? _alphas_ : 0;
var stopAlpha = Math.max(0, Math.min(1, (1 - alpha) * ceiling));
return {
color: `rgba(${red},${green},${blue},${Number(stopAlpha.toFixed(4))})`,
positions: [`${(index / last * 100).toFixed(2)}%`]
};
})
};
}
function OverlayStrip(param) {
var { edge, resolved, fallback } = param;
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, {
pointerEvents: "none",
style: [stripLayout(edge, resolved.size), { [BACKGROUND_IMAGE_KEY]: [stripGradient(edge, resolved, fallback)] }]
});
}
function EdgeFade(props) {
var resolved = (0, import_normalize.resolveEdges)(props, import_react_native.I18nManager.isRTL);
var { top: _top, bottom: _bottom, left: _left, right: _right, start: _start, end: _end, size: _size, curve: _curve, mode: _mode, color: _color, blurRadius: _blurRadius, frostProgression: _frostProgression, radius, style, children, ...viewProps } = props;
var { borderRadius: styleRadius, ...cleanStyle } = (0, import_normalize.flattenStyle)(style);
var resolvedRadius = (0, import_normalize.resolveRadius)(radius, styleRadius);
if (resolved.mode === "overlay") {
var _resolved_color;
var radiusStyle = resolvedRadius != null ? {
borderRadius: resolvedRadius,
overflow: "hidden"
} : null;
var fallback = (_resolved_color = resolved.color) !== null && _resolved_color !== void 0 ? _resolved_color : "black";
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.View, {
style: [cleanStyle, radiusStyle],
...viewProps,
children: [
children,
resolved.top && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OverlayStrip, {
edge: "top",
resolved: resolved.top,
fallback
}),
resolved.bottom && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OverlayStrip, {
edge: "bottom",
resolved: resolved.bottom,
fallback
}),
resolved.left && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OverlayStrip, {
edge: "left",
resolved: resolved.left,
fallback
}),
resolved.right && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OverlayStrip, {
edge: "right",
resolved: resolved.right,
fallback
})
]
});
}
var native = (0, import_nativeProps.resolveNativeProps)(resolved, resolvedRadius);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_OneNativeEdgeFadeNativeComponent.default, {
...viewProps,
style: cleanStyle,
fadeTop: native.fadeTop,
fadeBottom: native.fadeBottom,
fadeLeft: native.fadeLeft,
fadeRight: native.fadeRight,
curveTop: native.curveTop,
curveBottom: native.curveBottom,
curveLeft: native.curveLeft,
curveRight: native.curveRight,
fadeRadius: native.fadeRadius,
mode: native.mode,
blurRadius: native.blurRadius,
frostProgression: native.frostProgression,
overlayColor: native.overlayColor,
children
});
}