aksos-react-native-epub-reader 0.0.0-stage → 0.1.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 (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +351 -2
  3. package/lib/EpubReader.d.ts +76 -0
  4. package/lib/EpubReader.js +284 -0
  5. package/lib/EpubReaderView.d.ts +31 -0
  6. package/lib/EpubReaderView.js +599 -0
  7. package/lib/assets/page-turn-1.wav +0 -0
  8. package/lib/assets/page-turn-2.wav +0 -0
  9. package/lib/assets/page-turn-3.wav +0 -0
  10. package/lib/assets/page-turn-4.wav +0 -0
  11. package/lib/engine/html.d.ts +1 -0
  12. package/lib/engine/html.js +5 -0
  13. package/lib/index.d.ts +9 -0
  14. package/lib/index.js +34 -0
  15. package/lib/sound.d.ts +1 -0
  16. package/lib/sound.js +71 -0
  17. package/lib/strings.d.ts +94 -0
  18. package/lib/strings.js +96 -0
  19. package/lib/themes.d.ts +60 -0
  20. package/lib/themes.js +166 -0
  21. package/lib/types.d.ts +149 -0
  22. package/lib/types.js +2 -0
  23. package/lib/ui/AppearanceSheet.d.ts +15 -0
  24. package/lib/ui/AppearanceSheet.js +134 -0
  25. package/lib/ui/ContentsSheet.d.ts +27 -0
  26. package/lib/ui/ContentsSheet.js +89 -0
  27. package/lib/ui/CustomizeSheet.d.ts +16 -0
  28. package/lib/ui/CustomizeSheet.js +141 -0
  29. package/lib/ui/Glass.d.ts +15 -0
  30. package/lib/ui/Glass.js +27 -0
  31. package/lib/ui/HighlightMenu.d.ts +25 -0
  32. package/lib/ui/HighlightMenu.js +45 -0
  33. package/lib/ui/Icons.d.ts +17 -0
  34. package/lib/ui/Icons.js +193 -0
  35. package/lib/ui/LineGuide.d.ts +21 -0
  36. package/lib/ui/LineGuide.js +92 -0
  37. package/lib/ui/NoteEditor.d.ts +12 -0
  38. package/lib/ui/NoteEditor.js +63 -0
  39. package/lib/ui/Scrubber.d.ts +15 -0
  40. package/lib/ui/Scrubber.js +86 -0
  41. package/lib/ui/SearchSheet.d.ts +14 -0
  42. package/lib/ui/SearchSheet.js +79 -0
  43. package/lib/ui/Sheet.d.ts +19 -0
  44. package/lib/ui/Sheet.js +40 -0
  45. package/lib/ui/Slider.d.ts +14 -0
  46. package/lib/ui/Slider.js +53 -0
  47. package/package.json +76 -6
  48. package/src/EpubReader.tsx +356 -0
  49. package/src/EpubReaderView.tsx +865 -0
  50. package/src/assets/page-turn-1.wav +0 -0
  51. package/src/assets/page-turn-2.wav +0 -0
  52. package/src/assets/page-turn-3.wav +0 -0
  53. package/src/assets/page-turn-4.wav +0 -0
  54. package/src/engine/html.ts +2 -0
  55. package/src/engine/reader.js +2047 -0
  56. package/src/index.ts +9 -0
  57. package/src/sound.ts +66 -0
  58. package/src/strings.ts +187 -0
  59. package/src/themes.ts +188 -0
  60. package/src/types.ts +154 -0
  61. package/src/ui/AppearanceSheet.tsx +176 -0
  62. package/src/ui/ContentsSheet.tsx +146 -0
  63. package/src/ui/CustomizeSheet.tsx +191 -0
  64. package/src/ui/Glass.tsx +37 -0
  65. package/src/ui/HighlightMenu.tsx +66 -0
  66. package/src/ui/Icons.tsx +246 -0
  67. package/src/ui/LineGuide.tsx +87 -0
  68. package/src/ui/NoteEditor.tsx +57 -0
  69. package/src/ui/Scrubber.tsx +78 -0
  70. package/src/ui/SearchSheet.tsx +95 -0
  71. package/src/ui/Sheet.tsx +71 -0
  72. package/src/ui/Slider.tsx +30 -0
package/lib/sound.js ADDED
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.playPageTurn = playPageTurn;
4
+ // Page-turn sound: real recorded page flips (see README for credit), a different one each turn.
5
+ // expo-audio is optional: without it the reader is simply silent.
6
+ //
7
+ // One player per recording, and every play first waits for the rewind to finish.
8
+ // (Calling play() right after an un-awaited seekTo(0) on a player that already finished plays nothing.)
9
+ let audio = null;
10
+ let missing = false;
11
+ let players = [];
12
+ let last = -1;
13
+ let modeSet = false;
14
+ function sources() {
15
+ // static requires so the bundler can find the assets
16
+ return [
17
+ require('./assets/page-turn-1.wav'),
18
+ require('./assets/page-turn-2.wav'),
19
+ require('./assets/page-turn-3.wav'),
20
+ require('./assets/page-turn-4.wav')
21
+ ];
22
+ }
23
+ function load() {
24
+ if (audio)
25
+ return true;
26
+ if (missing)
27
+ return false;
28
+ try {
29
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
30
+ audio = require('expo-audio');
31
+ return true;
32
+ }
33
+ catch {
34
+ missing = true;
35
+ return false;
36
+ }
37
+ }
38
+ function player(i) {
39
+ if (!players[i]) {
40
+ players[i] = audio.createAudioPlayer(sources()[i]);
41
+ players[i].volume = 0.7;
42
+ }
43
+ return players[i];
44
+ }
45
+ function playPageTurn() {
46
+ if (!load())
47
+ return;
48
+ try {
49
+ if (!modeSet) {
50
+ modeSet = true;
51
+ // do not stop the user's music, and follow the silent switch
52
+ Promise.resolve(audio.setAudioModeAsync?.({ playsInSilentMode: false, interruptionMode: 'mixWithOthers' })).catch(() => undefined);
53
+ }
54
+ // random recording, never the same one twice in a row
55
+ let i = Math.floor(Math.random() * 4);
56
+ if (i === last)
57
+ i = (i + 1) % 4;
58
+ last = i;
59
+ const p = player(i);
60
+ Promise.resolve(p.seekTo(0))
61
+ .catch(() => undefined)
62
+ .then(() => p.play())
63
+ .catch(() => {
64
+ // a broken player is replaced on its next use
65
+ players = [];
66
+ });
67
+ }
68
+ catch {
69
+ players = [];
70
+ }
71
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Every text the reader shows. Pass a partial object as the `labels` prop of EpubReaderView to translate
3
+ * (for example into Pashto, Dari or Arabic); anything you leave out stays English.
4
+ */
5
+ export interface ReaderLabels {
6
+ contents: string;
7
+ chapters: string;
8
+ font: string;
9
+ lineSpacing: string;
10
+ characterSpacing: string;
11
+ wordSpacing: string;
12
+ margins: string;
13
+ columns: string;
14
+ columnsAuto: string;
15
+ columnsOne: string;
16
+ columnsTwo: string;
17
+ slide: string;
18
+ curl: string;
19
+ fastFade: string;
20
+ scrollMode: string;
21
+ light: string;
22
+ dark: string;
23
+ matchDevice: string;
24
+ matchSurroundings: string;
25
+ appearance: string;
26
+ pageTurnStyle: string;
27
+ delete: string;
28
+ deleteBookmark: string;
29
+ deleteHighlight: string;
30
+ search: string;
31
+ searchBook: string;
32
+ searchInBook: string;
33
+ searching: string;
34
+ noResults: string;
35
+ themesSettings: string;
36
+ customizeTheme: string;
37
+ customize: string;
38
+ resetTheme: string;
39
+ boldText: string;
40
+ justifyText: string;
41
+ pageTurnSound: string;
42
+ accessibilityLayout: string;
43
+ smallerText: string;
44
+ largerText: string;
45
+ readerMenu: string;
46
+ closeBook: string;
47
+ share: string;
48
+ rotationLock: string;
49
+ rotationLockNeedsPackage: string;
50
+ lineGuide: string;
51
+ turnOffLineGuide: string;
52
+ backgroundDimming: string;
53
+ dimHigh: string;
54
+ dimMedium: string;
55
+ dimLow: string;
56
+ dimNone: string;
57
+ bookmarkPage: string;
58
+ highlight: string;
59
+ note: string;
60
+ addNote: string;
61
+ addANote: string;
62
+ underline: string;
63
+ removeHighlight: string;
64
+ dismiss: string;
65
+ done: string;
66
+ close: string;
67
+ cancel: string;
68
+ save: string;
69
+ ok: string;
70
+ noToc: string;
71
+ noBookmarks: string;
72
+ noHighlights: string;
73
+ bookmarks: string;
74
+ highlights: string;
75
+ loading: string;
76
+ couldNotOpen: string;
77
+ tryAgain: string;
78
+ openLink: string;
79
+ open: string;
80
+ lastPageInChapter: string;
81
+ /** "N pages left in chapter" */
82
+ pagesLeft: (n: number) => string;
83
+ /** "3 of 120" */
84
+ pageOfTotal: (page: number, total: number) => string;
85
+ /** "Page 3 of 120" */
86
+ pageOfTotalLong: (page: number, total: number) => string;
87
+ returnToPage: (page: number) => string;
88
+ /** how numbers are written (e.g. Arabic-Indic digits for an Arabic UI) */
89
+ formatNumber: (n: number) => string;
90
+ }
91
+ export declare const DEFAULT_LABELS: ReaderLabels;
92
+ export declare const LabelsProvider: import("react").Provider<ReaderLabels>;
93
+ export declare function useLabels(): ReaderLabels;
94
+ export declare function mergeLabels(partial?: Partial<ReaderLabels>): ReaderLabels;
package/lib/strings.js ADDED
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LabelsProvider = exports.DEFAULT_LABELS = void 0;
4
+ exports.useLabels = useLabels;
5
+ exports.mergeLabels = mergeLabels;
6
+ const react_1 = require("react");
7
+ exports.DEFAULT_LABELS = {
8
+ contents: 'Contents',
9
+ chapters: 'Chapters',
10
+ font: 'Font',
11
+ lineSpacing: 'LINE SPACING',
12
+ characterSpacing: 'CHARACTER SPACING',
13
+ wordSpacing: 'WORD SPACING',
14
+ margins: 'MARGINS',
15
+ columns: 'Columns',
16
+ columnsAuto: 'Auto Set',
17
+ columnsOne: 'One',
18
+ columnsTwo: 'Two',
19
+ slide: 'Slide',
20
+ curl: 'Curl',
21
+ fastFade: 'Fast Fade',
22
+ scrollMode: 'Scroll',
23
+ light: 'Light',
24
+ dark: 'Dark',
25
+ matchDevice: 'Match Device',
26
+ matchSurroundings: 'Match Surroundings',
27
+ appearance: 'Appearance',
28
+ pageTurnStyle: 'Page turn style',
29
+ delete: 'Delete',
30
+ deleteBookmark: 'Delete bookmark?',
31
+ deleteHighlight: 'Delete highlight?',
32
+ search: 'Search',
33
+ searchBook: 'Search Book',
34
+ searchInBook: 'Search in book',
35
+ searching: 'Searching…',
36
+ noResults: 'No results',
37
+ themesSettings: 'Themes & Settings',
38
+ customizeTheme: 'Customize Theme',
39
+ customize: 'Customize',
40
+ resetTheme: 'Reset Theme',
41
+ boldText: 'Bold Text',
42
+ justifyText: 'Justify Text',
43
+ pageTurnSound: 'Page Turn Sound',
44
+ accessibilityLayout: 'Accessibility & Layout Options',
45
+ smallerText: 'Smaller text',
46
+ largerText: 'Larger text',
47
+ readerMenu: 'Reader menu',
48
+ closeBook: 'Close book',
49
+ share: 'Share',
50
+ rotationLock: 'Rotation lock',
51
+ rotationLockNeedsPackage: 'Install expo-screen-orientation to enable the rotation lock.',
52
+ lineGuide: 'Line guide',
53
+ turnOffLineGuide: 'Turn Off Line Guide',
54
+ backgroundDimming: 'Background Dimming',
55
+ dimHigh: 'High',
56
+ dimMedium: 'Medium',
57
+ dimLow: 'Low',
58
+ dimNone: 'None',
59
+ bookmarkPage: 'Bookmark this page',
60
+ highlight: 'Highlight',
61
+ note: 'Note',
62
+ addNote: 'Add note',
63
+ addANote: 'Add a note',
64
+ underline: 'Underline',
65
+ removeHighlight: 'Remove highlight',
66
+ dismiss: 'Dismiss',
67
+ done: 'Done',
68
+ close: 'Close',
69
+ cancel: 'Cancel',
70
+ save: 'Save',
71
+ ok: 'OK',
72
+ noToc: 'No table of contents',
73
+ noBookmarks: 'No bookmarks yet. Tap the bookmark button while reading.',
74
+ noHighlights: 'No highlights or notes yet. Select text to add one.',
75
+ bookmarks: 'Bookmarks',
76
+ highlights: 'Highlights',
77
+ loading: 'Opening book…',
78
+ couldNotOpen: 'This book could not be opened',
79
+ tryAgain: 'Try again',
80
+ openLink: 'Open this link?',
81
+ open: 'Open',
82
+ lastPageInChapter: 'Last page in chapter',
83
+ pagesLeft: (n) => `${n} page${n === 1 ? '' : 's'} left in chapter`,
84
+ pageOfTotal: (p, t) => `${p} of ${t}`,
85
+ pageOfTotalLong: (p, t) => `Page ${p} of ${t}`,
86
+ returnToPage: (p) => `Return to page ${p}`,
87
+ formatNumber: (n) => String(n)
88
+ };
89
+ const LabelsContext = (0, react_1.createContext)(exports.DEFAULT_LABELS);
90
+ exports.LabelsProvider = LabelsContext.Provider;
91
+ function useLabels() {
92
+ return (0, react_1.useContext)(LabelsContext);
93
+ }
94
+ function mergeLabels(partial) {
95
+ return partial ? { ...exports.DEFAULT_LABELS, ...partial } : exports.DEFAULT_LABELS;
96
+ }
@@ -0,0 +1,60 @@
1
+ import type { HighlightColor, ReaderFont, ReaderSettings, ReaderTheme, ThemeColors } from './types';
2
+ export declare const THEMES: ReaderTheme[];
3
+ /** Font stacks. iOS ships most of these, on Android the stacks fall back to the system serif / sans. */
4
+ export declare const FONTS: ReaderFont[];
5
+ export declare const HIGHLIGHT_COLORS: Record<HighlightColor, string>;
6
+ export declare const DEFAULT_SETTINGS: ReaderSettings;
7
+ export declare const getTheme: (id: string) => ReaderTheme;
8
+ export declare const getFont: (id: string) => ReaderFont;
9
+ export declare const serifFont: string;
10
+ export declare function isDark(settings: ReaderSettings, systemDark: boolean): boolean;
11
+ export declare function themeColors(settings: ReaderSettings, systemDark: boolean): ThemeColors;
12
+ /** Settings object understood by the WebView engine. */
13
+ export declare function toEngineSettings(settings: ReaderSettings, systemDark: boolean, insets: {
14
+ top: number;
15
+ bottom: number;
16
+ left?: number;
17
+ right?: number;
18
+ }): {
19
+ bg: string;
20
+ fg: string;
21
+ link: string;
22
+ bold: boolean;
23
+ fontFamily: string;
24
+ fontSize: number;
25
+ lineHeight: number;
26
+ letterSpacing: number;
27
+ wordSpacing: number;
28
+ marginX: number;
29
+ columns: import("./types").ColumnsSetting;
30
+ justify: boolean;
31
+ mode: import("./types").PageTurn;
32
+ direction: "auto" | "ltr" | "rtl";
33
+ insets: {
34
+ top: number;
35
+ bottom: number;
36
+ left: number;
37
+ right: number;
38
+ };
39
+ };
40
+ export interface ChromeColors {
41
+ /** translucent control background (pills, circles), tinted with the page colour */
42
+ glass: string;
43
+ glassBorder: string;
44
+ /** solid sheet colour and a translucent one for sheets that float over the book */
45
+ sheet: string;
46
+ sheetGlass: string;
47
+ /** rows / cards inside a sheet: a neutral wash that works on any theme */
48
+ card: string;
49
+ text: string;
50
+ subtext: string;
51
+ separator: string;
52
+ /** highlight for the current chapter / selected items */
53
+ accent: string;
54
+ dark: boolean;
55
+ }
56
+ /**
57
+ * Chrome (buttons, menus, sheets) is frosted glass tinted with the page colour, so a Calm page gets warm glass and a
58
+ * black page gets dark glass. Text and icons use the neutral text colour of the light / dark variant.
59
+ */
60
+ export declare function chromeColors(colors: ThemeColors, dark: boolean): ChromeColors;
package/lib/themes.js ADDED
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serifFont = exports.getFont = exports.getTheme = exports.DEFAULT_SETTINGS = exports.HIGHLIGHT_COLORS = exports.FONTS = exports.THEMES = void 0;
4
+ exports.isDark = isDark;
5
+ exports.themeColors = themeColors;
6
+ exports.toEngineSettings = toEngineSettings;
7
+ exports.chromeColors = chromeColors;
8
+ const react_native_1 = require("react-native");
9
+ exports.THEMES = [
10
+ {
11
+ id: 'original',
12
+ name: 'Original',
13
+ light: { bg: '#ffffff', fg: '#1c1c1e', link: '#0a60ff' },
14
+ dark: { bg: '#000000', fg: '#f2f2f7', link: '#64a8ff' }
15
+ },
16
+ {
17
+ id: 'quiet',
18
+ name: 'Quiet',
19
+ light: { bg: '#e8e8ea', fg: '#58585c', link: '#3a6ea5' },
20
+ dark: { bg: '#121212', fg: '#8e8e93', link: '#6c9bd1' }
21
+ },
22
+ {
23
+ id: 'paper',
24
+ name: 'Paper',
25
+ light: { bg: '#f6f0e1', fg: '#3b3226', link: '#8a5a2b' },
26
+ dark: { bg: '#1d1d1f', fg: '#e9e0cd', link: '#d6a86a' }
27
+ },
28
+ {
29
+ id: 'bold',
30
+ name: 'Bold',
31
+ bold: true,
32
+ light: { bg: '#ffffff', fg: '#000000', link: '#0a60ff' },
33
+ dark: { bg: '#000000', fg: '#ffffff', link: '#64a8ff' }
34
+ },
35
+ {
36
+ id: 'calm',
37
+ name: 'Calm',
38
+ light: { bg: '#ece1c9', fg: '#4a3f2c', link: '#7a5a1f' },
39
+ dark: { bg: '#3d372d', fg: '#f0e7d3', link: '#e0b66f' }
40
+ },
41
+ {
42
+ id: 'focus',
43
+ name: 'Focus',
44
+ light: { bg: '#f3efe2', fg: '#2d2a24', link: '#9a4b1c' },
45
+ dark: { bg: '#1a1913', fg: '#e8e2d0', link: '#d98f5a' }
46
+ }
47
+ ];
48
+ const SERIF = react_native_1.Platform.OS === 'ios' ? 'Georgia' : 'serif';
49
+ /** Font stacks. iOS ships most of these, on Android the stacks fall back to the system serif / sans. */
50
+ exports.FONTS = [
51
+ { id: 'original', name: 'Original', css: 'original' },
52
+ { id: 'system', name: 'System', css: "-apple-system, system-ui, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif" },
53
+ { id: 'newyork', name: 'New York', css: "ui-serif, 'New York', Georgia, serif" },
54
+ { id: 'athelas', name: 'Athelas', css: "Athelas, Georgia, serif" },
55
+ { id: 'charter', name: 'Charter', css: "Charter, 'Bitstream Charter', Georgia, serif" },
56
+ { id: 'georgia', name: 'Georgia', css: "Georgia, 'Times New Roman', serif" },
57
+ { id: 'iowan', name: 'Iowan', css: "'Iowan Old Style', Georgia, serif" },
58
+ { id: 'palatino', name: 'Palatino', css: "Palatino, 'Palatino Linotype', 'Book Antiqua', serif" },
59
+ { id: 'seravek', name: 'Seravek', css: "Seravek, 'Avenir Next', -apple-system, sans-serif" },
60
+ { id: 'times', name: 'Times New Roman', css: "'Times New Roman', Times, serif" },
61
+ { id: 'naskh', name: 'Naskh (عربي / پښتو)', css: "'Noto Naskh Arabic', 'Geeza Pro', 'Droid Arabic Naskh', 'Scheherazade New', serif" }
62
+ ];
63
+ exports.HIGHLIGHT_COLORS = {
64
+ yellow: '#ffd60a',
65
+ green: '#34c759',
66
+ blue: '#0a84ff',
67
+ pink: '#ff375f',
68
+ purple: '#bf5af2'
69
+ };
70
+ exports.DEFAULT_SETTINGS = {
71
+ themeId: 'original',
72
+ appearance: 'device',
73
+ fontId: 'original',
74
+ fontSize: 19,
75
+ bold: false,
76
+ customize: false,
77
+ lineHeight: 1.5,
78
+ letterSpacing: 0,
79
+ wordSpacing: 0,
80
+ margins: 0,
81
+ columns: 'auto',
82
+ justify: false,
83
+ pageTurn: 'slide',
84
+ pageSound: true,
85
+ brightness: 1,
86
+ direction: 'auto'
87
+ };
88
+ const getTheme = (id) => exports.THEMES.find((t) => t.id === id) || exports.THEMES[0];
89
+ exports.getTheme = getTheme;
90
+ const getFont = (id) => exports.FONTS.find((f) => f.id === id) || exports.FONTS[0];
91
+ exports.getFont = getFont;
92
+ exports.serifFont = SERIF;
93
+ function isDark(settings, systemDark) {
94
+ return settings.appearance === 'device' ? systemDark : settings.appearance === 'dark';
95
+ }
96
+ function themeColors(settings, systemDark) {
97
+ const t = (0, exports.getTheme)(settings.themeId);
98
+ return isDark(settings, systemDark) ? t.dark : t.light;
99
+ }
100
+ const BASE_MARGIN = 28;
101
+ /** Settings object understood by the WebView engine. */
102
+ function toEngineSettings(settings, systemDark, insets) {
103
+ const theme = (0, exports.getTheme)(settings.themeId);
104
+ const c = themeColors(settings, systemDark);
105
+ const custom = settings.customize;
106
+ return {
107
+ bg: c.bg,
108
+ fg: c.fg,
109
+ link: c.link,
110
+ bold: !!theme.bold || settings.bold,
111
+ fontFamily: (0, exports.getFont)(settings.fontId).css,
112
+ fontSize: settings.fontSize,
113
+ lineHeight: custom ? settings.lineHeight : 1.5,
114
+ letterSpacing: custom ? (settings.letterSpacing / 100) * 0.25 : 0,
115
+ wordSpacing: custom ? (settings.wordSpacing / 100) * 0.5 : 0,
116
+ marginX: Math.round(BASE_MARGIN * (1 + (custom ? settings.margins : 0) / 100)),
117
+ columns: settings.columns,
118
+ justify: settings.justify,
119
+ mode: settings.pageTurn,
120
+ direction: settings.direction,
121
+ insets: { top: insets.top + 40, bottom: insets.bottom + 40, left: insets.left || 0, right: insets.right || 0 }
122
+ };
123
+ }
124
+ function mix(hex, other, amount) {
125
+ const p = (h) => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16));
126
+ const a = p(hex);
127
+ const b = p(other);
128
+ const m = a.map((v, i) => Math.round(v + (b[i] - v) * amount));
129
+ return '#' + m.map((v) => v.toString(16).padStart(2, '0')).join('');
130
+ }
131
+ function rgba(hex, alpha) {
132
+ const v = [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16));
133
+ return `rgba(${v[0]},${v[1]},${v[2]},${alpha})`;
134
+ }
135
+ /**
136
+ * Chrome (buttons, menus, sheets) is frosted glass tinted with the page colour, so a Calm page gets warm glass and a
137
+ * black page gets dark glass. Text and icons use the neutral text colour of the light / dark variant.
138
+ */
139
+ function chromeColors(colors, dark) {
140
+ if (dark) {
141
+ return {
142
+ glass: rgba(mix(colors.bg, '#ffffff', 0.22), 0.4),
143
+ glassBorder: 'rgba(255,255,255,0.16)',
144
+ sheet: mix(colors.bg, '#ffffff', 0.1),
145
+ sheetGlass: rgba(mix(colors.bg, '#ffffff', 0.1), 0.84),
146
+ card: 'rgba(255,255,255,0.1)',
147
+ text: '#ffffff',
148
+ subtext: '#a09d96',
149
+ separator: 'rgba(255,255,255,0.14)',
150
+ accent: '#ffb340',
151
+ dark
152
+ };
153
+ }
154
+ return {
155
+ glass: rgba(mix(colors.bg, '#ffffff', 0.55), 0.5),
156
+ glassBorder: 'rgba(0,0,0,0.1)',
157
+ sheet: mix(colors.bg, '#ffffff', 0.5),
158
+ sheetGlass: rgba(mix(colors.bg, '#ffffff', 0.5), 0.86),
159
+ card: 'rgba(0,0,0,0.06)',
160
+ text: '#000000',
161
+ subtext: '#6c6c70',
162
+ separator: 'rgba(0,0,0,0.14)',
163
+ accent: '#ff9500',
164
+ dark
165
+ };
166
+ }
package/lib/types.d.ts ADDED
@@ -0,0 +1,149 @@
1
+ export type HighlightColor = 'yellow' | 'green' | 'blue' | 'pink' | 'purple';
2
+ export type HighlightStyle = 'highlight' | 'underline';
3
+ /** Position in the book. Offsets are text-character offsets inside the spine item, so they survive font/size changes. */
4
+ export interface BookLocation {
5
+ spine: number;
6
+ offset: number;
7
+ }
8
+ export interface Highlight {
9
+ id: string;
10
+ spine: number;
11
+ start: number;
12
+ end: number;
13
+ text: string;
14
+ color: HighlightColor;
15
+ style?: HighlightStyle;
16
+ note?: string;
17
+ chapter?: string;
18
+ createdAt: number;
19
+ }
20
+ export interface Bookmark {
21
+ id: string;
22
+ spine: number;
23
+ offset: number;
24
+ chapter: string;
25
+ excerpt: string;
26
+ progress: number;
27
+ createdAt: number;
28
+ }
29
+ export interface TocItem {
30
+ label: string;
31
+ spine: number;
32
+ fragment: string;
33
+ level: number;
34
+ }
35
+ export interface BookMetadata {
36
+ title: string;
37
+ author: string;
38
+ language: string;
39
+ publisher: string;
40
+ }
41
+ export interface RelocateEvent {
42
+ spine: number;
43
+ /** offset of the first character on the page */
44
+ offset: number;
45
+ /** offset just past the last character on the page */
46
+ end: number;
47
+ page: number;
48
+ pageCount: number;
49
+ spineCount: number;
50
+ /** number of characters in this spine item */
51
+ textLength: number;
52
+ /** 0..1 across the whole book (exact once `indexed` is true) */
53
+ progress: number;
54
+ chapter: string;
55
+ excerpt: string;
56
+ indexed: boolean;
57
+ }
58
+ export interface SelectionEvent {
59
+ spine: number;
60
+ start: number;
61
+ end: number;
62
+ text: string;
63
+ rect: {
64
+ x: number;
65
+ y: number;
66
+ width: number;
67
+ height: number;
68
+ };
69
+ }
70
+ export interface SearchResult {
71
+ spine: number;
72
+ offset: number;
73
+ length: number;
74
+ chapter: string;
75
+ before: string;
76
+ match: string;
77
+ after: string;
78
+ }
79
+ export interface ThemeColors {
80
+ /** page background */
81
+ bg: string;
82
+ /** body text */
83
+ fg: string;
84
+ link: string;
85
+ }
86
+ /** A theme has a light and a dark variant, like the themes in Apple Books. */
87
+ export interface ReaderTheme {
88
+ id: string;
89
+ name: string;
90
+ light: ThemeColors;
91
+ dark: ThemeColors;
92
+ bold?: boolean;
93
+ }
94
+ export type Appearance = 'light' | 'dark' | 'device';
95
+ export type PageTurn = 'slide' | 'curl' | 'fade' | 'scroll';
96
+ export type ColumnsSetting = 'auto' | 1 | 2;
97
+ export interface ReaderFont {
98
+ id: string;
99
+ name: string;
100
+ /** CSS font-family, or 'original' to keep the book's own fonts */
101
+ css: string;
102
+ }
103
+ export interface ReaderSettings {
104
+ themeId: string;
105
+ appearance: Appearance;
106
+ fontId: string;
107
+ fontSize: number;
108
+ /** extra bold weight on top of the theme's own */
109
+ bold: boolean;
110
+ /** when false the spacing values below are ignored (defaults are used) */
111
+ customize: boolean;
112
+ lineHeight: number;
113
+ /** percent, 0 = default */
114
+ letterSpacing: number;
115
+ /** percent, 0 = default */
116
+ wordSpacing: number;
117
+ /** percent change of the side margins, 0 = default */
118
+ margins: number;
119
+ columns: ColumnsSetting;
120
+ justify: boolean;
121
+ pageTurn: PageTurn;
122
+ /** paper sound when a page is turned (Curl) */
123
+ pageSound: boolean;
124
+ /** 0.3 .. 1, dims the page like the Books brightness slider */
125
+ brightness: number;
126
+ /** 'auto' follows the book's page-progression-direction / language */
127
+ direction: 'auto' | 'ltr' | 'rtl';
128
+ }
129
+ /**
130
+ * Where the book comes from.
131
+ * - uri: file://, content:// (Android), https://, or an asset/bundle URI that fetch() can read. `headers` are sent with the request.
132
+ * - base64: the EPUB bytes as base64 (a data: prefix is accepted).
133
+ * `key` identifies the book: when it changes the reader opens the new source. Defaults to the uri, or to a fingerprint of the data.
134
+ */
135
+ export type EpubSource = {
136
+ uri: string;
137
+ headers?: Record<string, string>;
138
+ key?: string;
139
+ } | {
140
+ base64: string;
141
+ key?: string;
142
+ };
143
+ /** Safe-area space around the page, in points. Left/right matter in landscape on notched phones. */
144
+ export interface SafeInsets {
145
+ top: number;
146
+ bottom: number;
147
+ left?: number;
148
+ right?: number;
149
+ }
package/lib/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import type { ChromeColors } from '../themes';
3
+ import type { ReaderSettings } from '../types';
4
+ interface Props {
5
+ visible: boolean;
6
+ colors: ChromeColors;
7
+ settings: ReaderSettings;
8
+ systemDark: boolean;
9
+ onChange: (patch: Partial<ReaderSettings>) => void;
10
+ onCustomize: () => void;
11
+ onClose: () => void;
12
+ }
13
+ /** "Themes & Settings" sheet. */
14
+ export declare function AppearanceSheet({ visible, colors, settings: s, systemDark, onChange, onCustomize, onClose }: Props): React.JSX.Element;
15
+ export {};