@caipira/vue-reader 0.0.2 → 0.0.3

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 (68) hide show
  1. package/README.md +38 -24
  2. package/dist/src/composables/useEpubReader.d.ts +5 -27786
  3. package/dist/src/composables/useEpubReader.js +222 -4
  4. package/dist/src/composables/useEpubReaderLogging.d.ts +5 -0
  5. package/dist/src/composables/useEpubReaderLogging.js +27 -0
  6. package/dist/src/composables/useEpubReaderNavigation.d.ts +3 -3
  7. package/dist/src/composables/useEpubReaderNavigation.js +8 -15
  8. package/dist/src/composables/useEpubReaderState.d.ts +27794 -20
  9. package/dist/src/composables/useEpubReaderState.js +31 -21
  10. package/dist/{composables → src/composables}/useEpubReaderStrategy.d.ts +1 -1
  11. package/dist/src/composables/useEpubReaderWasm.d.ts +2 -0
  12. package/dist/{composables → src/composables}/useEpubReaderWasm.js +5 -5
  13. package/dist/src/composables/useEpubReaderZipFetcher.d.ts +2 -0
  14. package/dist/{composables → src/composables}/useEpubReaderZipFetcher.js +5 -5
  15. package/dist/src/composables/useReaderColors.d.ts +10 -0
  16. package/dist/src/composables/useReaderColors.js +38 -0
  17. package/dist/src/composables/useReaderSettings.d.ts +28 -11
  18. package/dist/src/composables/useReaderSettings.js +110 -36
  19. package/dist/src/index.d.ts +6 -9
  20. package/dist/src/index.js +5 -8
  21. package/dist/{services → src/services}/browser/epub.d.ts +1 -1
  22. package/dist/{services → src/services}/browser/manifest.d.ts +1 -1
  23. package/dist/{services → src/services}/browser/manifest.js +1 -1
  24. package/dist/{services → src/services}/browser/url-rewrite.d.ts +1 -1
  25. package/dist/{services → src/services}/browser/url-rewrite.js +1 -1
  26. package/dist/{services → src/services}/browser/zip-fetcher.d.ts +1 -1
  27. package/dist/{services → src/services}/browser/zip-fetcher.js +2 -2
  28. package/dist/{services → src/services}/common/progression.d.ts +3 -11
  29. package/dist/{services → src/services}/common/progression.js +1 -32
  30. package/dist/src/{core → services/common}/storage.d.ts +1 -1
  31. package/dist/src/{core → services/common}/storage.js +1 -2
  32. package/dist/{services → src/services}/common/title.d.ts +1 -1
  33. package/dist/{services → src/services}/common/word-decorations.d.ts +1 -1
  34. package/dist/{services → src/services}/common/word-decorations.js +2 -2
  35. package/dist/{services → src/services}/common/word-lookup.js +1 -1
  36. package/dist/{types → src/types}/common.d.ts +36 -1
  37. package/package.json +1 -1
  38. package/dist/composables/useEpubReaderWasm.d.ts +0 -2
  39. package/dist/composables/useEpubReaderZipFetcher.d.ts +0 -2
  40. package/dist/src/composables/useEpubReaderController.d.ts +0 -27787
  41. package/dist/src/composables/useEpubReaderController.js +0 -23
  42. package/dist/src/composables/useEpubReaderSettings.d.ts +0 -15
  43. package/dist/src/composables/useEpubReaderSettings.js +0 -8
  44. package/dist/src/composables/utils.d.ts +0 -2
  45. package/dist/src/composables/utils.js +0 -1
  46. package/dist/src/core/controller.d.ts +0 -27789
  47. package/dist/src/core/controller.js +0 -262
  48. package/dist/src/core/settings-store.d.ts +0 -16
  49. package/dist/src/core/settings-store.js +0 -58
  50. package/dist/src/settings/options.d.ts +0 -20
  51. package/dist/src/settings/options.js +0 -27
  52. package/dist/src/types.d.ts +0 -40
  53. package/dist/src/types.js +0 -1
  54. /package/dist/{composables → src/composables}/useEpubReaderStrategy.js +0 -0
  55. /package/dist/{services → src/services}/browser/epub.js +0 -0
  56. /package/dist/{services → src/services}/browser/url.d.ts +0 -0
  57. /package/dist/{services → src/services}/browser/url.js +0 -0
  58. /package/dist/src/{core → services/common}/fonts.d.ts +0 -0
  59. /package/dist/src/{core → services/common}/fonts.js +0 -0
  60. /package/dist/{services → src/services}/common/title.js +0 -0
  61. /package/dist/{services → src/services}/common/word-lookup.d.ts +0 -0
  62. /package/dist/{services → src/services}/wasm/frame-document-bridge.d.ts +0 -0
  63. /package/dist/{services → src/services}/wasm/frame-document-bridge.js +0 -0
  64. /package/dist/{services → src/services}/wasm/wasm-streamer.d.ts +0 -0
  65. /package/dist/{services → src/services}/wasm/wasm-streamer.js +0 -0
  66. /package/dist/{types → src/types}/browser.d.ts +0 -0
  67. /package/dist/{types → src/types}/browser.js +0 -0
  68. /package/dist/{types → src/types}/common.js +0 -0
