Files
discord-decomp/modules/client_themes/native/ClientThemesUtils.tsx
T
2026-11-01 12:12:55 +02:00

239 lines
9.0 KiB
TypeScript

// Metro module 4000 (f4001).
import _slicedToArray from "../../../_bundle/_slicedToArray";
import { useMemo } from "react";
import ThemeStore from "../../user_settings/ThemeStore";
import ClientThemesBackgroundStore from "../ClientThemesBackgroundStore";
import CustomThemeMobileStore from "./CustomThemeMobileStore";
import Module712 from "../../../_bundle/Module712";
import Module689 from "../../../_bundle/Module689";
import { hexToRgb, mixColors, hexWithOpacity } from "../../../utils/ColorUtils";
import Color from "../../../utils/Color";
import { ClientThemeType } from "../ClientThemesTypes";
import * as _shared from "../../../design/shared";
import useColorThemeBackground from "./useColorThemeBackground";
import useTheme from "../../../hooks/useTheme";
import { getCustomBackgroundGradient } from "./MobileThemesUtils";
function $mk73404() {
return (a0) => a0.stop;
}
let c2278_8, c2278_9, c2278_10, c2278_11, getBottomColorWithOpacity, getTopColorWithOpacity, calculateGradientValueWithOpacity, $mk73405 = function() {
return (a0) => Module712.unsafe_rawColors[a0.token];
};
const getGradientColorByPercentage = function getGradientColorByPercentage(a0, a1) {
if (a0.type === ClientThemeType.BACKGROUND_GRADIENT_PRESET) {
const r44 = a0.colors.map($mk73405());
const r48 = a0.colors.map($mk73404());
const r61 = _slicedToArray(Module689.scale(r44).domain(r48)(a1).rgb(), 3);
return {
r: r61[0],
g: r61[1],
b: r61[2]
};
}
const colors = a0.customThemeSettings.colors;
if (colors.length === 1) {
return hexToRgb(colors[0]);
}
const r10 = colors.map((color, index) => index / (colors.length - 1) * 100);
const r31 = _slicedToArray(Module689.scale(colors).domain(r10)(a1).rgb(), 3);
return {
r: r31[0],
g: r31[1],
b: r31[2]
};
};
getBottomColorWithOpacity = function getBottomColorWithOpacity(a0, a1, a2) {
const gradientColorByPercentage = getGradientColorByPercentage(a0, (a0.type === ClientThemeType.BACKGROUND_GRADIENT_PRESET ? a0.angle : a0.customThemeSettings.gradientAngle) > c2278_8 ? c2278_11.END : c2278_11.START);
const r47 = mixColors(new Color(gradientColorByPercentage.r, gradientColorByPercentage.g, gradientColorByPercentage.b, a2), new Color(a1.r, a1.g, a1.b, 1 - a2));
return Module689.rgb(r47.red, r47.green, r47.blue).hex("rgb");
};
getTopColorWithOpacity = function getTopColorWithOpacity(a0, a1, a2) {
const gradientColorByPercentage = getGradientColorByPercentage(a0, (a0.type === ClientThemeType.BACKGROUND_GRADIENT_PRESET ? a0.angle : a0.customThemeSettings.gradientAngle) > c2278_8 ? c2278_11.START : c2278_11.END);
const r47 = mixColors(new Color(gradientColorByPercentage.r, gradientColorByPercentage.g, gradientColorByPercentage.b, a2), new Color(a1.r, a1.g, a1.b, 1 - a2));
return Module689.rgb(r47.red, r47.green, r47.blue).hex("rgb");
};
calculateGradientValueWithOpacity = function calculateGradientValueWithOpacity(a0, a1, theme, a3) {
let r39, r49, r104;
const r10 = _shared.isThemeDark(theme) ? hexToRgb(c2278_10.DARK) : hexToRgb(c2278_10.LIGHT);
if (a0.type === ClientThemeType.BACKGROUND_GRADIENT_PRESET) {
let midpointPercentage = a0.midpointPercentage;
if (midpointPercentage == null) {
midpointPercentage = c2278_11.MID;
}
r39 = midpointPercentage;
} else {
r39 = c2278_11.MID;
}
const r12 = a1 == null ? r39 : a1;
let r43 = a3;
if (a0.type === ClientThemeType.CUSTOM_BACKGROUND_GRADIENT) {
const r1 = a0.customThemeSettings.baseMix / 100;
if (a3 == null) {
const isThemeDark = _shared.isThemeDark(theme);
const r2 = 0.2 * r1;
r43 = isThemeDark ? 0.12 + r2 : 0.3 + r2;
}
r49 = r43;
} else {
r49 = a3 == null ? _shared.isThemeDark(theme) ? c2278_9.LEVEL_2 : c2278_9.LEVEL_4 : a3;
}
const r71 = a0.type === ClientThemeType.BACKGROUND_GRADIENT_PRESET ? a0.angle : a0.customThemeSettings.gradientAngle;
if (r12 === c2278_11.START) {
r104 = r71 < c2278_8 ? getBottomColorWithOpacity(a0, r10, r49) : getTopColorWithOpacity(a0, r10, r49);
} else if (r12 === c2278_11.END) {
r104 = r71 > c2278_8 ? getBottomColorWithOpacity(a0, r10, r49) : getTopColorWithOpacity(a0, r10, r49);
} else {
const gradientColorByPercentage = getGradientColorByPercentage(a0, r12);
const r94 = mixColors(new Color(gradientColorByPercentage.r, gradientColorByPercentage.g, gradientColorByPercentage.b, r49), new Color(r10.r, r10.g, r10.b, 1 - r49));
r104 = Module689.rgb(r94.red, r94.green, r94.blue).hex("rgb");
}
return r104;
};
c2278_8 = 128;
const r29 = {
LEVEL_9: 0.9
};
r29[0.9] = "LEVEL_9";
r29.LEVEL_85 = 0.85;
r29[0.85] = "LEVEL_85";
r29.LEVEL_8 = 0.8;
r29[0.8] = "LEVEL_8";
r29.LEVEL_75 = 0.75;
r29[0.75] = "LEVEL_75";
r29.LEVEL_7 = 0.7;
r29[0.7] = "LEVEL_7";
r29.LEVEL_6 = 0.6;
r29[0.6] = "LEVEL_6";
r29.LEVEL_5 = 0.5;
r29[0.5] = "LEVEL_5";
r29.LEVEL_4 = 0.4;
r29[0.4] = "LEVEL_4";
r29.LEVEL_35 = 0.35;
r29[0.35] = "LEVEL_35";
r29.LEVEL_3 = 0.3;
r29[0.3] = "LEVEL_3";
r29.LEVEL_25 = 0.25;
r29[0.25] = "LEVEL_25";
r29.LEVEL_2 = 0.2;
r29[0.2] = "LEVEL_2";
r29.LEVEL_15 = 0.15;
r29[0.15] = "LEVEL_15";
r29.LEVEL_1 = 0.1;
r29[0.1] = "LEVEL_1";
c2278_9 = r29;
c2278_10 = {
DARK: Module712.unsafe_rawColors.BLACK,
LIGHT: Module712.unsafe_rawColors.WHITE
};
c2278_11 = {
START: 0,
0: "START",
MID: 50,
50: "MID",
END: 100,
100: "END"
};
export const GRADIENT_ANGLE_BREAKPOINT = 128;
export { c2278_9 as OverlayOpacity };
export { c2278_10 as OverlayColors };
export { c2278_11 as GradientPercentage };
export function colorToHex(a0) {
return Module689.rgb(a0.red, a0.green, a0.blue).hex("rgb");
}
export function getClientThemesGradientColorByPercentage(a0, a1) {
const r7 = a0.colors.map($mk73405());
const r11 = a0.colors.map($mk73404());
const r25 = _slicedToArray(Module689.scale(r7).domain(r11)(a1).rgb(), 3);
return {
r: r25[0],
g: r25[1],
b: r25[2]
};
}
export function getClientThemesGradientHexColors(a0) {
return a0.colors.map($mk73405());
}
export function getGradientThemeMetadata(a0, a1) {
if (a0 != null && a1 != null) {
const r14 = calculateGradientValueWithOpacity(a1, c2278_11.START, a1.theme);
const r13 = calculateGradientValueWithOpacity(a1, c2278_11.MID, a1.theme);
const r12 = calculateGradientValueWithOpacity(a1, c2278_11.END, a1.theme);
const r37 = a1.type === ClientThemeType.BACKGROUND_GRADIENT_PRESET ? a1.angle : a1.customThemeSettings.gradientAngle;
const r38 = r37 > c2278_8 ? r14 : r12;
const r39 = r37 > c2278_8 ? r12 : r14;
const r46 = a1.type === ClientThemeType.BACKGROUND_GRADIENT_PRESET ? a1.colors.map($mk73405()) : a1.customThemeSettings.colors;
let r48 = r46[0];
let r51 = r46[r46.length - 1];
if (a1.type === ClientThemeType.CUSTOM_BACKGROUND_GRADIENT) {
const colors2 = a1.customThemeSettings.colors;
const r21 = colors2.map((item) => Module689(item).luminance());
const r23 = Math;
let r82 = Module689(colors2[r21.indexOf(r23.min.apply(r23, [...r21]))]).set("hsl.s", 0.2).set("hsl.l", 0.7).hex();
const r86 = Math;
const r106 = Module689(colors2[r21.indexOf(r86.max.apply(r86, [...r21]))]).set("hsl.s", 0.2).set("hsl.l", 0.9).hex();
const r108 = a0 === "dark";
const r109 = r108 ? r82 : r106;
if (r108) {
r82 = r106;
}
r51 = r82;
r48 = r109;
}
return {
theme: a0,
colors: {
"gradient.start": r14,
"gradient.mid": r13,
"gradient.end": r12,
"gradient.top": r38,
"gradient.bottom": r39,
"gradient.primary": r48,
"gradient.secondary": r51
}
};
}
return null;
}
export function getGradientValue(a0, a1) {
return calculateGradientValueWithOpacity(a0, a1, a0.theme);
}
export function useGradientValue(a0, a1) {
const colorThemeBackground = useColorThemeBackground();
let c13773_2 = colorThemeBackground;
const theme = useTheme();
let c13773_3 = theme;
return useMemo(() => {
if (c13773_2 == null) {
return null;
}
if (a1?.dark == null && a1?.light == null) {
return calculateGradientValueWithOpacity(c13773_2, a0, c13773_3);
}
const r29 = _shared.isThemeDark(c13773_3) ? c2278_9.LEVEL_2 : c2278_9.LEVEL_4;
const isThemeDark = _shared.isThemeDark(c13773_3);
const r34 = a1 == null;
let r35 = isThemeDark ? r34 ? void 0 : a1.dark : r34 ? void 0 : a1.light;
if (r35 == null) {
r35 = r29;
}
return calculateGradientValueWithOpacity(c13773_2, a0, c13773_3, r35);
}, [colorThemeBackground, a1?.dark, a1?.light, a0, theme]);
}
export function getEmbedScrollGradientBackground() {
let r6 = getCustomBackgroundGradient();
if (r6 == null) {
r6 = ClientThemesBackgroundStore.gradientPreset;
}
if (r6 == null) {
r6 = null;
}
return r6 == null ? null : calculateGradientValueWithOpacity(r6, void 0, r6.theme);
}
export function getEmbedBackground() {
const hasCustomTheme = CustomThemeMobileStore.hasCustomTheme();
if (ClientThemesBackgroundStore.gradientPreset == null && !hasCustomTheme) {
return null;
}
return hexWithOpacity(_shared.isThemeDark(ThemeStore.theme) ? c2278_10.DARK : c2278_10.LIGHT, c2278_9.LEVEL_1);
}