react-iiif-vault 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),v=require("react"),Re=require("@atlas-viewer/atlas"),W=require("@iiif/parser"),Se=require("@atlas-viewer/iiif-image-api");function ji(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const at=ji(v);function yt(e,t){return yt=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},yt(e,t)}function Ei(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,yt(e,t)}var Pi=function(t,r){return t===void 0&&(t=[]),r===void 0&&(r=[]),t.length!==r.length||t.some(function(n,i){return!Object.is(n,r[i])})},Yt={error:null},Oi=function(e){Ei(t,e);function t(){for(var n,i=arguments.length,s=new Array(i),a=0;a<i;a++)s[a]=arguments[a];return n=e.call.apply(e,[this].concat(s))||this,n.state=Yt,n.resetErrorBoundary=function(){for(var o,u=arguments.length,d=new Array(u),l=0;l<u;l++)d[l]=arguments[l];n.props.onReset==null||(o=n.props).onReset.apply(o,d),n.reset()},n}t.getDerivedStateFromError=function(i){return{error:i}};var r=t.prototype;return r.reset=function(){this.setState(Yt)},r.componentDidCatch=function(i,s){var a,o;(a=(o=this.props).onError)==null||a.call(o,i,s)},r.componentDidUpdate=function(i,s){var a=this.state.error,o=this.props.resetKeys;if(a!==null&&s.error!==null&&Pi(i.resetKeys,o)){var u,d;(u=(d=this.props).onResetKeysChange)==null||u.call(d,i.resetKeys,o),this.reset()}},r.render=function(){var i=this.state.error,s=this.props,a=s.fallbackRender,o=s.FallbackComponent,u=s.fallback;if(i!==null){var d={error:i,resetErrorBoundary:this.resetErrorBoundary};if(at.isValidElement(u))return u;if(typeof a=="function")return a(d);if(o)return at.createElement(o,d);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},t}(at.Component);const Li={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},Je=v.createContext(Li),se=()=>v.useContext(Je);function he({value:e,children:t}){const r=se(),n=v.useMemo(()=>({...r,...e}),[e,r]);return m.jsx(Je.Provider,{value:n,children:t})}var Fi=Object.defineProperty,$i=(e,t,r)=>t in e?Fi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,pe=(e,t,r)=>($i(e,typeof t!="symbol"?t+"":t,r),r);const q=function(e){return function(){const t={type:e,getType:()=>e,toString:()=>e};return(r,n)=>({...t,...r!==void 0&&{payload:r},...n!==void 0&&{meta:n}})}},dr="@iiif/IMPORT_ENTITIES",hr="@iiif/MODIFY_ENTITY_FIELD",vr="@iiif/REORDER_ENTITY_FIELD",yr="@iiif/ADD_REFERENCE",gt="@iiif/UPDATE_REFERENCE",gr="@iiif/REMOVE_REFERENCE",mr="@iiif/ADD_METADATA",xr="@iiif/REMOVE_METADATA",mt="@iiif/UPDATE_METADATA",br="@iiif/REORDER_METADATA",Ar=q(dr)(),Di=q(hr)(),qi=q(vr)(),Vi=q(yr)(),_i=q(gr)(),Ui=q(gt)(),Hi=q(mr)(),Ni=q(mt)(),Bi=q(xr)(),zi=q(br)(),Wi={importEntities:Ar,modifyEntityField:Di,reorderEntityField:qi,addReference:Vi,removeReference:_i,updateReference:Ui,addMetadata:Hi,removeMetadata:Bi,updateMetadata:Ni,reorderMetadata:zi},Sr="@iiif/ADD_MAPPING",wr="@iiif/ADD_MAPPINGS",Qi=q(Sr)(),Yi=q(wr)(),Cr="@iiif/SET_META_VALUE",Mr="@iiif/SET_META_VALUE_DYNAMIC",Rr="@iiif/UNSET_META_VALUE",Gi=q(Cr)(),Ji=q(Mr)(),Ki=q(Rr)(),Gt={setMetaValue:Gi,setMetaValueDynamic:Ji,unsetMetaValue:Ki},xt="RESOURCE_ERROR",Ir="RESOURCE_LOADING",bt="RESOURCE_READY",kr="@iiif/REQUEST_RESOURCE",Tr="@iiif/REQUEST_ERROR",jr="@iiif/REQUEST_MISMATCH",Er="@iiif/REQUEST_COMPLETE",Zi="@iiif/REQUEST_OFFLINE_RESOURCE",Xi=q(kr)(),Pr=q(Tr)(),es=q(jr)(),ts=q(Er)(),kt="@iiif/BATCH",rs="@iiif/BATCH_IMPORT",At=q(kt)(),ns=(e,t)=>{const{entities:r,resource:n,mapping:i}=W.normalize(t);if(n.id===void 0)return[Pr({id:e,message:"ID is not defined in resource."})];const s=[Ar({entities:r}),Yi({mapping:i})];return n.id!==e&&(s.push(Qi({id:e,type:n.type})),s.push(es({requestId:e,actualId:n.id}))),s.push(ts({id:e})),s},Jt=Number.isNaN||function(e){return typeof e=="number"&&e!==e};function is(e,t){return!!(e===t||Jt(e)&&Jt(t))}function Kt(e,t){if(!Array.isArray(e)||!Array.isArray(t))return e===t;if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!is(e[r],t[r]))return!1;return!0}function ot(e,t,r){const n=e.iiif.requests[t],i=e.iiif.mapping[t];if(!i||!e.iiif.entities[i][n.resourceUri])return;const s=e.iiif.entities[i][n.resourceUri];if(s&&s[W.HAS_PART]){const a=s[W.HAS_PART].find(o=>r?o[W.PART_OF]===r.id:o[W.PART_OF]===s.id);return W.frameResource(s,a)}return s}function Zt(e,t,{waitTimeout:r=30}={}){return async(n,i)=>{const s=e.getStore(),a=s.getState(),o=a.iiif.requests[n];if(o)switch(o.loadingState){case xt:break;case Ir:{let u,d=!1;try{const l=await Promise.race([new Promise((p,g)=>{d||(u=s.subscribe(()=>{const b=s.getState();if(b.iiif.requests[n].loadingState===xt){g();return}if(b.iiif.requests[n].loadingState===bt){const h=ot(b,n);h?p(h):g()}}))}),new Promise((p,g)=>setTimeout(()=>{d=!0,g()},r*60*1e3))]);if(u&&u(),l)return l}catch{u&&u();break}break}case bt:{const u=ot(a,n);if(u)return u;break}}e.dispatch(Xi({id:n}));try{const u=await t(n,i);!u.id&&!u["@id"]&&(u["@type"]&&(u["@id"]=n),u.id=n);const d=ns(n,u);return e.dispatch(At({actions:d})),ot(s.getState(),n)}catch(u){throw e.dispatch(Pr({id:n,message:u.toString()})),u}}}function Or(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}const Xt=e=>{let t;const r=new Set,n=(a,o)=>{const u=typeof a=="function"?a(t):a;if(!Object.is(u,t)){const d=t;t=o??typeof u!="object"?u:Object.assign({},t,u),r.forEach(l=>l(t,d))}},i=()=>t,s={setState:n,getState:i,subscribe:a=>(r.add(a),()=>r.delete(a)),destroy:()=>{r.clear()}};return t=e(n,i,s),s},ss=e=>e?Xt(e):Xt,as=(e,t)=>(r,n,i)=>(i.dispatch=s=>(r(a=>e(a,s),!1,s),s),i.dispatchFromDevtools=!0,{dispatch:(...s)=>i.dispatch(...s),...t}),os=as,St=new Map,Ue=e=>{const t=St.get(e);return t?Object.fromEntries(Object.entries(t.stores).map(([r,n])=>[r,n.getState()])):{}},cs=(e,t,r)=>{if(e===void 0)return{type:"untracked",connection:t.connect(r)};const n=St.get(r.name);if(n)return{type:"tracked",store:e,...n};const i={connection:t.connect(r),stores:{}};return St.set(r.name,i),{type:"tracked",store:e,...i}},us=(e,t={})=>(r,n,i)=>{const{enabled:s,anonymousActionType:a,store:o,...u}=t;let d;try{d=(s??!1)&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!d)return e(r,n,i);const{connection:l,...p}=cs(o,d,u);let g=!0;i.setState=(x,A,S)=>{const w=r(x,A);if(!g)return w;const M=S===void 0?{type:a||"anonymous"}:typeof S=="string"?{type:S}:S;return o===void 0?(l==null||l.send(M,n()),w):(l==null||l.send({...M,type:`${o}/${M.type}`},{...Ue(u.name),[o]:i.getState()}),w)};const b=(...x)=>{const A=g;g=!1,r(...x),g=A},h=e(i.setState,n,i);if(p.type==="untracked"?l==null||l.init(h):(p.stores[p.store]=i,l==null||l.init(Object.fromEntries(Object.entries(p.stores).map(([x,A])=>[x,x===p.store?h:A.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){const x=i.dispatch;i.dispatch=(...A)=>{x(...A)}}return l.subscribe(x=>{var A;switch(x.type){case"ACTION":if(typeof x.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return ct(x.payload,S=>{if(S.type==="__setState"){if(o===void 0){b(S.state);return}Object.keys(S.state).length!==1&&console.error(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react/jsx-runtime"),y=require("react"),Re=require("@atlas-viewer/atlas"),W=require("@iiif/parser"),Se=require("@atlas-viewer/iiif-image-api");function Li(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:()=>t[r]})}}return e.default=t,Object.freeze(e)}const at=Li(y);function vt(t,e){return vt=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},vt(t,e)}function Fi(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,vt(t,e)}var $i=function(e,r){return e===void 0&&(e=[]),r===void 0&&(r=[]),e.length!==r.length||e.some(function(n,i){return!Object.is(n,r[i])})},Gt={error:null},Di=function(t){Fi(e,t);function e(){for(var n,i=arguments.length,s=new Array(i),a=0;a<i;a++)s[a]=arguments[a];return n=t.call.apply(t,[this].concat(s))||this,n.state=Gt,n.resetErrorBoundary=function(){for(var o,u=arguments.length,d=new Array(u),l=0;l<u;l++)d[l]=arguments[l];n.props.onReset==null||(o=n.props).onReset.apply(o,d),n.reset()},n}e.getDerivedStateFromError=function(i){return{error:i}};var r=e.prototype;return r.reset=function(){this.setState(Gt)},r.componentDidCatch=function(i,s){var a,o;(a=(o=this.props).onError)==null||a.call(o,i,s)},r.componentDidUpdate=function(i,s){var a=this.state.error,o=this.props.resetKeys;if(a!==null&&s.error!==null&&$i(i.resetKeys,o)){var u,d;(u=(d=this.props).onResetKeysChange)==null||u.call(d,i.resetKeys,o),this.reset()}},r.render=function(){var i=this.state.error,s=this.props,a=s.fallbackRender,o=s.FallbackComponent,u=s.fallback;if(i!==null){var d={error:i,resetErrorBoundary:this.resetErrorBoundary};if(at.isValidElement(u))return u;if(typeof a=="function")return a(d);if(o)return at.createElement(o,d);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},e}(at.Component);const qi={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},Je=y.createContext(qi),se=()=>y.useContext(Je);function he({value:t,children:e}){const r=se(),n=y.useMemo(()=>({...r,...t}),[t,r]);return g.jsx(Je.Provider,{value:n,children:e})}var Vi=Object.defineProperty,_i=(t,e,r)=>e in t?Vi(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,pe=(t,e,r)=>(_i(t,typeof e!="symbol"?e+"":e,r),r);const q=function(t){return function(){const e={type:t,getType:()=>t,toString:()=>t};return(r,n)=>({...e,...r!==void 0&&{payload:r},...n!==void 0&&{meta:n}})}},hr="@iiif/IMPORT_ENTITIES",yr="@iiif/MODIFY_ENTITY_FIELD",vr="@iiif/REORDER_ENTITY_FIELD",gr="@iiif/ADD_REFERENCE",gt="@iiif/UPDATE_REFERENCE",mr="@iiif/REMOVE_REFERENCE",xr="@iiif/ADD_METADATA",br="@iiif/REMOVE_METADATA",mt="@iiif/UPDATE_METADATA",Ar="@iiif/REORDER_METADATA",Sr=q(hr)(),Ui=q(yr)(),Hi=q(vr)(),Ni=q(gr)(),Bi=q(mr)(),zi=q(gt)(),Wi=q(xr)(),Qi=q(mt)(),Yi=q(br)(),Gi=q(Ar)(),Ji={importEntities:Sr,modifyEntityField:Ui,reorderEntityField:Hi,addReference:Ni,removeReference:Bi,updateReference:zi,addMetadata:Wi,removeMetadata:Yi,updateMetadata:Qi,reorderMetadata:Gi},wr="@iiif/ADD_MAPPING",Cr="@iiif/ADD_MAPPINGS",Ki=q(wr)(),Zi=q(Cr)(),Mr="@iiif/SET_META_VALUE",Rr="@iiif/SET_META_VALUE_DYNAMIC",Ir="@iiif/UNSET_META_VALUE",Xi=q(Mr)(),es=q(Rr)(),ts=q(Ir)(),Jt={setMetaValue:Xi,setMetaValueDynamic:es,unsetMetaValue:ts},xt="RESOURCE_ERROR",kr="RESOURCE_LOADING",bt="RESOURCE_READY",Tr="@iiif/REQUEST_RESOURCE",jr="@iiif/REQUEST_ERROR",Pr="@iiif/REQUEST_MISMATCH",Er="@iiif/REQUEST_COMPLETE",rs="@iiif/REQUEST_OFFLINE_RESOURCE",ns=q(Tr)(),At=q(jr)(),is=q(Pr)(),ss=q(Er)(),Tt="@iiif/BATCH",as="@iiif/BATCH_IMPORT",St=q(Tt)(),os=(t,e)=>{const{entities:r,resource:n,mapping:i}=W.normalize(e);if(n.id===void 0)return[At({id:t,message:"ID is not defined in resource."})];const s=[Sr({entities:r}),Zi({mapping:i})];return n.id!==t&&(s.push(Ki({id:t,type:n.type})),s.push(is({requestId:t,actualId:n.id}))),s.push(ss({id:t})),s},Kt=Number.isNaN||function(t){return typeof t=="number"&&t!==t};function cs(t,e){return!!(t===e||Kt(t)&&Kt(e))}function Zt(t,e){if(!Array.isArray(t)||!Array.isArray(e))return t===e;if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(!cs(t[r],e[r]))return!1;return!0}function ot(t,e,r){const n=t.iiif.requests[e],i=t.iiif.mapping[e];if(!i||!t.iiif.entities[i][n.resourceUri])return;const s=t.iiif.entities[i][n.resourceUri];if(s&&s[W.HAS_PART]){const a=s[W.HAS_PART].find(o=>r?o[W.PART_OF]===r.id:o[W.PART_OF]===s.id);return W.frameResource(s,a)}return s}function us(t){return t&&typeof t.then=="function"}function Xt(t,e,{waitTimeout:r=30}={}){return(n,i)=>{const s=t.getStore(),a=s.getState(),o=a.iiif.requests[n];if(o){if(o.loadingState===bt){const d=ot(a,n);if(d)return d}switch(o.loadingState){case xt:break;case kr:return(async()=>{let d,l=!1;try{const p=await Promise.race([new Promise((m,A)=>{l||(d=s.subscribe(()=>{const h=s.getState();if(h.iiif.requests[n].loadingState===xt){A();return}if(h.iiif.requests[n].loadingState===bt){const x=ot(h,n);x?m(x):A()}}))}),new Promise((m,A)=>setTimeout(()=>{l=!0,A()},r*60*1e3))]);if(d&&d(),p)return p}catch{d&&d()}})()}}t.dispatch(ns({id:n}));const u=d=>{if(!d)return;!d.id&&!d["@id"]&&(d["@type"]&&(d["@id"]=n),d.id=n);const l=os(n,d);return t.dispatch(St({actions:l})),ot(s.getState(),n)};try{const d=e(n,i);return us(d)?(async()=>{try{return u(await d)}catch(l){throw t.dispatch(At({id:n,message:l.toString()})),l}})():u(d)}catch(d){throw t.dispatch(At({id:n,message:d.toString()})),d}}}function Or(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}const er=t=>{let e;const r=new Set,n=(a,o)=>{const u=typeof a=="function"?a(e):a;if(!Object.is(u,e)){const d=e;e=o??typeof u!="object"?u:Object.assign({},e,u),r.forEach(l=>l(e,d))}},i=()=>e,s={setState:n,getState:i,subscribe:a=>(r.add(a),()=>r.delete(a)),destroy:()=>{r.clear()}};return e=t(n,i,s),s},ls=t=>t?er(t):er,fs=(t,e)=>(r,n,i)=>(i.dispatch=s=>(r(a=>t(a,s),!1,s),s),i.dispatchFromDevtools=!0,{dispatch:(...s)=>i.dispatch(...s),...e}),ps=fs,wt=new Map,Ue=t=>{const e=wt.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([r,n])=>[r,n.getState()])):{}},ds=(t,e,r)=>{if(t===void 0)return{type:"untracked",connection:e.connect(r)};const n=wt.get(r.name);if(n)return{type:"tracked",store:t,...n};const i={connection:e.connect(r),stores:{}};return wt.set(r.name,i),{type:"tracked",store:t,...i}},hs=(t,e={})=>(r,n,i)=>{const{enabled:s,anonymousActionType:a,store:o,...u}=e;let d;try{d=(s??!1)&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!d)return t(r,n,i);const{connection:l,...p}=ds(o,d,u);let m=!0;i.setState=(x,b,S)=>{const w=r(x,b);if(!m)return w;const M=S===void 0?{type:a||"anonymous"}:typeof S=="string"?{type:S}:S;return o===void 0?(l==null||l.send(M,n()),w):(l==null||l.send({...M,type:`${o}/${M.type}`},{...Ue(u.name),[o]:i.getState()}),w)};const A=(...x)=>{const b=m;m=!1,r(...x),m=b},h=t(i.setState,n,i);if(p.type==="untracked"?l==null||l.init(h):(p.stores[p.store]=i,l==null||l.init(Object.fromEntries(Object.entries(p.stores).map(([x,b])=>[x,x===p.store?h:b.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){const x=i.dispatch;i.dispatch=(...b)=>{x(...b)}}return l.subscribe(x=>{var b;switch(x.type){case"ACTION":if(typeof x.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return ct(x.payload,S=>{if(S.type==="__setState"){if(o===void 0){A(S.state);return}Object.keys(S.state).length!==1&&console.error(`
2
2
  [zustand devtools middleware] Unsupported __setState action format.
3
3
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
4
4
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
5
- `);const w=S.state[o];if(w==null)return;JSON.stringify(i.getState())!==JSON.stringify(w)&&b(w);return}i.dispatchFromDevtools&&typeof i.dispatch=="function"&&i.dispatch(S)});case"DISPATCH":switch(x.payload.type){case"RESET":return b(h),o===void 0?l==null?void 0:l.init(i.getState()):l==null?void 0:l.init(Ue(u.name));case"COMMIT":if(o===void 0){l==null||l.init(i.getState());return}return l==null?void 0:l.init(Ue(u.name));case"ROLLBACK":return ct(x.state,S=>{if(o===void 0){b(S),l==null||l.init(i.getState());return}b(S[o]),l==null||l.init(Ue(u.name))});case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return ct(x.state,S=>{if(o===void 0){b(S);return}JSON.stringify(i.getState())!==JSON.stringify(S[o])&&b(S[o])});case"IMPORT_STATE":{const{nextLiftedState:S}=x.payload,w=(A=S.computedStates.slice(-1)[0])==null?void 0:A.state;if(!w)return;b(o===void 0?w:w[o]),l==null||l.send(null,S);return}case"PAUSE_RECORDING":return g=!g}return}}),h},ls=us,ct=(e,t)=>{let r;try{r=JSON.parse(e)}catch(n){console.error("[zustand devtools middleware] Could not parse the received json",n)}r!==void 0&&t(r)},fs=e=>(t,r,n)=>{const i=n.subscribe;return n.subscribe=(s,a,o)=>{let u=s;if(a){const d=(o==null?void 0:o.equalityFn)||Object.is;let l=s(n.getState());u=p=>{const g=s(p);if(!d(l,g)){const b=l;a(l=g,b)}},o!=null&&o.fireImmediately&&a(l,l)}return i(u)},e(t,r,n)},ps=fs,ds=(e={},t)=>{switch(t.type){case Sr:return{...e,[t.payload.id]:t.payload.type};case wr:return{...e,...t.payload.mapping};default:return e}};function ut(e,t,r,n){return!(!e[r]||!e[r][t]||!e[r][t][n]||!Array.isArray(e[r][t][n]))}function hs(e,t){const r={},n=[];for(const[i,s]of Object.entries(e||{})){n.push(i);const a=(t||{})[i];if(!a||a.length===0){r[i]=s;continue}r[i]=a}for(const[i,s]of Object.entries(t||{}))n.indexOf(i)===-1&&(r[i]=s);return r}function I(e){return e.payload}function lt(e,t){return typeof e>"u"?t:e}const vs=(e=Or(),t)=>{var r;const n=(i,s)=>({...e,[I(t).type]:{...e[I(t).type],[I(t).id]:{...i,...s}}});switch(t.type){case hr:{if(!e[I(t).type]||!e[I(t).type][I(t).id])return e;const i=e[I(t).type][I(t).id];return typeof i=="string"?e:n(i,{[I(t).key]:I(t).value})}case vr:{if(!ut(e,I(t).id,I(t).type,I(t).key))return e;const i=e[I(t).type][I(t).id];if(typeof i=="string")return e;const s=Array.from(i[I(t).key]),[a]=s.splice(I(t).startIndex,1);return s.splice(I(t).endIndex,0,a),n(i,{[I(t).key]:s})}case dr:{const i=Object.keys(I(t).entities),s={...e};for(const a of i){const o=I(t).entities[a],u={...e[a]||{}};let d=!1;const l=Object.keys(o||{})||[];if(o&&l){for(const p of l)d=!0,u[p]=e[a][p]?hs(e[a][p],o[p]):o[p];d&&(s[a]=u)}}return s}case yr:{if(!ut(e,I(t).id,I(t).type,I(t).key))return e;const i=e[I(t).type][I(t).id],s=Array.from(i[I(t).key]);return s.splice(lt(I(t).index,s.length+1),0,I(t).reference),n(i,{[I(t).key]:s})}case gt:case gr:{if(!ut(e,I(t).id,I(t).type,I(t).key))return e;const i=e[I(t).type][I(t).id],s=Array.from(i[I(t).key]),a=lt(I(t).index,s.findIndex(o=>o&&o.id===I(t).reference.id));return a===-1||((r=s[a])==null?void 0:r.id)!==I(t).reference.id?e:(t.type===gt?s.splice(a,1,I(t).reference):s.splice(a,1),n(i,{[I(t).key]:s}))}case mr:{const i=e[I(t).type][I(t).id];if(!i)return e;const s=Array.from(i.metadata||[]),a=I(t);return s.splice(lt(t.payload.beforeIndex,s.length+1),0,{label:a.label,value:a.label}),n(i,{metadata:s})}case br:{const i=e[I(t).type][I(t).id];if(typeof i=="string"||!i)return e;const s=Array.from(i.metadata||[]),[a]=s.splice(I(t).startIndex,1);return s.splice(I(t).endIndex,0,a),n(i,{metadata:s})}case mt:case xr:{const i=e[I(t).type][I(t).id],s=Array.from(i.metadata||[]),a=I(t).atIndex;return typeof a>"u"||a===-1||!s[a]?e:(t.type===mt?s.splice(a,1,{label:I(t).label,value:I(t).value}):s.splice(a,1),n(i,{metadata:s}))}default:return e}},ys=(e={},t)=>{switch(t.type){case kr:case Zi:return{...e,[t.payload.id]:{requestUri:t.payload.id,loadingState:Ir,uriMismatch:!1,resourceUri:t.payload.id}};case jr:return{...e,[t.payload.requestId]:{...e[t.payload.requestId]||{},uriMismatch:!0,resourceUri:t.payload.actualId},[t.payload.actualId]:{requestUri:t.payload.requestId,loadingState:e[t.payload.requestId].loadingState,uriMismatch:!0,resourceUri:t.payload.actualId}};case Tr:return{...e,[t.payload.id]:{...e[t.payload.id]||{},loadingState:xt,error:t.payload.message}};case Er:return{...e,[t.payload.id]:{...e[t.payload.id]||{},loadingState:bt,error:void 0}}}return e},gs=(e={},t)=>{const{id:r,updateValue:n,value:i,meta:s,key:a}=t&&t.payload||{};switch(t.type){case Cr:return{...e,[r]:{...e[r]||{},[s]:{...e[r]?e[r][s]||{}:{},[a]:i}}};case Mr:return{...e,[r]:{...e[r]||{},[s]:{...e[r]?e[r][s]||{}:{},[a]:e[r]&&e[r][s]?n(e[r][s][a]):n(void 0)}}};case Rr:return e[r]&&e[r][s]&&e[r][s][a]?{...e,[r]:{...e[r]||{},[s]:{...e[r]?e[r][s]||{}:{},[a]:void 0}}}:e;default:return e}};function Lr(e={}){const t=Object.keys(e);return function(r={},n){let i=!1;const s={};for(let a=0;a<t.length;a++){const o=t[a];s[o]=e[o](r[o],n),i=i||s[o]!==r[o]}return i?s:r}}function ms(e){return(t,r)=>r&&r.type===kt?r.payload.actions.reduce(e,t):r&&r.type===rs?{...t,iiif:{...t.iiif,...r.payload.state}}:e(t,r)}const xs=Lr({mapping:ds,entities:vs,requests:ys,meta:gs});function bs(){return{iiif:{entities:Or(),meta:{},mapping:{},requests:{}}}}function As(e={}){const{enableDevtools:t=!1,iiifStoreName:r="iiif",defaultState:n=bs(),customReducers:i={}}=e,s=ms(Lr({[r]:xs,...i}));return ss(ps(ls(os(s,n),{enabled:t})))}function Ss(e){return{all:e=e||new Map,on:function(t,r){var n=e.get(t);n?n.push(r):e.set(t,[r])},off:function(t,r){var n=e.get(t);n&&(r?n.splice(n.indexOf(r)>>>0,1):e.set(t,[]))},emit:function(t,r){var n=e.get(t);n&&n.slice().map(function(i){i(r)}),(n=e.get("*"))&&n.slice().map(function(i){i(t,r)})}}}function z(e,t,r,n=!0){t[we]=t[we]||[],t[we].push(e);const i=new Map;Object.defineProperty(t,e,{enumerable:n,get(){if(typeof t[xe][e]>"u")return;const s=t[xe][e];if(!s)return s;const a=r.get(t[xe][e],{parent:this.id?{id:this.id,type:this.type}:void 0});return i.has(a)||(i.clear(),i.set(a,be(a,r))),i.get(a)},set(s){t[xe][e]!==s&&(this[me]?r.modifyEntityField({id:this.id,type:this.type},e,Fr(s)):this[xe][e]=s)}})}const xe=Symbol.for("_refs_"),me=Symbol.for("_reactive_"),we=Symbol.for("_defined_"),er=Symbol.for("_parent_");function ws(e,t=!1,r){const n={id:"",type:"unknown",[we]:[],[xe]:{},[er]:r||null,[me]:null,is(i){return typeof i=="string"?this.id===i:i.id?i.id===this.id:!1},reactive(){if(!this[me])return this[me]=this.subscribe(()=>this.refresh(),!0),()=>{this.unreactive()}},refresh(){if(this.id){const i=this.unwrap();for(const s of Object.keys(i||{}))this[we].includes(s)?this[xe][s]=i[s]:this[s]=i[s]}},unreactive(){this[me]&&(this[me](),this[me]=null)},unwrap(){if(!this.id)throw new Error("Invalid object");const i=this[er];return e.get(this.id,{parent:i?{id:i,type:"unknown"}:void 0})},toPresentation3(){return e.toPresentation3(this.unwrap())},toPresentation2(){return e.toPresentation2(this.unwrap())},valueOf(){return this.unwrap()},toJSON(){const i=this;return{...i,items:i.items,annotations:i.annotations,structures:i.structures,seeAlso:i.seeAlso,service:i.service,services:i.services,rendering:i.rendering,partOf:i.partOf,start:i.start,supplementary:i.supplementary,homepage:i.homepage,thumbnail:i.thumbnail,placeholderCanvas:i.placeholderCanvas,accompanyingCanvas:i.accompanyingCanvas,provider:i.provider}},subscribe(i,s=!0){return e.subscribe(()=>this.id?e.get(this.id):null,i,s)}};return z("items",n,e),z("annotations",n,e),z("structures",n,e),z("seeAlso",n,e),z("rendering",n,e),z("partOf",n,e),z("start",n,e,!1),z("supplementary",n,e),z("homepage",n,e),z("thumbnail",n,e),z("placeholderCanvas",n,e,!1),z("accompanyingCanvas",n,e,!1),z("provider",n,e),z("body",n,e),z("logo",n,e),n}function Cs(e){return!!e[we]}function Fr(e){return Array.isArray(e)?e.map(t=>Fr(t)):!e||!e.type?e:{id:e.id,type:e.type}}function be(e,t,r=!1,n){if(Array.isArray(e))return e.map(o=>be(o,t,r));if(!e||!e.type||!e.id)return e;const i=ws(t,r),s=Object.create(i),a=Object.assign(s,e);return r&&a.reactive(),a}function tr(e){switch(e){case"Image":case"Video":case"Sound":case"Dataset":case"Text":case"Composite":case"List":case"Independents":case"Audience":return"ContentResource";case"ImageService1":case"ImageService2":case"ImageService3":return"Service"}return e}let wt=class{constructor(t,r){pe(this,"options"),pe(this,"store"),pe(this,"emitter"),pe(this,"isBatching",!1),pe(this,"batchQueue",[]),pe(this,"remoteFetcher"),pe(this,"staticFetcher"),pe(this,"defaultFetcher",n=>fetch(n).then(i=>i.json())),this.options=Object.assign({reducers:{},customFetcher:this.defaultFetcher,enableDevtools:!0},t||{}),this.store=r||As({customReducers:this.options.reducers,defaultState:this.options.defaultState,enableDevtools:this.options.enableDevtools}),this.emitter=Ss(),this.remoteFetcher=Zt(this,this.options.customFetcher),this.staticFetcher=Zt(this,(n,i)=>i)}batch(t){this.isBatching=!0;try{t(this),this.isBatching=!1,this.dispatch(At({actions:this.batchQueue}))}catch(r){throw this.batchQueue=[],this.isBatching=!1,r}this.batchQueue=[]}async asyncBatch(t){this.isBatching=!0;try{await t(this),this.isBatching=!1,this.dispatch(At({actions:this.batchQueue}))}catch(r){throw this.batchQueue=[],this.isBatching=!1,r}this.batchQueue=[]}modifyEntityField(t,r,n){this.dispatch(Wi.modifyEntityField({id:t.id,type:t.type,key:r,value:n}))}dispatch(t){if(this.isBatching)this.batchQueue.push(t);else{if(t.type===kt){for(const i of t.payload.actions)this.emitter.emit(i.type,{action:i,state:this.store.getState()});this.store.dispatch(t);const n=this.getState();for(const i of t.payload.actions)this.emitter.emit(`after:${i.type}`,{action:i,state:n});return}this.emitter.emit(t.type,{action:t,state:this.store.getState()}),this.store.dispatch(t);const r=this.store.getState();this.emitter.emit(`after:${t.type}`,{action:t,state:r});return}}on(t,r){return this.emitter.on(t,r),()=>{this.emitter.off(t,r)}}serialize(t,r){return W.serialize(this.getState().iiif,t,r)}toPresentation2(t){return this.serialize(t,W.serializeConfigPresentation2)}toPresentation3(t){return this.serialize(t,W.serializeConfigPresentation3)}hydrate(t,r,n={}){return this.get(t,r,{...n,skipSelfReturn:!1})}get(t,r,n={}){typeof r!="string"&&(n=r||{},r=void 0);const{skipSelfReturn:i=!0}=n||{};let s=n.parent?typeof n.parent=="string"?n.parent:n.parent.id:void 0;if(Array.isArray(t))return t.map(p=>this.get(p,n));const a=this.getState();if(W.isSpecificResource(t)&&!n.preserveSpecificResources&&(t=t.source),typeof t=="string"){const p=tr(r||a.iiif.mapping[t]);if(!p)return i?null:{id:t,type:"unknown"};t={id:t,type:p}}if(t&&t.partOf&&!s&&!n.skipPartOfCheck){const p=Array.isArray(t.partOf)?t.partOf[0]:t.partOf;p&&(typeof p=="string"&&(s=p),typeof p.id=="string"&&(s=p.id))}const o=tr(r||(t==null?void 0:t.type)),u=t==null?void 0:t.id,d=a.iiif.entities[o];if(!d){const p=a.iiif.requests[u];return p&&p.resourceUri!==u?this.get(p.resourceUri,n):i?null:t}const l=d[t.id];if(l&&l[W.HAS_PART]){const p=l[W.HAS_PART].find(g=>s?g[W.PART_OF]===s:g[W.PART_OF]===l.id);return W.frameResource(l,p)}return d[t.id]||(i?null:t)}select(t){return t(this.getState())}getStore(){return this.store}getState(){return this.store.getState()}deep(t,r){if(typeof t>"u")return this.get(r,{skipSelfReturn:!1});if(typeof t=="function")try{const i=t(this.get(r,{skipSelfReturn:!1})),s=a=>this.deep(a,i);return s.size=Array.isArray(i)?i.length:1,s}catch{const i=s=>this.deep(s,void 0);return i.size=0,i}const n=i=>this.deep(i,t);return n.size=Array.isArray(t)?t.length:1,n}loadManifest(t,r){const n=typeof t=="string"?t:t.id;return this.load(n,r)}loadCollection(t,r){const n=typeof t=="string"?t:t.id;return this.load(n,r)}load(t,r){const n=typeof t=="string"?t:t.id;return r?this.staticFetcher(n,r):this.remoteFetcher(n)}areInputsEqual(t,r){return Kt(t,r)}subscribe(t,r,n){return typeof n>"u"&&(typeof r>"u"||r===!1||r===!0)&&(n=r,r=t,t=i=>i),this.store.subscribe(t,i=>r(i,this),{equalityFn:Kt,fireImmediately:!n})}async ensureLoaded(t){const r=typeof t=="string"?t:t.id;this.requestStatus(r)||await this.load(r)}requestStatus(t){return this.select(r=>r.iiif.requests[t])}getResourceMeta(t,r){const n=this.getState().iiif.meta[t];if(n)return r?n[r]:n}getObject(t,r,n={}){const{reactive:i,...s}=n;return be(this.get(t,r,s),this,i)}async loadObject(t,r){return be(await this.load(t,r),this)}async loadManifestObject(t,r){return be(await this.loadManifest(t,r),this)}async loadCollectionObject(t,r){return be(await this.loadCollection(t,r),this)}wrapObject(t){return be(this.get(t,{skipSelfReturn:!1}),this)}isWrapped(t){return Cs(t)}setMetaValue([t,r,n],i){this.dispatch(typeof i=="function"?Gt.setMetaValueDynamic({id:t,meta:r,key:n,updateValue:i}):Gt.setMetaValue({id:t,meta:r,key:n,value:i}))}};function Ms(){return typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{}}function $r(e){const t=Ms();try{const n=t.IIIF_VAULT;if(n)return n}catch{}const r=new wt(e);try{t.IIIF_VAULT=r}catch{}return r}const $e=v.createContext({vault:null,setVaultInstance:e=>{}});function Tt({vault:e,vaultOptions:t,useGlobal:r,resources:n,children:i}){const[s,a]=v.useState(()=>e||(r?$r(t):t?new wt(t):new wt));return m.jsx($e.Provider,{value:{vault:s,setVaultInstance:a},children:m.jsx(he,{value:n||{},children:i})})}const V=()=>{const{vault:e}=v.useContext($e);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};function jt(e,{noCache:t=!1}={}){const r=typeof e=="string"?e:e.id,n=V(),[i,s]=v.useState(r),[a,o]=v.useState(void 0),u=v.useMemo(()=>n.get(r,{skipSelfReturn:!0})||void 0,[r,n]),[d,l]=v.useState(u);return v.useEffect(()=>{(async()=>{try{const p=u&&!t?u:await n.load(r),g=p?p.id||p["@id"]:null;p&&i!==g&&s(g),l(p)}catch(p){o(p)}})()},[r,t]),{isLoaded:!!d,id:i,requestId:r,error:a,resource:d,cached:!!(d&&d===u)}}function Dr(e,t){const{id:r,isLoaded:n,error:i,resource:s,requestId:a,cached:o}=jt(e,t);return{id:r,isLoaded:n,error:i,manifest:s,requestId:a,cached:o}}function qr({manifest:e,children:t}){return m.jsx(he,{value:{manifest:e},children:t})}function Ke({canvas:e,children:t}){return m.jsx(he,{value:{canvas:e},children:t})}function U(e,t=[]){const r=V(),[n,i]=v.useState(()=>e(r.getState(),r));return v.useEffect(()=>r.subscribe(s=>e(s,r),s=>{i(s)},!1),t),n}const De=v.createContext([]);function Et(){const e=v.useContext(De);return U(t=>e.map(r=>t.iiif.entities.Canvas[r]).filter(Boolean),[e])}function ve(e={},t=[]){const{id:r,selector:n}=e,i=se();V();const s=r||i.manifest,a=U(o=>s?o.iiif.entities.Manifest[s]:void 0,[s]);return v.useMemo(()=>{if(a)return n?n(a):a},[a,n,...t])}function Vr({range:e,children:t}){return m.jsx(he,{value:{range:e},children:t})}function _r(e,t){for(const r of t.items){if(r.type==="Canvas")return r;if(r.type==="SpecificResource")return r.source;if(r.type==="Range"){const n=_r(e,e.get(r));if(n)return n}}return null}function Pt(e,t){var n;const r=[];for(const i of t.items)if(i.type==="SpecificResource"&&((n=i.source)==null?void 0:n.type)==="Canvas"&&(i.source.id.indexOf("#")!==-1?r.push({id:i.source.id.split("#")[0],type:"Canvas"}):r.push(i.source)),i.type==="Range"&&r.push(...Pt(e,e.get(i))),i.type==="SpecificResource"){const s=typeof i.source=="string"?i.source:i.source.id;r.push({id:s,type:"Canvas"})}return r}function Rs(e,t,r){for(const n of t.structures){const i=Ot(e,e.get(n),r);if(i)return i}return null}function Ot(e,t,r){var n,i,s;for(const a of t.items){const o=(i=(n=a==null?void 0:a.source)==null?void 0:n.id)==null?void 0:i.split("#")[0];if(a.type==="SpecificResource"&&a.source===r||a.type==="SpecificResource"&&((s=a.source)==null?void 0:s.type)==="Canvas"&&r===o)return t;if(a.type==="Range"){const u=Ot(e,e.get(a),r);if(u)return u}}return null}function Is(e,t,r,n=!1){const i=t.behavior,s=r?e.get(r):null;if(!s)return[];const a=s.behavior,o=n?!1:i.includes("paged"),u=o?!1:i.includes("continuous"),d=o||u?!1:i.includes("individuals"),l=a.includes("facing-pages"),p=a.includes("non-paged");if(l||p||d||n)return[{id:s.id,type:"Canvas"}];const[g,b]=Lt(e,t);if(u)return g;const h=g.findIndex(x=>x.id===r);if(h===-1)return[];for(const x of b)if(x.includes(h))return x.map(A=>g[A]);return[{id:s.id,type:"Canvas"}]}function Lt(e,t,{disablePaging:r,skipNonPaged:n}={}){const i=t.behavior,s=i.includes("paged"),a=s?!1:i.includes("continuous"),o=s||a?!1:i.includes("individuals"),u=t.type==="Manifest"?t.items:Pt(e,t);if(a)return[u,[u.map((h,x)=>x)]];if(o||!s||r)return[u,u.map((h,x)=>[x])];const d=[];let l=[];const p=()=>{l.length&&(d.push([...l]),l=[])};let g=0,b=!1;for(let h=0;h<u.length;h++){const x=e.get(u[h]);if(x.behavior.includes("non-paged")){h===g&&g++,n||(p(),d.push([h]),p());continue}if(h===g||x.behavior.includes("facing-pages")){l.length&&(b=!0),p(),d.push([h]),p();continue}if(l.push(h),b){p(),b=!1;continue}l.length>1&&p()}return l.length&&p(),[u,d]}function Ur(e={},t=[]){const{id:r,selector:n}=e,i=se(),s=r||i.range,a=U(o=>s?o.iiif.entities.Range[s]:void 0,[s]);return v.useMemo(()=>{if(a)return n?n(a):a},[a,n,...t])}function Hr({startCanvas:e,disablePaging:t}){var h;const r=V(),n=ve(),i=Ur(),[s,a]=v.useState(void 0),o=i||n;if(!o)throw new Error("Nothing selected");const[u,d]=v.useMemo(()=>Lt(r,o,{disablePaging:t}),[r,o]),l=v.useCallback(x=>{const A=d.findIndex(S=>S.includes(x));a(A===-1?0:A)},[u,d]),p=v.useCallback(x=>{const A=u.findIndex(S=>S.id===x);A!==-1?l(A):a(0)},[u,d]),g=v.useCallback(()=>{a(x=>x>=d.length?x:x+1)},[d]),b=v.useCallback(()=>{a(x=>x<=0?0:x-1)},[d]);return typeof s>"u"&&(e?p(e):a(0)),{visibleItems:((h=d[s])==null?void 0:h.map(x=>u[x].id))||[],cursor:s,items:u,sequence:d,setSequenceIndex:a,setCanvasIndex:l,setCanvasId:p,next:g,previous:b}}const ke=()=>{},qe=v.createContext({setCurrentCanvasId:ke,setCurrentCanvasIndex:ke,nextCanvas:ke,previousCanvas:ke,items:[],sequence:[],setSequenceIndex:ke,currentSequenceIndex:0});function Nr(e){const t=ve(),{cursor:r,visibleItems:n,next:i,sequence:s,items:a,setCanvasIndex:o,setCanvasId:u,previous:d,setSequenceIndex:l}=Hr({startCanvas:e.startCanvas,disablePaging:e.pagingEnabled===!1}),p=v.useMemo(()=>({sequence:s,items:a,setCurrentCanvasId:u,nextCanvas:i,previousCanvas:d,totalCanvases:a.length,setCurrentCanvasIndex:o,setSequenceIndex:l,currentSequenceIndex:r}),[s,a,u,i,d,a,o,l,r]);return t?m.jsx(qe.Provider,{value:p,children:m.jsx(De.Provider,{value:n,children:m.jsx(Ke,{canvas:n[0],children:e.children})})}):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),m.jsx("div",{children:"Sorry, something went wrong."}))}function Br(e){const t=Dr(e.manifest);if(!t)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),m.jsx("div",{children:"Sorry, something went wrong."});if(t.error)return m.jsx("div",{children:t.error.toString()});if(!t.isLoaded)return m.jsx("div",{children:"Loading..."});const r=m.jsx(Nr,{...e,children:e.children});return m.jsx(qr,{manifest:t.id,children:e.rangeId?m.jsx(Vr,{range:e.rangeId,children:r}):r})}function zr(){return v.useContext(qe)}function Wr(){return{VaultContext:v.useContext($e),ResourceContext:v.useContext(Je),SimpleViewerReactContext:v.useContext(qe),VisibleCanvasReactContext:v.useContext(De)}}function Qr(e){return m.jsx(Tt,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext,children:m.jsx(De.Provider,{value:e.bridge.VisibleCanvasReactContext,children:m.jsx(qe.Provider,{value:e.bridge.SimpleViewerReactContext,children:e.children})})})}const te=function(e){return function(){const t={type:e,getType:()=>e,toString:()=>e};return(r,n)=>({...t,...r!==void 0&&{payload:r},...n!==void 0&&{meta:n}})}},ks="@iiif/IMPORT_ENTITIES",Ts="@iiif/MODIFY_ENTITY_FIELD",js="@iiif/REORDER_ENTITY_FIELD",Es="@iiif/ADD_REFERENCE",Ps="@iiif/UPDATE_REFERENCE",Os="@iiif/REMOVE_REFERENCE",Ls="@iiif/ADD_METADATA",Fs="@iiif/REMOVE_METADATA",$s="@iiif/UPDATE_METADATA",Ds="@iiif/REORDER_METADATA",qs=te(ks)(),Vs=te(Ts)(),_s=te(js)(),Us=te(Es)(),Hs=te(Os)(),Ns=te(Ps)(),Bs=te(Ls)(),zs=te($s)(),Ws=te(Fs)(),Qs=te(Ds)(),ft={importEntities:qs,modifyEntityField:Vs,reorderEntityField:_s,addReference:Us,removeReference:Hs,updateReference:Ns,addMetadata:Bs,removeMetadata:Ws,updateMetadata:zs,reorderMetadata:Qs};function Yr(){const t=V().getStore();return v.useMemo(()=>r=>t.dispatch(r),[t])}function rr(e){return typeof e!="string"&&e&&e.bindToVault}function Gr(){const e=V(),t=v.useRef([]),r=Yr(),n=v.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);v.useLayoutEffect(()=>{const o={id:n,type:"AnnotationPage",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],rendering:[],service:[]};r(ft.importEntities({entities:{AnnotationPage:{[o.id]:o}}}))},[n]);const i=U(o=>n?o.iiif.entities.AnnotationPage[n]:null,[n]),s=v.useCallback((o,u)=>{if(n){if(rr(o)){const p=o;p.__vault||p.bindToVault(e),o=typeof p.source=="string"?p.source:p.source.id,t.current[o]=p}else typeof o!="string"&&(o=o.id);const d=e.get({id:n,type:"AnnotationPage"}),l=e.get({id:o,type:"Annotation"});d&&l&&(d.items.find(p=>p.id===l.id)||r(ft.addReference({id:n,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"},index:u})))}},[n]),a=v.useCallback(o=>{n&&(rr(o)?o=typeof o.source=="string"?o.source:o.source.id:typeof o!="string"&&(o=o.id),t.current[o]&&t.current[o].beforeRemove(),e.get({id:n,type:"AnnotationPage"})&&r(ft.removeReference({id:n,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"}})))},[n]);return[i,{addAnnotation:s,removeAnnotation:a}]}const Jr=v.createContext(null);function Kr(){const e=v.useContext(Jr);return[e.fullPage,{addAnnotation:e.addAnnotation,removeAnnotation:e.removeAnnotation}]}function Zr({children:e}){const[t,{addAnnotation:r,removeAnnotation:n}]=Gr();return m.jsx(Jr.Provider,{value:v.useMemo(()=>({fullPage:t,addAnnotation:r,removeAnnotation:n}),[t]),children:e})}function Ys({width:e,style:t,height:r,error:n,resetErrorBoundary:i}){return m.jsxs("div",{style:{width:e,height:r,minHeight:500,...t||{},background:"#f9f9f9"},children:[m.jsx("h3",{children:"Error occurred"}),m.jsx("p",{children:n.message}),m.jsx("button",{onClick:i,children:"Reset"})]})}const Ze=v.createContext(null);function Xr(){return v.useContext(Ze)}const en=v.createContext(()=>{}),tn=v.createContext(()=>{});function Ie(e,t,r,n,i=[]){const s=v.useContext(e==="portal"?tn:en);v.useEffect(()=>(e!=="none"&&s(t,r,n),()=>{s(t,null)}),[t,e,s,...i])}function re(e={},t=[]){const{id:r,selector:n}=e,i=se(),s=r||i.canvas,a=U(o=>s?o.iiif.entities.Canvas[s]:void 0,[s]);return v.useMemo(()=>{if(a)return n?n(a):a},[a,n,...t])}const rn=v.createContext(()=>{});function Gs(e){const t=re(),r=v.useContext(rn);v.useEffect(()=>t&&t.id?(r(t.id,e),()=>r(t.id,-1)):()=>{},[t,e])}function Js({children:e,errorFallback:t,outerContainerProps:r={},worldScale:n,...i}){const[s,a]=v.useState(),o=Wr(),u=t||Ys,[d,l]=v.useState({}),p=Object.entries(d),[g,b]=v.useState({}),h=Object.entries(g),[x,A]=v.useState({}),S=v.useMemo(()=>n||Math.max(...Object.values(x)),[x]),w=v.useMemo(()=>({maxOverZoom:S||1,...i.runtimeOptions||{}}),[S,i.runtimeOptions]),M=v.useCallback((k,O)=>{A(P=>{if(O===-1){const{[k]:R,...$}=P;return $}return{...P,[k]:O}})},[]),T=v.useCallback((k,O,P)=>{l(({[k]:R,...$})=>O?{...$,[k]:{element:O,props:P}}:$)},[]),F=v.useCallback((k,O,P)=>{b(({[k]:R,...$})=>O?{...$,[k]:{element:O,props:P}}:$)},[]);return m.jsxs(Oi,{resetKeys:[],fallbackRender:k=>m.jsx(u,{...i,...k}),children:[m.jsx(Re.AtlasAuto,{...i,containerProps:{style:{position:"relative"},...i.containerProps||{}},htmlChildren:m.jsx(m.Fragment,{children:p.map(([k,{element:O,props:P}])=>m.jsx(v.Fragment,{children:m.jsx(O,{...P||{}})},k))}),onCreated:k=>{a(k),i.onCreated&&i.onCreated(k)},runtimeOptions:w,children:m.jsx(Ze.Provider,{value:s,children:m.jsx(rn.Provider,{value:M,children:m.jsx(en.Provider,{value:T,children:m.jsx(tn.Provider,{value:F,children:m.jsx(Qr,{bridge:o,children:m.jsx(Re.ModeContext.Provider,{value:i.mode||"explore",children:m.jsx(Zr,{children:e})})})})})})})}),m.jsx("div",{children:h.map(([k,{element:O,props:P}])=>m.jsx(v.Fragment,{children:m.jsx(O,{...P||{}})},k))})]})}const He={},nn={get(e){return e},setMetaValue([e,t,r],n){const i=nn.getResourceMeta(e,t),s=i?i[r]:void 0,a=typeof n=="function"?n(s):n;He[e]={...He[e]||{},[t]:{...(He[e]||{})[t]||{},[r]:a}}},getResourceMeta:(e,t)=>{const r=He[e];if(r)return t?r[t]:r}};function sn(e=nn){return{addEventListener(t,r,n,i){if(t)return e.setMetaValue([t.id,"eventManager",r],s=>{const a=s||[];for(const o of a)if(o.callback===n)return a;return[...a,{callback:n,scope:i}]}),n},removeEventListener(t,r,n){t&&e.setMetaValue([t.id,"eventManager",r],i=>(i||[]).filter(s=>s.callback!==n))},getListenersAsProps(t,r){const n=typeof t=="string"?{id:t}:t;if(!n||!n.id)return{};const i=e.getResourceMeta(n.id,"eventManager"),s={};if(i&&n)for(const a of Object.keys(i))s[a]=o=>{const u=e.get(n);for(const{callback:d,scope:l}of i[a]||[])(!l||r&&l.indexOf(r)!==-1)&&d(o,u)};return s}}}function Ft(e,t){const r=V(),n=v.useMemo(()=>sn(r),[r]),i=U(()=>e&&e.id?r.getResourceMeta(e.id,"eventManager"):null,[e]);return v.useMemo(()=>e?n.getListenersAsProps(e,t):{},[i,e,r,t])}const Ne={},an={get(e){return e},setMetaValue([e,t,r],n){const i=an.getResourceMeta(e,t),s=i?i[r]:void 0,a=typeof n=="function"?n(s):n;Ne[e]={...Ne[e]||{},[t]:{...(Ne[e]||{})[t]||{},[r]:a}}},getResourceMeta:(e,t)=>{const r=Ne[e];if(r)return t?r[t]:r}};function $t(e=an){return{applyStyles(t,r,n){const i=typeof t=="string"?t:t.id;return e.setMetaValue([i,"styles",r],n)},getAppliedStyles(t){const r=typeof t=="string"?t:t.id;return e.getResourceMeta(r,"styles")}}}function Fe(e,t){const r=V(),n=v.useMemo(()=>$t(r),[r]);return U(()=>{if(!e)return null;const i=n.getAppliedStyles(e.id);return i?t?i[t]:i:void 0},[e,t])}var Ks=Object.defineProperty,Zs=(e,t,r)=>t in e?Ks(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,We=(e,t,r)=>(Zs(e,typeof t!="symbol"?t+"":t,r),r),Xs=function(){function e(t,r){var n=[],i=!0,s=!1,a=void 0;try{for(var o=t[Symbol.iterator](),u;!(i=(u=o.next()).done)&&(n.push(u.value),!(r&&n.length===r));i=!0);}catch(d){s=!0,a=d}finally{try{!i&&o.return&&o.return()}finally{if(s)throw a}}return n}return function(t,r){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),je=Math.PI*2,pt=function(e,t,r,n,i,s,a){var o=e.x,u=e.y;o*=t,u*=r;var d=n*o-i*u,l=i*o+n*u;return{x:d+s,y:l+a}},ea=function(e,t){var r=t===1.5707963267948966?.551915024494:t===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(t/4),n=Math.cos(e),i=Math.sin(e),s=Math.cos(e+t),a=Math.sin(e+t);return[{x:n-i*r,y:i+n*r},{x:s+a*r,y:a-s*r},{x:s,y:a}]},nr=function(e,t,r,n){var i=e*n-t*r<0?-1:1,s=e*r+t*n;return s>1&&(s=1),s<-1&&(s=-1),i*Math.acos(s)},ta=function(e,t,r,n,i,s,a,o,u,d,l,p){var g=Math.pow(i,2),b=Math.pow(s,2),h=Math.pow(l,2),x=Math.pow(p,2),A=g*b-g*x-b*h;A<0&&(A=0),A/=g*x+b*h,A=Math.sqrt(A)*(a===o?-1:1);var S=A*i/s*p,w=A*-s/i*l,M=d*S-u*w+(e+r)/2,T=u*S+d*w+(t+n)/2,F=(l-S)/i,k=(p-w)/s,O=(-l-S)/i,P=(-p-w)/s,R=nr(1,0,F,k),$=nr(F,k,O,P);return o===0&&$>0&&($-=je),o===1&&$<0&&($+=je),[M,T,R,$]},ra=function(e){var t=e.px,r=e.py,n=e.cx,i=e.cy,s=e.rx,a=e.ry,o=e.xAxisRotation,u=o===void 0?0:o,d=e.largeArcFlag,l=d===void 0?0:d,p=e.sweepFlag,g=p===void 0?0:p,b=[];if(s===0||a===0)return[];var h=Math.sin(u*je/360),x=Math.cos(u*je/360),A=x*(t-n)/2+h*(r-i)/2,S=-h*(t-n)/2+x*(r-i)/2;if(A===0&&S===0)return[];s=Math.abs(s),a=Math.abs(a);var w=Math.pow(A,2)/Math.pow(s,2)+Math.pow(S,2)/Math.pow(a,2);w>1&&(s*=Math.sqrt(w),a*=Math.sqrt(w));var M=ta(t,r,n,i,s,a,l,g,h,x,A,S),T=Xs(M,4),F=T[0],k=T[1],O=T[2],P=T[3],R=Math.abs(P)/(je/4);Math.abs(1-R)<1e-7&&(R=1);var $=Math.max(Math.ceil(R),1);P/=$;for(var X=0;X<$;X++)b.push(ea(O,P)),O+=P;return b.map(function(Y){var _=pt(Y[0],s,a,x,h,F,k),H=_.x,J=_.y,ee=pt(Y[1],s,a,x,h,F,k),ge=ee.x,E=ee.y,N=pt(Y[2],s,a,x,h,F,k),G=N.x,ue=N.y;return{x1:H,y1:J,x2:ge,y2:E,x:G,y:ue}})};function on(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var na=sa,dt={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},ia=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function sa(e){var t=[];return e.replace(ia,function(r,n,i){var s=n.toLowerCase();for(i=oa(i),s=="m"&&i.length>2&&(t.push([n].concat(i.splice(0,2))),s="l",n=n=="m"?"l":"L");;){if(i.length==dt[s])return i.unshift(n),t.push(i);if(i.length<dt[s])throw new Error("malformed path data");t.push([n].concat(i.splice(0,dt[s])))}}),t}var aa=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function oa(e){var t=e.match(aa);return t?t.map(Number):[]}const ca=on(na);var ua=la;function la(e){var t=0,r=0,n=0,i=0;return e.map(function(s){s=s.slice();var a=s[0],o=a.toUpperCase();if(a!=o)switch(s[0]=o,a){case"a":s[6]+=n,s[7]+=i;break;case"v":s[1]+=i;break;case"h":s[1]+=n;break;default:for(var u=1;u<s.length;)s[u++]+=n,s[u++]+=i}switch(o){case"Z":n=t,i=r;break;case"H":n=s[1];break;case"V":i=s[1];break;case"M":n=t=s[1],i=r=s[2];break;default:n=s[s.length-2],i=s[s.length-1]}return s})}const fa=on(ua);function pa(e){const t=ca(e),r=fa(t);let n,i=0,s=0,a=0,o=0,u,d,l=0,p=0;const g=[];for(let b=0;b<r.length;b++){let h=r[b];const x=h[0];switch(x){case"M":i=h[1],s=h[2];break;case"H":h=["L",h[1],s];break;case"V":h=["L",i,h[1]];break;case"S":{let A=l,S=p;(n==="C"||n=="S")&&(A+=A-a,S+=S-o),h=["C",A,S,h[1],h[2],h[3],h[4]]}break;case"T":n==="Q"||n=="T"?(u=l*2-u,d=p*2-d):(u=l,d=p),h=["Q",u,d,h[1],h[2]];break;case"Q":u=h[1],d=h[2];break;case"A":{const A=ra({px:l,py:p,cx:h[6],cy:h[7],rx:h[1],ry:h[2],xAxisRotation:h[3],largeArcFlag:h[4],sweepFlag:h[5]});if(!A.length)continue;for(const[S,w]of A.entries())h=["C",w.x1,w.y1,w.x2,w.y2,w.x,w.y],S<A.length-1&&g.push(h);h=h}break;case"Z":h=["L",i,s];break}n=x,l=h[h.length-2],p=h[h.length-1],["C","Q","A"].indexOf(x)>-1?(a=h[h.length-4],o=h[h.length-3]):(a=l,o=p),g.push(h)}return g}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
5
+ `);const w=S.state[o];if(w==null)return;JSON.stringify(i.getState())!==JSON.stringify(w)&&A(w);return}i.dispatchFromDevtools&&typeof i.dispatch=="function"&&i.dispatch(S)});case"DISPATCH":switch(x.payload.type){case"RESET":return A(h),o===void 0?l==null?void 0:l.init(i.getState()):l==null?void 0:l.init(Ue(u.name));case"COMMIT":if(o===void 0){l==null||l.init(i.getState());return}return l==null?void 0:l.init(Ue(u.name));case"ROLLBACK":return ct(x.state,S=>{if(o===void 0){A(S),l==null||l.init(i.getState());return}A(S[o]),l==null||l.init(Ue(u.name))});case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return ct(x.state,S=>{if(o===void 0){A(S);return}JSON.stringify(i.getState())!==JSON.stringify(S[o])&&A(S[o])});case"IMPORT_STATE":{const{nextLiftedState:S}=x.payload,w=(b=S.computedStates.slice(-1)[0])==null?void 0:b.state;if(!w)return;A(o===void 0?w:w[o]),l==null||l.send(null,S);return}case"PAUSE_RECORDING":return m=!m}return}}),h},ys=hs,ct=(t,e)=>{let r;try{r=JSON.parse(t)}catch(n){console.error("[zustand devtools middleware] Could not parse the received json",n)}r!==void 0&&e(r)},vs=t=>(e,r,n)=>{const i=n.subscribe;return n.subscribe=(s,a,o)=>{let u=s;if(a){const d=(o==null?void 0:o.equalityFn)||Object.is;let l=s(n.getState());u=p=>{const m=s(p);if(!d(l,m)){const A=l;a(l=m,A)}},o!=null&&o.fireImmediately&&a(l,l)}return i(u)},t(e,r,n)},gs=vs,ms=(t={},e)=>{switch(e.type){case wr:return{...t,[e.payload.id]:e.payload.type};case Cr:return{...t,...e.payload.mapping};default:return t}};function ut(t,e,r,n){return!(!t[r]||!t[r][e]||!t[r][e][n]||!Array.isArray(t[r][e][n]))}function xs(t,e){const r={},n=[];for(const[i,s]of Object.entries(t||{})){n.push(i);const a=(e||{})[i];if(!a||a.length===0){r[i]=s;continue}r[i]=a}for(const[i,s]of Object.entries(e||{}))n.indexOf(i)===-1&&(r[i]=s);return r}function I(t){return t.payload}function lt(t,e){return typeof t>"u"?e:t}const bs=(t=Or(),e)=>{var r;const n=(i,s)=>({...t,[I(e).type]:{...t[I(e).type],[I(e).id]:{...i,...s}}});switch(e.type){case yr:{if(!t[I(e).type]||!t[I(e).type][I(e).id])return t;const i=t[I(e).type][I(e).id];return typeof i=="string"?t:n(i,{[I(e).key]:I(e).value})}case vr:{if(!ut(t,I(e).id,I(e).type,I(e).key))return t;const i=t[I(e).type][I(e).id];if(typeof i=="string")return t;const s=Array.from(i[I(e).key]),[a]=s.splice(I(e).startIndex,1);return s.splice(I(e).endIndex,0,a),n(i,{[I(e).key]:s})}case hr:{const i=Object.keys(I(e).entities),s={...t};for(const a of i){const o=I(e).entities[a],u={...t[a]||{}};let d=!1;const l=Object.keys(o||{})||[];if(o&&l){for(const p of l)d=!0,u[p]=t[a][p]?xs(t[a][p],o[p]):o[p];d&&(s[a]=u)}}return s}case gr:{if(!ut(t,I(e).id,I(e).type,I(e).key))return t;const i=t[I(e).type][I(e).id],s=Array.from(i[I(e).key]);return s.splice(lt(I(e).index,s.length+1),0,I(e).reference),n(i,{[I(e).key]:s})}case gt:case mr:{if(!ut(t,I(e).id,I(e).type,I(e).key))return t;const i=t[I(e).type][I(e).id],s=Array.from(i[I(e).key]),a=lt(I(e).index,s.findIndex(o=>o&&o.id===I(e).reference.id));return a===-1||((r=s[a])==null?void 0:r.id)!==I(e).reference.id?t:(e.type===gt?s.splice(a,1,I(e).reference):s.splice(a,1),n(i,{[I(e).key]:s}))}case xr:{const i=t[I(e).type][I(e).id];if(!i)return t;const s=Array.from(i.metadata||[]),a=I(e);return s.splice(lt(e.payload.beforeIndex,s.length+1),0,{label:a.label,value:a.label}),n(i,{metadata:s})}case Ar:{const i=t[I(e).type][I(e).id];if(typeof i=="string"||!i)return t;const s=Array.from(i.metadata||[]),[a]=s.splice(I(e).startIndex,1);return s.splice(I(e).endIndex,0,a),n(i,{metadata:s})}case mt:case br:{const i=t[I(e).type][I(e).id],s=Array.from(i.metadata||[]),a=I(e).atIndex;return typeof a>"u"||a===-1||!s[a]?t:(e.type===mt?s.splice(a,1,{label:I(e).label,value:I(e).value}):s.splice(a,1),n(i,{metadata:s}))}default:return t}},As=(t={},e)=>{switch(e.type){case Tr:case rs:return{...t,[e.payload.id]:{requestUri:e.payload.id,loadingState:kr,uriMismatch:!1,resourceUri:e.payload.id}};case Pr:return{...t,[e.payload.requestId]:{...t[e.payload.requestId]||{},uriMismatch:!0,resourceUri:e.payload.actualId},[e.payload.actualId]:{requestUri:e.payload.requestId,loadingState:t[e.payload.requestId].loadingState,uriMismatch:!0,resourceUri:e.payload.actualId}};case jr:return{...t,[e.payload.id]:{...t[e.payload.id]||{},loadingState:xt,error:e.payload.message}};case Er:return{...t,[e.payload.id]:{...t[e.payload.id]||{},loadingState:bt,error:void 0}}}return t},Ss=(t={},e)=>{const{id:r,updateValue:n,value:i,meta:s,key:a}=e&&e.payload||{};switch(e.type){case Mr:return{...t,[r]:{...t[r]||{},[s]:{...t[r]?t[r][s]||{}:{},[a]:i}}};case Rr:return{...t,[r]:{...t[r]||{},[s]:{...t[r]?t[r][s]||{}:{},[a]:t[r]&&t[r][s]?n(t[r][s][a]):n(void 0)}}};case Ir:return t[r]&&t[r][s]&&t[r][s][a]?{...t,[r]:{...t[r]||{},[s]:{...t[r]?t[r][s]||{}:{},[a]:void 0}}}:t;default:return t}};function Lr(t={}){const e=Object.keys(t);return function(r={},n){let i=!1;const s={};for(let a=0;a<e.length;a++){const o=e[a];s[o]=t[o](r[o],n),i=i||s[o]!==r[o]}return i?s:r}}function ws(t){return(e,r)=>r&&r.type===Tt?r.payload.actions.reduce(t,e):r&&r.type===as?{...e,iiif:{...e.iiif,...r.payload.state}}:t(e,r)}const Cs=Lr({mapping:ms,entities:bs,requests:As,meta:Ss});function Ms(){return{iiif:{entities:Or(),meta:{},mapping:{},requests:{}}}}function Rs(t={}){const{enableDevtools:e=!1,iiifStoreName:r="iiif",defaultState:n=Ms(),customReducers:i={}}=t,s=ws(Lr({[r]:Cs,...i}));return ls(gs(ys(ps(s,n),{enabled:e})))}function Is(t){return{all:t=t||new Map,on:function(e,r){var n=t.get(e);n?n.push(r):t.set(e,[r])},off:function(e,r){var n=t.get(e);n&&(r?n.splice(n.indexOf(r)>>>0,1):t.set(e,[]))},emit:function(e,r){var n=t.get(e);n&&n.slice().map(function(i){i(r)}),(n=t.get("*"))&&n.slice().map(function(i){i(e,r)})}}}function z(t,e,r,n=!0){e[we]=e[we]||[],e[we].push(t);const i=new Map;Object.defineProperty(e,t,{enumerable:n,get(){if(typeof e[xe][t]>"u")return;const s=e[xe][t];if(!s)return s;const a=r.get(e[xe][t],{parent:this.id?{id:this.id,type:this.type}:void 0});return i.has(a)||(i.clear(),i.set(a,be(a,r))),i.get(a)},set(s){e[xe][t]!==s&&(this[me]?r.modifyEntityField({id:this.id,type:this.type},t,Fr(s)):this[xe][t]=s)}})}const xe=Symbol.for("_refs_"),me=Symbol.for("_reactive_"),we=Symbol.for("_defined_"),tr=Symbol.for("_parent_");function ks(t,e=!1,r){const n={id:"",type:"unknown",[we]:[],[xe]:{},[tr]:r||null,[me]:null,is(i){return typeof i=="string"?this.id===i:i.id?i.id===this.id:!1},reactive(){if(!this[me])return this[me]=this.subscribe(()=>this.refresh(),!0),()=>{this.unreactive()}},refresh(){if(this.id){const i=this.unwrap();for(const s of Object.keys(i||{}))this[we].includes(s)?this[xe][s]=i[s]:this[s]=i[s]}},unreactive(){this[me]&&(this[me](),this[me]=null)},unwrap(){if(!this.id)throw new Error("Invalid object");const i=this[tr];return t.get(this.id,{parent:i?{id:i,type:"unknown"}:void 0})},toPresentation3(){return t.toPresentation3(this.unwrap())},toPresentation2(){return t.toPresentation2(this.unwrap())},valueOf(){return this.unwrap()},toJSON(){const i=this;return{...i,items:i.items,annotations:i.annotations,structures:i.structures,seeAlso:i.seeAlso,service:i.service,services:i.services,rendering:i.rendering,partOf:i.partOf,start:i.start,supplementary:i.supplementary,homepage:i.homepage,thumbnail:i.thumbnail,placeholderCanvas:i.placeholderCanvas,accompanyingCanvas:i.accompanyingCanvas,provider:i.provider}},subscribe(i,s=!0){return t.subscribe(()=>this.id?t.get(this.id):null,i,s)}};return z("items",n,t),z("annotations",n,t),z("structures",n,t),z("seeAlso",n,t),z("rendering",n,t),z("partOf",n,t),z("start",n,t,!1),z("supplementary",n,t),z("homepage",n,t),z("thumbnail",n,t),z("placeholderCanvas",n,t,!1),z("accompanyingCanvas",n,t,!1),z("provider",n,t),z("body",n,t),z("logo",n,t),n}function Ts(t){return!!t[we]}function Fr(t){return Array.isArray(t)?t.map(e=>Fr(e)):!t||!t.type?t:{id:t.id,type:t.type}}function be(t,e,r=!1,n){if(Array.isArray(t))return t.map(o=>be(o,e,r));if(!t||!t.type||!t.id)return t;const i=ks(e,r),s=Object.create(i),a=Object.assign(s,t);return r&&a.reactive(),a}function rr(t){switch(t){case"Image":case"Video":case"Sound":case"Dataset":case"Text":case"Composite":case"List":case"Independents":case"Audience":return"ContentResource";case"ImageService1":case"ImageService2":case"ImageService3":return"Service"}return t}let Ct=class{constructor(e,r){pe(this,"options"),pe(this,"store"),pe(this,"emitter"),pe(this,"isBatching",!1),pe(this,"batchQueue",[]),pe(this,"remoteFetcher"),pe(this,"staticFetcher"),pe(this,"defaultFetcher",n=>fetch(n).then(i=>i.json())),this.options=Object.assign({reducers:{},customFetcher:this.defaultFetcher,enableDevtools:!0},e||{}),this.store=r||Rs({customReducers:this.options.reducers,defaultState:this.options.defaultState,enableDevtools:this.options.enableDevtools}),this.emitter=Is(),this.remoteFetcher=Xt(this,this.options.customFetcher),this.staticFetcher=Xt(this,(n,i)=>i)}batch(e){this.isBatching=!0;try{e(this),this.isBatching=!1,this.dispatch(St({actions:this.batchQueue}))}catch(r){throw this.batchQueue=[],this.isBatching=!1,r}this.batchQueue=[]}async asyncBatch(e){this.isBatching=!0;try{await e(this),this.isBatching=!1,this.dispatch(St({actions:this.batchQueue}))}catch(r){throw this.batchQueue=[],this.isBatching=!1,r}this.batchQueue=[]}modifyEntityField(e,r,n){this.dispatch(Ji.modifyEntityField({id:e.id,type:e.type,key:r,value:n}))}dispatch(e){if(this.isBatching)this.batchQueue.push(e);else{if(e.type===Tt){for(const i of e.payload.actions)this.emitter.emit(i.type,{action:i,state:this.store.getState()});this.store.dispatch(e);const n=this.getState();for(const i of e.payload.actions)this.emitter.emit(`after:${i.type}`,{action:i,state:n});return}this.emitter.emit(e.type,{action:e,state:this.store.getState()}),this.store.dispatch(e);const r=this.store.getState();this.emitter.emit(`after:${e.type}`,{action:e,state:r});return}}on(e,r){return this.emitter.on(e,r),()=>{this.emitter.off(e,r)}}serialize(e,r){return W.serialize(this.getState().iiif,e,r)}toPresentation2(e){return this.serialize(e,W.serializeConfigPresentation2)}toPresentation3(e){return this.serialize(e,W.serializeConfigPresentation3)}hydrate(e,r,n={}){return this.get(e,r,{...n,skipSelfReturn:!1})}get(e,r,n={}){typeof r!="string"&&(n=r||{},r=void 0);const{skipSelfReturn:i=!0}=n||{};let s=n.parent?typeof n.parent=="string"?n.parent:n.parent.id:void 0;if(Array.isArray(e))return e.map(p=>this.get(p,n));const a=this.getState();if(W.isSpecificResource(e)&&!n.preserveSpecificResources&&(e=e.source),typeof e=="string"){const p=rr(r||a.iiif.mapping[e]);if(!p)return i?null:{id:e,type:"unknown"};e={id:e,type:p}}if(e&&e.partOf&&!s&&!n.skipPartOfCheck){const p=Array.isArray(e.partOf)?e.partOf[0]:e.partOf;p&&(typeof p=="string"&&(s=p),typeof p.id=="string"&&(s=p.id))}const o=rr(r||(e==null?void 0:e.type)),u=e==null?void 0:e.id,d=a.iiif.entities[o];if(!d){const p=a.iiif.requests[u];return p&&p.resourceUri!==u?this.get(p.resourceUri,n):i?null:e}const l=d[e.id];if(l&&l[W.HAS_PART]){const p=l[W.HAS_PART].find(m=>s?m[W.PART_OF]===s:m[W.PART_OF]===l.id);return W.frameResource(l,p)}return d[e.id]||(i?null:e)}select(e){return e(this.getState())}getStore(){return this.store}getState(){return this.store.getState()}deep(e,r){if(typeof e>"u")return this.get(r,{skipSelfReturn:!1});if(typeof e=="function")try{const i=e(this.get(r,{skipSelfReturn:!1})),s=a=>this.deep(a,i);return s.size=Array.isArray(i)?i.length:1,s}catch{const i=s=>this.deep(s,void 0);return i.size=0,i}const n=i=>this.deep(i,e);return n.size=Array.isArray(e)?e.length:1,n}loadManifest(e,r){const n=typeof e=="string"?e:e.id;return this.load(n,r)}loadCollection(e,r){const n=typeof e=="string"?e:e.id;return this.load(n,r)}load(e,r){const n=typeof e=="string"?e:e.id;return r?Promise.resolve(this.staticFetcher(n,r)):Promise.resolve(this.remoteFetcher(n))}loadSync(e,r){const n=typeof e=="string"?e:e.id;return this.staticFetcher(n,r)}loadManifestSync(e,r){const n=typeof e=="string"?e:e.id;return this.loadSync(n,r)}loadCollectionSync(e,r){const n=typeof e=="string"?e:e.id;return this.loadSync(n,r)}areInputsEqual(e,r){return Zt(e,r)}subscribe(e,r,n){return typeof n>"u"&&(typeof r>"u"||r===!1||r===!0)&&(n=r,r=e,e=i=>i),this.store.subscribe(e,i=>r(i,this),{equalityFn:Zt,fireImmediately:!n})}async ensureLoaded(e){const r=typeof e=="string"?e:e.id;this.requestStatus(r)||await this.load(r)}requestStatus(e){return this.select(r=>r.iiif.requests[e])}getResourceMeta(e,r){const n=this.getState().iiif.meta[e];if(n)return r?n[r]:n}getObject(e,r,n={}){const{reactive:i,...s}=n;return be(this.get(e,r,s),this,i)}async loadObject(e,r){return be(await this.load(e,r),this)}async loadManifestObject(e,r){return be(await this.loadManifest(e,r),this)}async loadCollectionObject(e,r){return be(await this.loadCollection(e,r),this)}wrapObject(e){return be(this.get(e,{skipSelfReturn:!1}),this)}isWrapped(e){return Ts(e)}setMetaValue([e,r,n],i){this.dispatch(typeof i=="function"?Jt.setMetaValueDynamic({id:e,meta:r,key:n,updateValue:i}):Jt.setMetaValue({id:e,meta:r,key:n,value:i}))}};function js(){return typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{}}function $r(t){const e=js();try{const n=e.IIIF_VAULT;if(n)return n}catch{}const r=new Ct(t);try{e.IIIF_VAULT=r}catch{}return r}const $e=y.createContext({vault:null,setVaultInstance:t=>{}});function jt({vault:t,vaultOptions:e,useGlobal:r,resources:n,children:i}){const[s,a]=y.useState(()=>t||(r?$r(e):e?new Ct(e):new Ct));return g.jsx($e.Provider,{value:{vault:s,setVaultInstance:a},children:g.jsx(he,{value:n||{},children:i})})}const V=()=>{const{vault:t}=y.useContext($e);if(t===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return t};function Pt(t,{noCache:e=!1}={}){const r=typeof t=="string"?t:t.id,n=V(),[i,s]=y.useState(r),[a,o]=y.useState(void 0),u=y.useMemo(()=>n.get(r,{skipSelfReturn:!0})||void 0,[r,n]),[d,l]=y.useState(u);return y.useEffect(()=>{(async()=>{try{const p=u&&!e?u:await n.load(r),m=p?p.id||p["@id"]:null;p&&i!==m&&s(m),l(p)}catch(p){o(p)}})()},[r,e]),{isLoaded:!!d,id:i,requestId:r,error:a,resource:d,cached:!!(d&&d===u)}}function Dr(t,e){const{id:r,isLoaded:n,error:i,resource:s,requestId:a,cached:o}=Pt(t,e);return{id:r,isLoaded:n,error:i,manifest:s,requestId:a,cached:o}}function qr({manifest:t,children:e}){return g.jsx(he,{value:{manifest:t},children:e})}function Ke({canvas:t,children:e}){return g.jsx(he,{value:{canvas:t},children:e})}function U(t,e=[]){const r=V(),[n,i]=y.useState(()=>t(r.getState(),r));return y.useEffect(()=>r.subscribe(s=>t(s,r),s=>{i(s)},!1),e),n}const De=y.createContext([]);function Et(){const t=y.useContext(De);return U(e=>t.map(r=>e.iiif.entities.Canvas[r]).filter(Boolean),[t])}function ye(t={},e=[]){const{id:r,selector:n}=t,i=se();V();const s=r||i.manifest,a=U(o=>s?o.iiif.entities.Manifest[s]:void 0,[s]);return y.useMemo(()=>{if(a)return n?n(a):a},[a,n,...e])}function Vr({range:t,children:e}){return g.jsx(he,{value:{range:t},children:e})}function _r(t,e){for(const r of e.items){if(r.type==="Canvas")return r;if(r.type==="SpecificResource")return r.source;if(r.type==="Range"){const n=_r(t,t.get(r));if(n)return n}}return null}function Ot(t,e){var n;const r=[];for(const i of e.items)if(i.type==="SpecificResource"&&((n=i.source)==null?void 0:n.type)==="Canvas"&&(i.source.id.indexOf("#")!==-1?r.push({id:i.source.id.split("#")[0],type:"Canvas"}):r.push(i.source)),i.type==="Range"&&r.push(...Ot(t,t.get(i))),i.type==="SpecificResource"){const s=typeof i.source=="string"?i.source:i.source.id;r.push({id:s,type:"Canvas"})}return r}function Ps(t,e,r){for(const n of e.structures){const i=Lt(t,t.get(n),r);if(i)return i}return null}function Lt(t,e,r){var n,i,s;for(const a of e.items){const o=(i=(n=a==null?void 0:a.source)==null?void 0:n.id)==null?void 0:i.split("#")[0];if(a.type==="SpecificResource"&&a.source===r||a.type==="SpecificResource"&&((s=a.source)==null?void 0:s.type)==="Canvas"&&r===o)return e;if(a.type==="Range"){const u=Lt(t,t.get(a),r);if(u)return u}}return null}function Es(t,e,r,n=!1){const i=e.behavior,s=r?t.get(r):null;if(!s)return[];const a=s.behavior,o=n?!1:i.includes("paged"),u=o?!1:i.includes("continuous"),d=o||u?!1:i.includes("individuals"),l=a.includes("facing-pages"),p=a.includes("non-paged");if(l||p||d||n)return[{id:s.id,type:"Canvas"}];const[m,A]=Ft(t,e);if(u)return m;const h=m.findIndex(x=>x.id===r);if(h===-1)return[];for(const x of A)if(x.includes(h))return x.map(b=>m[b]);return[{id:s.id,type:"Canvas"}]}function Ft(t,e,{disablePaging:r,skipNonPaged:n}={}){const i=e.behavior,s=i.includes("paged"),a=s?!1:i.includes("continuous"),o=s||a?!1:i.includes("individuals"),u=e.type==="Manifest"?e.items:Ot(t,e);if(a)return[u,[u.map((h,x)=>x)]];if(o||!s||r)return[u,u.map((h,x)=>[x])];const d=[];let l=[];const p=()=>{l.length&&(d.push([...l]),l=[])};let m=0,A=!1;for(let h=0;h<u.length;h++){const x=t.get(u[h]);if(x.behavior.includes("non-paged")){h===m&&m++,n||(p(),d.push([h]),p());continue}if(h===m||x.behavior.includes("facing-pages")){l.length&&(A=!0),p(),d.push([h]),p();continue}if(l.push(h),A){p(),A=!1;continue}l.length>1&&p()}return l.length&&p(),[u,d]}function Ur(t={},e=[]){const{id:r,selector:n}=t,i=se(),s=r||i.range,a=U(o=>s?o.iiif.entities.Range[s]:void 0,[s]);return y.useMemo(()=>{if(a)return n?n(a):a},[a,n,...e])}function Hr({startCanvas:t,disablePaging:e}){var h;const r=V(),n=ye(),i=Ur(),[s,a]=y.useState(void 0),o=i||n;if(!o)throw new Error("Nothing selected");const[u,d]=y.useMemo(()=>Ft(r,o,{disablePaging:e}),[r,o]),l=y.useCallback(x=>{const b=d.findIndex(S=>S.includes(x));a(b===-1?0:b)},[u,d]),p=y.useCallback(x=>{const b=u.findIndex(S=>S.id===x);b!==-1?l(b):a(0)},[u,d]),m=y.useCallback(()=>{a(x=>x>=d.length?x:x+1)},[d]),A=y.useCallback(()=>{a(x=>x<=0?0:x-1)},[d]);return typeof s>"u"&&(t?p(t):a(0)),{visibleItems:((h=d[s])==null?void 0:h.map(x=>u[x].id))||[],cursor:s,items:u,sequence:d,setSequenceIndex:a,setCanvasIndex:l,setCanvasId:p,next:m,previous:A}}const ke=()=>{},qe=y.createContext({setCurrentCanvasId:ke,setCurrentCanvasIndex:ke,nextCanvas:ke,previousCanvas:ke,items:[],sequence:[],setSequenceIndex:ke,currentSequenceIndex:0});function Nr(t){const e=ye(),{cursor:r,visibleItems:n,next:i,sequence:s,items:a,setCanvasIndex:o,setCanvasId:u,previous:d,setSequenceIndex:l}=Hr({startCanvas:t.startCanvas,disablePaging:t.pagingEnabled===!1}),p=y.useMemo(()=>({sequence:s,items:a,setCurrentCanvasId:u,nextCanvas:i,previousCanvas:d,totalCanvases:a.length,setCurrentCanvasIndex:o,setSequenceIndex:l,currentSequenceIndex:r}),[s,a,u,i,d,a,o,l,r]);return e?n.length===0?null:g.jsx(qe.Provider,{value:p,children:g.jsx(De.Provider,{value:n,children:g.jsx(Ke,{canvas:n[0],children:t.children})})}):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),g.jsx("div",{children:"Sorry, something went wrong."}))}function Br(t){const e=Dr(t.manifest);if(!e)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),g.jsx("div",{children:"Sorry, something went wrong."});if(e.error)return g.jsx("div",{children:e.error.toString()});if(!e.isLoaded)return g.jsx("div",{children:"Loading..."});const r=g.jsx(Nr,{...t,children:t.children});return g.jsx(qr,{manifest:e.id,children:t.rangeId?g.jsx(Vr,{range:t.rangeId,children:r}):r})}function zr(){return y.useContext(qe)}function Wr(){return{VaultContext:y.useContext($e),ResourceContext:y.useContext(Je),SimpleViewerReactContext:y.useContext(qe),VisibleCanvasReactContext:y.useContext(De)}}function Qr(t){return g.jsx(jt,{vault:t.bridge.VaultContext.vault||void 0,resources:t.bridge.ResourceContext,children:g.jsx(De.Provider,{value:t.bridge.VisibleCanvasReactContext,children:g.jsx(qe.Provider,{value:t.bridge.SimpleViewerReactContext,children:t.children})})})}const te=function(t){return function(){const e={type:t,getType:()=>t,toString:()=>t};return(r,n)=>({...e,...r!==void 0&&{payload:r},...n!==void 0&&{meta:n}})}},Os="@iiif/IMPORT_ENTITIES",Ls="@iiif/MODIFY_ENTITY_FIELD",Fs="@iiif/REORDER_ENTITY_FIELD",$s="@iiif/ADD_REFERENCE",Ds="@iiif/UPDATE_REFERENCE",qs="@iiif/REMOVE_REFERENCE",Vs="@iiif/ADD_METADATA",_s="@iiif/REMOVE_METADATA",Us="@iiif/UPDATE_METADATA",Hs="@iiif/REORDER_METADATA",Ns=te(Os)(),Bs=te(Ls)(),zs=te(Fs)(),Ws=te($s)(),Qs=te(qs)(),Ys=te(Ds)(),Gs=te(Vs)(),Js=te(Us)(),Ks=te(_s)(),Zs=te(Hs)(),ft={importEntities:Ns,modifyEntityField:Bs,reorderEntityField:zs,addReference:Ws,removeReference:Qs,updateReference:Ys,addMetadata:Gs,removeMetadata:Ks,updateMetadata:Js,reorderMetadata:Zs};function Yr(){const e=V().getStore();return y.useMemo(()=>r=>e.dispatch(r),[e])}function nr(t){return typeof t!="string"&&t&&t.bindToVault}function Gr(){const t=V(),e=y.useRef([]),r=Yr(),n=y.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);y.useLayoutEffect(()=>{const o={id:n,type:"AnnotationPage",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],rendering:[],service:[]};r(ft.importEntities({entities:{AnnotationPage:{[o.id]:o}}}))},[n]);const i=U(o=>n?o.iiif.entities.AnnotationPage[n]:null,[n]),s=y.useCallback((o,u)=>{if(n){if(nr(o)){const p=o;p.__vault||p.bindToVault(t),o=typeof p.source=="string"?p.source:p.source.id,e.current[o]=p}else typeof o!="string"&&(o=o.id);const d=t.get({id:n,type:"AnnotationPage"}),l=t.get({id:o,type:"Annotation"});d&&l&&(d.items.find(p=>p.id===l.id)||r(ft.addReference({id:n,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"},index:u})))}},[n]),a=y.useCallback(o=>{n&&(nr(o)?o=typeof o.source=="string"?o.source:o.source.id:typeof o!="string"&&(o=o.id),e.current[o]&&e.current[o].beforeRemove(),t.get({id:n,type:"AnnotationPage"})&&r(ft.removeReference({id:n,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"}})))},[n]);return[i,{addAnnotation:s,removeAnnotation:a}]}const Jr=y.createContext(null);function Kr(){const t=y.useContext(Jr);return[t.fullPage,{addAnnotation:t.addAnnotation,removeAnnotation:t.removeAnnotation}]}function Zr({children:t}){const[e,{addAnnotation:r,removeAnnotation:n}]=Gr();return g.jsx(Jr.Provider,{value:y.useMemo(()=>({fullPage:e,addAnnotation:r,removeAnnotation:n}),[e]),children:t})}function Xs({width:t,style:e,height:r,error:n,resetErrorBoundary:i}){return g.jsxs("div",{style:{width:t,height:r,minHeight:500,...e||{},background:"#f9f9f9"},children:[g.jsx("h3",{children:"Error occurred"}),g.jsx("p",{children:n.message}),g.jsx("button",{onClick:i,children:"Reset"})]})}const Ze=y.createContext(null);function Xr(){return y.useContext(Ze)}const en=y.createContext(()=>{}),tn=y.createContext(()=>{});function Ie(t,e,r,n,i=[]){const s=y.useContext(t==="portal"?tn:en);y.useEffect(()=>(t!=="none"&&s(e,r,n),()=>{s(e,null)}),[e,t,s,...i])}function re(t={},e=[]){const{id:r,selector:n}=t,i=se(),s=r||i.canvas,a=U(o=>s?o.iiif.entities.Canvas[s]:void 0,[s]);return y.useMemo(()=>{if(a)return n?n(a):a},[a,n,...e])}const rn=y.createContext(()=>{});function ea(t){const e=re(),r=y.useContext(rn);y.useEffect(()=>e&&e.id?(r(e.id,t),()=>r(e.id,-1)):()=>{},[e,t])}function ta({children:t,errorFallback:e,outerContainerProps:r={},worldScale:n,...i}){const[s,a]=y.useState(),o=Wr(),u=e||Xs,[d,l]=y.useState({}),p=Object.entries(d),[m,A]=y.useState({}),h=Object.entries(m),[x,b]=y.useState({}),S=y.useMemo(()=>n||Math.max(...Object.values(x)),[x]),w=y.useMemo(()=>({maxOverZoom:S||1,...i.runtimeOptions||{}}),[S,i.runtimeOptions]),M=y.useCallback((k,O)=>{b(E=>{if(O===-1){const{[k]:R,...$}=E;return $}return{...E,[k]:O}})},[]),T=y.useCallback((k,O,E)=>{l(({[k]:R,...$})=>O?{...$,[k]:{element:O,props:E}}:$)},[]),F=y.useCallback((k,O,E)=>{A(({[k]:R,...$})=>O?{...$,[k]:{element:O,props:E}}:$)},[]);return g.jsxs(Di,{resetKeys:[],fallbackRender:k=>g.jsx(u,{...i,...k}),children:[g.jsx(Re.AtlasAuto,{...i,containerProps:{style:{position:"relative"},...i.containerProps||{}},htmlChildren:g.jsx(g.Fragment,{children:p.map(([k,{element:O,props:E}])=>g.jsx(y.Fragment,{children:g.jsx(O,{...E||{}})},k))}),onCreated:k=>{a(k),i.onCreated&&i.onCreated(k)},runtimeOptions:w,children:g.jsx(Ze.Provider,{value:s,children:g.jsx(rn.Provider,{value:M,children:g.jsx(en.Provider,{value:T,children:g.jsx(tn.Provider,{value:F,children:g.jsx(Qr,{bridge:o,children:g.jsx(Re.ModeContext.Provider,{value:i.mode||"explore",children:g.jsx(Zr,{children:t})})})})})})})}),g.jsx("div",{children:h.map(([k,{element:O,props:E}])=>g.jsx(y.Fragment,{children:g.jsx(O,{...E||{}})},k))})]})}const He={},nn={get(t){return t},setMetaValue([t,e,r],n){const i=nn.getResourceMeta(t,e),s=i?i[r]:void 0,a=typeof n=="function"?n(s):n;He[t]={...He[t]||{},[e]:{...(He[t]||{})[e]||{},[r]:a}}},getResourceMeta:(t,e)=>{const r=He[t];if(r)return e?r[e]:r}};function sn(t=nn){return{addEventListener(e,r,n,i){if(e)return t.setMetaValue([e.id,"eventManager",r],s=>{const a=s||[];for(const o of a)if(o.callback===n)return a;return[...a,{callback:n,scope:i}]}),n},removeEventListener(e,r,n){e&&t.setMetaValue([e.id,"eventManager",r],i=>(i||[]).filter(s=>s.callback!==n))},getListenersAsProps(e,r){const n=typeof e=="string"?{id:e}:e;if(!n||!n.id)return{};const i=t.getResourceMeta(n.id,"eventManager"),s={};if(i&&n)for(const a of Object.keys(i))s[a]=o=>{const u=t.get(n);for(const{callback:d,scope:l}of i[a]||[])(!l||r&&l.indexOf(r)!==-1)&&d(o,u)};return s}}}function $t(t,e){const r=V(),n=y.useMemo(()=>sn(r),[r]),i=U(()=>t&&t.id?r.getResourceMeta(t.id,"eventManager"):null,[t]);return y.useMemo(()=>t?n.getListenersAsProps(t,e):{},[i,t,r,e])}const Ne={},an={get(t){return t},setMetaValue([t,e,r],n){const i=an.getResourceMeta(t,e),s=i?i[r]:void 0,a=typeof n=="function"?n(s):n;Ne[t]={...Ne[t]||{},[e]:{...(Ne[t]||{})[e]||{},[r]:a}}},getResourceMeta:(t,e)=>{const r=Ne[t];if(r)return e?r[e]:r}};function Dt(t=an){return{applyStyles(e,r,n){const i=typeof e=="string"?e:e.id;return t.setMetaValue([i,"styles",r],n)},getAppliedStyles(e){const r=typeof e=="string"?e:e.id;return t.getResourceMeta(r,"styles")}}}function Fe(t,e){const r=V(),n=y.useMemo(()=>Dt(r),[r]);return U(()=>{if(!t)return null;const i=n.getAppliedStyles(t.id);return i?e?i[e]:i:void 0},[t,e])}var ra=Object.defineProperty,na=(t,e,r)=>e in t?ra(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,We=(t,e,r)=>(na(t,typeof e!="symbol"?e+"":e,r),r),ia=function(){function t(e,r){var n=[],i=!0,s=!1,a=void 0;try{for(var o=e[Symbol.iterator](),u;!(i=(u=o.next()).done)&&(n.push(u.value),!(r&&n.length===r));i=!0);}catch(d){s=!0,a=d}finally{try{!i&&o.return&&o.return()}finally{if(s)throw a}}return n}return function(e,r){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),je=Math.PI*2,pt=function(t,e,r,n,i,s,a){var o=t.x,u=t.y;o*=e,u*=r;var d=n*o-i*u,l=i*o+n*u;return{x:d+s,y:l+a}},sa=function(t,e){var r=e===1.5707963267948966?.551915024494:e===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(e/4),n=Math.cos(t),i=Math.sin(t),s=Math.cos(t+e),a=Math.sin(t+e);return[{x:n-i*r,y:i+n*r},{x:s+a*r,y:a-s*r},{x:s,y:a}]},ir=function(t,e,r,n){var i=t*n-e*r<0?-1:1,s=t*r+e*n;return s>1&&(s=1),s<-1&&(s=-1),i*Math.acos(s)},aa=function(t,e,r,n,i,s,a,o,u,d,l,p){var m=Math.pow(i,2),A=Math.pow(s,2),h=Math.pow(l,2),x=Math.pow(p,2),b=m*A-m*x-A*h;b<0&&(b=0),b/=m*x+A*h,b=Math.sqrt(b)*(a===o?-1:1);var S=b*i/s*p,w=b*-s/i*l,M=d*S-u*w+(t+r)/2,T=u*S+d*w+(e+n)/2,F=(l-S)/i,k=(p-w)/s,O=(-l-S)/i,E=(-p-w)/s,R=ir(1,0,F,k),$=ir(F,k,O,E);return o===0&&$>0&&($-=je),o===1&&$<0&&($+=je),[M,T,R,$]},oa=function(t){var e=t.px,r=t.py,n=t.cx,i=t.cy,s=t.rx,a=t.ry,o=t.xAxisRotation,u=o===void 0?0:o,d=t.largeArcFlag,l=d===void 0?0:d,p=t.sweepFlag,m=p===void 0?0:p,A=[];if(s===0||a===0)return[];var h=Math.sin(u*je/360),x=Math.cos(u*je/360),b=x*(e-n)/2+h*(r-i)/2,S=-h*(e-n)/2+x*(r-i)/2;if(b===0&&S===0)return[];s=Math.abs(s),a=Math.abs(a);var w=Math.pow(b,2)/Math.pow(s,2)+Math.pow(S,2)/Math.pow(a,2);w>1&&(s*=Math.sqrt(w),a*=Math.sqrt(w));var M=aa(e,r,n,i,s,a,l,m,h,x,b,S),T=ia(M,4),F=T[0],k=T[1],O=T[2],E=T[3],R=Math.abs(E)/(je/4);Math.abs(1-R)<1e-7&&(R=1);var $=Math.max(Math.ceil(R),1);E/=$;for(var X=0;X<$;X++)A.push(sa(O,E)),O+=E;return A.map(function(Y){var _=pt(Y[0],s,a,x,h,F,k),H=_.x,J=_.y,ee=pt(Y[1],s,a,x,h,F,k),ge=ee.x,P=ee.y,N=pt(Y[2],s,a,x,h,F,k),G=N.x,ue=N.y;return{x1:H,y1:J,x2:ge,y2:P,x:G,y:ue}})};function on(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var ca=la,dt={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},ua=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function la(t){var e=[];return t.replace(ua,function(r,n,i){var s=n.toLowerCase();for(i=pa(i),s=="m"&&i.length>2&&(e.push([n].concat(i.splice(0,2))),s="l",n=n=="m"?"l":"L");;){if(i.length==dt[s])return i.unshift(n),e.push(i);if(i.length<dt[s])throw new Error("malformed path data");e.push([n].concat(i.splice(0,dt[s])))}}),e}var fa=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function pa(t){var e=t.match(fa);return e?e.map(Number):[]}const da=on(ca);var ha=ya;function ya(t){var e=0,r=0,n=0,i=0;return t.map(function(s){s=s.slice();var a=s[0],o=a.toUpperCase();if(a!=o)switch(s[0]=o,a){case"a":s[6]+=n,s[7]+=i;break;case"v":s[1]+=i;break;case"h":s[1]+=n;break;default:for(var u=1;u<s.length;)s[u++]+=n,s[u++]+=i}switch(o){case"Z":n=e,i=r;break;case"H":n=s[1];break;case"V":i=s[1];break;case"M":n=e=s[1],i=r=s[2];break;default:n=s[s.length-2],i=s[s.length-1]}return s})}const va=on(ha);function ga(t){const e=da(t),r=va(e);let n,i=0,s=0,a=0,o=0,u,d,l=0,p=0;const m=[];for(let A=0;A<r.length;A++){let h=r[A];const x=h[0];switch(x){case"M":i=h[1],s=h[2];break;case"H":h=["L",h[1],s];break;case"V":h=["L",i,h[1]];break;case"S":{let b=l,S=p;(n==="C"||n=="S")&&(b+=b-a,S+=S-o),h=["C",b,S,h[1],h[2],h[3],h[4]]}break;case"T":n==="Q"||n=="T"?(u=l*2-u,d=p*2-d):(u=l,d=p),h=["Q",u,d,h[1],h[2]];break;case"Q":u=h[1],d=h[2];break;case"A":{const b=oa({px:l,py:p,cx:h[6],cy:h[7],rx:h[1],ry:h[2],xAxisRotation:h[3],largeArcFlag:h[4],sweepFlag:h[5]});if(!b.length)continue;for(const[S,w]of b.entries())h=["C",w.x1,w.y1,w.x2,w.y2,w.x,w.y],S<b.length-1&&m.push(h);h=h}break;case"Z":h=["L",i,s];break}n=x,l=h[h.length-2],p=h[h.length-1],["C","Q","A"].indexOf(x)>-1?(a=h[h.length-4],o=h[h.length-3]):(a=l,o=p),m.push(h)}return m}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
6
6
  *
7
7
  * All code in this module is based on JavaScript code by Raph Levien, published on his blog at
8
8
  * https://raphlinus.github.io/.
@@ -32,7 +32,7 @@
32
32
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33
33
  * See the License for the specific language governing permissions and
34
34
  * limitations under the License.
35
- */function da(e,t,r,n=1){return new cn(e,t,r).subdivide(n)}function ha(e,t,r,n,i=1){return new Dt(new Float64Array([e.x,e.y,t.x,t.y,r.x,r.y,n.x,n.y])).subdivide(i)}function va(e){return e.x*e.x+e.y*e.y}function Ee(e){return e/(1-.67+Math.pow(Math.pow(.67,4)+.25*e*e,.25))}function Ce(e){return e*(1-.39+Math.sqrt(.39*.39+.25*e*e))}class cn{constructor(t,r,n){We(this,"start"),We(this,"control"),We(this,"end"),this.start=t,this.control=r,this.end=n}eval(t){const r=1-t;return{x:this.start.x*r*r+2*this.control.x*r*t+this.end.x*t*t,y:this.start.y*r*r+2*this.control.y*r*t+this.end.y*t*t}}mapToBasic(){const{x:t,y:r}=this.start,{x:n,y:i}=this.control,{x:s,y:a}=this.end,o=2*n-t-s,u=2*i-r-a,d=(n-t)*o+(i-r)*u,l=(s-n)*o+(a-i)*u,p=(s-t)*u-(a-r)*o,g=d/p,b=l/p,h=Math.abs(p)/(Math.hypot(o,u)*Math.abs(b-g));return{x0:t,x2:s,scale:h,cross:p}}subdivide(t){const r=this.mapToBasic(),n=Ee(r.x0),i=Ee(r.x2),s=.5*Math.abs(i-n)*Math.sqrt(r.scale/t),a=Math.ceil(s),o=Ce(n),u=Ce(i),d=[0];for(let l=1;l<a;l++){const p=(Ce(n+(i-n)*l/a)-o)/(u-o);d.push(p)}return d.push(1),d.map(l=>this.eval(l))}}class Dt{constructor(t){We(this,"c"),this.c=t}weightsum(t,r,n,i){const s=t*this.c[0]+r*this.c[2]+n*this.c[4]+i*this.c[6],a=t*this.c[1]+r*this.c[3]+n*this.c[5]+i*this.c[7];return{x:s,y:a}}eval(t){const r=1-t,n=r*r*r,i=3*r*r*t,s=3*r*t*t,a=t*t*t;return this.weightsum(n,i,s,a)}deriv(t){const r=1-t,n=-3*r*r,i=3*t*t,s=-6*t*r-n,a=6*t*r-i;return this.weightsum(n,s,a,i)}midpoint_quadbez(){const t=this.weightsum(-.25,.75,.75,-.25);return new cn({x:this.c[0],y:this.c[1]},t,{x:this.c[6],y:this.c[7]})}subsegment(t,r){const n=new Float64Array(8),i=this.eval(t),s=this.eval(r);n[0]=i.x,n[1]=i.y;const a=(r-t)/3,o=this.deriv(t);n[2]=i.x+a*o.x,n[3]=i.y+a*o.y;const u=this.deriv(r);return n[4]=s.x-a*u.x,n[5]=s.y-a*u.y,n[6]=s.x,n[7]=s.y,new Dt(n)}subdivide(t){const r=.1*t,n=t-r,i=Math.sqrt(n),s=va(this.weightsum(1,-3,3,-1)),a=Math.ceil(Math.pow(s/(432*r*r),1/6)),o=[];let u=0;for(let h=0;h<a;h++){const x=h/a,A=(h+1)/a,S=this.subsegment(x,A).midpoint_quadbez(),w=S.mapToBasic(),M=Ee(w.x0),T=Ee(w.x2),F=Math.sqrt(w.scale);let k=Math.abs(T-M)*F;if(Math.sign(w.x0)!=Math.sign(w.x2)){const O=i/F,P=i*Math.abs(T-M)/Ee(O);k=Math.max(k,P)}o.push({quad:S,a0:M,a2:T,val:k}),u+=k}const d=.5*u/i,l=Math.ceil(d),p=[{x:this.c[0],y:this.c[1]}];let g=0,b=0;for(let h=1;h<l;h++){const x=u*h/l;for(;g+o[b].val<x;)g+=o[b].val,b++;const A=o[b].a0,S=o[b].a2,w=Ce(A),M=Ce(S),T=A+(S-A)*(x-g)/o[b].val,F=(Ce(T)-w)/(M-w);p.push(o[b].quad.eval(F))}return p.push({x:this.c[6],y:this.c[7]}),p}}const ya=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,ga=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,ir=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function Pe(e,{domParser:t,svgPreprocessor:r,iiifRenderingHints:n}={}){if(Array.isArray(e))return K(e.reduce((i,s)=>{const{selector:a,selectors:o,iiifRenderingHints:u}=Pe(s,{domParser:t,svgPreprocessor:r,iiifRenderingHints:n});return a&&(i.selector||(i.selector=a),i.selectors.push(...o)),u&&(i.iiifRenderingHints=i.iiifRenderingHints||{type:"ImageApiSelector"},Object.assign(i.iiifRenderingHints,u)),i},{selector:null,selectors:[],iiifRenderingHints:n}));if(!e)return K({selector:null,selectors:[],iiifRenderingHints:n});if(typeof e=="string"){const[i,s]=e.split("#");return s?Pe({type:"FragmentSelector",value:s},{svgPreprocessor:r,iiifRenderingHints:n,domParser:t}):K({selector:null,selectors:[],iiifRenderingHints:n})}if(e.type&&e.type==="PointSelector"&&(e.t||e.t===0)){const i={type:"TemporalSelector",temporal:{startTime:e.t}};return K({selector:i,selectors:[i],iiifRenderingHints:n})}if(ln(e)){const i=[];if(e.region){const s=Pe({type:"FragmentSelector",value:"xywh="+e.region},{domParser:t,svgPreprocessor:r,iiifRenderingHints:n});i.push(...s.selectors)}return K({selector:i[0],selectors:i,iiifRenderingHints:n?{...n,...e}:e})}if(e.type==="FragmentSelector"){const i=ya.exec(e.value);if(i){const a={type:"BoxSelector",spatial:{unit:i[2]==="percent:"||i[2]==="pct:"?"percent":"pixel",x:parseFloat(i[3]),y:parseFloat(i[4]),width:parseFloat(i[5]),height:parseFloat(i[6])}};return K({selector:a,selectors:[a],iiifRenderingHints:n})}const s=e.value.match(ga);if(s){const a={type:"TemporalSelector",temporal:{startTime:s[4]?parseFloat(s[4]):0,endTime:s[7]?parseFloat(s[7]):void 0}};return K({selector:a,selectors:[a],iiifRenderingHints:n})}return K({selector:null,selectors:[],iiifRenderingHints:n})}if(e.type==="SvgSelector"&&"value"in e){t||(typeof window<"u"?t=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 i=[],s,a,o=(r==null?void 0:r(e.value))??e.value,u;if(t){const l=t.parseFromString(e.value,"image/svg+xml").querySelector("svg");if(!l)return console.warn(`Illegal SVG selector: ${e.value}`),K({selector:null,selectors:[],iiifRenderingHints:n});const p=un(l);p&&(i=p.points,u=p.shapeType,s=[Math.min(...i.map(g=>g[0])),Math.min(...i.map(g=>g[1])),Math.max(...i.map(g=>g[0])),Math.max(...i.map(g=>g[1]))],{style:a,svg:o}=ba(p.element)??{svg:o})}const d={type:"SvgSelector",svg:o,svgShape:u,style:a,points:i.length?i:void 0,spatial:s?{unit:"pixel",x:s[0],y:s[1],width:s[2]-s[0],height:s[3]-s[1]}:void 0};return K({selector:d,selectors:[d],iiifRenderingHints:n})}return K({selector:null,selectors:[],iiifRenderingHints:n})}function ma(e){const t=e.map(n=>n[0]).reduce((n,i)=>(n[i]+=1,n),{C:0,Q:0,L:0,M:0}),r=new Set(e.map(n=>n[0]));if(t.C>0||t.Q>0)return"path";if(t.L>0&&(r.size===1||r.size===2&&r.has("M"))){if(t.L===4)return"rect";const n=e.slice(-1)[0];return e[0][0]==="M"&&n[0]==="L"&&n[1]==e[0][1]&&n[2]===e[0][2]||n[1]===0&&n[2]===0?"polygon":"polyline"}return"path"}function un(e){var t;for(const r of Array.from(e.children))switch(r==null?void 0:r.tagName.toLowerCase()){case"g":{const n=un(r);if(n)return n}continue;case"path":{const n=r.getAttribute("d");if(!n)continue;const i=pa(n);return{element:r,points:xa(i),shapeType:ma(i)}}case"circle":{const n=parseFloat(r.getAttribute("cx")??"0"),i=parseFloat(r.getAttribute("cy")??"0"),s=parseFloat(r.getAttribute("r")??"0");if(!s)continue;const a=[];for(let o=0;o<=360;o+=12){const u=o*Math.PI/180;a.push([n+s*Math.cos(u),i+s*Math.sin(u)])}return{element:r,points:a,shapeType:"circle"}}case"ellipse":{const n=parseFloat(r.getAttribute("cx")??"0"),i=parseFloat(r.getAttribute("cy")??"0"),s=parseFloat(r.getAttribute("rx")??"0"),a=parseFloat(r.getAttribute("ry")??"0");if(!s&&!a)continue;const o=[];for(let u=0;u<=360;u+=12){const d=Math.tan(u/360*Math.PI),l=s*(1-d**2)/(1+d**2),p=a*2*d/(1+d**2);o.push([n+l,i+p])}return{element:r,points:o,shapeType:"ellipse"}}case"line":{const n=parseFloat(r.getAttribute("x0")??"0"),i=parseFloat(r.getAttribute("y0")??"0"),s=parseFloat(r.getAttribute("x1")??"0"),a=parseFloat(r.getAttribute("y1")??"0");if(n===s&&i===a)continue;return{element:r,points:[[n,i],[s,a]],shapeType:"polyline"}}case"polygon":case"polyline":{const n=((t=r.getAttribute("points"))==null?void 0:t.split(" ").map(s=>s.split(",").map(parseFloat)))??[];if(!n.length)continue;let i="polyline";return r.tagName.toLowerCase()==="polygon"&&(n.push(n[0]),i="polygon"),{element:r,points:n,shapeType:i}}case"rect":{const n=parseFloat(r.getAttribute("x")??"0"),i=parseFloat(r.getAttribute("y")??"0"),s=parseFloat(r.getAttribute("width")??"0"),a=parseFloat(r.getAttribute("height")??"0");if(!s||!a)continue;return{element:r,points:[[n,i],[n+s,i],[n+s,i+a],[n,i+a],[n,i]],shapeType:"rect"}}default:continue}return null}function xa(e){const t=[];for(let r=0;r<e.length;r++){const n=t[t.length-1]??[0,0],i=e[r];switch(i[0]){case"M":case"L":t.push([i[1],i[2]]);continue;case"C":t.push(...ha({x:n[0],y:n[1]},{x:i[1],y:i[2]},{x:i[3],y:i[4]},{x:i[5],y:i[6]}).map(s=>[s.x,s.y]).slice(1));continue;case"Q":t.push(...da({x:n[0],y:n[1]},{x:i[1],y:i[2]},{x:i[3],y:i[4]}).map(s=>[s.x,s.y]).slice(1));continue}}return t}function ba(e){const t={};if(e.hasAttribute("fill")?(t.fill=e.getAttribute("fill"),e.removeAttribute("fill")):e.style.fill&&(t.fill=e.style.fill),t.fill){const n=ir.exec(t.fill);n&&(t.fillOpacity=parseFloat(n[4]),t.fill=`rgb(${n[1]}, ${n[2]}, ${n[3]})`)}if(e.hasAttribute("fill-opacity")?(t.fillOpacity=parseFloat(e.getAttribute("fill-opacity")),e.removeAttribute("fill-opacity")):e.style.fillOpacity&&(t.fillOpacity=parseFloat(e.style.fillOpacity)),e.hasAttribute("stroke")?(t.stroke=e.getAttribute("stroke"),e.removeAttribute("stroke")):e.style.stroke&&(t.stroke=e.style.stroke),t.stroke){const n=ir.exec(t.stroke);n&&(t.strokeOpacity=parseFloat(n[4]),t.stroke=`rgb(${n[1]}, ${n[2]}, ${n[3]})`)}e.hasAttribute("stroke-opacity")?(t.strokeOpacity=parseFloat(e.getAttribute("stroke-opacity")),e.removeAttribute("stroke-opacity")):e.style.strokeOpacity&&(t.strokeOpacity=parseFloat(e.style.strokeOpacity)),e.hasAttribute("stroke-width")?(t.strokeWidth=e.getAttribute("stroke-width"),e.removeAttribute("stroke-width")):e.style.strokeWidth&&(t.strokeWidth=e.style.strokeWidth),e.hasAttribute("stroke-dasharray")?(t.strokeDasharray=e.getAttribute("stroke-dasharray"),e.removeAttribute("stroke-dasharray")):e.style.strokeDasharray&&(t.strokeDasharray=e.style.strokeDasharray);let r=e;for(;r.tagName.toLowerCase()!=="svg";)if(r=r.parentElement,r===null)throw new Error("Could not find root SVG element");return{svg:r.outerHTML,style:Object.keys(t).length>0?t:void 0}}function ln(e){return!!e&&e.type==="iiif:ImageApiSelector"&&e.type==="iiif:ImageApiSelector"}function K(e){if(e.iiifRenderingHints){const t=e.iiifRenderingHints;if(t.rotation){const r=fn(t.rotation);if(r)if(e.selectors.length)for(const n of e.selectors)n.rotation=r;else e.selectors.push({type:"RotationSelector",rotation:r})}}else delete e.iiifRenderingHints;return e}function fn(e){let t=parseFloat(e);return t&&e.startsWith("!")&&(t=360-t),t&&(t=t%360),t!==t?0:t||0}function de(e,t={}){if(Array.isArray(e))return de(e[0]);if(typeof e=="string"){const[r,n]=e.split("#");return n?de({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{id:r,type:t.typeMap&&t.typeMap[r]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return de(e.items[0]);if(e.type==="SpecificResource"){e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]);const{selector:r,selectors:n}=e.selector?Pe(e.selector,t):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:r,selectors:n}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[r,n]=e.id.split("#");return n?de({type:"SpecificResource",source:{...e,id:r},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{...e,id:r},selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function qt(e={},t=[]){const{id:r,selector:n}=e,i=se(),s=V(),a=r||i.annotation,o=U(d=>a?d.iiif.entities.Annotation[a]:void 0,[a]),u=U(d=>o&&o.body?o.body.map(l=>l?l.type==="SpecificResource"?{...l,source:s.get(l)}:l?d.iiif.entities[l.type][l.id]:null:null).filter(Boolean):[],[o]);return v.useMemo(()=>{if(!o)return;const d={...o,body:u,target:de(o.target,{typeMap:s.getState().iiif.mapping})};return n?n(d):d},[o,n,u,...t])}const pn=({id:e,style:t,className:r,interactive:n})=>{const i=qt({id:e}),s=Fe(i,"atlas"),a=Fe(i,"html"),o=Ft(i,["atlas"]),u=re(),d=v.useMemo(()=>Re.mergeStyles(t,s),[t,s]);return u&&i&&i.target&&i.target.selector&&i.target.selector.type==="BoxSelector"&&i.target.source&&(i.target.source.id===u.id||i.target.source===u.id)?m.jsx(Re.RegionHighlight,{id:i.id,isEditing:!0,region:i.target.selector.spatial,style:d,className:(a==null?void 0:a.className)||r,interactive:!!(a!=null&&a.href||n),href:(a==null?void 0:a.href)||null,title:(a==null?void 0:a.title)||null,hrefTarget:(a==null?void 0:a.target)||null,onClick:()=>{},...o}):null};function dn(e={},t=[]){const{id:r,selector:n}=e,i=se(),s=r||i.annotationPage,a=U(o=>s?o.iiif.entities.AnnotationPage[s]:void 0,[s]);return v.useMemo(()=>{if(a)return n?n(a):a},[a,...t])}const Ct=({className:e,page:t})=>{var s;const r=dn({id:t.id})||t,n=Fe(r,"atlas"),i=Fe(r,"html");return U(a=>r.id?a.iiif.entities.AnnotationPage[r.id]:null,[]),m.jsx(v.Fragment,{children:(s=r.items)==null?void 0:s.map(a=>m.jsx(pn,{id:a.id,style:n,className:(i==null?void 0:i.className)||e},a.id))})};function hn({id:e,image:t,thumbnail:r,isStatic:n,x:i=0,y:s=0,children:a,selector:o,onClick:u,enableSizes:d}){var p,g;const l=v.useMemo(()=>{if(!(!o||o.spatial.x===0&&o.spatial.y===0))return o.spatial},[o]);return m.jsx("world-object",{x:i+t.target.spatial.x,y:s+t.target.spatial.y,width:t.target.spatial.width,height:t.target.spatial.height,onClick:u,children:t.service?m.jsxs(v.Fragment,{children:[m.jsx(Re.TileSet,{tiles:{id:t.service.id||t.service["@id"]||"unknown",height:t.height,width:t.width,imageService:t.service,thumbnail:r&&r.type==="fixed"?r:void 0},enableSizes:d,x:0,y:0,width:(p=t.target)==null?void 0:p.spatial.width,height:(g=t.target)==null?void 0:g.spatial.height,crop:l}),a]},"service"):m.jsxs(v.Fragment,{children:[m.jsx("world-image",{onClick:u,uri:t.id,target:{x:0,y:0,width:t.target.spatial.width,height:t.target.spatial.height},display:t.width&&t.height?{width:t.width,height:t.height}:void 0,crop:l}),a]},"no-service")},e+(t.service?"server":"no-service"))}var Aa=Object.defineProperty,Sa=(e,t,r)=>t in e?Aa(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Qe=(e,t,r)=>(Sa(e,typeof t!="symbol"?t+"":t,r),r),wa=function(){function e(t,r){var n=[],i=!0,s=!1,a=void 0;try{for(var o=t[Symbol.iterator](),u;!(i=(u=o.next()).done)&&(n.push(u.value),!(r&&n.length===r));i=!0);}catch(d){s=!0,a=d}finally{try{!i&&o.return&&o.return()}finally{if(s)throw a}}return n}return function(t,r){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),Oe=Math.PI*2,ht=function(e,t,r,n,i,s,a){var o=e.x,u=e.y;o*=t,u*=r;var d=n*o-i*u,l=i*o+n*u;return{x:d+s,y:l+a}},Ca=function(e,t){var r=t===1.5707963267948966?.551915024494:t===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(t/4),n=Math.cos(e),i=Math.sin(e),s=Math.cos(e+t),a=Math.sin(e+t);return[{x:n-i*r,y:i+n*r},{x:s+a*r,y:a-s*r},{x:s,y:a}]},sr=function(e,t,r,n){var i=e*n-t*r<0?-1:1,s=e*r+t*n;return s>1&&(s=1),s<-1&&(s=-1),i*Math.acos(s)},Ma=function(e,t,r,n,i,s,a,o,u,d,l,p){var g=Math.pow(i,2),b=Math.pow(s,2),h=Math.pow(l,2),x=Math.pow(p,2),A=g*b-g*x-b*h;A<0&&(A=0),A/=g*x+b*h,A=Math.sqrt(A)*(a===o?-1:1);var S=A*i/s*p,w=A*-s/i*l,M=d*S-u*w+(e+r)/2,T=u*S+d*w+(t+n)/2,F=(l-S)/i,k=(p-w)/s,O=(-l-S)/i,P=(-p-w)/s,R=sr(1,0,F,k),$=sr(F,k,O,P);return o===0&&$>0&&($-=Oe),o===1&&$<0&&($+=Oe),[M,T,R,$]},Ra=function(e){var t=e.px,r=e.py,n=e.cx,i=e.cy,s=e.rx,a=e.ry,o=e.xAxisRotation,u=o===void 0?0:o,d=e.largeArcFlag,l=d===void 0?0:d,p=e.sweepFlag,g=p===void 0?0:p,b=[];if(s===0||a===0)return[];var h=Math.sin(u*Oe/360),x=Math.cos(u*Oe/360),A=x*(t-n)/2+h*(r-i)/2,S=-h*(t-n)/2+x*(r-i)/2;if(A===0&&S===0)return[];s=Math.abs(s),a=Math.abs(a);var w=Math.pow(A,2)/Math.pow(s,2)+Math.pow(S,2)/Math.pow(a,2);w>1&&(s*=Math.sqrt(w),a*=Math.sqrt(w));var M=Ma(t,r,n,i,s,a,l,g,h,x,A,S),T=wa(M,4),F=T[0],k=T[1],O=T[2],P=T[3],R=Math.abs(P)/(Oe/4);Math.abs(1-R)<1e-7&&(R=1);var $=Math.max(Math.ceil(R),1);P/=$;for(var X=0;X<$;X++)b.push(Ca(O,P)),O+=P;return b.map(function(Y){var _=ht(Y[0],s,a,x,h,F,k),H=_.x,J=_.y,ee=ht(Y[1],s,a,x,h,F,k),ge=ee.x,E=ee.y,N=ht(Y[2],s,a,x,h,F,k),G=N.x,ue=N.y;return{x1:H,y1:J,x2:ge,y2:E,x:G,y:ue}})},Ia=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function vn(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ka=ja,vt={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},Ta=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function ja(e){var t=[];return e.replace(Ta,function(r,n,i){var s=n.toLowerCase();for(i=Pa(i),s=="m"&&i.length>2&&(t.push([n].concat(i.splice(0,2))),s="l",n=n=="m"?"l":"L");;){if(i.length==vt[s])return i.unshift(n),t.push(i);if(i.length<vt[s])throw new Error("malformed path data");t.push([n].concat(i.splice(0,vt[s])))}}),t}var Ea=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function Pa(e){var t=e.match(Ea);return t?t.map(Number):[]}const Oa=vn(ka);var La=Fa;function Fa(e){var t=0,r=0,n=0,i=0;return e.map(function(s){s=s.slice();var a=s[0],o=a.toUpperCase();if(a!=o)switch(s[0]=o,a){case"a":s[6]+=n,s[7]+=i;break;case"v":s[1]+=i;break;case"h":s[1]+=n;break;default:for(var u=1;u<s.length;)s[u++]+=n,s[u++]+=i}switch(o){case"Z":n=t,i=r;break;case"H":n=s[1];break;case"V":i=s[1];break;case"M":n=t=s[1],i=r=s[2];break;default:n=s[s.length-2],i=s[s.length-1]}return s})}const $a=vn(La);function Da(e){const t=Oa(e),r=$a(t);let n,i=0,s=0,a=0,o=0,u,d,l=0,p=0;const g=[];for(let b=0;b<r.length;b++){let h=r[b];const x=h[0];switch(x){case"M":i=h[1],s=h[2];break;case"H":h=["L",h[1],s];break;case"V":h=["L",i,h[1]];break;case"S":{let A=l,S=p;(n==="C"||n=="S")&&(A+=A-a,S+=S-o),h=["C",A,S,h[1],h[2],h[3],h[4]]}break;case"T":n==="Q"||n=="T"?(u=l*2-u,d=p*2-d):(u=l,d=p),h=["Q",u,d,h[1],h[2]];break;case"Q":u=h[1],d=h[2];break;case"A":{const A=Ra({px:l,py:p,cx:h[6],cy:h[7],rx:h[1],ry:h[2],xAxisRotation:h[3],largeArcFlag:h[4],sweepFlag:h[5]});if(!A.length)continue;for(const[S,w]of A.entries())h=["C",w.x1,w.y1,w.x2,w.y2,w.x,w.y],S<A.length-1&&g.push(h);h=h}break;case"Z":h=["L",i,s];break}n=x,l=h[h.length-2],p=h[h.length-1],["C","Q","A"].indexOf(x)>-1?(a=h[h.length-4],o=h[h.length-3]):(a=l,o=p),g.push(h)}return g}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
35
+ */function ma(t,e,r,n=1){return new cn(t,e,r).subdivide(n)}function xa(t,e,r,n,i=1){return new qt(new Float64Array([t.x,t.y,e.x,e.y,r.x,r.y,n.x,n.y])).subdivide(i)}function ba(t){return t.x*t.x+t.y*t.y}function Pe(t){return t/(1-.67+Math.pow(Math.pow(.67,4)+.25*t*t,.25))}function Ce(t){return t*(1-.39+Math.sqrt(.39*.39+.25*t*t))}class cn{constructor(e,r,n){We(this,"start"),We(this,"control"),We(this,"end"),this.start=e,this.control=r,this.end=n}eval(e){const r=1-e;return{x:this.start.x*r*r+2*this.control.x*r*e+this.end.x*e*e,y:this.start.y*r*r+2*this.control.y*r*e+this.end.y*e*e}}mapToBasic(){const{x:e,y:r}=this.start,{x:n,y:i}=this.control,{x:s,y:a}=this.end,o=2*n-e-s,u=2*i-r-a,d=(n-e)*o+(i-r)*u,l=(s-n)*o+(a-i)*u,p=(s-e)*u-(a-r)*o,m=d/p,A=l/p,h=Math.abs(p)/(Math.hypot(o,u)*Math.abs(A-m));return{x0:e,x2:s,scale:h,cross:p}}subdivide(e){const r=this.mapToBasic(),n=Pe(r.x0),i=Pe(r.x2),s=.5*Math.abs(i-n)*Math.sqrt(r.scale/e),a=Math.ceil(s),o=Ce(n),u=Ce(i),d=[0];for(let l=1;l<a;l++){const p=(Ce(n+(i-n)*l/a)-o)/(u-o);d.push(p)}return d.push(1),d.map(l=>this.eval(l))}}class qt{constructor(e){We(this,"c"),this.c=e}weightsum(e,r,n,i){const s=e*this.c[0]+r*this.c[2]+n*this.c[4]+i*this.c[6],a=e*this.c[1]+r*this.c[3]+n*this.c[5]+i*this.c[7];return{x:s,y:a}}eval(e){const r=1-e,n=r*r*r,i=3*r*r*e,s=3*r*e*e,a=e*e*e;return this.weightsum(n,i,s,a)}deriv(e){const r=1-e,n=-3*r*r,i=3*e*e,s=-6*e*r-n,a=6*e*r-i;return this.weightsum(n,s,a,i)}midpoint_quadbez(){const e=this.weightsum(-.25,.75,.75,-.25);return new cn({x:this.c[0],y:this.c[1]},e,{x:this.c[6],y:this.c[7]})}subsegment(e,r){const n=new Float64Array(8),i=this.eval(e),s=this.eval(r);n[0]=i.x,n[1]=i.y;const a=(r-e)/3,o=this.deriv(e);n[2]=i.x+a*o.x,n[3]=i.y+a*o.y;const u=this.deriv(r);return n[4]=s.x-a*u.x,n[5]=s.y-a*u.y,n[6]=s.x,n[7]=s.y,new qt(n)}subdivide(e){const r=.1*e,n=e-r,i=Math.sqrt(n),s=ba(this.weightsum(1,-3,3,-1)),a=Math.ceil(Math.pow(s/(432*r*r),1/6)),o=[];let u=0;for(let h=0;h<a;h++){const x=h/a,b=(h+1)/a,S=this.subsegment(x,b).midpoint_quadbez(),w=S.mapToBasic(),M=Pe(w.x0),T=Pe(w.x2),F=Math.sqrt(w.scale);let k=Math.abs(T-M)*F;if(Math.sign(w.x0)!=Math.sign(w.x2)){const O=i/F,E=i*Math.abs(T-M)/Pe(O);k=Math.max(k,E)}o.push({quad:S,a0:M,a2:T,val:k}),u+=k}const d=.5*u/i,l=Math.ceil(d),p=[{x:this.c[0],y:this.c[1]}];let m=0,A=0;for(let h=1;h<l;h++){const x=u*h/l;for(;m+o[A].val<x;)m+=o[A].val,A++;const b=o[A].a0,S=o[A].a2,w=Ce(b),M=Ce(S),T=b+(S-b)*(x-m)/o[A].val,F=(Ce(T)-w)/(M-w);p.push(o[A].quad.eval(F))}return p.push({x:this.c[6],y:this.c[7]}),p}}const Aa=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,Sa=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,sr=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function Ee(t,{domParser:e,svgPreprocessor:r,iiifRenderingHints:n}={}){if(Array.isArray(t))return K(t.reduce((i,s)=>{const{selector:a,selectors:o,iiifRenderingHints:u}=Ee(s,{domParser:e,svgPreprocessor:r,iiifRenderingHints:n});return a&&(i.selector||(i.selector=a),i.selectors.push(...o)),u&&(i.iiifRenderingHints=i.iiifRenderingHints||{type:"ImageApiSelector"},Object.assign(i.iiifRenderingHints,u)),i},{selector:null,selectors:[],iiifRenderingHints:n}));if(!t)return K({selector:null,selectors:[],iiifRenderingHints:n});if(typeof t=="string"){const[i,s]=t.split("#");return s?Ee({type:"FragmentSelector",value:s},{svgPreprocessor:r,iiifRenderingHints:n,domParser:e}):K({selector:null,selectors:[],iiifRenderingHints:n})}if(t.type&&t.type==="PointSelector"&&(t.t||t.t===0)){const i={type:"TemporalSelector",temporal:{startTime:t.t}};return K({selector:i,selectors:[i],iiifRenderingHints:n})}if(ln(t)){const i=[];if(t.region){const s=Ee({type:"FragmentSelector",value:"xywh="+t.region},{domParser:e,svgPreprocessor:r,iiifRenderingHints:n});i.push(...s.selectors)}return K({selector:i[0],selectors:i,iiifRenderingHints:n?{...n,...t}:t})}if(t.type==="FragmentSelector"){const i=Aa.exec(t.value);if(i){const a={type:"BoxSelector",spatial:{unit:i[2]==="percent:"||i[2]==="pct:"?"percent":"pixel",x:parseFloat(i[3]),y:parseFloat(i[4]),width:parseFloat(i[5]),height:parseFloat(i[6])}};return K({selector:a,selectors:[a],iiifRenderingHints:n})}const s=t.value.match(Sa);if(s){const a={type:"TemporalSelector",temporal:{startTime:s[4]?parseFloat(s[4]):0,endTime:s[7]?parseFloat(s[7]):void 0}};return K({selector:a,selectors:[a],iiifRenderingHints:n})}return K({selector:null,selectors:[],iiifRenderingHints:n})}if(t.type==="SvgSelector"&&"value"in t){e||(typeof window<"u"?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 i=[],s,a,o=(r==null?void 0:r(t.value))??t.value,u;if(e){const l=e.parseFromString(t.value,"image/svg+xml").querySelector("svg");if(!l)return console.warn(`Illegal SVG selector: ${t.value}`),K({selector:null,selectors:[],iiifRenderingHints:n});const p=un(l);p&&(i=p.points,u=p.shapeType,s=[Math.min(...i.map(m=>m[0])),Math.min(...i.map(m=>m[1])),Math.max(...i.map(m=>m[0])),Math.max(...i.map(m=>m[1]))],{style:a,svg:o}=Ma(p.element)??{svg:o})}const d={type:"SvgSelector",svg:o,svgShape:u,style:a,points:i.length?i:void 0,spatial:s?{unit:"pixel",x:s[0],y:s[1],width:s[2]-s[0],height:s[3]-s[1]}:void 0};return K({selector:d,selectors:[d],iiifRenderingHints:n})}return K({selector:null,selectors:[],iiifRenderingHints:n})}function wa(t){const e=t.map(n=>n[0]).reduce((n,i)=>(n[i]+=1,n),{C:0,Q:0,L:0,M:0}),r=new Set(t.map(n=>n[0]));if(e.C>0||e.Q>0)return"path";if(e.L>0&&(r.size===1||r.size===2&&r.has("M"))){if(e.L===4)return"rect";const n=t.slice(-1)[0];return t[0][0]==="M"&&n[0]==="L"&&n[1]==t[0][1]&&n[2]===t[0][2]||n[1]===0&&n[2]===0?"polygon":"polyline"}return"path"}function un(t){var e;for(const r of Array.from(t.children))switch(r==null?void 0:r.tagName.toLowerCase()){case"g":{const n=un(r);if(n)return n}continue;case"path":{const n=r.getAttribute("d");if(!n)continue;const i=ga(n);return{element:r,points:Ca(i),shapeType:wa(i)}}case"circle":{const n=parseFloat(r.getAttribute("cx")??"0"),i=parseFloat(r.getAttribute("cy")??"0"),s=parseFloat(r.getAttribute("r")??"0");if(!s)continue;const a=[];for(let o=0;o<=360;o+=12){const u=o*Math.PI/180;a.push([n+s*Math.cos(u),i+s*Math.sin(u)])}return{element:r,points:a,shapeType:"circle"}}case"ellipse":{const n=parseFloat(r.getAttribute("cx")??"0"),i=parseFloat(r.getAttribute("cy")??"0"),s=parseFloat(r.getAttribute("rx")??"0"),a=parseFloat(r.getAttribute("ry")??"0");if(!s&&!a)continue;const o=[];for(let u=0;u<=360;u+=12){const d=Math.tan(u/360*Math.PI),l=s*(1-d**2)/(1+d**2),p=a*2*d/(1+d**2);o.push([n+l,i+p])}return{element:r,points:o,shapeType:"ellipse"}}case"line":{const n=parseFloat(r.getAttribute("x0")??"0"),i=parseFloat(r.getAttribute("y0")??"0"),s=parseFloat(r.getAttribute("x1")??"0"),a=parseFloat(r.getAttribute("y1")??"0");if(n===s&&i===a)continue;return{element:r,points:[[n,i],[s,a]],shapeType:"polyline"}}case"polygon":case"polyline":{const n=((e=r.getAttribute("points"))==null?void 0:e.split(" ").map(s=>s.split(",").map(parseFloat)))??[];if(!n.length)continue;let i="polyline";return r.tagName.toLowerCase()==="polygon"&&(n.push(n[0]),i="polygon"),{element:r,points:n,shapeType:i}}case"rect":{const n=parseFloat(r.getAttribute("x")??"0"),i=parseFloat(r.getAttribute("y")??"0"),s=parseFloat(r.getAttribute("width")??"0"),a=parseFloat(r.getAttribute("height")??"0");if(!s||!a)continue;return{element:r,points:[[n,i],[n+s,i],[n+s,i+a],[n,i+a],[n,i]],shapeType:"rect"}}default:continue}return null}function Ca(t){const e=[];for(let r=0;r<t.length;r++){const n=e[e.length-1]??[0,0],i=t[r];switch(i[0]){case"M":case"L":e.push([i[1],i[2]]);continue;case"C":e.push(...xa({x:n[0],y:n[1]},{x:i[1],y:i[2]},{x:i[3],y:i[4]},{x:i[5],y:i[6]}).map(s=>[s.x,s.y]).slice(1));continue;case"Q":e.push(...ma({x:n[0],y:n[1]},{x:i[1],y:i[2]},{x:i[3],y:i[4]}).map(s=>[s.x,s.y]).slice(1));continue}}return e}function Ma(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 n=sr.exec(e.fill);n&&(e.fillOpacity=parseFloat(n[4]),e.fill=`rgb(${n[1]}, ${n[2]}, ${n[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 n=sr.exec(e.stroke);n&&(e.strokeOpacity=parseFloat(n[4]),e.stroke=`rgb(${n[1]}, ${n[2]}, ${n[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 r=t;for(;r.tagName.toLowerCase()!=="svg";)if(r=r.parentElement,r===null)throw new Error("Could not find root SVG element");return{svg:r.outerHTML,style:Object.keys(e).length>0?e:void 0}}function ln(t){return!!t&&t.type==="iiif:ImageApiSelector"&&t.type==="iiif:ImageApiSelector"}function K(t){if(t.iiifRenderingHints){const e=t.iiifRenderingHints;if(e.rotation){const r=fn(e.rotation);if(r)if(t.selectors.length)for(const n of t.selectors)n.rotation=r;else t.selectors.push({type:"RotationSelector",rotation:r})}}else delete t.iiifRenderingHints;return t}function fn(t){let e=parseFloat(t);return e&&t.startsWith("!")&&(e=360-e),e&&(e=e%360),e!==e?0:e||0}function de(t,e={}){if(Array.isArray(t))return de(t[0]);if(typeof t=="string"){const[r,n]=t.split("#");return n?de({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{id:r,type:e.typeMap&&e.typeMap[r]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return de(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:r,selectors:n}=t.selector?Ee(t.selector,e):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:r,selectors:n}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[r,n]=t.id.split("#");return n?de({type:"SpecificResource",source:{...t,id:r},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{...t,id:r},selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}function Vt(t={},e=[]){const{id:r,selector:n}=t,i=se(),s=V(),a=r||i.annotation,o=U(d=>a?d.iiif.entities.Annotation[a]:void 0,[a]),u=U(d=>o&&o.body?o.body.map(l=>l?l.type==="SpecificResource"?{...l,source:s.get(l)}:l?d.iiif.entities[l.type][l.id]:null:null).filter(Boolean):[],[o]);return y.useMemo(()=>{if(!o)return;const d={...o,body:u,target:de(o.target,{typeMap:s.getState().iiif.mapping})};return n?n(d):d},[o,n,u,...e])}const pn=({id:t,style:e,className:r,interactive:n})=>{const i=Vt({id:t}),s=Fe(i,"atlas"),a=Fe(i,"html"),o=$t(i,["atlas"]),u=re(),d=y.useMemo(()=>Re.mergeStyles(e,s),[e,s]);return u&&i&&i.target&&i.target.selector&&i.target.selector.type==="BoxSelector"&&i.target.source&&(i.target.source.id===u.id||i.target.source===u.id)?g.jsx(Re.RegionHighlight,{id:i.id,isEditing:!0,region:i.target.selector.spatial,style:d,className:(a==null?void 0:a.className)||r,interactive:!!(a!=null&&a.href||n),href:(a==null?void 0:a.href)||null,title:(a==null?void 0:a.title)||null,hrefTarget:(a==null?void 0:a.target)||null,onClick:()=>{},...o}):null};function dn(t={},e=[]){const{id:r,selector:n}=t,i=se(),s=r||i.annotationPage,a=U(o=>s?o.iiif.entities.AnnotationPage[s]:void 0,[s]);return y.useMemo(()=>{if(a)return n?n(a):a},[a,...e])}const Mt=({className:t,page:e})=>{var s;const r=dn({id:e.id})||e,n=Fe(r,"atlas"),i=Fe(r,"html");return U(a=>r.id?a.iiif.entities.AnnotationPage[r.id]:null,[]),g.jsx(y.Fragment,{children:(s=r.items)==null?void 0:s.map(a=>g.jsx(pn,{id:a.id,style:n,className:(i==null?void 0:i.className)||t},a.id))})};function hn({id:t,image:e,thumbnail:r,isStatic:n,x:i=0,y:s=0,children:a,selector:o,onClick:u,enableSizes:d}){var p,m;const l=y.useMemo(()=>{if(!(!o||o.spatial.x===0&&o.spatial.y===0))return o.spatial},[o]);return g.jsx("world-object",{x:i+e.target.spatial.x,y:s+e.target.spatial.y,width:e.target.spatial.width,height:e.target.spatial.height,onClick:u,children:e.service?g.jsxs(y.Fragment,{children:[g.jsx(Re.TileSet,{tiles:{id:e.service.id||e.service["@id"]||"unknown",height:e.height,width:e.width,imageService:e.service,thumbnail:r&&r.type==="fixed"?r:void 0},enableSizes:d,x:0,y:0,width:(p=e.target)==null?void 0:p.spatial.width,height:(m=e.target)==null?void 0:m.spatial.height,crop:l}),a]},"service"):g.jsxs(y.Fragment,{children:[g.jsx("world-image",{onClick:u,uri:e.id,target:{x:0,y:0,width:e.target.spatial.width,height:e.target.spatial.height},display:e.width&&e.height?{width:e.width,height:e.height}:void 0,crop:l}),a]},"no-service")},t+(e.service?"server":"no-service"))}var Ra=Object.defineProperty,Ia=(t,e,r)=>e in t?Ra(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Qe=(t,e,r)=>(Ia(t,typeof e!="symbol"?e+"":e,r),r),ka=function(){function t(e,r){var n=[],i=!0,s=!1,a=void 0;try{for(var o=e[Symbol.iterator](),u;!(i=(u=o.next()).done)&&(n.push(u.value),!(r&&n.length===r));i=!0);}catch(d){s=!0,a=d}finally{try{!i&&o.return&&o.return()}finally{if(s)throw a}}return n}return function(e,r){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),Oe=Math.PI*2,ht=function(t,e,r,n,i,s,a){var o=t.x,u=t.y;o*=e,u*=r;var d=n*o-i*u,l=i*o+n*u;return{x:d+s,y:l+a}},Ta=function(t,e){var r=e===1.5707963267948966?.551915024494:e===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(e/4),n=Math.cos(t),i=Math.sin(t),s=Math.cos(t+e),a=Math.sin(t+e);return[{x:n-i*r,y:i+n*r},{x:s+a*r,y:a-s*r},{x:s,y:a}]},ar=function(t,e,r,n){var i=t*n-e*r<0?-1:1,s=t*r+e*n;return s>1&&(s=1),s<-1&&(s=-1),i*Math.acos(s)},ja=function(t,e,r,n,i,s,a,o,u,d,l,p){var m=Math.pow(i,2),A=Math.pow(s,2),h=Math.pow(l,2),x=Math.pow(p,2),b=m*A-m*x-A*h;b<0&&(b=0),b/=m*x+A*h,b=Math.sqrt(b)*(a===o?-1:1);var S=b*i/s*p,w=b*-s/i*l,M=d*S-u*w+(t+r)/2,T=u*S+d*w+(e+n)/2,F=(l-S)/i,k=(p-w)/s,O=(-l-S)/i,E=(-p-w)/s,R=ar(1,0,F,k),$=ar(F,k,O,E);return o===0&&$>0&&($-=Oe),o===1&&$<0&&($+=Oe),[M,T,R,$]},Pa=function(t){var e=t.px,r=t.py,n=t.cx,i=t.cy,s=t.rx,a=t.ry,o=t.xAxisRotation,u=o===void 0?0:o,d=t.largeArcFlag,l=d===void 0?0:d,p=t.sweepFlag,m=p===void 0?0:p,A=[];if(s===0||a===0)return[];var h=Math.sin(u*Oe/360),x=Math.cos(u*Oe/360),b=x*(e-n)/2+h*(r-i)/2,S=-h*(e-n)/2+x*(r-i)/2;if(b===0&&S===0)return[];s=Math.abs(s),a=Math.abs(a);var w=Math.pow(b,2)/Math.pow(s,2)+Math.pow(S,2)/Math.pow(a,2);w>1&&(s*=Math.sqrt(w),a*=Math.sqrt(w));var M=ja(e,r,n,i,s,a,l,m,h,x,b,S),T=ka(M,4),F=T[0],k=T[1],O=T[2],E=T[3],R=Math.abs(E)/(Oe/4);Math.abs(1-R)<1e-7&&(R=1);var $=Math.max(Math.ceil(R),1);E/=$;for(var X=0;X<$;X++)A.push(Ta(O,E)),O+=E;return A.map(function(Y){var _=ht(Y[0],s,a,x,h,F,k),H=_.x,J=_.y,ee=ht(Y[1],s,a,x,h,F,k),ge=ee.x,P=ee.y,N=ht(Y[2],s,a,x,h,F,k),G=N.x,ue=N.y;return{x1:H,y1:J,x2:ge,y2:P,x:G,y:ue}})},Ea=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function yn(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Oa=Fa,yt={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},La=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function Fa(t){var e=[];return t.replace(La,function(r,n,i){var s=n.toLowerCase();for(i=Da(i),s=="m"&&i.length>2&&(e.push([n].concat(i.splice(0,2))),s="l",n=n=="m"?"l":"L");;){if(i.length==yt[s])return i.unshift(n),e.push(i);if(i.length<yt[s])throw new Error("malformed path data");e.push([n].concat(i.splice(0,yt[s])))}}),e}var $a=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function Da(t){var e=t.match($a);return e?e.map(Number):[]}const qa=yn(Oa);var Va=_a;function _a(t){var e=0,r=0,n=0,i=0;return t.map(function(s){s=s.slice();var a=s[0],o=a.toUpperCase();if(a!=o)switch(s[0]=o,a){case"a":s[6]+=n,s[7]+=i;break;case"v":s[1]+=i;break;case"h":s[1]+=n;break;default:for(var u=1;u<s.length;)s[u++]+=n,s[u++]+=i}switch(o){case"Z":n=e,i=r;break;case"H":n=s[1];break;case"V":i=s[1];break;case"M":n=e=s[1],i=r=s[2];break;default:n=s[s.length-2],i=s[s.length-1]}return s})}const Ua=yn(Va);function Ha(t){const e=qa(t),r=Ua(e);let n,i=0,s=0,a=0,o=0,u,d,l=0,p=0;const m=[];for(let A=0;A<r.length;A++){let h=r[A];const x=h[0];switch(x){case"M":i=h[1],s=h[2];break;case"H":h=["L",h[1],s];break;case"V":h=["L",i,h[1]];break;case"S":{let b=l,S=p;(n==="C"||n=="S")&&(b+=b-a,S+=S-o),h=["C",b,S,h[1],h[2],h[3],h[4]]}break;case"T":n==="Q"||n=="T"?(u=l*2-u,d=p*2-d):(u=l,d=p),h=["Q",u,d,h[1],h[2]];break;case"Q":u=h[1],d=h[2];break;case"A":{const b=Pa({px:l,py:p,cx:h[6],cy:h[7],rx:h[1],ry:h[2],xAxisRotation:h[3],largeArcFlag:h[4],sweepFlag:h[5]});if(!b.length)continue;for(const[S,w]of b.entries())h=["C",w.x1,w.y1,w.x2,w.y2,w.x,w.y],S<b.length-1&&m.push(h);h=h}break;case"Z":h=["L",i,s];break}n=x,l=h[h.length-2],p=h[h.length-1],["C","Q","A"].indexOf(x)>-1?(a=h[h.length-4],o=h[h.length-3]):(a=l,o=p),m.push(h)}return m}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
36
36
  *
37
37
  * All code in this module is based on JavaScript code by Raph Levien, published on his blog at
38
38
  * https://raphlinus.github.io/.
@@ -62,7 +62,7 @@
62
62
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
63
63
  * See the License for the specific language governing permissions and
64
64
  * limitations under the License.
65
- */function qa(e,t,r,n=1){return new yn(e,t,r).subdivide(n)}function Va(e,t,r,n,i=1){return new Vt(new Float64Array([e.x,e.y,t.x,t.y,r.x,r.y,n.x,n.y])).subdivide(i)}function _a(e){return e.x*e.x+e.y*e.y}function Le(e){return e/(1-.67+Math.pow(Math.pow(.67,4)+.25*e*e,.25))}function Me(e){return e*(1-.39+Math.sqrt(.39*.39+.25*e*e))}class yn{constructor(t,r,n){Qe(this,"start"),Qe(this,"control"),Qe(this,"end"),this.start=t,this.control=r,this.end=n}eval(t){const r=1-t;return{x:this.start.x*r*r+2*this.control.x*r*t+this.end.x*t*t,y:this.start.y*r*r+2*this.control.y*r*t+this.end.y*t*t}}mapToBasic(){const{x:t,y:r}=this.start,{x:n,y:i}=this.control,{x:s,y:a}=this.end,o=2*n-t-s,u=2*i-r-a,d=(n-t)*o+(i-r)*u,l=(s-n)*o+(a-i)*u,p=(s-t)*u-(a-r)*o,g=d/p,b=l/p,h=Math.abs(p)/(Math.hypot(o,u)*Math.abs(b-g));return{x0:t,x2:s,scale:h,cross:p}}subdivide(t){const r=this.mapToBasic(),n=Le(r.x0),i=Le(r.x2),s=.5*Math.abs(i-n)*Math.sqrt(r.scale/t),a=Math.ceil(s),o=Me(n),u=Me(i),d=[0];for(let l=1;l<a;l++){const p=(Me(n+(i-n)*l/a)-o)/(u-o);d.push(p)}return d.push(1),d.map(l=>this.eval(l))}}class Vt{constructor(t){Qe(this,"c"),this.c=t}weightsum(t,r,n,i){const s=t*this.c[0]+r*this.c[2]+n*this.c[4]+i*this.c[6],a=t*this.c[1]+r*this.c[3]+n*this.c[5]+i*this.c[7];return{x:s,y:a}}eval(t){const r=1-t,n=r*r*r,i=3*r*r*t,s=3*r*t*t,a=t*t*t;return this.weightsum(n,i,s,a)}deriv(t){const r=1-t,n=-3*r*r,i=3*t*t,s=-6*t*r-n,a=6*t*r-i;return this.weightsum(n,s,a,i)}midpoint_quadbez(){const t=this.weightsum(-.25,.75,.75,-.25);return new yn({x:this.c[0],y:this.c[1]},t,{x:this.c[6],y:this.c[7]})}subsegment(t,r){const n=new Float64Array(8),i=this.eval(t),s=this.eval(r);n[0]=i.x,n[1]=i.y;const a=(r-t)/3,o=this.deriv(t);n[2]=i.x+a*o.x,n[3]=i.y+a*o.y;const u=this.deriv(r);return n[4]=s.x-a*u.x,n[5]=s.y-a*u.y,n[6]=s.x,n[7]=s.y,new Vt(n)}subdivide(t){const r=.1*t,n=t-r,i=Math.sqrt(n),s=_a(this.weightsum(1,-3,3,-1)),a=Math.ceil(Math.pow(s/(432*r*r),1/6)),o=[];let u=0;for(let h=0;h<a;h++){const x=h/a,A=(h+1)/a,S=this.subsegment(x,A).midpoint_quadbez(),w=S.mapToBasic(),M=Le(w.x0),T=Le(w.x2),F=Math.sqrt(w.scale);let k=Math.abs(T-M)*F;if(Math.sign(w.x0)!=Math.sign(w.x2)){const O=i/F,P=i*Math.abs(T-M)/Le(O);k=Math.max(k,P)}o.push({quad:S,a0:M,a2:T,val:k}),u+=k}const d=.5*u/i,l=Math.ceil(d),p=[{x:this.c[0],y:this.c[1]}];let g=0,b=0;for(let h=1;h<l;h++){const x=u*h/l;for(;g+o[b].val<x;)g+=o[b].val,b++;const A=o[b].a0,S=o[b].a2,w=Me(A),M=Me(S),T=A+(S-A)*(x-g)/o[b].val,F=(Me(T)-w)/(M-w);p.push(o[b].quad.eval(F))}return p.push({x:this.c[6],y:this.c[7]}),p}}const Ua=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,Ha=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,ar=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function Ye(e,{domParser:t,svgPreprocessor:r,iiifRenderingHints:n}={}){if(Array.isArray(e))return Z(e.reduce((i,s)=>{const{selector:a,selectors:o,iiifRenderingHints:u}=Ye(s,{domParser:t,svgPreprocessor:r,iiifRenderingHints:n});return a&&(i.selector||(i.selector=a),i.selectors.push(...o)),u&&(i.iiifRenderingHints=i.iiifRenderingHints||{type:"ImageApiSelector"},Object.assign(i.iiifRenderingHints,u)),i},{selector:null,selectors:[],iiifRenderingHints:n}));if(!e)return Z({selector:null,selectors:[],iiifRenderingHints:n});if(typeof e=="string"){const[i,s]=e.split("#");return s?Ye({type:"FragmentSelector",value:s},{svgPreprocessor:r,iiifRenderingHints:n,domParser:t}):Z({selector:null,selectors:[],iiifRenderingHints:n})}if(e.type&&e.type==="PointSelector"&&(e.t||e.t===0)){const i={type:"TemporalSelector",temporal:{startTime:e.t}};return Z({selector:i,selectors:[i],iiifRenderingHints:n})}if(Wa(e)){const i=[];if(e.region){const s=Ye({type:"FragmentSelector",value:"xywh="+e.region},{domParser:t,svgPreprocessor:r,iiifRenderingHints:n});i.push(...s.selectors)}return Z({selector:i[0],selectors:i,iiifRenderingHints:n?{...n,...e}:e})}if(e.type==="FragmentSelector"){const i=Ua.exec(e.value);if(i){const a={type:"BoxSelector",spatial:{unit:i[2]==="percent:"||i[2]==="pct:"?"percent":"pixel",x:parseFloat(i[3]),y:parseFloat(i[4]),width:parseFloat(i[5]),height:parseFloat(i[6])}};return Z({selector:a,selectors:[a],iiifRenderingHints:n})}const s=e.value.match(Ha);if(s){const a={type:"TemporalSelector",temporal:{startTime:s[4]?parseFloat(s[4]):0,endTime:s[7]?parseFloat(s[7]):void 0}};return Z({selector:a,selectors:[a],iiifRenderingHints:n})}return Z({selector:null,selectors:[],iiifRenderingHints:n})}if(e.type==="SvgSelector"&&"value"in e){t||(typeof window<"u"?t=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 i=[],s,a,o=(r==null?void 0:r(e.value))??e.value,u;if(t){const l=t.parseFromString(e.value,"image/svg+xml").querySelector("svg");if(!l)return console.warn(`Illegal SVG selector: ${e.value}`),Z({selector:null,selectors:[],iiifRenderingHints:n});const p=gn(l);p&&(i=p.points,u=p.shapeType,s=[Math.min(...i.map(g=>g[0])),Math.min(...i.map(g=>g[1])),Math.max(...i.map(g=>g[0])),Math.max(...i.map(g=>g[1]))],{style:a,svg:o}=za(p.element)??{svg:o})}const d={type:"SvgSelector",svg:o,svgShape:u,style:a,points:i.length?i:void 0,spatial:s?{unit:"pixel",x:s[0],y:s[1],width:s[2]-s[0],height:s[3]-s[1]}:void 0};return Z({selector:d,selectors:[d],iiifRenderingHints:n})}return Z({selector:null,selectors:[],iiifRenderingHints:n})}function Na(e){const t=e.map(n=>n[0]).reduce((n,i)=>(n[i]+=1,n),{C:0,Q:0,L:0,M:0}),r=new Set(e.map(n=>n[0]));if(t.C>0||t.Q>0)return"path";if(t.L>0&&(r.size===1||r.size===2&&r.has("M"))){if(t.L===4)return"rect";const n=e.slice(-1)[0];return e[0][0]==="M"&&n[0]==="L"&&n[1]==e[0][1]&&n[2]===e[0][2]||n[1]===0&&n[2]===0?"polygon":"polyline"}return"path"}function gn(e){var t;for(const r of Array.from(e.children))switch(r==null?void 0:r.tagName.toLowerCase()){case"g":{const n=gn(r);if(n)return n}continue;case"path":{const n=r.getAttribute("d");if(!n)continue;const i=Da(n);return{element:r,points:Ba(i),shapeType:Na(i)}}case"circle":{const n=parseFloat(r.getAttribute("cx")??"0"),i=parseFloat(r.getAttribute("cy")??"0"),s=parseFloat(r.getAttribute("r")??"0");if(!s)continue;const a=[];for(let o=0;o<=360;o+=12){const u=o*Math.PI/180;a.push([n+s*Math.cos(u),i+s*Math.sin(u)])}return{element:r,points:a,shapeType:"circle"}}case"ellipse":{const n=parseFloat(r.getAttribute("cx")??"0"),i=parseFloat(r.getAttribute("cy")??"0"),s=parseFloat(r.getAttribute("rx")??"0"),a=parseFloat(r.getAttribute("ry")??"0");if(!s&&!a)continue;const o=[];for(let u=0;u<=360;u+=12){const d=Math.tan(u/360*Math.PI),l=s*(1-d**2)/(1+d**2),p=a*2*d/(1+d**2);o.push([n+l,i+p])}return{element:r,points:o,shapeType:"ellipse"}}case"line":{const n=parseFloat(r.getAttribute("x0")??"0"),i=parseFloat(r.getAttribute("y0")??"0"),s=parseFloat(r.getAttribute("x1")??"0"),a=parseFloat(r.getAttribute("y1")??"0");if(n===s&&i===a)continue;return{element:r,points:[[n,i],[s,a]],shapeType:"polyline"}}case"polygon":case"polyline":{const n=((t=r.getAttribute("points"))==null?void 0:t.split(" ").map(s=>s.split(",").map(parseFloat)))??[];if(!n.length)continue;let i="polyline";return r.tagName.toLowerCase()==="polygon"&&(n.push(n[0]),i="polygon"),{element:r,points:n,shapeType:i}}case"rect":{const n=parseFloat(r.getAttribute("x")??"0"),i=parseFloat(r.getAttribute("y")??"0"),s=parseFloat(r.getAttribute("width")??"0"),a=parseFloat(r.getAttribute("height")??"0");if(!s||!a)continue;return{element:r,points:[[n,i],[n+s,i],[n+s,i+a],[n,i+a],[n,i]],shapeType:"rect"}}default:continue}return null}function Ba(e){const t=[];for(let r=0;r<e.length;r++){const n=t[t.length-1]??[0,0],i=e[r];switch(i[0]){case"M":case"L":t.push([i[1],i[2]]);continue;case"C":t.push(...Va({x:n[0],y:n[1]},{x:i[1],y:i[2]},{x:i[3],y:i[4]},{x:i[5],y:i[6]}).map(s=>[s.x,s.y]).slice(1));continue;case"Q":t.push(...qa({x:n[0],y:n[1]},{x:i[1],y:i[2]},{x:i[3],y:i[4]}).map(s=>[s.x,s.y]).slice(1));continue}}return t}function za(e){const t={};if(e.hasAttribute("fill")?(t.fill=e.getAttribute("fill"),e.removeAttribute("fill")):e.style.fill&&(t.fill=e.style.fill),t.fill){const n=ar.exec(t.fill);n&&(t.fillOpacity=parseFloat(n[4]),t.fill=`rgb(${n[1]}, ${n[2]}, ${n[3]})`)}if(e.hasAttribute("fill-opacity")?(t.fillOpacity=parseFloat(e.getAttribute("fill-opacity")),e.removeAttribute("fill-opacity")):e.style.fillOpacity&&(t.fillOpacity=parseFloat(e.style.fillOpacity)),e.hasAttribute("stroke")?(t.stroke=e.getAttribute("stroke"),e.removeAttribute("stroke")):e.style.stroke&&(t.stroke=e.style.stroke),t.stroke){const n=ar.exec(t.stroke);n&&(t.strokeOpacity=parseFloat(n[4]),t.stroke=`rgb(${n[1]}, ${n[2]}, ${n[3]})`)}e.hasAttribute("stroke-opacity")?(t.strokeOpacity=parseFloat(e.getAttribute("stroke-opacity")),e.removeAttribute("stroke-opacity")):e.style.strokeOpacity&&(t.strokeOpacity=parseFloat(e.style.strokeOpacity)),e.hasAttribute("stroke-width")?(t.strokeWidth=e.getAttribute("stroke-width"),e.removeAttribute("stroke-width")):e.style.strokeWidth&&(t.strokeWidth=e.style.strokeWidth),e.hasAttribute("stroke-dasharray")?(t.strokeDasharray=e.getAttribute("stroke-dasharray"),e.removeAttribute("stroke-dasharray")):e.style.strokeDasharray&&(t.strokeDasharray=e.style.strokeDasharray);let r=e;for(;r.tagName.toLowerCase()!=="svg";)if(r=r.parentElement,r===null)throw new Error("Could not find root SVG element");return{svg:r.outerHTML,style:Object.keys(t).length>0?t:void 0}}function Wa(e){return!!e&&e.type==="iiif:ImageApiSelector"&&e.type==="iiif:ImageApiSelector"}function Z(e){if(e.iiifRenderingHints){const t=e.iiifRenderingHints;if(t.rotation){const r=Qa(t.rotation);if(r)if(e.selectors.length)for(const n of e.selectors)n.rotation=r;else e.selectors.push({type:"RotationSelector",rotation:r})}}else delete e.iiifRenderingHints;return e}function Qa(e){let t=parseFloat(e);return t&&e.startsWith("!")&&(t=360-t),t&&(t=t%360),t!==t?0:t||0}function Te(e,t={}){if(Array.isArray(e))return Te(e[0]);if(typeof e=="string"){const[r,n]=e.split("#");return n?Te({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{id:r,type:t.typeMap&&t.typeMap[r]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return Te(e.items[0]);if(e.type==="SpecificResource"){e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]);const{selector:r,selectors:n}=e.selector?Ye(e.selector,t):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:r,selectors:n}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[r,n]=e.id.split("#");return n?Te({type:"SpecificResource",source:{...e,id:r},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{...e,id:r},selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}var Ya=Object.defineProperty,Ga=(e,t,r)=>t in e?Ya(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,or=(e,t,r)=>(Ga(e,typeof t!="symbol"?t+"":t,r),r);function Ja(e){return Array.isArray(e)?e:e?[e]:[]}const cr=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function Ka(e){if(typeof e>"u"||e===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(e))throw new Error("Array is not a valid entity");if(typeof e!="object")throw new Error(`${typeof e} is not a valid entity`);if(typeof e["@type"]=="string"){const t=cr.indexOf(e["@type"]);if(t!==-1)return cr[t]}if(e.profile)return"Service";if(e.format||e["@type"])return"ContentResource";throw new Error("Resource type is not known")}class _t{constructor(t,r={}){or(this,"traversals"),or(this,"options"),this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...t},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...r}}static all(t){return new _t({collection:[t],manifest:[t],canvas:[t],annotationList:[t],sequence:[t],annotation:[t],contentResource:[t],choice:[t],range:[t],service:[t],layer:[t]})}traverseCollection(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(t))),this.traversals.collection)}traverseCollectionItems(t){if(this.options.mergeMemberProperties){const r=[...(t.manifests||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n),...(t.collections||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n),...t.members||[]];delete t.collections,delete t.manifests,t.members=r}return t.manifests&&(t.manifests=t.manifests.map(r=>this.traverseManifest(typeof r=="string"?{"@id":r,"@type":"sc:Manifest"}:r))),t.collections&&(t.collections=t.collections.map(r=>this.traverseCollection(typeof r=="string"?{"@id":r,"@type":"sc:Collection"}:r))),t.members&&(t.members=t.members.map(r=>typeof r=="string"?r:this.traverseUnknown(r))),t}traverseManifest(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(t))),this.traversals.manifest)}traverseManifestItems(t){return t.sequences&&(t.sequences=t.sequences.map(r=>this.traverseSequence(r))),t.structures&&(t.structures=t.structures.map(r=>this.traverseRange(r))),t}traverseSequence(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(t))),this.traversals.sequence)}traverseSequenceItems(t){return t.canvases&&(t.canvases=t.canvases.map(r=>this.traverseCanvas(r))),t}traverseCanvas(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(t))),this.traversals.canvas)}traverseCanvasItems(t){return t.images&&(t.images=t.images.map(r=>this.traverseAnnotation(r))),t.otherContent&&(t.otherContent=t.otherContent.map(r=>this.traverseAnnotationList(r))),t}traverseRange(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(t))),this.traversals.range)}traverseRangeItems(t){if(this.options.mergeMemberProperties){const r=[...(t.ranges||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Range"}:n),...(t.canvases||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Canvas"}:n),...t.members||[]];delete t.ranges,delete t.canvases,t.members=r.length?r.map(n=>this.traverseUnknown(n)):void 0}return t}traverseAnnotationList(t){const r=typeof t=="string"?{"@id":t,"@type":"sc:AnnotationList"}:t;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(r)),this.traversals.annotationList)}traverseAnnotationListItems(t){return t.resources&&(t.resources=t.resources.map(r=>this.traverseAnnotation(r))),t}traverseAnnotation(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(t))),this.traversals.annotation)}traverseAnnotationItems(t){return t.resource&&(Array.isArray(t.resource)?t.resource=t.resource.map(r=>this.traverseContentResource(r)):t.resource=this.traverseContentResource(t.resource)),t.on,t}traverseLayer(t){return this.traverseType(this.traverseLinking(this.traverseLayerItems(t)),this.traversals.layer)}traverseLayerItems(t){return t.otherContent&&(t.otherContent=t.otherContent.map(r=>this.traverseAnnotationList(r))),t}traverseChoice(t){return this.traverseType(this.traverseChoiceItems(t),this.traversals.choice)}traverseChoiceItems(t){return t.default&&t.default!=="rdf:nil"&&(t.default=this.traverseContentResource(t.default)),t.item&&t.item!=="rdf:nil"&&(t.item=t.item.map(r=>this.traverseContentResource(r))),t}traverseService(t){return this.traverseType(this.traverseLinking(t),this.traversals.service)}traverseContentResource(t){return t["@type"]==="oa:Choice"?this.traverseChoice(t):this.traverseType(this.traverseDescriptive(this.traverseLinking(t)),this.traversals.contentResource)}traverseUnknown(t){if(!t["@type"]||typeof t=="string")return t;switch(Ka(t)){case"sc:Collection":return this.traverseCollection(t);case"sc:Manifest":return this.traverseManifest(t);case"sc:Canvas":return this.traverseCanvas(t);case"sc:Sequence":return this.traverseSequence(t);case"sc:Range":return this.traverseRange(t);case"oa:Annotation":return this.traverseAnnotation(t);case"sc:AnnotationList":return this.traverseAnnotationList(t);case"sc:Layer":return this.traverseLayer(t);case"Service":return this.traverseService(t);case"oa:Choice":return this.traverseChoice(t);case"ContentResource":return this.traverseContentResource(t)}return t.profile?this.traverseService(t):t}traverseImageResource(t){const r=Array.isArray(t),n=Array.isArray(t)?t:[t],i=[];for(const s of n)typeof s=="string"?i.push(this.traverseContentResource({"@id":s,"@type":"dctypes:Image"})):i.push(this.traverseContentResource(s));return!r&&!this.options.convertPropsToArray?i[0]:i}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=this.traverseImageResource(t.thumbnail)),t.logo&&(t.logo=this.traverseImageResource(t.logo)),t}traverseOneOrMoreServices(t){const r=Array.isArray(t),n=Array.isArray(t)?t:[t],i=[];for(const s of n)i.push(this.traverseService(s));return!r&&!this.options.convertPropsToArray?i[0]:i}traverseLinking(t){return t.related&&(t.related=this.traverseOneOrManyType(t.related,this.traversals.contentResource)),t.rendering&&(t.rendering=this.traverseOneOrManyType(t.rendering,this.traversals.contentResource)),t.service&&(t.service=this.traverseOneOrMoreServices(t.service)),t.seeAlso&&(t.seeAlso=this.traverseOneOrManyType(t.seeAlso,this.traversals.contentResource)),t.within&&(typeof t.within=="string"||(t.within=this.traverseOneOrManyType(t.within,this.traversals.contentResource))),t.startCanvas&&(typeof t.startCanvas=="string"?t.startCanvas=this.traverseType({"@id":t.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):t.startCanvas&&this.traverseType(t.startCanvas,this.traversals.canvas)),t.contentLayer&&(typeof t.contentLayer=="string"?t.contentLayer=this.traverseLayer({"@id":t.contentLayer,"@type":"sc:Layer"}):t.contentLayer=this.traverseLayer(t.contentLayer)),t}traverseOneOrManyType(t,r){if(!Array.isArray(t))if(this.options.convertPropsToArray)t=[t];else return this.traverseType(t,r);return t.map(n=>this.traverseType(n,r))}traverseType(t,r){return r.reduce((n,i)=>{const s=i(n);return typeof s>"u"&&!this.options.allowUndefinedReturn?n:s},t)}}const Za="http://library.stanford.edu/iiif/image-api/compliance.html#level0",mn="http://library.stanford.edu/iiif/image-api/compliance.html#level1",xn="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Xa="http://library.stanford.edu/iiif/image-api/conformance.html#level0",bn="http://library.stanford.edu/iiif/image-api/conformance.html#level1",An="http://library.stanford.edu/iiif/image-api/conformance.html#level2",eo="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Sn="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",wn="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",to="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Cn="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Mn="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",ro="http://iiif.io/api/image/1/level0.json",no="http://iiif.io/api/image/1/profiles/level0.json",Rn="http://iiif.io/api/image/1/level1.json",In="http://iiif.io/api/image/1/profiles/level1.json",kn="http://iiif.io/api/image/1/level2.json",Tn="http://iiif.io/api/image/1/profiles/level2.json",io="http://iiif.io/api/image/2/level0.json",so="http://iiif.io/api/image/2/profiles/level0.json",jn="http://iiif.io/api/image/2/level1.json",En="http://iiif.io/api/image/2/profiles/level1.json",Pn="http://iiif.io/api/image/2/level2.json",On="http://iiif.io/api/image/2/profiles/level2.json",ao="level0",Ln="level1",Fn="level2",oo="http://iiif.io/api/image/2/level0",$n="http://iiif.io/api/image/2/level1",Dn="http://iiif.io/api/image/2/level2",co=[$n,Dn,mn,xn,bn,An,Sn,wn,Cn,Mn,Rn,In,kn,Tn,jn,En,Pn,On,Ln,Fn],uo=[oo,$n,Dn,Za,mn,xn,Xa,bn,An,eo,Sn,wn,to,Cn,Mn,ro,no,Rn,In,kn,Tn,io,so,jn,En,Pn,On,ao,Ln,Fn];function ae(e){for(const t in e)(typeof e[t]>"u"||e[t]===null)&&delete e[t];return e}const Mt={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function Ae(e,t="none"){if(!e)return{};const r=Array.isArray(e)?e:[e],n={};for(const i of r){if(typeof i=="string"){n[t]=n[t]?n[t]:[],n[t].push(i||"");continue}if(!i["@language"]){n[t]=n[t]?n[t]:[],n[t].push(i["@value"]||"");continue}const s=i["@language"];n[s]=n[s]?n[s]:[],n[s].push(i["@value"]||"")}return n}function qn(e){if(Array.isArray(e))return qn(e.find(t=>typeof t=="string"));if(uo.indexOf(e)!==-1)return"level2";if(co.indexOf(e)!==-1)return"level1";if(typeof e=="string")return e}function lo(e){const t=Array.isArray(e)?e:[e];for(const r of t)switch(r){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function fo(e){switch(e){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}function ur(e){for(const t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}const po=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function Ut(e){const t=e["@id"]||e.id;let r=e["@type"]||e.type;const n=e.profile||void 0,i=e["@context"]||void 0;if(n){const s=fo(n);if(s)return s}if(i){const s=lo(i);if(s)return s}if(r){if(Array.isArray(r)){if(r.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(r.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";r=r[0]}for(const s of["sc","oa","dcterms","dctypes","iiif"])if(r.startsWith(`${s}:`)){r=r.slice(s.length+1);break}switch(r){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(r&&po.indexOf(r)!==-1)return r;if(e.format){if(e.format.startsWith("image/"))return"Image";if(e.format.startsWith("text/")||e.format==="application/pdf")return"Text";if(e.format.startsWith("application/"))return"Dataset"}return t&&(t.endsWith(".jpg")||t.endsWith(".png")||t.endsWith(".jpeg"))?"Image":r||"unknown"}const ho=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function vo(e){const t=e.match(ho);return t?t[0]:e}function yo(e,t="Rights/License",r="none"){let n=null;const i=[],s=Array.isArray(e)?e:[e];for(const a of s){const o=a?vo(a):void 0;if(o&&(o.indexOf("creativecommons.org")!==-1||o.indexOf("rightsstatements.org")!==-1)){o.startsWith("https://")?n=`http://${o.slice(8)}`:n=o;continue}o&&i.push({label:{[r]:[t]},value:{[r]:[o]}})}return[n,i]}const go=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function mo(e){if(e){const t=Array.isArray(e)?e:[e],r=[];for(const n of t)n==="http://iiif.io/api/presentation/2/context.json"&&r.push("http://iiif.io/api/presentation/3/context.json"),go.indexOf(n)===-1&&r.push(n);if(t.length)return r.length===1?r[0]:r}}function xo(e){return e?e.map(t=>({label:Ae(t.label),value:Ae(t.value)})):[]}let lr=0;function Vn(e,t){const r=encodeURI(e.id||e["@id"]||"").trim();return r&&t?`${r}/${t}`:r||(lr++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${lr}`)}function oe(e){const t=[...e.behavior||[]];e.viewingHint&&t.push(e.viewingHint);let r;return Array.isArray(e.motivation)?r=e.motivation.map(ur):e.motivation&&(r=ur(e.motivation)),{"@context":e["@context"]?mo(e["@context"]):void 0,id:(e["@id"]||Vn(e)).trim(),type:Ut(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:r,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function ce(e){const[t,r]=yo(e.license),n=[...e.metadata?xo(e.metadata):[],...r];return{rights:t,metadata:n.length?n:void 0,label:e.label?Ae(e.label):void 0,requiredStatement:e.attribution?{label:Ae(Mt.attributionLabel),value:Ae(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?Ae(e.description):void 0,thumbnail:bo(e.thumbnail)}}function bo(e){return e&&(Array.isArray(e)?e:[e]).map(t=>typeof t=="string"?{id:t,type:"Image"}:(t.type==="unknown"&&(t.type="Image"),t))}function Ao(e){if(!e.within)return;const t=Array.isArray(e.within)?e.within:[e.within],r=[];for(const n of t)if(typeof n=="string"){if(n)switch(e["@type"]){case"sc:Manifest":r.push({id:n,type:"Collection"});break}}else n["@id"]&&r.push({id:n["@id"],type:Ut(n)});return r.length?r:void 0}function ye(e){const t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],r=e.contentLayer;return{provider:e.logo||t.length?[{id:Mt.providerId,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:Ae(Mt.providerName)}]:void 0,partOf:Ao(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?Ja(e.service):void 0,supplementary:r?[r]:void 0}}function So(e){return{chars:e.chars,format:e.format?e.format:void 0,language:e.language}}function wo(e){return ae({...oe(e),...ce(e),...ye(e),items:e.members})}function Co(e){const t=[],r=[];let n;for(const s of e.sequences||[])s.canvases.length&&t.push(...s.canvases),s.behavior&&r.push(...s.behavior),s.startCanvas&&(n=s.startCanvas);const i=oe(e);return r.length&&(i.behavior?i.behavior.push(...r):i.behavior=r),ae({...i,...ce(e),...ye(e),start:n,items:t,structures:e.structures})}function Mo(e){return ae({...oe(e),...ce(e),...ye(e),annotations:e.otherContent&&e.otherContent.length?e.otherContent:void 0,items:e.images&&e.images.length?[{id:Vn(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}function Ro(e){return ae({...oe(e),...ce(e),...ye(e),items:e.resources&&e.resources.length?e.resources:void 0})}function Io(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}}function ko(e){function t(r){if(Array.isArray(r)){if(r.length>1)return{type:"List",items:r.map(t)};r=r[0]}if(typeof r=="string")return encodeURI(r).trim();if("@type"in r){let n;if(typeof r.full=="string")n=r.full;else if(r.full["@type"]==="dctypes:Image")n={id:r.full["@id"],type:"Image"};else if(r.full["@type"]==="sc:Canvas")n={id:r.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${r.full["@type"]}`);return{type:"SpecificResource",source:n,selector:It(r.selector)}}else return encodeURI(r["@id"]).trim()}return ae({...oe(e),...ce(e),...ye(e),target:t(e.on),body:Array.isArray(e.resource)?e.resource.map(Rt):Rt(e.resource)})}function Rt(e){const t=e;return ae({...oe(t),...ce(t),...ye(t),...So(t)})}function To(e){const t=[];return e.default&&e.default!=="rdf:nil"&&t.push(e.default),e.item&&e.item!=="rdf:nil"&&t.push(...e.item),{...oe(e),...ce(e),items:t}}function jo(e){return ae({...oe(e),...ce(e),...ye(e),items:e.members})}function Eo(e){const{"@id":t,"@type":r,"@context":n,profile:i,...s}=e,a={};return t&&(a["@id"]=t),a["@type"]=Ut(e),a["@type"]==="unknown"&&(n&&n.length&&(a["@context"]=n),a["@type"]="Service"),i&&(a.profile=qn(i)),ae({...a,...s})}function Po(e){return ae({...oe(e),...ce(e),...ye(e)})}new _t({collection:[wo],manifest:[Co],canvas:[Mo],annotationList:[Ro],sequence:[Io],annotation:[ko],contentResource:[Rt],choice:[To],range:[jo],service:[Eo],layer:[Po]});function It(e){if((Array.isArray(e["@type"])&&e["@type"].includes("oa:SvgSelector")||e["@type"]=="oa:SvgSelector")&&("chars"in e||"value"in e))return{type:"SvgSelector",value:"chars"in e?e.chars:e.value};if(e["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:e.value};if(e["@type"]==="oa:Choice")return[It(e.default),...(Array.isArray(e.item)?e.item:[e.item]).map(It)];if(e["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in e?e.region:void 0,rotation:"rotation"in e?e.rotation:void 0};throw new Error(`Unsupported selector type: ${e["@type"]}`)}var fr={exports:{}};(function(e,t){var r=Object.defineProperty,n=(s,a,o)=>a in s?r(s,a,{enumerable:!0,configurable:!0,writable:!0,value:o}):s[a]=o,i=(s,a,o)=>(n(s,typeof a!="symbol"?a+"":a,o),o);(function(s,a){a(t)})(Ia,function(s){const a="http://library.stanford.edu/iiif/image-api/compliance.html#level1",o="http://library.stanford.edu/iiif/image-api/compliance.html#level2",u="http://library.stanford.edu/iiif/image-api/conformance.html#level1",d="http://library.stanford.edu/iiif/image-api/conformance.html#level2",l="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",p="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",g="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",b="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",h="http://iiif.io/api/image/1/level1.json",x="http://iiif.io/api/image/1/profiles/level1.json",A="http://iiif.io/api/image/1/level2.json",S="http://iiif.io/api/image/1/profiles/level2.json",w="http://iiif.io/api/image/2/level1.json",M="http://iiif.io/api/image/2/profiles/level1.json",T="http://iiif.io/api/image/2/level2.json",F="http://iiif.io/api/image/2/profiles/level2.json",k="level1",O="level2",P="http://iiif.io/api/image/2/level1",R="http://iiif.io/api/image/2/level2",$=[P,R,a,o,u,d,l,p,g,b,h,x,A,S,w,M,T,F,k,O],X=["http://iiif.io/api/image/2/level0",P,R,"http://library.stanford.edu/iiif/image-api/compliance.html#level0",a,o,"http://library.stanford.edu/iiif/image-api/conformance.html#level0",u,d,"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",l,p,"http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",g,b,"http://iiif.io/api/image/1/level0.json","http://iiif.io/api/image/1/profiles/level0.json",h,x,A,S,"http://iiif.io/api/image/2/level0.json","http://iiif.io/api/image/2/profiles/level0.json",w,M,T,F,"level0",k,O],Y=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];class _{constructor(c,y={}){i(this,"traversals"),i(this,"options"),this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...c},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...y}}static all(c){return new _({collection:[c],manifest:[c],canvas:[c],annotationList:[c],sequence:[c],annotation:[c],contentResource:[c],choice:[c],range:[c],service:[c],layer:[c]})}traverseCollection(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(c))),this.traversals.collection)}traverseCollectionItems(c){if(this.options.mergeMemberProperties){const y=[...(c.manifests||[]).map(C=>typeof C=="string"?{"@id":C,"@type":"sc:Manifest"}:C),...(c.collections||[]).map(C=>typeof C=="string"?{"@id":C,"@type":"sc:Collection"}:C),...c.members||[]];delete c.collections,delete c.manifests,c.members=y}return c.manifests&&(c.manifests=c.manifests.map(y=>this.traverseManifest(typeof y=="string"?{"@id":y,"@type":"sc:Manifest"}:y))),c.collections&&(c.collections=c.collections.map(y=>this.traverseCollection(typeof y=="string"?{"@id":y,"@type":"sc:Collection"}:y))),c.members&&(c.members=c.members.map(y=>typeof y=="string"?y:this.traverseUnknown(y))),c}traverseManifest(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(c))),this.traversals.manifest)}traverseManifestItems(c){return c.sequences&&(c.sequences=c.sequences.map(y=>this.traverseSequence(y))),c.structures&&(c.structures=c.structures.map(y=>this.traverseRange(y))),c}traverseSequence(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(c))),this.traversals.sequence)}traverseSequenceItems(c){return c.canvases&&(c.canvases=c.canvases.map(y=>this.traverseCanvas(y))),c}traverseCanvas(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(c))),this.traversals.canvas)}traverseCanvasItems(c){return c.images&&(c.images=c.images.map(y=>this.traverseAnnotation(y))),c.otherContent&&(c.otherContent=c.otherContent.map(y=>this.traverseAnnotationList(y))),c}traverseRange(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(c))),this.traversals.range)}traverseRangeItems(c){if(this.options.mergeMemberProperties){const y=[...(c.ranges||[]).map(C=>typeof C=="string"?{"@id":C,"@type":"sc:Range"}:C),...(c.canvases||[]).map(C=>typeof C=="string"?{"@id":C,"@type":"sc:Canvas"}:C),...c.members||[]];delete c.ranges,delete c.canvases,c.members=y.length?y.map(C=>this.traverseUnknown(C)):void 0}return c}traverseAnnotationList(c){const y=typeof c=="string"?{"@id":c,"@type":"sc:AnnotationList"}:c;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(y)),this.traversals.annotationList)}traverseAnnotationListItems(c){return c.resources&&(c.resources=c.resources.map(y=>this.traverseAnnotation(y))),c}traverseAnnotation(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(c))),this.traversals.annotation)}traverseAnnotationItems(c){return c.resource&&(Array.isArray(c.resource)?c.resource=c.resource.map(y=>this.traverseContentResource(y)):c.resource=this.traverseContentResource(c.resource)),c.on,c}traverseLayer(c){return this.traverseType(this.traverseLinking(this.traverseLayerItems(c)),this.traversals.layer)}traverseLayerItems(c){return c.otherContent&&(c.otherContent=c.otherContent.map(y=>this.traverseAnnotationList(y))),c}traverseChoice(c){return this.traverseType(this.traverseChoiceItems(c),this.traversals.choice)}traverseChoiceItems(c){return c.default&&c.default!=="rdf:nil"&&(c.default=this.traverseContentResource(c.default)),c.item&&c.item!=="rdf:nil"&&(c.item=c.item.map(y=>this.traverseContentResource(y))),c}traverseService(c){return this.traverseType(this.traverseLinking(c),this.traversals.service)}traverseContentResource(c){return c["@type"]==="oa:Choice"?this.traverseChoice(c):this.traverseType(this.traverseDescriptive(this.traverseLinking(c)),this.traversals.contentResource)}traverseUnknown(c){if(!c["@type"]||typeof c=="string")return c;switch(function(y){if(y==null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(y))throw new Error("Array is not a valid entity");if(typeof y!="object")throw new Error(typeof y+" is not a valid entity");if(typeof y["@type"]=="string"){const C=Y.indexOf(y["@type"]);if(C!==-1)return Y[C]}if(y.profile)return"Service";if(y.format||y["@type"])return"ContentResource";throw new Error("Resource type is not known")}(c)){case"sc:Collection":return this.traverseCollection(c);case"sc:Manifest":return this.traverseManifest(c);case"sc:Canvas":return this.traverseCanvas(c);case"sc:Sequence":return this.traverseSequence(c);case"sc:Range":return this.traverseRange(c);case"oa:Annotation":return this.traverseAnnotation(c);case"sc:AnnotationList":return this.traverseAnnotationList(c);case"sc:Layer":return this.traverseLayer(c);case"Service":return this.traverseService(c);case"oa:Choice":return this.traverseChoice(c);case"ContentResource":return this.traverseContentResource(c)}return c.profile?this.traverseService(c):c}traverseImageResource(c){const y=Array.isArray(c),C=Array.isArray(c)?c:[c],L=[];for(const j of C)typeof j=="string"?L.push(this.traverseContentResource({"@id":j,"@type":"dctypes:Image"})):L.push(this.traverseContentResource(j));return y||this.options.convertPropsToArray?L:L[0]}traverseDescriptive(c){return c.thumbnail&&(c.thumbnail=this.traverseImageResource(c.thumbnail)),c.logo&&(c.logo=this.traverseImageResource(c.logo)),c}traverseOneOrMoreServices(c){const y=Array.isArray(c),C=Array.isArray(c)?c:[c],L=[];for(const j of C)L.push(this.traverseService(j));return y||this.options.convertPropsToArray?L:L[0]}traverseLinking(c){return c.related&&(c.related=this.traverseOneOrManyType(c.related,this.traversals.contentResource)),c.rendering&&(c.rendering=this.traverseOneOrManyType(c.rendering,this.traversals.contentResource)),c.service&&(c.service=this.traverseOneOrMoreServices(c.service)),c.seeAlso&&(c.seeAlso=this.traverseOneOrManyType(c.seeAlso,this.traversals.contentResource)),c.within&&(typeof c.within=="string"||(c.within=this.traverseOneOrManyType(c.within,this.traversals.contentResource))),c.startCanvas&&(typeof c.startCanvas=="string"?c.startCanvas=this.traverseType({"@id":c.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):c.startCanvas&&this.traverseType(c.startCanvas,this.traversals.canvas)),c.contentLayer&&(typeof c.contentLayer=="string"?c.contentLayer=this.traverseLayer({"@id":c.contentLayer,"@type":"sc:Layer"}):c.contentLayer=this.traverseLayer(c.contentLayer)),c}traverseOneOrManyType(c,y){if(!Array.isArray(c)){if(!this.options.convertPropsToArray)return this.traverseType(c,y);c=[c]}return c.map(C=>this.traverseType(C,y))}traverseType(c,y){return y.reduce((C,L)=>{const j=L(C);return j!==void 0||this.options.allowUndefinedReturn?j:C},c)}}function H(f){for(const c in f)f[c]!==void 0&&f[c]!==null||delete f[c];return f}const J="Attribution",ee="http://example.org/provider",ge="Unknown";function E(f,c="none"){if(!f)return{};const y=Array.isArray(f)?f:[f],C={};for(const L of y){if(typeof L=="string"){C[c]=C[c]?C[c]:[],C[c].push(L||"");continue}if(!L["@language"]){C[c]=C[c]?C[c]:[],C[c].push(L["@value"]||"");continue}const j=L["@language"];C[j]=C[j]?C[j]:[],C[j].push(L["@value"]||"")}return C}function N(f){return Array.isArray(f)?N(f.find(c=>typeof c=="string")):X.indexOf(f)!==-1?"level2":$.indexOf(f)!==-1?"level1":typeof f=="string"?f:void 0}function G(f){for(const c of["sc","oa","dcterms","dctypes","iiif"])if(f.startsWith(`${c}:`))return f.slice(c.length+1);return f}const ue=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function nt(f){const c=f["@id"]||f.id;let y=f["@type"]||f.type;const C=f.profile||void 0,L=f["@context"]||void 0;if(C){const j=function(B){switch(B){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}(C);if(j)return j}if(L){const j=function(B){const Ve=Array.isArray(B)?B:[B];for(const _e of Ve)switch(_e){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}(L);if(j)return j}if(y){if(Array.isArray(y)){if(y.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(y.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";y=y[0]}for(const j of["sc","oa","dcterms","dctypes","iiif"])if(y.startsWith(`${j}:`)){y=y.slice(j.length+1);break}switch(y){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(y&&ue.indexOf(y)!==-1)return y;if(f.format){if(f.format.startsWith("image/"))return"Image";if(f.format.startsWith("text/")||f.format==="application/pdf")return"Text";if(f.format.startsWith("application/"))return"Dataset"}return c&&(c.endsWith(".jpg")||c.endsWith(".png")||c.endsWith(".jpeg"))?"Image":y||"unknown"}const Ai=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Si(f){const c=f.match(Ai);return c?c[0]:f}const wi=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function Ci(f){if(f){const c=Array.isArray(f)?f:[f],y=[];for(const C of c)C==="http://iiif.io/api/presentation/2/context.json"&&y.push("http://iiif.io/api/presentation/3/context.json"),wi.indexOf(C)===-1&&y.push(C);if(c.length)return y.length===1?y[0]:y}}let Bt=0;function zt(f,c){const y=encodeURI(f.id||f["@id"]||"").trim();return y&&c?`${y}/${c}`:y||(Bt++,`http://example.org/${f["@type"]}${c?`/${c}`:""}/${Bt}`)}function ne(f){const c=[...f.behavior||[]];let y;return f.viewingHint&&c.push(f.viewingHint),Array.isArray(f.motivation)?y=f.motivation.map(G):f.motivation&&(y=G(f.motivation)),{"@context":f["@context"]?Ci(f["@context"]):void 0,id:(f["@id"]||zt(f)).trim(),type:nt(f),behavior:c.length?c:void 0,height:f.height?f.height:void 0,width:f.width?f.width:void 0,motivation:y,viewingDirection:f.viewingDirection,profile:f.profile,format:f.format?f.format:void 0,duration:void 0,timeMode:void 0}}function ie(f){const[c,y]=function(j,B="Rights/License",Ve="none"){let _e=null;const Wt=[],Ti=Array.isArray(j)?j:[j];for(const Qt of Ti){const fe=Qt?Si(Qt):void 0;!fe||fe.indexOf("creativecommons.org")===-1&&fe.indexOf("rightsstatements.org")===-1?fe&&Wt.push({label:{[Ve]:[B]},value:{[Ve]:[fe]}}):_e=fe.startsWith("https://")?`http://${fe.slice(8)}`:fe}return[_e,Wt]}(f.license),C=[...f.metadata?(L=f.metadata,L?L.map(j=>({label:E(j.label),value:E(j.value)})):[]):[],...y];var L;return{rights:c,metadata:C.length?C:void 0,label:f.label?E(f.label):void 0,requiredStatement:f.attribution?{label:E(J),value:E(f.attribution)}:void 0,navDate:f.navDate,summary:f.description?E(f.description):void 0,thumbnail:Mi(f.thumbnail)}}function Mi(f){return f&&(Array.isArray(f)?f:[f]).map(c=>typeof c=="string"?{id:c,type:"Image"}:(c.type==="unknown"&&(c.type="Image"),c))}function Ri(f){if(!f.within)return;const c=Array.isArray(f.within)?f.within:[f.within],y=[];for(const C of c)typeof C=="string"?C&&f["@type"]==="sc:Manifest"&&y.push({id:C,type:"Collection"}):C["@id"]&&y.push({id:C["@id"],type:nt(C)});return y.length?y:void 0}function le(f){const c=f.related?Array.isArray(f.related)?f.related:[f.related]:[],y=f.contentLayer;return{provider:f.logo||c.length?[{id:ee,type:"Agent",homepage:c.length?[c[0]]:void 0,logo:f.logo?Array.isArray(f.logo)?f.logo:[f.logo]:void 0,label:E(ge)}]:void 0,partOf:Ri(f),rendering:f.rendering,seeAlso:f.seeAlso,start:f.startCanvas,service:f.service?(C=f.service,Array.isArray(C)?C:C?[C]:[]):void 0,supplementary:y?[y]:void 0};var C}function it(f){const c=f;return H({...ne(c),...ie(c),...le(c),...(y=c,{chars:y.chars,format:y.format?y.format:void 0,language:y.language})});var y}const Ii=new _({collection:[function(f){return H({...ne(f),...ie(f),...le(f),items:f.members})}],manifest:[function(f){const c=[],y=[];let C;for(const j of f.sequences||[])j.canvases.length&&c.push(...j.canvases),j.behavior&&y.push(...j.behavior),j.startCanvas&&(C=j.startCanvas);const L=ne(f);return y.length&&(L.behavior?L.behavior.push(...y):L.behavior=y),H({...L,...ie(f),...le(f),start:C,items:c,structures:f.structures})}],canvas:[function(f){return H({...ne(f),...ie(f),...le(f),annotations:f.otherContent&&f.otherContent.length?f.otherContent:void 0,items:f.images&&f.images.length?[{id:zt(f,"annotation-page"),type:"AnnotationPage",items:f.images}]:void 0})}],annotationList:[function(f){return H({...ne(f),...ie(f),...le(f),items:f.resources&&f.resources.length?f.resources:void 0})}],sequence:[function(f){return f.canvases&&f.canvases.length!==0?{canvases:f.canvases,behavior:f.viewingHint?[f.viewingHint]:[],startCanvas:f.startCanvas}:{canvases:[],behavior:[]}}],annotation:[function(f){return H({...ne(f),...ie(f),...le(f),target:function c(y){if(Array.isArray(y)){if(y.length>1)return{type:"List",items:y.map(c)};y=y[0]}if(typeof y=="string")return encodeURI(y).trim();if("@type"in y){let C;if(typeof y.full=="string")C=y.full;else if(y.full["@type"]==="dctypes:Image")C={id:y.full["@id"],type:"Image"};else{if(y.full["@type"]!=="sc:Canvas")throw new Error(`Unsupported source type on annotation: ${y.full["@type"]}`);C={id:y.full["@id"],type:"Canvas"}}return{type:"SpecificResource",source:C,selector:st(y.selector)}}return encodeURI(y["@id"]).trim()}(f.on),body:Array.isArray(f.resource)?f.resource.map(it):it(f.resource)})}],contentResource:[it],choice:[function(f){const c=[];return f.default&&f.default!=="rdf:nil"&&c.push(f.default),f.item&&f.item!=="rdf:nil"&&c.push(...f.item),{...ne(f),...ie(f),items:c}}],range:[function(f){return H({...ne(f),...ie(f),...le(f),items:f.members})}],service:[function(f){const{"@id":c,"@type":y,"@context":C,profile:L,...j}=f,B={};return c&&(B["@id"]=c),B["@type"]=nt(f),B["@type"]==="unknown"&&(C&&C.length&&(B["@context"]=C),B["@type"]="Service"),L&&(B.profile=N(L)),H({...B,...j})}],layer:[function(f){return H({...ne(f),...ie(f),...le(f)})}]});function st(f){if((Array.isArray(f["@type"])&&f["@type"].includes("oa:SvgSelector")||f["@type"]=="oa:SvgSelector")&&("chars"in f||"value"in f))return{type:"SvgSelector",value:"chars"in f?f.chars:f.value};if(f["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:f.value};if(f["@type"]==="oa:Choice")return[st(f.default),...(Array.isArray(f.item)?f.item:[f.item]).map(st)];if(f["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in f?f.region:void 0,rotation:"rotation"in f?f.rotation:void 0};throw new Error(`Unsupported selector type: ${f["@type"]}`)}const ki=function(f){return f&&f["@context"]&&(f["@context"]==="http://iiif.io/api/presentation/2/context.json"||f["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")!==-1||f["@context"]==="http://www.shared-canvas.org/ns/context.json")||f["@context"]==="http://iiif.io/api/image/2/context.json"?Ii.traverseUnknown(f):f};s.upgrade=ki,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})})})(fr,fr.exports);function Oo(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function Ht(e,t){const{selector:r,source:n}=Te(t);if(n.id!==e.id)return[null,n];const i={type:"BoxSelector",spatial:{x:0,y:0,width:Number(e.width),height:Number(e.height)}};return[r?r.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:r.temporal,spatial:i.spatial}:r:null,n]}const _n={makeChoice:()=>{}},Ge={type:"unknown"},D=e=>({type:"unknown",reason:e,annotations:{pages:[]}}),Un=(e,t)=>({type:"empty",width:e,height:t,annotations:{pages:[]},image:null,images:[]});function Lo(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function Fo(e,t){return U(r=>{const n=[];if(!e)return n;const i=Object.keys(r.iiif.entities.AnnotationPage);for(const s of i)if(!t||t.indexOf(s)!==-1){const a=Lo(r,s);a&&a.views&&a.views[e]&&n.push(s)}return n},[e,t])}function Hn({canvas:e,manifest:t,all:r,canvases:n}){const i=[];if(t)for(const s of t.annotations)i.indexOf(s.id)===-1&&i.push(s.id);if(r){if(n&&n.length)for(const s of n)for(const a of s.annotations)i.indexOf(a.id)===-1&&i.push(a.id)}else if(e)for(const s of e.annotations)i.indexOf(s.id)===-1&&i.push(s.id);return i}function $o(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function Nn(e,t={}){const r=V(),n=ve(),i=re(),s=Et(),a=v.useMemo(()=>Hn({all:t.all,manifest:n,canvas:i,canvases:s}),[t.all,i,s,n]),o=Fo(e,t.all?void 0:a),u=v.useCallback(l=>{e&&r.setMetaValue([l,"annotationPageManager","views"],p=>p&&!p[e]?p:{...p||{},[e]:!1})},[e,r]),d=v.useCallback((l,p={})=>{if(!e)return;const g=r.getState(),b=[];if(p!=null&&p.deselectOthers){const h=Object.keys(g.iiif.entities.AnnotationPage);for(const x of h){const A=$o(g,x);A&&A.views&&A.views[e]&&b.push(x)}}for(const h of b)u(h);r.setMetaValue([l,"annotationPageManager","views"],h=>h&&h[e]?h:{...h||{},[e]:!0})},[e,u,r]);return{availablePageIds:a,enabledPageIds:o,setPageEnabled:d,setPageDisabled:u}}function Bn(e,t){return U((r,n)=>n.get(e.map(i=>({id:i,type:t}))),[e,t])}const zn=v.createContext(new Se.ImageServiceLoader);function Xe(){return v.useContext(zn)}function Wn(){const e=Xe(),[t,r]=v.useState({}),n=v.useRef(!1);return v.useEffect(()=>()=>{n.current=!0},[]),[v.useCallback((s,{height:a,width:o})=>{if(s){const u=s.id||s["@id"],d=e.loadServiceSync({id:u,width:s.width||o,height:s.height||a,source:s});d?s=d:t[u]||(n.current||r(l=>({...l,[u]:"loading"})),e.loadService({id:u,width:s.width||o,height:s.height||a}).then(()=>{n.current||r(l=>({...l,[u]:"done"}))}))}return s},[e,t]),t]}function et(e={}){const t=qt(),r=re(e.canvasId?{id:e.canvasId}:void 0);return U((n,i)=>{if(!r)return[];if(t&&e.enableSingleAnnotation)return[t];const s=i.get(r.items),a=[];for(const o of s)a.push(...i.get(o.items));return a},[r])}function Do(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}const Be={},Qn={get(e){return e},setMetaValue([e,t,r],n){const i=Qn.getResourceMeta(e,t),s=i?i[r]:void 0,a=typeof n=="function"?n(s):n;Be[e]={...Be[e]||{},[t]:{...(Be[e]||{})[t]||{},[r]:a}}},getResourceMeta:(e,t)=>{const r=Be[e];if(r)return t?r[t]:r}};function qo(e=Qn){function t(i){const s=i?typeof i=="string"?e.get(i):i:null;if(!s)return[];const a=e.get(s.items,{parent:s}),o=[];for(const u of a)o.push(...e.get(u.items,{parent:u}));return o}function r(i,s=[]){const a=Array.isArray(i)?i:t(i),o=[];let u=null;const d=[];for(const l of a){if(l.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const p=Array.from(Array.isArray(l.body)?l.body:[l.body]);for(const g of p){const[b,{selector:h}]=Do(g),x=e.get(b),A=(x.type||"unknown").toLowerCase();if(A==="choice"){const S=e.get(x.items,{parent:x.id}),w=s.length?s.map(M=>S.find(T=>T.id===M)).filter(Boolean):[S[0]];w.length===0&&w.push(S[0]),u={type:"single-choice",items:S.map(M=>({id:M.id,label:M.label,selected:w.indexOf(M)!==-1})),label:b.label},p.push(...w);continue}o.indexOf(A)===-1&&o.push(A),d.push({type:A,annotationId:l.id,resource:x,target:l.target,selector:h})}}return{types:o,items:d,choice:u}}function n(i){const{choice:s}=r(i);return s}return{getAllPaintingAnnotations:t,getPaintables:r,extractChoices:n}}function Yn(e,t=[]){const r=V(),n=v.useMemo(()=>qo(r),[]),i=et({enableSingleAnnotation:e==null?void 0:e.enableSingleAnnotation}),[s,a]=v.useState((e==null?void 0:e.defaultChoices)||[]),o=v.useMemo(()=>n.getPaintables(i,s),[r,i,s,...t]),d={makeChoice:v.useCallback((l,{deselectOthers:p=!0,deselect:g=!1}={})=>{if(o.choice){if(o.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");a(b=>{if(g){const x=b.filter(A=>A!==l);if(x.length===0){const A=o.items[0].resource.id;return A?[A]:[]}return x}if(p)return[l];const h=[...b];if(h.length===0&&o.items.length){const x=o.items[0].resource.id;x&&h.push(x)}return b.indexOf(l)!==-1?b:[...b,l]})}},[o.choice])};return[o,d]}function Gn(e,t,r){const n=[];for(const i of t.items){const s=i.resource&&i.resource.type==="SpecificResource"?i.resource.source:i.resource;if(!s.id)return D("No resource Identifier");let a;if(s.service){const b=Se.getImageServices(s);b[0]&&(a=r(b[0],e))}const o={type:"BoxSelector",spatial:{x:0,y:0,width:Number(e.width),height:Number(e.height)}},[u,d]=Ht(e,i.target);if(d.id!==e.id)continue;i.resource.width&&i.resource.height&&(i.resource.width,i.resource.height);let l=i.resource.type==="SpecificResource"?de(i.resource):null;if(i.selector){const b=de({type:"SpecificResource",source:i.resource,selector:i.selector});b&&(l=b)}const p=l&&l.selector&&(l.selector.type==="BoxSelector"||l.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:l.selector.spatial.x,y:l.selector.spatial.y,width:l.selector.spatial.width,height:l.selector.spatial.height}}:void 0;a&&!a.id&&(a.id=a["@id"]);const g={id:s.id,type:"Image",annotationId:i.annotationId,width:Number(u||p?s.width:e.width),height:Number(u||p?s.height:e.height),service:a,sizes:a&&a.sizes?a.sizes:s.width&&s.height?[{width:s.width,height:s.height}]:[],target:u&&u.type!=="PointSelector"?u:o,selector:p};n.push(g)}return{type:"images",image:n[0],images:n,choice:t.choice}}const Vo=["model/gltf-binary"];function _o(e,t){const n=t.items[0].resource;return n.format?Vo.indexOf(n.format)===-1?D(`3D format: ${n.format} is unsupported`):{type:"3d-model",model:n}:D("Unknown format")}function Uo(e,t){var n;if(!e.duration)return D("No duration on canvas");if(t.items.length>1)return D("Only one audio source supported");const r=(n=t.items[0])==null?void 0:n.resource;return r?r.format?{type:"media",media:{annotationId:t.items[0].annotationId,duration:e.duration,url:r.id,type:"Sound",target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:r.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}},annotations:{pages:[]}}:D("Audio does not have format"):D("Unknown audio")}const Ho=/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?vi?=|&vi?=))([^#&?]*).*/;function No(e,t){var a;const r=t.items.filter(o=>o.type==="video");if(!e.duration)return D("No duration on canvas");if(r.length>1)return D("Only one video source supported");const n=(a=r[0])==null?void 0:a.resource,i=!!(n.service||[]).find(o=>(o.profile||"").includes("youtube.com"));if(!n)return D("Unknown video");if((!n.format||n.format==="text/html")&&!i)return D("Video does not have format");const s={annotationId:t.items[0].annotationId,duration:e.duration,url:n.id,type:"Video",items:[],target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:n.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}};if(i){s.type="VideoYouTube";const o=n.id.match(Ho);if(!o[1])return D("Video is not known youtube video");s.youTubeId=o[1]}return{type:"media",media:s,annotations:{pages:[]}}}function Jn(e,t={},r){const n=e.language||r||"none";switch(e.type){case"TextualBody":{typeof e.value<"u"&&(t[n]=e.value);break}case"List":case"Composite":case"Choice":e.items&&e.items.forEach(i=>Jn(i,t,n))}return t}function Bo(e,t){const r=[];return t.items.forEach(n=>{if(n.resource){const[i]=Ht(e,n.target);r.push({annotationId:n.annotationId,text:Jn(n.resource),target:i})}}),{type:"textual-content",items:r}}function Kn(e){const t=ve(),r=re(),n=V(),[i,s]=Wn(),{enabledPageIds:a}=Nn((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(r==null?void 0:r.id),{all:!1}),o=Bn(a,"AnnotationPage"),u=(e==null?void 0:e.strategies)||["empty","images","media","textual-content","complex-timeline"],[d,l]=Yn(e,[s]),p=v.useMemo(()=>{if(!r)return console.log("No canvas"),Ge;if(d.types.length===0)return u.indexOf("empty")!==-1?Un(r.width,r.height):(console.log("No paintables"),Ge);if(d.types.length!==1)if(d.types.length===2&&d.types.indexOf("text")!==-1)d.types=d.types.filter(b=>b!=="text");else return u.indexOf("complex-timeline")===-1?D("Complex timeline not supported"):D("ComplexTimelineStrategy not yet supported");const g=d.types[0];return g==="image"?u.indexOf("images")===-1?D("Image not supported"):Gn(r,d,i):g==="Model"||g==="model"?u.indexOf("3d-model")===-1?D("3D not supported"):_o(r,d):g==="textualbody"?u.indexOf("textual-content")===-1?D("Textual content not supported"):Bo(r,d):g==="sound"||g==="audio"?u.indexOf("media")===-1?D("Media not supported"):Uo(r,d):g==="video"?u.indexOf("media")===-1?D("Media not supported"):No(r,d):(console.log("No idea"),Ge)},[r,d,n,l.makeChoice]);return v.useMemo(()=>p.type==="unknown"?[p,_n]:[{...p,annotations:{pages:o}},l],[p,o])}const Zn=(e,t=[])=>{const r=V();v.useEffect(()=>{e(r)},[r,...t])},ze={},Xn={get(e){return e},setMetaValue([e,t,r],n){const i=Xn.getResourceMeta(e,t),s=i?i[r]:void 0,a=typeof n=="function"?n(s):n;ze[e]={...ze[e]||{},[t]:{...(ze[e]||{})[t]||{},[r]:a}}},getResourceMeta:(e,t)=>{const r=ze[e];if(r)return t?r[t]:r}},zo=new Se.ImageServiceLoader;function Wo(e=Xn,t={}){const r=t.imageServiceLoader||zo;async function n(i,s,a=!1,o=[],u){const d=()=>r.getThumbnailFromResource(void 0,s,a,o);if(!i)return await r.getThumbnailFromResource(void 0,s,a,o);if(typeof i=="string"){const p=Se.getFixedSizeFromImage(i);return p&&o.push(p),await r.getThumbnailFromResource(void 0,s,a,o)}const l=e.get(i,{skipSelfReturn:!1});if(typeof l=="string")return{best:Se.getFixedSizeFromImage(l),fallback:[],log:[]};if(!l)return await d();switch(await(async p=>{if(p&&p.thumbnail&&p.thumbnail.length){const g=e.get(p.thumbnail[0]),b=await r.getImageCandidates(g,a);b&&b.length&&o.push(...b)}})(l),l.type){case"Annotation":{const p=Array.isArray(l.body)?l.body:[l.body],g=e.get(p[0]);return u&&!g.width&&(g.width=u.width,g.height=u.height),await r.getThumbnailFromResource(g,s,a,o)}case"Canvas":{const p=l;return n(p.items[0],s,a,o,{width:p.width,height:p.height})}case"AnnotationPage":return n(l.items[0],s,a,o,u);case"Choice":{const p=l;return!p.items||p.items[0]?await d():n(p.items[0],s,a,o,u)}case"Collection":{const p=l.items[0];return p?n(p,s,a,o,u):await d()}case"Manifest":{const p=l.items[0];return p?n(p,s,a,o,u):await d()}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return u&&!l.width&&(l.width=u.width,l.height=u.height),r.getThumbnailFromResource(l,s,a,o)}return await d()}return{getBestThumbnailAtSize:n}}function ei(e,t,{canvasId:r,manifestId:n}={}){const i=V(),s=Xe(),a=v.useMemo(()=>Wo(i,{imageServiceLoader:s}),[i,s]),[o,u]=v.useState(),d=ve(n?{id:n}:void 0),l=re(r?{id:r}:void 0),p=l||d,g=v.useRef(!1);if(v.useEffect(()=>(g.current=!1,()=>{g.current=!0}),[]),!p)throw new Error("Must be called under a manifest or canvas context.");return Zn(b=>{a.getBestThumbnailAtSize(p,e,t).then(h=>{h.best&&!g.current&&u(h.best)})},[p]),o}function Qo(e){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:e}}function Yo(e,t){switch(t.type){case"FINISHED":return{...e,isFinished:!0,isPlaying:!1,playRequested:!1};case"PLAY_PAUSE":return{...e,isFinished:!1,isPlaying:!e.isPlaying};case"PLAY_REQUESTED":return{...e,isFinished:!1,playRequested:!0};case"PAUSE":return{...e,isPlaying:!1};case"PLAY":return{...e,isFinished:!1,playRequested:!1,isPlaying:!0};case"MUTE":return{...e,isMuted:!0};case"SET_VOLUME":return{...e,volume:t.volume,isMuted:t.volume===0};case"TOGGLE_MUTE":return{...e,isMuted:!e.isMuted};case"UNMUTE":return{...e,isMuted:!1}}return e}function ti(e){const t=Math.round(e);return`${Math.floor(t/60)}:${`${t%60}`.padStart(2,"0")}`}function tt(e){const[t,r]=v.useReducer(Yo,Qo(e.duration)),n=v.useRef(null),i=v.useRef(null),s=v.useRef(null),a=v.useRef(!1),o=v.useCallback(()=>{i.current&&n.current&&(i.current.innerHTML=ti(n.current.currentTime),s.current&&(s.current.style.width=`${n.current.currentTime/e.duration*100}%`),a.current!==n.current.muted&&(a.current=n.current.muted,r(n.current.muted?{type:"MUTE"}:{type:"UNMUTE"})))},[e.duration]),u=v.useCallback(()=>{n.current&&(r({type:"PLAY_REQUESTED"}),n.current.play().then(()=>{r({type:"PLAY"})}),o())},[o]),d=v.useCallback(()=>{n.current&&(n.current.duration>0&&n.current.paused?u():l())},[o]),l=v.useCallback(()=>{n.current&&(n.current.pause(),r({type:"PAUSE"}),o())},[o]),p=v.useCallback(()=>{n.current&&(n.current.muted=!n.current.muted,r(n.current.muted?{type:"MUTE"}:{type:"UNMUTE"}))},[]),g=v.useCallback(()=>{n.current&&(n.current.muted=!0,r({type:"MUTE"}))},[]),b=v.useCallback(()=>{n.current&&(n.current.muted=!1,r({type:"UNMUTE"}))},[]),h=v.useCallback(S=>{n.current&&(n.current.muted=!1,n.current.volume=S/100,r({type:"SET_VOLUME",volume:S}))},[]),x=v.useCallback(S=>{n.current&&(n.current.currentTime=Math.max(0,Math.min(S*e.duration,e.duration)),o())},[]),A=v.useCallback(S=>{n.current&&(n.current.currentTime=Math.max(0,Math.min(S,e.duration)),o())},[]);return v.useEffect(()=>{const S=setInterval(()=>{o()},350);return()=>clearInterval(S)},[o,e.duration]),v.useEffect(()=>{const S=()=>{r({type:"FINISHED"})},w=n.current;return w==null||w.addEventListener("ended",S),()=>w==null?void 0:w.removeEventListener("ended",S)},[]),[{element:n,currentTime:i,progress:s},t,{play:u,pause:l,playPause:d,mute:g,unmute:b,toggleMute:p,setVolume:h,setDurationPercent:x,setTime:A}]}const ri=v.createContext(null),ni=v.createContext(null),ii=v.createContext(null);function Go(){const e=v.useContext(ri);if(!e)throw new Error("Ctx not found");return e}function Jo(){const e=v.useContext(ni);if(!e)throw new Error("Ctx not found");return e}function Ko(){const e=v.useContext(ii);if(!e)throw new Error("Ctx not found");return e}function Nt({actions:e,state:t,children:r,currentTime:n,progress:i,element:s}){return m.jsx(ii.Provider,{value:{currentTime:n,progress:i,element:s},children:m.jsx(ni.Provider,{value:e,children:m.jsx(ri.Provider,{value:t,children:r})})})}function si({media:e,children:t}){const[{element:r,currentTime:n,progress:i},s,a]=tt({duration:e.duration});return m.jsxs(Nt,{state:s,actions:a,currentTime:n,progress:i,element:r,children:[m.jsx("audio",{ref:r,src:e.url}),t]})}function ai({media:e,mediaControlsDeps:t,children:r}){return Ie("portal","audio",si,{media:e,children:r},[e,...t||[]]),null}function oi({element:e,media:t,playPause:r}){return m.jsxs("div",{className:"video-container",part:"video-container",onClick:r,children:[m.jsx("style",{children:`
65
+ */function Na(t,e,r,n=1){return new vn(t,e,r).subdivide(n)}function Ba(t,e,r,n,i=1){return new _t(new Float64Array([t.x,t.y,e.x,e.y,r.x,r.y,n.x,n.y])).subdivide(i)}function za(t){return t.x*t.x+t.y*t.y}function Le(t){return t/(1-.67+Math.pow(Math.pow(.67,4)+.25*t*t,.25))}function Me(t){return t*(1-.39+Math.sqrt(.39*.39+.25*t*t))}class vn{constructor(e,r,n){Qe(this,"start"),Qe(this,"control"),Qe(this,"end"),this.start=e,this.control=r,this.end=n}eval(e){const r=1-e;return{x:this.start.x*r*r+2*this.control.x*r*e+this.end.x*e*e,y:this.start.y*r*r+2*this.control.y*r*e+this.end.y*e*e}}mapToBasic(){const{x:e,y:r}=this.start,{x:n,y:i}=this.control,{x:s,y:a}=this.end,o=2*n-e-s,u=2*i-r-a,d=(n-e)*o+(i-r)*u,l=(s-n)*o+(a-i)*u,p=(s-e)*u-(a-r)*o,m=d/p,A=l/p,h=Math.abs(p)/(Math.hypot(o,u)*Math.abs(A-m));return{x0:e,x2:s,scale:h,cross:p}}subdivide(e){const r=this.mapToBasic(),n=Le(r.x0),i=Le(r.x2),s=.5*Math.abs(i-n)*Math.sqrt(r.scale/e),a=Math.ceil(s),o=Me(n),u=Me(i),d=[0];for(let l=1;l<a;l++){const p=(Me(n+(i-n)*l/a)-o)/(u-o);d.push(p)}return d.push(1),d.map(l=>this.eval(l))}}class _t{constructor(e){Qe(this,"c"),this.c=e}weightsum(e,r,n,i){const s=e*this.c[0]+r*this.c[2]+n*this.c[4]+i*this.c[6],a=e*this.c[1]+r*this.c[3]+n*this.c[5]+i*this.c[7];return{x:s,y:a}}eval(e){const r=1-e,n=r*r*r,i=3*r*r*e,s=3*r*e*e,a=e*e*e;return this.weightsum(n,i,s,a)}deriv(e){const r=1-e,n=-3*r*r,i=3*e*e,s=-6*e*r-n,a=6*e*r-i;return this.weightsum(n,s,a,i)}midpoint_quadbez(){const e=this.weightsum(-.25,.75,.75,-.25);return new vn({x:this.c[0],y:this.c[1]},e,{x:this.c[6],y:this.c[7]})}subsegment(e,r){const n=new Float64Array(8),i=this.eval(e),s=this.eval(r);n[0]=i.x,n[1]=i.y;const a=(r-e)/3,o=this.deriv(e);n[2]=i.x+a*o.x,n[3]=i.y+a*o.y;const u=this.deriv(r);return n[4]=s.x-a*u.x,n[5]=s.y-a*u.y,n[6]=s.x,n[7]=s.y,new _t(n)}subdivide(e){const r=.1*e,n=e-r,i=Math.sqrt(n),s=za(this.weightsum(1,-3,3,-1)),a=Math.ceil(Math.pow(s/(432*r*r),1/6)),o=[];let u=0;for(let h=0;h<a;h++){const x=h/a,b=(h+1)/a,S=this.subsegment(x,b).midpoint_quadbez(),w=S.mapToBasic(),M=Le(w.x0),T=Le(w.x2),F=Math.sqrt(w.scale);let k=Math.abs(T-M)*F;if(Math.sign(w.x0)!=Math.sign(w.x2)){const O=i/F,E=i*Math.abs(T-M)/Le(O);k=Math.max(k,E)}o.push({quad:S,a0:M,a2:T,val:k}),u+=k}const d=.5*u/i,l=Math.ceil(d),p=[{x:this.c[0],y:this.c[1]}];let m=0,A=0;for(let h=1;h<l;h++){const x=u*h/l;for(;m+o[A].val<x;)m+=o[A].val,A++;const b=o[A].a0,S=o[A].a2,w=Me(b),M=Me(S),T=b+(S-b)*(x-m)/o[A].val,F=(Me(T)-w)/(M-w);p.push(o[A].quad.eval(F))}return p.push({x:this.c[6],y:this.c[7]}),p}}const Wa=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,Qa=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,or=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function Ye(t,{domParser:e,svgPreprocessor:r,iiifRenderingHints:n}={}){if(Array.isArray(t))return Z(t.reduce((i,s)=>{const{selector:a,selectors:o,iiifRenderingHints:u}=Ye(s,{domParser:e,svgPreprocessor:r,iiifRenderingHints:n});return a&&(i.selector||(i.selector=a),i.selectors.push(...o)),u&&(i.iiifRenderingHints=i.iiifRenderingHints||{type:"ImageApiSelector"},Object.assign(i.iiifRenderingHints,u)),i},{selector:null,selectors:[],iiifRenderingHints:n}));if(!t)return Z({selector:null,selectors:[],iiifRenderingHints:n});if(typeof t=="string"){const[i,s]=t.split("#");return s?Ye({type:"FragmentSelector",value:s},{svgPreprocessor:r,iiifRenderingHints:n,domParser:e}):Z({selector:null,selectors:[],iiifRenderingHints:n})}if(t.type&&t.type==="PointSelector"&&(t.t||t.t===0)){const i={type:"TemporalSelector",temporal:{startTime:t.t}};return Z({selector:i,selectors:[i],iiifRenderingHints:n})}if(Ka(t)){const i=[];if(t.region){const s=Ye({type:"FragmentSelector",value:"xywh="+t.region},{domParser:e,svgPreprocessor:r,iiifRenderingHints:n});i.push(...s.selectors)}return Z({selector:i[0],selectors:i,iiifRenderingHints:n?{...n,...t}:t})}if(t.type==="FragmentSelector"){const i=Wa.exec(t.value);if(i){const a={type:"BoxSelector",spatial:{unit:i[2]==="percent:"||i[2]==="pct:"?"percent":"pixel",x:parseFloat(i[3]),y:parseFloat(i[4]),width:parseFloat(i[5]),height:parseFloat(i[6])}};return Z({selector:a,selectors:[a],iiifRenderingHints:n})}const s=t.value.match(Qa);if(s){const a={type:"TemporalSelector",temporal:{startTime:s[4]?parseFloat(s[4]):0,endTime:s[7]?parseFloat(s[7]):void 0}};return Z({selector:a,selectors:[a],iiifRenderingHints:n})}return Z({selector:null,selectors:[],iiifRenderingHints:n})}if(t.type==="SvgSelector"&&"value"in t){e||(typeof window<"u"?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 i=[],s,a,o=(r==null?void 0:r(t.value))??t.value,u;if(e){const l=e.parseFromString(t.value,"image/svg+xml").querySelector("svg");if(!l)return console.warn(`Illegal SVG selector: ${t.value}`),Z({selector:null,selectors:[],iiifRenderingHints:n});const p=gn(l);p&&(i=p.points,u=p.shapeType,s=[Math.min(...i.map(m=>m[0])),Math.min(...i.map(m=>m[1])),Math.max(...i.map(m=>m[0])),Math.max(...i.map(m=>m[1]))],{style:a,svg:o}=Ja(p.element)??{svg:o})}const d={type:"SvgSelector",svg:o,svgShape:u,style:a,points:i.length?i:void 0,spatial:s?{unit:"pixel",x:s[0],y:s[1],width:s[2]-s[0],height:s[3]-s[1]}:void 0};return Z({selector:d,selectors:[d],iiifRenderingHints:n})}return Z({selector:null,selectors:[],iiifRenderingHints:n})}function Ya(t){const e=t.map(n=>n[0]).reduce((n,i)=>(n[i]+=1,n),{C:0,Q:0,L:0,M:0}),r=new Set(t.map(n=>n[0]));if(e.C>0||e.Q>0)return"path";if(e.L>0&&(r.size===1||r.size===2&&r.has("M"))){if(e.L===4)return"rect";const n=t.slice(-1)[0];return t[0][0]==="M"&&n[0]==="L"&&n[1]==t[0][1]&&n[2]===t[0][2]||n[1]===0&&n[2]===0?"polygon":"polyline"}return"path"}function gn(t){var e;for(const r of Array.from(t.children))switch(r==null?void 0:r.tagName.toLowerCase()){case"g":{const n=gn(r);if(n)return n}continue;case"path":{const n=r.getAttribute("d");if(!n)continue;const i=Ha(n);return{element:r,points:Ga(i),shapeType:Ya(i)}}case"circle":{const n=parseFloat(r.getAttribute("cx")??"0"),i=parseFloat(r.getAttribute("cy")??"0"),s=parseFloat(r.getAttribute("r")??"0");if(!s)continue;const a=[];for(let o=0;o<=360;o+=12){const u=o*Math.PI/180;a.push([n+s*Math.cos(u),i+s*Math.sin(u)])}return{element:r,points:a,shapeType:"circle"}}case"ellipse":{const n=parseFloat(r.getAttribute("cx")??"0"),i=parseFloat(r.getAttribute("cy")??"0"),s=parseFloat(r.getAttribute("rx")??"0"),a=parseFloat(r.getAttribute("ry")??"0");if(!s&&!a)continue;const o=[];for(let u=0;u<=360;u+=12){const d=Math.tan(u/360*Math.PI),l=s*(1-d**2)/(1+d**2),p=a*2*d/(1+d**2);o.push([n+l,i+p])}return{element:r,points:o,shapeType:"ellipse"}}case"line":{const n=parseFloat(r.getAttribute("x0")??"0"),i=parseFloat(r.getAttribute("y0")??"0"),s=parseFloat(r.getAttribute("x1")??"0"),a=parseFloat(r.getAttribute("y1")??"0");if(n===s&&i===a)continue;return{element:r,points:[[n,i],[s,a]],shapeType:"polyline"}}case"polygon":case"polyline":{const n=((e=r.getAttribute("points"))==null?void 0:e.split(" ").map(s=>s.split(",").map(parseFloat)))??[];if(!n.length)continue;let i="polyline";return r.tagName.toLowerCase()==="polygon"&&(n.push(n[0]),i="polygon"),{element:r,points:n,shapeType:i}}case"rect":{const n=parseFloat(r.getAttribute("x")??"0"),i=parseFloat(r.getAttribute("y")??"0"),s=parseFloat(r.getAttribute("width")??"0"),a=parseFloat(r.getAttribute("height")??"0");if(!s||!a)continue;return{element:r,points:[[n,i],[n+s,i],[n+s,i+a],[n,i+a],[n,i]],shapeType:"rect"}}default:continue}return null}function Ga(t){const e=[];for(let r=0;r<t.length;r++){const n=e[e.length-1]??[0,0],i=t[r];switch(i[0]){case"M":case"L":e.push([i[1],i[2]]);continue;case"C":e.push(...Ba({x:n[0],y:n[1]},{x:i[1],y:i[2]},{x:i[3],y:i[4]},{x:i[5],y:i[6]}).map(s=>[s.x,s.y]).slice(1));continue;case"Q":e.push(...Na({x:n[0],y:n[1]},{x:i[1],y:i[2]},{x:i[3],y:i[4]}).map(s=>[s.x,s.y]).slice(1));continue}}return e}function Ja(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 n=or.exec(e.fill);n&&(e.fillOpacity=parseFloat(n[4]),e.fill=`rgb(${n[1]}, ${n[2]}, ${n[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 n=or.exec(e.stroke);n&&(e.strokeOpacity=parseFloat(n[4]),e.stroke=`rgb(${n[1]}, ${n[2]}, ${n[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 r=t;for(;r.tagName.toLowerCase()!=="svg";)if(r=r.parentElement,r===null)throw new Error("Could not find root SVG element");return{svg:r.outerHTML,style:Object.keys(e).length>0?e:void 0}}function Ka(t){return!!t&&t.type==="iiif:ImageApiSelector"&&t.type==="iiif:ImageApiSelector"}function Z(t){if(t.iiifRenderingHints){const e=t.iiifRenderingHints;if(e.rotation){const r=Za(e.rotation);if(r)if(t.selectors.length)for(const n of t.selectors)n.rotation=r;else t.selectors.push({type:"RotationSelector",rotation:r})}}else delete t.iiifRenderingHints;return t}function Za(t){let e=parseFloat(t);return e&&t.startsWith("!")&&(e=360-e),e&&(e=e%360),e!==e?0:e||0}function Te(t,e={}){if(Array.isArray(t))return Te(t[0]);if(typeof t=="string"){const[r,n]=t.split("#");return n?Te({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{id:r,type:e.typeMap&&e.typeMap[r]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return Te(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:r,selectors:n}=t.selector?Ye(t.selector,e):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:r,selectors:n}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[r,n]=t.id.split("#");return n?Te({type:"SpecificResource",source:{...t,id:r},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{...t,id:r},selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}var Xa=Object.defineProperty,eo=(t,e,r)=>e in t?Xa(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,cr=(t,e,r)=>(eo(t,typeof e!="symbol"?e+"":e,r),r);function to(t){return Array.isArray(t)?t:t?[t]:[]}const ur=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function ro(t){if(typeof t>"u"||t===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(t))throw new Error("Array is not a valid entity");if(typeof t!="object")throw new Error(`${typeof t} is not a valid entity`);if(typeof t["@type"]=="string"){const e=ur.indexOf(t["@type"]);if(e!==-1)return ur[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}class Ut{constructor(e,r={}){cr(this,"traversals"),cr(this,"options"),this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...r}}static all(e){return new Ut({collection:[e],manifest:[e],canvas:[e],annotationList:[e],sequence:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],layer:[e]})}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))),this.traversals.collection)}traverseCollectionItems(e){if(this.options.mergeMemberProperties){const r=[...(e.manifests||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n),...(e.collections||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n),...e.members||[]];delete e.collections,delete e.manifests,e.members=r}return e.manifests&&(e.manifests=e.manifests.map(r=>this.traverseManifest(typeof r=="string"?{"@id":r,"@type":"sc:Manifest"}:r))),e.collections&&(e.collections=e.collections.map(r=>this.traverseCollection(typeof r=="string"?{"@id":r,"@type":"sc:Collection"}:r))),e.members&&(e.members=e.members.map(r=>typeof r=="string"?r:this.traverseUnknown(r))),e}traverseManifest(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))),this.traversals.manifest)}traverseManifestItems(e){return e.sequences&&(e.sequences=e.sequences.map(r=>this.traverseSequence(r))),e.structures&&(e.structures=e.structures.map(r=>this.traverseRange(r))),e}traverseSequence(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))),this.traversals.sequence)}traverseSequenceItems(e){return e.canvases&&(e.canvases=e.canvases.map(r=>this.traverseCanvas(r))),e}traverseCanvas(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))),this.traversals.canvas)}traverseCanvasItems(e){return e.images&&(e.images=e.images.map(r=>this.traverseAnnotation(r))),e.otherContent&&(e.otherContent=e.otherContent.map(r=>this.traverseAnnotationList(r))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const r=[...(e.ranges||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Range"}:n),...(e.canvases||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Canvas"}:n),...e.members||[]];delete e.ranges,delete e.canvases,e.members=r.length?r.map(n=>this.traverseUnknown(n)):void 0}return e}traverseAnnotationList(e){const r=typeof e=="string"?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(r)),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map(r=>this.traverseAnnotation(r))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(Array.isArray(e.resource)?e.resource=e.resource.map(r=>this.traverseContentResource(r)):e.resource=this.traverseContentResource(e.resource)),e.on,e}traverseLayer(e){return this.traverseType(this.traverseLinking(this.traverseLayerItems(e)),this.traversals.layer)}traverseLayerItems(e){return e.otherContent&&(e.otherContent=e.otherContent.map(r=>this.traverseAnnotationList(r))),e}traverseChoice(e){return this.traverseType(this.traverseChoiceItems(e),this.traversals.choice)}traverseChoiceItems(e){return e.default&&e.default!=="rdf:nil"&&(e.default=this.traverseContentResource(e.default)),e.item&&e.item!=="rdf:nil"&&(e.item=e.item.map(r=>this.traverseContentResource(r))),e}traverseService(e){return this.traverseType(this.traverseLinking(e),this.traversals.service)}traverseContentResource(e){return e["@type"]==="oa:Choice"?this.traverseChoice(e):this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.contentResource)}traverseUnknown(e){if(!e["@type"]||typeof e=="string")return e;switch(ro(e)){case"sc:Collection":return this.traverseCollection(e);case"sc:Manifest":return this.traverseManifest(e);case"sc:Canvas":return this.traverseCanvas(e);case"sc:Sequence":return this.traverseSequence(e);case"sc:Range":return this.traverseRange(e);case"oa:Annotation":return this.traverseAnnotation(e);case"sc:AnnotationList":return this.traverseAnnotationList(e);case"sc:Layer":return this.traverseLayer(e);case"Service":return this.traverseService(e);case"oa:Choice":return this.traverseChoice(e);case"ContentResource":return this.traverseContentResource(e)}return e.profile?this.traverseService(e):e}traverseImageResource(e){const r=Array.isArray(e),n=Array.isArray(e)?e:[e],i=[];for(const s of n)typeof s=="string"?i.push(this.traverseContentResource({"@id":s,"@type":"dctypes:Image"})):i.push(this.traverseContentResource(s));return!r&&!this.options.convertPropsToArray?i[0]:i}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){const r=Array.isArray(e),n=Array.isArray(e)?e:[e],i=[];for(const s of n)i.push(this.traverseService(s));return!r&&!this.options.convertPropsToArray?i[0]:i}traverseLinking(e){return e.related&&(e.related=this.traverseOneOrManyType(e.related,this.traversals.contentResource)),e.rendering&&(e.rendering=this.traverseOneOrManyType(e.rendering,this.traversals.contentResource)),e.service&&(e.service=this.traverseOneOrMoreServices(e.service)),e.seeAlso&&(e.seeAlso=this.traverseOneOrManyType(e.seeAlso,this.traversals.contentResource)),e.within&&(typeof e.within=="string"||(e.within=this.traverseOneOrManyType(e.within,this.traversals.contentResource))),e.startCanvas&&(typeof e.startCanvas=="string"?e.startCanvas=this.traverseType({"@id":e.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):e.startCanvas&&this.traverseType(e.startCanvas,this.traversals.canvas)),e.contentLayer&&(typeof e.contentLayer=="string"?e.contentLayer=this.traverseLayer({"@id":e.contentLayer,"@type":"sc:Layer"}):e.contentLayer=this.traverseLayer(e.contentLayer)),e}traverseOneOrManyType(e,r){if(!Array.isArray(e))if(this.options.convertPropsToArray)e=[e];else return this.traverseType(e,r);return e.map(n=>this.traverseType(n,r))}traverseType(e,r){return r.reduce((n,i)=>{const s=i(n);return typeof s>"u"&&!this.options.allowUndefinedReturn?n:s},e)}}const no="http://library.stanford.edu/iiif/image-api/compliance.html#level0",mn="http://library.stanford.edu/iiif/image-api/compliance.html#level1",xn="http://library.stanford.edu/iiif/image-api/compliance.html#level2",io="http://library.stanford.edu/iiif/image-api/conformance.html#level0",bn="http://library.stanford.edu/iiif/image-api/conformance.html#level1",An="http://library.stanford.edu/iiif/image-api/conformance.html#level2",so="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Sn="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",wn="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",ao="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Cn="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Mn="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",oo="http://iiif.io/api/image/1/level0.json",co="http://iiif.io/api/image/1/profiles/level0.json",Rn="http://iiif.io/api/image/1/level1.json",In="http://iiif.io/api/image/1/profiles/level1.json",kn="http://iiif.io/api/image/1/level2.json",Tn="http://iiif.io/api/image/1/profiles/level2.json",uo="http://iiif.io/api/image/2/level0.json",lo="http://iiif.io/api/image/2/profiles/level0.json",jn="http://iiif.io/api/image/2/level1.json",Pn="http://iiif.io/api/image/2/profiles/level1.json",En="http://iiif.io/api/image/2/level2.json",On="http://iiif.io/api/image/2/profiles/level2.json",fo="level0",Ln="level1",Fn="level2",po="http://iiif.io/api/image/2/level0",$n="http://iiif.io/api/image/2/level1",Dn="http://iiif.io/api/image/2/level2",ho=[$n,Dn,mn,xn,bn,An,Sn,wn,Cn,Mn,Rn,In,kn,Tn,jn,Pn,En,On,Ln,Fn],yo=[po,$n,Dn,no,mn,xn,io,bn,An,so,Sn,wn,ao,Cn,Mn,oo,co,Rn,In,kn,Tn,uo,lo,jn,Pn,En,On,fo,Ln,Fn];function ae(t){for(const e in t)(typeof t[e]>"u"||t[e]===null)&&delete t[e];return t}const Rt={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function Ae(t,e="none"){if(!t)return{};const r=Array.isArray(t)?t:[t],n={};for(const i of r){if(typeof i=="string"){n[e]=n[e]?n[e]:[],n[e].push(i||"");continue}if(!i["@language"]){n[e]=n[e]?n[e]:[],n[e].push(i["@value"]||"");continue}const s=i["@language"];n[s]=n[s]?n[s]:[],n[s].push(i["@value"]||"")}return n}function qn(t){if(Array.isArray(t))return qn(t.find(e=>typeof e=="string"));if(yo.indexOf(t)!==-1)return"level2";if(ho.indexOf(t)!==-1)return"level1";if(typeof t=="string")return t}function vo(t){const e=Array.isArray(t)?t:[t];for(const r of e)switch(r){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function go(t){switch(t){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}function lr(t){for(const e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}const mo=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function Ht(t){const e=t["@id"]||t.id;let r=t["@type"]||t.type;const n=t.profile||void 0,i=t["@context"]||void 0;if(n){const s=go(n);if(s)return s}if(i){const s=vo(i);if(s)return s}if(r){if(Array.isArray(r)){if(r.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(r.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";r=r[0]}for(const s of["sc","oa","dcterms","dctypes","iiif"])if(r.startsWith(`${s}:`)){r=r.slice(s.length+1);break}switch(r){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(r&&mo.indexOf(r)!==-1)return r;if(t.format){if(t.format.startsWith("image/"))return"Image";if(t.format.startsWith("text/")||t.format==="application/pdf")return"Text";if(t.format.startsWith("application/"))return"Dataset"}return e&&(e.endsWith(".jpg")||e.endsWith(".png")||e.endsWith(".jpeg"))?"Image":r||"unknown"}const xo=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function bo(t){const e=t.match(xo);return e?e[0]:t}function Ao(t,e="Rights/License",r="none"){let n=null;const i=[],s=Array.isArray(t)?t:[t];for(const a of s){const o=a?bo(a):void 0;if(o&&(o.indexOf("creativecommons.org")!==-1||o.indexOf("rightsstatements.org")!==-1)){o.startsWith("https://")?n=`http://${o.slice(8)}`:n=o;continue}o&&i.push({label:{[r]:[e]},value:{[r]:[o]}})}return[n,i]}const So=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function wo(t){if(t){const e=Array.isArray(t)?t:[t],r=[];for(const n of e)n==="http://iiif.io/api/presentation/2/context.json"&&r.push("http://iiif.io/api/presentation/3/context.json"),So.indexOf(n)===-1&&r.push(n);if(e.length)return r.length===1?r[0]:r}}function Co(t){return t?t.map(e=>({label:Ae(e.label),value:Ae(e.value)})):[]}let fr=0;function Vn(t,e){const r=encodeURI(t.id||t["@id"]||"").trim();return r&&e?`${r}/${e}`:r||(fr++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${fr}`)}function oe(t){const e=[...t.behavior||[]];t.viewingHint&&e.push(t.viewingHint);let r;return Array.isArray(t.motivation)?r=t.motivation.map(lr):t.motivation&&(r=lr(t.motivation)),{"@context":t["@context"]?wo(t["@context"]):void 0,id:(t["@id"]||Vn(t)).trim(),type:Ht(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:r,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function ce(t){const[e,r]=Ao(t.license),n=[...t.metadata?Co(t.metadata):[],...r];return{rights:e,metadata:n.length?n:void 0,label:t.label?Ae(t.label):void 0,requiredStatement:t.attribution?{label:Ae(Rt.attributionLabel),value:Ae(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?Ae(t.description):void 0,thumbnail:Mo(t.thumbnail)}}function Mo(t){return t&&(Array.isArray(t)?t:[t]).map(e=>typeof e=="string"?{id:e,type:"Image"}:(e.type==="unknown"&&(e.type="Image"),e))}function Ro(t){if(!t.within)return;const e=Array.isArray(t.within)?t.within:[t.within],r=[];for(const n of e)if(typeof n=="string"){if(n)switch(t["@type"]){case"sc:Manifest":r.push({id:n,type:"Collection"});break}}else n["@id"]&&r.push({id:n["@id"],type:Ht(n)});return r.length?r:void 0}function ve(t){const e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],r=t.contentLayer;return{provider:t.logo||e.length?[{id:Rt.providerId,type:"Agent",homepage:e.length?[e[0]]:void 0,logo:t.logo?Array.isArray(t.logo)?t.logo:[t.logo]:void 0,label:Ae(Rt.providerName)}]:void 0,partOf:Ro(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?to(t.service):void 0,supplementary:r?[r]:void 0}}function Io(t){return{chars:t.chars,format:t.format?t.format:void 0,language:t.language}}function ko(t){return ae({...oe(t),...ce(t),...ve(t),items:t.members})}function To(t){const e=[],r=[];let n;for(const s of t.sequences||[])s.canvases.length&&e.push(...s.canvases),s.behavior&&r.push(...s.behavior),s.startCanvas&&(n=s.startCanvas);const i=oe(t);return r.length&&(i.behavior?i.behavior.push(...r):i.behavior=r),ae({...i,...ce(t),...ve(t),start:n,items:e,structures:t.structures})}function jo(t){return ae({...oe(t),...ce(t),...ve(t),annotations:t.otherContent&&t.otherContent.length?t.otherContent:void 0,items:t.images&&t.images.length?[{id:Vn(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function Po(t){return ae({...oe(t),...ce(t),...ve(t),items:t.resources&&t.resources.length?t.resources:void 0})}function Eo(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[],startCanvas:t.startCanvas}}function Oo(t){function e(r){if(Array.isArray(r)){if(r.length>1)return{type:"List",items:r.map(e)};r=r[0]}if(typeof r=="string")return encodeURI(r).trim();if("@type"in r){let n;if(typeof r.full=="string")n=r.full;else if(r.full["@type"]==="dctypes:Image")n={id:r.full["@id"],type:"Image"};else if(r.full["@type"]==="sc:Canvas")n={id:r.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${r.full["@type"]}`);return{type:"SpecificResource",source:n,selector:kt(r.selector)}}else return encodeURI(r["@id"]).trim()}return ae({...oe(t),...ce(t),...ve(t),target:e(t.on),body:Array.isArray(t.resource)?t.resource.map(It):It(t.resource)})}function It(t){const e=t;return ae({...oe(e),...ce(e),...ve(e),...Io(e)})}function Lo(t){const e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),{...oe(t),...ce(t),items:e}}function Fo(t){return ae({...oe(t),...ce(t),...ve(t),items:t.members})}function $o(t){const{"@id":e,"@type":r,"@context":n,profile:i,...s}=t,a={};return e&&(a["@id"]=e),a["@type"]=Ht(t),a["@type"]==="unknown"&&(n&&n.length&&(a["@context"]=n),a["@type"]="Service"),i&&(a.profile=qn(i)),ae({...a,...s})}function Do(t){return ae({...oe(t),...ce(t),...ve(t)})}new Ut({collection:[ko],manifest:[To],canvas:[jo],annotationList:[Po],sequence:[Eo],annotation:[Oo],contentResource:[It],choice:[Lo],range:[Fo],service:[$o],layer:[Do]});function kt(t){if((Array.isArray(t["@type"])&&t["@type"].includes("oa:SvgSelector")||t["@type"]=="oa:SvgSelector")&&("chars"in t||"value"in t))return{type:"SvgSelector",value:"chars"in t?t.chars:t.value};if(t["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:t.value};if(t["@type"]==="oa:Choice")return[kt(t.default),...(Array.isArray(t.item)?t.item:[t.item]).map(kt)];if(t["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in t?t.region:void 0,rotation:"rotation"in t?t.rotation:void 0};throw new Error(`Unsupported selector type: ${t["@type"]}`)}var pr={exports:{}};(function(t,e){var r=Object.defineProperty,n=(s,a,o)=>a in s?r(s,a,{enumerable:!0,configurable:!0,writable:!0,value:o}):s[a]=o,i=(s,a,o)=>(n(s,typeof a!="symbol"?a+"":a,o),o);(function(s,a){a(e)})(Ea,function(s){const a="http://library.stanford.edu/iiif/image-api/compliance.html#level1",o="http://library.stanford.edu/iiif/image-api/compliance.html#level2",u="http://library.stanford.edu/iiif/image-api/conformance.html#level1",d="http://library.stanford.edu/iiif/image-api/conformance.html#level2",l="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",p="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",m="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",A="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",h="http://iiif.io/api/image/1/level1.json",x="http://iiif.io/api/image/1/profiles/level1.json",b="http://iiif.io/api/image/1/level2.json",S="http://iiif.io/api/image/1/profiles/level2.json",w="http://iiif.io/api/image/2/level1.json",M="http://iiif.io/api/image/2/profiles/level1.json",T="http://iiif.io/api/image/2/level2.json",F="http://iiif.io/api/image/2/profiles/level2.json",k="level1",O="level2",E="http://iiif.io/api/image/2/level1",R="http://iiif.io/api/image/2/level2",$=[E,R,a,o,u,d,l,p,m,A,h,x,b,S,w,M,T,F,k,O],X=["http://iiif.io/api/image/2/level0",E,R,"http://library.stanford.edu/iiif/image-api/compliance.html#level0",a,o,"http://library.stanford.edu/iiif/image-api/conformance.html#level0",u,d,"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",l,p,"http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",m,A,"http://iiif.io/api/image/1/level0.json","http://iiif.io/api/image/1/profiles/level0.json",h,x,b,S,"http://iiif.io/api/image/2/level0.json","http://iiif.io/api/image/2/profiles/level0.json",w,M,T,F,"level0",k,O],Y=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];class _{constructor(c,v={}){i(this,"traversals"),i(this,"options"),this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...c},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...v}}static all(c){return new _({collection:[c],manifest:[c],canvas:[c],annotationList:[c],sequence:[c],annotation:[c],contentResource:[c],choice:[c],range:[c],service:[c],layer:[c]})}traverseCollection(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(c))),this.traversals.collection)}traverseCollectionItems(c){if(this.options.mergeMemberProperties){const v=[...(c.manifests||[]).map(C=>typeof C=="string"?{"@id":C,"@type":"sc:Manifest"}:C),...(c.collections||[]).map(C=>typeof C=="string"?{"@id":C,"@type":"sc:Collection"}:C),...c.members||[]];delete c.collections,delete c.manifests,c.members=v}return c.manifests&&(c.manifests=c.manifests.map(v=>this.traverseManifest(typeof v=="string"?{"@id":v,"@type":"sc:Manifest"}:v))),c.collections&&(c.collections=c.collections.map(v=>this.traverseCollection(typeof v=="string"?{"@id":v,"@type":"sc:Collection"}:v))),c.members&&(c.members=c.members.map(v=>typeof v=="string"?v:this.traverseUnknown(v))),c}traverseManifest(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(c))),this.traversals.manifest)}traverseManifestItems(c){return c.sequences&&(c.sequences=c.sequences.map(v=>this.traverseSequence(v))),c.structures&&(c.structures=c.structures.map(v=>this.traverseRange(v))),c}traverseSequence(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(c))),this.traversals.sequence)}traverseSequenceItems(c){return c.canvases&&(c.canvases=c.canvases.map(v=>this.traverseCanvas(v))),c}traverseCanvas(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(c))),this.traversals.canvas)}traverseCanvasItems(c){return c.images&&(c.images=c.images.map(v=>this.traverseAnnotation(v))),c.otherContent&&(c.otherContent=c.otherContent.map(v=>this.traverseAnnotationList(v))),c}traverseRange(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(c))),this.traversals.range)}traverseRangeItems(c){if(this.options.mergeMemberProperties){const v=[...(c.ranges||[]).map(C=>typeof C=="string"?{"@id":C,"@type":"sc:Range"}:C),...(c.canvases||[]).map(C=>typeof C=="string"?{"@id":C,"@type":"sc:Canvas"}:C),...c.members||[]];delete c.ranges,delete c.canvases,c.members=v.length?v.map(C=>this.traverseUnknown(C)):void 0}return c}traverseAnnotationList(c){const v=typeof c=="string"?{"@id":c,"@type":"sc:AnnotationList"}:c;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(v)),this.traversals.annotationList)}traverseAnnotationListItems(c){return c.resources&&(c.resources=c.resources.map(v=>this.traverseAnnotation(v))),c}traverseAnnotation(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(c))),this.traversals.annotation)}traverseAnnotationItems(c){return c.resource&&(Array.isArray(c.resource)?c.resource=c.resource.map(v=>this.traverseContentResource(v)):c.resource=this.traverseContentResource(c.resource)),c.on,c}traverseLayer(c){return this.traverseType(this.traverseLinking(this.traverseLayerItems(c)),this.traversals.layer)}traverseLayerItems(c){return c.otherContent&&(c.otherContent=c.otherContent.map(v=>this.traverseAnnotationList(v))),c}traverseChoice(c){return this.traverseType(this.traverseChoiceItems(c),this.traversals.choice)}traverseChoiceItems(c){return c.default&&c.default!=="rdf:nil"&&(c.default=this.traverseContentResource(c.default)),c.item&&c.item!=="rdf:nil"&&(c.item=c.item.map(v=>this.traverseContentResource(v))),c}traverseService(c){return this.traverseType(this.traverseLinking(c),this.traversals.service)}traverseContentResource(c){return c["@type"]==="oa:Choice"?this.traverseChoice(c):this.traverseType(this.traverseDescriptive(this.traverseLinking(c)),this.traversals.contentResource)}traverseUnknown(c){if(!c["@type"]||typeof c=="string")return c;switch(function(v){if(v==null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(v))throw new Error("Array is not a valid entity");if(typeof v!="object")throw new Error(typeof v+" is not a valid entity");if(typeof v["@type"]=="string"){const C=Y.indexOf(v["@type"]);if(C!==-1)return Y[C]}if(v.profile)return"Service";if(v.format||v["@type"])return"ContentResource";throw new Error("Resource type is not known")}(c)){case"sc:Collection":return this.traverseCollection(c);case"sc:Manifest":return this.traverseManifest(c);case"sc:Canvas":return this.traverseCanvas(c);case"sc:Sequence":return this.traverseSequence(c);case"sc:Range":return this.traverseRange(c);case"oa:Annotation":return this.traverseAnnotation(c);case"sc:AnnotationList":return this.traverseAnnotationList(c);case"sc:Layer":return this.traverseLayer(c);case"Service":return this.traverseService(c);case"oa:Choice":return this.traverseChoice(c);case"ContentResource":return this.traverseContentResource(c)}return c.profile?this.traverseService(c):c}traverseImageResource(c){const v=Array.isArray(c),C=Array.isArray(c)?c:[c],L=[];for(const j of C)typeof j=="string"?L.push(this.traverseContentResource({"@id":j,"@type":"dctypes:Image"})):L.push(this.traverseContentResource(j));return v||this.options.convertPropsToArray?L:L[0]}traverseDescriptive(c){return c.thumbnail&&(c.thumbnail=this.traverseImageResource(c.thumbnail)),c.logo&&(c.logo=this.traverseImageResource(c.logo)),c}traverseOneOrMoreServices(c){const v=Array.isArray(c),C=Array.isArray(c)?c:[c],L=[];for(const j of C)L.push(this.traverseService(j));return v||this.options.convertPropsToArray?L:L[0]}traverseLinking(c){return c.related&&(c.related=this.traverseOneOrManyType(c.related,this.traversals.contentResource)),c.rendering&&(c.rendering=this.traverseOneOrManyType(c.rendering,this.traversals.contentResource)),c.service&&(c.service=this.traverseOneOrMoreServices(c.service)),c.seeAlso&&(c.seeAlso=this.traverseOneOrManyType(c.seeAlso,this.traversals.contentResource)),c.within&&(typeof c.within=="string"||(c.within=this.traverseOneOrManyType(c.within,this.traversals.contentResource))),c.startCanvas&&(typeof c.startCanvas=="string"?c.startCanvas=this.traverseType({"@id":c.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):c.startCanvas&&this.traverseType(c.startCanvas,this.traversals.canvas)),c.contentLayer&&(typeof c.contentLayer=="string"?c.contentLayer=this.traverseLayer({"@id":c.contentLayer,"@type":"sc:Layer"}):c.contentLayer=this.traverseLayer(c.contentLayer)),c}traverseOneOrManyType(c,v){if(!Array.isArray(c)){if(!this.options.convertPropsToArray)return this.traverseType(c,v);c=[c]}return c.map(C=>this.traverseType(C,v))}traverseType(c,v){return v.reduce((C,L)=>{const j=L(C);return j!==void 0||this.options.allowUndefinedReturn?j:C},c)}}function H(f){for(const c in f)f[c]!==void 0&&f[c]!==null||delete f[c];return f}const J="Attribution",ee="http://example.org/provider",ge="Unknown";function P(f,c="none"){if(!f)return{};const v=Array.isArray(f)?f:[f],C={};for(const L of v){if(typeof L=="string"){C[c]=C[c]?C[c]:[],C[c].push(L||"");continue}if(!L["@language"]){C[c]=C[c]?C[c]:[],C[c].push(L["@value"]||"");continue}const j=L["@language"];C[j]=C[j]?C[j]:[],C[j].push(L["@value"]||"")}return C}function N(f){return Array.isArray(f)?N(f.find(c=>typeof c=="string")):X.indexOf(f)!==-1?"level2":$.indexOf(f)!==-1?"level1":typeof f=="string"?f:void 0}function G(f){for(const c of["sc","oa","dcterms","dctypes","iiif"])if(f.startsWith(`${c}:`))return f.slice(c.length+1);return f}const ue=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function nt(f){const c=f["@id"]||f.id;let v=f["@type"]||f.type;const C=f.profile||void 0,L=f["@context"]||void 0;if(C){const j=function(B){switch(B){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}(C);if(j)return j}if(L){const j=function(B){const Ve=Array.isArray(B)?B:[B];for(const _e of Ve)switch(_e){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}(L);if(j)return j}if(v){if(Array.isArray(v)){if(v.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(v.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";v=v[0]}for(const j of["sc","oa","dcterms","dctypes","iiif"])if(v.startsWith(`${j}:`)){v=v.slice(j.length+1);break}switch(v){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(v&&ue.indexOf(v)!==-1)return v;if(f.format){if(f.format.startsWith("image/"))return"Image";if(f.format.startsWith("text/")||f.format==="application/pdf")return"Text";if(f.format.startsWith("application/"))return"Dataset"}return c&&(c.endsWith(".jpg")||c.endsWith(".png")||c.endsWith(".jpeg"))?"Image":v||"unknown"}const Mi=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Ri(f){const c=f.match(Mi);return c?c[0]:f}const Ii=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function ki(f){if(f){const c=Array.isArray(f)?f:[f],v=[];for(const C of c)C==="http://iiif.io/api/presentation/2/context.json"&&v.push("http://iiif.io/api/presentation/3/context.json"),Ii.indexOf(C)===-1&&v.push(C);if(c.length)return v.length===1?v[0]:v}}let zt=0;function Wt(f,c){const v=encodeURI(f.id||f["@id"]||"").trim();return v&&c?`${v}/${c}`:v||(zt++,`http://example.org/${f["@type"]}${c?`/${c}`:""}/${zt}`)}function ne(f){const c=[...f.behavior||[]];let v;return f.viewingHint&&c.push(f.viewingHint),Array.isArray(f.motivation)?v=f.motivation.map(G):f.motivation&&(v=G(f.motivation)),{"@context":f["@context"]?ki(f["@context"]):void 0,id:(f["@id"]||Wt(f)).trim(),type:nt(f),behavior:c.length?c:void 0,height:f.height?f.height:void 0,width:f.width?f.width:void 0,motivation:v,viewingDirection:f.viewingDirection,profile:f.profile,format:f.format?f.format:void 0,duration:void 0,timeMode:void 0}}function ie(f){const[c,v]=function(j,B="Rights/License",Ve="none"){let _e=null;const Qt=[],Oi=Array.isArray(j)?j:[j];for(const Yt of Oi){const fe=Yt?Ri(Yt):void 0;!fe||fe.indexOf("creativecommons.org")===-1&&fe.indexOf("rightsstatements.org")===-1?fe&&Qt.push({label:{[Ve]:[B]},value:{[Ve]:[fe]}}):_e=fe.startsWith("https://")?`http://${fe.slice(8)}`:fe}return[_e,Qt]}(f.license),C=[...f.metadata?(L=f.metadata,L?L.map(j=>({label:P(j.label),value:P(j.value)})):[]):[],...v];var L;return{rights:c,metadata:C.length?C:void 0,label:f.label?P(f.label):void 0,requiredStatement:f.attribution?{label:P(J),value:P(f.attribution)}:void 0,navDate:f.navDate,summary:f.description?P(f.description):void 0,thumbnail:Ti(f.thumbnail)}}function Ti(f){return f&&(Array.isArray(f)?f:[f]).map(c=>typeof c=="string"?{id:c,type:"Image"}:(c.type==="unknown"&&(c.type="Image"),c))}function ji(f){if(!f.within)return;const c=Array.isArray(f.within)?f.within:[f.within],v=[];for(const C of c)typeof C=="string"?C&&f["@type"]==="sc:Manifest"&&v.push({id:C,type:"Collection"}):C["@id"]&&v.push({id:C["@id"],type:nt(C)});return v.length?v:void 0}function le(f){const c=f.related?Array.isArray(f.related)?f.related:[f.related]:[],v=f.contentLayer;return{provider:f.logo||c.length?[{id:ee,type:"Agent",homepage:c.length?[c[0]]:void 0,logo:f.logo?Array.isArray(f.logo)?f.logo:[f.logo]:void 0,label:P(ge)}]:void 0,partOf:ji(f),rendering:f.rendering,seeAlso:f.seeAlso,start:f.startCanvas,service:f.service?(C=f.service,Array.isArray(C)?C:C?[C]:[]):void 0,supplementary:v?[v]:void 0};var C}function it(f){const c=f;return H({...ne(c),...ie(c),...le(c),...(v=c,{chars:v.chars,format:v.format?v.format:void 0,language:v.language})});var v}const Pi=new _({collection:[function(f){return H({...ne(f),...ie(f),...le(f),items:f.members})}],manifest:[function(f){const c=[],v=[];let C;for(const j of f.sequences||[])j.canvases.length&&c.push(...j.canvases),j.behavior&&v.push(...j.behavior),j.startCanvas&&(C=j.startCanvas);const L=ne(f);return v.length&&(L.behavior?L.behavior.push(...v):L.behavior=v),H({...L,...ie(f),...le(f),start:C,items:c,structures:f.structures})}],canvas:[function(f){return H({...ne(f),...ie(f),...le(f),annotations:f.otherContent&&f.otherContent.length?f.otherContent:void 0,items:f.images&&f.images.length?[{id:Wt(f,"annotation-page"),type:"AnnotationPage",items:f.images}]:void 0})}],annotationList:[function(f){return H({...ne(f),...ie(f),...le(f),items:f.resources&&f.resources.length?f.resources:void 0})}],sequence:[function(f){return f.canvases&&f.canvases.length!==0?{canvases:f.canvases,behavior:f.viewingHint?[f.viewingHint]:[],startCanvas:f.startCanvas}:{canvases:[],behavior:[]}}],annotation:[function(f){return H({...ne(f),...ie(f),...le(f),target:function c(v){if(Array.isArray(v)){if(v.length>1)return{type:"List",items:v.map(c)};v=v[0]}if(typeof v=="string")return encodeURI(v).trim();if("@type"in v){let C;if(typeof v.full=="string")C=v.full;else if(v.full["@type"]==="dctypes:Image")C={id:v.full["@id"],type:"Image"};else{if(v.full["@type"]!=="sc:Canvas")throw new Error(`Unsupported source type on annotation: ${v.full["@type"]}`);C={id:v.full["@id"],type:"Canvas"}}return{type:"SpecificResource",source:C,selector:st(v.selector)}}return encodeURI(v["@id"]).trim()}(f.on),body:Array.isArray(f.resource)?f.resource.map(it):it(f.resource)})}],contentResource:[it],choice:[function(f){const c=[];return f.default&&f.default!=="rdf:nil"&&c.push(f.default),f.item&&f.item!=="rdf:nil"&&c.push(...f.item),{...ne(f),...ie(f),items:c}}],range:[function(f){return H({...ne(f),...ie(f),...le(f),items:f.members})}],service:[function(f){const{"@id":c,"@type":v,"@context":C,profile:L,...j}=f,B={};return c&&(B["@id"]=c),B["@type"]=nt(f),B["@type"]==="unknown"&&(C&&C.length&&(B["@context"]=C),B["@type"]="Service"),L&&(B.profile=N(L)),H({...B,...j})}],layer:[function(f){return H({...ne(f),...ie(f),...le(f)})}]});function st(f){if((Array.isArray(f["@type"])&&f["@type"].includes("oa:SvgSelector")||f["@type"]=="oa:SvgSelector")&&("chars"in f||"value"in f))return{type:"SvgSelector",value:"chars"in f?f.chars:f.value};if(f["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:f.value};if(f["@type"]==="oa:Choice")return[st(f.default),...(Array.isArray(f.item)?f.item:[f.item]).map(st)];if(f["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in f?f.region:void 0,rotation:"rotation"in f?f.rotation:void 0};throw new Error(`Unsupported selector type: ${f["@type"]}`)}const Ei=function(f){return f&&f["@context"]&&(f["@context"]==="http://iiif.io/api/presentation/2/context.json"||f["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")!==-1||f["@context"]==="http://www.shared-canvas.org/ns/context.json")||f["@context"]==="http://iiif.io/api/image/2/context.json"?Pi.traverseUnknown(f):f};s.upgrade=Ei,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})})})(pr,pr.exports);function qo(t){return t.type==="SpecificResource"?[t.source,{selector:t.selector}]:[t,{selector:null}]}function Nt(t,e){const{selector:r,source:n}=Te(e);if(n.id!==t.id)return[null,n];const i={type:"BoxSelector",spatial:{x:0,y:0,width:Number(t.width),height:Number(t.height)}};return[r?r.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:r.temporal,spatial:i.spatial}:r:null,n]}const _n={makeChoice:()=>{}},Ge={type:"unknown"},D=t=>({type:"unknown",reason:t,annotations:{pages:[]}}),Un=(t,e)=>({type:"empty",width:t,height:e,annotations:{pages:[]},image:null,images:[]});function Vo(t,e){var n;const r=(n=t==null?void 0:t.iiif)==null?void 0:n.meta[e];return r?r.annotationPageManager:null}function _o(t,e){return U(r=>{const n=[];if(!t)return n;const i=Object.keys(r.iiif.entities.AnnotationPage);for(const s of i)if(!e||e.indexOf(s)!==-1){const a=Vo(r,s);a&&a.views&&a.views[t]&&n.push(s)}return n},[t,e])}function Hn({canvas:t,manifest:e,all:r,canvases:n}){const i=[];if(e)for(const s of e.annotations)i.indexOf(s.id)===-1&&i.push(s.id);if(r){if(n&&n.length)for(const s of n)for(const a of s.annotations)i.indexOf(a.id)===-1&&i.push(a.id)}else if(t)for(const s of t.annotations)i.indexOf(s.id)===-1&&i.push(s.id);return i}function Uo(t,e){var n;const r=(n=t==null?void 0:t.iiif)==null?void 0:n.meta[e];return r?r.annotationPageManager:null}function Nn(t,e={}){const r=V(),n=ye(),i=re(),s=Et(),a=y.useMemo(()=>Hn({all:e.all,manifest:n,canvas:i,canvases:s}),[e.all,i,s,n]),o=_o(t,e.all?void 0:a),u=y.useCallback(l=>{t&&r.setMetaValue([l,"annotationPageManager","views"],p=>p&&!p[t]?p:{...p||{},[t]:!1})},[t,r]),d=y.useCallback((l,p={})=>{if(!t)return;const m=r.getState(),A=[];if(p!=null&&p.deselectOthers){const h=Object.keys(m.iiif.entities.AnnotationPage);for(const x of h){const b=Uo(m,x);b&&b.views&&b.views[t]&&A.push(x)}}for(const h of A)u(h);r.setMetaValue([l,"annotationPageManager","views"],h=>h&&h[t]?h:{...h||{},[t]:!0})},[t,u,r]);return{availablePageIds:a,enabledPageIds:o,setPageEnabled:d,setPageDisabled:u}}function Bn(t,e){return U((r,n)=>n.get(t.map(i=>({id:i,type:e}))),[t,e])}const zn=y.createContext(new Se.ImageServiceLoader);function Xe(){return y.useContext(zn)}function Wn(){const t=Xe(),[e,r]=y.useState({}),n=y.useRef(!1);return y.useEffect(()=>()=>{n.current=!0},[]),[y.useCallback((s,{height:a,width:o})=>{if(s){const u=s.id||s["@id"],d=t.loadServiceSync({id:u,width:s.width||o,height:s.height||a,source:s});d?s=d:e[u]||(n.current||r(l=>({...l,[u]:"loading"})),t.loadService({id:u,width:s.width||o,height:s.height||a}).then(()=>{n.current||r(l=>({...l,[u]:"done"}))}))}return s},[t,e]),e]}function et(t={}){const e=Vt(),r=re(t.canvasId?{id:t.canvasId}:void 0);return U((n,i)=>{if(!r)return[];if(e&&t.enableSingleAnnotation)return[e];const s=i.get(r.items),a=[];for(const o of s)a.push(...i.get(o.items));return a},[r])}function Ho(t){return t.type==="SpecificResource"?[t.source,{selector:t.selector}]:[t,{selector:null}]}const Be={},Qn={get(t){return t},setMetaValue([t,e,r],n){const i=Qn.getResourceMeta(t,e),s=i?i[r]:void 0,a=typeof n=="function"?n(s):n;Be[t]={...Be[t]||{},[e]:{...(Be[t]||{})[e]||{},[r]:a}}},getResourceMeta:(t,e)=>{const r=Be[t];if(r)return e?r[e]:r}};function No(t=Qn){function e(i){const s=i?typeof i=="string"?t.get(i):i:null;if(!s)return[];const a=t.get(s.items,{parent:s}),o=[];for(const u of a)o.push(...t.get(u.items,{parent:u}));return o}function r(i,s=[]){const a=Array.isArray(i)?i:e(i),o=[];let u=null;const d=[];for(const l of a){if(l.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const p=Array.from(Array.isArray(l.body)?l.body:[l.body]);for(const m of p){const[A,{selector:h}]=Ho(m),x=t.get(A),b=(x.type||"unknown").toLowerCase();if(b==="choice"){const S=t.get(x.items,{parent:x.id}),w=s.length?s.map(M=>S.find(T=>T.id===M)).filter(Boolean):[S[0]];w.length===0&&w.push(S[0]),u={type:"single-choice",items:S.map(M=>({id:M.id,label:M.label,selected:w.indexOf(M)!==-1})),label:A.label},p.push(...w);continue}o.indexOf(b)===-1&&o.push(b),d.push({type:b,annotationId:l.id,resource:x,target:l.target,selector:h})}}return{types:o,items:d,choice:u}}function n(i){const{choice:s}=r(i);return s}return{getAllPaintingAnnotations:e,getPaintables:r,extractChoices:n}}function Yn(t,e=[]){const r=V(),n=y.useMemo(()=>No(r),[]),i=et({enableSingleAnnotation:t==null?void 0:t.enableSingleAnnotation}),[s,a]=y.useState((t==null?void 0:t.defaultChoices)||[]),o=y.useMemo(()=>n.getPaintables(i,s),[r,i,s,...e]),d={makeChoice:y.useCallback((l,{deselectOthers:p=!0,deselect:m=!1}={})=>{if(o.choice){if(o.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");a(A=>{if(m){const x=A.filter(b=>b!==l);if(x.length===0){const b=o.items[0].resource.id;return b?[b]:[]}return x}if(p)return[l];const h=[...A];if(h.length===0&&o.items.length){const x=o.items[0].resource.id;x&&h.push(x)}return A.indexOf(l)!==-1?A:[...A,l]})}},[o.choice])};return[o,d]}const Bo=["model/gltf-binary"];function Gn(t,e){const n=e.items[0].resource;return n.format?Bo.indexOf(n.format)===-1?D(`3D format: ${n.format} is unsupported`):{type:"3d-model",model:n}:D("Unknown format")}function zo(t,e){var n;if(!t.duration)return D("No duration on canvas");if(e.items.length>1)return D("Only one audio source supported");const r=(n=e.items[0])==null?void 0:n.resource;return r?r.format?{type:"media",media:{annotationId:e.items[0].annotationId,duration:t.duration,url:r.id,type:"Sound",target:{type:"TemporalSelector",temporal:{startTime:0,endTime:t.duration}},format:r.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:t.duration}}},annotations:{pages:[]}}:D("Audio does not have format"):D("Unknown audio")}function Jn(t,e,r){const n=[];for(const i of e.items){const s=i.resource&&i.resource.type==="SpecificResource"?i.resource.source:i.resource;if(!s.id)return D("No resource Identifier");let a;if(s.service){const A=Se.getImageServices(s);A[0]&&(a=r(A[0],t))}const o={type:"BoxSelector",spatial:{x:0,y:0,width:Number(t.width),height:Number(t.height)}},[u,d]=Nt(t,i.target);if(d.id!==t.id)continue;i.resource.width&&i.resource.height&&(i.resource.width,i.resource.height);let l=i.resource.type==="SpecificResource"?de(i.resource):null;if(i.selector){const A=de({type:"SpecificResource",source:i.resource,selector:i.selector});A&&(l=A)}const p=l&&l.selector&&(l.selector.type==="BoxSelector"||l.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:l.selector.spatial.x,y:l.selector.spatial.y,width:l.selector.spatial.width,height:l.selector.spatial.height}}:void 0;a&&!a.id&&(a.id=a["@id"]);const m={id:s.id,type:"Image",annotationId:i.annotationId,width:Number(u||p?s.width:t.width),height:Number(u||p?s.height:t.height),service:a,sizes:a&&a.sizes?a.sizes:s.width&&s.height?[{width:s.width,height:s.height}]:[],target:u&&u.type!=="PointSelector"?u:o,selector:p};n.push(m)}return{type:"images",image:n[0],images:n,choice:e.choice}}function Kn(t,e={},r){const n=t.language||r||"none";switch(t.type){case"TextualBody":{typeof t.value<"u"&&(e[n]=t.value);break}case"List":case"Composite":case"Choice":t.items&&t.items.forEach(i=>Kn(i,e,n))}return e}function Zn(t,e){const r=[];return e.items.forEach(n=>{if(n.resource){const[i]=Nt(t,n.target);r.push({annotationId:n.annotationId,text:Kn(n.resource),target:i})}}),{type:"textual-content",items:r}}const Wo=/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?vi?=|&vi?=))([^#&?]*).*/;function Xn(t,e){var a;const r=e.items.filter(o=>o.type==="video");if(!t.duration)return D("No duration on canvas");if(r.length>1)return D("Only one video source supported");const n=(a=r[0])==null?void 0:a.resource,i=!!(n.service||[]).find(o=>(o.profile||"").includes("youtube.com"));if(!n)return D("Unknown video");if((!n.format||n.format==="text/html")&&!i)return D("Video does not have format");const s={annotationId:e.items[0].annotationId,duration:t.duration,url:n.id,type:"Video",items:[],target:{type:"TemporalSelector",temporal:{startTime:0,endTime:t.duration}},format:n.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:t.duration}}};if(i){s.type="VideoYouTube";const o=n.id.match(Wo);if(!o[1])return D("Video is not known youtube video");s.youTubeId=o[1]}return{type:"media",media:s,annotations:{pages:[]}}}function ei({canvas:t,paintables:e,supports:r,loadImageService:n}){if(!t)return console.log("No canvas"),Ge;if(e.types.length===0)return r.indexOf("empty")!==-1?Un(t.width,t.height):(console.log("No paintables"),Ge);if(e.types.length!==1)if(e.types.length===2&&e.types.indexOf("text")!==-1)e.types=e.types.filter(s=>s!=="text");else return r.indexOf("complex-timeline")===-1?D("Complex timeline not supported"):D("ComplexTimelineStrategy not yet supported");const i=e.types[0];return i==="image"?r.indexOf("images")===-1?D("Image not supported"):Jn(t,e,n):i==="Model"||i==="model"?r.indexOf("3d-model")===-1?D("3D not supported"):Gn(t,e):i==="textualbody"?r.indexOf("textual-content")===-1?D("Textual content not supported"):Zn(t,e):i==="sound"||i==="audio"?r.indexOf("media")===-1?D("Media not supported"):zo(t,e):i==="video"?r.indexOf("media")===-1?D("Media not supported"):Xn(t,e):Ge}function ti(t){const e=ye(),r=re(),n=V(),[i,s]=Wn(),{enabledPageIds:a}=Nn((t==null?void 0:t.annotationPageManagerId)||(e==null?void 0:e.id)||(r==null?void 0:r.id),{all:!1}),o=Bn(a,"AnnotationPage"),u=(t==null?void 0:t.strategies)||["empty","images","media","textual-content","complex-timeline"],[d,l]=Yn(t,[s]),p=y.useMemo(()=>ei({canvas:r,paintables:d,supports:u,loadImageService:i}),[r,d,n,l.makeChoice]);return y.useMemo(()=>p.type==="unknown"?[p,_n]:[{...p,annotations:{pages:o}},l],[p,o])}const ri=(t,e=[])=>{const r=V();y.useEffect(()=>{t(r)},[r,...e])},ze={},ni={get(t){return t},setMetaValue([t,e,r],n){const i=ni.getResourceMeta(t,e),s=i?i[r]:void 0,a=typeof n=="function"?n(s):n;ze[t]={...ze[t]||{},[e]:{...(ze[t]||{})[e]||{},[r]:a}}},getResourceMeta:(t,e)=>{const r=ze[t];if(r)return e?r[e]:r}},Qo=new Se.ImageServiceLoader;function Yo(t=ni,e={}){const r=e.imageServiceLoader||Qo;async function n(i,s,a=!1,o=[],u){const d=()=>r.getThumbnailFromResource(void 0,s,a,o);if(!i)return await r.getThumbnailFromResource(void 0,s,a,o);if(typeof i=="string"){const p=Se.getFixedSizeFromImage(i);return p&&o.push(p),await r.getThumbnailFromResource(void 0,s,a,o)}const l=t.get(i,{skipSelfReturn:!1});if(typeof l=="string")return{best:Se.getFixedSizeFromImage(l),fallback:[],log:[]};if(!l)return await d();switch(await(async p=>{if(p&&p.thumbnail&&p.thumbnail.length){const m=t.get(p.thumbnail[0]),A=await r.getImageCandidates(m,a);A&&A.length&&o.push(...A)}})(l),l.type){case"Annotation":{const p=Array.isArray(l.body)?l.body:[l.body],m=t.get(p[0]);return u&&!m.width&&(m.width=u.width,m.height=u.height),await r.getThumbnailFromResource(m,s,a,o)}case"Canvas":{const p=l;return n(p.items[0],s,a,o,{width:p.width,height:p.height})}case"AnnotationPage":return n(l.items[0],s,a,o,u);case"Choice":{const p=l;return!p.items||p.items[0]?await d():n(p.items[0],s,a,o,u)}case"Collection":{const p=l.items[0];return p?n(p,s,a,o,u):await d()}case"Manifest":{const p=l.items[0];return p?n(p,s,a,o,u):await d()}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return u&&!l.width&&(l.width=u.width,l.height=u.height),r.getThumbnailFromResource(l,s,a,o)}return await d()}return{getBestThumbnailAtSize:n}}function ii(t,e,{canvasId:r,manifestId:n}={}){const i=V(),s=Xe(),a=y.useMemo(()=>Yo(i,{imageServiceLoader:s}),[i,s]),[o,u]=y.useState(),d=ye(n?{id:n}:void 0),l=re(r?{id:r}:void 0),p=l||d,m=y.useRef(!1);if(y.useEffect(()=>(m.current=!1,()=>{m.current=!0}),[]),!p)throw new Error("Must be called under a manifest or canvas context.");return ri(A=>{a.getBestThumbnailAtSize(p,t,e).then(h=>{h.best&&!m.current&&u(h.best)})},[p]),o}function Go(t){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:t}}function Jo(t,e){switch(e.type){case"FINISHED":return{...t,isFinished:!0,isPlaying:!1,playRequested:!1};case"PLAY_PAUSE":return{...t,isFinished:!1,isPlaying:!t.isPlaying};case"PLAY_REQUESTED":return{...t,isFinished:!1,playRequested:!0};case"PAUSE":return{...t,isPlaying:!1};case"PLAY":return{...t,isFinished:!1,playRequested:!1,isPlaying:!0};case"MUTE":return{...t,isMuted:!0};case"SET_VOLUME":return{...t,volume:e.volume,isMuted:e.volume===0};case"TOGGLE_MUTE":return{...t,isMuted:!t.isMuted};case"UNMUTE":return{...t,isMuted:!1}}return t}function si(t){const e=Math.round(t);return`${Math.floor(e/60)}:${`${e%60}`.padStart(2,"0")}`}function tt(t){const[e,r]=y.useReducer(Jo,Go(t.duration)),n=y.useRef(null),i=y.useRef(null),s=y.useRef(null),a=y.useRef(!1),o=y.useCallback(()=>{i.current&&n.current&&(i.current.innerHTML=si(n.current.currentTime),s.current&&(s.current.style.width=`${n.current.currentTime/t.duration*100}%`),a.current!==n.current.muted&&(a.current=n.current.muted,r(n.current.muted?{type:"MUTE"}:{type:"UNMUTE"})))},[t.duration]),u=y.useCallback(()=>{n.current&&(r({type:"PLAY_REQUESTED"}),n.current.play().then(()=>{r({type:"PLAY"})}),o())},[o]),d=y.useCallback(()=>{n.current&&(n.current.duration>0&&n.current.paused?u():l())},[o]),l=y.useCallback(()=>{n.current&&(n.current.pause(),r({type:"PAUSE"}),o())},[o]),p=y.useCallback(()=>{n.current&&(n.current.muted=!n.current.muted,r(n.current.muted?{type:"MUTE"}:{type:"UNMUTE"}))},[]),m=y.useCallback(()=>{n.current&&(n.current.muted=!0,r({type:"MUTE"}))},[]),A=y.useCallback(()=>{n.current&&(n.current.muted=!1,r({type:"UNMUTE"}))},[]),h=y.useCallback(S=>{n.current&&(n.current.muted=!1,n.current.volume=S/100,r({type:"SET_VOLUME",volume:S}))},[]),x=y.useCallback(S=>{n.current&&(n.current.currentTime=Math.max(0,Math.min(S*t.duration,t.duration)),o())},[]),b=y.useCallback(S=>{n.current&&(n.current.currentTime=Math.max(0,Math.min(S,t.duration)),o())},[]);return y.useEffect(()=>{const S=setInterval(()=>{o()},350);return()=>clearInterval(S)},[o,t.duration]),y.useEffect(()=>{const S=()=>{r({type:"FINISHED"})},w=n.current;return w==null||w.addEventListener("ended",S),()=>w==null?void 0:w.removeEventListener("ended",S)},[]),[{element:n,currentTime:i,progress:s},e,{play:u,pause:l,playPause:d,mute:m,unmute:A,toggleMute:p,setVolume:h,setDurationPercent:x,setTime:b}]}const ai=y.createContext(null),oi=y.createContext(null),ci=y.createContext(null);function Ko(){const t=y.useContext(ai);if(!t)throw new Error("Ctx not found");return t}function Zo(){const t=y.useContext(oi);if(!t)throw new Error("Ctx not found");return t}function Xo(){const t=y.useContext(ci);if(!t)throw new Error("Ctx not found");return t}function Bt({actions:t,state:e,children:r,currentTime:n,progress:i,element:s}){return g.jsx(ci.Provider,{value:{currentTime:n,progress:i,element:s},children:g.jsx(oi.Provider,{value:t,children:g.jsx(ai.Provider,{value:e,children:r})})})}function ui({media:t,children:e}){const[{element:r,currentTime:n,progress:i},s,a]=tt({duration:t.duration});return g.jsxs(Bt,{state:s,actions:a,currentTime:n,progress:i,element:r,children:[g.jsx("audio",{ref:r,src:t.url}),e]})}function li({media:t,mediaControlsDeps:e,children:r}){return Ie("portal","audio",ui,{media:t,children:r},[t,...e||[]]),null}function fi({element:t,media:e,playPause:r}){return g.jsxs("div",{className:"video-container",part:"video-container",onClick:r,children:[g.jsx("style",{children:`
66
66
  .video-container {
67
67
  position: absolute;
68
68
  top: 0;
@@ -75,7 +75,7 @@
75
75
  justify-content: center;
76
76
  pointer-events: visible;
77
77
  }
