Files
discord-decomp/modules/a11y/AccessibilityStore.tsx
T
2026-11-01 12:12:55 +02:00

566 lines
17 KiB
TypeScript

// Metro module 4181 (f4182).
import _objectWithoutProperties from "../../_bundle/_objectWithoutProperties";
import ThemeStore from "../user_settings/ThemeStore";
import UserSettingsProtoStore from "../user_settings/UserSettingsProtoStore";
import { Accessibility, ThemeTypes } from "../../Constants";
import { DEFAULT_COMPACT_SPACING, DEFAULT_COZY_SPACING, MESSAGE_GROUP_SPACING } from "../messages/MessageConstants";
import CrossPlatformNativeUtils_native from "../../utils/CrossPlatformNativeUtils.native";
import { ClientThemeSettings, MessageDisplayCompact } from "../user_settings/UserSettings";
import Module589 from "../../_bundle/Module589";
import { Storage } from "../../_bundle/Module595";
import { LOW_SATURATION_THRESHOLD } from "../../design/shared";
import Dispatcher from "../../Dispatcher";
import { HermesBuiltin } from "../../_hermes/prelude";
let _excluded, c2407_12, c2407_13, c2407_14, c2407_15, c2407_16;
const maybeApplyNoTextColorForLightCustomTheme = function maybeApplyNoTextColorForLightCustomTheme() {
const officialMessageStyleExplicitlySet = c2407_15.officialMessageStyleExplicitlySet;
let r3 = !officialMessageStyleExplicitlySet;
if (!officialMessageStyleExplicitlySet) {
let r1 = c2407_15.officialMessageStyle !== "default" || ThemeStore.theme !== ThemeTypes.LIGHT;
if (!r1) {
const setting = ClientThemeSettings.getSetting();
let r2 = setting.backgroundGradientPresetId != null;
if (!r2) {
const customUserThemeSettings = setting.customUserThemeSettings;
let r26 = customUserThemeSettings == null ? void 0 : customUserThemeSettings.colors?.length;
if (r26 == null) {
r26 = 0;
}
r2 = r26 > 0;
}
r1 = !r2;
}
let r29 = !r1;
if (!r1) {
c2407_15.officialMessageStyle = "no_text_color";
r29 = true;
}
r3 = r29;
}
return r3;
};
_excluded = ["fontScale"];
c2407_12 = {
DEFAULT: "default",
HIGH: "high"
};
c2407_13 = {
FLEXIBLE: "flexible",
CONDENSED: "condensed",
HIDDEN: "hidden"
};
c2407_14 = {
fontSize: Accessibility.FONT_SIZE_DEFAULT,
zoom: Accessibility.ZOOM_DEFAULT,
keyboardModeEnabled: false,
contrastMode: c2407_12.DEFAULT,
colorblindMode: false,
lowContrastMode: false,
saturation: 1,
contrast: 1,
desaturateUserColors: false,
forcedColorsModalSeen: false,
keyboardNavigationExplainerModalSeen: false,
messageGroupSpacing: null,
systemPrefersReducedMotion: "no-preference",
systemPrefersCrossfades: false,
prefersReducedMotion: "auto",
systemForcedColors: "none",
syncForcedColors: true,
systemPrefersContrast: "no-preference",
alwaysShowLinkDecorations: false,
roleStyle: "username",
officialMessageStyle: "default",
officialMessageStyleExplicitlySet: false,
displayNameStylesEnabled: true,
submitButtonEnabled: false,
syncProfileThemeWithUserTheme: false,
enableCustomCursor: true,
switchIconsEnabled: false,
appsButtonEnabled: true,
expressionPickerFormat: c2407_13.FLEXIBLE,
condensePickerWhenNarrow: true,
emojiButtonEnabled: true,
gifButtonEnabled: true,
stickerButtonEnabled: true
};
c2407_15 = c2407_14;
c2407_16 = {
12: "font-size-12",
14: "font-size-14",
15: "font-size-15",
16: "font-size-16",
18: "font-size-18",
20: "font-size-20",
24: "font-size-24"
};
class AccessibilityStore extends Module589.DeviceSettingsStore {
static displayName = "AccessibilityStore";
static persistKey = "AccessibilityStore";
static migrations = [() => {
const fontScale2 = Storage.get("a11yFontScale") || 100;
const zoom2 = Storage.get("a11yZoom") || Accessibility.ZOOM_DEFAULT;
const colorblindMode2 = Storage.get("a11yColorblindMode") || false;
Storage.remove("a11yFontScale");
Storage.remove("a11yZoom");
Storage.remove("a11yColorblindMode");
return {
fontScale: fontScale2,
zoom: zoom2,
colorblindMode: colorblindMode2,
keyboardModeEnabled: false
};
}, (a0) => {
const fontScale2 = a0.fontScale;
return {
..._objectWithoutProperties(a0, _excluded),
fontSize: fontScale2 === 82 ? 12 : fontScale2 === 92 ? 15 : fontScale2 !== 100 ? fontScale2 === 110 ? 18 : fontScale2 === 125 ? 20 : fontScale2 === 150 ? 24 : 16 : 16
};
}, (a0) => ({
...a0,
darkSidebar: false
}), (a0) => ({
...a0,
messageGroupSpacing: null
}), (a0) => ({
...a0,
systemPrefersReducedMotion: "no-preference",
prefersReducedMotion: "auto"
}), (a0) => ({
...a0,
alwaysShowLinkDecorations: a0.saturation <= LOW_SATURATION_THRESHOLD
}), (a0) => ({
...a0,
disableVoiceBackgrounds: false
}), (a0) => {
try {
delete a0["disableVoiceBackgrounds"];
} catch ($e) {}
return a0;
}, (a0) => {
try {
delete a0["hideGuildTags"];
} catch ($e) {}
return a0;
}, (a0) => ({
...a0,
enableCustomCursor: true
}), (a0) => ({
...a0,
appsButtonEnabled: true,
expressionPickerFormat: c2407_13.FLEXIBLE,
condensePickerWhenNarrow: true,
emojiButtonEnabled: true,
gifButtonEnabled: true,
stickerButtonEnabled: true
})];
initialize(a0) {
let r6 = a0;
this.waitFor(UserSettingsProtoStore);
const r14 = {
...c2407_14
};
if (a0 == null) {
r6 = null;
}
HermesBuiltin.copyDataProperties(r14, r6);
c2407_15 = r14;
if (isNaN(c2407_15.fontSize)) {
c2407_15.fontSize = Accessibility.FONT_SIZE_DEFAULT;
}
if (MESSAGE_GROUP_SPACING.indexOf(c2407_15.messageGroupSpacing != null ? c2407_15.messageGroupSpacing : -1) < 0) {
c2407_15.messageGroupSpacing = null;
}
this.syncWith([UserSettingsProtoStore], maybeApplyNoTextColorForLightCustomTheme);
}
get fontScale() {
return c2407_15.fontSize / Accessibility.FONT_SIZE_DEFAULT * 100;
}
get fontSize() {
return c2407_15.fontSize;
}
get isFontScaledUp() {
return c2407_15.fontSize > Accessibility.FONT_SIZE_DEFAULT;
}
get isFontScaledDown() {
return c2407_15.fontSize < Accessibility.FONT_SIZE_DEFAULT;
}
get fontScaleClass() {
let r12;
let r4 = c2407_16[this.fontSize];
if (r4 == null) {
r4 = "";
}
if (this.isFontScaledUp) {
r12 = `a11y-font-scaled-up ${r4}`;
} else {
const isFontScaledDown2 = this.isFontScaledDown;
const concat = HermesInternal.concat;
r12 = isFontScaledDown2 ? concat.call("a11y-font-scaled-down ", r4) : concat.call("", r4);
}
return r12;
}
get zoom() {
return c2407_15.zoom;
}
get isZoomedIn() {
return c2407_15.zoom > Accessibility.ZOOM_DEFAULT;
}
get isZoomedOut() {
return c2407_15.zoom < Accessibility.ZOOM_DEFAULT;
}
get keyboardModeEnabled() {
return c2407_15.keyboardModeEnabled;
}
get colorblindMode() {
return c2407_15.colorblindMode;
}
get lowContrastMode() {
return c2407_15.lowContrastMode;
}
get saturation() {
return c2407_15.saturation;
}
get contrast() {
return c2407_15.contrast;
}
get desaturateUserColors() {
return c2407_15.desaturateUserColors;
}
get forcedColorsModalSeen() {
return c2407_15.forcedColorsModalSeen;
}
get keyboardNavigationExplainerModalSeen() {
return c2407_15.keyboardNavigationExplainerModalSeen;
}
get messageGroupSpacing() {
return c2407_15.messageGroupSpacing != null ? c2407_15.messageGroupSpacing : MessageDisplayCompact.getSetting() ? DEFAULT_COMPACT_SPACING : DEFAULT_COZY_SPACING;
}
get isMessageGroupSpacingIncreased() {
return this.messageGroupSpacing > (MessageDisplayCompact.getSetting() ? DEFAULT_COMPACT_SPACING : DEFAULT_COZY_SPACING);
}
get isMessageGroupSpacingDecreased() {
return this.messageGroupSpacing < (MessageDisplayCompact.getSetting() ? DEFAULT_COMPACT_SPACING : DEFAULT_COZY_SPACING);
}
get isSubmitButtonEnabled() {
return c2407_15.submitButtonEnabled;
}
get syncProfileThemeWithUserTheme() {
return c2407_15.syncProfileThemeWithUserTheme;
}
get systemPrefersReducedMotion() {
return c2407_15.systemPrefersReducedMotion;
}
get rawPrefersReducedMotion() {
return c2407_15.prefersReducedMotion;
}
get useReducedMotion() {
const prefersReducedMotion = c2407_15.prefersReducedMotion;
if (prefersReducedMotion === "no-preference") {
return false;
}
if (prefersReducedMotion === "reduce") {
return true;
}
return c2407_15.systemPrefersReducedMotion === "reduce";
}
get systemForcedColors() {
return c2407_15.systemForcedColors;
}
get syncForcedColors() {
return c2407_15.syncForcedColors;
}
get useForcedColors() {
const syncForcedColors2 = c2407_15.syncForcedColors;
return !(syncForcedColors2 ? c2407_15.systemForcedColors !== "active" : !syncForcedColors2);
}
get systemPrefersContrast() {
return c2407_15.systemPrefersContrast;
}
get systemPrefersCrossfades() {
return c2407_15.systemPrefersCrossfades;
}
get alwaysShowLinkDecorations() {
return c2407_15.alwaysShowLinkDecorations;
}
get enableCustomCursor() {
return c2407_15.enableCustomCursor;
}
get roleStyle() {
return c2407_15.roleStyle;
}
get officialMessageStyle() {
return c2407_15.officialMessageStyle;
}
get displayNameStylesEnabled() {
return c2407_15.displayNameStylesEnabled;
}
get isHighContrastModeEnabled() {
return c2407_15.contrastMode === c2407_12.HIGH;
}
get isSwitchIconsEnabled() {
return c2407_15.switchIconsEnabled;
}
get isAppsButtonEnabled() {
return c2407_15.appsButtonEnabled;
}
get expressionPickerFormat() {
return c2407_15.expressionPickerFormat;
}
get condensePickerWhenNarrow() {
return c2407_15.condensePickerWhenNarrow;
}
get isEmojiButtonEnabled() {
return c2407_15.emojiButtonEnabled;
}
get isGifButtonEnabled() {
return c2407_15.gifButtonEnabled;
}
get isStickerButtonEnabled() {
return c2407_15.stickerButtonEnabled;
}
getUserAgnosticState() {
return c2407_15;
}
}
const accessibilityStore = new AccessibilityStore(Dispatcher, {
ACCESSIBILITY_SET_FONT_SIZE: function handleFontScaleTo({ fontSize: fontSize2 }) {
if (!(Accessibility.FONT_SIZES.indexOf(fontSize2) >= 0)) {
fontSize2 = Accessibility.FONT_SIZE_DEFAULT;
}
if (!(fontSize2 > Accessibility.FONT_SIZE_MAX) && !(fontSize2 < Accessibility.FONT_SIZE_MIN) && c2407_15.fontSize !== fontSize2) {
const r15 = {
...c2407_15
};
c2407_15 = r15;
r15.fontSize = fontSize2;
return void 0;
}
return false;
},
ACCESSIBILITY_SET_ZOOM: function handleZoomTo(a0) {
if (!(a0.zoom < Accessibility.ZOOM_MIN) && !(a0.zoom > Accessibility.ZOOM_MAX) && c2407_15.zoom !== a0.zoom) {
const r13 = {
...c2407_15
};
c2407_15 = r13;
r13.zoom = a0.zoom;
CrossPlatformNativeUtils_native.setZoomFactor(c2407_15.zoom);
return void 0;
}
return false;
},
ACCESSIBILITY_RESET_TO_DEFAULT: function handleResetToDefault() {
const fontSize2 = c2407_15.fontSize;
const FONT_SIZE_DEFAULT = Accessibility.FONT_SIZE_DEFAULT;
const zoom2 = c2407_15.zoom;
const ZOOM_DEFAULT = Accessibility.ZOOM_DEFAULT;
if (fontSize2 === FONT_SIZE_DEFAULT && zoom2 === ZOOM_DEFAULT) {
return false;
}
const r11 = {
...c2407_15
};
c2407_15 = r11;
if (r11.fontSize !== Accessibility.FONT_SIZE_DEFAULT) {
c2407_15.fontSize = Accessibility.FONT_SIZE_DEFAULT;
}
if (c2407_15.zoom !== Accessibility.ZOOM_DEFAULT) {
c2407_15.zoom = Accessibility.ZOOM_DEFAULT;
CrossPlatformNativeUtils_native.setZoomFactor(c2407_15.zoom);
}
},
ACCESSIBILITY_KEYBOARD_MODE_ENABLE: function handleEnableKeyboardMode() {
if (c2407_15.keyboardModeEnabled) {
return false;
}
const r7 = {
...c2407_15
};
c2407_15 = r7;
r7.keyboardModeEnabled = true;
},
ACCESSIBILITY_KEYBOARD_MODE_DISABLE: function handleDisableKeyboardMode() {
if (c2407_15.keyboardModeEnabled) {
const r7 = {
...c2407_15
};
c2407_15 = r7;
r7.keyboardModeEnabled = false;
return void 0;
}
return false;
},
ACCESSIBILITY_COLORBLIND_TOGGLE: function handleToggleColorblindMode() {
const r1 = {
...c2407_15
};
c2407_15 = r1;
r1.colorblindMode = !r1.colorblindMode;
},
ACCESSIBILITY_LOW_CONTRAST_TOGGLE: function handleToggleLowContrastMode() {
const r1 = {
...c2407_15
};
c2407_15 = r1;
r1.lowContrastMode = !r1.lowContrastMode;
},
ACCESSIBILITY_SET_SATURATION: function handleSetSaturation(a0) {
const r2 = {
...c2407_15
};
c2407_15 = r2;
r2.saturation = a0.saturation;
},
ACCESSIBILITY_DESATURATE_ROLES_TOGGLE: function handledesaturateUserColorsToggle() {
const r1 = {
...c2407_15
};
c2407_15 = r1;
r1.desaturateUserColors = !r1.desaturateUserColors;
},
ACCESSIBILITY_SYSTEM_COLOR_PREFERENCES_CHANGED: function handleSystemColorPreferencesChanged({ systemForcedColors: systemForcedColors2 }) {
if (systemForcedColors2 == null) {
systemForcedColors2 = "none";
}
c2407_15 = {
...c2407_15,
systemForcedColors: systemForcedColors2
};
},
ACCESSIBILITY_SYSTEM_PREFERS_CONTRAST_CHANGED: function handleSystemPrefersContrastChanged(a0) {
if (c2407_15.systemPrefersContrast === a0.systemPrefersContrast) {
return false;
}
c2407_15 = {
...c2407_15,
systemPrefersContrast: a0.systemPrefersContrast
};
},
ACCESSIBILITY_SYSTEM_PREFERS_REDUCED_MOTION_CHANGED: function handleSystemPrefersReducedMotionChanged(a0) {
if (c2407_15.systemPrefersReducedMotion === a0.systemPrefersReducedMotion) {
return false;
}
c2407_15 = {
...c2407_15,
systemPrefersReducedMotion: a0.systemPrefersReducedMotion
};
},
ACCESSIBILITY_SYSTEM_PREFERS_CROSSFADES_CHANGED: function handleSystemPrefersCrossfadesChanged(a0) {
if (c2407_15.systemPrefersCrossfades === a0.systemPrefersCrossfades) {
return false;
}
c2407_15 = {
...c2407_15,
systemPrefersCrossfades: a0.systemPrefersCrossfades
};
},
ACCESSIBILITY_SET_PREFERS_REDUCED_MOTION: function handleSetPrefersReducedMotion(a0) {
if (c2407_15.prefersReducedMotion === a0.prefersReducedMotion) {
return false;
}
c2407_15 = {
...c2407_15,
prefersReducedMotion: a0.prefersReducedMotion
};
},
ACCESSIBILITY_SET_SYNC_FORCED_COLORS: function handleSetSyncForcedColors(a0) {
c2407_15.syncForcedColors = a0.syncForcedColors;
},
ACCESSIBILITY_SET_ALWAYS_SHOW_LINK_DECORATIONS: function handleSetAlwaysShowLinkDecorations(a0) {
c2407_15 = {
...c2407_15,
alwaysShowLinkDecorations: a0.alwaysShowLinkDecorations
};
},
ACCESSIBILITY_SET_ENABLE_CUSTOM_CURSOR: function handleSetEnableCustomCursor(a0) {
c2407_15 = {
...c2407_15,
enableCustomCursor: a0.enableCustomCursor
};
},
ACCESSIBILITY_SET_ROLE_STYLE: function handleSetRoleStyle(a0) {
c2407_15.roleStyle = a0.roleStyle;
},
ACCESSIBILITY_SET_OFFICIAL_MESSAGE_STYLE: function handleSetOfficialMessageStyle(a0) {
c2407_15.officialMessageStyle = a0.officialMessageStyle;
c2407_15.officialMessageStyleExplicitlySet = true;
},
ACCESSIBILITY_SET_DISPLAY_NAME_STYLES_ENABLED: function handleSetDisplayNameStylesEnabled(a0) {
c2407_15.displayNameStylesEnabled = a0.enabled;
},
ACCESSIBILITY_FORCED_COLORS_MODAL_SEEN: function handleForcedColorsModalSeen() {
c2407_15.forcedColorsModalSeen = true;
},
KEYBOARD_NAVIGATION_EXPLAINER_MODAL_SEEN: function handleKeyboardNavigationExplainerModalSeen() {
c2407_15 = {
...c2407_15,
keyboardNavigationExplainerModalSeen: true
};
},
ACCESSIBILITY_SET_MESSAGE_GROUP_SPACING: function handleMessageGroupSpacingChange(a0) {
c2407_15 = {
...c2407_15,
messageGroupSpacing: a0.messageGroupSpacing
};
},
ACCESSIBILITY_SUBMIT_BUTTON_TOGGLE: function handleSubmitButtonToggle() {
const r1 = {
...c2407_15
};
c2407_15 = r1;
r1.submitButtonEnabled = !r1.submitButtonEnabled;
},
ACCESSIBILITY_SYNC_PROFILE_THEME_WITH_USER_THEME_TOGGLE: function handleSyncProfileThemeWithUserThemeToggle() {
const r1 = {
...c2407_15
};
c2407_15 = r1;
r1.syncProfileThemeWithUserTheme = !r1.syncProfileThemeWithUserTheme;
},
ACCESSIBILITY_SET_CONTRAST: function handleSetContrast(a0) {
c2407_15 = {
...c2407_15,
contrast: a0.contrast
};
},
ACCESSIBILITY_SET_CONTRAST_MODE: function handleSetContrastMode(a0) {
c2407_15 = {
...c2407_15,
contrastMode: a0.contrastMode
};
},
ACCESSIBILITY_SET_SWITCH_ICONS_ENABLED: function handleSetSwitchIconsEnabled(a0) {
c2407_15 = {
...c2407_15,
switchIconsEnabled: a0.switchIconsEnabled
};
},
ACCESSIBILITY_SET_CHAT_BAR_SETTINGS: function handleSetChatBarSettings(a0) {
c2407_15 = {
...c2407_15,
...a0.appsButtonEnabled != null && {
appsButtonEnabled: a0.appsButtonEnabled
},
...a0.expressionPickerFormat != null && {
expressionPickerFormat: a0.expressionPickerFormat
},
...a0.condensePickerWhenNarrow != null && {
condensePickerWhenNarrow: a0.condensePickerWhenNarrow
},
...a0.emojiButtonEnabled != null && {
emojiButtonEnabled: a0.emojiButtonEnabled
},
...a0.gifButtonEnabled != null && {
gifButtonEnabled: a0.gifButtonEnabled
},
...a0.stickerButtonEnabled != null && {
stickerButtonEnabled: a0.stickerButtonEnabled
}
};
}
});
export default accessibilityStore;
export { c2407_12 as AccessibilityContrastMode };
export { c2407_13 as ExpressionPickerFormat };