react-iiif-vault 2.0.7 → 2.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import{c as ln,l as un}from"./chunk-FBET7GLW.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 Ci}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,f]=yt(l);return Qr(()=>{(async()=>{try{let c=l&&!t?l:await o.load(n),m=c?c.id||c["@id"]:null;c&&s!==m&&i(m),f(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"),f=r.includes("facing-pages"),c=r.includes("non-paged");if(f||c||u||o)return[{id:i.id,type:"Canvas"}];let[m,h]=St(e,t);if(l)return m;let v=m.findIndex(p=>p.id===n);if(v===-1)return[];for(let p of h)if(p.includes(v))return p.map(S=>m[S]);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((v,p)=>p)]];if(a||!i||n)return[l,l.map((v,p)=>[p])];let u=[],f=[],c=()=>{f.length&&(u.push([...f]),f=[])},m=0,h=!1;for(let v=0;v<l.length;v++){let p=e.get(l[v]);if(p.behavior.includes("non-paged")){v===m&&m++,o||(c(),u.push([v]),c());continue}if(v===m||p.behavior.includes("facing-pages")){f.length&&(h=!0),c(),u.push([v]),c();continue}if(f.push(v),h){c(),h=!1;continue}f.length>1&&c()}return f.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]),f=oi(u);if(f.current!==u){let S=f.current[i][0],y=u.findIndex(d=>d.includes(S));f.current=u,r(y)}let c=We(p=>{let S=u.findIndex(y=>y.includes(p));r(S===-1?0:S)},[l,u]),m=We(p=>{let S=l.findIndex(y=>y.id===p);S!==-1?c(S):r(0)},[l,u]),h=We(()=>{r(p=>p>=u.length-1?p:p+1)},[u]),v=We(()=>{r(p=>p<=0?0:p-1)},[u]);return typeof i>"u"&&(e?m(e):r(0)),{visibleItems:u[i]?.map(p=>l[p].id)||[],cursor:i,items:l,sequence:u,hasPrevious:i>0,hasNext:i<u.length-1,setSequenceIndex:r,setCanvasIndex:c,setCanvasId:m,next:h,previous:v}}import{createContext as bt,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 Cn=()=>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}))}})),bn=(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 f=u.data;if(f.messageId===s){if(t&&f.type!=="AuthAccessToken2"){a(),o("Invalid response, expected type=AuthAccessToken2");return}if(!f.accessToken){a(),o("Invalid response, expected accessToken");return}a(),n(f)}},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 Tn}from"react";import{useStore as ii}from"zustand";function wn(e){let t=Tn(()=>Rn(e),[e]),n=In(t.services.access?.id),o=Tn(()=>bn(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=bt(null),li=bt(null);li.displayName="CurrentAuth";var ui=bt(null);ui.displayName="AuthActions";function kn({children:e}){let t=si(()=>Cn(),[]);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 Ct(){return null}function Vn(e){let[t,n,o]=wn(e.resource),s=e.fallbackComponent||Ct,i=e.loadingComponent||Ct,r=e.errorComponent||Ct,a=n.service,l=null;if(!o||!a)return e.children(t);let u=a.service.filter(f=>f.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 f of u)l=Ue(mi,{service:f,probeId:a.id,children:l},f.id);return l}import{createContext as hi,useContext as Tc,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 f=await u.json();s({resources:f.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 bi(e){let t=B(),{cursor:n,visibleItems:o,next:s,sequence:i,items:r,setCanvasIndex:a,setCanvasId:l,previous:u,setSequenceIndex:f,hasNext:c,hasPrevious:m}=vn({startCanvas:e.startCanvas,disablePaging:e.pagingEnabled===!1}),h=Ci(()=>({sequence:i,items:r,setCurrentCanvasId:l,nextCanvas:s,previousCanvas:u,totalCanvases:r.length,setCurrentCanvasIndex:a,setSequenceIndex:f,currentSequenceIndex:n,hasNext:c,hasPrevious:m}),[i,r,l,s,u,r,a,f,n]);return t?o.length===0?null:F(ze.Provider,{value:h,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(bi,{...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 wi}from"react/jsx-runtime";var Ti=Ri(),At=Ai(Ti);function id({children:e,emitter:t}){return wi(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 Tt(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(f=>f.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 wt(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 Tt({type:"BoxSelector",spatial:{x:s,y:i,width:r,height:a}},t)}return Tt({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:wt({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:wt({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:m=>{s&&console.log("partial state",m),a(h=>({polygonState:{...h.polygonState,...m}}))}},m=>{a(h=>h.tool.requestId?{polygon:{...m,id:h.tool.requestId}}:{polygon:{id:void 0,points:[],open:!0}}),e.emit("atlas.polygon-update",m)});return{mode:"explore",tool:{enabled:!1,requestId:null,canvasId:null},requestType:null,requests:{},history:c.history,polygon:null,validRequestIds:[],metadata:{},stableViewport:null,canvasRelativePositions:{},canvasViewports:{},polygons:c,polygonState:Ei,setMetadata:(m,h)=>{let v=h||l().tool.requestId;v&&a(p=>({metadata:{...p.metadata,[v]:{...p.metadata[v]||{},...m}}}))},setToolCanvasId:m=>{a(h=>({tool:{...h.tool,canvasId:m}}))},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 m=l();m.tool.requestId&&(c.setShape({points:[],open:!0}),m.cancelRequest(m.tool.requestId))}},reset:()=>{let m=l();m.tool.requestId&&m.cancelRequest(m.tool.requestId)},setPolygonState:m=>a({polygonState:typeof m=="function"?m(l().polygonState):m}),getRequestId:()=>{let m=Math.random().toString(36).slice(2);return a(h=>({validRequestIds:[...h.validRequestIds,m]})),{requestId:m,clear:()=>{l().tool.requestId,a(h=>({tool:h.tool.requestId===m?{enabled:!1,requestId:null,canvasId:null}:h.tool,validRequestIds:h.validRequestIds.filter(v=>v!==m)}))}}},cancelRequest:m=>{let h=m||l().tool.requestId;h&&(a(v=>({mode:"explore",tool:v.tool.requestId===h?{enabled:!1,requestId:null,canvasId:null}:v.tool,validRequestIds:v.validRequestIds.filter(p=>p!==h)})),e.emit("atlas.request-cancelled",{id:h}))},requestAnnotation:async(m,h)=>{let p={...l().requests,[h.requestId]:m},S=qn(m);s&&console.log("requestAnnotation",{response:S,request:m});try{let{points:y=[],open:d=!0}=S.polygon||{},{requestId:g,canvasId:x=null,toolId:C}=h,b=C,R=l(),P=R.validRequestIds.includes(g),L=S.requestType;return s&&console.log("setting points",{requestType:L,points:y,open:d}),!P||R.tool.enabled?null:(c.setShape({id:g,points:y,open:d}),L==="polygon"&&(b=b||"pen",c.tools.setTool("pen")),L==="draw"&&(b=b||"draw",c.tools.setTool("pencil")),L==="box"&&(b=b||"box",c.tools.setTool("box")),L==="target"?(b=b||"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)),m.bounds&&c.setBounds(m.bounds),e.emit("atlas.annotation-request",{id:g}),a({polygon:{id:g,points:y,open:d},mode:"sketch",requestType:L,tool:{enabled:!0,requestId:g,canvasId:x},requests:p}),b?R.switchTool[b]?.():y.length===0&&R.switchTool.box(),(typeof m.selectByDefault>"u"&&y.length&&L==="box"||m.selectByDefault)&&R.switchTool.pointer(),new Promise(re=>{let w=T=>{T.id===g&&(a(I=>({mode:"explore",tool:{requestId:null,enabled:!1,canvasId:null},requests:Object.fromEntries(Object.entries(I.requests).filter(([E])=>E!==g))})),e.off("atlas.request-cancelled",w),e.off("atlas.annotation-completed",z),re(null))},z=T=>{T.id===g&&(a(I=>({mode:"explore",tool:{requestId:null,enabled:!1,canvasId:null},requests:Object.fromEntries(Object.entries(I.requests).filter(([E])=>E!==g))})),e.off("atlas.annotation-completed",z),e.off("atlas.request-cancelled",w),re(T))};e.on("atlas.request-cancelled",w),e.on("atlas.annotation-completed",z)}))}catch(y){return console.error(y),null}},completeRequest:m=>{let h=l().tool.requestId;if(typeof m=="string"&&m&&m!==h)return;let v=h?l().requests[h]?.arguments||{}:{},p=h?l().metadata[h]||{}:{},S=l().polygonState.bounds,y=l().polygon;y&&(e.emit("atlas.annotation-completed",{id:y.id,polygon:y,requestType:l().requestType,target:wt(y,S),canvasId:l().tool.canvasId,boundingBox:xe(y),metadata:p,arguments:{...v}}),c.setShape(null))},setAtlasRuntime:m=>{u=m,e.emit("atlas.ready",{runtime:m}),r.setScale(1/u._lastGoodScale),u.world.addLayoutSubscriber((h,v)=>{(h==="event-activation"||h==="zoom-to"||h==="go-home")&&u?._lastGoodScale&&!Number.isNaN(u._lastGoodScale)&&r.setScale(1/u._lastGoodScale)})},clearAtlasRuntime:()=>{u=null,a({stableViewport:null})},setCanvasRelativePosition:(m,h)=>{a(v=>({canvasRelativePositions:{...v.canvasRelativePositions,[m]:h}}))},clearCanvasRelativePosition:m=>{a(h=>{let v={...h.canvasRelativePositions};return delete v[m],{canvasRelativePositions:v}})},changeMode:m=>{a({mode:m})},nudgeLeft:()=>{},nudgeRight:()=>{},nudgeUp:()=>{},nudgeDown:()=>{},zoomIn:()=>{u?.world?.zoomIn()},zoomOut:()=>{u?.world?.zoomOut()},goHome:()=>{u?.world?.goHome()}}}),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 Ce=Ni(null);function q(){return Wn(Ce)}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(Ce),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(Ce.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 wd({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(`
1
+ import{c as ln,l as un}from"./chunk-FBET7GLW.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 Ci}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,f]=yt(l);return Qr(()=>{(async()=>{try{let c=l&&!t?l:await o.load(n),m=c?c.id||c["@id"]:null;c&&s!==m&&i(m),f(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"),f=r.includes("facing-pages"),c=r.includes("non-paged");if(f||c||u||o)return[{id:i.id,type:"Canvas"}];let[m,h]=St(e,t);if(l)return m;let v=m.findIndex(p=>p.id===n);if(v===-1)return[];for(let p of h)if(p.includes(v))return p.map(S=>m[S]);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((v,p)=>p)]];if(a||!i||n)return[l,l.map((v,p)=>[p])];let u=[],f=[],c=()=>{f.length&&(u.push([...f]),f=[])},m=0,h=!1;for(let v=0;v<l.length;v++){let p=e.get(l[v]);if(p.behavior.includes("non-paged")){v===m&&m++,o||(c(),u.push([v]),c());continue}if(v===m||p.behavior.includes("facing-pages")){f.length&&(h=!0),c(),u.push([v]),c();continue}if(f.push(v),h){c(),h=!1;continue}f.length>1&&c()}return f.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]),f=oi(u);if(f.current!==u){let S=f.current[i][0],y=u.findIndex(d=>d.includes(S));f.current=u,r(y)}let c=We(p=>{let S=u.findIndex(y=>y.includes(p));r(S===-1?0:S)},[l,u]),m=We(p=>{let S=l.findIndex(y=>y.id===p);S!==-1?c(S):r(0)},[l,u]),h=We(()=>{r(p=>p>=u.length-1?p:p+1)},[u]),v=We(()=>{r(p=>p<=0?0:p-1)},[u]);return typeof i>"u"&&(e?m(e):r(0)),{visibleItems:u[i]?.map(p=>l[p].id)||[],cursor:i,items:l,sequence:u,hasPrevious:i>0,hasNext:i<u.length-1,setSequenceIndex:r,setCanvasIndex:c,setCanvasId:m,next:h,previous:v}}import{createContext as bt,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 Cn=()=>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}))}})),bn=(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 f=u.data;if(f.messageId===s){if(t&&f.type!=="AuthAccessToken2"){a(),o("Invalid response, expected type=AuthAccessToken2");return}if(!f.accessToken){a(),o("Invalid response, expected accessToken");return}a(),n(f)}},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 Tn}from"react";import{useStore as ii}from"zustand";function wn(e){let t=Tn(()=>Rn(e),[e]),n=In(t.services.access?.id),o=Tn(()=>bn(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=bt(null),li=bt(null);li.displayName="CurrentAuth";var ui=bt(null);ui.displayName="AuthActions";function kn({children:e}){let t=si(()=>Cn(),[]);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 Ct(){return null}function Vn(e){let[t,n,o]=wn(e.resource),s=e.fallbackComponent||Ct,i=e.loadingComponent||Ct,r=e.errorComponent||Ct,a=n.service,l=null;if(!o||!a)return e.children(t);let u=a.service.filter(f=>f.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 f of u)l=Ue(mi,{service:f,probeId:a.id,children:l},f.id);return l}import{createContext as hi,useContext as Tc,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 f=await u.json();s({resources:f.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 bi(e){let t=B(),{cursor:n,visibleItems:o,next:s,sequence:i,items:r,setCanvasIndex:a,setCanvasId:l,previous:u,setSequenceIndex:f,hasNext:c,hasPrevious:m}=vn({startCanvas:e.startCanvas,disablePaging:e.pagingEnabled===!1}),h=Ci(()=>({sequence:i,items:r,setCurrentCanvasId:l,nextCanvas:s,previousCanvas:u,totalCanvases:r.length,setCurrentCanvasIndex:a,setSequenceIndex:f,currentSequenceIndex:n,hasNext:c,hasPrevious:m}),[i,r,l,s,u,r,a,f,n]);return t?o.length===0?null:F(ze.Provider,{value:h,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(bi,{...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 wi}from"react/jsx-runtime";var Ti=Ri(),At=Ai(Ti);function id({children:e,emitter:t}){return wi(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 Tt(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(f=>f.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 wt(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 Tt({type:"BoxSelector",spatial:{x:s,y:i,width:r,height:a}},t)}return Tt({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:wt({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:wt({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:m=>{s&&console.log("partial state",m),a(h=>({polygonState:{...h.polygonState,...m}}))}},m=>{a(h=>h.tool.requestId?{polygon:{...m,id:h.tool.requestId}}:{polygon:{id:void 0,points:[],open:!0}}),e.emit("atlas.polygon-update",m)});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:(m,h)=>{let v=h||l().tool.requestId;v&&a(p=>({metadata:{...p.metadata,[v]:{...p.metadata[v]||{},...m}}}))},setToolCanvasId:m=>{a(h=>({tool:{...h.tool,canvasId:m}}))},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 m=l();m.tool.requestId&&(c.setShape({points:[],open:!0}),m.cancelRequest(m.tool.requestId))}},reset:()=>{let m=l();m.tool.requestId&&m.cancelRequest(m.tool.requestId)},setPolygonState:m=>a({polygonState:typeof m=="function"?m(l().polygonState):m}),getRequestId:()=>{let m=Math.random().toString(36).slice(2);return a(h=>({validRequestIds:[...h.validRequestIds,m]})),{requestId:m,clear:()=>{l().tool.requestId,a(h=>({tool:h.tool.requestId===m?{enabled:!1,requestId:null,canvasId:null}:h.tool,validRequestIds:h.validRequestIds.filter(v=>v!==m)}))}}},cancelRequest:m=>{let h=m||l().tool.requestId;h&&(a(v=>({mode:"explore",tool:v.tool.requestId===h?{enabled:!1,requestId:null,canvasId:null}:v.tool,validRequestIds:v.validRequestIds.filter(p=>p!==h)})),e.emit("atlas.request-cancelled",{id:h}))},requestAnnotation:async(m,h)=>{let p={...l().requests,[h.requestId]:m},S=qn(m);s&&console.log("requestAnnotation",{response:S,request:m});try{let{points:y=[],open:d=!0}=S.polygon||{},{requestId:g,canvasId:x=null,toolId:C}=h,b=C,R=l(),P=R.validRequestIds.includes(g),L=S.requestType;return s&&console.log("setting points",{requestType:L,points:y,open:d}),!P||R.tool.enabled?null:(c.setShape({id:g,points:y,open:d}),L==="polygon"&&(b=b||"pen",c.tools.setTool("pen")),L==="draw"&&(b=b||"draw",c.tools.setTool("pencil")),L==="box"&&(b=b||"box",c.tools.setTool("box")),L==="target"?(b=b||"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)),m.bounds&&c.setBounds(m.bounds),e.emit("atlas.annotation-request",{id:g}),a({polygon:{id:g,points:y,open:d},mode:"sketch",requestType:L,tool:{enabled:!0,requestId:g,canvasId:x},requests:p}),b?R.switchTool[b]?.():y.length===0&&R.switchTool.box(),(typeof m.selectByDefault>"u"&&y.length&&L==="box"||m.selectByDefault)&&R.switchTool.pointer(),new Promise(re=>{let w=T=>{T.id===g&&(a(I=>({mode:"explore",tool:{requestId:null,enabled:!1,canvasId:null},requests:Object.fromEntries(Object.entries(I.requests).filter(([E])=>E!==g))})),e.off("atlas.request-cancelled",w),e.off("atlas.annotation-completed",z),re(null))},z=T=>{T.id===g&&(a(I=>({mode:"explore",tool:{requestId:null,enabled:!1,canvasId:null},requests:Object.fromEntries(Object.entries(I.requests).filter(([E])=>E!==g))})),e.off("atlas.annotation-completed",z),e.off("atlas.request-cancelled",w),re(T))};e.on("atlas.request-cancelled",w),e.on("atlas.annotation-completed",z)}))}catch(y){return console.error(y),null}},completeRequest:m=>{let h=l().tool.requestId;if(typeof m=="string"&&m&&m!==h)return;let v=h?l().requests[h]?.arguments||{}:{},p=h?l().metadata[h]||{}:{},S=l().polygonState.bounds,y=l().polygon;y&&(e.emit("atlas.annotation-completed",{id:y.id,polygon:y,requestType:l().requestType,target:wt(y,S),canvasId:l().tool.canvasId,boundingBox:xe(y),metadata:p,arguments:{...v}}),c.setShape(null))},setAtlasRuntime:m=>{u=m,e.emit("atlas.ready",{runtime:m}),r.setScale(1/u._lastGoodScale),u.world.addLayoutSubscriber((h,v)=>{(h==="event-activation"||h==="zoom-to"||h==="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:(m,h)=>{a(v=>({canvasRelativePositions:{...v.canvasRelativePositions,[m]:h}}))},clearCanvasRelativePosition:m=>{a(h=>{let v={...h.canvasRelativePositions};return delete v[m],{canvasRelativePositions:v}})},changeMode:m=>{a({mode:m})},nudgeLeft:()=>{},nudgeRight:()=>{},nudgeUp:()=>{},nudgeDown:()=>{},zoomIn:()=>{u?.world?.zoomIn()},zoomOut:()=>{u?.world?.zoomOut()},goHome:()=>{u?.world?.goHome()}}}),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 Ce=Ni(null);function q(){return Wn(Ce)}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(Ce),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(Ce.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 wd({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
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(f=>r?f.iiif.entities.Annotation[r]:void 0,[r]),[l]=Kn(a?.stylesheet),u=k(f=>a&&a.body?a.body.map(c=>c?c.type==="SpecificResource"?{...c,source:i.get(c)}:c?f.iiif.entities[c.type][c.id]:null:null).filter(Boolean):[],[a]);return Ki(()=>{if(!a)return;let f={...a,body:u,target:ji(a.target,{typeMap:i.getState().iiif.mapping,loadedStylesheets:l})};return o?o(f):f},[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 be(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:f,mouseEvent:c,isEditing:m}=Ji({x:a.x||0,y:a.y||0,width:a.width,height:a.height,aspectRatio:r,maintainAspectRatio:s},n),h=te(()=>c("translate"),[c]),v=te(()=>c("east"),[c]),p=te(()=>c("west"),[c]),S=te(()=>c("south"),[c]),y=te(()=>c("north"),[c]),d=te(()=>c("south-east"),[c]),g=te(()=>c("south-west"),[c]),x=te(()=>c("north-east"),[c]),C=te(()=>c("north-west"),[c]),b=f==="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:m?"none":b?"initial":"none"};return K(kt,{children:Et("world-object",{...a,children:[o,b&&t?K(Zi,{ref:u,target:{x:0,y:0,height:a.height,width:a.width},relative:!0,interactive:!1,children:b&&t?Et(kt,{children:[K("div",{onMouseDown:h,onTouchStart:h,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:m?"none":b?"initial":"none"}}),s?null:Et(kt,{children:[K("div",{title:"east",onTouchStart:v,onMouseDown:v,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:p,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:y,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:S,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:x,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:d,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:g,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:C,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:f={backgroundColor:"rgba(0,0,0,.5)"}}){let c=ea(m=>{u&&i?.({id:n.id,x:n.x,y:n.y,height:n.height,width:n.width,...m})},[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:m=>{m.preventDefault(),m.stopPropagation(),o?.(n)},relativeStyle:!0,onMouseEnter:()=>{s?.(n)},target:{x:0,y:0,width:n.width,height:n.height},style:f})})}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=be(r,"atlas"),l=be(r,"html"),u=Ke(r,["atlas"]),f=A(),c=jn(),m=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]),h=s||f?.id;return f&&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===h||r.target.source===h)?na(Xn,{id:r.id,isEditing:!0,region:r.target.selector.spatial,style:m,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=be(s,"atlas"),r=be(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():f())},[a]),f=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"}))},[]),m=Q(()=>{o.current&&(o.current.muted=!0,n({type:"MUTE"}))},[]),h=Q(()=>{o.current&&(o.current.muted=!1,n({type:"UNMUTE"}))},[]),v=Q(y=>{o.current&&(o.current.muted=!1,o.current.volume=y/100,n({type:"SET_VOLUME",volume:y}))},[]),p=Q(y=>{o.current&&(o.current.currentTime=Math.max(0,Math.min(y*e.duration,e.duration)),a())},[]),S=Q(y=>{if(o.current){let d=typeof y=="function"?y(o.current.currentTime):y;o.current.currentTime=Math.max(0,Math.min(d,e.duration)),a()}},[]);return zt(()=>{let y=setInterval(()=>{a()},350);return()=>clearInterval(y)},[a,e.duration]),zt(()=>{let y=()=>{n({type:"FINISHED"})},d=o.current;return d?.addEventListener("ended",y),()=>d?.removeEventListener("ended",y)},[]),[{element:o,currentTime:s,progress:i},t,{play:l,pause:f,playPause:u,mute:m,unmute:h,toggleMute:c,setVolume:v,setDurationPercent:p,setTime:S}]}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:`
3
3
  .model-container {
4
4
  position: absolute;
@@ -46,4 +46,4 @@ import{c as ln,l as un}from"./chunk-FBET7GLW.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",ws,{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(Te,{}),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(),f=Z(),c=Z(),m=Z(),[h,v]=Zo(null),[p,S]=Zo(!1),{helper:y,state:d,currentShape:g}=Xo((w,z)=>{if(w.closestLineIndex,oe.updateTransitionBoundingBox(i.current,w,z),oe.updateBoundingBoxPolygon(o.current,w,z),oe.updateBoundingBoxPolygon(s.current,w,z),oe.updateTransitionShape(u.current,w,z),oe.updateClosestLinePointTransform(a.current,w,z),oe.updateSelectBox(r.current,w,z),oe.updatePointLine(f.current,w,z),oe.updateDrawPreview(l.current,w,z,3),oe.updateLineBox(c.current,w),v(w.transitionDirection),S(w.transitionRotate),w.closestLineIndex!==-1&&m.current){let T=w.polygon,I=T.points[w.closestLineIndex],E=T.points[(w.closestLineIndex+1)%T.points.length];I&&E&&m.current.setAttribute("points",`${I[0]},${I[1]} ${E[0]},${E[1]}`)}});Vs(()=>{let w=()=>{y.modifiers.reset()};return document.addEventListener("mouseleave",w),()=>{document.removeEventListener("mouseleave",w)}},[]);let x=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})]})]}),C=g?g.open?"polyline":"polygon":null,b=!d.showBoundingBox&&d.closestPoint!==null&&d.actionIntentType==="select-point",R=d.actionIntentType==="add-open-point",P=d.transitionIntentType==="split-line",L=d.transitioning&&d.selectedStamp&&d.transitionIntentType==="stamp-shape",re=g&&C?Me(Zt,{children:[N(C,{fill:(!d.transitioning||d.transitionIntentType==="select-multiple-points")&&!g.open?n.shapeFill:"none",strokeWidth:L||d.showBoundingBox&&d.boxMode||d.transitioning&&d.transitionIntentType==="split-line"||d.transitioning&&d.transitionIntentType==="move-point"?0:2,stroke:n.shapeStroke,points:g.points.map(w=>w.join(",")).join(" "),vectorEffect:"non-scaling-stroke",markerStart:d.showBoundingBox?void 0:d.boxMode?"url(#resizer)":"url(#dot)",markerMid:d.showBoundingBox?void 0:d.boxMode?"url(#resizer)":"url(#dot)",markerEnd:d.showBoundingBox?void 0:d.boxMode?"url(#resizer)":"url(#dot)",style:{pointerEvents:"none"},opacity:d.transitioning&&d.transitionIntentType==="move-shape"?0:1}),d.currentTool==="lineBox"&&d.actionIntentType==="close-line-box"?N("polygon",{fill:n.shapeFill,ref:c,stroke:n.lineStroke,strokeWidth:2,vectorEffect:"non-scaling-stroke"}):null,d.transitionIntentType==="draw-shape"&&d.transitioning?N("polyline",{ref:l,fill:"none",stroke:n.activeLineStroke,strokeWidth:2,vectorEffect:"non-scaling-stroke"}):null,!(d.transitioning&&d.transitionIntentType==="move-point")&&!(d.transitioning&&d.transitionIntentType==="stamp-shape")&&!d.showBoundingBox&&d.selectedPoints&&d.selectedPoints.length?N("polyline",{strokeWidth:2,vectorEffect:"non-scaling-stroke",stroke:"transparent",markerStart:"url(#selected)",markerMid:"url(#selected)",markerEnd:"url(#selected)",fill:"transparent",points:g.points.filter((w,z)=>d.selectedPoints?.includes(z)).map(w=>w.join(",")).join(" "),opacity:d.transitioning&&d.transitionIntentType==="move-shape"?0:1}):null,b&&!d.transitioning&&d.closestPoint!==null&&g.points[d.closestPoint]?N("polyline",{strokeWidth:2,vectorEffect:"non-scaling-stroke",stroke:"transparent",markerStart:"url(#selected)",markerMid:"url(#selected)",markerEnd:"url(#selected)",fill:n.activeLineStroke,points:`${g.points[d.closestPoint][0]},${g.points[d.closestPoint][1]}`,opacity:d.transitioning&&d.transitionIntentType==="move-shape"?0:1}):null,!d.transitioning&&(d.actionIntentType==="add-open-point"||d.actionIntentType==="close-shape"||d.actionIntentType==="close-shape-line")?N("polyline",{stroke:n.activeLineStroke,ref:f,strokeWidth:d.actionIntentType==="add-open-point"?1:2,vectorEffect:"non-scaling-stroke"}):null,d.hasClosestLine&&!d.showBoundingBox&&!d.transitioning&&d.currentTool!=="box"&&d.transitionIntentType==="split-line"?N("g",{children:N("polyline",{ref:m,vectorEffect:"non-scaling-stroke",fill:"transparent",stroke:n.activeLineStroke,strokeWidth:3})}):null,d.hasClosestLine&&!d.showBoundingBox&&!d.transitioning&&d.currentTool!=="box"&&d.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,d.transitioning?N(C,{ref:u,fill:g.open?"none":n.shapeFill,stroke:d.transitionIntentType==="stamp-shape"?n.activeLineStroke:n.shapeStroke,vectorEffect:"non-scaling-stroke",strokeWidth:(g.open,2)}):null,d.transitioning&&d.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,d.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:y.state.slowState.currentTool,setCurrentTool:y.tools.setTool,helper:y,currentShape:g,state:d,isAddingPoint:R,isSplitting:P,isStamping:L,isHoveringPoint:b,transitionDirection:h,transitionRotate:p,defs:x,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:f,isAddingPoint:c}=Jo({image:e.image,theme:e.theme}),m=Jt(p=>{p.button!==2&&o.pointer([[~~p.atlas.x,~~p.atlas.y]])},[o]),h=Jt(p=>{p.button!==2&&o.pointerDown()},[o]),v=Jt(p=>{p.button!==2&&o.pointerUp()},[o]);return en(()=>{let p=S=>{o.key.up(S.key)};return document.addEventListener("keyup",p),()=>{document.removeEventListener("keyup",p)}},[o]),en(()=>{let p=S=>{S.target&&["INPUT","TEXTAREA"].includes(S.target.tagName)||S.target?.isContentEditable||document.activeElement&&(document.activeElement instanceof HTMLInputElement||document.activeElement instanceof HTMLTextAreaElement||document.activeElement.isContentEditable)||o.key.down(S.key)};return document.addEventListener("keydown",p),()=>{document.removeEventListener("keydown",p)}},[o]),en(()=>{let p=[];return a&&p.push(`atlas-cursor-${a}`),r.actionIntentType==="cut-line"&&r.modifiers?.Shift&&p.push("atlas-cursor-cut"),(f||r.transitionIntentType==="move-shape"||r.transitionIntentType==="move-point")&&p.push("atlas-cursor-move"),c&&p.push("atlas-cursor-crosshair"),l&&p.push("atlas-cursor-copy"),u&&p.push("atlas-cursor-rotate"),r.transitionIntentType==="draw-shape"&&p.push("atlas-cursor-draw"),t?.canvas&&t.canvas.classList.add(...p),()=>{t?.canvas&&t.canvas.classList.remove(...p)}},[t?.canvas,c,f,l,r.modifiers?.Shift,r.actionIntentType,r.transitionIntentType,a,u]),De("world-object",{height:n.height,width:n.width,onMouseMove:m,onMouseDown:h,onMouseUp:v,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(Ce)}}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(Ce.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:f,context:c}=Zs({open:s,onOpenChange:i,nodeId:e.id,placement:r||"bottom",middleware:[Gs(10),Qs(),Ys({mainAxis:!0})],whileElementsMounted:Ks}),m=Xs(c),{getReferenceProps:h,getFloatingProps:v}=Js([o?m:null].filter(p=>p!==null));return tl(js,{relative:!0,target:t,interactive:!1,children:[tn("div",{ref:u.setReference,...h(),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:f,...v(),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(),f=nl(h=>{n&&(h.preventDefault(),h.stopPropagation(),u(h.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:f},{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,C=>C.polygon),r=J(o,C=>C.polygonState.currentTool),a=J(o,C=>C.mode),l=J(o,C=>C.changeMode),u=J(o,C=>C.polygonState.transitioning),{enabled:f,requestId:c}=J(o,C=>C.tool),m=ll(()=>xe(i),[i]),h=or(),[v,p]=ft("editing-annotation",s?.id,t),S=h?.annotationPopup||n||ae(ul,{}),y=h?.svgTheme||e,d=()=>{l("sketch")};if(!f||!s||!c||!i)return null;let g=m&&i.id&&!u&&(r==="pointer"||r==="hand"||!i.open)?ae(pt,{annotation:i,target:m,children:S}):null,x="shape";return a==="explore"?nn(rr,{children:[ae(x,{id:`shape-${i.id}`,points:i.points,open:i.open,onClick:d,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)"},...p}),ae(x,{id:`shape-${i.id}`,points:i.points,open:i.open,onClick:d,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)"}}),g]}):nn(rr,{children:[t?ae(x,{id:`shape-${i.id}`,points:i.points,open:i.open,target:{x:0,y:0,width:s.width,height:s.height},...p}):null,ae(er,{image:s,theme:y}),g,v]})}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(f=>{e&&n.setMetaValue([f,"annotationPageManager","views"],c=>c&&!c[e]?c:{...c||{},[e]:!1})},[e,n]),u=lr((f,c={})=>{if(!e)return;let m=n.getState(),h=[];if(c?.deselectOthers){let v=Object.keys(m.iiif.entities.AnnotationPage);for(let p of v){let S=ml(m,p);S&&S.views&&S.views[e]&&h.push(p)}}for(let v of h)l(v);n.setMetaValue([f,"annotationPageManager","views"],v=>v&&v[e]?v:{...v||{},[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=To();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((f,{deselectOthers:c=!0,deselect:m=!1}={})=>{a.choice&&r(h=>{if(m){let p=h.filter(S=>S!==f);if(p.length===0){let S=a.items[0].resource.id;return S?[S]:[]}return p}if(c)return[f];let v=[...h];if(v.length===0&&a.items.length){let p=a.items[0].resource.id;p&&v.push(p)}return h.indexOf(f)!==-1?h:[...h,f]})},[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"),f=e?.strategies||["empty","images","media","textual-content","complex-timeline"],[c,m]=fr(e,[a]);gr(()=>{let v=p=>{m.makeChoice(p.choiceId,{deselectOthers:p.deselectOthers,deselect:p.deselect})};return i.on("make-choice",v),()=>{i.off("make-choice",v)}},[]);let h=hr(()=>un({canvas:n,paintables:c,supports:f,loadImageService:r,vault:o}),[n,c,o,m.makeChoice]);return gr(()=>{let v=c.allChoices,p={canvasId:n?.id,manifestId:t?.id};v&&i.emit("choice-change",{choice:v,partOf:p})},[n?.id,c.allChoices]),hr(()=>h.type==="unknown"?[h,ln]:[{...h,annotations:{pages:u}},m],[h,u])}import{createStylesHelper as Cl}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:f,children:c}){let m=A(),h=M(),v=rn(()=>Cl(h),[h]),[p,S]=yr({strategies:e||["images"],defaultChoices:n?.map(({id:x})=>x)}),y="choice"in p?p.choice:void 0;if(on(()=>{t&&t(S)},[p.annotations]),on(()=>{o&&o(y)},[y]),on(()=>{if(n)for(let x of n)typeof x.opacity<"u"&&v.applyStyles({id:x.id},"atlas",{opacity:x.opacity})},[n]),p.type==="unknown"&&f)throw new Error(p.reason||"Unknown strategy");let d=rn(()=>({renderMediaControls:i,mediaControlsDeps:s||[],renderViewerControls:r,viewControlsDeps:a||[],renderComplexTimelineControls:l,complexTimelineControlsDeps:u||[]}),[s,i,r,a,l,u]),g=rn(()=>({strategy:p,actions:S,choices:"choice"in p?p.choice:[]}),[p,m]);return vr(et.Provider,{value:d,children:vr(ce.Provider,{value:g,children:c})})}import{useEffect as Cr,useMemo as Pl}from"react";import{useStore as br}from"zustand";import{createContext as bl,useContext as Rl,useEffect as Al}from"react";var an=bl(()=>{});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 Tl}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=br(a,p=>p.setCanvasRelativePosition),f=br(a,p=>p.clearCanvasRelativePosition),[c,m]=ft(`context-menu/${r?.id}`,r?.id,o),h=Pl(()=>n?1:Math.max(1,...i.type==="images"?i.images.map(p=>(p.width||0)/p.target?.spatial.width):[]),[n,i]);Cr(()=>{if(r)return u(r.id,{x:e,y:t,width:r.width,height:r.height}),()=>{f(r.id)}},[e,t,r,f,u]),Cr(()=>{r&&a.getState().reset()},[a,r]),xr(h);let v=i.type==="images"?i.images.length:0;return r?Tl("world-object",{height:r.height,width:r.width,x:e,y:t,...m,...l,children:[c,s]},`${r.id}/${i.type}/${v}`):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:f,mediaControlsDeps:c,strategies:m,throwOnUnknown:h,backgroundStyle:v,alwaysShowBackground:p,keepCanvasScale:S=!1,enableSizes:y=!1,enableYouTube:d=!0,onClickPaintingAnnotation:g,components:x={},children:C,annotationPopup:b,svgTheme:R,renderContextMenu:P,renderAnnotationContextMenu:L}){return Ar(Sr,{throwOnUnknown:h,onChoiceChange:n,registerActions:o,strategies:m,defaultChoices:s,mediaControlsDeps:c,renderMediaControls:a,renderViewerControls:r,renderComplexTimelineControls:l,complexTimelineControlsDeps:u,viewControlsDeps:f,children:[Ar(Rr,{keepCanvasScale:S,x:e,y:t,renderContextMenu:P,children:[Y(Wo,{alwaysShowBackground:p,backgroundStyle:v}),Y(Fo,{}),Y(_o,{}),Y(Uo,{isStatic:i,enableSizes:y,onClickPaintingAnnotation:g}),Y(ho,{}),Y(io,{}),Y(xo,{as:x.Audio}),Y(Ko,{as:x.Video}),d?Y(Qo,{}):null,Y(ir,{theme:R,renderContextMenu:L,children:b}),C]}),Y(ao,{})]})}import{jsx as Pr}from"react/jsx-runtime";function Tr(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 wl,useMemo as Il}from"react";function wr(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();wl(()=>{let u=setInterval(()=>{if(e&&t!==-1){let f={x:e.x,y:e.y,width:e.width,height:e.height},c=a.getState().canvasRelativePositions,m={};for(let h of r){let v=c[h.id];if(v){let p=v.x,S=v.y,y=v.width,d=v.height,g={x:Math.max(p,f.x),y:Math.max(S,f.y),width:Math.min(p+y,f.x+f.width)-Math.max(p,f.x),height:Math.min(S+d,f.y+f.height)-Math.max(S,f.y)};g.width<=0||g.height<=0||(m[h.id]={x:g.x-v.x,y:g.y-v.y,width:g.width,height:g.height}),a.setState({canvasViewports:m})}}}},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,T=>T.mode),u=kr(a,T=>T.setAtlasRuntime),[f,c]=ht(),m=ct(),h=dt(),v=n||Ir,[p,S]=ht({}),y=Object.entries(p),[d,g]=ht({}),x=Object.entries(d),[C,b]=ht({}),{worldScale:R,runtimeOptions:P}=El(()=>{if(Object.values(C).length===0)return{worldScale:1,runtimeOptions:r.runtimeOptions||{maxOverZoom:1}};let I=Math.max(...Object.values(C));return{worldScale:I,runtimeOptions:{maxOverZoom:I||1,...r.runtimeOptions||{}}}},[C,r.runtimeOptions]);wr(f?.runtime,i);let L=gt((T,I)=>{b(E=>{if(I===-1){let{[T]:Ee,...se}=E;return se}return{...E,[T]:I}})},[]),re=gt((T,I,E)=>{S(({[T]:Ee,...se})=>I?{...se,[T]:{element:I,props:E}}:se)},[]),w=gt((T,I,E)=>{g(({[T]:Ee,...se})=>I?{...se,[T]:{element:I,props:E}}:se)},[]),z=gt(T=>{c(T),u(T.runtime),r.onCreated&&r.onCreated(T)},[r.onCreated,u]);return zl(Vl,{resetKeys:[],fallbackRender:T=>O(v,{...r,...T}),children:[O(kl,{...r,mode:l,containerProps:{style:{position:"relative"},...r.containerProps||{}},htmlChildren:O(Ll,{children:y.map(([T,{element:I,props:E}])=>O(Mr.Fragment,{children:O(I,{...E||{}})},T))}),onCreated:z,runtimeOptions:P,children:O(Oe,{name:e,existing:a,children:O(fe.Provider,{value:f,children:O(an.Provider,{value:L,children:O(Bt.Provider,{value:re,children:O(Ht.Provider,{value:w,children:O(mt,{bridge:h,custom:m,children:O(fo,{children:t})})})})})})})}),O("div",{children:x.map(([T,{element:I,props:E}])=>O(Mr.Fragment,{children:O(I,{...E||{}})},T))}),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,f=o.viewingDirection==="top-to-bottom",c=o.viewingDirection==="bottom-to-top",m=o.viewingDirection==="left-to-right",h=o.viewingDirection==="right-to-left",p=o.behavior.includes("continuous")?0:t.spacing||0,S=c||h,y=Bl(()=>S?[...s].reverse():s,[s,S]);return ql(Dl,{children:[t.header,G(H.Viewer,{height:t.height,mode:t.mode,renderPreset:t.renderPreset,runtimeOptions:t.runtimeOptions,updateViewportTimeout:t.updateViewportTimeout,children:y.map((d,g)=>{let x=0,C=0;return!f&&!c?(x=u,u+=d.width+p):(C=u,u+=d.height+p),G(ee,{canvas:d.id,children:G(H.RenderCanvas,{strategies:["3d-model","media","images","empty","textual-content","complex-timeline"],renderViewerControls:g===0&&r?()=>G(r,{}):void 0,renderMediaControls:g===0&&a?()=>G(a,{}):void 0,annotationPopup:t.annotationPopup,renderContextMenu:t.renderContextMenu,keepCanvasScale:t.keepCanvasScale,renderComplexTimelineControls:g===0&&l?()=>G(l,{}):void 0,renderAnnotationContextMenu:t.renderAnnotationContextMenu,x,y:C,svgTheme:t.svgTheme,...t.canvasProps||{},children:t.annotations},d.id)},d.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:f,runtimeOptions:c,annotationPopup:m,name:h,svgTheme:v,updateViewportTimeout:p,renderContextMenu:S,keepCanvasScale:y,renderAnnotationContextMenu:d,...g},x){let C=ye();return G(Oe,{name:h,children:G(ge,{vault:C,children:G(On,{...g,children:G(Hl,{ref:x,height:n,components:a,spacing:i,canvasProps:s,annotations:o,header:r,mode:l,reuseAtlas:u,renderPreset:f,runtimeOptions:c,annotationPopup:m,svgTheme:v,updateViewportTimeout:p,renderContextMenu:S,keepCanvasScale:y,renderAnnotationContextMenu:d,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=Tr;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,Cn as z,bn 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,bi 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,Tt as ba,wt as ca,qn as da,$n as ea,Ce as fa,q as ga,Un as ha,Oe as ia,_n as ja,jn as ka,wd as la,_i as ma,Kn as na,je as oa,A as pa,Ke as qa,be 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,Te as Ua,xo as Va,Co as Wa,cf as Xa,rt as Ya,Cf as Za,Pf as _a,Tf as $a,wf 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",ws,{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(Te,{}),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(),f=Z(),c=Z(),m=Z(),[h,v]=Zo(null),[p,S]=Zo(!1),{helper:y,state:d,currentShape:g}=Xo((w,z)=>{if(w.closestLineIndex,oe.updateTransitionBoundingBox(i.current,w,z),oe.updateBoundingBoxPolygon(o.current,w,z),oe.updateBoundingBoxPolygon(s.current,w,z),oe.updateTransitionShape(u.current,w,z),oe.updateClosestLinePointTransform(a.current,w,z),oe.updateSelectBox(r.current,w,z),oe.updatePointLine(f.current,w,z),oe.updateDrawPreview(l.current,w,z,3),oe.updateLineBox(c.current,w),v(w.transitionDirection),S(w.transitionRotate),w.closestLineIndex!==-1&&m.current){let T=w.polygon,I=T.points[w.closestLineIndex],E=T.points[(w.closestLineIndex+1)%T.points.length];I&&E&&m.current.setAttribute("points",`${I[0]},${I[1]} ${E[0]},${E[1]}`)}});Vs(()=>{let w=()=>{y.modifiers.reset()};return document.addEventListener("mouseleave",w),()=>{document.removeEventListener("mouseleave",w)}},[]);let x=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})]})]}),C=g?g.open?"polyline":"polygon":null,b=!d.showBoundingBox&&d.closestPoint!==null&&d.actionIntentType==="select-point",R=d.actionIntentType==="add-open-point",P=d.transitionIntentType==="split-line",L=d.transitioning&&d.selectedStamp&&d.transitionIntentType==="stamp-shape",re=g&&C?Me(Zt,{children:[N(C,{fill:(!d.transitioning||d.transitionIntentType==="select-multiple-points")&&!g.open?n.shapeFill:"none",strokeWidth:L||d.showBoundingBox&&d.boxMode||d.transitioning&&d.transitionIntentType==="split-line"||d.transitioning&&d.transitionIntentType==="move-point"?0:2,stroke:n.shapeStroke,points:g.points.map(w=>w.join(",")).join(" "),vectorEffect:"non-scaling-stroke",markerStart:d.showBoundingBox?void 0:d.boxMode?"url(#resizer)":"url(#dot)",markerMid:d.showBoundingBox?void 0:d.boxMode?"url(#resizer)":"url(#dot)",markerEnd:d.showBoundingBox?void 0:d.boxMode?"url(#resizer)":"url(#dot)",style:{pointerEvents:"none"},opacity:d.transitioning&&d.transitionIntentType==="move-shape"?0:1}),d.currentTool==="lineBox"&&d.actionIntentType==="close-line-box"?N("polygon",{fill:n.shapeFill,ref:c,stroke:n.lineStroke,strokeWidth:2,vectorEffect:"non-scaling-stroke"}):null,d.transitionIntentType==="draw-shape"&&d.transitioning?N("polyline",{ref:l,fill:"none",stroke:n.activeLineStroke,strokeWidth:2,vectorEffect:"non-scaling-stroke"}):null,!(d.transitioning&&d.transitionIntentType==="move-point")&&!(d.transitioning&&d.transitionIntentType==="stamp-shape")&&!d.showBoundingBox&&d.selectedPoints&&d.selectedPoints.length?N("polyline",{strokeWidth:2,vectorEffect:"non-scaling-stroke",stroke:"transparent",markerStart:"url(#selected)",markerMid:"url(#selected)",markerEnd:"url(#selected)",fill:"transparent",points:g.points.filter((w,z)=>d.selectedPoints?.includes(z)).map(w=>w.join(",")).join(" "),opacity:d.transitioning&&d.transitionIntentType==="move-shape"?0:1}):null,b&&!d.transitioning&&d.closestPoint!==null&&g.points[d.closestPoint]?N("polyline",{strokeWidth:2,vectorEffect:"non-scaling-stroke",stroke:"transparent",markerStart:"url(#selected)",markerMid:"url(#selected)",markerEnd:"url(#selected)",fill:n.activeLineStroke,points:`${g.points[d.closestPoint][0]},${g.points[d.closestPoint][1]}`,opacity:d.transitioning&&d.transitionIntentType==="move-shape"?0:1}):null,!d.transitioning&&(d.actionIntentType==="add-open-point"||d.actionIntentType==="close-shape"||d.actionIntentType==="close-shape-line")?N("polyline",{stroke:n.activeLineStroke,ref:f,strokeWidth:d.actionIntentType==="add-open-point"?1:2,vectorEffect:"non-scaling-stroke"}):null,d.hasClosestLine&&!d.showBoundingBox&&!d.transitioning&&d.currentTool!=="box"&&d.transitionIntentType==="split-line"?N("g",{children:N("polyline",{ref:m,vectorEffect:"non-scaling-stroke",fill:"transparent",stroke:n.activeLineStroke,strokeWidth:3})}):null,d.hasClosestLine&&!d.showBoundingBox&&!d.transitioning&&d.currentTool!=="box"&&d.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,d.transitioning?N(C,{ref:u,fill:g.open?"none":n.shapeFill,stroke:d.transitionIntentType==="stamp-shape"?n.activeLineStroke:n.shapeStroke,vectorEffect:"non-scaling-stroke",strokeWidth:(g.open,2)}):null,d.transitioning&&d.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,d.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:y.state.slowState.currentTool,setCurrentTool:y.tools.setTool,helper:y,currentShape:g,state:d,isAddingPoint:R,isSplitting:P,isStamping:L,isHoveringPoint:b,transitionDirection:h,transitionRotate:p,defs:x,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:f,isAddingPoint:c}=Jo({image:e.image,theme:e.theme}),m=Jt(p=>{p.button!==2&&o.pointer([[~~p.atlas.x,~~p.atlas.y]])},[o]),h=Jt(p=>{p.button!==2&&o.pointerDown()},[o]),v=Jt(p=>{p.button!==2&&o.pointerUp()},[o]);return en(()=>{let p=S=>{o.key.up(S.key)};return document.addEventListener("keyup",p),()=>{document.removeEventListener("keyup",p)}},[o]),en(()=>{let p=S=>{S.target&&["INPUT","TEXTAREA"].includes(S.target.tagName)||S.target?.isContentEditable||document.activeElement&&(document.activeElement instanceof HTMLInputElement||document.activeElement instanceof HTMLTextAreaElement||document.activeElement.isContentEditable)||o.key.down(S.key)};return document.addEventListener("keydown",p),()=>{document.removeEventListener("keydown",p)}},[o]),en(()=>{let p=[];return a&&p.push(`atlas-cursor-${a}`),r.actionIntentType==="cut-line"&&r.modifiers?.Shift&&p.push("atlas-cursor-cut"),(f||r.transitionIntentType==="move-shape"||r.transitionIntentType==="move-point")&&p.push("atlas-cursor-move"),c&&p.push("atlas-cursor-crosshair"),l&&p.push("atlas-cursor-copy"),u&&p.push("atlas-cursor-rotate"),r.transitionIntentType==="draw-shape"&&p.push("atlas-cursor-draw"),t?.canvas&&t.canvas.classList.add(...p),()=>{t?.canvas&&t.canvas.classList.remove(...p)}},[t?.canvas,c,f,l,r.modifiers?.Shift,r.actionIntentType,r.transitionIntentType,a,u]),De("world-object",{height:n.height,width:n.width,onMouseMove:m,onMouseDown:h,onMouseUp:v,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(Ce)}}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(Ce.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:f,context:c}=Zs({open:s,onOpenChange:i,nodeId:e.id,placement:r||"bottom",middleware:[Gs(10),Qs(),Ys({mainAxis:!0})],whileElementsMounted:Ks}),m=Xs(c),{getReferenceProps:h,getFloatingProps:v}=Js([o?m:null].filter(p=>p!==null));return tl(js,{relative:!0,target:t,interactive:!1,children:[tn("div",{ref:u.setReference,...h(),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:f,...v(),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(),f=nl(h=>{n&&(h.preventDefault(),h.stopPropagation(),u(h.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:f},{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,C=>C.polygon),r=J(o,C=>C.polygonState.currentTool),a=J(o,C=>C.mode),l=J(o,C=>C.changeMode),u=J(o,C=>C.polygonState.transitioning),{enabled:f,requestId:c}=J(o,C=>C.tool),m=ll(()=>xe(i),[i]),h=or(),[v,p]=ft("editing-annotation",s?.id,t),S=h?.annotationPopup||n||ae(ul,{}),y=h?.svgTheme||e,d=()=>{l("sketch")};if(!f||!s||!c||!i)return null;let g=m&&i.id&&!u&&(r==="pointer"||r==="hand"||!i.open)?ae(pt,{annotation:i,target:m,children:S}):null,x="shape";return a==="explore"?nn(rr,{children:[ae(x,{id:`shape-${i.id}`,points:i.points,open:i.open,onClick:d,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)"},...p}),ae(x,{id:`shape-${i.id}`,points:i.points,open:i.open,onClick:d,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)"}}),g]}):nn(rr,{children:[t?ae(x,{id:`shape-${i.id}`,points:i.points,open:i.open,target:{x:0,y:0,width:s.width,height:s.height},...p}):null,ae(er,{image:s,theme:y}),g,v]})}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(f=>{e&&n.setMetaValue([f,"annotationPageManager","views"],c=>c&&!c[e]?c:{...c||{},[e]:!1})},[e,n]),u=lr((f,c={})=>{if(!e)return;let m=n.getState(),h=[];if(c?.deselectOthers){let v=Object.keys(m.iiif.entities.AnnotationPage);for(let p of v){let S=ml(m,p);S&&S.views&&S.views[e]&&h.push(p)}}for(let v of h)l(v);n.setMetaValue([f,"annotationPageManager","views"],v=>v&&v[e]?v:{...v||{},[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=To();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((f,{deselectOthers:c=!0,deselect:m=!1}={})=>{a.choice&&r(h=>{if(m){let p=h.filter(S=>S!==f);if(p.length===0){let S=a.items[0].resource.id;return S?[S]:[]}return p}if(c)return[f];let v=[...h];if(v.length===0&&a.items.length){let p=a.items[0].resource.id;p&&v.push(p)}return h.indexOf(f)!==-1?h:[...h,f]})},[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"),f=e?.strategies||["empty","images","media","textual-content","complex-timeline"],[c,m]=fr(e,[a]);gr(()=>{let v=p=>{m.makeChoice(p.choiceId,{deselectOthers:p.deselectOthers,deselect:p.deselect})};return i.on("make-choice",v),()=>{i.off("make-choice",v)}},[]);let h=hr(()=>un({canvas:n,paintables:c,supports:f,loadImageService:r,vault:o}),[n,c,o,m.makeChoice]);return gr(()=>{let v=c.allChoices,p={canvasId:n?.id,manifestId:t?.id};v&&i.emit("choice-change",{choice:v,partOf:p})},[n?.id,c.allChoices]),hr(()=>h.type==="unknown"?[h,ln]:[{...h,annotations:{pages:u}},m],[h,u])}import{createStylesHelper as Cl}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:f,children:c}){let m=A(),h=M(),v=rn(()=>Cl(h),[h]),[p,S]=yr({strategies:e||["images"],defaultChoices:n?.map(({id:x})=>x)}),y="choice"in p?p.choice:void 0;if(on(()=>{t&&t(S)},[p.annotations]),on(()=>{o&&o(y)},[y]),on(()=>{if(n)for(let x of n)typeof x.opacity<"u"&&v.applyStyles({id:x.id},"atlas",{opacity:x.opacity})},[n]),p.type==="unknown"&&f)throw new Error(p.reason||"Unknown strategy");let d=rn(()=>({renderMediaControls:i,mediaControlsDeps:s||[],renderViewerControls:r,viewControlsDeps:a||[],renderComplexTimelineControls:l,complexTimelineControlsDeps:u||[]}),[s,i,r,a,l,u]),g=rn(()=>({strategy:p,actions:S,choices:"choice"in p?p.choice:[]}),[p,m]);return vr(et.Provider,{value:d,children:vr(ce.Provider,{value:g,children:c})})}import{useEffect as Cr,useMemo as Pl}from"react";import{useStore as br}from"zustand";import{createContext as bl,useContext as Rl,useEffect as Al}from"react";var an=bl(()=>{});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 Tl}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=br(a,p=>p.setCanvasRelativePosition),f=br(a,p=>p.clearCanvasRelativePosition),[c,m]=ft(`context-menu/${r?.id}`,r?.id,o),h=Pl(()=>n?1:Math.max(1,...i.type==="images"?i.images.map(p=>(p.width||0)/p.target?.spatial.width):[]),[n,i]);Cr(()=>{if(r)return u(r.id,{x:e,y:t,width:r.width,height:r.height}),()=>{f(r.id)}},[e,t,r,f,u]),Cr(()=>{r&&a.getState().reset()},[a,r]),xr(h);let v=i.type==="images"?i.images.length:0;return r?Tl("world-object",{height:r.height,width:r.width,x:e,y:t,...m,...l,children:[c,s]},`${r.id}/${i.type}/${v}`):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:f,mediaControlsDeps:c,strategies:m,throwOnUnknown:h,backgroundStyle:v,alwaysShowBackground:p,keepCanvasScale:S=!1,enableSizes:y=!1,enableYouTube:d=!0,onClickPaintingAnnotation:g,components:x={},children:C,annotationPopup:b,svgTheme:R,renderContextMenu:P,renderAnnotationContextMenu:L}){return Ar(Sr,{throwOnUnknown:h,onChoiceChange:n,registerActions:o,strategies:m,defaultChoices:s,mediaControlsDeps:c,renderMediaControls:a,renderViewerControls:r,renderComplexTimelineControls:l,complexTimelineControlsDeps:u,viewControlsDeps:f,children:[Ar(Rr,{keepCanvasScale:S,x:e,y:t,renderContextMenu:P,children:[Y(Wo,{alwaysShowBackground:p,backgroundStyle:v}),Y(Fo,{}),Y(_o,{}),Y(Uo,{isStatic:i,enableSizes:y,onClickPaintingAnnotation:g}),Y(ho,{}),Y(io,{}),Y(xo,{as:x.Audio}),Y(Ko,{as:x.Video}),d?Y(Qo,{}):null,Y(ir,{theme:R,renderContextMenu:L,children:b}),C]}),Y(ao,{})]})}import{jsx as Pr}from"react/jsx-runtime";function Tr(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 wl,useMemo as Il}from"react";function wr(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();wl(()=>{let u=setInterval(()=>{if(e&&t!==-1){let f={x:e.x,y:e.y,width:e.width,height:e.height},c=a.getState().canvasRelativePositions,m={};for(let h of r){let v=c[h.id];if(v){let p=v.x,S=v.y,y=v.width,d=v.height,g={x:Math.max(p,f.x),y:Math.max(S,f.y),width:Math.min(p+y,f.x+f.width)-Math.max(p,f.x),height:Math.min(S+d,f.y+f.height)-Math.max(S,f.y)};g.width<=0||g.height<=0||(m[h.id]={x:g.x-v.x,y:g.y-v.y,width:g.width,height:g.height}),a.setState({canvasViewports:m})}}}},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,T=>T.mode),u=kr(a,T=>T.setAtlasRuntime),[f,c]=ht(),m=ct(),h=dt(),v=n||Ir,[p,S]=ht({}),y=Object.entries(p),[d,g]=ht({}),x=Object.entries(d),[C,b]=ht({}),{worldScale:R,runtimeOptions:P}=El(()=>{if(Object.values(C).length===0)return{worldScale:1,runtimeOptions:r.runtimeOptions||{maxOverZoom:1}};let I=Math.max(...Object.values(C));return{worldScale:I,runtimeOptions:{maxOverZoom:I||1,...r.runtimeOptions||{}}}},[C,r.runtimeOptions]);wr(f?.runtime,i);let L=gt((T,I)=>{b(E=>{if(I===-1){let{[T]:Ee,...se}=E;return se}return{...E,[T]:I}})},[]),re=gt((T,I,E)=>{S(({[T]:Ee,...se})=>I?{...se,[T]:{element:I,props:E}}:se)},[]),w=gt((T,I,E)=>{g(({[T]:Ee,...se})=>I?{...se,[T]:{element:I,props:E}}:se)},[]),z=gt(T=>{c(T),u(T.runtime),r.onCreated&&r.onCreated(T)},[r.onCreated,u]);return zl(Vl,{resetKeys:[],fallbackRender:T=>O(v,{...r,...T}),children:[O(kl,{...r,mode:l,containerProps:{style:{position:"relative"},...r.containerProps||{}},htmlChildren:O(Ll,{children:y.map(([T,{element:I,props:E}])=>O(Mr.Fragment,{children:O(I,{...E||{}})},T))}),onCreated:z,runtimeOptions:P,children:O(Oe,{name:e,existing:a,children:O(fe.Provider,{value:f,children:O(an.Provider,{value:L,children:O(Bt.Provider,{value:re,children:O(Ht.Provider,{value:w,children:O(mt,{bridge:h,custom:m,children:O(fo,{children:t})})})})})})})}),O("div",{children:x.map(([T,{element:I,props:E}])=>O(Mr.Fragment,{children:O(I,{...E||{}})},T))}),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,f=o.viewingDirection==="top-to-bottom",c=o.viewingDirection==="bottom-to-top",m=o.viewingDirection==="left-to-right",h=o.viewingDirection==="right-to-left",p=o.behavior.includes("continuous")?0:t.spacing||0,S=c||h,y=Bl(()=>S?[...s].reverse():s,[s,S]);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:y.map((d,g)=>{let x=0,C=0;return!f&&!c?(x=u,u+=d.width+p):(C=u,u+=d.height+p),G(ee,{canvas:d.id,children:G(H.RenderCanvas,{strategies:["3d-model","media","images","empty","textual-content","complex-timeline"],renderViewerControls:g===0&&r?()=>G(r,{}):void 0,renderMediaControls:g===0&&a?()=>G(a,{}):void 0,annotationPopup:t.annotationPopup,renderContextMenu:t.renderContextMenu,keepCanvasScale:t.keepCanvasScale,renderComplexTimelineControls:g===0&&l?()=>G(l,{}):void 0,renderAnnotationContextMenu:t.renderAnnotationContextMenu,x,y:C,svgTheme:t.svgTheme,...t.canvasProps||{},children:t.annotations},d.id)},d.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:f,runtimeOptions:c,annotationPopup:m,name:h,svgTheme:v,updateViewportTimeout:p,renderContextMenu:S,keepCanvasScale:y,renderAnnotationContextMenu:d,padding:g,...x},C){let b=ye();return G(Oe,{name:h,children:G(ge,{vault:b,children:G(On,{...x,children:G(Hl,{ref:C,height:n,components:a,spacing:i,canvasProps:s,annotations:o,header:r,mode:l,reuseAtlas:u,renderPreset:f,runtimeOptions:c,annotationPopup:m,svgTheme:v,updateViewportTimeout:p,renderContextMenu:S,keepCanvasScale:y,renderAnnotationContextMenu:d,padding:g,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=Tr;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,Cn as z,bn 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,bi 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,Tt as ba,wt as ca,qn as da,$n as ea,Ce as fa,q as ga,Un as ha,Oe as ia,_n as ja,jn as ka,wd as la,_i as ma,Kn as na,je as oa,A as pa,Ke as qa,be 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,Te as Ua,xo as Va,Co as Wa,cf as Xa,rt as Ya,Cf as Za,Pf as _a,Tf as $a,wf 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};
@@ -305,6 +305,7 @@ type AnnotationRequestOptions = {
305
305
  };
306
306
  interface AtlasStore {
307
307
  mode: ViewerMode;
308
+ runtime: Runtime | null;
308
309
  tool: {
309
310
  enabled: boolean;
310
311
  requestId: string | null;
@@ -614,6 +615,7 @@ interface CanvasPanelProps {
614
615
  runtimeOptions?: any;
615
616
  renderPreset?: any;
616
617
  name?: string;
618
+ padding?: AtlasProps['homePaddingPx'];
617
619
  height?: number;
618
620
  spacing?: number;
619
621
  components?: {
@@ -305,6 +305,7 @@ type AnnotationRequestOptions = {
305
305
  };
306
306
  interface AtlasStore {
307
307
  mode: ViewerMode;
308
+ runtime: Runtime | null;
308
309
  tool: {
309
310
  enabled: boolean;
310
311
  requestId: string | null;
@@ -614,6 +615,7 @@ interface CanvasPanelProps {
614
615
  runtimeOptions?: any;
615
616
  renderPreset?: any;
616
617
  name?: string;
618
+ padding?: AtlasProps['homePaddingPx'];
617
619
  height?: number;
618
620
  spacing?: number;
619
621
  components?: {