UNPKG

maniiifest

Version:

Typesafe IIIF presentation v3 manifest and collection parsing without external dependencies

1,199 lines 50.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Maniiifest = void 0; /** * Imports all exports from the "specification" module as F and types from "iiif-types" as U. * * The F namespace is used to access functions and constants defined in the "specification" module. * The U namespace is used to access user-facing types from the "iiif-types" module. */ const F = require("./specification"); const ManiiifestAnnotation_1 = require("./ManiiifestAnnotation"); const ManiiifestAnnotationPage_1 = require("./ManiiifestAnnotationPage"); const ManiiifestAnnotationCollection_1 = require("./ManiiifestAnnotationCollection"); /** * The `Maniiifest` class provides methods to parse and manipulate IIIF Manifest and Collection resources. * For W3C annotation types, use the dedicated parse methods: * - `Maniiifest.parseAnnotation(data)` * - `Maniiifest.parseAnnotationPage(data)` * - `Maniiifest.parseAnnotationCollection(data)` */ class Maniiifest { /** * Constructs a new instance of the Maniiifest class. * * Parses the provided data as a IIIF Manifest or Collection. * For annotation types, use the static parse methods instead. * * @param data - The data to be parsed as a Manifest or Collection. */ constructor(data) { try { this.specification = F.readSpecificationT(data); } catch (error) { throw new Error(`Failed to parse IIIF data: ${error instanceof Error ? error.message : String(error)}`); } } /** * Parses a W3C Annotation. */ static parseAnnotation(data) { return new ManiiifestAnnotation_1.ManiiifestAnnotation(data); } /** * Parses a W3C Annotation Page. */ static parseAnnotationPage(data) { return new ManiiifestAnnotationPage_1.ManiiifestAnnotationPage(data); } /** * Parses a W3C Annotation Collection. */ static parseAnnotationCollection(data) { return new ManiiifestAnnotationCollection_1.ManiiifestAnnotationCollection(data); } /** * Yields service items from an ATD service field that may be Array or single Value. */ *yieldServiceItems(service) { var _a; if ((service === null || service === void 0 ? void 0 : service.kind) === 'Array') { for (const item of (_a = service.value) !== null && _a !== void 0 ? _a : []) { yield F.writeServiceItemT(item); } } else if ((service === null || service === void 0 ? void 0 : service.kind) === 'Value') { yield F.writeServiceItemT(service.value); } } /** * Recursively traverses all Collection nodes in the tree, yielding * whatever the extract callback produces for each collection value. */ *traverseCollections(extract) { if (this.specification.kind !== 'Collection') return; yield* extract(this.specification.value); const traverse = function* (items) { if (!items) return; for (const item of items) { if (item.kind === 'Collection') { yield* extract(item.value); if (item.value.items) { yield* traverse(item.value.items); } } } }; if (this.specification.value.items) { yield* traverse(this.specification.value.items); } } /** * 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 {U.Context | 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 {U.Id | 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 {U.Label | 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 {U.LngString | null} The label for the specified language if it exists, otherwise null. */ getManifestLabelByLanguage(language) { if (this.specification.kind === 'Manifest' && this.specification.value.label !== undefined && this.specification.value.label.kind === 'Multilingual') { const labels = this.specification.value.label.value; for (const [lang, values] of labels) { if (lang === language) { return F.writeLngStringT([[lang, values]]); } } } return null; } /** * Retrieves the summary from the manifest specification if it is of kind 'Manifest'. * * @returns {U.Summary | 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 {U.ViewingDirection | 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 {U.NavDate | 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 {U.NavPlace | 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 {U.Rights | 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 {U.RequiredStatement | 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 {U.Start | 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 {U.Service | 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 {U.Manifest | 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 {U.Collection | 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 {U.Context | 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 {U.Id | 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 {U.Label | 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 {U.LngString | null} The label for the specified language if it exists, otherwise null. */ getCollectionLabelByLanguage(language) { if (this.specification.kind === 'Collection' && this.specification.value.label !== undefined && this.specification.value.label.kind === 'Multilingual') { const labels = this.specification.value.label.value; for (const [lang, values] of labels) { if (lang === language) { return F.writeLngStringT([[lang, values]]); } } } return null; } /** * Retrieves the service from the collection specification if it is of kind 'Collection'. * * @returns {U.Service | 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 {U.RequiredStatement | null} The required statement if the specification is of kind 'Collection' 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 {U.Annotation} 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. * * @yields {U.AnnotationBodyTextualBody} The next textual body from a canvas annotation. */ *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) === 'Array') { /* if body is an array */ for (const body of annotation.body.value) { if (body.kind === 'TextualBody') { yield F.writeAnnotationBodyTextualBody(body.value); } } } else { /* single value */ if (((_f = (_e = annotation.body) === null || _e === void 0 ? void 0 : _e.value) === null || _f === void 0 ? void 0 : _f.kind) === 'TextualBody') { yield F.writeAnnotationBodyTextualBody(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 {U.AnnotationPage} 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 {U.AnnotationPage} 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 {U.Annotation} 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 {U.Canvas} 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 {U.Thumbnail} 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 {U.Homepage} 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 {U.Behavior} 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 {U.Provider} 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 {U.Rendering} 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 {U.Homepage} 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 {U.SeeAlso} 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 {U.Metadata} 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 {U.SeeAlso} 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 {U.PartOf} 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 {U.Range} 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 {U.Feature} 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 {U.Feature} 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 {U.RangeItems} 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 {U.Collection | U.Manifest} 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 {U.Collection} The next collection item in the specification. */ *iterateCollectionCollection() { yield* this.traverseCollections(function* (col) { yield F.writeCollectionT(col); }); } /** * Iterates over the manifests in the collection. * * This generator function yields manifests from the collection's manifest and recursively from nested collections. * * @yields {U.Manifest} 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 {U.Label} The next label item in the collection. */ *iterateCollectionLabel() { yield* this.traverseCollections(function* (col) { yield F.writeLabelT(col.label); }); } /** * Iterates over the thumbnails in the collection. * * This generator function yields thumbnails from the collection's thumbnail and recursively from nested collections. * * @yields {U.Thumbnail} The next thumbnail item in the collection. */ *iterateCollectionThumbnail() { yield* this.traverseCollections(function* (col) { var _a; for (const thumbnail of (_a = col.thumbnail) !== null && _a !== void 0 ? _a : []) { yield F.writeThumbnailT(thumbnail); } }); } /** * Iterates over the metadata in the collection. * * This generator function yields metadata from the collection's metadata and recursively from nested collections. * * @yields {U.Metadata} The next metadata item in the collection. */ *iterateCollectionMetadata() { yield* this.traverseCollections(function* (col) { var _a; for (const metadata of (_a = col.metadata) !== null && _a !== void 0 ? _a : []) { yield F.writeMetadataT(metadata); } }); } /** * Iterates over the providers in the collection. * * This generator function yields providers from the collection's provider property and recursively from nested collections. * * @yields {U.Provider} The next provider item in the collection. */ *iterateCollectionProvider() { yield* this.traverseCollections(function* (col) { var _a; for (const provider of (_a = col.provider) !== null && _a !== void 0 ? _a : []) { yield F.writeProviderT(provider); } }); } /** * Iterates over the homepages in the collection. * * This generator function yields homepages from the collection's homepage property and recursively from nested collections. * * @yields {U.Homepage} The next homepage item in the collection. */ *iterateCollectionHomepage() { yield* this.traverseCollections(function* (col) { var _a; for (const homepage of (_a = col.homepage) !== null && _a !== void 0 ? _a : []) { yield F.writeHomepageT(homepage); } }); } /** * Iterates over the services in the collection. * * This generator function yields services from the collection's service property and recursively from nested collections. * * @yields {U.ServiceItem} The next service item in the collection. */ *iterateCollectionService() { const self = this; yield* this.traverseCollections(function* (col) { yield* self.yieldServiceItems(col.service); }); } /** * Iterates over the services in the manifest. * * This generator function yields services from the service pages within the manifest. * * @yields {U.Service} The next service in the manifest. */ *iterateManifestService() { if (this.specification.kind === 'Manifest') { yield* this.yieldServiceItems(this.specification.value.service); } } /** * 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 {U.Service} The next service within the thumbnail services in the manifest. */ *iterateManifestThumbnailService() { var _a; if (this.specification.kind === 'Manifest') { for (const thumbnail of (_a = this.specification.value.thumbnail) !== null && _a !== void 0 ? _a : []) { yield* this.yieldServiceItems(thumbnail.service); } } } /** * Iterates over the services in the manifest. * * This generator function yields services from the manifest's service pages. * * @yields {U.Service} The next service in the manifest. */ *iterateManifestServices() { if (this.specification.kind === 'Manifest') { yield* this.yieldServiceItems(this.specification.value.services); } } /** * Iterates over the W3C annotations in the manifest. * * This generator function yields annotations from the manifest's annotation pages. * * @yields {U.Annotation} 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. * * @yields {U.AnnotationBodyTextualBody} The next textual body from a manifest annotation. */ *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) === 'Array') { /* if body is an array */ for (const body of annotation.body.value) { if (body.kind === 'TextualBody') { yield F.writeAnnotationBodyTextualBody(body.value); } } } else { /* single value */ if (((_e = (_d = annotation.body) === null || _d === void 0 ? void 0 : _d.value) === null || _e === void 0 ? void 0 : _e.kind) === 'TextualBody') { yield F.writeAnnotationBodyTextualBody(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<U.AnnotationPage>} An iterator that yields annotation pages as `U.AnnotationPage` 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); } } } // ────────────────────────────────────────── // Canvas accessors (within Manifest context) // ────────────────────────────────────────── /** * Iterates over the labels of canvases in the manifest. * * @yields {U.Label} The next canvas label in the manifest. */ *iterateManifestCanvasLabel() { var _a; if (this.specification.kind === 'Manifest') { for (const canvas of (_a = this.specification.value.items) !== null && _a !== void 0 ? _a : []) { if (canvas.label !== undefined) { yield F.writeLabelT(canvas.label); } } } } /** * Iterates over the metadata elements of canvases in the manifest. * * @yields {U.Metadata} The next canvas metadata element in the manifest. */ *iterateManifestCanvasMetadata() { var _a, _b; if (this.specification.kind === 'Manifest') { for (const canvas of (_a = this.specification.value.items) !== null && _a !== void 0 ? _a : []) { for (const metadata of (_b = canvas.metadata) !== null && _b !== void 0 ? _b : []) { yield F.writeMetadataT(metadata); } } } } /** * Iterates over the thumbnail elements of canvases in the manifest. * * @yields {U.Thumbnail} The next canvas thumbnail element in the manifest. */ *iterateManifestCanvasThumbnail() { var _a, _b; if (this.specification.kind === 'Manifest') { for (const canvas of (_a = this.specification.value.items) !== null && _a !== void 0 ? _a : []) { for (const thumbnail of (_b = canvas.thumbnail) !== null && _b !== void 0 ? _b : []) { yield F.writeThumbnailT(thumbnail); } } } } /** * Iterates over the rendering elements of canvases in the manifest. * * @yields {U.Rendering} The next canvas rendering element in the manifest. */ *iterateManifestCanvasRendering() { var _a, _b; if (this.specification.kind === 'Manifest') { for (const canvas of (_a = this.specification.value.items) !== null && _a !== void 0 ? _a : []) { for (const rendering of (_b = canvas.rendering) !== null && _b !== void 0 ? _b : []) { yield F.writeRenderingT(rendering); } } } } /** * Iterates over the seeAlso elements of canvases in the manifest. * * @yields {U.SeeAlso} The next canvas seeAlso element in the manifest. */ *iterateManifestCanvasSeeAlso() { var _a, _b; if (this.specification.kind === 'Manifest') { for (const canvas of (_a = this.specification.value.items) !== null && _a !== void 0 ? _a : []) { for (const seeAlso of (_b = canvas.seeAlso) !== null && _b !== void 0 ? _b : []) { yield F.writeSeeAlsoT(seeAlso); } } } } /** * Iterates over the homepage elements of canvases in the manifest. * * @yields {U.Homepage} The next canvas homepage element in the manifest. */ *iterateManifestCanvasHomepage() { var _a, _b; if (this.specification.kind === 'Manifest') { for (const canvas of (_a = this.specification.value.items) !== null && _a !== void 0 ? _a : []) { for (const homepage of (_b = canvas.homepage) !== null && _b !== void 0 ? _b : []) { yield F.writeHomepageT(homepage); } } } } /** * Iterates over the provider elements of canvases in the manifest. * * @yields {U.Provider} The next canvas provider element in the manifest. */ *iterateManifestCanvasProvider() { var _a, _b; if (this.specification.kind === 'Manifest') { for (const canvas of (_a = this.specification.value.items) !== null && _a !== void 0 ? _a : []) { for (const provider of (_b = canvas.provider) !== null && _b !== void 0 ? _b : []) { yield F.writeProviderT(provider); } } } } /** * Iterates over the service elements of canvases in the manifest. * * @yields {U.ServiceItem} The next canvas service item in the manifest. */ *iterateManifestCanvasService() { var _a; if (this.specification.kind === 'Manifest') { for (const canvas of (_a = this.specification.value.items) !== null && _a !== void 0 ? _a : []) { yield* this.yieldServiceItems(canvas.service); } } } /** * Iterates over the behavior elements of canvases in the manifest. * * @yields {U.Behavior} The next canvas behavior element in the manifest. */ *iterateManifestCanvasBehavior() { var _a, _b; if (this.specification.kind === 'Manifest') { for (const canvas of (_a = this.specification.value.items) !== null && _a !== void 0 ? _a : []) { for (const behavior of (_b = canvas.behavior) !== null && _b !== void 0 ? _b : []) { yield F.writeBehaviorT(behavior); } } } } // ────────────────────────────────────────── // Range accessors (within Manifest context) // ────────────────────────────────────────── /** * Iterates over the labels of ranges in the manifest. * * @yields {U.Label} The next range label in the manifest. */ *iterateManifestRangeLabel() { var _a; if (this.specification.kind === 'Manifest') { for (const range of (_a = this.specification.value.structures) !== null && _a !== void 0 ? _a : []) { if (range.label !== undefined) { yield F.writeLabelT(range.label); } } } } /** * Iterates over the rendering elements of ranges in the manifest. * * @yields {U.Rendering} The next range rendering element in the manifest. */ *iterateManifestRangeRendering() { var _a, _b; if (this.specification.kind === 'Manifest') { for (const range of (_a = this.specification.value.structures) !== null && _a !== void 0 ? _a : []) { for (const rendering of (_b = range.rendering) !== null && _b !== void 0 ? _b : []) { yield F.writeRenderingT(rendering); } } } } /** * Iterates over the thumbnail elements of ranges in the manifest. * * @yields {U.Thumbnail} The next range thumbnail element in the manifest. */ *iterateManifestRangeThumbnail() { var _a, _b; if (this.specification.kind === 'Manifest') { for (const range of (_a = this.specification.value.structures) !== null && _a !== void 0 ? _a : []) { for (const thumbnail of (_b = range.thumbnail) !== null && _b !== void 0 ? _b : []) { yield F.writeThumbnailT(thumbnail); } } } } /** * Iterates over the annotations in ranges of the manifest. * * @yields {U.Annotation} The next annotation in the ranges of the manifest. */ *iterateManifestRangeAnnotation() { var _a, _b, _c; if (this.specification.kind === 'Manifest') { for (const range of (_a = this.specification.value.structures) !== null && _a !== void 0 ? _a : []) { for (const annotationPage of (_b = range.annotations) !== null && _b !== void 0 ? _b : []) { for (const annotation of (_c = annotationPage.items) !== null && _c !== void 0 ? _c : []) { yield F.writeAnnotationT(annotation); } } } } } // ────────────────────────────────────────── // Collection getters & iterators // ────────────────────────────────────────── /** * Retrieves the summary from the collection specification if it is of kind 'Collection'. * * @returns {U.Summary | null} The summary if the specification is of kind 'Collection', otherwise null. */ getCollectionSummary() { var _a; return this.specification.kind === 'Collection' && ((_a = this.specification.value) === null || _a === void 0 ? void 0 : _a.summary) !== undefined ? F.writeSummaryT(this.specification.value.summary) : null; } /** * Retrieves the rights statement from the collection specification if it is of kind 'Collection'. * * @returns {U.Rights | null} The rights statement if the specification is of kind 'Collection', otherwise null. */ getCollectionRights() { return this.specification.kind === 'Collection' && this.specification.value.rights !== undefined ? F.writeRightsT(this.specification.value.rights) : null; } /** * Retrieves the navigation date from the collection specification if it is of kind 'Collection'. * * @returns {U.NavDate | null} The navigation date if the specification is of kind 'Collection', otherwise null. */ getCollectionNavDate() { return this.specification.kind === 'Collection' && this.specification.value.navDate !== undefined ? F.writeNavDateT(this.specification.value.navDate) : null; } /** * Retrieves the navigation place from the collection specification if it is of kind 'Collection'. * * @returns {U.NavPlace | null} The navigation place if the specification is of kind 'Collection', otherwise null. */ getCollectionNavPlace() { return this.specification.kind === 'Collection' && this.specification.value.navPlace !== undefined ? F.writeNavPlaceT(this.specification.value.navPlace) : null; } /** * Iterates over the rendering elements in the collection and nested collections. * * @yields {U.Rendering} The next rendering element in the collection. */ *iterateCollectionRendering() { yield* this.traverseCollections(function* (col) { var _a; for (const rendering of (_a = col.rendering) !== null && _a !== void 0 ? _a : []) { yield F.writeRenderingT(rendering); } }); } /** * Iterates over the seeAlso elements in the collection and nested collections. * * @yields {U.SeeAlso} The next seeAlso element in the collection. */ *iterateCollectionSeeAlso() { yield* this.traverseCollections(function* (col) { var _a; for (const seeAlso of (_a = col.seeAlso) !== null && _a !== void 0 ? _a : []) { yield F.writeSeeAlsoT(seeAlso); } }); } /** * Iterates over the behavior elements in the collection and nested collections. * * @yields {U.Behavior} The next behavior element in the collection. */ *iterateCollectionBehavior() { yield* this.traverseCollections(function* (col) { var _a; for (const behavior of (_a = col.behavior) !== null && _a !== void 0 ? _a : []) { yield F.writeBehaviorT(behavior); } }); } /** * Iterates over the partOf elements in the collection and nested collections. * * @yields {U.PartOf} The next partOf element in the collection. */ *it