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
5
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
2.1.0
to
2.1.1
+1
dist/chunk-3WVPINNO.js
import{E as C,H as A}from"./chunk-J657UVVW.js";import{a as m,b as s}from"./chunk-NJNTZ6QT.js";import{a as v}from"./chunk-D22QKJZO.js";var I=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function S(t){if(typeof t>"u"||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"){let e=I.indexOf(t["@type"]);if(e!==-1)return I[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}var u=class t{constructor(e,n={}){v(this,"traversals");v(this,"options");this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...n}}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){let n=[...(e.manifests||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i),...(e.collections||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i),...e.members||[]];delete e.collections,delete e.manifests,e.members=n}return e.manifests&&(e.manifests=e.manifests.map(n=>this.traverseManifest(typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n))),e.collections&&(e.collections=e.collections.map(n=>this.traverseCollection(typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n))),e.members&&(e.members=e.members.map(n=>typeof n=="string"?n:this.traverseUnknown(n))),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(n=>this.traverseSequence(n))),e.structures&&(e.structures=e.structures.map(n=>this.traverseRange(n))),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(n=>this.traverseCanvas(n))),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(n=>this.traverseAnnotation(n))),e.otherContent&&(e.otherContent=e.otherContent.map(n=>this.traverseAnnotationList(n))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){let n=[...(e.ranges||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Range"}:i),...(e.canvases||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Canvas"}:i),...e.members||[]];delete e.ranges,delete e.canvases,e.members=n.length?n.map(i=>this.traverseUnknown(i)):void 0}return e}traverseAnnotationList(e){let n=typeof e=="string"?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(n)),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map(n=>this.traverseAnnotation(n))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(Array.isArray(e.resource)?e.resource=e.resource.map(n=>this.traverseContentResource(n)):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(n=>this.traverseAnnotationList(n))),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(n=>this.traverseContentResource(n))),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(S(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"sc: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){let n=Array.isArray(e),i=Array.isArray(e)?e:[e],a=[];for(let r of i)typeof r=="string"?a.push(this.traverseContentResource({"@id":r,"@type":"dctypes:Image"})):a.push(this.traverseContentResource(r));return!n&&!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){let n=Array.isArray(e),i=Array.isArray(e)?e:[e],a=[];for(let r of i)a.push(this.traverseService(r));return!n&&!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,n){if(!Array.isArray(e))if(this.options.convertPropsToArray)e=[e];else return this.traverseType(e,n);return e.map(i=>this.traverseType(i,n))}traverseType(e,n){return n.reduce((i,a)=>{let r=a(i);return typeof r>"u"&&!this.options.allowUndefinedReturn?i:r},e)}};var M="http://library.stanford.edu/iiif/image-api/compliance.html#level1",O="http://library.stanford.edu/iiif/image-api/compliance.html#level2";var b="http://library.stanford.edu/iiif/image-api/conformance.html#level1",w="http://library.stanford.edu/iiif/image-api/conformance.html#level2";var F="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",N="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2";var k="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",D="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2";var j="http://iiif.io/api/image/1/level1.json",G="http://iiif.io/api/image/1/profiles/level1.json",q="http://iiif.io/api/image/1/level2.json",V="http://iiif.io/api/image/1/profiles/level2.json";var U="http://iiif.io/api/image/2/level1.json",$="http://iiif.io/api/image/2/profiles/level1.json",W="http://iiif.io/api/image/2/level2.json",B="http://iiif.io/api/image/2/profiles/level2.json";var H="level1",J="level2";var z="http://iiif.io/api/image/2/level1",K="http://iiif.io/api/image/2/level2",P=[z,K,M,O,b,w,F,N,k,D,j,G,q,V,U,$,W,B,H,J];var d={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function Q(t){if(typeof t=="string")return[t];if(!t)return[];let e=Array.isArray(t)?t:[t],n=[];for(let i of e){if(typeof i=="string"){n.push(i);continue}n.push({"@language":i["@language"]||i.language,"@value":i["@value"]||i.value})}return n}function h(t,e="none"){if(!t)return{};let n=Q(t),i={};for(let a of n){if(typeof a=="string"){i[e]=i[e]?i[e]:[],i[e].push(a||"");continue}if(!a["@language"]){i[e]=i[e]?i[e]:[],i[e].push(a["@value"]||"");continue}let r=a["@language"];i[r]=i[r]?i[r]:[],i[r].push(a["@value"]||"")}return i}function L(t){if(Array.isArray(t))return L(t.find(e=>typeof e=="string"));if(C.indexOf(t)!==-1)return"level2";if(P.indexOf(t)!==-1)return"level1";if(A.indexOf(t)!==-1)return"level0";if(typeof t=="string")return t}function X(t){let e=Array.isArray(t)?t:[t];for(let n of e)switch(n){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 Y(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 _(t){for(let e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}var Z=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function g(t){let e=t["@id"]||t.id,n=t["@type"]||t.type,i=t.profile||void 0,a=t["@context"]||void 0;if(i){let r=Y(i);if(r)return r}if(a){let r=X(a);if(r)return r}if(n){if(Array.isArray(n)){if(n.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(n.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";n=n[0]}for(let r of["sc","oa","dcterms","dctypes","iiif"])if(n.startsWith(`${r}:`)){n=n.slice(r.length+1);break}switch(n){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(n&&Z.indexOf(n)!==-1)return n;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":n||"unknown"}var ee=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function te(t){let e=t.match(ee);return e?e[0]:t}function ne(t,e="Rights/License",n="none"){let i=null,a=[],r=Array.isArray(t)?t:[t];for(let o of r){let c=o?te(o):void 0;if(c&&(c.indexOf("creativecommons.org")!==-1||c.indexOf("rightsstatements.org")!==-1)){c.startsWith("https://")?i=`http://${c.slice(8)}`:i=c;continue}c&&a.push({label:{[n]:[e]},value:{[n]:[c]}})}return[i,a]}var ie=["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 re(t){if(t){let e=Array.isArray(t)?t:[t],n=[];for(let i of e)i==="http://iiif.io/api/presentation/2/context.json"&&n.push("http://iiif.io/api/presentation/3/context.json"),ie.indexOf(i)===-1&&n.push(i);if(e.length)return n.length===1?n[0]:n}}function ae(t){return t?t.map(e=>({label:h(e.label),value:h(e.value)})):[]}var R=0;function x(t,e){let n=encodeURI(t.id||t["@id"]||"").trim();return n&&e?`${n}/${e}`:n||(R++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${R}`)}function p(t){let e=[...t.behavior||[]];t.viewingHint&&e.push(t.viewingHint);let n;return Array.isArray(t.motivation)?n=t.motivation.map(_):t.motivation&&(n=_(t.motivation)),{"@context":t["@context"]?re(t["@context"]):void 0,id:(t["@id"]||x(t)).trim(),type:g(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:n,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function f(t){let[e,n]=ne(t.license),i=[...t.metadata?ae(t.metadata):[],...n];return{rights:e,metadata:i.length?i:void 0,label:t.label?h(t.label):void 0,requiredStatement:t.attribution?{label:h(d.attributionLabel),value:h(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?h(t.description):void 0,thumbnail:se(t.thumbnail)}}function se(t){return t&&(Array.isArray(t)?t:[t]).map(n=>typeof n=="string"?{id:n,type:"Image"}:(n.type==="unknown"&&(n.type="Image"),n))}function oe(t){if(!t.within)return;let e=Array.isArray(t.within)?t.within:[t.within],n=[];for(let i of e)if(typeof i=="string"){if(i)switch(t["@type"]){case"sc:Manifest":n.push({id:i,type:"Collection"});break}}else i["@id"]&&n.push({id:i["@id"],type:g(i)});return n.length?n:void 0}function l(t){let e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],n=t.contentLayer;return{provider:t.logo||e.length?[{id:d.providerId,type:"Agent",homepage:e.length?[e[0]]:void 0,logo:t.logo?Array.isArray(t.logo)?t.logo:[t.logo]:void 0,label:h(d.providerName)}]:void 0,partOf:oe(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?m(t.service):void 0,supplementary:n?[n]:void 0}}function pe(t){return{chars:t.chars,format:t.format?t.format:void 0,language:t.language}}function fe(t){return s({...p(t),...f(t),...l(t),items:t.members})}function ce(t){let e=[],n=[],i;for(let r of t.sequences||[])r.canvases.length&&e.push(...r.canvases),r.behavior&&n.push(...r.behavior),r.startCanvas&&(i=r.startCanvas);let a=p(t);return n.length&&(a.behavior?a.behavior.push(...n):a.behavior=n),s({...a,...f(t),...l(t),start:i,items:e,structures:t.structures})}function le(t){return s({...p(t),...f(t),...l(t),annotations:t.otherContent&&t.otherContent.length?t.otherContent:void 0,items:t.images&&t.images.length?[{id:x(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function he(t){return s({...p(t),...f(t),...l(t),items:t.resources&&t.resources.length?t.resources:void 0})}function ue(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[],startCanvas:t.startCanvas}}function ve(t){function e(n){if(Array.isArray(n)){if(n.length>1)return{type:"List",items:n.map(e)};n=n[0]}if(typeof n=="string")return encodeURI(n).trim();if("@type"in n){let i;if(typeof n.full=="string")i=n.full;else if(n.full["@type"]==="dctypes:Image")i={id:n.full["@id"],type:"Image"};else if(n.full["@type"]==="sc:Canvas")i={id:n.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${n.full["@type"]}`);return{type:"SpecificResource",source:i,selector:y(n.selector)}}else return encodeURI(n["@id"]).trim()}return s({...p(t),...f(t),...l(t),target:e(t.on),body:Array.isArray(t.resource)?t.resource.map(T):T(t.resource)})}function T(t){return t.type==="Choice"?t:E(t)}function E(t){let e=t;return s({...p(e),...f(e),...l(e),...pe(e)})}function de(t){let e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),s({...p(t),...f(t),items:e})}function ye(t){return s({...p(t),...f(t),...l(t),items:t.members})}function ge(t){let{"@id":e,"@type":n,"@context":i,profile:a,...r}=t,o={};return e&&(o["@id"]=e),o["@type"]=g(t),o["@type"]==="unknown"&&(i&&i.length&&(o["@context"]=i),o["@type"]="Service"),a&&(o.profile=L(a)),s({...o,...r})}function me(t){return s({...p(t),...f(t),...l(t)})}var Ce=new u({collection:[fe],manifest:[ce],canvas:[le],annotationList:[he],sequence:[ue],annotation:[ve],contentResource:[E],choice:[de],range:[ye],service:[ge],layer:[me]});function Se(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"?Ce.traverseUnknown(t):t}function y(t){if((Array.isArray(t["@type"])&&t["@type"].includes("oa:SvgSelector")||t["@type"]=="oa:SvgSelector")&&("chars"in t||"value"in t))return{type:"SvgSelector",value:"chars"in t?t.chars:t.value};if(t["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:t.value};if(t["@type"]==="oa:Choice")return[y(t.default),...(Array.isArray(t.item)?t.item:[t.item]).map(y)];if(t["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in t?t.region:void 0,rotation:"rotation"in t?t.rotation:void 0};throw new Error(`Unsupported selector type: ${t["@type"]}`)}export{I as a,S as b,u as c,h as d,L as e,X as f,Ce as g,Se as h};
import{h as V}from"./chunk-3WVPINNO.js";import{a as z,d as H}from"./chunk-3Q4WO4OP.js";function L(e,n){let i=n||"unknown";if(!e)return;if(typeof e=="string")return{id:e,type:i};if(z(e))return L(e.source,n);let r=i&&i!=="unknown"?i:e.type||e["@type"],t=e.id||e["@id"];if(r&&r.indexOf(":")!==-1&&(r=r.split(":").pop()),t&&r)return{id:t,type:r}}var w={},f="iiif-parser:hasPart",v="iiif-parser:partOf",T="iiif-parser:isExternal",m="__$UNSET$__",I="__$UNWRAP$__",o=[];Object.freeze(o);Object.freeze(w);function te(e){if(e===w||Object.keys(e).length===0)return!0;for(let n in e)return!1;return!0}function oe(e,n){if(n&&n["@explicit"]){let i={},r=Object.keys(n);for(let t of r)t===v||t==="@explicit"||(te(n[t])?i[t]=e[t]:i[t]=n[t]);return i}return e}function F(e,n,i){let r=L(n);if(!r)return[void 0,void 0];let t=e.requests[r.id],a=r.type||e.mapping[r.id];if(!a||t&&t.resourceUri&&(!e.entities[a]||!e.entities[a][t.resourceUri]))return[void 0,void 0];let s=e.entities[a][t?t.resourceUri:r.id];if(r.type&&!s)return F(e,{id:r.id},i);if(s&&s[f]){let c=s[f].find(l=>i?l[v]===i.id:l[v]===s.id);return[oe(s,c),s]}return[s,s]}var xe={id:"https://iiif-parser/annotation",type:"Annotation",behavior:o,label:null,thumbnail:o,summary:null,requiredStatement:null,metadata:o,seeAlso:o,homepage:o,rendering:o,service:o,accessibility:o,audience:o,body:o,bodyValue:null,canonical:null,created:null,creator:o,generated:null,generator:o,modified:null,motivation:o,rights:null,stylesheet:null,target:o,timeMode:void 0,via:o,partOf:o},K={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:o,label:null,thumbnail:o,summary:null,requiredStatement:null,metadata:o,rights:null,provider:o,items:o,seeAlso:o,homepage:o,rendering:o,service:o},G={id:"https://iiif-parser/empty-canvas",type:"Canvas",label:null,behavior:o,thumbnail:o,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:o,rights:null,navDate:null,provider:o,items:o,annotations:o,seeAlso:o,homepage:o,partOf:o,rendering:o,service:o,duration:0,height:0,width:0},X={id:"https://iiif-parser/empty-collection",type:"Collection",label:null,viewingDirection:"left-to-right",behavior:o,thumbnail:o,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:o,rights:null,navDate:null,provider:o,items:o,annotations:o,seeAlso:o,homepage:o,partOf:o,rendering:o,service:o,services:o},Y={id:"https://iiif-parser/empty-manifest",type:"Manifest",annotations:o,behavior:o,homepage:o,items:o,label:null,metadata:o,navDate:null,provider:o,partOf:o,accompanyingCanvas:null,placeholderCanvas:null,rendering:o,requiredStatement:null,rights:null,seeAlso:o,service:o,services:o,start:null,structures:o,summary:null,thumbnail:o,viewingDirection:"left-to-right"},J={id:"https://iiif-parser/empty-canvas",type:"Range",label:null,behavior:o,thumbnail:o,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:o,rights:null,navDate:null,provider:o,items:o,annotations:o,seeAlso:o,homepage:o,partOf:o,rendering:o,service:o,start:null,supplementary:null,viewingDirection:"left-to-right"},B={id:"https://iiif-parser/empty-agent",type:"Agent",label:{},logo:o,seeAlso:o,homepage:o},Q={id:"https://iiif-parser/empty-service",type:"UnknownService"};function _(e,n={}){if(Array.isArray(e))return _(e[0]);if(typeof e=="string"){let[i,r]=e.split("#");return r?{type:"SpecificResource",source:{id:i,type:n.typeHint||"Unknown"},selector:{type:"FragmentSelector",value:r}}:{type:"SpecificResource",source:{id:i,type:n.typeMap&&n.typeMap[i]||n.typeHint||"Unknown"}}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return _(e.items[0]);if(e.type==="SpecificResource")return e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]),e.selector?{type:"SpecificResource",source:e.source,selector:e.selector}:{type:"SpecificResource",source:e.source};if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);let[i,r]=e.id.split("#");return r?{type:"SpecificResource",source:{...e,id:i},selector:{type:"FragmentSelector",value:r}}:{type:"SpecificResource",source:{...e,id:i}}}return{type:"SpecificResource",source:e}}var Le={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}};function ae(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}function Z(e,n){if(typeof e=="string")return{id:e,type:n};if(!e.id)throw new Error(`Invalid resource does not have an ID (${JSON.stringify(e)}, ${n})`);return e}function se(e,n){return(i,r)=>{let t=e[i]?e[i]:{};return(a,s)=>{let c=Z(a,r||i);return c&&c.id&&i?(t[c.id]=t[c.id]?W(t[c.id],c,{parent:s.parent,isTopLevel:n.id===c.id}):W({id:c.id,type:c.type},c,{parent:s.parent,isTopLevel:n.id===c.id}),{id:c.id,type:i==="ContentResource"?i:c.type}):c}}}function $(e,n,i){if(!n)return e;if(Array.isArray(e)){if(!Array.isArray(n))throw new Error("Cannot merge array with non-array");let r=[...e];for(let t of n)if(t["@id"]&&!t.id&&(t.id=t["@id"]),t["@type"]&&!t.type&&(t.type=t["@type"]),t!=null)if(Array.isArray(t))r.push(t);else if(typeof t=="object"&&t.id&&t.type){let a=r.findIndex(s=>s.id===t.id&&s.type===t.type);a>=0&&(r[a]=$(r[a],t))}else e.indexOf(t)===-1&&r.push(t);return r}else if(typeof e=="object"){if(Array.isArray(n)||typeof n!="object")throw new Error("Cannot merge object with non-object");let r={...e},t=[],a=[],s=Object.keys(e).filter(l=>l!==f&&l!=="id"&&l!=="type"),c={},A={};for(let[l,u]of Object.entries(n)){if(l===f||l==="id"||l==="type")continue;let y=r[l];y===u?a.push(l):y===o||!y?(t.push(l),r[l]=u):(y&&u&&(c[l]=y,A[l]=u),r[l]=$(y,u),r[l]===c[l]&&(a.push(l),delete c[l]))}if(i&&(i.parent&&i.parent.id||i.isTopLevel)){let l=[],u={};if(i.parent?u[v]=i.parent.id:i.isTopLevel&&(u[v]=e.id),r[f]&&r[f].length){let y=!(r[f]||[]).find(g=>g["@explicit"]),C=t.length>0||a.length!==s.length;if(y&&C)for(let g of r[f]){let p={...g},j=Object.keys(c);if(p){p["@explicit"]=!0;for(let M of s)M!==f&&(p[M]=w);for(let M of j)p[M]=c[M]}l.push(p)}else l.push(...r[f]);if(C){let g=Object.keys(A);u["@explicit"]=!0;for(let p of t)u[p]=w;for(let p of a)u[p]=w;for(let p of g)u[p]=A[p]}}u.id=r.id,u.type=r.type,l.push(u),r[f]=l}return r}else if(e)return e;return n}function W(e,n,i){if(typeof e=="string")return e;if(n.id!==e.id||n.type!==e.type){if(n.type==="ImageService3")return n;if(e.type==="ImageService3")return e;throw new Error(`Can only merge entities with identical identifiers and type! ${n.type}(${n.id}) => ${e.type}(${e.id})`)}return $({...e},n,i)}function le(e){return(n,i)=>r=>{let{id:t,type:a}=Z(r,i||n);if(typeof t>"u")throw new Error("Found invalid entity without an ID.");return n==="ContentResource"||n==="Service"?e[t]=n:e[t]=a,r}}function ce(e){let n=Object.assign({},e);if(n["@id"]&&(n.id=n["@id"]),n["@type"]&&(n.type=n["@type"]),n.service){let i=[];n.service=Array.isArray(n.service)?n.service:[n.service];for(let r of n.service)i.push({id:r["@id"]||r.id,type:r["@type"]||r.type});n.service=i}return Object.assign({},Q,n)}function de(e){return n=>{e.Service=e.Service?e.Service:{};let i=n.id||n["@id"],r=ce(n);return r&&r.id&&(e.Service[r.id]?e.Service[i]=W(e.Service[i],r):e.Service[i]=r),n}}function ue(e){let n=JSON.stringify(e),i=5381,r=n.length;for(;r;)i=i*33^n.charCodeAt(--r);let a=(i>>>0).toString(16);return a.length%2?"0"+a:a}function U(e){return n=>typeof n=="string"?{id:n,type:e}:n.id?n.type?n:{type:e,...n}:{id:`vault://${ue(n)}`,type:e,...n}}function E(e){return n=>({...e,...n})}function D(e){return Array.isArray(e)?e:[e]}function fe(e){return e.body&&(e.body=D(e.body)),e.seeAlso&&(e.seeAlso=D(e.seeAlso)),e.audience&&(e.audience=D(e.audience)),e.accessibility&&(e.accessibility=D(e.accessibility)),e.motivation&&(e.motivation=D(e.motivation)),e}function ee(e,{typeHint:n,partOfTypeHint:i}={}){if(typeof e=="string"&&(e={id:e,type:n||"unknown"}),z(e))return typeof e.source=="string"&&(e.source={id:e.source,type:n||"unknown"}),e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:i||"Manifest"}]),e;let r;if((e.id||"").indexOf("#")!==-1){let[t,a]=(e.id||"").split("#");e.id=t,a&&(r={type:"FragmentSelector",value:a})}return{type:"SpecificResource",source:e,selector:r}}function pe(e){let n=Object.assign({},e);return e&&e.items&&(n.items=e.items.map(i=>typeof i=="string"||i.type==="Canvas"?ee(i):i)),n}function ye(e){let n=Object.assign({},e);return n.start?(n.start=ee(n.start,{typeHint:"Canvas"}),n):e}function me(e){let n=Object.assign({},e);return n.target?(n.target=_(n.target,{typeHint:"Canvas"}),n):e}function ge(e){return e}function q(e){return typeof e.items>"u"&&(e[T]=!0),e}function Fe(e){let n=V(e),i=ae(),r={},t=se(i,n),a=le(r),c=new H({collection:[q,E(X),a("Collection"),t("Collection")],manifest:[q,E(Y),ye,a("Manifest"),t("Manifest")],canvas:[E(G),a("Canvas"),t("Canvas")],annotationPage:[q,U("AnnotationPage"),E(K),a("AnnotationPage"),t("AnnotationPage")],annotation:[U("Annotation"),fe,me,a("Annotation"),t("Annotation")],contentResource:[U("ContentResource"),a("ContentResource"),t("ContentResource")],range:[E(J),pe,a("Range","Canvas"),t("Range","Canvas")],agent:[E(B),a("Agent"),t("Agent")],specificResource:[ge],service:[de(i)]}).traverseUnknown(n);return{entities:i,resource:c,mapping:r}}function ve(e){let n={};for(let[i,r]of e){if(i===I&&r!==m)return r;r!==m&&typeof r<"u"&&r!==null&&(n[i]=r)}return n}function $e(e,n,i){if(!n.type||!n.id)throw new Error("Unknown entity");if(!i[n.type])throw new Error(`Serializer not found for ${n.type}`);function r(t,a,s=0){let c=i[t.type];if(!c)return m;if(s>20)throw new Error("Circular reference: "+t.id+" "+t.type);let[A,l]=F(e,t.type?t:t.id,a)||(t.id&&t.type?t:null);if(!A)return m;let u=c(A,e,{parent:a,isTopLevel:n.id===t.id,fullResource:l}),y=u.next();for(;!y.done;){let C=y.value,g=m;if(C)if(Array.isArray(C)){let p=[];for(let j of C)p.push(r(j,t,s+1));g=p}else g=r(C,t,s+1);y=u.next(g)}return y.value===m?m:ve(y.value)}return r(n)}function P(e,{allowSourceString:n=!0,allowString:i=!1,allowedStringType:r}={}){let t=a=>{if(n&&a&&a.source&&typeof a.source!="string"){let s=Object.keys(a.source);if(a.source.id&&a.source.type&&s.length===2)return{...a,source:a.source.id}}return a};if(e){if(e.source&&e.source.partOf)return t(e);let a=Object.keys(e);if(a.length===2&&e.type&&e.source||a.length===3&&e.type&&e.source&&a.indexOf("selector")!==-1&&!e.selector)return i&&(!r||r===e.source.type)?e.source.id:e.source.type==="ContentResource"?{type:"SpecificResource",source:e.source.id}:e.source;if(e.selector&&!Array.isArray(e.selector)&&typeof e.selector!="string"&&e.selector.type==="FragmentSelector"){let s=`${e.source.id}#${e.selector.value}`;return i?s:{id:s,type:e.source.type}}}return t(e)}function O(e){if(!e)return;let n=Object.keys(e);if(n.length!==0){if(n.length===1){let i=n[0];if(!i)return"";let r=(e[i]||[]).join("");return i==="@none"||i==="none"||i==="en"?r:{"@language":i,"@value":r}}return n.map(i=>({"@language":i,"@value":(e[i]||[]).join("")}))}}function ne(e){return Array.isArray(e)?e.map(n=>ne(n)):typeof e=="string"?e:e.type&&e.type==="Canvas"?e.id:e}function h(e,n=!1){if(e)return e.length>1&&!n?e:e[0]||void 0}function he(e){if(e){if(typeof e=="string")return{"@id":e};if("@id"in e){let n={...e};return delete n["@type"],n}return{"@context":"http://iiif.io/api/image/2/context.json","@id":e.id,profile:`http://iiif.io/api/image/2/profiles/${e.profile}.json`}}}function N(e,n){return[["@id",e.id],["@type",n],["format",e.format],["height",e.height],["width",e.width],["viewingDirection",e.viewingDirection!=="left-to-right"?e.viewingDirection:void 0],["license",e.license?e.license:void 0]]}function*b(e){let n=e.provider?yield e.provider[0]:void 0;return[["label",O(e.label)],["metadata",e.metadata&&e.metadata.length?e.metadata.map(i=>({label:O(i.label)||"",value:O(i.value)||""})):void 0],["description",O(e.summary)],["thumbnail",h(yield e.thumbnail)],["navDate",e.navDate],["logo",n?h(n.logo):void 0],["homepage",n?n.homepage:void 0],["attribution",e.requiredStatement?O(e.requiredStatement.value):void 0]]}function*k(e){let n=e.start&&e.start.type&&e.start.type==="SpecificResource"?P(e.start):e.start;return[["seeAlso",h(yield e.seeAlso)],["service",h((e.service||[]).map(he))],["rendering",h(yield e.rendering)],["startCanvas",n?n.id:void 0]]}function Se(e){return e.type==="SpecificResource"}function Re(e){return e&&e.type==="FragmentSelector"}function Ae(e){if(e&&Se(e)){let n=e.id,i=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return Re(i)&&(n+="#"+i.value),n}return e?.id}var Ke={Manifest:function*(e,n,{isTopLevel:i}){return[...i?[["@context","http://iiif.io/api/presentation/2/context.json"]]:[],...N(e,"sc:Manifest"),...yield*b(e),...yield*k(e),["sequences",[{"@id":`${e.id}/sequence0`,"@type":"sc:Sequence",canvases:yield e.items}]],["structures",yield e.structures]]},Canvas:function*(e){let i=(yield e.items)[0];return[...N(e,"sc:Canvas"),...yield*b(e),...yield*k(e),["images",i?[i.resources]:void 0],["annotations",e.annotations&&e.annotations.length?h(yield e.annotations):void 0]]},AnnotationPage:function*(e){return[...N(e,"sc:AnnotationList"),...yield*b(e),["resources",e.items&&e.items.length?h(yield e.items):void 0]]},Annotation:function*(e){return[["@id",e.id],["@type","oa:Annotation"],["motivation","sc:painting"],["on",ne(e.target)],["resource",h(yield e.body,!0)]]},ContentResource:function*(e){switch(e.type){case"Image":return[...N(e,"dctypes:Image"),...yield*b(e),...yield*k(e)];case"Text":case"Dataset":default:return[...N(e,void 0),...yield*b(e)]}},AnnotationCollection:function*(e){return[["@id",e.id],["@type","sc:Layer"],["label",O(e.label)]]},Collection:function*(e){return[...N(e,"sc:Collection"),...yield*b(e),...yield*k(e),["members",yield*e.items]]},Range:function*(e){let n=[],i=[];if(e.items)for(let r of e.items){let t=r.type==="SpecificResource"?r.source:r;if(t){let a=yield t;n.push({"@id":Ae(r),"@type":t.type,label:a?a.label:void 0,within:e.id}),t.type==="Canvas"&&i.push(t.id)}}return[...N(e,"sc:Range"),...yield*b(e),...yield*k(e),["canvases",i.length===n.length?i:void 0],["members",i.length!==n.length?n:void 0]]}};function x(e){return[["id",e.id?.startsWith("vault://")?void 0:e.id],["type",e.type],["format",e.format],["profile",e.profile],["height",e.height||void 0],["width",e.width||void 0],["duration",e.duration||void 0],["viewingDirection",e.viewingDirection!=="left-to-right"?e.viewingDirection:void 0],["behavior",e.behavior&&e.behavior.length?e.behavior:void 0],["timeMode",e.timeMode],["motivation",Array.isArray(e.motivation)?e.motivation[0]:e.motivation],[f,m]]}function d(e){if(e===m||!e||e.length===0)return;let n=e.filter(i=>i!==m);if(n.length!==0)return n}function re(e){if(e&&e.type&&e.type==="ImageService2"){let{id:n,type:i,profile:r,...t}=e,a=typeof r=="string"?r:Array.isArray(r)?r.find(s=>typeof s=="string"):"";return{"@id":n,"@type":i,profile:a?a.startsWith("http")?a:`http://iiif.io/api/image/2/${a}.json`:"http://iiif.io/api/image/2/level0.json",...t}}return e}function ie(e){if(Array.isArray(e)||(e=e?[e]:[]),!(!e||e.length===0))return e.map(re)}function*S(e){return[["label",e.label],["metadata",d(e.metadata)],["summary",e.summary],["requiredStatement",e.requiredStatement],["rights",Array.isArray(e.rights)?e.rights[0]||void 0:e.rights||void 0],["navDate",e.navDate],["language",e.language],["thumbnail",d(yield e.thumbnail)],["placeholderCanvas",yield e.placeholderCanvas],["accompanyingCanvas",yield e.accompanyingCanvas],["provider",d(yield e.provider)]]}function*R(e){return[["seeAlso",d(yield e.seeAlso)],["service",d(ie(e.service))],["services",d(ie(e.services))],["rendering",d(yield e.rendering)],["supplementary",d(yield e.supplementary)],["homepage",d(yield e.homepage)],["logo",d(yield e.logo)],["partOf",d(yield e.partOf)],["start",e.start?P(e.start):e.start]]}var Be={Manifest:function*(e,n,{isTopLevel:i}){return i?[["@context",e["@context"]?e["@context"]:"http://iiif.io/api/presentation/3/context.json"],...x(e),...yield*S(e),...yield*R(e),["items",yield e.items],["structures",d(yield e.structures)],["annotations",d(yield e.annotations)],["navPlace",e.navPlace]]:[...x(e),...yield*S(e)]},Canvas:function*(e){return[...x(e),...yield*S(e),...yield*R(e),["items",yield e.items],["annotations",d(yield e.annotations)],["navPlace",e.navPlace]]},Agent:function*(e){return[["id",e.id],["type","Agent"],["label",e.label],...yield*R(e)]},AnnotationPage:function*(e){let n=Object.entries(e).map(([r,t])=>[r,Array.isArray(t)?d(t):t]).filter(([r,t])=>r!=="items"&&r!=="id"&&r!==f&&r!==v&&r!==T),i=yield e.items;return[["id",e.id?.startsWith("vault://")?void 0:e.id],...n,...yield*R(e),["items",i.length||e[T]===!1?i:m]]},Service:function*(e){return[[I,re(e)]]},Annotation:function*(e){let n=Object.entries(e).map(([r,t])=>r==="motivation"?[r,Array.isArray(t)?t[0]:t]:r==="target"?[r,P(t,{allowString:!0,allowSourceString:!0,allowedStringType:"Canvas"})]:[r,Array.isArray(t)?d(t):t]).filter(([r])=>r!=="body"&&r!==f&&r!==T),i;if(Array.isArray(e.body)){let r=[];for(let t of e.body)if(t&&z(t)){let a={...t};a.source=yield t.source,r.push(P(a,{allowSourceString:!0}))}else r.push(yield t);i=r}else e.body&&z(e.body)?(i={...e.body},i.source=yield e.body.source):i=yield e.body;return[...n,...yield*S(e),...yield*R(e),["body",i.length===1?i[0]:i]]},ContentResource:function*(e){return Ce([...x(e),...yield*S(e),...yield*R(e),["annotations",d(yield e.annotations)],["items",d(yield e.items)]],e)},AnnotationCollection:function*(e){return[["id",e.id],["type","AnnotationCollection"],["label",e.label]]},Collection:function*(e,n,{isTopLevel:i}){return i?[["@context","http://iiif.io/api/presentation/3/context.json"],...x(e),...yield*S(e),...yield*R(e),["items",d(yield e.items)],["navPlace",e.navPlace]]:[...x(e),...yield*S(e)]},Range:function*(e){let n=[];for(let i of e.items)i.type==="Range"?n.push(yield i):i&&i.type==="SpecificResource"?n.push(P(i)):n.push(i);return[...x(e),...yield*S(e),...yield*R(e),["items",n],["annotations",d(yield e.annotations)],["navPlace",e.navPlace]]}};function Ce(e,n){let i=Object.keys(n),r=e.map(([t])=>t);for(let t of i)t===f||t===T||r.indexOf(t)===-1&&typeof n[t]<"u"&&e.push([t,n[t]]);return e}export{L as a,w as b,f as c,v as d,T as e,m as f,I as g,o as h,te as i,oe as j,F as k,xe as l,K as m,G as n,X as o,Y as p,J as q,B as r,Q as s,Le as t,ae as u,$ as v,W as w,ge as x,q as y,Fe as z,ve as A,$e as B,P as C,O as D,Ke as E,Be as F};
var e="http://library.stanford.edu/iiif/image-api/compliance.html#level0",i="http://library.stanford.edu/iiif/image-api/compliance.html#level1",t="http://library.stanford.edu/iiif/image-api/compliance.html#level2",o="http://library.stanford.edu/iiif/image-api/conformance.html#level0",r="http://library.stanford.edu/iiif/image-api/conformance.html#level1",a="http://library.stanford.edu/iiif/image-api/conformance.html#level2",_="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",I="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",p="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",s="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",n="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",E="http://iiif.io/api/image/1/level0.json",c="http://iiif.io/api/image/1/profiles/level0.json",F="http://iiif.io/api/image/1/level1.json",m="http://iiif.io/api/image/1/profiles/level1.json",f="http://iiif.io/api/image/1/level2.json",x="http://iiif.io/api/image/1/profiles/level2.json",A="http://iiif.io/api/image/2/level0.json",L="http://iiif.io/api/image/2/profiles/level0.json",h="http://iiif.io/api/image/2/level1.json",y="http://iiif.io/api/image/2/profiles/level1.json",d="http://iiif.io/api/image/2/level2.json",g="http://iiif.io/api/image/2/profiles/level2.json",M="level0",O="level1",v="level2",u="http://iiif.io/api/image/2/level0",N="http://iiif.io/api/image/2/level1",G="http://iiif.io/api/image/2/level2",R=[G,t,a,l,n,f,x,d,g,v],C=[...R,N,i,r,I,s,F,m,h,y,O],B=[u,N,G,e,i,t,o,r,a,_,I,l,p,s,n,E,c,F,m,f,x,A,L,h,y,d,g,M,O,v],P=B,S=[u,e,o,_,p,E,c,A,L,M],z={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},b={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},j={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]},V=["baseUriRedirect","canonicalLinkHeader","cors","jsonldMediaType","mirroring","profileLinkHeader","regionByPct","regionByPx","regionSquare","rotationArbitrary","rotationBy90s","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh","sizeUpscaling","sizeByWhListed","sizeByDistortedWh","sizeByForcedWh"];export{e as a,i as b,t as c,o as d,r as e,a as f,_ as g,I as h,l as i,p as j,s as k,n as l,E as m,c as n,F as o,m as p,f as q,x as r,A as s,L as t,h as u,y as v,d as w,g as x,M as y,O as z,v as A,u as B,N as C,G as D,R as E,C as F,B as G,P as H,S as I,z as J,b as K,j as L,V as M};
+1
-1

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

import"./chunk-D22QKJZO.js";function he(i){let e=i.replace(/(https?:\/\/)?(www.)?/i,"");return e.indexOf("/")!==-1?e.split("/")[0]:e}function y(i){try{if(i==="full")return{full:!0};if(i==="square")return{square:!0};let e=i.startsWith("pct:"),r=i.substr(e?4:0).split(",").map(o=>parseFloat(o));return{x:r[0],y:r[1],w:r[2],h:r[3],percent:e}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+i)}}function F(i){let e={upscaled:!1,max:!1,confined:!1};if(i[0]==="^"&&(e.upscaled=!0,i=i.slice(1)),i==="max"||i==="full")return e.max=!0,e.serialiseAsFull=i==="full",e;if(i[0]==="!"&&(e.confined=!0,i=i.slice(1)),i[0]==="p")return e.percentScale=parseFloat(i.slice(4)),e;let t=i.split(",").map(r=>r.trim());return t.length&&(t[0]!==""&&(e.width=parseInt(t[0],10)),t[1]!==""&&(e.height=parseInt(t[1],10))),e}function S(i){let e={angle:0};if(i[0]==="!"&&(e.mirror=!0,i=i.substr(1)),e.angle=parseFloat(i)%360,Number.isNaN(e.angle))throw new Error(`Invalid rotation ${i}`);return e}function E(i,e=""){let t=i.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!t)throw new Error(`Invalid or unknown input ${i}`);let r=t[2],o=t[3],a=t[4];if(a[0]==="/"&&(a=a.substring(1)),e.length>0){if(e[0]==="/"&&(e=e.substring(1)),e!==a.substring(0,e.length))throw new Error(`Path does not start with prefix (path: ${a}, prefix: ${e})`);a=a.substring(e.length)}return{scheme:r,server:o,path:a,prefix:e}}function z(i,e=""){let{path:t,scheme:r,server:o,prefix:a}=E(i,e),n=t.split("/").reverse(),[s,m,f,p,...g]=n,l=g.reverse().filter(Boolean).join("/");if(n.length===1||s==="")return{type:"base",scheme:r,server:o,prefix:a,identifier:l};if(s==="info.json"){let[,...ce]=n;return{type:"info",scheme:r,server:o,prefix:a,identifier:ce.reverse().filter(Boolean).join("/")}}if(typeof r>"u"||typeof o>"u"||typeof t>"u"||typeof p>"u"||typeof f>"u"||typeof m>"u"||typeof s>"u")throw new Error("Invalid image service URL");let[ue="",xe=""]=s.split(".");return{type:"image",scheme:r,server:o,prefix:a,identifier:l,originalPath:t,region:y(p),size:F(f),rotation:S(m),quality:ue,format:xe}}var A="http://library.stanford.edu/iiif/image-api/compliance.html#level0",v="http://library.stanford.edu/iiif/image-api/compliance.html#level1",O="http://library.stanford.edu/iiif/image-api/compliance.html#level2",L="http://library.stanford.edu/iiif/image-api/conformance.html#level0",R="http://library.stanford.edu/iiif/image-api/conformance.html#level1",w="http://library.stanford.edu/iiif/image-api/conformance.html#level2",M="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",P="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",B="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",N="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",j="http://iiif.io/api/image/1/level0.json",G="http://iiif.io/api/image/1/profiles/level0.json",$="http://iiif.io/api/image/1/level1.json",C="http://iiif.io/api/image/1/profiles/level1.json",T="http://iiif.io/api/image/1/level2.json",H="http://iiif.io/api/image/1/profiles/level2.json",Q="http://iiif.io/api/image/2/level0.json",V="http://iiif.io/api/image/2/profiles/level0.json",D="http://iiif.io/api/image/2/level1.json",U="http://iiif.io/api/image/2/profiles/level1.json",k="http://iiif.io/api/image/2/level2.json",J="http://iiif.io/api/image/2/profiles/level2.json",Z="level0",K="level1",X="level2",Y="http://iiif.io/api/image/2/level0",q="http://iiif.io/api/image/2/level1",ee="http://iiif.io/api/image/2/level2",d=[ee,O,w,B,W,T,H,k,J,X],u=[...d,q,v,R,P,N,$,C,D,U,K],I=[Y,q,ee,A,v,O,L,R,w,M,P,B,b,N,W,j,G,$,C,T,H,Q,V,D,U,k,J,Z,K,X],ve=I,ie=[Y,A,L,M,b,j,G,Q,V,Z],te={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},re={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},oe={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]},_=["baseUriRedirect","canonicalLinkHeader","cors","jsonldMediaType","mirroring","profileLinkHeader","regionByPct","regionByPx","regionSquare","rotationArbitrary","rotationBy90s","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh","sizeUpscaling","sizeByWhListed","sizeByDistortedWh","sizeByForcedWh"];function ae(i){return d.indexOf(i)!==-1?oe:u.indexOf(i)!==-1?re:te}function x(i){let e=i?Array.isArray(i.profile)?i.profile:[i.profile]:[],t={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let r of e)if(typeof r=="string"&&(r=ae(r)),!!r){if(r.formats)for(let o of r.formats)t.extraFormats.indexOf(o)===-1&&t.extraFormats.push(o);if(r.qualities)for(let o of r.qualities)t.extraQualities.indexOf(o)===-1&&t.extraQualities.push(o);if(r.supports)for(let o of r.supports)t.extraFeatures.indexOf(o)===-1&&t.extraFeatures.push(o);if(r.maxHeight&&(t.maxHeight=r.maxHeight),r.maxWidth&&(t.maxWidth=r.maxWidth),r.maxArea&&(t.maxArea=r.maxArea),r.extraFormats)for(let o of r.extraFormats)t.extraFormats.indexOf(o)===-1&&t.extraFormats.push(o);if(r.extraQualities)for(let o of r.extraQualities)t.extraQualities.indexOf(o)===-1&&t.extraQualities.push(o);if(r.extraFeatures)for(let o of r.extraFeatures)t.extraFeatures.indexOf(o)===-1&&t.extraFeatures.push(o);r.maxHeight&&(t.maxHeight=r.maxHeight),r.maxWidth&&(t.maxWidth=r.maxWidth),r.maxArea&&(t.maxArea=r.maxArea)}if(i.extraFormats)for(let r of i.extraFormats)t.extraFormats.indexOf(r)===-1&&t.extraFormats.push(r);if(i.extraFeatures)for(let r of i.extraFeatures)t.extraFeatures.indexOf(r)===-1&&t.extraFeatures.push(r);if(i.extraQualities)for(let r of i.extraQualities)t.extraQualities.indexOf(r)===-1&&t.extraQualities.push(r);return t}function be(i){let e=Array.isArray(i.profile)?i.profile:[i.profile];for(let t of e)if(typeof t=="string"&&ie.indexOf(t)!==-1)return!0;return!1}function ne(i){if(i["@id"])return i["@id"];if(i.id)return i.id}function c(i){if(!i||!i.profile||!ne(i))return!1;let e=Array.isArray(i.profile)?i.profile:[i.profile];for(let t of e)if(typeof t=="string"&&I.indexOf(t)!==-1)return!0;return!1}function h(i,e){if(!c(i))return[!1,"Not a valid image service"];e.extraFeatures=e.extraFeatures?e.extraFeatures:[];let t=x(i);if(e.exactSize){let r=!1;if(i.sizes)for(let o of i.sizes)o.width&&o.width===e.exactSize.width&&(_.indexOf("sizeByW")!==-1||o.height&&o.height===e.exactSize.height)&&(r=!0),o.height&&o.height===e.exactSize.height&&(_.indexOf("sizeByH")!==-1||o.width&&o.width===e.exactSize.width)&&(r=!0);r||(e.maxWidth=Math.max(e.maxWidth||0,e.exactSize.width||0)||void 0,e.maxHeight=Math.max(e.maxHeight||0,e.exactSize.height||0)||void 0,e.maxArea=Math.max(e.maxArea||0,(e.exactSize.width&&e.exactSize.height?e.exactSize.width*e.exactSize.height:e.maxArea)||0)||void 0,!e.exactSize.height&&e.exactSize.width?e.extraFeatures.indexOf("sizeByW")===-1&&e.extraFeatures.push("sizeByW"):!e.exactSize.width&&e.exactSize.height&&e.extraFeatures.indexOf("sizeByH")===-1&&e.extraFeatures.push("sizeByH"))}if(e.maxArea&&t.maxArea&&e.maxArea>t.maxArea)return[!1,`Max area is ${t.maxArea}`];if(e.maxWidth&&t.maxWidth&&e.maxWidth>t.maxWidth)return[!1,`Max width is ${t.maxWidth}`];if(e.maxHeight&&t.maxHeight&&e.maxHeight>t.maxHeight)return[!1,`Max height is ${t.maxHeight}`];if(e.extraFeatures){let r=[];for(let o of e.extraFeatures)t.extraFeatures.indexOf(o)===-1&&r.push(o);if(r.length)return[!1,`Missing features: ${r.join(", ")}`]}if(e.extraFormats){let r=[];for(let o of e.extraFormats)t.extraFormats.indexOf(o)===-1&&r.push(o);if(r.length)return[!1,`Missing formats: ${r.join(", ")}`]}if(e.extraQualities){let r=[];for(let o of e.extraQualities)t.extraQualities.indexOf(o)===-1&&r.push(o);if(r.length)return[!1,`Missing qualities: ${r.join(", ")}`]}return[!0]}function Je(i){if(!c(i))return!1;let e=Array.isArray(i.profile)?i.profile:[i.profile];for(let t of e)if(typeof t=="string"){if(u.indexOf(t)!==-1)return!0}else{let r=[...t.supports||[],...t.extraFeatures||[]];if(r.indexOf("regionByPx")!==-1&&(r.indexOf("sizeByW")!==-1||r.indexOf("sizeByWh")!==-1))return!0}return!1}function Xe(i,e){return h(i,{extraFormats:[e]})}function ei(i,e){if(e.type!=="image")return[!0];let t=[];e.rotation.mirror&&t.push("mirroring"),e.region.percent&&t.push("regionByPct"),e.region.square?t.push("regionSquare"):e.region.full||t.push("regionByPx"),e.rotation.angle&&(e.rotation.angle%90?t.push("rotationArbitrary"):t.push("rotationBy90s")),e.size.confined&&t.push("sizeByConfinedWh"),!e.size.width&&e.size.height&&t.push("sizeByH"),e.size.percentScale&&t.push("sizeByPct"),(i.sizes||[]).find(n=>n.width===e.size.width&&!e.size.height||n.height===e.size.height&&!e.size.width||n.height===e.size.height&&n.width===e.size.width)?t.push("sizeByWhListed"):(e.size.width&&!e.size.height&&t.push("sizeByW"),e.size.width&&e.size.height&&t.push("sizeByWh")),e.size.upscaled&&t.push("sizeUpscaling");let[o,a]=h(i,{extraFeatures:t,extraQualities:[e.quality],extraFormats:[e.format],exactSize:e.size});return o?[!0]:[!1,a]}function se({x:i=0,y:e=0,w:t,h:r,full:o,square:a,percent:n}){if(o)return"full";if(a)return"square";if(typeof t>"u"||typeof r>"u")throw new Error("RegionParameter: invalid region");let s=`${i},${e},${t},${r}`;return n?`pct:${s}`:s}function fe({max:i,percentScale:e,upscaled:t,confined:r,width:o,height:a,serialiseAsFull:n}){let s=[];return t&&s.push("^"),i?(s.push(n?"full":"max"),s.join("")):(r&&s.push("!"),e&&s.push(`pct:${e}`),o&&s.push(`${o}`),s.push(","),a&&s.push(`${a}`),s.join(""))}function me(i){return`${i.mirror?"!":""}${(i.angle||0)%360}`}function pe(i,e){let t=i.prefix.startsWith("/")?i.prefix.substr(1):i.prefix,r=`${i.scheme}://${i.server}/${t?`${t}/`:""}${i.identifier}`;if(i.type==="base")return r;if(i.type==="info")return`${r}/info.json`;let{size:o}=i,{region:a,rotation:n,format:s,quality:m}=i;if(e){let f=e["@context"]?Array.isArray(e["@context"])?e["@context"]:[e["@context"]]:[],p=f.indexOf("http://iiif.io/api/image/2/context.json")!==-1,g=f.indexOf("http://iiif.io/api/image/3/context.json")!==-1;if((o.width===e.width&&!o.height||o.height===e.height&&!o.width||o.width===e.width&&o.height===e.height)&&(o={...o,max:!0}),p&&(o.max&&!o.serialiseAsFull&&(o={...o,serialiseAsFull:!0}),!o.max&&o.width&&o.height&&(o={...o,height:void 0})),g&&(o.max&&o.serialiseAsFull&&(o={...o,serialiseAsFull:!1}),o.width&&!o.height&&e.width&&e.height)){let l=e.height/e.width;o={...o,height:Math.ceil(o.width*l)}}}return[r,se(a),fe(o),me(n),`${m}.${s}`].filter(Boolean).join("/")}function pi(i,e){return pe({...i,type:"info"},e)}function le(i){return i.endsWith("info.json")?i:i.endsWith("/")?`${i}info.json`:`${i}/info.json`}function gi(i){let e=z(le(i.id));if(e.type!=="info")throw new Error("Invalid service URL");let t=x(i);return{identifier:e.identifier,originalPath:"",server:e.server,prefix:e.prefix,scheme:e.scheme,type:"image",quality:t.extraQualities.indexOf("default")===-1?t.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}}function Ii(i,e,t){let r=t.length,o=[];for(let a=0;a<r;a++){let n=t[a];if(!n)continue;let s=n.width;o.push(i/s)}return o}function yi(i,e,t){let r=t.length,o=[];for(let a=0;a<r;a++){let n=t[a];n&&o.push({width:Math.floor(i/n),height:Math.floor(e/n)})}return o}function Si(i){if(i["@type"])return i["@type"];if(i.type)return i.type}export{j as IIIF_1_IMAGE_LEVEL_0,G as IIIF_1_IMAGE_LEVEL_0_PROFILE,$ as IIIF_1_IMAGE_LEVEL_1,C as IIIF_1_IMAGE_LEVEL_1_PROFILE,T as IIIF_1_IMAGE_LEVEL_2,H as IIIF_1_IMAGE_LEVEL_2_PROFILE,Q as IIIF_2_IMAGE_LEVEL_0,Y as IIIF_2_IMAGE_LEVEL_0_NO_JSON,V as IIIF_2_IMAGE_LEVEL_0_PROFILE,D as IIIF_2_IMAGE_LEVEL_1,q as IIIF_2_IMAGE_LEVEL_1_NO_JSON,U as IIIF_2_IMAGE_LEVEL_1_PROFILE,k as IIIF_2_IMAGE_LEVEL_2,ee as IIIF_2_IMAGE_LEVEL_2_NO_JSON,J as IIIF_2_IMAGE_LEVEL_2_PROFILE,Z as IIIF_3_IMAGE_LEVEL_0,K as IIIF_3_IMAGE_LEVEL_1,X as IIIF_3_IMAGE_LEVEL_2,M as STANFORD_IIIF_1_IMAGE_COMPLIANCE_0,P as STANFORD_IIIF_1_IMAGE_COMPLIANCE_1,B as STANFORD_IIIF_1_IMAGE_COMPLIANCE_2,b as STANFORD_IIIF_1_IMAGE_CONFORMANCE_0,N as STANFORD_IIIF_1_IMAGE_CONFORMANCE_1,W as STANFORD_IIIF_1_IMAGE_CONFORMANCE_2,A as STANFORD_IIIF_IMAGE_COMPLIANCE_0,v as STANFORD_IIIF_IMAGE_COMPLIANCE_1,O as STANFORD_IIIF_IMAGE_COMPLIANCE_2,L as STANFORD_IIIF_IMAGE_CONFORMANCE_0,R as STANFORD_IIIF_IMAGE_CONFORMANCE_1,w as STANFORD_IIIF_IMAGE_CONFORMANCE_2,le as canonicalServiceUrl,x as combineProfiles,gi as createImageServiceRequest,_ as extraFeatures,Ii as extractFixedSizeScales,yi as fixedSizesFromScales,ne as getId,Si as getType,I as imageServiceProfiles,pi as imageServiceRequestInfo,pe as imageServiceRequestToString,Xe as imageServiceSupportsFormat,ei as imageServiceSupportsRequest,c as isImageService,be as isLevel0,te as level0,ve as level0Support,re as level1,u as level1Support,oe as level2,d as level2Support,ae as levelToProfile,ie as onlyLevel0,he as parseImageServerFromId,z as parseImageServiceRequest,E as parseImageServiceUrl,y as parseRegionParameter,S as parseRotationParameter,F as parseSizeParameter,se as regionParameterToString,me as rotationParameterToString,fe as sizeParameterToString,h as supports,Je as supportsCustomSizes};
import{A as pe,B as xe,C as le,D as ge,E as S,F as x,G as y,H as he,I as z,J as I,K as w,L as F,M as d,a as L,b as U,c as N,d as C,e as k,f as Z,g as D,h as G,i as J,j as K,k as V,l as X,m as Y,n as _,o as q,p as ee,q as te,r as ie,s as re,t as oe,u as ae,v as ne,w as fe,x as se,y as me,z as ue}from"./chunk-J657UVVW.js";import"./chunk-D22QKJZO.js";function ce(t){let e=t.replace(/(https?:\/\/)?(www.)?/i,"");return e.indexOf("/")!==-1?e.split("/")[0]:e}function v(t){try{if(t==="full")return{full:!0};if(t==="square")return{square:!0};let e=t.startsWith("pct:"),r=t.substr(e?4:0).split(",").map(o=>parseFloat(o));return{x:r[0],y:r[1],w:r[2],h:r[3],percent:e}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+t)}}function R(t){let e={upscaled:!1,max:!1,confined:!1};if(t[0]==="^"&&(e.upscaled=!0,t=t.slice(1)),t==="max"||t==="full")return e.max=!0,e.serialiseAsFull=t==="full",e;if(t[0]==="!"&&(e.confined=!0,t=t.slice(1)),t[0]==="p")return e.percentScale=parseFloat(t.slice(4)),e;let i=t.split(",").map(r=>r.trim());return i.length&&(i[0]!==""&&(e.width=parseInt(i[0],10)),i[1]!==""&&(e.height=parseInt(i[1],10))),e}function P(t){let e={angle:0};if(t[0]==="!"&&(e.mirror=!0,t=t.substr(1)),e.angle=parseFloat(t)%360,Number.isNaN(e.angle))throw new Error(`Invalid rotation ${t}`);return e}function A(t,e=""){let i=t.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!i)throw new Error(`Invalid or unknown input ${t}`);let r=i[2],o=i[3],a=i[4];if(a[0]==="/"&&(a=a.substring(1)),e.length>0){if(e[0]==="/"&&(e=e.substring(1)),e!==a.substring(0,e.length))throw new Error(`Path does not start with prefix (path: ${a}, prefix: ${e})`);a=a.substring(e.length)}return{scheme:r,server:o,path:a,prefix:e}}function $(t,e=""){let{path:i,scheme:r,server:o,prefix:a}=A(t,e),n=i.split("/").reverse(),[f,m,s,u,...c]=n,p=c.reverse().filter(Boolean).join("/");if(n.length===1||f==="")return{type:"base",scheme:r,server:o,prefix:a,identifier:p};if(f==="info.json"){let[,...E]=n;return{type:"info",scheme:r,server:o,prefix:a,identifier:E.reverse().filter(Boolean).join("/")}}if(typeof r>"u"||typeof o>"u"||typeof i>"u"||typeof u>"u"||typeof s>"u"||typeof m>"u"||typeof f>"u")throw new Error("Invalid image service URL");let[M="",T=""]=f.split(".");return{type:"image",scheme:r,server:o,prefix:a,identifier:p,originalPath:i,region:v(u),size:R(s),rotation:P(m),quality:M,format:T}}function O(t){return S.indexOf(t)!==-1?F:x.indexOf(t)!==-1?w:I}function l(t){let e=t?Array.isArray(t.profile)?t.profile:[t.profile]:[],i={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let r of e)if(typeof r=="string"&&(r=O(r)),!!r){if(r.formats)for(let o of r.formats)i.extraFormats.indexOf(o)===-1&&i.extraFormats.push(o);if(r.qualities)for(let o of r.qualities)i.extraQualities.indexOf(o)===-1&&i.extraQualities.push(o);if(r.supports)for(let o of r.supports)i.extraFeatures.indexOf(o)===-1&&i.extraFeatures.push(o);if(r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea),r.extraFormats)for(let o of r.extraFormats)i.extraFormats.indexOf(o)===-1&&i.extraFormats.push(o);if(r.extraQualities)for(let o of r.extraQualities)i.extraQualities.indexOf(o)===-1&&i.extraQualities.push(o);if(r.extraFeatures)for(let o of r.extraFeatures)i.extraFeatures.indexOf(o)===-1&&i.extraFeatures.push(o);r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea)}if(t.extraFormats)for(let r of t.extraFormats)i.extraFormats.indexOf(r)===-1&&i.extraFormats.push(r);if(t.extraFeatures)for(let r of t.extraFeatures)i.extraFeatures.indexOf(r)===-1&&i.extraFeatures.push(r);if(t.extraQualities)for(let r of t.extraQualities)i.extraQualities.indexOf(r)===-1&&i.extraQualities.push(r);return i}function Qe(t){let e=Array.isArray(t.profile)?t.profile:[t.profile];for(let i of e)if(typeof i=="string"&&z.indexOf(i)!==-1)return!0;return!1}function b(t){if(t["@id"])return t["@id"];if(t.id)return t.id}function g(t){if(!t||!t.profile||!b(t))return!1;let e=Array.isArray(t.profile)?t.profile:[t.profile];for(let i of e)if(typeof i=="string"&&y.indexOf(i)!==-1)return!0;return!1}function h(t,e){if(!g(t))return[!1,"Not a valid image service"];e.extraFeatures=e.extraFeatures?e.extraFeatures:[];let i=l(t);if(e.exactSize){let r=!1;if(t.sizes)for(let o of t.sizes)o.width&&o.width===e.exactSize.width&&(d.indexOf("sizeByW")!==-1||o.height&&o.height===e.exactSize.height)&&(r=!0),o.height&&o.height===e.exactSize.height&&(d.indexOf("sizeByH")!==-1||o.width&&o.width===e.exactSize.width)&&(r=!0);r||(e.maxWidth=Math.max(e.maxWidth||0,e.exactSize.width||0)||void 0,e.maxHeight=Math.max(e.maxHeight||0,e.exactSize.height||0)||void 0,e.maxArea=Math.max(e.maxArea||0,(e.exactSize.width&&e.exactSize.height?e.exactSize.width*e.exactSize.height:e.maxArea)||0)||void 0,!e.exactSize.height&&e.exactSize.width?e.extraFeatures.indexOf("sizeByW")===-1&&e.extraFeatures.push("sizeByW"):!e.exactSize.width&&e.exactSize.height&&e.extraFeatures.indexOf("sizeByH")===-1&&e.extraFeatures.push("sizeByH"))}if(e.maxArea&&i.maxArea&&e.maxArea>i.maxArea)return[!1,`Max area is ${i.maxArea}`];if(e.maxWidth&&i.maxWidth&&e.maxWidth>i.maxWidth)return[!1,`Max width is ${i.maxWidth}`];if(e.maxHeight&&i.maxHeight&&e.maxHeight>i.maxHeight)return[!1,`Max height is ${i.maxHeight}`];if(e.extraFeatures){let r=[];for(let o of e.extraFeatures)i.extraFeatures.indexOf(o)===-1&&r.push(o);if(r.length)return[!1,`Missing features: ${r.join(", ")}`]}if(e.extraFormats){let r=[];for(let o of e.extraFormats)i.extraFormats.indexOf(o)===-1&&r.push(o);if(r.length)return[!1,`Missing formats: ${r.join(", ")}`]}if(e.extraQualities){let r=[];for(let o of e.extraQualities)i.extraQualities.indexOf(o)===-1&&r.push(o);if(r.length)return[!1,`Missing qualities: ${r.join(", ")}`]}return[!0]}function Je(t){if(!g(t))return!1;let e=Array.isArray(t.profile)?t.profile:[t.profile];for(let i of e)if(typeof i=="string"){if(x.indexOf(i)!==-1)return!0}else{let r=[...i.supports||[],...i.extraFeatures||[]];if(r.indexOf("regionByPx")!==-1&&(r.indexOf("sizeByW")!==-1||r.indexOf("sizeByWh")!==-1))return!0}return!1}function Xe(t,e){return h(t,{extraFormats:[e]})}function qe(t,e){if(e.type!=="image")return[!0];let i=[];e.rotation.mirror&&i.push("mirroring"),e.region.percent&&i.push("regionByPct"),e.region.square?i.push("regionSquare"):e.region.full||i.push("regionByPx"),e.rotation.angle&&(e.rotation.angle%90?i.push("rotationArbitrary"):i.push("rotationBy90s")),e.size.confined&&i.push("sizeByConfinedWh"),!e.size.width&&e.size.height&&i.push("sizeByH"),e.size.percentScale&&i.push("sizeByPct"),(t.sizes||[]).find(n=>n.width===e.size.width&&!e.size.height||n.height===e.size.height&&!e.size.width||n.height===e.size.height&&n.width===e.size.width)?i.push("sizeByWhListed"):(e.size.width&&!e.size.height&&i.push("sizeByW"),e.size.width&&e.size.height&&i.push("sizeByWh")),e.size.upscaled&&i.push("sizeUpscaling");let[o,a]=h(t,{extraFeatures:i,extraQualities:[e.quality],extraFormats:[e.format],exactSize:e.size});return o?[!0]:[!1,a]}function W({x:t=0,y:e=0,w:i,h:r,full:o,square:a,percent:n}){if(o)return"full";if(a)return"square";if(typeof i>"u"||typeof r>"u")throw new Error("RegionParameter: invalid region");let f=`${t},${e},${i},${r}`;return n?`pct:${f}`:f}function B({max:t,percentScale:e,upscaled:i,confined:r,width:o,height:a,serialiseAsFull:n}){let f=[];return i&&f.push("^"),t?(f.push(n?"full":"max"),f.join("")):(r&&f.push("!"),e&&f.push(`pct:${e}`),o&&f.push(`${o}`),f.push(","),a&&f.push(`${a}`),f.join(""))}function Q(t){return`${t.mirror?"!":""}${(t.angle||0)%360}`}function H(t,e){let i=t.prefix.startsWith("/")?t.prefix.substr(1):t.prefix,r=`${t.scheme}://${t.server}/${i?`${i}/`:""}${t.identifier}`;if(t.type==="base")return r;if(t.type==="info")return`${r}/info.json`;let{size:o}=t,{region:a,rotation:n,format:f,quality:m}=t;if(e){let s=e["@context"]?Array.isArray(e["@context"])?e["@context"]:[e["@context"]]:[],u=s.indexOf("http://iiif.io/api/image/2/context.json")!==-1,c=s.indexOf("http://iiif.io/api/image/3/context.json")!==-1;if((o.width===e.width&&!o.height||o.height===e.height&&!o.width||o.width===e.width&&o.height===e.height)&&(o={...o,max:!0}),u&&(o.max&&!o.serialiseAsFull&&(o={...o,serialiseAsFull:!0}),!o.max&&o.width&&o.height&&(o={...o,height:void 0})),c&&(o.max&&o.serialiseAsFull&&(o={...o,serialiseAsFull:!1}),o.width&&!o.height&&e.width&&e.height)){let p=e.height/e.width;o={...o,height:Math.ceil(o.width*p)}}}return[r,W(a),B(o),Q(n),`${m}.${f}`].filter(Boolean).join("/")}function mt(t,e){return H({...t,type:"info"},e)}function j(t){return t.endsWith("info.json")?t:t.endsWith("/")?`${t}info.json`:`${t}/info.json`}function ht(t){let e=$(j(t.id));if(e.type!=="info")throw new Error("Invalid service URL");let i=l(t);return{identifier:e.identifier,originalPath:"",server:e.server,prefix:e.prefix,scheme:e.scheme,type:"image",quality:i.extraQualities.indexOf("default")===-1?i.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}}function dt(t,e,i){let r=i.length,o=[];for(let a=0;a<r;a++){let n=i[a];if(!n)continue;let f=n.width;o.push(t/f)}return o}function yt(t,e,i){let r=i.length,o=[];for(let a=0;a<r;a++){let n=i[a];n&&o.push({width:Math.floor(t/n),height:Math.floor(e/n)})}return o}function It(t){if(t["@type"])return t["@type"];if(t.type)return t.type}export{Y as IIIF_1_IMAGE_LEVEL_0,_ as IIIF_1_IMAGE_LEVEL_0_PROFILE,q as IIIF_1_IMAGE_LEVEL_1,ee as IIIF_1_IMAGE_LEVEL_1_PROFILE,te as IIIF_1_IMAGE_LEVEL_2,ie as IIIF_1_IMAGE_LEVEL_2_PROFILE,re as IIIF_2_IMAGE_LEVEL_0,xe as IIIF_2_IMAGE_LEVEL_0_NO_JSON,oe as IIIF_2_IMAGE_LEVEL_0_PROFILE,ae as IIIF_2_IMAGE_LEVEL_1,le as IIIF_2_IMAGE_LEVEL_1_NO_JSON,ne as IIIF_2_IMAGE_LEVEL_1_PROFILE,fe as IIIF_2_IMAGE_LEVEL_2,ge as IIIF_2_IMAGE_LEVEL_2_NO_JSON,se as IIIF_2_IMAGE_LEVEL_2_PROFILE,me as IIIF_3_IMAGE_LEVEL_0,ue as IIIF_3_IMAGE_LEVEL_1,pe as IIIF_3_IMAGE_LEVEL_2,D as STANFORD_IIIF_1_IMAGE_COMPLIANCE_0,G as STANFORD_IIIF_1_IMAGE_COMPLIANCE_1,J as STANFORD_IIIF_1_IMAGE_COMPLIANCE_2,K as STANFORD_IIIF_1_IMAGE_CONFORMANCE_0,V as STANFORD_IIIF_1_IMAGE_CONFORMANCE_1,X as STANFORD_IIIF_1_IMAGE_CONFORMANCE_2,L as STANFORD_IIIF_IMAGE_COMPLIANCE_0,U as STANFORD_IIIF_IMAGE_COMPLIANCE_1,N as STANFORD_IIIF_IMAGE_COMPLIANCE_2,C as STANFORD_IIIF_IMAGE_CONFORMANCE_0,k as STANFORD_IIIF_IMAGE_CONFORMANCE_1,Z as STANFORD_IIIF_IMAGE_CONFORMANCE_2,j as canonicalServiceUrl,l as combineProfiles,ht as createImageServiceRequest,d as extraFeatures,dt as extractFixedSizeScales,yt as fixedSizesFromScales,b as getId,It as getType,y as imageServiceProfiles,mt as imageServiceRequestInfo,H as imageServiceRequestToString,Xe as imageServiceSupportsFormat,qe as imageServiceSupportsRequest,g as isImageService,Qe as isLevel0,I as level0,he as level0Support,w as level1,x as level1Support,F as level2,S as level2Support,O as levelToProfile,z as onlyLevel0,ce as parseImageServerFromId,$ as parseImageServiceRequest,A as parseImageServiceUrl,v as parseRegionParameter,P as parseRotationParameter,R as parseSizeParameter,W as regionParameterToString,Q as rotationParameterToString,B as sizeParameterToString,h as supports,Je as supportsCustomSizes};

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

"use strict";var V=Object.defineProperty;var Qe=Object.getOwnPropertyDescriptor;var Ze=Object.getOwnPropertyNames;var et=Object.prototype.hasOwnProperty;var tt=(e,t,n)=>t in e?V(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var nt=(e,t)=>{for(var n in t)V(e,n,{get:t[n],enumerable:!0})},it=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ze(t))!et.call(e,r)&&r!==n&&V(e,r,{get:()=>t[r],enumerable:!(i=Qe(t,r))||i.enumerable});return e};var rt=e=>it(V({},"__esModule",{value:!0}),e);var m=(e,t,n)=>(tt(e,typeof t!="symbol"?t+"":t,n),n);var on={};nt(on,{EMPTY:()=>s,HAS_PART:()=>u,IS_EXTERNAL:()=>S,PART_OF:()=>A,Traverse:()=>G,UNSET:()=>y,UNWRAP:()=>q,WILDCARD:()=>w,addFlagForExternalResource:()=>Y,compressSpecificResource:()=>x,defaultEntities:()=>Ut,emptyAgent:()=>ae,emptyAnnotation:()=>at,emptyAnnotationPage:()=>ee,emptyCanvas:()=>te,emptyCollection:()=>ne,emptyManifest:()=>ie,emptyRange:()=>re,emptyService:()=>se,frameResource:()=>ve,getDefaultEntities:()=>We,identifyResource:()=>ye,isSpecificResource:()=>h,isWildcard:()=>de,languageString2to3:()=>k,merge:()=>J,mergeEntities:()=>Q,normalize:()=>Jt,resolveIfExists:()=>B,serialize:()=>Qt,serializeConfigPresentation2:()=>rn,serializeConfigPresentation3:()=>an,serializedFieldsToObject:()=>Ke,toRef:()=>H,traverseSpecificResource:()=>Be,types:()=>oe});module.exports=rt(on);function h(e){return typeof e=="string"?!1:!!e&&e.type==="SpecificResource"}function H(e,t){let n=t||"unknown";if(!e)return;if(typeof e=="string")return{id:e,type:n};if(h(e))return H(e.source,t);let i=n&&n!=="unknown"?n:e.type||e["@type"],r=e.id||e["@id"];if(i&&i.indexOf(":")!==-1&&(i=i.split(":").pop()),r&&i)return{id:r,type:i}}var w={},u="iiif-parser:hasPart",A="iiif-parser:partOf",S="iiif-parser:isExternal",y="__$UNSET$__",q="__$UNWRAP$__",s=[];Object.freeze(s);Object.freeze(w);function de(e){if(e===w||Object.keys(e).length===0)return!0;for(let t in e)return!1;return!0}function ve(e,t){if(t&&t["@explicit"]){let n={},i=Object.keys(t);for(let r of i)r===A||r==="@explicit"||(de(t[r])?n[r]=e[r]:n[r]=t[r]);return n}return e}function B(e,t,n){let i=H(t);if(!i)return[void 0,void 0];let r=e.requests[i.id],a=i.type||e.mapping[i.id];if(!a||r&&r.resourceUri&&(!e.entities[a]||!e.entities[a][r.resourceUri]))return[void 0,void 0];let o=e.entities[a][r?r.resourceUri:i.id];if(i.type&&!o)return B(e,{id:i.id},n);if(o&&o[u]){let c=o[u].find(l=>n?l[A]===n.id:l[A]===o.id);return[ve(o,c),o]}return[o,o]}var at={id:"https://iiif-parser/annotation",type:"Annotation",behavior:s,label:null,thumbnail:s,summary:null,requiredStatement:null,metadata:s,seeAlso:s,homepage:s,rendering:s,service:s,accessibility:s,audience:s,body:s,bodyValue:null,canonical:null,created:null,creator:s,generated:null,generator:s,modified:null,motivation:s,rights:null,stylesheet:null,target:s,timeMode:void 0,via:s,partOf:s},ee={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:s,label:null,thumbnail:s,summary:null,requiredStatement:null,metadata:s,rights:null,provider:s,items:s,seeAlso:s,homepage:s,rendering:s,service:s},te={id:"https://iiif-parser/empty-canvas",type:"Canvas",label:null,behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,duration:0,height:0,width:0},ne={id:"https://iiif-parser/empty-collection",type:"Collection",label:null,viewingDirection:"left-to-right",behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,services:s},ie={id:"https://iiif-parser/empty-manifest",type:"Manifest",annotations:s,behavior:s,homepage:s,items:s,label:null,metadata:s,navDate:null,provider:s,partOf:s,accompanyingCanvas:null,placeholderCanvas:null,rendering:s,requiredStatement:null,rights:null,seeAlso:s,service:s,services:s,start:null,structures:s,summary:null,thumbnail:s,viewingDirection:"left-to-right"},re={id:"https://iiif-parser/empty-canvas",type:"Range",label:null,behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,start:null,supplementary:null,viewingDirection:"left-to-right"},ae={id:"https://iiif-parser/empty-agent",type:"Agent",label:{},logo:s,seeAlso:s,homepage:s},se={id:"https://iiif-parser/empty-service",type:"UnknownService"};function P(e){return Array.isArray(e)?e:e?[e]:[]}function U(...e){return t=>e.reduce((n,i)=>i(n),t)}var oe=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function ye(e,t){if(typeof e>"u"||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"){if(t)return t;throw new Error(`${typeof e} is not a valid entity`)}if(typeof e.type=="string"){let n=oe.indexOf(e.type);if(n!==-1)return oe[n]}if(e.profile)return"Service";throw new Error("Resource type is not known")}var G=class e{constructor(t,n={}){m(this,"traversals");m(this,"options");m(this,"_traverseManifest",U(this.traverseManifestItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseManifestStructures.bind(this),this.traverseInlineAnnotationPages.bind(this)));m(this,"_traverseCanvas",U(this.traverseCanvasItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseInlineAnnotationPages.bind(this)));m(this,"_traverseAnnotationPage",U(this.traverseAnnotationPageItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this)));m(this,"_traverseRange",U(this.traverseRangeRanges.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this)));this.traversals={collection:[],manifest:[],canvas:[],annotationCollection:[],annotationPage:[],annotation:[],contentResource:[],choice:[],range:[],service:[],agent:[],specificResource:[],geoJson:[],...t},this.options={allowUndefinedReturn:!1,...n}}static all(t){return new e({collection:[t],manifest:[t],canvas:[t],annotationCollection:[t],annotationPage:[t],annotation:[t],contentResource:[t],choice:[t],range:[t],service:[t],geoJson:[t],specificResource:[t],agent:[t]})}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=P(t.thumbnail).map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.provider&&(t.provider=t.provider.map(n=>this.traverseAgent(n,t))),t}traverseLinking(t){return t.seeAlso&&(t.seeAlso=t.seeAlso.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.service&&(t.service=P(t.service).map(n=>this.traverseService(n))),t.services&&(t.services=P(t.services).map(n=>this.traverseService(n,t))),t.logo&&(t.logo=t.logo.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.homepage&&(t.homepage=t.homepage.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.partOf&&(t.partOf=t.partOf.map(n=>typeof n=="string"||!n.type?this.traverseType(n,{parent:t},this.traversals.contentResource):n.type==="Canvas"?this.traverseType(n,{parent:t},this.traversals.canvas):n.type==="AnnotationCollection"?this.traverseType(n,{parent:t},this.traversals.annotationCollection):n.type==="Collection"?this.traverseType(n,{parent:t},this.traversals.collection):this.traverseType(n,{parent:t},this.traversals.contentResource))),t.start&&(h(t.start)?t.start=this.traverseSpecificResource(t.start,"Canvas",t):t.start=this.traverseType(t.start,{parent:t},this.traversals.canvas)),t.rendering&&(t.rendering=t.rendering.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.supplementary&&(t.supplementary=t.supplementary.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t}traverseCollectionItems(t){return t.items&&t.items.map(n=>n.type==="Collection"?this.traverseCollection(n):this.traverseManifest(n)),t}traverseCollection(t,n){return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traverseLinkedCanvases(this.traverseCollectionItems(t))))),{parent:n},this.traversals.collection)}traverseGeoJson(t,n){return this.traverseType(t,{parent:n},this.traversals.geoJson)}traverseNavPlace(t){return t.navPlace&&(t.navPlace=this.traverseGeoJson(t.navPlace,t)),t}traverseManifestItems(t){return t.items&&(t.items=t.items.map(n=>this.traverseCanvas(n))),t}traverseManifestStructures(t){return t.structures&&(t.structures=t.structures.map(n=>this.traverseRange(n))),t}traverseManifest(t,n){return this.traverseType(this._traverseManifest(t),{parent:n},this.traversals.manifest)}traverseCanvasItems(t){return t.items=(t.items||[]).map(n=>this.traverseAnnotationPage(n,t)),t}traverseInlineAnnotationPages(t){return typeof t=="string"||!t||t.annotations&&(t.annotations=t.annotations.map(n=>this.traverseAnnotationPage(n,t))),t}traverseCanvas(t,n){return this.traverseType(this._traverseCanvas(t),{parent:n},this.traversals.canvas)}traverseAnnotationPageItems(t){return t.items&&(t.items=t.items.map(n=>this.traverseAnnotation(n,t))),t}traverseAnnotationPage(t,n){return this.traverseType(this._traverseAnnotationPage(t),{parent:n},this.traversals.annotationPage)}traverseAnnotationBody(t){return Array.isArray(t.body)?t.body=t.body.map(n=>this.traverseContentResource(n,t)):t.body&&(t.body=this.traverseContentResource(t.body,t)),t}traverseLinkedCanvases(t){return t.placeholderCanvas&&(t.placeholderCanvas=this.traverseCanvas(t.placeholderCanvas)),t.accompanyingCanvas&&(t.accompanyingCanvas=this.traverseCanvas(t.accompanyingCanvas)),t}traverseAnnotation(t,n){return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(this.traverseDescriptive(t))),{parent:n},this.traversals.annotation)}traverseContentResourceLinking(t){return typeof t=="string"||!t||t&&t.service&&(t.service=P(t.service||[]).map(n=>this.traverseService(n,t))),t}traverseContentResource(t,n){return t.type==="Choice"&&(t.items=t.items.map(i=>this.traverseContentResource(i,t))),h(t)?this.traverseSpecificResource(t,"ContentResource"):this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(t)),{parent:n},this.traversals.contentResource)}traverseSpecificResource(t,n,i){let r=t.source;return typeof t.source=="string"&&(r={id:t.source,type:n||"unknown"}),this.traverseType({...t,source:n==="Canvas"||r.type==="Canvas"?this.traverseType(r,{parent:i},this.traversals.canvas):n==="ContentResource"?this.traverseContentResource(r,{parent:i}):this.traverseUnknown(r,{parent:i,typeHint:n})},{parent:i},this.traversals.specificResource)}traverseRangeRanges(t){return t.items&&(t.items=t.items.map(n=>typeof n=="string"?this.traverseCanvas({id:n,type:"Canvas"},t):h(n)?this.traverseSpecificResource(n,"Canvas",t):n.type==="Manifest"?this.traverseManifest(n,t):this.traverseRange(n,t))),t}traverseRange(t,n){return this.traverseType(this._traverseRange(t),{parent:n},this.traversals.range)}traverseAgent(t,n){return this.traverseType(this.traverseDescriptive(this.traverseLinking(t)),{parent:n},this.traversals.agent)}traverseType(t,n,i){return i.reduce((r,a)=>{let o=a(r,n);return typeof o>"u"&&!this.options.allowUndefinedReturn?r:o},t)}traverseService(t,n){let i=Object.assign({},t);return i&&i.service&&(i.service=P(i.service).map(r=>this.traverseService(r))),this.traverseType(i,{parent:n},this.traversals.service)}traverseUnknown(t,{parent:n,typeHint:i}={}){let r=ye(t,i);switch(r){case"Collection":return this.traverseCollection(t,n);case"Manifest":return this.traverseManifest(t,n);case"Canvas":return this.traverseCanvas(t,n);case"AnnotationPage":return this.traverseAnnotationPage(t,n);case"Annotation":return this.traverseAnnotation(t,n);case"ContentResource":return this.traverseContentResource(t,n);case"Range":return this.traverseRange(t,n);case"Service":return this.traverseService(t,n);case"Agent":return this.traverseAgent(t,n);default:throw new Error(`Unknown or unsupported resource type of ${r}`)}}};var he=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function st(e){if(typeof e>"u"||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"){let t=he.indexOf(e["@type"]);if(t!==-1)return he[t]}if(e.profile)return"Service";if(e.format||e["@type"])return"ContentResource";throw new Error("Resource type is not known")}var K=class e{constructor(t,n={}){m(this,"traversals");m(this,"options");this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...t},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...n}}static all(t){return new e({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){let n=[...(t.manifests||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i),...(t.collections||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i),...t.members||[]];delete t.collections,delete t.manifests,t.members=n}return t.manifests&&(t.manifests=t.manifests.map(n=>this.traverseManifest(typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n))),t.collections&&(t.collections=t.collections.map(n=>this.traverseCollection(typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n))),t.members&&(t.members=t.members.map(n=>typeof n=="string"?n:this.traverseUnknown(n))),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(n=>this.traverseSequence(n))),t.structures&&(t.structures=t.structures.map(n=>this.traverseRange(n))),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(n=>this.traverseCanvas(n))),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(n=>this.traverseAnnotation(n))),t.otherContent&&(t.otherContent=t.otherContent.map(n=>this.traverseAnnotationList(n))),t}traverseRange(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(t))),this.traversals.range)}traverseRangeItems(t){if(this.options.mergeMemberProperties){let n=[...(t.ranges||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Range"}:i),...(t.canvases||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Canvas"}:i),...t.members||[]];delete t.ranges,delete t.canvases,t.members=n.length?n.map(i=>this.traverseUnknown(i)):void 0}return t}traverseAnnotationList(t){let n=typeof t=="string"?{"@id":t,"@type":"sc:AnnotationList"}:t;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(n)),this.traversals.annotationList)}traverseAnnotationListItems(t){return t.resources&&(t.resources=t.resources.map(n=>this.traverseAnnotation(n))),t}traverseAnnotation(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(t))),this.traversals.annotation)}traverseAnnotationItems(t){return t.resource&&(Array.isArray(t.resource)?t.resource=t.resource.map(n=>this.traverseContentResource(n)):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(n=>this.traverseAnnotationList(n))),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(n=>this.traverseContentResource(n))),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(st(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"sc: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){let n=Array.isArray(t),i=Array.isArray(t)?t:[t],r=[];for(let a of i)typeof a=="string"?r.push(this.traverseContentResource({"@id":a,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(a));return!n&&!this.options.convertPropsToArray?r[0]:r}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=this.traverseImageResource(t.thumbnail)),t.logo&&(t.logo=this.traverseImageResource(t.logo)),t}traverseOneOrMoreServices(t){let n=Array.isArray(t),i=Array.isArray(t)?t:[t],r=[];for(let a of i)r.push(this.traverseService(a));return!n&&!this.options.convertPropsToArray?r[0]:r}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,n){if(!Array.isArray(t))if(this.options.convertPropsToArray)t=[t];else return this.traverseType(t,n);return t.map(i=>this.traverseType(i,n))}traverseType(t,n){return n.reduce((i,r)=>{let a=r(i);return typeof a>"u"&&!this.options.allowUndefinedReturn?i:a},t)}};var ot="http://library.stanford.edu/iiif/image-api/compliance.html#level0",me="http://library.stanford.edu/iiif/image-api/compliance.html#level1",ge="http://library.stanford.edu/iiif/image-api/compliance.html#level2",ct="http://library.stanford.edu/iiif/image-api/conformance.html#level0",Ce="http://library.stanford.edu/iiif/image-api/conformance.html#level1",Ae="http://library.stanford.edu/iiif/image-api/conformance.html#level2",lt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Re="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Te="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",pt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Se="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Pe="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",ft="http://iiif.io/api/image/1/level0.json",ut="http://iiif.io/api/image/1/profiles/level0.json",Ie="http://iiif.io/api/image/1/level1.json",xe="http://iiif.io/api/image/1/profiles/level1.json",be="http://iiif.io/api/image/1/level2.json",_e="http://iiif.io/api/image/1/profiles/level2.json",dt="http://iiif.io/api/image/2/level0.json",vt="http://iiif.io/api/image/2/profiles/level0.json",Ee="http://iiif.io/api/image/2/level1.json",Me="http://iiif.io/api/image/2/profiles/level1.json",Le="http://iiif.io/api/image/2/level2.json",we="http://iiif.io/api/image/2/profiles/level2.json",yt="level0",Ne="level1",Oe="level2",ht="http://iiif.io/api/image/2/level0",ze="http://iiif.io/api/image/2/level1",ke="http://iiif.io/api/image/2/level2",Fe=[ze,ke,me,ge,Ce,Ae,Re,Te,Se,Pe,Ie,xe,be,_e,Ee,Me,Le,we,Ne,Oe],De=[ht,ze,ke,ot,me,ge,ct,Ce,Ae,lt,Re,Te,pt,Se,Pe,ft,ut,Ie,xe,be,_e,dt,vt,Ee,Me,Le,we,yt,Ne,Oe];function g(e){for(let t in e)(typeof e[t]>"u"||e[t]===null)&&delete e[t];return e}var ce={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function mt(e){if(typeof e=="string")return[e];if(!e)return[];let t=Array.isArray(e)?e:[e],n=[];for(let i of t){if(typeof i=="string"){n.push(i);continue}n.push({"@language":i["@language"]||i.language,"@value":i["@value"]||i.value})}return n}function N(e,t="none"){if(!e)return{};let n=mt(e),i={};for(let r of n){if(typeof r=="string"){i[t]=i[t]?i[t]:[],i[t].push(r||"");continue}if(!r["@language"]){i[t]=i[t]?i[t]:[],i[t].push(r["@value"]||"");continue}let a=r["@language"];i[a]=i[a]?i[a]:[],i[a].push(r["@value"]||"")}return i}function Ue(e){if(Array.isArray(e))return Ue(e.find(t=>typeof t=="string"));if(De.indexOf(e)!==-1)return"level2";if(Fe.indexOf(e)!==-1)return"level1";if(typeof e=="string")return e}function gt(e){let t=Array.isArray(e)?e:[e];for(let n of t)switch(n){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 Ct(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 je(e){for(let t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}var At=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function fe(e){let t=e["@id"]||e.id,n=e["@type"]||e.type,i=e.profile||void 0,r=e["@context"]||void 0;if(i){let a=Ct(i);if(a)return a}if(r){let a=gt(r);if(a)return a}if(n){if(Array.isArray(n)){if(n.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(n.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";n=n[0]}for(let a of["sc","oa","dcterms","dctypes","iiif"])if(n.startsWith(`${a}:`)){n=n.slice(a.length+1);break}switch(n){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(n&&At.indexOf(n)!==-1)return n;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":n||"unknown"}var Rt=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Tt(e){let t=e.match(Rt);return t?t[0]:e}function St(e,t="Rights/License",n="none"){let i=null,r=[],a=Array.isArray(e)?e:[e];for(let o of a){let c=o?Tt(o):void 0;if(c&&(c.indexOf("creativecommons.org")!==-1||c.indexOf("rightsstatements.org")!==-1)){c.startsWith("https://")?i=`http://${c.slice(8)}`:i=c;continue}c&&r.push({label:{[n]:[t]},value:{[n]:[c]}})}return[i,r]}var 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 It(e){if(e){let t=Array.isArray(e)?e:[e],n=[];for(let i of t)i==="http://iiif.io/api/presentation/2/context.json"&&n.push("http://iiif.io/api/presentation/3/context.json"),Pt.indexOf(i)===-1&&n.push(i);if(t.length)return n.length===1?n[0]:n}}function xt(e){return e?e.map(t=>({label:N(t.label),value:N(t.value)})):[]}var qe=0;function Ge(e,t){let n=encodeURI(e.id||e["@id"]||"").trim();return n&&t?`${n}/${t}`:n||(qe++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${qe}`)}function R(e){let t=[...e.behavior||[]];e.viewingHint&&t.push(e.viewingHint);let n;return Array.isArray(e.motivation)?n=e.motivation.map(je):e.motivation&&(n=je(e.motivation)),{"@context":e["@context"]?It(e["@context"]):void 0,id:(e["@id"]||Ge(e)).trim(),type:fe(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:n,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function T(e){let[t,n]=St(e.license),i=[...e.metadata?xt(e.metadata):[],...n];return{rights:t,metadata:i.length?i:void 0,label:e.label?N(e.label):void 0,requiredStatement:e.attribution?{label:N(ce.attributionLabel),value:N(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?N(e.description):void 0,thumbnail:bt(e.thumbnail)}}function bt(e){return e&&(Array.isArray(e)?e:[e]).map(n=>typeof n=="string"?{id:n,type:"Image"}:(n.type==="unknown"&&(n.type="Image"),n))}function _t(e){if(!e.within)return;let t=Array.isArray(e.within)?e.within:[e.within],n=[];for(let i of t)if(typeof i=="string"){if(i)switch(e["@type"]){case"sc:Manifest":n.push({id:i,type:"Collection"});break}}else i["@id"]&&n.push({id:i["@id"],type:fe(i)});return n.length?n:void 0}function I(e){let t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],n=e.contentLayer;return{provider:e.logo||t.length?[{id:ce.providerId,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:N(ce.providerName)}]:void 0,partOf:_t(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?P(e.service):void 0,supplementary:n?[n]:void 0}}function Et(e){return{chars:e.chars,format:e.format?e.format:void 0,language:e.language}}function Mt(e){return g({...R(e),...T(e),...I(e),items:e.members})}function Lt(e){let t=[],n=[],i;for(let a of e.sequences||[])a.canvases.length&&t.push(...a.canvases),a.behavior&&n.push(...a.behavior),a.startCanvas&&(i=a.startCanvas);let r=R(e);return n.length&&(r.behavior?r.behavior.push(...n):r.behavior=n),g({...r,...T(e),...I(e),start:i,items:t,structures:e.structures})}function wt(e){return g({...R(e),...T(e),...I(e),annotations:e.otherContent&&e.otherContent.length?e.otherContent:void 0,items:e.images&&e.images.length?[{id:Ge(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}function Nt(e){return g({...R(e),...T(e),...I(e),items:e.resources&&e.resources.length?e.resources:void 0})}function Ot(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}}function zt(e){function t(n){if(Array.isArray(n)){if(n.length>1)return{type:"List",items:n.map(t)};n=n[0]}if(typeof n=="string")return encodeURI(n).trim();if("@type"in n){let i;if(typeof n.full=="string")i=n.full;else if(n.full["@type"]==="dctypes:Image")i={id:n.full["@id"],type:"Image"};else if(n.full["@type"]==="sc:Canvas")i={id:n.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${n.full["@type"]}`);return{type:"SpecificResource",source:i,selector:pe(n.selector)}}else return encodeURI(n["@id"]).trim()}return g({...R(e),...T(e),...I(e),target:t(e.on),body:Array.isArray(e.resource)?e.resource.map(le):le(e.resource)})}function le(e){let t=e;return g({...R(t),...T(t),...I(t),...Et(t)})}function kt(e){let t=[];return e.default&&e.default!=="rdf:nil"&&t.push(e.default),e.item&&e.item!=="rdf:nil"&&t.push(...e.item),{...R(e),...T(e),items:t}}function Ft(e){return g({...R(e),...T(e),...I(e),items:e.members})}function Dt(e){let{"@id":t,"@type":n,"@context":i,profile:r,...a}=e,o={};return t&&(o["@id"]=t),o["@type"]=fe(e),o["@type"]==="unknown"&&(i&&i.length&&(o["@context"]=i),o["@type"]="Service"),r&&(o.profile=Ue(r)),g({...o,...a})}function jt(e){return g({...R(e),...T(e),...I(e)})}var qt=new K({collection:[Mt],manifest:[Lt],canvas:[wt],annotationList:[Nt],sequence:[Ot],annotation:[zt],contentResource:[le],choice:[kt],range:[Ft],service:[Dt],layer:[jt]});function $e(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"?qt.traverseUnknown(e):e}function pe(e){if((Array.isArray(e["@type"])&&e["@type"].includes("oa:SvgSelector")||e["@type"]=="oa:SvgSelector")&&("chars"in e||"value"in e))return{type:"SvgSelector",value:"chars"in e?e.chars:e.value};if(e["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:e.value};if(e["@type"]==="oa:Choice")return[pe(e.default),...(Array.isArray(e.item)?e.item:[e.item]).map(pe)];if(e["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in e?e.region:void 0,rotation:"rotation"in e?e.rotation:void 0};throw new Error(`Unsupported selector type: ${e["@type"]}`)}function X(e,t={}){if(Array.isArray(e))return X(e[0]);if(typeof e=="string"){let[n,i]=e.split("#");return i?{type:"SpecificResource",source:{id:n,type:t.typeHint||"Unknown"},selector:{type:"FragmentSelector",value:i}}:{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||t.typeHint||"Unknown"}}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return X(e.items[0]);if(e.type==="SpecificResource")return e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]),e.selector?{type:"SpecificResource",source:e.source,selector:e.selector}:{type:"SpecificResource",source:e.source};if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);let[n,i]=e.id.split("#");return i?{type:"SpecificResource",source:{...e,id:n},selector:{type:"FragmentSelector",value:i}}:{type:"SpecificResource",source:{...e,id:n}}}return{type:"SpecificResource",source:e}}var Ut={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}};function We(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}function Ve(e,t){if(typeof e=="string")return{id:e,type:t};if(!e.id)throw new Error(`Invalid resource does not have an ID (${JSON.stringify(e)}, ${t})`);return e}function Gt(e,t){return(n,i)=>{let r=e[n]?e[n]:{};return(a,o)=>{let c=Ve(a,i||n);return c&&c.id&&n?(r[c.id]=r[c.id]?Q(r[c.id],c,{parent:o.parent,isTopLevel:t.id===c.id}):Q({id:c.id,type:c.type},c,{parent:o.parent,isTopLevel:t.id===c.id}),{id:c.id,type:n==="ContentResource"?n:c.type}):c}}}function J(e,t,n){if(!t)return e;if(Array.isArray(e)){if(!Array.isArray(t))throw new Error("Cannot merge array with non-array");let i=[...e];for(let r of t)if(r["@id"]&&!r.id&&(r.id=r["@id"]),r["@type"]&&!r.type&&(r.type=r["@type"]),r!=null)if(Array.isArray(r))i.push(r);else if(typeof r=="object"&&r.id&&r.type){let a=i.findIndex(o=>o.id===r.id&&o.type===r.type);a>=0&&(i[a]=J(i[a],r))}else e.indexOf(r)===-1&&i.push(r);return i}else if(typeof e=="object"){if(Array.isArray(t)||typeof t!="object")throw new Error("Cannot merge object with non-object");let i={...e},r=[],a=[],o=Object.keys(e).filter(l=>l!==u&&l!=="id"&&l!=="type"),c={},M={};for(let[l,f]of Object.entries(t)){if(l===u||l==="id"||l==="type")continue;let v=i[l];v===f?a.push(l):v===s||!v?(r.push(l),i[l]=f):(v&&f&&(c[l]=v,M[l]=f),i[l]=J(v,f),i[l]===c[l]&&(a.push(l),delete c[l]))}if(n&&(n.parent&&n.parent.id||n.isTopLevel)){let l=[],f={};if(n.parent?f[A]=n.parent.id:n.isTopLevel&&(f[A]=e.id),i[u]&&i[u].length){let v=!(i[u]||[]).find(C=>C["@explicit"]),L=r.length>0||a.length!==o.length;if(v&&L)for(let C of i[u]){let d={...C},Z=Object.keys(c);if(d){d["@explicit"]=!0;for(let j of o)j!==u&&(d[j]=w);for(let j of Z)d[j]=c[j]}l.push(d)}else l.push(...i[u]);if(L){let C=Object.keys(M);f["@explicit"]=!0;for(let d of r)f[d]=w;for(let d of a)f[d]=w;for(let d of C)f[d]=M[d]}}f.id=i.id,f.type=i.type,l.push(f),i[u]=l}return i}else if(e)return e;return t}function Q(e,t,n){if(typeof e=="string")return e;if(t.id!==e.id||t.type!==e.type){if(t.type==="ImageService3")return t;if(e.type==="ImageService3")return e;throw new Error(`Can only merge entities with identical identifiers and type! ${t.type}(${t.id}) => ${e.type}(${e.id})`)}return J({...e},t,n)}function $t(e){return(t,n)=>i=>{let{id:r,type:a}=Ve(i,n||t);if(typeof r>"u")throw new Error("Found invalid entity without an ID.");return t==="ContentResource"||t==="Service"?e[r]=t:e[r]=a,i}}function Wt(e){let t=Object.assign({},e);if(t["@id"]&&(t.id=t["@id"]),t["@type"]&&(t.type=t["@type"]),t.service){let n=[];t.service=Array.isArray(t.service)?t.service:[t.service];for(let i of t.service)n.push({id:i["@id"]||i.id,type:i["@type"]||i.type});t.service=n}return Object.assign({},se,t)}function Vt(e){return t=>{e.Service=e.Service?e.Service:{};let n=t.id||t["@id"],i=Wt(t);return i&&i.id&&(e.Service[i.id]?e.Service[n]=Q(e.Service[n],i):e.Service[n]=i),t}}function Ht(e){let t=JSON.stringify(e),n=5381,i=t.length;for(;i;)n=n*33^t.charCodeAt(--i);let a=(n>>>0).toString(16);return a.length%2?"0"+a:a}function ue(e){return t=>typeof t=="string"?{id:t,type:e}:t.id?t.type?t:{type:e,...t}:{id:`vault://${Ht(t)}`,type:e,...t}}function D(e){return t=>({...e,...t})}function $(e){return Array.isArray(e)?e:[e]}function Bt(e){return e.body&&(e.body=$(e.body)),e.seeAlso&&(e.seeAlso=$(e.seeAlso)),e.audience&&(e.audience=$(e.audience)),e.accessibility&&(e.accessibility=$(e.accessibility)),e.motivation&&(e.motivation=$(e.motivation)),e}function He(e,{typeHint:t,partOfTypeHint:n}={}){if(typeof e=="string"&&(e={id:e,type:t||"unknown"}),h(e))return typeof e.source=="string"&&(e.source={id:e.source,type:t||"unknown"}),e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:n||"Manifest"}]),e;let i;if((e.id||"").indexOf("#")!==-1){let[r,a]=(e.id||"").split("#");e.id=r,a&&(i={type:"FragmentSelector",value:a})}return{type:"SpecificResource",source:e,selector:i}}function Kt(e){let t=Object.assign({},e);return e&&e.items&&(t.items=e.items.map(n=>typeof n=="string"||n.type==="Canvas"?He(n):n)),t}function Xt(e){let t=Object.assign({},e);return t.start?(t.start=He(t.start,{typeHint:"Canvas"}),t):e}function Yt(e){let t=Object.assign({},e);return t.target?(t.target=X(t.target,{typeHint:"Canvas"}),t):e}function Be(e){return e}function Y(e){return typeof e.items>"u"&&(e[S]=!0),e}function Jt(e){let t=$e(e),n=We(),i={},r=Gt(n,t),a=$t(i),c=new G({collection:[Y,D(ne),a("Collection"),r("Collection")],manifest:[Y,D(ie),Xt,a("Manifest"),r("Manifest")],canvas:[D(te),a("Canvas"),r("Canvas")],annotationPage:[Y,ue("AnnotationPage"),D(ee),a("AnnotationPage"),r("AnnotationPage")],annotation:[ue("Annotation"),Bt,Yt,a("Annotation"),r("Annotation")],contentResource:[ue("ContentResource"),a("ContentResource"),r("ContentResource")],range:[D(re),Kt,a("Range","Canvas"),r("Range","Canvas")],agent:[D(ae),a("Agent"),r("Agent")],specificResource:[Be],service:[Vt(n)]}).traverseUnknown(t);return{entities:n,resource:c,mapping:i}}function Ke(e){let t={};for(let[n,i]of e){if(n===q&&i!==y)return i;i!==y&&typeof i<"u"&&i!==null&&(t[n]=i)}return t}function Qt(e,t,n){if(!t.type||!t.id)throw new Error("Unknown entity");if(!n[t.type])throw new Error(`Serializer not found for ${t.type}`);function i(r,a,o=0){let c=n[r.type];if(!c)return y;if(o>20)throw new Error("Circular reference: "+r.id+" "+r.type);let[M,l]=B(e,r.type?r:r.id,a)||(r.id&&r.type?r:null);if(!M)return y;let f=c(M,e,{parent:a,isTopLevel:t.id===r.id,fullResource:l}),v=f.next();for(;!v.done;){let L=v.value,C=y;if(L)if(Array.isArray(L)){let d=[];for(let Z of L)d.push(i(Z,r,o+1));C=d}else C=i(L,r,o+1);v=f.next(C)}return v.value===y?y:Ke(v.value)}return i(t)}function x(e,{allowSourceString:t=!0,allowString:n=!1,allowedStringType:i}={}){let r=a=>{if(t&&a&&a.source&&typeof a.source!="string"){let o=Object.keys(a.source);if(a.source.id&&a.source.type&&o.length===2)return{...a,source:a.source.id}}return a};if(e){if(e.source&&e.source.partOf)return r(e);let a=Object.keys(e);if(a.length===2&&e.type&&e.source||a.length===3&&e.type&&e.source&&a.indexOf("selector")!==-1&&!e.selector)return n&&(!i||i===e.source.type)?e.source.id:e.source.type==="ContentResource"?{type:"SpecificResource",source:e.source.id}:e.source;if(e.selector&&!Array.isArray(e.selector)&&typeof e.selector!="string"&&e.selector.type==="FragmentSelector"){let o=`${e.source.id}#${e.selector.value}`;return n?o:{id:o,type:e.source.type}}}return r(e)}function k(e){if(!e)return;let t=Object.keys(e);if(t.length!==0){if(t.length===1){let n=t[0];if(!n)return"";let i=(e[n]||[]).join("");return n==="@none"||n==="none"||n==="en"?i:{"@language":n,"@value":i}}return t.map(n=>({"@language":n,"@value":(e[n]||[]).join("")}))}}function Xe(e){return Array.isArray(e)?e.map(t=>Xe(t)):typeof e=="string"?e:e.type&&e.type==="Canvas"?e.id:e}function b(e,t=!1){if(e)return e.length>1&&!t?e:e[0]||void 0}function Zt(e){if(e){if(typeof e=="string")return{"@id":e};if("@id"in e){let t={...e};return delete t["@type"],t}return{"@context":"http://iiif.io/api/image/2/context.json","@id":e.id,profile:`http://iiif.io/api/image/2/profiles/${e.profile}.json`}}}function O(e,t){return[["@id",e.id],["@type",t],["format",e.format],["height",e.height],["width",e.width],["viewingDirection",e.viewingDirection!=="left-to-right"?e.viewingDirection:void 0],["license",e.license?e.license:void 0]]}function*z(e){let t=e.provider?yield e.provider[0]:void 0;return[["label",k(e.label)],["metadata",e.metadata&&e.metadata.length?e.metadata.map(n=>({label:k(n.label)||"",value:k(n.value)||""})):void 0],["description",k(e.summary)],["thumbnail",b(yield e.thumbnail)],["navDate",e.navDate],["logo",t?b(t.logo):void 0],["homepage",t?t.homepage:void 0],["attribution",e.requiredStatement?k(e.requiredStatement.value):void 0]]}function*W(e){let t=e.start&&e.start.type&&e.start.type==="SpecificResource"?x(e.start):e.start;return[["seeAlso",b(yield e.seeAlso)],["service",b((e.service||[]).map(Zt))],["rendering",b(yield e.rendering)],["startCanvas",t?t.id:void 0]]}function en(e){return e.type==="SpecificResource"}function tn(e){return e&&e.type==="FragmentSelector"}function nn(e){if(e&&en(e)){let t=e.id,n=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return tn(n)&&(t+="#"+n.value),t}return e?.id}var rn={Manifest:function*(e,t,{isTopLevel:n}){return[...n?[["@context","http://iiif.io/api/presentation/2/context.json"]]:[],...O(e,"sc:Manifest"),...yield*z(e),...yield*W(e),["sequences",[{"@id":`${e.id}/sequence0`,"@type":"sc:Sequence",canvases:yield e.items}]],["structures",yield e.structures]]},Canvas:function*(e){let n=(yield e.items)[0];return[...O(e,"sc:Canvas"),...yield*z(e),...yield*W(e),["images",n?[n.resources]:void 0],["annotations",e.annotations&&e.annotations.length?b(yield e.annotations):void 0]]},AnnotationPage:function*(e){return[...O(e,"sc:AnnotationList"),...yield*z(e),["resources",e.items&&e.items.length?b(yield e.items):void 0]]},Annotation:function*(e){return[["@id",e.id],["@type","oa:Annotation"],["motivation","sc:painting"],["on",Xe(e.target)],["resource",b(yield e.body,!0)]]},ContentResource:function*(e){switch(e.type){case"Image":return[...O(e,"dctypes:Image"),...yield*z(e),...yield*W(e)];case"Text":case"Dataset":default:return[...O(e,void 0),...yield*z(e)]}},AnnotationCollection:function*(e){return[["@id",e.id],["@type","sc:Layer"],["label",k(e.label)]]},Collection:function*(e){return[...O(e,"sc:Collection"),...yield*z(e),...yield*W(e),["members",yield*e.items]]},Range:function*(e){let t=[],n=[];if(e.items)for(let i of e.items){let r=i.type==="SpecificResource"?i.source:i;if(r){let a=yield r;t.push({"@id":nn(i),"@type":r.type,label:a?a.label:void 0,within:e.id}),r.type==="Canvas"&&n.push(r.id)}}return[...O(e,"sc:Range"),...yield*z(e),...yield*W(e),["canvases",n.length===t.length?n:void 0],["members",n.length!==t.length?t:void 0]]}};function F(e){return[["id",e.id?.startsWith("vault://")?void 0:e.id],["type",e.type],["format",e.format],["profile",e.profile],["height",e.height||void 0],["width",e.width||void 0],["duration",e.duration||void 0],["viewingDirection",e.viewingDirection!=="left-to-right"?e.viewingDirection:void 0],["behavior",e.behavior&&e.behavior.length?e.behavior:void 0],["timeMode",e.timeMode],["motivation",Array.isArray(e.motivation)?e.motivation[0]:e.motivation],[u,y]]}function p(e){if(e===y||!e||e.length===0)return;let t=e.filter(n=>n!==y);if(t.length!==0)return t}function Je(e){if(e&&e.type&&e.type==="ImageService2"){let{id:t,type:n,profile:i,...r}=e,a=typeof i=="string"?i:Array.isArray(i)?i.find(o=>typeof o=="string"):"";return{"@id":t,"@type":n,profile:a?a.startsWith("http")?a:`http://iiif.io/api/image/2/${a}.json`:"http://iiif.io/api/image/2/level0.json",...r}}return e}function Ye(e){if(Array.isArray(e)||(e=e?[e]:[]),!(!e||e.length===0))return e.map(Je)}function*_(e){return[["label",e.label],["metadata",p(e.metadata)],["summary",e.summary],["requiredStatement",e.requiredStatement],["rights",Array.isArray(e.rights)?e.rights[0]||void 0:e.rights||void 0],["navDate",e.navDate],["language",e.language],["thumbnail",p(yield e.thumbnail)],["placeholderCanvas",yield e.placeholderCanvas],["accompanyingCanvas",yield e.accompanyingCanvas],["provider",p(yield e.provider)]]}function*E(e){return[["seeAlso",p(yield e.seeAlso)],["service",p(Ye(e.service))],["services",p(Ye(e.services))],["rendering",p(yield e.rendering)],["supplementary",p(yield e.supplementary)],["homepage",p(yield e.homepage)],["logo",p(yield e.logo)],["partOf",p(yield e.partOf)],["start",e.start?x(e.start):e.start]]}var an={Manifest:function*(e,t,{isTopLevel:n}){return n?[["@context",e["@context"]?e["@context"]:"http://iiif.io/api/presentation/3/context.json"],...F(e),...yield*_(e),...yield*E(e),["items",yield e.items],["structures",p(yield e.structures)],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]:[...F(e),...yield*_(e)]},Canvas:function*(e){return[...F(e),...yield*_(e),...yield*E(e),["items",yield e.items],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]},Agent:function*(e){return[["id",e.id],["type","Agent"],["label",e.label],...yield*E(e)]},AnnotationPage:function*(e){let t=Object.entries(e).map(([i,r])=>[i,Array.isArray(r)?p(r):r]).filter(([i,r])=>i!=="items"&&i!=="id"&&i!==u&&i!==A&&i!==S),n=yield e.items;return[["id",e.id?.startsWith("vault://")?void 0:e.id],...t,...yield*E(e),["items",n.length||e[S]===!1?n:y]]},Service:function*(e){return[[q,Je(e)]]},Annotation:function*(e){let t=Object.entries(e).map(([i,r])=>i==="motivation"?[i,Array.isArray(r)?r[0]:r]:i==="target"?[i,x(r,{allowString:!0,allowSourceString:!0,allowedStringType:"Canvas"})]:[i,Array.isArray(r)?p(r):r]).filter(([i])=>i!=="body"&&i!==u&&i!==S),n;if(Array.isArray(e.body)){let i=[];for(let r of e.body)if(r&&h(r)){let a={...r};a.source=yield r.source,i.push(x(a,{allowSourceString:!0}))}else i.push(yield r);n=i}else e.body&&h(e.body)?(n={...e.body},n.source=yield e.body.source):n=yield e.body;return[...t,...yield*_(e),...yield*E(e),["body",n.length===1?n[0]:n]]},ContentResource:function*(e){return sn([...F(e),...yield*_(e),...yield*E(e),["annotations",p(yield e.annotations)],["items",p(yield e.items)]],e)},AnnotationCollection:function*(e){return[["id",e.id],["type","AnnotationCollection"],["label",e.label]]},Collection:function*(e,t,{isTopLevel:n}){return n?[["@context","http://iiif.io/api/presentation/3/context.json"],...F(e),...yield*_(e),...yield*E(e),["items",p(yield e.items)],["navPlace",e.navPlace]]:[...F(e),...yield*_(e)]},Range:function*(e){let t=[];for(let n of e.items)n.type==="Range"?t.push(yield n):n&&n.type==="SpecificResource"?t.push(x(n)):t.push(n);return[...F(e),...yield*_(e),...yield*E(e),["items",t],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]}};function sn(e,t){let n=Object.keys(t),i=e.map(([r])=>r);for(let r of n)r===u||r===S||i.indexOf(r)===-1&&typeof t[r]<"u"&&e.push([r,t[r]]);return e}
"use strict";var B=Object.defineProperty;var et=Object.getOwnPropertyDescriptor;var tt=Object.getOwnPropertyNames;var nt=Object.prototype.hasOwnProperty;var it=(e,t,n)=>t in e?B(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var rt=(e,t)=>{for(var n in t)B(e,n,{get:t[n],enumerable:!0})},at=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of tt(t))!nt.call(e,r)&&r!==n&&B(e,r,{get:()=>t[r],enumerable:!(i=et(t,r))||i.enumerable});return e};var st=e=>at(B({},"__esModule",{value:!0}),e);var g=(e,t,n)=>(it(e,typeof t!="symbol"?t+"":t,n),n);var Mn={};rt(Mn,{EMPTY:()=>s,HAS_PART:()=>u,IS_EXTERNAL:()=>T,PART_OF:()=>C,Traverse:()=>q,UNSET:()=>y,UNWRAP:()=>G,WILDCARD:()=>N,addFlagForExternalResource:()=>Q,compressSpecificResource:()=>_,defaultEntities:()=>fn,emptyAgent:()=>ae,emptyAnnotation:()=>ot,emptyAnnotationPage:()=>ee,emptyCanvas:()=>te,emptyCollection:()=>ne,emptyManifest:()=>ie,emptyRange:()=>re,emptyService:()=>se,frameResource:()=>ve,getDefaultEntities:()=>$e,identifyResource:()=>ye,isSpecificResource:()=>h,isWildcard:()=>de,languageString2to3:()=>z,merge:()=>X,mergeEntities:()=>Y,normalize:()=>Rn,resolveIfExists:()=>H,serialize:()=>In,serializeConfigPresentation2:()=>xn,serializeConfigPresentation3:()=>En,serializedFieldsToObject:()=>Qe,toRef:()=>$,traverseSpecificResource:()=>Je,types:()=>oe});module.exports=st(Mn);function h(e){return typeof e=="string"?!1:!!e&&e.type==="SpecificResource"}function $(e,t){let n=t||"unknown";if(!e)return;if(typeof e=="string")return{id:e,type:n};if(h(e))return $(e.source,t);let i=n&&n!=="unknown"?n:e.type||e["@type"],r=e.id||e["@id"];if(i&&i.indexOf(":")!==-1&&(i=i.split(":").pop()),r&&i)return{id:r,type:i}}var N={},u="iiif-parser:hasPart",C="iiif-parser:partOf",T="iiif-parser:isExternal",y="__$UNSET$__",G="__$UNWRAP$__",s=[];Object.freeze(s);Object.freeze(N);function de(e){if(e===N||Object.keys(e).length===0)return!0;for(let t in e)return!1;return!0}function ve(e,t){if(t&&t["@explicit"]){let n={},i=Object.keys(t);for(let r of i)r===C||r==="@explicit"||(de(t[r])?n[r]=e[r]:n[r]=t[r]);return n}return e}function H(e,t,n){let i=$(t);if(!i)return[void 0,void 0];let r=e.requests[i.id],a=i.type||e.mapping[i.id];if(!a||r&&r.resourceUri&&(!e.entities[a]||!e.entities[a][r.resourceUri]))return[void 0,void 0];let o=e.entities[a][r?r.resourceUri:i.id];if(i.type&&!o)return H(e,{id:i.id},n);if(o&&o[u]){let l=o[u].find(c=>n?c[C]===n.id:c[C]===o.id);return[ve(o,l),o]}return[o,o]}var ot={id:"https://iiif-parser/annotation",type:"Annotation",behavior:s,label:null,thumbnail:s,summary:null,requiredStatement:null,metadata:s,seeAlso:s,homepage:s,rendering:s,service:s,accessibility:s,audience:s,body:s,bodyValue:null,canonical:null,created:null,creator:s,generated:null,generator:s,modified:null,motivation:s,rights:null,stylesheet:null,target:s,timeMode:void 0,via:s,partOf:s},ee={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:s,label:null,thumbnail:s,summary:null,requiredStatement:null,metadata:s,rights:null,provider:s,items:s,seeAlso:s,homepage:s,rendering:s,service:s},te={id:"https://iiif-parser/empty-canvas",type:"Canvas",label:null,behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,duration:0,height:0,width:0},ne={id:"https://iiif-parser/empty-collection",type:"Collection",label:null,viewingDirection:"left-to-right",behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,services:s},ie={id:"https://iiif-parser/empty-manifest",type:"Manifest",annotations:s,behavior:s,homepage:s,items:s,label:null,metadata:s,navDate:null,provider:s,partOf:s,accompanyingCanvas:null,placeholderCanvas:null,rendering:s,requiredStatement:null,rights:null,seeAlso:s,service:s,services:s,start:null,structures:s,summary:null,thumbnail:s,viewingDirection:"left-to-right"},re={id:"https://iiif-parser/empty-canvas",type:"Range",label:null,behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,start:null,supplementary:null,viewingDirection:"left-to-right"},ae={id:"https://iiif-parser/empty-agent",type:"Agent",label:{},logo:s,seeAlso:s,homepage:s},se={id:"https://iiif-parser/empty-service",type:"UnknownService"};function S(e){return Array.isArray(e)?e:e?[e]:[]}function U(...e){return t=>e.reduce((n,i)=>i(n),t)}var oe=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function ye(e,t){if(typeof e>"u"||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"){if(t)return t;throw new Error(`${typeof e} is not a valid entity`)}if(typeof e.type=="string"){let n=oe.indexOf(e.type);if(n!==-1)return oe[n]}if(e.profile)return"Service";throw new Error("Resource type is not known")}var q=class e{constructor(t,n={}){g(this,"traversals");g(this,"options");g(this,"_traverseManifest",U(this.traverseManifestItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseManifestStructures.bind(this),this.traverseInlineAnnotationPages.bind(this)));g(this,"_traverseCanvas",U(this.traverseCanvasItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseInlineAnnotationPages.bind(this)));g(this,"_traverseAnnotationPage",U(this.traverseAnnotationPageItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this)));g(this,"_traverseRange",U(this.traverseRangeRanges.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this)));this.traversals={collection:[],manifest:[],canvas:[],annotationCollection:[],annotationPage:[],annotation:[],contentResource:[],choice:[],range:[],service:[],agent:[],specificResource:[],geoJson:[],...t},this.options={allowUndefinedReturn:!1,...n}}static all(t){return new e({collection:[t],manifest:[t],canvas:[t],annotationCollection:[t],annotationPage:[t],annotation:[t],contentResource:[t],choice:[t],range:[t],service:[t],geoJson:[t],specificResource:[t],agent:[t]})}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=S(t.thumbnail).map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.provider&&(t.provider=t.provider.map(n=>this.traverseAgent(n,t))),t}traverseLinking(t){return t.seeAlso&&(t.seeAlso=t.seeAlso.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.service&&(t.service=S(t.service).map(n=>this.traverseService(n))),t.services&&(t.services=S(t.services).map(n=>this.traverseService(n,t))),t.logo&&(t.logo=t.logo.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.homepage&&(t.homepage=t.homepage.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.partOf&&(t.partOf=t.partOf.map(n=>typeof n=="string"||!n.type?this.traverseType(n,{parent:t},this.traversals.contentResource):n.type==="Canvas"?this.traverseType(n,{parent:t},this.traversals.canvas):n.type==="AnnotationCollection"?this.traverseType(n,{parent:t},this.traversals.annotationCollection):n.type==="Collection"?this.traverseType(n,{parent:t},this.traversals.collection):this.traverseType(n,{parent:t},this.traversals.contentResource))),t.start&&(h(t.start)?t.start=this.traverseSpecificResource(t.start,"Canvas",t):t.start=this.traverseType(t.start,{parent:t},this.traversals.canvas)),t.rendering&&(t.rendering=t.rendering.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.supplementary&&(t.supplementary=t.supplementary.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t}traverseCollectionItems(t){return t.items&&t.items.map(n=>n.type==="Collection"?this.traverseCollection(n):this.traverseManifest(n)),t}traverseCollection(t,n){return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traverseLinkedCanvases(this.traverseCollectionItems(t))))),{parent:n},this.traversals.collection)}traverseGeoJson(t,n){return this.traverseType(t,{parent:n},this.traversals.geoJson)}traverseNavPlace(t){return t.navPlace&&(t.navPlace=this.traverseGeoJson(t.navPlace,t)),t}traverseManifestItems(t){return t.items&&(t.items=t.items.map(n=>this.traverseCanvas(n))),t}traverseManifestStructures(t){return t.structures&&(t.structures=t.structures.map(n=>this.traverseRange(n))),t}traverseManifest(t,n){return this.traverseType(this._traverseManifest(t),{parent:n},this.traversals.manifest)}traverseCanvasItems(t){return t.items=(t.items||[]).map(n=>this.traverseAnnotationPage(n,t)),t}traverseInlineAnnotationPages(t){return typeof t=="string"||!t||t.annotations&&(t.annotations=t.annotations.map(n=>this.traverseAnnotationPage(n,t))),t}traverseCanvas(t,n){return this.traverseType(this._traverseCanvas(t),{parent:n},this.traversals.canvas)}traverseAnnotationPageItems(t){return t.items&&(t.items=t.items.map(n=>this.traverseAnnotation(n,t))),t}traverseAnnotationPage(t,n){return this.traverseType(this._traverseAnnotationPage(t),{parent:n},this.traversals.annotationPage)}traverseAnnotationBody(t){return Array.isArray(t.body)?t.body=t.body.map(n=>this.traverseContentResource(n,t)):t.body&&(t.body=this.traverseContentResource(t.body,t)),t}traverseLinkedCanvases(t){return t.placeholderCanvas&&(t.placeholderCanvas=this.traverseCanvas(t.placeholderCanvas)),t.accompanyingCanvas&&(t.accompanyingCanvas=this.traverseCanvas(t.accompanyingCanvas)),t}traverseAnnotation(t,n){return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(this.traverseDescriptive(t))),{parent:n},this.traversals.annotation)}traverseContentResourceLinking(t){return typeof t=="string"||!t||t&&t.service&&(t.service=S(t.service||[]).map(n=>this.traverseService(n,t))),t}traverseContentResource(t,n){return t.type==="Choice"&&(t.items=t.items.map(i=>this.traverseContentResource(i,t))),h(t)?this.traverseSpecificResource(t,"ContentResource"):this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(t)),{parent:n},this.traversals.contentResource)}traverseSpecificResource(t,n,i){let r=t.source;return typeof t.source=="string"&&(r={id:t.source,type:n||"unknown"}),this.traverseType({...t,source:n==="Canvas"||r.type==="Canvas"?this.traverseType(r,{parent:i},this.traversals.canvas):n==="ContentResource"?this.traverseContentResource(r,{parent:i}):this.traverseUnknown(r,{parent:i,typeHint:n})},{parent:i},this.traversals.specificResource)}traverseRangeRanges(t){return t.items&&(t.items=t.items.map(n=>typeof n=="string"?this.traverseCanvas({id:n,type:"Canvas"},t):h(n)?this.traverseSpecificResource(n,"Canvas",t):n.type==="Manifest"?this.traverseManifest(n,t):this.traverseRange(n,t))),t}traverseRange(t,n){return this.traverseType(this._traverseRange(t),{parent:n},this.traversals.range)}traverseAgent(t,n){return this.traverseType(this.traverseDescriptive(this.traverseLinking(t)),{parent:n},this.traversals.agent)}traverseType(t,n,i){return i.reduce((r,a)=>{let o=a(r,n);return typeof o>"u"&&!this.options.allowUndefinedReturn?r:o},t)}traverseService(t,n){let i=Object.assign({},t);return i&&i.service&&(i.service=S(i.service).map(r=>this.traverseService(r))),this.traverseType(i,{parent:n},this.traversals.service)}traverseUnknown(t,{parent:n,typeHint:i}={}){let r=ye(t,i);switch(r){case"Collection":return this.traverseCollection(t,n);case"Manifest":return this.traverseManifest(t,n);case"Canvas":return this.traverseCanvas(t,n);case"AnnotationPage":return this.traverseAnnotationPage(t,n);case"Annotation":return this.traverseAnnotation(t,n);case"ContentResource":return this.traverseContentResource(t,n);case"Range":return this.traverseRange(t,n);case"Service":return this.traverseService(t,n);case"Agent":return this.traverseAgent(t,n);default:throw new Error(`Unknown or unsupported resource type of ${r}`)}}};var he=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function lt(e){if(typeof e>"u"||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"){let t=he.indexOf(e["@type"]);if(t!==-1)return he[t]}if(e.profile)return"Service";if(e.format||e["@type"])return"ContentResource";throw new Error("Resource type is not known")}var K=class e{constructor(t,n={}){g(this,"traversals");g(this,"options");this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...t},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...n}}static all(t){return new e({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){let n=[...(t.manifests||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i),...(t.collections||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i),...t.members||[]];delete t.collections,delete t.manifests,t.members=n}return t.manifests&&(t.manifests=t.manifests.map(n=>this.traverseManifest(typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n))),t.collections&&(t.collections=t.collections.map(n=>this.traverseCollection(typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n))),t.members&&(t.members=t.members.map(n=>typeof n=="string"?n:this.traverseUnknown(n))),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(n=>this.traverseSequence(n))),t.structures&&(t.structures=t.structures.map(n=>this.traverseRange(n))),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(n=>this.traverseCanvas(n))),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(n=>this.traverseAnnotation(n))),t.otherContent&&(t.otherContent=t.otherContent.map(n=>this.traverseAnnotationList(n))),t}traverseRange(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(t))),this.traversals.range)}traverseRangeItems(t){if(this.options.mergeMemberProperties){let n=[...(t.ranges||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Range"}:i),...(t.canvases||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Canvas"}:i),...t.members||[]];delete t.ranges,delete t.canvases,t.members=n.length?n.map(i=>this.traverseUnknown(i)):void 0}return t}traverseAnnotationList(t){let n=typeof t=="string"?{"@id":t,"@type":"sc:AnnotationList"}:t;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(n)),this.traversals.annotationList)}traverseAnnotationListItems(t){return t.resources&&(t.resources=t.resources.map(n=>this.traverseAnnotation(n))),t}traverseAnnotation(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(t))),this.traversals.annotation)}traverseAnnotationItems(t){return t.resource&&(Array.isArray(t.resource)?t.resource=t.resource.map(n=>this.traverseContentResource(n)):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(n=>this.traverseAnnotationList(n))),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(n=>this.traverseContentResource(n))),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(lt(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"sc: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){let n=Array.isArray(t),i=Array.isArray(t)?t:[t],r=[];for(let a of i)typeof a=="string"?r.push(this.traverseContentResource({"@id":a,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(a));return!n&&!this.options.convertPropsToArray?r[0]:r}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=this.traverseImageResource(t.thumbnail)),t.logo&&(t.logo=this.traverseImageResource(t.logo)),t}traverseOneOrMoreServices(t){let n=Array.isArray(t),i=Array.isArray(t)?t:[t],r=[];for(let a of i)r.push(this.traverseService(a));return!n&&!this.options.convertPropsToArray?r[0]:r}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,n){if(!Array.isArray(t))if(this.options.convertPropsToArray)t=[t];else return this.traverseType(t,n);return t.map(i=>this.traverseType(i,n))}traverseType(t,n){return n.reduce((i,r)=>{let a=r(i);return typeof a>"u"&&!this.options.allowUndefinedReturn?i:a},t)}};var ct="http://library.stanford.edu/iiif/image-api/compliance.html#level1",pt="http://library.stanford.edu/iiif/image-api/compliance.html#level2";var ft="http://library.stanford.edu/iiif/image-api/conformance.html#level1",ut="http://library.stanford.edu/iiif/image-api/conformance.html#level2";var dt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",vt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2";var yt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",ht="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2";var mt="http://iiif.io/api/image/1/level1.json",gt="http://iiif.io/api/image/1/profiles/level1.json",At="http://iiif.io/api/image/1/level2.json",Ct="http://iiif.io/api/image/1/profiles/level2.json";var Rt="http://iiif.io/api/image/2/level1.json",It="http://iiif.io/api/image/2/profiles/level1.json",Tt="http://iiif.io/api/image/2/level2.json",St="http://iiif.io/api/image/2/profiles/level2.json";var Pt="level1",_t="level2";var xt="http://iiif.io/api/image/2/level1",Et="http://iiif.io/api/image/2/level2",me=[xt,Et,ct,pt,ft,ut,dt,vt,yt,ht,mt,gt,At,Ct,Rt,It,Tt,St,Pt,_t];function m(e){for(let t in e)(typeof e[t]>"u"||e[t]===null)&&delete e[t];return e}var Lt="http://library.stanford.edu/iiif/image-api/compliance.html#level0",ge="http://library.stanford.edu/iiif/image-api/compliance.html#level1",Ae="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Mt="http://library.stanford.edu/iiif/image-api/conformance.html#level0",Ce="http://library.stanford.edu/iiif/image-api/conformance.html#level1",Re="http://library.stanford.edu/iiif/image-api/conformance.html#level2",bt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Ie="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Te="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Nt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Se="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Pe="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Ot="http://iiif.io/api/image/1/level0.json",Ft="http://iiif.io/api/image/1/profiles/level0.json",_e="http://iiif.io/api/image/1/level1.json",xe="http://iiif.io/api/image/1/profiles/level1.json",Ee="http://iiif.io/api/image/1/level2.json",Le="http://iiif.io/api/image/1/profiles/level2.json",wt="http://iiif.io/api/image/2/level0.json",zt="http://iiif.io/api/image/2/profiles/level0.json",Me="http://iiif.io/api/image/2/level1.json",be="http://iiif.io/api/image/2/profiles/level1.json",Ne="http://iiif.io/api/image/2/level2.json",Oe="http://iiif.io/api/image/2/profiles/level2.json",kt="level0",Fe="level1",we="level2",Dt="http://iiif.io/api/image/2/level0",ze="http://iiif.io/api/image/2/level1",ke="http://iiif.io/api/image/2/level2",le=[ke,Ae,Re,Te,Pe,Ee,Le,Ne,Oe,we],Qn=[...le,ze,ge,Ce,Ie,Se,_e,xe,Me,be,Fe],jt=[Dt,ze,ke,Lt,ge,Ae,Mt,Ce,Re,bt,Ie,Te,Nt,Se,Pe,Ot,Ft,_e,xe,Ee,Le,wt,zt,Me,be,Ne,Oe,kt,Fe,we],De=jt;var ce={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function Gt(e){if(typeof e=="string")return[e];if(!e)return[];let t=Array.isArray(e)?e:[e],n=[];for(let i of t){if(typeof i=="string"){n.push(i);continue}n.push({"@language":i["@language"]||i.language,"@value":i["@value"]||i.value})}return n}function O(e,t="none"){if(!e)return{};let n=Gt(e),i={};for(let r of n){if(typeof r=="string"){i[t]=i[t]?i[t]:[],i[t].push(r||"");continue}if(!r["@language"]){i[t]=i[t]?i[t]:[],i[t].push(r["@value"]||"");continue}let a=r["@language"];i[a]=i[a]?i[a]:[],i[a].push(r["@value"]||"")}return i}function qe(e){if(Array.isArray(e))return qe(e.find(t=>typeof t=="string"));if(le.indexOf(e)!==-1)return"level2";if(me.indexOf(e)!==-1)return"level1";if(De.indexOf(e)!==-1)return"level0";if(typeof e=="string")return e}function Ut(e){let t=Array.isArray(e)?e:[e];for(let n of t)switch(n){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 qt(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 je(e){for(let t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}var Vt=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function fe(e){let t=e["@id"]||e.id,n=e["@type"]||e.type,i=e.profile||void 0,r=e["@context"]||void 0;if(i){let a=qt(i);if(a)return a}if(r){let a=Ut(r);if(a)return a}if(n){if(Array.isArray(n)){if(n.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(n.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";n=n[0]}for(let a of["sc","oa","dcterms","dctypes","iiif"])if(n.startsWith(`${a}:`)){n=n.slice(a.length+1);break}switch(n){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(n&&Vt.indexOf(n)!==-1)return n;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":n||"unknown"}var Wt=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Bt(e){let t=e.match(Wt);return t?t[0]:e}function $t(e,t="Rights/License",n="none"){let i=null,r=[],a=Array.isArray(e)?e:[e];for(let o of a){let l=o?Bt(o):void 0;if(l&&(l.indexOf("creativecommons.org")!==-1||l.indexOf("rightsstatements.org")!==-1)){l.startsWith("https://")?i=`http://${l.slice(8)}`:i=l;continue}l&&r.push({label:{[n]:[t]},value:{[n]:[l]}})}return[i,r]}var Ht=["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 Kt(e){if(e){let t=Array.isArray(e)?e:[e],n=[];for(let i of t)i==="http://iiif.io/api/presentation/2/context.json"&&n.push("http://iiif.io/api/presentation/3/context.json"),Ht.indexOf(i)===-1&&n.push(i);if(t.length)return n.length===1?n[0]:n}}function Jt(e){return e?e.map(t=>({label:O(t.label),value:O(t.value)})):[]}var Ge=0;function Ve(e,t){let n=encodeURI(e.id||e["@id"]||"").trim();return n&&t?`${n}/${t}`:n||(Ge++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${Ge}`)}function R(e){let t=[...e.behavior||[]];e.viewingHint&&t.push(e.viewingHint);let n;return Array.isArray(e.motivation)?n=e.motivation.map(je):e.motivation&&(n=je(e.motivation)),{"@context":e["@context"]?Kt(e["@context"]):void 0,id:(e["@id"]||Ve(e)).trim(),type:fe(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:n,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function I(e){let[t,n]=$t(e.license),i=[...e.metadata?Jt(e.metadata):[],...n];return{rights:t,metadata:i.length?i:void 0,label:e.label?O(e.label):void 0,requiredStatement:e.attribution?{label:O(ce.attributionLabel),value:O(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?O(e.description):void 0,thumbnail:Qt(e.thumbnail)}}function Qt(e){return e&&(Array.isArray(e)?e:[e]).map(n=>typeof n=="string"?{id:n,type:"Image"}:(n.type==="unknown"&&(n.type="Image"),n))}function Xt(e){if(!e.within)return;let t=Array.isArray(e.within)?e.within:[e.within],n=[];for(let i of t)if(typeof i=="string"){if(i)switch(e["@type"]){case"sc:Manifest":n.push({id:i,type:"Collection"});break}}else i["@id"]&&n.push({id:i["@id"],type:fe(i)});return n.length?n:void 0}function P(e){let t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],n=e.contentLayer;return{provider:e.logo||t.length?[{id:ce.providerId,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:O(ce.providerName)}]:void 0,partOf:Xt(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?S(e.service):void 0,supplementary:n?[n]:void 0}}function Yt(e){return{chars:e.chars,format:e.format?e.format:void 0,language:e.language}}function Zt(e){return m({...R(e),...I(e),...P(e),items:e.members})}function en(e){let t=[],n=[],i;for(let a of e.sequences||[])a.canvases.length&&t.push(...a.canvases),a.behavior&&n.push(...a.behavior),a.startCanvas&&(i=a.startCanvas);let r=R(e);return n.length&&(r.behavior?r.behavior.push(...n):r.behavior=n),m({...r,...I(e),...P(e),start:i,items:t,structures:e.structures})}function tn(e){return m({...R(e),...I(e),...P(e),annotations:e.otherContent&&e.otherContent.length?e.otherContent:void 0,items:e.images&&e.images.length?[{id:Ve(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}function nn(e){return m({...R(e),...I(e),...P(e),items:e.resources&&e.resources.length?e.resources:void 0})}function rn(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}}function an(e){function t(n){if(Array.isArray(n)){if(n.length>1)return{type:"List",items:n.map(t)};n=n[0]}if(typeof n=="string")return encodeURI(n).trim();if("@type"in n){let i;if(typeof n.full=="string")i=n.full;else if(n.full["@type"]==="dctypes:Image")i={id:n.full["@id"],type:"Image"};else if(n.full["@type"]==="sc:Canvas")i={id:n.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${n.full["@type"]}`);return{type:"SpecificResource",source:i,selector:pe(n.selector)}}else return encodeURI(n["@id"]).trim()}return m({...R(e),...I(e),...P(e),target:t(e.on),body:Array.isArray(e.resource)?e.resource.map(Ue):Ue(e.resource)})}function Ue(e){return e.type==="Choice"?e:We(e)}function We(e){let t=e;return m({...R(t),...I(t),...P(t),...Yt(t)})}function sn(e){let t=[];return e.default&&e.default!=="rdf:nil"&&t.push(e.default),e.item&&e.item!=="rdf:nil"&&t.push(...e.item),m({...R(e),...I(e),items:t})}function on(e){return m({...R(e),...I(e),...P(e),items:e.members})}function ln(e){let{"@id":t,"@type":n,"@context":i,profile:r,...a}=e,o={};return t&&(o["@id"]=t),o["@type"]=fe(e),o["@type"]==="unknown"&&(i&&i.length&&(o["@context"]=i),o["@type"]="Service"),r&&(o.profile=qe(r)),m({...o,...a})}function cn(e){return m({...R(e),...I(e),...P(e)})}var pn=new K({collection:[Zt],manifest:[en],canvas:[tn],annotationList:[nn],sequence:[rn],annotation:[an],contentResource:[We],choice:[sn],range:[on],service:[ln],layer:[cn]});function Be(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"?pn.traverseUnknown(e):e}function pe(e){if((Array.isArray(e["@type"])&&e["@type"].includes("oa:SvgSelector")||e["@type"]=="oa:SvgSelector")&&("chars"in e||"value"in e))return{type:"SvgSelector",value:"chars"in e?e.chars:e.value};if(e["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:e.value};if(e["@type"]==="oa:Choice")return[pe(e.default),...(Array.isArray(e.item)?e.item:[e.item]).map(pe)];if(e["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in e?e.region:void 0,rotation:"rotation"in e?e.rotation:void 0};throw new Error(`Unsupported selector type: ${e["@type"]}`)}function J(e,t={}){if(Array.isArray(e))return J(e[0]);if(typeof e=="string"){let[n,i]=e.split("#");return i?{type:"SpecificResource",source:{id:n,type:t.typeHint||"Unknown"},selector:{type:"FragmentSelector",value:i}}:{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||t.typeHint||"Unknown"}}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return J(e.items[0]);if(e.type==="SpecificResource")return e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]),e.selector?{type:"SpecificResource",source:e.source,selector:e.selector}:{type:"SpecificResource",source:e.source};if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);let[n,i]=e.id.split("#");return i?{type:"SpecificResource",source:{...e,id:n},selector:{type:"FragmentSelector",value:i}}:{type:"SpecificResource",source:{...e,id:n}}}return{type:"SpecificResource",source:e}}var fn={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}};function $e(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}function He(e,t){if(typeof e=="string")return{id:e,type:t};if(!e.id)throw new Error(`Invalid resource does not have an ID (${JSON.stringify(e)}, ${t})`);return e}function un(e,t){return(n,i)=>{let r=e[n]?e[n]:{};return(a,o)=>{let l=He(a,i||n);return l&&l.id&&n?(r[l.id]=r[l.id]?Y(r[l.id],l,{parent:o.parent,isTopLevel:t.id===l.id}):Y({id:l.id,type:l.type},l,{parent:o.parent,isTopLevel:t.id===l.id}),{id:l.id,type:n==="ContentResource"?n:l.type}):l}}}function X(e,t,n){if(!t)return e;if(Array.isArray(e)){if(!Array.isArray(t))throw new Error("Cannot merge array with non-array");let i=[...e];for(let r of t)if(r["@id"]&&!r.id&&(r.id=r["@id"]),r["@type"]&&!r.type&&(r.type=r["@type"]),r!=null)if(Array.isArray(r))i.push(r);else if(typeof r=="object"&&r.id&&r.type){let a=i.findIndex(o=>o.id===r.id&&o.type===r.type);a>=0&&(i[a]=X(i[a],r))}else e.indexOf(r)===-1&&i.push(r);return i}else if(typeof e=="object"){if(Array.isArray(t)||typeof t!="object")throw new Error("Cannot merge object with non-object");let i={...e},r=[],a=[],o=Object.keys(e).filter(c=>c!==u&&c!=="id"&&c!=="type"),l={},M={};for(let[c,f]of Object.entries(t)){if(c===u||c==="id"||c==="type")continue;let v=i[c];v===f?a.push(c):v===s||!v?(r.push(c),i[c]=f):(v&&f&&(l[c]=v,M[c]=f),i[c]=X(v,f),i[c]===l[c]&&(a.push(c),delete l[c]))}if(n&&(n.parent&&n.parent.id||n.isTopLevel)){let c=[],f={};if(n.parent?f[C]=n.parent.id:n.isTopLevel&&(f[C]=e.id),i[u]&&i[u].length){let v=!(i[u]||[]).find(A=>A["@explicit"]),b=r.length>0||a.length!==o.length;if(v&&b)for(let A of i[u]){let d={...A},Z=Object.keys(l);if(d){d["@explicit"]=!0;for(let j of o)j!==u&&(d[j]=N);for(let j of Z)d[j]=l[j]}c.push(d)}else c.push(...i[u]);if(b){let A=Object.keys(M);f["@explicit"]=!0;for(let d of r)f[d]=N;for(let d of a)f[d]=N;for(let d of A)f[d]=M[d]}}f.id=i.id,f.type=i.type,c.push(f),i[u]=c}return i}else if(e)return e;return t}function Y(e,t,n){if(typeof e=="string")return e;if(t.id!==e.id||t.type!==e.type){if(t.type==="ImageService3")return t;if(e.type==="ImageService3")return e;throw new Error(`Can only merge entities with identical identifiers and type! ${t.type}(${t.id}) => ${e.type}(${e.id})`)}return X({...e},t,n)}function dn(e){return(t,n)=>i=>{let{id:r,type:a}=He(i,n||t);if(typeof r>"u")throw new Error("Found invalid entity without an ID.");return t==="ContentResource"||t==="Service"?e[r]=t:e[r]=a,i}}function vn(e){let t=Object.assign({},e);if(t["@id"]&&(t.id=t["@id"]),t["@type"]&&(t.type=t["@type"]),t.service){let n=[];t.service=Array.isArray(t.service)?t.service:[t.service];for(let i of t.service)n.push({id:i["@id"]||i.id,type:i["@type"]||i.type});t.service=n}return Object.assign({},se,t)}function yn(e){return t=>{e.Service=e.Service?e.Service:{};let n=t.id||t["@id"],i=vn(t);return i&&i.id&&(e.Service[i.id]?e.Service[n]=Y(e.Service[n],i):e.Service[n]=i),t}}function hn(e){let t=JSON.stringify(e),n=5381,i=t.length;for(;i;)n=n*33^t.charCodeAt(--i);let a=(n>>>0).toString(16);return a.length%2?"0"+a:a}function ue(e){return t=>typeof t=="string"?{id:t,type:e}:t.id?t.type?t:{type:e,...t}:{id:`vault://${hn(t)}`,type:e,...t}}function D(e){return t=>({...e,...t})}function V(e){return Array.isArray(e)?e:[e]}function mn(e){return e.body&&(e.body=V(e.body)),e.seeAlso&&(e.seeAlso=V(e.seeAlso)),e.audience&&(e.audience=V(e.audience)),e.accessibility&&(e.accessibility=V(e.accessibility)),e.motivation&&(e.motivation=V(e.motivation)),e}function Ke(e,{typeHint:t,partOfTypeHint:n}={}){if(typeof e=="string"&&(e={id:e,type:t||"unknown"}),h(e))return typeof e.source=="string"&&(e.source={id:e.source,type:t||"unknown"}),e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:n||"Manifest"}]),e;let i;if((e.id||"").indexOf("#")!==-1){let[r,a]=(e.id||"").split("#");e.id=r,a&&(i={type:"FragmentSelector",value:a})}return{type:"SpecificResource",source:e,selector:i}}function gn(e){let t=Object.assign({},e);return e&&e.items&&(t.items=e.items.map(n=>typeof n=="string"||n.type==="Canvas"?Ke(n):n)),t}function An(e){let t=Object.assign({},e);return t.start?(t.start=Ke(t.start,{typeHint:"Canvas"}),t):e}function Cn(e){let t=Object.assign({},e);return t.target?(t.target=J(t.target,{typeHint:"Canvas"}),t):e}function Je(e){return e}function Q(e){return typeof e.items>"u"&&(e[T]=!0),e}function Rn(e){let t=Be(e),n=$e(),i={},r=un(n,t),a=dn(i),l=new q({collection:[Q,D(ne),a("Collection"),r("Collection")],manifest:[Q,D(ie),An,a("Manifest"),r("Manifest")],canvas:[D(te),a("Canvas"),r("Canvas")],annotationPage:[Q,ue("AnnotationPage"),D(ee),a("AnnotationPage"),r("AnnotationPage")],annotation:[ue("Annotation"),mn,Cn,a("Annotation"),r("Annotation")],contentResource:[ue("ContentResource"),a("ContentResource"),r("ContentResource")],range:[D(re),gn,a("Range","Canvas"),r("Range","Canvas")],agent:[D(ae),a("Agent"),r("Agent")],specificResource:[Je],service:[yn(n)]}).traverseUnknown(t);return{entities:n,resource:l,mapping:i}}function Qe(e){let t={};for(let[n,i]of e){if(n===G&&i!==y)return i;i!==y&&typeof i<"u"&&i!==null&&(t[n]=i)}return t}function In(e,t,n){if(!t.type||!t.id)throw new Error("Unknown entity");if(!n[t.type])throw new Error(`Serializer not found for ${t.type}`);function i(r,a,o=0){let l=n[r.type];if(!l)return y;if(o>20)throw new Error("Circular reference: "+r.id+" "+r.type);let[M,c]=H(e,r.type?r:r.id,a)||(r.id&&r.type?r:null);if(!M)return y;let f=l(M,e,{parent:a,isTopLevel:t.id===r.id,fullResource:c}),v=f.next();for(;!v.done;){let b=v.value,A=y;if(b)if(Array.isArray(b)){let d=[];for(let Z of b)d.push(i(Z,r,o+1));A=d}else A=i(b,r,o+1);v=f.next(A)}return v.value===y?y:Qe(v.value)}return i(t)}function _(e,{allowSourceString:t=!0,allowString:n=!1,allowedStringType:i}={}){let r=a=>{if(t&&a&&a.source&&typeof a.source!="string"){let o=Object.keys(a.source);if(a.source.id&&a.source.type&&o.length===2)return{...a,source:a.source.id}}return a};if(e){if(e.source&&e.source.partOf)return r(e);let a=Object.keys(e);if(a.length===2&&e.type&&e.source||a.length===3&&e.type&&e.source&&a.indexOf("selector")!==-1&&!e.selector)return n&&(!i||i===e.source.type)?e.source.id:e.source.type==="ContentResource"?{type:"SpecificResource",source:e.source.id}:e.source;if(e.selector&&!Array.isArray(e.selector)&&typeof e.selector!="string"&&e.selector.type==="FragmentSelector"){let o=`${e.source.id}#${e.selector.value}`;return n?o:{id:o,type:e.source.type}}}return r(e)}function z(e){if(!e)return;let t=Object.keys(e);if(t.length!==0){if(t.length===1){let n=t[0];if(!n)return"";let i=(e[n]||[]).join("");return n==="@none"||n==="none"||n==="en"?i:{"@language":n,"@value":i}}return t.map(n=>({"@language":n,"@value":(e[n]||[]).join("")}))}}function Xe(e){return Array.isArray(e)?e.map(t=>Xe(t)):typeof e=="string"?e:e.type&&e.type==="Canvas"?e.id:e}function x(e,t=!1){if(e)return e.length>1&&!t?e:e[0]||void 0}function Tn(e){if(e){if(typeof e=="string")return{"@id":e};if("@id"in e){let t={...e};return delete t["@type"],t}return{"@context":"http://iiif.io/api/image/2/context.json","@id":e.id,profile:`http://iiif.io/api/image/2/profiles/${e.profile}.json`}}}function F(e,t){return[["@id",e.id],["@type",t],["format",e.format],["height",e.height],["width",e.width],["viewingDirection",e.viewingDirection!=="left-to-right"?e.viewingDirection:void 0],["license",e.license?e.license:void 0]]}function*w(e){let t=e.provider?yield e.provider[0]:void 0;return[["label",z(e.label)],["metadata",e.metadata&&e.metadata.length?e.metadata.map(n=>({label:z(n.label)||"",value:z(n.value)||""})):void 0],["description",z(e.summary)],["thumbnail",x(yield e.thumbnail)],["navDate",e.navDate],["logo",t?x(t.logo):void 0],["homepage",t?t.homepage:void 0],["attribution",e.requiredStatement?z(e.requiredStatement.value):void 0]]}function*W(e){let t=e.start&&e.start.type&&e.start.type==="SpecificResource"?_(e.start):e.start;return[["seeAlso",x(yield e.seeAlso)],["service",x((e.service||[]).map(Tn))],["rendering",x(yield e.rendering)],["startCanvas",t?t.id:void 0]]}function Sn(e){return e.type==="SpecificResource"}function Pn(e){return e&&e.type==="FragmentSelector"}function _n(e){if(e&&Sn(e)){let t=e.id,n=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return Pn(n)&&(t+="#"+n.value),t}return e?.id}var xn={Manifest:function*(e,t,{isTopLevel:n}){return[...n?[["@context","http://iiif.io/api/presentation/2/context.json"]]:[],...F(e,"sc:Manifest"),...yield*w(e),...yield*W(e),["sequences",[{"@id":`${e.id}/sequence0`,"@type":"sc:Sequence",canvases:yield e.items}]],["structures",yield e.structures]]},Canvas:function*(e){let n=(yield e.items)[0];return[...F(e,"sc:Canvas"),...yield*w(e),...yield*W(e),["images",n?[n.resources]:void 0],["annotations",e.annotations&&e.annotations.length?x(yield e.annotations):void 0]]},AnnotationPage:function*(e){return[...F(e,"sc:AnnotationList"),...yield*w(e),["resources",e.items&&e.items.length?x(yield e.items):void 0]]},Annotation:function*(e){return[["@id",e.id],["@type","oa:Annotation"],["motivation","sc:painting"],["on",Xe(e.target)],["resource",x(yield e.body,!0)]]},ContentResource:function*(e){switch(e.type){case"Image":return[...F(e,"dctypes:Image"),...yield*w(e),...yield*W(e)];case"Text":case"Dataset":default:return[...F(e,void 0),...yield*w(e)]}},AnnotationCollection:function*(e){return[["@id",e.id],["@type","sc:Layer"],["label",z(e.label)]]},Collection:function*(e){return[...F(e,"sc:Collection"),...yield*w(e),...yield*W(e),["members",yield*e.items]]},Range:function*(e){let t=[],n=[];if(e.items)for(let i of e.items){let r=i.type==="SpecificResource"?i.source:i;if(r){let a=yield r;t.push({"@id":_n(i),"@type":r.type,label:a?a.label:void 0,within:e.id}),r.type==="Canvas"&&n.push(r.id)}}return[...F(e,"sc:Range"),...yield*w(e),...yield*W(e),["canvases",n.length===t.length?n:void 0],["members",n.length!==t.length?t:void 0]]}};function k(e){return[["id",e.id?.startsWith("vault://")?void 0:e.id],["type",e.type],["format",e.format],["profile",e.profile],["height",e.height||void 0],["width",e.width||void 0],["duration",e.duration||void 0],["viewingDirection",e.viewingDirection!=="left-to-right"?e.viewingDirection:void 0],["behavior",e.behavior&&e.behavior.length?e.behavior:void 0],["timeMode",e.timeMode],["motivation",Array.isArray(e.motivation)?e.motivation[0]:e.motivation],[u,y]]}function p(e){if(e===y||!e||e.length===0)return;let t=e.filter(n=>n!==y);if(t.length!==0)return t}function Ze(e){if(e&&e.type&&e.type==="ImageService2"){let{id:t,type:n,profile:i,...r}=e,a=typeof i=="string"?i:Array.isArray(i)?i.find(o=>typeof o=="string"):"";return{"@id":t,"@type":n,profile:a?a.startsWith("http")?a:`http://iiif.io/api/image/2/${a}.json`:"http://iiif.io/api/image/2/level0.json",...r}}return e}function Ye(e){if(Array.isArray(e)||(e=e?[e]:[]),!(!e||e.length===0))return e.map(Ze)}function*E(e){return[["label",e.label],["metadata",p(e.metadata)],["summary",e.summary],["requiredStatement",e.requiredStatement],["rights",Array.isArray(e.rights)?e.rights[0]||void 0:e.rights||void 0],["navDate",e.navDate],["language",e.language],["thumbnail",p(yield e.thumbnail)],["placeholderCanvas",yield e.placeholderCanvas],["accompanyingCanvas",yield e.accompanyingCanvas],["provider",p(yield e.provider)]]}function*L(e){return[["seeAlso",p(yield e.seeAlso)],["service",p(Ye(e.service))],["services",p(Ye(e.services))],["rendering",p(yield e.rendering)],["supplementary",p(yield e.supplementary)],["homepage",p(yield e.homepage)],["logo",p(yield e.logo)],["partOf",p(yield e.partOf)],["start",e.start?_(e.start):e.start]]}var En={Manifest:function*(e,t,{isTopLevel:n}){return n?[["@context",e["@context"]?e["@context"]:"http://iiif.io/api/presentation/3/context.json"],...k(e),...yield*E(e),...yield*L(e),["items",yield e.items],["structures",p(yield e.structures)],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]:[...k(e),...yield*E(e)]},Canvas:function*(e){return[...k(e),...yield*E(e),...yield*L(e),["items",yield e.items],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]},Agent:function*(e){return[["id",e.id],["type","Agent"],["label",e.label],...yield*L(e)]},AnnotationPage:function*(e){let t=Object.entries(e).map(([i,r])=>[i,Array.isArray(r)?p(r):r]).filter(([i,r])=>i!=="items"&&i!=="id"&&i!==u&&i!==C&&i!==T),n=yield e.items;return[["id",e.id?.startsWith("vault://")?void 0:e.id],...t,...yield*L(e),["items",n.length||e[T]===!1?n:y]]},Service:function*(e){return[[G,Ze(e)]]},Annotation:function*(e){let t=Object.entries(e).map(([i,r])=>i==="motivation"?[i,Array.isArray(r)?r[0]:r]:i==="target"?[i,_(r,{allowString:!0,allowSourceString:!0,allowedStringType:"Canvas"})]:[i,Array.isArray(r)?p(r):r]).filter(([i])=>i!=="body"&&i!==u&&i!==T),n;if(Array.isArray(e.body)){let i=[];for(let r of e.body)if(r&&h(r)){let a={...r};a.source=yield r.source,i.push(_(a,{allowSourceString:!0}))}else i.push(yield r);n=i}else e.body&&h(e.body)?(n={...e.body},n.source=yield e.body.source):n=yield e.body;return[...t,...yield*E(e),...yield*L(e),["body",n.length===1?n[0]:n]]},ContentResource:function*(e){return Ln([...k(e),...yield*E(e),...yield*L(e),["annotations",p(yield e.annotations)],["items",p(yield e.items)]],e)},AnnotationCollection:function*(e){return[["id",e.id],["type","AnnotationCollection"],["label",e.label]]},Collection:function*(e,t,{isTopLevel:n}){return n?[["@context","http://iiif.io/api/presentation/3/context.json"],...k(e),...yield*E(e),...yield*L(e),["items",p(yield e.items)],["navPlace",e.navPlace]]:[...k(e),...yield*E(e)]},Range:function*(e){let t=[];for(let n of e.items)n.type==="Range"?t.push(yield n):n&&n.type==="SpecificResource"?t.push(_(n)):t.push(n);return[...k(e),...yield*E(e),...yield*L(e),["items",t],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]}};function Ln(e,t){let n=Object.keys(t),i=e.map(([r])=>r);for(let r of n)r===u||r===T||i.indexOf(r)===-1&&typeof t[r]<"u"&&e.push([r,t[r]]);return e}

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

"use strict";var IIIFParser=(()=>{var V=Object.defineProperty;var Qe=Object.getOwnPropertyDescriptor;var Ze=Object.getOwnPropertyNames;var et=Object.prototype.hasOwnProperty;var tt=(e,t,n)=>t in e?V(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var nt=(e,t)=>{for(var n in t)V(e,n,{get:t[n],enumerable:!0})},it=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ze(t))!et.call(e,r)&&r!==n&&V(e,r,{get:()=>t[r],enumerable:!(i=Qe(t,r))||i.enumerable});return e};var rt=e=>it(V({},"__esModule",{value:!0}),e);var m=(e,t,n)=>(tt(e,typeof t!="symbol"?t+"":t,n),n);var on={};nt(on,{EMPTY:()=>s,HAS_PART:()=>u,IS_EXTERNAL:()=>S,PART_OF:()=>A,Traverse:()=>G,UNSET:()=>y,UNWRAP:()=>q,WILDCARD:()=>w,addFlagForExternalResource:()=>Y,compressSpecificResource:()=>x,defaultEntities:()=>Ut,emptyAgent:()=>ae,emptyAnnotation:()=>at,emptyAnnotationPage:()=>ee,emptyCanvas:()=>te,emptyCollection:()=>ne,emptyManifest:()=>ie,emptyRange:()=>re,emptyService:()=>se,frameResource:()=>ve,getDefaultEntities:()=>We,identifyResource:()=>ye,isSpecificResource:()=>h,isWildcard:()=>de,languageString2to3:()=>k,merge:()=>J,mergeEntities:()=>Q,normalize:()=>Jt,resolveIfExists:()=>B,serialize:()=>Qt,serializeConfigPresentation2:()=>rn,serializeConfigPresentation3:()=>an,serializedFieldsToObject:()=>Ke,toRef:()=>H,traverseSpecificResource:()=>Be,types:()=>oe});function h(e){return typeof e=="string"?!1:!!e&&e.type==="SpecificResource"}function H(e,t){let n=t||"unknown";if(!e)return;if(typeof e=="string")return{id:e,type:n};if(h(e))return H(e.source,t);let i=n&&n!=="unknown"?n:e.type||e["@type"],r=e.id||e["@id"];if(i&&i.indexOf(":")!==-1&&(i=i.split(":").pop()),r&&i)return{id:r,type:i}}var w={},u="iiif-parser:hasPart",A="iiif-parser:partOf",S="iiif-parser:isExternal",y="__$UNSET$__",q="__$UNWRAP$__",s=[];Object.freeze(s);Object.freeze(w);function de(e){if(e===w||Object.keys(e).length===0)return!0;for(let t in e)return!1;return!0}function ve(e,t){if(t&&t["@explicit"]){let n={},i=Object.keys(t);for(let r of i)r===A||r==="@explicit"||(de(t[r])?n[r]=e[r]:n[r]=t[r]);return n}return e}function B(e,t,n){let i=H(t);if(!i)return[void 0,void 0];let r=e.requests[i.id],a=i.type||e.mapping[i.id];if(!a||r&&r.resourceUri&&(!e.entities[a]||!e.entities[a][r.resourceUri]))return[void 0,void 0];let o=e.entities[a][r?r.resourceUri:i.id];if(i.type&&!o)return B(e,{id:i.id},n);if(o&&o[u]){let c=o[u].find(l=>n?l[A]===n.id:l[A]===o.id);return[ve(o,c),o]}return[o,o]}var at={id:"https://iiif-parser/annotation",type:"Annotation",behavior:s,label:null,thumbnail:s,summary:null,requiredStatement:null,metadata:s,seeAlso:s,homepage:s,rendering:s,service:s,accessibility:s,audience:s,body:s,bodyValue:null,canonical:null,created:null,creator:s,generated:null,generator:s,modified:null,motivation:s,rights:null,stylesheet:null,target:s,timeMode:void 0,via:s,partOf:s},ee={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:s,label:null,thumbnail:s,summary:null,requiredStatement:null,metadata:s,rights:null,provider:s,items:s,seeAlso:s,homepage:s,rendering:s,service:s},te={id:"https://iiif-parser/empty-canvas",type:"Canvas",label:null,behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,duration:0,height:0,width:0},ne={id:"https://iiif-parser/empty-collection",type:"Collection",label:null,viewingDirection:"left-to-right",behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,services:s},ie={id:"https://iiif-parser/empty-manifest",type:"Manifest",annotations:s,behavior:s,homepage:s,items:s,label:null,metadata:s,navDate:null,provider:s,partOf:s,accompanyingCanvas:null,placeholderCanvas:null,rendering:s,requiredStatement:null,rights:null,seeAlso:s,service:s,services:s,start:null,structures:s,summary:null,thumbnail:s,viewingDirection:"left-to-right"},re={id:"https://iiif-parser/empty-canvas",type:"Range",label:null,behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,start:null,supplementary:null,viewingDirection:"left-to-right"},ae={id:"https://iiif-parser/empty-agent",type:"Agent",label:{},logo:s,seeAlso:s,homepage:s},se={id:"https://iiif-parser/empty-service",type:"UnknownService"};function P(e){return Array.isArray(e)?e:e?[e]:[]}function U(...e){return t=>e.reduce((n,i)=>i(n),t)}var oe=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function ye(e,t){if(typeof e>"u"||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"){if(t)return t;throw new Error(`${typeof e} is not a valid entity`)}if(typeof e.type=="string"){let n=oe.indexOf(e.type);if(n!==-1)return oe[n]}if(e.profile)return"Service";throw new Error("Resource type is not known")}var G=class e{constructor(t,n={}){m(this,"traversals");m(this,"options");m(this,"_traverseManifest",U(this.traverseManifestItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseManifestStructures.bind(this),this.traverseInlineAnnotationPages.bind(this)));m(this,"_traverseCanvas",U(this.traverseCanvasItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseInlineAnnotationPages.bind(this)));m(this,"_traverseAnnotationPage",U(this.traverseAnnotationPageItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this)));m(this,"_traverseRange",U(this.traverseRangeRanges.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this)));this.traversals={collection:[],manifest:[],canvas:[],annotationCollection:[],annotationPage:[],annotation:[],contentResource:[],choice:[],range:[],service:[],agent:[],specificResource:[],geoJson:[],...t},this.options={allowUndefinedReturn:!1,...n}}static all(t){return new e({collection:[t],manifest:[t],canvas:[t],annotationCollection:[t],annotationPage:[t],annotation:[t],contentResource:[t],choice:[t],range:[t],service:[t],geoJson:[t],specificResource:[t],agent:[t]})}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=P(t.thumbnail).map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.provider&&(t.provider=t.provider.map(n=>this.traverseAgent(n,t))),t}traverseLinking(t){return t.seeAlso&&(t.seeAlso=t.seeAlso.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.service&&(t.service=P(t.service).map(n=>this.traverseService(n))),t.services&&(t.services=P(t.services).map(n=>this.traverseService(n,t))),t.logo&&(t.logo=t.logo.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.homepage&&(t.homepage=t.homepage.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.partOf&&(t.partOf=t.partOf.map(n=>typeof n=="string"||!n.type?this.traverseType(n,{parent:t},this.traversals.contentResource):n.type==="Canvas"?this.traverseType(n,{parent:t},this.traversals.canvas):n.type==="AnnotationCollection"?this.traverseType(n,{parent:t},this.traversals.annotationCollection):n.type==="Collection"?this.traverseType(n,{parent:t},this.traversals.collection):this.traverseType(n,{parent:t},this.traversals.contentResource))),t.start&&(h(t.start)?t.start=this.traverseSpecificResource(t.start,"Canvas",t):t.start=this.traverseType(t.start,{parent:t},this.traversals.canvas)),t.rendering&&(t.rendering=t.rendering.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.supplementary&&(t.supplementary=t.supplementary.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t}traverseCollectionItems(t){return t.items&&t.items.map(n=>n.type==="Collection"?this.traverseCollection(n):this.traverseManifest(n)),t}traverseCollection(t,n){return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traverseLinkedCanvases(this.traverseCollectionItems(t))))),{parent:n},this.traversals.collection)}traverseGeoJson(t,n){return this.traverseType(t,{parent:n},this.traversals.geoJson)}traverseNavPlace(t){return t.navPlace&&(t.navPlace=this.traverseGeoJson(t.navPlace,t)),t}traverseManifestItems(t){return t.items&&(t.items=t.items.map(n=>this.traverseCanvas(n))),t}traverseManifestStructures(t){return t.structures&&(t.structures=t.structures.map(n=>this.traverseRange(n))),t}traverseManifest(t,n){return this.traverseType(this._traverseManifest(t),{parent:n},this.traversals.manifest)}traverseCanvasItems(t){return t.items=(t.items||[]).map(n=>this.traverseAnnotationPage(n,t)),t}traverseInlineAnnotationPages(t){return typeof t=="string"||!t||t.annotations&&(t.annotations=t.annotations.map(n=>this.traverseAnnotationPage(n,t))),t}traverseCanvas(t,n){return this.traverseType(this._traverseCanvas(t),{parent:n},this.traversals.canvas)}traverseAnnotationPageItems(t){return t.items&&(t.items=t.items.map(n=>this.traverseAnnotation(n,t))),t}traverseAnnotationPage(t,n){return this.traverseType(this._traverseAnnotationPage(t),{parent:n},this.traversals.annotationPage)}traverseAnnotationBody(t){return Array.isArray(t.body)?t.body=t.body.map(n=>this.traverseContentResource(n,t)):t.body&&(t.body=this.traverseContentResource(t.body,t)),t}traverseLinkedCanvases(t){return t.placeholderCanvas&&(t.placeholderCanvas=this.traverseCanvas(t.placeholderCanvas)),t.accompanyingCanvas&&(t.accompanyingCanvas=this.traverseCanvas(t.accompanyingCanvas)),t}traverseAnnotation(t,n){return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(this.traverseDescriptive(t))),{parent:n},this.traversals.annotation)}traverseContentResourceLinking(t){return typeof t=="string"||!t||t&&t.service&&(t.service=P(t.service||[]).map(n=>this.traverseService(n,t))),t}traverseContentResource(t,n){return t.type==="Choice"&&(t.items=t.items.map(i=>this.traverseContentResource(i,t))),h(t)?this.traverseSpecificResource(t,"ContentResource"):this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(t)),{parent:n},this.traversals.contentResource)}traverseSpecificResource(t,n,i){let r=t.source;return typeof t.source=="string"&&(r={id:t.source,type:n||"unknown"}),this.traverseType({...t,source:n==="Canvas"||r.type==="Canvas"?this.traverseType(r,{parent:i},this.traversals.canvas):n==="ContentResource"?this.traverseContentResource(r,{parent:i}):this.traverseUnknown(r,{parent:i,typeHint:n})},{parent:i},this.traversals.specificResource)}traverseRangeRanges(t){return t.items&&(t.items=t.items.map(n=>typeof n=="string"?this.traverseCanvas({id:n,type:"Canvas"},t):h(n)?this.traverseSpecificResource(n,"Canvas",t):n.type==="Manifest"?this.traverseManifest(n,t):this.traverseRange(n,t))),t}traverseRange(t,n){return this.traverseType(this._traverseRange(t),{parent:n},this.traversals.range)}traverseAgent(t,n){return this.traverseType(this.traverseDescriptive(this.traverseLinking(t)),{parent:n},this.traversals.agent)}traverseType(t,n,i){return i.reduce((r,a)=>{let o=a(r,n);return typeof o>"u"&&!this.options.allowUndefinedReturn?r:o},t)}traverseService(t,n){let i=Object.assign({},t);return i&&i.service&&(i.service=P(i.service).map(r=>this.traverseService(r))),this.traverseType(i,{parent:n},this.traversals.service)}traverseUnknown(t,{parent:n,typeHint:i}={}){let r=ye(t,i);switch(r){case"Collection":return this.traverseCollection(t,n);case"Manifest":return this.traverseManifest(t,n);case"Canvas":return this.traverseCanvas(t,n);case"AnnotationPage":return this.traverseAnnotationPage(t,n);case"Annotation":return this.traverseAnnotation(t,n);case"ContentResource":return this.traverseContentResource(t,n);case"Range":return this.traverseRange(t,n);case"Service":return this.traverseService(t,n);case"Agent":return this.traverseAgent(t,n);default:throw new Error(`Unknown or unsupported resource type of ${r}`)}}};var he=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function st(e){if(typeof e>"u"||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"){let t=he.indexOf(e["@type"]);if(t!==-1)return he[t]}if(e.profile)return"Service";if(e.format||e["@type"])return"ContentResource";throw new Error("Resource type is not known")}var K=class e{constructor(t,n={}){m(this,"traversals");m(this,"options");this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...t},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...n}}static all(t){return new e({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){let n=[...(t.manifests||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i),...(t.collections||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i),...t.members||[]];delete t.collections,delete t.manifests,t.members=n}return t.manifests&&(t.manifests=t.manifests.map(n=>this.traverseManifest(typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n))),t.collections&&(t.collections=t.collections.map(n=>this.traverseCollection(typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n))),t.members&&(t.members=t.members.map(n=>typeof n=="string"?n:this.traverseUnknown(n))),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(n=>this.traverseSequence(n))),t.structures&&(t.structures=t.structures.map(n=>this.traverseRange(n))),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(n=>this.traverseCanvas(n))),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(n=>this.traverseAnnotation(n))),t.otherContent&&(t.otherContent=t.otherContent.map(n=>this.traverseAnnotationList(n))),t}traverseRange(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(t))),this.traversals.range)}traverseRangeItems(t){if(this.options.mergeMemberProperties){let n=[...(t.ranges||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Range"}:i),...(t.canvases||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Canvas"}:i),...t.members||[]];delete t.ranges,delete t.canvases,t.members=n.length?n.map(i=>this.traverseUnknown(i)):void 0}return t}traverseAnnotationList(t){let n=typeof t=="string"?{"@id":t,"@type":"sc:AnnotationList"}:t;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(n)),this.traversals.annotationList)}traverseAnnotationListItems(t){return t.resources&&(t.resources=t.resources.map(n=>this.traverseAnnotation(n))),t}traverseAnnotation(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(t))),this.traversals.annotation)}traverseAnnotationItems(t){return t.resource&&(Array.isArray(t.resource)?t.resource=t.resource.map(n=>this.traverseContentResource(n)):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(n=>this.traverseAnnotationList(n))),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(n=>this.traverseContentResource(n))),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(st(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"sc: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){let n=Array.isArray(t),i=Array.isArray(t)?t:[t],r=[];for(let a of i)typeof a=="string"?r.push(this.traverseContentResource({"@id":a,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(a));return!n&&!this.options.convertPropsToArray?r[0]:r}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=this.traverseImageResource(t.thumbnail)),t.logo&&(t.logo=this.traverseImageResource(t.logo)),t}traverseOneOrMoreServices(t){let n=Array.isArray(t),i=Array.isArray(t)?t:[t],r=[];for(let a of i)r.push(this.traverseService(a));return!n&&!this.options.convertPropsToArray?r[0]:r}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,n){if(!Array.isArray(t))if(this.options.convertPropsToArray)t=[t];else return this.traverseType(t,n);return t.map(i=>this.traverseType(i,n))}traverseType(t,n){return n.reduce((i,r)=>{let a=r(i);return typeof a>"u"&&!this.options.allowUndefinedReturn?i:a},t)}};var ot="http://library.stanford.edu/iiif/image-api/compliance.html#level0",me="http://library.stanford.edu/iiif/image-api/compliance.html#level1",ge="http://library.stanford.edu/iiif/image-api/compliance.html#level2",ct="http://library.stanford.edu/iiif/image-api/conformance.html#level0",Ce="http://library.stanford.edu/iiif/image-api/conformance.html#level1",Ae="http://library.stanford.edu/iiif/image-api/conformance.html#level2",lt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Re="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Te="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",pt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Se="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Pe="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",ft="http://iiif.io/api/image/1/level0.json",ut="http://iiif.io/api/image/1/profiles/level0.json",Ie="http://iiif.io/api/image/1/level1.json",xe="http://iiif.io/api/image/1/profiles/level1.json",be="http://iiif.io/api/image/1/level2.json",_e="http://iiif.io/api/image/1/profiles/level2.json",dt="http://iiif.io/api/image/2/level0.json",vt="http://iiif.io/api/image/2/profiles/level0.json",Ee="http://iiif.io/api/image/2/level1.json",Me="http://iiif.io/api/image/2/profiles/level1.json",Le="http://iiif.io/api/image/2/level2.json",we="http://iiif.io/api/image/2/profiles/level2.json",yt="level0",Ne="level1",Oe="level2",ht="http://iiif.io/api/image/2/level0",ze="http://iiif.io/api/image/2/level1",ke="http://iiif.io/api/image/2/level2",Fe=[ze,ke,me,ge,Ce,Ae,Re,Te,Se,Pe,Ie,xe,be,_e,Ee,Me,Le,we,Ne,Oe],De=[ht,ze,ke,ot,me,ge,ct,Ce,Ae,lt,Re,Te,pt,Se,Pe,ft,ut,Ie,xe,be,_e,dt,vt,Ee,Me,Le,we,yt,Ne,Oe];function g(e){for(let t in e)(typeof e[t]>"u"||e[t]===null)&&delete e[t];return e}var ce={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function mt(e){if(typeof e=="string")return[e];if(!e)return[];let t=Array.isArray(e)?e:[e],n=[];for(let i of t){if(typeof i=="string"){n.push(i);continue}n.push({"@language":i["@language"]||i.language,"@value":i["@value"]||i.value})}return n}function N(e,t="none"){if(!e)return{};let n=mt(e),i={};for(let r of n){if(typeof r=="string"){i[t]=i[t]?i[t]:[],i[t].push(r||"");continue}if(!r["@language"]){i[t]=i[t]?i[t]:[],i[t].push(r["@value"]||"");continue}let a=r["@language"];i[a]=i[a]?i[a]:[],i[a].push(r["@value"]||"")}return i}function Ue(e){if(Array.isArray(e))return Ue(e.find(t=>typeof t=="string"));if(De.indexOf(e)!==-1)return"level2";if(Fe.indexOf(e)!==-1)return"level1";if(typeof e=="string")return e}function gt(e){let t=Array.isArray(e)?e:[e];for(let n of t)switch(n){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 Ct(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 je(e){for(let t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}var At=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function fe(e){let t=e["@id"]||e.id,n=e["@type"]||e.type,i=e.profile||void 0,r=e["@context"]||void 0;if(i){let a=Ct(i);if(a)return a}if(r){let a=gt(r);if(a)return a}if(n){if(Array.isArray(n)){if(n.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(n.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";n=n[0]}for(let a of["sc","oa","dcterms","dctypes","iiif"])if(n.startsWith(`${a}:`)){n=n.slice(a.length+1);break}switch(n){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(n&&At.indexOf(n)!==-1)return n;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":n||"unknown"}var Rt=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Tt(e){let t=e.match(Rt);return t?t[0]:e}function St(e,t="Rights/License",n="none"){let i=null,r=[],a=Array.isArray(e)?e:[e];for(let o of a){let c=o?Tt(o):void 0;if(c&&(c.indexOf("creativecommons.org")!==-1||c.indexOf("rightsstatements.org")!==-1)){c.startsWith("https://")?i=`http://${c.slice(8)}`:i=c;continue}c&&r.push({label:{[n]:[t]},value:{[n]:[c]}})}return[i,r]}var 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 It(e){if(e){let t=Array.isArray(e)?e:[e],n=[];for(let i of t)i==="http://iiif.io/api/presentation/2/context.json"&&n.push("http://iiif.io/api/presentation/3/context.json"),Pt.indexOf(i)===-1&&n.push(i);if(t.length)return n.length===1?n[0]:n}}function xt(e){return e?e.map(t=>({label:N(t.label),value:N(t.value)})):[]}var qe=0;function Ge(e,t){let n=encodeURI(e.id||e["@id"]||"").trim();return n&&t?`${n}/${t}`:n||(qe++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${qe}`)}function R(e){let t=[...e.behavior||[]];e.viewingHint&&t.push(e.viewingHint);let n;return Array.isArray(e.motivation)?n=e.motivation.map(je):e.motivation&&(n=je(e.motivation)),{"@context":e["@context"]?It(e["@context"]):void 0,id:(e["@id"]||Ge(e)).trim(),type:fe(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:n,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function T(e){let[t,n]=St(e.license),i=[...e.metadata?xt(e.metadata):[],...n];return{rights:t,metadata:i.length?i:void 0,label:e.label?N(e.label):void 0,requiredStatement:e.attribution?{label:N(ce.attributionLabel),value:N(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?N(e.description):void 0,thumbnail:bt(e.thumbnail)}}function bt(e){return e&&(Array.isArray(e)?e:[e]).map(n=>typeof n=="string"?{id:n,type:"Image"}:(n.type==="unknown"&&(n.type="Image"),n))}function _t(e){if(!e.within)return;let t=Array.isArray(e.within)?e.within:[e.within],n=[];for(let i of t)if(typeof i=="string"){if(i)switch(e["@type"]){case"sc:Manifest":n.push({id:i,type:"Collection"});break}}else i["@id"]&&n.push({id:i["@id"],type:fe(i)});return n.length?n:void 0}function I(e){let t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],n=e.contentLayer;return{provider:e.logo||t.length?[{id:ce.providerId,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:N(ce.providerName)}]:void 0,partOf:_t(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?P(e.service):void 0,supplementary:n?[n]:void 0}}function Et(e){return{chars:e.chars,format:e.format?e.format:void 0,language:e.language}}function Mt(e){return g({...R(e),...T(e),...I(e),items:e.members})}function Lt(e){let t=[],n=[],i;for(let a of e.sequences||[])a.canvases.length&&t.push(...a.canvases),a.behavior&&n.push(...a.behavior),a.startCanvas&&(i=a.startCanvas);let r=R(e);return n.length&&(r.behavior?r.behavior.push(...n):r.behavior=n),g({...r,...T(e),...I(e),start:i,items:t,structures:e.structures})}function wt(e){return g({...R(e),...T(e),...I(e),annotations:e.otherContent&&e.otherContent.length?e.otherContent:void 0,items:e.images&&e.images.length?[{id:Ge(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}function Nt(e){return g({...R(e),...T(e),...I(e),items:e.resources&&e.resources.length?e.resources:void 0})}function Ot(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}}function zt(e){function t(n){if(Array.isArray(n)){if(n.length>1)return{type:"List",items:n.map(t)};n=n[0]}if(typeof n=="string")return encodeURI(n).trim();if("@type"in n){let i;if(typeof n.full=="string")i=n.full;else if(n.full["@type"]==="dctypes:Image")i={id:n.full["@id"],type:"Image"};else if(n.full["@type"]==="sc:Canvas")i={id:n.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${n.full["@type"]}`);return{type:"SpecificResource",source:i,selector:pe(n.selector)}}else return encodeURI(n["@id"]).trim()}return g({...R(e),...T(e),...I(e),target:t(e.on),body:Array.isArray(e.resource)?e.resource.map(le):le(e.resource)})}function le(e){let t=e;return g({...R(t),...T(t),...I(t),...Et(t)})}function kt(e){let t=[];return e.default&&e.default!=="rdf:nil"&&t.push(e.default),e.item&&e.item!=="rdf:nil"&&t.push(...e.item),{...R(e),...T(e),items:t}}function Ft(e){return g({...R(e),...T(e),...I(e),items:e.members})}function Dt(e){let{"@id":t,"@type":n,"@context":i,profile:r,...a}=e,o={};return t&&(o["@id"]=t),o["@type"]=fe(e),o["@type"]==="unknown"&&(i&&i.length&&(o["@context"]=i),o["@type"]="Service"),r&&(o.profile=Ue(r)),g({...o,...a})}function jt(e){return g({...R(e),...T(e),...I(e)})}var qt=new K({collection:[Mt],manifest:[Lt],canvas:[wt],annotationList:[Nt],sequence:[Ot],annotation:[zt],contentResource:[le],choice:[kt],range:[Ft],service:[Dt],layer:[jt]});function $e(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"?qt.traverseUnknown(e):e}function pe(e){if((Array.isArray(e["@type"])&&e["@type"].includes("oa:SvgSelector")||e["@type"]=="oa:SvgSelector")&&("chars"in e||"value"in e))return{type:"SvgSelector",value:"chars"in e?e.chars:e.value};if(e["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:e.value};if(e["@type"]==="oa:Choice")return[pe(e.default),...(Array.isArray(e.item)?e.item:[e.item]).map(pe)];if(e["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in e?e.region:void 0,rotation:"rotation"in e?e.rotation:void 0};throw new Error(`Unsupported selector type: ${e["@type"]}`)}function X(e,t={}){if(Array.isArray(e))return X(e[0]);if(typeof e=="string"){let[n,i]=e.split("#");return i?{type:"SpecificResource",source:{id:n,type:t.typeHint||"Unknown"},selector:{type:"FragmentSelector",value:i}}:{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||t.typeHint||"Unknown"}}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return X(e.items[0]);if(e.type==="SpecificResource")return e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]),e.selector?{type:"SpecificResource",source:e.source,selector:e.selector}:{type:"SpecificResource",source:e.source};if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);let[n,i]=e.id.split("#");return i?{type:"SpecificResource",source:{...e,id:n},selector:{type:"FragmentSelector",value:i}}:{type:"SpecificResource",source:{...e,id:n}}}return{type:"SpecificResource",source:e}}var Ut={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}};function We(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}function Ve(e,t){if(typeof e=="string")return{id:e,type:t};if(!e.id)throw new Error(`Invalid resource does not have an ID (${JSON.stringify(e)}, ${t})`);return e}function Gt(e,t){return(n,i)=>{let r=e[n]?e[n]:{};return(a,o)=>{let c=Ve(a,i||n);return c&&c.id&&n?(r[c.id]=r[c.id]?Q(r[c.id],c,{parent:o.parent,isTopLevel:t.id===c.id}):Q({id:c.id,type:c.type},c,{parent:o.parent,isTopLevel:t.id===c.id}),{id:c.id,type:n==="ContentResource"?n:c.type}):c}}}function J(e,t,n){if(!t)return e;if(Array.isArray(e)){if(!Array.isArray(t))throw new Error("Cannot merge array with non-array");let i=[...e];for(let r of t)if(r["@id"]&&!r.id&&(r.id=r["@id"]),r["@type"]&&!r.type&&(r.type=r["@type"]),r!=null)if(Array.isArray(r))i.push(r);else if(typeof r=="object"&&r.id&&r.type){let a=i.findIndex(o=>o.id===r.id&&o.type===r.type);a>=0&&(i[a]=J(i[a],r))}else e.indexOf(r)===-1&&i.push(r);return i}else if(typeof e=="object"){if(Array.isArray(t)||typeof t!="object")throw new Error("Cannot merge object with non-object");let i={...e},r=[],a=[],o=Object.keys(e).filter(l=>l!==u&&l!=="id"&&l!=="type"),c={},M={};for(let[l,f]of Object.entries(t)){if(l===u||l==="id"||l==="type")continue;let v=i[l];v===f?a.push(l):v===s||!v?(r.push(l),i[l]=f):(v&&f&&(c[l]=v,M[l]=f),i[l]=J(v,f),i[l]===c[l]&&(a.push(l),delete c[l]))}if(n&&(n.parent&&n.parent.id||n.isTopLevel)){let l=[],f={};if(n.parent?f[A]=n.parent.id:n.isTopLevel&&(f[A]=e.id),i[u]&&i[u].length){let v=!(i[u]||[]).find(C=>C["@explicit"]),L=r.length>0||a.length!==o.length;if(v&&L)for(let C of i[u]){let d={...C},Z=Object.keys(c);if(d){d["@explicit"]=!0;for(let j of o)j!==u&&(d[j]=w);for(let j of Z)d[j]=c[j]}l.push(d)}else l.push(...i[u]);if(L){let C=Object.keys(M);f["@explicit"]=!0;for(let d of r)f[d]=w;for(let d of a)f[d]=w;for(let d of C)f[d]=M[d]}}f.id=i.id,f.type=i.type,l.push(f),i[u]=l}return i}else if(e)return e;return t}function Q(e,t,n){if(typeof e=="string")return e;if(t.id!==e.id||t.type!==e.type){if(t.type==="ImageService3")return t;if(e.type==="ImageService3")return e;throw new Error(`Can only merge entities with identical identifiers and type! ${t.type}(${t.id}) => ${e.type}(${e.id})`)}return J({...e},t,n)}function $t(e){return(t,n)=>i=>{let{id:r,type:a}=Ve(i,n||t);if(typeof r>"u")throw new Error("Found invalid entity without an ID.");return t==="ContentResource"||t==="Service"?e[r]=t:e[r]=a,i}}function Wt(e){let t=Object.assign({},e);if(t["@id"]&&(t.id=t["@id"]),t["@type"]&&(t.type=t["@type"]),t.service){let n=[];t.service=Array.isArray(t.service)?t.service:[t.service];for(let i of t.service)n.push({id:i["@id"]||i.id,type:i["@type"]||i.type});t.service=n}return Object.assign({},se,t)}function Vt(e){return t=>{e.Service=e.Service?e.Service:{};let n=t.id||t["@id"],i=Wt(t);return i&&i.id&&(e.Service[i.id]?e.Service[n]=Q(e.Service[n],i):e.Service[n]=i),t}}function Ht(e){let t=JSON.stringify(e),n=5381,i=t.length;for(;i;)n=n*33^t.charCodeAt(--i);let a=(n>>>0).toString(16);return a.length%2?"0"+a:a}function ue(e){return t=>typeof t=="string"?{id:t,type:e}:t.id?t.type?t:{type:e,...t}:{id:`vault://${Ht(t)}`,type:e,...t}}function D(e){return t=>({...e,...t})}function $(e){return Array.isArray(e)?e:[e]}function Bt(e){return e.body&&(e.body=$(e.body)),e.seeAlso&&(e.seeAlso=$(e.seeAlso)),e.audience&&(e.audience=$(e.audience)),e.accessibility&&(e.accessibility=$(e.accessibility)),e.motivation&&(e.motivation=$(e.motivation)),e}function He(e,{typeHint:t,partOfTypeHint:n}={}){if(typeof e=="string"&&(e={id:e,type:t||"unknown"}),h(e))return typeof e.source=="string"&&(e.source={id:e.source,type:t||"unknown"}),e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:n||"Manifest"}]),e;let i;if((e.id||"").indexOf("#")!==-1){let[r,a]=(e.id||"").split("#");e.id=r,a&&(i={type:"FragmentSelector",value:a})}return{type:"SpecificResource",source:e,selector:i}}function Kt(e){let t=Object.assign({},e);return e&&e.items&&(t.items=e.items.map(n=>typeof n=="string"||n.type==="Canvas"?He(n):n)),t}function Xt(e){let t=Object.assign({},e);return t.start?(t.start=He(t.start,{typeHint:"Canvas"}),t):e}function Yt(e){let t=Object.assign({},e);return t.target?(t.target=X(t.target,{typeHint:"Canvas"}),t):e}function Be(e){return e}function Y(e){return typeof e.items>"u"&&(e[S]=!0),e}function Jt(e){let t=$e(e),n=We(),i={},r=Gt(n,t),a=$t(i),c=new G({collection:[Y,D(ne),a("Collection"),r("Collection")],manifest:[Y,D(ie),Xt,a("Manifest"),r("Manifest")],canvas:[D(te),a("Canvas"),r("Canvas")],annotationPage:[Y,ue("AnnotationPage"),D(ee),a("AnnotationPage"),r("AnnotationPage")],annotation:[ue("Annotation"),Bt,Yt,a("Annotation"),r("Annotation")],contentResource:[ue("ContentResource"),a("ContentResource"),r("ContentResource")],range:[D(re),Kt,a("Range","Canvas"),r("Range","Canvas")],agent:[D(ae),a("Agent"),r("Agent")],specificResource:[Be],service:[Vt(n)]}).traverseUnknown(t);return{entities:n,resource:c,mapping:i}}function Ke(e){let t={};for(let[n,i]of e){if(n===q&&i!==y)return i;i!==y&&typeof i<"u"&&i!==null&&(t[n]=i)}return t}function Qt(e,t,n){if(!t.type||!t.id)throw new Error("Unknown entity");if(!n[t.type])throw new Error(`Serializer not found for ${t.type}`);function i(r,a,o=0){let c=n[r.type];if(!c)return y;if(o>20)throw new Error("Circular reference: "+r.id+" "+r.type);let[M,l]=B(e,r.type?r:r.id,a)||(r.id&&r.type?r:null);if(!M)return y;let f=c(M,e,{parent:a,isTopLevel:t.id===r.id,fullResource:l}),v=f.next();for(;!v.done;){let L=v.value,C=y;if(L)if(Array.isArray(L)){let d=[];for(let Z of L)d.push(i(Z,r,o+1));C=d}else C=i(L,r,o+1);v=f.next(C)}return v.value===y?y:Ke(v.value)}return i(t)}function x(e,{allowSourceString:t=!0,allowString:n=!1,allowedStringType:i}={}){let r=a=>{if(t&&a&&a.source&&typeof a.source!="string"){let o=Object.keys(a.source);if(a.source.id&&a.source.type&&o.length===2)return{...a,source:a.source.id}}return a};if(e){if(e.source&&e.source.partOf)return r(e);let a=Object.keys(e);if(a.length===2&&e.type&&e.source||a.length===3&&e.type&&e.source&&a.indexOf("selector")!==-1&&!e.selector)return n&&(!i||i===e.source.type)?e.source.id:e.source.type==="ContentResource"?{type:"SpecificResource",source:e.source.id}:e.source;if(e.selector&&!Array.isArray(e.selector)&&typeof e.selector!="string"&&e.selector.type==="FragmentSelector"){let o=`${e.source.id}#${e.selector.value}`;return n?o:{id:o,type:e.source.type}}}return r(e)}function k(e){if(!e)return;let t=Object.keys(e);if(t.length!==0){if(t.length===1){let n=t[0];if(!n)return"";let i=(e[n]||[]).join("");return n==="@none"||n==="none"||n==="en"?i:{"@language":n,"@value":i}}return t.map(n=>({"@language":n,"@value":(e[n]||[]).join("")}))}}function Xe(e){return Array.isArray(e)?e.map(t=>Xe(t)):typeof e=="string"?e:e.type&&e.type==="Canvas"?e.id:e}function b(e,t=!1){if(e)return e.length>1&&!t?e:e[0]||void 0}function Zt(e){if(e){if(typeof e=="string")return{"@id":e};if("@id"in e){let t={...e};return delete t["@type"],t}return{"@context":"http://iiif.io/api/image/2/context.json","@id":e.id,profile:`http://iiif.io/api/image/2/profiles/${e.profile}.json`}}}function O(e,t){return[["@id",e.id],["@type",t],["format",e.format],["height",e.height],["width",e.width],["viewingDirection",e.viewingDirection!=="left-to-right"?e.viewingDirection:void 0],["license",e.license?e.license:void 0]]}function*z(e){let t=e.provider?yield e.provider[0]:void 0;return[["label",k(e.label)],["metadata",e.metadata&&e.metadata.length?e.metadata.map(n=>({label:k(n.label)||"",value:k(n.value)||""})):void 0],["description",k(e.summary)],["thumbnail",b(yield e.thumbnail)],["navDate",e.navDate],["logo",t?b(t.logo):void 0],["homepage",t?t.homepage:void 0],["attribution",e.requiredStatement?k(e.requiredStatement.value):void 0]]}function*W(e){let t=e.start&&e.start.type&&e.start.type==="SpecificResource"?x(e.start):e.start;return[["seeAlso",b(yield e.seeAlso)],["service",b((e.service||[]).map(Zt))],["rendering",b(yield e.rendering)],["startCanvas",t?t.id:void 0]]}function en(e){return e.type==="SpecificResource"}function tn(e){return e&&e.type==="FragmentSelector"}function nn(e){if(e&&en(e)){let t=e.id,n=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return tn(n)&&(t+="#"+n.value),t}return e?.id}var rn={Manifest:function*(e,t,{isTopLevel:n}){return[...n?[["@context","http://iiif.io/api/presentation/2/context.json"]]:[],...O(e,"sc:Manifest"),...yield*z(e),...yield*W(e),["sequences",[{"@id":`${e.id}/sequence0`,"@type":"sc:Sequence",canvases:yield e.items}]],["structures",yield e.structures]]},Canvas:function*(e){let n=(yield e.items)[0];return[...O(e,"sc:Canvas"),...yield*z(e),...yield*W(e),["images",n?[n.resources]:void 0],["annotations",e.annotations&&e.annotations.length?b(yield e.annotations):void 0]]},AnnotationPage:function*(e){return[...O(e,"sc:AnnotationList"),...yield*z(e),["resources",e.items&&e.items.length?b(yield e.items):void 0]]},Annotation:function*(e){return[["@id",e.id],["@type","oa:Annotation"],["motivation","sc:painting"],["on",Xe(e.target)],["resource",b(yield e.body,!0)]]},ContentResource:function*(e){switch(e.type){case"Image":return[...O(e,"dctypes:Image"),...yield*z(e),...yield*W(e)];case"Text":case"Dataset":default:return[...O(e,void 0),...yield*z(e)]}},AnnotationCollection:function*(e){return[["@id",e.id],["@type","sc:Layer"],["label",k(e.label)]]},Collection:function*(e){return[...O(e,"sc:Collection"),...yield*z(e),...yield*W(e),["members",yield*e.items]]},Range:function*(e){let t=[],n=[];if(e.items)for(let i of e.items){let r=i.type==="SpecificResource"?i.source:i;if(r){let a=yield r;t.push({"@id":nn(i),"@type":r.type,label:a?a.label:void 0,within:e.id}),r.type==="Canvas"&&n.push(r.id)}}return[...O(e,"sc:Range"),...yield*z(e),...yield*W(e),["canvases",n.length===t.length?n:void 0],["members",n.length!==t.length?t:void 0]]}};function F(e){return[["id",e.id?.startsWith("vault://")?void 0:e.id],["type",e.type],["format",e.format],["profile",e.profile],["height",e.height||void 0],["width",e.width||void 0],["duration",e.duration||void 0],["viewingDirection",e.viewingDirection!=="left-to-right"?e.viewingDirection:void 0],["behavior",e.behavior&&e.behavior.length?e.behavior:void 0],["timeMode",e.timeMode],["motivation",Array.isArray(e.motivation)?e.motivation[0]:e.motivation],[u,y]]}function p(e){if(e===y||!e||e.length===0)return;let t=e.filter(n=>n!==y);if(t.length!==0)return t}function Je(e){if(e&&e.type&&e.type==="ImageService2"){let{id:t,type:n,profile:i,...r}=e,a=typeof i=="string"?i:Array.isArray(i)?i.find(o=>typeof o=="string"):"";return{"@id":t,"@type":n,profile:a?a.startsWith("http")?a:`http://iiif.io/api/image/2/${a}.json`:"http://iiif.io/api/image/2/level0.json",...r}}return e}function Ye(e){if(Array.isArray(e)||(e=e?[e]:[]),!(!e||e.length===0))return e.map(Je)}function*_(e){return[["label",e.label],["metadata",p(e.metadata)],["summary",e.summary],["requiredStatement",e.requiredStatement],["rights",Array.isArray(e.rights)?e.rights[0]||void 0:e.rights||void 0],["navDate",e.navDate],["language",e.language],["thumbnail",p(yield e.thumbnail)],["placeholderCanvas",yield e.placeholderCanvas],["accompanyingCanvas",yield e.accompanyingCanvas],["provider",p(yield e.provider)]]}function*E(e){return[["seeAlso",p(yield e.seeAlso)],["service",p(Ye(e.service))],["services",p(Ye(e.services))],["rendering",p(yield e.rendering)],["supplementary",p(yield e.supplementary)],["homepage",p(yield e.homepage)],["logo",p(yield e.logo)],["partOf",p(yield e.partOf)],["start",e.start?x(e.start):e.start]]}var an={Manifest:function*(e,t,{isTopLevel:n}){return n?[["@context",e["@context"]?e["@context"]:"http://iiif.io/api/presentation/3/context.json"],...F(e),...yield*_(e),...yield*E(e),["items",yield e.items],["structures",p(yield e.structures)],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]:[...F(e),...yield*_(e)]},Canvas:function*(e){return[...F(e),...yield*_(e),...yield*E(e),["items",yield e.items],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]},Agent:function*(e){return[["id",e.id],["type","Agent"],["label",e.label],...yield*E(e)]},AnnotationPage:function*(e){let t=Object.entries(e).map(([i,r])=>[i,Array.isArray(r)?p(r):r]).filter(([i,r])=>i!=="items"&&i!=="id"&&i!==u&&i!==A&&i!==S),n=yield e.items;return[["id",e.id?.startsWith("vault://")?void 0:e.id],...t,...yield*E(e),["items",n.length||e[S]===!1?n:y]]},Service:function*(e){return[[q,Je(e)]]},Annotation:function*(e){let t=Object.entries(e).map(([i,r])=>i==="motivation"?[i,Array.isArray(r)?r[0]:r]:i==="target"?[i,x(r,{allowString:!0,allowSourceString:!0,allowedStringType:"Canvas"})]:[i,Array.isArray(r)?p(r):r]).filter(([i])=>i!=="body"&&i!==u&&i!==S),n;if(Array.isArray(e.body)){let i=[];for(let r of e.body)if(r&&h(r)){let a={...r};a.source=yield r.source,i.push(x(a,{allowSourceString:!0}))}else i.push(yield r);n=i}else e.body&&h(e.body)?(n={...e.body},n.source=yield e.body.source):n=yield e.body;return[...t,...yield*_(e),...yield*E(e),["body",n.length===1?n[0]:n]]},ContentResource:function*(e){return sn([...F(e),...yield*_(e),...yield*E(e),["annotations",p(yield e.annotations)],["items",p(yield e.items)]],e)},AnnotationCollection:function*(e){return[["id",e.id],["type","AnnotationCollection"],["label",e.label]]},Collection:function*(e,t,{isTopLevel:n}){return n?[["@context","http://iiif.io/api/presentation/3/context.json"],...F(e),...yield*_(e),...yield*E(e),["items",p(yield e.items)],["navPlace",e.navPlace]]:[...F(e),...yield*_(e)]},Range:function*(e){let t=[];for(let n of e.items)n.type==="Range"?t.push(yield n):n&&n.type==="SpecificResource"?t.push(x(n)):t.push(n);return[...F(e),...yield*_(e),...yield*E(e),["items",t],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]}};function sn(e,t){let n=Object.keys(t),i=e.map(([r])=>r);for(let r of n)r===u||r===S||i.indexOf(r)===-1&&typeof t[r]<"u"&&e.push([r,t[r]]);return e}return rt(on);})();
"use strict";var IIIFParser=(()=>{var B=Object.defineProperty;var et=Object.getOwnPropertyDescriptor;var tt=Object.getOwnPropertyNames;var nt=Object.prototype.hasOwnProperty;var it=(e,t,n)=>t in e?B(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var rt=(e,t)=>{for(var n in t)B(e,n,{get:t[n],enumerable:!0})},at=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of tt(t))!nt.call(e,r)&&r!==n&&B(e,r,{get:()=>t[r],enumerable:!(i=et(t,r))||i.enumerable});return e};var st=e=>at(B({},"__esModule",{value:!0}),e);var g=(e,t,n)=>(it(e,typeof t!="symbol"?t+"":t,n),n);var Mn={};rt(Mn,{EMPTY:()=>s,HAS_PART:()=>u,IS_EXTERNAL:()=>T,PART_OF:()=>C,Traverse:()=>q,UNSET:()=>y,UNWRAP:()=>G,WILDCARD:()=>N,addFlagForExternalResource:()=>Q,compressSpecificResource:()=>_,defaultEntities:()=>fn,emptyAgent:()=>ae,emptyAnnotation:()=>ot,emptyAnnotationPage:()=>ee,emptyCanvas:()=>te,emptyCollection:()=>ne,emptyManifest:()=>ie,emptyRange:()=>re,emptyService:()=>se,frameResource:()=>ve,getDefaultEntities:()=>$e,identifyResource:()=>ye,isSpecificResource:()=>h,isWildcard:()=>de,languageString2to3:()=>z,merge:()=>X,mergeEntities:()=>Y,normalize:()=>Rn,resolveIfExists:()=>H,serialize:()=>In,serializeConfigPresentation2:()=>xn,serializeConfigPresentation3:()=>En,serializedFieldsToObject:()=>Qe,toRef:()=>$,traverseSpecificResource:()=>Je,types:()=>oe});function h(e){return typeof e=="string"?!1:!!e&&e.type==="SpecificResource"}function $(e,t){let n=t||"unknown";if(!e)return;if(typeof e=="string")return{id:e,type:n};if(h(e))return $(e.source,t);let i=n&&n!=="unknown"?n:e.type||e["@type"],r=e.id||e["@id"];if(i&&i.indexOf(":")!==-1&&(i=i.split(":").pop()),r&&i)return{id:r,type:i}}var N={},u="iiif-parser:hasPart",C="iiif-parser:partOf",T="iiif-parser:isExternal",y="__$UNSET$__",G="__$UNWRAP$__",s=[];Object.freeze(s);Object.freeze(N);function de(e){if(e===N||Object.keys(e).length===0)return!0;for(let t in e)return!1;return!0}function ve(e,t){if(t&&t["@explicit"]){let n={},i=Object.keys(t);for(let r of i)r===C||r==="@explicit"||(de(t[r])?n[r]=e[r]:n[r]=t[r]);return n}return e}function H(e,t,n){let i=$(t);if(!i)return[void 0,void 0];let r=e.requests[i.id],a=i.type||e.mapping[i.id];if(!a||r&&r.resourceUri&&(!e.entities[a]||!e.entities[a][r.resourceUri]))return[void 0,void 0];let o=e.entities[a][r?r.resourceUri:i.id];if(i.type&&!o)return H(e,{id:i.id},n);if(o&&o[u]){let l=o[u].find(c=>n?c[C]===n.id:c[C]===o.id);return[ve(o,l),o]}return[o,o]}var ot={id:"https://iiif-parser/annotation",type:"Annotation",behavior:s,label:null,thumbnail:s,summary:null,requiredStatement:null,metadata:s,seeAlso:s,homepage:s,rendering:s,service:s,accessibility:s,audience:s,body:s,bodyValue:null,canonical:null,created:null,creator:s,generated:null,generator:s,modified:null,motivation:s,rights:null,stylesheet:null,target:s,timeMode:void 0,via:s,partOf:s},ee={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:s,label:null,thumbnail:s,summary:null,requiredStatement:null,metadata:s,rights:null,provider:s,items:s,seeAlso:s,homepage:s,rendering:s,service:s},te={id:"https://iiif-parser/empty-canvas",type:"Canvas",label:null,behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,duration:0,height:0,width:0},ne={id:"https://iiif-parser/empty-collection",type:"Collection",label:null,viewingDirection:"left-to-right",behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,services:s},ie={id:"https://iiif-parser/empty-manifest",type:"Manifest",annotations:s,behavior:s,homepage:s,items:s,label:null,metadata:s,navDate:null,provider:s,partOf:s,accompanyingCanvas:null,placeholderCanvas:null,rendering:s,requiredStatement:null,rights:null,seeAlso:s,service:s,services:s,start:null,structures:s,summary:null,thumbnail:s,viewingDirection:"left-to-right"},re={id:"https://iiif-parser/empty-canvas",type:"Range",label:null,behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,start:null,supplementary:null,viewingDirection:"left-to-right"},ae={id:"https://iiif-parser/empty-agent",type:"Agent",label:{},logo:s,seeAlso:s,homepage:s},se={id:"https://iiif-parser/empty-service",type:"UnknownService"};function S(e){return Array.isArray(e)?e:e?[e]:[]}function U(...e){return t=>e.reduce((n,i)=>i(n),t)}var oe=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function ye(e,t){if(typeof e>"u"||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"){if(t)return t;throw new Error(`${typeof e} is not a valid entity`)}if(typeof e.type=="string"){let n=oe.indexOf(e.type);if(n!==-1)return oe[n]}if(e.profile)return"Service";throw new Error("Resource type is not known")}var q=class e{constructor(t,n={}){g(this,"traversals");g(this,"options");g(this,"_traverseManifest",U(this.traverseManifestItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseManifestStructures.bind(this),this.traverseInlineAnnotationPages.bind(this)));g(this,"_traverseCanvas",U(this.traverseCanvasItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseInlineAnnotationPages.bind(this)));g(this,"_traverseAnnotationPage",U(this.traverseAnnotationPageItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this)));g(this,"_traverseRange",U(this.traverseRangeRanges.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this)));this.traversals={collection:[],manifest:[],canvas:[],annotationCollection:[],annotationPage:[],annotation:[],contentResource:[],choice:[],range:[],service:[],agent:[],specificResource:[],geoJson:[],...t},this.options={allowUndefinedReturn:!1,...n}}static all(t){return new e({collection:[t],manifest:[t],canvas:[t],annotationCollection:[t],annotationPage:[t],annotation:[t],contentResource:[t],choice:[t],range:[t],service:[t],geoJson:[t],specificResource:[t],agent:[t]})}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=S(t.thumbnail).map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.provider&&(t.provider=t.provider.map(n=>this.traverseAgent(n,t))),t}traverseLinking(t){return t.seeAlso&&(t.seeAlso=t.seeAlso.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.service&&(t.service=S(t.service).map(n=>this.traverseService(n))),t.services&&(t.services=S(t.services).map(n=>this.traverseService(n,t))),t.logo&&(t.logo=t.logo.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.homepage&&(t.homepage=t.homepage.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.partOf&&(t.partOf=t.partOf.map(n=>typeof n=="string"||!n.type?this.traverseType(n,{parent:t},this.traversals.contentResource):n.type==="Canvas"?this.traverseType(n,{parent:t},this.traversals.canvas):n.type==="AnnotationCollection"?this.traverseType(n,{parent:t},this.traversals.annotationCollection):n.type==="Collection"?this.traverseType(n,{parent:t},this.traversals.collection):this.traverseType(n,{parent:t},this.traversals.contentResource))),t.start&&(h(t.start)?t.start=this.traverseSpecificResource(t.start,"Canvas",t):t.start=this.traverseType(t.start,{parent:t},this.traversals.canvas)),t.rendering&&(t.rendering=t.rendering.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.supplementary&&(t.supplementary=t.supplementary.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t}traverseCollectionItems(t){return t.items&&t.items.map(n=>n.type==="Collection"?this.traverseCollection(n):this.traverseManifest(n)),t}traverseCollection(t,n){return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traverseLinkedCanvases(this.traverseCollectionItems(t))))),{parent:n},this.traversals.collection)}traverseGeoJson(t,n){return this.traverseType(t,{parent:n},this.traversals.geoJson)}traverseNavPlace(t){return t.navPlace&&(t.navPlace=this.traverseGeoJson(t.navPlace,t)),t}traverseManifestItems(t){return t.items&&(t.items=t.items.map(n=>this.traverseCanvas(n))),t}traverseManifestStructures(t){return t.structures&&(t.structures=t.structures.map(n=>this.traverseRange(n))),t}traverseManifest(t,n){return this.traverseType(this._traverseManifest(t),{parent:n},this.traversals.manifest)}traverseCanvasItems(t){return t.items=(t.items||[]).map(n=>this.traverseAnnotationPage(n,t)),t}traverseInlineAnnotationPages(t){return typeof t=="string"||!t||t.annotations&&(t.annotations=t.annotations.map(n=>this.traverseAnnotationPage(n,t))),t}traverseCanvas(t,n){return this.traverseType(this._traverseCanvas(t),{parent:n},this.traversals.canvas)}traverseAnnotationPageItems(t){return t.items&&(t.items=t.items.map(n=>this.traverseAnnotation(n,t))),t}traverseAnnotationPage(t,n){return this.traverseType(this._traverseAnnotationPage(t),{parent:n},this.traversals.annotationPage)}traverseAnnotationBody(t){return Array.isArray(t.body)?t.body=t.body.map(n=>this.traverseContentResource(n,t)):t.body&&(t.body=this.traverseContentResource(t.body,t)),t}traverseLinkedCanvases(t){return t.placeholderCanvas&&(t.placeholderCanvas=this.traverseCanvas(t.placeholderCanvas)),t.accompanyingCanvas&&(t.accompanyingCanvas=this.traverseCanvas(t.accompanyingCanvas)),t}traverseAnnotation(t,n){return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(this.traverseDescriptive(t))),{parent:n},this.traversals.annotation)}traverseContentResourceLinking(t){return typeof t=="string"||!t||t&&t.service&&(t.service=S(t.service||[]).map(n=>this.traverseService(n,t))),t}traverseContentResource(t,n){return t.type==="Choice"&&(t.items=t.items.map(i=>this.traverseContentResource(i,t))),h(t)?this.traverseSpecificResource(t,"ContentResource"):this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(t)),{parent:n},this.traversals.contentResource)}traverseSpecificResource(t,n,i){let r=t.source;return typeof t.source=="string"&&(r={id:t.source,type:n||"unknown"}),this.traverseType({...t,source:n==="Canvas"||r.type==="Canvas"?this.traverseType(r,{parent:i},this.traversals.canvas):n==="ContentResource"?this.traverseContentResource(r,{parent:i}):this.traverseUnknown(r,{parent:i,typeHint:n})},{parent:i},this.traversals.specificResource)}traverseRangeRanges(t){return t.items&&(t.items=t.items.map(n=>typeof n=="string"?this.traverseCanvas({id:n,type:"Canvas"},t):h(n)?this.traverseSpecificResource(n,"Canvas",t):n.type==="Manifest"?this.traverseManifest(n,t):this.traverseRange(n,t))),t}traverseRange(t,n){return this.traverseType(this._traverseRange(t),{parent:n},this.traversals.range)}traverseAgent(t,n){return this.traverseType(this.traverseDescriptive(this.traverseLinking(t)),{parent:n},this.traversals.agent)}traverseType(t,n,i){return i.reduce((r,a)=>{let o=a(r,n);return typeof o>"u"&&!this.options.allowUndefinedReturn?r:o},t)}traverseService(t,n){let i=Object.assign({},t);return i&&i.service&&(i.service=S(i.service).map(r=>this.traverseService(r))),this.traverseType(i,{parent:n},this.traversals.service)}traverseUnknown(t,{parent:n,typeHint:i}={}){let r=ye(t,i);switch(r){case"Collection":return this.traverseCollection(t,n);case"Manifest":return this.traverseManifest(t,n);case"Canvas":return this.traverseCanvas(t,n);case"AnnotationPage":return this.traverseAnnotationPage(t,n);case"Annotation":return this.traverseAnnotation(t,n);case"ContentResource":return this.traverseContentResource(t,n);case"Range":return this.traverseRange(t,n);case"Service":return this.traverseService(t,n);case"Agent":return this.traverseAgent(t,n);default:throw new Error(`Unknown or unsupported resource type of ${r}`)}}};var he=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function lt(e){if(typeof e>"u"||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"){let t=he.indexOf(e["@type"]);if(t!==-1)return he[t]}if(e.profile)return"Service";if(e.format||e["@type"])return"ContentResource";throw new Error("Resource type is not known")}var K=class e{constructor(t,n={}){g(this,"traversals");g(this,"options");this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...t},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...n}}static all(t){return new e({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){let n=[...(t.manifests||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i),...(t.collections||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i),...t.members||[]];delete t.collections,delete t.manifests,t.members=n}return t.manifests&&(t.manifests=t.manifests.map(n=>this.traverseManifest(typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n))),t.collections&&(t.collections=t.collections.map(n=>this.traverseCollection(typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n))),t.members&&(t.members=t.members.map(n=>typeof n=="string"?n:this.traverseUnknown(n))),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(n=>this.traverseSequence(n))),t.structures&&(t.structures=t.structures.map(n=>this.traverseRange(n))),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(n=>this.traverseCanvas(n))),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(n=>this.traverseAnnotation(n))),t.otherContent&&(t.otherContent=t.otherContent.map(n=>this.traverseAnnotationList(n))),t}traverseRange(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(t))),this.traversals.range)}traverseRangeItems(t){if(this.options.mergeMemberProperties){let n=[...(t.ranges||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Range"}:i),...(t.canvases||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Canvas"}:i),...t.members||[]];delete t.ranges,delete t.canvases,t.members=n.length?n.map(i=>this.traverseUnknown(i)):void 0}return t}traverseAnnotationList(t){let n=typeof t=="string"?{"@id":t,"@type":"sc:AnnotationList"}:t;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(n)),this.traversals.annotationList)}traverseAnnotationListItems(t){return t.resources&&(t.resources=t.resources.map(n=>this.traverseAnnotation(n))),t}traverseAnnotation(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(t))),this.traversals.annotation)}traverseAnnotationItems(t){return t.resource&&(Array.isArray(t.resource)?t.resource=t.resource.map(n=>this.traverseContentResource(n)):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(n=>this.traverseAnnotationList(n))),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(n=>this.traverseContentResource(n))),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(lt(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"sc: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){let n=Array.isArray(t),i=Array.isArray(t)?t:[t],r=[];for(let a of i)typeof a=="string"?r.push(this.traverseContentResource({"@id":a,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(a));return!n&&!this.options.convertPropsToArray?r[0]:r}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=this.traverseImageResource(t.thumbnail)),t.logo&&(t.logo=this.traverseImageResource(t.logo)),t}traverseOneOrMoreServices(t){let n=Array.isArray(t),i=Array.isArray(t)?t:[t],r=[];for(let a of i)r.push(this.traverseService(a));return!n&&!this.options.convertPropsToArray?r[0]:r}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,n){if(!Array.isArray(t))if(this.options.convertPropsToArray)t=[t];else return this.traverseType(t,n);return t.map(i=>this.traverseType(i,n))}traverseType(t,n){return n.reduce((i,r)=>{let a=r(i);return typeof a>"u"&&!this.options.allowUndefinedReturn?i:a},t)}};var ct="http://library.stanford.edu/iiif/image-api/compliance.html#level1",pt="http://library.stanford.edu/iiif/image-api/compliance.html#level2";var ft="http://library.stanford.edu/iiif/image-api/conformance.html#level1",ut="http://library.stanford.edu/iiif/image-api/conformance.html#level2";var dt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",vt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2";var yt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",ht="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2";var mt="http://iiif.io/api/image/1/level1.json",gt="http://iiif.io/api/image/1/profiles/level1.json",At="http://iiif.io/api/image/1/level2.json",Ct="http://iiif.io/api/image/1/profiles/level2.json";var Rt="http://iiif.io/api/image/2/level1.json",It="http://iiif.io/api/image/2/profiles/level1.json",Tt="http://iiif.io/api/image/2/level2.json",St="http://iiif.io/api/image/2/profiles/level2.json";var Pt="level1",_t="level2";var xt="http://iiif.io/api/image/2/level1",Et="http://iiif.io/api/image/2/level2",me=[xt,Et,ct,pt,ft,ut,dt,vt,yt,ht,mt,gt,At,Ct,Rt,It,Tt,St,Pt,_t];function m(e){for(let t in e)(typeof e[t]>"u"||e[t]===null)&&delete e[t];return e}var Lt="http://library.stanford.edu/iiif/image-api/compliance.html#level0",ge="http://library.stanford.edu/iiif/image-api/compliance.html#level1",Ae="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Mt="http://library.stanford.edu/iiif/image-api/conformance.html#level0",Ce="http://library.stanford.edu/iiif/image-api/conformance.html#level1",Re="http://library.stanford.edu/iiif/image-api/conformance.html#level2",bt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Ie="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Te="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Nt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Se="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Pe="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Ot="http://iiif.io/api/image/1/level0.json",Ft="http://iiif.io/api/image/1/profiles/level0.json",_e="http://iiif.io/api/image/1/level1.json",xe="http://iiif.io/api/image/1/profiles/level1.json",Ee="http://iiif.io/api/image/1/level2.json",Le="http://iiif.io/api/image/1/profiles/level2.json",wt="http://iiif.io/api/image/2/level0.json",zt="http://iiif.io/api/image/2/profiles/level0.json",Me="http://iiif.io/api/image/2/level1.json",be="http://iiif.io/api/image/2/profiles/level1.json",Ne="http://iiif.io/api/image/2/level2.json",Oe="http://iiif.io/api/image/2/profiles/level2.json",kt="level0",Fe="level1",we="level2",Dt="http://iiif.io/api/image/2/level0",ze="http://iiif.io/api/image/2/level1",ke="http://iiif.io/api/image/2/level2",le=[ke,Ae,Re,Te,Pe,Ee,Le,Ne,Oe,we],Qn=[...le,ze,ge,Ce,Ie,Se,_e,xe,Me,be,Fe],jt=[Dt,ze,ke,Lt,ge,Ae,Mt,Ce,Re,bt,Ie,Te,Nt,Se,Pe,Ot,Ft,_e,xe,Ee,Le,wt,zt,Me,be,Ne,Oe,kt,Fe,we],De=jt;var ce={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function Gt(e){if(typeof e=="string")return[e];if(!e)return[];let t=Array.isArray(e)?e:[e],n=[];for(let i of t){if(typeof i=="string"){n.push(i);continue}n.push({"@language":i["@language"]||i.language,"@value":i["@value"]||i.value})}return n}function O(e,t="none"){if(!e)return{};let n=Gt(e),i={};for(let r of n){if(typeof r=="string"){i[t]=i[t]?i[t]:[],i[t].push(r||"");continue}if(!r["@language"]){i[t]=i[t]?i[t]:[],i[t].push(r["@value"]||"");continue}let a=r["@language"];i[a]=i[a]?i[a]:[],i[a].push(r["@value"]||"")}return i}function qe(e){if(Array.isArray(e))return qe(e.find(t=>typeof t=="string"));if(le.indexOf(e)!==-1)return"level2";if(me.indexOf(e)!==-1)return"level1";if(De.indexOf(e)!==-1)return"level0";if(typeof e=="string")return e}function Ut(e){let t=Array.isArray(e)?e:[e];for(let n of t)switch(n){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 qt(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 je(e){for(let t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}var Vt=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function fe(e){let t=e["@id"]||e.id,n=e["@type"]||e.type,i=e.profile||void 0,r=e["@context"]||void 0;if(i){let a=qt(i);if(a)return a}if(r){let a=Ut(r);if(a)return a}if(n){if(Array.isArray(n)){if(n.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(n.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";n=n[0]}for(let a of["sc","oa","dcterms","dctypes","iiif"])if(n.startsWith(`${a}:`)){n=n.slice(a.length+1);break}switch(n){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(n&&Vt.indexOf(n)!==-1)return n;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":n||"unknown"}var Wt=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Bt(e){let t=e.match(Wt);return t?t[0]:e}function $t(e,t="Rights/License",n="none"){let i=null,r=[],a=Array.isArray(e)?e:[e];for(let o of a){let l=o?Bt(o):void 0;if(l&&(l.indexOf("creativecommons.org")!==-1||l.indexOf("rightsstatements.org")!==-1)){l.startsWith("https://")?i=`http://${l.slice(8)}`:i=l;continue}l&&r.push({label:{[n]:[t]},value:{[n]:[l]}})}return[i,r]}var Ht=["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 Kt(e){if(e){let t=Array.isArray(e)?e:[e],n=[];for(let i of t)i==="http://iiif.io/api/presentation/2/context.json"&&n.push("http://iiif.io/api/presentation/3/context.json"),Ht.indexOf(i)===-1&&n.push(i);if(t.length)return n.length===1?n[0]:n}}function Jt(e){return e?e.map(t=>({label:O(t.label),value:O(t.value)})):[]}var Ge=0;function Ve(e,t){let n=encodeURI(e.id||e["@id"]||"").trim();return n&&t?`${n}/${t}`:n||(Ge++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${Ge}`)}function R(e){let t=[...e.behavior||[]];e.viewingHint&&t.push(e.viewingHint);let n;return Array.isArray(e.motivation)?n=e.motivation.map(je):e.motivation&&(n=je(e.motivation)),{"@context":e["@context"]?Kt(e["@context"]):void 0,id:(e["@id"]||Ve(e)).trim(),type:fe(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:n,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function I(e){let[t,n]=$t(e.license),i=[...e.metadata?Jt(e.metadata):[],...n];return{rights:t,metadata:i.length?i:void 0,label:e.label?O(e.label):void 0,requiredStatement:e.attribution?{label:O(ce.attributionLabel),value:O(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?O(e.description):void 0,thumbnail:Qt(e.thumbnail)}}function Qt(e){return e&&(Array.isArray(e)?e:[e]).map(n=>typeof n=="string"?{id:n,type:"Image"}:(n.type==="unknown"&&(n.type="Image"),n))}function Xt(e){if(!e.within)return;let t=Array.isArray(e.within)?e.within:[e.within],n=[];for(let i of t)if(typeof i=="string"){if(i)switch(e["@type"]){case"sc:Manifest":n.push({id:i,type:"Collection"});break}}else i["@id"]&&n.push({id:i["@id"],type:fe(i)});return n.length?n:void 0}function P(e){let t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],n=e.contentLayer;return{provider:e.logo||t.length?[{id:ce.providerId,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:O(ce.providerName)}]:void 0,partOf:Xt(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?S(e.service):void 0,supplementary:n?[n]:void 0}}function Yt(e){return{chars:e.chars,format:e.format?e.format:void 0,language:e.language}}function Zt(e){return m({...R(e),...I(e),...P(e),items:e.members})}function en(e){let t=[],n=[],i;for(let a of e.sequences||[])a.canvases.length&&t.push(...a.canvases),a.behavior&&n.push(...a.behavior),a.startCanvas&&(i=a.startCanvas);let r=R(e);return n.length&&(r.behavior?r.behavior.push(...n):r.behavior=n),m({...r,...I(e),...P(e),start:i,items:t,structures:e.structures})}function tn(e){return m({...R(e),...I(e),...P(e),annotations:e.otherContent&&e.otherContent.length?e.otherContent:void 0,items:e.images&&e.images.length?[{id:Ve(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}function nn(e){return m({...R(e),...I(e),...P(e),items:e.resources&&e.resources.length?e.resources:void 0})}function rn(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}}function an(e){function t(n){if(Array.isArray(n)){if(n.length>1)return{type:"List",items:n.map(t)};n=n[0]}if(typeof n=="string")return encodeURI(n).trim();if("@type"in n){let i;if(typeof n.full=="string")i=n.full;else if(n.full["@type"]==="dctypes:Image")i={id:n.full["@id"],type:"Image"};else if(n.full["@type"]==="sc:Canvas")i={id:n.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${n.full["@type"]}`);return{type:"SpecificResource",source:i,selector:pe(n.selector)}}else return encodeURI(n["@id"]).trim()}return m({...R(e),...I(e),...P(e),target:t(e.on),body:Array.isArray(e.resource)?e.resource.map(Ue):Ue(e.resource)})}function Ue(e){return e.type==="Choice"?e:We(e)}function We(e){let t=e;return m({...R(t),...I(t),...P(t),...Yt(t)})}function sn(e){let t=[];return e.default&&e.default!=="rdf:nil"&&t.push(e.default),e.item&&e.item!=="rdf:nil"&&t.push(...e.item),m({...R(e),...I(e),items:t})}function on(e){return m({...R(e),...I(e),...P(e),items:e.members})}function ln(e){let{"@id":t,"@type":n,"@context":i,profile:r,...a}=e,o={};return t&&(o["@id"]=t),o["@type"]=fe(e),o["@type"]==="unknown"&&(i&&i.length&&(o["@context"]=i),o["@type"]="Service"),r&&(o.profile=qe(r)),m({...o,...a})}function cn(e){return m({...R(e),...I(e),...P(e)})}var pn=new K({collection:[Zt],manifest:[en],canvas:[tn],annotationList:[nn],sequence:[rn],annotation:[an],contentResource:[We],choice:[sn],range:[on],service:[ln],layer:[cn]});function Be(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"?pn.traverseUnknown(e):e}function pe(e){if((Array.isArray(e["@type"])&&e["@type"].includes("oa:SvgSelector")||e["@type"]=="oa:SvgSelector")&&("chars"in e||"value"in e))return{type:"SvgSelector",value:"chars"in e?e.chars:e.value};if(e["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:e.value};if(e["@type"]==="oa:Choice")return[pe(e.default),...(Array.isArray(e.item)?e.item:[e.item]).map(pe)];if(e["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in e?e.region:void 0,rotation:"rotation"in e?e.rotation:void 0};throw new Error(`Unsupported selector type: ${e["@type"]}`)}function J(e,t={}){if(Array.isArray(e))return J(e[0]);if(typeof e=="string"){let[n,i]=e.split("#");return i?{type:"SpecificResource",source:{id:n,type:t.typeHint||"Unknown"},selector:{type:"FragmentSelector",value:i}}:{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||t.typeHint||"Unknown"}}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return J(e.items[0]);if(e.type==="SpecificResource")return e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]),e.selector?{type:"SpecificResource",source:e.source,selector:e.selector}:{type:"SpecificResource",source:e.source};if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);let[n,i]=e.id.split("#");return i?{type:"SpecificResource",source:{...e,id:n},selector:{type:"FragmentSelector",value:i}}:{type:"SpecificResource",source:{...e,id:n}}}return{type:"SpecificResource",source:e}}var fn={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}};function $e(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}function He(e,t){if(typeof e=="string")return{id:e,type:t};if(!e.id)throw new Error(`Invalid resource does not have an ID (${JSON.stringify(e)}, ${t})`);return e}function un(e,t){return(n,i)=>{let r=e[n]?e[n]:{};return(a,o)=>{let l=He(a,i||n);return l&&l.id&&n?(r[l.id]=r[l.id]?Y(r[l.id],l,{parent:o.parent,isTopLevel:t.id===l.id}):Y({id:l.id,type:l.type},l,{parent:o.parent,isTopLevel:t.id===l.id}),{id:l.id,type:n==="ContentResource"?n:l.type}):l}}}function X(e,t,n){if(!t)return e;if(Array.isArray(e)){if(!Array.isArray(t))throw new Error("Cannot merge array with non-array");let i=[...e];for(let r of t)if(r["@id"]&&!r.id&&(r.id=r["@id"]),r["@type"]&&!r.type&&(r.type=r["@type"]),r!=null)if(Array.isArray(r))i.push(r);else if(typeof r=="object"&&r.id&&r.type){let a=i.findIndex(o=>o.id===r.id&&o.type===r.type);a>=0&&(i[a]=X(i[a],r))}else e.indexOf(r)===-1&&i.push(r);return i}else if(typeof e=="object"){if(Array.isArray(t)||typeof t!="object")throw new Error("Cannot merge object with non-object");let i={...e},r=[],a=[],o=Object.keys(e).filter(c=>c!==u&&c!=="id"&&c!=="type"),l={},M={};for(let[c,f]of Object.entries(t)){if(c===u||c==="id"||c==="type")continue;let v=i[c];v===f?a.push(c):v===s||!v?(r.push(c),i[c]=f):(v&&f&&(l[c]=v,M[c]=f),i[c]=X(v,f),i[c]===l[c]&&(a.push(c),delete l[c]))}if(n&&(n.parent&&n.parent.id||n.isTopLevel)){let c=[],f={};if(n.parent?f[C]=n.parent.id:n.isTopLevel&&(f[C]=e.id),i[u]&&i[u].length){let v=!(i[u]||[]).find(A=>A["@explicit"]),b=r.length>0||a.length!==o.length;if(v&&b)for(let A of i[u]){let d={...A},Z=Object.keys(l);if(d){d["@explicit"]=!0;for(let j of o)j!==u&&(d[j]=N);for(let j of Z)d[j]=l[j]}c.push(d)}else c.push(...i[u]);if(b){let A=Object.keys(M);f["@explicit"]=!0;for(let d of r)f[d]=N;for(let d of a)f[d]=N;for(let d of A)f[d]=M[d]}}f.id=i.id,f.type=i.type,c.push(f),i[u]=c}return i}else if(e)return e;return t}function Y(e,t,n){if(typeof e=="string")return e;if(t.id!==e.id||t.type!==e.type){if(t.type==="ImageService3")return t;if(e.type==="ImageService3")return e;throw new Error(`Can only merge entities with identical identifiers and type! ${t.type}(${t.id}) => ${e.type}(${e.id})`)}return X({...e},t,n)}function dn(e){return(t,n)=>i=>{let{id:r,type:a}=He(i,n||t);if(typeof r>"u")throw new Error("Found invalid entity without an ID.");return t==="ContentResource"||t==="Service"?e[r]=t:e[r]=a,i}}function vn(e){let t=Object.assign({},e);if(t["@id"]&&(t.id=t["@id"]),t["@type"]&&(t.type=t["@type"]),t.service){let n=[];t.service=Array.isArray(t.service)?t.service:[t.service];for(let i of t.service)n.push({id:i["@id"]||i.id,type:i["@type"]||i.type});t.service=n}return Object.assign({},se,t)}function yn(e){return t=>{e.Service=e.Service?e.Service:{};let n=t.id||t["@id"],i=vn(t);return i&&i.id&&(e.Service[i.id]?e.Service[n]=Y(e.Service[n],i):e.Service[n]=i),t}}function hn(e){let t=JSON.stringify(e),n=5381,i=t.length;for(;i;)n=n*33^t.charCodeAt(--i);let a=(n>>>0).toString(16);return a.length%2?"0"+a:a}function ue(e){return t=>typeof t=="string"?{id:t,type:e}:t.id?t.type?t:{type:e,...t}:{id:`vault://${hn(t)}`,type:e,...t}}function D(e){return t=>({...e,...t})}function V(e){return Array.isArray(e)?e:[e]}function mn(e){return e.body&&(e.body=V(e.body)),e.seeAlso&&(e.seeAlso=V(e.seeAlso)),e.audience&&(e.audience=V(e.audience)),e.accessibility&&(e.accessibility=V(e.accessibility)),e.motivation&&(e.motivation=V(e.motivation)),e}function Ke(e,{typeHint:t,partOfTypeHint:n}={}){if(typeof e=="string"&&(e={id:e,type:t||"unknown"}),h(e))return typeof e.source=="string"&&(e.source={id:e.source,type:t||"unknown"}),e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:n||"Manifest"}]),e;let i;if((e.id||"").indexOf("#")!==-1){let[r,a]=(e.id||"").split("#");e.id=r,a&&(i={type:"FragmentSelector",value:a})}return{type:"SpecificResource",source:e,selector:i}}function gn(e){let t=Object.assign({},e);return e&&e.items&&(t.items=e.items.map(n=>typeof n=="string"||n.type==="Canvas"?Ke(n):n)),t}function An(e){let t=Object.assign({},e);return t.start?(t.start=Ke(t.start,{typeHint:"Canvas"}),t):e}function Cn(e){let t=Object.assign({},e);return t.target?(t.target=J(t.target,{typeHint:"Canvas"}),t):e}function Je(e){return e}function Q(e){return typeof e.items>"u"&&(e[T]=!0),e}function Rn(e){let t=Be(e),n=$e(),i={},r=un(n,t),a=dn(i),l=new q({collection:[Q,D(ne),a("Collection"),r("Collection")],manifest:[Q,D(ie),An,a("Manifest"),r("Manifest")],canvas:[D(te),a("Canvas"),r("Canvas")],annotationPage:[Q,ue("AnnotationPage"),D(ee),a("AnnotationPage"),r("AnnotationPage")],annotation:[ue("Annotation"),mn,Cn,a("Annotation"),r("Annotation")],contentResource:[ue("ContentResource"),a("ContentResource"),r("ContentResource")],range:[D(re),gn,a("Range","Canvas"),r("Range","Canvas")],agent:[D(ae),a("Agent"),r("Agent")],specificResource:[Je],service:[yn(n)]}).traverseUnknown(t);return{entities:n,resource:l,mapping:i}}function Qe(e){let t={};for(let[n,i]of e){if(n===G&&i!==y)return i;i!==y&&typeof i<"u"&&i!==null&&(t[n]=i)}return t}function In(e,t,n){if(!t.type||!t.id)throw new Error("Unknown entity");if(!n[t.type])throw new Error(`Serializer not found for ${t.type}`);function i(r,a,o=0){let l=n[r.type];if(!l)return y;if(o>20)throw new Error("Circular reference: "+r.id+" "+r.type);let[M,c]=H(e,r.type?r:r.id,a)||(r.id&&r.type?r:null);if(!M)return y;let f=l(M,e,{parent:a,isTopLevel:t.id===r.id,fullResource:c}),v=f.next();for(;!v.done;){let b=v.value,A=y;if(b)if(Array.isArray(b)){let d=[];for(let Z of b)d.push(i(Z,r,o+1));A=d}else A=i(b,r,o+1);v=f.next(A)}return v.value===y?y:Qe(v.value)}return i(t)}function _(e,{allowSourceString:t=!0,allowString:n=!1,allowedStringType:i}={}){let r=a=>{if(t&&a&&a.source&&typeof a.source!="string"){let o=Object.keys(a.source);if(a.source.id&&a.source.type&&o.length===2)return{...a,source:a.source.id}}return a};if(e){if(e.source&&e.source.partOf)return r(e);let a=Object.keys(e);if(a.length===2&&e.type&&e.source||a.length===3&&e.type&&e.source&&a.indexOf("selector")!==-1&&!e.selector)return n&&(!i||i===e.source.type)?e.source.id:e.source.type==="ContentResource"?{type:"SpecificResource",source:e.source.id}:e.source;if(e.selector&&!Array.isArray(e.selector)&&typeof e.selector!="string"&&e.selector.type==="FragmentSelector"){let o=`${e.source.id}#${e.selector.value}`;return n?o:{id:o,type:e.source.type}}}return r(e)}function z(e){if(!e)return;let t=Object.keys(e);if(t.length!==0){if(t.length===1){let n=t[0];if(!n)return"";let i=(e[n]||[]).join("");return n==="@none"||n==="none"||n==="en"?i:{"@language":n,"@value":i}}return t.map(n=>({"@language":n,"@value":(e[n]||[]).join("")}))}}function Xe(e){return Array.isArray(e)?e.map(t=>Xe(t)):typeof e=="string"?e:e.type&&e.type==="Canvas"?e.id:e}function x(e,t=!1){if(e)return e.length>1&&!t?e:e[0]||void 0}function Tn(e){if(e){if(typeof e=="string")return{"@id":e};if("@id"in e){let t={...e};return delete t["@type"],t}return{"@context":"http://iiif.io/api/image/2/context.json","@id":e.id,profile:`http://iiif.io/api/image/2/profiles/${e.profile}.json`}}}function F(e,t){return[["@id",e.id],["@type",t],["format",e.format],["height",e.height],["width",e.width],["viewingDirection",e.viewingDirection!=="left-to-right"?e.viewingDirection:void 0],["license",e.license?e.license:void 0]]}function*w(e){let t=e.provider?yield e.provider[0]:void 0;return[["label",z(e.label)],["metadata",e.metadata&&e.metadata.length?e.metadata.map(n=>({label:z(n.label)||"",value:z(n.value)||""})):void 0],["description",z(e.summary)],["thumbnail",x(yield e.thumbnail)],["navDate",e.navDate],["logo",t?x(t.logo):void 0],["homepage",t?t.homepage:void 0],["attribution",e.requiredStatement?z(e.requiredStatement.value):void 0]]}function*W(e){let t=e.start&&e.start.type&&e.start.type==="SpecificResource"?_(e.start):e.start;return[["seeAlso",x(yield e.seeAlso)],["service",x((e.service||[]).map(Tn))],["rendering",x(yield e.rendering)],["startCanvas",t?t.id:void 0]]}function Sn(e){return e.type==="SpecificResource"}function Pn(e){return e&&e.type==="FragmentSelector"}function _n(e){if(e&&Sn(e)){let t=e.id,n=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return Pn(n)&&(t+="#"+n.value),t}return e?.id}var xn={Manifest:function*(e,t,{isTopLevel:n}){return[...n?[["@context","http://iiif.io/api/presentation/2/context.json"]]:[],...F(e,"sc:Manifest"),...yield*w(e),...yield*W(e),["sequences",[{"@id":`${e.id}/sequence0`,"@type":"sc:Sequence",canvases:yield e.items}]],["structures",yield e.structures]]},Canvas:function*(e){let n=(yield e.items)[0];return[...F(e,"sc:Canvas"),...yield*w(e),...yield*W(e),["images",n?[n.resources]:void 0],["annotations",e.annotations&&e.annotations.length?x(yield e.annotations):void 0]]},AnnotationPage:function*(e){return[...F(e,"sc:AnnotationList"),...yield*w(e),["resources",e.items&&e.items.length?x(yield e.items):void 0]]},Annotation:function*(e){return[["@id",e.id],["@type","oa:Annotation"],["motivation","sc:painting"],["on",Xe(e.target)],["resource",x(yield e.body,!0)]]},ContentResource:function*(e){switch(e.type){case"Image":return[...F(e,"dctypes:Image"),...yield*w(e),...yield*W(e)];case"Text":case"Dataset":default:return[...F(e,void 0),...yield*w(e)]}},AnnotationCollection:function*(e){return[["@id",e.id],["@type","sc:Layer"],["label",z(e.label)]]},Collection:function*(e){return[...F(e,"sc:Collection"),...yield*w(e),...yield*W(e),["members",yield*e.items]]},Range:function*(e){let t=[],n=[];if(e.items)for(let i of e.items){let r=i.type==="SpecificResource"?i.source:i;if(r){let a=yield r;t.push({"@id":_n(i),"@type":r.type,label:a?a.label:void 0,within:e.id}),r.type==="Canvas"&&n.push(r.id)}}return[...F(e,"sc:Range"),...yield*w(e),...yield*W(e),["canvases",n.length===t.length?n:void 0],["members",n.length!==t.length?t:void 0]]}};function k(e){return[["id",e.id?.startsWith("vault://")?void 0:e.id],["type",e.type],["format",e.format],["profile",e.profile],["height",e.height||void 0],["width",e.width||void 0],["duration",e.duration||void 0],["viewingDirection",e.viewingDirection!=="left-to-right"?e.viewingDirection:void 0],["behavior",e.behavior&&e.behavior.length?e.behavior:void 0],["timeMode",e.timeMode],["motivation",Array.isArray(e.motivation)?e.motivation[0]:e.motivation],[u,y]]}function p(e){if(e===y||!e||e.length===0)return;let t=e.filter(n=>n!==y);if(t.length!==0)return t}function Ze(e){if(e&&e.type&&e.type==="ImageService2"){let{id:t,type:n,profile:i,...r}=e,a=typeof i=="string"?i:Array.isArray(i)?i.find(o=>typeof o=="string"):"";return{"@id":t,"@type":n,profile:a?a.startsWith("http")?a:`http://iiif.io/api/image/2/${a}.json`:"http://iiif.io/api/image/2/level0.json",...r}}return e}function Ye(e){if(Array.isArray(e)||(e=e?[e]:[]),!(!e||e.length===0))return e.map(Ze)}function*E(e){return[["label",e.label],["metadata",p(e.metadata)],["summary",e.summary],["requiredStatement",e.requiredStatement],["rights",Array.isArray(e.rights)?e.rights[0]||void 0:e.rights||void 0],["navDate",e.navDate],["language",e.language],["thumbnail",p(yield e.thumbnail)],["placeholderCanvas",yield e.placeholderCanvas],["accompanyingCanvas",yield e.accompanyingCanvas],["provider",p(yield e.provider)]]}function*L(e){return[["seeAlso",p(yield e.seeAlso)],["service",p(Ye(e.service))],["services",p(Ye(e.services))],["rendering",p(yield e.rendering)],["supplementary",p(yield e.supplementary)],["homepage",p(yield e.homepage)],["logo",p(yield e.logo)],["partOf",p(yield e.partOf)],["start",e.start?_(e.start):e.start]]}var En={Manifest:function*(e,t,{isTopLevel:n}){return n?[["@context",e["@context"]?e["@context"]:"http://iiif.io/api/presentation/3/context.json"],...k(e),...yield*E(e),...yield*L(e),["items",yield e.items],["structures",p(yield e.structures)],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]:[...k(e),...yield*E(e)]},Canvas:function*(e){return[...k(e),...yield*E(e),...yield*L(e),["items",yield e.items],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]},Agent:function*(e){return[["id",e.id],["type","Agent"],["label",e.label],...yield*L(e)]},AnnotationPage:function*(e){let t=Object.entries(e).map(([i,r])=>[i,Array.isArray(r)?p(r):r]).filter(([i,r])=>i!=="items"&&i!=="id"&&i!==u&&i!==C&&i!==T),n=yield e.items;return[["id",e.id?.startsWith("vault://")?void 0:e.id],...t,...yield*L(e),["items",n.length||e[T]===!1?n:y]]},Service:function*(e){return[[G,Ze(e)]]},Annotation:function*(e){let t=Object.entries(e).map(([i,r])=>i==="motivation"?[i,Array.isArray(r)?r[0]:r]:i==="target"?[i,_(r,{allowString:!0,allowSourceString:!0,allowedStringType:"Canvas"})]:[i,Array.isArray(r)?p(r):r]).filter(([i])=>i!=="body"&&i!==u&&i!==T),n;if(Array.isArray(e.body)){let i=[];for(let r of e.body)if(r&&h(r)){let a={...r};a.source=yield r.source,i.push(_(a,{allowSourceString:!0}))}else i.push(yield r);n=i}else e.body&&h(e.body)?(n={...e.body},n.source=yield e.body.source):n=yield e.body;return[...t,...yield*E(e),...yield*L(e),["body",n.length===1?n[0]:n]]},ContentResource:function*(e){return Ln([...k(e),...yield*E(e),...yield*L(e),["annotations",p(yield e.annotations)],["items",p(yield e.items)]],e)},AnnotationCollection:function*(e){return[["id",e.id],["type","AnnotationCollection"],["label",e.label]]},Collection:function*(e,t,{isTopLevel:n}){return n?[["@context","http://iiif.io/api/presentation/3/context.json"],...k(e),...yield*E(e),...yield*L(e),["items",p(yield e.items)],["navPlace",e.navPlace]]:[...k(e),...yield*E(e)]},Range:function*(e){let t=[];for(let n of e.items)n.type==="Range"?t.push(yield n):n&&n.type==="SpecificResource"?t.push(_(n)):t.push(n);return[...k(e),...yield*E(e),...yield*L(e),["items",t],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]}};function Ln(e,t){let n=Object.keys(t),i=e.map(([r])=>r);for(let r of n)r===u||r===T||i.indexOf(r)===-1&&typeof t[r]<"u"&&e.push([r,t[r]]);return e}return st(Mn);})();

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

import{A as E,B as F,C as G,D as H,E as I,F as J,a as r,b as e,c as f,d as m,e as p,f as t,g as x,h as a,i as b,j as c,k as d,l as g,m as h,n as i,o as j,p as k,q as l,r as n,s as q,t as w,u as y,v as z,w as A,x as B,y as C,z as D}from"./chunk-B3QFAJ6Y.js";import"./chunk-R2Q75YNZ.js";import"./chunk-7IIDO3IU.js";import{a as o,b as s,c as u,d as v}from"./chunk-3Q4WO4OP.js";import"./chunk-NJNTZ6QT.js";import"./chunk-D22QKJZO.js";export{a as EMPTY,f as HAS_PART,p as IS_EXTERNAL,m as PART_OF,v as Traverse,t as UNSET,x as UNWRAP,e as WILDCARD,C as addFlagForExternalResource,G as compressSpecificResource,w as defaultEntities,n as emptyAgent,g as emptyAnnotation,h as emptyAnnotationPage,i as emptyCanvas,j as emptyCollection,k as emptyManifest,l as emptyRange,q as emptyService,c as frameResource,y as getDefaultEntities,u as identifyResource,o as isSpecificResource,b as isWildcard,H as languageString2to3,z as merge,A as mergeEntities,D as normalize,d as resolveIfExists,F as serialize,I as serializeConfigPresentation2,J as serializeConfigPresentation3,E as serializedFieldsToObject,r as toRef,B as traverseSpecificResource,s as types};
import{A as E,B as F,C as G,D as H,E as I,F as J,a as r,b as e,c as f,d as m,e as p,f as t,g as x,h as a,i as b,j as c,k as d,l as g,m as h,n as i,o as j,p as k,q as l,r as n,s as q,t as w,u as y,v as z,w as A,x as B,y as C,z as D}from"./chunk-I7GUVEYK.js";import"./chunk-R2Q75YNZ.js";import"./chunk-3WVPINNO.js";import"./chunk-J657UVVW.js";import{a as o,b as s,c as u,d as v}from"./chunk-3Q4WO4OP.js";import"./chunk-NJNTZ6QT.js";import"./chunk-D22QKJZO.js";export{a as EMPTY,f as HAS_PART,p as IS_EXTERNAL,m as PART_OF,v as Traverse,t as UNSET,x as UNWRAP,e as WILDCARD,C as addFlagForExternalResource,G as compressSpecificResource,w as defaultEntities,n as emptyAgent,g as emptyAnnotation,h as emptyAnnotationPage,i as emptyCanvas,j as emptyCollection,k as emptyManifest,l as emptyRange,q as emptyService,c as frameResource,y as getDefaultEntities,u as identifyResource,o as isSpecificResource,b as isWildcard,H as languageString2to3,z as merge,A as mergeEntities,D as normalize,d as resolveIfExists,F as serialize,I as serializeConfigPresentation2,J as serializeConfigPresentation3,E as serializedFieldsToObject,r as toRef,B as traverseSpecificResource,s as types};

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

"use strict";var v=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Z=Object.prototype.hasOwnProperty;var ee=(t,e,n)=>e in t?v(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var te=(t,e)=>{for(var n in e)v(t,n,{get:e[n],enumerable:!0})},ne=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Y(e))!Z.call(t,r)&&r!==n&&v(t,r,{get:()=>e[r],enumerable:!(i=X(e,r))||i.enumerable});return t};var ie=t=>ne(v({},"__esModule",{value:!0}),t);var d=(t,e,n)=>(ee(t,typeof e!="symbol"?e+"":e,n),n);var De={};te(De,{Traverse:()=>h,convertLanguageMapping:()=>l,convertPresentation2:()=>ke,getProfile:()=>I,getTypeFromContext:()=>z,identifyResource:()=>P,presentation2to3:()=>Q,types:()=>y});module.exports=ie(De);var y=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function P(t){if(typeof t>"u"||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"){let e=y.indexOf(t["@type"]);if(e!==-1)return y[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}var h=class t{constructor(e,n={}){d(this,"traversals");d(this,"options");this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...n}}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){let n=[...(e.manifests||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i),...(e.collections||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i),...e.members||[]];delete e.collections,delete e.manifests,e.members=n}return e.manifests&&(e.manifests=e.manifests.map(n=>this.traverseManifest(typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n))),e.collections&&(e.collections=e.collections.map(n=>this.traverseCollection(typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n))),e.members&&(e.members=e.members.map(n=>typeof n=="string"?n:this.traverseUnknown(n))),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(n=>this.traverseSequence(n))),e.structures&&(e.structures=e.structures.map(n=>this.traverseRange(n))),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(n=>this.traverseCanvas(n))),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(n=>this.traverseAnnotation(n))),e.otherContent&&(e.otherContent=e.otherContent.map(n=>this.traverseAnnotationList(n))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){let n=[...(e.ranges||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Range"}:i),...(e.canvases||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Canvas"}:i),...e.members||[]];delete e.ranges,delete e.canvases,e.members=n.length?n.map(i=>this.traverseUnknown(i)):void 0}return e}traverseAnnotationList(e){let n=typeof e=="string"?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(n)),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map(n=>this.traverseAnnotation(n))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(Array.isArray(e.resource)?e.resource=e.resource.map(n=>this.traverseContentResource(n)):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(n=>this.traverseAnnotationList(n))),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(n=>this.traverseContentResource(n))),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(P(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"sc: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){let n=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(let a of i)typeof a=="string"?r.push(this.traverseContentResource({"@id":a,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(a));return!n&&!this.options.convertPropsToArray?r[0]:r}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){let n=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(let a of i)r.push(this.traverseService(a));return!n&&!this.options.convertPropsToArray?r[0]:r}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,n){if(!Array.isArray(e))if(this.options.convertPropsToArray)e=[e];else return this.traverseType(e,n);return e.map(i=>this.traverseType(i,n))}traverseType(e,n){return n.reduce((i,r)=>{let a=r(i);return typeof a>"u"&&!this.options.allowUndefinedReturn?i:a},e)}};var re="http://library.stanford.edu/iiif/image-api/compliance.html#level0",_="http://library.stanford.edu/iiif/image-api/compliance.html#level1",T="http://library.stanford.edu/iiif/image-api/compliance.html#level2",ae="http://library.stanford.edu/iiif/image-api/conformance.html#level0",x="http://library.stanford.edu/iiif/image-api/conformance.html#level1",L="http://library.stanford.edu/iiif/image-api/conformance.html#level2",se="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",R="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",E="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",oe="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",S="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",M="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",pe="http://iiif.io/api/image/1/level0.json",fe="http://iiif.io/api/image/1/profiles/level0.json",O="http://iiif.io/api/image/1/level1.json",w="http://iiif.io/api/image/1/profiles/level1.json",b="http://iiif.io/api/image/1/level2.json",F="http://iiif.io/api/image/1/profiles/level2.json",ce="http://iiif.io/api/image/2/level0.json",le="http://iiif.io/api/image/2/profiles/level0.json",N="http://iiif.io/api/image/2/level1.json",k="http://iiif.io/api/image/2/profiles/level1.json",D="http://iiif.io/api/image/2/level2.json",G="http://iiif.io/api/image/2/profiles/level2.json",ue="level0",j="level1",q="level2",he="http://iiif.io/api/image/2/level0",V="http://iiif.io/api/image/2/level1",U="http://iiif.io/api/image/2/level2",$=[V,U,_,T,x,L,R,E,S,M,O,w,b,F,N,k,D,G,j,q],W=[he,V,U,re,_,T,ae,x,L,se,R,E,oe,S,M,pe,fe,O,w,b,F,ce,le,N,k,D,G,ue,j,q];function B(t){return Array.isArray(t)?t:t?[t]:[]}function o(t){for(let e in t)(typeof t[e]>"u"||t[e]===null)&&delete t[e];return t}var g={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function ve(t){if(typeof t=="string")return[t];if(!t)return[];let e=Array.isArray(t)?t:[t],n=[];for(let i of e){if(typeof i=="string"){n.push(i);continue}n.push({"@language":i["@language"]||i.language,"@value":i["@value"]||i.value})}return n}function l(t,e="none"){if(!t)return{};let n=ve(t),i={};for(let r of n){if(typeof r=="string"){i[e]=i[e]?i[e]:[],i[e].push(r||"");continue}if(!r["@language"]){i[e]=i[e]?i[e]:[],i[e].push(r["@value"]||"");continue}let a=r["@language"];i[a]=i[a]?i[a]:[],i[a].push(r["@value"]||"")}return i}function I(t){if(Array.isArray(t))return I(t.find(e=>typeof e=="string"));if(W.indexOf(t)!==-1)return"level2";if($.indexOf(t)!==-1)return"level1";if(typeof t=="string")return t}function z(t){let e=Array.isArray(t)?t:[t];for(let n of e)switch(n){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 H(t){for(let e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}var ye=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function C(t){let e=t["@id"]||t.id,n=t["@type"]||t.type,i=t.profile||void 0,r=t["@context"]||void 0;if(i){let a=de(i);if(a)return a}if(r){let a=z(r);if(a)return a}if(n){if(Array.isArray(n)){if(n.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(n.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";n=n[0]}for(let a of["sc","oa","dcterms","dctypes","iiif"])if(n.startsWith(`${a}:`)){n=n.slice(a.length+1);break}switch(n){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(n&&ye.indexOf(n)!==-1)return n;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":n||"unknown"}var ge=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function me(t){let e=t.match(ge);return e?e[0]:t}function Ae(t,e="Rights/License",n="none"){let i=null,r=[],a=Array.isArray(t)?t:[t];for(let s of a){let c=s?me(s):void 0;if(c&&(c.indexOf("creativecommons.org")!==-1||c.indexOf("rightsstatements.org")!==-1)){c.startsWith("https://")?i=`http://${c.slice(8)}`:i=c;continue}c&&r.push({label:{[n]:[e]},value:{[n]:[c]}})}return[i,r]}var Ie=["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 Ce(t){if(t){let e=Array.isArray(t)?t:[t],n=[];for(let i of e)i==="http://iiif.io/api/presentation/2/context.json"&&n.push("http://iiif.io/api/presentation/3/context.json"),Ie.indexOf(i)===-1&&n.push(i);if(e.length)return n.length===1?n[0]:n}}function Pe(t){return t?t.map(e=>({label:l(e.label),value:l(e.value)})):[]}var J=0;function K(t,e){let n=encodeURI(t.id||t["@id"]||"").trim();return n&&e?`${n}/${e}`:n||(J++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${J}`)}function p(t){let e=[...t.behavior||[]];t.viewingHint&&e.push(t.viewingHint);let n;return Array.isArray(t.motivation)?n=t.motivation.map(H):t.motivation&&(n=H(t.motivation)),{"@context":t["@context"]?Ce(t["@context"]):void 0,id:(t["@id"]||K(t)).trim(),type:C(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:n,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function f(t){let[e,n]=Ae(t.license),i=[...t.metadata?Pe(t.metadata):[],...n];return{rights:e,metadata:i.length?i:void 0,label:t.label?l(t.label):void 0,requiredStatement:t.attribution?{label:l(g.attributionLabel),value:l(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?l(t.description):void 0,thumbnail:_e(t.thumbnail)}}function _e(t){return t&&(Array.isArray(t)?t:[t]).map(n=>typeof n=="string"?{id:n,type:"Image"}:(n.type==="unknown"&&(n.type="Image"),n))}function Te(t){if(!t.within)return;let e=Array.isArray(t.within)?t.within:[t.within],n=[];for(let i of e)if(typeof i=="string"){if(i)switch(t["@type"]){case"sc:Manifest":n.push({id:i,type:"Collection"});break}}else i["@id"]&&n.push({id:i["@id"],type:C(i)});return n.length?n:void 0}function u(t){let e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],n=t.contentLayer;return{provider:t.logo||e.length?[{id:g.providerId,type:"Agent",homepage:e.length?[e[0]]:void 0,logo:t.logo?Array.isArray(t.logo)?t.logo:[t.logo]:void 0,label:l(g.providerName)}]:void 0,partOf:Te(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?B(t.service):void 0,supplementary:n?[n]:void 0}}function xe(t){return{chars:t.chars,format:t.format?t.format:void 0,language:t.language}}function Le(t){return o({...p(t),...f(t),...u(t),items:t.members})}function Re(t){let e=[],n=[],i;for(let a of t.sequences||[])a.canvases.length&&e.push(...a.canvases),a.behavior&&n.push(...a.behavior),a.startCanvas&&(i=a.startCanvas);let r=p(t);return n.length&&(r.behavior?r.behavior.push(...n):r.behavior=n),o({...r,...f(t),...u(t),start:i,items:e,structures:t.structures})}function Ee(t){return o({...p(t),...f(t),...u(t),annotations:t.otherContent&&t.otherContent.length?t.otherContent:void 0,items:t.images&&t.images.length?[{id:K(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function Se(t){return o({...p(t),...f(t),...u(t),items:t.resources&&t.resources.length?t.resources:void 0})}function Me(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[],startCanvas:t.startCanvas}}function Oe(t){function e(n){if(Array.isArray(n)){if(n.length>1)return{type:"List",items:n.map(e)};n=n[0]}if(typeof n=="string")return encodeURI(n).trim();if("@type"in n){let i;if(typeof n.full=="string")i=n.full;else if(n.full["@type"]==="dctypes:Image")i={id:n.full["@id"],type:"Image"};else if(n.full["@type"]==="sc:Canvas")i={id:n.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${n.full["@type"]}`);return{type:"SpecificResource",source:i,selector:A(n.selector)}}else return encodeURI(n["@id"]).trim()}return o({...p(t),...f(t),...u(t),target:e(t.on),body:Array.isArray(t.resource)?t.resource.map(m):m(t.resource)})}function m(t){let e=t;return o({...p(e),...f(e),...u(e),...xe(e)})}function we(t){let e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),{...p(t),...f(t),items:e}}function be(t){return o({...p(t),...f(t),...u(t),items:t.members})}function Fe(t){let{"@id":e,"@type":n,"@context":i,profile:r,...a}=t,s={};return e&&(s["@id"]=e),s["@type"]=C(t),s["@type"]==="unknown"&&(i&&i.length&&(s["@context"]=i),s["@type"]="Service"),r&&(s.profile=I(r)),o({...s,...a})}function Ne(t){return o({...p(t),...f(t),...u(t)})}var Q=new h({collection:[Le],manifest:[Re],canvas:[Ee],annotationList:[Se],sequence:[Me],annotation:[Oe],contentResource:[m],choice:[we],range:[be],service:[Fe],layer:[Ne]});function ke(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"?Q.traverseUnknown(t):t}function A(t){if((Array.isArray(t["@type"])&&t["@type"].includes("oa:SvgSelector")||t["@type"]=="oa:SvgSelector")&&("chars"in t||"value"in t))return{type:"SvgSelector",value:"chars"in t?t.chars:t.value};if(t["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:t.value};if(t["@type"]==="oa:Choice")return[A(t.default),...(Array.isArray(t.item)?t.item:[t.item]).map(A)];if(t["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in t?t.region:void 0,rotation:"rotation"in t?t.rotation:void 0};throw new Error(`Unsupported selector type: ${t["@type"]}`)}
"use strict";var v=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var ie=(t,e,i)=>e in t?v(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var ne=(t,e)=>{for(var i in e)v(t,i,{get:e[i],enumerable:!0})},re=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ee(e))!te.call(t,r)&&r!==i&&v(t,r,{get:()=>e[r],enumerable:!(n=Z(e,r))||n.enumerable});return t};var ae=t=>re(v({},"__esModule",{value:!0}),t);var d=(t,e,i)=>(ie(t,typeof e!="symbol"?e+"":e,i),i);var st={};ne(st,{Traverse:()=>u,convertLanguageMapping:()=>c,convertPresentation2:()=>at,getProfile:()=>_,getTypeFromContext:()=>Q,identifyResource:()=>C,presentation2to3:()=>Y,types:()=>y});module.exports=ae(st);var y=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function C(t){if(typeof t>"u"||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"){let e=y.indexOf(t["@type"]);if(e!==-1)return y[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}var u=class t{constructor(e,i={}){d(this,"traversals");d(this,"options");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){let 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){let 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){let i=typeof e=="string"?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(i)),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&&(Array.isArray(e.resource)?e.resource=e.resource.map(i=>this.traverseContentResource(i)):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(C(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"sc: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){let i=Array.isArray(e),n=Array.isArray(e)?e:[e],r=[];for(let a of n)typeof a=="string"?r.push(this.traverseContentResource({"@id":a,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(a));return!i&&!this.options.convertPropsToArray?r[0]:r}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){let i=Array.isArray(e),n=Array.isArray(e)?e:[e],r=[];for(let a of n)r.push(this.traverseService(a));return!i&&!this.options.convertPropsToArray?r[0]:r}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,r)=>{let a=r(n);return typeof a>"u"&&!this.options.allowUndefinedReturn?n:a},e)}};var se="http://library.stanford.edu/iiif/image-api/compliance.html#level1",oe="http://library.stanford.edu/iiif/image-api/compliance.html#level2";var pe="http://library.stanford.edu/iiif/image-api/conformance.html#level1",fe="http://library.stanford.edu/iiif/image-api/conformance.html#level2";var le="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",ce="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2";var he="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",ue="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2";var ve="http://iiif.io/api/image/1/level1.json",de="http://iiif.io/api/image/1/profiles/level1.json",ye="http://iiif.io/api/image/1/level2.json",me="http://iiif.io/api/image/1/profiles/level2.json";var ge="http://iiif.io/api/image/2/level1.json",Ie="http://iiif.io/api/image/2/profiles/level1.json",_e="http://iiif.io/api/image/2/level2.json",Ae="http://iiif.io/api/image/2/profiles/level2.json";var Ce="level1",Ee="level2";var xe="http://iiif.io/api/image/2/level1",Pe="http://iiif.io/api/image/2/level2",E=[xe,Pe,se,oe,pe,fe,le,ce,he,ue,ve,de,ye,me,ge,Ie,_e,Ae,Ce,Ee];function x(t){return Array.isArray(t)?t:t?[t]:[]}function s(t){for(let e in t)(typeof t[e]>"u"||t[e]===null)&&delete t[e];return t}var Le="http://library.stanford.edu/iiif/image-api/compliance.html#level0",P="http://library.stanford.edu/iiif/image-api/compliance.html#level1",L="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Re="http://library.stanford.edu/iiif/image-api/conformance.html#level0",R="http://library.stanford.edu/iiif/image-api/conformance.html#level1",M="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Me="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",T="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",O="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Te="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",F="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",S="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Oe="http://iiif.io/api/image/1/level0.json",Fe="http://iiif.io/api/image/1/profiles/level0.json",b="http://iiif.io/api/image/1/level1.json",N="http://iiif.io/api/image/1/profiles/level1.json",w="http://iiif.io/api/image/1/level2.json",G="http://iiif.io/api/image/1/profiles/level2.json",Se="http://iiif.io/api/image/2/level0.json",be="http://iiif.io/api/image/2/profiles/level0.json",D="http://iiif.io/api/image/2/level1.json",j="http://iiif.io/api/image/2/profiles/level1.json",k="http://iiif.io/api/image/2/level2.json",V="http://iiif.io/api/image/2/profiles/level2.json",Ne="level0",B="level1",q="level2",we="http://iiif.io/api/image/2/level0",W="http://iiif.io/api/image/2/level1",U="http://iiif.io/api/image/2/level2",m=[U,L,M,O,S,w,G,k,V,q],ut=[...m,W,P,R,T,F,b,N,D,j,B],Ge=[we,W,U,Le,P,L,Re,R,M,Me,T,O,Te,F,S,Oe,Fe,b,N,w,G,Se,be,D,j,k,V,Ne,B,q],z=Ge;var g={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function De(t){if(typeof t=="string")return[t];if(!t)return[];let e=Array.isArray(t)?t:[t],i=[];for(let n of e){if(typeof n=="string"){i.push(n);continue}i.push({"@language":n["@language"]||n.language,"@value":n["@value"]||n.value})}return i}function c(t,e="none"){if(!t)return{};let i=De(t),n={};for(let r of i){if(typeof r=="string"){n[e]=n[e]?n[e]:[],n[e].push(r||"");continue}if(!r["@language"]){n[e]=n[e]?n[e]:[],n[e].push(r["@value"]||"");continue}let a=r["@language"];n[a]=n[a]?n[a]:[],n[a].push(r["@value"]||"")}return n}function _(t){if(Array.isArray(t))return _(t.find(e=>typeof e=="string"));if(m.indexOf(t)!==-1)return"level2";if(E.indexOf(t)!==-1)return"level1";if(z.indexOf(t)!==-1)return"level0";if(typeof t=="string")return t}function Q(t){let e=Array.isArray(t)?t:[t];for(let 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 je(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 $(t){for(let e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}var ke=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function A(t){let e=t["@id"]||t.id,i=t["@type"]||t.type,n=t.profile||void 0,r=t["@context"]||void 0;if(n){let a=je(n);if(a)return a}if(r){let a=Q(r);if(a)return a}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(let a of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${a}:`)){i=i.slice(a.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(i&&ke.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"}var Ve=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Be(t){let e=t.match(Ve);return e?e[0]:t}function qe(t,e="Rights/License",i="none"){let n=null,r=[],a=Array.isArray(t)?t:[t];for(let o of a){let l=o?Be(o):void 0;if(l&&(l.indexOf("creativecommons.org")!==-1||l.indexOf("rightsstatements.org")!==-1)){l.startsWith("https://")?n=`http://${l.slice(8)}`:n=l;continue}l&&r.push({label:{[i]:[e]},value:{[i]:[l]}})}return[n,r]}var We=["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){let e=Array.isArray(t)?t:[t],i=[];for(let n of e)n==="http://iiif.io/api/presentation/2/context.json"&&i.push("http://iiif.io/api/presentation/3/context.json"),We.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:c(e.label),value:c(e.value)})):[]}var H=0;function K(t,e){let i=encodeURI(t.id||t["@id"]||"").trim();return i&&e?`${i}/${e}`:i||(H++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${H}`)}function p(t){let e=[...t.behavior||[]];t.viewingHint&&e.push(t.viewingHint);let i;return Array.isArray(t.motivation)?i=t.motivation.map($):t.motivation&&(i=$(t.motivation)),{"@context":t["@context"]?Ue(t["@context"]):void 0,id:(t["@id"]||K(t)).trim(),type:A(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:i,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function f(t){let[e,i]=qe(t.license),n=[...t.metadata?ze(t.metadata):[],...i];return{rights:e,metadata:n.length?n:void 0,label:t.label?c(t.label):void 0,requiredStatement:t.attribution?{label:c(g.attributionLabel),value:c(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?c(t.description):void 0,thumbnail:$e(t.thumbnail)}}function $e(t){return t&&(Array.isArray(t)?t:[t]).map(i=>typeof i=="string"?{id:i,type:"Image"}:(i.type==="unknown"&&(i.type="Image"),i))}function He(t){if(!t.within)return;let e=Array.isArray(t.within)?t.within:[t.within],i=[];for(let 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:A(n)});return i.length?i:void 0}function h(t){let e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],i=t.contentLayer;return{provider:t.logo||e.length?[{id:g.providerId,type:"Agent",homepage:e.length?[e[0]]:void 0,logo:t.logo?Array.isArray(t.logo)?t.logo:[t.logo]:void 0,label:c(g.providerName)}]:void 0,partOf:He(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?x(t.service):void 0,supplementary:i?[i]:void 0}}function Je(t){return{chars:t.chars,format:t.format?t.format:void 0,language:t.language}}function Qe(t){return s({...p(t),...f(t),...h(t),items:t.members})}function Ke(t){let e=[],i=[],n;for(let a of t.sequences||[])a.canvases.length&&e.push(...a.canvases),a.behavior&&i.push(...a.behavior),a.startCanvas&&(n=a.startCanvas);let r=p(t);return i.length&&(r.behavior?r.behavior.push(...i):r.behavior=i),s({...r,...f(t),...h(t),start:n,items:e,structures:t.structures})}function Xe(t){return s({...p(t),...f(t),...h(t),annotations:t.otherContent&&t.otherContent.length?t.otherContent:void 0,items:t.images&&t.images.length?[{id:K(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function Ye(t){return s({...p(t),...f(t),...h(t),items:t.resources&&t.resources.length?t.resources:void 0})}function Ze(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[],startCanvas:t.startCanvas}}function et(t){function e(i){if(Array.isArray(i)){if(i.length>1)return{type:"List",items:i.map(e)};i=i[0]}if(typeof i=="string")return encodeURI(i).trim();if("@type"in i){let n;if(typeof i.full=="string")n=i.full;else if(i.full["@type"]==="dctypes:Image")n={id:i.full["@id"],type:"Image"};else if(i.full["@type"]==="sc:Canvas")n={id:i.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${i.full["@type"]}`);return{type:"SpecificResource",source:n,selector:I(i.selector)}}else return encodeURI(i["@id"]).trim()}return s({...p(t),...f(t),...h(t),target:e(t.on),body:Array.isArray(t.resource)?t.resource.map(J):J(t.resource)})}function J(t){return t.type==="Choice"?t:X(t)}function X(t){let e=t;return s({...p(e),...f(e),...h(e),...Je(e)})}function tt(t){let e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),s({...p(t),...f(t),items:e})}function it(t){return s({...p(t),...f(t),...h(t),items:t.members})}function nt(t){let{"@id":e,"@type":i,"@context":n,profile:r,...a}=t,o={};return e&&(o["@id"]=e),o["@type"]=A(t),o["@type"]==="unknown"&&(n&&n.length&&(o["@context"]=n),o["@type"]="Service"),r&&(o.profile=_(r)),s({...o,...a})}function rt(t){return s({...p(t),...f(t),...h(t)})}var Y=new u({collection:[Qe],manifest:[Ke],canvas:[Xe],annotationList:[Ye],sequence:[Ze],annotation:[et],contentResource:[X],choice:[tt],range:[it],service:[nt],layer:[rt]});function at(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"?Y.traverseUnknown(t):t}function I(t){if((Array.isArray(t["@type"])&&t["@type"].includes("oa:SvgSelector")||t["@type"]=="oa:SvgSelector")&&("chars"in t||"value"in t))return{type:"SvgSelector",value:"chars"in t?t.chars:t.value};if(t["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:t.value};if(t["@type"]==="oa:Choice")return[I(t.default),...(Array.isArray(t.item)?t.item:[t.item]).map(I)];if(t["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in t?t.region:void 0,rotation:"rotation"in t?t.rotation:void 0};throw new Error(`Unsupported selector type: ${t["@type"]}`)}

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

"use strict";var IIIFParser=(()=>{var v=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Z=Object.prototype.hasOwnProperty;var ee=(t,e,n)=>e in t?v(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var te=(t,e)=>{for(var n in e)v(t,n,{get:e[n],enumerable:!0})},ne=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Y(e))!Z.call(t,r)&&r!==n&&v(t,r,{get:()=>e[r],enumerable:!(i=X(e,r))||i.enumerable});return t};var ie=t=>ne(v({},"__esModule",{value:!0}),t);var d=(t,e,n)=>(ee(t,typeof e!="symbol"?e+"":e,n),n);var De={};te(De,{Traverse:()=>h,convertLanguageMapping:()=>l,convertPresentation2:()=>ke,getProfile:()=>I,getTypeFromContext:()=>z,identifyResource:()=>P,presentation2to3:()=>Q,types:()=>y});var y=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function P(t){if(typeof t>"u"||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"){let e=y.indexOf(t["@type"]);if(e!==-1)return y[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}var h=class t{constructor(e,n={}){d(this,"traversals");d(this,"options");this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...n}}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){let n=[...(e.manifests||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i),...(e.collections||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i),...e.members||[]];delete e.collections,delete e.manifests,e.members=n}return e.manifests&&(e.manifests=e.manifests.map(n=>this.traverseManifest(typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n))),e.collections&&(e.collections=e.collections.map(n=>this.traverseCollection(typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n))),e.members&&(e.members=e.members.map(n=>typeof n=="string"?n:this.traverseUnknown(n))),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(n=>this.traverseSequence(n))),e.structures&&(e.structures=e.structures.map(n=>this.traverseRange(n))),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(n=>this.traverseCanvas(n))),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(n=>this.traverseAnnotation(n))),e.otherContent&&(e.otherContent=e.otherContent.map(n=>this.traverseAnnotationList(n))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){let n=[...(e.ranges||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Range"}:i),...(e.canvases||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Canvas"}:i),...e.members||[]];delete e.ranges,delete e.canvases,e.members=n.length?n.map(i=>this.traverseUnknown(i)):void 0}return e}traverseAnnotationList(e){let n=typeof e=="string"?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(n)),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map(n=>this.traverseAnnotation(n))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(Array.isArray(e.resource)?e.resource=e.resource.map(n=>this.traverseContentResource(n)):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(n=>this.traverseAnnotationList(n))),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(n=>this.traverseContentResource(n))),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(P(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"sc: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){let n=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(let a of i)typeof a=="string"?r.push(this.traverseContentResource({"@id":a,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(a));return!n&&!this.options.convertPropsToArray?r[0]:r}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){let n=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(let a of i)r.push(this.traverseService(a));return!n&&!this.options.convertPropsToArray?r[0]:r}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,n){if(!Array.isArray(e))if(this.options.convertPropsToArray)e=[e];else return this.traverseType(e,n);return e.map(i=>this.traverseType(i,n))}traverseType(e,n){return n.reduce((i,r)=>{let a=r(i);return typeof a>"u"&&!this.options.allowUndefinedReturn?i:a},e)}};var re="http://library.stanford.edu/iiif/image-api/compliance.html#level0",_="http://library.stanford.edu/iiif/image-api/compliance.html#level1",T="http://library.stanford.edu/iiif/image-api/compliance.html#level2",ae="http://library.stanford.edu/iiif/image-api/conformance.html#level0",x="http://library.stanford.edu/iiif/image-api/conformance.html#level1",L="http://library.stanford.edu/iiif/image-api/conformance.html#level2",se="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",R="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",E="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",oe="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",S="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",M="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",pe="http://iiif.io/api/image/1/level0.json",fe="http://iiif.io/api/image/1/profiles/level0.json",O="http://iiif.io/api/image/1/level1.json",w="http://iiif.io/api/image/1/profiles/level1.json",b="http://iiif.io/api/image/1/level2.json",F="http://iiif.io/api/image/1/profiles/level2.json",ce="http://iiif.io/api/image/2/level0.json",le="http://iiif.io/api/image/2/profiles/level0.json",N="http://iiif.io/api/image/2/level1.json",k="http://iiif.io/api/image/2/profiles/level1.json",D="http://iiif.io/api/image/2/level2.json",G="http://iiif.io/api/image/2/profiles/level2.json",ue="level0",j="level1",q="level2",he="http://iiif.io/api/image/2/level0",V="http://iiif.io/api/image/2/level1",U="http://iiif.io/api/image/2/level2",$=[V,U,_,T,x,L,R,E,S,M,O,w,b,F,N,k,D,G,j,q],W=[he,V,U,re,_,T,ae,x,L,se,R,E,oe,S,M,pe,fe,O,w,b,F,ce,le,N,k,D,G,ue,j,q];function B(t){return Array.isArray(t)?t:t?[t]:[]}function o(t){for(let e in t)(typeof t[e]>"u"||t[e]===null)&&delete t[e];return t}var g={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function ve(t){if(typeof t=="string")return[t];if(!t)return[];let e=Array.isArray(t)?t:[t],n=[];for(let i of e){if(typeof i=="string"){n.push(i);continue}n.push({"@language":i["@language"]||i.language,"@value":i["@value"]||i.value})}return n}function l(t,e="none"){if(!t)return{};let n=ve(t),i={};for(let r of n){if(typeof r=="string"){i[e]=i[e]?i[e]:[],i[e].push(r||"");continue}if(!r["@language"]){i[e]=i[e]?i[e]:[],i[e].push(r["@value"]||"");continue}let a=r["@language"];i[a]=i[a]?i[a]:[],i[a].push(r["@value"]||"")}return i}function I(t){if(Array.isArray(t))return I(t.find(e=>typeof e=="string"));if(W.indexOf(t)!==-1)return"level2";if($.indexOf(t)!==-1)return"level1";if(typeof t=="string")return t}function z(t){let e=Array.isArray(t)?t:[t];for(let n of e)switch(n){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 H(t){for(let e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}var ye=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function C(t){let e=t["@id"]||t.id,n=t["@type"]||t.type,i=t.profile||void 0,r=t["@context"]||void 0;if(i){let a=de(i);if(a)return a}if(r){let a=z(r);if(a)return a}if(n){if(Array.isArray(n)){if(n.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(n.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";n=n[0]}for(let a of["sc","oa","dcterms","dctypes","iiif"])if(n.startsWith(`${a}:`)){n=n.slice(a.length+1);break}switch(n){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(n&&ye.indexOf(n)!==-1)return n;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":n||"unknown"}var ge=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function me(t){let e=t.match(ge);return e?e[0]:t}function Ae(t,e="Rights/License",n="none"){let i=null,r=[],a=Array.isArray(t)?t:[t];for(let s of a){let c=s?me(s):void 0;if(c&&(c.indexOf("creativecommons.org")!==-1||c.indexOf("rightsstatements.org")!==-1)){c.startsWith("https://")?i=`http://${c.slice(8)}`:i=c;continue}c&&r.push({label:{[n]:[e]},value:{[n]:[c]}})}return[i,r]}var Ie=["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 Ce(t){if(t){let e=Array.isArray(t)?t:[t],n=[];for(let i of e)i==="http://iiif.io/api/presentation/2/context.json"&&n.push("http://iiif.io/api/presentation/3/context.json"),Ie.indexOf(i)===-1&&n.push(i);if(e.length)return n.length===1?n[0]:n}}function Pe(t){return t?t.map(e=>({label:l(e.label),value:l(e.value)})):[]}var J=0;function K(t,e){let n=encodeURI(t.id||t["@id"]||"").trim();return n&&e?`${n}/${e}`:n||(J++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${J}`)}function p(t){let e=[...t.behavior||[]];t.viewingHint&&e.push(t.viewingHint);let n;return Array.isArray(t.motivation)?n=t.motivation.map(H):t.motivation&&(n=H(t.motivation)),{"@context":t["@context"]?Ce(t["@context"]):void 0,id:(t["@id"]||K(t)).trim(),type:C(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:n,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function f(t){let[e,n]=Ae(t.license),i=[...t.metadata?Pe(t.metadata):[],...n];return{rights:e,metadata:i.length?i:void 0,label:t.label?l(t.label):void 0,requiredStatement:t.attribution?{label:l(g.attributionLabel),value:l(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?l(t.description):void 0,thumbnail:_e(t.thumbnail)}}function _e(t){return t&&(Array.isArray(t)?t:[t]).map(n=>typeof n=="string"?{id:n,type:"Image"}:(n.type==="unknown"&&(n.type="Image"),n))}function Te(t){if(!t.within)return;let e=Array.isArray(t.within)?t.within:[t.within],n=[];for(let i of e)if(typeof i=="string"){if(i)switch(t["@type"]){case"sc:Manifest":n.push({id:i,type:"Collection"});break}}else i["@id"]&&n.push({id:i["@id"],type:C(i)});return n.length?n:void 0}function u(t){let e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],n=t.contentLayer;return{provider:t.logo||e.length?[{id:g.providerId,type:"Agent",homepage:e.length?[e[0]]:void 0,logo:t.logo?Array.isArray(t.logo)?t.logo:[t.logo]:void 0,label:l(g.providerName)}]:void 0,partOf:Te(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?B(t.service):void 0,supplementary:n?[n]:void 0}}function xe(t){return{chars:t.chars,format:t.format?t.format:void 0,language:t.language}}function Le(t){return o({...p(t),...f(t),...u(t),items:t.members})}function Re(t){let e=[],n=[],i;for(let a of t.sequences||[])a.canvases.length&&e.push(...a.canvases),a.behavior&&n.push(...a.behavior),a.startCanvas&&(i=a.startCanvas);let r=p(t);return n.length&&(r.behavior?r.behavior.push(...n):r.behavior=n),o({...r,...f(t),...u(t),start:i,items:e,structures:t.structures})}function Ee(t){return o({...p(t),...f(t),...u(t),annotations:t.otherContent&&t.otherContent.length?t.otherContent:void 0,items:t.images&&t.images.length?[{id:K(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function Se(t){return o({...p(t),...f(t),...u(t),items:t.resources&&t.resources.length?t.resources:void 0})}function Me(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[],startCanvas:t.startCanvas}}function Oe(t){function e(n){if(Array.isArray(n)){if(n.length>1)return{type:"List",items:n.map(e)};n=n[0]}if(typeof n=="string")return encodeURI(n).trim();if("@type"in n){let i;if(typeof n.full=="string")i=n.full;else if(n.full["@type"]==="dctypes:Image")i={id:n.full["@id"],type:"Image"};else if(n.full["@type"]==="sc:Canvas")i={id:n.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${n.full["@type"]}`);return{type:"SpecificResource",source:i,selector:A(n.selector)}}else return encodeURI(n["@id"]).trim()}return o({...p(t),...f(t),...u(t),target:e(t.on),body:Array.isArray(t.resource)?t.resource.map(m):m(t.resource)})}function m(t){let e=t;return o({...p(e),...f(e),...u(e),...xe(e)})}function we(t){let e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),{...p(t),...f(t),items:e}}function be(t){return o({...p(t),...f(t),...u(t),items:t.members})}function Fe(t){let{"@id":e,"@type":n,"@context":i,profile:r,...a}=t,s={};return e&&(s["@id"]=e),s["@type"]=C(t),s["@type"]==="unknown"&&(i&&i.length&&(s["@context"]=i),s["@type"]="Service"),r&&(s.profile=I(r)),o({...s,...a})}function Ne(t){return o({...p(t),...f(t),...u(t)})}var Q=new h({collection:[Le],manifest:[Re],canvas:[Ee],annotationList:[Se],sequence:[Me],annotation:[Oe],contentResource:[m],choice:[we],range:[be],service:[Fe],layer:[Ne]});function ke(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"?Q.traverseUnknown(t):t}function A(t){if((Array.isArray(t["@type"])&&t["@type"].includes("oa:SvgSelector")||t["@type"]=="oa:SvgSelector")&&("chars"in t||"value"in t))return{type:"SvgSelector",value:"chars"in t?t.chars:t.value};if(t["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:t.value};if(t["@type"]==="oa:Choice")return[A(t.default),...(Array.isArray(t.item)?t.item:[t.item]).map(A)];if(t["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in t?t.region:void 0,rotation:"rotation"in t?t.rotation:void 0};throw new Error(`Unsupported selector type: ${t["@type"]}`)}return ie(De);})();
"use strict";var IIIFParser=(()=>{var v=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var ie=(t,e,i)=>e in t?v(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var ne=(t,e)=>{for(var i in e)v(t,i,{get:e[i],enumerable:!0})},re=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ee(e))!te.call(t,r)&&r!==i&&v(t,r,{get:()=>e[r],enumerable:!(n=Z(e,r))||n.enumerable});return t};var ae=t=>re(v({},"__esModule",{value:!0}),t);var d=(t,e,i)=>(ie(t,typeof e!="symbol"?e+"":e,i),i);var st={};ne(st,{Traverse:()=>u,convertLanguageMapping:()=>c,convertPresentation2:()=>at,getProfile:()=>_,getTypeFromContext:()=>Q,identifyResource:()=>C,presentation2to3:()=>Y,types:()=>y});var y=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function C(t){if(typeof t>"u"||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"){let e=y.indexOf(t["@type"]);if(e!==-1)return y[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}var u=class t{constructor(e,i={}){d(this,"traversals");d(this,"options");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){let 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){let 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){let i=typeof e=="string"?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(i)),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&&(Array.isArray(e.resource)?e.resource=e.resource.map(i=>this.traverseContentResource(i)):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(C(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"sc: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){let i=Array.isArray(e),n=Array.isArray(e)?e:[e],r=[];for(let a of n)typeof a=="string"?r.push(this.traverseContentResource({"@id":a,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(a));return!i&&!this.options.convertPropsToArray?r[0]:r}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){let i=Array.isArray(e),n=Array.isArray(e)?e:[e],r=[];for(let a of n)r.push(this.traverseService(a));return!i&&!this.options.convertPropsToArray?r[0]:r}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,r)=>{let a=r(n);return typeof a>"u"&&!this.options.allowUndefinedReturn?n:a},e)}};var se="http://library.stanford.edu/iiif/image-api/compliance.html#level1",oe="http://library.stanford.edu/iiif/image-api/compliance.html#level2";var pe="http://library.stanford.edu/iiif/image-api/conformance.html#level1",fe="http://library.stanford.edu/iiif/image-api/conformance.html#level2";var le="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",ce="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2";var he="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",ue="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2";var ve="http://iiif.io/api/image/1/level1.json",de="http://iiif.io/api/image/1/profiles/level1.json",ye="http://iiif.io/api/image/1/level2.json",me="http://iiif.io/api/image/1/profiles/level2.json";var ge="http://iiif.io/api/image/2/level1.json",Ie="http://iiif.io/api/image/2/profiles/level1.json",_e="http://iiif.io/api/image/2/level2.json",Ae="http://iiif.io/api/image/2/profiles/level2.json";var Ce="level1",Ee="level2";var xe="http://iiif.io/api/image/2/level1",Pe="http://iiif.io/api/image/2/level2",E=[xe,Pe,se,oe,pe,fe,le,ce,he,ue,ve,de,ye,me,ge,Ie,_e,Ae,Ce,Ee];function x(t){return Array.isArray(t)?t:t?[t]:[]}function s(t){for(let e in t)(typeof t[e]>"u"||t[e]===null)&&delete t[e];return t}var Le="http://library.stanford.edu/iiif/image-api/compliance.html#level0",P="http://library.stanford.edu/iiif/image-api/compliance.html#level1",L="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Re="http://library.stanford.edu/iiif/image-api/conformance.html#level0",R="http://library.stanford.edu/iiif/image-api/conformance.html#level1",M="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Me="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",T="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",O="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Te="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",F="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",S="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Oe="http://iiif.io/api/image/1/level0.json",Fe="http://iiif.io/api/image/1/profiles/level0.json",b="http://iiif.io/api/image/1/level1.json",N="http://iiif.io/api/image/1/profiles/level1.json",w="http://iiif.io/api/image/1/level2.json",G="http://iiif.io/api/image/1/profiles/level2.json",Se="http://iiif.io/api/image/2/level0.json",be="http://iiif.io/api/image/2/profiles/level0.json",D="http://iiif.io/api/image/2/level1.json",j="http://iiif.io/api/image/2/profiles/level1.json",k="http://iiif.io/api/image/2/level2.json",V="http://iiif.io/api/image/2/profiles/level2.json",Ne="level0",B="level1",q="level2",we="http://iiif.io/api/image/2/level0",W="http://iiif.io/api/image/2/level1",U="http://iiif.io/api/image/2/level2",m=[U,L,M,O,S,w,G,k,V,q],ut=[...m,W,P,R,T,F,b,N,D,j,B],Ge=[we,W,U,Le,P,L,Re,R,M,Me,T,O,Te,F,S,Oe,Fe,b,N,w,G,Se,be,D,j,k,V,Ne,B,q],z=Ge;var g={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function De(t){if(typeof t=="string")return[t];if(!t)return[];let e=Array.isArray(t)?t:[t],i=[];for(let n of e){if(typeof n=="string"){i.push(n);continue}i.push({"@language":n["@language"]||n.language,"@value":n["@value"]||n.value})}return i}function c(t,e="none"){if(!t)return{};let i=De(t),n={};for(let r of i){if(typeof r=="string"){n[e]=n[e]?n[e]:[],n[e].push(r||"");continue}if(!r["@language"]){n[e]=n[e]?n[e]:[],n[e].push(r["@value"]||"");continue}let a=r["@language"];n[a]=n[a]?n[a]:[],n[a].push(r["@value"]||"")}return n}function _(t){if(Array.isArray(t))return _(t.find(e=>typeof e=="string"));if(m.indexOf(t)!==-1)return"level2";if(E.indexOf(t)!==-1)return"level1";if(z.indexOf(t)!==-1)return"level0";if(typeof t=="string")return t}function Q(t){let e=Array.isArray(t)?t:[t];for(let 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 je(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 $(t){for(let e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}var ke=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function A(t){let e=t["@id"]||t.id,i=t["@type"]||t.type,n=t.profile||void 0,r=t["@context"]||void 0;if(n){let a=je(n);if(a)return a}if(r){let a=Q(r);if(a)return a}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(let a of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${a}:`)){i=i.slice(a.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(i&&ke.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"}var Ve=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Be(t){let e=t.match(Ve);return e?e[0]:t}function qe(t,e="Rights/License",i="none"){let n=null,r=[],a=Array.isArray(t)?t:[t];for(let o of a){let l=o?Be(o):void 0;if(l&&(l.indexOf("creativecommons.org")!==-1||l.indexOf("rightsstatements.org")!==-1)){l.startsWith("https://")?n=`http://${l.slice(8)}`:n=l;continue}l&&r.push({label:{[i]:[e]},value:{[i]:[l]}})}return[n,r]}var We=["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){let e=Array.isArray(t)?t:[t],i=[];for(let n of e)n==="http://iiif.io/api/presentation/2/context.json"&&i.push("http://iiif.io/api/presentation/3/context.json"),We.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:c(e.label),value:c(e.value)})):[]}var H=0;function K(t,e){let i=encodeURI(t.id||t["@id"]||"").trim();return i&&e?`${i}/${e}`:i||(H++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${H}`)}function p(t){let e=[...t.behavior||[]];t.viewingHint&&e.push(t.viewingHint);let i;return Array.isArray(t.motivation)?i=t.motivation.map($):t.motivation&&(i=$(t.motivation)),{"@context":t["@context"]?Ue(t["@context"]):void 0,id:(t["@id"]||K(t)).trim(),type:A(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:i,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function f(t){let[e,i]=qe(t.license),n=[...t.metadata?ze(t.metadata):[],...i];return{rights:e,metadata:n.length?n:void 0,label:t.label?c(t.label):void 0,requiredStatement:t.attribution?{label:c(g.attributionLabel),value:c(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?c(t.description):void 0,thumbnail:$e(t.thumbnail)}}function $e(t){return t&&(Array.isArray(t)?t:[t]).map(i=>typeof i=="string"?{id:i,type:"Image"}:(i.type==="unknown"&&(i.type="Image"),i))}function He(t){if(!t.within)return;let e=Array.isArray(t.within)?t.within:[t.within],i=[];for(let 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:A(n)});return i.length?i:void 0}function h(t){let e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],i=t.contentLayer;return{provider:t.logo||e.length?[{id:g.providerId,type:"Agent",homepage:e.length?[e[0]]:void 0,logo:t.logo?Array.isArray(t.logo)?t.logo:[t.logo]:void 0,label:c(g.providerName)}]:void 0,partOf:He(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?x(t.service):void 0,supplementary:i?[i]:void 0}}function Je(t){return{chars:t.chars,format:t.format?t.format:void 0,language:t.language}}function Qe(t){return s({...p(t),...f(t),...h(t),items:t.members})}function Ke(t){let e=[],i=[],n;for(let a of t.sequences||[])a.canvases.length&&e.push(...a.canvases),a.behavior&&i.push(...a.behavior),a.startCanvas&&(n=a.startCanvas);let r=p(t);return i.length&&(r.behavior?r.behavior.push(...i):r.behavior=i),s({...r,...f(t),...h(t),start:n,items:e,structures:t.structures})}function Xe(t){return s({...p(t),...f(t),...h(t),annotations:t.otherContent&&t.otherContent.length?t.otherContent:void 0,items:t.images&&t.images.length?[{id:K(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function Ye(t){return s({...p(t),...f(t),...h(t),items:t.resources&&t.resources.length?t.resources:void 0})}function Ze(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[],startCanvas:t.startCanvas}}function et(t){function e(i){if(Array.isArray(i)){if(i.length>1)return{type:"List",items:i.map(e)};i=i[0]}if(typeof i=="string")return encodeURI(i).trim();if("@type"in i){let n;if(typeof i.full=="string")n=i.full;else if(i.full["@type"]==="dctypes:Image")n={id:i.full["@id"],type:"Image"};else if(i.full["@type"]==="sc:Canvas")n={id:i.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${i.full["@type"]}`);return{type:"SpecificResource",source:n,selector:I(i.selector)}}else return encodeURI(i["@id"]).trim()}return s({...p(t),...f(t),...h(t),target:e(t.on),body:Array.isArray(t.resource)?t.resource.map(J):J(t.resource)})}function J(t){return t.type==="Choice"?t:X(t)}function X(t){let e=t;return s({...p(e),...f(e),...h(e),...Je(e)})}function tt(t){let e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),s({...p(t),...f(t),items:e})}function it(t){return s({...p(t),...f(t),...h(t),items:t.members})}function nt(t){let{"@id":e,"@type":i,"@context":n,profile:r,...a}=t,o={};return e&&(o["@id"]=e),o["@type"]=A(t),o["@type"]==="unknown"&&(n&&n.length&&(o["@context"]=n),o["@type"]="Service"),r&&(o.profile=_(r)),s({...o,...a})}function rt(t){return s({...p(t),...f(t),...h(t)})}var Y=new u({collection:[Qe],manifest:[Ke],canvas:[Xe],annotationList:[Ye],sequence:[Ze],annotation:[et],contentResource:[X],choice:[tt],range:[it],service:[nt],layer:[rt]});function at(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"?Y.traverseUnknown(t):t}function I(t){if((Array.isArray(t["@type"])&&t["@type"].includes("oa:SvgSelector")||t["@type"]=="oa:SvgSelector")&&("chars"in t||"value"in t))return{type:"SvgSelector",value:"chars"in t?t.chars:t.value};if(t["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:t.value};if(t["@type"]==="oa:Choice")return[I(t.default),...(Array.isArray(t.item)?t.item:[t.item]).map(I)];if(t["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in t?t.region:void 0,rotation:"rotation"in t?t.rotation:void 0};throw new Error(`Unsupported selector type: ${t["@type"]}`)}return ae(st);})();

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

import"./chunk-R2Q75YNZ.js";import{a,b,c,d,e,f,g,h}from"./chunk-7IIDO3IU.js";import"./chunk-NJNTZ6QT.js";import"./chunk-D22QKJZO.js";export{c as Traverse,d as convertLanguageMapping,h as convertPresentation2,e as getProfile,f as getTypeFromContext,b as identifyResource,g as presentation2to3,a as types};
import"./chunk-R2Q75YNZ.js";import{a,b,c,d,e,f,g,h}from"./chunk-3WVPINNO.js";import"./chunk-J657UVVW.js";import"./chunk-NJNTZ6QT.js";import"./chunk-D22QKJZO.js";export{c as Traverse,d as convertLanguageMapping,h as convertPresentation2,e as getProfile,f as getTypeFromContext,b as identifyResource,g as presentation2to3,a as types};

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

"use strict";var V=Object.defineProperty;var Qe=Object.getOwnPropertyDescriptor;var Ze=Object.getOwnPropertyNames;var et=Object.prototype.hasOwnProperty;var tt=(e,t,n)=>t in e?V(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var nt=(e,t)=>{for(var n in t)V(e,n,{get:t[n],enumerable:!0})},it=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ze(t))!et.call(e,r)&&r!==n&&V(e,r,{get:()=>t[r],enumerable:!(i=Qe(t,r))||i.enumerable});return e};var rt=e=>it(V({},"__esModule",{value:!0}),e);var m=(e,t,n)=>(tt(e,typeof t!="symbol"?t+"":t,n),n);var on={};nt(on,{EMPTY:()=>s,HAS_PART:()=>u,IS_EXTERNAL:()=>S,PART_OF:()=>A,Traverse:()=>G,UNSET:()=>y,UNWRAP:()=>q,WILDCARD:()=>w,addFlagForExternalResource:()=>Y,compressSpecificResource:()=>x,defaultEntities:()=>Ut,emptyAgent:()=>ae,emptyAnnotation:()=>at,emptyAnnotationPage:()=>ee,emptyCanvas:()=>te,emptyCollection:()=>ne,emptyManifest:()=>ie,emptyRange:()=>re,emptyService:()=>se,frameResource:()=>ve,getDefaultEntities:()=>We,identifyResource:()=>ye,isSpecificResource:()=>h,isWildcard:()=>de,languageString2to3:()=>k,merge:()=>J,mergeEntities:()=>Q,normalize:()=>Jt,resolveIfExists:()=>B,serialize:()=>Qt,serializeConfigPresentation2:()=>rn,serializeConfigPresentation3:()=>an,serializedFieldsToObject:()=>Ke,toRef:()=>H,traverseSpecificResource:()=>Be,types:()=>oe});module.exports=rt(on);function h(e){return typeof e=="string"?!1:!!e&&e.type==="SpecificResource"}function H(e,t){let n=t||"unknown";if(!e)return;if(typeof e=="string")return{id:e,type:n};if(h(e))return H(e.source,t);let i=n&&n!=="unknown"?n:e.type||e["@type"],r=e.id||e["@id"];if(i&&i.indexOf(":")!==-1&&(i=i.split(":").pop()),r&&i)return{id:r,type:i}}var w={},u="iiif-parser:hasPart",A="iiif-parser:partOf",S="iiif-parser:isExternal",y="__$UNSET$__",q="__$UNWRAP$__",s=[];Object.freeze(s);Object.freeze(w);function de(e){if(e===w||Object.keys(e).length===0)return!0;for(let t in e)return!1;return!0}function ve(e,t){if(t&&t["@explicit"]){let n={},i=Object.keys(t);for(let r of i)r===A||r==="@explicit"||(de(t[r])?n[r]=e[r]:n[r]=t[r]);return n}return e}function B(e,t,n){let i=H(t);if(!i)return[void 0,void 0];let r=e.requests[i.id],a=i.type||e.mapping[i.id];if(!a||r&&r.resourceUri&&(!e.entities[a]||!e.entities[a][r.resourceUri]))return[void 0,void 0];let o=e.entities[a][r?r.resourceUri:i.id];if(i.type&&!o)return B(e,{id:i.id},n);if(o&&o[u]){let c=o[u].find(l=>n?l[A]===n.id:l[A]===o.id);return[ve(o,c),o]}return[o,o]}var at={id:"https://iiif-parser/annotation",type:"Annotation",behavior:s,label:null,thumbnail:s,summary:null,requiredStatement:null,metadata:s,seeAlso:s,homepage:s,rendering:s,service:s,accessibility:s,audience:s,body:s,bodyValue:null,canonical:null,created:null,creator:s,generated:null,generator:s,modified:null,motivation:s,rights:null,stylesheet:null,target:s,timeMode:void 0,via:s,partOf:s},ee={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:s,label:null,thumbnail:s,summary:null,requiredStatement:null,metadata:s,rights:null,provider:s,items:s,seeAlso:s,homepage:s,rendering:s,service:s},te={id:"https://iiif-parser/empty-canvas",type:"Canvas",label:null,behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,duration:0,height:0,width:0},ne={id:"https://iiif-parser/empty-collection",type:"Collection",label:null,viewingDirection:"left-to-right",behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,services:s},ie={id:"https://iiif-parser/empty-manifest",type:"Manifest",annotations:s,behavior:s,homepage:s,items:s,label:null,metadata:s,navDate:null,provider:s,partOf:s,accompanyingCanvas:null,placeholderCanvas:null,rendering:s,requiredStatement:null,rights:null,seeAlso:s,service:s,services:s,start:null,structures:s,summary:null,thumbnail:s,viewingDirection:"left-to-right"},re={id:"https://iiif-parser/empty-canvas",type:"Range",label:null,behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,start:null,supplementary:null,viewingDirection:"left-to-right"},ae={id:"https://iiif-parser/empty-agent",type:"Agent",label:{},logo:s,seeAlso:s,homepage:s},se={id:"https://iiif-parser/empty-service",type:"UnknownService"};function P(e){return Array.isArray(e)?e:e?[e]:[]}function U(...e){return t=>e.reduce((n,i)=>i(n),t)}var oe=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function ye(e,t){if(typeof e>"u"||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"){if(t)return t;throw new Error(`${typeof e} is not a valid entity`)}if(typeof e.type=="string"){let n=oe.indexOf(e.type);if(n!==-1)return oe[n]}if(e.profile)return"Service";throw new Error("Resource type is not known")}var G=class e{constructor(t,n={}){m(this,"traversals");m(this,"options");m(this,"_traverseManifest",U(this.traverseManifestItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseManifestStructures.bind(this),this.traverseInlineAnnotationPages.bind(this)));m(this,"_traverseCanvas",U(this.traverseCanvasItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseInlineAnnotationPages.bind(this)));m(this,"_traverseAnnotationPage",U(this.traverseAnnotationPageItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this)));m(this,"_traverseRange",U(this.traverseRangeRanges.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this)));this.traversals={collection:[],manifest:[],canvas:[],annotationCollection:[],annotationPage:[],annotation:[],contentResource:[],choice:[],range:[],service:[],agent:[],specificResource:[],geoJson:[],...t},this.options={allowUndefinedReturn:!1,...n}}static all(t){return new e({collection:[t],manifest:[t],canvas:[t],annotationCollection:[t],annotationPage:[t],annotation:[t],contentResource:[t],choice:[t],range:[t],service:[t],geoJson:[t],specificResource:[t],agent:[t]})}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=P(t.thumbnail).map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.provider&&(t.provider=t.provider.map(n=>this.traverseAgent(n,t))),t}traverseLinking(t){return t.seeAlso&&(t.seeAlso=t.seeAlso.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.service&&(t.service=P(t.service).map(n=>this.traverseService(n))),t.services&&(t.services=P(t.services).map(n=>this.traverseService(n,t))),t.logo&&(t.logo=t.logo.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.homepage&&(t.homepage=t.homepage.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.partOf&&(t.partOf=t.partOf.map(n=>typeof n=="string"||!n.type?this.traverseType(n,{parent:t},this.traversals.contentResource):n.type==="Canvas"?this.traverseType(n,{parent:t},this.traversals.canvas):n.type==="AnnotationCollection"?this.traverseType(n,{parent:t},this.traversals.annotationCollection):n.type==="Collection"?this.traverseType(n,{parent:t},this.traversals.collection):this.traverseType(n,{parent:t},this.traversals.contentResource))),t.start&&(h(t.start)?t.start=this.traverseSpecificResource(t.start,"Canvas",t):t.start=this.traverseType(t.start,{parent:t},this.traversals.canvas)),t.rendering&&(t.rendering=t.rendering.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.supplementary&&(t.supplementary=t.supplementary.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t}traverseCollectionItems(t){return t.items&&t.items.map(n=>n.type==="Collection"?this.traverseCollection(n):this.traverseManifest(n)),t}traverseCollection(t,n){return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traverseLinkedCanvases(this.traverseCollectionItems(t))))),{parent:n},this.traversals.collection)}traverseGeoJson(t,n){return this.traverseType(t,{parent:n},this.traversals.geoJson)}traverseNavPlace(t){return t.navPlace&&(t.navPlace=this.traverseGeoJson(t.navPlace,t)),t}traverseManifestItems(t){return t.items&&(t.items=t.items.map(n=>this.traverseCanvas(n))),t}traverseManifestStructures(t){return t.structures&&(t.structures=t.structures.map(n=>this.traverseRange(n))),t}traverseManifest(t,n){return this.traverseType(this._traverseManifest(t),{parent:n},this.traversals.manifest)}traverseCanvasItems(t){return t.items=(t.items||[]).map(n=>this.traverseAnnotationPage(n,t)),t}traverseInlineAnnotationPages(t){return typeof t=="string"||!t||t.annotations&&(t.annotations=t.annotations.map(n=>this.traverseAnnotationPage(n,t))),t}traverseCanvas(t,n){return this.traverseType(this._traverseCanvas(t),{parent:n},this.traversals.canvas)}traverseAnnotationPageItems(t){return t.items&&(t.items=t.items.map(n=>this.traverseAnnotation(n,t))),t}traverseAnnotationPage(t,n){return this.traverseType(this._traverseAnnotationPage(t),{parent:n},this.traversals.annotationPage)}traverseAnnotationBody(t){return Array.isArray(t.body)?t.body=t.body.map(n=>this.traverseContentResource(n,t)):t.body&&(t.body=this.traverseContentResource(t.body,t)),t}traverseLinkedCanvases(t){return t.placeholderCanvas&&(t.placeholderCanvas=this.traverseCanvas(t.placeholderCanvas)),t.accompanyingCanvas&&(t.accompanyingCanvas=this.traverseCanvas(t.accompanyingCanvas)),t}traverseAnnotation(t,n){return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(this.traverseDescriptive(t))),{parent:n},this.traversals.annotation)}traverseContentResourceLinking(t){return typeof t=="string"||!t||t&&t.service&&(t.service=P(t.service||[]).map(n=>this.traverseService(n,t))),t}traverseContentResource(t,n){return t.type==="Choice"&&(t.items=t.items.map(i=>this.traverseContentResource(i,t))),h(t)?this.traverseSpecificResource(t,"ContentResource"):this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(t)),{parent:n},this.traversals.contentResource)}traverseSpecificResource(t,n,i){let r=t.source;return typeof t.source=="string"&&(r={id:t.source,type:n||"unknown"}),this.traverseType({...t,source:n==="Canvas"||r.type==="Canvas"?this.traverseType(r,{parent:i},this.traversals.canvas):n==="ContentResource"?this.traverseContentResource(r,{parent:i}):this.traverseUnknown(r,{parent:i,typeHint:n})},{parent:i},this.traversals.specificResource)}traverseRangeRanges(t){return t.items&&(t.items=t.items.map(n=>typeof n=="string"?this.traverseCanvas({id:n,type:"Canvas"},t):h(n)?this.traverseSpecificResource(n,"Canvas",t):n.type==="Manifest"?this.traverseManifest(n,t):this.traverseRange(n,t))),t}traverseRange(t,n){return this.traverseType(this._traverseRange(t),{parent:n},this.traversals.range)}traverseAgent(t,n){return this.traverseType(this.traverseDescriptive(this.traverseLinking(t)),{parent:n},this.traversals.agent)}traverseType(t,n,i){return i.reduce((r,a)=>{let o=a(r,n);return typeof o>"u"&&!this.options.allowUndefinedReturn?r:o},t)}traverseService(t,n){let i=Object.assign({},t);return i&&i.service&&(i.service=P(i.service).map(r=>this.traverseService(r))),this.traverseType(i,{parent:n},this.traversals.service)}traverseUnknown(t,{parent:n,typeHint:i}={}){let r=ye(t,i);switch(r){case"Collection":return this.traverseCollection(t,n);case"Manifest":return this.traverseManifest(t,n);case"Canvas":return this.traverseCanvas(t,n);case"AnnotationPage":return this.traverseAnnotationPage(t,n);case"Annotation":return this.traverseAnnotation(t,n);case"ContentResource":return this.traverseContentResource(t,n);case"Range":return this.traverseRange(t,n);case"Service":return this.traverseService(t,n);case"Agent":return this.traverseAgent(t,n);default:throw new Error(`Unknown or unsupported resource type of ${r}`)}}};var he=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function st(e){if(typeof e>"u"||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"){let t=he.indexOf(e["@type"]);if(t!==-1)return he[t]}if(e.profile)return"Service";if(e.format||e["@type"])return"ContentResource";throw new Error("Resource type is not known")}var K=class e{constructor(t,n={}){m(this,"traversals");m(this,"options");this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...t},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...n}}static all(t){return new e({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){let n=[...(t.manifests||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i),...(t.collections||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i),...t.members||[]];delete t.collections,delete t.manifests,t.members=n}return t.manifests&&(t.manifests=t.manifests.map(n=>this.traverseManifest(typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n))),t.collections&&(t.collections=t.collections.map(n=>this.traverseCollection(typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n))),t.members&&(t.members=t.members.map(n=>typeof n=="string"?n:this.traverseUnknown(n))),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(n=>this.traverseSequence(n))),t.structures&&(t.structures=t.structures.map(n=>this.traverseRange(n))),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(n=>this.traverseCanvas(n))),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(n=>this.traverseAnnotation(n))),t.otherContent&&(t.otherContent=t.otherContent.map(n=>this.traverseAnnotationList(n))),t}traverseRange(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(t))),this.traversals.range)}traverseRangeItems(t){if(this.options.mergeMemberProperties){let n=[...(t.ranges||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Range"}:i),...(t.canvases||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Canvas"}:i),...t.members||[]];delete t.ranges,delete t.canvases,t.members=n.length?n.map(i=>this.traverseUnknown(i)):void 0}return t}traverseAnnotationList(t){let n=typeof t=="string"?{"@id":t,"@type":"sc:AnnotationList"}:t;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(n)),this.traversals.annotationList)}traverseAnnotationListItems(t){return t.resources&&(t.resources=t.resources.map(n=>this.traverseAnnotation(n))),t}traverseAnnotation(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(t))),this.traversals.annotation)}traverseAnnotationItems(t){return t.resource&&(Array.isArray(t.resource)?t.resource=t.resource.map(n=>this.traverseContentResource(n)):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(n=>this.traverseAnnotationList(n))),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(n=>this.traverseContentResource(n))),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(st(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"sc: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){let n=Array.isArray(t),i=Array.isArray(t)?t:[t],r=[];for(let a of i)typeof a=="string"?r.push(this.traverseContentResource({"@id":a,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(a));return!n&&!this.options.convertPropsToArray?r[0]:r}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=this.traverseImageResource(t.thumbnail)),t.logo&&(t.logo=this.traverseImageResource(t.logo)),t}traverseOneOrMoreServices(t){let n=Array.isArray(t),i=Array.isArray(t)?t:[t],r=[];for(let a of i)r.push(this.traverseService(a));return!n&&!this.options.convertPropsToArray?r[0]:r}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,n){if(!Array.isArray(t))if(this.options.convertPropsToArray)t=[t];else return this.traverseType(t,n);return t.map(i=>this.traverseType(i,n))}traverseType(t,n){return n.reduce((i,r)=>{let a=r(i);return typeof a>"u"&&!this.options.allowUndefinedReturn?i:a},t)}};var ot="http://library.stanford.edu/iiif/image-api/compliance.html#level0",me="http://library.stanford.edu/iiif/image-api/compliance.html#level1",ge="http://library.stanford.edu/iiif/image-api/compliance.html#level2",ct="http://library.stanford.edu/iiif/image-api/conformance.html#level0",Ce="http://library.stanford.edu/iiif/image-api/conformance.html#level1",Ae="http://library.stanford.edu/iiif/image-api/conformance.html#level2",lt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Re="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Te="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",pt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Se="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Pe="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",ft="http://iiif.io/api/image/1/level0.json",ut="http://iiif.io/api/image/1/profiles/level0.json",Ie="http://iiif.io/api/image/1/level1.json",xe="http://iiif.io/api/image/1/profiles/level1.json",be="http://iiif.io/api/image/1/level2.json",_e="http://iiif.io/api/image/1/profiles/level2.json",dt="http://iiif.io/api/image/2/level0.json",vt="http://iiif.io/api/image/2/profiles/level0.json",Ee="http://iiif.io/api/image/2/level1.json",Me="http://iiif.io/api/image/2/profiles/level1.json",Le="http://iiif.io/api/image/2/level2.json",we="http://iiif.io/api/image/2/profiles/level2.json",yt="level0",Ne="level1",Oe="level2",ht="http://iiif.io/api/image/2/level0",ze="http://iiif.io/api/image/2/level1",ke="http://iiif.io/api/image/2/level2",Fe=[ze,ke,me,ge,Ce,Ae,Re,Te,Se,Pe,Ie,xe,be,_e,Ee,Me,Le,we,Ne,Oe],De=[ht,ze,ke,ot,me,ge,ct,Ce,Ae,lt,Re,Te,pt,Se,Pe,ft,ut,Ie,xe,be,_e,dt,vt,Ee,Me,Le,we,yt,Ne,Oe];function g(e){for(let t in e)(typeof e[t]>"u"||e[t]===null)&&delete e[t];return e}var ce={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function mt(e){if(typeof e=="string")return[e];if(!e)return[];let t=Array.isArray(e)?e:[e],n=[];for(let i of t){if(typeof i=="string"){n.push(i);continue}n.push({"@language":i["@language"]||i.language,"@value":i["@value"]||i.value})}return n}function N(e,t="none"){if(!e)return{};let n=mt(e),i={};for(let r of n){if(typeof r=="string"){i[t]=i[t]?i[t]:[],i[t].push(r||"");continue}if(!r["@language"]){i[t]=i[t]?i[t]:[],i[t].push(r["@value"]||"");continue}let a=r["@language"];i[a]=i[a]?i[a]:[],i[a].push(r["@value"]||"")}return i}function Ue(e){if(Array.isArray(e))return Ue(e.find(t=>typeof t=="string"));if(De.indexOf(e)!==-1)return"level2";if(Fe.indexOf(e)!==-1)return"level1";if(typeof e=="string")return e}function gt(e){let t=Array.isArray(e)?e:[e];for(let n of t)switch(n){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 Ct(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 je(e){for(let t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}var At=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function fe(e){let t=e["@id"]||e.id,n=e["@type"]||e.type,i=e.profile||void 0,r=e["@context"]||void 0;if(i){let a=Ct(i);if(a)return a}if(r){let a=gt(r);if(a)return a}if(n){if(Array.isArray(n)){if(n.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(n.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";n=n[0]}for(let a of["sc","oa","dcterms","dctypes","iiif"])if(n.startsWith(`${a}:`)){n=n.slice(a.length+1);break}switch(n){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(n&&At.indexOf(n)!==-1)return n;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":n||"unknown"}var Rt=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Tt(e){let t=e.match(Rt);return t?t[0]:e}function St(e,t="Rights/License",n="none"){let i=null,r=[],a=Array.isArray(e)?e:[e];for(let o of a){let c=o?Tt(o):void 0;if(c&&(c.indexOf("creativecommons.org")!==-1||c.indexOf("rightsstatements.org")!==-1)){c.startsWith("https://")?i=`http://${c.slice(8)}`:i=c;continue}c&&r.push({label:{[n]:[t]},value:{[n]:[c]}})}return[i,r]}var 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 It(e){if(e){let t=Array.isArray(e)?e:[e],n=[];for(let i of t)i==="http://iiif.io/api/presentation/2/context.json"&&n.push("http://iiif.io/api/presentation/3/context.json"),Pt.indexOf(i)===-1&&n.push(i);if(t.length)return n.length===1?n[0]:n}}function xt(e){return e?e.map(t=>({label:N(t.label),value:N(t.value)})):[]}var qe=0;function Ge(e,t){let n=encodeURI(e.id||e["@id"]||"").trim();return n&&t?`${n}/${t}`:n||(qe++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${qe}`)}function R(e){let t=[...e.behavior||[]];e.viewingHint&&t.push(e.viewingHint);let n;return Array.isArray(e.motivation)?n=e.motivation.map(je):e.motivation&&(n=je(e.motivation)),{"@context":e["@context"]?It(e["@context"]):void 0,id:(e["@id"]||Ge(e)).trim(),type:fe(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:n,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function T(e){let[t,n]=St(e.license),i=[...e.metadata?xt(e.metadata):[],...n];return{rights:t,metadata:i.length?i:void 0,label:e.label?N(e.label):void 0,requiredStatement:e.attribution?{label:N(ce.attributionLabel),value:N(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?N(e.description):void 0,thumbnail:bt(e.thumbnail)}}function bt(e){return e&&(Array.isArray(e)?e:[e]).map(n=>typeof n=="string"?{id:n,type:"Image"}:(n.type==="unknown"&&(n.type="Image"),n))}function _t(e){if(!e.within)return;let t=Array.isArray(e.within)?e.within:[e.within],n=[];for(let i of t)if(typeof i=="string"){if(i)switch(e["@type"]){case"sc:Manifest":n.push({id:i,type:"Collection"});break}}else i["@id"]&&n.push({id:i["@id"],type:fe(i)});return n.length?n:void 0}function I(e){let t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],n=e.contentLayer;return{provider:e.logo||t.length?[{id:ce.providerId,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:N(ce.providerName)}]:void 0,partOf:_t(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?P(e.service):void 0,supplementary:n?[n]:void 0}}function Et(e){return{chars:e.chars,format:e.format?e.format:void 0,language:e.language}}function Mt(e){return g({...R(e),...T(e),...I(e),items:e.members})}function Lt(e){let t=[],n=[],i;for(let a of e.sequences||[])a.canvases.length&&t.push(...a.canvases),a.behavior&&n.push(...a.behavior),a.startCanvas&&(i=a.startCanvas);let r=R(e);return n.length&&(r.behavior?r.behavior.push(...n):r.behavior=n),g({...r,...T(e),...I(e),start:i,items:t,structures:e.structures})}function wt(e){return g({...R(e),...T(e),...I(e),annotations:e.otherContent&&e.otherContent.length?e.otherContent:void 0,items:e.images&&e.images.length?[{id:Ge(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}function Nt(e){return g({...R(e),...T(e),...I(e),items:e.resources&&e.resources.length?e.resources:void 0})}function Ot(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}}function zt(e){function t(n){if(Array.isArray(n)){if(n.length>1)return{type:"List",items:n.map(t)};n=n[0]}if(typeof n=="string")return encodeURI(n).trim();if("@type"in n){let i;if(typeof n.full=="string")i=n.full;else if(n.full["@type"]==="dctypes:Image")i={id:n.full["@id"],type:"Image"};else if(n.full["@type"]==="sc:Canvas")i={id:n.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${n.full["@type"]}`);return{type:"SpecificResource",source:i,selector:pe(n.selector)}}else return encodeURI(n["@id"]).trim()}return g({...R(e),...T(e),...I(e),target:t(e.on),body:Array.isArray(e.resource)?e.resource.map(le):le(e.resource)})}function le(e){let t=e;return g({...R(t),...T(t),...I(t),...Et(t)})}function kt(e){let t=[];return e.default&&e.default!=="rdf:nil"&&t.push(e.default),e.item&&e.item!=="rdf:nil"&&t.push(...e.item),{...R(e),...T(e),items:t}}function Ft(e){return g({...R(e),...T(e),...I(e),items:e.members})}function Dt(e){let{"@id":t,"@type":n,"@context":i,profile:r,...a}=e,o={};return t&&(o["@id"]=t),o["@type"]=fe(e),o["@type"]==="unknown"&&(i&&i.length&&(o["@context"]=i),o["@type"]="Service"),r&&(o.profile=Ue(r)),g({...o,...a})}function jt(e){return g({...R(e),...T(e),...I(e)})}var qt=new K({collection:[Mt],manifest:[Lt],canvas:[wt],annotationList:[Nt],sequence:[Ot],annotation:[zt],contentResource:[le],choice:[kt],range:[Ft],service:[Dt],layer:[jt]});function $e(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"?qt.traverseUnknown(e):e}function pe(e){if((Array.isArray(e["@type"])&&e["@type"].includes("oa:SvgSelector")||e["@type"]=="oa:SvgSelector")&&("chars"in e||"value"in e))return{type:"SvgSelector",value:"chars"in e?e.chars:e.value};if(e["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:e.value};if(e["@type"]==="oa:Choice")return[pe(e.default),...(Array.isArray(e.item)?e.item:[e.item]).map(pe)];if(e["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in e?e.region:void 0,rotation:"rotation"in e?e.rotation:void 0};throw new Error(`Unsupported selector type: ${e["@type"]}`)}function X(e,t={}){if(Array.isArray(e))return X(e[0]);if(typeof e=="string"){let[n,i]=e.split("#");return i?{type:"SpecificResource",source:{id:n,type:t.typeHint||"Unknown"},selector:{type:"FragmentSelector",value:i}}:{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||t.typeHint||"Unknown"}}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return X(e.items[0]);if(e.type==="SpecificResource")return e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]),e.selector?{type:"SpecificResource",source:e.source,selector:e.selector}:{type:"SpecificResource",source:e.source};if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);let[n,i]=e.id.split("#");return i?{type:"SpecificResource",source:{...e,id:n},selector:{type:"FragmentSelector",value:i}}:{type:"SpecificResource",source:{...e,id:n}}}return{type:"SpecificResource",source:e}}var Ut={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}};function We(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}function Ve(e,t){if(typeof e=="string")return{id:e,type:t};if(!e.id)throw new Error(`Invalid resource does not have an ID (${JSON.stringify(e)}, ${t})`);return e}function Gt(e,t){return(n,i)=>{let r=e[n]?e[n]:{};return(a,o)=>{let c=Ve(a,i||n);return c&&c.id&&n?(r[c.id]=r[c.id]?Q(r[c.id],c,{parent:o.parent,isTopLevel:t.id===c.id}):Q({id:c.id,type:c.type},c,{parent:o.parent,isTopLevel:t.id===c.id}),{id:c.id,type:n==="ContentResource"?n:c.type}):c}}}function J(e,t,n){if(!t)return e;if(Array.isArray(e)){if(!Array.isArray(t))throw new Error("Cannot merge array with non-array");let i=[...e];for(let r of t)if(r["@id"]&&!r.id&&(r.id=r["@id"]),r["@type"]&&!r.type&&(r.type=r["@type"]),r!=null)if(Array.isArray(r))i.push(r);else if(typeof r=="object"&&r.id&&r.type){let a=i.findIndex(o=>o.id===r.id&&o.type===r.type);a>=0&&(i[a]=J(i[a],r))}else e.indexOf(r)===-1&&i.push(r);return i}else if(typeof e=="object"){if(Array.isArray(t)||typeof t!="object")throw new Error("Cannot merge object with non-object");let i={...e},r=[],a=[],o=Object.keys(e).filter(l=>l!==u&&l!=="id"&&l!=="type"),c={},M={};for(let[l,f]of Object.entries(t)){if(l===u||l==="id"||l==="type")continue;let v=i[l];v===f?a.push(l):v===s||!v?(r.push(l),i[l]=f):(v&&f&&(c[l]=v,M[l]=f),i[l]=J(v,f),i[l]===c[l]&&(a.push(l),delete c[l]))}if(n&&(n.parent&&n.parent.id||n.isTopLevel)){let l=[],f={};if(n.parent?f[A]=n.parent.id:n.isTopLevel&&(f[A]=e.id),i[u]&&i[u].length){let v=!(i[u]||[]).find(C=>C["@explicit"]),L=r.length>0||a.length!==o.length;if(v&&L)for(let C of i[u]){let d={...C},Z=Object.keys(c);if(d){d["@explicit"]=!0;for(let j of o)j!==u&&(d[j]=w);for(let j of Z)d[j]=c[j]}l.push(d)}else l.push(...i[u]);if(L){let C=Object.keys(M);f["@explicit"]=!0;for(let d of r)f[d]=w;for(let d of a)f[d]=w;for(let d of C)f[d]=M[d]}}f.id=i.id,f.type=i.type,l.push(f),i[u]=l}return i}else if(e)return e;return t}function Q(e,t,n){if(typeof e=="string")return e;if(t.id!==e.id||t.type!==e.type){if(t.type==="ImageService3")return t;if(e.type==="ImageService3")return e;throw new Error(`Can only merge entities with identical identifiers and type! ${t.type}(${t.id}) => ${e.type}(${e.id})`)}return J({...e},t,n)}function $t(e){return(t,n)=>i=>{let{id:r,type:a}=Ve(i,n||t);if(typeof r>"u")throw new Error("Found invalid entity without an ID.");return t==="ContentResource"||t==="Service"?e[r]=t:e[r]=a,i}}function Wt(e){let t=Object.assign({},e);if(t["@id"]&&(t.id=t["@id"]),t["@type"]&&(t.type=t["@type"]),t.service){let n=[];t.service=Array.isArray(t.service)?t.service:[t.service];for(let i of t.service)n.push({id:i["@id"]||i.id,type:i["@type"]||i.type});t.service=n}return Object.assign({},se,t)}function Vt(e){return t=>{e.Service=e.Service?e.Service:{};let n=t.id||t["@id"],i=Wt(t);return i&&i.id&&(e.Service[i.id]?e.Service[n]=Q(e.Service[n],i):e.Service[n]=i),t}}function Ht(e){let t=JSON.stringify(e),n=5381,i=t.length;for(;i;)n=n*33^t.charCodeAt(--i);let a=(n>>>0).toString(16);return a.length%2?"0"+a:a}function ue(e){return t=>typeof t=="string"?{id:t,type:e}:t.id?t.type?t:{type:e,...t}:{id:`vault://${Ht(t)}`,type:e,...t}}function D(e){return t=>({...e,...t})}function $(e){return Array.isArray(e)?e:[e]}function Bt(e){return e.body&&(e.body=$(e.body)),e.seeAlso&&(e.seeAlso=$(e.seeAlso)),e.audience&&(e.audience=$(e.audience)),e.accessibility&&(e.accessibility=$(e.accessibility)),e.motivation&&(e.motivation=$(e.motivation)),e}function He(e,{typeHint:t,partOfTypeHint:n}={}){if(typeof e=="string"&&(e={id:e,type:t||"unknown"}),h(e))return typeof e.source=="string"&&(e.source={id:e.source,type:t||"unknown"}),e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:n||"Manifest"}]),e;let i;if((e.id||"").indexOf("#")!==-1){let[r,a]=(e.id||"").split("#");e.id=r,a&&(i={type:"FragmentSelector",value:a})}return{type:"SpecificResource",source:e,selector:i}}function Kt(e){let t=Object.assign({},e);return e&&e.items&&(t.items=e.items.map(n=>typeof n=="string"||n.type==="Canvas"?He(n):n)),t}function Xt(e){let t=Object.assign({},e);return t.start?(t.start=He(t.start,{typeHint:"Canvas"}),t):e}function Yt(e){let t=Object.assign({},e);return t.target?(t.target=X(t.target,{typeHint:"Canvas"}),t):e}function Be(e){return e}function Y(e){return typeof e.items>"u"&&(e[S]=!0),e}function Jt(e){let t=$e(e),n=We(),i={},r=Gt(n,t),a=$t(i),c=new G({collection:[Y,D(ne),a("Collection"),r("Collection")],manifest:[Y,D(ie),Xt,a("Manifest"),r("Manifest")],canvas:[D(te),a("Canvas"),r("Canvas")],annotationPage:[Y,ue("AnnotationPage"),D(ee),a("AnnotationPage"),r("AnnotationPage")],annotation:[ue("Annotation"),Bt,Yt,a("Annotation"),r("Annotation")],contentResource:[ue("ContentResource"),a("ContentResource"),r("ContentResource")],range:[D(re),Kt,a("Range","Canvas"),r("Range","Canvas")],agent:[D(ae),a("Agent"),r("Agent")],specificResource:[Be],service:[Vt(n)]}).traverseUnknown(t);return{entities:n,resource:c,mapping:i}}function Ke(e){let t={};for(let[n,i]of e){if(n===q&&i!==y)return i;i!==y&&typeof i<"u"&&i!==null&&(t[n]=i)}return t}function Qt(e,t,n){if(!t.type||!t.id)throw new Error("Unknown entity");if(!n[t.type])throw new Error(`Serializer not found for ${t.type}`);function i(r,a,o=0){let c=n[r.type];if(!c)return y;if(o>20)throw new Error("Circular reference: "+r.id+" "+r.type);let[M,l]=B(e,r.type?r:r.id,a)||(r.id&&r.type?r:null);if(!M)return y;let f=c(M,e,{parent:a,isTopLevel:t.id===r.id,fullResource:l}),v=f.next();for(;!v.done;){let L=v.value,C=y;if(L)if(Array.isArray(L)){let d=[];for(let Z of L)d.push(i(Z,r,o+1));C=d}else C=i(L,r,o+1);v=f.next(C)}return v.value===y?y:Ke(v.value)}return i(t)}function x(e,{allowSourceString:t=!0,allowString:n=!1,allowedStringType:i}={}){let r=a=>{if(t&&a&&a.source&&typeof a.source!="string"){let o=Object.keys(a.source);if(a.source.id&&a.source.type&&o.length===2)return{...a,source:a.source.id}}return a};if(e){if(e.source&&e.source.partOf)return r(e);let a=Object.keys(e);if(a.length===2&&e.type&&e.source||a.length===3&&e.type&&e.source&&a.indexOf("selector")!==-1&&!e.selector)return n&&(!i||i===e.source.type)?e.source.id:e.source.type==="ContentResource"?{type:"SpecificResource",source:e.source.id}:e.source;if(e.selector&&!Array.isArray(e.selector)&&typeof e.selector!="string"&&e.selector.type==="FragmentSelector"){let o=`${e.source.id}#${e.selector.value}`;return n?o:{id:o,type:e.source.type}}}return r(e)}function k(e){if(!e)return;let t=Object.keys(e);if(t.length!==0){if(t.length===1){let n=t[0];if(!n)return"";let i=(e[n]||[]).join("");return n==="@none"||n==="none"||n==="en"?i:{"@language":n,"@value":i}}return t.map(n=>({"@language":n,"@value":(e[n]||[]).join("")}))}}function Xe(e){return Array.isArray(e)?e.map(t=>Xe(t)):typeof e=="string"?e:e.type&&e.type==="Canvas"?e.id:e}function b(e,t=!1){if(e)return e.length>1&&!t?e:e[0]||void 0}function Zt(e){if(e){if(typeof e=="string")return{"@id":e};if("@id"in e){let t={...e};return delete t["@type"],t}return{"@context":"http://iiif.io/api/image/2/context.json","@id":e.id,profile:`http://iiif.io/api/image/2/profiles/${e.profile}.json`}}}function O(e,t){return[["@id",e.id],["@type",t],["format",e.format],["height",e.height],["width",e.width],["viewingDirection",e.viewingDirection!=="left-to-right"?e.viewingDirection:void 0],["license",e.license?e.license:void 0]]}function*z(e){let t=e.provider?yield e.provider[0]:void 0;return[["label",k(e.label)],["metadata",e.metadata&&e.metadata.length?e.metadata.map(n=>({label:k(n.label)||"",value:k(n.value)||""})):void 0],["description",k(e.summary)],["thumbnail",b(yield e.thumbnail)],["navDate",e.navDate],["logo",t?b(t.logo):void 0],["homepage",t?t.homepage:void 0],["attribution",e.requiredStatement?k(e.requiredStatement.value):void 0]]}function*W(e){let t=e.start&&e.start.type&&e.start.type==="SpecificResource"?x(e.start):e.start;return[["seeAlso",b(yield e.seeAlso)],["service",b((e.service||[]).map(Zt))],["rendering",b(yield e.rendering)],["startCanvas",t?t.id:void 0]]}function en(e){return e.type==="SpecificResource"}function tn(e){return e&&e.type==="FragmentSelector"}function nn(e){if(e&&en(e)){let t=e.id,n=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return tn(n)&&(t+="#"+n.value),t}return e?.id}var rn={Manifest:function*(e,t,{isTopLevel:n}){return[...n?[["@context","http://iiif.io/api/presentation/2/context.json"]]:[],...O(e,"sc:Manifest"),...yield*z(e),...yield*W(e),["sequences",[{"@id":`${e.id}/sequence0`,"@type":"sc:Sequence",canvases:yield e.items}]],["structures",yield e.structures]]},Canvas:function*(e){let n=(yield e.items)[0];return[...O(e,"sc:Canvas"),...yield*z(e),...yield*W(e),["images",n?[n.resources]:void 0],["annotations",e.annotations&&e.annotations.length?b(yield e.annotations):void 0]]},AnnotationPage:function*(e){return[...O(e,"sc:AnnotationList"),...yield*z(e),["resources",e.items&&e.items.length?b(yield e.items):void 0]]},Annotation:function*(e){return[["@id",e.id],["@type","oa:Annotation"],["motivation","sc:painting"],["on",Xe(e.target)],["resource",b(yield e.body,!0)]]},ContentResource:function*(e){switch(e.type){case"Image":return[...O(e,"dctypes:Image"),...yield*z(e),...yield*W(e)];case"Text":case"Dataset":default:return[...O(e,void 0),...yield*z(e)]}},AnnotationCollection:function*(e){return[["@id",e.id],["@type","sc:Layer"],["label",k(e.label)]]},Collection:function*(e){return[...O(e,"sc:Collection"),...yield*z(e),...yield*W(e),["members",yield*e.items]]},Range:function*(e){let t=[],n=[];if(e.items)for(let i of e.items){let r=i.type==="SpecificResource"?i.source:i;if(r){let a=yield r;t.push({"@id":nn(i),"@type":r.type,label:a?a.label:void 0,within:e.id}),r.type==="Canvas"&&n.push(r.id)}}return[...O(e,"sc:Range"),...yield*z(e),...yield*W(e),["canvases",n.length===t.length?n:void 0],["members",n.length!==t.length?t:void 0]]}};function F(e){return[["id",e.id?.startsWith("vault://")?void 0:e.id],["type",e.type],["format",e.format],["profile",e.profile],["height",e.height||void 0],["width",e.width||void 0],["duration",e.duration||void 0],["viewingDirection",e.viewingDirection!=="left-to-right"?e.viewingDirection:void 0],["behavior",e.behavior&&e.behavior.length?e.behavior:void 0],["timeMode",e.timeMode],["motivation",Array.isArray(e.motivation)?e.motivation[0]:e.motivation],[u,y]]}function p(e){if(e===y||!e||e.length===0)return;let t=e.filter(n=>n!==y);if(t.length!==0)return t}function Je(e){if(e&&e.type&&e.type==="ImageService2"){let{id:t,type:n,profile:i,...r}=e,a=typeof i=="string"?i:Array.isArray(i)?i.find(o=>typeof o=="string"):"";return{"@id":t,"@type":n,profile:a?a.startsWith("http")?a:`http://iiif.io/api/image/2/${a}.json`:"http://iiif.io/api/image/2/level0.json",...r}}return e}function Ye(e){if(Array.isArray(e)||(e=e?[e]:[]),!(!e||e.length===0))return e.map(Je)}function*_(e){return[["label",e.label],["metadata",p(e.metadata)],["summary",e.summary],["requiredStatement",e.requiredStatement],["rights",Array.isArray(e.rights)?e.rights[0]||void 0:e.rights||void 0],["navDate",e.navDate],["language",e.language],["thumbnail",p(yield e.thumbnail)],["placeholderCanvas",yield e.placeholderCanvas],["accompanyingCanvas",yield e.accompanyingCanvas],["provider",p(yield e.provider)]]}function*E(e){return[["seeAlso",p(yield e.seeAlso)],["service",p(Ye(e.service))],["services",p(Ye(e.services))],["rendering",p(yield e.rendering)],["supplementary",p(yield e.supplementary)],["homepage",p(yield e.homepage)],["logo",p(yield e.logo)],["partOf",p(yield e.partOf)],["start",e.start?x(e.start):e.start]]}var an={Manifest:function*(e,t,{isTopLevel:n}){return n?[["@context",e["@context"]?e["@context"]:"http://iiif.io/api/presentation/3/context.json"],...F(e),...yield*_(e),...yield*E(e),["items",yield e.items],["structures",p(yield e.structures)],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]:[...F(e),...yield*_(e)]},Canvas:function*(e){return[...F(e),...yield*_(e),...yield*E(e),["items",yield e.items],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]},Agent:function*(e){return[["id",e.id],["type","Agent"],["label",e.label],...yield*E(e)]},AnnotationPage:function*(e){let t=Object.entries(e).map(([i,r])=>[i,Array.isArray(r)?p(r):r]).filter(([i,r])=>i!=="items"&&i!=="id"&&i!==u&&i!==A&&i!==S),n=yield e.items;return[["id",e.id?.startsWith("vault://")?void 0:e.id],...t,...yield*E(e),["items",n.length||e[S]===!1?n:y]]},Service:function*(e){return[[q,Je(e)]]},Annotation:function*(e){let t=Object.entries(e).map(([i,r])=>i==="motivation"?[i,Array.isArray(r)?r[0]:r]:i==="target"?[i,x(r,{allowString:!0,allowSourceString:!0,allowedStringType:"Canvas"})]:[i,Array.isArray(r)?p(r):r]).filter(([i])=>i!=="body"&&i!==u&&i!==S),n;if(Array.isArray(e.body)){let i=[];for(let r of e.body)if(r&&h(r)){let a={...r};a.source=yield r.source,i.push(x(a,{allowSourceString:!0}))}else i.push(yield r);n=i}else e.body&&h(e.body)?(n={...e.body},n.source=yield e.body.source):n=yield e.body;return[...t,...yield*_(e),...yield*E(e),["body",n.length===1?n[0]:n]]},ContentResource:function*(e){return sn([...F(e),...yield*_(e),...yield*E(e),["annotations",p(yield e.annotations)],["items",p(yield e.items)]],e)},AnnotationCollection:function*(e){return[["id",e.id],["type","AnnotationCollection"],["label",e.label]]},Collection:function*(e,t,{isTopLevel:n}){return n?[["@context","http://iiif.io/api/presentation/3/context.json"],...F(e),...yield*_(e),...yield*E(e),["items",p(yield e.items)],["navPlace",e.navPlace]]:[...F(e),...yield*_(e)]},Range:function*(e){let t=[];for(let n of e.items)n.type==="Range"?t.push(yield n):n&&n.type==="SpecificResource"?t.push(x(n)):t.push(n);return[...F(e),...yield*_(e),...yield*E(e),["items",t],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]}};function sn(e,t){let n=Object.keys(t),i=e.map(([r])=>r);for(let r of n)r===u||r===S||i.indexOf(r)===-1&&typeof t[r]<"u"&&e.push([r,t[r]]);return e}
"use strict";var B=Object.defineProperty;var et=Object.getOwnPropertyDescriptor;var tt=Object.getOwnPropertyNames;var nt=Object.prototype.hasOwnProperty;var it=(e,t,n)=>t in e?B(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var rt=(e,t)=>{for(var n in t)B(e,n,{get:t[n],enumerable:!0})},at=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of tt(t))!nt.call(e,r)&&r!==n&&B(e,r,{get:()=>t[r],enumerable:!(i=et(t,r))||i.enumerable});return e};var st=e=>at(B({},"__esModule",{value:!0}),e);var g=(e,t,n)=>(it(e,typeof t!="symbol"?t+"":t,n),n);var Mn={};rt(Mn,{EMPTY:()=>s,HAS_PART:()=>u,IS_EXTERNAL:()=>T,PART_OF:()=>C,Traverse:()=>q,UNSET:()=>y,UNWRAP:()=>G,WILDCARD:()=>N,addFlagForExternalResource:()=>Q,compressSpecificResource:()=>_,defaultEntities:()=>fn,emptyAgent:()=>ae,emptyAnnotation:()=>ot,emptyAnnotationPage:()=>ee,emptyCanvas:()=>te,emptyCollection:()=>ne,emptyManifest:()=>ie,emptyRange:()=>re,emptyService:()=>se,frameResource:()=>ve,getDefaultEntities:()=>$e,identifyResource:()=>ye,isSpecificResource:()=>h,isWildcard:()=>de,languageString2to3:()=>z,merge:()=>X,mergeEntities:()=>Y,normalize:()=>Rn,resolveIfExists:()=>H,serialize:()=>In,serializeConfigPresentation2:()=>xn,serializeConfigPresentation3:()=>En,serializedFieldsToObject:()=>Qe,toRef:()=>$,traverseSpecificResource:()=>Je,types:()=>oe});module.exports=st(Mn);function h(e){return typeof e=="string"?!1:!!e&&e.type==="SpecificResource"}function $(e,t){let n=t||"unknown";if(!e)return;if(typeof e=="string")return{id:e,type:n};if(h(e))return $(e.source,t);let i=n&&n!=="unknown"?n:e.type||e["@type"],r=e.id||e["@id"];if(i&&i.indexOf(":")!==-1&&(i=i.split(":").pop()),r&&i)return{id:r,type:i}}var N={},u="iiif-parser:hasPart",C="iiif-parser:partOf",T="iiif-parser:isExternal",y="__$UNSET$__",G="__$UNWRAP$__",s=[];Object.freeze(s);Object.freeze(N);function de(e){if(e===N||Object.keys(e).length===0)return!0;for(let t in e)return!1;return!0}function ve(e,t){if(t&&t["@explicit"]){let n={},i=Object.keys(t);for(let r of i)r===C||r==="@explicit"||(de(t[r])?n[r]=e[r]:n[r]=t[r]);return n}return e}function H(e,t,n){let i=$(t);if(!i)return[void 0,void 0];let r=e.requests[i.id],a=i.type||e.mapping[i.id];if(!a||r&&r.resourceUri&&(!e.entities[a]||!e.entities[a][r.resourceUri]))return[void 0,void 0];let o=e.entities[a][r?r.resourceUri:i.id];if(i.type&&!o)return H(e,{id:i.id},n);if(o&&o[u]){let l=o[u].find(c=>n?c[C]===n.id:c[C]===o.id);return[ve(o,l),o]}return[o,o]}var ot={id:"https://iiif-parser/annotation",type:"Annotation",behavior:s,label:null,thumbnail:s,summary:null,requiredStatement:null,metadata:s,seeAlso:s,homepage:s,rendering:s,service:s,accessibility:s,audience:s,body:s,bodyValue:null,canonical:null,created:null,creator:s,generated:null,generator:s,modified:null,motivation:s,rights:null,stylesheet:null,target:s,timeMode:void 0,via:s,partOf:s},ee={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:s,label:null,thumbnail:s,summary:null,requiredStatement:null,metadata:s,rights:null,provider:s,items:s,seeAlso:s,homepage:s,rendering:s,service:s},te={id:"https://iiif-parser/empty-canvas",type:"Canvas",label:null,behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,duration:0,height:0,width:0},ne={id:"https://iiif-parser/empty-collection",type:"Collection",label:null,viewingDirection:"left-to-right",behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,services:s},ie={id:"https://iiif-parser/empty-manifest",type:"Manifest",annotations:s,behavior:s,homepage:s,items:s,label:null,metadata:s,navDate:null,provider:s,partOf:s,accompanyingCanvas:null,placeholderCanvas:null,rendering:s,requiredStatement:null,rights:null,seeAlso:s,service:s,services:s,start:null,structures:s,summary:null,thumbnail:s,viewingDirection:"left-to-right"},re={id:"https://iiif-parser/empty-canvas",type:"Range",label:null,behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,start:null,supplementary:null,viewingDirection:"left-to-right"},ae={id:"https://iiif-parser/empty-agent",type:"Agent",label:{},logo:s,seeAlso:s,homepage:s},se={id:"https://iiif-parser/empty-service",type:"UnknownService"};function S(e){return Array.isArray(e)?e:e?[e]:[]}function U(...e){return t=>e.reduce((n,i)=>i(n),t)}var oe=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function ye(e,t){if(typeof e>"u"||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"){if(t)return t;throw new Error(`${typeof e} is not a valid entity`)}if(typeof e.type=="string"){let n=oe.indexOf(e.type);if(n!==-1)return oe[n]}if(e.profile)return"Service";throw new Error("Resource type is not known")}var q=class e{constructor(t,n={}){g(this,"traversals");g(this,"options");g(this,"_traverseManifest",U(this.traverseManifestItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseManifestStructures.bind(this),this.traverseInlineAnnotationPages.bind(this)));g(this,"_traverseCanvas",U(this.traverseCanvasItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseInlineAnnotationPages.bind(this)));g(this,"_traverseAnnotationPage",U(this.traverseAnnotationPageItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this)));g(this,"_traverseRange",U(this.traverseRangeRanges.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this)));this.traversals={collection:[],manifest:[],canvas:[],annotationCollection:[],annotationPage:[],annotation:[],contentResource:[],choice:[],range:[],service:[],agent:[],specificResource:[],geoJson:[],...t},this.options={allowUndefinedReturn:!1,...n}}static all(t){return new e({collection:[t],manifest:[t],canvas:[t],annotationCollection:[t],annotationPage:[t],annotation:[t],contentResource:[t],choice:[t],range:[t],service:[t],geoJson:[t],specificResource:[t],agent:[t]})}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=S(t.thumbnail).map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.provider&&(t.provider=t.provider.map(n=>this.traverseAgent(n,t))),t}traverseLinking(t){return t.seeAlso&&(t.seeAlso=t.seeAlso.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.service&&(t.service=S(t.service).map(n=>this.traverseService(n))),t.services&&(t.services=S(t.services).map(n=>this.traverseService(n,t))),t.logo&&(t.logo=t.logo.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.homepage&&(t.homepage=t.homepage.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.partOf&&(t.partOf=t.partOf.map(n=>typeof n=="string"||!n.type?this.traverseType(n,{parent:t},this.traversals.contentResource):n.type==="Canvas"?this.traverseType(n,{parent:t},this.traversals.canvas):n.type==="AnnotationCollection"?this.traverseType(n,{parent:t},this.traversals.annotationCollection):n.type==="Collection"?this.traverseType(n,{parent:t},this.traversals.collection):this.traverseType(n,{parent:t},this.traversals.contentResource))),t.start&&(h(t.start)?t.start=this.traverseSpecificResource(t.start,"Canvas",t):t.start=this.traverseType(t.start,{parent:t},this.traversals.canvas)),t.rendering&&(t.rendering=t.rendering.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.supplementary&&(t.supplementary=t.supplementary.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t}traverseCollectionItems(t){return t.items&&t.items.map(n=>n.type==="Collection"?this.traverseCollection(n):this.traverseManifest(n)),t}traverseCollection(t,n){return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traverseLinkedCanvases(this.traverseCollectionItems(t))))),{parent:n},this.traversals.collection)}traverseGeoJson(t,n){return this.traverseType(t,{parent:n},this.traversals.geoJson)}traverseNavPlace(t){return t.navPlace&&(t.navPlace=this.traverseGeoJson(t.navPlace,t)),t}traverseManifestItems(t){return t.items&&(t.items=t.items.map(n=>this.traverseCanvas(n))),t}traverseManifestStructures(t){return t.structures&&(t.structures=t.structures.map(n=>this.traverseRange(n))),t}traverseManifest(t,n){return this.traverseType(this._traverseManifest(t),{parent:n},this.traversals.manifest)}traverseCanvasItems(t){return t.items=(t.items||[]).map(n=>this.traverseAnnotationPage(n,t)),t}traverseInlineAnnotationPages(t){return typeof t=="string"||!t||t.annotations&&(t.annotations=t.annotations.map(n=>this.traverseAnnotationPage(n,t))),t}traverseCanvas(t,n){return this.traverseType(this._traverseCanvas(t),{parent:n},this.traversals.canvas)}traverseAnnotationPageItems(t){return t.items&&(t.items=t.items.map(n=>this.traverseAnnotation(n,t))),t}traverseAnnotationPage(t,n){return this.traverseType(this._traverseAnnotationPage(t),{parent:n},this.traversals.annotationPage)}traverseAnnotationBody(t){return Array.isArray(t.body)?t.body=t.body.map(n=>this.traverseContentResource(n,t)):t.body&&(t.body=this.traverseContentResource(t.body,t)),t}traverseLinkedCanvases(t){return t.placeholderCanvas&&(t.placeholderCanvas=this.traverseCanvas(t.placeholderCanvas)),t.accompanyingCanvas&&(t.accompanyingCanvas=this.traverseCanvas(t.accompanyingCanvas)),t}traverseAnnotation(t,n){return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(this.traverseDescriptive(t))),{parent:n},this.traversals.annotation)}traverseContentResourceLinking(t){return typeof t=="string"||!t||t&&t.service&&(t.service=S(t.service||[]).map(n=>this.traverseService(n,t))),t}traverseContentResource(t,n){return t.type==="Choice"&&(t.items=t.items.map(i=>this.traverseContentResource(i,t))),h(t)?this.traverseSpecificResource(t,"ContentResource"):this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(t)),{parent:n},this.traversals.contentResource)}traverseSpecificResource(t,n,i){let r=t.source;return typeof t.source=="string"&&(r={id:t.source,type:n||"unknown"}),this.traverseType({...t,source:n==="Canvas"||r.type==="Canvas"?this.traverseType(r,{parent:i},this.traversals.canvas):n==="ContentResource"?this.traverseContentResource(r,{parent:i}):this.traverseUnknown(r,{parent:i,typeHint:n})},{parent:i},this.traversals.specificResource)}traverseRangeRanges(t){return t.items&&(t.items=t.items.map(n=>typeof n=="string"?this.traverseCanvas({id:n,type:"Canvas"},t):h(n)?this.traverseSpecificResource(n,"Canvas",t):n.type==="Manifest"?this.traverseManifest(n,t):this.traverseRange(n,t))),t}traverseRange(t,n){return this.traverseType(this._traverseRange(t),{parent:n},this.traversals.range)}traverseAgent(t,n){return this.traverseType(this.traverseDescriptive(this.traverseLinking(t)),{parent:n},this.traversals.agent)}traverseType(t,n,i){return i.reduce((r,a)=>{let o=a(r,n);return typeof o>"u"&&!this.options.allowUndefinedReturn?r:o},t)}traverseService(t,n){let i=Object.assign({},t);return i&&i.service&&(i.service=S(i.service).map(r=>this.traverseService(r))),this.traverseType(i,{parent:n},this.traversals.service)}traverseUnknown(t,{parent:n,typeHint:i}={}){let r=ye(t,i);switch(r){case"Collection":return this.traverseCollection(t,n);case"Manifest":return this.traverseManifest(t,n);case"Canvas":return this.traverseCanvas(t,n);case"AnnotationPage":return this.traverseAnnotationPage(t,n);case"Annotation":return this.traverseAnnotation(t,n);case"ContentResource":return this.traverseContentResource(t,n);case"Range":return this.traverseRange(t,n);case"Service":return this.traverseService(t,n);case"Agent":return this.traverseAgent(t,n);default:throw new Error(`Unknown or unsupported resource type of ${r}`)}}};var he=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function lt(e){if(typeof e>"u"||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"){let t=he.indexOf(e["@type"]);if(t!==-1)return he[t]}if(e.profile)return"Service";if(e.format||e["@type"])return"ContentResource";throw new Error("Resource type is not known")}var K=class e{constructor(t,n={}){g(this,"traversals");g(this,"options");this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...t},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...n}}static all(t){return new e({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){let n=[...(t.manifests||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i),...(t.collections||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i),...t.members||[]];delete t.collections,delete t.manifests,t.members=n}return t.manifests&&(t.manifests=t.manifests.map(n=>this.traverseManifest(typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n))),t.collections&&(t.collections=t.collections.map(n=>this.traverseCollection(typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n))),t.members&&(t.members=t.members.map(n=>typeof n=="string"?n:this.traverseUnknown(n))),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(n=>this.traverseSequence(n))),t.structures&&(t.structures=t.structures.map(n=>this.traverseRange(n))),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(n=>this.traverseCanvas(n))),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(n=>this.traverseAnnotation(n))),t.otherContent&&(t.otherContent=t.otherContent.map(n=>this.traverseAnnotationList(n))),t}traverseRange(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(t))),this.traversals.range)}traverseRangeItems(t){if(this.options.mergeMemberProperties){let n=[...(t.ranges||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Range"}:i),...(t.canvases||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Canvas"}:i),...t.members||[]];delete t.ranges,delete t.canvases,t.members=n.length?n.map(i=>this.traverseUnknown(i)):void 0}return t}traverseAnnotationList(t){let n=typeof t=="string"?{"@id":t,"@type":"sc:AnnotationList"}:t;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(n)),this.traversals.annotationList)}traverseAnnotationListItems(t){return t.resources&&(t.resources=t.resources.map(n=>this.traverseAnnotation(n))),t}traverseAnnotation(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(t))),this.traversals.annotation)}traverseAnnotationItems(t){return t.resource&&(Array.isArray(t.resource)?t.resource=t.resource.map(n=>this.traverseContentResource(n)):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(n=>this.traverseAnnotationList(n))),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(n=>this.traverseContentResource(n))),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(lt(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"sc: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){let n=Array.isArray(t),i=Array.isArray(t)?t:[t],r=[];for(let a of i)typeof a=="string"?r.push(this.traverseContentResource({"@id":a,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(a));return!n&&!this.options.convertPropsToArray?r[0]:r}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=this.traverseImageResource(t.thumbnail)),t.logo&&(t.logo=this.traverseImageResource(t.logo)),t}traverseOneOrMoreServices(t){let n=Array.isArray(t),i=Array.isArray(t)?t:[t],r=[];for(let a of i)r.push(this.traverseService(a));return!n&&!this.options.convertPropsToArray?r[0]:r}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,n){if(!Array.isArray(t))if(this.options.convertPropsToArray)t=[t];else return this.traverseType(t,n);return t.map(i=>this.traverseType(i,n))}traverseType(t,n){return n.reduce((i,r)=>{let a=r(i);return typeof a>"u"&&!this.options.allowUndefinedReturn?i:a},t)}};var ct="http://library.stanford.edu/iiif/image-api/compliance.html#level1",pt="http://library.stanford.edu/iiif/image-api/compliance.html#level2";var ft="http://library.stanford.edu/iiif/image-api/conformance.html#level1",ut="http://library.stanford.edu/iiif/image-api/conformance.html#level2";var dt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",vt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2";var yt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",ht="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2";var mt="http://iiif.io/api/image/1/level1.json",gt="http://iiif.io/api/image/1/profiles/level1.json",At="http://iiif.io/api/image/1/level2.json",Ct="http://iiif.io/api/image/1/profiles/level2.json";var Rt="http://iiif.io/api/image/2/level1.json",It="http://iiif.io/api/image/2/profiles/level1.json",Tt="http://iiif.io/api/image/2/level2.json",St="http://iiif.io/api/image/2/profiles/level2.json";var Pt="level1",_t="level2";var xt="http://iiif.io/api/image/2/level1",Et="http://iiif.io/api/image/2/level2",me=[xt,Et,ct,pt,ft,ut,dt,vt,yt,ht,mt,gt,At,Ct,Rt,It,Tt,St,Pt,_t];function m(e){for(let t in e)(typeof e[t]>"u"||e[t]===null)&&delete e[t];return e}var Lt="http://library.stanford.edu/iiif/image-api/compliance.html#level0",ge="http://library.stanford.edu/iiif/image-api/compliance.html#level1",Ae="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Mt="http://library.stanford.edu/iiif/image-api/conformance.html#level0",Ce="http://library.stanford.edu/iiif/image-api/conformance.html#level1",Re="http://library.stanford.edu/iiif/image-api/conformance.html#level2",bt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Ie="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Te="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Nt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Se="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Pe="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Ot="http://iiif.io/api/image/1/level0.json",Ft="http://iiif.io/api/image/1/profiles/level0.json",_e="http://iiif.io/api/image/1/level1.json",xe="http://iiif.io/api/image/1/profiles/level1.json",Ee="http://iiif.io/api/image/1/level2.json",Le="http://iiif.io/api/image/1/profiles/level2.json",wt="http://iiif.io/api/image/2/level0.json",zt="http://iiif.io/api/image/2/profiles/level0.json",Me="http://iiif.io/api/image/2/level1.json",be="http://iiif.io/api/image/2/profiles/level1.json",Ne="http://iiif.io/api/image/2/level2.json",Oe="http://iiif.io/api/image/2/profiles/level2.json",kt="level0",Fe="level1",we="level2",Dt="http://iiif.io/api/image/2/level0",ze="http://iiif.io/api/image/2/level1",ke="http://iiif.io/api/image/2/level2",le=[ke,Ae,Re,Te,Pe,Ee,Le,Ne,Oe,we],Qn=[...le,ze,ge,Ce,Ie,Se,_e,xe,Me,be,Fe],jt=[Dt,ze,ke,Lt,ge,Ae,Mt,Ce,Re,bt,Ie,Te,Nt,Se,Pe,Ot,Ft,_e,xe,Ee,Le,wt,zt,Me,be,Ne,Oe,kt,Fe,we],De=jt;var ce={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function Gt(e){if(typeof e=="string")return[e];if(!e)return[];let t=Array.isArray(e)?e:[e],n=[];for(let i of t){if(typeof i=="string"){n.push(i);continue}n.push({"@language":i["@language"]||i.language,"@value":i["@value"]||i.value})}return n}function O(e,t="none"){if(!e)return{};let n=Gt(e),i={};for(let r of n){if(typeof r=="string"){i[t]=i[t]?i[t]:[],i[t].push(r||"");continue}if(!r["@language"]){i[t]=i[t]?i[t]:[],i[t].push(r["@value"]||"");continue}let a=r["@language"];i[a]=i[a]?i[a]:[],i[a].push(r["@value"]||"")}return i}function qe(e){if(Array.isArray(e))return qe(e.find(t=>typeof t=="string"));if(le.indexOf(e)!==-1)return"level2";if(me.indexOf(e)!==-1)return"level1";if(De.indexOf(e)!==-1)return"level0";if(typeof e=="string")return e}function Ut(e){let t=Array.isArray(e)?e:[e];for(let n of t)switch(n){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 qt(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 je(e){for(let t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}var Vt=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function fe(e){let t=e["@id"]||e.id,n=e["@type"]||e.type,i=e.profile||void 0,r=e["@context"]||void 0;if(i){let a=qt(i);if(a)return a}if(r){let a=Ut(r);if(a)return a}if(n){if(Array.isArray(n)){if(n.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(n.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";n=n[0]}for(let a of["sc","oa","dcterms","dctypes","iiif"])if(n.startsWith(`${a}:`)){n=n.slice(a.length+1);break}switch(n){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(n&&Vt.indexOf(n)!==-1)return n;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":n||"unknown"}var Wt=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Bt(e){let t=e.match(Wt);return t?t[0]:e}function $t(e,t="Rights/License",n="none"){let i=null,r=[],a=Array.isArray(e)?e:[e];for(let o of a){let l=o?Bt(o):void 0;if(l&&(l.indexOf("creativecommons.org")!==-1||l.indexOf("rightsstatements.org")!==-1)){l.startsWith("https://")?i=`http://${l.slice(8)}`:i=l;continue}l&&r.push({label:{[n]:[t]},value:{[n]:[l]}})}return[i,r]}var Ht=["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 Kt(e){if(e){let t=Array.isArray(e)?e:[e],n=[];for(let i of t)i==="http://iiif.io/api/presentation/2/context.json"&&n.push("http://iiif.io/api/presentation/3/context.json"),Ht.indexOf(i)===-1&&n.push(i);if(t.length)return n.length===1?n[0]:n}}function Jt(e){return e?e.map(t=>({label:O(t.label),value:O(t.value)})):[]}var Ge=0;function Ve(e,t){let n=encodeURI(e.id||e["@id"]||"").trim();return n&&t?`${n}/${t}`:n||(Ge++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${Ge}`)}function R(e){let t=[...e.behavior||[]];e.viewingHint&&t.push(e.viewingHint);let n;return Array.isArray(e.motivation)?n=e.motivation.map(je):e.motivation&&(n=je(e.motivation)),{"@context":e["@context"]?Kt(e["@context"]):void 0,id:(e["@id"]||Ve(e)).trim(),type:fe(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:n,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function I(e){let[t,n]=$t(e.license),i=[...e.metadata?Jt(e.metadata):[],...n];return{rights:t,metadata:i.length?i:void 0,label:e.label?O(e.label):void 0,requiredStatement:e.attribution?{label:O(ce.attributionLabel),value:O(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?O(e.description):void 0,thumbnail:Qt(e.thumbnail)}}function Qt(e){return e&&(Array.isArray(e)?e:[e]).map(n=>typeof n=="string"?{id:n,type:"Image"}:(n.type==="unknown"&&(n.type="Image"),n))}function Xt(e){if(!e.within)return;let t=Array.isArray(e.within)?e.within:[e.within],n=[];for(let i of t)if(typeof i=="string"){if(i)switch(e["@type"]){case"sc:Manifest":n.push({id:i,type:"Collection"});break}}else i["@id"]&&n.push({id:i["@id"],type:fe(i)});return n.length?n:void 0}function P(e){let t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],n=e.contentLayer;return{provider:e.logo||t.length?[{id:ce.providerId,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:O(ce.providerName)}]:void 0,partOf:Xt(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?S(e.service):void 0,supplementary:n?[n]:void 0}}function Yt(e){return{chars:e.chars,format:e.format?e.format:void 0,language:e.language}}function Zt(e){return m({...R(e),...I(e),...P(e),items:e.members})}function en(e){let t=[],n=[],i;for(let a of e.sequences||[])a.canvases.length&&t.push(...a.canvases),a.behavior&&n.push(...a.behavior),a.startCanvas&&(i=a.startCanvas);let r=R(e);return n.length&&(r.behavior?r.behavior.push(...n):r.behavior=n),m({...r,...I(e),...P(e),start:i,items:t,structures:e.structures})}function tn(e){return m({...R(e),...I(e),...P(e),annotations:e.otherContent&&e.otherContent.length?e.otherContent:void 0,items:e.images&&e.images.length?[{id:Ve(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}function nn(e){return m({...R(e),...I(e),...P(e),items:e.resources&&e.resources.length?e.resources:void 0})}function rn(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}}function an(e){function t(n){if(Array.isArray(n)){if(n.length>1)return{type:"List",items:n.map(t)};n=n[0]}if(typeof n=="string")return encodeURI(n).trim();if("@type"in n){let i;if(typeof n.full=="string")i=n.full;else if(n.full["@type"]==="dctypes:Image")i={id:n.full["@id"],type:"Image"};else if(n.full["@type"]==="sc:Canvas")i={id:n.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${n.full["@type"]}`);return{type:"SpecificResource",source:i,selector:pe(n.selector)}}else return encodeURI(n["@id"]).trim()}return m({...R(e),...I(e),...P(e),target:t(e.on),body:Array.isArray(e.resource)?e.resource.map(Ue):Ue(e.resource)})}function Ue(e){return e.type==="Choice"?e:We(e)}function We(e){let t=e;return m({...R(t),...I(t),...P(t),...Yt(t)})}function sn(e){let t=[];return e.default&&e.default!=="rdf:nil"&&t.push(e.default),e.item&&e.item!=="rdf:nil"&&t.push(...e.item),m({...R(e),...I(e),items:t})}function on(e){return m({...R(e),...I(e),...P(e),items:e.members})}function ln(e){let{"@id":t,"@type":n,"@context":i,profile:r,...a}=e,o={};return t&&(o["@id"]=t),o["@type"]=fe(e),o["@type"]==="unknown"&&(i&&i.length&&(o["@context"]=i),o["@type"]="Service"),r&&(o.profile=qe(r)),m({...o,...a})}function cn(e){return m({...R(e),...I(e),...P(e)})}var pn=new K({collection:[Zt],manifest:[en],canvas:[tn],annotationList:[nn],sequence:[rn],annotation:[an],contentResource:[We],choice:[sn],range:[on],service:[ln],layer:[cn]});function Be(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"?pn.traverseUnknown(e):e}function pe(e){if((Array.isArray(e["@type"])&&e["@type"].includes("oa:SvgSelector")||e["@type"]=="oa:SvgSelector")&&("chars"in e||"value"in e))return{type:"SvgSelector",value:"chars"in e?e.chars:e.value};if(e["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:e.value};if(e["@type"]==="oa:Choice")return[pe(e.default),...(Array.isArray(e.item)?e.item:[e.item]).map(pe)];if(e["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in e?e.region:void 0,rotation:"rotation"in e?e.rotation:void 0};throw new Error(`Unsupported selector type: ${e["@type"]}`)}function J(e,t={}){if(Array.isArray(e))return J(e[0]);if(typeof e=="string"){let[n,i]=e.split("#");return i?{type:"SpecificResource",source:{id:n,type:t.typeHint||"Unknown"},selector:{type:"FragmentSelector",value:i}}:{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||t.typeHint||"Unknown"}}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return J(e.items[0]);if(e.type==="SpecificResource")return e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]),e.selector?{type:"SpecificResource",source:e.source,selector:e.selector}:{type:"SpecificResource",source:e.source};if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);let[n,i]=e.id.split("#");return i?{type:"SpecificResource",source:{...e,id:n},selector:{type:"FragmentSelector",value:i}}:{type:"SpecificResource",source:{...e,id:n}}}return{type:"SpecificResource",source:e}}var fn={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}};function $e(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}function He(e,t){if(typeof e=="string")return{id:e,type:t};if(!e.id)throw new Error(`Invalid resource does not have an ID (${JSON.stringify(e)}, ${t})`);return e}function un(e,t){return(n,i)=>{let r=e[n]?e[n]:{};return(a,o)=>{let l=He(a,i||n);return l&&l.id&&n?(r[l.id]=r[l.id]?Y(r[l.id],l,{parent:o.parent,isTopLevel:t.id===l.id}):Y({id:l.id,type:l.type},l,{parent:o.parent,isTopLevel:t.id===l.id}),{id:l.id,type:n==="ContentResource"?n:l.type}):l}}}function X(e,t,n){if(!t)return e;if(Array.isArray(e)){if(!Array.isArray(t))throw new Error("Cannot merge array with non-array");let i=[...e];for(let r of t)if(r["@id"]&&!r.id&&(r.id=r["@id"]),r["@type"]&&!r.type&&(r.type=r["@type"]),r!=null)if(Array.isArray(r))i.push(r);else if(typeof r=="object"&&r.id&&r.type){let a=i.findIndex(o=>o.id===r.id&&o.type===r.type);a>=0&&(i[a]=X(i[a],r))}else e.indexOf(r)===-1&&i.push(r);return i}else if(typeof e=="object"){if(Array.isArray(t)||typeof t!="object")throw new Error("Cannot merge object with non-object");let i={...e},r=[],a=[],o=Object.keys(e).filter(c=>c!==u&&c!=="id"&&c!=="type"),l={},M={};for(let[c,f]of Object.entries(t)){if(c===u||c==="id"||c==="type")continue;let v=i[c];v===f?a.push(c):v===s||!v?(r.push(c),i[c]=f):(v&&f&&(l[c]=v,M[c]=f),i[c]=X(v,f),i[c]===l[c]&&(a.push(c),delete l[c]))}if(n&&(n.parent&&n.parent.id||n.isTopLevel)){let c=[],f={};if(n.parent?f[C]=n.parent.id:n.isTopLevel&&(f[C]=e.id),i[u]&&i[u].length){let v=!(i[u]||[]).find(A=>A["@explicit"]),b=r.length>0||a.length!==o.length;if(v&&b)for(let A of i[u]){let d={...A},Z=Object.keys(l);if(d){d["@explicit"]=!0;for(let j of o)j!==u&&(d[j]=N);for(let j of Z)d[j]=l[j]}c.push(d)}else c.push(...i[u]);if(b){let A=Object.keys(M);f["@explicit"]=!0;for(let d of r)f[d]=N;for(let d of a)f[d]=N;for(let d of A)f[d]=M[d]}}f.id=i.id,f.type=i.type,c.push(f),i[u]=c}return i}else if(e)return e;return t}function Y(e,t,n){if(typeof e=="string")return e;if(t.id!==e.id||t.type!==e.type){if(t.type==="ImageService3")return t;if(e.type==="ImageService3")return e;throw new Error(`Can only merge entities with identical identifiers and type! ${t.type}(${t.id}) => ${e.type}(${e.id})`)}return X({...e},t,n)}function dn(e){return(t,n)=>i=>{let{id:r,type:a}=He(i,n||t);if(typeof r>"u")throw new Error("Found invalid entity without an ID.");return t==="ContentResource"||t==="Service"?e[r]=t:e[r]=a,i}}function vn(e){let t=Object.assign({},e);if(t["@id"]&&(t.id=t["@id"]),t["@type"]&&(t.type=t["@type"]),t.service){let n=[];t.service=Array.isArray(t.service)?t.service:[t.service];for(let i of t.service)n.push({id:i["@id"]||i.id,type:i["@type"]||i.type});t.service=n}return Object.assign({},se,t)}function yn(e){return t=>{e.Service=e.Service?e.Service:{};let n=t.id||t["@id"],i=vn(t);return i&&i.id&&(e.Service[i.id]?e.Service[n]=Y(e.Service[n],i):e.Service[n]=i),t}}function hn(e){let t=JSON.stringify(e),n=5381,i=t.length;for(;i;)n=n*33^t.charCodeAt(--i);let a=(n>>>0).toString(16);return a.length%2?"0"+a:a}function ue(e){return t=>typeof t=="string"?{id:t,type:e}:t.id?t.type?t:{type:e,...t}:{id:`vault://${hn(t)}`,type:e,...t}}function D(e){return t=>({...e,...t})}function V(e){return Array.isArray(e)?e:[e]}function mn(e){return e.body&&(e.body=V(e.body)),e.seeAlso&&(e.seeAlso=V(e.seeAlso)),e.audience&&(e.audience=V(e.audience)),e.accessibility&&(e.accessibility=V(e.accessibility)),e.motivation&&(e.motivation=V(e.motivation)),e}function Ke(e,{typeHint:t,partOfTypeHint:n}={}){if(typeof e=="string"&&(e={id:e,type:t||"unknown"}),h(e))return typeof e.source=="string"&&(e.source={id:e.source,type:t||"unknown"}),e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:n||"Manifest"}]),e;let i;if((e.id||"").indexOf("#")!==-1){let[r,a]=(e.id||"").split("#");e.id=r,a&&(i={type:"FragmentSelector",value:a})}return{type:"SpecificResource",source:e,selector:i}}function gn(e){let t=Object.assign({},e);return e&&e.items&&(t.items=e.items.map(n=>typeof n=="string"||n.type==="Canvas"?Ke(n):n)),t}function An(e){let t=Object.assign({},e);return t.start?(t.start=Ke(t.start,{typeHint:"Canvas"}),t):e}function Cn(e){let t=Object.assign({},e);return t.target?(t.target=J(t.target,{typeHint:"Canvas"}),t):e}function Je(e){return e}function Q(e){return typeof e.items>"u"&&(e[T]=!0),e}function Rn(e){let t=Be(e),n=$e(),i={},r=un(n,t),a=dn(i),l=new q({collection:[Q,D(ne),a("Collection"),r("Collection")],manifest:[Q,D(ie),An,a("Manifest"),r("Manifest")],canvas:[D(te),a("Canvas"),r("Canvas")],annotationPage:[Q,ue("AnnotationPage"),D(ee),a("AnnotationPage"),r("AnnotationPage")],annotation:[ue("Annotation"),mn,Cn,a("Annotation"),r("Annotation")],contentResource:[ue("ContentResource"),a("ContentResource"),r("ContentResource")],range:[D(re),gn,a("Range","Canvas"),r("Range","Canvas")],agent:[D(ae),a("Agent"),r("Agent")],specificResource:[Je],service:[yn(n)]}).traverseUnknown(t);return{entities:n,resource:l,mapping:i}}function Qe(e){let t={};for(let[n,i]of e){if(n===G&&i!==y)return i;i!==y&&typeof i<"u"&&i!==null&&(t[n]=i)}return t}function In(e,t,n){if(!t.type||!t.id)throw new Error("Unknown entity");if(!n[t.type])throw new Error(`Serializer not found for ${t.type}`);function i(r,a,o=0){let l=n[r.type];if(!l)return y;if(o>20)throw new Error("Circular reference: "+r.id+" "+r.type);let[M,c]=H(e,r.type?r:r.id,a)||(r.id&&r.type?r:null);if(!M)return y;let f=l(M,e,{parent:a,isTopLevel:t.id===r.id,fullResource:c}),v=f.next();for(;!v.done;){let b=v.value,A=y;if(b)if(Array.isArray(b)){let d=[];for(let Z of b)d.push(i(Z,r,o+1));A=d}else A=i(b,r,o+1);v=f.next(A)}return v.value===y?y:Qe(v.value)}return i(t)}function _(e,{allowSourceString:t=!0,allowString:n=!1,allowedStringType:i}={}){let r=a=>{if(t&&a&&a.source&&typeof a.source!="string"){let o=Object.keys(a.source);if(a.source.id&&a.source.type&&o.length===2)return{...a,source:a.source.id}}return a};if(e){if(e.source&&e.source.partOf)return r(e);let a=Object.keys(e);if(a.length===2&&e.type&&e.source||a.length===3&&e.type&&e.source&&a.indexOf("selector")!==-1&&!e.selector)return n&&(!i||i===e.source.type)?e.source.id:e.source.type==="ContentResource"?{type:"SpecificResource",source:e.source.id}:e.source;if(e.selector&&!Array.isArray(e.selector)&&typeof e.selector!="string"&&e.selector.type==="FragmentSelector"){let o=`${e.source.id}#${e.selector.value}`;return n?o:{id:o,type:e.source.type}}}return r(e)}function z(e){if(!e)return;let t=Object.keys(e);if(t.length!==0){if(t.length===1){let n=t[0];if(!n)return"";let i=(e[n]||[]).join("");return n==="@none"||n==="none"||n==="en"?i:{"@language":n,"@value":i}}return t.map(n=>({"@language":n,"@value":(e[n]||[]).join("")}))}}function Xe(e){return Array.isArray(e)?e.map(t=>Xe(t)):typeof e=="string"?e:e.type&&e.type==="Canvas"?e.id:e}function x(e,t=!1){if(e)return e.length>1&&!t?e:e[0]||void 0}function Tn(e){if(e){if(typeof e=="string")return{"@id":e};if("@id"in e){let t={...e};return delete t["@type"],t}return{"@context":"http://iiif.io/api/image/2/context.json","@id":e.id,profile:`http://iiif.io/api/image/2/profiles/${e.profile}.json`}}}function F(e,t){return[["@id",e.id],["@type",t],["format",e.format],["height",e.height],["width",e.width],["viewingDirection",e.viewingDirection!=="left-to-right"?e.viewingDirection:void 0],["license",e.license?e.license:void 0]]}function*w(e){let t=e.provider?yield e.provider[0]:void 0;return[["label",z(e.label)],["metadata",e.metadata&&e.metadata.length?e.metadata.map(n=>({label:z(n.label)||"",value:z(n.value)||""})):void 0],["description",z(e.summary)],["thumbnail",x(yield e.thumbnail)],["navDate",e.navDate],["logo",t?x(t.logo):void 0],["homepage",t?t.homepage:void 0],["attribution",e.requiredStatement?z(e.requiredStatement.value):void 0]]}function*W(e){let t=e.start&&e.start.type&&e.start.type==="SpecificResource"?_(e.start):e.start;return[["seeAlso",x(yield e.seeAlso)],["service",x((e.service||[]).map(Tn))],["rendering",x(yield e.rendering)],["startCanvas",t?t.id:void 0]]}function Sn(e){return e.type==="SpecificResource"}function Pn(e){return e&&e.type==="FragmentSelector"}function _n(e){if(e&&Sn(e)){let t=e.id,n=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return Pn(n)&&(t+="#"+n.value),t}return e?.id}var xn={Manifest:function*(e,t,{isTopLevel:n}){return[...n?[["@context","http://iiif.io/api/presentation/2/context.json"]]:[],...F(e,"sc:Manifest"),...yield*w(e),...yield*W(e),["sequences",[{"@id":`${e.id}/sequence0`,"@type":"sc:Sequence",canvases:yield e.items}]],["structures",yield e.structures]]},Canvas:function*(e){let n=(yield e.items)[0];return[...F(e,"sc:Canvas"),...yield*w(e),...yield*W(e),["images",n?[n.resources]:void 0],["annotations",e.annotations&&e.annotations.length?x(yield e.annotations):void 0]]},AnnotationPage:function*(e){return[...F(e,"sc:AnnotationList"),...yield*w(e),["resources",e.items&&e.items.length?x(yield e.items):void 0]]},Annotation:function*(e){return[["@id",e.id],["@type","oa:Annotation"],["motivation","sc:painting"],["on",Xe(e.target)],["resource",x(yield e.body,!0)]]},ContentResource:function*(e){switch(e.type){case"Image":return[...F(e,"dctypes:Image"),...yield*w(e),...yield*W(e)];case"Text":case"Dataset":default:return[...F(e,void 0),...yield*w(e)]}},AnnotationCollection:function*(e){return[["@id",e.id],["@type","sc:Layer"],["label",z(e.label)]]},Collection:function*(e){return[...F(e,"sc:Collection"),...yield*w(e),...yield*W(e),["members",yield*e.items]]},Range:function*(e){let t=[],n=[];if(e.items)for(let i of e.items){let r=i.type==="SpecificResource"?i.source:i;if(r){let a=yield r;t.push({"@id":_n(i),"@type":r.type,label:a?a.label:void 0,within:e.id}),r.type==="Canvas"&&n.push(r.id)}}return[...F(e,"sc:Range"),...yield*w(e),...yield*W(e),["canvases",n.length===t.length?n:void 0],["members",n.length!==t.length?t:void 0]]}};function k(e){return[["id",e.id?.startsWith("vault://")?void 0:e.id],["type",e.type],["format",e.format],["profile",e.profile],["height",e.height||void 0],["width",e.width||void 0],["duration",e.duration||void 0],["viewingDirection",e.viewingDirection!=="left-to-right"?e.viewingDirection:void 0],["behavior",e.behavior&&e.behavior.length?e.behavior:void 0],["timeMode",e.timeMode],["motivation",Array.isArray(e.motivation)?e.motivation[0]:e.motivation],[u,y]]}function p(e){if(e===y||!e||e.length===0)return;let t=e.filter(n=>n!==y);if(t.length!==0)return t}function Ze(e){if(e&&e.type&&e.type==="ImageService2"){let{id:t,type:n,profile:i,...r}=e,a=typeof i=="string"?i:Array.isArray(i)?i.find(o=>typeof o=="string"):"";return{"@id":t,"@type":n,profile:a?a.startsWith("http")?a:`http://iiif.io/api/image/2/${a}.json`:"http://iiif.io/api/image/2/level0.json",...r}}return e}function Ye(e){if(Array.isArray(e)||(e=e?[e]:[]),!(!e||e.length===0))return e.map(Ze)}function*E(e){return[["label",e.label],["metadata",p(e.metadata)],["summary",e.summary],["requiredStatement",e.requiredStatement],["rights",Array.isArray(e.rights)?e.rights[0]||void 0:e.rights||void 0],["navDate",e.navDate],["language",e.language],["thumbnail",p(yield e.thumbnail)],["placeholderCanvas",yield e.placeholderCanvas],["accompanyingCanvas",yield e.accompanyingCanvas],["provider",p(yield e.provider)]]}function*L(e){return[["seeAlso",p(yield e.seeAlso)],["service",p(Ye(e.service))],["services",p(Ye(e.services))],["rendering",p(yield e.rendering)],["supplementary",p(yield e.supplementary)],["homepage",p(yield e.homepage)],["logo",p(yield e.logo)],["partOf",p(yield e.partOf)],["start",e.start?_(e.start):e.start]]}var En={Manifest:function*(e,t,{isTopLevel:n}){return n?[["@context",e["@context"]?e["@context"]:"http://iiif.io/api/presentation/3/context.json"],...k(e),...yield*E(e),...yield*L(e),["items",yield e.items],["structures",p(yield e.structures)],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]:[...k(e),...yield*E(e)]},Canvas:function*(e){return[...k(e),...yield*E(e),...yield*L(e),["items",yield e.items],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]},Agent:function*(e){return[["id",e.id],["type","Agent"],["label",e.label],...yield*L(e)]},AnnotationPage:function*(e){let t=Object.entries(e).map(([i,r])=>[i,Array.isArray(r)?p(r):r]).filter(([i,r])=>i!=="items"&&i!=="id"&&i!==u&&i!==C&&i!==T),n=yield e.items;return[["id",e.id?.startsWith("vault://")?void 0:e.id],...t,...yield*L(e),["items",n.length||e[T]===!1?n:y]]},Service:function*(e){return[[G,Ze(e)]]},Annotation:function*(e){let t=Object.entries(e).map(([i,r])=>i==="motivation"?[i,Array.isArray(r)?r[0]:r]:i==="target"?[i,_(r,{allowString:!0,allowSourceString:!0,allowedStringType:"Canvas"})]:[i,Array.isArray(r)?p(r):r]).filter(([i])=>i!=="body"&&i!==u&&i!==T),n;if(Array.isArray(e.body)){let i=[];for(let r of e.body)if(r&&h(r)){let a={...r};a.source=yield r.source,i.push(_(a,{allowSourceString:!0}))}else i.push(yield r);n=i}else e.body&&h(e.body)?(n={...e.body},n.source=yield e.body.source):n=yield e.body;return[...t,...yield*E(e),...yield*L(e),["body",n.length===1?n[0]:n]]},ContentResource:function*(e){return Ln([...k(e),...yield*E(e),...yield*L(e),["annotations",p(yield e.annotations)],["items",p(yield e.items)]],e)},AnnotationCollection:function*(e){return[["id",e.id],["type","AnnotationCollection"],["label",e.label]]},Collection:function*(e,t,{isTopLevel:n}){return n?[["@context","http://iiif.io/api/presentation/3/context.json"],...k(e),...yield*E(e),...yield*L(e),["items",p(yield e.items)],["navPlace",e.navPlace]]:[...k(e),...yield*E(e)]},Range:function*(e){let t=[];for(let n of e.items)n.type==="Range"?t.push(yield n):n&&n.type==="SpecificResource"?t.push(_(n)):t.push(n);return[...k(e),...yield*E(e),...yield*L(e),["items",t],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]}};function Ln(e,t){let n=Object.keys(t),i=e.map(([r])=>r);for(let r of n)r===u||r===T||i.indexOf(r)===-1&&typeof t[r]<"u"&&e.push([r,t[r]]);return e}

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

"use strict";var IIIFParser=(()=>{var V=Object.defineProperty;var Qe=Object.getOwnPropertyDescriptor;var Ze=Object.getOwnPropertyNames;var et=Object.prototype.hasOwnProperty;var tt=(e,t,n)=>t in e?V(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var nt=(e,t)=>{for(var n in t)V(e,n,{get:t[n],enumerable:!0})},it=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ze(t))!et.call(e,r)&&r!==n&&V(e,r,{get:()=>t[r],enumerable:!(i=Qe(t,r))||i.enumerable});return e};var rt=e=>it(V({},"__esModule",{value:!0}),e);var m=(e,t,n)=>(tt(e,typeof t!="symbol"?t+"":t,n),n);var on={};nt(on,{EMPTY:()=>s,HAS_PART:()=>u,IS_EXTERNAL:()=>S,PART_OF:()=>A,Traverse:()=>G,UNSET:()=>y,UNWRAP:()=>q,WILDCARD:()=>w,addFlagForExternalResource:()=>Y,compressSpecificResource:()=>x,defaultEntities:()=>Ut,emptyAgent:()=>ae,emptyAnnotation:()=>at,emptyAnnotationPage:()=>ee,emptyCanvas:()=>te,emptyCollection:()=>ne,emptyManifest:()=>ie,emptyRange:()=>re,emptyService:()=>se,frameResource:()=>ve,getDefaultEntities:()=>We,identifyResource:()=>ye,isSpecificResource:()=>h,isWildcard:()=>de,languageString2to3:()=>k,merge:()=>J,mergeEntities:()=>Q,normalize:()=>Jt,resolveIfExists:()=>B,serialize:()=>Qt,serializeConfigPresentation2:()=>rn,serializeConfigPresentation3:()=>an,serializedFieldsToObject:()=>Ke,toRef:()=>H,traverseSpecificResource:()=>Be,types:()=>oe});function h(e){return typeof e=="string"?!1:!!e&&e.type==="SpecificResource"}function H(e,t){let n=t||"unknown";if(!e)return;if(typeof e=="string")return{id:e,type:n};if(h(e))return H(e.source,t);let i=n&&n!=="unknown"?n:e.type||e["@type"],r=e.id||e["@id"];if(i&&i.indexOf(":")!==-1&&(i=i.split(":").pop()),r&&i)return{id:r,type:i}}var w={},u="iiif-parser:hasPart",A="iiif-parser:partOf",S="iiif-parser:isExternal",y="__$UNSET$__",q="__$UNWRAP$__",s=[];Object.freeze(s);Object.freeze(w);function de(e){if(e===w||Object.keys(e).length===0)return!0;for(let t in e)return!1;return!0}function ve(e,t){if(t&&t["@explicit"]){let n={},i=Object.keys(t);for(let r of i)r===A||r==="@explicit"||(de(t[r])?n[r]=e[r]:n[r]=t[r]);return n}return e}function B(e,t,n){let i=H(t);if(!i)return[void 0,void 0];let r=e.requests[i.id],a=i.type||e.mapping[i.id];if(!a||r&&r.resourceUri&&(!e.entities[a]||!e.entities[a][r.resourceUri]))return[void 0,void 0];let o=e.entities[a][r?r.resourceUri:i.id];if(i.type&&!o)return B(e,{id:i.id},n);if(o&&o[u]){let c=o[u].find(l=>n?l[A]===n.id:l[A]===o.id);return[ve(o,c),o]}return[o,o]}var at={id:"https://iiif-parser/annotation",type:"Annotation",behavior:s,label:null,thumbnail:s,summary:null,requiredStatement:null,metadata:s,seeAlso:s,homepage:s,rendering:s,service:s,accessibility:s,audience:s,body:s,bodyValue:null,canonical:null,created:null,creator:s,generated:null,generator:s,modified:null,motivation:s,rights:null,stylesheet:null,target:s,timeMode:void 0,via:s,partOf:s},ee={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:s,label:null,thumbnail:s,summary:null,requiredStatement:null,metadata:s,rights:null,provider:s,items:s,seeAlso:s,homepage:s,rendering:s,service:s},te={id:"https://iiif-parser/empty-canvas",type:"Canvas",label:null,behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,duration:0,height:0,width:0},ne={id:"https://iiif-parser/empty-collection",type:"Collection",label:null,viewingDirection:"left-to-right",behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,services:s},ie={id:"https://iiif-parser/empty-manifest",type:"Manifest",annotations:s,behavior:s,homepage:s,items:s,label:null,metadata:s,navDate:null,provider:s,partOf:s,accompanyingCanvas:null,placeholderCanvas:null,rendering:s,requiredStatement:null,rights:null,seeAlso:s,service:s,services:s,start:null,structures:s,summary:null,thumbnail:s,viewingDirection:"left-to-right"},re={id:"https://iiif-parser/empty-canvas",type:"Range",label:null,behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,start:null,supplementary:null,viewingDirection:"left-to-right"},ae={id:"https://iiif-parser/empty-agent",type:"Agent",label:{},logo:s,seeAlso:s,homepage:s},se={id:"https://iiif-parser/empty-service",type:"UnknownService"};function P(e){return Array.isArray(e)?e:e?[e]:[]}function U(...e){return t=>e.reduce((n,i)=>i(n),t)}var oe=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function ye(e,t){if(typeof e>"u"||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"){if(t)return t;throw new Error(`${typeof e} is not a valid entity`)}if(typeof e.type=="string"){let n=oe.indexOf(e.type);if(n!==-1)return oe[n]}if(e.profile)return"Service";throw new Error("Resource type is not known")}var G=class e{constructor(t,n={}){m(this,"traversals");m(this,"options");m(this,"_traverseManifest",U(this.traverseManifestItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseManifestStructures.bind(this),this.traverseInlineAnnotationPages.bind(this)));m(this,"_traverseCanvas",U(this.traverseCanvasItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseInlineAnnotationPages.bind(this)));m(this,"_traverseAnnotationPage",U(this.traverseAnnotationPageItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this)));m(this,"_traverseRange",U(this.traverseRangeRanges.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this)));this.traversals={collection:[],manifest:[],canvas:[],annotationCollection:[],annotationPage:[],annotation:[],contentResource:[],choice:[],range:[],service:[],agent:[],specificResource:[],geoJson:[],...t},this.options={allowUndefinedReturn:!1,...n}}static all(t){return new e({collection:[t],manifest:[t],canvas:[t],annotationCollection:[t],annotationPage:[t],annotation:[t],contentResource:[t],choice:[t],range:[t],service:[t],geoJson:[t],specificResource:[t],agent:[t]})}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=P(t.thumbnail).map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.provider&&(t.provider=t.provider.map(n=>this.traverseAgent(n,t))),t}traverseLinking(t){return t.seeAlso&&(t.seeAlso=t.seeAlso.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.service&&(t.service=P(t.service).map(n=>this.traverseService(n))),t.services&&(t.services=P(t.services).map(n=>this.traverseService(n,t))),t.logo&&(t.logo=t.logo.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.homepage&&(t.homepage=t.homepage.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.partOf&&(t.partOf=t.partOf.map(n=>typeof n=="string"||!n.type?this.traverseType(n,{parent:t},this.traversals.contentResource):n.type==="Canvas"?this.traverseType(n,{parent:t},this.traversals.canvas):n.type==="AnnotationCollection"?this.traverseType(n,{parent:t},this.traversals.annotationCollection):n.type==="Collection"?this.traverseType(n,{parent:t},this.traversals.collection):this.traverseType(n,{parent:t},this.traversals.contentResource))),t.start&&(h(t.start)?t.start=this.traverseSpecificResource(t.start,"Canvas",t):t.start=this.traverseType(t.start,{parent:t},this.traversals.canvas)),t.rendering&&(t.rendering=t.rendering.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.supplementary&&(t.supplementary=t.supplementary.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t}traverseCollectionItems(t){return t.items&&t.items.map(n=>n.type==="Collection"?this.traverseCollection(n):this.traverseManifest(n)),t}traverseCollection(t,n){return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traverseLinkedCanvases(this.traverseCollectionItems(t))))),{parent:n},this.traversals.collection)}traverseGeoJson(t,n){return this.traverseType(t,{parent:n},this.traversals.geoJson)}traverseNavPlace(t){return t.navPlace&&(t.navPlace=this.traverseGeoJson(t.navPlace,t)),t}traverseManifestItems(t){return t.items&&(t.items=t.items.map(n=>this.traverseCanvas(n))),t}traverseManifestStructures(t){return t.structures&&(t.structures=t.structures.map(n=>this.traverseRange(n))),t}traverseManifest(t,n){return this.traverseType(this._traverseManifest(t),{parent:n},this.traversals.manifest)}traverseCanvasItems(t){return t.items=(t.items||[]).map(n=>this.traverseAnnotationPage(n,t)),t}traverseInlineAnnotationPages(t){return typeof t=="string"||!t||t.annotations&&(t.annotations=t.annotations.map(n=>this.traverseAnnotationPage(n,t))),t}traverseCanvas(t,n){return this.traverseType(this._traverseCanvas(t),{parent:n},this.traversals.canvas)}traverseAnnotationPageItems(t){return t.items&&(t.items=t.items.map(n=>this.traverseAnnotation(n,t))),t}traverseAnnotationPage(t,n){return this.traverseType(this._traverseAnnotationPage(t),{parent:n},this.traversals.annotationPage)}traverseAnnotationBody(t){return Array.isArray(t.body)?t.body=t.body.map(n=>this.traverseContentResource(n,t)):t.body&&(t.body=this.traverseContentResource(t.body,t)),t}traverseLinkedCanvases(t){return t.placeholderCanvas&&(t.placeholderCanvas=this.traverseCanvas(t.placeholderCanvas)),t.accompanyingCanvas&&(t.accompanyingCanvas=this.traverseCanvas(t.accompanyingCanvas)),t}traverseAnnotation(t,n){return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(this.traverseDescriptive(t))),{parent:n},this.traversals.annotation)}traverseContentResourceLinking(t){return typeof t=="string"||!t||t&&t.service&&(t.service=P(t.service||[]).map(n=>this.traverseService(n,t))),t}traverseContentResource(t,n){return t.type==="Choice"&&(t.items=t.items.map(i=>this.traverseContentResource(i,t))),h(t)?this.traverseSpecificResource(t,"ContentResource"):this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(t)),{parent:n},this.traversals.contentResource)}traverseSpecificResource(t,n,i){let r=t.source;return typeof t.source=="string"&&(r={id:t.source,type:n||"unknown"}),this.traverseType({...t,source:n==="Canvas"||r.type==="Canvas"?this.traverseType(r,{parent:i},this.traversals.canvas):n==="ContentResource"?this.traverseContentResource(r,{parent:i}):this.traverseUnknown(r,{parent:i,typeHint:n})},{parent:i},this.traversals.specificResource)}traverseRangeRanges(t){return t.items&&(t.items=t.items.map(n=>typeof n=="string"?this.traverseCanvas({id:n,type:"Canvas"},t):h(n)?this.traverseSpecificResource(n,"Canvas",t):n.type==="Manifest"?this.traverseManifest(n,t):this.traverseRange(n,t))),t}traverseRange(t,n){return this.traverseType(this._traverseRange(t),{parent:n},this.traversals.range)}traverseAgent(t,n){return this.traverseType(this.traverseDescriptive(this.traverseLinking(t)),{parent:n},this.traversals.agent)}traverseType(t,n,i){return i.reduce((r,a)=>{let o=a(r,n);return typeof o>"u"&&!this.options.allowUndefinedReturn?r:o},t)}traverseService(t,n){let i=Object.assign({},t);return i&&i.service&&(i.service=P(i.service).map(r=>this.traverseService(r))),this.traverseType(i,{parent:n},this.traversals.service)}traverseUnknown(t,{parent:n,typeHint:i}={}){let r=ye(t,i);switch(r){case"Collection":return this.traverseCollection(t,n);case"Manifest":return this.traverseManifest(t,n);case"Canvas":return this.traverseCanvas(t,n);case"AnnotationPage":return this.traverseAnnotationPage(t,n);case"Annotation":return this.traverseAnnotation(t,n);case"ContentResource":return this.traverseContentResource(t,n);case"Range":return this.traverseRange(t,n);case"Service":return this.traverseService(t,n);case"Agent":return this.traverseAgent(t,n);default:throw new Error(`Unknown or unsupported resource type of ${r}`)}}};var he=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function st(e){if(typeof e>"u"||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"){let t=he.indexOf(e["@type"]);if(t!==-1)return he[t]}if(e.profile)return"Service";if(e.format||e["@type"])return"ContentResource";throw new Error("Resource type is not known")}var K=class e{constructor(t,n={}){m(this,"traversals");m(this,"options");this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...t},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...n}}static all(t){return new e({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){let n=[...(t.manifests||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i),...(t.collections||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i),...t.members||[]];delete t.collections,delete t.manifests,t.members=n}return t.manifests&&(t.manifests=t.manifests.map(n=>this.traverseManifest(typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n))),t.collections&&(t.collections=t.collections.map(n=>this.traverseCollection(typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n))),t.members&&(t.members=t.members.map(n=>typeof n=="string"?n:this.traverseUnknown(n))),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(n=>this.traverseSequence(n))),t.structures&&(t.structures=t.structures.map(n=>this.traverseRange(n))),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(n=>this.traverseCanvas(n))),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(n=>this.traverseAnnotation(n))),t.otherContent&&(t.otherContent=t.otherContent.map(n=>this.traverseAnnotationList(n))),t}traverseRange(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(t))),this.traversals.range)}traverseRangeItems(t){if(this.options.mergeMemberProperties){let n=[...(t.ranges||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Range"}:i),...(t.canvases||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Canvas"}:i),...t.members||[]];delete t.ranges,delete t.canvases,t.members=n.length?n.map(i=>this.traverseUnknown(i)):void 0}return t}traverseAnnotationList(t){let n=typeof t=="string"?{"@id":t,"@type":"sc:AnnotationList"}:t;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(n)),this.traversals.annotationList)}traverseAnnotationListItems(t){return t.resources&&(t.resources=t.resources.map(n=>this.traverseAnnotation(n))),t}traverseAnnotation(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(t))),this.traversals.annotation)}traverseAnnotationItems(t){return t.resource&&(Array.isArray(t.resource)?t.resource=t.resource.map(n=>this.traverseContentResource(n)):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(n=>this.traverseAnnotationList(n))),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(n=>this.traverseContentResource(n))),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(st(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"sc: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){let n=Array.isArray(t),i=Array.isArray(t)?t:[t],r=[];for(let a of i)typeof a=="string"?r.push(this.traverseContentResource({"@id":a,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(a));return!n&&!this.options.convertPropsToArray?r[0]:r}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=this.traverseImageResource(t.thumbnail)),t.logo&&(t.logo=this.traverseImageResource(t.logo)),t}traverseOneOrMoreServices(t){let n=Array.isArray(t),i=Array.isArray(t)?t:[t],r=[];for(let a of i)r.push(this.traverseService(a));return!n&&!this.options.convertPropsToArray?r[0]:r}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,n){if(!Array.isArray(t))if(this.options.convertPropsToArray)t=[t];else return this.traverseType(t,n);return t.map(i=>this.traverseType(i,n))}traverseType(t,n){return n.reduce((i,r)=>{let a=r(i);return typeof a>"u"&&!this.options.allowUndefinedReturn?i:a},t)}};var ot="http://library.stanford.edu/iiif/image-api/compliance.html#level0",me="http://library.stanford.edu/iiif/image-api/compliance.html#level1",ge="http://library.stanford.edu/iiif/image-api/compliance.html#level2",ct="http://library.stanford.edu/iiif/image-api/conformance.html#level0",Ce="http://library.stanford.edu/iiif/image-api/conformance.html#level1",Ae="http://library.stanford.edu/iiif/image-api/conformance.html#level2",lt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Re="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Te="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",pt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Se="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Pe="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",ft="http://iiif.io/api/image/1/level0.json",ut="http://iiif.io/api/image/1/profiles/level0.json",Ie="http://iiif.io/api/image/1/level1.json",xe="http://iiif.io/api/image/1/profiles/level1.json",be="http://iiif.io/api/image/1/level2.json",_e="http://iiif.io/api/image/1/profiles/level2.json",dt="http://iiif.io/api/image/2/level0.json",vt="http://iiif.io/api/image/2/profiles/level0.json",Ee="http://iiif.io/api/image/2/level1.json",Me="http://iiif.io/api/image/2/profiles/level1.json",Le="http://iiif.io/api/image/2/level2.json",we="http://iiif.io/api/image/2/profiles/level2.json",yt="level0",Ne="level1",Oe="level2",ht="http://iiif.io/api/image/2/level0",ze="http://iiif.io/api/image/2/level1",ke="http://iiif.io/api/image/2/level2",Fe=[ze,ke,me,ge,Ce,Ae,Re,Te,Se,Pe,Ie,xe,be,_e,Ee,Me,Le,we,Ne,Oe],De=[ht,ze,ke,ot,me,ge,ct,Ce,Ae,lt,Re,Te,pt,Se,Pe,ft,ut,Ie,xe,be,_e,dt,vt,Ee,Me,Le,we,yt,Ne,Oe];function g(e){for(let t in e)(typeof e[t]>"u"||e[t]===null)&&delete e[t];return e}var ce={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function mt(e){if(typeof e=="string")return[e];if(!e)return[];let t=Array.isArray(e)?e:[e],n=[];for(let i of t){if(typeof i=="string"){n.push(i);continue}n.push({"@language":i["@language"]||i.language,"@value":i["@value"]||i.value})}return n}function N(e,t="none"){if(!e)return{};let n=mt(e),i={};for(let r of n){if(typeof r=="string"){i[t]=i[t]?i[t]:[],i[t].push(r||"");continue}if(!r["@language"]){i[t]=i[t]?i[t]:[],i[t].push(r["@value"]||"");continue}let a=r["@language"];i[a]=i[a]?i[a]:[],i[a].push(r["@value"]||"")}return i}function Ue(e){if(Array.isArray(e))return Ue(e.find(t=>typeof t=="string"));if(De.indexOf(e)!==-1)return"level2";if(Fe.indexOf(e)!==-1)return"level1";if(typeof e=="string")return e}function gt(e){let t=Array.isArray(e)?e:[e];for(let n of t)switch(n){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 Ct(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 je(e){for(let t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}var At=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function fe(e){let t=e["@id"]||e.id,n=e["@type"]||e.type,i=e.profile||void 0,r=e["@context"]||void 0;if(i){let a=Ct(i);if(a)return a}if(r){let a=gt(r);if(a)return a}if(n){if(Array.isArray(n)){if(n.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(n.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";n=n[0]}for(let a of["sc","oa","dcterms","dctypes","iiif"])if(n.startsWith(`${a}:`)){n=n.slice(a.length+1);break}switch(n){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(n&&At.indexOf(n)!==-1)return n;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":n||"unknown"}var Rt=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Tt(e){let t=e.match(Rt);return t?t[0]:e}function St(e,t="Rights/License",n="none"){let i=null,r=[],a=Array.isArray(e)?e:[e];for(let o of a){let c=o?Tt(o):void 0;if(c&&(c.indexOf("creativecommons.org")!==-1||c.indexOf("rightsstatements.org")!==-1)){c.startsWith("https://")?i=`http://${c.slice(8)}`:i=c;continue}c&&r.push({label:{[n]:[t]},value:{[n]:[c]}})}return[i,r]}var 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 It(e){if(e){let t=Array.isArray(e)?e:[e],n=[];for(let i of t)i==="http://iiif.io/api/presentation/2/context.json"&&n.push("http://iiif.io/api/presentation/3/context.json"),Pt.indexOf(i)===-1&&n.push(i);if(t.length)return n.length===1?n[0]:n}}function xt(e){return e?e.map(t=>({label:N(t.label),value:N(t.value)})):[]}var qe=0;function Ge(e,t){let n=encodeURI(e.id||e["@id"]||"").trim();return n&&t?`${n}/${t}`:n||(qe++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${qe}`)}function R(e){let t=[...e.behavior||[]];e.viewingHint&&t.push(e.viewingHint);let n;return Array.isArray(e.motivation)?n=e.motivation.map(je):e.motivation&&(n=je(e.motivation)),{"@context":e["@context"]?It(e["@context"]):void 0,id:(e["@id"]||Ge(e)).trim(),type:fe(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:n,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function T(e){let[t,n]=St(e.license),i=[...e.metadata?xt(e.metadata):[],...n];return{rights:t,metadata:i.length?i:void 0,label:e.label?N(e.label):void 0,requiredStatement:e.attribution?{label:N(ce.attributionLabel),value:N(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?N(e.description):void 0,thumbnail:bt(e.thumbnail)}}function bt(e){return e&&(Array.isArray(e)?e:[e]).map(n=>typeof n=="string"?{id:n,type:"Image"}:(n.type==="unknown"&&(n.type="Image"),n))}function _t(e){if(!e.within)return;let t=Array.isArray(e.within)?e.within:[e.within],n=[];for(let i of t)if(typeof i=="string"){if(i)switch(e["@type"]){case"sc:Manifest":n.push({id:i,type:"Collection"});break}}else i["@id"]&&n.push({id:i["@id"],type:fe(i)});return n.length?n:void 0}function I(e){let t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],n=e.contentLayer;return{provider:e.logo||t.length?[{id:ce.providerId,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:N(ce.providerName)}]:void 0,partOf:_t(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?P(e.service):void 0,supplementary:n?[n]:void 0}}function Et(e){return{chars:e.chars,format:e.format?e.format:void 0,language:e.language}}function Mt(e){return g({...R(e),...T(e),...I(e),items:e.members})}function Lt(e){let t=[],n=[],i;for(let a of e.sequences||[])a.canvases.length&&t.push(...a.canvases),a.behavior&&n.push(...a.behavior),a.startCanvas&&(i=a.startCanvas);let r=R(e);return n.length&&(r.behavior?r.behavior.push(...n):r.behavior=n),g({...r,...T(e),...I(e),start:i,items:t,structures:e.structures})}function wt(e){return g({...R(e),...T(e),...I(e),annotations:e.otherContent&&e.otherContent.length?e.otherContent:void 0,items:e.images&&e.images.length?[{id:Ge(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}function Nt(e){return g({...R(e),...T(e),...I(e),items:e.resources&&e.resources.length?e.resources:void 0})}function Ot(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}}function zt(e){function t(n){if(Array.isArray(n)){if(n.length>1)return{type:"List",items:n.map(t)};n=n[0]}if(typeof n=="string")return encodeURI(n).trim();if("@type"in n){let i;if(typeof n.full=="string")i=n.full;else if(n.full["@type"]==="dctypes:Image")i={id:n.full["@id"],type:"Image"};else if(n.full["@type"]==="sc:Canvas")i={id:n.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${n.full["@type"]}`);return{type:"SpecificResource",source:i,selector:pe(n.selector)}}else return encodeURI(n["@id"]).trim()}return g({...R(e),...T(e),...I(e),target:t(e.on),body:Array.isArray(e.resource)?e.resource.map(le):le(e.resource)})}function le(e){let t=e;return g({...R(t),...T(t),...I(t),...Et(t)})}function kt(e){let t=[];return e.default&&e.default!=="rdf:nil"&&t.push(e.default),e.item&&e.item!=="rdf:nil"&&t.push(...e.item),{...R(e),...T(e),items:t}}function Ft(e){return g({...R(e),...T(e),...I(e),items:e.members})}function Dt(e){let{"@id":t,"@type":n,"@context":i,profile:r,...a}=e,o={};return t&&(o["@id"]=t),o["@type"]=fe(e),o["@type"]==="unknown"&&(i&&i.length&&(o["@context"]=i),o["@type"]="Service"),r&&(o.profile=Ue(r)),g({...o,...a})}function jt(e){return g({...R(e),...T(e),...I(e)})}var qt=new K({collection:[Mt],manifest:[Lt],canvas:[wt],annotationList:[Nt],sequence:[Ot],annotation:[zt],contentResource:[le],choice:[kt],range:[Ft],service:[Dt],layer:[jt]});function $e(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"?qt.traverseUnknown(e):e}function pe(e){if((Array.isArray(e["@type"])&&e["@type"].includes("oa:SvgSelector")||e["@type"]=="oa:SvgSelector")&&("chars"in e||"value"in e))return{type:"SvgSelector",value:"chars"in e?e.chars:e.value};if(e["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:e.value};if(e["@type"]==="oa:Choice")return[pe(e.default),...(Array.isArray(e.item)?e.item:[e.item]).map(pe)];if(e["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in e?e.region:void 0,rotation:"rotation"in e?e.rotation:void 0};throw new Error(`Unsupported selector type: ${e["@type"]}`)}function X(e,t={}){if(Array.isArray(e))return X(e[0]);if(typeof e=="string"){let[n,i]=e.split("#");return i?{type:"SpecificResource",source:{id:n,type:t.typeHint||"Unknown"},selector:{type:"FragmentSelector",value:i}}:{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||t.typeHint||"Unknown"}}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return X(e.items[0]);if(e.type==="SpecificResource")return e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]),e.selector?{type:"SpecificResource",source:e.source,selector:e.selector}:{type:"SpecificResource",source:e.source};if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);let[n,i]=e.id.split("#");return i?{type:"SpecificResource",source:{...e,id:n},selector:{type:"FragmentSelector",value:i}}:{type:"SpecificResource",source:{...e,id:n}}}return{type:"SpecificResource",source:e}}var Ut={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}};function We(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}function Ve(e,t){if(typeof e=="string")return{id:e,type:t};if(!e.id)throw new Error(`Invalid resource does not have an ID (${JSON.stringify(e)}, ${t})`);return e}function Gt(e,t){return(n,i)=>{let r=e[n]?e[n]:{};return(a,o)=>{let c=Ve(a,i||n);return c&&c.id&&n?(r[c.id]=r[c.id]?Q(r[c.id],c,{parent:o.parent,isTopLevel:t.id===c.id}):Q({id:c.id,type:c.type},c,{parent:o.parent,isTopLevel:t.id===c.id}),{id:c.id,type:n==="ContentResource"?n:c.type}):c}}}function J(e,t,n){if(!t)return e;if(Array.isArray(e)){if(!Array.isArray(t))throw new Error("Cannot merge array with non-array");let i=[...e];for(let r of t)if(r["@id"]&&!r.id&&(r.id=r["@id"]),r["@type"]&&!r.type&&(r.type=r["@type"]),r!=null)if(Array.isArray(r))i.push(r);else if(typeof r=="object"&&r.id&&r.type){let a=i.findIndex(o=>o.id===r.id&&o.type===r.type);a>=0&&(i[a]=J(i[a],r))}else e.indexOf(r)===-1&&i.push(r);return i}else if(typeof e=="object"){if(Array.isArray(t)||typeof t!="object")throw new Error("Cannot merge object with non-object");let i={...e},r=[],a=[],o=Object.keys(e).filter(l=>l!==u&&l!=="id"&&l!=="type"),c={},M={};for(let[l,f]of Object.entries(t)){if(l===u||l==="id"||l==="type")continue;let v=i[l];v===f?a.push(l):v===s||!v?(r.push(l),i[l]=f):(v&&f&&(c[l]=v,M[l]=f),i[l]=J(v,f),i[l]===c[l]&&(a.push(l),delete c[l]))}if(n&&(n.parent&&n.parent.id||n.isTopLevel)){let l=[],f={};if(n.parent?f[A]=n.parent.id:n.isTopLevel&&(f[A]=e.id),i[u]&&i[u].length){let v=!(i[u]||[]).find(C=>C["@explicit"]),L=r.length>0||a.length!==o.length;if(v&&L)for(let C of i[u]){let d={...C},Z=Object.keys(c);if(d){d["@explicit"]=!0;for(let j of o)j!==u&&(d[j]=w);for(let j of Z)d[j]=c[j]}l.push(d)}else l.push(...i[u]);if(L){let C=Object.keys(M);f["@explicit"]=!0;for(let d of r)f[d]=w;for(let d of a)f[d]=w;for(let d of C)f[d]=M[d]}}f.id=i.id,f.type=i.type,l.push(f),i[u]=l}return i}else if(e)return e;return t}function Q(e,t,n){if(typeof e=="string")return e;if(t.id!==e.id||t.type!==e.type){if(t.type==="ImageService3")return t;if(e.type==="ImageService3")return e;throw new Error(`Can only merge entities with identical identifiers and type! ${t.type}(${t.id}) => ${e.type}(${e.id})`)}return J({...e},t,n)}function $t(e){return(t,n)=>i=>{let{id:r,type:a}=Ve(i,n||t);if(typeof r>"u")throw new Error("Found invalid entity without an ID.");return t==="ContentResource"||t==="Service"?e[r]=t:e[r]=a,i}}function Wt(e){let t=Object.assign({},e);if(t["@id"]&&(t.id=t["@id"]),t["@type"]&&(t.type=t["@type"]),t.service){let n=[];t.service=Array.isArray(t.service)?t.service:[t.service];for(let i of t.service)n.push({id:i["@id"]||i.id,type:i["@type"]||i.type});t.service=n}return Object.assign({},se,t)}function Vt(e){return t=>{e.Service=e.Service?e.Service:{};let n=t.id||t["@id"],i=Wt(t);return i&&i.id&&(e.Service[i.id]?e.Service[n]=Q(e.Service[n],i):e.Service[n]=i),t}}function Ht(e){let t=JSON.stringify(e),n=5381,i=t.length;for(;i;)n=n*33^t.charCodeAt(--i);let a=(n>>>0).toString(16);return a.length%2?"0"+a:a}function ue(e){return t=>typeof t=="string"?{id:t,type:e}:t.id?t.type?t:{type:e,...t}:{id:`vault://${Ht(t)}`,type:e,...t}}function D(e){return t=>({...e,...t})}function $(e){return Array.isArray(e)?e:[e]}function Bt(e){return e.body&&(e.body=$(e.body)),e.seeAlso&&(e.seeAlso=$(e.seeAlso)),e.audience&&(e.audience=$(e.audience)),e.accessibility&&(e.accessibility=$(e.accessibility)),e.motivation&&(e.motivation=$(e.motivation)),e}function He(e,{typeHint:t,partOfTypeHint:n}={}){if(typeof e=="string"&&(e={id:e,type:t||"unknown"}),h(e))return typeof e.source=="string"&&(e.source={id:e.source,type:t||"unknown"}),e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:n||"Manifest"}]),e;let i;if((e.id||"").indexOf("#")!==-1){let[r,a]=(e.id||"").split("#");e.id=r,a&&(i={type:"FragmentSelector",value:a})}return{type:"SpecificResource",source:e,selector:i}}function Kt(e){let t=Object.assign({},e);return e&&e.items&&(t.items=e.items.map(n=>typeof n=="string"||n.type==="Canvas"?He(n):n)),t}function Xt(e){let t=Object.assign({},e);return t.start?(t.start=He(t.start,{typeHint:"Canvas"}),t):e}function Yt(e){let t=Object.assign({},e);return t.target?(t.target=X(t.target,{typeHint:"Canvas"}),t):e}function Be(e){return e}function Y(e){return typeof e.items>"u"&&(e[S]=!0),e}function Jt(e){let t=$e(e),n=We(),i={},r=Gt(n,t),a=$t(i),c=new G({collection:[Y,D(ne),a("Collection"),r("Collection")],manifest:[Y,D(ie),Xt,a("Manifest"),r("Manifest")],canvas:[D(te),a("Canvas"),r("Canvas")],annotationPage:[Y,ue("AnnotationPage"),D(ee),a("AnnotationPage"),r("AnnotationPage")],annotation:[ue("Annotation"),Bt,Yt,a("Annotation"),r("Annotation")],contentResource:[ue("ContentResource"),a("ContentResource"),r("ContentResource")],range:[D(re),Kt,a("Range","Canvas"),r("Range","Canvas")],agent:[D(ae),a("Agent"),r("Agent")],specificResource:[Be],service:[Vt(n)]}).traverseUnknown(t);return{entities:n,resource:c,mapping:i}}function Ke(e){let t={};for(let[n,i]of e){if(n===q&&i!==y)return i;i!==y&&typeof i<"u"&&i!==null&&(t[n]=i)}return t}function Qt(e,t,n){if(!t.type||!t.id)throw new Error("Unknown entity");if(!n[t.type])throw new Error(`Serializer not found for ${t.type}`);function i(r,a,o=0){let c=n[r.type];if(!c)return y;if(o>20)throw new Error("Circular reference: "+r.id+" "+r.type);let[M,l]=B(e,r.type?r:r.id,a)||(r.id&&r.type?r:null);if(!M)return y;let f=c(M,e,{parent:a,isTopLevel:t.id===r.id,fullResource:l}),v=f.next();for(;!v.done;){let L=v.value,C=y;if(L)if(Array.isArray(L)){let d=[];for(let Z of L)d.push(i(Z,r,o+1));C=d}else C=i(L,r,o+1);v=f.next(C)}return v.value===y?y:Ke(v.value)}return i(t)}function x(e,{allowSourceString:t=!0,allowString:n=!1,allowedStringType:i}={}){let r=a=>{if(t&&a&&a.source&&typeof a.source!="string"){let o=Object.keys(a.source);if(a.source.id&&a.source.type&&o.length===2)return{...a,source:a.source.id}}return a};if(e){if(e.source&&e.source.partOf)return r(e);let a=Object.keys(e);if(a.length===2&&e.type&&e.source||a.length===3&&e.type&&e.source&&a.indexOf("selector")!==-1&&!e.selector)return n&&(!i||i===e.source.type)?e.source.id:e.source.type==="ContentResource"?{type:"SpecificResource",source:e.source.id}:e.source;if(e.selector&&!Array.isArray(e.selector)&&typeof e.selector!="string"&&e.selector.type==="FragmentSelector"){let o=`${e.source.id}#${e.selector.value}`;return n?o:{id:o,type:e.source.type}}}return r(e)}function k(e){if(!e)return;let t=Object.keys(e);if(t.length!==0){if(t.length===1){let n=t[0];if(!n)return"";let i=(e[n]||[]).join("");return n==="@none"||n==="none"||n==="en"?i:{"@language":n,"@value":i}}return t.map(n=>({"@language":n,"@value":(e[n]||[]).join("")}))}}function Xe(e){return Array.isArray(e)?e.map(t=>Xe(t)):typeof e=="string"?e:e.type&&e.type==="Canvas"?e.id:e}function b(e,t=!1){if(e)return e.length>1&&!t?e:e[0]||void 0}function Zt(e){if(e){if(typeof e=="string")return{"@id":e};if("@id"in e){let t={...e};return delete t["@type"],t}return{"@context":"http://iiif.io/api/image/2/context.json","@id":e.id,profile:`http://iiif.io/api/image/2/profiles/${e.profile}.json`}}}function O(e,t){return[["@id",e.id],["@type",t],["format",e.format],["height",e.height],["width",e.width],["viewingDirection",e.viewingDirection!=="left-to-right"?e.viewingDirection:void 0],["license",e.license?e.license:void 0]]}function*z(e){let t=e.provider?yield e.provider[0]:void 0;return[["label",k(e.label)],["metadata",e.metadata&&e.metadata.length?e.metadata.map(n=>({label:k(n.label)||"",value:k(n.value)||""})):void 0],["description",k(e.summary)],["thumbnail",b(yield e.thumbnail)],["navDate",e.navDate],["logo",t?b(t.logo):void 0],["homepage",t?t.homepage:void 0],["attribution",e.requiredStatement?k(e.requiredStatement.value):void 0]]}function*W(e){let t=e.start&&e.start.type&&e.start.type==="SpecificResource"?x(e.start):e.start;return[["seeAlso",b(yield e.seeAlso)],["service",b((e.service||[]).map(Zt))],["rendering",b(yield e.rendering)],["startCanvas",t?t.id:void 0]]}function en(e){return e.type==="SpecificResource"}function tn(e){return e&&e.type==="FragmentSelector"}function nn(e){if(e&&en(e)){let t=e.id,n=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return tn(n)&&(t+="#"+n.value),t}return e?.id}var rn={Manifest:function*(e,t,{isTopLevel:n}){return[...n?[["@context","http://iiif.io/api/presentation/2/context.json"]]:[],...O(e,"sc:Manifest"),...yield*z(e),...yield*W(e),["sequences",[{"@id":`${e.id}/sequence0`,"@type":"sc:Sequence",canvases:yield e.items}]],["structures",yield e.structures]]},Canvas:function*(e){let n=(yield e.items)[0];return[...O(e,"sc:Canvas"),...yield*z(e),...yield*W(e),["images",n?[n.resources]:void 0],["annotations",e.annotations&&e.annotations.length?b(yield e.annotations):void 0]]},AnnotationPage:function*(e){return[...O(e,"sc:AnnotationList"),...yield*z(e),["resources",e.items&&e.items.length?b(yield e.items):void 0]]},Annotation:function*(e){return[["@id",e.id],["@type","oa:Annotation"],["motivation","sc:painting"],["on",Xe(e.target)],["resource",b(yield e.body,!0)]]},ContentResource:function*(e){switch(e.type){case"Image":return[...O(e,"dctypes:Image"),...yield*z(e),...yield*W(e)];case"Text":case"Dataset":default:return[...O(e,void 0),...yield*z(e)]}},AnnotationCollection:function*(e){return[["@id",e.id],["@type","sc:Layer"],["label",k(e.label)]]},Collection:function*(e){return[...O(e,"sc:Collection"),...yield*z(e),...yield*W(e),["members",yield*e.items]]},Range:function*(e){let t=[],n=[];if(e.items)for(let i of e.items){let r=i.type==="SpecificResource"?i.source:i;if(r){let a=yield r;t.push({"@id":nn(i),"@type":r.type,label:a?a.label:void 0,within:e.id}),r.type==="Canvas"&&n.push(r.id)}}return[...O(e,"sc:Range"),...yield*z(e),...yield*W(e),["canvases",n.length===t.length?n:void 0],["members",n.length!==t.length?t:void 0]]}};function F(e){return[["id",e.id?.startsWith("vault://")?void 0:e.id],["type",e.type],["format",e.format],["profile",e.profile],["height",e.height||void 0],["width",e.width||void 0],["duration",e.duration||void 0],["viewingDirection",e.viewingDirection!=="left-to-right"?e.viewingDirection:void 0],["behavior",e.behavior&&e.behavior.length?e.behavior:void 0],["timeMode",e.timeMode],["motivation",Array.isArray(e.motivation)?e.motivation[0]:e.motivation],[u,y]]}function p(e){if(e===y||!e||e.length===0)return;let t=e.filter(n=>n!==y);if(t.length!==0)return t}function Je(e){if(e&&e.type&&e.type==="ImageService2"){let{id:t,type:n,profile:i,...r}=e,a=typeof i=="string"?i:Array.isArray(i)?i.find(o=>typeof o=="string"):"";return{"@id":t,"@type":n,profile:a?a.startsWith("http")?a:`http://iiif.io/api/image/2/${a}.json`:"http://iiif.io/api/image/2/level0.json",...r}}return e}function Ye(e){if(Array.isArray(e)||(e=e?[e]:[]),!(!e||e.length===0))return e.map(Je)}function*_(e){return[["label",e.label],["metadata",p(e.metadata)],["summary",e.summary],["requiredStatement",e.requiredStatement],["rights",Array.isArray(e.rights)?e.rights[0]||void 0:e.rights||void 0],["navDate",e.navDate],["language",e.language],["thumbnail",p(yield e.thumbnail)],["placeholderCanvas",yield e.placeholderCanvas],["accompanyingCanvas",yield e.accompanyingCanvas],["provider",p(yield e.provider)]]}function*E(e){return[["seeAlso",p(yield e.seeAlso)],["service",p(Ye(e.service))],["services",p(Ye(e.services))],["rendering",p(yield e.rendering)],["supplementary",p(yield e.supplementary)],["homepage",p(yield e.homepage)],["logo",p(yield e.logo)],["partOf",p(yield e.partOf)],["start",e.start?x(e.start):e.start]]}var an={Manifest:function*(e,t,{isTopLevel:n}){return n?[["@context",e["@context"]?e["@context"]:"http://iiif.io/api/presentation/3/context.json"],...F(e),...yield*_(e),...yield*E(e),["items",yield e.items],["structures",p(yield e.structures)],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]:[...F(e),...yield*_(e)]},Canvas:function*(e){return[...F(e),...yield*_(e),...yield*E(e),["items",yield e.items],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]},Agent:function*(e){return[["id",e.id],["type","Agent"],["label",e.label],...yield*E(e)]},AnnotationPage:function*(e){let t=Object.entries(e).map(([i,r])=>[i,Array.isArray(r)?p(r):r]).filter(([i,r])=>i!=="items"&&i!=="id"&&i!==u&&i!==A&&i!==S),n=yield e.items;return[["id",e.id?.startsWith("vault://")?void 0:e.id],...t,...yield*E(e),["items",n.length||e[S]===!1?n:y]]},Service:function*(e){return[[q,Je(e)]]},Annotation:function*(e){let t=Object.entries(e).map(([i,r])=>i==="motivation"?[i,Array.isArray(r)?r[0]:r]:i==="target"?[i,x(r,{allowString:!0,allowSourceString:!0,allowedStringType:"Canvas"})]:[i,Array.isArray(r)?p(r):r]).filter(([i])=>i!=="body"&&i!==u&&i!==S),n;if(Array.isArray(e.body)){let i=[];for(let r of e.body)if(r&&h(r)){let a={...r};a.source=yield r.source,i.push(x(a,{allowSourceString:!0}))}else i.push(yield r);n=i}else e.body&&h(e.body)?(n={...e.body},n.source=yield e.body.source):n=yield e.body;return[...t,...yield*_(e),...yield*E(e),["body",n.length===1?n[0]:n]]},ContentResource:function*(e){return sn([...F(e),...yield*_(e),...yield*E(e),["annotations",p(yield e.annotations)],["items",p(yield e.items)]],e)},AnnotationCollection:function*(e){return[["id",e.id],["type","AnnotationCollection"],["label",e.label]]},Collection:function*(e,t,{isTopLevel:n}){return n?[["@context","http://iiif.io/api/presentation/3/context.json"],...F(e),...yield*_(e),...yield*E(e),["items",p(yield e.items)],["navPlace",e.navPlace]]:[...F(e),...yield*_(e)]},Range:function*(e){let t=[];for(let n of e.items)n.type==="Range"?t.push(yield n):n&&n.type==="SpecificResource"?t.push(x(n)):t.push(n);return[...F(e),...yield*_(e),...yield*E(e),["items",t],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]}};function sn(e,t){let n=Object.keys(t),i=e.map(([r])=>r);for(let r of n)r===u||r===S||i.indexOf(r)===-1&&typeof t[r]<"u"&&e.push([r,t[r]]);return e}return rt(on);})();
"use strict";var IIIFParser=(()=>{var B=Object.defineProperty;var et=Object.getOwnPropertyDescriptor;var tt=Object.getOwnPropertyNames;var nt=Object.prototype.hasOwnProperty;var it=(e,t,n)=>t in e?B(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var rt=(e,t)=>{for(var n in t)B(e,n,{get:t[n],enumerable:!0})},at=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of tt(t))!nt.call(e,r)&&r!==n&&B(e,r,{get:()=>t[r],enumerable:!(i=et(t,r))||i.enumerable});return e};var st=e=>at(B({},"__esModule",{value:!0}),e);var g=(e,t,n)=>(it(e,typeof t!="symbol"?t+"":t,n),n);var Mn={};rt(Mn,{EMPTY:()=>s,HAS_PART:()=>u,IS_EXTERNAL:()=>T,PART_OF:()=>C,Traverse:()=>q,UNSET:()=>y,UNWRAP:()=>G,WILDCARD:()=>N,addFlagForExternalResource:()=>Q,compressSpecificResource:()=>_,defaultEntities:()=>fn,emptyAgent:()=>ae,emptyAnnotation:()=>ot,emptyAnnotationPage:()=>ee,emptyCanvas:()=>te,emptyCollection:()=>ne,emptyManifest:()=>ie,emptyRange:()=>re,emptyService:()=>se,frameResource:()=>ve,getDefaultEntities:()=>$e,identifyResource:()=>ye,isSpecificResource:()=>h,isWildcard:()=>de,languageString2to3:()=>z,merge:()=>X,mergeEntities:()=>Y,normalize:()=>Rn,resolveIfExists:()=>H,serialize:()=>In,serializeConfigPresentation2:()=>xn,serializeConfigPresentation3:()=>En,serializedFieldsToObject:()=>Qe,toRef:()=>$,traverseSpecificResource:()=>Je,types:()=>oe});function h(e){return typeof e=="string"?!1:!!e&&e.type==="SpecificResource"}function $(e,t){let n=t||"unknown";if(!e)return;if(typeof e=="string")return{id:e,type:n};if(h(e))return $(e.source,t);let i=n&&n!=="unknown"?n:e.type||e["@type"],r=e.id||e["@id"];if(i&&i.indexOf(":")!==-1&&(i=i.split(":").pop()),r&&i)return{id:r,type:i}}var N={},u="iiif-parser:hasPart",C="iiif-parser:partOf",T="iiif-parser:isExternal",y="__$UNSET$__",G="__$UNWRAP$__",s=[];Object.freeze(s);Object.freeze(N);function de(e){if(e===N||Object.keys(e).length===0)return!0;for(let t in e)return!1;return!0}function ve(e,t){if(t&&t["@explicit"]){let n={},i=Object.keys(t);for(let r of i)r===C||r==="@explicit"||(de(t[r])?n[r]=e[r]:n[r]=t[r]);return n}return e}function H(e,t,n){let i=$(t);if(!i)return[void 0,void 0];let r=e.requests[i.id],a=i.type||e.mapping[i.id];if(!a||r&&r.resourceUri&&(!e.entities[a]||!e.entities[a][r.resourceUri]))return[void 0,void 0];let o=e.entities[a][r?r.resourceUri:i.id];if(i.type&&!o)return H(e,{id:i.id},n);if(o&&o[u]){let l=o[u].find(c=>n?c[C]===n.id:c[C]===o.id);return[ve(o,l),o]}return[o,o]}var ot={id:"https://iiif-parser/annotation",type:"Annotation",behavior:s,label:null,thumbnail:s,summary:null,requiredStatement:null,metadata:s,seeAlso:s,homepage:s,rendering:s,service:s,accessibility:s,audience:s,body:s,bodyValue:null,canonical:null,created:null,creator:s,generated:null,generator:s,modified:null,motivation:s,rights:null,stylesheet:null,target:s,timeMode:void 0,via:s,partOf:s},ee={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:s,label:null,thumbnail:s,summary:null,requiredStatement:null,metadata:s,rights:null,provider:s,items:s,seeAlso:s,homepage:s,rendering:s,service:s},te={id:"https://iiif-parser/empty-canvas",type:"Canvas",label:null,behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,duration:0,height:0,width:0},ne={id:"https://iiif-parser/empty-collection",type:"Collection",label:null,viewingDirection:"left-to-right",behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,services:s},ie={id:"https://iiif-parser/empty-manifest",type:"Manifest",annotations:s,behavior:s,homepage:s,items:s,label:null,metadata:s,navDate:null,provider:s,partOf:s,accompanyingCanvas:null,placeholderCanvas:null,rendering:s,requiredStatement:null,rights:null,seeAlso:s,service:s,services:s,start:null,structures:s,summary:null,thumbnail:s,viewingDirection:"left-to-right"},re={id:"https://iiif-parser/empty-canvas",type:"Range",label:null,behavior:s,thumbnail:s,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:s,rights:null,navDate:null,provider:s,items:s,annotations:s,seeAlso:s,homepage:s,partOf:s,rendering:s,service:s,start:null,supplementary:null,viewingDirection:"left-to-right"},ae={id:"https://iiif-parser/empty-agent",type:"Agent",label:{},logo:s,seeAlso:s,homepage:s},se={id:"https://iiif-parser/empty-service",type:"UnknownService"};function S(e){return Array.isArray(e)?e:e?[e]:[]}function U(...e){return t=>e.reduce((n,i)=>i(n),t)}var oe=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function ye(e,t){if(typeof e>"u"||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"){if(t)return t;throw new Error(`${typeof e} is not a valid entity`)}if(typeof e.type=="string"){let n=oe.indexOf(e.type);if(n!==-1)return oe[n]}if(e.profile)return"Service";throw new Error("Resource type is not known")}var q=class e{constructor(t,n={}){g(this,"traversals");g(this,"options");g(this,"_traverseManifest",U(this.traverseManifestItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseManifestStructures.bind(this),this.traverseInlineAnnotationPages.bind(this)));g(this,"_traverseCanvas",U(this.traverseCanvasItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseInlineAnnotationPages.bind(this)));g(this,"_traverseAnnotationPage",U(this.traverseAnnotationPageItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this)));g(this,"_traverseRange",U(this.traverseRangeRanges.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this)));this.traversals={collection:[],manifest:[],canvas:[],annotationCollection:[],annotationPage:[],annotation:[],contentResource:[],choice:[],range:[],service:[],agent:[],specificResource:[],geoJson:[],...t},this.options={allowUndefinedReturn:!1,...n}}static all(t){return new e({collection:[t],manifest:[t],canvas:[t],annotationCollection:[t],annotationPage:[t],annotation:[t],contentResource:[t],choice:[t],range:[t],service:[t],geoJson:[t],specificResource:[t],agent:[t]})}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=S(t.thumbnail).map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.provider&&(t.provider=t.provider.map(n=>this.traverseAgent(n,t))),t}traverseLinking(t){return t.seeAlso&&(t.seeAlso=t.seeAlso.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.service&&(t.service=S(t.service).map(n=>this.traverseService(n))),t.services&&(t.services=S(t.services).map(n=>this.traverseService(n,t))),t.logo&&(t.logo=t.logo.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.homepage&&(t.homepage=t.homepage.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.partOf&&(t.partOf=t.partOf.map(n=>typeof n=="string"||!n.type?this.traverseType(n,{parent:t},this.traversals.contentResource):n.type==="Canvas"?this.traverseType(n,{parent:t},this.traversals.canvas):n.type==="AnnotationCollection"?this.traverseType(n,{parent:t},this.traversals.annotationCollection):n.type==="Collection"?this.traverseType(n,{parent:t},this.traversals.collection):this.traverseType(n,{parent:t},this.traversals.contentResource))),t.start&&(h(t.start)?t.start=this.traverseSpecificResource(t.start,"Canvas",t):t.start=this.traverseType(t.start,{parent:t},this.traversals.canvas)),t.rendering&&(t.rendering=t.rendering.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t.supplementary&&(t.supplementary=t.supplementary.map(n=>this.traverseType(n,{parent:t},this.traversals.contentResource))),t}traverseCollectionItems(t){return t.items&&t.items.map(n=>n.type==="Collection"?this.traverseCollection(n):this.traverseManifest(n)),t}traverseCollection(t,n){return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traverseLinkedCanvases(this.traverseCollectionItems(t))))),{parent:n},this.traversals.collection)}traverseGeoJson(t,n){return this.traverseType(t,{parent:n},this.traversals.geoJson)}traverseNavPlace(t){return t.navPlace&&(t.navPlace=this.traverseGeoJson(t.navPlace,t)),t}traverseManifestItems(t){return t.items&&(t.items=t.items.map(n=>this.traverseCanvas(n))),t}traverseManifestStructures(t){return t.structures&&(t.structures=t.structures.map(n=>this.traverseRange(n))),t}traverseManifest(t,n){return this.traverseType(this._traverseManifest(t),{parent:n},this.traversals.manifest)}traverseCanvasItems(t){return t.items=(t.items||[]).map(n=>this.traverseAnnotationPage(n,t)),t}traverseInlineAnnotationPages(t){return typeof t=="string"||!t||t.annotations&&(t.annotations=t.annotations.map(n=>this.traverseAnnotationPage(n,t))),t}traverseCanvas(t,n){return this.traverseType(this._traverseCanvas(t),{parent:n},this.traversals.canvas)}traverseAnnotationPageItems(t){return t.items&&(t.items=t.items.map(n=>this.traverseAnnotation(n,t))),t}traverseAnnotationPage(t,n){return this.traverseType(this._traverseAnnotationPage(t),{parent:n},this.traversals.annotationPage)}traverseAnnotationBody(t){return Array.isArray(t.body)?t.body=t.body.map(n=>this.traverseContentResource(n,t)):t.body&&(t.body=this.traverseContentResource(t.body,t)),t}traverseLinkedCanvases(t){return t.placeholderCanvas&&(t.placeholderCanvas=this.traverseCanvas(t.placeholderCanvas)),t.accompanyingCanvas&&(t.accompanyingCanvas=this.traverseCanvas(t.accompanyingCanvas)),t}traverseAnnotation(t,n){return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(this.traverseDescriptive(t))),{parent:n},this.traversals.annotation)}traverseContentResourceLinking(t){return typeof t=="string"||!t||t&&t.service&&(t.service=S(t.service||[]).map(n=>this.traverseService(n,t))),t}traverseContentResource(t,n){return t.type==="Choice"&&(t.items=t.items.map(i=>this.traverseContentResource(i,t))),h(t)?this.traverseSpecificResource(t,"ContentResource"):this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(t)),{parent:n},this.traversals.contentResource)}traverseSpecificResource(t,n,i){let r=t.source;return typeof t.source=="string"&&(r={id:t.source,type:n||"unknown"}),this.traverseType({...t,source:n==="Canvas"||r.type==="Canvas"?this.traverseType(r,{parent:i},this.traversals.canvas):n==="ContentResource"?this.traverseContentResource(r,{parent:i}):this.traverseUnknown(r,{parent:i,typeHint:n})},{parent:i},this.traversals.specificResource)}traverseRangeRanges(t){return t.items&&(t.items=t.items.map(n=>typeof n=="string"?this.traverseCanvas({id:n,type:"Canvas"},t):h(n)?this.traverseSpecificResource(n,"Canvas",t):n.type==="Manifest"?this.traverseManifest(n,t):this.traverseRange(n,t))),t}traverseRange(t,n){return this.traverseType(this._traverseRange(t),{parent:n},this.traversals.range)}traverseAgent(t,n){return this.traverseType(this.traverseDescriptive(this.traverseLinking(t)),{parent:n},this.traversals.agent)}traverseType(t,n,i){return i.reduce((r,a)=>{let o=a(r,n);return typeof o>"u"&&!this.options.allowUndefinedReturn?r:o},t)}traverseService(t,n){let i=Object.assign({},t);return i&&i.service&&(i.service=S(i.service).map(r=>this.traverseService(r))),this.traverseType(i,{parent:n},this.traversals.service)}traverseUnknown(t,{parent:n,typeHint:i}={}){let r=ye(t,i);switch(r){case"Collection":return this.traverseCollection(t,n);case"Manifest":return this.traverseManifest(t,n);case"Canvas":return this.traverseCanvas(t,n);case"AnnotationPage":return this.traverseAnnotationPage(t,n);case"Annotation":return this.traverseAnnotation(t,n);case"ContentResource":return this.traverseContentResource(t,n);case"Range":return this.traverseRange(t,n);case"Service":return this.traverseService(t,n);case"Agent":return this.traverseAgent(t,n);default:throw new Error(`Unknown or unsupported resource type of ${r}`)}}};var he=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function lt(e){if(typeof e>"u"||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"){let t=he.indexOf(e["@type"]);if(t!==-1)return he[t]}if(e.profile)return"Service";if(e.format||e["@type"])return"ContentResource";throw new Error("Resource type is not known")}var K=class e{constructor(t,n={}){g(this,"traversals");g(this,"options");this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...t},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...n}}static all(t){return new e({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){let n=[...(t.manifests||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i),...(t.collections||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i),...t.members||[]];delete t.collections,delete t.manifests,t.members=n}return t.manifests&&(t.manifests=t.manifests.map(n=>this.traverseManifest(typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n))),t.collections&&(t.collections=t.collections.map(n=>this.traverseCollection(typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n))),t.members&&(t.members=t.members.map(n=>typeof n=="string"?n:this.traverseUnknown(n))),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(n=>this.traverseSequence(n))),t.structures&&(t.structures=t.structures.map(n=>this.traverseRange(n))),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(n=>this.traverseCanvas(n))),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(n=>this.traverseAnnotation(n))),t.otherContent&&(t.otherContent=t.otherContent.map(n=>this.traverseAnnotationList(n))),t}traverseRange(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(t))),this.traversals.range)}traverseRangeItems(t){if(this.options.mergeMemberProperties){let n=[...(t.ranges||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Range"}:i),...(t.canvases||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Canvas"}:i),...t.members||[]];delete t.ranges,delete t.canvases,t.members=n.length?n.map(i=>this.traverseUnknown(i)):void 0}return t}traverseAnnotationList(t){let n=typeof t=="string"?{"@id":t,"@type":"sc:AnnotationList"}:t;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(n)),this.traversals.annotationList)}traverseAnnotationListItems(t){return t.resources&&(t.resources=t.resources.map(n=>this.traverseAnnotation(n))),t}traverseAnnotation(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(t))),this.traversals.annotation)}traverseAnnotationItems(t){return t.resource&&(Array.isArray(t.resource)?t.resource=t.resource.map(n=>this.traverseContentResource(n)):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(n=>this.traverseAnnotationList(n))),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(n=>this.traverseContentResource(n))),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(lt(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"sc: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){let n=Array.isArray(t),i=Array.isArray(t)?t:[t],r=[];for(let a of i)typeof a=="string"?r.push(this.traverseContentResource({"@id":a,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(a));return!n&&!this.options.convertPropsToArray?r[0]:r}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=this.traverseImageResource(t.thumbnail)),t.logo&&(t.logo=this.traverseImageResource(t.logo)),t}traverseOneOrMoreServices(t){let n=Array.isArray(t),i=Array.isArray(t)?t:[t],r=[];for(let a of i)r.push(this.traverseService(a));return!n&&!this.options.convertPropsToArray?r[0]:r}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,n){if(!Array.isArray(t))if(this.options.convertPropsToArray)t=[t];else return this.traverseType(t,n);return t.map(i=>this.traverseType(i,n))}traverseType(t,n){return n.reduce((i,r)=>{let a=r(i);return typeof a>"u"&&!this.options.allowUndefinedReturn?i:a},t)}};var ct="http://library.stanford.edu/iiif/image-api/compliance.html#level1",pt="http://library.stanford.edu/iiif/image-api/compliance.html#level2";var ft="http://library.stanford.edu/iiif/image-api/conformance.html#level1",ut="http://library.stanford.edu/iiif/image-api/conformance.html#level2";var dt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",vt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2";var yt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",ht="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2";var mt="http://iiif.io/api/image/1/level1.json",gt="http://iiif.io/api/image/1/profiles/level1.json",At="http://iiif.io/api/image/1/level2.json",Ct="http://iiif.io/api/image/1/profiles/level2.json";var Rt="http://iiif.io/api/image/2/level1.json",It="http://iiif.io/api/image/2/profiles/level1.json",Tt="http://iiif.io/api/image/2/level2.json",St="http://iiif.io/api/image/2/profiles/level2.json";var Pt="level1",_t="level2";var xt="http://iiif.io/api/image/2/level1",Et="http://iiif.io/api/image/2/level2",me=[xt,Et,ct,pt,ft,ut,dt,vt,yt,ht,mt,gt,At,Ct,Rt,It,Tt,St,Pt,_t];function m(e){for(let t in e)(typeof e[t]>"u"||e[t]===null)&&delete e[t];return e}var Lt="http://library.stanford.edu/iiif/image-api/compliance.html#level0",ge="http://library.stanford.edu/iiif/image-api/compliance.html#level1",Ae="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Mt="http://library.stanford.edu/iiif/image-api/conformance.html#level0",Ce="http://library.stanford.edu/iiif/image-api/conformance.html#level1",Re="http://library.stanford.edu/iiif/image-api/conformance.html#level2",bt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Ie="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Te="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Nt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Se="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Pe="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Ot="http://iiif.io/api/image/1/level0.json",Ft="http://iiif.io/api/image/1/profiles/level0.json",_e="http://iiif.io/api/image/1/level1.json",xe="http://iiif.io/api/image/1/profiles/level1.json",Ee="http://iiif.io/api/image/1/level2.json",Le="http://iiif.io/api/image/1/profiles/level2.json",wt="http://iiif.io/api/image/2/level0.json",zt="http://iiif.io/api/image/2/profiles/level0.json",Me="http://iiif.io/api/image/2/level1.json",be="http://iiif.io/api/image/2/profiles/level1.json",Ne="http://iiif.io/api/image/2/level2.json",Oe="http://iiif.io/api/image/2/profiles/level2.json",kt="level0",Fe="level1",we="level2",Dt="http://iiif.io/api/image/2/level0",ze="http://iiif.io/api/image/2/level1",ke="http://iiif.io/api/image/2/level2",le=[ke,Ae,Re,Te,Pe,Ee,Le,Ne,Oe,we],Qn=[...le,ze,ge,Ce,Ie,Se,_e,xe,Me,be,Fe],jt=[Dt,ze,ke,Lt,ge,Ae,Mt,Ce,Re,bt,Ie,Te,Nt,Se,Pe,Ot,Ft,_e,xe,Ee,Le,wt,zt,Me,be,Ne,Oe,kt,Fe,we],De=jt;var ce={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function Gt(e){if(typeof e=="string")return[e];if(!e)return[];let t=Array.isArray(e)?e:[e],n=[];for(let i of t){if(typeof i=="string"){n.push(i);continue}n.push({"@language":i["@language"]||i.language,"@value":i["@value"]||i.value})}return n}function O(e,t="none"){if(!e)return{};let n=Gt(e),i={};for(let r of n){if(typeof r=="string"){i[t]=i[t]?i[t]:[],i[t].push(r||"");continue}if(!r["@language"]){i[t]=i[t]?i[t]:[],i[t].push(r["@value"]||"");continue}let a=r["@language"];i[a]=i[a]?i[a]:[],i[a].push(r["@value"]||"")}return i}function qe(e){if(Array.isArray(e))return qe(e.find(t=>typeof t=="string"));if(le.indexOf(e)!==-1)return"level2";if(me.indexOf(e)!==-1)return"level1";if(De.indexOf(e)!==-1)return"level0";if(typeof e=="string")return e}function Ut(e){let t=Array.isArray(e)?e:[e];for(let n of t)switch(n){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 qt(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 je(e){for(let t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}var Vt=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function fe(e){let t=e["@id"]||e.id,n=e["@type"]||e.type,i=e.profile||void 0,r=e["@context"]||void 0;if(i){let a=qt(i);if(a)return a}if(r){let a=Ut(r);if(a)return a}if(n){if(Array.isArray(n)){if(n.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(n.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";n=n[0]}for(let a of["sc","oa","dcterms","dctypes","iiif"])if(n.startsWith(`${a}:`)){n=n.slice(a.length+1);break}switch(n){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(n&&Vt.indexOf(n)!==-1)return n;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":n||"unknown"}var Wt=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Bt(e){let t=e.match(Wt);return t?t[0]:e}function $t(e,t="Rights/License",n="none"){let i=null,r=[],a=Array.isArray(e)?e:[e];for(let o of a){let l=o?Bt(o):void 0;if(l&&(l.indexOf("creativecommons.org")!==-1||l.indexOf("rightsstatements.org")!==-1)){l.startsWith("https://")?i=`http://${l.slice(8)}`:i=l;continue}l&&r.push({label:{[n]:[t]},value:{[n]:[l]}})}return[i,r]}var Ht=["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 Kt(e){if(e){let t=Array.isArray(e)?e:[e],n=[];for(let i of t)i==="http://iiif.io/api/presentation/2/context.json"&&n.push("http://iiif.io/api/presentation/3/context.json"),Ht.indexOf(i)===-1&&n.push(i);if(t.length)return n.length===1?n[0]:n}}function Jt(e){return e?e.map(t=>({label:O(t.label),value:O(t.value)})):[]}var Ge=0;function Ve(e,t){let n=encodeURI(e.id||e["@id"]||"").trim();return n&&t?`${n}/${t}`:n||(Ge++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${Ge}`)}function R(e){let t=[...e.behavior||[]];e.viewingHint&&t.push(e.viewingHint);let n;return Array.isArray(e.motivation)?n=e.motivation.map(je):e.motivation&&(n=je(e.motivation)),{"@context":e["@context"]?Kt(e["@context"]):void 0,id:(e["@id"]||Ve(e)).trim(),type:fe(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:n,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function I(e){let[t,n]=$t(e.license),i=[...e.metadata?Jt(e.metadata):[],...n];return{rights:t,metadata:i.length?i:void 0,label:e.label?O(e.label):void 0,requiredStatement:e.attribution?{label:O(ce.attributionLabel),value:O(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?O(e.description):void 0,thumbnail:Qt(e.thumbnail)}}function Qt(e){return e&&(Array.isArray(e)?e:[e]).map(n=>typeof n=="string"?{id:n,type:"Image"}:(n.type==="unknown"&&(n.type="Image"),n))}function Xt(e){if(!e.within)return;let t=Array.isArray(e.within)?e.within:[e.within],n=[];for(let i of t)if(typeof i=="string"){if(i)switch(e["@type"]){case"sc:Manifest":n.push({id:i,type:"Collection"});break}}else i["@id"]&&n.push({id:i["@id"],type:fe(i)});return n.length?n:void 0}function P(e){let t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],n=e.contentLayer;return{provider:e.logo||t.length?[{id:ce.providerId,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:O(ce.providerName)}]:void 0,partOf:Xt(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?S(e.service):void 0,supplementary:n?[n]:void 0}}function Yt(e){return{chars:e.chars,format:e.format?e.format:void 0,language:e.language}}function Zt(e){return m({...R(e),...I(e),...P(e),items:e.members})}function en(e){let t=[],n=[],i;for(let a of e.sequences||[])a.canvases.length&&t.push(...a.canvases),a.behavior&&n.push(...a.behavior),a.startCanvas&&(i=a.startCanvas);let r=R(e);return n.length&&(r.behavior?r.behavior.push(...n):r.behavior=n),m({...r,...I(e),...P(e),start:i,items:t,structures:e.structures})}function tn(e){return m({...R(e),...I(e),...P(e),annotations:e.otherContent&&e.otherContent.length?e.otherContent:void 0,items:e.images&&e.images.length?[{id:Ve(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}function nn(e){return m({...R(e),...I(e),...P(e),items:e.resources&&e.resources.length?e.resources:void 0})}function rn(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}}function an(e){function t(n){if(Array.isArray(n)){if(n.length>1)return{type:"List",items:n.map(t)};n=n[0]}if(typeof n=="string")return encodeURI(n).trim();if("@type"in n){let i;if(typeof n.full=="string")i=n.full;else if(n.full["@type"]==="dctypes:Image")i={id:n.full["@id"],type:"Image"};else if(n.full["@type"]==="sc:Canvas")i={id:n.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${n.full["@type"]}`);return{type:"SpecificResource",source:i,selector:pe(n.selector)}}else return encodeURI(n["@id"]).trim()}return m({...R(e),...I(e),...P(e),target:t(e.on),body:Array.isArray(e.resource)?e.resource.map(Ue):Ue(e.resource)})}function Ue(e){return e.type==="Choice"?e:We(e)}function We(e){let t=e;return m({...R(t),...I(t),...P(t),...Yt(t)})}function sn(e){let t=[];return e.default&&e.default!=="rdf:nil"&&t.push(e.default),e.item&&e.item!=="rdf:nil"&&t.push(...e.item),m({...R(e),...I(e),items:t})}function on(e){return m({...R(e),...I(e),...P(e),items:e.members})}function ln(e){let{"@id":t,"@type":n,"@context":i,profile:r,...a}=e,o={};return t&&(o["@id"]=t),o["@type"]=fe(e),o["@type"]==="unknown"&&(i&&i.length&&(o["@context"]=i),o["@type"]="Service"),r&&(o.profile=qe(r)),m({...o,...a})}function cn(e){return m({...R(e),...I(e),...P(e)})}var pn=new K({collection:[Zt],manifest:[en],canvas:[tn],annotationList:[nn],sequence:[rn],annotation:[an],contentResource:[We],choice:[sn],range:[on],service:[ln],layer:[cn]});function Be(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"?pn.traverseUnknown(e):e}function pe(e){if((Array.isArray(e["@type"])&&e["@type"].includes("oa:SvgSelector")||e["@type"]=="oa:SvgSelector")&&("chars"in e||"value"in e))return{type:"SvgSelector",value:"chars"in e?e.chars:e.value};if(e["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:e.value};if(e["@type"]==="oa:Choice")return[pe(e.default),...(Array.isArray(e.item)?e.item:[e.item]).map(pe)];if(e["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in e?e.region:void 0,rotation:"rotation"in e?e.rotation:void 0};throw new Error(`Unsupported selector type: ${e["@type"]}`)}function J(e,t={}){if(Array.isArray(e))return J(e[0]);if(typeof e=="string"){let[n,i]=e.split("#");return i?{type:"SpecificResource",source:{id:n,type:t.typeHint||"Unknown"},selector:{type:"FragmentSelector",value:i}}:{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||t.typeHint||"Unknown"}}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return J(e.items[0]);if(e.type==="SpecificResource")return e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]),e.selector?{type:"SpecificResource",source:e.source,selector:e.selector}:{type:"SpecificResource",source:e.source};if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);let[n,i]=e.id.split("#");return i?{type:"SpecificResource",source:{...e,id:n},selector:{type:"FragmentSelector",value:i}}:{type:"SpecificResource",source:{...e,id:n}}}return{type:"SpecificResource",source:e}}var fn={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}};function $e(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}function He(e,t){if(typeof e=="string")return{id:e,type:t};if(!e.id)throw new Error(`Invalid resource does not have an ID (${JSON.stringify(e)}, ${t})`);return e}function un(e,t){return(n,i)=>{let r=e[n]?e[n]:{};return(a,o)=>{let l=He(a,i||n);return l&&l.id&&n?(r[l.id]=r[l.id]?Y(r[l.id],l,{parent:o.parent,isTopLevel:t.id===l.id}):Y({id:l.id,type:l.type},l,{parent:o.parent,isTopLevel:t.id===l.id}),{id:l.id,type:n==="ContentResource"?n:l.type}):l}}}function X(e,t,n){if(!t)return e;if(Array.isArray(e)){if(!Array.isArray(t))throw new Error("Cannot merge array with non-array");let i=[...e];for(let r of t)if(r["@id"]&&!r.id&&(r.id=r["@id"]),r["@type"]&&!r.type&&(r.type=r["@type"]),r!=null)if(Array.isArray(r))i.push(r);else if(typeof r=="object"&&r.id&&r.type){let a=i.findIndex(o=>o.id===r.id&&o.type===r.type);a>=0&&(i[a]=X(i[a],r))}else e.indexOf(r)===-1&&i.push(r);return i}else if(typeof e=="object"){if(Array.isArray(t)||typeof t!="object")throw new Error("Cannot merge object with non-object");let i={...e},r=[],a=[],o=Object.keys(e).filter(c=>c!==u&&c!=="id"&&c!=="type"),l={},M={};for(let[c,f]of Object.entries(t)){if(c===u||c==="id"||c==="type")continue;let v=i[c];v===f?a.push(c):v===s||!v?(r.push(c),i[c]=f):(v&&f&&(l[c]=v,M[c]=f),i[c]=X(v,f),i[c]===l[c]&&(a.push(c),delete l[c]))}if(n&&(n.parent&&n.parent.id||n.isTopLevel)){let c=[],f={};if(n.parent?f[C]=n.parent.id:n.isTopLevel&&(f[C]=e.id),i[u]&&i[u].length){let v=!(i[u]||[]).find(A=>A["@explicit"]),b=r.length>0||a.length!==o.length;if(v&&b)for(let A of i[u]){let d={...A},Z=Object.keys(l);if(d){d["@explicit"]=!0;for(let j of o)j!==u&&(d[j]=N);for(let j of Z)d[j]=l[j]}c.push(d)}else c.push(...i[u]);if(b){let A=Object.keys(M);f["@explicit"]=!0;for(let d of r)f[d]=N;for(let d of a)f[d]=N;for(let d of A)f[d]=M[d]}}f.id=i.id,f.type=i.type,c.push(f),i[u]=c}return i}else if(e)return e;return t}function Y(e,t,n){if(typeof e=="string")return e;if(t.id!==e.id||t.type!==e.type){if(t.type==="ImageService3")return t;if(e.type==="ImageService3")return e;throw new Error(`Can only merge entities with identical identifiers and type! ${t.type}(${t.id}) => ${e.type}(${e.id})`)}return X({...e},t,n)}function dn(e){return(t,n)=>i=>{let{id:r,type:a}=He(i,n||t);if(typeof r>"u")throw new Error("Found invalid entity without an ID.");return t==="ContentResource"||t==="Service"?e[r]=t:e[r]=a,i}}function vn(e){let t=Object.assign({},e);if(t["@id"]&&(t.id=t["@id"]),t["@type"]&&(t.type=t["@type"]),t.service){let n=[];t.service=Array.isArray(t.service)?t.service:[t.service];for(let i of t.service)n.push({id:i["@id"]||i.id,type:i["@type"]||i.type});t.service=n}return Object.assign({},se,t)}function yn(e){return t=>{e.Service=e.Service?e.Service:{};let n=t.id||t["@id"],i=vn(t);return i&&i.id&&(e.Service[i.id]?e.Service[n]=Y(e.Service[n],i):e.Service[n]=i),t}}function hn(e){let t=JSON.stringify(e),n=5381,i=t.length;for(;i;)n=n*33^t.charCodeAt(--i);let a=(n>>>0).toString(16);return a.length%2?"0"+a:a}function ue(e){return t=>typeof t=="string"?{id:t,type:e}:t.id?t.type?t:{type:e,...t}:{id:`vault://${hn(t)}`,type:e,...t}}function D(e){return t=>({...e,...t})}function V(e){return Array.isArray(e)?e:[e]}function mn(e){return e.body&&(e.body=V(e.body)),e.seeAlso&&(e.seeAlso=V(e.seeAlso)),e.audience&&(e.audience=V(e.audience)),e.accessibility&&(e.accessibility=V(e.accessibility)),e.motivation&&(e.motivation=V(e.motivation)),e}function Ke(e,{typeHint:t,partOfTypeHint:n}={}){if(typeof e=="string"&&(e={id:e,type:t||"unknown"}),h(e))return typeof e.source=="string"&&(e.source={id:e.source,type:t||"unknown"}),e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:n||"Manifest"}]),e;let i;if((e.id||"").indexOf("#")!==-1){let[r,a]=(e.id||"").split("#");e.id=r,a&&(i={type:"FragmentSelector",value:a})}return{type:"SpecificResource",source:e,selector:i}}function gn(e){let t=Object.assign({},e);return e&&e.items&&(t.items=e.items.map(n=>typeof n=="string"||n.type==="Canvas"?Ke(n):n)),t}function An(e){let t=Object.assign({},e);return t.start?(t.start=Ke(t.start,{typeHint:"Canvas"}),t):e}function Cn(e){let t=Object.assign({},e);return t.target?(t.target=J(t.target,{typeHint:"Canvas"}),t):e}function Je(e){return e}function Q(e){return typeof e.items>"u"&&(e[T]=!0),e}function Rn(e){let t=Be(e),n=$e(),i={},r=un(n,t),a=dn(i),l=new q({collection:[Q,D(ne),a("Collection"),r("Collection")],manifest:[Q,D(ie),An,a("Manifest"),r("Manifest")],canvas:[D(te),a("Canvas"),r("Canvas")],annotationPage:[Q,ue("AnnotationPage"),D(ee),a("AnnotationPage"),r("AnnotationPage")],annotation:[ue("Annotation"),mn,Cn,a("Annotation"),r("Annotation")],contentResource:[ue("ContentResource"),a("ContentResource"),r("ContentResource")],range:[D(re),gn,a("Range","Canvas"),r("Range","Canvas")],agent:[D(ae),a("Agent"),r("Agent")],specificResource:[Je],service:[yn(n)]}).traverseUnknown(t);return{entities:n,resource:l,mapping:i}}function Qe(e){let t={};for(let[n,i]of e){if(n===G&&i!==y)return i;i!==y&&typeof i<"u"&&i!==null&&(t[n]=i)}return t}function In(e,t,n){if(!t.type||!t.id)throw new Error("Unknown entity");if(!n[t.type])throw new Error(`Serializer not found for ${t.type}`);function i(r,a,o=0){let l=n[r.type];if(!l)return y;if(o>20)throw new Error("Circular reference: "+r.id+" "+r.type);let[M,c]=H(e,r.type?r:r.id,a)||(r.id&&r.type?r:null);if(!M)return y;let f=l(M,e,{parent:a,isTopLevel:t.id===r.id,fullResource:c}),v=f.next();for(;!v.done;){let b=v.value,A=y;if(b)if(Array.isArray(b)){let d=[];for(let Z of b)d.push(i(Z,r,o+1));A=d}else A=i(b,r,o+1);v=f.next(A)}return v.value===y?y:Qe(v.value)}return i(t)}function _(e,{allowSourceString:t=!0,allowString:n=!1,allowedStringType:i}={}){let r=a=>{if(t&&a&&a.source&&typeof a.source!="string"){let o=Object.keys(a.source);if(a.source.id&&a.source.type&&o.length===2)return{...a,source:a.source.id}}return a};if(e){if(e.source&&e.source.partOf)return r(e);let a=Object.keys(e);if(a.length===2&&e.type&&e.source||a.length===3&&e.type&&e.source&&a.indexOf("selector")!==-1&&!e.selector)return n&&(!i||i===e.source.type)?e.source.id:e.source.type==="ContentResource"?{type:"SpecificResource",source:e.source.id}:e.source;if(e.selector&&!Array.isArray(e.selector)&&typeof e.selector!="string"&&e.selector.type==="FragmentSelector"){let o=`${e.source.id}#${e.selector.value}`;return n?o:{id:o,type:e.source.type}}}return r(e)}function z(e){if(!e)return;let t=Object.keys(e);if(t.length!==0){if(t.length===1){let n=t[0];if(!n)return"";let i=(e[n]||[]).join("");return n==="@none"||n==="none"||n==="en"?i:{"@language":n,"@value":i}}return t.map(n=>({"@language":n,"@value":(e[n]||[]).join("")}))}}function Xe(e){return Array.isArray(e)?e.map(t=>Xe(t)):typeof e=="string"?e:e.type&&e.type==="Canvas"?e.id:e}function x(e,t=!1){if(e)return e.length>1&&!t?e:e[0]||void 0}function Tn(e){if(e){if(typeof e=="string")return{"@id":e};if("@id"in e){let t={...e};return delete t["@type"],t}return{"@context":"http://iiif.io/api/image/2/context.json","@id":e.id,profile:`http://iiif.io/api/image/2/profiles/${e.profile}.json`}}}function F(e,t){return[["@id",e.id],["@type",t],["format",e.format],["height",e.height],["width",e.width],["viewingDirection",e.viewingDirection!=="left-to-right"?e.viewingDirection:void 0],["license",e.license?e.license:void 0]]}function*w(e){let t=e.provider?yield e.provider[0]:void 0;return[["label",z(e.label)],["metadata",e.metadata&&e.metadata.length?e.metadata.map(n=>({label:z(n.label)||"",value:z(n.value)||""})):void 0],["description",z(e.summary)],["thumbnail",x(yield e.thumbnail)],["navDate",e.navDate],["logo",t?x(t.logo):void 0],["homepage",t?t.homepage:void 0],["attribution",e.requiredStatement?z(e.requiredStatement.value):void 0]]}function*W(e){let t=e.start&&e.start.type&&e.start.type==="SpecificResource"?_(e.start):e.start;return[["seeAlso",x(yield e.seeAlso)],["service",x((e.service||[]).map(Tn))],["rendering",x(yield e.rendering)],["startCanvas",t?t.id:void 0]]}function Sn(e){return e.type==="SpecificResource"}function Pn(e){return e&&e.type==="FragmentSelector"}function _n(e){if(e&&Sn(e)){let t=e.id,n=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return Pn(n)&&(t+="#"+n.value),t}return e?.id}var xn={Manifest:function*(e,t,{isTopLevel:n}){return[...n?[["@context","http://iiif.io/api/presentation/2/context.json"]]:[],...F(e,"sc:Manifest"),...yield*w(e),...yield*W(e),["sequences",[{"@id":`${e.id}/sequence0`,"@type":"sc:Sequence",canvases:yield e.items}]],["structures",yield e.structures]]},Canvas:function*(e){let n=(yield e.items)[0];return[...F(e,"sc:Canvas"),...yield*w(e),...yield*W(e),["images",n?[n.resources]:void 0],["annotations",e.annotations&&e.annotations.length?x(yield e.annotations):void 0]]},AnnotationPage:function*(e){return[...F(e,"sc:AnnotationList"),...yield*w(e),["resources",e.items&&e.items.length?x(yield e.items):void 0]]},Annotation:function*(e){return[["@id",e.id],["@type","oa:Annotation"],["motivation","sc:painting"],["on",Xe(e.target)],["resource",x(yield e.body,!0)]]},ContentResource:function*(e){switch(e.type){case"Image":return[...F(e,"dctypes:Image"),...yield*w(e),...yield*W(e)];case"Text":case"Dataset":default:return[...F(e,void 0),...yield*w(e)]}},AnnotationCollection:function*(e){return[["@id",e.id],["@type","sc:Layer"],["label",z(e.label)]]},Collection:function*(e){return[...F(e,"sc:Collection"),...yield*w(e),...yield*W(e),["members",yield*e.items]]},Range:function*(e){let t=[],n=[];if(e.items)for(let i of e.items){let r=i.type==="SpecificResource"?i.source:i;if(r){let a=yield r;t.push({"@id":_n(i),"@type":r.type,label:a?a.label:void 0,within:e.id}),r.type==="Canvas"&&n.push(r.id)}}return[...F(e,"sc:Range"),...yield*w(e),...yield*W(e),["canvases",n.length===t.length?n:void 0],["members",n.length!==t.length?t:void 0]]}};function k(e){return[["id",e.id?.startsWith("vault://")?void 0:e.id],["type",e.type],["format",e.format],["profile",e.profile],["height",e.height||void 0],["width",e.width||void 0],["duration",e.duration||void 0],["viewingDirection",e.viewingDirection!=="left-to-right"?e.viewingDirection:void 0],["behavior",e.behavior&&e.behavior.length?e.behavior:void 0],["timeMode",e.timeMode],["motivation",Array.isArray(e.motivation)?e.motivation[0]:e.motivation],[u,y]]}function p(e){if(e===y||!e||e.length===0)return;let t=e.filter(n=>n!==y);if(t.length!==0)return t}function Ze(e){if(e&&e.type&&e.type==="ImageService2"){let{id:t,type:n,profile:i,...r}=e,a=typeof i=="string"?i:Array.isArray(i)?i.find(o=>typeof o=="string"):"";return{"@id":t,"@type":n,profile:a?a.startsWith("http")?a:`http://iiif.io/api/image/2/${a}.json`:"http://iiif.io/api/image/2/level0.json",...r}}return e}function Ye(e){if(Array.isArray(e)||(e=e?[e]:[]),!(!e||e.length===0))return e.map(Ze)}function*E(e){return[["label",e.label],["metadata",p(e.metadata)],["summary",e.summary],["requiredStatement",e.requiredStatement],["rights",Array.isArray(e.rights)?e.rights[0]||void 0:e.rights||void 0],["navDate",e.navDate],["language",e.language],["thumbnail",p(yield e.thumbnail)],["placeholderCanvas",yield e.placeholderCanvas],["accompanyingCanvas",yield e.accompanyingCanvas],["provider",p(yield e.provider)]]}function*L(e){return[["seeAlso",p(yield e.seeAlso)],["service",p(Ye(e.service))],["services",p(Ye(e.services))],["rendering",p(yield e.rendering)],["supplementary",p(yield e.supplementary)],["homepage",p(yield e.homepage)],["logo",p(yield e.logo)],["partOf",p(yield e.partOf)],["start",e.start?_(e.start):e.start]]}var En={Manifest:function*(e,t,{isTopLevel:n}){return n?[["@context",e["@context"]?e["@context"]:"http://iiif.io/api/presentation/3/context.json"],...k(e),...yield*E(e),...yield*L(e),["items",yield e.items],["structures",p(yield e.structures)],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]:[...k(e),...yield*E(e)]},Canvas:function*(e){return[...k(e),...yield*E(e),...yield*L(e),["items",yield e.items],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]},Agent:function*(e){return[["id",e.id],["type","Agent"],["label",e.label],...yield*L(e)]},AnnotationPage:function*(e){let t=Object.entries(e).map(([i,r])=>[i,Array.isArray(r)?p(r):r]).filter(([i,r])=>i!=="items"&&i!=="id"&&i!==u&&i!==C&&i!==T),n=yield e.items;return[["id",e.id?.startsWith("vault://")?void 0:e.id],...t,...yield*L(e),["items",n.length||e[T]===!1?n:y]]},Service:function*(e){return[[G,Ze(e)]]},Annotation:function*(e){let t=Object.entries(e).map(([i,r])=>i==="motivation"?[i,Array.isArray(r)?r[0]:r]:i==="target"?[i,_(r,{allowString:!0,allowSourceString:!0,allowedStringType:"Canvas"})]:[i,Array.isArray(r)?p(r):r]).filter(([i])=>i!=="body"&&i!==u&&i!==T),n;if(Array.isArray(e.body)){let i=[];for(let r of e.body)if(r&&h(r)){let a={...r};a.source=yield r.source,i.push(_(a,{allowSourceString:!0}))}else i.push(yield r);n=i}else e.body&&h(e.body)?(n={...e.body},n.source=yield e.body.source):n=yield e.body;return[...t,...yield*E(e),...yield*L(e),["body",n.length===1?n[0]:n]]},ContentResource:function*(e){return Ln([...k(e),...yield*E(e),...yield*L(e),["annotations",p(yield e.annotations)],["items",p(yield e.items)]],e)},AnnotationCollection:function*(e){return[["id",e.id],["type","AnnotationCollection"],["label",e.label]]},Collection:function*(e,t,{isTopLevel:n}){return n?[["@context","http://iiif.io/api/presentation/3/context.json"],...k(e),...yield*E(e),...yield*L(e),["items",p(yield e.items)],["navPlace",e.navPlace]]:[...k(e),...yield*E(e)]},Range:function*(e){let t=[];for(let n of e.items)n.type==="Range"?t.push(yield n):n&&n.type==="SpecificResource"?t.push(_(n)):t.push(n);return[...k(e),...yield*E(e),...yield*L(e),["items",t],["annotations",p(yield e.annotations)],["navPlace",e.navPlace]]}};function Ln(e,t){let n=Object.keys(t),i=e.map(([r])=>r);for(let r of n)r===u||r===T||i.indexOf(r)===-1&&typeof t[r]<"u"&&e.push([r,t[r]]);return e}return st(Mn);})();

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

import{A as E,B as F,C as G,D as H,E as I,F as J,a as b,b as c,c as d,d as e,e as f,f as g,g as h,h as i,i as j,j as k,k as l,l as m,m as n,n as o,o as p,p as q,q as r,r as s,s as t,t as x,u as y,v as z,w as A,x as B,y as C,z as D}from"./chunk-B3QFAJ6Y.js";import"./chunk-R2Q75YNZ.js";import"./chunk-7IIDO3IU.js";import{a,b as u,c as v,d as w}from"./chunk-3Q4WO4OP.js";import"./chunk-NJNTZ6QT.js";import"./chunk-D22QKJZO.js";export{i as EMPTY,d as HAS_PART,f as IS_EXTERNAL,e as PART_OF,w as Traverse,g as UNSET,h as UNWRAP,c as WILDCARD,C as addFlagForExternalResource,G as compressSpecificResource,x as defaultEntities,s as emptyAgent,m as emptyAnnotation,n as emptyAnnotationPage,o as emptyCanvas,p as emptyCollection,q as emptyManifest,r as emptyRange,t as emptyService,k as frameResource,y as getDefaultEntities,v as identifyResource,a as isSpecificResource,j as isWildcard,H as languageString2to3,z as merge,A as mergeEntities,D as normalize,l as resolveIfExists,F as serialize,I as serializeConfigPresentation2,J as serializeConfigPresentation3,E as serializedFieldsToObject,b as toRef,B as traverseSpecificResource,u as types};
import{A as E,B as F,C as G,D as H,E as I,F as J,a as b,b as c,c as d,d as e,e as f,f as g,g as h,h as i,i as j,j as k,k as l,l as m,m as n,n as o,o as p,p as q,q as r,r as s,s as t,t as x,u as y,v as z,w as A,x as B,y as C,z as D}from"./chunk-I7GUVEYK.js";import"./chunk-R2Q75YNZ.js";import"./chunk-3WVPINNO.js";import"./chunk-J657UVVW.js";import{a,b as u,c as v,d as w}from"./chunk-3Q4WO4OP.js";import"./chunk-NJNTZ6QT.js";import"./chunk-D22QKJZO.js";export{i as EMPTY,d as HAS_PART,f as IS_EXTERNAL,e as PART_OF,w as Traverse,g as UNSET,h as UNWRAP,c as WILDCARD,C as addFlagForExternalResource,G as compressSpecificResource,x as defaultEntities,s as emptyAgent,m as emptyAnnotation,n as emptyAnnotationPage,o as emptyCanvas,p as emptyCollection,q as emptyManifest,r as emptyRange,t as emptyService,k as frameResource,y as getDefaultEntities,v as identifyResource,a as isSpecificResource,j as isWildcard,H as languageString2to3,z as merge,A as mergeEntities,D as normalize,l as resolveIfExists,F as serialize,I as serializeConfigPresentation2,J as serializeConfigPresentation3,E as serializedFieldsToObject,b as toRef,B as traverseSpecificResource,u as types};

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

"use strict";var h=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var X=Object.prototype.hasOwnProperty;var Y=(t,e,n)=>e in t?h(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var Z=(t,e)=>{for(var n in e)h(t,n,{get:e[n],enumerable:!0})},ee=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Q(e))!X.call(t,r)&&r!==n&&h(t,r,{get:()=>e[r],enumerable:!(i=K(e,r))||i.enumerable});return t};var te=t=>ee(h({},"__esModule",{value:!0}),t);var d=(t,e,n)=>(Y(t,typeof e!="symbol"?e+"":e,n),n);var Ge={};Z(Ge,{upgrade:()=>De});module.exports=te(Ge);var ne="http://library.stanford.edu/iiif/image-api/compliance.html#level0",I="http://library.stanford.edu/iiif/image-api/compliance.html#level1",C="http://library.stanford.edu/iiif/image-api/compliance.html#level2",ie="http://library.stanford.edu/iiif/image-api/conformance.html#level0",P="http://library.stanford.edu/iiif/image-api/conformance.html#level1",_="http://library.stanford.edu/iiif/image-api/conformance.html#level2",re="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",T="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",x="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",ae="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",L="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",R="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",se="http://iiif.io/api/image/1/level0.json",oe="http://iiif.io/api/image/1/profiles/level0.json",E="http://iiif.io/api/image/1/level1.json",S="http://iiif.io/api/image/1/profiles/level1.json",M="http://iiif.io/api/image/1/level2.json",O="http://iiif.io/api/image/1/profiles/level2.json",pe="http://iiif.io/api/image/2/level0.json",fe="http://iiif.io/api/image/2/profiles/level0.json",w="http://iiif.io/api/image/2/level1.json",b="http://iiif.io/api/image/2/profiles/level1.json",F="http://iiif.io/api/image/2/level2.json",N="http://iiif.io/api/image/2/profiles/level2.json",ce="level0",k="level1",D="level2",le="http://iiif.io/api/image/2/level0",G="http://iiif.io/api/image/2/level1",j="http://iiif.io/api/image/2/level2",q=[G,j,I,C,P,_,T,x,L,R,E,S,M,O,w,b,F,N,k,D],V=[le,G,j,ne,I,C,ie,P,_,re,T,x,ae,L,R,se,oe,E,S,M,O,pe,fe,w,b,F,N,ce,k,D];var U=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function ue(t){if(typeof t>"u"||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"){let e=U.indexOf(t["@type"]);if(e!==-1)return U[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}var v=class t{constructor(e,n={}){d(this,"traversals");d(this,"options");this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...n}}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){let n=[...(e.manifests||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i),...(e.collections||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i),...e.members||[]];delete e.collections,delete e.manifests,e.members=n}return e.manifests&&(e.manifests=e.manifests.map(n=>this.traverseManifest(typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n))),e.collections&&(e.collections=e.collections.map(n=>this.traverseCollection(typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n))),e.members&&(e.members=e.members.map(n=>typeof n=="string"?n:this.traverseUnknown(n))),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(n=>this.traverseSequence(n))),e.structures&&(e.structures=e.structures.map(n=>this.traverseRange(n))),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(n=>this.traverseCanvas(n))),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(n=>this.traverseAnnotation(n))),e.otherContent&&(e.otherContent=e.otherContent.map(n=>this.traverseAnnotationList(n))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){let n=[...(e.ranges||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Range"}:i),...(e.canvases||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Canvas"}:i),...e.members||[]];delete e.ranges,delete e.canvases,e.members=n.length?n.map(i=>this.traverseUnknown(i)):void 0}return e}traverseAnnotationList(e){let n=typeof e=="string"?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(n)),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map(n=>this.traverseAnnotation(n))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(Array.isArray(e.resource)?e.resource=e.resource.map(n=>this.traverseContentResource(n)):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(n=>this.traverseAnnotationList(n))),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(n=>this.traverseContentResource(n))),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(ue(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"sc: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){let n=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(let a of i)typeof a=="string"?r.push(this.traverseContentResource({"@id":a,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(a));return!n&&!this.options.convertPropsToArray?r[0]:r}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){let n=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(let a of i)r.push(this.traverseService(a));return!n&&!this.options.convertPropsToArray?r[0]:r}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,n){if(!Array.isArray(e))if(this.options.convertPropsToArray)e=[e];else return this.traverseType(e,n);return e.map(i=>this.traverseType(i,n))}traverseType(e,n){return n.reduce((i,r)=>{let a=r(i);return typeof a>"u"&&!this.options.allowUndefinedReturn?i:a},e)}};function $(t){return Array.isArray(t)?t:t?[t]:[]}function o(t){for(let e in t)(typeof t[e]>"u"||t[e]===null)&&delete t[e];return t}var y={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function he(t){if(typeof t=="string")return[t];if(!t)return[];let e=Array.isArray(t)?t:[t],n=[];for(let i of e){if(typeof i=="string"){n.push(i);continue}n.push({"@language":i["@language"]||i.language,"@value":i["@value"]||i.value})}return n}function u(t,e="none"){if(!t)return{};let n=he(t),i={};for(let r of n){if(typeof r=="string"){i[e]=i[e]?i[e]:[],i[e].push(r||"");continue}if(!r["@language"]){i[e]=i[e]?i[e]:[],i[e].push(r["@value"]||"");continue}let a=r["@language"];i[a]=i[a]?i[a]:[],i[a].push(r["@value"]||"")}return i}function H(t){if(Array.isArray(t))return H(t.find(e=>typeof e=="string"));if(V.indexOf(t)!==-1)return"level2";if(q.indexOf(t)!==-1)return"level1";if(typeof t=="string")return t}function ve(t){let e=Array.isArray(t)?t:[t];for(let n of e)switch(n){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 W(t){for(let e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}var ye=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function A(t){let e=t["@id"]||t.id,n=t["@type"]||t.type,i=t.profile||void 0,r=t["@context"]||void 0;if(i){let a=de(i);if(a)return a}if(r){let a=ve(r);if(a)return a}if(n){if(Array.isArray(n)){if(n.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(n.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";n=n[0]}for(let a of["sc","oa","dcterms","dctypes","iiif"])if(n.startsWith(`${a}:`)){n=n.slice(a.length+1);break}switch(n){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(n&&ye.indexOf(n)!==-1)return n;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":n||"unknown"}var ge=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function me(t){let e=t.match(ge);return e?e[0]:t}function Ae(t,e="Rights/License",n="none"){let i=null,r=[],a=Array.isArray(t)?t:[t];for(let s of a){let c=s?me(s):void 0;if(c&&(c.indexOf("creativecommons.org")!==-1||c.indexOf("rightsstatements.org")!==-1)){c.startsWith("https://")?i=`http://${c.slice(8)}`:i=c;continue}c&&r.push({label:{[n]:[e]},value:{[n]:[c]}})}return[i,r]}var Ie=["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 Ce(t){if(t){let e=Array.isArray(t)?t:[t],n=[];for(let i of e)i==="http://iiif.io/api/presentation/2/context.json"&&n.push("http://iiif.io/api/presentation/3/context.json"),Ie.indexOf(i)===-1&&n.push(i);if(e.length)return n.length===1?n[0]:n}}function Pe(t){return t?t.map(e=>({label:u(e.label),value:u(e.value)})):[]}var B=0;function J(t,e){let n=encodeURI(t.id||t["@id"]||"").trim();return n&&e?`${n}/${e}`:n||(B++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${B}`)}function p(t){let e=[...t.behavior||[]];t.viewingHint&&e.push(t.viewingHint);let n;return Array.isArray(t.motivation)?n=t.motivation.map(W):t.motivation&&(n=W(t.motivation)),{"@context":t["@context"]?Ce(t["@context"]):void 0,id:(t["@id"]||J(t)).trim(),type:A(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:n,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function f(t){let[e,n]=Ae(t.license),i=[...t.metadata?Pe(t.metadata):[],...n];return{rights:e,metadata:i.length?i:void 0,label:t.label?u(t.label):void 0,requiredStatement:t.attribution?{label:u(y.attributionLabel),value:u(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?u(t.description):void 0,thumbnail:_e(t.thumbnail)}}function _e(t){return t&&(Array.isArray(t)?t:[t]).map(n=>typeof n=="string"?{id:n,type:"Image"}:(n.type==="unknown"&&(n.type="Image"),n))}function Te(t){if(!t.within)return;let e=Array.isArray(t.within)?t.within:[t.within],n=[];for(let i of e)if(typeof i=="string"){if(i)switch(t["@type"]){case"sc:Manifest":n.push({id:i,type:"Collection"});break}}else i["@id"]&&n.push({id:i["@id"],type:A(i)});return n.length?n:void 0}function l(t){let e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],n=t.contentLayer;return{provider:t.logo||e.length?[{id:y.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(y.providerName)}]:void 0,partOf:Te(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?$(t.service):void 0,supplementary:n?[n]:void 0}}function xe(t){return{chars:t.chars,format:t.format?t.format:void 0,language:t.language}}function Le(t){return o({...p(t),...f(t),...l(t),items:t.members})}function Re(t){let e=[],n=[],i;for(let a of t.sequences||[])a.canvases.length&&e.push(...a.canvases),a.behavior&&n.push(...a.behavior),a.startCanvas&&(i=a.startCanvas);let r=p(t);return n.length&&(r.behavior?r.behavior.push(...n):r.behavior=n),o({...r,...f(t),...l(t),start:i,items:e,structures:t.structures})}function Ee(t){return o({...p(t),...f(t),...l(t),annotations:t.otherContent&&t.otherContent.length?t.otherContent:void 0,items:t.images&&t.images.length?[{id:J(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function Se(t){return o({...p(t),...f(t),...l(t),items:t.resources&&t.resources.length?t.resources:void 0})}function Me(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[],startCanvas:t.startCanvas}}function Oe(t){function e(n){if(Array.isArray(n)){if(n.length>1)return{type:"List",items:n.map(e)};n=n[0]}if(typeof n=="string")return encodeURI(n).trim();if("@type"in n){let i;if(typeof n.full=="string")i=n.full;else if(n.full["@type"]==="dctypes:Image")i={id:n.full["@id"],type:"Image"};else if(n.full["@type"]==="sc:Canvas")i={id:n.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${n.full["@type"]}`);return{type:"SpecificResource",source:i,selector:m(n.selector)}}else return encodeURI(n["@id"]).trim()}return o({...p(t),...f(t),...l(t),target:e(t.on),body:Array.isArray(t.resource)?t.resource.map(g):g(t.resource)})}function g(t){let e=t;return o({...p(e),...f(e),...l(e),...xe(e)})}function we(t){let e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),{...p(t),...f(t),items:e}}function be(t){return o({...p(t),...f(t),...l(t),items:t.members})}function Fe(t){let{"@id":e,"@type":n,"@context":i,profile:r,...a}=t,s={};return e&&(s["@id"]=e),s["@type"]=A(t),s["@type"]==="unknown"&&(i&&i.length&&(s["@context"]=i),s["@type"]="Service"),r&&(s.profile=H(r)),o({...s,...a})}function Ne(t){return o({...p(t),...f(t),...l(t)})}var ke=new v({collection:[Le],manifest:[Re],canvas:[Ee],annotationList:[Se],sequence:[Me],annotation:[Oe],contentResource:[g],choice:[we],range:[be],service:[Fe],layer:[Ne]});function z(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"?ke.traverseUnknown(t):t}function m(t){if((Array.isArray(t["@type"])&&t["@type"].includes("oa:SvgSelector")||t["@type"]=="oa:SvgSelector")&&("chars"in t||"value"in t))return{type:"SvgSelector",value:"chars"in t?t.chars:t.value};if(t["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:t.value};if(t["@type"]==="oa:Choice")return[m(t.default),...(Array.isArray(t.item)?t.item:[t.item]).map(m)];if(t["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in t?t.region:void 0,rotation:"rotation"in t?t.rotation:void 0};throw new Error(`Unsupported selector type: ${t["@type"]}`)}var De=z;
"use strict";var u=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Z=Object.prototype.hasOwnProperty;var ee=(t,e,i)=>e in t?u(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var te=(t,e)=>{for(var i in e)u(t,i,{get:e[i],enumerable:!0})},ie=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Y(e))!Z.call(t,r)&&r!==i&&u(t,r,{get:()=>e[r],enumerable:!(n=X(e,r))||n.enumerable});return t};var ne=t=>ie(u({},"__esModule",{value:!0}),t);var d=(t,e,i)=>(ee(t,typeof e!="symbol"?e+"":e,i),i);var ot={};te(ot,{upgrade:()=>st});module.exports=ne(ot);var re="http://library.stanford.edu/iiif/image-api/compliance.html#level1",ae="http://library.stanford.edu/iiif/image-api/compliance.html#level2";var se="http://library.stanford.edu/iiif/image-api/conformance.html#level1",oe="http://library.stanford.edu/iiif/image-api/conformance.html#level2";var pe="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",fe="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2";var le="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",ce="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2";var he="http://iiif.io/api/image/1/level1.json",ue="http://iiif.io/api/image/1/profiles/level1.json",ve="http://iiif.io/api/image/1/level2.json",de="http://iiif.io/api/image/1/profiles/level2.json";var ye="http://iiif.io/api/image/2/level1.json",me="http://iiif.io/api/image/2/profiles/level1.json",ge="http://iiif.io/api/image/2/level2.json",Ie="http://iiif.io/api/image/2/profiles/level2.json";var _e="level1",Ae="level2";var Ce="http://iiif.io/api/image/2/level1",Ee="http://iiif.io/api/image/2/level2",_=[Ce,Ee,re,ae,se,oe,pe,fe,le,ce,he,ue,ve,de,ye,me,ge,Ie,_e,Ae];var A=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function xe(t){if(typeof t>"u"||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"){let e=A.indexOf(t["@type"]);if(e!==-1)return A[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}var v=class t{constructor(e,i={}){d(this,"traversals");d(this,"options");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){let 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){let 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){let i=typeof e=="string"?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(i)),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&&(Array.isArray(e.resource)?e.resource=e.resource.map(i=>this.traverseContentResource(i)):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(xe(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"sc: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){let i=Array.isArray(e),n=Array.isArray(e)?e:[e],r=[];for(let a of n)typeof a=="string"?r.push(this.traverseContentResource({"@id":a,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(a));return!i&&!this.options.convertPropsToArray?r[0]:r}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){let i=Array.isArray(e),n=Array.isArray(e)?e:[e],r=[];for(let a of n)r.push(this.traverseService(a));return!i&&!this.options.convertPropsToArray?r[0]:r}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,r)=>{let a=r(n);return typeof a>"u"&&!this.options.allowUndefinedReturn?n:a},e)}};function C(t){return Array.isArray(t)?t:t?[t]:[]}function s(t){for(let e in t)(typeof t[e]>"u"||t[e]===null)&&delete t[e];return t}var Pe="http://library.stanford.edu/iiif/image-api/compliance.html#level0",E="http://library.stanford.edu/iiif/image-api/compliance.html#level1",x="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Le="http://library.stanford.edu/iiif/image-api/conformance.html#level0",P="http://library.stanford.edu/iiif/image-api/conformance.html#level1",L="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Re="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",R="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",M="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Me="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",T="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",Te="http://iiif.io/api/image/1/level0.json",Oe="http://iiif.io/api/image/1/profiles/level0.json",F="http://iiif.io/api/image/1/level1.json",S="http://iiif.io/api/image/1/profiles/level1.json",b="http://iiif.io/api/image/1/level2.json",N="http://iiif.io/api/image/1/profiles/level2.json",Fe="http://iiif.io/api/image/2/level0.json",Se="http://iiif.io/api/image/2/profiles/level0.json",w="http://iiif.io/api/image/2/level1.json",G="http://iiif.io/api/image/2/profiles/level1.json",D="http://iiif.io/api/image/2/level2.json",j="http://iiif.io/api/image/2/profiles/level2.json",be="level0",k="level1",V="level2",Ne="http://iiif.io/api/image/2/level0",B="http://iiif.io/api/image/2/level1",q="http://iiif.io/api/image/2/level2",y=[q,x,L,M,O,b,N,D,j,V],vt=[...y,B,E,P,R,T,F,S,w,G,k],we=[Ne,B,q,Pe,E,x,Le,P,L,Re,R,M,Me,T,O,Te,Oe,F,S,b,N,Fe,Se,w,G,D,j,be,k,V],W=we;var m={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function Ge(t){if(typeof t=="string")return[t];if(!t)return[];let e=Array.isArray(t)?t:[t],i=[];for(let n of e){if(typeof n=="string"){i.push(n);continue}i.push({"@language":n["@language"]||n.language,"@value":n["@value"]||n.value})}return i}function h(t,e="none"){if(!t)return{};let i=Ge(t),n={};for(let r of i){if(typeof r=="string"){n[e]=n[e]?n[e]:[],n[e].push(r||"");continue}if(!r["@language"]){n[e]=n[e]?n[e]:[],n[e].push(r["@value"]||"");continue}let a=r["@language"];n[a]=n[a]?n[a]:[],n[a].push(r["@value"]||"")}return n}function H(t){if(Array.isArray(t))return H(t.find(e=>typeof e=="string"));if(y.indexOf(t)!==-1)return"level2";if(_.indexOf(t)!==-1)return"level1";if(W.indexOf(t)!==-1)return"level0";if(typeof t=="string")return t}function De(t){let e=Array.isArray(t)?t:[t];for(let 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 je(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 U(t){for(let e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}var ke=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function I(t){let e=t["@id"]||t.id,i=t["@type"]||t.type,n=t.profile||void 0,r=t["@context"]||void 0;if(n){let a=je(n);if(a)return a}if(r){let a=De(r);if(a)return a}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(let a of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${a}:`)){i=i.slice(a.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(i&&ke.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"}var Ve=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Be(t){let e=t.match(Ve);return e?e[0]:t}function qe(t,e="Rights/License",i="none"){let n=null,r=[],a=Array.isArray(t)?t:[t];for(let o of a){let l=o?Be(o):void 0;if(l&&(l.indexOf("creativecommons.org")!==-1||l.indexOf("rightsstatements.org")!==-1)){l.startsWith("https://")?n=`http://${l.slice(8)}`:n=l;continue}l&&r.push({label:{[i]:[e]},value:{[i]:[l]}})}return[n,r]}var We=["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){let e=Array.isArray(t)?t:[t],i=[];for(let n of e)n==="http://iiif.io/api/presentation/2/context.json"&&i.push("http://iiif.io/api/presentation/3/context.json"),We.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:h(e.label),value:h(e.value)})):[]}var z=0;function J(t,e){let i=encodeURI(t.id||t["@id"]||"").trim();return i&&e?`${i}/${e}`:i||(z++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${z}`)}function p(t){let e=[...t.behavior||[]];t.viewingHint&&e.push(t.viewingHint);let i;return Array.isArray(t.motivation)?i=t.motivation.map(U):t.motivation&&(i=U(t.motivation)),{"@context":t["@context"]?Ue(t["@context"]):void 0,id:(t["@id"]||J(t)).trim(),type:I(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:i,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function f(t){let[e,i]=qe(t.license),n=[...t.metadata?ze(t.metadata):[],...i];return{rights:e,metadata:n.length?n:void 0,label:t.label?h(t.label):void 0,requiredStatement:t.attribution?{label:h(m.attributionLabel),value:h(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?h(t.description):void 0,thumbnail:$e(t.thumbnail)}}function $e(t){return t&&(Array.isArray(t)?t:[t]).map(i=>typeof i=="string"?{id:i,type:"Image"}:(i.type==="unknown"&&(i.type="Image"),i))}function He(t){if(!t.within)return;let e=Array.isArray(t.within)?t.within:[t.within],i=[];for(let 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:I(n)});return i.length?i:void 0}function c(t){let e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],i=t.contentLayer;return{provider:t.logo||e.length?[{id:m.providerId,type:"Agent",homepage:e.length?[e[0]]:void 0,logo:t.logo?Array.isArray(t.logo)?t.logo:[t.logo]:void 0,label:h(m.providerName)}]:void 0,partOf:He(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?C(t.service):void 0,supplementary:i?[i]:void 0}}function Je(t){return{chars:t.chars,format:t.format?t.format:void 0,language:t.language}}function Qe(t){return s({...p(t),...f(t),...c(t),items:t.members})}function Ke(t){let e=[],i=[],n;for(let a of t.sequences||[])a.canvases.length&&e.push(...a.canvases),a.behavior&&i.push(...a.behavior),a.startCanvas&&(n=a.startCanvas);let r=p(t);return i.length&&(r.behavior?r.behavior.push(...i):r.behavior=i),s({...r,...f(t),...c(t),start:n,items:e,structures:t.structures})}function Xe(t){return s({...p(t),...f(t),...c(t),annotations:t.otherContent&&t.otherContent.length?t.otherContent:void 0,items:t.images&&t.images.length?[{id:J(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function Ye(t){return s({...p(t),...f(t),...c(t),items:t.resources&&t.resources.length?t.resources:void 0})}function Ze(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[],startCanvas:t.startCanvas}}function et(t){function e(i){if(Array.isArray(i)){if(i.length>1)return{type:"List",items:i.map(e)};i=i[0]}if(typeof i=="string")return encodeURI(i).trim();if("@type"in i){let n;if(typeof i.full=="string")n=i.full;else if(i.full["@type"]==="dctypes:Image")n={id:i.full["@id"],type:"Image"};else if(i.full["@type"]==="sc:Canvas")n={id:i.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${i.full["@type"]}`);return{type:"SpecificResource",source:n,selector:g(i.selector)}}else return encodeURI(i["@id"]).trim()}return s({...p(t),...f(t),...c(t),target:e(t.on),body:Array.isArray(t.resource)?t.resource.map($):$(t.resource)})}function $(t){return t.type==="Choice"?t:Q(t)}function Q(t){let e=t;return s({...p(e),...f(e),...c(e),...Je(e)})}function tt(t){let e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),s({...p(t),...f(t),items:e})}function it(t){return s({...p(t),...f(t),...c(t),items:t.members})}function nt(t){let{"@id":e,"@type":i,"@context":n,profile:r,...a}=t,o={};return e&&(o["@id"]=e),o["@type"]=I(t),o["@type"]==="unknown"&&(n&&n.length&&(o["@context"]=n),o["@type"]="Service"),r&&(o.profile=H(r)),s({...o,...a})}function rt(t){return s({...p(t),...f(t),...c(t)})}var at=new v({collection:[Qe],manifest:[Ke],canvas:[Xe],annotationList:[Ye],sequence:[Ze],annotation:[et],contentResource:[Q],choice:[tt],range:[it],service:[nt],layer:[rt]});function K(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"?at.traverseUnknown(t):t}function g(t){if((Array.isArray(t["@type"])&&t["@type"].includes("oa:SvgSelector")||t["@type"]=="oa:SvgSelector")&&("chars"in t||"value"in t))return{type:"SvgSelector",value:"chars"in t?t.chars:t.value};if(t["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:t.value};if(t["@type"]==="oa:Choice")return[g(t.default),...(Array.isArray(t.item)?t.item:[t.item]).map(g)];if(t["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in t?t.region:void 0,rotation:"rotation"in t?t.rotation:void 0};throw new Error(`Unsupported selector type: ${t["@type"]}`)}var st=K;

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

"use strict";var IIIFParser=(()=>{var h=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var X=Object.prototype.hasOwnProperty;var Y=(t,e,n)=>e in t?h(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var Z=(t,e)=>{for(var n in e)h(t,n,{get:e[n],enumerable:!0})},ee=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Q(e))!X.call(t,r)&&r!==n&&h(t,r,{get:()=>e[r],enumerable:!(i=K(e,r))||i.enumerable});return t};var te=t=>ee(h({},"__esModule",{value:!0}),t);var d=(t,e,n)=>(Y(t,typeof e!="symbol"?e+"":e,n),n);var Ge={};Z(Ge,{upgrade:()=>De});var ne="http://library.stanford.edu/iiif/image-api/compliance.html#level0",I="http://library.stanford.edu/iiif/image-api/compliance.html#level1",C="http://library.stanford.edu/iiif/image-api/compliance.html#level2",ie="http://library.stanford.edu/iiif/image-api/conformance.html#level0",P="http://library.stanford.edu/iiif/image-api/conformance.html#level1",_="http://library.stanford.edu/iiif/image-api/conformance.html#level2",re="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",T="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",x="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",ae="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",L="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",R="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",se="http://iiif.io/api/image/1/level0.json",oe="http://iiif.io/api/image/1/profiles/level0.json",E="http://iiif.io/api/image/1/level1.json",S="http://iiif.io/api/image/1/profiles/level1.json",M="http://iiif.io/api/image/1/level2.json",O="http://iiif.io/api/image/1/profiles/level2.json",pe="http://iiif.io/api/image/2/level0.json",fe="http://iiif.io/api/image/2/profiles/level0.json",w="http://iiif.io/api/image/2/level1.json",b="http://iiif.io/api/image/2/profiles/level1.json",F="http://iiif.io/api/image/2/level2.json",N="http://iiif.io/api/image/2/profiles/level2.json",ce="level0",k="level1",D="level2",le="http://iiif.io/api/image/2/level0",G="http://iiif.io/api/image/2/level1",j="http://iiif.io/api/image/2/level2",q=[G,j,I,C,P,_,T,x,L,R,E,S,M,O,w,b,F,N,k,D],V=[le,G,j,ne,I,C,ie,P,_,re,T,x,ae,L,R,se,oe,E,S,M,O,pe,fe,w,b,F,N,ce,k,D];var U=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function ue(t){if(typeof t>"u"||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"){let e=U.indexOf(t["@type"]);if(e!==-1)return U[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}var v=class t{constructor(e,n={}){d(this,"traversals");d(this,"options");this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...n}}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){let n=[...(e.manifests||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i),...(e.collections||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i),...e.members||[]];delete e.collections,delete e.manifests,e.members=n}return e.manifests&&(e.manifests=e.manifests.map(n=>this.traverseManifest(typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n))),e.collections&&(e.collections=e.collections.map(n=>this.traverseCollection(typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n))),e.members&&(e.members=e.members.map(n=>typeof n=="string"?n:this.traverseUnknown(n))),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(n=>this.traverseSequence(n))),e.structures&&(e.structures=e.structures.map(n=>this.traverseRange(n))),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(n=>this.traverseCanvas(n))),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(n=>this.traverseAnnotation(n))),e.otherContent&&(e.otherContent=e.otherContent.map(n=>this.traverseAnnotationList(n))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){let n=[...(e.ranges||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Range"}:i),...(e.canvases||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Canvas"}:i),...e.members||[]];delete e.ranges,delete e.canvases,e.members=n.length?n.map(i=>this.traverseUnknown(i)):void 0}return e}traverseAnnotationList(e){let n=typeof e=="string"?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(n)),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map(n=>this.traverseAnnotation(n))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(Array.isArray(e.resource)?e.resource=e.resource.map(n=>this.traverseContentResource(n)):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(n=>this.traverseAnnotationList(n))),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(n=>this.traverseContentResource(n))),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(ue(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"sc: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){let n=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(let a of i)typeof a=="string"?r.push(this.traverseContentResource({"@id":a,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(a));return!n&&!this.options.convertPropsToArray?r[0]:r}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){let n=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(let a of i)r.push(this.traverseService(a));return!n&&!this.options.convertPropsToArray?r[0]:r}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,n){if(!Array.isArray(e))if(this.options.convertPropsToArray)e=[e];else return this.traverseType(e,n);return e.map(i=>this.traverseType(i,n))}traverseType(e,n){return n.reduce((i,r)=>{let a=r(i);return typeof a>"u"&&!this.options.allowUndefinedReturn?i:a},e)}};function $(t){return Array.isArray(t)?t:t?[t]:[]}function o(t){for(let e in t)(typeof t[e]>"u"||t[e]===null)&&delete t[e];return t}var y={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function he(t){if(typeof t=="string")return[t];if(!t)return[];let e=Array.isArray(t)?t:[t],n=[];for(let i of e){if(typeof i=="string"){n.push(i);continue}n.push({"@language":i["@language"]||i.language,"@value":i["@value"]||i.value})}return n}function u(t,e="none"){if(!t)return{};let n=he(t),i={};for(let r of n){if(typeof r=="string"){i[e]=i[e]?i[e]:[],i[e].push(r||"");continue}if(!r["@language"]){i[e]=i[e]?i[e]:[],i[e].push(r["@value"]||"");continue}let a=r["@language"];i[a]=i[a]?i[a]:[],i[a].push(r["@value"]||"")}return i}function H(t){if(Array.isArray(t))return H(t.find(e=>typeof e=="string"));if(V.indexOf(t)!==-1)return"level2";if(q.indexOf(t)!==-1)return"level1";if(typeof t=="string")return t}function ve(t){let e=Array.isArray(t)?t:[t];for(let n of e)switch(n){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 W(t){for(let e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}var ye=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function A(t){let e=t["@id"]||t.id,n=t["@type"]||t.type,i=t.profile||void 0,r=t["@context"]||void 0;if(i){let a=de(i);if(a)return a}if(r){let a=ve(r);if(a)return a}if(n){if(Array.isArray(n)){if(n.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(n.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";n=n[0]}for(let a of["sc","oa","dcterms","dctypes","iiif"])if(n.startsWith(`${a}:`)){n=n.slice(a.length+1);break}switch(n){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(n&&ye.indexOf(n)!==-1)return n;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":n||"unknown"}var ge=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function me(t){let e=t.match(ge);return e?e[0]:t}function Ae(t,e="Rights/License",n="none"){let i=null,r=[],a=Array.isArray(t)?t:[t];for(let s of a){let c=s?me(s):void 0;if(c&&(c.indexOf("creativecommons.org")!==-1||c.indexOf("rightsstatements.org")!==-1)){c.startsWith("https://")?i=`http://${c.slice(8)}`:i=c;continue}c&&r.push({label:{[n]:[e]},value:{[n]:[c]}})}return[i,r]}var Ie=["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 Ce(t){if(t){let e=Array.isArray(t)?t:[t],n=[];for(let i of e)i==="http://iiif.io/api/presentation/2/context.json"&&n.push("http://iiif.io/api/presentation/3/context.json"),Ie.indexOf(i)===-1&&n.push(i);if(e.length)return n.length===1?n[0]:n}}function Pe(t){return t?t.map(e=>({label:u(e.label),value:u(e.value)})):[]}var B=0;function J(t,e){let n=encodeURI(t.id||t["@id"]||"").trim();return n&&e?`${n}/${e}`:n||(B++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${B}`)}function p(t){let e=[...t.behavior||[]];t.viewingHint&&e.push(t.viewingHint);let n;return Array.isArray(t.motivation)?n=t.motivation.map(W):t.motivation&&(n=W(t.motivation)),{"@context":t["@context"]?Ce(t["@context"]):void 0,id:(t["@id"]||J(t)).trim(),type:A(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:n,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function f(t){let[e,n]=Ae(t.license),i=[...t.metadata?Pe(t.metadata):[],...n];return{rights:e,metadata:i.length?i:void 0,label:t.label?u(t.label):void 0,requiredStatement:t.attribution?{label:u(y.attributionLabel),value:u(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?u(t.description):void 0,thumbnail:_e(t.thumbnail)}}function _e(t){return t&&(Array.isArray(t)?t:[t]).map(n=>typeof n=="string"?{id:n,type:"Image"}:(n.type==="unknown"&&(n.type="Image"),n))}function Te(t){if(!t.within)return;let e=Array.isArray(t.within)?t.within:[t.within],n=[];for(let i of e)if(typeof i=="string"){if(i)switch(t["@type"]){case"sc:Manifest":n.push({id:i,type:"Collection"});break}}else i["@id"]&&n.push({id:i["@id"],type:A(i)});return n.length?n:void 0}function l(t){let e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],n=t.contentLayer;return{provider:t.logo||e.length?[{id:y.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(y.providerName)}]:void 0,partOf:Te(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?$(t.service):void 0,supplementary:n?[n]:void 0}}function xe(t){return{chars:t.chars,format:t.format?t.format:void 0,language:t.language}}function Le(t){return o({...p(t),...f(t),...l(t),items:t.members})}function Re(t){let e=[],n=[],i;for(let a of t.sequences||[])a.canvases.length&&e.push(...a.canvases),a.behavior&&n.push(...a.behavior),a.startCanvas&&(i=a.startCanvas);let r=p(t);return n.length&&(r.behavior?r.behavior.push(...n):r.behavior=n),o({...r,...f(t),...l(t),start:i,items:e,structures:t.structures})}function Ee(t){return o({...p(t),...f(t),...l(t),annotations:t.otherContent&&t.otherContent.length?t.otherContent:void 0,items:t.images&&t.images.length?[{id:J(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function Se(t){return o({...p(t),...f(t),...l(t),items:t.resources&&t.resources.length?t.resources:void 0})}function Me(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[],startCanvas:t.startCanvas}}function Oe(t){function e(n){if(Array.isArray(n)){if(n.length>1)return{type:"List",items:n.map(e)};n=n[0]}if(typeof n=="string")return encodeURI(n).trim();if("@type"in n){let i;if(typeof n.full=="string")i=n.full;else if(n.full["@type"]==="dctypes:Image")i={id:n.full["@id"],type:"Image"};else if(n.full["@type"]==="sc:Canvas")i={id:n.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${n.full["@type"]}`);return{type:"SpecificResource",source:i,selector:m(n.selector)}}else return encodeURI(n["@id"]).trim()}return o({...p(t),...f(t),...l(t),target:e(t.on),body:Array.isArray(t.resource)?t.resource.map(g):g(t.resource)})}function g(t){let e=t;return o({...p(e),...f(e),...l(e),...xe(e)})}function we(t){let e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),{...p(t),...f(t),items:e}}function be(t){return o({...p(t),...f(t),...l(t),items:t.members})}function Fe(t){let{"@id":e,"@type":n,"@context":i,profile:r,...a}=t,s={};return e&&(s["@id"]=e),s["@type"]=A(t),s["@type"]==="unknown"&&(i&&i.length&&(s["@context"]=i),s["@type"]="Service"),r&&(s.profile=H(r)),o({...s,...a})}function Ne(t){return o({...p(t),...f(t),...l(t)})}var ke=new v({collection:[Le],manifest:[Re],canvas:[Ee],annotationList:[Se],sequence:[Me],annotation:[Oe],contentResource:[g],choice:[we],range:[be],service:[Fe],layer:[Ne]});function z(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"?ke.traverseUnknown(t):t}function m(t){if((Array.isArray(t["@type"])&&t["@type"].includes("oa:SvgSelector")||t["@type"]=="oa:SvgSelector")&&("chars"in t||"value"in t))return{type:"SvgSelector",value:"chars"in t?t.chars:t.value};if(t["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:t.value};if(t["@type"]==="oa:Choice")return[m(t.default),...(Array.isArray(t.item)?t.item:[t.item]).map(m)];if(t["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in t?t.region:void 0,rotation:"rotation"in t?t.rotation:void 0};throw new Error(`Unsupported selector type: ${t["@type"]}`)}var De=z;return te(Ge);})();
"use strict";var IIIFParser=(()=>{var u=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Z=Object.prototype.hasOwnProperty;var ee=(t,e,i)=>e in t?u(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var te=(t,e)=>{for(var i in e)u(t,i,{get:e[i],enumerable:!0})},ie=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Y(e))!Z.call(t,r)&&r!==i&&u(t,r,{get:()=>e[r],enumerable:!(n=X(e,r))||n.enumerable});return t};var ne=t=>ie(u({},"__esModule",{value:!0}),t);var d=(t,e,i)=>(ee(t,typeof e!="symbol"?e+"":e,i),i);var ot={};te(ot,{upgrade:()=>st});var re="http://library.stanford.edu/iiif/image-api/compliance.html#level1",ae="http://library.stanford.edu/iiif/image-api/compliance.html#level2";var se="http://library.stanford.edu/iiif/image-api/conformance.html#level1",oe="http://library.stanford.edu/iiif/image-api/conformance.html#level2";var pe="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",fe="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2";var le="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",ce="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2";var he="http://iiif.io/api/image/1/level1.json",ue="http://iiif.io/api/image/1/profiles/level1.json",ve="http://iiif.io/api/image/1/level2.json",de="http://iiif.io/api/image/1/profiles/level2.json";var ye="http://iiif.io/api/image/2/level1.json",me="http://iiif.io/api/image/2/profiles/level1.json",ge="http://iiif.io/api/image/2/level2.json",Ie="http://iiif.io/api/image/2/profiles/level2.json";var _e="level1",Ae="level2";var Ce="http://iiif.io/api/image/2/level1",Ee="http://iiif.io/api/image/2/level2",_=[Ce,Ee,re,ae,se,oe,pe,fe,le,ce,he,ue,ve,de,ye,me,ge,Ie,_e,Ae];var A=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function xe(t){if(typeof t>"u"||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"){let e=A.indexOf(t["@type"]);if(e!==-1)return A[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}var v=class t{constructor(e,i={}){d(this,"traversals");d(this,"options");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){let 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){let 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){let i=typeof e=="string"?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(i)),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&&(Array.isArray(e.resource)?e.resource=e.resource.map(i=>this.traverseContentResource(i)):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(xe(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"sc: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){let i=Array.isArray(e),n=Array.isArray(e)?e:[e],r=[];for(let a of n)typeof a=="string"?r.push(this.traverseContentResource({"@id":a,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(a));return!i&&!this.options.convertPropsToArray?r[0]:r}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){let i=Array.isArray(e),n=Array.isArray(e)?e:[e],r=[];for(let a of n)r.push(this.traverseService(a));return!i&&!this.options.convertPropsToArray?r[0]:r}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,r)=>{let a=r(n);return typeof a>"u"&&!this.options.allowUndefinedReturn?n:a},e)}};function C(t){return Array.isArray(t)?t:t?[t]:[]}function s(t){for(let e in t)(typeof t[e]>"u"||t[e]===null)&&delete t[e];return t}var Pe="http://library.stanford.edu/iiif/image-api/compliance.html#level0",E="http://library.stanford.edu/iiif/image-api/compliance.html#level1",x="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Le="http://library.stanford.edu/iiif/image-api/conformance.html#level0",P="http://library.stanford.edu/iiif/image-api/conformance.html#level1",L="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Re="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",R="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",M="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Me="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",T="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",Te="http://iiif.io/api/image/1/level0.json",Oe="http://iiif.io/api/image/1/profiles/level0.json",F="http://iiif.io/api/image/1/level1.json",S="http://iiif.io/api/image/1/profiles/level1.json",b="http://iiif.io/api/image/1/level2.json",N="http://iiif.io/api/image/1/profiles/level2.json",Fe="http://iiif.io/api/image/2/level0.json",Se="http://iiif.io/api/image/2/profiles/level0.json",w="http://iiif.io/api/image/2/level1.json",G="http://iiif.io/api/image/2/profiles/level1.json",D="http://iiif.io/api/image/2/level2.json",j="http://iiif.io/api/image/2/profiles/level2.json",be="level0",k="level1",V="level2",Ne="http://iiif.io/api/image/2/level0",B="http://iiif.io/api/image/2/level1",q="http://iiif.io/api/image/2/level2",y=[q,x,L,M,O,b,N,D,j,V],vt=[...y,B,E,P,R,T,F,S,w,G,k],we=[Ne,B,q,Pe,E,x,Le,P,L,Re,R,M,Me,T,O,Te,Oe,F,S,b,N,Fe,Se,w,G,D,j,be,k,V],W=we;var m={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function Ge(t){if(typeof t=="string")return[t];if(!t)return[];let e=Array.isArray(t)?t:[t],i=[];for(let n of e){if(typeof n=="string"){i.push(n);continue}i.push({"@language":n["@language"]||n.language,"@value":n["@value"]||n.value})}return i}function h(t,e="none"){if(!t)return{};let i=Ge(t),n={};for(let r of i){if(typeof r=="string"){n[e]=n[e]?n[e]:[],n[e].push(r||"");continue}if(!r["@language"]){n[e]=n[e]?n[e]:[],n[e].push(r["@value"]||"");continue}let a=r["@language"];n[a]=n[a]?n[a]:[],n[a].push(r["@value"]||"")}return n}function H(t){if(Array.isArray(t))return H(t.find(e=>typeof e=="string"));if(y.indexOf(t)!==-1)return"level2";if(_.indexOf(t)!==-1)return"level1";if(W.indexOf(t)!==-1)return"level0";if(typeof t=="string")return t}function De(t){let e=Array.isArray(t)?t:[t];for(let 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 je(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 U(t){for(let e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}var ke=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function I(t){let e=t["@id"]||t.id,i=t["@type"]||t.type,n=t.profile||void 0,r=t["@context"]||void 0;if(n){let a=je(n);if(a)return a}if(r){let a=De(r);if(a)return a}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(let a of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${a}:`)){i=i.slice(a.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(i&&ke.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"}var Ve=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Be(t){let e=t.match(Ve);return e?e[0]:t}function qe(t,e="Rights/License",i="none"){let n=null,r=[],a=Array.isArray(t)?t:[t];for(let o of a){let l=o?Be(o):void 0;if(l&&(l.indexOf("creativecommons.org")!==-1||l.indexOf("rightsstatements.org")!==-1)){l.startsWith("https://")?n=`http://${l.slice(8)}`:n=l;continue}l&&r.push({label:{[i]:[e]},value:{[i]:[l]}})}return[n,r]}var We=["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){let e=Array.isArray(t)?t:[t],i=[];for(let n of e)n==="http://iiif.io/api/presentation/2/context.json"&&i.push("http://iiif.io/api/presentation/3/context.json"),We.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:h(e.label),value:h(e.value)})):[]}var z=0;function J(t,e){let i=encodeURI(t.id||t["@id"]||"").trim();return i&&e?`${i}/${e}`:i||(z++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${z}`)}function p(t){let e=[...t.behavior||[]];t.viewingHint&&e.push(t.viewingHint);let i;return Array.isArray(t.motivation)?i=t.motivation.map(U):t.motivation&&(i=U(t.motivation)),{"@context":t["@context"]?Ue(t["@context"]):void 0,id:(t["@id"]||J(t)).trim(),type:I(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:i,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function f(t){let[e,i]=qe(t.license),n=[...t.metadata?ze(t.metadata):[],...i];return{rights:e,metadata:n.length?n:void 0,label:t.label?h(t.label):void 0,requiredStatement:t.attribution?{label:h(m.attributionLabel),value:h(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?h(t.description):void 0,thumbnail:$e(t.thumbnail)}}function $e(t){return t&&(Array.isArray(t)?t:[t]).map(i=>typeof i=="string"?{id:i,type:"Image"}:(i.type==="unknown"&&(i.type="Image"),i))}function He(t){if(!t.within)return;let e=Array.isArray(t.within)?t.within:[t.within],i=[];for(let 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:I(n)});return i.length?i:void 0}function c(t){let e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],i=t.contentLayer;return{provider:t.logo||e.length?[{id:m.providerId,type:"Agent",homepage:e.length?[e[0]]:void 0,logo:t.logo?Array.isArray(t.logo)?t.logo:[t.logo]:void 0,label:h(m.providerName)}]:void 0,partOf:He(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?C(t.service):void 0,supplementary:i?[i]:void 0}}function Je(t){return{chars:t.chars,format:t.format?t.format:void 0,language:t.language}}function Qe(t){return s({...p(t),...f(t),...c(t),items:t.members})}function Ke(t){let e=[],i=[],n;for(let a of t.sequences||[])a.canvases.length&&e.push(...a.canvases),a.behavior&&i.push(...a.behavior),a.startCanvas&&(n=a.startCanvas);let r=p(t);return i.length&&(r.behavior?r.behavior.push(...i):r.behavior=i),s({...r,...f(t),...c(t),start:n,items:e,structures:t.structures})}function Xe(t){return s({...p(t),...f(t),...c(t),annotations:t.otherContent&&t.otherContent.length?t.otherContent:void 0,items:t.images&&t.images.length?[{id:J(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function Ye(t){return s({...p(t),...f(t),...c(t),items:t.resources&&t.resources.length?t.resources:void 0})}function Ze(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[],startCanvas:t.startCanvas}}function et(t){function e(i){if(Array.isArray(i)){if(i.length>1)return{type:"List",items:i.map(e)};i=i[0]}if(typeof i=="string")return encodeURI(i).trim();if("@type"in i){let n;if(typeof i.full=="string")n=i.full;else if(i.full["@type"]==="dctypes:Image")n={id:i.full["@id"],type:"Image"};else if(i.full["@type"]==="sc:Canvas")n={id:i.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${i.full["@type"]}`);return{type:"SpecificResource",source:n,selector:g(i.selector)}}else return encodeURI(i["@id"]).trim()}return s({...p(t),...f(t),...c(t),target:e(t.on),body:Array.isArray(t.resource)?t.resource.map($):$(t.resource)})}function $(t){return t.type==="Choice"?t:Q(t)}function Q(t){let e=t;return s({...p(e),...f(e),...c(e),...Je(e)})}function tt(t){let e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),s({...p(t),...f(t),items:e})}function it(t){return s({...p(t),...f(t),...c(t),items:t.members})}function nt(t){let{"@id":e,"@type":i,"@context":n,profile:r,...a}=t,o={};return e&&(o["@id"]=e),o["@type"]=I(t),o["@type"]==="unknown"&&(n&&n.length&&(o["@context"]=n),o["@type"]="Service"),r&&(o.profile=H(r)),s({...o,...a})}function rt(t){return s({...p(t),...f(t),...c(t)})}var at=new v({collection:[Qe],manifest:[Ke],canvas:[Xe],annotationList:[Ye],sequence:[Ze],annotation:[et],contentResource:[Q],choice:[tt],range:[it],service:[nt],layer:[rt]});function K(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"?at.traverseUnknown(t):t}function g(t){if((Array.isArray(t["@type"])&&t["@type"].includes("oa:SvgSelector")||t["@type"]=="oa:SvgSelector")&&("chars"in t||"value"in t))return{type:"SvgSelector",value:"chars"in t?t.chars:t.value};if(t["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:t.value};if(t["@type"]==="oa:Choice")return[g(t.default),...(Array.isArray(t.item)?t.item:[t.item]).map(g)];if(t["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in t?t.region:void 0,rotation:"rotation"in t?t.rotation:void 0};throw new Error(`Unsupported selector type: ${t["@type"]}`)}var st=K;return ne(ot);})();

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

import{h as o}from"./chunk-7IIDO3IU.js";import"./chunk-NJNTZ6QT.js";import"./chunk-D22QKJZO.js";var t=o;export{t as upgrade};
import{h as o}from"./chunk-3WVPINNO.js";import"./chunk-J657UVVW.js";import"./chunk-NJNTZ6QT.js";import"./chunk-D22QKJZO.js";var t=o;export{t as upgrade};
{
"name": "@iiif/parser",
"version": "2.1.0",
"version": "2.1.1",
"license": "MIT",

@@ -5,0 +5,0 @@ "type": "module",

import{a as A,b as o}from"./chunk-NJNTZ6QT.js";import{a as v}from"./chunk-D22QKJZO.js";var I=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function J(t){if(typeof t>"u"||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"){let e=I.indexOf(t["@type"]);if(e!==-1)return I[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}var u=class t{constructor(e,n={}){v(this,"traversals");v(this,"options");this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...n}}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){let n=[...(e.manifests||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i),...(e.collections||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i),...e.members||[]];delete e.collections,delete e.manifests,e.members=n}return e.manifests&&(e.manifests=e.manifests.map(n=>this.traverseManifest(typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n))),e.collections&&(e.collections=e.collections.map(n=>this.traverseCollection(typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n))),e.members&&(e.members=e.members.map(n=>typeof n=="string"?n:this.traverseUnknown(n))),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(n=>this.traverseSequence(n))),e.structures&&(e.structures=e.structures.map(n=>this.traverseRange(n))),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(n=>this.traverseCanvas(n))),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(n=>this.traverseAnnotation(n))),e.otherContent&&(e.otherContent=e.otherContent.map(n=>this.traverseAnnotationList(n))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){let n=[...(e.ranges||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Range"}:i),...(e.canvases||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Canvas"}:i),...e.members||[]];delete e.ranges,delete e.canvases,e.members=n.length?n.map(i=>this.traverseUnknown(i)):void 0}return e}traverseAnnotationList(e){let n=typeof e=="string"?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(n)),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map(n=>this.traverseAnnotation(n))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(Array.isArray(e.resource)?e.resource=e.resource.map(n=>this.traverseContentResource(n)):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(n=>this.traverseAnnotationList(n))),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(n=>this.traverseContentResource(n))),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(J(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"sc: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){let n=Array.isArray(e),i=Array.isArray(e)?e:[e],a=[];for(let r of i)typeof r=="string"?a.push(this.traverseContentResource({"@id":r,"@type":"dctypes:Image"})):a.push(this.traverseContentResource(r));return!n&&!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){let n=Array.isArray(e),i=Array.isArray(e)?e:[e],a=[];for(let r of i)a.push(this.traverseService(r));return!n&&!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,n){if(!Array.isArray(e))if(this.options.convertPropsToArray)e=[e];else return this.traverseType(e,n);return e.map(i=>this.traverseType(i,n))}traverseType(e,n){return n.reduce((i,a)=>{let r=a(i);return typeof r>"u"&&!this.options.allowUndefinedReturn?i:r},e)}};var z="http://library.stanford.edu/iiif/image-api/compliance.html#level0",C="http://library.stanford.edu/iiif/image-api/compliance.html#level1",P="http://library.stanford.edu/iiif/image-api/compliance.html#level2",K="http://library.stanford.edu/iiif/image-api/conformance.html#level0",_="http://library.stanford.edu/iiif/image-api/conformance.html#level1",T="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Q="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",L="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",R="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",X="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",E="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Y="http://iiif.io/api/image/1/level0.json",Z="http://iiif.io/api/image/1/profiles/level0.json",S="http://iiif.io/api/image/1/level1.json",M="http://iiif.io/api/image/1/profiles/level1.json",O="http://iiif.io/api/image/1/level2.json",b="http://iiif.io/api/image/1/profiles/level2.json",ee="http://iiif.io/api/image/2/level0.json",te="http://iiif.io/api/image/2/profiles/level0.json",w="http://iiif.io/api/image/2/level1.json",F="http://iiif.io/api/image/2/profiles/level1.json",N="http://iiif.io/api/image/2/level2.json",k="http://iiif.io/api/image/2/profiles/level2.json",ne="level0",D="level1",j="level2",ie="http://iiif.io/api/image/2/level0",G="http://iiif.io/api/image/2/level1",q="http://iiif.io/api/image/2/level2",V=[G,q,C,P,_,T,L,R,x,E,S,M,O,b,w,F,N,k,D,j],U=[ie,G,q,z,C,P,K,_,T,Q,L,R,X,x,E,Y,Z,S,M,O,b,ee,te,w,F,N,k,ne,D,j];var y={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function re(t){if(typeof t=="string")return[t];if(!t)return[];let e=Array.isArray(t)?t:[t],n=[];for(let i of e){if(typeof i=="string"){n.push(i);continue}n.push({"@language":i["@language"]||i.language,"@value":i["@value"]||i.value})}return n}function h(t,e="none"){if(!t)return{};let n=re(t),i={};for(let a of n){if(typeof a=="string"){i[e]=i[e]?i[e]:[],i[e].push(a||"");continue}if(!a["@language"]){i[e]=i[e]?i[e]:[],i[e].push(a["@value"]||"");continue}let r=a["@language"];i[r]=i[r]?i[r]:[],i[r].push(a["@value"]||"")}return i}function B(t){if(Array.isArray(t))return B(t.find(e=>typeof e=="string"));if(U.indexOf(t)!==-1)return"level2";if(V.indexOf(t)!==-1)return"level1";if(typeof t=="string")return t}function ae(t){let e=Array.isArray(t)?t:[t];for(let n of e)switch(n){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 se(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 $(t){for(let e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}var oe=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function m(t){let e=t["@id"]||t.id,n=t["@type"]||t.type,i=t.profile||void 0,a=t["@context"]||void 0;if(i){let r=se(i);if(r)return r}if(a){let r=ae(a);if(r)return r}if(n){if(Array.isArray(n)){if(n.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(n.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";n=n[0]}for(let r of["sc","oa","dcterms","dctypes","iiif"])if(n.startsWith(`${r}:`)){n=n.slice(r.length+1);break}switch(n){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(n&&oe.indexOf(n)!==-1)return n;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":n||"unknown"}var pe=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function fe(t){let e=t.match(pe);return e?e[0]:t}function ce(t,e="Rights/License",n="none"){let i=null,a=[],r=Array.isArray(t)?t:[t];for(let s of r){let c=s?fe(s):void 0;if(c&&(c.indexOf("creativecommons.org")!==-1||c.indexOf("rightsstatements.org")!==-1)){c.startsWith("https://")?i=`http://${c.slice(8)}`:i=c;continue}c&&a.push({label:{[n]:[e]},value:{[n]:[c]}})}return[i,a]}var le=["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 he(t){if(t){let e=Array.isArray(t)?t:[t],n=[];for(let i of e)i==="http://iiif.io/api/presentation/2/context.json"&&n.push("http://iiif.io/api/presentation/3/context.json"),le.indexOf(i)===-1&&n.push(i);if(e.length)return n.length===1?n[0]:n}}function ue(t){return t?t.map(e=>({label:h(e.label),value:h(e.value)})):[]}var W=0;function H(t,e){let n=encodeURI(t.id||t["@id"]||"").trim();return n&&e?`${n}/${e}`:n||(W++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${W}`)}function p(t){let e=[...t.behavior||[]];t.viewingHint&&e.push(t.viewingHint);let n;return Array.isArray(t.motivation)?n=t.motivation.map($):t.motivation&&(n=$(t.motivation)),{"@context":t["@context"]?he(t["@context"]):void 0,id:(t["@id"]||H(t)).trim(),type:m(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:n,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function f(t){let[e,n]=ce(t.license),i=[...t.metadata?ue(t.metadata):[],...n];return{rights:e,metadata:i.length?i:void 0,label:t.label?h(t.label):void 0,requiredStatement:t.attribution?{label:h(y.attributionLabel),value:h(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?h(t.description):void 0,thumbnail:ve(t.thumbnail)}}function ve(t){return t&&(Array.isArray(t)?t:[t]).map(n=>typeof n=="string"?{id:n,type:"Image"}:(n.type==="unknown"&&(n.type="Image"),n))}function ye(t){if(!t.within)return;let e=Array.isArray(t.within)?t.within:[t.within],n=[];for(let i of e)if(typeof i=="string"){if(i)switch(t["@type"]){case"sc:Manifest":n.push({id:i,type:"Collection"});break}}else i["@id"]&&n.push({id:i["@id"],type:m(i)});return n.length?n:void 0}function l(t){let e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],n=t.contentLayer;return{provider:t.logo||e.length?[{id:y.providerId,type:"Agent",homepage:e.length?[e[0]]:void 0,logo:t.logo?Array.isArray(t.logo)?t.logo:[t.logo]:void 0,label:h(y.providerName)}]:void 0,partOf:ye(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?A(t.service):void 0,supplementary:n?[n]:void 0}}function de(t){return{chars:t.chars,format:t.format?t.format:void 0,language:t.language}}function ge(t){return o({...p(t),...f(t),...l(t),items:t.members})}function me(t){let e=[],n=[],i;for(let r of t.sequences||[])r.canvases.length&&e.push(...r.canvases),r.behavior&&n.push(...r.behavior),r.startCanvas&&(i=r.startCanvas);let a=p(t);return n.length&&(a.behavior?a.behavior.push(...n):a.behavior=n),o({...a,...f(t),...l(t),start:i,items:e,structures:t.structures})}function Ae(t){return o({...p(t),...f(t),...l(t),annotations:t.otherContent&&t.otherContent.length?t.otherContent:void 0,items:t.images&&t.images.length?[{id:H(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function Ie(t){return o({...p(t),...f(t),...l(t),items:t.resources&&t.resources.length?t.resources:void 0})}function Ce(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[],startCanvas:t.startCanvas}}function Pe(t){function e(n){if(Array.isArray(n)){if(n.length>1)return{type:"List",items:n.map(e)};n=n[0]}if(typeof n=="string")return encodeURI(n).trim();if("@type"in n){let i;if(typeof n.full=="string")i=n.full;else if(n.full["@type"]==="dctypes:Image")i={id:n.full["@id"],type:"Image"};else if(n.full["@type"]==="sc:Canvas")i={id:n.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${n.full["@type"]}`);return{type:"SpecificResource",source:i,selector:g(n.selector)}}else return encodeURI(n["@id"]).trim()}return o({...p(t),...f(t),...l(t),target:e(t.on),body:Array.isArray(t.resource)?t.resource.map(d):d(t.resource)})}function d(t){let e=t;return o({...p(e),...f(e),...l(e),...de(e)})}function _e(t){let e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),{...p(t),...f(t),items:e}}function Te(t){return o({...p(t),...f(t),...l(t),items:t.members})}function Le(t){let{"@id":e,"@type":n,"@context":i,profile:a,...r}=t,s={};return e&&(s["@id"]=e),s["@type"]=m(t),s["@type"]==="unknown"&&(i&&i.length&&(s["@context"]=i),s["@type"]="Service"),a&&(s.profile=B(a)),o({...s,...r})}function Re(t){return o({...p(t),...f(t),...l(t)})}var xe=new u({collection:[ge],manifest:[me],canvas:[Ae],annotationList:[Ie],sequence:[Ce],annotation:[Pe],contentResource:[d],choice:[_e],range:[Te],service:[Le],layer:[Re]});function Ne(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"?xe.traverseUnknown(t):t}function g(t){if((Array.isArray(t["@type"])&&t["@type"].includes("oa:SvgSelector")||t["@type"]=="oa:SvgSelector")&&("chars"in t||"value"in t))return{type:"SvgSelector",value:"chars"in t?t.chars:t.value};if(t["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:t.value};if(t["@type"]==="oa:Choice")return[g(t.default),...(Array.isArray(t.item)?t.item:[t.item]).map(g)];if(t["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in t?t.region:void 0,rotation:"rotation"in t?t.rotation:void 0};throw new Error(`Unsupported selector type: ${t["@type"]}`)}export{I as a,J as b,u as c,h as d,B as e,ae as f,xe as g,Ne as h};
import{h as V}from"./chunk-7IIDO3IU.js";import{a as z,d as H}from"./chunk-3Q4WO4OP.js";function L(e,n){let i=n||"unknown";if(!e)return;if(typeof e=="string")return{id:e,type:i};if(z(e))return L(e.source,n);let r=i&&i!=="unknown"?i:e.type||e["@type"],t=e.id||e["@id"];if(r&&r.indexOf(":")!==-1&&(r=r.split(":").pop()),t&&r)return{id:t,type:r}}var w={},f="iiif-parser:hasPart",v="iiif-parser:partOf",T="iiif-parser:isExternal",m="__$UNSET$__",I="__$UNWRAP$__",o=[];Object.freeze(o);Object.freeze(w);function te(e){if(e===w||Object.keys(e).length===0)return!0;for(let n in e)return!1;return!0}function oe(e,n){if(n&&n["@explicit"]){let i={},r=Object.keys(n);for(let t of r)t===v||t==="@explicit"||(te(n[t])?i[t]=e[t]:i[t]=n[t]);return i}return e}function F(e,n,i){let r=L(n);if(!r)return[void 0,void 0];let t=e.requests[r.id],a=r.type||e.mapping[r.id];if(!a||t&&t.resourceUri&&(!e.entities[a]||!e.entities[a][t.resourceUri]))return[void 0,void 0];let s=e.entities[a][t?t.resourceUri:r.id];if(r.type&&!s)return F(e,{id:r.id},i);if(s&&s[f]){let c=s[f].find(l=>i?l[v]===i.id:l[v]===s.id);return[oe(s,c),s]}return[s,s]}var xe={id:"https://iiif-parser/annotation",type:"Annotation",behavior:o,label:null,thumbnail:o,summary:null,requiredStatement:null,metadata:o,seeAlso:o,homepage:o,rendering:o,service:o,accessibility:o,audience:o,body:o,bodyValue:null,canonical:null,created:null,creator:o,generated:null,generator:o,modified:null,motivation:o,rights:null,stylesheet:null,target:o,timeMode:void 0,via:o,partOf:o},K={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:o,label:null,thumbnail:o,summary:null,requiredStatement:null,metadata:o,rights:null,provider:o,items:o,seeAlso:o,homepage:o,rendering:o,service:o},G={id:"https://iiif-parser/empty-canvas",type:"Canvas",label:null,behavior:o,thumbnail:o,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:o,rights:null,navDate:null,provider:o,items:o,annotations:o,seeAlso:o,homepage:o,partOf:o,rendering:o,service:o,duration:0,height:0,width:0},X={id:"https://iiif-parser/empty-collection",type:"Collection",label:null,viewingDirection:"left-to-right",behavior:o,thumbnail:o,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:o,rights:null,navDate:null,provider:o,items:o,annotations:o,seeAlso:o,homepage:o,partOf:o,rendering:o,service:o,services:o},Y={id:"https://iiif-parser/empty-manifest",type:"Manifest",annotations:o,behavior:o,homepage:o,items:o,label:null,metadata:o,navDate:null,provider:o,partOf:o,accompanyingCanvas:null,placeholderCanvas:null,rendering:o,requiredStatement:null,rights:null,seeAlso:o,service:o,services:o,start:null,structures:o,summary:null,thumbnail:o,viewingDirection:"left-to-right"},J={id:"https://iiif-parser/empty-canvas",type:"Range",label:null,behavior:o,thumbnail:o,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:o,rights:null,navDate:null,provider:o,items:o,annotations:o,seeAlso:o,homepage:o,partOf:o,rendering:o,service:o,start:null,supplementary:null,viewingDirection:"left-to-right"},B={id:"https://iiif-parser/empty-agent",type:"Agent",label:{},logo:o,seeAlso:o,homepage:o},Q={id:"https://iiif-parser/empty-service",type:"UnknownService"};function _(e,n={}){if(Array.isArray(e))return _(e[0]);if(typeof e=="string"){let[i,r]=e.split("#");return r?{type:"SpecificResource",source:{id:i,type:n.typeHint||"Unknown"},selector:{type:"FragmentSelector",value:r}}:{type:"SpecificResource",source:{id:i,type:n.typeMap&&n.typeMap[i]||n.typeHint||"Unknown"}}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return _(e.items[0]);if(e.type==="SpecificResource")return e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]),e.selector?{type:"SpecificResource",source:e.source,selector:e.selector}:{type:"SpecificResource",source:e.source};if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);let[i,r]=e.id.split("#");return r?{type:"SpecificResource",source:{...e,id:i},selector:{type:"FragmentSelector",value:r}}:{type:"SpecificResource",source:{...e,id:i}}}return{type:"SpecificResource",source:e}}var Le={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}};function ae(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}function Z(e,n){if(typeof e=="string")return{id:e,type:n};if(!e.id)throw new Error(`Invalid resource does not have an ID (${JSON.stringify(e)}, ${n})`);return e}function se(e,n){return(i,r)=>{let t=e[i]?e[i]:{};return(a,s)=>{let c=Z(a,r||i);return c&&c.id&&i?(t[c.id]=t[c.id]?W(t[c.id],c,{parent:s.parent,isTopLevel:n.id===c.id}):W({id:c.id,type:c.type},c,{parent:s.parent,isTopLevel:n.id===c.id}),{id:c.id,type:i==="ContentResource"?i:c.type}):c}}}function $(e,n,i){if(!n)return e;if(Array.isArray(e)){if(!Array.isArray(n))throw new Error("Cannot merge array with non-array");let r=[...e];for(let t of n)if(t["@id"]&&!t.id&&(t.id=t["@id"]),t["@type"]&&!t.type&&(t.type=t["@type"]),t!=null)if(Array.isArray(t))r.push(t);else if(typeof t=="object"&&t.id&&t.type){let a=r.findIndex(s=>s.id===t.id&&s.type===t.type);a>=0&&(r[a]=$(r[a],t))}else e.indexOf(t)===-1&&r.push(t);return r}else if(typeof e=="object"){if(Array.isArray(n)||typeof n!="object")throw new Error("Cannot merge object with non-object");let r={...e},t=[],a=[],s=Object.keys(e).filter(l=>l!==f&&l!=="id"&&l!=="type"),c={},A={};for(let[l,u]of Object.entries(n)){if(l===f||l==="id"||l==="type")continue;let y=r[l];y===u?a.push(l):y===o||!y?(t.push(l),r[l]=u):(y&&u&&(c[l]=y,A[l]=u),r[l]=$(y,u),r[l]===c[l]&&(a.push(l),delete c[l]))}if(i&&(i.parent&&i.parent.id||i.isTopLevel)){let l=[],u={};if(i.parent?u[v]=i.parent.id:i.isTopLevel&&(u[v]=e.id),r[f]&&r[f].length){let y=!(r[f]||[]).find(g=>g["@explicit"]),C=t.length>0||a.length!==s.length;if(y&&C)for(let g of r[f]){let p={...g},j=Object.keys(c);if(p){p["@explicit"]=!0;for(let M of s)M!==f&&(p[M]=w);for(let M of j)p[M]=c[M]}l.push(p)}else l.push(...r[f]);if(C){let g=Object.keys(A);u["@explicit"]=!0;for(let p of t)u[p]=w;for(let p of a)u[p]=w;for(let p of g)u[p]=A[p]}}u.id=r.id,u.type=r.type,l.push(u),r[f]=l}return r}else if(e)return e;return n}function W(e,n,i){if(typeof e=="string")return e;if(n.id!==e.id||n.type!==e.type){if(n.type==="ImageService3")return n;if(e.type==="ImageService3")return e;throw new Error(`Can only merge entities with identical identifiers and type! ${n.type}(${n.id}) => ${e.type}(${e.id})`)}return $({...e},n,i)}function le(e){return(n,i)=>r=>{let{id:t,type:a}=Z(r,i||n);if(typeof t>"u")throw new Error("Found invalid entity without an ID.");return n==="ContentResource"||n==="Service"?e[t]=n:e[t]=a,r}}function ce(e){let n=Object.assign({},e);if(n["@id"]&&(n.id=n["@id"]),n["@type"]&&(n.type=n["@type"]),n.service){let i=[];n.service=Array.isArray(n.service)?n.service:[n.service];for(let r of n.service)i.push({id:r["@id"]||r.id,type:r["@type"]||r.type});n.service=i}return Object.assign({},Q,n)}function de(e){return n=>{e.Service=e.Service?e.Service:{};let i=n.id||n["@id"],r=ce(n);return r&&r.id&&(e.Service[r.id]?e.Service[i]=W(e.Service[i],r):e.Service[i]=r),n}}function ue(e){let n=JSON.stringify(e),i=5381,r=n.length;for(;r;)i=i*33^n.charCodeAt(--r);let a=(i>>>0).toString(16);return a.length%2?"0"+a:a}function U(e){return n=>typeof n=="string"?{id:n,type:e}:n.id?n.type?n:{type:e,...n}:{id:`vault://${ue(n)}`,type:e,...n}}function E(e){return n=>({...e,...n})}function D(e){return Array.isArray(e)?e:[e]}function fe(e){return e.body&&(e.body=D(e.body)),e.seeAlso&&(e.seeAlso=D(e.seeAlso)),e.audience&&(e.audience=D(e.audience)),e.accessibility&&(e.accessibility=D(e.accessibility)),e.motivation&&(e.motivation=D(e.motivation)),e}function ee(e,{typeHint:n,partOfTypeHint:i}={}){if(typeof e=="string"&&(e={id:e,type:n||"unknown"}),z(e))return typeof e.source=="string"&&(e.source={id:e.source,type:n||"unknown"}),e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:i||"Manifest"}]),e;let r;if((e.id||"").indexOf("#")!==-1){let[t,a]=(e.id||"").split("#");e.id=t,a&&(r={type:"FragmentSelector",value:a})}return{type:"SpecificResource",source:e,selector:r}}function pe(e){let n=Object.assign({},e);return e&&e.items&&(n.items=e.items.map(i=>typeof i=="string"||i.type==="Canvas"?ee(i):i)),n}function ye(e){let n=Object.assign({},e);return n.start?(n.start=ee(n.start,{typeHint:"Canvas"}),n):e}function me(e){let n=Object.assign({},e);return n.target?(n.target=_(n.target,{typeHint:"Canvas"}),n):e}function ge(e){return e}function q(e){return typeof e.items>"u"&&(e[T]=!0),e}function Fe(e){let n=V(e),i=ae(),r={},t=se(i,n),a=le(r),c=new H({collection:[q,E(X),a("Collection"),t("Collection")],manifest:[q,E(Y),ye,a("Manifest"),t("Manifest")],canvas:[E(G),a("Canvas"),t("Canvas")],annotationPage:[q,U("AnnotationPage"),E(K),a("AnnotationPage"),t("AnnotationPage")],annotation:[U("Annotation"),fe,me,a("Annotation"),t("Annotation")],contentResource:[U("ContentResource"),a("ContentResource"),t("ContentResource")],range:[E(J),pe,a("Range","Canvas"),t("Range","Canvas")],agent:[E(B),a("Agent"),t("Agent")],specificResource:[ge],service:[de(i)]}).traverseUnknown(n);return{entities:i,resource:c,mapping:r}}function ve(e){let n={};for(let[i,r]of e){if(i===I&&r!==m)return r;r!==m&&typeof r<"u"&&r!==null&&(n[i]=r)}return n}function $e(e,n,i){if(!n.type||!n.id)throw new Error("Unknown entity");if(!i[n.type])throw new Error(`Serializer not found for ${n.type}`);function r(t,a,s=0){let c=i[t.type];if(!c)return m;if(s>20)throw new Error("Circular reference: "+t.id+" "+t.type);let[A,l]=F(e,t.type?t:t.id,a)||(t.id&&t.type?t:null);if(!A)return m;let u=c(A,e,{parent:a,isTopLevel:n.id===t.id,fullResource:l}),y=u.next();for(;!y.done;){let C=y.value,g=m;if(C)if(Array.isArray(C)){let p=[];for(let j of C)p.push(r(j,t,s+1));g=p}else g=r(C,t,s+1);y=u.next(g)}return y.value===m?m:ve(y.value)}return r(n)}function P(e,{allowSourceString:n=!0,allowString:i=!1,allowedStringType:r}={}){let t=a=>{if(n&&a&&a.source&&typeof a.source!="string"){let s=Object.keys(a.source);if(a.source.id&&a.source.type&&s.length===2)return{...a,source:a.source.id}}return a};if(e){if(e.source&&e.source.partOf)return t(e);let a=Object.keys(e);if(a.length===2&&e.type&&e.source||a.length===3&&e.type&&e.source&&a.indexOf("selector")!==-1&&!e.selector)return i&&(!r||r===e.source.type)?e.source.id:e.source.type==="ContentResource"?{type:"SpecificResource",source:e.source.id}:e.source;if(e.selector&&!Array.isArray(e.selector)&&typeof e.selector!="string"&&e.selector.type==="FragmentSelector"){let s=`${e.source.id}#${e.selector.value}`;return i?s:{id:s,type:e.source.type}}}return t(e)}function O(e){if(!e)return;let n=Object.keys(e);if(n.length!==0){if(n.length===1){let i=n[0];if(!i)return"";let r=(e[i]||[]).join("");return i==="@none"||i==="none"||i==="en"?r:{"@language":i,"@value":r}}return n.map(i=>({"@language":i,"@value":(e[i]||[]).join("")}))}}function ne(e){return Array.isArray(e)?e.map(n=>ne(n)):typeof e=="string"?e:e.type&&e.type==="Canvas"?e.id:e}function h(e,n=!1){if(e)return e.length>1&&!n?e:e[0]||void 0}function he(e){if(e){if(typeof e=="string")return{"@id":e};if("@id"in e){let n={...e};return delete n["@type"],n}return{"@context":"http://iiif.io/api/image/2/context.json","@id":e.id,profile:`http://iiif.io/api/image/2/profiles/${e.profile}.json`}}}function N(e,n){return[["@id",e.id],["@type",n],["format",e.format],["height",e.height],["width",e.width],["viewingDirection",e.viewingDirection!=="left-to-right"?e.viewingDirection:void 0],["license",e.license?e.license:void 0]]}function*b(e){let n=e.provider?yield e.provider[0]:void 0;return[["label",O(e.label)],["metadata",e.metadata&&e.metadata.length?e.metadata.map(i=>({label:O(i.label)||"",value:O(i.value)||""})):void 0],["description",O(e.summary)],["thumbnail",h(yield e.thumbnail)],["navDate",e.navDate],["logo",n?h(n.logo):void 0],["homepage",n?n.homepage:void 0],["attribution",e.requiredStatement?O(e.requiredStatement.value):void 0]]}function*k(e){let n=e.start&&e.start.type&&e.start.type==="SpecificResource"?P(e.start):e.start;return[["seeAlso",h(yield e.seeAlso)],["service",h((e.service||[]).map(he))],["rendering",h(yield e.rendering)],["startCanvas",n?n.id:void 0]]}function Se(e){return e.type==="SpecificResource"}function Re(e){return e&&e.type==="FragmentSelector"}function Ae(e){if(e&&Se(e)){let n=e.id,i=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return Re(i)&&(n+="#"+i.value),n}return e?.id}var Ke={Manifest:function*(e,n,{isTopLevel:i}){return[...i?[["@context","http://iiif.io/api/presentation/2/context.json"]]:[],...N(e,"sc:Manifest"),...yield*b(e),...yield*k(e),["sequences",[{"@id":`${e.id}/sequence0`,"@type":"sc:Sequence",canvases:yield e.items}]],["structures",yield e.structures]]},Canvas:function*(e){let i=(yield e.items)[0];return[...N(e,"sc:Canvas"),...yield*b(e),...yield*k(e),["images",i?[i.resources]:void 0],["annotations",e.annotations&&e.annotations.length?h(yield e.annotations):void 0]]},AnnotationPage:function*(e){return[...N(e,"sc:AnnotationList"),...yield*b(e),["resources",e.items&&e.items.length?h(yield e.items):void 0]]},Annotation:function*(e){return[["@id",e.id],["@type","oa:Annotation"],["motivation","sc:painting"],["on",ne(e.target)],["resource",h(yield e.body,!0)]]},ContentResource:function*(e){switch(e.type){case"Image":return[...N(e,"dctypes:Image"),...yield*b(e),...yield*k(e)];case"Text":case"Dataset":default:return[...N(e,void 0),...yield*b(e)]}},AnnotationCollection:function*(e){return[["@id",e.id],["@type","sc:Layer"],["label",O(e.label)]]},Collection:function*(e){return[...N(e,"sc:Collection"),...yield*b(e),...yield*k(e),["members",yield*e.items]]},Range:function*(e){let n=[],i=[];if(e.items)for(let r of e.items){let t=r.type==="SpecificResource"?r.source:r;if(t){let a=yield t;n.push({"@id":Ae(r),"@type":t.type,label:a?a.label:void 0,within:e.id}),t.type==="Canvas"&&i.push(t.id)}}return[...N(e,"sc:Range"),...yield*b(e),...yield*k(e),["canvases",i.length===n.length?i:void 0],["members",i.length!==n.length?n:void 0]]}};function x(e){return[["id",e.id?.startsWith("vault://")?void 0:e.id],["type",e.type],["format",e.format],["profile",e.profile],["height",e.height||void 0],["width",e.width||void 0],["duration",e.duration||void 0],["viewingDirection",e.viewingDirection!=="left-to-right"?e.viewingDirection:void 0],["behavior",e.behavior&&e.behavior.length?e.behavior:void 0],["timeMode",e.timeMode],["motivation",Array.isArray(e.motivation)?e.motivation[0]:e.motivation],[f,m]]}function d(e){if(e===m||!e||e.length===0)return;let n=e.filter(i=>i!==m);if(n.length!==0)return n}function re(e){if(e&&e.type&&e.type==="ImageService2"){let{id:n,type:i,profile:r,...t}=e,a=typeof r=="string"?r:Array.isArray(r)?r.find(s=>typeof s=="string"):"";return{"@id":n,"@type":i,profile:a?a.startsWith("http")?a:`http://iiif.io/api/image/2/${a}.json`:"http://iiif.io/api/image/2/level0.json",...t}}return e}function ie(e){if(Array.isArray(e)||(e=e?[e]:[]),!(!e||e.length===0))return e.map(re)}function*S(e){return[["label",e.label],["metadata",d(e.metadata)],["summary",e.summary],["requiredStatement",e.requiredStatement],["rights",Array.isArray(e.rights)?e.rights[0]||void 0:e.rights||void 0],["navDate",e.navDate],["language",e.language],["thumbnail",d(yield e.thumbnail)],["placeholderCanvas",yield e.placeholderCanvas],["accompanyingCanvas",yield e.accompanyingCanvas],["provider",d(yield e.provider)]]}function*R(e){return[["seeAlso",d(yield e.seeAlso)],["service",d(ie(e.service))],["services",d(ie(e.services))],["rendering",d(yield e.rendering)],["supplementary",d(yield e.supplementary)],["homepage",d(yield e.homepage)],["logo",d(yield e.logo)],["partOf",d(yield e.partOf)],["start",e.start?P(e.start):e.start]]}var Be={Manifest:function*(e,n,{isTopLevel:i}){return i?[["@context",e["@context"]?e["@context"]:"http://iiif.io/api/presentation/3/context.json"],...x(e),...yield*S(e),...yield*R(e),["items",yield e.items],["structures",d(yield e.structures)],["annotations",d(yield e.annotations)],["navPlace",e.navPlace]]:[...x(e),...yield*S(e)]},Canvas:function*(e){return[...x(e),...yield*S(e),...yield*R(e),["items",yield e.items],["annotations",d(yield e.annotations)],["navPlace",e.navPlace]]},Agent:function*(e){return[["id",e.id],["type","Agent"],["label",e.label],...yield*R(e)]},AnnotationPage:function*(e){let n=Object.entries(e).map(([r,t])=>[r,Array.isArray(t)?d(t):t]).filter(([r,t])=>r!=="items"&&r!=="id"&&r!==f&&r!==v&&r!==T),i=yield e.items;return[["id",e.id?.startsWith("vault://")?void 0:e.id],...n,...yield*R(e),["items",i.length||e[T]===!1?i:m]]},Service:function*(e){return[[I,re(e)]]},Annotation:function*(e){let n=Object.entries(e).map(([r,t])=>r==="motivation"?[r,Array.isArray(t)?t[0]:t]:r==="target"?[r,P(t,{allowString:!0,allowSourceString:!0,allowedStringType:"Canvas"})]:[r,Array.isArray(t)?d(t):t]).filter(([r])=>r!=="body"&&r!==f&&r!==T),i;if(Array.isArray(e.body)){let r=[];for(let t of e.body)if(t&&z(t)){let a={...t};a.source=yield t.source,r.push(P(a,{allowSourceString:!0}))}else r.push(yield t);i=r}else e.body&&z(e.body)?(i={...e.body},i.source=yield e.body.source):i=yield e.body;return[...n,...yield*S(e),...yield*R(e),["body",i.length===1?i[0]:i]]},ContentResource:function*(e){return Ce([...x(e),...yield*S(e),...yield*R(e),["annotations",d(yield e.annotations)],["items",d(yield e.items)]],e)},AnnotationCollection:function*(e){return[["id",e.id],["type","AnnotationCollection"],["label",e.label]]},Collection:function*(e,n,{isTopLevel:i}){return i?[["@context","http://iiif.io/api/presentation/3/context.json"],...x(e),...yield*S(e),...yield*R(e),["items",d(yield e.items)],["navPlace",e.navPlace]]:[...x(e),...yield*S(e)]},Range:function*(e){let n=[];for(let i of e.items)i.type==="Range"?n.push(yield i):i&&i.type==="SpecificResource"?n.push(P(i)):n.push(i);return[...x(e),...yield*S(e),...yield*R(e),["items",n],["annotations",d(yield e.annotations)],["navPlace",e.navPlace]]}};function Ce(e,n){let i=Object.keys(n),r=e.map(([t])=>t);for(let t of i)t===f||t===T||r.indexOf(t)===-1&&typeof n[t]<"u"&&e.push([t,n[t]]);return e}export{L as a,w as b,f as c,v as d,T as e,m as f,I as g,o as h,te as i,oe as j,F as k,xe as l,K as m,G as n,X as o,Y as p,J as q,B as r,Q as s,Le as t,ae as u,$ as v,W as w,ge as x,q as y,Fe as z,ve as A,$e as B,P as C,O as D,Ke as E,Be as F};