// @ts-ignore import pSBC from "shade-blend-color"; import styles from "./Panes.module.scss"; import { Text } from "preact-i18n"; import { useCallback, useContext, useEffect, useState } from "preact/hooks"; import TextAreaAutoSize from "../../../lib/TextAreaAutoSize"; import { debounce } from "../../../lib/debounce"; import { dispatch } from "../../../redux"; import { connectState } from "../../../redux/connector"; import { EmojiPacks, Settings } from "../../../redux/reducers/settings"; import { DEFAULT_FONT, DEFAULT_MONO_FONT, FONTS, FONT_KEYS, MONOSCAPE_FONTS, MONOSCAPE_FONT_KEYS, Theme, ThemeContext, ThemeOptions, } from "../../../context/Theme"; import { useIntermediate } from "../../../context/intermediate/Intermediate"; import CollapsibleSection from "../../../components/common/CollapsibleSection"; import Button from "../../../components/ui/Button"; import Checkbox from "../../../components/ui/Checkbox"; import ColourSwatches from "../../../components/ui/ColourSwatches"; import ComboBox from "../../../components/ui/ComboBox"; import InputBox from "../../../components/ui/InputBox"; import darkSVG from "../assets/dark.svg"; import lightSVG from "../assets/light.svg"; import mutantSVG from "../assets/mutant_emoji.svg"; import notoSVG from "../assets/noto_emoji.svg"; import openmojiSVG from "../assets/openmoji_emoji.svg"; import twemojiSVG from "../assets/twemoji_emoji.svg"; interface Props { settings: Settings; } // ! FIXME: code needs to be rewritten to fix jittering export function Component(props: Props) { const theme = useContext(ThemeContext); const { writeClipboard, openScreen } = useIntermediate(); function setTheme(theme: ThemeOptions) { dispatch({ type: "SETTINGS_SET_THEME", theme, }); } function pushOverride(custom: Partial) { dispatch({ type: "SETTINGS_SET_THEME_OVERRIDE", custom, }); } function setAccent(accent: string) { setOverride({ accent, "scrollbar-thumb": pSBC(-0.2, accent), }); } const emojiPack = props.settings.appearance?.emojiPack ?? "mutant"; function setEmojiPack(emojiPack: EmojiPacks) { dispatch({ type: "SETTINGS_SET_APPEARANCE", options: { emojiPack, }, }); } const setOverride = useCallback(debounce(pushOverride, 200), []) as ( custom: Partial, ) => void; const [css, setCSS] = useState(props.settings.theme?.custom?.css ?? ""); useEffect(() => setOverride({ css }), [css]); const selected = props.settings.theme?.preset ?? "dark"; return (

selected !== "light" && setTheme({ preset: "light" }) } />

selected !== "dark" && setTheme({ preset: "dark" }) } />

{/* setTheme({ ligatures: !props.settings.theme?.ligatures, }) }> Use the system theme */}

{/*

} checked > } disabled >
*/}

pushOverride({ font: e.currentTarget.value as any }) }> {FONT_KEYS.map((key) => ( ))}

setTheme({ ligatures: !props.settings.theme?.ligatures, }) } description={ }>

setEmojiPack("mutant")} data-active={emojiPack === "mutant"}>

Mutant Remix{" "} (by Revolt)

setEmojiPack("twemoji")} data-active={emojiPack === "twemoji"}>

Twemoji

setEmojiPack("openmoji")} data-active={emojiPack === "openmoji"}>

Openmoji

setEmojiPack("noto")} data-active={emojiPack === "noto"}>

Noto Emoji

}>

{( [ "accent", "background", "foreground", "primary-background", "primary-header", "secondary-background", "secondary-foreground", "secondary-header", "tertiary-background", "tertiary-foreground", "block", "message-box", "mention", "scrollbar-thumb", "scrollbar-track", "status-online", "status-away", "status-busy", "status-streaming", "status-invisible", "success", "warning", "error", "hover", ] as const ).map((x) => (
{x}
setOverride({ [x]: v.currentTarget.value, }) } />
setOverride({ [x]: y.currentTarget.value, }) } />
))}

pushOverride({ monoscapeFont: e.currentTarget.value as any, }) }> {MONOSCAPE_FONT_KEYS.map((key) => ( ))}

setCSS(ev.currentTarget.value)} />
); } export const Appearance = connectState(Component, (state) => { return { settings: state.settings, }; });