aksos-react-native-epub-reader 0.1.1 → 0.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 (44) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +158 -13
  3. package/lib/EpubReader.d.ts +47 -9
  4. package/lib/EpubReader.js +69 -16
  5. package/lib/EpubReaderView.d.ts +27 -2
  6. package/lib/EpubReaderView.js +38 -32
  7. package/lib/cfiOrder.d.ts +2 -0
  8. package/lib/cfiOrder.js +34 -0
  9. package/lib/engine/html.js +1 -1
  10. package/lib/index.d.ts +1 -1
  11. package/lib/themes.d.ts +24 -6
  12. package/lib/themes.js +80 -20
  13. package/lib/types.d.ts +66 -1
  14. package/lib/ui/AppearanceSheet.d.ts +4 -2
  15. package/lib/ui/AppearanceSheet.js +20 -13
  16. package/lib/ui/ContentsSheet.d.ts +2 -0
  17. package/lib/ui/ContentsSheet.js +21 -13
  18. package/lib/ui/CustomizeSheet.d.ts +4 -2
  19. package/lib/ui/CustomizeSheet.js +20 -18
  20. package/lib/ui/HighlightMenu.d.ts +4 -2
  21. package/lib/ui/HighlightMenu.js +3 -3
  22. package/lib/ui/NoteEditor.js +6 -5
  23. package/lib/ui/SearchSheet.js +6 -5
  24. package/lib/ui/Sheet.js +5 -4
  25. package/lib/ui/Text.d.ts +9 -0
  26. package/lib/ui/Text.js +62 -0
  27. package/package.json +81 -76
  28. package/src/EpubReader.tsx +121 -25
  29. package/src/EpubReaderView.tsx +61 -17
  30. package/src/cfiOrder.ts +28 -0
  31. package/src/engine/epubcfi.js +527 -0
  32. package/src/engine/html.ts +1 -1
  33. package/src/engine/reader.js +830 -65
  34. package/src/index.ts +1 -1
  35. package/src/themes.ts +97 -21
  36. package/src/types.ts +71 -1
  37. package/src/ui/AppearanceSheet.tsx +19 -10
  38. package/src/ui/ContentsSheet.tsx +14 -4
  39. package/src/ui/CustomizeSheet.tsx +14 -10
  40. package/src/ui/HighlightMenu.tsx +6 -4
  41. package/src/ui/NoteEditor.tsx +2 -1
  42. package/src/ui/SearchSheet.tsx +2 -1
  43. package/src/ui/Sheet.tsx +4 -3
  44. package/src/ui/Text.tsx +27 -0
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.EpubReaderView = EpubReaderView;
37
37
  const react_1 = __importStar(require("react"));
38
38
  const react_native_1 = require("react-native");
39
+ const Text_1 = require("./ui/Text");
39
40
  const EpubReader_1 = require("./EpubReader");
40
41
  const themes_1 = require("./themes");
41
42
  const AppearanceSheet_1 = require("./ui/AppearanceSheet");
@@ -100,13 +101,15 @@ function EpubReaderView(props) {
100
101
  const [attempt, setAttempt] = (0, react_1.useState)(0);
101
102
  const labels = (0, react_1.useMemo)(() => (0, strings_1.mergeLabels)(props.labels), [props.labels]);
102
103
  return (react_1.default.createElement(strings_1.LabelsProvider, { value: labels },
103
- react_1.default.createElement(ReaderScreen, { key: `${(0, EpubReader_1.sourceKeyOf)(props.source)}#${attempt}`, ...props, onRetry: () => setAttempt((a) => a + 1) })));
104
+ react_1.default.createElement(Text_1.UiFontsContext.Provider, { value: props.uiFonts || null },
105
+ react_1.default.createElement(ReaderScreen, { key: `${(0, EpubReader_1.sourceKeyOf)(props.source)}#${attempt}`, ...props, onRetry: () => setAttempt((a) => a + 1) }))));
104
106
  }
