react-iiif-vault 1.2.7 → 1.3.2

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