/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/iiif-prezi2to3@2.0.2/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var crypto=_interopDefault(require("crypto"));function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),e}var urlAlphabet="ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW",buffers={},random=function(e){var t=buffers[e];return t||(t=Buffer.allocUnsafe(e),e<=255&&(buffers[e]=t)),crypto.randomFillSync(t)},customRandom=function(e,t,r){var i=(2<<31-Math.clz32(e.length-1|1))-1,n=Math.ceil(1.6*i*t/e.length);return function(){for(var a="";;)for(var s=r(n),o=n;o--;)if((a+=e[s[o]&i]||"").length===+t)return a}},customAlphabet=function(e,t){return customRandom(e,t,random)},nanoid=function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:21,t=random(e),r="";e--;)r+=urlAlphabet[63&t[e]];return r},nanoid$1=Object.freeze({__proto__:null,nanoid:nanoid,customAlphabet:customAlphabet,customRandom:customRandom,urlAlphabet:urlAlphabet,random:random}),nanoid$2=nanoid$1.nanoid,FLAGS={crawl:{prop:"crawl",default:!1,description:""},desc_2_md:{prop:"description_is_metadata",default:!0,description:""},related_2_md:{prop:"related_is_metadata",default:!1,description:""},ext_ok:{prop:"ext_ok",default:!1,description:""},default_lang:{prop:"default_lang",default:"@none",description:""},deref_links:{prop:"deref_links",default:!0,description:""},debug:{prop:"debug",default:!1,description:""},attribution_label:{prop:"attribution_label",default:"Attribution",description:""},license_label:{prop:"license_label",default:"Rights/License",description:""}},CONTENT_TYPE_MAP={image:"Image",audio:"Sound",video:"Video","application/pdf":"Text","text/html":"Text","text/plain":"Text","application/xml":"Dataset","text/xml":"Dataset"},OBJECT_PROPERTY_TYPES={thumbnail:"Image",logo:"Image",homepage:null,rendering:null,seeAlso:"Dataset",partOf:null},SET_PROPERTIES=["thumbnail","logo","behavior","rendering","service","seeAlso","partOf"],LANGUAGE_PROPERTIES=["label","summary"],DO_NOT_TRAVERSE=["metadata","structures","_structures","requiredStatement"],SIMPLE_TYPE_MAP={Layer:"AnnotationCollection",AnnotationList:"AnnotationPage","cnt:ContentAsText":"TextualBody"},TYPES_WITH_MANDATORY_ID=["Collection","Manifest","Canvas","Annotation","Range","AnnotationCollection","AnnotationPage"],PARTOF_MAPPING={Collection:"Collection",Manifest:"Collection",Canvas:"Manifest",Annotation:"AnnotationPage",AnnotationPage:"AnnotationCollection"},isArray=function(e){return e instanceof Array},isDictionary=function(e){return e instanceof Object&&!(e instanceof Array)},Upgrader=function(){function e(){var t=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(var i in _classCallCheck(this,e),this.warn=function(e){},this.retrieveResource=function(e){var t=new XMLHttpRequest;t.open("GET",e,!1);try{if(t.send(null),200===t.status)return JSON.parse(t.responseText)}catch(e){}return{}},this.mintURI=function(){var e=nanoid$2();return"https://example.org/uuid/".concat(e)},this.traverse=function(e){var r={},i=null,n=null,a=function(a){if(i=e[a],LANGUAGE_PROPERTIES.includes(a)||DO_NOT_TRAVERSE.includes(a))return r[a]=i,"continue";if(n="service"===a?t.processService:t.processResource,isDictionary(i)){var s=Object.keys(i);2===s.length&&s.includes("type")&&s.includes("id")?r[a]=i:r[a]=n(i)}else if(isArray(i)){var o=[];i.forEach((function(e){if(isDictionary(e)){var t=Object.keys(e);2===t.length&&t.includes("type")&&t.includes("id")?o.push(e):o.push(n(e))}else o.push(e);r[a]=o}))}else r[a]=i;LANGUAGE_PROPERTIES.includes(a)||DO_NOT_TRAVERSE.includes(a)||t.warn("Unknown property: ".concat(a))};for(var s in e)a(s);return r},this.fixServiceType=function(e){if(e.hasOwnProperty("@context")){var r=e["@context"];if("http://iiif.io/api/image/2/context.json"===r||"http://iiif.io/api/image/2/level2.json"===r)return e["@type"]="ImageService2",delete e["@context"],e;if(["http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json"].includes(r))return e["@type"]="ImageService1",delete e["@context"],e;["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"].includes(r)?delete e["@context"]:"http://iiif.io/api/annex/openannotation/context.json"===r?(e["@type"]="ImageApiSelector",delete e["@context"]):(e["@type"]="Service",t.warn("Unknown context: ".concat(r)))}else e["@type"]="Service",t.warn("No cotext at all");if(e.hasOwnProperty("profile")){var i=e.profile;["http://iiif.io/api/auth/1/kiosk","http://iiif.io/api/auth/1/login","http://iiif.io/api/auth/1/clickthrough","http://iiif.io/api/auth/1/external","http://iiif.io/api/auth/0/kiosk","http://iiif.io/api/auth/0/login","http://iiif.io/api/auth/0/clickthrough","http://iiif.io/api/auth/0/external"].includes(i)?e["@type"]="AuthCookieService1":["http://iiif.io/api/auth/1/token","http://iiif.io/api/auth/0/token"].includes(i)?e["@type"]="AuthTokenService1":["http://iiif.io/api/auth/1/logout","http://iiif.io/api/auth/0/logout"].includes(i)?e["@type"]="AuthLogoutService1":["http://iiif.io/api/search/1/search","http://iiif.io/api/search/0/search"].includes(i)?e["@type"]="SearchService1":["http://iiif.io/api/search/1/autocomplete","http://iiif.io/api/search/0/autocomplete"].includes(i)&&(e["@type"]="AutoCompleteService1")}return e},this.fixType=function(e){var t=e["@type"]||"";return t&&(isArray(t)&&(t.includes("oa:CssStyle")?t="CssStylesheet":t.includes("cnt:ContentAsText")&&(t="TextualBody")),t=t.replace(/^(sc|oa|dctypes|iiif)\:/,""),SIMPLE_TYPE_MAP.hasOwnProperty(t)&&(t=SIMPLE_TYPE_MAP[t]),e.type=t,delete e["@type"]),e},this.fixLanguages=function(e){return LANGUAGE_PROPERTIES.forEach((function(r){if(e.hasOwnProperty(r))try{e[r]=t.doLanguageMap(e[r])}catch(e){throw e}})),e.hasOwnProperty("metadata")&&(e.metadata=e.metadata.map((function(e){return{label:t.doLanguageMap(e.label),value:t.doLanguageMap(e.value)}}))),e},this.fixSets=function(e){return SET_PROPERTIES.forEach((function(t){e.hasOwnProperty(t)&&(isArray(e[t])||(e[t]=[e[t]]))})),e},this.getHeader=function(e){var t=new XMLHttpRequest;t.open("HEAD",e,!1);try{if(t.send(null),200===t.status)return{headers:{get:function(e){return t.getResponseHeader(e)}},status:t.status}}catch(e){}return null},this.setRemoteType=function(e){var r=null;try{r=t.getHeader(e.id)}catch(e){}if(r&&200==r.status){var i=r.headers.get("content-type");e.format=i;var n=(i=i.toLowerCase()).split("/")[0];if(CONTENT_TYPE_MAP.hasOwnProperty(n))e.type=CONTENT_TYPE_MAP[n];else if(CONTENT_TYPE_MAP.hasOwnProperty(i))e.type=CONTENT_TYPE_MAP[i];else if(i.startsWith("application/json")||i.startsWith("application/ld+json")){var a=t.retrieveResource(e.id);a.hasOwnProperty("type")?e.type=a.type:a.hasOwnProperty("@type")&&(a=t.fixType(a),e.type=a.type)}}},this.fixObject=function(e,r){if(isDictionary(e)){if(isDictionary(e)&&0===Object.keys(e).length)return{}}else e={id:e};var i=e.id||e["@id"]||"";return!e.hasOwnProperty("type")&&r?e.type=r:!e.hasOwnProperty("type")&&i&&(t.idTypeHash.hasOwnProperty(i)?e.type=t.idTypeHash[i]:!0===t.deref_links?t.setRemoteType(e):(e.hasOwnProperty("format")&&(e.format.startsWith("image/")?e.type="Image":e.format.startsWith("video/")?e.type="Video":e.format.startsWith("audio/")?e.type="Audio":(e.format.startsWith("text/")||e.format.startsWith("application/pdf"))&&(e.type="Text")),!e.hasOwnProperty("type")&&i.indexOf(".htm")>-1?e.type="Text":e.hasOwnProperty("type"))),e},this.fixObjects=function(e){var r=function(){var r=OBJECT_PROPERTY_TYPES[i];e.hasOwnProperty(i)&&(SET_PROPERTIES.includes(i)?e[i]=e[i].map((function(e){return t.fixObject(e,r)})):e[i]=t.fixObject(e[i],r))};for(var i in OBJECT_PROPERTY_TYPES)r();return e},this.processGeneric=function(e){if(e.hasOwnProperty("@id")&&(e.id=e["@id"],delete e["@id"]),e.hasOwnProperty("type")&&TYPES_WITH_MANDATORY_ID.includes(e.type)&&!e.hasOwnProperty("id")&&(e.id=t.mintURI()),e.hasOwnProperty("id")&&e.hasOwnProperty("type"))try{t.idTypeHash[e.id]=e.type}catch(t){throw"ValueError: ".concat(e.id)}if(e.hasOwnProperty("license")){var r=e.license;isArray(r)||(r=[r]);var i=!1;r.forEach((function(r){if(isDictionary(r)&&(r=r["@id"]),!i&&(r.indexOf("creativecommons.org/")>-1||r.indexOf("rightsstatements.org/")>-1))e.rights=r,i=!0;else{var n={label:t.license_label,value:r},a=e.metadata||[];a.push(n),e.metadata=a}})),delete e.license}if(e.hasOwnProperty("attribution")){var n=t.doLanguageMap(t.attribution_label),a=t.doLanguageMap(e.attribution);e.requiredStatement={label:n,value:a},delete e.attribution}if(e.hasOwnProperty("viewingHint")&&(e.hasOwnProperty("behavior")?isArray(e.viewingHint)?e.behavior=e.behavior.concat(e.viewingHint):e.behavior.push(e.viewingHint):e.behavior=e.viewingHint,delete e.viewingHint),e.hasOwnProperty("description")){if(t.description_is_metadata){var s=e.metadata||[];s.push({label:"Description",value:e.description}),e.metadata=s}else e.summary=e.description;delete e.description}if(e.hasOwnProperty("related")){var o=e.related;isArray(o)||(o=[o]),o.forEach((function(r){if(t.related_is_metadata||r!==o[0]){var i="",n="";isDictionary(r)?(i=r["@id"],r.hasOwnProperty("label")&&(n=r.label)):i=r;var a=e.metadata||[];a.push({label:"Related",value:"<a href='"+i+"'>"+n+"</a>"}),e.metadata=a}else isDictionary(r)||(r={"@id":r}),e.homepage=r})),delete e.related}return e.hasOwnProperty("otherContent")&&(e.annotations=e.otherContent,delete e.otherContent),e.hasOwnProperty("within")&&(e.partOf=e.within,delete e.within),e=t.fixLanguages(e),e=t.fixSets(e),e=t.fixObjects(e)},this.processService=function(e){if((e=t.fixServiceType(e)).hasOwnProperty("@id")&&(e.id=e["@id"],delete e["@id"]),e.hasOwnProperty("@type")&&(e.type=e["@type"],delete e["@type"]),e.hasOwnProperty("service")){var r=e.service;isArray(r)||(e.service=[r]),e.service=e.service.map((function(e){return t.processService(e)}))}else if(1===Object.keys(e).length&&e.hasOwnProperty("type"))return{};return e},this.processCollection=function(e){if((e=t.processGeneric(e)).hasOwnProperty("members"))e.items=e.members,delete e.members;else{var r=(e.hasOwnProperty("collections")?e.collections:[]).map((function(e){return isDictionary(e)?(e.hasOwnProperty("type")||(e.type="Collection"),e):{id:e,type:"Collection"}})),i=(e.hasOwnProperty("manifests")?e.manifests:[]).map((function(e){return isDictionary(e)?(e.hasOwnProperty("type")||(e.type="Manifest"),e):{id:e,type:"Manifest"}})),n=r.concat(i);n.length>0&&(e.items=n)}return e.hasOwnProperty("manifests")&&delete e.manifests,e.hasOwnProperty("collections")&&delete e.collections,e},this.areSequencesNeeded=function(e){var t=e.sequences,r=t.length;if(0===r)return!1;if(r>1)return!0;var i=t[0].hasOwnProperty("viewingHint")&&"paged"!==t[0].viewingHint,n=t[0].hasOwnProperty("viewingDirection")&&"left-to-right"!==t[0].viewingDirection,a=t[0].hasOwnProperty("metadata");return i||n||a},this.processManifest=function(e){if((e=t.processGeneric(e)).hasOwnProperty("startCanvas")){var r=e.startCanvas;isDictionary(r)?(r.type="Canvas",e.start=r):e.start={id:r,type:"Canvas"},delete e.startCanvas}if(e.hasOwnProperty("sequences")){var i=e.sequences,n=t.areSequencesNeeded(e);e.items=i[0].canvases,delete e.sequences,n&&(e._structures=[],i.forEach((function(r){var i={id:r["@id"]||t.mintURI(),type:"Range",behavior:["sequence"]};i.items=(r.canvases||[]).map((function(e){return isDictionary(e)?{id:e["@id"],type:"Canvas"}:"string"==typeof e?{id:e,type:"Canvas"}:void 0})),delete r.canvases,Object.keys(r).forEach((function(e){["@id","@type"].includes(e)||(i[e]=r[e])})),t.processGeneric(i),e._structures.push(i)})))}return e},this.processRange=function(e){if((e=t.processGeneric(e)).hasOwnProperty("items"));else if(e.hasOwnProperty("members")){var r=e.members;delete e.members,e.items=r.map((function(e){return isDictionary(e)?e:t.idTypeHash.hasOwnProperty(e)?{id:e,type:t.idTypeHash[e]}:{id:e}}))}else{var i=[];i=(e.ranges||[]).map((function(e){return isDictionary(e)?(e.hasOwnProperty("type")||(e.type="Range"),e):{id:e,type:"Range"}}));var n=e.canvases||[];i=i.concat(n.map((function(e){return isDictionary(e)?(e.hasOwnProperty("type")&&(e.type="Canvas"),e):{id:e,type:"Canvas"}}))),e.items=i}if(e.hasOwnProperty("canvases")&&delete e.canvases,e.hasOwnProperty("ranges")&&delete e.ranges,e.hasOwnProperty("contentLayer")){var a=e.contentLayer;isArray(a)&&1===a.length&&(a=a[0]),isDictionary(a)?(a.type="AnnotationCollection",e.supplementary=a):e.supplementary={id:a,type:"AnnotationCollection"},delete e.contentLayer}return e.hasOwnProperty("behavior")&&e.behavior.includes("top")&&(e.behavior.splice(e.behavior.indexOf("top"),1),0===e.behavior.length&&delete e.behavior),e.hasOwnProperty("supplementary")&&(e.supplementary=t.processResource(e.supplementary)),e},this.processCanvas=function(e){return(e=t.processGeneric(e)).hasOwnProperty("images")&&(e.items=[{type:"AnnotationPage",items:e.images.map((function(e){return JSON.parse(JSON.stringify(e))}))}],delete e.images),e},this.processLayer=function(e){return t.processGeneric(e)},this.processAnnotationpage=function(e){return(e=t.processGeneric(e)).hasOwnProperty("resources")?(e.items=e.resources,delete e.resources):e.hasOwnProperty("items")||(e.items=[]),e},this.processAnnotationcollection=function(e){return t.processGeneric(e)},this.processAnnotation=function(e){(e=t.processGeneric(e)).hasOwnProperty("on")&&(e.target=e.on,delete e.on),e.hasOwnProperty("resource")&&(e.body=e.resource,delete e.resource);var r=e.motivation||"";if(r&&(r.startsWith("sc:")?r=r.replace("sc:",""):r.startsWith("oa:")&&(r=r.replace("oa:","")),e.motivation=r),e.hasOwnProperty("stylesheet")){var i=e.stylesheet;isDictionary(i)?(i["@type"]="oa:CssStylesheet",i.hasOwnProperty("chars")&&(i.value=i.chars,delete i.chars)):e.stylesheet={"@id":i,"@type":"oa:CssStylesheet"}}return e},this.processSpecificresource=function(e){return(e=t.processGeneric(e)).hasOwnProperty("full")&&(e.source=e.full,delete e.full),e.hasOwnProperty("style")&&(e.styleClass=e.style,delete e.style),e},this.processTextualbody=function(e){return e.hasOwnProperty("chars")&&(e.value=e.chars,delete e.chars),e},this.processChoice=function(e){var r=[];if((e=t.processGeneric(e)).hasOwnProperty("default")&&(r.push(e.default),delete e.default),e.hasOwnProperty("item")){var i=e.item;isArray(i)||(i=[i]),r=r.concat(i),delete e.item}return e.items=r,e},this.postProcessGeneric=function(e){e.hasOwnProperty("homepage")&&!e.homepage.hasOwnProperty("type")&&(e.homepage.type="Text");var t={};for(var r in e){var i=e[r];isArray(i)&&0===(i=i.filter((function(e){return!(e.constructor===Object&&0===Object.keys(e).length)&&null!=e}))).length&&(i=!1),i&&(t[r]=i)}return t.hasOwnProperty("type")&&PARTOF_MAPPING.hasOwnProperty(t.type)&&t.hasOwnProperty("partOf")&&t.partOf.constructor===Array&&t.partOf.forEach((function(e){e.hasOwnProperty("type")||(e.type=PARTOF_MAPPING[t.type])})),t},this.postProcessManifest=function(e){e=t.postProcessGeneric(e);var r=[],i={},n=[];if(e.hasOwnProperty("structures")){e.structures.forEach((function(e){var n=t.fixType(e);n=t.processRange(n),i[n.id]=n,r.push(n.id)}));var a=[];e.structures.forEach((function(e){if(a=[],e.items.forEach((function(e){var n={};e.hasOwnProperty("@id")?(n=t.fixType(e),n=t.processGeneric(n)):n=e,"Range"===n.type&&i.hasOwnProperty(n.id)?(a.push(i[n.id]),delete i[n.id],r.splice(r.indexOf(n.id),1)):a.push(n)})),e.items=a,e.hasOwnProperty("partOf")){r.splice(r.indexOf(e.id),1);var n=e.partOf[0].id;delete e.partOf;var s=i[n];s?(e.items.forEach((function(e){s.items=s.items.filter((function(t){return e.id!==t.id}))})),s.items.push(e)):t.warn("Unknown parent range: %s"%n)}}))}return e.hasOwnProperty("_structures")&&(n=e._structures,delete e._structures),r.length>0&&r.forEach((function(e){i.hasOwnProperty(e)&&n.push(i[e])})),n.length>0&&(e.structures=n),e},this.processResource=function(e){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i="";r&&(i=e["@context"],delete e["@context"]);var n=((e=t.fixType(e)).type||"").split("").map((function(e,t){return 0===t?e.toUpperCase():e.toLowerCase()})).join("");return e=(t["process".concat(n)]||t.processGeneric)(e),e=t.traverse(e),e=(t["postProcess".concat(n)]||t.postProcessGeneric)(e),r&&(isArray(i)||(e["@context"]=["http://www.w3.org/ns/anno.jsonld","http://iiif.io/api/presentation/3/context.json"])),e},this.processUri=function(e){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=t.retrieveResource(e);return t.processResource(i,r)},this)"function"==typeof this[i]&&(this[i]=this[i].bind(this));var n=null;for(var a in FLAGS)this[(n=FLAGS[a]).prop]=r.hasOwnProperty(a)?r[a]:n.default;this.idTypeHash={}}return _createClass(e,[{key:"doLanguageMap",value:function(e){var t={},r=this.default_lang;return"string"==typeof e?t[r]=[e]:isDictionary(e)?(t.hasOwnProperty(e["@language"])||(t[e["@language"]]=[]),t[e["@language"]].push(e["@value"])):isArray(e)&&e.forEach((function(e){if(isDictionary(e)){var i=e["@language"]||"@none";t.hasOwnProperty(i)||(t[i]=[]),t[i].push(e["@value"])}else isArray(e)||(t.hasOwnProperty(r)||(t[r]=[]),t[r].push(e))})),t}}]),e}(),src=Upgrader;module.exports=src;
//# sourceMappingURL=/sm/14427a4e95c52ea26054c1098426f664730606252c55e340d357bb53b723f26d.map