78 lines
2 KiB
TypeScript
78 lines
2 KiB
TypeScript
// JSXInternal.CSSProperties
|
|
|
|
import { Conversation, Database, Message } from "types";
|
|
import { remove_undefined_keys } from "utils";
|
|
|
|
export const DEFAULT_FONT = '"courier-std", courier, monospace';
|
|
|
|
// gonna use special presets, page for page, default for default
|
|
// did that lol: default, page, box
|
|
export const DEFAULT_STYLE: preact.JSX.CSSProperties = {
|
|
color: "#000000",
|
|
fontFamily: DEFAULT_FONT,
|
|
fontWeight: "bold",
|
|
};
|
|
|
|
export function msg_style(
|
|
msg: Message,
|
|
db: Database,
|
|
conv?: Conversation
|
|
): preact.JSX.CSSProperties {
|
|
const preset_style_ = msg.preset ? preset_style(msg.preset, db, conv) : {};
|
|
const conv_default_style = conv?.presets?.default ?? {};
|
|
return {
|
|
...DEFAULT_STYLE,
|
|
...conv_default_style,
|
|
...preset_style_,
|
|
...convert_fg_bg_font(msg),
|
|
};
|
|
}
|
|
|
|
// conversation presets override global oness
|
|
function preset_style(
|
|
preset: string,
|
|
db: Database,
|
|
conv?: Conversation
|
|
): preact.JSX.CSSProperties {
|
|
if (conv && conv.presets && conv.presets[preset]) {
|
|
const preset_ = (conv.presets ?? {})[preset] ?? {};
|
|
|
|
const box_bg = conv?.presets.box?.bg;
|
|
if (!preset_.bg && box_bg) {
|
|
preset_.bg = box_bg;
|
|
}
|
|
return convert_fg_bg_font(preset_);
|
|
} else {
|
|
const preset_ = db.presets[preset] ?? {};
|
|
return convert_fg_bg_font(preset_);
|
|
}
|
|
}
|
|
|
|
export function convert_fg_bg_font(thing: {
|
|
fg?: string;
|
|
bg?: string;
|
|
font?: string;
|
|
}): preact.JSX.CSSProperties {
|
|
return remove_undefined_keys({
|
|
color: thing.fg,
|
|
backgroundColor: thing.bg,
|
|
fontFamily: thing.font,
|
|
});
|
|
}
|
|
|
|
export function conv_style(conv: Conversation) {
|
|
return {
|
|
...DEFAULT_STYLE,
|
|
...convert_fg_bg_font(conv.presets?.box ?? conv),
|
|
};
|
|
}
|
|
|
|
export function page_style(conv: Conversation) {
|
|
return {
|
|
color: "black",
|
|
backgroundColor: "white",
|
|
fontFamily: DEFAULT_FONT,
|
|
...remove_undefined_keys(convert_fg_bg_font(conv.presets?.page)),
|
|
};
|
|
}
|