maniiifest
Version:
Typesafe IIIF presentation v3 manifest and collection parsing without external dependencies
591 lines (590 loc) • 27 kB
TypeScript
import type * as T from "./specification";
/**
* The `Maniiifest` class provides methods to parse and manipulate IIIF JSON manifests and collections.
* It ensures type safety and offers utility functions for working with IIIF data.
*/
export declare class Maniiifest {
specification: any;
/**
* Constructs a new instance of the Maniiifest class.
*
* This constructor initializes the specification based on the provided data and type.
* It supports the following types:
* - "AnnotationCollection": Reads the data as an AnnotationCollection specification.
* - "AnnotationPage": Reads the data as an AnnotationPage specification.
* - "Annotation": Reads the data as an Annotation specification.
* - undefined: Reads the data as a general specification.
*
* @param data - The data to be parsed into a specification.
* @param type - The type of the specification. Can be "AnnotationCollection", "AnnotationPage", "Annotation", or undefined.
* @throws {Error} Throws an error if an unsupported type is provided.
*/
constructor(data: any, type?: string);
/**
* Retrieves the type of the manifest specification.
*
* @returns {string} The type of the manifest specification.
*/
getSpecificationType(): string;
/**
* Retrieves the context from the manifest specification if it is of kind 'Manifest'.
*
* @returns {T.ContextT | null} The context if the specification is of kind 'Manifest', otherwise null.
*/
getManifestContext(): T.ContextT | null;
/**
* Retrieves the manifest ID if the specification kind is 'Manifest'.
*
* @returns {T.IdT | null} The manifest ID if the specification kind is 'Manifest', otherwise `null`.
*/
getManifestId(): T.IdT | null;
/**
* Retrieves the label from the manifest specification if it is of kind 'Manifest'.
*
* @returns {T.LabelT | null} The label if the specification is of kind 'Manifest' and has a label value, otherwise null.
*/
getManifestLabel(): T.LabelT | null;
/**
* Retrieves the label from the manifest specification by language if it is of kind 'Manifest'.
*
* @param {string} language - The language code to retrieve the label for.
* @returns {T.LabelT2 | null} The label for the specified language if it exists, otherwise null.
*/
getManifestLabelByLanguage(language: string): T.LngStringT | null;
/**
* Retrieves the summary from the manifest specification if it is of kind 'Manifest'.
*
* @returns {T.SummaryT | null} The summary if the specification is of kind 'Manifest' and has a summary value, otherwise null.
*/
getManifestSummary(): T.SummaryT | null;
/**
* Retrieves the viewing direction from the manifest specification if it is of kind 'Manifest'.
*
* @returns {T.ViewingDirectionT | null} The viewing direction if the specification is of kind 'Manifest' and has a viewing direction value, otherwise null.
*/
getManifestViewingDirection(): T.ViewingDirectionT | null;
/**
* Retrieves the navigation date from the manifest specification if it is of kind 'Manifest'.
*
* @returns {T.NavDateT | null} The navigation date if the specification is of kind 'Manifest' and has a navDate value, otherwise null.
*/
getManifestNavDate(): T.NavDateT | null;
/**
* Retrieves the navigation place from the manifest specification if it is of kind 'Manifest'.
*
* @returns {T.NavPlaceT | null} The navigation place if the specification is of kind 'Manifest' and has a navPlace value, otherwise null.
*/
getManifestNavPlace(): T.NavPlaceT | null;
/**
* Retrieves the rights statement from the manifest specification if it is of kind 'Manifest'.
*
* @returns {T.RightsT | null} The rights statement if the specification is of kind 'Manifest' and has a rights value, otherwise null.
*/
getManifestRights(): T.RightsT | null;
/**
* Retrieves the required statement from the manifest specification if it is of kind 'Manifest'.
*
* @returns {T.RequiredStatementT | null} The required statement if the specification is of kind 'Manifest' and has a required statement value, otherwise null.
*/
getManifestRequiredStatement(): T.RequiredStatementT | null;
/**
* Retrieves the start element from the manifest specification if it is of kind 'Manifest'.
*
* @returns {T.StartT | null} The start element if the specification is of kind 'Manifest' and has a start value, otherwise null.
*/
getManifestStart(): T.StartT | null;
/**
* Retrieves the service from the manifest specification if it is of kind 'Manifest'.
*
* @returns {T.ServiceT | null} The service if the specification is of kind 'Manifest' and has a service value, otherwise null.
*/
getManifestService(): T.ServiceT | null;
/**
* Retrieves the manifest from the manifest specification if it is of kind 'Manifest'.
*
* @returns {T.ManifestT | null} The manifest if the specification is of kind 'Manifest' and has a value, otherwise null.
*/
getManifest(): T.ManifestT | null;
/**
* Retrieves the collection from the manifest specification if it is of kind 'Collection'.
*
* @returns {T.CollectionT | null} The collection if the specification is of kind 'Collection' and has a value, otherwise null.
*/
getCollection(): T.CollectionT | null;
/**
* Retrieves the context from the manifest specification if it is of kind 'Collection'.
*
* @returns {T.ContextT | null} The context if the specification is of kind 'Collection', otherwise null.
*/
getCollectionContext(): T.ContextT | null;
/**
* Retrieves the collection ID from the manifest specification if it is of kind 'Collection'.
*
* @returns {T.IdT | null} The collection ID if the specification is of kind 'Collection', otherwise null.
*/
getCollectionId(): T.IdT | null;
/**
* Retrieves the collection label from the manifest specification if it is of kind 'Collection'.
*
* @returns {T.LabelT | null} The collection label if the specification is of kind 'Collection', otherwise null.
*/
getCollectionLabel(): T.LabelT | null;
/**
* Retrieves the label from the collection specification by language if it is of kind 'Collection'.
*
* @param {string} language - The language code to retrieve the label for.
* @returns {T.LabelT2 | null} The label for the specified language if it exists, otherwise null.
*/
getCollectionLabelByLanguage(language: string): T.LngStringT | null;
/**
* Retrieves the service from the collection specification if it is of kind 'Collection'.
*
* @returns {T.ServiceT | null} The service if the specification is of kind 'Collection' and has a service value, otherwise null.
*/
getCollectionService(): T.ServiceT | null;
/**
* Retrieves the required statement from the collection specification if it is of kind 'Collection'.
*
* @returns {T.RequiredStatementT | null} The required statement if the specification is of kind 'Manifest' and has a required statement value, otherwise null.
*/
getCollectionRequiredStatement(): T.RequiredStatementT | null;
/**
* Iterates over the W3C annotation elements on the canvases in the manifest.
*
* This generator function yields W3C annotation elements from the canvases in the manifest.
*
* @yields {T.AnnotationT} The next W3C annotation element on the canvases in the manifest.
*/
iterateManifestCanvasW3cAnnotation(): IterableIterator<T.AnnotationT>;
/**
* Iterates over the textual bodies of annotations in the manifest's canvases.
*
* @returns {IterableIterator<T.AnnotationBodyT4>} An iterator over the textual bodies of annotations.
*/
iterateManifestCanvasW3cAnnotationTextualBody(): IterableIterator<T.AnnotationBodyT4>;
/**
* Iterates over the W3C annotation page elements on the canvases in the manifest.
*
* This generator function yields W3C annotation page elements from the canvases in the manifest.
*
* @yields {T.AnnotationPageT} The next W3C annotation page element on the canvases in the manifest.
*/
iterateManifestCanvasW3cAnnotationPage(): IterableIterator<T.AnnotationPageT>;
/**
* Iterates over the annotation page elements on the canvases in the manifest.
*
* This generator function yields annotation page elements from the canvases in the manifest.
*
* @yields {T.AnnotationPageT} The next annotation page element on the canvases in the manifest.
*/
iterateManifestCanvasAnnotationPage(): IterableIterator<T.AnnotationPageT>;
/**
* Iterates over the annotation elements on the canvases in the manifest.
*
* This generator function yields annotation elements from the canvases in the manifest.
*
* @yields {T.AnnotationT} The next annotation element on the canvases in the manifest.
*/
iterateManifestCanvasAnnotation(): IterableIterator<T.AnnotationT>;
/**
* Iterates over the canvas elements in the manifest.
*
* This generator function yields canvas elements from the manifest.
*
* @yields {T.CanvasT} The next canvas element in the manifest.
*/
iterateManifestCanvas(): IterableIterator<T.CanvasT>;
/**
* Iterates over the thumbnail elements in the manifest.
*
* This generator function yields thumbnail elements from the manifest.
*
* @yields {T.ThumbnailT} The next thumbnail element in the manifest.
*/
iterateManifestThumbnail(): IterableIterator<T.ThumbnailT>;
/**
* Iterates over the homepage elements in the manifest.
*
* This generator function yields homepage elements from the manifest.
*
* @yields {T.HomepageT} The next homepage element in the manifest.
*/
iterateManifestHomepage(): IterableIterator<T.HomepageT>;
/**
* Iterates over the behavior elements in the manifest.
*
* This generator function yields behavior elements from the manifest.
*
* @yields {T.BehaviorT} The next behavior element in the manifest.
*/
iterateManifestBehavior(): IterableIterator<T.BehaviorT>;
/**
* Iterates over the providers in the manifest.
*
* This generator function yields providers from the manifest.
*
* @yields {T.ProviderT} The next provider in the manifest.
*/
iterateManifestProvider(): IterableIterator<T.ProviderT>;
/**
* Iterates over the "rendering" elements in the manifest.
*
* This generator function yields "rendering" elements from the manifest.
*
* @yields {T.RenderingT} The next "rendering" element in the manifest.
*/
iterateManifestRendering(): IterableIterator<T.RenderingT>;
/**
* Iterates over the "homepage" elements in the providers of the manifest.
*
* This generator function yields "homepage" elements from the providers within the manifest.
*
* @yields {T.HomepageT} The next "homepage" element in the providers of the manifest.
*/
iterateManifestProviderHomepage(): IterableIterator<T.HomepageT>;
/**
* Iterates over the "seeAlso" elements in the providers of the manifest.
*
* This generator function yields "seeAlso" elements from the providers within the manifest.
*
* @yields {T.SeeAlsoT} The next "seeAlso" element in the providers of the manifest.
*/
iterateManifestProviderSeeAlso(): IterableIterator<T.SeeAlsoT>;
/**
* Iterates over the metadata elements in the manifest.
*
* This generator function yields metadata elements from the manifest.
*
* @yields {T.MetadataT} The next metadata element in the manifest.
*/
iterateManifestMetadata(): IterableIterator<T.MetadataT>;
/**
* Iterates over the "seeAlso" elements in the manifest.
*
* This generator function yields "seeAlso" elements from the manifest.
*
* @yields {T.SeeAlsoT} The next "seeAlso" element in the manifest.
*/
iterateManifestSeeAlso(): IterableIterator<T.SeeAlsoT>;
/**
* Iterates over the "partOf" elements in the manifest.
*
* This generator function yields "partOf" elements from the manifest.
*
* @yields {T.PartOfT} The next "partOf" element in the manifest.
*/
iterateManifestPartOf(): IterableIterator<T.PartOfT>;
/**
* Iterates over the ranges in the manifest.
*
* This generator function yields ranges from the structures within the manifest.
*
* @yields {T.RangeT} The next range in the manifest.
*/
iterateManifestRange(): IterableIterator<T.RangeT>;
/**
* Iterates over the navigation place features in the manifest.
*
* This generator function yields features from the navigation places within the manifest.
*
* @yields {T.FeatureT} The next feature in the navigation places of the manifest.
*/
iterateManifestNavPlaceFeature(): IterableIterator<T.FeatureT>;
/**
* Iterates over the navigation place features in the manifest's canvases.
*
* This generator function yields features from the navigation places within the canvases of the manifest.
*
* @yields {T.FeatureT} The next feature in the navigation places of the manifest's canvases.
*/
iterateManifestCanvasNavPlaceFeature(): IterableIterator<T.FeatureT>;
/**
* Iterates over the range items in the manifest.
*
* This generator function yields range items from the structures within the manifest.
*
* @yields {T.RangeItemsT} The next range item in the manifest.
*/
iterateManifestRangeItem(): IterableIterator<T.RangeItemsT>;
/**
* Iterates over the collections and manifests in the specification.
*
* This generator function yields collections from the specification, recursively from nested collections,
* and manifests found within the collections.
*
* @yields {T.CollectionT | T.ManifestT} The next collection or manifest item in the specification.
*/
iterateCollection(): IterableIterator<T.CollectionT | T.ManifestT>;
/**
* Iterates over the collections in the specification.
*
* This generator function yields collections from the specification and recursively from nested collections.
*
* @yields {T.CollectionT} The next collection item in the specification.
*/
iterateCollectionCollection(): IterableIterator<T.CollectionT>;
/**
* Iterates over the manifests in the collection.
*
* This generator function yields manifests from the collection's manifest and recursively from nested collections.
*
* @yields {T.ManifestT} The next manifest item in the collection.
*/
iterateCollectionManifest(): IterableIterator<T.ManifestT>;
/**
* Iterates over the labels in the collection.
*
* This generator function yields labels from the collection's label and recursively from nested collections.
*
* @yields {T.LabelT} The next label item in the collection.
*/
iterateCollectionLabel(): IterableIterator<T.LabelT>;
/**
* Iterates over the thumbnails in the collection.
*
* This generator function yields thumbnails from the collection's thumbnail and recursively from nested collections.
*
* @yields {T.ThumbnailT} The next thumbnail item in the collection.
*/
iterateCollectionThumbnail(): IterableIterator<T.ThumbnailT>;
/**
* Iterates over the metadata in the collection.
*
* This generator function yields metadata from the collection's metadata and recursively from nested collections.
*
* @yields {T.MetadataT} The next metadata item in the collection.
*/
iterateCollectionMetadata(): IterableIterator<T.MetadataT>;
/**
* Iterates over the providers in the collection.
*
* This generator function yields providers from the collection's provider property and recursively from nested collections.
*
* @yields {T.ProviderT} The next provider item in the collection.
*/
iterateCollectionProvider(): IterableIterator<T.ProviderT>;
/**
* Iterates over the services in the collection.
*
* This generator function yields services from the collection's service property and recursively from nested collections.
*
* @yields {T.ServiceItemT} The next service item in the collection.
*/
iterateCollectionService(): IterableIterator<T.ServiceItemT>;
/**
* Iterates over the services in the manifest.
*
* This generator function yields services from the service pages within the manifest.
*
* @yields {T.ServiceT} The next service in the manifest.
*/
iterateManifestService(): IterableIterator<T.ServiceItemT>;
/**
* Iterates over the services within the thumbnail services in the manifest.
*
* This generator function yields services from the service pages within the thumbnail services of the manifest.
*
* @yields {T.ServiceT} The next service within the thumbnail services in the manifest.
*/
iterateManifestThumbnailService(): IterableIterator<T.ServiceItemT>;
/**
* Iterates over the services in the manifest.
*
* This generator function yields services from the manifest's service pages.
*
* @yields {T.ServiceT} The next service in the manifest.
*/
iterateManifestServices(): IterableIterator<T.ServiceItemT>;
/**
* Iterates over the W3C annotations in the manifest.
*
* This generator function yields annotations from the manifest's annotation pages.
*
* @yields {T.AnnotationT} The next annotation in the manifest.
*/
iterateManifestW3cAnnotation(): IterableIterator<T.AnnotationT>;
/**
* Iterates over the textual bodies of annotations in the manifest.
*
* @returns {IterableIterator<T.AnnotationBodyT4>} An iterator over the textual bodies of annotations.
*/
iterateManifestW3cAnnotationTextualBody(): IterableIterator<T.AnnotationBodyT4>;
/**
* Iterates over W3C Annotation Pages in a Manifest.
*
* This generator function iterates through each annotation page present in the manifest's annotations.
* It yields each annotation page transformed by `F.writeAnnotationPageT` for further processing.
*
* @yields {IterableIterator<T.AnnotationPageT>} An iterator that yields annotation pages as `T.AnnotationPageT` objects.
*/
iterateManifestW3cAnnotationPage(): IterableIterator<T.AnnotationPageT>;
/**
* Retrieves the annotation collection if the specification type is 'AnnotationCollection'.
*
* @returns {T.AnnotationCollectionT | null} The annotation collection if the specification type is 'AnnotationCollection', otherwise `null`.
*/
getAnnotationCollection(): T.AnnotationCollectionT | null;
/**
* Retrieves the annotation collection ID if the specification type is 'AnnotationCollection'.
*
* @returns {T.IdT | null} The annotation collection ID if the specification type is 'AnnotationCollection', otherwise `null`.
*/
getAnnotationCollectionId(): T.IdT | null;
/**
* Retrieves the type of the annotation collection if the specification type is 'AnnotationCollection'.
*
* @returns {T.TypeT | null} The type of the annotation collection if the specification type is 'AnnotationCollection', otherwise `null`.
*/
getAnnotationCollectionType(): T.TypeT | null;
/**
* Retrieves the annotation collection context if the specification type is 'AnnotationCollection'.
*
* @returns {T.ContextT | null} The annotation collection context if the specification type is 'AnnotationCollection', otherwise `null`.
*/
getAnnotationCollectionContext(): T.ContextT | null;
/**
* Retrieves the annotation collection label if the specification type is 'AnnotationCollection'.
*
* @returns {T.LabelT | null} The annotation collection label if the specification type is 'AnnotationCollection', otherwise `null`.
*/
getAnnotationCollectionLabel(): T.LabelT | null;
/**
* Retrieves the first annotation in the collection if the specification type is 'AnnotationCollection'.
*
* @returns {T.FirstT | null} The first annotation in the collection if the specification type is 'AnnotationCollection', otherwise `null`.
*/
getAnnotationCollectionFirst(): T.FirstT | null;
/**
* Retrieves the last annotation in the collection if the specification type is 'AnnotationCollection'.
*
* @returns {T.LastT | null} The last annotation in the collection if the specification type is 'AnnotationCollection', otherwise `null`.
*/
getAnnotationCollectionLast(): T.LastT | null;
/**
* Retrieves the total number of annotations in the collection if the specification type is 'AnnotationCollection'.
*
* @returns {T.TotalT | null} The total number of annotations in the collection if the specification type is 'AnnotationCollection', otherwise `null`.
*/
getAnnotationCollectionTotal(): T.TotalT | null;
/**
* Retrieves the annotation page if the specification type is 'AnnotationPage'.
*
* @returns {T.AnnotationPageT | null} The annotation page if the specification type is 'AnnotationPage', otherwise `null`.
*/
getAnnotationPage(): T.AnnotationPageT | null;
/**
* Retrieves the type of the annotation page if the specification type is 'AnnotationPage'.
*
* @returns {T.TypeT | null} The type of the annotation page if the specification type is 'AnnotationPage', otherwise `null`.
*/
getAnnotationPageType(): T.TypeT | null;
/**
* Retrieves the annotation page ID if the specification type is 'AnnotationPage'.
*
* @returns {T.IdT | null} The annotation page ID if the specification type is 'AnnotationPage', otherwise `null`.
*/
getAnnotationPageId(): T.IdT | null;
/**
* Retrieves the annotation page context if the specification type is 'AnnotationPage'.
*
* @returns {T.ContextT | null} The annotation page context if the specification type is 'AnnotationPage', otherwise `null`.
*/
getAnnotationPageContext(): T.ContextT | null;
/**
* Retrieves the 'partOf' property from the specification if the type is 'AnnotationPage'.
*
* @returns {T.PartOfT | null} The 'partOf' property if the specification type is 'AnnotationPage', otherwise null.
*/
getAnnotationPagePartOf(): T.PartOfT | null;
/**
* Iterates over the annotations in the specification if the type is 'AnnotationPage'.
*
* @yields {T.AnnotationT} The annotations from the specification.
*/
iterateAnnotationPageAnnotation(): IterableIterator<T.AnnotationT>;
/**
* Iterates over the textual bodies of annotations in the annotation page.
*
* @returns {IterableIterator<T.AnnotationBodyT4>} An iterator over the textual bodies of annotations.
*/
iterateAnnotationPageAnnotationTextualBody(): IterableIterator<T.AnnotationBodyT4>;
/**
* Iterates over the textual bodies in a single annotation.
*
* @returns {IterableIterator<T.AnnotationBodyT4>} An iterator over the textual bodies of an annotation.
*/
iterateAnnotationTextualBody(): IterableIterator<T.AnnotationBodyT4>;
/**
* Iterates over the resource bodies in a single annotation.
*
* @returns {IterableIterator<T.AnnotationBodyT2>} An iterator over the resource bodies of an annotation.
*/
iterateAnnotationResourceBody(): IterableIterator<T.AnnotationBodyT2>;
/**
* Iterates over targets in a single annotation.
*
* @returns {IterableIterator<T.AnnotationTargetT>} An iterator over the target of an annotation.
*/
iterateAnnotationTarget(): IterableIterator<T.AnnotationTargetT>;
/**
* Iterates over the target of annotations that contain partOf properties in the annotation page.
*
* @returns {IterableIterator<T.AnnotationTargetT4>} An iterator over the target of annotations with partOf properties.
*/
iterateAnnotationPageAnnotationPartOf(): IterableIterator<T.AnnotationTargetT4>;
/**
* Retrieves the annotation if the specification type is 'Annotation'.
*
* @returns {T.AnnotationT | null} The annotation if the specification type is 'Annotation', otherwise `null`.
*/
getAnnotation(): T.AnnotationT | null;
/**
* Retrieves the annotation ID if the specification type is 'Annotation'.
*
* @returns {T.IdT | null} The annotation ID if the specification type is 'Annotation', otherwise `null`.
*/
getAnnotationId(): T.IdT | null;
/**
* Retrieves the annotation type if the specification type is 'Annotation'.
*
* @returns {T.TypeT | null} The annotation type if the specification type is 'Annotation', otherwise `null`.
*/
getAnnotationType(): T.TypeT | null;
/**
* Retrieves the annotation context if the specification type is 'Annotation'.
*
* @returns {T.ContextT | null} The annotation context if the specification type is 'Annotation', otherwise `null`.
*/
getAnnotationContext(): T.ContextT | null;
/**
* Retrieves the annotation body if the specification type is 'Annotation'.
*
* @returns {T.BodyT | null} The annotation body if the specification type is 'Annotation', otherwise `null`.
*/
getAnnotationBody(): T.BodyT | null;
/**
* Retrieves the annotation target if the specification type is 'Annotation'.
*
* @returns {T.TargetT | null} The annotation target if the specification type is 'Annotation', otherwise `null`.
*/
getAnnotationTarget(): T.TargetT | null;
/**
* Retrieves the annotation motivation if the specification type is 'Annotation'.
*
* @returns {T.MotivationT | null} The annotation motivation if the specification type is 'Annotation', otherwise `null`.
*/
getAnnotationMotivation(): T.MotivationT | null;
/**
* Returns the feature collection if the specification kind is 'T6', otherwise returns null.
*/
getAnnotationFeatureCollection(): T.FeatureCollectionT | null;
/**
* Generator function that yields each feature if the specification kind is 'T6'.
*/
iterateAnnotationFeature(): IterableIterator<T.FeatureT>;
/**
* Generator function that yields point coordinates for each feature with geometry kind 'T1'
* if the specification kind is 'T6'.
*/
iterateAnnotationGeometryPointCoordinates(): IterableIterator<T.PointCoordinatesT>;
}