react-iiif-vault 1.3.2 → 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,7 +1,7 @@
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 Pe}from"react";import{AtlasAuto as vo,ModeContext as ho}from"@atlas-viewer/atlas";import{ErrorBoundary as yo}from"react-error-boundary";import{useContext as Q}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},Se=nr.createContext(ir),H=()=>rr(Se);function _({value:e,children:n}){let t=H(),r=or(()=>({...t,...e}),[e,t]);return ar(Se.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 Y=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(Y.Provider,{value:{vault:s,setVaultInstance:i},children:St(_,{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(Y);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(_,{value:{manifest:e},children:n})}import{jsx as gr}from"react/jsx-runtime";function q({canvas:e,children:n}){return gr(_,{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(Y);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 Ce(){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(_,{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 Ae,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(C=>C.includes(b));l.current=c,i(p)}let d=Ae(g=>{let b=c.findIndex(p=>p.includes(g));i(b===-1?0:b)},[u,c]),y=Ae(g=>{let b=u.findIndex(p=>p.id===g);b!==-1?d(b):i(0)},[u,c]),A=Ae(()=>{i(g=>g>=c.length-1?g:g+1)},[c]),h=Ae(()=>{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 be}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 be(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=be(i,{resource:e.resource,error:t.error||"",heading:t.errorHeading,note:t.errorNote,extra:e.extra})),(t.status==="unknown"||t.status==="probing")&&(u=be(s,{})),t.status==="success"&&(u=e.children(n));for(let l of c)u=be(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:Q(Y),ResourceContext:Q(Se),SimpleViewerReactContext:Q(pe),VisibleCanvasReactContext:Q(ee),AuthRContext:Q(te),SearchReactContext:Q(ne),ReactEventContext:Q(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]=Pe(),a=Qt(),u=n||rn,[c,l]=Pe({}),d=Object.entries(c),[y,A]=Pe({}),h=Object.entries(y),[g,b]=Pe({}),p=cn(()=>r||Math.max(...Object.values(g)),[g]),C=cn(()=>({maxOverZoom:p||1,...o.runtimeOptions||{}}),[p,o.runtimeOptions]),m=tt((S,P)=>{b(x=>{if(P===-1){let{[S]:K,...f}=x;return f}return{...x,[S]:P}})},[]),v=tt((S,P,x)=>{l(({[S]:K,...f})=>P?{...f,[S]:{element:P,props:x}}:f)},[]),I=tt((S,P,x)=>{A(({[S]:K,...f})=>P?{...f,[S]:{element:P,props:x}}:f)},[]);return So(yo,{resetKeys:[],fallbackRender:S=>V(u,{...o,...S}),children:[V(vo,{...o,containerProps:{style:{position:"relative"},...o.containerProps||{}},htmlChildren:V(xo,{children:d.map(([S,{element:P,props:x}])=>V(un.Fragment,{children:V(P,{...x||{}})},S))}),onCreated:S=>{i(S),o.onCreated&&o.onCreated(S)},runtimeOptions:C,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(([S,{element:P,props:x}])=>V(un.Fragment,{children:V(P,{...x||{}})},S))})]})}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 Re(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 Te(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 Ie=({id:e,style:n,className:t,interactive:r})=>{let o=Te({id:e}),s=ie(o,"atlas"),i=ie(o,"html"),a=Re(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(Ie,{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 W(e,n,t,r){return n?t?t(e[n]||n,r||"none"):e[n]||n:""}function Lo(e,n,t=`
2
- `,r={}){let o=yn(),s=No(()=>Object.keys(e||{}),[e]);return[nt(()=>{if(!e)return W(r,n,o)||"";if(typeof e=="string")return W(r,e,o);let i=s?e[s]:void 0;return i?typeof i=="string"?i:i.map(a=>W(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
- `,a=n){let u=Object.keys(o||{}),c=Sn(e,u,[]);if(!o)return W(a,s,t)||"";if(typeof o=="string")return W(a,o,t);let l=c?o[c]:void 0;return l?typeof l=="string"?W(a,l,t,c):l.map(d=>W(a,d,t,c)).join(typeof i<"u"?i:`
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=Ce(),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 Me(){return Bo(jo)}function En(){let e=Me(),[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=Te(),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 we(e,n,{canvasId:t,manifestId:r}={}){let o=R(),s=Me(),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 Ee}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=Ee(null),o=Ee(null),s=Ee(null),i=Ee(!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=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(p,e.duration)),a())},[]);return Fn(()=>{let p=setInterval(()=>{a()},350);return()=>clearInterval(p)},[a,e.duration]),Fn(()=>{let p=()=>{t({type:"FINISHED"})},C=r.current;return C?.addEventListener("ended",p),()=>C?.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 Ve({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 ke(){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(Ve,{state:i,actions:a,currentTime:o,progress:s,element:r,children:[li("audio",{ref:r,src:u}),t]})}function Ne({media:e,mediaControlsDeps:n,children:t}){let r=ke();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:`
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
+ `,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
+ `,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
+ `):""}}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:`
5
5
  .video-container {
6
6
  position: absolute;
7
7
  top: 0;
@@ -14,7 +14,7 @@ import{c as ht,l as yt}from"./chunk-QCPOOHCR.js";import{forwardRef as er,useImpe
14
14
  justify-content: center;
15
15
  pointer-events: visible;
16
16
  }
17
- `}),qn("video",{poster:o,ref:e,src:i,style:{width:"100%",objectFit:"contain"}})]})}function Le({media:e,mediaControlsDeps:n,children:t,videoComponent:r=lt}){let o=M(),s=ke(),i=o&&o.placeholderCanvas&&o.placeholderCanvas.id||void 0,a=we({},!1,{canvasId:i}),[{element:u,currentTime:c,progress:l},d,y]=ue({duration:e.duration});return O("overlay","video-element",r,{element:u,media:e,playPause:y.playPause,poster:a?.id,startTime:s?s.startTime:null},[a]),O("portal","custom-controls",Ve,{state:d,actions:y,currentTime:c,progress:l,element:u,children:t},[c,d,e,...n||[]]),null}import{Fragment as fi,jsx as dt,jsxs as pi}from"react/jsx-runtime";function mt({model:e}){return pi(fi,{children:[dt("style",{children:`
17
+ `}),qn("video",{poster:o,ref:e,src:i,style:{width:"100%",objectFit:"contain"}})]})}function ze({media:e,mediaControlsDeps:n,children:t,videoComponent:r=lt}){let o=M(),s=Ne(),i=o&&o.placeholderCanvas&&o.placeholderCanvas.id||void 0,a=Ee({},!1,{canvasId:i}),[{element:u,currentTime:c,progress:l},d,y]=ue({duration:e.duration});return O("overlay","video-element",r,{element:u,media:e,playPause:y.playPause,poster:a?.id,startTime:s?s.startTime:null},[a]),O("portal","custom-controls",ke,{state:d,actions:y,currentTime:c,progress:l,element:u,children:t},[c,d,e,...n||[]]),null}import{Fragment as fi,jsx as dt,jsxs as pi}from"react/jsx-runtime";function mt({model:e}){return pi(fi,{children:[dt("style",{children:`
18
18
  .model-container {
19
19
  position: absolute;
20
20
  top: 0;
@@ -27,7 +27,7 @@ import{c as ht,l as yt}from"./chunk-QCPOOHCR.js";import{forwardRef as er,useImpe
27
27
  justify-content: center;
28
28
  pointer-events: visible;
29
29
  }
30
- `}),dt("div",{className:"model-container",children:dt("model-viewer",{"interaction-prompt":"none",style:{width:"100%",height:"100%"},"camera-controls":"","ar-status":"not-presenting",src:e.id})})]})}function ze({model:e,name:n}){return O("overlay",`model-${n}`,mt,{model:e},[e]),null}import{jsx as gi}from"react/jsx-runtime";function Oe({style:e}){let n=M();return!n||!n.height||!n.width?null:gi("box",{interactive:!1,target:{x:0,y:0,width:Number(n.width),height:Number(n.height)},style:e})}import{jsx as Bn}from"react/jsx-runtime";function He(e){let n=M();return!n||!n.placeholderCanvas?null:Bn(q,{canvas:n.placeholderCanvas.id,children:Bn(ce,{renderViewerControls:e.renderViewerControls})})}import{useRef as vi}from"react";import{jsx as _n,jsxs as yi}from"react/jsx-runtime";function hi({element:e,media:n,playPause:t}){let r=vi(null);return n.youTubeId?yi("div",{className:"video-container",part:"video-container",onClick:t,children:[_n("style",{children:`
30
+ `}),dt("div",{className:"model-container",children:dt("model-viewer",{"interaction-prompt":"none",style:{width:"100%",height:"100%"},"camera-controls":"","ar-status":"not-presenting",src:e.id})})]})}function Oe({model:e,name:n}){return O("overlay",`model-${n}`,mt,{model:e},[e]),null}import{jsx as gi}from"react/jsx-runtime";function He({style:e}){let n=M();return!n||!n.height||!n.width?null:gi("box",{interactive:!1,target:{x:0,y:0,width:Number(n.width),height:Number(n.height)},style:e})}import{jsx as Bn}from"react/jsx-runtime";function Fe(e){let n=M();return!n||!n.placeholderCanvas?null:Bn(q,{canvas:n.placeholderCanvas.id,children:Bn(ce,{renderViewerControls:e.renderViewerControls})})}import{useRef as vi}from"react";import{jsx as _n,jsxs as yi}from"react/jsx-runtime";function hi({element:e,media:n,playPause:t}){let r=vi(null);return n.youTubeId?yi("div",{className:"video-container",part:"video-container",onClick:t,children:[_n("style",{children:`
31
31
  .video-container {
32
32
  position: absolute;
33
33
  top: 0;
@@ -45,4 +45,4 @@ import{c as ht,l as yt}from"./chunk-QCPOOHCR.js";import{forwardRef as er,useImpe
45
45
  width: 100%;
46
46
  object-fit: contain;
47
47
  }
48
- `}),_n("iframe",{className:"video-yt",ref:r,src:`https://www.youtube.com/embed/${n.youTubeId}?enablejsapi=1&origin=${window.location.host}`,referrerPolicy:"no-referrer",sandbox:"allow-scripts allow-same-origin allow-presentation"})]}):null}function jn({media:e,mediaControlsDeps:n,children:t}){let[{element:r,currentTime:o,progress:s},i,a]=ue({duration:e.duration});return O("overlay","video-element",hi,{element:r,media:e,playPause:a.playPause}),null}import{useLayoutEffect as Ti,useMemo as Ii}from"react";import xi from"mitt";import{createStore as Si}from"zustand/vanilla";function Kn({currentKeyFrameIndex:e,keyframes:n,targetTime:t,currentTime:r}){if(r<=t){let o=n.findIndex(a=>a.time>t);if(o===-1)return[e,[]];let s={},i=n.slice(e,o);for(let a of i)a.type==="enter"&&(s[a.id]=a),a.type==="exit"&&(s[a.id]?delete s[a.id]:s[a.id]=a);return[o,Object.values(s)]}return[e,[]]}function Yn({complexTimeline:e,startTime:n=0}){let t=xi(),r={},o={progress:null,currentTime:null},s=0,i=null,a=0,u=null;function c(){let C=b.getState().visibleElements,m=r,v=[],I=Object.keys(m);for(let S of I){let P=m[S],x=C[S];P&&x&&v.push(P)}return v}function l(){return Object.keys(r).map(C=>r[C])}function d(p){o.currentTime&&(o.currentTime.innerHTML=it(p),o.progress&&(o.progress.style.width=`${p/e.duration*100}%`))}let y=()=>{let p=b.getState(),C=p.currentPrime;if(!C)return;let m=r,v=p.visibleElements,I=Object.keys(m);for(let S of I){let P=m[S],x=v[S];if(P&&S!==C.id&&x){let K=a-x.time*1e3;Math.abs(a-x.time*1e3-P.currentTime*1e3)>300&&(P.currentTime=K/1e3)}}},A=(p=0)=>{let C=p-s,m=b.getState();if(m.isPlaying){let v=m.currentPrime;if(v){let x=r[v.id];x&&(x.paused?a+=C:a=(v.time+x.currentTime)*1e3)}else a+=C;let I=a/1e3;if(I>m.duration){b.getState().setTime(0),b.setState({isPlaying:!1}),h(),d(0);return}d(I);let[S,P]=Kn({currentTime:I,currentKeyFrameIndex:m.nextKeyframeIndex,keyframes:m.complexTimeline.keyframes,targetTime:I});P.length&&m.applyKeyframes(S,P)}s=p,i=requestAnimationFrame(A)},h=()=>{i&&cancelAnimationFrame(i)},g=(p,C)=>{},b=Si((p,C)=>({complexTimeline:e,elements:{},visibleElements:{},isBuffering:!1,bufferMap:{},isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,isReady:!1,volume:100,duration:e.duration,clockStartRequests:0,clockStartTime:0,primeTime:0,currentPrime:null,clockRunning:!1,nextKeyframeIndex:0,startClock:()=>{C().clockRunning||(A(),u=setInterval(y,500)),p({clockRunning:!0,clockStartRequests:C().clockStartRequests+1})},applyKeyframes(m,v){let I=C(),S={...I.visibleElements},P=I.currentPrime;for(let x of v)x.type==="enter"&&(S[x.id]=x,t.emit("complex-timeline.enter",{id:x.id})),x.type==="exit"&&(S[x.id]=null,t.emit("complex-timeline.exit",{id:x.id})),x.isPrime&&(P=x);p({nextKeyframeIndex:m,visibleElements:S,currentPrime:P})},stopClock:()=>{let m=C().clockStartRequests;if(m!==0){if(m===1){h(),u&&clearInterval(u),p({clockRunning:!1,clockStartRequests:0});return}p({clockStartRequests:m-1})}},setElement:(m,v)=>{r[m]=v;let I=Object.keys(r),S=C().complexTimeline;g(v,m),S.items.filter(x=>x.type!=="Image"&&x.type!=="Text").every(x=>I.includes(x.annotationId))&&!C().isReady&&(t.emit("complex-timeline.ready",{complexTimeline:S}),p({isReady:!0}))},removeElement:m=>{delete r[m]},mute(){for(let m of l())m.muted=!0;p({isMuted:!0})},unmute(){for(let m of l())m.muted=!1;p({isMuted:!1})},play(){if(!C().isPlaying){for(let v of c())v.play();p({isPlaying:!0})}},pause(){if(C().isPlaying){for(let v of c())v.pause();p({isPlaying:!1})}},playPause(){let m=C();m.isPlaying?m.pause():m.play()},setDurationPercent(m){let I=C().duration*m;C().setTime(I)},setTime(m){let v=C(),I=a/1e3,S=v.nextKeyframeIndex;if(I>m){p({visibleElements:{},currentPrime:null});let G=Object.keys(v.visibleElements);for(let L of G)t.emit("complex-timeline.exit",{id:L});I=0,S=0}let[P,x]=Kn({currentTime:I,currentKeyFrameIndex:S,keyframes:v.complexTimeline.keyframes,targetTime:m});v.applyKeyframes(P,x),a=m*1e3;let f=b.getState().visibleElements,Ue=r,xe=Object.keys(f);for(let G of xe){let L=f[G];if(L){let Z=Ue[G];Z&&(Z.currentTime=(a-L.time*1e3)/1e3)}}},setVolume(m){for(let v of l())v.volume=Math.min(1,Math.max(0,m/100));p({volume:m})},toggleMute(){let m=C();m.isMuted?(m.unmute(),p({isMuted:!1})):(m.mute(),p({isMuted:!0}))},clearProgressElement(){o.progress=null},setProgressElement(m){o.progress=m},setCurrentTimeElement(m){o.currentTime=m},clearCurrentTimeElement(){o.currentTime=null}}));return t.on("complex-timeline.enter",p=>{let C=b.getState(),m=p.id,v=r[m];v&&C.isPlaying&&v.play()}),t.on("complex-timeline.exit",p=>{let C=b.getState(),m=p.id,v=r[m];v&&(v.currentTime=0,v.pause())}),b.getState().setTime(n),{store:b,emitter:t}}import{HTMLPortal as Mi}from"@atlas-viewer/atlas";import{useStore as Gn}from"zustand";import{createContext as Ci,useContext as Ai}from"react";import{useStore as bi}from"zustand";import{jsx as Pi}from"react/jsx-runtime";var ft=Ci(null);ft.displayName="ComplexTimeline";function Qn({children:e,store:n}){return Pi(ft.Provider,{value:n,children:e})}function gm(e){let n=Ai(ft);if(!n)throw new Error("useComplexTimeline must be used within a ComplexTimelineProvider");return bi(n,e)}import{HTMLPortal as Ri}from"@atlas-viewer/atlas";import{Fragment as Wn,jsx as ye}from"react/jsx-runtime";function Fe({strategy:e,onClickPaintingAnnotation:n}){return ye(Wn,{children:e.items.map((t,r)=>ye(Wn,{children:ye(Ri,{onClick:n?o=>{o.stopPropagation(),n(t.annotationId,t,o)}:void 0,target:t.target?.spatial||void 0,children:ye("div",{"data-textual-content":!0,children:ye(he,{enableDangerouslySetInnerHTML:!0,children:t.text})})},r)}))})}import{Fragment as wi,jsx as $e,jsxs as Ei}from"react/jsx-runtime";function Zn({strategy:e,children:n}){let{store:t}=Ii(()=>Yn({complexTimeline:e}),[e]),r=Gn(t,i=>i.isReady),o=Gn(t,i=>i.visibleElements);function s(i){return a=>{a&&t.getState().setElement(i,a)}}return Ti(()=>{if(r){let{startClock:i,stopClock:a}=t.getState();return i(),()=>{a()}}},[r]),O("portal","custom-controls",Qn,{store:t,children:n},[r]),Ei(wi,{children:[e.items.map(i=>i.type!=="Image"||!o[i.annotationId]?null:$e(se,{image:i,id:i.annotationId},i.id)),e.items.map((i,a)=>i.type!=="Text"||!o[i.annotationId]?null:$e(Fe,{strategy:{type:"textual-content",items:[i]}},a)),e.items.map((i,a)=>i.type!=="Video"||!i.target.spatial?null:$e(Mi,{target:i.target.spatial,children:$e("video",{ref:s(i.annotationId),src:i.url,style:{height:"100%",width:"100%",opacity:o[i.annotationId]?1:0}})},a))]})}import{Fragment as De,jsx as k,jsxs as j}from"react/jsx-runtime";function ce({x:e,y:n,onChoiceChange:t,registerActions:r,defaultChoices:o,isStatic:s,renderViewerControls:i,renderMediaControls:a,renderComplexTimelineControls:u,viewControlsDeps:c,mediaControlsDeps:l,strategies:d,throwOnUnknown:y,backgroundStyle:A,alwaysShowBackground:h,keepCanvasScale:g=!1,enableSizes:b=!1,enableYouTube:p=!0,onClickPaintingAnnotation:C,children:m}){let v=M(),I=Re(v,["deep-zoom"]),[S]=tn(),P=on(),x=R(),K=Xn(()=>Vi(x),[x]),[f,Ue]=On({strategies:d||["images"],defaultChoices:o?.map(({id:w})=>w)}),xe=f.type==="images"?f.choice:void 0,G=Xn(()=>g?1:Math.max(1,...f.type==="images"?f.images.map(w=>(w.width||0)/w.target?.spatial.width):[]),[g,f]);sn(G),Jn(()=>{r&&r(Ue)},[f.annotations]),Jn(()=>{if(o)for(let w of o)typeof w.opacity<"u"&&K.applyStyles({id:w.id},"atlas",{opacity:w.opacity})},[o]),Ni(()=>{t&&t(xe)},[xe]),O(P&&(f.type==="images"||f.type==="empty"||f.type==="textual-content"&&i)?"overlay":"none",`canvas-portal-controls-${v?.id}`,ge.Provider,i?{value:P||null,children:i(f)}:{},[v,P,f,...c||[]]);let L=we({maxWidth:256,maxHeight:256});if(!v)return null;let Z=v.accompanyingCanvas,qe=v.placeholderCanvas,le=L&&L.type==="fixed"?k("world-object",{height:v.height,width:v.width,x:e,y:n,children:k("world-image",{uri:L.id,target:{x:0,y:0,width:v.width,height:v.height},display:L.width&&L.height?{width:L.width,height:L.height}:void 0,crop:void 0})}):null;if(f.type==="unknown"){if(le)return le;if(y)throw new Error(f.reason||"Unknown image strategy");return null}let pt=j(ki,{children:[S?k(ve,{page:S}):null,f.annotations&&f.annotations.pages?f.annotations.pages.map(w=>k(ve,{page:w},w.id)):null,m]}),tr=f.type==="images"?f.images.length:0,Fi=f.type==="media"&&f.media.type==="Video"&&qe?k(He,{renderViewerControls:i}):null;return j(De,{children:[j("world-object",{height:v.height,width:v.width,x:e,y:n,...I,children:[f.type==="empty"||h?k(Oe,{style:A}):null,f.type==="complex-timeline"?k(Zn,{strategy:f,children:u?u(f):null}):null,f.type==="textual-content"?j(De,{children:[k(Fe,{strategy:f,onClickPaintingAnnotation:C}),pt]}):null,f.type==="images"?j(De,{children:[f.images.map((w,gt)=>k(se,{isStatic:s,image:w,id:w.id,thumbnail:gt===0?L:void 0,selector:w.selector,enableSizes:b,onClick:C?vt=>{vt.stopPropagation(),C(w.annotationId,w,vt)}:void 0},w.id+gt)),pt]}):null,f.type==="3d-model"?k(ze,{model:f.model}):null,f.type==="media"?k(De,{children:f.media.type==="Sound"?j(Ne,{media:f.media,mediaControlsDeps:l,children:[le,a?a(f):null]}):f.media.type==="Video"?j(Le,{media:f.media,mediaControlsDeps:l,children:[le,a?a(f):null]}):f.media.type==="VideoYouTube"&&p?j(jn,{media:f.media,mediaControlsDeps:l,children:[le,a?a(f):null]}):null}):null]},`${v.id}/${f.type}/${tr}`),f.type==="media"&&f.media.type==="Sound"&&Z?k(q,{canvas:Z.id,children:k(ce,{renderViewerControls:i})}):null,f.type==="media"&&f.media.type==="Sound"&&qe&&!Z?k(q,{canvas:qe.id,children:k(ce,{renderViewerControls:i})}):null]})}import{Fragment as Oi,jsx as U,jsxs as Hi}from"react/jsx-runtime";var zi=er(function(n,t){let r=E(),o=Ce(),s=Kt(),{ViewerControls:i,MediaControls:a,ComplexTimelineControls:u}=n.components||{};if(Li(t,()=>s,[s]),!r)return U("div",{});let c=0;return Hi(Oi,{children:[n.header,U(N.Viewer,{height:n.height,mode:n.mode,renderPreset:n.renderPreset,runtimeOptions:n.runtimeOptions,children:o.map((l,d)=>{let y=c;return c+=l.width+(n.spacing||0),U(q,{canvas:l.id,children:U(N.RenderCanvas,{strategies:["3d-model","media","images","empty","textual-content","complex-timeline"],renderViewerControls:d===0&&i?()=>U(i,{}):void 0,renderMediaControls:d===0&&a?()=>U(a,{}):void 0,renderComplexTimelineControls:d===0&&u?()=>U(u,{}):void 0,x:y,...n.canvasProps||{},children:n.annotations},l.id)},l.id)})},n.reuseAtlas?"":s.currentSequenceIndex),n.children]})}),N=er(function({children:n,height:t,annotations:r,canvasProps:o,spacing:s,header:i,components:a,mode:u,reuseAtlas:c,renderPreset:l,runtimeOptions:d,...y},A){let h=X();return U(J,{vault:h,children:U(jt,{...y,children:U(zi,{ref:A,height:t,components:a,spacing:s,canvasProps:o,annotations:r,header:i,mode:u,reuseAtlas:c,renderPreset:l,runtimeOptions:d,children:n})})})});N.RenderImage=se;N.RenderCanvas=ce;N.RenderAnnotationPage=ve;N.RenderAnnotation=Ie;N.Viewer=ln;N.CanvasBackground=Oe;N.Audio=Ne;N.Video=Le;N.Model=ze;N.AudioHTML=ct;N.VideoHTML=lt;N.ModelHTML=mt;N.PlaceholderCanvas=He;export{Se as a,H as b,_ as c,Y as d,J as e,X as f,Ct as g,At as h,bt as i,q as j,R as k,T as l,ee as m,Ce as n,E as o,Pt as p,br as q,_e as r,La as s,Rt as t,Ha as u,je as v,Tt as w,It as x,Ga as y,Et as z,Vt as A,kt as B,Ke as C,Mt as D,te as E,Vr as F,kr as G,$t as H,Dt as I,me as J,Nr as K,ps as L,Lr as M,Ht as N,gs as O,Ut as P,Bt as Q,pe as R,jr as S,jt as T,Kt as U,Gr as V,re as W,Yt as X,au as Y,Qt as Z,Wt as _,Gt as $,Xt as aa,tn as ba,nn as ca,ge as da,on as ea,M as fa,Re as ga,ie as ha,Te as ia,mn as ja,Xc as ka,el as la,tl as ma,yn as na,rt as oa,xn as pa,ko as qa,No as ra,Lo as sa,nl as ta,he as ua,Tn as va,Mn as wa,wn as xa,jo as ya,Me as za,En as Aa,Vn as Ba,Nn as Ca,On as Da,Hn as Ea,we as Fa,it as Ga,ue as Ha,xd as Ia,Sd as Ja,Cd as Ka,Ve as La,ke as Ma,Qn as Na,gm as Oa,N as Pa};
48
+ `}),_n("iframe",{className:"video-yt",ref:r,src:`https://www.youtube.com/embed/${n.youTubeId}?enablejsapi=1&origin=${window.location.host}`,referrerPolicy:"no-referrer",sandbox:"allow-scripts allow-same-origin allow-presentation"})]}):null}function jn({media:e,mediaControlsDeps:n,children:t}){let[{element:r,currentTime:o,progress:s},i,a]=ue({duration:e.duration});return O("overlay","video-element",hi,{element:r,media:e,playPause:a.playPause}),null}import{useLayoutEffect as Ti,useMemo as Ii}from"react";import xi from"mitt";import{createStore as Si}from"zustand/vanilla";function Kn({currentKeyFrameIndex:e,keyframes:n,targetTime:t,currentTime:r}){if(r<=t){let o=n.findIndex(a=>a.time>t);if(o===-1)return[e,[]];let s={},i=n.slice(e,o);for(let a of i)a.type==="enter"&&(s[a.id]=a),a.type==="exit"&&(s[a.id]?delete s[a.id]:s[a.id]=a);return[o,Object.values(s)]}return[e,[]]}function Yn({complexTimeline:e,startTime:n=0}){let t=xi(),r={},o={progress:null,currentTime:null},s=0,i=null,a=0,u=null;function c(){let S=b.getState().visibleElements,m=r,v=[],I=Object.keys(m);for(let x of I){let P=m[x],C=S[x];P&&C&&v.push(P)}return v}function l(){return Object.keys(r).map(S=>r[S])}function d(p){o.currentTime&&(o.currentTime.innerHTML=it(p),o.progress&&(o.progress.style.width=`${p/e.duration*100}%`))}let y=()=>{let p=b.getState(),S=p.currentPrime;if(!S)return;let m=r,v=p.visibleElements,I=Object.keys(m);for(let x of I){let P=m[x],C=v[x];if(P&&x!==S.id&&C){let _=a-C.time*1e3;Math.abs(a-C.time*1e3-P.currentTime*1e3)>300&&(P.currentTime=_/1e3)}}},A=(p=0)=>{let S=p-s,m=b.getState();if(m.isPlaying){let v=m.currentPrime;if(v){let C=r[v.id];C&&(C.paused?a+=S:a=(v.time+C.currentTime)*1e3)}else a+=S;let I=a/1e3;if(I>m.duration){b.getState().setTime(0),b.setState({isPlaying:!1}),h(),d(0);return}d(I);let[x,P]=Kn({currentTime:I,currentKeyFrameIndex:m.nextKeyframeIndex,keyframes:m.complexTimeline.keyframes,targetTime:I});P.length&&m.applyKeyframes(x,P)}s=p,i=requestAnimationFrame(A)},h=()=>{i&&cancelAnimationFrame(i)},g=(p,S)=>{},b=Si((p,S)=>({complexTimeline:e,elements:{},visibleElements:{},isBuffering:!1,bufferMap:{},isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,isReady:!1,volume:100,duration:e.duration,clockStartRequests:0,clockStartTime:0,primeTime:0,currentPrime:null,clockRunning:!1,nextKeyframeIndex:0,startClock:()=>{S().clockRunning||(A(),u=setInterval(y,500)),p({clockRunning:!0,clockStartRequests:S().clockStartRequests+1})},applyKeyframes(m,v){let I=S(),x={...I.visibleElements},P=I.currentPrime;for(let C of v)C.type==="enter"&&(x[C.id]=C,t.emit("complex-timeline.enter",{id:C.id})),C.type==="exit"&&(x[C.id]=null,t.emit("complex-timeline.exit",{id:C.id})),C.isPrime&&(P=C);p({nextKeyframeIndex:m,visibleElements:x,currentPrime:P})},stopClock:()=>{let m=S().clockStartRequests;if(m!==0){if(m===1){h(),u&&clearInterval(u),p({clockRunning:!1,clockStartRequests:0});return}p({clockStartRequests:m-1})}},setElement:(m,v)=>{r[m]=v;let I=Object.keys(r),x=S().complexTimeline;g(v,m),x.items.filter(C=>C.type!=="Image"&&C.type!=="Text").every(C=>I.includes(C.annotationId))&&!S().isReady&&(t.emit("complex-timeline.ready",{complexTimeline:x}),p({isReady:!0}))},removeElement:m=>{delete r[m]},mute(){for(let m of l())m.muted=!0;p({isMuted:!0})},unmute(){for(let m of l())m.muted=!1;p({isMuted:!1})},play(){if(!S().isPlaying){for(let v of c())v.play();p({isPlaying:!0})}},pause(){if(S().isPlaying){for(let v of c())v.pause();p({isPlaying:!1})}},playPause(){let m=S();m.isPlaying?m.pause():m.play()},setDurationPercent(m){let I=S().duration*m;S().setTime(I)},setTime(m){let v=S(),I=a/1e3,x=typeof m=="function"?m(I):m,P=v.nextKeyframeIndex;if(I>x){p({visibleElements:{},currentPrime:null});let L=Object.keys(v.visibleElements);for(let j of L)t.emit("complex-timeline.exit",{id:j});I=0,P=0}let[C,_]=Kn({currentTime:I,currentKeyFrameIndex:P,keyframes:v.complexTimeline.keyframes,targetTime:x});v.applyKeyframes(C,_),a=x*1e3;let xe=b.getState().visibleElements,Se=r,qe=Object.keys(xe);for(let L of qe){let j=xe[L];if(j){let Z=Se[L];Z&&(Z.currentTime=(a-j.time*1e3)/1e3)}}d(x)},setVolume(m){for(let v of l())v.volume=Math.min(1,Math.max(0,m/100));p({volume:m})},toggleMute(){let m=S();m.isMuted?(m.unmute(),p({isMuted:!1})):(m.mute(),p({isMuted:!0}))},clearProgressElement(){o.progress=null},setProgressElement(m){o.progress=m},setCurrentTimeElement(m){o.currentTime=m},clearCurrentTimeElement(){o.currentTime=null}}));return t.on("complex-timeline.enter",p=>{let S=b.getState(),m=p.id,v=r[m];v&&S.isPlaying&&v.play()}),t.on("complex-timeline.exit",p=>{let S=b.getState(),m=p.id,v=r[m];v&&(v.currentTime=0,v.pause())}),b.getState().setTime(n),{store:b,emitter:t}}import{HTMLPortal as Mi}from"@atlas-viewer/atlas";import{useStore as Gn}from"zustand";import{createContext as Ci,useContext as Ai}from"react";import{useStore as bi}from"zustand";import{jsx as Pi}from"react/jsx-runtime";var ft=Ci(null);ft.displayName="ComplexTimeline";function Qn({children:e,store:n}){return Pi(ft.Provider,{value:n,children:e})}function gm(e){let n=Ai(ft);if(!n)throw new Error("useComplexTimeline must be used within a ComplexTimelineProvider");return bi(n,e)}import{HTMLPortal as Ri}from"@atlas-viewer/atlas";import{Fragment as Wn,jsx as ye}from"react/jsx-runtime";function $e({strategy:e,onClickPaintingAnnotation:n}){return ye(Wn,{children:e.items.map((t,r)=>ye(Wn,{children:ye(Ri,{onClick:n?o=>{o.stopPropagation(),n(t.annotationId,t,o)}:void 0,target:t.target?.spatial||void 0,children:ye("div",{"data-textual-content":!0,children:ye(he,{enableDangerouslySetInnerHTML:!0,children:t.text})})},r)}))})}import{Fragment as wi,jsx as De,jsxs as Ei}from"react/jsx-runtime";function Zn({strategy:e,children:n}){let{store:t}=Ii(()=>Yn({complexTimeline:e}),[e]),r=Gn(t,i=>i.isReady),o=Gn(t,i=>i.visibleElements);function s(i){return a=>{a&&t.getState().setElement(i,a)}}return Ti(()=>{if(r){let{startClock:i,stopClock:a}=t.getState();return i(),()=>{a()}}},[e,r]),O("portal","custom-controls",Qn,{store:t,children:n},[r]),Ei(wi,{children:[e.items.map(i=>i.type!=="Image"||!o[i.annotationId]?null:De(se,{image:i,id:i.annotationId},i.id)),e.items.map((i,a)=>i.type!=="Text"||!o[i.annotationId]?null:De($e,{strategy:{type:"textual-content",items:[i]}},a)),e.items.map((i,a)=>i.type!=="Video"||!i.target.spatial?null:De(Mi,{target:i.target.spatial,children:De("video",{ref:s(i.annotationId),src:i.url,style:{height:"100%",width:"100%",opacity:o[i.annotationId]?1:0}})},a))]})}import{Fragment as Ue,jsx as k,jsxs as Y}from"react/jsx-runtime";function ce({x:e,y:n,onChoiceChange:t,registerActions:r,defaultChoices:o,isStatic:s,renderViewerControls:i,renderMediaControls:a,renderComplexTimelineControls:u,viewControlsDeps:c,mediaControlsDeps:l,strategies:d,throwOnUnknown:y,backgroundStyle:A,alwaysShowBackground:h,keepCanvasScale:g=!1,enableSizes:b=!1,enableYouTube:p=!0,onClickPaintingAnnotation:S,children:m}){let v=M(),I=Te(v,["deep-zoom"]),[x]=tn(),P=on(),C=R(),_=Xn(()=>Vi(C),[C]),[f,xe]=On({strategies:d||["images"],defaultChoices:o?.map(({id:w})=>w)}),Se=f.type==="images"?f.choice:void 0,qe=Xn(()=>g?1:Math.max(1,...f.type==="images"?f.images.map(w=>(w.width||0)/w.target?.spatial.width):[]),[g,f]);sn(qe),Jn(()=>{r&&r(xe)},[f.annotations]),Jn(()=>{if(o)for(let w of o)typeof w.opacity<"u"&&_.applyStyles({id:w.id},"atlas",{opacity:w.opacity})},[o]),Ni(()=>{t&&t(Se)},[Se]),O(P&&(f.type==="images"||f.type==="empty"||f.type==="textual-content"&&i)?"overlay":"none",`canvas-portal-controls-${v?.id}`,ge.Provider,i?{value:P||null,children:i(f)}:{},[v,P,f,...c||[]]);let L=Ee({maxWidth:256,maxHeight:256});if(!v)return null;let j=v.accompanyingCanvas,Z=v.placeholderCanvas,le=L&&L.type==="fixed"?k("world-object",{height:v.height,width:v.width,x:e,y:n,children:k("world-image",{uri:L.id,target:{x:0,y:0,width:v.width,height:v.height},display:L.width&&L.height?{width:L.width,height:L.height}:void 0,crop:void 0})}):null;if(f.type==="unknown"){if(le)return le;if(y)throw new Error(f.reason||"Unknown image strategy");return null}let pt=Y(ki,{children:[x?k(ve,{page:x}):null,f.annotations&&f.annotations.pages?f.annotations.pages.map(w=>k(ve,{page:w},w.id)):null,m]}),tr=f.type==="images"?f.images.length:0,Fi=f.type==="media"&&f.media.type==="Video"&&Z?k(Fe,{renderViewerControls:i}):null;return Y(Ue,{children:[Y("world-object",{height:v.height,width:v.width,x:e,y:n,...I,children:[f.type==="empty"||h?k(He,{style:A}):null,f.type==="complex-timeline"?k(Zn,{strategy:f,children:u?u(f):null}):null,f.type==="textual-content"?Y(Ue,{children:[k($e,{strategy:f,onClickPaintingAnnotation:S}),pt]}):null,f.type==="images"?Y(Ue,{children:[f.images.map((w,gt)=>k(se,{isStatic:s,image:w,id:w.id,thumbnail:gt===0?L:void 0,selector:w.selector,enableSizes:b,onClick:S?vt=>{vt.stopPropagation(),S(w.annotationId,w,vt)}:void 0},w.id+gt)),pt]}):null,f.type==="3d-model"?k(Oe,{model:f.model}):null,f.type==="media"?k(Ue,{children:f.media.type==="Sound"?Y(Le,{media:f.media,mediaControlsDeps:l,children:[le,a?a(f):null]}):f.media.type==="Video"?Y(ze,{media:f.media,mediaControlsDeps:l,children:[le,a?a(f):null]}):f.media.type==="VideoYouTube"&&p?Y(jn,{media:f.media,mediaControlsDeps:l,children:[le,a?a(f):null]}):null}):null]},`${v.id}/${f.type}/${tr}`),f.type==="media"&&f.media.type==="Sound"&&j?k(q,{canvas:j.id,children:k(ce,{renderViewerControls:i})}):null,f.type==="media"&&f.media.type==="Sound"&&Z&&!j?k(q,{canvas:Z.id,children:k(ce,{renderViewerControls:i})}):null]})}import{Fragment as Oi,jsx as U,jsxs as Hi}from"react/jsx-runtime";var zi=er(function(n,t){let r=E(),o=Ae(),s=Kt(),{ViewerControls:i,MediaControls:a,ComplexTimelineControls:u}=n.components||{};if(Li(t,()=>s,[s]),!r)return U("div",{});let c=0;return Hi(Oi,{children:[n.header,U(N.Viewer,{height:n.height,mode:n.mode,renderPreset:n.renderPreset,runtimeOptions:n.runtimeOptions,children:o.map((l,d)=>{let y=c;return c+=l.width+(n.spacing||0),U(q,{canvas:l.id,children:U(N.RenderCanvas,{strategies:["3d-model","media","images","empty","textual-content","complex-timeline"],renderViewerControls:d===0&&i?()=>U(i,{}):void 0,renderMediaControls:d===0&&a?()=>U(a,{}):void 0,renderComplexTimelineControls:d===0&&u?()=>U(u,{}):void 0,x:y,...n.canvasProps||{},children:n.annotations},l.id)},l.id)})},n.reuseAtlas?"":s.currentSequenceIndex),n.children]})}),N=er(function({children:n,height:t,annotations:r,canvasProps:o,spacing:s,header:i,components:a,mode:u,reuseAtlas:c,renderPreset:l,runtimeOptions:d,...y},A){let h=X();return U(J,{vault:h,children:U(jt,{...y,children:U(zi,{ref:A,height:t,components:a,spacing:s,canvasProps:o,annotations:r,header:i,mode:u,reuseAtlas:c,renderPreset:l,runtimeOptions:d,children:n})})})});N.RenderImage=se;N.RenderCanvas=ce;N.RenderAnnotationPage=ve;N.RenderAnnotation=Me;N.Viewer=ln;N.CanvasBackground=He;N.Audio=Le;N.Video=ze;N.Model=Oe;N.AudioHTML=ct;N.VideoHTML=lt;N.ModelHTML=mt;N.PlaceholderCanvas=Fe;export{Ce as a,H as b,K as c,Q as d,J as e,X as f,Ct as g,At as h,bt as i,q as j,R as k,T as l,ee as m,Ae as n,E as o,Pt as p,br as q,_e as r,La as s,Rt as t,Ha as u,je as v,Tt as w,It as x,Ga as y,Et as z,Vt as A,kt as B,Ke as C,Mt as D,te as E,Vr as F,kr as G,$t as H,Dt as I,me as J,Nr as K,ps as L,Lr as M,Ht as N,gs as O,Ut as P,Bt as Q,pe as R,jr as S,jt as T,Kt as U,Gr as V,re as W,Yt as X,au as Y,Qt as Z,Wt as _,Gt as $,Xt as aa,tn as ba,nn as ca,ge as da,on as ea,M as fa,Te as ga,ie as ha,Ie as ia,mn as ja,Xc as ka,el as la,tl as ma,yn as na,rt as oa,xn as pa,ko as qa,No as ra,Lo as sa,nl as ta,he as ua,Tn as va,Mn as wa,wn as xa,jo as ya,we as za,En as Aa,Vn as Ba,Nn as Ca,On as Da,Hn as Ea,Ee as Fa,it as Ga,ue as Ha,xd as Ia,Sd as Ja,Cd as Ka,ke as La,Ne as Ma,Qn as Na,gm as Oa,N as Pa};
@@ -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};