@revenuecat/purchases-ui-js
Version:
Web components for Paywalls. Powered by RevenueCat
25 lines (24 loc) • 992 B
JavaScript
import { DEFAULT_COLOR_MODE } from "../../utils/constants";
import { getColor, prefixObject, stringifyStyles, } from "../../utils/style-utils";
export function getBackgroundStyles({ background, colorMode, }) {
const styles = { "--background": "initial" };
if (background?.type === "color") {
Object.assign(styles, {
"--background": getColor({
colorMap: background.value,
colorMode,
fallback: "transparent",
}),
});
}
const prefixedStyles = prefixObject(styles, "paywall");
return stringifyStyles(prefixedStyles);
}
export function getBackgroundImageSource(paywallData, colorMode) {
if (paywallData.components_config.base?.background?.type !== "image")
return "";
const backgroundObject = paywallData.components_config.base
.background;
return (backgroundObject.value[colorMode]?.original ||
backgroundObject.value[DEFAULT_COLOR_MODE]?.original);
}