react-native-readium 3.0.2 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/android/src/main/java/com/reactnativereadium/ReadiumView.kt +10 -7
- package/android/src/main/java/com/reactnativereadium/ReadiumViewManager.kt +7 -6
- package/android/src/main/java/com/reactnativereadium/reader/EpubReaderFragment.kt +25 -47
- package/android/src/main/java/com/reactnativereadium/reader/ReaderService.kt +2 -15
- package/android/src/main/java/com/reactnativereadium/utils/FragmentFactory.kt +1 -1
- package/ios/App/AppModule.swift +1 -1
- package/ios/Common/EPUBPreferences.swift +8 -0
- package/ios/Reader/Common/ReaderViewController.swift +8 -14
- package/ios/Reader/EPUB/AssociatedColors.swift +7 -7
- package/ios/Reader/EPUB/EPUBModule.swift +6 -7
- package/ios/Reader/EPUB/EPUBViewController.swift +8 -10
- package/ios/Reader/ReaderFormatModule.swift +3 -4
- package/ios/Reader/ReaderModule.swift +3 -7
- package/ios/Reader/ReaderService.swift +4 -19
- package/ios/ReadiumView.swift +31 -33
- package/ios/ReadiumViewManager.m +1 -1
- package/lib/src/components/ReadiumView.d.ts +4 -2
- package/lib/src/components/ReadiumView.js +4 -4
- package/lib/src/components/ReadiumView.web.d.ts +5 -1
- package/lib/src/components/ReadiumView.web.js +2 -2
- package/lib/src/interfaces/BaseReadiumViewProps.d.ts +1 -2
- package/lib/src/interfaces/Preferences.d.ts +27 -0
- package/lib/src/interfaces/Preferences.js +1 -0
- package/lib/src/interfaces/index.d.ts +1 -1
- package/lib/src/interfaces/index.js +1 -1
- package/lib/src/utils/RANGES.js +1 -1
- package/lib/web/hooks/useSettingsObserver.d.ts +2 -2
- package/lib/web/hooks/useSettingsObserver.js +39 -5
- package/package.json +1 -1
- package/react-native-readium.podspec +2 -0
- package/src/components/ReadiumView.tsx +16 -7
- package/src/components/ReadiumView.web.tsx +7 -3
- package/src/interfaces/BaseReadiumViewProps.ts +1 -3
- package/src/interfaces/Preferences.ts +35 -0
- package/src/interfaces/index.ts +1 -1
- package/src/utils/RANGES.ts +1 -1
- package/web/hooks/useSettingsObserver.ts +52 -7
- package/android/src/main/java/com/reactnativereadium/epub/UserSettings.kt +0 -246
- package/lib/src/interfaces/Settings.d.ts +0 -40
- package/lib/src/interfaces/Settings.js +0 -61
- package/src/interfaces/Settings.ts +0 -75
package/ios/ReadiumView.swift
CHANGED
|
@@ -28,9 +28,9 @@ class ReadiumView : UIView, Loggable {
|
|
|
28
28
|
self.updateLocation()
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
@objc var
|
|
31
|
+
@objc var preferences: NSString? = nil {
|
|
32
32
|
didSet {
|
|
33
|
-
self.
|
|
33
|
+
self.updatePreferences(preferences)
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
@objc var onLocationChange: RCTDirectEventBlock?
|
|
@@ -77,40 +77,29 @@ class ReadiumView : UIView, Loggable {
|
|
|
77
77
|
)
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
func
|
|
80
|
+
func updatePreferences(_ preferences: NSString?) {
|
|
81
81
|
|
|
82
82
|
if (readerViewController == nil) {
|
|
83
83
|
// defer setting update as view isn't initialized yet
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
for property in userProperties.properties {
|
|
91
|
-
let value = settings?[property.reference]
|
|
92
|
-
|
|
93
|
-
if (value == nil) {
|
|
94
|
-
continue
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if let e = property as? Enumerable {
|
|
98
|
-
e.index = value as! Int
|
|
99
|
-
|
|
100
|
-
// synchronize background color
|
|
101
|
-
if property.reference == ReadiumCSSReference.appearance.rawValue {
|
|
102
|
-
if let vc = readerViewController as? EPUBViewController {
|
|
103
|
-
vc.setUIColor(for: property)
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
} else if let i = property as? Incrementable {
|
|
107
|
-
i.value = value as! Float
|
|
108
|
-
} else if let s = property as? Switchable {
|
|
109
|
-
s.on = value as! Bool
|
|
110
|
-
}
|
|
111
|
-
}
|
|
87
|
+
guard let navigator = readerViewController!.navigator as? EPUBNavigatorViewController else {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
112
90
|
|
|
113
|
-
|
|
91
|
+
guard let preferencesJson = preferences as? String else {
|
|
92
|
+
print("TODO: handle error. Bad string conversion for preferences")
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
do {
|
|
97
|
+
let preferences = try JSONDecoder().decode(EPUBPreferences.self, from: Data(preferencesJson.utf8))
|
|
98
|
+
navigator.submitPreferences(preferences)
|
|
99
|
+
} catch {
|
|
100
|
+
print(error)
|
|
101
|
+
print("TODO: handle error. Skipping preferences due to thrown exception")
|
|
102
|
+
return;
|
|
114
103
|
}
|
|
115
104
|
}
|
|
116
105
|
|
|
@@ -139,12 +128,21 @@ class ReadiumView : UIView, Loggable {
|
|
|
139
128
|
|
|
140
129
|
readerViewController = vc
|
|
141
130
|
|
|
142
|
-
// if the controller was just instantiated then apply any existing
|
|
143
|
-
if (
|
|
144
|
-
self.
|
|
131
|
+
// if the controller was just instantiated then apply any existing preferences
|
|
132
|
+
if (preferences != nil) {
|
|
133
|
+
self.updatePreferences(preferences)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
guard
|
|
137
|
+
readerViewController != nil,
|
|
138
|
+
superview?.frame != nil,
|
|
139
|
+
self.viewController != nil,
|
|
140
|
+
self.readerViewController != nil
|
|
141
|
+
else {
|
|
142
|
+
return
|
|
145
143
|
}
|
|
146
144
|
|
|
147
|
-
readerViewController!.view.frame =
|
|
145
|
+
readerViewController!.view.frame = superview!.frame
|
|
148
146
|
self.viewController!.addChild(readerViewController!)
|
|
149
147
|
let rootView = self.readerViewController!.view!
|
|
150
148
|
self.addSubview(rootView)
|
package/ios/ReadiumViewManager.m
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
RCT_EXPORT_VIEW_PROPERTY(file, NSDictionary *)
|
|
6
6
|
RCT_EXPORT_VIEW_PROPERTY(location, NSDictionary *)
|
|
7
|
-
RCT_EXPORT_VIEW_PROPERTY(
|
|
7
|
+
RCT_EXPORT_VIEW_PROPERTY(preferences, NSString *)
|
|
8
8
|
RCT_EXPORT_VIEW_PROPERTY(onLocationChange, RCTDirectEventBlock)
|
|
9
9
|
RCT_EXPORT_VIEW_PROPERTY(onTableOfContents, RCTDirectEventBlock)
|
|
10
10
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { BaseReadiumViewProps } from '../interfaces';
|
|
3
|
-
export type ReadiumProps = BaseReadiumViewProps
|
|
2
|
+
import type { BaseReadiumViewProps, Preferences } from '../interfaces';
|
|
3
|
+
export type ReadiumProps = Omit<BaseReadiumViewProps, 'preferences'> & {
|
|
4
|
+
preferences: Preferences;
|
|
5
|
+
};
|
|
4
6
|
export declare const ReadiumView: React.FC<ReadiumProps>;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import React, { useCallback, useState, useEffect, forwardRef, useRef, } from 'react';
|
|
1
|
+
import React, { useCallback, useState, useEffect, forwardRef, useRef, useMemo, } from 'react';
|
|
2
2
|
import { View, Platform, findNodeHandle, StyleSheet } from 'react-native';
|
|
3
|
-
import { Settings } from '../interfaces';
|
|
4
3
|
import { createFragment, getWidthOrHeightValue as dimension } from '../utils';
|
|
5
4
|
import { BaseReadiumView } from './BaseReadiumView';
|
|
6
|
-
export const ReadiumView = forwardRef(({ onLocationChange: wrappedOnLocationChange, onTableOfContents: wrappedOnTableOfContents,
|
|
5
|
+
export const ReadiumView = forwardRef(({ onLocationChange: wrappedOnLocationChange, onTableOfContents: wrappedOnTableOfContents, preferences, ...props }, forwardedRef) => {
|
|
7
6
|
const defaultRef = useRef(null);
|
|
8
7
|
const [{ height, width }, setDimensions] = useState({
|
|
9
8
|
width: 0,
|
|
@@ -44,8 +43,9 @@ export const ReadiumView = forwardRef(({ onLocationChange: wrappedOnLocationChan
|
|
|
44
43
|
forwardedRef(defaultRef);
|
|
45
44
|
}
|
|
46
45
|
}, [defaultRef.current !== null]);
|
|
46
|
+
const stringifiedPreferences = useMemo(() => JSON.stringify(preferences), [preferences]);
|
|
47
47
|
return (<View style={styles.container} onLayout={onLayout}>
|
|
48
|
-
<BaseReadiumView height={height} width={width} {...props} onLocationChange={onLocationChange} onTableOfContents={onTableOfContents}
|
|
48
|
+
<BaseReadiumView height={height} width={width} {...props} preferences={stringifiedPreferences} onLocationChange={onLocationChange} onTableOfContents={onTableOfContents} ref={defaultRef}/>
|
|
49
49
|
</View>);
|
|
50
50
|
});
|
|
51
51
|
const styles = StyleSheet.create({
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
2
|
+
import type { BaseReadiumViewProps, Preferences } from '../interfaces';
|
|
3
|
+
export type ReadiumProps = Omit<BaseReadiumViewProps, 'preferences'> & {
|
|
4
|
+
preferences: Preferences;
|
|
5
|
+
};
|
|
6
|
+
export declare const ReadiumView: React.ForwardRefExoticComponent<Omit<ReadiumProps, "ref"> & React.RefAttributes<{
|
|
3
7
|
nextPage: () => void;
|
|
4
8
|
prevPage: () => void;
|
|
5
9
|
}>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useImperativeHandle } from 'react';
|
|
2
2
|
import { View, StyleSheet } from 'react-native';
|
|
3
3
|
import { useReaderRef, useSettingsObserver, useLocationObserver, } from '../../web/hooks';
|
|
4
|
-
export const ReadiumView = React.forwardRef(({ file,
|
|
4
|
+
export const ReadiumView = React.forwardRef(({ file, preferences, location, onLocationChange, onTableOfContents, style = {}, height, width, }, ref) => {
|
|
5
5
|
const readerRef = useReaderRef({
|
|
6
6
|
file,
|
|
7
7
|
onLocationChange,
|
|
@@ -16,7 +16,7 @@ export const ReadiumView = React.forwardRef(({ file, settings, location, onLocat
|
|
|
16
16
|
readerRef.current?.previousPage();
|
|
17
17
|
},
|
|
18
18
|
}));
|
|
19
|
-
useSettingsObserver(reader,
|
|
19
|
+
useSettingsObserver(reader, preferences);
|
|
20
20
|
useLocationObserver(reader, location);
|
|
21
21
|
const mainStyle = {
|
|
22
22
|
...styles.maximize,
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { ViewStyle } from 'react-native';
|
|
2
|
-
import type { Settings } from './Settings';
|
|
3
2
|
import type { Link } from './Link';
|
|
4
3
|
import type { Locator } from './Locator';
|
|
5
4
|
import type { File } from './File';
|
|
6
5
|
export type BaseReadiumViewProps = {
|
|
7
6
|
file: File;
|
|
8
7
|
location?: Locator | Link;
|
|
9
|
-
|
|
8
|
+
preferences?: string;
|
|
10
9
|
style?: ViewStyle;
|
|
11
10
|
onLocationChange?: (locator: Locator) => void;
|
|
12
11
|
onTableOfContents?: (toc: Link[] | null) => void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface Preferences {
|
|
2
|
+
backgroundColor?: number;
|
|
3
|
+
columnCount?: 'auto' | '1' | '2';
|
|
4
|
+
fontFamily?: 'serif' | 'sans-serif' | 'cursive' | 'fantasy' | 'monospace' | 'AccessibleDfA' | 'IA Writer Duospace' | 'OpenDyslexic';
|
|
5
|
+
fontSize?: number;
|
|
6
|
+
fontWeight?: number;
|
|
7
|
+
hyphens?: boolean;
|
|
8
|
+
imageFilter?: 'darken' | 'invert';
|
|
9
|
+
language?: string;
|
|
10
|
+
letterSpacing?: number;
|
|
11
|
+
ligatures?: boolean;
|
|
12
|
+
lineHeight?: number;
|
|
13
|
+
pageMargins?: number;
|
|
14
|
+
paragraphIndent?: number;
|
|
15
|
+
paragraphSpacing?: number;
|
|
16
|
+
publisherStyles?: boolean;
|
|
17
|
+
readingProgression?: 'ltr' | 'rtl';
|
|
18
|
+
scroll?: boolean;
|
|
19
|
+
spread?: 'auto' | 'never' | 'always';
|
|
20
|
+
textAlign?: 'center' | 'justify' | 'start' | 'end' | 'left' | 'right';
|
|
21
|
+
textColor?: number;
|
|
22
|
+
textNormalization?: boolean;
|
|
23
|
+
theme?: 'light' | 'dark' | 'sepia';
|
|
24
|
+
typeScale?: number;
|
|
25
|
+
verticalText?: boolean;
|
|
26
|
+
wordSpacing?: number;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/src/utils/RANGES.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const useSettingsObserver: (reader?: D2Reader | null,
|
|
1
|
+
import type { Preferences } from '../../src/interfaces';
|
|
2
|
+
export declare const useSettingsObserver: (reader?: D2Reader | null, preferences?: Partial<Preferences> | null) => void;
|
|
@@ -1,10 +1,44 @@
|
|
|
1
1
|
import { useDeepCompareEffect } from 'use-deep-compare';
|
|
2
|
-
export const useSettingsObserver = (reader,
|
|
2
|
+
export const useSettingsObserver = (reader, preferences) => {
|
|
3
3
|
useDeepCompareEffect(() => {
|
|
4
|
-
if (reader &&
|
|
5
|
-
|
|
6
|
-
// are equivalent or not
|
|
4
|
+
if (reader && preferences) {
|
|
5
|
+
const settings = preferencesToUserSettings(preferences);
|
|
7
6
|
reader?.applyUserSettings(settings);
|
|
8
7
|
}
|
|
9
|
-
}, [
|
|
8
|
+
}, [preferences, !!reader]);
|
|
9
|
+
};
|
|
10
|
+
const preferencesToUserSettings = (preferences) => ({
|
|
11
|
+
appearance: preferences.theme
|
|
12
|
+
? themeToUserSettingsAppearance(preferences.theme)
|
|
13
|
+
: undefined,
|
|
14
|
+
fontSize: preferences.fontSize ? preferences.fontSize * 100 : undefined,
|
|
15
|
+
// fontOverride: boolean;
|
|
16
|
+
// fontFamily: number;
|
|
17
|
+
verticalScroll: preferences.scroll,
|
|
18
|
+
columnCount: columnCountToUserSettingsColumnCount(preferences.columnCount),
|
|
19
|
+
// direction: number;
|
|
20
|
+
wordSpacing: preferences.wordSpacing,
|
|
21
|
+
letterSpacing: preferences.letterSpacing,
|
|
22
|
+
pageMargins: preferences.pageMargins,
|
|
23
|
+
lineHeight: preferences.lineHeight,
|
|
24
|
+
// userProperties?: UserProperties;
|
|
25
|
+
// view: BookView;
|
|
26
|
+
});
|
|
27
|
+
const themeToUserSettingsAppearance = (theme) => {
|
|
28
|
+
if (theme === 'dark') {
|
|
29
|
+
return 'night';
|
|
30
|
+
}
|
|
31
|
+
if (theme === 'sepia') {
|
|
32
|
+
return 'sepia';
|
|
33
|
+
}
|
|
34
|
+
return 'day';
|
|
35
|
+
};
|
|
36
|
+
const columnCountToUserSettingsColumnCount = (columnCount) => {
|
|
37
|
+
if (columnCount === '1') {
|
|
38
|
+
return 1;
|
|
39
|
+
}
|
|
40
|
+
if (columnCount === '2') {
|
|
41
|
+
return 2;
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
10
44
|
};
|
package/package.json
CHANGED
|
@@ -4,22 +4,28 @@ import React, {
|
|
|
4
4
|
useEffect,
|
|
5
5
|
forwardRef,
|
|
6
6
|
useRef,
|
|
7
|
+
useMemo,
|
|
7
8
|
} from 'react';
|
|
8
9
|
import { View, Platform, findNodeHandle, StyleSheet } from 'react-native';
|
|
9
10
|
|
|
10
|
-
import type {
|
|
11
|
-
|
|
11
|
+
import type {
|
|
12
|
+
BaseReadiumViewProps,
|
|
13
|
+
Dimensions,
|
|
14
|
+
Preferences,
|
|
15
|
+
} from '../interfaces';
|
|
12
16
|
import { createFragment, getWidthOrHeightValue as dimension } from '../utils';
|
|
13
17
|
import { BaseReadiumView } from './BaseReadiumView';
|
|
14
18
|
|
|
15
|
-
export type ReadiumProps = BaseReadiumViewProps
|
|
19
|
+
export type ReadiumProps = Omit<BaseReadiumViewProps, 'preferences'> & {
|
|
20
|
+
preferences: Preferences;
|
|
21
|
+
};
|
|
16
22
|
|
|
17
23
|
export const ReadiumView: React.FC<ReadiumProps> = forwardRef(
|
|
18
24
|
(
|
|
19
25
|
{
|
|
20
26
|
onLocationChange: wrappedOnLocationChange,
|
|
21
27
|
onTableOfContents: wrappedOnTableOfContents,
|
|
22
|
-
|
|
28
|
+
preferences,
|
|
23
29
|
...props
|
|
24
30
|
},
|
|
25
31
|
forwardedRef
|
|
@@ -82,17 +88,20 @@ export const ReadiumView: React.FC<ReadiumProps> = forwardRef(
|
|
|
82
88
|
}
|
|
83
89
|
}, [defaultRef.current !== null]);
|
|
84
90
|
|
|
91
|
+
const stringifiedPreferences = useMemo(
|
|
92
|
+
() => JSON.stringify(preferences),
|
|
93
|
+
[preferences]
|
|
94
|
+
);
|
|
95
|
+
|
|
85
96
|
return (
|
|
86
97
|
<View style={styles.container} onLayout={onLayout}>
|
|
87
98
|
<BaseReadiumView
|
|
88
99
|
height={height}
|
|
89
100
|
width={width}
|
|
90
101
|
{...props}
|
|
102
|
+
preferences={stringifiedPreferences}
|
|
91
103
|
onLocationChange={onLocationChange}
|
|
92
104
|
onTableOfContents={onTableOfContents}
|
|
93
|
-
settings={
|
|
94
|
-
unmappedSettings ? Settings.map(unmappedSettings) : undefined
|
|
95
|
-
}
|
|
96
105
|
ref={defaultRef}
|
|
97
106
|
/>
|
|
98
107
|
</View>
|
|
@@ -2,13 +2,17 @@ import React, { useImperativeHandle } from 'react';
|
|
|
2
2
|
import type { CSSProperties } from 'react';
|
|
3
3
|
import { View, StyleSheet } from 'react-native';
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type { BaseReadiumViewProps, Preferences } from '../interfaces';
|
|
6
6
|
import {
|
|
7
7
|
useReaderRef,
|
|
8
8
|
useSettingsObserver,
|
|
9
9
|
useLocationObserver,
|
|
10
10
|
} from '../../web/hooks';
|
|
11
11
|
|
|
12
|
+
export type ReadiumProps = Omit<BaseReadiumViewProps, 'preferences'> & {
|
|
13
|
+
preferences: Preferences;
|
|
14
|
+
};
|
|
15
|
+
|
|
12
16
|
export const ReadiumView = React.forwardRef<
|
|
13
17
|
{
|
|
14
18
|
nextPage: () => void;
|
|
@@ -19,7 +23,7 @@ export const ReadiumView = React.forwardRef<
|
|
|
19
23
|
(
|
|
20
24
|
{
|
|
21
25
|
file,
|
|
22
|
-
|
|
26
|
+
preferences,
|
|
23
27
|
location,
|
|
24
28
|
onLocationChange,
|
|
25
29
|
onTableOfContents,
|
|
@@ -45,7 +49,7 @@ export const ReadiumView = React.forwardRef<
|
|
|
45
49
|
},
|
|
46
50
|
}));
|
|
47
51
|
|
|
48
|
-
useSettingsObserver(reader,
|
|
52
|
+
useSettingsObserver(reader, preferences);
|
|
49
53
|
useLocationObserver(reader, location);
|
|
50
54
|
|
|
51
55
|
const mainStyle = {
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { ViewStyle } from 'react-native';
|
|
2
|
-
|
|
3
|
-
import type { Settings } from './Settings';
|
|
4
2
|
import type { Link } from './Link';
|
|
5
3
|
import type { Locator } from './Locator';
|
|
6
4
|
import type { File } from './File';
|
|
@@ -8,7 +6,7 @@ import type { File } from './File';
|
|
|
8
6
|
export type BaseReadiumViewProps = {
|
|
9
7
|
file: File;
|
|
10
8
|
location?: Locator | Link;
|
|
11
|
-
|
|
9
|
+
preferences?: string; // JSON between native and JS, which we deserialise later
|
|
12
10
|
style?: ViewStyle;
|
|
13
11
|
onLocationChange?: (locator: Locator) => void;
|
|
14
12
|
onTableOfContents?: (toc: Link[] | null) => void;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface Preferences {
|
|
2
|
+
backgroundColor?: number;
|
|
3
|
+
columnCount?: 'auto' | '1' | '2';
|
|
4
|
+
fontFamily?:
|
|
5
|
+
| 'serif'
|
|
6
|
+
| 'sans-serif'
|
|
7
|
+
| 'cursive'
|
|
8
|
+
| 'fantasy'
|
|
9
|
+
| 'monospace'
|
|
10
|
+
| 'AccessibleDfA'
|
|
11
|
+
| 'IA Writer Duospace'
|
|
12
|
+
| 'OpenDyslexic';
|
|
13
|
+
fontSize?: number;
|
|
14
|
+
fontWeight?: number;
|
|
15
|
+
hyphens?: boolean;
|
|
16
|
+
imageFilter?: 'darken' | 'invert';
|
|
17
|
+
language?: string;
|
|
18
|
+
letterSpacing?: number;
|
|
19
|
+
ligatures?: boolean;
|
|
20
|
+
lineHeight?: number;
|
|
21
|
+
pageMargins?: number;
|
|
22
|
+
paragraphIndent?: number;
|
|
23
|
+
paragraphSpacing?: number;
|
|
24
|
+
publisherStyles?: boolean;
|
|
25
|
+
readingProgression?: 'ltr' | 'rtl';
|
|
26
|
+
scroll?: boolean;
|
|
27
|
+
spread?: 'auto' | 'never' | 'always';
|
|
28
|
+
textAlign?: 'center' | 'justify' | 'start' | 'end' | 'left' | 'right';
|
|
29
|
+
textColor?: number;
|
|
30
|
+
textNormalization?: boolean;
|
|
31
|
+
theme?: 'light' | 'dark' | 'sepia';
|
|
32
|
+
typeScale?: number;
|
|
33
|
+
verticalText?: boolean;
|
|
34
|
+
wordSpacing?: number;
|
|
35
|
+
}
|
package/src/interfaces/index.ts
CHANGED
package/src/utils/RANGES.ts
CHANGED
|
@@ -1,16 +1,61 @@
|
|
|
1
1
|
import { useDeepCompareEffect } from 'use-deep-compare';
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { Preferences } from '../../src/interfaces';
|
|
4
4
|
|
|
5
5
|
export const useSettingsObserver = (
|
|
6
6
|
reader?: D2Reader | null,
|
|
7
|
-
|
|
7
|
+
preferences?: Partial<Preferences> | null
|
|
8
8
|
) => {
|
|
9
9
|
useDeepCompareEffect(() => {
|
|
10
|
-
if (reader &&
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
reader?.applyUserSettings(settings as Partial<D2UserSettings>);
|
|
10
|
+
if (reader && preferences) {
|
|
11
|
+
const settings = preferencesToUserSettings(preferences);
|
|
12
|
+
reader?.applyUserSettings(settings);
|
|
14
13
|
}
|
|
15
|
-
}, [
|
|
14
|
+
}, [preferences, !!reader]);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const preferencesToUserSettings = (
|
|
18
|
+
preferences: Preferences
|
|
19
|
+
): Partial<D2UserSettings> => ({
|
|
20
|
+
appearance: preferences.theme
|
|
21
|
+
? themeToUserSettingsAppearance(preferences.theme)
|
|
22
|
+
: undefined,
|
|
23
|
+
fontSize: preferences.fontSize ? preferences.fontSize * 100 : undefined,
|
|
24
|
+
// fontOverride: boolean;
|
|
25
|
+
// fontFamily: number;
|
|
26
|
+
verticalScroll: preferences.scroll,
|
|
27
|
+
columnCount: columnCountToUserSettingsColumnCount(preferences.columnCount),
|
|
28
|
+
// direction: number;
|
|
29
|
+
wordSpacing: preferences.wordSpacing,
|
|
30
|
+
letterSpacing: preferences.letterSpacing,
|
|
31
|
+
pageMargins: preferences.pageMargins,
|
|
32
|
+
lineHeight: preferences.lineHeight,
|
|
33
|
+
// userProperties?: UserProperties;
|
|
34
|
+
// view: BookView;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const themeToUserSettingsAppearance = (theme: Preferences['theme']) => {
|
|
38
|
+
if (theme === 'dark') {
|
|
39
|
+
return 'night';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (theme === 'sepia') {
|
|
43
|
+
return 'sepia';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return 'day';
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const columnCountToUserSettingsColumnCount = (
|
|
50
|
+
columnCount: Preferences['columnCount']
|
|
51
|
+
) => {
|
|
52
|
+
if (columnCount === '1') {
|
|
53
|
+
return 1;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (columnCount === '2') {
|
|
57
|
+
return 2;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return undefined;
|
|
16
61
|
};
|