Colibrio Reader Framework API - Cloud license
    Preparing search index...

    Format specific API for an EPUB ReaderPublication.

    interface IEpubReaderPublication {
        createContentPositionTimeline(
            readerDocuments: IReaderDocument[],
            options?: EpubContentPositionTimelineOptions,
            progressCallback?: (progress: number) => void,
        ): Promise<IContentPositionTimeline>;
        createMediaOverlaySyncMediaTimeline(
            readerDocuments: IReaderDocument[],
            options?: IEpubMediaOverlaySyncMediaTimelineOptions,
            progressCallback?: (progress: number) => void,
        ): Promise<ISyncMediaTimeline>;
        createTtsSyncMediaTimeline(
            readerDocuments: IReaderDocument[],
            options?: ISyncMediaTtsTimelineBuilderOptions,
            progressCallback?: (progress: number) => void,
        ): Promise<ISyncMediaTimeline>;
        destroy(): void;
        fetchContentLocation(
            locator:
                | ILocator
                | ILocatorData
                | IReaderPublicationNavigationItemData
                | IReaderPublicationNavigationItem,
        ): Promise<IContentLocation>;
        fetchContentLocationFromHref(
            href: string,
            baseUrl?: URL,
        ): Promise<IContentLocation>;
        fetchPreferredPageAspectRatio(): Promise<number>;
        fetchPublicationNavigation(): Promise<IReaderPublicationNavigation>;
        fetchUnresolvedContentLocation(
            locator:
                | ILocator
                | ILocatorData
                | IReaderPublicationNavigationItemData
                | IReaderPublicationNavigationItem,
        ): Promise<IUnresolvedContentLocation>;
        getAvailableContentPositionTimelineUnits(): ContentPositionTimelineUnit[];
        getAvailableSyncMediaFormats(): SyncMediaFormat[];
        getDefaultLocatorUrl(): string;
        getLocatorFactory(): ILocatorFactory;
        getOptions(): DeepRequired<IEpubReaderPublicationOptions>;
        getReaderPublicationStorage(): IReaderPublicationStorage;
        getReadingSystemEngine(): IReadingSystemEngine;
        getSourcePublication(): IEpubPublication;
        getSpine(): IReaderDocument[];
        isDestroyed(): boolean;
        isLocatorSourceUrlInPublication(locator: ILocator | ILocatorData): boolean;
        isMediaOverlaySyncMediaAvailable(): boolean;
        setOptions(options: IEpubReaderPublicationOptions): void;
        toJSON(): IReaderPublicationData;
    }

    Hierarchy (View Summary)

    Methods

    • 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.

      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.

      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.

      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.

      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.

      • Optionaloptions: EpubContentPositionTimelineOptions

        Options to use for the timeline.

      • OptionalprogressCallback: (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.

      Returns Promise<IContentPositionTimeline>

    • 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.

      • Optionaloptions: IEpubMediaOverlaySyncMediaTimelineOptions

        Options for the IEpubMediaOverlaySyncMediaTimeline.

      • OptionalprogressCallback: (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.

      Returns Promise<ISyncMediaTimeline>

    • 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.

      • Optionaloptions: ISyncMediaTtsTimelineBuilderOptions

        Options to use when building the timeline.

      • OptionalprogressCallback: (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.

      Returns Promise<ISyncMediaTimeline>

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

      Returns void

    • 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
      • OptionalbaseUrl: URL

      Returns Promise<IContentLocation>

    • 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

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

      Returns boolean

    • 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(true) is called.

      Returns void