@caipira/vue-reader 0.0.3 → 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/dist/src/composables/useEpubReader.js +1 -5
- package/dist/src/composables/useReaderSettings.d.ts +2 -8
- package/dist/src/composables/useReaderSettings.js +27 -42
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.js +1 -1
- package/dist/src/types/common.d.ts +4 -4
- package/package.json +1 -1
|
@@ -20,10 +20,7 @@ export const useEpubReader = (src, containerRef, options) => {
|
|
|
20
20
|
const sourceRef = computed(() => toValue(src));
|
|
21
21
|
const storage = options?.storage ?? createSessionStorageAdapter();
|
|
22
22
|
const fontBaseUrl = options?.assets?.fontBaseUrl ?? '/fonts';
|
|
23
|
-
const { settings,
|
|
24
|
-
initialSettings: options?.settings,
|
|
25
|
-
preferences: options?.preferences,
|
|
26
|
-
});
|
|
23
|
+
const { settings, onSettingsChange } = useReaderSettings(options?.preferences);
|
|
27
24
|
let stopSettingsWatcher = null;
|
|
28
25
|
let activeChapterHref = '';
|
|
29
26
|
let chapterProgressions = new Map();
|
|
@@ -95,7 +92,6 @@ export const useEpubReader = (src, containerRef, options) => {
|
|
|
95
92
|
if (!containerRef.value) {
|
|
96
93
|
return;
|
|
97
94
|
}
|
|
98
|
-
await hydrate();
|
|
99
95
|
loading.value = true;
|
|
100
96
|
error.value = null;
|
|
101
97
|
try {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ReaderPreferences, ReaderSettings } from '../../src/types/common';
|
|
2
2
|
import { TextAlignment } from '@readium/navigator';
|
|
3
3
|
export declare const EPUB_FONT_SIZE_OPTIONS: {
|
|
4
4
|
value: number;
|
|
@@ -19,11 +19,7 @@ export declare const ALIGN_OPTIONS: ({
|
|
|
19
19
|
key: TextAlignment;
|
|
20
20
|
label: string;
|
|
21
21
|
})[];
|
|
22
|
-
|
|
23
|
-
initialSettings?: Partial<ReaderSettings>;
|
|
24
|
-
preferences?: ReaderPreferencesAdapter;
|
|
25
|
-
};
|
|
26
|
-
export declare const useReaderSettings: (options?: UseReaderSettingsOptions) => {
|
|
22
|
+
export declare const useReaderSettings: (options?: ReaderPreferences) => {
|
|
27
23
|
settings: {
|
|
28
24
|
backgroundColor: string | null;
|
|
29
25
|
columnCount: number | null;
|
|
@@ -35,8 +31,6 @@ export declare const useReaderSettings: (options?: UseReaderSettingsOptions) =>
|
|
|
35
31
|
textAlign: TextAlignment | null;
|
|
36
32
|
textColor: string | null;
|
|
37
33
|
};
|
|
38
|
-
hydrate: () => Promise<void>;
|
|
39
34
|
onSettingsChange: (handler: (next: Readonly<ReaderSettings>) => void) => () => boolean;
|
|
40
35
|
toggleFullscreen: () => void;
|
|
41
36
|
};
|
|
42
|
-
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TextAlignment } from '@readium/navigator';
|
|
2
|
-
import { reactive, watch } from 'vue';
|
|
2
|
+
import { reactive, ref, watch } from 'vue';
|
|
3
3
|
import { getReaderColors } from '../../src/composables/useReaderColors';
|
|
4
4
|
import { useEpubReaderState } from '../../src/composables/useEpubReaderState';
|
|
5
5
|
export const EPUB_FONT_SIZE_OPTIONS = [
|
|
@@ -41,52 +41,38 @@ const settings = reactive({
|
|
|
41
41
|
isFullscreen: false,
|
|
42
42
|
});
|
|
43
43
|
const listeners = new Set();
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
settings.backgroundColor,
|
|
60
|
-
settings.textColor,
|
|
61
|
-
settings.isFullscreen,
|
|
62
|
-
], () => {
|
|
63
|
-
listeners.forEach((handler) => handler(settings));
|
|
64
|
-
void activePreferences?.save?.(settings);
|
|
65
|
-
});
|
|
66
|
-
};
|
|
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
|
+
});
|
|
67
59
|
export const useReaderSettings = (options) => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
const { containerRef } = useEpubReaderState();
|
|
77
|
-
const hydrate = async () => {
|
|
78
|
-
if (hydrated || !activePreferences?.load) {
|
|
79
|
-
hydrated = true;
|
|
80
|
-
return;
|
|
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 ?? {});
|
|
81
67
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
};
|
|
68
|
+
// Then only set the new options
|
|
69
|
+
currentOptions.value = options;
|
|
70
|
+
}
|
|
86
71
|
const onSettingsChange = (handler) => {
|
|
87
72
|
listeners.add(handler);
|
|
88
73
|
return () => listeners.delete(handler);
|
|
89
74
|
};
|
|
75
|
+
const { containerRef } = useEpubReaderState();
|
|
90
76
|
const toggleFullscreen = () => {
|
|
91
77
|
const el = containerRef.value?.parentElement;
|
|
92
78
|
if (!el) {
|
|
@@ -109,7 +95,6 @@ export const useReaderSettings = (options) => {
|
|
|
109
95
|
};
|
|
110
96
|
return {
|
|
111
97
|
settings,
|
|
112
|
-
hydrate,
|
|
113
98
|
onSettingsChange,
|
|
114
99
|
toggleFullscreen,
|
|
115
100
|
};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export type { TocEntry, ReaderSettings, ReaderAssetConfig, EpubReaderStrategy, ReaderStorageAdapter,
|
|
2
|
-
export { createSessionStorageAdapter } from '../src/services/common/storage';
|
|
1
|
+
export type { TocEntry, ReaderSettings, ReaderAssetConfig, EpubReaderOptions, EpubReaderStrategy, ReaderStorageAdapter, } from '../src/types/common';
|
|
3
2
|
export { useEpubReader } from '../src/composables/useEpubReader';
|
|
4
3
|
export { useEpubReaderState } from '../src/composables/useEpubReaderState';
|
|
5
4
|
export { useEpubReaderNavigation } from '../src/composables/useEpubReaderNavigation';
|
|
5
|
+
export { createSessionStorageAdapter } from '../src/services/common/storage';
|
|
6
6
|
export { useReaderSettings, ALIGN_OPTIONS, COLUMN_OPTIONS, PX_FONT_SIZE_OPTIONS, EPUB_FONT_SIZE_OPTIONS, } from '../src/composables/useReaderSettings';
|
|
7
7
|
export { setReaderColors, getReaderColors } from '../src/composables/useReaderColors';
|
|
8
8
|
export { setReaderDictionary, hasReaderDictionary, useReaderDictionary, } from '../src/composables/useReaderDictionary';
|
package/dist/src/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { createSessionStorageAdapter } from '../src/services/common/storage';
|
|
2
1
|
export { useEpubReader } from '../src/composables/useEpubReader';
|
|
3
2
|
export { useEpubReaderState } from '../src/composables/useEpubReaderState';
|
|
4
3
|
export { useEpubReaderNavigation } from '../src/composables/useEpubReaderNavigation';
|
|
4
|
+
export { createSessionStorageAdapter } from '../src/services/common/storage';
|
|
5
5
|
export { useReaderSettings, ALIGN_OPTIONS, COLUMN_OPTIONS, PX_FONT_SIZE_OPTIONS, EPUB_FONT_SIZE_OPTIONS, } from '../src/composables/useReaderSettings';
|
|
6
6
|
export { setReaderColors, getReaderColors } from '../src/composables/useReaderColors';
|
|
7
7
|
export { setReaderDictionary, hasReaderDictionary, useReaderDictionary, } from '../src/composables/useReaderDictionary';
|
|
@@ -69,9 +69,9 @@ export type ReaderStorageAdapter = {
|
|
|
69
69
|
savePosition: (key: string, locator: Locator) => void;
|
|
70
70
|
restorePosition: (key: string, publication: Publication) => Locator | undefined;
|
|
71
71
|
};
|
|
72
|
-
export type
|
|
73
|
-
load: () => Partial<ReaderSettings
|
|
74
|
-
save?: (settings: Readonly<ReaderSettings>) => void
|
|
72
|
+
export type ReaderPreferences = {
|
|
73
|
+
load: () => Partial<ReaderSettings>;
|
|
74
|
+
save?: (settings: Readonly<ReaderSettings>) => void;
|
|
75
75
|
};
|
|
76
76
|
export type ReaderAssetConfig = {
|
|
77
77
|
swUrl?: string;
|
|
@@ -83,7 +83,7 @@ export type EpubReaderOptions = {
|
|
|
83
83
|
strategy?: EpubReaderStrategy;
|
|
84
84
|
settings?: Partial<ReaderSettings>;
|
|
85
85
|
storage?: ReaderStorageAdapter;
|
|
86
|
-
preferences?:
|
|
86
|
+
preferences?: ReaderPreferences;
|
|
87
87
|
assets?: ReaderAssetConfig;
|
|
88
88
|
logNamespace?: string;
|
|
89
89
|
};
|