### Layout and Sizing Methods Source: http://epubjs.org/documentation/0.3 Methods for getting and setting dimensions, overflow, and layout properties of the content. ```APIDOC ## width(w?) ### Description Get or set the width of the contents. ### Parameters - **w** (number) - Optional - The width value. ### Response - **number** - The current or updated width. ## size(width?, height?) ### Description Size the contents to a given width and height. ### Parameters - **width** (number) - Optional - Target width. - **height** (number) - Optional - Target height. ``` -------------------------------- ### Get Path String Source: http://epubjs.org/documentation/0.3 Returns the string representation of the current Path object. ```javascript toString(): string ``` -------------------------------- ### Get First Spine Section Source: http://epubjs.org/documentation/0.3 Retrieves the first section in the spine. ```javascript first(): Section ``` -------------------------------- ### Get Last Spine Section Source: http://epubjs.org/documentation/0.3 Retrieves the last section in the spine. ```javascript last(): Section ``` -------------------------------- ### Rendition Events Source: http://epubjs.org/documentation/0.3 Listens for events emitted by the Rendition instance during its lifecycle, such as rendering start, display, and errors. ```APIDOC ## Rendition Events ### Description Events are emitted by the Rendition instance to signal various states and occurrences during the rendering process. ### Event List - **started**: Emitted when rendering has started. - **attached**: Emitted when the rendition has been attached to an element. - **displayed**: Emitted when a section has been displayed. - **Parameters**: - `section` (Section) - The displayed section. - **displayError**: Emitted when there has been an error displaying a section. - **Parameters**: - `section` (Section) - The section that caused the error. - **rendered**: Emitted when a section has been rendered. - **Parameters**: - `section` (Section) - The rendered section. - `view` (View) - The view associated with the rendered section. - **removed**: Emitted when a view or section is removed. ``` -------------------------------- ### Get a canonical link to a path Source: http://epubjs.org/documentation/0.3 The `canonical` method returns a canonical link for a given path within the EPUB. ```javascript book.canonical(path) ``` -------------------------------- ### Get CFI from Element Source: http://epubjs.org/documentation/0.3 Generates an EpubCFI string from a given Element object within the section. ```javascript cfiFromElement(el: element): string ``` -------------------------------- ### Get Spine Item Source: http://epubjs.org/documentation/0.3 Retrieves a specific section from the spine by its index, ID, or URL. ```javascript get(target: (string | number)?): Section ``` ```javascript spine.get(); ``` ```javascript spine.get(1); ``` ```javascript spine.get("chap1.html"); ``` ```javascript spine.get("#id1234"); ``` -------------------------------- ### Get the cover URL of the Book Source: http://epubjs.org/documentation/0.3 Retrieve the URL of the EPUB's cover image using the `coverUrl` method. ```javascript book.coverUrl() ``` -------------------------------- ### Get CFI from Range Source: http://epubjs.org/documentation/0.3 Generates an EpubCFI string from a given Range object within the section. ```javascript cfiFromRange(_range: range): string ``` -------------------------------- ### Get the path from a Url object Source: http://epubjs.org/documentation/0.3 Retrieve the path component of a Url object using the `path` method. ```javascript url.path() ``` -------------------------------- ### Get a Section from the Book's Spine Source: http://epubjs.org/documentation/0.3 Retrieve a specific Section of the Book using its target identifier. This is an alias for `book.spine.get`. ```javascript book.section(target) ``` -------------------------------- ### Get Relative Path Source: http://epubjs.org/documentation/0.3 Resolves a path relative to the directory of the current Path object. Consult Node.js path documentation for usage. ```javascript relative(what: string): string ``` -------------------------------- ### Resolve a path within a Book Source: http://epubjs.org/documentation/0.3 Use the `resolve` method to get the absolute path or URL of a resource within the EPUB. An optional boolean can force resolving the full URL. ```javascript book.resolve(path, absolute?) ``` -------------------------------- ### Get a relative path from a Url Source: http://epubjs.org/documentation/0.3 The `relative` method on a Url object calculates a path relative to the Url's own path. ```javascript url.relative(what) ``` -------------------------------- ### Get a DOM Range for a CFI Range Source: http://epubjs.org/documentation/0.3 The `getRange` method finds a DOM Range object corresponding to a given EpubCFI range string. ```javascript book.getRange(cfiRange) ``` -------------------------------- ### Create a new Book instance Source: http://epubjs.org/documentation/0.3 Instantiate a new Book object to represent an EPUB. Provide the URL or path to the EPUB file and optional configuration options. ```javascript ePub("/path/to/book.epub", {}) ``` ```javascript new Book("/path/to/book.epub", {}) ``` ```javascript new Book({ replacements: "blobUrl" }) ``` -------------------------------- ### Rendition Constructor Source: http://epubjs.org/documentation/0.3 Initializes a new Rendition instance to display an Epub. It requires a Book instance and accepts an options object for customization. ```APIDOC ## Rendition Constructor ### Description Displays an Epub as a series of Views for each Section. Requires Manager and View class to handle specifics of rendering the section content. ### Method `new Rendition(book: Book, options: object?)` ### Parameters #### Path Parameters - **book** (Book) - The Book instance to render. - **options** (object?) - Optional configuration object for Rendition. #### Query Parameters - **options.width** (number?) - Sets the width of the rendition. - **options.height** (number?) - Sets the height of the rendition. - **options.ignoreClass** (string?) - A CSS class for the CFI parser to ignore. - **options.manager** (string | function | object?) - Specifies the view manager. Defaults to 'default'. - **options.view** (string | function?) - Specifies the view type. Defaults to 'iframe'. - **options.layout** (string?) - Forces a specific layout (e.g., 'reflowable', 'pre-paginated'). - **options.spread** (string?) - Forces a specific spread value (e.g., 'none', 'auto'). - **options.minSpreadWidth** (number?) - Overrides the minimum width for spreads. - **options.stylesheet** (string?) - URL of a stylesheet to inject into the rendition. - **options.resizeOnOrientationChange** (boolean?) - Set to false to disable orientation change events. - **options.script** (string?) - URL of a script to inject into the rendition. ### Request Example ```json { "book": "", "options": { "width": 800, "height": 600, "layout": "reflowable" } } ``` ### Response This is a constructor, it does not return a value directly but initializes an object. ``` -------------------------------- ### Resources Module Source: http://epubjs.org/documentation/0.3 Handles package resources, URL creation, and asset substitution. ```APIDOC ## Resources ### Description Manages package resources, including URL resolution, blob creation, and content substitution. ### Constructor new Resources(manifest: Manifest, options: object?) ### Methods - **createUrl(url: string)**: Creates a URL for a resource (returns Promise). - **replacements()**: Creates blob URLs for assets. - **relativeTo(absolute: string, resolver: resolver?)**: Resolves resource URLs relative to an absolute URL. - **get(path: string)**: Gets a URL for a resource. - **substitute(content: string, url: string?)**: Substitutes URLs in content. ``` -------------------------------- ### EPub Constructor Source: http://epubjs.org/documentation/0.3 Creates a new Book instance to represent an ePub file. ```APIDOC ## ePub Constructor ### Description Creates a new Book instance to represent an ePub file. ### Method `ePub(url: (string | ArrayBuffer), options: object): Book` ### Parameters - **url** ((string | ArrayBuffer)) - Required - URL, Path or ArrayBuffer of the ePub file. - **options** (object) - Optional - Options to pass to the book constructor. ### Returns - **Book**: A new Book object. ### Request Example ```javascript ePub("/path/to/book.epub", {}) ``` ``` -------------------------------- ### Open an EPUB file Source: http://epubjs.org/documentation/0.3 Use the `open` method on a Book instance to load an EPUB from a URL, path, or ArrayBuffer. You can optionally force the opening type. ```javascript book.open("/path/to/book.epub") ``` -------------------------------- ### Initialize a new Hook Source: http://epubjs.org/documentation/0.3 Create a new hook instance with a specified context. ```javascript this.content = new EPUBJS.Hook(this); ``` -------------------------------- ### Generate a Book Key Source: http://epubjs.org/documentation/0.3 Create a unique key for the Book, either using the identifier from the manifest or a provided string. ```javascript book.key(identifier?) ``` -------------------------------- ### Mapping Class Constructor Source: http://epubjs.org/documentation/0.3 Initializes a new Mapping instance with layout, direction, and axis configurations. ```APIDOC ## new Mapping() ### Description Initializes a new Mapping instance. ### Parameters #### Path Parameters - **layout** (Layout) - Required - The layout to apply. - **direction** (string) - Optional - Text direction, defaults to "ltr". Accepts "ltr" or "rtl". - **axis** (string) - Optional - The axis for mapping, defaults to "horizontal". Accepts "horizontal" or "vertical". - **dev** (boolean) - Optional - Toggles developer highlighting. ``` -------------------------------- ### Register themes in EpubJS Source: http://epubjs.org/documentation/0.3 Register new themes using a URL, a style object, or a collection of themes. ```javascript themes.register("light", "http://example.com/light.css") ``` ```javascript themes.register("light", { "body": { "color": "purple"}}) ``` ```javascript themes.register({ "light" : {...}, "dark" : {...}}) ``` -------------------------------- ### Create a Section Object Source: http://epubjs.org/documentation/0.3 Initializes a Section object, representing a chapter or part of an EPUB book. Requires item and hooks parameters. ```javascript new Section(item: object, hooks: object) ``` -------------------------------- ### Set default theme in EpubJS Source: http://epubjs.org/documentation/0.3 Define a default theme for the rendition using a URL or a style object. ```javascript themes.register("http://example.com/default.css") ``` ```javascript themes.register({ "body": { "color": "purple"}}) ``` -------------------------------- ### Navigation Module Source: http://epubjs.org/documentation/0.3 Parses and manages navigation items for an EPUB. ```APIDOC ## Navigation ### Description Parses navigation files (html/xhtml/ncx) and provides access to navigation items and landmarks. ### Constructor new Navigation(xml: document) ### Methods - **parse(xml: document)**: Parses navigation items. - **get(target: string)**: Retrieves a navigation item by target. - **landmark(type: string)**: Retrieves a landmark by type. - **load(json: object)**: Loads spine items from JSON. - **forEach(fn: Function)**: Iterates through navigation items. ``` -------------------------------- ### Set request headers for Book Source: http://epubjs.org/documentation/0.3 Specify custom headers to be included in XHR requests made by the Book instance. ```javascript book.setRequestHeaders(headers) ``` -------------------------------- ### Asset Management Methods Source: http://epubjs.org/documentation/0.3 Methods for injecting stylesheets and scripts into the document head. ```APIDOC ## addStylesheet(src) ### Description Append a stylesheet link to the document head. ### Parameters - **src** (string) - Required - URL of the stylesheet. ## addScript(src) ### Description Append a script tag to the document head. ### Parameters - **src** (string) - Required - URL of the script. ### Response - **Promise** - Resolves when the script is loaded. ``` -------------------------------- ### Constructor: new Contents() Source: http://epubjs.org/documentation/0.3 Initializes a new instance of the Contents class to handle DOM manipulation for a specific section. ```APIDOC ## new Contents(doc, content, cfiBase, sectionIndex) ### Description Initializes the Contents handler for a specific document section. ### Parameters - **doc** (document) - Required - The document object. - **content** (element) - Required - The parent element (typically body). - **cfiBase** (string) - Required - Section component of CFIs. - **sectionIndex** (number) - Required - Index in Spine of Content's Section. ``` -------------------------------- ### Create a Path Object Source: http://epubjs.org/documentation/0.3 Instantiate a Path object to parse and manipulate URL strings. This uses a Node.js path polyfill. ```javascript new Path(pathString: string) ``` -------------------------------- ### Load a resource from a Book Source: http://epubjs.org/documentation/0.3 The `load` method retrieves a specific resource from the loaded EPUB, such as an image or HTML file, using its path. ```javascript book.load(path) ``` -------------------------------- ### Data and Promise Utilities Source: http://epubjs.org/documentation/0.3 Utility functions for data conversion and promise management. ```APIDOC ## blob2base64(blob) ### Description Convert a blob to a base64 encoded string. ### Parameters - **blob** (Blog) - Required - The blob to convert. ### Returns - **string** - The base64 encoded string. ## defer() ### Description Creates a new pending promise and provides methods to resolve or reject it. ``` -------------------------------- ### Set request credentials for Book Source: http://epubjs.org/documentation/0.3 Configure whether XHR requests made by the Book instance should include credentials. ```javascript book.setRequestCredentials(credentials) ``` -------------------------------- ### Create a Spine Object Source: http://epubjs.org/documentation/0.3 Initializes a Spine object, which manages a collection of Spine Items (sections) in a book. ```javascript new Spine() ``` -------------------------------- ### Parse a Path String Source: http://epubjs.org/documentation/0.3 Parses a given path string. Refer to Node.js path documentation for details. ```javascript parse(what: string): object ``` -------------------------------- ### Themes API Source: http://epubjs.org/documentation/0.3 Methods for registering, selecting, and applying visual themes to the rendition. ```APIDOC ## Themes.register(name, input) ### Description Registers a theme for use by a rendition. ### Parameters - **name** (string) - Required - Theme name - **input** (string|object) - Required - CSS URL or style object ## Themes.select(name) ### Description Selects an active theme by name. ### Parameters - **name** (string) - Required - Name of the theme to select ## Themes.fontSize(size) ### Description Adjusts the font size of the rendition. ### Parameters - **size** (number) - Required - Font size value ``` -------------------------------- ### Locations Module Source: http://epubjs.org/documentation/0.3 Handles location generation and mapping within an EPUB book. ```APIDOC ## Locations ### Description Manages book locations, allowing for generation and conversion between CFIs, percentages, and location indices. ### Constructor new Locations(spine: Spine, request: request, pause: number) ### Methods - **generate(chars: int)**: Generates locations by splitting on character count. - **locationFromCfi(cfi: EpubCFI)**: Returns a location index from a CFI. - **percentageFromCfi(cfi: EpubCFI)**: Returns a percentage position from a CFI. - **percentageFromLocation(loc: any, location: number)**: Returns a percentage from a location index. - **cfiFromLocation(loc: number)**: Returns an EpubCFI from a location index. - **cfiFromPercentage(percentage: number)**: Returns an EpubCFI from a percentage. - **load(locations: json)**: Loads locations from JSON. - **save()**: Returns locations as JSON. ``` -------------------------------- ### Core Utilities API Source: http://epubjs.org/documentation/0.3 This section covers various utility functions for common tasks. ```APIDOC ## requestAnimationFrame ### Description Vendor prefixed requestAnimationFrame. ### Method N/A (Static Member) ### Endpoint N/A ### Returns `function`: requestAnimationFrame ``` ```APIDOC ## uuid() ### Description Generates a UUID based on: http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript ### Method N/A (Static Member) ### Endpoint N/A ### Returns `string`: uuid ``` ```APIDOC ## documentHeight() ### Description Gets the height of a document. ### Method N/A (Static Member) ### Endpoint N/A ### Returns `number`: height ``` ```APIDOC ## isElement(obj) ### Description Checks if a node is an element. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **obj** (object) - Required - The object to check. ### Returns `boolean` ``` ```APIDOC ## isNumber(n) ### Description Checks if a value is a number. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **n** (any) - Required - The value to check. ### Returns `boolean` ``` ```APIDOC ## isFloat(n) ### Description Checks if a value is a float. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **n** (any) - Required - The value to check. ### Returns `boolean` ``` ```APIDOC ## prefixed(unprefixed) ### Description Get a prefixed css property. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **unprefixed** (string) - Required - The unprefixed CSS property name. ### Returns `string`: The prefixed CSS property name. ``` ```APIDOC ## defaults(obj) ### Description Apply defaults to an object. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **obj** (object) - Required - The object to apply defaults to. ### Returns `object`: The object with defaults applied. ``` ```APIDOC ## extend(target) ### Description Extend properties of an object. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **target** (object) - Required - The object to extend. ### Returns `object`: The extended object. ``` ```APIDOC ## insert(item, array, compareFunction?) ### Description Fast quicksort insert for sorted array -- based on: http://stackoverflow.com/questions/1344500/efficient-way-to-insert-a-number-into-a-sorted-array-of-numbers ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **item** (any) - Required - The item to insert. - **array** (array) - Required - The sorted array. - **compareFunction** (function?) - Optional - A function to compare elements. ### Returns `number`: The location (index) where the item was inserted in the array. ``` ```APIDOC ## locationOf(item, array, compareFunction?, _start?, _end?) ### Description Finds where something would fit into a sorted array. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **item** (any) - Required - The item to find the location for. - **array** (array) - Required - The sorted array. - **compareFunction** (function?) - Optional - A function to compare elements. - **_start** (function?) - Optional - The starting index for the search. - **_end** (function?) - Optional - The ending index for the search. ### Returns `number`: The location (index) where the item would fit in the array. ``` ```APIDOC ## indexOfSorted(item, array, compareFunction?, _start?, _end?) ### Description Finds the index of an item in a sorted array. Returns -1 if not found. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **item** (any) - Required - The item to find the index of. - **array** (array) - Required - The sorted array. - **compareFunction** (function?) - Optional - A function to compare elements. - **_start** (function?) - Optional - The starting index for the search. - **_end** (function?) - Optional - The ending index for the search. ### Returns `number`: The index of the item in the array, or -1 if not found. ``` ```APIDOC ## bounds(el) ### Description Find the bounds of an element taking padding and margin into account. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **el** (element) - Required - The element to get the bounds for. ### Returns `{width: Number, height: Number}`: An object containing the width and height of the element. ``` ```APIDOC ## borders(el) ### Description Find the bounds of an element taking padding, margin and borders into account. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **el** (element) - Required - The element to get the bounds for. ### Returns `{width: Number, height: Number}`: An object containing the width and height of the element including borders. ``` ```APIDOC ## nodeBounds(node) ### Description Find the bounds of any node. Allows for getting bounds of text nodes by wrapping them in a range. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **node** (node) - Required - The node to get the bounds for. ### Returns `BoundingClientRect`: The bounding rectangle of the node. ``` ```APIDOC ## windowBounds() ### Description Find the equivalent of getBoundingClientRect of a browser window. ### Method N/A (Static Member) ### Endpoint N/A ### Returns `{width: Number, height: Number, top: Number, left: Number, right: Number, bottom: Number}`: An object containing the bounds of the window. ``` ```APIDOC ## indexOfNode(node, typeId) ### Description Gets the index of a node in its parent. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **node** (Node) - Required - The node to find the index of. - **typeId** (string) - Required - The type identifier for the node. ### Returns `number`: The index of the node in its parent. ``` ```APIDOC ## indexOfTextNode(textNode) ### Description Gets the index of a text node in its parent. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **textNode** (node) - Required - The text node to find the index of. ### Returns `number`: The index of the text node in its parent. ``` ```APIDOC ## indexOfElementNode(elementNode) ### Description Gets the index of an element node in its parent. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **elementNode** (element) - Required - The element node to find the index of. ### Returns `number`: The index of the element node in its parent. ``` ```APIDOC ## isXml(ext) ### Description Check if an extension is an XML extension. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **ext** (string) - Required - The file extension to check. ### Returns `boolean`: True if the extension is an XML extension, false otherwise. ``` ```APIDOC ## createBlob(content, mime) ### Description Create a new blob. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **content** (any) - Required - The content for the blob. - **mime** (string) - Required - The MIME type of the blob. ### Returns `Blob`: The created blob object. ``` ```APIDOC ## createBlobUrl(content, mime) ### Description Create a new blob URL. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **content** (any) - Required - The content for the blob. - **mime** (string) - Required - The MIME type of the blob. ### Returns `string`: The created blob URL. ``` ```APIDOC ## revokeBlobUrl(url) ### Description Remove a blob URL. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **url** (string) - Required - The blob URL to revoke. ``` ```APIDOC ## createBase64Url(content, mime) ### Description Create a new base64 encoded URL. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **content** (any) - Required - The content to encode. - **mime** (string) - Required - The MIME type of the content. ### Returns `string`: The created base64 encoded URL. ``` ```APIDOC ## type(obj) ### Description Get the type of an object. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **obj** (object) - Required - The object to get the type of. ### Returns `string`: The type of the object. ``` ```APIDOC ## parse(markup, mime, forceXMLDom) ### Description Parse XML (or HTML) markup. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **markup** (string) - Required - The markup string to parse. - **mime** (string) - Required - The MIME type of the markup. - **forceXMLDom** (boolean) - Optional - Force using xmlDom to parse instead of the native parser. ### Returns `document`: The parsed document object. ``` ```APIDOC ## qs(el, sel) ### Description querySelector polyfill. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **el** (element) - Required - The element to query within. - **sel** (string) - Required - The selector string. ### Returns `element`: The found element. ``` ```APIDOC ## qsa(el, sel) ### Description querySelectorAll polyfill. ### Method N/A (Static Member) ### Endpoint N/A ### Parameters #### Path Parameters - **el** (element) - Required - The element to query within. - **sel** (string) - Required - The selector string. ### Returns `NodeList`: A NodeList of found elements. ``` -------------------------------- ### Tree Traversal Utilities Source: http://epubjs.org/documentation/0.3 Functions for walking through nodes and finding relationships between elements. ```APIDOC ## sprint(root, func) ### Description Sprint through all text nodes in a document. ### Parameters - **root** (element) - Required - Element to start with. - **func** (function) - Required - Function to run on each element. ## treeWalker(root, func, filter) ### Description Create a treeWalker. ### Parameters - **root** (element) - Required - Element to start with. - **func** (function) - Required - Function to run on each element. - **filter** (function | object) - Required - Function or object to filter with. ## findChildren(el) ### Description Find direct descendants of an element. ### Parameters - **el** (element) - Required - The element to search. ### Returns - **Array** - The children. ## parents(node) ### Description Find all parents (ancestors) of an element. ### Parameters - **node** (element) - Required - The node to search from. ### Returns - **Array** - The parents. ``` -------------------------------- ### Render a Book to an element Source: http://epubjs.org/documentation/0.3 The `renderTo` method provides a convenient way to render the EPUB content into a specified HTML element or selector. It returns a Rendition object. ```javascript book.renderTo(element, options?) ``` -------------------------------- ### Rendition Instance Members Source: http://epubjs.org/documentation/0.3 Details the instance methods available on a Rendition object for controlling playback, layout, and accessing rendition state. ```APIDOC ## Rendition Instance Members ### Description Instance members provide methods to interact with and control the Rendition after it has been initialized. ### Methods - **setManager(manager)** - **Description**: Set the manager function. - **Parameters**: - `manager` (function) - The manager function to set. - **requireManager(manager)** - **Description**: Require the manager from a passed string or class function. - **Parameters**: - `manager` ((string | object)) - The manager identifier or class. - **Returns**: `method` - **requireView(view)** - **Description**: Require the view from a passed string or class function. - **Parameters**: - `view` ((string | object)) - The view identifier or class. - **Returns**: `view` - **start()** - **Description**: Start the rendering process. - **Returns**: `Promise` - Resolves when rendering has started. - **attachTo(element)** - **Description**: Attach the rendition container to a DOM element. Must be called before rendering can begin. - **Parameters**: - `element` (element) - The DOM element to attach to. - **Returns**: `Promise` - **display(target)** - **Description**: Display a specific point in the book (by URL or EpubCFI). The request is queued and will be processed after the book is opened and rendering has started. - **Parameters**: - `target` (string) - The URL or EpubCFI to display. - **Returns**: `Promise` - **moveTo(offset)** - **Description**: Move the Rendition to a specific offset. `display()` is usually preferred. - **Parameters**: - `offset` (object) - The offset object specifying the target location. - **resize(width?, height?)** - **Description**: Trigger a resize of the rendition views. - **Parameters**: - `width` (number?) - The new width. - `height` (number?) - The new height. - **clear()** - **Description**: Clear all rendered views. - **next()** - **Description**: Navigate to the next "page" in the rendition. - **Returns**: `Promise` - **prev()** - **Description**: Navigate to the previous "page" in the rendition. - **Returns**: `Promise` - **flow(flow)** - **Description**: Adjust the flow of the rendition (e.g., 'paginated', 'scrolled'). - **Parameters**: - `flow` (string) - The desired flow type. - **layout(settings)** - **Description**: Adjust the layout of the rendition (e.g., 'reflowable', 'pre-paginated'). - **Parameters**: - `settings` (object) - Layout settings. - **spread(spread, min)** - **Description**: Adjust if the rendition uses spreads. - **Parameters**: - `spread` (string) - 'none' or 'auto'. - `min` (int) - Minimum width to use spreads. - **direction(dir)** - **Description**: Adjust the direction of the rendition (e.g., 'ltr', 'rtl'). - **Parameters**: - `dir` (string) - The desired direction. - **reportLocation()** - **Description**: Report the current location of the rendition. - **currentLocation()** - **Description**: Get the current location object. - **Returns**: `(displayedLocation | promise)` - The current location, possibly as a promise. - **destroy()** - **Description**: Remove and clean up the Rendition instance. - **getRange(cfi, ignoreClass)** - **Description**: Get a Range object from a Visible CFI. - **Parameters**: - `cfi` (string) - The EpubCfi String. - `ignoreClass` (string) - A CSS class to ignore. - **Returns**: `range` - **getContents()** - **Description**: Get the Contents object for each rendered view. - **Returns**: `Array` - **views()** - **Description**: Get the views member from the manager. - **Returns**: `Views` ``` -------------------------------- ### DOM Query and Traversal Utilities Source: http://epubjs.org/documentation/0.3 Functions for querying elements, filtering by properties, and traversing the DOM tree. ```APIDOC ## qsa(el, sel) ### Description Polyfill for querySelectorAll. ### Parameters - **el** (element) - Required - The element to search within. - **sel** (string) - Required - The selector string. ### Returns - **Array** - The found elements. ## qsp(el, sel, props) ### Description Performs a querySelector by property. ### Parameters - **el** (element) - Required - The element to search within. - **sel** (string) - Required - The selector string. - **props** (Array) - Required - Properties to filter by. ### Returns - **Array** - The found elements. ## querySelectorByType(html, element, type) ### Description Performs a querySelector with a filter by epub type. ### Parameters - **html** (element) - Required - The element to search within. - **element** (string) - Required - The element type to find. - **type** (string) - Required - The epub type to find. ### Returns - **Array** - The found elements. ``` -------------------------------- ### EpubCFI Class Source: http://epubjs.org/documentation/0.3 Methods for parsing, creating, and comparing EpubCFI strings. ```APIDOC ## EpubCFI ### Description Handles parsing and creation of EpubCFIs as defined by the IDPF specification. ### Constructor new EpubCFI(cfiFrom: (string | Range | Node)?, base: (string | object)?, ignoreClass: string?) ### Instance Members - **parse(cfiStr)**: Parse a cfi string to a CFI object representation. - **toString()**: Convert CFI to a epubcfi(...) string. - **compare(cfiOne, cfiTwo)**: Compare which of two CFIs is earlier in the text. Returns -1 if first is earlier, 1 if second is earlier, 0 if equal. - **fromRange(range, base, ignoreClass?)**: Create a CFI object from a Range. - **fromNode(anchor, base, ignoreClass?)**: Create a CFI object from a Node. - **toRange(_doc, ignoreClass?)**: Creates a DOM range representing a CFI. - **isCfiString(str)**: Check if a string is wrapped with "epubcfi()". - **collapse(toStart)**: Collapse a CFI Range to a single CFI Position. ``` -------------------------------- ### Annotation Class Source: http://epubjs.org/documentation/0.3 Methods for creating and managing annotations in an EPUB document. ```APIDOC ## Annotation ### Description Represents an annotation object that can be attached to a view. ### Constructor new Annotation($0: Object, options: object, className: string, styles: object) ### Parameters - **options.type** (string) - Required - Type of annotation: "highlight", "underline", "mark" - **options.cfiRange** (EpubCFI) - Required - EpubCFI range to attach annotation to - **options.data** (object) - Optional - Data to assign to annotation - **options.sectionIndex** (int) - Required - Index in the Spine of the Section - **options.cb** (function) - Optional - Callback after annotation is added - **className** (string) - Optional - CSS class to assign - **styles** (object) - Optional - CSS styles to assign ### Instance Members - **update(data)**: Update stored data. - **attach(view)**: Add to a view. - **detach(view)**: Remove from a view. - **text()**: Get text of an annotation (Not Implemented). ``` -------------------------------- ### Create a new Url object Source: http://epubjs.org/documentation/0.3 Instantiate a Url object for parsing and manipulating URL strings. A base URL can be provided for relative paths. ```javascript new Url(urlString, baseString?) ``` -------------------------------- ### Queue Class Source: http://epubjs.org/documentation/0.3 The Queue class handles tasks one at a time, ensuring sequential execution. ```APIDOC ## Queue Class ### new Queue(context: scope) **Parameters** - context (scope) - what this will resolve to in the tasks ### enqueue() Add an item to the queue. **Returns** - Promise: ### dequeue() Run one item. **Returns** - Promise: ### run() Run all tasks sequentially. **Returns** - Promise: ### flush() Flush all, as quickly as possible. **Returns** - Promise: ### clear() Clear all items in wait. ### length() Get the number of tasks in the queue. **Returns** - number: tasks ### pause() Pause a running queue. ### stop() End the queue. ``` -------------------------------- ### Render Section Content Source: http://epubjs.org/documentation/0.3 Renders the content of a section, optionally using a provided request method. Returns the serialized XML document as a string. ```javascript render(_request: method?): string ``` -------------------------------- ### Book Class Source: http://epubjs.org/documentation/0.3 Represents an Epub file with methods for loading, parsing, and manipulating its contents. ```APIDOC ## Book Class ### Description An Epub representation with methods for the loading, parsing and manipulation of its contents. ### Constructor `new Book(url: string?, options: object?): Book` ### Parameters - **url** (string?) - Optional - The URL or path to the ePub file. - **options** (object?) - Optional - Configuration options for the Book. - **options.requestMethod** (method?) - A request function to use instead of the default. - **options.requestCredentials** (boolean) - Send the xhr request withCredentials (default: `undefined`). - **options.requestHeaders** (object) - Send the xhr request headers (default: `undefined`). - **options.encoding** (string) - Optional encoding ('binary' or 'base64') for archived Epubs (default: `binary`). - **options.replacements** (string) - Method for replacing assets in archived Epubs ('base64', 'blobUrl', or 'none') (default: `none`). - **options.canonical** (method?) - Optional function to determine canonical URLs for a path. - **options.openAs** (string?) - Optional string to determine the input type. ### Returns - **Book**: A new Book object. ### Request Examples ```javascript new Book("/path/to/book.epub", {}) new Book({ replacements: "blobUrl" }) ``` ### Static Members - **opened**: (static property) - **spine**: (static property of type `Spine`) - **locations**: (static property of type `Locations`) - **navigation**: (static property of type `Navigation`) - **pagelist**: (static property of type `PageList`) ### Instance Members - **open(input, what)**: Opens an ePub or URL. - **Method**: `open(input: (string | ArrayBuffer), what: string): Promise` - **Parameters**: - **input** ((string | ArrayBuffer)) - Required - URL, Path or ArrayBuffer of the ePub. - **what** (string) - Required - Force opening as a certain type (`"binary","base64","epub","opf","json","directory"`). - **Returns**: `Promise` - A promise that resolves when the book has been loaded. - **Example**: `book.open("/path/to/book.epub")` - **load(path)**: Loads a resource from the Book. - **Method**: `load(path: string): Promise` - **Parameters**: - **path** (string) - Required - Path to the resource to load. - **Returns**: `Promise` - A promise with the requested resource. - **resolve(path, absolute?)**: Resolves a path to its absolute position in the Book. - **Method**: `resolve(path: string, absolute: boolean?): string` - **Parameters**: - **path** (string) - Required - The path to resolve. - **absolute** (boolean?) - Optional - Force resolving the full URL. - **Returns**: `string` - The resolved path string. - **canonical(path)**: Gets a canonical link to a path. - **Method**: `canonical(path: string): string` - **Parameters**: - **path** (string) - Required - The path. - **Returns**: `string` - The canonical path string. - **section(target)**: Gets a Section of the Book from the Spine (Alias for `book.spine.get`). - **Method**: `section(target: string): Section` - **Parameters**: - **target** (string) - Required - The target section identifier. - **Returns**: `Section` - The requested Section object. - **renderTo(element, options?)**: Sugar to render a book to an element. - **Method**: `renderTo(element: (element | string), options: object?): Rendition` - **Parameters**: - **element** ((element | string)) - Required - The DOM element or its selector to render the book into. - **options** (object?) - Optional - Rendering options. - **Returns**: `Rendition` - The Rendition object. - **setRequestCredentials(credentials)**: Sets if requests should use withCredentials. - **Method**: `setRequestCredentials(credentials: boolean)` - **Parameters**: - **credentials** (boolean) - Required - Whether to use withCredentials. - **setRequestHeaders(headers)**: Sets headers for requests. - **Method**: `setRequestHeaders(headers: object)` - **Parameters**: - **headers** (object) - Required - The headers to set. - **coverUrl()**: Gets the cover URL of the book. - **Method**: `coverUrl(): string` - **Returns**: `string` - The cover URL. - **getRange(cfiRange)**: Finds a DOM Range for a given CFI Range. - **Method**: `getRange(cfiRange: EpubCFI): Range` - **Parameters**: - **cfiRange** (EpubCFI) - Required - A epub CFI range. - **Returns**: `Range` - The DOM Range object. - **key(identifier?)**: Generates the Book Key using the identifier in the manifest or another provided string. - **Method**: `key(identifier: string?): string` - **Parameters**: - **identifier** (string?) - Optional - Identifier to use instead of the metadata identifier. - **Returns**: `string` - The generated book key. - **destroy()**: Destroys the Book and all associated objects. - **Method**: `destroy()` ``` -------------------------------- ### Archive API Source: http://epubjs.org/documentation/0.3 API for handling unzipping and requesting files from an Epub Archive. ```APIDOC ## Archive ### Description Handles Unzipping and requesting files from an Epub Archive. ### Constructor `new Archive()` ### Instance Members #### `open(input: binary, isBase64?: boolean): Promise` ##### Description Open an archive. ##### Parameters - **input** (binary) - The binary data of the archive. - **isBase64** (boolean?) - Tells JSZip if the input data is base64 encoded. ##### Returns - `Promise`: A promise that resolves with the zipfile object. #### `openUrl(zipUrl: string, isBase64?: boolean): Promise` ##### Description Load and Open an archive from a URL. ##### Parameters - **zipUrl** (string) - The URL of the archive. - **isBase64** (boolean?) - Tells JSZip if the input data is base64 encoded. ##### Returns - `Promise`: A promise that resolves with the zipfile object. #### `request(url: string, type?: string): Promise` ##### Description Request a URL from the archive. ##### Parameters - **url** (string) - A URL to request from the archive. - **type** (string?) - Specify the type of the returned result (e.g., 'blob', 'text', 'json', 'document'). ##### Returns - `Promise<(Blob | string | JSON | Document | XMLDocument)>`: A promise that resolves with the requested content. #### `getBlob(url: string, mimeType?: string): Blob` ##### Description Get a Blob from the Archive by URL. ##### Parameters - **url** (string) - The URL of the item in the archive. - **mimeType** (string?) - The MIME type of the Blob. ##### Returns - `Blob`: The Blob object. #### `getText(url: string, encoding?: string): string` ##### Description Get Text from the Archive by URL. ##### Parameters - **url** (string) - The URL of the item in the archive. - **encoding** (string?) - The encoding of the text. ##### Returns - `string`: The text content. #### `getBase64(url: string, mimeType?: string): string` ##### Description Get a base64 encoded result from the Archive by URL. ##### Parameters - **url** (string) - The URL of the item in the archive. - **mimeType** (string?) - The MIME type of the result. ##### Returns - `string`: Base64 encoded string. #### `createUrl(url: string, options: any): Promise` ##### Description Create a temporary URL from an unarchived item. ##### Parameters - **url** (string) - The URL of the item in the archive. - **options** (any) - Options for creating the URL. ##### Returns - `Promise`: A promise that resolves with the temporary URL string. #### `revokeUrl(url: string): void` ##### Description Revoke a temporary URL for an archive item. ##### Parameters - **url** (string) - The URL of the item in the archive to revoke. ``` -------------------------------- ### Reconcile Layout Settings Source: http://epubjs.org/documentation/0.3 Reconciles the section's layout properties with global layout settings. ```javascript reconcileLayoutSettings(globalLayout: object): object ```