2021-10-18 01:05:43 +02:00
|
|
|
|
<template>
|
2022-12-17 23:36:41 +01:00
|
|
|
|
<div v-if="show" class="w-screen h-screen fixed top-0 left-0 z-60 bg-primary text-white">
|
2023-03-22 11:16:01 +01:00
|
|
|
|
<div class="absolute top-4 left-4 z-20">
|
2023-03-24 23:57:41 +01:00
|
|
|
|
<span v-if="hasToC && !tocOpen" ref="tocButton" class="material-icons cursor-pointer text-2xl" @click="toggleToC">menu</span>
|
2021-10-18 01:05:43 +02:00
|
|
|
|
</div>
|
|
|
|
|
|
2023-03-22 11:16:01 +01:00
|
|
|
|
<div class="absolute top-4 left-1/2 transform -translate-x-1/2">
|
2023-03-26 21:44:59 +02:00
|
|
|
|
<h1 class="text-lg sm:text-xl md:text-2xl mb-1" style="line-height: 1.15; font-weight: 100">
|
2023-03-22 11:16:01 +01:00
|
|
|
|
<span style="font-weight: 600">{{ abTitle }}</span>
|
|
|
|
|
<span v-if="abAuthor" style="display: inline"> – </span>
|
|
|
|
|
<span v-if="abAuthor">{{ abAuthor }}</span>
|
|
|
|
|
</h1>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="absolute top-4 right-4 z-20">
|
|
|
|
|
<span v-if="hasSettings" class="material-icons cursor-pointer text-2xl" @click="openSettings">settings</span>
|
|
|
|
|
<span class="material-icons cursor-pointer text-2xl" @click="close">close</span>
|
2021-10-18 01:05:43 +02:00
|
|
|
|
</div>
|
|
|
|
|
|
2023-03-24 23:57:41 +01:00
|
|
|
|
<component v-if="componentName" ref="readerComponent" :is="componentName" :url="ebookUrl" :library-item="selectedLibraryItem" />
|
2023-03-22 11:16:01 +01:00
|
|
|
|
|
2023-03-24 23:57:41 +01:00
|
|
|
|
<!-- TOC side nav -->
|
|
|
|
|
<div v-if="tocOpen" class="w-full h-full fixed inset-0 bg-black/20 z-20" @click.stop.prevent="toggleToC"></div>
|
|
|
|
|
<div v-if="hasToC" class="w-72 h-full max-h-full absolute top-0 left-0 bg-bg shadow-xl transition-transform z-30" :class="tocOpen ? 'translate-x-0' : '-translate-x-72'" @click.stop.prevent="toggleToC">
|
|
|
|
|
<div class="p-4 h-full overflow-hidden">
|
|
|
|
|
<p class="text-lg font-semibold mb-2">Table of Contents</p>
|
|
|
|
|
<div class="tocContent">
|
2023-03-22 11:16:01 +01:00
|
|
|
|
<ul>
|
2023-03-24 23:57:41 +01:00
|
|
|
|
<li v-for="chapter in chapters" :key="chapter.id" class="py-1">
|
|
|
|
|
<a :href="chapter.href" @click.prevent="$refs.readerComponent.goToChapter(chapter.href)">{{ chapter.label }}</a>
|
2023-03-22 11:16:01 +01:00
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-10-18 01:05:43 +02:00
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
2023-03-22 11:16:01 +01:00
|
|
|
|
return {
|
|
|
|
|
chapters: [],
|
|
|
|
|
tocOpen: false
|
|
|
|
|
}
|
2021-10-18 01:05:43 +02:00
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
show(newVal) {
|
|
|
|
|
if (newVal) {
|
|
|
|
|
this.init()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
show: {
|
|
|
|
|
get() {
|
|
|
|
|
return this.$store.state.showEReader
|
|
|
|
|
},
|
|
|
|
|
set(val) {
|
|
|
|
|
this.$store.commit('setShowEReader', val)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
componentName() {
|
2023-03-21 13:27:21 +01:00
|
|
|
|
if (this.ebookType === 'epub') return 'readers-epub-reader'
|
2021-10-18 01:05:43 +02:00
|
|
|
|
else if (this.ebookType === 'mobi') return 'readers-mobi-reader'
|
|
|
|
|
else if (this.ebookType === 'pdf') return 'readers-pdf-reader'
|
|
|
|
|
else if (this.ebookType === 'comic') return 'readers-comic-reader'
|
|
|
|
|
return null
|
|
|
|
|
},
|
2023-03-22 11:16:01 +01:00
|
|
|
|
hasToC() {
|
|
|
|
|
return this.isEpub
|
|
|
|
|
},
|
|
|
|
|
hasSettings() {
|
|
|
|
|
return false
|
|
|
|
|
},
|
2021-10-18 01:05:43 +02:00
|
|
|
|
abTitle() {
|
2022-04-13 15:26:43 +02:00
|
|
|
|
return this.mediaMetadata.title
|
2021-10-18 01:05:43 +02:00
|
|
|
|
},
|
|
|
|
|
abAuthor() {
|
2022-04-13 15:26:43 +02:00
|
|
|
|
return this.mediaMetadata.authorName
|
2021-10-18 01:05:43 +02:00
|
|
|
|
},
|
2022-03-14 01:34:31 +01:00
|
|
|
|
selectedLibraryItem() {
|
2022-04-13 15:26:43 +02:00
|
|
|
|
return this.$store.state.selectedLibraryItem || {}
|
|
|
|
|
},
|
|
|
|
|
media() {
|
|
|
|
|
return this.selectedLibraryItem.media || {}
|
|
|
|
|
},
|
|
|
|
|
mediaMetadata() {
|
|
|
|
|
return this.media.metadata || {}
|
2021-10-18 01:05:43 +02:00
|
|
|
|
},
|
|
|
|
|
libraryId() {
|
2022-03-14 01:34:31 +01:00
|
|
|
|
return this.selectedLibraryItem.libraryId
|
2021-10-18 01:05:43 +02:00
|
|
|
|
},
|
|
|
|
|
folderId() {
|
2022-03-14 01:34:31 +01:00
|
|
|
|
return this.selectedLibraryItem.folderId
|
2021-10-18 01:05:43 +02:00
|
|
|
|
},
|
2022-04-13 15:26:43 +02:00
|
|
|
|
ebookFile() {
|
|
|
|
|
return this.media.ebookFile
|
|
|
|
|
},
|
|
|
|
|
ebookFormat() {
|
|
|
|
|
if (!this.ebookFile) return null
|
|
|
|
|
return this.ebookFile.ebookFormat
|
|
|
|
|
},
|
|
|
|
|
ebookType() {
|
|
|
|
|
if (this.isMobi) return 'mobi'
|
|
|
|
|
else if (this.isEpub) return 'epub'
|
|
|
|
|
else if (this.isPdf) return 'pdf'
|
|
|
|
|
else if (this.isComic) return 'comic'
|
|
|
|
|
return null
|
2021-10-18 01:05:43 +02:00
|
|
|
|
},
|
2022-04-13 15:26:43 +02:00
|
|
|
|
isEpub() {
|
|
|
|
|
return this.ebookFormat == 'epub'
|
2021-10-18 01:05:43 +02:00
|
|
|
|
},
|
2022-04-13 15:26:43 +02:00
|
|
|
|
isMobi() {
|
|
|
|
|
return this.ebookFormat == 'mobi' || this.ebookFormat == 'azw3'
|
2021-10-18 01:05:43 +02:00
|
|
|
|
},
|
2022-04-13 15:26:43 +02:00
|
|
|
|
isPdf() {
|
|
|
|
|
return this.ebookFormat == 'pdf'
|
2021-10-18 01:05:43 +02:00
|
|
|
|
},
|
2022-04-13 15:26:43 +02:00
|
|
|
|
isComic() {
|
|
|
|
|
return this.ebookFormat == 'cbz' || this.ebookFormat == 'cbr'
|
|
|
|
|
},
|
|
|
|
|
ebookUrl() {
|
|
|
|
|
if (!this.ebookFile) return null
|
2022-11-30 23:15:25 +01:00
|
|
|
|
let filepath = ''
|
|
|
|
|
if (this.selectedLibraryItem.isFile) {
|
|
|
|
|
filepath = this.$encodeUriPath(this.ebookFile.metadata.filename)
|
|
|
|
|
} else {
|
|
|
|
|
const itemRelPath = this.selectedLibraryItem.relPath
|
|
|
|
|
if (itemRelPath.startsWith('/')) itemRelPath = itemRelPath.slice(1)
|
|
|
|
|
const relPath = this.ebookFile.metadata.relPath
|
|
|
|
|
if (relPath.startsWith('/')) relPath = relPath.slice(1)
|
2022-10-05 00:29:26 +02:00
|
|
|
|
|
2022-11-30 23:15:25 +01:00
|
|
|
|
filepath = this.$encodeUriPath(`${itemRelPath}/${relPath}`)
|
|
|
|
|
}
|
|
|
|
|
return `/ebook/${this.libraryId}/${this.folderId}/${filepath}`
|
2021-10-18 01:05:43 +02:00
|
|
|
|
},
|
|
|
|
|
userToken() {
|
|
|
|
|
return this.$store.getters['user/getToken']
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
2023-03-22 11:16:01 +01:00
|
|
|
|
toggleToC() {
|
2023-03-24 23:57:41 +01:00
|
|
|
|
this.tocOpen = !this.tocOpen
|
|
|
|
|
this.chapters = this.$refs.readerComponent.chapters
|
2023-03-22 11:16:01 +01:00
|
|
|
|
},
|
2023-03-24 23:57:41 +01:00
|
|
|
|
openSettings() {},
|
2021-10-23 23:49:34 +02:00
|
|
|
|
hotkey(action) {
|
|
|
|
|
console.log('Reader hotkey', action)
|
|
|
|
|
if (!this.$refs.readerComponent) return
|
|
|
|
|
|
2021-10-24 21:02:49 +02:00
|
|
|
|
if (action === this.$hotkeys.EReader.NEXT_PAGE) {
|
2023-03-26 21:44:59 +02:00
|
|
|
|
this.next()
|
2021-10-24 21:02:49 +02:00
|
|
|
|
} else if (action === this.$hotkeys.EReader.PREV_PAGE) {
|
2023-03-26 21:44:59 +02:00
|
|
|
|
this.prev()
|
2021-10-24 21:02:49 +02:00
|
|
|
|
} else if (action === this.$hotkeys.EReader.CLOSE) {
|
2021-10-23 23:49:34 +02:00
|
|
|
|
this.close()
|
2021-10-18 01:05:43 +02:00
|
|
|
|
}
|
|
|
|
|
},
|
2023-03-26 21:44:59 +02:00
|
|
|
|
next() {
|
|
|
|
|
if (this.$refs.readerComponent?.next) this.$refs.readerComponent.next()
|
|
|
|
|
},
|
|
|
|
|
prev() {
|
|
|
|
|
if (this.$refs.readerComponent?.prev) this.$refs.readerComponent.prev()
|
|
|
|
|
},
|
2021-10-18 01:05:43 +02:00
|
|
|
|
registerListeners() {
|
2021-10-23 23:49:34 +02:00
|
|
|
|
this.$eventBus.$on('reader-hotkey', this.hotkey)
|
2021-10-18 01:05:43 +02:00
|
|
|
|
},
|
|
|
|
|
unregisterListeners() {
|
2021-10-23 23:49:34 +02:00
|
|
|
|
this.$eventBus.$off('reader-hotkey', this.hotkey)
|
2021-10-18 01:05:43 +02:00
|
|
|
|
},
|
|
|
|
|
init() {
|
|
|
|
|
this.registerListeners()
|
|
|
|
|
},
|
|
|
|
|
close() {
|
2021-10-23 23:49:34 +02:00
|
|
|
|
this.unregisterListeners()
|
|
|
|
|
this.show = false
|
2021-10-18 01:05:43 +02:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
if (this.show) this.init()
|
|
|
|
|
},
|
|
|
|
|
beforeDestroy() {
|
2021-10-23 23:49:34 +02:00
|
|
|
|
this.unregisterListeners()
|
2021-10-18 01:05:43 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
/* @import url(@/assets/calibre/basic.css); */
|
|
|
|
|
.ebook-viewer {
|
|
|
|
|
height: calc(100% - 96px);
|
|
|
|
|
}
|
2023-03-24 23:57:41 +01:00
|
|
|
|
.tocContent {
|
|
|
|
|
height: calc(100% - 36px);
|
|
|
|
|
overflow-y: auto;
|
|
|
|
|
}
|
2021-10-18 01:05:43 +02:00
|
|
|
|
</style>
|