react-native-readium 1.2.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.
Files changed (182) hide show
  1. package/README.md +23 -2
  2. package/lib/src/components/BaseReadiumView.d.ts +2 -0
  3. package/lib/src/components/BaseReadiumView.js +7 -0
  4. package/lib/src/components/BaseReadiumView.web.d.ts +1 -0
  5. package/lib/src/components/BaseReadiumView.web.js +1 -0
  6. package/lib/{typescript → src}/components/ReadiumView.d.ts +1 -1
  7. package/lib/src/components/ReadiumView.js +43 -0
  8. package/lib/src/components/ReadiumView.web.d.ts +5 -0
  9. package/lib/src/components/ReadiumView.web.js +67 -0
  10. package/lib/src/enums/Appearance.js +13 -0
  11. package/lib/src/enums/ColumnCount.js +7 -0
  12. package/lib/src/enums/FontFamily.js +12 -0
  13. package/lib/src/enums/TextAlignment.js +6 -0
  14. package/lib/{module → src}/enums/index.js +0 -1
  15. package/lib/{module → src}/index.js +0 -1
  16. package/lib/{typescript/components/BaseReadiumView.d.ts → src/interfaces/BaseReadiumViewProps.d.ts} +5 -3
  17. package/lib/src/interfaces/BaseReadiumViewProps.js +1 -0
  18. package/lib/src/interfaces/Dimensions.js +1 -0
  19. package/lib/src/interfaces/File.js +1 -0
  20. package/lib/src/interfaces/Link.js +1 -0
  21. package/lib/src/interfaces/Locator.js +1 -0
  22. package/lib/src/interfaces/Settings.js +61 -0
  23. package/lib/{typescript → src}/interfaces/index.d.ts +1 -0
  24. package/lib/{module → src}/interfaces/index.js +1 -1
  25. package/lib/{module → src}/utils/COMPONENT_NAME.js +0 -1
  26. package/lib/src/utils/LINKING_ERROR.js +5 -0
  27. package/lib/src/utils/RANGES.js +8 -0
  28. package/lib/src/utils/clamp.js +7 -0
  29. package/lib/src/utils/createFragment.js +10 -0
  30. package/lib/src/utils/getWidthOrHeightValue.js +4 -0
  31. package/lib/{module → src}/utils/index.js +0 -1
  32. package/lib/src/utils/indexOfObjectValue.js +3 -0
  33. package/lib/web/hooks/useLocationObserver.d.ts +2 -0
  34. package/lib/web/hooks/useLocationObserver.js +13 -0
  35. package/lib/web/hooks/useReaderRef.d.ts +3 -0
  36. package/lib/web/hooks/useReaderRef.js +48 -0
  37. package/lib/web/hooks/useSettingsObserver.d.ts +2 -0
  38. package/lib/web/hooks/useSettingsObserver.js +13 -0
  39. package/package.json +8 -23
  40. package/src/components/BaseReadiumView.tsx +1 -14
  41. package/src/components/BaseReadiumView.web.tsx +1 -0
  42. package/src/components/ReadiumView.tsx +1 -2
  43. package/src/{web/ReadiumView.tsx → components/ReadiumView.web.tsx} +1 -1
  44. package/src/interfaces/BaseReadiumViewProps.ts +18 -0
  45. package/src/interfaces/index.ts +1 -0
  46. package/{lib/module/web/hooks/index.js → web/hooks/index.ts} +0 -1
  47. package/{src/web → web}/hooks/useLocationObserver.ts +1 -3
  48. package/{src/web → web}/hooks/useReaderRef.ts +20 -17
  49. package/{src/web → web}/hooks/useSettingsObserver.ts +2 -4
  50. package/lib/commonjs/components/BaseReadiumView.js +0 -16
  51. package/lib/commonjs/components/BaseReadiumView.js.map +0 -1
  52. package/lib/commonjs/components/ReadiumView.js +0 -94
  53. package/lib/commonjs/components/ReadiumView.js.map +0 -1
  54. package/lib/commonjs/enums/Appearance.js +0 -16
  55. package/lib/commonjs/enums/Appearance.js.map +0 -1
  56. package/lib/commonjs/enums/ColumnCount.js +0 -16
  57. package/lib/commonjs/enums/ColumnCount.js.map +0 -1
  58. package/lib/commonjs/enums/FontFamily.js +0 -21
  59. package/lib/commonjs/enums/FontFamily.js.map +0 -1
  60. package/lib/commonjs/enums/TextAlignment.js +0 -15
  61. package/lib/commonjs/enums/TextAlignment.js.map +0 -1
  62. package/lib/commonjs/enums/index.js +0 -58
  63. package/lib/commonjs/enums/index.js.map +0 -1
  64. package/lib/commonjs/index.js +0 -59
  65. package/lib/commonjs/index.js.map +0 -1
  66. package/lib/commonjs/index.web.js +0 -54
  67. package/lib/commonjs/index.web.js.map +0 -1
  68. package/lib/commonjs/interfaces/Dimensions.js +0 -2
  69. package/lib/commonjs/interfaces/Dimensions.js.map +0 -1
  70. package/lib/commonjs/interfaces/File.js +0 -6
  71. package/lib/commonjs/interfaces/File.js.map +0 -1
  72. package/lib/commonjs/interfaces/Link.js +0 -2
  73. package/lib/commonjs/interfaces/Link.js.map +0 -1
  74. package/lib/commonjs/interfaces/Locator.js +0 -2
  75. package/lib/commonjs/interfaces/Locator.js.map +0 -1
  76. package/lib/commonjs/interfaces/Settings.js +0 -71
  77. package/lib/commonjs/interfaces/Settings.js.map +0 -1
  78. package/lib/commonjs/interfaces/index.js +0 -71
  79. package/lib/commonjs/interfaces/index.js.map +0 -1
  80. package/lib/commonjs/utils/COMPONENT_NAME.js +0 -9
  81. package/lib/commonjs/utils/COMPONENT_NAME.js.map +0 -1
  82. package/lib/commonjs/utils/LINKING_ERROR.js +0 -15
  83. package/lib/commonjs/utils/LINKING_ERROR.js.map +0 -1
  84. package/lib/commonjs/utils/RANGES.js +0 -16
  85. package/lib/commonjs/utils/RANGES.js.map +0 -1
  86. package/lib/commonjs/utils/clamp.js +0 -15
  87. package/lib/commonjs/utils/clamp.js.map +0 -1
  88. package/lib/commonjs/utils/createFragment.js +0 -21
  89. package/lib/commonjs/utils/createFragment.js.map +0 -1
  90. package/lib/commonjs/utils/getWidthOrHeightValue.js +0 -15
  91. package/lib/commonjs/utils/getWidthOrHeightValue.js.map +0 -1
  92. package/lib/commonjs/utils/index.js +0 -97
  93. package/lib/commonjs/utils/index.js.map +0 -1
  94. package/lib/commonjs/utils/indexOfObjectValue.js +0 -13
  95. package/lib/commonjs/utils/indexOfObjectValue.js.map +0 -1
  96. package/lib/commonjs/web/ReadiumView.js +0 -106
  97. package/lib/commonjs/web/ReadiumView.js.map +0 -1
  98. package/lib/commonjs/web/hooks/index.js +0 -45
  99. package/lib/commonjs/web/hooks/index.js.map +0 -1
  100. package/lib/commonjs/web/hooks/useLocationObserver.js +0 -21
  101. package/lib/commonjs/web/hooks/useLocationObserver.js.map +0 -1
  102. package/lib/commonjs/web/hooks/useReaderRef.js +0 -63
  103. package/lib/commonjs/web/hooks/useReaderRef.js.map +0 -1
  104. package/lib/commonjs/web/hooks/useSettingsObserver.js +0 -21
  105. package/lib/commonjs/web/hooks/useSettingsObserver.js.map +0 -1
  106. package/lib/module/components/BaseReadiumView.js +0 -6
  107. package/lib/module/components/BaseReadiumView.js.map +0 -1
  108. package/lib/module/components/ReadiumView.js +0 -75
  109. package/lib/module/components/ReadiumView.js.map +0 -1
  110. package/lib/module/enums/Appearance.js +0 -9
  111. package/lib/module/enums/Appearance.js.map +0 -1
  112. package/lib/module/enums/ColumnCount.js +0 -9
  113. package/lib/module/enums/ColumnCount.js.map +0 -1
  114. package/lib/module/enums/FontFamily.js +0 -14
  115. package/lib/module/enums/FontFamily.js.map +0 -1
  116. package/lib/module/enums/TextAlignment.js +0 -8
  117. package/lib/module/enums/TextAlignment.js.map +0 -1
  118. package/lib/module/enums/index.js.map +0 -1
  119. package/lib/module/index.js.map +0 -1
  120. package/lib/module/index.web.js +0 -5
  121. package/lib/module/index.web.js.map +0 -1
  122. package/lib/module/interfaces/Dimensions.js +0 -2
  123. package/lib/module/interfaces/Dimensions.js.map +0 -1
  124. package/lib/module/interfaces/File.js +0 -2
  125. package/lib/module/interfaces/File.js.map +0 -1
  126. package/lib/module/interfaces/Link.js +0 -2
  127. package/lib/module/interfaces/Link.js.map +0 -1
  128. package/lib/module/interfaces/Locator.js +0 -2
  129. package/lib/module/interfaces/Locator.js.map +0 -1
  130. package/lib/module/interfaces/Settings.js +0 -61
  131. package/lib/module/interfaces/Settings.js.map +0 -1
  132. package/lib/module/interfaces/index.js.map +0 -1
  133. package/lib/module/utils/COMPONENT_NAME.js.map +0 -1
  134. package/lib/module/utils/LINKING_ERROR.js +0 -6
  135. package/lib/module/utils/LINKING_ERROR.js.map +0 -1
  136. package/lib/module/utils/RANGES.js +0 -9
  137. package/lib/module/utils/RANGES.js.map +0 -1
  138. package/lib/module/utils/clamp.js +0 -6
  139. package/lib/module/utils/clamp.js.map +0 -1
  140. package/lib/module/utils/createFragment.js +0 -10
  141. package/lib/module/utils/createFragment.js.map +0 -1
  142. package/lib/module/utils/getWidthOrHeightValue.js +0 -5
  143. package/lib/module/utils/getWidthOrHeightValue.js.map +0 -1
  144. package/lib/module/utils/index.js.map +0 -1
  145. package/lib/module/utils/indexOfObjectValue.js +0 -4
  146. package/lib/module/utils/indexOfObjectValue.js.map +0 -1
  147. package/lib/module/web/ReadiumView.js +0 -89
  148. package/lib/module/web/ReadiumView.js.map +0 -1
  149. package/lib/module/web/hooks/index.js.map +0 -1
  150. package/lib/module/web/hooks/useLocationObserver.js +0 -11
  151. package/lib/module/web/hooks/useLocationObserver.js.map +0 -1
  152. package/lib/module/web/hooks/useReaderRef.js +0 -50
  153. package/lib/module/web/hooks/useReaderRef.js.map +0 -1
  154. package/lib/module/web/hooks/useSettingsObserver.js +0 -11
  155. package/lib/module/web/hooks/useSettingsObserver.js.map +0 -1
  156. package/lib/typescript/index.web.d.ts +0 -4
  157. package/lib/typescript/web/ReadiumView.d.ts +0 -5
  158. package/lib/typescript/web/hooks/useLocationObserver.d.ts +0 -3
  159. package/lib/typescript/web/hooks/useReaderRef.d.ts +0 -4
  160. package/lib/typescript/web/hooks/useSettingsObserver.d.ts +0 -3
  161. package/src/index.web.tsx +0 -5
  162. /package/lib/{typescript → src}/enums/Appearance.d.ts +0 -0
  163. /package/lib/{typescript → src}/enums/ColumnCount.d.ts +0 -0
  164. /package/lib/{typescript → src}/enums/FontFamily.d.ts +0 -0
  165. /package/lib/{typescript → src}/enums/TextAlignment.d.ts +0 -0
  166. /package/lib/{typescript → src}/enums/index.d.ts +0 -0
  167. /package/lib/{typescript → src}/index.d.ts +0 -0
  168. /package/lib/{typescript → src}/interfaces/Dimensions.d.ts +0 -0
  169. /package/lib/{typescript → src}/interfaces/File.d.ts +0 -0
  170. /package/lib/{typescript → src}/interfaces/Link.d.ts +0 -0
  171. /package/lib/{typescript → src}/interfaces/Locator.d.ts +0 -0
  172. /package/lib/{typescript → src}/interfaces/Settings.d.ts +0 -0
  173. /package/lib/{typescript → src}/utils/COMPONENT_NAME.d.ts +0 -0
  174. /package/lib/{typescript → src}/utils/LINKING_ERROR.d.ts +0 -0
  175. /package/lib/{typescript → src}/utils/RANGES.d.ts +0 -0
  176. /package/lib/{typescript → src}/utils/clamp.d.ts +0 -0
  177. /package/lib/{typescript → src}/utils/createFragment.d.ts +0 -0
  178. /package/lib/{typescript → src}/utils/getWidthOrHeightValue.d.ts +0 -0
  179. /package/lib/{typescript → src}/utils/index.d.ts +0 -0
  180. /package/lib/{typescript → src}/utils/indexOfObjectValue.d.ts +0 -0
  181. /package/lib/{typescript/web → web}/hooks/index.d.ts +0 -0
  182. /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
