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.
- package/LICENSE +20 -0
- package/README.md +37 -0
- package/lib/module/components/GestureHandler/index.js +39 -0
- package/lib/module/components/GestureHandler/index.js.map +1 -0
- package/lib/module/components/Reader.js +207 -0
- package/lib/module/components/Reader.js.map +1 -0
- package/lib/module/constants/template.js +402 -0
- package/lib/module/constants/template.js.map +1 -0
- package/lib/module/constants/theme.js +43 -0
- package/lib/module/constants/theme.js.map +1 -0
- package/lib/module/context/ReaderContext.js +213 -0
- package/lib/module/context/ReaderContext.js.map +1 -0
- package/lib/module/context/types.js +4 -0
- package/lib/module/context/types.js.map +1 -0
- package/lib/module/helpers/downloadEpub.js +17 -0
- package/lib/module/helpers/downloadEpub.js.map +1 -0
- package/lib/module/helpers/loadScripts.js +21 -0
- package/lib/module/helpers/loadScripts.js.map +1 -0
- package/lib/module/helpers/saveTemplateToFile.js +21 -0
- package/lib/module/helpers/saveTemplateToFile.js.map +1 -0
- package/lib/module/helpers/webViewInjectFunctions.js +14 -0
- package/lib/module/helpers/webViewInjectFunctions.js.map +1 -0
- package/lib/module/hooks/useInjectWebviewVariables.js +20 -0
- package/lib/module/hooks/useInjectWebviewVariables.js.map +1 -0
- package/lib/module/hooks/useReaderState.js +117 -0
- package/lib/module/hooks/useReaderState.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/scripts/epub.js +14326 -0
- package/lib/module/scripts/epub.js.map +1 -0
- package/lib/module/scripts/jszip.js +6646 -0
- package/lib/module/scripts/jszip.js.map +1 -0
- package/lib/module/types/index.js +14 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/types/state.types.js +23 -0
- package/lib/module/types/state.types.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/components/GestureHandler/index.d.ts +5 -0
- package/lib/typescript/src/components/GestureHandler/index.d.ts.map +1 -0
- package/lib/typescript/src/components/Reader.d.ts +4 -0
- package/lib/typescript/src/components/Reader.d.ts.map +1 -0
- package/lib/typescript/src/constants/template.d.ts +3 -0
- package/lib/typescript/src/constants/template.d.ts.map +1 -0
- package/lib/typescript/src/constants/theme.d.ts +3 -0
- package/lib/typescript/src/constants/theme.d.ts.map +1 -0
- package/lib/typescript/src/context/ReaderContext.d.ts +7 -0
- package/lib/typescript/src/context/ReaderContext.d.ts.map +1 -0
- package/lib/typescript/src/context/types.d.ts +60 -0
- package/lib/typescript/src/context/types.d.ts.map +1 -0
- package/lib/typescript/src/helpers/downloadEpub.d.ts +2 -0
- package/lib/typescript/src/helpers/downloadEpub.d.ts.map +1 -0
- package/lib/typescript/src/helpers/loadScripts.d.ts +2 -0
- package/lib/typescript/src/helpers/loadScripts.d.ts.map +1 -0
- package/lib/typescript/src/helpers/saveTemplateToFile.d.ts +3 -0
- package/lib/typescript/src/helpers/saveTemplateToFile.d.ts.map +1 -0
- package/lib/typescript/src/helpers/webViewInjectFunctions.d.ts +4 -0
- package/lib/typescript/src/helpers/webViewInjectFunctions.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useInjectWebviewVariables.d.ts +12 -0
- package/lib/typescript/src/hooks/useInjectWebviewVariables.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useReaderState.d.ts +6 -0
- package/lib/typescript/src/hooks/useReaderState.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/scripts/epub.d.ts +3 -0
- package/lib/typescript/src/scripts/epub.d.ts.map +1 -0
- package/lib/typescript/src/scripts/jszip.d.ts +3 -0
- package/lib/typescript/src/scripts/jszip.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +72 -0
- package/lib/typescript/src/types/index.d.ts.map +1 -0
- package/lib/typescript/src/types/state.types.d.ts +83 -0
- package/lib/typescript/src/types/state.types.d.ts.map +1 -0
- package/package.json +171 -0
- package/src/components/GestureHandler/index.tsx +63 -0
- package/src/components/Reader.tsx +262 -0
- package/src/constants/template.ts +399 -0
- package/src/constants/theme.ts +42 -0
- package/src/context/ReaderContext.tsx +265 -0
- package/src/context/types.ts +62 -0
- package/src/helpers/downloadEpub.ts +21 -0
- package/src/helpers/loadScripts.ts +22 -0
- package/src/helpers/saveTemplateToFile.ts +20 -0
- package/src/helpers/webViewInjectFunctions.ts +18 -0
- package/src/hooks/useInjectWebviewVariables.ts +51 -0
- package/src/hooks/useReaderState.ts +118 -0
- package/src/index.tsx +3 -0
- package/src/scripts/epub.ts +14323 -0
- package/src/scripts/jszip.ts +6643 -0
- package/src/types/index.ts +83 -0
- 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
|
+
};
|