Skip to content
Enhanced eBooks in the browser.
JavaScript Other
Branch: master
Clone or download

Latest commit

fchasen Merge pull request #1059 from alidbc/master
Fix left offset calculation of RTL prev navigation
Latest commit 0adbb08 May 22, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
documentation/md Change Book.coverUrl to return null when there is no cover May 22, 2020
examples Fix the themes example Feb 9, 2020
libs Add metatags for annotations Jul 6, 2017
src Merge pull request #1059 from alidbc/master May 23, 2020
test Change Book.coverUrl to return null when there is no cover May 22, 2020
tools Updates to contents for Android, server update, jszip updated to 3.1.1 Aug 19, 2016
types Change Book.coverUrl to return null when there is no cover May 22, 2020
.babelrc Use es2015 for lib compile Dec 9, 2016
.eslintrc.js Added type declarations Aug 21, 2018
.gitignore Added type declarations Aug 21, 2018
.jshintrc Added webpack build, karma test runner, travis config Oct 26, 2016
.nojekyll Turned of Jekyll Nov 17, 2013
.npmignore Ignore .babelrc for npm Dec 9, 2016
.travis.yml Clean up pageList Nov 6, 2017
.watchmanconfig added polymer/url library Nov 15, 2016
README.md changed npm run preprocess to npm run prepare (#922) Mar 8, 2019
bower.json Remove ePub.register, update Readme May 1, 2018
documentation.yml Added pageList, initial documentation Nov 10, 2016
gulpfile.js Update gulp documentation Nov 6, 2017
karma.conf.js update url-polyfill Dec 6, 2018
license Add license file back, correct in package.json Oct 30, 2016
package-lock.json Version bump to 0.3.86 May 15, 2020
package.json Remove unnecessary absolute paths to npm scripts May 17, 2020
webpack.config.js require "jszip" in lowercase as external dependency Dec 1, 2017

README.md

Epub.js v0.3

FuturePress Views

Epub.js is a JavaScript library for rendering ePub documents in the browser, across many devices.

Epub.js provides an interface for common ebook functions (such as rendering, persistence and pagination) without the need to develop a dedicated application or plugin. Importantly, it has an incredibly permissive Free BSD license.

Try it while reading Moby Dick

Why EPUB

Why EPUB

The EPUB standard is a widely used and easily convertible format. Many books are currently in this format, and it is convertible to many other formats (such as PDF, Mobi and iBooks).

An unzipped EPUB3 is a collection of HTML5 files, CSS, images and other media – just like any other website. However, it enforces a schema of book components, which allows us to render a book and its parts based on a controlled vocabulary.

More specifically, the EPUB schema standardizes the table of contents, provides a manifest that enables the caching of the entire book, and separates the storage of the content from how it’s displayed.

Getting Started

Get the minified code from the build folder:

<script src="../dist/epub.min.js"></script>

If using archived .epub files include JSZip:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.5/jszip.min.js"></script>

Set up a element to render to:

<div id="area"></div>

Create the new ePub, and then render it to that element:

<script>
  var book = ePub("url/to/book/package.opf");
  var rendition = book.renderTo("area", {width: 600, height: 400});
  var displayed = rendition.display();
</script>

Render Methods

Default

book.renderTo("area", { method: "default", width: "100%", height: "100%" });

View example

The default manager only displays a single section at a time.

Continuous

book.renderTo("area", { method: "continuous", width: "100%", height: "100%" });

View example

The continuous manager will display as many sections as need to fill the screen, and preload the next section offscreen. This enables seamless swiping / scrolling between pages on mobile and desktop, but is less performant than the default method.

Flow Overrides

Auto (Default)

book.renderTo("area", { flow: "auto", width: "900", height: "600" });

Flow will be based on the settings in the OPF, defaults to paginated.

Paginated

book.renderTo("area", { flow: "paginated", width: "900", height: "600" });

View example

Scrolled: book.renderTo("area", { flow: "scrolled-doc" });

View example

Documentation

API documentation is available at epubjs.org/documentation/0.3/

A Markdown version is included in the repo at documentation/API.md

Running Locally

install node.js

Then install the project dependences with npm

npm install

You can run the reader locally with the command

npm start

Examples

View All Examples

Testing

Test can be run by Karma from NPM

npm test

Building for Distribution

Builds are concatenated and minified using webpack and babel

To generate a new build run

npm run prepare

or to continuously build run

npm run watch

Hooks

Similar to a plugins, Epub.js implements events that can be "hooked" into. Thus you can interact with and manipulate the contents of the book.

Examples of this functionality is loading videos from YouTube links before displaying a chapter's contents or implementing annotation.

Hooks require an event to register to and a can return a promise to block until they are finished.

Example hook:

rendition.hooks.content.register(function(contents, view) {

    var elements = contents.document.querySelectorAll('[video]');
    var items = Array.prototype.slice.call(elements);

    items.forEach(function(item){
      // do something with the video item
    });

})

The parts of the rendering process that can be hooked into are below.

book.spine.hooks.serialize // Section is being converted to text
book.spine.hooks.content // Section has been loaded and parsed
rendition.hooks.render // Section is rendered to the screen
rendition.hooks.content // Section contents have been loaded
rendition.hooks.unloaded // Section contents are being unloaded

Reader

The reader has moved to its own repo at: https://github.com/futurepress/epubjs-reader/

Additional Resources

Gitter Chat

Epub.js Developer Mailing List

IRC Server: freenode.net Channel: #epub.js

Follow us on twitter: @Epubjs

Other

EPUB is a registered trademark of the IDPF.

You can’t perform that action at this time.