Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
"increment": "node scripts/increment.mjs"
},
"peerDependencies": {
"@readium/css": "^2.0.2",
"@readium/navigator": "^2.5.1",
"@readium/navigator-html-injectables": "^2.4.1",
"@readium/css": "^2.0.4",
"@readium/navigator": "^2.5.2",
"@readium/navigator-html-injectables": "^2.4.2",
"@readium/shared": "^2.2.0",
"@reduxjs/toolkit": "^2.11.2",
"i18next": "^25.8.13",
Expand All @@ -85,9 +85,9 @@
},
"dependencies": {
"@edrlab/thorium-locales": "github:edrlab/thorium-locales",
"@readium/css": "^2.0.2",
"@readium/navigator": "^2.5.1",
"@readium/navigator-html-injectables": "^2.4.1",
"@readium/css": "^2.0.4",
"@readium/navigator": "^2.5.2",
"@readium/navigator-html-injectables": "^2.4.2",
"@readium/shared": "^2.2.0",
"@reduxjs/toolkit": "^2.11.2",
"classnames": "^2.5.1",
Expand Down
30 changes: 15 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/components/Epub/Hooks/usePreferencesConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { FontMetadata } from "@/preferences/services/fonts";
import { ThColorScheme } from "@/core/Hooks/useColorScheme";
import { ReadiumCSSSettings } from "@/core/Hooks/Epub/useEpubSettingsCache";
import { useSettingsComponentStatus } from "@/components/Settings/hooks/useSettingsComponentStatus";
import { useLineHeight } from "@/components/Settings/Spacing/hooks/useLineHeight";

import { useAppSelector } from "@/lib/hooks";

Expand All @@ -23,7 +24,6 @@ interface UseEpubPreferencesConfigProps {
arrowsWidth: React.RefObject<number>;
preferences: ThPreferences;
getFontMetadata: (fontFamily: string) => FontMetadata;
lineHeightOptions: Record<ThLineHeightOptions, number | null>;
fxlThemeKeys: string[];
reflowThemeKeys: string[];
}
Expand All @@ -37,10 +37,10 @@ export const useEpubPreferencesConfig = ({
arrowsWidth,
preferences,
getFontMetadata,
lineHeightOptions,
fxlThemeKeys,
reflowThemeKeys,
}: UseEpubPreferencesConfigProps) => {
const { processedValues: lineHeightOptions } = useLineHeight();
const scriptMode = useAppSelector(state => state.publication.scriptMode);
const isVerticalScript = scriptMode === "cjk-vertical" || scriptMode === "mongolian-vertical";

Expand Down Expand Up @@ -145,7 +145,7 @@ export const useEpubPreferencesConfig = ({
? undefined
: settings.lineHeight === null
? null
: lineHeightOptions[settings.lineHeight],
: lineHeightOptions[settings.lineHeight as ThLineHeightOptions.small | ThLineHeightOptions.medium | ThLineHeightOptions.large],
optimalLineLength: settings.lineLength?.optimal != null
? settings.lineLength.optimal
: undefined,
Expand Down Expand Up @@ -178,7 +178,6 @@ export const useEpubPreferencesConfig = ({
preferences.theming.themes.keys,
preferences.theming.themes.systemThemes,
getFontMetadata,
lineHeightOptions,
fxlThemeKeys,
reflowThemeKeys,
isVerticalScript,
Expand All @@ -197,6 +196,7 @@ export const useEpubPreferencesConfig = ({
isTextAlignUsed,
isTextNormalizeUsed,
isWordSpacingUsed,
lineHeightOptions
]);

const epubDefaults = useMemo(() => {
Expand Down
4 changes: 0 additions & 4 deletions src/components/Epub/Hooks/useReaderInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { useCallback, useEffect, useState, useRef } from "react";

import { Locator, Publication } from "@readium/shared";
import { ThLineHeightOptions } from "@/preferences/models";
import { EpubNavigatorListeners, IContentProtectionConfig, ILinkInjectable, IBlobInjectable } from "@readium/navigator";
import { ThPreferences } from "@/preferences";
import { FontMetadata, InjectableFontResources } from "@/preferences/services/fonts";
Expand All @@ -30,7 +29,6 @@ interface UseEpubReaderInitProps {
getFontInjectables: (options?: { language?: string } | { key?: string }, optimize?: boolean) => InjectableFontResources | null;
fxlThemeKeys: string[];
reflowThemeKeys: string[];
lineHeightOptions: Record<ThLineHeightOptions, number | null>;
arrowsOccupySpace: boolean;
arrowsWidth: React.RefObject<number>;
colorScheme: any;
Expand Down Expand Up @@ -59,7 +57,6 @@ export const useEpubReaderInit = ({
getFontInjectables,
fxlThemeKeys,
reflowThemeKeys,
lineHeightOptions,
arrowsOccupySpace,
arrowsWidth,
colorScheme,
Expand All @@ -81,7 +78,6 @@ export const useEpubReaderInit = ({
arrowsWidth,
preferences,
getFontMetadata,
lineHeightOptions,
fxlThemeKeys,
reflowThemeKeys,
});
Expand Down
4 changes: 0 additions & 4 deletions src/components/Epub/StatefulReader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ import { useTimeline } from "@/core/Hooks/useTimeline";
import { useIsScroll, usePositionStorage } from "@/hooks";
import { useDocumentTitle } from "@/core/Hooks/useDocumentTitle";
import { useSpacingPresets } from "../Settings/Spacing/hooks/useSpacingPresets";
import { useLineHeight } from "../Settings/Spacing/hooks/useLineHeight";
import { usePaginatedArrows } from "@/hooks/usePaginatedArrows";
import { useFonts } from "@/core/Hooks/fonts/useFonts";

Expand Down Expand Up @@ -265,8 +264,6 @@ const StatefulReaderInner = ({ publication, localDataKey, positionStorage, conta
}
});

const lineHeightOptions = useLineHeight();

const documentTitleFormat = preferences.metadata?.documentTitle?.format;

let documentTitle: string | undefined;
Expand Down Expand Up @@ -550,7 +547,6 @@ const StatefulReaderInner = ({ publication, localDataKey, positionStorage, conta
getFontInjectables,
fxlThemeKeys,
reflowThemeKeys,
lineHeightOptions,
arrowsOccupySpace,
arrowsWidth,
colorScheme,
Expand Down
46 changes: 19 additions & 27 deletions src/components/Settings/Spacing/StatefulLineHeight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ import LargeIcon from "./assets/icons/density_large.svg";
import { StatefulRadioGroup } from "../StatefulRadioGroup";

import { useNavigator } from "@/core/Navigator";
import { EpubPreferencesEditor } from "@readium/navigator";
import { useI18n } from "@/i18n/useI18n";
import { usePreferences } from "@/preferences/hooks/usePreferences";
import { useEffectiveRange } from "../hooks/useEffectiveRange";

import { useAppSelector } from "@/lib/hooks";
import { useLineHeight } from "./hooks/useLineHeight";
import { useSpacingPresets } from "./hooks/useSpacingPresets";
import { useReaderSetting } from "../hooks/useReaderSetting";


export const StatefulLineHeight = ({ standalone = true }: StatefulSettingsItemProps) => {
const { t } = useI18n();
const { preferences } = usePreferences();
Expand All @@ -34,28 +33,25 @@ export const StatefulLineHeight = ({ standalone = true }: StatefulSettingsItemPr

const publisherStyles = useReaderSetting("publisherStyles");

const { getSetting, submitPreferences, preferencesEditor } = useNavigator().visual;
const { getSetting, submitPreferences } = useNavigator().visual;

const prefKey = SETTINGS_KEY_TO_PREFERENCE[ThSettingsKeys.lineHeight];

const { getEffectiveSpacingValue, setLineHeight } = useSpacingPresets();

const lineHeight = getEffectiveSpacingValue(ThSpacingSettingsKeys.lineHeight);

const lineHeightOptions = useLineHeight();
const { processedValues } = useLineHeight();

const lineHeightNumericValues = useMemo(
() => Object.values(lineHeightOptions).filter((v): v is number => v !== null),
[lineHeightOptions]
);
// Build map from processed values for settings UI
const processedPresets = useMemo(() => {
const result = new Map<ThLineHeightOptions, number>();
result.set(ThLineHeightOptions.small, processedValues[ThLineHeightOptions.small]);
result.set(ThLineHeightOptions.medium, processedValues[ThLineHeightOptions.medium]);
result.set(ThLineHeightOptions.large, processedValues[ThLineHeightOptions.large]);
return result;
}, [processedValues]);

const { presets: effectivePresets } = useEffectiveRange(
[Math.min(...lineHeightNumericValues), Math.max(...lineHeightNumericValues)],
(preferencesEditor as EpubPreferencesEditor | undefined)?.lineHeight?.supportedRange,
lineHeightNumericValues
);

// Dynamically build items array based on allowUnset preference and navigator supported range
const items = useMemo(() => {
const baseItems = [
{
Expand All @@ -76,12 +72,8 @@ export const StatefulLineHeight = ({ standalone = true }: StatefulSettingsItemPr
label: t("reader.preferences.lineHeight.large"),
value: ThLineHeightOptions.large
},
].filter(item => {
const v = lineHeightOptions[item.id];
return effectivePresets === undefined || effectivePresets.includes(v);
});
].filter(item => processedPresets.has(item.id));

// Only add publisher option if allowUnset is true
if (preferences.settings.keys[ThSettingsKeys.lineHeight].allowUnset !== false) {
baseItems.unshift({
id: ThLineHeightOptions.publisher,
Expand All @@ -92,21 +84,21 @@ export const StatefulLineHeight = ({ standalone = true }: StatefulSettingsItemPr
}

return baseItems;
}, [preferences.settings.keys, lineHeightOptions, effectivePresets, t]);
}, [preferences.settings.keys, processedPresets, t]);

const updatePreference = useCallback(async (value: string) => {
const computedValue = value === ThLineHeightOptions.publisher
const submitValue = value === ThLineHeightOptions.publisher
? null
: lineHeightOptions[value as keyof typeof ThLineHeightOptions];
: processedPresets.get(value as ThLineHeightOptions) ?? null;
await submitPreferences({
[prefKey]: computedValue
[prefKey]: submitValue
});

const currentLineHeight = getSetting(prefKey);
const currentDisplayLineHeightOption = Object.entries(lineHeightOptions).find(([_key, value]) => value === currentLineHeight)?.[0] as ThLineHeightOptions;
const storedLineHeight = getSetting(prefKey) as number | null;
const currentDisplayLineHeightOption = [...processedPresets.entries()].find(([, v]) => v === storedLineHeight)?.[0] as ThLineHeightOptions;

setLineHeight(currentDisplayLineHeightOption);
}, [prefKey, submitPreferences, getSetting, setLineHeight, lineHeightOptions]);
}, [prefKey, submitPreferences, getSetting, setLineHeight, processedPresets]);

return (
<>
Expand Down
8 changes: 4 additions & 4 deletions src/components/Settings/Spacing/StatefulSpacingPresets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const StatefulSpacingPresets = ({ standalone }: StatefulSettingsItemProps
const paragraphSpacingPrefKey = SETTINGS_KEY_TO_PREFERENCE[ThSettingsKeys.paragraphSpacing];
const wordSpacingPrefKey = SETTINGS_KEY_TO_PREFERENCE[ThSettingsKeys.wordSpacing];

const lineHeightOptions = useLineHeight();
const { values: lineHeightOptions, compensate: compensateLineHeight } = useLineHeight();

const { getPresetValues } = useSpacingPresets();

Expand Down Expand Up @@ -104,10 +104,10 @@ export const StatefulSpacingPresets = ({ standalone }: StatefulSettingsItemProps
[ThSpacingSettingsKeys.wordSpacing]: presetValues?.[ThSpacingSettingsKeys.wordSpacing] ?? null,
};

// Convert lineHeight for preferences API (enum to number)
// Convert lineHeight for preferences API (enum to compensated number)
const lineHeightValue = reduxValues[ThSpacingSettingsKeys.lineHeight];
const lineHeightValueNumber = lineHeightValue && lineHeightValue !== ThLineHeightOptions.publisher
? lineHeightOptions[lineHeightValue as ThLineHeightOptions]
? compensateLineHeight(lineHeightOptions[lineHeightValue as ThLineHeightOptions])
: null;

// Only include spacing settings if their plugins are being used
Expand Down Expand Up @@ -141,7 +141,7 @@ export const StatefulSpacingPresets = ({ standalone }: StatefulSettingsItemProps
values: reduxValues,
}));
}
}, [isWebPub, dispatch, submitPreferences, getPresetValues, lineHeightOptions, letterSpacingPrefKey, lineHeightPrefKey, paragraphIndentPrefKey, paragraphSpacingPrefKey, wordSpacingPrefKey, isLetterSpacingUsed, isLineHeightUsed, isParagraphIndentUsed, isParagraphSpacingUsed, isWordSpacingUsed]);
}, [isWebPub, dispatch, submitPreferences, getPresetValues, lineHeightOptions, compensateLineHeight, letterSpacingPrefKey, lineHeightPrefKey, paragraphIndentPrefKey, paragraphSpacingPrefKey, wordSpacingPrefKey, isLetterSpacingUsed, isLineHeightUsed, isParagraphIndentUsed, isParagraphSpacingUsed, isWordSpacingUsed]);

// Use appropriate spacing keys based on layout
const spacingKeys = useMemo(() => {
Expand Down
Loading