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
0
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.2
to
2.1.3
+1
dist/chunk-7YCHMFAA.js
import{h as V}from"./chunk-5GMXZJIZ.js";import{a as z,d as H}from"./chunk-BCORR5FZ.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};
import{a as i}from"./chunk-NJNTZ6QT.js";import{a as r}from"./chunk-D22QKJZO.js";function v(n){return typeof n=="string"?!1:!!n&&n.type==="SpecificResource"}function o(...n){return e=>n.reduce((t,a)=>a(t),e)}var p=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function y(n,e){if(typeof n>"u"||n===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(n))throw new Error("Array is not a valid entity");if(typeof n!="object"){if(e)return e;throw new Error(`${typeof n} is not a valid entity`)}if(typeof n.type=="string"){let t=p.indexOf(n.type);if(t!==-1)return p[t]}if(n.profile)return"Service";throw new Error("Resource type is not known")}var l=class n{constructor(e,t={}){r(this,"traversals");r(this,"options");r(this,"_traverseManifest",o(this.traverseManifestItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseManifestStructures.bind(this),this.traverseInlineAnnotationPages.bind(this)));r(this,"_traverseCanvas",o(this.traverseCanvasItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseInlineAnnotationPages.bind(this)));r(this,"_traverseAnnotationPage",o(this.traverseAnnotationPageItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this)));r(this,"_traverseRange",o(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:[],...e},this.options={allowUndefinedReturn:!1,...t}}static all(e){return new n({collection:[e],manifest:[e],canvas:[e],annotationCollection:[e],annotationPage:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],geoJson:[e],specificResource:[e],agent:[e]})}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=i(e.thumbnail).map(t=>this.traverseType(t,{parent:e},this.traversals.contentResource))),e.provider&&(e.provider=e.provider.map(t=>this.traverseAgent(t,e))),e}traverseLinking(e){return e.seeAlso&&(e.seeAlso=e.seeAlso.map(t=>this.traverseType(t,{parent:e},this.traversals.contentResource))),e.service&&(e.service=i(e.service).map(t=>this.traverseService(t))),e.services&&(e.services=i(e.services).map(t=>this.traverseService(t,e))),e.logo&&(e.logo=e.logo.map(t=>this.traverseType(t,{parent:e},this.traversals.contentResource))),e.homepage&&(e.homepage=i(e.homepage).map(t=>this.traverseType(t,{parent:e},this.traversals.contentResource))),e.partOf&&(e.partOf=e.partOf.map(t=>typeof t=="string"||!t.type?this.traverseType(t,{parent:e},this.traversals.contentResource):t.type==="Canvas"?this.traverseType(t,{parent:e},this.traversals.canvas):t.type==="AnnotationCollection"?this.traverseType(t,{parent:e},this.traversals.annotationCollection):t.type==="Collection"?this.traverseType(t,{parent:e},this.traversals.collection):this.traverseType(t,{parent:e},this.traversals.contentResource))),e.start&&(v(e.start)?e.start=this.traverseSpecificResource(e.start,"Canvas",e):e.start=this.traverseType(e.start,{parent:e},this.traversals.canvas)),e.rendering&&(e.rendering=e.rendering.map(t=>this.traverseType(t,{parent:e},this.traversals.contentResource))),e.supplementary&&(e.supplementary=e.supplementary.map(t=>this.traverseType(t,{parent:e},this.traversals.contentResource))),e}traverseCollectionItems(e){return e.items&&e.items.map(t=>t.type==="Collection"?this.traverseCollection(t):this.traverseManifest(t)),e}traverseCollection(e,t){return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traverseLinkedCanvases(this.traverseCollectionItems(e))))),{parent:t},this.traversals.collection)}traverseGeoJson(e,t){return this.traverseType(e,{parent:t},this.traversals.geoJson)}traverseNavPlace(e){return e.navPlace&&(e.navPlace=this.traverseGeoJson(e.navPlace,e)),e}traverseManifestItems(e){return e.items&&(e.items=e.items.map(t=>this.traverseCanvas(t))),e}traverseManifestStructures(e){return e.structures&&(e.structures=e.structures.map(t=>this.traverseRange(t))),e}traverseManifest(e,t){return this.traverseType(this._traverseManifest(e),{parent:t},this.traversals.manifest)}traverseCanvasItems(e){return e.items=(e.items||[]).map(t=>this.traverseAnnotationPage(t,e)),e}traverseInlineAnnotationPages(e){return typeof e=="string"||!e||e.annotations&&(e.annotations=e.annotations.map(t=>this.traverseAnnotationPage(t,e))),e}traverseCanvas(e,t){return this.traverseType(this._traverseCanvas(e),{parent:t},this.traversals.canvas)}traverseAnnotationPageItems(e){return e.items&&(e.items=e.items.map(t=>this.traverseAnnotation(t,e))),e}traverseAnnotationPage(e,t){return this.traverseType(this._traverseAnnotationPage(e),{parent:t},this.traversals.annotationPage)}traverseAnnotationBody(e){return Array.isArray(e.body)?e.body=e.body.map(t=>this.traverseContentResource(t,e)):e.body&&(e.body=this.traverseContentResource(e.body,e)),e}traverseLinkedCanvases(e){return e.placeholderCanvas&&(e.placeholderCanvas=this.traverseCanvas(e.placeholderCanvas)),e.accompanyingCanvas&&(e.accompanyingCanvas=this.traverseCanvas(e.accompanyingCanvas)),e}traverseAnnotation(e,t){return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(this.traverseDescriptive(e))),{parent:t},this.traversals.annotation)}traverseContentResourceLinking(e){return typeof e=="string"||!e||e&&e.service&&(e.service=i(e.service||[]).map(t=>this.traverseService(t,e))),e}traverseContentResource(e,t){return e.type==="Choice"&&(e.items=e.items.map(a=>this.traverseContentResource(a,e))),v(e)?this.traverseSpecificResource(e,"ContentResource"):this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)),{parent:t},this.traversals.contentResource)}traverseSpecificResource(e,t,a){let s=e.source;return typeof e.source=="string"&&(s={id:e.source,type:t||"unknown"}),this.traverseType({...e,source:t==="Canvas"||s.type==="Canvas"?this.traverseType(s,{parent:a},this.traversals.canvas):t==="ContentResource"?this.traverseContentResource(s,{parent:a}):this.traverseUnknown(s,{parent:a,typeHint:t})},{parent:a},this.traversals.specificResource)}traverseRangeRanges(e){return e.items&&(e.items=e.items.map(t=>typeof t=="string"?this.traverseCanvas({id:t,type:"Canvas"},e):v(t)?this.traverseSpecificResource(t,"Canvas",e):t.type==="Manifest"?this.traverseManifest(t,e):this.traverseRange(t,e))),e}traverseRange(e,t){return this.traverseType(this._traverseRange(e),{parent:t},this.traversals.range)}traverseAgent(e,t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),{parent:t},this.traversals.agent)}traverseType(e,t,a){return a.reduce((s,c)=>{let h=c(s,t);return typeof h>"u"&&!this.options.allowUndefinedReturn?s:h},e)}traverseService(e,t){let a=Object.assign({},e);return a&&a.service&&(a.service=i(a.service).map(s=>this.traverseService(s))),this.traverseType(a,{parent:t},this.traversals.service)}traverseUnknown(e,{parent:t,typeHint:a}={}){let s=y(e,a);switch(s){case"Collection":return this.traverseCollection(e,t);case"Manifest":return this.traverseManifest(e,t);case"Canvas":return this.traverseCanvas(e,t);case"AnnotationPage":return this.traverseAnnotationPage(e,t);case"Annotation":return this.traverseAnnotation(e,t);case"ContentResource":return this.traverseContentResource(e,t);case"Range":return this.traverseRange(e,t);case"Service":return this.traverseService(e,t);case"Agent":return this.traverseAgent(e,t);default:throw new Error(`Unknown or unsupported resource type of ${s}`)}}};export{v as a,p as b,y as c,l as d};
+1
-1

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

