diff options
Diffstat (limited to 'viewer')
-rw-r--r-- | viewer/src/views/item_handlers/async/AsyncEpubViewer.vue | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/viewer/src/views/item_handlers/async/AsyncEpubViewer.vue b/viewer/src/views/item_handlers/async/AsyncEpubViewer.vue index 712a844..20b1bee 100644 --- a/viewer/src/views/item_handlers/async/AsyncEpubViewer.vue +++ b/viewer/src/views/item_handlers/async/AsyncEpubViewer.vue | |||
@@ -52,43 +52,50 @@ | |||
52 | </template> | 52 | </template> |
53 | 53 | ||
54 | <script setup lang="ts"> | 54 | <script setup lang="ts"> |
55 | |||
56 | import { EPUBItem } from '@/@types/gallery'; | 55 | import { EPUBItem } from '@/@types/gallery'; |
57 | import { useItemResource } from '@/services/ui/ldItemResourceUrl'; | 56 | import { useItemResource } from '@/services/ui/ldItemResourceUrl'; |
58 | import ePub from 'epubjs'; | 57 | import { useUiStore } from '@/store/uiStore'; |
58 | import ePub, { Rendition } from 'epubjs'; | ||
59 | import { SpineItem } from 'epubjs/types/section'; | 59 | import { SpineItem } from 'epubjs/types/section'; |
60 | import { PropType, Ref, ref, toRef, computed, watchEffect } from 'vue'; | 60 | import { computed, PropType, Ref, ref, toRef, watch } from 'vue'; |
61 | import { useI18n } from 'vue-i18n'; | 61 | import { useI18n } from 'vue-i18n'; |
62 | |||
62 | const { t } = useI18n(); | 63 | const { t } = useI18n(); |
64 | const uiStore = useUiStore(); | ||
63 | 65 | ||
64 | const props = defineProps({ | 66 | const props = defineProps({ |
65 | item: { type: Object as PropType<EPUBItem>, required: true }, | 67 | item: { type: Object as PropType<EPUBItem>, required: true }, |
66 | }); | 68 | }); |
67 | 69 | ||
68 | const { itemResourceUrl } = useItemResource(toRef(props, 'item')); | 70 | const { itemResourceUrl } = useItemResource(toRef(props, 'item')); |
71 | |||
69 | const view = ref<HTMLDivElement>(); | 72 | const view = ref<HTMLDivElement>(); |
73 | const rendition = ref<Rendition>(); | ||
74 | const currSection = ref<SpineItem>(); | ||
75 | const prevSection = ref<SpineItem>(); | ||
76 | const nextSection = ref<SpineItem>(); | ||
70 | 77 | ||
71 | const book = computed(() => ePub(itemResourceUrl.value)); | 78 | const book = computed(() => ePub(itemResourceUrl.value)); |
72 | 79 | ||
73 | const rendition = computed(() => { | 80 | watch([book, view], ([book, view]) => { |
74 | if (!view.value) return; | 81 | if (!view) return; |
75 | return book.value.renderTo(view.value, { | 82 | view.innerHTML = ''; |
83 | rendition.value = book.renderTo(view, { | ||
76 | flow: 'scrolled-doc', | 84 | flow: 'scrolled-doc', |
77 | width: '100%', | 85 | width: '100%', |
78 | fullsize: true, | ||
79 | }); | 86 | }); |
80 | }); | 87 | }); |
81 | 88 | ||
82 | const currSection = ref<SpineItem>(); | 89 | watch(rendition, async(rendition, oldRendition) => { |
83 | const prevSection = ref<SpineItem>(); | 90 | if (!rendition) return; |
84 | const nextSection = ref<SpineItem>(); | 91 | oldRendition?.off('rendered', updateNavigation); |
85 | 92 | await rendition.display(); | |
86 | // TODO: reflow on side panel open/close event, like when resizing the window | 93 | rendition.on('rendered', updateNavigation); |
94 | }); | ||
87 | 95 | ||
88 | watchEffect(async() => { | 96 | watch(() => uiStore.fullWidth, () => { |
89 | if (!rendition.value) return; | 97 | // Simulate a window resize to force EPub to resize the container |
90 | await rendition.value.display(); | 98 | setTimeout(() => window.dispatchEvent(new Event('resize'))); |
91 | rendition.value.on('rendered', updateNavigation); | ||
92 | }); | 99 | }); |
93 | 100 | ||
94 | function updateNavigation(currentSection: SpineItem) { | 101 | function updateNavigation(currentSection: SpineItem) { |