Options
All
  • Public
  • Public/Protected
  • All
Menu

Format specific API for an EPUB ReaderPublication.

Hierarchy

Index

Methods

createContentPositionTimeline

  • Creates a new ContentPositionTimeline using the specified list of ReaderDocuments. A ContentPositionTimeline is used for describing positions in ReaderPublication content as integers.

    See IContentPositionTimeline for more information and examples.

    Choosing unit of measurement

    The ContentPositionTimeline can be configured with different units of measurement. See getAvailableContentPositionTimelineUnits() for which units of measurement that are available in with this publication instance. By default, CHARACTERS will be used as unit of measurement if no unit is specified.

    CHARACTERS

    The timeline is created by counting all the characters in the provided list of ReaderDocuments. Each position in the timeline can be resolved to a specific character in the publication content. This is generally the most high-resolution unit of measurement available.

    In publications with lots of media, it might be desirable to count media elements (or other replaced elements) as x number of characters to get a better estimation of the "length" of the rendered publication. By default each replaced element is counted as 50 characters.

    Many HTML documents may contain lots of whitespace that is not visible in the rendered publication. By default, multiple adjacent whitespaces are collapsed and counted as a single whitespace.

    You can change those behaviours by configuring and passing an options object.

    WORDS

    The timeline is created by counting all words in the provided list of ReaderDocuments. Each position in the timeline can be resolved to a specific word in the publication content.

    NOTE: The current implementation uses whitespace as word boundary and is thus not suitable for all languages.

    PAGES

    The timeline is created by counting all pre-paginated pages in the provided list of ReaderDocuments. Each position in the timeline points to the start of a pre-paginated page. This unit of measurement is not available in reflowable EPUBs. Use getAvailableContentPositionTimelineUnits() to see if this unit of measurement is supported for this publication instance.

    DOCUMENTS

    The timeline is created by counting all provided ReaderDocuments.

    Specifying the list of ReaderDocuments

    The passed list of ReaderDocuments is validated according to the following rules:

    • The list must not be empty
    • All ReaderDocuments must belong to this publication.
    • All ReaderDocuments must be ordered as in the publication spine.

    If the passed list of readerDocuments fails validation, the returned Promise will be rejected with an error.

    Some examples:

    const spine = readerPublication.getSpine();
    readerPublication.createContentPositionTimeline(spine); // OK!
    readerPublication.createContentPositionTimeline(spine.slice(1, 4)) // OK!
    readerPublication.createContentPositionTimeline(spine.filter(item => item.isReflowable()); // OK!
    readerPublication.createContentPositionTimeline(spine.reverse()); // ERROR!

    Parameters

    • readerDocuments: IReaderDocument[]

      The reader documents that should be part of the timeline.

    • Optional options: EpubContentPositionTimelineOptions

      Options to use for the timeline.

    • Optional progressCallback: (progress: number) => void

      A function called several times indicating the create progress as a value between 0 and 1. You can also listen on the event 'contentPositionTimelineCreateProgress' to get this information.

        • (progress: number): void
        • Parameters

          • progress: number

          Returns void

    Returns Promise<IContentPositionTimeline>

createMediaOverlaySyncMediaTimeline

  • Creates a new EPUB Media Overlay SyncMediaTimeline if available in the publication.

    The returned promise is rejected if this EPUB does not contain Media Overlays, or if the resulting timeline is empty.

    Parameters

    • readerDocuments: IReaderDocument[]

      The reader documents that should be part of the timeline.

    • Optional options: IEpubMediaOverlaySyncMediaTimelineOptions

      Options for the IEpubMediaOverlaySyncMediaTimeline.

    • Optional progressCallback: (progress: number) => void

      A function called several times indicating the create progress as a value between 0 and 1. You can also listen on the event 'syncMediaTimelineCreateProgress' to get this information.

        • (progress: number): void
        • Parameters

          • progress: number

          Returns void

    Returns Promise<ISyncMediaTimeline>

createTtsSyncMediaTimeline

  • Creates a TTS SyncMediaTimeline using the ContentBlocks from the specified reader documents.

    The returned promise is rejected if this EPUB does not contain any text, i.e. if the resulting timeline is empty.

    Parameters

    • readerDocuments: IReaderDocument[]

      The reader documents that should be part of the timeline.

    • Optional options: ISyncMediaTtsTimelineBuilderOptions

      Options to use when building the timeline.

    • Optional progressCallback: (progress: number) => void

      A function called several times indicating the create progress as a value between 0 and 1. You can also listen on the event 'syncMediaTimelineCreateProgress' to get this information.

        • (progress: number): void
        • Parameters

          • progress: number

          Returns void

    Returns Promise<ISyncMediaTimeline>

destroy

  • destroy(): void
  • Destroy this instance, allowing used resources to be garbage collected. This method has the same effect as calling readingSystemEngine.unloadPublication(),

    Returns void

fetchContentLocation

  • Fetch the resolved IContentLocation from a locator, ILocatorData, URL, URI, URN, IRI.

    In contrast to UnresolvedContentLocation, a ContentLocation knows its position within the publication content and can thereby be used to compare and sort ContentLocation instances synchronously.

    See IContentLocation for more information

    Parameters

    Returns Promise<IContentLocation>

fetchContentLocationFromHref

  • fetchContentLocationFromHref(href: string, baseUrl?: URL): Promise<IContentLocation>
  • Fetches a ContentLocation for hrefs like chapter02.xhtml#title-4.

    If href is a relative URL, you can specify a baseUrl to from where href is relative to. If you don't specify a baseUrl it will default to the root of the EPUB.

    For example: To resolve a relative href link found in a ReaderDocument, you should pass the URL of that ReaderDocument as baseUrl:

    await readerPublication.fetchContentLocationFromHref(href, readerDocument.getSourceContentDocument().getContentUrl())
    

    The returned Promise is rejected with an error if:

    • href does not resolve to a ReaderDocument in this publication.
    • a "#hash" is specified in href and does not match any element id in the document.

    Parameters

    • href: string
    • Optional baseUrl: URL

    Returns Promise<IContentLocation>

fetchPreferredPageAspectRatio

  • fetchPreferredPageAspectRatio(): Promise<number>

fetchPublicationNavigation

fetchUnresolvedContentLocation

getAvailableContentPositionTimelineUnits

getAvailableSyncMediaFormats

getDefaultLocatorUrl

  • getDefaultLocatorUrl(): string

getLocatorFactory

getOptions

getReaderPublicationStorage

  • Get the IReaderPublicationStorage instance for this publication. Use the returned instance to manage the publication's storage, such as 'localStorage' for EPUB. This allows applications to save and restore the state of the IReaderPublicationStorage across reading-sessions and devices.

    Returns IReaderPublicationStorage

getReadingSystemEngine

getSourcePublication

getSpine

isDestroyed

  • isDestroyed(): boolean

isLocatorSourceUrlInPublication

  • If the source URL of the locator, (that is URL without the hash) matches the any source URL in the Publication.

    If this method returns true, the locator MAY target content in the publication, depending on selectors inside the Locator. If this method return false, the locator DOES NOT target any content in the publication.

    Parameters

    Returns boolean

isMediaOverlaySyncMediaAvailable

  • isMediaOverlaySyncMediaAvailable(): boolean
  • If this publication contains Media Overlays. If this method returns true, you can create a SyncMediaTimeline from the Media Overlays using createMediaOverlaySyncMediaTimeline().

    Returns boolean

setOptions

  • Sets new IReaderPublicationOptions for this instance. Existing properties are preserved if they aren't defined in the passed options object. Properties explicitly set to undefined will be restored to their default values.

    Changes affecting the appearance or behavior of the ReaderPublication when used with a ReaderView will not take effect until ReaderView.refresh() is called.

    Parameters

    Returns void

toJSON

Generated using TypeDoc