react-native-simple-epub-reader 0.1.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.
Files changed (90) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +37 -0
  3. package/lib/module/components/GestureHandler/index.js +39 -0
  4. package/lib/module/components/GestureHandler/index.js.map +1 -0
  5. package/lib/module/components/Reader.js +207 -0
  6. package/lib/module/components/Reader.js.map +1 -0
  7. package/lib/module/constants/template.js +402 -0
  8. package/lib/module/constants/template.js.map +1 -0
  9. package/lib/module/constants/theme.js +43 -0
  10. package/lib/module/constants/theme.js.map +1 -0
  11. package/lib/module/context/ReaderContext.js +213 -0
  12. package/lib/module/context/ReaderContext.js.map +1 -0
  13. package/lib/module/context/types.js +4 -0
  14. package/lib/module/context/types.js.map +1 -0
  15. package/lib/module/helpers/downloadEpub.js +17 -0
  16. package/lib/module/helpers/downloadEpub.js.map +1 -0
  17. package/lib/module/helpers/loadScripts.js +21 -0
  18. package/lib/module/helpers/loadScripts.js.map +1 -0
  19. package/lib/module/helpers/saveTemplateToFile.js +21 -0
  20. package/lib/module/helpers/saveTemplateToFile.js.map +1 -0
  21. package/lib/module/helpers/webViewInjectFunctions.js +14 -0
  22. package/lib/module/helpers/webViewInjectFunctions.js.map +1 -0
  23. package/lib/module/hooks/useInjectWebviewVariables.js +20 -0
  24. package/lib/module/hooks/useInjectWebviewVariables.js.map +1 -0
  25. package/lib/module/hooks/useReaderState.js +117 -0
  26. package/lib/module/hooks/useReaderState.js.map +1 -0
  27. package/lib/module/index.js +6 -0
  28. package/lib/module/index.js.map +1 -0
  29. package/lib/module/package.json +1 -0
  30. package/lib/module/scripts/epub.js +14326 -0
  31. package/lib/module/scripts/epub.js.map +1 -0
  32. package/lib/module/scripts/jszip.js +6646 -0
  33. package/lib/module/scripts/jszip.js.map +1 -0
  34. package/lib/module/types/index.js +14 -0
  35. package/lib/module/types/index.js.map +1 -0
  36. package/lib/module/types/state.types.js +23 -0
  37. package/lib/module/types/state.types.js.map +1 -0
  38. package/lib/typescript/package.json +1 -0
  39. package/lib/typescript/src/components/GestureHandler/index.d.ts +5 -0
  40. package/lib/typescript/src/components/GestureHandler/index.d.ts.map +1 -0
  41. package/lib/typescript/src/components/Reader.d.ts +4 -0
  42. package/lib/typescript/src/components/Reader.d.ts.map +1 -0
  43. package/lib/typescript/src/constants/template.d.ts +3 -0
  44. package/lib/typescript/src/constants/template.d.ts.map +1 -0
  45. package/lib/typescript/src/constants/theme.d.ts +3 -0
  46. package/lib/typescript/src/constants/theme.d.ts.map +1 -0
  47. package/lib/typescript/src/context/ReaderContext.d.ts +7 -0
  48. package/lib/typescript/src/context/ReaderContext.d.ts.map +1 -0
  49. package/lib/typescript/src/context/types.d.ts +60 -0
  50. package/lib/typescript/src/context/types.d.ts.map +1 -0
  51. package/lib/typescript/src/helpers/downloadEpub.d.ts +2 -0
  52. package/lib/typescript/src/helpers/downloadEpub.d.ts.map +1 -0
  53. package/lib/typescript/src/helpers/loadScripts.d.ts +2 -0
  54. package/lib/typescript/src/helpers/loadScripts.d.ts.map +1 -0
  55. package/lib/typescript/src/helpers/saveTemplateToFile.d.ts +3 -0
  56. package/lib/typescript/src/helpers/saveTemplateToFile.d.ts.map +1 -0
  57. package/lib/typescript/src/helpers/webViewInjectFunctions.d.ts +4 -0
  58. package/lib/typescript/src/helpers/webViewInjectFunctions.d.ts.map +1 -0
  59. package/lib/typescript/src/hooks/useInjectWebviewVariables.d.ts +12 -0
  60. package/lib/typescript/src/hooks/useInjectWebviewVariables.d.ts.map +1 -0
  61. package/lib/typescript/src/hooks/useReaderState.d.ts +6 -0
  62. package/lib/typescript/src/hooks/useReaderState.d.ts.map +1 -0
  63. package/lib/typescript/src/index.d.ts +4 -0
  64. package/lib/typescript/src/index.d.ts.map +1 -0
  65. package/lib/typescript/src/scripts/epub.d.ts +3 -0
  66. package/lib/typescript/src/scripts/epub.d.ts.map +1 -0
  67. package/lib/typescript/src/scripts/jszip.d.ts +3 -0
  68. package/lib/typescript/src/scripts/jszip.d.ts.map +1 -0
  69. package/lib/typescript/src/types/index.d.ts +72 -0
  70. package/lib/typescript/src/types/index.d.ts.map +1 -0
  71. package/lib/typescript/src/types/state.types.d.ts +83 -0
  72. package/lib/typescript/src/types/state.types.d.ts.map +1 -0
  73. package/package.json +171 -0
  74. package/src/components/GestureHandler/index.tsx +63 -0
  75. package/src/components/Reader.tsx +262 -0
  76. package/src/constants/template.ts +399 -0
  77. package/src/constants/theme.ts +42 -0
  78. package/src/context/ReaderContext.tsx +265 -0
  79. package/src/context/types.ts +62 -0
  80. package/src/helpers/downloadEpub.ts +21 -0
  81. package/src/helpers/loadScripts.ts +22 -0
  82. package/src/helpers/saveTemplateToFile.ts +20 -0
  83. package/src/helpers/webViewInjectFunctions.ts +18 -0
  84. package/src/hooks/useInjectWebviewVariables.ts +51 -0
  85. package/src/hooks/useReaderState.ts +118 -0
  86. package/src/index.tsx +3 -0
  87. package/src/scripts/epub.ts +14323 -0
  88. package/src/scripts/jszip.ts +6643 -0
  89. package/src/types/index.ts +83 -0
  90. package/src/types/state.types.ts +86 -0