105
107
  function ReaderScreen(props) {
106
108
  const L = (0, strings_1.useLabels)();
107
109
  const screen = (0, react_native_1.useWindowDimensions)();
108
110
  const safe = props.safeInsets || defaultInsets(screen.width, screen.height);
109
- const systemDark = (0, react_native_1.useColorScheme)() === 'dark';
111
+ const phoneScheme = (0, react_native_1.useColorScheme)();
112
+ const systemDark = (props.colorScheme || phoneScheme) === 'dark';
110
113
  const reader = (0, react_1.useRef)(null);
111
114
  const [settings, setSettings] = (0, react_1.useState)({ ...themes_1.DEFAULT_SETTINGS, ...props.initialSettings });
112
115
  const [highlights, setHighlights] = (0, react_1.useState)(props.initialHighlights || []);
@@ -158,8 +161,8 @@ function ReaderScreen(props) {
158
161
  // people who asked for less motion get the fade instead of the curl or slide
159
162
  const readerSettings = (0, react_1.useMemo)(() => (reduceMotion && (settings.pageTurn === 'curl' || settings.pageTurn === 'slide') ? { ...settings, pageTurn: 'fade' } : settings), [settings, reduceMotion]);
160
163
  const dark = (0, themes_1.isDark)(settings, systemDark);
161
- const page = (0, themes_1.themeColors)(settings, systemDark);
162
- const colors = (0, react_1.useMemo)(() => (0, themes_1.chromeColors)(page, dark), [page, dark]);
164
+ const page = (0, themes_1.themeColors)(settings, systemDark, props.themes);
165
+ const colors = (0, react_1.useMemo)(() => (0, themes_1.chromeColors)(page, dark, props.chrome), [page, dark, props.chrome]);
163
166
  // ----- chrome visibility animation
164
167
  const fade = (0, react_1.useRef)(new react_native_1.Animated.Value(1)).current;
165
168
  (0, react_1.useEffect)(() => {
@@ -245,7 +248,7 @@ function ReaderScreen(props) {
245
248
  else {
246
249
  updateBookmarks((prev) => [
247
250
  ...prev,
248
- { id: uid(), spine: loc.spine, offset: loc.offset, chapter: loc.chapter, excerpt: loc.excerpt, progress: loc.progress, createdAt: Date.now() }
251
+ { id: uid(), spine: loc.spine, offset: loc.offset, cfi: loc.startCfi, chapter: loc.chapter, excerpt: loc.excerpt, progress: loc.progress, createdAt: Date.now() }
249
252
  ]);
250
253
  }
251
254
  };
@@ -258,7 +261,8 @@ function ReaderScreen(props) {
258
261
  start: sel.start,
259
262
  end: sel.end,
260
263
  text: sel.text.replace(/\s+/g, ' ').trim(),
261
- color: 'yellow',
264
+ color: props.highlightColors ? Object.keys(props.highlightColors)[0] || 'yellow' : 'yellow',
265
+ cfi: sel.cfi,
262
266
  chapter: loc?.chapter,
263
267
  createdAt: Date.now()
264
268
  };
@@ -353,8 +357,10 @@ function ReaderScreen(props) {
353
357
  };
354
358
  const progressFill = Math.max(0, Math.min(1, loc?.progress ?? 0));
355
359
  const tx = colors.text;
360
+ // text on the progress fill: the host's onStrong, else the default for that fill
361
+ const onFill = colors.onStrong || (colors.strong ? '#ffffff' : dark ? tx : '#ffffff');
356
362
  return (react_1.default.createElement(react_native_1.View, { style: [styles.root, { backgroundColor: page.bg }] },
357
- react_1.default.createElement(EpubReader_1.EpubReader, { ref: reader, source: props.source, settings: readerSettings, systemDark: systemDark, safeInsets: safe, initialLocation: props.initialLocation, highlights: highlights, maxFileSize: props.maxFileSize, onReady: ({ metadata, rtl: isRtl }) => {
363
+ react_1.default.createElement(EpubReader_1.EpubReader, { ref: reader, source: props.source, settings: readerSettings, systemDark: systemDark, safeInsets: safe, initialLocation: props.initialLocation, highlights: highlights, maxFileSize: props.maxFileSize, highlightColors: props.highlightColors, highlightOpacity: props.highlightOpacity, fonts: props.fonts, bookColors: props.bookColors, themes: props.themes, maxZoom: props.maxZoom, locationChars: props.locationChars, repairZeroWidth: props.repairZeroWidth, onLocations: props.onLocations, onReady: ({ metadata, rtl: isRtl }) => {
358
364
  setMeta(metadata);
359
365
  setRtl(isRtl);
360
366
  props.onMetadata?.(metadata);
@@ -416,7 +422,7 @@ function ReaderScreen(props) {
416
422
  }, hitSlop: 8, accessibilityRole: "button", accessibilityLabel: L.returnToPage(returnTo.page) },
417
423
  react_1.default.createElement(Glass_1.Glass, { dark: dark, background: colors.glass, border: colors.glassBorder, style: styles.returnPill },
418
424
  react_1.default.createElement(Icons_1.Icon, { name: "undo", color: tx, size: 22 }),
419
- react_1.default.createElement(react_native_1.Text, { style: { color: tx, fontSize: 20, marginStart: 8 }, maxFontSizeMultiplier: 1.3 }, L.formatNumber(returnTo.page)))))),
425
+ react_1.default.createElement(Text_1.Text, { style: { color: tx, fontSize: 20, marginStart: 8 }, maxFontSizeMultiplier: 1.3 }, L.formatNumber(returnTo.page)))))),
420
426
  react_1.default.createElement(react_native_1.Animated.View, { pointerEvents: chrome && !menuOpen ? 'auto' : 'none', ...hiddenA11y(!(chrome && !menuOpen)), style: [styles.menuBtnWrap, { bottom: safe.bottom + 14, right: 16 + (safe.right || 0), opacity: react_native_1.Animated.multiply(fade, react_native_1.Animated.subtract(1, menuFade)) }] },
421
427
  react_1.default.createElement(react_native_1.Pressable, { onPress: () => setMenuOpen(true), accessibilityRole: "button", accessibilityLabel: L.readerMenu },
422
428
  react_1.default.createElement(Glass_1.Glass, { dark: dark, background: colors.glass, border: colors.glassBorder, style: styles.menuBtn },
@@ -428,27 +434,27 @@ function ReaderScreen(props) {
428
434
  }, accessibilityRole: "button", accessibilityLabel: L.contents, style: styles.pillWrap },
429
435
  react_1.default.createElement(Glass_1.Glass, { dark: dark, background: colors.glass, border: colors.glassBorder, style: styles.pill },
430
436
  react_1.default.createElement(react_native_1.View, { style: styles.pillRow, onLayout: (e) => setPillW(e.nativeEvent.layout.width) },
431
- react_1.default.createElement(react_native_1.Text, { style: [styles.pillText, { color: tx }], maxFontSizeMultiplier: 1.3 },
437
+ react_1.default.createElement(Text_1.Text, { style: [styles.pillText, { color: tx }], maxFontSizeMultiplier: 1.3 },
432
438
  L.contents,
433
439
  " \u2022 ",
434
440
  L.formatNumber(percent),
435
441
  "%"),
436
442
  react_1.default.createElement(Icons_1.Icon, { name: "list", color: tx, size: 24 })),
437
- react_1.default.createElement(react_native_1.View, { pointerEvents: "none", style: [styles.fill, { width: progressFill * pillW, backgroundColor: dark ? 'rgba(255,255,255,0.35)' : '#1c1408', [rtl ? 'right' : 'left']: 0 }] },
443
+ react_1.default.createElement(react_native_1.View, { pointerEvents: "none", style: [styles.fill, { width: progressFill * pillW, backgroundColor: colors.strong || (dark ? 'rgba(255,255,255,0.35)' : '#1c1408'), [rtl ? 'right' : 'left']: 0 }] },
438
444
  react_1.default.createElement(react_native_1.View, { style: [styles.pillRow, { position: 'absolute', top: 0, width: pillW, [rtl ? 'right' : 'left']: 0 }] },
439
- react_1.default.createElement(react_native_1.Text, { style: [styles.pillText, { color: dark ? tx : '#ffffff' }], maxFontSizeMultiplier: 1.3 },
445
+ react_1.default.createElement(Text_1.Text, { style: [styles.pillText, { color: onFill }], maxFontSizeMultiplier: 1.3 },
440
446
  L.contents,
441
447
  " \u2022 ",
442
448
  L.formatNumber(percent),
443
449
  "%"),
444
- react_1.default.createElement(Icons_1.Icon, { name: "list", color: dark ? tx : '#ffffff', size: 24 }))))),
450
+ react_1.default.createElement(Icons_1.Icon, { name: "list", color: onFill, size: 24 }))))),
445
451
  react_1.default.createElement(react_native_1.Pressable, { onPress: () => {
446
452
  setMenuOpen(false);
447
453
  setSheet('search');
448
454
  }, accessibilityRole: "button", accessibilityLabel: L.searchBook, style: styles.pillWrap },
449
455
  react_1.default.createElement(Glass_1.Glass, { dark: dark, background: colors.glass, border: colors.glassBorder, style: styles.pill },
450
456
  react_1.default.createElement(react_native_1.View, { style: styles.pillRow },
451
- react_1.default.createElement(react_native_1.Text, { style: [styles.pillText, { color: tx }], maxFontSizeMultiplier: 1.3 }, L.searchBook),
457
+ react_1.default.createElement(Text_1.Text, { style: [styles.pillText, { color: tx }], maxFontSizeMultiplier: 1.3 }, L.searchBook),
452
458
  react_1.default.createElement(Icons_1.Icon, { name: "search", color: tx, size: 24 })))),
453
459
  react_1.default.createElement(react_native_1.Pressable, { onPress: () => {
454
460
  setMenuOpen(false);
@@ -456,7 +462,7 @@ function ReaderScreen(props) {
456
462
  }, accessibilityRole: "button", accessibilityLabel: L.themesSettings, style: styles.pillWrap },
457
463
  react_1.default.createElement(Glass_1.Glass, { dark: dark, background: colors.glass, border: colors.glassBorder, style: styles.pill },
458
464
  react_1.default.createElement(react_native_1.View, { style: styles.pillRow },
459
- react_1.default.createElement(react_native_1.Text, { style: [styles.pillText, { color: tx }], maxFontSizeMultiplier: 1.3 }, L.themesSettings),
465
+ react_1.default.createElement(Text_1.Text, { style: [styles.pillText, { color: tx }], maxFontSizeMultiplier: 1.3 }, L.themesSettings),
460
466
  react_1.default.createElement(Icons_1.Icon, { name: "textSize", color: tx, size: 26 })))),
461
467
  react_1.default.createElement(react_native_1.View, { style: styles.roundRow },
462
468
  react_1.default.createElement(react_native_1.Pressable, { onPress: share, style: styles.roundWrap, accessibilityRole: "button", accessibilityLabel: L.share },
@@ -481,60 +487,60 @@ function ReaderScreen(props) {
481
487
  return (react_1.default.createElement(Glass_1.Glass, { dark: dark, background: colors.sheetGlass, border: colors.glassBorder, intensity: 55, style: [styles.selBar, { left, top, width: w }] },
482
488
  react_1.default.createElement(react_native_1.Pressable, { style: styles.selBtn, onPress: () => createHighlight(selection, false), accessibilityRole: "button", accessibilityLabel: L.highlight },
483
489
  react_1.default.createElement(Icons_1.Icon, { name: "highlighter", color: tx, size: 22 }),
484
- react_1.default.createElement(react_native_1.Text, { style: [styles.selText, { color: tx }], numberOfLines: 1, maxFontSizeMultiplier: 1.2 }, L.highlight)),
490
+ react_1.default.createElement(Text_1.Text, { style: [styles.selText, { color: tx }], numberOfLines: 1, maxFontSizeMultiplier: 1.2 }, L.highlight)),
485
491
  react_1.default.createElement(react_native_1.View, { style: [styles.selSep, { backgroundColor: colors.separator }] }),
486
492
  react_1.default.createElement(react_native_1.Pressable, { style: styles.selBtn, onPress: () => createHighlight(selection, true), accessibilityRole: "button", accessibilityLabel: L.addNote },
487
493
  react_1.default.createElement(Icons_1.Icon, { name: "pencil", color: tx, size: 22 }),
488
- react_1.default.createElement(react_native_1.Text, { style: [styles.selText, { color: tx }], numberOfLines: 1, maxFontSizeMultiplier: 1.2 }, L.note))));
494
+ react_1.default.createElement(Text_1.Text, { style: [styles.selText, { color: tx }], numberOfLines: 1, maxFontSizeMultiplier: 1.2 }, L.note))));
489
495
  })(),
490
- activeHighlight && active && (react_1.default.createElement(HighlightMenu_1.HighlightMenu, { highlight: activeHighlight, rect: active.rect, screen: screen, colors: colors, onColor: (c) => patchHighlight(activeHighlight.id, { color: c }), onToggleUnderline: () => patchHighlight(activeHighlight.id, { style: activeHighlight.style === 'underline' ? 'highlight' : 'underline' }), onNote: () => {
496
+ activeHighlight && active && (react_1.default.createElement(HighlightMenu_1.HighlightMenu, { highlight: activeHighlight, rect: active.rect, screen: screen, colors: colors, palette: props.highlightColors, onColor: (c) => patchHighlight(activeHighlight.id, { color: c }), onToggleUnderline: () => patchHighlight(activeHighlight.id, { style: activeHighlight.style === 'underline' ? 'highlight' : 'underline' }), onNote: () => {
491
497
  setNoteFor(activeHighlight.id);
492
498
  setActive(null);
493
499
  }, onDelete: () => removeHighlight(activeHighlight.id), onDismiss: () => setActive(null) })),
494
500
  !loaded && !fatal && (react_1.default.createElement(react_native_1.View, { style: [react_native_1.StyleSheet.absoluteFill, styles.splash, { backgroundColor: page.bg }], pointerEvents: "box-none" },
495
501
  react_1.default.createElement(react_native_1.ActivityIndicator, { color: page.fg }),
496
- react_1.default.createElement(react_native_1.Text, { style: { color: page.fg, opacity: 0.6, marginTop: 12, fontSize: 15 }, maxFontSizeMultiplier: 1.3 }, L.loading),
502
+ react_1.default.createElement(Text_1.Text, { style: { color: page.fg, opacity: 0.6, marginTop: 12, fontSize: 15 }, maxFontSizeMultiplier: 1.3 }, L.loading),
497
503
  react_1.default.createElement(react_native_1.Pressable, { onPress: props.onClose, hitSlop: 10, accessibilityRole: "button", accessibilityLabel: L.closeBook, style: [styles.splashClose, { top: safe.top + 2, right: 16 + (safe.right || 0) }] },
498
504
  react_1.default.createElement(Glass_1.Glass, { dark: dark, background: colors.glass, border: colors.glassBorder, style: styles.circle },
499
505
  react_1.default.createElement(Icons_1.Icon, { name: "close", color: tx, size: 22 }))))),
500
506
  !!fatal && (react_1.default.createElement(react_native_1.View, { style: [react_native_1.StyleSheet.absoluteFill, styles.splash, { backgroundColor: page.bg }], accessibilityViewIsModal: true },
501
- react_1.default.createElement(react_native_1.Text, { style: { color: page.fg, fontSize: 18, fontWeight: '600', textAlign: 'center' }, accessibilityRole: "header" }, L.couldNotOpen),
502
- react_1.default.createElement(react_native_1.Text, { style: { color: page.fg, opacity: 0.7, fontSize: 15, textAlign: 'center', marginTop: 10 }, accessibilityRole: "alert" }, fatal),
507
+ react_1.default.createElement(Text_1.Text, { style: { color: page.fg, fontSize: 18, fontWeight: '600', textAlign: 'center' }, accessibilityRole: "header" }, L.couldNotOpen),
508
+ react_1.default.createElement(Text_1.Text, { style: { color: page.fg, opacity: 0.7, fontSize: 15, textAlign: 'center', marginTop: 10 }, accessibilityRole: "alert" }, fatal),
503
509
  react_1.default.createElement(react_native_1.View, { style: styles.fatalButtons },
504
510
  react_1.default.createElement(react_native_1.Pressable, { onPress: props.onRetry, style: [styles.fatalBtn, { backgroundColor: colors.accent }], accessibilityRole: "button" },
505
- react_1.default.createElement(react_native_1.Text, { style: { color: '#ffffff', fontSize: 16, fontWeight: '600' } }, L.tryAgain)),
511
+ react_1.default.createElement(Text_1.Text, { style: { color: '#ffffff', fontSize: 16, fontWeight: '600' } }, L.tryAgain)),
506
512
  !!props.onClose && (react_1.default.createElement(react_native_1.Pressable, { onPress: props.onClose, style: [styles.fatalBtn, { backgroundColor: colors.card }], accessibilityRole: "button" },
507
- react_1.default.createElement(react_native_1.Text, { style: { color: tx, fontSize: 16, fontWeight: '600' } }, L.close)))))),
513
+ react_1.default.createElement(Text_1.Text, { style: { color: tx, fontSize: 16, fontWeight: '600' } }, L.close)))))),
508
514
  error && !fatal && (react_1.default.createElement(react_native_1.View, { style: [styles.error, { backgroundColor: colors.sheet }], accessibilityRole: "alert" },
509
- react_1.default.createElement(react_native_1.Text, { style: { color: colors.text, fontSize: 15, textAlign: 'center' } }, error),
515
+ react_1.default.createElement(Text_1.Text, { style: { color: colors.text, fontSize: 15, textAlign: 'center' } }, error),
510
516
  react_1.default.createElement(react_native_1.Pressable, { onPress: () => setError(null), style: { marginTop: 12, padding: 8 }, accessibilityRole: "button" },
511
- react_1.default.createElement(react_native_1.Text, { style: { color: colors.accent, fontSize: 16 } }, L.ok)))),
517
+ react_1.default.createElement(Text_1.Text, { style: { color: colors.accent, fontSize: 16 } }, L.ok)))),
512
518
  lineMenu && (react_1.default.createElement(react_1.default.Fragment, null,
513
519
  react_1.default.createElement(react_native_1.Pressable, { style: react_native_1.StyleSheet.absoluteFill, onPress: () => setLineMenu(false), accessibilityLabel: L.dismiss }),
514
520
  react_1.default.createElement(react_native_1.View, { style: [styles.lineMenu, { bottom: safe.bottom + 20, backgroundColor: colors.dark ? '#4a4742' : '#ffffff', borderColor: colors.glassBorder }] },
515
- react_1.default.createElement(react_native_1.Text, { style: [styles.lineMenuHead, { color: colors.subtext }] }, L.backgroundDimming),
521
+ react_1.default.createElement(Text_1.Text, { style: [styles.lineMenuHead, { color: colors.subtext }] }, L.backgroundDimming),
516
522
  DIM_IDS.map((d) => (react_1.default.createElement(react_native_1.Pressable, { key: d.id, style: styles.lineItem, accessibilityRole: "button", accessibilityState: { selected: dimLevel === d.id }, onPress: () => {
517
523
  setDimLevel(d.id);
518
524
  setLineMenu(false);
519
525
  } },
520
526
  react_1.default.createElement(react_native_1.View, { style: styles.lineCheck }, dimLevel === d.id && react_1.default.createElement(Icons_1.Icon, { name: "check", color: tx, size: 20 })),
521
- react_1.default.createElement(react_native_1.Text, { style: { color: tx, fontSize: 19 } }, L[d.label])))),
527
+ react_1.default.createElement(Text_1.Text, { style: { color: tx, fontSize: 19 } }, L[d.label])))),
522
528
  react_1.default.createElement(react_native_1.View, { style: [styles.lineSep, { backgroundColor: colors.separator }] }),
