maniiifest
Version:
Typesafe IIIF presentation v3 manifest and collection parsing without external dependencies
1,129 lines (1,128 loc) • 59.4 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Maniiifest = void 0;
/**
* Imports all exports from the "specification" module as F and imports types from the "specification" module as T.
*
* The F namespace is used to access functions and constants defined in the "specification" module.
* The T namespace is used to access types defined in the "specification" module.
*/
const F = require("./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.
*/
class Maniiifest {
/**
* 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, type) {
switch (type) {
case "AnnotationCollection":
this.specification = F.readAnnotationCollectionT(data);
break;
case "AnnotationPage":
this.specification = F.readAnnotationPageT(data);
break;
case "Annotation":
this.specification = F.readAnnotationT(data);
break;
case undefined:
this.specification = F.readSpecificationT(data);
break;
default:
throw new Error(`Unsupported type: ${type}`);
}
}
/**
* Retrieves the type of the manifest specification.
*
* @returns {string} The type of the manifest specification.
*/
getSpecificationType() {
return this.specification.kind;
}
/**
* 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() {
return this.specification.kind === 'Manifest' && this.specification.value.context != undefined
? F.writeContextT(this.specification.value.context)
: 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() {
return this.specification.kind === 'Manifest' && this.specification.value.id != undefined
? F.writeIdT(this.specification.value.id)
: 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() {
return this.specification.kind === 'Manifest' && this.specification.value.label != undefined
? F.writeLabelT(this.specification.value.label)
: 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) {
if (this.specification.kind === 'Manifest' && this.specification.value.label.kind === 'T2') {
const labels = this.specification.value.label.value;
for (const [lang, _] of labels) {
if (lang === language) {
return F.writeLngStringT(this.specification.value.label.value);
}
}
}
return 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() {
var _a;
return this.specification.kind === 'Manifest' && ((_a = this.specification.value) === null || _a === void 0 ? void 0 : _a.summary) !== undefined
? F.writeSummaryT(this.specification.value.summary)
: 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() {
return this.specification.kind === 'Manifest' && this.specification.value.viewingDirection !== undefined
? F.writeViewingDirectionT(this.specification.value.viewingDirection)
: 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() {
return this.specification.kind === 'Manifest' && this.specification.value.navDate !== undefined
? F.writeNavDateT(this.specification.value.navDate)
: 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() {
return this.specification.kind === 'Manifest' && this.specification.value.navPlace !== undefined
? F.writeNavPlaceT(this.specification.value.navPlace)
: 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() {
return this.specification.kind === 'Manifest' && this.specification.value.rights !== undefined
? F.writeRightsT(this.specification.value.rights)
: 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() {
return this.specification.kind === 'Manifest' && this.specification.value.requiredStatement !== undefined
? F.writeRequiredStatementT(this.specification.value.requiredStatement)
: 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() {
return this.specification.kind === 'Manifest' && this.specification.value.start !== undefined
? F.writeStartT(this.specification.value.start)
: 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() {
return this.specification.kind === 'Manifest' && this.specification.value.service !== undefined
? F.writeServiceT(this.specification.value.service)
: 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() {
return this.specification.kind === 'Manifest' && this.specification.value !== undefined
? F.writeManifestT(this.specification.value)
: 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() {
return this.specification.kind === 'Collection' && this.specification.value !== undefined
? F.writeCollectionT(this.specification.value)
: 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() {
return this.specification.kind === 'Collection' && this.specification.value.context != undefined
? F.writeContextT(this.specification.value.context)
: 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() {
return this.specification.kind === 'Collection' && this.specification.value.id != undefined
? F.writeIdT(this.specification.value.id)
: 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() {
return this.specification.kind === 'Collection' && this.specification.value.label != undefined
? F.writeLabelT(this.specification.value.label)
: 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) {
if (this.specification.kind === 'Collection' && this.specification.value.label.kind === 'T2') {
const labels = this.specification.value.label.value;
for (const [lang, _] of labels) {
if (lang === language) {
return F.writeLngStringT(this.specification.value.label.value);
}
}
}
return 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() {
return this.specification.kind === 'Collection' && this.specification.value.service !== undefined
? F.writeServiceT(this.specification.value.service)
: 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() {
return this.specification.kind === 'Collection' && this.specification.value.requiredStatement !== undefined
? F.writeRequiredStatementT(this.specification.value.requiredStatement)
: 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() {
var _a, _b, _c;
if (this.specification.kind === 'Manifest') {
for (const canvas of (_a = this.specification.value.items) !== null && _a !== void 0 ? _a : []) {
for (const annotationPage of (_b = canvas.annotations) !== null && _b !== void 0 ? _b : []) {
for (const annotation of (_c = annotationPage.items) !== null && _c !== void 0 ? _c : []) {
yield F.writeAnnotationT(annotation);
}
}
}
}
}
/**
* 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() {
var _a, _b, _c, _d, _e, _f;
if (this.specification.kind === 'Manifest') {
for (const canvas of (_a = this.specification.value.items) !== null && _a !== void 0 ? _a : []) {
for (const annotationPage of (_b = canvas.annotations) !== null && _b !== void 0 ? _b : []) {
for (const annotation of (_c = annotationPage.items) !== null && _c !== void 0 ? _c : []) {
if (((_d = annotation.body) === null || _d === void 0 ? void 0 : _d.kind) === 'T2') { /* if body is an array */
for (const body of annotation.body.value) {
if (body.kind === 'T4') {
yield F.writeAnnotationBodyT4(body.value);
}
}
}
else { /* must be T1 */
if (((_f = (_e = annotation.body) === null || _e === void 0 ? void 0 : _e.value) === null || _f === void 0 ? void 0 : _f.kind) === 'T4') {
yield F.writeAnnotationBodyT4(annotation.body.value.value);
}
}
}
}
}
}
}
/**
* 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() {
var _a, _b;
if (this.specification.kind === 'Manifest') {
for (const canvas of (_a = this.specification.value.items) !== null && _a !== void 0 ? _a : []) {
for (const annotationPage of (_b = canvas.annotations) !== null && _b !== void 0 ? _b : []) {
yield F.writeAnnotationPageT(annotationPage);
}
}
}
}
/**
* 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() {
var _a, _b;
if (this.specification.kind === 'Manifest') {
for (const canvas of (_a = this.specification.value.items) !== null && _a !== void 0 ? _a : []) {
for (const annotationPage of (_b = canvas.items) !== null && _b !== void 0 ? _b : []) {
yield F.writeAnnotationPageT(annotationPage);
}
}
}
}
/**
* 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() {
var _a, _b, _c;
if (this.specification.kind === 'Manifest') {
for (const canvas of (_a = this.specification.value.items) !== null && _a !== void 0 ? _a : []) {
for (const annotationPage of (_b = canvas.items) !== null && _b !== void 0 ? _b : []) {
for (const annotation of (_c = annotationPage.items) !== null && _c !== void 0 ? _c : []) {
yield F.writeAnnotationT(annotation);
}
}
}
}
}
/**
* 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() {
var _a;
if (this.specification.kind === 'Manifest') {
for (const canvas of (_a = this.specification.value.items) !== null && _a !== void 0 ? _a : []) {
yield F.writeCanvasT(canvas);
}
}
}
/**
* 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() {
var _a;
if (this.specification.kind === 'Manifest') {
for (const thumbnail of (_a = this.specification.value.thumbnail) !== null && _a !== void 0 ? _a : []) {
yield F.writeThumbnailT(thumbnail);
}
}
}
/**
* 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() {
var _a;
if (this.specification.kind === 'Manifest') {
for (const homepage of (_a = this.specification.value.homepage) !== null && _a !== void 0 ? _a : []) {
yield F.writeHomepageT(homepage);
}
}
}
/**
* 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() {
var _a;
if (this.specification.kind === 'Manifest') {
for (const behavior of (_a = this.specification.value.behavior) !== null && _a !== void 0 ? _a : []) {
yield F.writeBehaviorT(behavior);
}
}
}
/**
* 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() {
var _a;
if (this.specification.kind === 'Manifest') {
for (const provider of (_a = this.specification.value.provider) !== null && _a !== void 0 ? _a : []) {
yield F.writeProviderT(provider);
}
}
}
/**
* 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() {
var _a;
if (this.specification.kind === 'Manifest') {
for (const rendering of (_a = this.specification.value.rendering) !== null && _a !== void 0 ? _a : []) {
yield F.writeRenderingT(rendering);
}
}
}
/**
* 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() {
var _a, _b;
if (this.specification.kind === 'Manifest') {
for (const provider of (_a = this.specification.value.provider) !== null && _a !== void 0 ? _a : []) {
for (const homepage of (_b = provider.homepage) !== null && _b !== void 0 ? _b : []) {
yield F.writeHomepageT(homepage);
}
}
}
}
/**
* 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() {
var _a, _b;
if (this.specification.kind === 'Manifest') {
for (const provider of (_a = this.specification.value.provider) !== null && _a !== void 0 ? _a : []) {
for (const seeAlso of (_b = provider.seeAlso) !== null && _b !== void 0 ? _b : []) {
yield F.writeSeeAlsoT(seeAlso);
}
}
}
}
/**
* 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() {
var _a;
if (this.specification.kind === 'Manifest') {
for (const metadata of (_a = this.specification.value.metadata) !== null && _a !== void 0 ? _a : []) {
yield F.writeMetadataT(metadata);
}
}
}
/**
* 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() {
var _a;
if (this.specification.kind === 'Manifest') {
for (const seeAlso of (_a = this.specification.value.seeAlso) !== null && _a !== void 0 ? _a : []) {
yield F.writeSeeAlsoT(seeAlso);
}
}
}
/**
* 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() {
var _a;
if (this.specification.kind === 'Manifest') {
for (const partOf of (_a = this.specification.value.partOf) !== null && _a !== void 0 ? _a : []) {
yield F.writePartOfT(partOf);
}
}
}
/**
* 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() {
var _a;
if (this.specification.kind === 'Manifest') {
for (const range of (_a = this.specification.value.structures) !== null && _a !== void 0 ? _a : []) {
yield F.writeRangeT(range);
}
}
}
/**
* 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() {
var _a, _b;
if (this.specification.kind === 'Manifest') {
for (const feature of (_b = (_a = this.specification.value.navPlace) === null || _a === void 0 ? void 0 : _a.features) !== null && _b !== void 0 ? _b : []) {
yield F.writeFeatureT(feature);
}
}
}
/**
* 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() {
var _a, _b, _c;
if (this.specification.kind === 'Manifest') {
for (const canvas of (_a = this.specification.value.items) !== null && _a !== void 0 ? _a : []) {
for (const feature of (_c = (_b = canvas.navPlace) === null || _b === void 0 ? void 0 : _b.features) !== null && _c !== void 0 ? _c : []) {
yield F.writeFeatureT(feature);
}
}
}
}
/**
* 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() {
var _a, _b;
if (this.specification.kind === 'Manifest') {
for (const range of (_a = this.specification.value.structures) !== null && _a !== void 0 ? _a : []) {
for (const item of (_b = range.items) !== null && _b !== void 0 ? _b : []) {
yield F.writeRangeItemsT(item);
}
}
}
}
/**
* 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() {
if (!this.specification || !this.specification.kind || !this.specification.value) {
return; // Handle invalid specification
}
if (this.specification.kind === "Collection") {
yield F.writeCollectionT(this.specification.value);
const traverse = function* (items) {
if (!items)
return; // Handle case where items might not exist
for (const item of items) {
if (item.kind === "Collection") {
yield F.writeCollectionT(item.value);
if (item.value.items) {
yield* traverse(item.value.items); // Recursively process nested collections
}
}
else if (item.kind === "Manifest") {
yield F.writeManifestT(item.value); // Yield manifests found in the collection
}
}
};
if (this.specification.value.items) {
yield* traverse(this.specification.value.items);
}
}
else if (this.specification.kind === "Manifest") {
// If the specification is a Manifest, yield it directly
yield F.writeManifestT(this.specification.value);
}
}
/**
* 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() {
if (this.specification.kind === 'Collection') {
yield F.writeCollectionT(this.specification.value);
const traverse = function* (items) {
if (!items)
return; // Handle case where items might not exist
for (const item of items) {
if (item.kind === 'Collection') {
yield F.writeCollectionT(item.value);
if (item.value.items) { // Check if items exist before recursion
yield* traverse(item.value.items);
}
}
}
};
if (this.specification.value.items) { // Check if items exist before starting traversal
yield* traverse(this.specification.value.items);
}
}
}
/**
* 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() {
if (this.specification.kind === 'Manifest') {
yield F.writeManifestT(this.specification.value);
}
else if (this.specification.kind === 'Collection' && this.specification.value.items) {
const traverse = function* (items) {
if (!items)
return; // Handle case where items might not exist
for (const item of items) {
if (item.kind === 'Manifest') {
yield F.writeManifestT(item.value);
}
else if (item.kind === 'Collection' && item.value.items) {
yield* traverse(item.value.items);
}
}
};
yield* traverse(this.specification.value.items);
}
}
/**
* 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() {
if (this.specification.kind === 'Collection') {
yield F.writeLabelT(this.specification.value.label);
const traverse = function* (items) {
if (!items)
return; // Handle case where items might not exist
for (const item of items) {
if (item.kind === 'Collection') {
yield F.writeLabelT(item.value.label);
if (item.value.items) { // Check if items exist before recursion
yield* traverse(item.value.items);
}
}
}
};
if (this.specification.value.items) { // Check if items exist before starting traversal
yield* traverse(this.specification.value.items);
}
}
}
/**
* 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() {
var _a;
if (this.specification.kind === 'Collection') {
for (const thumbnail of (_a = this.specification.value.thumbnail) !== null && _a !== void 0 ? _a : []) {
yield F.writeThumbnailT(thumbnail);
}
const traverse = function* (items) {
var _a;
if (!items)
return; // Handle case where items might not exist
for (const item of items) {
if (item.kind === 'Collection') {
for (const thumbnail of (_a = item.value.thumbnail) !== null && _a !== void 0 ? _a : []) {
yield F.writeThumbnailT(thumbnail);
}
if (item.value.items) { // Check if items exist before recursion
yield* traverse(item.value.items);
}
}
}
};
if (this.specification.value.items) { // Check if items exist before starting traversal
yield* traverse(this.specification.value.items);
}
}
}
/**
* 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() {
var _a;
if (this.specification.kind === 'Collection') {
for (const metadata of (_a = this.specification.value.metadata) !== null && _a !== void 0 ? _a : []) {
yield F.writeMetadataT(metadata);
}
const traverse = function* (items) {
var _a;
if (!items)
return; // Handle case where items might not exist
for (const item of items) {
if (item.kind === 'Collection') {
for (const metadata of (_a = item.value.metadata) !== null && _a !== void 0 ? _a : []) {
yield F.writeMetadataT(metadata);
}
if (item.value.items) { // Check if items exist before recursion
yield* traverse(item.value.items);
}
}
}
};
if (this.specification.value.items) { // Check if items exist before starting traversal
yield* traverse(this.specification.value.items);
}
}
}
/**
* 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() {
var _a;
if (this.specification.kind === 'Collection') {
// Yield providers from the top-level collection
for (const provider of (_a = this.specification.value.provider) !== null && _a !== void 0 ? _a : []) {
yield F.writeProviderT(provider);
}
// Define a recursive generator function to traverse nested collections
const traverse = function* (items) {
var _a;
if (!items)
return; // Handle case where items might not exist
for (const item of items) {
if (item.kind === 'Collection') {
// Yield providers from nested collections
for (const provider of (_a = item.value.provider) !== null && _a !== void 0 ? _a : []) {
yield F.writeProviderT(provider);
}
// Recursively traverse nested collections
if (item.value.items) {
yield* traverse(item.value.items);
}
}
}
};
// Start traversal if there are nested items
if (this.specification.value.items) {
yield* traverse(this.specification.value.items);
}
}
}
/**
* 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() {
var _a, _b;
if (this.specification.kind === 'Collection') {
// Yield services from the top-level collection
if (((_a = this.specification.value.service) === null || _a === void 0 ? void 0 : _a.kind) === 'T2') {
for (const serviceItem of (_b = this.specification.value.service.value) !== null && _b !== void 0 ? _b : []) {
yield F.writeServiceItemT(serviceItem);
}
}
// Define a recursive generator function to traverse nested collections
const traverse = function* (items) {
var _a, _b;
if (!items)
return; // Handle case where items might not exist
for (const item of items) {
if (item.kind === 'Collection') {
// Yield services from nested collections
if (((_a = item.value.service) === null || _a === void 0 ? void 0 : _a.kind) === 'T2') {
for (const serviceItem of (_b = item.value.service.value) !== null && _b !== void 0 ? _b : []) {
yield F.writeServiceItemT(serviceItem);
}
}
// Recursively traverse nested collections
if (item.value.items) {
yield* traverse(item.value.items);
}
}
}
};
// Start traversal if there are nested items
if (this.specification.value.items) {
yield* traverse(this.specification.value.items);
}
}
}
/**
* 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() {
var _a, _b;
if (this.specification.kind === 'Manifest') {
if (((_a = this.specification.value.service) === null || _a === void 0 ? void 0 : _a.kind) === 'T2') {
for (const serviceItem of (_b = this.specification.value.service.value) !== null && _b !== void 0 ? _b : []) {
yield F.writeServiceItemT(serviceItem);
}
}
}
}
/**
* 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() {
var _a, _b, _c;
if (this.specification.kind === 'Manifest') {
for (const thumbnail of (_a = this.specification.value.thumbnail) !== null && _a !== void 0 ? _a : []) {
if (((_b = this.specification.value.service) === null || _b === void 0 ? void 0 : _b.kind) === 'T2') {
for (const serviceItem of (_c = thumbnail.service.value) !== null && _c !== void 0 ? _c : []) {
yield F.writeServiceItemT(serviceItem);
}
}
}
}
}
/**
* 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() {
var _a, _b;
if (this.specification.kind === 'Manifest') {
if (((_a = this.specification.value.services) === null || _a === void 0 ? void 0 : _a.kind) === 'T2') {
for (const servicesItem of (_b = this.specification.value.services.value) !== null && _b !== void 0 ? _b : []) {
yield F.writeServiceItemT(servicesItem);
}
}
}
}
/**
* 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() {
var _a, _b;
if (this.specification.kind === 'Manifest') {
for (const annotationPage of (_a = this.specification.value.annotations) !== null && _a !== void 0 ? _a : []) {
for (const annotation of (_b = annotationPage.items) !== null && _b !== void 0 ? _b : []) {
yield F.writeAnnotationT(annotation);
}
}
}
}
/**
* Iterates over the textual bodies of annotations in the manifest.
*
* @returns {IterableIterator<T.AnnotationBodyT4>} An iterator over the textual bodies of annotations.
*/
*iterateManifestW3cAnnotationTextualBody() {
var _a, _b, _c, _d, _e;
if (this.specification.kind === 'Manifest') {
for (const annotationPage of (_a = this.specification.value.annotations) !== null && _a !== void 0 ? _a : []) {
for (const annotation of (_b = annotationPage.items) !== null && _b !== void 0 ? _b : []) {
if (((_c = annotation.body) === null || _c === void 0 ? void 0 : _c.kind) === 'T2') { /* if body is an array */
for (const body of annotation.body.value) {
if (body.kind === 'T4') {
yield F.writeAnnotationBodyT4(body.value);
}
}
}
else { /* must be T1 */
if (((_e = (_d = annotation.body) === null || _d === void 0 ? void 0 : _d.value) === null || _e === void 0 ? void 0 : _e.kind) === 'T4') {
yield F.writeAnnotationBodyT4(annotation.body.value.value);
}
}
}
}
}
}
/**
* 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() {
var _a;
if (this.specification.kind === 'Manifest') {
for (const annotationPage of (_a = this.specification.value.annotations) !== null && _a !== void 0 ? _a : []) {
yield F.writeAnnotationPageT(annotationPage);
}
}
}
/**
* 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() {
return this.specification.type === 'AnnotationCollection' && this.specification != undefined
? F.writeAnnotationCollectionT(this.specification)
: 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() {
return this.specification.type === 'AnnotationCollection' && this.specification.id != undefined
? F.writeIdT(this.specification.id)
: 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() {
return this.specification.type === 'AnnotationCollection' && this.specification.type != undefined
? F.writeTypeT(this.specification.type)
: 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() {
return this.specification.type === 'AnnotationCollection' && this.specification.context != undefined
? F.writeContextT(this.specification.context)
: 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() {
return this.specification.type === 'AnnotationCollection' && this.specification.label != undefined
? F.writeLabelT(this.specification.label)
: 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() {
return this.specification.type === 'AnnotationCollection' && this.specification.first != undefined
? F.writeFirstT(this.specification.first)
: 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() {
return this.specification.type === 'AnnotationCollection' && this.specification.last != undefined
? F.writeLastT(this.specification.last)
: 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() {
return this.specification.type === 'AnnotationCollection' && this.specification.total != undefined
? F.writeTotalT(this.specification.total)
: 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() {
return this.specification.type === 'AnnotationPage' && this.specification != undefined
? F.writeAnnotationPageT(this.specification)
: 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() {
return this.specification.type === 'AnnotationPage' && this.specification.type != undefined
? F.writeTypeT(this.specification.type)
: 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() {
return this.specification.type === 'AnnotationPage' && this.specification.id != undefined
? F.writeIdT(this.specification.id)
: 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() {
return this.specification.type === 'AnnotationPage' && this.specification.context != undefined
? F.writeContextT(this.specification.context)
: 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() {
return this.specification.type === 'AnnotationPage' && this.specification.partOf != undefined
? F.writePartOfT(this.specification.partOf)
: null;
}
/**
* Iterates over the annotations in the specification if the type is 'AnnotationPage'.
*
* @yields {T.AnnotationT} The annotations from the specification.
*/
*iterateAnnotationPageAnnotation() {
var _a;
if (this.specification.type === 'AnnotationPage') {
for (const annotation of (_a = this.specification.items) !== null && _a !== void 0 ? _a : []) {
yield F.writeAnnotationT(annotation);
}
}
}
/**
* Iterates over the textual bodies of annotations in the annotation page.
*
* @returns {IterableIterator<T.AnnotationBodyT4>} An iterator over the textual bodies of annotations.
*/