react-iiif-vault 1.1.1 → 1.2.1

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,47 +0,0 @@
1
- import{c as ct,k as lt}from"./chunk-DXFXJCXN.js";import{forwardRef as En,useImperativeHandle as Go}from"react";import Zt,{useCallback as We,useMemo as Kt,useState as xe}from"react";import{AtlasAuto as qr,ModeContext as Br}from"@atlas-viewer/atlas";import{ErrorBoundary as $r}from"react-error-boundary";import{useContext as ne}from"react";import On,{useContext as Fn,useMemo as Hn}from"react";import{jsx as Un}from"react/jsx-runtime";var Dn={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},ye=On.createContext(Dn),k=()=>Fn(ye);function _({value:e,children:n}){let t=k(),r=Hn(()=>({...t,...e}),[e,t]);return Un(ye.Provider,{value:r,children:n})}import _n,{useState as qn}from"react";import{Vault as dt,globalVault as Bn}from"@iiif/helpers/vault";import{jsx as ft}from"react/jsx-runtime";var $=_n.createContext({vault:null,setVaultInstance:e=>{}});function W({vault:e,vaultOptions:n,useGlobal:t,resources:r,children:o}){let[a,i]=qn(()=>e||(t?Bn(n):n?new dt(n):new dt));return ft($.Provider,{value:{vault:a,setVaultInstance:i},children:ft(_,{value:r||{},children:o})})}import{useContext as xr}from"react";import{createContext as Cr,useMemo as br}from"react";import{globalVault as $n}from"@iiif/helpers/vault";import{useContext as jn}from"react";function G(e){let n=jn($);return e||(n&&n.vault?n.vault:$n())}import{useEffect as Yn,useMemo as Qn,useState as ze}from"react";function mt(e,{noCache:n=!1}={}){let t=typeof e=="string"?e:e.id,r=G(),[o,a]=ze(t),[i,s]=ze(void 0),u=Qn(()=>r.get(t,{skipSelfReturn:!0})||void 0,[t,r]),[c,l]=ze(u);return Yn(()=>{(async()=>{try{let f=u&&!n?u:await r.load(t),d=f?f.id||f["@id"]:null;f&&o!==d&&a(d),l(f)}catch(f){s(f)}})()},[t,n]),{isLoaded:!!c,id:o,requestId:t,error:i,resource:c,cached:!!(c&&c===u)}}function pt(e,n){let{id:t,isLoaded:r,error:o,resource:a,requestId:i,cached:s}=mt(e,n);return{id:t,isLoaded:r,error:o,manifest:a,requestId:i,cached:s}}import{jsx as Wn}from"react/jsx-runtime";function gt({manifest:e,children:n}){return Wn(_,{value:{manifest:e},children:n})}import{jsx as Gn}from"react/jsx-runtime";function Z({canvas:e,children:n}){return Gn(_,{value:{canvas:e},children:n})}import{useContext as Xn}from"react";import er from"react";import{useContext as Zn}from"react";var y=()=>{let{vault:e}=Zn($);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};import{useEffect as Kn,useState as Jn}from"react";function S(e,n=[]){let t=y(),[r,o]=Jn(()=>e(t.getState(),t));return Kn(()=>t.subscribe(a=>e(a,t),a=>{o(a)},!1),n),r}var K=er.createContext([]);function Se(){let e=Xn(K);return S(n=>e.map(t=>n.iiif.entities.Canvas[t]).filter(Boolean),[e])}import{useMemo as tr}from"react";function w(e={},n=[]){let{id:t,selector:r}=e,o=k(),a=y(),i=t||o.manifest,s=S(u=>i?u.iiif.entities.Manifest[i]:void 0,[i]);return tr(()=>{if(s)return r?r(s):s},[s,r,...n])}import{jsx as nr}from"react/jsx-runtime";function ht({range:e,children:n}){return nr(_,{value:{range:e},children:n})}function rr(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=rr(e,e.get(t));if(r)return r}}return null}function Oe(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(...Oe(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 Qi(e,n,t){for(let r of n.structures){let o=vt(e,e.get(r),t);if(o)return o}return null}function vt(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 a=vt(e,e.get(r),t);if(a)return a}}return null}function Zi(e,n,t,r=!1){let o=n.behavior,a=t?e.get(t):null;if(!a)return[];let i=a.behavior,s=r?!1:o.includes("paged"),u=s?!1:o.includes("continuous"),c=s||u?!1:o.includes("individuals"),l=i.includes("facing-pages"),f=i.includes("non-paged");if(l||f||c||r)return[{id:a.id,type:"Canvas"}];let[d,v]=Fe(e,n);if(u)return d;let m=d.findIndex(p=>p.id===t);if(m===-1)return[];for(let p of v)if(p.includes(m))return p.map(g=>d[g]);return[{id:a.id,type:"Canvas"}]}function Fe(e,n,{disablePaging:t,skipNonPaged:r}={}){let o=n.behavior,a=o.includes("paged"),i=a?!1:o.includes("continuous"),s=a||i?!1:o.includes("individuals"),u=n.type==="Manifest"?n.items:Oe(e,n);if(i)return[u,[u.map((m,p)=>p)]];if(s||!a||t)return[u,u.map((m,p)=>[p])];let c=[],l=[],f=()=>{l.length&&(c.push([...l]),l=[])},d=0,v=!1;for(let m=0;m<u.length;m++){let p=e.get(u[m]);if(p.behavior.includes("non-paged")){m===d&&d++,r||(f(),c.push([m]),f());continue}if(m===d||p.behavior.includes("facing-pages")){l.length&&(v=!0),f(),c.push([m]),f();continue}if(l.push(m),v){f(),v=!1;continue}l.length>1&&f()}return l.length&&f(),[u,c]}import{useCallback as Ae,useMemo as ir,useRef as ar,useState as sr}from"react";import{useMemo as or}from"react";function yt(e={},n=[]){let{id:t,selector:r}=e,o=k(),a=t||o.range,i=S(s=>a?s.iiif.entities.Range[a]:void 0,[a]);return or(()=>{if(i)return r?r(i):i},[i,r,...n])}function St({startCanvas:e,disablePaging:n}){let t=y(),r=w(),o=yt(),[a,i]=sr(void 0),s=o||r;if(!s)throw new Error("Nothing selected");let[u,c]=ir(()=>Fe(t,s,{disablePaging:n}),[t,s,n]),l=ar(c);if(l.current!==c){let g=l.current[a][0],A=c.findIndex(D=>D.includes(g));l.current=c,i(A)}let f=Ae(p=>{let g=c.findIndex(A=>A.includes(p));i(g===-1?0:g)},[u,c]),d=Ae(p=>{let g=u.findIndex(A=>A.id===p);g!==-1?f(g):i(0)},[u,c]),v=Ae(()=>{i(p=>p>=c.length-1?p:p+1)},[c]),m=Ae(()=>{i(p=>p<=0?0:p-1)},[c]);return typeof a>"u"&&(e?d(e):i(0)),{visibleItems:c[a]?.map(p=>u[p].id)||[],cursor:a,items:u,sequence:c,hasPrevious:a>0,hasNext:a<c.length-1,setSequenceIndex:i,setCanvasIndex:f,setCanvasId:d,next:v,previous:m}}import{createContext as Ue,useContext as Q,useEffect as cr,useMemo as De,useReducer as lr}from"react";import{useEffect as Rt,useMemo as It}from"react";import{createStore as At}from"zustand/vanilla";function ca(e){let n=e.service||e.services||[];for(let t of n)if(t.type==="AuthProbeService2")return!0;return!1}function E(e,n,t){let r=n.findIndex(i=>i.service.id===e);if(r===-1)return n;let o=[...n],a=t(o[r]);return a===o[r]?n:(o[r]=a,o)}var xt=()=>At((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:E(t.id,n().authItems,o=>({...o,isPending:!0}))})),se(t.service).then(()=>{j(r).then(o=>{let a=o.expiresIn,i=Date.now()+a*1e3;e(()=>({authItems:E(t.id,n().authItems,s=>({...s,isLoggedIn:!0,isPending:!1,session:{token:o.accessToken,expires:i}}))}))}).catch(o=>{e(()=>({authItems:E(t.id,n().authItems,a=>({...a,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=${Pt()}`,a=window.open(o);e(()=>({authItems:E(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(s=>s.type==="AuthAccessTokenService2"),a=t;if(n().authItems.find(s=>s.service.id===t.id)){e(()=>({authItems:E(t.id,n().authItems,s=>({...s,instances:s.instances+1}))}));return}if(e(()=>({currentAuth:a.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");j(o).then(s=>{e(()=>({authItems:E(t.id,n().authItems,u=>({...u,isLoggedIn:!0,isPending:!1,session:{token:s.accessToken,expires:s.expiresIn}}))}))}).catch(s=>{e(()=>({authItems:E(t.id,n().authItems,u=>({...u,isLoggedIn:!1,isPending:!1,canAuthenticate:!1,error:s.message}))}))})}if(t.profile==="kiosk"){if(!o)throw new Error("Token service not found");e(()=>({authItems:E(t.id,n().authItems,s=>({...s,isPending:!0}))})),se(a).then(()=>{j(o).then(s=>{e(()=>({authItems:E(t.id,n().authItems,u=>({...u,isLoggedIn:!0,isPending:!1,session:{token:s.accessToken,expires:s.expiresIn}}))}))}).catch(s=>{e(()=>({authItems:E(t.id,n().authItems,u=>({...u,isLoggedIn:!1,isPending:!1,error:s.message}))}))})})}t.profile},removeService:(t,r)=>{let o=n().currentAuth===n().authItems.findIndex(i=>i.service.id===t.id),a=n().currentAuth;if(o){let i=n().authItems.find(u=>u.service.id===t.id);i&&i.instances>1||(a=n().authItems.findIndex(c=>c.service.id!==t.id&&c.instances>0))}e(()=>({authItems:E(t.id,n().authItems,i=>({...i,instances:i.instances-1})),currentAuth:a}))}})),Ct=(e,n)=>At((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 a=r().token;try{let i=await fetch(o,{headers:a?{Authorization:`Bearer ${r().token}`,Accept:"application/json"}:{Accept:"application/json"}}).then(s=>s.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 bt(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(a=>a.type==="AuthAccessService2");o[0]&&(t.services.access=o[0])}return t}async function j(e,{strict:n=!0}={}){return new Promise((t,r)=>{let o=Math.random().toString(36).substring(7),a=`${e.id}?messageId=${o}&origin=${window.location.origin}`,i=c=>{let l=c.data;if(l.messageId===o){if(n&&l.type!=="AuthAccessToken2"){s(),r("Invalid response, expected type=AuthAccessToken2");return}if(!l.accessToken){s(),r("Invalid response, expected accessToken");return}s(),t(l)}},s=()=>window.removeEventListener("message",i),u=document.createElement("iframe");u.src=a,u.style.display="none",document.body.appendChild(u),window.addEventListener("message",i)})}function Pt(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 se(e){let n=`${e.id}?origin=${Pt()}`,t=window.open(n);if(!t)throw new Error("Failed to open window");return new Promise((r,o)=>{let a=setInterval(()=>{t.closed&&(clearInterval(a),r())},500)})}import{useStore as ur}from"zustand";function wt(e){let n=It(()=>bt(e),[e]),t=Mt(n.services.access?.id),r=It(()=>Ct(n.services.probe,t),[n.services.probe]),o=ur(r);return Rt(()=>{o.status==="unknown"&&!t&&o.probe()},[n.services.probe,o.status]),Rt(()=>{t&&(o.setToken(t),o.probe())},[t]),[e,o,n.hasAuth]}import{useStore as ue}from"zustand";import{jsx as J}from"react/jsx-runtime";var X=Ue(null),ee=Ue(null);ee.displayName="CurrentAuth";var _e=Ue(null);_e.displayName="AuthActions";function Y(e,n,t){let r=n.authItems.findIndex(i=>i.service.id===e);if(r===-1)return n;let o=[...n.authItems],a=t(o[r]);return a===o[r]?n:(o[r]=a,{...n,authItems:o})}function dr(e,n){switch(n.type){case"login.start":return Y(n.payload.id,e,t=>({...t,isPending:!0}));case"login.success":return Y(n.payload.id,e,t=>({...t,isLoggedIn:!0,isPending:!1,session:{token:n.payload.token,expires:n.payload.expires}}));case"login.error":return Y(n.payload.id,e,t=>({...t,isLoggedIn:!1,isPending:!1,canAuthenticate:!1,error:n.payload.error}));case"session.expire":return Y(n.payload.id,e,t=>({...t,isPending:!1,isLoggedIn:!1,session:null}));case"logout":return Y(n.payload.id,e,t=>({...t,isLoggedIn:!1,session:null,isPending:!1}));case"service.add":return e.authItems.find(r=>r.service.id===n.payload.service.id)?Y(n.payload.service.id,e,r=>({...r,instances:r.instances+1})):{...e,currentAuth:n.payload.service.profile==="active"?0:e.currentAuth,authItems:[{id:n.payload.service.id,type:n.payload.service.profile,service:n.payload.service,probeId:n.payload.probeId,canAuthenticate:!0,instances:1,isPending:!1,isLoggedIn:!1,session:null},...e.authItems]};case"service.remove":{let t=e.currentAuth===e.authItems.findIndex(o=>o.service.id===n.payload.id),r=e.currentAuth;if(t){let o=e.authItems.find(i=>i.service.id===n.payload.id);o&&o.instances>1||(r=e.authItems.findIndex(s=>s.service.id!==n.payload.id&&s.instances>0))}return{...Y(n.payload.id,e,o=>({...o,instances:o.instances-1})),currentAuth:r}}case"list.next":{let t=e.authItems.length,r=e.currentAuth+1;return r>=t?e:{...e,currentAuth:r}}case"list.previous":{let t=e.currentAuth-1;return t<0?e:{...e,currentAuth:t}}case"list.set":return n.payload!==-1&&(n.payload<0||n.payload>=e.authItems.length)?e:{...e,currentAuth:n.payload};default:return e}}function Tt({children:e}){let n=De(()=>xt(),[]);return J(X.Provider,{value:n,children:e})}function wa({children:e}){let[n,t]=lr(dr,{currentAuth:-1,authItems:[]}),r=(d,v)=>{if(!d.service)return;let m=d.service.find(g=>g.type==="AuthAccessTokenService2"),p=d;if(t({type:"service.add",payload:{service:d,probeId:v}}),d.profile==="external"){if(!m)throw new Error("Token service not found");j(m).then(g=>{t({type:"login.success",payload:{id:d.id,token:g.accessToken,expires:g.expiresIn}})}).catch(g=>{t({type:"login.error",payload:{id:d.id,error:g.message}})})}if(d.profile==="kiosk"){if(!m)throw new Error("Token service not found");t({type:"login.start",payload:{id:d.id}}),se(p).then(()=>{j(m).then(g=>{t({type:"login.success",payload:{id:d.id,token:g.accessToken,expires:g.expiresIn}})}).catch(g=>{t({type:"login.error",payload:{id:d.id,error:g.message}})})}).catch(g=>{t({type:"login.error",payload:{id:d.id,error:g.message}})})}d.profile},o=d=>{t({type:"service.remove",payload:d})},a=()=>{let d=n.authItems[n.currentAuth];if(!d||d.isPending||d.isLoggedIn)return;if(d.type!=="active")throw new Error("Cannot login to non-active service");let v=d.service.service.find(m=>m.type==="AuthAccessTokenService2");if(!v)throw new Error("Token service not found");t({type:"login.start",payload:{id:d.id}}),se(d.service).then(()=>{j(v).then(m=>{let p=m.expiresIn,g=Date.now()+p*1e3;t({type:"login.success",payload:{id:d.id,token:m.accessToken,expires:g}})}).catch(m=>{t({type:"login.error",payload:{id:d.id,error:m.message}})})})},i=()=>{let d=n.authItems[n.currentAuth];if(!d||d.isPending||!d.isLoggedIn)return;if(d.type!=="active")throw new Error("Cannot logout of non-active service");let v=d.service.service.find(g=>g.type==="AuthLogoutService2");if(!v)return;let m=`${v.id}?origin=${window.location.origin}`,p=window.open(m);t({type:"logout",payload:{id:d.id}})},s=()=>{},u=()=>{},c=d=>{},l=De(()=>({addService:r,removeService:o}),[]),f=De(()=>({...n,login:a,logout:i,nextAuth:s,previousAuth:u,setAuth:c}),[n]);return J(ee.Provider,{value:f,children:J(_e.Provider,{value:l,children:e})})}function Vt(){return!!Q(X)}function ce(){let e=Q(X);if(!e)throw new Error("useAuthActions must be used within a AuthProvider");return e}function fr(){let e=ce();return ue(e,t=>({login:t.login,logout:t.logout,nextAuth:t.nextAuth,previousAuth:t.previousAuth,setAuth:t.setAuth,addService:t.addService,removeService:t.removeService}))}function Ma(){let e=ce();return ue(e,n=>n)}function mr(e){let n=ce();return ue(n,r=>r.authItems.find(o=>o.service.id===e))}function Mt(e){let n=ce();return ue(n,r=>r.authItems.find(o=>o.id===e)?.session?.token)}function Ta(e){let n=ce();return ue(n,r=>{let o=r.authItems.find(a=>a.service.id===e);return!o||!o.isLoggedIn||!o.session?null:o.session?.token||null})}function Va(){let e=Q(ee);if(!e)throw new Error("useCurrentAuth must be used within a AuthProvider");return e}function Na(e){let n=Q(ee);return n&&n.authItems.find(t=>t.service.id===e)||null}function ka(e){let n=Q(ee);return!n||!e?null:n.authItems.find(t=>t.id===e)?.session?.token||null}function Ea(e){let n=Q(ee);if(!e||!n)return null;let t=n.authItems.find(r=>r.service.id===e);return!t||!t.isLoggedIn||!t.session?null:t.session?.token||null}function La(){return Q(_e)}function pr(e){let n=fr(),t=mr(e.service.id);return cr(()=>(n?.addService(e.service,e.probeId),()=>{n?.removeService(e.service,e.probeId)}),[e.service]),t?(t.error||!t.isLoggedIn,e.children):null}function He(){return null}function Nt(e){let[n,t,r]=wt(e.resource),o=e.fallbackComponent||He,a=e.loadingComponent||He,i=e.errorComponent||He,s=t.service,u=null;if(!r||!s)return e.children(n);let c=s.service.filter(l=>l.type==="AuthAccessService2");t.status==="error"&&(u=J(i,{resource:e.resource,error:t.error||"",heading:t.errorHeading,note:t.errorNote,extra:e.extra})),(t.status==="unknown"||t.status==="probing")&&(u=J(a,{})),t.status==="success"&&(u=e.children(n));for(let l of c)u=J(pr,{service:l,probeId:s.id,children:u},l.id);return u}import{createContext as yr,useContext as Ba,useMemo as Sr}from"react";import{createStore as gr}from"zustand/vanilla";var hr=e=>e.id||e["@id"];function vr(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 kt=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 gr((o,a)=>({service:n,resources:[],lastQuery:{},loading:!1,error:!1,highlight:null,hasSearch:!!n,hasAutocomplete:n?!!vr(n):!1,errorMessage:"",search(i,s={}){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",...s.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 s=a().resources.find(u=>u["@id"]===i);o({highlight:s})},nextResult(){let i=a().resources,s=a().highlight;if(!s){o({highlight:i[0]||null});return}let u=i.findIndex(c=>c["@id"]===s["@id"]);if(u===-1){o({highlight:i[0]||null});return}o({highlight:i[u+1]||i[0]||null})},previousResult(){let i=a().resources,s=a().highlight;if(!s){o({highlight:i[i.length-1]||null});return}let u=i.findIndex(c=>c["@id"]===s["@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 Wa}from"zustand";function Et(){let e=w();return e?e.service.find(n=>n.profile==="SearchService1"||n.profile==="http://iiif.io/api/search/1/search"):void 0}import{jsx as qe}from"react/jsx-runtime";var te=yr(null);te.displayName="Search";function Lt(e){let n=Et();return e.store?qe(te.Provider,{value:e.store,children:e.children}):qe(Ar,{service:n,children:e.children})}function Ar({service:e,children:n}){let t=Sr(()=>kt(e),[e]);return qe(te.Provider,{value:t,children:n})}import{jsx as T}from"react/jsx-runtime";var le=()=>{},de=Cr({setCurrentCanvasId:le,setCurrentCanvasIndex:le,nextCanvas:le,previousCanvas:le,items:[],sequence:[],setSequenceIndex:le,currentSequenceIndex:0,hasNext:!1,hasPrevious:!1});function Pr(e){let n=w(),{cursor:t,visibleItems:r,next:o,sequence:a,items:i,setCanvasIndex:s,setCanvasId:u,previous:c,setSequenceIndex:l,hasNext:f,hasPrevious:d}=St({startCanvas:e.startCanvas,disablePaging:e.pagingEnabled===!1}),v=br(()=>({sequence:a,items:i,setCurrentCanvasId:u,nextCanvas:o,previousCanvas:c,totalCanvases:i.length,setCurrentCanvasIndex:s,setSequenceIndex:l,currentSequenceIndex:t,hasNext:f,hasPrevious:d}),[a,i,u,o,c,i,s,l,t]);return n?r.length===0?null:T(de.Provider,{value:v,children:T(K.Provider,{value:r,children:T(Z,{canvas:r[0],children:e.children})})}):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),T("div",{children:"Sorry, something went wrong."}))}function zt(e){let n=G(e.vault),t=pt(e.manifest);if(!t)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),T("div",{children:"Sorry, something went wrong."});if(t.error)return T("div",{children:t.error.toString()});if(!t.isLoaded)return T("div",{children:"Loading..."});let r=T(Pr,{...e,children:e.children});return T(W,{vault:n,children:T(gt,{manifest:t.id,children:T(Tt,{children:T(Lt,{children:e.rangeId?T(ht,{range:e.rangeId,children:r}):r})})})})}function Ot(){return xr(de)}import{jsx as fe}from"react/jsx-runtime";function Ft(){return{VaultContext:ne($),ResourceContext:ne(ye),SimpleViewerReactContext:ne(de),VisibleCanvasReactContext:ne(K),AuthRContext:ne(X),SearchReactContext:ne(te)}}function Ht(e){return fe(W,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext,children:fe(K.Provider,{value:e.bridge.VisibleCanvasReactContext,children:fe(de.Provider,{value:e.bridge.SimpleViewerReactContext,children:fe(X.Provider,{value:e.bridge.AuthRContext,children:fe(te.Provider,{value:e.bridge.SearchReactContext,children:e.children})})})})})}import{createContext as Tr,useContext as Vr,useMemo as Nr}from"react";import{useCallback as Ut,useLayoutEffect as Ir,useMemo as wr,useRef as Mr}from"react";import{entityActions as Be}from"@iiif/helpers/vault/actions";import{useMemo as Rr}from"react";function Dt(){let n=y().getStore();return Rr(()=>t=>n.dispatch(t),[n])}function _t(e){return typeof e!="string"&&e&&e.bindToVault}function qt(){let e=y(),n=Mr([]),t=Dt(),r=wr(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);Ir(()=>{let s={id:r,type:"AnnotationPage",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],rendering:[],service:[]};t(Be.importEntities({entities:{AnnotationPage:{[s.id]:s}}}))},[r]);let o=S(s=>r&&s.iiif.entities.AnnotationPage[r]||null,[r]),a=Ut((s,u)=>{if(r){if(_t(s)){let f=s;f.__vault||f.bindToVault(e),s=typeof f.source=="string"?f.source:f.source.id,n.current[s]=f}else typeof s!="string"&&(s=s.id);let c=e.get({id:r,type:"AnnotationPage"}),l=e.get({id:s,type:"Annotation"});c&&l&&(c.items.find(f=>f.id===l.id)||t(Be.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:s,type:"Annotation"},index:u})))}},[r]),i=Ut(s=>{r&&(_t(s)?s=typeof s.source=="string"?s.source:s.source.id:typeof s!="string"&&(s=s.id),n.current[s]&&n.current[s].beforeRemove(),e.get({id:r,type:"AnnotationPage"})&&t(Be.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:s,type:"Annotation"}})))},[r]);return[o,{addAnnotation:a,removeAnnotation:i}]}import{jsx as kr}from"react/jsx-runtime";var Bt=Tr(null);function $t(){let e=Vr(Bt);return[e.fullPage,{addAnnotation:e.addAnnotation,removeAnnotation:e.removeAnnotation}]}function jt({children:e}){let[n,{addAnnotation:t,removeAnnotation:r}]=qt();return kr(Bt.Provider,{value:Nr(()=>({fullPage:n,addAnnotation:t,removeAnnotation:r}),[n]),children:e})}import{jsx as $e,jsxs as Er}from"react/jsx-runtime";function Yt({width:e,style:n,height:t,error:r,resetErrorBoundary:o}){return Er("div",{style:{width:e,height:t,minHeight:500,...n||{},background:"#f9f9f9"},children:[$e("h3",{children:"Error occurred"}),$e("p",{children:r.message}),$e("button",{onClick:o,children:"Reset"})]})}import{createContext as Lr,useContext as zr}from"react";var me=Lr(null);function Qt(){return zr(me)}import{createContext as Wt,useContext as Or,useEffect as Fr}from"react";var je=Wt(()=>{}),Ye=Wt(()=>{});function L(e,n,t,r,o=[]){let a=Or(e==="portal"?Ye:je);Fr(()=>(e!=="none"&&a(n,t,r),()=>{a(n,null)}),[n,e,a,...o])}import{createContext as Dr,useContext as Ur,useEffect as _r}from"react";import{useMemo as Hr}from"react";function b(e={},n=[]){let{id:t,selector:r}=e,o=k(),a=t||o.canvas,i=S(s=>a?s.iiif.entities.Canvas[a]:void 0,[a]);return Hr(()=>{if(i)return r?r(i):i},[i,r,...n])}var Qe=Dr(()=>{});function Gt(e){let n=b(),t=Ur(Qe);_r(()=>n&&n.id?(t(n.id,e),()=>t(n.id,-1)):()=>{},[n,e])}import{Fragment as jr,jsx as R,jsxs as Yr}from"react/jsx-runtime";function Jt({children:e,errorFallback:n,outerContainerProps:t={},worldScale:r,...o}){let[a,i]=xe(),s=Ft(),u=n||Yt,[c,l]=xe({}),f=Object.entries(c),[d,v]=xe({}),m=Object.entries(d),[p,g]=xe({}),A=Kt(()=>r||Math.max(...Object.values(p)),[p]),D=Kt(()=>({maxOverZoom:A||1,...o.runtimeOptions||{}}),[A,o.runtimeOptions]),I=We((C,P)=>{g(N=>{if(P===-1){let{[C]:h,...O}=N;return O}return{...N,[C]:P}})},[]),Le=We((C,P,N)=>{l(({[C]:h,...O})=>P?{...O,[C]:{element:P,props:N}}:O)},[]),he=We((C,P,N)=>{v(({[C]:h,...O})=>P?{...O,[C]:{element:P,props:N}}:O)},[]);return Yr($r,{resetKeys:[],fallbackRender:C=>R(u,{...o,...C}),children:[R(qr,{...o,containerProps:{style:{position:"relative"},...o.containerProps||{}},htmlChildren:R(jr,{children:f.map(([C,{element:P,props:N}])=>R(Zt.Fragment,{children:R(P,{...N||{}})},C))}),onCreated:C=>{i(C),o.onCreated&&o.onCreated(C)},runtimeOptions:D,children:R(me.Provider,{value:a,children:R(Qe.Provider,{value:I,children:R(je.Provider,{value:Le,children:R(Ye.Provider,{value:he,children:R(Ht,{bridge:s,children:R(Br.Provider,{value:o.mode||"explore",children:R(jt,{children:e})})})})})})})}),R("div",{children:m.map(([C,{element:P,props:N}])=>R(Zt.Fragment,{children:R(P,{...N||{}})},C))})]})}import{mergeStyles as Jr,RegionHighlight as Xr}from"@atlas-viewer/atlas";import{useMemo as Xt}from"react";import{createEventsHelper as Qr}from"@iiif/helpers/events";function Ce(e,n){let t=y(),r=Xt(()=>Qr(t),[t]),o=S(()=>e&&e.id?t.getResourceMeta(e.id,"eventManager"):null,[e]);return Xt(()=>e?r.getListenersAsProps(e,n):{},[o,e,t,n])}import{useMemo as Wr}from"react";import{createStylesHelper as Gr}from"@iiif/helpers/styles";function re(e,n){let t=y(),r=Wr(()=>Gr(t),[t]);return S(()=>{if(!e)return null;let o=r.getAppliedStyles(e.id);return o?n?o[n]:o:void 0},[e,n])}import{useMemo as eo}from"react";import{useMemo as Zr}from"react";import{expandTarget as Kr}from"@iiif/helpers/annotation-targets";function be(e={},n=[]){let{id:t,selector:r}=e,o=k(),a=y(),i=t||o.annotation,s=S(c=>i?c.iiif.entities.Annotation[i]:void 0,[i]),u=S(c=>s&&s.body?s.body.map(l=>l?l.type==="SpecificResource"?{...l,source:a.get(l)}:l?c.iiif.entities[l.type][l.id]:null:null).filter(Boolean):[],[s]);return Zr(()=>{if(!s)return;let c={...s,body:u,target:Kr(s.target,{typeMap:a.getState().iiif.mapping})};return r?r(c):c},[s,r,u,...n])}import{jsx as to}from"react/jsx-runtime";var Pe=({id:e,style:n,className:t,interactive:r})=>{let o=be({id:e}),a=re(o,"atlas"),i=re(o,"html"),s=Ce(o,["atlas"]),u=b(),c=eo(()=>Jr(n,a),[n,a]);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)?to(Xr,{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:()=>{},...s}):null};import{Fragment as ro}from"react";import{useMemo as no}from"react";function en(e={},n=[]){let{id:t,selector:r}=e,o=k(),a=t||o.annotationPage,i=S(s=>a?s.iiif.entities.AnnotationPage[a]:void 0,[a]);return no(()=>{if(i)return r?r(i):i},[i,...n])}import{jsx as tn}from"react/jsx-runtime";var pe=({className:e,page:n})=>{let t=en({id:n.id})||n,r=re(t,"atlas"),o=re(t,"html");return S(a=>t.id?a.iiif.entities.AnnotationPage[t.id]:null,[]),tn(ro,{children:t.items?.map(a=>tn(Pe,{id:a.id,style:r,className:o?.className||e},a.id))})};import{createStylesHelper as jo}from"@iiif/helpers/styles";import{Fragment as cn,useMemo as lo}from"react";import{HTMLPortal as so,TileSet as sn}from"@atlas-viewer/atlas";import rn,{useMemo as Ge}from"react";import{jsx as q}from"react/jsx-runtime";var on=rn.createContext("en");function cc(e){return q(on.Provider,{value:e.language,children:e.children})}function Ze(){return rn.useContext(on)}function nn(e){return e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):e}function oo({as:e,language:n,children:t,viewingDirection:r,...o}){let a=Ze();return Ge(()=>nn(a)===nn(n),[a,n])?e?q(e,{...o,children:t}):q("span",{...o,children:t}):e?q(e,{...o,lang:n,dir:r,children:t}):q("span",{...o,lang:n,dir:r,children:t})}function an(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 io=(e,n=[])=>{let t=Ze();return Ge(()=>{let r=e();return an(t,r,[])},[t,...n])};function ao(e,n,t=`
2
- `){let r=io(()=>Object.keys(e||{}),[e]);return[Ge(()=>{if(!e)return n||"";if(typeof e=="string")return e;let o=r?e[r]:void 0;return o?typeof o=="string"?o:o.join(t):""},[r,n,e]),r]}function lc(){let e=Ze();return function(t,r,o){let a=Object.keys(t||{}),i=an(e,a,[]);if(!t)return r||"";if(typeof t=="string")return t;let s=i?t[i]:void 0;return s?typeof s=="string"?s:s.join(typeof o<"u"?o:`
3
- `):""}}function ge({as:e,defaultText:n,enableDangerouslySetInnerHTML:t,children:r,separator:o,...a}){let[i,s]=ao(r,n,o);return s?q(oo,{...a,as:e,language:s,title:t?void 0:i,dangerouslySetInnerHTML:t?{__html:i}:void 0,children:t?void 0:i}):e?q(e,{...a,children:i}):q("span",{...a,title:t?void 0:i,dangerouslySetInnerHTML:t?{__html:i}:void 0,children:t?void 0:i})}import{jsx as F,jsxs as co}from"react/jsx-runtime";function uo({resource:e,heading:n,note:t,extra:r}){return r?F(so,{target:{x:0,y:0,width:r.target?.spatial.width,height:r.target?.spatial.height},backgroundColor:"#333",relative:!0,children:F("div",{style:{display:"flex",alignContent:"center",justifyContent:"center",alignItems:"center",height:"100%",width:"100%",background:"#444",color:"#BBB"},children:co("div",{children:[F(ge,{children:n||"Not authorised"}),t&&F("p",{children:F(ge,{children:t})}),F("p",{children:e.id||e["@id"]||"unknown"})]})})}):null}function un({image:e,thumbnail:n,crop:t,enableSizes:r}){if(!Vt()){let a=e.service,i=a.width||e.width||0,s=a.height||e.height||0;return F(sn,{tiles:{id:a.id||a["@id"]||"unknown",height:s,width:i,imageService:a},enableSizes:r,x:0,y:0,width:e.target?.spatial.width,height:e.target?.spatial.height,crop:t})}return F(Nt,{resource:e.service,errorComponent:uo,extra:e,children:a=>{let i=a.width||e.width||0,s=a.height||e.height||0;return F(sn,{tiles:{id:a.id||a["@id"]||"unknown",height:s,width:i,imageService:a},enableSizes:r,x:0,y:0,width:e.target?.spatial.width,height:e.target?.spatial.height,crop:t})}},e.id)}import{jsx as Ke,jsxs as ln}from"react/jsx-runtime";function Re({id:e,image:n,thumbnail:t,isStatic:r,x:o=0,y:a=0,children:i,selector:s,onClick:u,enableSizes:c}){let l=lo(()=>{if(!(!s||s.spatial.x===0&&s.spatial.y===0))return s.spatial},[s]);return Ke("world-object",{x:o+n.target.spatial.x,y:a+n.target.spatial.y,width:n.target.spatial.width,height:n.target.spatial.height,onClick:u,children:n.service?ln(cn,{children:[Ke(un,{image:n,thumbnail:t,crop:l,enableSizes:c}),i]},"service"):ln(cn,{children:[Ke("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 Yo,useEffect as Nn,useLayoutEffect as Qo,useMemo as kn}from"react";import{HTMLPortal as Wo}from"@atlas-viewer/atlas";import{useMemo as An}from"react";import{useCallback as mn,useMemo as mo}from"react";function fo(e,n){let t=e?.iiif?.meta[n];return t?t.annotationPageManager:null}function dn(e,n){return S(t=>{let r=[];if(!e)return r;let o=Object.keys(t.iiif.entities.AnnotationPage);for(let a of o)if(!n||n.indexOf(a)!==-1){let i=fo(t,a);i&&i.views&&i.views[e]&&r.push(a)}return r},[e,n])}function fn({canvas:e,manifest:n,all:t,canvases:r}){let o=[];if(n)for(let a of n.annotations)o.indexOf(a.id)===-1&&o.push(a.id);if(t){if(r&&r.length)for(let a of r)for(let i of a.annotations)o.indexOf(i.id)===-1&&o.push(i.id)}else if(e)for(let a of e.annotations)o.indexOf(a.id)===-1&&o.push(a.id);return o}function po(e,n){let t=e?.iiif?.meta[n];return t?t.annotationPageManager:null}function pn(e,n={}){let t=y(),r=w(),o=b(),a=Se(),i=mo(()=>fn({all:n.all,manifest:r,canvas:o,canvases:a}),[n.all,o,a,r]),s=dn(e,n.all?void 0:i),u=mn(l=>{e&&t.setMetaValue([l,"annotationPageManager","views"],f=>f&&!f[e]?f:{...f||{},[e]:!1})},[e,t]),c=mn((l,f={})=>{if(!e)return;let d=t.getState(),v=[];if(f?.deselectOthers){let m=Object.keys(d.iiif.entities.AnnotationPage);for(let p of m){let g=po(d,p);g&&g.views&&g.views[e]&&v.push(p)}}for(let m of v)u(m);t.setMetaValue([l,"annotationPageManager","views"],m=>m&&m[e]?m:{...m||{},[e]:!0})},[e,u,t]);return{availablePageIds:i,enabledPageIds:s,setPageEnabled:c,setPageDisabled:u}}function gn(e,n){return S((t,r)=>r.get(e.map(o=>({id:o,type:n}))),[e,n])}import{useCallback as So,useEffect as Ao,useRef as xo,useState as Co}from"react";import go,{useContext as ho}from"react";import{ImageServiceLoader as vo}from"@atlas-viewer/iiif-image-api";var yo=go.createContext(new vo);function Ie(){return ho(yo)}function hn(){let e=Ie(),[n,t]=Co({}),r=xo(!1);return Ao(()=>()=>{r.current=!0},[]),[So((a,{height:i,width:s})=>{if(a){let u=a.id||a["@id"],c=e.loadServiceSync({id:u,width:a.width||s,height:a.height||i,source:a});c?a=c:n[u]||(r.current||t(l=>({...l,[u]:"loading"})),e.loadService({id:u,width:a.width||s,height:a.height||i}).then(()=>{r.current||t(l=>({...l,[u]:"done"}))}))}return a},[e,n]),n]}import{useCallback as bo,useMemo as yn,useState as Po}from"react";function vn(e={}){let n=be(),t=b(e.canvasId?{id:e.canvasId}:void 0);return S((r,o)=>{if(!t)return[];if(n&&e.enableSingleAnnotation)return[n];let a=o.get(t.items),i=[];for(let s of a)i.push(...o.get(s.items));return i},[t])}import{createPaintingAnnotationsHelper as Ro}from"@iiif/helpers/painting-annotations";function Sn(e,n=[]){let t=y(),r=yn(()=>Ro(t),[]),o=vn({enableSingleAnnotation:e?.enableSingleAnnotation}),[a,i]=Po(e?.defaultChoices||[]),s=yn(()=>r.getPaintables(o,a),[t,o,a,...n]),c={makeChoice:bo((l,{deselectOthers:f=!0,deselect:d=!1}={})=>{if(s.choice){if(s.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");i(v=>{if(d){let p=v.filter(g=>g!==l);if(p.length===0){let g=s.items[0].resource.id;return g?[g]:[]}return p}if(f)return[l];let m=[...v];if(m.length===0&&s.items.length){let p=s.items[0].resource.id;p&&m.push(p)}return v.indexOf(l)!==-1?v:[...v,l]})}},[s.choice])};return[s,c]}function xn(e){let n=w(),t=b(),r=y(),[o,a]=hn(),{enabledPageIds:i}=pn(e?.annotationPageManagerId||n?.id||t?.id,{all:!1}),s=gn(i,"AnnotationPage"),u=e?.strategies||["empty","images","media","textual-content","complex-timeline"],[c,l]=Sn(e,[a]),f=An(()=>lt({canvas:t,paintables:c,supports:u,loadImageService:o}),[t,c,r,l.makeChoice]);return An(()=>f.type==="unknown"?[f,ct]:[{...f,annotations:{pages:s}},l],[f,s])}import{useEffect as wo,useMemo as Mo,useRef as To,useState as Vo}from"react";import{useEffect as Io}from"react";var Cn=(e,n=[])=>{let t=y();Io(()=>{e(t)},[t,...n])};import{createThumbnailHelper as No}from"@iiif/helpers/thumbnail";function bn(e,n,{canvasId:t,manifestId:r}={}){let o=y(),a=Ie(),i=Mo(()=>No(o,{imageServiceLoader:a}),[o,a]),[s,u]=Vo(),c=w(r?{id:r}:void 0),l=b(t?{id:t}:void 0),f=l||c,d=To(!1);if(wo(()=>(d.current=!1,()=>{d.current=!0}),[]),!f)throw new Error("Must be called under a manifest or canvas context.");return Cn(v=>{i.getBestThumbnailAtSize(f,e,n).then(m=>{m.best&&!d.current&&u(m.best)})},[f]),s}import{useCallback as z,useEffect as Pn,useReducer as ko,useRef as we}from"react";function Eo(e){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:e}}function Lo(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 zo(e){let n=Math.round(e);return`${Math.floor(n/60)}:${`${n%60}`.padStart(2,"0")}`}function oe(e){let[n,t]=ko(Lo,Eo(e.duration)),r=we(null),o=we(null),a=we(null),i=we(!1),s=z(()=>{o.current&&r.current&&(o.current.innerHTML=zo(r.current.currentTime),a.current&&(a.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=z(()=>{r.current&&(t({type:"PLAY_REQUESTED"}),r.current.play().then(()=>{t({type:"PLAY"})}),s())},[s]),c=z(()=>{r.current&&(r.current.duration>0&&r.current.paused?u():l())},[s]),l=z(()=>{r.current&&(r.current.pause(),t({type:"PAUSE"}),s())},[s]),f=z(()=>{r.current&&(r.current.muted=!r.current.muted,t(r.current.muted?{type:"MUTE"}:{type:"UNMUTE"}))},[]),d=z(()=>{r.current&&(r.current.muted=!0,t({type:"MUTE"}))},[]),v=z(()=>{r.current&&(r.current.muted=!1,t({type:"UNMUTE"}))},[]),m=z(A=>{r.current&&(r.current.muted=!1,r.current.volume=A/100,t({type:"SET_VOLUME",volume:A}))},[]),p=z(A=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(A*e.duration,e.duration)),s())},[]),g=z(A=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(A,e.duration)),s())},[]);return Pn(()=>{let A=setInterval(()=>{s()},350);return()=>clearInterval(A)},[s,e.duration]),Pn(()=>{let A=()=>{t({type:"FINISHED"})},D=r.current;return D?.addEventListener("ended",A),()=>D?.removeEventListener("ended",A)},[]),[{element:r,currentTime:o,progress:a},n,{play:u,pause:l,playPause:c,mute:d,unmute:v,toggleMute:f,setVolume:m,setDurationPercent:p,setTime:g}]}import{createContext as Xe,useContext as et}from"react";import{jsx as Je}from"react/jsx-runtime";var Rn=Xe(null),In=Xe(null),wn=Xe(null);function Tl(){let e=et(Rn);if(!e)throw new Error("Ctx not found");return e}function Vl(){let e=et(In);if(!e)throw new Error("Ctx not found");return e}function Nl(){let e=et(wn);if(!e)throw new Error("Ctx not found");return e}function Me({actions:e,state:n,children:t,currentTime:r,progress:o,element:a}){return Je(wn.Provider,{value:{currentTime:r,progress:o,element:a},children:Je(In.Provider,{value:e,children:Je(Rn.Provider,{value:n,children:t})})})}import{jsx as Oo,jsxs as Fo}from"react/jsx-runtime";function tt({media:e,children:n}){let[{element:t,currentTime:r,progress:o},a,i]=oe({duration:e.duration});return Fo(Me,{state:a,actions:i,currentTime:r,progress:o,element:t,children:[Oo("audio",{ref:t,src:e.url}),n]})}function Te({media:e,mediaControlsDeps:n,children:t}){return L("portal","audio",tt,{media:e,children:t},[e,...n||[]]),null}import{jsx as Mn,jsxs as Ho}from"react/jsx-runtime";function nt({element:e,media:n,playPause:t}){return Ho("div",{className:"video-container",part:"video-container",onClick:t,children:[Mn("style",{children:`
4
- .video-container {
5
- position: absolute;
6
- top: 0;
7
- bottom: 0;
8
- left: 0;
9
- right: 0;
10
- background: #000;
11
- z-index: 13;
12
- display: flex;
13
- justify-content: center;
14
- pointer-events: visible;
15
- }
16
- `}),Mn("video",{ref:e,src:n.url,style:{width:"100%",objectFit:"contain"}})]})}function Ve({media:e,mediaControlsDeps:n,children:t}){let[{element:r,currentTime:o,progress:a},i,s]=oe({duration:e.duration});return L("overlay","video-element",nt,{element:r,media:e,playPause:s.playPause}),L("portal","custom-controls",Me,{state:i,actions:s,currentTime:o,progress:a,element:r,children:t},[o,i,e,...n||[]]),null}import{Fragment as Do,jsx as rt,jsxs as Uo}from"react/jsx-runtime";function ot({model:e}){return Uo(Do,{children:[rt("style",{children:`
17
- .model-container {
18
- position: absolute;
19
- top: 0;
20
- bottom: 0;
21
- left: 0;
22
- right: 0;
23
- background: #000;
24
- z-index: 13;
25
- display: flex;
26
- justify-content: center;
27
- pointer-events: visible;
28
- }
29
- `}),rt("div",{className:"model-container",children:rt("model-viewer",{"interaction-prompt":"none",style:{width:"100%",height:"100%"},"camera-controls":"","ar-status":"not-presenting",src:e.id})})]})}function Ne({model:e,name:n}){return L("overlay",`model-${n}`,ot,{model:e},[e]),null}import{jsx as _o}from"react/jsx-runtime";function ke({style:e}){let n=b();return!n||!n.height||!n.width?null:_o("box",{interactive:!1,target:{x:0,y:0,width:Number(n.width),height:Number(n.height)},style:e})}import{useRef as qo}from"react";import{jsx as Tn,jsxs as $o}from"react/jsx-runtime";function Bo({element:e,media:n,playPause:t}){let r=qo(null);return n.youTubeId?$o("div",{className:"video-container",part:"video-container",onClick:t,children:[Tn("style",{children:`
30
- .video-container {
31
- position: absolute;
32
- top: 0;
33
- bottom: 0;
34
- left: 0;
35
- right: 0;
36
- background: #000;
37
- z-index: 13;
38
- display: flex;
39
- justify-content: center;
40
- pointer-events: visible;
41
- }
42
- .video-yt {
43
- border: none;
44
- width: 100%;
45
- object-fit: contain;
46
- }
47
- `}),Tn("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 Vn({media:e,mediaControlsDeps:n,children:t}){let[{element:r,currentTime:o,progress:a},i,s]=oe({duration:e.duration});return L("overlay","video-element",Bo,{element:r,media:e,playPause:s.playPause}),null}import{Fragment as Ee,jsx as V,jsxs as B}from"react/jsx-runtime";function it({x:e,y:n,onChoiceChange:t,registerActions:r,defaultChoices:o,isStatic:a,renderViewerControls:i,renderMediaControls:s,viewControlsDeps:u,mediaControlsDeps:c,strategies:l,throwOnUnknown:f,backgroundStyle:d,alwaysShowBackground:v,keepCanvasScale:m=!1,enableSizes:p=!1,enableYouTube:g=!0,onClickPaintingAnnotation:A,children:D}){let I=b(),Le=Ce(I,["deep-zoom"]),[he]=$t(),C=Qt(),P=y(),N=kn(()=>jo(P),[P]),[h,O]=xn({strategies:l||["images"],defaultChoices:o?.map(({id:x})=>x)}),at=h.type==="images"?h.choice:void 0,Ln=kn(()=>m?1:Math.max(1,...h.type==="images"?h.images.map(x=>(x.width||0)/x.target?.spatial.width):[]),[m,h]);Gt(Ln),Nn(()=>{r&&r(O)},[h.annotations]),Nn(()=>{if(o)for(let x of o)typeof x.opacity<"u"&&N.applyStyles({id:x.id},"atlas",{opacity:x.opacity})},[o]),Qo(()=>{t&&t(at)},[at]),L(C&&(h.type==="images"||h.type==="empty"||h.type==="textual-content"&&i)?"overlay":"none",`canvas-portal-controls-${I?.id}`,me.Provider,i?{value:C||null,children:i(h)}:{},[I,C,h,...u||[]]);let U=bn({maxWidth:256,maxHeight:256});if(!I)return null;let st=I.accompanyingCanvas,ie=U&&U.type==="fixed"?V("world-object",{height:I.height,width:I.width,x:e,y:n,children:V("world-image",{uri:U.id,target:{x:0,y:0,width:I.width,height:I.height},display:U.width&&U.height?{width:U.width,height:U.height}:void 0,crop:void 0})}):null;if(h.type==="unknown"){if(ie)return ie;if(f)throw new Error(h.reason||"Unknown image strategy");return null}let ut=B(Yo,{children:[he?V(pe,{page:he}):null,h.annotations&&h.annotations.pages?h.annotations.pages.map(x=>V(pe,{page:x},x.id)):null,D]}),zn=h.type==="images"?h.images.length:0;return B(Ee,{children:[B("world-object",{height:I.height,width:I.width,x:e,y:n,...Le,children:[h.type==="empty"||v?V(ke,{style:d}):null,h.type==="textual-content"?h.items.map((x,ve)=>B(Ee,{children:[V(Wo,{onClick:A?ae=>{ae.stopPropagation(),A(x.annotationId,x,ae)}:void 0,target:x.target?.spatial||void 0,children:V("div",{"data-textual-content":!0,children:V(ge,{enableDangerouslySetInnerHTML:!0,children:x.text})})},ve),ut]})):null,h.type==="images"?B(Ee,{children:[h.images.map((x,ve)=>V(Re,{isStatic:a,image:x,id:x.id,thumbnail:ve===0?U:void 0,selector:x.selector,enableSizes:p,onClick:A?ae=>{ae.stopPropagation(),A(x.annotationId,x,ae)}:void 0},x.id+ve)),ut]}):null,h.type==="3d-model"?V(Ne,{model:h.model}):null,h.type==="media"?V(Ee,{children:h.media.type==="Sound"?B(Te,{media:h.media,mediaControlsDeps:c,children:[ie,s?s(h):null]}):h.media.type==="Video"?B(Ve,{media:h.media,mediaControlsDeps:c,children:[ie,s?s(h):null]}):h.media.type==="VideoYouTube"&&g?B(Vn,{media:h.media,mediaControlsDeps:c,children:[ie,s?s(h):null]}):null}):null]},`${I.id}/${h.type}/${zn}`),h.type==="media"&&h.media.type==="Sound"&&st?V(Z,{canvas:st.id,children:V(it,{renderViewerControls:i})}):null]})}import{Fragment as Ko,jsx as H,jsxs as Jo}from"react/jsx-runtime";var Zo=En(function(n,t){let r=w(),o=Se(),a=Ot(),{ViewerControls:i,MediaControls:s}=n.components||{};if(Go(t,()=>a,[a]),!r)return H("div",{});let u=0;return Jo(Ko,{children:[n.header,H(M.Viewer,{height:n.height,mode:n.mode,children:o.map((c,l)=>{let f=u;return u+=c.width+(n.spacing||0),H(Z,{canvas:c.id,children:H(M.RenderCanvas,{strategies:["3d-model","media","images","empty","textual-content"],renderViewerControls:l===0&&i?()=>H(i,{}):void 0,renderMediaControls:l===0&&s?()=>H(s,{}):void 0,x:f,...n.canvasProps||{},children:n.annotations},c.id)},c.id)})},n.reuseAtlas?"":a.currentSequenceIndex),n.children]})}),M=En(function({children:n,height:t,annotations:r,canvasProps:o,spacing:a,header:i,components:s,mode:u,reuseAtlas:c,...l},f){let d=G();return H(W,{vault:d,children:H(zt,{...l,children:H(Zo,{ref:f,height:t,components:s,spacing:a,canvasProps:o,annotations:r,header:i,mode:u,reuseAtlas:c,children:n})})})});M.RenderImage=Re;M.RenderCanvas=it;M.RenderAnnotationPage=pe;M.RenderAnnotation=Pe;M.Viewer=Jt;M.CanvasBackground=ke;M.Audio=Te;M.Video=Ve;M.Model=Ne;M.AudioHTML=tt;M.VideoHTML=nt;M.ModelHTML=ot;export{ye as a,k as b,_ as c,$ as d,W as e,G as f,mt as g,pt as h,gt as i,Z as j,y as k,S as l,K as m,Se as n,w as o,ht as p,rr as q,Oe as r,Qi as s,vt as t,Zi as u,Fe as v,yt as w,St as x,ca as y,xt as z,Ct as A,bt as B,j as C,se as D,X as E,ee as F,_e as G,Tt as H,wa as I,Vt as J,ce as K,fr as L,Ma as M,mr as N,Mt as O,Ta as P,Va as Q,Na as R,ka as S,Ea as T,La as U,Nt as V,Et as W,de as X,Pr as Y,zt as Z,Ot as _,Ft as $,Ht as aa,Dt as ba,qt as ca,$t as da,jt as ea,me as fa,Qt as ga,b as ha,Ce as ia,re as ja,be as ka,en as la,cc as ma,Ze as na,oo as oa,io as pa,ao as qa,lc as ra,ge as sa,fn as ta,pn as ua,gn as va,yo as wa,Ie as xa,hn as ya,vn as za,Sn as Aa,xn as Ba,Cn as Ca,bn as Da,zo as Ea,oe as Fa,Tl as Ga,Vl as Ha,Nl as Ia,Me as Ja,M as Ka};