react-native-readium 1.1.0 → 1.2.1
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 +23 -2
- package/lib/src/components/BaseReadiumView.d.ts +2 -0
- package/lib/src/components/BaseReadiumView.js +7 -0
- package/lib/src/components/BaseReadiumView.web.d.ts +1 -0
- package/lib/src/components/BaseReadiumView.web.js +1 -0
- package/lib/{typescript → src}/components/ReadiumView.d.ts +1 -1
- package/lib/src/components/ReadiumView.js +43 -0
- package/lib/src/components/ReadiumView.web.d.ts +5 -0
- package/lib/src/components/ReadiumView.web.js +67 -0
- package/lib/src/enums/Appearance.js +13 -0
- package/lib/src/enums/ColumnCount.js +7 -0
- package/lib/src/enums/FontFamily.js +12 -0
- package/lib/src/enums/TextAlignment.js +6 -0
- package/lib/{module → src}/enums/index.js +0 -1
- package/lib/{module → src}/index.js +0 -1
- package/lib/{typescript/components/BaseReadiumView.d.ts → src/interfaces/BaseReadiumViewProps.d.ts} +5 -3
- package/lib/src/interfaces/BaseReadiumViewProps.js +1 -0
- package/lib/src/interfaces/Dimensions.js +1 -0
- package/lib/src/interfaces/File.js +1 -0
- package/lib/src/interfaces/Link.js +1 -0
- package/lib/src/interfaces/Locator.js +1 -0
- package/lib/src/interfaces/Settings.js +61 -0
- package/lib/{typescript → src}/interfaces/index.d.ts +1 -0
- package/lib/{module → src}/interfaces/index.js +1 -1
- package/lib/{module → src}/utils/COMPONENT_NAME.js +0 -1
- package/lib/src/utils/LINKING_ERROR.js +5 -0
- package/lib/src/utils/RANGES.js +8 -0
- package/lib/src/utils/clamp.js +7 -0
- package/lib/src/utils/createFragment.js +10 -0
- package/lib/src/utils/getWidthOrHeightValue.js +4 -0
- package/lib/{module → src}/utils/index.js +0 -1
- package/lib/src/utils/indexOfObjectValue.js +3 -0
- package/lib/web/hooks/useLocationObserver.d.ts +2 -0
- package/lib/web/hooks/useLocationObserver.js +13 -0
- package/lib/web/hooks/useReaderRef.d.ts +3 -0
- package/lib/web/hooks/useReaderRef.js +48 -0
- package/lib/web/hooks/useSettingsObserver.d.ts +2 -0
- package/lib/web/hooks/useSettingsObserver.js +13 -0
- package/package.json +8 -23
- package/src/components/BaseReadiumView.tsx +1 -14
- package/src/components/BaseReadiumView.web.tsx +1 -0
- package/src/components/ReadiumView.tsx +1 -2
- package/src/{web/ReadiumView.tsx → components/ReadiumView.web.tsx} +31 -9
- package/src/interfaces/BaseReadiumViewProps.ts +18 -0
- package/src/interfaces/index.ts +1 -0
- package/{lib/module/web/hooks/index.js → web/hooks/index.ts} +0 -1
- package/{src/web → web}/hooks/useLocationObserver.ts +1 -3
- package/{src/web → web}/hooks/useReaderRef.ts +20 -16
- package/{src/web → web}/hooks/useSettingsObserver.ts +2 -4
- package/lib/commonjs/components/BaseReadiumView.js +0 -16
- package/lib/commonjs/components/BaseReadiumView.js.map +0 -1
- package/lib/commonjs/components/ReadiumView.js +0 -94
- package/lib/commonjs/components/ReadiumView.js.map +0 -1
- package/lib/commonjs/enums/Appearance.js +0 -16
- package/lib/commonjs/enums/Appearance.js.map +0 -1
- package/lib/commonjs/enums/ColumnCount.js +0 -16
- package/lib/commonjs/enums/ColumnCount.js.map +0 -1
- package/lib/commonjs/enums/FontFamily.js +0 -21
- package/lib/commonjs/enums/FontFamily.js.map +0 -1
- package/lib/commonjs/enums/TextAlignment.js +0 -15
- package/lib/commonjs/enums/TextAlignment.js.map +0 -1
- package/lib/commonjs/enums/index.js +0 -58
- package/lib/commonjs/enums/index.js.map +0 -1
- package/lib/commonjs/index.js +0 -59
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/index.web.js +0 -54
- package/lib/commonjs/index.web.js.map +0 -1
- package/lib/commonjs/interfaces/Dimensions.js +0 -2
- package/lib/commonjs/interfaces/Dimensions.js.map +0 -1
- package/lib/commonjs/interfaces/File.js +0 -6
- package/lib/commonjs/interfaces/File.js.map +0 -1
- package/lib/commonjs/interfaces/Link.js +0 -2
- package/lib/commonjs/interfaces/Link.js.map +0 -1
- package/lib/commonjs/interfaces/Locator.js +0 -2
- package/lib/commonjs/interfaces/Locator.js.map +0 -1
- package/lib/commonjs/interfaces/Settings.js +0 -71
- package/lib/commonjs/interfaces/Settings.js.map +0 -1
- package/lib/commonjs/interfaces/index.js +0 -71
- package/lib/commonjs/interfaces/index.js.map +0 -1
- package/lib/commonjs/utils/COMPONENT_NAME.js +0 -9
- package/lib/commonjs/utils/COMPONENT_NAME.js.map +0 -1
- package/lib/commonjs/utils/LINKING_ERROR.js +0 -15
- package/lib/commonjs/utils/LINKING_ERROR.js.map +0 -1
- package/lib/commonjs/utils/RANGES.js +0 -16
- package/lib/commonjs/utils/RANGES.js.map +0 -1
- package/lib/commonjs/utils/clamp.js +0 -15
- package/lib/commonjs/utils/clamp.js.map +0 -1
- package/lib/commonjs/utils/createFragment.js +0 -21
- package/lib/commonjs/utils/createFragment.js.map +0 -1
- package/lib/commonjs/utils/getWidthOrHeightValue.js +0 -15
- package/lib/commonjs/utils/getWidthOrHeightValue.js.map +0 -1
- package/lib/commonjs/utils/index.js +0 -97
- package/lib/commonjs/utils/index.js.map +0 -1
- package/lib/commonjs/utils/indexOfObjectValue.js +0 -13
- package/lib/commonjs/utils/indexOfObjectValue.js.map +0 -1
- package/lib/commonjs/web/ReadiumView.js +0 -90
- package/lib/commonjs/web/ReadiumView.js.map +0 -1
- package/lib/commonjs/web/hooks/index.js +0 -45
- package/lib/commonjs/web/hooks/index.js.map +0 -1
- package/lib/commonjs/web/hooks/useLocationObserver.js +0 -21
- package/lib/commonjs/web/hooks/useLocationObserver.js.map +0 -1
- package/lib/commonjs/web/hooks/useReaderRef.js +0 -60
- package/lib/commonjs/web/hooks/useReaderRef.js.map +0 -1
- package/lib/commonjs/web/hooks/useSettingsObserver.js +0 -21
- package/lib/commonjs/web/hooks/useSettingsObserver.js.map +0 -1
- package/lib/module/components/BaseReadiumView.js +0 -6
- package/lib/module/components/BaseReadiumView.js.map +0 -1
- package/lib/module/components/ReadiumView.js +0 -75
- package/lib/module/components/ReadiumView.js.map +0 -1
- package/lib/module/enums/Appearance.js +0 -9
- package/lib/module/enums/Appearance.js.map +0 -1
- package/lib/module/enums/ColumnCount.js +0 -9
- package/lib/module/enums/ColumnCount.js.map +0 -1
- package/lib/module/enums/FontFamily.js +0 -14
- package/lib/module/enums/FontFamily.js.map +0 -1
- package/lib/module/enums/TextAlignment.js +0 -8
- package/lib/module/enums/TextAlignment.js.map +0 -1
- package/lib/module/enums/index.js.map +0 -1
- package/lib/module/index.js.map +0 -1
- package/lib/module/index.web.js +0 -5
- package/lib/module/index.web.js.map +0 -1
- package/lib/module/interfaces/Dimensions.js +0 -2
- package/lib/module/interfaces/Dimensions.js.map +0 -1
- package/lib/module/interfaces/File.js +0 -2
- package/lib/module/interfaces/File.js.map +0 -1
- package/lib/module/interfaces/Link.js +0 -2
- package/lib/module/interfaces/Link.js.map +0 -1
- package/lib/module/interfaces/Locator.js +0 -2
- package/lib/module/interfaces/Locator.js.map +0 -1
- package/lib/module/interfaces/Settings.js +0 -61
- package/lib/module/interfaces/Settings.js.map +0 -1
- package/lib/module/interfaces/index.js.map +0 -1
- package/lib/module/utils/COMPONENT_NAME.js.map +0 -1
- package/lib/module/utils/LINKING_ERROR.js +0 -6
- package/lib/module/utils/LINKING_ERROR.js.map +0 -1
- package/lib/module/utils/RANGES.js +0 -9
- package/lib/module/utils/RANGES.js.map +0 -1
- package/lib/module/utils/clamp.js +0 -6
- package/lib/module/utils/clamp.js.map +0 -1
- package/lib/module/utils/createFragment.js +0 -10
- package/lib/module/utils/createFragment.js.map +0 -1
- package/lib/module/utils/getWidthOrHeightValue.js +0 -5
- package/lib/module/utils/getWidthOrHeightValue.js.map +0 -1
- package/lib/module/utils/index.js.map +0 -1
- package/lib/module/utils/indexOfObjectValue.js +0 -4
- package/lib/module/utils/indexOfObjectValue.js.map +0 -1
- package/lib/module/web/ReadiumView.js +0 -75
- package/lib/module/web/ReadiumView.js.map +0 -1
- package/lib/module/web/hooks/index.js.map +0 -1
- package/lib/module/web/hooks/useLocationObserver.js +0 -11
- package/lib/module/web/hooks/useLocationObserver.js.map +0 -1
- package/lib/module/web/hooks/useReaderRef.js +0 -47
- package/lib/module/web/hooks/useReaderRef.js.map +0 -1
- package/lib/module/web/hooks/useSettingsObserver.js +0 -11
- package/lib/module/web/hooks/useSettingsObserver.js.map +0 -1
- package/lib/typescript/index.web.d.ts +0 -4
- package/lib/typescript/web/ReadiumView.d.ts +0 -3
- package/lib/typescript/web/hooks/useLocationObserver.d.ts +0 -3
- package/lib/typescript/web/hooks/useReaderRef.d.ts +0 -4
- package/lib/typescript/web/hooks/useSettingsObserver.d.ts +0 -3
- package/src/index.web.tsx +0 -5
- /package/lib/{typescript → src}/enums/Appearance.d.ts +0 -0
- /package/lib/{typescript → src}/enums/ColumnCount.d.ts +0 -0
- /package/lib/{typescript → src}/enums/FontFamily.d.ts +0 -0
- /package/lib/{typescript → src}/enums/TextAlignment.d.ts +0 -0
- /package/lib/{typescript → src}/enums/index.d.ts +0 -0
- /package/lib/{typescript → src}/index.d.ts +0 -0
- /package/lib/{typescript → src}/interfaces/Dimensions.d.ts +0 -0
- /package/lib/{typescript → src}/interfaces/File.d.ts +0 -0
- /package/lib/{typescript → src}/interfaces/Link.d.ts +0 -0
- /package/lib/{typescript → src}/interfaces/Locator.d.ts +0 -0
- /package/lib/{typescript → src}/interfaces/Settings.d.ts +0 -0
- /package/lib/{typescript → src}/utils/COMPONENT_NAME.d.ts +0 -0
- /package/lib/{typescript → src}/utils/LINKING_ERROR.d.ts +0 -0
- /package/lib/{typescript → src}/utils/RANGES.d.ts +0 -0
- /package/lib/{typescript → src}/utils/clamp.d.ts +0 -0
- /package/lib/{typescript → src}/utils/createFragment.d.ts +0 -0
- /package/lib/{typescript → src}/utils/getWidthOrHeightValue.d.ts +0 -0
- /package/lib/{typescript → src}/utils/index.d.ts +0 -0
- /package/lib/{typescript → src}/utils/indexOfObjectValue.d.ts +0 -0
- /package/lib/{typescript/web → web}/hooks/index.d.ts +0 -0
- /package/{src/web/hooks/index.ts → lib/web/hooks/index.js} +0 -0
package/README.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# react-native-readium
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/react-native-readium)
|
|
4
|
+
[](http://commitizen.github.io/cz-cli/)
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
----
|
|
9
|
+
|
|
10
|
+
## Have A Bug/Feature You Care About?
|
|
11
|
+
|
|
12
|
+
We :heart: open source. We work on the things that are important to us when
|
|
13
|
+
we're able to work on them. Have an issue you care about?
|
|
14
|
+
|
|
15
|
+
- [Dive Into The Code!](CONTRIBUTING.md)
|
|
16
|
+
- [Sponsor Your Issue](https://issuehunt.io/r/5-stones/react-native-readium).
|
|
17
|
+
|
|
18
|
+
[](https://issuehunt.io/r/5-stones/react-native-readium)
|
|
19
|
+
|
|
20
|
+
----
|
|
21
|
+
|
|
22
|
+
## Overview
|
|
23
|
+
|
|
3
24
|
A react-native wrapper for https://readium.org/. At a high level this package
|
|
4
25
|
allows you to do things like:
|
|
5
26
|
|
|
@@ -13,7 +34,7 @@ allows you to do things like:
|
|
|
13
34
|
- More (see the `Settings` documentation in the [API section](#api))
|
|
14
35
|
- Etc. (read on for more details. :book:)
|
|
15
36
|
|
|
16
|
-
##
|
|
37
|
+
## Table of Contents
|
|
17
38
|
|
|
18
39
|
- [Installation](#installation)
|
|
19
40
|
- [Usage](#usage)
|
|
@@ -24,7 +45,7 @@ allows you to do things like:
|
|
|
24
45
|
- [License](#license)
|
|
25
46
|
|
|
26
47
|
| Dark Mode| Light Mode |
|
|
27
|
-
|
|
48
|
+
|----------|------------|
|
|
28
49
|
|  |  |
|
|
29
50
|
|
|
30
51
|
## Installation
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { requireNativeComponent, UIManager, } from 'react-native';
|
|
2
|
+
import { COMPONENT_NAME, LINKING_ERROR } from '../utils';
|
|
3
|
+
export const BaseReadiumView = UIManager.getViewManagerConfig(COMPONENT_NAME) != null
|
|
4
|
+
? requireNativeComponent(COMPONENT_NAME)
|
|
5
|
+
: () => {
|
|
6
|
+
throw new Error(LINKING_ERROR);
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const BaseReadiumView: () => null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const BaseReadiumView = () => null;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React, { useCallback, useState, useRef, useEffect } from 'react';
|
|
2
|
+
import { View, Platform, findNodeHandle, StyleSheet } from 'react-native';
|
|
3
|
+
import { Settings } from '../interfaces';
|
|
4
|
+
import { createFragment, getWidthOrHeightValue as dimension } from '../utils';
|
|
5
|
+
import { BaseReadiumView } from './BaseReadiumView';
|
|
6
|
+
export const ReadiumView = ({ onLocationChange: wrappedOnLocationChange, onTableOfContents: wrappedOnTableOfContents, settings: unmappedSettings, ...props }) => {
|
|
7
|
+
const ref = useRef(null);
|
|
8
|
+
const [{ height, width }, setDimensions] = useState({
|
|
9
|
+
width: 0,
|
|
10
|
+
height: 0,
|
|
11
|
+
});
|
|
12
|
+
// set the view dimensions on layout
|
|
13
|
+
const onLayout = useCallback(({ nativeEvent: { layout: { width, height } } }) => {
|
|
14
|
+
setDimensions({
|
|
15
|
+
width: dimension(width),
|
|
16
|
+
height: dimension(height),
|
|
17
|
+
});
|
|
18
|
+
}, []);
|
|
19
|
+
// wrap the native onLocationChange and extract the raw event value
|
|
20
|
+
const onLocationChange = useCallback((event) => {
|
|
21
|
+
if (wrappedOnLocationChange) {
|
|
22
|
+
wrappedOnLocationChange(event.nativeEvent);
|
|
23
|
+
}
|
|
24
|
+
}, [wrappedOnLocationChange]);
|
|
25
|
+
const onTableOfContents = useCallback((event) => {
|
|
26
|
+
if (wrappedOnTableOfContents) {
|
|
27
|
+
const toc = event.nativeEvent.toc || null;
|
|
28
|
+
wrappedOnTableOfContents(toc);
|
|
29
|
+
}
|
|
30
|
+
}, [wrappedOnTableOfContents]);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (Platform.OS === 'android') {
|
|
33
|
+
const viewId = findNodeHandle(ref.current);
|
|
34
|
+
createFragment(viewId);
|
|
35
|
+
}
|
|
36
|
+
}, []);
|
|
37
|
+
return (<View style={styles.container} onLayout={onLayout}>
|
|
38
|
+
<BaseReadiumView height={height} width={width} {...props} onLocationChange={onLocationChange} onTableOfContents={onTableOfContents} settings={unmappedSettings ? Settings.map(unmappedSettings) : undefined} ref={ref}/>
|
|
39
|
+
</View>);
|
|
40
|
+
};
|
|
41
|
+
const styles = StyleSheet.create({
|
|
42
|
+
container: { width: '100%', height: '100%' },
|
|
43
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare const ReadiumView: React.ForwardRefExoticComponent<Pick<import("..").BaseReadiumViewProps, "onLocationChange" | "onTableOfContents" | "settings" | "file" | "location" | "style" | "height" | "width"> & React.RefAttributes<{
|
|
3
|
+
nextPage: () => void;
|
|
4
|
+
prevPage: () => void;
|
|
5
|
+
}>>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import React, { useImperativeHandle } from 'react';
|
|
2
|
+
import { View, StyleSheet } from 'react-native';
|
|
3
|
+
import { useReaderRef, useSettingsObserver, useLocationObserver, } from '../../web/hooks';
|
|
4
|
+
export const ReadiumView = React.forwardRef(({ file, settings, location, onLocationChange, onTableOfContents, style = {}, height, width, }, ref) => {
|
|
5
|
+
const readerRef = useReaderRef({
|
|
6
|
+
file,
|
|
7
|
+
onLocationChange,
|
|
8
|
+
onTableOfContents,
|
|
9
|
+
});
|
|
10
|
+
const reader = readerRef.current;
|
|
11
|
+
useImperativeHandle(ref, () => ({
|
|
12
|
+
nextPage: () => {
|
|
13
|
+
readerRef.current?.nextPage();
|
|
14
|
+
},
|
|
15
|
+
prevPage: () => {
|
|
16
|
+
readerRef.current?.previousPage();
|
|
17
|
+
},
|
|
18
|
+
}));
|
|
19
|
+
useSettingsObserver(reader, settings);
|
|
20
|
+
useLocationObserver(reader, location);
|
|
21
|
+
const mainStyle = {
|
|
22
|
+
...styles.maximize,
|
|
23
|
+
...style,
|
|
24
|
+
};
|
|
25
|
+
if (height)
|
|
26
|
+
mainStyle.height = height;
|
|
27
|
+
if (width)
|
|
28
|
+
mainStyle.width = width;
|
|
29
|
+
return (<View style={styles.container}>
|
|
30
|
+
{!reader && <div style={styles.loader}>Loading reader...</div>}
|
|
31
|
+
<div id="D2Reader-Container" style={styles.d2Container}>
|
|
32
|
+
<main style={mainStyle} tabIndex={-1} id="iframe-wrapper">
|
|
33
|
+
<div id="reader-loading" className="loading" style={styles.loader}></div>
|
|
34
|
+
<div id="reader-error" className="error"></div>
|
|
35
|
+
</main>
|
|
36
|
+
</div>
|
|
37
|
+
</View>);
|
|
38
|
+
});
|
|
39
|
+
const styles = StyleSheet.create({
|
|
40
|
+
container: {
|
|
41
|
+
width: '100%',
|
|
42
|
+
height: '100%',
|
|
43
|
+
},
|
|
44
|
+
d2Container: {
|
|
45
|
+
width: '100%',
|
|
46
|
+
height: '100%',
|
|
47
|
+
display: 'flex',
|
|
48
|
+
},
|
|
49
|
+
maximize: {
|
|
50
|
+
width: '100%',
|
|
51
|
+
height: '100%',
|
|
52
|
+
display: 'flex',
|
|
53
|
+
},
|
|
54
|
+
button: {
|
|
55
|
+
width: 50,
|
|
56
|
+
fontSize: 100,
|
|
57
|
+
backgroundColor: 'transparent',
|
|
58
|
+
border: 'none',
|
|
59
|
+
},
|
|
60
|
+
loader: {
|
|
61
|
+
width: '100%',
|
|
62
|
+
height: '100%',
|
|
63
|
+
textAlign: 'center',
|
|
64
|
+
position: 'relative',
|
|
65
|
+
top: 'calc(50% - 10px)',
|
|
66
|
+
},
|
|
67
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// NOTE: readium uses an index so the order is very important here
|
|
2
|
+
export var Appearance;
|
|
3
|
+
(function (Appearance) {
|
|
4
|
+
/**
|
|
5
|
+
* A traditional "light" mode
|
|
6
|
+
*/
|
|
7
|
+
Appearance["DEFAULT"] = "readium-default-on";
|
|
8
|
+
Appearance["SEPIA"] = "readium-sepia-on";
|
|
9
|
+
/**
|
|
10
|
+
* A traditional "dark" mode
|
|
11
|
+
*/
|
|
12
|
+
Appearance["NIGHT"] = "readium-night-on";
|
|
13
|
+
})(Appearance || (Appearance = {}));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// NOTE: readium uses an index so the order is very important here
|
|
2
|
+
export var FontFamily;
|
|
3
|
+
(function (FontFamily) {
|
|
4
|
+
FontFamily["ORIGINAL"] = "Original";
|
|
5
|
+
FontFamily["HELVETICA_NEUE"] = "Helvetica Neue";
|
|
6
|
+
FontFamily["IOWAN_OLD_STYLE"] = "Iowan Old Style";
|
|
7
|
+
FontFamily["ATHELAS"] = "Athelas";
|
|
8
|
+
FontFamily["SERAVEK"] = "Seravek";
|
|
9
|
+
FontFamily["OPEN_DYSLEXIC"] = "OpenDyslexic";
|
|
10
|
+
FontFamily["ACCESSIBLE_DFA"] = "AccessibleDfA";
|
|
11
|
+
FontFamily["IA_WRITER_DUOSPACE"] = "IA Writer Duospace";
|
|
12
|
+
})(FontFamily || (FontFamily = {}));
|
package/lib/{typescript/components/BaseReadiumView.d.ts → src/interfaces/BaseReadiumViewProps.d.ts}
RENAMED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { ViewStyle } from 'react-native';
|
|
2
|
-
import type { Settings
|
|
1
|
+
import type { ViewStyle } from 'react-native';
|
|
2
|
+
import type { Settings } from './Settings';
|
|
3
|
+
import type { Link } from './Link';
|
|
4
|
+
import type { Locator } from './Locator';
|
|
5
|
+
import type { File } from './File';
|
|
3
6
|
export declare type BaseReadiumViewProps = {
|
|
4
7
|
file: File;
|
|
5
8
|
location?: Locator | Link;
|
|
@@ -11,4 +14,3 @@ export declare type BaseReadiumViewProps = {
|
|
|
11
14
|
height?: number;
|
|
12
15
|
width?: number;
|
|
13
16
|
};
|
|
14
|
-
export declare const BaseReadiumView: import("react-native").HostComponent<BaseReadiumViewProps> | (() => never);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Appearance, FontFamily, TextAlignment, ColumnCount, } from '../enums';
|
|
2
|
+
import { RANGES, indexOfObjectValue, clamp, } from '../utils';
|
|
3
|
+
/**
|
|
4
|
+
* A reader settings object with sensible defaults.
|
|
5
|
+
*/
|
|
6
|
+
export class Settings {
|
|
7
|
+
// TODO:
|
|
8
|
+
// - ligatures
|
|
9
|
+
// - paraIndent
|
|
10
|
+
appearance = Appearance.DEFAULT;
|
|
11
|
+
fontFamily = FontFamily.ORIGINAL;
|
|
12
|
+
textAlign = TextAlignment.JUSTIFY;
|
|
13
|
+
colCount = ColumnCount.AUTO;
|
|
14
|
+
scroll = false;
|
|
15
|
+
fontOverride = false;
|
|
16
|
+
verticalScroll = false;
|
|
17
|
+
bodyHyphens = false;
|
|
18
|
+
advancedSettings = true;
|
|
19
|
+
/**
|
|
20
|
+
* Range: 100.0 - 300.0
|
|
21
|
+
*/
|
|
22
|
+
fontSize = 100;
|
|
23
|
+
/**
|
|
24
|
+
* Range: 0.0 - 0.5
|
|
25
|
+
*/
|
|
26
|
+
wordSpacing = 0;
|
|
27
|
+
/**
|
|
28
|
+
* Range: 0.0 - 0.5
|
|
29
|
+
*/
|
|
30
|
+
letterSpacing = 0;
|
|
31
|
+
/**
|
|
32
|
+
* Range: 0.5 - 4.0
|
|
33
|
+
*/
|
|
34
|
+
pageMargins = 0;
|
|
35
|
+
/**
|
|
36
|
+
* Range: 1.0 - 2.0
|
|
37
|
+
*/
|
|
38
|
+
lineHeight = 1;
|
|
39
|
+
/**
|
|
40
|
+
* Range: 0.0 - 2.0
|
|
41
|
+
*/
|
|
42
|
+
paragraphMargins = 0;
|
|
43
|
+
static map(settings) {
|
|
44
|
+
const defaultValues = new Settings();
|
|
45
|
+
const mapped = {};
|
|
46
|
+
Object.keys(defaultValues)
|
|
47
|
+
.forEach((key) => {
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
mapped[key] = settings[key] !== undefined ? settings[key] : defaultValues[key];
|
|
50
|
+
});
|
|
51
|
+
mapped.appearance = indexOfObjectValue(Appearance, mapped.appearance);
|
|
52
|
+
mapped.fontFamily = indexOfObjectValue(FontFamily, mapped.fontFamily);
|
|
53
|
+
mapped.textAlign = indexOfObjectValue(TextAlignment, mapped.textAlign);
|
|
54
|
+
mapped.colCount = indexOfObjectValue(ColumnCount, mapped.colCount);
|
|
55
|
+
Object.keys(RANGES).forEach((key) => {
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
mapped[key] = clamp(mapped[key], RANGES[key][0], RANGES[key][1]);
|
|
58
|
+
});
|
|
59
|
+
return mapped;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
export const LINKING_ERROR = `The package 'react-native-readium' doesn't seem to be linked. Make sure: \n\n` +
|
|
3
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
4
|
+
'- You rebuilt the app after installing the package\n' +
|
|
5
|
+
'- You are not using Expo managed workflow\n';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { UIManager } from 'react-native';
|
|
2
|
+
import { COMPONENT_NAME } from './COMPONENT_NAME';
|
|
3
|
+
export const createFragment = (viewId) => {
|
|
4
|
+
if (viewId !== null) {
|
|
5
|
+
UIManager.dispatchViewManagerCommand(viewId,
|
|
6
|
+
// we are calling the 'create' command
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
UIManager.getViewManagerConfig(COMPONENT_NAME).Commands.create.toString(), [viewId]);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useDeepCompareEffect } from 'use-deep-compare';
|
|
2
|
+
export const useLocationObserver = (reader, location) => {
|
|
3
|
+
useDeepCompareEffect(() => {
|
|
4
|
+
if (reader && location) {
|
|
5
|
+
// NOTE: technically this is a Link | Locator. However, under the hood the
|
|
6
|
+
// R2D2BC is converting Links to locators, so just force the type here.
|
|
7
|
+
reader.goTo(location);
|
|
8
|
+
}
|
|
9
|
+
}, [
|
|
10
|
+
location,
|
|
11
|
+
!!reader,
|
|
12
|
+
]);
|
|
13
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ReadiumProps } from '../../src/components/ReadiumView';
|
|
3
|
+
export declare const useReaderRef: ({ file, onLocationChange, onTableOfContents, }: Pick<ReadiumProps, 'file' | 'onLocationChange' | 'onTableOfContents'>) => import("react").MutableRefObject<import("@d-i-t-a/reader").default | null>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
export const useReaderRef = ({ file, onLocationChange, onTableOfContents, }) => {
|
|
3
|
+
const readerRef = useRef(null);
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
async function run() {
|
|
6
|
+
const D2Reader = await import('@d-i-t-a/reader');
|
|
7
|
+
const ref = await D2Reader.load({
|
|
8
|
+
url: new URL(file.url),
|
|
9
|
+
lastReadingPosition: file.initialLocation,
|
|
10
|
+
userSettings: { verticalScroll: false },
|
|
11
|
+
api: {
|
|
12
|
+
updateCurrentLocation: async (location) => {
|
|
13
|
+
if (onLocationChange)
|
|
14
|
+
onLocationChange(location);
|
|
15
|
+
return location;
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
injectables: injectables,
|
|
19
|
+
});
|
|
20
|
+
if (onTableOfContents) {
|
|
21
|
+
onTableOfContents(ref.tableOfContents);
|
|
22
|
+
}
|
|
23
|
+
readerRef.current = ref;
|
|
24
|
+
}
|
|
25
|
+
run();
|
|
26
|
+
}, []);
|
|
27
|
+
return readerRef;
|
|
28
|
+
};
|
|
29
|
+
// NOTE: right now we're serving these through statically.io, which is just
|
|
30
|
+
// pulling them from Github... Might not be the best way and maybe we should
|
|
31
|
+
// consider bundling them with the library.
|
|
32
|
+
const injectables = [
|
|
33
|
+
{
|
|
34
|
+
type: "style",
|
|
35
|
+
url: "https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-before.css",
|
|
36
|
+
r2before: true,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
type: "style",
|
|
40
|
+
url: "https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-default.css",
|
|
41
|
+
r2default: true,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
type: "style",
|
|
45
|
+
url: "https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-after.css",
|
|
46
|
+
r2after: true,
|
|
47
|
+
},
|
|
48
|
+
];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useDeepCompareEffect } from 'use-deep-compare';
|
|
2
|
+
export const useSettingsObserver = (reader, settings) => {
|
|
3
|
+
useDeepCompareEffect(() => {
|
|
4
|
+
if (reader && settings) {
|
|
5
|
+
// @ts-ignore - FIXME need to do some deeper investigation if these
|
|
6
|
+
// are equivalent or not
|
|
7
|
+
reader?.applyUserSettings(settings);
|
|
8
|
+
}
|
|
9
|
+
}, [
|
|
10
|
+
settings,
|
|
11
|
+
!!reader,
|
|
12
|
+
]);
|
|
13
|
+
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-readium",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "A react-native wrapper for https://readium.org/",
|
|
5
|
-
"main": "lib/
|
|
6
|
-
"
|
|
7
|
-
"types": "lib/typescript/index.d.ts",
|
|
5
|
+
"main": "lib/src/index",
|
|
6
|
+
"types": "lib/src/index.d.ts",
|
|
8
7
|
"react-native": "src/index",
|
|
9
8
|
"source": "src/index",
|
|
10
9
|
"files": [
|
|
@@ -12,6 +11,7 @@
|
|
|
12
11
|
"lib",
|
|
13
12
|
"android",
|
|
14
13
|
"ios",
|
|
14
|
+
"web",
|
|
15
15
|
"cpp",
|
|
16
16
|
"react-native-readium.podspec",
|
|
17
17
|
"!lib/typescript/example",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"test": "jest",
|
|
26
26
|
"typescript": "tsc --noEmit",
|
|
27
27
|
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
28
|
-
"prepare": "
|
|
28
|
+
"prepare": "rimraf lib && tsc",
|
|
29
29
|
"release": "release-it",
|
|
30
30
|
"example": "yarn --cwd example",
|
|
31
31
|
"pods": "cd example && pod-install --quiet",
|
|
@@ -59,11 +59,11 @@
|
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@commitlint/config-conventional": "^11.0.0",
|
|
62
|
-
"@react-native-community/eslint-config": "^2.0
|
|
62
|
+
"@react-native-community/eslint-config": "^3.2.0",
|
|
63
63
|
"@release-it/conventional-changelog": "^2.0.0",
|
|
64
64
|
"@types/jest": "^26.0.0",
|
|
65
|
-
"@types/react": "^
|
|
66
|
-
"@types/react-native": "^0.
|
|
65
|
+
"@types/react": "^17.0.52",
|
|
66
|
+
"@types/react-native": "^0.68",
|
|
67
67
|
"commitlint": "^11.0.0",
|
|
68
68
|
"conventional-changelog-cli": "^2.2.2",
|
|
69
69
|
"eslint": "^7.2.0",
|
|
@@ -75,7 +75,6 @@
|
|
|
75
75
|
"prettier": "^2.0.5",
|
|
76
76
|
"react": "^18.2.0",
|
|
77
77
|
"react-native": "^0.70.6",
|
|
78
|
-
"react-native-builder-bob": "^0.18.2",
|
|
79
78
|
"release-it": "^14.2.2",
|
|
80
79
|
"typescript": "^4.1.3"
|
|
81
80
|
},
|
|
@@ -142,20 +141,6 @@
|
|
|
142
141
|
"trailingComma": "es5",
|
|
143
142
|
"useTabs": false
|
|
144
143
|
},
|
|
145
|
-
"react-native-builder-bob": {
|
|
146
|
-
"source": "src",
|
|
147
|
-
"output": "lib",
|
|
148
|
-
"targets": [
|
|
149
|
-
"commonjs",
|
|
150
|
-
"module",
|
|
151
|
-
[
|
|
152
|
-
"typescript",
|
|
153
|
-
{
|
|
154
|
-
"project": "tsconfig.build.json"
|
|
155
|
-
}
|
|
156
|
-
]
|
|
157
|
-
]
|
|
158
|
-
},
|
|
159
144
|
"dependencies": {
|
|
160
145
|
"@d-i-t-a/reader": "^2.1.4",
|
|
161
146
|
"use-deep-compare": "^1.1.0"
|
|
@@ -1,24 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
requireNativeComponent,
|
|
3
3
|
UIManager,
|
|
4
|
-
ViewStyle,
|
|
5
4
|
} from 'react-native';
|
|
6
5
|
|
|
7
|
-
import type {
|
|
6
|
+
import type { BaseReadiumViewProps } from '../interfaces';
|
|
8
7
|
import { COMPONENT_NAME, LINKING_ERROR } from '../utils';
|
|
9
8
|
|
|
10
|
-
export type BaseReadiumViewProps = {
|
|
11
|
-
file: File;
|
|
12
|
-
location?: Locator | Link;
|
|
13
|
-
settings?: Partial<Settings>;
|
|
14
|
-
style?: ViewStyle;
|
|
15
|
-
onLocationChange?: (locator: Locator) => void;
|
|
16
|
-
onTableOfContents?: (toc: Link[] | null) => void;
|
|
17
|
-
ref?: any;
|
|
18
|
-
height?: number;
|
|
19
|
-
width?: number;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
9
|
export const BaseReadiumView =
|
|
23
10
|
UIManager.getViewManagerConfig(COMPONENT_NAME) != null
|
|
24
11
|
? requireNativeComponent<BaseReadiumViewProps>(COMPONENT_NAME)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const BaseReadiumView = () => null
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import React, { useCallback, useState, useRef, useEffect } from 'react';
|
|
2
2
|
import { View, Platform, findNodeHandle, StyleSheet } from 'react-native';
|
|
3
3
|
|
|
4
|
-
import type { Dimensions } from '../interfaces';
|
|
4
|
+
import type { BaseReadiumViewProps, Dimensions } from '../interfaces';
|
|
5
5
|
import { Settings } from '../interfaces';
|
|
6
6
|
import { createFragment, getWidthOrHeightValue as dimension } from '../utils';
|
|
7
|
-
import type { BaseReadiumViewProps } from './BaseReadiumView';
|
|
8
7
|
import { BaseReadiumView } from './BaseReadiumView';
|
|
9
8
|
|
|
10
9
|
export type ReadiumProps = BaseReadiumViewProps;
|