@caipira/vue-reader 0.0.2 → 0.0.4
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/README.md +38 -24
- package/dist/src/composables/useEpubReader.d.ts +5 -27786
- package/dist/src/composables/useEpubReader.js +218 -4
- package/dist/src/composables/useEpubReaderLogging.d.ts +5 -0
- package/dist/src/composables/useEpubReaderLogging.js +27 -0
- package/dist/src/composables/useEpubReaderNavigation.d.ts +3 -3
- package/dist/src/composables/useEpubReaderNavigation.js +8 -15
- package/dist/src/composables/useEpubReaderState.d.ts +27794 -20
- package/dist/src/composables/useEpubReaderState.js +31 -21
- package/dist/{composables → src/composables}/useEpubReaderStrategy.d.ts +1 -1
- package/dist/src/composables/useEpubReaderWasm.d.ts +2 -0
- package/dist/{composables → src/composables}/useEpubReaderWasm.js +5 -5
- package/dist/src/composables/useEpubReaderZipFetcher.d.ts +2 -0
- package/dist/{composables → src/composables}/useEpubReaderZipFetcher.js +5 -5
- package/dist/src/composables/useReaderColors.d.ts +10 -0
- package/dist/src/composables/useReaderColors.js +38 -0
- package/dist/src/composables/useReaderSettings.d.ts +24 -13
- package/dist/src/composables/useReaderSettings.js +97 -38
- package/dist/src/index.d.ts +6 -9
- package/dist/src/index.js +5 -8
- package/dist/{services → src/services}/browser/epub.d.ts +1 -1
- package/dist/{services → src/services}/browser/manifest.d.ts +1 -1
- package/dist/{services → src/services}/browser/manifest.js +1 -1
- package/dist/{services → src/services}/browser/url-rewrite.d.ts +1 -1
- package/dist/{services → src/services}/browser/url-rewrite.js +1 -1
- package/dist/{services → src/services}/browser/zip-fetcher.d.ts +1 -1
- package/dist/{services → src/services}/browser/zip-fetcher.js +2 -2
- package/dist/{services → src/services}/common/progression.d.ts +3 -11
- package/dist/{services → src/services}/common/progression.js +1 -32
- package/dist/src/{core → services/common}/storage.d.ts +1 -1
- package/dist/src/{core → services/common}/storage.js +1 -2
- package/dist/{services → src/services}/common/title.d.ts +1 -1
- package/dist/{services → src/services}/common/word-decorations.d.ts +1 -1
- package/dist/{services → src/services}/common/word-decorations.js +2 -2
- package/dist/{services → src/services}/common/word-lookup.js +1 -1
- package/dist/{types → src/types}/common.d.ts +36 -1
- package/package.json +1 -1
- package/dist/composables/useEpubReaderWasm.d.ts +0 -2
- package/dist/composables/useEpubReaderZipFetcher.d.ts +0 -2
- package/dist/src/composables/useEpubReaderController.d.ts +0 -27787
- package/dist/src/composables/useEpubReaderController.js +0 -23
- package/dist/src/composables/useEpubReaderSettings.d.ts +0 -15
- package/dist/src/composables/useEpubReaderSettings.js +0 -8
- package/dist/src/composables/utils.d.ts +0 -2
- package/dist/src/composables/utils.js +0 -1
- package/dist/src/core/controller.d.ts +0 -27789
- package/dist/src/core/controller.js +0 -262
- package/dist/src/core/settings-store.d.ts +0 -16
- package/dist/src/core/settings-store.js +0 -58
- package/dist/src/settings/options.d.ts +0 -20
- package/dist/src/settings/options.js +0 -27
- package/dist/src/types.d.ts +0 -40
- package/dist/src/types.js +0 -1
- /package/dist/{composables → src/composables}/useEpubReaderStrategy.js +0 -0
- /package/dist/{services → src/services}/browser/epub.js +0 -0
- /package/dist/{services → src/services}/browser/url.d.ts +0 -0
- /package/dist/{services → src/services}/browser/url.js +0 -0
- /package/dist/src/{core → services/common}/fonts.d.ts +0 -0
- /package/dist/src/{core → services/common}/fonts.js +0 -0
- /package/dist/{services → src/services}/common/title.js +0 -0
- /package/dist/{services → src/services}/common/word-lookup.d.ts +0 -0
- /package/dist/{services → src/services}/wasm/frame-document-bridge.d.ts +0 -0
- /package/dist/{services → src/services}/wasm/frame-document-bridge.js +0 -0
- /package/dist/{services → src/services}/wasm/wasm-streamer.d.ts +0 -0
- /package/dist/{services → src/services}/wasm/wasm-streamer.js +0 -0
- /package/dist/{types → src/types}/browser.d.ts +0 -0
- /package/dist/{types → src/types}/browser.js +0 -0
- /package/dist/{types → src/types}/common.js +0 -0
|
@@ -1,29 +1,39 @@
|
|
|
1
|
-
import { computed, ref
|
|
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
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export
|
|
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
|
|
18
|
-
loading
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
error,
|
|
27
|
+
loading,
|
|
28
|
+
logMode,
|
|
29
|
+
tocLinks,
|
|
30
|
+
settings,
|
|
31
|
+
navigator,
|
|
32
|
+
publication,
|
|
22
33
|
containerRef: computed(() => containerRef.value?.value),
|
|
23
|
-
totalPositions
|
|
24
|
-
currentPosition
|
|
25
|
-
progressPercent
|
|
26
|
-
currentChapterTitle
|
|
27
|
-
settings: computed(() => activeState.value?.settings),
|
|
34
|
+
totalPositions,
|
|
35
|
+
currentPosition,
|
|
36
|
+
progressPercent,
|
|
37
|
+
currentChapterTitle,
|
|
28
38
|
};
|
|
29
39
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { resolveHref } from '
|
|
2
|
-
import { computePublicationChaptersSize } from '
|
|
3
|
-
import { loadPublication, createPublication, unloadPublication, } from '
|
|
4
|
-
import { buildWeightsFromResolver } from '
|
|
5
|
-
import { installFrameDocumentBridge } from '
|
|
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 === '' ||
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import ZipFetcher from '
|
|
2
|
-
import { buildManifest } from '
|
|
3
|
-
import { clearBlobUrlCache } from '
|
|
4
|
-
import { fetchEpub, unzipEpub } from '
|
|
5
|
-
import { buildWeightsFromZip, computeChapterProgressions, } from '
|
|
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,25 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export declare const
|
|
1
|
+
import type { ReaderPreferences, 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
|
+
export declare const useReaderSettings: (options?: ReaderPreferences) => {
|
|
12
23
|
settings: {
|
|
13
24
|
backgroundColor: string | null;
|
|
14
25
|
columnCount: number | null;
|
|
@@ -17,9 +28,9 @@ export declare const useReaderSettings: (controller: ReturnTypeCreateController)
|
|
|
17
28
|
isFullscreen: boolean;
|
|
18
29
|
lineHeight: number | null;
|
|
19
30
|
scroll: boolean | null;
|
|
20
|
-
textAlign:
|
|
31
|
+
textAlign: TextAlignment | null;
|
|
21
32
|
textColor: string | null;
|
|
22
33
|
};
|
|
34
|
+
onSettingsChange: (handler: (next: Readonly<ReaderSettings>) => void) => () => boolean;
|
|
23
35
|
toggleFullscreen: () => void;
|
|
24
36
|
};
|
|
25
|
-
export {};
|
|
@@ -1,42 +1,101 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
import { TextAlignment } from '@readium/navigator';
|
|
2
|
+
import { reactive, ref, 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
|
+
const currentOptions = ref();
|
|
45
|
+
watch(() => [
|
|
46
|
+
settings.fontFamily,
|
|
47
|
+
settings.fontSize,
|
|
48
|
+
settings.lineHeight,
|
|
49
|
+
settings.textAlign,
|
|
50
|
+
settings.columnCount,
|
|
51
|
+
settings.scroll,
|
|
52
|
+
settings.backgroundColor,
|
|
53
|
+
settings.textColor,
|
|
54
|
+
settings.isFullscreen,
|
|
55
|
+
], () => {
|
|
56
|
+
listeners.forEach((handler) => handler(settings));
|
|
57
|
+
void currentOptions.value?.save?.(settings);
|
|
58
|
+
});
|
|
59
|
+
export const useReaderSettings = (options) => {
|
|
60
|
+
if (options) {
|
|
61
|
+
// Clear current options to prevent triggering save
|
|
62
|
+
currentOptions.value = undefined;
|
|
63
|
+
// Load the new options
|
|
64
|
+
if (options.load) {
|
|
65
|
+
const loaded = options.load();
|
|
66
|
+
Object.assign(settings, loaded ?? {});
|
|
67
|
+
}
|
|
68
|
+
// Then only set the new options
|
|
69
|
+
currentOptions.value = options;
|
|
25
70
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (readerColorsListener === handler) {
|
|
36
|
-
readerColorsListener = null;
|
|
71
|
+
const onSettingsChange = (handler) => {
|
|
72
|
+
listeners.add(handler);
|
|
73
|
+
return () => listeners.delete(handler);
|
|
74
|
+
};
|
|
75
|
+
const { containerRef } = useEpubReaderState();
|
|
76
|
+
const toggleFullscreen = () => {
|
|
77
|
+
const el = containerRef.value?.parentElement;
|
|
78
|
+
if (!el) {
|
|
79
|
+
return;
|
|
37
80
|
}
|
|
81
|
+
if (!document.fullscreenElement) {
|
|
82
|
+
el.requestFullscreen()
|
|
83
|
+
.then(() => {
|
|
84
|
+
settings.isFullscreen = true;
|
|
85
|
+
})
|
|
86
|
+
.catch(() => { });
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
document
|
|
90
|
+
.exitFullscreen()
|
|
91
|
+
.then(() => {
|
|
92
|
+
settings.isFullscreen = false;
|
|
93
|
+
})
|
|
94
|
+
.catch(() => { });
|
|
95
|
+
};
|
|
96
|
+
return {
|
|
97
|
+
settings,
|
|
98
|
+
onSettingsChange,
|
|
99
|
+
toggleFullscreen,
|
|
38
100
|
};
|
|
39
|
-
};
|
|
40
|
-
export const useReaderSettings = (controller) => {
|
|
41
|
-
return useEpubReaderSettings(controller);
|
|
42
101
|
};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
export type { TocEntry, ReaderSettings, ReaderAssetConfig, EpubReaderStrategy, ReaderStorageAdapter,
|
|
2
|
-
export { createEpubReaderController } from '../src/core/controller';
|
|
3
|
-
export { createSessionStorageAdapter } from '../src/core/storage';
|
|
1
|
+
export type { TocEntry, ReaderSettings, ReaderAssetConfig, EpubReaderOptions, EpubReaderStrategy, ReaderStorageAdapter, } from '../src/types/common';
|
|
4
2
|
export { useEpubReader } from '../src/composables/useEpubReader';
|
|
5
|
-
export {
|
|
6
|
-
export { useEpubReaderController } from '../src/composables/useEpubReaderController';
|
|
3
|
+
export { useEpubReaderState } from '../src/composables/useEpubReaderState';
|
|
7
4
|
export { useEpubReaderNavigation } from '../src/composables/useEpubReaderNavigation';
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
5
|
+
export { createSessionStorageAdapter } from '../src/services/common/storage';
|
|
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 {
|
|
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';
|
|
3
1
|
export { useEpubReader } from '../src/composables/useEpubReader';
|
|
4
|
-
export {
|
|
5
|
-
export { useEpubReaderController } from '../src/composables/useEpubReaderController';
|
|
2
|
+
export { useEpubReaderState } from '../src/composables/useEpubReaderState';
|
|
6
3
|
export { useEpubReaderNavigation } from '../src/composables/useEpubReaderNavigation';
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
4
|
+
export { createSessionStorageAdapter } from '../src/services/common/storage';
|
|
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 {
|
|
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 '
|
|
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,5 +1,5 @@
|
|
|
1
1
|
import { Link, Links, Metadata, Manifest, Contributor, Contributors, LocalizedString, ReadingProgression, } from '@readium/shared';
|
|
2
|
-
import { guessMediaType, getExt, resolveHref } from '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
4
|
-
import { rewriteCssUrls, rewriteXhtmlUrls, clearBlobUrlCache, } from '
|
|
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 '
|
|
2
|
-
import type { ChapterBoundary } from '
|
|
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 {
|
|
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 {
|
|
138
|
+
export { generatePositions, buildWeightsFromZip, buildWeightsFromResolver, computeChapterProgressions, computePublicationChaptersSize, };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { ReaderStorageAdapter } from '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
4
|
-
import { useReaderDictionary } from '
|
|
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 '
|
|
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 {
|
|
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 ReaderPreferences = {
|
|
73
|
+
load: () => Partial<ReaderSettings>;
|
|
74
|
+
save?: (settings: Readonly<ReaderSettings>) => 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?: ReaderPreferences;
|
|
87
|
+
assets?: ReaderAssetConfig;
|
|
88
|
+
logNamespace?: string;
|
|
89
|
+
};
|
|
55
90
|
export {};
|
package/package.json
CHANGED