epubjs

0.3.73

ePub

Creates a new Book

ePub(url: (string | ArrayBuffer), options: object): Book
Parameters
url ((string | ArrayBuffer)) URL, Path or ArrayBuffer
options (object) to pass to the book
Returns
Book: a new Book object
Example
ePub("/path/to/book.epub", {})

Book

An Epub representation with methods for the loading, parsing and manipulation of its contents.

new Book(url: string?, options: object?): Book
Parameters
url (string?)
options (object?)
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 none) use base64, blobUrl, or none for replacing assets in archived Epubs
options.canonical method? optional function to determine canonical urls for a path
options.openAs string? optional string to determine the input type
Returns
Book:
Example
new Book("/path/to/book.epub", {})
new Book({ replacements: "blobUrl" })
Static Members
opened
spine
locations
navigation
pagelist
Instance Members
open(input, what)
load(path)
resolve(path, absolute?)
canonical(path)
section(target)
renderTo(element, options?)
setRequestCredentials(credentials)
setRequestHeaders(headers)
coverUrl()
getRange(cfiRange)
key(identifier?)
destroy()

Url

creates a Url object for parsing and manipulation of a url string

new Url(urlString: string, baseString: string?)
Parameters
urlString (string) a url string (relative or absolute)
baseString (string?) optional base for the url, default to window.location.href
Instance Members
path()
resolve(what)
relative(what)
toString()

Path

Creates a Path object for parsing and manipulation of a path strings

Uses a polyfill for Nodejs path: https://nodejs.org/api/path.html

new Path(pathString: string)
Parameters
pathString (string) a url string (relative or absolute)
Instance Members
parse(what)
isAbsolute(what)
isDirectory(what)
resolve(what)
relative(what)
toString()

Spine

A collection of Spine Items

new Spine()
Instance Members
unpack(_package, resolver, canonical)
get(target?)
each()
first()
last()

Section

Represents a Section of the Book

In most books this is equivelent to a Chapter

new Section(item: object, hooks: object)
Parameters
item (object) The spine item representing the section
hooks (object) hooks for serialize and content
Instance Members
load(_request?)
render(_request?)
find(_query)
reconcileLayoutSettings(globalLayout)
cfiFromRange(_range)
cfiFromElement(el)
unload()

Locations

Find Locations for a Book

new Locations(spine: Spine, request: request, pause: number)
Parameters
spine (Spine)
request (request)
pause (number = 100)
Instance Members
generate(chars)
locationFromCfi(cfi)
percentageFromCfi(cfi)
percentageFromLocation(loc, location)
cfiFromLocation(loc)
cfiFromPercentage(percentage)
load(locations)
save()
currentLocation
currentLocation
length()

Container

Handles Parsing and Accessing an Epub Container

new Container(containerDocument: document?)
Parameters
containerDocument (document?) xml document
Instance Members
parse(containerDocument)

Packaging

Open Packaging Format Parser

new Packaging(packageDocument: document)
Parameters
packageDocument (document) OPF XML
Instance Members
parse(packageDocument)
load(json, packageDocument)

Navigation Parser

new Navigation(xml: document)
Parameters
xml (document) navigation html / xhtml / ncx
Instance Members

Resources

Handle Package Resources

new Resources(manifest: Manifest, options: object?)
Parameters
manifest (Manifest)
options (object?)
Name Description
options.replacements string (default "base64")
options.archive Archive?
options.resolver method?
Instance Members
createUrl(url)
replacements()
relativeTo(absolute, resolver?)
get(path)
substitute(content, url?)

PageList

Page List Parser

new PageList(xml: document?)
Parameters
xml (document?)
Instance Members
parse(xml)
pageFromCfi(cfi)
cfiFromPage(pg)
pageFromPercentage(percent)
percentageFromPage(pg)
percentageFromCfi(cfi)
destroy()

Archive

Handles Unzipping a requesting files from an Epub Archive

new Archive()
Instance Members
open(input, isBase64?)
openUrl(zipUrl, isBase64?)
request(url, type?)
getBlob(url, mimeType?)
getText(url, encoding?)
getBase64(url, mimeType?)
createUrl(url, options)
revokeUrl(url)

Rendition

Displays an Epub as a series of Views for each Section. Requires Manager and View class to handle specifics of rendering the section contetn.

new Rendition(book: Book, options: object?)
Parameters
book (Book)
options (object?)
Name Description
options.width number?
options.height number?
options.ignoreClass string? class for the cfi parser to ignore
options.manager (string | function | object) (default 'default')
options.view (string | function) (default 'iframe')
options.layout string? layout to force
options.spread string? force spread value
options.minSpreadWidth number? overridden by spread: none (never) / both (always)
options.stylesheet string? url of stylesheet to be injected
options.resizeOnOrientationChange boolean? false to disable orientation events
options.script string? url of script to be injected
Static Members
hooks
themes
annotations
location
started
Instance Members
setManager(manager)
requireManager(manager)
requireView(view)
start()
attachTo(element)
display(target)
moveTo(offset)
resize(width?, height?)
clear()
next()
prev()
flow(flow)
layout(settings)
spread(spread, min)
direction(dir)
reportLocation()
currentLocation()
destroy()
getRange(cfi, ignoreClass)
getContents()
views()
Events
started
attached
displayed
displayError
rendered
removed
resized
orientationchange
locationChanged
relocated
selected
markClicked

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
register()
trigger()

