docs.vivliostyle.org

Core API Reference

Table of Contents

constants

constants.PageProgression

Enum PageProgression represents page progression direction. PageProgression has members, LTR and RTL.

constants.PageSide

Enum PageSide represents page side. PageSide has members, LEFT and RIGHT.

constants.ReadyState

Enum ReadyState represents viewer ready state. ReadyState has members, LOADING, INTERACTIVE and COMPLETE.

plugin

plugin.registerHook(name, fn)

Register a function to a hook with the specified name. The registered function is called at appropriate timings by the core code. Arguments passed to the function depend on the hook. When multiple functions are registered, they are called by the order in which they are registered.

Parameters

plugin.removeHook(name, fn)

Remove a function already registered to the specified name. Note that even if the same function are registered multiple times, this method removes only the first one.

Parameters

profile

profile.profiler.registerStartTiming(name, timestamp)

Registers start timing of some event.

Parameters

profile.profiler.registerEndTiming(name, timestamp)

Registers end timing of some event.

Parameters

profile.profiler.printTimings()

Log registered timings (start/end/duration). All values are printed in ms unit.

profile.profiler.disable()

Disable profiling.

profile.profiler.enable()

Enable profiling.

core-viewer

new CoreViewer(settings, options)

Vivliostyle CoreViewer class. Creates CoreViewer.

Parameters

PageViewMode

Enum PageViewMode. PageViewMode has members, SINGLE_PAGE, SPREAD and AUTO_SPREAD.

ZoomType

Enum ZoomType. ZoomType has only one member, FIT_INSIDE_VIEWPORT.

Classes

CoreViewer

CoreViewer.addListener(type, listener)

Add a listener function, which is invoked when the specified type of event is dispatched.

Parameters

CoreViewer.getCurrentPageProgression()

Returns the current page progression of the viewer. If no document is loaded, returns null.

Returns

PageProgression

CoreViewer.getPageSizes()

Returns

Array<{width: number, height: number}>

CoreViewer.isTOCVisible()

Returns true if TOC is visible, false if hidden, null if TOC is unavailable

CoreViewer.loadDocument(singleDocumentOptions, documentOptions, viewerOptions)

Load an HTML or XML document(s).

Parameters

CoreViewer.loadPublication(pubURL, documentOptions, viewerOptions)

Load a EPUB/WebPub publication.

Parameters

CoreViewer.navigateToInternalUrl()

Navigate to the specified internal URL.

CoreViewer.navigateToPage()

Navigate to the specified page.

CoreViewer.queryZoomFactor(type)

Returns zoom factor corresponding to the specified zoom type.

Parameters
Returns

number

CoreViewer.removeListener(type, listener)

Remove an event listener.

Parameters

CoreViewer.setOptions(options)

Set CoreViewerOptions to the viewer.

Parameters

CoreViewer.showTOC(opt_show, opt_autohide)

Show or hide TOC box

Parameters

TypeDefs

DocumentOptions

Options for the displayed document.

SingleDocumentOptions

Options for a single source document. SingleDocumentOptions is the object that has members below, or otherwise string that represents url.

CoreViewerSettings

CoreViewer settings that must be passed to CoreViewer’s constructor.

CoreViewerOptions

Viewer options that can be set after the Viewer object is constructed.

print

printHTML

Allows page-layouting using the vivliostyle for printing within a website without destroying the original layout

import { printHTML } from '@vivliostyle/core';

const htmlDoc = `<!doctype html>
<html>
    <head>
        <style>
        ... Add your CSS code here ...
        </style>
    </head>
    <body>
        ... Add your HTML code here ...
    </body>
</html>`;

const config = {
  title: 'My printed page',
  printCallback: (iframeWin) => iframeWin.print(), // optional: only needed if calling something other than window.print() for printing.
};

printHTML(htmlDoc, config);