Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Epub reader dark theme support #10462

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions packages/web-app-epub-reader/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,24 @@
<script lang="ts">
import { defineComponent, nextTick, PropType, ref, unref, watch } from 'vue'
import { Resource } from '@ownclouders/web-client/src/helpers/resource/types'
import { AppConfigObject, Key, useKeyboardActions } from '@ownclouders/web-pkg'
import { AppConfigObject, Key, useKeyboardActions, useThemeStore } from '@ownclouders/web-pkg'
import ePub, { Book, NavItem, Rendition } from 'epubjs'

const DARK_THEME_CONFIG = {
html: {
'-webkit-filter': 'invert(1) hue-rotate(180deg)',
filter: 'invert(1) hue-rotate(180deg)'
},
img: {
'-webkit-filter': 'invert(1) hue-rotate(180deg)',
filter: 'invert(1) hue-rotate(180deg)'
}
}

const LIGHT_THEME_CONFIG = {
html: { background: 'white' }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a placeholder, we can update the theme to our own needs later.
but could also kick that.

FYI @kulmann

}

export default defineComponent({
name: 'EpubReader',
props: {
Expand All @@ -53,6 +68,7 @@ export default defineComponent({
const currentChapter = ref<NavItem>()
const navigateLeftDisabled = ref(true)
const navigateRightDisabled = ref(false)
const themeStore = useThemeStore()
let book: Book
let rendition: Rendition

Expand Down Expand Up @@ -91,7 +107,12 @@ export default defineComponent({
width: 650,
height: '100%'
})

rendition.themes.register('dark', DARK_THEME_CONFIG)
rendition.themes.register('light', LIGHT_THEME_CONFIG)
rendition.themes.select(themeStore.currentTheme.isDark ? 'dark' : 'light')
rendition.display()

rendition.on('keydown', (event: KeyboardEvent) => {
if (event.key === Key.ArrowLeft) {
navigateLeft()
Expand All @@ -100,6 +121,7 @@ export default defineComponent({
navigateRight()
}
})

rendition.on('relocated', () => {
const currentLocation = rendition.currentLocation() as any
const locationCfi = currentLocation.start.cfi
Expand Down Expand Up @@ -135,10 +157,6 @@ export default defineComponent({
</script>
<style lang="scss">
.epub-reader {
.epub-container {
background: white;
}

&-chapters-list {
position: absolute;
left: var(--oc-space-small);
Expand Down