ePub
Creates a new Book
Parameters
options (object)
to pass to the book
Returns
Book
:
a new Book object
Example
ePub("/path/to/book.epub", {})
Static Members
register plugins
register
Static Members
register a new view manager
manager()
register a new view
view()
Book
Creates a new Book
Parameters
Name |
Description |
options.requestMethod method
|
a request function to use instead of the default
|
options.requestCredentials [boolean]
(default undefined )
|
send the xhr request withCredentials
|
options.requestHeaders [object]
(default undefined )
|
send the xhr request headers
|
options.encoding [string]
(default binary )
|
optional to pass 'binary' or base64' for archived Epubs
|
options.replacements [string]
(default base64 )
|
use base64, blobs, or none for replacing assets in archived Epubs
|
Returns
Book
:
Example
new Book("/path/to/book.epub", {})
Instance Members
opened
Properties
opened (promise)
: returns after the book is loaded
Open a epub or url
Parameters
input (string)
URL, Path or ArrayBuffer
what ([string])
to force opening
Returns
Promise
:
of when the book has been loaded
Example
book.open("/path/to/book.epub")
Load a resource from the Book
Parameters
path (string)
path to the resource to load
Returns
Promise
:
returns a promise with the requested resource
▸
resolve(path, absolute)
Resolve a path to it's absolute position in the Book
Parameters
absolute ([boolean])
force resolving the full URL
Returns
string
:
the resolved path string
Alias for book.spine.get
Parameters
▸
renderTo(element, options)
Sugar to render a book
Parameters
element (element)
element to add the views to
Returns
Rendition
:
▸
setRequestCredentials(credentials)
Set if request should use withCredentials
setRequestCredentials(credentials:
boolean)
Parameters
Get the cover url
Returns
string
:
coverUrl
Find a DOM Range for a given CFI Range
Parameters
cfiRange (EpubCFI)
a epub cfi range
Returns
Range
:
Locations
Find Locations for a Book
new Locations(spine: Spine, request:
request)
Parameters
Instance Members
Load all of sections in the book to generate locations
Parameters
chars (int)
how many chars to split on
Returns
object
:
locations
Container
Handles Parsing and Accessing an Epub Container
new Container(containerDocument: [
document])
Parameters
containerDocument ([document])
xml document
Instance Members
▸
parse(containerDocument)
Parse the Container XML
Parameters
Packaging
Open Packaging Format Parser
new Packaging(packageDocument:
document)
Parameters
Instance Members
Parse OPF XML
Parameters
Returns
object
:
parsed package parts
▸
parseSpine(spineXml, manifest)
Parse Spine
Parameters
manifest (Packaging.manifest)
Returns
object
:
spine
▸
findCoverPath(packageXml)
Find the Cover Path
Fallback for Epub 2.0
Parameters
Returns
string
:
href
Navigation
Navigation Parser
Parameters
xml (document)
navigation html / xhtml / ncx
Instance Members
Parse out the navigation items
Parameters
xml (document)
navigation html / xhtml / ncx
Get an item from the navigation
Parameters
Returns
object
:
navItems
Resources
Handle Package Resources
new Resources(manifest: Manifest, options: [
object])
Parameters
Name |
Description |
options.archive [Archive]
|
|
options.resolver [method]
|
|
Instance Members
▸
replacements(archive, resolver)
Create blob urls for all the assets
Parameters
resolver (resolver)
Url resolver
Returns
Promise
:
returns replacement urls
▸
relativeTo(absolute, resolver)
Resolve all resources URLs relative to an absolute URL
Parameters
absolute (string)
to be resolved to
Returns
Array<string>
:
array with relative Urls
Get a URL for a resource
Parameters
Returns
string
:
url
Archive
Handles Unzipping a requesting files from an Epub Archive
new Archive()
Instance Members
Open an archive
Parameters
isBase64 (boolean)
tells JSZip if the input data is base64 encoded
Returns
Promise
:
zipfile
▸
openUrl(zipUrl, isBase64)
Load and Open an archive
Parameters
isBase64 (boolean)
tells JSZip if the input data is base64 encoded
Returns
Promise
:
zipfile
Request
Parameters
url (string)
a url to request from the archive
type ([string])
specify the type of the returned result
Returns
Promise
:
Get a Blob from Archive by Url
Parameters
Returns
Blob
:
Get Text from Archive by Url
Parameters
Returns
string
:
▸
getBase64(url, mimeType)
Get a base64 encoded result from Archive by Url
Parameters
Returns
string
:
base64 encoded
▸
createUrl(url, options)
Create a Url from an unarchived item
Parameters
options (any)
Name |
Description |
options.base64 [object]
|
use base64 encoding or blob url
|
Returns
Promise
:
url promise with Url string
Revoke Temp Url for a achive item
Parameters
url (string)
url of the item in the archive
EpubCFI
EPUB CFI spec: http://www.idpf.org/epub/linking/cfi/epub-cfi.html
Implements:
- Character Offset: epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3)
- Simple Ranges : epubcfi(/6/4[chap01ref]!/4[body01]/10[para05],/2/1:1,/3:4)
Does Not Implement:
- Temporal Offset (~)
- Spatial Offset (@)
- Temporal-Spatial Offset (~ + @)
- Text Location Assertion ([)
new EpubCFI(cfiFrom: any, base: any, ignoreClass: any)
Parameters
Url
creates a uri object
Parameters
urlString (string)
a url string (relative or absolute)
baseString ([string])
optional base for the url,
default to window.location.href
Returns
object
:
url
content
content
Properties
Rendition
[Rendition description]
Parameters
Name |
Description |
options.width int
|
|
options.height int
|
|
options.ignoreClass string
|
|
options.manager string
|
|
options.view string
|
|
options.layout string
|
|
options.spread string
|
|
options.minSpreadWidth int
|
overridden by spread: none (never) / both (always)
|
Instance Members
Adds Hook methods to the Rendition prototype
hooks
Properties
Set the manager function
Parameters
▸
requireManager(manager)
Require the manager from passed string, or as a function
Parameters
Returns
method
:
Require the view from passed string, or as a function
Parameters
Returns
view
:
Start the rendering
Returns
Promise
:
rendering has started
Call to attach the container to an element in the dom
Container must be attached before rendering can begin
Parameters
Returns
Promise
:
Display a point in the book
The request will be added to the rendering Queue,
so it will wait until book is opened, rendering started
and all other rendering tasks have finished to be called.
Parameters
target (string)
Url or EpubCFI
Returns
Promise
:
Move the Rendition to a specific offset
Usually you would be better off calling display()
Parameters
Go to the next "page" in the rendition
Returns
Promise
:
Go to the previous "page" in the rendition
Returns
Promise
:
Adjust the flow of the rendition to paginated or scrolled
(scrolled-continuous vs scrolled-doc are handled by different view managers)
Parameters
Adjust the layout of the rendition to reflowable or pre-paginated
Parameters
Adjust if the rendition uses spreads
spread(spread:
string, min: int)
Parameters
spread (string)
none | auto (TODO: implement landscape, portrait, both)
min (int)
min width to use spreads at
Report the current location
reportLocation()
Remove and Clean Up the Rendition
destroy()
▸
range(cfi, ignoreClass)
Get a Range from a Visible CFI
Parameters
Returns
range
:
Hook to adjust images to fit in columns
adjustImages(view: View)
Parameters
Hook
Hooks allow for injecting functions that must all complete in order before finishing
They will execute in parallel but all must finish before continuing
Functions may return a promise if they are asycn.
new Hook(context: any)
Parameters
context (any)
scope of this
Example
this.content = new EPUBJS.Hook(this);
Instance Members
Adds a function to be run before a hook completes
register()
Example
this.content.register(function(){...});
Triggers a hook to run all functions
trigger()
Example
this.content.trigger(args).then(function(){...});
Layout
Figures out the CSS to apply for a layout
Parameters
Name |
Description |
settings.spread [string]
|
|
Instance Members
Switch the flow between paginated and scrolled
Parameters
flow (string)
paginated | scrolled
Switch between using spreads or not, and set the
width at which they switch to single.
Parameters
▸
calculate(_width, _height, _gap)
Calculate the dimensions of the pagination
Parameters
_width (number)
[
description
]
_height (number)
[
description
]
Count number of pages
Parameters
Returns
number
:
spreads
Returns
number
:
pages