Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@iiif/vault-helpers

Package Overview
Dependencies
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iiif/vault-helpers - npm Package Compare versions

Comparing version 0.9.10 to 0.9.11

.build/types/ranges.d.ts

2

.build/types/index.d.ts

@@ -9,1 +9,3 @@ export * from './events';

export * from './objects';
export * from './ranges';
export * from './sequences';

6

dist/cjs/index.js

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

"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function Jt(t){return{addEventListener(e,i,r,s){if(!!e)return t.setMetaValue([e.id,"eventManager",i],n=>{const o=n||[];for(const a of o)if(a.callback===r)return o;return[...o,{callback:r,scope:s}]}),r},removeEventListener(e,i,r){!e||t.setMetaValue([e.id,"eventManager",i],s=>(s||[]).filter(n=>n.callback!==r))},getListenersAsProps(e,i){const r=typeof e=="string"?{id:e}:e;if(!r||!r.id)return{};const s=t.getResourceMeta(r.id,"eventManager"),n={};if(s&&r)for(const o of Object.keys(s))n[o]=a=>{const c=t.get(r);for(const{callback:l,scope:f}of s[o]||[])(!f||i&&f.indexOf(i)!==-1)&&l(a,c)};return n}}}function Yt(t){return{applyStyles(e,i,r){const s=typeof e=="string"?e:e.id;return t.setMetaValue([s,"styles",i],r)},getAppliedStyles(e){const i=typeof e=="string"?e:e.id;return t.getResourceMeta(i,"styles")}}}function I(t){return t.endsWith("info.json")?t:t.endsWith("/")?`${t}info.json`:`${t}/info.json`}const Zt="http://library.stanford.edu/iiif/image-api/compliance.html#level0",ht="http://library.stanford.edu/iiif/image-api/compliance.html#level1",ut="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Kt="http://library.stanford.edu/iiif/image-api/conformance.html#level0",pt="http://library.stanford.edu/iiif/image-api/conformance.html#level1",dt="http://library.stanford.edu/iiif/image-api/conformance.html#level2",te="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",gt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",ee="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",mt="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",ie="http://iiif.io/api/image/1/level0.json",re="http://iiif.io/api/image/1/profiles/level0.json",vt="http://iiif.io/api/image/1/level1.json",bt="http://iiif.io/api/image/1/profiles/level1.json",wt="http://iiif.io/api/image/1/level2.json",St="http://iiif.io/api/image/1/profiles/level2.json",ne="http://iiif.io/api/image/2/level0.json",se="http://iiif.io/api/image/2/profiles/level0.json",At="http://iiif.io/api/image/2/level1.json",Ot="http://iiif.io/api/image/2/profiles/level1.json",kt="http://iiif.io/api/image/2/level2.json",Mt="http://iiif.io/api/image/2/profiles/level2.json",oe="level0",Ft="level1",Ct="level2",ae="http://iiif.io/api/image/2/level0",jt="http://iiif.io/api/image/2/level1",Tt="http://iiif.io/api/image/2/level2",Rt=[Tt,ut,dt,gt,xt,wt,St,kt,Mt,Ct],zt=[...Rt,jt,ht,pt,yt,mt,vt,bt,At,Ot,Ft],ce=[ae,jt,Tt,Zt,ht,ut,Kt,pt,dt,te,yt,gt,ee,mt,xt,ie,re,vt,bt,wt,St,ne,se,At,Ot,kt,Mt,oe,Ft,Ct],le={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},fe={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},he={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function ue(t){return Rt.indexOf(t)!==-1?he:zt.indexOf(t)!==-1?fe:le}function pe(t){const e=t?Array.isArray(t.profile)?t.profile:[t.profile]:[],i={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let r of e)if(typeof r=="string"&&(r=ue(r)),!!r){if(r.formats)for(const s of r.formats)i.extraFormats.indexOf(s)===-1&&i.extraFormats.push(s);if(r.qualities)for(const s of r.qualities)i.extraQualities.indexOf(s)===-1&&i.extraQualities.push(s);if(r.supports)for(const s of r.supports)i.extraFeatures.indexOf(s)===-1&&i.extraFeatures.push(s);if(r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea),r.extraFormats)for(const s of r.extraFormats)i.extraFormats.indexOf(s)===-1&&i.extraFormats.push(s);if(r.extraQualities)for(const s of r.extraQualities)i.extraQualities.indexOf(s)===-1&&i.extraQualities.push(s);if(r.extraFeatures)for(const s of r.extraFeatures)i.extraFeatures.indexOf(s)===-1&&i.extraFeatures.push(s);r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea)}if(t.extraFormats)for(const r of t.extraFormats)i.extraFormats.indexOf(r)===-1&&i.extraFormats.push(r);if(t.extraFeatures)for(const r of t.extraFeatures)i.extraFeatures.indexOf(r)===-1&&i.extraFeatures.push(r);if(t.extraQualities)for(const r of t.extraQualities)i.extraQualities.indexOf(r)===-1&&i.extraQualities.push(r);return i}function de(t){try{if(t==="full")return{full:!0};if(t==="square")return{square:!0};const e=t.startsWith("pct:"),i=t.substr(e?4:0).split(",").map(r=>parseFloat(r));return{x:i[0],y:i[1],w:i[2],h:i[3],percent:e}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+t)}}function ye(t){const e={upscaled:!1,max:!1,confined:!1};if(t[0]==="^"&&(e.upscaled=!0,t=t.slice(1)),t==="max"||t==="full")return e.max=!0,e.serialiseAsFull=t==="full",e;if(t[0]==="!"&&(e.confined=!0,t=t.slice(1)),t[0]==="p")return e.percentScale=parseFloat(t.slice(4)),e;const i=t.split(",").map(r=>r.trim());return i.length&&(i[0]!==""&&(e.width=parseInt(i[0],10)),i[1]!==""&&(e.height=parseInt(i[1],10))),e}function ge(t){const e={angle:0};if(t[0]==="!"&&(e.mirror=!0,t=t.substr(1)),e.angle=parseFloat(t)%360,Number.isNaN(e.angle))throw new Error(`Invalid rotation ${t}`);return e}function me(t,e=""){const i=t.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!i)throw new Error(`Invalid or unknown input ${t}`);const r=i[2],s=i[3];let n=i[4];if(n[0]==="/"&&(n=n.substr(1)),e.length>0){if(e[0]==="/"&&(e=e.substr(1)),e!==n.substr(0,e.length))throw new Error(`Path does not start with prefix (path: ${n}, prefix: ${e})`);n=n.substr(e.length)}return{scheme:r,server:s,path:n,prefix:e}}function xe(t,e=""){const{path:i,scheme:r,server:s,prefix:n}=me(t,e),o=i.split("/").reverse(),[a,c,l,f,...d]=o,y=d.reverse().filter(Boolean).join("/");if(o.length===1||a==="")return{type:"base",scheme:r,server:s,prefix:n,identifier:y};if(a==="info.json"){const[,...h]=o;return{type:"info",scheme:r,server:s,prefix:n,identifier:h.reverse().filter(Boolean).join("/")}}const p=a.split(".");return{type:"image",scheme:r,server:s,prefix:n,identifier:y,originalPath:i,region:de(f),size:ye(l),rotation:ge(c),quality:p[0],format:p[1]}}function ve(t){const e=xe(I(t.id));if(e.type!=="info")throw new Error("Invalid service URL");const i=pe(t);return{identifier:e.identifier,originalPath:"",server:e.server,prefix:e.prefix,scheme:e.scheme,type:"image",quality:i.extraQualities.indexOf("default")===-1?i.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}}function be(t,e,i){const r=i.length,s=[];for(let n=0;n<r;n++){const o=i[n].width;s.push(t/o)}return s}function we(t,e,i){const r=i.length,s=[];for(let n=0;n<r;n++){const o=i[n];s.push({width:Math.floor(t/o),height:Math.floor(e/o)})}return s}function A(t){if(t["@id"])return t["@id"];if(t.id)return t.id}function J(t){if(!t||!t.profile||!A(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if(typeof i=="string"&&ce.indexOf(i)!==-1)return!0;return!1}function Se(t){if(!J(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if(typeof i=="string"){if(zt.indexOf(i)!==-1)return!0}else{const r=[...i.supports||[],...i.extraFeatures||[]];if(r.indexOf("regionByPx")!==-1&&(r.indexOf("sizeByW")!==-1||r.indexOf("sizeByWh")!==-1))return!0}return!1}function Ae(t){if(!Se(t))return[];const e=[],i=Array.isArray(t.profile)?t.profile:[t.profile],r=i.length;for(let s=0;s<r;s++){const n=i[s];if(typeof n!="string"&&(n.maxHeight||n.maxWidth))return[{id:A(t),type:"variable",minWidth:0,minHeight:0,maxHeight:n.maxHeight||n.maxWidth,maxWidth:n.maxWidth||n.maxHeight}]}if(t.tiles){const s=t.tiles.length;for(let n=0;n<s;n++){const o=t.tiles[n];(o.height||o.width)&&e.push({id:A(t),type:"variable",minHeight:0,minWidth:0,maxHeight:o.height||o.width,maxWidth:o.width})}}return e}function it(t){const e=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,i=t.match(e);if(i){const r=i[1],s=parseInt(i[4],10),n=parseInt(i[5],10),o=i[7];if((r==="max"||r==="full")&&s&&n&&o)return{type:"fixed",id:t,height:n,width:s}}return{type:"unknown",id:t}}function Oe(t){if(t["@type"])return t["@type"];if(t.type)return t.type}function X(t){if(typeof t=="string")return it(t);const e=Oe(t);if(e!=="Image"&&e!=="sc:Image")return null;const i=t,r=A(i);return r?r&&i.width&&i.height?{id:r,type:"fixed",width:i.width,height:i.height,unsafe:!0}:it(r):null}function ke(t){return J(t)?(t&&t.sizes?t.sizes:[]).map(e=>({id:A(t),type:"fixed-service",height:e.height,width:e.width})):[]}function rt(t){const e=[],i=t.length;for(let r=0;r<i;r++){const s=ke(t[r]);s.length&&e.push(...s);const n=Ae(t[r]);n.length&&e.push(...n)}return e}function It(t){const e=t.service?Array.isArray(t.service)?t.service:[t.service]:[],i=e.length,r=[];for(let s=0;s<i;s++)J(e[s])&&r.push(e[s]);return r}function Me(t,e=!0,i){const r=[],s=X(t);if(s===null)return r;const n=t;if(r.push(s),e&&n.width&&n.height){const o=[],a=It(n);for(const c of a){const l={id:A(c),width:n.width,height:n.height};if(i.canLoadSync(l)){const f=i.loadServiceSync(l);f&&(f.height||(f.height=n.height),f.width||(f.width=n.width),o.push(...rt([f])))}}if(o.length)return r.push(...o),r}return n.service&&r.push(...rt(n.service)),r}function Fe({x:t=0,y:e=0,w:i,h:r,full:s,square:n,percent:o}){if(s)return"full";if(n)return"square";if(typeof i>"u"||typeof r>"u")throw new Error("RegionParameter: invalid region");const a=`${t},${e},${i},${r}`;return o?`pct:${a}`:a}function Ce({max:t,percentScale:e,upscaled:i,confined:r,width:s,height:n,serialiseAsFull:o}){const a=[];return i&&a.push("^"),t?(a.push(o?"full":"max"),a.join("")):(r&&a.push("!"),e&&a.push(`pct:${e}`),s&&a.push(`${s}`),a.push(","),n&&a.push(`${n}`),a.join(""))}function je(t){return`${t.mirror?"!":""}${(t.angle||0)%360}`}var Te=Object.defineProperty,Re=Object.defineProperties,ze=Object.getOwnPropertyDescriptors,nt=Object.getOwnPropertySymbols,Ie=Object.prototype.hasOwnProperty,Pe=Object.prototype.propertyIsEnumerable,st=(t,e,i)=>e in t?Te(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,H=(t,e)=>{for(var i in e||(e={}))Ie.call(e,i)&&st(t,i,e[i]);if(nt)for(var i of nt(e))Pe.call(e,i)&&st(t,i,e[i]);return t},L=(t,e)=>Re(t,ze(e));function We(t,e){const i=t.prefix.startsWith("/")?t.prefix.substr(1):t.prefix,r=`${t.scheme}://${t.server}/${i?`${i}/`:""}${t.identifier}`;if(t.type==="base")return r;if(t.type==="info")return`${r}/info.json`;let{region:s,size:n,rotation:o,format:a,quality:c}=t;if(e){const l=e["@context"]?Array.isArray(e["@context"])?e["@context"]:[e["@context"]]:[],f=l.indexOf("http://iiif.io/api/image/2/context.json")!==-1,d=l.indexOf("http://iiif.io/api/image/3/context.json")!==-1;if((n.width===e.width&&!n.height||n.height===e.height&&!n.width||n.width===e.width&&n.height===e.height)&&(n=L(H({},n),{max:!0})),f&&(n.max&&!n.serialiseAsFull&&(n=L(H({},n),{serialiseAsFull:!0})),!n.max&&n.width&&n.height&&(n=L(H({},n),{height:void 0}))),d&&(n.max&&n.serialiseAsFull&&(n=L(H({},n),{serialiseAsFull:!1})),n.width&&!n.height&&e.width&&e.height)){const y=e.height/e.width;n=L(H({},n),{height:Math.ceil(n.width*y)})}}return[r,Fe(s),Ce(n),je(o),`${c}.${a}`].filter(Boolean).join("/")}function V(t,e,i){const r=ve({id:I(A(t)),profile:"level2",type:"ImageService2"});if(r.type!=="image")throw new Error("Invalid service");return r.size.max=!1,r.size.width=e,r.size.height=i,{id:We(r),type:"fixed",width:e,height:i||t.height/(t.width||1)*e,unsafe:t.width>e}}function W(t){const e=t.replace(/(https?:\/\/)?(www.)?/i,"");return e.indexOf("/")!==-1?e.split("/")[0]:e}function Be(t,e,i){const r=t.width?t.width:t.maxWidth;return i.height<=t.maxHeight&&i.width<=t.maxWidth&&i.height>=t.minHeight&&i.width>=t.minWidth&&(!e||Math.abs(i.width-r)<Math.abs(e.width-r))}function qe(t,e){const i=[],r=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},t),s=[],n=[];let o=null;const a=(l,f)=>{if(Be(r,f,l)){if(r.preferFixedSize&&l.unsafe){n.push(l);return}r.returnAllOptions&&f&&n.push(f),o=l}else r.returnAllOptions&&n.push(l)},c=e.length;for(let l=0;l<c;l++){const f=e[l](),d=f.length;for(let y=0;y<d;y++){const p=f[y];if(p.type==="unknown"&&r.atAnyCost&&s.push(p),p.type==="fixed"&&(p.unsafe?s.push(p):a(p,o)),p.type==="fixed-service")if(r.unsafeImageService){const h=V(p,r.width,r.height);a(h,o)}else{const h=V(p,p.width,p.height);a(h,o)}if(p.type==="variable"&&p.maxWidth){const h=V({id:p.id,type:"fixed-service",width:p.maxWidth,height:p.maxWidth},p.maxWidth);a(h,o)}}if(o&&!r.returnAllOptions){if(o.unsafe||r.allowUnsafe)continue;break}}return r.atAnyCost&&n.length===0?{best:o||s[0],fallback:s.slice(1),log:i}:r.returnAllOptions?{best:r.atAnyCost?o||n[0]||s[0]:o||n[0],fallback:[...n,...s],log:i}:{best:o||n[0]||null,fallback:o?n:n.slice(1),log:i}}var $e=Object.defineProperty,He=Object.defineProperties,Le=Object.getOwnPropertyDescriptors,ot=Object.getOwnPropertySymbols,Qe=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable,at=(t,e,i)=>e in t?$e(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ee=(t,e)=>{for(var i in e||(e={}))Qe.call(e,i)&&at(t,i,e[i]);if(ot)for(var i of ot(e))_e.call(e,i)&&at(t,i,e[i]);return t},Ne=(t,e)=>He(t,Le(e));function Ve(t,e,i){const r=t>e?t:e,s=i.length,n=[];for(let o=0;o<s;o++){const a=i[o];let c=a.scaleFactors[0],l=r/c;const f=[c];for(;l>=a.width;)c=c*2,f.push(c),l=l/2;n.push(Ne(Ee({},a),{scaleFactors:f}))}return n}function Ue(t,e){if(t.length!==e.length)return!1;if(t.length===0&&e.length===0)return!0;const i=t.length;let r=!0;for(let n=0;n<i;n++){const o=t[n],a=e[n];if(o.width!==a.width||o.height!==a.height){r=!1;break}}if(r)return!0;let s=0;for(let n=0;n<i;n++)for(let o=0;o<i;o++)if(t[n].width===e[o].width&&t[n].height===e[o].height){s++;break}return s===i}function ct(t){if(t&&t.profile){const e=t.profile;if(e){const i=Array.isArray(e)?e:[e];return i.includes("level0")||i.includes("http://iiif.io/api/image/2/level0.json")||i.includes("http://iiif.io/api/image/1/level0.json")||i.includes("http://iiif.io/api/image/1/profiles/level0.json")}}return!1}var z=(t,e,i)=>new Promise((r,s)=>{var n=c=>{try{a(i.next(c))}catch(l){s(l)}},o=c=>{try{a(i.throw(c))}catch(l){s(l)}},a=c=>c.done?r(c.value):Promise.resolve(c.value).then(n,o);a((i=i.apply(t,e)).next())});class Pt{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(e){Object.assign(this.config,e)}sample(e,i,r=!0){const s=W(A(e)),n=I(A(e)),o=this.knownImageServers[s];return this.imageServices[n]=Object.assign(e,{real:!0}),!o&&e.tiles&&!ct(e)?(this.knownImageServers[s]={verifications:0,malformed:!1,root:s,preLoaded:r,sampledId:A(e),verified:!1,server:null,result:{context:e["@context"]||[],sampledProfile:e.profile,resourceServiceRatio:i&&e.height?i.height/e.height:1,sampledSizes:e.sizes||[],sizeRatios:be(e.width,e.height,e.sizes||[]),sampledTiles:e.tiles||[]}},!0):this.verify(e)}preLoad(e,i=!0){this.knownImageServers[e.root]=e,i&&(this.knownImageServers[e.root].malformed=!1,this.knownImageServers[e.root].verifications=this.config.verificationsRequired)}predict(e,i=!1,r=!1){const s=e==null?void 0:e.source,n=W(A(e)),o=this.knownImageServers[n];if(!o||!o.result||!r&&(o.malformed||o.verifications<this.config.verificationsRequired)||ct(e.source))return null;const a=I(A(e));return this.imageServices[a]||(this.imageServices[a]={"@context":o.result.context,"@id":A(e),id:A(e),protocol:"http://iiif.io/api/image",tiles:(s==null?void 0:s.tiles)||Ve(e.width,e.height,o.result.sampledTiles),sizes:(s==null?void 0:s.sizes)||we(Math.round(e.width/o.result.resourceServiceRatio),Math.round(e.height/o.result.resourceServiceRatio),o.result.sizeRatios),profile:(s==null?void 0:s.profile)||o.result.sampledProfile,height:(s==null?void 0:s.height)||e.height,width:(s==null?void 0:s.width)||e.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(e,i){return z(this,arguments,function*(r,s,n=!0,o=[]){const a=yield this.getImageCandidates(r,n);return qe(s,[()=>o,()=>a])})}getImageCandidates(e,i=!0){return z(this,null,function*(){const r=e;if(i&&r.height&&r.width){const s=It(r);for(const n of s){const o={id:A(n),width:n.width?n.width:r.width,height:n.height?n.height:r.height,source:n};yield this.loadService(o)}}return Me(e,i,this)})}verify(e){return z(this,null,function*(){const i=this.predict(e,!1,!0),r=yield this.fetchService(A(e));if(!i)return!1;const s=i.height===r.height&&i.width===r.width&&i["@context"]===r["@context"]&&Ue(i.sizes||[],r.sizes||[]);if(s){const n=W(A(e));this.knownImageServers[n].verifications+=1,this.knownImageServers[n].verifications>=this.config.verificationsRequired&&(this.knownImageServers[n].verified=!0)}return s})}canLoadSync(e){const i=typeof e=="string"?e:A(e),r=I(i);if(this.imageServices[r])return!0;const s=this.knownImageServers[W(i)];return s&&!s.malformed&&s.verifications>=this.config.verificationsRequired}markAsMalformed(e){return z(this,null,function*(){return this.knownImageServers[W(A(e))].malformed=!0,this.loadService(e,!0)})}fetchService(e,i=!1){return z(this,null,function*(){const r=I(e);if(this.imageServices[r]&&(!i||this.imageServices[r].real))return this.imageServices[r];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const s=yield this.fetch(r).then(n=>n.json());return!s.id&&s["@id"]&&(s.id=s["@id"]),s.id!==e&&(s.id=e,s["@id"]&&(s["@id"]=e)),this.imageServices[r]=Object.assign(s,{real:!0}),this.imageServices[r]})}fetch(e,i){return z(this,null,function*(){return fetch(e,i)})}loadService(e,i=!1){return z(this,null,function*(){if(!this.config.disableThrottling){let n=!0;for(;n;)if(this.fetchingCount>=this.config.verificationsRequired)yield new Promise(o=>setTimeout(o,500));else{n=!1;break}}const r=this.knownImageServers[W(A(e))];if(r&&!r.malformed&&!i){yield r.result;const n=this.loadServiceSync(e);if(n)return n}this.fetchingCount++;const s=yield this.fetchService(A(e),i);return this.fetchingCount--,s.real&&this.sample(s,e),s})}loadServiceSync(e){const i=I(A(e));return this.imageServices[i]?this.imageServices[i]:this.predict(e)}}new Pt;function De(t,e={}){const i=e.imageServiceLoader||new Pt;async function r(s,n,o,a=[],c){if(typeof s=="string")return{best:X(s),fallback:[],log:[]};const l=t.get(s);if(typeof l=="string")return{best:X(l),fallback:[],log:[]};switch(l.type){case"Annotation":{const f=l.body,d=t.get(f[0]);return c&&!d.width&&(d.width=c.width,d.height=c.height),await i.getThumbnailFromResource(d,n,o,a)}case"Canvas":{const f=l;if(f.thumbnail&&f.thumbnail.length){const d=t.get(f.thumbnail[0]),y=await i.getImageCandidates(d,o);y&&y.length&&a.push(...y)}return r(f.items[0],n,o,a,{width:f.width,height:f.height})}case"AnnotationPage":return r(l.items[0],n,o,a,c);case"Choice":return r(l.items[0],n,o,a,c);case"Collection":{const d=l.items[0];return r(d,n,o,a,c)}case"Manifest":{const d=l.items[0];return r(d,n,o,a,c)}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return c&&!l.width&&(l.width=c.width,l.height=c.height),i.getThumbnailFromResource(l,n,o,a);case"Service":case"Range":case"AnnotationCollection":case"CanvasReference":case"ContentResource":return{best:void 0,fallback:[],log:[]}}return{best:void 0,fallback:[],log:[]}}return{getBestThumbnailAtSize:r}}function Wt(t,e,i=[],r=!1){if(!t||!e||e.length===0)return;if(e.length===1)return e[0];if(e.indexOf(t)!==-1)return t;const s=t.indexOf("-")!==-1?t.slice(0,t.indexOf("-")):null;if(s&&e.indexOf(s)!==-1)return s;for(const n of i)if(e.indexOf(n)!==-1)return n;if(!r){const o=e.map(a=>a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null).indexOf(t);if(o!==-1)return e[o];for(const a of i){const c=a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null,l=c?e.indexOf(c):-1;if(l!==-1)return e[l]}}return e.indexOf("none")!==-1?"none":e.indexOf("@none")!==-1?"@none":e[0]}function Bt(t,e,i={}){const{strictFallback:r=!1,defaultText:s="",separator:n=`
`,fallbackLanguages:o=[],closest:a}=i,c=Object.keys(t||{}),l=a?e:Wt(e,c,o,r);if(!t)return s;if(typeof t=="string")return t;const f=l?t[l]:void 0;return f?typeof f=="string"?f:f.join(n):""}function Xe(t,e={}){return Bt(t,typeof navigator!="undefined"?navigator.language:void 0,e)}var Ge=function(){function t(e,i){var r=[],s=!0,n=!1,o=void 0;try{for(var a=e[Symbol.iterator](),c;!(s=(c=a.next()).done)&&(r.push(c.value),!(i&&r.length===i));s=!0);}catch(l){n=!0,o=l}finally{try{!s&&a.return&&a.return()}finally{if(n)throw o}}return r}return function(e,i){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,i);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),Q=Math.PI*2,U=function(e,i,r,s,n,o,a){var c=e.x,l=e.y;c*=i,l*=r;var f=s*c-n*l,d=n*c+s*l;return{x:f+o,y:d+a}},Je=function(e,i){var r=i===1.5707963267948966?.551915024494:i===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(i/4),s=Math.cos(e),n=Math.sin(e),o=Math.cos(e+i),a=Math.sin(e+i);return[{x:s-n*r,y:n+s*r},{x:o+a*r,y:a-o*r},{x:o,y:a}]},lt=function(e,i,r,s){var n=e*s-i*r<0?-1:1,o=e*r+i*s;return o>1&&(o=1),o<-1&&(o=-1),n*Math.acos(o)},Ye=function(e,i,r,s,n,o,a,c,l,f,d,y){var p=Math.pow(n,2),h=Math.pow(o,2),b=Math.pow(d,2),m=Math.pow(y,2),x=p*h-p*m-h*b;x<0&&(x=0),x/=p*m+h*b,x=Math.sqrt(x)*(a===c?-1:1);var u=x*n/o*y,g=x*-o/n*d,v=f*u-l*g+(e+r)/2,w=l*u+f*g+(i+s)/2,S=(d-u)/n,k=(y-g)/o,M=(-d-u)/n,F=(-y-g)/o,R=lt(1,0,S,k),C=lt(S,k,M,F);return c===0&&C>0&&(C-=Q),c===1&&C<0&&(C+=Q),[v,w,R,C]},Ze=function(e){var i=e.px,r=e.py,s=e.cx,n=e.cy,o=e.rx,a=e.ry,c=e.xAxisRotation,l=c===void 0?0:c,f=e.largeArcFlag,d=f===void 0?0:f,y=e.sweepFlag,p=y===void 0?0:y,h=[];if(o===0||a===0)return[];var b=Math.sin(l*Q/360),m=Math.cos(l*Q/360),x=m*(i-s)/2+b*(r-n)/2,u=-b*(i-s)/2+m*(r-n)/2;if(x===0&&u===0)return[];o=Math.abs(o),a=Math.abs(a);var g=Math.pow(x,2)/Math.pow(o,2)+Math.pow(u,2)/Math.pow(a,2);g>1&&(o*=Math.sqrt(g),a*=Math.sqrt(g));var v=Ye(i,r,s,n,o,a,d,p,b,m,x,u),w=Ge(v,4),S=w[0],k=w[1],M=w[2],F=w[3],R=Math.abs(F)/(Q/4);Math.abs(1-R)<1e-7&&(R=1);var C=Math.max(Math.ceil(R),1);F/=C;for(var Z=0;Z<C;Z++)h.push(Je(M,F)),M+=F;return h.map(function(N){var K=U(N[0],o,a,m,b,S,k),Nt=K.x,Vt=K.y,tt=U(N[1],o,a,m,b,S,k),Ut=tt.x,Dt=tt.y,et=U(N[2],o,a,m,b,S,k),Xt=et.x,Gt=et.y;return{x1:Nt,y1:Vt,x2:Ut,y2:Dt,x:Xt,y:Gt}})},Ke=ei,D={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},ti=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function ei(t){var e=[];return t.replace(ti,function(i,r,s){var n=r.toLowerCase();for(s=ri(s),n=="m"&&s.length>2&&(e.push([r].concat(s.splice(0,2))),n="l",r=r=="m"?"l":"L");;){if(s.length==D[n])return s.unshift(r),e.push(s);if(s.length<D[n])throw new Error("malformed path data");e.push([r].concat(s.splice(0,D[n])))}}),e}var ii=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function ri(t){var e=t.match(ii);return e?e.map(Number):[]}var ni=si;function si(t){var e=0,i=0,r=0,s=0;return t.map(function(n){n=n.slice();var o=n[0],a=o.toUpperCase();if(o!=a)switch(n[0]=a,o){case"a":n[6]+=r,n[7]+=s;break;case"v":n[1]+=s;break;case"h":n[1]+=r;break;default:for(var c=1;c<n.length;)n[c++]+=r,n[c++]+=s}switch(a){case"Z":r=e,s=i;break;case"H":r=n[1];break;case"V":s=n[1];break;case"M":r=e=n[1],s=i=n[2];break;default:r=n[n.length-2],s=n[n.length-1]}return n})}function oi(t){const e=Ke(t),i=ni(e);let r,s=0,n=0,o=0,a=0,c,l,f=0,d=0;const y=[];for(let p=0;p<i.length;p++){let h=i[p];const b=h[0];switch(b){case"M":s=h[1],n=h[2];break;case"H":h=["L",h[1],n];break;case"V":h=["L",s,h[1]];break;case"S":{let m=f,x=d;(r==="C"||r=="S")&&(m+=m-o,x+=x-a),h=["C",m,x,h[1],h[2],h[3],h[4]]}break;case"T":r==="Q"||r=="T"?(c=f*2-c,l=d*2-l):(c=f,l=d),h=["Q",c,l,h[1],h[2]];break;case"Q":c=h[1],l=h[2];break;case"A":{const m=Ze({px:f,py:d,cx:h[6],cy:h[7],rx:h[1],ry:h[2],xAxisRotation:h[3],largeArcFlag:h[4],sweepFlag:h[5]});if(!m.length)continue;for(const[x,u]of m.entries())h=["C",u.x1,u.y1,u.x2,u.y2,u.x,u.y],x<m.length-1&&y.push(h);h=h}break;case"Z":h=["L",s,n];break}r=b,f=h[h.length-2],d=h[h.length-1],["C","Q","A"].indexOf(b)>-1?(o=h[h.length-4],a=h[h.length-3]):(o=f,a=d),y.push(h)}return y}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function ie(t){return{addEventListener(e,i,r,s){if(!!e)return t.setMetaValue([e.id,"eventManager",i],n=>{const o=n||[];for(const a of o)if(a.callback===r)return o;return[...o,{callback:r,scope:s}]}),r},removeEventListener(e,i,r){!e||t.setMetaValue([e.id,"eventManager",i],s=>(s||[]).filter(n=>n.callback!==r))},getListenersAsProps(e,i){const r=typeof e=="string"?{id:e}:e;if(!r||!r.id)return{};const s=t.getResourceMeta(r.id,"eventManager"),n={};if(s&&r)for(const o of Object.keys(s))n[o]=a=>{const c=t.get(r);for(const{callback:l,scope:f}of s[o]||[])(!f||i&&f.indexOf(i)!==-1)&&l(a,c)};return n}}}function re(t){return{applyStyles(e,i,r){const s=typeof e=="string"?e:e.id;return t.setMetaValue([s,"styles",i],r)},getAppliedStyles(e){const i=typeof e=="string"?e:e.id;return t.getResourceMeta(i,"styles")}}}function z(t){return t.endsWith("info.json")?t:t.endsWith("/")?`${t}info.json`:`${t}/info.json`}const ne="http://library.stanford.edu/iiif/image-api/compliance.html#level0",gt="http://library.stanford.edu/iiif/image-api/compliance.html#level1",yt="http://library.stanford.edu/iiif/image-api/compliance.html#level2",se="http://library.stanford.edu/iiif/image-api/conformance.html#level0",mt="http://library.stanford.edu/iiif/image-api/conformance.html#level1",vt="http://library.stanford.edu/iiif/image-api/conformance.html#level2",oe="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",xt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",bt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",ae="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",wt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",St="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",ce="http://iiif.io/api/image/1/level0.json",le="http://iiif.io/api/image/1/profiles/level0.json",At="http://iiif.io/api/image/1/level1.json",Ft="http://iiif.io/api/image/1/profiles/level1.json",Mt="http://iiif.io/api/image/1/level2.json",Ot="http://iiif.io/api/image/1/profiles/level2.json",fe="http://iiif.io/api/image/2/level0.json",ue="http://iiif.io/api/image/2/profiles/level0.json",Ct="http://iiif.io/api/image/2/level1.json",kt="http://iiif.io/api/image/2/profiles/level1.json",Rt="http://iiif.io/api/image/2/level2.json",jt="http://iiif.io/api/image/2/profiles/level2.json",he="level0",It="level1",Tt="level2",pe="http://iiif.io/api/image/2/level0",zt="http://iiif.io/api/image/2/level1",Pt="http://iiif.io/api/image/2/level2",Wt=[Pt,yt,vt,bt,St,Mt,Ot,Rt,jt,Tt],qt=[...Wt,zt,gt,mt,xt,wt,At,Ft,Ct,kt,It],de=[pe,zt,Pt,ne,gt,yt,se,mt,vt,oe,xt,bt,ae,wt,St,ce,le,At,Ft,Mt,Ot,fe,ue,Ct,kt,Rt,jt,he,It,Tt],ge={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},ye={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},me={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function ve(t){return Wt.indexOf(t)!==-1?me:qt.indexOf(t)!==-1?ye:ge}function xe(t){const e=t?Array.isArray(t.profile)?t.profile:[t.profile]:[],i={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let r of e)if(typeof r=="string"&&(r=ve(r)),!!r){if(r.formats)for(const s of r.formats)i.extraFormats.indexOf(s)===-1&&i.extraFormats.push(s);if(r.qualities)for(const s of r.qualities)i.extraQualities.indexOf(s)===-1&&i.extraQualities.push(s);if(r.supports)for(const s of r.supports)i.extraFeatures.indexOf(s)===-1&&i.extraFeatures.push(s);if(r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea),r.extraFormats)for(const s of r.extraFormats)i.extraFormats.indexOf(s)===-1&&i.extraFormats.push(s);if(r.extraQualities)for(const s of r.extraQualities)i.extraQualities.indexOf(s)===-1&&i.extraQualities.push(s);if(r.extraFeatures)for(const s of r.extraFeatures)i.extraFeatures.indexOf(s)===-1&&i.extraFeatures.push(s);r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea)}if(t.extraFormats)for(const r of t.extraFormats)i.extraFormats.indexOf(r)===-1&&i.extraFormats.push(r);if(t.extraFeatures)for(const r of t.extraFeatures)i.extraFeatures.indexOf(r)===-1&&i.extraFeatures.push(r);if(t.extraQualities)for(const r of t.extraQualities)i.extraQualities.indexOf(r)===-1&&i.extraQualities.push(r);return i}function be(t){try{if(t==="full")return{full:!0};if(t==="square")return{square:!0};const e=t.startsWith("pct:"),i=t.substr(e?4:0).split(",").map(r=>parseFloat(r));return{x:i[0],y:i[1],w:i[2],h:i[3],percent:e}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+t)}}function we(t){const e={upscaled:!1,max:!1,confined:!1};if(t[0]==="^"&&(e.upscaled=!0,t=t.slice(1)),t==="max"||t==="full")return e.max=!0,e.serialiseAsFull=t==="full",e;if(t[0]==="!"&&(e.confined=!0,t=t.slice(1)),t[0]==="p")return e.percentScale=parseFloat(t.slice(4)),e;const i=t.split(",").map(r=>r.trim());return i.length&&(i[0]!==""&&(e.width=parseInt(i[0],10)),i[1]!==""&&(e.height=parseInt(i[1],10))),e}function Se(t){const e={angle:0};if(t[0]==="!"&&(e.mirror=!0,t=t.substr(1)),e.angle=parseFloat(t)%360,Number.isNaN(e.angle))throw new Error(`Invalid rotation ${t}`);return e}function Ae(t,e=""){const i=t.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!i)throw new Error(`Invalid or unknown input ${t}`);const r=i[2],s=i[3];let n=i[4];if(n[0]==="/"&&(n=n.substr(1)),e.length>0){if(e[0]==="/"&&(e=e.substr(1)),e!==n.substr(0,e.length))throw new Error(`Path does not start with prefix (path: ${n}, prefix: ${e})`);n=n.substr(e.length)}return{scheme:r,server:s,path:n,prefix:e}}function Fe(t,e=""){const{path:i,scheme:r,server:s,prefix:n}=Ae(t,e),o=i.split("/").reverse(),[a,c,l,f,...h]=o,g=h.reverse().filter(Boolean).join("/");if(o.length===1||a==="")return{type:"base",scheme:r,server:s,prefix:n,identifier:g};if(a==="info.json"){const[,...u]=o;return{type:"info",scheme:r,server:s,prefix:n,identifier:u.reverse().filter(Boolean).join("/")}}const p=a.split(".");return{type:"image",scheme:r,server:s,prefix:n,identifier:g,originalPath:i,region:be(f),size:we(l),rotation:Se(c),quality:p[0],format:p[1]}}function Me(t){const e=Fe(z(t.id));if(e.type!=="info")throw new Error("Invalid service URL");const i=xe(t);return{identifier:e.identifier,originalPath:"",server:e.server,prefix:e.prefix,scheme:e.scheme,type:"image",quality:i.extraQualities.indexOf("default")===-1?i.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}}function Oe(t,e,i){const r=i.length,s=[];for(let n=0;n<r;n++){const o=i[n].width;s.push(t/o)}return s}function Ce(t,e,i){const r=i.length,s=[];for(let n=0;n<r;n++){const o=i[n];s.push({width:Math.floor(t/o),height:Math.floor(e/o)})}return s}function A(t){if(t["@id"])return t["@id"];if(t.id)return t.id}function Z(t){if(!t||!t.profile||!A(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if(typeof i=="string"&&de.indexOf(i)!==-1)return!0;return!1}function ke(t){if(!Z(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if(typeof i=="string"){if(qt.indexOf(i)!==-1)return!0}else{const r=[...i.supports||[],...i.extraFeatures||[]];if(r.indexOf("regionByPx")!==-1&&(r.indexOf("sizeByW")!==-1||r.indexOf("sizeByWh")!==-1))return!0}return!1}function Re(t){if(!ke(t))return[];const e=[],i=Array.isArray(t.profile)?t.profile:[t.profile],r=i.length;for(let s=0;s<r;s++){const n=i[s];if(typeof n!="string"&&(n.maxHeight||n.maxWidth))return[{id:A(t),type:"variable",minWidth:0,minHeight:0,maxHeight:n.maxHeight||n.maxWidth,maxWidth:n.maxWidth||n.maxHeight}]}if(t.tiles){const s=t.tiles.length;for(let n=0;n<s;n++){const o=t.tiles[n];(o.height||o.width)&&e.push({id:A(t),type:"variable",minHeight:0,minWidth:0,maxHeight:o.height||o.width,maxWidth:o.width})}}return e}function ot(t){const e=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,i=t.match(e);if(i){const r=i[1],s=parseInt(i[4],10),n=parseInt(i[5],10),o=i[7];if((r==="max"||r==="full")&&s&&n&&o)return{type:"fixed",id:t,height:n,width:s}}return{type:"unknown",id:t}}function je(t){if(t["@type"])return t["@type"];if(t.type)return t.type}function J(t){if(typeof t=="string")return ot(t);const e=je(t);if(e!=="Image"&&e!=="sc:Image")return null;const i=t,r=A(i);return r?r&&i.width&&i.height?{id:r,type:"fixed",width:i.width,height:i.height,unsafe:!0}:ot(r):null}function Ie(t){return Z(t)?(t&&t.sizes?t.sizes:[]).map(e=>({id:A(t),type:"fixed-service",height:e.height,width:e.width})):[]}function at(t){const e=[],i=t.length;for(let r=0;r<i;r++){const s=Ie(t[r]);s.length&&e.push(...s);const n=Re(t[r]);n.length&&e.push(...n)}return e}function Bt(t){const e=t.service?Array.isArray(t.service)?t.service:[t.service]:[],i=e.length,r=[];for(let s=0;s<i;s++)Z(e[s])&&r.push(e[s]);return r}function Te(t,e=!0,i){const r=[],s=J(t);if(s===null)return r;const n=t;if(r.push(s),e&&n.width&&n.height){const o=[],a=Bt(n);for(const c of a){const l={id:A(c),width:n.width,height:n.height};if(i.canLoadSync(l)){const f=i.loadServiceSync(l);f&&(f.height||(f.height=n.height),f.width||(f.width=n.width),o.push(...at([f])))}}if(o.length)return r.push(...o),r}return n.service&&r.push(...at(n.service)),r}function ze({x:t=0,y:e=0,w:i,h:r,full:s,square:n,percent:o}){if(s)return"full";if(n)return"square";if(typeof i>"u"||typeof r>"u")throw new Error("RegionParameter: invalid region");const a=`${t},${e},${i},${r}`;return o?`pct:${a}`:a}function Pe({max:t,percentScale:e,upscaled:i,confined:r,width:s,height:n,serialiseAsFull:o}){const a=[];return i&&a.push("^"),t?(a.push(o?"full":"max"),a.join("")):(r&&a.push("!"),e&&a.push(`pct:${e}`),s&&a.push(`${s}`),a.push(","),n&&a.push(`${n}`),a.join(""))}function We(t){return`${t.mirror?"!":""}${(t.angle||0)%360}`}var qe=Object.defineProperty,Be=Object.defineProperties,$e=Object.getOwnPropertyDescriptors,ct=Object.getOwnPropertySymbols,He=Object.prototype.hasOwnProperty,Le=Object.prototype.propertyIsEnumerable,lt=(t,e,i)=>e in t?qe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,H=(t,e)=>{for(var i in e||(e={}))He.call(e,i)&&lt(t,i,e[i]);if(ct)for(var i of ct(e))Le.call(e,i)&&lt(t,i,e[i]);return t},L=(t,e)=>Be(t,$e(e));function Qe(t,e){const i=t.prefix.startsWith("/")?t.prefix.substr(1):t.prefix,r=`${t.scheme}://${t.server}/${i?`${i}/`:""}${t.identifier}`;if(t.type==="base")return r;if(t.type==="info")return`${r}/info.json`;let{region:s,size:n,rotation:o,format:a,quality:c}=t;if(e){const l=e["@context"]?Array.isArray(e["@context"])?e["@context"]:[e["@context"]]:[],f=l.indexOf("http://iiif.io/api/image/2/context.json")!==-1,h=l.indexOf("http://iiif.io/api/image/3/context.json")!==-1;if((n.width===e.width&&!n.height||n.height===e.height&&!n.width||n.width===e.width&&n.height===e.height)&&(n=L(H({},n),{max:!0})),f&&(n.max&&!n.serialiseAsFull&&(n=L(H({},n),{serialiseAsFull:!0})),!n.max&&n.width&&n.height&&(n=L(H({},n),{height:void 0}))),h&&(n.max&&n.serialiseAsFull&&(n=L(H({},n),{serialiseAsFull:!1})),n.width&&!n.height&&e.width&&e.height)){const g=e.height/e.width;n=L(H({},n),{height:Math.ceil(n.width*g)})}}return[r,ze(s),Pe(n),We(o),`${c}.${a}`].filter(Boolean).join("/")}function D(t,e,i){const r=Me({id:z(A(t)),profile:"level2",type:"ImageService2"});if(r.type!=="image")throw new Error("Invalid service");return r.size.max=!1,r.size.width=e,r.size.height=i,{id:Qe(r),type:"fixed",width:e,height:i||t.height/(t.width||1)*e,unsafe:t.width>e}}function W(t){const e=t.replace(/(https?:\/\/)?(www.)?/i,"");return e.indexOf("/")!==-1?e.split("/")[0]:e}function _e(t,e,i){const r=t.width?t.width:t.maxWidth;return i.height<=t.maxHeight&&i.width<=t.maxWidth&&i.height>=t.minHeight&&i.width>=t.minWidth&&(!e||Math.abs(i.width-r)<Math.abs(e.width-r))}function Ne(t,e){const i=[],r=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},t),s=[],n=[];let o=null;const a=(l,f)=>{if(_e(r,f,l)){if(r.preferFixedSize&&l.unsafe){n.push(l);return}r.returnAllOptions&&f&&n.push(f),o=l}else r.returnAllOptions&&n.push(l)},c=e.length;for(let l=0;l<c;l++){const f=e[l](),h=f.length;for(let g=0;g<h;g++){const p=f[g];if(p.type==="unknown"&&r.atAnyCost&&s.push(p),p.type==="fixed"&&(p.unsafe?s.push(p):a(p,o)),p.type==="fixed-service")if(r.unsafeImageService){const u=D(p,r.width,r.height);a(u,o)}else{const u=D(p,p.width,p.height);a(u,o)}if(p.type==="variable"&&p.maxWidth){const u=D({id:p.id,type:"fixed-service",width:p.maxWidth,height:p.maxWidth},p.maxWidth);a(u,o)}}if(o&&!r.returnAllOptions){if(o.unsafe||r.allowUnsafe)continue;break}}return r.atAnyCost&&n.length===0?{best:o||s[0],fallback:s.slice(1),log:i}:r.returnAllOptions?{best:r.atAnyCost?o||n[0]||s[0]:o||n[0],fallback:[...n,...s],log:i}:{best:o||n[0]||null,fallback:o?n:n.slice(1),log:i}}var Ve=Object.defineProperty,Ee=Object.defineProperties,Ue=Object.getOwnPropertyDescriptors,ft=Object.getOwnPropertySymbols,De=Object.prototype.hasOwnProperty,Xe=Object.prototype.propertyIsEnumerable,ut=(t,e,i)=>e in t?Ve(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ge=(t,e)=>{for(var i in e||(e={}))De.call(e,i)&&ut(t,i,e[i]);if(ft)for(var i of ft(e))Xe.call(e,i)&&ut(t,i,e[i]);return t},Je=(t,e)=>Ee(t,Ue(e));function Ye(t,e,i){const r=t>e?t:e,s=i.length,n=[];for(let o=0;o<s;o++){const a=i[o];let c=a.scaleFactors[0],l=r/c;const f=[c];for(;l>=a.width;)c=c*2,f.push(c),l=l/2;n.push(Je(Ge({},a),{scaleFactors:f}))}return n}function Ze(t,e){if(t.length!==e.length)return!1;if(t.length===0&&e.length===0)return!0;const i=t.length;let r=!0;for(let n=0;n<i;n++){const o=t[n],a=e[n];if(o.width!==a.width||o.height!==a.height){r=!1;break}}if(r)return!0;let s=0;for(let n=0;n<i;n++)for(let o=0;o<i;o++)if(t[n].width===e[o].width&&t[n].height===e[o].height){s++;break}return s===i}function ht(t){if(t&&t.profile){const e=t.profile;if(e){const i=Array.isArray(e)?e:[e];return i.includes("level0")||i.includes("http://iiif.io/api/image/2/level0.json")||i.includes("http://iiif.io/api/image/1/level0.json")||i.includes("http://iiif.io/api/image/1/profiles/level0.json")}}return!1}var T=(t,e,i)=>new Promise((r,s)=>{var n=c=>{try{a(i.next(c))}catch(l){s(l)}},o=c=>{try{a(i.throw(c))}catch(l){s(l)}},a=c=>c.done?r(c.value):Promise.resolve(c.value).then(n,o);a((i=i.apply(t,e)).next())});class $t{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(e){Object.assign(this.config,e)}sample(e,i,r=!0){const s=W(A(e)),n=z(A(e)),o=this.knownImageServers[s];return this.imageServices[n]=Object.assign(e,{real:!0}),!o&&e.tiles&&!ht(e)?(this.knownImageServers[s]={verifications:0,malformed:!1,root:s,preLoaded:r,sampledId:A(e),verified:!1,server:null,result:{context:e["@context"]||[],sampledProfile:e.profile,resourceServiceRatio:i&&e.height?i.height/e.height:1,sampledSizes:e.sizes||[],sizeRatios:Oe(e.width,e.height,e.sizes||[]),sampledTiles:e.tiles||[]}},!0):this.verify(e)}preLoad(e,i=!0){this.knownImageServers[e.root]=e,i&&(this.knownImageServers[e.root].malformed=!1,this.knownImageServers[e.root].verifications=this.config.verificationsRequired)}predict(e,i=!1,r=!1){const s=e==null?void 0:e.source,n=W(A(e)),o=this.knownImageServers[n];if(!o||!o.result||!r&&(o.malformed||o.verifications<this.config.verificationsRequired)||ht(e.source))return null;const a=z(A(e));return this.imageServices[a]||(this.imageServices[a]={"@context":o.result.context,"@id":A(e),id:A(e),protocol:"http://iiif.io/api/image",tiles:(s==null?void 0:s.tiles)||Ye(e.width,e.height,o.result.sampledTiles),sizes:(s==null?void 0:s.sizes)||Ce(Math.round(e.width/o.result.resourceServiceRatio),Math.round(e.height/o.result.resourceServiceRatio),o.result.sizeRatios),profile:(s==null?void 0:s.profile)||o.result.sampledProfile,height:(s==null?void 0:s.height)||e.height,width:(s==null?void 0:s.width)||e.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(e,i){return T(this,arguments,function*(r,s,n=!0,o=[]){const a=yield this.getImageCandidates(r,n);return Ne(s,[()=>o,()=>a])})}getImageCandidates(e,i=!0){return T(this,null,function*(){const r=e;if(i&&r.height&&r.width){const s=Bt(r);for(const n of s){const o={id:A(n),width:n.width?n.width:r.width,height:n.height?n.height:r.height,source:n};yield this.loadService(o)}}return Te(e,i,this)})}verify(e){return T(this,null,function*(){const i=this.predict(e,!1,!0),r=yield this.fetchService(A(e));if(!i)return!1;const s=i.height===r.height&&i.width===r.width&&i["@context"]===r["@context"]&&Ze(i.sizes||[],r.sizes||[]);if(s){const n=W(A(e));this.knownImageServers[n].verifications+=1,this.knownImageServers[n].verifications>=this.config.verificationsRequired&&(this.knownImageServers[n].verified=!0)}return s})}canLoadSync(e){const i=typeof e=="string"?e:A(e),r=z(i);if(this.imageServices[r])return!0;const s=this.knownImageServers[W(i)];return s&&!s.malformed&&s.verifications>=this.config.verificationsRequired}markAsMalformed(e){return T(this,null,function*(){return this.knownImageServers[W(A(e))].malformed=!0,this.loadService(e,!0)})}fetchService(e,i=!1){return T(this,null,function*(){const r=z(e);if(this.imageServices[r]&&(!i||this.imageServices[r].real))return this.imageServices[r];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const s=yield this.fetch(r).then(n=>n.json());return!s.id&&s["@id"]&&(s.id=s["@id"]),s.id!==e&&(s.id=e,s["@id"]&&(s["@id"]=e)),this.imageServices[r]=Object.assign(s,{real:!0}),this.imageServices[r]})}fetch(e,i){return T(this,null,function*(){return fetch(e,i)})}loadService(e,i=!1){return T(this,null,function*(){if(!this.config.disableThrottling){let n=!0;for(;n;)if(this.fetchingCount>=this.config.verificationsRequired)yield new Promise(o=>setTimeout(o,500));else{n=!1;break}}const r=this.knownImageServers[W(A(e))];if(r&&!r.malformed&&!i){yield r.result;const n=this.loadServiceSync(e);if(n)return n}this.fetchingCount++;const s=yield this.fetchService(A(e),i);return this.fetchingCount--,s.real&&this.sample(s,e),s})}loadServiceSync(e){const i=z(A(e));return this.imageServices[i]?this.imageServices[i]:this.predict(e)}}new $t;function Ke(t,e={}){const i=e.imageServiceLoader||new $t;async function r(s,n,o,a=[],c){if(typeof s=="string")return{best:J(s),fallback:[],log:[]};const l=t.get(s);if(typeof l=="string")return{best:J(l),fallback:[],log:[]};switch(l.type){case"Annotation":{const f=l.body,h=t.get(f[0]);return c&&!h.width&&(h.width=c.width,h.height=c.height),await i.getThumbnailFromResource(h,n,o,a)}case"Canvas":{const f=l;if(f.thumbnail&&f.thumbnail.length){const h=t.get(f.thumbnail[0]),g=await i.getImageCandidates(h,o);g&&g.length&&a.push(...g)}return r(f.items[0],n,o,a,{width:f.width,height:f.height})}case"AnnotationPage":return r(l.items[0],n,o,a,c);case"Choice":return r(l.items[0],n,o,a,c);case"Collection":{const h=l.items[0];return r(h,n,o,a,c)}case"Manifest":{const h=l.items[0];return r(h,n,o,a,c)}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return c&&!l.width&&(l.width=c.width,l.height=c.height),i.getThumbnailFromResource(l,n,o,a);case"Service":case"Range":case"AnnotationCollection":case"CanvasReference":case"ContentResource":return{best:void 0,fallback:[],log:[]}}return{best:void 0,fallback:[],log:[]}}return{getBestThumbnailAtSize:r}}function Ht(t,e,i=[],r=!1){if(!t||!e||e.length===0)return;if(e.length===1)return e[0];if(e.indexOf(t)!==-1)return t;const s=t.indexOf("-")!==-1?t.slice(0,t.indexOf("-")):null;if(s&&e.indexOf(s)!==-1)return s;for(const n of i)if(e.indexOf(n)!==-1)return n;if(!r){const o=e.map(a=>a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null).indexOf(t);if(o!==-1)return e[o];for(const a of i){const c=a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null,l=c?e.indexOf(c):-1;if(l!==-1)return e[l]}}return e.indexOf("none")!==-1?"none":e.indexOf("@none")!==-1?"@none":e[0]}function Lt(t,e,i={}){const{strictFallback:r=!1,defaultText:s="",separator:n=`
`,fallbackLanguages:o=[],closest:a}=i,c=Object.keys(t||{}),l=a?e:Ht(e,c,o,r);if(!t)return s;if(typeof t=="string")return t;const f=l?t[l]:void 0;return f?typeof f=="string"?f:f.join(n):""}function ti(t,e={}){return Lt(t,typeof navigator!="undefined"?navigator.language:void 0,e)}var ei=function(){function t(e,i){var r=[],s=!0,n=!1,o=void 0;try{for(var a=e[Symbol.iterator](),c;!(s=(c=a.next()).done)&&(r.push(c.value),!(i&&r.length===i));s=!0);}catch(l){n=!0,o=l}finally{try{!s&&a.return&&a.return()}finally{if(n)throw o}}return r}return function(e,i){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,i);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),Q=Math.PI*2,X=function(e,i,r,s,n,o,a){var c=e.x,l=e.y;c*=i,l*=r;var f=s*c-n*l,h=n*c+s*l;return{x:f+o,y:h+a}},ii=function(e,i){var r=i===1.5707963267948966?.551915024494:i===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(i/4),s=Math.cos(e),n=Math.sin(e),o=Math.cos(e+i),a=Math.sin(e+i);return[{x:s-n*r,y:n+s*r},{x:o+a*r,y:a-o*r},{x:o,y:a}]},pt=function(e,i,r,s){var n=e*s-i*r<0?-1:1,o=e*r+i*s;return o>1&&(o=1),o<-1&&(o=-1),n*Math.acos(o)},ri=function(e,i,r,s,n,o,a,c,l,f,h,g){var p=Math.pow(n,2),u=Math.pow(o,2),m=Math.pow(h,2),v=Math.pow(g,2),x=p*u-p*v-u*m;x<0&&(x=0),x/=p*v+u*m,x=Math.sqrt(x)*(a===c?-1:1);var d=x*n/o*g,y=x*-o/n*h,b=f*d-l*y+(e+r)/2,w=l*d+f*y+(i+s)/2,S=(h-d)/n,M=(g-y)/o,O=(-h-d)/n,C=(-g-y)/o,I=pt(1,0,S,M),k=pt(S,M,O,C);return c===0&&k>0&&(k-=Q),c===1&&k<0&&(k+=Q),[b,w,I,k]},ni=function(e){var i=e.px,r=e.py,s=e.cx,n=e.cy,o=e.rx,a=e.ry,c=e.xAxisRotation,l=c===void 0?0:c,f=e.largeArcFlag,h=f===void 0?0:f,g=e.sweepFlag,p=g===void 0?0:g,u=[];if(o===0||a===0)return[];var m=Math.sin(l*Q/360),v=Math.cos(l*Q/360),x=v*(i-s)/2+m*(r-n)/2,d=-m*(i-s)/2+v*(r-n)/2;if(x===0&&d===0)return[];o=Math.abs(o),a=Math.abs(a);var y=Math.pow(x,2)/Math.pow(o,2)+Math.pow(d,2)/Math.pow(a,2);y>1&&(o*=Math.sqrt(y),a*=Math.sqrt(y));var b=ri(i,r,s,n,o,a,h,p,m,v,x,d),w=ei(b,4),S=w[0],M=w[1],O=w[2],C=w[3],I=Math.abs(C)/(Q/4);Math.abs(1-I)<1e-7&&(I=1);var k=Math.max(Math.ceil(I),1);C/=k;for(var it=0;it<k;it++)u.push(ii(O,C)),O+=C;return u.map(function(U){var rt=X(U[0],o,a,v,m,S,M),Jt=rt.x,Yt=rt.y,nt=X(U[1],o,a,v,m,S,M),Zt=nt.x,Kt=nt.y,st=X(U[2],o,a,v,m,S,M),te=st.x,ee=st.y;return{x1:Jt,y1:Yt,x2:Zt,y2:Kt,x:te,y:ee}})},si=ai,G={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},oi=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function ai(t){var e=[];return t.replace(oi,function(i,r,s){var n=r.toLowerCase();for(s=li(s),n=="m"&&s.length>2&&(e.push([r].concat(s.splice(0,2))),n="l",r=r=="m"?"l":"L");;){if(s.length==G[n])return s.unshift(r),e.push(s);if(s.length<G[n])throw new Error("malformed path data");e.push([r].concat(s.splice(0,G[n])))}}),e}var ci=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function li(t){var e=t.match(ci);return e?e.map(Number):[]}var fi=ui;function ui(t){var e=0,i=0,r=0,s=0;return t.map(function(n){n=n.slice();var o=n[0],a=o.toUpperCase();if(o!=a)switch(n[0]=a,o){case"a":n[6]+=r,n[7]+=s;break;case"v":n[1]+=s;break;case"h":n[1]+=r;break;default:for(var c=1;c<n.length;)n[c++]+=r,n[c++]+=s}switch(a){case"Z":r=e,s=i;break;case"H":r=n[1];break;case"V":s=n[1];break;case"M":r=e=n[1],s=i=n[2];break;default:r=n[n.length-2],s=n[n.length-1]}return n})}function hi(t){const e=si(t),i=fi(e);let r,s=0,n=0,o=0,a=0,c,l,f=0,h=0;const g=[];for(let p=0;p<i.length;p++){let u=i[p];const m=u[0];switch(m){case"M":s=u[1],n=u[2];break;case"H":u=["L",u[1],n];break;case"V":u=["L",s,u[1]];break;case"S":{let v=f,x=h;(r==="C"||r=="S")&&(v+=v-o,x+=x-a),u=["C",v,x,u[1],u[2],u[3],u[4]]}break;case"T":r==="Q"||r=="T"?(c=f*2-c,l=h*2-l):(c=f,l=h),u=["Q",c,l,u[1],u[2]];break;case"Q":c=u[1],l=u[2];break;case"A":{const v=ni({px:f,py:h,cx:u[6],cy:u[7],rx:u[1],ry:u[2],xAxisRotation:u[3],largeArcFlag:u[4],sweepFlag:u[5]});if(!v.length)continue;for(const[x,d]of v.entries())u=["C",d.x1,d.y1,d.x2,d.y2,d.x,d.y],x<v.length-1&&g.push(u);u=u}break;case"Z":u=["L",s,n];break}r=m,f=u[u.length-2],h=u[u.length-1],["C","Q","A"].indexOf(m)>-1?(o=u[u.length-4],a=u[u.length-3]):(o=f,a=h),g.push(u)}return g}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
*

@@ -32,3 +32,3 @@ * All code in this module is based on JavaScript code by Raph Levien, published on his blog at

* limitations under the License.
*/function ai(t,e,i,r=1){return new qt(t,e,i).subdivide(r)}function ci(t,e,i,r,s=1){return new Y(new Float64Array([t.x,t.y,e.x,e.y,i.x,i.y,r.x,r.y])).subdivide(s)}function li(t){return t.x*t.x+t.y*t.y}function _(t){return t/(1-.67+Math.pow(Math.pow(.67,4)+.25*t*t,.25))}function q(t){return t*(1-.39+Math.sqrt(.39*.39+.25*t*t))}class qt{constructor(e,i,r){this.start=e,this.control=i,this.end=r}eval(e){const i=1-e;return{x:this.start.x*i*i+2*this.control.x*i*e+this.end.x*e*e,y:this.start.y*i*i+2*this.control.y*i*e+this.end.y*e*e}}mapToBasic(){const{x:e,y:i}=this.start,{x:r,y:s}=this.control,{x:n,y:o}=this.end,a=2*r-e-n,c=2*s-i-o,l=(r-e)*a+(s-i)*c,f=(n-r)*a+(o-s)*c,d=(n-e)*c-(o-i)*a,y=l/d,p=f/d,h=Math.abs(d)/(Math.hypot(a,c)*Math.abs(p-y));return{x0:e,x2:n,scale:h,cross:d}}subdivide(e){const i=this.mapToBasic(),r=_(i.x0),s=_(i.x2),n=.5*Math.abs(s-r)*Math.sqrt(i.scale/e),o=Math.ceil(n),a=q(r),c=q(s),l=[0];for(let f=1;f<o;f++){const y=(q(r+(s-r)*f/o)-a)/(c-a);l.push(y)}return l.push(1),l.map(f=>this.eval(f))}}class Y{constructor(e){this.c=e}weightsum(e,i,r,s){const n=e*this.c[0]+i*this.c[2]+r*this.c[4]+s*this.c[6],o=e*this.c[1]+i*this.c[3]+r*this.c[5]+s*this.c[7];return{x:n,y:o}}eval(e){const i=1-e,r=i*i*i,s=3*i*i*e,n=3*i*e*e,o=e*e*e;return this.weightsum(r,s,n,o)}deriv(e){const i=1-e,r=-3*i*i,s=3*e*e,n=-6*e*i-r,o=6*e*i-s;return this.weightsum(r,n,o,s)}midpoint_quadbez(){const e=this.weightsum(-.25,.75,.75,-.25);return new qt({x:this.c[0],y:this.c[1]},e,{x:this.c[6],y:this.c[7]})}subsegment(e,i){const r=new Float64Array(8),s=this.eval(e),n=this.eval(i);r[0]=s.x,r[1]=s.y;const o=(i-e)/3,a=this.deriv(e);r[2]=s.x+o*a.x,r[3]=s.y+o*a.y;const c=this.deriv(i);return r[4]=n.x-o*c.x,r[5]=n.y-o*c.y,r[6]=n.x,r[7]=n.y,new Y(r)}subdivide(e){const i=.1*e,r=e-i,s=Math.sqrt(r),n=li(this.weightsum(1,-3,3,-1)),o=Math.ceil(Math.pow(n/(432*i*i),1/6)),a=[];let c=0;for(let h=0;h<o;h++){const b=h/o,m=(h+1)/o,x=this.subsegment(b,m).midpoint_quadbez(),u=x.mapToBasic(),g=_(u.x0),v=_(u.x2),w=Math.sqrt(u.scale);let S=Math.abs(v-g)*w;if(Math.sign(u.x0)!=Math.sign(u.x2)){const k=s/w,M=s*Math.abs(v-g)/_(k);S=Math.max(S,M)}a.push({quad:x,a0:g,a2:v,val:S}),c+=S}const l=.5*c/s,f=Math.ceil(l),d=[{x:this.c[0],y:this.c[1]}];let y=0,p=0;for(let h=1;h<f;h++){const b=c*h/f;for(;y+a[p].val<b;)y+=a[p].val,p++;const m=a[p].a0,x=a[p].a2,u=q(m),g=q(x),v=m+(x-m)*(b-y)/a[p].val,S=(q(v)-u)/(g-u);d.push(a[p].quad.eval(S))}return d.push({x:this.c[6],y:this.c[7]}),d}}const fi=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,hi=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,ft=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function E(t,{domParser:e,svgPreprocessor:i}={}){var r,s;if(Array.isArray(t))return t.reduce((n,o)=>{const{selector:a,selectors:c}=E(o);return a&&(n.selector||(n.selector=a),n.selectors.push(...c)),n},{selector:null,selectors:[]});if(!t)return{selector:null,selectors:[]};if(typeof t=="string"){const[n,o]=t.split("#");return o?E({type:"FragmentSelector",value:o}):{selector:null,selectors:[]}}if(t.type==="PointSelector"&&(t.t||t.t===0)){const n={type:"TemporalSelector",temporal:{startTime:t.t}};return{selector:n,selectors:[n]}}if(t.type==="FragmentSelector"){const n=fi.exec(t.value);if(n){const a={type:"BoxSelector",spatial:{unit:n[2]==="percent:"||n[2]==="pct:"?"percent":"pixel",x:parseFloat(n[3]),y:parseFloat(n[4]),width:parseFloat(n[5]),height:parseFloat(n[6])}};return{selector:a,selectors:[a]}}const o=t.value.match(hi);if(o){const a={type:"TemporalSelector",temporal:{startTime:o[4]?parseFloat(o[4]):0,endTime:o[7]?parseFloat(o[7]):void 0}};return{selector:a,selectors:[a]}}return{selector:null,selectors:[]}}if(t.type==="SvgSelector"&&"value"in t){e||(typeof window!="undefined"?e=new window.DOMParser:console.warn("No DOMParser available, cannot parse SVG selector, `points`, `spatial` and `style` will be unavailable and the SVG will not be normalized."));let n=[],o,a,c=(r=i==null?void 0:i(t.value))!=null?r:t.value,l;if(e){const d=e.parseFromString(t.value,"image/svg+xml").querySelector("svg");if(!d)return console.warn(`Illegal SVG selector: ${t.value}`),{selector:null,selectors:[]};const y=$t(d);y&&(n=y.points,l=y.shapeType,o=[Math.min(...n.map(p=>p[0])),Math.min(...n.map(p=>p[1])),Math.max(...n.map(p=>p[0])),Math.max(...n.map(p=>p[1]))],{style:a,svg:c}=(s=di(y.element))!=null?s:{svg:c})}const f={type:"SvgSelector",svg:c,svgShape:l,style:a,points:n.length?n:void 0,spatial:o?{unit:"pixel",x:o[0],y:o[1],width:o[2]-o[0],height:o[3]-o[1]}:void 0};return{selector:f,selectors:[f]}}return{selector:null,selectors:[]}}function ui(t){const e=t.map(r=>r[0]).reduce((r,s)=>(r[s]+=1,r),{C:0,Q:0,L:0,M:0}),i=new Set(t.map(r=>r[0]));if(e.C>0||e.Q>0)return"path";if(e.L>0&&(i.size===1||i.size===2&&i.has("M"))){if(e.L===4)return"rect";const r=t.slice(-1)[0];return t[0][0]==="M"&&r[0]==="L"&&r[1]==t[0][1]&&r[2]===t[0][2]||r[1]===0&&r[2]===0?"polygon":"polyline"}return"path"}function $t(t){var e,i,r,s,n,o,a,c,l,f,d,y,p,h,b,m,x;for(const u of Array.from(t.children))switch(u==null?void 0:u.tagName.toLowerCase()){case"g":{const g=$t(u);if(g)return g}continue;case"path":{const g=u.getAttribute("d");if(!g)continue;const v=oi(g);return{element:u,points:pi(v),shapeType:ui(v)}}case"circle":{const g=parseFloat((e=u.getAttribute("cx"))!=null?e:"0"),v=parseFloat((i=u.getAttribute("cy"))!=null?i:"0"),w=parseFloat((r=u.getAttribute("r"))!=null?r:"0");if(!w)continue;const S=[];for(let k=0;k<=360;k+=12){const M=k*Math.PI/180;S.push([g+w*Math.cos(M),v+w*Math.sin(M)])}return{element:u,points:S,shapeType:"circle"}}case"ellipse":{const g=parseFloat((s=u.getAttribute("cx"))!=null?s:"0"),v=parseFloat((n=u.getAttribute("cy"))!=null?n:"0"),w=parseFloat((o=u.getAttribute("rx"))!=null?o:"0"),S=parseFloat((a=u.getAttribute("ry"))!=null?a:"0");if(!w&&!S)continue;const k=[];for(let M=0;M<=360;M+=12){const F=Math.tan(M/360*Math.PI),R=w*(1-F**2)/(1+F**2),C=S*2*F/(1+F**2);k.push([g+R,v+C])}return{element:u,points:k,shapeType:"ellipse"}}case"line":{const g=parseFloat((c=u.getAttribute("x0"))!=null?c:"0"),v=parseFloat((l=u.getAttribute("y0"))!=null?l:"0"),w=parseFloat((f=u.getAttribute("x1"))!=null?f:"0"),S=parseFloat((d=u.getAttribute("y1"))!=null?d:"0");if(g===w&&v===S)continue;return{element:u,points:[[g,v],[w,S]],shapeType:"polyline"}}case"polygon":case"polyline":{const g=(p=(y=u.getAttribute("points"))==null?void 0:y.split(" ").map(w=>w.split(",").map(parseFloat)))!=null?p:[];if(!g.length)continue;let v="polyline";return u.tagName.toLowerCase()==="polygon"&&(g.push(g[0]),v="polygon"),{element:u,points:g,shapeType:v}}case"rect":{const g=parseFloat((h=u.getAttribute("x"))!=null?h:"0"),v=parseFloat((b=u.getAttribute("y"))!=null?b:"0"),w=parseFloat((m=u.getAttribute("width"))!=null?m:"0"),S=parseFloat((x=u.getAttribute("height"))!=null?x:"0");if(!w||!S)continue;return{element:u,points:[[g,v],[g+w,v],[g+w,v+S],[g,v+S],[g,v]],shapeType:"rect"}}default:continue}return null}function pi(t){var i;const e=[];for(let r=0;r<t.length;r++){const s=(i=e[e.length-1])!=null?i:[0,0],n=t[r];switch(n[0]){case"M":case"L":e.push([n[1],n[2]]);continue;case"C":e.push(...ci({x:s[0],y:s[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]},{x:n[5],y:n[6]}).map(o=>[o.x,o.y]).slice(1));continue;case"Q":e.push(...ai({x:s[0],y:s[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]}).map(o=>[o.x,o.y]).slice(1));continue}}return e}function di(t){const e={};if(t.hasAttribute("fill")?(e.fill=t.getAttribute("fill"),t.removeAttribute("fill")):t.style.fill&&(e.fill=t.style.fill),e.fill){const r=ft.exec(e.fill);r&&(e.fillOpacity=parseFloat(r[4]),e.fill=`rgb(${r[1]}, ${r[2]}, ${r[3]})`)}if(t.hasAttribute("fill-opacity")?(e.fillOpacity=parseFloat(t.getAttribute("fill-opacity")),t.removeAttribute("fill-opacity")):t.style.fillOpacity&&(e.fillOpacity=parseFloat(t.style.fillOpacity)),t.hasAttribute("stroke")?(e.stroke=t.getAttribute("stroke"),t.removeAttribute("stroke")):t.style.stroke&&(e.stroke=t.style.stroke),e.stroke){const r=ft.exec(e.stroke);r&&(e.strokeOpacity=parseFloat(r[4]),e.stroke=`rgb(${r[1]}, ${r[2]}, ${r[3]})`)}t.hasAttribute("stroke-opacity")?(e.strokeOpacity=parseFloat(t.getAttribute("stroke-opacity")),t.removeAttribute("stroke-opacity")):t.style.strokeOpacity&&(e.strokeOpacity=parseFloat(t.style.strokeOpacity)),t.hasAttribute("stroke-width")?(e.strokeWidth=t.getAttribute("stroke-width"),t.removeAttribute("stroke-width")):t.style.strokeWidth&&(e.strokeWidth=t.style.strokeWidth),t.hasAttribute("stroke-dasharray")?(e.strokeDasharray=t.getAttribute("stroke-dasharray"),t.removeAttribute("stroke-dasharray")):t.style.strokeDasharray&&(e.strokeDasharray=t.style.strokeDasharray);let i=t;for(;i.tagName.toLowerCase()!=="svg";)if(i=i.parentElement,i===null)throw new Error("Could not find root SVG element");return{svg:i.outerHTML,style:Object.keys(e).length>0?e:void 0}}function T(t,e={}){if(Array.isArray(t))return T(t[0]);if(typeof t=="string"){const[i,r]=t.split("#");return r?T({type:"SpecificResource",source:{id:i,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:i,type:e.typeMap&&e.typeMap[i]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return T(t.items[0]);if(t.type==="SpecificResource"){t.source.type==="Canvas"&&t.source.partOf&&typeof t.source.partOf=="string"&&(t.source.partOf=[{id:t.source.partOf,type:"Manifest"}]);const{selector:i,selectors:r}=t.selector?E(t.selector,e):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:i,selectors:r}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[i,r]=t.id.split("#");return r?T({type:"SpecificResource",source:{...t,id:i},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{...t,id:i},selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}function G(t,e=!1){if(typeof t=="string"){if(t.startsWith("{"))try{const i=JSON.parse(t);return G(i)}catch{return[!1,{reason:"Invalid JSON"}]}return[!0]}if(Array.isArray(t)){for(const i of t){const[r,s]=G(i);if(!r&&s)return[r,s]}return[!0]}return t.type==="Annotation"?[!0]:e&&t.type==="Canvas"&&!t.partOf?[!1,{reason:"Canvas without partOf cannot be loaded"}]:[!0]}function yi(t){return Lt(typeof t=="string"?t:JSON.stringify(t))}function Ht(t,e){if(t=t.trim(),t[0]==="{")return e?Promise.resolve(JSON.parse(t)):JSON.parse(t);if(t.startsWith("http")){if(!e)throw new Error("Cannot fetch remote fetch with async=false in parseContentState");return fetch(t).then(i=>i.json())}return Ht(Qt(t),e)}function Lt(t){const e=encodeURIComponent(t);return(typeof btoa=="undefined"?Buffer.from(e,"utf-8").toString("base64"):btoa(e)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function Qt(t){const i=gi(t).replace(/-/g,"+").replace(/_/g,"/"),r=typeof atob=="undefined"?Buffer.from(i,"base64").toString("utf-8"):atob(i);return decodeURIComponent(r).trim()}function gi(t){const e=t.length%4;if(e===1)throw new Error("InvalidLengthError: Input base64url string is the wrong length to determine padding");return t+(e?"====".slice(0,4-e):"")}function mi(t){if(!t)throw new Error("Content state is empty");Array.isArray(t)||(t=[t]);let e="vault://virtual-annotation/"+new Date().getTime();const i=[];for(const r of t){if(typeof r=="string")throw new Error("Content state is a [String] type and cannot be inferred");if(r.type==="Annotation"){if(e=r.id,Array.isArray(r.motivation))for(const n of r.motivation);if(Array.isArray(r.target))for(const n of r.target){const o=T(n);i.push(o)}else{const n=T(r.target);i.push(n)}continue}const s=T(r);i.push(s)}return{id:e,type:"Annotation",motivation:["contentState",...t.motivation||[]],target:i,extensions:{}}}function _t(t){return t.type==="SpecificResource"?[t.source,{selector:t.selector}]:[t,{selector:null}]}function xi(t){function e(s){const n=s?typeof s=="string"?t.get(s):s:null;if(!n)return[];const o=t.get(n.items),a=[];for(const c of o)a.push(...t.get(c.items));return a}function i(s,n=[]){const o=Array.isArray(s)?s:e(s),a=[];let c=null;const l=[];for(const f of o){if(f.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const d=t.get(f.body);for(const y of d){const[p,{selector:h}]=_t(y),b=(p.type||"unknown").toLowerCase();if(b==="choice"){const m=t.get(p.items),x=n.length?n.map(u=>m.find(g=>g.id===u)).filter(Boolean):[m[0]];x.length===0&&x.push(m[0]),c={type:"single-choice",items:m.map(u=>({id:u.id,label:u.label,selected:x.indexOf(u)!==-1})),label:y.label},d.push(...x);continue}a.indexOf(b)===-1&&a.push(b),l.push({type:b,resource:p,target:f.target,selector:h})}}return{types:a,items:l,choice:c}}function r(s){const{choice:n}=i(s);return n}return{getAllPaintingAnnotations:e,getPaintables:i,extractChoices:r}}function O(t,e,i){e[$]=e[$]||[],e[$].push(t),Object.defineProperty(e,t,{get(){if(typeof e[P][t]=="undefined")return;const r=e[P][t];return r&&j(i.get(e[P][t]),i)},set(r){e[P][t]!==r&&(this[P][t]=r)}})}const P=Symbol.for("_refs_"),B=Symbol.for("_reactive_"),$=Symbol.for("_defined_");function vi(t,e=!1){const i={id:null,[$]:[],[P]:{},[B]:null,is(r){return typeof r=="string"?this.id===r:r.id?r.id===this.id:!1},reactive(){if(!this[B])return this[B]=this.subscribe(()=>this.refresh(),!0),()=>{this.unreactive()}},refresh(){if(this.id){const r=this.unwrap();for(const s of Object.keys(r||{}))this[$].includes(s)?this[P][s]=r[s]:this[s]=r[s]}},unreactive(){this[B]&&(this[B](),this[B]=null)},unwrap(){if(!this.id)throw new Error("Invalid object");return t.get(this.id)},toPresentation3(){return t.toPresentation3(this.unwrap())},toPresentation2(){return t.toPresentation2(this.unwrap())},toJSON(){const r=this;return{...r,items:r.items,annotations:r.annotations,structures:r.structures,seeAlso:r.seeAlso,service:r.service,services:r.services,rendering:r.rendering,partOf:r.partOf,start:r.start,supplementary:r.supplementary,homepage:r.homepage,thumbnail:r.thumbnail,placeholderCanvas:r.placeholderCanvas,accompanyingCanvas:r.accompanyingCanvas,provider:r.provider}},subscribe(r,s=!0){return t.subscribe(()=>this.id?t.get(this.id):null,r,s)}};return O("items",i,t),O("annotations",i,t),O("structures",i,t),O("seeAlso",i,t),O("service",i,t),O("services",i,t),O("rendering",i,t),O("partOf",i,t),O("start",i,t),O("supplementary",i,t),O("homepage",i,t),O("thumbnail",i,t),O("placeholderCanvas",i,t),O("accompanyingCanvas",i,t),O("provider",i,t),O("body",i,t),O("logo",i,t),i}function Et(t){return Array.isArray(t)?t.map(e=>Et(e)):!t||!t.type?t:{id:t.id,type:t.type}}function j(t,e,i=!1){if(Array.isArray(t))return t.map(o=>j(o,e,i));if(!t||!t.type||!t.id)return t;const r=vi(e,i),s=Object.create(r),n=Object.assign(s,t);return i&&n.reactive(),n}function bi(t){return{get(e,i=!1){return j(t.get(e),t,i)},async load(e,i){return j(await t.load(e,i),t)},async loadManifest(e,i){return j(await t.loadManifest(e,i),t)},async loadCollection(e,i){return j(await t.loadCollection(e,i),t)},wrapObject(e){return j(t.get(e,{skipSelfReturn:!1}),t)},isWrapped(e){return!!e[$]}}}exports.buildLocaleString=Bt;exports.createEventsHelper=Jt;exports.createObjectsHelper=bi;exports.createPaintingAnnotationsHelper=xi;exports.createStylesHelper=Yt;exports.createThumbnailHelper=De;exports.decodeContentState=Qt;exports.encodeContentState=Lt;exports.expandTarget=T;exports.getClosestLanguage=Wt;exports.getValue=Xe;exports.normaliseContentState=mi;exports.parseContentState=Ht;exports.parseSelector=E;exports.parseSpecificResource=_t;exports.serialiseContentState=yi;exports.unwrapObject=Et;exports.validateContentState=G;exports.wrapObject=j;
*/function pi(t,e,i,r=1){return new Qt(t,e,i).subdivide(r)}function di(t,e,i,r,s=1){return new K(new Float64Array([t.x,t.y,e.x,e.y,i.x,i.y,r.x,r.y])).subdivide(s)}function gi(t){return t.x*t.x+t.y*t.y}function _(t){return t/(1-.67+Math.pow(Math.pow(.67,4)+.25*t*t,.25))}function B(t){return t*(1-.39+Math.sqrt(.39*.39+.25*t*t))}class Qt{constructor(e,i,r){this.start=e,this.control=i,this.end=r}eval(e){const i=1-e;return{x:this.start.x*i*i+2*this.control.x*i*e+this.end.x*e*e,y:this.start.y*i*i+2*this.control.y*i*e+this.end.y*e*e}}mapToBasic(){const{x:e,y:i}=this.start,{x:r,y:s}=this.control,{x:n,y:o}=this.end,a=2*r-e-n,c=2*s-i-o,l=(r-e)*a+(s-i)*c,f=(n-r)*a+(o-s)*c,h=(n-e)*c-(o-i)*a,g=l/h,p=f/h,u=Math.abs(h)/(Math.hypot(a,c)*Math.abs(p-g));return{x0:e,x2:n,scale:u,cross:h}}subdivide(e){const i=this.mapToBasic(),r=_(i.x0),s=_(i.x2),n=.5*Math.abs(s-r)*Math.sqrt(i.scale/e),o=Math.ceil(n),a=B(r),c=B(s),l=[0];for(let f=1;f<o;f++){const g=(B(r+(s-r)*f/o)-a)/(c-a);l.push(g)}return l.push(1),l.map(f=>this.eval(f))}}class K{constructor(e){this.c=e}weightsum(e,i,r,s){const n=e*this.c[0]+i*this.c[2]+r*this.c[4]+s*this.c[6],o=e*this.c[1]+i*this.c[3]+r*this.c[5]+s*this.c[7];return{x:n,y:o}}eval(e){const i=1-e,r=i*i*i,s=3*i*i*e,n=3*i*e*e,o=e*e*e;return this.weightsum(r,s,n,o)}deriv(e){const i=1-e,r=-3*i*i,s=3*e*e,n=-6*e*i-r,o=6*e*i-s;return this.weightsum(r,n,o,s)}midpoint_quadbez(){const e=this.weightsum(-.25,.75,.75,-.25);return new Qt({x:this.c[0],y:this.c[1]},e,{x:this.c[6],y:this.c[7]})}subsegment(e,i){const r=new Float64Array(8),s=this.eval(e),n=this.eval(i);r[0]=s.x,r[1]=s.y;const o=(i-e)/3,a=this.deriv(e);r[2]=s.x+o*a.x,r[3]=s.y+o*a.y;const c=this.deriv(i);return r[4]=n.x-o*c.x,r[5]=n.y-o*c.y,r[6]=n.x,r[7]=n.y,new K(r)}subdivide(e){const i=.1*e,r=e-i,s=Math.sqrt(r),n=gi(this.weightsum(1,-3,3,-1)),o=Math.ceil(Math.pow(n/(432*i*i),1/6)),a=[];let c=0;for(let u=0;u<o;u++){const m=u/o,v=(u+1)/o,x=this.subsegment(m,v).midpoint_quadbez(),d=x.mapToBasic(),y=_(d.x0),b=_(d.x2),w=Math.sqrt(d.scale);let S=Math.abs(b-y)*w;if(Math.sign(d.x0)!=Math.sign(d.x2)){const M=s/w,O=s*Math.abs(b-y)/_(M);S=Math.max(S,O)}a.push({quad:x,a0:y,a2:b,val:S}),c+=S}const l=.5*c/s,f=Math.ceil(l),h=[{x:this.c[0],y:this.c[1]}];let g=0,p=0;for(let u=1;u<f;u++){const m=c*u/f;for(;g+a[p].val<m;)g+=a[p].val,p++;const v=a[p].a0,x=a[p].a2,d=B(v),y=B(x),b=v+(x-v)*(m-g)/a[p].val,S=(B(b)-d)/(y-d);h.push(a[p].quad.eval(S))}return h.push({x:this.c[6],y:this.c[7]}),h}}const yi=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,mi=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,dt=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function N(t,{domParser:e,svgPreprocessor:i}={}){var r,s;if(Array.isArray(t))return t.reduce((n,o)=>{const{selector:a,selectors:c}=N(o);return a&&(n.selector||(n.selector=a),n.selectors.push(...c)),n},{selector:null,selectors:[]});if(!t)return{selector:null,selectors:[]};if(typeof t=="string"){const[n,o]=t.split("#");return o?N({type:"FragmentSelector",value:o}):{selector:null,selectors:[]}}if(t.type==="PointSelector"&&(t.t||t.t===0)){const n={type:"TemporalSelector",temporal:{startTime:t.t}};return{selector:n,selectors:[n]}}if(t.type==="FragmentSelector"){const n=yi.exec(t.value);if(n){const a={type:"BoxSelector",spatial:{unit:n[2]==="percent:"||n[2]==="pct:"?"percent":"pixel",x:parseFloat(n[3]),y:parseFloat(n[4]),width:parseFloat(n[5]),height:parseFloat(n[6])}};return{selector:a,selectors:[a]}}const o=t.value.match(mi);if(o){const a={type:"TemporalSelector",temporal:{startTime:o[4]?parseFloat(o[4]):0,endTime:o[7]?parseFloat(o[7]):void 0}};return{selector:a,selectors:[a]}}return{selector:null,selectors:[]}}if(t.type==="SvgSelector"&&"value"in t){e||(typeof window!="undefined"?e=new window.DOMParser:console.warn("No DOMParser available, cannot parse SVG selector, `points`, `spatial` and `style` will be unavailable and the SVG will not be normalized."));let n=[],o,a,c=(r=i==null?void 0:i(t.value))!=null?r:t.value,l;if(e){const h=e.parseFromString(t.value,"image/svg+xml").querySelector("svg");if(!h)return console.warn(`Illegal SVG selector: ${t.value}`),{selector:null,selectors:[]};const g=_t(h);g&&(n=g.points,l=g.shapeType,o=[Math.min(...n.map(p=>p[0])),Math.min(...n.map(p=>p[1])),Math.max(...n.map(p=>p[0])),Math.max(...n.map(p=>p[1]))],{style:a,svg:c}=(s=bi(g.element))!=null?s:{svg:c})}const f={type:"SvgSelector",svg:c,svgShape:l,style:a,points:n.length?n:void 0,spatial:o?{unit:"pixel",x:o[0],y:o[1],width:o[2]-o[0],height:o[3]-o[1]}:void 0};return{selector:f,selectors:[f]}}return{selector:null,selectors:[]}}function vi(t){const e=t.map(r=>r[0]).reduce((r,s)=>(r[s]+=1,r),{C:0,Q:0,L:0,M:0}),i=new Set(t.map(r=>r[0]));if(e.C>0||e.Q>0)return"path";if(e.L>0&&(i.size===1||i.size===2&&i.has("M"))){if(e.L===4)return"rect";const r=t.slice(-1)[0];return t[0][0]==="M"&&r[0]==="L"&&r[1]==t[0][1]&&r[2]===t[0][2]||r[1]===0&&r[2]===0?"polygon":"polyline"}return"path"}function _t(t){var e,i,r,s,n,o,a,c,l,f,h,g,p,u,m,v,x;for(const d of Array.from(t.children))switch(d==null?void 0:d.tagName.toLowerCase()){case"g":{const y=_t(d);if(y)return y}continue;case"path":{const y=d.getAttribute("d");if(!y)continue;const b=hi(y);return{element:d,points:xi(b),shapeType:vi(b)}}case"circle":{const y=parseFloat((e=d.getAttribute("cx"))!=null?e:"0"),b=parseFloat((i=d.getAttribute("cy"))!=null?i:"0"),w=parseFloat((r=d.getAttribute("r"))!=null?r:"0");if(!w)continue;const S=[];for(let M=0;M<=360;M+=12){const O=M*Math.PI/180;S.push([y+w*Math.cos(O),b+w*Math.sin(O)])}return{element:d,points:S,shapeType:"circle"}}case"ellipse":{const y=parseFloat((s=d.getAttribute("cx"))!=null?s:"0"),b=parseFloat((n=d.getAttribute("cy"))!=null?n:"0"),w=parseFloat((o=d.getAttribute("rx"))!=null?o:"0"),S=parseFloat((a=d.getAttribute("ry"))!=null?a:"0");if(!w&&!S)continue;const M=[];for(let O=0;O<=360;O+=12){const C=Math.tan(O/360*Math.PI),I=w*(1-C**2)/(1+C**2),k=S*2*C/(1+C**2);M.push([y+I,b+k])}return{element:d,points:M,shapeType:"ellipse"}}case"line":{const y=parseFloat((c=d.getAttribute("x0"))!=null?c:"0"),b=parseFloat((l=d.getAttribute("y0"))!=null?l:"0"),w=parseFloat((f=d.getAttribute("x1"))!=null?f:"0"),S=parseFloat((h=d.getAttribute("y1"))!=null?h:"0");if(y===w&&b===S)continue;return{element:d,points:[[y,b],[w,S]],shapeType:"polyline"}}case"polygon":case"polyline":{const y=(p=(g=d.getAttribute("points"))==null?void 0:g.split(" ").map(w=>w.split(",").map(parseFloat)))!=null?p:[];if(!y.length)continue;let b="polyline";return d.tagName.toLowerCase()==="polygon"&&(y.push(y[0]),b="polygon"),{element:d,points:y,shapeType:b}}case"rect":{const y=parseFloat((u=d.getAttribute("x"))!=null?u:"0"),b=parseFloat((m=d.getAttribute("y"))!=null?m:"0"),w=parseFloat((v=d.getAttribute("width"))!=null?v:"0"),S=parseFloat((x=d.getAttribute("height"))!=null?x:"0");if(!w||!S)continue;return{element:d,points:[[y,b],[y+w,b],[y+w,b+S],[y,b+S],[y,b]],shapeType:"rect"}}default:continue}return null}function xi(t){var i;const e=[];for(let r=0;r<t.length;r++){const s=(i=e[e.length-1])!=null?i:[0,0],n=t[r];switch(n[0]){case"M":case"L":e.push([n[1],n[2]]);continue;case"C":e.push(...di({x:s[0],y:s[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]},{x:n[5],y:n[6]}).map(o=>[o.x,o.y]).slice(1));continue;case"Q":e.push(...pi({x:s[0],y:s[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]}).map(o=>[o.x,o.y]).slice(1));continue}}return e}function bi(t){const e={};if(t.hasAttribute("fill")?(e.fill=t.getAttribute("fill"),t.removeAttribute("fill")):t.style.fill&&(e.fill=t.style.fill),e.fill){const r=dt.exec(e.fill);r&&(e.fillOpacity=parseFloat(r[4]),e.fill=`rgb(${r[1]}, ${r[2]}, ${r[3]})`)}if(t.hasAttribute("fill-opacity")?(e.fillOpacity=parseFloat(t.getAttribute("fill-opacity")),t.removeAttribute("fill-opacity")):t.style.fillOpacity&&(e.fillOpacity=parseFloat(t.style.fillOpacity)),t.hasAttribute("stroke")?(e.stroke=t.getAttribute("stroke"),t.removeAttribute("stroke")):t.style.stroke&&(e.stroke=t.style.stroke),e.stroke){const r=dt.exec(e.stroke);r&&(e.strokeOpacity=parseFloat(r[4]),e.stroke=`rgb(${r[1]}, ${r[2]}, ${r[3]})`)}t.hasAttribute("stroke-opacity")?(e.strokeOpacity=parseFloat(t.getAttribute("stroke-opacity")),t.removeAttribute("stroke-opacity")):t.style.strokeOpacity&&(e.strokeOpacity=parseFloat(t.style.strokeOpacity)),t.hasAttribute("stroke-width")?(e.strokeWidth=t.getAttribute("stroke-width"),t.removeAttribute("stroke-width")):t.style.strokeWidth&&(e.strokeWidth=t.style.strokeWidth),t.hasAttribute("stroke-dasharray")?(e.strokeDasharray=t.getAttribute("stroke-dasharray"),t.removeAttribute("stroke-dasharray")):t.style.strokeDasharray&&(e.strokeDasharray=t.style.strokeDasharray);let i=t;for(;i.tagName.toLowerCase()!=="svg";)if(i=i.parentElement,i===null)throw new Error("Could not find root SVG element");return{svg:i.outerHTML,style:Object.keys(e).length>0?e:void 0}}function j(t,e={}){if(Array.isArray(t))return j(t[0]);if(typeof t=="string"){const[i,r]=t.split("#");return r?j({type:"SpecificResource",source:{id:i,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:i,type:e.typeMap&&e.typeMap[i]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return j(t.items[0]);if(t.type==="SpecificResource"){t.source.type==="Canvas"&&t.source.partOf&&typeof t.source.partOf=="string"&&(t.source.partOf=[{id:t.source.partOf,type:"Manifest"}]);const{selector:i,selectors:r}=t.selector?N(t.selector,e):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:i,selectors:r}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[i,r]=t.id.split("#");return r?j({type:"SpecificResource",source:{...t,id:i},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{...t,id:i},selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}function Y(t,e=!1){if(typeof t=="string"){if(t.startsWith("{"))try{const i=JSON.parse(t);return Y(i)}catch{return[!1,{reason:"Invalid JSON"}]}return[!0]}if(Array.isArray(t)){for(const i of t){const[r,s]=Y(i);if(!r&&s)return[r,s]}return[!0]}return t.type==="Annotation"?[!0]:e&&t.type==="Canvas"&&!t.partOf?[!1,{reason:"Canvas without partOf cannot be loaded"}]:[!0]}function wi(t){return Vt(typeof t=="string"?t:JSON.stringify(t))}function Nt(t,e){if(t=t.trim(),t[0]==="{")return e?Promise.resolve(JSON.parse(t)):JSON.parse(t);if(t.startsWith("http")){if(!e)throw new Error("Cannot fetch remote fetch with async=false in parseContentState");return fetch(t).then(i=>i.json())}return Nt(Et(t),e)}function Vt(t){const e=encodeURIComponent(t);return(typeof btoa=="undefined"?Buffer.from(e,"utf-8").toString("base64"):btoa(e)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function Et(t){const i=Si(t).replace(/-/g,"+").replace(/_/g,"/"),r=typeof atob=="undefined"?Buffer.from(i,"base64").toString("utf-8"):atob(i);return decodeURIComponent(r).trim()}function Si(t){const e=t.length%4;if(e===1)throw new Error("InvalidLengthError: Input base64url string is the wrong length to determine padding");return t+(e?"====".slice(0,4-e):"")}function Ai(t){if(!t)throw new Error("Content state is empty");Array.isArray(t)||(t=[t]);let e="vault://virtual-annotation/"+new Date().getTime();const i=[];for(const r of t){if(typeof r=="string")throw new Error("Content state is a [String] type and cannot be inferred");if(r.type==="Annotation"){if(e=r.id,Array.isArray(r.motivation))for(const n of r.motivation);if(Array.isArray(r.target))for(const n of r.target){const o=j(n);i.push(o)}else{const n=j(r.target);i.push(n)}continue}const s=j(r);i.push(s)}return{id:e,type:"Annotation",motivation:["contentState",...t.motivation||[]],target:i,extensions:{}}}function Ut(t){return t.type==="SpecificResource"?[t.source,{selector:t.selector}]:[t,{selector:null}]}function Fi(t){function e(s){const n=s?typeof s=="string"?t.get(s):s:null;if(!n)return[];const o=t.get(n.items),a=[];for(const c of o)a.push(...t.get(c.items));return a}function i(s,n=[]){const o=Array.isArray(s)?s:e(s),a=[];let c=null;const l=[];for(const f of o){if(f.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const h=t.get(f.body);for(const g of h){const[p,{selector:u}]=Ut(g),m=(p.type||"unknown").toLowerCase();if(m==="choice"){const v=t.get(p.items),x=n.length?n.map(d=>v.find(y=>y.id===d)).filter(Boolean):[v[0]];x.length===0&&x.push(v[0]),c={type:"single-choice",items:v.map(d=>({id:d.id,label:d.label,selected:x.indexOf(d)!==-1})),label:g.label},h.push(...x);continue}a.indexOf(m)===-1&&a.push(m),l.push({type:m,resource:p,target:f.target,selector:u})}}return{types:a,items:l,choice:c}}function r(s){const{choice:n}=i(s);return n}return{getAllPaintingAnnotations:e,getPaintables:i,extractChoices:r}}function F(t,e,i){e[$]=e[$]||[],e[$].push(t),Object.defineProperty(e,t,{get(){if(typeof e[P][t]=="undefined")return;const r=e[P][t];return r&&R(i.get(e[P][t]),i)},set(r){e[P][t]!==r&&(this[P][t]=r)}})}const P=Symbol.for("_refs_"),q=Symbol.for("_reactive_"),$=Symbol.for("_defined_");function Mi(t,e=!1){const i={id:null,[$]:[],[P]:{},[q]:null,is(r){return typeof r=="string"?this.id===r:r.id?r.id===this.id:!1},reactive(){if(!this[q])return this[q]=this.subscribe(()=>this.refresh(),!0),()=>{this.unreactive()}},refresh(){if(this.id){const r=this.unwrap();for(const s of Object.keys(r||{}))this[$].includes(s)?this[P][s]=r[s]:this[s]=r[s]}},unreactive(){this[q]&&(this[q](),this[q]=null)},unwrap(){if(!this.id)throw new Error("Invalid object");return t.get(this.id)},toPresentation3(){return t.toPresentation3(this.unwrap())},toPresentation2(){return t.toPresentation2(this.unwrap())},toJSON(){const r=this;return{...r,items:r.items,annotations:r.annotations,structures:r.structures,seeAlso:r.seeAlso,service:r.service,services:r.services,rendering:r.rendering,partOf:r.partOf,start:r.start,supplementary:r.supplementary,homepage:r.homepage,thumbnail:r.thumbnail,placeholderCanvas:r.placeholderCanvas,accompanyingCanvas:r.accompanyingCanvas,provider:r.provider}},subscribe(r,s=!0){return t.subscribe(()=>this.id?t.get(this.id):null,r,s)}};return F("items",i,t),F("annotations",i,t),F("structures",i,t),F("seeAlso",i,t),F("service",i,t),F("services",i,t),F("rendering",i,t),F("partOf",i,t),F("start",i,t),F("supplementary",i,t),F("homepage",i,t),F("thumbnail",i,t),F("placeholderCanvas",i,t),F("accompanyingCanvas",i,t),F("provider",i,t),F("body",i,t),F("logo",i,t),i}function Dt(t){return Array.isArray(t)?t.map(e=>Dt(e)):!t||!t.type?t:{id:t.id,type:t.type}}function R(t,e,i=!1){if(Array.isArray(t))return t.map(o=>R(o,e,i));if(!t||!t.type||!t.id)return t;const r=Mi(e,i),s=Object.create(r),n=Object.assign(s,t);return i&&n.reactive(),n}function Oi(t){return{get(e,i=!1){return R(t.get(e),t,i)},async load(e,i){return R(await t.load(e,i),t)},async loadManifest(e,i){return R(await t.loadManifest(e,i),t)},async loadCollection(e,i){return R(await t.loadCollection(e,i),t)},wrapObject(e){return R(t.get(e,{skipSelfReturn:!1}),t)},isWrapped(e){return!!e[$]}}}function Ci(t){return{findFirstCanvasFromRange:e=>tt(t,e),findAllCanvasesInRange:e=>V(t,e),findManifestSelectedRange:(e,i)=>Xt(t,e,i),findSelectedRange:(e,i)=>E(t,e,i)}}function tt(t,e){for(const i of e.items){if(i.type==="Canvas")return i;if(i.type==="Range"){const r=tt(t,t.get(i));if(r)return r}}return null}function V(t,e){const i=[];for(const r of e.items)if(r.type==="Canvas"&&(r.id.indexOf("#")!==-1?i.push({id:r.id.split("#")[0],type:"Canvas"}):i.push(r)),r.type==="Range"&&i.push(...V(t,t.get(r))),r.type==="SpecificResource"){const s=typeof r.source=="string"?r.source:r.source.id;i.push({id:s,type:"Canvas"})}return i}function Xt(t,e,i){for(const r of e.structures){const s=E(t,t.get(r),i);if(s)return s}return null}function E(t,e,i){var r;for(const s of e.items){const n=(r=s.id)==null?void 0:r.split("#")[0];if(s.type==="SpecificResource"&&s.source===i||s.type==="Canvas"&&i===n)return e;if(s.type==="Range"){const o=E(t,t.get(s),i);if(o)return o}}return null}function ki(t){return{getVisibleCanvasesFromCanvasId:(e,i,r=!1)=>Gt(t,e,i,r),getManifestSequence:(e,i={})=>et(t,e,i)}}function Gt(t,e,i,r=!1){const s=e.behavior,n=i?t.get(i):null;if(!n)return[];const o=n.behavior,a=r?!1:s.includes("paged"),c=a?!1:s.includes("continuous"),l=a||c?!1:s.includes("individuals"),f=o.includes("facing-pages"),h=o.includes("non-paged");if(f||h||l||r)return[{id:n.id,type:"Canvas"}];const[g,p]=et(t,e);if(c)return g;const u=g.findIndex(m=>m.id===i);if(u===-1)return[];for(const m of p)if(m.includes(u))return m.map(v=>g[v]);return[{id:n.id,type:"Canvas"}]}function et(t,e,{disablePaging:i,skipNonPaged:r}={}){const s=e.behavior,n=s.includes("paged"),o=n?!1:s.includes("continuous"),a=n||o?!1:s.includes("individuals"),c=e.type==="Manifest"?e.items:V(t,e);if(o)return[c,[c.map((u,m)=>m)]];if(a||!n||i)return[c,c.map((u,m)=>[m])];const l=[];let f=[];const h=()=>{f.length&&(l.push([...f]),f=[])};let g=0,p=!1;for(let u=0;u<c.length;u++){const m=t.get(c[u]);if(m.behavior.includes("non-paged")){u===g&&g++,r||(h(),l.push([u]),h());continue}if(u===g||m.behavior.includes("facing-pages")){f.length&&(p=!0),h(),l.push([u]),h();continue}if(f.push(u),p){h(),p=!1;continue}f.length>1&&h()}return f.length&&h(),[c,l]}exports.buildLocaleString=Lt;exports.createEventsHelper=ie;exports.createObjectsHelper=Oi;exports.createPaintingAnnotationsHelper=Fi;exports.createRangeHelper=Ci;exports.createSequenceHelper=ki;exports.createStylesHelper=re;exports.createThumbnailHelper=Ke;exports.decodeContentState=Et;exports.encodeContentState=Vt;exports.expandTarget=j;exports.findAllCanvasesInRange=V;exports.findFirstCanvasFromRange=tt;exports.findManifestSelectedRange=Xt;exports.findSelectedRange=E;exports.getClosestLanguage=Ht;exports.getManifestSequence=et;exports.getValue=ti;exports.getVisibleCanvasesFromCanvasId=Gt;exports.normaliseContentState=Ai;exports.parseContentState=Nt;exports.parseSelector=N;exports.parseSpecificResource=Ut;exports.serialiseContentState=wi;exports.unwrapObject=Dt;exports.validateContentState=Y;exports.wrapObject=R;
//# sourceMappingURL=index.js.map

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

(function(A,L){typeof exports=="object"&&typeof module!="undefined"?L(exports):typeof define=="function"&&define.amd?define(["exports"],L):(A=typeof globalThis!="undefined"?globalThis:A||self,L(A.VaultHelpers={}))})(this,function(A){"use strict";function L(t){return{addEventListener(e,i,r,s){if(!!e)return t.setMetaValue([e.id,"eventManager",i],n=>{const o=n||[];for(const a of o)if(a.callback===r)return o;return[...o,{callback:r,scope:s}]}),r},removeEventListener(e,i,r){!e||t.setMetaValue([e.id,"eventManager",i],s=>(s||[]).filter(n=>n.callback!==r))},getListenersAsProps(e,i){const r=typeof e=="string"?{id:e}:e;if(!r||!r.id)return{};const s=t.getResourceMeta(r.id,"eventManager"),n={};if(s&&r)for(const o of Object.keys(s))n[o]=a=>{const c=t.get(r);for(const{callback:l,scope:f}of s[o]||[])(!f||i&&f.indexOf(i)!==-1)&&l(a,c)};return n}}}function Ut(t){return{applyStyles(e,i,r){const s=typeof e=="string"?e:e.id;return t.setMetaValue([s,"styles",i],r)},getAppliedStyles(e){const i=typeof e=="string"?e:e.id;return t.getResourceMeta(i,"styles")}}}function z(t){return t.endsWith("info.json")?t:t.endsWith("/")?`${t}info.json`:`${t}/info.json`}const Dt="http://library.stanford.edu/iiif/image-api/compliance.html#level0",tt="http://library.stanford.edu/iiif/image-api/compliance.html#level1",et="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Xt="http://library.stanford.edu/iiif/image-api/conformance.html#level0",it="http://library.stanford.edu/iiif/image-api/conformance.html#level1",rt="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Gt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",nt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",st="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Jt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",ot="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",at="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Yt="http://iiif.io/api/image/1/level0.json",Zt="http://iiif.io/api/image/1/profiles/level0.json",ct="http://iiif.io/api/image/1/level1.json",lt="http://iiif.io/api/image/1/profiles/level1.json",ft="http://iiif.io/api/image/1/level2.json",ht="http://iiif.io/api/image/1/profiles/level2.json",Kt="http://iiif.io/api/image/2/level0.json",te="http://iiif.io/api/image/2/profiles/level0.json",ut="http://iiif.io/api/image/2/level1.json",pt="http://iiif.io/api/image/2/profiles/level1.json",dt="http://iiif.io/api/image/2/level2.json",yt="http://iiif.io/api/image/2/profiles/level2.json",ee="level0",gt="level1",mt="level2",ie="http://iiif.io/api/image/2/level0",vt="http://iiif.io/api/image/2/level1",xt="http://iiif.io/api/image/2/level2",bt=[xt,et,rt,st,at,ft,ht,dt,yt,mt],wt=[...bt,vt,tt,it,nt,ot,ct,lt,ut,pt,gt],re=[ie,vt,xt,Dt,tt,et,Xt,it,rt,Gt,nt,st,Jt,ot,at,Yt,Zt,ct,lt,ft,ht,Kt,te,ut,pt,dt,yt,ee,gt,mt],ne={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},se={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},oe={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function ae(t){return bt.indexOf(t)!==-1?oe:wt.indexOf(t)!==-1?se:ne}function ce(t){const e=t?Array.isArray(t.profile)?t.profile:[t.profile]:[],i={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let r of e)if(typeof r=="string"&&(r=ae(r)),!!r){if(r.formats)for(const s of r.formats)i.extraFormats.indexOf(s)===-1&&i.extraFormats.push(s);if(r.qualities)for(const s of r.qualities)i.extraQualities.indexOf(s)===-1&&i.extraQualities.push(s);if(r.supports)for(const s of r.supports)i.extraFeatures.indexOf(s)===-1&&i.extraFeatures.push(s);if(r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea),r.extraFormats)for(const s of r.extraFormats)i.extraFormats.indexOf(s)===-1&&i.extraFormats.push(s);if(r.extraQualities)for(const s of r.extraQualities)i.extraQualities.indexOf(s)===-1&&i.extraQualities.push(s);if(r.extraFeatures)for(const s of r.extraFeatures)i.extraFeatures.indexOf(s)===-1&&i.extraFeatures.push(s);r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea)}if(t.extraFormats)for(const r of t.extraFormats)i.extraFormats.indexOf(r)===-1&&i.extraFormats.push(r);if(t.extraFeatures)for(const r of t.extraFeatures)i.extraFeatures.indexOf(r)===-1&&i.extraFeatures.push(r);if(t.extraQualities)for(const r of t.extraQualities)i.extraQualities.indexOf(r)===-1&&i.extraQualities.push(r);return i}function le(t){try{if(t==="full")return{full:!0};if(t==="square")return{square:!0};const e=t.startsWith("pct:"),i=t.substr(e?4:0).split(",").map(r=>parseFloat(r));return{x:i[0],y:i[1],w:i[2],h:i[3],percent:e}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+t)}}function fe(t){const e={upscaled:!1,max:!1,confined:!1};if(t[0]==="^"&&(e.upscaled=!0,t=t.slice(1)),t==="max"||t==="full")return e.max=!0,e.serialiseAsFull=t==="full",e;if(t[0]==="!"&&(e.confined=!0,t=t.slice(1)),t[0]==="p")return e.percentScale=parseFloat(t.slice(4)),e;const i=t.split(",").map(r=>r.trim());return i.length&&(i[0]!==""&&(e.width=parseInt(i[0],10)),i[1]!==""&&(e.height=parseInt(i[1],10))),e}function he(t){const e={angle:0};if(t[0]==="!"&&(e.mirror=!0,t=t.substr(1)),e.angle=parseFloat(t)%360,Number.isNaN(e.angle))throw new Error(`Invalid rotation ${t}`);return e}function ue(t,e=""){const i=t.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!i)throw new Error(`Invalid or unknown input ${t}`);const r=i[2],s=i[3];let n=i[4];if(n[0]==="/"&&(n=n.substr(1)),e.length>0){if(e[0]==="/"&&(e=e.substr(1)),e!==n.substr(0,e.length))throw new Error(`Path does not start with prefix (path: ${n}, prefix: ${e})`);n=n.substr(e.length)}return{scheme:r,server:s,path:n,prefix:e}}function pe(t,e=""){const{path:i,scheme:r,server:s,prefix:n}=ue(t,e),o=i.split("/").reverse(),[a,c,l,f,...d]=o,y=d.reverse().filter(Boolean).join("/");if(o.length===1||a==="")return{type:"base",scheme:r,server:s,prefix:n,identifier:y};if(a==="info.json"){const[,...h]=o;return{type:"info",scheme:r,server:s,prefix:n,identifier:h.reverse().filter(Boolean).join("/")}}const p=a.split(".");return{type:"image",scheme:r,server:s,prefix:n,identifier:y,originalPath:i,region:le(f),size:fe(l),rotation:he(c),quality:p[0],format:p[1]}}function de(t){const e=pe(z(t.id));if(e.type!=="info")throw new Error("Invalid service URL");const i=ce(t);return{identifier:e.identifier,originalPath:"",server:e.server,prefix:e.prefix,scheme:e.scheme,type:"image",quality:i.extraQualities.indexOf("default")===-1?i.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}}function ye(t,e,i){const r=i.length,s=[];for(let n=0;n<r;n++){const o=i[n].width;s.push(t/o)}return s}function ge(t,e,i){const r=i.length,s=[];for(let n=0;n<r;n++){const o=i[n];s.push({width:Math.floor(t/o),height:Math.floor(e/o)})}return s}function O(t){if(t["@id"])return t["@id"];if(t.id)return t.id}function U(t){if(!t||!t.profile||!O(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if(typeof i=="string"&&re.indexOf(i)!==-1)return!0;return!1}function me(t){if(!U(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if(typeof i=="string"){if(wt.indexOf(i)!==-1)return!0}else{const r=[...i.supports||[],...i.extraFeatures||[]];if(r.indexOf("regionByPx")!==-1&&(r.indexOf("sizeByW")!==-1||r.indexOf("sizeByWh")!==-1))return!0}return!1}function ve(t){if(!me(t))return[];const e=[],i=Array.isArray(t.profile)?t.profile:[t.profile],r=i.length;for(let s=0;s<r;s++){const n=i[s];if(typeof n!="string"&&(n.maxHeight||n.maxWidth))return[{id:O(t),type:"variable",minWidth:0,minHeight:0,maxHeight:n.maxHeight||n.maxWidth,maxWidth:n.maxWidth||n.maxHeight}]}if(t.tiles){const s=t.tiles.length;for(let n=0;n<s;n++){const o=t.tiles[n];(o.height||o.width)&&e.push({id:O(t),type:"variable",minHeight:0,minWidth:0,maxHeight:o.height||o.width,maxWidth:o.width})}}return e}function St(t){const e=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,i=t.match(e);if(i){const r=i[1],s=parseInt(i[4],10),n=parseInt(i[5],10),o=i[7];if((r==="max"||r==="full")&&s&&n&&o)return{type:"fixed",id:t,height:n,width:s}}return{type:"unknown",id:t}}function xe(t){if(t["@type"])return t["@type"];if(t.type)return t.type}function D(t){if(typeof t=="string")return St(t);const e=xe(t);if(e!=="Image"&&e!=="sc:Image")return null;const i=t,r=O(i);return r?r&&i.width&&i.height?{id:r,type:"fixed",width:i.width,height:i.height,unsafe:!0}:St(r):null}function be(t){return U(t)?(t&&t.sizes?t.sizes:[]).map(e=>({id:O(t),type:"fixed-service",height:e.height,width:e.width})):[]}function At(t){const e=[],i=t.length;for(let r=0;r<i;r++){const s=be(t[r]);s.length&&e.push(...s);const n=ve(t[r]);n.length&&e.push(...n)}return e}function Ot(t){const e=t.service?Array.isArray(t.service)?t.service:[t.service]:[],i=e.length,r=[];for(let s=0;s<i;s++)U(e[s])&&r.push(e[s]);return r}function we(t,e=!0,i){const r=[],s=D(t);if(s===null)return r;const n=t;if(r.push(s),e&&n.width&&n.height){const o=[],a=Ot(n);for(const c of a){const l={id:O(c),width:n.width,height:n.height};if(i.canLoadSync(l)){const f=i.loadServiceSync(l);f&&(f.height||(f.height=n.height),f.width||(f.width=n.width),o.push(...At([f])))}}if(o.length)return r.push(...o),r}return n.service&&r.push(...At(n.service)),r}function Se({x:t=0,y:e=0,w:i,h:r,full:s,square:n,percent:o}){if(s)return"full";if(n)return"square";if(typeof i>"u"||typeof r>"u")throw new Error("RegionParameter: invalid region");const a=`${t},${e},${i},${r}`;return o?`pct:${a}`:a}function Ae({max:t,percentScale:e,upscaled:i,confined:r,width:s,height:n,serialiseAsFull:o}){const a=[];return i&&a.push("^"),t?(a.push(o?"full":"max"),a.join("")):(r&&a.push("!"),e&&a.push(`pct:${e}`),s&&a.push(`${s}`),a.push(","),n&&a.push(`${n}`),a.join(""))}function Oe(t){return`${t.mirror?"!":""}${(t.angle||0)%360}`}var ke=Object.defineProperty,Me=Object.defineProperties,Fe=Object.getOwnPropertyDescriptors,kt=Object.getOwnPropertySymbols,Ce=Object.prototype.hasOwnProperty,je=Object.prototype.propertyIsEnumerable,Mt=(t,e,i)=>e in t?ke(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Q=(t,e)=>{for(var i in e||(e={}))Ce.call(e,i)&&Mt(t,i,e[i]);if(kt)for(var i of kt(e))je.call(e,i)&&Mt(t,i,e[i]);return t},_=(t,e)=>Me(t,Fe(e));function Te(t,e){const i=t.prefix.startsWith("/")?t.prefix.substr(1):t.prefix,r=`${t.scheme}://${t.server}/${i?`${i}/`:""}${t.identifier}`;if(t.type==="base")return r;if(t.type==="info")return`${r}/info.json`;let{region:s,size:n,rotation:o,format:a,quality:c}=t;if(e){const l=e["@context"]?Array.isArray(e["@context"])?e["@context"]:[e["@context"]]:[],f=l.indexOf("http://iiif.io/api/image/2/context.json")!==-1,d=l.indexOf("http://iiif.io/api/image/3/context.json")!==-1;if((n.width===e.width&&!n.height||n.height===e.height&&!n.width||n.width===e.width&&n.height===e.height)&&(n=_(Q({},n),{max:!0})),f&&(n.max&&!n.serialiseAsFull&&(n=_(Q({},n),{serialiseAsFull:!0})),!n.max&&n.width&&n.height&&(n=_(Q({},n),{height:void 0}))),d&&(n.max&&n.serialiseAsFull&&(n=_(Q({},n),{serialiseAsFull:!1})),n.width&&!n.height&&e.width&&e.height)){const y=e.height/e.width;n=_(Q({},n),{height:Math.ceil(n.width*y)})}}return[r,Se(s),Ae(n),Oe(o),`${c}.${a}`].filter(Boolean).join("/")}function X(t,e,i){const r=de({id:z(O(t)),profile:"level2",type:"ImageService2"});if(r.type!=="image")throw new Error("Invalid service");return r.size.max=!1,r.size.width=e,r.size.height=i,{id:Te(r),type:"fixed",width:e,height:i||t.height/(t.width||1)*e,unsafe:t.width>e}}function B(t){const e=t.replace(/(https?:\/\/)?(www.)?/i,"");return e.indexOf("/")!==-1?e.split("/")[0]:e}function Re(t,e,i){const r=t.width?t.width:t.maxWidth;return i.height<=t.maxHeight&&i.width<=t.maxWidth&&i.height>=t.minHeight&&i.width>=t.minWidth&&(!e||Math.abs(i.width-r)<Math.abs(e.width-r))}function ze(t,e){const i=[],r=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},t),s=[],n=[];let o=null;const a=(l,f)=>{if(Re(r,f,l)){if(r.preferFixedSize&&l.unsafe){n.push(l);return}r.returnAllOptions&&f&&n.push(f),o=l}else r.returnAllOptions&&n.push(l)},c=e.length;for(let l=0;l<c;l++){const f=e[l](),d=f.length;for(let y=0;y<d;y++){const p=f[y];if(p.type==="unknown"&&r.atAnyCost&&s.push(p),p.type==="fixed"&&(p.unsafe?s.push(p):a(p,o)),p.type==="fixed-service")if(r.unsafeImageService){const h=X(p,r.width,r.height);a(h,o)}else{const h=X(p,p.width,p.height);a(h,o)}if(p.type==="variable"&&p.maxWidth){const h=X({id:p.id,type:"fixed-service",width:p.maxWidth,height:p.maxWidth},p.maxWidth);a(h,o)}}if(o&&!r.returnAllOptions){if(o.unsafe||r.allowUnsafe)continue;break}}return r.atAnyCost&&n.length===0?{best:o||s[0],fallback:s.slice(1),log:i}:r.returnAllOptions?{best:r.atAnyCost?o||n[0]||s[0]:o||n[0],fallback:[...n,...s],log:i}:{best:o||n[0]||null,fallback:o?n:n.slice(1),log:i}}var Ie=Object.defineProperty,Pe=Object.defineProperties,We=Object.getOwnPropertyDescriptors,Ft=Object.getOwnPropertySymbols,Be=Object.prototype.hasOwnProperty,qe=Object.prototype.propertyIsEnumerable,Ct=(t,e,i)=>e in t?Ie(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,$e=(t,e)=>{for(var i in e||(e={}))Be.call(e,i)&&Ct(t,i,e[i]);if(Ft)for(var i of Ft(e))qe.call(e,i)&&Ct(t,i,e[i]);return t},He=(t,e)=>Pe(t,We(e));function Le(t,e,i){const r=t>e?t:e,s=i.length,n=[];for(let o=0;o<s;o++){const a=i[o];let c=a.scaleFactors[0],l=r/c;const f=[c];for(;l>=a.width;)c=c*2,f.push(c),l=l/2;n.push(He($e({},a),{scaleFactors:f}))}return n}function Qe(t,e){if(t.length!==e.length)return!1;if(t.length===0&&e.length===0)return!0;const i=t.length;let r=!0;for(let n=0;n<i;n++){const o=t[n],a=e[n];if(o.width!==a.width||o.height!==a.height){r=!1;break}}if(r)return!0;let s=0;for(let n=0;n<i;n++)for(let o=0;o<i;o++)if(t[n].width===e[o].width&&t[n].height===e[o].height){s++;break}return s===i}function jt(t){if(t&&t.profile){const e=t.profile;if(e){const i=Array.isArray(e)?e:[e];return i.includes("level0")||i.includes("http://iiif.io/api/image/2/level0.json")||i.includes("http://iiif.io/api/image/1/level0.json")||i.includes("http://iiif.io/api/image/1/profiles/level0.json")}}return!1}var I=(t,e,i)=>new Promise((r,s)=>{var n=c=>{try{a(i.next(c))}catch(l){s(l)}},o=c=>{try{a(i.throw(c))}catch(l){s(l)}},a=c=>c.done?r(c.value):Promise.resolve(c.value).then(n,o);a((i=i.apply(t,e)).next())});class Tt{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(e){Object.assign(this.config,e)}sample(e,i,r=!0){const s=B(O(e)),n=z(O(e)),o=this.knownImageServers[s];return this.imageServices[n]=Object.assign(e,{real:!0}),!o&&e.tiles&&!jt(e)?(this.knownImageServers[s]={verifications:0,malformed:!1,root:s,preLoaded:r,sampledId:O(e),verified:!1,server:null,result:{context:e["@context"]||[],sampledProfile:e.profile,resourceServiceRatio:i&&e.height?i.height/e.height:1,sampledSizes:e.sizes||[],sizeRatios:ye(e.width,e.height,e.sizes||[]),sampledTiles:e.tiles||[]}},!0):this.verify(e)}preLoad(e,i=!0){this.knownImageServers[e.root]=e,i&&(this.knownImageServers[e.root].malformed=!1,this.knownImageServers[e.root].verifications=this.config.verificationsRequired)}predict(e,i=!1,r=!1){const s=e==null?void 0:e.source,n=B(O(e)),o=this.knownImageServers[n];if(!o||!o.result||!r&&(o.malformed||o.verifications<this.config.verificationsRequired)||jt(e.source))return null;const a=z(O(e));return this.imageServices[a]||(this.imageServices[a]={"@context":o.result.context,"@id":O(e),id:O(e),protocol:"http://iiif.io/api/image",tiles:(s==null?void 0:s.tiles)||Le(e.width,e.height,o.result.sampledTiles),sizes:(s==null?void 0:s.sizes)||ge(Math.round(e.width/o.result.resourceServiceRatio),Math.round(e.height/o.result.resourceServiceRatio),o.result.sizeRatios),profile:(s==null?void 0:s.profile)||o.result.sampledProfile,height:(s==null?void 0:s.height)||e.height,width:(s==null?void 0:s.width)||e.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(e,i){return I(this,arguments,function*(r,s,n=!0,o=[]){const a=yield this.getImageCandidates(r,n);return ze(s,[()=>o,()=>a])})}getImageCandidates(e,i=!0){return I(this,null,function*(){const r=e;if(i&&r.height&&r.width){const s=Ot(r);for(const n of s){const o={id:O(n),width:n.width?n.width:r.width,height:n.height?n.height:r.height,source:n};yield this.loadService(o)}}return we(e,i,this)})}verify(e){return I(this,null,function*(){const i=this.predict(e,!1,!0),r=yield this.fetchService(O(e));if(!i)return!1;const s=i.height===r.height&&i.width===r.width&&i["@context"]===r["@context"]&&Qe(i.sizes||[],r.sizes||[]);if(s){const n=B(O(e));this.knownImageServers[n].verifications+=1,this.knownImageServers[n].verifications>=this.config.verificationsRequired&&(this.knownImageServers[n].verified=!0)}return s})}canLoadSync(e){const i=typeof e=="string"?e:O(e),r=z(i);if(this.imageServices[r])return!0;const s=this.knownImageServers[B(i)];return s&&!s.malformed&&s.verifications>=this.config.verificationsRequired}markAsMalformed(e){return I(this,null,function*(){return this.knownImageServers[B(O(e))].malformed=!0,this.loadService(e,!0)})}fetchService(e,i=!1){return I(this,null,function*(){const r=z(e);if(this.imageServices[r]&&(!i||this.imageServices[r].real))return this.imageServices[r];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const s=yield this.fetch(r).then(n=>n.json());return!s.id&&s["@id"]&&(s.id=s["@id"]),s.id!==e&&(s.id=e,s["@id"]&&(s["@id"]=e)),this.imageServices[r]=Object.assign(s,{real:!0}),this.imageServices[r]})}fetch(e,i){return I(this,null,function*(){return fetch(e,i)})}loadService(e,i=!1){return I(this,null,function*(){if(!this.config.disableThrottling){let n=!0;for(;n;)if(this.fetchingCount>=this.config.verificationsRequired)yield new Promise(o=>setTimeout(o,500));else{n=!1;break}}const r=this.knownImageServers[B(O(e))];if(r&&!r.malformed&&!i){yield r.result;const n=this.loadServiceSync(e);if(n)return n}this.fetchingCount++;const s=yield this.fetchService(O(e),i);return this.fetchingCount--,s.real&&this.sample(s,e),s})}loadServiceSync(e){const i=z(O(e));return this.imageServices[i]?this.imageServices[i]:this.predict(e)}}new Tt;function _e(t,e={}){const i=e.imageServiceLoader||new Tt;async function r(s,n,o,a=[],c){if(typeof s=="string")return{best:D(s),fallback:[],log:[]};const l=t.get(s);if(typeof l=="string")return{best:D(l),fallback:[],log:[]};switch(l.type){case"Annotation":{const f=l.body,d=t.get(f[0]);return c&&!d.width&&(d.width=c.width,d.height=c.height),await i.getThumbnailFromResource(d,n,o,a)}case"Canvas":{const f=l;if(f.thumbnail&&f.thumbnail.length){const d=t.get(f.thumbnail[0]),y=await i.getImageCandidates(d,o);y&&y.length&&a.push(...y)}return r(f.items[0],n,o,a,{width:f.width,height:f.height})}case"AnnotationPage":return r(l.items[0],n,o,a,c);case"Choice":return r(l.items[0],n,o,a,c);case"Collection":{const d=l.items[0];return r(d,n,o,a,c)}case"Manifest":{const d=l.items[0];return r(d,n,o,a,c)}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return c&&!l.width&&(l.width=c.width,l.height=c.height),i.getThumbnailFromResource(l,n,o,a);case"Service":case"Range":case"AnnotationCollection":case"CanvasReference":case"ContentResource":return{best:void 0,fallback:[],log:[]}}return{best:void 0,fallback:[],log:[]}}return{getBestThumbnailAtSize:r}}function Rt(t,e,i=[],r=!1){if(!t||!e||e.length===0)return;if(e.length===1)return e[0];if(e.indexOf(t)!==-1)return t;const s=t.indexOf("-")!==-1?t.slice(0,t.indexOf("-")):null;if(s&&e.indexOf(s)!==-1)return s;for(const n of i)if(e.indexOf(n)!==-1)return n;if(!r){const o=e.map(a=>a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null).indexOf(t);if(o!==-1)return e[o];for(const a of i){const c=a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null,l=c?e.indexOf(c):-1;if(l!==-1)return e[l]}}return e.indexOf("none")!==-1?"none":e.indexOf("@none")!==-1?"@none":e[0]}function zt(t,e,i={}){const{strictFallback:r=!1,defaultText:s="",separator:n=`
`,fallbackLanguages:o=[],closest:a}=i,c=Object.keys(t||{}),l=a?e:Rt(e,c,o,r);if(!t)return s;if(typeof t=="string")return t;const f=l?t[l]:void 0;return f?typeof f=="string"?f:f.join(n):""}function Ee(t,e={}){return zt(t,typeof navigator!="undefined"?navigator.language:void 0,e)}var Ne=function(){function t(e,i){var r=[],s=!0,n=!1,o=void 0;try{for(var a=e[Symbol.iterator](),c;!(s=(c=a.next()).done)&&(r.push(c.value),!(i&&r.length===i));s=!0);}catch(l){n=!0,o=l}finally{try{!s&&a.return&&a.return()}finally{if(n)throw o}}return r}return function(e,i){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,i);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),E=Math.PI*2,G=function(e,i,r,s,n,o,a){var c=e.x,l=e.y;c*=i,l*=r;var f=s*c-n*l,d=n*c+s*l;return{x:f+o,y:d+a}},Ve=function(e,i){var r=i===1.5707963267948966?.551915024494:i===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(i/4),s=Math.cos(e),n=Math.sin(e),o=Math.cos(e+i),a=Math.sin(e+i);return[{x:s-n*r,y:n+s*r},{x:o+a*r,y:a-o*r},{x:o,y:a}]},It=function(e,i,r,s){var n=e*s-i*r<0?-1:1,o=e*r+i*s;return o>1&&(o=1),o<-1&&(o=-1),n*Math.acos(o)},Ue=function(e,i,r,s,n,o,a,c,l,f,d,y){var p=Math.pow(n,2),h=Math.pow(o,2),b=Math.pow(d,2),m=Math.pow(y,2),v=p*h-p*m-h*b;v<0&&(v=0),v/=p*m+h*b,v=Math.sqrt(v)*(a===c?-1:1);var u=v*n/o*y,g=v*-o/n*d,x=f*u-l*g+(e+r)/2,w=l*u+f*g+(i+s)/2,S=(d-u)/n,M=(y-g)/o,F=(-d-u)/n,C=(-y-g)/o,W=It(1,0,S,M),j=It(S,M,F,C);return c===0&&j>0&&(j-=E),c===1&&j<0&&(j+=E),[x,w,W,j]},De=function(e){var i=e.px,r=e.py,s=e.cx,n=e.cy,o=e.rx,a=e.ry,c=e.xAxisRotation,l=c===void 0?0:c,f=e.largeArcFlag,d=f===void 0?0:f,y=e.sweepFlag,p=y===void 0?0:y,h=[];if(o===0||a===0)return[];var b=Math.sin(l*E/360),m=Math.cos(l*E/360),v=m*(i-s)/2+b*(r-n)/2,u=-b*(i-s)/2+m*(r-n)/2;if(v===0&&u===0)return[];o=Math.abs(o),a=Math.abs(a);var g=Math.pow(v,2)/Math.pow(o,2)+Math.pow(u,2)/Math.pow(a,2);g>1&&(o*=Math.sqrt(g),a*=Math.sqrt(g));var x=Ue(i,r,s,n,o,a,d,p,b,m,v,u),w=Ne(x,4),S=w[0],M=w[1],F=w[2],C=w[3],W=Math.abs(C)/(E/4);Math.abs(1-W)<1e-7&&(W=1);var j=Math.max(Math.ceil(W),1);C/=j;for(var _t=0;_t<j;_t++)h.push(Ve(F,C)),F+=C;return h.map(function(K){var Et=G(K[0],o,a,m,b,S,M),gi=Et.x,mi=Et.y,Nt=G(K[1],o,a,m,b,S,M),vi=Nt.x,xi=Nt.y,Vt=G(K[2],o,a,m,b,S,M),bi=Vt.x,wi=Vt.y;return{x1:gi,y1:mi,x2:vi,y2:xi,x:bi,y:wi}})},Xe=Je,J={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},Ge=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function Je(t){var e=[];return t.replace(Ge,function(i,r,s){var n=r.toLowerCase();for(s=Ze(s),n=="m"&&s.length>2&&(e.push([r].concat(s.splice(0,2))),n="l",r=r=="m"?"l":"L");;){if(s.length==J[n])return s.unshift(r),e.push(s);if(s.length<J[n])throw new Error("malformed path data");e.push([r].concat(s.splice(0,J[n])))}}),e}var Ye=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function Ze(t){var e=t.match(Ye);return e?e.map(Number):[]}var Ke=ti;function ti(t){var e=0,i=0,r=0,s=0;return t.map(function(n){n=n.slice();var o=n[0],a=o.toUpperCase();if(o!=a)switch(n[0]=a,o){case"a":n[6]+=r,n[7]+=s;break;case"v":n[1]+=s;break;case"h":n[1]+=r;break;default:for(var c=1;c<n.length;)n[c++]+=r,n[c++]+=s}switch(a){case"Z":r=e,s=i;break;case"H":r=n[1];break;case"V":s=n[1];break;case"M":r=e=n[1],s=i=n[2];break;default:r=n[n.length-2],s=n[n.length-1]}return n})}function ei(t){const e=Xe(t),i=Ke(e);let r,s=0,n=0,o=0,a=0,c,l,f=0,d=0;const y=[];for(let p=0;p<i.length;p++){let h=i[p];const b=h[0];switch(b){case"M":s=h[1],n=h[2];break;case"H":h=["L",h[1],n];break;case"V":h=["L",s,h[1]];break;case"S":{let m=f,v=d;(r==="C"||r=="S")&&(m+=m-o,v+=v-a),h=["C",m,v,h[1],h[2],h[3],h[4]]}break;case"T":r==="Q"||r=="T"?(c=f*2-c,l=d*2-l):(c=f,l=d),h=["Q",c,l,h[1],h[2]];break;case"Q":c=h[1],l=h[2];break;case"A":{const m=De({px:f,py:d,cx:h[6],cy:h[7],rx:h[1],ry:h[2],xAxisRotation:h[3],largeArcFlag:h[4],sweepFlag:h[5]});if(!m.length)continue;for(const[v,u]of m.entries())h=["C",u.x1,u.y1,u.x2,u.y2,u.x,u.y],v<m.length-1&&y.push(h);h=h}break;case"Z":h=["L",s,n];break}r=b,f=h[h.length-2],d=h[h.length-1],["C","Q","A"].indexOf(b)>-1?(o=h[h.length-4],a=h[h.length-3]):(o=f,a=d),y.push(h)}return y}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
(function(x,L){typeof exports=="object"&&typeof module!="undefined"?L(exports):typeof define=="function"&&define.amd?define(["exports"],L):(x=typeof globalThis!="undefined"?globalThis:x||self,L(x.VaultHelpers={}))})(this,function(x){"use strict";function L(t){return{addEventListener(e,i,r,s){if(!!e)return t.setMetaValue([e.id,"eventManager",i],n=>{const o=n||[];for(const a of o)if(a.callback===r)return o;return[...o,{callback:r,scope:s}]}),r},removeEventListener(e,i,r){!e||t.setMetaValue([e.id,"eventManager",i],s=>(s||[]).filter(n=>n.callback!==r))},getListenersAsProps(e,i){const r=typeof e=="string"?{id:e}:e;if(!r||!r.id)return{};const s=t.getResourceMeta(r.id,"eventManager"),n={};if(s&&r)for(const o of Object.keys(s))n[o]=a=>{const c=t.get(r);for(const{callback:l,scope:f}of s[o]||[])(!f||i&&f.indexOf(i)!==-1)&&l(a,c)};return n}}}function Zt(t){return{applyStyles(e,i,r){const s=typeof e=="string"?e:e.id;return t.setMetaValue([s,"styles",i],r)},getAppliedStyles(e){const i=typeof e=="string"?e:e.id;return t.getResourceMeta(i,"styles")}}}function T(t){return t.endsWith("info.json")?t:t.endsWith("/")?`${t}info.json`:`${t}/info.json`}const Kt="http://library.stanford.edu/iiif/image-api/compliance.html#level0",nt="http://library.stanford.edu/iiif/image-api/compliance.html#level1",st="http://library.stanford.edu/iiif/image-api/compliance.html#level2",te="http://library.stanford.edu/iiif/image-api/conformance.html#level0",ot="http://library.stanford.edu/iiif/image-api/conformance.html#level1",at="http://library.stanford.edu/iiif/image-api/conformance.html#level2",ee="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",ct="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",lt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",ie="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",ft="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",ut="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",re="http://iiif.io/api/image/1/level0.json",ne="http://iiif.io/api/image/1/profiles/level0.json",ht="http://iiif.io/api/image/1/level1.json",pt="http://iiif.io/api/image/1/profiles/level1.json",dt="http://iiif.io/api/image/1/level2.json",gt="http://iiif.io/api/image/1/profiles/level2.json",se="http://iiif.io/api/image/2/level0.json",oe="http://iiif.io/api/image/2/profiles/level0.json",yt="http://iiif.io/api/image/2/level1.json",mt="http://iiif.io/api/image/2/profiles/level1.json",vt="http://iiif.io/api/image/2/level2.json",xt="http://iiif.io/api/image/2/profiles/level2.json",ae="level0",bt="level1",wt="level2",ce="http://iiif.io/api/image/2/level0",St="http://iiif.io/api/image/2/level1",At="http://iiif.io/api/image/2/level2",Ft=[At,st,at,lt,ut,dt,gt,vt,xt,wt],Mt=[...Ft,St,nt,ot,ct,ft,ht,pt,yt,mt,bt],le=[ce,St,At,Kt,nt,st,te,ot,at,ee,ct,lt,ie,ft,ut,re,ne,ht,pt,dt,gt,se,oe,yt,mt,vt,xt,ae,bt,wt],fe={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},ue={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},he={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function pe(t){return Ft.indexOf(t)!==-1?he:Mt.indexOf(t)!==-1?ue:fe}function de(t){const e=t?Array.isArray(t.profile)?t.profile:[t.profile]:[],i={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let r of e)if(typeof r=="string"&&(r=pe(r)),!!r){if(r.formats)for(const s of r.formats)i.extraFormats.indexOf(s)===-1&&i.extraFormats.push(s);if(r.qualities)for(const s of r.qualities)i.extraQualities.indexOf(s)===-1&&i.extraQualities.push(s);if(r.supports)for(const s of r.supports)i.extraFeatures.indexOf(s)===-1&&i.extraFeatures.push(s);if(r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea),r.extraFormats)for(const s of r.extraFormats)i.extraFormats.indexOf(s)===-1&&i.extraFormats.push(s);if(r.extraQualities)for(const s of r.extraQualities)i.extraQualities.indexOf(s)===-1&&i.extraQualities.push(s);if(r.extraFeatures)for(const s of r.extraFeatures)i.extraFeatures.indexOf(s)===-1&&i.extraFeatures.push(s);r.maxHeight&&(i.maxHeight=r.maxHeight),r.maxWidth&&(i.maxWidth=r.maxWidth),r.maxArea&&(i.maxArea=r.maxArea)}if(t.extraFormats)for(const r of t.extraFormats)i.extraFormats.indexOf(r)===-1&&i.extraFormats.push(r);if(t.extraFeatures)for(const r of t.extraFeatures)i.extraFeatures.indexOf(r)===-1&&i.extraFeatures.push(r);if(t.extraQualities)for(const r of t.extraQualities)i.extraQualities.indexOf(r)===-1&&i.extraQualities.push(r);return i}function ge(t){try{if(t==="full")return{full:!0};if(t==="square")return{square:!0};const e=t.startsWith("pct:"),i=t.substr(e?4:0).split(",").map(r=>parseFloat(r));return{x:i[0],y:i[1],w:i[2],h:i[3],percent:e}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+t)}}function ye(t){const e={upscaled:!1,max:!1,confined:!1};if(t[0]==="^"&&(e.upscaled=!0,t=t.slice(1)),t==="max"||t==="full")return e.max=!0,e.serialiseAsFull=t==="full",e;if(t[0]==="!"&&(e.confined=!0,t=t.slice(1)),t[0]==="p")return e.percentScale=parseFloat(t.slice(4)),e;const i=t.split(",").map(r=>r.trim());return i.length&&(i[0]!==""&&(e.width=parseInt(i[0],10)),i[1]!==""&&(e.height=parseInt(i[1],10))),e}function me(t){const e={angle:0};if(t[0]==="!"&&(e.mirror=!0,t=t.substr(1)),e.angle=parseFloat(t)%360,Number.isNaN(e.angle))throw new Error(`Invalid rotation ${t}`);return e}function ve(t,e=""){const i=t.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!i)throw new Error(`Invalid or unknown input ${t}`);const r=i[2],s=i[3];let n=i[4];if(n[0]==="/"&&(n=n.substr(1)),e.length>0){if(e[0]==="/"&&(e=e.substr(1)),e!==n.substr(0,e.length))throw new Error(`Path does not start with prefix (path: ${n}, prefix: ${e})`);n=n.substr(e.length)}return{scheme:r,server:s,path:n,prefix:e}}function xe(t,e=""){const{path:i,scheme:r,server:s,prefix:n}=ve(t,e),o=i.split("/").reverse(),[a,c,l,f,...h]=o,g=h.reverse().filter(Boolean).join("/");if(o.length===1||a==="")return{type:"base",scheme:r,server:s,prefix:n,identifier:g};if(a==="info.json"){const[,...u]=o;return{type:"info",scheme:r,server:s,prefix:n,identifier:u.reverse().filter(Boolean).join("/")}}const p=a.split(".");return{type:"image",scheme:r,server:s,prefix:n,identifier:g,originalPath:i,region:ge(f),size:ye(l),rotation:me(c),quality:p[0],format:p[1]}}function be(t){const e=xe(T(t.id));if(e.type!=="info")throw new Error("Invalid service URL");const i=de(t);return{identifier:e.identifier,originalPath:"",server:e.server,prefix:e.prefix,scheme:e.scheme,type:"image",quality:i.extraQualities.indexOf("default")===-1?i.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}}function we(t,e,i){const r=i.length,s=[];for(let n=0;n<r;n++){const o=i[n].width;s.push(t/o)}return s}function Se(t,e,i){const r=i.length,s=[];for(let n=0;n<r;n++){const o=i[n];s.push({width:Math.floor(t/o),height:Math.floor(e/o)})}return s}function F(t){if(t["@id"])return t["@id"];if(t.id)return t.id}function X(t){if(!t||!t.profile||!F(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if(typeof i=="string"&&le.indexOf(i)!==-1)return!0;return!1}function Ae(t){if(!X(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if(typeof i=="string"){if(Mt.indexOf(i)!==-1)return!0}else{const r=[...i.supports||[],...i.extraFeatures||[]];if(r.indexOf("regionByPx")!==-1&&(r.indexOf("sizeByW")!==-1||r.indexOf("sizeByWh")!==-1))return!0}return!1}function Fe(t){if(!Ae(t))return[];const e=[],i=Array.isArray(t.profile)?t.profile:[t.profile],r=i.length;for(let s=0;s<r;s++){const n=i[s];if(typeof n!="string"&&(n.maxHeight||n.maxWidth))return[{id:F(t),type:"variable",minWidth:0,minHeight:0,maxHeight:n.maxHeight||n.maxWidth,maxWidth:n.maxWidth||n.maxHeight}]}if(t.tiles){const s=t.tiles.length;for(let n=0;n<s;n++){const o=t.tiles[n];(o.height||o.width)&&e.push({id:F(t),type:"variable",minHeight:0,minWidth:0,maxHeight:o.height||o.width,maxWidth:o.width})}}return e}function Ot(t){const e=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,i=t.match(e);if(i){const r=i[1],s=parseInt(i[4],10),n=parseInt(i[5],10),o=i[7];if((r==="max"||r==="full")&&s&&n&&o)return{type:"fixed",id:t,height:n,width:s}}return{type:"unknown",id:t}}function Me(t){if(t["@type"])return t["@type"];if(t.type)return t.type}function G(t){if(typeof t=="string")return Ot(t);const e=Me(t);if(e!=="Image"&&e!=="sc:Image")return null;const i=t,r=F(i);return r?r&&i.width&&i.height?{id:r,type:"fixed",width:i.width,height:i.height,unsafe:!0}:Ot(r):null}function Oe(t){return X(t)?(t&&t.sizes?t.sizes:[]).map(e=>({id:F(t),type:"fixed-service",height:e.height,width:e.width})):[]}function Ct(t){const e=[],i=t.length;for(let r=0;r<i;r++){const s=Oe(t[r]);s.length&&e.push(...s);const n=Fe(t[r]);n.length&&e.push(...n)}return e}function kt(t){const e=t.service?Array.isArray(t.service)?t.service:[t.service]:[],i=e.length,r=[];for(let s=0;s<i;s++)X(e[s])&&r.push(e[s]);return r}function Ce(t,e=!0,i){const r=[],s=G(t);if(s===null)return r;const n=t;if(r.push(s),e&&n.width&&n.height){const o=[],a=kt(n);for(const c of a){const l={id:F(c),width:n.width,height:n.height};if(i.canLoadSync(l)){const f=i.loadServiceSync(l);f&&(f.height||(f.height=n.height),f.width||(f.width=n.width),o.push(...Ct([f])))}}if(o.length)return r.push(...o),r}return n.service&&r.push(...Ct(n.service)),r}function ke({x:t=0,y:e=0,w:i,h:r,full:s,square:n,percent:o}){if(s)return"full";if(n)return"square";if(typeof i>"u"||typeof r>"u")throw new Error("RegionParameter: invalid region");const a=`${t},${e},${i},${r}`;return o?`pct:${a}`:a}function Re({max:t,percentScale:e,upscaled:i,confined:r,width:s,height:n,serialiseAsFull:o}){const a=[];return i&&a.push("^"),t?(a.push(o?"full":"max"),a.join("")):(r&&a.push("!"),e&&a.push(`pct:${e}`),s&&a.push(`${s}`),a.push(","),n&&a.push(`${n}`),a.join(""))}function je(t){return`${t.mirror?"!":""}${(t.angle||0)%360}`}var Ie=Object.defineProperty,Te=Object.defineProperties,ze=Object.getOwnPropertyDescriptors,Rt=Object.getOwnPropertySymbols,Pe=Object.prototype.hasOwnProperty,We=Object.prototype.propertyIsEnumerable,jt=(t,e,i)=>e in t?Ie(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Q=(t,e)=>{for(var i in e||(e={}))Pe.call(e,i)&&jt(t,i,e[i]);if(Rt)for(var i of Rt(e))We.call(e,i)&&jt(t,i,e[i]);return t},_=(t,e)=>Te(t,ze(e));function qe(t,e){const i=t.prefix.startsWith("/")?t.prefix.substr(1):t.prefix,r=`${t.scheme}://${t.server}/${i?`${i}/`:""}${t.identifier}`;if(t.type==="base")return r;if(t.type==="info")return`${r}/info.json`;let{region:s,size:n,rotation:o,format:a,quality:c}=t;if(e){const l=e["@context"]?Array.isArray(e["@context"])?e["@context"]:[e["@context"]]:[],f=l.indexOf("http://iiif.io/api/image/2/context.json")!==-1,h=l.indexOf("http://iiif.io/api/image/3/context.json")!==-1;if((n.width===e.width&&!n.height||n.height===e.height&&!n.width||n.width===e.width&&n.height===e.height)&&(n=_(Q({},n),{max:!0})),f&&(n.max&&!n.serialiseAsFull&&(n=_(Q({},n),{serialiseAsFull:!0})),!n.max&&n.width&&n.height&&(n=_(Q({},n),{height:void 0}))),h&&(n.max&&n.serialiseAsFull&&(n=_(Q({},n),{serialiseAsFull:!1})),n.width&&!n.height&&e.width&&e.height)){const g=e.height/e.width;n=_(Q({},n),{height:Math.ceil(n.width*g)})}}return[r,ke(s),Re(n),je(o),`${c}.${a}`].filter(Boolean).join("/")}function J(t,e,i){const r=be({id:T(F(t)),profile:"level2",type:"ImageService2"});if(r.type!=="image")throw new Error("Invalid service");return r.size.max=!1,r.size.width=e,r.size.height=i,{id:qe(r),type:"fixed",width:e,height:i||t.height/(t.width||1)*e,unsafe:t.width>e}}function q(t){const e=t.replace(/(https?:\/\/)?(www.)?/i,"");return e.indexOf("/")!==-1?e.split("/")[0]:e}function Be(t,e,i){const r=t.width?t.width:t.maxWidth;return i.height<=t.maxHeight&&i.width<=t.maxWidth&&i.height>=t.minHeight&&i.width>=t.minWidth&&(!e||Math.abs(i.width-r)<Math.abs(e.width-r))}function He(t,e){const i=[],r=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},t),s=[],n=[];let o=null;const a=(l,f)=>{if(Be(r,f,l)){if(r.preferFixedSize&&l.unsafe){n.push(l);return}r.returnAllOptions&&f&&n.push(f),o=l}else r.returnAllOptions&&n.push(l)},c=e.length;for(let l=0;l<c;l++){const f=e[l](),h=f.length;for(let g=0;g<h;g++){const p=f[g];if(p.type==="unknown"&&r.atAnyCost&&s.push(p),p.type==="fixed"&&(p.unsafe?s.push(p):a(p,o)),p.type==="fixed-service")if(r.unsafeImageService){const u=J(p,r.width,r.height);a(u,o)}else{const u=J(p,p.width,p.height);a(u,o)}if(p.type==="variable"&&p.maxWidth){const u=J({id:p.id,type:"fixed-service",width:p.maxWidth,height:p.maxWidth},p.maxWidth);a(u,o)}}if(o&&!r.returnAllOptions){if(o.unsafe||r.allowUnsafe)continue;break}}return r.atAnyCost&&n.length===0?{best:o||s[0],fallback:s.slice(1),log:i}:r.returnAllOptions?{best:r.atAnyCost?o||n[0]||s[0]:o||n[0],fallback:[...n,...s],log:i}:{best:o||n[0]||null,fallback:o?n:n.slice(1),log:i}}var $e=Object.defineProperty,Le=Object.defineProperties,Qe=Object.getOwnPropertyDescriptors,It=Object.getOwnPropertySymbols,_e=Object.prototype.hasOwnProperty,Ve=Object.prototype.propertyIsEnumerable,Tt=(t,e,i)=>e in t?$e(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ne=(t,e)=>{for(var i in e||(e={}))_e.call(e,i)&&Tt(t,i,e[i]);if(It)for(var i of It(e))Ve.call(e,i)&&Tt(t,i,e[i]);return t},Ee=(t,e)=>Le(t,Qe(e));function Ue(t,e,i){const r=t>e?t:e,s=i.length,n=[];for(let o=0;o<s;o++){const a=i[o];let c=a.scaleFactors[0],l=r/c;const f=[c];for(;l>=a.width;)c=c*2,f.push(c),l=l/2;n.push(Ee(Ne({},a),{scaleFactors:f}))}return n}function De(t,e){if(t.length!==e.length)return!1;if(t.length===0&&e.length===0)return!0;const i=t.length;let r=!0;for(let n=0;n<i;n++){const o=t[n],a=e[n];if(o.width!==a.width||o.height!==a.height){r=!1;break}}if(r)return!0;let s=0;for(let n=0;n<i;n++)for(let o=0;o<i;o++)if(t[n].width===e[o].width&&t[n].height===e[o].height){s++;break}return s===i}function zt(t){if(t&&t.profile){const e=t.profile;if(e){const i=Array.isArray(e)?e:[e];return i.includes("level0")||i.includes("http://iiif.io/api/image/2/level0.json")||i.includes("http://iiif.io/api/image/1/level0.json")||i.includes("http://iiif.io/api/image/1/profiles/level0.json")}}return!1}var z=(t,e,i)=>new Promise((r,s)=>{var n=c=>{try{a(i.next(c))}catch(l){s(l)}},o=c=>{try{a(i.throw(c))}catch(l){s(l)}},a=c=>c.done?r(c.value):Promise.resolve(c.value).then(n,o);a((i=i.apply(t,e)).next())});class Pt{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(e){Object.assign(this.config,e)}sample(e,i,r=!0){const s=q(F(e)),n=T(F(e)),o=this.knownImageServers[s];return this.imageServices[n]=Object.assign(e,{real:!0}),!o&&e.tiles&&!zt(e)?(this.knownImageServers[s]={verifications:0,malformed:!1,root:s,preLoaded:r,sampledId:F(e),verified:!1,server:null,result:{context:e["@context"]||[],sampledProfile:e.profile,resourceServiceRatio:i&&e.height?i.height/e.height:1,sampledSizes:e.sizes||[],sizeRatios:we(e.width,e.height,e.sizes||[]),sampledTiles:e.tiles||[]}},!0):this.verify(e)}preLoad(e,i=!0){this.knownImageServers[e.root]=e,i&&(this.knownImageServers[e.root].malformed=!1,this.knownImageServers[e.root].verifications=this.config.verificationsRequired)}predict(e,i=!1,r=!1){const s=e==null?void 0:e.source,n=q(F(e)),o=this.knownImageServers[n];if(!o||!o.result||!r&&(o.malformed||o.verifications<this.config.verificationsRequired)||zt(e.source))return null;const a=T(F(e));return this.imageServices[a]||(this.imageServices[a]={"@context":o.result.context,"@id":F(e),id:F(e),protocol:"http://iiif.io/api/image",tiles:(s==null?void 0:s.tiles)||Ue(e.width,e.height,o.result.sampledTiles),sizes:(s==null?void 0:s.sizes)||Se(Math.round(e.width/o.result.resourceServiceRatio),Math.round(e.height/o.result.resourceServiceRatio),o.result.sizeRatios),profile:(s==null?void 0:s.profile)||o.result.sampledProfile,height:(s==null?void 0:s.height)||e.height,width:(s==null?void 0:s.width)||e.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(e,i){return z(this,arguments,function*(r,s,n=!0,o=[]){const a=yield this.getImageCandidates(r,n);return He(s,[()=>o,()=>a])})}getImageCandidates(e,i=!0){return z(this,null,function*(){const r=e;if(i&&r.height&&r.width){const s=kt(r);for(const n of s){const o={id:F(n),width:n.width?n.width:r.width,height:n.height?n.height:r.height,source:n};yield this.loadService(o)}}return Ce(e,i,this)})}verify(e){return z(this,null,function*(){const i=this.predict(e,!1,!0),r=yield this.fetchService(F(e));if(!i)return!1;const s=i.height===r.height&&i.width===r.width&&i["@context"]===r["@context"]&&De(i.sizes||[],r.sizes||[]);if(s){const n=q(F(e));this.knownImageServers[n].verifications+=1,this.knownImageServers[n].verifications>=this.config.verificationsRequired&&(this.knownImageServers[n].verified=!0)}return s})}canLoadSync(e){const i=typeof e=="string"?e:F(e),r=T(i);if(this.imageServices[r])return!0;const s=this.knownImageServers[q(i)];return s&&!s.malformed&&s.verifications>=this.config.verificationsRequired}markAsMalformed(e){return z(this,null,function*(){return this.knownImageServers[q(F(e))].malformed=!0,this.loadService(e,!0)})}fetchService(e,i=!1){return z(this,null,function*(){const r=T(e);if(this.imageServices[r]&&(!i||this.imageServices[r].real))return this.imageServices[r];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const s=yield this.fetch(r).then(n=>n.json());return!s.id&&s["@id"]&&(s.id=s["@id"]),s.id!==e&&(s.id=e,s["@id"]&&(s["@id"]=e)),this.imageServices[r]=Object.assign(s,{real:!0}),this.imageServices[r]})}fetch(e,i){return z(this,null,function*(){return fetch(e,i)})}loadService(e,i=!1){return z(this,null,function*(){if(!this.config.disableThrottling){let n=!0;for(;n;)if(this.fetchingCount>=this.config.verificationsRequired)yield new Promise(o=>setTimeout(o,500));else{n=!1;break}}const r=this.knownImageServers[q(F(e))];if(r&&!r.malformed&&!i){yield r.result;const n=this.loadServiceSync(e);if(n)return n}this.fetchingCount++;const s=yield this.fetchService(F(e),i);return this.fetchingCount--,s.real&&this.sample(s,e),s})}loadServiceSync(e){const i=T(F(e));return this.imageServices[i]?this.imageServices[i]:this.predict(e)}}new Pt;function Xe(t,e={}){const i=e.imageServiceLoader||new Pt;async function r(s,n,o,a=[],c){if(typeof s=="string")return{best:G(s),fallback:[],log:[]};const l=t.get(s);if(typeof l=="string")return{best:G(l),fallback:[],log:[]};switch(l.type){case"Annotation":{const f=l.body,h=t.get(f[0]);return c&&!h.width&&(h.width=c.width,h.height=c.height),await i.getThumbnailFromResource(h,n,o,a)}case"Canvas":{const f=l;if(f.thumbnail&&f.thumbnail.length){const h=t.get(f.thumbnail[0]),g=await i.getImageCandidates(h,o);g&&g.length&&a.push(...g)}return r(f.items[0],n,o,a,{width:f.width,height:f.height})}case"AnnotationPage":return r(l.items[0],n,o,a,c);case"Choice":return r(l.items[0],n,o,a,c);case"Collection":{const h=l.items[0];return r(h,n,o,a,c)}case"Manifest":{const h=l.items[0];return r(h,n,o,a,c)}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return c&&!l.width&&(l.width=c.width,l.height=c.height),i.getThumbnailFromResource(l,n,o,a);case"Service":case"Range":case"AnnotationCollection":case"CanvasReference":case"ContentResource":return{best:void 0,fallback:[],log:[]}}return{best:void 0,fallback:[],log:[]}}return{getBestThumbnailAtSize:r}}function Wt(t,e,i=[],r=!1){if(!t||!e||e.length===0)return;if(e.length===1)return e[0];if(e.indexOf(t)!==-1)return t;const s=t.indexOf("-")!==-1?t.slice(0,t.indexOf("-")):null;if(s&&e.indexOf(s)!==-1)return s;for(const n of i)if(e.indexOf(n)!==-1)return n;if(!r){const o=e.map(a=>a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null).indexOf(t);if(o!==-1)return e[o];for(const a of i){const c=a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null,l=c?e.indexOf(c):-1;if(l!==-1)return e[l]}}return e.indexOf("none")!==-1?"none":e.indexOf("@none")!==-1?"@none":e[0]}function qt(t,e,i={}){const{strictFallback:r=!1,defaultText:s="",separator:n=`
`,fallbackLanguages:o=[],closest:a}=i,c=Object.keys(t||{}),l=a?e:Wt(e,c,o,r);if(!t)return s;if(typeof t=="string")return t;const f=l?t[l]:void 0;return f?typeof f=="string"?f:f.join(n):""}function Ge(t,e={}){return qt(t,typeof navigator!="undefined"?navigator.language:void 0,e)}var Je=function(){function t(e,i){var r=[],s=!0,n=!1,o=void 0;try{for(var a=e[Symbol.iterator](),c;!(s=(c=a.next()).done)&&(r.push(c.value),!(i&&r.length===i));s=!0);}catch(l){n=!0,o=l}finally{try{!s&&a.return&&a.return()}finally{if(n)throw o}}return r}return function(e,i){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,i);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),V=Math.PI*2,Y=function(e,i,r,s,n,o,a){var c=e.x,l=e.y;c*=i,l*=r;var f=s*c-n*l,h=n*c+s*l;return{x:f+o,y:h+a}},Ye=function(e,i){var r=i===1.5707963267948966?.551915024494:i===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(i/4),s=Math.cos(e),n=Math.sin(e),o=Math.cos(e+i),a=Math.sin(e+i);return[{x:s-n*r,y:n+s*r},{x:o+a*r,y:a-o*r},{x:o,y:a}]},Bt=function(e,i,r,s){var n=e*s-i*r<0?-1:1,o=e*r+i*s;return o>1&&(o=1),o<-1&&(o=-1),n*Math.acos(o)},Ze=function(e,i,r,s,n,o,a,c,l,f,h,g){var p=Math.pow(n,2),u=Math.pow(o,2),m=Math.pow(h,2),v=Math.pow(g,2),b=p*u-p*v-u*m;b<0&&(b=0),b/=p*v+u*m,b=Math.sqrt(b)*(a===c?-1:1);var d=b*n/o*g,y=b*-o/n*h,w=f*d-l*y+(e+r)/2,S=l*d+f*y+(i+s)/2,A=(h-d)/n,O=(g-y)/o,C=(-h-d)/n,k=(-g-y)/o,W=Bt(1,0,A,O),R=Bt(A,O,C,k);return c===0&&R>0&&(R-=V),c===1&&R<0&&(R+=V),[w,S,W,R]},Ke=function(e){var i=e.px,r=e.py,s=e.cx,n=e.cy,o=e.rx,a=e.ry,c=e.xAxisRotation,l=c===void 0?0:c,f=e.largeArcFlag,h=f===void 0?0:f,g=e.sweepFlag,p=g===void 0?0:g,u=[];if(o===0||a===0)return[];var m=Math.sin(l*V/360),v=Math.cos(l*V/360),b=v*(i-s)/2+m*(r-n)/2,d=-m*(i-s)/2+v*(r-n)/2;if(b===0&&d===0)return[];o=Math.abs(o),a=Math.abs(a);var y=Math.pow(b,2)/Math.pow(o,2)+Math.pow(d,2)/Math.pow(a,2);y>1&&(o*=Math.sqrt(y),a*=Math.sqrt(y));var w=Ze(i,r,s,n,o,a,h,p,m,v,b,d),S=Je(w,4),A=S[0],O=S[1],C=S[2],k=S[3],W=Math.abs(k)/(V/4);Math.abs(1-W)<1e-7&&(W=1);var R=Math.max(Math.ceil(W),1);k/=R;for(var Xt=0;Xt<R;Xt++)u.push(Ye(C,k)),C+=k;return u.map(function(rt){var Gt=Y(rt[0],o,a,v,m,A,O),Fi=Gt.x,Mi=Gt.y,Jt=Y(rt[1],o,a,v,m,A,O),Oi=Jt.x,Ci=Jt.y,Yt=Y(rt[2],o,a,v,m,A,O),ki=Yt.x,Ri=Yt.y;return{x1:Fi,y1:Mi,x2:Oi,y2:Ci,x:ki,y:Ri}})},ti=ii,Z={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},ei=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function ii(t){var e=[];return t.replace(ei,function(i,r,s){var n=r.toLowerCase();for(s=ni(s),n=="m"&&s.length>2&&(e.push([r].concat(s.splice(0,2))),n="l",r=r=="m"?"l":"L");;){if(s.length==Z[n])return s.unshift(r),e.push(s);if(s.length<Z[n])throw new Error("malformed path data");e.push([r].concat(s.splice(0,Z[n])))}}),e}var ri=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function ni(t){var e=t.match(ri);return e?e.map(Number):[]}var si=oi;function oi(t){var e=0,i=0,r=0,s=0;return t.map(function(n){n=n.slice();var o=n[0],a=o.toUpperCase();if(o!=a)switch(n[0]=a,o){case"a":n[6]+=r,n[7]+=s;break;case"v":n[1]+=s;break;case"h":n[1]+=r;break;default:for(var c=1;c<n.length;)n[c++]+=r,n[c++]+=s}switch(a){case"Z":r=e,s=i;break;case"H":r=n[1];break;case"V":s=n[1];break;case"M":r=e=n[1],s=i=n[2];break;default:r=n[n.length-2],s=n[n.length-1]}return n})}function ai(t){const e=ti(t),i=si(e);let r,s=0,n=0,o=0,a=0,c,l,f=0,h=0;const g=[];for(let p=0;p<i.length;p++){let u=i[p];const m=u[0];switch(m){case"M":s=u[1],n=u[2];break;case"H":u=["L",u[1],n];break;case"V":u=["L",s,u[1]];break;case"S":{let v=f,b=h;(r==="C"||r=="S")&&(v+=v-o,b+=b-a),u=["C",v,b,u[1],u[2],u[3],u[4]]}break;case"T":r==="Q"||r=="T"?(c=f*2-c,l=h*2-l):(c=f,l=h),u=["Q",c,l,u[1],u[2]];break;case"Q":c=u[1],l=u[2];break;case"A":{const v=Ke({px:f,py:h,cx:u[6],cy:u[7],rx:u[1],ry:u[2],xAxisRotation:u[3],largeArcFlag:u[4],sweepFlag:u[5]});if(!v.length)continue;for(const[b,d]of v.entries())u=["C",d.x1,d.y1,d.x2,d.y2,d.x,d.y],b<v.length-1&&g.push(u);u=u}break;case"Z":u=["L",s,n];break}r=m,f=u[u.length-2],h=u[u.length-1],["C","Q","A"].indexOf(m)>-1?(o=u[u.length-4],a=u[u.length-3]):(o=f,a=h),g.push(u)}return g}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
*

@@ -32,3 +32,3 @@ * All code in this module is based on JavaScript code by Raph Levien, published on his blog at

* limitations under the License.
*/function ii(t,e,i,r=1){return new Pt(t,e,i).subdivide(r)}function ri(t,e,i,r,s=1){return new Y(new Float64Array([t.x,t.y,e.x,e.y,i.x,i.y,r.x,r.y])).subdivide(s)}function ni(t){return t.x*t.x+t.y*t.y}function N(t){return t/(1-.67+Math.pow(Math.pow(.67,4)+.25*t*t,.25))}function q(t){return t*(1-.39+Math.sqrt(.39*.39+.25*t*t))}class Pt{constructor(e,i,r){this.start=e,this.control=i,this.end=r}eval(e){const i=1-e;return{x:this.start.x*i*i+2*this.control.x*i*e+this.end.x*e*e,y:this.start.y*i*i+2*this.control.y*i*e+this.end.y*e*e}}mapToBasic(){const{x:e,y:i}=this.start,{x:r,y:s}=this.control,{x:n,y:o}=this.end,a=2*r-e-n,c=2*s-i-o,l=(r-e)*a+(s-i)*c,f=(n-r)*a+(o-s)*c,d=(n-e)*c-(o-i)*a,y=l/d,p=f/d,h=Math.abs(d)/(Math.hypot(a,c)*Math.abs(p-y));return{x0:e,x2:n,scale:h,cross:d}}subdivide(e){const i=this.mapToBasic(),r=N(i.x0),s=N(i.x2),n=.5*Math.abs(s-r)*Math.sqrt(i.scale/e),o=Math.ceil(n),a=q(r),c=q(s),l=[0];for(let f=1;f<o;f++){const y=(q(r+(s-r)*f/o)-a)/(c-a);l.push(y)}return l.push(1),l.map(f=>this.eval(f))}}class Y{constructor(e){this.c=e}weightsum(e,i,r,s){const n=e*this.c[0]+i*this.c[2]+r*this.c[4]+s*this.c[6],o=e*this.c[1]+i*this.c[3]+r*this.c[5]+s*this.c[7];return{x:n,y:o}}eval(e){const i=1-e,r=i*i*i,s=3*i*i*e,n=3*i*e*e,o=e*e*e;return this.weightsum(r,s,n,o)}deriv(e){const i=1-e,r=-3*i*i,s=3*e*e,n=-6*e*i-r,o=6*e*i-s;return this.weightsum(r,n,o,s)}midpoint_quadbez(){const e=this.weightsum(-.25,.75,.75,-.25);return new Pt({x:this.c[0],y:this.c[1]},e,{x:this.c[6],y:this.c[7]})}subsegment(e,i){const r=new Float64Array(8),s=this.eval(e),n=this.eval(i);r[0]=s.x,r[1]=s.y;const o=(i-e)/3,a=this.deriv(e);r[2]=s.x+o*a.x,r[3]=s.y+o*a.y;const c=this.deriv(i);return r[4]=n.x-o*c.x,r[5]=n.y-o*c.y,r[6]=n.x,r[7]=n.y,new Y(r)}subdivide(e){const i=.1*e,r=e-i,s=Math.sqrt(r),n=ni(this.weightsum(1,-3,3,-1)),o=Math.ceil(Math.pow(n/(432*i*i),1/6)),a=[];let c=0;for(let h=0;h<o;h++){const b=h/o,m=(h+1)/o,v=this.subsegment(b,m).midpoint_quadbez(),u=v.mapToBasic(),g=N(u.x0),x=N(u.x2),w=Math.sqrt(u.scale);let S=Math.abs(x-g)*w;if(Math.sign(u.x0)!=Math.sign(u.x2)){const M=s/w,F=s*Math.abs(x-g)/N(M);S=Math.max(S,F)}a.push({quad:v,a0:g,a2:x,val:S}),c+=S}const l=.5*c/s,f=Math.ceil(l),d=[{x:this.c[0],y:this.c[1]}];let y=0,p=0;for(let h=1;h<f;h++){const b=c*h/f;for(;y+a[p].val<b;)y+=a[p].val,p++;const m=a[p].a0,v=a[p].a2,u=q(m),g=q(v),x=m+(v-m)*(b-y)/a[p].val,S=(q(x)-u)/(g-u);d.push(a[p].quad.eval(S))}return d.push({x:this.c[6],y:this.c[7]}),d}}const si=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,oi=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,Wt=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function V(t,{domParser:e,svgPreprocessor:i}={}){var r,s;if(Array.isArray(t))return t.reduce((n,o)=>{const{selector:a,selectors:c}=V(o);return a&&(n.selector||(n.selector=a),n.selectors.push(...c)),n},{selector:null,selectors:[]});if(!t)return{selector:null,selectors:[]};if(typeof t=="string"){const[n,o]=t.split("#");return o?V({type:"FragmentSelector",value:o}):{selector:null,selectors:[]}}if(t.type==="PointSelector"&&(t.t||t.t===0)){const n={type:"TemporalSelector",temporal:{startTime:t.t}};return{selector:n,selectors:[n]}}if(t.type==="FragmentSelector"){const n=si.exec(t.value);if(n){const a={type:"BoxSelector",spatial:{unit:n[2]==="percent:"||n[2]==="pct:"?"percent":"pixel",x:parseFloat(n[3]),y:parseFloat(n[4]),width:parseFloat(n[5]),height:parseFloat(n[6])}};return{selector:a,selectors:[a]}}const o=t.value.match(oi);if(o){const a={type:"TemporalSelector",temporal:{startTime:o[4]?parseFloat(o[4]):0,endTime:o[7]?parseFloat(o[7]):void 0}};return{selector:a,selectors:[a]}}return{selector:null,selectors:[]}}if(t.type==="SvgSelector"&&"value"in t){e||(typeof window!="undefined"?e=new window.DOMParser:console.warn("No DOMParser available, cannot parse SVG selector, `points`, `spatial` and `style` will be unavailable and the SVG will not be normalized."));let n=[],o,a,c=(r=i==null?void 0:i(t.value))!=null?r:t.value,l;if(e){const d=e.parseFromString(t.value,"image/svg+xml").querySelector("svg");if(!d)return console.warn(`Illegal SVG selector: ${t.value}`),{selector:null,selectors:[]};const y=Bt(d);y&&(n=y.points,l=y.shapeType,o=[Math.min(...n.map(p=>p[0])),Math.min(...n.map(p=>p[1])),Math.max(...n.map(p=>p[0])),Math.max(...n.map(p=>p[1]))],{style:a,svg:c}=(s=li(y.element))!=null?s:{svg:c})}const f={type:"SvgSelector",svg:c,svgShape:l,style:a,points:n.length?n:void 0,spatial:o?{unit:"pixel",x:o[0],y:o[1],width:o[2]-o[0],height:o[3]-o[1]}:void 0};return{selector:f,selectors:[f]}}return{selector:null,selectors:[]}}function ai(t){const e=t.map(r=>r[0]).reduce((r,s)=>(r[s]+=1,r),{C:0,Q:0,L:0,M:0}),i=new Set(t.map(r=>r[0]));if(e.C>0||e.Q>0)return"path";if(e.L>0&&(i.size===1||i.size===2&&i.has("M"))){if(e.L===4)return"rect";const r=t.slice(-1)[0];return t[0][0]==="M"&&r[0]==="L"&&r[1]==t[0][1]&&r[2]===t[0][2]||r[1]===0&&r[2]===0?"polygon":"polyline"}return"path"}function Bt(t){var e,i,r,s,n,o,a,c,l,f,d,y,p,h,b,m,v;for(const u of Array.from(t.children))switch(u==null?void 0:u.tagName.toLowerCase()){case"g":{const g=Bt(u);if(g)return g}continue;case"path":{const g=u.getAttribute("d");if(!g)continue;const x=ei(g);return{element:u,points:ci(x),shapeType:ai(x)}}case"circle":{const g=parseFloat((e=u.getAttribute("cx"))!=null?e:"0"),x=parseFloat((i=u.getAttribute("cy"))!=null?i:"0"),w=parseFloat((r=u.getAttribute("r"))!=null?r:"0");if(!w)continue;const S=[];for(let M=0;M<=360;M+=12){const F=M*Math.PI/180;S.push([g+w*Math.cos(F),x+w*Math.sin(F)])}return{element:u,points:S,shapeType:"circle"}}case"ellipse":{const g=parseFloat((s=u.getAttribute("cx"))!=null?s:"0"),x=parseFloat((n=u.getAttribute("cy"))!=null?n:"0"),w=parseFloat((o=u.getAttribute("rx"))!=null?o:"0"),S=parseFloat((a=u.getAttribute("ry"))!=null?a:"0");if(!w&&!S)continue;const M=[];for(let F=0;F<=360;F+=12){const C=Math.tan(F/360*Math.PI),W=w*(1-C**2)/(1+C**2),j=S*2*C/(1+C**2);M.push([g+W,x+j])}return{element:u,points:M,shapeType:"ellipse"}}case"line":{const g=parseFloat((c=u.getAttribute("x0"))!=null?c:"0"),x=parseFloat((l=u.getAttribute("y0"))!=null?l:"0"),w=parseFloat((f=u.getAttribute("x1"))!=null?f:"0"),S=parseFloat((d=u.getAttribute("y1"))!=null?d:"0");if(g===w&&x===S)continue;return{element:u,points:[[g,x],[w,S]],shapeType:"polyline"}}case"polygon":case"polyline":{const g=(p=(y=u.getAttribute("points"))==null?void 0:y.split(" ").map(w=>w.split(",").map(parseFloat)))!=null?p:[];if(!g.length)continue;let x="polyline";return u.tagName.toLowerCase()==="polygon"&&(g.push(g[0]),x="polygon"),{element:u,points:g,shapeType:x}}case"rect":{const g=parseFloat((h=u.getAttribute("x"))!=null?h:"0"),x=parseFloat((b=u.getAttribute("y"))!=null?b:"0"),w=parseFloat((m=u.getAttribute("width"))!=null?m:"0"),S=parseFloat((v=u.getAttribute("height"))!=null?v:"0");if(!w||!S)continue;return{element:u,points:[[g,x],[g+w,x],[g+w,x+S],[g,x+S],[g,x]],shapeType:"rect"}}default:continue}return null}function ci(t){var i;const e=[];for(let r=0;r<t.length;r++){const s=(i=e[e.length-1])!=null?i:[0,0],n=t[r];switch(n[0]){case"M":case"L":e.push([n[1],n[2]]);continue;case"C":e.push(...ri({x:s[0],y:s[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]},{x:n[5],y:n[6]}).map(o=>[o.x,o.y]).slice(1));continue;case"Q":e.push(...ii({x:s[0],y:s[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]}).map(o=>[o.x,o.y]).slice(1));continue}}return e}function li(t){const e={};if(t.hasAttribute("fill")?(e.fill=t.getAttribute("fill"),t.removeAttribute("fill")):t.style.fill&&(e.fill=t.style.fill),e.fill){const r=Wt.exec(e.fill);r&&(e.fillOpacity=parseFloat(r[4]),e.fill=`rgb(${r[1]}, ${r[2]}, ${r[3]})`)}if(t.hasAttribute("fill-opacity")?(e.fillOpacity=parseFloat(t.getAttribute("fill-opacity")),t.removeAttribute("fill-opacity")):t.style.fillOpacity&&(e.fillOpacity=parseFloat(t.style.fillOpacity)),t.hasAttribute("stroke")?(e.stroke=t.getAttribute("stroke"),t.removeAttribute("stroke")):t.style.stroke&&(e.stroke=t.style.stroke),e.stroke){const r=Wt.exec(e.stroke);r&&(e.strokeOpacity=parseFloat(r[4]),e.stroke=`rgb(${r[1]}, ${r[2]}, ${r[3]})`)}t.hasAttribute("stroke-opacity")?(e.strokeOpacity=parseFloat(t.getAttribute("stroke-opacity")),t.removeAttribute("stroke-opacity")):t.style.strokeOpacity&&(e.strokeOpacity=parseFloat(t.style.strokeOpacity)),t.hasAttribute("stroke-width")?(e.strokeWidth=t.getAttribute("stroke-width"),t.removeAttribute("stroke-width")):t.style.strokeWidth&&(e.strokeWidth=t.style.strokeWidth),t.hasAttribute("stroke-dasharray")?(e.strokeDasharray=t.getAttribute("stroke-dasharray"),t.removeAttribute("stroke-dasharray")):t.style.strokeDasharray&&(e.strokeDasharray=t.style.strokeDasharray);let i=t;for(;i.tagName.toLowerCase()!=="svg";)if(i=i.parentElement,i===null)throw new Error("Could not find root SVG element");return{svg:i.outerHTML,style:Object.keys(e).length>0?e:void 0}}function T(t,e={}){if(Array.isArray(t))return T(t[0]);if(typeof t=="string"){const[i,r]=t.split("#");return r?T({type:"SpecificResource",source:{id:i,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:i,type:e.typeMap&&e.typeMap[i]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return T(t.items[0]);if(t.type==="SpecificResource"){t.source.type==="Canvas"&&t.source.partOf&&typeof t.source.partOf=="string"&&(t.source.partOf=[{id:t.source.partOf,type:"Manifest"}]);const{selector:i,selectors:r}=t.selector?V(t.selector,e):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:i,selectors:r}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[i,r]=t.id.split("#");return r?T({type:"SpecificResource",source:{...t,id:i},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{...t,id:i},selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}function Z(t,e=!1){if(typeof t=="string"){if(t.startsWith("{"))try{const i=JSON.parse(t);return Z(i)}catch{return[!1,{reason:"Invalid JSON"}]}return[!0]}if(Array.isArray(t)){for(const i of t){const[r,s]=Z(i);if(!r&&s)return[r,s]}return[!0]}return t.type==="Annotation"?[!0]:e&&t.type==="Canvas"&&!t.partOf?[!1,{reason:"Canvas without partOf cannot be loaded"}]:[!0]}function fi(t){return $t(typeof t=="string"?t:JSON.stringify(t))}function qt(t,e){if(t=t.trim(),t[0]==="{")return e?Promise.resolve(JSON.parse(t)):JSON.parse(t);if(t.startsWith("http")){if(!e)throw new Error("Cannot fetch remote fetch with async=false in parseContentState");return fetch(t).then(i=>i.json())}return qt(Ht(t),e)}function $t(t){const e=encodeURIComponent(t);return(typeof btoa=="undefined"?Buffer.from(e,"utf-8").toString("base64"):btoa(e)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function Ht(t){const i=hi(t).replace(/-/g,"+").replace(/_/g,"/"),r=typeof atob=="undefined"?Buffer.from(i,"base64").toString("utf-8"):atob(i);return decodeURIComponent(r).trim()}function hi(t){const e=t.length%4;if(e===1)throw new Error("InvalidLengthError: Input base64url string is the wrong length to determine padding");return t+(e?"====".slice(0,4-e):"")}function ui(t){if(!t)throw new Error("Content state is empty");Array.isArray(t)||(t=[t]);let e="vault://virtual-annotation/"+new Date().getTime();const i=[];for(const r of t){if(typeof r=="string")throw new Error("Content state is a [String] type and cannot be inferred");if(r.type==="Annotation"){if(e=r.id,Array.isArray(r.motivation))for(const n of r.motivation);if(Array.isArray(r.target))for(const n of r.target){const o=T(n);i.push(o)}else{const n=T(r.target);i.push(n)}continue}const s=T(r);i.push(s)}return{id:e,type:"Annotation",motivation:["contentState",...t.motivation||[]],target:i,extensions:{}}}function Lt(t){return t.type==="SpecificResource"?[t.source,{selector:t.selector}]:[t,{selector:null}]}function pi(t){function e(s){const n=s?typeof s=="string"?t.get(s):s:null;if(!n)return[];const o=t.get(n.items),a=[];for(const c of o)a.push(...t.get(c.items));return a}function i(s,n=[]){const o=Array.isArray(s)?s:e(s),a=[];let c=null;const l=[];for(const f of o){if(f.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const d=t.get(f.body);for(const y of d){const[p,{selector:h}]=Lt(y),b=(p.type||"unknown").toLowerCase();if(b==="choice"){const m=t.get(p.items),v=n.length?n.map(u=>m.find(g=>g.id===u)).filter(Boolean):[m[0]];v.length===0&&v.push(m[0]),c={type:"single-choice",items:m.map(u=>({id:u.id,label:u.label,selected:v.indexOf(u)!==-1})),label:y.label},d.push(...v);continue}a.indexOf(b)===-1&&a.push(b),l.push({type:b,resource:p,target:f.target,selector:h})}}return{types:a,items:l,choice:c}}function r(s){const{choice:n}=i(s);return n}return{getAllPaintingAnnotations:e,getPaintables:i,extractChoices:r}}function k(t,e,i){e[H]=e[H]||[],e[H].push(t),Object.defineProperty(e,t,{get(){if(typeof e[P][t]=="undefined")return;const r=e[P][t];return r&&R(i.get(e[P][t]),i)},set(r){e[P][t]!==r&&(this[P][t]=r)}})}const P=Symbol.for("_refs_"),$=Symbol.for("_reactive_"),H=Symbol.for("_defined_");function di(t,e=!1){const i={id:null,[H]:[],[P]:{},[$]:null,is(r){return typeof r=="string"?this.id===r:r.id?r.id===this.id:!1},reactive(){if(!this[$])return this[$]=this.subscribe(()=>this.refresh(),!0),()=>{this.unreactive()}},refresh(){if(this.id){const r=this.unwrap();for(const s of Object.keys(r||{}))this[H].includes(s)?this[P][s]=r[s]:this[s]=r[s]}},unreactive(){this[$]&&(this[$](),this[$]=null)},unwrap(){if(!this.id)throw new Error("Invalid object");return t.get(this.id)},toPresentation3(){return t.toPresentation3(this.unwrap())},toPresentation2(){return t.toPresentation2(this.unwrap())},toJSON(){const r=this;return{...r,items:r.items,annotations:r.annotations,structures:r.structures,seeAlso:r.seeAlso,service:r.service,services:r.services,rendering:r.rendering,partOf:r.partOf,start:r.start,supplementary:r.supplementary,homepage:r.homepage,thumbnail:r.thumbnail,placeholderCanvas:r.placeholderCanvas,accompanyingCanvas:r.accompanyingCanvas,provider:r.provider}},subscribe(r,s=!0){return t.subscribe(()=>this.id?t.get(this.id):null,r,s)}};return k("items",i,t),k("annotations",i,t),k("structures",i,t),k("seeAlso",i,t),k("service",i,t),k("services",i,t),k("rendering",i,t),k("partOf",i,t),k("start",i,t),k("supplementary",i,t),k("homepage",i,t),k("thumbnail",i,t),k("placeholderCanvas",i,t),k("accompanyingCanvas",i,t),k("provider",i,t),k("body",i,t),k("logo",i,t),i}function Qt(t){return Array.isArray(t)?t.map(e=>Qt(e)):!t||!t.type?t:{id:t.id,type:t.type}}function R(t,e,i=!1){if(Array.isArray(t))return t.map(o=>R(o,e,i));if(!t||!t.type||!t.id)return t;const r=di(e,i),s=Object.create(r),n=Object.assign(s,t);return i&&n.reactive(),n}function yi(t){return{get(e,i=!1){return R(t.get(e),t,i)},async load(e,i){return R(await t.load(e,i),t)},async loadManifest(e,i){return R(await t.loadManifest(e,i),t)},async loadCollection(e,i){return R(await t.loadCollection(e,i),t)},wrapObject(e){return R(t.get(e,{skipSelfReturn:!1}),t)},isWrapped(e){return!!e[H]}}}A.buildLocaleString=zt,A.createEventsHelper=L,A.createObjectsHelper=yi,A.createPaintingAnnotationsHelper=pi,A.createStylesHelper=Ut,A.createThumbnailHelper=_e,A.decodeContentState=Ht,A.encodeContentState=$t,A.expandTarget=T,A.getClosestLanguage=Rt,A.getValue=Ee,A.normaliseContentState=ui,A.parseContentState=qt,A.parseSelector=V,A.parseSpecificResource=Lt,A.serialiseContentState=fi,A.unwrapObject=Qt,A.validateContentState=Z,A.wrapObject=R,Object.defineProperties(A,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
*/function ci(t,e,i,r=1){return new Ht(t,e,i).subdivide(r)}function li(t,e,i,r,s=1){return new K(new Float64Array([t.x,t.y,e.x,e.y,i.x,i.y,r.x,r.y])).subdivide(s)}function fi(t){return t.x*t.x+t.y*t.y}function N(t){return t/(1-.67+Math.pow(Math.pow(.67,4)+.25*t*t,.25))}function B(t){return t*(1-.39+Math.sqrt(.39*.39+.25*t*t))}class Ht{constructor(e,i,r){this.start=e,this.control=i,this.end=r}eval(e){const i=1-e;return{x:this.start.x*i*i+2*this.control.x*i*e+this.end.x*e*e,y:this.start.y*i*i+2*this.control.y*i*e+this.end.y*e*e}}mapToBasic(){const{x:e,y:i}=this.start,{x:r,y:s}=this.control,{x:n,y:o}=this.end,a=2*r-e-n,c=2*s-i-o,l=(r-e)*a+(s-i)*c,f=(n-r)*a+(o-s)*c,h=(n-e)*c-(o-i)*a,g=l/h,p=f/h,u=Math.abs(h)/(Math.hypot(a,c)*Math.abs(p-g));return{x0:e,x2:n,scale:u,cross:h}}subdivide(e){const i=this.mapToBasic(),r=N(i.x0),s=N(i.x2),n=.5*Math.abs(s-r)*Math.sqrt(i.scale/e),o=Math.ceil(n),a=B(r),c=B(s),l=[0];for(let f=1;f<o;f++){const g=(B(r+(s-r)*f/o)-a)/(c-a);l.push(g)}return l.push(1),l.map(f=>this.eval(f))}}class K{constructor(e){this.c=e}weightsum(e,i,r,s){const n=e*this.c[0]+i*this.c[2]+r*this.c[4]+s*this.c[6],o=e*this.c[1]+i*this.c[3]+r*this.c[5]+s*this.c[7];return{x:n,y:o}}eval(e){const i=1-e,r=i*i*i,s=3*i*i*e,n=3*i*e*e,o=e*e*e;return this.weightsum(r,s,n,o)}deriv(e){const i=1-e,r=-3*i*i,s=3*e*e,n=-6*e*i-r,o=6*e*i-s;return this.weightsum(r,n,o,s)}midpoint_quadbez(){const e=this.weightsum(-.25,.75,.75,-.25);return new Ht({x:this.c[0],y:this.c[1]},e,{x:this.c[6],y:this.c[7]})}subsegment(e,i){const r=new Float64Array(8),s=this.eval(e),n=this.eval(i);r[0]=s.x,r[1]=s.y;const o=(i-e)/3,a=this.deriv(e);r[2]=s.x+o*a.x,r[3]=s.y+o*a.y;const c=this.deriv(i);return r[4]=n.x-o*c.x,r[5]=n.y-o*c.y,r[6]=n.x,r[7]=n.y,new K(r)}subdivide(e){const i=.1*e,r=e-i,s=Math.sqrt(r),n=fi(this.weightsum(1,-3,3,-1)),o=Math.ceil(Math.pow(n/(432*i*i),1/6)),a=[];let c=0;for(let u=0;u<o;u++){const m=u/o,v=(u+1)/o,b=this.subsegment(m,v).midpoint_quadbez(),d=b.mapToBasic(),y=N(d.x0),w=N(d.x2),S=Math.sqrt(d.scale);let A=Math.abs(w-y)*S;if(Math.sign(d.x0)!=Math.sign(d.x2)){const O=s/S,C=s*Math.abs(w-y)/N(O);A=Math.max(A,C)}a.push({quad:b,a0:y,a2:w,val:A}),c+=A}const l=.5*c/s,f=Math.ceil(l),h=[{x:this.c[0],y:this.c[1]}];let g=0,p=0;for(let u=1;u<f;u++){const m=c*u/f;for(;g+a[p].val<m;)g+=a[p].val,p++;const v=a[p].a0,b=a[p].a2,d=B(v),y=B(b),w=v+(b-v)*(m-g)/a[p].val,A=(B(w)-d)/(y-d);h.push(a[p].quad.eval(A))}return h.push({x:this.c[6],y:this.c[7]}),h}}const ui=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,hi=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,$t=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function E(t,{domParser:e,svgPreprocessor:i}={}){var r,s;if(Array.isArray(t))return t.reduce((n,o)=>{const{selector:a,selectors:c}=E(o);return a&&(n.selector||(n.selector=a),n.selectors.push(...c)),n},{selector:null,selectors:[]});if(!t)return{selector:null,selectors:[]};if(typeof t=="string"){const[n,o]=t.split("#");return o?E({type:"FragmentSelector",value:o}):{selector:null,selectors:[]}}if(t.type==="PointSelector"&&(t.t||t.t===0)){const n={type:"TemporalSelector",temporal:{startTime:t.t}};return{selector:n,selectors:[n]}}if(t.type==="FragmentSelector"){const n=ui.exec(t.value);if(n){const a={type:"BoxSelector",spatial:{unit:n[2]==="percent:"||n[2]==="pct:"?"percent":"pixel",x:parseFloat(n[3]),y:parseFloat(n[4]),width:parseFloat(n[5]),height:parseFloat(n[6])}};return{selector:a,selectors:[a]}}const o=t.value.match(hi);if(o){const a={type:"TemporalSelector",temporal:{startTime:o[4]?parseFloat(o[4]):0,endTime:o[7]?parseFloat(o[7]):void 0}};return{selector:a,selectors:[a]}}return{selector:null,selectors:[]}}if(t.type==="SvgSelector"&&"value"in t){e||(typeof window!="undefined"?e=new window.DOMParser:console.warn("No DOMParser available, cannot parse SVG selector, `points`, `spatial` and `style` will be unavailable and the SVG will not be normalized."));let n=[],o,a,c=(r=i==null?void 0:i(t.value))!=null?r:t.value,l;if(e){const h=e.parseFromString(t.value,"image/svg+xml").querySelector("svg");if(!h)return console.warn(`Illegal SVG selector: ${t.value}`),{selector:null,selectors:[]};const g=Lt(h);g&&(n=g.points,l=g.shapeType,o=[Math.min(...n.map(p=>p[0])),Math.min(...n.map(p=>p[1])),Math.max(...n.map(p=>p[0])),Math.max(...n.map(p=>p[1]))],{style:a,svg:c}=(s=gi(g.element))!=null?s:{svg:c})}const f={type:"SvgSelector",svg:c,svgShape:l,style:a,points:n.length?n:void 0,spatial:o?{unit:"pixel",x:o[0],y:o[1],width:o[2]-o[0],height:o[3]-o[1]}:void 0};return{selector:f,selectors:[f]}}return{selector:null,selectors:[]}}function pi(t){const e=t.map(r=>r[0]).reduce((r,s)=>(r[s]+=1,r),{C:0,Q:0,L:0,M:0}),i=new Set(t.map(r=>r[0]));if(e.C>0||e.Q>0)return"path";if(e.L>0&&(i.size===1||i.size===2&&i.has("M"))){if(e.L===4)return"rect";const r=t.slice(-1)[0];return t[0][0]==="M"&&r[0]==="L"&&r[1]==t[0][1]&&r[2]===t[0][2]||r[1]===0&&r[2]===0?"polygon":"polyline"}return"path"}function Lt(t){var e,i,r,s,n,o,a,c,l,f,h,g,p,u,m,v,b;for(const d of Array.from(t.children))switch(d==null?void 0:d.tagName.toLowerCase()){case"g":{const y=Lt(d);if(y)return y}continue;case"path":{const y=d.getAttribute("d");if(!y)continue;const w=ai(y);return{element:d,points:di(w),shapeType:pi(w)}}case"circle":{const y=parseFloat((e=d.getAttribute("cx"))!=null?e:"0"),w=parseFloat((i=d.getAttribute("cy"))!=null?i:"0"),S=parseFloat((r=d.getAttribute("r"))!=null?r:"0");if(!S)continue;const A=[];for(let O=0;O<=360;O+=12){const C=O*Math.PI/180;A.push([y+S*Math.cos(C),w+S*Math.sin(C)])}return{element:d,points:A,shapeType:"circle"}}case"ellipse":{const y=parseFloat((s=d.getAttribute("cx"))!=null?s:"0"),w=parseFloat((n=d.getAttribute("cy"))!=null?n:"0"),S=parseFloat((o=d.getAttribute("rx"))!=null?o:"0"),A=parseFloat((a=d.getAttribute("ry"))!=null?a:"0");if(!S&&!A)continue;const O=[];for(let C=0;C<=360;C+=12){const k=Math.tan(C/360*Math.PI),W=S*(1-k**2)/(1+k**2),R=A*2*k/(1+k**2);O.push([y+W,w+R])}return{element:d,points:O,shapeType:"ellipse"}}case"line":{const y=parseFloat((c=d.getAttribute("x0"))!=null?c:"0"),w=parseFloat((l=d.getAttribute("y0"))!=null?l:"0"),S=parseFloat((f=d.getAttribute("x1"))!=null?f:"0"),A=parseFloat((h=d.getAttribute("y1"))!=null?h:"0");if(y===S&&w===A)continue;return{element:d,points:[[y,w],[S,A]],shapeType:"polyline"}}case"polygon":case"polyline":{const y=(p=(g=d.getAttribute("points"))==null?void 0:g.split(" ").map(S=>S.split(",").map(parseFloat)))!=null?p:[];if(!y.length)continue;let w="polyline";return d.tagName.toLowerCase()==="polygon"&&(y.push(y[0]),w="polygon"),{element:d,points:y,shapeType:w}}case"rect":{const y=parseFloat((u=d.getAttribute("x"))!=null?u:"0"),w=parseFloat((m=d.getAttribute("y"))!=null?m:"0"),S=parseFloat((v=d.getAttribute("width"))!=null?v:"0"),A=parseFloat((b=d.getAttribute("height"))!=null?b:"0");if(!S||!A)continue;return{element:d,points:[[y,w],[y+S,w],[y+S,w+A],[y,w+A],[y,w]],shapeType:"rect"}}default:continue}return null}function di(t){var i;const e=[];for(let r=0;r<t.length;r++){const s=(i=e[e.length-1])!=null?i:[0,0],n=t[r];switch(n[0]){case"M":case"L":e.push([n[1],n[2]]);continue;case"C":e.push(...li({x:s[0],y:s[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]},{x:n[5],y:n[6]}).map(o=>[o.x,o.y]).slice(1));continue;case"Q":e.push(...ci({x:s[0],y:s[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]}).map(o=>[o.x,o.y]).slice(1));continue}}return e}function gi(t){const e={};if(t.hasAttribute("fill")?(e.fill=t.getAttribute("fill"),t.removeAttribute("fill")):t.style.fill&&(e.fill=t.style.fill),e.fill){const r=$t.exec(e.fill);r&&(e.fillOpacity=parseFloat(r[4]),e.fill=`rgb(${r[1]}, ${r[2]}, ${r[3]})`)}if(t.hasAttribute("fill-opacity")?(e.fillOpacity=parseFloat(t.getAttribute("fill-opacity")),t.removeAttribute("fill-opacity")):t.style.fillOpacity&&(e.fillOpacity=parseFloat(t.style.fillOpacity)),t.hasAttribute("stroke")?(e.stroke=t.getAttribute("stroke"),t.removeAttribute("stroke")):t.style.stroke&&(e.stroke=t.style.stroke),e.stroke){const r=$t.exec(e.stroke);r&&(e.strokeOpacity=parseFloat(r[4]),e.stroke=`rgb(${r[1]}, ${r[2]}, ${r[3]})`)}t.hasAttribute("stroke-opacity")?(e.strokeOpacity=parseFloat(t.getAttribute("stroke-opacity")),t.removeAttribute("stroke-opacity")):t.style.strokeOpacity&&(e.strokeOpacity=parseFloat(t.style.strokeOpacity)),t.hasAttribute("stroke-width")?(e.strokeWidth=t.getAttribute("stroke-width"),t.removeAttribute("stroke-width")):t.style.strokeWidth&&(e.strokeWidth=t.style.strokeWidth),t.hasAttribute("stroke-dasharray")?(e.strokeDasharray=t.getAttribute("stroke-dasharray"),t.removeAttribute("stroke-dasharray")):t.style.strokeDasharray&&(e.strokeDasharray=t.style.strokeDasharray);let i=t;for(;i.tagName.toLowerCase()!=="svg";)if(i=i.parentElement,i===null)throw new Error("Could not find root SVG element");return{svg:i.outerHTML,style:Object.keys(e).length>0?e:void 0}}function j(t,e={}){if(Array.isArray(t))return j(t[0]);if(typeof t=="string"){const[i,r]=t.split("#");return r?j({type:"SpecificResource",source:{id:i,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:i,type:e.typeMap&&e.typeMap[i]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return j(t.items[0]);if(t.type==="SpecificResource"){t.source.type==="Canvas"&&t.source.partOf&&typeof t.source.partOf=="string"&&(t.source.partOf=[{id:t.source.partOf,type:"Manifest"}]);const{selector:i,selectors:r}=t.selector?E(t.selector,e):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:i,selectors:r}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[i,r]=t.id.split("#");return r?j({type:"SpecificResource",source:{...t,id:i},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{...t,id:i},selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}function tt(t,e=!1){if(typeof t=="string"){if(t.startsWith("{"))try{const i=JSON.parse(t);return tt(i)}catch{return[!1,{reason:"Invalid JSON"}]}return[!0]}if(Array.isArray(t)){for(const i of t){const[r,s]=tt(i);if(!r&&s)return[r,s]}return[!0]}return t.type==="Annotation"?[!0]:e&&t.type==="Canvas"&&!t.partOf?[!1,{reason:"Canvas without partOf cannot be loaded"}]:[!0]}function yi(t){return _t(typeof t=="string"?t:JSON.stringify(t))}function Qt(t,e){if(t=t.trim(),t[0]==="{")return e?Promise.resolve(JSON.parse(t)):JSON.parse(t);if(t.startsWith("http")){if(!e)throw new Error("Cannot fetch remote fetch with async=false in parseContentState");return fetch(t).then(i=>i.json())}return Qt(Vt(t),e)}function _t(t){const e=encodeURIComponent(t);return(typeof btoa=="undefined"?Buffer.from(e,"utf-8").toString("base64"):btoa(e)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function Vt(t){const i=mi(t).replace(/-/g,"+").replace(/_/g,"/"),r=typeof atob=="undefined"?Buffer.from(i,"base64").toString("utf-8"):atob(i);return decodeURIComponent(r).trim()}function mi(t){const e=t.length%4;if(e===1)throw new Error("InvalidLengthError: Input base64url string is the wrong length to determine padding");return t+(e?"====".slice(0,4-e):"")}function vi(t){if(!t)throw new Error("Content state is empty");Array.isArray(t)||(t=[t]);let e="vault://virtual-annotation/"+new Date().getTime();const i=[];for(const r of t){if(typeof r=="string")throw new Error("Content state is a [String] type and cannot be inferred");if(r.type==="Annotation"){if(e=r.id,Array.isArray(r.motivation))for(const n of r.motivation);if(Array.isArray(r.target))for(const n of r.target){const o=j(n);i.push(o)}else{const n=j(r.target);i.push(n)}continue}const s=j(r);i.push(s)}return{id:e,type:"Annotation",motivation:["contentState",...t.motivation||[]],target:i,extensions:{}}}function Nt(t){return t.type==="SpecificResource"?[t.source,{selector:t.selector}]:[t,{selector:null}]}function xi(t){function e(s){const n=s?typeof s=="string"?t.get(s):s:null;if(!n)return[];const o=t.get(n.items),a=[];for(const c of o)a.push(...t.get(c.items));return a}function i(s,n=[]){const o=Array.isArray(s)?s:e(s),a=[];let c=null;const l=[];for(const f of o){if(f.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const h=t.get(f.body);for(const g of h){const[p,{selector:u}]=Nt(g),m=(p.type||"unknown").toLowerCase();if(m==="choice"){const v=t.get(p.items),b=n.length?n.map(d=>v.find(y=>y.id===d)).filter(Boolean):[v[0]];b.length===0&&b.push(v[0]),c={type:"single-choice",items:v.map(d=>({id:d.id,label:d.label,selected:b.indexOf(d)!==-1})),label:g.label},h.push(...b);continue}a.indexOf(m)===-1&&a.push(m),l.push({type:m,resource:p,target:f.target,selector:u})}}return{types:a,items:l,choice:c}}function r(s){const{choice:n}=i(s);return n}return{getAllPaintingAnnotations:e,getPaintables:i,extractChoices:r}}function M(t,e,i){e[$]=e[$]||[],e[$].push(t),Object.defineProperty(e,t,{get(){if(typeof e[P][t]=="undefined")return;const r=e[P][t];return r&&I(i.get(e[P][t]),i)},set(r){e[P][t]!==r&&(this[P][t]=r)}})}const P=Symbol.for("_refs_"),H=Symbol.for("_reactive_"),$=Symbol.for("_defined_");function bi(t,e=!1){const i={id:null,[$]:[],[P]:{},[H]:null,is(r){return typeof r=="string"?this.id===r:r.id?r.id===this.id:!1},reactive(){if(!this[H])return this[H]=this.subscribe(()=>this.refresh(),!0),()=>{this.unreactive()}},refresh(){if(this.id){const r=this.unwrap();for(const s of Object.keys(r||{}))this[$].includes(s)?this[P][s]=r[s]:this[s]=r[s]}},unreactive(){this[H]&&(this[H](),this[H]=null)},unwrap(){if(!this.id)throw new Error("Invalid object");return t.get(this.id)},toPresentation3(){return t.toPresentation3(this.unwrap())},toPresentation2(){return t.toPresentation2(this.unwrap())},toJSON(){const r=this;return{...r,items:r.items,annotations:r.annotations,structures:r.structures,seeAlso:r.seeAlso,service:r.service,services:r.services,rendering:r.rendering,partOf:r.partOf,start:r.start,supplementary:r.supplementary,homepage:r.homepage,thumbnail:r.thumbnail,placeholderCanvas:r.placeholderCanvas,accompanyingCanvas:r.accompanyingCanvas,provider:r.provider}},subscribe(r,s=!0){return t.subscribe(()=>this.id?t.get(this.id):null,r,s)}};return M("items",i,t),M("annotations",i,t),M("structures",i,t),M("seeAlso",i,t),M("service",i,t),M("services",i,t),M("rendering",i,t),M("partOf",i,t),M("start",i,t),M("supplementary",i,t),M("homepage",i,t),M("thumbnail",i,t),M("placeholderCanvas",i,t),M("accompanyingCanvas",i,t),M("provider",i,t),M("body",i,t),M("logo",i,t),i}function Et(t){return Array.isArray(t)?t.map(e=>Et(e)):!t||!t.type?t:{id:t.id,type:t.type}}function I(t,e,i=!1){if(Array.isArray(t))return t.map(o=>I(o,e,i));if(!t||!t.type||!t.id)return t;const r=bi(e,i),s=Object.create(r),n=Object.assign(s,t);return i&&n.reactive(),n}function wi(t){return{get(e,i=!1){return I(t.get(e),t,i)},async load(e,i){return I(await t.load(e,i),t)},async loadManifest(e,i){return I(await t.loadManifest(e,i),t)},async loadCollection(e,i){return I(await t.loadCollection(e,i),t)},wrapObject(e){return I(t.get(e,{skipSelfReturn:!1}),t)},isWrapped(e){return!!e[$]}}}function Si(t){return{findFirstCanvasFromRange:e=>et(t,e),findAllCanvasesInRange:e=>U(t,e),findManifestSelectedRange:(e,i)=>Ut(t,e,i),findSelectedRange:(e,i)=>D(t,e,i)}}function et(t,e){for(const i of e.items){if(i.type==="Canvas")return i;if(i.type==="Range"){const r=et(t,t.get(i));if(r)return r}}return null}function U(t,e){const i=[];for(const r of e.items)if(r.type==="Canvas"&&(r.id.indexOf("#")!==-1?i.push({id:r.id.split("#")[0],type:"Canvas"}):i.push(r)),r.type==="Range"&&i.push(...U(t,t.get(r))),r.type==="SpecificResource"){const s=typeof r.source=="string"?r.source:r.source.id;i.push({id:s,type:"Canvas"})}return i}function Ut(t,e,i){for(const r of e.structures){const s=D(t,t.get(r),i);if(s)return s}return null}function D(t,e,i){var r;for(const s of e.items){const n=(r=s.id)==null?void 0:r.split("#")[0];if(s.type==="SpecificResource"&&s.source===i||s.type==="Canvas"&&i===n)return e;if(s.type==="Range"){const o=D(t,t.get(s),i);if(o)return o}}return null}function Ai(t){return{getVisibleCanvasesFromCanvasId:(e,i,r=!1)=>Dt(t,e,i,r),getManifestSequence:(e,i={})=>it(t,e,i)}}function Dt(t,e,i,r=!1){const s=e.behavior,n=i?t.get(i):null;if(!n)return[];const o=n.behavior,a=r?!1:s.includes("paged"),c=a?!1:s.includes("continuous"),l=a||c?!1:s.includes("individuals"),f=o.includes("facing-pages"),h=o.includes("non-paged");if(f||h||l||r)return[{id:n.id,type:"Canvas"}];const[g,p]=it(t,e);if(c)return g;const u=g.findIndex(m=>m.id===i);if(u===-1)return[];for(const m of p)if(m.includes(u))return m.map(v=>g[v]);return[{id:n.id,type:"Canvas"}]}function it(t,e,{disablePaging:i,skipNonPaged:r}={}){const s=e.behavior,n=s.includes("paged"),o=n?!1:s.includes("continuous"),a=n||o?!1:s.includes("individuals"),c=e.type==="Manifest"?e.items:U(t,e);if(o)return[c,[c.map((u,m)=>m)]];if(a||!n||i)return[c,c.map((u,m)=>[m])];const l=[];let f=[];const h=()=>{f.length&&(l.push([...f]),f=[])};let g=0,p=!1;for(let u=0;u<c.length;u++){const m=t.get(c[u]);if(m.behavior.includes("non-paged")){u===g&&g++,r||(h(),l.push([u]),h());continue}if(u===g||m.behavior.includes("facing-pages")){f.length&&(p=!0),h(),l.push([u]),h();continue}if(f.push(u),p){h(),p=!1;continue}f.length>1&&h()}return f.length&&h(),[c,l]}x.buildLocaleString=qt,x.createEventsHelper=L,x.createObjectsHelper=wi,x.createPaintingAnnotationsHelper=xi,x.createRangeHelper=Si,x.createSequenceHelper=Ai,x.createStylesHelper=Zt,x.createThumbnailHelper=Xe,x.decodeContentState=Vt,x.encodeContentState=_t,x.expandTarget=j,x.findAllCanvasesInRange=U,x.findFirstCanvasFromRange=et,x.findManifestSelectedRange=Ut,x.findSelectedRange=D,x.getClosestLanguage=Wt,x.getManifestSequence=it,x.getValue=Ge,x.getVisibleCanvasesFromCanvasId=Dt,x.normaliseContentState=vi,x.parseContentState=Qt,x.parseSelector=E,x.parseSpecificResource=Nt,x.serialiseContentState=yi,x.unwrapObject=Et,x.validateContentState=tt,x.wrapObject=I,Object.defineProperties(x,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
//# sourceMappingURL=index.umd.js.map
{
"name": "@iiif/vault-helpers",
"version": "0.9.10",
"version": "0.9.11",
"license": "MIT",

@@ -54,2 +54,10 @@ "main": "dist/cjs/index.js",

"import": "./dist/objects/esm/objects.mjs"
},
"./ranges": {
"require": "./dist/ranges/cjs/ranges.js",
"import": "./dist/ranges/esm/ranges.mjs"
},
"./sequences": {
"require": "./dist/sequences/cjs/sequences.js",
"import": "./dist/sequences/esm/sequences.mjs"
}

@@ -88,2 +96,8 @@ },

".build/types/objects.d.ts"
],
"ranges": [
".build/types/ranges.d.ts"
],
"sequences": [
".build/types/sequences.d.ts"
]

@@ -90,0 +104,0 @@ }

@@ -25,3 +25,3 @@ # Vault helpers

```ts
import { getValue } from '@iiif/vault-helpers/styles';
import { getValue } from '@iiif/vault-helpers/i18n';

@@ -43,3 +43,2 @@ // Simple utility.

);
```

@@ -46,0 +45,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc