diff --git a/apps/readest-app/src/__tests__/utils/replacement.test.ts b/apps/readest-app/src/__tests__/utils/replacement.test.ts index 0cdc3519..ca7129f0 100644 --- a/apps/readest-app/src/__tests__/utils/replacement.test.ts +++ b/apps/readest-app/src/__tests__/utils/replacement.test.ts @@ -99,6 +99,7 @@ describe('proofreadTransformer', () => { viewSettings, userLocale: 'en', content, + isFixedLayout: false, sectionHref, transformers: ['proofread'], }; diff --git a/apps/readest-app/src/app/reader/components/FoliateViewer.tsx b/apps/readest-app/src/app/reader/components/FoliateViewer.tsx index 385559fe..27e8beca 100644 --- a/apps/readest-app/src/app/reader/components/FoliateViewer.tsx +++ b/apps/readest-app/src/app/reader/components/FoliateViewer.tsx @@ -159,6 +159,7 @@ const FoliateViewer: React.FC<{ viewSettings, width, height, + isFixedLayout: bookData.isFixedLayout, primaryLanguage: bookData.book?.primaryLanguage, userLocale: getLocale(), content: data, diff --git a/apps/readest-app/src/app/reader/components/annotator/Annotator.tsx b/apps/readest-app/src/app/reader/components/annotator/Annotator.tsx index b16e516c..c031b474 100644 --- a/apps/readest-app/src/app/reader/components/annotator/Annotator.tsx +++ b/apps/readest-app/src/app/reader/components/annotator/Annotator.tsx @@ -175,6 +175,7 @@ const Annotator: React.FC<{ bookKey: string }> = ({ bookKey }) => { viewSettings: getViewSettings(bookKey)!, userLocale: getLocale(), content: '', + isFixedLayout: bookData.isFixedLayout, transformers: ['punctuation'], reversePunctuationTransform: true, }), diff --git a/apps/readest-app/src/app/reader/hooks/useTTSControl.ts b/apps/readest-app/src/app/reader/hooks/useTTSControl.ts index e845e64b..7c54dd27 100644 --- a/apps/readest-app/src/app/reader/hooks/useTTSControl.ts +++ b/apps/readest-app/src/app/reader/hooks/useTTSControl.ts @@ -225,6 +225,7 @@ export const useTTSControl = ({ bookKey, onRequestHidePanel }: UseTTSControlProp }; const viewSettings = getViewSettings(bookKey); + const bookData = getBookData(bookKey); const ttsTime = useMemo(() => { const rate = viewSettings?.ttsRate ?? 1; return estimateTTSTime(progress, rate); @@ -236,7 +237,6 @@ export const useTTSControl = ({ bookKey, onRequestHidePanel }: UseTTSControlProp if (vs?.translationEnabled && ttsReadAloudText === 'translated') { return vs?.translateTargetLang || getLocale(); } else if (vs?.translationEnabled && ttsReadAloudText === 'source') { - const bookData = getBookData(bookKey); return bookData?.book?.primaryLanguage || ''; } return null; @@ -260,6 +260,7 @@ export const useTTSControl = ({ bookKey, onRequestHidePanel }: UseTTSControlProp bookKey, viewSettings: getViewSettings(bookKey)!, userLocale: getLocale(), + isFixedLayout: bookData?.isFixedLayout || false, content: '', transformers: [], reversePunctuationTransform: true, diff --git a/apps/readest-app/src/services/transformers/style.ts b/apps/readest-app/src/services/transformers/style.ts index fb036221..6b29457c 100644 --- a/apps/readest-app/src/services/transformers/style.ts +++ b/apps/readest-app/src/services/transformers/style.ts @@ -6,6 +6,8 @@ export const styleTransformer: Transformer = { transform: async (ctx) => { let result = ctx.content; + if (ctx.isFixedLayout) return result; + const styleMatches = [...result.matchAll(/]*>([\s\S]*?)<\/style>/gi)]; for (const match of styleMatches) { diff --git a/apps/readest-app/src/services/transformers/types.ts b/apps/readest-app/src/services/transformers/types.ts index b914b490..a2317eca 100644 --- a/apps/readest-app/src/services/transformers/types.ts +++ b/apps/readest-app/src/services/transformers/types.ts @@ -4,6 +4,7 @@ export type TransformContext = { bookKey: string; viewSettings: ViewSettings; userLocale: string; + isFixedLayout: boolean; primaryLanguage?: string; width?: number; height?: number; diff --git a/apps/readest-app/src/store/bookDataStore.ts b/apps/readest-app/src/store/bookDataStore.ts index 85a93e02..dc3ed781 100644 --- a/apps/readest-app/src/store/bookDataStore.ts +++ b/apps/readest-app/src/store/bookDataStore.ts @@ -5,7 +5,7 @@ import { EnvConfigType } from '@/services/environment'; import { BookDoc } from '@/libs/document'; import { useLibraryStore } from './libraryStore'; -interface BookData { +export interface BookData { /* Persistent data shared with different views of the same book */ id: string; book: Book | null; diff --git a/apps/readest-app/src/store/readerStore.ts b/apps/readest-app/src/store/readerStore.ts index d6249002..e1a1ee2a 100644 --- a/apps/readest-app/src/store/readerStore.ts +++ b/apps/readest-app/src/store/readerStore.ts @@ -18,7 +18,7 @@ import { formatTitle, getMetadataHash, getPrimaryLanguage } from '@/utils/book'; import { getBaseFilename } from '@/utils/path'; import { SUPPORTED_LANGNAMES } from '@/services/constants'; import { useSettingsStore } from './settingsStore'; -import { useBookDataStore } from './bookDataStore'; +import { BookData, useBookDataStore } from './bookDataStore'; import { useLibraryStore } from './libraryStore'; import { uniqueId } from '@/utils/misc'; @@ -196,11 +196,13 @@ export const useReaderStore = create((set, get) => ({ // book.metaHash = book.metaHash ?? getMetadataHash(bookDoc.metadata); book.metaHash = getMetadataHash(bookDoc.metadata); - const isFixedLayout = FIXED_LAYOUT_FORMATS.has(book.format); + const isFixedLayout = + bookDoc.rendition?.layout === 'pre-paginated' || FIXED_LAYOUT_FORMATS.has(book.format); + const newBookData: BookData = { id, book, file, config, bookDoc, isFixedLayout }; useBookDataStore.setState((state) => ({ booksData: { ...state.booksData, - [id]: { id, book, file, config, bookDoc, isFixedLayout }, + [id]: newBookData, }, })); const configViewSettings = config.viewSettings!;