"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 bn={};rt(bn,{EMPTY:()=>s,HAS_PART:()=>u,IS_EXTERNAL:()=>S,PART_OF:()=>C,Traverse:()=>q,UNSET:()=>y,UNWRAP:()=>G,WILDCARD:()=>N,addFlagForExternalResource:()=>Q,compressSpecificResource:()=>_,defaultEntities:()=>un,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:()=>In,resolveIfExists:()=>H,serialize:()=>Sn,serializeConfigPresentation2:()=>En,serializeConfigPresentation3:()=>Ln,serializedFieldsToObject:()=>Qe,toRef:()=>$,traverseSpecificResource:()=>Je,types:()=>oe});module.exports=st(bn);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",S="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 T(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=T(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=T(t.service).map(n=>this.traverseService(n))),t.services&&(t.services=T(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=T(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=T(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",St="http://iiif.io/api/image/2/level2.json",Tt="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,St,Tt,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",Se="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",Te="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,Se,Pe,Ee,Le,Ne,Oe,we],Xn=[...le,ze,ge,Ce,Ie,Te,_e,xe,Me,be,Fe],jt=[Dt,ze,ke,Lt,ge,Ae,Mt,Ce,Re,bt,Ie,Se,Nt,Te,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?T(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:tn(e.structures)})}function tn(e){if(!e)return e;let t=new Map;for(let i of e)t.set(i.id,i);let n=[];for(let i of e)if(i.items){let r=i.items.map(a=>typeof a=="string"?(n.push(a),t.get(a)||a):a&&a.id?(n.push(a.id),t.get(a.id)||a):a);i.items=r}return e.filter(i=>n.indexOf(i.id)===-1)}function nn(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 rn(e){return m({...R(e),...I(e),...P(e),items:e.resources&&e.resources.length?e.resources:void 0})}function an(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}}function sn(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 on(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 ln(e){return m({...R(e),...I(e),...P(e),items:e.members})}function cn(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 pn(e){return m({...R(e),...I(e),...P(e)})}var fn=new K({collection:[Zt],manifest:[en],canvas:[nn],annotationList:[rn],sequence:[an],annotation:[sn],contentResource:[We],choice:[on],range:[ln],service:[cn],layer:[pn]});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"?fn.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 un={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 dn(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 vn(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 yn(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 hn(e){return t=>{e.Service=e.Service?e.Service:{};let n=t.id||t["@id"],i=yn(t);return i&&i.id&&(e.Service[i.id]?e.Service[n]=Y(e.Service[n],i):e.Service[n]=i),t}}function mn(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://${mn(t)}`,type:e,...t}}function D(e){return t=>({...e,...t})}function V(e){return Array.isArray(e)?e:[e]}function gn(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 An(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 Cn(e){let t=Object.assign({},e);return t.start?(t.start=Ke(t.start,{typeHint:"Canvas"}),t):e}function Rn(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[S]=!0),e}function In(e){let t=Be(e),n=$e(),i={},r=dn(n,t),a=vn(i),l=new q({collection:[Q,D(ne),a("Collection"),r("Collection")],manifest:[Q,D(ie),Cn,a("Manifest"),r("Manifest")],canvas:[D(te),a("Canvas"),r("Canvas")],annotationPage:[Q,ue("AnnotationPage"),D(ee),a("AnnotationPage"),r("AnnotationPage")],annotation:[ue("Annotation"),gn,Rn,a("Annotation"),r("Annotation")],contentResource:[ue("ContentResource"),a("ContentResource"),r("ContentResource")],range:[D(re),An,a("Range","Canvas"),r("Range","Canvas")],agent:[D(ae),a("Agent"),r("Agent")],specificResource:[Je],service:[hn(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 Sn(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 Pn(e){return e.type==="SpecificResource"}function _n(e){return e&&e.type==="FragmentSelector"}function xn(e){if(e&&Pn(e)){let t=e.id,n=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return _n(n)&&(t+="#"+n.value),t}return e?.id}var En={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":xn(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 Ln={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!==S),n=yield e.items;return[["id",e.id?.startsWith("vault://")?void 0:e.id],...t,...yield*L(e),["items",n.length||e[S]===!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!==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(_(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 Mn([...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 Mn(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 bn={};rt(bn,{EMPTY:()=>s,HAS_PART:()=>u,IS_EXTERNAL:()=>T,PART_OF:()=>C,Traverse:()=>q,UNSET:()=>y,UNWRAP:()=>G,WILDCARD:()=>N,addFlagForExternalResource:()=>Q,compressSpecificResource:()=>_,defaultEntities:()=>un,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:()=>In,resolveIfExists:()=>H,serialize:()=>Sn,serializeConfigPresentation2:()=>En,serializeConfigPresentation3:()=>Ln,serializedFieldsToObject:()=>Qe,toRef:()=>$,traverseSpecificResource:()=>Je,types:()=>oe});module.exports=st(bn);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 R(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=R(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=R(t.service).map(n=>this.traverseService(n))),t.services&&(t.services=R(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=R(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=R(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=R(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",St="http://iiif.io/api/image/2/level2.json",Tt="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,St,Tt,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",Se="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",Te="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,Se,Pe,Ee,Le,Ne,Oe,we],Xn=[...le,ze,ge,Ce,Ie,Te,_e,xe,Me,be,Fe],jt=[Dt,ze,ke,Lt,ge,Ae,Mt,Ce,Re,bt,Ie,Se,Nt,Te,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 I(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 S(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?R(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({...I(e),...S(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=I(e);return n.length&&(r.behavior?r.behavior.push(...n):r.behavior=n),m({...r,...S(e),...P(e),start:i,items:t,structures:tn(e.structures)})}function tn(e){if(!e)return e;let t=new Map;for(let i of e)t.set(i.id,i);let n=[];for(let i of e)if(i.items){let r=i.items.map(a=>typeof a=="string"?(n.push(a),t.get(a)||a):a&&a.id?(n.push(a.id),t.get(a.id)||a):a);i.items=r}return e.filter(i=>n.indexOf(i.id)===-1)}function nn(e){return m({...I(e),...S(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 rn(e){return m({...I(e),...S(e),...P(e),items:e.resources&&e.resources.length?e.resources:void 0})}function an(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}}function sn(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({...I(e),...S(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({...I(t),...S(t),...P(t),...Yt(t)})}function on(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({...I(e),...S(e),items:t})}function ln(e){return m({...I(e),...S(e),...P(e),items:e.members})}function cn(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 pn(e){return m({...I(e),...S(e),...P(e)})}var fn=new K({collection:[Zt],manifest:[en],canvas:[nn],annotationList:[rn],sequence:[an],annotation:[sn],contentResource:[We],choice:[on],range:[ln],service:[cn],layer:[pn]});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"?fn.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 un={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 dn(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 vn(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 yn(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 hn(e){return t=>{e.Service=e.Service?e.Service:{};let n=t.id||t["@id"],i=yn(t);return i&&i.id&&(e.Service[i.id]?e.Service[n]=Y(e.Service[n],i):e.Service[n]=i),t}}function mn(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://${mn(t)}`,type:e,...t}}function D(e){return t=>({...e,...t})}function V(e){return Array.isArray(e)?e:[e]}function gn(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 An(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 Cn(e){let t=Object.assign({},e);return t.start?(t.start=Ke(t.start,{typeHint:"Canvas"}),t):e}function Rn(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 In(e){let t=Be(e),n=$e(),i={},r=dn(n,t),a=vn(i),l=new q({collection:[Q,D(ne),a("Collection"),r("Collection")],manifest:[Q,D(ie),Cn,a("Manifest"),r("Manifest")],canvas:[D(te),a("Canvas"),r("Canvas")],annotationPage:[Q,ue("AnnotationPage"),D(ee),a("AnnotationPage"),r("AnnotationPage")],annotation:[ue("Annotation"),gn,Rn,a("Annotation"),r("Annotation")],contentResource:[ue("ContentResource"),a("ContentResource"),r("ContentResource")],range:[D(re),An,a("Range","Canvas"),r("Range","Canvas")],agent:[D(ae),a("Agent"),r("Agent")],specificResource:[Je],service:[hn(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 Sn(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 Pn(e){return e.type==="SpecificResource"}function _n(e){return e&&e.type==="FragmentSelector"}function xn(e){if(e&&Pn(e)){let t=e.id,n=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return _n(n)&&(t+="#"+n.value),t}return e?.id}var En={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":xn(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 Ln={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 Mn([...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 Mn(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 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 bn={};rt(bn,{EMPTY:()=>s,HAS_PART:()=>u,IS_EXTERNAL:()=>S,PART_OF:()=>C,Traverse:()=>q,UNSET:()=>y,UNWRAP:()=>G,WILDCARD:()=>N,addFlagForExternalResource:()=>Q,compressSpecificResource:()=>_,defaultEntities:()=>un,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:()=>In,resolveIfExists:()=>H,serialize:()=>Sn,serializeConfigPresentation2:()=>En,serializeConfigPresentation3:()=>Ln,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",S="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 T(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=T(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=T(t.service).map(n=>this.traverseService(n))),t.services&&(t.services=T(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=T(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=T(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",St="http://iiif.io/api/image/2/level2.json",Tt="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,St,Tt,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",Se="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",Te="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,Se,Pe,Ee,Le,Ne,Oe,we],Xn=[...le,ze,ge,Ce,Ie,Te,_e,xe,Me,be,Fe],jt=[Dt,ze,ke,Lt,ge,Ae,Mt,Ce,Re,bt,Ie,Se,Nt,Te,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?T(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:tn(e.structures)})}function tn(e){if(!e)return e;let t=new Map;for(let i of e)t.set(i.id,i);let n=[];for(let i of e)if(i.items){let r=i.items.map(a=>typeof a=="string"?(n.push(a),t.get(a)||a):a&&a.id?(n.push(a.id),t.get(a.id)||a):a);i.items=r}return e.filter(i=>n.indexOf(i.id)===-1)}function nn(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 rn(e){return m({...R(e),...I(e),...P(e),items:e.resources&&e.resources.length?e.resources:void 0})}function an(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}}function sn(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 on(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 ln(e){return m({...R(e),...I(e),...P(e),items:e.members})}function cn(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 pn(e){return m({...R(e),...I(e),...P(e)})}var fn=new K({collection:[Zt],manifest:[en],canvas:[nn],annotationList:[rn],sequence:[an],annotation:[sn],contentResource:[We],choice:[on],range:[ln],service:[cn],layer:[pn]});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"?fn.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 un={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 dn(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 vn(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 yn(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 hn(e){return t=>{e.Service=e.Service?e.Service:{};let n=t.id||t["@id"],i=yn(t);return i&&i.id&&(e.Service[i.id]?e.Service[n]=Y(e.Service[n],i):e.Service[n]=i),t}}function mn(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://${mn(t)}`,type:e,...t}}function D(e){return t=>({...e,...t})}function V(e){return Array.isArray(e)?e:[e]}function gn(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 An(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 Cn(e){let t=Object.assign({},e);return t.start?(t.start=Ke(t.start,{typeHint:"Canvas"}),t):e}function Rn(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[S]=!0),e}function In(e){let t=Be(e),n=$e(),i={},r=dn(n,t),a=vn(i),l=new q({collection:[Q,D(ne),a("Collection"),r("Collection")],manifest:[Q,D(ie),Cn,a("Manifest"),r("Manifest")],canvas:[D(te),a("Canvas"),r("Canvas")],annotationPage:[Q,ue("AnnotationPage"),D(ee),a("AnnotationPage"),r("AnnotationPage")],annotation:[ue("Annotation"),gn,Rn,a("Annotation"),r("Annotation")],contentResource:[ue("ContentResource"),a("ContentResource"),r("ContentResource")],range:[D(re),An,a("Range","Canvas"),r("Range","Canvas")],agent:[D(ae),a("Agent"),r("Agent")],specificResource:[Je],service:[hn(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 Sn(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 Pn(e){return e.type==="SpecificResource"}function _n(e){return e&&e.type==="FragmentSelector"}function xn(e){if(e&&Pn(e)){let t=e.id,n=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return _n(n)&&(t+="#"+n.value),t}return e?.id}var En={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":xn(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 Ln={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!==S),n=yield e.items;return[["id",e.id?.startsWith("vault://")?void 0:e.id],...t,...yield*L(e),["items",n.length||e[S]===!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!==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(_(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 Mn([...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 Mn(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 st(bn);})();
"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 bn={};rt(bn,{EMPTY:()=>s,HAS_PART:()=>u,IS_EXTERNAL:()=>T,PART_OF:()=>C,Traverse:()=>q,UNSET:()=>y,UNWRAP:()=>G,WILDCARD:()=>N,addFlagForExternalResource:()=>Q,compressSpecificResource:()=>_,defaultEntities:()=>un,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:()=>In,resolveIfExists:()=>H,serialize:()=>Sn,serializeConfigPresentation2:()=>En,serializeConfigPresentation3:()=>Ln,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 R(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=R(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=R(t.service).map(n=>this.traverseService(n))),t.services&&(t.services=R(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=R(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=R(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=R(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",St="http://iiif.io/api/image/2/level2.json",Tt="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,St,Tt,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",Se="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",Te="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,Se,Pe,Ee,Le,Ne,Oe,we],Xn=[...le,ze,ge,Ce,Ie,Te,_e,xe,Me,be,Fe],jt=[Dt,ze,ke,Lt,ge,Ae,Mt,Ce,Re,bt,Ie,Se,Nt,Te,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 I(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 S(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?R(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({...I(e),...S(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=I(e);return n.length&&(r.behavior?r.behavior.push(...n):r.behavior=n),m({...r,...S(e),...P(e),start:i,items:t,structures:tn(e.structures)})}function tn(e){if(!e)return e;let t=new Map;for(let i of e)t.set(i.id,i);let n=[];for(let i of e)if(i.items){let r=i.items.map(a=>typeof a=="string"?(n.push(a),t.get(a)||a):a&&a.id?(n.push(a.id),t.get(a.id)||a):a);i.items=r}return e.filter(i=>n.indexOf(i.id)===-1)}function nn(e){return m({...I(e),...S(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 rn(e){return m({...I(e),...S(e),...P(e),items:e.resources&&e.resources.length?e.resources:void 0})}function an(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}}function sn(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({...I(e),...S(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({...I(t),...S(t),...P(t),...Yt(t)})}function on(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({...I(e),...S(e),items:t})}function ln(e){return m({...I(e),...S(e),...P(e),items:e.members})}function cn(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 pn(e){return m({...I(e),...S(e),...P(e)})}var fn=new K({collection:[Zt],manifest:[en],canvas:[nn],annotationList:[rn],sequence:[an],annotation:[sn],contentResource:[We],choice:[on],range:[ln],service:[cn],layer:[pn]});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"?fn.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 un={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 dn(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 vn(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 yn(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 hn(e){return t=>{e.Service=e.Service?e.Service:{};let n=t.id||t["@id"],i=yn(t);return i&&i.id&&(e.Service[i.id]?e.Service[n]=Y(e.Service[n],i):e.Service[n]=i),t}}function mn(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://${mn(t)}`,type:e,...t}}function D(e){return t=>({...e,...t})}function V(e){return Array.isArray(e)?e:[e]}function gn(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 An(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 Cn(e){let t=Object.assign({},e);return t.start?(t.start=Ke(t.start,{typeHint:"Canvas"}),t):e}function Rn(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 In(e){let t=Be(e),n=$e(),i={},r=dn(n,t),a=vn(i),l=new q({collection:[Q,D(ne),a("Collection"),r("Collection")],manifest:[Q,D(ie),Cn,a("Manifest"),r("Manifest")],canvas:[D(te),a("Canvas"),r("Canvas")],annotationPage:[Q,ue("AnnotationPage"),D(ee),a("AnnotationPage"),r("AnnotationPage")],annotation:[ue("Annotation"),gn,Rn,a("Annotation"),r("Annotation")],contentResource:[ue("ContentResource"),a("ContentResource"),r("ContentResource")],range:[D(re),An,a("Range","Canvas"),r("Range","Canvas")],agent:[D(ae),a("Agent"),r("Agent")],specificResource:[Je],service:[hn(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 Sn(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 Pn(e){return e.type==="SpecificResource"}function _n(e){return e&&e.type==="FragmentSelector"}function xn(e){if(e&&Pn(e)){let t=e.id,n=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return _n(n)&&(t+="#"+n.value),t}return e?.id}var En={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":xn(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 Ln={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 Mn([...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 Mn(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(bn);})();

@@ -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-XVRUT7GK.js";import"./chunk-R2Q75YNZ.js";import"./chunk-5GMXZJIZ.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};
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-7YCHMFAA.js";import"./chunk-R2Q75YNZ.js";import"./chunk-5GMXZJIZ.js";import"./chunk-J657UVVW.js";import{a as o,b as s,c as u,d as v}from"./chunk-BCORR5FZ.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 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 bn={};rt(bn,{EMPTY:()=>s,HAS_PART:()=>u,IS_EXTERNAL:()=>S,PART_OF:()=>C,Traverse:()=>q,UNSET:()=>y,UNWRAP:()=>G,WILDCARD:()=>N,addFlagForExternalResource:()=>Q,compressSpecificResource:()=>_,defaultEntities:()=>un,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:()=>In,resolveIfExists:()=>H,serialize:()=>Sn,serializeConfigPresentation2:()=>En,serializeConfigPresentation3:()=>Ln,serializedFieldsToObject:()=>Qe,toRef:()=>$,traverseSpecificResource:()=>Je,types:()=>oe});module.exports=st(bn);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",S="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 T(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=T(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=T(t.service).map(n=>this.traverseService(n))),t.services&&(t.services=T(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=T(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=T(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",St="http://iiif.io/api/image/2/level2.json",Tt="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,St,Tt,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",Se="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",Te="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,Se,Pe,Ee,Le,Ne,Oe,we],Xn=[...le,ze,ge,Ce,Ie,Te,_e,xe,Me,be,Fe],jt=[Dt,ze,ke,Lt,ge,Ae,Mt,Ce,Re,bt,Ie,Se,Nt,Te,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?T(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:tn(e.structures)})}function tn(e){if(!e)return e;let t=new Map;for(let i of e)t.set(i.id,i);let n=[];for(let i of e)if(i.items){let r=i.items.map(a=>typeof a=="string"?(n.push(a),t.get(a)||a):a&&a.id?(n.push(a.id),t.get(a.id)||a):a);i.items=r}return e.filter(i=>n.indexOf(i.id)===-1)}function nn(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 rn(e){return m({...R(e),...I(e),...P(e),items:e.resources&&e.resources.length?e.resources:void 0})}function an(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}}function sn(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 on(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 ln(e){return m({...R(e),...I(e),...P(e),items:e.members})}function cn(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 pn(e){return m({...R(e),...I(e),...P(e)})}var fn=new K({collection:[Zt],manifest:[en],canvas:[nn],annotationList:[rn],sequence:[an],annotation:[sn],contentResource:[We],choice:[on],range:[ln],service:[cn],layer:[pn]});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"?fn.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 un={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 dn(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 vn(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 yn(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 hn(e){return t=>{e.Service=e.Service?e.Service:{};let n=t.id||t["@id"],i=yn(t);return i&&i.id&&(e.Service[i.id]?e.Service[n]=Y(e.Service[n],i):e.Service[n]=i),t}}function mn(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://${mn(t)}`,type:e,...t}}function D(e){return t=>({...e,...t})}function V(e){return Array.isArray(e)?e:[e]}function gn(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 An(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 Cn(e){let t=Object.assign({},e);return t.start?(t.start=Ke(t.start,{typeHint:"Canvas"}),t):e}function Rn(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[S]=!0),e}function In(e){let t=Be(e),n=$e(),i={},r=dn(n,t),a=vn(i),l=new q({collection:[Q,D(ne),a("Collection"),r("Collection")],manifest:[Q,D(ie),Cn,a("Manifest"),r("Manifest")],canvas:[D(te),a("Canvas"),r("Canvas")],annotationPage:[Q,ue("AnnotationPage"),D(ee),a("AnnotationPage"),r("AnnotationPage")],annotation:[ue("Annotation"),gn,Rn,a("Annotation"),r("Annotation")],contentResource:[ue("ContentResource"),a("ContentResource"),r("ContentResource")],range:[D(re),An,a("Range","Canvas"),r("Range","Canvas")],agent:[D(ae),a("Agent"),r("Agent")],specificResource:[Je],service:[hn(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 Sn(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 Pn(e){return e.type==="SpecificResource"}function _n(e){return e&&e.type==="FragmentSelector"}function xn(e){if(e&&Pn(e)){let t=e.id,n=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return _n(n)&&(t+="#"+n.value),t}return e?.id}var En={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":xn(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 Ln={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!==S),n=yield e.items;return[["id",e.id?.startsWith("vault://")?void 0:e.id],...t,...yield*L(e),["items",n.length||e[S]===!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!==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(_(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 Mn([...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 Mn(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 bn={};rt(bn,{EMPTY:()=>s,HAS_PART:()=>u,IS_EXTERNAL:()=>T,PART_OF:()=>C,Traverse:()=>q,UNSET:()=>y,UNWRAP:()=>G,WILDCARD:()=>N,addFlagForExternalResource:()=>Q,compressSpecificResource:()=>_,defaultEntities:()=>un,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:()=>In,resolveIfExists:()=>H,serialize:()=>Sn,serializeConfigPresentation2:()=>En,serializeConfigPresentation3:()=>Ln,serializedFieldsToObject:()=>Qe,toRef:()=>$,traverseSpecificResource:()=>Je,types:()=>oe});module.exports=st(bn);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 R(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=R(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=R(t.service).map(n=>this.traverseService(n))),t.services&&(t.services=R(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=R(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=R(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=R(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",St="http://iiif.io/api/image/2/level2.json",Tt="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,St,Tt,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",Se="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",Te="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,Se,Pe,Ee,Le,Ne,Oe,we],Xn=[...le,ze,ge,Ce,Ie,Te,_e,xe,Me,be,Fe],jt=[Dt,ze,ke,Lt,ge,Ae,Mt,Ce,Re,bt,Ie,Se,Nt,Te,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 I(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 S(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?R(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({...I(e),...S(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=I(e);return n.length&&(r.behavior?r.behavior.push(...n):r.behavior=n),m({...r,...S(e),...P(e),start:i,items:t,structures:tn(e.structures)})}function tn(e){if(!e)return e;let t=new Map;for(let i of e)t.set(i.id,i);let n=[];for(let i of e)if(i.items){let r=i.items.map(a=>typeof a=="string"?(n.push(a),t.get(a)||a):a&&a.id?(n.push(a.id),t.get(a.id)||a):a);i.items=r}return e.filter(i=>n.indexOf(i.id)===-1)}function nn(e){return m({...I(e),...S(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 rn(e){return m({...I(e),...S(e),...P(e),items:e.resources&&e.resources.length?e.resources:void 0})}function an(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}}function sn(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({...I(e),...S(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({...I(t),...S(t),...P(t),...Yt(t)})}function on(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({...I(e),...S(e),items:t})}function ln(e){return m({...I(e),...S(e),...P(e),items:e.members})}function cn(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 pn(e){return m({...I(e),...S(e),...P(e)})}var fn=new K({collection:[Zt],manifest:[en],canvas:[nn],annotationList:[rn],sequence:[an],annotation:[sn],contentResource:[We],choice:[on],range:[ln],service:[cn],layer:[pn]});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"?fn.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 un={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 dn(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 vn(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 yn(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 hn(e){return t=>{e.Service=e.Service?e.Service:{};let n=t.id||t["@id"],i=yn(t);return i&&i.id&&(e.Service[i.id]?e.Service[n]=Y(e.Service[n],i):e.Service[n]=i),t}}function mn(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://${mn(t)}`,type:e,...t}}function D(e){return t=>({...e,...t})}function V(e){return Array.isArray(e)?e:[e]}function gn(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 An(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 Cn(e){let t=Object.assign({},e);return t.start?(t.start=Ke(t.start,{typeHint:"Canvas"}),t):e}function Rn(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 In(e){let t=Be(e),n=$e(),i={},r=dn(n,t),a=vn(i),l=new q({collection:[Q,D(ne),a("Collection"),r("Collection")],manifest:[Q,D(ie),Cn,a("Manifest"),r("Manifest")],canvas:[D(te),a("Canvas"),r("Canvas")],annotationPage:[Q,ue("AnnotationPage"),D(ee),a("AnnotationPage"),r("AnnotationPage")],annotation:[ue("Annotation"),gn,Rn,a("Annotation"),r("Annotation")],contentResource:[ue("ContentResource"),a("ContentResource"),r("ContentResource")],range:[D(re),An,a("Range","Canvas"),r("Range","Canvas")],agent:[D(ae),a("Agent"),r("Agent")],specificResource:[Je],service:[hn(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 Sn(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 Pn(e){return e.type==="SpecificResource"}function _n(e){return e&&e.type==="FragmentSelector"}function xn(e){if(e&&Pn(e)){let t=e.id,n=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return _n(n)&&(t+="#"+n.value),t}return e?.id}var En={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":xn(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 Ln={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 Mn([...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 Mn(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 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 bn={};rt(bn,{EMPTY:()=>s,HAS_PART:()=>u,IS_EXTERNAL:()=>S,PART_OF:()=>C,Traverse:()=>q,UNSET:()=>y,UNWRAP:()=>G,WILDCARD:()=>N,addFlagForExternalResource:()=>Q,compressSpecificResource:()=>_,defaultEntities:()=>un,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:()=>In,resolveIfExists:()=>H,serialize:()=>Sn,serializeConfigPresentation2:()=>En,serializeConfigPresentation3:()=>Ln,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",S="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 T(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=T(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=T(t.service).map(n=>this.traverseService(n))),t.services&&(t.services=T(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=T(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=T(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",St="http://iiif.io/api/image/2/level2.json",Tt="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,St,Tt,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",Se="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",Te="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,Se,Pe,Ee,Le,Ne,Oe,we],Xn=[...le,ze,ge,Ce,Ie,Te,_e,xe,Me,be,Fe],jt=[Dt,ze,ke,Lt,ge,Ae,Mt,Ce,Re,bt,Ie,Se,Nt,Te,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?T(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:tn(e.structures)})}function tn(e){if(!e)return e;let t=new Map;for(let i of e)t.set(i.id,i);let n=[];for(let i of e)if(i.items){let r=i.items.map(a=>typeof a=="string"?(n.push(a),t.get(a)||a):a&&a.id?(n.push(a.id),t.get(a.id)||a):a);i.items=r}return e.filter(i=>n.indexOf(i.id)===-1)}function nn(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 rn(e){return m({...R(e),...I(e),...P(e),items:e.resources&&e.resources.length?e.resources:void 0})}function an(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}}function sn(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 on(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 ln(e){return m({...R(e),...I(e),...P(e),items:e.members})}function cn(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 pn(e){return m({...R(e),...I(e),...P(e)})}var fn=new K({collection:[Zt],manifest:[en],canvas:[nn],annotationList:[rn],sequence:[an],annotation:[sn],contentResource:[We],choice:[on],range:[ln],service:[cn],layer:[pn]});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"?fn.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 un={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 dn(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 vn(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 yn(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 hn(e){return t=>{e.Service=e.Service?e.Service:{};let n=t.id||t["@id"],i=yn(t);return i&&i.id&&(e.Service[i.id]?e.Service[n]=Y(e.Service[n],i):e.Service[n]=i),t}}function mn(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://${mn(t)}`,type:e,...t}}function D(e){return t=>({...e,...t})}function V(e){return Array.isArray(e)?e:[e]}function gn(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 An(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 Cn(e){let t=Object.assign({},e);return t.start?(t.start=Ke(t.start,{typeHint:"Canvas"}),t):e}function Rn(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[S]=!0),e}function In(e){let t=Be(e),n=$e(),i={},r=dn(n,t),a=vn(i),l=new q({collection:[Q,D(ne),a("Collection"),r("Collection")],manifest:[Q,D(ie),Cn,a("Manifest"),r("Manifest")],canvas:[D(te),a("Canvas"),r("Canvas")],annotationPage:[Q,ue("AnnotationPage"),D(ee),a("AnnotationPage"),r("AnnotationPage")],annotation:[ue("Annotation"),gn,Rn,a("Annotation"),r("Annotation")],contentResource:[ue("ContentResource"),a("ContentResource"),r("ContentResource")],range:[D(re),An,a("Range","Canvas"),r("Range","Canvas")],agent:[D(ae),a("Agent"),r("Agent")],specificResource:[Je],service:[hn(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 Sn(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 Pn(e){return e.type==="SpecificResource"}function _n(e){return e&&e.type==="FragmentSelector"}function xn(e){if(e&&Pn(e)){let t=e.id,n=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return _n(n)&&(t+="#"+n.value),t}return e?.id}var En={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":xn(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 Ln={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!==S),n=yield e.items;return[["id",e.id?.startsWith("vault://")?void 0:e.id],...t,...yield*L(e),["items",n.length||e[S]===!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!==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(_(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 Mn([...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 Mn(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 st(bn);})();
"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 bn={};rt(bn,{EMPTY:()=>s,HAS_PART:()=>u,IS_EXTERNAL:()=>T,PART_OF:()=>C,Traverse:()=>q,UNSET:()=>y,UNWRAP:()=>G,WILDCARD:()=>N,addFlagForExternalResource:()=>Q,compressSpecificResource:()=>_,defaultEntities:()=>un,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:()=>In,resolveIfExists:()=>H,serialize:()=>Sn,serializeConfigPresentation2:()=>En,serializeConfigPresentation3:()=>Ln,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 R(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=R(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=R(t.service).map(n=>this.traverseService(n))),t.services&&(t.services=R(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=R(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=R(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=R(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",St="http://iiif.io/api/image/2/level2.json",Tt="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,St,Tt,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",Se="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",Te="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,Se,Pe,Ee,Le,Ne,Oe,we],Xn=[...le,ze,ge,Ce,Ie,Te,_e,xe,Me,be,Fe],jt=[Dt,ze,ke,Lt,ge,Ae,Mt,Ce,Re,bt,Ie,Se,Nt,Te,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 I(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 S(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?R(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({...I(e),...S(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=I(e);return n.length&&(r.behavior?r.behavior.push(...n):r.behavior=n),m({...r,...S(e),...P(e),start:i,items:t,structures:tn(e.structures)})}function tn(e){if(!e)return e;let t=new Map;for(let i of e)t.set(i.id,i);let n=[];for(let i of e)if(i.items){let r=i.items.map(a=>typeof a=="string"?(n.push(a),t.get(a)||a):a&&a.id?(n.push(a.id),t.get(a.id)||a):a);i.items=r}return e.filter(i=>n.indexOf(i.id)===-1)}function nn(e){return m({...I(e),...S(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 rn(e){return m({...I(e),...S(e),...P(e),items:e.resources&&e.resources.length?e.resources:void 0})}function an(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}}function sn(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({...I(e),...S(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({...I(t),...S(t),...P(t),...Yt(t)})}function on(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({...I(e),...S(e),items:t})}function ln(e){return m({...I(e),...S(e),...P(e),items:e.members})}function cn(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 pn(e){return m({...I(e),...S(e),...P(e)})}var fn=new K({collection:[Zt],manifest:[en],canvas:[nn],annotationList:[rn],sequence:[an],annotation:[sn],contentResource:[We],choice:[on],range:[ln],service:[cn],layer:[pn]});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"?fn.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 un={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 dn(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 vn(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 yn(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 hn(e){return t=>{e.Service=e.Service?e.Service:{};let n=t.id||t["@id"],i=yn(t);return i&&i.id&&(e.Service[i.id]?e.Service[n]=Y(e.Service[n],i):e.Service[n]=i),t}}function mn(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://${mn(t)}`,type:e,...t}}function D(e){return t=>({...e,...t})}function V(e){return Array.isArray(e)?e:[e]}function gn(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 An(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 Cn(e){let t=Object.assign({},e);return t.start?(t.start=Ke(t.start,{typeHint:"Canvas"}),t):e}function Rn(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 In(e){let t=Be(e),n=$e(),i={},r=dn(n,t),a=vn(i),l=new q({collection:[Q,D(ne),a("Collection"),r("Collection")],manifest:[Q,D(ie),Cn,a("Manifest"),r("Manifest")],canvas:[D(te),a("Canvas"),r("Canvas")],annotationPage:[Q,ue("AnnotationPage"),D(ee),a("AnnotationPage"),r("AnnotationPage")],annotation:[ue("Annotation"),gn,Rn,a("Annotation"),r("Annotation")],contentResource:[ue("ContentResource"),a("ContentResource"),r("ContentResource")],range:[D(re),An,a("Range","Canvas"),r("Range","Canvas")],agent:[D(ae),a("Agent"),r("Agent")],specificResource:[Je],service:[hn(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 Sn(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 Pn(e){return e.type==="SpecificResource"}function _n(e){return e&&e.type==="FragmentSelector"}function xn(e){if(e&&Pn(e)){let t=e.id,n=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return _n(n)&&(t+="#"+n.value),t}return e?.id}var En={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":xn(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 Ln={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 Mn([...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 Mn(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(bn);})();

@@ -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-XVRUT7GK.js";import"./chunk-R2Q75YNZ.js";import"./chunk-5GMXZJIZ.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};
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-7YCHMFAA.js";import"./chunk-R2Q75YNZ.js";import"./chunk-5GMXZJIZ.js";import"./chunk-J657UVVW.js";import{a,b as u,c as v,d as w}from"./chunk-BCORR5FZ.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 c=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var x=(n,e,a)=>e in n?c(n,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):n[e]=a;var L=(n,e)=>{for(var a in e)c(n,a,{get:e[a],enumerable:!0})},k=(n,e,a,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of S(e))!M.call(n,r)&&r!==a&&c(n,r,{get:()=>e[r],enumerable:!(t=I(e,r))||t.enumerable});return n};var D=n=>k(c({},"__esModule",{value:!0}),n);var o=(n,e,a)=>(x(n,typeof e!="symbol"?e+"":e,a),a);var N={};L(N,{presentation3StrictUpgrade:()=>G});module.exports=D(N);function d(n){return typeof n=="string"?!1:!!n&&n.type==="SpecificResource"}function l(n){return Array.isArray(n)?n:n?[n]:[]}function f(...n){return e=>n.reduce((a,t)=>t(a),e)}var R=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function $(n,e){if(typeof n>"u"||n===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(n))throw new Error("Array is not a valid entity");if(typeof n!="object"){if(e)return e;throw new Error(`${typeof n} is not a valid entity`)}if(typeof n.type=="string"){let a=R.indexOf(n.type);if(a!==-1)return R[a]}if(n.profile)return"Service";throw new Error("Resource type is not known")}var y=class n{constructor(e,a={}){o(this,"traversals");o(this,"options");o(this,"_traverseManifest",f(this.traverseManifestItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseManifestStructures.bind(this),this.traverseInlineAnnotationPages.bind(this)));o(this,"_traverseCanvas",f(this.traverseCanvasItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseInlineAnnotationPages.bind(this)));o(this,"_traverseAnnotationPage",f(this.traverseAnnotationPageItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this)));o(this,"_traverseRange",f(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:[],...e},this.options={allowUndefinedReturn:!1,...a}}static all(e){return new n({collection:[e],manifest:[e],canvas:[e],annotationCollection:[e],annotationPage:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],geoJson:[e],specificResource:[e],agent:[e]})}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=l(e.thumbnail).map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e.provider&&(e.provider=e.provider.map(a=>this.traverseAgent(a,e))),e}traverseLinking(e){return e.seeAlso&&(e.seeAlso=e.seeAlso.map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e.service&&(e.service=l(e.service).map(a=>this.traverseService(a))),e.services&&(e.services=l(e.services).map(a=>this.traverseService(a,e))),e.logo&&(e.logo=e.logo.map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e.homepage&&(e.homepage=e.homepage.map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e.partOf&&(e.partOf=e.partOf.map(a=>typeof a=="string"||!a.type?this.traverseType(a,{parent:e},this.traversals.contentResource):a.type==="Canvas"?this.traverseType(a,{parent:e},this.traversals.canvas):a.type==="AnnotationCollection"?this.traverseType(a,{parent:e},this.traversals.annotationCollection):a.type==="Collection"?this.traverseType(a,{parent:e},this.traversals.collection):this.traverseType(a,{parent:e},this.traversals.contentResource))),e.start&&(d(e.start)?e.start=this.traverseSpecificResource(e.start,"Canvas",e):e.start=this.traverseType(e.start,{parent:e},this.traversals.canvas)),e.rendering&&(e.rendering=e.rendering.map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e.supplementary&&(e.supplementary=e.supplementary.map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e}traverseCollectionItems(e){return e.items&&e.items.map(a=>a.type==="Collection"?this.traverseCollection(a):this.traverseManifest(a)),e}traverseCollection(e,a){return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traverseLinkedCanvases(this.traverseCollectionItems(e))))),{parent:a},this.traversals.collection)}traverseGeoJson(e,a){return this.traverseType(e,{parent:a},this.traversals.geoJson)}traverseNavPlace(e){return e.navPlace&&(e.navPlace=this.traverseGeoJson(e.navPlace,e)),e}traverseManifestItems(e){return e.items&&(e.items=e.items.map(a=>this.traverseCanvas(a))),e}traverseManifestStructures(e){return e.structures&&(e.structures=e.structures.map(a=>this.traverseRange(a))),e}traverseManifest(e,a){return this.traverseType(this._traverseManifest(e),{parent:a},this.traversals.manifest)}traverseCanvasItems(e){return e.items=(e.items||[]).map(a=>this.traverseAnnotationPage(a,e)),e}traverseInlineAnnotationPages(e){return typeof e=="string"||!e||e.annotations&&(e.annotations=e.annotations.map(a=>this.traverseAnnotationPage(a,e))),e}traverseCanvas(e,a){return this.traverseType(this._traverseCanvas(e),{parent:a},this.traversals.canvas)}traverseAnnotationPageItems(e){return e.items&&(e.items=e.items.map(a=>this.traverseAnnotation(a,e))),e}traverseAnnotationPage(e,a){return this.traverseType(this._traverseAnnotationPage(e),{parent:a},this.traversals.annotationPage)}traverseAnnotationBody(e){return Array.isArray(e.body)?e.body=e.body.map(a=>this.traverseContentResource(a,e)):e.body&&(e.body=this.traverseContentResource(e.body,e)),e}traverseLinkedCanvases(e){return e.placeholderCanvas&&(e.placeholderCanvas=this.traverseCanvas(e.placeholderCanvas)),e.accompanyingCanvas&&(e.accompanyingCanvas=this.traverseCanvas(e.accompanyingCanvas)),e}traverseAnnotation(e,a){return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(this.traverseDescriptive(e))),{parent:a},this.traversals.annotation)}traverseContentResourceLinking(e){return typeof e=="string"||!e||e&&e.service&&(e.service=l(e.service||[]).map(a=>this.traverseService(a,e))),e}traverseContentResource(e,a){return e.type==="Choice"&&(e.items=e.items.map(t=>this.traverseContentResource(t,e))),d(e)?this.traverseSpecificResource(e,"ContentResource"):this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)),{parent:a},this.traversals.contentResource)}traverseSpecificResource(e,a,t){let r=e.source;return typeof e.source=="string"&&(r={id:e.source,type:a||"unknown"}),this.traverseType({...e,source:a==="Canvas"||r.type==="Canvas"?this.traverseType(r,{parent:t},this.traversals.canvas):a==="ContentResource"?this.traverseContentResource(r,{parent:t}):this.traverseUnknown(r,{parent:t,typeHint:a})},{parent:t},this.traversals.specificResource)}traverseRangeRanges(e){return e.items&&(e.items=e.items.map(a=>typeof a=="string"?this.traverseCanvas({id:a,type:"Canvas"},e):d(a)?this.traverseSpecificResource(a,"Canvas",e):a.type==="Manifest"?this.traverseManifest(a,e):this.traverseRange(a,e))),e}traverseRange(e,a){return this.traverseType(this._traverseRange(e),{parent:a},this.traversals.range)}traverseAgent(e,a){return this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),{parent:a},this.traversals.agent)}traverseType(e,a,t){return t.reduce((r,v)=>{let h=v(r,a);return typeof h>"u"&&!this.options.allowUndefinedReturn?r:h},e)}traverseService(e,a){let t=Object.assign({},e);return t&&t.service&&(t.service=l(t.service).map(r=>this.traverseService(r))),this.traverseType(t,{parent:a},this.traversals.service)}traverseUnknown(e,{parent:a,typeHint:t}={}){let r=$(e,t);switch(r){case"Collection":return this.traverseCollection(e,a);case"Manifest":return this.traverseManifest(e,a);case"Canvas":return this.traverseCanvas(e,a);case"AnnotationPage":return this.traverseAnnotationPage(e,a);case"Annotation":return this.traverseAnnotation(e,a);case"ContentResource":return this.traverseContentResource(e,a);case"Range":return this.traverseRange(e,a);case"Service":return this.traverseService(e,a);case"Agent":return this.traverseAgent(e,a);default:throw new Error(`Unknown or unsupported resource type of ${r}`)}}};function P(n){for(let e in n)(typeof n[e]>"u"||n[e]===null)&&delete n[e];return n}var U=/-?([1-9]\d{3,}|0\d{3})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])T(([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d+)?|(24:00:00(\.0+)?))(Z|(\+|-)((0\d|1[0-3]):[0-5]\d|14:00))?/,i={warnings:[]};function E(n,e=i){return n.behavior&&(n.behavior=s(n.behavior,"behavior",e)),n.width=C(n.width,"width",!1,e),n.height=C(n.height,"height",!1,e),n.duration=C(n.duration,"duration",!0,e),n.format&&typeof n.format!="string"&&(e.warnings.push('"format" should be a single string'),Array.isArray(n.format)&&typeof n.format[0]=="string"?n.format=n.format[0]:n.format=void 0),n}function m(n,e,a=i){return n&&Array.isArray(n)?n.filter(t=>{let r=e(t);return r&&a.warnings.indexOf(r)===-1&&a.warnings.push(r),!r}):n}function s(n,e,a=i){return Array.isArray(n)?n:(a.warnings.push(`"${e}" should be Array of values`),[n])}function A(n,e,a=i){return Array.isArray(n)?(a.warnings.push(`"${e}" should only contain a single value`),n.length===0?void 0:n[0]):n}function C(n,e,a=!1,t=i){if(!(typeof n>"u")){if(typeof n=="string"){let r=a?parseFloat(n):Math.abs(Number(n));if(Number.isNaN(r)||r<=0){t.warnings.push(`"${e}" expected value to be a ${a?"Number":"Integer"}, instead found an invalid value`);return}return t.warnings.push(`"${e}" expected value to be a ${a?"Number":"Integer"}, instead found a string`),r}return!a&&n%1!==0?(t.warnings.push(`"${e}" expected value to be a Integer, instead found a Float`),Math.floor(n)):n}}function g(n,e,a=i){if(Array.isArray(n))return typeof n[0]=="string"?(a.warnings.push(`"${e}" should be a language map instead found a string`),{none:n}):(a.warnings.push(`"${e}" should be a language map instead found an unknown value`),{none:[""]});if(typeof n=="string")return a.warnings.push(`"${e}" should be a language map instead found a string`),{none:[n]};let t=Object.keys(n),r={},v=!1;for(let h of t){let p=n[h],u=[];if(typeof p=="string")v=!0,a.warnings.push(`"${e}" values inside a language map should be an Array of strings, found a string`),u.push(p);else if(Array.isArray(p))for(let T of p)typeof T!="string"?(v=!0,a.warnings.push(`"${e}" values inside a language map should be an Array of strings, found an unknown value`)):u.push(T);else v=!0,a.warnings.push(`"${e}" values inside a language map should be an Array of strings, found an unknown value`);u.length>0&&(r[h]=u)}return v?Object.keys(r).length===0?{none:[""]}:r:n}function b(n,e,a="",t=i){return typeof n=="string"?(t.warnings.push(`"${e}" should be a {label, value} set of Language maps`),{label:{none:[a]},value:{none:[n]}}):((!n.label&&n.value||n.label&&!n.value)&&t.warnings.push(`"${e}" should have both a label and a value`),n.label?n.label=g(n.label,`${e}.label`,t):n.label={none:[a]},n.value?n.value=g(n.value,`${e}.value`,t):n.value={none:[""]},n)}function W(n,e=i){if(n.label&&(n.label=g(n.label,"label",e)),n.summary&&(n.summary=g(n.summary,"summary",e)),n.requiredStatement&&(n.requiredStatement=b(n.requiredStatement,"requiredStatement","Required statement",e)),n.metadata)if(Array.isArray(n.metadata))for(let a=0;a<n.metadata.length;a++)n.metadata[a]=b(n.metadata[a],`metadata.${a}`,"",e);else e.warnings.push('"metadata" should be an array of {label, value} Language maps'),n.metadata=[];if(n.rights&&(Array.isArray(n.rights)&&(e.warnings.push('"rights" should only contain a single string'),n.rights=typeof n.rights[0]=="string"?n.rights[0]:""),typeof n.rights=="string"&&!n.rights.startsWith("http")?e.warnings.push('"rights" should be a valid URI'):typeof n.rights=="string"&&n.rights.startsWith("https")&&(e.warnings.push('"rights" is an informative property and should contain the http variation of the rights statement'),n.rights=`http${n.rights.slice(5)}`)),n.navDate){let a=typeof n.navDate=="string"?n.navDate.trim():void 0;a!==n.navDate&&(e.warnings.push('"navDate" should not contain extra whitespace'),n.navDate=a),(typeof n.navDate!="string"||!n.navDate.match(U))&&(e.warnings.push('"navDate" should be a valid XSD dateTime literal'),n.navDate=void 0)}return n.language&&(n.language=s(n.language,"language",e),n.language=m(n.language,a=>typeof a=="string"?void 0:`'"language" expected array of strings`,e)),n.accompanyingCanvas&&(n.accompanyingCanvas=A(n.accompanyingCanvas,"accompanyingCanvas",e),n.accompanyingCanvas?.type!=="Canvas"&&e.warnings.push('"accompanyingCanvas" should be a Canvas')),n.placeholderCanvas&&(n.placeholderCanvas=A(n.placeholderCanvas,"placeholderCanvas",e),n.placeholderCanvas?.type!=="Canvas"&&e.warnings.push('"placeholderCanvas" should be a Canvas')),n.thumbnail&&(n.thumbnail=s(n.thumbnail,"thumbnail",e)),n}var w={Manifest:"Canvas",Canvas:"AnnotationPage",AnnotationPage:"Annotation"};function _(n,e=i){let a=n.type;switch(a){case"Canvas":case"AnnotationPage":case"Manifest":n&&n.items&&(n.items=m(n.items,t=>t.type===w[a]?void 0:`"${n.type}.items" should contain only type ${w[a]}, found ${t.type}`,e))}return n}function q(n,e=i){return n.logo&&(n.logo=s(n.logo,"logo",e)),n.service&&(n.service=s(n.service,"service",e)),n.seeAlso&&(n.seeAlso=s(n.seeAlso,"seeAlso",e)),n.rendering&&(n.rendering=s(n.rendering,"rendering",e)),n.partOf&&(n.partOf=s(n.partOf,"partOf",e)),n.homepage&&(n.homepage=s(n.homepage,"homepage",e)),n.services&&(n.services=s(n.services,"services",e)),n.supplementary&&(n.supplementary=s(n.supplementary,"supplementary",e)),n.start&&(n.start=A(n.start,"start",e)),n}function B(n){return e=>{if(e)return typeof e=="string"||Array.isArray(e)?e:P({...e,...E(e,n),...W(e,n),...q(e,n),..._(e,n)})}}function G(n,e=i){return y.all(B(e)).traverseManifest(n)}
"use strict";var c=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var x=(n,e,a)=>e in n?c(n,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):n[e]=a;var L=(n,e)=>{for(var a in e)c(n,a,{get:e[a],enumerable:!0})},k=(n,e,a,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of S(e))!M.call(n,r)&&r!==a&&c(n,r,{get:()=>e[r],enumerable:!(t=I(e,r))||t.enumerable});return n};var D=n=>k(c({},"__esModule",{value:!0}),n);var o=(n,e,a)=>(x(n,typeof e!="symbol"?e+"":e,a),a);var N={};L(N,{presentation3StrictUpgrade:()=>G});module.exports=D(N);function d(n){return typeof n=="string"?!1:!!n&&n.type==="SpecificResource"}function v(n){return Array.isArray(n)?n:n?[n]:[]}function f(...n){return e=>n.reduce((a,t)=>t(a),e)}var R=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function $(n,e){if(typeof n>"u"||n===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(n))throw new Error("Array is not a valid entity");if(typeof n!="object"){if(e)return e;throw new Error(`${typeof n} is not a valid entity`)}if(typeof n.type=="string"){let a=R.indexOf(n.type);if(a!==-1)return R[a]}if(n.profile)return"Service";throw new Error("Resource type is not known")}var y=class n{constructor(e,a={}){o(this,"traversals");o(this,"options");o(this,"_traverseManifest",f(this.traverseManifestItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseManifestStructures.bind(this),this.traverseInlineAnnotationPages.bind(this)));o(this,"_traverseCanvas",f(this.traverseCanvasItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseInlineAnnotationPages.bind(this)));o(this,"_traverseAnnotationPage",f(this.traverseAnnotationPageItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this)));o(this,"_traverseRange",f(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:[],...e},this.options={allowUndefinedReturn:!1,...a}}static all(e){return new n({collection:[e],manifest:[e],canvas:[e],annotationCollection:[e],annotationPage:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],geoJson:[e],specificResource:[e],agent:[e]})}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=v(e.thumbnail).map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e.provider&&(e.provider=e.provider.map(a=>this.traverseAgent(a,e))),e}traverseLinking(e){return e.seeAlso&&(e.seeAlso=e.seeAlso.map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e.service&&(e.service=v(e.service).map(a=>this.traverseService(a))),e.services&&(e.services=v(e.services).map(a=>this.traverseService(a,e))),e.logo&&(e.logo=e.logo.map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e.homepage&&(e.homepage=v(e.homepage).map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e.partOf&&(e.partOf=e.partOf.map(a=>typeof a=="string"||!a.type?this.traverseType(a,{parent:e},this.traversals.contentResource):a.type==="Canvas"?this.traverseType(a,{parent:e},this.traversals.canvas):a.type==="AnnotationCollection"?this.traverseType(a,{parent:e},this.traversals.annotationCollection):a.type==="Collection"?this.traverseType(a,{parent:e},this.traversals.collection):this.traverseType(a,{parent:e},this.traversals.contentResource))),e.start&&(d(e.start)?e.start=this.traverseSpecificResource(e.start,"Canvas",e):e.start=this.traverseType(e.start,{parent:e},this.traversals.canvas)),e.rendering&&(e.rendering=e.rendering.map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e.supplementary&&(e.supplementary=e.supplementary.map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e}traverseCollectionItems(e){return e.items&&e.items.map(a=>a.type==="Collection"?this.traverseCollection(a):this.traverseManifest(a)),e}traverseCollection(e,a){return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traverseLinkedCanvases(this.traverseCollectionItems(e))))),{parent:a},this.traversals.collection)}traverseGeoJson(e,a){return this.traverseType(e,{parent:a},this.traversals.geoJson)}traverseNavPlace(e){return e.navPlace&&(e.navPlace=this.traverseGeoJson(e.navPlace,e)),e}traverseManifestItems(e){return e.items&&(e.items=e.items.map(a=>this.traverseCanvas(a))),e}traverseManifestStructures(e){return e.structures&&(e.structures=e.structures.map(a=>this.traverseRange(a))),e}traverseManifest(e,a){return this.traverseType(this._traverseManifest(e),{parent:a},this.traversals.manifest)}traverseCanvasItems(e){return e.items=(e.items||[]).map(a=>this.traverseAnnotationPage(a,e)),e}traverseInlineAnnotationPages(e){return typeof e=="string"||!e||e.annotations&&(e.annotations=e.annotations.map(a=>this.traverseAnnotationPage(a,e))),e}traverseCanvas(e,a){return this.traverseType(this._traverseCanvas(e),{parent:a},this.traversals.canvas)}traverseAnnotationPageItems(e){return e.items&&(e.items=e.items.map(a=>this.traverseAnnotation(a,e))),e}traverseAnnotationPage(e,a){return this.traverseType(this._traverseAnnotationPage(e),{parent:a},this.traversals.annotationPage)}traverseAnnotationBody(e){return Array.isArray(e.body)?e.body=e.body.map(a=>this.traverseContentResource(a,e)):e.body&&(e.body=this.traverseContentResource(e.body,e)),e}traverseLinkedCanvases(e){return e.placeholderCanvas&&(e.placeholderCanvas=this.traverseCanvas(e.placeholderCanvas)),e.accompanyingCanvas&&(e.accompanyingCanvas=this.traverseCanvas(e.accompanyingCanvas)),e}traverseAnnotation(e,a){return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(this.traverseDescriptive(e))),{parent:a},this.traversals.annotation)}traverseContentResourceLinking(e){return typeof e=="string"||!e||e&&e.service&&(e.service=v(e.service||[]).map(a=>this.traverseService(a,e))),e}traverseContentResource(e,a){return e.type==="Choice"&&(e.items=e.items.map(t=>this.traverseContentResource(t,e))),d(e)?this.traverseSpecificResource(e,"ContentResource"):this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)),{parent:a},this.traversals.contentResource)}traverseSpecificResource(e,a,t){let r=e.source;return typeof e.source=="string"&&(r={id:e.source,type:a||"unknown"}),this.traverseType({...e,source:a==="Canvas"||r.type==="Canvas"?this.traverseType(r,{parent:t},this.traversals.canvas):a==="ContentResource"?this.traverseContentResource(r,{parent:t}):this.traverseUnknown(r,{parent:t,typeHint:a})},{parent:t},this.traversals.specificResource)}traverseRangeRanges(e){return e.items&&(e.items=e.items.map(a=>typeof a=="string"?this.traverseCanvas({id:a,type:"Canvas"},e):d(a)?this.traverseSpecificResource(a,"Canvas",e):a.type==="Manifest"?this.traverseManifest(a,e):this.traverseRange(a,e))),e}traverseRange(e,a){return this.traverseType(this._traverseRange(e),{parent:a},this.traversals.range)}traverseAgent(e,a){return this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),{parent:a},this.traversals.agent)}traverseType(e,a,t){return t.reduce((r,l)=>{let h=l(r,a);return typeof h>"u"&&!this.options.allowUndefinedReturn?r:h},e)}traverseService(e,a){let t=Object.assign({},e);return t&&t.service&&(t.service=v(t.service).map(r=>this.traverseService(r))),this.traverseType(t,{parent:a},this.traversals.service)}traverseUnknown(e,{parent:a,typeHint:t}={}){let r=$(e,t);switch(r){case"Collection":return this.traverseCollection(e,a);case"Manifest":return this.traverseManifest(e,a);case"Canvas":return this.traverseCanvas(e,a);case"AnnotationPage":return this.traverseAnnotationPage(e,a);case"Annotation":return this.traverseAnnotation(e,a);case"ContentResource":return this.traverseContentResource(e,a);case"Range":return this.traverseRange(e,a);case"Service":return this.traverseService(e,a);case"Agent":return this.traverseAgent(e,a);default:throw new Error(`Unknown or unsupported resource type of ${r}`)}}};function P(n){for(let e in n)(typeof n[e]>"u"||n[e]===null)&&delete n[e];return n}var U=/-?([1-9]\d{3,}|0\d{3})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])T(([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d+)?|(24:00:00(\.0+)?))(Z|(\+|-)((0\d|1[0-3]):[0-5]\d|14:00))?/,i={warnings:[]};function E(n,e=i){return n.behavior&&(n.behavior=s(n.behavior,"behavior",e)),n.width=C(n.width,"width",!1,e),n.height=C(n.height,"height",!1,e),n.duration=C(n.duration,"duration",!0,e),n.format&&typeof n.format!="string"&&(e.warnings.push('"format" should be a single string'),Array.isArray(n.format)&&typeof n.format[0]=="string"?n.format=n.format[0]:n.format=void 0),n}function m(n,e,a=i){return n&&Array.isArray(n)?n.filter(t=>{let r=e(t);return r&&a.warnings.indexOf(r)===-1&&a.warnings.push(r),!r}):n}function s(n,e,a=i){return Array.isArray(n)?n:(a.warnings.push(`"${e}" should be Array of values`),[n])}function A(n,e,a=i){return Array.isArray(n)?(a.warnings.push(`"${e}" should only contain a single value`),n.length===0?void 0:n[0]):n}function C(n,e,a=!1,t=i){if(!(typeof n>"u")){if(typeof n=="string"){let r=a?parseFloat(n):Math.abs(Number(n));if(Number.isNaN(r)||r<=0){t.warnings.push(`"${e}" expected value to be a ${a?"Number":"Integer"}, instead found an invalid value`);return}return t.warnings.push(`"${e}" expected value to be a ${a?"Number":"Integer"}, instead found a string`),r}return!a&&n%1!==0?(t.warnings.push(`"${e}" expected value to be a Integer, instead found a Float`),Math.floor(n)):n}}function g(n,e,a=i){if(Array.isArray(n))return typeof n[0]=="string"?(a.warnings.push(`"${e}" should be a language map instead found a string`),{none:n}):(a.warnings.push(`"${e}" should be a language map instead found an unknown value`),{none:[""]});if(typeof n=="string")return a.warnings.push(`"${e}" should be a language map instead found a string`),{none:[n]};let t=Object.keys(n),r={},l=!1;for(let h of t){let p=n[h],u=[];if(typeof p=="string")l=!0,a.warnings.push(`"${e}" values inside a language map should be an Array of strings, found a string`),u.push(p);else if(Array.isArray(p))for(let T of p)typeof T!="string"?(l=!0,a.warnings.push(`"${e}" values inside a language map should be an Array of strings, found an unknown value`)):u.push(T);else l=!0,a.warnings.push(`"${e}" values inside a language map should be an Array of strings, found an unknown value`);u.length>0&&(r[h]=u)}return l?Object.keys(r).length===0?{none:[""]}:r:n}function b(n,e,a="",t=i){return typeof n=="string"?(t.warnings.push(`"${e}" should be a {label, value} set of Language maps`),{label:{none:[a]},value:{none:[n]}}):((!n.label&&n.value||n.label&&!n.value)&&t.warnings.push(`"${e}" should have both a label and a value`),n.label?n.label=g(n.label,`${e}.label`,t):n.label={none:[a]},n.value?n.value=g(n.value,`${e}.value`,t):n.value={none:[""]},n)}function W(n,e=i){if(n.label&&(n.label=g(n.label,"label",e)),n.summary&&(n.summary=g(n.summary,"summary",e)),n.requiredStatement&&(n.requiredStatement=b(n.requiredStatement,"requiredStatement","Required statement",e)),n.metadata)if(Array.isArray(n.metadata))for(let a=0;a<n.metadata.length;a++)n.metadata[a]=b(n.metadata[a],`metadata.${a}`,"",e);else e.warnings.push('"metadata" should be an array of {label, value} Language maps'),n.metadata=[];if(n.rights&&(Array.isArray(n.rights)&&(e.warnings.push('"rights" should only contain a single string'),n.rights=typeof n.rights[0]=="string"?n.rights[0]:""),typeof n.rights=="string"&&!n.rights.startsWith("http")?e.warnings.push('"rights" should be a valid URI'):typeof n.rights=="string"&&n.rights.startsWith("https")&&(e.warnings.push('"rights" is an informative property and should contain the http variation of the rights statement'),n.rights=`http${n.rights.slice(5)}`)),n.navDate){let a=typeof n.navDate=="string"?n.navDate.trim():void 0;a!==n.navDate&&(e.warnings.push('"navDate" should not contain extra whitespace'),n.navDate=a),(typeof n.navDate!="string"||!n.navDate.match(U))&&(e.warnings.push('"navDate" should be a valid XSD dateTime literal'),n.navDate=void 0)}return n.language&&(n.language=s(n.language,"language",e),n.language=m(n.language,a=>typeof a=="string"?void 0:`'"language" expected array of strings`,e)),n.accompanyingCanvas&&(n.accompanyingCanvas=A(n.accompanyingCanvas,"accompanyingCanvas",e),n.accompanyingCanvas?.type!=="Canvas"&&e.warnings.push('"accompanyingCanvas" should be a Canvas')),n.placeholderCanvas&&(n.placeholderCanvas=A(n.placeholderCanvas,"placeholderCanvas",e),n.placeholderCanvas?.type!=="Canvas"&&e.warnings.push('"placeholderCanvas" should be a Canvas')),n.thumbnail&&(n.thumbnail=s(n.thumbnail,"thumbnail",e)),n}var w={Manifest:"Canvas",Canvas:"AnnotationPage",AnnotationPage:"Annotation"};function _(n,e=i){let a=n.type;switch(a){case"Canvas":case"AnnotationPage":case"Manifest":n&&n.items&&(n.items=m(n.items,t=>t.type===w[a]?void 0:`"${n.type}.items" should contain only type ${w[a]}, found ${t.type}`,e))}return n}function q(n,e=i){return n.logo&&(n.logo=s(n.logo,"logo",e)),n.service&&(n.service=s(n.service,"service",e)),n.seeAlso&&(n.seeAlso=s(n.seeAlso,"seeAlso",e)),n.rendering&&(n.rendering=s(n.rendering,"rendering",e)),n.partOf&&(n.partOf=s(n.partOf,"partOf",e)),n.homepage&&(n.homepage=s(n.homepage,"homepage",e)),n.services&&(n.services=s(n.services,"services",e)),n.supplementary&&(n.supplementary=s(n.supplementary,"supplementary",e)),n.start&&(n.start=A(n.start,"start",e)),n}function B(n){return e=>{if(e)return typeof e=="string"||Array.isArray(e)?e:P({...e,...E(e,n),...W(e,n),...q(e,n),..._(e,n)})}}function G(n,e=i){return y.all(B(e)).traverseManifest(n)}

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

"use strict";var IIIFParser=(()=>{var c=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var x=(n,e,a)=>e in n?c(n,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):n[e]=a;var L=(n,e)=>{for(var a in e)c(n,a,{get:e[a],enumerable:!0})},k=(n,e,a,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of S(e))!M.call(n,r)&&r!==a&&c(n,r,{get:()=>e[r],enumerable:!(t=I(e,r))||t.enumerable});return n};var D=n=>k(c({},"__esModule",{value:!0}),n);var o=(n,e,a)=>(x(n,typeof e!="symbol"?e+"":e,a),a);var N={};L(N,{presentation3StrictUpgrade:()=>G});function d(n){return typeof n=="string"?!1:!!n&&n.type==="SpecificResource"}function l(n){return Array.isArray(n)?n:n?[n]:[]}function f(...n){return e=>n.reduce((a,t)=>t(a),e)}var R=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function $(n,e){if(typeof n>"u"||n===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(n))throw new Error("Array is not a valid entity");if(typeof n!="object"){if(e)return e;throw new Error(`${typeof n} is not a valid entity`)}if(typeof n.type=="string"){let a=R.indexOf(n.type);if(a!==-1)return R[a]}if(n.profile)return"Service";throw new Error("Resource type is not known")}var y=class n{constructor(e,a={}){o(this,"traversals");o(this,"options");o(this,"_traverseManifest",f(this.traverseManifestItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseManifestStructures.bind(this),this.traverseInlineAnnotationPages.bind(this)));o(this,"_traverseCanvas",f(this.traverseCanvasItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseInlineAnnotationPages.bind(this)));o(this,"_traverseAnnotationPage",f(this.traverseAnnotationPageItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this)));o(this,"_traverseRange",f(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:[],...e},this.options={allowUndefinedReturn:!1,...a}}static all(e){return new n({collection:[e],manifest:[e],canvas:[e],annotationCollection:[e],annotationPage:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],geoJson:[e],specificResource:[e],agent:[e]})}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=l(e.thumbnail).map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e.provider&&(e.provider=e.provider.map(a=>this.traverseAgent(a,e))),e}traverseLinking(e){return e.seeAlso&&(e.seeAlso=e.seeAlso.map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e.service&&(e.service=l(e.service).map(a=>this.traverseService(a))),e.services&&(e.services=l(e.services).map(a=>this.traverseService(a,e))),e.logo&&(e.logo=e.logo.map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e.homepage&&(e.homepage=e.homepage.map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e.partOf&&(e.partOf=e.partOf.map(a=>typeof a=="string"||!a.type?this.traverseType(a,{parent:e},this.traversals.contentResource):a.type==="Canvas"?this.traverseType(a,{parent:e},this.traversals.canvas):a.type==="AnnotationCollection"?this.traverseType(a,{parent:e},this.traversals.annotationCollection):a.type==="Collection"?this.traverseType(a,{parent:e},this.traversals.collection):this.traverseType(a,{parent:e},this.traversals.contentResource))),e.start&&(d(e.start)?e.start=this.traverseSpecificResource(e.start,"Canvas",e):e.start=this.traverseType(e.start,{parent:e},this.traversals.canvas)),e.rendering&&(e.rendering=e.rendering.map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e.supplementary&&(e.supplementary=e.supplementary.map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e}traverseCollectionItems(e){return e.items&&e.items.map(a=>a.type==="Collection"?this.traverseCollection(a):this.traverseManifest(a)),e}traverseCollection(e,a){return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traverseLinkedCanvases(this.traverseCollectionItems(e))))),{parent:a},this.traversals.collection)}traverseGeoJson(e,a){return this.traverseType(e,{parent:a},this.traversals.geoJson)}traverseNavPlace(e){return e.navPlace&&(e.navPlace=this.traverseGeoJson(e.navPlace,e)),e}traverseManifestItems(e){return e.items&&(e.items=e.items.map(a=>this.traverseCanvas(a))),e}traverseManifestStructures(e){return e.structures&&(e.structures=e.structures.map(a=>this.traverseRange(a))),e}traverseManifest(e,a){return this.traverseType(this._traverseManifest(e),{parent:a},this.traversals.manifest)}traverseCanvasItems(e){return e.items=(e.items||[]).map(a=>this.traverseAnnotationPage(a,e)),e}traverseInlineAnnotationPages(e){return typeof e=="string"||!e||e.annotations&&(e.annotations=e.annotations.map(a=>this.traverseAnnotationPage(a,e))),e}traverseCanvas(e,a){return this.traverseType(this._traverseCanvas(e),{parent:a},this.traversals.canvas)}traverseAnnotationPageItems(e){return e.items&&(e.items=e.items.map(a=>this.traverseAnnotation(a,e))),e}traverseAnnotationPage(e,a){return this.traverseType(this._traverseAnnotationPage(e),{parent:a},this.traversals.annotationPage)}traverseAnnotationBody(e){return Array.isArray(e.body)?e.body=e.body.map(a=>this.traverseContentResource(a,e)):e.body&&(e.body=this.traverseContentResource(e.body,e)),e}traverseLinkedCanvases(e){return e.placeholderCanvas&&(e.placeholderCanvas=this.traverseCanvas(e.placeholderCanvas)),e.accompanyingCanvas&&(e.accompanyingCanvas=this.traverseCanvas(e.accompanyingCanvas)),e}traverseAnnotation(e,a){return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(this.traverseDescriptive(e))),{parent:a},this.traversals.annotation)}traverseContentResourceLinking(e){return typeof e=="string"||!e||e&&e.service&&(e.service=l(e.service||[]).map(a=>this.traverseService(a,e))),e}traverseContentResource(e,a){return e.type==="Choice"&&(e.items=e.items.map(t=>this.traverseContentResource(t,e))),d(e)?this.traverseSpecificResource(e,"ContentResource"):this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)),{parent:a},this.traversals.contentResource)}traverseSpecificResource(e,a,t){let r=e.source;return typeof e.source=="string"&&(r={id:e.source,type:a||"unknown"}),this.traverseType({...e,source:a==="Canvas"||r.type==="Canvas"?this.traverseType(r,{parent:t},this.traversals.canvas):a==="ContentResource"?this.traverseContentResource(r,{parent:t}):this.traverseUnknown(r,{parent:t,typeHint:a})},{parent:t},this.traversals.specificResource)}traverseRangeRanges(e){return e.items&&(e.items=e.items.map(a=>typeof a=="string"?this.traverseCanvas({id:a,type:"Canvas"},e):d(a)?this.traverseSpecificResource(a,"Canvas",e):a.type==="Manifest"?this.traverseManifest(a,e):this.traverseRange(a,e))),e}traverseRange(e,a){return this.traverseType(this._traverseRange(e),{parent:a},this.traversals.range)}traverseAgent(e,a){return this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),{parent:a},this.traversals.agent)}traverseType(e,a,t){return t.reduce((r,v)=>{let h=v(r,a);return typeof h>"u"&&!this.options.allowUndefinedReturn?r:h},e)}traverseService(e,a){let t=Object.assign({},e);return t&&t.service&&(t.service=l(t.service).map(r=>this.traverseService(r))),this.traverseType(t,{parent:a},this.traversals.service)}traverseUnknown(e,{parent:a,typeHint:t}={}){let r=$(e,t);switch(r){case"Collection":return this.traverseCollection(e,a);case"Manifest":return this.traverseManifest(e,a);case"Canvas":return this.traverseCanvas(e,a);case"AnnotationPage":return this.traverseAnnotationPage(e,a);case"Annotation":return this.traverseAnnotation(e,a);case"ContentResource":return this.traverseContentResource(e,a);case"Range":return this.traverseRange(e,a);case"Service":return this.traverseService(e,a);case"Agent":return this.traverseAgent(e,a);default:throw new Error(`Unknown or unsupported resource type of ${r}`)}}};function P(n){for(let e in n)(typeof n[e]>"u"||n[e]===null)&&delete n[e];return n}var U=/-?([1-9]\d{3,}|0\d{3})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])T(([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d+)?|(24:00:00(\.0+)?))(Z|(\+|-)((0\d|1[0-3]):[0-5]\d|14:00))?/,i={warnings:[]};function E(n,e=i){return n.behavior&&(n.behavior=s(n.behavior,"behavior",e)),n.width=C(n.width,"width",!1,e),n.height=C(n.height,"height",!1,e),n.duration=C(n.duration,"duration",!0,e),n.format&&typeof n.format!="string"&&(e.warnings.push('"format" should be a single string'),Array.isArray(n.format)&&typeof n.format[0]=="string"?n.format=n.format[0]:n.format=void 0),n}function m(n,e,a=i){return n&&Array.isArray(n)?n.filter(t=>{let r=e(t);return r&&a.warnings.indexOf(r)===-1&&a.warnings.push(r),!r}):n}function s(n,e,a=i){return Array.isArray(n)?n:(a.warnings.push(`"${e}" should be Array of values`),[n])}function A(n,e,a=i){return Array.isArray(n)?(a.warnings.push(`"${e}" should only contain a single value`),n.length===0?void 0:n[0]):n}function C(n,e,a=!1,t=i){if(!(typeof n>"u")){if(typeof n=="string"){let r=a?parseFloat(n):Math.abs(Number(n));if(Number.isNaN(r)||r<=0){t.warnings.push(`"${e}" expected value to be a ${a?"Number":"Integer"}, instead found an invalid value`);return}return t.warnings.push(`"${e}" expected value to be a ${a?"Number":"Integer"}, instead found a string`),r}return!a&&n%1!==0?(t.warnings.push(`"${e}" expected value to be a Integer, instead found a Float`),Math.floor(n)):n}}function g(n,e,a=i){if(Array.isArray(n))return typeof n[0]=="string"?(a.warnings.push(`"${e}" should be a language map instead found a string`),{none:n}):(a.warnings.push(`"${e}" should be a language map instead found an unknown value`),{none:[""]});if(typeof n=="string")return a.warnings.push(`"${e}" should be a language map instead found a string`),{none:[n]};let t=Object.keys(n),r={},v=!1;for(let h of t){let p=n[h],u=[];if(typeof p=="string")v=!0,a.warnings.push(`"${e}" values inside a language map should be an Array of strings, found a string`),u.push(p);else if(Array.isArray(p))for(let T of p)typeof T!="string"?(v=!0,a.warnings.push(`"${e}" values inside a language map should be an Array of strings, found an unknown value`)):u.push(T);else v=!0,a.warnings.push(`"${e}" values inside a language map should be an Array of strings, found an unknown value`);u.length>0&&(r[h]=u)}return v?Object.keys(r).length===0?{none:[""]}:r:n}function b(n,e,a="",t=i){return typeof n=="string"?(t.warnings.push(`"${e}" should be a {label, value} set of Language maps`),{label:{none:[a]},value:{none:[n]}}):((!n.label&&n.value||n.label&&!n.value)&&t.warnings.push(`"${e}" should have both a label and a value`),n.label?n.label=g(n.label,`${e}.label`,t):n.label={none:[a]},n.value?n.value=g(n.value,`${e}.value`,t):n.value={none:[""]},n)}function W(n,e=i){if(n.label&&(n.label=g(n.label,"label",e)),n.summary&&(n.summary=g(n.summary,"summary",e)),n.requiredStatement&&(n.requiredStatement=b(n.requiredStatement,"requiredStatement","Required statement",e)),n.metadata)if(Array.isArray(n.metadata))for(let a=0;a<n.metadata.length;a++)n.metadata[a]=b(n.metadata[a],`metadata.${a}`,"",e);else e.warnings.push('"metadata" should be an array of {label, value} Language maps'),n.metadata=[];if(n.rights&&(Array.isArray(n.rights)&&(e.warnings.push('"rights" should only contain a single string'),n.rights=typeof n.rights[0]=="string"?n.rights[0]:""),typeof n.rights=="string"&&!n.rights.startsWith("http")?e.warnings.push('"rights" should be a valid URI'):typeof n.rights=="string"&&n.rights.startsWith("https")&&(e.warnings.push('"rights" is an informative property and should contain the http variation of the rights statement'),n.rights=`http${n.rights.slice(5)}`)),n.navDate){let a=typeof n.navDate=="string"?n.navDate.trim():void 0;a!==n.navDate&&(e.warnings.push('"navDate" should not contain extra whitespace'),n.navDate=a),(typeof n.navDate!="string"||!n.navDate.match(U))&&(e.warnings.push('"navDate" should be a valid XSD dateTime literal'),n.navDate=void 0)}return n.language&&(n.language=s(n.language,"language",e),n.language=m(n.language,a=>typeof a=="string"?void 0:`'"language" expected array of strings`,e)),n.accompanyingCanvas&&(n.accompanyingCanvas=A(n.accompanyingCanvas,"accompanyingCanvas",e),n.accompanyingCanvas?.type!=="Canvas"&&e.warnings.push('"accompanyingCanvas" should be a Canvas')),n.placeholderCanvas&&(n.placeholderCanvas=A(n.placeholderCanvas,"placeholderCanvas",e),n.placeholderCanvas?.type!=="Canvas"&&e.warnings.push('"placeholderCanvas" should be a Canvas')),n.thumbnail&&(n.thumbnail=s(n.thumbnail,"thumbnail",e)),n}var w={Manifest:"Canvas",Canvas:"AnnotationPage",AnnotationPage:"Annotation"};function _(n,e=i){let a=n.type;switch(a){case"Canvas":case"AnnotationPage":case"Manifest":n&&n.items&&(n.items=m(n.items,t=>t.type===w[a]?void 0:`"${n.type}.items" should contain only type ${w[a]}, found ${t.type}`,e))}return n}function q(n,e=i){return n.logo&&(n.logo=s(n.logo,"logo",e)),n.service&&(n.service=s(n.service,"service",e)),n.seeAlso&&(n.seeAlso=s(n.seeAlso,"seeAlso",e)),n.rendering&&(n.rendering=s(n.rendering,"rendering",e)),n.partOf&&(n.partOf=s(n.partOf,"partOf",e)),n.homepage&&(n.homepage=s(n.homepage,"homepage",e)),n.services&&(n.services=s(n.services,"services",e)),n.supplementary&&(n.supplementary=s(n.supplementary,"supplementary",e)),n.start&&(n.start=A(n.start,"start",e)),n}function B(n){return e=>{if(e)return typeof e=="string"||Array.isArray(e)?e:P({...e,...E(e,n),...W(e,n),...q(e,n),..._(e,n)})}}function G(n,e=i){return y.all(B(e)).traverseManifest(n)}return D(N);})();
"use strict";var IIIFParser=(()=>{var c=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var x=(n,e,a)=>e in n?c(n,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):n[e]=a;var L=(n,e)=>{for(var a in e)c(n,a,{get:e[a],enumerable:!0})},k=(n,e,a,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of S(e))!M.call(n,r)&&r!==a&&c(n,r,{get:()=>e[r],enumerable:!(t=I(e,r))||t.enumerable});return n};var D=n=>k(c({},"__esModule",{value:!0}),n);var o=(n,e,a)=>(x(n,typeof e!="symbol"?e+"":e,a),a);var N={};L(N,{presentation3StrictUpgrade:()=>G});function d(n){return typeof n=="string"?!1:!!n&&n.type==="SpecificResource"}function v(n){return Array.isArray(n)?n:n?[n]:[]}function f(...n){return e=>n.reduce((a,t)=>t(a),e)}var R=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function $(n,e){if(typeof n>"u"||n===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(n))throw new Error("Array is not a valid entity");if(typeof n!="object"){if(e)return e;throw new Error(`${typeof n} is not a valid entity`)}if(typeof n.type=="string"){let a=R.indexOf(n.type);if(a!==-1)return R[a]}if(n.profile)return"Service";throw new Error("Resource type is not known")}var y=class n{constructor(e,a={}){o(this,"traversals");o(this,"options");o(this,"_traverseManifest",f(this.traverseManifestItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseManifestStructures.bind(this),this.traverseInlineAnnotationPages.bind(this)));o(this,"_traverseCanvas",f(this.traverseCanvasItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseInlineAnnotationPages.bind(this)));o(this,"_traverseAnnotationPage",f(this.traverseAnnotationPageItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this)));o(this,"_traverseRange",f(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:[],...e},this.options={allowUndefinedReturn:!1,...a}}static all(e){return new n({collection:[e],manifest:[e],canvas:[e],annotationCollection:[e],annotationPage:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],geoJson:[e],specificResource:[e],agent:[e]})}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=v(e.thumbnail).map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e.provider&&(e.provider=e.provider.map(a=>this.traverseAgent(a,e))),e}traverseLinking(e){return e.seeAlso&&(e.seeAlso=e.seeAlso.map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e.service&&(e.service=v(e.service).map(a=>this.traverseService(a))),e.services&&(e.services=v(e.services).map(a=>this.traverseService(a,e))),e.logo&&(e.logo=e.logo.map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e.homepage&&(e.homepage=v(e.homepage).map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e.partOf&&(e.partOf=e.partOf.map(a=>typeof a=="string"||!a.type?this.traverseType(a,{parent:e},this.traversals.contentResource):a.type==="Canvas"?this.traverseType(a,{parent:e},this.traversals.canvas):a.type==="AnnotationCollection"?this.traverseType(a,{parent:e},this.traversals.annotationCollection):a.type==="Collection"?this.traverseType(a,{parent:e},this.traversals.collection):this.traverseType(a,{parent:e},this.traversals.contentResource))),e.start&&(d(e.start)?e.start=this.traverseSpecificResource(e.start,"Canvas",e):e.start=this.traverseType(e.start,{parent:e},this.traversals.canvas)),e.rendering&&(e.rendering=e.rendering.map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e.supplementary&&(e.supplementary=e.supplementary.map(a=>this.traverseType(a,{parent:e},this.traversals.contentResource))),e}traverseCollectionItems(e){return e.items&&e.items.map(a=>a.type==="Collection"?this.traverseCollection(a):this.traverseManifest(a)),e}traverseCollection(e,a){return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traverseLinkedCanvases(this.traverseCollectionItems(e))))),{parent:a},this.traversals.collection)}traverseGeoJson(e,a){return this.traverseType(e,{parent:a},this.traversals.geoJson)}traverseNavPlace(e){return e.navPlace&&(e.navPlace=this.traverseGeoJson(e.navPlace,e)),e}traverseManifestItems(e){return e.items&&(e.items=e.items.map(a=>this.traverseCanvas(a))),e}traverseManifestStructures(e){return e.structures&&(e.structures=e.structures.map(a=>this.traverseRange(a))),e}traverseManifest(e,a){return this.traverseType(this._traverseManifest(e),{parent:a},this.traversals.manifest)}traverseCanvasItems(e){return e.items=(e.items||[]).map(a=>this.traverseAnnotationPage(a,e)),e}traverseInlineAnnotationPages(e){return typeof e=="string"||!e||e.annotations&&(e.annotations=e.annotations.map(a=>this.traverseAnnotationPage(a,e))),e}traverseCanvas(e,a){return this.traverseType(this._traverseCanvas(e),{parent:a},this.traversals.canvas)}traverseAnnotationPageItems(e){return e.items&&(e.items=e.items.map(a=>this.traverseAnnotation(a,e))),e}traverseAnnotationPage(e,a){return this.traverseType(this._traverseAnnotationPage(e),{parent:a},this.traversals.annotationPage)}traverseAnnotationBody(e){return Array.isArray(e.body)?e.body=e.body.map(a=>this.traverseContentResource(a,e)):e.body&&(e.body=this.traverseContentResource(e.body,e)),e}traverseLinkedCanvases(e){return e.placeholderCanvas&&(e.placeholderCanvas=this.traverseCanvas(e.placeholderCanvas)),e.accompanyingCanvas&&(e.accompanyingCanvas=this.traverseCanvas(e.accompanyingCanvas)),e}traverseAnnotation(e,a){return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(this.traverseDescriptive(e))),{parent:a},this.traversals.annotation)}traverseContentResourceLinking(e){return typeof e=="string"||!e||e&&e.service&&(e.service=v(e.service||[]).map(a=>this.traverseService(a,e))),e}traverseContentResource(e,a){return e.type==="Choice"&&(e.items=e.items.map(t=>this.traverseContentResource(t,e))),d(e)?this.traverseSpecificResource(e,"ContentResource"):this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)),{parent:a},this.traversals.contentResource)}traverseSpecificResource(e,a,t){let r=e.source;return typeof e.source=="string"&&(r={id:e.source,type:a||"unknown"}),this.traverseType({...e,source:a==="Canvas"||r.type==="Canvas"?this.traverseType(r,{parent:t},this.traversals.canvas):a==="ContentResource"?this.traverseContentResource(r,{parent:t}):this.traverseUnknown(r,{parent:t,typeHint:a})},{parent:t},this.traversals.specificResource)}traverseRangeRanges(e){return e.items&&(e.items=e.items.map(a=>typeof a=="string"?this.traverseCanvas({id:a,type:"Canvas"},e):d(a)?this.traverseSpecificResource(a,"Canvas",e):a.type==="Manifest"?this.traverseManifest(a,e):this.traverseRange(a,e))),e}traverseRange(e,a){return this.traverseType(this._traverseRange(e),{parent:a},this.traversals.range)}traverseAgent(e,a){return this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),{parent:a},this.traversals.agent)}traverseType(e,a,t){return t.reduce((r,l)=>{let h=l(r,a);return typeof h>"u"&&!this.options.allowUndefinedReturn?r:h},e)}traverseService(e,a){let t=Object.assign({},e);return t&&t.service&&(t.service=v(t.service).map(r=>this.traverseService(r))),this.traverseType(t,{parent:a},this.traversals.service)}traverseUnknown(e,{parent:a,typeHint:t}={}){let r=$(e,t);switch(r){case"Collection":return this.traverseCollection(e,a);case"Manifest":return this.traverseManifest(e,a);case"Canvas":return this.traverseCanvas(e,a);case"AnnotationPage":return this.traverseAnnotationPage(e,a);case"Annotation":return this.traverseAnnotation(e,a);case"ContentResource":return this.traverseContentResource(e,a);case"Range":return this.traverseRange(e,a);case"Service":return this.traverseService(e,a);case"Agent":return this.traverseAgent(e,a);default:throw new Error(`Unknown or unsupported resource type of ${r}`)}}};function P(n){for(let e in n)(typeof n[e]>"u"||n[e]===null)&&delete n[e];return n}var U=/-?([1-9]\d{3,}|0\d{3})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])T(([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d+)?|(24:00:00(\.0+)?))(Z|(\+|-)((0\d|1[0-3]):[0-5]\d|14:00))?/,i={warnings:[]};function E(n,e=i){return n.behavior&&(n.behavior=s(n.behavior,"behavior",e)),n.width=C(n.width,"width",!1,e),n.height=C(n.height,"height",!1,e),n.duration=C(n.duration,"duration",!0,e),n.format&&typeof n.format!="string"&&(e.warnings.push('"format" should be a single string'),Array.isArray(n.format)&&typeof n.format[0]=="string"?n.format=n.format[0]:n.format=void 0),n}function m(n,e,a=i){return n&&Array.isArray(n)?n.filter(t=>{let r=e(t);return r&&a.warnings.indexOf(r)===-1&&a.warnings.push(r),!r}):n}function s(n,e,a=i){return Array.isArray(n)?n:(a.warnings.push(`"${e}" should be Array of values`),[n])}function A(n,e,a=i){return Array.isArray(n)?(a.warnings.push(`"${e}" should only contain a single value`),n.length===0?void 0:n[0]):n}function C(n,e,a=!1,t=i){if(!(typeof n>"u")){if(typeof n=="string"){let r=a?parseFloat(n):Math.abs(Number(n));if(Number.isNaN(r)||r<=0){t.warnings.push(`"${e}" expected value to be a ${a?"Number":"Integer"}, instead found an invalid value`);return}return t.warnings.push(`"${e}" expected value to be a ${a?"Number":"Integer"}, instead found a string`),r}return!a&&n%1!==0?(t.warnings.push(`"${e}" expected value to be a Integer, instead found a Float`),Math.floor(n)):n}}function g(n,e,a=i){if(Array.isArray(n))return typeof n[0]=="string"?(a.warnings.push(`"${e}" should be a language map instead found a string`),{none:n}):(a.warnings.push(`"${e}" should be a language map instead found an unknown value`),{none:[""]});if(typeof n=="string")return a.warnings.push(`"${e}" should be a language map instead found a string`),{none:[n]};let t=Object.keys(n),r={},l=!1;for(let h of t){let p=n[h],u=[];if(typeof p=="string")l=!0,a.warnings.push(`"${e}" values inside a language map should be an Array of strings, found a string`),u.push(p);else if(Array.isArray(p))for(let T of p)typeof T!="string"?(l=!0,a.warnings.push(`"${e}" values inside a language map should be an Array of strings, found an unknown value`)):u.push(T);else l=!0,a.warnings.push(`"${e}" values inside a language map should be an Array of strings, found an unknown value`);u.length>0&&(r[h]=u)}return l?Object.keys(r).length===0?{none:[""]}:r:n}function b(n,e,a="",t=i){return typeof n=="string"?(t.warnings.push(`"${e}" should be a {label, value} set of Language maps`),{label:{none:[a]},value:{none:[n]}}):((!n.label&&n.value||n.label&&!n.value)&&t.warnings.push(`"${e}" should have both a label and a value`),n.label?n.label=g(n.label,`${e}.label`,t):n.label={none:[a]},n.value?n.value=g(n.value,`${e}.value`,t):n.value={none:[""]},n)}function W(n,e=i){if(n.label&&(n.label=g(n.label,"label",e)),n.summary&&(n.summary=g(n.summary,"summary",e)),n.requiredStatement&&(n.requiredStatement=b(n.requiredStatement,"requiredStatement","Required statement",e)),n.metadata)if(Array.isArray(n.metadata))for(let a=0;a<n.metadata.length;a++)n.metadata[a]=b(n.metadata[a],`metadata.${a}`,"",e);else e.warnings.push('"metadata" should be an array of {label, value} Language maps'),n.metadata=[];if(n.rights&&(Array.isArray(n.rights)&&(e.warnings.push('"rights" should only contain a single string'),n.rights=typeof n.rights[0]=="string"?n.rights[0]:""),typeof n.rights=="string"&&!n.rights.startsWith("http")?e.warnings.push('"rights" should be a valid URI'):typeof n.rights=="string"&&n.rights.startsWith("https")&&(e.warnings.push('"rights" is an informative property and should contain the http variation of the rights statement'),n.rights=`http${n.rights.slice(5)}`)),n.navDate){let a=typeof n.navDate=="string"?n.navDate.trim():void 0;a!==n.navDate&&(e.warnings.push('"navDate" should not contain extra whitespace'),n.navDate=a),(typeof n.navDate!="string"||!n.navDate.match(U))&&(e.warnings.push('"navDate" should be a valid XSD dateTime literal'),n.navDate=void 0)}return n.language&&(n.language=s(n.language,"language",e),n.language=m(n.language,a=>typeof a=="string"?void 0:`'"language" expected array of strings`,e)),n.accompanyingCanvas&&(n.accompanyingCanvas=A(n.accompanyingCanvas,"accompanyingCanvas",e),n.accompanyingCanvas?.type!=="Canvas"&&e.warnings.push('"accompanyingCanvas" should be a Canvas')),n.placeholderCanvas&&(n.placeholderCanvas=A(n.placeholderCanvas,"placeholderCanvas",e),n.placeholderCanvas?.type!=="Canvas"&&e.warnings.push('"placeholderCanvas" should be a Canvas')),n.thumbnail&&(n.thumbnail=s(n.thumbnail,"thumbnail",e)),n}var w={Manifest:"Canvas",Canvas:"AnnotationPage",AnnotationPage:"Annotation"};function _(n,e=i){let a=n.type;switch(a){case"Canvas":case"AnnotationPage":case"Manifest":n&&n.items&&(n.items=m(n.items,t=>t.type===w[a]?void 0:`"${n.type}.items" should contain only type ${w[a]}, found ${t.type}`,e))}return n}function q(n,e=i){return n.logo&&(n.logo=s(n.logo,"logo",e)),n.service&&(n.service=s(n.service,"service",e)),n.seeAlso&&(n.seeAlso=s(n.seeAlso,"seeAlso",e)),n.rendering&&(n.rendering=s(n.rendering,"rendering",e)),n.partOf&&(n.partOf=s(n.partOf,"partOf",e)),n.homepage&&(n.homepage=s(n.homepage,"homepage",e)),n.services&&(n.services=s(n.services,"services",e)),n.supplementary&&(n.supplementary=s(n.supplementary,"supplementary",e)),n.start&&(n.start=A(n.start,"start",e)),n}function B(n){return e=>{if(e)return typeof e=="string"||Array.isArray(e)?e:P({...e,...E(e,n),...W(e,n),...q(e,n),..._(e,n)})}}function G(n,e=i){return y.all(B(e)).traverseManifest(n)}return D(N);})();

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