+ [![NPM version](https://img.shields.io/npm/v/react-native-readium.svg?color=success&label=npm%20package&logo=npm)](https://www.npmjs.com/package/react-native-readium)
4
+ [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
5
+ ![PRs welcome!](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)
6
+ ![This project is released under the MIT license](https://img.shields.io/badge/license-MIT-blue.svg)
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
+ [![Issue Hunt](https://issuehunt.io/static/embed/issuehunt-button-v1.svg)](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
- ## Overview
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
  | ![Dark Mode](https://github.com/5-stones/react-native-readium/blob/main/docs/demo-dark-mode.gif) | ![Light Mode](https://github.com/5-stones/react-native-readium/blob/main/docs/demo-light-mode.gif) |
29
50
 
30
51
  ## Installation
@@ -0,0 +1,2 @@
1
+ import type { BaseReadiumViewProps } from '../interfaces';
2
+ export declare const BaseReadiumView: import("react-native").HostComponent<BaseReadiumViewProps> | (() => never);
@@ -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;
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
- import type { BaseReadiumViewProps } from './BaseReadiumView';
2
+ import type { BaseReadiumViewProps } from '../interfaces';
3
3
  export declare type ReadiumProps = BaseReadiumViewProps;
4
4
  export declare const ReadiumView: React.FC<ReadiumProps>;
@@ -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,7 @@
1
+ // NOTE: readium uses an index so the order is very important here
2
+ export var ColumnCount;
3
+ (function (ColumnCount) {
4
+ ColumnCount["AUTO"] = "auto";
5
+ ColumnCount["ONE"] = "1";
6
+ ColumnCount["TWO"] = "2";
7
+ })(ColumnCount || (ColumnCount = {}));
@@ -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 = {}));
@@ -0,0 +1,6 @@
1
+ // NOTE: readium uses an index so the order is very important here
2
+ export var TextAlignment;
3
+ (function (TextAlignment) {
4
+ TextAlignment["JUSTIFY"] = "justify";
5
+ TextAlignment["START"] = "start";
6
+ })(TextAlignment || (TextAlignment = {}));
@@ -2,4 +2,3 @@ export * from './Appearance';
2
2
  export * from './ColumnCount';
3
3
  export * from './FontFamily';
4
4
  export * from './TextAlignment';
5
- //# sourceMappingURL=index.js.map
@@ -2,4 +2,3 @@ export * from './enums';
2
2
  export * from './interfaces';
3
3
  export { RANGES } from './utils';
4
4
  export * from './components/ReadiumView';
5
- //# sourceMappingURL=index.js.map
@@ -1,5 +1,8 @@
1
- import { ViewStyle } from 'react-native';
2
- import type { Settings, Link, Locator, File } from '../interfaces';
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
+ }
@@ -1,3 +1,4 @@
1
+ export * from './BaseReadiumViewProps';
1
2
  export * from './Dimensions';
2
3
  export * from './File';
3
4
  export * from './Link';
@@ -1,6 +1,6 @@
1
+ export * from './BaseReadiumViewProps';
1
2
  export * from './Dimensions';
2
3
  export * from './File';
3
4
  export * from './Link';
4
5
  export * from './Locator';
5
6
  export * from './Settings';
6
- //# sourceMappingURL=index.js.map
@@ -1,2 +1 @@
1
1
  export const COMPONENT_NAME = 'ReadiumView';
2
- //# sourceMappingURL=COMPONENT_NAME.js.map
@@ -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,8 @@
1
+ export const RANGES = {
2
+ fontSize: [100.0, 300.0],
3
+ wordSpacing: [0.0, 0.5],
4
+ letterSpacing: [0.0, 0.5],
5
+ pageMargins: [0.5, 4.0],
6
+ lineHeight: [1.0, 2.0],
7
+ paragraphMargins: [0.0, 2.0],
8
+ };
@@ -0,0 +1,7 @@
1
+ export const clamp = (val, lower, upper) => {
2
+ if (val < lower)
3
+ return lower;
4
+ if (val > upper)
5
+ return upper;
6
+ return val;
7
+ };
@@ -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,4 @@
1
+ import { Platform, PixelRatio } from 'react-native';
2
+ export const getWidthOrHeightValue = (val) => {
3
+ return Platform.OS === 'android' ? PixelRatio.getPixelSizeForLayoutSize(val) : val;
4
+ };
@@ -5,4 +5,3 @@ export * from './getWidthOrHeightValue';
5
5
  export * from './indexOfObjectValue';
6
6
  export * from './LINKING_ERROR';
7
7
  export * from './RANGES';
8
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ export const indexOfObjectValue = (obj, val) => {
2
+ return Object.values(obj).indexOf(val);
3
+ };
@@ -0,0 +1,2 @@
1
+ import type { Link, Locator } from '../../src/interfaces';
2
+ export declare const useLocationObserver: (reader?: import("@d-i-t-a/reader").default | null | undefined, location?: Link | Locator | null | undefined) => void;
@@ -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,2 @@
1
+ import type { Settings } from '../../src/interfaces';
2
+ export declare const useSettingsObserver: (reader?: import("@d-i-t-a/reader").default | null | undefined, settings?: Partial<Settings> | null | undefined) => void;
@@ -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.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "A react-native wrapper for https://readium.org/",
5
- "main": "lib/commonjs/index",
6
- "module": "lib/module/index",
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": "bob build",
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.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": "^18.0.26",
66
- "@types/react-native": "^0.70.8",
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 { Settings, Link, Locator, File, } from '../interfaces';
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;
@@ -7,7 +7,7 @@ import {
7
7
  useReaderRef,
8
8
  useSettingsObserver,
9
9
  useLocationObserver,
10
- } from './hooks';
10
+ } from '../../web/hooks';
11
11
 
12
12
  export const ReadiumView = React.forwardRef<{
13
13
  nextPage: () => void;