0.0.10 • Published 6 years ago

vue-epub-reader v0.0.10

Weekly downloads
49
License
MIT
Repository
github
Last release
6 years ago

vue-epub-reader

⚠️ This package was created for educational purposes only.

⛔️ Don't use it in production.

npm npm vue2

Wrapper around epubjs for Vue

Table of contents

Installation

npm install --save vue-epub-reader

Import

import Vue from 'vue'
import { BookReader, PreferencesDropdown, TreeMenu } from 'vue-epub-reader'

components: {
    BookReader,
    PreferencesDropdown,
    TreeMenu
}

⚠️ A css file is included when importing the package. You may have to setup your bundler to embed the css in your page.

Components

BookReader

Component of the book with the progress

Props
PropsRequiredTypeDefaultDescription
epubUrltrueString/static/moby-dick.epuburl book
fontSizefalseNumber100font size in percent
themestrueObjectthemes of text and background color
themetrueStringwhitecurrent theme of text and background color
progress*trueNumber29progress in reading the book
bookAreafalseStringareaid element for render
contentBookModifyfalseNumber0amount of padding at the top and bottom of the book

*you need to use .sync

Slots

Component has named slots so that you can create custom elements of the reader.

nameDescription
prev-btnleft arrow
book-content<div :id="bookArea"></div> block in which is generated an iframe for the book
next-btnright arrow
progress-barprogress bar for progress of reading

Methods

Each slot has certain methods for working with a book

methodslotDescription
goToPrevPageprev-btngo to the next "page"
goToNextPagenext-btngo to the previous "page"
onChangeprogress-barevent change for input, that is the progress bar of reading a book. It
onMousedownprogress-barevent mousedown by clicking on the progress bar
onMouseupprogress-barevent mouseup by clicking on the progress bar

Custom events

methodDescription
tocget table of contents of book
closeAppearanceMenuclose appearance menu on click on book

PreferencesDropdown

Component that displays a menu of search by content, content, and appearance changes

Props

PropsRequiredTypeDefaultDescription
themestrueObjectthemes of text and background color
current-theme*trueStringwhitecurrent theme of text and background color
font-size*falseNumberfont size in percent

*you need to use .sync

Slots

Component has named slots so that you can create custom elements of the reader.

nameDescription
book-contentbutton and a menu that displays the contents of the book
book-searchbutton and a menu that displays the search results of the book
book-appearancebutton and menu to change the appearance of the reader

Methods

Each slot has certain methods for working with a book

methodslotDescription
showContentbook-contentshow content of books
<TreeMenu :subContent="toc"/>book-contentan auxiliary component for content (toc) that is displayed as a nested list
findTextbook-searchevent change for input, that takes the value of an input
removeHighlightbook-searchremove highlight of found text
showPage(excerpt .cfi)book-searchshow results of search
fontSizeDecreasebook-appearancedecreases the text size by 10%
ontSizeIncreasebook-appearanceincreases the text size by 10%
selectTheme(key)book-appearanceset selected theme. Requires the object key of the themes

Custom events

methodDescription
searchResultsget search results of books
v-model="searchQuery"searchQuery - value of search input

Usage

<template>
  <div id="app">
    <PreferencesDropdown
      :themes="themes"
      :current-theme.sync="currentTheme"
      :font-size.sync="size"
      v-model="serchQuery"
      @searchResults="onSearchResults"
    >
      <template slot="book-content" slot-scope="props">
        <button class="my-find my-content" @click="showContent">
          <img src="/static/left-alignment.svg" alt="">
        </button>
        <div class="search-widget1" v-if="openContent">
          <TreeMenu :subContent="toc"/>
        </div>
      </template>
      <template slot="book-search" slot-scope="props">
        <button class="my-find" @click="toggleSearchWidget">
          <img src="/static/search.svg" alt="">
        </button>
        <div class="search-widget1" v-if="openSearch">
          <input type="text"
                 :value="serchQuery"
                 @change="props.findText($event.target.value)"
          >
          <button @click="props.removeHighlight">x</button>
          <ul>
            <li v-for="(excerpt, i) in searchContent" :key="i" @click="props.showPage(excerpt.cfi)">
              <p>{{excerpt.excerpt}}</p>
            </li>
          </ul>
        </div>
      </template>
    </PreferencesDropdown>
    <BookReader
      :epub-url="url"
      :font-size="size"
      :themes="themes"
      :theme="currentTheme"
      :progress.sync="readingProgress"
      @toc="getContent"
      :contentBookModify="90"
    >
      <template slot="progress-bar" slot-scope="props">
        <input size="3" type="range" max="100" min="0" step="1"
          @change="props.onChange($event.target.value)"
          :value="readingProgress"
        /> %
        <input type="text"
          @change="props.onChange($event.target.value)"
          @mousedown="props.onMousedown"
          @mouseup="props.onMouseup"
          :value="readingProgress"
        >
      </template>
    </BookReader>
  </div>
</template>

<script>
import BookReader from './components/BookReader'
import TreeMenu from './components/TreeMenu'
import PreferencesDropdown from './components/PreferencesDropdown.vue'
import vueSlider from 'vue-slider-component'
export default {
  name: 'App',
  components: {
    BookReader,
    PreferencesDropdown,
    TreeMenu,
    vueSlider
  },
  data () {
    return {
      url: './static/alice.epub',
      size: 80,
      currentTheme: 'beige',
      themes: {
        white: {
          body: {
            color: '#000000',
            background: '#ffffff'
          },
          name: 'WHITE'
        },
        beige: {
          body: {
            color: '#000000',
            background: '#f3e8d2'
          },
          name: 'BEIGE'
        },
        night: {
          body: {
            color: '#ffffff',
            background: '#4a4a4a'
          },
          name: 'NIGHT'
        }
      },
      serchQuery: '',
      readingProgress: 20,
      openSearch: false,
      openContent: false,
      searchContent: [],
      toc: []
    }
  },
  methods: {
    toggleSearchWidget () {
      this.openSearch = !this.openSearch
    },

    showContent () {
      this.openContent = !this.openContent
    },

    onSearchResults (value) {
      this.searchContent = value
    },

    getContent (value) {
      this.toc = value
    }
  },
  mounted () {
    this.$root.$on('toc', (toc) => {
      this.toc = toc
    })
  }
}
</script>

Example

You can play around with that here


Plugin Development

Installation

The first time you create or clone your plugin, you need to install the default dependencies:

npm install

Watch and compile

This will run webpack in watching mode and output the compiled files in the dist folder.

npm run dev

Use it in another project

While developping, you can follow the install instructions of your plugin and link it into the project that uses it.

In the plugin folder:

npm link

In the other project folder:

npm link vue-epub-reader

This will install it in the dependencies as a symlink, so that it gets any modifications made to the plugin.

Publish to npm

You may have to login to npm before, with npm adduser. The plugin will be built in production mode before getting published on npm.

npm publish

Manual build

This will build the plugin into the dist folder in production mode.

npm run build

License

MIT

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago