Merge pull request #5179 from frostime/contrib-font

 feat(config): Config the font-family of chat content
This commit is contained in:
Dogtiti 2024-08-03 21:04:43 +08:00 committed by GitHub
commit 764c0cb865
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
25 changed files with 136 additions and 2 deletions

View File

@ -732,6 +732,7 @@ function _Chat() {
const session = chatStore.currentSession(); const session = chatStore.currentSession();
const config = useAppConfig(); const config = useAppConfig();
const fontSize = config.fontSize; const fontSize = config.fontSize;
const fontFamily = config.fontFamily;
const [showExport, setShowExport] = useState(false); const [showExport, setShowExport] = useState(false);
@ -1482,6 +1483,7 @@ function _Chat() {
setUserInput(getMessageTextContent(message)); setUserInput(getMessageTextContent(message));
}} }}
fontSize={fontSize} fontSize={fontSize}
fontFamily={fontFamily}
parentRef={scrollRef} parentRef={scrollRef}
defaultShow={i >= messages.length - 6} defaultShow={i >= messages.length - 6}
/> />
@ -1576,6 +1578,7 @@ function _Chat() {
autoFocus={autoFocus} autoFocus={autoFocus}
style={{ style={{
fontSize: config.fontSize, fontSize: config.fontSize,
fontFamily: config.fontFamily,
}} }}
/> />
{attachImages.length != 0 && ( {attachImages.length != 0 && (

View File

@ -583,6 +583,7 @@ export function ImagePreviewer(props: {
<Markdown <Markdown
content={getMessageTextContent(m)} content={getMessageTextContent(m)}
fontSize={config.fontSize} fontSize={config.fontSize}
fontFamily={config.fontFamily}
defaultShow defaultShow
/> />
{getMessageImages(m).length == 1 && ( {getMessageImages(m).length == 1 && (

View File

@ -232,6 +232,7 @@ export function Markdown(
content: string; content: string;
loading?: boolean; loading?: boolean;
fontSize?: number; fontSize?: number;
fontFamily?: string;
parentRef?: RefObject<HTMLDivElement>; parentRef?: RefObject<HTMLDivElement>;
defaultShow?: boolean; defaultShow?: boolean;
} & React.DOMAttributes<HTMLDivElement>, } & React.DOMAttributes<HTMLDivElement>,
@ -243,6 +244,7 @@ export function Markdown(
className="markdown-body" className="markdown-body"
style={{ style={{
fontSize: `${props.fontSize ?? 14}px`, fontSize: `${props.fontSize ?? 14}px`,
fontFamily: props.fontFamily || "inherit",
}} }}
ref={mdRef} ref={mdRef}
onContextMenu={props.onContextMenu} onContextMenu={props.onContextMenu}

View File

@ -1316,6 +1316,22 @@ export function Settings() {
></InputRange> ></InputRange>
</ListItem> </ListItem>
<ListItem
title={Locale.Settings.FontFamily.Title}
subTitle={Locale.Settings.FontFamily.SubTitle}
>
<input
type="text"
value={config.fontFamily}
placeholder={Locale.Settings.FontFamily.Placeholder}
onChange={(e) =>
updateConfig(
(config) => (config.fontFamily = e.currentTarget.value),
)
}
></input>
</ListItem>
<ListItem <ListItem
title={Locale.Settings.AutoGenerateTitle.Title} title={Locale.Settings.AutoGenerateTitle.Title}
subTitle={Locale.Settings.AutoGenerateTitle.SubTitle} subTitle={Locale.Settings.AutoGenerateTitle.SubTitle}

View File

@ -111,6 +111,11 @@ const ar: PartialLocaleType = {
Title: "حجم الخط", Title: "حجم الخط",
SubTitle: "ضبط حجم الخط لمحتوى الدردشة", SubTitle: "ضبط حجم الخط لمحتوى الدردشة",
}, },
FontFamily: {
Title: "خط الدردشة",
SubTitle: "خط محتوى الدردشة، اتركه فارغًا لتطبيق الخط الافتراضي العالمي",
Placeholder: "اسم الخط",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "حقن تلميحات النظام", Title: "حقن تلميحات النظام",
SubTitle: SubTitle:

View File

@ -136,6 +136,12 @@ const bn: PartialLocaleType = {
Title: "ফন্ট সাইজ", Title: "ফন্ট সাইজ",
SubTitle: "চ্যাট সামগ্রীর ফন্ট সাইজ সংশোধন করুন", SubTitle: "চ্যাট সামগ্রীর ফন্ট সাইজ সংশোধন করুন",
}, },
FontFamily: {
Title: "চ্যাট ফন্ট",
SubTitle:
"চ্যাট সামগ্রীর ফন্ট, বিশ্বব্যাপী ডিফল্ট ফন্ট প্রয়োগ করতে খালি রাখুন",
Placeholder: "ফন্টের নাম",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "حقن تلميحات النظام", Title: "حقن تلميحات النظام",
SubTitle: SubTitle:

View File

@ -156,6 +156,11 @@ const cn = {
Title: "字体大小", Title: "字体大小",
SubTitle: "聊天内容的字体大小", SubTitle: "聊天内容的字体大小",
}, },
FontFamily: {
Title: "聊天字体",
SubTitle: "聊天内容的字体,若置空则应用全局默认字体",
Placeholder: "字体名称",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "注入系统级提示信息", Title: "注入系统级提示信息",
SubTitle: "强制给每次请求的消息列表开头添加一个模拟 ChatGPT 的系统提示", SubTitle: "强制给每次请求的消息列表开头添加一个模拟 ChatGPT 的系统提示",

View File

@ -71,6 +71,12 @@ const cs: PartialLocaleType = {
Title: "Velikost písma", Title: "Velikost písma",
SubTitle: "Nastavení velikosti písma obsahu chatu", SubTitle: "Nastavení velikosti písma obsahu chatu",
}, },
FontFamily: {
Title: "Chatové Písmo",
SubTitle:
"Písmo obsahu chatu, ponechejte prázdné pro použití globálního výchozího písma",
Placeholder: "Název Písma",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "Vložit systémové prompty", Title: "Vložit systémové prompty",
SubTitle: SubTitle:

View File

@ -71,6 +71,12 @@ const de: PartialLocaleType = {
Title: "Schriftgröße", Title: "Schriftgröße",
SubTitle: "Schriftgröße des Chat-Inhalts anpassen", SubTitle: "Schriftgröße des Chat-Inhalts anpassen",
}, },
FontFamily: {
Title: "Chat-Schriftart",
SubTitle:
"Schriftart des Chat-Inhalts, leer lassen, um die globale Standardschriftart anzuwenden",
Placeholder: "Schriftartname",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "System-Prompts einfügen", Title: "System-Prompts einfügen",
SubTitle: SubTitle:

View File

@ -158,6 +158,12 @@ const en: LocaleType = {
Title: "Font Size", Title: "Font Size",
SubTitle: "Adjust font size of chat content", SubTitle: "Adjust font size of chat content",
}, },
FontFamily: {
Title: "Chat Font Family",
SubTitle:
"Font Family of the chat content, leave empty to apply global default font",
Placeholder: "Font Family Name",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "Inject System Prompts", Title: "Inject System Prompts",
SubTitle: "Inject a global system prompt for every request", SubTitle: "Inject a global system prompt for every request",

View File

@ -71,6 +71,12 @@ const es: PartialLocaleType = {
Title: "Tamaño de fuente", Title: "Tamaño de fuente",
SubTitle: "Ajustar el tamaño de fuente del contenido del chat", SubTitle: "Ajustar el tamaño de fuente del contenido del chat",
}, },
FontFamily: {
Title: "Fuente del Chat",
SubTitle:
"Fuente del contenido del chat, dejar vacío para aplicar la fuente predeterminada global",
Placeholder: "Nombre de la Fuente",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "Inyectar Prompts del Sistema", Title: "Inyectar Prompts del Sistema",
SubTitle: SubTitle:

View File

@ -111,6 +111,12 @@ const fr: PartialLocaleType = {
Title: "Taille des polices", Title: "Taille des polices",
SubTitle: "Ajuste la taille de police du contenu de la conversation", SubTitle: "Ajuste la taille de police du contenu de la conversation",
}, },
FontFamily: {
Title: "Police de Chat",
SubTitle:
"Police du contenu du chat, laissez vide pour appliquer la police par défaut globale",
Placeholder: "Nom de la Police",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "Injecter des invites système", Title: "Injecter des invites système",
SubTitle: SubTitle:

View File

@ -140,6 +140,12 @@ const id: PartialLocaleType = {
Title: "Ukuran Font", Title: "Ukuran Font",
SubTitle: "Ubah ukuran font konten chat", SubTitle: "Ubah ukuran font konten chat",
}, },
FontFamily: {
Title: "Font Obrolan",
SubTitle:
"Font dari konten obrolan, biarkan kosong untuk menerapkan font default global",
Placeholder: "Nama Font",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "Suntikkan Petunjuk Sistem", Title: "Suntikkan Petunjuk Sistem",
SubTitle: SubTitle:
@ -369,8 +375,8 @@ const id: PartialLocaleType = {
}, },
Exporter: { Exporter: {
Description: { Description: {
Title: "Hanya pesan setelah menghapus konteks yang akan ditampilkan" Title: "Hanya pesan setelah menghapus konteks yang akan ditampilkan",
}, },
Model: "Model", Model: "Model",
Messages: "Pesan", Messages: "Pesan",
Topic: "Topik", Topic: "Topik",

View File

@ -71,6 +71,12 @@ const it: PartialLocaleType = {
Title: "Dimensione carattere", Title: "Dimensione carattere",
SubTitle: "Regolare la dimensione dei caratteri del contenuto della chat", SubTitle: "Regolare la dimensione dei caratteri del contenuto della chat",
}, },
FontFamily: {
Title: "Font della Chat",
SubTitle:
"Carattere del contenuto della chat, lascia vuoto per applicare il carattere predefinito globale",
Placeholder: "Nome del Font",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "Inserisci Prompts di Sistema", Title: "Inserisci Prompts di Sistema",
SubTitle: SubTitle:

View File

@ -118,6 +118,12 @@ const jp: PartialLocaleType = {
Title: "フォントサイズ", Title: "フォントサイズ",
SubTitle: "チャット内容のフォントサイズ", SubTitle: "チャット内容のフォントサイズ",
}, },
FontFamily: {
Title: "チャットフォント",
SubTitle:
"チャットコンテンツのフォント、空白の場合はグローバルデフォルトフォントを適用します",
Placeholder: "フォント名",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "システムプロンプトの挿入", Title: "システムプロンプトの挿入",
SubTitle: SubTitle:

View File

@ -72,6 +72,11 @@ const ko: PartialLocaleType = {
Title: "글꼴 크기", Title: "글꼴 크기",
SubTitle: "채팅 내용의 글꼴 크기 조정", SubTitle: "채팅 내용의 글꼴 크기 조정",
}, },
FontFamily: {
Title: "채팅 폰트",
SubTitle: "채팅 내용의 폰트, 비워 두면 글로벌 기본 폰트를 적용",
Placeholder: "폰트 이름",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "시스템 프롬프트 주입", Title: "시스템 프롬프트 주입",
SubTitle: SubTitle:

View File

@ -66,6 +66,12 @@ const no: PartialLocaleType = {
Title: "Fontstørrelsen", Title: "Fontstørrelsen",
SubTitle: "Juster fontstørrelsen for samtaleinnholdet.", SubTitle: "Juster fontstørrelsen for samtaleinnholdet.",
}, },
FontFamily: {
Title: "Chat-skrifttype",
SubTitle:
"Skrifttypen for chatinnhold, la stå tom for å bruke global standardskrifttype",
Placeholder: "Skriftnavn",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "Sett inn systemprompter", Title: "Sett inn systemprompter",
SubTitle: SubTitle:

View File

@ -153,6 +153,12 @@ const pt: PartialLocaleType = {
Title: "Tamanho da Fonte", Title: "Tamanho da Fonte",
SubTitle: "Ajustar o tamanho da fonte do conteúdo do chat", SubTitle: "Ajustar o tamanho da fonte do conteúdo do chat",
}, },
FontFamily: {
Title: "Fonte do Chat",
SubTitle:
"Fonte do conteúdo do chat, deixe vazio para aplicar a fonte padrão global",
Placeholder: "Nome da Fonte",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "Inserir Prompts de Sistema", Title: "Inserir Prompts de Sistema",
SubTitle: "Inserir um prompt de sistema global para cada requisição", SubTitle: "Inserir um prompt de sistema global para cada requisição",

View File

@ -71,6 +71,12 @@ const ru: PartialLocaleType = {
Title: "Размер шрифта", Title: "Размер шрифта",
SubTitle: "Настроить размер шрифта контента чата", SubTitle: "Настроить размер шрифта контента чата",
}, },
FontFamily: {
Title: "Шрифт чата",
SubTitle:
"Шрифт содержимого чата, оставьте пустым для применения глобального шрифта по умолчанию",
Placeholder: "Название шрифта",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "Вставить системные подсказки", Title: "Вставить системные подсказки",
SubTitle: SubTitle:

View File

@ -155,6 +155,12 @@ const sk: PartialLocaleType = {
Title: "Veľkosť písma", Title: "Veľkosť písma",
SubTitle: "Nastaviť veľkosť písma obsahu chatu", SubTitle: "Nastaviť veľkosť písma obsahu chatu",
}, },
FontFamily: {
Title: "Chatové Písmo",
SubTitle:
"Písmo obsahu chatu, ponechajte prázdne pre použitie globálneho predvoleného písma",
Placeholder: "Názov Písma",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "Vložiť systémové výzvy", Title: "Vložiť systémové výzvy",
SubTitle: "Vložiť globálnu systémovú výzvu pre každú požiadavku", SubTitle: "Vložiť globálnu systémovú výzvu pre každú požiadavku",

View File

@ -71,6 +71,12 @@ const tr: PartialLocaleType = {
Title: "Yazı Boyutu", Title: "Yazı Boyutu",
SubTitle: "Sohbet içeriğinin yazı boyutunu ayarlayın", SubTitle: "Sohbet içeriğinin yazı boyutunu ayarlayın",
}, },
FontFamily: {
Title: "Sohbet Yazı Tipi",
SubTitle:
"Sohbet içeriğinin yazı tipi, boş bırakıldığında küresel varsayılan yazı tipi uygulanır",
Placeholder: "Yazı Tipi Adı",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "Sistem İpucu Ekleyin", Title: "Sistem İpucu Ekleyin",
SubTitle: SubTitle:

View File

@ -153,6 +153,11 @@ const tw = {
Title: "字型大小", Title: "字型大小",
SubTitle: "聊天內容的字型大小", SubTitle: "聊天內容的字型大小",
}, },
FontFamily: {
Title: "聊天字體",
SubTitle: "聊天內容的字體,若置空則應用全局默認字體",
Placeholder: "字體名稱",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "匯入系統提示", Title: "匯入系統提示",
SubTitle: "強制在每個請求的訊息列表開頭新增一個模擬 ChatGPT 的系統提示", SubTitle: "強制在每個請求的訊息列表開頭新增一個模擬 ChatGPT 的系統提示",

View File

@ -71,6 +71,12 @@ const vi: PartialLocaleType = {
Title: "Font chữ", Title: "Font chữ",
SubTitle: "Thay đổi font chữ của nội dung trò chuyện", SubTitle: "Thay đổi font chữ của nội dung trò chuyện",
}, },
FontFamily: {
Title: "Phông Chữ Trò Chuyện",
SubTitle:
"Phông chữ của nội dung trò chuyện, để trống để áp dụng phông chữ mặc định toàn cầu",
Placeholder: "Tên Phông Chữ",
},
InjectSystemPrompts: { InjectSystemPrompts: {
Title: "Tiêm Prompt Hệ thống", Title: "Tiêm Prompt Hệ thống",
SubTitle: SubTitle:

View File

@ -33,6 +33,7 @@ export const DEFAULT_CONFIG = {
submitKey: SubmitKey.Enter, submitKey: SubmitKey.Enter,
avatar: "1f603", avatar: "1f603",
fontSize: 14, fontSize: 14,
fontFamily: "",
theme: Theme.Auto as Theme, theme: Theme.Auto as Theme,
tightBorder: !!config?.isApp, tightBorder: !!config?.isApp,
sendPreviewBubble: true, sendPreviewBubble: true,

View File

@ -194,6 +194,7 @@ export function autoGrowTextArea(dom: HTMLTextAreaElement) {
measureDom.style.width = width + "px"; measureDom.style.width = width + "px";
measureDom.innerText = dom.value !== "" ? dom.value : "1"; measureDom.innerText = dom.value !== "" ? dom.value : "1";
measureDom.style.fontSize = dom.style.fontSize; measureDom.style.fontSize = dom.style.fontSize;
measureDom.style.fontFamily = dom.style.fontFamily;
const endWithEmptyLine = dom.value.endsWith("\n"); const endWithEmptyLine = dom.value.endsWith("\n");
const height = parseFloat(window.getComputedStyle(measureDom).height); const height = parseFloat(window.getComputedStyle(measureDom).height);
const singleLineHeight = parseFloat( const singleLineHeight = parseFloat(