react-iiif-vault 1.3.3 → 1.3.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,4 +1,4 @@
1
- import{c as ht,l as yt}from"./chunk-QCPOOHCR.js";import{forwardRef as er,useImperativeHandle as Li}from"react";import un,{useCallback as tt,useMemo as cn,useState as Re}from"react";import{AtlasAuto as vo,ModeContext as ho}from"@atlas-viewer/atlas";import{ErrorBoundary as yo}from"react-error-boundary";import{useContext as W}from"react";import nr,{useContext as rr,useMemo as or}from"react";import{jsx as ar}from"react/jsx-runtime";var ir={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},Ce=nr.createContext(ir),H=()=>rr(Ce);function K({value:e,children:n}){let t=H(),r=or(()=>({...t,...e}),[e,t]);return ar(Ce.Provider,{value:r,children:n})}import sr,{useState as ur}from"react";import{Vault as xt,globalVault as cr}from"@iiif/helpers/vault";import{jsx as St}from"react/jsx-runtime";var Q=sr.createContext({vault:null,setVaultInstance:e=>{}});function J({vault:e,vaultOptions:n,useGlobal:t,resources:r,children:o}){let[s,i]=ur(()=>e||(t?cr(n):n?new xt(n):new xt));return St(Q.Provider,{value:{vault:s,setVaultInstance:i},children:St(K,{value:r||{},children:o})})}import{useContext as qr}from"react";import{createContext as Br,useMemo as _r}from"react";import{globalVault as lr}from"@iiif/helpers/vault";import{useContext as dr}from"react";function X(e){let n=dr(Q);return e||(n&&n.vault?n.vault:lr())}import{useEffect as mr,useMemo as fr,useState as Be}from"react";function Ct(e,{noCache:n=!1}={}){let t=typeof e=="string"?e:e.id,r=X(),[o,s]=Be(t),[i,a]=Be(void 0),u=fr(()=>r.get(t,{skipSelfReturn:!0})||void 0,[t,r]),[c,l]=Be(u);return mr(()=>{(async()=>{try{let d=u&&!n?u:await r.load(t),y=d?d.id||d["@id"]:null;d&&o!==y&&s(y),l(d)}catch(d){a(d)}})()},[t,n]),{isLoaded:!!c,id:o,requestId:t,error:i,resource:c,cached:!!(c&&c===u)}}function At(e,n){let{id:t,isLoaded:r,error:o,resource:s,requestId:i,cached:a}=Ct(e,n);return{id:t,isLoaded:r,error:o,manifest:s,requestId:i,cached:a}}import{jsx as pr}from"react/jsx-runtime";function bt({manifest:e,children:n}){return pr(K,{value:{manifest:e},children:n})}import{jsx as gr}from"react/jsx-runtime";function q({canvas:e,children:n}){return gr(K,{value:{canvas:e},children:n})}import{useContext as xr}from"react";import Sr from"react";import{useContext as vr}from"react";var R=()=>{let{vault:e}=vr(Q);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};import{useEffect as hr,useState as yr}from"react";function T(e,n=[]){let t=R(),[r,o]=yr(()=>e(t.getState(),t));return hr(()=>t.subscribe(s=>e(s,t),s=>{o(s)},!1),n),r}var ee=Sr.createContext([]);function Ae(){let e=xr(ee);return T(n=>e.map(t=>n.iiif.entities.Canvas[t]).filter(Boolean),[e])}import{useMemo as Cr}from"react";function E(e={},n=[]){let{id:t,selector:r}=e,o=H(),s=R(),i=t||o.manifest,a=T(u=>i?u.iiif.entities.Manifest[i]:void 0,[i]);return Cr(()=>{if(a)return r?r(a):a},[a,r,...n])}import{jsx as Ar}from"react/jsx-runtime";function Pt({range:e,children:n}){return Ar(K,{value:{range:e},children:n})}function br(e,n){for(let t of n.items){if(t.type==="Canvas")return t;if(t.type==="SpecificResource")return t.source;if(t.type==="Range"){let r=br(e,e.get(t));if(r)return r}}return null}function _e(e,n){let t=[];for(let r of n.items)if(r.type==="SpecificResource"&&r.source?.type==="Canvas"&&(r.source.id.indexOf("#")!==-1?t.push({id:r.source.id.split("#")[0],type:"Canvas"}):t.push(r.source)),r.type==="Range"&&t.push(..._e(e,e.get(r))),r.type==="SpecificResource"){let o=typeof r.source=="string"?r.source:r.source.id;t.push({id:o,type:"Canvas"})}return t}function La(e,n,t){for(let r of n.structures){let o=Rt(e,e.get(r),t);if(o)return o}return null}function Rt(e,n,t){for(let r of n.items){let o=r?.source?.id?.split("#")[0];if(r.type==="SpecificResource"&&r.source===t||r.type==="SpecificResource"&&r.source?.type==="Canvas"&&t===o)return n;if(r.type==="Range"){let s=Rt(e,e.get(r),t);if(s)return s}}return null}function Ha(e,n,t,r=!1){let o=n.behavior,s=t?e.get(t):null;if(!s)return[];let i=s.behavior,a=r?!1:o.includes("paged"),u=a?!1:o.includes("continuous"),c=a||u?!1:o.includes("individuals"),l=i.includes("facing-pages"),d=i.includes("non-paged");if(l||d||c||r)return[{id:s.id,type:"Canvas"}];let[y,A]=je(e,n);if(u)return y;let h=y.findIndex(g=>g.id===t);if(h===-1)return[];for(let g of A)if(g.includes(h))return g.map(b=>y[b]);return[{id:s.id,type:"Canvas"}]}function je(e,n,{disablePaging:t,skipNonPaged:r}={}){let o=n.behavior,s=o.includes("paged"),i=s?!1:o.includes("continuous"),a=s||i?!1:o.includes("individuals"),u=n.type==="Manifest"?n.items:_e(e,n);if(i)return[u,[u.map((h,g)=>g)]];if(a||!s||t)return[u,u.map((h,g)=>[g])];let c=[],l=[],d=()=>{l.length&&(c.push([...l]),l=[])},y=0,A=!1;for(let h=0;h<u.length;h++){let g=e.get(u[h]);if(g.behavior.includes("non-paged")){h===y&&y++,r||(d(),c.push([h]),d());continue}if(h===y||g.behavior.includes("facing-pages")){l.length&&(A=!0),d(),c.push([h]),d();continue}if(l.push(h),A){d(),A=!1;continue}l.length>1&&d()}return l.length&&d(),[u,c]}import{useCallback as be,useMemo as Rr,useRef as Tr,useState as Ir}from"react";import{useMemo as Pr}from"react";function Tt(e={},n=[]){let{id:t,selector:r}=e,o=H(),s=t||o.range,i=T(a=>s?a.iiif.entities.Range[s]:void 0,[s]);return Pr(()=>{if(i)return r?r(i):i},[i,r,...n])}function It({startCanvas:e,disablePaging:n}){let t=R(),r=E(),o=Tt(),[s,i]=Ir(void 0),a=o||r;if(!a)throw new Error("Nothing selected");let[u,c]=Rr(()=>je(t,a,{disablePaging:n}),[t,a,n]),l=Tr(c);if(l.current!==c){let b=l.current[s][0],p=c.findIndex(S=>S.includes(b));l.current=c,i(p)}let d=be(g=>{let b=c.findIndex(p=>p.includes(g));i(b===-1?0:b)},[u,c]),y=be(g=>{let b=u.findIndex(p=>p.id===g);b!==-1?d(b):i(0)},[u,c]),A=be(()=>{i(g=>g>=c.length-1?g:g+1)},[c]),h=be(()=>{i(g=>g<=0?0:g-1)},[c]);return typeof s>"u"&&(e?y(e):i(0)),{visibleItems:c[s]?.map(g=>u[g].id)||[],cursor:s,items:u,sequence:c,hasPrevious:s>0,hasNext:s<c.length-1,setSequenceIndex:i,setCanvasIndex:d,setCanvasId:y,next:A,previous:h}}import{createContext as Qe,useContext as Ft,useEffect as wr,useMemo as Er}from"react";import{useStore as de}from"zustand";import{createStore as wt}from"zustand/vanilla";function Ga(e){let n=e.service||e.services||[];for(let t of n)if(t.type==="AuthProbeService2")return!0;return!1}function F(e,n,t){let r=n.findIndex(i=>i.service.id===e);if(r===-1)return n;let o=[...n],s=t(o[r]);return s===o[r]?n:(o[r]=s,o)}var Et=()=>wt((e,n)=>({currentAuth:-1,authItems:[],login:()=>{let t=n().authItems[n().currentAuth];if(!t||t.isPending||t.isLoggedIn)return;if(t.type!=="active")throw new Error("Cannot login to non-active service");let r=t.service.service.find(o=>o.type==="AuthAccessTokenService2");if(!r)throw new Error("Token service not found");e(()=>({authItems:F(t.id,n().authItems,o=>({...o,isPending:!0}))})),Mt(t.service).then(()=>{Ke(r).then(o=>{let s=o.expiresIn,i=Date.now()+s*1e3;e(()=>({authItems:F(t.id,n().authItems,a=>({...a,isLoggedIn:!0,isPending:!1,session:{token:o.accessToken,expires:i}}))}))}).catch(o=>{e(()=>({authItems:F(t.id,n().authItems,s=>({...s,isLoggedIn:!1,isPending:!1,error:o.message}))}))})})},logout:()=>{let t=n().authItems[n().currentAuth];if(!t||t.isPending||!t.isLoggedIn)return;if(t.type!=="active")throw new Error("Cannot logout of non-active service");let r=t.service.service.find(i=>i.type==="AuthLogoutService2");if(!r)return;let o=`${r.id}?origin=${Nt()}`,s=window.open(o);e(()=>({authItems:F(t.id,n().authItems,i=>({...i,isLoggedIn:!1,session:null,isPending:!1}))}))},nextAuth:()=>{let t=n().authItems.length,r=n().currentAuth+1;r>=t||e(()=>({currentAuth:r}))},previousAuth:()=>{let t=n().currentAuth-1;t<0||e(()=>({currentAuth:t}))},setAuth:t=>{t!==-1&&(t<0||t>=n().authItems.length)||e(()=>({currentAuth:t}))},addService:(t,r)=>{if(!t.service)return;let o=t.service.find(a=>a.type==="AuthAccessTokenService2"),s=t;if(n().authItems.find(a=>a.service.id===t.id)){e(()=>({authItems:F(t.id,n().authItems,a=>({...a,instances:a.instances+1}))}));return}if(e(()=>({currentAuth:s.profile==="active"?0:n().currentAuth,authItems:[{id:t.id,type:t.profile,service:t,probeId:r,canAuthenticate:!0,instances:1,isPending:!1,isLoggedIn:!1,session:null},...n().authItems]})),t.profile==="external"){if(!o)throw new Error("Token service not found");Ke(o).then(a=>{e(()=>({authItems:F(t.id,n().authItems,u=>({...u,isLoggedIn:!0,isPending:!1,session:{token:a.accessToken,expires:a.expiresIn}}))}))}).catch(a=>{e(()=>({authItems:F(t.id,n().authItems,u=>({...u,isLoggedIn:!1,isPending:!1,canAuthenticate:!1,error:a.message}))}))})}if(t.profile==="kiosk"){if(!o)throw new Error("Token service not found");e(()=>({authItems:F(t.id,n().authItems,a=>({...a,isPending:!0}))})),Mt(s).then(()=>{Ke(o).then(a=>{e(()=>({authItems:F(t.id,n().authItems,u=>({...u,isLoggedIn:!0,isPending:!1,session:{token:a.accessToken,expires:a.expiresIn}}))}))}).catch(a=>{e(()=>({authItems:F(t.id,n().authItems,u=>({...u,isLoggedIn:!1,isPending:!1,error:a.message}))}))})})}t.profile},removeService:(t,r)=>{let o=n().currentAuth===n().authItems.findIndex(i=>i.service.id===t.id),s=n().currentAuth;if(o){let i=n().authItems.find(u=>u.service.id===t.id);i&&i.instances>1||(s=n().authItems.findIndex(c=>c.service.id!==t.id&&c.instances>0))}e(()=>({authItems:F(t.id,n().authItems,i=>({...i,instances:i.instances-1})),currentAuth:s}))}})),Vt=(e,n)=>wt((t,r)=>({service:e,status:e?"unknown":"success",shouldRedirect:!1,redirectResource:null,shouldSubstitute:!1,substituteResource:null,error:null,errorHeading:null,errorNote:null,shouldDisplayResource:!1,token:n||null,async probe(){if(!r().service)return;let o=r().service?.id;if(!o){t({status:"error",error:"Service ID not found",errorHeading:{en:["Service ID not found"]}});return}t({status:"probing"});let s=r().token;try{let i=await fetch(o,{headers:s?{Authorization:`Bearer ${r().token}`,Accept:"application/json"}:{Accept:"application/json"}}).then(a=>a.json());if(i.status===200)t({status:"success",shouldDisplayResource:!0,error:null,errorHeading:null,errorNote:null,shouldSubstitute:!1,shouldRedirect:!1});else if(i.status<400&&i.status>=300){if(!i.location)throw new Error("Redirect location not found");t({status:"error",shouldDisplayResource:!1,shouldRedirect:!0,redirectResource:i.location||null})}else if(i.status===401)t({status:"error",shouldDisplayResource:!1,shouldRedirect:!1,shouldSubstitute:!!i.substitute,substituteResource:i.substitute||null,error:"Unauthorized",errorHeading:i.heading||{en:["Unauthorized"]},errorNote:i.note||null});else throw new Error("Unknown error")}catch(i){t({status:"error",error:i.message,errorHeading:{en:["Unknown error"]}})}},setToken(o){t({token:o})}}));function kt(e){let n=e.service||e.services||[],t={hasAuth:!1,services:{}};for(let r of n)if(r.type==="AuthProbeService2"){t.services.probe=r,t.hasAuth=!0;let o=r.service.filter(s=>s.type==="AuthAccessService2");o[0]&&(t.services.access=o[0])}return t}async function Ke(e,{strict:n=!0}={}){return new Promise((t,r)=>{let o=Math.random().toString(36).substring(7),s=`${e.id}?messageId=${o}&origin=${window.location.origin}`,i=c=>{let l=c.data;if(l.messageId===o){if(n&&l.type!=="AuthAccessToken2"){a(),r("Invalid response, expected type=AuthAccessToken2");return}if(!l.accessToken){a(),r("Invalid response, expected accessToken");return}a(),t(l)}},a=()=>window.removeEventListener("message",i),u=document.createElement("iframe");u.src=s,u.style.display="none",document.body.appendChild(u),window.addEventListener("message",i)})}function Nt(e){let n=window.location;if(e){let t=document.createElement("a");return t.href=e,t.protocol+"//"+t.hostname+(t.port?":"+t.port:"")}return n.protocol+"//"+n.hostname+(n.port?":"+n.port:"")}async function Mt(e){let n=`${e.id}?origin=${Nt()}`,t=window.open(n);if(!t)throw new Error("Failed to open window");return new Promise((r,o)=>{let s=setInterval(()=>{t.closed&&(clearInterval(s),r())},500)})}import{useEffect as Lt,useMemo as zt}from"react";import{useStore as Mr}from"zustand";function Ot(e){let n=zt(()=>kt(e),[e]),t=Ht(n.services.access?.id),r=zt(()=>Vt(n.services.probe,t),[n.services.probe]),o=Mr(r);return Lt(()=>{o.status==="unknown"&&!t&&o.probe()},[n.services.probe,o.status]),Lt(()=>{t&&(o.setToken(t),o.probe())},[t]),[e,o,n.hasAuth]}import{jsx as Pe}from"react/jsx-runtime";var te=Qe(null),Vr=Qe(null);Vr.displayName="CurrentAuth";var kr=Qe(null);kr.displayName="AuthActions";function $t({children:e}){let n=Er(()=>Et(),[]);return Pe(te.Provider,{value:n,children:e})}function Dt(){return!!Ft(te)}function me(){let e=Ft(te);if(!e)throw new Error("useAuthActions must be used within a AuthProvider");return e}function Nr(){let e=me();return de(e,t=>({login:t.login,logout:t.logout,nextAuth:t.nextAuth,previousAuth:t.previousAuth,setAuth:t.setAuth,addService:t.addService,removeService:t.removeService}))}function ps(){let e=me();return de(e,n=>n)}function Lr(e){let n=me();return de(n,r=>r.authItems.find(o=>o.service.id===e))}function Ht(e){let n=me();return de(n,r=>r.authItems.find(o=>o.id===e)?.session?.token)}function gs(e){let n=me();return de(n,r=>{let o=r.authItems.find(s=>s.service.id===e);return!o||!o.isLoggedIn||!o.session?null:o.session?.token||null})}function zr(e){let n=Nr(),t=Lr(e.service.id);return wr(()=>(n?.addService(e.service,e.probeId),()=>{n?.removeService(e.service,e.probeId)}),[e.service]),t?(t.error||!t.isLoggedIn,e.children):null}function Ye(){return null}function Ut(e){let[n,t,r]=Ot(e.resource),o=e.fallbackComponent||Ye,s=e.loadingComponent||Ye,i=e.errorComponent||Ye,a=t.service,u=null;if(!r||!a)return e.children(n);let c=a.service.filter(l=>l.type==="AuthAccessService2");t.status==="error"&&(u=Pe(i,{resource:e.resource,error:t.error||"",heading:t.errorHeading,note:t.errorNote,extra:e.extra})),(t.status==="unknown"||t.status==="probing")&&(u=Pe(s,{})),t.status==="success"&&(u=e.children(n));for(let l of c)u=Pe(zr,{service:l,probeId:a.id,children:u},l.id);return u}import{createContext as $r,useContext as Ps,useMemo as Dr}from"react";import{createStore as Or}from"zustand/vanilla";var Hr=e=>e.id||e["@id"];function Fr(e){return(Array.isArray(e.service)?e.service:[e.service]).find(t=>t.profile==="http://iiif.io/api/search/0/autocomplete"||t.profile==="http://iiif.io/api/search/1/autocomplete"||t.profile==="AutoCompleteService1")}var qt=e=>{let n;typeof e=="string"?n={"@context":"http://iiif.io/api/search/1/context.json",profile:"http://iiif.io/api/search/1/search","@id":e,id:e,service:[]}:n=e;let t=n?Hr(n):void 0,r=null;return Or((o,s)=>({service:n,resources:[],lastQuery:{},loading:!1,error:!1,highlight:null,hasSearch:!!n,hasAutocomplete:n?!!Fr(n):!1,errorMessage:"",search(i,a={}){if(!t)throw new Error("No search service found.");r&&!r.signal.aborted&&r.abort(),r=new AbortController;let u=new URLSearchParams;i.q&&u.set("q",i.q),i.motivation&&u.set("motivation",i.motivation),i.date&&u.set("date",i.date),i.user&&u.set("user",i.user),o({loading:!0}),fetch(`${t}?${u.toString()}`,{signal:r.signal,headers:{"Content-Type":"application/json",Accept:"application/json",...a.headers||{}}}).then(async c=>{if(!r?.signal.aborted)if(c.ok){let l=await c.json();o({resources:l.resources,error:!1,errorMessage:""})}else o({resources:[],error:!0,errorMessage:c.statusText})})},clearSearch(){o({resources:[],error:!1,errorMessage:""})},highlightResult(i){let a=s().resources.find(u=>u["@id"]===i);o({highlight:a})},nextResult(){let i=s().resources,a=s().highlight;if(!a){o({highlight:i[0]||null});return}let u=i.findIndex(c=>c["@id"]===a["@id"]);if(u===-1){o({highlight:i[0]||null});return}o({highlight:i[u+1]||i[0]||null})},previousResult(){let i=s().resources,a=s().highlight;if(!a){o({highlight:i[i.length-1]||null});return}let u=i.findIndex(c=>c["@id"]===a["@id"]);if(u===-1){o({highlight:i[i.length-1]||null});return}if(u===0){o({highlight:i[i.length-1]||null});return}o({highlight:i[u-1]||i[i.length-1]||null})}}))};import{useStore as ws}from"zustand";function Bt(){let e=E();return e?e.service.find(n=>n.profile==="SearchService1"||n.profile==="http://iiif.io/api/search/1/search"):void 0}import{jsx as We}from"react/jsx-runtime";var ne=$r(null);ne.displayName="Search";function _t(e){let n=Bt();return e.store?We(ne.Provider,{value:e.store,children:e.children}):We(Ur,{service:n,children:e.children})}function Ur({service:e,children:n}){let t=Dr(()=>qt(e),[e]);return We(ne.Provider,{value:t,children:n})}import{jsx as z}from"react/jsx-runtime";var fe=()=>{},pe=Br({setCurrentCanvasId:fe,setCurrentCanvasIndex:fe,nextCanvas:fe,previousCanvas:fe,items:[],sequence:[],setSequenceIndex:fe,currentSequenceIndex:0,hasNext:!1,hasPrevious:!1});function jr(e){let n=E(),{cursor:t,visibleItems:r,next:o,sequence:s,items:i,setCanvasIndex:a,setCanvasId:u,previous:c,setSequenceIndex:l,hasNext:d,hasPrevious:y}=It({startCanvas:e.startCanvas,disablePaging:e.pagingEnabled===!1}),A=_r(()=>({sequence:s,items:i,setCurrentCanvasId:u,nextCanvas:o,previousCanvas:c,totalCanvases:i.length,setCurrentCanvasIndex:a,setSequenceIndex:l,currentSequenceIndex:t,hasNext:d,hasPrevious:y}),[s,i,u,o,c,i,a,l,t]);return n?r.length===0?null:z(pe.Provider,{value:A,children:z(ee.Provider,{value:r,children:z(q,{canvas:r[0],children:e.children})})}):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),z("div",{children:"Sorry, something went wrong."}))}function jt(e){let n=X(e.vault),t=At(e.manifest);if(!t)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),z("div",{children:"Sorry, something went wrong."});if(t.error)return z("div",{children:t.error.toString()});if(!t.isLoaded)return z("div",{children:"Loading..."});let r=z(jr,{...e,children:e.children});return z(J,{vault:n,children:z(bt,{manifest:t.id,children:z($t,{children:z(_t,{children:e.rangeId?z(Pt,{range:e.rangeId,children:r}):r})})})})}function Kt(){return qr(pe)}import Kr from"react";import{createContext as Yr,useMemo as Qr}from"react";import Wr from"mitt";import{jsx as Zr}from"react/jsx-runtime";var Gr=Wr(),re=Yr({emitter:Gr});re.displayName="Events";function Yt(){return Kr.useContext(re).emitter}function au({emitter:e,children:n}){return Zr(re.Provider,{value:Qr(()=>({emitter:e}),[e]),children:n})}import{jsx as oe}from"react/jsx-runtime";function Qt(){return{VaultContext:W(Q),ResourceContext:W(Ce),SimpleViewerReactContext:W(pe),VisibleCanvasReactContext:W(ee),AuthRContext:W(te),SearchReactContext:W(ne),ReactEventContext:W(re)}}function Wt(e){return oe(J,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext,children:oe(ee.Provider,{value:e.bridge.VisibleCanvasReactContext,children:oe(pe.Provider,{value:e.bridge.SimpleViewerReactContext,children:oe(re.Provider,{value:e.bridge.ReactEventContext,children:oe(te.Provider,{value:e.bridge.AuthRContext,children:oe(ne.Provider,{value:e.bridge.SearchReactContext,children:e.children})})})})})})}import{createContext as no,useContext as ro,useMemo as oo}from"react";import{useCallback as Zt,useLayoutEffect as Xr,useMemo as eo,useRef as to}from"react";import{entityActions as Ge}from"@iiif/helpers/vault/actions";import{useMemo as Jr}from"react";function Gt(){let n=R().getStore();return Jr(()=>t=>n.dispatch(t),[n])}function Jt(e){return typeof e!="string"&&e&&e.bindToVault}function Xt(){let e=R(),n=to([]),t=Gt(),r=eo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);Xr(()=>{let a={id:r,type:"AnnotationPage",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],rendering:[],service:[]};t(Ge.importEntities({entities:{AnnotationPage:{[a.id]:a}}}))},[r]);let o=T(a=>r&&a.iiif.entities.AnnotationPage[r]||null,[r]),s=Zt((a,u)=>{if(r){if(Jt(a)){let d=a;d.__vault||d.bindToVault(e),a=typeof d.source=="string"?d.source:d.source.id,n.current[a]=d}else typeof a!="string"&&(a=a.id);let c=e.get({id:r,type:"AnnotationPage"}),l=e.get({id:a,type:"Annotation"});c&&l&&(c.items.find(d=>d.id===l.id)||t(Ge.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"},index:u})))}},[r]),i=Zt(a=>{r&&(Jt(a)?a=typeof a.source=="string"?a.source:a.source.id:typeof a!="string"&&(a=a.id),n.current[a]&&n.current[a].beforeRemove(),e.get({id:r,type:"AnnotationPage"})&&t(Ge.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"}})))},[r]);return[o,{addAnnotation:s,removeAnnotation:i}]}import{jsx as io}from"react/jsx-runtime";var en=no(null);function tn(){let e=ro(en);return[e.fullPage,{addAnnotation:e.addAnnotation,removeAnnotation:e.removeAnnotation}]}function nn({children:e}){let[n,{addAnnotation:t,removeAnnotation:r}]=Xt();return io(en.Provider,{value:oo(()=>({fullPage:n,addAnnotation:t,removeAnnotation:r}),[n]),children:e})}import{jsx as Ze,jsxs as ao}from"react/jsx-runtime";function rn({width:e,style:n,height:t,error:r,resetErrorBoundary:o}){return ao("div",{style:{width:e,height:t,minHeight:500,...n||{},background:"#f9f9f9"},children:[Ze("h3",{children:"Error occurred"}),Ze("p",{children:r.message}),Ze("button",{onClick:o,children:"Reset"})]})}import{createContext as so,useContext as uo}from"react";var ge=so(null);function on(){return uo(ge)}import{createContext as an,useContext as co,useEffect as lo}from"react";var Je=an(()=>{}),Xe=an(()=>{});function O(e,n,t,r,o=[]){let s=co(e==="portal"?Xe:Je);lo(()=>(e!=="none"&&s(n,t,r),()=>{s(n,null)}),[n,e,s,...o])}import{createContext as fo,useContext as po,useEffect as go}from"react";import{useMemo as mo}from"react";function M(e={},n=[]){let{id:t,selector:r}=e,o=H(),s=t||o.canvas,i=T(a=>s?a.iiif.entities.Canvas[s]:void 0,[s]);return mo(()=>{if(i)return r?r(i):i},[i,r,...n])}var et=fo(()=>{});function sn(e){let n=M(),t=po(et);go(()=>n&&n.id?(t(n.id,e),()=>t(n.id,-1)):()=>{},[n,e])}import{Fragment as xo,jsx as V,jsxs as So}from"react/jsx-runtime";function ln({children:e,errorFallback:n,outerContainerProps:t={},worldScale:r,...o}){let[s,i]=Re(),a=Qt(),u=n||rn,[c,l]=Re({}),d=Object.entries(c),[y,A]=Re({}),h=Object.entries(y),[g,b]=Re({}),p=cn(()=>r||Math.max(...Object.values(g)),[g]),S=cn(()=>({maxOverZoom:p||1,...o.runtimeOptions||{}}),[p,o.runtimeOptions]),m=tt((x,P)=>{b(C=>{if(P===-1){let{[x]:_,...f}=C;return f}return{...C,[x]:P}})},[]),v=tt((x,P,C)=>{l(({[x]:_,...f})=>P?{...f,[x]:{element:P,props:C}}:f)},[]),I=tt((x,P,C)=>{A(({[x]:_,...f})=>P?{...f,[x]:{element:P,props:C}}:f)},[]);return So(yo,{resetKeys:[],fallbackRender:x=>V(u,{...o,...x}),children:[V(vo,{...o,containerProps:{style:{position:"relative"},...o.containerProps||{}},htmlChildren:V(xo,{children:d.map(([x,{element:P,props:C}])=>V(un.Fragment,{children:V(P,{...C||{}})},x))}),onCreated:x=>{i(x),o.onCreated&&o.onCreated(x)},runtimeOptions:S,children:V(ge.Provider,{value:s,children:V(et.Provider,{value:m,children:V(Je.Provider,{value:v,children:V(Xe.Provider,{value:I,children:V(Wt,{bridge:a,children:V(ho.Provider,{value:o.mode||"explore",children:V(nn,{children:e})})})})})})})}),V("div",{children:h.map(([x,{element:P,props:C}])=>V(un.Fragment,{children:V(P,{...C||{}})},x))})]})}import{mergeStyles as To,RegionHighlight as Io}from"@atlas-viewer/atlas";import{useMemo as dn}from"react";import{createEventsHelper as Co}from"@iiif/helpers/events";function Te(e,n){let t=R(),r=dn(()=>Co(t),[t]),o=T(()=>e&&e.id?t.getResourceMeta(e.id,"eventManager"):null,[e]);return dn(()=>e?r.getListenersAsProps(e,n):{},[o,e,t,n])}import{useMemo as Ao}from"react";import{createStylesHelper as bo}from"@iiif/helpers/styles";function ie(e,n){let t=R(),r=Ao(()=>bo(t),[t]);return T(()=>{if(!e)return null;let o=r.getAppliedStyles(e.id);return o?n?o[n]:o:void 0},[e,n])}import{useMemo as Mo}from"react";import{useMemo as Po}from"react";import{expandTarget as Ro}from"@iiif/helpers/annotation-targets";function Ie(e={},n=[]){let{id:t,selector:r}=e,o=H(),s=R(),i=t||o.annotation,a=T(c=>i?c.iiif.entities.Annotation[i]:void 0,[i]),u=T(c=>a&&a.body?a.body.map(l=>l?l.type==="SpecificResource"?{...l,source:s.get(l)}:l?c.iiif.entities[l.type][l.id]:null:null).filter(Boolean):[],[a]);return Po(()=>{if(!a)return;let c={...a,body:u,target:Ro(a.target,{typeMap:s.getState().iiif.mapping})};return r?r(c):c},[a,r,u,...n])}import{jsx as wo}from"react/jsx-runtime";var Me=({id:e,style:n,className:t,interactive:r})=>{let o=Ie({id:e}),s=ie(o,"atlas"),i=ie(o,"html"),a=Te(o,["atlas"]),u=M(),c=Mo(()=>To(n,s),[n,s]);return u&&o&&o.target&&o.target.selector&&o.target.selector.type==="BoxSelector"&&o.target.source&&(o.target.source.id===u.id||o.target.source===u.id)?wo(Io,{id:o.id,isEditing:!0,region:o.target.selector.spatial,style:c,className:i?.className||t,interactive:!!(i?.href||r),href:i?.href||null,title:i?.title||null,hrefTarget:i?.target||null,onClick:()=>{},...a}):null};import{Fragment as Vo}from"react";import{useMemo as Eo}from"react";function mn(e={},n=[]){let{id:t,selector:r}=e,o=H(),s=t||o.annotationPage,i=T(a=>s?a.iiif.entities.AnnotationPage[s]:void 0,[s]);return Eo(()=>{if(i)return r?r(i):i},[i,...n])}import{jsx as fn}from"react/jsx-runtime";var ve=({className:e,page:n})=>{let t=mn({id:n.id})||n,r=ie(t,"atlas"),o=ie(t,"html");return T(s=>t.id?s.iiif.entities.AnnotationPage[t.id]:null,[]),fn(Vo,{children:t.items?.map(s=>fn(Me,{id:s.id,style:r,className:o?.className||e},s.id))})};import{createStylesHelper as Vi}from"@iiif/helpers/styles";import{Fragment as bn,useMemo as Fo}from"react";import{HTMLPortal as zo,TileSet as Cn}from"@atlas-viewer/atlas";import ae,{useMemo as nt}from"react";import{jsx as $}from"react/jsx-runtime";var gn=ae.createContext("en"),vn=ae.createContext({}),hn=ae.createContext(null);function Xc(e){return $(vn.Provider,{value:e.translations,children:e.children})}function el(e){return $(gn.Provider,{value:e.language,children:e.children})}function tl(e){return $(hn.Provider,{value:e.convert,children:e.children})}function yn(){return ae.useContext(hn)}function rt(){return ae.useContext(gn)}function xn(){return ae.useContext(vn)}function pn(e){return e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):e}function ko({as:e,language:n,children:t,viewingDirection:r,...o}){let s=rt();return nt(()=>pn(s)===pn(n),[s,n])?e?$(e,{...o,children:t}):$("span",{...o,children:t}):e?$(e,{...o,lang:n,dir:r,children:t}):$("span",{...o,lang:n,dir:r,children:t})}function Sn(e,n,t){if(n.length===0)return;if(n.length===1)return n[0];if(n.indexOf(e)!==-1)return e;let r=e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):null;if(r&&n.indexOf(r)!==-1)return r;for(let o of t)if(n.indexOf(o)!==-1)return o;return n.indexOf("none")!==-1?"none":n.indexOf("@none")!==-1?"@none":n[0]}var No=(e,n=[])=>{let t=rt();return nt(()=>{let r=e();return Sn(t,r,[])},[t,...n])};function G(e,n,t,r){return n?t?t(e[n]||n,r||"none"):e[n]||n:""}function Lo(e,n,t=`
1
+ import{c as ht,l as yt}from"./chunk-UFC4ZSNV.js";import{forwardRef as er,useImperativeHandle as Li}from"react";import un,{useCallback as tt,useMemo as cn,useState as Re}from"react";import{AtlasAuto as vo,ModeContext as ho}from"@atlas-viewer/atlas";import{ErrorBoundary as yo}from"react-error-boundary";import{useContext as W}from"react";import nr,{useContext as rr,useMemo as or}from"react";import{jsx as ar}from"react/jsx-runtime";var ir={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},Ce=nr.createContext(ir),H=()=>rr(Ce);function K({value:e,children:n}){let t=H(),r=or(()=>({...t,...e}),[e,t]);return ar(Ce.Provider,{value:r,children:n})}import sr,{useState as ur}from"react";import{Vault as xt,globalVault as cr}from"@iiif/helpers/vault";import{jsx as St}from"react/jsx-runtime";var Q=sr.createContext({vault:null,setVaultInstance:e=>{}});function J({vault:e,vaultOptions:n,useGlobal:t,resources:r,children:o}){let[s,i]=ur(()=>e||(t?cr(n):n?new xt(n):new xt));return St(Q.Provider,{value:{vault:s,setVaultInstance:i},children:St(K,{value:r||{},children:o})})}import{useContext as qr}from"react";import{createContext as Br,useMemo as _r}from"react";import{globalVault as lr}from"@iiif/helpers/vault";import{useContext as dr}from"react";function X(e){let n=dr(Q);return e||(n&&n.vault?n.vault:lr())}import{useEffect as mr,useMemo as fr,useState as Be}from"react";function Ct(e,{noCache:n=!1}={}){let t=typeof e=="string"?e:e.id,r=X(),[o,s]=Be(t),[i,a]=Be(void 0),u=fr(()=>r.get(t,{skipSelfReturn:!0})||void 0,[t,r]),[c,l]=Be(u);return mr(()=>{(async()=>{try{let d=u&&!n?u:await r.load(t),y=d?d.id||d["@id"]:null;d&&o!==y&&s(y),l(d)}catch(d){a(d)}})()},[t,n]),{isLoaded:!!c,id:o,requestId:t,error:i,resource:c,cached:!!(c&&c===u)}}function At(e,n){let{id:t,isLoaded:r,error:o,resource:s,requestId:i,cached:a}=Ct(e,n);return{id:t,isLoaded:r,error:o,manifest:s,requestId:i,cached:a}}import{jsx as pr}from"react/jsx-runtime";function bt({manifest:e,children:n}){return pr(K,{value:{manifest:e},children:n})}import{jsx as gr}from"react/jsx-runtime";function q({canvas:e,children:n}){return gr(K,{value:{canvas:e},children:n})}import{useContext as xr}from"react";import Sr from"react";import{useContext as vr}from"react";var R=()=>{let{vault:e}=vr(Q);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};import{useEffect as hr,useState as yr}from"react";function T(e,n=[]){let t=R(),[r,o]=yr(()=>e(t.getState(),t));return hr(()=>t.subscribe(s=>e(s,t),s=>{o(s)},!1),n),r}var ee=Sr.createContext([]);function Ae(){let e=xr(ee);return T(n=>e.map(t=>n.iiif.entities.Canvas[t]).filter(Boolean),[e])}import{useMemo as Cr}from"react";function E(e={},n=[]){let{id:t,selector:r}=e,o=H(),s=R(),i=t||o.manifest,a=T(u=>i?u.iiif.entities.Manifest[i]:void 0,[i]);return Cr(()=>{if(a)return r?r(a):a},[a,r,...n])}import{jsx as Ar}from"react/jsx-runtime";function Pt({range:e,children:n}){return Ar(K,{value:{range:e},children:n})}function br(e,n){for(let t of n.items){if(t.type==="Canvas")return t;if(t.type==="SpecificResource")return t.source;if(t.type==="Range"){let r=br(e,e.get(t));if(r)return r}}return null}function _e(e,n){let t=[];for(let r of n.items)if(r.type==="SpecificResource"&&r.source?.type==="Canvas"&&(r.source.id.indexOf("#")!==-1?t.push({id:r.source.id.split("#")[0],type:"Canvas"}):t.push(r.source)),r.type==="Range"&&t.push(..._e(e,e.get(r))),r.type==="SpecificResource"){let o=typeof r.source=="string"?r.source:r.source.id;t.push({id:o,type:"Canvas"})}return t}function La(e,n,t){for(let r of n.structures){let o=Rt(e,e.get(r),t);if(o)return o}return null}function Rt(e,n,t){for(let r of n.items){let o=r?.source?.id?.split("#")[0];if(r.type==="SpecificResource"&&r.source===t||r.type==="SpecificResource"&&r.source?.type==="Canvas"&&t===o)return n;if(r.type==="Range"){let s=Rt(e,e.get(r),t);if(s)return s}}return null}function Ha(e,n,t,r=!1){let o=n.behavior,s=t?e.get(t):null;if(!s)return[];let i=s.behavior,a=r?!1:o.includes("paged"),u=a?!1:o.includes("continuous"),c=a||u?!1:o.includes("individuals"),l=i.includes("facing-pages"),d=i.includes("non-paged");if(l||d||c||r)return[{id:s.id,type:"Canvas"}];let[y,A]=je(e,n);if(u)return y;let h=y.findIndex(g=>g.id===t);if(h===-1)return[];for(let g of A)if(g.includes(h))return g.map(b=>y[b]);return[{id:s.id,type:"Canvas"}]}function je(e,n,{disablePaging:t,skipNonPaged:r}={}){let o=n.behavior,s=o.includes("paged"),i=s?!1:o.includes("continuous"),a=s||i?!1:o.includes("individuals"),u=n.type==="Manifest"?n.items:_e(e,n);if(i)return[u,[u.map((h,g)=>g)]];if(a||!s||t)return[u,u.map((h,g)=>[g])];let c=[],l=[],d=()=>{l.length&&(c.push([...l]),l=[])},y=0,A=!1;for(let h=0;h<u.length;h++){let g=e.get(u[h]);if(g.behavior.includes("non-paged")){h===y&&y++,r||(d(),c.push([h]),d());continue}if(h===y||g.behavior.includes("facing-pages")){l.length&&(A=!0),d(),c.push([h]),d();continue}if(l.push(h),A){d(),A=!1;continue}l.length>1&&d()}return l.length&&d(),[u,c]}import{useCallback as be,useMemo as Rr,useRef as Tr,useState as Ir}from"react";import{useMemo as Pr}from"react";function Tt(e={},n=[]){let{id:t,selector:r}=e,o=H(),s=t||o.range,i=T(a=>s?a.iiif.entities.Range[s]:void 0,[s]);return Pr(()=>{if(i)return r?r(i):i},[i,r,...n])}function It({startCanvas:e,disablePaging:n}){let t=R(),r=E(),o=Tt(),[s,i]=Ir(void 0),a=o||r;if(!a)throw new Error("Nothing selected");let[u,c]=Rr(()=>je(t,a,{disablePaging:n}),[t,a,n]),l=Tr(c);if(l.current!==c){let b=l.current[s][0],p=c.findIndex(S=>S.includes(b));l.current=c,i(p)}let d=be(g=>{let b=c.findIndex(p=>p.includes(g));i(b===-1?0:b)},[u,c]),y=be(g=>{let b=u.findIndex(p=>p.id===g);b!==-1?d(b):i(0)},[u,c]),A=be(()=>{i(g=>g>=c.length-1?g:g+1)},[c]),h=be(()=>{i(g=>g<=0?0:g-1)},[c]);return typeof s>"u"&&(e?y(e):i(0)),{visibleItems:c[s]?.map(g=>u[g].id)||[],cursor:s,items:u,sequence:c,hasPrevious:s>0,hasNext:s<c.length-1,setSequenceIndex:i,setCanvasIndex:d,setCanvasId:y,next:A,previous:h}}import{createContext as Qe,useContext as Ft,useEffect as wr,useMemo as Er}from"react";import{useStore as de}from"zustand";import{createStore as wt}from"zustand/vanilla";function Ga(e){let n=e.service||e.services||[];for(let t of n)if(t.type==="AuthProbeService2")return!0;return!1}function F(e,n,t){let r=n.findIndex(i=>i.service.id===e);if(r===-1)return n;let o=[...n],s=t(o[r]);return s===o[r]?n:(o[r]=s,o)}var Et=()=>wt((e,n)=>({currentAuth:-1,authItems:[],login:()=>{let t=n().authItems[n().currentAuth];if(!t||t.isPending||t.isLoggedIn)return;if(t.type!=="active")throw new Error("Cannot login to non-active service");let r=t.service.service.find(o=>o.type==="AuthAccessTokenService2");if(!r)throw new Error("Token service not found");e(()=>({authItems:F(t.id,n().authItems,o=>({...o,isPending:!0}))})),Mt(t.service).then(()=>{Ke(r).then(o=>{let s=o.expiresIn,i=Date.now()+s*1e3;e(()=>({authItems:F(t.id,n().authItems,a=>({...a,isLoggedIn:!0,isPending:!1,session:{token:o.accessToken,expires:i}}))}))}).catch(o=>{e(()=>({authItems:F(t.id,n().authItems,s=>({...s,isLoggedIn:!1,isPending:!1,error:o.message}))}))})})},logout:()=>{let t=n().authItems[n().currentAuth];if(!t||t.isPending||!t.isLoggedIn)return;if(t.type!=="active")throw new Error("Cannot logout of non-active service");let r=t.service.service.find(i=>i.type==="AuthLogoutService2");if(!r)return;let o=`${r.id}?origin=${Nt()}`,s=window.open(o);e(()=>({authItems:F(t.id,n().authItems,i=>({...i,isLoggedIn:!1,session:null,isPending:!1}))}))},nextAuth:()=>{let t=n().authItems.length,r=n().currentAuth+1;r>=t||e(()=>({currentAuth:r}))},previousAuth:()=>{let t=n().currentAuth-1;t<0||e(()=>({currentAuth:t}))},setAuth:t=>{t!==-1&&(t<0||t>=n().authItems.length)||e(()=>({currentAuth:t}))},addService:(t,r)=>{if(!t.service)return;let o=t.service.find(a=>a.type==="AuthAccessTokenService2"),s=t;if(n().authItems.find(a=>a.service.id===t.id)){e(()=>({authItems:F(t.id,n().authItems,a=>({...a,instances:a.instances+1}))}));return}if(e(()=>({currentAuth:s.profile==="active"?0:n().currentAuth,authItems:[{id:t.id,type:t.profile,service:t,probeId:r,canAuthenticate:!0,instances:1,isPending:!1,isLoggedIn:!1,session:null},...n().authItems]})),t.profile==="external"){if(!o)throw new Error("Token service not found");Ke(o).then(a=>{e(()=>({authItems:F(t.id,n().authItems,u=>({...u,isLoggedIn:!0,isPending:!1,session:{token:a.accessToken,expires:a.expiresIn}}))}))}).catch(a=>{e(()=>({authItems:F(t.id,n().authItems,u=>({...u,isLoggedIn:!1,isPending:!1,canAuthenticate:!1,error:a.message}))}))})}if(t.profile==="kiosk"){if(!o)throw new Error("Token service not found");e(()=>({authItems:F(t.id,n().authItems,a=>({...a,isPending:!0}))})),Mt(s).then(()=>{Ke(o).then(a=>{e(()=>({authItems:F(t.id,n().authItems,u=>({...u,isLoggedIn:!0,isPending:!1,session:{token:a.accessToken,expires:a.expiresIn}}))}))}).catch(a=>{e(()=>({authItems:F(t.id,n().authItems,u=>({...u,isLoggedIn:!1,isPending:!1,error:a.message}))}))})})}t.profile},removeService:(t,r)=>{let o=n().currentAuth===n().authItems.findIndex(i=>i.service.id===t.id),s=n().currentAuth;if(o){let i=n().authItems.find(u=>u.service.id===t.id);i&&i.instances>1||(s=n().authItems.findIndex(c=>c.service.id!==t.id&&c.instances>0))}e(()=>({authItems:F(t.id,n().authItems,i=>({...i,instances:i.instances-1})),currentAuth:s}))}})),Vt=(e,n)=>wt((t,r)=>({service:e,status:e?"unknown":"success",shouldRedirect:!1,redirectResource:null,shouldSubstitute:!1,substituteResource:null,error:null,errorHeading:null,errorNote:null,shouldDisplayResource:!1,token:n||null,async probe(){if(!r().service)return;let o=r().service?.id;if(!o){t({status:"error",error:"Service ID not found",errorHeading:{en:["Service ID not found"]}});return}t({status:"probing"});let s=r().token;try{let i=await fetch(o,{headers:s?{Authorization:`Bearer ${r().token}`,Accept:"application/json"}:{Accept:"application/json"}}).then(a=>a.json());if(i.status===200)t({status:"success",shouldDisplayResource:!0,error:null,errorHeading:null,errorNote:null,shouldSubstitute:!1,shouldRedirect:!1});else if(i.status<400&&i.status>=300){if(!i.location)throw new Error("Redirect location not found");t({status:"error",shouldDisplayResource:!1,shouldRedirect:!0,redirectResource:i.location||null})}else if(i.status===401)t({status:"error",shouldDisplayResource:!1,shouldRedirect:!1,shouldSubstitute:!!i.substitute,substituteResource:i.substitute||null,error:"Unauthorized",errorHeading:i.heading||{en:["Unauthorized"]},errorNote:i.note||null});else throw new Error("Unknown error")}catch(i){t({status:"error",error:i.message,errorHeading:{en:["Unknown error"]}})}},setToken(o){t({token:o})}}));function kt(e){let n=e.service||e.services||[],t={hasAuth:!1,services:{}};for(let r of n)if(r.type==="AuthProbeService2"){t.services.probe=r,t.hasAuth=!0;let o=r.service.filter(s=>s.type==="AuthAccessService2");o[0]&&(t.services.access=o[0])}return t}async function Ke(e,{strict:n=!0}={}){return new Promise((t,r)=>{let o=Math.random().toString(36).substring(7),s=`${e.id}?messageId=${o}&origin=${window.location.origin}`,i=c=>{let l=c.data;if(l.messageId===o){if(n&&l.type!=="AuthAccessToken2"){a(),r("Invalid response, expected type=AuthAccessToken2");return}if(!l.accessToken){a(),r("Invalid response, expected accessToken");return}a(),t(l)}},a=()=>window.removeEventListener("message",i),u=document.createElement("iframe");u.src=s,u.style.display="none",document.body.appendChild(u),window.addEventListener("message",i)})}function Nt(e){let n=window.location;if(e){let t=document.createElement("a");return t.href=e,t.protocol+"//"+t.hostname+(t.port?":"+t.port:"")}return n.protocol+"//"+n.hostname+(n.port?":"+n.port:"")}async function Mt(e){let n=`${e.id}?origin=${Nt()}`,t=window.open(n);if(!t)throw new Error("Failed to open window");return new Promise((r,o)=>{let s=setInterval(()=>{t.closed&&(clearInterval(s),r())},500)})}import{useEffect as Lt,useMemo as zt}from"react";import{useStore as Mr}from"zustand";function Ot(e){let n=zt(()=>kt(e),[e]),t=Ht(n.services.access?.id),r=zt(()=>Vt(n.services.probe,t),[n.services.probe]),o=Mr(r);return Lt(()=>{o.status==="unknown"&&!t&&o.probe()},[n.services.probe,o.status]),Lt(()=>{t&&(o.setToken(t),o.probe())},[t]),[e,o,n.hasAuth]}import{jsx as Pe}from"react/jsx-runtime";var te=Qe(null),Vr=Qe(null);Vr.displayName="CurrentAuth";var kr=Qe(null);kr.displayName="AuthActions";function $t({children:e}){let n=Er(()=>Et(),[]);return Pe(te.Provider,{value:n,children:e})}function Dt(){return!!Ft(te)}function me(){let e=Ft(te);if(!e)throw new Error("useAuthActions must be used within a AuthProvider");return e}function Nr(){let e=me();return de(e,t=>({login:t.login,logout:t.logout,nextAuth:t.nextAuth,previousAuth:t.previousAuth,setAuth:t.setAuth,addService:t.addService,removeService:t.removeService}))}function ps(){let e=me();return de(e,n=>n)}function Lr(e){let n=me();return de(n,r=>r.authItems.find(o=>o.service.id===e))}function Ht(e){let n=me();return de(n,r=>r.authItems.find(o=>o.id===e)?.session?.token)}function gs(e){let n=me();return de(n,r=>{let o=r.authItems.find(s=>s.service.id===e);return!o||!o.isLoggedIn||!o.session?null:o.session?.token||null})}function zr(e){let n=Nr(),t=Lr(e.service.id);return wr(()=>(n?.addService(e.service,e.probeId),()=>{n?.removeService(e.service,e.probeId)}),[e.service]),t?(t.error||!t.isLoggedIn,e.children):null}function Ye(){return null}function Ut(e){let[n,t,r]=Ot(e.resource),o=e.fallbackComponent||Ye,s=e.loadingComponent||Ye,i=e.errorComponent||Ye,a=t.service,u=null;if(!r||!a)return e.children(n);let c=a.service.filter(l=>l.type==="AuthAccessService2");t.status==="error"&&(u=Pe(i,{resource:e.resource,error:t.error||"",heading:t.errorHeading,note:t.errorNote,extra:e.extra})),(t.status==="unknown"||t.status==="probing")&&(u=Pe(s,{})),t.status==="success"&&(u=e.children(n));for(let l of c)u=Pe(zr,{service:l,probeId:a.id,children:u},l.id);return u}import{createContext as $r,useContext as Ps,useMemo as Dr}from"react";import{createStore as Or}from"zustand/vanilla";var Hr=e=>e.id||e["@id"];function Fr(e){return(Array.isArray(e.service)?e.service:[e.service]).find(t=>t.profile==="http://iiif.io/api/search/0/autocomplete"||t.profile==="http://iiif.io/api/search/1/autocomplete"||t.profile==="AutoCompleteService1")}var qt=e=>{let n;typeof e=="string"?n={"@context":"http://iiif.io/api/search/1/context.json",profile:"http://iiif.io/api/search/1/search","@id":e,id:e,service:[]}:n=e;let t=n?Hr(n):void 0,r=null;return Or((o,s)=>({service:n,resources:[],lastQuery:{},loading:!1,error:!1,highlight:null,hasSearch:!!n,hasAutocomplete:n?!!Fr(n):!1,errorMessage:"",search(i,a={}){if(!t)throw new Error("No search service found.");r&&!r.signal.aborted&&r.abort(),r=new AbortController;let u=new URLSearchParams;i.q&&u.set("q",i.q),i.motivation&&u.set("motivation",i.motivation),i.date&&u.set("date",i.date),i.user&&u.set("user",i.user),o({loading:!0}),fetch(`${t}?${u.toString()}`,{signal:r.signal,headers:{"Content-Type":"application/json",Accept:"application/json",...a.headers||{}}}).then(async c=>{if(!r?.signal.aborted)if(c.ok){let l=await c.json();o({resources:l.resources,error:!1,errorMessage:""})}else o({resources:[],error:!0,errorMessage:c.statusText})})},clearSearch(){o({resources:[],error:!1,errorMessage:""})},highlightResult(i){let a=s().resources.find(u=>u["@id"]===i);o({highlight:a})},nextResult(){let i=s().resources,a=s().highlight;if(!a){o({highlight:i[0]||null});return}let u=i.findIndex(c=>c["@id"]===a["@id"]);if(u===-1){o({highlight:i[0]||null});return}o({highlight:i[u+1]||i[0]||null})},previousResult(){let i=s().resources,a=s().highlight;if(!a){o({highlight:i[i.length-1]||null});return}let u=i.findIndex(c=>c["@id"]===a["@id"]);if(u===-1){o({highlight:i[i.length-1]||null});return}if(u===0){o({highlight:i[i.length-1]||null});return}o({highlight:i[u-1]||i[i.length-1]||null})}}))};import{useStore as ws}from"zustand";function Bt(){let e=E();return e?e.service.find(n=>n.profile==="SearchService1"||n.profile==="http://iiif.io/api/search/1/search"):void 0}import{jsx as We}from"react/jsx-runtime";var ne=$r(null);ne.displayName="Search";function _t(e){let n=Bt();return e.store?We(ne.Provider,{value:e.store,children:e.children}):We(Ur,{service:n,children:e.children})}function Ur({service:e,children:n}){let t=Dr(()=>qt(e),[e]);return We(ne.Provider,{value:t,children:n})}import{jsx as z}from"react/jsx-runtime";var fe=()=>{},pe=Br({setCurrentCanvasId:fe,setCurrentCanvasIndex:fe,nextCanvas:fe,previousCanvas:fe,items:[],sequence:[],setSequenceIndex:fe,currentSequenceIndex:0,hasNext:!1,hasPrevious:!1});function jr(e){let n=E(),{cursor:t,visibleItems:r,next:o,sequence:s,items:i,setCanvasIndex:a,setCanvasId:u,previous:c,setSequenceIndex:l,hasNext:d,hasPrevious:y}=It({startCanvas:e.startCanvas,disablePaging:e.pagingEnabled===!1}),A=_r(()=>({sequence:s,items:i,setCurrentCanvasId:u,nextCanvas:o,previousCanvas:c,totalCanvases:i.length,setCurrentCanvasIndex:a,setSequenceIndex:l,currentSequenceIndex:t,hasNext:d,hasPrevious:y}),[s,i,u,o,c,i,a,l,t]);return n?r.length===0?null:z(pe.Provider,{value:A,children:z(ee.Provider,{value:r,children:z(q,{canvas:r[0],children:e.children})})}):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),z("div",{children:"Sorry, something went wrong."}))}function jt(e){let n=X(e.vault),t=At(e.manifest);if(!t)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),z("div",{children:"Sorry, something went wrong."});if(t.error)return z("div",{children:t.error.toString()});if(!t.isLoaded)return z("div",{children:"Loading..."});let r=z(jr,{...e,children:e.children});return z(J,{vault:n,children:z(bt,{manifest:t.id,children:z($t,{children:z(_t,{children:e.rangeId?z(Pt,{range:e.rangeId,children:r}):r})})})})}function Kt(){return qr(pe)}import Kr from"react";import{createContext as Yr,useMemo as Qr}from"react";import Wr from"mitt";import{jsx as Zr}from"react/jsx-runtime";var Gr=Wr(),re=Yr({emitter:Gr});re.displayName="Events";function Yt(){return Kr.useContext(re).emitter}function au({emitter:e,children:n}){return Zr(re.Provider,{value:Qr(()=>({emitter:e}),[e]),children:n})}import{jsx as oe}from"react/jsx-runtime";function Qt(){return{VaultContext:W(Q),ResourceContext:W(Ce),SimpleViewerReactContext:W(pe),VisibleCanvasReactContext:W(ee),AuthRContext:W(te),SearchReactContext:W(ne),ReactEventContext:W(re)}}function Wt(e){return oe(J,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext,children:oe(ee.Provider,{value:e.bridge.VisibleCanvasReactContext,children:oe(pe.Provider,{value:e.bridge.SimpleViewerReactContext,children:oe(re.Provider,{value:e.bridge.ReactEventContext,children:oe(te.Provider,{value:e.bridge.AuthRContext,children:oe(ne.Provider,{value:e.bridge.SearchReactContext,children:e.children})})})})})})}import{createContext as no,useContext as ro,useMemo as oo}from"react";import{useCallback as Zt,useLayoutEffect as Xr,useMemo as eo,useRef as to}from"react";import{entityActions as Ge}from"@iiif/helpers/vault/actions";import{useMemo as Jr}from"react";function Gt(){let n=R().getStore();return Jr(()=>t=>n.dispatch(t),[n])}function Jt(e){return typeof e!="string"&&e&&e.bindToVault}function Xt(){let e=R(),n=to([]),t=Gt(),r=eo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);Xr(()=>{let a={id:r,type:"AnnotationPage",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],rendering:[],service:[]};t(Ge.importEntities({entities:{AnnotationPage:{[a.id]:a}}}))},[r]);let o=T(a=>r&&a.iiif.entities.AnnotationPage[r]||null,[r]),s=Zt((a,u)=>{if(r){if(Jt(a)){let d=a;d.__vault||d.bindToVault(e),a=typeof d.source=="string"?d.source:d.source.id,n.current[a]=d}else typeof a!="string"&&(a=a.id);let c=e.get({id:r,type:"AnnotationPage"}),l=e.get({id:a,type:"Annotation"});c&&l&&(c.items.find(d=>d.id===l.id)||t(Ge.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"},index:u})))}},[r]),i=Zt(a=>{r&&(Jt(a)?a=typeof a.source=="string"?a.source:a.source.id:typeof a!="string"&&(a=a.id),n.current[a]&&n.current[a].beforeRemove(),e.get({id:r,type:"AnnotationPage"})&&t(Ge.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"}})))},[r]);return[o,{addAnnotation:s,removeAnnotation:i}]}import{jsx as io}from"react/jsx-runtime";var en=no(null);function tn(){let e=ro(en);return[e.fullPage,{addAnnotation:e.addAnnotation,removeAnnotation:e.removeAnnotation}]}function nn({children:e}){let[n,{addAnnotation:t,removeAnnotation:r}]=Xt();return io(en.Provider,{value:oo(()=>({fullPage:n,addAnnotation:t,removeAnnotation:r}),[n]),children:e})}import{jsx as Ze,jsxs as ao}from"react/jsx-runtime";function rn({width:e,style:n,height:t,error:r,resetErrorBoundary:o}){return ao("div",{style:{width:e,height:t,minHeight:500,...n||{},background:"#f9f9f9"},children:[Ze("h3",{children:"Error occurred"}),Ze("p",{children:r.message}),Ze("button",{onClick:o,children:"Reset"})]})}import{createContext as so,useContext as uo}from"react";var ge=so(null);function on(){return uo(ge)}import{createContext as an,useContext as co,useEffect as lo}from"react";var Je=an(()=>{}),Xe=an(()=>{});function O(e,n,t,r,o=[]){let s=co(e==="portal"?Xe:Je);lo(()=>(e!=="none"&&s(n,t,r),()=>{s(n,null)}),[n,e,s,...o])}import{createContext as fo,useContext as po,useEffect as go}from"react";import{useMemo as mo}from"react";function M(e={},n=[]){let{id:t,selector:r}=e,o=H(),s=t||o.canvas,i=T(a=>s?a.iiif.entities.Canvas[s]:void 0,[s]);return mo(()=>{if(i)return r?r(i):i},[i,r,...n])}var et=fo(()=>{});function sn(e){let n=M(),t=po(et);go(()=>n&&n.id?(t(n.id,e),()=>t(n.id,-1)):()=>{},[n,e])}import{Fragment as xo,jsx as V,jsxs as So}from"react/jsx-runtime";function ln({children:e,errorFallback:n,outerContainerProps:t={},worldScale:r,...o}){let[s,i]=Re(),a=Qt(),u=n||rn,[c,l]=Re({}),d=Object.entries(c),[y,A]=Re({}),h=Object.entries(y),[g,b]=Re({}),p=cn(()=>r||Math.max(...Object.values(g)),[g]),S=cn(()=>({maxOverZoom:p||1,...o.runtimeOptions||{}}),[p,o.runtimeOptions]),m=tt((x,P)=>{b(C=>{if(P===-1){let{[x]:_,...f}=C;return f}return{...C,[x]:P}})},[]),v=tt((x,P,C)=>{l(({[x]:_,...f})=>P?{...f,[x]:{element:P,props:C}}:f)},[]),I=tt((x,P,C)=>{A(({[x]:_,...f})=>P?{...f,[x]:{element:P,props:C}}:f)},[]);return So(yo,{resetKeys:[],fallbackRender:x=>V(u,{...o,...x}),children:[V(vo,{...o,containerProps:{style:{position:"relative"},...o.containerProps||{}},htmlChildren:V(xo,{children:d.map(([x,{element:P,props:C}])=>V(un.Fragment,{children:V(P,{...C||{}})},x))}),onCreated:x=>{i(x),o.onCreated&&o.onCreated(x)},runtimeOptions:S,children:V(ge.Provider,{value:s,children:V(et.Provider,{value:m,children:V(Je.Provider,{value:v,children:V(Xe.Provider,{value:I,children:V(Wt,{bridge:a,children:V(ho.Provider,{value:o.mode||"explore",children:V(nn,{children:e})})})})})})})}),V("div",{children:h.map(([x,{element:P,props:C}])=>V(un.Fragment,{children:V(P,{...C||{}})},x))})]})}import{mergeStyles as To,RegionHighlight as Io}from"@atlas-viewer/atlas";import{useMemo as dn}from"react";import{createEventsHelper as Co}from"@iiif/helpers/events";function Te(e,n){let t=R(),r=dn(()=>Co(t),[t]),o=T(()=>e&&e.id?t.getResourceMeta(e.id,"eventManager"):null,[e]);return dn(()=>e?r.getListenersAsProps(e,n):{},[o,e,t,n])}import{useMemo as Ao}from"react";import{createStylesHelper as bo}from"@iiif/helpers/styles";function ie(e,n){let t=R(),r=Ao(()=>bo(t),[t]);return T(()=>{if(!e)return null;let o=r.getAppliedStyles(e.id);return o?n?o[n]:o:void 0},[e,n])}import{useMemo as Mo}from"react";import{useMemo as Po}from"react";import{expandTarget as Ro}from"@iiif/helpers/annotation-targets";function Ie(e={},n=[]){let{id:t,selector:r}=e,o=H(),s=R(),i=t||o.annotation,a=T(c=>i?c.iiif.entities.Annotation[i]:void 0,[i]),u=T(c=>a&&a.body?a.body.map(l=>l?l.type==="SpecificResource"?{...l,source:s.get(l)}:l?c.iiif.entities[l.type][l.id]:null:null).filter(Boolean):[],[a]);return Po(()=>{if(!a)return;let c={...a,body:u,target:Ro(a.target,{typeMap:s.getState().iiif.mapping})};return r?r(c):c},[a,r,u,...n])}import{jsx as wo}from"react/jsx-runtime";var Me=({id:e,style:n,className:t,interactive:r})=>{let o=Ie({id:e}),s=ie(o,"atlas"),i=ie(o,"html"),a=Te(o,["atlas"]),u=M(),c=Mo(()=>To(n,s),[n,s]);return u&&o&&o.target&&o.target.selector&&o.target.selector.type==="BoxSelector"&&o.target.source&&(o.target.source.id===u.id||o.target.source===u.id)?wo(Io,{id:o.id,isEditing:!0,region:o.target.selector.spatial,style:c,className:i?.className||t,interactive:!!(i?.href||r),href:i?.href||null,title:i?.title||null,hrefTarget:i?.target||null,onClick:()=>{},...a}):null};import{Fragment as Vo}from"react";import{useMemo as Eo}from"react";function mn(e={},n=[]){let{id:t,selector:r}=e,o=H(),s=t||o.annotationPage,i=T(a=>s?a.iiif.entities.AnnotationPage[s]:void 0,[s]);return Eo(()=>{if(i)return r?r(i):i},[i,...n])}import{jsx as fn}from"react/jsx-runtime";var ve=({className:e,page:n})=>{let t=mn({id:n.id})||n,r=ie(t,"atlas"),o=ie(t,"html");return T(s=>t.id?s.iiif.entities.AnnotationPage[t.id]:null,[]),fn(Vo,{children:t.items?.map(s=>fn(Me,{id:s.id,style:r,className:o?.className||e},s.id))})};import{createStylesHelper as Vi}from"@iiif/helpers/styles";import{Fragment as bn,useMemo as Fo}from"react";import{HTMLPortal as zo,TileSet as Cn}from"@atlas-viewer/atlas";import ae,{useMemo as nt}from"react";import{jsx as $}from"react/jsx-runtime";var gn=ae.createContext("en"),vn=ae.createContext({}),hn=ae.createContext(null);function Xc(e){return $(vn.Provider,{value:e.translations,children:e.children})}function el(e){return $(gn.Provider,{value:e.language,children:e.children})}function tl(e){return $(hn.Provider,{value:e.convert,children:e.children})}function yn(){return ae.useContext(hn)}function rt(){return ae.useContext(gn)}function xn(){return ae.useContext(vn)}function pn(e){return e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):e}function ko({as:e,language:n,children:t,viewingDirection:r,...o}){let s=rt();return nt(()=>pn(s)===pn(n),[s,n])?e?$(e,{...o,children:t}):$("span",{...o,children:t}):e?$(e,{...o,lang:n,dir:r,children:t}):$("span",{...o,lang:n,dir:r,children:t})}function Sn(e,n,t){if(n.length===0)return;if(n.length===1)return n[0];if(n.indexOf(e)!==-1)return e;let r=e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):null;if(r&&n.indexOf(r)!==-1)return r;for(let o of t)if(n.indexOf(o)!==-1)return o;return n.indexOf("none")!==-1?"none":n.indexOf("@none")!==-1?"@none":n[0]}var No=(e,n=[])=>{let t=rt();return nt(()=>{let r=e();return Sn(t,r,[])},[t,...n])};function G(e,n,t,r){return n?t?t(e[n]||n,r||"none"):e[n]||n:""}function Lo(e,n,t=`
2
2
  `,r={}){let o=yn(),s=No(()=>Object.keys(e||{}),[e]);return[nt(()=>{if(!e)return G(r,n,o)||"";if(typeof e=="string")return G(r,e,o);let i=s?e[s]:void 0;return i?typeof i=="string"?i:i.map(a=>G(r,a,o,s)).join(t):""},[s,n,e]),s]}function nl(){let e=rt(),n=xn(),t=yn();return function(o,s="",i=`
3
3
  `,a=n){let u=Object.keys(o||{}),c=Sn(e,u,[]);if(!o)return G(a,s,t)||"";if(typeof o=="string")return G(a,o,t);let l=c?o[c]:void 0;return l?typeof l=="string"?G(a,l,t,c):l.map(d=>G(a,d,t,c)).join(typeof i<"u"?i:`
4
4
  `):""}}function he({as:e,defaultText:n,enableDangerouslySetInnerHTML:t,children:r,separator:o,...s}){let i=xn(),[a,u]=Lo(r,n,o,i);return u?$(ko,{...s,as:e,language:u,title:t?void 0:a,dangerouslySetInnerHTML:t?{__html:a}:void 0,children:t?void 0:a}):e?$(e,{...s,children:a}):$("span",{...s,title:t?void 0:a,dangerouslySetInnerHTML:t?{__html:a}:void 0,children:t?void 0:a})}import{jsx as B,jsxs as Ho}from"react/jsx-runtime";function Oo({resource:e,heading:n,note:t,extra:r}){return r?B(zo,{target:{x:0,y:0,width:r.target?.spatial.width,height:r.target?.spatial.height},backgroundColor:"#333",relative:!0,children:B("div",{style:{display:"flex",alignContent:"center",justifyContent:"center",alignItems:"center",height:"100%",width:"100%",background:"#444",color:"#BBB"},children:Ho("div",{children:[B(he,{children:n||"Not authorised"}),t&&B("p",{children:B(he,{children:t})}),B("p",{children:e.id||e["@id"]||"unknown"})]})})}):null}function An({image:e,thumbnail:n,crop:t,enableSizes:r}){if(!Dt()){let s=e.service,i=s.width||e.width||0,a=s.height||e.height||0;return B(Cn,{tiles:{id:s.id||s["@id"]||"unknown",height:a,width:i,imageService:s},enableSizes:r,x:0,y:0,width:e.target?.spatial.width,height:e.target?.spatial.height,crop:t})}return B(Ut,{resource:e.service,errorComponent:Oo,extra:e,children:s=>{let i=s.width||e.width||0,a=s.height||e.height||0;return B(Cn,{tiles:{id:s.id||s["@id"]||"unknown",height:a,width:i,imageService:s},enableSizes:r,x:0,y:0,width:e.target?.spatial.width,height:e.target?.spatial.height,crop:t})}},e.id)}import{jsx as ot,jsxs as Pn}from"react/jsx-runtime";function se({id:e,image:n,thumbnail:t,isStatic:r,x:o=0,y:s=0,children:i,selector:a,onClick:u,enableSizes:c}){let l=Fo(()=>{if(!(!a||a.spatial.x===0&&a.spatial.y===0))return a.spatial},[a]);return ot("world-object",{x:o+n.target.spatial.x,y:s+n.target.spatial.y,width:n.target.spatial.width,height:n.target.spatial.height,onClick:u,children:n.service?Pn(bn,{children:[ot(An,{image:n,thumbnail:t,crop:l,enableSizes:c}),i]},"service"):Pn(bn,{children:[ot("world-image",{onClick:u,uri:n.id,target:{x:0,y:0,width:n.target.spatial.width,height:n.target.spatial.height},display:n.width&&n.height?{width:n.width,height:n.height}:void 0,crop:l}),i]},"no-service")},e+(n.service?"server":"no-service"))}import{Fragment as ki,useEffect as Jn,useLayoutEffect as Ni,useMemo as Xn}from"react";import{useEffect as Ln,useMemo as zn}from"react";import{useCallback as In,useMemo as Do}from"react";function $o(e,n){let t=e?.iiif?.meta[n];return t?t.annotationPageManager:null}function Rn(e,n){return T(t=>{let r=[];if(!e)return r;let o=Object.keys(t.iiif.entities.AnnotationPage);for(let s of o)if(!n||n.indexOf(s)!==-1){let i=$o(t,s);i&&i.views&&i.views[e]&&r.push(s)}return r},[e,n])}function Tn({canvas:e,manifest:n,all:t,canvases:r}){let o=[];if(n)for(let s of n.annotations)o.indexOf(s.id)===-1&&o.push(s.id);if(t){if(r&&r.length)for(let s of r)for(let i of s.annotations)o.indexOf(i.id)===-1&&o.push(i.id)}else if(e)for(let s of e.annotations)o.indexOf(s.id)===-1&&o.push(s.id);return o}function Uo(e,n){let t=e?.iiif?.meta[n];return t?t.annotationPageManager:null}function Mn(e,n={}){let t=R(),r=E(),o=M(),s=Ae(),i=Do(()=>Tn({all:n.all,manifest:r,canvas:o,canvases:s}),[n.all,o,s,r]),a=Rn(e,n.all?void 0:i),u=In(l=>{e&&t.setMetaValue([l,"annotationPageManager","views"],d=>d&&!d[e]?d:{...d||{},[e]:!1})},[e,t]),c=In((l,d={})=>{if(!e)return;let y=t.getState(),A=[];if(d?.deselectOthers){let h=Object.keys(y.iiif.entities.AnnotationPage);for(let g of h){let b=Uo(y,g);b&&b.views&&b.views[e]&&A.push(g)}}for(let h of A)u(h);t.setMetaValue([l,"annotationPageManager","views"],h=>h&&h[e]?h:{...h||{},[e]:!0})},[e,u,t]);return{availablePageIds:i,enabledPageIds:a,setPageEnabled:c,setPageDisabled:u}}function wn(e,n){return T((t,r)=>r.get(e.map(o=>({id:o,type:n}))),[e,n])}import{useCallback as Ko,useEffect as Yo,useRef as Qo,useState as Wo}from"react";import qo,{useContext as Bo}from"react";import{ImageServiceLoader as _o}from"@atlas-viewer/iiif-image-api";var jo=qo.createContext(new _o);function we(){return Bo(jo)}function En(){let e=we(),[n,t]=Wo({}),r=Qo(!1);return Yo(()=>()=>{r.current=!0},[]),[Ko((s,{height:i,width:a})=>{if(s){let u=s.id||s["@id"],c=e.loadServiceSync({id:u,width:s.width||a,height:s.height||i,source:s});c?s=c:n[u]||(r.current||t(l=>({...l,[u]:"loading"})),e.loadService({id:u,width:s.width||a,height:s.height||i}).then(()=>{r.current||t(l=>({...l,[u]:"done"}))}))}return s},[e,n]),n]}import{useCallback as Go,useMemo as kn,useState as Zo}from"react";function Vn(e={}){let n=Ie(),t=M(e.canvasId?{id:e.canvasId}:void 0);return T((r,o)=>{if(!t)return[];if(n&&e.enableSingleAnnotation)return[n];let s=o.get(t.items),i=[];for(let a of s)i.push(...o.get(a.items));return i},[t])}import{createPaintingAnnotationsHelper as Jo}from"@iiif/helpers/painting-annotations";function Nn(e,n=[]){let t=R(),r=kn(()=>Jo(t),[]),o=Vn({enableSingleAnnotation:e?.enableSingleAnnotation}),[s,i]=Zo(e?.defaultChoices||[]),a=kn(()=>r.getPaintables(o,s),[t,o,s,...n]),c={makeChoice:Go((l,{deselectOthers:d=!0,deselect:y=!1}={})=>{a.choice&&i(A=>{if(y){let g=A.filter(b=>b!==l);if(g.length===0){let b=a.items[0].resource.id;return b?[b]:[]}return g}if(d)return[l];let h=[...A];if(h.length===0&&a.items.length){let g=a.items[0].resource.id;g&&h.push(g)}return A.indexOf(l)!==-1?A:[...A,l]})},[a.choice])};return[a,c]}function On(e){let n=E(),t=M(),r=R(),o=Yt(),s=e?.emitter||o,[i,a]=En(),{enabledPageIds:u}=Mn(e?.annotationPageManagerId||n?.id||t?.id,{all:!1}),c=wn(u,"AnnotationPage"),l=e?.strategies||["empty","images","media","textual-content","complex-timeline"],[d,y]=Nn(e,[a]);Ln(()=>{let h=g=>{y.makeChoice(g.choiceId,{deselectOthers:g.deselectOthers,deselect:g.deselect})};return s.on("make-choice",h),()=>{s.off("make-choice",h)}},[]);let A=zn(()=>yt({canvas:t,paintables:d,supports:l,loadImageService:i}),[t,d,r,y.makeChoice]);return Ln(()=>{let h=d.allChoices,g={canvasId:t?.id,manifestId:n?.id};h&&s.emit("choice-change",{choice:h,partOf:g})},[t?.id,d.allChoices]),zn(()=>A.type==="unknown"?[A,ht]:[{...A,annotations:{pages:c}},y],[A,c])}import{useEffect as ei,useMemo as ti,useRef as ni,useState as ri}from"react";import{useEffect as Xo}from"react";var Hn=(e,n=[])=>{let t=R();Xo(()=>{e(t)},[t,...n])};import{createThumbnailHelper as oi}from"@iiif/helpers/thumbnail";function Ee(e,n,{canvasId:t,manifestId:r}={}){let o=R(),s=we(),i=ti(()=>oi(o,{imageServiceLoader:s}),[o,s]),[a,u]=ri(),c=E(r?{id:r}:void 0),l=M(t?{id:t}:void 0),d=l||c,y=ni(!1);if(ei(()=>(y.current=!1,()=>{y.current=!0}),[]),!d)throw new Error("Must be called under a manifest or canvas context.");return Hn(A=>{i.getBestThumbnailAtSize(d,e,n).then(h=>{h.best&&!y.current&&u(h.best)})},[d]),a}import{useCallback as D,useEffect as Fn,useReducer as ii,useRef as Ve}from"react";function ai(e){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:e}}function si(e,n){switch(n.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:n.volume,isMuted:n.volume===0};case"TOGGLE_MUTE":return{...e,isMuted:!e.isMuted};case"UNMUTE":return{...e,isMuted:!1}}return e}function it(e){let n=Math.round(e);return`${Math.floor(n/60)}:${`${n%60}`.padStart(2,"0")}`}function ue(e){let[n,t]=ii(si,ai(e.duration)),r=Ve(null),o=Ve(null),s=Ve(null),i=Ve(!1),a=D(()=>{o.current&&r.current&&(o.current.innerHTML=it(r.current.currentTime),s.current&&(s.current.style.width=`${r.current.currentTime/e.duration*100}%`),i.current!==r.current.muted&&(i.current=r.current.muted,t(r.current.muted?{type:"MUTE"}:{type:"UNMUTE"})))},[e.duration]),u=D(()=>{r.current&&(t({type:"PLAY_REQUESTED"}),r.current.play().then(()=>{t({type:"PLAY"})}),a())},[a]),c=D(()=>{r.current&&(r.current.duration>0&&r.current.paused?u():l())},[a]),l=D(()=>{r.current&&(r.current.pause(),t({type:"PAUSE"}),a())},[a]),d=D(()=>{r.current&&(r.current.muted=!r.current.muted,t(r.current.muted?{type:"MUTE"}:{type:"UNMUTE"}))},[]),y=D(()=>{r.current&&(r.current.muted=!0,t({type:"MUTE"}))},[]),A=D(()=>{r.current&&(r.current.muted=!1,t({type:"UNMUTE"}))},[]),h=D(p=>{r.current&&(r.current.muted=!1,r.current.volume=p/100,t({type:"SET_VOLUME",volume:p}))},[]),g=D(p=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(p*e.duration,e.duration)),a())},[]),b=D(p=>{if(r.current){let S=typeof p=="function"?p(r.current.currentTime):p;r.current.currentTime=Math.max(0,Math.min(S,e.duration)),a()}},[]);return Fn(()=>{let p=setInterval(()=>{a()},350);return()=>clearInterval(p)},[a,e.duration]),Fn(()=>{let p=()=>{t({type:"FINISHED"})},S=r.current;return S?.addEventListener("ended",p),()=>S?.removeEventListener("ended",p)},[]),[{element:r,currentTime:o,progress:s},n,{play:u,pause:l,playPause:c,mute:y,unmute:A,toggleMute:d,setVolume:h,setDurationPercent:g,setTime:b}]}import{createContext as st,useContext as ut}from"react";import{jsx as at}from"react/jsx-runtime";var $n=st(null),Dn=st(null),Un=st(null);function xd(){let e=ut($n);if(!e)throw new Error("Ctx not found");return e}function Sd(){let e=ut(Dn);if(!e)throw new Error("Ctx not found");return e}function Cd(){let e=ut(Un);if(!e)throw new Error("Ctx not found");return e}function ke({actions:e,state:n,children:t,currentTime:r,progress:o,element:s}){return at(Un.Provider,{value:{currentTime:r,progress:o,element:s},children:at(Dn.Provider,{value:e,children:at($n.Provider,{value:n,children:t})})})}import{useMemo as ui}from"react";import{expandTarget as ci}from"@iiif/helpers";function Ne(){let e=E(),n=M();return ui(()=>{if(!e||!n||!e.start)return null;let t=ci(e.start);return!t||t.source.id!==n.id||!t||!t.selector||t.selector.type!=="TemporalSelector"?null:t.selector.temporal},[e,n])}import{jsx as li,jsxs as di}from"react/jsx-runtime";function ct({media:e,startTime:n,children:t}){let[{element:r,currentTime:o,progress:s},i,a]=ue({duration:e.duration}),u=n?`${e.url}#t=${n}`:e.url;return di(ke,{state:i,actions:a,currentTime:o,progress:s,element:r,children:[li("audio",{ref:r,src:u}),t]})}function Le({media:e,mediaControlsDeps:n,children:t}){let r=Ne();return O("portal","audio",ct,{media:e,startTime:r?r.startTime:null,children:t},[e,r,...n||[]]),null}import{jsx as qn,jsxs as mi}from"react/jsx-runtime";function lt({element:e,media:n,startTime:t,playPause:r,poster:o}){let s="div",i=t?`${n.url}#t=${t}`:n.url;return mi(s,{className:"video-container",part:"video-container",onClick:r,children:[qn("style",{children:`
@@ -0,0 +1 @@
1
+ import{expandTarget as v}from"@iiif/helpers";function M(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function f(e,r){let{selector:a,source:o}=v(r);if(o.id!==e.id)return[null,o];let t={type:"BoxSelector",spatial:{x:0,y:0,width:Number(e.width),height:Number(e.height)}};return[a?a.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:a.temporal,spatial:t.spatial}:a:null,o]}var L={makeChoice:()=>{}},S={type:"unknown"},m=e=>({type:"unknown",reason:e,annotations:{pages:[]}}),C=(e,r)=>({type:"empty",width:e,height:r,annotations:{pages:[]},image:null,images:[]});var N=["model/gltf-binary"];function I(e,r){let o=r.items[0].resource;return o.format?N.indexOf(o.format)===-1?m(`3D format: ${o.format} is unsupported`):{type:"3d-model",model:o}:m("Unknown format")}import{getImageServices as z}from"@atlas-viewer/iiif-image-api";import{expandTarget as w}from"@iiif/helpers/annotation-targets";function h(e,r,a){let o=[];for(let t of r.items){let p=t.resource&&t.resource.type==="SpecificResource"?t.resource.source:t.resource;if(!p.id)return m("No resource Identifier");let c;if(p.service){let y=z(p);y[0]&&(c=a(y[0],e))}let d={type:"BoxSelector",spatial:{x:0,y:0,width:Number(e.width),height:Number(e.height)}},[i,n]=f(e,t.target),s=e.id?.split("?")[0]||"";if(!(n.id===e.id||decodeURIComponent(n.id||"")===(e.id||"")||n.id===s||decodeURIComponent(n.id||"")===s))continue;let l=t.resource.width&&t.resource.height?{type:"BoxSelector",spatial:{x:0,y:0,width:t.resource.width,height:t.resource.height}}:void 0,u=t.resource.type==="SpecificResource"?w(t.resource):null;if(t.selector){let y=w({type:"SpecificResource",source:t.resource,selector:t.selector});y&&(u=y)}let g=u&&u.selector&&(u.selector.type==="BoxSelector"||u.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:u.selector.spatial.x,y:u.selector.spatial.y,width:u.selector.spatial.width,height:u.selector.spatial.height}}:void 0;c&&!c.id&&(c.id=c["@id"]);let R={id:p.id,type:"Image",annotationId:t.annotationId,width:Number(i||g?p.width:e.width),height:Number(i||g?p.height:e.height),service:c,sizes:c&&c.sizes?c.sizes:p.width&&p.height?[{width:p.width,height:p.height}]:[],target:i&&i.type!=="PointSelector"?i:d,selector:g||{type:"BoxSelector",spatial:{x:0,y:0,width:Number(e.width),height:Number(e.height)}}};o.push(R)}return{type:"images",image:o[0],images:o,choice:r.choice}}function b(e,r={},a){let o=e.language||a||"none";switch(e.type){case"TextualBody":{typeof e.value<"u"&&(r[o]=[e.value]);break}case"List":case"Composite":case"Choice":e.items&&e.items.forEach(t=>b(t,r,o))}return r}function x(e,r){let a=[];return r.items.forEach(o=>{if(o.resource){let[t]=f(e,o.target);a.push({type:"Text",annotationId:o.annotationId,text:b(o.resource),target:t})}}),{type:"textual-content",items:a}}import{expandTarget as B,parseSelector as D}from"@iiif/helpers";var O=/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?vi?=|&vi?=))([^#&?]*).*/;function T(e,r){let a=r.items.filter(s=>s.type==="video"),o=!1;if(e.duration||(o=!0),a.length>1)return m("Only one video source supported");let t=a[0]?.resource,p=!!(t.service||[]).find(s=>(s.profile||"").includes("youtube.com"));if(!p&&o)return m("Video does not have duration");if(!t)return m("Unknown video");if((!t.format||t.format==="text/html")&&!p)return m("Video does not have format");let c=r.items[0],d={annotationId:r.items[0].annotationId,duration:e.duration,url:t.id,type:"Video",target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:t.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}},i=B(c.target);i.selector&&i.selector.type==="TemporalBoxSelector"&&(d.target=i.selector);let{selector:n}=D(c.selector);if(n===null){let s=d.target.temporal.startTime,u=(d.target.temporal.endTime||e.duration)-s;d.selector={type:"TemporalSelector",temporal:{startTime:0,endTime:u}}}else n.type==="TemporalSelector"&&(d.selector=n);if(p){d.type="VideoYouTube";let s=t.id.match(O);if(!s[1])return m("Video is not known youtube video");d.youTubeId=s[1]}return{type:"media",media:d,annotations:{pages:[]}}}function P(e,r,a){let o={type:"complex-timeline",items:[],keyframes:[],duration:e.duration||0},t={type:"complex-choice",items:[]};function p(i){i.choice&&(i.choice.type==="complex-choice"?t.items.push(...i.choice.items):t.items.push(i.choice))}for(let i of r.items){if(i.type==="image"){let n=h(e,{choice:null,allChoices:null,types:["image"],items:[i]},a);if(n.type==="images"){p(n),o.items.push(n.image);let s={id:n.image.annotationId,type:"enter",resourceType:"image",time:n.image.target?.temporal?.startTime||0};o.keyframes.push(s);let l={id:n.image.annotationId,type:"exit",resourceType:"image",time:n.image.target?.temporal?.endTime||e.duration||0};o.keyframes.push(l)}}if(i.type==="textualbody"){let n=x(e,{choice:null,allChoices:null,types:["textualbody"],items:[i]});if(n.type==="textual-content"){p(n);let s=n.items[0];o.items.push(s);let l=s.target,u={id:s.annotationId,type:"enter",resourceType:"text",time:l.temporal?.startTime||0};o.keyframes.push(u);let g={id:s.annotationId,type:"exit",resourceType:"text",time:l.temporal?.endTime||e.duration||0};o.keyframes.push(g)}}if(i.type==="video"){let n=T(e,{choice:null,allChoices:null,types:["video"],items:[i]});if(n.type==="media"){p(n);let s=n.media;o.items.push(s);let l={id:s.annotationId,type:"enter",resourceType:"video",time:s.target?.temporal?.startTime||0};o.keyframes.push(l);let u={id:s.annotationId,type:"exit",resourceType:"video",time:s.target?.temporal?.endTime||e.duration||0};o.keyframes.push(u)}}}o.keyframes.sort((i,n)=>i.time-n.time);let c=[],d=[];for(let i of o.keyframes){if(i.resourceType==="image"||i.resourceType==="text"){d.push(i);continue}if(i.type==="enter"){c.length===0&&(i.isPrime=!0),c.push(i),d.push(i);continue}if(i.type==="exit"&&(d.push(i),c=c.filter(n=>n.id!==i.id),c.length!==0)){let n=c[0],s={id:n.id,type:"change",isPrime:!0,resourceType:n.resourceType,time:i.time};d.push(s)}}return o.keyframes=d,t.items.length&&(o.choice=t),o}function k(e,r){if(!e.duration)return m("No duration on canvas");if(r.items.length>1)return m("Only one audio source supported");let a=r.items[0]?.resource;return a?a.format?{type:"media",media:{annotationId:r.items[0].annotationId,duration:e.duration,url:a.id,type:"Sound",target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:a.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}},annotations:{pages:[]}}:m("Audio does not have format"):m("Unknown audio")}function ue({canvas:e,paintables:r,supports:a,loadImageService:o}){if(!e)return S;if(r.types.length===0)return a.indexOf("empty")!==-1?C(e.width,e.height):S;if(r.types.length!==1)if(r.types.length===2&&r.types.indexOf("text")!==-1)r.types=r.types.filter(p=>p!=="text");else return a.indexOf("complex-timeline")===-1?m("Complex timeline not supported"):P(e,r,o);let t=r.types[0];return t==="image"?a.indexOf("images")===-1?m("Image not supported"):h(e,r,o):t==="Model"||t==="model"?a.indexOf("3d-model")===-1?m("3D not supported"):I(e,r):t==="textualbody"?a.indexOf("textual-content")===-1?m("Textual content not supported"):x(e,r):t==="sound"||t==="audio"?a.indexOf("media")===-1?m("Media not supported"):k(e,r):t==="video"?a.indexOf("media")===-1?m("Media not supported"):T(e,r):S}export{M as a,f as b,L as c,S as d,m as e,C as f,I as g,h,x as i,T as j,P as k,ue as l};