Skip to content

Commit

Permalink
feat(reader): Online ebook reading via vue-reader (foliate-js)
Browse files Browse the repository at this point in the history
  • Loading branch information
ragusa87 authored and SergioMendolia committed Aug 11, 2024
1 parent 5f3f0f3 commit 9632229
Show file tree
Hide file tree
Showing 8 changed files with 2,651 additions and 2,367 deletions.
38 changes: 38 additions & 0 deletions assets/ReadEbook.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<template>
<div id="area" style="width: 100vw; height: 100vh; min-height: 95vh;">
<vue-reader
:url="props.file"
:showToc="true"
:getRendition="getRendition"
backgroundColor="#000"
@update:location="locationChange"
:location="getInitialLocation()"
/>
</div>
</template>

<script setup>
const props = defineProps({'file': String})
import { VueReader } from 'vue-book-reader'
const initialCfi = new URLSearchParams(window.location.search).get('cfi');
const locationChange = (detail) => {
const { fraction } = detail
console.log('locationChange', fraction, detail)
history.pushState({fraction: fraction, }, document.title, "?cfi=" + encodeURIComponent(detail.cfi) + "#page="+ detail.location.current+"&percent=" + (fraction * 100).toFixed(2));
}
const getInitialLocation = () => {
return initialCfi ?? null
}
const getRendition = async (rendition) => {
rendition.renderer.setStyles([
`
html {
background: #000;
color: #fff;
}`,
])
}
</script>
7 changes: 7 additions & 0 deletions assets/read-ebook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createApp } from 'vue'
import ReadEBook from './ReadEbook.vue'

document.addEventListener('DOMContentLoaded', () => {
const file = document.getElementById('mount').getAttribute('data-file')
createApp(ReadEBook, {file: file}).mount('#mount');
});
Loading

0 comments on commit 9632229

Please sign in to comment.