@@ -1,29 +1,39 @@
1
- import { computed, ref, shallowRef } from 'vue';
1
+ import { computed, ref } from 'vue';
2
+ export var LOG_MODES;
3
+ (function (LOG_MODES) {
4
+ LOG_MODES["ALL"] = "all";
5
+ LOG_MODES["WARNING"] = "warning";
6
+ LOG_MODES["ERROR"] = "error";
7
+ LOG_MODES["NONE"] = "none";
8
+ })(LOG_MODES || (LOG_MODES = {}));
9
+ const error = ref(null);
10
+ const logMode = ref(LOG_MODES.ALL);
11
+ const loading = ref(false);
12
+ const tocLinks = ref([]);
13
+ const settings = ref(null);
14
+ const navigator = ref(null);
15
+ const publication = ref(null);
2
16
  const containerRef = ref();
3
- const epubReaderController = shallowRef(null);
4
- export const setEpubReaderController = (reader) => {
5
- epubReaderController.value = reader;
6
- };
7
- export const useEpubReaderControllerRef = () => epubReaderController;
8
- export function useEpubReaderState(controller, container) {
17
+ const totalPositions = ref(0);
18
+ const currentPosition = ref(0);
19
+ const progressPercent = computed(() => Math.min(100, Math.max(0, currentPosition.value)));
20
+ const currentChapterTitle = ref('');
21
+ export function useEpubReaderState(container) {
9
22
  if (container) {
10
23
  containerRef.value = container;
11
24
  }
12
- if (controller) {
13
- return controller.state;
14
- }
15
- const activeState = computed(() => epubReaderController.value?.state);
16
25
  return {
17
- error: computed(() => activeState.value?.error?.value),
18
- loading: computed(() => activeState.value?.loading?.value),
19
- tocLinks: computed(() => activeState.value?.tocLinks?.value),
20
- navigator: computed(() => activeState.value?.navigator?.value),
21
- publication: computed(() => activeState.value?.publication?.value),
26
+ error,
27
+ loading,
28
+ logMode,
29
+ tocLinks,
30
+ settings,
31
+ navigator,
32
+ publication,
22
33
  containerRef: computed(() => containerRef.value?.value),
23
- totalPositions: computed(() => activeState.value?.totalPositions?.value),
24
- currentPosition: computed(() => activeState.value?.currentPosition?.value),
25
- progressPercent: computed(() => activeState.value?.progressPercent?.value),
26
- currentChapterTitle: computed(() => activeState.value?.currentChapterTitle?.value),
27
- settings: computed(() => activeState.value?.settings),
34
+ totalPositions,
35
+ currentPosition,
36
+ progressPercent,
37
+ currentChapterTitle,
28
38
  };
29
39
  }
@@ -1,4 +1,4 @@
1
- import type { ChapterBoundary } from '../types/common';
1
+ import type { ChapterBoundary } from '../../src/types/common';
2
2
  export type ReaderProgress = {
3
3
  progress: number;
4
4
  resourceProgression: number;
@@ -0,0 +1,2 @@
1
+ import type { ReaderSourceStrategy } from '../../src/composables/useEpubReaderStrategy';
2
+ export declare function useEpubReaderWasm(): ReaderSourceStrategy;
@@ -1,8 +1,8 @@
1
- import { resolveHref } from '../services/browser/url';
2
- import { computePublicationChaptersSize } from '../services/common/progression';
3
- import { loadPublication, createPublication, unloadPublication, } from '../services/wasm/wasm-streamer';
4
- import { buildWeightsFromResolver } from '../services/common/progression';
5
- import { installFrameDocumentBridge } from '../services/wasm/frame-document-bridge';
1
+ import { resolveHref } from '../../src/services/browser/url';
2
+ import { computePublicationChaptersSize } from '../../src/services/common/progression';
3
+ import { loadPublication, createPublication, unloadPublication, } from '../../src/services/wasm/wasm-streamer';
4
+ import { buildWeightsFromResolver } from '../../src/services/common/progression';
5
+ import { installFrameDocumentBridge } from '../../src/services/wasm/frame-document-bridge';
6
6
  const isExternalRef = (value) => {
7
7
  const ref = value.trim().toLowerCase();
8
8
  return (ref === '' ||
@@ -0,0 +1,2 @@
1
+ import type { ReaderSourceStrategy } from '../../src/composables/useEpubReaderStrategy';
2
+ export declare function useEpubReaderZipFetcher(): ReaderSourceStrategy;
@@ -1,8 +1,8 @@
1
- import ZipFetcher from '../services/browser/zip-fetcher';
2
- import { buildManifest } from '../services/browser/manifest';
3
- import { clearBlobUrlCache } from '../services/browser/url-rewrite';
4
- import { fetchEpub, unzipEpub } from '../services/browser/epub';
5
- import { buildWeightsFromZip, computeChapterProgressions, } from '../services/common/progression';
1
+ import ZipFetcher from '../../src/services/browser/zip-fetcher';
2
+ import { buildManifest } from '../../src/services/browser/manifest';
3
+ import { clearBlobUrlCache } from '../../src/services/browser/url-rewrite';
4
+ import { fetchEpub, unzipEpub } from '../../src/services/browser/epub';
5
+ import { buildWeightsFromZip, computeChapterProgressions, } from '../../src/services/common/progression';
6
6
  export function useEpubReaderZipFetcher() {
7
7
  const load = async (url) => {
8
8
  const zip = await unzipEpub(await fetchEpub(url));
@@ -0,0 +1,10 @@
1
+ export type ReaderColors = {
2
+ text: string | null;
3
+ background: string | null;
4
+ highlight: string | null;
5
+ };
6
+ type ReaderColorsListener = (colors: Readonly<ReaderColors>) => void;
7
+ export declare const setReaderColors: (colors: Partial<ReaderColors>) => void;
8
+ export declare const getReaderColors: () => ReaderColors;
9
+ export declare const onReaderColorsChange: (handler: ReaderColorsListener) => () => void;
10
+ export {};
@@ -0,0 +1,38 @@
1
+ const readerColors = {
2
+ text: null,
3
+ background: null,
4
+ highlight: null,
5
+ };
6
+ let readerColorsListener = null;
7
+ const notifyReaderColorsListeners = () => {
8
+ const snapshot = {
9
+ text: readerColors.text,
10
+ background: readerColors.background,
11
+ highlight: readerColors.highlight,
12
+ };
13
+ readerColorsListener?.(snapshot);
14
+ };
15
+ export const setReaderColors = (colors) => {
16
+ if (colors.text !== undefined) {
17
+ readerColors.text = colors.text;
18
+ }
19
+ if (colors.background !== undefined) {
20
+ readerColors.background = colors.background;
21
+ }
22
+ if (colors.highlight !== undefined) {
23
+ readerColors.highlight = colors.highlight;
24
+ }
25
+ notifyReaderColorsListeners();
26
+ };
27
+ export const getReaderColors = () => {
28
+ return readerColors;
29
+ };
30
+ export const onReaderColorsChange = (handler) => {
31
+ readerColorsListener = handler;
32
+ handler(getReaderColors());
33
+ return () => {
34
+ if (readerColorsListener === handler) {
35
+ readerColorsListener = null;
36
+ }
37
+ };
38
+ };
@@ -1,14 +1,29 @@
1
- import type { ReturnTypeCreateController } from '../../src/composables/utils';
2
- export type ReaderColors = {
3
- text: string | null;
4
- background: string | null;
5
- highlight: string | null;
1
+ import type { ReaderPreferencesAdapter, ReaderSettings } from '../../src/types/common';
2
+ import { TextAlignment } from '@readium/navigator';
3
+ export declare const EPUB_FONT_SIZE_OPTIONS: {
4
+ value: number;
5
+ label: string;
6
+ }[];
7
+ export declare const PX_FONT_SIZE_OPTIONS: {
8
+ value: number;
9
+ label: string;
10
+ }[];
11
+ export declare const COLUMN_OPTIONS: {
12
+ value: number;
13
+ label: string;
14
+ }[];
15
+ export declare const ALIGN_OPTIONS: ({
16
+ key: null;
17
+ label: string;
18
+ } | {
19
+ key: TextAlignment;
20
+ label: string;
21
+ })[];
22
+ type UseReaderSettingsOptions = {
23
+ initialSettings?: Partial<ReaderSettings>;
24
+ preferences?: ReaderPreferencesAdapter;
6
25
  };
7
- type ReaderColorsListener = (colors: Readonly<ReaderColors>) => void;
8
- export declare const setReaderColors: (colors: Partial<ReaderColors>) => void;
9
- export declare const getReaderColors: () => ReaderColors;
10
- export declare const onReaderColorsChange: (handler: ReaderColorsListener) => () => void;
11
- export declare const useReaderSettings: (controller: ReturnTypeCreateController) => {
26
+ export declare const useReaderSettings: (options?: UseReaderSettingsOptions) => {
12
27
  settings: {
13
28
  backgroundColor: string | null;
14
29
  columnCount: number | null;
@@ -17,9 +32,11 @@ export declare const useReaderSettings: (controller: ReturnTypeCreateController)
17
32
  isFullscreen: boolean;
18
33
  lineHeight: number | null;
19
34
  scroll: boolean | null;
20
- textAlign: import("@readium/navigator").TextAlignment | null;
35
+ textAlign: TextAlignment | null;
21
36
  textColor: string | null;
22
37
  };
38
+ hydrate: () => Promise<void>;
39
+ onSettingsChange: (handler: (next: Readonly<ReaderSettings>) => void) => () => boolean;
23
40
  toggleFullscreen: () => void;
24
41
  };
25
42
  export {};
@@ -1,42 +1,116 @@
1
- import { useEpubReaderSettings } from '../../src/composables/useEpubReaderSettings';
2
- const readerColors = {
3
- text: null,
4
- background: null,
5
- highlight: null,
6
- };
7
- let readerColorsListener = null;
8
- const notifyReaderColorsListeners = () => {
9
- const snapshot = {
10
- text: readerColors.text,
11
- background: readerColors.background,
12
- highlight: readerColors.highlight,
13
- };
14
- readerColorsListener?.(snapshot);
15
- };
16
- export const setReaderColors = (colors) => {
17
- if (colors.text !== undefined) {
18
- readerColors.text = colors.text;
1
+ import { TextAlignment } from '@readium/navigator';
2
+ import { reactive, watch } from 'vue';
3
+ import { getReaderColors } from '../../src/composables/useReaderColors';
4
+ import { useEpubReaderState } from '../../src/composables/useEpubReaderState';
5
+ export const EPUB_FONT_SIZE_OPTIONS = [
6
+ { value: 0.8, label: '80%' },
7
+ { value: 1, label: '100% (Default)' },
8
+ { value: 1.2, label: '120%' },
9
+ { value: 1.4, label: '140%' },
10
+ { value: 1.6, label: '160%' },
11
+ ];
12
+ export const PX_FONT_SIZE_OPTIONS = [
13
+ { value: 16, label: '16 (Default)' },
14
+ { value: 20, label: '20' },
15
+ { value: 24, label: '24' },
16
+ { value: 28, label: '28' },
17
+ { value: 32, label: '32' },
18
+ ];
19
+ export const COLUMN_OPTIONS = [
20
+ { value: 0, label: 'Auto' },
21
+ { value: 1, label: '1' },
22
+ { value: 2, label: '2' },
23
+ ];
24
+ export const ALIGN_OPTIONS = [
25
+ { key: null, label: 'Auto' },
26
+ { key: TextAlignment.start, label: 'Start' },
27
+ { key: TextAlignment.left, label: 'Left' },
28
+ { key: TextAlignment.right, label: 'Right' },
29
+ { key: TextAlignment.justify, label: 'Justify' },
30
+ ];
31
+ const colors = getReaderColors();
32
+ const settings = reactive({
33
+ backgroundColor: colors.background,
34
+ textColor: colors.text,
35
+ fontFamily: 'DEFAULT',
36
+ fontSize: 1,
37
+ lineHeight: null,
38
+ textAlign: null,
39
+ columnCount: null,
40
+ scroll: null,
41
+ isFullscreen: false,
42
+ });
43
+ const listeners = new Set();
44
+ let activePreferences;
45
+ let hydrated = false;
46
+ let watchInitialized = false;
47
+ const initWatcher = () => {
48
+ if (watchInitialized) {
49
+ return;
19
50
  }
20
- if (colors.background !== undefined) {
21
- readerColors.background = colors.background;
51
+ watchInitialized = true;
52
+ watch(() => [
53
+ settings.fontFamily,
54
+ settings.fontSize,
55
+ settings.lineHeight,
56
+ settings.textAlign,
57
+ settings.columnCount,
58
+ settings.scroll,
59
+ settings.backgroundColor,
60
+ settings.textColor,
61
+ settings.isFullscreen,
62
+ ], () => {
63
+ listeners.forEach((handler) => handler(settings));
64
+ void activePreferences?.save?.(settings);
65
+ });
66
+ };
67
+ export const useReaderSettings = (options) => {
68
+ initWatcher();
69
+ if (options?.preferences && options.preferences !== activePreferences) {
70
+ activePreferences = options.preferences;
71
+ hydrated = false;
22
72
  }
23
- if (colors.highlight !== undefined) {
24
- readerColors.highlight = colors.highlight;
73
+ if (options?.initialSettings) {
74
+ Object.assign(settings, options.initialSettings);
25
75
  }
26
- notifyReaderColorsListeners();
27
- };
28
- export const getReaderColors = () => {
29
- return readerColors;
30
- };
31
- export const onReaderColorsChange = (handler) => {
32
- readerColorsListener = handler;
33
- handler(getReaderColors());
34
- return () => {
35
- if (readerColorsListener === handler) {
36
- readerColorsListener = null;
76
+ const { containerRef } = useEpubReaderState();
77
+ const hydrate = async () => {
78
+ if (hydrated || !activePreferences?.load) {
79
+ hydrated = true;
80
+ return;
37
81
  }
82
+ const loaded = await activePreferences.load();
83
+ Object.assign(settings, loaded ?? {});
84
+ hydrated = true;
85
+ };
86
+ const onSettingsChange = (handler) => {
87
+ listeners.add(handler);
88
+ return () => listeners.delete(handler);
89
+ };
90
+ const toggleFullscreen = () => {
91
+ const el = containerRef.value?.parentElement;
92
+ if (!el) {
93
+ return;
94
+ }
95
+ if (!document.fullscreenElement) {
96
+ el.requestFullscreen()
97
+ .then(() => {
98
+ settings.isFullscreen = true;
99
+ })
100
+ .catch(() => { });
101
+ return;
102
+ }
103
+ document
104
+ .exitFullscreen()
105
+ .then(() => {
106
+ settings.isFullscreen = false;
107
+ })
108
+ .catch(() => { });
109
+ };
110
+ return {
111
+ settings,
112
+ hydrate,
113
+ onSettingsChange,
114
+ toggleFullscreen,
38
115
  };
39
- };
40
- export const useReaderSettings = (controller) => {
41
- return useEpubReaderSettings(controller);
42
116
  };
@@ -1,13 +1,10 @@
1
- export type { TocEntry, ReaderSettings, ReaderAssetConfig, EpubReaderStrategy, ReaderStorageAdapter, ReaderPreferencesAdapter, EpubReaderControllerOptions, } from '../src/types';
2
- export { createEpubReaderController } from '../src/core/controller';
3
- export { createSessionStorageAdapter } from '../src/core/storage';
1
+ export type { TocEntry, ReaderSettings, ReaderAssetConfig, EpubReaderStrategy, ReaderStorageAdapter, ReaderPreferencesAdapter, EpubReaderOptions, } from '../src/types/common';
2
+ export { createSessionStorageAdapter } from '../src/services/common/storage';
4
3
  export { useEpubReader } from '../src/composables/useEpubReader';
5
- export { useEpubReaderSettings } from '../src/composables/useEpubReaderSettings';
6
- export { useEpubReaderController } from '../src/composables/useEpubReaderController';
4
+ export { useEpubReaderState } from '../src/composables/useEpubReaderState';
7
5
  export { useEpubReaderNavigation } from '../src/composables/useEpubReaderNavigation';
8
- export { useEpubReaderState, setEpubReaderController, useEpubReaderControllerRef, } from '../src/composables/useEpubReaderState';
9
- export { setReaderColors, getReaderColors, useReaderSettings, } from '../src/composables/useReaderSettings';
6
+ export { useReaderSettings, ALIGN_OPTIONS, COLUMN_OPTIONS, PX_FONT_SIZE_OPTIONS, EPUB_FONT_SIZE_OPTIONS, } from '../src/composables/useReaderSettings';
7
+ export { setReaderColors, getReaderColors } from '../src/composables/useReaderColors';
10
8
  export { setReaderDictionary, hasReaderDictionary, useReaderDictionary, } from '../src/composables/useReaderDictionary';
11
9
  export type { ReaderDictionaryApi, ReaderDictionaryWordStatus, } from '../src/composables/useReaderDictionary';
12
- export { ALIGN_OPTIONS, COLUMN_OPTIONS, PX_FONT_SIZE_OPTIONS, EPUB_FONT_SIZE_OPTIONS, } from '../src/settings/options';
13
- export { setWasmStreamerConfig, ensureSW as ensureEpubServiceWorker, } from '../services/wasm/wasm-streamer';
10
+ export { setWasmStreamerConfig, ensureSW as ensureEpubServiceWorker, } from '../src/services/wasm/wasm-streamer';
package/dist/src/index.js CHANGED
@@ -1,11 +1,8 @@
1
- export { createEpubReaderController } from '../src/core/controller';
2
- export { createSessionStorageAdapter } from '../src/core/storage';
1
+ export { createSessionStorageAdapter } from '../src/services/common/storage';
3
2
  export { useEpubReader } from '../src/composables/useEpubReader';
4
- export { useEpubReaderSettings } from '../src/composables/useEpubReaderSettings';
5
- export { useEpubReaderController } from '../src/composables/useEpubReaderController';
3
+ export { useEpubReaderState } from '../src/composables/useEpubReaderState';
6
4
  export { useEpubReaderNavigation } from '../src/composables/useEpubReaderNavigation';
7
- export { useEpubReaderState, setEpubReaderController, useEpubReaderControllerRef, } from '../src/composables/useEpubReaderState';
8
- export { setReaderColors, getReaderColors, useReaderSettings, } from '../src/composables/useReaderSettings';
5
+ export { useReaderSettings, ALIGN_OPTIONS, COLUMN_OPTIONS, PX_FONT_SIZE_OPTIONS, EPUB_FONT_SIZE_OPTIONS, } from '../src/composables/useReaderSettings';
6
+ export { setReaderColors, getReaderColors } from '../src/composables/useReaderColors';
9
7
  export { setReaderDictionary, hasReaderDictionary, useReaderDictionary, } from '../src/composables/useReaderDictionary';
10
- export { ALIGN_OPTIONS, COLUMN_OPTIONS, PX_FONT_SIZE_OPTIONS, EPUB_FONT_SIZE_OPTIONS, } from '../src/settings/options';
11
- export { setWasmStreamerConfig, ensureSW as ensureEpubServiceWorker, } from '../services/wasm/wasm-streamer';
8
+ export { setWasmStreamerConfig, ensureSW as ensureEpubServiceWorker, } from '../src/services/wasm/wasm-streamer';
@@ -1,4 +1,4 @@
1
- import type { ZipData } from '../../types/browser';
1
+ import type { ZipData } from '../../../src/types/browser';
2
2
  declare const fetchEpub: (url: string) => Promise<ArrayBuffer>;
3
3
  declare const unzipEpub: (buf: ArrayBuffer) => Promise<ZipData>;
4
4
  export { fetchEpub, unzipEpub };
@@ -1,4 +1,4 @@
1
- import type { ZipData } from '../../types/browser';
1
+ import type { ZipData } from '../../../src/types/browser';
2
2
  import { Manifest } from '@readium/shared';
3
3
  /**
4
4
  * Build a RWPM Manifest from the OPF file and related resources in the zip.
@@ -1,5 +1,5 @@
1
1
  import { Link, Links, Metadata, Manifest, Contributor, Contributors, LocalizedString, ReadingProgression, } from '@readium/shared';
2
- import { guessMediaType, getExt, resolveHref } from '../../services/browser/url';
2
+ import { guessMediaType, getExt, resolveHref } from '../../../src/services/browser/url';
3
3
  const parseNavDoc = (html, baseDir) => {
4
4
  const doc = new DOMParser().parseFromString(html, 'text/html');
5
5
  const nav = doc.querySelector('nav[epub\\:type="toc"]') ??
@@ -1,4 +1,4 @@
1
- import type { ZipData } from '../../types/browser';
1
+ import type { ZipData } from '../../../src/types/browser';
2
2
  declare const clearBlobUrlCache: () => void;
3
3
  declare const rewriteXhtmlUrls: (doc: Document, resourceHref: string, zip: ZipData) => void;
4
4
  declare const rewriteCssUrls: (css: string, resourceHref: string, zip: ZipData) => string;
@@ -1,4 +1,4 @@
1
- import { getExt, resolveHref, parseSrcset, guessMediaType, } from '../../services/browser/url';
1
+ import { getExt, resolveHref, parseSrcset, guessMediaType, } from '../../../src/services/browser/url';
2
2
  const blobUrlCache = new Map();
3
3
  const getBlobUrl = (zip, path) => {
4
4
  const existing = blobUrlCache.get(path);
@@ -1,5 +1,5 @@
1
1
  import type { Fetcher } from '@readium/shared';
2
- import type { ZipData } from '../../types/browser';
2
+ import type { ZipData } from '../../../src/types/browser';
3
3
  import { Link } from '@readium/shared';
4
4
  import { Resource } from '@readium/shared';
5
5
  declare class ZipFetcher implements Fetcher {
@@ -1,7 +1,7 @@
1
1
  import { Link } from '@readium/shared';
2
2
  import { Resource } from '@readium/shared';
3
- import { guessMediaType, getExt } from '../../services/browser/url';
4
- import { rewriteCssUrls, rewriteXhtmlUrls, clearBlobUrlCache, } from '../../services/browser/url-rewrite';
3
+ import { guessMediaType, getExt } from '../../../src/services/browser/url';
4
+ import { rewriteCssUrls, rewriteXhtmlUrls, clearBlobUrlCache, } from '../../../src/services/browser/url-rewrite';
5
5
  const isHtmlType = (path) => {
6
6
  const ext = getExt(path);
7
7
  return ext === 'xhtml' || ext === 'html' || ext === 'htm' || ext === 'svg';
@@ -1,5 +1,5 @@
1
- import type { ZipData } from '../../types/browser';
2
- import type { ChapterBoundary } from '../../types/common';
1
+ import type { ZipData } from '../../../src/types/browser';
2
+ import type { ChapterBoundary } from '../../../src/types/common';
3
3
  import { Link, Locator, Publication } from '@readium/shared';
4
4
  /**
5
5
  * Scan the content files referenced by TOC entries and compute
@@ -20,13 +20,5 @@ declare const buildWeightsFromResolver: (pub: Publication, resolveSize: (href: s
20
20
  progress: number;
21
21
  resourceProgression: number;
22
22
  });
23
- /**
24
- * Save the current position (spine index and progression) for the given URL in sessionStorage.
25
- */
26
- declare const savePosition: (url: string, persisted: Locator) => void;
27
- /**
28
- * Restore the saved position for the given URL from sessionStorage.
29
- */
30
- declare const restorePosition: (url: string, publication: Publication) => Locator | undefined;
31
23
  declare const computePublicationChaptersSize: (publication: Publication) => Promise<Map<string, number>>;
32
- export { savePosition, restorePosition, generatePositions, buildWeightsFromZip, buildWeightsFromResolver, computeChapterProgressions, computePublicationChaptersSize, };
24
+ export { generatePositions, buildWeightsFromZip, buildWeightsFromResolver, computeChapterProgressions, computePublicationChaptersSize, };
@@ -121,37 +121,6 @@ const buildWeightsFromResolver = (pub, resolveSize) => {
121
121
  }));
122
122
  return buildWeightedProgressCalculator(resourceWeights);
123
123
  };
124
- /**
125
- * Save the current position (spine index and progression) for the given URL in sessionStorage.
126
- */
127
- const savePosition = (url, persisted) => {
128
- sessionStorage.setItem(`epub-locator:${url}`, JSON.stringify(persisted.serialize()));
129
- };
130
- /**
131
- * Restore the saved position for the given URL from sessionStorage.
132
- */
133
- const restorePosition = (url, publication) => {
134
- const saved = sessionStorage.getItem(`epub-locator:${url}`);
135
- if (saved) {
136
- const raw = JSON.parse(saved);
137
- const parsed = Locator.deserialize(raw);
138
- if (parsed) {
139
- const href = parsed.href;
140
- const idx = publication.readingOrder.findIndexWithHref(href) ?? -1;
141
- if (idx >= 0) {
142
- const prog = parsed.locations?.progression !== undefined &&
143
- parsed.locations.progression >= 0 &&
144
- parsed.locations.progression <= 1
145
- ? parsed.locations.progression
146
- : 0;
147
- return parsed.copyWithLocations({
148
- position: idx + 1,
149
- progression: prog,
150
- });
151
- }
152
- }
153
- }
154
- };
155
124
  const computePublicationChaptersSize = async (publication) => {
156
125
  const resourceSizes = new Map();
157
126
  await Promise.all(publication.readingOrder.items.map(async (item) => {
@@ -166,4 +135,4 @@ const computePublicationChaptersSize = async (publication) => {
166
135
  }));
167
136
  return resourceSizes;
168
137
  };
169
- export { savePosition, restorePosition, generatePositions, buildWeightsFromZip, buildWeightsFromResolver, computeChapterProgressions, computePublicationChaptersSize, };
138
+ export { generatePositions, buildWeightsFromZip, buildWeightsFromResolver, computeChapterProgressions, computePublicationChaptersSize, };
@@ -1,2 +1,2 @@
1
- import type { ReaderStorageAdapter } from '../../src/types';
1
+ import type { ReaderStorageAdapter } from '../../../src/types/common';
2
2
  export declare const createSessionStorageAdapter: () => ReaderStorageAdapter;
@@ -14,8 +14,7 @@ export const createSessionStorageAdapter = () => {
14
14
  if (!parsed) {
15
15
  return undefined;
16
16
  }
17
- const idx = publication.readingOrder.findIndexWithHref(parsed.href) ??
18
- -1;
17
+ const idx = publication.readingOrder.findIndexWithHref(parsed.href) ?? -1;
19
18
  if (idx < 0) {
20
19
  return undefined;
21
20
  }
@@ -1,5 +1,5 @@
1
1
  import type { Locator } from '@readium/shared';
2
- import type { TocEntry, ChapterBoundary } from '../../types/common';
2
+ import type { TocEntry, ChapterBoundary } from '../../../src/types/common';
3
3
  /**
4
4
  * Determine chapter title:
5
5
  * 1. Progression-based lookup (single-file multi-chapter books)
@@ -1,4 +1,4 @@
1
1
  import type { Ref } from 'vue';
2
2
  import type { EpubNavigator } from '@readium/navigator';
3
- import type { ReadiumWordDecorationsController } from '../../types/common';
3
+ import type { ReadiumWordDecorationsController } from '../../../src/types/common';
4
4
  export declare const createReadiumWordDecorationsController: (navigatorRef: Ref<EpubNavigator | null>, languageRef: () => string | undefined) => ReadiumWordDecorationsController;
@@ -1,7 +1,7 @@
1
1
  import { toRaw } from 'vue';
2
2
  import { debounce } from 'lodash';
3
- import { getReaderColors } from '../../src/composables/useReaderSettings';
4
- import { useReaderDictionary } from '../../src/composables/useReaderDictionary';
3
+ import { getReaderColors } from '../../../src/composables/useReaderColors';
4
+ import { useReaderDictionary } from '../../../src/composables/useReaderDictionary';
5
5
  const GROUP_KNOWN = 'known-words-known';
6
6
  const GROUP_UNKNOWN = 'known-words-unknown';
7
7
  const MAX_VISIBLE_WORDS = 2000;
@@ -1,4 +1,4 @@
1
- import { useReaderDictionary } from '../../src/composables/useReaderDictionary';
1
+ import { useReaderDictionary } from '../../../src/composables/useReaderDictionary';
2
2
  const EPUB_WORD_REGEX = /[a-zA-Z0-9\u00C0-\u00FF]+(?:[’']?[a-zA-Z\u00C0-\u00FF]+)?/g;
3
3
  const normalizeLookupText = (text) => {
4
4
  return text.replace(/\s+/g, ' ').trim();
@@ -1,4 +1,5 @@
1
- import type { Link } from '@readium/shared';
1
+ import type { TextAlignment } from '@readium/navigator';
2
+ import type { Link, Locator, Publication } from '@readium/shared';
2
3
  export type ChapterBoundary = {
3
4
  title: string;
4
5
  /** Normalised progression (0–1) where this chapter starts in the file. */
@@ -52,4 +53,38 @@ export type ReadiumWordDecorationsController = {
52
53
  refresh: () => Promise<void>;
53
54
  destroy: () => void;
54
55
  };
56
+ export type EpubReaderStrategy = 'wasm' | 'zip-fetcher';
57
+ export type ReaderSettings = {
58
+ backgroundColor: string | null;
59
+ columnCount: number | null;
60
+ fontFamily: string | null;
61
+ fontSize: number | null;
62
+ isFullscreen: boolean;
63
+ lineHeight: number | null;
64
+ scroll: boolean | null;
65
+ textAlign: TextAlignment | null;
66
+ textColor: string | null;
67
+ };
68
+ export type ReaderStorageAdapter = {
69
+ savePosition: (key: string, locator: Locator) => void;
70
+ restorePosition: (key: string, publication: Publication) => Locator | undefined;
71
+ };
72
+ export type ReaderPreferencesAdapter = {
73
+ load: () => Partial<ReaderSettings> | Promise<Partial<ReaderSettings>>;
74
+ save?: (settings: Readonly<ReaderSettings>) => void | Promise<void>;
75
+ };
76
+ export type ReaderAssetConfig = {
77
+ swUrl?: string;
78
+ swScope?: string;
79
+ wasmUrl?: string;
80
+ fontBaseUrl?: string;
81
+ };
82
+ export type EpubReaderOptions = {
83
+ strategy?: EpubReaderStrategy;
84
+ settings?: Partial<ReaderSettings>;
85
+ storage?: ReaderStorageAdapter;
86
+ preferences?: ReaderPreferencesAdapter;
87
+ assets?: ReaderAssetConfig;
88
+ logNamespace?: string;
89
+ };
55
90
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caipira/vue-reader",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "private": false,
5
5
  "description": "Headless e-book reader toolkit for vue",
6
6
  "author": {