@iiif/parser
Advanced tools
@@ -1,2 +0,2 @@ | ||
| "use strict";var e=Object.defineProperty,t=(t,i,r)=>(((t,i,r)=>{i in t?e(t,i,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[i]=r})(t,"symbol"!=typeof i?i+"":i,r),r);function i(e){return"string"!=typeof e&&(!!e&&"SpecificResource"===e.type)}function r(e,t){const n=t||"unknown";if(!e)return;if("string"==typeof e)return{id:e,type:n};if(i(e))return r(e.source,t);let s=n&&"unknown"!==n?n:e.type||e["@type"];const a=e.id||e["@id"];return-1!==s.indexOf(":")&&(s=s.split(":").pop()),a&&s?{id:a,type:s}:void 0}Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n={},s="iiif-parser:hasPart",a="iiif-parser:partOf",o="iiif-parser:isExternal",c="__$UNSET$__",l="__$UNWRAP$__",p=[];function u(e){if(e===n||0===Object.keys(e).length)return!0;for(const t in e)return!1;return!0}function v(e,t){if(t&&t["@explicit"]){const i={},r=Object.keys(t);for(const n of r)n!==a&&"@explicit"!==n&&(u(t[n])?i[n]=e[n]:i[n]=t[n]);return i}return e}function f(e,t,i){const n=r(t);if(!n)return[void 0,void 0];const o=e.requests[n.id],c=n.type||e.mapping[n.id];if(!c||o&&o.resourceUri&&!e.entities[c][o.resourceUri])return[void 0,void 0];const l=e.entities[c][o?o.resourceUri:n.id];if(n.type&&!l)return f(e,{id:n.id},i);if(l&&l[s]){const e=l[s].find((e=>i?e[a]===i.id:e[a]===l.id));return[v(l,e),l]}return[l,l]}Object.freeze(p),Object.freeze(n);const h={id:"https://iiif-parser/annotation",type:"Annotation",behavior:p,label:null,thumbnail:p,summary:null,requiredStatement:null,metadata:p,seeAlso:p,homepage:p,rendering:p,service:p,accessibility:p,audience:p,body:p,bodyValue:null,canonical:null,created:null,creator:p,generated:null,generator:p,modified:null,motivation:p,rights:null,stylesheet:null,target:p,timeMode:void 0,via:p,partOf:p},y={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:p,label:null,thumbnail:p,summary:null,requiredStatement:null,metadata:p,rights:null,provider:p,items:p,seeAlso:p,homepage:p,rendering:p,service:p},d={id:"https://iiif-parser/empty-canvas",type:"Canvas",label:null,behavior:p,thumbnail:p,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:p,rights:null,navDate:null,provider:p,items:p,annotations:p,seeAlso:p,homepage:p,partOf:p,rendering:p,service:p,duration:0,height:0,width:0},m={id:"https://iiif-parser/empty-collection",type:"Collection",label:null,viewingDirection:"left-to-right",behavior:p,thumbnail:p,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:p,rights:null,navDate:null,provider:p,items:p,annotations:p,seeAlso:p,homepage:p,partOf:p,rendering:p,service:p,services:p},g={id:"https://iiif-parser/empty-manifest",type:"Manifest",annotations:p,behavior:p,homepage:p,items:p,label:null,metadata:p,navDate:null,provider:p,partOf:p,accompanyingCanvas:null,placeholderCanvas:null,rendering:p,requiredStatement:null,rights:null,seeAlso:p,service:p,services:p,start:null,structures:p,summary:null,thumbnail:p,viewingDirection:"left-to-right"},A={id:"https://iiif-parser/empty-canvas",type:"Range",label:null,behavior:p,thumbnail:p,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:p,rights:null,navDate:null,provider:p,items:p,annotations:p,seeAlso:p,homepage:p,partOf:p,rendering:p,service:p,start:null,supplementary:null,viewingDirection:"left-to-right"},C={id:"https://iiif-parser/empty-agent",type:"Agent",label:{},logo:p,seeAlso:p,homepage:p},b={id:"https://iiif-parser/empty-service",type:"UnknownService"};function R(e){return Array.isArray(e)?e:e?[e]:[]}function S(...e){return t=>e.reduce(((e,t)=>t(e)),t)}const w=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function x(e,t){if(null==e)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("object"!=typeof e){if(t)return t;throw new Error(typeof e+" is not a valid entity")}if("string"==typeof e.type){const t=w.indexOf(e.type);if(-1!==t)return w[t]}if(e.profile)return"Service";throw new Error("Resource type is not known")}class j{constructor(e,i={}){t(this,"traversals"),t(this,"options"),t(this,"_traverseManifest",S(this.traverseManifestItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseManifestStructures.bind(this),this.traverseInlineAnnotationPages.bind(this))),t(this,"_traverseCanvas",S(this.traverseCanvasItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseInlineAnnotationPages.bind(this))),t(this,"_traverseAnnotationPage",S(this.traverseAnnotationPageItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this))),t(this,"_traverseRange",S(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,...i}}static all(e){return new j({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=R(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=R(e.service).map((e=>this.traverseService(e)))),e.services&&(e.services=R(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=>"string"!=typeof t&&t.type?"Canvas"===t.type?this.traverseType(t,{parent:e},this.traversals.canvas):"AnnotationCollection"===t.type?this.traverseType(t,{parent:e},this.traversals.annotationCollection):"Collection"===t.type?this.traverseType(t,{parent:e},this.traversals.collection):this.traverseType(t,{parent:e},this.traversals.contentResource):this.traverseType(t,{parent:e},this.traversals.contentResource)))),e.start&&(i(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((e=>"Collection"===e.type?this.traverseCollection(e):this.traverseManifest(e))),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((e=>this.traverseCanvas(e)))),e}traverseManifestStructures(e){return e.structures&&(e.structures=e.structures.map((e=>this.traverseRange(e)))),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"string"!=typeof e&&e?(e.annotations&&(e.annotations=e.annotations.map((t=>this.traverseAnnotationPage(t,e)))),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"string"!=typeof e&&e?(e&&e.service&&(e.service=R(e.service||[]).map((t=>this.traverseService(t,e)))),e):e}traverseContentResource(e,t){return"Choice"===e.type&&(e.items=e.items.map((t=>this.traverseContentResource(t,e)))),i(e)?this.traverseSpecificResource(e,"ContentResource"):this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)),{parent:t},this.traversals.contentResource)}traverseSpecificResource(e,t,i){let r=e.source;return"string"==typeof e.source&&(r={id:e.source,type:t||"unknown"}),this.traverseType({...e,source:"Canvas"===t||"Canvas"===r.type?this.traverseType(r,{parent:i},this.traversals.canvas):"ContentResource"===t?this.traverseContentResource(r,{parent:i}):this.traverseUnknown(r,{parent:i,typeHint:t})},{parent:i},this.traversals.specificResource)}traverseRangeRanges(e){return e.items&&(e.items=e.items.map((t=>"string"==typeof t?this.traverseCanvas({id:t,type:"Canvas"},e):i(t)?this.traverseSpecificResource(t,"Canvas",e):"Manifest"===t.type?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,i){return i.reduce(((e,i)=>{const r=i(e,t);return void 0!==r||this.options.allowUndefinedReturn?r:e}),e)}traverseService(e,t){const i=Object.assign({},e);return i&&i.service&&(i.service=R(i.service).map((e=>this.traverseService(e)))),this.traverseType(i,{parent:t},this.traversals.service)}traverseUnknown(e,{parent:t,typeHint:i}={}){const r=x(e,i);switch(r){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:if(i)return i;throw new Error(`Unknown or unsupported resource type of ${r}`)}}}const O=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];class T{constructor(e,i={}){t(this,"traversals"),t(this,"options"),this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...i}}static all(e){return new T({collection:[e],manifest:[e],canvas:[e],annotationList:[e],sequence:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],layer:[e]})}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))),this.traversals.collection)}traverseCollectionItems(e){if(this.options.mergeMemberProperties){const t=[...(e.manifests||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Manifest"}:e)),...(e.collections||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Collection"}:e)),...e.members||[]];delete e.collections,delete e.manifests,e.members=t}return e.manifests&&(e.manifests=e.manifests.map((e=>this.traverseManifest("string"==typeof e?{"@id":e,"@type":"sc:Manifest"}:e)))),e.collections&&(e.collections=e.collections.map((e=>this.traverseCollection("string"==typeof e?{"@id":e,"@type":"sc:Collection"}:e)))),e.members&&(e.members=e.members.map((e=>"string"==typeof e?e:this.traverseUnknown(e)))),e}traverseManifest(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))),this.traversals.manifest)}traverseManifestItems(e){return e.sequences&&(e.sequences=e.sequences.map((e=>this.traverseSequence(e)))),e.structures&&(e.structures=e.structures.map((e=>this.traverseRange(e)))),e}traverseSequence(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))),this.traversals.sequence)}traverseSequenceItems(e){return e.canvases&&(e.canvases=e.canvases.map((e=>this.traverseCanvas(e)))),e}traverseCanvas(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))),this.traversals.canvas)}traverseCanvasItems(e){return e.images&&(e.images=e.images.map((e=>this.traverseAnnotation(e)))),e.otherContent&&(e.otherContent=e.otherContent.map((e=>this.traverseAnnotationList(e)))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const t=[...(e.ranges||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Range"}:e)),...(e.canvases||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Canvas"}:e)),...e.members||[]];delete e.ranges,delete e.canvases,e.members=t.length?t.map((e=>this.traverseUnknown(e))):void 0}return e}traverseAnnotationList(e){const t="string"==typeof e?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(t)),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map((e=>this.traverseAnnotation(e)))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(Array.isArray(e.resource)?e.resource=e.resource.map((e=>this.traverseContentResource(e))):e.resource=this.traverseContentResource(e.resource)),e.on,e}traverseLayer(e){return this.traverseType(this.traverseLinking(this.traverseLayerItems(e)),this.traversals.layer)}traverseLayerItems(e){return e.otherContent&&(e.otherContent=e.otherContent.map((e=>this.traverseAnnotationList(e)))),e}traverseChoice(e){return this.traverseType(this.traverseChoiceItems(e),this.traversals.choice)}traverseChoiceItems(e){return e.default&&"rdf:nil"!==e.default&&(e.default=this.traverseContentResource(e.default)),e.item&&"rdf:nil"!==e.item&&(e.item=e.item.map((e=>this.traverseContentResource(e)))),e}traverseService(e){return this.traverseType(this.traverseLinking(e),this.traversals.service)}traverseContentResource(e){return"oa:Choice"===e["@type"]?this.traverseChoice(e):this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.contentResource)}traverseUnknown(e){if(!e["@type"]||"string"==typeof e)return e;switch(function(e){if(null==e)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("object"!=typeof e)throw new Error(typeof e+" is not a valid entity");if("string"==typeof e["@type"]){const t=O.indexOf(e["@type"]);if(-1!==t)return O[t]}if(e.profile)return"Service";if(e.format)return"ContentResource";if(e["@type"])return"ContentResource";throw new Error("Resource type is not known")}(e)){case"sc:Collection":return this.traverseCollection(e);case"sc:Manifest":return this.traverseManifest(e);case"sc:Canvas":return this.traverseCanvas(e);case"sc:Sequence":return this.traverseSequence(e);case"sc:Range":return this.traverseRange(e);case"oa:Annotation":return this.traverseAnnotation(e);case"sc:AnnotationList":return this.traverseAnnotationList(e);case"sc:Layer":return this.traverseLayer(e);case"Service":return this.traverseService(e);case"oa:Choice":return this.traverseChoice(e);case"ContentResource":return this.traverseContentResource(e)}return e.profile?this.traverseService(e):e}traverseImageResource(e){const t=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(const n of i)"string"==typeof n?r.push(this.traverseContentResource({"@id":n,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(n));return t||this.options.convertPropsToArray?r:r[0]}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){const t=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(const n of i)r.push(this.traverseService(n));return t||this.options.convertPropsToArray?r:r[0]}traverseLinking(e){return e.related&&(e.related=this.traverseOneOrManyType(e.related,this.traversals.contentResource)),e.rendering&&(e.rendering=this.traverseOneOrManyType(e.rendering,this.traversals.contentResource)),e.service&&(e.service=this.traverseOneOrMoreServices(e.service)),e.seeAlso&&(e.seeAlso=this.traverseOneOrManyType(e.seeAlso,this.traversals.contentResource)),e.within&&("string"==typeof e.within||(e.within=this.traverseOneOrManyType(e.within,this.traversals.contentResource))),e.startCanvas&&("string"==typeof e.startCanvas?e.startCanvas=this.traverseType({"@id":e.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):e.startCanvas&&this.traverseType(e.startCanvas,this.traversals.canvas)),e.contentLayer&&("string"==typeof e.contentLayer?e.contentLayer=this.traverseLayer({"@id":e.contentLayer,"@type":"sc:Layer"}):e.contentLayer=this.traverseLayer(e.contentLayer)),e}traverseOneOrManyType(e,t){if(!Array.isArray(e)){if(!this.options.convertPropsToArray)return this.traverseType(e,t);e=[e]}return e.map((e=>this.traverseType(e,t)))}traverseType(e,t){return t.reduce(((e,t)=>{const i=t(e);return void 0!==i||this.options.allowUndefinedReturn?i:e}),e)}}const L=["http://iiif.io/api/image/2/level1","http://iiif.io/api/image/2/level2","http://library.stanford.edu/iiif/image-api/compliance.html#level1","http://library.stanford.edu/iiif/image-api/compliance.html#level2","http://library.stanford.edu/iiif/image-api/conformance.html#level1","http://library.stanford.edu/iiif/image-api/conformance.html#level2","http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1","http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2","http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1","http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2","http://iiif.io/api/image/1/level1.json","http://iiif.io/api/image/1/profiles/level1.json","http://iiif.io/api/image/1/level2.json","http://iiif.io/api/image/1/profiles/level2.json","http://iiif.io/api/image/2/level1.json","http://iiif.io/api/image/2/profiles/level1.json","http://iiif.io/api/image/2/level2.json","http://iiif.io/api/image/2/profiles/level2.json","level1","level2"],k=["http://iiif.io/api/image/2/level0","http://iiif.io/api/image/2/level1","http://iiif.io/api/image/2/level2","http://library.stanford.edu/iiif/image-api/compliance.html#level0","http://library.stanford.edu/iiif/image-api/compliance.html#level1","http://library.stanford.edu/iiif/image-api/compliance.html#level2","http://library.stanford.edu/iiif/image-api/conformance.html#level0","http://library.stanford.edu/iiif/image-api/conformance.html#level1","http://library.stanford.edu/iiif/image-api/conformance.html#level2","http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0","http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1","http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2","http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0","http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1","http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2","http://iiif.io/api/image/1/level0.json","http://iiif.io/api/image/1/profiles/level0.json","http://iiif.io/api/image/1/level1.json","http://iiif.io/api/image/1/profiles/level1.json","http://iiif.io/api/image/1/level2.json","http://iiif.io/api/image/1/profiles/level2.json","http://iiif.io/api/image/2/level0.json","http://iiif.io/api/image/2/profiles/level0.json","http://iiif.io/api/image/2/level1.json","http://iiif.io/api/image/2/profiles/level1.json","http://iiif.io/api/image/2/level2.json","http://iiif.io/api/image/2/profiles/level2.json","level0","level1","level2"];function I(e){for(const t in e)void 0!==e[t]&&null!==e[t]||delete e[t];return e}const P="Attribution",M="http://example.org/provider",D="Unknown";function q(e,t="none"){if(!e)return{};const i=Array.isArray(e)?e:[e],r={};for(const n of i){if("string"==typeof n){r[t]=r[t]?r[t]:[],r[t].push(n||"");continue}if(!n["@language"]){r[t]=r[t]?r[t]:[],r[t].push(n["@value"]||"");continue}const e=n["@language"];r[e]=r[e]?r[e]:[],r[e].push(n["@value"]||"")}return r}function E(e){return Array.isArray(e)?E(e.find((e=>"string"==typeof e))):-1!==k.indexOf(e)?"level2":-1!==L.indexOf(e)?"level1":"string"==typeof e?e:void 0}function U(e){for(const t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}const $=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function _(e){const t=e["@id"]||e.id;let i=e["@type"]||e.type;const r=e.profile||void 0,n=e["@context"]||void 0;if(r){const e=function(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"}}(r);if(e)return e}if(n){const e=function(e){const t=Array.isArray(e)?e:[e];for(const i of t)switch(i){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}(n);if(e)return e}if(i){if(Array.isArray(i)){if(-1!==i.indexOf("oa:CssStylesheet"))return"CssStylesheet";if(-1!==i.indexOf("cnt:ContentAsText"))return"TextualBody";i=i[0]}for(const e of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${e}:`)){i=i.slice(e.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(i&&-1!==$.indexOf(i))return i;if(e.format){if(e.format.startsWith("image/"))return"Image";if(e.format.startsWith("text/"))return"Text";if("application/pdf"===e.format)return"Text";if(e.format.startsWith("application/"))return"Dataset"}return t&&(t.endsWith(".jpg")||t.endsWith(".png")||t.endsWith(".jpeg"))?"Image":i||"unknown"}const W=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function H(e){const t=e.match(W);return t?t[0]:e}const F=["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 N(e){if(e){const t=Array.isArray(e)?e:[e],i=[];for(const e of t)"http://iiif.io/api/presentation/2/context.json"===e&&i.push("http://iiif.io/api/presentation/3/context.json"),-1===F.indexOf(e)&&i.push(e);if(t.length)return 1===i.length?i[0]:i}}let z=0;function J(e,t){const i=encodeURI(e.id||e["@id"]||"").trim();return i&&t?`${i}/${t}`:i||(z++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${z}`)}function B(e){const t=[...e.behavior||[]];let i;return e.viewingHint&&t.push(e.viewingHint),Array.isArray(e.motivation)?i=e.motivation.map(U):e.motivation&&(i=U(e.motivation)),{"@context":e["@context"]?N(e["@context"]):void 0,id:(e["@id"]||J(e)).trim(),type:_(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:i,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function G(e){const[t,i]=function(e,t="Rights/License",i="none"){let r=null;const n=[],s=Array.isArray(e)?e:[e];for(const a of s){const e=a?H(a):void 0;!e||-1===e.indexOf("creativecommons.org")&&-1===e.indexOf("rightsstatements.org")?e&&n.push({label:{[i]:[t]},value:{[i]:[e]}}):r=e.startsWith("https://")?`http://${e.slice(8)}`:e}return[r,n]}(e.license),r=[...e.metadata?(n=e.metadata,n?n.map((e=>({label:q(e.label),value:q(e.value)}))):[]):[],...i];var n;return{rights:t,metadata:r.length?r:void 0,label:e.label?q(e.label):void 0,requiredStatement:e.attribution?{label:q(P),value:q(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?q(e.description):void 0,thumbnail:V(e.thumbnail)}}function V(e){if(e){return(Array.isArray(e)?e:[e]).map((e=>"string"==typeof e?{id:e,type:"Image"}:("unknown"===e.type&&(e.type="Image"),e)))}return e}function X(e){if(!e.within)return;const t=Array.isArray(e.within)?e.within:[e.within],i=[];for(const r of t)if("string"==typeof r){if(r&&"sc:Manifest"===e["@type"])i.push({id:r,type:"Collection"})}else r["@id"]&&i.push({id:r["@id"],type:_(r)});return i.length?i:void 0}function Y(e){const t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],i=e.contentLayer;return{provider:e.logo||t.length?[{id:M,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:q(D)}]:void 0,partOf:X(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?R(e.service):void 0,supplementary:i?[i]:void 0}}function K(e){const t=e;return I({...B(t),...G(t),...Y(t),...(i=t,{chars:i.chars,format:i.format?i.format:void 0,language:i.language})});var i}const Q=new T({collection:[function(e){return I({...B(e),...G(e),...Y(e),items:e.members})}],manifest:[function(e){const t=[],i=[];let r;for(const s of e.sequences||[])s.canvases.length&&t.push(...s.canvases),s.behavior&&i.push(...s.behavior),s.startCanvas&&(r=s.startCanvas);const n=B(e);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),I({...n,...G(e),...Y(e),start:r,items:t,structures:e.structures})}],canvas:[function(e){return I({...B(e),...G(e),...Y(e),annotations:e.otherContent&&e.otherContent.length?e.otherContent:void 0,items:e.images&&e.images.length?[{id:J(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}],annotationList:[function(e){return I({...B(e),...G(e),...Y(e),items:e.resources&&e.resources.length?e.resources:void 0})}],sequence:[function(e){return e.canvases&&0!==e.canvases.length?{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}:{canvases:[],behavior:[]}}],annotation:[function(e){return I({...B(e),...G(e),...Y(e),target:function e(t){if(Array.isArray(t)){if(t.length>1)return{type:"List",items:t.map(e)};t=t[0]}if("string"==typeof t)return encodeURI(t).trim();if("@type"in t){let e;if("string"==typeof t.full)e=t.full;else if("dctypes:Image"===t.full["@type"])e={id:t.full["@id"],type:"Image"};else{if("sc:Canvas"!==t.full["@type"])throw new Error(`Unsupported source type on annotation: ${t.full["@type"]}`);e={id:t.full["@id"],type:"Canvas"}}return{type:"SpecificResource",source:e,selector:Z(t.selector)}}return encodeURI(t["@id"]).trim()}(e.on),body:Array.isArray(e.resource)?e.resource.map(K):K(e.resource)})}],contentResource:[K],choice:[function(e){const t=[];return e.default&&"rdf:nil"!==e.default&&t.push(e.default),e.item&&"rdf:nil"!==e.item&&t.push(...e.item),{...B(e),...G(e),items:t}}],range:[function(e){return I({...B(e),...G(e),...Y(e),items:e.members})}],service:[function(e){const{"@id":t,"@type":i,"@context":r,profile:n,...s}=e,a={};return t&&(a["@id"]=t),a["@type"]=_(e),"unknown"===a["@type"]&&(r&&r.length&&(a["@context"]=r),a["@type"]="Service"),n&&(a.profile=E(n)),I({...a,...s})}],layer:[function(e){return I({...B(e),...G(e),...Y(e)})}]});function Z(e){if((Array.isArray(e["@type"])&&e["@type"].includes("oa:SvgSelector")||"oa:SvgSelector"==e["@type"])&&("chars"in e||"value"in e))return{type:"SvgSelector",value:"chars"in e?e.chars:e.value};if("oa:FragmentSelector"===e["@type"])return{type:"FragmentSelector",value:e.value};if("oa:Choice"===e["@type"])return[Z(e.default),...(Array.isArray(e.item)?e.item:[e.item]).map(Z)];if("iiif:ImageApiSelector"==e["@type"])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 ee(e,t={}){if(Array.isArray(e))return ee(e[0]);if("string"==typeof e){const[i,r]=e.split("#");return r?{type:"SpecificResource",source:{id:i,type:t.typeHint||"Unknown"},selector:{type:"FragmentSelector",value:r}}:{type:"SpecificResource",source:{id:i,type:t.typeMap&&t.typeMap[i]||t.typeHint||"Unknown"}}}if("Choice"===e.type||"List"===e.type||"Composite"===e.type||"Independents"===e.type)return ee(e.items[0]);if("SpecificResource"===e.type)return"Canvas"===e.source.type&&e.source.partOf&&"string"==typeof e.source.partOf&&(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){"Canvas"===e.type&&e.partOf&&"string"==typeof e.partOf&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[t,i]=e.id.split("#");return i?{type:"SpecificResource",source:{...e,id:t},selector:{type:"FragmentSelector",value:i}}:{type:"SpecificResource",source:{...e,id:t}}}return{type:"SpecificResource",source:e}}function te(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}function ie(e,t){if("string"==typeof e)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 re(e,t,i){if(!t)return e;if(Array.isArray(e)){if(!Array.isArray(t))throw new Error("Cannot merge array with non-array");const i=[...e];for(const r of t)if(r["@id"]&&!r.id&&(r.id=r["@id"]),r["@type"]&&!r.type&&(r.type=r["@type"]),null!=r)if(Array.isArray(r))i.push(r);else if("object"==typeof r&&r.id&&r.type){const e=i.findIndex((e=>e.id===r.id&&e.type===r.type));e>=0&&(i[e]=re(i[e],r))}else-1===e.indexOf(r)&&i.push(r);return i}if("object"==typeof e){if(Array.isArray(t)||"object"!=typeof t)throw new Error("Cannot merge object with non-object");const r={...e},o=[],c=[],l=Object.keys(e).filter((e=>e!==s&&"id"!==e&&"type"!==e)),u={},v={};for(const[e,i]of Object.entries(t)){if(e===s||"id"===e||"type"===e)continue;const t=r[e];t===i?c.push(e):t!==p&&t?(t&&i&&(u[e]=t,v[e]=i),r[e]=re(t,i),r[e]===u[e]&&(c.push(e),delete u[e])):(o.push(e),r[e]=i)}if(i&&(i.parent&&i.parent.id||i.isTopLevel)){const t=[],p={};if(i.parent?p[a]=i.parent.id:i.isTopLevel&&(p[a]=e.id),r[s]&&r[s].length){const e=!(r[s]||[]).find((e=>e["@explicit"])),i=o.length>0||c.length!==l.length;if(e&&i)for(const a of r[s]){const e={...a},i=Object.keys(u);if(e){e["@explicit"]=!0;for(const t of l)t!==s&&(e[t]=n);for(const t of i)e[t]=u[t]}t.push(e)}else t.push(...r[s]);if(i){const e=Object.keys(v);p["@explicit"]=!0;for(const t of o)p[t]=n;for(const t of c)p[t]=n;for(const t of e)p[t]=v[t]}}p.id=r.id,p.type=r.type,t.push(p),r[s]=t}return r}return e||t}function ne(e,t,i){if("string"==typeof e)return e;if(t.id!==e.id||t.type!==e.type){if("ImageService3"===t.type)return t;if("ImageService3"===e.type)return e;throw new Error(`Can only merge entities with identical identifiers and type! ${t.type}(${t.id}) => ${e.type}(${e.id})`)}return re({...e},t,i)}function se(e){return t=>{e.Service=e.Service?e.Service:{};const i=t.id||t["@id"],r=function(e){const t=Object.assign({},e);if(t["@id"]&&(t.id=t["@id"]),t["@type"]&&(t.type=t["@type"]),t.service){const e=[];t.service=Array.isArray(t.service)?t.service:[t.service];for(const i of t.service)e.push({id:i["@id"]||i.id,type:i["@type"]||i.type});t.service=e}return Object.assign({},b,t)}(t);return r&&r.id&&(e.Service[r.id]?e.Service[i]=ne(e.Service[i],r):e.Service[i]=r),t}}function ae(e){const t=JSON.stringify(e);let i=5381,r=t.length;for(;r;)i=33*i^t.charCodeAt(--r);const n=(i>>>0).toString(16);return n.length%2?"0"+n:n}function oe(e){return t=>"string"==typeof t?{id:t,type:e}:t.id?t.type?t:{type:e,...t}:{id:`vault://${ae(t)}`,type:e,...t}}function ce(e){return t=>({...e,...t})}function le(e){return Array.isArray(e)?e:[e]}function pe(e){return e.body&&(e.body=le(e.body)),e.seeAlso&&(e.seeAlso=le(e.seeAlso)),e.audience&&(e.audience=le(e.audience)),e.accessibility&&(e.accessibility=le(e.accessibility)),e.motivation&&(e.motivation=le(e.motivation)),e}function ue(e,{typeHint:t,partOfTypeHint:r}={}){if("string"==typeof e&&(e={id:e,type:t||"unknown"}),i(e))return"string"==typeof e.source&&(e.source={id:e.source,type:t||"unknown"}),"Canvas"===e.source.type&&e.source.partOf&&"string"==typeof e.source.partOf&&(e.source.partOf=[{id:e.source.partOf,type:r||"Manifest"}]),e;let n;if(-1!==(e.id||"").indexOf("#")){const[t,i]=(e.id||"").split("#");e.id=t,i&&(n={type:"FragmentSelector",value:i})}return{type:"SpecificResource",source:e,selector:n}}function ve(e){const t=Object.assign({},e);return e&&e.items&&(t.items=e.items.map((e=>"string"==typeof e||"Canvas"===e.type?ue(e):e))),t}function fe(e){const t=Object.assign({},e);return t.start?(t.start=ue(t.start,{typeHint:"Canvas"}),t):e}function he(e){const t=Object.assign({},e);return t.target?(t.target=ee(t.target,{typeHint:"Canvas"}),t):e}function ye(e){return e}function de(e){return void 0===e.items&&(e[o]=!0),e}function me(e){const t={};for(const[i,r]of e){if(i===l&&r!==c)return r;r!==c&&null!=r&&(t[i]=r)}return t}function ge(e,{allowSourceString:t=!0,allowString:i=!1,allowedStringType:r}={}){const n=e=>{if(t&&e&&e.source&&"string"!=typeof e.source){const t=Object.keys(e.source);if(e.source.id&&e.source.type&&2===t.length)return{...e,source:e.source.id}}return e};if(e){if(e.source&&e.source.partOf)return n(e);const t=Object.keys(e);if(2===t.length&&e.type&&e.source||3===t.length&&e.type&&e.source&&-1!==t.indexOf("selector")&&!e.selector)return!i||r&&r!==e.source.type?"ContentResource"===e.source.type?{type:"SpecificResource",source:e.source.id}:e.source:e.source.id;if(e.selector&&!Array.isArray(e.selector)&&"string"!=typeof e.selector&&"FragmentSelector"===e.selector.type){const t=`${e.source.id}#${e.selector.value}`;return i?t:{id:t,type:e.source.type}}}return n(e)}function Ae(e){if(!e)return;const t=Object.keys(e);if(0!==t.length){if(1===t.length){const i=t[0];if(!i)return"";const r=(e[i]||[]).join("");return"@none"===i||"none"===i||"en"===i?r:{"@language":i,"@value":r}}return t.map((t=>({"@language":t,"@value":(e[t]||[]).join("")})))}}function Ce(e){return Array.isArray(e)?e.map((e=>Ce(e))):"string"==typeof e?e:e.type&&"Canvas"===e.type?e.id:e}function be(e,t=!1){if(e)return e.length>1&&!t?e:e[0]||void 0}function Re(e){if(e){if("string"==typeof e)return{"@id":e};if("@id"in e){const 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 Se(e,t){return[["@id",e.id],["@type",t],["format",e.format],["height",e.height],["width",e.width],["viewingDirection","left-to-right"!==e.viewingDirection?e.viewingDirection:void 0],["license",e.license?e.license:void 0]]}function*we(e){const t=e.provider?yield e.provider[0]:void 0;return[["label",Ae(e.label)],["metadata",e.metadata&&e.metadata.length?e.metadata.map((e=>({label:Ae(e.label)||"",value:Ae(e.value)||""}))):void 0],["description",Ae(e.summary)],["thumbnail",be(yield e.thumbnail)],["navDate",e.navDate],["logo",t?be(t.logo):void 0],["homepage",t?t.homepage:void 0],["attribution",e.requiredStatement?Ae(e.requiredStatement.value):void 0]]}function*xe(e){const t=e.start&&e.start.type&&"SpecificResource"===e.start.type?ge(e.start):e.start;return[["seeAlso",be(yield e.seeAlso)],["service",be((e.service||[]).map(Re))],["rendering",be(yield e.rendering)],["startCanvas",t?t.id:void 0]]}function je(e){if(e&&function(e){return"SpecificResource"===e.type}(e)){let t=e.id;const i=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return function(e){return e&&"FragmentSelector"===e.type}(i)&&(t+="#"+i.value),t}return null==e?void 0:e.id}const Oe={Manifest:function*(e,t,{isTopLevel:i}){return[...i?[["@context","http://iiif.io/api/presentation/2/context.json"]]:[],...Se(e,"sc:Manifest"),...yield*we(e),...yield*xe(e),["sequences",[{"@id":`${e.id}/sequence0`,"@type":"sc:Sequence",canvases:yield e.items}]],["structures",yield e.structures]]},Canvas:function*(e){const t=(yield e.items)[0];return[...Se(e,"sc:Canvas"),...yield*we(e),...yield*xe(e),["images",t?[t.resources]:void 0],["annotations",e.annotations&&e.annotations.length?be(yield e.annotations):void 0]]},AnnotationPage:function*(e){return[...Se(e,"sc:AnnotationList"),...yield*we(e),["resources",e.items&&e.items.length?be(yield e.items):void 0]]},Annotation:function*(e){return[["@id",e.id],["@type","oa:Annotation"],["motivation","sc:painting"],["on",Ce(e.target)],["resource",be(yield e.body,!0)]]},ContentResource:function*(e){return"Image"===e.type?[...Se(e,"dctypes:Image"),...yield*we(e),...yield*xe(e)]:[...Se(e,void 0),...yield*we(e)]},AnnotationCollection:function*(e){return[["@id",e.id],["@type","sc:Layer"],["label",Ae(e.label)]]},Collection:function*(e){return[...Se(e,"sc:Collection"),...yield*we(e),...yield*xe(e),["members",yield*e.items]]},Range:function*(e){const t=[],i=[];if(e.items)for(const r of e.items){const n="SpecificResource"===r.type?r.source:r;if(n){const s=yield n;t.push({"@id":je(r),"@type":n.type,label:s?s.label:void 0,within:e.id}),"Canvas"===n.type&&i.push(n.id)}}return[...Se(e,"sc:Range"),...yield*we(e),...yield*xe(e),["canvases",i.length===t.length?i:void 0],["members",i.length!==t.length?t:void 0]]}};function Te(e){var t;return[["id",(null==(t=e.id)?void 0:t.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","left-to-right"!==e.viewingDirection?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],[s,c]]}function Le(e){if(e===c)return;if(!e||0===e.length)return;const t=e.filter((e=>e!==c));return 0!==t.length?t:void 0}function ke(e){if(e&&e.type&&"ImageService2"===e.type){const{id:t,type:i,profile:r,...n}=e,s="string"==typeof r?r:Array.isArray(r)?r.find((e=>"string"==typeof e)):"";return{"@id":t,"@type":i,profile:s?s.startsWith("http")?s:`http://iiif.io/api/image/2/${s}.json`:"http://iiif.io/api/image/2/level0.json",...n}}return e}function Ie(e){if(Array.isArray(e)||(e=e?[e]:[]),e&&0!==e.length)return e.map(ke)}function*Pe(e){return[["label",e.label],["metadata",Le(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",Le(yield e.thumbnail)],["placeholderCanvas",yield e.placeholderCanvas],["accompanyingCanvas",yield e.accompanyingCanvas],["provider",Le(yield e.provider)]]}function*Me(e){return[["seeAlso",Le(yield e.seeAlso)],["service",Le(Ie(e.service))],["services",Le(Ie(e.services))],["rendering",Le(yield e.rendering)],["supplementary",Le(yield e.supplementary)],["homepage",Le(yield e.homepage)],["logo",Le(yield e.logo)],["partOf",Le(yield e.partOf)],["start",e.start?ge(e.start):e.start]]}const De={Manifest:function*(e,t,{isTopLevel:i}){return i?[["@context",e["@context"]?e["@context"]:"http://iiif.io/api/presentation/3/context.json"],...Te(e),...yield*Pe(e),...yield*Me(e),["items",yield e.items],["structures",Le(yield e.structures)],["annotations",Le(yield e.annotations)],["navPlace",e.navPlace]]:[...Te(e),...yield*Pe(e)]},Canvas:function*(e){return[...Te(e),...yield*Pe(e),...yield*Me(e),["items",yield e.items],["annotations",Le(yield e.annotations)],["navPlace",e.navPlace]]},Agent:function*(e){return[["id",e.id],["type","Agent"],["label",e.label],...yield*Me(e)]},AnnotationPage:function*(e){var t;const i=Object.entries(e).map((([e,t])=>[e,Array.isArray(t)?Le(t):t])).filter((([e,t])=>"items"!==e&&"id"!==e&&e!==s&&e!==a&&e!==o)),r=yield e.items;return[["id",(null==(t=e.id)?void 0:t.startsWith("vault://"))?void 0:e.id],...i,...yield*Me(e),["items",r.length||!1===e[o]?r:c]]},Service:function*(e){return[[l,ke(e)]]},Annotation:function*(e){const t=Object.entries(e).map((([e,t])=>"motivation"===e?[e,Array.isArray(t)?t[0]:t]:"target"===e?[e,ge(t,{allowString:!0,allowSourceString:!0,allowedStringType:"Canvas"})]:[e,Array.isArray(t)?Le(t):t])).filter((([e])=>"body"!==e&&e!==s&&e!==o));let r;if(Array.isArray(e.body)){const t=[];for(const r of e.body)if(r&&i(r)){const e={...r};e.source=yield r.source,t.push(ge(e,{allowSourceString:!0}))}else t.push(yield r);r=t}else e.body&&i(e.body)?(r={...e.body},r.source=yield e.body.source):r=yield e.body;return[...t,...yield*Pe(e),...yield*Me(e),["body",1===r.length?r[0]:r]]},ContentResource:function*(e){return function(e,t){const i=Object.keys(t),r=e.map((([e])=>e));for(const n of i)n!==s&&n!==o&&-1===r.indexOf(n)&&void 0!==t[n]&&e.push([n,t[n]]);return e}([...Te(e),...yield*Pe(e),...yield*Me(e),["annotations",Le(yield e.annotations)],["items",Le(yield e.items)]],e)},AnnotationCollection:function*(e){return[["id",e.id],["type","AnnotationCollection"],["label",e.label]]},Collection:function*(e,t,{isTopLevel:i}){return i?[["@context","http://iiif.io/api/presentation/3/context.json"],...Te(e),...yield*Pe(e),...yield*Me(e),["items",Le(yield e.items)],["navPlace",e.navPlace]]:[...Te(e),...yield*Pe(e)]},Range:function*(e){const t=[];for(const i of e.items)"Range"===i.type?t.push(yield i):i&&"SpecificResource"===i.type?t.push(ge(i)):t.push(i);return[...Te(e),...yield*Pe(e),...yield*Me(e),["items",t],["annotations",Le(yield e.annotations)],["navPlace",e.navPlace]]}};exports.EMPTY=p,exports.HAS_PART=s,exports.IS_EXTERNAL=o,exports.PART_OF=a,exports.Traverse=j,exports.UNSET=c,exports.UNWRAP=l,exports.WILDCARD=n,exports.addFlagForExternalResource=de,exports.compressSpecificResource=ge,exports.defaultEntities={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}},exports.emptyAgent=C,exports.emptyAnnotation=h,exports.emptyAnnotationPage=y,exports.emptyCanvas=d,exports.emptyCollection=m,exports.emptyManifest=g,exports.emptyRange=A,exports.emptyService=b,exports.frameResource=v,exports.getDefaultEntities=te,exports.identifyResource=x,exports.isSpecificResource=i,exports.isWildcard=u,exports.languageString2to3=Ae,exports.merge=re,exports.mergeEntities=ne,exports.normalize=function(e){const t=function(e){return e&&e["@context"]&&("http://iiif.io/api/presentation/2/context.json"===e["@context"]||-1!==e["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")||"http://www.shared-canvas.org/ns/context.json"===e["@context"])||"http://iiif.io/api/image/2/context.json"===e["@context"]?Q.traverseUnknown(e):e}(e),i={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}},r={},n=function(e,t){return(i,r)=>{const n=e[i]?e[i]:{};return(e,s)=>{const a=ie(e,r||i);return a&&a.id&&i?(n[a.id]=n[a.id]?ne(n[a.id],a,{parent:s.parent,isTopLevel:t.id===a.id}):ne({id:a.id,type:a.type},a,{parent:s.parent,isTopLevel:t.id===a.id}),{id:a.id,type:"ContentResource"===i?i:a.type}):a}}}(i,t),s=function(e){return(t,i)=>r=>{const{id:n,type:s}=ie(r,i||t);if(void 0===n)throw new Error("Found invalid entity without an ID.");return e[n]="ContentResource"===t||"Service"===t?t:s,r}}(r);return{entities:i,resource:new j({collection:[de,ce(m),s("Collection"),n("Collection")],manifest:[de,ce(g),fe,s("Manifest"),n("Manifest")],canvas:[ce(d),s("Canvas"),n("Canvas")],annotationPage:[de,oe("AnnotationPage"),ce(y),s("AnnotationPage"),n("AnnotationPage")],annotation:[oe("Annotation"),pe,he,s("Annotation"),n("Annotation")],contentResource:[oe("ContentResource"),s("ContentResource"),n("ContentResource")],range:[ce(A),ve,s("Range","Canvas"),n("Range","Canvas")],agent:[ce(C),s("Agent"),n("Agent")],specificResource:[ye],service:[se(i)]}).traverseUnknown(t),mapping:r}},exports.resolveIfExists=f,exports.serialize=function(e,t,i){if(!t.type||!t.id)throw new Error("Unknown entity");if(!i[t.type])throw new Error(`Serializer not found for ${t.type}`);return function r(n,s,a=0){const o=i[n.type];if(!o)return c;if(a>20)throw new Error("Circular reference: "+n.id+" "+n.type);const[l,p]=f(e,n.type?n:n.id,s)||(n.id&&n.type?n:null);if(!l)return c;const u=o(l,e,{parent:s,isTopLevel:t.id===n.id,fullResource:p});let v=u.next();for(;!v.done;){const e=v.value;let t=c;if(e)if(Array.isArray(e)){const i=[];for(const t of e)i.push(r(t,n,a+1));t=i}else t=r(e,n,a+1);v=u.next(t)}return v.value===c?c:me(v.value)}(t)},exports.serializeConfigPresentation2=Oe,exports.serializeConfigPresentation3=De,exports.serializedFieldsToObject=me,exports.toRef=r,exports.traverseSpecificResource=ye,exports.types=w; | ||
| "use strict";var e=Object.defineProperty,t=(t,i,r)=>(((t,i,r)=>{i in t?e(t,i,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[i]=r})(t,"symbol"!=typeof i?i+"":i,r),r);function i(e){return"string"!=typeof e&&(!!e&&"SpecificResource"===e.type)}function r(e,t){const n=t||"unknown";if(!e)return;if("string"==typeof e)return{id:e,type:n};if(i(e))return r(e.source,t);let s=n&&"unknown"!==n?n:e.type||e["@type"];const a=e.id||e["@id"];return s&&-1!==s.indexOf(":")&&(s=s.split(":").pop()),a&&s?{id:a,type:s}:void 0}Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n={},s="iiif-parser:hasPart",a="iiif-parser:partOf",o="iiif-parser:isExternal",c="__$UNSET$__",l="__$UNWRAP$__",p=[];function u(e){if(e===n||0===Object.keys(e).length)return!0;for(const t in e)return!1;return!0}function v(e,t){if(t&&t["@explicit"]){const i={},r=Object.keys(t);for(const n of r)n!==a&&"@explicit"!==n&&(u(t[n])?i[n]=e[n]:i[n]=t[n]);return i}return e}function f(e,t,i){const n=r(t);if(!n)return[void 0,void 0];const o=e.requests[n.id],c=n.type||e.mapping[n.id];if(!c||o&&o.resourceUri&&!e.entities[c][o.resourceUri])return[void 0,void 0];const l=e.entities[c][o?o.resourceUri:n.id];if(n.type&&!l)return f(e,{id:n.id},i);if(l&&l[s]){const e=l[s].find((e=>i?e[a]===i.id:e[a]===l.id));return[v(l,e),l]}return[l,l]}Object.freeze(p),Object.freeze(n);const h={id:"https://iiif-parser/annotation",type:"Annotation",behavior:p,label:null,thumbnail:p,summary:null,requiredStatement:null,metadata:p,seeAlso:p,homepage:p,rendering:p,service:p,accessibility:p,audience:p,body:p,bodyValue:null,canonical:null,created:null,creator:p,generated:null,generator:p,modified:null,motivation:p,rights:null,stylesheet:null,target:p,timeMode:void 0,via:p,partOf:p},y={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:p,label:null,thumbnail:p,summary:null,requiredStatement:null,metadata:p,rights:null,provider:p,items:p,seeAlso:p,homepage:p,rendering:p,service:p},d={id:"https://iiif-parser/empty-canvas",type:"Canvas",label:null,behavior:p,thumbnail:p,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:p,rights:null,navDate:null,provider:p,items:p,annotations:p,seeAlso:p,homepage:p,partOf:p,rendering:p,service:p,duration:0,height:0,width:0},m={id:"https://iiif-parser/empty-collection",type:"Collection",label:null,viewingDirection:"left-to-right",behavior:p,thumbnail:p,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:p,rights:null,navDate:null,provider:p,items:p,annotations:p,seeAlso:p,homepage:p,partOf:p,rendering:p,service:p,services:p},g={id:"https://iiif-parser/empty-manifest",type:"Manifest",annotations:p,behavior:p,homepage:p,items:p,label:null,metadata:p,navDate:null,provider:p,partOf:p,accompanyingCanvas:null,placeholderCanvas:null,rendering:p,requiredStatement:null,rights:null,seeAlso:p,service:p,services:p,start:null,structures:p,summary:null,thumbnail:p,viewingDirection:"left-to-right"},A={id:"https://iiif-parser/empty-canvas",type:"Range",label:null,behavior:p,thumbnail:p,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:p,rights:null,navDate:null,provider:p,items:p,annotations:p,seeAlso:p,homepage:p,partOf:p,rendering:p,service:p,start:null,supplementary:null,viewingDirection:"left-to-right"},C={id:"https://iiif-parser/empty-agent",type:"Agent",label:{},logo:p,seeAlso:p,homepage:p},b={id:"https://iiif-parser/empty-service",type:"UnknownService"};function R(e){return Array.isArray(e)?e:e?[e]:[]}function S(...e){return t=>e.reduce(((e,t)=>t(e)),t)}const w=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function x(e,t){if(null==e)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("object"!=typeof e){if(t)return t;throw new Error(typeof e+" is not a valid entity")}if("string"==typeof e.type){const t=w.indexOf(e.type);if(-1!==t)return w[t]}if(e.profile)return"Service";throw new Error("Resource type is not known")}class j{constructor(e,i={}){t(this,"traversals"),t(this,"options"),t(this,"_traverseManifest",S(this.traverseManifestItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseManifestStructures.bind(this),this.traverseInlineAnnotationPages.bind(this))),t(this,"_traverseCanvas",S(this.traverseCanvasItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseInlineAnnotationPages.bind(this))),t(this,"_traverseAnnotationPage",S(this.traverseAnnotationPageItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this))),t(this,"_traverseRange",S(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,...i}}static all(e){return new j({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=R(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=R(e.service).map((e=>this.traverseService(e)))),e.services&&(e.services=R(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=>"string"!=typeof t&&t.type?"Canvas"===t.type?this.traverseType(t,{parent:e},this.traversals.canvas):"AnnotationCollection"===t.type?this.traverseType(t,{parent:e},this.traversals.annotationCollection):"Collection"===t.type?this.traverseType(t,{parent:e},this.traversals.collection):this.traverseType(t,{parent:e},this.traversals.contentResource):this.traverseType(t,{parent:e},this.traversals.contentResource)))),e.start&&(i(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((e=>"Collection"===e.type?this.traverseCollection(e):this.traverseManifest(e))),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((e=>this.traverseCanvas(e)))),e}traverseManifestStructures(e){return e.structures&&(e.structures=e.structures.map((e=>this.traverseRange(e)))),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"string"!=typeof e&&e?(e.annotations&&(e.annotations=e.annotations.map((t=>this.traverseAnnotationPage(t,e)))),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"string"!=typeof e&&e?(e&&e.service&&(e.service=R(e.service||[]).map((t=>this.traverseService(t,e)))),e):e}traverseContentResource(e,t){return"Choice"===e.type&&(e.items=e.items.map((t=>this.traverseContentResource(t,e)))),i(e)?this.traverseSpecificResource(e,"ContentResource"):this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)),{parent:t},this.traversals.contentResource)}traverseSpecificResource(e,t,i){let r=e.source;return"string"==typeof e.source&&(r={id:e.source,type:t||"unknown"}),this.traverseType({...e,source:"Canvas"===t||"Canvas"===r.type?this.traverseType(r,{parent:i},this.traversals.canvas):"ContentResource"===t?this.traverseContentResource(r,{parent:i}):this.traverseUnknown(r,{parent:i,typeHint:t})},{parent:i},this.traversals.specificResource)}traverseRangeRanges(e){return e.items&&(e.items=e.items.map((t=>"string"==typeof t?this.traverseCanvas({id:t,type:"Canvas"},e):i(t)?this.traverseSpecificResource(t,"Canvas",e):"Manifest"===t.type?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,i){return i.reduce(((e,i)=>{const r=i(e,t);return void 0!==r||this.options.allowUndefinedReturn?r:e}),e)}traverseService(e,t){const i=Object.assign({},e);return i&&i.service&&(i.service=R(i.service).map((e=>this.traverseService(e)))),this.traverseType(i,{parent:t},this.traversals.service)}traverseUnknown(e,{parent:t,typeHint:i}={}){const r=x(e,i);switch(r){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:if(i)return i;throw new Error(`Unknown or unsupported resource type of ${r}`)}}}const O=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];class T{constructor(e,i={}){t(this,"traversals"),t(this,"options"),this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...i}}static all(e){return new T({collection:[e],manifest:[e],canvas:[e],annotationList:[e],sequence:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],layer:[e]})}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))),this.traversals.collection)}traverseCollectionItems(e){if(this.options.mergeMemberProperties){const t=[...(e.manifests||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Manifest"}:e)),...(e.collections||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Collection"}:e)),...e.members||[]];delete e.collections,delete e.manifests,e.members=t}return e.manifests&&(e.manifests=e.manifests.map((e=>this.traverseManifest("string"==typeof e?{"@id":e,"@type":"sc:Manifest"}:e)))),e.collections&&(e.collections=e.collections.map((e=>this.traverseCollection("string"==typeof e?{"@id":e,"@type":"sc:Collection"}:e)))),e.members&&(e.members=e.members.map((e=>"string"==typeof e?e:this.traverseUnknown(e)))),e}traverseManifest(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))),this.traversals.manifest)}traverseManifestItems(e){return e.sequences&&(e.sequences=e.sequences.map((e=>this.traverseSequence(e)))),e.structures&&(e.structures=e.structures.map((e=>this.traverseRange(e)))),e}traverseSequence(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))),this.traversals.sequence)}traverseSequenceItems(e){return e.canvases&&(e.canvases=e.canvases.map((e=>this.traverseCanvas(e)))),e}traverseCanvas(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))),this.traversals.canvas)}traverseCanvasItems(e){return e.images&&(e.images=e.images.map((e=>this.traverseAnnotation(e)))),e.otherContent&&(e.otherContent=e.otherContent.map((e=>this.traverseAnnotationList(e)))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const t=[...(e.ranges||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Range"}:e)),...(e.canvases||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Canvas"}:e)),...e.members||[]];delete e.ranges,delete e.canvases,e.members=t.length?t.map((e=>this.traverseUnknown(e))):void 0}return e}traverseAnnotationList(e){const t="string"==typeof e?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(t)),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map((e=>this.traverseAnnotation(e)))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(Array.isArray(e.resource)?e.resource=e.resource.map((e=>this.traverseContentResource(e))):e.resource=this.traverseContentResource(e.resource)),e.on,e}traverseLayer(e){return this.traverseType(this.traverseLinking(this.traverseLayerItems(e)),this.traversals.layer)}traverseLayerItems(e){return e.otherContent&&(e.otherContent=e.otherContent.map((e=>this.traverseAnnotationList(e)))),e}traverseChoice(e){return this.traverseType(this.traverseChoiceItems(e),this.traversals.choice)}traverseChoiceItems(e){return e.default&&"rdf:nil"!==e.default&&(e.default=this.traverseContentResource(e.default)),e.item&&"rdf:nil"!==e.item&&(e.item=e.item.map((e=>this.traverseContentResource(e)))),e}traverseService(e){return this.traverseType(this.traverseLinking(e),this.traversals.service)}traverseContentResource(e){return"oa:Choice"===e["@type"]?this.traverseChoice(e):this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.contentResource)}traverseUnknown(e){if(!e["@type"]||"string"==typeof e)return e;switch(function(e){if(null==e)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("object"!=typeof e)throw new Error(typeof e+" is not a valid entity");if("string"==typeof e["@type"]){const t=O.indexOf(e["@type"]);if(-1!==t)return O[t]}if(e.profile)return"Service";if(e.format)return"ContentResource";if(e["@type"])return"ContentResource";throw new Error("Resource type is not known")}(e)){case"sc:Collection":return this.traverseCollection(e);case"sc:Manifest":return this.traverseManifest(e);case"sc:Canvas":return this.traverseCanvas(e);case"sc:Sequence":return this.traverseSequence(e);case"sc:Range":return this.traverseRange(e);case"oa:Annotation":return this.traverseAnnotation(e);case"sc:AnnotationList":return this.traverseAnnotationList(e);case"sc:Layer":return this.traverseLayer(e);case"Service":return this.traverseService(e);case"oa:Choice":return this.traverseChoice(e);case"ContentResource":return this.traverseContentResource(e)}return e.profile?this.traverseService(e):e}traverseImageResource(e){const t=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(const n of i)"string"==typeof n?r.push(this.traverseContentResource({"@id":n,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(n));return t||this.options.convertPropsToArray?r:r[0]}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){const t=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(const n of i)r.push(this.traverseService(n));return t||this.options.convertPropsToArray?r:r[0]}traverseLinking(e){return e.related&&(e.related=this.traverseOneOrManyType(e.related,this.traversals.contentResource)),e.rendering&&(e.rendering=this.traverseOneOrManyType(e.rendering,this.traversals.contentResource)),e.service&&(e.service=this.traverseOneOrMoreServices(e.service)),e.seeAlso&&(e.seeAlso=this.traverseOneOrManyType(e.seeAlso,this.traversals.contentResource)),e.within&&("string"==typeof e.within||(e.within=this.traverseOneOrManyType(e.within,this.traversals.contentResource))),e.startCanvas&&("string"==typeof e.startCanvas?e.startCanvas=this.traverseType({"@id":e.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):e.startCanvas&&this.traverseType(e.startCanvas,this.traversals.canvas)),e.contentLayer&&("string"==typeof e.contentLayer?e.contentLayer=this.traverseLayer({"@id":e.contentLayer,"@type":"sc:Layer"}):e.contentLayer=this.traverseLayer(e.contentLayer)),e}traverseOneOrManyType(e,t){if(!Array.isArray(e)){if(!this.options.convertPropsToArray)return this.traverseType(e,t);e=[e]}return e.map((e=>this.traverseType(e,t)))}traverseType(e,t){return t.reduce(((e,t)=>{const i=t(e);return void 0!==i||this.options.allowUndefinedReturn?i:e}),e)}}const L=["http://iiif.io/api/image/2/level1","http://iiif.io/api/image/2/level2","http://library.stanford.edu/iiif/image-api/compliance.html#level1","http://library.stanford.edu/iiif/image-api/compliance.html#level2","http://library.stanford.edu/iiif/image-api/conformance.html#level1","http://library.stanford.edu/iiif/image-api/conformance.html#level2","http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1","http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2","http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1","http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2","http://iiif.io/api/image/1/level1.json","http://iiif.io/api/image/1/profiles/level1.json","http://iiif.io/api/image/1/level2.json","http://iiif.io/api/image/1/profiles/level2.json","http://iiif.io/api/image/2/level1.json","http://iiif.io/api/image/2/profiles/level1.json","http://iiif.io/api/image/2/level2.json","http://iiif.io/api/image/2/profiles/level2.json","level1","level2"],k=["http://iiif.io/api/image/2/level0","http://iiif.io/api/image/2/level1","http://iiif.io/api/image/2/level2","http://library.stanford.edu/iiif/image-api/compliance.html#level0","http://library.stanford.edu/iiif/image-api/compliance.html#level1","http://library.stanford.edu/iiif/image-api/compliance.html#level2","http://library.stanford.edu/iiif/image-api/conformance.html#level0","http://library.stanford.edu/iiif/image-api/conformance.html#level1","http://library.stanford.edu/iiif/image-api/conformance.html#level2","http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0","http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1","http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2","http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0","http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1","http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2","http://iiif.io/api/image/1/level0.json","http://iiif.io/api/image/1/profiles/level0.json","http://iiif.io/api/image/1/level1.json","http://iiif.io/api/image/1/profiles/level1.json","http://iiif.io/api/image/1/level2.json","http://iiif.io/api/image/1/profiles/level2.json","http://iiif.io/api/image/2/level0.json","http://iiif.io/api/image/2/profiles/level0.json","http://iiif.io/api/image/2/level1.json","http://iiif.io/api/image/2/profiles/level1.json","http://iiif.io/api/image/2/level2.json","http://iiif.io/api/image/2/profiles/level2.json","level0","level1","level2"];function I(e){for(const t in e)void 0!==e[t]&&null!==e[t]||delete e[t];return e}const P="Attribution",M="http://example.org/provider",D="Unknown";function q(e,t="none"){if(!e)return{};const i=function(e){if("string"==typeof e)return[e];if(!e)return[];const t=Array.isArray(e)?e:[e],i=[];for(const r of t)"string"!=typeof r?i.push({"@language":r["@language"]||r.language,"@value":r["@value"]||r.value}):i.push(r);return i}(e),r={};for(const n of i){if("string"==typeof n){r[t]=r[t]?r[t]:[],r[t].push(n||"");continue}if(!n["@language"]){r[t]=r[t]?r[t]:[],r[t].push(n["@value"]||"");continue}const e=n["@language"];r[e]=r[e]?r[e]:[],r[e].push(n["@value"]||"")}return r}function E(e){return Array.isArray(e)?E(e.find((e=>"string"==typeof e))):-1!==k.indexOf(e)?"level2":-1!==L.indexOf(e)?"level1":"string"==typeof e?e:void 0}function U(e){for(const t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}const $=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function _(e){const t=e["@id"]||e.id;let i=e["@type"]||e.type;const r=e.profile||void 0,n=e["@context"]||void 0;if(r){const e=function(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"}}(r);if(e)return e}if(n){const e=function(e){const t=Array.isArray(e)?e:[e];for(const i of t)switch(i){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}(n);if(e)return e}if(i){if(Array.isArray(i)){if(-1!==i.indexOf("oa:CssStylesheet"))return"CssStylesheet";if(-1!==i.indexOf("cnt:ContentAsText"))return"TextualBody";i=i[0]}for(const e of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${e}:`)){i=i.slice(e.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(i&&-1!==$.indexOf(i))return i;if(e.format){if(e.format.startsWith("image/"))return"Image";if(e.format.startsWith("text/"))return"Text";if("application/pdf"===e.format)return"Text";if(e.format.startsWith("application/"))return"Dataset"}return t&&(t.endsWith(".jpg")||t.endsWith(".png")||t.endsWith(".jpeg"))?"Image":i||"unknown"}const W=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function H(e){const t=e.match(W);return t?t[0]:e}const F=["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 N(e){if(e){const t=Array.isArray(e)?e:[e],i=[];for(const e of t)"http://iiif.io/api/presentation/2/context.json"===e&&i.push("http://iiif.io/api/presentation/3/context.json"),-1===F.indexOf(e)&&i.push(e);if(t.length)return 1===i.length?i[0]:i}}let z=0;function J(e,t){const i=encodeURI(e.id||e["@id"]||"").trim();return i&&t?`${i}/${t}`:i||(z++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${z}`)}function B(e){const t=[...e.behavior||[]];let i;return e.viewingHint&&t.push(e.viewingHint),Array.isArray(e.motivation)?i=e.motivation.map(U):e.motivation&&(i=U(e.motivation)),{"@context":e["@context"]?N(e["@context"]):void 0,id:(e["@id"]||J(e)).trim(),type:_(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:i,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function G(e){const[t,i]=function(e,t="Rights/License",i="none"){let r=null;const n=[],s=Array.isArray(e)?e:[e];for(const a of s){const e=a?H(a):void 0;!e||-1===e.indexOf("creativecommons.org")&&-1===e.indexOf("rightsstatements.org")?e&&n.push({label:{[i]:[t]},value:{[i]:[e]}}):r=e.startsWith("https://")?`http://${e.slice(8)}`:e}return[r,n]}(e.license),r=[...e.metadata?(n=e.metadata,n?n.map((e=>({label:q(e.label),value:q(e.value)}))):[]):[],...i];var n;return{rights:t,metadata:r.length?r:void 0,label:e.label?q(e.label):void 0,requiredStatement:e.attribution?{label:q(P),value:q(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?q(e.description):void 0,thumbnail:V(e.thumbnail)}}function V(e){if(e){return(Array.isArray(e)?e:[e]).map((e=>"string"==typeof e?{id:e,type:"Image"}:("unknown"===e.type&&(e.type="Image"),e)))}return e}function X(e){if(!e.within)return;const t=Array.isArray(e.within)?e.within:[e.within],i=[];for(const r of t)if("string"==typeof r){if(r&&"sc:Manifest"===e["@type"])i.push({id:r,type:"Collection"})}else r["@id"]&&i.push({id:r["@id"],type:_(r)});return i.length?i:void 0}function Y(e){const t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],i=e.contentLayer;return{provider:e.logo||t.length?[{id:M,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:q(D)}]:void 0,partOf:X(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?R(e.service):void 0,supplementary:i?[i]:void 0}}function K(e){const t=e;return I({...B(t),...G(t),...Y(t),...(i=t,{chars:i.chars,format:i.format?i.format:void 0,language:i.language})});var i}const Q=new T({collection:[function(e){return I({...B(e),...G(e),...Y(e),items:e.members})}],manifest:[function(e){const t=[],i=[];let r;for(const s of e.sequences||[])s.canvases.length&&t.push(...s.canvases),s.behavior&&i.push(...s.behavior),s.startCanvas&&(r=s.startCanvas);const n=B(e);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),I({...n,...G(e),...Y(e),start:r,items:t,structures:e.structures})}],canvas:[function(e){return I({...B(e),...G(e),...Y(e),annotations:e.otherContent&&e.otherContent.length?e.otherContent:void 0,items:e.images&&e.images.length?[{id:J(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}],annotationList:[function(e){return I({...B(e),...G(e),...Y(e),items:e.resources&&e.resources.length?e.resources:void 0})}],sequence:[function(e){return e.canvases&&0!==e.canvases.length?{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}:{canvases:[],behavior:[]}}],annotation:[function(e){return I({...B(e),...G(e),...Y(e),target:function e(t){if(Array.isArray(t)){if(t.length>1)return{type:"List",items:t.map(e)};t=t[0]}if("string"==typeof t)return encodeURI(t).trim();if("@type"in t){let e;if("string"==typeof t.full)e=t.full;else if("dctypes:Image"===t.full["@type"])e={id:t.full["@id"],type:"Image"};else{if("sc:Canvas"!==t.full["@type"])throw new Error(`Unsupported source type on annotation: ${t.full["@type"]}`);e={id:t.full["@id"],type:"Canvas"}}return{type:"SpecificResource",source:e,selector:Z(t.selector)}}return encodeURI(t["@id"]).trim()}(e.on),body:Array.isArray(e.resource)?e.resource.map(K):K(e.resource)})}],contentResource:[K],choice:[function(e){const t=[];return e.default&&"rdf:nil"!==e.default&&t.push(e.default),e.item&&"rdf:nil"!==e.item&&t.push(...e.item),{...B(e),...G(e),items:t}}],range:[function(e){return I({...B(e),...G(e),...Y(e),items:e.members})}],service:[function(e){const{"@id":t,"@type":i,"@context":r,profile:n,...s}=e,a={};return t&&(a["@id"]=t),a["@type"]=_(e),"unknown"===a["@type"]&&(r&&r.length&&(a["@context"]=r),a["@type"]="Service"),n&&(a.profile=E(n)),I({...a,...s})}],layer:[function(e){return I({...B(e),...G(e),...Y(e)})}]});function Z(e){if((Array.isArray(e["@type"])&&e["@type"].includes("oa:SvgSelector")||"oa:SvgSelector"==e["@type"])&&("chars"in e||"value"in e))return{type:"SvgSelector",value:"chars"in e?e.chars:e.value};if("oa:FragmentSelector"===e["@type"])return{type:"FragmentSelector",value:e.value};if("oa:Choice"===e["@type"])return[Z(e.default),...(Array.isArray(e.item)?e.item:[e.item]).map(Z)];if("iiif:ImageApiSelector"==e["@type"])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 ee(e,t={}){if(Array.isArray(e))return ee(e[0]);if("string"==typeof e){const[i,r]=e.split("#");return r?{type:"SpecificResource",source:{id:i,type:t.typeHint||"Unknown"},selector:{type:"FragmentSelector",value:r}}:{type:"SpecificResource",source:{id:i,type:t.typeMap&&t.typeMap[i]||t.typeHint||"Unknown"}}}if("Choice"===e.type||"List"===e.type||"Composite"===e.type||"Independents"===e.type)return ee(e.items[0]);if("SpecificResource"===e.type)return"Canvas"===e.source.type&&e.source.partOf&&"string"==typeof e.source.partOf&&(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){"Canvas"===e.type&&e.partOf&&"string"==typeof e.partOf&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[t,i]=e.id.split("#");return i?{type:"SpecificResource",source:{...e,id:t},selector:{type:"FragmentSelector",value:i}}:{type:"SpecificResource",source:{...e,id:t}}}return{type:"SpecificResource",source:e}}function te(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}function ie(e,t){if("string"==typeof e)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 re(e,t,i){if(!t)return e;if(Array.isArray(e)){if(!Array.isArray(t))throw new Error("Cannot merge array with non-array");const i=[...e];for(const r of t)if(r["@id"]&&!r.id&&(r.id=r["@id"]),r["@type"]&&!r.type&&(r.type=r["@type"]),null!=r)if(Array.isArray(r))i.push(r);else if("object"==typeof r&&r.id&&r.type){const e=i.findIndex((e=>e.id===r.id&&e.type===r.type));e>=0&&(i[e]=re(i[e],r))}else-1===e.indexOf(r)&&i.push(r);return i}if("object"==typeof e){if(Array.isArray(t)||"object"!=typeof t)throw new Error("Cannot merge object with non-object");const r={...e},o=[],c=[],l=Object.keys(e).filter((e=>e!==s&&"id"!==e&&"type"!==e)),u={},v={};for(const[e,i]of Object.entries(t)){if(e===s||"id"===e||"type"===e)continue;const t=r[e];t===i?c.push(e):t!==p&&t?(t&&i&&(u[e]=t,v[e]=i),r[e]=re(t,i),r[e]===u[e]&&(c.push(e),delete u[e])):(o.push(e),r[e]=i)}if(i&&(i.parent&&i.parent.id||i.isTopLevel)){const t=[],p={};if(i.parent?p[a]=i.parent.id:i.isTopLevel&&(p[a]=e.id),r[s]&&r[s].length){const e=!(r[s]||[]).find((e=>e["@explicit"])),i=o.length>0||c.length!==l.length;if(e&&i)for(const a of r[s]){const e={...a},i=Object.keys(u);if(e){e["@explicit"]=!0;for(const t of l)t!==s&&(e[t]=n);for(const t of i)e[t]=u[t]}t.push(e)}else t.push(...r[s]);if(i){const e=Object.keys(v);p["@explicit"]=!0;for(const t of o)p[t]=n;for(const t of c)p[t]=n;for(const t of e)p[t]=v[t]}}p.id=r.id,p.type=r.type,t.push(p),r[s]=t}return r}return e||t}function ne(e,t,i){if("string"==typeof e)return e;if(t.id!==e.id||t.type!==e.type){if("ImageService3"===t.type)return t;if("ImageService3"===e.type)return e;throw new Error(`Can only merge entities with identical identifiers and type! ${t.type}(${t.id}) => ${e.type}(${e.id})`)}return re({...e},t,i)}function se(e){return t=>{e.Service=e.Service?e.Service:{};const i=t.id||t["@id"],r=function(e){const t=Object.assign({},e);if(t["@id"]&&(t.id=t["@id"]),t["@type"]&&(t.type=t["@type"]),t.service){const e=[];t.service=Array.isArray(t.service)?t.service:[t.service];for(const i of t.service)e.push({id:i["@id"]||i.id,type:i["@type"]||i.type});t.service=e}return Object.assign({},b,t)}(t);return r&&r.id&&(e.Service[r.id]?e.Service[i]=ne(e.Service[i],r):e.Service[i]=r),t}}function ae(e){const t=JSON.stringify(e);let i=5381,r=t.length;for(;r;)i=33*i^t.charCodeAt(--r);const n=(i>>>0).toString(16);return n.length%2?"0"+n:n}function oe(e){return t=>"string"==typeof t?{id:t,type:e}:t.id?t.type?t:{type:e,...t}:{id:`vault://${ae(t)}`,type:e,...t}}function ce(e){return t=>({...e,...t})}function le(e){return Array.isArray(e)?e:[e]}function pe(e){return e.body&&(e.body=le(e.body)),e.seeAlso&&(e.seeAlso=le(e.seeAlso)),e.audience&&(e.audience=le(e.audience)),e.accessibility&&(e.accessibility=le(e.accessibility)),e.motivation&&(e.motivation=le(e.motivation)),e}function ue(e,{typeHint:t,partOfTypeHint:r}={}){if("string"==typeof e&&(e={id:e,type:t||"unknown"}),i(e))return"string"==typeof e.source&&(e.source={id:e.source,type:t||"unknown"}),"Canvas"===e.source.type&&e.source.partOf&&"string"==typeof e.source.partOf&&(e.source.partOf=[{id:e.source.partOf,type:r||"Manifest"}]),e;let n;if(-1!==(e.id||"").indexOf("#")){const[t,i]=(e.id||"").split("#");e.id=t,i&&(n={type:"FragmentSelector",value:i})}return{type:"SpecificResource",source:e,selector:n}}function ve(e){const t=Object.assign({},e);return e&&e.items&&(t.items=e.items.map((e=>"string"==typeof e||"Canvas"===e.type?ue(e):e))),t}function fe(e){const t=Object.assign({},e);return t.start?(t.start=ue(t.start,{typeHint:"Canvas"}),t):e}function he(e){const t=Object.assign({},e);return t.target?(t.target=ee(t.target,{typeHint:"Canvas"}),t):e}function ye(e){return e}function de(e){return void 0===e.items&&(e[o]=!0),e}function me(e){const t={};for(const[i,r]of e){if(i===l&&r!==c)return r;r!==c&&null!=r&&(t[i]=r)}return t}function ge(e,{allowSourceString:t=!0,allowString:i=!1,allowedStringType:r}={}){const n=e=>{if(t&&e&&e.source&&"string"!=typeof e.source){const t=Object.keys(e.source);if(e.source.id&&e.source.type&&2===t.length)return{...e,source:e.source.id}}return e};if(e){if(e.source&&e.source.partOf)return n(e);const t=Object.keys(e);if(2===t.length&&e.type&&e.source||3===t.length&&e.type&&e.source&&-1!==t.indexOf("selector")&&!e.selector)return!i||r&&r!==e.source.type?"ContentResource"===e.source.type?{type:"SpecificResource",source:e.source.id}:e.source:e.source.id;if(e.selector&&!Array.isArray(e.selector)&&"string"!=typeof e.selector&&"FragmentSelector"===e.selector.type){const t=`${e.source.id}#${e.selector.value}`;return i?t:{id:t,type:e.source.type}}}return n(e)}function Ae(e){if(!e)return;const t=Object.keys(e);if(0!==t.length){if(1===t.length){const i=t[0];if(!i)return"";const r=(e[i]||[]).join("");return"@none"===i||"none"===i||"en"===i?r:{"@language":i,"@value":r}}return t.map((t=>({"@language":t,"@value":(e[t]||[]).join("")})))}}function Ce(e){return Array.isArray(e)?e.map((e=>Ce(e))):"string"==typeof e?e:e.type&&"Canvas"===e.type?e.id:e}function be(e,t=!1){if(e)return e.length>1&&!t?e:e[0]||void 0}function Re(e){if(e){if("string"==typeof e)return{"@id":e};if("@id"in e){const 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 Se(e,t){return[["@id",e.id],["@type",t],["format",e.format],["height",e.height],["width",e.width],["viewingDirection","left-to-right"!==e.viewingDirection?e.viewingDirection:void 0],["license",e.license?e.license:void 0]]}function*we(e){const t=e.provider?yield e.provider[0]:void 0;return[["label",Ae(e.label)],["metadata",e.metadata&&e.metadata.length?e.metadata.map((e=>({label:Ae(e.label)||"",value:Ae(e.value)||""}))):void 0],["description",Ae(e.summary)],["thumbnail",be(yield e.thumbnail)],["navDate",e.navDate],["logo",t?be(t.logo):void 0],["homepage",t?t.homepage:void 0],["attribution",e.requiredStatement?Ae(e.requiredStatement.value):void 0]]}function*xe(e){const t=e.start&&e.start.type&&"SpecificResource"===e.start.type?ge(e.start):e.start;return[["seeAlso",be(yield e.seeAlso)],["service",be((e.service||[]).map(Re))],["rendering",be(yield e.rendering)],["startCanvas",t?t.id:void 0]]}function je(e){if(e&&function(e){return"SpecificResource"===e.type}(e)){let t=e.id;const i=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return function(e){return e&&"FragmentSelector"===e.type}(i)&&(t+="#"+i.value),t}return null==e?void 0:e.id}const Oe={Manifest:function*(e,t,{isTopLevel:i}){return[...i?[["@context","http://iiif.io/api/presentation/2/context.json"]]:[],...Se(e,"sc:Manifest"),...yield*we(e),...yield*xe(e),["sequences",[{"@id":`${e.id}/sequence0`,"@type":"sc:Sequence",canvases:yield e.items}]],["structures",yield e.structures]]},Canvas:function*(e){const t=(yield e.items)[0];return[...Se(e,"sc:Canvas"),...yield*we(e),...yield*xe(e),["images",t?[t.resources]:void 0],["annotations",e.annotations&&e.annotations.length?be(yield e.annotations):void 0]]},AnnotationPage:function*(e){return[...Se(e,"sc:AnnotationList"),...yield*we(e),["resources",e.items&&e.items.length?be(yield e.items):void 0]]},Annotation:function*(e){return[["@id",e.id],["@type","oa:Annotation"],["motivation","sc:painting"],["on",Ce(e.target)],["resource",be(yield e.body,!0)]]},ContentResource:function*(e){return"Image"===e.type?[...Se(e,"dctypes:Image"),...yield*we(e),...yield*xe(e)]:[...Se(e,void 0),...yield*we(e)]},AnnotationCollection:function*(e){return[["@id",e.id],["@type","sc:Layer"],["label",Ae(e.label)]]},Collection:function*(e){return[...Se(e,"sc:Collection"),...yield*we(e),...yield*xe(e),["members",yield*e.items]]},Range:function*(e){const t=[],i=[];if(e.items)for(const r of e.items){const n="SpecificResource"===r.type?r.source:r;if(n){const s=yield n;t.push({"@id":je(r),"@type":n.type,label:s?s.label:void 0,within:e.id}),"Canvas"===n.type&&i.push(n.id)}}return[...Se(e,"sc:Range"),...yield*we(e),...yield*xe(e),["canvases",i.length===t.length?i:void 0],["members",i.length!==t.length?t:void 0]]}};function Te(e){var t;return[["id",(null==(t=e.id)?void 0:t.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","left-to-right"!==e.viewingDirection?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],[s,c]]}function Le(e){if(e===c)return;if(!e||0===e.length)return;const t=e.filter((e=>e!==c));return 0!==t.length?t:void 0}function ke(e){if(e&&e.type&&"ImageService2"===e.type){const{id:t,type:i,profile:r,...n}=e,s="string"==typeof r?r:Array.isArray(r)?r.find((e=>"string"==typeof e)):"";return{"@id":t,"@type":i,profile:s?s.startsWith("http")?s:`http://iiif.io/api/image/2/${s}.json`:"http://iiif.io/api/image/2/level0.json",...n}}return e}function Ie(e){if(Array.isArray(e)||(e=e?[e]:[]),e&&0!==e.length)return e.map(ke)}function*Pe(e){return[["label",e.label],["metadata",Le(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",Le(yield e.thumbnail)],["placeholderCanvas",yield e.placeholderCanvas],["accompanyingCanvas",yield e.accompanyingCanvas],["provider",Le(yield e.provider)]]}function*Me(e){return[["seeAlso",Le(yield e.seeAlso)],["service",Le(Ie(e.service))],["services",Le(Ie(e.services))],["rendering",Le(yield e.rendering)],["supplementary",Le(yield e.supplementary)],["homepage",Le(yield e.homepage)],["logo",Le(yield e.logo)],["partOf",Le(yield e.partOf)],["start",e.start?ge(e.start):e.start]]}const De={Manifest:function*(e,t,{isTopLevel:i}){return i?[["@context",e["@context"]?e["@context"]:"http://iiif.io/api/presentation/3/context.json"],...Te(e),...yield*Pe(e),...yield*Me(e),["items",yield e.items],["structures",Le(yield e.structures)],["annotations",Le(yield e.annotations)],["navPlace",e.navPlace]]:[...Te(e),...yield*Pe(e)]},Canvas:function*(e){return[...Te(e),...yield*Pe(e),...yield*Me(e),["items",yield e.items],["annotations",Le(yield e.annotations)],["navPlace",e.navPlace]]},Agent:function*(e){return[["id",e.id],["type","Agent"],["label",e.label],...yield*Me(e)]},AnnotationPage:function*(e){var t;const i=Object.entries(e).map((([e,t])=>[e,Array.isArray(t)?Le(t):t])).filter((([e,t])=>"items"!==e&&"id"!==e&&e!==s&&e!==a&&e!==o)),r=yield e.items;return[["id",(null==(t=e.id)?void 0:t.startsWith("vault://"))?void 0:e.id],...i,...yield*Me(e),["items",r.length||!1===e[o]?r:c]]},Service:function*(e){return[[l,ke(e)]]},Annotation:function*(e){const t=Object.entries(e).map((([e,t])=>"motivation"===e?[e,Array.isArray(t)?t[0]:t]:"target"===e?[e,ge(t,{allowString:!0,allowSourceString:!0,allowedStringType:"Canvas"})]:[e,Array.isArray(t)?Le(t):t])).filter((([e])=>"body"!==e&&e!==s&&e!==o));let r;if(Array.isArray(e.body)){const t=[];for(const r of e.body)if(r&&i(r)){const e={...r};e.source=yield r.source,t.push(ge(e,{allowSourceString:!0}))}else t.push(yield r);r=t}else e.body&&i(e.body)?(r={...e.body},r.source=yield e.body.source):r=yield e.body;return[...t,...yield*Pe(e),...yield*Me(e),["body",1===r.length?r[0]:r]]},ContentResource:function*(e){return function(e,t){const i=Object.keys(t),r=e.map((([e])=>e));for(const n of i)n!==s&&n!==o&&-1===r.indexOf(n)&&void 0!==t[n]&&e.push([n,t[n]]);return e}([...Te(e),...yield*Pe(e),...yield*Me(e),["annotations",Le(yield e.annotations)],["items",Le(yield e.items)]],e)},AnnotationCollection:function*(e){return[["id",e.id],["type","AnnotationCollection"],["label",e.label]]},Collection:function*(e,t,{isTopLevel:i}){return i?[["@context","http://iiif.io/api/presentation/3/context.json"],...Te(e),...yield*Pe(e),...yield*Me(e),["items",Le(yield e.items)],["navPlace",e.navPlace]]:[...Te(e),...yield*Pe(e)]},Range:function*(e){const t=[];for(const i of e.items)"Range"===i.type?t.push(yield i):i&&"SpecificResource"===i.type?t.push(ge(i)):t.push(i);return[...Te(e),...yield*Pe(e),...yield*Me(e),["items",t],["annotations",Le(yield e.annotations)],["navPlace",e.navPlace]]}};exports.EMPTY=p,exports.HAS_PART=s,exports.IS_EXTERNAL=o,exports.PART_OF=a,exports.Traverse=j,exports.UNSET=c,exports.UNWRAP=l,exports.WILDCARD=n,exports.addFlagForExternalResource=de,exports.compressSpecificResource=ge,exports.defaultEntities={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}},exports.emptyAgent=C,exports.emptyAnnotation=h,exports.emptyAnnotationPage=y,exports.emptyCanvas=d,exports.emptyCollection=m,exports.emptyManifest=g,exports.emptyRange=A,exports.emptyService=b,exports.frameResource=v,exports.getDefaultEntities=te,exports.identifyResource=x,exports.isSpecificResource=i,exports.isWildcard=u,exports.languageString2to3=Ae,exports.merge=re,exports.mergeEntities=ne,exports.normalize=function(e){const t=function(e){return e&&e["@context"]&&("http://iiif.io/api/presentation/2/context.json"===e["@context"]||-1!==e["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")||"http://www.shared-canvas.org/ns/context.json"===e["@context"])||"http://iiif.io/api/image/2/context.json"===e["@context"]?Q.traverseUnknown(e):e}(e),i={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}},r={},n=function(e,t){return(i,r)=>{const n=e[i]?e[i]:{};return(e,s)=>{const a=ie(e,r||i);return a&&a.id&&i?(n[a.id]=n[a.id]?ne(n[a.id],a,{parent:s.parent,isTopLevel:t.id===a.id}):ne({id:a.id,type:a.type},a,{parent:s.parent,isTopLevel:t.id===a.id}),{id:a.id,type:"ContentResource"===i?i:a.type}):a}}}(i,t),s=function(e){return(t,i)=>r=>{const{id:n,type:s}=ie(r,i||t);if(void 0===n)throw new Error("Found invalid entity without an ID.");return e[n]="ContentResource"===t||"Service"===t?t:s,r}}(r);return{entities:i,resource:new j({collection:[de,ce(m),s("Collection"),n("Collection")],manifest:[de,ce(g),fe,s("Manifest"),n("Manifest")],canvas:[ce(d),s("Canvas"),n("Canvas")],annotationPage:[de,oe("AnnotationPage"),ce(y),s("AnnotationPage"),n("AnnotationPage")],annotation:[oe("Annotation"),pe,he,s("Annotation"),n("Annotation")],contentResource:[oe("ContentResource"),s("ContentResource"),n("ContentResource")],range:[ce(A),ve,s("Range","Canvas"),n("Range","Canvas")],agent:[ce(C),s("Agent"),n("Agent")],specificResource:[ye],service:[se(i)]}).traverseUnknown(t),mapping:r}},exports.resolveIfExists=f,exports.serialize=function(e,t,i){if(!t.type||!t.id)throw new Error("Unknown entity");if(!i[t.type])throw new Error(`Serializer not found for ${t.type}`);return function r(n,s,a=0){const o=i[n.type];if(!o)return c;if(a>20)throw new Error("Circular reference: "+n.id+" "+n.type);const[l,p]=f(e,n.type?n:n.id,s)||(n.id&&n.type?n:null);if(!l)return c;const u=o(l,e,{parent:s,isTopLevel:t.id===n.id,fullResource:p});let v=u.next();for(;!v.done;){const e=v.value;let t=c;if(e)if(Array.isArray(e)){const i=[];for(const t of e)i.push(r(t,n,a+1));t=i}else t=r(e,n,a+1);v=u.next(t)}return v.value===c?c:me(v.value)}(t)},exports.serializeConfigPresentation2=Oe,exports.serializeConfigPresentation3=De,exports.serializedFieldsToObject=me,exports.toRef=r,exports.traverseSpecificResource=ye,exports.types=w; | ||
| //# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
| var __defProp=Object.defineProperty,__defNormalProp=(e,t,i)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,__publicField=(e,t,i)=>(__defNormalProp(e,"symbol"!=typeof t?t+"":t,i),i);!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).IIIFParser=t()}(this,(function(){"use strict";const e=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function t(t){if(null==t)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(t))throw new Error("Array is not a valid entity");if("object"!=typeof t)throw new Error(typeof t+" is not a valid entity");if("string"==typeof t["@type"]){const i=e.indexOf(t["@type"]);if(-1!==i)return e[i]}if(t.profile)return"Service";if(t.format)return"ContentResource";if(t["@type"])return"ContentResource";throw new Error("Resource type is not known")}class i{constructor(e,t={}){__publicField(this,"traversals"),__publicField(this,"options"),this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...t}}static all(e){return new i({collection:[e],manifest:[e],canvas:[e],annotationList:[e],sequence:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],layer:[e]})}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))),this.traversals.collection)}traverseCollectionItems(e){if(this.options.mergeMemberProperties){const t=[...(e.manifests||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Manifest"}:e)),...(e.collections||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Collection"}:e)),...e.members||[]];delete e.collections,delete e.manifests,e.members=t}return e.manifests&&(e.manifests=e.manifests.map((e=>this.traverseManifest("string"==typeof e?{"@id":e,"@type":"sc:Manifest"}:e)))),e.collections&&(e.collections=e.collections.map((e=>this.traverseCollection("string"==typeof e?{"@id":e,"@type":"sc:Collection"}:e)))),e.members&&(e.members=e.members.map((e=>"string"==typeof e?e:this.traverseUnknown(e)))),e}traverseManifest(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))),this.traversals.manifest)}traverseManifestItems(e){return e.sequences&&(e.sequences=e.sequences.map((e=>this.traverseSequence(e)))),e.structures&&(e.structures=e.structures.map((e=>this.traverseRange(e)))),e}traverseSequence(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))),this.traversals.sequence)}traverseSequenceItems(e){return e.canvases&&(e.canvases=e.canvases.map((e=>this.traverseCanvas(e)))),e}traverseCanvas(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))),this.traversals.canvas)}traverseCanvasItems(e){return e.images&&(e.images=e.images.map((e=>this.traverseAnnotation(e)))),e.otherContent&&(e.otherContent=e.otherContent.map((e=>this.traverseAnnotationList(e)))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const t=[...(e.ranges||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Range"}:e)),...(e.canvases||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Canvas"}:e)),...e.members||[]];delete e.ranges,delete e.canvases,e.members=t.length?t.map((e=>this.traverseUnknown(e))):void 0}return e}traverseAnnotationList(e){const t="string"==typeof e?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(t)),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map((e=>this.traverseAnnotation(e)))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(Array.isArray(e.resource)?e.resource=e.resource.map((e=>this.traverseContentResource(e))):e.resource=this.traverseContentResource(e.resource)),e.on,e}traverseLayer(e){return this.traverseType(this.traverseLinking(this.traverseLayerItems(e)),this.traversals.layer)}traverseLayerItems(e){return e.otherContent&&(e.otherContent=e.otherContent.map((e=>this.traverseAnnotationList(e)))),e}traverseChoice(e){return this.traverseType(this.traverseChoiceItems(e),this.traversals.choice)}traverseChoiceItems(e){return e.default&&"rdf:nil"!==e.default&&(e.default=this.traverseContentResource(e.default)),e.item&&"rdf:nil"!==e.item&&(e.item=e.item.map((e=>this.traverseContentResource(e)))),e}traverseService(e){return this.traverseType(this.traverseLinking(e),this.traversals.service)}traverseContentResource(e){return"oa:Choice"===e["@type"]?this.traverseChoice(e):this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.contentResource)}traverseUnknown(e){if(!e["@type"]||"string"==typeof e)return e;switch(t(e)){case"sc:Collection":return this.traverseCollection(e);case"sc:Manifest":return this.traverseManifest(e);case"sc:Canvas":return this.traverseCanvas(e);case"sc:Sequence":return this.traverseSequence(e);case"sc:Range":return this.traverseRange(e);case"oa:Annotation":return this.traverseAnnotation(e);case"sc:AnnotationList":return this.traverseAnnotationList(e);case"sc:Layer":return this.traverseLayer(e);case"Service":return this.traverseService(e);case"oa:Choice":return this.traverseChoice(e);case"ContentResource":return this.traverseContentResource(e)}return e.profile?this.traverseService(e):e}traverseImageResource(e){const t=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(const n of i)"string"==typeof n?r.push(this.traverseContentResource({"@id":n,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(n));return t||this.options.convertPropsToArray?r:r[0]}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){const t=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(const n of i)r.push(this.traverseService(n));return t||this.options.convertPropsToArray?r:r[0]}traverseLinking(e){return e.related&&(e.related=this.traverseOneOrManyType(e.related,this.traversals.contentResource)),e.rendering&&(e.rendering=this.traverseOneOrManyType(e.rendering,this.traversals.contentResource)),e.service&&(e.service=this.traverseOneOrMoreServices(e.service)),e.seeAlso&&(e.seeAlso=this.traverseOneOrManyType(e.seeAlso,this.traversals.contentResource)),e.within&&("string"==typeof e.within||(e.within=this.traverseOneOrManyType(e.within,this.traversals.contentResource))),e.startCanvas&&("string"==typeof e.startCanvas?e.startCanvas=this.traverseType({"@id":e.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):e.startCanvas&&this.traverseType(e.startCanvas,this.traversals.canvas)),e.contentLayer&&("string"==typeof e.contentLayer?e.contentLayer=this.traverseLayer({"@id":e.contentLayer,"@type":"sc:Layer"}):e.contentLayer=this.traverseLayer(e.contentLayer)),e}traverseOneOrManyType(e,t){if(!Array.isArray(e)){if(!this.options.convertPropsToArray)return this.traverseType(e,t);e=[e]}return e.map((e=>this.traverseType(e,t)))}traverseType(e,t){return t.reduce(((e,t)=>{const i=t(e);return void 0!==i||this.options.allowUndefinedReturn?i:e}),e)}}const r="http://library.stanford.edu/iiif/image-api/compliance.html#level1",n="http://library.stanford.edu/iiif/image-api/compliance.html#level2",s="http://library.stanford.edu/iiif/image-api/conformance.html#level1",a="http://library.stanford.edu/iiif/image-api/conformance.html#level2",o="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",c="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",l="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",u="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",p="http://iiif.io/api/image/1/level1.json",f="http://iiif.io/api/image/1/profiles/level1.json",h="http://iiif.io/api/image/1/level2.json",v="http://iiif.io/api/image/1/profiles/level2.json",d="http://iiif.io/api/image/2/level1.json",y="http://iiif.io/api/image/2/profiles/level1.json",m="http://iiif.io/api/image/2/level2.json",g="http://iiif.io/api/image/2/profiles/level2.json",A="level1",x="level2",b="http://iiif.io/api/image/2/level1",C="http://iiif.io/api/image/2/level2",I=[b,C,r,n,s,a,o,c,l,u,p,f,h,v,d,y,m,g,A,x],S=["http://iiif.io/api/image/2/level0",b,C,"http://library.stanford.edu/iiif/image-api/compliance.html#level0",r,n,"http://library.stanford.edu/iiif/image-api/conformance.html#level0",s,a,"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",o,c,"http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",l,u,"http://iiif.io/api/image/1/level0.json","http://iiif.io/api/image/1/profiles/level0.json",p,f,h,v,"http://iiif.io/api/image/2/level0.json","http://iiif.io/api/image/2/profiles/level0.json",d,y,m,g,"level0",A,x];function _(e){return Array.isArray(e)?e:e?[e]:[]}function w(e){for(const t in e)void 0!==e[t]&&null!==e[t]||delete e[t];return e}const R="Attribution",O="http://example.org/provider",F="Unknown";function L(e,t="none"){if(!e)return{};const i=Array.isArray(e)?e:[e],r={};for(const n of i){if("string"==typeof n){r[t]=r[t]?r[t]:[],r[t].push(n||"");continue}if(!n["@language"]){r[t]=r[t]?r[t]:[],r[t].push(n["@value"]||"");continue}const e=n["@language"];r[e]=r[e]?r[e]:[],r[e].push(n["@value"]||"")}return r}function E(e){return Array.isArray(e)?E(e.find((e=>"string"==typeof e))):-1!==S.indexOf(e)?"level2":-1!==I.indexOf(e)?"level1":"string"==typeof e?e:void 0}function j(e){const t=Array.isArray(e)?e:[e];for(const i of t)switch(i){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function M(e){for(const t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}const P=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function T(e){const t=e["@id"]||e.id;let i=e["@type"]||e.type;const r=e.profile||void 0,n=e["@context"]||void 0;if(r){const e=function(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"}}(r);if(e)return e}if(n){const e=j(n);if(e)return e}if(i){if(Array.isArray(i)){if(-1!==i.indexOf("oa:CssStylesheet"))return"CssStylesheet";if(-1!==i.indexOf("cnt:ContentAsText"))return"TextualBody";i=i[0]}for(const e of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${e}:`)){i=i.slice(e.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(i&&-1!==P.indexOf(i))return i;if(e.format){if(e.format.startsWith("image/"))return"Image";if(e.format.startsWith("text/"))return"Text";if("application/pdf"===e.format)return"Text";if(e.format.startsWith("application/"))return"Dataset"}return t&&(t.endsWith(".jpg")||t.endsWith(".png")||t.endsWith(".jpeg"))?"Image":i||"unknown"}const z=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function k(e){const t=e.match(z);return t?t[0]:e}const $=["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 D(e){if(e){const t=Array.isArray(e)?e:[e],i=[];for(const e of t)"http://iiif.io/api/presentation/2/context.json"===e&&i.push("http://iiif.io/api/presentation/3/context.json"),-1===$.indexOf(e)&&i.push(e);if(t.length)return 1===i.length?i[0]:i}}let W=0;function N(e,t){const i=encodeURI(e.id||e["@id"]||"").trim();return i&&t?`${i}/${t}`:i||(W++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${W}`)}function q(e){const t=[...e.behavior||[]];let i;return e.viewingHint&&t.push(e.viewingHint),Array.isArray(e.motivation)?i=e.motivation.map(M):e.motivation&&(i=M(e.motivation)),{"@context":e["@context"]?D(e["@context"]):void 0,id:(e["@id"]||N(e)).trim(),type:T(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:i,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function B(e){const[t,i]=function(e,t="Rights/License",i="none"){let r=null;const n=[],s=Array.isArray(e)?e:[e];for(const a of s){const e=a?k(a):void 0;!e||-1===e.indexOf("creativecommons.org")&&-1===e.indexOf("rightsstatements.org")?e&&n.push({label:{[i]:[t]},value:{[i]:[e]}}):r=e.startsWith("https://")?`http://${e.slice(8)}`:e}return[r,n]}(e.license),r=[...e.metadata?(n=e.metadata,n?n.map((e=>({label:L(e.label),value:L(e.value)}))):[]):[],...i];var n;return{rights:t,metadata:r.length?r:void 0,label:e.label?L(e.label):void 0,requiredStatement:e.attribution?{label:L(R),value:L(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?L(e.description):void 0,thumbnail:U(e.thumbnail)}}function U(e){if(e){return(Array.isArray(e)?e:[e]).map((e=>"string"==typeof e?{id:e,type:"Image"}:("unknown"===e.type&&(e.type="Image"),e)))}return e}function H(e){if(!e.within)return;const t=Array.isArray(e.within)?e.within:[e.within],i=[];for(const r of t)if("string"==typeof r){if(r&&"sc:Manifest"===e["@type"])i.push({id:r,type:"Collection"})}else r["@id"]&&i.push({id:r["@id"],type:T(r)});return i.length?i:void 0}function G(e){const t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],i=e.contentLayer;return{provider:e.logo||t.length?[{id:O,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:L(F)}]:void 0,partOf:H(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?_(e.service):void 0,supplementary:i?[i]:void 0}}function Q(e){const t=e;return w({...q(t),...B(t),...G(t),...(i=t,{chars:i.chars,format:i.format?i.format:void 0,language:i.language})});var i}const V=new i({collection:[function(e){return w({...q(e),...B(e),...G(e),items:e.members})}],manifest:[function(e){const t=[],i=[];let r;for(const s of e.sequences||[])s.canvases.length&&t.push(...s.canvases),s.behavior&&i.push(...s.behavior),s.startCanvas&&(r=s.startCanvas);const n=q(e);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),w({...n,...B(e),...G(e),start:r,items:t,structures:e.structures})}],canvas:[function(e){return w({...q(e),...B(e),...G(e),annotations:e.otherContent&&e.otherContent.length?e.otherContent:void 0,items:e.images&&e.images.length?[{id:N(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}],annotationList:[function(e){return w({...q(e),...B(e),...G(e),items:e.resources&&e.resources.length?e.resources:void 0})}],sequence:[function(e){return e.canvases&&0!==e.canvases.length?{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}:{canvases:[],behavior:[]}}],annotation:[function(e){return w({...q(e),...B(e),...G(e),target:function e(t){if(Array.isArray(t)){if(t.length>1)return{type:"List",items:t.map(e)};t=t[0]}if("string"==typeof t)return encodeURI(t).trim();if("@type"in t){let e;if("string"==typeof t.full)e=t.full;else if("dctypes:Image"===t.full["@type"])e={id:t.full["@id"],type:"Image"};else{if("sc:Canvas"!==t.full["@type"])throw new Error(`Unsupported source type on annotation: ${t.full["@type"]}`);e={id:t.full["@id"],type:"Canvas"}}return{type:"SpecificResource",source:e,selector:X(t.selector)}}return encodeURI(t["@id"]).trim()}(e.on),body:Array.isArray(e.resource)?e.resource.map(Q):Q(e.resource)})}],contentResource:[Q],choice:[function(e){const t=[];return e.default&&"rdf:nil"!==e.default&&t.push(e.default),e.item&&"rdf:nil"!==e.item&&t.push(...e.item),{...q(e),...B(e),items:t}}],range:[function(e){return w({...q(e),...B(e),...G(e),items:e.members})}],service:[function(e){const{"@id":t,"@type":i,"@context":r,profile:n,...s}=e,a={};return t&&(a["@id"]=t),a["@type"]=T(e),"unknown"===a["@type"]&&(r&&r.length&&(a["@context"]=r),a["@type"]="Service"),n&&(a.profile=E(n)),w({...a,...s})}],layer:[function(e){return w({...q(e),...B(e),...G(e)})}]});function J(e){return e&&e["@context"]&&("http://iiif.io/api/presentation/2/context.json"===e["@context"]||-1!==e["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")||"http://www.shared-canvas.org/ns/context.json"===e["@context"])||"http://iiif.io/api/image/2/context.json"===e["@context"]?V.traverseUnknown(e):e}function X(e){if((Array.isArray(e["@type"])&&e["@type"].includes("oa:SvgSelector")||"oa:SvgSelector"==e["@type"])&&("chars"in e||"value"in e))return{type:"SvgSelector",value:"chars"in e?e.chars:e.value};if("oa:FragmentSelector"===e["@type"])return{type:"FragmentSelector",value:e.value};if("oa:Choice"===e["@type"])return[X(e.default),...(Array.isArray(e.item)?e.item:[e.item]).map(X)];if("iiif:ImageApiSelector"==e["@type"])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"]}`)}const Y=Object.freeze(Object.defineProperty({__proto__:null,types:e,identifyResource:t,Traverse:i,convertLanguageMapping:L,getProfile:E,getTypeFromContext:j,presentation2to3:V,convertPresentation2:J},Symbol.toStringTag,{value:"Module"}));function Z(e){return"string"!=typeof e&&(!!e&&"SpecificResource"===e.type)}function K(e,t){const i=t||"unknown";if(!e)return;if("string"==typeof e)return{id:e,type:i};if(Z(e))return K(e.source,t);let r=i&&"unknown"!==i?i:e.type||e["@type"];const n=e.id||e["@id"];return-1!==r.indexOf(":")&&(r=r.split(":").pop()),n&&r?{id:n,type:r}:void 0}const ee={},te="iiif-parser:hasPart",ie="iiif-parser:partOf",re="iiif-parser:isExternal",ne="__$UNSET$__",se="__$UNWRAP$__",ae=[];function oe(e){if(e===ee||0===Object.keys(e).length)return!0;for(const t in e)return!1;return!0}function ce(e,t){if(t&&t["@explicit"]){const i={},r=Object.keys(t);for(const n of r)n!==ie&&"@explicit"!==n&&(oe(t[n])?i[n]=e[n]:i[n]=t[n]);return i}return e}function le(e,t,i){const r=K(t);if(!r)return[void 0,void 0];const n=e.requests[r.id],s=r.type||e.mapping[r.id];if(!s||n&&n.resourceUri&&!e.entities[s][n.resourceUri])return[void 0,void 0];const a=e.entities[s][n?n.resourceUri:r.id];if(r.type&&!a)return le(e,{id:r.id},i);if(a&&a[te]){const e=a[te].find((e=>i?e[ie]===i.id:e[ie]===a.id));return[ce(a,e),a]}return[a,a]}Object.freeze(ae),Object.freeze(ee);const ue={id:"https://iiif-parser/annotation",type:"Annotation",behavior:ae,label:null,thumbnail:ae,summary:null,requiredStatement:null,metadata:ae,seeAlso:ae,homepage:ae,rendering:ae,service:ae,accessibility:ae,audience:ae,body:ae,bodyValue:null,canonical:null,created:null,creator:ae,generated:null,generator:ae,modified:null,motivation:ae,rights:null,stylesheet:null,target:ae,timeMode:void 0,via:ae,partOf:ae},pe={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:ae,label:null,thumbnail:ae,summary:null,requiredStatement:null,metadata:ae,rights:null,provider:ae,items:ae,seeAlso:ae,homepage:ae,rendering:ae,service:ae},fe={id:"https://iiif-parser/empty-canvas",type:"Canvas",label:null,behavior:ae,thumbnail:ae,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:ae,rights:null,navDate:null,provider:ae,items:ae,annotations:ae,seeAlso:ae,homepage:ae,partOf:ae,rendering:ae,service:ae,duration:0,height:0,width:0},he={id:"https://iiif-parser/empty-collection",type:"Collection",label:null,viewingDirection:"left-to-right",behavior:ae,thumbnail:ae,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:ae,rights:null,navDate:null,provider:ae,items:ae,annotations:ae,seeAlso:ae,homepage:ae,partOf:ae,rendering:ae,service:ae,services:ae},ve={id:"https://iiif-parser/empty-manifest",type:"Manifest",annotations:ae,behavior:ae,homepage:ae,items:ae,label:null,metadata:ae,navDate:null,provider:ae,partOf:ae,accompanyingCanvas:null,placeholderCanvas:null,rendering:ae,requiredStatement:null,rights:null,seeAlso:ae,service:ae,services:ae,start:null,structures:ae,summary:null,thumbnail:ae,viewingDirection:"left-to-right"},de={id:"https://iiif-parser/empty-canvas",type:"Range",label:null,behavior:ae,thumbnail:ae,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:ae,rights:null,navDate:null,provider:ae,items:ae,annotations:ae,seeAlso:ae,homepage:ae,partOf:ae,rendering:ae,service:ae,start:null,supplementary:null,viewingDirection:"left-to-right"},ye={id:"https://iiif-parser/empty-agent",type:"Agent",label:{},logo:ae,seeAlso:ae,homepage:ae},me={id:"https://iiif-parser/empty-service",type:"UnknownService"};function ge(...e){return t=>e.reduce(((e,t)=>t(e)),t)}const Ae=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function xe(e,t){if(null==e)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("object"!=typeof e){if(t)return t;throw new Error(typeof e+" is not a valid entity")}if("string"==typeof e.type){const t=Ae.indexOf(e.type);if(-1!==t)return Ae[t]}if(e.profile)return"Service";throw new Error("Resource type is not known")}class be{constructor(e,t={}){__publicField(this,"traversals"),__publicField(this,"options"),__publicField(this,"_traverseManifest",ge(this.traverseManifestItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseManifestStructures.bind(this),this.traverseInlineAnnotationPages.bind(this))),__publicField(this,"_traverseCanvas",ge(this.traverseCanvasItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseInlineAnnotationPages.bind(this))),__publicField(this,"_traverseAnnotationPage",ge(this.traverseAnnotationPageItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this))),__publicField(this,"_traverseRange",ge(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 be({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=_(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=_(e.service).map((e=>this.traverseService(e)))),e.services&&(e.services=_(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=>"string"!=typeof t&&t.type?"Canvas"===t.type?this.traverseType(t,{parent:e},this.traversals.canvas):"AnnotationCollection"===t.type?this.traverseType(t,{parent:e},this.traversals.annotationCollection):"Collection"===t.type?this.traverseType(t,{parent:e},this.traversals.collection):this.traverseType(t,{parent:e},this.traversals.contentResource):this.traverseType(t,{parent:e},this.traversals.contentResource)))),e.start&&(Z(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((e=>"Collection"===e.type?this.traverseCollection(e):this.traverseManifest(e))),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((e=>this.traverseCanvas(e)))),e}traverseManifestStructures(e){return e.structures&&(e.structures=e.structures.map((e=>this.traverseRange(e)))),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"string"!=typeof e&&e?(e.annotations&&(e.annotations=e.annotations.map((t=>this.traverseAnnotationPage(t,e)))),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"string"!=typeof e&&e?(e&&e.service&&(e.service=_(e.service||[]).map((t=>this.traverseService(t,e)))),e):e}traverseContentResource(e,t){return"Choice"===e.type&&(e.items=e.items.map((t=>this.traverseContentResource(t,e)))),Z(e)?this.traverseSpecificResource(e,"ContentResource"):this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)),{parent:t},this.traversals.contentResource)}traverseSpecificResource(e,t,i){let r=e.source;return"string"==typeof e.source&&(r={id:e.source,type:t||"unknown"}),this.traverseType({...e,source:"Canvas"===t||"Canvas"===r.type?this.traverseType(r,{parent:i},this.traversals.canvas):"ContentResource"===t?this.traverseContentResource(r,{parent:i}):this.traverseUnknown(r,{parent:i,typeHint:t})},{parent:i},this.traversals.specificResource)}traverseRangeRanges(e){return e.items&&(e.items=e.items.map((t=>"string"==typeof t?this.traverseCanvas({id:t,type:"Canvas"},e):Z(t)?this.traverseSpecificResource(t,"Canvas",e):"Manifest"===t.type?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,i){return i.reduce(((e,i)=>{const r=i(e,t);return void 0!==r||this.options.allowUndefinedReturn?r:e}),e)}traverseService(e,t){const i=Object.assign({},e);return i&&i.service&&(i.service=_(i.service).map((e=>this.traverseService(e)))),this.traverseType(i,{parent:t},this.traversals.service)}traverseUnknown(e,{parent:t,typeHint:i}={}){const r=xe(e,i);switch(r){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:if(i)return i;throw new Error(`Unknown or unsupported resource type of ${r}`)}}}function Ce(e,t={}){if(Array.isArray(e))return Ce(e[0]);if("string"==typeof e){const[i,r]=e.split("#");return r?{type:"SpecificResource",source:{id:i,type:t.typeHint||"Unknown"},selector:{type:"FragmentSelector",value:r}}:{type:"SpecificResource",source:{id:i,type:t.typeMap&&t.typeMap[i]||t.typeHint||"Unknown"}}}if("Choice"===e.type||"List"===e.type||"Composite"===e.type||"Independents"===e.type)return Ce(e.items[0]);if("SpecificResource"===e.type)return"Canvas"===e.source.type&&e.source.partOf&&"string"==typeof e.source.partOf&&(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){"Canvas"===e.type&&e.partOf&&"string"==typeof e.partOf&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[t,i]=e.id.split("#");return i?{type:"SpecificResource",source:{...e,id:t},selector:{type:"FragmentSelector",value:i}}:{type:"SpecificResource",source:{...e,id:t}}}return{type:"SpecificResource",source:e}}function Ie(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}function Se(e,t){if("string"==typeof e)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 _e(e,t,i){if(!t)return e;if(Array.isArray(e)){if(!Array.isArray(t))throw new Error("Cannot merge array with non-array");const i=[...e];for(const r of t)if(r["@id"]&&!r.id&&(r.id=r["@id"]),r["@type"]&&!r.type&&(r.type=r["@type"]),null!=r)if(Array.isArray(r))i.push(r);else if("object"==typeof r&&r.id&&r.type){const e=i.findIndex((e=>e.id===r.id&&e.type===r.type));e>=0&&(i[e]=_e(i[e],r))}else-1===e.indexOf(r)&&i.push(r);return i}if("object"==typeof e){if(Array.isArray(t)||"object"!=typeof t)throw new Error("Cannot merge object with non-object");const r={...e},n=[],s=[],a=Object.keys(e).filter((e=>e!==te&&"id"!==e&&"type"!==e)),o={},c={};for(const[e,i]of Object.entries(t)){if(e===te||"id"===e||"type"===e)continue;const t=r[e];t===i?s.push(e):t!==ae&&t?(t&&i&&(o[e]=t,c[e]=i),r[e]=_e(t,i),r[e]===o[e]&&(s.push(e),delete o[e])):(n.push(e),r[e]=i)}if(i&&(i.parent&&i.parent.id||i.isTopLevel)){const t=[],l={};if(i.parent?l[ie]=i.parent.id:i.isTopLevel&&(l[ie]=e.id),r[te]&&r[te].length){const e=!(r[te]||[]).find((e=>e["@explicit"])),i=n.length>0||s.length!==a.length;if(e&&i)for(const n of r[te]){const e={...n},i=Object.keys(o);if(e){e["@explicit"]=!0;for(const t of a)t!==te&&(e[t]=ee);for(const t of i)e[t]=o[t]}t.push(e)}else t.push(...r[te]);if(i){const e=Object.keys(c);l["@explicit"]=!0;for(const t of n)l[t]=ee;for(const t of s)l[t]=ee;for(const t of e)l[t]=c[t]}}l.id=r.id,l.type=r.type,t.push(l),r[te]=t}return r}return e||t}function we(e,t,i){if("string"==typeof e)return e;if(t.id!==e.id||t.type!==e.type){if("ImageService3"===t.type)return t;if("ImageService3"===e.type)return e;throw new Error(`Can only merge entities with identical identifiers and type! ${t.type}(${t.id}) => ${e.type}(${e.id})`)}return _e({...e},t,i)}function Re(e){return t=>{e.Service=e.Service?e.Service:{};const i=t.id||t["@id"],r=function(e){const t=Object.assign({},e);if(t["@id"]&&(t.id=t["@id"]),t["@type"]&&(t.type=t["@type"]),t.service){const e=[];t.service=Array.isArray(t.service)?t.service:[t.service];for(const i of t.service)e.push({id:i["@id"]||i.id,type:i["@type"]||i.type});t.service=e}return Object.assign({},me,t)}(t);return r&&r.id&&(e.Service[r.id]?e.Service[i]=we(e.Service[i],r):e.Service[i]=r),t}}function Oe(e){const t=JSON.stringify(e);let i=5381,r=t.length;for(;r;)i=33*i^t.charCodeAt(--r);const n=(i>>>0).toString(16);return n.length%2?"0"+n:n}function Fe(e){return t=>"string"==typeof t?{id:t,type:e}:t.id?t.type?t:{type:e,...t}:{id:`vault://${Oe(t)}`,type:e,...t}}function Le(e){return t=>({...e,...t})}function Ee(e){return Array.isArray(e)?e:[e]}function je(e){return e.body&&(e.body=Ee(e.body)),e.seeAlso&&(e.seeAlso=Ee(e.seeAlso)),e.audience&&(e.audience=Ee(e.audience)),e.accessibility&&(e.accessibility=Ee(e.accessibility)),e.motivation&&(e.motivation=Ee(e.motivation)),e}function Me(e,{typeHint:t,partOfTypeHint:i}={}){if("string"==typeof e&&(e={id:e,type:t||"unknown"}),Z(e))return"string"==typeof e.source&&(e.source={id:e.source,type:t||"unknown"}),"Canvas"===e.source.type&&e.source.partOf&&"string"==typeof e.source.partOf&&(e.source.partOf=[{id:e.source.partOf,type:i||"Manifest"}]),e;let r;if(-1!==(e.id||"").indexOf("#")){const[t,i]=(e.id||"").split("#");e.id=t,i&&(r={type:"FragmentSelector",value:i})}return{type:"SpecificResource",source:e,selector:r}}function Pe(e){const t=Object.assign({},e);return e&&e.items&&(t.items=e.items.map((e=>"string"==typeof e||"Canvas"===e.type?Me(e):e))),t}function Te(e){const t=Object.assign({},e);return t.start?(t.start=Me(t.start,{typeHint:"Canvas"}),t):e}function ze(e){const t=Object.assign({},e);return t.target?(t.target=Ce(t.target,{typeHint:"Canvas"}),t):e}function ke(e){return e}function $e(e){return void 0===e.items&&(e[re]=!0),e}function De(e){const t={};for(const[i,r]of e){if(i===se&&r!==ne)return r;r!==ne&&null!=r&&(t[i]=r)}return t}function We(e,{allowSourceString:t=!0,allowString:i=!1,allowedStringType:r}={}){const n=e=>{if(t&&e&&e.source&&"string"!=typeof e.source){const t=Object.keys(e.source);if(e.source.id&&e.source.type&&2===t.length)return{...e,source:e.source.id}}return e};if(e){if(e.source&&e.source.partOf)return n(e);const t=Object.keys(e);if(2===t.length&&e.type&&e.source||3===t.length&&e.type&&e.source&&-1!==t.indexOf("selector")&&!e.selector)return!i||r&&r!==e.source.type?"ContentResource"===e.source.type?{type:"SpecificResource",source:e.source.id}:e.source:e.source.id;if(e.selector&&!Array.isArray(e.selector)&&"string"!=typeof e.selector&&"FragmentSelector"===e.selector.type){const t=`${e.source.id}#${e.selector.value}`;return i?t:{id:t,type:e.source.type}}}return n(e)}function Ne(e){if(!e)return;const t=Object.keys(e);if(0!==t.length){if(1===t.length){const i=t[0];if(!i)return"";const r=(e[i]||[]).join("");return"@none"===i||"none"===i||"en"===i?r:{"@language":i,"@value":r}}return t.map((t=>({"@language":t,"@value":(e[t]||[]).join("")})))}}function qe(e){return Array.isArray(e)?e.map((e=>qe(e))):"string"==typeof e?e:e.type&&"Canvas"===e.type?e.id:e}function Be(e,t=!1){if(e)return e.length>1&&!t?e:e[0]||void 0}function Ue(e){if(e){if("string"==typeof e)return{"@id":e};if("@id"in e){const 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 He(e,t){return[["@id",e.id],["@type",t],["format",e.format],["height",e.height],["width",e.width],["viewingDirection","left-to-right"!==e.viewingDirection?e.viewingDirection:void 0],["license",e.license?e.license:void 0]]}function*Ge(e){const t=e.provider?yield e.provider[0]:void 0;return[["label",Ne(e.label)],["metadata",e.metadata&&e.metadata.length?e.metadata.map((e=>({label:Ne(e.label)||"",value:Ne(e.value)||""}))):void 0],["description",Ne(e.summary)],["thumbnail",Be(yield e.thumbnail)],["navDate",e.navDate],["logo",t?Be(t.logo):void 0],["homepage",t?t.homepage:void 0],["attribution",e.requiredStatement?Ne(e.requiredStatement.value):void 0]]}function*Qe(e){const t=e.start&&e.start.type&&"SpecificResource"===e.start.type?We(e.start):e.start;return[["seeAlso",Be(yield e.seeAlso)],["service",Be((e.service||[]).map(Ue))],["rendering",Be(yield e.rendering)],["startCanvas",t?t.id:void 0]]}function Ve(e){if(e&&function(e){return"SpecificResource"===e.type}(e)){let t=e.id;const i=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return function(e){return e&&"FragmentSelector"===e.type}(i)&&(t+="#"+i.value),t}return null==e?void 0:e.id}const Je={Manifest:function*(e,t,{isTopLevel:i}){return[...i?[["@context","http://iiif.io/api/presentation/2/context.json"]]:[],...He(e,"sc:Manifest"),...yield*Ge(e),...yield*Qe(e),["sequences",[{"@id":`${e.id}/sequence0`,"@type":"sc:Sequence",canvases:yield e.items}]],["structures",yield e.structures]]},Canvas:function*(e){const t=(yield e.items)[0];return[...He(e,"sc:Canvas"),...yield*Ge(e),...yield*Qe(e),["images",t?[t.resources]:void 0],["annotations",e.annotations&&e.annotations.length?Be(yield e.annotations):void 0]]},AnnotationPage:function*(e){return[...He(e,"sc:AnnotationList"),...yield*Ge(e),["resources",e.items&&e.items.length?Be(yield e.items):void 0]]},Annotation:function*(e){return[["@id",e.id],["@type","oa:Annotation"],["motivation","sc:painting"],["on",qe(e.target)],["resource",Be(yield e.body,!0)]]},ContentResource:function*(e){return"Image"===e.type?[...He(e,"dctypes:Image"),...yield*Ge(e),...yield*Qe(e)]:[...He(e,void 0),...yield*Ge(e)]},AnnotationCollection:function*(e){return[["@id",e.id],["@type","sc:Layer"],["label",Ne(e.label)]]},Collection:function*(e){return[...He(e,"sc:Collection"),...yield*Ge(e),...yield*Qe(e),["members",yield*e.items]]},Range:function*(e){const t=[],i=[];if(e.items)for(const r of e.items){const n="SpecificResource"===r.type?r.source:r;if(n){const s=yield n;t.push({"@id":Ve(r),"@type":n.type,label:s?s.label:void 0,within:e.id}),"Canvas"===n.type&&i.push(n.id)}}return[...He(e,"sc:Range"),...yield*Ge(e),...yield*Qe(e),["canvases",i.length===t.length?i:void 0],["members",i.length!==t.length?t:void 0]]}};function Xe(e){var t;return[["id",(null==(t=e.id)?void 0:t.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","left-to-right"!==e.viewingDirection?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],[te,ne]]}function Ye(e){if(e===ne)return;if(!e||0===e.length)return;const t=e.filter((e=>e!==ne));return 0!==t.length?t:void 0}function Ze(e){if(e&&e.type&&"ImageService2"===e.type){const{id:t,type:i,profile:r,...n}=e,s="string"==typeof r?r:Array.isArray(r)?r.find((e=>"string"==typeof e)):"";return{"@id":t,"@type":i,profile:s?s.startsWith("http")?s:`http://iiif.io/api/image/2/${s}.json`:"http://iiif.io/api/image/2/level0.json",...n}}return e}function Ke(e){if(Array.isArray(e)||(e=e?[e]:[]),e&&0!==e.length)return e.map(Ze)}function*et(e){return[["label",e.label],["metadata",Ye(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",Ye(yield e.thumbnail)],["placeholderCanvas",yield e.placeholderCanvas],["accompanyingCanvas",yield e.accompanyingCanvas],["provider",Ye(yield e.provider)]]}function*tt(e){return[["seeAlso",Ye(yield e.seeAlso)],["service",Ye(Ke(e.service))],["services",Ye(Ke(e.services))],["rendering",Ye(yield e.rendering)],["supplementary",Ye(yield e.supplementary)],["homepage",Ye(yield e.homepage)],["logo",Ye(yield e.logo)],["partOf",Ye(yield e.partOf)],["start",e.start?We(e.start):e.start]]}const it={Manifest:function*(e,t,{isTopLevel:i}){return i?[["@context",e["@context"]?e["@context"]:"http://iiif.io/api/presentation/3/context.json"],...Xe(e),...yield*et(e),...yield*tt(e),["items",yield e.items],["structures",Ye(yield e.structures)],["annotations",Ye(yield e.annotations)],["navPlace",e.navPlace]]:[...Xe(e),...yield*et(e)]},Canvas:function*(e){return[...Xe(e),...yield*et(e),...yield*tt(e),["items",yield e.items],["annotations",Ye(yield e.annotations)],["navPlace",e.navPlace]]},Agent:function*(e){return[["id",e.id],["type","Agent"],["label",e.label],...yield*tt(e)]},AnnotationPage:function*(e){var t;const i=Object.entries(e).map((([e,t])=>[e,Array.isArray(t)?Ye(t):t])).filter((([e,t])=>"items"!==e&&"id"!==e&&e!==te&&e!==ie&&e!==re)),r=yield e.items;return[["id",(null==(t=e.id)?void 0:t.startsWith("vault://"))?void 0:e.id],...i,...yield*tt(e),["items",r.length||!1===e[re]?r:ne]]},Service:function*(e){return[[se,Ze(e)]]},Annotation:function*(e){const t=Object.entries(e).map((([e,t])=>"motivation"===e?[e,Array.isArray(t)?t[0]:t]:"target"===e?[e,We(t,{allowString:!0,allowSourceString:!0,allowedStringType:"Canvas"})]:[e,Array.isArray(t)?Ye(t):t])).filter((([e])=>"body"!==e&&e!==te&&e!==re));let i;if(Array.isArray(e.body)){const t=[];for(const i of e.body)if(i&&Z(i)){const e={...i};e.source=yield i.source,t.push(We(e,{allowSourceString:!0}))}else t.push(yield i);i=t}else e.body&&Z(e.body)?(i={...e.body},i.source=yield e.body.source):i=yield e.body;return[...t,...yield*et(e),...yield*tt(e),["body",1===i.length?i[0]:i]]},ContentResource:function*(e){return function(e,t){const i=Object.keys(t),r=e.map((([e])=>e));for(const n of i)n!==te&&n!==re&&-1===r.indexOf(n)&&void 0!==t[n]&&e.push([n,t[n]]);return e}([...Xe(e),...yield*et(e),...yield*tt(e),["annotations",Ye(yield e.annotations)],["items",Ye(yield e.items)]],e)},AnnotationCollection:function*(e){return[["id",e.id],["type","AnnotationCollection"],["label",e.label]]},Collection:function*(e,t,{isTopLevel:i}){return i?[["@context","http://iiif.io/api/presentation/3/context.json"],...Xe(e),...yield*et(e),...yield*tt(e),["items",Ye(yield e.items)],["navPlace",e.navPlace]]:[...Xe(e),...yield*et(e)]},Range:function*(e){const t=[];for(const i of e.items)"Range"===i.type?t.push(yield i):i&&"SpecificResource"===i.type?t.push(We(i)):t.push(i);return[...Xe(e),...yield*et(e),...yield*tt(e),["items",t],["annotations",Ye(yield e.annotations)],["navPlace",e.navPlace]]}};const rt=Object.freeze(Object.defineProperty({__proto__:null,emptyAnnotation:ue,emptyAnnotationPage:pe,emptyCanvas:fe,emptyCollection:he,emptyManifest:ve,emptyRange:de,emptyAgent:ye,emptyService:me,defaultEntities:{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}},getDefaultEntities:Ie,merge:_e,mergeEntities:we,traverseSpecificResource:ke,addFlagForExternalResource:$e,normalize:function(e){const t=J(e),i={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}},r={},n=function(e,t){return(i,r)=>{const n=e[i]?e[i]:{};return(e,s)=>{const a=Se(e,r||i);return a&&a.id&&i?(n[a.id]=n[a.id]?we(n[a.id],a,{parent:s.parent,isTopLevel:t.id===a.id}):we({id:a.id,type:a.type},a,{parent:s.parent,isTopLevel:t.id===a.id}),{id:a.id,type:"ContentResource"===i?i:a.type}):a}}}(i,t),s=function(e){return(t,i)=>r=>{const{id:n,type:s}=Se(r,i||t);if(void 0===n)throw new Error("Found invalid entity without an ID.");return e[n]="ContentResource"===t||"Service"===t?t:s,r}}(r);return{entities:i,resource:new be({collection:[$e,Le(he),s("Collection"),n("Collection")],manifest:[$e,Le(ve),Te,s("Manifest"),n("Manifest")],canvas:[Le(fe),s("Canvas"),n("Canvas")],annotationPage:[$e,Fe("AnnotationPage"),Le(pe),s("AnnotationPage"),n("AnnotationPage")],annotation:[Fe("Annotation"),je,ze,s("Annotation"),n("Annotation")],contentResource:[Fe("ContentResource"),s("ContentResource"),n("ContentResource")],range:[Le(de),Pe,s("Range","Canvas"),n("Range","Canvas")],agent:[Le(ye),s("Agent"),n("Agent")],specificResource:[ke],service:[Re(i)]}).traverseUnknown(t),mapping:r}},types:Ae,identifyResource:xe,Traverse:be,serializedFieldsToObject:De,serialize:function(e,t,i){if(!t.type||!t.id)throw new Error("Unknown entity");if(!i[t.type])throw new Error(`Serializer not found for ${t.type}`);return function r(n,s,a=0){const o=i[n.type];if(!o)return ne;if(a>20)throw new Error("Circular reference: "+n.id+" "+n.type);const[c,l]=le(e,n.type?n:n.id,s)||(n.id&&n.type?n:null);if(!c)return ne;const u=o(c,e,{parent:s,isTopLevel:t.id===n.id,fullResource:l});let p=u.next();for(;!p.done;){const e=p.value;let t=ne;if(e)if(Array.isArray(e)){const i=[];for(const t of e)i.push(r(t,n,a+1));t=i}else t=r(e,n,a+1);p=u.next(t)}return p.value===ne?ne:De(p.value)}(t)},languageString2to3:Ne,serializeConfigPresentation2:Je,serializeConfigPresentation3:it,WILDCARD:ee,HAS_PART:te,PART_OF:ie,IS_EXTERNAL:re,UNSET:ne,UNWRAP:se,EMPTY:ae,isWildcard:oe,frameResource:ce,resolveIfExists:le,toRef:K,compressSpecificResource:We,isSpecificResource:Z},Symbol.toStringTag,{value:"Module"}));function nt(e){try{if("full"===e)return{full:!0};if("square"===e)return{square:!0};const t=e.startsWith("pct:"),i=e.substr(t?4:0).split(",").map((e=>parseFloat(e)));return{x:i[0],y:i[1],w:i[2],h:i[3],percent:t}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+e)}}function st(e){const t={upscaled:!1,max:!1,confined:!1};if("^"===e[0]&&(t.upscaled=!0,e=e.slice(1)),"max"===e||"full"===e)return t.max=!0,t.serialiseAsFull="full"===e,t;if("!"===e[0]&&(t.confined=!0,e=e.slice(1)),"p"===e[0])return t.percentScale=parseFloat(e.slice(4)),t;const i=e.split(",").map((e=>e.trim()));return i.length&&(""!==i[0]&&(t.width=parseInt(i[0],10)),""!==i[1]&&(t.height=parseInt(i[1],10))),t}function at(e){const t={angle:0};if("!"===e[0]&&(t.mirror=!0,e=e.substr(1)),t.angle=parseFloat(e)%360,Number.isNaN(t.angle))throw new Error(`Invalid rotation ${e}`);return t}function ot(e,t=""){const i=e.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!i)throw new Error(`Invalid or unknown input ${e}`);const r=i[2],n=i[3];let s=i[4];if("/"===s[0]&&(s=s.substr(1)),t.length>0){if("/"===t[0]&&(t=t.substr(1)),t!==s.substr(0,t.length))throw new Error(`Path does not start with prefix (path: ${s}, prefix: ${t})`);s=s.substr(t.length)}return{scheme:r,server:n,path:s,prefix:t}}function ct(e,t=""){const{path:i,scheme:r,server:n,prefix:s}=ot(e,t),a=i.split("/").reverse(),[o,c,l,u,...p]=a,f=p.reverse().filter(Boolean).join("/");if(1===a.length||""===o)return{type:"base",scheme:r,server:n,prefix:s,identifier:f};if("info.json"===o){const[,...e]=a;return{type:"info",scheme:r,server:n,prefix:s,identifier:e.reverse().filter(Boolean).join("/")}}const h=o.split(".");return{type:"image",scheme:r,server:n,prefix:s,identifier:f,originalPath:i,region:nt(u),size:st(l),rotation:at(c),quality:h[0],format:h[1]}}const lt="http://library.stanford.edu/iiif/image-api/compliance.html#level0",ut="http://library.stanford.edu/iiif/image-api/compliance.html#level1",pt="http://library.stanford.edu/iiif/image-api/compliance.html#level2",ft="http://library.stanford.edu/iiif/image-api/conformance.html#level0",ht="http://library.stanford.edu/iiif/image-api/conformance.html#level1",vt="http://library.stanford.edu/iiif/image-api/conformance.html#level2",dt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",yt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",mt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",gt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",At="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",xt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",bt="http://iiif.io/api/image/1/level0.json",Ct="http://iiif.io/api/image/1/profiles/level0.json",It="http://iiif.io/api/image/1/level1.json",St="http://iiif.io/api/image/1/profiles/level1.json",_t="http://iiif.io/api/image/1/level2.json",wt="http://iiif.io/api/image/1/profiles/level2.json",Rt="http://iiif.io/api/image/2/level0.json",Ot="http://iiif.io/api/image/2/profiles/level0.json",Ft="http://iiif.io/api/image/2/level1.json",Lt="http://iiif.io/api/image/2/profiles/level1.json",Et="http://iiif.io/api/image/2/level2.json",jt="http://iiif.io/api/image/2/profiles/level2.json",Mt="level0",Pt="level1",Tt="level2",zt="http://iiif.io/api/image/2/level0",kt="http://iiif.io/api/image/2/level1",$t="http://iiif.io/api/image/2/level2",Dt=[$t,pt,vt,mt,xt,_t,wt,Et,jt,Tt],Wt=[...Dt,kt,ut,ht,yt,At,It,St,Ft,Lt,Pt],Nt=[zt,kt,$t,lt,ut,pt,ft,ht,vt,dt,yt,mt,gt,At,xt,bt,Ct,It,St,_t,wt,Rt,Ot,Ft,Lt,Et,jt,Mt,Pt,Tt],qt=Nt,Bt=[zt,lt,ft,dt,gt,bt,Ct,Rt,Ot,Mt],Ut={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},Ht={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},Gt={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]},Qt=["baseUriRedirect","canonicalLinkHeader","cors","jsonldMediaType","mirroring","profileLinkHeader","regionByPct","regionByPx","regionSquare","rotationArbitrary","rotationBy90s","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh","sizeUpscaling","sizeByWhListed","sizeByDistortedWh","sizeByForcedWh"];function Vt(e){if(-1!==Dt.indexOf(e))return Gt;return-1!==Wt.indexOf(e)?Ht:Ut}function Jt(e){const t=e?Array.isArray(e.profile)?e.profile:[e.profile]:[],i={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let r of t)if("string"==typeof r&&(r=Vt(r)),r){if(r.formats)for(const e of r.formats)-1===i.extraFormats.indexOf(e)&&i.extraFormats.push(e);if(r.qualities)for(const e of r.qualities)-1===i.extraQualities.indexOf(e)&&i.extraQualities.push(e);if(r.supports)for(const e of r.supports)-1===i.extraFeatures.indexOf(e)&&i.extraFeatures.push(e);if(r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea),r.extraFormats)for(const e of r.extraFormats)-1===i.extraFormats.indexOf(e)&&i.extraFormats.push(e);if(r.extraQualities)for(const e of r.extraQualities)-1===i.extraQualities.indexOf(e)&&i.extraQualities.push(e);if(r.extraFeatures)for(const e of r.extraFeatures)-1===i.extraFeatures.indexOf(e)&&i.extraFeatures.push(e);r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea)}if(e.extraFormats)for(const r of e.extraFormats)-1===i.extraFormats.indexOf(r)&&i.extraFormats.push(r);if(e.extraFeatures)for(const r of e.extraFeatures)-1===i.extraFeatures.indexOf(r)&&i.extraFeatures.push(r);if(e.extraQualities)for(const r of e.extraQualities)-1===i.extraQualities.indexOf(r)&&i.extraQualities.push(r);return i}function Xt(e){return e["@id"]?e["@id"]:e.id?e.id:void 0}function Yt(e){if(!e||!e.profile)return!1;if(!Xt(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if("string"==typeof i&&-1!==Nt.indexOf(i))return!0;return!1}function Zt(e,t){if(!Yt(e))return[!1,"Not a valid image service"];t.extraFeatures=t.extraFeatures?t.extraFeatures:[];const i=Jt(e);if(t.exactSize){let i=!1;if(e.sizes)for(const r of e.sizes)r.width&&r.width===t.exactSize.width&&(-1!==Qt.indexOf("sizeByW")||r.height&&r.height===t.exactSize.height)&&(i=!0),r.height&&r.height===t.exactSize.height&&(-1!==Qt.indexOf("sizeByH")||r.width&&r.width===t.exactSize.width)&&(i=!0);i||(t.maxWidth=Math.max(t.maxWidth||0,t.exactSize.width||0)||void 0,t.maxHeight=Math.max(t.maxHeight||0,t.exactSize.height||0)||void 0,t.maxArea=Math.max(t.maxArea||0,(t.exactSize.width&&t.exactSize.height?t.exactSize.width*t.exactSize.height:t.maxArea)||0)||void 0,!t.exactSize.height&&t.exactSize.width?-1===t.extraFeatures.indexOf("sizeByW")&&t.extraFeatures.push("sizeByW"):!t.exactSize.width&&t.exactSize.height&&-1===t.extraFeatures.indexOf("sizeByH")&&t.extraFeatures.push("sizeByH"))}if(t.maxArea&&i.maxArea&&t.maxArea>i.maxArea)return[!1,`Max area is ${i.maxArea}`];if(t.maxWidth&&i.maxWidth&&t.maxWidth>i.maxWidth)return[!1,`Max width is ${i.maxWidth}`];if(t.maxHeight&&i.maxHeight&&t.maxHeight>i.maxHeight)return[!1,`Max height is ${i.maxHeight}`];if(t.extraFeatures){const e=[];for(const r of t.extraFeatures)-1===i.extraFeatures.indexOf(r)&&e.push(r);if(e.length)return[!1,`Missing features: ${e.join(", ")}`]}if(t.extraFormats){const e=[];for(const r of t.extraFormats)-1===i.extraFormats.indexOf(r)&&e.push(r);if(e.length)return[!1,`Missing formats: ${e.join(", ")}`]}if(t.extraQualities){const e=[];for(const r of t.extraQualities)-1===i.extraQualities.indexOf(r)&&e.push(r);if(e.length)return[!1,`Missing qualities: ${e.join(", ")}`]}return[!0]}function Kt({x:e=0,y:t=0,w:i,h:r,full:n,square:s,percent:a}){if(n)return"full";if(s)return"square";if(void 0===i||void 0===r)throw new Error("RegionParameter: invalid region");const o=`${e},${t},${i},${r}`;return a?`pct:${o}`:o}function ei({max:e,percentScale:t,upscaled:i,confined:r,width:n,height:s,serialiseAsFull:a}){const o=[];return i&&o.push("^"),e?(o.push(a?"full":"max"),o.join("")):(r&&o.push("!"),t&&o.push(`pct:${t}`),n&&o.push(`${n}`),o.push(","),s&&o.push(`${s}`),o.join(""))}function ti(e){return`${e.mirror?"!":""}${(e.angle||0)%360}`}function ii(e){return e.endsWith("info.json")?e:e.endsWith("/")?`${e}info.json`:`${e}/info.json`}return{Presentation2:Y,Presentation3:rt,Image3:Object.freeze(Object.defineProperty({__proto__:null,parseImageServerFromId:function(e){const t=e.replace(/(https?:\/\/)?(www.)?/i,"");return-1!==t.indexOf("/")?t.split("/")[0]:t},parseImageServiceRequest:ct,parseImageServiceUrl:ot,parseRegionParameter:nt,parseRotationParameter:at,parseSizeParameter:st,STANFORD_IIIF_IMAGE_COMPLIANCE_0:lt,STANFORD_IIIF_IMAGE_COMPLIANCE_1:ut,STANFORD_IIIF_IMAGE_COMPLIANCE_2:pt,STANFORD_IIIF_IMAGE_CONFORMANCE_0:ft,STANFORD_IIIF_IMAGE_CONFORMANCE_1:ht,STANFORD_IIIF_IMAGE_CONFORMANCE_2:vt,STANFORD_IIIF_1_IMAGE_COMPLIANCE_0:dt,STANFORD_IIIF_1_IMAGE_COMPLIANCE_1:yt,STANFORD_IIIF_1_IMAGE_COMPLIANCE_2:mt,STANFORD_IIIF_1_IMAGE_CONFORMANCE_0:gt,STANFORD_IIIF_1_IMAGE_CONFORMANCE_1:At,STANFORD_IIIF_1_IMAGE_CONFORMANCE_2:xt,IIIF_1_IMAGE_LEVEL_0:bt,IIIF_1_IMAGE_LEVEL_0_PROFILE:Ct,IIIF_1_IMAGE_LEVEL_1:It,IIIF_1_IMAGE_LEVEL_1_PROFILE:St,IIIF_1_IMAGE_LEVEL_2:_t,IIIF_1_IMAGE_LEVEL_2_PROFILE:wt,IIIF_2_IMAGE_LEVEL_0:Rt,IIIF_2_IMAGE_LEVEL_0_PROFILE:Ot,IIIF_2_IMAGE_LEVEL_1:Ft,IIIF_2_IMAGE_LEVEL_1_PROFILE:Lt,IIIF_2_IMAGE_LEVEL_2:Et,IIIF_2_IMAGE_LEVEL_2_PROFILE:jt,IIIF_3_IMAGE_LEVEL_0:Mt,IIIF_3_IMAGE_LEVEL_1:Pt,IIIF_3_IMAGE_LEVEL_2:Tt,IIIF_2_IMAGE_LEVEL_0_NO_JSON:zt,IIIF_2_IMAGE_LEVEL_1_NO_JSON:kt,IIIF_2_IMAGE_LEVEL_2_NO_JSON:$t,level2Support:Dt,level1Support:Wt,imageServiceProfiles:Nt,level0Support:qt,onlyLevel0:Bt,level0:Ut,level1:Ht,level2:Gt,extraFeatures:Qt,combineProfiles:Jt,levelToProfile:Vt,isLevel0:function(e){const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if("string"==typeof i&&-1!==Bt.indexOf(i))return!0;return!1},supports:Zt,supportsCustomSizes:function(e){if(!Yt(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if("string"==typeof i){if(-1!==Wt.indexOf(i))return!0}else{const e=[...i.supports||[],...i.extraFeatures||[]];if(-1!==e.indexOf("regionByPx")&&(-1!==e.indexOf("sizeByW")||-1!==e.indexOf("sizeByWh")))return!0}return!1},imageServiceSupportsFormat:function(e,t){return Zt(e,{extraFormats:[t]})},imageServiceSupportsRequest:function(e,t){if("image"!==t.type)return[!0];const i=[];if(t.rotation.mirror&&i.push("mirroring"),t.region.percent&&i.push("regionByPct"),t.region.square?i.push("regionSquare"):t.region.full||i.push("regionByPx"),t.rotation.angle){t.rotation.angle%90?i.push("rotationArbitrary"):i.push("rotationBy90s")}t.size.confined&&i.push("sizeByConfinedWh"),!t.size.width&&t.size.height&&i.push("sizeByH"),t.size.percentScale&&i.push("sizeByPct"),(e.sizes||[]).find((e=>e.width===t.size.width&&!t.size.height||e.height===t.size.height&&!t.size.width||e.height===t.size.height&&e.width===t.size.width))?i.push("sizeByWhListed"):(t.size.width&&!t.size.height&&i.push("sizeByW"),t.size.width&&t.size.height&&i.push("sizeByWh")),t.size.upscaled&&i.push("sizeUpscaling");const[r,n]=Zt(e,{extraFeatures:i,extraQualities:[t.quality],extraFormats:[t.format],exactSize:t.size});return r?[!0]:[!1,n]},imageServiceRequestToString:function(e,t){const i=e.prefix.startsWith("/")?e.prefix.substr(1):e.prefix,r=`${e.scheme}://${e.server}/${i?`${i}/`:""}${e.identifier}`;if("base"===e.type)return r;if("info"===e.type)return`${r}/info.json`;let{size:n}=e;const{region:s,rotation:a,format:o,quality:c}=e;if(t){const e=t["@context"]?Array.isArray(t["@context"])?t["@context"]:[t["@context"]]:[],i=-1!==e.indexOf("http://iiif.io/api/image/2/context.json"),r=-1!==e.indexOf("http://iiif.io/api/image/3/context.json");if((n.width===t.width&&!n.height||n.height===t.height&&!n.width||n.width===t.width&&n.height===t.height)&&(n={...n,max:!0}),i&&(n.max&&!n.serialiseAsFull&&(n={...n,serialiseAsFull:!0}),!n.max&&n.width&&n.height&&(n={...n,height:void 0})),r&&(n.max&&n.serialiseAsFull&&(n={...n,serialiseAsFull:!1}),n.width&&!n.height&&t.width&&t.height)){const e=t.height/t.width;n={...n,height:Math.ceil(n.width*e)}}}return[r,Kt(s),ei(n),ti(a),`${c}.${o}`].filter(Boolean).join("/")},regionParameterToString:Kt,rotationParameterToString:ti,sizeParameterToString:ei,canonicalServiceUrl:ii,createImageServiceRequest:function(e){const t=ct(ii(e.id));if("info"!==t.type)throw new Error("Invalid service URL");const i=Jt(e);return{identifier:t.identifier,originalPath:"",server:t.server,prefix:t.prefix,scheme:t.scheme,type:"image",quality:-1===i.extraQualities.indexOf("default")?i.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}},extractFixedSizeScales:function(e,t,i){const r=i.length,n=[];for(let s=0;s<r;s++){const t=i[s].width;n.push(e/t)}return n},fixedSizesFromScales:function(e,t,i){const r=i.length,n=[];for(let s=0;s<r;s++){const r=i[s];n.push({width:Math.floor(e/r),height:Math.floor(t/r)})}return n},getId:Xt,getType:function(e){return e["@type"]?e["@type"]:e.type?e.type:void 0},isImageService:Yt},Symbol.toStringTag,{value:"Module"}))}})); | ||
| var __defProp=Object.defineProperty,__defNormalProp=(e,t,i)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,__publicField=(e,t,i)=>(__defNormalProp(e,"symbol"!=typeof t?t+"":t,i),i);!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).IIIFParser=t()}(this,(function(){"use strict";const e=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function t(t){if(null==t)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(t))throw new Error("Array is not a valid entity");if("object"!=typeof t)throw new Error(typeof t+" is not a valid entity");if("string"==typeof t["@type"]){const i=e.indexOf(t["@type"]);if(-1!==i)return e[i]}if(t.profile)return"Service";if(t.format)return"ContentResource";if(t["@type"])return"ContentResource";throw new Error("Resource type is not known")}class i{constructor(e,t={}){__publicField(this,"traversals"),__publicField(this,"options"),this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...t}}static all(e){return new i({collection:[e],manifest:[e],canvas:[e],annotationList:[e],sequence:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],layer:[e]})}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))),this.traversals.collection)}traverseCollectionItems(e){if(this.options.mergeMemberProperties){const t=[...(e.manifests||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Manifest"}:e)),...(e.collections||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Collection"}:e)),...e.members||[]];delete e.collections,delete e.manifests,e.members=t}return e.manifests&&(e.manifests=e.manifests.map((e=>this.traverseManifest("string"==typeof e?{"@id":e,"@type":"sc:Manifest"}:e)))),e.collections&&(e.collections=e.collections.map((e=>this.traverseCollection("string"==typeof e?{"@id":e,"@type":"sc:Collection"}:e)))),e.members&&(e.members=e.members.map((e=>"string"==typeof e?e:this.traverseUnknown(e)))),e}traverseManifest(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))),this.traversals.manifest)}traverseManifestItems(e){return e.sequences&&(e.sequences=e.sequences.map((e=>this.traverseSequence(e)))),e.structures&&(e.structures=e.structures.map((e=>this.traverseRange(e)))),e}traverseSequence(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))),this.traversals.sequence)}traverseSequenceItems(e){return e.canvases&&(e.canvases=e.canvases.map((e=>this.traverseCanvas(e)))),e}traverseCanvas(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))),this.traversals.canvas)}traverseCanvasItems(e){return e.images&&(e.images=e.images.map((e=>this.traverseAnnotation(e)))),e.otherContent&&(e.otherContent=e.otherContent.map((e=>this.traverseAnnotationList(e)))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const t=[...(e.ranges||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Range"}:e)),...(e.canvases||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Canvas"}:e)),...e.members||[]];delete e.ranges,delete e.canvases,e.members=t.length?t.map((e=>this.traverseUnknown(e))):void 0}return e}traverseAnnotationList(e){const t="string"==typeof e?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(t)),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map((e=>this.traverseAnnotation(e)))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(Array.isArray(e.resource)?e.resource=e.resource.map((e=>this.traverseContentResource(e))):e.resource=this.traverseContentResource(e.resource)),e.on,e}traverseLayer(e){return this.traverseType(this.traverseLinking(this.traverseLayerItems(e)),this.traversals.layer)}traverseLayerItems(e){return e.otherContent&&(e.otherContent=e.otherContent.map((e=>this.traverseAnnotationList(e)))),e}traverseChoice(e){return this.traverseType(this.traverseChoiceItems(e),this.traversals.choice)}traverseChoiceItems(e){return e.default&&"rdf:nil"!==e.default&&(e.default=this.traverseContentResource(e.default)),e.item&&"rdf:nil"!==e.item&&(e.item=e.item.map((e=>this.traverseContentResource(e)))),e}traverseService(e){return this.traverseType(this.traverseLinking(e),this.traversals.service)}traverseContentResource(e){return"oa:Choice"===e["@type"]?this.traverseChoice(e):this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.contentResource)}traverseUnknown(e){if(!e["@type"]||"string"==typeof e)return e;switch(t(e)){case"sc:Collection":return this.traverseCollection(e);case"sc:Manifest":return this.traverseManifest(e);case"sc:Canvas":return this.traverseCanvas(e);case"sc:Sequence":return this.traverseSequence(e);case"sc:Range":return this.traverseRange(e);case"oa:Annotation":return this.traverseAnnotation(e);case"sc:AnnotationList":return this.traverseAnnotationList(e);case"sc:Layer":return this.traverseLayer(e);case"Service":return this.traverseService(e);case"oa:Choice":return this.traverseChoice(e);case"ContentResource":return this.traverseContentResource(e)}return e.profile?this.traverseService(e):e}traverseImageResource(e){const t=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(const n of i)"string"==typeof n?r.push(this.traverseContentResource({"@id":n,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(n));return t||this.options.convertPropsToArray?r:r[0]}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){const t=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(const n of i)r.push(this.traverseService(n));return t||this.options.convertPropsToArray?r:r[0]}traverseLinking(e){return e.related&&(e.related=this.traverseOneOrManyType(e.related,this.traversals.contentResource)),e.rendering&&(e.rendering=this.traverseOneOrManyType(e.rendering,this.traversals.contentResource)),e.service&&(e.service=this.traverseOneOrMoreServices(e.service)),e.seeAlso&&(e.seeAlso=this.traverseOneOrManyType(e.seeAlso,this.traversals.contentResource)),e.within&&("string"==typeof e.within||(e.within=this.traverseOneOrManyType(e.within,this.traversals.contentResource))),e.startCanvas&&("string"==typeof e.startCanvas?e.startCanvas=this.traverseType({"@id":e.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):e.startCanvas&&this.traverseType(e.startCanvas,this.traversals.canvas)),e.contentLayer&&("string"==typeof e.contentLayer?e.contentLayer=this.traverseLayer({"@id":e.contentLayer,"@type":"sc:Layer"}):e.contentLayer=this.traverseLayer(e.contentLayer)),e}traverseOneOrManyType(e,t){if(!Array.isArray(e)){if(!this.options.convertPropsToArray)return this.traverseType(e,t);e=[e]}return e.map((e=>this.traverseType(e,t)))}traverseType(e,t){return t.reduce(((e,t)=>{const i=t(e);return void 0!==i||this.options.allowUndefinedReturn?i:e}),e)}}const r="http://library.stanford.edu/iiif/image-api/compliance.html#level1",n="http://library.stanford.edu/iiif/image-api/compliance.html#level2",s="http://library.stanford.edu/iiif/image-api/conformance.html#level1",a="http://library.stanford.edu/iiif/image-api/conformance.html#level2",o="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",c="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",l="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",u="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",p="http://iiif.io/api/image/1/level1.json",f="http://iiif.io/api/image/1/profiles/level1.json",h="http://iiif.io/api/image/1/level2.json",v="http://iiif.io/api/image/1/profiles/level2.json",d="http://iiif.io/api/image/2/level1.json",y="http://iiif.io/api/image/2/profiles/level1.json",m="http://iiif.io/api/image/2/level2.json",g="http://iiif.io/api/image/2/profiles/level2.json",A="level1",x="level2",b="http://iiif.io/api/image/2/level1",C="http://iiif.io/api/image/2/level2",I=[b,C,r,n,s,a,o,c,l,u,p,f,h,v,d,y,m,g,A,x],S=["http://iiif.io/api/image/2/level0",b,C,"http://library.stanford.edu/iiif/image-api/compliance.html#level0",r,n,"http://library.stanford.edu/iiif/image-api/conformance.html#level0",s,a,"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",o,c,"http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",l,u,"http://iiif.io/api/image/1/level0.json","http://iiif.io/api/image/1/profiles/level0.json",p,f,h,v,"http://iiif.io/api/image/2/level0.json","http://iiif.io/api/image/2/profiles/level0.json",d,y,m,g,"level0",A,x];function _(e){return Array.isArray(e)?e:e?[e]:[]}function w(e){for(const t in e)void 0!==e[t]&&null!==e[t]||delete e[t];return e}const R="Attribution",O="http://example.org/provider",F="Unknown";function L(e,t="none"){if(!e)return{};const i=function(e){if("string"==typeof e)return[e];if(!e)return[];const t=Array.isArray(e)?e:[e],i=[];for(const r of t)"string"!=typeof r?i.push({"@language":r["@language"]||r.language,"@value":r["@value"]||r.value}):i.push(r);return i}(e),r={};for(const n of i){if("string"==typeof n){r[t]=r[t]?r[t]:[],r[t].push(n||"");continue}if(!n["@language"]){r[t]=r[t]?r[t]:[],r[t].push(n["@value"]||"");continue}const e=n["@language"];r[e]=r[e]?r[e]:[],r[e].push(n["@value"]||"")}return r}function E(e){return Array.isArray(e)?E(e.find((e=>"string"==typeof e))):-1!==S.indexOf(e)?"level2":-1!==I.indexOf(e)?"level1":"string"==typeof e?e:void 0}function j(e){const t=Array.isArray(e)?e:[e];for(const i of t)switch(i){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function M(e){for(const t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}const P=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function T(e){const t=e["@id"]||e.id;let i=e["@type"]||e.type;const r=e.profile||void 0,n=e["@context"]||void 0;if(r){const e=function(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"}}(r);if(e)return e}if(n){const e=j(n);if(e)return e}if(i){if(Array.isArray(i)){if(-1!==i.indexOf("oa:CssStylesheet"))return"CssStylesheet";if(-1!==i.indexOf("cnt:ContentAsText"))return"TextualBody";i=i[0]}for(const e of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${e}:`)){i=i.slice(e.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(i&&-1!==P.indexOf(i))return i;if(e.format){if(e.format.startsWith("image/"))return"Image";if(e.format.startsWith("text/"))return"Text";if("application/pdf"===e.format)return"Text";if(e.format.startsWith("application/"))return"Dataset"}return t&&(t.endsWith(".jpg")||t.endsWith(".png")||t.endsWith(".jpeg"))?"Image":i||"unknown"}const z=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function k(e){const t=e.match(z);return t?t[0]:e}const $=["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 D(e){if(e){const t=Array.isArray(e)?e:[e],i=[];for(const e of t)"http://iiif.io/api/presentation/2/context.json"===e&&i.push("http://iiif.io/api/presentation/3/context.json"),-1===$.indexOf(e)&&i.push(e);if(t.length)return 1===i.length?i[0]:i}}let W=0;function N(e,t){const i=encodeURI(e.id||e["@id"]||"").trim();return i&&t?`${i}/${t}`:i||(W++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${W}`)}function q(e){const t=[...e.behavior||[]];let i;return e.viewingHint&&t.push(e.viewingHint),Array.isArray(e.motivation)?i=e.motivation.map(M):e.motivation&&(i=M(e.motivation)),{"@context":e["@context"]?D(e["@context"]):void 0,id:(e["@id"]||N(e)).trim(),type:T(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:i,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function B(e){const[t,i]=function(e,t="Rights/License",i="none"){let r=null;const n=[],s=Array.isArray(e)?e:[e];for(const a of s){const e=a?k(a):void 0;!e||-1===e.indexOf("creativecommons.org")&&-1===e.indexOf("rightsstatements.org")?e&&n.push({label:{[i]:[t]},value:{[i]:[e]}}):r=e.startsWith("https://")?`http://${e.slice(8)}`:e}return[r,n]}(e.license),r=[...e.metadata?(n=e.metadata,n?n.map((e=>({label:L(e.label),value:L(e.value)}))):[]):[],...i];var n;return{rights:t,metadata:r.length?r:void 0,label:e.label?L(e.label):void 0,requiredStatement:e.attribution?{label:L(R),value:L(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?L(e.description):void 0,thumbnail:U(e.thumbnail)}}function U(e){if(e){return(Array.isArray(e)?e:[e]).map((e=>"string"==typeof e?{id:e,type:"Image"}:("unknown"===e.type&&(e.type="Image"),e)))}return e}function H(e){if(!e.within)return;const t=Array.isArray(e.within)?e.within:[e.within],i=[];for(const r of t)if("string"==typeof r){if(r&&"sc:Manifest"===e["@type"])i.push({id:r,type:"Collection"})}else r["@id"]&&i.push({id:r["@id"],type:T(r)});return i.length?i:void 0}function G(e){const t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],i=e.contentLayer;return{provider:e.logo||t.length?[{id:O,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:L(F)}]:void 0,partOf:H(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?_(e.service):void 0,supplementary:i?[i]:void 0}}function Q(e){const t=e;return w({...q(t),...B(t),...G(t),...(i=t,{chars:i.chars,format:i.format?i.format:void 0,language:i.language})});var i}const V=new i({collection:[function(e){return w({...q(e),...B(e),...G(e),items:e.members})}],manifest:[function(e){const t=[],i=[];let r;for(const s of e.sequences||[])s.canvases.length&&t.push(...s.canvases),s.behavior&&i.push(...s.behavior),s.startCanvas&&(r=s.startCanvas);const n=q(e);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),w({...n,...B(e),...G(e),start:r,items:t,structures:e.structures})}],canvas:[function(e){return w({...q(e),...B(e),...G(e),annotations:e.otherContent&&e.otherContent.length?e.otherContent:void 0,items:e.images&&e.images.length?[{id:N(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}],annotationList:[function(e){return w({...q(e),...B(e),...G(e),items:e.resources&&e.resources.length?e.resources:void 0})}],sequence:[function(e){return e.canvases&&0!==e.canvases.length?{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}:{canvases:[],behavior:[]}}],annotation:[function(e){return w({...q(e),...B(e),...G(e),target:function e(t){if(Array.isArray(t)){if(t.length>1)return{type:"List",items:t.map(e)};t=t[0]}if("string"==typeof t)return encodeURI(t).trim();if("@type"in t){let e;if("string"==typeof t.full)e=t.full;else if("dctypes:Image"===t.full["@type"])e={id:t.full["@id"],type:"Image"};else{if("sc:Canvas"!==t.full["@type"])throw new Error(`Unsupported source type on annotation: ${t.full["@type"]}`);e={id:t.full["@id"],type:"Canvas"}}return{type:"SpecificResource",source:e,selector:X(t.selector)}}return encodeURI(t["@id"]).trim()}(e.on),body:Array.isArray(e.resource)?e.resource.map(Q):Q(e.resource)})}],contentResource:[Q],choice:[function(e){const t=[];return e.default&&"rdf:nil"!==e.default&&t.push(e.default),e.item&&"rdf:nil"!==e.item&&t.push(...e.item),{...q(e),...B(e),items:t}}],range:[function(e){return w({...q(e),...B(e),...G(e),items:e.members})}],service:[function(e){const{"@id":t,"@type":i,"@context":r,profile:n,...s}=e,a={};return t&&(a["@id"]=t),a["@type"]=T(e),"unknown"===a["@type"]&&(r&&r.length&&(a["@context"]=r),a["@type"]="Service"),n&&(a.profile=E(n)),w({...a,...s})}],layer:[function(e){return w({...q(e),...B(e),...G(e)})}]});function J(e){return e&&e["@context"]&&("http://iiif.io/api/presentation/2/context.json"===e["@context"]||-1!==e["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")||"http://www.shared-canvas.org/ns/context.json"===e["@context"])||"http://iiif.io/api/image/2/context.json"===e["@context"]?V.traverseUnknown(e):e}function X(e){if((Array.isArray(e["@type"])&&e["@type"].includes("oa:SvgSelector")||"oa:SvgSelector"==e["@type"])&&("chars"in e||"value"in e))return{type:"SvgSelector",value:"chars"in e?e.chars:e.value};if("oa:FragmentSelector"===e["@type"])return{type:"FragmentSelector",value:e.value};if("oa:Choice"===e["@type"])return[X(e.default),...(Array.isArray(e.item)?e.item:[e.item]).map(X)];if("iiif:ImageApiSelector"==e["@type"])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"]}`)}const Y=Object.freeze(Object.defineProperty({__proto__:null,types:e,identifyResource:t,Traverse:i,convertLanguageMapping:L,getProfile:E,getTypeFromContext:j,presentation2to3:V,convertPresentation2:J},Symbol.toStringTag,{value:"Module"}));function Z(e){return"string"!=typeof e&&(!!e&&"SpecificResource"===e.type)}function K(e,t){const i=t||"unknown";if(!e)return;if("string"==typeof e)return{id:e,type:i};if(Z(e))return K(e.source,t);let r=i&&"unknown"!==i?i:e.type||e["@type"];const n=e.id||e["@id"];return r&&-1!==r.indexOf(":")&&(r=r.split(":").pop()),n&&r?{id:n,type:r}:void 0}const ee={},te="iiif-parser:hasPart",ie="iiif-parser:partOf",re="iiif-parser:isExternal",ne="__$UNSET$__",se="__$UNWRAP$__",ae=[];function oe(e){if(e===ee||0===Object.keys(e).length)return!0;for(const t in e)return!1;return!0}function ce(e,t){if(t&&t["@explicit"]){const i={},r=Object.keys(t);for(const n of r)n!==ie&&"@explicit"!==n&&(oe(t[n])?i[n]=e[n]:i[n]=t[n]);return i}return e}function le(e,t,i){const r=K(t);if(!r)return[void 0,void 0];const n=e.requests[r.id],s=r.type||e.mapping[r.id];if(!s||n&&n.resourceUri&&!e.entities[s][n.resourceUri])return[void 0,void 0];const a=e.entities[s][n?n.resourceUri:r.id];if(r.type&&!a)return le(e,{id:r.id},i);if(a&&a[te]){const e=a[te].find((e=>i?e[ie]===i.id:e[ie]===a.id));return[ce(a,e),a]}return[a,a]}Object.freeze(ae),Object.freeze(ee);const ue={id:"https://iiif-parser/annotation",type:"Annotation",behavior:ae,label:null,thumbnail:ae,summary:null,requiredStatement:null,metadata:ae,seeAlso:ae,homepage:ae,rendering:ae,service:ae,accessibility:ae,audience:ae,body:ae,bodyValue:null,canonical:null,created:null,creator:ae,generated:null,generator:ae,modified:null,motivation:ae,rights:null,stylesheet:null,target:ae,timeMode:void 0,via:ae,partOf:ae},pe={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:ae,label:null,thumbnail:ae,summary:null,requiredStatement:null,metadata:ae,rights:null,provider:ae,items:ae,seeAlso:ae,homepage:ae,rendering:ae,service:ae},fe={id:"https://iiif-parser/empty-canvas",type:"Canvas",label:null,behavior:ae,thumbnail:ae,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:ae,rights:null,navDate:null,provider:ae,items:ae,annotations:ae,seeAlso:ae,homepage:ae,partOf:ae,rendering:ae,service:ae,duration:0,height:0,width:0},he={id:"https://iiif-parser/empty-collection",type:"Collection",label:null,viewingDirection:"left-to-right",behavior:ae,thumbnail:ae,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:ae,rights:null,navDate:null,provider:ae,items:ae,annotations:ae,seeAlso:ae,homepage:ae,partOf:ae,rendering:ae,service:ae,services:ae},ve={id:"https://iiif-parser/empty-manifest",type:"Manifest",annotations:ae,behavior:ae,homepage:ae,items:ae,label:null,metadata:ae,navDate:null,provider:ae,partOf:ae,accompanyingCanvas:null,placeholderCanvas:null,rendering:ae,requiredStatement:null,rights:null,seeAlso:ae,service:ae,services:ae,start:null,structures:ae,summary:null,thumbnail:ae,viewingDirection:"left-to-right"},de={id:"https://iiif-parser/empty-canvas",type:"Range",label:null,behavior:ae,thumbnail:ae,accompanyingCanvas:null,placeholderCanvas:null,summary:null,requiredStatement:null,metadata:ae,rights:null,navDate:null,provider:ae,items:ae,annotations:ae,seeAlso:ae,homepage:ae,partOf:ae,rendering:ae,service:ae,start:null,supplementary:null,viewingDirection:"left-to-right"},ye={id:"https://iiif-parser/empty-agent",type:"Agent",label:{},logo:ae,seeAlso:ae,homepage:ae},me={id:"https://iiif-parser/empty-service",type:"UnknownService"};function ge(...e){return t=>e.reduce(((e,t)=>t(e)),t)}const Ae=["Collection","Manifest","Canvas","AnnotationPage","AnnotationCollection","Annotation","ContentResource","Range","Service","Selector","Agent"];function xe(e,t){if(null==e)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("object"!=typeof e){if(t)return t;throw new Error(typeof e+" is not a valid entity")}if("string"==typeof e.type){const t=Ae.indexOf(e.type);if(-1!==t)return Ae[t]}if(e.profile)return"Service";throw new Error("Resource type is not known")}class be{constructor(e,t={}){__publicField(this,"traversals"),__publicField(this,"options"),__publicField(this,"_traverseManifest",ge(this.traverseManifestItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseManifestStructures.bind(this),this.traverseInlineAnnotationPages.bind(this))),__publicField(this,"_traverseCanvas",ge(this.traverseCanvasItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this),this.traverseLinkedCanvases.bind(this),this.traverseInlineAnnotationPages.bind(this))),__publicField(this,"_traverseAnnotationPage",ge(this.traverseAnnotationPageItems.bind(this),this.traverseLinking.bind(this),this.traverseDescriptive.bind(this))),__publicField(this,"_traverseRange",ge(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 be({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=_(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=_(e.service).map((e=>this.traverseService(e)))),e.services&&(e.services=_(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=>"string"!=typeof t&&t.type?"Canvas"===t.type?this.traverseType(t,{parent:e},this.traversals.canvas):"AnnotationCollection"===t.type?this.traverseType(t,{parent:e},this.traversals.annotationCollection):"Collection"===t.type?this.traverseType(t,{parent:e},this.traversals.collection):this.traverseType(t,{parent:e},this.traversals.contentResource):this.traverseType(t,{parent:e},this.traversals.contentResource)))),e.start&&(Z(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((e=>"Collection"===e.type?this.traverseCollection(e):this.traverseManifest(e))),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((e=>this.traverseCanvas(e)))),e}traverseManifestStructures(e){return e.structures&&(e.structures=e.structures.map((e=>this.traverseRange(e)))),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"string"!=typeof e&&e?(e.annotations&&(e.annotations=e.annotations.map((t=>this.traverseAnnotationPage(t,e)))),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"string"!=typeof e&&e?(e&&e.service&&(e.service=_(e.service||[]).map((t=>this.traverseService(t,e)))),e):e}traverseContentResource(e,t){return"Choice"===e.type&&(e.items=e.items.map((t=>this.traverseContentResource(t,e)))),Z(e)?this.traverseSpecificResource(e,"ContentResource"):this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)),{parent:t},this.traversals.contentResource)}traverseSpecificResource(e,t,i){let r=e.source;return"string"==typeof e.source&&(r={id:e.source,type:t||"unknown"}),this.traverseType({...e,source:"Canvas"===t||"Canvas"===r.type?this.traverseType(r,{parent:i},this.traversals.canvas):"ContentResource"===t?this.traverseContentResource(r,{parent:i}):this.traverseUnknown(r,{parent:i,typeHint:t})},{parent:i},this.traversals.specificResource)}traverseRangeRanges(e){return e.items&&(e.items=e.items.map((t=>"string"==typeof t?this.traverseCanvas({id:t,type:"Canvas"},e):Z(t)?this.traverseSpecificResource(t,"Canvas",e):"Manifest"===t.type?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,i){return i.reduce(((e,i)=>{const r=i(e,t);return void 0!==r||this.options.allowUndefinedReturn?r:e}),e)}traverseService(e,t){const i=Object.assign({},e);return i&&i.service&&(i.service=_(i.service).map((e=>this.traverseService(e)))),this.traverseType(i,{parent:t},this.traversals.service)}traverseUnknown(e,{parent:t,typeHint:i}={}){const r=xe(e,i);switch(r){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:if(i)return i;throw new Error(`Unknown or unsupported resource type of ${r}`)}}}function Ce(e,t={}){if(Array.isArray(e))return Ce(e[0]);if("string"==typeof e){const[i,r]=e.split("#");return r?{type:"SpecificResource",source:{id:i,type:t.typeHint||"Unknown"},selector:{type:"FragmentSelector",value:r}}:{type:"SpecificResource",source:{id:i,type:t.typeMap&&t.typeMap[i]||t.typeHint||"Unknown"}}}if("Choice"===e.type||"List"===e.type||"Composite"===e.type||"Independents"===e.type)return Ce(e.items[0]);if("SpecificResource"===e.type)return"Canvas"===e.source.type&&e.source.partOf&&"string"==typeof e.source.partOf&&(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){"Canvas"===e.type&&e.partOf&&"string"==typeof e.partOf&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[t,i]=e.id.split("#");return i?{type:"SpecificResource",source:{...e,id:t},selector:{type:"FragmentSelector",value:i}}:{type:"SpecificResource",source:{...e,id:t}}}return{type:"SpecificResource",source:e}}function Ie(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}function Se(e,t){if("string"==typeof e)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 _e(e,t,i){if(!t)return e;if(Array.isArray(e)){if(!Array.isArray(t))throw new Error("Cannot merge array with non-array");const i=[...e];for(const r of t)if(r["@id"]&&!r.id&&(r.id=r["@id"]),r["@type"]&&!r.type&&(r.type=r["@type"]),null!=r)if(Array.isArray(r))i.push(r);else if("object"==typeof r&&r.id&&r.type){const e=i.findIndex((e=>e.id===r.id&&e.type===r.type));e>=0&&(i[e]=_e(i[e],r))}else-1===e.indexOf(r)&&i.push(r);return i}if("object"==typeof e){if(Array.isArray(t)||"object"!=typeof t)throw new Error("Cannot merge object with non-object");const r={...e},n=[],s=[],a=Object.keys(e).filter((e=>e!==te&&"id"!==e&&"type"!==e)),o={},c={};for(const[e,i]of Object.entries(t)){if(e===te||"id"===e||"type"===e)continue;const t=r[e];t===i?s.push(e):t!==ae&&t?(t&&i&&(o[e]=t,c[e]=i),r[e]=_e(t,i),r[e]===o[e]&&(s.push(e),delete o[e])):(n.push(e),r[e]=i)}if(i&&(i.parent&&i.parent.id||i.isTopLevel)){const t=[],l={};if(i.parent?l[ie]=i.parent.id:i.isTopLevel&&(l[ie]=e.id),r[te]&&r[te].length){const e=!(r[te]||[]).find((e=>e["@explicit"])),i=n.length>0||s.length!==a.length;if(e&&i)for(const n of r[te]){const e={...n},i=Object.keys(o);if(e){e["@explicit"]=!0;for(const t of a)t!==te&&(e[t]=ee);for(const t of i)e[t]=o[t]}t.push(e)}else t.push(...r[te]);if(i){const e=Object.keys(c);l["@explicit"]=!0;for(const t of n)l[t]=ee;for(const t of s)l[t]=ee;for(const t of e)l[t]=c[t]}}l.id=r.id,l.type=r.type,t.push(l),r[te]=t}return r}return e||t}function we(e,t,i){if("string"==typeof e)return e;if(t.id!==e.id||t.type!==e.type){if("ImageService3"===t.type)return t;if("ImageService3"===e.type)return e;throw new Error(`Can only merge entities with identical identifiers and type! ${t.type}(${t.id}) => ${e.type}(${e.id})`)}return _e({...e},t,i)}function Re(e){return t=>{e.Service=e.Service?e.Service:{};const i=t.id||t["@id"],r=function(e){const t=Object.assign({},e);if(t["@id"]&&(t.id=t["@id"]),t["@type"]&&(t.type=t["@type"]),t.service){const e=[];t.service=Array.isArray(t.service)?t.service:[t.service];for(const i of t.service)e.push({id:i["@id"]||i.id,type:i["@type"]||i.type});t.service=e}return Object.assign({},me,t)}(t);return r&&r.id&&(e.Service[r.id]?e.Service[i]=we(e.Service[i],r):e.Service[i]=r),t}}function Oe(e){const t=JSON.stringify(e);let i=5381,r=t.length;for(;r;)i=33*i^t.charCodeAt(--r);const n=(i>>>0).toString(16);return n.length%2?"0"+n:n}function Fe(e){return t=>"string"==typeof t?{id:t,type:e}:t.id?t.type?t:{type:e,...t}:{id:`vault://${Oe(t)}`,type:e,...t}}function Le(e){return t=>({...e,...t})}function Ee(e){return Array.isArray(e)?e:[e]}function je(e){return e.body&&(e.body=Ee(e.body)),e.seeAlso&&(e.seeAlso=Ee(e.seeAlso)),e.audience&&(e.audience=Ee(e.audience)),e.accessibility&&(e.accessibility=Ee(e.accessibility)),e.motivation&&(e.motivation=Ee(e.motivation)),e}function Me(e,{typeHint:t,partOfTypeHint:i}={}){if("string"==typeof e&&(e={id:e,type:t||"unknown"}),Z(e))return"string"==typeof e.source&&(e.source={id:e.source,type:t||"unknown"}),"Canvas"===e.source.type&&e.source.partOf&&"string"==typeof e.source.partOf&&(e.source.partOf=[{id:e.source.partOf,type:i||"Manifest"}]),e;let r;if(-1!==(e.id||"").indexOf("#")){const[t,i]=(e.id||"").split("#");e.id=t,i&&(r={type:"FragmentSelector",value:i})}return{type:"SpecificResource",source:e,selector:r}}function Pe(e){const t=Object.assign({},e);return e&&e.items&&(t.items=e.items.map((e=>"string"==typeof e||"Canvas"===e.type?Me(e):e))),t}function Te(e){const t=Object.assign({},e);return t.start?(t.start=Me(t.start,{typeHint:"Canvas"}),t):e}function ze(e){const t=Object.assign({},e);return t.target?(t.target=Ce(t.target,{typeHint:"Canvas"}),t):e}function ke(e){return e}function $e(e){return void 0===e.items&&(e[re]=!0),e}function De(e){const t={};for(const[i,r]of e){if(i===se&&r!==ne)return r;r!==ne&&null!=r&&(t[i]=r)}return t}function We(e,{allowSourceString:t=!0,allowString:i=!1,allowedStringType:r}={}){const n=e=>{if(t&&e&&e.source&&"string"!=typeof e.source){const t=Object.keys(e.source);if(e.source.id&&e.source.type&&2===t.length)return{...e,source:e.source.id}}return e};if(e){if(e.source&&e.source.partOf)return n(e);const t=Object.keys(e);if(2===t.length&&e.type&&e.source||3===t.length&&e.type&&e.source&&-1!==t.indexOf("selector")&&!e.selector)return!i||r&&r!==e.source.type?"ContentResource"===e.source.type?{type:"SpecificResource",source:e.source.id}:e.source:e.source.id;if(e.selector&&!Array.isArray(e.selector)&&"string"!=typeof e.selector&&"FragmentSelector"===e.selector.type){const t=`${e.source.id}#${e.selector.value}`;return i?t:{id:t,type:e.source.type}}}return n(e)}function Ne(e){if(!e)return;const t=Object.keys(e);if(0!==t.length){if(1===t.length){const i=t[0];if(!i)return"";const r=(e[i]||[]).join("");return"@none"===i||"none"===i||"en"===i?r:{"@language":i,"@value":r}}return t.map((t=>({"@language":t,"@value":(e[t]||[]).join("")})))}}function qe(e){return Array.isArray(e)?e.map((e=>qe(e))):"string"==typeof e?e:e.type&&"Canvas"===e.type?e.id:e}function Be(e,t=!1){if(e)return e.length>1&&!t?e:e[0]||void 0}function Ue(e){if(e){if("string"==typeof e)return{"@id":e};if("@id"in e){const 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 He(e,t){return[["@id",e.id],["@type",t],["format",e.format],["height",e.height],["width",e.width],["viewingDirection","left-to-right"!==e.viewingDirection?e.viewingDirection:void 0],["license",e.license?e.license:void 0]]}function*Ge(e){const t=e.provider?yield e.provider[0]:void 0;return[["label",Ne(e.label)],["metadata",e.metadata&&e.metadata.length?e.metadata.map((e=>({label:Ne(e.label)||"",value:Ne(e.value)||""}))):void 0],["description",Ne(e.summary)],["thumbnail",Be(yield e.thumbnail)],["navDate",e.navDate],["logo",t?Be(t.logo):void 0],["homepage",t?t.homepage:void 0],["attribution",e.requiredStatement?Ne(e.requiredStatement.value):void 0]]}function*Qe(e){const t=e.start&&e.start.type&&"SpecificResource"===e.start.type?We(e.start):e.start;return[["seeAlso",Be(yield e.seeAlso)],["service",Be((e.service||[]).map(Ue))],["rendering",Be(yield e.rendering)],["startCanvas",t?t.id:void 0]]}function Ve(e){if(e&&function(e){return"SpecificResource"===e.type}(e)){let t=e.id;const i=e.selector?Array.isArray(e.selector)?e.selector[0]:e.selector:void 0;return function(e){return e&&"FragmentSelector"===e.type}(i)&&(t+="#"+i.value),t}return null==e?void 0:e.id}const Je={Manifest:function*(e,t,{isTopLevel:i}){return[...i?[["@context","http://iiif.io/api/presentation/2/context.json"]]:[],...He(e,"sc:Manifest"),...yield*Ge(e),...yield*Qe(e),["sequences",[{"@id":`${e.id}/sequence0`,"@type":"sc:Sequence",canvases:yield e.items}]],["structures",yield e.structures]]},Canvas:function*(e){const t=(yield e.items)[0];return[...He(e,"sc:Canvas"),...yield*Ge(e),...yield*Qe(e),["images",t?[t.resources]:void 0],["annotations",e.annotations&&e.annotations.length?Be(yield e.annotations):void 0]]},AnnotationPage:function*(e){return[...He(e,"sc:AnnotationList"),...yield*Ge(e),["resources",e.items&&e.items.length?Be(yield e.items):void 0]]},Annotation:function*(e){return[["@id",e.id],["@type","oa:Annotation"],["motivation","sc:painting"],["on",qe(e.target)],["resource",Be(yield e.body,!0)]]},ContentResource:function*(e){return"Image"===e.type?[...He(e,"dctypes:Image"),...yield*Ge(e),...yield*Qe(e)]:[...He(e,void 0),...yield*Ge(e)]},AnnotationCollection:function*(e){return[["@id",e.id],["@type","sc:Layer"],["label",Ne(e.label)]]},Collection:function*(e){return[...He(e,"sc:Collection"),...yield*Ge(e),...yield*Qe(e),["members",yield*e.items]]},Range:function*(e){const t=[],i=[];if(e.items)for(const r of e.items){const n="SpecificResource"===r.type?r.source:r;if(n){const s=yield n;t.push({"@id":Ve(r),"@type":n.type,label:s?s.label:void 0,within:e.id}),"Canvas"===n.type&&i.push(n.id)}}return[...He(e,"sc:Range"),...yield*Ge(e),...yield*Qe(e),["canvases",i.length===t.length?i:void 0],["members",i.length!==t.length?t:void 0]]}};function Xe(e){var t;return[["id",(null==(t=e.id)?void 0:t.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","left-to-right"!==e.viewingDirection?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],[te,ne]]}function Ye(e){if(e===ne)return;if(!e||0===e.length)return;const t=e.filter((e=>e!==ne));return 0!==t.length?t:void 0}function Ze(e){if(e&&e.type&&"ImageService2"===e.type){const{id:t,type:i,profile:r,...n}=e,s="string"==typeof r?r:Array.isArray(r)?r.find((e=>"string"==typeof e)):"";return{"@id":t,"@type":i,profile:s?s.startsWith("http")?s:`http://iiif.io/api/image/2/${s}.json`:"http://iiif.io/api/image/2/level0.json",...n}}return e}function Ke(e){if(Array.isArray(e)||(e=e?[e]:[]),e&&0!==e.length)return e.map(Ze)}function*et(e){return[["label",e.label],["metadata",Ye(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",Ye(yield e.thumbnail)],["placeholderCanvas",yield e.placeholderCanvas],["accompanyingCanvas",yield e.accompanyingCanvas],["provider",Ye(yield e.provider)]]}function*tt(e){return[["seeAlso",Ye(yield e.seeAlso)],["service",Ye(Ke(e.service))],["services",Ye(Ke(e.services))],["rendering",Ye(yield e.rendering)],["supplementary",Ye(yield e.supplementary)],["homepage",Ye(yield e.homepage)],["logo",Ye(yield e.logo)],["partOf",Ye(yield e.partOf)],["start",e.start?We(e.start):e.start]]}const it={Manifest:function*(e,t,{isTopLevel:i}){return i?[["@context",e["@context"]?e["@context"]:"http://iiif.io/api/presentation/3/context.json"],...Xe(e),...yield*et(e),...yield*tt(e),["items",yield e.items],["structures",Ye(yield e.structures)],["annotations",Ye(yield e.annotations)],["navPlace",e.navPlace]]:[...Xe(e),...yield*et(e)]},Canvas:function*(e){return[...Xe(e),...yield*et(e),...yield*tt(e),["items",yield e.items],["annotations",Ye(yield e.annotations)],["navPlace",e.navPlace]]},Agent:function*(e){return[["id",e.id],["type","Agent"],["label",e.label],...yield*tt(e)]},AnnotationPage:function*(e){var t;const i=Object.entries(e).map((([e,t])=>[e,Array.isArray(t)?Ye(t):t])).filter((([e,t])=>"items"!==e&&"id"!==e&&e!==te&&e!==ie&&e!==re)),r=yield e.items;return[["id",(null==(t=e.id)?void 0:t.startsWith("vault://"))?void 0:e.id],...i,...yield*tt(e),["items",r.length||!1===e[re]?r:ne]]},Service:function*(e){return[[se,Ze(e)]]},Annotation:function*(e){const t=Object.entries(e).map((([e,t])=>"motivation"===e?[e,Array.isArray(t)?t[0]:t]:"target"===e?[e,We(t,{allowString:!0,allowSourceString:!0,allowedStringType:"Canvas"})]:[e,Array.isArray(t)?Ye(t):t])).filter((([e])=>"body"!==e&&e!==te&&e!==re));let i;if(Array.isArray(e.body)){const t=[];for(const i of e.body)if(i&&Z(i)){const e={...i};e.source=yield i.source,t.push(We(e,{allowSourceString:!0}))}else t.push(yield i);i=t}else e.body&&Z(e.body)?(i={...e.body},i.source=yield e.body.source):i=yield e.body;return[...t,...yield*et(e),...yield*tt(e),["body",1===i.length?i[0]:i]]},ContentResource:function*(e){return function(e,t){const i=Object.keys(t),r=e.map((([e])=>e));for(const n of i)n!==te&&n!==re&&-1===r.indexOf(n)&&void 0!==t[n]&&e.push([n,t[n]]);return e}([...Xe(e),...yield*et(e),...yield*tt(e),["annotations",Ye(yield e.annotations)],["items",Ye(yield e.items)]],e)},AnnotationCollection:function*(e){return[["id",e.id],["type","AnnotationCollection"],["label",e.label]]},Collection:function*(e,t,{isTopLevel:i}){return i?[["@context","http://iiif.io/api/presentation/3/context.json"],...Xe(e),...yield*et(e),...yield*tt(e),["items",Ye(yield e.items)],["navPlace",e.navPlace]]:[...Xe(e),...yield*et(e)]},Range:function*(e){const t=[];for(const i of e.items)"Range"===i.type?t.push(yield i):i&&"SpecificResource"===i.type?t.push(We(i)):t.push(i);return[...Xe(e),...yield*et(e),...yield*tt(e),["items",t],["annotations",Ye(yield e.annotations)],["navPlace",e.navPlace]]}};const rt=Object.freeze(Object.defineProperty({__proto__:null,emptyAnnotation:ue,emptyAnnotationPage:pe,emptyCanvas:fe,emptyCollection:he,emptyManifest:ve,emptyRange:de,emptyAgent:ye,emptyService:me,defaultEntities:{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}},getDefaultEntities:Ie,merge:_e,mergeEntities:we,traverseSpecificResource:ke,addFlagForExternalResource:$e,normalize:function(e){const t=J(e),i={Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}},r={},n=function(e,t){return(i,r)=>{const n=e[i]?e[i]:{};return(e,s)=>{const a=Se(e,r||i);return a&&a.id&&i?(n[a.id]=n[a.id]?we(n[a.id],a,{parent:s.parent,isTopLevel:t.id===a.id}):we({id:a.id,type:a.type},a,{parent:s.parent,isTopLevel:t.id===a.id}),{id:a.id,type:"ContentResource"===i?i:a.type}):a}}}(i,t),s=function(e){return(t,i)=>r=>{const{id:n,type:s}=Se(r,i||t);if(void 0===n)throw new Error("Found invalid entity without an ID.");return e[n]="ContentResource"===t||"Service"===t?t:s,r}}(r);return{entities:i,resource:new be({collection:[$e,Le(he),s("Collection"),n("Collection")],manifest:[$e,Le(ve),Te,s("Manifest"),n("Manifest")],canvas:[Le(fe),s("Canvas"),n("Canvas")],annotationPage:[$e,Fe("AnnotationPage"),Le(pe),s("AnnotationPage"),n("AnnotationPage")],annotation:[Fe("Annotation"),je,ze,s("Annotation"),n("Annotation")],contentResource:[Fe("ContentResource"),s("ContentResource"),n("ContentResource")],range:[Le(de),Pe,s("Range","Canvas"),n("Range","Canvas")],agent:[Le(ye),s("Agent"),n("Agent")],specificResource:[ke],service:[Re(i)]}).traverseUnknown(t),mapping:r}},types:Ae,identifyResource:xe,Traverse:be,serializedFieldsToObject:De,serialize:function(e,t,i){if(!t.type||!t.id)throw new Error("Unknown entity");if(!i[t.type])throw new Error(`Serializer not found for ${t.type}`);return function r(n,s,a=0){const o=i[n.type];if(!o)return ne;if(a>20)throw new Error("Circular reference: "+n.id+" "+n.type);const[c,l]=le(e,n.type?n:n.id,s)||(n.id&&n.type?n:null);if(!c)return ne;const u=o(c,e,{parent:s,isTopLevel:t.id===n.id,fullResource:l});let p=u.next();for(;!p.done;){const e=p.value;let t=ne;if(e)if(Array.isArray(e)){const i=[];for(const t of e)i.push(r(t,n,a+1));t=i}else t=r(e,n,a+1);p=u.next(t)}return p.value===ne?ne:De(p.value)}(t)},languageString2to3:Ne,serializeConfigPresentation2:Je,serializeConfigPresentation3:it,WILDCARD:ee,HAS_PART:te,PART_OF:ie,IS_EXTERNAL:re,UNSET:ne,UNWRAP:se,EMPTY:ae,isWildcard:oe,frameResource:ce,resolveIfExists:le,toRef:K,compressSpecificResource:We,isSpecificResource:Z},Symbol.toStringTag,{value:"Module"}));function nt(e){try{if("full"===e)return{full:!0};if("square"===e)return{square:!0};const t=e.startsWith("pct:"),i=e.substr(t?4:0).split(",").map((e=>parseFloat(e)));return{x:i[0],y:i[1],w:i[2],h:i[3],percent:t}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+e)}}function st(e){const t={upscaled:!1,max:!1,confined:!1};if("^"===e[0]&&(t.upscaled=!0,e=e.slice(1)),"max"===e||"full"===e)return t.max=!0,t.serialiseAsFull="full"===e,t;if("!"===e[0]&&(t.confined=!0,e=e.slice(1)),"p"===e[0])return t.percentScale=parseFloat(e.slice(4)),t;const i=e.split(",").map((e=>e.trim()));return i.length&&(""!==i[0]&&(t.width=parseInt(i[0],10)),""!==i[1]&&(t.height=parseInt(i[1],10))),t}function at(e){const t={angle:0};if("!"===e[0]&&(t.mirror=!0,e=e.substr(1)),t.angle=parseFloat(e)%360,Number.isNaN(t.angle))throw new Error(`Invalid rotation ${e}`);return t}function ot(e,t=""){const i=e.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!i)throw new Error(`Invalid or unknown input ${e}`);const r=i[2],n=i[3];let s=i[4];if("/"===s[0]&&(s=s.substr(1)),t.length>0){if("/"===t[0]&&(t=t.substr(1)),t!==s.substr(0,t.length))throw new Error(`Path does not start with prefix (path: ${s}, prefix: ${t})`);s=s.substr(t.length)}return{scheme:r,server:n,path:s,prefix:t}}function ct(e,t=""){const{path:i,scheme:r,server:n,prefix:s}=ot(e,t),a=i.split("/").reverse(),[o,c,l,u,...p]=a,f=p.reverse().filter(Boolean).join("/");if(1===a.length||""===o)return{type:"base",scheme:r,server:n,prefix:s,identifier:f};if("info.json"===o){const[,...e]=a;return{type:"info",scheme:r,server:n,prefix:s,identifier:e.reverse().filter(Boolean).join("/")}}const h=o.split(".");return{type:"image",scheme:r,server:n,prefix:s,identifier:f,originalPath:i,region:nt(u),size:st(l),rotation:at(c),quality:h[0],format:h[1]}}const lt="http://library.stanford.edu/iiif/image-api/compliance.html#level0",ut="http://library.stanford.edu/iiif/image-api/compliance.html#level1",pt="http://library.stanford.edu/iiif/image-api/compliance.html#level2",ft="http://library.stanford.edu/iiif/image-api/conformance.html#level0",ht="http://library.stanford.edu/iiif/image-api/conformance.html#level1",vt="http://library.stanford.edu/iiif/image-api/conformance.html#level2",dt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",yt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",mt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",gt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",At="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",xt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",bt="http://iiif.io/api/image/1/level0.json",Ct="http://iiif.io/api/image/1/profiles/level0.json",It="http://iiif.io/api/image/1/level1.json",St="http://iiif.io/api/image/1/profiles/level1.json",_t="http://iiif.io/api/image/1/level2.json",wt="http://iiif.io/api/image/1/profiles/level2.json",Rt="http://iiif.io/api/image/2/level0.json",Ot="http://iiif.io/api/image/2/profiles/level0.json",Ft="http://iiif.io/api/image/2/level1.json",Lt="http://iiif.io/api/image/2/profiles/level1.json",Et="http://iiif.io/api/image/2/level2.json",jt="http://iiif.io/api/image/2/profiles/level2.json",Mt="level0",Pt="level1",Tt="level2",zt="http://iiif.io/api/image/2/level0",kt="http://iiif.io/api/image/2/level1",$t="http://iiif.io/api/image/2/level2",Dt=[$t,pt,vt,mt,xt,_t,wt,Et,jt,Tt],Wt=[...Dt,kt,ut,ht,yt,At,It,St,Ft,Lt,Pt],Nt=[zt,kt,$t,lt,ut,pt,ft,ht,vt,dt,yt,mt,gt,At,xt,bt,Ct,It,St,_t,wt,Rt,Ot,Ft,Lt,Et,jt,Mt,Pt,Tt],qt=Nt,Bt=[zt,lt,ft,dt,gt,bt,Ct,Rt,Ot,Mt],Ut={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},Ht={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},Gt={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]},Qt=["baseUriRedirect","canonicalLinkHeader","cors","jsonldMediaType","mirroring","profileLinkHeader","regionByPct","regionByPx","regionSquare","rotationArbitrary","rotationBy90s","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh","sizeUpscaling","sizeByWhListed","sizeByDistortedWh","sizeByForcedWh"];function Vt(e){if(-1!==Dt.indexOf(e))return Gt;return-1!==Wt.indexOf(e)?Ht:Ut}function Jt(e){const t=e?Array.isArray(e.profile)?e.profile:[e.profile]:[],i={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let r of t)if("string"==typeof r&&(r=Vt(r)),r){if(r.formats)for(const e of r.formats)-1===i.extraFormats.indexOf(e)&&i.extraFormats.push(e);if(r.qualities)for(const e of r.qualities)-1===i.extraQualities.indexOf(e)&&i.extraQualities.push(e);if(r.supports)for(const e of r.supports)-1===i.extraFeatures.indexOf(e)&&i.extraFeatures.push(e);if(r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea),r.extraFormats)for(const e of r.extraFormats)-1===i.extraFormats.indexOf(e)&&i.extraFormats.push(e);if(r.extraQualities)for(const e of r.extraQualities)-1===i.extraQualities.indexOf(e)&&i.extraQualities.push(e);if(r.extraFeatures)for(const e of r.extraFeatures)-1===i.extraFeatures.indexOf(e)&&i.extraFeatures.push(e);r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea)}if(e.extraFormats)for(const r of e.extraFormats)-1===i.extraFormats.indexOf(r)&&i.extraFormats.push(r);if(e.extraFeatures)for(const r of e.extraFeatures)-1===i.extraFeatures.indexOf(r)&&i.extraFeatures.push(r);if(e.extraQualities)for(const r of e.extraQualities)-1===i.extraQualities.indexOf(r)&&i.extraQualities.push(r);return i}function Xt(e){return e["@id"]?e["@id"]:e.id?e.id:void 0}function Yt(e){if(!e||!e.profile)return!1;if(!Xt(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if("string"==typeof i&&-1!==Nt.indexOf(i))return!0;return!1}function Zt(e,t){if(!Yt(e))return[!1,"Not a valid image service"];t.extraFeatures=t.extraFeatures?t.extraFeatures:[];const i=Jt(e);if(t.exactSize){let i=!1;if(e.sizes)for(const r of e.sizes)r.width&&r.width===t.exactSize.width&&(-1!==Qt.indexOf("sizeByW")||r.height&&r.height===t.exactSize.height)&&(i=!0),r.height&&r.height===t.exactSize.height&&(-1!==Qt.indexOf("sizeByH")||r.width&&r.width===t.exactSize.width)&&(i=!0);i||(t.maxWidth=Math.max(t.maxWidth||0,t.exactSize.width||0)||void 0,t.maxHeight=Math.max(t.maxHeight||0,t.exactSize.height||0)||void 0,t.maxArea=Math.max(t.maxArea||0,(t.exactSize.width&&t.exactSize.height?t.exactSize.width*t.exactSize.height:t.maxArea)||0)||void 0,!t.exactSize.height&&t.exactSize.width?-1===t.extraFeatures.indexOf("sizeByW")&&t.extraFeatures.push("sizeByW"):!t.exactSize.width&&t.exactSize.height&&-1===t.extraFeatures.indexOf("sizeByH")&&t.extraFeatures.push("sizeByH"))}if(t.maxArea&&i.maxArea&&t.maxArea>i.maxArea)return[!1,`Max area is ${i.maxArea}`];if(t.maxWidth&&i.maxWidth&&t.maxWidth>i.maxWidth)return[!1,`Max width is ${i.maxWidth}`];if(t.maxHeight&&i.maxHeight&&t.maxHeight>i.maxHeight)return[!1,`Max height is ${i.maxHeight}`];if(t.extraFeatures){const e=[];for(const r of t.extraFeatures)-1===i.extraFeatures.indexOf(r)&&e.push(r);if(e.length)return[!1,`Missing features: ${e.join(", ")}`]}if(t.extraFormats){const e=[];for(const r of t.extraFormats)-1===i.extraFormats.indexOf(r)&&e.push(r);if(e.length)return[!1,`Missing formats: ${e.join(", ")}`]}if(t.extraQualities){const e=[];for(const r of t.extraQualities)-1===i.extraQualities.indexOf(r)&&e.push(r);if(e.length)return[!1,`Missing qualities: ${e.join(", ")}`]}return[!0]}function Kt({x:e=0,y:t=0,w:i,h:r,full:n,square:s,percent:a}){if(n)return"full";if(s)return"square";if(void 0===i||void 0===r)throw new Error("RegionParameter: invalid region");const o=`${e},${t},${i},${r}`;return a?`pct:${o}`:o}function ei({max:e,percentScale:t,upscaled:i,confined:r,width:n,height:s,serialiseAsFull:a}){const o=[];return i&&o.push("^"),e?(o.push(a?"full":"max"),o.join("")):(r&&o.push("!"),t&&o.push(`pct:${t}`),n&&o.push(`${n}`),o.push(","),s&&o.push(`${s}`),o.join(""))}function ti(e){return`${e.mirror?"!":""}${(e.angle||0)%360}`}function ii(e){return e.endsWith("info.json")?e:e.endsWith("/")?`${e}info.json`:`${e}/info.json`}return{Presentation2:Y,Presentation3:rt,Image3:Object.freeze(Object.defineProperty({__proto__:null,parseImageServerFromId:function(e){const t=e.replace(/(https?:\/\/)?(www.)?/i,"");return-1!==t.indexOf("/")?t.split("/")[0]:t},parseImageServiceRequest:ct,parseImageServiceUrl:ot,parseRegionParameter:nt,parseRotationParameter:at,parseSizeParameter:st,STANFORD_IIIF_IMAGE_COMPLIANCE_0:lt,STANFORD_IIIF_IMAGE_COMPLIANCE_1:ut,STANFORD_IIIF_IMAGE_COMPLIANCE_2:pt,STANFORD_IIIF_IMAGE_CONFORMANCE_0:ft,STANFORD_IIIF_IMAGE_CONFORMANCE_1:ht,STANFORD_IIIF_IMAGE_CONFORMANCE_2:vt,STANFORD_IIIF_1_IMAGE_COMPLIANCE_0:dt,STANFORD_IIIF_1_IMAGE_COMPLIANCE_1:yt,STANFORD_IIIF_1_IMAGE_COMPLIANCE_2:mt,STANFORD_IIIF_1_IMAGE_CONFORMANCE_0:gt,STANFORD_IIIF_1_IMAGE_CONFORMANCE_1:At,STANFORD_IIIF_1_IMAGE_CONFORMANCE_2:xt,IIIF_1_IMAGE_LEVEL_0:bt,IIIF_1_IMAGE_LEVEL_0_PROFILE:Ct,IIIF_1_IMAGE_LEVEL_1:It,IIIF_1_IMAGE_LEVEL_1_PROFILE:St,IIIF_1_IMAGE_LEVEL_2:_t,IIIF_1_IMAGE_LEVEL_2_PROFILE:wt,IIIF_2_IMAGE_LEVEL_0:Rt,IIIF_2_IMAGE_LEVEL_0_PROFILE:Ot,IIIF_2_IMAGE_LEVEL_1:Ft,IIIF_2_IMAGE_LEVEL_1_PROFILE:Lt,IIIF_2_IMAGE_LEVEL_2:Et,IIIF_2_IMAGE_LEVEL_2_PROFILE:jt,IIIF_3_IMAGE_LEVEL_0:Mt,IIIF_3_IMAGE_LEVEL_1:Pt,IIIF_3_IMAGE_LEVEL_2:Tt,IIIF_2_IMAGE_LEVEL_0_NO_JSON:zt,IIIF_2_IMAGE_LEVEL_1_NO_JSON:kt,IIIF_2_IMAGE_LEVEL_2_NO_JSON:$t,level2Support:Dt,level1Support:Wt,imageServiceProfiles:Nt,level0Support:qt,onlyLevel0:Bt,level0:Ut,level1:Ht,level2:Gt,extraFeatures:Qt,combineProfiles:Jt,levelToProfile:Vt,isLevel0:function(e){const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if("string"==typeof i&&-1!==Bt.indexOf(i))return!0;return!1},supports:Zt,supportsCustomSizes:function(e){if(!Yt(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if("string"==typeof i){if(-1!==Wt.indexOf(i))return!0}else{const e=[...i.supports||[],...i.extraFeatures||[]];if(-1!==e.indexOf("regionByPx")&&(-1!==e.indexOf("sizeByW")||-1!==e.indexOf("sizeByWh")))return!0}return!1},imageServiceSupportsFormat:function(e,t){return Zt(e,{extraFormats:[t]})},imageServiceSupportsRequest:function(e,t){if("image"!==t.type)return[!0];const i=[];if(t.rotation.mirror&&i.push("mirroring"),t.region.percent&&i.push("regionByPct"),t.region.square?i.push("regionSquare"):t.region.full||i.push("regionByPx"),t.rotation.angle){t.rotation.angle%90?i.push("rotationArbitrary"):i.push("rotationBy90s")}t.size.confined&&i.push("sizeByConfinedWh"),!t.size.width&&t.size.height&&i.push("sizeByH"),t.size.percentScale&&i.push("sizeByPct"),(e.sizes||[]).find((e=>e.width===t.size.width&&!t.size.height||e.height===t.size.height&&!t.size.width||e.height===t.size.height&&e.width===t.size.width))?i.push("sizeByWhListed"):(t.size.width&&!t.size.height&&i.push("sizeByW"),t.size.width&&t.size.height&&i.push("sizeByWh")),t.size.upscaled&&i.push("sizeUpscaling");const[r,n]=Zt(e,{extraFeatures:i,extraQualities:[t.quality],extraFormats:[t.format],exactSize:t.size});return r?[!0]:[!1,n]},imageServiceRequestToString:function(e,t){const i=e.prefix.startsWith("/")?e.prefix.substr(1):e.prefix,r=`${e.scheme}://${e.server}/${i?`${i}/`:""}${e.identifier}`;if("base"===e.type)return r;if("info"===e.type)return`${r}/info.json`;let{size:n}=e;const{region:s,rotation:a,format:o,quality:c}=e;if(t){const e=t["@context"]?Array.isArray(t["@context"])?t["@context"]:[t["@context"]]:[],i=-1!==e.indexOf("http://iiif.io/api/image/2/context.json"),r=-1!==e.indexOf("http://iiif.io/api/image/3/context.json");if((n.width===t.width&&!n.height||n.height===t.height&&!n.width||n.width===t.width&&n.height===t.height)&&(n={...n,max:!0}),i&&(n.max&&!n.serialiseAsFull&&(n={...n,serialiseAsFull:!0}),!n.max&&n.width&&n.height&&(n={...n,height:void 0})),r&&(n.max&&n.serialiseAsFull&&(n={...n,serialiseAsFull:!1}),n.width&&!n.height&&t.width&&t.height)){const e=t.height/t.width;n={...n,height:Math.ceil(n.width*e)}}}return[r,Kt(s),ei(n),ti(a),`${c}.${o}`].filter(Boolean).join("/")},regionParameterToString:Kt,rotationParameterToString:ti,sizeParameterToString:ei,canonicalServiceUrl:ii,createImageServiceRequest:function(e){const t=ct(ii(e.id));if("info"!==t.type)throw new Error("Invalid service URL");const i=Jt(e);return{identifier:t.identifier,originalPath:"",server:t.server,prefix:t.prefix,scheme:t.scheme,type:"image",quality:-1===i.extraQualities.indexOf("default")?i.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}},extractFixedSizeScales:function(e,t,i){const r=i.length,n=[];for(let s=0;s<r;s++){const t=i[s].width;n.push(e/t)}return n},fixedSizesFromScales:function(e,t,i){const r=i.length,n=[];for(let s=0;s<r;s++){const r=i[s];n.push({width:Math.floor(e/r),height:Math.floor(t/r)})}return n},getId:Xt,getType:function(e){return e["@type"]?e["@type"]:e.type?e.type:void 0},isImageService:Yt},Symbol.toStringTag,{value:"Module"}))}})); | ||
| //# sourceMappingURL=index.umd.js.map |
@@ -1,2 +0,2 @@ | ||
| "use strict";var e=Object.defineProperty,t=(t,i,r)=>(((t,i,r)=>{i in t?e(t,i,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[i]=r})(t,"symbol"!=typeof i?i+"":i,r),r);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function r(e){if(null==e)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("object"!=typeof e)throw new Error(typeof e+" is not a valid entity");if("string"==typeof e["@type"]){const t=i.indexOf(e["@type"]);if(-1!==t)return i[t]}if(e.profile)return"Service";if(e.format)return"ContentResource";if(e["@type"])return"ContentResource";throw new Error("Resource type is not known")}class n{constructor(e,i={}){t(this,"traversals"),t(this,"options"),this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...i}}static all(e){return new n({collection:[e],manifest:[e],canvas:[e],annotationList:[e],sequence:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],layer:[e]})}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))),this.traversals.collection)}traverseCollectionItems(e){if(this.options.mergeMemberProperties){const t=[...(e.manifests||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Manifest"}:e)),...(e.collections||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Collection"}:e)),...e.members||[]];delete e.collections,delete e.manifests,e.members=t}return e.manifests&&(e.manifests=e.manifests.map((e=>this.traverseManifest("string"==typeof e?{"@id":e,"@type":"sc:Manifest"}:e)))),e.collections&&(e.collections=e.collections.map((e=>this.traverseCollection("string"==typeof e?{"@id":e,"@type":"sc:Collection"}:e)))),e.members&&(e.members=e.members.map((e=>"string"==typeof e?e:this.traverseUnknown(e)))),e}traverseManifest(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))),this.traversals.manifest)}traverseManifestItems(e){return e.sequences&&(e.sequences=e.sequences.map((e=>this.traverseSequence(e)))),e.structures&&(e.structures=e.structures.map((e=>this.traverseRange(e)))),e}traverseSequence(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))),this.traversals.sequence)}traverseSequenceItems(e){return e.canvases&&(e.canvases=e.canvases.map((e=>this.traverseCanvas(e)))),e}traverseCanvas(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))),this.traversals.canvas)}traverseCanvasItems(e){return e.images&&(e.images=e.images.map((e=>this.traverseAnnotation(e)))),e.otherContent&&(e.otherContent=e.otherContent.map((e=>this.traverseAnnotationList(e)))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const t=[...(e.ranges||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Range"}:e)),...(e.canvases||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Canvas"}:e)),...e.members||[]];delete e.ranges,delete e.canvases,e.members=t.length?t.map((e=>this.traverseUnknown(e))):void 0}return e}traverseAnnotationList(e){const t="string"==typeof e?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(t)),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map((e=>this.traverseAnnotation(e)))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(Array.isArray(e.resource)?e.resource=e.resource.map((e=>this.traverseContentResource(e))):e.resource=this.traverseContentResource(e.resource)),e.on,e}traverseLayer(e){return this.traverseType(this.traverseLinking(this.traverseLayerItems(e)),this.traversals.layer)}traverseLayerItems(e){return e.otherContent&&(e.otherContent=e.otherContent.map((e=>this.traverseAnnotationList(e)))),e}traverseChoice(e){return this.traverseType(this.traverseChoiceItems(e),this.traversals.choice)}traverseChoiceItems(e){return e.default&&"rdf:nil"!==e.default&&(e.default=this.traverseContentResource(e.default)),e.item&&"rdf:nil"!==e.item&&(e.item=e.item.map((e=>this.traverseContentResource(e)))),e}traverseService(e){return this.traverseType(this.traverseLinking(e),this.traversals.service)}traverseContentResource(e){return"oa:Choice"===e["@type"]?this.traverseChoice(e):this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.contentResource)}traverseUnknown(e){if(!e["@type"]||"string"==typeof e)return e;switch(r(e)){case"sc:Collection":return this.traverseCollection(e);case"sc:Manifest":return this.traverseManifest(e);case"sc:Canvas":return this.traverseCanvas(e);case"sc:Sequence":return this.traverseSequence(e);case"sc:Range":return this.traverseRange(e);case"oa:Annotation":return this.traverseAnnotation(e);case"sc:AnnotationList":return this.traverseAnnotationList(e);case"sc:Layer":return this.traverseLayer(e);case"Service":return this.traverseService(e);case"oa:Choice":return this.traverseChoice(e);case"ContentResource":return this.traverseContentResource(e)}return e.profile?this.traverseService(e):e}traverseImageResource(e){const t=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(const n of i)"string"==typeof n?r.push(this.traverseContentResource({"@id":n,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(n));return t||this.options.convertPropsToArray?r:r[0]}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){const t=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(const n of i)r.push(this.traverseService(n));return t||this.options.convertPropsToArray?r:r[0]}traverseLinking(e){return e.related&&(e.related=this.traverseOneOrManyType(e.related,this.traversals.contentResource)),e.rendering&&(e.rendering=this.traverseOneOrManyType(e.rendering,this.traversals.contentResource)),e.service&&(e.service=this.traverseOneOrMoreServices(e.service)),e.seeAlso&&(e.seeAlso=this.traverseOneOrManyType(e.seeAlso,this.traversals.contentResource)),e.within&&("string"==typeof e.within||(e.within=this.traverseOneOrManyType(e.within,this.traversals.contentResource))),e.startCanvas&&("string"==typeof e.startCanvas?e.startCanvas=this.traverseType({"@id":e.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):e.startCanvas&&this.traverseType(e.startCanvas,this.traversals.canvas)),e.contentLayer&&("string"==typeof e.contentLayer?e.contentLayer=this.traverseLayer({"@id":e.contentLayer,"@type":"sc:Layer"}):e.contentLayer=this.traverseLayer(e.contentLayer)),e}traverseOneOrManyType(e,t){if(!Array.isArray(e)){if(!this.options.convertPropsToArray)return this.traverseType(e,t);e=[e]}return e.map((e=>this.traverseType(e,t)))}traverseType(e,t){return t.reduce(((e,t)=>{const i=t(e);return void 0!==i||this.options.allowUndefinedReturn?i:e}),e)}}const a=["http://iiif.io/api/image/2/level1","http://iiif.io/api/image/2/level2","http://library.stanford.edu/iiif/image-api/compliance.html#level1","http://library.stanford.edu/iiif/image-api/compliance.html#level2","http://library.stanford.edu/iiif/image-api/conformance.html#level1","http://library.stanford.edu/iiif/image-api/conformance.html#level2","http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1","http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2","http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1","http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2","http://iiif.io/api/image/1/level1.json","http://iiif.io/api/image/1/profiles/level1.json","http://iiif.io/api/image/1/level2.json","http://iiif.io/api/image/1/profiles/level2.json","http://iiif.io/api/image/2/level1.json","http://iiif.io/api/image/2/profiles/level1.json","http://iiif.io/api/image/2/level2.json","http://iiif.io/api/image/2/profiles/level2.json","level1","level2"],s=["http://iiif.io/api/image/2/level0","http://iiif.io/api/image/2/level1","http://iiif.io/api/image/2/level2","http://library.stanford.edu/iiif/image-api/compliance.html#level0","http://library.stanford.edu/iiif/image-api/compliance.html#level1","http://library.stanford.edu/iiif/image-api/compliance.html#level2","http://library.stanford.edu/iiif/image-api/conformance.html#level0","http://library.stanford.edu/iiif/image-api/conformance.html#level1","http://library.stanford.edu/iiif/image-api/conformance.html#level2","http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0","http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1","http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2","http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0","http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1","http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2","http://iiif.io/api/image/1/level0.json","http://iiif.io/api/image/1/profiles/level0.json","http://iiif.io/api/image/1/level1.json","http://iiif.io/api/image/1/profiles/level1.json","http://iiif.io/api/image/1/level2.json","http://iiif.io/api/image/1/profiles/level2.json","http://iiif.io/api/image/2/level0.json","http://iiif.io/api/image/2/profiles/level0.json","http://iiif.io/api/image/2/level1.json","http://iiif.io/api/image/2/profiles/level1.json","http://iiif.io/api/image/2/level2.json","http://iiif.io/api/image/2/profiles/level2.json","level0","level1","level2"];function o(e){for(const t in e)void 0!==e[t]&&null!==e[t]||delete e[t];return e}const c="Attribution",l="http://example.org/provider",p="Unknown";function h(e,t="none"){if(!e)return{};const i=Array.isArray(e)?e:[e],r={};for(const n of i){if("string"==typeof n){r[t]=r[t]?r[t]:[],r[t].push(n||"");continue}if(!n["@language"]){r[t]=r[t]?r[t]:[],r[t].push(n["@value"]||"");continue}const e=n["@language"];r[e]=r[e]?r[e]:[],r[e].push(n["@value"]||"")}return r}function v(e){return Array.isArray(e)?v(e.find((e=>"string"==typeof e))):-1!==s.indexOf(e)?"level2":-1!==a.indexOf(e)?"level1":"string"==typeof e?e:void 0}function u(e){const t=Array.isArray(e)?e:[e];for(const i of t)switch(i){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function f(e){for(const t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}const m=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function g(e){const t=e["@id"]||e.id;let i=e["@type"]||e.type;const r=e.profile||void 0,n=e["@context"]||void 0;if(r){const e=function(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"}}(r);if(e)return e}if(n){const e=u(n);if(e)return e}if(i){if(Array.isArray(i)){if(-1!==i.indexOf("oa:CssStylesheet"))return"CssStylesheet";if(-1!==i.indexOf("cnt:ContentAsText"))return"TextualBody";i=i[0]}for(const e of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${e}:`)){i=i.slice(e.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(i&&-1!==m.indexOf(i))return i;if(e.format){if(e.format.startsWith("image/"))return"Image";if(e.format.startsWith("text/"))return"Text";if("application/pdf"===e.format)return"Text";if(e.format.startsWith("application/"))return"Dataset"}return t&&(t.endsWith(".jpg")||t.endsWith(".png")||t.endsWith(".jpeg"))?"Image":i||"unknown"}const y=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function d(e){const t=e.match(y);return t?t[0]:e}const A=["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 C(e){if(e){const t=Array.isArray(e)?e:[e],i=[];for(const e of t)"http://iiif.io/api/presentation/2/context.json"===e&&i.push("http://iiif.io/api/presentation/3/context.json"),-1===A.indexOf(e)&&i.push(e);if(t.length)return 1===i.length?i[0]:i}}let b=0;function x(e,t){const i=encodeURI(e.id||e["@id"]||"").trim();return i&&t?`${i}/${t}`:i||(b++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${b}`)}function w(e){const t=[...e.behavior||[]];let i;return e.viewingHint&&t.push(e.viewingHint),Array.isArray(e.motivation)?i=e.motivation.map(f):e.motivation&&(i=f(e.motivation)),{"@context":e["@context"]?C(e["@context"]):void 0,id:(e["@id"]||x(e)).trim(),type:g(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:i,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function j(e){const[t,i]=function(e,t="Rights/License",i="none"){let r=null;const n=[],a=Array.isArray(e)?e:[e];for(const s of a){const e=s?d(s):void 0;!e||-1===e.indexOf("creativecommons.org")&&-1===e.indexOf("rightsstatements.org")?e&&n.push({label:{[i]:[t]},value:{[i]:[e]}}):r=e.startsWith("https://")?`http://${e.slice(8)}`:e}return[r,n]}(e.license),r=[...e.metadata?(n=e.metadata,n?n.map((e=>({label:h(e.label),value:h(e.value)}))):[]):[],...i];var n;return{rights:t,metadata:r.length?r:void 0,label:e.label?h(e.label):void 0,requiredStatement:e.attribution?{label:h(c),value:h(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?h(e.description):void 0,thumbnail:L(e.thumbnail)}}function L(e){if(e){return(Array.isArray(e)?e:[e]).map((e=>"string"==typeof e?{id:e,type:"Image"}:("unknown"===e.type&&(e.type="Image"),e)))}return e}function S(e){if(!e.within)return;const t=Array.isArray(e.within)?e.within:[e.within],i=[];for(const r of t)if("string"==typeof r){if(r&&"sc:Manifest"===e["@type"])i.push({id:r,type:"Collection"})}else r["@id"]&&i.push({id:r["@id"],type:g(r)});return i.length?i:void 0}function R(e){const t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],i=e.contentLayer;return{provider:e.logo||t.length?[{id:l,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:h(p)}]:void 0,partOf:S(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?(r=e.service,Array.isArray(r)?r:r?[r]:[]):void 0,supplementary:i?[i]:void 0};var r}function I(e){const t=e;return o({...w(t),...j(t),...R(t),...(i=t,{chars:i.chars,format:i.format?i.format:void 0,language:i.language})});var i}const T=new n({collection:[function(e){return o({...w(e),...j(e),...R(e),items:e.members})}],manifest:[function(e){const t=[],i=[];let r;for(const a of e.sequences||[])a.canvases.length&&t.push(...a.canvases),a.behavior&&i.push(...a.behavior),a.startCanvas&&(r=a.startCanvas);const n=w(e);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),o({...n,...j(e),...R(e),start:r,items:t,structures:e.structures})}],canvas:[function(e){return o({...w(e),...j(e),...R(e),annotations:e.otherContent&&e.otherContent.length?e.otherContent:void 0,items:e.images&&e.images.length?[{id:x(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}],annotationList:[function(e){return o({...w(e),...j(e),...R(e),items:e.resources&&e.resources.length?e.resources:void 0})}],sequence:[function(e){return e.canvases&&0!==e.canvases.length?{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}:{canvases:[],behavior:[]}}],annotation:[function(e){return o({...w(e),...j(e),...R(e),target:function e(t){if(Array.isArray(t)){if(t.length>1)return{type:"List",items:t.map(e)};t=t[0]}if("string"==typeof t)return encodeURI(t).trim();if("@type"in t){let e;if("string"==typeof t.full)e=t.full;else if("dctypes:Image"===t.full["@type"])e={id:t.full["@id"],type:"Image"};else{if("sc:Canvas"!==t.full["@type"])throw new Error(`Unsupported source type on annotation: ${t.full["@type"]}`);e={id:t.full["@id"],type:"Canvas"}}return{type:"SpecificResource",source:e,selector:k(t.selector)}}return encodeURI(t["@id"]).trim()}(e.on),body:Array.isArray(e.resource)?e.resource.map(I):I(e.resource)})}],contentResource:[I],choice:[function(e){const t=[];return e.default&&"rdf:nil"!==e.default&&t.push(e.default),e.item&&"rdf:nil"!==e.item&&t.push(...e.item),{...w(e),...j(e),items:t}}],range:[function(e){return o({...w(e),...j(e),...R(e),items:e.members})}],service:[function(e){const{"@id":t,"@type":i,"@context":r,profile:n,...a}=e,s={};return t&&(s["@id"]=t),s["@type"]=g(e),"unknown"===s["@type"]&&(r&&r.length&&(s["@context"]=r),s["@type"]="Service"),n&&(s.profile=v(n)),o({...s,...a})}],layer:[function(e){return o({...w(e),...j(e),...R(e)})}]});function k(e){if((Array.isArray(e["@type"])&&e["@type"].includes("oa:SvgSelector")||"oa:SvgSelector"==e["@type"])&&("chars"in e||"value"in e))return{type:"SvgSelector",value:"chars"in e?e.chars:e.value};if("oa:FragmentSelector"===e["@type"])return{type:"FragmentSelector",value:e.value};if("oa:Choice"===e["@type"])return[k(e.default),...(Array.isArray(e.item)?e.item:[e.item]).map(k)];if("iiif:ImageApiSelector"==e["@type"])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"]}`)}exports.Traverse=n,exports.convertLanguageMapping=h,exports.convertPresentation2=function(e){return e&&e["@context"]&&("http://iiif.io/api/presentation/2/context.json"===e["@context"]||-1!==e["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")||"http://www.shared-canvas.org/ns/context.json"===e["@context"])||"http://iiif.io/api/image/2/context.json"===e["@context"]?T.traverseUnknown(e):e},exports.getProfile=v,exports.getTypeFromContext=u,exports.identifyResource=r,exports.presentation2to3=T,exports.types=i; | ||
| "use strict";var e=Object.defineProperty,t=(t,i,r)=>(((t,i,r)=>{i in t?e(t,i,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[i]=r})(t,"symbol"!=typeof i?i+"":i,r),r);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function r(e){if(null==e)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("object"!=typeof e)throw new Error(typeof e+" is not a valid entity");if("string"==typeof e["@type"]){const t=i.indexOf(e["@type"]);if(-1!==t)return i[t]}if(e.profile)return"Service";if(e.format)return"ContentResource";if(e["@type"])return"ContentResource";throw new Error("Resource type is not known")}class n{constructor(e,i={}){t(this,"traversals"),t(this,"options"),this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...i}}static all(e){return new n({collection:[e],manifest:[e],canvas:[e],annotationList:[e],sequence:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],layer:[e]})}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))),this.traversals.collection)}traverseCollectionItems(e){if(this.options.mergeMemberProperties){const t=[...(e.manifests||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Manifest"}:e)),...(e.collections||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Collection"}:e)),...e.members||[]];delete e.collections,delete e.manifests,e.members=t}return e.manifests&&(e.manifests=e.manifests.map((e=>this.traverseManifest("string"==typeof e?{"@id":e,"@type":"sc:Manifest"}:e)))),e.collections&&(e.collections=e.collections.map((e=>this.traverseCollection("string"==typeof e?{"@id":e,"@type":"sc:Collection"}:e)))),e.members&&(e.members=e.members.map((e=>"string"==typeof e?e:this.traverseUnknown(e)))),e}traverseManifest(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))),this.traversals.manifest)}traverseManifestItems(e){return e.sequences&&(e.sequences=e.sequences.map((e=>this.traverseSequence(e)))),e.structures&&(e.structures=e.structures.map((e=>this.traverseRange(e)))),e}traverseSequence(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))),this.traversals.sequence)}traverseSequenceItems(e){return e.canvases&&(e.canvases=e.canvases.map((e=>this.traverseCanvas(e)))),e}traverseCanvas(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))),this.traversals.canvas)}traverseCanvasItems(e){return e.images&&(e.images=e.images.map((e=>this.traverseAnnotation(e)))),e.otherContent&&(e.otherContent=e.otherContent.map((e=>this.traverseAnnotationList(e)))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const t=[...(e.ranges||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Range"}:e)),...(e.canvases||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Canvas"}:e)),...e.members||[]];delete e.ranges,delete e.canvases,e.members=t.length?t.map((e=>this.traverseUnknown(e))):void 0}return e}traverseAnnotationList(e){const t="string"==typeof e?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(t)),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map((e=>this.traverseAnnotation(e)))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(Array.isArray(e.resource)?e.resource=e.resource.map((e=>this.traverseContentResource(e))):e.resource=this.traverseContentResource(e.resource)),e.on,e}traverseLayer(e){return this.traverseType(this.traverseLinking(this.traverseLayerItems(e)),this.traversals.layer)}traverseLayerItems(e){return e.otherContent&&(e.otherContent=e.otherContent.map((e=>this.traverseAnnotationList(e)))),e}traverseChoice(e){return this.traverseType(this.traverseChoiceItems(e),this.traversals.choice)}traverseChoiceItems(e){return e.default&&"rdf:nil"!==e.default&&(e.default=this.traverseContentResource(e.default)),e.item&&"rdf:nil"!==e.item&&(e.item=e.item.map((e=>this.traverseContentResource(e)))),e}traverseService(e){return this.traverseType(this.traverseLinking(e),this.traversals.service)}traverseContentResource(e){return"oa:Choice"===e["@type"]?this.traverseChoice(e):this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.contentResource)}traverseUnknown(e){if(!e["@type"]||"string"==typeof e)return e;switch(r(e)){case"sc:Collection":return this.traverseCollection(e);case"sc:Manifest":return this.traverseManifest(e);case"sc:Canvas":return this.traverseCanvas(e);case"sc:Sequence":return this.traverseSequence(e);case"sc:Range":return this.traverseRange(e);case"oa:Annotation":return this.traverseAnnotation(e);case"sc:AnnotationList":return this.traverseAnnotationList(e);case"sc:Layer":return this.traverseLayer(e);case"Service":return this.traverseService(e);case"oa:Choice":return this.traverseChoice(e);case"ContentResource":return this.traverseContentResource(e)}return e.profile?this.traverseService(e):e}traverseImageResource(e){const t=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(const n of i)"string"==typeof n?r.push(this.traverseContentResource({"@id":n,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(n));return t||this.options.convertPropsToArray?r:r[0]}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){const t=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(const n of i)r.push(this.traverseService(n));return t||this.options.convertPropsToArray?r:r[0]}traverseLinking(e){return e.related&&(e.related=this.traverseOneOrManyType(e.related,this.traversals.contentResource)),e.rendering&&(e.rendering=this.traverseOneOrManyType(e.rendering,this.traversals.contentResource)),e.service&&(e.service=this.traverseOneOrMoreServices(e.service)),e.seeAlso&&(e.seeAlso=this.traverseOneOrManyType(e.seeAlso,this.traversals.contentResource)),e.within&&("string"==typeof e.within||(e.within=this.traverseOneOrManyType(e.within,this.traversals.contentResource))),e.startCanvas&&("string"==typeof e.startCanvas?e.startCanvas=this.traverseType({"@id":e.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):e.startCanvas&&this.traverseType(e.startCanvas,this.traversals.canvas)),e.contentLayer&&("string"==typeof e.contentLayer?e.contentLayer=this.traverseLayer({"@id":e.contentLayer,"@type":"sc:Layer"}):e.contentLayer=this.traverseLayer(e.contentLayer)),e}traverseOneOrManyType(e,t){if(!Array.isArray(e)){if(!this.options.convertPropsToArray)return this.traverseType(e,t);e=[e]}return e.map((e=>this.traverseType(e,t)))}traverseType(e,t){return t.reduce(((e,t)=>{const i=t(e);return void 0!==i||this.options.allowUndefinedReturn?i:e}),e)}}const a=["http://iiif.io/api/image/2/level1","http://iiif.io/api/image/2/level2","http://library.stanford.edu/iiif/image-api/compliance.html#level1","http://library.stanford.edu/iiif/image-api/compliance.html#level2","http://library.stanford.edu/iiif/image-api/conformance.html#level1","http://library.stanford.edu/iiif/image-api/conformance.html#level2","http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1","http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2","http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1","http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2","http://iiif.io/api/image/1/level1.json","http://iiif.io/api/image/1/profiles/level1.json","http://iiif.io/api/image/1/level2.json","http://iiif.io/api/image/1/profiles/level2.json","http://iiif.io/api/image/2/level1.json","http://iiif.io/api/image/2/profiles/level1.json","http://iiif.io/api/image/2/level2.json","http://iiif.io/api/image/2/profiles/level2.json","level1","level2"],s=["http://iiif.io/api/image/2/level0","http://iiif.io/api/image/2/level1","http://iiif.io/api/image/2/level2","http://library.stanford.edu/iiif/image-api/compliance.html#level0","http://library.stanford.edu/iiif/image-api/compliance.html#level1","http://library.stanford.edu/iiif/image-api/compliance.html#level2","http://library.stanford.edu/iiif/image-api/conformance.html#level0","http://library.stanford.edu/iiif/image-api/conformance.html#level1","http://library.stanford.edu/iiif/image-api/conformance.html#level2","http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0","http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1","http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2","http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0","http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1","http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2","http://iiif.io/api/image/1/level0.json","http://iiif.io/api/image/1/profiles/level0.json","http://iiif.io/api/image/1/level1.json","http://iiif.io/api/image/1/profiles/level1.json","http://iiif.io/api/image/1/level2.json","http://iiif.io/api/image/1/profiles/level2.json","http://iiif.io/api/image/2/level0.json","http://iiif.io/api/image/2/profiles/level0.json","http://iiif.io/api/image/2/level1.json","http://iiif.io/api/image/2/profiles/level1.json","http://iiif.io/api/image/2/level2.json","http://iiif.io/api/image/2/profiles/level2.json","level0","level1","level2"];function o(e){for(const t in e)void 0!==e[t]&&null!==e[t]||delete e[t];return e}const c="Attribution",l="http://example.org/provider",p="Unknown";function h(e,t="none"){if(!e)return{};const i=function(e){if("string"==typeof e)return[e];if(!e)return[];const t=Array.isArray(e)?e:[e],i=[];for(const r of t)"string"!=typeof r?i.push({"@language":r["@language"]||r.language,"@value":r["@value"]||r.value}):i.push(r);return i}(e),r={};for(const n of i){if("string"==typeof n){r[t]=r[t]?r[t]:[],r[t].push(n||"");continue}if(!n["@language"]){r[t]=r[t]?r[t]:[],r[t].push(n["@value"]||"");continue}const e=n["@language"];r[e]=r[e]?r[e]:[],r[e].push(n["@value"]||"")}return r}function v(e){return Array.isArray(e)?v(e.find((e=>"string"==typeof e))):-1!==s.indexOf(e)?"level2":-1!==a.indexOf(e)?"level1":"string"==typeof e?e:void 0}function u(e){const t=Array.isArray(e)?e:[e];for(const i of t)switch(i){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function f(e){for(const t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}const m=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function g(e){const t=e["@id"]||e.id;let i=e["@type"]||e.type;const r=e.profile||void 0,n=e["@context"]||void 0;if(r){const e=function(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"}}(r);if(e)return e}if(n){const e=u(n);if(e)return e}if(i){if(Array.isArray(i)){if(-1!==i.indexOf("oa:CssStylesheet"))return"CssStylesheet";if(-1!==i.indexOf("cnt:ContentAsText"))return"TextualBody";i=i[0]}for(const e of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${e}:`)){i=i.slice(e.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(i&&-1!==m.indexOf(i))return i;if(e.format){if(e.format.startsWith("image/"))return"Image";if(e.format.startsWith("text/"))return"Text";if("application/pdf"===e.format)return"Text";if(e.format.startsWith("application/"))return"Dataset"}return t&&(t.endsWith(".jpg")||t.endsWith(".png")||t.endsWith(".jpeg"))?"Image":i||"unknown"}const y=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function d(e){const t=e.match(y);return t?t[0]:e}const A=["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 C(e){if(e){const t=Array.isArray(e)?e:[e],i=[];for(const e of t)"http://iiif.io/api/presentation/2/context.json"===e&&i.push("http://iiif.io/api/presentation/3/context.json"),-1===A.indexOf(e)&&i.push(e);if(t.length)return 1===i.length?i[0]:i}}let b=0;function x(e,t){const i=encodeURI(e.id||e["@id"]||"").trim();return i&&t?`${i}/${t}`:i||(b++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${b}`)}function w(e){const t=[...e.behavior||[]];let i;return e.viewingHint&&t.push(e.viewingHint),Array.isArray(e.motivation)?i=e.motivation.map(f):e.motivation&&(i=f(e.motivation)),{"@context":e["@context"]?C(e["@context"]):void 0,id:(e["@id"]||x(e)).trim(),type:g(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:i,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function j(e){const[t,i]=function(e,t="Rights/License",i="none"){let r=null;const n=[],a=Array.isArray(e)?e:[e];for(const s of a){const e=s?d(s):void 0;!e||-1===e.indexOf("creativecommons.org")&&-1===e.indexOf("rightsstatements.org")?e&&n.push({label:{[i]:[t]},value:{[i]:[e]}}):r=e.startsWith("https://")?`http://${e.slice(8)}`:e}return[r,n]}(e.license),r=[...e.metadata?(n=e.metadata,n?n.map((e=>({label:h(e.label),value:h(e.value)}))):[]):[],...i];var n;return{rights:t,metadata:r.length?r:void 0,label:e.label?h(e.label):void 0,requiredStatement:e.attribution?{label:h(c),value:h(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?h(e.description):void 0,thumbnail:L(e.thumbnail)}}function L(e){if(e){return(Array.isArray(e)?e:[e]).map((e=>"string"==typeof e?{id:e,type:"Image"}:("unknown"===e.type&&(e.type="Image"),e)))}return e}function S(e){if(!e.within)return;const t=Array.isArray(e.within)?e.within:[e.within],i=[];for(const r of t)if("string"==typeof r){if(r&&"sc:Manifest"===e["@type"])i.push({id:r,type:"Collection"})}else r["@id"]&&i.push({id:r["@id"],type:g(r)});return i.length?i:void 0}function R(e){const t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],i=e.contentLayer;return{provider:e.logo||t.length?[{id:l,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:h(p)}]:void 0,partOf:S(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?(r=e.service,Array.isArray(r)?r:r?[r]:[]):void 0,supplementary:i?[i]:void 0};var r}function I(e){const t=e;return o({...w(t),...j(t),...R(t),...(i=t,{chars:i.chars,format:i.format?i.format:void 0,language:i.language})});var i}const T=new n({collection:[function(e){return o({...w(e),...j(e),...R(e),items:e.members})}],manifest:[function(e){const t=[],i=[];let r;for(const a of e.sequences||[])a.canvases.length&&t.push(...a.canvases),a.behavior&&i.push(...a.behavior),a.startCanvas&&(r=a.startCanvas);const n=w(e);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),o({...n,...j(e),...R(e),start:r,items:t,structures:e.structures})}],canvas:[function(e){return o({...w(e),...j(e),...R(e),annotations:e.otherContent&&e.otherContent.length?e.otherContent:void 0,items:e.images&&e.images.length?[{id:x(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}],annotationList:[function(e){return o({...w(e),...j(e),...R(e),items:e.resources&&e.resources.length?e.resources:void 0})}],sequence:[function(e){return e.canvases&&0!==e.canvases.length?{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}:{canvases:[],behavior:[]}}],annotation:[function(e){return o({...w(e),...j(e),...R(e),target:function e(t){if(Array.isArray(t)){if(t.length>1)return{type:"List",items:t.map(e)};t=t[0]}if("string"==typeof t)return encodeURI(t).trim();if("@type"in t){let e;if("string"==typeof t.full)e=t.full;else if("dctypes:Image"===t.full["@type"])e={id:t.full["@id"],type:"Image"};else{if("sc:Canvas"!==t.full["@type"])throw new Error(`Unsupported source type on annotation: ${t.full["@type"]}`);e={id:t.full["@id"],type:"Canvas"}}return{type:"SpecificResource",source:e,selector:k(t.selector)}}return encodeURI(t["@id"]).trim()}(e.on),body:Array.isArray(e.resource)?e.resource.map(I):I(e.resource)})}],contentResource:[I],choice:[function(e){const t=[];return e.default&&"rdf:nil"!==e.default&&t.push(e.default),e.item&&"rdf:nil"!==e.item&&t.push(...e.item),{...w(e),...j(e),items:t}}],range:[function(e){return o({...w(e),...j(e),...R(e),items:e.members})}],service:[function(e){const{"@id":t,"@type":i,"@context":r,profile:n,...a}=e,s={};return t&&(s["@id"]=t),s["@type"]=g(e),"unknown"===s["@type"]&&(r&&r.length&&(s["@context"]=r),s["@type"]="Service"),n&&(s.profile=v(n)),o({...s,...a})}],layer:[function(e){return o({...w(e),...j(e),...R(e)})}]});function k(e){if((Array.isArray(e["@type"])&&e["@type"].includes("oa:SvgSelector")||"oa:SvgSelector"==e["@type"])&&("chars"in e||"value"in e))return{type:"SvgSelector",value:"chars"in e?e.chars:e.value};if("oa:FragmentSelector"===e["@type"])return{type:"FragmentSelector",value:e.value};if("oa:Choice"===e["@type"])return[k(e.default),...(Array.isArray(e.item)?e.item:[e.item]).map(k)];if("iiif:ImageApiSelector"==e["@type"])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"]}`)}exports.Traverse=n,exports.convertLanguageMapping=h,exports.convertPresentation2=function(e){return e&&e["@context"]&&("http://iiif.io/api/presentation/2/context.json"===e["@context"]||-1!==e["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")||"http://www.shared-canvas.org/ns/context.json"===e["@context"])||"http://iiif.io/api/image/2/context.json"===e["@context"]?T.traverseUnknown(e):e},exports.getProfile=v,exports.getTypeFromContext=u,exports.identifyResource=r,exports.presentation2to3=T,exports.types=i; | ||
| //# sourceMappingURL=index.js.map |
@@ -519,2 +519,23 @@ var __defProp = Object.defineProperty; | ||
| }; | ||
| function compatLanguageMap(inputLangProperty) { | ||
| if (typeof inputLangProperty === "string") { | ||
| return [inputLangProperty]; | ||
| } | ||
| if (!inputLangProperty) { | ||
| return []; | ||
| } | ||
| const arrayOfValues = Array.isArray(inputLangProperty) ? inputLangProperty : [inputLangProperty]; | ||
| const languageArray = []; | ||
| for (const language of arrayOfValues) { | ||
| if (typeof language === "string") { | ||
| languageArray.push(language); | ||
| continue; | ||
| } | ||
| languageArray.push({ | ||
| "@language": language["@language"] || language.language, | ||
| "@value": language["@value"] || language.value | ||
| }); | ||
| } | ||
| return languageArray; | ||
| } | ||
| function convertLanguageMapping(inputLangProperty, defaultLang = "none") { | ||
@@ -524,3 +545,3 @@ if (!inputLangProperty) { | ||
| } | ||
| const arrayOfValues = Array.isArray(inputLangProperty) ? inputLangProperty : [inputLangProperty]; | ||
| const arrayOfValues = compatLanguageMap(inputLangProperty); | ||
| const languageMap = {}; | ||
@@ -527,0 +548,0 @@ for (const language of arrayOfValues) { |
@@ -1,2 +0,2 @@ | ||
| var __defProp=Object.defineProperty,__defNormalProp=(e,t,i)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,__publicField=(e,t,i)=>(__defNormalProp(e,"symbol"!=typeof t?t+"":t,i),i);!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).IIIFUpgrader={})}(this,(function(e){"use strict";const t="http://library.stanford.edu/iiif/image-api/compliance.html#level1",i="http://library.stanford.edu/iiif/image-api/compliance.html#level2",r="http://library.stanford.edu/iiif/image-api/conformance.html#level1",n="http://library.stanford.edu/iiif/image-api/conformance.html#level2",s="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",a="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",o="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",c="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",l="http://iiif.io/api/image/1/level1.json",p="http://iiif.io/api/image/1/profiles/level1.json",h="http://iiif.io/api/image/1/level2.json",u="http://iiif.io/api/image/1/profiles/level2.json",v="http://iiif.io/api/image/2/level1.json",f="http://iiif.io/api/image/2/profiles/level1.json",m="http://iiif.io/api/image/2/level2.json",y="http://iiif.io/api/image/2/profiles/level2.json",g="level1",d="level2",A="http://iiif.io/api/image/2/level1",C="http://iiif.io/api/image/2/level2",b=[A,C,t,i,r,n,s,a,o,c,l,p,h,u,v,f,m,y,g,d],x=["http://iiif.io/api/image/2/level0",A,C,"http://library.stanford.edu/iiif/image-api/compliance.html#level0",t,i,"http://library.stanford.edu/iiif/image-api/conformance.html#level0",r,n,"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",s,a,"http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",o,c,"http://iiif.io/api/image/1/level0.json","http://iiif.io/api/image/1/profiles/level0.json",l,p,h,u,"http://iiif.io/api/image/2/level0.json","http://iiif.io/api/image/2/profiles/level0.json",v,f,m,y,"level0",g,d],w=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];class L{constructor(e,t={}){__publicField(this,"traversals"),__publicField(this,"options"),this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...t}}static all(e){return new L({collection:[e],manifest:[e],canvas:[e],annotationList:[e],sequence:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],layer:[e]})}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))),this.traversals.collection)}traverseCollectionItems(e){if(this.options.mergeMemberProperties){const t=[...(e.manifests||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Manifest"}:e)),...(e.collections||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Collection"}:e)),...e.members||[]];delete e.collections,delete e.manifests,e.members=t}return e.manifests&&(e.manifests=e.manifests.map((e=>this.traverseManifest("string"==typeof e?{"@id":e,"@type":"sc:Manifest"}:e)))),e.collections&&(e.collections=e.collections.map((e=>this.traverseCollection("string"==typeof e?{"@id":e,"@type":"sc:Collection"}:e)))),e.members&&(e.members=e.members.map((e=>"string"==typeof e?e:this.traverseUnknown(e)))),e}traverseManifest(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))),this.traversals.manifest)}traverseManifestItems(e){return e.sequences&&(e.sequences=e.sequences.map((e=>this.traverseSequence(e)))),e.structures&&(e.structures=e.structures.map((e=>this.traverseRange(e)))),e}traverseSequence(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))),this.traversals.sequence)}traverseSequenceItems(e){return e.canvases&&(e.canvases=e.canvases.map((e=>this.traverseCanvas(e)))),e}traverseCanvas(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))),this.traversals.canvas)}traverseCanvasItems(e){return e.images&&(e.images=e.images.map((e=>this.traverseAnnotation(e)))),e.otherContent&&(e.otherContent=e.otherContent.map((e=>this.traverseAnnotationList(e)))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const t=[...(e.ranges||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Range"}:e)),...(e.canvases||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Canvas"}:e)),...e.members||[]];delete e.ranges,delete e.canvases,e.members=t.length?t.map((e=>this.traverseUnknown(e))):void 0}return e}traverseAnnotationList(e){const t="string"==typeof e?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(t)),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map((e=>this.traverseAnnotation(e)))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(Array.isArray(e.resource)?e.resource=e.resource.map((e=>this.traverseContentResource(e))):e.resource=this.traverseContentResource(e.resource)),e.on,e}traverseLayer(e){return this.traverseType(this.traverseLinking(this.traverseLayerItems(e)),this.traversals.layer)}traverseLayerItems(e){return e.otherContent&&(e.otherContent=e.otherContent.map((e=>this.traverseAnnotationList(e)))),e}traverseChoice(e){return this.traverseType(this.traverseChoiceItems(e),this.traversals.choice)}traverseChoiceItems(e){return e.default&&"rdf:nil"!==e.default&&(e.default=this.traverseContentResource(e.default)),e.item&&"rdf:nil"!==e.item&&(e.item=e.item.map((e=>this.traverseContentResource(e)))),e}traverseService(e){return this.traverseType(this.traverseLinking(e),this.traversals.service)}traverseContentResource(e){return"oa:Choice"===e["@type"]?this.traverseChoice(e):this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.contentResource)}traverseUnknown(e){if(!e["@type"]||"string"==typeof e)return e;switch(function(e){if(null==e)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("object"!=typeof e)throw new Error(typeof e+" is not a valid entity");if("string"==typeof e["@type"]){const t=w.indexOf(e["@type"]);if(-1!==t)return w[t]}if(e.profile)return"Service";if(e.format)return"ContentResource";if(e["@type"])return"ContentResource";throw new Error("Resource type is not known")}(e)){case"sc:Collection":return this.traverseCollection(e);case"sc:Manifest":return this.traverseManifest(e);case"sc:Canvas":return this.traverseCanvas(e);case"sc:Sequence":return this.traverseSequence(e);case"sc:Range":return this.traverseRange(e);case"oa:Annotation":return this.traverseAnnotation(e);case"sc:AnnotationList":return this.traverseAnnotationList(e);case"sc:Layer":return this.traverseLayer(e);case"Service":return this.traverseService(e);case"oa:Choice":return this.traverseChoice(e);case"ContentResource":return this.traverseContentResource(e)}return e.profile?this.traverseService(e):e}traverseImageResource(e){const t=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(const n of i)"string"==typeof n?r.push(this.traverseContentResource({"@id":n,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(n));return t||this.options.convertPropsToArray?r:r[0]}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){const t=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(const n of i)r.push(this.traverseService(n));return t||this.options.convertPropsToArray?r:r[0]}traverseLinking(e){return e.related&&(e.related=this.traverseOneOrManyType(e.related,this.traversals.contentResource)),e.rendering&&(e.rendering=this.traverseOneOrManyType(e.rendering,this.traversals.contentResource)),e.service&&(e.service=this.traverseOneOrMoreServices(e.service)),e.seeAlso&&(e.seeAlso=this.traverseOneOrManyType(e.seeAlso,this.traversals.contentResource)),e.within&&("string"==typeof e.within||(e.within=this.traverseOneOrManyType(e.within,this.traversals.contentResource))),e.startCanvas&&("string"==typeof e.startCanvas?e.startCanvas=this.traverseType({"@id":e.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):e.startCanvas&&this.traverseType(e.startCanvas,this.traversals.canvas)),e.contentLayer&&("string"==typeof e.contentLayer?e.contentLayer=this.traverseLayer({"@id":e.contentLayer,"@type":"sc:Layer"}):e.contentLayer=this.traverseLayer(e.contentLayer)),e}traverseOneOrManyType(e,t){if(!Array.isArray(e)){if(!this.options.convertPropsToArray)return this.traverseType(e,t);e=[e]}return e.map((e=>this.traverseType(e,t)))}traverseType(e,t){return t.reduce(((e,t)=>{const i=t(e);return void 0!==i||this.options.allowUndefinedReturn?i:e}),e)}}function S(e){for(const t in e)void 0!==e[t]&&null!==e[t]||delete e[t];return e}const j="Attribution",I="http://example.org/provider",R="Unknown";function T(e,t="none"){if(!e)return{};const i=Array.isArray(e)?e:[e],r={};for(const n of i){if("string"==typeof n){r[t]=r[t]?r[t]:[],r[t].push(n||"");continue}if(!n["@language"]){r[t]=r[t]?r[t]:[],r[t].push(n["@value"]||"");continue}const e=n["@language"];r[e]=r[e]?r[e]:[],r[e].push(n["@value"]||"")}return r}function k(e){return Array.isArray(e)?k(e.find((e=>"string"==typeof e))):-1!==x.indexOf(e)?"level2":-1!==b.indexOf(e)?"level1":"string"==typeof e?e:void 0}function O(e){for(const t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}const M=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function q(e){const t=e["@id"]||e.id;let i=e["@type"]||e.type;const r=e.profile||void 0,n=e["@context"]||void 0;if(r){const e=function(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"}}(r);if(e)return e}if(n){const e=function(e){const t=Array.isArray(e)?e:[e];for(const i of t)switch(i){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}(n);if(e)return e}if(i){if(Array.isArray(i)){if(-1!==i.indexOf("oa:CssStylesheet"))return"CssStylesheet";if(-1!==i.indexOf("cnt:ContentAsText"))return"TextualBody";i=i[0]}for(const e of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${e}:`)){i=i.slice(e.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(i&&-1!==M.indexOf(i))return i;if(e.format){if(e.format.startsWith("image/"))return"Image";if(e.format.startsWith("text/"))return"Text";if("application/pdf"===e.format)return"Text";if(e.format.startsWith("application/"))return"Dataset"}return t&&(t.endsWith(".jpg")||t.endsWith(".png")||t.endsWith(".jpeg"))?"Image":i||"unknown"}const P=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function _(e){const t=e.match(P);return t?t[0]:e}const D=["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 U(e){if(e){const t=Array.isArray(e)?e:[e],i=[];for(const e of t)"http://iiif.io/api/presentation/2/context.json"===e&&i.push("http://iiif.io/api/presentation/3/context.json"),-1===D.indexOf(e)&&i.push(e);if(t.length)return 1===i.length?i[0]:i}}let $=0;function W(e,t){const i=encodeURI(e.id||e["@id"]||"").trim();return i&&t?`${i}/${t}`:i||($++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${$}`)}function E(e){const t=[...e.behavior||[]];let i;return e.viewingHint&&t.push(e.viewingHint),Array.isArray(e.motivation)?i=e.motivation.map(O):e.motivation&&(i=O(e.motivation)),{"@context":e["@context"]?U(e["@context"]):void 0,id:(e["@id"]||W(e)).trim(),type:q(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:i,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function F(e){const[t,i]=function(e,t="Rights/License",i="none"){let r=null;const n=[],s=Array.isArray(e)?e:[e];for(const a of s){const e=a?_(a):void 0;!e||-1===e.indexOf("creativecommons.org")&&-1===e.indexOf("rightsstatements.org")?e&&n.push({label:{[i]:[t]},value:{[i]:[e]}}):r=e.startsWith("https://")?`http://${e.slice(8)}`:e}return[r,n]}(e.license),r=[...e.metadata?(n=e.metadata,n?n.map((e=>({label:T(e.label),value:T(e.value)}))):[]):[],...i];var n;return{rights:t,metadata:r.length?r:void 0,label:e.label?T(e.label):void 0,requiredStatement:e.attribution?{label:T(j),value:T(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?T(e.description):void 0,thumbnail:H(e.thumbnail)}}function H(e){if(e){return(Array.isArray(e)?e:[e]).map((e=>"string"==typeof e?{id:e,type:"Image"}:("unknown"===e.type&&(e.type="Image"),e)))}return e}function N(e){if(!e.within)return;const t=Array.isArray(e.within)?e.within:[e.within],i=[];for(const r of t)if("string"==typeof r){if(r&&"sc:Manifest"===e["@type"])i.push({id:r,type:"Collection"})}else r["@id"]&&i.push({id:r["@id"],type:q(r)});return i.length?i:void 0}function B(e){const t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],i=e.contentLayer;return{provider:e.logo||t.length?[{id:I,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:T(R)}]:void 0,partOf:N(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?(r=e.service,Array.isArray(r)?r:r?[r]:[]):void 0,supplementary:i?[i]:void 0};var r}function z(e){const t=e;return S({...E(t),...F(t),...B(t),...(i=t,{chars:i.chars,format:i.format?i.format:void 0,language:i.language})});var i}const G=new L({collection:[function(e){return S({...E(e),...F(e),...B(e),items:e.members})}],manifest:[function(e){const t=[],i=[];let r;for(const s of e.sequences||[])s.canvases.length&&t.push(...s.canvases),s.behavior&&i.push(...s.behavior),s.startCanvas&&(r=s.startCanvas);const n=E(e);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),S({...n,...F(e),...B(e),start:r,items:t,structures:e.structures})}],canvas:[function(e){return S({...E(e),...F(e),...B(e),annotations:e.otherContent&&e.otherContent.length?e.otherContent:void 0,items:e.images&&e.images.length?[{id:W(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}],annotationList:[function(e){return S({...E(e),...F(e),...B(e),items:e.resources&&e.resources.length?e.resources:void 0})}],sequence:[function(e){return e.canvases&&0!==e.canvases.length?{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}:{canvases:[],behavior:[]}}],annotation:[function(e){return S({...E(e),...F(e),...B(e),target:function e(t){if(Array.isArray(t)){if(t.length>1)return{type:"List",items:t.map(e)};t=t[0]}if("string"==typeof t)return encodeURI(t).trim();if("@type"in t){let e;if("string"==typeof t.full)e=t.full;else if("dctypes:Image"===t.full["@type"])e={id:t.full["@id"],type:"Image"};else{if("sc:Canvas"!==t.full["@type"])throw new Error(`Unsupported source type on annotation: ${t.full["@type"]}`);e={id:t.full["@id"],type:"Canvas"}}return{type:"SpecificResource",source:e,selector:J(t.selector)}}return encodeURI(t["@id"]).trim()}(e.on),body:Array.isArray(e.resource)?e.resource.map(z):z(e.resource)})}],contentResource:[z],choice:[function(e){const t=[];return e.default&&"rdf:nil"!==e.default&&t.push(e.default),e.item&&"rdf:nil"!==e.item&&t.push(...e.item),{...E(e),...F(e),items:t}}],range:[function(e){return S({...E(e),...F(e),...B(e),items:e.members})}],service:[function(e){const{"@id":t,"@type":i,"@context":r,profile:n,...s}=e,a={};return t&&(a["@id"]=t),a["@type"]=q(e),"unknown"===a["@type"]&&(r&&r.length&&(a["@context"]=r),a["@type"]="Service"),n&&(a.profile=k(n)),S({...a,...s})}],layer:[function(e){return S({...E(e),...F(e),...B(e)})}]});function J(e){if((Array.isArray(e["@type"])&&e["@type"].includes("oa:SvgSelector")||"oa:SvgSelector"==e["@type"])&&("chars"in e||"value"in e))return{type:"SvgSelector",value:"chars"in e?e.chars:e.value};if("oa:FragmentSelector"===e["@type"])return{type:"FragmentSelector",value:e.value};if("oa:Choice"===e["@type"])return[J(e.default),...(Array.isArray(e.item)?e.item:[e.item]).map(J)];if("iiif:ImageApiSelector"==e["@type"])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"]}`)}const K=function(e){return e&&e["@context"]&&("http://iiif.io/api/presentation/2/context.json"===e["@context"]||-1!==e["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")||"http://www.shared-canvas.org/ns/context.json"===e["@context"])||"http://iiif.io/api/image/2/context.json"===e["@context"]?G.traverseUnknown(e):e};e.upgrade=K,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})})); | ||
| var __defProp=Object.defineProperty,__defNormalProp=(e,t,i)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,__publicField=(e,t,i)=>(__defNormalProp(e,"symbol"!=typeof t?t+"":t,i),i);!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).IIIFUpgrader={})}(this,(function(e){"use strict";const t="http://library.stanford.edu/iiif/image-api/compliance.html#level1",i="http://library.stanford.edu/iiif/image-api/compliance.html#level2",r="http://library.stanford.edu/iiif/image-api/conformance.html#level1",n="http://library.stanford.edu/iiif/image-api/conformance.html#level2",s="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",a="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",o="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",c="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",l="http://iiif.io/api/image/1/level1.json",p="http://iiif.io/api/image/1/profiles/level1.json",u="http://iiif.io/api/image/1/level2.json",h="http://iiif.io/api/image/1/profiles/level2.json",v="http://iiif.io/api/image/2/level1.json",f="http://iiif.io/api/image/2/profiles/level1.json",m="http://iiif.io/api/image/2/level2.json",y="http://iiif.io/api/image/2/profiles/level2.json",g="level1",d="level2",A="http://iiif.io/api/image/2/level1",C="http://iiif.io/api/image/2/level2",b=[A,C,t,i,r,n,s,a,o,c,l,p,u,h,v,f,m,y,g,d],x=["http://iiif.io/api/image/2/level0",A,C,"http://library.stanford.edu/iiif/image-api/compliance.html#level0",t,i,"http://library.stanford.edu/iiif/image-api/conformance.html#level0",r,n,"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",s,a,"http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",o,c,"http://iiif.io/api/image/1/level0.json","http://iiif.io/api/image/1/profiles/level0.json",l,p,u,h,"http://iiif.io/api/image/2/level0.json","http://iiif.io/api/image/2/profiles/level0.json",v,f,m,y,"level0",g,d],w=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];class L{constructor(e,t={}){__publicField(this,"traversals"),__publicField(this,"options"),this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...t}}static all(e){return new L({collection:[e],manifest:[e],canvas:[e],annotationList:[e],sequence:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],layer:[e]})}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))),this.traversals.collection)}traverseCollectionItems(e){if(this.options.mergeMemberProperties){const t=[...(e.manifests||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Manifest"}:e)),...(e.collections||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Collection"}:e)),...e.members||[]];delete e.collections,delete e.manifests,e.members=t}return e.manifests&&(e.manifests=e.manifests.map((e=>this.traverseManifest("string"==typeof e?{"@id":e,"@type":"sc:Manifest"}:e)))),e.collections&&(e.collections=e.collections.map((e=>this.traverseCollection("string"==typeof e?{"@id":e,"@type":"sc:Collection"}:e)))),e.members&&(e.members=e.members.map((e=>"string"==typeof e?e:this.traverseUnknown(e)))),e}traverseManifest(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))),this.traversals.manifest)}traverseManifestItems(e){return e.sequences&&(e.sequences=e.sequences.map((e=>this.traverseSequence(e)))),e.structures&&(e.structures=e.structures.map((e=>this.traverseRange(e)))),e}traverseSequence(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))),this.traversals.sequence)}traverseSequenceItems(e){return e.canvases&&(e.canvases=e.canvases.map((e=>this.traverseCanvas(e)))),e}traverseCanvas(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))),this.traversals.canvas)}traverseCanvasItems(e){return e.images&&(e.images=e.images.map((e=>this.traverseAnnotation(e)))),e.otherContent&&(e.otherContent=e.otherContent.map((e=>this.traverseAnnotationList(e)))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const t=[...(e.ranges||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Range"}:e)),...(e.canvases||[]).map((e=>"string"==typeof e?{"@id":e,"@type":"sc:Canvas"}:e)),...e.members||[]];delete e.ranges,delete e.canvases,e.members=t.length?t.map((e=>this.traverseUnknown(e))):void 0}return e}traverseAnnotationList(e){const t="string"==typeof e?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(t)),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map((e=>this.traverseAnnotation(e)))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(Array.isArray(e.resource)?e.resource=e.resource.map((e=>this.traverseContentResource(e))):e.resource=this.traverseContentResource(e.resource)),e.on,e}traverseLayer(e){return this.traverseType(this.traverseLinking(this.traverseLayerItems(e)),this.traversals.layer)}traverseLayerItems(e){return e.otherContent&&(e.otherContent=e.otherContent.map((e=>this.traverseAnnotationList(e)))),e}traverseChoice(e){return this.traverseType(this.traverseChoiceItems(e),this.traversals.choice)}traverseChoiceItems(e){return e.default&&"rdf:nil"!==e.default&&(e.default=this.traverseContentResource(e.default)),e.item&&"rdf:nil"!==e.item&&(e.item=e.item.map((e=>this.traverseContentResource(e)))),e}traverseService(e){return this.traverseType(this.traverseLinking(e),this.traversals.service)}traverseContentResource(e){return"oa:Choice"===e["@type"]?this.traverseChoice(e):this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.contentResource)}traverseUnknown(e){if(!e["@type"]||"string"==typeof e)return e;switch(function(e){if(null==e)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("object"!=typeof e)throw new Error(typeof e+" is not a valid entity");if("string"==typeof e["@type"]){const t=w.indexOf(e["@type"]);if(-1!==t)return w[t]}if(e.profile)return"Service";if(e.format)return"ContentResource";if(e["@type"])return"ContentResource";throw new Error("Resource type is not known")}(e)){case"sc:Collection":return this.traverseCollection(e);case"sc:Manifest":return this.traverseManifest(e);case"sc:Canvas":return this.traverseCanvas(e);case"sc:Sequence":return this.traverseSequence(e);case"sc:Range":return this.traverseRange(e);case"oa:Annotation":return this.traverseAnnotation(e);case"sc:AnnotationList":return this.traverseAnnotationList(e);case"sc:Layer":return this.traverseLayer(e);case"Service":return this.traverseService(e);case"oa:Choice":return this.traverseChoice(e);case"ContentResource":return this.traverseContentResource(e)}return e.profile?this.traverseService(e):e}traverseImageResource(e){const t=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(const n of i)"string"==typeof n?r.push(this.traverseContentResource({"@id":n,"@type":"dctypes:Image"})):r.push(this.traverseContentResource(n));return t||this.options.convertPropsToArray?r:r[0]}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){const t=Array.isArray(e),i=Array.isArray(e)?e:[e],r=[];for(const n of i)r.push(this.traverseService(n));return t||this.options.convertPropsToArray?r:r[0]}traverseLinking(e){return e.related&&(e.related=this.traverseOneOrManyType(e.related,this.traversals.contentResource)),e.rendering&&(e.rendering=this.traverseOneOrManyType(e.rendering,this.traversals.contentResource)),e.service&&(e.service=this.traverseOneOrMoreServices(e.service)),e.seeAlso&&(e.seeAlso=this.traverseOneOrManyType(e.seeAlso,this.traversals.contentResource)),e.within&&("string"==typeof e.within||(e.within=this.traverseOneOrManyType(e.within,this.traversals.contentResource))),e.startCanvas&&("string"==typeof e.startCanvas?e.startCanvas=this.traverseType({"@id":e.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):e.startCanvas&&this.traverseType(e.startCanvas,this.traversals.canvas)),e.contentLayer&&("string"==typeof e.contentLayer?e.contentLayer=this.traverseLayer({"@id":e.contentLayer,"@type":"sc:Layer"}):e.contentLayer=this.traverseLayer(e.contentLayer)),e}traverseOneOrManyType(e,t){if(!Array.isArray(e)){if(!this.options.convertPropsToArray)return this.traverseType(e,t);e=[e]}return e.map((e=>this.traverseType(e,t)))}traverseType(e,t){return t.reduce(((e,t)=>{const i=t(e);return void 0!==i||this.options.allowUndefinedReturn?i:e}),e)}}function S(e){for(const t in e)void 0!==e[t]&&null!==e[t]||delete e[t];return e}const j="Attribution",I="http://example.org/provider",R="Unknown";function T(e,t="none"){if(!e)return{};const i=function(e){if("string"==typeof e)return[e];if(!e)return[];const t=Array.isArray(e)?e:[e],i=[];for(const r of t)"string"!=typeof r?i.push({"@language":r["@language"]||r.language,"@value":r["@value"]||r.value}):i.push(r);return i}(e),r={};for(const n of i){if("string"==typeof n){r[t]=r[t]?r[t]:[],r[t].push(n||"");continue}if(!n["@language"]){r[t]=r[t]?r[t]:[],r[t].push(n["@value"]||"");continue}const e=n["@language"];r[e]=r[e]?r[e]:[],r[e].push(n["@value"]||"")}return r}function k(e){return Array.isArray(e)?k(e.find((e=>"string"==typeof e))):-1!==x.indexOf(e)?"level2":-1!==b.indexOf(e)?"level1":"string"==typeof e?e:void 0}function O(e){for(const t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}const M=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function q(e){const t=e["@id"]||e.id;let i=e["@type"]||e.type;const r=e.profile||void 0,n=e["@context"]||void 0;if(r){const e=function(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"}}(r);if(e)return e}if(n){const e=function(e){const t=Array.isArray(e)?e:[e];for(const i of t)switch(i){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}(n);if(e)return e}if(i){if(Array.isArray(i)){if(-1!==i.indexOf("oa:CssStylesheet"))return"CssStylesheet";if(-1!==i.indexOf("cnt:ContentAsText"))return"TextualBody";i=i[0]}for(const e of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${e}:`)){i=i.slice(e.length+1);break}switch(i){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(i&&-1!==M.indexOf(i))return i;if(e.format){if(e.format.startsWith("image/"))return"Image";if(e.format.startsWith("text/"))return"Text";if("application/pdf"===e.format)return"Text";if(e.format.startsWith("application/"))return"Dataset"}return t&&(t.endsWith(".jpg")||t.endsWith(".png")||t.endsWith(".jpeg"))?"Image":i||"unknown"}const P=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function _(e){const t=e.match(P);return t?t[0]:e}const D=["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 U(e){if(e){const t=Array.isArray(e)?e:[e],i=[];for(const e of t)"http://iiif.io/api/presentation/2/context.json"===e&&i.push("http://iiif.io/api/presentation/3/context.json"),-1===D.indexOf(e)&&i.push(e);if(t.length)return 1===i.length?i[0]:i}}let $=0;function W(e,t){const i=encodeURI(e.id||e["@id"]||"").trim();return i&&t?`${i}/${t}`:i||($++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${$}`)}function E(e){const t=[...e.behavior||[]];let i;return e.viewingHint&&t.push(e.viewingHint),Array.isArray(e.motivation)?i=e.motivation.map(O):e.motivation&&(i=O(e.motivation)),{"@context":e["@context"]?U(e["@context"]):void 0,id:(e["@id"]||W(e)).trim(),type:q(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:i,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function F(e){const[t,i]=function(e,t="Rights/License",i="none"){let r=null;const n=[],s=Array.isArray(e)?e:[e];for(const a of s){const e=a?_(a):void 0;!e||-1===e.indexOf("creativecommons.org")&&-1===e.indexOf("rightsstatements.org")?e&&n.push({label:{[i]:[t]},value:{[i]:[e]}}):r=e.startsWith("https://")?`http://${e.slice(8)}`:e}return[r,n]}(e.license),r=[...e.metadata?(n=e.metadata,n?n.map((e=>({label:T(e.label),value:T(e.value)}))):[]):[],...i];var n;return{rights:t,metadata:r.length?r:void 0,label:e.label?T(e.label):void 0,requiredStatement:e.attribution?{label:T(j),value:T(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?T(e.description):void 0,thumbnail:H(e.thumbnail)}}function H(e){if(e){return(Array.isArray(e)?e:[e]).map((e=>"string"==typeof e?{id:e,type:"Image"}:("unknown"===e.type&&(e.type="Image"),e)))}return e}function N(e){if(!e.within)return;const t=Array.isArray(e.within)?e.within:[e.within],i=[];for(const r of t)if("string"==typeof r){if(r&&"sc:Manifest"===e["@type"])i.push({id:r,type:"Collection"})}else r["@id"]&&i.push({id:r["@id"],type:q(r)});return i.length?i:void 0}function B(e){const t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],i=e.contentLayer;return{provider:e.logo||t.length?[{id:I,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:T(R)}]:void 0,partOf:N(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?(r=e.service,Array.isArray(r)?r:r?[r]:[]):void 0,supplementary:i?[i]:void 0};var r}function z(e){const t=e;return S({...E(t),...F(t),...B(t),...(i=t,{chars:i.chars,format:i.format?i.format:void 0,language:i.language})});var i}const G=new L({collection:[function(e){return S({...E(e),...F(e),...B(e),items:e.members})}],manifest:[function(e){const t=[],i=[];let r;for(const s of e.sequences||[])s.canvases.length&&t.push(...s.canvases),s.behavior&&i.push(...s.behavior),s.startCanvas&&(r=s.startCanvas);const n=E(e);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),S({...n,...F(e),...B(e),start:r,items:t,structures:e.structures})}],canvas:[function(e){return S({...E(e),...F(e),...B(e),annotations:e.otherContent&&e.otherContent.length?e.otherContent:void 0,items:e.images&&e.images.length?[{id:W(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}],annotationList:[function(e){return S({...E(e),...F(e),...B(e),items:e.resources&&e.resources.length?e.resources:void 0})}],sequence:[function(e){return e.canvases&&0!==e.canvases.length?{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}:{canvases:[],behavior:[]}}],annotation:[function(e){return S({...E(e),...F(e),...B(e),target:function e(t){if(Array.isArray(t)){if(t.length>1)return{type:"List",items:t.map(e)};t=t[0]}if("string"==typeof t)return encodeURI(t).trim();if("@type"in t){let e;if("string"==typeof t.full)e=t.full;else if("dctypes:Image"===t.full["@type"])e={id:t.full["@id"],type:"Image"};else{if("sc:Canvas"!==t.full["@type"])throw new Error(`Unsupported source type on annotation: ${t.full["@type"]}`);e={id:t.full["@id"],type:"Canvas"}}return{type:"SpecificResource",source:e,selector:J(t.selector)}}return encodeURI(t["@id"]).trim()}(e.on),body:Array.isArray(e.resource)?e.resource.map(z):z(e.resource)})}],contentResource:[z],choice:[function(e){const t=[];return e.default&&"rdf:nil"!==e.default&&t.push(e.default),e.item&&"rdf:nil"!==e.item&&t.push(...e.item),{...E(e),...F(e),items:t}}],range:[function(e){return S({...E(e),...F(e),...B(e),items:e.members})}],service:[function(e){const{"@id":t,"@type":i,"@context":r,profile:n,...s}=e,a={};return t&&(a["@id"]=t),a["@type"]=q(e),"unknown"===a["@type"]&&(r&&r.length&&(a["@context"]=r),a["@type"]="Service"),n&&(a.profile=k(n)),S({...a,...s})}],layer:[function(e){return S({...E(e),...F(e),...B(e)})}]});function J(e){if((Array.isArray(e["@type"])&&e["@type"].includes("oa:SvgSelector")||"oa:SvgSelector"==e["@type"])&&("chars"in e||"value"in e))return{type:"SvgSelector",value:"chars"in e?e.chars:e.value};if("oa:FragmentSelector"===e["@type"])return{type:"FragmentSelector",value:e.value};if("oa:Choice"===e["@type"])return[J(e.default),...(Array.isArray(e.item)?e.item:[e.item]).map(J)];if("iiif:ImageApiSelector"==e["@type"])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"]}`)}const K=function(e){return e&&e["@context"]&&("http://iiif.io/api/presentation/2/context.json"===e["@context"]||-1!==e["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")||"http://www.shared-canvas.org/ns/context.json"===e["@context"])||"http://iiif.io/api/image/2/context.json"===e["@context"]?G.traverseUnknown(e):e};e.upgrade=K,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})})); | ||
| //# sourceMappingURL=index.umd.js.map |
+1
-1
| { | ||
| "name": "@iiif/parser", | ||
| "version": "2.0.1", | ||
| "version": "2.0.2", | ||
| "license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "IIIF Presentation 2 and 3 parsing utilities", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
2669245
0.31%34392
0.13%