import{d as g}from"./chunk-3Q4WO4OP.js";import{b as v}from"./chunk-NJNTZ6QT.js";import"./chunk-D22QKJZO.js";var A=/-?([1-9]\d{3,}|0\d{3})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])T(([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d+)?|(24:00:00(\.0+)?))(Z|(\+|-)((0\d|1[0-3]):[0-5]\d|14:00))?/,i={warnings:[]};function P(a,n=i){return a.behavior&&(a.behavior=t(a.behavior,"behavior",n)),a.width=l(a.width,"width",!1,n),a.height=l(a.height,"height",!1,n),a.duration=l(a.duration,"duration",!0,n),a.format&&typeof a.format!="string"&&(n.warnings.push('"format" should be a single string'),Array.isArray(a.format)&&typeof a.format[0]=="string"?a.format=a.format[0]:a.format=void 0),a}function w(a,n,e=i){return a&&Array.isArray(a)?a.filter(r=>{let s=n(r);return s&&e.warnings.indexOf(s)===-1&&e.warnings.push(s),!s}):a}function t(a,n,e=i){return Array.isArray(a)?a:(e.warnings.push(`"${n}" should be Array of values`),[a])}function h(a,n,e=i){return Array.isArray(a)?(e.warnings.push(`"${n}" should only contain a single value`),a.length===0?void 0:a[0]):a}function l(a,n,e=!1,r=i){if(!(typeof a>"u")){if(typeof a=="string"){let s=e?parseFloat(a):Math.abs(Number(a));if(Number.isNaN(s)||s<=0){r.warnings.push(`"${n}" expected value to be a ${e?"Number":"Integer"}, instead found an invalid value`);return}return r.warnings.push(`"${n}" expected value to be a ${e?"Number":"Integer"}, instead found a string`),s}return!e&&a%1!==0?(r.warnings.push(`"${n}" expected value to be a Integer, instead found a Float`),Math.floor(a)):a}}function d(a,n,e=i){if(Array.isArray(a))return typeof a[0]=="string"?(e.warnings.push(`"${n}" should be a language map instead found a string`),{none:a}):(e.warnings.push(`"${n}" should be a language map instead found an unknown value`),{none:[""]});if(typeof a=="string")return e.warnings.push(`"${n}" should be a language map instead found a string`),{none:[a]};let r=Object.keys(a),s={},u=!1;for(let p of r){let o=a[p],f=[];if(typeof o=="string")u=!0,e.warnings.push(`"${n}" values inside a language map should be an Array of strings, found a string`),f.push(o);else if(Array.isArray(o))for(let y of o)typeof y!="string"?(u=!0,e.warnings.push(`"${n}" values inside a language map should be an Array of strings, found an unknown value`)):f.push(y);else u=!0,e.warnings.push(`"${n}" values inside a language map should be an Array of strings, found an unknown value`);f.length>0&&(s[p]=f)}return u?Object.keys(s).length===0?{none:[""]}:s:a}function c(a,n,e="",r=i){return typeof a=="string"?(r.warnings.push(`"${n}" should be a {label, value} set of Language maps`),{label:{none:[e]},value:{none:[a]}}):((!a.label&&a.value||a.label&&!a.value)&&r.warnings.push(`"${n}" should have both a label and a value`),a.label?a.label=d(a.label,`${n}.label`,r):a.label={none:[e]},a.value?a.value=d(a.value,`${n}.value`,r):a.value={none:[""]},a)}function I(a,n=i){if(a.label&&(a.label=d(a.label,"label",n)),a.summary&&(a.summary=d(a.summary,"summary",n)),a.requiredStatement&&(a.requiredStatement=c(a.requiredStatement,"requiredStatement","Required statement",n)),a.metadata)if(Array.isArray(a.metadata))for(let e=0;e<a.metadata.length;e++)a.metadata[e]=c(a.metadata[e],`metadata.${e}`,"",n);else n.warnings.push('"metadata" should be an array of {label, value} Language maps'),a.metadata=[];if(a.rights&&(Array.isArray(a.rights)&&(n.warnings.push('"rights" should only contain a single string'),a.rights=typeof a.rights[0]=="string"?a.rights[0]:""),typeof a.rights=="string"&&!a.rights.startsWith("http")?n.warnings.push('"rights" should be a valid URI'):typeof a.rights=="string"&&a.rights.startsWith("https")&&(n.warnings.push('"rights" is an informative property and should contain the http variation of the rights statement'),a.rights=`http${a.rights.slice(5)}`)),a.navDate){let e=typeof a.navDate=="string"?a.navDate.trim():void 0;e!==a.navDate&&(n.warnings.push('"navDate" should not contain extra whitespace'),a.navDate=e),(typeof a.navDate!="string"||!a.navDate.match(A))&&(n.warnings.push('"navDate" should be a valid XSD dateTime literal'),a.navDate=void 0)}return a.language&&(a.language=t(a.language,"language",n),a.language=w(a.language,e=>typeof e=="string"?void 0:`'"language" expected array of strings`,n)),a.accompanyingCanvas&&(a.accompanyingCanvas=h(a.accompanyingCanvas,"accompanyingCanvas",n),a.accompanyingCanvas?.type!=="Canvas"&&n.warnings.push('"accompanyingCanvas" should be a Canvas')),a.placeholderCanvas&&(a.placeholderCanvas=h(a.placeholderCanvas,"placeholderCanvas",n),a.placeholderCanvas?.type!=="Canvas"&&n.warnings.push('"placeholderCanvas" should be a Canvas')),a.thumbnail&&(a.thumbnail=t(a.thumbnail,"thumbnail",n)),a}var b={Manifest:"Canvas",Canvas:"AnnotationPage",AnnotationPage:"Annotation"};function $(a,n=i){let e=a.type;switch(e){case"Canvas":case"AnnotationPage":case"Manifest":a&&a.items&&(a.items=w(a.items,r=>r.type===b[e]?void 0:`"${a.type}.items" should contain only type ${b[e]}, found ${r.type}`,n))}return a}function C(a,n=i){return a.logo&&(a.logo=t(a.logo,"logo",n)),a.service&&(a.service=t(a.service,"service",n)),a.seeAlso&&(a.seeAlso=t(a.seeAlso,"seeAlso",n)),a.rendering&&(a.rendering=t(a.rendering,"rendering",n)),a.partOf&&(a.partOf=t(a.partOf,"partOf",n)),a.homepage&&(a.homepage=t(a.homepage,"homepage",n)),a.services&&(a.services=t(a.services,"services",n)),a.supplementary&&(a.supplementary=t(a.supplementary,"supplementary",n)),a.start&&(a.start=h(a.start,"start",n)),a}function L(a){return n=>{if(n)return typeof n=="string"||Array.isArray(n)?n:v({...n,...P(n,a),...I(n,a),...C(n,a),...$(n,a)})}}function k(a,n=i){return g.all(L(n)).traverseManifest(a)}export{k as presentation3StrictUpgrade};
import{d as g}from"./chunk-BCORR5FZ.js";import{b as v}from"./chunk-NJNTZ6QT.js";import"./chunk-D22QKJZO.js";var A=/-?([1-9]\d{3,}|0\d{3})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])T(([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d+)?|(24:00:00(\.0+)?))(Z|(\+|-)((0\d|1[0-3]):[0-5]\d|14:00))?/,i={warnings:[]};function P(a,n=i){return a.behavior&&(a.behavior=t(a.behavior,"behavior",n)),a.width=l(a.width,"width",!1,n),a.height=l(a.height,"height",!1,n),a.duration=l(a.duration,"duration",!0,n),a.format&&typeof a.format!="string"&&(n.warnings.push('"format" should be a single string'),Array.isArray(a.format)&&typeof a.format[0]=="string"?a.format=a.format[0]:a.format=void 0),a}function w(a,n,e=i){return a&&Array.isArray(a)?a.filter(r=>{let s=n(r);return s&&e.warnings.indexOf(s)===-1&&e.warnings.push(s),!s}):a}function t(a,n,e=i){return Array.isArray(a)?a:(e.warnings.push(`"${n}" should be Array of values`),[a])}function h(a,n,e=i){return Array.isArray(a)?(e.warnings.push(`"${n}" should only contain a single value`),a.length===0?void 0:a[0]):a}function l(a,n,e=!1,r=i){if(!(typeof a>"u")){if(typeof a=="string"){let s=e?parseFloat(a):Math.abs(Number(a));if(Number.isNaN(s)||s<=0){r.warnings.push(`"${n}" expected value to be a ${e?"Number":"Integer"}, instead found an invalid value`);return}return r.warnings.push(`"${n}" expected value to be a ${e?"Number":"Integer"}, instead found a string`),s}return!e&&a%1!==0?(r.warnings.push(`"${n}" expected value to be a Integer, instead found a Float`),Math.floor(a)):a}}function d(a,n,e=i){if(Array.isArray(a))return typeof a[0]=="string"?(e.warnings.push(`"${n}" should be a language map instead found a string`),{none:a}):(e.warnings.push(`"${n}" should be a language map instead found an unknown value`),{none:[""]});if(typeof a=="string")return e.warnings.push(`"${n}" should be a language map instead found a string`),{none:[a]};let r=Object.keys(a),s={},u=!1;for(let p of r){let o=a[p],f=[];if(typeof o=="string")u=!0,e.warnings.push(`"${n}" values inside a language map should be an Array of strings, found a string`),f.push(o);else if(Array.isArray(o))for(let y of o)typeof y!="string"?(u=!0,e.warnings.push(`"${n}" values inside a language map should be an Array of strings, found an unknown value`)):f.push(y);else u=!0,e.warnings.push(`"${n}" values inside a language map should be an Array of strings, found an unknown value`);f.length>0&&(s[p]=f)}return u?Object.keys(s).length===0?{none:[""]}:s:a}function c(a,n,e="",r=i){return typeof a=="string"?(r.warnings.push(`"${n}" should be a {label, value} set of Language maps`),{label:{none:[e]},value:{none:[a]}}):((!a.label&&a.value||a.label&&!a.value)&&r.warnings.push(`"${n}" should have both a label and a value`),a.label?a.label=d(a.label,`${n}.label`,r):a.label={none:[e]},a.value?a.value=d(a.value,`${n}.value`,r):a.value={none:[""]},a)}function I(a,n=i){if(a.label&&(a.label=d(a.label,"label",n)),a.summary&&(a.summary=d(a.summary,"summary",n)),a.requiredStatement&&(a.requiredStatement=c(a.requiredStatement,"requiredStatement","Required statement",n)),a.metadata)if(Array.isArray(a.metadata))for(let e=0;e<a.metadata.length;e++)a.metadata[e]=c(a.metadata[e],`metadata.${e}`,"",n);else n.warnings.push('"metadata" should be an array of {label, value} Language maps'),a.metadata=[];if(a.rights&&(Array.isArray(a.rights)&&(n.warnings.push('"rights" should only contain a single string'),a.rights=typeof a.rights[0]=="string"?a.rights[0]:""),typeof a.rights=="string"&&!a.rights.startsWith("http")?n.warnings.push('"rights" should be a valid URI'):typeof a.rights=="string"&&a.rights.startsWith("https")&&(n.warnings.push('"rights" is an informative property and should contain the http variation of the rights statement'),a.rights=`http${a.rights.slice(5)}`)),a.navDate){let e=typeof a.navDate=="string"?a.navDate.trim():void 0;e!==a.navDate&&(n.warnings.push('"navDate" should not contain extra whitespace'),a.navDate=e),(typeof a.navDate!="string"||!a.navDate.match(A))&&(n.warnings.push('"navDate" should be a valid XSD dateTime literal'),a.navDate=void 0)}return a.language&&(a.language=t(a.language,"language",n),a.language=w(a.language,e=>typeof e=="string"?void 0:`'"language" expected array of strings`,n)),a.accompanyingCanvas&&(a.accompanyingCanvas=h(a.accompanyingCanvas,"accompanyingCanvas",n),a.accompanyingCanvas?.type!=="Canvas"&&n.warnings.push('"accompanyingCanvas" should be a Canvas')),a.placeholderCanvas&&(a.placeholderCanvas=h(a.placeholderCanvas,"placeholderCanvas",n),a.placeholderCanvas?.type!=="Canvas"&&n.warnings.push('"placeholderCanvas" should be a Canvas')),a.thumbnail&&(a.thumbnail=t(a.thumbnail,"thumbnail",n)),a}var b={Manifest:"Canvas",Canvas:"AnnotationPage",AnnotationPage:"Annotation"};function $(a,n=i){let e=a.type;switch(e){case"Canvas":case"AnnotationPage":case"Manifest":a&&a.items&&(a.items=w(a.items,r=>r.type===b[e]?void 0:`"${a.type}.items" should contain only type ${b[e]}, found ${r.type}`,n))}return a}function C(a,n=i){return a.logo&&(a.logo=t(a.logo,"logo",n)),a.service&&(a.service=t(a.service,"service",n)),a.seeAlso&&(a.seeAlso=t(a.seeAlso,"seeAlso",n)),a.rendering&&(a.rendering=t(a.rendering,"rendering",n)),a.partOf&&(a.partOf=t(a.partOf,"partOf",n)),a.homepage&&(a.homepage=t(a.homepage,"homepage",n)),a.services&&(a.services=t(a.services,"services",n)),a.supplementary&&(a.supplementary=t(a.supplementary,"supplementary",n)),a.start&&(a.start=h(a.start,"start",n)),a}function L(a){return n=>{if(n)return typeof n=="string"||Array.isArray(n)?n:v({...n,...P(n,a),...I(n,a),...C(n,a),...$(n,a)})}}function k(a,n=i){return g.all(L(n)).traverseManifest(a)}export{k as presentation3StrictUpgrade};
{
"name": "@iiif/parser",
"version": "2.1.2",
"version": "2.1.3",
"license": "MIT",

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

import{a as i}from"./chunk-NJNTZ6QT.js";import{a as r}from"./chunk-D22QKJZO.js";function v(n){return typeof n=="string"?!1:!!n&&n.type==="SpecificResource"}function o(...n){return e=>n.reduce((t,a)=>a(t),e)}var p=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function y(n,e){if(typeof n>"u"||n===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(n))throw new Error("Array is not a valid entity");if(typeof n!="object"){if(e)return e;throw new Error(`${typeof n} is not a valid entity`)}if(typeof n.type=="string"){let t=p.indexOf(n.type);if(t!==-1)return p[t]}if(n.profile)return"Service";throw new Error("Resource type is not known")}var l=class n{constructor(e,t={}){r(this,"traversals");r(this,"options");r(this,"_traverseManifest",o(this.traverseManifestItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseManifestStructures.bind(this),this.traverseInlineAnnotationPages.bind(this)));r(this,"_traverseCanvas",o(this.traverseCanvasItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseInlineAnnotationPages.bind(this)));r(this,"_traverseAnnotationPage",o(this.traverseAnnotationPageItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this)));r(this,"_traverseRange",o(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:[],...e},this.options={allowUndefinedReturn:!1,...t}}static all(e){return new n({collection:[e],manifest:[e],canvas:[e],annotationCollection:[e],annotationPage:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],geoJson:[e],specificResource:[e],agent:[e]})}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=i(e.thumbnail).map(t=>this.traverseType(t,{parent:e},this.traversals.contentResource))),e.provider&&(e.provider=e.provider.map(t=>this.traverseAgent(t,e))),e}traverseLinking(e){return e.seeAlso&&(e.seeAlso=e.seeAlso.map(t=>this.traverseType(t,{parent:e},this.traversals.contentResource))),e.service&&(e.service=i(e.service).map(t=>this.traverseService(t))),e.services&&(e.services=i(e.services).map(t=>this.traverseService(t,e))),e.logo&&(e.logo=e.logo.map(t=>this.traverseType(t,{parent:e},this.traversals.contentResource))),e.homepage&&(e.homepage=e.homepage.map(t=>this.traverseType(t,{parent:e},this.traversals.contentResource))),e.partOf&&(e.partOf=e.partOf.map(t=>typeof t=="string"||!t.type?this.traverseType(t,{parent:e},this.traversals.contentResource):t.type==="Canvas"?this.traverseType(t,{parent:e},this.traversals.canvas):t.type==="AnnotationCollection"?this.traverseType(t,{parent:e},this.traversals.annotationCollection):t.type==="Collection"?this.traverseType(t,{parent:e},this.traversals.collection):this.traverseType(t,{parent:e},this.traversals.contentResource))),e.start&&(v(e.start)?e.start=this.traverseSpecificResource(e.start,"Canvas",e):e.start=this.traverseType(e.start,{parent:e},this.traversals.canvas)),e.rendering&&(e.rendering=e.rendering.map(t=>this.traverseType(t,{parent:e},this.traversals.contentResource))),e.supplementary&&(e.supplementary=e.supplementary.map(t=>this.traverseType(t,{parent:e},this.traversals.contentResource))),e}traverseCollectionItems(e){return e.items&&e.items.map(t=>t.type==="Collection"?this.traverseCollection(t):this.traverseManifest(t)),e}traverseCollection(e,t){return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traverseLinkedCanvases(this.traverseCollectionItems(e))))),{parent:t},this.traversals.collection)}traverseGeoJson(e,t){return this.traverseType(e,{parent:t},this.traversals.geoJson)}traverseNavPlace(e){return e.navPlace&&(e.navPlace=this.traverseGeoJson(e.navPlace,e)),e}traverseManifestItems(e){return e.items&&(e.items=e.items.map(t=>this.traverseCanvas(t))),e}traverseManifestStructures(e){return e.structures&&(e.structures=e.structures.map(t=>this.traverseRange(t))),e}traverseManifest(e,t){return this.traverseType(this._traverseManifest(e),{parent:t},this.traversals.manifest)}traverseCanvasItems(e){return e.items=(e.items||[]).map(t=>this.traverseAnnotationPage(t,e)),e}traverseInlineAnnotationPages(e){return typeof e=="string"||!e||e.annotations&&(e.annotations=e.annotations.map(t=>this.traverseAnnotationPage(t,e))),e}traverseCanvas(e,t){return this.traverseType(this._traverseCanvas(e),{parent:t},this.traversals.canvas)}traverseAnnotationPageItems(e){return e.items&&(e.items=e.items.map(t=>this.traverseAnnotation(t,e))),e}traverseAnnotationPage(e,t){return this.traverseType(this._traverseAnnotationPage(e),{parent:t},this.traversals.annotationPage)}traverseAnnotationBody(e){return Array.isArray(e.body)?e.body=e.body.map(t=>this.traverseContentResource(t,e)):e.body&&(e.body=this.traverseContentResource(e.body,e)),e}traverseLinkedCanvases(e){return e.placeholderCanvas&&(e.placeholderCanvas=this.traverseCanvas(e.placeholderCanvas)),e.accompanyingCanvas&&(e.accompanyingCanvas=this.traverseCanvas(e.accompanyingCanvas)),e}traverseAnnotation(e,t){return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(this.traverseDescriptive(e))),{parent:t},this.traversals.annotation)}traverseContentResourceLinking(e){return typeof e=="string"||!e||e&&e.service&&(e.service=i(e.service||[]).map(t=>this.traverseService(t,e))),e}traverseContentResource(e,t){return e.type==="Choice"&&(e.items=e.items.map(a=>this.traverseContentResource(a,e))),v(e)?this.traverseSpecificResource(e,"ContentResource"):this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)),{parent:t},this.traversals.contentResource)}traverseSpecificResource(e,t,a){let s=e.source;return typeof e.source=="string"&&(s={id:e.source,type:t||"unknown"}),this.traverseType({...e,source:t==="Canvas"||s.type==="Canvas"?this.traverseType(s,{parent:a},this.traversals.canvas):t==="ContentResource"?this.traverseContentResource(s,{parent:a}):this.traverseUnknown(s,{parent:a,typeHint:t})},{parent:a},this.traversals.specificResource)}traverseRangeRanges(e){return e.items&&(e.items=e.items.map(t=>typeof t=="string"?this.traverseCanvas({id:t,type:"Canvas"},e):v(t)?this.traverseSpecificResource(t,"Canvas",e):t.type==="Manifest"?this.traverseManifest(t,e):this.traverseRange(t,e))),e}traverseRange(e,t){return this.traverseType(this._traverseRange(e),{parent:t},this.traversals.range)}traverseAgent(e,t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),{parent:t},this.traversals.agent)}traverseType(e,t,a){return a.reduce((s,c)=>{let h=c(s,t);return typeof h>"u"&&!this.options.allowUndefinedReturn?s:h},e)}traverseService(e,t){let a=Object.assign({},e);return a&&a.service&&(a.service=i(a.service).map(s=>this.traverseService(s))),this.traverseType(a,{parent:t},this.traversals.service)}traverseUnknown(e,{parent:t,typeHint:a}={}){let s=y(e,a);switch(s){case"Collection":return this.traverseCollection(e,t);case"Manifest":return this.traverseManifest(e,t);case"Canvas":return this.traverseCanvas(e,t);case"AnnotationPage":return this.traverseAnnotationPage(e,t);case"Annotation":return this.traverseAnnotation(e,t);case"ContentResource":return this.traverseContentResource(e,t);case"Range":return this.traverseRange(e,t);case"Service":return this.traverseService(e,t);case"Agent":return this.traverseAgent(e,t);default:throw new Error(`Unknown or unsupported resource type of ${s}`)}}};export{v as a,p as b,y as c,l as d};
import{h as V}from"./chunk-5GMXZJIZ.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};