react-iiif-vault 2.0.10 → 2.0.11

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,5 +1,5 @@
1
- import{c as ln,l as un}from"./chunk-P7XHGETS.js";import{forwardRef as Vr,useImperativeHandle as Ol,useMemo as Bl}from"react";import Nr,{useContext as Lr,useMemo as zr}from"react";import{jsx as Br}from"react/jsx-runtime";var Or={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},$e=Nr.createContext(Or),_=()=>Lr($e);function ie({value:e,children:t}){let n=_(),o=zr(()=>({...n,...e}),[e,n]);return Br($e.Provider,{value:o,children:t})}import{jsx as Hr}from"react/jsx-runtime";function ee({canvas:e,children:t}){return Hr(ie,{value:{canvas:e},children:t})}import Dr,{useState as qr}from"react";import{Vault as cn,globalVault as $r}from"@iiif/helpers/vault";import{jsx as dn}from"react/jsx-runtime";var le=Dr.createContext({vault:null,setVaultInstance:e=>{}});function ge({vault:e,vaultOptions:t,useGlobal:n,resources:o,children:s}){let[i,r]=qr(()=>e||(n?$r(t):t?new cn(t):new cn));return dn(le.Provider,{value:{vault:i,setVaultInstance:r},children:dn(ie,{value:o||{},children:s})})}import{useContext as _r}from"react";import jr from"react";import{useContext as Fr}from"react";var M=()=>{let{vault:e}=Fr(le);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};import{useEffect as Wr,useState as Ur}from"react";function k(e,t=[]){let n=M(),[o,s]=Ur(()=>e(n.getState(),n));return Wr(()=>n.subscribe(i=>e(i,n),i=>{s(i)},!1),t),o}var he=jr.createContext([]);function Fe(){let e=_r(he);return k(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}import{globalVault as Kr}from"@iiif/helpers/vault";import{useContext as Yr}from"react";function ye(e){let t=Yr(le);return e||(t&&t.vault?t.vault:Kr())}import{useMemo as Gr}from"react";function B(e={},t=[]){let{id:n,selector:o}=e,s=_(),i=M(),r=n||s.manifest,a=k(l=>r?l.iiif.entities.Manifest[r]:void 0,[r]);return Gr(()=>{if(a)return o?o(a):a},[a,o,...t])}import{useContext as Si}from"react";import{createContext as xi,useMemo as bi}from"react";import{useEffect as Qr,useMemo as Xr,useState as yt}from"react";function mn(e,{noCache:t=!1}={}){let n=typeof e=="string"?e:e.id,o=ye(),[s,i]=yt(n),[r,a]=yt(void 0),l=Xr(()=>o.get(n,{skipSelfReturn:!0})||void 0,[n,o]),[u,g]=yt(l);return Qr(()=>{(async()=>{try{let c=l&&!t?l:await o.load(n),d=c?c.id||c["@id"]:null;c&&s!==d&&i(d),g(c)}catch(c){a(c)}})()},[n,t]),{isLoaded:!!u,id:s,requestId:n,error:r,resource:u,cached:!!(u&&u===l)}}function pn(e,t){let{id:n,isLoaded:o,error:s,resource:i,requestId:r,cached:a}=mn(e,t);return{id:n,isLoaded:o,error:s,manifest:i,requestId:r,cached:a}}import{jsx as Zr}from"react/jsx-runtime";function fn({manifest:e,children:t}){return Zr(ie,{value:{manifest:e},children:t})}import{jsx as Jr}from"react/jsx-runtime";function gn({range:e,children:t}){return Jr(ie,{value:{range:e},children:t})}function ei(e,t){for(let n of t.items){if(n.type==="Canvas")return n;if(n.type==="SpecificResource")return n.source;if(n.type==="Range"){let o=ei(e,e.get(n));if(o)return o}}return null}function vt(e,t){let n=[];for(let o of t.items)if(o.type==="SpecificResource"&&o.source?.type==="Canvas"&&(o.source.id.indexOf("#")!==-1?n.push({id:o.source.id.split("#")[0],type:"Canvas"}):n.push(o.source)),o.type==="Range"&&n.push(...vt(e,e.get(o))),o.type==="SpecificResource"){let s=typeof o.source=="string"?o.source:o.source.id;n.push({id:s,type:"Canvas"})}return n}function Ou(e,t,n){for(let o of t.structures){let s=hn(e,e.get(o),n);if(s)return s}return null}function hn(e,t,n){for(let o of t.items){let s=o?.source?.id?.split("#")[0];if(o.type==="SpecificResource"&&o.source===n||o.type==="SpecificResource"&&o.source?.type==="Canvas"&&n===s)return t;if(o.type==="Range"){let i=hn(e,e.get(o),n);if(i)return i}}return null}function Du(e,t,n,o=!1){let s=t.behavior,i=n?e.get(n):null;if(!i)return[];let r=i.behavior,a=o?!1:s.includes("paged"),l=a?!1:s.includes("continuous"),u=a||l?!1:s.includes("individuals"),g=r.includes("facing-pages"),c=r.includes("non-paged");if(g||c||u||o)return[{id:i.id,type:"Canvas"}];let[d,p]=St(e,t);if(l)return d;let y=d.findIndex(f=>f.id===n);if(y===-1)return[];for(let f of p)if(f.includes(y))return f.map(x=>d[x]);return[{id:i.id,type:"Canvas"}]}function St(e,t,{disablePaging:n,skipNonPaged:o}={}){let s=t.behavior,i=s.includes("paged"),r=i?!1:s.includes("continuous"),a=i||r?!1:s.includes("individuals"),l=t.type==="Manifest"?t.items:vt(e,t);if(r)return[l,[l.map((y,f)=>f)]];if(a||!i||n)return[l,l.map((y,f)=>[f])];let u=[],g=[],c=()=>{g.length&&(u.push([...g]),g=[])},d=0,p=!1;for(let y=0;y<l.length;y++){let f=e.get(l[y]);if(f.behavior.includes("non-paged")){y===d&&d++,o||(c(),u.push([y]),c());continue}if(y===d||f.behavior.includes("facing-pages")){g.length&&(p=!0),c(),u.push([y]),c();continue}if(g.push(y),p){c(),p=!1;continue}g.length>1&&c()}return g.length&&c(),[l,u]}import{useCallback as We,useMemo as ni,useRef as oi,useState as ri}from"react";import{useMemo as ti}from"react";function yn(e={},t=[]){let{id:n,selector:o}=e,s=_(),i=n||s.range,r=k(a=>i?a.iiif.entities.Range[i]:void 0,[i]);return ti(()=>{if(r)return o?o(r):r},[r,o,...t])}function vn({startCanvas:e,disablePaging:t}){let n=M(),o=B(),s=yn(),[i,r]=ri(void 0),a=s||o;if(!a)throw new Error("Nothing selected");let[l,u]=ni(()=>St(n,a,{disablePaging:t}),[n,a,t]),g=oi(u);if(g.current!==u){let x=g.current[i][0],v=u.findIndex(m=>m.includes(x));g.current=u,r(v)}let c=We(f=>{let x=u.findIndex(v=>v.includes(f));r(x===-1?0:x)},[l,u]),d=We(f=>{let x=l.findIndex(v=>v.id===f);x!==-1?c(x):r(0)},[l,u]),p=We(()=>{r(f=>f>=u.length-1?f:f+1)},[u]),y=We(()=>{r(f=>f<=0?0:f-1)},[u]);return typeof i>"u"&&(e?d(e):r(0)),{visibleItems:u[i]?.map(f=>l[f].id)||[],cursor:i,items:l,sequence:u,hasPrevious:i>0,hasNext:i<u.length-1,setSequenceIndex:r,setCanvasIndex:c,setCanvasId:d,next:p,previous:y}}import{createContext as Ct,useContext as Mn,useEffect as ai,useMemo as si}from"react";import{useStore as Ve}from"zustand";import{createStore as xn}from"zustand/vanilla";function Zu(e){let t=e.service||e.services||[];for(let n of t)if(n.type==="AuthProbeService2")return!0;return!1}function j(e,t,n){let o=t.findIndex(r=>r.service.id===e);if(o===-1)return t;let s=[...t],i=n(s[o]);return i===s[o]?t:(s[o]=i,s)}var bn=()=>xn((e,t)=>({currentAuth:-1,authItems:[],login:()=>{let n=t().authItems[t().currentAuth];if(!n||n.isPending||n.isLoggedIn)return;if(n.type!=="active")throw new Error("Cannot login to non-active service");let o=n.service.service.find(s=>s.type==="AuthAccessTokenService2");if(!o)throw new Error("Token service not found");e(()=>({authItems:j(n.id,t().authItems,s=>({...s,isPending:!0}))})),Sn(n.service).then(()=>{xt(o).then(s=>{let i=s.expiresIn,r=Date.now()+i*1e3;e(()=>({authItems:j(n.id,t().authItems,a=>({...a,isLoggedIn:!0,isPending:!1,session:{token:s.accessToken,expires:r}}))}))}).catch(s=>{e(()=>({authItems:j(n.id,t().authItems,i=>({...i,isLoggedIn:!1,isPending:!1,error:s.message}))}))})})},logout:()=>{let n=t().authItems[t().currentAuth];if(!n||n.isPending||!n.isLoggedIn)return;if(n.type!=="active")throw new Error("Cannot logout of non-active service");let o=n.service.service.find(r=>r.type==="AuthLogoutService2");if(!o)return;let s=`${o.id}?origin=${An()}`,i=window.open(s);e(()=>({authItems:j(n.id,t().authItems,r=>({...r,isLoggedIn:!1,session:null,isPending:!1}))}))},nextAuth:()=>{let n=t().authItems.length,o=t().currentAuth+1;o>=n||e(()=>({currentAuth:o}))},previousAuth:()=>{let n=t().currentAuth-1;n<0||e(()=>({currentAuth:n}))},setAuth:n=>{n!==-1&&(n<0||n>=t().authItems.length)||e(()=>({currentAuth:n}))},addService:(n,o)=>{if(!n.service)return;let s=n.service.find(a=>a.type==="AuthAccessTokenService2"),i=n;if(t().authItems.find(a=>a.service.id===n.id)){e(()=>({authItems:j(n.id,t().authItems,a=>({...a,instances:a.instances+1}))}));return}if(e(()=>({currentAuth:i.profile==="active"?0:t().currentAuth,authItems:[{id:n.id,type:n.profile,service:n,probeId:o,canAuthenticate:!0,instances:1,isPending:!1,isLoggedIn:!1,session:null},...t().authItems]})),n.profile==="external"){if(!s)throw new Error("Token service not found");xt(s).then(a=>{e(()=>({authItems:j(n.id,t().authItems,l=>({...l,isLoggedIn:!0,isPending:!1,session:{token:a.accessToken,expires:a.expiresIn}}))}))}).catch(a=>{e(()=>({authItems:j(n.id,t().authItems,l=>({...l,isLoggedIn:!1,isPending:!1,canAuthenticate:!1,error:a.message}))}))})}if(n.profile==="kiosk"){if(!s)throw new Error("Token service not found");e(()=>({authItems:j(n.id,t().authItems,a=>({...a,isPending:!0}))})),Sn(i).then(()=>{xt(s).then(a=>{e(()=>({authItems:j(n.id,t().authItems,l=>({...l,isLoggedIn:!0,isPending:!1,session:{token:a.accessToken,expires:a.expiresIn}}))}))}).catch(a=>{e(()=>({authItems:j(n.id,t().authItems,l=>({...l,isLoggedIn:!1,isPending:!1,error:a.message}))}))})})}n.profile},removeService:(n,o)=>{let s=t().currentAuth===t().authItems.findIndex(r=>r.service.id===n.id),i=t().currentAuth;if(s){let r=t().authItems.find(l=>l.service.id===n.id);r&&r.instances>1||(i=t().authItems.findIndex(u=>u.service.id!==n.id&&u.instances>0))}e(()=>({authItems:j(n.id,t().authItems,r=>({...r,instances:r.instances-1})),currentAuth:i}))}})),Cn=(e,t)=>xn((n,o)=>({service:e,status:e?"unknown":"success",shouldRedirect:!1,redirectResource:null,shouldSubstitute:!1,substituteResource:null,error:null,errorHeading:null,errorNote:null,shouldDisplayResource:!1,token:t||null,async probe(){if(!o().service)return;let s=o().service?.id;if(!s){n({status:"error",error:"Service ID not found",errorHeading:{en:["Service ID not found"]}});return}n({status:"probing"});let i=o().token;try{let r=await fetch(s,{headers:i?{Authorization:`Bearer ${o().token}`,Accept:"application/json"}:{Accept:"application/json"}}).then(a=>a.json());if(r.status===200)n({status:"success",shouldDisplayResource:!0,error:null,errorHeading:null,errorNote:null,shouldSubstitute:!1,shouldRedirect:!1});else if(r.status<400&&r.status>=300){if(!r.location)throw new Error("Redirect location not found");n({status:"error",shouldDisplayResource:!1,shouldRedirect:!0,redirectResource:r.location||null})}else if(r.status===401)n({status:"error",shouldDisplayResource:!1,shouldRedirect:!1,shouldSubstitute:!!r.substitute,substituteResource:r.substitute||null,error:"Unauthorized",errorHeading:r.heading||{en:["Unauthorized"]},errorNote:r.note||null});else throw new Error("Unknown error")}catch(r){n({status:"error",error:r.message,errorHeading:{en:["Unknown error"]}})}},setToken(s){n({token:s})}}));function Rn(e){let t=e.service||e.services||[],n={hasAuth:!1,services:{}};for(let o of t)if(o.type==="AuthProbeService2"){n.services.probe=o,n.hasAuth=!0;let s=o.service.filter(i=>i.type==="AuthAccessService2");s[0]&&(n.services.access=s[0])}return n}async function xt(e,{strict:t=!0}={}){return new Promise((n,o)=>{let s=Math.random().toString(36).substring(7),i=`${e.id}?messageId=${s}&origin=${window.location.origin}`,r=u=>{let g=u.data;if(g.messageId===s){if(t&&g.type!=="AuthAccessToken2"){a(),o("Invalid response, expected type=AuthAccessToken2");return}if(!g.accessToken){a(),o("Invalid response, expected accessToken");return}a(),n(g)}},a=()=>window.removeEventListener("message",r),l=document.createElement("iframe");l.src=i,l.style.display="none",document.body.appendChild(l),window.addEventListener("message",r)})}function An(e){let t=window.location;if(e){let n=document.createElement("a");return n.href=e,n.protocol+"//"+n.hostname+(n.port?":"+n.port:"")}return t.protocol+"//"+t.hostname+(t.port?":"+t.port:"")}async function Sn(e){let t=`${e.id}?origin=${An()}`,n=window.open(t);if(!n)throw new Error("Failed to open window");return new Promise((o,s)=>{let i=setInterval(()=>{n.closed&&(clearInterval(i),o())},500)})}import{useEffect as Pn,useMemo as wn}from"react";import{useStore as ii}from"zustand";function Tn(e){let t=wn(()=>Rn(e),[e]),n=In(t.services.access?.id),o=wn(()=>Cn(t.services.probe,n),[t.services.probe]),s=ii(o);return Pn(()=>{s.status==="unknown"&&!n&&s.probe()},[t.services.probe,s.status]),Pn(()=>{n&&(s.setToken(n),s.probe())},[n]),[e,s,t.hasAuth]}import{jsx as Ue}from"react/jsx-runtime";var ve=Ct(null),li=Ct(null);li.displayName="CurrentAuth";var ui=Ct(null);ui.displayName="AuthActions";function kn({children:e}){let t=si(()=>bn(),[]);return Ue(ve.Provider,{value:t,children:e})}function En(){return!!Mn(ve)}function Ne(){let e=Mn(ve);if(!e)throw new Error("useAuthActions must be used within a AuthProvider");return e}function ci(){let e=Ne();return Ve(e,n=>({login:n.login,logout:n.logout,nextAuth:n.nextAuth,previousAuth:n.previousAuth,setAuth:n.setAuth,addService:n.addService,removeService:n.removeService}))}function hc(){let e=Ne();return Ve(e,t=>t)}function di(e){let t=Ne();return Ve(t,o=>o.authItems.find(s=>s.service.id===e))}function In(e){let t=Ne();return Ve(t,o=>o.authItems.find(s=>s.id===e)?.session?.token)}function yc(e){let t=Ne();return Ve(t,o=>{let s=o.authItems.find(i=>i.service.id===e);return!s||!s.isLoggedIn||!s.session?null:s.session?.token||null})}function mi(e){let t=ci(),n=di(e.service.id);return ai(()=>(t?.addService(e.service,e.probeId),()=>{t?.removeService(e.service,e.probeId)}),[e.service]),n?(n.error||!n.isLoggedIn,e.children):null}function bt(){return null}function Vn(e){let[t,n,o]=Tn(e.resource),s=e.fallbackComponent||bt,i=e.loadingComponent||bt,r=e.errorComponent||bt,a=n.service,l=null;if(!o||!a)return e.children(t);let u=a.service.filter(g=>g.type==="AuthAccessService2");n.status==="error"&&(l=Ue(r,{resource:e.resource,error:n.error||"",heading:n.errorHeading,note:n.errorNote,extra:e.extra})),(n.status==="unknown"||n.status==="probing")&&(l=Ue(i,{})),n.status==="success"&&(l=e.children(t));for(let g of u)l=Ue(mi,{service:g,probeId:a.id,children:l},g.id);return l}import{createContext as hi,useContext as wc,useMemo as yi}from"react";import{createStore as pi}from"zustand/vanilla";var fi=e=>e.id||e["@id"];function gi(e){return(Array.isArray(e.service)?e.service:[e.service]).find(n=>n.profile==="http://iiif.io/api/search/0/autocomplete"||n.profile==="http://iiif.io/api/search/1/autocomplete"||n.profile==="AutoCompleteService1")}var Nn=e=>{let t;typeof e=="string"?t={"@context":"http://iiif.io/api/search/1/context.json",profile:"http://iiif.io/api/search/1/search","@id":e,id:e,service:[]}:t=e;let n=t?fi(t):void 0,o=null;return pi((s,i)=>({service:t,resources:[],lastQuery:{},loading:!1,error:!1,highlight:null,hasSearch:!!t,hasAutocomplete:t?!!gi(t):!1,errorMessage:"",search(r,a={}){if(!n)throw new Error("No search service found.");o&&!o.signal.aborted&&o.abort(),o=new AbortController;let l=new URLSearchParams;r.q&&l.set("q",r.q),r.motivation&&l.set("motivation",r.motivation),r.date&&l.set("date",r.date),r.user&&l.set("user",r.user),s({loading:!0}),fetch(`${n}?${l.toString()}`,{signal:o.signal,headers:{"Content-Type":"application/json",Accept:"application/json",...a.headers||{}}}).then(async u=>{if(!o?.signal.aborted)if(u.ok){let g=await u.json();s({resources:g.resources,error:!1,errorMessage:""})}else s({resources:[],error:!0,errorMessage:u.statusText})})},clearSearch(){s({resources:[],error:!1,errorMessage:""})},highlightResult(r){let a=i().resources.find(l=>l["@id"]===r);s({highlight:a})},nextResult(){let r=i().resources,a=i().highlight;if(!a){s({highlight:r[0]||null});return}let l=r.findIndex(u=>u["@id"]===a["@id"]);if(l===-1){s({highlight:r[0]||null});return}s({highlight:r[l+1]||r[0]||null})},previousResult(){let r=i().resources,a=i().highlight;if(!a){s({highlight:r[r.length-1]||null});return}let l=r.findIndex(u=>u["@id"]===a["@id"]);if(l===-1){s({highlight:r[r.length-1]||null});return}if(l===0){s({highlight:r[r.length-1]||null});return}s({highlight:r[l-1]||r[r.length-1]||null})}}))};import{useStore as Ec}from"zustand";function Ln(){let e=B();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}import{jsx as Rt}from"react/jsx-runtime";var Se=hi(null);Se.displayName="Search";function zn(e){let t=Ln();return e.store?Rt(Se.Provider,{value:e.store,children:e.children}):Rt(vi,{service:t,children:e.children})}function vi({service:e,children:t}){let n=yi(()=>Nn(e),[e]);return Rt(Se.Provider,{value:n,children:t})}import{jsx as F}from"react/jsx-runtime";var Le=()=>{},ze=xi({setCurrentCanvasId:Le,setCurrentCanvasIndex:Le,nextCanvas:Le,previousCanvas:Le,items:[],sequence:[],setSequenceIndex:Le,currentSequenceIndex:0,hasNext:!1,hasPrevious:!1});function Ci(e){let t=B(),{cursor:n,visibleItems:o,next:s,sequence:i,items:r,setCanvasIndex:a,setCanvasId:l,previous:u,setSequenceIndex:g,hasNext:c,hasPrevious:d}=vn({startCanvas:e.startCanvas,disablePaging:e.pagingEnabled===!1}),p=bi(()=>({sequence:i,items:r,setCurrentCanvasId:l,nextCanvas:s,previousCanvas:u,totalCanvases:r.length,setCurrentCanvasIndex:a,setSequenceIndex:g,currentSequenceIndex:n,hasNext:c,hasPrevious:d}),[i,r,l,s,u,r,a,g,n]);return t?o.length===0?null:F(ze.Provider,{value:p,children:F(he.Provider,{value:o,children:F(ee,{canvas:o[0],children:e.children})})}):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),F("div",{children:"Sorry, something went wrong."}))}function On(e){let t=ye(e.vault),n=pn(e.manifest);if(!n)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),F("div",{children:"Sorry, something went wrong."});if(n.error)return F("div",{children:n.error.toString()});if(!n.isLoaded)return F("div",{children:"Loading..."});let o=F(Ci,{...e,children:e.children});return F(ge,{vault:t,children:F(fn,{manifest:n.id,children:F(kn,{children:F(zn,{children:e.rangeId?F(gn,{range:e.rangeId,children:o}):o})})})})}function _e(){return Si(ze)}import{ModeContext as Vi}from"@atlas-viewer/atlas";import{createContext as Ni,useContext as Wn,useEffect as Li,useMemo as zi}from"react";import{useStore as Oi}from"zustand";import Ri from"mitt";import{createContext as Ai,useContext as Bn,useEffect as Pi}from"react";import{jsx as Ti}from"react/jsx-runtime";var wi=Ri(),At=Ai(wi);function id({children:e,emitter:t}){return Ti(At.Provider,{value:t,children:e})}function Hn(){return Bn(At)}function Dn(e,t,n=[]){let o=Bn(At);Pi(()=>{let s=i=>{t(i)};return o.on(e,s),()=>{o.off(e,s)}},[o,e,...n])}import{createHelper as Mi}from"polygon-editor";import{createStore as ki}from"zustand/vanilla";function Pt(e){let t=Math.max(...e.map(i=>i[0])),n=Math.min(...e.map(i=>i[0])),o=Math.max(...e.map(i=>i[1])),s=Math.min(...e.map(i=>i[1]));for(let i of e)if(i[0]!==n&&i[0]!==t&&i[1]!==s&&i[1]!==o||i[0]<n||i[0]>t||i[1]<s||i[1]>o)return!1;return!0}function xe(e){if(!e)return null;if(e.points.length>2){let t=Math.min(...e.points.map(i=>i[0])),n=Math.min(...e.points.map(i=>i[1])),o=Math.max(0,...e.points.map(i=>i[0])),s=Math.max(0,...e.points.map(i=>i[1]));return{x:t,y:n,width:o-t,height:s-n}}return null}function Ii(e){return e.type==="SvgSelector"}function cd(e){return e.type==="BoxSelector"}function wt(e,t){if(Ii(e)){let r=e.svgShape==="polyline";if(!e.points||e.points.length===0)return null;if(t){let{width:a,height:l}=t;return{type:"SvgSelector",value:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${a} ${l}" width="${a}" height="${l}"><${r?"polygon":"polyline"} points="${e.points.map(g=>g.join(",")).join(" ")}" /></svg>`}}return{type:"SvgSelector",value:`<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'><g><path d='M${e.points.map(a=>a.join(",")).join(" ")}${r?" Z":""}' /></g></svg>`}}if(!e.spatial)return null;let{x:n,y:o,width:s,height:i}=e.spatial||{};return!s||!i?null:{type:"FragmentSelector",value:`xywh=${~~n},${~~o},${~~s},${~~i}`}}function Tt(e,t){if(!e||!e.points.length)return null;if(Pt(e.points)){let n=e.points.map(l=>l[0]),o=e.points.map(l=>l[1]),s=Math.min(...n),i=Math.min(...o),r=Math.max(...n)-s,a=Math.max(...o)-i;return wt({type:"BoxSelector",spatial:{x:s,y:i,width:r,height:a}},t)}return wt({type:"SvgSelector",points:e.points,svgShape:e.open?"polygon":"polyline"},t)}function qn(e){if(e.type==="polygon"&&!e.noBox&&e.points&&Pt(e.points)){let n=xe({open:!1,points:e.points||[]});return qn({...e,type:"box",selector:n})}if(e.type==="polygon"||e.type==="draw")return{polygon:{points:e.points||[],open:e.open||!1},requestType:e.type,boundingBox:xe({points:e.points||[],open:!1}),metadata:{},arguments:e.arguments||{},target:Tt({points:e.points||[],open:!1},e.bounds)};let t=e.selector;if(t){let n=[[t.x,t.y],[t.x+t.width,t.y],[t.x+t.width,t.y+t.height],[t.x,t.y+t.height]];return{polygon:{points:n,open:!1},requestType:e.type,boundingBox:t,metadata:{},target:Tt({points:n,open:!1},e.bounds),arguments:e.arguments||{}}}return{polygon:{points:[],open:!1},requestType:e.type,boundingBox:null,target:null,metadata:{},arguments:e.arguments||{}}}var Ei={shapeId:null,noShape:!0,transitioning:!1,actionIntentType:null,transitionIntentType:null,selectedPoints:[],hasClosestLine:!1,lastCreationTool:null,modifiers:{Alt:!1,Shift:!1,Meta:!1,proximity:0},bounds:null,showBoundingBox:!1,currentModifiers:{},validIntentKeys:{},pointerInsideShape:!1,closestPoint:null,transitionModifiers:null,selectedStamp:null,bezierLines:[],boxMode:!1,fixedAspectRatio:!1,cursor:"",enabledTools:["pointer","pen","box","lineBox","stamp","hand","line","pencil"],canDelete:!0,canDeselect:!0,isToolSwitchingLocked:!1,currentTool:"box",snapEnabled:!1,snapToPoints:!1,snapToLines:!1,snapToIntersections:!1,snapToGrid:!1,snapToParallel:!1};function $n({events:e,enabledTools:t,keyboardShortcutMapping:n,keyboardShortcutsEnabled:o=!1,debug:s}){let i=ki((a,l)=>{let u=null,c=Mi({emitter:e,keyboardShortcutsEnabled:o,keyboardShortcutMapping:n,enabledTools:t,customSetState:d=>{s&&console.log("partial state",d),a(p=>({polygonState:{...p.polygonState,...d}}))}},d=>{a(p=>p.tool.requestId?{polygon:{...d,id:p.tool.requestId}}:{polygon:{id:void 0,points:[],open:!0}}),e.emit("atlas.polygon-update",d)});return{mode:"explore",tool:{enabled:!1,requestId:null,canvasId:null},runtime:null,requestType:null,requests:{},history:c.history,polygon:null,validRequestIds:[],metadata:{},stableViewport:null,canvasRelativePositions:{},canvasViewports:{},polygons:c,polygonState:Ei,setMetadata:(d,p)=>{let y=p||l().tool.requestId;y&&a(f=>({metadata:{...f.metadata,[y]:{...f.metadata[y]||{},...d}}}))},setToolCanvasId:d=>{a(p=>({tool:{...p.tool,canvasId:d}}))},switchTool:{pointer(){a({mode:"sketch"}),r.tools.setTool("pointer")},hand(){a({mode:"explore"}),r.tools.setTool("hand")},draw(){a({mode:"sketch"}),r.tools.setTool("pencil")},pen(){a({mode:"sketch"}),r.tools.setTool("pen")},line(){a({mode:"sketch"}),r.tools.setTool("line")},lineBox(){a({mode:"sketch"}),r.tools.setTool("lineBox")},box(){a({mode:"sketch"}),r.tools.setTool("box")},triangle(){a({mode:"sketch"}),r.tools.setTool("stamp"),r.stamps.triangle()},hexagon(){a({mode:"sketch"}),r.tools.setTool("stamp"),r.stamps.hexagon()},circle(){a({mode:"sketch"}),r.tools.setTool("stamp"),r.stamps.circle()},remove(){let d=l();d.tool.requestId&&(c.setShape({points:[],open:!0}),d.cancelRequest(d.tool.requestId))}},reset:()=>{let d=l();d.tool.requestId&&d.cancelRequest(d.tool.requestId)},setPolygonState:d=>a({polygonState:typeof d=="function"?d(l().polygonState):d}),getRequestId:()=>{let d=Math.random().toString(36).slice(2);return a(p=>({validRequestIds:[...p.validRequestIds,d]})),{requestId:d,clear:()=>{l().tool.requestId,a(p=>({tool:p.tool.requestId===d?{enabled:!1,requestId:null,canvasId:null}:p.tool,validRequestIds:p.validRequestIds.filter(y=>y!==d)}))}}},cancelRequest:d=>{let p=d||l().tool.requestId;p&&(a(y=>({mode:"explore",tool:y.tool.requestId===p?{enabled:!1,requestId:null,canvasId:null}:y.tool,validRequestIds:y.validRequestIds.filter(f=>f!==p)})),e.emit("atlas.request-cancelled",{id:p}))},requestAnnotation:async(d,p)=>{let f={...l().requests,[p.requestId]:d},x=qn(d);s&&console.log("requestAnnotation",{response:x,request:d});try{let{points:v=[],open:m=!0}=x.polygon||{},{requestId:h,canvasId:S=null,toolId:b}=p,C=b,R=l(),P=R.validRequestIds.includes(h),L=x.requestType;return s&&console.log("setting points",{requestType:L,points:v,open:m}),!P||R.tool.enabled?null:(c.setShape({id:h,points:v,open:m}),L==="polygon"&&(C=C||"pen",c.tools.setTool("pen")),L==="draw"&&(C=C||"draw",c.tools.setTool("pencil")),L==="box"&&(C=C||"box",c.tools.setTool("box")),L==="target"?(C=C||"box",c.tools.setTool("box"),c.lockAspectRatio(),c.tools.lockToolSwitching(),c.tools.setCanDeselect(!1),c.tools.setCanDelete(!1)):(c.tools.unlockToolSwitching(),c.tools.setCanDeselect(!0),c.tools.setCanDelete(!0)),d.bounds&&c.setBounds(d.bounds),e.emit("atlas.annotation-request",{id:h}),a({polygon:{id:h,points:v,open:m},mode:"sketch",requestType:L,tool:{enabled:!0,requestId:h,canvasId:S},requests:f}),C?R.switchTool[C]?.():v.length===0&&R.switchTool.box(),(typeof d.selectByDefault>"u"&&v.length&&L==="box"||d.selectByDefault)&&R.switchTool.pointer(),new Promise(re=>{let T=w=>{w.id===h&&(a(I=>({mode:"explore",tool:{requestId:null,enabled:!1,canvasId:null},requests:Object.fromEntries(Object.entries(I.requests).filter(([E])=>E!==h))})),e.off("atlas.request-cancelled",T),e.off("atlas.annotation-completed",z),re(null))},z=w=>{w.id===h&&(a(I=>({mode:"explore",tool:{requestId:null,enabled:!1,canvasId:null},requests:Object.fromEntries(Object.entries(I.requests).filter(([E])=>E!==h))})),e.off("atlas.annotation-completed",z),e.off("atlas.request-cancelled",T),re(w))};e.on("atlas.request-cancelled",T),e.on("atlas.annotation-completed",z)}))}catch(v){return console.error(v),null}},completeRequest:d=>{let p=l().tool.requestId;if(typeof d=="string"&&d&&d!==p)return;let y=p?l().requests[p]?.arguments||{}:{},f=p?l().metadata[p]||{}:{},x=l().polygonState.bounds,v=l().polygon;v&&(e.emit("atlas.annotation-completed",{id:v.id,polygon:v,requestType:l().requestType,target:Tt(v,x),canvasId:l().tool.canvasId,boundingBox:xe(v),metadata:f,arguments:{...y}}),c.setShape(null))},setAtlasRuntime:d=>{u=d,e.emit("atlas.ready",{runtime:d}),r.setScale(1/u._lastGoodScale),u.world.addLayoutSubscriber((p,y)=>{(p==="event-activation"||p==="zoom-to"||p==="go-home")&&u?._lastGoodScale&&!Number.isNaN(u._lastGoodScale)&&r.setScale(1/u._lastGoodScale)}),a({runtime:u})},clearAtlasRuntime:()=>{u=null,a({stableViewport:null,runtime:null})},setCanvasRelativePosition:(d,p)=>{a(y=>({canvasRelativePositions:{...y.canvasRelativePositions,[d]:p}}))},clearCanvasRelativePosition:d=>{a(p=>{let y={...p.canvasRelativePositions};return delete y[d],{canvasRelativePositions:y}})},changeMode:d=>{a({mode:d})},nudgeLeft:d=>{if(!u)return;let p=u.getViewport(),y=d??p.width*.1;u.world.gotoRegion({x:p.x-y,y:p.y,width:p.width,height:p.height,nudge:!0})},nudgeRight:d=>{if(!u)return;let p=u.getViewport(),y=d??p.width*.1;u.world.gotoRegion({x:p.x+y,y:p.y,width:p.width,height:p.height,nudge:!0})},nudgeUp:d=>{if(!u)return;let p=u.getViewport(),y=d??p.height*.1;u.world.gotoRegion({x:p.x,y:p.y-y,width:p.width,height:p.height,nudge:!0})},nudgeDown:d=>{if(!u)return;let p=u.getViewport(),y=d??p.height*.1;u.world.gotoRegion({x:p.x,y:p.y+y,width:p.width,height:p.height,nudge:!0})},zoomIn:()=>{u?.world?.zoomIn()},zoomOut:()=>{u?.world?.zoomOut()},goHome:()=>{u?.world?.goHome()},goToRegion:d=>{u?.world?.gotoRegion(d)},getRuntime:()=>u}}),r=i.getState().polygons;return e.on("atlas.annotation-request",()=>{r.clock.start((a,l,u)=>{e.emit("atlas.polygon-render",{state:a,slowState:l,dt:u})},a=>{typeof a=="object"?i.setState({polygonState:a}):i.setState(l=>({polygonState:a(l.polygonState)}))})}),e.on("atlas.annotation-completed",()=>{r.clock.stop()}),e.on("atlas.request-cancelled",()=>{r.clock.stop()}),i}import{jsx as Fn}from"react/jsx-runtime";var be=Ni(null);function q(){return Wn(be)}var It={};function Un(e="atlas"){return It[e]?.getState()}function Oe({children:e,name:t="atlas",existing:n,atlasStoreConfig:o}){let s=Hn(),i=Wn(be),r=zi(()=>n||i||$n({events:s,...o||{}}),[s,n,i]),a=Oi(r,l=>l.mode);return Li(()=>{let l=t;return l&&(It[l]=r),()=>{l&&delete It[l]}},[r,t]),Fn(be.Provider,{value:r,children:Fn(Vi.Provider,{value:a||"explore",children:e})})}import{mergeStyles as Ye}from"@atlas-viewer/atlas";import{useMemo as ta}from"react";import{createContext as Bi,useContext as Hi,useMemo as Di}from"react";import{jsx as qi}from"react/jsx-runtime";function _n(){return{default:{backgroundColor:"rgba(0,0,0,0)",borderWidth:"2px",borderColor:"rgba(252,0,98, .5)"},highlighted:{backgroundColor:"rgba(75, 103, 225, 0.4)",borderWidth:"1px",borderColor:"rgba(75,103,225,0.99)"},hidden:{borderWidth:"0px",borderColor:"rgba(0,0,0,0)",backgroundColor:"rgba(0,0,0,0)",hidden:!0}}}var Mt=Bi(_n());Mt.displayName="AnnotationStyle";function jn(){return Hi(Mt)}function Td({theme:e,children:t}){let n=Di(()=>e||_n(),[e]);return qi(Mt.Provider,{value:n,children:t})}import{expandTarget as ji}from"@iiif/helpers/annotation-targets";import{useMemo as Ki}from"react";import{useEffect as $i,useMemo as Fi,useState as Wi}from"react";import{create as Ui}from"zustand";var _i=Ui()((e,t)=>{let n=new Map,o=()=>Math.random().toString(36).substring(2,15),s=i=>{let r=n.get(i);if(r)return r;let a=o();return n.set(i,a),a};return{stylesheets:{},loading:[],errors:[],async parseStylesheet(i){let{loadStylesheet:r,setStylesheet:a}=t();if(!i)return null;if(typeof i=="string")return i.startsWith("http")?{id:i,type:"CssStylesheet",value:await r(i)}:{id:a(i),type:"CssStylesheet",value:i};if(i.type==="CssStylesheet"){let l=i.id;if("value"in i){let u=Array.isArray(i.value)?i.value.join(`
2
- `):i.value;if(u)return{id:a(u,l),type:"CssStylesheet",value:u}}if("id"in i&&i.id){let u=await r(i.id);return{id:i.id,type:"CssStylesheet",value:u}}}return null},async loadStylesheet(i){if(t().loading.includes(i))return"";try{let a=await fetch(i);if(!a.ok)throw new Error(`Failed to load stylesheet from ${i}`);let l=await a.text();return e(u=>({stylesheets:{...u.stylesheets,[i]:l}})),l}catch(a){return e(l=>({errors:[...l.errors,{url:i,error:a}]})),""}},setStylesheet(i,r){let a=r||s(i);return e(l=>({stylesheets:{...l.stylesheets,[a]:i}})),a}}});function Kn(e){let[t,n]=Wi(""),{loading:o,errors:s,stylesheets:i,parseStylesheet:r}=_i();return $i(()=>{e&&r(e).then(l=>{l?.id&&n(l.id)})},[e,r]),[Fi(()=>{let l={};return t&&i[t]&&(l[t]=i[t]),l},[t,i]),{id:t,stylesheets:i,loading:o,errors:s}]}function je(e={},t=[]){let{id:n,selector:o}=e,s=_(),i=M(),r=n||s.annotation,a=k(g=>r?g.iiif.entities.Annotation[r]:void 0,[r]),[l]=Kn(a?.stylesheet),u=k(g=>a&&a.body?a.body.map(c=>c?c.type==="SpecificResource"?{...c,source:i.get(c)}:c?g.iiif.entities[c.type][c.id]:null:null).filter(Boolean):[],[a]);return Ki(()=>{if(!a)return;let g={...a,body:u,target:ji(a.target,{typeMap:i.getState().iiif.mapping,loadedStylesheets:l})};return o?o(g):g},[a,o,u,l,...t])}import{useMemo as Yi}from"react";function A(e={},t=[]){let{id:n,selector:o}=e,s=_(),i=n||s.canvas,r=k(a=>i?a.iiif.entities.Canvas[i]:void 0,[i]);return Yi(()=>{if(r)return o?o(r):r},[r,o,...t])}import{useMemo as Yn}from"react";import{createEventsHelper as Gi}from"@iiif/helpers/events";function Ke(e,t){let n=M(),o=Yn(()=>Gi(n),[n]),s=k(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return Yn(()=>e?o.getListenersAsProps(e,t):{},[s,e,n,t])}import{useMemo as Qi}from"react";import{createStylesHelper as Xi}from"@iiif/helpers/styles";function Ce(e,t){let n=M(),o=Qi(()=>Xi(n),[n]);return k(()=>{if(!e)return null;let s=o.getAppliedStyles(e.id);return s?t?s[t]:s:void 0},[e,t])}import{useCallback as ea}from"react";import{HTMLPortal as Zi,useResizeWorldItem as Ji}from"@atlas-viewer/atlas";import{useMemo as te}from"react";import{Fragment as kt,jsx as K,jsxs as Et}from"react/jsx-runtime";function Gn({handleSize:e,resizable:t,onSave:n,children:o,maintainAspectRatio:s,disableCardinalControls:i,aspectRatio:r,...a}){let l=typeof e>"u"?s?12:8:e,{portalRef:u,mode:g,mouseEvent:c,isEditing:d}=Ji({x:a.x||0,y:a.y||0,width:a.width,height:a.height,aspectRatio:r,maintainAspectRatio:s},n),p=te(()=>c("translate"),[c]),y=te(()=>c("east"),[c]),f=te(()=>c("west"),[c]),x=te(()=>c("south"),[c]),v=te(()=>c("north"),[c]),m=te(()=>c("south-east"),[c]),h=te(()=>c("south-west"),[c]),S=te(()=>c("north-east"),[c]),b=te(()=>c("north-west"),[c]),C=g==="sketch",R={zIndex:999,boxShadow:"0px 2px 3px 0 rgba(0,0,0,0.2)",outline:"2px solid rgba(155,155,155,.7)",borderRadius:s||i?"50%":2,position:"absolute",background:"#fff",pointerEvents:d?"none":C?"initial":"none"};return K(kt,{children:Et("world-object",{...a,children:[o,C&&t?K(Zi,{ref:u,target:{x:0,y:0,height:a.height,width:a.width},relative:!0,interactive:!1,children:C&&t?Et(kt,{children:[K("div",{onMouseDown:p,onTouchStart:p,style:{display:"block",width:"100%",height:"100%",cursor:"move",border:"1px solid rgba(255,255,255, .7)",outline:"2px solid rgba(155,155,155, .7)",boxSizing:"border-box",pointerEvents:d?"none":C?"initial":"none"}}),s?null:Et(kt,{children:[K("div",{title:"east",onTouchStart:y,onMouseDown:y,style:{...R,cursor:"e-resize",height:l*2,width:l,right:0,top:"50%",opacity:i?0:1,transform:`translate(${l/2}px, -${l}px)`}}),K("div",{title:"west",onMouseDown:f,style:{...R,cursor:"w-resize",position:"absolute",height:l*2,width:l,left:0,top:"50%",opacity:i?0:1,transform:`translate(-${l/2}px, -${l}px)`}}),K("div",{title:"north",onMouseDown:v,style:{...R,cursor:"n-resize",position:"absolute",height:l,width:l*2,left:"50%",top:0,opacity:i?0:1,transform:`translate(-${l}px, -${l/2}px)`}}),K("div",{title:"south",onMouseDown:x,style:{...R,cursor:"s-resize",position:"absolute",height:l,width:l*2,left:"50%",bottom:0,opacity:i?0:1,transform:`translate(-${l}px, ${l/2}px)`}})]}),K("div",{title:"north-east",onMouseDown:S,style:{...R,cursor:"ne-resize",position:"absolute",height:l,width:l,right:0,top:0,transform:`translate(${l/2}px, -${l/2}px)`}}),K("div",{title:"south-east",onMouseDown:m,style:{...R,cursor:"se-resize",position:"absolute",height:l,width:l,bottom:0,right:0,transform:`translate(${l/2}px, ${l/2}px)`}}),K("div",{title:"south-west",onMouseDown:h,style:{...R,cursor:"sw-resize",position:"absolute",height:l,width:l,bottom:0,left:0,transform:`translate(-${l/2}px, ${l/2}px)`}}),K("div",{title:"north-west",onMouseDown:b,style:{...R,cursor:"nw-resize",position:"absolute",height:l,width:l,top:0,left:0,transform:`translate(-${l/2}px, -${l/2}px)`}})]}):null}):null]})})}import{jsx as Qn}from"react/jsx-runtime";function Xn({id:e,interactive:t,region:n,onClick:o,onHover:s,onSave:i,aspectRatio:r,maintainAspectRatio:a,disableCardinalControls:l,isEditing:u,style:g={backgroundColor:"rgba(0,0,0,.5)"}}){let c=ea(d=>{u&&i?.({id:n.id,x:n.x,y:n.y,height:n.height,width:n.width,...d})},[i,u,n.id,n.x,n.y,n.height,n.width]);return Qn(Gn,{id:e,x:n.x,y:n.y,width:n.width,aspectRatio:r,height:n.height,resizable:u,onSave:c,maintainAspectRatio:a,disableCardinalControls:l,children:Qn("box",{interactive:t,onClick:d=>{d.preventDefault(),d.stopPropagation(),o?.(n)},relativeStyle:!0,onMouseEnter:()=>{s?.(n)},target:{x:0,y:0,width:n.width,height:n.height},style:g})})}import{jsx as na}from"react/jsx-runtime";var Re=({id:e,style:t,className:n,interactive:o,targetId:s,ignoreTargetId:i})=>{let r=je({id:e}),a=Ce(r,"atlas"),l=Ce(r,"html"),u=Ke(r,["atlas"]),g=A(),c=jn(),d=ta(()=>Ye(Ye(Ye(Ye(t,a),r?.motivation?.includes("highlighting")?c.highlighted:c.default),r?.target?.selector?.boxStyle||{})),[t,a,c,r?.motivation,r?.target]),p=s||g?.id;return g&&r&&r.target&&r.target.selector&&(r.target.selector.type==="BoxSelector"||r.target.selector.type==="SvgSelector")&&r.target.source&&(i?!0:r.target.source.id===p||r.target.source===p)?na(Xn,{id:r.id,isEditing:!0,region:r.target.selector.spatial,style:d,className:l?.className||n,interactive:!!(l?.href||o),href:l?.href||null,title:l?.title||null,hrefTarget:l?.target||null,onClick:()=>{},...u}):null};import{Fragment as ra}from"react";import{useMemo as oa}from"react";function Zn(e={},t=[]){let{id:n,selector:o}=e,s=_(),i=n||s.annotationPage,r=k(a=>i?a.iiif.entities.AnnotationPage[i]:void 0,[i]);return oa(()=>{if(r)return o?o(r):r},[r,...t])}import{jsx as Jn}from"react/jsx-runtime";var ue=({className:e,page:t,targetId:n,ignoreTargetId:o})=>{let s=Zn({id:t.id})||t,i=Ce(s,"atlas"),r=Ce(s,"html");return k(a=>s.id?a.iiif.entities.AnnotationPage[s.id]:null,[]),Jn(ra,{children:s.items?.map(a=>Jn(Re,{id:a.id,style:i,className:r?.className||e,targetId:n,ignoreTargetId:o},a.id))})};import{createContext as Nt,useContext as Lt}from"react";import{jsx as Vt}from"react/jsx-runtime";var eo=Nt(null),to=Nt(null),no=Nt(null);function Em(){let e=Lt(eo);if(!e)throw new Error("Ctx not found");return e}function Vm(){let e=Lt(to);if(!e)throw new Error("Ctx not found");return e}function Nm(){let e=Lt(no);if(!e)throw new Error("Ctx not found");return e}function Ge({actions:e,state:t,children:n,currentTime:o,progress:s,element:i}){return Vt(no.Provider,{value:{currentTime:o,progress:s,element:i},children:Vt(to.Provider,{value:e,children:Vt(eo.Provider,{value:t,children:n})})})}import{useMemo as ia}from"react";import{expandTarget as aa}from"@iiif/helpers";function Qe(){let e=B(),t=A();return ia(()=>{if(!e||!t||!e.start)return null;let n=aa(e.start);return!n||n.source.id!==t.id||!n||!n.selector||n.selector.type!=="TemporalSelector"?null:n.selector.temporal},[e,t])}import{useCallback as Q,useEffect as zt,useReducer as sa,useRef as Xe}from"react";function oo(e){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:e}}function la(e,t){switch(t.type){case"RESET":return t.state;case"FINISHED":return{...e,isFinished:!0,isPlaying:!1,playRequested:!1};case"PLAY_PAUSE":return{...e,isFinished:!1,isPlaying:!e.isPlaying};case"PLAY_REQUESTED":return{...e,isFinished:!1,playRequested:!0};case"PAUSE":return{...e,isPlaying:!1};case"PLAY":return{...e,isFinished:!1,playRequested:!1,isPlaying:!0};case"MUTE":return{...e,isMuted:!0};case"SET_VOLUME":return{...e,volume:t.volume,isMuted:t.volume===0};case"TOGGLE_MUTE":return{...e,isMuted:!e.isMuted};case"UNMUTE":return{...e,isMuted:!1}}return e}function Ot(e){let t=Math.round(e);return`${Math.floor(t/60)}:${`${t%60}`.padStart(2,"0")}`}function Ae(e){let[t,n]=sa(la,oo(e.duration));zt(()=>{n({type:"RESET",state:oo(e.duration)})},[e.duration]);let o=Xe(null),s=Xe(null),i=Xe(null),r=Xe(!1),a=Q(()=>{s.current&&o.current&&(s.current.innerHTML=Ot(o.current.currentTime),i.current&&(i.current.style.width=`${o.current.currentTime/e.duration*100}%`),r.current!==o.current.muted&&(r.current=o.current.muted,n(o.current.muted?{type:"MUTE"}:{type:"UNMUTE"})))},[e.duration]),l=Q(()=>{o.current&&(n({type:"PLAY_REQUESTED"}),o.current.play().then(()=>{n({type:"PLAY"})}),a())},[a]),u=Q(()=>{o.current&&(o.current.duration>0&&o.current.paused?l():g())},[a]),g=Q(()=>{o.current&&(o.current.pause(),n({type:"PAUSE"}),a())},[a]),c=Q(()=>{o.current&&(o.current.muted=!o.current.muted,n(o.current.muted?{type:"MUTE"}:{type:"UNMUTE"}))},[]),d=Q(()=>{o.current&&(o.current.muted=!0,n({type:"MUTE"}))},[]),p=Q(()=>{o.current&&(o.current.muted=!1,n({type:"UNMUTE"}))},[]),y=Q(v=>{o.current&&(o.current.muted=!1,o.current.volume=v/100,n({type:"SET_VOLUME",volume:v}))},[]),f=Q(v=>{o.current&&(o.current.currentTime=Math.max(0,Math.min(v*e.duration,e.duration)),a())},[]),x=Q(v=>{if(o.current){let m=typeof v=="function"?v(o.current.currentTime):v;o.current.currentTime=Math.max(0,Math.min(m,e.duration)),a()}},[]);return zt(()=>{let v=setInterval(()=>{a()},350);return()=>clearInterval(v)},[a,e.duration]),zt(()=>{let v=()=>{n({type:"FINISHED"})},m=o.current;return m?.addEventListener("ended",v),()=>m?.removeEventListener("ended",v)},[]),[{element:o,currentTime:s,progress:i},t,{play:l,pause:g,playPause:u,mute:d,unmute:p,toggleMute:c,setVolume:y,setDurationPercent:f,setTime:x}]}import{createContext as ro,useContext as ua,useEffect as ca}from"react";var Bt=ro(()=>{}),Ht=ro(()=>{});function D(e,t,n,o,s=[]){let i=ua(e==="portal"?Ht:Bt);ca(()=>(e!=="none"&&i(t,n,o),()=>{i(t,null)}),[t,e,i,...s])}import{jsx as da,jsxs as ma}from"react/jsx-runtime";function Dt({media:e,startTime:t,children:n}){let[{element:o,currentTime:s,progress:i},r,a]=Ae({duration:e.duration}),l=t?`${e.url}#t=${t}`:e.url;return ma(Ge,{state:r,actions:a,currentTime:s,progress:i,element:o,children:[da("audio",{ref:o,src:l}),n]},e.url)}function Ze({media:e,mediaControlsDeps:t,audioCopmonent:n=Dt,children:o}){let s=Qe();return D("portal","audio",n,{media:e,startTime:s?s.startTime:null,children:o},[e,s,...t||[]]),null}import{createContext as pa,useContext as fa}from"react";var ce=pa(null);ce.displayName="Strategy";function V(){let e=fa(ce);if(!e)throw new Error("useStrategy must be used within a StrategyProvider");return e}import{Fragment as ga,jsx as qt,jsxs as ha}from"react/jsx-runtime";function $t({model:e}){return ha(ga,{children:[qt("style",{children:`
1
+ import{c as ln,l as un}from"./chunk-P7XHGETS.js";import{forwardRef as zr,useImperativeHandle as Wl,useMemo as Ul}from"react";import Or,{useContext as Br,useMemo as Hr}from"react";import{jsx as qr}from"react/jsx-runtime";var Dr={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},Fe=Or.createContext(Dr),_=()=>Br(Fe);function ie({value:e,children:t}){let n=_(),o=Hr(()=>({...n,...e}),[e,n]);return qr(Fe.Provider,{value:o,children:t})}import{jsx as Fr}from"react/jsx-runtime";function ee({canvas:e,children:t}){return Fr(ie,{value:{canvas:e},children:t})}import $r,{useState as Wr}from"react";import{Vault as cn,globalVault as Ur}from"@iiif/helpers/vault";import{jsx as dn}from"react/jsx-runtime";var le=$r.createContext({vault:null,setVaultInstance:e=>{}});function ge({vault:e,vaultOptions:t,useGlobal:n,resources:o,children:s}){let[i,r]=Wr(()=>e||(n?Ur(t):t?new cn(t):new cn));return dn(le.Provider,{value:{vault:i,setVaultInstance:r},children:dn(ie,{value:o||{},children:s})})}import{useContext as Yr}from"react";import Gr from"react";import{useContext as _r}from"react";var M=()=>{let{vault:e}=_r(le);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};import{useEffect as jr,useState as Kr}from"react";function k(e,t=[]){let n=M(),[o,s]=Kr(()=>e(n.getState(),n));return jr(()=>n.subscribe(i=>e(i,n),i=>{s(i)},!1),t),o}var he=Gr.createContext([]);function $e(){let e=Yr(he);return k(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}import{globalVault as Qr}from"@iiif/helpers/vault";import{useContext as Xr}from"react";function ye(e){let t=Xr(le);return e||(t&&t.vault?t.vault:Qr())}import{useMemo as Zr}from"react";function B(e={},t=[]){let{id:n,selector:o}=e,s=_(),i=M(),r=n||s.manifest,a=k(l=>r?l.iiif.entities.Manifest[r]:void 0,[r]);return Zr(()=>{if(a)return o?o(a):a},[a,o,...t])}import{useContext as Ci}from"react";import{createContext as Ri,useMemo as Ai}from"react";import{useEffect as Jr,useMemo as ei,useState as yt}from"react";function mn(e,{noCache:t=!1}={}){let n=typeof e=="string"?e:e.id,o=ye(),[s,i]=yt(n),[r,a]=yt(void 0),l=ei(()=>o.get(n,{skipSelfReturn:!0})||void 0,[n,o]),[u,p]=yt(l);return Jr(()=>{(async()=>{try{let c=l&&!t?l:await o.load(n),d=c?c.id||c["@id"]:null;c&&s!==d&&i(d),p(c)}catch(c){a(c)}})()},[n,t]),{isLoaded:!!u,id:s,requestId:n,error:r,resource:u,cached:!!(u&&u===l)}}function pn(e,t){let{id:n,isLoaded:o,error:s,resource:i,requestId:r,cached:a}=mn(e,t);return{id:n,isLoaded:o,error:s,manifest:i,requestId:r,cached:a}}import{jsx as ti}from"react/jsx-runtime";function fn({manifest:e,children:t}){return ti(ie,{value:{manifest:e},children:t})}import{jsx as ni}from"react/jsx-runtime";function gn({range:e,children:t}){return ni(ie,{value:{range:e},children:t})}function oi(e,t){for(let n of t.items){if(n.type==="Canvas")return n;if(n.type==="SpecificResource")return n.source;if(n.type==="Range"){let o=oi(e,e.get(n));if(o)return o}}return null}function vt(e,t){let n=[];for(let o of t.items)if(o.type==="SpecificResource"&&o.source?.type==="Canvas"&&(o.source.id.indexOf("#")!==-1?n.push({id:o.source.id.split("#")[0],type:"Canvas"}):n.push(o.source)),o.type==="Range"&&n.push(...vt(e,e.get(o))),o.type==="SpecificResource"){let s=typeof o.source=="string"?o.source:o.source.id;n.push({id:s,type:"Canvas"})}return n}function Wu(e,t,n){for(let o of t.structures){let s=hn(e,e.get(o),n);if(s)return s}return null}function hn(e,t,n){for(let o of t.items){let s=o?.source?.id?.split("#")[0];if(o.type==="SpecificResource"&&o.source===n||o.type==="SpecificResource"&&o.source?.type==="Canvas"&&n===s)return t;if(o.type==="Range"){let i=hn(e,e.get(o),n);if(i)return i}}return null}function ju(e,t,n,o=!1){let s=t.behavior,i=n?e.get(n):null;if(!i)return[];let r=i.behavior,a=o?!1:s.includes("paged"),l=a?!1:s.includes("continuous"),u=a||l?!1:s.includes("individuals"),p=r.includes("facing-pages"),c=r.includes("non-paged");if(p||c||u||o)return[{id:i.id,type:"Canvas"}];let[d,f]=St(e,t);if(l)return d;let y=d.findIndex(g=>g.id===n);if(y===-1)return[];for(let g of f)if(g.includes(y))return g.map(x=>d[x]);return[{id:i.id,type:"Canvas"}]}function St(e,t,{disablePaging:n,skipNonPaged:o}={}){let s=t.behavior,i=s.includes("paged"),r=i?!1:s.includes("continuous"),a=i||r?!1:s.includes("individuals"),l=t.type==="Manifest"?t.items:vt(e,t);if(r)return[l,[l.map((y,g)=>g)]];if(a||!i||n)return[l,l.map((y,g)=>[g])];let u=[],p=[],c=()=>{p.length&&(u.push([...p]),p=[])},d=0,f=!1;for(let y=0;y<l.length;y++){let g=e.get(l[y]);if(g.behavior.includes("non-paged")){y===d&&d++,o||(c(),u.push([y]),c());continue}if(y===d||g.behavior.includes("facing-pages")){p.length&&(f=!0),c(),u.push([y]),c();continue}if(p.push(y),f){c(),f=!1;continue}p.length>1&&c()}return p.length&&c(),[l,u]}import{useCallback as We,useMemo as ii,useRef as ai,useState as si}from"react";import{useMemo as ri}from"react";function yn(e={},t=[]){let{id:n,selector:o}=e,s=_(),i=n||s.range,r=k(a=>i?a.iiif.entities.Range[i]:void 0,[i]);return ri(()=>{if(r)return o?o(r):r},[r,o,...t])}function vn({startCanvas:e,disablePaging:t}){let n=M(),o=B(),s=yn(),[i,r]=si(void 0),a=s||o;if(!a)throw new Error("Nothing selected");let[l,u]=ii(()=>St(n,a,{disablePaging:t}),[n,a,t]),p=ai(u);if(p.current!==u){let x=p.current[i][0],v=u.findIndex(m=>m.includes(x));p.current=u,r(v)}let c=We(g=>{let x=u.findIndex(v=>v.includes(g));r(x===-1?0:x)},[l,u]),d=We(g=>{let x=l.findIndex(v=>v.id===g);x!==-1?c(x):r(0)},[l,u]),f=We(()=>{r(g=>g>=u.length-1?g:g+1)},[u]),y=We(()=>{r(g=>g<=0?0:g-1)},[u]);return typeof i>"u"&&(e?d(e):r(0)),{visibleItems:u[i]?.map(g=>l[g].id)||[],cursor:i,items:l,sequence:u,hasPrevious:i>0,hasNext:i<u.length-1,setSequenceIndex:r,setCanvasIndex:c,setCanvasId:d,next:f,previous:y}}import{createContext as Ct,useContext as Mn,useEffect as ui,useMemo as ci}from"react";import{useStore as Ve}from"zustand";import{createStore as xn}from"zustand/vanilla";function ic(e){let t=e.service||e.services||[];for(let n of t)if(n.type==="AuthProbeService2")return!0;return!1}function j(e,t,n){let o=t.findIndex(r=>r.service.id===e);if(o===-1)return t;let s=[...t],i=n(s[o]);return i===s[o]?t:(s[o]=i,s)}var bn=()=>xn((e,t)=>({currentAuth:-1,authItems:[],login:()=>{let n=t().authItems[t().currentAuth];if(!n||n.isPending||n.isLoggedIn)return;if(n.type!=="active")throw new Error("Cannot login to non-active service");let o=n.service.service.find(s=>s.type==="AuthAccessTokenService2");if(!o)throw new Error("Token service not found");e(()=>({authItems:j(n.id,t().authItems,s=>({...s,isPending:!0}))})),Sn(n.service).then(()=>{xt(o).then(s=>{let i=s.expiresIn,r=Date.now()+i*1e3;e(()=>({authItems:j(n.id,t().authItems,a=>({...a,isLoggedIn:!0,isPending:!1,session:{token:s.accessToken,expires:r}}))}))}).catch(s=>{e(()=>({authItems:j(n.id,t().authItems,i=>({...i,isLoggedIn:!1,isPending:!1,error:s.message}))}))})})},logout:()=>{let n=t().authItems[t().currentAuth];if(!n||n.isPending||!n.isLoggedIn)return;if(n.type!=="active")throw new Error("Cannot logout of non-active service");let o=n.service.service.find(r=>r.type==="AuthLogoutService2");if(!o)return;let s=`${o.id}?origin=${An()}`,i=window.open(s);e(()=>({authItems:j(n.id,t().authItems,r=>({...r,isLoggedIn:!1,session:null,isPending:!1}))}))},nextAuth:()=>{let n=t().authItems.length,o=t().currentAuth+1;o>=n||e(()=>({currentAuth:o}))},previousAuth:()=>{let n=t().currentAuth-1;n<0||e(()=>({currentAuth:n}))},setAuth:n=>{n!==-1&&(n<0||n>=t().authItems.length)||e(()=>({currentAuth:n}))},addService:(n,o)=>{if(!n.service)return;let s=n.service.find(a=>a.type==="AuthAccessTokenService2"),i=n;if(t().authItems.find(a=>a.service.id===n.id)){e(()=>({authItems:j(n.id,t().authItems,a=>({...a,instances:a.instances+1}))}));return}if(e(()=>({currentAuth:i.profile==="active"?0:t().currentAuth,authItems:[{id:n.id,type:n.profile,service:n,probeId:o,canAuthenticate:!0,instances:1,isPending:!1,isLoggedIn:!1,session:null},...t().authItems]})),n.profile==="external"){if(!s)throw new Error("Token service not found");xt(s).then(a=>{e(()=>({authItems:j(n.id,t().authItems,l=>({...l,isLoggedIn:!0,isPending:!1,session:{token:a.accessToken,expires:a.expiresIn}}))}))}).catch(a=>{e(()=>({authItems:j(n.id,t().authItems,l=>({...l,isLoggedIn:!1,isPending:!1,canAuthenticate:!1,error:a.message}))}))})}if(n.profile==="kiosk"){if(!s)throw new Error("Token service not found");e(()=>({authItems:j(n.id,t().authItems,a=>({...a,isPending:!0}))})),Sn(i).then(()=>{xt(s).then(a=>{e(()=>({authItems:j(n.id,t().authItems,l=>({...l,isLoggedIn:!0,isPending:!1,session:{token:a.accessToken,expires:a.expiresIn}}))}))}).catch(a=>{e(()=>({authItems:j(n.id,t().authItems,l=>({...l,isLoggedIn:!1,isPending:!1,error:a.message}))}))})})}n.profile},removeService:(n,o)=>{let s=t().currentAuth===t().authItems.findIndex(r=>r.service.id===n.id),i=t().currentAuth;if(s){let r=t().authItems.find(l=>l.service.id===n.id);r&&r.instances>1||(i=t().authItems.findIndex(u=>u.service.id!==n.id&&u.instances>0))}e(()=>({authItems:j(n.id,t().authItems,r=>({...r,instances:r.instances-1})),currentAuth:i}))}})),Cn=(e,t)=>xn((n,o)=>({service:e,status:e?"unknown":"success",shouldRedirect:!1,redirectResource:null,shouldSubstitute:!1,substituteResource:null,error:null,errorHeading:null,errorNote:null,shouldDisplayResource:!1,token:t||null,async probe(){if(!o().service)return;let s=o().service?.id;if(!s){n({status:"error",error:"Service ID not found",errorHeading:{en:["Service ID not found"]}});return}n({status:"probing"});let i=o().token;try{let r=await fetch(s,{headers:i?{Authorization:`Bearer ${o().token}`,Accept:"application/json"}:{Accept:"application/json"}}).then(a=>a.json());if(r.status===200)n({status:"success",shouldDisplayResource:!0,error:null,errorHeading:null,errorNote:null,shouldSubstitute:!1,shouldRedirect:!1});else if(r.status<400&&r.status>=300){if(!r.location)throw new Error("Redirect location not found");n({status:"error",shouldDisplayResource:!1,shouldRedirect:!0,redirectResource:r.location||null})}else if(r.status===401)n({status:"error",shouldDisplayResource:!1,shouldRedirect:!1,shouldSubstitute:!!r.substitute,substituteResource:r.substitute||null,error:"Unauthorized",errorHeading:r.heading||{en:["Unauthorized"]},errorNote:r.note||null});else throw new Error("Unknown error")}catch(r){n({status:"error",error:r.message,errorHeading:{en:["Unknown error"]}})}},setToken(s){n({token:s})}}));function Rn(e){let t=e.service||e.services||[],n={hasAuth:!1,services:{}};for(let o of t)if(o.type==="AuthProbeService2"){n.services.probe=o,n.hasAuth=!0;let s=o.service.filter(i=>i.type==="AuthAccessService2");s[0]&&(n.services.access=s[0])}return n}async function xt(e,{strict:t=!0}={}){return new Promise((n,o)=>{let s=Math.random().toString(36).substring(7),i=`${e.id}?messageId=${s}&origin=${window.location.origin}`,r=u=>{let p=u.data;if(p.messageId===s){if(t&&p.type!=="AuthAccessToken2"){a(),o("Invalid response, expected type=AuthAccessToken2");return}if(!p.accessToken){a(),o("Invalid response, expected accessToken");return}a(),n(p)}},a=()=>window.removeEventListener("message",r),l=document.createElement("iframe");l.src=i,l.style.display="none",document.body.appendChild(l),window.addEventListener("message",r)})}function An(e){let t=window.location;if(e){let n=document.createElement("a");return n.href=e,n.protocol+"//"+n.hostname+(n.port?":"+n.port:"")}return t.protocol+"//"+t.hostname+(t.port?":"+t.port:"")}async function Sn(e){let t=`${e.id}?origin=${An()}`,n=window.open(t);if(!n)throw new Error("Failed to open window");return new Promise((o,s)=>{let i=setInterval(()=>{n.closed&&(clearInterval(i),o())},500)})}import{useEffect as Pn,useMemo as wn}from"react";import{useStore as li}from"zustand";function Tn(e){let t=wn(()=>Rn(e),[e]),n=In(t.services.access?.id),o=wn(()=>Cn(t.services.probe,n),[t.services.probe]),s=li(o);return Pn(()=>{s.status==="unknown"&&!n&&s.probe()},[t.services.probe,s.status]),Pn(()=>{n&&(s.setToken(n),s.probe())},[n]),[e,s,t.hasAuth]}import{jsx as Ue}from"react/jsx-runtime";var ve=Ct(null),di=Ct(null);di.displayName="CurrentAuth";var mi=Ct(null);mi.displayName="AuthActions";function kn({children:e}){let t=ci(()=>bn(),[]);return Ue(ve.Provider,{value:t,children:e})}function En(){return!!Mn(ve)}function Ne(){let e=Mn(ve);if(!e)throw new Error("useAuthActions must be used within a AuthProvider");return e}function pi(){let e=Ne();return Ve(e,n=>({login:n.login,logout:n.logout,nextAuth:n.nextAuth,previousAuth:n.previousAuth,setAuth:n.setAuth,addService:n.addService,removeService:n.removeService}))}function Rc(){let e=Ne();return Ve(e,t=>t)}function fi(e){let t=Ne();return Ve(t,o=>o.authItems.find(s=>s.service.id===e))}function In(e){let t=Ne();return Ve(t,o=>o.authItems.find(s=>s.id===e)?.session?.token)}function Ac(e){let t=Ne();return Ve(t,o=>{let s=o.authItems.find(i=>i.service.id===e);return!s||!s.isLoggedIn||!s.session?null:s.session?.token||null})}function gi(e){let t=pi(),n=fi(e.service.id);return ui(()=>(t?.addService(e.service,e.probeId),()=>{t?.removeService(e.service,e.probeId)}),[e.service]),n?(n.error||!n.isLoggedIn,e.children):null}function bt(){return null}function Vn(e){let[t,n,o]=Tn(e.resource),s=e.fallbackComponent||bt,i=e.loadingComponent||bt,r=e.errorComponent||bt,a=n.service,l=null;if(!o||!a)return e.children(t);let u=a.service.filter(p=>p.type==="AuthAccessService2");n.status==="error"&&(l=Ue(r,{resource:e.resource,error:n.error||"",heading:n.errorHeading,note:n.errorNote,extra:e.extra})),(n.status==="unknown"||n.status==="probing")&&(l=Ue(i,{})),n.status==="success"&&(l=e.children(t));for(let p of u)l=Ue(gi,{service:p,probeId:a.id,children:l},p.id);return l}import{createContext as Si,useContext as Nc,useMemo as xi}from"react";import{createStore as hi}from"zustand/vanilla";var yi=e=>e.id||e["@id"];function vi(e){return(Array.isArray(e.service)?e.service:[e.service]).find(n=>n.profile==="http://iiif.io/api/search/0/autocomplete"||n.profile==="http://iiif.io/api/search/1/autocomplete"||n.profile==="AutoCompleteService1")}var Nn=e=>{let t;typeof e=="string"?t={"@context":"http://iiif.io/api/search/1/context.json",profile:"http://iiif.io/api/search/1/search","@id":e,id:e,service:[]}:t=e;let n=t?yi(t):void 0,o=null;return hi((s,i)=>({service:t,resources:[],lastQuery:{},loading:!1,error:!1,highlight:null,hasSearch:!!t,hasAutocomplete:t?!!vi(t):!1,errorMessage:"",search(r,a={}){if(!n)throw new Error("No search service found.");o&&!o.signal.aborted&&o.abort(),o=new AbortController;let l=new URLSearchParams;r.q&&l.set("q",r.q),r.motivation&&l.set("motivation",r.motivation),r.date&&l.set("date",r.date),r.user&&l.set("user",r.user),s({loading:!0}),fetch(`${n}?${l.toString()}`,{signal:o.signal,headers:{"Content-Type":"application/json",Accept:"application/json",...a.headers||{}}}).then(async u=>{if(!o?.signal.aborted)if(u.ok){let p=await u.json();s({resources:p.resources,error:!1,errorMessage:""})}else s({resources:[],error:!0,errorMessage:u.statusText})})},clearSearch(){s({resources:[],error:!1,errorMessage:""})},highlightResult(r){let a=i().resources.find(l=>l["@id"]===r);s({highlight:a})},nextResult(){let r=i().resources,a=i().highlight;if(!a){s({highlight:r[0]||null});return}let l=r.findIndex(u=>u["@id"]===a["@id"]);if(l===-1){s({highlight:r[0]||null});return}s({highlight:r[l+1]||r[0]||null})},previousResult(){let r=i().resources,a=i().highlight;if(!a){s({highlight:r[r.length-1]||null});return}let l=r.findIndex(u=>u["@id"]===a["@id"]);if(l===-1){s({highlight:r[r.length-1]||null});return}if(l===0){s({highlight:r[r.length-1]||null});return}s({highlight:r[l-1]||r[r.length-1]||null})}}))};import{useStore as Hc}from"zustand";function Ln(){let e=B();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}import{jsx as Rt}from"react/jsx-runtime";var Se=Si(null);Se.displayName="Search";function zn(e){let t=Ln();return e.store?Rt(Se.Provider,{value:e.store,children:e.children}):Rt(bi,{service:t,children:e.children})}function bi({service:e,children:t}){let n=xi(()=>Nn(e),[e]);return Rt(Se.Provider,{value:n,children:t})}import{jsx as $}from"react/jsx-runtime";var Le=()=>{},ze=Ri({setCurrentCanvasId:Le,setCurrentCanvasIndex:Le,nextCanvas:Le,previousCanvas:Le,items:[],sequence:[],setSequenceIndex:Le,currentSequenceIndex:0,hasNext:!1,hasPrevious:!1});function Pi(e){let t=B(),{cursor:n,visibleItems:o,next:s,sequence:i,items:r,setCanvasIndex:a,setCanvasId:l,previous:u,setSequenceIndex:p,hasNext:c,hasPrevious:d}=vn({startCanvas:e.startCanvas,disablePaging:e.pagingEnabled===!1}),f=Ai(()=>({sequence:i,items:r,setCurrentCanvasId:l,nextCanvas:s,previousCanvas:u,totalCanvases:r.length,setCurrentCanvasIndex:a,setSequenceIndex:p,currentSequenceIndex:n,hasNext:c,hasPrevious:d}),[i,r,l,s,u,r,a,p,n]);return t?o.length===0?null:$(ze.Provider,{value:f,children:$(he.Provider,{value:o,children:$(ee,{canvas:o[0],children:e.children})})}):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),$("div",{children:"Sorry, something went wrong."}))}function On(e){let t=ye(e.vault),n=pn(e.manifest);if(!n)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),$("div",{children:"Sorry, something went wrong."});if(n.error)return $("div",{children:n.error.toString()});if(!n.isLoaded)return $("div",{children:"Loading..."});let o=$(Pi,{...e,children:e.children});return $(ge,{vault:t,children:$(fn,{manifest:n.id,children:$(kn,{children:$(zn,{children:e.rangeId?$(gn,{range:e.rangeId,children:o}):o})})})})}function _e(){return Ci(ze)}import{ModeContext as zi}from"@atlas-viewer/atlas";import{createContext as Oi,useContext as Wn,useEffect as Bi,useMemo as Hi}from"react";import{useStore as Di}from"zustand";import wi from"mitt";import{createContext as Ti,useContext as Bn,useEffect as Ii}from"react";import{jsx as ki}from"react/jsx-runtime";var Mi=wi(),At=Ti(Mi);function md({children:e,emitter:t}){return ki(At.Provider,{value:t,children:e})}function Hn(){return Bn(At)}function Dn(e,t,n=[]){let o=Bn(At);Ii(()=>{let s=i=>{t(i)};return o.on(e,s),()=>{o.off(e,s)}},[o,e,...n])}import{createHelper as Vi}from"polygon-editor";import{createStore as Ni}from"zustand/vanilla";function Pt(e){let t=Math.max(...e.map(i=>i[0])),n=Math.min(...e.map(i=>i[0])),o=Math.max(...e.map(i=>i[1])),s=Math.min(...e.map(i=>i[1]));for(let i of e)if(i[0]!==n&&i[0]!==t&&i[1]!==s&&i[1]!==o||i[0]<n||i[0]>t||i[1]<s||i[1]>o)return!1;return!0}function xe(e){if(!e)return null;if(e.points.length>2){let t=Math.min(...e.points.map(i=>i[0])),n=Math.min(...e.points.map(i=>i[1])),o=Math.max(0,...e.points.map(i=>i[0])),s=Math.max(0,...e.points.map(i=>i[1]));return{x:t,y:n,width:o-t,height:s-n}}return null}function Ei(e){return e.type==="SvgSelector"}function yd(e){return e.type==="BoxSelector"}function wt(e,t){if(Ei(e)){let r=e.svgShape==="polyline";if(!e.points||e.points.length===0)return null;if(t){let{width:a,height:l}=t;return{type:"SvgSelector",value:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${a} ${l}" width="${a}" height="${l}"><${r?"polygon":"polyline"} points="${e.points.map(p=>p.join(",")).join(" ")}" /></svg>`}}return{type:"SvgSelector",value:`<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'><g><path d='M${e.points.map(a=>a.join(",")).join(" ")}${r?" Z":""}' /></g></svg>`}}if(!e.spatial)return null;let{x:n,y:o,width:s,height:i}=e.spatial||{};return!s||!i?null:{type:"FragmentSelector",value:`xywh=${~~n},${~~o},${~~s},${~~i}`}}function Tt(e,t){if(!e||!e.points.length)return null;if(Pt(e.points)){let n=e.points.map(l=>l[0]),o=e.points.map(l=>l[1]),s=Math.min(...n),i=Math.min(...o),r=Math.max(...n)-s,a=Math.max(...o)-i;return wt({type:"BoxSelector",spatial:{x:s,y:i,width:r,height:a}},t)}return wt({type:"SvgSelector",points:e.points,svgShape:e.open?"polygon":"polyline"},t)}function qn(e){if(e.type==="polygon"&&!e.noBox&&e.points&&Pt(e.points)){let n=xe({open:!1,points:e.points||[]});return qn({...e,type:"box",selector:n})}if(e.type==="polygon"||e.type==="draw")return{polygon:{points:e.points||[],open:e.open||!1},requestType:e.type,boundingBox:xe({points:e.points||[],open:!1}),metadata:{},arguments:e.arguments||{},target:Tt({points:e.points||[],open:!1},e.bounds)};let t=e.selector;if(t){let n=[[t.x,t.y],[t.x+t.width,t.y],[t.x+t.width,t.y+t.height],[t.x,t.y+t.height]];return{polygon:{points:n,open:!1},requestType:e.type,boundingBox:t,metadata:{},target:Tt({points:n,open:!1},e.bounds),arguments:e.arguments||{}}}return{polygon:{points:[],open:!1},requestType:e.type,boundingBox:null,target:null,metadata:{},arguments:e.arguments||{}}}var Li={shapeId:null,noShape:!0,transitioning:!1,actionIntentType:null,transitionIntentType:null,selectedPoints:[],hasClosestLine:!1,lastCreationTool:null,modifiers:{Alt:!1,Shift:!1,Meta:!1,proximity:0},bounds:null,showBoundingBox:!1,currentModifiers:{},validIntentKeys:{},pointerInsideShape:!1,closestPoint:null,transitionModifiers:null,selectedStamp:null,bezierLines:[],boxMode:!1,fixedAspectRatio:!1,cursor:"",enabledTools:["pointer","pen","box","lineBox","stamp","hand","line","pencil"],canDelete:!0,canDeselect:!0,isToolSwitchingLocked:!1,currentTool:"box",snapEnabled:!1,snapToPoints:!1,snapToLines:!1,snapToIntersections:!1,snapToGrid:!1,snapToParallel:!1};function Fn({events:e,enabledTools:t,keyboardShortcutMapping:n,keyboardShortcutsEnabled:o=!1,debug:s}){let i=Ni((a,l)=>{let u=null,c=Vi({emitter:e,keyboardShortcutsEnabled:o,keyboardShortcutMapping:n,enabledTools:t,customSetState:d=>{s&&console.log("partial state",d),a(f=>({polygonState:{...f.polygonState,...d}}))}},d=>{a(f=>f.tool.requestId?{polygon:{...d,id:f.tool.requestId}}:{polygon:{id:void 0,points:[],open:!0}}),e.emit("atlas.polygon-update",d)});return{mode:"explore",tool:{enabled:!1,requestId:null,canvasId:null},runtime:null,requestType:null,requests:{},history:c.history,polygon:null,validRequestIds:[],metadata:{},stableViewport:null,canvasRelativePositions:{},canvasViewports:{},polygons:c,polygonState:Li,setMetadata:(d,f)=>{let y=f||l().tool.requestId;y&&a(g=>({metadata:{...g.metadata,[y]:{...g.metadata[y]||{},...d}}}))},setToolCanvasId:d=>{a(f=>({tool:{...f.tool,canvasId:d}}))},switchTool:{pointer(){a({mode:"sketch"}),r.tools.setTool("pointer")},hand(){a({mode:"explore"}),r.tools.setTool("hand")},draw(){a({mode:"sketch"}),r.tools.setTool("pencil")},pen(){a({mode:"sketch"}),r.tools.setTool("pen")},line(){a({mode:"sketch"}),r.tools.setTool("line")},lineBox(){a({mode:"sketch"}),r.tools.setTool("lineBox")},box(){a({mode:"sketch"}),r.tools.setTool("box")},triangle(){a({mode:"sketch"}),r.tools.setTool("stamp"),r.stamps.triangle()},hexagon(){a({mode:"sketch"}),r.tools.setTool("stamp"),r.stamps.hexagon()},circle(){a({mode:"sketch"}),r.tools.setTool("stamp"),r.stamps.circle()},remove(){let d=l();d.tool.requestId&&(c.setShape({points:[],open:!0}),d.cancelRequest(d.tool.requestId))}},reset:()=>{let d=l();d.tool.requestId&&d.cancelRequest(d.tool.requestId)},setPolygonState:d=>a({polygonState:typeof d=="function"?d(l().polygonState):d}),getRequestId:()=>{let d=Math.random().toString(36).slice(2);return a(f=>({validRequestIds:[...f.validRequestIds,d]})),{requestId:d,clear:()=>{l().tool.requestId,a(f=>({tool:f.tool.requestId===d?{enabled:!1,requestId:null,canvasId:null}:f.tool,validRequestIds:f.validRequestIds.filter(y=>y!==d)}))}}},cancelRequest:d=>{let f=d||l().tool.requestId;f&&(a(y=>({mode:"explore",tool:y.tool.requestId===f?{enabled:!1,requestId:null,canvasId:null}:y.tool,validRequestIds:y.validRequestIds.filter(g=>g!==f)})),e.emit("atlas.request-cancelled",{id:f}))},requestAnnotation:async(d,f)=>{let g={...l().requests,[f.requestId]:d},x=qn(d);s&&console.log("requestAnnotation",{response:x,request:d});try{let{points:v=[],open:m=!0}=x.polygon||{},{requestId:h,canvasId:S=null,toolId:b}=f,C=b,R=l(),P=R.validRequestIds.includes(h),L=x.requestType;return s&&console.log("setting points",{requestType:L,points:v,open:m}),!P||R.tool.enabled?null:(c.setShape({id:h,points:v,open:m}),L==="polygon"&&(C=C||"pen",c.tools.setTool("pen")),L==="draw"&&(C=C||"draw",c.tools.setTool("pencil")),L==="box"&&(C=C||"box",c.tools.setTool("box")),L==="target"?(C=C||"box",c.tools.setTool("box"),c.lockAspectRatio(),c.tools.lockToolSwitching(),c.tools.setCanDeselect(!1),c.tools.setCanDelete(!1)):(c.tools.unlockToolSwitching(),c.tools.setCanDeselect(!0),c.tools.setCanDelete(!0)),d.bounds&&c.setBounds(d.bounds),e.emit("atlas.annotation-request",{id:h}),a({polygon:{id:h,points:v,open:m},mode:"sketch",requestType:L,tool:{enabled:!0,requestId:h,canvasId:S},requests:g}),C?R.switchTool[C]?.():v.length===0&&R.switchTool.box(),(typeof d.selectByDefault>"u"&&v.length&&L==="box"||d.selectByDefault)&&R.switchTool.pointer(),new Promise(re=>{let T=w=>{w.id===h&&(a(I=>({mode:"explore",tool:{requestId:null,enabled:!1,canvasId:null},requests:Object.fromEntries(Object.entries(I.requests).filter(([E])=>E!==h))})),e.off("atlas.request-cancelled",T),e.off("atlas.annotation-completed",z),re(null))},z=w=>{w.id===h&&(a(I=>({mode:"explore",tool:{requestId:null,enabled:!1,canvasId:null},requests:Object.fromEntries(Object.entries(I.requests).filter(([E])=>E!==h))})),e.off("atlas.annotation-completed",z),e.off("atlas.request-cancelled",T),re(w))};e.on("atlas.request-cancelled",T),e.on("atlas.annotation-completed",z)}))}catch(v){return console.error(v),null}},completeRequest:d=>{let f=l().tool.requestId;if(typeof d=="string"&&d&&d!==f)return;let y=f?l().requests[f]?.arguments||{}:{},g=f?l().metadata[f]||{}:{},x=l().polygonState.bounds,v=l().polygon;v&&(e.emit("atlas.annotation-completed",{id:v.id,polygon:v,requestType:l().requestType,target:Tt(v,x),canvasId:l().tool.canvasId,boundingBox:xe(v),metadata:g,arguments:{...y}}),c.setShape(null))},setAtlasRuntime:d=>{u=d,e.emit("atlas.ready",{runtime:d}),r.setScale(1/u._lastGoodScale),u.world.addLayoutSubscriber((f,y)=>{(f==="event-activation"||f==="zoom-to"||f==="go-home")&&u?._lastGoodScale&&!Number.isNaN(u._lastGoodScale)&&r.setScale(1/u._lastGoodScale)}),a({runtime:u})},clearAtlasRuntime:()=>{u=null,a({stableViewport:null,runtime:null})},setCanvasRelativePosition:(d,f)=>{a(y=>({canvasRelativePositions:{...y.canvasRelativePositions,[d]:f}}))},clearCanvasRelativePosition:d=>{a(f=>{let y={...f.canvasRelativePositions};return delete y[d],{canvasRelativePositions:y}})},changeMode:d=>{a({mode:d})},nudgeLeft:d=>{if(!u)return;let f=u.getViewport(),y=d??f.width*.1;u.world.gotoRegion({x:f.x-y,y:f.y,width:f.width,height:f.height,nudge:!0})},nudgeRight:d=>{if(!u)return;let f=u.getViewport(),y=d??f.width*.1;u.world.gotoRegion({x:f.x+y,y:f.y,width:f.width,height:f.height,nudge:!0})},nudgeUp:d=>{if(!u)return;let f=u.getViewport(),y=d??f.height*.1;u.world.gotoRegion({x:f.x,y:f.y-y,width:f.width,height:f.height,nudge:!0})},nudgeDown:d=>{if(!u)return;let f=u.getViewport(),y=d??f.height*.1;u.world.gotoRegion({x:f.x,y:f.y+y,width:f.width,height:f.height,nudge:!0})},zoomIn:()=>{u?.world?.zoomIn()},zoomOut:()=>{u?.world?.zoomOut()},goHome:()=>{u?.world?.goHome()},goToRegion:d=>{u?.world?.gotoRegion(d)},getRuntime:()=>u}}),r=i.getState().polygons;return e.on("atlas.annotation-request",()=>{r.clock.start((a,l,u)=>{e.emit("atlas.polygon-render",{state:a,slowState:l,dt:u})},a=>{typeof a=="object"?i.setState({polygonState:a}):i.setState(l=>({polygonState:a(l.polygonState)}))})}),e.on("atlas.annotation-completed",()=>{r.clock.stop()}),e.on("atlas.request-cancelled",()=>{r.clock.stop()}),i}import{jsx as $n}from"react/jsx-runtime";var be=Oi(null);function q(){return Wn(be)}var It={};function Un(e="atlas"){return It[e]?.getState()}function Oe({children:e,name:t="atlas",existing:n,atlasStoreConfig:o}){let s=Hn(),i=Wn(be),r=Hi(()=>n||i||Fn({events:s,...o||{}}),[s,n,i]),a=Di(r,l=>l.mode);return Bi(()=>{let l=t;return l&&(It[l]=r),()=>{l&&delete It[l]}},[r,t]),$n(be.Provider,{value:r,children:$n(zi.Provider,{value:a||"explore",children:e})})}import{mergeStyles as Ye}from"@atlas-viewer/atlas";import{useMemo as ra}from"react";import{createContext as qi,useContext as Fi,useMemo as $i}from"react";import{jsx as Wi}from"react/jsx-runtime";function _n(){return{default:{backgroundColor:"rgba(0,0,0,0)",borderWidth:"2px",borderColor:"rgba(252,0,98, .5)"},highlighted:{backgroundColor:"rgba(75, 103, 225, 0.4)",borderWidth:"1px",borderColor:"rgba(75,103,225,0.99)"},hidden:{borderWidth:"0px",borderColor:"rgba(0,0,0,0)",backgroundColor:"rgba(0,0,0,0)",hidden:!0}}}var Mt=qi(_n());Mt.displayName="AnnotationStyle";function jn(){return Fi(Mt)}function Ld({theme:e,children:t}){let n=$i(()=>e||_n(),[e]);return Wi(Mt.Provider,{value:n,children:t})}import{expandTarget as Gi}from"@iiif/helpers/annotation-targets";import{useMemo as Qi}from"react";import{useEffect as Ui,useMemo as _i,useState as ji}from"react";import{create as Ki}from"zustand";var Yi=Ki()((e,t)=>{let n=new Map,o=()=>Math.random().toString(36).substring(2,15),s=i=>{let r=n.get(i);if(r)return r;let a=o();return n.set(i,a),a};return{stylesheets:{},loading:[],errors:[],async parseStylesheet(i){let{loadStylesheet:r,setStylesheet:a}=t();if(!i)return null;if(typeof i=="string")return i.startsWith("http")?{id:i,type:"CssStylesheet",value:await r(i)}:{id:a(i),type:"CssStylesheet",value:i};if(i.type==="CssStylesheet"){let l=i.id;if("value"in i){let u=Array.isArray(i.value)?i.value.join(`
2
+ `):i.value;if(u)return{id:a(u,l),type:"CssStylesheet",value:u}}if("id"in i&&i.id){let u=await r(i.id);return{id:i.id,type:"CssStylesheet",value:u}}}return null},async loadStylesheet(i){if(t().loading.includes(i))return"";try{let a=await fetch(i);if(!a.ok)throw new Error(`Failed to load stylesheet from ${i}`);let l=await a.text();return e(u=>({stylesheets:{...u.stylesheets,[i]:l}})),l}catch(a){return e(l=>({errors:[...l.errors,{url:i,error:a}]})),""}},setStylesheet(i,r){let a=r||s(i);return e(l=>({stylesheets:{...l.stylesheets,[a]:i}})),a}}});function Kn(e){let[t,n]=ji(""),{loading:o,errors:s,stylesheets:i,parseStylesheet:r}=Yi();return Ui(()=>{e&&r(e).then(l=>{l?.id&&n(l.id)})},[e,r]),[_i(()=>{let l={};return t&&i[t]&&(l[t]=i[t]),l},[t,i]),{id:t,stylesheets:i,loading:o,errors:s}]}function je(e={},t=[]){let{id:n,selector:o}=e,s=_(),i=M(),r=n||s.annotation,a=k(p=>r?p.iiif.entities.Annotation[r]:void 0,[r]),[l]=Kn(a?.stylesheet),u=k(p=>a&&a.body?a.body.map(c=>c?c.type==="SpecificResource"?{...c,source:i.get(c)}:c?p.iiif.entities[c.type][c.id]:null:null).filter(Boolean):[],[a]);return Qi(()=>{if(!a)return;let p={...a,body:u,target:Gi(a.target,{typeMap:i.getState().iiif.mapping,loadedStylesheets:l})};return o?o(p):p},[a,o,u,l,...t])}import{useMemo as Xi}from"react";function A(e={},t=[]){let{id:n,selector:o}=e,s=_(),i=n||s.canvas,r=k(a=>i?a.iiif.entities.Canvas[i]:void 0,[i]);return Xi(()=>{if(r)return o?o(r):r},[r,o,...t])}import{useMemo as Yn}from"react";import{createEventsHelper as Zi}from"@iiif/helpers/events";function Ke(e,t){let n=M(),o=Yn(()=>Zi(n),[n]),s=k(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return Yn(()=>e?o.getListenersAsProps(e,t):{},[s,e,n,t])}import{useMemo as Ji}from"react";import{createStylesHelper as ea}from"@iiif/helpers/styles";function Ce(e,t){let n=M(),o=Ji(()=>ea(n),[n]);return k(()=>{if(!e)return null;let s=o.getAppliedStyles(e.id);return s?t?s[t]:s:void 0},[e,t])}import{useCallback as oa}from"react";import{HTMLPortal as ta,useResizeWorldItem as na}from"@atlas-viewer/atlas";import{useMemo as te}from"react";import{Fragment as kt,jsx as K,jsxs as Et}from"react/jsx-runtime";function Gn({handleSize:e,resizable:t,onSave:n,children:o,maintainAspectRatio:s,disableCardinalControls:i,aspectRatio:r,...a}){let l=typeof e>"u"?s?12:8:e,{portalRef:u,mode:p,mouseEvent:c,isEditing:d}=na({x:a.x||0,y:a.y||0,width:a.width,height:a.height,aspectRatio:r,maintainAspectRatio:s},n),f=te(()=>c("translate"),[c]),y=te(()=>c("east"),[c]),g=te(()=>c("west"),[c]),x=te(()=>c("south"),[c]),v=te(()=>c("north"),[c]),m=te(()=>c("south-east"),[c]),h=te(()=>c("south-west"),[c]),S=te(()=>c("north-east"),[c]),b=te(()=>c("north-west"),[c]),C=p==="sketch",R={zIndex:999,boxShadow:"0px 2px 3px 0 rgba(0,0,0,0.2)",outline:"2px solid rgba(155,155,155,.7)",borderRadius:s||i?"50%":2,position:"absolute",background:"#fff",pointerEvents:d?"none":C?"initial":"none"};return K(kt,{children:Et("world-object",{...a,children:[o,C&&t?K(ta,{ref:u,target:{x:0,y:0,height:a.height,width:a.width},relative:!0,interactive:!1,children:C&&t?Et(kt,{children:[K("div",{onMouseDown:f,onTouchStart:f,style:{display:"block",width:"100%",height:"100%",cursor:"move",border:"1px solid rgba(255,255,255, .7)",outline:"2px solid rgba(155,155,155, .7)",boxSizing:"border-box",pointerEvents:d?"none":C?"initial":"none"}}),s?null:Et(kt,{children:[K("div",{title:"east",onTouchStart:y,onMouseDown:y,style:{...R,cursor:"e-resize",height:l*2,width:l,right:0,top:"50%",opacity:i?0:1,transform:`translate(${l/2}px, -${l}px)`}}),K("div",{title:"west",onMouseDown:g,style:{...R,cursor:"w-resize",position:"absolute",height:l*2,width:l,left:0,top:"50%",opacity:i?0:1,transform:`translate(-${l/2}px, -${l}px)`}}),K("div",{title:"north",onMouseDown:v,style:{...R,cursor:"n-resize",position:"absolute",height:l,width:l*2,left:"50%",top:0,opacity:i?0:1,transform:`translate(-${l}px, -${l/2}px)`}}),K("div",{title:"south",onMouseDown:x,style:{...R,cursor:"s-resize",position:"absolute",height:l,width:l*2,left:"50%",bottom:0,opacity:i?0:1,transform:`translate(-${l}px, ${l/2}px)`}})]}),K("div",{title:"north-east",onMouseDown:S,style:{...R,cursor:"ne-resize",position:"absolute",height:l,width:l,right:0,top:0,transform:`translate(${l/2}px, -${l/2}px)`}}),K("div",{title:"south-east",onMouseDown:m,style:{...R,cursor:"se-resize",position:"absolute",height:l,width:l,bottom:0,right:0,transform:`translate(${l/2}px, ${l/2}px)`}}),K("div",{title:"south-west",onMouseDown:h,style:{...R,cursor:"sw-resize",position:"absolute",height:l,width:l,bottom:0,left:0,transform:`translate(-${l/2}px, ${l/2}px)`}}),K("div",{title:"north-west",onMouseDown:b,style:{...R,cursor:"nw-resize",position:"absolute",height:l,width:l,top:0,left:0,transform:`translate(-${l/2}px, -${l/2}px)`}})]}):null}):null]})})}import{jsx as Qn}from"react/jsx-runtime";function Xn({id:e,interactive:t,region:n,onClick:o,onHover:s,onSave:i,aspectRatio:r,maintainAspectRatio:a,disableCardinalControls:l,isEditing:u,style:p={backgroundColor:"rgba(0,0,0,.5)"}}){let c=oa(d=>{u&&i?.({id:n.id,x:n.x,y:n.y,height:n.height,width:n.width,...d})},[i,u,n.id,n.x,n.y,n.height,n.width]);return Qn(Gn,{id:e,x:n.x,y:n.y,width:n.width,aspectRatio:r,height:n.height,resizable:u,onSave:c,maintainAspectRatio:a,disableCardinalControls:l,children:Qn("box",{interactive:t,onClick:d=>{d.preventDefault(),d.stopPropagation(),o?.(n)},relativeStyle:!0,onMouseEnter:()=>{s?.(n)},target:{x:0,y:0,width:n.width,height:n.height},style:p})})}import{jsx as ia}from"react/jsx-runtime";var Re=({id:e,style:t,className:n,interactive:o,targetId:s,ignoreTargetId:i})=>{let r=je({id:e}),a=Ce(r,"atlas"),l=Ce(r,"html"),u=Ke(r,["atlas"]),p=A(),c=jn(),d=ra(()=>Ye(Ye(Ye(Ye(t,a),r?.motivation?.includes("highlighting")?c.highlighted:c.default),r?.target?.selector?.boxStyle||{})),[t,a,c,r?.motivation,r?.target]),f=s||p?.id;return p&&r&&r.target&&r.target.selector&&(r.target.selector.type==="BoxSelector"||r.target.selector.type==="SvgSelector")&&r.target.source&&(i?!0:r.target.source.id===f||r.target.source===f)?ia(Xn,{id:r.id,isEditing:!0,region:r.target.selector.spatial,style:d,className:l?.className||n,interactive:!!(l?.href||o),href:l?.href||null,title:l?.title||null,hrefTarget:l?.target||null,onClick:()=>{},...u}):null};import{Fragment as sa}from"react";import{useMemo as aa}from"react";function Zn(e={},t=[]){let{id:n,selector:o}=e,s=_(),i=n||s.annotationPage,r=k(a=>i?a.iiif.entities.AnnotationPage[i]:void 0,[i]);return aa(()=>{if(r)return o?o(r):r},[r,...t])}import{jsx as Jn}from"react/jsx-runtime";var ue=({className:e,page:t,targetId:n,ignoreTargetId:o})=>{let s=Zn({id:t.id})||t,i=Ce(s,"atlas"),r=Ce(s,"html");return k(a=>s.id?a.iiif.entities.AnnotationPage[s.id]:null,[]),Jn(sa,{children:s.items?.map(a=>Jn(Re,{id:a.id,style:i,className:r?.className||e,targetId:n,ignoreTargetId:o},a.id))})};import{createContext as Nt,useContext as Lt}from"react";import{jsx as Vt}from"react/jsx-runtime";var eo=Nt(null),to=Nt(null),no=Nt(null);function Hm(){let e=Lt(eo);if(!e)throw new Error("Ctx not found");return e}function Dm(){let e=Lt(to);if(!e)throw new Error("Ctx not found");return e}function qm(){let e=Lt(no);if(!e)throw new Error("Ctx not found");return e}function Ge({actions:e,state:t,children:n,currentTime:o,progress:s,element:i}){return Vt(no.Provider,{value:{currentTime:o,progress:s,element:i},children:Vt(to.Provider,{value:e,children:Vt(eo.Provider,{value:t,children:n})})})}import{useMemo as la}from"react";import{expandTarget as ua}from"@iiif/helpers";function Qe(){let e=B(),t=A();return la(()=>{if(!e||!t||!e.start)return null;let n=ua(e.start);return!n||n.source.id!==t.id||!n||!n.selector||n.selector.type!=="TemporalSelector"?null:n.selector.temporal},[e,t])}import{useCallback as Q,useEffect as zt,useReducer as ca,useRef as Xe}from"react";function oo(e){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:e}}function da(e,t){switch(t.type){case"RESET":return t.state;case"FINISHED":return{...e,isFinished:!0,isPlaying:!1,playRequested:!1};case"PLAY_PAUSE":return{...e,isFinished:!1,isPlaying:!e.isPlaying};case"PLAY_REQUESTED":return{...e,isFinished:!1,playRequested:!0};case"PAUSE":return{...e,isPlaying:!1};case"PLAY":return{...e,isFinished:!1,playRequested:!1,isPlaying:!0};case"MUTE":return{...e,isMuted:!0};case"SET_VOLUME":return{...e,volume:t.volume,isMuted:t.volume===0};case"TOGGLE_MUTE":return{...e,isMuted:!e.isMuted};case"UNMUTE":return{...e,isMuted:!1}}return e}function Ot(e){let t=Math.round(e);return`${Math.floor(t/60)}:${`${t%60}`.padStart(2,"0")}`}function Ae(e){let[t,n]=ca(da,oo(e.duration));zt(()=>{n({type:"RESET",state:oo(e.duration)})},[e.duration]);let o=Xe(null),s=Xe(null),i=Xe(null),r=Xe(!1),a=Q(()=>{s.current&&o.current&&(s.current.innerHTML=Ot(o.current.currentTime),i.current&&(i.current.style.width=`${o.current.currentTime/e.duration*100}%`),r.current!==o.current.muted&&(r.current=o.current.muted,n(o.current.muted?{type:"MUTE"}:{type:"UNMUTE"})))},[e.duration]),l=Q(()=>{o.current&&(n({type:"PLAY_REQUESTED"}),o.current.play().then(()=>{n({type:"PLAY"})}),a())},[a]),u=Q(()=>{o.current&&(o.current.duration>0&&o.current.paused?l():p())},[a]),p=Q(()=>{o.current&&(o.current.pause(),n({type:"PAUSE"}),a())},[a]),c=Q(()=>{o.current&&(o.current.muted=!o.current.muted,n(o.current.muted?{type:"MUTE"}:{type:"UNMUTE"}))},[]),d=Q(()=>{o.current&&(o.current.muted=!0,n({type:"MUTE"}))},[]),f=Q(()=>{o.current&&(o.current.muted=!1,n({type:"UNMUTE"}))},[]),y=Q(v=>{o.current&&(o.current.muted=!1,o.current.volume=v/100,n({type:"SET_VOLUME",volume:v}))},[]),g=Q(v=>{o.current&&(o.current.currentTime=Math.max(0,Math.min(v*e.duration,e.duration)),a())},[]),x=Q(v=>{if(o.current){let m=typeof v=="function"?v(o.current.currentTime):v;o.current.currentTime=Math.max(0,Math.min(m,e.duration)),a()}},[]);return zt(()=>{let v=setInterval(()=>{a()},350);return()=>clearInterval(v)},[a,e.duration]),zt(()=>{let v=()=>{n({type:"FINISHED"})},m=o.current;return m?.addEventListener("ended",v),()=>m?.removeEventListener("ended",v)},[]),[{element:o,currentTime:s,progress:i},t,{play:l,pause:p,playPause:u,mute:d,unmute:f,toggleMute:c,setVolume:y,setDurationPercent:g,setTime:x}]}import{createContext as ro,useContext as ma,useEffect as pa}from"react";var Bt=ro(()=>{}),Ht=ro(()=>{});function D(e,t,n,o,s=[]){let i=ma(e==="portal"?Ht:Bt);pa(()=>(e!=="none"&&i(t,n,o),()=>{i(t,null)}),[t,e,i,...s])}import{jsx as fa,jsxs as ga}from"react/jsx-runtime";function Dt({media:e,startTime:t,children:n}){let[{element:o,currentTime:s,progress:i},r,a]=Ae({duration:e.duration}),l=t?`${e.url}#t=${t}`:e.url;return ga(Ge,{state:r,actions:a,currentTime:s,progress:i,element:o,children:[fa("audio",{ref:o,src:l}),n]},e.url)}function Ze({media:e,mediaControlsDeps:t,audioCopmonent:n=Dt,children:o}){let s=Qe();return D("portal","audio",n,{media:e,startTime:s?s.startTime:null,children:o},[e,s,...t||[]]),null}import{createContext as ha,useContext as ya}from"react";var ce=ha(null);ce.displayName="Strategy";function V(){let e=ya(ce);if(!e)throw new Error("useStrategy must be used within a StrategyProvider");return e}import{Fragment as va,jsx as qt,jsxs as Sa}from"react/jsx-runtime";function Ft({model:e}){return Sa(va,{children:[qt("style",{children:`
3
3
  .model-container {
4
4
  position: absolute;
5
5
  top: 0;
@@ -12,10 +12,10 @@ import{c as ln,l as un}from"./chunk-P7XHGETS.js";import{forwardRef as Vr,useImpe
12
12
  justify-content: center;
13
13
  pointer-events: visible;
14
14
  }
15
- `}),qt("div",{className:"model-container",children:qt("model-viewer",{"interaction-prompt":"none",style:{width:"100%",height:"100%"},"camera-controls":"","ar-status":"not-presenting",src:e.id})})]})}function Je({model:e,name:t}){return D("overlay",`model-${t}`,$t,{model:e},[e]),null}import{jsx as ya}from"react/jsx-runtime";function io(){let{strategy:e}=V();return e.type!=="3d-model"?null:ya(Je,{model:e.model})}import{createContext as va,useContext as Sa}from"react";var et=va(null);et.displayName="Controls";function $(){let e=Sa(et);if(!e)throw new Error("useStrategy must be used within a StrategyProvider");return e}import{Fragment as xa,jsx as tt,jsxs as ba}from"react/jsx-runtime";function ao(){let{strategy:e}=V(),{renderViewerControls:t,viewControlsDeps:n}=$(),o=A(),s=o?.accompanyingCanvas,i=o?.placeholderCanvas;return ba(xa,{children:[e.type==="media"&&e.media.type==="Sound"&&s?tt(ee,{canvas:s.id,children:tt(de,{renderViewerControls:t,viewControlsDeps:n})}):null,e.type==="media"&&e.media.type==="Sound"&&i&&!s?tt(ee,{canvas:i.id,children:tt(de,{renderViewerControls:t,viewControlsDeps:n})}):null]})}import{createContext as wa,useContext as Ta,useMemo as Ia}from"react";import{useCallback as lo,useLayoutEffect as Ra,useMemo as Aa,useRef as Pa}from"react";import{entityActions as Ft}from"@iiif/helpers/vault/actions";import{useMemo as Ca}from"react";function so(){let t=M().getStore();return Ca(()=>n=>t.dispatch(n),[t])}function uo(e){return typeof e!="string"&&e&&e.bindToVault}function co(){let e=M(),t=Pa([]),n=so(),o=Aa(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);Ra(()=>{let a={id:o,type:"AnnotationPage",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],rendering:[],service:[]};n(Ft.importEntities({entities:{AnnotationPage:{[a.id]:a}}}))},[o]);let s=k(a=>o&&a.iiif.entities.AnnotationPage[o]||null,[o]),i=lo((a,l)=>{if(o){if(uo(a)){let c=a;c.__vault||c.bindToVault(e),a=typeof c.source=="string"?c.source:c.source.id,t.current[a]=c}else typeof a!="string"&&(a=a.id);let u=e.get({id:o,type:"AnnotationPage"}),g=e.get({id:a,type:"Annotation"});u&&g&&(u.items.find(c=>c.id===g.id)||n(Ft.addReference({id:o,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"},index:l})))}},[o]),r=lo(a=>{o&&(uo(a)?a=typeof a.source=="string"?a.source:a.source.id:typeof a!="string"&&(a=a.id),t.current[a]&&t.current[a].beforeRemove(),e.get({id:o,type:"AnnotationPage"})&&n(Ft.removeReference({id:o,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"}})))},[o]);return[s,{addAnnotation:i,removeAnnotation:r}]}import{jsx as Ma}from"react/jsx-runtime";var mo=wa(null);function po(){let e=Ta(mo);return[e.fullPage,{addAnnotation:e.addAnnotation,removeAnnotation:e.removeAnnotation}]}function fo({children:e}){let[t,{addAnnotation:n,removeAnnotation:o}]=co();return Ma(mo.Provider,{value:Ia(()=>({fullPage:t,addAnnotation:n,removeAnnotation:o}),[t]),children:e})}import{Fragment as ka,jsx as go,jsxs as Ea}from"react/jsx-runtime";function ho({children:e}){let{strategy:t}=V(),[n]=po();return t.type!=="images"?null:Ea(ka,{children:[n?go(ue,{page:n}):null,t.annotations&&t.annotations.pages?t.annotations.pages.map(o=>go(ue,{page:o},o.id)):null,e]})}import{useEffect as Ba,useMemo as Ha,useRef as Da,useState as qa}from"react";import{useEffect as Va}from"react";var yo=(e,t=[])=>{let n=M();Va(()=>{e(n)},[n,...t])};import Na,{useContext as La}from"react";import{ImageServiceLoader as za}from"@iiif/helpers/image-service";var Oa=Na.createContext(new za);function vo(){return La(Oa)}import{createThumbnailHelper as $a}from"@iiif/helpers/thumbnail";function Pe(e,t,{canvasId:n,manifestId:o}={}){let s=M(),i=vo(),r=Ha(()=>$a(s,{imageServiceLoader:i}),[s,i]),[a,l]=qa(),u=B(o?{id:o}:void 0),g=A(n?{id:n}:void 0),c=g||u,d=Da(!1);if(Ba(()=>(d.current=!1,()=>{d.current=!0}),[]),!c)throw new Error("Must be called under a manifest or canvas context.");return yo(p=>{r.getBestThumbnailAtSize(c,e,t).then(y=>{y.best&&!d.current&&l(y.best)})},[c]),a}import{jsx as So}from"react/jsx-runtime";function we({x:e=0,y:t=0}){let n=A(),o=Pe({maxWidth:256,maxHeight:256});return!n||!o||o.type!=="fixed"?null:So("world-object",{height:n.height,width:n.width,x:e,y:t,children:So("world-image",{uri:o.id,target:{x:0,y:0,width:n.width,height:n.height},display:o.width&&o.height?{width:o.width,height:o.height}:void 0,crop:void 0})})}import{jsx as Fa,jsxs as Wa}from"react/jsx-runtime";function xo({as:e}){let{strategy:t}=V(),{renderMediaControls:n,mediaControlsDeps:o}=$();return t.type!=="media"||t.media.type!=="Sound"?null:Wa(Ze,{media:t.media,mediaControlsDeps:o,audioCopmonent:e,children:[Fa(we,{}),n?n(t):null]},t.media.url)}import{HTMLPortal as Do}from"@atlas-viewer/atlas";import{useLayoutEffect as ls,useMemo as us}from"react";import{useStore as qo}from"zustand";import{createContext as Ua,useContext as _a}from"react";import{useStore as ja}from"zustand";import{jsx as Ka}from"react/jsx-runtime";var Wt=Ua(null);Wt.displayName="ComplexTimeline";function bo({children:e,store:t}){return Ka(Wt.Provider,{value:t,children:e})}function cf(e){let t=_a(Wt);if(!t)throw new Error("useComplexTimeline must be used within a ComplexTimelineProvider");return ja(t,e)}import Ya from"mitt";import{createStore as Ga}from"zustand/vanilla";function Co({currentKeyFrameIndex:e,keyframes:t,targetTime:n,currentTime:o}){if(o<=n){let s=t.findIndex(a=>a.time>n);if(s===-1)return[e,[]];let i={},r=t.slice(e,s);for(let a of r)a.type==="enter"&&(i[a.id]=a),a.type==="exit"&&(i[a.id]?delete i[a.id]:i[a.id]=a);return[s,Object.values(i)]}return[e,[]]}function Ro({complexTimeline:e,startTime:t=0}){let n=Ya(),o={},s={progress:null,currentTime:null},i=0,r=null,a=0,l=null;function u(){let m=x.getState().visibleElements,h=o,S=[],b=Object.keys(h);for(let C of b){let R=h[C],P=m[C];R&&P&&S.push(R)}return S}function g(){return Object.keys(o).map(m=>o[m])}function c(v){s.currentTime&&(s.currentTime.innerHTML=Ot(v),s.progress&&(s.progress.style.width=`${v/e.duration*100}%`))}let d=()=>{let v=x.getState(),m=v.currentPrime;if(!m)return;let h=o,S=v.visibleElements,b=Object.keys(h);for(let C of b){let R=h[C],P=S[C];if(R&&C!==m.id&&P){let L=a-P.time*1e3;Math.abs(a-P.time*1e3-R.currentTime*1e3)>300&&(R.currentTime=L/1e3)}}},p=(v=0)=>{let m=v-i,h=x.getState();if(h.isPlaying){let S=h.currentPrime;if(S){let P=o[S.id];P&&(P.paused?a+=m:a=(S.time+P.currentTime)*1e3)}else a+=m;let b=a/1e3;if(b>h.duration){x.getState().setTime(0),x.setState({isPlaying:!1}),y(),c(0);return}c(b);let[C,R]=Co({currentTime:b,currentKeyFrameIndex:h.nextKeyframeIndex,keyframes:h.complexTimeline.keyframes,targetTime:b});R.length&&h.applyKeyframes(C,R)}i=v,r=requestAnimationFrame(p)},y=()=>{r&&cancelAnimationFrame(r)},f=(v,m)=>{},x=Ga((v,m)=>({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:()=>{m().clockRunning||(p(),l=setInterval(d,500)),v({clockRunning:!0,clockStartRequests:m().clockStartRequests+1})},applyKeyframes(h,S){let b=m(),C={...b.visibleElements},R=b.currentPrime;for(let P of S)P.type==="enter"&&(C[P.id]=P,n.emit("complex-timeline.enter",{id:P.id})),P.type==="exit"&&(C[P.id]=null,n.emit("complex-timeline.exit",{id:P.id})),P.isPrime&&(R=P);v({nextKeyframeIndex:h,visibleElements:C,currentPrime:R})},stopClock:()=>{let h=m().clockStartRequests;if(h!==0){if(h===1){y(),l&&clearInterval(l),v({clockRunning:!1,clockStartRequests:0});return}v({clockStartRequests:h-1})}},setElement:(h,S)=>{o[h]=S;let b=Object.keys(o),C=m().complexTimeline;f(S,h),C.items.filter(P=>P.type!=="Image"&&P.type!=="Text").every(P=>b.includes(P.annotationId))&&!m().isReady&&(n.emit("complex-timeline.ready",{complexTimeline:C}),v({isReady:!0}))},removeElement:h=>{delete o[h]},mute(){for(let h of g())h.muted=!0;v({isMuted:!0})},unmute(){for(let h of g())h.muted=!1;v({isMuted:!1})},play(){if(!m().isPlaying){for(let S of u())S.play();v({isPlaying:!0})}},pause(){if(m().isPlaying){for(let S of u())S.pause();v({isPlaying:!1})}},playPause(){let h=m();h.isPlaying?h.pause():h.play()},setDurationPercent(h){let b=m().duration*h;m().setTime(b)},setTime(h){let S=m(),b=a/1e3,C=typeof h=="function"?h(b):h,R=S.nextKeyframeIndex;if(b>C){v({visibleElements:{},currentPrime:null});let I=Object.keys(S.visibleElements);for(let E of I)n.emit("complex-timeline.exit",{id:E});b=0,R=0}let[P,L]=Co({currentTime:b,currentKeyFrameIndex:R,keyframes:S.complexTimeline.keyframes,targetTime:C});S.applyKeyframes(P,L),a=C*1e3;let T=x.getState().visibleElements,z=o,w=Object.keys(T);for(let I of w){let E=T[I];if(E){let Ee=z[I];Ee&&(Ee.currentTime=(a-E.time*1e3)/1e3)}}c(C)},setVolume(h){for(let S of g())S.volume=Math.min(1,Math.max(0,h/100));v({volume:h})},toggleMute(){let h=m();h.isMuted?(h.unmute(),v({isMuted:!1})):(h.mute(),v({isMuted:!0}))},clearProgressElement(){s.progress=null},setProgressElement(h){s.progress=h},setCurrentTimeElement(h){s.currentTime=h},clearCurrentTimeElement(){s.currentTime=null}}));return n.on("complex-timeline.enter",v=>{let m=x.getState(),h=v.id,S=o[h];S&&m.isPlaying&&S.play()}),n.on("complex-timeline.exit",v=>{let m=x.getState(),h=v.id,S=o[h];S&&(S.currentTime=0,S.pause())}),x.getState().setTime(t),{store:x,emitter:n}}import{Fragment as Oo,useMemo as Bo}from"react";import{HTMLPortal as os}from"@atlas-viewer/atlas";import{getId as rs}from"@iiif/parser/image-3";import Qa,{useContext as Xa}from"react";import{imageServices as Za}from"@iiif/helpers/image-service";import{useStore as nt}from"zustand";var Ao=Qa.createContext(Za.store);Ao.displayName="ImageServicesHelper";function ot(){return Xa(Ao)}function Po(e){let t=ot();return nt(t,({loaded:n})=>n[e])}function rt(){let e=ot();return nt(e,({loadServiceSync:t})=>t)}function wo(){let e=ot();return nt(e,({loaded:t})=>t)}function bf(){let e=ot();return nt(e,({loadService:t})=>t)}import Te,{useMemo as Ut}from"react";import{jsx as X}from"react/jsx-runtime";var Io=Te.createContext("en"),Mo=Te.createContext({}),ko=Te.createContext(null);function Pf(e){return X(Mo.Provider,{value:e.translations,children:e.children})}function wf(e){return X(Io.Provider,{value:e.language,children:e.children})}function Tf(e){return X(ko.Provider,{value:e.convert,children:e.children})}function Eo(){return Te.useContext(ko)}function _t(){return Te.useContext(Io)}function Vo(){return Te.useContext(Mo)}function To(e){return e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):e}function Ja({as:e,language:t,children:n,viewingDirection:o,...s}){let i=_t();return Ut(()=>To(i)===To(t),[i,t])?e?X(e,{...s,children:n}):X("span",{...s,children:n}):e?X(e,{...s,lang:t,dir:o,children:n}):X("span",{...s,lang:t,dir:o,children:n})}function No(e,t,n){if(t.length===0)return;if(t.length===1)return t[0];if(t.indexOf(e)!==-1)return e;let o=e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):null;if(o&&t.indexOf(o)!==-1)return o;for(let s of n)if(t.indexOf(s)!==-1)return s;return t.indexOf("none")!==-1?"none":t.indexOf("@none")!==-1?"@none":t[0]}var es=(e,t=[])=>{let n=_t();return Ut(()=>{let o=e();return No(n,o,[])},[n,...t])};function me(e,t,n,o){return t?n?n(e[t]||t,o||"none"):e[t]||t:""}function ts(e,t,n=`
16
- `,o={}){let s=Eo(),i=es(()=>Object.keys(e||{}),[e]);return[Ut(()=>{if(!e)return me(o,t,s)||"";if(typeof e=="string")return me(o,e,s);let r=i?e[i]:void 0;return r?typeof r=="string"?r:r.map(a=>me(o,a,s,i)).join(n):""},[i,t,e]),i]}function If(){let e=_t(),t=Vo(),n=Eo();return function(s,i="",r=`
17
- `,a=t){let l=Object.keys(s||{}),u=No(e,l,[]);if(!s)return me(a,i,n)||"";if(typeof s=="string")return me(a,s,n);let g=u?s[u]:void 0;return g?typeof g=="string"?me(a,g,n,u):g.map(c=>me(a,c,n,u)).join(typeof r<"u"?r:`
18
- `):""}}function Be({as:e,defaultText:t,enableDangerouslySetInnerHTML:n,children:o,separator:s,...i}){let r=Vo(),[a,l]=ts(o,t,s,r);return l?X(Ja,{...i,as:e,language:l,title:n?void 0:a,dangerouslySetInnerHTML:n?{__html:a}:void 0,children:n?void 0:a}):e?X(e,{...i,children:a}):X("span",{...i,title:n?void 0:a,dangerouslySetInnerHTML:n?{__html:a}:void 0,children:n?void 0:a})}import{isImageServiceLevel as Lo}from"@iiif/parser/image-3";import{useMemo as jt}from"react";import{jsx as it,jsxs as ns}from"react/jsx-runtime";var Kt=e=>{let t=e.format||"jpg",n=e.width/(e.crop?.width||e.tiles.width),o=e.tiles.imageService.sizes||[],s=e.enableThumbnail,i=e.enableSizes,r=jt(()=>{let u=e.tiles.imageService.id||e.tiles.imageService["@id"];return u?.endsWith("/info.json")?u.slice(0,-1*10):u},[e.tiles.imageService.id,e.tiles.imageService["@id"]]),a=jt(()=>{let u=e.tiles.imageService.tiles||[];if(!u.length){let g=e.width,c=[1],d=1;for(;2**d<g;)d=d*2,c.push(d);return(e.tiles.imageService.maxArea||e.tiles.imageService.maxWidth||e.tiles.imageService.maxHeight)&&Lo(2,e.tiles.imageService)?[{width:256,height:256,scaleFactors:c}]:Lo(2,e.tiles.imageService)?[{width:256,height:256,scaleFactors:c}]:[]}return u},[e.tiles.imageService,e.width]),l=jt(()=>{let u=e.tiles.imageService;return(u?u["@context"]?Array.isArray(u["@context"])?u["@context"]:[u["@context"]]:[]:[]).indexOf("http://iiif.io/api/image/3/context.json")!==-1},[e.tiles.imageService.id,e.tiles.imageService]);return it("world-object",{rotation:e.rotation,scale:n,height:e.crop?.height||e.tiles.height,width:e.crop?.width||e.tiles.width,x:e.x,y:e.y,onClick:e.onClick,children:ns("composite-image",{id:e.tiles.imageService.id,width:e.crop?.width||e.tiles.width,height:e.crop?.height||e.tiles.height,crop:e.crop,renderOptions:e.renderOptions,children:[s&&e.tiles.thumbnail?it("world-image",{priority:!0,uri:e.tiles.thumbnail.id,target:{width:e.tiles.width,height:e.tiles.height},display:{width:e.tiles.thumbnail.width,height:e.tiles.thumbnail.height},crop:e.crop}):null,i&&o.map((u,g)=>it("world-image",{uri:`${r}/full/${u.width},${l?u.height:""}/0/default.${t}`,target:{width:e.tiles.width,height:e.tiles.height},display:{width:u.width,height:u.height},crop:e.crop},g)),a.map(u=>(u.scaleFactors||[]).map(g=>it("tiled-image",{uri:e.tiles.imageService.id,display:{width:e.tiles.width,height:e.tiles.height},format:t,tile:u,scaleFactor:g,crop:e.crop,version3:l},`${e.tiles.imageService.id}-tile-${g}`)))]},e.tiles.imageService.id)},e.tiles.imageService.id)};import{jsx as ne,jsxs as as}from"react/jsx-runtime";function is({resource:e,heading:t,note:n,extra:o}){return o?ne(os,{target:{x:0,y:0,width:o.target?.spatial.width,height:o.target?.spatial.height},backgroundColor:"#333",relative:!0,children:ne("div",{style:{display:"flex",alignContent:"center",justifyContent:"center",alignItems:"center",height:"100%",width:"100%",background:"#444",color:"#BBB"},children:as("div",{children:[ne(Be,{children:t||"Not authorised"}),n&&ne("p",{children:ne(Be,{children:n})}),ne("p",{children:e.id||e["@id"]||"unknown"})]})})}):null}function zo({image:e,thumbnail:t,crop:n,enableSizes:o,enableThumbnail:s,renderOptions:i,rotation:r}){let a=En(),l=rs(e.service),u=Po(l),g=rt(),c=u?.service;g(e.service,e);let d=c&&u?.status==="done",p=(c?.preferredFormats||[])[0],y=t&&t.type==="fixed"&&t.id&&!t.id.includes("/full/full/")&&!t.id.includes("/max/")?t:void 0;if(d===!1)return null;if(!a){let f=e.service,x=f.width||e.width||0,v=f.height||e.height||0,m=0,h=0,S=e.target?.spatial.width||x,b=e.target?.spatial.height||v,C=S,R=b;return(r===90||r===270)&&([S,b]=[b,S],m=(C-S)/2,h=(R-b)/2),ne(Kt,{enableThumbnail:s,renderOptions:i,rotation:r,tiles:{id:f.id||f["@id"]||"unknown",height:v,width:x,imageService:f,thumbnail:y},enableSizes:o,x:m,y:h,format:p,width:S,height:b,crop:n})}return ne(Vn,{resource:e.service,errorComponent:is,extra:e,children:f=>{let x=f.width||e.width||0,v=f.height||e.height||0,m=0,h=0,S=e.target?.spatial.width||x,b=e.target?.spatial.height||v,C=S,R=b;return(r===90||r===270)&&([S,b]=[b,S],m=(C-S)/2,h=(R-b)/2),ne(Kt,{enableThumbnail:s,renderOptions:i,tiles:{id:f.id||f["@id"]||"unknown",height:v,width:x,imageService:f,thumbnail:y},rotation:r,format:p,enableSizes:o,x:m,y:h,width:S,height:b,crop:n})}},e.id)}import{jsx as Yt,jsxs as Gt}from"react/jsx-runtime";function Ie({id:e,image:t,thumbnail:n,isStatic:o,x:s=0,y:i=0,children:r,selector:a,onClick:l,enableSizes:u,enableAnnotations:g}){let c=Bo(()=>{if(!(!a||a.spatial.x===0&&a.spatial.y===0))return a.spatial},[a]),d=Bo(()=>{if(typeof t.rotation<"u")return t.rotation;if(!t.annotation)return 0;let S=Array.isArray(t.annotation.body)?t.annotation.body?.[0]:t.annotation.body;if(S&&S.selector?.type==="ImageApiSelector")return Number(S.selector.rotation)},[t]),p=!!t.service,y=s+t.target.spatial.x,f=i+t.target.spatial.y,x=t.target.spatial.width,v=t.target.spatial.height,m=t.target.spatial.width,h=t.target.spatial.height;return(d===90||d===270)&&([m,h]=[h,m],p||([x,v]=[v,x],y+=(t.target.spatial.width-x)/2,f+=(t.target.spatial.height-v)/2)),Gt("world-object",{x:y,y:f,width:x,height:v,onClick:l,rotation:p?0:d,children:[t.service?Gt(Oo,{children:[Yt(zo,{image:t,thumbnail:n,crop:c,enableSizes:u,rotation:d}),r]},"service"):Gt(Oo,{children:[Yt("world-image",{onClick:l,uri:t.id,target:{x:0,y:0,width:m,height:h},display:m&&h?{width:m,height:h}:void 0,crop:c}),r]},"no-service"),g&&t.annotationPages?t.annotationPages.map(S=>Yt(ue,{page:S,className:"image-service-annotation",ignoreTargetId:!0},S.id)):null]},e+(p?"server":"no-service"))}import{HTMLPortal as ss}from"@atlas-viewer/atlas";import{Fragment as Ho,jsx as He}from"react/jsx-runtime";function at({strategy:e,onClickPaintingAnnotation:t}){return He(Ho,{children:e.items.map((n,o)=>He(Ho,{children:He(ss,{onClick:t?s=>{s.stopPropagation(),t(n.annotationId,n,s)}:void 0,target:n.target?.spatial||void 0,children:He("div",{"data-textual-content":!0,children:He(Be,{enableDangerouslySetInnerHTML:!0,children:n.text})})},o)}))})}import{Fragment as cs,jsx as pe,jsxs as ds}from"react/jsx-runtime";function $o({strategy:e,children:t}){let{store:n}=us(()=>Ro({complexTimeline:e}),[e]),o=qo(n,r=>r.isReady),s=qo(n,r=>r.visibleElements);function i(r){return a=>{a&&n.getState().setElement(r,a)}}return ls(()=>{if(o){let{startClock:r,stopClock:a}=n.getState();return r(),()=>{a()}}},[e,o]),D("portal","custom-controls",bo,{store:n,children:t},[o]),ds(cs,{children:[e.items.map(r=>r.type!=="Image"||!s[r.annotationId]?null:pe(Ie,{image:r,id:r.annotationId},r.id)),e.items.map((r,a)=>r.type!=="Text"||!s[r.annotationId]?null:pe(at,{strategy:{type:"textual-content",items:[r]}},a)),e.items.map((r,a)=>r.type!=="Video"||!r.target.spatial?null:pe(Do,{target:r.target.spatial,children:pe("video",{ref:i(r.annotationId),src:r.url,style:{height:"100%",width:"100%",opacity:s[r.annotationId]?1:0}})},a)),e.items.map((r,a)=>r.type!=="Sound"?null:pe(Do,{children:pe("audio",{ref:i(r.annotationId),src:r.url})},a)),e.highlights.map(({annotation:r})=>s[r.id]?pe(Re,{id:r.id,ignoreTargetId:!0,style:{outline:"3px solid red"},className:"image-service-annotation"},r.id):null)]})}import{jsx as ms}from"react/jsx-runtime";function Fo(){let{strategy:e}=V(),{renderComplexTimelineControls:t}=$();return e.type!=="complex-timeline"?null:ms($o,{strategy:e,children:t?t(e):null})}import{jsx as ps}from"react/jsx-runtime";function st({style:e}){let t=A();return!t||!t.height||!t.width?null:ps("box",{interactive:!1,target:{x:0,y:0,width:Number(t.width),height:Number(t.height)},style:e})}import{jsx as fs}from"react/jsx-runtime";function Wo({backgroundStyle:e,alwaysShowBackground:t}){let{strategy:n}=V();return n.type!=="empty"&&!t?null:fs(st,{style:e})}import{createContext as gs,useContext as hs}from"react";var fe=gs(null);function lt(){return hs(fe)}import{Fragment as vs,jsx as ys,jsxs as Ss}from"react/jsx-runtime";function Uo({isStatic:e=!1,enableSizes:t=!1,enableAnnotations:n=!0,onClickPaintingAnnotation:o,children:s}){let{strategy:i}=V(),{renderViewerControls:r,viewControlsDeps:a}=$(),l=A(),u=lt(),g=Pe({maxWidth:256,maxHeight:256});return D(u&&i.type==="images"&&r?"overlay":"none",`canvas-portal-controls-${l?.id}`,fe.Provider,r?{value:u||null,children:r(i)}:{},[l,u,i,...a||[]]),i.type!=="images"?null:Ss(vs,{children:[i.images.map((c,d)=>ys(Ie,{isStatic:e,image:c,id:c.id,thumbnail:d===0?g:void 0,selector:c.selector,enableSizes:t,enableAnnotations:n,onClick:o?p=>{o(c.annotationId,c,p)}:void 0},c.id+d)),s]})}import{Fragment as bs,jsx as xs,jsxs as Cs}from"react/jsx-runtime";function _o({onClickPaintingAnnotation:e,children:t}){let{strategy:n}=V(),{renderViewerControls:o,viewControlsDeps:s}=$(),i=lt(),r=A();return D(i&&n.type==="textual-content"&&o?"overlay":"none",`canvas-portal-controls-${r?.id}`,fe.Provider,o?{value:i||null,children:o(n)}:{},[r,i,n,...s||[]]),n.type!=="textual-content"?null:Cs(bs,{children:[xs(at,{strategy:n,onClickPaintingAnnotation:e}),t]})}import{jsx as jo,jsxs as Rs}from"react/jsx-runtime";function Qt({element:e,media:t,startTime:n,playPause:o,poster:s}){let i="div",r=n?`${t.url}#t=${n}`:t.url;return Rs(i,{className:"video-container",part:"video-container",onClick:o,children:[jo("style",{children:`
15
+ `}),qt("div",{className:"model-container",children:qt("model-viewer",{"interaction-prompt":"none",style:{width:"100%",height:"100%"},"camera-controls":"","ar-status":"not-presenting",src:e.id})})]})}function Je({model:e,name:t}){return D("overlay",`model-${t}`,Ft,{model:e},[e]),null}import{jsx as xa}from"react/jsx-runtime";function io(){let{strategy:e}=V();return e.type!=="3d-model"?null:xa(Je,{model:e.model})}import{createContext as ba,useContext as Ca}from"react";var et=ba(null);et.displayName="Controls";function F(){let e=Ca(et);if(!e)throw new Error("useStrategy must be used within a StrategyProvider");return e}import{Fragment as Ra,jsx as tt,jsxs as Aa}from"react/jsx-runtime";function ao(){let{strategy:e}=V(),{renderViewerControls:t,viewControlsDeps:n}=F(),o=A(),s=o?.accompanyingCanvas,i=o?.placeholderCanvas;return Aa(Ra,{children:[e.type==="media"&&e.media.type==="Sound"&&s?tt(ee,{canvas:s.id,children:tt(de,{renderViewerControls:t,viewControlsDeps:n})}):null,e.type==="media"&&e.media.type==="Sound"&&i&&!s?tt(ee,{canvas:i.id,children:tt(de,{renderViewerControls:t,viewControlsDeps:n})}):null]})}import{createContext as Ma,useContext as ka,useMemo as Ea}from"react";import{useCallback as lo,useLayoutEffect as wa,useMemo as Ta,useRef as Ia}from"react";import{entityActions as $t}from"@iiif/helpers/vault/actions";import{useMemo as Pa}from"react";function so(){let t=M().getStore();return Pa(()=>n=>t.dispatch(n),[t])}function uo(e){return typeof e!="string"&&e&&e.bindToVault}function co(){let e=M(),t=Ia([]),n=so(),o=Ta(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);wa(()=>{let a={id:o,type:"AnnotationPage",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],rendering:[],service:[]};n($t.importEntities({entities:{AnnotationPage:{[a.id]:a}}}))},[o]);let s=k(a=>o&&a.iiif.entities.AnnotationPage[o]||null,[o]),i=lo((a,l)=>{if(o){if(uo(a)){let c=a;c.__vault||c.bindToVault(e),a=typeof c.source=="string"?c.source:c.source.id,t.current[a]=c}else typeof a!="string"&&(a=a.id);let u=e.get({id:o,type:"AnnotationPage"}),p=e.get({id:a,type:"Annotation"});u&&p&&(u.items.find(c=>c.id===p.id)||n($t.addReference({id:o,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"},index:l})))}},[o]),r=lo(a=>{o&&(uo(a)?a=typeof a.source=="string"?a.source:a.source.id:typeof a!="string"&&(a=a.id),t.current[a]&&t.current[a].beforeRemove(),e.get({id:o,type:"AnnotationPage"})&&n($t.removeReference({id:o,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"}})))},[o]);return[s,{addAnnotation:i,removeAnnotation:r}]}import{jsx as Va}from"react/jsx-runtime";var mo=Ma(null);function po(){let e=ka(mo);return[e.fullPage,{addAnnotation:e.addAnnotation,removeAnnotation:e.removeAnnotation}]}function fo({children:e}){let[t,{addAnnotation:n,removeAnnotation:o}]=co();return Va(mo.Provider,{value:Ea(()=>({fullPage:t,addAnnotation:n,removeAnnotation:o}),[t]),children:e})}import{Fragment as Na,jsx as go,jsxs as La}from"react/jsx-runtime";function ho({children:e}){let{strategy:t}=V(),[n]=po();return t.type!=="images"?null:La(Na,{children:[n?go(ue,{page:n}):null,t.annotations&&t.annotations.pages?t.annotations.pages.map(o=>go(ue,{page:o},o.id)):null,e]})}import{useEffect as qa,useMemo as Fa,useRef as $a,useState as Wa}from"react";import{useEffect as za}from"react";var yo=(e,t=[])=>{let n=M();za(()=>{e(n)},[n,...t])};import Oa,{useContext as Ba}from"react";import{ImageServiceLoader as Ha}from"@iiif/helpers/image-service";var Da=Oa.createContext(new Ha);function vo(){return Ba(Da)}import{createThumbnailHelper as Ua}from"@iiif/helpers/thumbnail";function Pe(e,t,{canvasId:n,manifestId:o}={}){let s=M(),i=vo(),r=Fa(()=>Ua(s,{imageServiceLoader:i}),[s,i]),[a,l]=Wa(),u=B(o?{id:o}:void 0),p=A(n?{id:n}:void 0),c=p||u,d=$a(!1);if(qa(()=>(d.current=!1,()=>{d.current=!0}),[]),!c)throw new Error("Must be called under a manifest or canvas context.");return yo(f=>{r.getBestThumbnailAtSize(c,e,t).then(y=>{y.best&&!d.current&&l(y.best)})},[c]),a}import{jsx as So}from"react/jsx-runtime";function we({x:e=0,y:t=0}){let n=A(),o=Pe({maxWidth:256,maxHeight:256});return!n||!o||o.type!=="fixed"?null:So("world-object",{height:n.height,width:n.width,x:e,y:t,children:So("world-image",{uri:o.id,target:{x:0,y:0,width:n.width,height:n.height},display:o.width&&o.height?{width:o.width,height:o.height}:void 0,crop:void 0})})}import{jsx as _a,jsxs as ja}from"react/jsx-runtime";function xo({as:e}){let{strategy:t}=V(),{renderMediaControls:n,mediaControlsDeps:o}=F();return t.type!=="media"||t.media.type!=="Sound"?null:ja(Ze,{media:t.media,mediaControlsDeps:o,audioCopmonent:e,children:[_a(we,{}),n?n(t):null]},t.media.url)}import{HTMLPortal as Do}from"@atlas-viewer/atlas";import{useLayoutEffect as ds,useMemo as ms}from"react";import{useStore as qo}from"zustand";import{createContext as Ka,useContext as Ya}from"react";import{useStore as Ga}from"zustand";import{jsx as Qa}from"react/jsx-runtime";var Wt=Ka(null);Wt.displayName="ComplexTimeline";function bo({children:e,store:t}){return Qa(Wt.Provider,{value:t,children:e})}function yf(e){let t=Ya(Wt);if(!t)throw new Error("useComplexTimeline must be used within a ComplexTimelineProvider");return Ga(t,e)}import Xa from"mitt";import{createStore as Za}from"zustand/vanilla";function Co({currentKeyFrameIndex:e,keyframes:t,targetTime:n,currentTime:o}){if(o<=n){let s=t.findIndex(a=>a.time>n);if(s===-1)return[e,[]];let i={},r=t.slice(e,s);for(let a of r)a.type==="enter"&&(i[a.id]=a),a.type==="exit"&&(i[a.id]?delete i[a.id]:i[a.id]=a);return[s,Object.values(i)]}return[e,[]]}function Ro({complexTimeline:e,startTime:t=0}){let n=Xa(),o={},s={progress:null,currentTime:null},i=0,r=null,a=0,l=null;function u(){let m=x.getState().visibleElements,h=o,S=[],b=Object.keys(h);for(let C of b){let R=h[C],P=m[C];R&&P&&S.push(R)}return S}function p(){return Object.keys(o).map(m=>o[m])}function c(v){s.currentTime&&(s.currentTime.innerHTML=Ot(v),s.progress&&(s.progress.style.width=`${v/e.duration*100}%`))}let d=()=>{let v=x.getState(),m=v.currentPrime;if(!m)return;let h=o,S=v.visibleElements,b=Object.keys(h);for(let C of b){let R=h[C],P=S[C];if(R&&C!==m.id&&P){let L=a-P.time*1e3;Math.abs(a-P.time*1e3-R.currentTime*1e3)>300&&(R.currentTime=L/1e3)}}},f=(v=0)=>{let m=v-i,h=x.getState();if(h.isPlaying){let S=h.currentPrime;if(S){let P=o[S.id];P&&(P.paused?a+=m:a=(S.time+P.currentTime)*1e3)}else a+=m;let b=a/1e3;if(b>h.duration){x.getState().setTime(0),x.setState({isPlaying:!1}),y(),c(0);return}c(b);let[C,R]=Co({currentTime:b,currentKeyFrameIndex:h.nextKeyframeIndex,keyframes:h.complexTimeline.keyframes,targetTime:b});R.length&&h.applyKeyframes(C,R)}i=v,r=requestAnimationFrame(f)},y=()=>{r&&cancelAnimationFrame(r)},g=(v,m)=>{},x=Za((v,m)=>({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:()=>{m().clockRunning||(f(),l=setInterval(d,500)),v({clockRunning:!0,clockStartRequests:m().clockStartRequests+1})},applyKeyframes(h,S){let b=m(),C={...b.visibleElements},R=b.currentPrime;for(let P of S)P.type==="enter"&&(C[P.id]=P,n.emit("complex-timeline.enter",{id:P.id})),P.type==="exit"&&(C[P.id]=null,n.emit("complex-timeline.exit",{id:P.id})),P.isPrime&&(R=P);v({nextKeyframeIndex:h,visibleElements:C,currentPrime:R})},stopClock:()=>{let h=m().clockStartRequests;if(h!==0){if(h===1){y(),l&&clearInterval(l),v({clockRunning:!1,clockStartRequests:0});return}v({clockStartRequests:h-1})}},setElement:(h,S)=>{o[h]=S;let b=Object.keys(o),C=m().complexTimeline;g(S,h),C.items.filter(P=>P.type!=="Image"&&P.type!=="Text").every(P=>b.includes(P.annotationId))&&!m().isReady&&(n.emit("complex-timeline.ready",{complexTimeline:C}),v({isReady:!0}))},removeElement:h=>{delete o[h]},mute(){for(let h of p())h.muted=!0;v({isMuted:!0})},unmute(){for(let h of p())h.muted=!1;v({isMuted:!1})},play(){if(!m().isPlaying){for(let S of u())S.play();v({isPlaying:!0})}},pause(){if(m().isPlaying){for(let S of u())S.pause();v({isPlaying:!1})}},playPause(){let h=m();h.isPlaying?h.pause():h.play()},setDurationPercent(h){let b=m().duration*h;m().setTime(b)},setTime(h){let S=m(),b=a/1e3,C=typeof h=="function"?h(b):h,R=S.nextKeyframeIndex;if(b>C){v({visibleElements:{},currentPrime:null});let I=Object.keys(S.visibleElements);for(let E of I)n.emit("complex-timeline.exit",{id:E});b=0,R=0}let[P,L]=Co({currentTime:b,currentKeyFrameIndex:R,keyframes:S.complexTimeline.keyframes,targetTime:C});S.applyKeyframes(P,L),a=C*1e3;let T=x.getState().visibleElements,z=o,w=Object.keys(T);for(let I of w){let E=T[I];if(E){let Ee=z[I];Ee&&(Ee.currentTime=(a-E.time*1e3)/1e3)}}c(C)},setVolume(h){for(let S of p())S.volume=Math.min(1,Math.max(0,h/100));v({volume:h})},toggleMute(){let h=m();h.isMuted?(h.unmute(),v({isMuted:!1})):(h.mute(),v({isMuted:!0}))},clearProgressElement(){s.progress=null},setProgressElement(h){s.progress=h},setCurrentTimeElement(h){s.currentTime=h},clearCurrentTimeElement(){s.currentTime=null}}));return n.on("complex-timeline.enter",v=>{let m=x.getState(),h=v.id,S=o[h];S&&m.isPlaying&&S.play()}),n.on("complex-timeline.exit",v=>{let m=x.getState(),h=v.id,S=o[h];S&&(S.currentTime=0,S.pause())}),x.getState().setTime(t),{store:x,emitter:n}}import{Fragment as Oo,useMemo as Bo}from"react";import{HTMLPortal as as}from"@atlas-viewer/atlas";import{getId as ss}from"@iiif/parser/image-3";import Ja,{useContext as es}from"react";import{imageServices as ts}from"@iiif/helpers/image-service";import{useStore as nt}from"zustand";var Ao=Ja.createContext(ts.store);Ao.displayName="ImageServicesHelper";function ot(){return es(Ao)}function Po(e){let t=ot();return nt(t,({loaded:n})=>n[e])}function rt(){let e=ot();return nt(e,({loadServiceSync:t})=>t)}function wo(){let e=ot();return nt(e,({loaded:t})=>t)}function If(){let e=ot();return nt(e,({loadService:t})=>t)}import Te,{useMemo as Ut}from"react";import{jsx as X}from"react/jsx-runtime";var Io=Te.createContext("en"),Mo=Te.createContext({}),ko=Te.createContext(null);function Vf(e){return X(Mo.Provider,{value:e.translations,children:e.children})}function Nf(e){return X(Io.Provider,{value:e.language,children:e.children})}function Lf(e){return X(ko.Provider,{value:e.convert,children:e.children})}function Eo(){return Te.useContext(ko)}function _t(){return Te.useContext(Io)}function Vo(){return Te.useContext(Mo)}function To(e){return e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):e}function ns({as:e,language:t,children:n,viewingDirection:o,...s}){let i=_t();return Ut(()=>To(i)===To(t),[i,t])?e?X(e,{...s,children:n}):X("span",{...s,children:n}):e?X(e,{...s,lang:t,dir:o,children:n}):X("span",{...s,lang:t,dir:o,children:n})}function No(e,t,n){if(t.length===0)return;if(t.length===1)return t[0];if(t.indexOf(e)!==-1)return e;let o=e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):null;if(o&&t.indexOf(o)!==-1)return o;for(let s of n)if(t.indexOf(s)!==-1)return s;return t.indexOf("none")!==-1?"none":t.indexOf("@none")!==-1?"@none":t[0]}var os=(e,t=[])=>{let n=_t();return Ut(()=>{let o=e();return No(n,o,[])},[n,...t])};function me(e,t,n,o){return t?n?n(e[t]||t,o||"none"):e[t]||t:""}function rs(e,t,n=`
16
+ `,o={}){let s=Eo(),i=os(()=>Object.keys(e||{}),[e]);return[Ut(()=>{if(!e)return me(o,t,s)||"";if(typeof e=="string")return me(o,e,s);let r=i?e[i]:void 0;return r?typeof r=="string"?r:r.map(a=>me(o,a,s,i)).join(n):""},[i,t,e]),i]}function zf(){let e=_t(),t=Vo(),n=Eo();return function(s,i="",r=`
17
+ `,a=t){let l=Object.keys(s||{}),u=No(e,l,[]);if(!s)return me(a,i,n)||"";if(typeof s=="string")return me(a,s,n);let p=u?s[u]:void 0;return p?typeof p=="string"?me(a,p,n,u):p.map(c=>me(a,c,n,u)).join(typeof r<"u"?r:`
18
+ `):""}}function Be({as:e,defaultText:t,enableDangerouslySetInnerHTML:n,children:o,separator:s,...i}){let r=Vo(),[a,l]=rs(o,t,s,r);return l?X(ns,{...i,as:e,language:l,title:n?void 0:a,dangerouslySetInnerHTML:n?{__html:a}:void 0,children:n?void 0:a}):e?X(e,{...i,children:a}):X("span",{...i,title:n?void 0:a,dangerouslySetInnerHTML:n?{__html:a}:void 0,children:n?void 0:a})}import{isImageServiceLevel as Lo}from"@iiif/parser/image-3";import{useMemo as jt}from"react";import{jsx as it,jsxs as is}from"react/jsx-runtime";var Kt=e=>{let t=e.format||"jpg",n=e.width/(e.crop?.width||e.tiles.width),o=e.tiles.imageService.sizes||[],s=e.enableThumbnail,i=e.enableSizes,r=jt(()=>{let u=e.tiles.imageService.id||e.tiles.imageService["@id"];return u?.endsWith("/info.json")?u.slice(0,-1*10):u},[e.tiles.imageService.id,e.tiles.imageService["@id"]]),a=jt(()=>{let u=e.tiles.imageService.tiles||[];if(!u.length){let p=e.width,c=[1],d=1;for(;2**d<p;)d=d*2,c.push(d);return(e.tiles.imageService.maxArea||e.tiles.imageService.maxWidth||e.tiles.imageService.maxHeight)&&Lo(2,e.tiles.imageService)?[{width:256,height:256,scaleFactors:c}]:Lo(2,e.tiles.imageService)?[{width:256,height:256,scaleFactors:c}]:[]}return u},[e.tiles.imageService,e.width]),l=jt(()=>{let u=e.tiles.imageService;return(u?u["@context"]?Array.isArray(u["@context"])?u["@context"]:[u["@context"]]:[]:[]).indexOf("http://iiif.io/api/image/3/context.json")!==-1},[e.tiles.imageService.id,e.tiles.imageService]);return it("world-object",{rotation:e.rotation,scale:n,height:e.crop?.height||e.tiles.height,width:e.crop?.width||e.tiles.width,x:e.x,y:e.y,onClick:e.onClick,children:is("composite-image",{id:e.tiles.imageService.id,width:e.crop?.width||e.tiles.width,height:e.crop?.height||e.tiles.height,crop:e.crop,renderOptions:e.renderOptions,children:[s&&e.tiles.thumbnail?it("world-image",{priority:!0,uri:e.tiles.thumbnail.id,target:{width:e.tiles.width,height:e.tiles.height},display:{width:e.tiles.thumbnail.width,height:e.tiles.thumbnail.height},crop:e.crop}):null,i&&o.map((u,p)=>it("world-image",{uri:`${r}/full/${u.width},${l?u.height:""}/0/default.${t}`,target:{width:e.tiles.width,height:e.tiles.height},display:{width:u.width,height:u.height},crop:e.crop},p)),a.map(u=>(u.scaleFactors||[]).map(p=>it("tiled-image",{uri:e.tiles.imageService.id,display:{width:e.tiles.width,height:e.tiles.height},format:t,tile:u,scaleFactor:p,crop:e.crop,version3:l},`${e.tiles.imageService.id}-tile-${p}`)))]},e.tiles.imageService.id)},e.tiles.imageService.id)};import{jsx as ne,jsxs as us}from"react/jsx-runtime";function ls({resource:e,heading:t,note:n,extra:o}){return o?ne(as,{target:{x:0,y:0,width:o.target?.spatial.width,height:o.target?.spatial.height},backgroundColor:"#333",relative:!0,children:ne("div",{style:{display:"flex",alignContent:"center",justifyContent:"center",alignItems:"center",height:"100%",width:"100%",background:"#444",color:"#BBB"},children:us("div",{children:[ne(Be,{children:t||"Not authorised"}),n&&ne("p",{children:ne(Be,{children:n})}),ne("p",{children:e.id||e["@id"]||"unknown"})]})})}):null}function zo({image:e,thumbnail:t,crop:n,enableSizes:o,enableThumbnail:s,renderOptions:i,rotation:r}){let a=En(),l=ss(e.service),u=Po(l),p=rt(),c=u?.service;p(e.service,e);let d=c&&u?.status==="done",f=(c?.preferredFormats||[])[0],y=t&&t.type==="fixed"&&t.id&&!t.id.includes("/full/full/")&&!t.id.includes("/max/")?t:void 0;if(d===!1)return null;if(!a){let g=e.service,x=g.width||e.width||0,v=g.height||e.height||0,m=0,h=0,S=e.target?.spatial.width||x,b=e.target?.spatial.height||v,C=S,R=b;return(r===90||r===270)&&([S,b]=[b,S],m=(C-S)/2,h=(R-b)/2),ne(Kt,{enableThumbnail:s,renderOptions:i,rotation:r,tiles:{id:g.id||g["@id"]||"unknown",height:v,width:x,imageService:g,thumbnail:y},enableSizes:o,x:m,y:h,format:f,width:S,height:b,crop:n})}return ne(Vn,{resource:e.service,errorComponent:ls,extra:e,children:g=>{let x=g.width||e.width||0,v=g.height||e.height||0,m=0,h=0,S=e.target?.spatial.width||x,b=e.target?.spatial.height||v,C=S,R=b;return(r===90||r===270)&&([S,b]=[b,S],m=(C-S)/2,h=(R-b)/2),ne(Kt,{enableThumbnail:s,renderOptions:i,tiles:{id:g.id||g["@id"]||"unknown",height:v,width:x,imageService:g,thumbnail:y},rotation:r,format:f,enableSizes:o,x:m,y:h,width:S,height:b,crop:n})}},e.id)}import{jsx as Yt,jsxs as Gt}from"react/jsx-runtime";function Ie({id:e,image:t,thumbnail:n,isStatic:o,x:s=0,y:i=0,children:r,selector:a,onClick:l,enableSizes:u,enableAnnotations:p}){let c=Bo(()=>{if(!(!a||a.spatial.x===0&&a.spatial.y===0))return a.spatial},[a]),d=Bo(()=>{if(typeof t.rotation<"u")return t.rotation;if(!t.annotation)return 0;let S=Array.isArray(t.annotation.body)?t.annotation.body?.[0]:t.annotation.body;if(S&&S.selector?.type==="ImageApiSelector")return Number(S.selector.rotation)},[t]),f=!!t.service,y=s+t.target.spatial.x,g=i+t.target.spatial.y,x=t.target.spatial.width,v=t.target.spatial.height,m=t.target.spatial.width,h=t.target.spatial.height;return(d===90||d===270)&&([m,h]=[h,m],f||([x,v]=[v,x],y+=(t.target.spatial.width-x)/2,g+=(t.target.spatial.height-v)/2)),Gt("world-object",{x:y,y:g,width:x,height:v,onClick:l,rotation:f?0:d,children:[t.service?Gt(Oo,{children:[Yt(zo,{image:t,thumbnail:n,crop:c,enableSizes:u,rotation:d}),r]},"service"):Gt(Oo,{children:[Yt("world-image",{onClick:l,uri:t.id,target:{x:0,y:0,width:m,height:h},display:m&&h?{width:m,height:h}:void 0,crop:c}),r]},"no-service"),p&&t.annotationPages?t.annotationPages.map(S=>Yt(ue,{page:S,className:"image-service-annotation",ignoreTargetId:!0},S.id)):null]},e+(f?"server":"no-service"))}import{HTMLPortal as cs}from"@atlas-viewer/atlas";import{Fragment as Ho,jsx as He}from"react/jsx-runtime";function at({strategy:e,onClickPaintingAnnotation:t}){return He(Ho,{children:e.items.map((n,o)=>He(Ho,{children:He(cs,{onClick:t?s=>{s.stopPropagation(),t(n.annotationId,n,s)}:void 0,target:n.target?.spatial||void 0,children:He("div",{"data-textual-content":!0,children:He(Be,{enableDangerouslySetInnerHTML:!0,children:n.text})})},o)}))})}import{Fragment as ps,jsx as pe,jsxs as fs}from"react/jsx-runtime";function Fo({strategy:e,children:t}){let{store:n}=ms(()=>Ro({complexTimeline:e}),[e]),o=qo(n,r=>r.isReady),s=qo(n,r=>r.visibleElements);function i(r){return a=>{a&&n.getState().setElement(r,a)}}return ds(()=>{if(o){let{startClock:r,stopClock:a}=n.getState();return r(),()=>{a()}}},[e,o]),D("portal","custom-controls",bo,{store:n,children:t},[o]),fs(ps,{children:[e.items.map(r=>r.type!=="Image"||!s[r.annotationId]?null:pe(Ie,{image:r,id:r.annotationId},r.id)),e.items.map((r,a)=>r.type!=="Text"||!s[r.annotationId]?null:pe(at,{strategy:{type:"textual-content",items:[r]}},a)),e.items.map((r,a)=>r.type!=="Video"||!r.target.spatial?null:pe(Do,{target:r.target.spatial,children:pe("video",{ref:i(r.annotationId),src:r.url,style:{height:"100%",width:"100%",opacity:s[r.annotationId]?1:0}})},a)),e.items.map((r,a)=>r.type!=="Sound"?null:pe(Do,{children:pe("audio",{ref:i(r.annotationId),src:r.url})},a)),e.highlights.map(({annotation:r})=>s[r.id]?pe(Re,{id:r.id,ignoreTargetId:!0,style:{outline:"3px solid red"},className:"image-service-annotation"},r.id):null)]})}import{jsx as gs}from"react/jsx-runtime";function $o(){let{strategy:e}=V(),{renderComplexTimelineControls:t}=F();return e.type!=="complex-timeline"?null:gs(Fo,{strategy:e,children:t?t(e):null})}import{jsx as hs}from"react/jsx-runtime";function st({style:e}){let t=A();return!t||!t.height||!t.width?null:hs("box",{interactive:!1,target:{x:0,y:0,width:Number(t.width),height:Number(t.height)},style:e})}import{jsx as ys}from"react/jsx-runtime";function Wo({backgroundStyle:e,alwaysShowBackground:t}){let{strategy:n}=V();return n.type!=="empty"&&!t?null:ys(st,{style:e})}import{createContext as vs,useContext as Ss}from"react";var fe=vs(null);function lt(){return Ss(fe)}import{Fragment as bs,jsx as xs,jsxs as Cs}from"react/jsx-runtime";function Uo({isStatic:e=!1,enableSizes:t=!1,enableAnnotations:n=!0,onClickPaintingAnnotation:o,children:s}){let{strategy:i}=V(),{renderViewerControls:r,viewControlsDeps:a}=F(),l=A(),u=lt(),p=Pe({maxWidth:256,maxHeight:256});return D(u&&i.type==="images"&&r?"overlay":"none",`canvas-portal-controls-${l?.id}`,fe.Provider,r?{value:u||null,children:r(i)}:{},[l,u,i,...a||[]]),i.type!=="images"?null:Cs(bs,{children:[i.images.map((c,d)=>xs(Ie,{isStatic:e,image:c,id:c.id,thumbnail:d===0?p:void 0,selector:c.selector,enableSizes:t,enableAnnotations:n,onClick:o?f=>{o(c.annotationId,c,f)}:void 0},c.id+d)),s]})}import{Fragment as As,jsx as Rs,jsxs as Ps}from"react/jsx-runtime";function _o({onClickPaintingAnnotation:e,children:t}){let{strategy:n}=V(),{renderViewerControls:o,viewControlsDeps:s}=F(),i=lt(),r=A();return D(i&&n.type==="textual-content"&&o?"overlay":"none",`canvas-portal-controls-${r?.id}`,fe.Provider,o?{value:i||null,children:o(n)}:{},[r,i,n,...s||[]]),n.type!=="textual-content"?null:Ps(As,{children:[Rs(at,{strategy:n,onClickPaintingAnnotation:e}),t]})}import{jsx as jo,jsxs as ws}from"react/jsx-runtime";function Qt({element:e,media:t,startTime:n,playPause:o,poster:s}){let i="div",r=n?`${t.url}#t=${n}`:t.url;return ws(i,{className:"video-container",part:"video-container",onClick:o,children:[jo("style",{children:`
19
19
  .video-container {
20
20
  position: absolute;
21
21
  top: 0;
@@ -28,7 +28,7 @@ import{c as ln,l as un}from"./chunk-P7XHGETS.js";import{forwardRef as Vr,useImpe
28
28
  justify-content: center;
29
29
  pointer-events: visible;
30
30
  }
31
- `}),jo("video",{poster:s,ref:e,src:r,style:{width:"100%",objectFit:"contain"}})]})}function ut({media:e,mediaControlsDeps:t,children:n,videoComponent:o=Qt,captions:s}){let i=A(),r=Qe(),a=i&&i.placeholderCanvas&&i.placeholderCanvas.id||void 0,l=Pe({},!1,{canvasId:a}),[{element:u,currentTime:g,progress:c},d,p]=Ae({duration:e.duration});return D("overlay","video-element",o,{element:u,media:e,playPause:p.playPause,poster:l?.id,canvas:i,startTime:r?r.startTime:null,captions:s},[l]),D("portal","custom-controls",Ge,{state:d,actions:p,currentTime:g,progress:c,element:u,children:n},[g,d,e,...t||[]]),null}import{jsx as As,jsxs as Ps}from"react/jsx-runtime";function Ko({as:e}){let{strategy:t}=V(),{renderMediaControls:n,mediaControlsDeps:o}=$();return t.type!=="media"||t.media.type!=="Video"?null:Ps(ut,{captions:t.captions,media:t.media,mediaControlsDeps:o,videoComponent:e,children:[As(we,{}),n?n(t):null]},t.media.url)}import{useRef as ws}from"react";import{jsx as Yo,jsxs as Is}from"react/jsx-runtime";function Ts({element:e,media:t,playPause:n}){let o=ws(null);return t.youTubeId?Is("div",{className:"video-container",part:"video-container",onClick:n,children:[Yo("style",{children:`
31
+ `}),jo("video",{poster:s,ref:e,src:r,style:{width:"100%",objectFit:"contain"}})]})}function ut({media:e,mediaControlsDeps:t,children:n,videoComponent:o=Qt,captions:s}){let i=A(),r=Qe(),a=i&&i.placeholderCanvas&&i.placeholderCanvas.id||void 0,l=Pe({},!1,{canvasId:a}),[{element:u,currentTime:p,progress:c},d,f]=Ae({duration:e.duration});return D("overlay","video-element",o,{element:u,media:e,playPause:f.playPause,poster:l?.id,canvas:i,startTime:r?r.startTime:null,captions:s},[l]),D("portal","custom-controls",Ge,{state:d,actions:f,currentTime:p,progress:c,element:u,children:n},[p,d,e,...t||[]]),null}import{jsx as Ts,jsxs as Is}from"react/jsx-runtime";function Ko({as:e}){let{strategy:t}=V(),{renderMediaControls:n,mediaControlsDeps:o}=F();return t.type!=="media"||t.media.type!=="Video"?null:Is(ut,{captions:t.captions,media:t.media,mediaControlsDeps:o,videoComponent:e,children:[Ts(we,{}),n?n(t):null]},t.media.url)}import{useRef as Ms}from"react";import{jsx as Yo,jsxs as Es}from"react/jsx-runtime";function ks({element:e,media:t,playPause:n}){let o=Ms(null);return t.youTubeId?Es("div",{className:"video-container",part:"video-container",onClick:n,children:[Yo("style",{children:`
32
32
  .video-container {
33
33
  position: absolute;
34
34
  top: 0;
@@ -46,4 +46,4 @@ import{c as ln,l as un}from"./chunk-P7XHGETS.js";import{forwardRef as Vr,useImpe
46
46
  width: 100%;
47
47
  object-fit: contain;
48
48
  }
49
- `}),Yo("iframe",{className:"video-yt",ref:o,src:`https://www.youtube.com/embed/${t.youTubeId}?enablejsapi=1&origin=${window.location.host}`,referrerPolicy:"no-referrer",sandbox:"allow-scripts allow-same-origin allow-presentation"})]}):null}function Go({media:e,mediaControlsDeps:t,children:n}){let[{element:o,currentTime:s,progress:i},r,a]=Ae({duration:e.duration});return D("overlay","video-element",Ts,{element:o,media:e,playPause:a.playPause}),null}import{jsx as Ms,jsxs as ks}from"react/jsx-runtime";function Qo(){let{strategy:e}=V(),{renderMediaControls:t,mediaControlsDeps:n}=$();return e.type!=="media"||e.media.type!=="VideoYouTube"?null:ks(Go,{media:e.media,mediaControlsDeps:n,children:[Ms(we,{}),t?t(e):null]})}import{startTransition as sl,useMemo as ll}from"react";import{useStore as J}from"zustand";import{HTMLPortal as Ls,useAtlas as zs}from"@atlas-viewer/atlas";import{useCallback as Jt,useEffect as en}from"react";import{createSvgHelpers as Es}from"polygon-editor";import{useEffect as Vs,useRef as Z,useState as Zo}from"react";import{useStore as Xt}from"zustand";function Xo(e){let t=q(),n=Xt(t,i=>i.polygons),o=Xt(t,i=>i.polygonState),s=Xt(t,i=>i.polygon);return Dn("atlas.polygon-render",({state:i,slowState:r,dt:a})=>{e(i,r,a)}),{currentShape:s,state:o,helper:n}}import{Fragment as Zt,jsx as N,jsxs as Me}from"react/jsx-runtime";var oe=Es(),Ns={shapeFill:"#ffffff33",shapeStroke:"#000",lineStroke:"#000",ghostLineStroke:"#0F0",activeLineStroke:"#4D7EEA",boundingBoxDottedStroke:"#0007",boundingBoxStroke:"#fffA",controlFill:"#fff"};function Jo(e){let{image:t}=e,n={...Ns,...e.theme||{}},o=Z(),s=Z(),i=Z(),r=Z(),a=Z(),l=Z(),u=Z(),g=Z(),c=Z(),d=Z(),[p,y]=Zo(null),[f,x]=Zo(!1),{helper:v,state:m,currentShape:h}=Xo((T,z)=>{if(T.closestLineIndex,oe.updateTransitionBoundingBox(i.current,T,z),oe.updateBoundingBoxPolygon(o.current,T,z),oe.updateBoundingBoxPolygon(s.current,T,z),oe.updateTransitionShape(u.current,T,z),oe.updateClosestLinePointTransform(a.current,T,z),oe.updateSelectBox(r.current,T,z),oe.updatePointLine(g.current,T,z),oe.updateDrawPreview(l.current,T,z,3),oe.updateLineBox(c.current,T),y(T.transitionDirection),x(T.transitionRotate),T.closestLineIndex!==-1&&d.current){let w=T.polygon,I=w.points[T.closestLineIndex],E=w.points[(T.closestLineIndex+1)%w.points.length];I&&E&&d.current.setAttribute("points",`${I[0]},${I[1]} ${E[0]},${E[1]}`)}});Vs(()=>{let T=()=>{v.modifiers.reset()};return document.addEventListener("mouseleave",T),()=>{document.removeEventListener("mouseleave",T)}},[]);let S=Me(Zt,{children:[Me("marker",{id:"dot",viewBox:"0 0 10 10",refX:"5",refY:"5",markerWidth:"5",markerHeight:"5",children:[N("circle",{cx:"5",cy:"5",r:"5",fill:n.lineStroke,className:"marker"}),N("circle",{cx:"5",cy:"5",r:"3",fill:n.controlFill})]}),N("marker",{id:"newdot",viewBox:"0 0 10 10",refX:"5",refY:"5",markerWidth:"5",markerHeight:"5",children:N("circle",{cx:"5",cy:"5",r:"5",fill:n.activeLineStroke,className:"marker"})}),Me("marker",{id:"selected",viewBox:"0 0 10 10",refX:"5",refY:"5",markerWidth:"5",markerHeight:"5",children:[N("circle",{cx:"5",cy:"5",r:"5",fill:n.lineStroke}),N("circle",{cx:"5",cy:"5",r:"3",fill:n.activeLineStroke})]}),Me("marker",{id:"resizer",viewBox:"0 0 10 10",refX:"5",refY:"5",markerWidth:"6",markerHeight:"6",children:[N("rect",{width:"10",height:"10",fill:n.lineStroke}),N("rect",{x:"1",y:"1",width:"8",height:"8",fill:n.controlFill})]})]}),b=h?h.open?"polyline":"polygon":null,C=!m.showBoundingBox&&m.closestPoint!==null&&m.actionIntentType==="select-point",R=m.actionIntentType==="add-open-point",P=m.transitionIntentType==="split-line",L=m.transitioning&&m.selectedStamp&&m.transitionIntentType==="stamp-shape",re=h&&b?Me(Zt,{children:[N(b,{fill:(!m.transitioning||m.transitionIntentType==="select-multiple-points")&&!h.open?n.shapeFill:"none",strokeWidth:L||m.showBoundingBox&&m.boxMode||m.transitioning&&m.transitionIntentType==="split-line"||m.transitioning&&m.transitionIntentType==="move-point"?0:2,stroke:n.shapeStroke,points:h.points.map(T=>T.join(",")).join(" "),vectorEffect:"non-scaling-stroke",markerStart:m.showBoundingBox?void 0:m.boxMode?"url(#resizer)":"url(#dot)",markerMid:m.showBoundingBox?void 0:m.boxMode?"url(#resizer)":"url(#dot)",markerEnd:m.showBoundingBox?void 0:m.boxMode?"url(#resizer)":"url(#dot)",style:{pointerEvents:"none"},opacity:m.transitioning&&m.transitionIntentType==="move-shape"?0:1}),m.currentTool==="lineBox"&&m.actionIntentType==="close-line-box"?N("polygon",{fill:n.shapeFill,ref:c,stroke:n.lineStroke,strokeWidth:2,vectorEffect:"non-scaling-stroke"}):null,m.transitionIntentType==="draw-shape"&&m.transitioning?N("polyline",{ref:l,fill:"none",stroke:n.activeLineStroke,strokeWidth:2,vectorEffect:"non-scaling-stroke"}):null,!(m.transitioning&&m.transitionIntentType==="move-point")&&!(m.transitioning&&m.transitionIntentType==="stamp-shape")&&!m.showBoundingBox&&m.selectedPoints&&m.selectedPoints.length?N("polyline",{strokeWidth:2,vectorEffect:"non-scaling-stroke",stroke:"transparent",markerStart:"url(#selected)",markerMid:"url(#selected)",markerEnd:"url(#selected)",fill:"transparent",points:h.points.filter((T,z)=>m.selectedPoints?.includes(z)).map(T=>T.join(",")).join(" "),opacity:m.transitioning&&m.transitionIntentType==="move-shape"?0:1}):null,C&&!m.transitioning&&m.closestPoint!==null&&h.points[m.closestPoint]?N("polyline",{strokeWidth:2,vectorEffect:"non-scaling-stroke",stroke:"transparent",markerStart:"url(#selected)",markerMid:"url(#selected)",markerEnd:"url(#selected)",fill:n.activeLineStroke,points:`${h.points[m.closestPoint][0]},${h.points[m.closestPoint][1]}`,opacity:m.transitioning&&m.transitionIntentType==="move-shape"?0:1}):null,!m.transitioning&&(m.actionIntentType==="add-open-point"||m.actionIntentType==="close-shape"||m.actionIntentType==="close-shape-line")?N("polyline",{stroke:n.activeLineStroke,ref:g,strokeWidth:m.actionIntentType==="add-open-point"?1:2,vectorEffect:"non-scaling-stroke"}):null,m.hasClosestLine&&!m.showBoundingBox&&!m.transitioning&&m.currentTool!=="box"&&m.transitionIntentType==="split-line"?N("g",{children:N("polyline",{ref:d,vectorEffect:"non-scaling-stroke",fill:"transparent",stroke:n.activeLineStroke,strokeWidth:3})}):null,m.hasClosestLine&&!m.showBoundingBox&&!m.transitioning&&m.currentTool!=="box"&&m.transitionIntentType==="split-line"?N("g",{ref:a,children:N("polyline",{markerStart:"url(#newdot)",points:"0,0 1,1",vectorEffect:"non-scaling-stroke",stroke:"transparent",fill:"transparent",strokeWidth:2})}):null,m.transitioning?N(b,{ref:u,fill:h.open?"none":n.shapeFill,stroke:m.transitionIntentType==="stamp-shape"?n.activeLineStroke:n.shapeStroke,vectorEffect:"non-scaling-stroke",strokeWidth:(h.open,2)}):null,m.transitioning&&m.transitionIntentType==="select-multiple-points"?N("rect",{ref:r,fill:"rgba(255, 255, 255, .3)",strokeWidth:1,stroke:"rgba(0,0,0,.2)",vectorEffect:"non-scaling-stroke"}):null,m.showBoundingBox&&!L?Me(Zt,{children:[N("polygon",{ref:o,strokeWidth:2,stroke:n.boundingBoxStroke,fill:"none",markerStart:"url(#resizer)",markerMid:"url(#resizer)",markerEnd:"url(#resizer)",vectorEffect:"non-scaling-stroke"}),N("polygon",{ref:s,strokeWidth:2,stroke:n.boundingBoxDottedStroke,fill:"none",strokeDasharray:"4 4",markerStart:"url(#resizer)",markerMid:"url(#resizer)",markerEnd:"url(#resizer)",vectorEffect:"non-scaling-stroke"})]}):null]}):null;return{currentTool:v.state.slowState.currentTool,setCurrentTool:v.tools.setTool,helper:v,currentShape:h,state:m,isAddingPoint:R,isSplitting:P,isStamping:L,isHoveringPoint:C,transitionDirection:p,transitionRotate:f,defs:S,editor:re}}import{jsx as De,jsxs as Os}from"react/jsx-runtime";function er(e){let t=zs(),{image:n}=e,{helper:o,defs:s,editor:i,state:r,transitionDirection:a,isSplitting:l,transitionRotate:u,isHoveringPoint:g,isAddingPoint:c}=Jo({image:e.image,theme:e.theme}),d=Jt(f=>{f.button!==2&&o.pointer([[~~f.atlas.x,~~f.atlas.y]])},[o]),p=Jt(f=>{f.button!==2&&o.pointerDown()},[o]),y=Jt(f=>{f.button!==2&&o.pointerUp()},[o]);return en(()=>{let f=x=>{o.key.up(x.key)};return document.addEventListener("keyup",f),()=>{document.removeEventListener("keyup",f)}},[o]),en(()=>{let f=x=>{x.target&&["INPUT","TEXTAREA"].includes(x.target.tagName)||x.target?.isContentEditable||document.activeElement&&(document.activeElement instanceof HTMLInputElement||document.activeElement instanceof HTMLTextAreaElement||document.activeElement.isContentEditable)||o.key.down(x.key)};return document.addEventListener("keydown",f),()=>{document.removeEventListener("keydown",f)}},[o]),en(()=>{let f=[];return a&&f.push(`atlas-cursor-${a}`),r.actionIntentType==="cut-line"&&r.modifiers?.Shift&&f.push("atlas-cursor-cut"),(g||r.transitionIntentType==="move-shape"||r.transitionIntentType==="move-point")&&f.push("atlas-cursor-move"),c&&f.push("atlas-cursor-crosshair"),l&&f.push("atlas-cursor-copy"),u&&f.push("atlas-cursor-rotate"),r.transitionIntentType==="draw-shape"&&f.push("atlas-cursor-draw"),t?.canvas&&t.canvas.classList.add(...f),()=>{t?.canvas&&t.canvas.classList.remove(...f)}},[t?.canvas,c,g,l,r.modifiers?.Shift,r.actionIntentType,r.transitionIntentType,a,u]),De("world-object",{height:n.height,width:n.width,onMouseMove:d,onMouseDown:p,onMouseUp:y,onMouseLeave:o.blur,children:De(Ls,{relative:!0,interactive:!1,children:De("div",{className:"absolute top-0 right-0 left-0 bottom-0",children:Os("svg",{width:"100%",height:"100%",viewBox:`0 0 ${n.width} ${n.height}`,tabIndex:-1,children:[De("title",{children:"Annotation Editor"}),De("defs",{children:s}),i]})})})})}import{useCallback as nl}from"react";import{create as ol}from"zustand";import{HTMLPortal as js}from"@atlas-viewer/atlas";import{autoUpdate as Ks,flip as Ys,offset as Gs,shift as Qs,useDismiss as Xs,useFloating as Zs,useInteractions as Js}from"@floating-ui/react";import{createPortal as el}from"react-dom";import Ws,{useContext as W,useMemo as Us}from"react";import Bs from"react";import{createContext as Hs,useMemo as Ds}from"react";import qs from"mitt";import{jsx as Fs}from"react/jsx-runtime";var $s=qs(),ke=Hs({emitter:$s});ke.displayName="Events";function tr(){return Bs.useContext(ke).emitter}function Lh({emitter:e,children:t}){return Fs(ke.Provider,{value:Ds(()=>({emitter:e}),[e]),children:t})}import{jsx as U}from"react/jsx-runtime";var qe=Ws.createContext({});function ct(){let e=W(qe),t=Object.keys(e),n={};for(let o of t)e[o].Provider&&(n[o]={value:W(e[o]),Provider:e[o].Provider});return n}function _s(e){let t=Object.keys(e),n=e.children;for(let o of t){if(o==="children")continue;let{value:s,Provider:i}=e[o];n=U(i,{value:s,children:n})}return n}function Kh(e){let t=W(qe),n=Us(()=>({...t,...e.providers}),[e.providers]);return U(qe.Provider,{value:n,children:e.children})}function dt(){return{VaultContext:W(le),ResourceContext:W($e),SimpleViewerReactContext:W(ze),VisibleCanvasReactContext:W(he),AuthRContext:W(ve),SearchReactContext:W(Se),ReactEventContext:W(ke),ContextBridgeReactContext:W(qe),StrategyReactContext:W(ce),AtlasStoreReactContext:W(be)}}function mt(e){return U(ge,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext,children:U(he.Provider,{value:e.bridge.VisibleCanvasReactContext,children:U(ze.Provider,{value:e.bridge.SimpleViewerReactContext,children:U(ke.Provider,{value:e.bridge.ReactEventContext,children:U(be.Provider,{value:e.bridge.AtlasStoreReactContext,children:U(ve.Provider,{value:e.bridge.AuthRContext,children:U(Se.Provider,{value:e.bridge.SearchReactContext,children:U(qe.Provider,{value:e.bridge.ContextBridgeReactContext,children:U(ce.Provider,{value:e.bridge.StrategyReactContext,children:e.custom?U(_s,{...e.custom,children:e.children}):e.children})})})})})})})})})}import{jsx as tn,jsxs as tl}from"react/jsx-runtime";function pt({annotation:e,target:t,children:n,dismissable:o,isOpen:s,onOpenChange:i,placement:r}){let a=dt(),l=ct(),{refs:u,floatingStyles:g,context:c}=Zs({open:s,onOpenChange:i,nodeId:e.id,placement:r||"bottom",middleware:[Gs(10),Qs(),Ys({mainAxis:!0})],whileElementsMounted:Ks}),d=Xs(c),{getReferenceProps:p,getFloatingProps:y}=Js([o?d:null].filter(f=>f!==null));return tl(js,{relative:!0,target:t,interactive:!1,children:[tn("div",{ref:u.setReference,...p(),style:{position:"absolute",top:0,left:0,right:0,bottom:0,pointerEvents:"none"}}),el(tn(mt,{bridge:a,custom:l,children:tn("div",{ref:u.setFloating,style:g,...y(),children:n})}),document.getElementById("atlas-floating-ui"))]})}import{Fragment as il,jsx as nr}from"react/jsx-runtime";var rl=ol()(e=>({isMenuOpen:!1,menuPosition:{x:0,y:0},setMenuPosition(t){e({menuPosition:t})},toggle(t){e(n=>({isMenuOpen:!n.isMenuOpen,menuPosition:t}))},open(t){e({isMenuOpen:!0,menuPosition:t})},setIsMenuOpen(t){e(typeof t=="function"?n=>({isMenuOpen:t(n.isMenuOpen)}):{isMenuOpen:t})},close(){e({isMenuOpen:!1})}}));function ft(e,t,n){let{isMenuOpen:o,setIsMenuOpen:s,close:i,open:r,menuPosition:a,setMenuPosition:l,toggle:u}=rl(),g=nl(p=>{n&&(p.preventDefault(),p.stopPropagation(),u(p.atlas))},[u,n]);return[nr(il,{children:n&&o&&nr(pt,{dismissable:!0,placement:"bottom-start",isOpen:o,onOpenChange:s,annotation:{id:e},target:{x:a.x,y:a.y,height:1,width:1},children:o&&n({canvasId:t,position:a,close:()=>s(!1)})})}),{onContextMenu:g},{open:r,close:i,toggle:u,isMenuOpen:o,setIsMenuOpen:s,menuPosition:a,setMenuPosition:l}]}import{useStore as al}from"zustand";function or(){let e=q();return al(e,t=>t.tool.requestId&&t.requests[t.tool.requestId]||null)}import{Fragment as rr,jsx as ae,jsxs as nn}from"react/jsx-runtime";function ir({theme:e,renderContextMenu:t,children:n}){let o=q(),s=A(),i=J(o,b=>b.polygon),r=J(o,b=>b.polygonState.currentTool),a=J(o,b=>b.mode),l=J(o,b=>b.changeMode),u=J(o,b=>b.polygonState.transitioning),{enabled:g,requestId:c}=J(o,b=>b.tool),d=ll(()=>xe(i),[i]),p=or(),[y,f]=ft("editing-annotation",s?.id,t),x=p?.annotationPopup||n||ae(ul,{}),v=p?.svgTheme||e,m=()=>{l("sketch")};if(!g||!s||!c||!i)return null;let h=d&&i.id&&!u&&(r==="pointer"||r==="hand"||!i.open)?ae(pt,{annotation:i,target:d,children:x}):null,S="shape";return a==="explore"?nn(rr,{children:[ae(S,{id:`shape-${i.id}`,points:i.points,open:i.open,onClick:m,relativeStyle:!0,target:{x:0,y:0,width:s.width,height:s.height},style:{":hover":{backgroundColor:"rgba(0,0,0,0.2)"},backgroundColor:"rgba(0,0,0,0)",borderWidth:"4px",borderColor:"rgba(255, 255, 255, .4)"},...f}),ae(S,{id:`shape-${i.id}`,points:i.points,open:i.open,onClick:m,relativeStyle:!0,target:{x:0,y:0,width:s.width,height:s.height},style:{backgroundColor:"rgba(0,0,0,0)",borderWidth:"2px",borderColor:"rgba(0, 0, 0, .4)"}}),h]}):nn(rr,{children:[t?ae(S,{id:`shape-${i.id}`,points:i.points,open:i.open,target:{x:0,y:0,width:s.width,height:s.height},...f}):null,ae(er,{image:s,theme:v}),h,y]})}function ul(){let e=q(),t=J(e,r=>r.changeMode),n=J(e,r=>r.mode),o=J(e,r=>r.completeRequest),s=J(e,r=>r.tool),i=()=>{sl(()=>{o()})};return s.enabled?nn("div",{className:"svg-tools-container animate-fadeIn",children:[n!=="sketch"&&ae("button",{className:"svg-tools-button",onClick:()=>{t("sketch")},children:"Edit"}),ae("button",{className:"svg-tools-button",onClick:i,children:"Save"})]}):null}import{useEffect as on,useMemo as rn}from"react";import{useEffect as gr,useMemo as hr}from"react";import{useCallback as lr,useMemo as dl}from"react";function cl(e,t){let n=e?.iiif?.meta[t];return n?n.annotationPageManager:null}function ar(e,t){return k(n=>{let o=[];if(!e)return o;let s=Object.keys(n.iiif.entities.AnnotationPage);for(let i of s)if(!t||t.indexOf(i)!==-1){let r=cl(n,i);r&&r.views&&r.views[e]&&o.push(i)}return o},[e,t])}function sr({canvas:e,manifest:t,all:n,canvases:o}){let s=[];if(t)for(let i of t.annotations)s.indexOf(i.id)===-1&&s.push(i.id);if(n){if(o&&o.length)for(let i of o)for(let r of i.annotations)s.indexOf(r.id)===-1&&s.push(r.id)}else if(e)for(let i of e.annotations)s.indexOf(i.id)===-1&&s.push(i.id);return s}function ml(e,t){let n=e?.iiif?.meta[t];return n?n.annotationPageManager:null}function ur(e,t={}){let n=M(),o=B(),s=A(),i=Fe(),r=dl(()=>sr({all:t.all,manifest:o,canvas:s,canvases:i}),[t.all,s,i,o]),a=ar(e,t.all?void 0:r),l=lr(g=>{e&&n.setMetaValue([g,"annotationPageManager","views"],c=>c&&!c[e]?c:{...c||{},[e]:!1})},[e,n]),u=lr((g,c={})=>{if(!e)return;let d=n.getState(),p=[];if(c?.deselectOthers){let y=Object.keys(d.iiif.entities.AnnotationPage);for(let f of y){let x=ml(d,f);x&&x.views&&x.views[e]&&p.push(f)}}for(let y of p)l(y);n.setMetaValue([g,"annotationPageManager","views"],y=>y&&y[e]?y:{...y||{},[e]:!0})},[e,l,n]);return{availablePageIds:r,enabledPageIds:a,setPageEnabled:u,setPageDisabled:l}}function cr(e,t){return k((n,o)=>o.get(e.map(s=>({id:s,type:t}))),[e,t])}import pl from"mitt";import{useCallback as fl}from"react";import{createStore as gl}from"zustand";var hl=gl((e,t)=>({loaded:{},setLoaded:(n,o="done")=>{e(s=>({loaded:{...s.loaded,[n]:o}}))}})),yl=pl();yl.on("loaded",e=>{hl.getState().setLoaded(e.imageServiceId)});function dr(){let e=rt(),t=wo();return[fl((o,{height:s,width:i})=>o&&e(o,{height:s,width:i},!0),[e]),t]}import{useCallback as vl,useMemo as pr,useState as Sl}from"react";function mr(e={}){let t=je(),n=A(e.canvasId?{id:e.canvasId}:void 0);return k((o,s)=>{if(!n)return[];if(t&&e.enableSingleAnnotation)return[t];let i=s.get(n.items),r=[];for(let a of i)r.push(...s.get(a.items));return r},[n])}import{createPaintingAnnotationsHelper as xl}from"@iiif/helpers/painting-annotations";function fr(e,t=[]){let n=M(),o=pr(()=>xl(n),[]),s=mr({enableSingleAnnotation:e?.enableSingleAnnotation}),[i,r]=Sl(e?.defaultChoices||[]),a=pr(()=>o.getPaintables(s,i),[n,s,i,...t]),u={makeChoice:vl((g,{deselectOthers:c=!0,deselect:d=!1}={})=>{a.choice&&r(p=>{if(d){let f=p.filter(x=>x!==g);if(f.length===0){let x=a.items[0].resource.id;return x?[x]:[]}return f}if(c)return[g];let y=[...p];if(y.length===0&&a.items.length){let f=a.items[0].resource.id;f&&y.push(f)}return p.indexOf(g)!==-1?p:[...p,g]})},[a.choice])};return[a,u]}function yr(e){let t=B(),n=A(),o=M(),s=tr(),i=e?.emitter||s,[r,a]=dr(),{enabledPageIds:l}=ur(e?.annotationPageManagerId||t?.id||n?.id,{all:!1}),u=cr(l,"AnnotationPage"),g=e?.strategies||["empty","images","media","textual-content","complex-timeline"],[c,d]=fr(e,[a]);gr(()=>{let y=f=>{d.makeChoice(f.choiceId,{deselectOthers:f.deselectOthers,deselect:f.deselect})};return i.on("make-choice",y),()=>{i.off("make-choice",y)}},[]);let p=hr(()=>un({canvas:n,paintables:c,supports:g,loadImageService:r,vault:o}),[n,c,o,d.makeChoice]);return gr(()=>{let y=c.allChoices,f={canvasId:n?.id,manifestId:t?.id};y&&i.emit("choice-change",{choice:y,partOf:f})},[n?.id,c.allChoices]),hr(()=>p.type==="unknown"?[p,ln]:[{...p,annotations:{pages:u}},d],[p,u])}import{createStylesHelper as bl}from"@iiif/helpers";import{jsx as vr}from"react/jsx-runtime";function Sr({strategies:e,registerActions:t,defaultChoices:n,onChoiceChange:o,mediaControlsDeps:s,renderMediaControls:i,renderViewerControls:r,viewControlsDeps:a,renderComplexTimelineControls:l,complexTimelineControlsDeps:u,throwOnUnknown:g,children:c}){let d=A(),p=M(),y=rn(()=>bl(p),[p]),[f,x]=yr({strategies:e||["images"],defaultChoices:n?.map(({id:S})=>S)}),v="choice"in f?f.choice:void 0;if(on(()=>{t&&t(x)},[f.annotations]),on(()=>{o&&o(v)},[v]),on(()=>{if(n)for(let S of n)typeof S.opacity<"u"&&y.applyStyles({id:S.id},"atlas",{opacity:S.opacity})},[n]),f.type==="unknown"&&g)throw new Error(f.reason||"Unknown strategy");let m=rn(()=>({renderMediaControls:i,mediaControlsDeps:s||[],renderViewerControls:r,viewControlsDeps:a||[],renderComplexTimelineControls:l,complexTimelineControlsDeps:u||[]}),[s,i,r,a,l,u]),h=rn(()=>({strategy:f,actions:x,choices:"choice"in f?f.choice:[]}),[f,d]);return vr(et.Provider,{value:m,children:vr(ce.Provider,{value:h,children:c})})}import{useEffect as br,useMemo as Pl}from"react";import{useStore as Cr}from"zustand";import{createContext as Cl,useContext as Rl,useEffect as Al}from"react";var an=Cl(()=>{});function xr(e){let t=A(),n=Rl(an);Al(()=>t&&t.id?(n(t.id,e),()=>n(t.id,-1)):()=>{},[t,e])}import{jsxs as wl}from"react/jsx-runtime";function Rr({x:e=0,y:t=0,keepCanvasScale:n=!0,renderContextMenu:o,children:s}){let{strategy:i}=V(),r=A(),a=q(),l=Ke(r,["deep-zoom"]),u=Cr(a,f=>f.setCanvasRelativePosition),g=Cr(a,f=>f.clearCanvasRelativePosition),[c,d]=ft(`context-menu/${r?.id}`,r?.id,o),p=Pl(()=>n?1:Math.max(1,...i.type==="images"?i.images.map(f=>(f.width||0)/f.target?.spatial.width):[]),[n,i]);br(()=>{if(r)return u(r.id,{x:e,y:t,width:r.width,height:r.height}),()=>{g(r.id)}},[e,t,r,g,u]),br(()=>{r&&a.getState().reset()},[a,r]),xr(p);let y=i.type==="images"?i.images.length:0;return r?wl("world-object",{height:r.height,width:r.width,x:e,y:t,...d,...l,children:[c,s]},`${r.id}/${i.type}/${y}`):null}import{jsx as Y,jsxs as Ar}from"react/jsx-runtime";function de({x:e,y:t,onChoiceChange:n,registerActions:o,defaultChoices:s,isStatic:i,renderViewerControls:r,renderMediaControls:a,renderComplexTimelineControls:l,complexTimelineControlsDeps:u,viewControlsDeps:g,mediaControlsDeps:c,strategies:d,throwOnUnknown:p,backgroundStyle:y,alwaysShowBackground:f,keepCanvasScale:x=!1,enableSizes:v=!1,enableYouTube:m=!0,onClickPaintingAnnotation:h,components:S={},children:b,annotationPopup:C,svgTheme:R,renderContextMenu:P,renderAnnotationContextMenu:L}){return Ar(Sr,{throwOnUnknown:p,onChoiceChange:n,registerActions:o,strategies:d,defaultChoices:s,mediaControlsDeps:c,renderMediaControls:a,renderViewerControls:r,renderComplexTimelineControls:l,complexTimelineControlsDeps:u,viewControlsDeps:g,children:[Ar(Rr,{keepCanvasScale:x,x:e,y:t,renderContextMenu:P,children:[Y(Wo,{alwaysShowBackground:f,backgroundStyle:y}),Y(Fo,{}),Y(_o,{}),Y(Uo,{isStatic:i,enableSizes:v,onClickPaintingAnnotation:h}),Y(ho,{}),Y(io,{}),Y(xo,{as:S.Audio}),Y(Ko,{as:S.Video}),m?Y(Qo,{}):null,Y(ir,{theme:R,renderContextMenu:L,children:C}),b]}),Y(ao,{})]})}import{jsx as Pr}from"react/jsx-runtime";function wr(e){let t=A();return!t||!t.placeholderCanvas?null:Pr(ee,{canvas:t.placeholderCanvas.id,children:Pr(de,{renderViewerControls:e.renderViewerControls})})}import{AtlasAuto as kl}from"@atlas-viewer/atlas";import Mr,{useCallback as gt,useMemo as El,useState as ht}from"react";import{ErrorBoundary as Vl}from"react-error-boundary";import{useStore as kr}from"zustand";import{useEffect as Tl,useMemo as Il}from"react";function Tr(e,t=2e3){let{currentSequenceIndex:n,sequence:o,items:s}=_e(),i=A(),r=Il(()=>{let l=o[n]||[];return l.length===0&&i?[{id:i.id,type:"Canvas"}]:l.map(u=>s[u])},[o,n,i,s]),a=q();Tl(()=>{let u=setInterval(()=>{if(e&&t!==-1){let g={x:e.x,y:e.y,width:e.width,height:e.height},c=a.getState().canvasRelativePositions,d={};for(let p of r){let y=c[p.id];if(y){let f=y.x,x=y.y,v=y.width,m=y.height,h={x:Math.max(f,g.x),y:Math.max(x,g.y),width:Math.min(f+v,g.x+g.width)-Math.max(f,g.x),height:Math.min(x+m,g.y+g.height)-Math.max(x,g.y)};h.width<=0||h.height<=0||(d[p.id]={x:h.x-y.x,y:h.y-y.y,width:h.width,height:h.height}),a.setState({canvasViewports:d})}}}},t);return()=>{clearTimeout(u)}},[r,e,a,t])}import{jsx as sn,jsxs as Ml}from"react/jsx-runtime";function Ir({width:e,style:t,height:n,error:o,resetErrorBoundary:s}){return Ml("div",{style:{width:e,height:n,minHeight:500,...t||{},background:"#f9f9f9"},children:[sn("h3",{children:"Error occurred"}),sn("p",{children:o.message}),sn("button",{type:"button",onClick:s,children:"Reset"})]})}import{Fragment as Ll,jsx as O,jsxs as zl}from"react/jsx-runtime";function Er(e){let t=q();return O(Oe,{name:e.name,existing:t,children:O(Nl,{...e})})}function Nl({name:e,children:t,errorFallback:n,outerContainerProps:o={},worldScale:s,updateViewportTimeout:i,...r}){let a=q(),l=kr(a,w=>w.mode),u=kr(a,w=>w.setAtlasRuntime),[g,c]=ht(),d=ct(),p=dt(),y=n||Ir,[f,x]=ht({}),v=Object.entries(f),[m,h]=ht({}),S=Object.entries(m),[b,C]=ht({}),{worldScale:R,runtimeOptions:P}=El(()=>{if(Object.values(b).length===0)return{worldScale:1,runtimeOptions:r.runtimeOptions||{maxOverZoom:1}};let I=Math.max(...Object.values(b));return{worldScale:I,runtimeOptions:{maxOverZoom:I||1,...r.runtimeOptions||{}}}},[b,r.runtimeOptions]);Tr(g?.runtime,i);let L=gt((w,I)=>{C(E=>{if(I===-1){let{[w]:Ee,...se}=E;return se}return{...E,[w]:I}})},[]),re=gt((w,I,E)=>{x(({[w]:Ee,...se})=>I?{...se,[w]:{element:I,props:E}}:se)},[]),T=gt((w,I,E)=>{h(({[w]:Ee,...se})=>I?{...se,[w]:{element:I,props:E}}:se)},[]),z=gt(w=>{c(w),u(w.runtime),r.onCreated&&r.onCreated(w)},[r.onCreated,u]);return zl(Vl,{resetKeys:[],fallbackRender:w=>O(y,{...r,...w}),children:[O(kl,{...r,mode:l,containerProps:{style:{position:"relative"},...r.containerProps||{}},htmlChildren:O(Ll,{children:v.map(([w,{element:I,props:E}])=>O(Mr.Fragment,{children:O(I,{...E||{}})},w))}),onCreated:z,runtimeOptions:P,children:O(Oe,{name:e,existing:a,children:O(fe.Provider,{value:g,children:O(an.Provider,{value:L,children:O(Bt.Provider,{value:re,children:O(Ht.Provider,{value:T,children:O(mt,{bridge:p,custom:d,children:O(fo,{children:t})})})})})})})}),O("div",{children:S.map(([w,{element:I,props:E}])=>O(Mr.Fragment,{children:O(I,{...E||{}})},w))}),O("div",{id:"atlas-floating-ui",style:{position:"relative",zIndex:999999}})]})}import{Fragment as Dl,jsx as G,jsxs as ql}from"react/jsx-runtime";var Hl=Vr(function(t,n){let o=B(),s=Fe(),i=_e(),{ViewerControls:r,MediaControls:a,ComplexTimelineControls:l}=t.components||{};if(Ol(n,()=>i,[i]),!o)return G("div",{});let u=0,g=o.viewingDirection==="top-to-bottom",c=o.viewingDirection==="bottom-to-top",d=o.viewingDirection==="left-to-right",p=o.viewingDirection==="right-to-left",f=o.behavior.includes("continuous")?0:t.spacing||0,x=c||p,v=Bl(()=>x?[...s].reverse():s,[s,x]);return ql(Dl,{children:[t.header,G(H.Viewer,{height:t.height,mode:t.mode,renderPreset:t.renderPreset,runtimeOptions:t.runtimeOptions,updateViewportTimeout:t.updateViewportTimeout,homePaddingPx:t.padding,children:v.map((m,h)=>{let S=0,b=0;return!g&&!c?(S=u,u+=m.width+f):(b=u,u+=m.height+f),G(ee,{canvas:m.id,children:G(H.RenderCanvas,{strategies:["3d-model","media","images","empty","textual-content","complex-timeline"],renderViewerControls:h===0&&r?()=>G(r,{}):void 0,renderMediaControls:h===0&&a?()=>G(a,{}):void 0,annotationPopup:t.annotationPopup,renderContextMenu:t.renderContextMenu,keepCanvasScale:t.keepCanvasScale,renderComplexTimelineControls:h===0&&l?()=>G(l,{}):void 0,renderAnnotationContextMenu:t.renderAnnotationContextMenu,x:S,y:b,svgTheme:t.svgTheme,...t.canvasProps||{},children:t.annotations},m.id)},m.id)})},t.reuseAtlas?"":i.currentSequenceIndex),t.children]})}),H=Vr(function({children:t,height:n,annotations:o,canvasProps:s,spacing:i,header:r,components:a,mode:l,reuseAtlas:u,renderPreset:g,runtimeOptions:c,annotationPopup:d,name:p,svgTheme:y,updateViewportTimeout:f,renderContextMenu:x,keepCanvasScale:v,renderAnnotationContextMenu:m,padding:h,...S},b){let C=ye();return G(Oe,{name:p,children:G(ge,{vault:C,children:G(On,{...S,children:G(Hl,{ref:b,height:n,components:a,spacing:i,canvasProps:s,annotations:o,header:r,mode:l,reuseAtlas:u,renderPreset:g,runtimeOptions:c,annotationPopup:d,svgTheme:y,updateViewportTimeout:f,renderContextMenu:x,keepCanvasScale:v,renderAnnotationContextMenu:m,padding:h,children:t})})})})});H.RenderImage=Ie;H.RenderCanvas=de;H.RenderAnnotationPage=ue;H.RenderAnnotation=Re;H.Viewer=Er;H.CanvasBackground=st;H.Audio=Ze;H.Video=ut;H.Model=Je;H.AudioHTML=Dt;H.VideoHTML=Qt;H.ModelHTML=$t;H.PlaceholderCanvas=wr;H.getAtlasStoreByName=Un;export{$e as a,_ as b,ie as c,ee as d,le as e,ge as f,M as g,k as h,he as i,Fe as j,ye as k,B as l,mn as m,pn as n,fn as o,gn as p,ei as q,vt as r,Ou as s,hn as t,Du as u,St as v,yn as w,vn as x,Zu as y,bn as z,Cn as A,Rn as B,xt as C,Sn as D,ve as E,li as F,ui as G,kn as H,En as I,Ne as J,ci as K,hc as L,di as M,In as N,yc as O,Vn as P,Ln as Q,ze as R,Ci as S,On as T,_e as U,At as V,id as W,Hn as X,Dn as Y,Pt as Z,xe as _,Ii as $,cd as aa,wt as ba,Tt as ca,qn as da,$n as ea,be as fa,q as ga,Un as ha,Oe as ia,_n as ja,jn as ka,Td as la,_i as ma,Kn as na,je as oa,A as pa,Ke as qa,Ce as ra,Gn as sa,Xn as ta,Re as ua,Zn as va,ue as wa,Em as xa,Vm as ya,Nm as za,Ge as Aa,Qe as Ba,Ot as Ca,Ae as Da,D as Ea,ce as Fa,V as Ga,io as Ha,et as Ia,$ as Ja,ao as Ka,so as La,co as Ma,po as Na,fo as Oa,ho as Pa,yo as Qa,Oa as Ra,vo as Sa,Pe as Ta,we as Ua,xo as Va,bo as Wa,cf as Xa,rt as Ya,bf as Za,Pf as _a,wf as $a,Tf as ab,Eo as bb,_t as cb,Vo as db,Ja as eb,es as fb,ts as gb,If as hb,Be as ib,Ie as jb,Fo as kb,Wo as lb,fe as mb,lt as nb,Uo as ob,_o as pb,Ko as qb,Qo as rb,Xo as sb,Ns as tb,Jo as ub,$s as vb,ke as wb,tr as xb,Lh as yb,ct as zb,_s as Ab,Kh as Bb,dt as Cb,mt as Db,rl as Eb,ft as Fb,or as Gb,ir as Hb,ul as Ib,sr as Jb,ur as Kb,cr as Lb,dr as Mb,mr as Nb,fr as Ob,yr as Pb,Sr as Qb,Rr as Rb,Ir as Sb,Er as Tb,H as Ub};
49
+ `}),Yo("iframe",{className:"video-yt",ref:o,src:`https://www.youtube.com/embed/${t.youTubeId}?enablejsapi=1&origin=${window.location.host}`,referrerPolicy:"no-referrer",sandbox:"allow-scripts allow-same-origin allow-presentation"})]}):null}function Go({media:e,mediaControlsDeps:t,children:n}){let[{element:o,currentTime:s,progress:i},r,a]=Ae({duration:e.duration});return D("overlay","video-element",ks,{element:o,media:e,playPause:a.playPause}),null}import{jsx as Vs,jsxs as Ns}from"react/jsx-runtime";function Qo(){let{strategy:e}=V(),{renderMediaControls:t,mediaControlsDeps:n}=F();return e.type!=="media"||e.media.type!=="VideoYouTube"?null:Ns(Go,{media:e.media,mediaControlsDeps:n,children:[Vs(we,{}),t?t(e):null]})}import{startTransition as fl,useMemo as gl}from"react";import{useStore as J}from"zustand";import{HTMLPortal as Bs,useAtlas as Hs}from"@atlas-viewer/atlas";import{useCallback as Jt,useEffect as en}from"react";import{createSvgHelpers as Ls}from"polygon-editor";import{useEffect as zs,useRef as Z,useState as Zo}from"react";import{useStore as Xt}from"zustand";function Xo(e){let t=q(),n=Xt(t,i=>i.polygons),o=Xt(t,i=>i.polygonState),s=Xt(t,i=>i.polygon);return Dn("atlas.polygon-render",({state:i,slowState:r,dt:a})=>{e(i,r,a)}),{currentShape:s,state:o,helper:n}}import{Fragment as Zt,jsx as N,jsxs as Me}from"react/jsx-runtime";var oe=Ls(),Os={shapeFill:"#ffffff33",shapeStroke:"#000",lineStroke:"#000",ghostLineStroke:"#0F0",activeLineStroke:"#4D7EEA",boundingBoxDottedStroke:"#0007",boundingBoxStroke:"#fffA",controlFill:"#fff"};function Jo(e){let{image:t}=e,n={...Os,...e.theme||{}},o=Z(),s=Z(),i=Z(),r=Z(),a=Z(),l=Z(),u=Z(),p=Z(),c=Z(),d=Z(),[f,y]=Zo(null),[g,x]=Zo(!1),{helper:v,state:m,currentShape:h}=Xo((T,z)=>{if(T.closestLineIndex,oe.updateTransitionBoundingBox(i.current,T,z),oe.updateBoundingBoxPolygon(o.current,T,z),oe.updateBoundingBoxPolygon(s.current,T,z),oe.updateTransitionShape(u.current,T,z),oe.updateClosestLinePointTransform(a.current,T,z),oe.updateSelectBox(r.current,T,z),oe.updatePointLine(p.current,T,z),oe.updateDrawPreview(l.current,T,z,3),oe.updateLineBox(c.current,T),y(T.transitionDirection),x(T.transitionRotate),T.closestLineIndex!==-1&&d.current){let w=T.polygon,I=w.points[T.closestLineIndex],E=w.points[(T.closestLineIndex+1)%w.points.length];I&&E&&d.current.setAttribute("points",`${I[0]},${I[1]} ${E[0]},${E[1]}`)}});zs(()=>{let T=()=>{v.modifiers.reset()};return document.addEventListener("mouseleave",T),()=>{document.removeEventListener("mouseleave",T)}},[]);let S=Me(Zt,{children:[Me("marker",{id:"dot",viewBox:"0 0 10 10",refX:"5",refY:"5",markerWidth:"5",markerHeight:"5",children:[N("circle",{cx:"5",cy:"5",r:"5",fill:n.lineStroke,className:"marker"}),N("circle",{cx:"5",cy:"5",r:"3",fill:n.controlFill})]}),N("marker",{id:"newdot",viewBox:"0 0 10 10",refX:"5",refY:"5",markerWidth:"5",markerHeight:"5",children:N("circle",{cx:"5",cy:"5",r:"5",fill:n.activeLineStroke,className:"marker"})}),Me("marker",{id:"selected",viewBox:"0 0 10 10",refX:"5",refY:"5",markerWidth:"5",markerHeight:"5",children:[N("circle",{cx:"5",cy:"5",r:"5",fill:n.lineStroke}),N("circle",{cx:"5",cy:"5",r:"3",fill:n.activeLineStroke})]}),Me("marker",{id:"resizer",viewBox:"0 0 10 10",refX:"5",refY:"5",markerWidth:"6",markerHeight:"6",children:[N("rect",{width:"10",height:"10",fill:n.lineStroke}),N("rect",{x:"1",y:"1",width:"8",height:"8",fill:n.controlFill})]})]}),b=h?h.open?"polyline":"polygon":null,C=!m.showBoundingBox&&m.closestPoint!==null&&m.actionIntentType==="select-point",R=m.actionIntentType==="add-open-point",P=m.transitionIntentType==="split-line",L=m.transitioning&&m.selectedStamp&&m.transitionIntentType==="stamp-shape",re=h&&b?Me(Zt,{children:[N(b,{fill:(!m.transitioning||m.transitionIntentType==="select-multiple-points")&&!h.open?n.shapeFill:"none",strokeWidth:L||m.showBoundingBox&&m.boxMode||m.transitioning&&m.transitionIntentType==="split-line"||m.transitioning&&m.transitionIntentType==="move-point"?0:2,stroke:n.shapeStroke,points:h.points.map(T=>T.join(",")).join(" "),vectorEffect:"non-scaling-stroke",markerStart:m.showBoundingBox?void 0:m.boxMode?"url(#resizer)":"url(#dot)",markerMid:m.showBoundingBox?void 0:m.boxMode?"url(#resizer)":"url(#dot)",markerEnd:m.showBoundingBox?void 0:m.boxMode?"url(#resizer)":"url(#dot)",style:{pointerEvents:"none"},opacity:m.transitioning&&m.transitionIntentType==="move-shape"?0:1}),m.currentTool==="lineBox"&&m.actionIntentType==="close-line-box"?N("polygon",{fill:n.shapeFill,ref:c,stroke:n.lineStroke,strokeWidth:2,vectorEffect:"non-scaling-stroke"}):null,m.transitionIntentType==="draw-shape"&&m.transitioning?N("polyline",{ref:l,fill:"none",stroke:n.activeLineStroke,strokeWidth:2,vectorEffect:"non-scaling-stroke"}):null,!(m.transitioning&&m.transitionIntentType==="move-point")&&!(m.transitioning&&m.transitionIntentType==="stamp-shape")&&!m.showBoundingBox&&m.selectedPoints&&m.selectedPoints.length?N("polyline",{strokeWidth:2,vectorEffect:"non-scaling-stroke",stroke:"transparent",markerStart:"url(#selected)",markerMid:"url(#selected)",markerEnd:"url(#selected)",fill:"transparent",points:h.points.filter((T,z)=>m.selectedPoints?.includes(z)).map(T=>T.join(",")).join(" "),opacity:m.transitioning&&m.transitionIntentType==="move-shape"?0:1}):null,C&&!m.transitioning&&m.closestPoint!==null&&h.points[m.closestPoint]?N("polyline",{strokeWidth:2,vectorEffect:"non-scaling-stroke",stroke:"transparent",markerStart:"url(#selected)",markerMid:"url(#selected)",markerEnd:"url(#selected)",fill:n.activeLineStroke,points:`${h.points[m.closestPoint][0]},${h.points[m.closestPoint][1]}`,opacity:m.transitioning&&m.transitionIntentType==="move-shape"?0:1}):null,!m.transitioning&&(m.actionIntentType==="add-open-point"||m.actionIntentType==="close-shape"||m.actionIntentType==="close-shape-line")?N("polyline",{stroke:n.activeLineStroke,ref:p,strokeWidth:m.actionIntentType==="add-open-point"?1:2,vectorEffect:"non-scaling-stroke"}):null,m.hasClosestLine&&!m.showBoundingBox&&!m.transitioning&&m.currentTool!=="box"&&m.transitionIntentType==="split-line"?N("g",{children:N("polyline",{ref:d,vectorEffect:"non-scaling-stroke",fill:"transparent",stroke:n.activeLineStroke,strokeWidth:3})}):null,m.hasClosestLine&&!m.showBoundingBox&&!m.transitioning&&m.currentTool!=="box"&&m.transitionIntentType==="split-line"?N("g",{ref:a,children:N("polyline",{markerStart:"url(#newdot)",points:"0,0 1,1",vectorEffect:"non-scaling-stroke",stroke:"transparent",fill:"transparent",strokeWidth:2})}):null,m.transitioning?N(b,{ref:u,fill:h.open?"none":n.shapeFill,stroke:m.transitionIntentType==="stamp-shape"?n.activeLineStroke:n.shapeStroke,vectorEffect:"non-scaling-stroke",strokeWidth:(h.open,2)}):null,m.transitioning&&m.transitionIntentType==="select-multiple-points"?N("rect",{ref:r,fill:"rgba(255, 255, 255, .3)",strokeWidth:1,stroke:"rgba(0,0,0,.2)",vectorEffect:"non-scaling-stroke"}):null,m.showBoundingBox&&!L?Me(Zt,{children:[N("polygon",{ref:o,strokeWidth:2,stroke:n.boundingBoxStroke,fill:"none",markerStart:"url(#resizer)",markerMid:"url(#resizer)",markerEnd:"url(#resizer)",vectorEffect:"non-scaling-stroke"}),N("polygon",{ref:s,strokeWidth:2,stroke:n.boundingBoxDottedStroke,fill:"none",strokeDasharray:"4 4",markerStart:"url(#resizer)",markerMid:"url(#resizer)",markerEnd:"url(#resizer)",vectorEffect:"non-scaling-stroke"})]}):null]}):null;return{currentTool:v.state.slowState.currentTool,setCurrentTool:v.tools.setTool,helper:v,currentShape:h,state:m,isAddingPoint:R,isSplitting:P,isStamping:L,isHoveringPoint:C,transitionDirection:f,transitionRotate:g,defs:S,editor:re}}import{jsx as De,jsxs as Ds}from"react/jsx-runtime";function er(e){let t=Hs(),{image:n}=e,{helper:o,defs:s,editor:i,state:r,transitionDirection:a,isSplitting:l,transitionRotate:u,isHoveringPoint:p,isAddingPoint:c}=Jo({image:e.image,theme:e.theme}),d=Jt(g=>{g.button!==2&&o.pointer([[~~g.atlas.x,~~g.atlas.y]])},[o]),f=Jt(g=>{g.button!==2&&o.pointerDown()},[o]),y=Jt(g=>{g.button!==2&&o.pointerUp()},[o]);return en(()=>{let g=x=>{o.key.up(x.key)};return document.addEventListener("keyup",g),()=>{document.removeEventListener("keyup",g)}},[o]),en(()=>{let g=x=>{x.target&&["INPUT","TEXTAREA"].includes(x.target.tagName)||x.target?.isContentEditable||document.activeElement&&(document.activeElement instanceof HTMLInputElement||document.activeElement instanceof HTMLTextAreaElement||document.activeElement.isContentEditable)||o.key.down(x.key)};return document.addEventListener("keydown",g),()=>{document.removeEventListener("keydown",g)}},[o]),en(()=>{let g=[];return a&&g.push(`atlas-cursor-${a}`),r.actionIntentType==="cut-line"&&r.modifiers?.Shift&&g.push("atlas-cursor-cut"),(p||r.transitionIntentType==="move-shape"||r.transitionIntentType==="move-point")&&g.push("atlas-cursor-move"),c&&g.push("atlas-cursor-crosshair"),l&&g.push("atlas-cursor-copy"),u&&g.push("atlas-cursor-rotate"),r.transitionIntentType==="draw-shape"&&g.push("atlas-cursor-draw"),t?.canvas&&t.canvas.classList.add(...g),()=>{t?.canvas&&t.canvas.classList.remove(...g)}},[t?.canvas,c,p,l,r.modifiers?.Shift,r.actionIntentType,r.transitionIntentType,a,u]),De("world-object",{height:n.height,width:n.width,onMouseMove:d,onMouseDown:f,onMouseUp:y,onMouseLeave:o.blur,children:De(Bs,{relative:!0,interactive:!1,children:De("div",{className:"absolute top-0 right-0 left-0 bottom-0",children:Ds("svg",{width:"100%",height:"100%",viewBox:`0 0 ${n.width} ${n.height}`,tabIndex:-1,children:[De("title",{children:"Annotation Editor"}),De("defs",{children:s}),i]})})})})}import{useCallback as ul}from"react";import{create as cl}from"zustand";import{HTMLPortal as Gs}from"@atlas-viewer/atlas";import{autoUpdate as Qs,detectOverflow as Xs,flip as Zs,offset as Js,shift as el,useDismiss as tl,useFloating as nl,useInteractions as ol}from"@floating-ui/react";import{createPortal as rl}from"react-dom";import js,{useContext as W,useMemo as Ks}from"react";import qs from"react";import{createContext as Fs,useMemo as $s}from"react";import Ws from"mitt";import{jsx as _s}from"react/jsx-runtime";var Us=Ws(),ke=Fs({emitter:Us});ke.displayName="Events";function tr(){return qs.useContext(ke).emitter}function Fh({emitter:e,children:t}){return _s(ke.Provider,{value:$s(()=>({emitter:e}),[e]),children:t})}import{jsx as U}from"react/jsx-runtime";var qe=js.createContext({});function ct(){let e=W(qe),t=Object.keys(e),n={};for(let o of t)e[o].Provider&&(n[o]={value:W(e[o]),Provider:e[o].Provider});return n}function Ys(e){let t=Object.keys(e),n=e.children;for(let o of t){if(o==="children")continue;let{value:s,Provider:i}=e[o];n=U(i,{value:s,children:n})}return n}function ey(e){let t=W(qe),n=Ks(()=>({...t,...e.providers}),[e.providers]);return U(qe.Provider,{value:n,children:e.children})}function dt(){return{VaultContext:W(le),ResourceContext:W(Fe),SimpleViewerReactContext:W(ze),VisibleCanvasReactContext:W(he),AuthRContext:W(ve),SearchReactContext:W(Se),ReactEventContext:W(ke),ContextBridgeReactContext:W(qe),StrategyReactContext:W(ce),AtlasStoreReactContext:W(be)}}function mt(e){return U(ge,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext,children:U(he.Provider,{value:e.bridge.VisibleCanvasReactContext,children:U(ze.Provider,{value:e.bridge.SimpleViewerReactContext,children:U(ke.Provider,{value:e.bridge.ReactEventContext,children:U(be.Provider,{value:e.bridge.AtlasStoreReactContext,children:U(ve.Provider,{value:e.bridge.AuthRContext,children:U(Se.Provider,{value:e.bridge.SearchReactContext,children:U(qe.Provider,{value:e.bridge.ContextBridgeReactContext,children:U(ce.Provider,{value:e.bridge.StrategyReactContext,children:e.custom?U(Ys,{...e.custom,children:e.children}):e.children})})})})})})})})})}import{jsx as tn,jsxs as ll}from"react/jsx-runtime";var rr=10,nr=1;function il(e){let[t,n]=e.split("-");return[t,n]}function or(e,t,n){return t>n?e:Math.min(Math.max(e,t),n)}function al(e){return e.top>0||e.right>0||e.bottom>0||e.left>0}function sl(e){return{name:"insideHighlightFallback",options:e,async fn(t){if(e.width<=nr||e.height<=nr)return{};let n=await Xs(t,{altBoundary:!0});if(!al(n))return{};let{reference:o,floating:s}=t.rects,[i,r]=il(t.initialPlacement),a=Math.min(rr,o.width/2,o.height/2),l=o.x+(o.width-s.width)/2,u=o.y+(o.height-s.height)/2,p=t.x,c=t.y;return i==="top"||i==="bottom"?(c=i==="top"?o.y+a:o.y+o.height-s.height-a,r==="start"?p=o.x+a:r==="end"?p=o.x+o.width-s.width-a:p=l,p=or(p,o.x+a,o.x+o.width-s.width-a)):(p=i==="left"?o.x+a:o.x+o.width-s.width-a,r==="start"?c=o.y+a:r==="end"?c=o.y+o.height-s.height-a:c=u,c=or(c,o.y+a,o.y+o.height-s.height-a)),{x:p,y:c}}}}function pt({annotation:e,target:t,children:n,dismissable:o,isOpen:s,onOpenChange:i,placement:r}){let a=dt(),l=ct(),{refs:u,floatingStyles:p,context:c}=nl({open:s,onOpenChange:i,nodeId:e.id,placement:r||"bottom",middleware:[Js(rr),Zs({mainAxis:!0,fallbackStrategy:"bestFit",altBoundary:!0}),el({altBoundary:!0}),sl(t)],whileElementsMounted:Qs}),d=tl(c),{getReferenceProps:f,getFloatingProps:y}=ol([o?d:null].filter(g=>g!==null));return ll(Gs,{relative:!0,target:t,interactive:!1,children:[tn("div",{ref:u.setReference,...f(),style:{position:"absolute",top:0,left:0,right:0,bottom:0,pointerEvents:"none"}}),rl(tn(mt,{bridge:a,custom:l,children:tn("div",{ref:u.setFloating,style:p,...y(),children:n})}),document.getElementById("atlas-floating-ui"))]})}import{Fragment as ml,jsx as ir}from"react/jsx-runtime";var dl=cl()(e=>({isMenuOpen:!1,menuPosition:{x:0,y:0},setMenuPosition(t){e({menuPosition:t})},toggle(t){e(n=>({isMenuOpen:!n.isMenuOpen,menuPosition:t}))},open(t){e({isMenuOpen:!0,menuPosition:t})},setIsMenuOpen(t){e(typeof t=="function"?n=>({isMenuOpen:t(n.isMenuOpen)}):{isMenuOpen:t})},close(){e({isMenuOpen:!1})}}));function ft(e,t,n){let{isMenuOpen:o,setIsMenuOpen:s,close:i,open:r,menuPosition:a,setMenuPosition:l,toggle:u}=dl(),p=ul(f=>{n&&(f.preventDefault(),f.stopPropagation(),u(f.atlas))},[u,n]);return[ir(ml,{children:n&&o&&ir(pt,{dismissable:!0,placement:"bottom-start",isOpen:o,onOpenChange:s,annotation:{id:e},target:{x:a.x,y:a.y,height:1,width:1},children:o&&n({canvasId:t,position:a,close:()=>s(!1)})})}),{onContextMenu:p},{open:r,close:i,toggle:u,isMenuOpen:o,setIsMenuOpen:s,menuPosition:a,setMenuPosition:l}]}import{useStore as pl}from"zustand";function ar(){let e=q();return pl(e,t=>t.tool.requestId&&t.requests[t.tool.requestId]||null)}import{Fragment as sr,jsx as ae,jsxs as nn}from"react/jsx-runtime";function lr({theme:e,renderContextMenu:t,children:n}){let o=q(),s=A(),i=J(o,b=>b.polygon),r=J(o,b=>b.polygonState.currentTool),a=J(o,b=>b.mode),l=J(o,b=>b.changeMode),u=J(o,b=>b.polygonState.transitioning),{enabled:p,requestId:c}=J(o,b=>b.tool),d=gl(()=>xe(i),[i]),f=ar(),[y,g]=ft("editing-annotation",s?.id,t),x=f?.annotationPopup||n||ae(hl,{}),v=f?.svgTheme||e,m=()=>{l("sketch")};if(!p||!s||!c||!i)return null;let h=d&&i.id&&!u&&(r==="pointer"||r==="hand"||!i.open)?ae(pt,{annotation:i,target:d,children:x}):null,S="shape";return a==="explore"?nn(sr,{children:[ae(S,{id:`shape-${i.id}`,points:i.points,open:i.open,onClick:m,relativeStyle:!0,target:{x:0,y:0,width:s.width,height:s.height},style:{":hover":{backgroundColor:"rgba(0,0,0,0.2)"},backgroundColor:"rgba(0,0,0,0)",borderWidth:"4px",borderColor:"rgba(255, 255, 255, .4)"},...g}),ae(S,{id:`shape-${i.id}`,points:i.points,open:i.open,onClick:m,relativeStyle:!0,target:{x:0,y:0,width:s.width,height:s.height},style:{backgroundColor:"rgba(0,0,0,0)",borderWidth:"2px",borderColor:"rgba(0, 0, 0, .4)"}}),h]}):nn(sr,{children:[t?ae(S,{id:`shape-${i.id}`,points:i.points,open:i.open,target:{x:0,y:0,width:s.width,height:s.height},...g}):null,ae(er,{image:s,theme:v}),h,y]})}function hl(){let e=q(),t=J(e,r=>r.changeMode),n=J(e,r=>r.mode),o=J(e,r=>r.completeRequest),s=J(e,r=>r.tool),i=()=>{fl(()=>{o()})};return s.enabled?nn("div",{className:"svg-tools-container animate-fadeIn",children:[n!=="sketch"&&ae("button",{className:"svg-tools-button",onClick:()=>{t("sketch")},children:"Edit"}),ae("button",{className:"svg-tools-button",onClick:i,children:"Save"})]}):null}import{useEffect as on,useMemo as rn}from"react";import{useEffect as vr,useMemo as Sr}from"react";import{useCallback as dr,useMemo as vl}from"react";function yl(e,t){let n=e?.iiif?.meta[t];return n?n.annotationPageManager:null}function ur(e,t){return k(n=>{let o=[];if(!e)return o;let s=Object.keys(n.iiif.entities.AnnotationPage);for(let i of s)if(!t||t.indexOf(i)!==-1){let r=yl(n,i);r&&r.views&&r.views[e]&&o.push(i)}return o},[e,t])}function cr({canvas:e,manifest:t,all:n,canvases:o}){let s=[];if(t)for(let i of t.annotations)s.indexOf(i.id)===-1&&s.push(i.id);if(n){if(o&&o.length)for(let i of o)for(let r of i.annotations)s.indexOf(r.id)===-1&&s.push(r.id)}else if(e)for(let i of e.annotations)s.indexOf(i.id)===-1&&s.push(i.id);return s}function Sl(e,t){let n=e?.iiif?.meta[t];return n?n.annotationPageManager:null}function mr(e,t={}){let n=M(),o=B(),s=A(),i=$e(),r=vl(()=>cr({all:t.all,manifest:o,canvas:s,canvases:i}),[t.all,s,i,o]),a=ur(e,t.all?void 0:r),l=dr(p=>{e&&n.setMetaValue([p,"annotationPageManager","views"],c=>c&&!c[e]?c:{...c||{},[e]:!1})},[e,n]),u=dr((p,c={})=>{if(!e)return;let d=n.getState(),f=[];if(c?.deselectOthers){let y=Object.keys(d.iiif.entities.AnnotationPage);for(let g of y){let x=Sl(d,g);x&&x.views&&x.views[e]&&f.push(g)}}for(let y of f)l(y);n.setMetaValue([p,"annotationPageManager","views"],y=>y&&y[e]?y:{...y||{},[e]:!0})},[e,l,n]);return{availablePageIds:r,enabledPageIds:a,setPageEnabled:u,setPageDisabled:l}}function pr(e,t){return k((n,o)=>o.get(e.map(s=>({id:s,type:t}))),[e,t])}import xl from"mitt";import{useCallback as bl}from"react";import{createStore as Cl}from"zustand";var Rl=Cl((e,t)=>({loaded:{},setLoaded:(n,o="done")=>{e(s=>({loaded:{...s.loaded,[n]:o}}))}})),Al=xl();Al.on("loaded",e=>{Rl.getState().setLoaded(e.imageServiceId)});function fr(){let e=rt(),t=wo();return[bl((o,{height:s,width:i})=>o&&e(o,{height:s,width:i},!0),[e]),t]}import{useCallback as Pl,useMemo as hr,useState as wl}from"react";function gr(e={}){let t=je(),n=A(e.canvasId?{id:e.canvasId}:void 0);return k((o,s)=>{if(!n)return[];if(t&&e.enableSingleAnnotation)return[t];let i=s.get(n.items),r=[];for(let a of i)r.push(...s.get(a.items));return r},[n])}import{createPaintingAnnotationsHelper as Tl}from"@iiif/helpers/painting-annotations";function yr(e,t=[]){let n=M(),o=hr(()=>Tl(n),[]),s=gr({enableSingleAnnotation:e?.enableSingleAnnotation}),[i,r]=wl(e?.defaultChoices||[]),a=hr(()=>o.getPaintables(s,i),[n,s,i,...t]),u={makeChoice:Pl((p,{deselectOthers:c=!0,deselect:d=!1}={})=>{a.choice&&r(f=>{if(d){let g=f.filter(x=>x!==p);if(g.length===0){let x=a.items[0].resource.id;return x?[x]:[]}return g}if(c)return[p];let y=[...f];if(y.length===0&&a.items.length){let g=a.items[0].resource.id;g&&y.push(g)}return f.indexOf(p)!==-1?f:[...f,p]})},[a.choice])};return[a,u]}function xr(e){let t=B(),n=A(),o=M(),s=tr(),i=e?.emitter||s,[r,a]=fr(),{enabledPageIds:l}=mr(e?.annotationPageManagerId||t?.id||n?.id,{all:!1}),u=pr(l,"AnnotationPage"),p=e?.strategies||["empty","images","media","textual-content","complex-timeline"],[c,d]=yr(e,[a]);vr(()=>{let y=g=>{d.makeChoice(g.choiceId,{deselectOthers:g.deselectOthers,deselect:g.deselect})};return i.on("make-choice",y),()=>{i.off("make-choice",y)}},[]);let f=Sr(()=>un({canvas:n,paintables:c,supports:p,loadImageService:r,vault:o}),[n,c,o,d.makeChoice]);return vr(()=>{let y=c.allChoices,g={canvasId:n?.id,manifestId:t?.id};y&&i.emit("choice-change",{choice:y,partOf:g})},[n?.id,c.allChoices]),Sr(()=>f.type==="unknown"?[f,ln]:[{...f,annotations:{pages:u}},d],[f,u])}import{createStylesHelper as Il}from"@iiif/helpers";import{jsx as br}from"react/jsx-runtime";function Cr({strategies:e,registerActions:t,defaultChoices:n,onChoiceChange:o,mediaControlsDeps:s,renderMediaControls:i,renderViewerControls:r,viewControlsDeps:a,renderComplexTimelineControls:l,complexTimelineControlsDeps:u,throwOnUnknown:p,children:c}){let d=A(),f=M(),y=rn(()=>Il(f),[f]),[g,x]=xr({strategies:e||["images"],defaultChoices:n?.map(({id:S})=>S)}),v="choice"in g?g.choice:void 0;if(on(()=>{t&&t(x)},[g.annotations]),on(()=>{o&&o(v)},[v]),on(()=>{if(n)for(let S of n)typeof S.opacity<"u"&&y.applyStyles({id:S.id},"atlas",{opacity:S.opacity})},[n]),g.type==="unknown"&&p)throw new Error(g.reason||"Unknown strategy");let m=rn(()=>({renderMediaControls:i,mediaControlsDeps:s||[],renderViewerControls:r,viewControlsDeps:a||[],renderComplexTimelineControls:l,complexTimelineControlsDeps:u||[]}),[s,i,r,a,l,u]),h=rn(()=>({strategy:g,actions:x,choices:"choice"in g?g.choice:[]}),[g,d]);return br(et.Provider,{value:m,children:br(ce.Provider,{value:h,children:c})})}import{useEffect as Ar,useMemo as Vl}from"react";import{useStore as Pr}from"zustand";import{createContext as Ml,useContext as kl,useEffect as El}from"react";var an=Ml(()=>{});function Rr(e){let t=A(),n=kl(an);El(()=>t&&t.id?(n(t.id,e),()=>n(t.id,-1)):()=>{},[t,e])}import{jsxs as Nl}from"react/jsx-runtime";function wr({x:e=0,y:t=0,keepCanvasScale:n=!0,renderContextMenu:o,children:s}){let{strategy:i}=V(),r=A(),a=q(),l=Ke(r,["deep-zoom"]),u=Pr(a,g=>g.setCanvasRelativePosition),p=Pr(a,g=>g.clearCanvasRelativePosition),[c,d]=ft(`context-menu/${r?.id}`,r?.id,o),f=Vl(()=>n?1:Math.max(1,...i.type==="images"?i.images.map(g=>(g.width||0)/g.target?.spatial.width):[]),[n,i]);Ar(()=>{if(r)return u(r.id,{x:e,y:t,width:r.width,height:r.height}),()=>{p(r.id)}},[e,t,r,p,u]),Ar(()=>{r&&a.getState().reset()},[a,r]),Rr(f);let y=i.type==="images"?i.images.length:0;return r?Nl("world-object",{height:r.height,width:r.width,x:e,y:t,...d,...l,children:[c,s]},`${r.id}/${i.type}/${y}`):null}import{jsx as Y,jsxs as Tr}from"react/jsx-runtime";function de({x:e,y:t,onChoiceChange:n,registerActions:o,defaultChoices:s,isStatic:i,renderViewerControls:r,renderMediaControls:a,renderComplexTimelineControls:l,complexTimelineControlsDeps:u,viewControlsDeps:p,mediaControlsDeps:c,strategies:d,throwOnUnknown:f,backgroundStyle:y,alwaysShowBackground:g,keepCanvasScale:x=!1,enableSizes:v=!1,enableYouTube:m=!0,onClickPaintingAnnotation:h,components:S={},children:b,annotationPopup:C,svgTheme:R,renderContextMenu:P,renderAnnotationContextMenu:L}){return Tr(Cr,{throwOnUnknown:f,onChoiceChange:n,registerActions:o,strategies:d,defaultChoices:s,mediaControlsDeps:c,renderMediaControls:a,renderViewerControls:r,renderComplexTimelineControls:l,complexTimelineControlsDeps:u,viewControlsDeps:p,children:[Tr(wr,{keepCanvasScale:x,x:e,y:t,renderContextMenu:P,children:[Y(Wo,{alwaysShowBackground:g,backgroundStyle:y}),Y($o,{}),Y(_o,{}),Y(Uo,{isStatic:i,enableSizes:v,onClickPaintingAnnotation:h}),Y(ho,{}),Y(io,{}),Y(xo,{as:S.Audio}),Y(Ko,{as:S.Video}),m?Y(Qo,{}):null,Y(lr,{theme:R,renderContextMenu:L,children:C}),b]}),Y(ao,{})]})}import{jsx as Ir}from"react/jsx-runtime";function Mr(e){let t=A();return!t||!t.placeholderCanvas?null:Ir(ee,{canvas:t.placeholderCanvas.id,children:Ir(de,{renderViewerControls:e.renderViewerControls})})}import{AtlasAuto as Bl}from"@atlas-viewer/atlas";import Vr,{useCallback as gt,useMemo as Hl,useState as ht}from"react";import{ErrorBoundary as Dl}from"react-error-boundary";import{useStore as Nr}from"zustand";import{useEffect as Ll,useMemo as zl}from"react";function kr(e,t=2e3){let{currentSequenceIndex:n,sequence:o,items:s}=_e(),i=A(),r=zl(()=>{let l=o[n]||[];return l.length===0&&i?[{id:i.id,type:"Canvas"}]:l.map(u=>s[u])},[o,n,i,s]),a=q();Ll(()=>{let u=setInterval(()=>{if(e&&t!==-1){let p={x:e.x,y:e.y,width:e.width,height:e.height},c=a.getState().canvasRelativePositions,d={};for(let f of r){let y=c[f.id];if(y){let g=y.x,x=y.y,v=y.width,m=y.height,h={x:Math.max(g,p.x),y:Math.max(x,p.y),width:Math.min(g+v,p.x+p.width)-Math.max(g,p.x),height:Math.min(x+m,p.y+p.height)-Math.max(x,p.y)};h.width<=0||h.height<=0||(d[f.id]={x:h.x-y.x,y:h.y-y.y,width:h.width,height:h.height}),a.setState({canvasViewports:d})}}}},t);return()=>{clearTimeout(u)}},[r,e,a,t])}import{jsx as sn,jsxs as Ol}from"react/jsx-runtime";function Er({width:e,style:t,height:n,error:o,resetErrorBoundary:s}){return Ol("div",{style:{width:e,height:n,minHeight:500,...t||{},background:"#f9f9f9"},children:[sn("h3",{children:"Error occurred"}),sn("p",{children:o.message}),sn("button",{type:"button",onClick:s,children:"Reset"})]})}import{Fragment as Fl,jsx as O,jsxs as $l}from"react/jsx-runtime";function Lr(e){let t=q();return O(Oe,{name:e.name,existing:t,children:O(ql,{...e})})}function ql({name:e,children:t,errorFallback:n,outerContainerProps:o={},worldScale:s,updateViewportTimeout:i,...r}){let a=q(),l=Nr(a,w=>w.mode),u=Nr(a,w=>w.setAtlasRuntime),[p,c]=ht(),d=ct(),f=dt(),y=n||Er,[g,x]=ht({}),v=Object.entries(g),[m,h]=ht({}),S=Object.entries(m),[b,C]=ht({}),{worldScale:R,runtimeOptions:P}=Hl(()=>{if(Object.values(b).length===0)return{worldScale:1,runtimeOptions:r.runtimeOptions||{maxOverZoom:1}};let I=Math.max(...Object.values(b));return{worldScale:I,runtimeOptions:{maxOverZoom:I||1,...r.runtimeOptions||{}}}},[b,r.runtimeOptions]);kr(p?.runtime,i);let L=gt((w,I)=>{C(E=>{if(I===-1){let{[w]:Ee,...se}=E;return se}return{...E,[w]:I}})},[]),re=gt((w,I,E)=>{x(({[w]:Ee,...se})=>I?{...se,[w]:{element:I,props:E}}:se)},[]),T=gt((w,I,E)=>{h(({[w]:Ee,...se})=>I?{...se,[w]:{element:I,props:E}}:se)},[]),z=gt(w=>{c(w),u(w.runtime),r.onCreated&&r.onCreated(w)},[r.onCreated,u]);return $l(Dl,{resetKeys:[],fallbackRender:w=>O(y,{...r,...w}),children:[O(Bl,{...r,mode:l,containerProps:{style:{position:"relative"},...r.containerProps||{}},htmlChildren:O(Fl,{children:v.map(([w,{element:I,props:E}])=>O(Vr.Fragment,{children:O(I,{...E||{}})},w))}),onCreated:z,runtimeOptions:P,children:O(Oe,{name:e,existing:a,children:O(fe.Provider,{value:p,children:O(an.Provider,{value:L,children:O(Bt.Provider,{value:re,children:O(Ht.Provider,{value:T,children:O(mt,{bridge:f,custom:d,children:O(fo,{children:t})})})})})})})}),O("div",{children:S.map(([w,{element:I,props:E}])=>O(Vr.Fragment,{children:O(I,{...E||{}})},w))}),O("div",{id:"atlas-floating-ui",style:{position:"relative",zIndex:999999}})]})}import{Fragment as jl,jsx as G,jsxs as Kl}from"react/jsx-runtime";var _l=zr(function(t,n){let o=B(),s=$e(),i=_e(),{ViewerControls:r,MediaControls:a,ComplexTimelineControls:l}=t.components||{};if(Wl(n,()=>i,[i]),!o)return G("div",{});let u=0,p=o.viewingDirection==="top-to-bottom",c=o.viewingDirection==="bottom-to-top",d=o.viewingDirection==="left-to-right",f=o.viewingDirection==="right-to-left",g=o.behavior.includes("continuous")?0:t.spacing||0,x=c||f,v=Ul(()=>x?[...s].reverse():s,[s,x]);return Kl(jl,{children:[t.header,G(H.Viewer,{height:t.height,mode:t.mode,renderPreset:t.renderPreset,runtimeOptions:t.runtimeOptions,updateViewportTimeout:t.updateViewportTimeout,homePaddingPx:t.padding,children:v.map((m,h)=>{let S=0,b=0;return!p&&!c?(S=u,u+=m.width+g):(b=u,u+=m.height+g),G(ee,{canvas:m.id,children:G(H.RenderCanvas,{strategies:["3d-model","media","images","empty","textual-content","complex-timeline"],renderViewerControls:h===0&&r?()=>G(r,{}):void 0,renderMediaControls:h===0&&a?()=>G(a,{}):void 0,annotationPopup:t.annotationPopup,renderContextMenu:t.renderContextMenu,keepCanvasScale:t.keepCanvasScale,renderComplexTimelineControls:h===0&&l?()=>G(l,{}):void 0,renderAnnotationContextMenu:t.renderAnnotationContextMenu,x:S,y:b,svgTheme:t.svgTheme,...t.canvasProps||{},children:t.annotations},m.id)},m.id)})},t.reuseAtlas?"":i.currentSequenceIndex),t.children]})}),H=zr(function({children:t,height:n,annotations:o,canvasProps:s,spacing:i,header:r,components:a,mode:l,reuseAtlas:u,renderPreset:p,runtimeOptions:c,annotationPopup:d,name:f,svgTheme:y,updateViewportTimeout:g,renderContextMenu:x,keepCanvasScale:v,renderAnnotationContextMenu:m,padding:h,...S},b){let C=ye();return G(Oe,{name:f,children:G(ge,{vault:C,children:G(On,{...S,children:G(_l,{ref:b,height:n,components:a,spacing:i,canvasProps:s,annotations:o,header:r,mode:l,reuseAtlas:u,renderPreset:p,runtimeOptions:c,annotationPopup:d,svgTheme:y,updateViewportTimeout:g,renderContextMenu:x,keepCanvasScale:v,renderAnnotationContextMenu:m,padding:h,children:t})})})})});H.RenderImage=Ie;H.RenderCanvas=de;H.RenderAnnotationPage=ue;H.RenderAnnotation=Re;H.Viewer=Lr;H.CanvasBackground=st;H.Audio=Ze;H.Video=ut;H.Model=Je;H.AudioHTML=Dt;H.VideoHTML=Qt;H.ModelHTML=Ft;H.PlaceholderCanvas=Mr;H.getAtlasStoreByName=Un;export{Fe as a,_ as b,ie as c,ee as d,le as e,ge as f,M as g,k as h,he as i,$e as j,ye as k,B as l,mn as m,pn as n,fn as o,gn as p,oi as q,vt as r,Wu as s,hn as t,ju as u,St as v,yn as w,vn as x,ic as y,bn as z,Cn as A,Rn as B,xt as C,Sn as D,ve as E,di as F,mi as G,kn as H,En as I,Ne as J,pi as K,Rc as L,fi as M,In as N,Ac as O,Vn as P,Ln as Q,ze as R,Pi as S,On as T,_e as U,At as V,md as W,Hn as X,Dn as Y,Pt as Z,xe as _,Ei as $,yd as aa,wt as ba,Tt as ca,qn as da,Fn as ea,be as fa,q as ga,Un as ha,Oe as ia,_n as ja,jn as ka,Ld as la,Yi as ma,Kn as na,je as oa,A as pa,Ke as qa,Ce as ra,Gn as sa,Xn as ta,Re as ua,Zn as va,ue as wa,Hm as xa,Dm as ya,qm as za,Ge as Aa,Qe as Ba,Ot as Ca,Ae as Da,D as Ea,ce as Fa,V as Ga,io as Ha,et as Ia,F as Ja,ao as Ka,so as La,co as Ma,po as Na,fo as Oa,ho as Pa,yo as Qa,Da as Ra,vo as Sa,Pe as Ta,we as Ua,xo as Va,bo as Wa,yf as Xa,rt as Ya,If as Za,Vf as _a,Nf as $a,Lf as ab,Eo as bb,_t as cb,Vo as db,ns as eb,os as fb,rs as gb,zf as hb,Be as ib,Ie as jb,$o as kb,Wo as lb,fe as mb,lt as nb,Uo as ob,_o as pb,Ko as qb,Qo as rb,Xo as sb,Os as tb,Jo as ub,Us as vb,ke as wb,tr as xb,Fh as yb,ct as zb,Ys as Ab,ey as Bb,dt as Cb,mt as Db,dl as Eb,ft as Fb,ar as Gb,lr as Hb,hl as Ib,cr as Jb,mr as Kb,pr as Lb,fr as Mb,gr as Nb,yr as Ob,xr as Pb,Cr as Qb,wr as Rb,Er as Sb,Lr as Tb,H as Ub};