523
529
  react_1.default.createElement(react_native_1.Pressable, { style: styles.lineItem, accessibilityRole: "button", onPress: () => {
524
530
  setLineGuide(false);
525
531
  setLineMenu(false);
526
532
  } },
527
533
  react_1.default.createElement(react_native_1.View, { style: styles.lineCheck }),
528
- react_1.default.createElement(react_native_1.Text, { style: { color: tx, fontSize: 19 } }, L.turnOffLineGuide))))),
529
- react_1.default.createElement(ContentsSheet_1.ContentsSheet, { visible: sheet === 'contents', colors: colors, title: meta?.title || props.title || '', subtitle: L.pageOfTotalLong(curPage, totalPages), toc: toc, currentSpine: loc?.spine ?? 0, pageOf: pageOf, bookmarks: bookmarks, highlights: highlights, onClose: closeSheet, onGoToc: (item) => {
534
+ react_1.default.createElement(Text_1.Text, { style: { color: tx, fontSize: 19 } }, L.turnOffLineGuide))))),
535
+ react_1.default.createElement(ContentsSheet_1.ContentsSheet, { visible: sheet === 'contents', colors: colors, title: meta?.title || props.title || '', subtitle: L.pageOfTotalLong(curPage, totalPages), toc: toc, currentSpine: loc?.spine ?? 0, pageOf: pageOf, bookmarks: bookmarks, highlights: highlights, palette: props.highlightColors, onClose: closeSheet, onGoToc: (item) => {
530
536
  closeSheet();
531
537
  jump({ spine: item.spine, fragment: item.fragment });
532
538
  }, onGoBookmark: (b) => {
533
539
  closeSheet();
534
- jump({ spine: b.spine, offset: b.offset });
540
+ jump(b.cfi ? { cfi: b.cfi, spine: b.spine, offset: b.offset } : { spine: b.spine, offset: b.offset });
535
541
  }, onGoHighlight: (h) => {
536
542
  closeSheet();
537
- jump({ spine: h.spine, offset: h.start });
543
+ jump(h.cfi ? { cfi: h.cfi, spine: h.spine, offset: h.start } : { spine: h.spine, offset: h.start });
538
544
  }, onDeleteBookmark: (id) => updateBookmarks((prev) => prev.filter((b) => b.id !== id)), onDeleteHighlight: (id) => updateHighlights((prev) => prev.filter((h) => h.id !== id)) }),