78
- `}),m.jsx("video",{ref:e,src:t.url,style:{width:"100%",objectFit:"contain"}})]})}function ci({media:e,mediaControlsDeps:t,children:r}){const[{element:n,currentTime:i,progress:s},a,o]=tt({duration:e.duration});return Ie("overlay","video-element",oi,{element:n,media:e,playPause:o.playPause}),Ie("portal","custom-controls",Nt,{state:a,actions:o,currentTime:i,progress:s,element:n,children:r},[i,a,e,...t||[]]),null}function ui({model:e}){return m.jsxs(m.Fragment,{children:[m.jsx("style",{children:`
78
+ `}),g.jsx("video",{ref:t,src:e.url,style:{width:"100%",objectFit:"contain"}})]})}function pi({media:t,mediaControlsDeps:e,children:r}){const[{element:n,currentTime:i,progress:s},a,o]=tt({duration:t.duration});return Ie("overlay","video-element",fi,{element:n,media:t,playPause:o.playPause}),Ie("portal","custom-controls",Bt,{state:a,actions:o,currentTime:i,progress:s,element:n,children:r},[i,a,t,...e||[]]),null}function di({model:t}){return g.jsxs(g.Fragment,{children:[g.jsx("style",{children:`
79
79
  .model-container {
80
80
  position: absolute;
81
81
  top: 0;
@@ -88,9 +88,9 @@
88
88
  justify-content: center;
89
89
  pointer-events: visible;
90
90
  }
