diff --git a/apps/readest-app/public/locales/de/translation.json b/apps/readest-app/public/locales/de/translation.json index 48018527..7f4e91b9 100644 --- a/apps/readest-app/public/locales/de/translation.json +++ b/apps/readest-app/public/locales/de/translation.json @@ -2,6 +2,7 @@ "About Readest": "Über Readest", "Add your notes here...": "Fügen Sie hier Ihre Notizen hinzu...", "Animation": "Animation", + "Apply": "Anwenden", "Are you sure to delete the selected books?": "Möchten Sie die ausgewählten Bücher wirklich löschen?", "Auto Mode": "Automatischer Modus", "Behavior": "Verhalten", diff --git a/apps/readest-app/public/locales/es/translation.json b/apps/readest-app/public/locales/es/translation.json index 7f36ead2..f1c4fa5f 100644 --- a/apps/readest-app/public/locales/es/translation.json +++ b/apps/readest-app/public/locales/es/translation.json @@ -2,6 +2,7 @@ "About Readest": "Acerca de Readest", "Add your notes here...": "Añade tus notas aquí...", "Animation": "Animación", + "Apply": "Aplicar", "Are you sure to delete the selected books?": "¿Estás seguro de eliminar los libros seleccionados?", "Auto Mode": "Modo automático", "Behavior": "Comportamiento", diff --git a/apps/readest-app/public/locales/fr/translation.json b/apps/readest-app/public/locales/fr/translation.json index 7b85980e..96115e6e 100644 --- a/apps/readest-app/public/locales/fr/translation.json +++ b/apps/readest-app/public/locales/fr/translation.json @@ -2,6 +2,7 @@ "About Readest": "À propos de Readest", "Add your notes here...": "Ajoutez vos notes ici...", "Animation": "Animation", + "Apply": "Appliquer", "Are you sure to delete the selected books?": "Êtes-vous sûr de vouloir supprimer les livres sélectionnés ?", "Auto Mode": "Mode automatique", "Behavior": "Comportement", diff --git a/apps/readest-app/public/locales/id/translation.json b/apps/readest-app/public/locales/id/translation.json index 261b516f..89a09055 100644 --- a/apps/readest-app/public/locales/id/translation.json +++ b/apps/readest-app/public/locales/id/translation.json @@ -2,6 +2,7 @@ "About Readest": "Tentang Readest", "Add your notes here...": "Tambahkan catatan Anda di sini...", "Animation": "Animasi", + "Apply": "Terapkan", "Are you sure to delete the selected books?": "Apakah Anda yakin ingin menghapus buku yang dipilih?", "Auto Mode": "Mode Otomatis", "Behavior": "Perilaku", diff --git a/apps/readest-app/public/locales/it/translation.json b/apps/readest-app/public/locales/it/translation.json index 2467827d..2aed8deb 100644 --- a/apps/readest-app/public/locales/it/translation.json +++ b/apps/readest-app/public/locales/it/translation.json @@ -2,6 +2,7 @@ "About Readest": "Informazioni su Readest", "Add your notes here...": "Aggiungi qui le tue note...", "Animation": "Animazione", + "Apply": "Applica", "Are you sure to delete the selected books?": "Sei sicuro di voler eliminare i libri selezionati?", "Auto Mode": "Modalità automatica", "Behavior": "Comportamento", diff --git a/apps/readest-app/public/locales/ja/translation.json b/apps/readest-app/public/locales/ja/translation.json index e3fbe988..de999291 100644 --- a/apps/readest-app/public/locales/ja/translation.json +++ b/apps/readest-app/public/locales/ja/translation.json @@ -2,6 +2,7 @@ "About Readest": "Readestについて", "Add your notes here...": "ここにメモを追加...", "Animation": "アニメーション", + "Apply": "適用", "Are you sure to delete the selected books?": "選択した書籍を削除してもよろしいですか?", "Auto Mode": "自動モード", "Behavior": "動作", diff --git a/apps/readest-app/public/locales/ko/translation.json b/apps/readest-app/public/locales/ko/translation.json index e0a5c456..b9286729 100644 --- a/apps/readest-app/public/locales/ko/translation.json +++ b/apps/readest-app/public/locales/ko/translation.json @@ -2,6 +2,7 @@ "About Readest": "Readest 정보", "Add your notes here...": "여기에 메모를 추가하세요...", "Animation": "애니메이션", + "Apply": "적용", "Are you sure to delete the selected books?": "선택한 책을 삭제하시겠습니까?", "Auto Mode": "자동 모드", "Behavior": "동작", diff --git a/apps/readest-app/public/locales/pt/translation.json b/apps/readest-app/public/locales/pt/translation.json index e2efbebe..937fff28 100644 --- a/apps/readest-app/public/locales/pt/translation.json +++ b/apps/readest-app/public/locales/pt/translation.json @@ -2,6 +2,7 @@ "About Readest": "Sobre o Readest", "Add your notes here...": "Adicione suas notas aqui...", "Animation": "Animação", + "Apply": "Aplicar", "Are you sure to delete the selected books?": "Tem certeza de que deseja excluir os livros selecionados?", "Auto Mode": "Modo Automático", "Behavior": "Comportamento", diff --git a/apps/readest-app/public/locales/ru/translation.json b/apps/readest-app/public/locales/ru/translation.json index f9a784f1..0e32a3d0 100644 --- a/apps/readest-app/public/locales/ru/translation.json +++ b/apps/readest-app/public/locales/ru/translation.json @@ -2,6 +2,7 @@ "About Readest": "О Readest", "Add your notes here...": "Добавьте свои заметки здесь...", "Animation": "Анимация", + "Apply": "Применить", "Are you sure to delete the selected books?": "Вы уверены, что хотите удалить выбранные книги?", "Auto Mode": "Автоматический режим", "Behavior": "Поведение", diff --git a/apps/readest-app/public/locales/tr/translation.json b/apps/readest-app/public/locales/tr/translation.json index 571d0afc..36dd4886 100644 --- a/apps/readest-app/public/locales/tr/translation.json +++ b/apps/readest-app/public/locales/tr/translation.json @@ -2,6 +2,7 @@ "About Readest": "Readest Hakkında", "Add your notes here...": "Notlarınızı buraya ekleyin...", "Animation": "Animasyon", + "Apply": "Uygula", "Are you sure to delete the selected books?": "Seçili kitapları silmek istediğinizden emin misiniz?", "Auto Mode": "Otomatik Mod", "Behavior": "Davranış", diff --git a/apps/readest-app/public/locales/vi/translation.json b/apps/readest-app/public/locales/vi/translation.json index e002c3c0..fb2930c2 100644 --- a/apps/readest-app/public/locales/vi/translation.json +++ b/apps/readest-app/public/locales/vi/translation.json @@ -2,6 +2,7 @@ "About Readest": "Về Readest", "Add your notes here...": "Thêm ghi chú của bạn vào đây...", "Animation": "Hiệu ứng động", + "Apply": "Áp dụng", "Are you sure to delete the selected books?": "Bạn có chắc chắn muốn xóa các sách đã chọn?", "Auto Mode": "Chế độ tự động", "Behavior": "Hành vi", diff --git a/apps/readest-app/public/locales/zh-CN/translation.json b/apps/readest-app/public/locales/zh-CN/translation.json index 9e00524c..954b6f3a 100644 --- a/apps/readest-app/public/locales/zh-CN/translation.json +++ b/apps/readest-app/public/locales/zh-CN/translation.json @@ -2,6 +2,7 @@ "About Readest": "关于 Readest", "Add your notes here...": "在这里添加您的笔记...", "Animation": "动画", + "Apply": "应用", "Are you sure to delete the selected books?": "您确定要删除所选书籍吗?", "Auto Mode": "自动主题", "Behavior": "行为", diff --git a/apps/readest-app/public/locales/zh-TW/translation.json b/apps/readest-app/public/locales/zh-TW/translation.json index 0f45c41d..552160aa 100644 --- a/apps/readest-app/public/locales/zh-TW/translation.json +++ b/apps/readest-app/public/locales/zh-TW/translation.json @@ -2,6 +2,7 @@ "About Readest": "關於 Readest", "Add your notes here...": "在這裡添加您的筆記...", "Animation": "動畫", + "Apply": "應用", "Are you sure to delete the selected books?": "您確定要刪除所選書籍嗎?", "Auto Mode": "自動主題", "Behavior": "行為", diff --git a/apps/readest-app/src/app/reader/components/settings/MiscPanel.tsx b/apps/readest-app/src/app/reader/components/settings/MiscPanel.tsx index 6fbdf553..56490fe0 100644 --- a/apps/readest-app/src/app/reader/components/settings/MiscPanel.tsx +++ b/apps/readest-app/src/app/reader/components/settings/MiscPanel.tsx @@ -1,13 +1,12 @@ +import clsx from 'clsx'; import React, { useEffect, useState } from 'react'; import { useReaderStore } from '@/store/readerStore'; import { useSettingsStore } from '@/store/settingsStore'; import { useTranslation } from '@/hooks/useTranslation'; -import cssbeautify from 'cssbeautify'; import { getStyles } from '@/utils/style'; import { useTheme } from '@/hooks/useTheme'; - -const cssRegex = - /((?:\s*)([\w#.@*,:\-.:>+~$$$$\"=(),*\s]+)\s*{(?:[\s]*)((?:[^\}]+[:][^\}]+;?)*)*\s*}(?:\s*))/gim; +import cssbeautify from 'cssbeautify'; +import cssValidate from '@/utils/css'; const MiscPanel: React.FC<{ bookKey: string }> = ({ bookKey }) => { const _ = useTranslation(); @@ -18,44 +17,48 @@ const MiscPanel: React.FC<{ bookKey: string }> = ({ bookKey }) => { const [animated, setAnimated] = useState(viewSettings.animated!); const [isDisableClick, setIsDisableClick] = useState(viewSettings.disableClick!); - const [userStylesheet, setUserStylesheet] = useState(viewSettings.userStylesheet!); + const [draftStylesheet, setDraftStylesheet] = useState(viewSettings.userStylesheet!); const [error, setError] = useState(null); - let cssInput = userStylesheet; - - const validateCSS = (css: string) => { - return cssRegex.test(css); - }; - const handleUserStylesheetChange = (e: React.ChangeEvent) => { - cssInput = e.target.value; + const cssInput = e.target.value; + setDraftStylesheet(cssInput); try { - const formattedCSS = cssbeautify(cssInput, { - indent: ' ', - openbrace: 'end-of-line', - autosemicolon: true, - }); - setUserStylesheet(formattedCSS); - - if (cssInput && !validateCSS(cssInput)) { - throw new Error('Invalid CSS'); + const { isValid, error } = cssValidate(cssInput); + if (cssInput && !isValid) { + throw new Error(error || 'Invalid CSS'); } setError(null); - - viewSettings.userStylesheet = formattedCSS; - setViewSettings(bookKey, viewSettings); - if (isFontLayoutSettingsGlobal) { - settings.globalViewSettings.userStylesheet = formattedCSS; - setSettings(settings); + } catch (err: unknown) { + if (err instanceof Error) { + setError(err.message); + } else { + setError('Invalid CSS: Please check your input.'); } - getView(bookKey)?.renderer.setStyles?.(getStyles(viewSettings, themeCode)); - } catch (err) { - setError('Invalid CSS: Please check your input.'); console.log('CSS Error:', err); } }; + const applyStyles = () => { + const formattedCSS = cssbeautify(draftStylesheet, { + indent: ' ', + openbrace: 'end-of-line', + autosemicolon: true, + }); + + setDraftStylesheet(formattedCSS); + viewSettings.userStylesheet = formattedCSS; + setViewSettings(bookKey, viewSettings); + + if (isFontLayoutSettingsGlobal) { + settings.globalViewSettings.userStylesheet = formattedCSS; + setSettings(settings); + } + + getView(bookKey)?.renderer.setStyles?.(getStyles(viewSettings, themeCode)); + }; + const handleInput = (e: React.FormEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); @@ -125,21 +128,31 @@ const MiscPanel: React.FC<{ bookKey: string }> = ({ bookKey }) => {

{_('Custom CSS')}

-
-
-