Diva.js Public API - v7.4.0
    Preparing search index...

    Class Diva

    A browser viewer for IIIF Presentation manifests and collections.

    Diva is an EventTarget. Listen on the instance for the typed events in DivaEventMap; OpenSeadragon objects, Elm ports, and authorization state are intentionally not part of the public API.

    Page indexes are zero-based. Commands that require a loaded viewer wait for Diva.ready or an active Diva.setResource operation.

    const viewer = new Diva("diva-wrapper", {
    objectData: "https://example.org/iiif/manifest.json"
    });

    await viewer.ready;
    console.log(viewer.getPages());
    import Diva from "diva.js";

    const viewer = new Diva("diva-wrapper", { objectData: manifestUrl });
    await viewer.ready;

    Hierarchy

    • EventTarget
      • Diva
    Index
    • Create a Diva viewer in an existing root element.

      Parameters

      • rootId: string

        HTML id of the root element, without a leading #.

      • flags: DivaOptions

        Initial resource and display options.

      Returns Diva

      Error Thrown synchronously when no element has the supplied rootId.

      Constructing another Diva instance for the same root destroys the previous instance first.

    ready: Promise<void>

    Resolves when the initial resource and selected initial page are ready.

    Collections without an active manifest resolve when their collection UI is ready. Calling Diva.setResource before readiness supersedes the constructor resource, so this promise follows that replacement. It rejects when the resource that owns startup fails or the instance is destroyed.

    • Register a listener for a typed Diva event.

      Type Parameters

      Parameters

      • type: K

        Event name from DivaEventMap.

      • listener: (this: Diva, event: DivaEventMap[K]) => any

        Callback invoked with the event's typed CustomEvent.

      • Optionaloptions: boolean | AddEventListenerOptions

        Standard DOM listener options.

      Returns void

    • Register a listener for a typed Diva event.

      Parameters

      • type: string

        Event name from DivaEventMap.

      • listener: EventListenerOrEventListenerObject | null

        Callback invoked with the event's typed CustomEvent.

      • Optionaloptions: boolean | AddEventListenerOptions

        Standard DOM listener options.

      Returns void

    • Remove a previously registered Diva event listener.

      Type Parameters

      Parameters

      Returns void

    • Remove a previously registered Diva event listener.

      Parameters

      • type: string

        Event name from DivaEventMap.

      • listener: EventListenerOrEventListenerObject | null

        Callback originally passed to Diva.addEventListener.

      • Optionaloptions: boolean | EventListenerOptions

        Standard DOM listener options used for matching.

      Returns void

    • Return a defensive snapshot of current viewer state.

      Returns Readonly<DivaState>

      State that callers may retain without observing later mutations.

    • Return defensive metadata snapshots for every displayed page.

      Returns readonly DivaPage[]

      Pages in zero-based display order. Auth tokens and resolved loading URLs are never included.

    • Find a displayed page by Canvas identifier or localized display label.

      Parameters

      Returns DivaPage | undefined

      A defensive page snapshot, or undefined when no page matches.

      TypeError Thrown when a runtime value is not a valid DivaPageSelector.

      Canvas IDs are case-sensitive. Labels are case-insensitive but are not trimmed, whitespace-normalized, or substring-matched. Duplicate labels return the first page in manifest order.

    • Return metadata for the active page, if the resource has pages.

      Returns DivaPage | undefined

      The active page, or undefined before page initialization and for collections without an active manifest.

    • Return the pages in the active row or opening.

      Returns readonly DivaPage[]

      One page in single mode, or the pages belonging to the current logical opening in a spread mode.

    • Replace the current IIIF manifest or collection without replacing this instance.

      Parameters

      • url: string

        URL of a IIIF Presentation manifest or collection.

      Returns Promise<void>

      A promise that resolves when the replacement and its first displayable page are ready.

      TypeError Rejected when url is empty.

      DOMException Rejected with AbortError when superseded by a newer replacement, or with InvalidStateError when the viewer has been destroyed.

      Event listeners remain attached. Fetching or parsing failures leave the previous resource active. Once a replacement parses, it becomes active; failure of its required image rejects while leaving that replacement and its unavailable-image UI in place. Calling this method before any resource is ready supersedes the constructor resource and determines the outcome of Diva.ready.

      await viewer.setResource("https://example.org/iiif/next-manifest.json");
      
    • Navigate to a zero-based page index.

      Parameters

      Returns Promise<void>

      A promise that resolves after the navigation command is accepted.

      RangeError Rejected when index is not an available integer page index.

      DOMException Rejected with InvalidStateError after destruction.

    • Navigate to a page selected by Canvas identifier or display label.

      Parameters

      Returns Promise<boolean>

      true after navigation, or false without moving when no page matches.

      TypeError Rejected when a runtime selector object is malformed.

    • Navigate to the next page or opening for the active layout.

      Returns Promise<void>

      A promise that resolves after navigation, or immediately at the final opening.

      Spread modes advance by logical opening; clients do not need to calculate a page step.

    • Navigate to the previous page or opening for the active layout.

      Returns Promise<void>

      A promise that resolves after navigation, or immediately at the first opening.

    • Set the OpenSeadragon viewport zoom to a positive value.

      Parameters

      • zoom: number

        Positive finite viewport zoom value.

      Returns Promise<void>

      A promise that resolves after the zoom command is applied.

      RangeError Rejected when zoom is not positive and finite.

    • Multiply the current viewport zoom by a positive factor.

      Parameters

      • factor: number

        Positive finite multiplier; values above 1 zoom in and values below 1 zoom out.

      Returns Promise<void>

      A promise that resolves after the zoom command is applied.

      RangeError Rejected when factor is not positive and finite.

    • Zoom in by Diva's standard zoom factor.

      Returns Promise<void>

      A promise that resolves after multiplying the zoom by 1.6.

    • Zoom out by Diva's standard zoom factor.

      Returns Promise<void>

      A promise that resolves after dividing the zoom by 1.6.

    • Fit a page, or the current page when omitted, into the viewport.

      Parameters

      • OptionalpageIndex: number

        Optional zero-based page index. Defaults to the active page.

      Returns Promise<void>

      A promise that resolves after the page image loads and is fitted.

      RangeError Rejected when there is no active page or pageIndex is unavailable.

    • Frame a full-resolution pixel rectangle on a page, waiting for that image when necessary.

      Parameters

      • pageIndex: number

        Zero-based page index containing the region.

      • region: DivaRegion

        Rectangle in full-resolution image pixels from the upper-left origin.

      • Optionaloptions: ZoomToRegionOptions

        Optional padding and animation settings.

      Returns Promise<void>

      A promise that resolves after the image loads and the viewport fits the region.

      RangeError Rejected for an unavailable page, negative coordinates, non-positive dimensions, non-finite values, or negative padding.

      Error Rejected when authorization or image loading fails.

      await viewer.zoomToRegion(
      12,
      { x: 840, y: 1250, width: 460, height: 180 },
      { padding: 0.08 }
      );
    • Change the page layout while preserving the active page.

      Parameters

      Returns Promise<void>

      A promise that resolves after the layout is applied.

      RangeError Rejected for a value outside DivaLayoutMode.

    • Request fullscreen display; browser user-activation rules apply.

      Returns Promise<void>

      A promise that resolves when the root enters fullscreen or is already fullscreen.

      DOMException Rejected when browser permissions or user-activation rules deny the request, or with InvalidStateError after destruction.

    • Exit fullscreen display when active.

      Returns Promise<void>

      A promise that resolves when fullscreen exits or when it was already inactive.

      DOMException Rejected when the browser cannot exit fullscreen or with InvalidStateError after destruction.

    • Enter or exit fullscreen display; browser user-activation rules apply.

      Returns Promise<void>

      The promise returned by Diva.enterFullscreen or Diva.exitFullscreen.

    • Cancel outstanding work, release resources, and empty the viewer root.

      Returns void

      Destruction is idempotent and permanent. Pending public commands reject with InvalidStateError; later commands do the same. State snapshots remain readable.

    • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.

      MDN Reference

      Parameters

      • event: Event

      Returns boolean