From 80364f359b295df729cd29063c56934fd42898dd Mon Sep 17 00:00:00 2001 From: "imranasghar96@hotmail.com" Date: Tue, 8 Dec 2020 14:38:10 -0500 Subject: [PATCH] Update getSequences to also return ranges .. .. Seq behavior --- src/Manifest.ts | 19 +++++++++++--- test/fixtures/pres3.json | 55 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 5 deletions(-) diff --git a/src/Manifest.ts b/src/Manifest.ts index 024a2e6c..006e6e7c 100644 --- a/src/Manifest.ts +++ b/src/Manifest.ts @@ -20,7 +20,7 @@ import { export class Manifest extends IIIFResource { public index: number = 0; private _allRanges: Range[] | null = null; - public items: Sequence[] = []; + public items: (Sequence | Range)[] = []; private _topRanges: Range[] = []; constructor(jsonld?: any, options?: IManifestoOptions) { @@ -238,8 +238,15 @@ export class Manifest extends IIIFResource { return null; } - getSequences(): Sequence[] { - if (this.items.length) { + getSequences(): (Sequence | Range)[] { + let v3SeqRanges: Range[] = []; + if (this.getTopRanges().length > 0) { + v3SeqRanges = this.getTopRanges().filter( + r => r.getBehavior() == "sequence" + ); + } + + if (v3SeqRanges.length === 0 && this.items.length) { return this.items; } @@ -258,10 +265,14 @@ export class Manifest extends IIIFResource { this.items.push(sequence); } + if (v3SeqRanges.length > 0) { + this.items.concat(v3SeqRanges); + } + return this.items; } - getSequenceByIndex(sequenceIndex: number): Sequence { + getSequenceByIndex(sequenceIndex: number): Sequence | Range { return this.getSequences()[sequenceIndex]; } diff --git a/test/fixtures/pres3.json b/test/fixtures/pres3.json index bcbdeb5c..4a273b4f 100644 --- a/test/fixtures/pres3.json +++ b/test/fixtures/pres3.json @@ -142,6 +142,59 @@ ] } ] + }, + { + "id": "http://example.org/iiif/book1/canvas/1", + "type": "Canvas", + "label": { + "@none": [ + "p. 1" + ] + }, + "height": 1000, + "width": 750, + "duration": 180.0, + "items": [ + { + "id": "http://example.org/iiif/book1/canvas/1/annotationpage/0", + "type": "AnnotationPage", + "items": [ + { + "id": "http://example.org/iiif/book1/canvas/1/annotation/0", + "type": "Annotation", + "motivation": "painting", + "body": { + "id": "http://example.org/iiif/book1/canvas/1/images/page1.jpg", + "type": "Image", + "format": "image/jpeg", + "label": { + "@none": [ + "Page 1" + ] + } + }, + "target": "http://example.org/iiif/book1/canvas/1" + } + ] + } + ] } + ], + "structures": [ + { + "id": "http://foo.test/1/range/root", + "type": "Range", + "behavior": "sequence", + "items": [ + { + "type": "SpecificResource", + "source": "http://example.org/iiif/book1/canvas/0", + "selector": { + "type": "FragmentSelector", + "value": "xywh=0,0,750,300" + } + } + ] + } ] -} \ No newline at end of file +}