@@ -0,0 +1,83 @@
1
+ import type {
2
+ GestureUpdateEvent,
3
+ PinchGestureHandlerEventPayload,
4
+ } from 'react-native-gesture-handler';
5
+
6
+ export interface LocationChangeData {
7
+ totalLocations: number;
8
+ currentLocation: Location;
9
+ progress: number;
10
+ currentSection: Section | null;
11
+ }
12
+
13
+ export type Location = {
14
+ atStart?: boolean;
15
+ atEnd?: boolean;
16
+ end: {
17
+ cfi: ePubCfi;
18
+ displayed: {
19
+ page: number;
20
+ total: number;
21
+ };
22
+ href: string;
23
+ index: number;
24
+ location: number;
25
+ percentage: number;
26
+ };
27
+ start: {
28
+ cfi: ePubCfi;
29
+ displayed: {
30
+ page: number;
31
+ total: number;
32
+ };
33
+ href: string;
34
+ index: number;
35
+ location: number;
36
+ percentage: number;
37
+ };
38
+ };
39
+
40
+ export type Section = {
41
+ id: string;
42
+ href: string;
43
+ label: string;
44
+ parent?: any;
45
+ subitems: any[];
46
+ };
47
+
48
+ /**
49
+ * @example
50
+ * ````
51
+ * epubcfi(/6/6!/4/2,/2/2/1:0,/4[q1]/2/14/2/1:14)
52
+ * ````
53
+ */
54
+ export type ePubCfi = string;
55
+
56
+ export enum SourceType {
57
+ EPUB = 'epub',
58
+ }
59
+
60
+ export type Theme = {
61
+ [key: string]: {
62
+ [key: string]: string;
63
+ };
64
+ };
65
+
66
+ export interface GestureHandlerProps {
67
+ onSwipeLeft?: () => void;
68
+ onSwipeRight?: () => void;
69
+ onTap?: () => void;
70
+ onPinch?: (e: GestureUpdateEvent<PinchGestureHandlerEventPayload>) => void;
71
+ }
72
+
73
+ export type ReaderProps = {
74
+ src: string;
75
+ initialLocation?: string;
76
+ onLocationChange?: (data: LocationChangeData) => void;
77
+ onLocationsReady?: (epubKey: string, locations: ePubCfi[]) => void;
78
+ onFinish?: () => void;
79
+ onBeginning?: () => void;
80
+ LoaderComponent?: React.ComponentType;
81
+ } & GestureHandlerProps;
82
+
83
+ export type Flow = 'paginated' | 'scrolled-doc';
@@ -0,0 +1,86 @@
1
+ import type { ePubCfi, Flow, Location, Section, Theme } from './index';
2
+
3
+ export enum Actions {
4
+ CHANGE_FONT_SIZE = 'CHANGE_FONT_SIZE',
5
+ SET_AT_START = 'SET_AT_START',
6
+ SET_AT_END = 'SET_AT_END',
7
+ SET_KEY = 'SET_KEY',
8
+ SET_TOTAL_LOCATIONS = 'SET_TOTAL_LOCATIONS',
9
+ SET_CURRENT_LOCATION = 'SET_CURRENT_LOCATION',
10
+ SET_META = 'SET_META',
11
+ SET_PROGRESS = 'SET_PROGRESS',
12
+ SET_LOCATIONS = 'SET_LOCATIONS',
13
+ SET_IS_LOADING = 'SET_IS_LOADING',
14
+ SET_IS_RENDERING = 'SET_IS_RENDERING',
15
+ SET_SECTION = 'SET_SECTION',
16
+ SET_TOC = 'SET_TOC',
17
+ SET_LANDMARKS = 'SET_LANDMARKS',
18
+ SET_FLOW = 'SET_FLOW',
19
+ CHANGE_THEME = 'CHANGE_THEME',
20
+ CHANGE_FONT_FAMILY = 'CHANGE_FONT_FAMILY',
21
+ }
22
+
23
+ type BookPayload = {
24
+ [Actions.CHANGE_THEME]: Theme;
25
+ [Actions.CHANGE_FONT_SIZE]: string;
26
+ [Actions.SET_AT_START]: boolean;
27
+ [Actions.SET_AT_END]: boolean;
28
+ [Actions.SET_KEY]: string;
29
+ [Actions.SET_TOTAL_LOCATIONS]: number;
30
+ [Actions.SET_CURRENT_LOCATION]: Location;
31
+ [Actions.SET_META]: {
32
+ cover: string | ArrayBuffer | null | undefined;
33
+ author: string;
34
+ title: string;
35
+ description: string;
36
+ language: string;
37
+ publisher: string;
38
+ rights: string;
39
+ };
40
+ [Actions.SET_PROGRESS]: number;
41
+ [Actions.SET_LOCATIONS]: ePubCfi[];
42
+ [Actions.SET_IS_LOADING]: boolean;
43
+ [Actions.SET_IS_RENDERING]: boolean;
44
+ [Actions.SET_SECTION]: Section | null;
45
+ [Actions.SET_FLOW]: Flow;
46
+ [Actions.CHANGE_FONT_FAMILY]: string;
47
+ };
48
+
49
+ type ActionMap<M extends { [index: string]: unknown }> = {
50
+ [Key in keyof M]: M[Key] extends undefined
51
+ ? {
52
+ type: Key;
53
+ }
54
+ : {
55
+ type: Key;
56
+ payload: M[Key];
57
+ };
58
+ };
59
+
60
+ export type BookActions = ActionMap<BookPayload>[keyof ActionMap<BookPayload>];
61
+
62
+ export type InitialState = {
63
+ theme: Theme;
64
+ fontFamily: string;
65
+ fontSize: string;
66
+ atStart: boolean;
67
+ atEnd: boolean;
68
+ key: string;
69
+ totalLocations: number;
70
+ currentLocation: Location | null;
71
+ meta: {
72
+ cover: string | ArrayBuffer | null | undefined;
73
+ author: string;
74
+ title: string;
75
+ description: string;
76
+ language: string;
77
+ publisher: string;
78
+ rights: string;
79
+ };
80
+ progress: number;
81
+ locations: ePubCfi[];
82
+ isLoading: boolean;
83
+ isRendering: boolean;
84
+ section: Section | null;
85
+ flow: Flow;
86
+ };