Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@iiif/parser

Package Overview
Dependencies
Maintainers
4
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iiif/parser - npm Package Compare versions

Comparing version
1.0.5
to
1.0.6
+1
-1
dist/cjs/index.js

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const Ce={id:"https://iiif-parser/annotation",type:"Annotation",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[],accessibility:[],audience:[],body:[],bodyValue:null,canonical:null,created:null,creator:[],generated:null,generator:[],modified:null,motivation:[],rights:[],stylesheet:null,target:[],timeMode:void 0,via:[],partOf:[]},k={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:[],motivation:null,label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[]},N={id:"https://iiif-parser/empty-canvas",type:"Canvas",label:null,behavior:[],motivation:null,thumbnail:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:[],rights:null,navDate:null,provider:[],items:[],annotations:[],seeAlso:[],homepage:[],logo:[],partOf:[],rendering:[],service:[],duration:0,height:0,width:0},j={id:"https://iiif-parser/empty-collection",type:"Collection",label:null,viewingDirection:"left-to-right",behavior:[],motivation:null,thumbnail:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:[],rights:null,navDate:null,provider:[],items:[],annotations:[],seeAlso:[],homepage:[],logo:[],partOf:[],rendering:[],service:[],services:[]},G={id:"https://iiif-parser/empty-manifest",type:"Manifest",annotations:[],behavior:[],homepage:[],items:[],label:null,logo:[],metadata:[],motivation:null,navDate:null,provider:[],partOf:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,rendering:[],requiredStatement:null,rights:null,seeAlso:[],service:[],services:[],start:null,structures:[],summary:null,thumbnail:[],viewingDirection:"left-to-right"},$={id:"https://iiif-parser/empty-canvas",type:"Range",label:null,behavior:[],motivation:null,thumbnail:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:[],rights:null,navDate:null,provider:[],items:[],annotations:[],seeAlso:[],homepage:[],logo:[],partOf:[],rendering:[],service:[],start:null,supplementary:null,viewingDirection:"left-to-right"},q={id:"https://iiif-parser/empty-agent",type:"Agent",label:{},logo:[],seeAlso:[],homepage:[]},M=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function U(t){if(typeof t=="undefined"||t===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(t))throw new Error("Array is not a valid entity");if(typeof t!="object")throw new Error(`${typeof t} is not a valid entity`);if(typeof t.type=="string"){const e=M.indexOf(t.type);if(e!==-1)return M[e]}if(t.profile)return"Service";throw new Error("Resource type is not known")}class L{traversals;options;constructor(e,i={}){this.traversals={collection:[],manifest:[],canvas:[],annotationCollection:[],annotationPage:[],annotation:[],contentResource:[],choice:[],range:[],service:[],agent:[],...e},this.options={allowUndefinedReturn:!1,...i}}static all(e){return new L({collection:[e],manifest:[e],canvas:[e],annotationCollection:[e],annotationPage:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e]})}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=e.thumbnail.map(i=>this.traverseType(i,this.traversals.contentResource))),e.provider&&(e.provider=e.provider.map(i=>this.traverseAgent(i))),e}traverseLinking(e){return e.seeAlso&&(e.seeAlso=e.seeAlso.map(i=>this.traverseType(i,this.traversals.contentResource))),e.service&&(e.service=e.service.map(i=>this.traverseType(i,this.traversals.service))),e.services&&(e.services=e.services.map(i=>this.traverseType(i,this.traversals.service))),e.logo&&(e.logo=e.logo.map(i=>this.traverseType(i,this.traversals.contentResource))),e.homepage&&(e.homepage=e.homepage.map(i=>this.traverseType(i,this.traversals.contentResource))),e.partOf&&(e.partOf=e.partOf.map(i=>typeof i=="string"||!i.type?this.traverseType(i,this.traversals.contentResource):i.type==="Canvas"?this.traverseType(i,this.traversals.canvas):i.type==="AnnotationCollection"?this.traverseType(i,this.traversals.annotationCollection):this.traverseType(i,this.traversals.contentResource))),e.start&&(e.start=e.start?this.traverseType(e.start,this.traversals.canvas):null),e.rendering&&(e.rendering=e.rendering.map(i=>this.traverseType(i,this.traversals.contentResource))),e.supplementary&&(e.supplementary=e.supplementary.map(i=>this.traverseType(i,this.traversals.contentResource))),e}traverseCollectionItems(e){return e.items&&e.items.map(i=>i.type==="Collection"?this.traverseCollection(i):this.traverseManifest(i)),e}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traversePosterCanvas(this.traverseCollectionItems(e))))),this.traversals.collection)}traverseManifestItems(e){return e.items&&(e.items=e.items.map(i=>this.traverseCanvas(i))),e}traverseManifestStructures(e){return e.structures&&(e.structures=e.structures.map(i=>this.traverseRange(i))),e}traverseManifest(e){return this.traverseType(this.traverseInlineAnnotationPages(this.traverseManifestStructures(this.traversePosterCanvas(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e)))))),this.traversals.manifest)}traverseCanvasItems(e){return e.items=(e.items||[]).map(i=>this.traverseAnnotationPage(i)),e}traverseInlineAnnotationPages(e){return typeof e=="string"||!e||e.annotations&&(e.annotations=e.annotations.map(i=>this.traverseAnnotationPage(i))),e}traverseCanvas(e){return this.traverseType(this.traverseInlineAnnotationPages(this.traversePosterCanvas(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))))),this.traversals.canvas)}traverseAnnotationPageItems(e){return e.items&&(e.items=e.items.map(i=>this.traverseAnnotation(i))),e}traverseAnnotationPage(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationPageItems(e))),this.traversals.annotationPage)}traverseAnnotationBody(e){return Array.isArray(e.body)?e.body=e.body.map(i=>this.traverseContentResource(i)):e.body&&(e.body=this.traverseContentResource(e.body)),e}traversePosterCanvas(e){return e.posterCanvas&&(e.posterCanvas=this.traverseType(e.posterCanvas,this.traversals.canvas)),e.placeholderCanvas&&(e.placeholderCanvas=this.traverseType(e.placeholderCanvas,this.traversals.canvas)),e.accompanyingCanvas&&(e.accompanyingCanvas=this.traverseType(e.accompanyingCanvas,this.traversals.canvas)),e}traverseAnnotation(e){return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(e)),this.traversals.annotation)}traverseContentResourceLinking(e){return typeof e=="string"||!e||e&&e.service&&(e.service=(e.service||[]).map(i=>this.traverseType(i,this.traversals.service))),e}traverseContentResource(e){return e.type==="Choice"&&(e.items=e.items.map(i=>this.traverseContentResource(i))),this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)),this.traversals.contentResource)}traverseRangeRanges(e){return e.items&&(e.items=e.items.map(i=>typeof i=="string"?this.traverseCanvas({id:i,type:"Canvas"}):i.type==="Manifest"?this.traverseManifest(i):this.traverseRange(i))),e}traverseRange(e){return this.traverseType(this.traversePosterCanvas(this.traverseDescriptive(this.traverseLinking(this.traverseRangeRanges(e)))),this.traversals.range)}traverseAgent(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.agent)}traverseType(e,i){return i.reduce((n,a)=>{const r=a(n);return typeof r=="undefined"&&!this.options.allowUndefinedReturn?n:r},e)}traverseService(e){return this.traverseType(e,this.traversals.service)}traverseUnknown(e){const i=U(e);switch(i){case"Collection":return this.traverseCollection(e);case"Manifest":return this.traverseManifest(e);case"Canvas":return this.traverseCanvas(e);case"AnnotationPage":return this.traverseAnnotationPage(e);case"Annotation":return this.traverseAnnotation(e);case"ContentResource":return this.traverseContentResource(e);case"Range":return this.traverseRange(e);case"Service":return this.traverseService(e);case"Agent":return this.traverseAgent(e);default:throw new Error(`Unknown or unsupported resource type of ${i}`)}}}const V=["sc:Collection","sc:Manifest","sc:Canvas","oa:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function Ie(t){if(typeof t=="undefined"||t===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(t))throw new Error("Array is not a valid entity");if(typeof t!="object")throw new Error(`${typeof t} is not a valid entity`);if(typeof t["@type"]=="string"){const e=V.indexOf(t["@type"]);if(e!==-1)return V[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}class S{traversals;options;constructor(e,i={}){this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...i}}static all(e){return new S({collection:[e],manifest:[e],canvas:[e],annotationList:[e],sequence:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],layer:[e]})}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))),this.traversals.collection)}traverseCollectionItems(e){if(this.options.mergeMemberProperties){const i=[...(e.manifests||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n),...(e.collections||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n),...e.members||[]];delete e.collections,delete e.manifests,e.members=i}return e.manifests&&(e.manifests=e.manifests.map(i=>this.traverseManifest(typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i))),e.collections&&(e.collections=e.collections.map(i=>this.traverseCollection(typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i))),e.members&&(e.members=e.members.map(i=>typeof i=="string"?i:this.traverseUnknown(i))),e}traverseManifest(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))),this.traversals.manifest)}traverseManifestItems(e){return e.sequences&&(e.sequences=e.sequences.map(i=>this.traverseSequence(i))),e.structures&&(e.structures=e.structures.map(i=>this.traverseRange(i))),e}traverseSequence(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))),this.traversals.sequence)}traverseSequenceItems(e){return e.canvases&&(e.canvases=e.canvases.map(i=>this.traverseCanvas(i))),e}traverseCanvas(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))),this.traversals.canvas)}traverseCanvasItems(e){return e.images&&(e.images=e.images.map(i=>this.traverseAnnotation(i))),e.otherContent&&(e.otherContent=e.otherContent.map(i=>this.traverseAnnotationList(i))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const i=[...(e.ranges||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Range"}:n),...(e.canvases||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Canvas"}:n),...e.members||[]];delete e.ranges,delete e.canvases,e.members=i.length?i.map(n=>this.traverseUnknown(n)):void 0}return e}traverseAnnotationList(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationListItems(e))),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map(i=>this.traverseAnnotation(i))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(e.resource=this.traverseContentResource(e.resource)),e.on,e}traverseLayer(e){return this.traverseType(this.traverseLinking(this.traverseLayerItems(e)),this.traversals.layer)}traverseLayerItems(e){return e.otherContent&&(e.otherContent=e.otherContent.map(i=>this.traverseAnnotationList(i))),e}traverseChoice(e){return this.traverseType(this.traverseChoiceItems(e),this.traversals.choice)}traverseChoiceItems(e){return e.default&&e.default!=="rdf:nil"&&(e.default=this.traverseContentResource(e.default)),e.item&&e.item!=="rdf:nil"&&(e.item=e.item.map(i=>this.traverseContentResource(i))),e}traverseService(e){return this.traverseType(this.traverseLinking(e),this.traversals.service)}traverseContentResource(e){return e["@type"]==="oa:Choice"?this.traverseChoice(e):this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.contentResource)}traverseUnknown(e){if(!e["@type"]||typeof e=="string")return e;switch(Ie(e)){case"sc:Collection":return this.traverseCollection(e);case"sc:Manifest":return this.traverseManifest(e);case"sc:Canvas":return this.traverseCanvas(e);case"sc:Sequence":return this.traverseSequence(e);case"sc:Range":return this.traverseRange(e);case"oa:Annotation":return this.traverseAnnotation(e);case"oa:AnnotationList":return this.traverseAnnotationList(e);case"sc:Layer":return this.traverseLayer(e);case"Service":return this.traverseService(e);case"oa:Choice":return this.traverseChoice(e);case"ContentResource":return this.traverseContentResource(e)}return e.profile?this.traverseService(e):e}traverseImageResource(e){const i=Array.isArray(e),n=Array.isArray(e)?e:[e],a=[];for(const r of n)typeof r=="string"?a.push(this.traverseContentResource({"@id":r,"@type":"dctypes:Image"})):a.push(this.traverseContentResource(r));return!i&&!this.options.convertPropsToArray?a[0]:a}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){const i=Array.isArray(e),n=Array.isArray(e)?e:[e],a=[];for(const r of n)a.push(this.traverseService(r));return!i&&!this.options.convertPropsToArray?a[0]:a}traverseLinking(e){return e.related&&(e.related=this.traverseOneOrManyType(e.related,this.traversals.contentResource)),e.rendering&&(e.rendering=this.traverseOneOrManyType(e.rendering,this.traversals.contentResource)),e.service&&(e.service=this.traverseOneOrMoreServices(e.service)),e.seeAlso&&(e.seeAlso=this.traverseOneOrManyType(e.seeAlso,this.traversals.contentResource)),e.within&&(typeof e.within=="string"||(e.within=this.traverseOneOrManyType(e.within,this.traversals.contentResource))),e.startCanvas&&(typeof e.startCanvas=="string"?e.startCanvas=this.traverseType({"@id":e.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):e.startCanvas&&this.traverseType(e.startCanvas,this.traversals.canvas)),e.contentLayer&&(typeof e.contentLayer=="string"?e.contentLayer=this.traverseLayer({"@id":e.contentLayer,"@type":"sc:Layer"}):e.contentLayer=this.traverseLayer(e.contentLayer)),e}traverseOneOrManyType(e,i){if(!Array.isArray(e))if(this.options.convertPropsToArray)e=[e];else return this.traverseType(e,i);return e.map(n=>this.traverseType(n,i))}traverseType(e,i){return i.reduce((n,a)=>{const r=a(n);return typeof r=="undefined"&&!this.options.allowUndefinedReturn?n:r},e)}}const _e="http://library.stanford.edu/iiif/image-api/compliance.html#level0",W="http://library.stanford.edu/iiif/image-api/compliance.html#level1",z="http://library.stanford.edu/iiif/image-api/compliance.html#level2",be="http://library.stanford.edu/iiif/image-api/conformance.html#level0",H="http://library.stanford.edu/iiif/image-api/conformance.html#level1",B="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Re="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",K="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Q="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Ee="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",X="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Y="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",we="http://iiif.io/api/image/1/level0.json",Le="http://iiif.io/api/image/1/profiles/level0.json",Z="http://iiif.io/api/image/1/level1.json",J="http://iiif.io/api/image/1/profiles/level1.json",ee="http://iiif.io/api/image/1/level2.json",te="http://iiif.io/api/image/1/profiles/level2.json",Te="http://iiif.io/api/image/2/level0.json",Me="http://iiif.io/api/image/2/profiles/level0.json",ie="http://iiif.io/api/image/2/level1.json",ne="http://iiif.io/api/image/2/profiles/level1.json",re="http://iiif.io/api/image/2/level2.json",ae="http://iiif.io/api/image/2/profiles/level2.json",Se="level0",se="level1",oe="level2",xe="http://iiif.io/api/image/2/level0",le="http://iiif.io/api/image/2/level1",ve="http://iiif.io/api/image/2/level2",Pe=[le,ve,W,z,H,B,K,Q,X,Y,Z,J,ee,te,ie,ne,re,ae,se,oe],Oe=[xe,le,ve,_e,W,z,be,H,B,Re,K,Q,Ee,X,Y,we,Le,Z,J,ee,te,Te,Me,ie,ne,re,ae,Se,se,oe],x={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function u(t,e="none"){if(!t)return{};const i=Array.isArray(t)?t:[t],n={};for(const a of i){if(typeof a=="string"){n[e]=n[e]?n[e]:[],n[e].push(a||"");continue}if(!a["@language"]){n[e]=n[e]?n[e]:[],n[e].push(a["@value"]||"");continue}const r=a["@language"];n[r]=n[r]?n[r]:[],n[r].push(a["@value"]||"")}return n}function pe(t){if(Array.isArray(t))return pe(t.find(e=>typeof e=="string"));if(Oe.indexOf(t)!==-1)return"level2";if(Pe.indexOf(t)!==-1)return"level1";if(typeof t=="string")return t}function Fe(t){const e=Array.isArray(t)?t:[t];for(const i of e)switch(i){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function De(t){switch(t){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}function ke(t){return Array.isArray(t)?t:[t]}function Ne(t){for(const e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}function P(t){const e=t["@id"]||t.id;let i=t["@type"]||t.type;const n=t.profile||void 0,a=t["@context"]||void 0;if(n){const r=De(n);if(r)return r}if(a){const r=Fe(a);if(r)return r}if(i){if(Array.isArray(i)){if(i.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(i.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";i=i[0]}for(const r of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${r}:`)){i=i.slice(r.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(t.format){if(t.format.startsWith("image/"))return"Image";if(t.format.startsWith("text/")||t.format==="application/pdf")return"Text";if(t.format.startsWith("application/"))return"Dataset"}return e&&(e.endsWith(".jpg")||e.endsWith(".png")||e.endsWith(".jpeg"))?"Image":i||"unknown"}const je=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Ge(t){const e=t.match(je);return e?e[0]:t}function $e(t,e="Rights/License",i="none"){let n=null;const a=[],r=Array.isArray(t)?t:[t];for(const I of r){const o=I?Ge(I):void 0;if(o&&(o.indexOf("creativecommons.org")!==-1||o.indexOf("rightsstatements.org")!==-1)){o.startsWith("https://")?n=`http://${o.slice(8)}`:n=o;continue}o&&a.push({label:{[i]:[e]},value:{[i]:[o]}})}return[n,a]}const qe=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function Ue(t){if(t){const e=Array.isArray(t)?t:[t],i=[];for(const n of e)n==="http://iiif.io/api/presentation/2/context.json"&&i.push("http://iiif.io/api/presentation/3/context.json"),qe.indexOf(n)===-1&&i.push(n);if(e.length)return i.length===1?i[0]:i}}function Ve(t){return t?t.map(e=>({label:u(e.label),value:u(e.value)})):[]}function v(t){for(const e in t)(typeof t[e]=="undefined"||t[e]===null)&&delete t[e];return t}let he=0;function ce(t,e){const i=encodeURI(t.id||t["@id"]||"").trim();return i&&e?`${i}/${e}`:i||(he++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${he}`)}function p(t){const e=[...t.behavior||[]];return t.viewingHint&&e.push(t.viewingHint),{"@context":t["@context"]?Ue(t["@context"]):void 0,id:(t["@id"]||ce(t)).trim(),type:P(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:t.motivation?Ne(t.motivation):void 0,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function l(t){const[e,i]=$e(t.license),n=[...t.metadata?Ve(t.metadata):[],...i];return{rights:e,metadata:n.length?n:void 0,label:t.label?u(t.label):void 0,requiredStatement:t.attribution?{label:u(x.attributionLabel),value:u(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?u(t.description):void 0,thumbnail:t.thumbnail}}function We(t){if(!t.within)return;const e=Array.isArray(t.within)?t.within:[t.within],i=[];for(const n of e)if(typeof n=="string"){if(n)switch(t["@type"]){case"sc:Manifest":i.push({id:n,type:"Collection"});break}}else n["@id"]&&i.push({id:n["@id"],type:P(n)});return i.length?i:void 0}function h(t){const e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],i=t.contentLayer;return{provider:t.logo||e.length?[{id:x.providerId,type:"Agent",homepage:e.length?[e[0]]:void 0,logo:t.logo?Array.isArray(t.logo)?t.logo:[t.logo]:void 0,label:u(x.providerName)}]:void 0,partOf:We(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?ke(t.service):void 0,supplementary:i?[i]:void 0}}function ze(t){return v({...p(t),...l(t),...h(t),items:t.members})}function He(t){const e=[],i=[];for(const a of t.sequences||[])a.canvases.length&&e.push(...a.canvases),a.behavior&&i.push(...a.behavior);const n=p(t);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),v({...n,...l(t),...h(t),items:e,structures:t.structures})}function Be(t){return v({...p(t),...l(t),...h(t),items:t.images&&t.images.length?[{id:ce(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function Ke(t){return v({...p(t),...l(t),...h(t),items:t.resources})}function Qe(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[]}}function Xe(t){return v({...p(t),...l(t),...h(t),target:typeof t.on=="string"?encodeURI(t.on).trim():t.on,body:t.resource})}function Ye(t){const e=t;return v({...p(e),...l(e),...h(e)})}function Ze(t){const e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),{...p(t),...l(t),items:e}}function Je(t){return v({...p(t),...l(t),...h(t),items:t.members})}function et(t){const{"@id":e,"@type":i,"@context":n,profile:a,...r}=t;return e&&(r.id=e),r.type=P(t),r.type==="unknown"&&(r.type="Service"),a&&(r.profile=pe(a)),v({...r,...l(r)})}function tt(t){return v({...p(t),...l(t),...h(t)})}const it=new S({collection:[ze],manifest:[He],canvas:[Be],annotationList:[Ke],sequence:[Qe],annotation:[Xe],contentResource:[Ye],choice:[Ze],range:[Je],service:[et],layer:[tt]});function nt(t){return t&&t["@context"]&&(t["@context"]==="http://iiif.io/api/presentation/2/context.json"||t["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")!==-1||t["@context"]==="http://www.shared-canvas.org/ns/context.json")||t["@context"]==="http://iiif.io/api/image/2/context.json"?it.traverseUnknown(t):t}const rt={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}};function fe(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}function ue(t,e){if(typeof t=="string")return{id:t,type:e};if(!t.id)throw new Error(`Invalid resource does not have an ID (${e})`);return t}function at(t){return(e,i)=>{const n=t[e]?t[e]:{};return a=>{const r=ue(a,i||e);return r&&r.id&&e?(n[r.id]=n[r.id]?Object.assign({},n[r.id],r):Object.assign({},r),{id:r.id,type:e==="ContentResource"?e:r.type}):r}}}function st(t){return(e,i)=>n=>{const{id:a,type:r}=ue(n,i||e);if(typeof a=="undefined")throw new Error("Found invalid entity without an ID.");return e==="ContentResource"?t[a]=e:t[a]=r,n}}function ot(t){const e=JSON.stringify(t);let i=5381,n=e.length;for(;n;)i=i*33^e.charCodeAt(--n);const r=(i>>>0).toString(16);return r.length%2?"0"+r:r}function O(t){return e=>typeof e=="string"?{id:e,type:t}:e.id?e.type?e:{type:t,...e}:{id:ot(e),type:t,...e}}function _(t){return e=>({...t,...e})}function b(t){return Array.isArray(t)?t:[t]}function lt(t){return t.body&&(t.body=b(t.body)),t.seeAlso&&(t.seeAlso=b(t.seeAlso)),t.body&&(t.body=b(t.body)),t.audience&&(t.audience=b(t.audience)),t.accessibility&&(t.accessibility=b(t.accessibility)),t.motivation&&(t.motivation=b(t.motivation)),t}function vt(t){const e=nt(t),i=fe(),n={},a=at(i),r=st(n),o=new L({collection:[_(j),r("Collection"),a("Collection")],manifest:[_(G),r("Manifest"),a("Manifest")],canvas:[_(N),r("Canvas"),a("Canvas")],annotationPage:[O("AnnotationPage"),_(k),r("AnnotationPage"),a("AnnotationPage")],annotation:[O("Annotation"),lt,r("Annotation"),a("Annotation")],contentResource:[O("ContentResource"),r("ContentResource"),a("ContentResource")],range:[_($),r("Range","Canvas"),a("Range","Canvas")],agent:[_(q),r("Agent"),a("Agent")]}).traverseUnknown(e);return{entities:i,resource:o,mapping:n}}const c="__$UNSET$__",F="__$UNWRAP$__";function pt(t,e){const i=t.requests[e],n=t.mapping[e];if(!(!n||i&&i.resourceUri&&!t.entities[n][i.resourceUri]))return t.entities[n][i?i.resourceUri:e]}function de(t){const e={};for(const[i,n]of t){if(i===F&&n!==c)return n;n!==c&&typeof n!="undefined"&&n!==null&&(e[i]=n)}return e}function ht(t,e,i){if(!e.type||!e.id)throw new Error("Unknown entity");if(!i[e.type])throw new Error(`Serializer not found for ${e.type}`);function n(a){const r=i[a.type];if(!r)return c;const I=pt(t,a.id)||(a.id&&a.type?a:null);if(!I)return c;const o=r(I,t,{isTopLevel:e.id===a.id});let R=o.next();for(;!R.done;){const w=R.value;let T=c;if(w)if(Array.isArray(w)){const D=[];for(const Ae of w)D.push(n(Ae));T=D}else T=n(w);R=o.next(T)}return R.value===c?c:de(R.value)}return n(e)}function d(t){if(!t)return;const e=Object.keys(t);if(e.length!==0){if(e.length===1){const i=e[0];if(!i)return"";const n=(t[i]||[]).join("");return i==="@none"||i==="none"||i==="en"?n:{"@language":i,"@value":n}}return e.map(i=>({"@language":i,"@value":(t[i]||[]).join("")}))}}function me(t){return Array.isArray(t)?t.map(e=>me(e)):typeof t=="string"?t:t.type&&t.type==="Canvas"?t.id:t}function f(t,e=!1){if(!!t)return t.length>1&&!e?t:t[0]||void 0}function ct(t){if(!!t){if(typeof t=="string")return{"@id":t};if("@id"in t){const e={...t};return delete e["@type"],e}return{"@context":"http://iiif.io/api/image/2/context.json","@id":t.id,profile:`http://iiif.io/api/image/2/profiles/${t.profile}.json`}}}function m(t,e){return[["@id",t.id],["@type",e],["format",t.format],["height",t.height],["width",t.width],["viewingDirection",t.viewingDirection!=="left-to-right"?t.viewingDirection:void 0]]}function*g(t){const e=t.provider?yield t.provider[0]:void 0;return[["label",d(t.label)],["metadata",t.metadata&&t.metadata.length?t.metadata.map(i=>({label:d(i.label)||"",value:d(i.value)||""})):void 0],["description",d(t.summary)],["thumbnail",f(yield t.thumbnail)],["navDate",t.navDate],["logo",e?f(e.logo):void 0],["homepage",e?e.homepage:void 0],["attribution",t.requiredStatement?d(t.requiredStatement.value):void 0]]}function*E(t){return[["seeAlso",f(yield t.seeAlso)],["service",f((t.service||[]).map(ct))],["rendering",f(yield t.rendering)],["startCanvas",t.start?t.start.id:void 0]]}const ft={Manifest:function*(t){return[...m(t,"sc:Manifest"),...yield*g(t),...yield*E(t),["sequences",[{"@id":`${t.id}/sequence0`,"@type":"sc:Sequence",canvases:yield t.items}]],["structures",yield t.structures]]},Canvas:function*(t){const i=(yield t.items)[0];return[...m(t,"sc:Canvas"),...yield*g(t),...yield*E(t),["images",i?[i.resources]:void 0],["annotations",t.annotations&&t.annotations.length?f(yield t.annotations):void 0]]},AnnotationPage:function*(t){return[...m(t,"sc:AnnotationList"),...yield*g(t),["resources",t.items&&t.items.length?f(yield t.items):void 0]]},Annotation:function*(t){return[["@id",t.id],["@type","oa:Annotation"],["motivation","sc:painting"],["on",me(t.target)],["resource",f(yield t.body,!0)]]},ContentResource:function*(t){switch(t.type){case"Image":return[...m(t,"dctypes:Image"),...yield*g(t),...yield*E(t)];case"Text":case"Dataset":default:return[...m(t,void 0),...yield*g(t)]}},AnnotationCollection:function*(t){return[["@id",t.id],["@type","sc:Layer"],["label",d(t.label)]]},Collection:function*(t){return[...m(t,"sc:Collection"),...yield*g(t),...yield*E(t),["members",yield*t.items]]},Range:function*(t){const e=[],i=[];if(t.items)for(const n of t.items){const a=yield n;e.push({"@id":n.id,"@type":n.type,label:a?a.label:void 0,within:t.id}),n.type==="Canvas"&&i.push(n.id)}return[...m(t,"sc:Range"),...yield*g(t),...yield*E(t),["canvases",i.length===e.length?i:void 0],["members",i.length!==e.length?e:void 0]]}};function y(t){return[["id",t.id],["type",t.type],["format",t.format],["profile",t.profile],["height",t.height],["width",t.width],["duration",t.duration||void 0],["viewingDirection",t.viewingDirection!=="left-to-right"?t.viewingDirection:void 0],["behavior",t.behavior&&t.behavior.length?t.behavior:void 0],["timeMode",t.timeMode],["motivation",t.motivation]]}function s(t){if(!(!t||t.length===0))return t}function ge(t){if(t&&t.type&&t.type==="ImageService2"){const{id:e,type:i,profile:n,...a}=t;return{"@id":e,"@type":i,profile:n.startsWith("http")?n:`http://iiif.io/api/image/2/${n}.json`,...a}}return t}function ye(t){if(!(!t||t.length===0))return t.map(ge)}function*A(t){return[["label",t.label],["metadata",s(t.metadata)],["summary",t.summary],["requiredStatement",t.requiredStatement],["rights",t.rights],["navDate",t.navDate],["language",t.language],["thumbnail",s(yield t.thumbnail)],["placeholderCanvas",yield t.placeholderCanvas],["accompanyingCanvas",yield t.accompanyingCanvas],["provider",s(yield t.provider)]]}function*C(t){return[["seeAlso",s(yield t.seeAlso)],["service",ye(t.service)],["services",ye(t.services)],["rendering",s(yield t.rendering)],["supplementary",s(yield t.supplementary)],["homepage",s(yield t.homepage)],["logo",s(yield t.logo)],["partOf",s(yield t.partOf)],["start",t.start]]}const ut={Manifest:function*(t,e,{isTopLevel:i}){return i?[["@context","http://iiif.io/api/presentation/3/context.json"],...y(t),...yield*A(t),...yield*C(t),["items",yield t.items],["structures",s(yield t.structures)],["annotations",s(yield t.annotations)]]:[...y(t),...yield*A(t)]},Canvas:function*(t){return[...y(t),...yield*A(t),...yield*C(t),["items",yield t.items],["annotations",s(yield t.annotations)]]},Agent:function*(t){return[["id",t.id],["type","Agent"],["label",t.label],...yield*C(t)]},AnnotationPage:function*(t){return[...Object.entries(t).map(([i,n])=>[i,Array.isArray(n)?s(n):n]).filter(([i,n])=>i!=="items"),...yield*C(t),["items",yield t.items]]},Service:function*(t){return[[F,ge(t)]]},Annotation:function*(t){return[...Object.entries(t).map(([i,n])=>[i,Array.isArray(n)?s(n):n]).filter(([i])=>i!=="body"),["body",yield t.body]]},ContentResource:function*(t){return[...y(t),...yield*A(t),...yield*C(t),["annotations",s(yield t.annotations)]]},AnnotationCollection:function*(t){return[["id",t.id],["type","AnnotationCollection"],["label",t.label]]},Collection:function*(t,e,{isTopLevel:i}){return i?[["@context","http://iiif.io/api/presentation/3/context.json"],...y(t),...yield*A(t),...yield*C(t),["items",s(yield t.items)]]:[...y(t),...yield*A(t)]},Range:function*(t){const e=[];for(const i of t.items)i.type==="Range"?e.push(yield i):e.push(i);return[...y(t),...yield*A(t),...yield*C(t),["items",e],["annotations",s(yield t.annotations)]]}};exports.Traverse=L,exports.UNSET=c,exports.UNWRAP=F,exports.defaultEntities=rt,exports.emptyAgent=q,exports.emptyAnnotation=Ce,exports.emptyAnnotationPage=k,exports.emptyCanvas=N,exports.emptyCollection=j,exports.emptyManifest=G,exports.emptyRange=$,exports.getDefaultEntities=fe,exports.identifyResource=U,exports.languageString2to3=d,exports.normalize=vt,exports.serialize=ht,exports.serializeConfigPresentation2=ft,exports.serializeConfigPresentation3=ut,exports.serializedFieldsToObject=de,exports.types=M;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const Ce={id:"https://iiif-parser/annotation",type:"Annotation",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[],accessibility:[],audience:[],body:[],bodyValue:null,canonical:null,created:null,creator:[],generated:null,generator:[],modified:null,motivation:[],rights:[],stylesheet:null,target:[],timeMode:void 0,via:[],partOf:[]},k={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:[],motivation:null,label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[]},N={id:"https://iiif-parser/empty-canvas",type:"Canvas",label:null,behavior:[],motivation:null,thumbnail:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:[],rights:null,navDate:null,provider:[],items:[],annotations:[],seeAlso:[],homepage:[],logo:[],partOf:[],rendering:[],service:[],duration:0,height:0,width:0},j={id:"https://iiif-parser/empty-collection",type:"Collection",label:null,viewingDirection:"left-to-right",behavior:[],motivation:null,thumbnail:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:[],rights:null,navDate:null,provider:[],items:[],annotations:[],seeAlso:[],homepage:[],logo:[],partOf:[],rendering:[],service:[],services:[]},G={id:"https://iiif-parser/empty-manifest",type:"Manifest",annotations:[],behavior:[],homepage:[],items:[],label:null,logo:[],metadata:[],motivation:null,navDate:null,provider:[],partOf:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,rendering:[],requiredStatement:null,rights:null,seeAlso:[],service:[],services:[],start:null,structures:[],summary:null,thumbnail:[],viewingDirection:"left-to-right"},$={id:"https://iiif-parser/empty-canvas",type:"Range",label:null,behavior:[],motivation:null,thumbnail:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:[],rights:null,navDate:null,provider:[],items:[],annotations:[],seeAlso:[],homepage:[],logo:[],partOf:[],rendering:[],service:[],start:null,supplementary:null,viewingDirection:"left-to-right"},q={id:"https://iiif-parser/empty-agent",type:"Agent",label:{},logo:[],seeAlso:[],homepage:[]},M=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function U(t){if(typeof t=="undefined"||t===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(t))throw new Error("Array is not a valid entity");if(typeof t!="object")throw new Error(`${typeof t} is not a valid entity`);if(typeof t.type=="string"){const e=M.indexOf(t.type);if(e!==-1)return M[e]}if(t.profile)return"Service";throw new Error("Resource type is not known")}class L{traversals;options;constructor(e,i={}){this.traversals={collection:[],manifest:[],canvas:[],annotationCollection:[],annotationPage:[],annotation:[],contentResource:[],choice:[],range:[],service:[],agent:[],...e},this.options={allowUndefinedReturn:!1,...i}}static all(e){return new L({collection:[e],manifest:[e],canvas:[e],annotationCollection:[e],annotationPage:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e]})}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=e.thumbnail.map(i=>this.traverseType(i,this.traversals.contentResource))),e.provider&&(e.provider=e.provider.map(i=>this.traverseAgent(i))),e}traverseLinking(e){return e.seeAlso&&(e.seeAlso=e.seeAlso.map(i=>this.traverseType(i,this.traversals.contentResource))),e.service&&(e.service=e.service.map(i=>this.traverseType(i,this.traversals.service))),e.services&&(e.services=e.services.map(i=>this.traverseType(i,this.traversals.service))),e.logo&&(e.logo=e.logo.map(i=>this.traverseType(i,this.traversals.contentResource))),e.homepage&&(e.homepage=e.homepage.map(i=>this.traverseType(i,this.traversals.contentResource))),e.partOf&&(e.partOf=e.partOf.map(i=>typeof i=="string"||!i.type?this.traverseType(i,this.traversals.contentResource):i.type==="Canvas"?this.traverseType(i,this.traversals.canvas):i.type==="AnnotationCollection"?this.traverseType(i,this.traversals.annotationCollection):this.traverseType(i,this.traversals.contentResource))),e.start&&(e.start=e.start?this.traverseType(e.start,this.traversals.canvas):null),e.rendering&&(e.rendering=e.rendering.map(i=>this.traverseType(i,this.traversals.contentResource))),e.supplementary&&(e.supplementary=e.supplementary.map(i=>this.traverseType(i,this.traversals.contentResource))),e}traverseCollectionItems(e){return e.items&&e.items.map(i=>i.type==="Collection"?this.traverseCollection(i):this.traverseManifest(i)),e}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traversePosterCanvas(this.traverseCollectionItems(e))))),this.traversals.collection)}traverseManifestItems(e){return e.items&&(e.items=e.items.map(i=>this.traverseCanvas(i))),e}traverseManifestStructures(e){return e.structures&&(e.structures=e.structures.map(i=>this.traverseRange(i))),e}traverseManifest(e){return this.traverseType(this.traverseInlineAnnotationPages(this.traverseManifestStructures(this.traversePosterCanvas(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e)))))),this.traversals.manifest)}traverseCanvasItems(e){return e.items=(e.items||[]).map(i=>this.traverseAnnotationPage(i)),e}traverseInlineAnnotationPages(e){return typeof e=="string"||!e||e.annotations&&(e.annotations=e.annotations.map(i=>this.traverseAnnotationPage(i))),e}traverseCanvas(e){return this.traverseType(this.traverseInlineAnnotationPages(this.traversePosterCanvas(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))))),this.traversals.canvas)}traverseAnnotationPageItems(e){return e.items&&(e.items=e.items.map(i=>this.traverseAnnotation(i))),e}traverseAnnotationPage(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationPageItems(e))),this.traversals.annotationPage)}traverseAnnotationBody(e){return Array.isArray(e.body)?e.body=e.body.map(i=>this.traverseContentResource(i)):e.body&&(e.body=this.traverseContentResource(e.body)),e}traversePosterCanvas(e){return e.posterCanvas&&(e.posterCanvas=this.traverseType(e.posterCanvas,this.traversals.canvas)),e.placeholderCanvas&&(e.placeholderCanvas=this.traverseType(e.placeholderCanvas,this.traversals.canvas)),e.accompanyingCanvas&&(e.accompanyingCanvas=this.traverseType(e.accompanyingCanvas,this.traversals.canvas)),e}traverseAnnotation(e){return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(e)),this.traversals.annotation)}traverseContentResourceLinking(e){return typeof e=="string"||!e||e&&e.service&&(e.service=(e.service||[]).map(i=>this.traverseType(i,this.traversals.service))),e}traverseContentResource(e){return e.type==="Choice"&&(e.items=e.items.map(i=>this.traverseContentResource(i))),this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)),this.traversals.contentResource)}traverseRangeRanges(e){return e.items&&(e.items=e.items.map(i=>typeof i=="string"?this.traverseCanvas({id:i,type:"Canvas"}):i.type==="Manifest"?this.traverseManifest(i):this.traverseRange(i))),e}traverseRange(e){return this.traverseType(this.traversePosterCanvas(this.traverseDescriptive(this.traverseLinking(this.traverseRangeRanges(e)))),this.traversals.range)}traverseAgent(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.agent)}traverseType(e,i){return i.reduce((n,a)=>{const r=a(n);return typeof r=="undefined"&&!this.options.allowUndefinedReturn?n:r},e)}traverseService(e){return this.traverseType(e,this.traversals.service)}traverseUnknown(e){const i=U(e);switch(i){case"Collection":return this.traverseCollection(e);case"Manifest":return this.traverseManifest(e);case"Canvas":return this.traverseCanvas(e);case"AnnotationPage":return this.traverseAnnotationPage(e);case"Annotation":return this.traverseAnnotation(e);case"ContentResource":return this.traverseContentResource(e);case"Range":return this.traverseRange(e);case"Service":return this.traverseService(e);case"Agent":return this.traverseAgent(e);default:throw new Error(`Unknown or unsupported resource type of ${i}`)}}}const V=["sc:Collection","sc:Manifest","sc:Canvas","oa:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function Ie(t){if(typeof t=="undefined"||t===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(t))throw new Error("Array is not a valid entity");if(typeof t!="object")throw new Error(`${typeof t} is not a valid entity`);if(typeof t["@type"]=="string"){const e=V.indexOf(t["@type"]);if(e!==-1)return V[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}class S{traversals;options;constructor(e,i={}){this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...i}}static all(e){return new S({collection:[e],manifest:[e],canvas:[e],annotationList:[e],sequence:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],layer:[e]})}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))),this.traversals.collection)}traverseCollectionItems(e){if(this.options.mergeMemberProperties){const i=[...(e.manifests||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n),...(e.collections||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n),...e.members||[]];delete e.collections,delete e.manifests,e.members=i}return e.manifests&&(e.manifests=e.manifests.map(i=>this.traverseManifest(typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i))),e.collections&&(e.collections=e.collections.map(i=>this.traverseCollection(typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i))),e.members&&(e.members=e.members.map(i=>typeof i=="string"?i:this.traverseUnknown(i))),e}traverseManifest(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))),this.traversals.manifest)}traverseManifestItems(e){return e.sequences&&(e.sequences=e.sequences.map(i=>this.traverseSequence(i))),e.structures&&(e.structures=e.structures.map(i=>this.traverseRange(i))),e}traverseSequence(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))),this.traversals.sequence)}traverseSequenceItems(e){return e.canvases&&(e.canvases=e.canvases.map(i=>this.traverseCanvas(i))),e}traverseCanvas(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))),this.traversals.canvas)}traverseCanvasItems(e){return e.images&&(e.images=e.images.map(i=>this.traverseAnnotation(i))),e.otherContent&&(e.otherContent=e.otherContent.map(i=>this.traverseAnnotationList(i))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const i=[...(e.ranges||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Range"}:n),...(e.canvases||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Canvas"}:n),...e.members||[]];delete e.ranges,delete e.canvases,e.members=i.length?i.map(n=>this.traverseUnknown(n)):void 0}return e}traverseAnnotationList(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationListItems(e))),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map(i=>this.traverseAnnotation(i))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(e.resource=this.traverseContentResource(e.resource)),e.on,e}traverseLayer(e){return this.traverseType(this.traverseLinking(this.traverseLayerItems(e)),this.traversals.layer)}traverseLayerItems(e){return e.otherContent&&(e.otherContent=e.otherContent.map(i=>this.traverseAnnotationList(i))),e}traverseChoice(e){return this.traverseType(this.traverseChoiceItems(e),this.traversals.choice)}traverseChoiceItems(e){return e.default&&e.default!=="rdf:nil"&&(e.default=this.traverseContentResource(e.default)),e.item&&e.item!=="rdf:nil"&&(e.item=e.item.map(i=>this.traverseContentResource(i))),e}traverseService(e){return this.traverseType(this.traverseLinking(e),this.traversals.service)}traverseContentResource(e){return e["@type"]==="oa:Choice"?this.traverseChoice(e):this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.contentResource)}traverseUnknown(e){if(!e["@type"]||typeof e=="string")return e;switch(Ie(e)){case"sc:Collection":return this.traverseCollection(e);case"sc:Manifest":return this.traverseManifest(e);case"sc:Canvas":return this.traverseCanvas(e);case"sc:Sequence":return this.traverseSequence(e);case"sc:Range":return this.traverseRange(e);case"oa:Annotation":return this.traverseAnnotation(e);case"oa:AnnotationList":return this.traverseAnnotationList(e);case"sc:Layer":return this.traverseLayer(e);case"Service":return this.traverseService(e);case"oa:Choice":return this.traverseChoice(e);case"ContentResource":return this.traverseContentResource(e)}return e.profile?this.traverseService(e):e}traverseImageResource(e){const i=Array.isArray(e),n=Array.isArray(e)?e:[e],a=[];for(const r of n)typeof r=="string"?a.push(this.traverseContentResource({"@id":r,"@type":"dctypes:Image"})):a.push(this.traverseContentResource(r));return!i&&!this.options.convertPropsToArray?a[0]:a}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){const i=Array.isArray(e),n=Array.isArray(e)?e:[e],a=[];for(const r of n)a.push(this.traverseService(r));return!i&&!this.options.convertPropsToArray?a[0]:a}traverseLinking(e){return e.related&&(e.related=this.traverseOneOrManyType(e.related,this.traversals.contentResource)),e.rendering&&(e.rendering=this.traverseOneOrManyType(e.rendering,this.traversals.contentResource)),e.service&&(e.service=this.traverseOneOrMoreServices(e.service)),e.seeAlso&&(e.seeAlso=this.traverseOneOrManyType(e.seeAlso,this.traversals.contentResource)),e.within&&(typeof e.within=="string"||(e.within=this.traverseOneOrManyType(e.within,this.traversals.contentResource))),e.startCanvas&&(typeof e.startCanvas=="string"?e.startCanvas=this.traverseType({"@id":e.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):e.startCanvas&&this.traverseType(e.startCanvas,this.traversals.canvas)),e.contentLayer&&(typeof e.contentLayer=="string"?e.contentLayer=this.traverseLayer({"@id":e.contentLayer,"@type":"sc:Layer"}):e.contentLayer=this.traverseLayer(e.contentLayer)),e}traverseOneOrManyType(e,i){if(!Array.isArray(e))if(this.options.convertPropsToArray)e=[e];else return this.traverseType(e,i);return e.map(n=>this.traverseType(n,i))}traverseType(e,i){return i.reduce((n,a)=>{const r=a(n);return typeof r=="undefined"&&!this.options.allowUndefinedReturn?n:r},e)}}const _e="http://library.stanford.edu/iiif/image-api/compliance.html#level0",W="http://library.stanford.edu/iiif/image-api/compliance.html#level1",z="http://library.stanford.edu/iiif/image-api/compliance.html#level2",be="http://library.stanford.edu/iiif/image-api/conformance.html#level0",H="http://library.stanford.edu/iiif/image-api/conformance.html#level1",B="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Re="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",K="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Q="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Ee="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",X="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Y="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",we="http://iiif.io/api/image/1/level0.json",Le="http://iiif.io/api/image/1/profiles/level0.json",Z="http://iiif.io/api/image/1/level1.json",J="http://iiif.io/api/image/1/profiles/level1.json",ee="http://iiif.io/api/image/1/level2.json",te="http://iiif.io/api/image/1/profiles/level2.json",Te="http://iiif.io/api/image/2/level0.json",Me="http://iiif.io/api/image/2/profiles/level0.json",ie="http://iiif.io/api/image/2/level1.json",ne="http://iiif.io/api/image/2/profiles/level1.json",re="http://iiif.io/api/image/2/level2.json",ae="http://iiif.io/api/image/2/profiles/level2.json",Se="level0",se="level1",oe="level2",xe="http://iiif.io/api/image/2/level0",le="http://iiif.io/api/image/2/level1",ve="http://iiif.io/api/image/2/level2",Pe=[le,ve,W,z,H,B,K,Q,X,Y,Z,J,ee,te,ie,ne,re,ae,se,oe],Oe=[xe,le,ve,_e,W,z,be,H,B,Re,K,Q,Ee,X,Y,we,Le,Z,J,ee,te,Te,Me,ie,ne,re,ae,Se,se,oe],x={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function u(t,e="none"){if(!t)return{};const i=Array.isArray(t)?t:[t],n={};for(const a of i){if(typeof a=="string"){n[e]=n[e]?n[e]:[],n[e].push(a||"");continue}if(!a["@language"]){n[e]=n[e]?n[e]:[],n[e].push(a["@value"]||"");continue}const r=a["@language"];n[r]=n[r]?n[r]:[],n[r].push(a["@value"]||"")}return n}function pe(t){if(Array.isArray(t))return pe(t.find(e=>typeof e=="string"));if(Oe.indexOf(t)!==-1)return"level2";if(Pe.indexOf(t)!==-1)return"level1";if(typeof t=="string")return t}function Fe(t){const e=Array.isArray(t)?t:[t];for(const i of e)switch(i){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function De(t){switch(t){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}function ke(t){return Array.isArray(t)?t:[t]}function Ne(t){for(const e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}const je=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function P(t){const e=t["@id"]||t.id;let i=t["@type"]||t.type;const n=t.profile||void 0,a=t["@context"]||void 0;if(n){const r=De(n);if(r)return r}if(a){const r=Fe(a);if(r)return r}if(i){if(Array.isArray(i)){if(i.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(i.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";i=i[0]}for(const r of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${r}:`)){i=i.slice(r.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(i&&je.indexOf(i)!==-1)return i;if(t.format){if(t.format.startsWith("image/"))return"Image";if(t.format.startsWith("text/")||t.format==="application/pdf")return"Text";if(t.format.startsWith("application/"))return"Dataset"}return e&&(e.endsWith(".jpg")||e.endsWith(".png")||e.endsWith(".jpeg"))?"Image":i||"unknown"}const Ge=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function $e(t){const e=t.match(Ge);return e?e[0]:t}function qe(t,e="Rights/License",i="none"){let n=null;const a=[],r=Array.isArray(t)?t:[t];for(const I of r){const o=I?$e(I):void 0;if(o&&(o.indexOf("creativecommons.org")!==-1||o.indexOf("rightsstatements.org")!==-1)){o.startsWith("https://")?n=`http://${o.slice(8)}`:n=o;continue}o&&a.push({label:{[i]:[e]},value:{[i]:[o]}})}return[n,a]}const Ue=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function Ve(t){if(t){const e=Array.isArray(t)?t:[t],i=[];for(const n of e)n==="http://iiif.io/api/presentation/2/context.json"&&i.push("http://iiif.io/api/presentation/3/context.json"),Ue.indexOf(n)===-1&&i.push(n);if(e.length)return i.length===1?i[0]:i}}function We(t){return t?t.map(e=>({label:u(e.label),value:u(e.value)})):[]}function v(t){for(const e in t)(typeof t[e]=="undefined"||t[e]===null)&&delete t[e];return t}let ce=0;function he(t,e){const i=encodeURI(t.id||t["@id"]||"").trim();return i&&e?`${i}/${e}`:i||(ce++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${ce}`)}function p(t){const e=[...t.behavior||[]];return t.viewingHint&&e.push(t.viewingHint),{"@context":t["@context"]?Ve(t["@context"]):void 0,id:(t["@id"]||he(t)).trim(),type:P(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:t.motivation?Ne(t.motivation):void 0,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function l(t){const[e,i]=qe(t.license),n=[...t.metadata?We(t.metadata):[],...i];return{rights:e,metadata:n.length?n:void 0,label:t.label?u(t.label):void 0,requiredStatement:t.attribution?{label:u(x.attributionLabel),value:u(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?u(t.description):void 0,thumbnail:t.thumbnail}}function ze(t){if(!t.within)return;const e=Array.isArray(t.within)?t.within:[t.within],i=[];for(const n of e)if(typeof n=="string"){if(n)switch(t["@type"]){case"sc:Manifest":i.push({id:n,type:"Collection"});break}}else n["@id"]&&i.push({id:n["@id"],type:P(n)});return i.length?i:void 0}function c(t){const e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],i=t.contentLayer;return{provider:t.logo||e.length?[{id:x.providerId,type:"Agent",homepage:e.length?[e[0]]:void 0,logo:t.logo?Array.isArray(t.logo)?t.logo:[t.logo]:void 0,label:u(x.providerName)}]:void 0,partOf:ze(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?ke(t.service):void 0,supplementary:i?[i]:void 0}}function He(t){return v({...p(t),...l(t),...c(t),items:t.members})}function Be(t){const e=[],i=[];for(const a of t.sequences||[])a.canvases.length&&e.push(...a.canvases),a.behavior&&i.push(...a.behavior);const n=p(t);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),v({...n,...l(t),...c(t),items:e,structures:t.structures})}function Ke(t){return v({...p(t),...l(t),...c(t),items:t.images&&t.images.length?[{id:he(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function Qe(t){return v({...p(t),...l(t),...c(t),items:t.resources})}function Xe(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[]}}function Ye(t){return v({...p(t),...l(t),...c(t),target:typeof t.on=="string"?encodeURI(t.on).trim():t.on,body:t.resource})}function Ze(t){const e=t;return v({...p(e),...l(e),...c(e)})}function Je(t){const e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),{...p(t),...l(t),items:e}}function et(t){return v({...p(t),...l(t),...c(t),items:t.members})}function tt(t){const{"@id":e,"@type":i,"@context":n,profile:a,...r}=t;return e&&(r.id=e),r.type=P(t),r.type==="unknown"&&(r.type="Service"),a&&(r.profile=pe(a)),v({...r,...l(r)})}function it(t){return v({...p(t),...l(t),...c(t)})}const nt=new S({collection:[He],manifest:[Be],canvas:[Ke],annotationList:[Qe],sequence:[Xe],annotation:[Ye],contentResource:[Ze],choice:[Je],range:[et],service:[tt],layer:[it]});function rt(t){return t&&t["@context"]&&(t["@context"]==="http://iiif.io/api/presentation/2/context.json"||t["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")!==-1||t["@context"]==="http://www.shared-canvas.org/ns/context.json")||t["@context"]==="http://iiif.io/api/image/2/context.json"?nt.traverseUnknown(t):t}const at={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}};function fe(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}function ue(t,e){if(typeof t=="string")return{id:t,type:e};if(!t.id)throw new Error(`Invalid resource does not have an ID (${e})`);return t}function st(t){return(e,i)=>{const n=t[e]?t[e]:{};return a=>{const r=ue(a,i||e);return r&&r.id&&e?(n[r.id]=n[r.id]?Object.assign({},n[r.id],r):Object.assign({},r),{id:r.id,type:e==="ContentResource"?e:r.type}):r}}}function ot(t){return(e,i)=>n=>{const{id:a,type:r}=ue(n,i||e);if(typeof a=="undefined")throw new Error("Found invalid entity without an ID.");return e==="ContentResource"?t[a]=e:t[a]=r,n}}function lt(t){const e=JSON.stringify(t);let i=5381,n=e.length;for(;n;)i=i*33^e.charCodeAt(--n);const r=(i>>>0).toString(16);return r.length%2?"0"+r:r}function O(t){return e=>typeof e=="string"?{id:e,type:t}:e.id?e.type?e:{type:t,...e}:{id:lt(e),type:t,...e}}function _(t){return e=>({...t,...e})}function b(t){return Array.isArray(t)?t:[t]}function vt(t){return t.body&&(t.body=b(t.body)),t.seeAlso&&(t.seeAlso=b(t.seeAlso)),t.body&&(t.body=b(t.body)),t.audience&&(t.audience=b(t.audience)),t.accessibility&&(t.accessibility=b(t.accessibility)),t.motivation&&(t.motivation=b(t.motivation)),t}function pt(t){const e=rt(t),i=fe(),n={},a=st(i),r=ot(n),o=new L({collection:[_(j),r("Collection"),a("Collection")],manifest:[_(G),r("Manifest"),a("Manifest")],canvas:[_(N),r("Canvas"),a("Canvas")],annotationPage:[O("AnnotationPage"),_(k),r("AnnotationPage"),a("AnnotationPage")],annotation:[O("Annotation"),vt,r("Annotation"),a("Annotation")],contentResource:[O("ContentResource"),r("ContentResource"),a("ContentResource")],range:[_($),r("Range","Canvas"),a("Range","Canvas")],agent:[_(q),r("Agent"),a("Agent")]}).traverseUnknown(e);return{entities:i,resource:o,mapping:n}}const h="__$UNSET$__",F="__$UNWRAP$__";function ct(t,e){const i=t.requests[e],n=t.mapping[e];if(!(!n||i&&i.resourceUri&&!t.entities[n][i.resourceUri]))return t.entities[n][i?i.resourceUri:e]}function de(t){const e={};for(const[i,n]of t){if(i===F&&n!==h)return n;n!==h&&typeof n!="undefined"&&n!==null&&(e[i]=n)}return e}function ht(t,e,i){if(!e.type||!e.id)throw new Error("Unknown entity");if(!i[e.type])throw new Error(`Serializer not found for ${e.type}`);function n(a){const r=i[a.type];if(!r)return h;const I=ct(t,a.id)||(a.id&&a.type?a:null);if(!I)return h;const o=r(I,t,{isTopLevel:e.id===a.id});let R=o.next();for(;!R.done;){const w=R.value;let T=h;if(w)if(Array.isArray(w)){const D=[];for(const Ae of w)D.push(n(Ae));T=D}else T=n(w);R=o.next(T)}return R.value===h?h:de(R.value)}return n(e)}function d(t){if(!t)return;const e=Object.keys(t);if(e.length!==0){if(e.length===1){const i=e[0];if(!i)return"";const n=(t[i]||[]).join("");return i==="@none"||i==="none"||i==="en"?n:{"@language":i,"@value":n}}return e.map(i=>({"@language":i,"@value":(t[i]||[]).join("")}))}}function me(t){return Array.isArray(t)?t.map(e=>me(e)):typeof t=="string"?t:t.type&&t.type==="Canvas"?t.id:t}function f(t,e=!1){if(!!t)return t.length>1&&!e?t:t[0]||void 0}function ft(t){if(!!t){if(typeof t=="string")return{"@id":t};if("@id"in t){const e={...t};return delete e["@type"],e}return{"@context":"http://iiif.io/api/image/2/context.json","@id":t.id,profile:`http://iiif.io/api/image/2/profiles/${t.profile}.json`}}}function m(t,e){return[["@id",t.id],["@type",e],["format",t.format],["height",t.height],["width",t.width],["viewingDirection",t.viewingDirection!=="left-to-right"?t.viewingDirection:void 0]]}function*g(t){const e=t.provider?yield t.provider[0]:void 0;return[["label",d(t.label)],["metadata",t.metadata&&t.metadata.length?t.metadata.map(i=>({label:d(i.label)||"",value:d(i.value)||""})):void 0],["description",d(t.summary)],["thumbnail",f(yield t.thumbnail)],["navDate",t.navDate],["logo",e?f(e.logo):void 0],["homepage",e?e.homepage:void 0],["attribution",t.requiredStatement?d(t.requiredStatement.value):void 0]]}function*E(t){return[["seeAlso",f(yield t.seeAlso)],["service",f((t.service||[]).map(ft))],["rendering",f(yield t.rendering)],["startCanvas",t.start?t.start.id:void 0]]}const ut={Manifest:function*(t){return[...m(t,"sc:Manifest"),...yield*g(t),...yield*E(t),["sequences",[{"@id":`${t.id}/sequence0`,"@type":"sc:Sequence",canvases:yield t.items}]],["structures",yield t.structures]]},Canvas:function*(t){const i=(yield t.items)[0];return[...m(t,"sc:Canvas"),...yield*g(t),...yield*E(t),["images",i?[i.resources]:void 0],["annotations",t.annotations&&t.annotations.length?f(yield t.annotations):void 0]]},AnnotationPage:function*(t){return[...m(t,"sc:AnnotationList"),...yield*g(t),["resources",t.items&&t.items.length?f(yield t.items):void 0]]},Annotation:function*(t){return[["@id",t.id],["@type","oa:Annotation"],["motivation","sc:painting"],["on",me(t.target)],["resource",f(yield t.body,!0)]]},ContentResource:function*(t){switch(t.type){case"Image":return[...m(t,"dctypes:Image"),...yield*g(t),...yield*E(t)];case"Text":case"Dataset":default:return[...m(t,void 0),...yield*g(t)]}},AnnotationCollection:function*(t){return[["@id",t.id],["@type","sc:Layer"],["label",d(t.label)]]},Collection:function*(t){return[...m(t,"sc:Collection"),...yield*g(t),...yield*E(t),["members",yield*t.items]]},Range:function*(t){const e=[],i=[];if(t.items)for(const n of t.items){const a=yield n;e.push({"@id":n.id,"@type":n.type,label:a?a.label:void 0,within:t.id}),n.type==="Canvas"&&i.push(n.id)}return[...m(t,"sc:Range"),...yield*g(t),...yield*E(t),["canvases",i.length===e.length?i:void 0],["members",i.length!==e.length?e:void 0]]}};function y(t){return[["id",t.id],["type",t.type],["format",t.format],["profile",t.profile],["height",t.height],["width",t.width],["duration",t.duration||void 0],["viewingDirection",t.viewingDirection!=="left-to-right"?t.viewingDirection:void 0],["behavior",t.behavior&&t.behavior.length?t.behavior:void 0],["timeMode",t.timeMode],["motivation",t.motivation]]}function s(t){if(!(!t||t.length===0))return t}function ge(t){if(t&&t.type&&t.type==="ImageService2"){const{id:e,type:i,profile:n,...a}=t;return{"@id":e,"@type":i,profile:n.startsWith("http")?n:`http://iiif.io/api/image/2/${n}.json`,...a}}return t}function ye(t){if(!(!t||t.length===0))return t.map(ge)}function*A(t){return[["label",t.label],["metadata",s(t.metadata)],["summary",t.summary],["requiredStatement",t.requiredStatement],["rights",t.rights],["navDate",t.navDate],["language",t.language],["thumbnail",s(yield t.thumbnail)],["placeholderCanvas",yield t.placeholderCanvas],["accompanyingCanvas",yield t.accompanyingCanvas],["provider",s(yield t.provider)]]}function*C(t){return[["seeAlso",s(yield t.seeAlso)],["service",ye(t.service)],["services",ye(t.services)],["rendering",s(yield t.rendering)],["supplementary",s(yield t.supplementary)],["homepage",s(yield t.homepage)],["logo",s(yield t.logo)],["partOf",s(yield t.partOf)],["start",t.start]]}const dt={Manifest:function*(t,e,{isTopLevel:i}){return i?[["@context","http://iiif.io/api/presentation/3/context.json"],...y(t),...yield*A(t),...yield*C(t),["items",yield t.items],["structures",s(yield t.structures)],["annotations",s(yield t.annotations)]]:[...y(t),...yield*A(t)]},Canvas:function*(t){return[...y(t),...yield*A(t),...yield*C(t),["items",yield t.items],["annotations",s(yield t.annotations)]]},Agent:function*(t){return[["id",t.id],["type","Agent"],["label",t.label],...yield*C(t)]},AnnotationPage:function*(t){return[...Object.entries(t).map(([i,n])=>[i,Array.isArray(n)?s(n):n]).filter(([i,n])=>i!=="items"),...yield*C(t),["items",yield t.items]]},Service:function*(t){return[[F,ge(t)]]},Annotation:function*(t){return[...Object.entries(t).map(([i,n])=>[i,Array.isArray(n)?s(n):n]).filter(([i])=>i!=="body"),["body",yield t.body]]},ContentResource:function*(t){return[...y(t),...yield*A(t),...yield*C(t),["annotations",s(yield t.annotations)]]},AnnotationCollection:function*(t){return[["id",t.id],["type","AnnotationCollection"],["label",t.label]]},Collection:function*(t,e,{isTopLevel:i}){return i?[["@context","http://iiif.io/api/presentation/3/context.json"],...y(t),...yield*A(t),...yield*C(t),["items",s(yield t.items)]]:[...y(t),...yield*A(t)]},Range:function*(t){const e=[];for(const i of t.items)i.type==="Range"?e.push(yield i):e.push(i);return[...y(t),...yield*A(t),...yield*C(t),["items",e],["annotations",s(yield t.annotations)]]}};exports.Traverse=L,exports.UNSET=h,exports.UNWRAP=F,exports.defaultEntities=at,exports.emptyAgent=q,exports.emptyAnnotation=Ce,exports.emptyAnnotationPage=k,exports.emptyCanvas=N,exports.emptyCollection=j,exports.emptyManifest=G,exports.emptyRange=$,exports.getDefaultEntities=fe,exports.identifyResource=U,exports.languageString2to3=d,exports.normalize=pt,exports.serialize=ht,exports.serializeConfigPresentation2=ut,exports.serializeConfigPresentation3=dt,exports.serializedFieldsToObject=de,exports.types=M;

@@ -1,1 +0,1 @@

const Ie={id:"https://iiif-parser/annotation",type:"Annotation",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[],accessibility:[],audience:[],body:[],bodyValue:null,canonical:null,created:null,creator:[],generated:null,generator:[],modified:null,motivation:[],rights:[],stylesheet:null,target:[],timeMode:void 0,via:[],partOf:[]},k={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:[],motivation:null,label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[]},N={id:"https://iiif-parser/empty-canvas",type:"Canvas",label:null,behavior:[],motivation:null,thumbnail:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:[],rights:null,navDate:null,provider:[],items:[],annotations:[],seeAlso:[],homepage:[],logo:[],partOf:[],rendering:[],service:[],duration:0,height:0,width:0},j={id:"https://iiif-parser/empty-collection",type:"Collection",label:null,viewingDirection:"left-to-right",behavior:[],motivation:null,thumbnail:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:[],rights:null,navDate:null,provider:[],items:[],annotations:[],seeAlso:[],homepage:[],logo:[],partOf:[],rendering:[],service:[],services:[]},G={id:"https://iiif-parser/empty-manifest",type:"Manifest",annotations:[],behavior:[],homepage:[],items:[],label:null,logo:[],metadata:[],motivation:null,navDate:null,provider:[],partOf:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,rendering:[],requiredStatement:null,rights:null,seeAlso:[],service:[],services:[],start:null,structures:[],summary:null,thumbnail:[],viewingDirection:"left-to-right"},$={id:"https://iiif-parser/empty-canvas",type:"Range",label:null,behavior:[],motivation:null,thumbnail:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:[],rights:null,navDate:null,provider:[],items:[],annotations:[],seeAlso:[],homepage:[],logo:[],partOf:[],rendering:[],service:[],start:null,supplementary:null,viewingDirection:"left-to-right"},q={id:"https://iiif-parser/empty-agent",type:"Agent",label:{},logo:[],seeAlso:[],homepage:[]},M=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function U(t){if(typeof t=="undefined"||t===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(t))throw new Error("Array is not a valid entity");if(typeof t!="object")throw new Error(`${typeof t} is not a valid entity`);if(typeof t.type=="string"){const e=M.indexOf(t.type);if(e!==-1)return M[e]}if(t.profile)return"Service";throw new Error("Resource type is not known")}class L{traversals;options;constructor(e,i={}){this.traversals={collection:[],manifest:[],canvas:[],annotationCollection:[],annotationPage:[],annotation:[],contentResource:[],choice:[],range:[],service:[],agent:[],...e},this.options={allowUndefinedReturn:!1,...i}}static all(e){return new L({collection:[e],manifest:[e],canvas:[e],annotationCollection:[e],annotationPage:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e]})}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=e.thumbnail.map(i=>this.traverseType(i,this.traversals.contentResource))),e.provider&&(e.provider=e.provider.map(i=>this.traverseAgent(i))),e}traverseLinking(e){return e.seeAlso&&(e.seeAlso=e.seeAlso.map(i=>this.traverseType(i,this.traversals.contentResource))),e.service&&(e.service=e.service.map(i=>this.traverseType(i,this.traversals.service))),e.services&&(e.services=e.services.map(i=>this.traverseType(i,this.traversals.service))),e.logo&&(e.logo=e.logo.map(i=>this.traverseType(i,this.traversals.contentResource))),e.homepage&&(e.homepage=e.homepage.map(i=>this.traverseType(i,this.traversals.contentResource))),e.partOf&&(e.partOf=e.partOf.map(i=>typeof i=="string"||!i.type?this.traverseType(i,this.traversals.contentResource):i.type==="Canvas"?this.traverseType(i,this.traversals.canvas):i.type==="AnnotationCollection"?this.traverseType(i,this.traversals.annotationCollection):this.traverseType(i,this.traversals.contentResource))),e.start&&(e.start=e.start?this.traverseType(e.start,this.traversals.canvas):null),e.rendering&&(e.rendering=e.rendering.map(i=>this.traverseType(i,this.traversals.contentResource))),e.supplementary&&(e.supplementary=e.supplementary.map(i=>this.traverseType(i,this.traversals.contentResource))),e}traverseCollectionItems(e){return e.items&&e.items.map(i=>i.type==="Collection"?this.traverseCollection(i):this.traverseManifest(i)),e}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traversePosterCanvas(this.traverseCollectionItems(e))))),this.traversals.collection)}traverseManifestItems(e){return e.items&&(e.items=e.items.map(i=>this.traverseCanvas(i))),e}traverseManifestStructures(e){return e.structures&&(e.structures=e.structures.map(i=>this.traverseRange(i))),e}traverseManifest(e){return this.traverseType(this.traverseInlineAnnotationPages(this.traverseManifestStructures(this.traversePosterCanvas(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e)))))),this.traversals.manifest)}traverseCanvasItems(e){return e.items=(e.items||[]).map(i=>this.traverseAnnotationPage(i)),e}traverseInlineAnnotationPages(e){return typeof e=="string"||!e||e.annotations&&(e.annotations=e.annotations.map(i=>this.traverseAnnotationPage(i))),e}traverseCanvas(e){return this.traverseType(this.traverseInlineAnnotationPages(this.traversePosterCanvas(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))))),this.traversals.canvas)}traverseAnnotationPageItems(e){return e.items&&(e.items=e.items.map(i=>this.traverseAnnotation(i))),e}traverseAnnotationPage(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationPageItems(e))),this.traversals.annotationPage)}traverseAnnotationBody(e){return Array.isArray(e.body)?e.body=e.body.map(i=>this.traverseContentResource(i)):e.body&&(e.body=this.traverseContentResource(e.body)),e}traversePosterCanvas(e){return e.posterCanvas&&(e.posterCanvas=this.traverseType(e.posterCanvas,this.traversals.canvas)),e.placeholderCanvas&&(e.placeholderCanvas=this.traverseType(e.placeholderCanvas,this.traversals.canvas)),e.accompanyingCanvas&&(e.accompanyingCanvas=this.traverseType(e.accompanyingCanvas,this.traversals.canvas)),e}traverseAnnotation(e){return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(e)),this.traversals.annotation)}traverseContentResourceLinking(e){return typeof e=="string"||!e||e&&e.service&&(e.service=(e.service||[]).map(i=>this.traverseType(i,this.traversals.service))),e}traverseContentResource(e){return e.type==="Choice"&&(e.items=e.items.map(i=>this.traverseContentResource(i))),this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)),this.traversals.contentResource)}traverseRangeRanges(e){return e.items&&(e.items=e.items.map(i=>typeof i=="string"?this.traverseCanvas({id:i,type:"Canvas"}):i.type==="Manifest"?this.traverseManifest(i):this.traverseRange(i))),e}traverseRange(e){return this.traverseType(this.traversePosterCanvas(this.traverseDescriptive(this.traverseLinking(this.traverseRangeRanges(e)))),this.traversals.range)}traverseAgent(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.agent)}traverseType(e,i){return i.reduce((n,a)=>{const r=a(n);return typeof r=="undefined"&&!this.options.allowUndefinedReturn?n:r},e)}traverseService(e){return this.traverseType(e,this.traversals.service)}traverseUnknown(e){const i=U(e);switch(i){case"Collection":return this.traverseCollection(e);case"Manifest":return this.traverseManifest(e);case"Canvas":return this.traverseCanvas(e);case"AnnotationPage":return this.traverseAnnotationPage(e);case"Annotation":return this.traverseAnnotation(e);case"ContentResource":return this.traverseContentResource(e);case"Range":return this.traverseRange(e);case"Service":return this.traverseService(e);case"Agent":return this.traverseAgent(e);default:throw new Error(`Unknown or unsupported resource type of ${i}`)}}}const V=["sc:Collection","sc:Manifest","sc:Canvas","oa:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function Ce(t){if(typeof t=="undefined"||t===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(t))throw new Error("Array is not a valid entity");if(typeof t!="object")throw new Error(`${typeof t} is not a valid entity`);if(typeof t["@type"]=="string"){const e=V.indexOf(t["@type"]);if(e!==-1)return V[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}class x{traversals;options;constructor(e,i={}){this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...i}}static all(e){return new x({collection:[e],manifest:[e],canvas:[e],annotationList:[e],sequence:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],layer:[e]})}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))),this.traversals.collection)}traverseCollectionItems(e){if(this.options.mergeMemberProperties){const i=[...(e.manifests||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n),...(e.collections||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n),...e.members||[]];delete e.collections,delete e.manifests,e.members=i}return e.manifests&&(e.manifests=e.manifests.map(i=>this.traverseManifest(typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i))),e.collections&&(e.collections=e.collections.map(i=>this.traverseCollection(typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i))),e.members&&(e.members=e.members.map(i=>typeof i=="string"?i:this.traverseUnknown(i))),e}traverseManifest(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))),this.traversals.manifest)}traverseManifestItems(e){return e.sequences&&(e.sequences=e.sequences.map(i=>this.traverseSequence(i))),e.structures&&(e.structures=e.structures.map(i=>this.traverseRange(i))),e}traverseSequence(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))),this.traversals.sequence)}traverseSequenceItems(e){return e.canvases&&(e.canvases=e.canvases.map(i=>this.traverseCanvas(i))),e}traverseCanvas(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))),this.traversals.canvas)}traverseCanvasItems(e){return e.images&&(e.images=e.images.map(i=>this.traverseAnnotation(i))),e.otherContent&&(e.otherContent=e.otherContent.map(i=>this.traverseAnnotationList(i))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const i=[...(e.ranges||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Range"}:n),...(e.canvases||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Canvas"}:n),...e.members||[]];delete e.ranges,delete e.canvases,e.members=i.length?i.map(n=>this.traverseUnknown(n)):void 0}return e}traverseAnnotationList(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationListItems(e))),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map(i=>this.traverseAnnotation(i))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(e.resource=this.traverseContentResource(e.resource)),e.on,e}traverseLayer(e){return this.traverseType(this.traverseLinking(this.traverseLayerItems(e)),this.traversals.layer)}traverseLayerItems(e){return e.otherContent&&(e.otherContent=e.otherContent.map(i=>this.traverseAnnotationList(i))),e}traverseChoice(e){return this.traverseType(this.traverseChoiceItems(e),this.traversals.choice)}traverseChoiceItems(e){return e.default&&e.default!=="rdf:nil"&&(e.default=this.traverseContentResource(e.default)),e.item&&e.item!=="rdf:nil"&&(e.item=e.item.map(i=>this.traverseContentResource(i))),e}traverseService(e){return this.traverseType(this.traverseLinking(e),this.traversals.service)}traverseContentResource(e){return e["@type"]==="oa:Choice"?this.traverseChoice(e):this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.contentResource)}traverseUnknown(e){if(!e["@type"]||typeof e=="string")return e;switch(Ce(e)){case"sc:Collection":return this.traverseCollection(e);case"sc:Manifest":return this.traverseManifest(e);case"sc:Canvas":return this.traverseCanvas(e);case"sc:Sequence":return this.traverseSequence(e);case"sc:Range":return this.traverseRange(e);case"oa:Annotation":return this.traverseAnnotation(e);case"oa:AnnotationList":return this.traverseAnnotationList(e);case"sc:Layer":return this.traverseLayer(e);case"Service":return this.traverseService(e);case"oa:Choice":return this.traverseChoice(e);case"ContentResource":return this.traverseContentResource(e)}return e.profile?this.traverseService(e):e}traverseImageResource(e){const i=Array.isArray(e),n=Array.isArray(e)?e:[e],a=[];for(const r of n)typeof r=="string"?a.push(this.traverseContentResource({"@id":r,"@type":"dctypes:Image"})):a.push(this.traverseContentResource(r));return!i&&!this.options.convertPropsToArray?a[0]:a}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){const i=Array.isArray(e),n=Array.isArray(e)?e:[e],a=[];for(const r of n)a.push(this.traverseService(r));return!i&&!this.options.convertPropsToArray?a[0]:a}traverseLinking(e){return e.related&&(e.related=this.traverseOneOrManyType(e.related,this.traversals.contentResource)),e.rendering&&(e.rendering=this.traverseOneOrManyType(e.rendering,this.traversals.contentResource)),e.service&&(e.service=this.traverseOneOrMoreServices(e.service)),e.seeAlso&&(e.seeAlso=this.traverseOneOrManyType(e.seeAlso,this.traversals.contentResource)),e.within&&(typeof e.within=="string"||(e.within=this.traverseOneOrManyType(e.within,this.traversals.contentResource))),e.startCanvas&&(typeof e.startCanvas=="string"?e.startCanvas=this.traverseType({"@id":e.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):e.startCanvas&&this.traverseType(e.startCanvas,this.traversals.canvas)),e.contentLayer&&(typeof e.contentLayer=="string"?e.contentLayer=this.traverseLayer({"@id":e.contentLayer,"@type":"sc:Layer"}):e.contentLayer=this.traverseLayer(e.contentLayer)),e}traverseOneOrManyType(e,i){if(!Array.isArray(e))if(this.options.convertPropsToArray)e=[e];else return this.traverseType(e,i);return e.map(n=>this.traverseType(n,i))}traverseType(e,i){return i.reduce((n,a)=>{const r=a(n);return typeof r=="undefined"&&!this.options.allowUndefinedReturn?n:r},e)}}const _e="http://library.stanford.edu/iiif/image-api/compliance.html#level0",W="http://library.stanford.edu/iiif/image-api/compliance.html#level1",z="http://library.stanford.edu/iiif/image-api/compliance.html#level2",be="http://library.stanford.edu/iiif/image-api/conformance.html#level0",H="http://library.stanford.edu/iiif/image-api/conformance.html#level1",B="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Re="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",K="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Q="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Ee="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",X="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Y="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",we="http://iiif.io/api/image/1/level0.json",Le="http://iiif.io/api/image/1/profiles/level0.json",Z="http://iiif.io/api/image/1/level1.json",J="http://iiif.io/api/image/1/profiles/level1.json",ee="http://iiif.io/api/image/1/level2.json",te="http://iiif.io/api/image/1/profiles/level2.json",Te="http://iiif.io/api/image/2/level0.json",Me="http://iiif.io/api/image/2/profiles/level0.json",ie="http://iiif.io/api/image/2/level1.json",ne="http://iiif.io/api/image/2/profiles/level1.json",re="http://iiif.io/api/image/2/level2.json",ae="http://iiif.io/api/image/2/profiles/level2.json",xe="level0",se="level1",oe="level2",Se="http://iiif.io/api/image/2/level0",le="http://iiif.io/api/image/2/level1",ve="http://iiif.io/api/image/2/level2",Oe=[le,ve,W,z,H,B,K,Q,X,Y,Z,J,ee,te,ie,ne,re,ae,se,oe],Pe=[Se,le,ve,_e,W,z,be,H,B,Re,K,Q,Ee,X,Y,we,Le,Z,J,ee,te,Te,Me,ie,ne,re,ae,xe,se,oe],S={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function u(t,e="none"){if(!t)return{};const i=Array.isArray(t)?t:[t],n={};for(const a of i){if(typeof a=="string"){n[e]=n[e]?n[e]:[],n[e].push(a||"");continue}if(!a["@language"]){n[e]=n[e]?n[e]:[],n[e].push(a["@value"]||"");continue}const r=a["@language"];n[r]=n[r]?n[r]:[],n[r].push(a["@value"]||"")}return n}function pe(t){if(Array.isArray(t))return pe(t.find(e=>typeof e=="string"));if(Pe.indexOf(t)!==-1)return"level2";if(Oe.indexOf(t)!==-1)return"level1";if(typeof t=="string")return t}function Fe(t){const e=Array.isArray(t)?t:[t];for(const i of e)switch(i){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function De(t){switch(t){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}function ke(t){return Array.isArray(t)?t:[t]}function Ne(t){for(const e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}function O(t){const e=t["@id"]||t.id;let i=t["@type"]||t.type;const n=t.profile||void 0,a=t["@context"]||void 0;if(n){const r=De(n);if(r)return r}if(a){const r=Fe(a);if(r)return r}if(i){if(Array.isArray(i)){if(i.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(i.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";i=i[0]}for(const r of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${r}:`)){i=i.slice(r.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(t.format){if(t.format.startsWith("image/"))return"Image";if(t.format.startsWith("text/")||t.format==="application/pdf")return"Text";if(t.format.startsWith("application/"))return"Dataset"}return e&&(e.endsWith(".jpg")||e.endsWith(".png")||e.endsWith(".jpeg"))?"Image":i||"unknown"}const je=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Ge(t){const e=t.match(je);return e?e[0]:t}function $e(t,e="Rights/License",i="none"){let n=null;const a=[],r=Array.isArray(t)?t:[t];for(const C of r){const o=C?Ge(C):void 0;if(o&&(o.indexOf("creativecommons.org")!==-1||o.indexOf("rightsstatements.org")!==-1)){o.startsWith("https://")?n=`http://${o.slice(8)}`:n=o;continue}o&&a.push({label:{[i]:[e]},value:{[i]:[o]}})}return[n,a]}const qe=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function Ue(t){if(t){const e=Array.isArray(t)?t:[t],i=[];for(const n of e)n==="http://iiif.io/api/presentation/2/context.json"&&i.push("http://iiif.io/api/presentation/3/context.json"),qe.indexOf(n)===-1&&i.push(n);if(e.length)return i.length===1?i[0]:i}}function Ve(t){return t?t.map(e=>({label:u(e.label),value:u(e.value)})):[]}function v(t){for(const e in t)(typeof t[e]=="undefined"||t[e]===null)&&delete t[e];return t}let he=0;function ce(t,e){const i=encodeURI(t.id||t["@id"]||"").trim();return i&&e?`${i}/${e}`:i||(he++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${he}`)}function p(t){const e=[...t.behavior||[]];return t.viewingHint&&e.push(t.viewingHint),{"@context":t["@context"]?Ue(t["@context"]):void 0,id:(t["@id"]||ce(t)).trim(),type:O(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:t.motivation?Ne(t.motivation):void 0,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function l(t){const[e,i]=$e(t.license),n=[...t.metadata?Ve(t.metadata):[],...i];return{rights:e,metadata:n.length?n:void 0,label:t.label?u(t.label):void 0,requiredStatement:t.attribution?{label:u(S.attributionLabel),value:u(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?u(t.description):void 0,thumbnail:t.thumbnail}}function We(t){if(!t.within)return;const e=Array.isArray(t.within)?t.within:[t.within],i=[];for(const n of e)if(typeof n=="string"){if(n)switch(t["@type"]){case"sc:Manifest":i.push({id:n,type:"Collection"});break}}else n["@id"]&&i.push({id:n["@id"],type:O(n)});return i.length?i:void 0}function h(t){const e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],i=t.contentLayer;return{provider:t.logo||e.length?[{id:S.providerId,type:"Agent",homepage:e.length?[e[0]]:void 0,logo:t.logo?Array.isArray(t.logo)?t.logo:[t.logo]:void 0,label:u(S.providerName)}]:void 0,partOf:We(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?ke(t.service):void 0,supplementary:i?[i]:void 0}}function ze(t){return v({...p(t),...l(t),...h(t),items:t.members})}function He(t){const e=[],i=[];for(const a of t.sequences||[])a.canvases.length&&e.push(...a.canvases),a.behavior&&i.push(...a.behavior);const n=p(t);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),v({...n,...l(t),...h(t),items:e,structures:t.structures})}function Be(t){return v({...p(t),...l(t),...h(t),items:t.images&&t.images.length?[{id:ce(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function Ke(t){return v({...p(t),...l(t),...h(t),items:t.resources})}function Qe(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[]}}function Xe(t){return v({...p(t),...l(t),...h(t),target:typeof t.on=="string"?encodeURI(t.on).trim():t.on,body:t.resource})}function Ye(t){const e=t;return v({...p(e),...l(e),...h(e)})}function Ze(t){const e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),{...p(t),...l(t),items:e}}function Je(t){return v({...p(t),...l(t),...h(t),items:t.members})}function et(t){const{"@id":e,"@type":i,"@context":n,profile:a,...r}=t;return e&&(r.id=e),r.type=O(t),r.type==="unknown"&&(r.type="Service"),a&&(r.profile=pe(a)),v({...r,...l(r)})}function tt(t){return v({...p(t),...l(t),...h(t)})}const it=new x({collection:[ze],manifest:[He],canvas:[Be],annotationList:[Ke],sequence:[Qe],annotation:[Xe],contentResource:[Ye],choice:[Ze],range:[Je],service:[et],layer:[tt]});function nt(t){return t&&t["@context"]&&(t["@context"]==="http://iiif.io/api/presentation/2/context.json"||t["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")!==-1||t["@context"]==="http://www.shared-canvas.org/ns/context.json")||t["@context"]==="http://iiif.io/api/image/2/context.json"?it.traverseUnknown(t):t}const rt={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}};function fe(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}function ue(t,e){if(typeof t=="string")return{id:t,type:e};if(!t.id)throw new Error(`Invalid resource does not have an ID (${e})`);return t}function at(t){return(e,i)=>{const n=t[e]?t[e]:{};return a=>{const r=ue(a,i||e);return r&&r.id&&e?(n[r.id]=n[r.id]?Object.assign({},n[r.id],r):Object.assign({},r),{id:r.id,type:e==="ContentResource"?e:r.type}):r}}}function st(t){return(e,i)=>n=>{const{id:a,type:r}=ue(n,i||e);if(typeof a=="undefined")throw new Error("Found invalid entity without an ID.");return e==="ContentResource"?t[a]=e:t[a]=r,n}}function ot(t){const e=JSON.stringify(t);let i=5381,n=e.length;for(;n;)i=i*33^e.charCodeAt(--n);const r=(i>>>0).toString(16);return r.length%2?"0"+r:r}function P(t){return e=>typeof e=="string"?{id:e,type:t}:e.id?e.type?e:{type:t,...e}:{id:ot(e),type:t,...e}}function _(t){return e=>({...t,...e})}function b(t){return Array.isArray(t)?t:[t]}function lt(t){return t.body&&(t.body=b(t.body)),t.seeAlso&&(t.seeAlso=b(t.seeAlso)),t.body&&(t.body=b(t.body)),t.audience&&(t.audience=b(t.audience)),t.accessibility&&(t.accessibility=b(t.accessibility)),t.motivation&&(t.motivation=b(t.motivation)),t}function vt(t){const e=nt(t),i=fe(),n={},a=at(i),r=st(n),o=new L({collection:[_(j),r("Collection"),a("Collection")],manifest:[_(G),r("Manifest"),a("Manifest")],canvas:[_(N),r("Canvas"),a("Canvas")],annotationPage:[P("AnnotationPage"),_(k),r("AnnotationPage"),a("AnnotationPage")],annotation:[P("Annotation"),lt,r("Annotation"),a("Annotation")],contentResource:[P("ContentResource"),r("ContentResource"),a("ContentResource")],range:[_($),r("Range","Canvas"),a("Range","Canvas")],agent:[_(q),r("Agent"),a("Agent")]}).traverseUnknown(e);return{entities:i,resource:o,mapping:n}}const c="__$UNSET$__",F="__$UNWRAP$__";function pt(t,e){const i=t.requests[e],n=t.mapping[e];if(!(!n||i&&i.resourceUri&&!t.entities[n][i.resourceUri]))return t.entities[n][i?i.resourceUri:e]}function de(t){const e={};for(const[i,n]of t){if(i===F&&n!==c)return n;n!==c&&typeof n!="undefined"&&n!==null&&(e[i]=n)}return e}function ht(t,e,i){if(!e.type||!e.id)throw new Error("Unknown entity");if(!i[e.type])throw new Error(`Serializer not found for ${e.type}`);function n(a){const r=i[a.type];if(!r)return c;const C=pt(t,a.id)||(a.id&&a.type?a:null);if(!C)return c;const o=r(C,t,{isTopLevel:e.id===a.id});let R=o.next();for(;!R.done;){const w=R.value;let T=c;if(w)if(Array.isArray(w)){const D=[];for(const Ae of w)D.push(n(Ae));T=D}else T=n(w);R=o.next(T)}return R.value===c?c:de(R.value)}return n(e)}function d(t){if(!t)return;const e=Object.keys(t);if(e.length!==0){if(e.length===1){const i=e[0];if(!i)return"";const n=(t[i]||[]).join("");return i==="@none"||i==="none"||i==="en"?n:{"@language":i,"@value":n}}return e.map(i=>({"@language":i,"@value":(t[i]||[]).join("")}))}}function me(t){return Array.isArray(t)?t.map(e=>me(e)):typeof t=="string"?t:t.type&&t.type==="Canvas"?t.id:t}function f(t,e=!1){if(!!t)return t.length>1&&!e?t:t[0]||void 0}function ct(t){if(!!t){if(typeof t=="string")return{"@id":t};if("@id"in t){const e={...t};return delete e["@type"],e}return{"@context":"http://iiif.io/api/image/2/context.json","@id":t.id,profile:`http://iiif.io/api/image/2/profiles/${t.profile}.json`}}}function m(t,e){return[["@id",t.id],["@type",e],["format",t.format],["height",t.height],["width",t.width],["viewingDirection",t.viewingDirection!=="left-to-right"?t.viewingDirection:void 0]]}function*g(t){const e=t.provider?yield t.provider[0]:void 0;return[["label",d(t.label)],["metadata",t.metadata&&t.metadata.length?t.metadata.map(i=>({label:d(i.label)||"",value:d(i.value)||""})):void 0],["description",d(t.summary)],["thumbnail",f(yield t.thumbnail)],["navDate",t.navDate],["logo",e?f(e.logo):void 0],["homepage",e?e.homepage:void 0],["attribution",t.requiredStatement?d(t.requiredStatement.value):void 0]]}function*E(t){return[["seeAlso",f(yield t.seeAlso)],["service",f((t.service||[]).map(ct))],["rendering",f(yield t.rendering)],["startCanvas",t.start?t.start.id:void 0]]}const ft={Manifest:function*(t){return[...m(t,"sc:Manifest"),...yield*g(t),...yield*E(t),["sequences",[{"@id":`${t.id}/sequence0`,"@type":"sc:Sequence",canvases:yield t.items}]],["structures",yield t.structures]]},Canvas:function*(t){const i=(yield t.items)[0];return[...m(t,"sc:Canvas"),...yield*g(t),...yield*E(t),["images",i?[i.resources]:void 0],["annotations",t.annotations&&t.annotations.length?f(yield t.annotations):void 0]]},AnnotationPage:function*(t){return[...m(t,"sc:AnnotationList"),...yield*g(t),["resources",t.items&&t.items.length?f(yield t.items):void 0]]},Annotation:function*(t){return[["@id",t.id],["@type","oa:Annotation"],["motivation","sc:painting"],["on",me(t.target)],["resource",f(yield t.body,!0)]]},ContentResource:function*(t){switch(t.type){case"Image":return[...m(t,"dctypes:Image"),...yield*g(t),...yield*E(t)];case"Text":case"Dataset":default:return[...m(t,void 0),...yield*g(t)]}},AnnotationCollection:function*(t){return[["@id",t.id],["@type","sc:Layer"],["label",d(t.label)]]},Collection:function*(t){return[...m(t,"sc:Collection"),...yield*g(t),...yield*E(t),["members",yield*t.items]]},Range:function*(t){const e=[],i=[];if(t.items)for(const n of t.items){const a=yield n;e.push({"@id":n.id,"@type":n.type,label:a?a.label:void 0,within:t.id}),n.type==="Canvas"&&i.push(n.id)}return[...m(t,"sc:Range"),...yield*g(t),...yield*E(t),["canvases",i.length===e.length?i:void 0],["members",i.length!==e.length?e:void 0]]}};function y(t){return[["id",t.id],["type",t.type],["format",t.format],["profile",t.profile],["height",t.height],["width",t.width],["duration",t.duration||void 0],["viewingDirection",t.viewingDirection!=="left-to-right"?t.viewingDirection:void 0],["behavior",t.behavior&&t.behavior.length?t.behavior:void 0],["timeMode",t.timeMode],["motivation",t.motivation]]}function s(t){if(!(!t||t.length===0))return t}function ge(t){if(t&&t.type&&t.type==="ImageService2"){const{id:e,type:i,profile:n,...a}=t;return{"@id":e,"@type":i,profile:n.startsWith("http")?n:`http://iiif.io/api/image/2/${n}.json`,...a}}return t}function ye(t){if(!(!t||t.length===0))return t.map(ge)}function*A(t){return[["label",t.label],["metadata",s(t.metadata)],["summary",t.summary],["requiredStatement",t.requiredStatement],["rights",t.rights],["navDate",t.navDate],["language",t.language],["thumbnail",s(yield t.thumbnail)],["placeholderCanvas",yield t.placeholderCanvas],["accompanyingCanvas",yield t.accompanyingCanvas],["provider",s(yield t.provider)]]}function*I(t){return[["seeAlso",s(yield t.seeAlso)],["service",ye(t.service)],["services",ye(t.services)],["rendering",s(yield t.rendering)],["supplementary",s(yield t.supplementary)],["homepage",s(yield t.homepage)],["logo",s(yield t.logo)],["partOf",s(yield t.partOf)],["start",t.start]]}const ut={Manifest:function*(t,e,{isTopLevel:i}){return i?[["@context","http://iiif.io/api/presentation/3/context.json"],...y(t),...yield*A(t),...yield*I(t),["items",yield t.items],["structures",s(yield t.structures)],["annotations",s(yield t.annotations)]]:[...y(t),...yield*A(t)]},Canvas:function*(t){return[...y(t),...yield*A(t),...yield*I(t),["items",yield t.items],["annotations",s(yield t.annotations)]]},Agent:function*(t){return[["id",t.id],["type","Agent"],["label",t.label],...yield*I(t)]},AnnotationPage:function*(t){return[...Object.entries(t).map(([i,n])=>[i,Array.isArray(n)?s(n):n]).filter(([i,n])=>i!=="items"),...yield*I(t),["items",yield t.items]]},Service:function*(t){return[[F,ge(t)]]},Annotation:function*(t){return[...Object.entries(t).map(([i,n])=>[i,Array.isArray(n)?s(n):n]).filter(([i])=>i!=="body"),["body",yield t.body]]},ContentResource:function*(t){return[...y(t),...yield*A(t),...yield*I(t),["annotations",s(yield t.annotations)]]},AnnotationCollection:function*(t){return[["id",t.id],["type","AnnotationCollection"],["label",t.label]]},Collection:function*(t,e,{isTopLevel:i}){return i?[["@context","http://iiif.io/api/presentation/3/context.json"],...y(t),...yield*A(t),...yield*I(t),["items",s(yield t.items)]]:[...y(t),...yield*A(t)]},Range:function*(t){const e=[];for(const i of t.items)i.type==="Range"?e.push(yield i):e.push(i);return[...y(t),...yield*A(t),...yield*I(t),["items",e],["annotations",s(yield t.annotations)]]}};export{L as Traverse,c as UNSET,F as UNWRAP,rt as defaultEntities,q as emptyAgent,Ie as emptyAnnotation,k as emptyAnnotationPage,N as emptyCanvas,j as emptyCollection,G as emptyManifest,$ as emptyRange,fe as getDefaultEntities,U as identifyResource,d as languageString2to3,vt as normalize,ht as serialize,ft as serializeConfigPresentation2,ut as serializeConfigPresentation3,de as serializedFieldsToObject,M as types};
const Ce={id:"https://iiif-parser/annotation",type:"Annotation",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[],accessibility:[],audience:[],body:[],bodyValue:null,canonical:null,created:null,creator:[],generated:null,generator:[],modified:null,motivation:[],rights:[],stylesheet:null,target:[],timeMode:void 0,via:[],partOf:[]},k={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:[],motivation:null,label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[]},N={id:"https://iiif-parser/empty-canvas",type:"Canvas",label:null,behavior:[],motivation:null,thumbnail:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:[],rights:null,navDate:null,provider:[],items:[],annotations:[],seeAlso:[],homepage:[],logo:[],partOf:[],rendering:[],service:[],duration:0,height:0,width:0},j={id:"https://iiif-parser/empty-collection",type:"Collection",label:null,viewingDirection:"left-to-right",behavior:[],motivation:null,thumbnail:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:[],rights:null,navDate:null,provider:[],items:[],annotations:[],seeAlso:[],homepage:[],logo:[],partOf:[],rendering:[],service:[],services:[]},G={id:"https://iiif-parser/empty-manifest",type:"Manifest",annotations:[],behavior:[],homepage:[],items:[],label:null,logo:[],metadata:[],motivation:null,navDate:null,provider:[],partOf:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,rendering:[],requiredStatement:null,rights:null,seeAlso:[],service:[],services:[],start:null,structures:[],summary:null,thumbnail:[],viewingDirection:"left-to-right"},$={id:"https://iiif-parser/empty-canvas",type:"Range",label:null,behavior:[],motivation:null,thumbnail:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:[],rights:null,navDate:null,provider:[],items:[],annotations:[],seeAlso:[],homepage:[],logo:[],partOf:[],rendering:[],service:[],start:null,supplementary:null,viewingDirection:"left-to-right"},q={id:"https://iiif-parser/empty-agent",type:"Agent",label:{},logo:[],seeAlso:[],homepage:[]},M=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function U(t){if(typeof t=="undefined"||t===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(t))throw new Error("Array is not a valid entity");if(typeof t!="object")throw new Error(`${typeof t} is not a valid entity`);if(typeof t.type=="string"){const e=M.indexOf(t.type);if(e!==-1)return M[e]}if(t.profile)return"Service";throw new Error("Resource type is not known")}class L{traversals;options;constructor(e,i={}){this.traversals={collection:[],manifest:[],canvas:[],annotationCollection:[],annotationPage:[],annotation:[],contentResource:[],choice:[],range:[],service:[],agent:[],...e},this.options={allowUndefinedReturn:!1,...i}}static all(e){return new L({collection:[e],manifest:[e],canvas:[e],annotationCollection:[e],annotationPage:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e]})}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=e.thumbnail.map(i=>this.traverseType(i,this.traversals.contentResource))),e.provider&&(e.provider=e.provider.map(i=>this.traverseAgent(i))),e}traverseLinking(e){return e.seeAlso&&(e.seeAlso=e.seeAlso.map(i=>this.traverseType(i,this.traversals.contentResource))),e.service&&(e.service=e.service.map(i=>this.traverseType(i,this.traversals.service))),e.services&&(e.services=e.services.map(i=>this.traverseType(i,this.traversals.service))),e.logo&&(e.logo=e.logo.map(i=>this.traverseType(i,this.traversals.contentResource))),e.homepage&&(e.homepage=e.homepage.map(i=>this.traverseType(i,this.traversals.contentResource))),e.partOf&&(e.partOf=e.partOf.map(i=>typeof i=="string"||!i.type?this.traverseType(i,this.traversals.contentResource):i.type==="Canvas"?this.traverseType(i,this.traversals.canvas):i.type==="AnnotationCollection"?this.traverseType(i,this.traversals.annotationCollection):this.traverseType(i,this.traversals.contentResource))),e.start&&(e.start=e.start?this.traverseType(e.start,this.traversals.canvas):null),e.rendering&&(e.rendering=e.rendering.map(i=>this.traverseType(i,this.traversals.contentResource))),e.supplementary&&(e.supplementary=e.supplementary.map(i=>this.traverseType(i,this.traversals.contentResource))),e}traverseCollectionItems(e){return e.items&&e.items.map(i=>i.type==="Collection"?this.traverseCollection(i):this.traverseManifest(i)),e}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traversePosterCanvas(this.traverseCollectionItems(e))))),this.traversals.collection)}traverseManifestItems(e){return e.items&&(e.items=e.items.map(i=>this.traverseCanvas(i))),e}traverseManifestStructures(e){return e.structures&&(e.structures=e.structures.map(i=>this.traverseRange(i))),e}traverseManifest(e){return this.traverseType(this.traverseInlineAnnotationPages(this.traverseManifestStructures(this.traversePosterCanvas(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e)))))),this.traversals.manifest)}traverseCanvasItems(e){return e.items=(e.items||[]).map(i=>this.traverseAnnotationPage(i)),e}traverseInlineAnnotationPages(e){return typeof e=="string"||!e||e.annotations&&(e.annotations=e.annotations.map(i=>this.traverseAnnotationPage(i))),e}traverseCanvas(e){return this.traverseType(this.traverseInlineAnnotationPages(this.traversePosterCanvas(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))))),this.traversals.canvas)}traverseAnnotationPageItems(e){return e.items&&(e.items=e.items.map(i=>this.traverseAnnotation(i))),e}traverseAnnotationPage(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationPageItems(e))),this.traversals.annotationPage)}traverseAnnotationBody(e){return Array.isArray(e.body)?e.body=e.body.map(i=>this.traverseContentResource(i)):e.body&&(e.body=this.traverseContentResource(e.body)),e}traversePosterCanvas(e){return e.posterCanvas&&(e.posterCanvas=this.traverseType(e.posterCanvas,this.traversals.canvas)),e.placeholderCanvas&&(e.placeholderCanvas=this.traverseType(e.placeholderCanvas,this.traversals.canvas)),e.accompanyingCanvas&&(e.accompanyingCanvas=this.traverseType(e.accompanyingCanvas,this.traversals.canvas)),e}traverseAnnotation(e){return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(e)),this.traversals.annotation)}traverseContentResourceLinking(e){return typeof e=="string"||!e||e&&e.service&&(e.service=(e.service||[]).map(i=>this.traverseType(i,this.traversals.service))),e}traverseContentResource(e){return e.type==="Choice"&&(e.items=e.items.map(i=>this.traverseContentResource(i))),this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)),this.traversals.contentResource)}traverseRangeRanges(e){return e.items&&(e.items=e.items.map(i=>typeof i=="string"?this.traverseCanvas({id:i,type:"Canvas"}):i.type==="Manifest"?this.traverseManifest(i):this.traverseRange(i))),e}traverseRange(e){return this.traverseType(this.traversePosterCanvas(this.traverseDescriptive(this.traverseLinking(this.traverseRangeRanges(e)))),this.traversals.range)}traverseAgent(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.agent)}traverseType(e,i){return i.reduce((n,a)=>{const r=a(n);return typeof r=="undefined"&&!this.options.allowUndefinedReturn?n:r},e)}traverseService(e){return this.traverseType(e,this.traversals.service)}traverseUnknown(e){const i=U(e);switch(i){case"Collection":return this.traverseCollection(e);case"Manifest":return this.traverseManifest(e);case"Canvas":return this.traverseCanvas(e);case"AnnotationPage":return this.traverseAnnotationPage(e);case"Annotation":return this.traverseAnnotation(e);case"ContentResource":return this.traverseContentResource(e);case"Range":return this.traverseRange(e);case"Service":return this.traverseService(e);case"Agent":return this.traverseAgent(e);default:throw new Error(`Unknown or unsupported resource type of ${i}`)}}}const V=["sc:Collection","sc:Manifest","sc:Canvas","oa:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function Ie(t){if(typeof t=="undefined"||t===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(t))throw new Error("Array is not a valid entity");if(typeof t!="object")throw new Error(`${typeof t} is not a valid entity`);if(typeof t["@type"]=="string"){const e=V.indexOf(t["@type"]);if(e!==-1)return V[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}class x{traversals;options;constructor(e,i={}){this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...i}}static all(e){return new x({collection:[e],manifest:[e],canvas:[e],annotationList:[e],sequence:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],layer:[e]})}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))),this.traversals.collection)}traverseCollectionItems(e){if(this.options.mergeMemberProperties){const i=[...(e.manifests||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n),...(e.collections||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n),...e.members||[]];delete e.collections,delete e.manifests,e.members=i}return e.manifests&&(e.manifests=e.manifests.map(i=>this.traverseManifest(typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i))),e.collections&&(e.collections=e.collections.map(i=>this.traverseCollection(typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i))),e.members&&(e.members=e.members.map(i=>typeof i=="string"?i:this.traverseUnknown(i))),e}traverseManifest(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))),this.traversals.manifest)}traverseManifestItems(e){return e.sequences&&(e.sequences=e.sequences.map(i=>this.traverseSequence(i))),e.structures&&(e.structures=e.structures.map(i=>this.traverseRange(i))),e}traverseSequence(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))),this.traversals.sequence)}traverseSequenceItems(e){return e.canvases&&(e.canvases=e.canvases.map(i=>this.traverseCanvas(i))),e}traverseCanvas(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))),this.traversals.canvas)}traverseCanvasItems(e){return e.images&&(e.images=e.images.map(i=>this.traverseAnnotation(i))),e.otherContent&&(e.otherContent=e.otherContent.map(i=>this.traverseAnnotationList(i))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const i=[...(e.ranges||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Range"}:n),...(e.canvases||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Canvas"}:n),...e.members||[]];delete e.ranges,delete e.canvases,e.members=i.length?i.map(n=>this.traverseUnknown(n)):void 0}return e}traverseAnnotationList(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationListItems(e))),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map(i=>this.traverseAnnotation(i))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(e.resource=this.traverseContentResource(e.resource)),e.on,e}traverseLayer(e){return this.traverseType(this.traverseLinking(this.traverseLayerItems(e)),this.traversals.layer)}traverseLayerItems(e){return e.otherContent&&(e.otherContent=e.otherContent.map(i=>this.traverseAnnotationList(i))),e}traverseChoice(e){return this.traverseType(this.traverseChoiceItems(e),this.traversals.choice)}traverseChoiceItems(e){return e.default&&e.default!=="rdf:nil"&&(e.default=this.traverseContentResource(e.default)),e.item&&e.item!=="rdf:nil"&&(e.item=e.item.map(i=>this.traverseContentResource(i))),e}traverseService(e){return this.traverseType(this.traverseLinking(e),this.traversals.service)}traverseContentResource(e){return e["@type"]==="oa:Choice"?this.traverseChoice(e):this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.contentResource)}traverseUnknown(e){if(!e["@type"]||typeof e=="string")return e;switch(Ie(e)){case"sc:Collection":return this.traverseCollection(e);case"sc:Manifest":return this.traverseManifest(e);case"sc:Canvas":return this.traverseCanvas(e);case"sc:Sequence":return this.traverseSequence(e);case"sc:Range":return this.traverseRange(e);case"oa:Annotation":return this.traverseAnnotation(e);case"oa:AnnotationList":return this.traverseAnnotationList(e);case"sc:Layer":return this.traverseLayer(e);case"Service":return this.traverseService(e);case"oa:Choice":return this.traverseChoice(e);case"ContentResource":return this.traverseContentResource(e)}return e.profile?this.traverseService(e):e}traverseImageResource(e){const i=Array.isArray(e),n=Array.isArray(e)?e:[e],a=[];for(const r of n)typeof r=="string"?a.push(this.traverseContentResource({"@id":r,"@type":"dctypes:Image"})):a.push(this.traverseContentResource(r));return!i&&!this.options.convertPropsToArray?a[0]:a}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){const i=Array.isArray(e),n=Array.isArray(e)?e:[e],a=[];for(const r of n)a.push(this.traverseService(r));return!i&&!this.options.convertPropsToArray?a[0]:a}traverseLinking(e){return e.related&&(e.related=this.traverseOneOrManyType(e.related,this.traversals.contentResource)),e.rendering&&(e.rendering=this.traverseOneOrManyType(e.rendering,this.traversals.contentResource)),e.service&&(e.service=this.traverseOneOrMoreServices(e.service)),e.seeAlso&&(e.seeAlso=this.traverseOneOrManyType(e.seeAlso,this.traversals.contentResource)),e.within&&(typeof e.within=="string"||(e.within=this.traverseOneOrManyType(e.within,this.traversals.contentResource))),e.startCanvas&&(typeof e.startCanvas=="string"?e.startCanvas=this.traverseType({"@id":e.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):e.startCanvas&&this.traverseType(e.startCanvas,this.traversals.canvas)),e.contentLayer&&(typeof e.contentLayer=="string"?e.contentLayer=this.traverseLayer({"@id":e.contentLayer,"@type":"sc:Layer"}):e.contentLayer=this.traverseLayer(e.contentLayer)),e}traverseOneOrManyType(e,i){if(!Array.isArray(e))if(this.options.convertPropsToArray)e=[e];else return this.traverseType(e,i);return e.map(n=>this.traverseType(n,i))}traverseType(e,i){return i.reduce((n,a)=>{const r=a(n);return typeof r=="undefined"&&!this.options.allowUndefinedReturn?n:r},e)}}const _e="http://library.stanford.edu/iiif/image-api/compliance.html#level0",W="http://library.stanford.edu/iiif/image-api/compliance.html#level1",z="http://library.stanford.edu/iiif/image-api/compliance.html#level2",be="http://library.stanford.edu/iiif/image-api/conformance.html#level0",H="http://library.stanford.edu/iiif/image-api/conformance.html#level1",B="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Re="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",K="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Q="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",we="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",X="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Y="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Ee="http://iiif.io/api/image/1/level0.json",Le="http://iiif.io/api/image/1/profiles/level0.json",Z="http://iiif.io/api/image/1/level1.json",J="http://iiif.io/api/image/1/profiles/level1.json",ee="http://iiif.io/api/image/1/level2.json",te="http://iiif.io/api/image/1/profiles/level2.json",Te="http://iiif.io/api/image/2/level0.json",Me="http://iiif.io/api/image/2/profiles/level0.json",ie="http://iiif.io/api/image/2/level1.json",ne="http://iiif.io/api/image/2/profiles/level1.json",re="http://iiif.io/api/image/2/level2.json",ae="http://iiif.io/api/image/2/profiles/level2.json",xe="level0",se="level1",oe="level2",Se="http://iiif.io/api/image/2/level0",le="http://iiif.io/api/image/2/level1",ve="http://iiif.io/api/image/2/level2",Oe=[le,ve,W,z,H,B,K,Q,X,Y,Z,J,ee,te,ie,ne,re,ae,se,oe],Pe=[Se,le,ve,_e,W,z,be,H,B,Re,K,Q,we,X,Y,Ee,Le,Z,J,ee,te,Te,Me,ie,ne,re,ae,xe,se,oe],S={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function u(t,e="none"){if(!t)return{};const i=Array.isArray(t)?t:[t],n={};for(const a of i){if(typeof a=="string"){n[e]=n[e]?n[e]:[],n[e].push(a||"");continue}if(!a["@language"]){n[e]=n[e]?n[e]:[],n[e].push(a["@value"]||"");continue}const r=a["@language"];n[r]=n[r]?n[r]:[],n[r].push(a["@value"]||"")}return n}function pe(t){if(Array.isArray(t))return pe(t.find(e=>typeof e=="string"));if(Pe.indexOf(t)!==-1)return"level2";if(Oe.indexOf(t)!==-1)return"level1";if(typeof t=="string")return t}function Fe(t){const e=Array.isArray(t)?t:[t];for(const i of e)switch(i){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function De(t){switch(t){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}function ke(t){return Array.isArray(t)?t:[t]}function Ne(t){for(const e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}const je=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function O(t){const e=t["@id"]||t.id;let i=t["@type"]||t.type;const n=t.profile||void 0,a=t["@context"]||void 0;if(n){const r=De(n);if(r)return r}if(a){const r=Fe(a);if(r)return r}if(i){if(Array.isArray(i)){if(i.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(i.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";i=i[0]}for(const r of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${r}:`)){i=i.slice(r.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(i&&je.indexOf(i)!==-1)return i;if(t.format){if(t.format.startsWith("image/"))return"Image";if(t.format.startsWith("text/")||t.format==="application/pdf")return"Text";if(t.format.startsWith("application/"))return"Dataset"}return e&&(e.endsWith(".jpg")||e.endsWith(".png")||e.endsWith(".jpeg"))?"Image":i||"unknown"}const Ge=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function $e(t){const e=t.match(Ge);return e?e[0]:t}function qe(t,e="Rights/License",i="none"){let n=null;const a=[],r=Array.isArray(t)?t:[t];for(const I of r){const o=I?$e(I):void 0;if(o&&(o.indexOf("creativecommons.org")!==-1||o.indexOf("rightsstatements.org")!==-1)){o.startsWith("https://")?n=`http://${o.slice(8)}`:n=o;continue}o&&a.push({label:{[i]:[e]},value:{[i]:[o]}})}return[n,a]}const Ue=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function Ve(t){if(t){const e=Array.isArray(t)?t:[t],i=[];for(const n of e)n==="http://iiif.io/api/presentation/2/context.json"&&i.push("http://iiif.io/api/presentation/3/context.json"),Ue.indexOf(n)===-1&&i.push(n);if(e.length)return i.length===1?i[0]:i}}function We(t){return t?t.map(e=>({label:u(e.label),value:u(e.value)})):[]}function v(t){for(const e in t)(typeof t[e]=="undefined"||t[e]===null)&&delete t[e];return t}let he=0;function ce(t,e){const i=encodeURI(t.id||t["@id"]||"").trim();return i&&e?`${i}/${e}`:i||(he++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${he}`)}function p(t){const e=[...t.behavior||[]];return t.viewingHint&&e.push(t.viewingHint),{"@context":t["@context"]?Ve(t["@context"]):void 0,id:(t["@id"]||ce(t)).trim(),type:O(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:t.motivation?Ne(t.motivation):void 0,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function l(t){const[e,i]=qe(t.license),n=[...t.metadata?We(t.metadata):[],...i];return{rights:e,metadata:n.length?n:void 0,label:t.label?u(t.label):void 0,requiredStatement:t.attribution?{label:u(S.attributionLabel),value:u(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?u(t.description):void 0,thumbnail:t.thumbnail}}function ze(t){if(!t.within)return;const e=Array.isArray(t.within)?t.within:[t.within],i=[];for(const n of e)if(typeof n=="string"){if(n)switch(t["@type"]){case"sc:Manifest":i.push({id:n,type:"Collection"});break}}else n["@id"]&&i.push({id:n["@id"],type:O(n)});return i.length?i:void 0}function h(t){const e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],i=t.contentLayer;return{provider:t.logo||e.length?[{id:S.providerId,type:"Agent",homepage:e.length?[e[0]]:void 0,logo:t.logo?Array.isArray(t.logo)?t.logo:[t.logo]:void 0,label:u(S.providerName)}]:void 0,partOf:ze(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?ke(t.service):void 0,supplementary:i?[i]:void 0}}function He(t){return v({...p(t),...l(t),...h(t),items:t.members})}function Be(t){const e=[],i=[];for(const a of t.sequences||[])a.canvases.length&&e.push(...a.canvases),a.behavior&&i.push(...a.behavior);const n=p(t);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),v({...n,...l(t),...h(t),items:e,structures:t.structures})}function Ke(t){return v({...p(t),...l(t),...h(t),items:t.images&&t.images.length?[{id:ce(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function Qe(t){return v({...p(t),...l(t),...h(t),items:t.resources})}function Xe(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[]}}function Ye(t){return v({...p(t),...l(t),...h(t),target:typeof t.on=="string"?encodeURI(t.on).trim():t.on,body:t.resource})}function Ze(t){const e=t;return v({...p(e),...l(e),...h(e)})}function Je(t){const e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),{...p(t),...l(t),items:e}}function et(t){return v({...p(t),...l(t),...h(t),items:t.members})}function tt(t){const{"@id":e,"@type":i,"@context":n,profile:a,...r}=t;return e&&(r.id=e),r.type=O(t),r.type==="unknown"&&(r.type="Service"),a&&(r.profile=pe(a)),v({...r,...l(r)})}function it(t){return v({...p(t),...l(t),...h(t)})}const nt=new x({collection:[He],manifest:[Be],canvas:[Ke],annotationList:[Qe],sequence:[Xe],annotation:[Ye],contentResource:[Ze],choice:[Je],range:[et],service:[tt],layer:[it]});function rt(t){return t&&t["@context"]&&(t["@context"]==="http://iiif.io/api/presentation/2/context.json"||t["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")!==-1||t["@context"]==="http://www.shared-canvas.org/ns/context.json")||t["@context"]==="http://iiif.io/api/image/2/context.json"?nt.traverseUnknown(t):t}const at={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}};function fe(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}function ue(t,e){if(typeof t=="string")return{id:t,type:e};if(!t.id)throw new Error(`Invalid resource does not have an ID (${e})`);return t}function st(t){return(e,i)=>{const n=t[e]?t[e]:{};return a=>{const r=ue(a,i||e);return r&&r.id&&e?(n[r.id]=n[r.id]?Object.assign({},n[r.id],r):Object.assign({},r),{id:r.id,type:e==="ContentResource"?e:r.type}):r}}}function ot(t){return(e,i)=>n=>{const{id:a,type:r}=ue(n,i||e);if(typeof a=="undefined")throw new Error("Found invalid entity without an ID.");return e==="ContentResource"?t[a]=e:t[a]=r,n}}function lt(t){const e=JSON.stringify(t);let i=5381,n=e.length;for(;n;)i=i*33^e.charCodeAt(--n);const r=(i>>>0).toString(16);return r.length%2?"0"+r:r}function P(t){return e=>typeof e=="string"?{id:e,type:t}:e.id?e.type?e:{type:t,...e}:{id:lt(e),type:t,...e}}function _(t){return e=>({...t,...e})}function b(t){return Array.isArray(t)?t:[t]}function vt(t){return t.body&&(t.body=b(t.body)),t.seeAlso&&(t.seeAlso=b(t.seeAlso)),t.body&&(t.body=b(t.body)),t.audience&&(t.audience=b(t.audience)),t.accessibility&&(t.accessibility=b(t.accessibility)),t.motivation&&(t.motivation=b(t.motivation)),t}function pt(t){const e=rt(t),i=fe(),n={},a=st(i),r=ot(n),o=new L({collection:[_(j),r("Collection"),a("Collection")],manifest:[_(G),r("Manifest"),a("Manifest")],canvas:[_(N),r("Canvas"),a("Canvas")],annotationPage:[P("AnnotationPage"),_(k),r("AnnotationPage"),a("AnnotationPage")],annotation:[P("Annotation"),vt,r("Annotation"),a("Annotation")],contentResource:[P("ContentResource"),r("ContentResource"),a("ContentResource")],range:[_($),r("Range","Canvas"),a("Range","Canvas")],agent:[_(q),r("Agent"),a("Agent")]}).traverseUnknown(e);return{entities:i,resource:o,mapping:n}}const c="__$UNSET$__",F="__$UNWRAP$__";function ht(t,e){const i=t.requests[e],n=t.mapping[e];if(!(!n||i&&i.resourceUri&&!t.entities[n][i.resourceUri]))return t.entities[n][i?i.resourceUri:e]}function de(t){const e={};for(const[i,n]of t){if(i===F&&n!==c)return n;n!==c&&typeof n!="undefined"&&n!==null&&(e[i]=n)}return e}function ct(t,e,i){if(!e.type||!e.id)throw new Error("Unknown entity");if(!i[e.type])throw new Error(`Serializer not found for ${e.type}`);function n(a){const r=i[a.type];if(!r)return c;const I=ht(t,a.id)||(a.id&&a.type?a:null);if(!I)return c;const o=r(I,t,{isTopLevel:e.id===a.id});let R=o.next();for(;!R.done;){const E=R.value;let T=c;if(E)if(Array.isArray(E)){const D=[];for(const Ae of E)D.push(n(Ae));T=D}else T=n(E);R=o.next(T)}return R.value===c?c:de(R.value)}return n(e)}function d(t){if(!t)return;const e=Object.keys(t);if(e.length!==0){if(e.length===1){const i=e[0];if(!i)return"";const n=(t[i]||[]).join("");return i==="@none"||i==="none"||i==="en"?n:{"@language":i,"@value":n}}return e.map(i=>({"@language":i,"@value":(t[i]||[]).join("")}))}}function me(t){return Array.isArray(t)?t.map(e=>me(e)):typeof t=="string"?t:t.type&&t.type==="Canvas"?t.id:t}function f(t,e=!1){if(!!t)return t.length>1&&!e?t:t[0]||void 0}function ft(t){if(!!t){if(typeof t=="string")return{"@id":t};if("@id"in t){const e={...t};return delete e["@type"],e}return{"@context":"http://iiif.io/api/image/2/context.json","@id":t.id,profile:`http://iiif.io/api/image/2/profiles/${t.profile}.json`}}}function m(t,e){return[["@id",t.id],["@type",e],["format",t.format],["height",t.height],["width",t.width],["viewingDirection",t.viewingDirection!=="left-to-right"?t.viewingDirection:void 0]]}function*g(t){const e=t.provider?yield t.provider[0]:void 0;return[["label",d(t.label)],["metadata",t.metadata&&t.metadata.length?t.metadata.map(i=>({label:d(i.label)||"",value:d(i.value)||""})):void 0],["description",d(t.summary)],["thumbnail",f(yield t.thumbnail)],["navDate",t.navDate],["logo",e?f(e.logo):void 0],["homepage",e?e.homepage:void 0],["attribution",t.requiredStatement?d(t.requiredStatement.value):void 0]]}function*w(t){return[["seeAlso",f(yield t.seeAlso)],["service",f((t.service||[]).map(ft))],["rendering",f(yield t.rendering)],["startCanvas",t.start?t.start.id:void 0]]}const ut={Manifest:function*(t){return[...m(t,"sc:Manifest"),...yield*g(t),...yield*w(t),["sequences",[{"@id":`${t.id}/sequence0`,"@type":"sc:Sequence",canvases:yield t.items}]],["structures",yield t.structures]]},Canvas:function*(t){const i=(yield t.items)[0];return[...m(t,"sc:Canvas"),...yield*g(t),...yield*w(t),["images",i?[i.resources]:void 0],["annotations",t.annotations&&t.annotations.length?f(yield t.annotations):void 0]]},AnnotationPage:function*(t){return[...m(t,"sc:AnnotationList"),...yield*g(t),["resources",t.items&&t.items.length?f(yield t.items):void 0]]},Annotation:function*(t){return[["@id",t.id],["@type","oa:Annotation"],["motivation","sc:painting"],["on",me(t.target)],["resource",f(yield t.body,!0)]]},ContentResource:function*(t){switch(t.type){case"Image":return[...m(t,"dctypes:Image"),...yield*g(t),...yield*w(t)];case"Text":case"Dataset":default:return[...m(t,void 0),...yield*g(t)]}},AnnotationCollection:function*(t){return[["@id",t.id],["@type","sc:Layer"],["label",d(t.label)]]},Collection:function*(t){return[...m(t,"sc:Collection"),...yield*g(t),...yield*w(t),["members",yield*t.items]]},Range:function*(t){const e=[],i=[];if(t.items)for(const n of t.items){const a=yield n;e.push({"@id":n.id,"@type":n.type,label:a?a.label:void 0,within:t.id}),n.type==="Canvas"&&i.push(n.id)}return[...m(t,"sc:Range"),...yield*g(t),...yield*w(t),["canvases",i.length===e.length?i:void 0],["members",i.length!==e.length?e:void 0]]}};function y(t){return[["id",t.id],["type",t.type],["format",t.format],["profile",t.profile],["height",t.height],["width",t.width],["duration",t.duration||void 0],["viewingDirection",t.viewingDirection!=="left-to-right"?t.viewingDirection:void 0],["behavior",t.behavior&&t.behavior.length?t.behavior:void 0],["timeMode",t.timeMode],["motivation",t.motivation]]}function s(t){if(!(!t||t.length===0))return t}function ge(t){if(t&&t.type&&t.type==="ImageService2"){const{id:e,type:i,profile:n,...a}=t;return{"@id":e,"@type":i,profile:n.startsWith("http")?n:`http://iiif.io/api/image/2/${n}.json`,...a}}return t}function ye(t){if(!(!t||t.length===0))return t.map(ge)}function*A(t){return[["label",t.label],["metadata",s(t.metadata)],["summary",t.summary],["requiredStatement",t.requiredStatement],["rights",t.rights],["navDate",t.navDate],["language",t.language],["thumbnail",s(yield t.thumbnail)],["placeholderCanvas",yield t.placeholderCanvas],["accompanyingCanvas",yield t.accompanyingCanvas],["provider",s(yield t.provider)]]}function*C(t){return[["seeAlso",s(yield t.seeAlso)],["service",ye(t.service)],["services",ye(t.services)],["rendering",s(yield t.rendering)],["supplementary",s(yield t.supplementary)],["homepage",s(yield t.homepage)],["logo",s(yield t.logo)],["partOf",s(yield t.partOf)],["start",t.start]]}const dt={Manifest:function*(t,e,{isTopLevel:i}){return i?[["@context","http://iiif.io/api/presentation/3/context.json"],...y(t),...yield*A(t),...yield*C(t),["items",yield t.items],["structures",s(yield t.structures)],["annotations",s(yield t.annotations)]]:[...y(t),...yield*A(t)]},Canvas:function*(t){return[...y(t),...yield*A(t),...yield*C(t),["items",yield t.items],["annotations",s(yield t.annotations)]]},Agent:function*(t){return[["id",t.id],["type","Agent"],["label",t.label],...yield*C(t)]},AnnotationPage:function*(t){return[...Object.entries(t).map(([i,n])=>[i,Array.isArray(n)?s(n):n]).filter(([i,n])=>i!=="items"),...yield*C(t),["items",yield t.items]]},Service:function*(t){return[[F,ge(t)]]},Annotation:function*(t){return[...Object.entries(t).map(([i,n])=>[i,Array.isArray(n)?s(n):n]).filter(([i])=>i!=="body"),["body",yield t.body]]},ContentResource:function*(t){return[...y(t),...yield*A(t),...yield*C(t),["annotations",s(yield t.annotations)]]},AnnotationCollection:function*(t){return[["id",t.id],["type","AnnotationCollection"],["label",t.label]]},Collection:function*(t,e,{isTopLevel:i}){return i?[["@context","http://iiif.io/api/presentation/3/context.json"],...y(t),...yield*A(t),...yield*C(t),["items",s(yield t.items)]]:[...y(t),...yield*A(t)]},Range:function*(t){const e=[];for(const i of t.items)i.type==="Range"?e.push(yield i):e.push(i);return[...y(t),...yield*A(t),...yield*C(t),["items",e],["annotations",s(yield t.annotations)]]}};export{L as Traverse,c as UNSET,F as UNWRAP,at as defaultEntities,q as emptyAgent,Ce as emptyAnnotation,k as emptyAnnotationPage,N as emptyCanvas,j as emptyCollection,G as emptyManifest,$ as emptyRange,fe as getDefaultEntities,U as identifyResource,d as languageString2to3,pt as normalize,ct as serialize,ut as serializeConfigPresentation2,dt as serializeConfigPresentation3,de as serializedFieldsToObject,M as types};

@@ -1,1 +0,1 @@

(function(d,_){typeof exports=="object"&&typeof module!="undefined"?module.exports=_():typeof define=="function"&&define.amd?define(_):(d=typeof globalThis!="undefined"?globalThis:d||self,d.IIIFParser=_())})(this,function(){"use strict";const d=["sc:Collection","sc:Manifest","sc:Canvas","oa:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function _(t){if(typeof t=="undefined"||t===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(t))throw new Error("Array is not a valid entity");if(typeof t!="object")throw new Error(`${typeof t} is not a valid entity`);if(typeof t["@type"]=="string"){const e=d.indexOf(t["@type"]);if(e!==-1)return d[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}class T{traversals;options;constructor(e,i={}){this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...i}}static all(e){return new T({collection:[e],manifest:[e],canvas:[e],annotationList:[e],sequence:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],layer:[e]})}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))),this.traversals.collection)}traverseCollectionItems(e){if(this.options.mergeMemberProperties){const i=[...(e.manifests||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n),...(e.collections||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n),...e.members||[]];delete e.collections,delete e.manifests,e.members=i}return e.manifests&&(e.manifests=e.manifests.map(i=>this.traverseManifest(typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i))),e.collections&&(e.collections=e.collections.map(i=>this.traverseCollection(typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i))),e.members&&(e.members=e.members.map(i=>typeof i=="string"?i:this.traverseUnknown(i))),e}traverseManifest(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))),this.traversals.manifest)}traverseManifestItems(e){return e.sequences&&(e.sequences=e.sequences.map(i=>this.traverseSequence(i))),e.structures&&(e.structures=e.structures.map(i=>this.traverseRange(i))),e}traverseSequence(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))),this.traversals.sequence)}traverseSequenceItems(e){return e.canvases&&(e.canvases=e.canvases.map(i=>this.traverseCanvas(i))),e}traverseCanvas(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))),this.traversals.canvas)}traverseCanvasItems(e){return e.images&&(e.images=e.images.map(i=>this.traverseAnnotation(i))),e.otherContent&&(e.otherContent=e.otherContent.map(i=>this.traverseAnnotationList(i))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const i=[...(e.ranges||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Range"}:n),...(e.canvases||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Canvas"}:n),...e.members||[]];delete e.ranges,delete e.canvases,e.members=i.length?i.map(n=>this.traverseUnknown(n)):void 0}return e}traverseAnnotationList(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationListItems(e))),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map(i=>this.traverseAnnotation(i))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(e.resource=this.traverseContentResource(e.resource)),e.on,e}traverseLayer(e){return this.traverseType(this.traverseLinking(this.traverseLayerItems(e)),this.traversals.layer)}traverseLayerItems(e){return e.otherContent&&(e.otherContent=e.otherContent.map(i=>this.traverseAnnotationList(i))),e}traverseChoice(e){return this.traverseType(this.traverseChoiceItems(e),this.traversals.choice)}traverseChoiceItems(e){return e.default&&e.default!=="rdf:nil"&&(e.default=this.traverseContentResource(e.default)),e.item&&e.item!=="rdf:nil"&&(e.item=e.item.map(i=>this.traverseContentResource(i))),e}traverseService(e){return this.traverseType(this.traverseLinking(e),this.traversals.service)}traverseContentResource(e){return e["@type"]==="oa:Choice"?this.traverseChoice(e):this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.contentResource)}traverseUnknown(e){if(!e["@type"]||typeof e=="string")return e;switch(_(e)){case"sc:Collection":return this.traverseCollection(e);case"sc:Manifest":return this.traverseManifest(e);case"sc:Canvas":return this.traverseCanvas(e);case"sc:Sequence":return this.traverseSequence(e);case"sc:Range":return this.traverseRange(e);case"oa:Annotation":return this.traverseAnnotation(e);case"oa:AnnotationList":return this.traverseAnnotationList(e);case"sc:Layer":return this.traverseLayer(e);case"Service":return this.traverseService(e);case"oa:Choice":return this.traverseChoice(e);case"ContentResource":return this.traverseContentResource(e)}return e.profile?this.traverseService(e):e}traverseImageResource(e){const i=Array.isArray(e),n=Array.isArray(e)?e:[e],a=[];for(const r of n)typeof r=="string"?a.push(this.traverseContentResource({"@id":r,"@type":"dctypes:Image"})):a.push(this.traverseContentResource(r));return!i&&!this.options.convertPropsToArray?a[0]:a}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){const i=Array.isArray(e),n=Array.isArray(e)?e:[e],a=[];for(const r of n)a.push(this.traverseService(r));return!i&&!this.options.convertPropsToArray?a[0]:a}traverseLinking(e){return e.related&&(e.related=this.traverseOneOrManyType(e.related,this.traversals.contentResource)),e.rendering&&(e.rendering=this.traverseOneOrManyType(e.rendering,this.traversals.contentResource)),e.service&&(e.service=this.traverseOneOrMoreServices(e.service)),e.seeAlso&&(e.seeAlso=this.traverseOneOrManyType(e.seeAlso,this.traversals.contentResource)),e.within&&(typeof e.within=="string"||(e.within=this.traverseOneOrManyType(e.within,this.traversals.contentResource))),e.startCanvas&&(typeof e.startCanvas=="string"?e.startCanvas=this.traverseType({"@id":e.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):e.startCanvas&&this.traverseType(e.startCanvas,this.traversals.canvas)),e.contentLayer&&(typeof e.contentLayer=="string"?e.contentLayer=this.traverseLayer({"@id":e.contentLayer,"@type":"sc:Layer"}):e.contentLayer=this.traverseLayer(e.contentLayer)),e}traverseOneOrManyType(e,i){if(!Array.isArray(e))if(this.options.convertPropsToArray)e=[e];else return this.traverseType(e,i);return e.map(n=>this.traverseType(n,i))}traverseType(e,i){return i.reduce((n,a)=>{const r=a(n);return typeof r=="undefined"&&!this.options.allowUndefinedReturn?n:r},e)}}const be="http://library.stanford.edu/iiif/image-api/compliance.html#level0",j="http://library.stanford.edu/iiif/image-api/compliance.html#level1",G="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Re="http://library.stanford.edu/iiif/image-api/conformance.html#level0",$="http://library.stanford.edu/iiif/image-api/conformance.html#level1",q="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Ee="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",U="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",V="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Le="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",z="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",W="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",we="http://iiif.io/api/image/1/level0.json",Te="http://iiif.io/api/image/1/profiles/level0.json",H="http://iiif.io/api/image/1/level1.json",B="http://iiif.io/api/image/1/profiles/level1.json",K="http://iiif.io/api/image/1/level2.json",Q="http://iiif.io/api/image/1/profiles/level2.json",Me="http://iiif.io/api/image/2/level0.json",xe="http://iiif.io/api/image/2/profiles/level0.json",X="http://iiif.io/api/image/2/level1.json",Y="http://iiif.io/api/image/2/profiles/level1.json",Z="http://iiif.io/api/image/2/level2.json",J="http://iiif.io/api/image/2/profiles/level2.json",Se="level0",ee="level1",te="level2",Pe="http://iiif.io/api/image/2/level0",ie="http://iiif.io/api/image/2/level1",ne="http://iiif.io/api/image/2/level2",Oe=[ie,ne,j,G,$,q,U,V,z,W,H,B,K,Q,X,Y,Z,J,ee,te],Fe=[Pe,ie,ne,be,j,G,Re,$,q,Ee,U,V,Le,z,W,we,Te,H,B,K,Q,Me,xe,X,Y,Z,J,Se,ee,te],S={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function f(t,e="none"){if(!t)return{};const i=Array.isArray(t)?t:[t],n={};for(const a of i){if(typeof a=="string"){n[e]=n[e]?n[e]:[],n[e].push(a||"");continue}if(!a["@language"]){n[e]=n[e]?n[e]:[],n[e].push(a["@value"]||"");continue}const r=a["@language"];n[r]=n[r]?n[r]:[],n[r].push(a["@value"]||"")}return n}function P(t){if(Array.isArray(t))return P(t.find(e=>typeof e=="string"));if(Fe.indexOf(t)!==-1)return"level2";if(Oe.indexOf(t)!==-1)return"level1";if(typeof t=="string")return t}function re(t){const e=Array.isArray(t)?t:[t];for(const i of e)switch(i){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function De(t){switch(t){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}function ke(t){return Array.isArray(t)?t:[t]}function Ne(t){for(const e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}function O(t){const e=t["@id"]||t.id;let i=t["@type"]||t.type;const n=t.profile||void 0,a=t["@context"]||void 0;if(n){const r=De(n);if(r)return r}if(a){const r=re(a);if(r)return r}if(i){if(Array.isArray(i)){if(i.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(i.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";i=i[0]}for(const r of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${r}:`)){i=i.slice(r.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(t.format){if(t.format.startsWith("image/"))return"Image";if(t.format.startsWith("text/")||t.format==="application/pdf")return"Text";if(t.format.startsWith("application/"))return"Dataset"}return e&&(e.endsWith(".jpg")||e.endsWith(".png")||e.endsWith(".jpeg"))?"Image":i||"unknown"}const je=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Ge(t){const e=t.match(je);return e?e[0]:t}function $e(t,e="Rights/License",i="none"){let n=null;const a=[],r=Array.isArray(t)?t:[t];for(const E of r){const o=E?Ge(E):void 0;if(o&&(o.indexOf("creativecommons.org")!==-1||o.indexOf("rightsstatements.org")!==-1)){o.startsWith("https://")?n=`http://${o.slice(8)}`:n=o;continue}o&&a.push({label:{[i]:[e]},value:{[i]:[o]}})}return[n,a]}const qe=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function Ue(t){if(t){const e=Array.isArray(t)?t:[t],i=[];for(const n of e)n==="http://iiif.io/api/presentation/2/context.json"&&i.push("http://iiif.io/api/presentation/3/context.json"),qe.indexOf(n)===-1&&i.push(n);if(e.length)return i.length===1?i[0]:i}}function Ve(t){return t?t.map(e=>({label:f(e.label),value:f(e.value)})):[]}function v(t){for(const e in t)(typeof t[e]=="undefined"||t[e]===null)&&delete t[e];return t}let ae=0;function se(t,e){const i=encodeURI(t.id||t["@id"]||"").trim();return i&&e?`${i}/${e}`:i||(ae++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${ae}`)}function p(t){const e=[...t.behavior||[]];return t.viewingHint&&e.push(t.viewingHint),{"@context":t["@context"]?Ue(t["@context"]):void 0,id:(t["@id"]||se(t)).trim(),type:O(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:t.motivation?Ne(t.motivation):void 0,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function l(t){const[e,i]=$e(t.license),n=[...t.metadata?Ve(t.metadata):[],...i];return{rights:e,metadata:n.length?n:void 0,label:t.label?f(t.label):void 0,requiredStatement:t.attribution?{label:f(S.attributionLabel),value:f(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?f(t.description):void 0,thumbnail:t.thumbnail}}function ze(t){if(!t.within)return;const e=Array.isArray(t.within)?t.within:[t.within],i=[];for(const n of e)if(typeof n=="string"){if(n)switch(t["@type"]){case"sc:Manifest":i.push({id:n,type:"Collection"});break}}else n["@id"]&&i.push({id:n["@id"],type:O(n)});return i.length?i:void 0}function c(t){const e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],i=t.contentLayer;return{provider:t.logo||e.length?[{id:S.providerId,type:"Agent",homepage:e.length?[e[0]]:void 0,logo:t.logo?Array.isArray(t.logo)?t.logo:[t.logo]:void 0,label:f(S.providerName)}]:void 0,partOf:ze(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?ke(t.service):void 0,supplementary:i?[i]:void 0}}function We(t){return v({...p(t),...l(t),...c(t),items:t.members})}function He(t){const e=[],i=[];for(const a of t.sequences||[])a.canvases.length&&e.push(...a.canvases),a.behavior&&i.push(...a.behavior);const n=p(t);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),v({...n,...l(t),...c(t),items:e,structures:t.structures})}function Be(t){return v({...p(t),...l(t),...c(t),items:t.images&&t.images.length?[{id:se(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function Ke(t){return v({...p(t),...l(t),...c(t),items:t.resources})}function Qe(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[]}}function Xe(t){return v({...p(t),...l(t),...c(t),target:typeof t.on=="string"?encodeURI(t.on).trim():t.on,body:t.resource})}function Ye(t){const e=t;return v({...p(e),...l(e),...c(e)})}function Ze(t){const e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),{...p(t),...l(t),items:e}}function Je(t){return v({...p(t),...l(t),...c(t),items:t.members})}function et(t){const{"@id":e,"@type":i,"@context":n,profile:a,...r}=t;return e&&(r.id=e),r.type=O(t),r.type==="unknown"&&(r.type="Service"),a&&(r.profile=P(a)),v({...r,...l(r)})}function tt(t){return v({...p(t),...l(t),...c(t)})}const oe=new T({collection:[We],manifest:[He],canvas:[Be],annotationList:[Ke],sequence:[Qe],annotation:[Xe],contentResource:[Ye],choice:[Ze],range:[Je],service:[et],layer:[tt]});function le(t){return t&&t["@context"]&&(t["@context"]==="http://iiif.io/api/presentation/2/context.json"||t["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")!==-1||t["@context"]==="http://www.shared-canvas.org/ns/context.json")||t["@context"]==="http://iiif.io/api/image/2/context.json"?oe.traverseUnknown(t):t}var it=Object.freeze({__proto__:null,types:d,identifyResource:_,Traverse:T,convertLanguageMapping:f,getProfile:P,getTypeFromContext:re,presentation2to3:oe,convertPresentation2:le});const nt={id:"https://iiif-parser/annotation",type:"Annotation",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[],accessibility:[],audience:[],body:[],bodyValue:null,canonical:null,created:null,creator:[],generated:null,generator:[],modified:null,motivation:[],rights:[],stylesheet:null,target:[],timeMode:void 0,via:[],partOf:[]},ve={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:[],motivation:null,label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[]},pe={id:"https://iiif-parser/empty-canvas",type:"Canvas",label:null,behavior:[],motivation:null,thumbnail:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:[],rights:null,navDate:null,provider:[],items:[],annotations:[],seeAlso:[],homepage:[],logo:[],partOf:[],rendering:[],service:[],duration:0,height:0,width:0},fe={id:"https://iiif-parser/empty-collection",type:"Collection",label:null,viewingDirection:"left-to-right",behavior:[],motivation:null,thumbnail:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:[],rights:null,navDate:null,provider:[],items:[],annotations:[],seeAlso:[],homepage:[],logo:[],partOf:[],rendering:[],service:[],services:[]},ce={id:"https://iiif-parser/empty-manifest",type:"Manifest",annotations:[],behavior:[],homepage:[],items:[],label:null,logo:[],metadata:[],motivation:null,navDate:null,provider:[],partOf:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,rendering:[],requiredStatement:null,rights:null,seeAlso:[],service:[],services:[],start:null,structures:[],summary:null,thumbnail:[],viewingDirection:"left-to-right"},he={id:"https://iiif-parser/empty-canvas",type:"Range",label:null,behavior:[],motivation:null,thumbnail:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:[],rights:null,navDate:null,provider:[],items:[],annotations:[],seeAlso:[],homepage:[],logo:[],partOf:[],rendering:[],service:[],start:null,supplementary:null,viewingDirection:"left-to-right"},ue={id:"https://iiif-parser/empty-agent",type:"Agent",label:{},logo:[],seeAlso:[],homepage:[]},F=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function de(t){if(typeof t=="undefined"||t===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(t))throw new Error("Array is not a valid entity");if(typeof t!="object")throw new Error(`${typeof t} is not a valid entity`);if(typeof t.type=="string"){const e=F.indexOf(t.type);if(e!==-1)return F[e]}if(t.profile)return"Service";throw new Error("Resource type is not known")}class M{traversals;options;constructor(e,i={}){this.traversals={collection:[],manifest:[],canvas:[],annotationCollection:[],annotationPage:[],annotation:[],contentResource:[],choice:[],range:[],service:[],agent:[],...e},this.options={allowUndefinedReturn:!1,...i}}static all(e){return new M({collection:[e],manifest:[e],canvas:[e],annotationCollection:[e],annotationPage:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e]})}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=e.thumbnail.map(i=>this.traverseType(i,this.traversals.contentResource))),e.provider&&(e.provider=e.provider.map(i=>this.traverseAgent(i))),e}traverseLinking(e){return e.seeAlso&&(e.seeAlso=e.seeAlso.map(i=>this.traverseType(i,this.traversals.contentResource))),e.service&&(e.service=e.service.map(i=>this.traverseType(i,this.traversals.service))),e.services&&(e.services=e.services.map(i=>this.traverseType(i,this.traversals.service))),e.logo&&(e.logo=e.logo.map(i=>this.traverseType(i,this.traversals.contentResource))),e.homepage&&(e.homepage=e.homepage.map(i=>this.traverseType(i,this.traversals.contentResource))),e.partOf&&(e.partOf=e.partOf.map(i=>typeof i=="string"||!i.type?this.traverseType(i,this.traversals.contentResource):i.type==="Canvas"?this.traverseType(i,this.traversals.canvas):i.type==="AnnotationCollection"?this.traverseType(i,this.traversals.annotationCollection):this.traverseType(i,this.traversals.contentResource))),e.start&&(e.start=e.start?this.traverseType(e.start,this.traversals.canvas):null),e.rendering&&(e.rendering=e.rendering.map(i=>this.traverseType(i,this.traversals.contentResource))),e.supplementary&&(e.supplementary=e.supplementary.map(i=>this.traverseType(i,this.traversals.contentResource))),e}traverseCollectionItems(e){return e.items&&e.items.map(i=>i.type==="Collection"?this.traverseCollection(i):this.traverseManifest(i)),e}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traversePosterCanvas(this.traverseCollectionItems(e))))),this.traversals.collection)}traverseManifestItems(e){return e.items&&(e.items=e.items.map(i=>this.traverseCanvas(i))),e}traverseManifestStructures(e){return e.structures&&(e.structures=e.structures.map(i=>this.traverseRange(i))),e}traverseManifest(e){return this.traverseType(this.traverseInlineAnnotationPages(this.traverseManifestStructures(this.traversePosterCanvas(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e)))))),this.traversals.manifest)}traverseCanvasItems(e){return e.items=(e.items||[]).map(i=>this.traverseAnnotationPage(i)),e}traverseInlineAnnotationPages(e){return typeof e=="string"||!e||e.annotations&&(e.annotations=e.annotations.map(i=>this.traverseAnnotationPage(i))),e}traverseCanvas(e){return this.traverseType(this.traverseInlineAnnotationPages(this.traversePosterCanvas(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))))),this.traversals.canvas)}traverseAnnotationPageItems(e){return e.items&&(e.items=e.items.map(i=>this.traverseAnnotation(i))),e}traverseAnnotationPage(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationPageItems(e))),this.traversals.annotationPage)}traverseAnnotationBody(e){return Array.isArray(e.body)?e.body=e.body.map(i=>this.traverseContentResource(i)):e.body&&(e.body=this.traverseContentResource(e.body)),e}traversePosterCanvas(e){return e.posterCanvas&&(e.posterCanvas=this.traverseType(e.posterCanvas,this.traversals.canvas)),e.placeholderCanvas&&(e.placeholderCanvas=this.traverseType(e.placeholderCanvas,this.traversals.canvas)),e.accompanyingCanvas&&(e.accompanyingCanvas=this.traverseType(e.accompanyingCanvas,this.traversals.canvas)),e}traverseAnnotation(e){return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(e)),this.traversals.annotation)}traverseContentResourceLinking(e){return typeof e=="string"||!e||e&&e.service&&(e.service=(e.service||[]).map(i=>this.traverseType(i,this.traversals.service))),e}traverseContentResource(e){return e.type==="Choice"&&(e.items=e.items.map(i=>this.traverseContentResource(i))),this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)),this.traversals.contentResource)}traverseRangeRanges(e){return e.items&&(e.items=e.items.map(i=>typeof i=="string"?this.traverseCanvas({id:i,type:"Canvas"}):i.type==="Manifest"?this.traverseManifest(i):this.traverseRange(i))),e}traverseRange(e){return this.traverseType(this.traversePosterCanvas(this.traverseDescriptive(this.traverseLinking(this.traverseRangeRanges(e)))),this.traversals.range)}traverseAgent(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.agent)}traverseType(e,i){return i.reduce((n,a)=>{const r=a(n);return typeof r=="undefined"&&!this.options.allowUndefinedReturn?n:r},e)}traverseService(e){return this.traverseType(e,this.traversals.service)}traverseUnknown(e){const i=de(e);switch(i){case"Collection":return this.traverseCollection(e);case"Manifest":return this.traverseManifest(e);case"Canvas":return this.traverseCanvas(e);case"AnnotationPage":return this.traverseAnnotationPage(e);case"Annotation":return this.traverseAnnotation(e);case"ContentResource":return this.traverseContentResource(e);case"Range":return this.traverseRange(e);case"Service":return this.traverseService(e);case"Agent":return this.traverseAgent(e);default:throw new Error(`Unknown or unsupported resource type of ${i}`)}}}const rt={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}};function me(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}function ge(t,e){if(typeof t=="string")return{id:t,type:e};if(!t.id)throw new Error(`Invalid resource does not have an ID (${e})`);return t}function at(t){return(e,i)=>{const n=t[e]?t[e]:{};return a=>{const r=ge(a,i||e);return r&&r.id&&e?(n[r.id]=n[r.id]?Object.assign({},n[r.id],r):Object.assign({},r),{id:r.id,type:e==="ContentResource"?e:r.type}):r}}}function st(t){return(e,i)=>n=>{const{id:a,type:r}=ge(n,i||e);if(typeof a=="undefined")throw new Error("Found invalid entity without an ID.");return e==="ContentResource"?t[a]=e:t[a]=r,n}}function ot(t){const e=JSON.stringify(t);let i=5381,n=e.length;for(;n;)i=i*33^e.charCodeAt(--n);const r=(i>>>0).toString(16);return r.length%2?"0"+r:r}function D(t){return e=>typeof e=="string"?{id:e,type:t}:e.id?e.type?e:{type:t,...e}:{id:ot(e),type:t,...e}}function b(t){return e=>({...t,...e})}function R(t){return Array.isArray(t)?t:[t]}function lt(t){return t.body&&(t.body=R(t.body)),t.seeAlso&&(t.seeAlso=R(t.seeAlso)),t.body&&(t.body=R(t.body)),t.audience&&(t.audience=R(t.audience)),t.accessibility&&(t.accessibility=R(t.accessibility)),t.motivation&&(t.motivation=R(t.motivation)),t}function vt(t){const e=le(t),i=me(),n={},a=at(i),r=st(n),o=new M({collection:[b(fe),r("Collection"),a("Collection")],manifest:[b(ce),r("Manifest"),a("Manifest")],canvas:[b(pe),r("Canvas"),a("Canvas")],annotationPage:[D("AnnotationPage"),b(ve),r("AnnotationPage"),a("AnnotationPage")],annotation:[D("Annotation"),lt,r("Annotation"),a("Annotation")],contentResource:[D("ContentResource"),r("ContentResource"),a("ContentResource")],range:[b(he),r("Range","Canvas"),a("Range","Canvas")],agent:[b(ue),r("Agent"),a("Agent")]}).traverseUnknown(e);return{entities:i,resource:o,mapping:n}}const h="__$UNSET$__",k="__$UNWRAP$__";function pt(t,e){const i=t.requests[e],n=t.mapping[e];if(!(!n||i&&i.resourceUri&&!t.entities[n][i.resourceUri]))return t.entities[n][i?i.resourceUri:e]}function ye(t){const e={};for(const[i,n]of t){if(i===k&&n!==h)return n;n!==h&&typeof n!="undefined"&&n!==null&&(e[i]=n)}return e}function ft(t,e,i){if(!e.type||!e.id)throw new Error("Unknown entity");if(!i[e.type])throw new Error(`Serializer not found for ${e.type}`);function n(a){const r=i[a.type];if(!r)return h;const E=pt(t,a.id)||(a.id&&a.type?a:null);if(!E)return h;const o=r(E,t,{isTopLevel:e.id===a.id});let w=o.next();for(;!w.done;){const x=w.value;let N=h;if(x)if(Array.isArray(x)){const _e=[];for(const mt of x)_e.push(n(mt));N=_e}else N=n(x);w=o.next(N)}return w.value===h?h:ye(w.value)}return n(e)}function m(t){if(!t)return;const e=Object.keys(t);if(e.length!==0){if(e.length===1){const i=e[0];if(!i)return"";const n=(t[i]||[]).join("");return i==="@none"||i==="none"||i==="en"?n:{"@language":i,"@value":n}}return e.map(i=>({"@language":i,"@value":(t[i]||[]).join("")}))}}function Ae(t){return Array.isArray(t)?t.map(e=>Ae(e)):typeof t=="string"?t:t.type&&t.type==="Canvas"?t.id:t}function u(t,e=!1){if(!!t)return t.length>1&&!e?t:t[0]||void 0}function ct(t){if(!!t){if(typeof t=="string")return{"@id":t};if("@id"in t){const e={...t};return delete e["@type"],e}return{"@context":"http://iiif.io/api/image/2/context.json","@id":t.id,profile:`http://iiif.io/api/image/2/profiles/${t.profile}.json`}}}function g(t,e){return[["@id",t.id],["@type",e],["format",t.format],["height",t.height],["width",t.width],["viewingDirection",t.viewingDirection!=="left-to-right"?t.viewingDirection:void 0]]}function*y(t){const e=t.provider?yield t.provider[0]:void 0;return[["label",m(t.label)],["metadata",t.metadata&&t.metadata.length?t.metadata.map(i=>({label:m(i.label)||"",value:m(i.value)||""})):void 0],["description",m(t.summary)],["thumbnail",u(yield t.thumbnail)],["navDate",t.navDate],["logo",e?u(e.logo):void 0],["homepage",e?e.homepage:void 0],["attribution",t.requiredStatement?m(t.requiredStatement.value):void 0]]}function*L(t){return[["seeAlso",u(yield t.seeAlso)],["service",u((t.service||[]).map(ct))],["rendering",u(yield t.rendering)],["startCanvas",t.start?t.start.id:void 0]]}const ht={Manifest:function*(t){return[...g(t,"sc:Manifest"),...yield*y(t),...yield*L(t),["sequences",[{"@id":`${t.id}/sequence0`,"@type":"sc:Sequence",canvases:yield t.items}]],["structures",yield t.structures]]},Canvas:function*(t){const i=(yield t.items)[0];return[...g(t,"sc:Canvas"),...yield*y(t),...yield*L(t),["images",i?[i.resources]:void 0],["annotations",t.annotations&&t.annotations.length?u(yield t.annotations):void 0]]},AnnotationPage:function*(t){return[...g(t,"sc:AnnotationList"),...yield*y(t),["resources",t.items&&t.items.length?u(yield t.items):void 0]]},Annotation:function*(t){return[["@id",t.id],["@type","oa:Annotation"],["motivation","sc:painting"],["on",Ae(t.target)],["resource",u(yield t.body,!0)]]},ContentResource:function*(t){switch(t.type){case"Image":return[...g(t,"dctypes:Image"),...yield*y(t),...yield*L(t)];case"Text":case"Dataset":default:return[...g(t,void 0),...yield*y(t)]}},AnnotationCollection:function*(t){return[["@id",t.id],["@type","sc:Layer"],["label",m(t.label)]]},Collection:function*(t){return[...g(t,"sc:Collection"),...yield*y(t),...yield*L(t),["members",yield*t.items]]},Range:function*(t){const e=[],i=[];if(t.items)for(const n of t.items){const a=yield n;e.push({"@id":n.id,"@type":n.type,label:a?a.label:void 0,within:t.id}),n.type==="Canvas"&&i.push(n.id)}return[...g(t,"sc:Range"),...yield*y(t),...yield*L(t),["canvases",i.length===e.length?i:void 0],["members",i.length!==e.length?e:void 0]]}};function A(t){return[["id",t.id],["type",t.type],["format",t.format],["profile",t.profile],["height",t.height],["width",t.width],["duration",t.duration||void 0],["viewingDirection",t.viewingDirection!=="left-to-right"?t.viewingDirection:void 0],["behavior",t.behavior&&t.behavior.length?t.behavior:void 0],["timeMode",t.timeMode],["motivation",t.motivation]]}function s(t){if(!(!t||t.length===0))return t}function Ce(t){if(t&&t.type&&t.type==="ImageService2"){const{id:e,type:i,profile:n,...a}=t;return{"@id":e,"@type":i,profile:n.startsWith("http")?n:`http://iiif.io/api/image/2/${n}.json`,...a}}return t}function Ie(t){if(!(!t||t.length===0))return t.map(Ce)}function*C(t){return[["label",t.label],["metadata",s(t.metadata)],["summary",t.summary],["requiredStatement",t.requiredStatement],["rights",t.rights],["navDate",t.navDate],["language",t.language],["thumbnail",s(yield t.thumbnail)],["placeholderCanvas",yield t.placeholderCanvas],["accompanyingCanvas",yield t.accompanyingCanvas],["provider",s(yield t.provider)]]}function*I(t){return[["seeAlso",s(yield t.seeAlso)],["service",Ie(t.service)],["services",Ie(t.services)],["rendering",s(yield t.rendering)],["supplementary",s(yield t.supplementary)],["homepage",s(yield t.homepage)],["logo",s(yield t.logo)],["partOf",s(yield t.partOf)],["start",t.start]]}var ut=Object.freeze({__proto__:null,emptyAnnotation:nt,emptyAnnotationPage:ve,emptyCanvas:pe,emptyCollection:fe,emptyManifest:ce,emptyRange:he,emptyAgent:ue,defaultEntities:rt,getDefaultEntities:me,normalize:vt,types:F,identifyResource:de,Traverse:M,UNSET:h,UNWRAP:k,serializedFieldsToObject:ye,serialize:ft,languageString2to3:m,serializeConfigPresentation2:ht,serializeConfigPresentation3:{Manifest:function*(t,e,{isTopLevel:i}){return i?[["@context","http://iiif.io/api/presentation/3/context.json"],...A(t),...yield*C(t),...yield*I(t),["items",yield t.items],["structures",s(yield t.structures)],["annotations",s(yield t.annotations)]]:[...A(t),...yield*C(t)]},Canvas:function*(t){return[...A(t),...yield*C(t),...yield*I(t),["items",yield t.items],["annotations",s(yield t.annotations)]]},Agent:function*(t){return[["id",t.id],["type","Agent"],["label",t.label],...yield*I(t)]},AnnotationPage:function*(t){return[...Object.entries(t).map(([i,n])=>[i,Array.isArray(n)?s(n):n]).filter(([i,n])=>i!=="items"),...yield*I(t),["items",yield t.items]]},Service:function*(t){return[[k,Ce(t)]]},Annotation:function*(t){return[...Object.entries(t).map(([i,n])=>[i,Array.isArray(n)?s(n):n]).filter(([i])=>i!=="body"),["body",yield t.body]]},ContentResource:function*(t){return[...A(t),...yield*C(t),...yield*I(t),["annotations",s(yield t.annotations)]]},AnnotationCollection:function*(t){return[["id",t.id],["type","AnnotationCollection"],["label",t.label]]},Collection:function*(t,e,{isTopLevel:i}){return i?[["@context","http://iiif.io/api/presentation/3/context.json"],...A(t),...yield*C(t),...yield*I(t),["items",s(yield t.items)]]:[...A(t),...yield*C(t)]},Range:function*(t){const e=[];for(const i of t.items)i.type==="Range"?e.push(yield i):e.push(i);return[...A(t),...yield*C(t),...yield*I(t),["items",e],["annotations",s(yield t.annotations)]]}}}),dt={Presentation2:it,Presentation3:ut};return dt});
(function(d,_){typeof exports=="object"&&typeof module!="undefined"?module.exports=_():typeof define=="function"&&define.amd?define(_):(d=typeof globalThis!="undefined"?globalThis:d||self,d.IIIFParser=_())})(this,function(){"use strict";const d=["sc:Collection","sc:Manifest","sc:Canvas","oa:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function _(t){if(typeof t=="undefined"||t===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(t))throw new Error("Array is not a valid entity");if(typeof t!="object")throw new Error(`${typeof t} is not a valid entity`);if(typeof t["@type"]=="string"){const e=d.indexOf(t["@type"]);if(e!==-1)return d[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}class T{traversals;options;constructor(e,i={}){this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...i}}static all(e){return new T({collection:[e],manifest:[e],canvas:[e],annotationList:[e],sequence:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],layer:[e]})}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))),this.traversals.collection)}traverseCollectionItems(e){if(this.options.mergeMemberProperties){const i=[...(e.manifests||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n),...(e.collections||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n),...e.members||[]];delete e.collections,delete e.manifests,e.members=i}return e.manifests&&(e.manifests=e.manifests.map(i=>this.traverseManifest(typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i))),e.collections&&(e.collections=e.collections.map(i=>this.traverseCollection(typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i))),e.members&&(e.members=e.members.map(i=>typeof i=="string"?i:this.traverseUnknown(i))),e}traverseManifest(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))),this.traversals.manifest)}traverseManifestItems(e){return e.sequences&&(e.sequences=e.sequences.map(i=>this.traverseSequence(i))),e.structures&&(e.structures=e.structures.map(i=>this.traverseRange(i))),e}traverseSequence(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))),this.traversals.sequence)}traverseSequenceItems(e){return e.canvases&&(e.canvases=e.canvases.map(i=>this.traverseCanvas(i))),e}traverseCanvas(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))),this.traversals.canvas)}traverseCanvasItems(e){return e.images&&(e.images=e.images.map(i=>this.traverseAnnotation(i))),e.otherContent&&(e.otherContent=e.otherContent.map(i=>this.traverseAnnotationList(i))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const i=[...(e.ranges||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Range"}:n),...(e.canvases||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Canvas"}:n),...e.members||[]];delete e.ranges,delete e.canvases,e.members=i.length?i.map(n=>this.traverseUnknown(n)):void 0}return e}traverseAnnotationList(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationListItems(e))),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map(i=>this.traverseAnnotation(i))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(e.resource=this.traverseContentResource(e.resource)),e.on,e}traverseLayer(e){return this.traverseType(this.traverseLinking(this.traverseLayerItems(e)),this.traversals.layer)}traverseLayerItems(e){return e.otherContent&&(e.otherContent=e.otherContent.map(i=>this.traverseAnnotationList(i))),e}traverseChoice(e){return this.traverseType(this.traverseChoiceItems(e),this.traversals.choice)}traverseChoiceItems(e){return e.default&&e.default!=="rdf:nil"&&(e.default=this.traverseContentResource(e.default)),e.item&&e.item!=="rdf:nil"&&(e.item=e.item.map(i=>this.traverseContentResource(i))),e}traverseService(e){return this.traverseType(this.traverseLinking(e),this.traversals.service)}traverseContentResource(e){return e["@type"]==="oa:Choice"?this.traverseChoice(e):this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.contentResource)}traverseUnknown(e){if(!e["@type"]||typeof e=="string")return e;switch(_(e)){case"sc:Collection":return this.traverseCollection(e);case"sc:Manifest":return this.traverseManifest(e);case"sc:Canvas":return this.traverseCanvas(e);case"sc:Sequence":return this.traverseSequence(e);case"sc:Range":return this.traverseRange(e);case"oa:Annotation":return this.traverseAnnotation(e);case"oa:AnnotationList":return this.traverseAnnotationList(e);case"sc:Layer":return this.traverseLayer(e);case"Service":return this.traverseService(e);case"oa:Choice":return this.traverseChoice(e);case"ContentResource":return this.traverseContentResource(e)}return e.profile?this.traverseService(e):e}traverseImageResource(e){const i=Array.isArray(e),n=Array.isArray(e)?e:[e],a=[];for(const r of n)typeof r=="string"?a.push(this.traverseContentResource({"@id":r,"@type":"dctypes:Image"})):a.push(this.traverseContentResource(r));return!i&&!this.options.convertPropsToArray?a[0]:a}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){const i=Array.isArray(e),n=Array.isArray(e)?e:[e],a=[];for(const r of n)a.push(this.traverseService(r));return!i&&!this.options.convertPropsToArray?a[0]:a}traverseLinking(e){return e.related&&(e.related=this.traverseOneOrManyType(e.related,this.traversals.contentResource)),e.rendering&&(e.rendering=this.traverseOneOrManyType(e.rendering,this.traversals.contentResource)),e.service&&(e.service=this.traverseOneOrMoreServices(e.service)),e.seeAlso&&(e.seeAlso=this.traverseOneOrManyType(e.seeAlso,this.traversals.contentResource)),e.within&&(typeof e.within=="string"||(e.within=this.traverseOneOrManyType(e.within,this.traversals.contentResource))),e.startCanvas&&(typeof e.startCanvas=="string"?e.startCanvas=this.traverseType({"@id":e.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):e.startCanvas&&this.traverseType(e.startCanvas,this.traversals.canvas)),e.contentLayer&&(typeof e.contentLayer=="string"?e.contentLayer=this.traverseLayer({"@id":e.contentLayer,"@type":"sc:Layer"}):e.contentLayer=this.traverseLayer(e.contentLayer)),e}traverseOneOrManyType(e,i){if(!Array.isArray(e))if(this.options.convertPropsToArray)e=[e];else return this.traverseType(e,i);return e.map(n=>this.traverseType(n,i))}traverseType(e,i){return i.reduce((n,a)=>{const r=a(n);return typeof r=="undefined"&&!this.options.allowUndefinedReturn?n:r},e)}}const be="http://library.stanford.edu/iiif/image-api/compliance.html#level0",j="http://library.stanford.edu/iiif/image-api/compliance.html#level1",G="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Re="http://library.stanford.edu/iiif/image-api/conformance.html#level0",$="http://library.stanford.edu/iiif/image-api/conformance.html#level1",q="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Ee="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",U="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",V="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",we="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",z="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",W="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Le="http://iiif.io/api/image/1/level0.json",Te="http://iiif.io/api/image/1/profiles/level0.json",H="http://iiif.io/api/image/1/level1.json",B="http://iiif.io/api/image/1/profiles/level1.json",K="http://iiif.io/api/image/1/level2.json",Q="http://iiif.io/api/image/1/profiles/level2.json",Me="http://iiif.io/api/image/2/level0.json",xe="http://iiif.io/api/image/2/profiles/level0.json",X="http://iiif.io/api/image/2/level1.json",Y="http://iiif.io/api/image/2/profiles/level1.json",Z="http://iiif.io/api/image/2/level2.json",J="http://iiif.io/api/image/2/profiles/level2.json",Se="level0",ee="level1",te="level2",Pe="http://iiif.io/api/image/2/level0",ie="http://iiif.io/api/image/2/level1",ne="http://iiif.io/api/image/2/level2",Oe=[ie,ne,j,G,$,q,U,V,z,W,H,B,K,Q,X,Y,Z,J,ee,te],Fe=[Pe,ie,ne,be,j,G,Re,$,q,Ee,U,V,we,z,W,Le,Te,H,B,K,Q,Me,xe,X,Y,Z,J,Se,ee,te],S={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function f(t,e="none"){if(!t)return{};const i=Array.isArray(t)?t:[t],n={};for(const a of i){if(typeof a=="string"){n[e]=n[e]?n[e]:[],n[e].push(a||"");continue}if(!a["@language"]){n[e]=n[e]?n[e]:[],n[e].push(a["@value"]||"");continue}const r=a["@language"];n[r]=n[r]?n[r]:[],n[r].push(a["@value"]||"")}return n}function P(t){if(Array.isArray(t))return P(t.find(e=>typeof e=="string"));if(Fe.indexOf(t)!==-1)return"level2";if(Oe.indexOf(t)!==-1)return"level1";if(typeof t=="string")return t}function re(t){const e=Array.isArray(t)?t:[t];for(const i of e)switch(i){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function De(t){switch(t){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}function ke(t){return Array.isArray(t)?t:[t]}function Ne(t){for(const e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}const je=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function O(t){const e=t["@id"]||t.id;let i=t["@type"]||t.type;const n=t.profile||void 0,a=t["@context"]||void 0;if(n){const r=De(n);if(r)return r}if(a){const r=re(a);if(r)return r}if(i){if(Array.isArray(i)){if(i.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(i.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";i=i[0]}for(const r of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${r}:`)){i=i.slice(r.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(i&&je.indexOf(i)!==-1)return i;if(t.format){if(t.format.startsWith("image/"))return"Image";if(t.format.startsWith("text/")||t.format==="application/pdf")return"Text";if(t.format.startsWith("application/"))return"Dataset"}return e&&(e.endsWith(".jpg")||e.endsWith(".png")||e.endsWith(".jpeg"))?"Image":i||"unknown"}const Ge=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function $e(t){const e=t.match(Ge);return e?e[0]:t}function qe(t,e="Rights/License",i="none"){let n=null;const a=[],r=Array.isArray(t)?t:[t];for(const E of r){const o=E?$e(E):void 0;if(o&&(o.indexOf("creativecommons.org")!==-1||o.indexOf("rightsstatements.org")!==-1)){o.startsWith("https://")?n=`http://${o.slice(8)}`:n=o;continue}o&&a.push({label:{[i]:[e]},value:{[i]:[o]}})}return[n,a]}const Ue=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function Ve(t){if(t){const e=Array.isArray(t)?t:[t],i=[];for(const n of e)n==="http://iiif.io/api/presentation/2/context.json"&&i.push("http://iiif.io/api/presentation/3/context.json"),Ue.indexOf(n)===-1&&i.push(n);if(e.length)return i.length===1?i[0]:i}}function ze(t){return t?t.map(e=>({label:f(e.label),value:f(e.value)})):[]}function v(t){for(const e in t)(typeof t[e]=="undefined"||t[e]===null)&&delete t[e];return t}let ae=0;function se(t,e){const i=encodeURI(t.id||t["@id"]||"").trim();return i&&e?`${i}/${e}`:i||(ae++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${ae}`)}function p(t){const e=[...t.behavior||[]];return t.viewingHint&&e.push(t.viewingHint),{"@context":t["@context"]?Ve(t["@context"]):void 0,id:(t["@id"]||se(t)).trim(),type:O(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:t.motivation?Ne(t.motivation):void 0,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function l(t){const[e,i]=qe(t.license),n=[...t.metadata?ze(t.metadata):[],...i];return{rights:e,metadata:n.length?n:void 0,label:t.label?f(t.label):void 0,requiredStatement:t.attribution?{label:f(S.attributionLabel),value:f(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?f(t.description):void 0,thumbnail:t.thumbnail}}function We(t){if(!t.within)return;const e=Array.isArray(t.within)?t.within:[t.within],i=[];for(const n of e)if(typeof n=="string"){if(n)switch(t["@type"]){case"sc:Manifest":i.push({id:n,type:"Collection"});break}}else n["@id"]&&i.push({id:n["@id"],type:O(n)});return i.length?i:void 0}function c(t){const e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],i=t.contentLayer;return{provider:t.logo||e.length?[{id:S.providerId,type:"Agent",homepage:e.length?[e[0]]:void 0,logo:t.logo?Array.isArray(t.logo)?t.logo:[t.logo]:void 0,label:f(S.providerName)}]:void 0,partOf:We(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?ke(t.service):void 0,supplementary:i?[i]:void 0}}function He(t){return v({...p(t),...l(t),...c(t),items:t.members})}function Be(t){const e=[],i=[];for(const a of t.sequences||[])a.canvases.length&&e.push(...a.canvases),a.behavior&&i.push(...a.behavior);const n=p(t);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),v({...n,...l(t),...c(t),items:e,structures:t.structures})}function Ke(t){return v({...p(t),...l(t),...c(t),items:t.images&&t.images.length?[{id:se(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function Qe(t){return v({...p(t),...l(t),...c(t),items:t.resources})}function Xe(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[]}}function Ye(t){return v({...p(t),...l(t),...c(t),target:typeof t.on=="string"?encodeURI(t.on).trim():t.on,body:t.resource})}function Ze(t){const e=t;return v({...p(e),...l(e),...c(e)})}function Je(t){const e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),{...p(t),...l(t),items:e}}function et(t){return v({...p(t),...l(t),...c(t),items:t.members})}function tt(t){const{"@id":e,"@type":i,"@context":n,profile:a,...r}=t;return e&&(r.id=e),r.type=O(t),r.type==="unknown"&&(r.type="Service"),a&&(r.profile=P(a)),v({...r,...l(r)})}function it(t){return v({...p(t),...l(t),...c(t)})}const oe=new T({collection:[He],manifest:[Be],canvas:[Ke],annotationList:[Qe],sequence:[Xe],annotation:[Ye],contentResource:[Ze],choice:[Je],range:[et],service:[tt],layer:[it]});function le(t){return t&&t["@context"]&&(t["@context"]==="http://iiif.io/api/presentation/2/context.json"||t["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")!==-1||t["@context"]==="http://www.shared-canvas.org/ns/context.json")||t["@context"]==="http://iiif.io/api/image/2/context.json"?oe.traverseUnknown(t):t}var nt=Object.freeze({__proto__:null,types:d,identifyResource:_,Traverse:T,convertLanguageMapping:f,getProfile:P,getTypeFromContext:re,presentation2to3:oe,convertPresentation2:le});const rt={id:"https://iiif-parser/annotation",type:"Annotation",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[],accessibility:[],audience:[],body:[],bodyValue:null,canonical:null,created:null,creator:[],generated:null,generator:[],modified:null,motivation:[],rights:[],stylesheet:null,target:[],timeMode:void 0,via:[],partOf:[]},ve={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:[],motivation:null,label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[]},pe={id:"https://iiif-parser/empty-canvas",type:"Canvas",label:null,behavior:[],motivation:null,thumbnail:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:[],rights:null,navDate:null,provider:[],items:[],annotations:[],seeAlso:[],homepage:[],logo:[],partOf:[],rendering:[],service:[],duration:0,height:0,width:0},fe={id:"https://iiif-parser/empty-collection",type:"Collection",label:null,viewingDirection:"left-to-right",behavior:[],motivation:null,thumbnail:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:[],rights:null,navDate:null,provider:[],items:[],annotations:[],seeAlso:[],homepage:[],logo:[],partOf:[],rendering:[],service:[],services:[]},ce={id:"https://iiif-parser/empty-manifest",type:"Manifest",annotations:[],behavior:[],homepage:[],items:[],label:null,logo:[],metadata:[],motivation:null,navDate:null,provider:[],partOf:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,rendering:[],requiredStatement:null,rights:null,seeAlso:[],service:[],services:[],start:null,structures:[],summary:null,thumbnail:[],viewingDirection:"left-to-right"},he={id:"https://iiif-parser/empty-canvas",type:"Range",label:null,behavior:[],motivation:null,thumbnail:[],posterCanvas:null,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:[],rights:null,navDate:null,provider:[],items:[],annotations:[],seeAlso:[],homepage:[],logo:[],partOf:[],rendering:[],service:[],start:null,supplementary:null,viewingDirection:"left-to-right"},ue={id:"https://iiif-parser/empty-agent",type:"Agent",label:{},logo:[],seeAlso:[],homepage:[]},F=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function de(t){if(typeof t=="undefined"||t===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(t))throw new Error("Array is not a valid entity");if(typeof t!="object")throw new Error(`${typeof t} is not a valid entity`);if(typeof t.type=="string"){const e=F.indexOf(t.type);if(e!==-1)return F[e]}if(t.profile)return"Service";throw new Error("Resource type is not known")}class M{traversals;options;constructor(e,i={}){this.traversals={collection:[],manifest:[],canvas:[],annotationCollection:[],annotationPage:[],annotation:[],contentResource:[],choice:[],range:[],service:[],agent:[],...e},this.options={allowUndefinedReturn:!1,...i}}static all(e){return new M({collection:[e],manifest:[e],canvas:[e],annotationCollection:[e],annotationPage:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e]})}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=e.thumbnail.map(i=>this.traverseType(i,this.traversals.contentResource))),e.provider&&(e.provider=e.provider.map(i=>this.traverseAgent(i))),e}traverseLinking(e){return e.seeAlso&&(e.seeAlso=e.seeAlso.map(i=>this.traverseType(i,this.traversals.contentResource))),e.service&&(e.service=e.service.map(i=>this.traverseType(i,this.traversals.service))),e.services&&(e.services=e.services.map(i=>this.traverseType(i,this.traversals.service))),e.logo&&(e.logo=e.logo.map(i=>this.traverseType(i,this.traversals.contentResource))),e.homepage&&(e.homepage=e.homepage.map(i=>this.traverseType(i,this.traversals.contentResource))),e.partOf&&(e.partOf=e.partOf.map(i=>typeof i=="string"||!i.type?this.traverseType(i,this.traversals.contentResource):i.type==="Canvas"?this.traverseType(i,this.traversals.canvas):i.type==="AnnotationCollection"?this.traverseType(i,this.traversals.annotationCollection):this.traverseType(i,this.traversals.contentResource))),e.start&&(e.start=e.start?this.traverseType(e.start,this.traversals.canvas):null),e.rendering&&(e.rendering=e.rendering.map(i=>this.traverseType(i,this.traversals.contentResource))),e.supplementary&&(e.supplementary=e.supplementary.map(i=>this.traverseType(i,this.traversals.contentResource))),e}traverseCollectionItems(e){return e.items&&e.items.map(i=>i.type==="Collection"?this.traverseCollection(i):this.traverseManifest(i)),e}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traversePosterCanvas(this.traverseCollectionItems(e))))),this.traversals.collection)}traverseManifestItems(e){return e.items&&(e.items=e.items.map(i=>this.traverseCanvas(i))),e}traverseManifestStructures(e){return e.structures&&(e.structures=e.structures.map(i=>this.traverseRange(i))),e}traverseManifest(e){return this.traverseType(this.traverseInlineAnnotationPages(this.traverseManifestStructures(this.traversePosterCanvas(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e)))))),this.traversals.manifest)}traverseCanvasItems(e){return e.items=(e.items||[]).map(i=>this.traverseAnnotationPage(i)),e}traverseInlineAnnotationPages(e){return typeof e=="string"||!e||e.annotations&&(e.annotations=e.annotations.map(i=>this.traverseAnnotationPage(i))),e}traverseCanvas(e){return this.traverseType(this.traverseInlineAnnotationPages(this.traversePosterCanvas(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))))),this.traversals.canvas)}traverseAnnotationPageItems(e){return e.items&&(e.items=e.items.map(i=>this.traverseAnnotation(i))),e}traverseAnnotationPage(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationPageItems(e))),this.traversals.annotationPage)}traverseAnnotationBody(e){return Array.isArray(e.body)?e.body=e.body.map(i=>this.traverseContentResource(i)):e.body&&(e.body=this.traverseContentResource(e.body)),e}traversePosterCanvas(e){return e.posterCanvas&&(e.posterCanvas=this.traverseType(e.posterCanvas,this.traversals.canvas)),e.placeholderCanvas&&(e.placeholderCanvas=this.traverseType(e.placeholderCanvas,this.traversals.canvas)),e.accompanyingCanvas&&(e.accompanyingCanvas=this.traverseType(e.accompanyingCanvas,this.traversals.canvas)),e}traverseAnnotation(e){return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(e)),this.traversals.annotation)}traverseContentResourceLinking(e){return typeof e=="string"||!e||e&&e.service&&(e.service=(e.service||[]).map(i=>this.traverseType(i,this.traversals.service))),e}traverseContentResource(e){return e.type==="Choice"&&(e.items=e.items.map(i=>this.traverseContentResource(i))),this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)),this.traversals.contentResource)}traverseRangeRanges(e){return e.items&&(e.items=e.items.map(i=>typeof i=="string"?this.traverseCanvas({id:i,type:"Canvas"}):i.type==="Manifest"?this.traverseManifest(i):this.traverseRange(i))),e}traverseRange(e){return this.traverseType(this.traversePosterCanvas(this.traverseDescriptive(this.traverseLinking(this.traverseRangeRanges(e)))),this.traversals.range)}traverseAgent(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.agent)}traverseType(e,i){return i.reduce((n,a)=>{const r=a(n);return typeof r=="undefined"&&!this.options.allowUndefinedReturn?n:r},e)}traverseService(e){return this.traverseType(e,this.traversals.service)}traverseUnknown(e){const i=de(e);switch(i){case"Collection":return this.traverseCollection(e);case"Manifest":return this.traverseManifest(e);case"Canvas":return this.traverseCanvas(e);case"AnnotationPage":return this.traverseAnnotationPage(e);case"Annotation":return this.traverseAnnotation(e);case"ContentResource":return this.traverseContentResource(e);case"Range":return this.traverseRange(e);case"Service":return this.traverseService(e);case"Agent":return this.traverseAgent(e);default:throw new Error(`Unknown or unsupported resource type of ${i}`)}}}const at={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}};function me(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}function ge(t,e){if(typeof t=="string")return{id:t,type:e};if(!t.id)throw new Error(`Invalid resource does not have an ID (${e})`);return t}function st(t){return(e,i)=>{const n=t[e]?t[e]:{};return a=>{const r=ge(a,i||e);return r&&r.id&&e?(n[r.id]=n[r.id]?Object.assign({},n[r.id],r):Object.assign({},r),{id:r.id,type:e==="ContentResource"?e:r.type}):r}}}function ot(t){return(e,i)=>n=>{const{id:a,type:r}=ge(n,i||e);if(typeof a=="undefined")throw new Error("Found invalid entity without an ID.");return e==="ContentResource"?t[a]=e:t[a]=r,n}}function lt(t){const e=JSON.stringify(t);let i=5381,n=e.length;for(;n;)i=i*33^e.charCodeAt(--n);const r=(i>>>0).toString(16);return r.length%2?"0"+r:r}function D(t){return e=>typeof e=="string"?{id:e,type:t}:e.id?e.type?e:{type:t,...e}:{id:lt(e),type:t,...e}}function b(t){return e=>({...t,...e})}function R(t){return Array.isArray(t)?t:[t]}function vt(t){return t.body&&(t.body=R(t.body)),t.seeAlso&&(t.seeAlso=R(t.seeAlso)),t.body&&(t.body=R(t.body)),t.audience&&(t.audience=R(t.audience)),t.accessibility&&(t.accessibility=R(t.accessibility)),t.motivation&&(t.motivation=R(t.motivation)),t}function pt(t){const e=le(t),i=me(),n={},a=st(i),r=ot(n),o=new M({collection:[b(fe),r("Collection"),a("Collection")],manifest:[b(ce),r("Manifest"),a("Manifest")],canvas:[b(pe),r("Canvas"),a("Canvas")],annotationPage:[D("AnnotationPage"),b(ve),r("AnnotationPage"),a("AnnotationPage")],annotation:[D("Annotation"),vt,r("Annotation"),a("Annotation")],contentResource:[D("ContentResource"),r("ContentResource"),a("ContentResource")],range:[b(he),r("Range","Canvas"),a("Range","Canvas")],agent:[b(ue),r("Agent"),a("Agent")]}).traverseUnknown(e);return{entities:i,resource:o,mapping:n}}const h="__$UNSET$__",k="__$UNWRAP$__";function ft(t,e){const i=t.requests[e],n=t.mapping[e];if(!(!n||i&&i.resourceUri&&!t.entities[n][i.resourceUri]))return t.entities[n][i?i.resourceUri:e]}function ye(t){const e={};for(const[i,n]of t){if(i===k&&n!==h)return n;n!==h&&typeof n!="undefined"&&n!==null&&(e[i]=n)}return e}function ct(t,e,i){if(!e.type||!e.id)throw new Error("Unknown entity");if(!i[e.type])throw new Error(`Serializer not found for ${e.type}`);function n(a){const r=i[a.type];if(!r)return h;const E=ft(t,a.id)||(a.id&&a.type?a:null);if(!E)return h;const o=r(E,t,{isTopLevel:e.id===a.id});let L=o.next();for(;!L.done;){const x=L.value;let N=h;if(x)if(Array.isArray(x)){const _e=[];for(const gt of x)_e.push(n(gt));N=_e}else N=n(x);L=o.next(N)}return L.value===h?h:ye(L.value)}return n(e)}function m(t){if(!t)return;const e=Object.keys(t);if(e.length!==0){if(e.length===1){const i=e[0];if(!i)return"";const n=(t[i]||[]).join("");return i==="@none"||i==="none"||i==="en"?n:{"@language":i,"@value":n}}return e.map(i=>({"@language":i,"@value":(t[i]||[]).join("")}))}}function Ae(t){return Array.isArray(t)?t.map(e=>Ae(e)):typeof t=="string"?t:t.type&&t.type==="Canvas"?t.id:t}function u(t,e=!1){if(!!t)return t.length>1&&!e?t:t[0]||void 0}function ht(t){if(!!t){if(typeof t=="string")return{"@id":t};if("@id"in t){const e={...t};return delete e["@type"],e}return{"@context":"http://iiif.io/api/image/2/context.json","@id":t.id,profile:`http://iiif.io/api/image/2/profiles/${t.profile}.json`}}}function g(t,e){return[["@id",t.id],["@type",e],["format",t.format],["height",t.height],["width",t.width],["viewingDirection",t.viewingDirection!=="left-to-right"?t.viewingDirection:void 0]]}function*y(t){const e=t.provider?yield t.provider[0]:void 0;return[["label",m(t.label)],["metadata",t.metadata&&t.metadata.length?t.metadata.map(i=>({label:m(i.label)||"",value:m(i.value)||""})):void 0],["description",m(t.summary)],["thumbnail",u(yield t.thumbnail)],["navDate",t.navDate],["logo",e?u(e.logo):void 0],["homepage",e?e.homepage:void 0],["attribution",t.requiredStatement?m(t.requiredStatement.value):void 0]]}function*w(t){return[["seeAlso",u(yield t.seeAlso)],["service",u((t.service||[]).map(ht))],["rendering",u(yield t.rendering)],["startCanvas",t.start?t.start.id:void 0]]}const ut={Manifest:function*(t){return[...g(t,"sc:Manifest"),...yield*y(t),...yield*w(t),["sequences",[{"@id":`${t.id}/sequence0`,"@type":"sc:Sequence",canvases:yield t.items}]],["structures",yield t.structures]]},Canvas:function*(t){const i=(yield t.items)[0];return[...g(t,"sc:Canvas"),...yield*y(t),...yield*w(t),["images",i?[i.resources]:void 0],["annotations",t.annotations&&t.annotations.length?u(yield t.annotations):void 0]]},AnnotationPage:function*(t){return[...g(t,"sc:AnnotationList"),...yield*y(t),["resources",t.items&&t.items.length?u(yield t.items):void 0]]},Annotation:function*(t){return[["@id",t.id],["@type","oa:Annotation"],["motivation","sc:painting"],["on",Ae(t.target)],["resource",u(yield t.body,!0)]]},ContentResource:function*(t){switch(t.type){case"Image":return[...g(t,"dctypes:Image"),...yield*y(t),...yield*w(t)];case"Text":case"Dataset":default:return[...g(t,void 0),...yield*y(t)]}},AnnotationCollection:function*(t){return[["@id",t.id],["@type","sc:Layer"],["label",m(t.label)]]},Collection:function*(t){return[...g(t,"sc:Collection"),...yield*y(t),...yield*w(t),["members",yield*t.items]]},Range:function*(t){const e=[],i=[];if(t.items)for(const n of t.items){const a=yield n;e.push({"@id":n.id,"@type":n.type,label:a?a.label:void 0,within:t.id}),n.type==="Canvas"&&i.push(n.id)}return[...g(t,"sc:Range"),...yield*y(t),...yield*w(t),["canvases",i.length===e.length?i:void 0],["members",i.length!==e.length?e:void 0]]}};function A(t){return[["id",t.id],["type",t.type],["format",t.format],["profile",t.profile],["height",t.height],["width",t.width],["duration",t.duration||void 0],["viewingDirection",t.viewingDirection!=="left-to-right"?t.viewingDirection:void 0],["behavior",t.behavior&&t.behavior.length?t.behavior:void 0],["timeMode",t.timeMode],["motivation",t.motivation]]}function s(t){if(!(!t||t.length===0))return t}function Ce(t){if(t&&t.type&&t.type==="ImageService2"){const{id:e,type:i,profile:n,...a}=t;return{"@id":e,"@type":i,profile:n.startsWith("http")?n:`http://iiif.io/api/image/2/${n}.json`,...a}}return t}function Ie(t){if(!(!t||t.length===0))return t.map(Ce)}function*C(t){return[["label",t.label],["metadata",s(t.metadata)],["summary",t.summary],["requiredStatement",t.requiredStatement],["rights",t.rights],["navDate",t.navDate],["language",t.language],["thumbnail",s(yield t.thumbnail)],["placeholderCanvas",yield t.placeholderCanvas],["accompanyingCanvas",yield t.accompanyingCanvas],["provider",s(yield t.provider)]]}function*I(t){return[["seeAlso",s(yield t.seeAlso)],["service",Ie(t.service)],["services",Ie(t.services)],["rendering",s(yield t.rendering)],["supplementary",s(yield t.supplementary)],["homepage",s(yield t.homepage)],["logo",s(yield t.logo)],["partOf",s(yield t.partOf)],["start",t.start]]}var dt=Object.freeze({__proto__:null,emptyAnnotation:rt,emptyAnnotationPage:ve,emptyCanvas:pe,emptyCollection:fe,emptyManifest:ce,emptyRange:he,emptyAgent:ue,defaultEntities:at,getDefaultEntities:me,normalize:pt,types:F,identifyResource:de,Traverse:M,UNSET:h,UNWRAP:k,serializedFieldsToObject:ye,serialize:ct,languageString2to3:m,serializeConfigPresentation2:ut,serializeConfigPresentation3:{Manifest:function*(t,e,{isTopLevel:i}){return i?[["@context","http://iiif.io/api/presentation/3/context.json"],...A(t),...yield*C(t),...yield*I(t),["items",yield t.items],["structures",s(yield t.structures)],["annotations",s(yield t.annotations)]]:[...A(t),...yield*C(t)]},Canvas:function*(t){return[...A(t),...yield*C(t),...yield*I(t),["items",yield t.items],["annotations",s(yield t.annotations)]]},Agent:function*(t){return[["id",t.id],["type","Agent"],["label",t.label],...yield*I(t)]},AnnotationPage:function*(t){return[...Object.entries(t).map(([i,n])=>[i,Array.isArray(n)?s(n):n]).filter(([i,n])=>i!=="items"),...yield*I(t),["items",yield t.items]]},Service:function*(t){return[[k,Ce(t)]]},Annotation:function*(t){return[...Object.entries(t).map(([i,n])=>[i,Array.isArray(n)?s(n):n]).filter(([i])=>i!=="body"),["body",yield t.body]]},ContentResource:function*(t){return[...A(t),...yield*C(t),...yield*I(t),["annotations",s(yield t.annotations)]]},AnnotationCollection:function*(t){return[["id",t.id],["type","AnnotationCollection"],["label",t.label]]},Collection:function*(t,e,{isTopLevel:i}){return i?[["@context","http://iiif.io/api/presentation/3/context.json"],...A(t),...yield*C(t),...yield*I(t),["items",s(yield t.items)]]:[...A(t),...yield*C(t)]},Range:function*(t){const e=[];for(const i of t.items)i.type==="Range"?e.push(yield i):e.push(i);return[...A(t),...yield*C(t),...yield*I(t),["items",e],["annotations",s(yield t.annotations)]]}}}),mt={Presentation2:nt,Presentation3:dt};return mt});

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const l=["sc:Collection","sc:Manifest","sc:Canvas","oa:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function I(e){if(typeof e=="undefined"||e===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(e))throw new Error("Array is not a valid entity");if(typeof e!="object")throw new Error(`${typeof e} is not a valid entity`);if(typeof e["@type"]=="string"){const t=l.indexOf(e["@type"]);if(t!==-1)return l[t]}if(e.profile)return"Service";if(e.format||e["@type"])return"ContentResource";throw new Error("Resource type is not known")}class c{traversals;options;constructor(t,i={}){this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...t},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...i}}static all(t){return new c({collection:[t],manifest:[t],canvas:[t],annotationList:[t],sequence:[t],annotation:[t],contentResource:[t],choice:[t],range:[t],service:[t],layer:[t]})}traverseCollection(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(t))),this.traversals.collection)}traverseCollectionItems(t){if(this.options.mergeMemberProperties){const i=[...(t.manifests||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n),...(t.collections||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n),...t.members||[]];delete t.collections,delete t.manifests,t.members=i}return t.manifests&&(t.manifests=t.manifests.map(i=>this.traverseManifest(typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i))),t.collections&&(t.collections=t.collections.map(i=>this.traverseCollection(typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i))),t.members&&(t.members=t.members.map(i=>typeof i=="string"?i:this.traverseUnknown(i))),t}traverseManifest(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(t))),this.traversals.manifest)}traverseManifestItems(t){return t.sequences&&(t.sequences=t.sequences.map(i=>this.traverseSequence(i))),t.structures&&(t.structures=t.structures.map(i=>this.traverseRange(i))),t}traverseSequence(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(t))),this.traversals.sequence)}traverseSequenceItems(t){return t.canvases&&(t.canvases=t.canvases.map(i=>this.traverseCanvas(i))),t}traverseCanvas(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(t))),this.traversals.canvas)}traverseCanvasItems(t){return t.images&&(t.images=t.images.map(i=>this.traverseAnnotation(i))),t.otherContent&&(t.otherContent=t.otherContent.map(i=>this.traverseAnnotationList(i))),t}traverseRange(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(t))),this.traversals.range)}traverseRangeItems(t){if(this.options.mergeMemberProperties){const i=[...(t.ranges||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Range"}:n),...(t.canvases||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Canvas"}:n),...t.members||[]];delete t.ranges,delete t.canvases,t.members=i.length?i.map(n=>this.traverseUnknown(n)):void 0}return t}traverseAnnotationList(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationListItems(t))),this.traversals.annotationList)}traverseAnnotationListItems(t){return t.resources&&(t.resources=t.resources.map(i=>this.traverseAnnotation(i))),t}traverseAnnotation(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(t))),this.traversals.annotation)}traverseAnnotationItems(t){return t.resource&&(t.resource=this.traverseContentResource(t.resource)),t.on,t}traverseLayer(t){return this.traverseType(this.traverseLinking(this.traverseLayerItems(t)),this.traversals.layer)}traverseLayerItems(t){return t.otherContent&&(t.otherContent=t.otherContent.map(i=>this.traverseAnnotationList(i))),t}traverseChoice(t){return this.traverseType(this.traverseChoiceItems(t),this.traversals.choice)}traverseChoiceItems(t){return t.default&&t.default!=="rdf:nil"&&(t.default=this.traverseContentResource(t.default)),t.item&&t.item!=="rdf:nil"&&(t.item=t.item.map(i=>this.traverseContentResource(i))),t}traverseService(t){return this.traverseType(this.traverseLinking(t),this.traversals.service)}traverseContentResource(t){return t["@type"]==="oa:Choice"?this.traverseChoice(t):this.traverseType(this.traverseDescriptive(this.traverseLinking(t)),this.traversals.contentResource)}traverseUnknown(t){if(!t["@type"]||typeof t=="string")return t;switch(I(t)){case"sc:Collection":return this.traverseCollection(t);case"sc:Manifest":return this.traverseManifest(t);case"sc:Canvas":return this.traverseCanvas(t);case"sc:Sequence":return this.traverseSequence(t);case"sc:Range":return this.traverseRange(t);case"oa:Annotation":return this.traverseAnnotation(t);case"oa:AnnotationList":return this.traverseAnnotationList(t);case"sc:Layer":return this.traverseLayer(t);case"Service":return this.traverseService(t);case"oa:Choice":return this.traverseChoice(t);case"ContentResource":return this.traverseContentResource(t)}return t.profile?this.traverseService(t):t}traverseImageResource(t){const i=Array.isArray(t),n=Array.isArray(t)?t:[t],s=[];for(const r of n)typeof r=="string"?s.push(this.traverseContentResource({"@id":r,"@type":"dctypes:Image"})):s.push(this.traverseContentResource(r));return!i&&!this.options.convertPropsToArray?s[0]:s}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=this.traverseImageResource(t.thumbnail)),t.logo&&(t.logo=this.traverseImageResource(t.logo)),t}traverseOneOrMoreServices(t){const i=Array.isArray(t),n=Array.isArray(t)?t:[t],s=[];for(const r of n)s.push(this.traverseService(r));return!i&&!this.options.convertPropsToArray?s[0]:s}traverseLinking(t){return t.related&&(t.related=this.traverseOneOrManyType(t.related,this.traversals.contentResource)),t.rendering&&(t.rendering=this.traverseOneOrManyType(t.rendering,this.traversals.contentResource)),t.service&&(t.service=this.traverseOneOrMoreServices(t.service)),t.seeAlso&&(t.seeAlso=this.traverseOneOrManyType(t.seeAlso,this.traversals.contentResource)),t.within&&(typeof t.within=="string"||(t.within=this.traverseOneOrManyType(t.within,this.traversals.contentResource))),t.startCanvas&&(typeof t.startCanvas=="string"?t.startCanvas=this.traverseType({"@id":t.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):t.startCanvas&&this.traverseType(t.startCanvas,this.traversals.canvas)),t.contentLayer&&(typeof t.contentLayer=="string"?t.contentLayer=this.traverseLayer({"@id":t.contentLayer,"@type":"sc:Layer"}):t.contentLayer=this.traverseLayer(t.contentLayer)),t}traverseOneOrManyType(t,i){if(!Array.isArray(t))if(this.options.convertPropsToArray)t=[t];else return this.traverseType(t,i);return t.map(n=>this.traverseType(n,i))}traverseType(t,i){return i.reduce((n,s)=>{const r=s(n);return typeof r=="undefined"&&!this.options.allowUndefinedReturn?n:r},t)}}const W="http://library.stanford.edu/iiif/image-api/compliance.html#level0",y="http://library.stanford.edu/iiif/image-api/compliance.html#level1",_="http://library.stanford.edu/iiif/image-api/compliance.html#level2",$="http://library.stanford.edu/iiif/image-api/conformance.html#level0",A="http://library.stanford.edu/iiif/image-api/conformance.html#level1",L="http://library.stanford.edu/iiif/image-api/conformance.html#level2",H="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",E="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",C="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",B="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",M="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",O="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",J="http://iiif.io/api/image/1/level0.json",z="http://iiif.io/api/image/1/profiles/level0.json",x="http://iiif.io/api/image/1/level1.json",R="http://iiif.io/api/image/1/profiles/level1.json",F="http://iiif.io/api/image/1/level2.json",w="http://iiif.io/api/image/1/profiles/level2.json",K="http://iiif.io/api/image/2/level0.json",Q="http://iiif.io/api/image/2/profiles/level0.json",T="http://iiif.io/api/image/2/level1.json",S="http://iiif.io/api/image/2/profiles/level1.json",b="http://iiif.io/api/image/2/level2.json",N="http://iiif.io/api/image/2/profiles/level2.json",X="level0",k="level1",j="level2",Y="http://iiif.io/api/image/2/level0",G="http://iiif.io/api/image/2/level1",P="http://iiif.io/api/image/2/level2",Z=[G,P,y,_,A,L,E,C,M,O,x,R,F,w,T,S,b,N,k,j],tt=[Y,G,P,W,y,_,$,A,L,H,E,C,B,M,O,J,z,x,R,F,w,K,Q,T,S,b,N,X,k,j],u={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function h(e,t="none"){if(!e)return{};const i=Array.isArray(e)?e:[e],n={};for(const s of i){if(typeof s=="string"){n[t]=n[t]?n[t]:[],n[t].push(s||"");continue}if(!s["@language"]){n[t]=n[t]?n[t]:[],n[t].push(s["@value"]||"");continue}const r=s["@language"];n[r]=n[r]?n[r]:[],n[r].push(s["@value"]||"")}return n}function d(e){if(Array.isArray(e))return d(e.find(t=>typeof t=="string"));if(tt.indexOf(e)!==-1)return"level2";if(Z.indexOf(e)!==-1)return"level1";if(typeof e=="string")return e}function D(e){const t=Array.isArray(e)?e:[e];for(const i of t)switch(i){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function et(e){switch(e){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}function it(e){return Array.isArray(e)?e:[e]}function nt(e){for(const t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}function m(e){const t=e["@id"]||e.id;let i=e["@type"]||e.type;const n=e.profile||void 0,s=e["@context"]||void 0;if(n){const r=et(n);if(r)return r}if(s){const r=D(s);if(r)return r}if(i){if(Array.isArray(i)){if(i.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(i.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";i=i[0]}for(const r of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${r}:`)){i=i.slice(r.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(e.format){if(e.format.startsWith("image/"))return"Image";if(e.format.startsWith("text/")||e.format==="application/pdf")return"Text";if(e.format.startsWith("application/"))return"Dataset"}return t&&(t.endsWith(".jpg")||t.endsWith(".png")||t.endsWith(".jpeg"))?"Image":i||"unknown"}const rt=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function st(e){const t=e.match(rt);return t?t[0]:e}function at(e,t="Rights/License",i="none"){let n=null;const s=[],r=Array.isArray(e)?e:[e];for(const g of r){const f=g?st(g):void 0;if(f&&(f.indexOf("creativecommons.org")!==-1||f.indexOf("rightsstatements.org")!==-1)){f.startsWith("https://")?n=`http://${f.slice(8)}`:n=f;continue}f&&s.push({label:{[i]:[t]},value:{[i]:[f]}})}return[n,s]}const ot=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function pt(e){if(e){const t=Array.isArray(e)?e:[e],i=[];for(const n of t)n==="http://iiif.io/api/presentation/2/context.json"&&i.push("http://iiif.io/api/presentation/3/context.json"),ot.indexOf(n)===-1&&i.push(n);if(t.length)return i.length===1?i[0]:i}}function ft(e){return e?e.map(t=>({label:h(t.label),value:h(t.value)})):[]}function o(e){for(const t in e)(typeof e[t]=="undefined"||e[t]===null)&&delete e[t];return e}let V=0;function q(e,t){const i=encodeURI(e.id||e["@id"]||"").trim();return i&&t?`${i}/${t}`:i||(V++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${V}`)}function p(e){const t=[...e.behavior||[]];return e.viewingHint&&t.push(e.viewingHint),{"@context":e["@context"]?pt(e["@context"]):void 0,id:(e["@id"]||q(e)).trim(),type:m(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:e.motivation?nt(e.motivation):void 0,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function a(e){const[t,i]=at(e.license),n=[...e.metadata?ft(e.metadata):[],...i];return{rights:t,metadata:n.length?n:void 0,label:e.label?h(e.label):void 0,requiredStatement:e.attribution?{label:h(u.attributionLabel),value:h(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?h(e.description):void 0,thumbnail:e.thumbnail}}function ht(e){if(!e.within)return;const t=Array.isArray(e.within)?e.within:[e.within],i=[];for(const n of t)if(typeof n=="string"){if(n)switch(e["@type"]){case"sc:Manifest":i.push({id:n,type:"Collection"});break}}else n["@id"]&&i.push({id:n["@id"],type:m(n)});return i.length?i:void 0}function v(e){const t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],i=e.contentLayer;return{provider:e.logo||t.length?[{id:u.providerId,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:h(u.providerName)}]:void 0,partOf:ht(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?it(e.service):void 0,supplementary:i?[i]:void 0}}function vt(e){return o({...p(e),...a(e),...v(e),items:e.members})}function ct(e){const t=[],i=[];for(const s of e.sequences||[])s.canvases.length&&t.push(...s.canvases),s.behavior&&i.push(...s.behavior);const n=p(e);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),o({...n,...a(e),...v(e),items:t,structures:e.structures})}function lt(e){return o({...p(e),...a(e),...v(e),items:e.images&&e.images.length?[{id:q(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}function ut(e){return o({...p(e),...a(e),...v(e),items:e.resources})}function dt(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[]}}function mt(e){return o({...p(e),...a(e),...v(e),target:typeof e.on=="string"?encodeURI(e.on).trim():e.on,body:e.resource})}function gt(e){const t=e;return o({...p(t),...a(t),...v(t)})}function It(e){const t=[];return e.default&&e.default!=="rdf:nil"&&t.push(e.default),e.item&&e.item!=="rdf:nil"&&t.push(...e.item),{...p(e),...a(e),items:t}}function yt(e){return o({...p(e),...a(e),...v(e),items:e.members})}function _t(e){const{"@id":t,"@type":i,"@context":n,profile:s,...r}=e;return t&&(r.id=t),r.type=m(e),r.type==="unknown"&&(r.type="Service"),s&&(r.profile=d(s)),o({...r,...a(r)})}function At(e){return o({...p(e),...a(e),...v(e)})}const U=new c({collection:[vt],manifest:[ct],canvas:[lt],annotationList:[ut],sequence:[dt],annotation:[mt],contentResource:[gt],choice:[It],range:[yt],service:[_t],layer:[At]});function Lt(e){return e&&e["@context"]&&(e["@context"]==="http://iiif.io/api/presentation/2/context.json"||e["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")!==-1||e["@context"]==="http://www.shared-canvas.org/ns/context.json")||e["@context"]==="http://iiif.io/api/image/2/context.json"?U.traverseUnknown(e):e}exports.Traverse=c,exports.convertLanguageMapping=h,exports.convertPresentation2=Lt,exports.getProfile=d,exports.getTypeFromContext=D,exports.identifyResource=I,exports.presentation2to3=U,exports.types=l;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const l=["sc:Collection","sc:Manifest","sc:Canvas","oa:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function I(e){if(typeof e=="undefined"||e===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(e))throw new Error("Array is not a valid entity");if(typeof e!="object")throw new Error(`${typeof e} is not a valid entity`);if(typeof e["@type"]=="string"){const t=l.indexOf(e["@type"]);if(t!==-1)return l[t]}if(e.profile)return"Service";if(e.format||e["@type"])return"ContentResource";throw new Error("Resource type is not known")}class c{traversals;options;constructor(t,i={}){this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...t},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...i}}static all(t){return new c({collection:[t],manifest:[t],canvas:[t],annotationList:[t],sequence:[t],annotation:[t],contentResource:[t],choice:[t],range:[t],service:[t],layer:[t]})}traverseCollection(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(t))),this.traversals.collection)}traverseCollectionItems(t){if(this.options.mergeMemberProperties){const i=[...(t.manifests||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n),...(t.collections||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n),...t.members||[]];delete t.collections,delete t.manifests,t.members=i}return t.manifests&&(t.manifests=t.manifests.map(i=>this.traverseManifest(typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i))),t.collections&&(t.collections=t.collections.map(i=>this.traverseCollection(typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i))),t.members&&(t.members=t.members.map(i=>typeof i=="string"?i:this.traverseUnknown(i))),t}traverseManifest(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(t))),this.traversals.manifest)}traverseManifestItems(t){return t.sequences&&(t.sequences=t.sequences.map(i=>this.traverseSequence(i))),t.structures&&(t.structures=t.structures.map(i=>this.traverseRange(i))),t}traverseSequence(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(t))),this.traversals.sequence)}traverseSequenceItems(t){return t.canvases&&(t.canvases=t.canvases.map(i=>this.traverseCanvas(i))),t}traverseCanvas(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(t))),this.traversals.canvas)}traverseCanvasItems(t){return t.images&&(t.images=t.images.map(i=>this.traverseAnnotation(i))),t.otherContent&&(t.otherContent=t.otherContent.map(i=>this.traverseAnnotationList(i))),t}traverseRange(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(t))),this.traversals.range)}traverseRangeItems(t){if(this.options.mergeMemberProperties){const i=[...(t.ranges||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Range"}:n),...(t.canvases||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Canvas"}:n),...t.members||[]];delete t.ranges,delete t.canvases,t.members=i.length?i.map(n=>this.traverseUnknown(n)):void 0}return t}traverseAnnotationList(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationListItems(t))),this.traversals.annotationList)}traverseAnnotationListItems(t){return t.resources&&(t.resources=t.resources.map(i=>this.traverseAnnotation(i))),t}traverseAnnotation(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(t))),this.traversals.annotation)}traverseAnnotationItems(t){return t.resource&&(t.resource=this.traverseContentResource(t.resource)),t.on,t}traverseLayer(t){return this.traverseType(this.traverseLinking(this.traverseLayerItems(t)),this.traversals.layer)}traverseLayerItems(t){return t.otherContent&&(t.otherContent=t.otherContent.map(i=>this.traverseAnnotationList(i))),t}traverseChoice(t){return this.traverseType(this.traverseChoiceItems(t),this.traversals.choice)}traverseChoiceItems(t){return t.default&&t.default!=="rdf:nil"&&(t.default=this.traverseContentResource(t.default)),t.item&&t.item!=="rdf:nil"&&(t.item=t.item.map(i=>this.traverseContentResource(i))),t}traverseService(t){return this.traverseType(this.traverseLinking(t),this.traversals.service)}traverseContentResource(t){return t["@type"]==="oa:Choice"?this.traverseChoice(t):this.traverseType(this.traverseDescriptive(this.traverseLinking(t)),this.traversals.contentResource)}traverseUnknown(t){if(!t["@type"]||typeof t=="string")return t;switch(I(t)){case"sc:Collection":return this.traverseCollection(t);case"sc:Manifest":return this.traverseManifest(t);case"sc:Canvas":return this.traverseCanvas(t);case"sc:Sequence":return this.traverseSequence(t);case"sc:Range":return this.traverseRange(t);case"oa:Annotation":return this.traverseAnnotation(t);case"oa:AnnotationList":return this.traverseAnnotationList(t);case"sc:Layer":return this.traverseLayer(t);case"Service":return this.traverseService(t);case"oa:Choice":return this.traverseChoice(t);case"ContentResource":return this.traverseContentResource(t)}return t.profile?this.traverseService(t):t}traverseImageResource(t){const i=Array.isArray(t),n=Array.isArray(t)?t:[t],s=[];for(const r of n)typeof r=="string"?s.push(this.traverseContentResource({"@id":r,"@type":"dctypes:Image"})):s.push(this.traverseContentResource(r));return!i&&!this.options.convertPropsToArray?s[0]:s}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=this.traverseImageResource(t.thumbnail)),t.logo&&(t.logo=this.traverseImageResource(t.logo)),t}traverseOneOrMoreServices(t){const i=Array.isArray(t),n=Array.isArray(t)?t:[t],s=[];for(const r of n)s.push(this.traverseService(r));return!i&&!this.options.convertPropsToArray?s[0]:s}traverseLinking(t){return t.related&&(t.related=this.traverseOneOrManyType(t.related,this.traversals.contentResource)),t.rendering&&(t.rendering=this.traverseOneOrManyType(t.rendering,this.traversals.contentResource)),t.service&&(t.service=this.traverseOneOrMoreServices(t.service)),t.seeAlso&&(t.seeAlso=this.traverseOneOrManyType(t.seeAlso,this.traversals.contentResource)),t.within&&(typeof t.within=="string"||(t.within=this.traverseOneOrManyType(t.within,this.traversals.contentResource))),t.startCanvas&&(typeof t.startCanvas=="string"?t.startCanvas=this.traverseType({"@id":t.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):t.startCanvas&&this.traverseType(t.startCanvas,this.traversals.canvas)),t.contentLayer&&(typeof t.contentLayer=="string"?t.contentLayer=this.traverseLayer({"@id":t.contentLayer,"@type":"sc:Layer"}):t.contentLayer=this.traverseLayer(t.contentLayer)),t}traverseOneOrManyType(t,i){if(!Array.isArray(t))if(this.options.convertPropsToArray)t=[t];else return this.traverseType(t,i);return t.map(n=>this.traverseType(n,i))}traverseType(t,i){return i.reduce((n,s)=>{const r=s(n);return typeof r=="undefined"&&!this.options.allowUndefinedReturn?n:r},t)}}const W="http://library.stanford.edu/iiif/image-api/compliance.html#level0",y="http://library.stanford.edu/iiif/image-api/compliance.html#level1",_="http://library.stanford.edu/iiif/image-api/compliance.html#level2",$="http://library.stanford.edu/iiif/image-api/conformance.html#level0",A="http://library.stanford.edu/iiif/image-api/conformance.html#level1",L="http://library.stanford.edu/iiif/image-api/conformance.html#level2",H="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",E="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",C="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",B="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",M="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",O="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",J="http://iiif.io/api/image/1/level0.json",z="http://iiif.io/api/image/1/profiles/level0.json",x="http://iiif.io/api/image/1/level1.json",R="http://iiif.io/api/image/1/profiles/level1.json",F="http://iiif.io/api/image/1/level2.json",w="http://iiif.io/api/image/1/profiles/level2.json",K="http://iiif.io/api/image/2/level0.json",Q="http://iiif.io/api/image/2/profiles/level0.json",T="http://iiif.io/api/image/2/level1.json",S="http://iiif.io/api/image/2/profiles/level1.json",b="http://iiif.io/api/image/2/level2.json",N="http://iiif.io/api/image/2/profiles/level2.json",X="level0",k="level1",j="level2",Y="http://iiif.io/api/image/2/level0",G="http://iiif.io/api/image/2/level1",P="http://iiif.io/api/image/2/level2",Z=[G,P,y,_,A,L,E,C,M,O,x,R,F,w,T,S,b,N,k,j],tt=[Y,G,P,W,y,_,$,A,L,H,E,C,B,M,O,J,z,x,R,F,w,K,Q,T,S,b,N,X,k,j],u={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function h(e,t="none"){if(!e)return{};const i=Array.isArray(e)?e:[e],n={};for(const s of i){if(typeof s=="string"){n[t]=n[t]?n[t]:[],n[t].push(s||"");continue}if(!s["@language"]){n[t]=n[t]?n[t]:[],n[t].push(s["@value"]||"");continue}const r=s["@language"];n[r]=n[r]?n[r]:[],n[r].push(s["@value"]||"")}return n}function d(e){if(Array.isArray(e))return d(e.find(t=>typeof t=="string"));if(tt.indexOf(e)!==-1)return"level2";if(Z.indexOf(e)!==-1)return"level1";if(typeof e=="string")return e}function D(e){const t=Array.isArray(e)?e:[e];for(const i of t)switch(i){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function et(e){switch(e){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}function it(e){return Array.isArray(e)?e:[e]}function nt(e){for(const t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}const rt=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function m(e){const t=e["@id"]||e.id;let i=e["@type"]||e.type;const n=e.profile||void 0,s=e["@context"]||void 0;if(n){const r=et(n);if(r)return r}if(s){const r=D(s);if(r)return r}if(i){if(Array.isArray(i)){if(i.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(i.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";i=i[0]}for(const r of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${r}:`)){i=i.slice(r.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(i&&rt.indexOf(i)!==-1)return i;if(e.format){if(e.format.startsWith("image/"))return"Image";if(e.format.startsWith("text/")||e.format==="application/pdf")return"Text";if(e.format.startsWith("application/"))return"Dataset"}return t&&(t.endsWith(".jpg")||t.endsWith(".png")||t.endsWith(".jpeg"))?"Image":i||"unknown"}const st=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function at(e){const t=e.match(st);return t?t[0]:e}function ot(e,t="Rights/License",i="none"){let n=null;const s=[],r=Array.isArray(e)?e:[e];for(const g of r){const f=g?at(g):void 0;if(f&&(f.indexOf("creativecommons.org")!==-1||f.indexOf("rightsstatements.org")!==-1)){f.startsWith("https://")?n=`http://${f.slice(8)}`:n=f;continue}f&&s.push({label:{[i]:[t]},value:{[i]:[f]}})}return[n,s]}const pt=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function ft(e){if(e){const t=Array.isArray(e)?e:[e],i=[];for(const n of t)n==="http://iiif.io/api/presentation/2/context.json"&&i.push("http://iiif.io/api/presentation/3/context.json"),pt.indexOf(n)===-1&&i.push(n);if(t.length)return i.length===1?i[0]:i}}function ht(e){return e?e.map(t=>({label:h(t.label),value:h(t.value)})):[]}function o(e){for(const t in e)(typeof e[t]=="undefined"||e[t]===null)&&delete e[t];return e}let V=0;function q(e,t){const i=encodeURI(e.id||e["@id"]||"").trim();return i&&t?`${i}/${t}`:i||(V++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${V}`)}function p(e){const t=[...e.behavior||[]];return e.viewingHint&&t.push(e.viewingHint),{"@context":e["@context"]?ft(e["@context"]):void 0,id:(e["@id"]||q(e)).trim(),type:m(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:e.motivation?nt(e.motivation):void 0,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function a(e){const[t,i]=ot(e.license),n=[...e.metadata?ht(e.metadata):[],...i];return{rights:t,metadata:n.length?n:void 0,label:e.label?h(e.label):void 0,requiredStatement:e.attribution?{label:h(u.attributionLabel),value:h(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?h(e.description):void 0,thumbnail:e.thumbnail}}function vt(e){if(!e.within)return;const t=Array.isArray(e.within)?e.within:[e.within],i=[];for(const n of t)if(typeof n=="string"){if(n)switch(e["@type"]){case"sc:Manifest":i.push({id:n,type:"Collection"});break}}else n["@id"]&&i.push({id:n["@id"],type:m(n)});return i.length?i:void 0}function v(e){const t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],i=e.contentLayer;return{provider:e.logo||t.length?[{id:u.providerId,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:h(u.providerName)}]:void 0,partOf:vt(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?it(e.service):void 0,supplementary:i?[i]:void 0}}function ct(e){return o({...p(e),...a(e),...v(e),items:e.members})}function lt(e){const t=[],i=[];for(const s of e.sequences||[])s.canvases.length&&t.push(...s.canvases),s.behavior&&i.push(...s.behavior);const n=p(e);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),o({...n,...a(e),...v(e),items:t,structures:e.structures})}function ut(e){return o({...p(e),...a(e),...v(e),items:e.images&&e.images.length?[{id:q(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}function dt(e){return o({...p(e),...a(e),...v(e),items:e.resources})}function mt(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[]}}function gt(e){return o({...p(e),...a(e),...v(e),target:typeof e.on=="string"?encodeURI(e.on).trim():e.on,body:e.resource})}function It(e){const t=e;return o({...p(t),...a(t),...v(t)})}function yt(e){const t=[];return e.default&&e.default!=="rdf:nil"&&t.push(e.default),e.item&&e.item!=="rdf:nil"&&t.push(...e.item),{...p(e),...a(e),items:t}}function _t(e){return o({...p(e),...a(e),...v(e),items:e.members})}function At(e){const{"@id":t,"@type":i,"@context":n,profile:s,...r}=e;return t&&(r.id=t),r.type=m(e),r.type==="unknown"&&(r.type="Service"),s&&(r.profile=d(s)),o({...r,...a(r)})}function Lt(e){return o({...p(e),...a(e),...v(e)})}const U=new c({collection:[ct],manifest:[lt],canvas:[ut],annotationList:[dt],sequence:[mt],annotation:[gt],contentResource:[It],choice:[yt],range:[_t],service:[At],layer:[Lt]});function Et(e){return e&&e["@context"]&&(e["@context"]==="http://iiif.io/api/presentation/2/context.json"||e["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")!==-1||e["@context"]==="http://www.shared-canvas.org/ns/context.json")||e["@context"]==="http://iiif.io/api/image/2/context.json"?U.traverseUnknown(e):e}exports.Traverse=c,exports.convertLanguageMapping=h,exports.convertPresentation2=Et,exports.getProfile=d,exports.getTypeFromContext=D,exports.identifyResource=I,exports.presentation2to3=U,exports.types=l;

@@ -1,1 +0,1 @@

const l=["sc:Collection","sc:Manifest","sc:Canvas","oa:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function I(e){if(typeof e=="undefined"||e===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(e))throw new Error("Array is not a valid entity");if(typeof e!="object")throw new Error(`${typeof e} is not a valid entity`);if(typeof e["@type"]=="string"){const t=l.indexOf(e["@type"]);if(t!==-1)return l[t]}if(e.profile)return"Service";if(e.format||e["@type"])return"ContentResource";throw new Error("Resource type is not known")}class c{traversals;options;constructor(t,i={}){this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...t},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...i}}static all(t){return new c({collection:[t],manifest:[t],canvas:[t],annotationList:[t],sequence:[t],annotation:[t],contentResource:[t],choice:[t],range:[t],service:[t],layer:[t]})}traverseCollection(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(t))),this.traversals.collection)}traverseCollectionItems(t){if(this.options.mergeMemberProperties){const i=[...(t.manifests||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n),...(t.collections||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n),...t.members||[]];delete t.collections,delete t.manifests,t.members=i}return t.manifests&&(t.manifests=t.manifests.map(i=>this.traverseManifest(typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i))),t.collections&&(t.collections=t.collections.map(i=>this.traverseCollection(typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i))),t.members&&(t.members=t.members.map(i=>typeof i=="string"?i:this.traverseUnknown(i))),t}traverseManifest(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(t))),this.traversals.manifest)}traverseManifestItems(t){return t.sequences&&(t.sequences=t.sequences.map(i=>this.traverseSequence(i))),t.structures&&(t.structures=t.structures.map(i=>this.traverseRange(i))),t}traverseSequence(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(t))),this.traversals.sequence)}traverseSequenceItems(t){return t.canvases&&(t.canvases=t.canvases.map(i=>this.traverseCanvas(i))),t}traverseCanvas(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(t))),this.traversals.canvas)}traverseCanvasItems(t){return t.images&&(t.images=t.images.map(i=>this.traverseAnnotation(i))),t.otherContent&&(t.otherContent=t.otherContent.map(i=>this.traverseAnnotationList(i))),t}traverseRange(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(t))),this.traversals.range)}traverseRangeItems(t){if(this.options.mergeMemberProperties){const i=[...(t.ranges||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Range"}:n),...(t.canvases||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Canvas"}:n),...t.members||[]];delete t.ranges,delete t.canvases,t.members=i.length?i.map(n=>this.traverseUnknown(n)):void 0}return t}traverseAnnotationList(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationListItems(t))),this.traversals.annotationList)}traverseAnnotationListItems(t){return t.resources&&(t.resources=t.resources.map(i=>this.traverseAnnotation(i))),t}traverseAnnotation(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(t))),this.traversals.annotation)}traverseAnnotationItems(t){return t.resource&&(t.resource=this.traverseContentResource(t.resource)),t.on,t}traverseLayer(t){return this.traverseType(this.traverseLinking(this.traverseLayerItems(t)),this.traversals.layer)}traverseLayerItems(t){return t.otherContent&&(t.otherContent=t.otherContent.map(i=>this.traverseAnnotationList(i))),t}traverseChoice(t){return this.traverseType(this.traverseChoiceItems(t),this.traversals.choice)}traverseChoiceItems(t){return t.default&&t.default!=="rdf:nil"&&(t.default=this.traverseContentResource(t.default)),t.item&&t.item!=="rdf:nil"&&(t.item=t.item.map(i=>this.traverseContentResource(i))),t}traverseService(t){return this.traverseType(this.traverseLinking(t),this.traversals.service)}traverseContentResource(t){return t["@type"]==="oa:Choice"?this.traverseChoice(t):this.traverseType(this.traverseDescriptive(this.traverseLinking(t)),this.traversals.contentResource)}traverseUnknown(t){if(!t["@type"]||typeof t=="string")return t;switch(I(t)){case"sc:Collection":return this.traverseCollection(t);case"sc:Manifest":return this.traverseManifest(t);case"sc:Canvas":return this.traverseCanvas(t);case"sc:Sequence":return this.traverseSequence(t);case"sc:Range":return this.traverseRange(t);case"oa:Annotation":return this.traverseAnnotation(t);case"oa:AnnotationList":return this.traverseAnnotationList(t);case"sc:Layer":return this.traverseLayer(t);case"Service":return this.traverseService(t);case"oa:Choice":return this.traverseChoice(t);case"ContentResource":return this.traverseContentResource(t)}return t.profile?this.traverseService(t):t}traverseImageResource(t){const i=Array.isArray(t),n=Array.isArray(t)?t:[t],s=[];for(const r of n)typeof r=="string"?s.push(this.traverseContentResource({"@id":r,"@type":"dctypes:Image"})):s.push(this.traverseContentResource(r));return!i&&!this.options.convertPropsToArray?s[0]:s}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=this.traverseImageResource(t.thumbnail)),t.logo&&(t.logo=this.traverseImageResource(t.logo)),t}traverseOneOrMoreServices(t){const i=Array.isArray(t),n=Array.isArray(t)?t:[t],s=[];for(const r of n)s.push(this.traverseService(r));return!i&&!this.options.convertPropsToArray?s[0]:s}traverseLinking(t){return t.related&&(t.related=this.traverseOneOrManyType(t.related,this.traversals.contentResource)),t.rendering&&(t.rendering=this.traverseOneOrManyType(t.rendering,this.traversals.contentResource)),t.service&&(t.service=this.traverseOneOrMoreServices(t.service)),t.seeAlso&&(t.seeAlso=this.traverseOneOrManyType(t.seeAlso,this.traversals.contentResource)),t.within&&(typeof t.within=="string"||(t.within=this.traverseOneOrManyType(t.within,this.traversals.contentResource))),t.startCanvas&&(typeof t.startCanvas=="string"?t.startCanvas=this.traverseType({"@id":t.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):t.startCanvas&&this.traverseType(t.startCanvas,this.traversals.canvas)),t.contentLayer&&(typeof t.contentLayer=="string"?t.contentLayer=this.traverseLayer({"@id":t.contentLayer,"@type":"sc:Layer"}):t.contentLayer=this.traverseLayer(t.contentLayer)),t}traverseOneOrManyType(t,i){if(!Array.isArray(t))if(this.options.convertPropsToArray)t=[t];else return this.traverseType(t,i);return t.map(n=>this.traverseType(n,i))}traverseType(t,i){return i.reduce((n,s)=>{const r=s(n);return typeof r=="undefined"&&!this.options.allowUndefinedReturn?n:r},t)}}const W="http://library.stanford.edu/iiif/image-api/compliance.html#level0",y="http://library.stanford.edu/iiif/image-api/compliance.html#level1",_="http://library.stanford.edu/iiif/image-api/compliance.html#level2",$="http://library.stanford.edu/iiif/image-api/conformance.html#level0",A="http://library.stanford.edu/iiif/image-api/conformance.html#level1",L="http://library.stanford.edu/iiif/image-api/conformance.html#level2",H="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",E="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",C="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",B="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",M="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",O="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",J="http://iiif.io/api/image/1/level0.json",z="http://iiif.io/api/image/1/profiles/level0.json",x="http://iiif.io/api/image/1/level1.json",R="http://iiif.io/api/image/1/profiles/level1.json",F="http://iiif.io/api/image/1/level2.json",w="http://iiif.io/api/image/1/profiles/level2.json",K="http://iiif.io/api/image/2/level0.json",Q="http://iiif.io/api/image/2/profiles/level0.json",T="http://iiif.io/api/image/2/level1.json",S="http://iiif.io/api/image/2/profiles/level1.json",b="http://iiif.io/api/image/2/level2.json",N="http://iiif.io/api/image/2/profiles/level2.json",X="level0",k="level1",G="level2",Y="http://iiif.io/api/image/2/level0",j="http://iiif.io/api/image/2/level1",D="http://iiif.io/api/image/2/level2",Z=[j,D,y,_,A,L,E,C,M,O,x,R,F,w,T,S,b,N,k,G],tt=[Y,j,D,W,y,_,$,A,L,H,E,C,B,M,O,J,z,x,R,F,w,K,Q,T,S,b,N,X,k,G],u={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function h(e,t="none"){if(!e)return{};const i=Array.isArray(e)?e:[e],n={};for(const s of i){if(typeof s=="string"){n[t]=n[t]?n[t]:[],n[t].push(s||"");continue}if(!s["@language"]){n[t]=n[t]?n[t]:[],n[t].push(s["@value"]||"");continue}const r=s["@language"];n[r]=n[r]?n[r]:[],n[r].push(s["@value"]||"")}return n}function d(e){if(Array.isArray(e))return d(e.find(t=>typeof t=="string"));if(tt.indexOf(e)!==-1)return"level2";if(Z.indexOf(e)!==-1)return"level1";if(typeof e=="string")return e}function P(e){const t=Array.isArray(e)?e:[e];for(const i of t)switch(i){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function et(e){switch(e){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}function it(e){return Array.isArray(e)?e:[e]}function nt(e){for(const t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}function m(e){const t=e["@id"]||e.id;let i=e["@type"]||e.type;const n=e.profile||void 0,s=e["@context"]||void 0;if(n){const r=et(n);if(r)return r}if(s){const r=P(s);if(r)return r}if(i){if(Array.isArray(i)){if(i.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(i.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";i=i[0]}for(const r of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${r}:`)){i=i.slice(r.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(e.format){if(e.format.startsWith("image/"))return"Image";if(e.format.startsWith("text/")||e.format==="application/pdf")return"Text";if(e.format.startsWith("application/"))return"Dataset"}return t&&(t.endsWith(".jpg")||t.endsWith(".png")||t.endsWith(".jpeg"))?"Image":i||"unknown"}const rt=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function st(e){const t=e.match(rt);return t?t[0]:e}function at(e,t="Rights/License",i="none"){let n=null;const s=[],r=Array.isArray(e)?e:[e];for(const g of r){const f=g?st(g):void 0;if(f&&(f.indexOf("creativecommons.org")!==-1||f.indexOf("rightsstatements.org")!==-1)){f.startsWith("https://")?n=`http://${f.slice(8)}`:n=f;continue}f&&s.push({label:{[i]:[t]},value:{[i]:[f]}})}return[n,s]}const ot=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function pt(e){if(e){const t=Array.isArray(e)?e:[e],i=[];for(const n of t)n==="http://iiif.io/api/presentation/2/context.json"&&i.push("http://iiif.io/api/presentation/3/context.json"),ot.indexOf(n)===-1&&i.push(n);if(t.length)return i.length===1?i[0]:i}}function ft(e){return e?e.map(t=>({label:h(t.label),value:h(t.value)})):[]}function o(e){for(const t in e)(typeof e[t]=="undefined"||e[t]===null)&&delete e[t];return e}let V=0;function q(e,t){const i=encodeURI(e.id||e["@id"]||"").trim();return i&&t?`${i}/${t}`:i||(V++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${V}`)}function p(e){const t=[...e.behavior||[]];return e.viewingHint&&t.push(e.viewingHint),{"@context":e["@context"]?pt(e["@context"]):void 0,id:(e["@id"]||q(e)).trim(),type:m(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:e.motivation?nt(e.motivation):void 0,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function a(e){const[t,i]=at(e.license),n=[...e.metadata?ft(e.metadata):[],...i];return{rights:t,metadata:n.length?n:void 0,label:e.label?h(e.label):void 0,requiredStatement:e.attribution?{label:h(u.attributionLabel),value:h(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?h(e.description):void 0,thumbnail:e.thumbnail}}function ht(e){if(!e.within)return;const t=Array.isArray(e.within)?e.within:[e.within],i=[];for(const n of t)if(typeof n=="string"){if(n)switch(e["@type"]){case"sc:Manifest":i.push({id:n,type:"Collection"});break}}else n["@id"]&&i.push({id:n["@id"],type:m(n)});return i.length?i:void 0}function v(e){const t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],i=e.contentLayer;return{provider:e.logo||t.length?[{id:u.providerId,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:h(u.providerName)}]:void 0,partOf:ht(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?it(e.service):void 0,supplementary:i?[i]:void 0}}function vt(e){return o({...p(e),...a(e),...v(e),items:e.members})}function ct(e){const t=[],i=[];for(const s of e.sequences||[])s.canvases.length&&t.push(...s.canvases),s.behavior&&i.push(...s.behavior);const n=p(e);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),o({...n,...a(e),...v(e),items:t,structures:e.structures})}function lt(e){return o({...p(e),...a(e),...v(e),items:e.images&&e.images.length?[{id:q(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}function ut(e){return o({...p(e),...a(e),...v(e),items:e.resources})}function dt(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[]}}function mt(e){return o({...p(e),...a(e),...v(e),target:typeof e.on=="string"?encodeURI(e.on).trim():e.on,body:e.resource})}function gt(e){const t=e;return o({...p(t),...a(t),...v(t)})}function It(e){const t=[];return e.default&&e.default!=="rdf:nil"&&t.push(e.default),e.item&&e.item!=="rdf:nil"&&t.push(...e.item),{...p(e),...a(e),items:t}}function yt(e){return o({...p(e),...a(e),...v(e),items:e.members})}function _t(e){const{"@id":t,"@type":i,"@context":n,profile:s,...r}=e;return t&&(r.id=t),r.type=m(e),r.type==="unknown"&&(r.type="Service"),s&&(r.profile=d(s)),o({...r,...a(r)})}function At(e){return o({...p(e),...a(e),...v(e)})}const U=new c({collection:[vt],manifest:[ct],canvas:[lt],annotationList:[ut],sequence:[dt],annotation:[mt],contentResource:[gt],choice:[It],range:[yt],service:[_t],layer:[At]});function Lt(e){return e&&e["@context"]&&(e["@context"]==="http://iiif.io/api/presentation/2/context.json"||e["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")!==-1||e["@context"]==="http://www.shared-canvas.org/ns/context.json")||e["@context"]==="http://iiif.io/api/image/2/context.json"?U.traverseUnknown(e):e}export{c as Traverse,h as convertLanguageMapping,Lt as convertPresentation2,d as getProfile,P as getTypeFromContext,I as identifyResource,U as presentation2to3,l as types};
const l=["sc:Collection","sc:Manifest","sc:Canvas","oa:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function I(e){if(typeof e=="undefined"||e===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(e))throw new Error("Array is not a valid entity");if(typeof e!="object")throw new Error(`${typeof e} is not a valid entity`);if(typeof e["@type"]=="string"){const t=l.indexOf(e["@type"]);if(t!==-1)return l[t]}if(e.profile)return"Service";if(e.format||e["@type"])return"ContentResource";throw new Error("Resource type is not known")}class c{traversals;options;constructor(t,i={}){this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...t},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...i}}static all(t){return new c({collection:[t],manifest:[t],canvas:[t],annotationList:[t],sequence:[t],annotation:[t],contentResource:[t],choice:[t],range:[t],service:[t],layer:[t]})}traverseCollection(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(t))),this.traversals.collection)}traverseCollectionItems(t){if(this.options.mergeMemberProperties){const i=[...(t.manifests||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n),...(t.collections||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n),...t.members||[]];delete t.collections,delete t.manifests,t.members=i}return t.manifests&&(t.manifests=t.manifests.map(i=>this.traverseManifest(typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i))),t.collections&&(t.collections=t.collections.map(i=>this.traverseCollection(typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i))),t.members&&(t.members=t.members.map(i=>typeof i=="string"?i:this.traverseUnknown(i))),t}traverseManifest(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(t))),this.traversals.manifest)}traverseManifestItems(t){return t.sequences&&(t.sequences=t.sequences.map(i=>this.traverseSequence(i))),t.structures&&(t.structures=t.structures.map(i=>this.traverseRange(i))),t}traverseSequence(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(t))),this.traversals.sequence)}traverseSequenceItems(t){return t.canvases&&(t.canvases=t.canvases.map(i=>this.traverseCanvas(i))),t}traverseCanvas(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(t))),this.traversals.canvas)}traverseCanvasItems(t){return t.images&&(t.images=t.images.map(i=>this.traverseAnnotation(i))),t.otherContent&&(t.otherContent=t.otherContent.map(i=>this.traverseAnnotationList(i))),t}traverseRange(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(t))),this.traversals.range)}traverseRangeItems(t){if(this.options.mergeMemberProperties){const i=[...(t.ranges||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Range"}:n),...(t.canvases||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Canvas"}:n),...t.members||[]];delete t.ranges,delete t.canvases,t.members=i.length?i.map(n=>this.traverseUnknown(n)):void 0}return t}traverseAnnotationList(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationListItems(t))),this.traversals.annotationList)}traverseAnnotationListItems(t){return t.resources&&(t.resources=t.resources.map(i=>this.traverseAnnotation(i))),t}traverseAnnotation(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(t))),this.traversals.annotation)}traverseAnnotationItems(t){return t.resource&&(t.resource=this.traverseContentResource(t.resource)),t.on,t}traverseLayer(t){return this.traverseType(this.traverseLinking(this.traverseLayerItems(t)),this.traversals.layer)}traverseLayerItems(t){return t.otherContent&&(t.otherContent=t.otherContent.map(i=>this.traverseAnnotationList(i))),t}traverseChoice(t){return this.traverseType(this.traverseChoiceItems(t),this.traversals.choice)}traverseChoiceItems(t){return t.default&&t.default!=="rdf:nil"&&(t.default=this.traverseContentResource(t.default)),t.item&&t.item!=="rdf:nil"&&(t.item=t.item.map(i=>this.traverseContentResource(i))),t}traverseService(t){return this.traverseType(this.traverseLinking(t),this.traversals.service)}traverseContentResource(t){return t["@type"]==="oa:Choice"?this.traverseChoice(t):this.traverseType(this.traverseDescriptive(this.traverseLinking(t)),this.traversals.contentResource)}traverseUnknown(t){if(!t["@type"]||typeof t=="string")return t;switch(I(t)){case"sc:Collection":return this.traverseCollection(t);case"sc:Manifest":return this.traverseManifest(t);case"sc:Canvas":return this.traverseCanvas(t);case"sc:Sequence":return this.traverseSequence(t);case"sc:Range":return this.traverseRange(t);case"oa:Annotation":return this.traverseAnnotation(t);case"oa:AnnotationList":return this.traverseAnnotationList(t);case"sc:Layer":return this.traverseLayer(t);case"Service":return this.traverseService(t);case"oa:Choice":return this.traverseChoice(t);case"ContentResource":return this.traverseContentResource(t)}return t.profile?this.traverseService(t):t}traverseImageResource(t){const i=Array.isArray(t),n=Array.isArray(t)?t:[t],s=[];for(const r of n)typeof r=="string"?s.push(this.traverseContentResource({"@id":r,"@type":"dctypes:Image"})):s.push(this.traverseContentResource(r));return!i&&!this.options.convertPropsToArray?s[0]:s}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=this.traverseImageResource(t.thumbnail)),t.logo&&(t.logo=this.traverseImageResource(t.logo)),t}traverseOneOrMoreServices(t){const i=Array.isArray(t),n=Array.isArray(t)?t:[t],s=[];for(const r of n)s.push(this.traverseService(r));return!i&&!this.options.convertPropsToArray?s[0]:s}traverseLinking(t){return t.related&&(t.related=this.traverseOneOrManyType(t.related,this.traversals.contentResource)),t.rendering&&(t.rendering=this.traverseOneOrManyType(t.rendering,this.traversals.contentResource)),t.service&&(t.service=this.traverseOneOrMoreServices(t.service)),t.seeAlso&&(t.seeAlso=this.traverseOneOrManyType(t.seeAlso,this.traversals.contentResource)),t.within&&(typeof t.within=="string"||(t.within=this.traverseOneOrManyType(t.within,this.traversals.contentResource))),t.startCanvas&&(typeof t.startCanvas=="string"?t.startCanvas=this.traverseType({"@id":t.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):t.startCanvas&&this.traverseType(t.startCanvas,this.traversals.canvas)),t.contentLayer&&(typeof t.contentLayer=="string"?t.contentLayer=this.traverseLayer({"@id":t.contentLayer,"@type":"sc:Layer"}):t.contentLayer=this.traverseLayer(t.contentLayer)),t}traverseOneOrManyType(t,i){if(!Array.isArray(t))if(this.options.convertPropsToArray)t=[t];else return this.traverseType(t,i);return t.map(n=>this.traverseType(n,i))}traverseType(t,i){return i.reduce((n,s)=>{const r=s(n);return typeof r=="undefined"&&!this.options.allowUndefinedReturn?n:r},t)}}const W="http://library.stanford.edu/iiif/image-api/compliance.html#level0",y="http://library.stanford.edu/iiif/image-api/compliance.html#level1",_="http://library.stanford.edu/iiif/image-api/compliance.html#level2",$="http://library.stanford.edu/iiif/image-api/conformance.html#level0",A="http://library.stanford.edu/iiif/image-api/conformance.html#level1",L="http://library.stanford.edu/iiif/image-api/conformance.html#level2",H="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",E="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",C="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",B="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",M="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",O="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",J="http://iiif.io/api/image/1/level0.json",z="http://iiif.io/api/image/1/profiles/level0.json",x="http://iiif.io/api/image/1/level1.json",R="http://iiif.io/api/image/1/profiles/level1.json",w="http://iiif.io/api/image/1/level2.json",F="http://iiif.io/api/image/1/profiles/level2.json",K="http://iiif.io/api/image/2/level0.json",Q="http://iiif.io/api/image/2/profiles/level0.json",T="http://iiif.io/api/image/2/level1.json",S="http://iiif.io/api/image/2/profiles/level1.json",b="http://iiif.io/api/image/2/level2.json",N="http://iiif.io/api/image/2/profiles/level2.json",X="level0",k="level1",G="level2",Y="http://iiif.io/api/image/2/level0",j="http://iiif.io/api/image/2/level1",P="http://iiif.io/api/image/2/level2",Z=[j,P,y,_,A,L,E,C,M,O,x,R,w,F,T,S,b,N,k,G],tt=[Y,j,P,W,y,_,$,A,L,H,E,C,B,M,O,J,z,x,R,w,F,K,Q,T,S,b,N,X,k,G],u={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function h(e,t="none"){if(!e)return{};const i=Array.isArray(e)?e:[e],n={};for(const s of i){if(typeof s=="string"){n[t]=n[t]?n[t]:[],n[t].push(s||"");continue}if(!s["@language"]){n[t]=n[t]?n[t]:[],n[t].push(s["@value"]||"");continue}const r=s["@language"];n[r]=n[r]?n[r]:[],n[r].push(s["@value"]||"")}return n}function d(e){if(Array.isArray(e))return d(e.find(t=>typeof t=="string"));if(tt.indexOf(e)!==-1)return"level2";if(Z.indexOf(e)!==-1)return"level1";if(typeof e=="string")return e}function D(e){const t=Array.isArray(e)?e:[e];for(const i of t)switch(i){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function et(e){switch(e){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}function it(e){return Array.isArray(e)?e:[e]}function nt(e){for(const t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}const rt=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function m(e){const t=e["@id"]||e.id;let i=e["@type"]||e.type;const n=e.profile||void 0,s=e["@context"]||void 0;if(n){const r=et(n);if(r)return r}if(s){const r=D(s);if(r)return r}if(i){if(Array.isArray(i)){if(i.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(i.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";i=i[0]}for(const r of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${r}:`)){i=i.slice(r.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(i&&rt.indexOf(i)!==-1)return i;if(e.format){if(e.format.startsWith("image/"))return"Image";if(e.format.startsWith("text/")||e.format==="application/pdf")return"Text";if(e.format.startsWith("application/"))return"Dataset"}return t&&(t.endsWith(".jpg")||t.endsWith(".png")||t.endsWith(".jpeg"))?"Image":i||"unknown"}const st=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function at(e){const t=e.match(st);return t?t[0]:e}function ot(e,t="Rights/License",i="none"){let n=null;const s=[],r=Array.isArray(e)?e:[e];for(const g of r){const f=g?at(g):void 0;if(f&&(f.indexOf("creativecommons.org")!==-1||f.indexOf("rightsstatements.org")!==-1)){f.startsWith("https://")?n=`http://${f.slice(8)}`:n=f;continue}f&&s.push({label:{[i]:[t]},value:{[i]:[f]}})}return[n,s]}const pt=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function ft(e){if(e){const t=Array.isArray(e)?e:[e],i=[];for(const n of t)n==="http://iiif.io/api/presentation/2/context.json"&&i.push("http://iiif.io/api/presentation/3/context.json"),pt.indexOf(n)===-1&&i.push(n);if(t.length)return i.length===1?i[0]:i}}function ht(e){return e?e.map(t=>({label:h(t.label),value:h(t.value)})):[]}function o(e){for(const t in e)(typeof e[t]=="undefined"||e[t]===null)&&delete e[t];return e}let V=0;function q(e,t){const i=encodeURI(e.id||e["@id"]||"").trim();return i&&t?`${i}/${t}`:i||(V++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${V}`)}function p(e){const t=[...e.behavior||[]];return e.viewingHint&&t.push(e.viewingHint),{"@context":e["@context"]?ft(e["@context"]):void 0,id:(e["@id"]||q(e)).trim(),type:m(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:e.motivation?nt(e.motivation):void 0,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function a(e){const[t,i]=ot(e.license),n=[...e.metadata?ht(e.metadata):[],...i];return{rights:t,metadata:n.length?n:void 0,label:e.label?h(e.label):void 0,requiredStatement:e.attribution?{label:h(u.attributionLabel),value:h(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?h(e.description):void 0,thumbnail:e.thumbnail}}function vt(e){if(!e.within)return;const t=Array.isArray(e.within)?e.within:[e.within],i=[];for(const n of t)if(typeof n=="string"){if(n)switch(e["@type"]){case"sc:Manifest":i.push({id:n,type:"Collection"});break}}else n["@id"]&&i.push({id:n["@id"],type:m(n)});return i.length?i:void 0}function v(e){const t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],i=e.contentLayer;return{provider:e.logo||t.length?[{id:u.providerId,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:h(u.providerName)}]:void 0,partOf:vt(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?it(e.service):void 0,supplementary:i?[i]:void 0}}function ct(e){return o({...p(e),...a(e),...v(e),items:e.members})}function lt(e){const t=[],i=[];for(const s of e.sequences||[])s.canvases.length&&t.push(...s.canvases),s.behavior&&i.push(...s.behavior);const n=p(e);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),o({...n,...a(e),...v(e),items:t,structures:e.structures})}function ut(e){return o({...p(e),...a(e),...v(e),items:e.images&&e.images.length?[{id:q(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}function dt(e){return o({...p(e),...a(e),...v(e),items:e.resources})}function mt(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[]}}function gt(e){return o({...p(e),...a(e),...v(e),target:typeof e.on=="string"?encodeURI(e.on).trim():e.on,body:e.resource})}function It(e){const t=e;return o({...p(t),...a(t),...v(t)})}function yt(e){const t=[];return e.default&&e.default!=="rdf:nil"&&t.push(e.default),e.item&&e.item!=="rdf:nil"&&t.push(...e.item),{...p(e),...a(e),items:t}}function _t(e){return o({...p(e),...a(e),...v(e),items:e.members})}function At(e){const{"@id":t,"@type":i,"@context":n,profile:s,...r}=e;return t&&(r.id=t),r.type=m(e),r.type==="unknown"&&(r.type="Service"),s&&(r.profile=d(s)),o({...r,...a(r)})}function Lt(e){return o({...p(e),...a(e),...v(e)})}const U=new c({collection:[ct],manifest:[lt],canvas:[ut],annotationList:[dt],sequence:[mt],annotation:[gt],contentResource:[It],choice:[yt],range:[_t],service:[At],layer:[Lt]});function Et(e){return e&&e["@context"]&&(e["@context"]==="http://iiif.io/api/presentation/2/context.json"||e["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")!==-1||e["@context"]==="http://www.shared-canvas.org/ns/context.json")||e["@context"]==="http://iiif.io/api/image/2/context.json"?U.traverseUnknown(e):e}export{c as Traverse,h as convertLanguageMapping,Et as convertPresentation2,d as getProfile,D as getTypeFromContext,I as identifyResource,U as presentation2to3,l as types};

@@ -1,1 +0,1 @@

(function(c,l){typeof exports=="object"&&typeof module!="undefined"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(c=typeof globalThis!="undefined"?globalThis:c||self,l(c.IIIFUpgrader={}))})(this,function(c){"use strict";const l="http://library.stanford.edu/iiif/image-api/compliance.html#level0",g="http://library.stanford.edu/iiif/image-api/compliance.html#level1",I="http://library.stanford.edu/iiif/image-api/compliance.html#level2",U="http://library.stanford.edu/iiif/image-api/conformance.html#level0",y="http://library.stanford.edu/iiif/image-api/conformance.html#level1",_="http://library.stanford.edu/iiif/image-api/conformance.html#level2",W="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",A="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",L="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",$="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",E="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",C="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",H="http://iiif.io/api/image/1/level0.json",B="http://iiif.io/api/image/1/profiles/level0.json",M="http://iiif.io/api/image/1/level1.json",O="http://iiif.io/api/image/1/profiles/level1.json",x="http://iiif.io/api/image/1/level2.json",R="http://iiif.io/api/image/1/profiles/level2.json",J="http://iiif.io/api/image/2/level0.json",z="http://iiif.io/api/image/2/profiles/level0.json",F="http://iiif.io/api/image/2/level1.json",w="http://iiif.io/api/image/2/profiles/level1.json",T="http://iiif.io/api/image/2/level2.json",b="http://iiif.io/api/image/2/profiles/level2.json",K="level0",S="level1",N="level2",Q="http://iiif.io/api/image/2/level0",k="http://iiif.io/api/image/2/level1",j="http://iiif.io/api/image/2/level2",X=[k,j,g,I,y,_,A,L,E,C,M,O,x,R,F,w,T,b,S,N],Y=[Q,k,j,l,g,I,U,y,_,W,A,L,$,E,C,H,B,M,O,x,R,J,z,F,w,T,b,K,S,N],G=["sc:Collection","sc:Manifest","sc:Canvas","oa:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function Z(e){if(typeof e=="undefined"||e===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(e))throw new Error("Array is not a valid entity");if(typeof e!="object")throw new Error(`${typeof e} is not a valid entity`);if(typeof e["@type"]=="string"){const t=G.indexOf(e["@type"]);if(t!==-1)return G[t]}if(e.profile)return"Service";if(e.format||e["@type"])return"ContentResource";throw new Error("Resource type is not known")}class u{traversals;options;constructor(t,i={}){this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...t},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...i}}static all(t){return new u({collection:[t],manifest:[t],canvas:[t],annotationList:[t],sequence:[t],annotation:[t],contentResource:[t],choice:[t],range:[t],service:[t],layer:[t]})}traverseCollection(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(t))),this.traversals.collection)}traverseCollectionItems(t){if(this.options.mergeMemberProperties){const i=[...(t.manifests||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n),...(t.collections||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n),...t.members||[]];delete t.collections,delete t.manifests,t.members=i}return t.manifests&&(t.manifests=t.manifests.map(i=>this.traverseManifest(typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i))),t.collections&&(t.collections=t.collections.map(i=>this.traverseCollection(typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i))),t.members&&(t.members=t.members.map(i=>typeof i=="string"?i:this.traverseUnknown(i))),t}traverseManifest(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(t))),this.traversals.manifest)}traverseManifestItems(t){return t.sequences&&(t.sequences=t.sequences.map(i=>this.traverseSequence(i))),t.structures&&(t.structures=t.structures.map(i=>this.traverseRange(i))),t}traverseSequence(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(t))),this.traversals.sequence)}traverseSequenceItems(t){return t.canvases&&(t.canvases=t.canvases.map(i=>this.traverseCanvas(i))),t}traverseCanvas(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(t))),this.traversals.canvas)}traverseCanvasItems(t){return t.images&&(t.images=t.images.map(i=>this.traverseAnnotation(i))),t.otherContent&&(t.otherContent=t.otherContent.map(i=>this.traverseAnnotationList(i))),t}traverseRange(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(t))),this.traversals.range)}traverseRangeItems(t){if(this.options.mergeMemberProperties){const i=[...(t.ranges||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Range"}:n),...(t.canvases||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Canvas"}:n),...t.members||[]];delete t.ranges,delete t.canvases,t.members=i.length?i.map(n=>this.traverseUnknown(n)):void 0}return t}traverseAnnotationList(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationListItems(t))),this.traversals.annotationList)}traverseAnnotationListItems(t){return t.resources&&(t.resources=t.resources.map(i=>this.traverseAnnotation(i))),t}traverseAnnotation(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(t))),this.traversals.annotation)}traverseAnnotationItems(t){return t.resource&&(t.resource=this.traverseContentResource(t.resource)),t.on,t}traverseLayer(t){return this.traverseType(this.traverseLinking(this.traverseLayerItems(t)),this.traversals.layer)}traverseLayerItems(t){return t.otherContent&&(t.otherContent=t.otherContent.map(i=>this.traverseAnnotationList(i))),t}traverseChoice(t){return this.traverseType(this.traverseChoiceItems(t),this.traversals.choice)}traverseChoiceItems(t){return t.default&&t.default!=="rdf:nil"&&(t.default=this.traverseContentResource(t.default)),t.item&&t.item!=="rdf:nil"&&(t.item=t.item.map(i=>this.traverseContentResource(i))),t}traverseService(t){return this.traverseType(this.traverseLinking(t),this.traversals.service)}traverseContentResource(t){return t["@type"]==="oa:Choice"?this.traverseChoice(t):this.traverseType(this.traverseDescriptive(this.traverseLinking(t)),this.traversals.contentResource)}traverseUnknown(t){if(!t["@type"]||typeof t=="string")return t;switch(Z(t)){case"sc:Collection":return this.traverseCollection(t);case"sc:Manifest":return this.traverseManifest(t);case"sc:Canvas":return this.traverseCanvas(t);case"sc:Sequence":return this.traverseSequence(t);case"sc:Range":return this.traverseRange(t);case"oa:Annotation":return this.traverseAnnotation(t);case"oa:AnnotationList":return this.traverseAnnotationList(t);case"sc:Layer":return this.traverseLayer(t);case"Service":return this.traverseService(t);case"oa:Choice":return this.traverseChoice(t);case"ContentResource":return this.traverseContentResource(t)}return t.profile?this.traverseService(t):t}traverseImageResource(t){const i=Array.isArray(t),n=Array.isArray(t)?t:[t],s=[];for(const r of n)typeof r=="string"?s.push(this.traverseContentResource({"@id":r,"@type":"dctypes:Image"})):s.push(this.traverseContentResource(r));return!i&&!this.options.convertPropsToArray?s[0]:s}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=this.traverseImageResource(t.thumbnail)),t.logo&&(t.logo=this.traverseImageResource(t.logo)),t}traverseOneOrMoreServices(t){const i=Array.isArray(t),n=Array.isArray(t)?t:[t],s=[];for(const r of n)s.push(this.traverseService(r));return!i&&!this.options.convertPropsToArray?s[0]:s}traverseLinking(t){return t.related&&(t.related=this.traverseOneOrManyType(t.related,this.traversals.contentResource)),t.rendering&&(t.rendering=this.traverseOneOrManyType(t.rendering,this.traversals.contentResource)),t.service&&(t.service=this.traverseOneOrMoreServices(t.service)),t.seeAlso&&(t.seeAlso=this.traverseOneOrManyType(t.seeAlso,this.traversals.contentResource)),t.within&&(typeof t.within=="string"||(t.within=this.traverseOneOrManyType(t.within,this.traversals.contentResource))),t.startCanvas&&(typeof t.startCanvas=="string"?t.startCanvas=this.traverseType({"@id":t.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):t.startCanvas&&this.traverseType(t.startCanvas,this.traversals.canvas)),t.contentLayer&&(typeof t.contentLayer=="string"?t.contentLayer=this.traverseLayer({"@id":t.contentLayer,"@type":"sc:Layer"}):t.contentLayer=this.traverseLayer(t.contentLayer)),t}traverseOneOrManyType(t,i){if(!Array.isArray(t))if(this.options.convertPropsToArray)t=[t];else return this.traverseType(t,i);return t.map(n=>this.traverseType(n,i))}traverseType(t,i){return i.reduce((n,s)=>{const r=s(n);return typeof r=="undefined"&&!this.options.allowUndefinedReturn?n:r},t)}}const d={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function v(e,t="none"){if(!e)return{};const i=Array.isArray(e)?e:[e],n={};for(const s of i){if(typeof s=="string"){n[t]=n[t]?n[t]:[],n[t].push(s||"");continue}if(!s["@language"]){n[t]=n[t]?n[t]:[],n[t].push(s["@value"]||"");continue}const r=s["@language"];n[r]=n[r]?n[r]:[],n[r].push(s["@value"]||"")}return n}function P(e){if(Array.isArray(e))return P(e.find(t=>typeof t=="string"));if(Y.indexOf(e)!==-1)return"level2";if(X.indexOf(e)!==-1)return"level1";if(typeof e=="string")return e}function tt(e){const t=Array.isArray(e)?e:[e];for(const i of t)switch(i){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function et(e){switch(e){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}function it(e){return Array.isArray(e)?e:[e]}function nt(e){for(const t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}function m(e){const t=e["@id"]||e.id;let i=e["@type"]||e.type;const n=e.profile||void 0,s=e["@context"]||void 0;if(n){const r=et(n);if(r)return r}if(s){const r=tt(s);if(r)return r}if(i){if(Array.isArray(i)){if(i.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(i.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";i=i[0]}for(const r of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${r}:`)){i=i.slice(r.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(e.format){if(e.format.startsWith("image/"))return"Image";if(e.format.startsWith("text/")||e.format==="application/pdf")return"Text";if(e.format.startsWith("application/"))return"Dataset"}return t&&(t.endsWith(".jpg")||t.endsWith(".png")||t.endsWith(".jpeg"))?"Image":i||"unknown"}const rt=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function st(e){const t=e.match(rt);return t?t[0]:e}function at(e,t="Rights/License",i="none"){let n=null;const s=[],r=Array.isArray(e)?e:[e];for(const q of r){const h=q?st(q):void 0;if(h&&(h.indexOf("creativecommons.org")!==-1||h.indexOf("rightsstatements.org")!==-1)){h.startsWith("https://")?n=`http://${h.slice(8)}`:n=h;continue}h&&s.push({label:{[i]:[t]},value:{[i]:[h]}})}return[n,s]}const ot=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function pt(e){if(e){const t=Array.isArray(e)?e:[e],i=[];for(const n of t)n==="http://iiif.io/api/presentation/2/context.json"&&i.push("http://iiif.io/api/presentation/3/context.json"),ot.indexOf(n)===-1&&i.push(n);if(t.length)return i.length===1?i[0]:i}}function ft(e){return e?e.map(t=>({label:v(t.label),value:v(t.value)})):[]}function o(e){for(const t in e)(typeof e[t]=="undefined"||e[t]===null)&&delete e[t];return e}let D=0;function V(e,t){const i=encodeURI(e.id||e["@id"]||"").trim();return i&&t?`${i}/${t}`:i||(D++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${D}`)}function p(e){const t=[...e.behavior||[]];return e.viewingHint&&t.push(e.viewingHint),{"@context":e["@context"]?pt(e["@context"]):void 0,id:(e["@id"]||V(e)).trim(),type:m(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:e.motivation?nt(e.motivation):void 0,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function a(e){const[t,i]=at(e.license),n=[...e.metadata?ft(e.metadata):[],...i];return{rights:t,metadata:n.length?n:void 0,label:e.label?v(e.label):void 0,requiredStatement:e.attribution?{label:v(d.attributionLabel),value:v(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?v(e.description):void 0,thumbnail:e.thumbnail}}function ht(e){if(!e.within)return;const t=Array.isArray(e.within)?e.within:[e.within],i=[];for(const n of t)if(typeof n=="string"){if(n)switch(e["@type"]){case"sc:Manifest":i.push({id:n,type:"Collection"});break}}else n["@id"]&&i.push({id:n["@id"],type:m(n)});return i.length?i:void 0}function f(e){const t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],i=e.contentLayer;return{provider:e.logo||t.length?[{id:d.providerId,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:v(d.providerName)}]:void 0,partOf:ht(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?it(e.service):void 0,supplementary:i?[i]:void 0}}function vt(e){return o({...p(e),...a(e),...f(e),items:e.members})}function ct(e){const t=[],i=[];for(const s of e.sequences||[])s.canvases.length&&t.push(...s.canvases),s.behavior&&i.push(...s.behavior);const n=p(e);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),o({...n,...a(e),...f(e),items:t,structures:e.structures})}function lt(e){return o({...p(e),...a(e),...f(e),items:e.images&&e.images.length?[{id:V(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}function ut(e){return o({...p(e),...a(e),...f(e),items:e.resources})}function dt(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[]}}function mt(e){return o({...p(e),...a(e),...f(e),target:typeof e.on=="string"?encodeURI(e.on).trim():e.on,body:e.resource})}function gt(e){const t=e;return o({...p(t),...a(t),...f(t)})}function It(e){const t=[];return e.default&&e.default!=="rdf:nil"&&t.push(e.default),e.item&&e.item!=="rdf:nil"&&t.push(...e.item),{...p(e),...a(e),items:t}}function yt(e){return o({...p(e),...a(e),...f(e),items:e.members})}function _t(e){const{"@id":t,"@type":i,"@context":n,profile:s,...r}=e;return t&&(r.id=t),r.type=m(e),r.type==="unknown"&&(r.type="Service"),s&&(r.profile=P(s)),o({...r,...a(r)})}function At(e){return o({...p(e),...a(e),...f(e)})}const Lt=new u({collection:[vt],manifest:[ct],canvas:[lt],annotationList:[ut],sequence:[dt],annotation:[mt],contentResource:[gt],choice:[It],range:[yt],service:[_t],layer:[At]});function Et(e){return e&&e["@context"]&&(e["@context"]==="http://iiif.io/api/presentation/2/context.json"||e["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")!==-1||e["@context"]==="http://www.shared-canvas.org/ns/context.json")||e["@context"]==="http://iiif.io/api/image/2/context.json"?Lt.traverseUnknown(e):e}const Ct=Et;c.upgrade=Ct,Object.defineProperty(c,"__esModule",{value:!0})});
(function(c,l){typeof exports=="object"&&typeof module!="undefined"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(c=typeof globalThis!="undefined"?globalThis:c||self,l(c.IIIFUpgrader={}))})(this,function(c){"use strict";const l="http://library.stanford.edu/iiif/image-api/compliance.html#level0",g="http://library.stanford.edu/iiif/image-api/compliance.html#level1",I="http://library.stanford.edu/iiif/image-api/compliance.html#level2",U="http://library.stanford.edu/iiif/image-api/conformance.html#level0",y="http://library.stanford.edu/iiif/image-api/conformance.html#level1",_="http://library.stanford.edu/iiif/image-api/conformance.html#level2",W="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",A="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",L="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",$="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",E="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",C="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",H="http://iiif.io/api/image/1/level0.json",B="http://iiif.io/api/image/1/profiles/level0.json",M="http://iiif.io/api/image/1/level1.json",O="http://iiif.io/api/image/1/profiles/level1.json",x="http://iiif.io/api/image/1/level2.json",R="http://iiif.io/api/image/1/profiles/level2.json",J="http://iiif.io/api/image/2/level0.json",z="http://iiif.io/api/image/2/profiles/level0.json",F="http://iiif.io/api/image/2/level1.json",w="http://iiif.io/api/image/2/profiles/level1.json",T="http://iiif.io/api/image/2/level2.json",S="http://iiif.io/api/image/2/profiles/level2.json",K="level0",b="level1",N="level2",Q="http://iiif.io/api/image/2/level0",k="http://iiif.io/api/image/2/level1",j="http://iiif.io/api/image/2/level2",X=[k,j,g,I,y,_,A,L,E,C,M,O,x,R,F,w,T,S,b,N],Y=[Q,k,j,l,g,I,U,y,_,W,A,L,$,E,C,H,B,M,O,x,R,J,z,F,w,T,S,K,b,N],G=["sc:Collection","sc:Manifest","sc:Canvas","oa:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function Z(e){if(typeof e=="undefined"||e===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(e))throw new Error("Array is not a valid entity");if(typeof e!="object")throw new Error(`${typeof e} is not a valid entity`);if(typeof e["@type"]=="string"){const t=G.indexOf(e["@type"]);if(t!==-1)return G[t]}if(e.profile)return"Service";if(e.format||e["@type"])return"ContentResource";throw new Error("Resource type is not known")}class u{traversals;options;constructor(t,i={}){this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...t},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...i}}static all(t){return new u({collection:[t],manifest:[t],canvas:[t],annotationList:[t],sequence:[t],annotation:[t],contentResource:[t],choice:[t],range:[t],service:[t],layer:[t]})}traverseCollection(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(t))),this.traversals.collection)}traverseCollectionItems(t){if(this.options.mergeMemberProperties){const i=[...(t.manifests||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n),...(t.collections||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n),...t.members||[]];delete t.collections,delete t.manifests,t.members=i}return t.manifests&&(t.manifests=t.manifests.map(i=>this.traverseManifest(typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i))),t.collections&&(t.collections=t.collections.map(i=>this.traverseCollection(typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i))),t.members&&(t.members=t.members.map(i=>typeof i=="string"?i:this.traverseUnknown(i))),t}traverseManifest(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(t))),this.traversals.manifest)}traverseManifestItems(t){return t.sequences&&(t.sequences=t.sequences.map(i=>this.traverseSequence(i))),t.structures&&(t.structures=t.structures.map(i=>this.traverseRange(i))),t}traverseSequence(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(t))),this.traversals.sequence)}traverseSequenceItems(t){return t.canvases&&(t.canvases=t.canvases.map(i=>this.traverseCanvas(i))),t}traverseCanvas(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(t))),this.traversals.canvas)}traverseCanvasItems(t){return t.images&&(t.images=t.images.map(i=>this.traverseAnnotation(i))),t.otherContent&&(t.otherContent=t.otherContent.map(i=>this.traverseAnnotationList(i))),t}traverseRange(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(t))),this.traversals.range)}traverseRangeItems(t){if(this.options.mergeMemberProperties){const i=[...(t.ranges||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Range"}:n),...(t.canvases||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Canvas"}:n),...t.members||[]];delete t.ranges,delete t.canvases,t.members=i.length?i.map(n=>this.traverseUnknown(n)):void 0}return t}traverseAnnotationList(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationListItems(t))),this.traversals.annotationList)}traverseAnnotationListItems(t){return t.resources&&(t.resources=t.resources.map(i=>this.traverseAnnotation(i))),t}traverseAnnotation(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(t))),this.traversals.annotation)}traverseAnnotationItems(t){return t.resource&&(t.resource=this.traverseContentResource(t.resource)),t.on,t}traverseLayer(t){return this.traverseType(this.traverseLinking(this.traverseLayerItems(t)),this.traversals.layer)}traverseLayerItems(t){return t.otherContent&&(t.otherContent=t.otherContent.map(i=>this.traverseAnnotationList(i))),t}traverseChoice(t){return this.traverseType(this.traverseChoiceItems(t),this.traversals.choice)}traverseChoiceItems(t){return t.default&&t.default!=="rdf:nil"&&(t.default=this.traverseContentResource(t.default)),t.item&&t.item!=="rdf:nil"&&(t.item=t.item.map(i=>this.traverseContentResource(i))),t}traverseService(t){return this.traverseType(this.traverseLinking(t),this.traversals.service)}traverseContentResource(t){return t["@type"]==="oa:Choice"?this.traverseChoice(t):this.traverseType(this.traverseDescriptive(this.traverseLinking(t)),this.traversals.contentResource)}traverseUnknown(t){if(!t["@type"]||typeof t=="string")return t;switch(Z(t)){case"sc:Collection":return this.traverseCollection(t);case"sc:Manifest":return this.traverseManifest(t);case"sc:Canvas":return this.traverseCanvas(t);case"sc:Sequence":return this.traverseSequence(t);case"sc:Range":return this.traverseRange(t);case"oa:Annotation":return this.traverseAnnotation(t);case"oa:AnnotationList":return this.traverseAnnotationList(t);case"sc:Layer":return this.traverseLayer(t);case"Service":return this.traverseService(t);case"oa:Choice":return this.traverseChoice(t);case"ContentResource":return this.traverseContentResource(t)}return t.profile?this.traverseService(t):t}traverseImageResource(t){const i=Array.isArray(t),n=Array.isArray(t)?t:[t],s=[];for(const r of n)typeof r=="string"?s.push(this.traverseContentResource({"@id":r,"@type":"dctypes:Image"})):s.push(this.traverseContentResource(r));return!i&&!this.options.convertPropsToArray?s[0]:s}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=this.traverseImageResource(t.thumbnail)),t.logo&&(t.logo=this.traverseImageResource(t.logo)),t}traverseOneOrMoreServices(t){const i=Array.isArray(t),n=Array.isArray(t)?t:[t],s=[];for(const r of n)s.push(this.traverseService(r));return!i&&!this.options.convertPropsToArray?s[0]:s}traverseLinking(t){return t.related&&(t.related=this.traverseOneOrManyType(t.related,this.traversals.contentResource)),t.rendering&&(t.rendering=this.traverseOneOrManyType(t.rendering,this.traversals.contentResource)),t.service&&(t.service=this.traverseOneOrMoreServices(t.service)),t.seeAlso&&(t.seeAlso=this.traverseOneOrManyType(t.seeAlso,this.traversals.contentResource)),t.within&&(typeof t.within=="string"||(t.within=this.traverseOneOrManyType(t.within,this.traversals.contentResource))),t.startCanvas&&(typeof t.startCanvas=="string"?t.startCanvas=this.traverseType({"@id":t.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):t.startCanvas&&this.traverseType(t.startCanvas,this.traversals.canvas)),t.contentLayer&&(typeof t.contentLayer=="string"?t.contentLayer=this.traverseLayer({"@id":t.contentLayer,"@type":"sc:Layer"}):t.contentLayer=this.traverseLayer(t.contentLayer)),t}traverseOneOrManyType(t,i){if(!Array.isArray(t))if(this.options.convertPropsToArray)t=[t];else return this.traverseType(t,i);return t.map(n=>this.traverseType(n,i))}traverseType(t,i){return i.reduce((n,s)=>{const r=s(n);return typeof r=="undefined"&&!this.options.allowUndefinedReturn?n:r},t)}}const d={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function v(e,t="none"){if(!e)return{};const i=Array.isArray(e)?e:[e],n={};for(const s of i){if(typeof s=="string"){n[t]=n[t]?n[t]:[],n[t].push(s||"");continue}if(!s["@language"]){n[t]=n[t]?n[t]:[],n[t].push(s["@value"]||"");continue}const r=s["@language"];n[r]=n[r]?n[r]:[],n[r].push(s["@value"]||"")}return n}function P(e){if(Array.isArray(e))return P(e.find(t=>typeof t=="string"));if(Y.indexOf(e)!==-1)return"level2";if(X.indexOf(e)!==-1)return"level1";if(typeof e=="string")return e}function tt(e){const t=Array.isArray(e)?e:[e];for(const i of t)switch(i){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function et(e){switch(e){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}function it(e){return Array.isArray(e)?e:[e]}function nt(e){for(const t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}const rt=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function m(e){const t=e["@id"]||e.id;let i=e["@type"]||e.type;const n=e.profile||void 0,s=e["@context"]||void 0;if(n){const r=et(n);if(r)return r}if(s){const r=tt(s);if(r)return r}if(i){if(Array.isArray(i)){if(i.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(i.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";i=i[0]}for(const r of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${r}:`)){i=i.slice(r.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(i&&rt.indexOf(i)!==-1)return i;if(e.format){if(e.format.startsWith("image/"))return"Image";if(e.format.startsWith("text/")||e.format==="application/pdf")return"Text";if(e.format.startsWith("application/"))return"Dataset"}return t&&(t.endsWith(".jpg")||t.endsWith(".png")||t.endsWith(".jpeg"))?"Image":i||"unknown"}const st=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function at(e){const t=e.match(st);return t?t[0]:e}function ot(e,t="Rights/License",i="none"){let n=null;const s=[],r=Array.isArray(e)?e:[e];for(const q of r){const h=q?at(q):void 0;if(h&&(h.indexOf("creativecommons.org")!==-1||h.indexOf("rightsstatements.org")!==-1)){h.startsWith("https://")?n=`http://${h.slice(8)}`:n=h;continue}h&&s.push({label:{[i]:[t]},value:{[i]:[h]}})}return[n,s]}const pt=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function ft(e){if(e){const t=Array.isArray(e)?e:[e],i=[];for(const n of t)n==="http://iiif.io/api/presentation/2/context.json"&&i.push("http://iiif.io/api/presentation/3/context.json"),pt.indexOf(n)===-1&&i.push(n);if(t.length)return i.length===1?i[0]:i}}function ht(e){return e?e.map(t=>({label:v(t.label),value:v(t.value)})):[]}function o(e){for(const t in e)(typeof e[t]=="undefined"||e[t]===null)&&delete e[t];return e}let D=0;function V(e,t){const i=encodeURI(e.id||e["@id"]||"").trim();return i&&t?`${i}/${t}`:i||(D++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${D}`)}function p(e){const t=[...e.behavior||[]];return e.viewingHint&&t.push(e.viewingHint),{"@context":e["@context"]?ft(e["@context"]):void 0,id:(e["@id"]||V(e)).trim(),type:m(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:e.motivation?nt(e.motivation):void 0,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function a(e){const[t,i]=ot(e.license),n=[...e.metadata?ht(e.metadata):[],...i];return{rights:t,metadata:n.length?n:void 0,label:e.label?v(e.label):void 0,requiredStatement:e.attribution?{label:v(d.attributionLabel),value:v(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?v(e.description):void 0,thumbnail:e.thumbnail}}function vt(e){if(!e.within)return;const t=Array.isArray(e.within)?e.within:[e.within],i=[];for(const n of t)if(typeof n=="string"){if(n)switch(e["@type"]){case"sc:Manifest":i.push({id:n,type:"Collection"});break}}else n["@id"]&&i.push({id:n["@id"],type:m(n)});return i.length?i:void 0}function f(e){const t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],i=e.contentLayer;return{provider:e.logo||t.length?[{id:d.providerId,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:v(d.providerName)}]:void 0,partOf:vt(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?it(e.service):void 0,supplementary:i?[i]:void 0}}function ct(e){return o({...p(e),...a(e),...f(e),items:e.members})}function lt(e){const t=[],i=[];for(const s of e.sequences||[])s.canvases.length&&t.push(...s.canvases),s.behavior&&i.push(...s.behavior);const n=p(e);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),o({...n,...a(e),...f(e),items:t,structures:e.structures})}function ut(e){return o({...p(e),...a(e),...f(e),items:e.images&&e.images.length?[{id:V(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}function dt(e){return o({...p(e),...a(e),...f(e),items:e.resources})}function mt(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[]}}function gt(e){return o({...p(e),...a(e),...f(e),target:typeof e.on=="string"?encodeURI(e.on).trim():e.on,body:e.resource})}function It(e){const t=e;return o({...p(t),...a(t),...f(t)})}function yt(e){const t=[];return e.default&&e.default!=="rdf:nil"&&t.push(e.default),e.item&&e.item!=="rdf:nil"&&t.push(...e.item),{...p(e),...a(e),items:t}}function _t(e){return o({...p(e),...a(e),...f(e),items:e.members})}function At(e){const{"@id":t,"@type":i,"@context":n,profile:s,...r}=e;return t&&(r.id=t),r.type=m(e),r.type==="unknown"&&(r.type="Service"),s&&(r.profile=P(s)),o({...r,...a(r)})}function Lt(e){return o({...p(e),...a(e),...f(e)})}const Et=new u({collection:[ct],manifest:[lt],canvas:[ut],annotationList:[dt],sequence:[mt],annotation:[gt],contentResource:[It],choice:[yt],range:[_t],service:[At],layer:[Lt]});function Ct(e){return e&&e["@context"]&&(e["@context"]==="http://iiif.io/api/presentation/2/context.json"||e["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")!==-1||e["@context"]==="http://www.shared-canvas.org/ns/context.json")||e["@context"]==="http://iiif.io/api/image/2/context.json"?Et.traverseUnknown(e):e}const Mt=Ct;c.upgrade=Mt,Object.defineProperty(c,"__esModule",{value:!0})});
{
"name": "@iiif/parser",
"version": "1.0.5",
"version": "1.0.6",
"license": "MIT",

@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js",