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