91
- `}),m.jsx("div",{className:"model-container",children:m.jsx("model-viewer",{"interaction-prompt":"none",style:{width:"100%",height:"100%"},"camera-controls":"","ar-status":"not-presenting",src:e.id})})]})}function li({model:e,name:t}){return Ie("overlay",`model-${t}`,ui,{model:e},[e]),null}function fi({style:e}){const t=re();return!t||!t.height||!t.width?null:m.jsx("box",{interactive:!1,target:{x:0,y:0,width:Number(t.width),height:Number(t.height)},style:e})}const pi=v.createContext("en");function Zo(e){return m.jsx(pi.Provider,{value:e.language,children:e.children})}function rt(){return v.useContext(pi)}function pr(e){return e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):e}function di({as:e,language:t,children:r,viewingDirection:n,...i}){const s=rt();return v.useMemo(()=>pr(s)===pr(t),[s,t])?e?m.jsx(e,{...i,children:r}):m.jsx("span",{...i,children:r}):e?m.jsx(e,{...i,lang:t,dir:n,children:r}):m.jsx("span",{...i,lang:t,dir:n,children:r})}function hi(e,t,r){if(t.length===0)return;if(t.length===1)return t[0];if(t.indexOf(e)!==-1)return e;const n=e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):null;if(n&&t.indexOf(n)!==-1)return n;for(const i of r)if(t.indexOf(i)!==-1)return i;return t.indexOf("none")!==-1?"none":t.indexOf("@none")!==-1?"@none":t[0]}const vi=(e,t=[])=>{const r=rt();return v.useMemo(()=>{const n=e();return hi(r,n,[])},[r,...t])};function yi(e,t){const r=vi(()=>Object.keys(e||{}),[e]);return[v.useMemo(()=>{if(!e)return t||"";if(typeof e=="string")return e;const n=r?e[r]:void 0;return n?typeof n=="string"?n:n.join(`
92
- `):""},[r,t,e]),r]}function Xo(){const e=rt();return function(r,n,i){const s=Object.keys(r||{}),a=hi(e,s,[]);if(!r)return n||"";if(typeof r=="string")return r;const o=a?r[a]:void 0;return o?typeof o=="string"?o:o.join(typeof i<"u"?i:`
93
- `):""}}const gi=({as:e,defaultText:t,enableDangerouslySetInnerHTML:r,children:n,...i})=>{const[s,a]=yi(n,t);return a?m.jsx(di,{...i,as:e,language:a,title:r?void 0:s,dangerouslySetInnerHTML:r?{__html:s}:void 0,children:r?void 0:s}):e?m.jsx(e,{...i,children:s}):m.jsx("span",{...i,title:r?void 0:s,dangerouslySetInnerHTML:r?{__html:s}:void 0,children:r?void 0:s})};function ec({element:e,media:t,playPause:r}){const n=v.useRef(null);return t.youTubeId?m.jsxs("div",{className:"video-container",part:"video-container",onClick:r,children:[m.jsx("style",{children:`
91
+ `}),g.jsx("div",{className:"model-container",children:g.jsx("model-viewer",{"interaction-prompt":"none",style:{width:"100%",height:"100%"},"camera-controls":"","ar-status":"not-presenting",src:t.id})})]})}function hi({model:t,name:e}){return Ie("overlay",`model-${e}`,di,{model:t},[t]),null}function yi({style:t}){const e=re();return!e||!e.height||!e.width?null:g.jsx("box",{interactive:!1,target:{x:0,y:0,width:Number(e.width),height:Number(e.height)},style:t})}const vi=y.createContext("en");function ec(t){return g.jsx(vi.Provider,{value:t.language,children:t.children})}function rt(){return y.useContext(vi)}function dr(t){return t.indexOf("-")!==-1?t.slice(0,t.indexOf("-")):t}function gi({as:t,language:e,children:r,viewingDirection:n,...i}){const s=rt();return y.useMemo(()=>dr(s)===dr(e),[s,e])?t?g.jsx(t,{...i,children:r}):g.jsx("span",{...i,children:r}):t?g.jsx(t,{...i,lang:e,dir:n,children:r}):g.jsx("span",{...i,lang:e,dir:n,children:r})}function mi(t,e,r){if(e.length===0)return;if(e.length===1)return e[0];if(e.indexOf(t)!==-1)return t;const n=t.indexOf("-")!==-1?t.slice(0,t.indexOf("-")):null;if(n&&e.indexOf(n)!==-1)return n;for(const i of r)if(e.indexOf(i)!==-1)return i;return e.indexOf("none")!==-1?"none":e.indexOf("@none")!==-1?"@none":e[0]}const xi=(t,e=[])=>{const r=rt();return y.useMemo(()=>{const n=t();return mi(r,n,[])},[r,...e])};function bi(t,e){const r=xi(()=>Object.keys(t||{}),[t]);return[y.useMemo(()=>{if(!t)return e||"";if(typeof t=="string")return t;const n=r?t[r]:void 0;return n?typeof n=="string"?n:n.join(`
92
+ `):""},[r,e,t]),r]}function tc(){const t=rt();return function(r,n,i){const s=Object.keys(r||{}),a=mi(t,s,[]);if(!r)return n||"";if(typeof r=="string")return r;const o=a?r[a]:void 0;return o?typeof o=="string"?o:o.join(typeof i<"u"?i:`
93
+ `):""}}const Ai=({as:t,defaultText:e,enableDangerouslySetInnerHTML:r,children:n,...i})=>{const[s,a]=bi(n,e);return a?g.jsx(gi,{...i,as:t,language:a,title:r?void 0:s,dangerouslySetInnerHTML:r?{__html:s}:void 0,children:r?void 0:s}):t?g.jsx(t,{...i,children:s}):g.jsx("span",{...i,title:r?void 0:s,dangerouslySetInnerHTML:r?{__html:s}:void 0,children:r?void 0:s})};function rc({element:t,media:e,playPause:r}){const n=y.useRef(null);return e.youTubeId?g.jsxs("div",{className:"video-container",part:"video-container",onClick:r,children:[g.jsx("style",{children:`
94
94
  .video-container {
95
95
  position: absolute;
96
96
  top: 0;
@@ -108,5 +108,5 @@
108
108
  width: 100%;
109
109
  object-fit: contain;
110
110
  }