539
545
  react_1.default.createElement(SearchSheet_1.SearchSheet, { visible: sheet === 'search', colors: colors, results: results, searching: searching, onClose: closeSheet, onSearch: runSearch, onPick: (r) => {
540
546
  closeSheet();
@@ -543,8 +549,8 @@ function ReaderScreen(props) {
543
549
  setChrome(false);
544
550
  reader.current?.showSearchResult(r);
545
551
  } }),
546
- react_1.default.createElement(AppearanceSheet_1.AppearanceSheet, { visible: sheet === 'appearance', colors: colors, settings: settings, systemDark: systemDark, onChange: changeSettings, onCustomize: () => switchSheet('customize'), onClose: closeSheet }),
547
- react_1.default.createElement(CustomizeSheet_1.CustomizeSheet, { visible: sheet === 'customize', colors: colors, page: page, settings: settings, sample: loc?.excerpt || SAMPLE, onChange: changeSettings, onReset: () => changeSettings(RESET_THEME), onClose: () => switchSheet('appearance') }),
552
+ react_1.default.createElement(AppearanceSheet_1.AppearanceSheet, { visible: sheet === 'appearance', colors: colors, settings: settings, systemDark: systemDark, themes: props.themes, onChange: changeSettings, onCustomize: () => switchSheet('customize'), onClose: closeSheet }),
553
+ react_1.default.createElement(CustomizeSheet_1.CustomizeSheet, { visible: sheet === 'customize', colors: colors, page: page, settings: settings, sample: loc?.excerpt || SAMPLE, fontList: (0, themes_1.fontChoices)(props.fonts), onChange: changeSettings, onReset: () => changeSettings(RESET_THEME), onClose: () => switchSheet('appearance') }),
548
554
  react_1.default.createElement(NoteEditor_1.NoteEditor, { visible: !!noteHighlight, quote: noteHighlight?.text || '', initial: noteHighlight?.note || '', colors: colors, onCancel: () => setNoteFor(null), onSave: (text) => {
549
555
  if (noteFor)
550
556
  patchHighlight(noteFor, { note: text || undefined });
@@ -0,0 +1,2 @@
1
+ /** Negative when `a` comes first, positive when `b` comes first, 0 when equal or unreadable. */
2
+ export declare function compareCfi(a: string, b: string): number;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ // Book order of two epub.js CFIs, without a DOM. A range CFI counts from its start.
3
+ // Only the step numbers and the character offset matter for order; [id] assertions are ignored.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.compareCfi = compareCfi;
6
+ function partsOf(cfi) {
7
+ const m = /^epubcfi\((.*)\)$/.exec(cfi.trim());
8
+ if (!m)
9
+ return null;
10
+ // drop [..] assertions first, they may contain ',' or ':'
11
+ const bits = m[1].replace(/\[[^\]]*\]/g, '').split(',');
12
+ const path = bits.length === 3 ? bits[0] + bits[1] : bits[0];
13
+ const steps = [];
14
+ const re = /\/(\d+)/g;
15
+ let s;
16
+ while ((s = re.exec(path)))
17
+ steps.push(+s[1]);
18
+ const off = /:(\d+)[^/]*$/.exec(path);
19
+ return steps.length ? { steps, offset: off ? +off[1] : 0 } : null;
20
+ }
21
+ /** Negative when `a` comes first, positive when `b` comes first, 0 when equal or unreadable. */
22
+ function compareCfi(a, b) {
23
+ const x = partsOf(a);
24
+ const y = partsOf(b);
25
+ if (!x || !y)
26
+ return 0;
27
+ for (let i = 0; i < Math.min(x.steps.length, y.steps.length); i++) {
28
+ if (x.steps[i] !== y.steps[i])
29
+ return x.steps[i] - y.steps[i];
30
+ }
31
+ if (x.steps.length !== y.steps.length)
32
+ return x.steps.length - y.steps.length;
33
+ return x.offset - y.offset;
34
+ }