UNPKG

maniiifest

Version:

Typesafe IIIF presentation v3 manifest and collection parsing without external dependencies

94 lines (93 loc) 4.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ManiiifestAnnotationPage = void 0; const F = require("./specification"); /** * Parses and provides access to a standalone W3C Annotation Page. * * Create via `Maniiifest.parseAnnotationPage(data)` or `new ManiiifestAnnotationPage(data)`. */ class ManiiifestAnnotationPage { constructor(data) { try { this.specification = F.readAnnotationPageT(data); } catch (error) { throw new Error(`Failed to parse IIIF data as AnnotationPage: ${error instanceof Error ? error.message : String(error)}`); } } getAnnotationPage() { return F.writeAnnotationPageT(this.specification); } getAnnotationPageId() { return this.specification.id !== undefined ? F.writeIdT(this.specification.id) : null; } getAnnotationPageType() { return F.writeTypeT(this.specification.type); } getAnnotationPageContext() { return this.specification.context !== undefined ? F.writeContextT(this.specification.context) : null; } getAnnotationPagePartOf() { return this.specification.partOf !== undefined ? F.writePartOfT(this.specification.partOf) : null; } getAnnotationPageLabel() { return this.specification.label !== undefined ? F.writeLabelT(this.specification.label) : null; } getAnnotationPageNext() { return this.specification.next !== undefined ? F.writeNextT(this.specification.next) : null; } getAnnotationPageStartIndex() { return this.specification.startIndex !== undefined ? F.writeStartIndexT(this.specification.startIndex) : null; } /** @yields {U.Annotation} Each annotation in the page. */ *iterateAnnotationPageAnnotation() { var _a; for (const annotation of (_a = this.specification.items) !== null && _a !== void 0 ? _a : []) { yield F.writeAnnotationT(annotation); } } /** @yields {U.AnnotationBodyTextualBody} Each textual body from annotations in the page. */ *iterateAnnotationPageAnnotationTextualBody() { var _a, _b, _c, _d; for (const annotation of (_a = this.specification.items) !== null && _a !== void 0 ? _a : []) { if (((_b = annotation.body) === null || _b === void 0 ? void 0 : _b.kind) === 'Array') { for (const body of annotation.body.value) { if (body.kind === 'TextualBody') { yield F.writeAnnotationBodyTextualBody(body.value); } } } else { if (((_d = (_c = annotation.body) === null || _c === void 0 ? void 0 : _c.value) === null || _d === void 0 ? void 0 : _d.kind) === 'TextualBody') { yield F.writeAnnotationBodyTextualBody(annotation.body.value.value); } } } } /** @yields {U.AnnotationTargetCanvasRef} Each canvas reference target from annotations in the page. */ *iterateAnnotationPageAnnotationCanvasRef() { var _a, _b, _c, _d; for (const annotation of (_a = this.specification.items) !== null && _a !== void 0 ? _a : []) { if (((_b = annotation.target) === null || _b === void 0 ? void 0 : _b.kind) === 'Array') { for (const target of annotation.target.value) { if (target.kind === 'CanvasRef') { yield F.writeAnnotationTargetCanvasRef(target.value); } } } else { if (((_d = (_c = annotation.target) === null || _c === void 0 ? void 0 : _c.value) === null || _d === void 0 ? void 0 : _d.kind) === 'CanvasRef') { yield F.writeAnnotationTargetCanvasRef(annotation.target.value.value); } } } } } exports.ManiiifestAnnotationPage = ManiiifestAnnotationPage;