react-native-uikit-colors
Version:
react native ui kit colors
195 lines (191 loc) • 5.82 kB
JavaScript
;
//#region rolldown:runtime
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 __commonJS = (cb, mod) => function() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: ((k) => from[k]).bind(null, 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));
//#endregion
const nativewind = __toESM(require("nativewind"));
const react = __toESM(require("react"));
const react_native = __toESM(require("react-native"));
const apple_uikit_colors = __toESM(require("apple-uikit-colors"));
//#region src/utils.ts
const getCurrentColors = () => {
const colorScheme = react_native.Appearance.getColorScheme() || "light";
return react_native.StyleSheet.compose(colorVariants[colorScheme], palette[colorScheme]);
};
const getSystemBackgroundColor = () => {
return getColor("systemBackground");
};
const mergedColorsLight = {
...apple_uikit_colors.lightElements,
...apple_uikit_colors.lightPalette
};
const mergedColorsDark = {
...apple_uikit_colors.darkElements,
...apple_uikit_colors.darkPalette
};
const getColor = (color) => {
const colorScheme = react_native.Appearance.getColorScheme() || "light";
const colors = colorScheme === "light" ? mergedColorsLight : mergedColorsDark;
return rgbStringToRgb(colors[color]);
};
const rgbStringToRgb = (input) => {
let rgbPart = input;
let alpha = 1;
if (input.includes("/")) {
const [rgb, a] = input.split("/");
rgbPart = rgb.trim();
alpha = Number.parseFloat(a.trim());
} else {
const parts = input.trim().split(/\s+/);
if (parts.length === 4) {
alpha = Number.parseFloat(parts[3]);
rgbPart = parts.slice(0, 3).join(" ");
}
}
const [r, g, b] = rgbPart.split(/\s+/).map((s) => Number.parseFloat(s));
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
};
//#endregion
//#region src/colors.ts
const IS_DOM = typeof ReactNativeWebView !== "undefined";
const varPrefix = "--color";
const buildVars = (_vars) => {
const cssVars = {};
for (const [key, value] of Object.entries(_vars)) cssVars[`${varPrefix}-${key}`] = value;
return IS_DOM ? cssVars : (0, nativewind.vars)(cssVars);
};
const palette = {
light: buildVars(apple_uikit_colors.lightPalette),
dark: buildVars(apple_uikit_colors.darkPalette)
};
const mergedLightColors = {
...apple_uikit_colors.lightElements,
...apple_uikit_colors.lightPalette
};
const mergedDarkColors = {
...apple_uikit_colors.darkElements,
...apple_uikit_colors.darkPalette
};
const mergedColors = {
light: mergedLightColors,
dark: mergedDarkColors
};
const mergedColorsHex = {
light: Object.fromEntries(Object.entries(mergedLightColors).map(([key, value]) => [key, rgbStringToRgb(value)])),
dark: Object.fromEntries(Object.entries(mergedDarkColors).map(([key, value]) => [key, rgbStringToRgb(value)]))
};
const colorVariants = {
light: buildVars(apple_uikit_colors.lightElements),
dark: buildVars(apple_uikit_colors.darkElements)
};
const useColor = (color) => {
const { colorScheme } = (0, nativewind.useColorScheme)();
const colors = mergedColorsHex[colorScheme || "light"];
return (0, react.useMemo)(() => colors[color], [color, colors]);
};
const useColorsVariants = () => {
const { colorScheme } = (0, nativewind.useColorScheme)();
return mergedColors[colorScheme || "light"];
};
const useColors = () => {
const { colorScheme } = (0, nativewind.useColorScheme)();
return mergedColorsHex[colorScheme || "light"];
};
const useCurrentColorsVariants = () => {
(0, nativewind.useColorScheme)();
return getCurrentColors();
};
//#endregion
Object.defineProperty(exports, '__commonJS', {
enumerable: true,
get: function () {
return __commonJS;
}
});
Object.defineProperty(exports, '__toESM', {
enumerable: true,
get: function () {
return __toESM;
}
});
Object.defineProperty(exports, 'colorVariants', {
enumerable: true,
get: function () {
return colorVariants;
}
});
Object.defineProperty(exports, 'getColor', {
enumerable: true,
get: function () {
return getColor;
}
});
Object.defineProperty(exports, 'getCurrentColors', {
enumerable: true,
get: function () {
return getCurrentColors;
}
});
Object.defineProperty(exports, 'getSystemBackgroundColor', {
enumerable: true,
get: function () {
return getSystemBackgroundColor;
}
});
Object.defineProperty(exports, 'palette', {
enumerable: true,
get: function () {
return palette;
}
});
Object.defineProperty(exports, 'rgbStringToRgb', {
enumerable: true,
get: function () {
return rgbStringToRgb;
}
});
Object.defineProperty(exports, 'useColor', {
enumerable: true,
get: function () {
return useColor;
}
});
Object.defineProperty(exports, 'useColors', {
enumerable: true,
get: function () {
return useColors;
}
});
Object.defineProperty(exports, 'useColorsVariants', {
enumerable: true,
get: function () {
return useColorsVariants;
}
});
Object.defineProperty(exports, 'useCurrentColorsVariants', {
enumerable: true,
get: function () {
return useCurrentColorsVariants;
}
});