Queue

Queue for handling tasks one at a time

new Queue(context: scope)
Parameters
context (scope) what this will resolve to in the tasks
Instance Members
enqueue()
dequeue()
run()
flush()
clear()
length()
pause()
stop()

Layout

Figures out the CSS values to apply for a layout

new Layout(settings: object)
Parameters
settings (object)
Name Description
settings.layout string (default 'reflowable')
settings.spread string?
settings.minSpreadWidth number (default 800)
settings.evenSpreads boolean (default false)
Instance Members
flow(flow)
spread(spread, min)
calculate(_width, _height, _gap)
format(contents)
count(totalLength, pageLength)

Themes

Themes to apply to displayed content

new Themes(rendition: Rendition)
Parameters
rendition (Rendition)
Instance Members
register()
default(theme)
registerThemes(themes)
registerUrl(name, input)
registerRules(name, rules)
select(name)
update(name)
inject(contents)
add(name, contents)
override(name, value, priority)
overrides(contents, content)
fontSize(size)
font(f)

Annotations

Handles managing adding & removing Annotations

new Annotations(rendition: Rendition)
Parameters
rendition (Rendition)
Instance Members
add(type, cfiRange, data, cb?, className, styles)
remove(cfiRange, type)
highlight(cfiRange, data, cb, className, styles)
underline(cfiRange, data, cb, className, styles)
mark(cfiRange, data, cb)
each()
show()
hide()

Annotation

Annotation object

new Annotation($0: Object, options: object, className: string, styles: object): Annotation
Parameters
$0 (Object)
Name Description
$0.type any
$0.cfiRange any
$0.data any
$0.sectionIndex any
$0.cb any
$0.className any
$0.styles any
options (object)
Name Description
options.type string Type of annotation to add: "highlight", "underline", "mark"
options.cfiRange EpubCFI EpubCFI range to attach annotation to
options.data object Data to assign to annotation
options.sectionIndex int Index in the Spine of the Section annotation belongs to
options.cb function? Callback after annotation is added
className (string) CSS class to assign to annotation
styles (object) CSS styles to assign to annotation
Returns
Annotation: annotation
Instance Members
update(data)
attach(view)
detach(view)
text()

EpubCFI

Parsing and creation of EpubCFIs: 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: (string | Range | Node)?, base: (string | object)?, ignoreClass: string?)
Parameters
cfiFrom ((string | Range | Node)?)
base ((string | object)?)
ignoreClass (string?) class to ignore when parsing DOM
Instance Members
parse(cfiStr)
toString()
compare(cfiOne, cfiTwo)
fromRange(range, base, ignoreClass?)
fromNode(anchor, base, ignoreClass?)
toRange(_doc, ignoreClass?)
isCfiString(str)
collapse(toStart)

Contents

Handles DOM manipulation, queries and events for View contents

new Contents(doc: document, content: element, cfiBase: string, sectionIndex: number)
Parameters
doc (document) Document
content (element) Parent Element (typically Body)
cfiBase (string) Section component of CFIs
sectionIndex (number) Index in Spine of Conntent's Section
Static Members
listenedEvents
Instance Members
width(w?)
height(h?)
contentWidth(w?)
contentHeight(h?)
textWidth()
textHeight()
scrollWidth()
scrollHeight()
overflow(overflow?)
overflowX(overflow?)
overflowY(overflow?)
css(property, value, priority?)
viewport(options?)
root()
locationOf(target, ignoreClass?)
addStylesheet(src)
addStylesheetRules(rules)
addScript(src)
addClass(className)
removeClass(className, removeClass)
range(_cfi, ignoreClass?)
cfiFromRange(range, ignoreClass?)
cfiFromNode(node, ignoreClass?)
size(width?, height?)
columns(width, height, columnWidth, gap)
scaler(scale, offsetX, offsetY)
fit(width, height)
direction(dir)
writingMode(mode)

Mapping

Map text locations to CFI ranges

new Mapping(layout: Layout, direction: string, axis: string, dev: boolean?)
Parameters
layout (Layout) Layout to apply
direction (string = "ltr") Text direction
axis (string = "horizontal") vertical or horizontal axis
dev (boolean?) toggle developer highlighting
Instance Members
section(view)
page(contents, cfiBase, start, end)
axis(axis)

Core

Core Utilities and Helpers

Core
Static Members
requestAnimationFrame
documentHeight()
isElement(obj)
isNumber(n)
isFloat(n)
prefixed(unprefixed)
defaults(obj)
extend(target)
insert(item, array, compareFunction?)
locationOf(item, array, compareFunction?, _start?, _end?)
indexOfSorted(item, array, compareFunction?, _start?, _end?)
bounds(el)
borders(el)
nodeBounds(node)
windowBounds()
indexOfNode(node, typeId)
indexOfTextNode(textNode)
indexOfElementNode(elementNode)
isXml(ext)
createBlob(content, mime)
createBlobUrl(content, mime)
revokeBlobUrl(url)
createBase64Url(content, mime)
type(obj)
parse(markup, mime, forceXMLDom)
qs(el, sel)
qsa(el, sel)
qsp(el, sel, props)
sprint(root, func)
treeWalker(root, func, filter)
walk(node, callback, return)
blob2base64(blob)
defer()
querySelectorByType(html, element, type)
findChildren(el)
parents(node)
filterChildren(el, nodeName, single?)
getParentByTagName(node, tagname)
new RangeObject()