111
- `}),m.jsx("iframe",{className:"video-yt",ref:n,src:`https://www.youtube.com/embed/${t.youTubeId}?enablejsapi=1&origin=${window.location.host}`,referrerPolicy:"no-referrer",sandbox:"allow-scripts allow-same-origin allow-presentation"})]}):null}function tc({media:e,mediaControlsDeps:t,children:r}){const[{element:n,currentTime:i,progress:s},a,o]=tt({duration:e.duration});return Ie("overlay","video-element",ec,{element:n,media:e,playPause:o.playPause}),null}function mi({x:e,y:t,onChoiceChange:r,registerActions:n,defaultChoices:i,isStatic:s,renderViewerControls:a,renderMediaControls:o,viewControlsDeps:u,mediaControlsDeps:d,strategies:l,throwOnUnknown:p,backgroundStyle:g,alwaysShowBackground:b,keepCanvasScale:h=!1,enableSizes:x=!1,enableYouTube:A=!0,onClickPaintingAnnotation:S,children:w}){const M=re(),T=Ft(M,["deep-zoom"]),[F]=Kr(),k=Xr(),O=V(),P=v.useMemo(()=>$t(O),[O]),[R,$]=Kn({strategies:l||["images"],defaultChoices:i==null?void 0:i.map(({id:E})=>E)}),X=R.type==="images"?R.choice:void 0,Y=v.useMemo(()=>h?1:Math.max(1,...R.type==="images"?R.images.map(E=>{var N;return(E.width||0)/((N=E.target)==null?void 0:N.spatial.width)}):[]),[h,R]);Gs(Y),v.useEffect(()=>{n&&n($)},[R.annotations]),v.useEffect(()=>{if(i)for(const E of i)typeof E.opacity<"u"&&P.applyStyles({id:E.id},"atlas",{opacity:E.opacity})},[i]),v.useLayoutEffect(()=>{r&&r(X)},[X]),Ie(k&&(R.type==="images"||R.type==="empty"||R.type==="textual-content"&&a)?"overlay":"none",`canvas-portal-controls-${M==null?void 0:M.id}`,Ze.Provider,a?{value:k||null,children:a(R)}:{},[M,k,R,...u||[]]);const _=ei({maxWidth:256,maxHeight:256});if(!M)return null;const H=M.accompanyingCanvas,J=_&&_.type==="fixed"?m.jsx("world-object",{height:M.height,width:M.width,x:e,y:t,children:m.jsx("world-image",{uri:_.id,target:{x:0,y:0,width:M.width,height:M.height},display:_.width&&_.height?{width:_.width,height:_.height}:void 0,crop:void 0})}):null;if(R.type==="unknown"){if(J)return J;if(p)throw new Error(R.reason||"Unknown image strategy");return null}const ee=m.jsxs(v.Fragment,{children:[F?m.jsx(Ct,{page:F}):null,R.annotations&&R.annotations.pages?R.annotations.pages.map(E=>m.jsx(Ct,{page:E},E.id)):null,w]}),ge=R.type==="images"?R.images.length:0;return m.jsxs(m.Fragment,{children:[m.jsxs("world-object",{height:M.height,width:M.width,x:e,y:t,...T,children:[R.type==="empty"||b?m.jsx(fi,{style:g}):null,R.type==="textual-content"?R.items.map((E,N)=>{var G;return m.jsxs(m.Fragment,{children:[m.jsx(Re.HTMLPortal,{onClick:S?ue=>{ue.stopPropagation(),S(E.annotationId,E,ue)}:void 0,target:((G=E.target)==null?void 0:G.spatial)||void 0,children:m.jsx("div",{"data-textual-content":!0,children:m.jsx(gi,{enableDangerouslySetInnerHTML:!0,children:E.text})})},N),ee]})}):null,R.type==="images"?m.jsxs(m.Fragment,{children:[R.images.map((E,N)=>m.jsx(hn,{isStatic:s,image:E,id:E.id,thumbnail:N===0?_:void 0,selector:E.selector,enableSizes:x,onClick:S?G=>{G.stopPropagation(),S(E.annotationId,E,G)}:void 0},E.id+N)),ee]}):null,R.type==="3d-model"?m.jsx(li,{model:R.model}):null,R.type==="media"?m.jsx(m.Fragment,{children:R.media.type==="Sound"?m.jsxs(ai,{media:R.media,mediaControlsDeps:d,children:[J,o?o(R):null]}):R.media.type==="Video"?m.jsxs(ci,{media:R.media,mediaControlsDeps:d,children:[J,o?o(R):null]}):R.media.type==="VideoYouTube"&&A?m.jsxs(tc,{media:R.media,mediaControlsDeps:d,children:[J,o?o(R):null]}):null}):null]},`${M.id}/${R.type}/${ge}`),R.type==="media"&&R.media.type==="Sound"&&H?m.jsx(Ke,{canvas:H.id,children:m.jsx(mi,{renderViewerControls:a})}):null]})}function xi(){const e=v.useContext($e);return e&&e.vault?e.vault:$r()}const rc=v.forwardRef(function(t,r){const n=ve(),i=Et(),s=zr(),{ViewerControls:a,MediaControls:o}=t.components||{};if(v.useImperativeHandle(r,()=>s,[s]),!n)return m.jsx("div",{});let u=0;return m.jsxs(m.Fragment,{children:[t.header,m.jsx(Q.Viewer,{height:t.height,mode:t.mode,children:i.map((d,l)=>{const p=u;return u+=d.width+(t.spacing||0),m.jsx(Ke,{canvas:d.id,children:m.jsx(Q.RenderCanvas,{strategies:["3d-model","media","images","empty","textual-content"],renderViewerControls:l===0&&a?()=>m.jsx(a,{}):void 0,renderMediaControls:l===0&&o?()=>m.jsx(o,{}):void 0,x:p,...t.canvasProps||{},children:t.annotations},d.id)},d.id)})},t.reuseAtlas?"":s.currentSequenceIndex),t.children]})}),Q=v.forwardRef(function({children:t,height:r,annotations:n,canvasProps:i,spacing:s,header:a,components:o,mode:u,...d},l){const p=xi();return m.jsx(Tt,{vault:p,children:m.jsx(Br,{...d,children:m.jsx(rc,{ref:l,height:r,components:o,spacing:s,canvasProps:i,annotations:n,header:a,mode:u,children:t})})})});Q.RenderImage=hn;Q.RenderCanvas=mi;Q.RenderAnnotationPage=Ct;Q.RenderAnnotation=pn;Q.Viewer=Js;Q.CanvasBackground=fi;Q.Audio=ai;Q.Video=ci;Q.Model=li;Q.AudioHTML=si;Q.VideoHTML=oi;Q.ModelHTML=ui;function nc({annotation:e,children:t}){return m.jsx(he,{value:{annotation:e},children:t})}function ic({annotationPage:e,children:t}){return m.jsx(he,{value:{annotationPage:e},children:t})}function sc({collection:e,children:t}){return m.jsx(he,{value:{collection:e},children:t})}function ac(e,t={}){return et(t)}function oc(e,t=!1){}function cc(e){const r=se().manifest,n=e?e.map(i=>typeof i=="string"?i:i==null?void 0:i.id):[];return U(i=>{const s=r?i.iiif.entities.Manifest[r]:void 0,a=(s==null?void 0:s.items)||[];if(typeof e>"u")return a;const o=[];for(const u of(s==null?void 0:s.items)||[])n.indexOf(u.id)!==-1&&o.push(u);return o},[n.join("/")])}function uc(e,t=[]){const{id:r,selector:n}=e,i=se(),s=r||i.collection,a=U(o=>s?o.iiif.entities.Collection[s]:void 0,[s]);return v.useMemo(()=>{if(a)return n?n(a):a},[a,n,...t])}function lc(e,t,r,n,i=[]){const s=V(),a=v.useMemo(()=>sn(s),[s]);v.useEffect(()=>{const o=e;return o?(a.addEventListener(o,t,r,n),()=>{a.removeEventListener(o,t,r)}):()=>{}},[a,e,t,...i])}function fc(e,t){const{id:r,isLoaded:n,error:i,resource:s,requestId:a,cached:o}=jt(e,t);return{id:r,isLoaded:n,error:i,manifest:s,requestId:a,cached:o}}function bi({cacheKey:e}={}){const t=re(),r=et(),n=V(),i=Xe(),[s,a]=v.useState(void 0),[o,u]=v.useState(!1),[d,l]=v.useState("idle"),[p,g]=v.useState(void 0),b=t?t.id:"undefined",h=v.useMemo(()=>{try{if(t&&r.length){const A=r[0],S=n.get(A.body[0]),M=Se.getImageServices(S)[0];return M&&i.loadServiceSync({id:M.id||M["@id"],width:M.width||t.width,height:M.height||t.height})||void 0}}catch(A){console.error(A)}},[b,e,t]),x=d==="success"&&s?s:h;return v.useEffect(()=>{(async()=>{try{if(t&&r.length){const A=r[0],S=n.get(A.body[0]),M=Se.getImageServices(S)[0];if(!M)return;u(!0),l("loading");try{const T=await i.loadService({id:M.id||M["@id"],width:M.width||t.width,height:M.height||t.height})||void 0;a(T),l("success"),u(!1)}catch(T){l("error"),g(T)}}}catch(A){l("error"),g(A)}})()},[b,e]),v.useMemo(()=>({data:x,isFetching:o,status:d,error:p}),[x,o,d,p])}function pc(){const e=bi();return{isLoading:e.isFetching,tile:e.data?{id:e.data.id||e.data["@id"],width:e.data.width,height:e.data.height,imageService:e.data,thumbnail:void 0}:null}}function dc(){const e=ve();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function hc(){const e=V();return v.useMemo(()=>$t(e),[e])}exports.AnnotationContext=nc;exports.AnnotationPageContext=ic;exports.CanvasContext=Ke;exports.CanvasPanel=Q;exports.CollectionContext=sc;exports.ContextBridge=Qr;exports.ImageServiceLoaderContext=zn;exports.InnerViewerProvider=Nr;exports.LanguageProvider=Zo;exports.LanguageString=di;exports.LocaleString=gi;exports.ManifestContext=qr;exports.MediaPlayerProvider=Nt;exports.RangeContext=Vr;exports.ReactVaultContext=$e;exports.ResourceProvider=he;exports.ResourceReactContext=Je;exports.SimpleViewerProvider=Br;exports.SimpleViewerReactContext=qe;exports.VaultProvider=Tt;exports.ViewerPresetContext=Ze;exports.VirtualAnnotationProvider=Zr;exports.VisibleCanvasReactContext=De;exports.emptyActions=_n;exports.emptyStrategy=Un;exports.expandTarget=de;exports.findAllCanvasesInRange=Pt;exports.findFirstCanvasFromRange=_r;exports.findManifestSelectedRange=Rs;exports.findSelectedRange=Ot;exports.flattenAnnotationPageIds=Hn;exports.formatTime=ti;exports.getImageStrategy=Gn;exports.getManifestSequence=Lt;exports.getParsedTargetSelector=Ht;exports.getVisibleCanvasesFromCanvasId=Is;exports.isImageApiSelector=ln;exports.parseRotation=fn;exports.parseSelector=Pe;exports.parseSpecificResource=Oo;exports.unknownResponse=Ge;exports.unsupportedStrategy=D;exports.useAnnotation=qt;exports.useAnnotationPage=dn;exports.useAnnotationPageManager=Nn;exports.useAnnotationsAtTime=ac;exports.useCanvas=re;exports.useCanvasClock=oc;exports.useCanvasSequence=Hr;exports.useCanvasSubset=cc;exports.useClosestLanguage=vi;exports.useCollection=uc;exports.useContextBridge=Wr;exports.useCreateLocaleString=Xo;exports.useDispatch=Yr;exports.useEventListener=lc;exports.useExistingVault=xi;exports.useExternalCollection=fc;exports.useExternalManifest=Dr;exports.useExternalResource=jt;exports.useIIIFLanguage=rt;exports.useImageService=bi;exports.useImageServiceLoader=Xe;exports.useImageTile=pc;exports.useLoadImageService=Wn;exports.useLocaleString=yi;exports.useManifest=ve;exports.useMediaActions=Jo;exports.useMediaElements=Ko;exports.useMediaState=Go;exports.usePaintables=Yn;exports.usePaintingAnnotations=et;exports.useRange=Ur;exports.useRenderingStrategy=Kn;exports.useResourceContext=se;exports.useResourceEvents=Ft;exports.useResources=Bn;exports.useSearchService=dc;exports.useSimpleMediaPlayer=tt;exports.useSimpleViewer=zr;exports.useStyleHelper=hc;exports.useStyles=Fe;exports.useThumbnail=ei;exports.useVault=V;exports.useVaultEffect=Zn;exports.useVaultSelector=U;exports.useViewerPreset=Xr;exports.useVirtualAnnotationPage=Gr;exports.useVirtualAnnotationPageContext=Kr;exports.useVisibleCanvases=Et;
111
+ `}),g.jsx("iframe",{className:"video-yt",ref:n,src:`https://www.youtube.com/embed/${e.youTubeId}?enablejsapi=1&origin=${window.location.host}`,referrerPolicy:"no-referrer",sandbox:"allow-scripts allow-same-origin allow-presentation"})]}):null}function nc({media:t,mediaControlsDeps:e,children:r}){const[{element:n,currentTime:i,progress:s},a,o]=tt({duration:t.duration});return Ie("overlay","video-element",rc,{element:n,media:t,playPause:o.playPause}),null}function Si({x:t,y:e,onChoiceChange:r,registerActions:n,defaultChoices:i,isStatic:s,renderViewerControls:a,renderMediaControls:o,viewControlsDeps:u,mediaControlsDeps:d,strategies:l,throwOnUnknown:p,backgroundStyle:m,alwaysShowBackground:A,keepCanvasScale:h=!1,enableSizes:x=!1,enableYouTube:b=!0,onClickPaintingAnnotation:S,children:w}){const M=re(),T=$t(M,["deep-zoom"]),[F]=Kr(),k=Xr(),O=V(),E=y.useMemo(()=>Dt(O),[O]),[R,$]=ti({strategies:l||["images"],defaultChoices:i==null?void 0:i.map(({id:P})=>P)}),X=R.type==="images"?R.choice:void 0,Y=y.useMemo(()=>h?1:Math.max(1,...R.type==="images"?R.images.map(P=>{var N;return(P.width||0)/((N=P.target)==null?void 0:N.spatial.width)}):[]),[h,R]);ea(Y),y.useEffect(()=>{n&&n($)},[R.annotations]),y.useEffect(()=>{if(i)for(const P of i)typeof P.opacity<"u"&&E.applyStyles({id:P.id},"atlas",{opacity:P.opacity})},[i]),y.useLayoutEffect(()=>{r&&r(X)},[X]),Ie(k&&(R.type==="images"||R.type==="empty"||R.type==="textual-content"&&a)?"overlay":"none",`canvas-portal-controls-${M==null?void 0:M.id}`,Ze.Provider,a?{value:k||null,children:a(R)}:{},[M,k,R,...u||[]]);const _=ii({maxWidth:256,maxHeight:256});if(!M)return null;const H=M.accompanyingCanvas,J=_&&_.type==="fixed"?g.jsx("world-object",{height:M.height,width:M.width,x:t,y:e,children:g.jsx("world-image",{uri:_.id,target:{x:0,y:0,width:M.width,height:M.height},display:_.width&&_.height?{width:_.width,height:_.height}:void 0,crop:void 0})}):null;if(R.type==="unknown"){if(J)return J;if(p)throw new Error(R.reason||"Unknown image strategy");return null}const ee=g.jsxs(y.Fragment,{children:[F?g.jsx(Mt,{page:F}):null,R.annotations&&R.annotations.pages?R.annotations.pages.map(P=>g.jsx(Mt,{page:P},P.id)):null,w]}),ge=R.type==="images"?R.images.length:0;return g.jsxs(g.Fragment,{children:[g.jsxs("world-object",{height:M.height,width:M.width,x:t,y:e,...T,children:[R.type==="empty"||A?g.jsx(yi,{style:m}):null,R.type==="textual-content"?R.items.map((P,N)=>{var G;return g.jsxs(g.Fragment,{children:[g.jsx(Re.HTMLPortal,{onClick:S?ue=>{ue.stopPropagation(),S(P.annotationId,P,ue)}:void 0,target:((G=P.target)==null?void 0:G.spatial)||void 0,children:g.jsx("div",{"data-textual-content":!0,children:g.jsx(Ai,{enableDangerouslySetInnerHTML:!0,children:P.text})})},N),ee]})}):null,R.type==="images"?g.jsxs(g.Fragment,{children:[R.images.map((P,N)=>g.jsx(hn,{isStatic:s,image:P,id:P.id,thumbnail:N===0?_:void 0,selector:P.selector,enableSizes:x,onClick:S?G=>{G.stopPropagation(),S(P.annotationId,P,G)}:void 0},P.id+N)),ee]}):null,R.type==="3d-model"?g.jsx(hi,{model:R.model}):null,R.type==="media"?g.jsx(g.Fragment,{children:R.media.type==="Sound"?g.jsxs(li,{media:R.media,mediaControlsDeps:d,children:[J,o?o(R):null]}):R.media.type==="Video"?g.jsxs(pi,{media:R.media,mediaControlsDeps:d,children:[J,o?o(R):null]}):R.media.type==="VideoYouTube"&&b?g.jsxs(nc,{media:R.media,mediaControlsDeps:d,children:[J,o?o(R):null]}):null}):null]},`${M.id}/${R.type}/${ge}`),R.type==="media"&&R.media.type==="Sound"&&H?g.jsx(Ke,{canvas:H.id,children:g.jsx(Si,{renderViewerControls:a})}):null]})}function wi(){const t=y.useContext($e);return t&&t.vault?t.vault:$r()}const ic=y.forwardRef(function(e,r){const n=ye(),i=Et(),s=zr(),{ViewerControls:a,MediaControls:o}=e.components||{};if(y.useImperativeHandle(r,()=>s,[s]),!n)return g.jsx("div",{});let u=0;return g.jsxs(g.Fragment,{children:[e.header,g.jsx(Q.Viewer,{height:e.height,mode:e.mode,children:i.map((d,l)=>{const p=u;return u+=d.width+(e.spacing||0),g.jsx(Ke,{canvas:d.id,children:g.jsx(Q.RenderCanvas,{strategies:["3d-model","media","images","empty","textual-content"],renderViewerControls:l===0&&a?()=>g.jsx(a,{}):void 0,renderMediaControls:l===0&&o?()=>g.jsx(o,{}):void 0,x:p,...e.canvasProps||{},children:e.annotations},d.id)},d.id)})},e.reuseAtlas?"":s.currentSequenceIndex),e.children]})}),Q=y.forwardRef(function({children:e,height:r,annotations:n,canvasProps:i,spacing:s,header:a,components:o,mode:u,...d},l){const p=wi();return g.jsx(jt,{vault:p,children:g.jsx(Br,{...d,children:g.jsx(ic,{ref:l,height:r,components:o,spacing:s,canvasProps:i,annotations:n,header:a,mode:u,children:e})})})});Q.RenderImage=hn;Q.RenderCanvas=Si;Q.RenderAnnotationPage=Mt;Q.RenderAnnotation=pn;Q.Viewer=ta;Q.CanvasBackground=yi;Q.Audio=li;Q.Video=pi;Q.Model=hi;Q.AudioHTML=ui;Q.VideoHTML=fi;Q.ModelHTML=di;function sc({annotation:t,children:e}){return g.jsx(he,{value:{annotation:t},children:e})}function ac({annotationPage:t,children:e}){return g.jsx(he,{value:{annotationPage:t},children:e})}function oc({collection:t,children:e}){return g.jsx(he,{value:{collection:t},children:e})}function cc(t,e={}){return et(e)}function uc(t,e=!1){}function lc(t){const r=se().manifest,n=t?t.map(i=>typeof i=="string"?i:i==null?void 0:i.id):[];return U(i=>{const s=r?i.iiif.entities.Manifest[r]:void 0,a=(s==null?void 0:s.items)||[];if(typeof t>"u")return a;const o=[];for(const u of(s==null?void 0:s.items)||[])n.indexOf(u.id)!==-1&&o.push(u);return o},[n.join("/")])}function fc(t,e=[]){const{id:r,selector:n}=t,i=se(),s=r||i.collection,a=U(o=>s?o.iiif.entities.Collection[s]:void 0,[s]);return y.useMemo(()=>{if(a)return n?n(a):a},[a,n,...e])}function pc(t,e,r,n,i=[]){const s=V(),a=y.useMemo(()=>sn(s),[s]);y.useEffect(()=>{const o=t;return o?(a.addEventListener(o,e,r,n),()=>{a.removeEventListener(o,e,r)}):()=>{}},[a,t,e,...i])}function dc(t,e){const{id:r,isLoaded:n,error:i,resource:s,requestId:a,cached:o}=Pt(t,e);return{id:r,isLoaded:n,error:i,manifest:s,requestId:a,cached:o}}function Ci({cacheKey:t}={}){const e=re(),r=et(),n=V(),i=Xe(),[s,a]=y.useState(void 0),[o,u]=y.useState(!1),[d,l]=y.useState("idle"),[p,m]=y.useState(void 0),A=e?e.id:"undefined",h=y.useMemo(()=>{try{if(e&&r.length){const b=r[0],S=n.get(b.body[0]),M=Se.getImageServices(S)[0];return M&&i.loadServiceSync({id:M.id||M["@id"],width:M.width||e.width,height:M.height||e.height})||void 0}}catch(b){console.error(b)}},[A,t,e]),x=d==="success"&&s?s:h;return y.useEffect(()=>{(async()=>{try{if(e&&r.length){const b=r[0],S=n.get(b.body[0]),M=Se.getImageServices(S)[0];if(!M)return;u(!0),l("loading");try{const T=await i.loadService({id:M.id||M["@id"],width:M.width||e.width,height:M.height||e.height})||void 0;a(T),l("success"),u(!1)}catch(T){l("error"),m(T)}}}catch(b){l("error"),m(b)}})()},[A,t]),y.useMemo(()=>({data:x,isFetching:o,status:d,error:p}),[x,o,d,p])}function hc(){const t=Ci();return{isLoading:t.isFetching,tile:t.data?{id:t.data.id||t.data["@id"],width:t.data.width,height:t.data.height,imageService:t.data,thumbnail:void 0}:null}}function yc(){const t=ye();return t?t.service.find(e=>e.profile==="SearchService1"||e.profile==="http://iiif.io/api/search/1/search"):void 0}function vc(){const t=V();return y.useMemo(()=>Dt(t),[t])}exports.AnnotationContext=sc;exports.AnnotationPageContext=ac;exports.CanvasContext=Ke;exports.CanvasPanel=Q;exports.CollectionContext=oc;exports.ContextBridge=Qr;exports.ImageServiceLoaderContext=zn;exports.InnerViewerProvider=Nr;exports.LanguageProvider=ec;exports.LanguageString=gi;exports.LocaleString=Ai;exports.ManifestContext=qr;exports.MediaPlayerProvider=Bt;exports.RangeContext=Vr;exports.ReactVaultContext=$e;exports.ResourceProvider=he;exports.ResourceReactContext=Je;exports.SimpleViewerProvider=Br;exports.SimpleViewerReactContext=qe;exports.VaultProvider=jt;exports.ViewerPresetContext=Ze;exports.VirtualAnnotationProvider=Zr;exports.VisibleCanvasReactContext=De;exports.emptyActions=_n;exports.emptyStrategy=Un;exports.expandTarget=de;exports.findAllCanvasesInRange=Ot;exports.findFirstCanvasFromRange=_r;exports.findManifestSelectedRange=Ps;exports.findSelectedRange=Lt;exports.flattenAnnotationPageIds=Hn;exports.formatTime=si;exports.get3dStrategy=Gn;exports.getImageStrategy=Jn;exports.getManifestSequence=Ft;exports.getParsedTargetSelector=Nt;exports.getRenderingStrategy=ei;exports.getTextualContentStrategy=Zn;exports.getVideoStrategy=Xn;exports.getVisibleCanvasesFromCanvasId=Es;exports.isImageApiSelector=ln;exports.parseRotation=fn;exports.parseSelector=Ee;exports.parseSpecificResource=qo;exports.unknownResponse=Ge;exports.unsupportedStrategy=D;exports.useAnnotation=Vt;exports.useAnnotationPage=dn;exports.useAnnotationPageManager=Nn;exports.useAnnotationsAtTime=cc;exports.useCanvas=re;exports.useCanvasClock=uc;exports.useCanvasSequence=Hr;exports.useCanvasSubset=lc;exports.useClosestLanguage=xi;exports.useCollection=fc;exports.useContextBridge=Wr;exports.useCreateLocaleString=tc;exports.useDispatch=Yr;exports.useEventListener=pc;exports.useExistingVault=wi;exports.useExternalCollection=dc;exports.useExternalManifest=Dr;exports.useExternalResource=Pt;exports.useIIIFLanguage=rt;exports.useImageService=Ci;exports.useImageServiceLoader=Xe;exports.useImageTile=hc;exports.useLoadImageService=Wn;exports.useLocaleString=bi;exports.useManifest=ye;exports.useMediaActions=Zo;exports.useMediaElements=Xo;exports.useMediaState=Ko;exports.usePaintables=Yn;exports.usePaintingAnnotations=et;exports.useRange=Ur;exports.useRenderingStrategy=ti;exports.useResourceContext=se;exports.useResourceEvents=$t;exports.useResources=Bn;exports.useSearchService=yc;exports.useSimpleMediaPlayer=tt;exports.useSimpleViewer=zr;exports.useStyleHelper=vc;exports.useStyles=Fe;exports.useThumbnail=ii;exports.useVault=V;exports.useVaultEffect=ri;exports.useVaultSelector=U;exports.useViewerPreset=Xr;exports.useVirtualAnnotationPage=Gr;exports.useVirtualAnnotationPageContext=Kr;exports.useVisibleCanvases=Et;
112
112
  //# sourceMappingURL=index.js.map