react-iiif-vault 2.0.12 → 2.0.13

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/index.js CHANGED
@@ -1 +1 @@
1
- import{$ as Jr,$a as Uo,A as Nr,Aa as Io,Ab as dn,B as Ar,Ba as Ro,Bb as gn,C as kr,Ca as Co,Cb as hn,D as Mr,Da as Po,Db as yn,E as Lr,Ea as Pe,Eb as vn,F as Hr,Fa as To,Fb as bn,G as zr,Ga as wo,Gb as xn,H as Br,Ha as Eo,Hb as Sn,I as Fr,Ia as qo,Ib as In,J as Or,Ja as No,Jb as qn,K as Vr,Ka as Ao,Kb as ke,L as Wr,La as ko,Lb as Nn,M as Dr,Ma as Mo,Mb as Me,N as _r,Na as Lo,Nb as B,O as Ur,Oa as Ho,Ob as An,P as $r,Pa as zo,Pb as Bn,Q as Xr,Qa as Bo,Qb as Fn,R as Kr,Ra as Fo,Rb as On,S as Gr,Sa as Te,Sb as He,T as Qr,Ta as we,Tb as ze,U as be,Ua as Oo,Ub as Be,V as Yr,Va as Vo,W as Zr,Wa as Wo,X as jr,Xa as Do,Y as G,Ya as Ee,Z as xe,Za as qe,_ as Se,_a as _o,a as gr,aa as eo,ab as $o,b as $,ba as to,bb as Xo,c as z,ca as Ie,cb as Ko,d as pe,da as Re,db as Go,e as hr,ea as ro,eb as Qo,f as de,fa as oo,fb as Yo,g as T,ga as w,gb as Zo,h as X,ha as no,hb as jo,i as yr,ia as io,ib as L,j as ge,ja as ao,jb as Ne,k as he,ka as Ce,kb as Jo,l as K,la as so,lb as en,m as ye,ma as co,mb as ae,n as vr,na as lo,nb as tn,o as br,oa as uo,ob as rn,p as xr,pa as E,pb as on,q as Sr,qa as mo,qb as nn,r as Ir,ra as fo,rb as an,s as Rr,sa as po,sb as sn,t as Cr,ta as go,tb as cn,u as Pr,ua as ho,ub as ln,v as Tr,va as yo,vb as un,w as ve,wa as vo,wb as mn,x as wr,xa as bo,xb as Ae,y as Er,ya as xo,yb as fn,z as qr,za as So,zb as pn}from"./chunk-5EBWATUV.js";import"./chunk-UNH7HXGJ.js";import{a as Rn,b as Cn,c as Pn,d as Tn,e as wn,f as En,g as kn,h as Mn,i as Ln,j as Hn,k as zn,l as Le}from"./chunk-P7XHGETS.js";export*from"@iiif/helpers/annotation-targets";import{useEffect as gt}from"react";import{useCallback as Fe,useEffect as pt,useRef as dt,useState as Q}from"react";import{useStore as F}from"zustand";function Oe(e){let[t,r]=Q(0),o=w(),n=F(o,h=>h.tool.enabled),i=F(o,h=>h.tool.requestId),a=F(o,h=>h.getRequestId),c=F(o,h=>h.requestAnnotation),g=F(o,h=>h.completeRequest),m=F(o,h=>h.cancelRequest),s=dt(e?.onSuccess);s.current=e?.onSuccess;let[b,x]=Q(!1),[S,l]=Q(null),[f,v]=Q(null),u=n&&i!==f,y=n&&i===f,p=Fe(async(h,C)=>{if(f){let M=s.current;x(!0);let q=await c(h,{...C,requestId:f});if(q)return M?.(q),r(A=>A+1),x(!1),l(q),q;let H={id:f,cancelled:!0,...Re(h)};return M?.(H),l(H),r(A=>A+1),x(!1),H}return null},[c,f]),d=Fe(()=>{l(null),x(!1)},[]);return pt(()=>{let h=a();return v(h.requestId),()=>{h.clear()}},[t]),{id:t,busy:u,isPending:b,isActive:y,requestId:f,requestAnnotation:p,cancelRequest:()=>f?m(f):void 0,completeRequest:()=>f?g(f):void 0,reset:d,data:S}}var Kn=[{name:"Default",outer:{borderWidth:4,borderColor:"rgba(255, 255, 255, .4)"},inner:{borderWidth:2,borderColor:"#000"}},{name:"High contrast",outer:{borderWidth:3,borderColor:"#fff"},inner:{borderWidth:1,borderColor:"#000"}},{name:"Lightsaber",outer:{borderWidth:"4",borderColor:"rgba(56,68,255,0.64)"},inner:{borderWidth:"2",borderColor:"#fff"}},{name:"Bright",outer:{borderWidth:"6",borderColor:"#25d527"},inner:{borderWidth:"3",borderColor:"#a916ff"}},{name:"pink",outer:{borderWidth:"4",borderColor:"#ff00ff"},inner:{borderWidth:"2",borderColor:"#ffffff"}},{name:"fine (dark)",outer:{borderWidth:"1",borderColor:"#000000"},inner:{}},{name:"fine (light)",outer:{borderWidth:"1",borderColor:"#FFF"},inner:{}}];function Ve(e){let{id:t,data:r,requestAnnotation:o,cancelRequest:n,isPending:i}=Oe({onSuccess:a=>{e.updateShape(a.polygon)}});return gt(()=>(o({type:"polygon",open:e.shape?.open,points:e.shape?.points}),()=>{n()}),[]),null}import{createContext as ht,useCallback as We,useContext as _e,useEffect as De,useMemo as se,useState as yt}from"react";import Ue from"mitt";import{jsx as vt}from"react/jsx-runtime";var Y=ht(Ue());Y.displayName="SelectorHelper";function ei({children:e}){return vt(Y.Provider,{value:se(()=>Ue(),[]),children:e})}function ti(){return _e(Y)}function $e(e){let t=Xe(),[r,o]=yt(!1);De(()=>t.withSelector(e).on("highlight",()=>{o(!0)}),[t,e]),De(()=>t.withSelector(e).on("clear-highlight",()=>{o(!1)}),[t,e]);let n=We(a=>{t.emit("click",{selectorId:e,event:a})},[e,t]),i=We(a=>{t.emit("hover",{selectorId:e,event:a})},[e,t]);return{controller:t,onClick:n,onHover:i,isHighlighted:r}}function Xe(){let e=_e(Y);return se(()=>({withSelector(t){return{on(r,o){let n=i=>{i&&i.selectorId===t&&o(i)};return e.on(r,n),()=>{e.off(r,n)}},emit(r,o){e.emit(r,{...o,selectorId:t})}}},on(t,r){return e.on(t,r),()=>{e.off(t,r)}},emit(t,r){e.emit(t,r)}}),[e])}function ri(){let e=Xe();return se(()=>({withSelector(t){return{highlight(){e.emit("highlight",{selectorId:t})},clearHighlight(){e.emit("clear-highlight",{selectorId:t})},zoomTo(){e.emit("zoom-to",{selectorId:t})},addEventListener(r,o){return e.emit("event-listener",{selectorId:t,name:r,callback:o}),()=>{e.emit("remove-event-listener",{selectorId:t,name:r,callback:o})}},getImagePreview(){return new Promise((r,o)=>{e.emit("image-preview-request",{selectorId:t,resolve:r,reject:o})})},on(r,o){return e.withSelector(t).on(r,o)}}},highlight(t){e.emit("highlight",{selectorId:t})},clearHighlight(t){e.emit("clear-highlight",{selectorId:t})},zoomTo(t){e.emit("zoom-to",{selectorId:t})},addEventListener(t,r,o){return e.emit("event-listener",{selectorId:t,name:r,callback:o}),()=>{e.emit("remove-event-listener",{selectorId:t,name:r,callback:o})}},getImagePreview(t){return new Promise((r,o)=>{e.emit("image-preview-request",{selectorId:t,resolve:r,reject:o})})},on(t,r){return e.on(t,r)}}),[e])}import{jsx as Ke}from"react/jsx-runtime";function mi(e){let t=E(),r=e.annotationBucket,o=e.readOnly,n=e.id,{onClick:i,isHighlighted:a}=$e(e.id),c=Ce(),g=a?c.highlighted:c[r||"hidden"]||c.hidden;if(!t)return null;if(o){let m="shape",s=e.polygon,b=s.open;return s?Ke(m,{id:`shape-${n}`,points:s.points,open:b,onClick:i,relativeStyle:!0,target:{x:0,y:0,width:t.width,height:t.height},style:g}):null}return Ke(Ve,{image:t,shape:e.polygon||{id:e.id,open:!0,points:[]},updateShape:e.updatePolygon,theme:e.theme,controlsHtmlId:e.controlsHtmlId,renderControls:e.renderControls})}import{useCanvas as bt}from"@atlas-viewer/atlas";import{forwardRef as xt,useImperativeHandle as St}from"react";import{Fragment as It,jsx as Ge}from"react/jsx-runtime";var bi=xt(function({canvasId:t},r){let o=bt(),n=ke(t||o?.id),i=T();return St(r,()=>n,[t,o]),!o||n.enabledPageIds.length===0?null:Ge(It,{children:n.enabledPageIds.map(a=>Ge(Be.RenderAnnotationPage,{page:i.get(a)},a))})});import{useMemo as Pt}from"react";import{useMemo as Rt}from"react";import{Fragment as Ct,jsx as R,jsxs as Z}from"react/jsx-runtime";function j({metadata:e=[],config:t,labelWidth:r=16,showEmptyMessage:o=!0,allowHtml:n,emptyFallback:i,classes:a={},emptyMessage:c="No metadata available",emptyValueFallback:g="No value",emptyLabelFallback:m="",separator:s,tableFooter:b,tableHeader:x,customLabelRender:S,customValueRender:l}){let f=Rt(()=>{let u=(t||[]).reduce((p,d)=>[...p,...d.keys],[]),y={};for(let p of e){let d=p?.label?Object.values(p.label):[];for(let h of d)if(h?.length&&(u.indexOf(`metadata.${h[0]}`)!==-1||u.length===0)&&p){let C=`metadata.${h[0]}`;y[C]=y[C]?y[C]:[],y[C].push(p);break}}return y},[t,e]);return Object.keys(f).length===0&&o?R(Ct,{children:i})||R("div",{className:a.empty,children:c}):t?.length?Z("table",{className:a.container,children:[x,R("tbody",{children:t.map((u,y)=>{let p=[];for(let h of u.keys)for(let C of f[h]||[]){let M=R(L,{enableDangerouslySetInnerHTML:n,defaultText:g,separator:s,children:C.value},y+"__"+h);l?p.push(l(C,M)):p.push(M)}if(p.length===0)return null;let d=R(L,{enableDangerouslySetInnerHTML:n,separator:s,defaultText:m,children:u.label});return Z("tr",{className:a.row,children:[R("td",{className:a.label,style:r?{minWidth:r}:{},children:S?S(u.label,d):d}),R("td",{className:a.value,children:p})]},y)})}),b]}):Z("table",{className:a.container,children:[x,R("tbody",{children:e?.length?e.map((u,y)=>{if(!u)return null;let p=R(L,{enableDangerouslySetInnerHTML:n,defaultText:g,separator:s,children:u.label}),d=R(L,{enableDangerouslySetInnerHTML:n,defaultText:g,separator:s,children:u.value});return Z("tr",{className:a.row,children:[R("td",{className:a.label,style:r?{minWidth:r}:{},children:S?S(u.label,p):p}),R("td",{className:a.value,children:l?l(u,d):d})]},y)}):null}),b]})}import{jsx as Tt}from"react/jsx-runtime";function ki(e){let t=K(),r=E(),o=ve(),n=Pt(()=>{let i=t?.metadata||[],a=r?.metadata||[],c=o?.metadata||[];return[...i,...a,...c]},[t,r,o]);return Tt(j,{metadata:n,...e})}import{useEffect as Nt,useState as At}from"react";import{createImageServiceRequest as wt,imageServiceRequestToString as Et}from"@iiif/parser/image-3";import{useMemo as qt}from"react";function ce(e,t={},r=[]){return qt(()=>{if(!e)return null;let o=t.quality;e&&e.extraQualities&&t.quality&&(e.extraQualities.includes(t.quality)||(o="default"));let n=wt(e);return Et({identifier:n.identifier,server:n.server,scheme:n.scheme,type:"image",size:{max:!t.size?.width&&!t.size?.height,confined:!1,upscaled:!1,...t.size||{}},format:t.format||"jpg",region:t.region||{full:!0},rotation:t?.rotation?Number.isInteger(t.rotation)?{angle:t.rotation}:t.rotation:{angle:0},quality:o||"default",prefix:n.prefix,originalPath:n.originalPath})},[...r])}import{jsx as J}from"react/jsx-runtime";function kt(e){let t=typeof e.src=="string"?e.src:e.src.id,r=Te(),[o,n]=At(!1),i;if(t){let c=r.loadServiceSync({id:t});c&&(i=c)}!i&&!o&&r.loadService({id:t}).then(()=>{n(!0)});let a=ce(i,{size:e.size,selector:e.region,rotation:e.rotation,format:e.format,region:e.region,quality:e.quality},[o,e.src,e.size,e.region,e.rotation,e.format,e.region,e.quality]);return Nt(()=>()=>{n(!1)},[t]),a?J("img",{src:a,alt:e.alt,className:e.className,style:e.style}):J(Mt,{...e,fetchImageService:!1})}function Mt(e){if(e.fetchImageService)return J(kt,{...e});let t=typeof e.src=="string"?{id:e.src,profile:"level0"}:e.src,r=ce(t,{size:e.size,selector:e.region,rotation:e.rotation,format:e.format,region:e.region,quality:e.quality},[e.src,e.size,e.region,e.rotation,e.format,e.region,e.quality]);return r?J("img",{src:r,alt:e.alt,className:e.className,style:e.style}):null}import{useMemo as Lt,useState as Ht}from"react";import{ErrorBoundary as zt}from"react-error-boundary";import{jsx as O,jsxs as Ft}from"react/jsx-runtime";function ta({src:e,errorFallback:t,interactive:r,skipSizes:o,children:n,renderViewerControls:i,viewControlsDeps:a,fluid:c,x:g,y:m,...s}){let b=he(),[x,S]=Ht(),l=t||He,[f,v]=Me(),u=Lt(()=>{let p=v[e]?.status,d=f({id:e},{});return d?.height&&d.width&&p!=="loading"?{id:e,width:d.width,height:d.height,service:d,type:"Image",selector:{type:"BoxSelector",spatial:{x:0,y:0,width:d.width,height:d.height}},target:{type:"BoxSelector",spatial:{x:0,y:0,width:d.width,height:d.height}}}:null},[f,e,v]);if(!u||!u.height||!u.width)return null;let y=c?void 0:s.homePosition?s.homePosition.width/s.homePosition.height:u.width/u.height;return O(zt,{resetKeys:[],fallbackRender:p=>O(l,{...s,...p}),children:O(de,{vault:b,children:O(ze,{...s,aspectRatio:y,containerProps:{style:{position:"relative"},...s.containerProps||{}},onCreated:p=>{S(p),s.onCreated&&s.onCreated(p)},children:Ft(ae.Provider,{value:x,children:[O(Ne,{image:u,id:u.id,isStatic:!r,x:g,y:m},u.id),O(Bt,{viewerPreset:x,renderViewerControls:i,image:u,src:e,viewControlsDeps:a}),n]})})})})}function Bt({viewerPreset:e,renderViewerControls:t,image:r,src:o,viewControlsDeps:n}){return Pe(e&&t?"overlay":"none",`canvas-portal-controls-${o}`,ae.Provider,t&&r?{value:e||null,children:t({image:r,images:[r],type:"images"})}:{},[o,e,...n||[]]),null}import{jsx as Ot}from"react/jsx-runtime";function sa(e){let t=K();return Ot(j,{metadata:t?.metadata||[],...e})}import{useLayoutEffect as Ut,useRef as $t}from"react";import*as le from"react-lazy-load-image-component";import{getValue as Vt}from"@iiif/helpers/i18n";import{Fragment as Qe,jsx as k,jsxs as _t}from"react/jsx-runtime";var{LazyLoadComponent:Wt}=le||le.default;function Ye(e){let{size:t,visible:r,classes:o,canvasId:n,figure:i}=e,a=t?.width||128,c=t?.height||t?.width||128,g=k(Dt,{...e}),m=k(Wt,{threshold:300,style:{height:c,width:a},visibleByDefault:r,children:n?k(pe,{canvas:n,children:g}):g});return i?k("figure",{className:o?.figure,children:m}):m}function Dt({fallback:e,size:t,classes:r,showLabel:o,alt:n,dereference:i=!1}){let a=E(),c=t?.width||128,g=t?.height||t?.width||128,m=n||Vt(a?.label)||"",s=we({width:c,height:g,allowUnsafe:!0},i);return!s||s.type!=="fixed"?k(Qe,{children:e}):_t(Qe,{children:[k("div",{className:r?.imageWrapper,children:k("img",{className:r?.img,src:s.id,alt:m})}),o?k(L,{as:"figcaption",className:r?.label,children:a?.label}):null]})}import{jsx as W}from"react/jsx-runtime";function xa({scrollBehaviour:e,dereference:t,flat:r,size:o,classes:n={},showLabel:i,figure:a,fallback:c}){let g=$t(null),{items:m,sequence:s,currentSequenceIndex:b,setSequenceIndex:x}=be(),S={row:n.selected?.row||n.row,item:n.selected?.item||n.item,figure:n.selected?.figure||n.figure,img:n.selected?.img||n.img,label:n.selected?.label||n.label,imageWrapper:n.selected?.imageWrapper||n.imageWrapper};Ut(()=>{if(!g.current)return;let f=g.current.querySelector("[data-selected=true]");f&&f.scrollIntoView({behavior:e||"instant",block:"nearest",inline:"center"})},[b]);let l=[];for(let f of s){let v=[],u=s[b]===f;for(let y of f){let p=m[y];v.push(W("div",{className:u?S.item:n.item,children:W(Ye,{classes:u?S:n,canvasId:p.id,size:o,dereference:t,showLabel:i,figure:a,placeholder:W("div",{style:{height:128,width:128}}),fallback:c})},y))}if(r){l.push(v);continue}l.push(W("div",{onClick:y=>{x(s.indexOf(f))},"data-selected":u,className:u?S.row:n.row,children:v},f.join("-")))}return W("div",{ref:g,className:n.container,children:l})}import{useStore as ee}from"zustand";function Ze(){let e=w(),t=ee(e,i=>i.completeRequest),r=ee(e,i=>i.polygonState.currentTool),o=ee(e,i=>i.polygonState.selectedStamp),n=ee(e,i=>i.switchTool);return{completeRequest:t,currentTool:r,selectedStamp:o,switchTool:n}}import{Fragment as je,jsx as P,jsxs as Je}from"react/jsx-runtime";var Xt={draw:!0,polygon:!0,line:!0,lineBox:!0,box:!0,triangle:!0,hexagon:!0,circle:!0,delete:!0,pen:!0};function wa({showShapes:e=!0,enabled:t=Xt,classNames:r={},icons:o={}}){let{currentTool:n,switchTool:i,selectedStamp:a}=Ze();return Je(je,{children:[n,P("button",{className:r.button,onClick:i.pointer,"data-active":n==="pointer",children:o.PointerIcon||"Pointer"}),P("button",{className:r.button,onClick:i.hand,"data-active":n==="hand",children:o.HandIcon||"Hand"}),e?Je(je,{children:[t.box&&P("button",{className:r.button,onClick:i.box,"data-active":n==="box",children:o.BoxIcon||"Box"}),t.pen&&P("button",{className:r.button,onClick:i.pen,"data-active":n==="pen",children:o.PenIcon||"Pen"}),t.draw&&P("button",{className:r.button,onClick:i.draw,"data-active":n==="pencil",children:o.DrawIcon||"Draw"}),t.line&&P("button",{className:r.button,onClick:i.line,"data-active":n==="line",children:o.LineIcon||"Line"}),t.lineBox&&P("button",{className:r.button,onClick:i.lineBox,"data-active":n==="lineBox",children:o.LineBoxIcon||"LineBox"}),t.triangle&&P("button",{className:r.button,onClick:i.triangle,"data-active":n==="stamp"&&a?.id==="triangle",children:o.TriangleIcon||"Triangle"}),t.hexagon&&P("button",{className:r.button,onClick:i.hexagon,"data-active":n==="stamp"&&a?.id==="hexagon",children:o.HexagonIcon||"Hexagon"}),t.circle&&P("button",{className:r.button,"data-active":n==="stamp"&&a?.id==="circle",onClick:i.circle,children:o.CircleIcon||"Circle"})]}):null,t.delete&&P("button",{className:r.button,onClick:i.remove,children:o.DeleteForeverIcon||"Delete"})]})}import{jsx as Kt}from"react/jsx-runtime";function Aa({annotation:e,children:t}){return Kt(z,{value:{annotation:e},children:t})}import{jsx as Gt}from"react/jsx-runtime";function Ha({annotationPage:e,children:t}){return Gt(z,{value:{annotationPage:e},children:t})}import{jsx as Qt}from"react/jsx-runtime";function Oa({collection:e,children:t}){return Qt(z,{value:{collection:e},children:t})}function _a(e,t={}){return B(t)}import{useCanvas as Yt}from"@atlas-viewer/atlas";import{useEffect as Zt,useMemo as ue,useState as jt}from"react";function Qa({canvasId:e}={}){let t=Yt(),r=ge(),o=ue(()=>e?[e]:t?[t.id]:r.map(m=>m.id),[e,t,r]),[n,i]=jt({}),a=Ae();Zt(()=>{let m=s=>{let b=s.partOf.canvasId;b&&i(x=>({...x,[b]:s.choice}))};return a.on("choice-change",m),()=>{a.off("choice-change",m)}},[]);let c=ue(()=>{let m=[];for(let s of o){let b=n[s];b&&m.push({canvasId:s,choice:b})}return m},[o,n]),g=ue(()=>({makeChoice:(m,s)=>{a.emit("make-choice",{choiceId:m,...s})}}),[a]);return{choices:c,actions:g}}function Za(e,t=!1){}function ts(e){let r=$().manifest,o=e?e.map(n=>typeof n=="string"?n:n?.id):[];return X(n=>{let i=r?n.iiif.entities.Manifest[r]:void 0,a=i?.items||[];if(typeof e>"u")return a;let c=[];for(let g of i?.items||[])o.indexOf(g.id)!==-1&&c.push(g);return c},[o.join("/")])}import{useMemo as Jt}from"react";function as(e,t=[]){let{id:r,selector:o}=e,n=$(),i=r||n.collection,a=X(c=>i?c.iiif.entities.Collection[i]:void 0,[i]);return Jt(()=>{if(a)return o?o(a):a},[a,o,...t])}import{startTransition as er,useMemo as tr}from"react";import{useStore as et}from"zustand";function ms(){let e=w(),t=et(e,o=>o.completeRequest),r=et(e,o=>o.cancelRequest);return tr(()=>({saveAnnotation:()=>{er(()=>{t()})},cancelRequest:r}),[t,r])}import{useCallback as rr}from"react";import{useStore as me}from"zustand";function hs({requestId:e}={}){let t=w(),r=me(t,c=>c.metadata),o=me(t,c=>c.tool.requestId),n=e||o,i=me(t,c=>c.setMetadata),a=rr(c=>i(c,n||void 0),[i,n]);return[n?r[n]||{}:{},a]}import{useStore as or}from"zustand";function Ss(e){let t=w(),r=or(t,o=>o.tool.requestId);G("polygons.start-transition",o=>{e.requestId&&r!==e.requestId||e?.onStart?.(o.transitionIntent)},[r,e.requestId]),G("polygons.end-transition",o=>{e.requestId&&r!==e.requestId||e?.onEnd?.(o.transitionIntent,o.response)},[r,e.requestId]),G("polygons.transition",o=>{e.requestId&&r!==e.requestId||e?.onTransition?.(o.transitionIntent)},[r,e.requestId])}import{useEffect as nr,useMemo as ir}from"react";import{createEventsHelper as ar}from"@iiif/helpers/events";function Ts(e,t,r,o,n=[]){let i=T(),a=ir(()=>ar(i),[i]);nr(()=>{let c=e;return c?(a.addEventListener(c,t,r,o),()=>{a.removeEventListener(c,t,r)}):()=>{}},[a,e,t,...n])}function Ns(e,t){let{id:r,isLoaded:o,error:n,resource:i,requestId:a,cached:c}=ye(e,t);return{id:r,isLoaded:o,error:n,manifest:i,requestId:a,cached:c}}import{getImageServices as tt}from"@iiif/parser/image-3";import{useEffect as sr,useMemo as rt,useState as te}from"react";function ot({cacheKey:e}={}){let t=E(),r=B(),o=T(),n=Ee(),i=qe(),[a,c]=te(void 0),[g,m]=te(!1),[s,b]=te("idle"),[x,S]=te(void 0),l=t?t.id:"undefined",f=rt(()=>{try{if(t&&r.length){let u=r[0],y=o.get(u.body[0]),d=tt(y)[0];return d&&n(d,{width:d.width||t.width,height:d.height||t.height},!0)||void 0}}catch(u){console.error(u)}},[l,e,t]),v=s==="success"&&a?a:f;return sr(()=>{(async()=>{try{if(t&&r.length){let u=r[0],y=o.get(u.body[0]),d=tt(y)[0];if(!d)return;m(!0),b("loading");try{let h=await i(d,{width:d.width||t.width,height:d.height||t.height})||void 0;c(h),b("success"),m(!1)}catch(h){b("error"),S(h)}}}catch(u){b("error"),S(u)}})()},[l,e]),rt(()=>({data:v,isFetching:g,status:s,error:x}),[v,g,s,x])}function Vs(){let e=ot();return{isLoading:e.isFetching,tile:e.data?{id:e.data.id||e.data["@id"],width:e.data.width,height:e.data.height,imageService:e.data,thumbnail:void 0}:null}}import{useMemo as fe}from"react";import{createPaintingAnnotationsHelper as cr}from"@iiif/helpers";function Gs({supports:e=["empty","images","media","3d-model","textual-content","complex-timeline"]}={}){let t=T(),r=E(),o=B(),n=fe(()=>cr(t),[t]),i=fe(()=>n.getPaintables(o),[n,o]);return fe(()=>Le({canvas:r,loadImageService:a=>a,paintables:i,supports:e}),[r,i,e])}import{createStylesHelper as lr}from"@iiif/helpers/styles";import{useMemo as ur}from"react";function Js(){let e=T();return ur(()=>lr(e),[e])}import{useCallback as mr,useEffect as oe,useMemo as lt,useRef as ne,useState as ut}from"react";var re=[.6,.02,0,.75],nt=16,it={linear:[0,0,1,1],"ease-in":[.42,0,1,1],"ease-out":[0,0,.58,1],"ease-in-out":[.42,0,.58,1],"ease-in-cubic":re,"ease-out-cubic":[.215,.61,.355,1]};function at(e,t,r){let o=Math.max(0,Math.min(1,r));return{x:e.x+(t.x-e.x)*o,y:e.y+(t.y-e.y)*o,width:e.width+(t.width-e.width)*o,height:e.height+(t.height-e.height)*o}}function st(e,t){let r=[],o=e;for(let n of t)r.push({from:o,to:n}),o=n;return r}function D([e,t,r,o]){let n=3*e,i=3*(r-e)-n,a=1-n-i,c=3*t,g=3*(o-t)-c,m=1-c-g;function s(l){return((a*l+i)*l+n)*l}function b(l){return((m*l+g)*l+c)*l}function x(l){return(3*a*l+2*i)*l+n}function S(l,f=1e-6){let v=l;for(let p=0;p<8;p++){let d=s(v)-l;if(Math.abs(d)<f)return v;let h=x(v);if(Math.abs(h)<1e-6)break;v=v-d/h}let u=0,y=1;for(v=l;u<y;){let p=s(v);if(Math.abs(p-l)<f)return v;l>p?u=v:y=v,v=(y-u)*.5+u}return v}return l=>{if(l<=0)return 0;if(l>=1)return 1;let f=S(l);return b(f)}}function ct(e,t){if(!t||t.length===0)return{index:-1,t:0};if(Number.isNaN(e)||!isFinite(e))return{index:-1,t:0};if(e<0)return{index:-1,t:0};if(e>=t.length)return{index:t.length,t:0};let r=Math.floor(e),o=e-r;return{index:r,t:o}}function nc(e){let{initial:t,regions:r,progress:o,getProgress:n,enabled:i=!0,easing:a,reportEveryFrame:c=!1,pollInterval:g=nt,loop:m=!1,onEnter:s,onExit:b,onProgress:x,jumpTo:S}=e,l=lt(()=>st(t,r),[t,r]),[f,v]=ut(()=>-1),[u,y]=ut(0),p=ne(-1),d=ne(0),h=ne(!0),C=ne(()=>{});oe(()=>(h.current=!0,()=>{h.current=!1}),[]);let M=lt(()=>{if(!a)return D(re);if(typeof a=="function")return a;if(Array.isArray(a)&&a.length===4)return D(a);let I=it[a];return I?D(I):D(re)},[a]),q=mr(I=>{if(!(I<0||I>=l.length)&&(v(I),p.current=I,d.current=0,y(0),s))try{s(I)}catch{}},[l,s]);oe(()=>{C.current=q,S&&S(q)},[q,S]);function H(I){let{index:V,t:_}=ct(I,l),N=V;if(m&&l.length>0){let ie=l.length;N=(V%ie+ie)%ie}let U=M(_);if(N!==p.current){if(p.current>=0&&b)try{b(p.current)}catch{}if(N>=0&&s)try{s(N)}catch{}p.current=N,h.current&&v(N)}if(d.current=U,h.current&&(c||N!==f)&&y(U),x&&N>=0)try{x(N,U)}catch{}}oe(()=>{i&&typeof o=="number"&&H(o)},[o,i]),oe(()=>{if(!i||typeof n!="function")return;let I=null,V=()=>{try{let _=n();H(_)}catch{}};return V(),I=setInterval(V,g),()=>clearInterval(I)},[n,i,g]);let A=f>=0&&f<l.length?l[f]:void 0,ft=A?at(A.from,A.to,d.current):void 0;return{transitions:l,currentIndex:f,currentTransition:A,t:d.current,rect:ft,jumpTo:q}}import{useEffect as fr,useRef as mt,useState as pr}from"react";function sc(e,t={}){let{axis:r="y",offset:o=0,steps:n=1,enabled:i=!0}=t,[a,c]=pr(0),g=mt(-1),m=mt(null);return fr(()=>{if(!i||!e||!e.current)return;let s=e.current,b=()=>{let S=r==="y"?s.scrollTop:s.scrollLeft,l=r==="y"?s.clientHeight:s.clientWidth,v=(r==="y"?s.scrollHeight:s.scrollWidth)-l,y=(v<=0?0:Math.max(0,Math.min(1,(S+o)/v)))*n;y!==g.current&&(g.current=y,c(y)),m.current=null},x=()=>{m.current===null&&(m.current=requestAnimationFrame(b))};return s.addEventListener("scroll",x,{passive:!0}),b(),()=>{s.removeEventListener("scroll",x),m.current!==null&&cancelAnimationFrame(m.current)}},[e,r,o,n,i]),a}function lc(e,t){let{x:r,y:o,width:n,height:i}=e,{x:a,y:c}=t,{width:g,height:m}=t;return r+n>a&&r<a+g&&o+i>c&&o<c+m}import dr from"tiny-invariant";function gc(e,t){let r=e.boundingBox||Se(e.polygon);if(e.polygon&&!xe(e.polygon.points)){let o=e.target||Ie(e.polygon,t);return dr(o?.type==="SvgSelector"),{type:"SvgSelector",points:e.polygon.points,spatial:{unit:"pixel",...r||{}},svgShape:e.polygon.open?"polyline":"polygon",svg:o.value}}return{type:"BoxSelector",spatial:r}}export{Aa as AnnotationContext,Ha as AnnotationPageContext,so as AnnotationStyleProvider,io as AtlasStoreProvider,oo as AtlasStoreReactContext,$r as Auth,Br as AuthProvider,Lr as AuthRContext,Hr as AuthReactContext,zr as AuthReactContextActions,bi as CanvasAnnotations,pe as CanvasContext,Be as CanvasPanel,Fn as CanvasStrategyProvider,On as CanvasWorldObject,Oa as CollectionContext,ki as CombinedMetadata,Wo as ComplexTimelineProvider,yn as ContextBridge,qo as ControlsReactContext,Ve as CreateCustomShape,dn as CustomContextBridge,gn as CustomContextBridgeProvider,re as DEFAULT_BEZIER,nt as DEFAULT_POLL_INTERVAL,In as DefaultEditingTools,it as EASING_PRESETS,Zr as EventEmitterProvider,fn as EventsProvider,Mt as Image,ta as ImageService,Fo as ImageServiceLoaderContext,Gr as InnerViewerProvider,Uo as LanguageProvider,Qo as LanguageString,L as LocaleString,br as ManifestContext,sa as ManifestMetadata,Io as MediaPlayerProvider,j as Metadata,mi as PolygonSelector,xr as RangeContext,Yr as ReactEmitterContext,mn as ReactEventContext,hr as ReactVaultContext,go as RegionHighlight,Eo as Render3DModelStrategy,Ao as RenderAccompanyingCanvas,ho as RenderAnnotation,Sn as RenderAnnotationEditing,vo as RenderAnnotationPage,zo as RenderAnnotationStrategy,Vo as RenderAudioStrategy,Jo as RenderComplexTimelineStrategy,en as RenderEmptyStrategy,rn as RenderImageStrategy,wa as RenderSvgEditorControls,on as RenderTextualContentStrategy,nn as RenderVideoStrategy,an as RenderYouTubeStrategy,po as ResizeWorldItem,z as ResourceProvider,gr as ResourceReactContext,ei as SelectorControllerProvider,xa as SequenceThumbnails,Qr as SimpleViewerProvider,Kr as SimpleViewerReactContext,Ye as SingleCanvasThumbnail,To as StrategyReactContext,Oo as ThumbnailFallbackImage,_o as TranslationProvider,$o as TransliterationProvider,de as VaultProvider,ae as ViewerPresetContext,Ho as VirtualAnnotationProvider,yr as VisibleCanvasReactContext,gc as annotationResponseToSelector,Ar as authDetailsForResource,st as buildTransitions,ro as createAtlasStore,qr as createAuthStateStore,Nr as createProbe,D as cubicBezierEasing,un as defaultEmitter,cn as defaultSvgTheme,Pn as emptyActions,En as emptyStrategy,Ir as findAllCanvasesInRange,Sr as findFirstCanvasFromRange,Rr as findManifestSelectedRange,Cr as findSelectedRange,qn as flattenAnnotationPageIds,Co as formatTime,kn as get3dStrategy,no as getAtlasStoreByName,zn as getComplexTimelineStrategy,ao as getDefaultAnnotationStyles,Mn as getImageStrategy,Tr as getManifestSequence,Cn as getParsedTargetSelector,Le as getRenderingStrategy,ct as getStepFromProgress,Ln as getTextualContentStrategy,Hn as getVideoStrategy,Pr as getVisibleCanvasesFromCanvasId,Er as hasAuth,at as interpolateRect,eo as isBoxSelector,xe as isRectangle,Jr as isSvgSelector,Mr as makeAccessServiceRequest,kr as makeAccessTokenRequest,Rn as parseSpecificResource,Ie as polygonToTarget,Re as requestToAnnotationResponse,to as seraliseSupportedSelector,Kn as svgThemes,lc as targetIntersects,Tn as unknownResponse,wn as unsupportedStrategy,uo as useAnnotation,yo as useAnnotationPage,ke as useAnnotationPageManager,Ce as useAnnotationStyles,_a as useAnnotationsAtTime,bn as useAtlasContextMenu,w as useAtlasStore,Vr as useAuthActions,Dr as useAuthService,Or as useAuthStore,Ur as useAuthToken,_r as useAuthTokens,E as useCanvas,Qa as useCanvasChoices,Za as useCanvasClock,wr as useCanvasSequence,Ro as useCanvasStartTime,ts as useCanvasSubset,Yo as useClosestLanguage,as as useCollection,Do as useComplexTimeline,hn as useContextBridge,vn as useContextMenuStore,jo as useCreateLocaleString,ms as useCurrentAnnotationActions,hs as useCurrentAnnotationMetadata,xn as useCurrentAnnotationRequest,Ss as useCurrentAnnotationTransition,Wr as useCurrentAuth,pn as useCustomContextBridge,ko as useDispatch,jr as useEmitter,G as useEvent,Ae as useEventEmitter,Ts as useEventListener,he as useExistingVault,Ns as useExternalCollection,vr as useExternalManifest,ye as useExternalResource,Ko as useIIIFLanguage,ce as useImage,ot as useImageService,Te as useImageServiceLoader,Vs as useImageTile,Fr as useIsAuthEnabled,Me as useLoadImageService,Zo as useLocaleString,K as useManifest,xo as useMediaActions,So as useMediaElements,bo as useMediaState,An as usePaintables,B as usePaintingAnnotations,sn as usePolygonHelper,ve as useRange,lo as useRemoteStylesheet,No as useRenderControls,Bn as useRenderingStrategy,Oe as useRequestAnnotation,$ as useResourceContext,mo as useResourceEvents,Nn as useResources,Xr as useSearchService,Xe as useSelectorController,ti as useSelectorEmitter,$e as useSelectorEvents,ri as useSelectorHelper,Po as useSimpleMediaPlayer,be as useSimpleViewer,Gs as useStaticRenderingStrategy,wo as useStrategy,Js as useStyleHelper,fo as useStyles,co as useStylesheetStore,ln as useSvgEditor,Ze as useSvgEditorControls,we as useThumbnail,Go as useTranslations,Xo as useTransliteration,T as useVault,Bo as useVaultEffect,X as useVaultSelector,tn as useViewerPreset,sc as useViewportScroll,nc as useViewportTour,Mo as useVirtualAnnotationPage,Lo as useVirtualAnnotationPageContext,ge as useVisibleCanvases};
1
+ import{$ as er,$a as Ne,$b as De,A as Ao,Aa as Ir,Ab as ln,B as ko,Ba as Cr,Bb as cn,C as Mo,Ca as Rr,Cb as mn,D as Ho,Da as Pr,Db as un,E as Lo,Ea as Pe,Eb as ze,F as zo,Fa as wr,Fb as fn,G as Bo,Ga as Tr,Gb as pn,H as Fo,Ha as Er,Hb as dn,I as Oo,Ia as qr,Ib as gn,J as Vo,Ja as Nr,Jb as hn,K as Wo,Ka as Ar,Kb as yn,L as Do,La as kr,Lb as vn,M as Uo,Ma as Mr,Mb as xn,N as _o,Na as Hr,Nb as bn,O as $o,Oa as Lr,Ob as Sn,P as Ko,Pa as zr,Pb as In,Q as Qo,Qa as Br,Qb as qn,R as Go,Ra as Fr,Rb as Be,S as Xo,Sa as we,Sb as Nn,T as Yo,Ta as Te,Tb as Fe,U as xe,Ua as Or,Ub as B,V as Zo,Va as Vr,Vb as An,W as jo,Wa as Wr,Wb as Bn,X as Jo,Xa as Dr,Xb as Fn,Y as G,Ya as ie,Yb as On,Z as be,Za as Ee,Zb as Ve,_ as Se,_a as qe,_b as We,a as ho,aa as tr,ab as Ae,b as $,ba as or,bb as W,c as z,ca as Ie,cb as ke,d as pe,da as Ce,db as Me,e as yo,ea as rr,eb as He,f as de,fa as nr,fb as Ur,g as w,ga as T,gb as _r,h as K,ha as ir,hb as $r,i as vo,ia as ar,ib as Kr,j as ge,ja as sr,jb as Qr,k as he,ka as Re,kb as Gr,l as Q,la as lr,lb as Xr,m as ye,ma as cr,mb as Yr,n as xo,na as mr,nb as Zr,o as bo,oa as ur,ob as jr,p as So,pa as E,pb as H,q as Io,qa as fr,qb as Le,r as Co,ra as pr,rb as Jr,s as Ro,sa as dr,sb as en,t as Po,ta as gr,tb as ae,u as wo,ua as hr,ub as tn,v as To,va as yr,vb as on,w as ve,wa as vr,wb as rn,x as Eo,xa as xr,xb as nn,y as qo,ya as br,yb as an,z as No,za as Sr,zb as sn}from"./chunk-WI6XIZ2T.js";import"./chunk-UNH7HXGJ.js";import{a as Cn,b as Rn,c as Pn,d as wn,e as Tn,f as En,g as kn,h as Mn,i as Hn,j as Ln,k as zn,l as Oe}from"./chunk-P7XHGETS.js";export*from"@iiif/helpers/annotation-targets";import{useEffect as gt}from"react";import{useCallback as Ue,useEffect as pt,useRef as dt,useState as X}from"react";import{useStore as F}from"zustand";function _e(e){let[t,o]=X(0),r=T(),n=F(r,g=>g.tool.enabled),i=F(r,g=>g.tool.requestId),a=F(r,g=>g.getRequestId),l=F(r,g=>g.requestAnnotation),f=F(r,g=>g.completeRequest),m=F(r,g=>g.cancelRequest),s=dt(e?.onSuccess);s.current=e?.onSuccess;let[y,x]=X(!1),[b,v]=X(null),[p,S]=X(null),c=n&&i!==p,h=n&&i===p,d=Ue(async(g,R)=>{if(p){let M=s.current;x(!0);let q=await l(g,{...R,requestId:p});if(q)return M?.(q),o(A=>A+1),x(!1),v(q),q;let L={id:p,cancelled:!0,...Ce(g)};return M?.(L),v(L),o(A=>A+1),x(!1),L}return null},[l,p]),u=Ue(()=>{v(null),x(!1)},[]);return pt(()=>{let g=a();return S(g.requestId),()=>{g.clear()}},[t]),{id:t,busy:c,isPending:y,isActive:h,requestId:p,requestAnnotation:d,cancelRequest:()=>p?m(p):void 0,completeRequest:()=>p?f(p):void 0,reset:u,data:b}}var Qn=[{name:"Default",outer:{borderWidth:4,borderColor:"rgba(255, 255, 255, .4)"},inner:{borderWidth:2,borderColor:"#000"}},{name:"High contrast",outer:{borderWidth:3,borderColor:"#fff"},inner:{borderWidth:1,borderColor:"#000"}},{name:"Lightsaber",outer:{borderWidth:"4",borderColor:"rgba(56,68,255,0.64)"},inner:{borderWidth:"2",borderColor:"#fff"}},{name:"Bright",outer:{borderWidth:"6",borderColor:"#25d527"},inner:{borderWidth:"3",borderColor:"#a916ff"}},{name:"pink",outer:{borderWidth:"4",borderColor:"#ff00ff"},inner:{borderWidth:"2",borderColor:"#ffffff"}},{name:"fine (dark)",outer:{borderWidth:"1",borderColor:"#000000"},inner:{}},{name:"fine (light)",outer:{borderWidth:"1",borderColor:"#FFF"},inner:{}}];function $e(e){let{id:t,data:o,requestAnnotation:r,cancelRequest:n,isPending:i}=_e({onSuccess:a=>{e.updateShape(a.polygon)}});return gt(()=>(r({type:"polygon",open:e.shape?.open,points:e.shape?.points}),()=>{n()}),[]),null}import{createContext as ht,useCallback as Ke,useContext as Ge,useEffect as Qe,useMemo as se,useState as yt}from"react";import Xe from"mitt";import{jsx as vt}from"react/jsx-runtime";var Y=ht(Xe());Y.displayName="SelectorHelper";function ei({children:e}){return vt(Y.Provider,{value:se(()=>Xe(),[]),children:e})}function ti(){return Ge(Y)}function Ye(e){let t=Ze(),[o,r]=yt(!1);Qe(()=>t.withSelector(e).on("highlight",()=>{r(!0)}),[t,e]),Qe(()=>t.withSelector(e).on("clear-highlight",()=>{r(!1)}),[t,e]);let n=Ke(a=>{t.emit("click",{selectorId:e,event:a})},[e,t]),i=Ke(a=>{t.emit("hover",{selectorId:e,event:a})},[e,t]);return{controller:t,onClick:n,onHover:i,isHighlighted:o}}function Ze(){let e=Ge(Y);return se(()=>({withSelector(t){return{on(o,r){let n=i=>{i&&i.selectorId===t&&r(i)};return e.on(o,n),()=>{e.off(o,n)}},emit(o,r){e.emit(o,{...r,selectorId:t})}}},on(t,o){return e.on(t,o),()=>{e.off(t,o)}},emit(t,o){e.emit(t,o)}}),[e])}function oi(){let e=Ze();return se(()=>({withSelector(t){return{highlight(){e.emit("highlight",{selectorId:t})},clearHighlight(){e.emit("clear-highlight",{selectorId:t})},zoomTo(){e.emit("zoom-to",{selectorId:t})},addEventListener(o,r){return e.emit("event-listener",{selectorId:t,name:o,callback:r}),()=>{e.emit("remove-event-listener",{selectorId:t,name:o,callback:r})}},getImagePreview(){return new Promise((o,r)=>{e.emit("image-preview-request",{selectorId:t,resolve:o,reject:r})})},on(o,r){return e.withSelector(t).on(o,r)}}},highlight(t){e.emit("highlight",{selectorId:t})},clearHighlight(t){e.emit("clear-highlight",{selectorId:t})},zoomTo(t){e.emit("zoom-to",{selectorId:t})},addEventListener(t,o,r){return e.emit("event-listener",{selectorId:t,name:o,callback:r}),()=>{e.emit("remove-event-listener",{selectorId:t,name:o,callback:r})}},getImagePreview(t){return new Promise((o,r)=>{e.emit("image-preview-request",{selectorId:t,resolve:o,reject:r})})},on(t,o){return e.on(t,o)}}),[e])}import{jsx as je}from"react/jsx-runtime";function ui(e){let t=E(),o=e.annotationBucket,r=e.readOnly,n=e.id,{onClick:i,isHighlighted:a}=Ye(e.id),l=Re(),f=a?l.highlighted:l[o||"hidden"]||l.hidden;if(!t)return null;if(r){let m="shape",s=e.polygon,y=s.open;return s?je(m,{id:`shape-${n}`,points:s.points,open:y,onClick:i,relativeStyle:!0,target:{x:0,y:0,width:t.width,height:t.height},style:f}):null}return je($e,{image:t,shape:e.polygon||{id:e.id,open:!0,points:[]},updateShape:e.updatePolygon,theme:e.theme,controlsHtmlId:e.controlsHtmlId,renderControls:e.renderControls})}import{useCanvas as xt}from"@atlas-viewer/atlas";import{forwardRef as bt,useImperativeHandle as St}from"react";import{Fragment as It,jsx as Je}from"react/jsx-runtime";var xi=bt(function({canvasId:t},o){let r=xt(),n=Be(t||r?.id),i=w();return St(o,()=>n,[t,r]),!r||n.enabledPageIds.length===0?null:Je(It,{children:n.enabledPageIds.map(a=>Je(De.RenderAnnotationPage,{page:i.get(a)},a))})});import{useMemo as Pt}from"react";import{useMemo as Ct}from"react";import{Fragment as Rt,jsx as C,jsxs as Z}from"react/jsx-runtime";function j({metadata:e=[],config:t,labelWidth:o=16,showEmptyMessage:r=!0,allowHtml:n,emptyFallback:i,classes:a={},emptyMessage:l="No metadata available",emptyValueFallback:f="No value",emptyLabelFallback:m="",separator:s,tableFooter:y,tableHeader:x,customLabelRender:b,customValueRender:v}){let p=Ct(()=>{let c=(t||[]).reduce((d,u)=>[...d,...u.keys],[]),h={};for(let d of e){let u=d?.label?Object.values(d.label):[];for(let g of u)if(g?.length&&(c.indexOf(`metadata.${g[0]}`)!==-1||c.length===0)&&d){let R=`metadata.${g[0]}`;h[R]=h[R]?h[R]:[],h[R].push(d);break}}return h},[t,e]);return Object.keys(p).length===0&&r?C(Rt,{children:i})||C("div",{className:a.empty,children:l}):t?.length?Z("table",{className:a.container,children:[x,C("tbody",{children:t.map((c,h)=>{let d=[];for(let g of c.keys)for(let R of p[g]||[]){let M=C(H,{enableDangerouslySetInnerHTML:n,defaultText:f,separator:s,children:R.value},h+"__"+g);v?d.push(v(R,M)):d.push(M)}if(d.length===0)return null;let u=C(H,{enableDangerouslySetInnerHTML:n,separator:s,defaultText:m,children:c.label});return Z("tr",{className:a.row,children:[C("td",{className:a.label,style:o?{minWidth:o}:{},children:b?b(c.label,u):u}),C("td",{className:a.value,children:d})]},h)})}),y]}):Z("table",{className:a.container,children:[x,C("tbody",{children:e?.length?e.map((c,h)=>{if(!c)return null;let d=C(H,{enableDangerouslySetInnerHTML:n,defaultText:f,separator:s,children:c.label}),u=C(H,{enableDangerouslySetInnerHTML:n,defaultText:f,separator:s,children:c.value});return Z("tr",{className:a.row,children:[C("td",{className:a.label,style:o?{minWidth:o}:{},children:b?b(c.label,d):d}),C("td",{className:a.value,children:v?v(c,u):u})]},h)}):null}),y]})}import{jsx as wt}from"react/jsx-runtime";function ki(e){let t=Q(),o=E(),r=ve(),n=Pt(()=>{let i=t?.metadata||[],a=o?.metadata||[],l=r?.metadata||[];return[...i,...a,...l]},[t,o,r]);return wt(j,{metadata:n,...e})}import{useEffect as Nt,useState as At}from"react";import{createImageServiceRequest as Tt,imageServiceRequestToString as Et}from"@iiif/parser/image-3";import{useMemo as qt}from"react";function le(e,t={},o=[]){return qt(()=>{if(!e)return null;let r=t.quality;e&&e.extraQualities&&t.quality&&(e.extraQualities.includes(t.quality)||(r="default"));let n=Tt(e);return Et({identifier:n.identifier,server:n.server,scheme:n.scheme,type:"image",size:{max:!t.size?.width&&!t.size?.height,confined:!1,upscaled:!1,...t.size||{}},format:t.format||"jpg",region:t.region||{full:!0},rotation:t?.rotation?Number.isInteger(t.rotation)?{angle:t.rotation}:t.rotation:{angle:0},quality:r||"default",prefix:n.prefix,originalPath:n.originalPath})},[...o])}import{jsx as J}from"react/jsx-runtime";function kt(e){let t=typeof e.src=="string"?e.src:e.src.id,o=we(),[r,n]=At(!1),i;if(t){let l=o.loadServiceSync({id:t});l&&(i=l)}!i&&!r&&o.loadService({id:t}).then(()=>{n(!0)});let a=le(i,{size:e.size,selector:e.region,rotation:e.rotation,format:e.format,region:e.region,quality:e.quality},[r,e.src,e.size,e.region,e.rotation,e.format,e.region,e.quality]);return Nt(()=>()=>{n(!1)},[t]),a?J("img",{src:a,alt:e.alt,className:e.className,style:e.style}):J(Mt,{...e,fetchImageService:!1})}function Mt(e){if(e.fetchImageService)return J(kt,{...e});let t=typeof e.src=="string"?{id:e.src,profile:"level0"}:e.src,o=le(t,{size:e.size,selector:e.region,rotation:e.rotation,format:e.format,region:e.region,quality:e.quality},[e.src,e.size,e.region,e.rotation,e.format,e.region,e.quality]);return o?J("img",{src:o,alt:e.alt,className:e.className,style:e.style}):null}import{useMemo as Ht,useState as Lt}from"react";import{ErrorBoundary as zt}from"react-error-boundary";import{jsx as O,jsxs as Ft}from"react/jsx-runtime";function ta({src:e,errorFallback:t,interactive:o,skipSizes:r,children:n,renderViewerControls:i,viewControlsDeps:a,fluid:l,x:f,y:m,...s}){let y=he(),[x,b]=Lt(),v=t||Ve,[p,S]=Fe(),c=Ht(()=>{let d=S[e]?.status,u=p({id:e},{});return u?.height&&u.width&&d!=="loading"?{id:e,width:u.width,height:u.height,service:u,type:"Image",selector:{type:"BoxSelector",spatial:{x:0,y:0,width:u.width,height:u.height}},target:{type:"BoxSelector",spatial:{x:0,y:0,width:u.width,height:u.height}}}:null},[p,e,S]);if(!c||!c.height||!c.width)return null;let h=l?void 0:s.homePosition?s.homePosition.width/s.homePosition.height:c.width/c.height;return O(zt,{resetKeys:[],fallbackRender:d=>O(v,{...s,...d}),children:O(de,{vault:y,children:O(We,{...s,aspectRatio:h,containerProps:{style:{position:"relative"},...s.containerProps||{}},onCreated:d=>{b(d),s.onCreated&&s.onCreated(d)},children:Ft(ae.Provider,{value:x,children:[O(Le,{image:c,id:c.id,isStatic:!o,x:f,y:m},c.id),O(Bt,{viewerPreset:x,renderViewerControls:i,image:c,src:e,viewControlsDeps:a}),n]})})})})}function Bt({viewerPreset:e,renderViewerControls:t,image:o,src:r,viewControlsDeps:n}){return Pe(e&&t?"overlay":"none",`canvas-portal-controls-${r}`,ae.Provider,t&&o?{value:e||null,children:t({image:o,images:[o],type:"images"})}:{},[r,e,...n||[]]),null}import{jsx as Ot}from"react/jsx-runtime";function sa(e){let t=Q();return Ot(j,{metadata:t?.metadata||[],...e})}import{useLayoutEffect as _t,useRef as $t}from"react";import*as ce from"react-lazy-load-image-component";import{getValue as Vt}from"@iiif/helpers/i18n";import{Fragment as et,jsx as k,jsxs as Ut}from"react/jsx-runtime";var{LazyLoadComponent:Wt}=ce||ce.default;function tt(e){let{size:t,visible:o,classes:r,canvasId:n,figure:i}=e,a=t?.width||128,l=t?.height||t?.width||128,f=k(Dt,{...e}),m=k(Wt,{threshold:300,style:{height:l,width:a},visibleByDefault:o,children:n?k(pe,{canvas:n,children:f}):f});return i?k("figure",{className:r?.figure,children:m}):m}function Dt({fallback:e,size:t,classes:o,showLabel:r,alt:n,dereference:i=!1}){let a=E(),l=t?.width||128,f=t?.height||t?.width||128,m=n||Vt(a?.label)||"",s=Te({width:l,height:f,allowUnsafe:!0},i);return!s||s.type!=="fixed"?k(et,{children:e}):Ut(et,{children:[k("div",{className:o?.imageWrapper,children:k("img",{className:o?.img,src:s.id,alt:m})}),r?k(H,{as:"figcaption",className:o?.label,children:a?.label}):null]})}import{jsx as D}from"react/jsx-runtime";function ba({scrollBehaviour:e,dereference:t,flat:o,size:r,classes:n={},showLabel:i,figure:a,fallback:l}){let f=$t(null),{items:m,sequence:s,currentSequenceIndex:y,setSequenceIndex:x}=xe(),b={row:n.selected?.row||n.row,item:n.selected?.item||n.item,figure:n.selected?.figure||n.figure,img:n.selected?.img||n.img,label:n.selected?.label||n.label,imageWrapper:n.selected?.imageWrapper||n.imageWrapper};_t(()=>{if(!f.current)return;let p=f.current.querySelector("[data-selected=true]");p&&p.scrollIntoView({behavior:e||"instant",block:"nearest",inline:"center"})},[y]);let v=[];for(let p of s){let S=[],c=s[y]===p;for(let h of p){let d=m[h];S.push(D("div",{className:c?b.item:n.item,children:D(tt,{classes:c?b:n,canvasId:d.id,size:r,dereference:t,showLabel:i,figure:a,placeholder:D("div",{style:{height:128,width:128}}),fallback:l})},h))}if(o){v.push(S);continue}v.push(D("div",{onClick:h=>{x(s.indexOf(p))},"data-selected":c,className:c?b.row:n.row,children:S},p.join("-")))}return D("div",{ref:f,className:n.container,children:v})}import{useStore as ee}from"zustand";function ot(){let e=T(),t=ee(e,i=>i.completeRequest),o=ee(e,i=>i.polygonState.currentTool),r=ee(e,i=>i.polygonState.selectedStamp),n=ee(e,i=>i.switchTool);return{completeRequest:t,currentTool:o,selectedStamp:r,switchTool:n}}import{Fragment as rt,jsx as P,jsxs as nt}from"react/jsx-runtime";var Kt={draw:!0,polygon:!0,line:!0,lineBox:!0,box:!0,triangle:!0,hexagon:!0,circle:!0,delete:!0,pen:!0};function Ta({showShapes:e=!0,enabled:t=Kt,classNames:o={},icons:r={}}){let{currentTool:n,switchTool:i,selectedStamp:a}=ot();return nt(rt,{children:[n,P("button",{className:o.button,onClick:i.pointer,"data-active":n==="pointer",children:r.PointerIcon||"Pointer"}),P("button",{className:o.button,onClick:i.hand,"data-active":n==="hand",children:r.HandIcon||"Hand"}),e?nt(rt,{children:[t.box&&P("button",{className:o.button,onClick:i.box,"data-active":n==="box",children:r.BoxIcon||"Box"}),t.pen&&P("button",{className:o.button,onClick:i.pen,"data-active":n==="pen",children:r.PenIcon||"Pen"}),t.draw&&P("button",{className:o.button,onClick:i.draw,"data-active":n==="pencil",children:r.DrawIcon||"Draw"}),t.line&&P("button",{className:o.button,onClick:i.line,"data-active":n==="line",children:r.LineIcon||"Line"}),t.lineBox&&P("button",{className:o.button,onClick:i.lineBox,"data-active":n==="lineBox",children:r.LineBoxIcon||"LineBox"}),t.triangle&&P("button",{className:o.button,onClick:i.triangle,"data-active":n==="stamp"&&a?.id==="triangle",children:r.TriangleIcon||"Triangle"}),t.hexagon&&P("button",{className:o.button,onClick:i.hexagon,"data-active":n==="stamp"&&a?.id==="hexagon",children:r.HexagonIcon||"Hexagon"}),t.circle&&P("button",{className:o.button,"data-active":n==="stamp"&&a?.id==="circle",onClick:i.circle,children:r.CircleIcon||"Circle"})]}):null,t.delete&&P("button",{className:o.button,onClick:i.remove,children:r.DeleteForeverIcon||"Delete"})]})}import{jsx as Qt}from"react/jsx-runtime";function Aa({annotation:e,children:t}){return Qt(z,{value:{annotation:e},children:t})}import{jsx as Gt}from"react/jsx-runtime";function La({annotationPage:e,children:t}){return Gt(z,{value:{annotationPage:e},children:t})}import{jsx as Xt}from"react/jsx-runtime";function Oa({collection:e,children:t}){return Xt(z,{value:{collection:e},children:t})}function Ua(e,t={}){return B(t)}import{useCanvas as Yt}from"@atlas-viewer/atlas";import{useEffect as Zt,useMemo as me,useState as jt}from"react";function Xa({canvasId:e}={}){let t=Yt(),o=ge(),r=me(()=>e?[e]:t?[t.id]:o.map(m=>m.id),[e,t,o]),[n,i]=jt({}),a=ze();Zt(()=>{let m=s=>{let y=s.partOf.canvasId;y&&i(x=>({...x,[y]:s.choice}))};return a.on("choice-change",m),()=>{a.off("choice-change",m)}},[]);let l=me(()=>{let m=[];for(let s of r){let y=n[s];y&&m.push({canvasId:s,choice:y})}return m},[r,n]),f=me(()=>({makeChoice:(m,s)=>{a.emit("make-choice",{choiceId:m,...s})}}),[a]);return{choices:l,actions:f}}function Za(e,t=!1){}function ts(e){let o=$().manifest,r=e?e.map(n=>typeof n=="string"?n:n?.id):[];return K(n=>{let i=o?n.iiif.entities.Manifest[o]:void 0,a=i?.items||[];if(typeof e>"u")return a;let l=[];for(let f of i?.items||[])r.indexOf(f.id)!==-1&&l.push(f);return l},[r.join("/")])}import{useMemo as Jt}from"react";function as(e,t=[]){let{id:o,selector:r}=e,n=$(),i=o||n.collection,a=K(l=>i?l.iiif.entities.Collection[i]:void 0,[i]);return Jt(()=>{if(a)return r?r(a):a},[a,r,...t])}import{startTransition as eo,useMemo as to}from"react";import{useStore as it}from"zustand";function us(){let e=T(),t=it(e,r=>r.completeRequest),o=it(e,r=>r.cancelRequest);return to(()=>({saveAnnotation:()=>{eo(()=>{t()})},cancelRequest:o}),[t,o])}import{useCallback as oo}from"react";import{useStore as ue}from"zustand";function hs({requestId:e}={}){let t=T(),o=ue(t,l=>l.metadata),r=ue(t,l=>l.tool.requestId),n=e||r,i=ue(t,l=>l.setMetadata),a=oo(l=>i(l,n||void 0),[i,n]);return[n?o[n]||{}:{},a]}import{useStore as ro}from"zustand";function Ss(e){let t=T(),o=ro(t,r=>r.tool.requestId);G("polygons.start-transition",r=>{e.requestId&&o!==e.requestId||e?.onStart?.(r.transitionIntent)},[o,e.requestId]),G("polygons.end-transition",r=>{e.requestId&&o!==e.requestId||e?.onEnd?.(r.transitionIntent,r.response)},[o,e.requestId]),G("polygons.transition",r=>{e.requestId&&o!==e.requestId||e?.onTransition?.(r.transitionIntent)},[o,e.requestId])}import{useEffect as no,useMemo as io}from"react";import{createEventsHelper as ao}from"@iiif/helpers/events";function ws(e,t,o,r,n=[]){let i=w(),a=io(()=>ao(i),[i]);no(()=>{let l=e;return l?(a.addEventListener(l,t,o,r),()=>{a.removeEventListener(l,t,o)}):()=>{}},[a,e,t,...n])}function Ns(e,t){let{id:o,isLoaded:r,error:n,resource:i,requestId:a,cached:l}=ye(e,t);return{id:o,isLoaded:r,error:n,manifest:i,requestId:a,cached:l}}import{getImageServices as at}from"@iiif/parser/image-3";import{useEffect as so,useMemo as st,useState as te}from"react";function lt({cacheKey:e}={}){let t=E(),o=B(),r=w(),n=Me(),i=He(),[a,l]=te(void 0),[f,m]=te(!1),[s,y]=te("idle"),[x,b]=te(void 0),v=t?t.id:"undefined",p=st(()=>{try{if(t&&o.length){let c=o[0],h=r.get(c.body[0]),u=at(h)[0];return u&&n(u,{width:u.width||t.width,height:u.height||t.height},!0)||void 0}}catch(c){console.error(c)}},[v,e,t]),S=s==="success"&&a?a:p;return so(()=>{(async()=>{try{if(t&&o.length){let c=o[0],h=r.get(c.body[0]),u=at(h)[0];if(!u)return;m(!0),y("loading");try{let g=await i(u,{width:u.width||t.width,height:u.height||t.height})||void 0;l(g),y("success"),m(!1)}catch(g){y("error"),b(g)}}}catch(c){y("error"),b(c)}})()},[v,e]),st(()=>({data:S,isFetching:f,status:s,error:x}),[S,f,s,x])}function Vs(){let e=lt();return{isLoading:e.isFetching,tile:e.data?{id:e.data.id||e.data["@id"],width:e.data.width,height:e.data.height,imageService:e.data,thumbnail:void 0}:null}}import{useMemo as fe}from"react";import{createPaintingAnnotationsHelper as lo}from"@iiif/helpers";function Gs({supports:e=["empty","images","media","3d-model","textual-content","complex-timeline"]}={}){let t=w(),o=E(),r=B(),n=fe(()=>lo(t),[t]),i=fe(()=>n.getPaintables(r),[n,r]);return fe(()=>Oe({canvas:o,loadImageService:a=>a,paintables:i,supports:e}),[o,i,e])}import{createStylesHelper as co}from"@iiif/helpers/styles";import{useMemo as mo}from"react";function Js(){let e=w();return mo(()=>co(e),[e])}import{useCallback as uo,useEffect as oe,useMemo as ct,useRef as re,useState as mt}from"react";function rl(e){let{initial:t,regions:o,progress:r,getProgress:n,enabled:i=!0,easing:a,reportEveryFrame:l=!1,pollInterval:f=Ee,loop:m=!1,onEnter:s,onExit:y,onProgress:x,jumpTo:b}=e,v=ct(()=>Ae(t,o),[t,o]),[p,S]=mt(()=>-1),[c,h]=mt(0),d=re(-1),u=re(0),g=re(!0),R=re(()=>{});oe(()=>(g.current=!0,()=>{g.current=!1}),[]);let M=ct(()=>{if(!a)return W(ie);if(typeof a=="function")return a;if(Array.isArray(a)&&a.length===4)return W(a);let I=qe[a];return I?W(I):W(ie)},[a]),q=uo(I=>{if(!(I<0||I>=v.length)&&(S(I),d.current=I,u.current=0,h(0),s))try{s(I)}catch{}},[v,s]);oe(()=>{R.current=q,b&&b(q)},[q,b]);function L(I){let{index:V,t:U}=ke(I,v),N=V;if(m&&v.length>0){let ne=v.length;N=(V%ne+ne)%ne}let _=M(U);if(N!==d.current){if(d.current>=0&&y)try{y(d.current)}catch{}if(N>=0&&s)try{s(N)}catch{}d.current=N,g.current&&S(N)}if(u.current=_,g.current&&(l||N!==p)&&h(_),x&&N>=0)try{x(N,_)}catch{}}oe(()=>{i&&typeof r=="number"&&L(r)},[r,i]),oe(()=>{if(!i||typeof n!="function")return;let I=null,V=()=>{try{let U=n();L(U)}catch{}};return V(),I=setInterval(V,f),()=>clearInterval(I)},[n,i,f]);let A=p>=0&&p<v.length?v[p]:void 0,ft=A?Ne(A.from,A.to,u.current):void 0;return{transitions:v,currentIndex:p,currentTransition:A,t:u.current,rect:ft,jumpTo:q}}import{useEffect as fo,useRef as ut,useState as po}from"react";function al(e,t={}){let{axis:o="y",offset:r=0,steps:n=1,enabled:i=!0}=t,[a,l]=po(0),f=ut(-1),m=ut(null);return fo(()=>{if(!i||!e||!e.current)return;let s=e.current,y=()=>{let b=o==="y"?s.scrollTop:s.scrollLeft,v=o==="y"?s.clientHeight:s.clientWidth,S=(o==="y"?s.scrollHeight:s.scrollWidth)-v,h=(S<=0?0:Math.max(0,Math.min(1,(b+r)/S)))*n;h!==f.current&&(f.current=h,l(h)),m.current=null},x=()=>{m.current===null&&(m.current=requestAnimationFrame(y))};return s.addEventListener("scroll",x,{passive:!0}),y(),()=>{s.removeEventListener("scroll",x),m.current!==null&&cancelAnimationFrame(m.current)}},[e,o,r,n,i]),a}function ll(e,t){let{x:o,y:r,width:n,height:i}=e,{x:a,y:l}=t,{width:f,height:m}=t;return o+n>a&&o<a+f&&r+i>l&&r<l+m}import go from"tiny-invariant";function dl(e,t){let o=e.boundingBox||Se(e.polygon);if(e.polygon&&!be(e.polygon.points)){let r=e.target||Ie(e.polygon,t);return go(r?.type==="SvgSelector"),{type:"SvgSelector",points:e.polygon.points,spatial:{unit:"pixel",...o||{}},svgShape:e.polygon.open?"polyline":"polygon",svg:r.value}}return{type:"BoxSelector",spatial:o}}export{Aa as AnnotationContext,La as AnnotationPageContext,lr as AnnotationStyleProvider,ar as AtlasStoreProvider,nr as AtlasStoreReactContext,Ko as Auth,Fo as AuthProvider,Lo as AuthRContext,zo as AuthReactContext,Bo as AuthReactContextActions,xi as CanvasAnnotations,pe as CanvasContext,De as CanvasPanel,Fn as CanvasStrategyProvider,On as CanvasWorldObject,Oa as CollectionContext,ki as CombinedMetadata,Wr as ComplexTimelineProvider,yn as ContextBridge,qr as ControlsReactContext,$e as CreateCustomShape,dn as CustomContextBridge,gn as CustomContextBridgeProvider,ie as DEFAULT_BEZIER,Ee as DEFAULT_POLL_INTERVAL,In as DefaultEditingTools,qe as EASING_PRESETS,jo as EventEmitterProvider,fn as EventsProvider,Mt as Image,ta as ImageService,Fr as ImageServiceLoaderContext,Xo as InnerViewerProvider,_r as LanguageProvider,Xr as LanguageString,H as LocaleString,bo as ManifestContext,sa as ManifestMetadata,Ir as MediaPlayerProvider,j as Metadata,ui as PolygonSelector,So as RangeContext,Zo as ReactEmitterContext,un as ReactEventContext,yo as ReactVaultContext,gr as RegionHighlight,Er as Render3DModelStrategy,Ar as RenderAccompanyingCanvas,hr as RenderAnnotation,Sn as RenderAnnotationEditing,vr as RenderAnnotationPage,zr as RenderAnnotationStrategy,Vr as RenderAudioStrategy,Jr as RenderComplexTimelineStrategy,en as RenderEmptyStrategy,on as RenderImageStrategy,Ta as RenderSvgEditorControls,rn as RenderTextualContentStrategy,nn as RenderVideoStrategy,an as RenderYouTubeStrategy,dr as ResizeWorldItem,z as ResourceProvider,ho as ResourceReactContext,ei as SelectorControllerProvider,ba as SequenceThumbnails,Yo as SimpleViewerProvider,Go as SimpleViewerReactContext,tt as SingleCanvasThumbnail,wr as StrategyReactContext,Or as ThumbnailFallbackImage,Ur as TranslationProvider,$r as TransliterationProvider,de as VaultProvider,ae as ViewerPresetContext,Lr as VirtualAnnotationProvider,vo as VisibleCanvasReactContext,dl as annotationResponseToSelector,ko as authDetailsForResource,Ae as buildTransitions,rr as createAtlasStore,No as createAuthStateStore,Ao as createProbe,W as cubicBezierEasing,mn as defaultEmitter,ln as defaultSvgTheme,Pn as emptyActions,En as emptyStrategy,Co as findAllCanvasesInRange,Io as findFirstCanvasFromRange,Ro as findManifestSelectedRange,Po as findSelectedRange,qn as flattenAnnotationPageIds,Rr as formatTime,kn as get3dStrategy,ir as getAtlasStoreByName,zn as getComplexTimelineStrategy,sr as getDefaultAnnotationStyles,Mn as getImageStrategy,To as getManifestSequence,Rn as getParsedTargetSelector,Oe as getRenderingStrategy,ke as getStepFromProgress,Hn as getTextualContentStrategy,Ln as getVideoStrategy,wo as getVisibleCanvasesFromCanvasId,qo as hasAuth,Ne as interpolateRect,tr as isBoxSelector,be as isRectangle,er as isSvgSelector,Ho as makeAccessServiceRequest,Mo as makeAccessTokenRequest,Cn as parseSpecificResource,Ie as polygonToTarget,Ce as requestToAnnotationResponse,or as seraliseSupportedSelector,Qn as svgThemes,ll as targetIntersects,wn as unknownResponse,Tn as unsupportedStrategy,ur as useAnnotation,yr as useAnnotationPage,Be as useAnnotationPageManager,Re as useAnnotationStyles,Ua as useAnnotationsAtTime,xn as useAtlasContextMenu,T as useAtlasStore,Wo as useAuthActions,Uo as useAuthService,Vo as useAuthStore,$o as useAuthToken,_o as useAuthTokens,E as useCanvas,Xa as useCanvasChoices,Za as useCanvasClock,Eo as useCanvasSequence,Cr as useCanvasStartTime,ts as useCanvasSubset,Yr as useClosestLanguage,as as useCollection,Dr as useComplexTimeline,hn as useContextBridge,vn as useContextMenuStore,jr as useCreateLocaleString,us as useCurrentAnnotationActions,hs as useCurrentAnnotationMetadata,bn as useCurrentAnnotationRequest,Ss as useCurrentAnnotationTransition,Do as useCurrentAuth,pn as useCustomContextBridge,kr as useDispatch,Jo as useEmitter,G as useEvent,ze as useEventEmitter,ws as useEventListener,he as useExistingVault,Ns as useExternalCollection,xo as useExternalManifest,ye as useExternalResource,Qr as useIIIFLanguage,le as useImage,lt as useImageService,we as useImageServiceLoader,Vs as useImageTile,Oo as useIsAuthEnabled,Fe as useLoadImageService,Zr as useLocaleString,Q as useManifest,br as useMediaActions,Sr as useMediaElements,xr as useMediaState,An as usePaintables,B as usePaintingAnnotations,sn as usePolygonHelper,ve as useRange,mr as useRemoteStylesheet,Nr as useRenderControls,Bn as useRenderingStrategy,_e as useRequestAnnotation,$ as useResourceContext,fr as useResourceEvents,Nn as useResources,Qo as useSearchService,Ze as useSelectorController,ti as useSelectorEmitter,Ye as useSelectorEvents,oi as useSelectorHelper,Pr as useSimpleMediaPlayer,xe as useSimpleViewer,Gs as useStaticRenderingStrategy,Tr as useStrategy,Js as useStyleHelper,pr as useStyles,cr as useStylesheetStore,cn as useSvgEditor,ot as useSvgEditorControls,Te as useThumbnail,Gr as useTranslations,Kr as useTransliteration,w as useVault,Br as useVaultEffect,K as useVaultSelector,tn as useViewerPreset,al as useViewportScroll,rl as useViewportTour,Mr as useVirtualAnnotationPage,Hr as useVirtualAnnotationPageContext,ge as useVisibleCanvases};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-iiif-vault",
3
- "version": "2.0.12",
3
+ "version": "2.0.13",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -1,49 +0,0 @@
1
- import{c as ln,l as un}from"./chunk-P7XHGETS.js";import{forwardRef as zr,useImperativeHandle as Wl,useMemo as Ul}from"react";import Or,{useContext as Br,useMemo as Hr}from"react";import{jsx as qr}from"react/jsx-runtime";var Dr={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},Fe=Or.createContext(Dr),_=()=>Br(Fe);function ie({value:e,children:t}){let n=_(),o=Hr(()=>({...n,...e}),[e,n]);return qr(Fe.Provider,{value:o,children:t})}import{jsx as Fr}from"react/jsx-runtime";function te({canvas:e,children:t}){return Fr(ie,{value:{canvas:e},children:t})}import $r,{useState as Wr}from"react";import{Vault as cn,globalVault as Ur}from"@iiif/helpers/vault";import{jsx as dn}from"react/jsx-runtime";var le=$r.createContext({vault:null,setVaultInstance:e=>{}});function ge({vault:e,vaultOptions:t,useGlobal:n,resources:o,children:s}){let[i,r]=Wr(()=>e||(n?Ur(t):t?new cn(t):new cn));return dn(le.Provider,{value:{vault:i,setVaultInstance:r},children:dn(ie,{value:o||{},children:s})})}import{useContext as Yr}from"react";import Gr from"react";import{useContext as _r}from"react";var M=()=>{let{vault:e}=_r(le);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};import{useEffect as jr,useState as Kr}from"react";function k(e,t=[]){let n=M(),[o,s]=Kr(()=>e(n.getState(),n));return jr(()=>n.subscribe(i=>e(i,n),i=>{s(i)},!1),t),o}var he=Gr.createContext([]);function $e(){let e=Yr(he);return k(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}import{globalVault as Qr}from"@iiif/helpers/vault";import{useContext as Xr}from"react";function ye(e){let t=Xr(le);return e||(t&&t.vault?t.vault:Qr())}import{useMemo as Zr}from"react";function B(e={},t=[]){let{id:n,selector:o}=e,s=_(),i=M(),r=n||s.manifest,a=k(l=>r?l.iiif.entities.Manifest[r]:void 0,[r]);return Zr(()=>{if(a)return o?o(a):a},[a,o,...t])}import{useContext as Ci}from"react";import{createContext as Ri,useMemo as Ai}from"react";import{useEffect as Jr,useMemo as ei,useState as yt}from"react";function mn(e,{noCache:t=!1}={}){let n=typeof e=="string"?e:e.id,o=ye(),[s,i]=yt(n),[r,a]=yt(void 0),l=ei(()=>o.get(n,{skipSelfReturn:!0})||void 0,[n,o]),[u,p]=yt(l);return Jr(()=>{(async()=>{try{let c=l&&!t?l:await o.load(n),d=c?c.id||c["@id"]:null;c&&s!==d&&i(d),p(c)}catch(c){a(c)}})()},[n,t]),{isLoaded:!!u,id:s,requestId:n,error:r,resource:u,cached:!!(u&&u===l)}}function pn(e,t){let{id:n,isLoaded:o,error:s,resource:i,requestId:r,cached:a}=mn(e,t);return{id:n,isLoaded:o,error:s,manifest:i,requestId:r,cached:a}}import{jsx as ti}from"react/jsx-runtime";function fn({manifest:e,children:t}){return ti(ie,{value:{manifest:e},children:t})}import{jsx as ni}from"react/jsx-runtime";function gn({range:e,children:t}){return ni(ie,{value:{range:e},children:t})}function oi(e,t){for(let n of t.items){if(n.type==="Canvas")return n;if(n.type==="SpecificResource")return n.source;if(n.type==="Range"){let o=oi(e,e.get(n));if(o)return o}}return null}function vt(e,t){let n=[];for(let o of t.items)if(o.type==="SpecificResource"&&o.source?.type==="Canvas"&&(o.source.id.indexOf("#")!==-1?n.push({id:o.source.id.split("#")[0],type:"Canvas"}):n.push(o.source)),o.type==="Range"&&n.push(...vt(e,e.get(o))),o.type==="SpecificResource"){let s=typeof o.source=="string"?o.source:o.source.id;n.push({id:s,type:"Canvas"})}return n}function Wu(e,t,n){for(let o of t.structures){let s=hn(e,e.get(o),n);if(s)return s}return null}function hn(e,t,n){for(let o of t.items){let s=o?.source?.id?.split("#")[0];if(o.type==="SpecificResource"&&o.source===n||o.type==="SpecificResource"&&o.source?.type==="Canvas"&&n===s)return t;if(o.type==="Range"){let i=hn(e,e.get(o),n);if(i)return i}}return null}function ju(e,t,n,o=!1){let s=t.behavior,i=n?e.get(n):null;if(!i)return[];let r=i.behavior,a=o?!1:s.includes("paged"),l=a?!1:s.includes("continuous"),u=a||l?!1:s.includes("individuals"),p=r.includes("facing-pages"),c=r.includes("non-paged");if(p||c||u||o)return[{id:i.id,type:"Canvas"}];let[d,m]=St(e,t);if(l)return d;let y=d.findIndex(g=>g.id===n);if(y===-1)return[];for(let g of m)if(g.includes(y))return g.map(S=>d[S]);return[{id:i.id,type:"Canvas"}]}function St(e,t,{disablePaging:n,skipNonPaged:o}={}){let s=t.behavior,i=s.includes("paged"),r=i?!1:s.includes("continuous"),a=i||r?!1:s.includes("individuals"),l=t.type==="Manifest"?t.items:vt(e,t);if(r)return[l,[l.map((y,g)=>g)]];if(a||!i||n)return[l,l.map((y,g)=>[g])];let u=[],p=[],c=()=>{p.length&&(u.push([...p]),p=[])},d=0,m=!1;for(let y=0;y<l.length;y++){let g=e.get(l[y]);if(g.behavior.includes("non-paged")){y===d&&d++,o||(c(),u.push([y]),c());continue}if(y===d||g.behavior.includes("facing-pages")){p.length&&(m=!0),c(),u.push([y]),c();continue}if(p.push(y),m){c(),m=!1;continue}p.length>1&&c()}return p.length&&c(),[l,u]}import{useCallback as We,useMemo as ii,useRef as ai,useState as si}from"react";import{useMemo as ri}from"react";function yn(e={},t=[]){let{id:n,selector:o}=e,s=_(),i=n||s.range,r=k(a=>i?a.iiif.entities.Range[i]:void 0,[i]);return ri(()=>{if(r)return o?o(r):r},[r,o,...t])}function vn({startCanvas:e,disablePaging:t}){let n=M(),o=B(),s=yn(),[i,r]=si(void 0),a=s||o;if(!a)throw new Error("Nothing selected");let[l,u]=ii(()=>St(n,a,{disablePaging:t}),[n,a,t]),p=ai(u);if(p.current!==u){let S=p.current[i][0],v=u.findIndex(f=>f.includes(S));p.current=u,r(v)}let c=We(g=>{let S=u.findIndex(v=>v.includes(g));r(S===-1?0:S)},[l,u]),d=We(g=>{let S=l.findIndex(v=>v.id===g);S!==-1?c(S):r(0)},[l,u]),m=We(()=>{r(g=>g>=u.length-1?g:g+1)},[u]),y=We(()=>{r(g=>g<=0?0:g-1)},[u]);return typeof i>"u"&&(e?d(e):r(0)),{visibleItems:u[i]?.map(g=>l[g].id)||[],cursor:i,items:l,sequence:u,hasPrevious:i>0,hasNext:i<u.length-1,setSequenceIndex:r,setCanvasIndex:c,setCanvasId:d,next:m,previous:y}}import{createContext as Ct,useContext as Mn,useEffect as ui,useMemo as ci}from"react";import{useStore as Ve}from"zustand";import{createStore as xn}from"zustand/vanilla";function ic(e){let t=e.service||e.services||[];for(let n of t)if(n.type==="AuthProbeService2")return!0;return!1}function j(e,t,n){let o=t.findIndex(r=>r.service.id===e);if(o===-1)return t;let s=[...t],i=n(s[o]);return i===s[o]?t:(s[o]=i,s)}var bn=()=>xn((e,t)=>({currentAuth:-1,authItems:[],login:()=>{let n=t().authItems[t().currentAuth];if(!n||n.isPending||n.isLoggedIn)return;if(n.type!=="active")throw new Error("Cannot login to non-active service");let o=n.service.service.find(s=>s.type==="AuthAccessTokenService2");if(!o)throw new Error("Token service not found");e(()=>({authItems:j(n.id,t().authItems,s=>({...s,isPending:!0}))})),Sn(n.service).then(()=>{xt(o).then(s=>{let i=s.expiresIn,r=Date.now()+i*1e3;e(()=>({authItems:j(n.id,t().authItems,a=>({...a,isLoggedIn:!0,isPending:!1,session:{token:s.accessToken,expires:r}}))}))}).catch(s=>{e(()=>({authItems:j(n.id,t().authItems,i=>({...i,isLoggedIn:!1,isPending:!1,error:s.message}))}))})})},logout:()=>{let n=t().authItems[t().currentAuth];if(!n||n.isPending||!n.isLoggedIn)return;if(n.type!=="active")throw new Error("Cannot logout of non-active service");let o=n.service.service.find(r=>r.type==="AuthLogoutService2");if(!o)return;let s=`${o.id}?origin=${An()}`,i=window.open(s);e(()=>({authItems:j(n.id,t().authItems,r=>({...r,isLoggedIn:!1,session:null,isPending:!1}))}))},nextAuth:()=>{let n=t().authItems.length,o=t().currentAuth+1;o>=n||e(()=>({currentAuth:o}))},previousAuth:()=>{let n=t().currentAuth-1;n<0||e(()=>({currentAuth:n}))},setAuth:n=>{n!==-1&&(n<0||n>=t().authItems.length)||e(()=>({currentAuth:n}))},addService:(n,o)=>{if(!n.service)return;let s=n.service.find(a=>a.type==="AuthAccessTokenService2"),i=n;if(t().authItems.find(a=>a.service.id===n.id)){e(()=>({authItems:j(n.id,t().authItems,a=>({...a,instances:a.instances+1}))}));return}if(e(()=>({currentAuth:i.profile==="active"?0:t().currentAuth,authItems:[{id:n.id,type:n.profile,service:n,probeId:o,canAuthenticate:!0,instances:1,isPending:!1,isLoggedIn:!1,session:null},...t().authItems]})),n.profile==="external"){if(!s)throw new Error("Token service not found");xt(s).then(a=>{e(()=>({authItems:j(n.id,t().authItems,l=>({...l,isLoggedIn:!0,isPending:!1,session:{token:a.accessToken,expires:a.expiresIn}}))}))}).catch(a=>{e(()=>({authItems:j(n.id,t().authItems,l=>({...l,isLoggedIn:!1,isPending:!1,canAuthenticate:!1,error:a.message}))}))})}if(n.profile==="kiosk"){if(!s)throw new Error("Token service not found");e(()=>({authItems:j(n.id,t().authItems,a=>({...a,isPending:!0}))})),Sn(i).then(()=>{xt(s).then(a=>{e(()=>({authItems:j(n.id,t().authItems,l=>({...l,isLoggedIn:!0,isPending:!1,session:{token:a.accessToken,expires:a.expiresIn}}))}))}).catch(a=>{e(()=>({authItems:j(n.id,t().authItems,l=>({...l,isLoggedIn:!1,isPending:!1,error:a.message}))}))})})}n.profile},removeService:(n,o)=>{let s=t().currentAuth===t().authItems.findIndex(r=>r.service.id===n.id),i=t().currentAuth;if(s){let r=t().authItems.find(l=>l.service.id===n.id);r&&r.instances>1||(i=t().authItems.findIndex(u=>u.service.id!==n.id&&u.instances>0))}e(()=>({authItems:j(n.id,t().authItems,r=>({...r,instances:r.instances-1})),currentAuth:i}))}})),Cn=(e,t)=>xn((n,o)=>({service:e,status:e?"unknown":"success",shouldRedirect:!1,redirectResource:null,shouldSubstitute:!1,substituteResource:null,error:null,errorHeading:null,errorNote:null,shouldDisplayResource:!1,token:t||null,async probe(){if(!o().service)return;let s=o().service?.id;if(!s){n({status:"error",error:"Service ID not found",errorHeading:{en:["Service ID not found"]}});return}n({status:"probing"});let i=o().token;try{let r=await fetch(s,{headers:i?{Authorization:`Bearer ${o().token}`,Accept:"application/json"}:{Accept:"application/json"}}).then(a=>a.json());if(r.status===200)n({status:"success",shouldDisplayResource:!0,error:null,errorHeading:null,errorNote:null,shouldSubstitute:!1,shouldRedirect:!1});else if(r.status<400&&r.status>=300){if(!r.location)throw new Error("Redirect location not found");n({status:"error",shouldDisplayResource:!1,shouldRedirect:!0,redirectResource:r.location||null})}else if(r.status===401)n({status:"error",shouldDisplayResource:!1,shouldRedirect:!1,shouldSubstitute:!!r.substitute,substituteResource:r.substitute||null,error:"Unauthorized",errorHeading:r.heading||{en:["Unauthorized"]},errorNote:r.note||null});else throw new Error("Unknown error")}catch(r){n({status:"error",error:r.message,errorHeading:{en:["Unknown error"]}})}},setToken(s){n({token:s})}}));function Rn(e){let t=e.service||e.services||[],n={hasAuth:!1,services:{}};for(let o of t)if(o.type==="AuthProbeService2"){n.services.probe=o,n.hasAuth=!0;let s=o.service.filter(i=>i.type==="AuthAccessService2");s[0]&&(n.services.access=s[0])}return n}async function xt(e,{strict:t=!0}={}){return new Promise((n,o)=>{let s=Math.random().toString(36).substring(7),i=`${e.id}?messageId=${s}&origin=${window.location.origin}`,r=u=>{let p=u.data;if(p.messageId===s){if(t&&p.type!=="AuthAccessToken2"){a(),o("Invalid response, expected type=AuthAccessToken2");return}if(!p.accessToken){a(),o("Invalid response, expected accessToken");return}a(),n(p)}},a=()=>window.removeEventListener("message",r),l=document.createElement("iframe");l.src=i,l.style.display="none",document.body.appendChild(l),window.addEventListener("message",r)})}function An(e){let t=window.location;if(e){let n=document.createElement("a");return n.href=e,n.protocol+"//"+n.hostname+(n.port?":"+n.port:"")}return t.protocol+"//"+t.hostname+(t.port?":"+t.port:"")}async function Sn(e){let t=`${e.id}?origin=${An()}`,n=window.open(t);if(!n)throw new Error("Failed to open window");return new Promise((o,s)=>{let i=setInterval(()=>{n.closed&&(clearInterval(i),o())},500)})}import{useEffect as Pn,useMemo as wn}from"react";import{useStore as li}from"zustand";function Tn(e){let t=wn(()=>Rn(e),[e]),n=In(t.services.access?.id),o=wn(()=>Cn(t.services.probe,n),[t.services.probe]),s=li(o);return Pn(()=>{s.status==="unknown"&&!n&&s.probe()},[t.services.probe,s.status]),Pn(()=>{n&&(s.setToken(n),s.probe())},[n]),[e,s,t.hasAuth]}import{jsx as Ue}from"react/jsx-runtime";var ve=Ct(null),di=Ct(null);di.displayName="CurrentAuth";var mi=Ct(null);mi.displayName="AuthActions";function kn({children:e}){let t=ci(()=>bn(),[]);return Ue(ve.Provider,{value:t,children:e})}function En(){return!!Mn(ve)}function Ne(){let e=Mn(ve);if(!e)throw new Error("useAuthActions must be used within a AuthProvider");return e}function pi(){let e=Ne();return Ve(e,n=>({login:n.login,logout:n.logout,nextAuth:n.nextAuth,previousAuth:n.previousAuth,setAuth:n.setAuth,addService:n.addService,removeService:n.removeService}))}function Rc(){let e=Ne();return Ve(e,t=>t)}function fi(e){let t=Ne();return Ve(t,o=>o.authItems.find(s=>s.service.id===e))}function In(e){let t=Ne();return Ve(t,o=>o.authItems.find(s=>s.id===e)?.session?.token)}function Ac(e){let t=Ne();return Ve(t,o=>{let s=o.authItems.find(i=>i.service.id===e);return!s||!s.isLoggedIn||!s.session?null:s.session?.token||null})}function gi(e){let t=pi(),n=fi(e.service.id);return ui(()=>(t?.addService(e.service,e.probeId),()=>{t?.removeService(e.service,e.probeId)}),[e.service]),n?(n.error||!n.isLoggedIn,e.children):null}function bt(){return null}function Vn(e){let[t,n,o]=Tn(e.resource),s=e.fallbackComponent||bt,i=e.loadingComponent||bt,r=e.errorComponent||bt,a=n.service,l=null;if(!o||!a)return e.children(t);let u=a.service.filter(p=>p.type==="AuthAccessService2");n.status==="error"&&(l=Ue(r,{resource:e.resource,error:n.error||"",heading:n.errorHeading,note:n.errorNote,extra:e.extra})),(n.status==="unknown"||n.status==="probing")&&(l=Ue(i,{})),n.status==="success"&&(l=e.children(t));for(let p of u)l=Ue(gi,{service:p,probeId:a.id,children:l},p.id);return l}import{createContext as Si,useContext as Nc,useMemo as xi}from"react";import{createStore as hi}from"zustand/vanilla";var yi=e=>e.id||e["@id"];function vi(e){return(Array.isArray(e.service)?e.service:[e.service]).find(n=>n.profile==="http://iiif.io/api/search/0/autocomplete"||n.profile==="http://iiif.io/api/search/1/autocomplete"||n.profile==="AutoCompleteService1")}var Nn=e=>{let t;typeof e=="string"?t={"@context":"http://iiif.io/api/search/1/context.json",profile:"http://iiif.io/api/search/1/search","@id":e,id:e,service:[]}:t=e;let n=t?yi(t):void 0,o=null;return hi((s,i)=>({service:t,resources:[],lastQuery:{},loading:!1,error:!1,highlight:null,hasSearch:!!t,hasAutocomplete:t?!!vi(t):!1,errorMessage:"",search(r,a={}){if(!n)throw new Error("No search service found.");o&&!o.signal.aborted&&o.abort(),o=new AbortController;let l=new URLSearchParams;r.q&&l.set("q",r.q),r.motivation&&l.set("motivation",r.motivation),r.date&&l.set("date",r.date),r.user&&l.set("user",r.user),s({loading:!0}),fetch(`${n}?${l.toString()}`,{signal:o.signal,headers:{"Content-Type":"application/json",Accept:"application/json",...a.headers||{}}}).then(async u=>{if(!o?.signal.aborted)if(u.ok){let p=await u.json();s({resources:p.resources,error:!1,errorMessage:""})}else s({resources:[],error:!0,errorMessage:u.statusText})})},clearSearch(){s({resources:[],error:!1,errorMessage:""})},highlightResult(r){let a=i().resources.find(l=>l["@id"]===r);s({highlight:a})},nextResult(){let r=i().resources,a=i().highlight;if(!a){s({highlight:r[0]||null});return}let l=r.findIndex(u=>u["@id"]===a["@id"]);if(l===-1){s({highlight:r[0]||null});return}s({highlight:r[l+1]||r[0]||null})},previousResult(){let r=i().resources,a=i().highlight;if(!a){s({highlight:r[r.length-1]||null});return}let l=r.findIndex(u=>u["@id"]===a["@id"]);if(l===-1){s({highlight:r[r.length-1]||null});return}if(l===0){s({highlight:r[r.length-1]||null});return}s({highlight:r[l-1]||r[r.length-1]||null})}}))};import{useStore as Hc}from"zustand";function Ln(){let e=B();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}import{jsx as Rt}from"react/jsx-runtime";var Se=Si(null);Se.displayName="Search";function zn(e){let t=Ln();return e.store?Rt(Se.Provider,{value:e.store,children:e.children}):Rt(bi,{service:t,children:e.children})}function bi({service:e,children:t}){let n=xi(()=>Nn(e),[e]);return Rt(Se.Provider,{value:n,children:t})}import{jsx as $}from"react/jsx-runtime";var Le=()=>{},ze=Ri({setCurrentCanvasId:Le,setCurrentCanvasIndex:Le,nextCanvas:Le,previousCanvas:Le,items:[],sequence:[],setSequenceIndex:Le,currentSequenceIndex:0,hasNext:!1,hasPrevious:!1});function Pi(e){let t=B(),{cursor:n,visibleItems:o,next:s,sequence:i,items:r,setCanvasIndex:a,setCanvasId:l,previous:u,setSequenceIndex:p,hasNext:c,hasPrevious:d}=vn({startCanvas:e.startCanvas,disablePaging:e.pagingEnabled===!1}),m=Ai(()=>({sequence:i,items:r,setCurrentCanvasId:l,nextCanvas:s,previousCanvas:u,totalCanvases:r.length,setCurrentCanvasIndex:a,setSequenceIndex:p,currentSequenceIndex:n,hasNext:c,hasPrevious:d}),[i,r,l,s,u,r,a,p,n]);return t?o.length===0?null:$(ze.Provider,{value:m,children:$(he.Provider,{value:o,children:$(te,{canvas:o[0],children:e.children})})}):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),$("div",{children:"Sorry, something went wrong."}))}function On(e){let t=ye(e.vault),n=pn(e.manifest);if(!n)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),$("div",{children:"Sorry, something went wrong."});if(n.error)return $("div",{children:n.error.toString()});if(!n.isLoaded)return $("div",{children:"Loading..."});let o=$(Pi,{...e,children:e.children});return $(ge,{vault:t,children:$(fn,{manifest:n.id,children:$(kn,{children:$(zn,{children:e.rangeId?$(gn,{range:e.rangeId,children:o}):o})})})})}function _e(){return Ci(ze)}import{ModeContext as zi}from"@atlas-viewer/atlas";import{createContext as Oi,useContext as Wn,useEffect as Bi,useMemo as Hi}from"react";import{useStore as Di}from"zustand";import wi from"mitt";import{createContext as Ti,useContext as Bn,useEffect as Ii}from"react";import{jsx as ki}from"react/jsx-runtime";var Mi=wi(),At=Ti(Mi);function md({children:e,emitter:t}){return ki(At.Provider,{value:t,children:e})}function Hn(){return Bn(At)}function Dn(e,t,n=[]){let o=Bn(At);Ii(()=>{let s=i=>{t(i)};return o.on(e,s),()=>{o.off(e,s)}},[o,e,...n])}import{createHelper as Vi}from"polygon-editor";import{createStore as Ni}from"zustand/vanilla";function Pt(e){let t=Math.max(...e.map(i=>i[0])),n=Math.min(...e.map(i=>i[0])),o=Math.max(...e.map(i=>i[1])),s=Math.min(...e.map(i=>i[1]));for(let i of e)if(i[0]!==n&&i[0]!==t&&i[1]!==s&&i[1]!==o||i[0]<n||i[0]>t||i[1]<s||i[1]>o)return!1;return!0}function xe(e){if(!e)return null;if(e.points.length>2){let t=Math.min(...e.points.map(i=>i[0])),n=Math.min(...e.points.map(i=>i[1])),o=Math.max(0,...e.points.map(i=>i[0])),s=Math.max(0,...e.points.map(i=>i[1]));return{x:t,y:n,width:o-t,height:s-n}}return null}function Ei(e){return e.type==="SvgSelector"}function yd(e){return e.type==="BoxSelector"}function wt(e,t){if(Ei(e)){let r=e.svgShape==="polyline";if(!e.points||e.points.length===0)return null;if(t){let{width:a,height:l}=t;return{type:"SvgSelector",value:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${a} ${l}" width="${a}" height="${l}"><${r?"polygon":"polyline"} points="${e.points.map(p=>p.join(",")).join(" ")}" /></svg>`}}return{type:"SvgSelector",value:`<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'><g><path d='M${e.points.map(a=>a.join(",")).join(" ")}${r?" Z":""}' /></g></svg>`}}if(!e.spatial)return null;let{x:n,y:o,width:s,height:i}=e.spatial||{};return!s||!i?null:{type:"FragmentSelector",value:`xywh=${~~n},${~~o},${~~s},${~~i}`}}function Tt(e,t){if(!e||!e.points.length)return null;if(Pt(e.points)){let n=e.points.map(l=>l[0]),o=e.points.map(l=>l[1]),s=Math.min(...n),i=Math.min(...o),r=Math.max(...n)-s,a=Math.max(...o)-i;return wt({type:"BoxSelector",spatial:{x:s,y:i,width:r,height:a}},t)}return wt({type:"SvgSelector",points:e.points,svgShape:e.open?"polygon":"polyline"},t)}function qn(e){if(e.type==="polygon"&&!e.noBox&&e.points&&Pt(e.points)){let n=xe({open:!1,points:e.points||[]});return qn({...e,type:"box",selector:n})}if(e.type==="polygon"||e.type==="draw")return{polygon:{points:e.points||[],open:e.open||!1},requestType:e.type,boundingBox:xe({points:e.points||[],open:!1}),metadata:{},arguments:e.arguments||{},target:Tt({points:e.points||[],open:!1},e.bounds)};let t=e.selector;if(t){let n=[[t.x,t.y],[t.x+t.width,t.y],[t.x+t.width,t.y+t.height],[t.x,t.y+t.height]];return{polygon:{points:n,open:!1},requestType:e.type,boundingBox:t,metadata:{},target:Tt({points:n,open:!1},e.bounds),arguments:e.arguments||{}}}return{polygon:{points:[],open:!1},requestType:e.type,boundingBox:null,target:null,metadata:{},arguments:e.arguments||{}}}var Li={shapeId:null,noShape:!0,transitioning:!1,actionIntentType:null,transitionIntentType:null,selectedPoints:[],hasClosestLine:!1,lastCreationTool:null,modifiers:{Alt:!1,Shift:!1,Meta:!1,proximity:0},bounds:null,showBoundingBox:!1,currentModifiers:{},validIntentKeys:{},pointerInsideShape:!1,closestPoint:null,transitionModifiers:null,selectedStamp:null,bezierLines:[],boxMode:!1,fixedAspectRatio:!1,cursor:"",enabledTools:["pointer","pen","box","lineBox","stamp","hand","line","pencil"],canDelete:!0,canDeselect:!0,isToolSwitchingLocked:!1,currentTool:"box",snapEnabled:!1,snapToPoints:!1,snapToLines:!1,snapToIntersections:!1,snapToGrid:!1,snapToParallel:!1};function Fn({events:e,enabledTools:t,keyboardShortcutMapping:n,keyboardShortcutsEnabled:o=!1,debug:s}){let i=Ni((a,l)=>{let u=null,c=Vi({emitter:e,keyboardShortcutsEnabled:o,keyboardShortcutMapping:n,enabledTools:t,customSetState:d=>{s&&console.log("partial state",d),a(m=>({polygonState:{...m.polygonState,...d}}))}},d=>{a(m=>m.tool.requestId?{polygon:{...d,id:m.tool.requestId}}:{polygon:{id:void 0,points:[],open:!0}}),e.emit("atlas.polygon-update",d)});return{mode:"explore",tool:{enabled:!1,requestId:null,canvasId:null},runtime:null,requestType:null,requests:{},history:c.history,polygon:null,validRequestIds:[],metadata:{},stableViewport:null,canvasRelativePositions:{},canvasViewports:{},polygons:c,polygonState:Li,setMetadata:(d,m)=>{let y=m||l().tool.requestId;y&&a(g=>({metadata:{...g.metadata,[y]:{...g.metadata[y]||{},...d}}}))},setToolCanvasId:d=>{a(m=>({tool:{...m.tool,canvasId:d}}))},switchTool:{pointer(){a({mode:"sketch"}),r.tools.setTool("pointer")},hand(){a({mode:"explore"}),r.tools.setTool("hand")},draw(){a({mode:"sketch"}),r.tools.setTool("pencil")},pen(){a({mode:"sketch"}),r.tools.setTool("pen")},line(){a({mode:"sketch"}),r.tools.setTool("line")},lineBox(){a({mode:"sketch"}),r.tools.setTool("lineBox")},box(){a({mode:"sketch"}),r.tools.setTool("box")},triangle(){a({mode:"sketch"}),r.tools.setTool("stamp"),r.stamps.triangle()},hexagon(){a({mode:"sketch"}),r.tools.setTool("stamp"),r.stamps.hexagon()},circle(){a({mode:"sketch"}),r.tools.setTool("stamp"),r.stamps.circle()},remove(){let d=l();d.tool.requestId&&(c.setShape({points:[],open:!0}),d.cancelRequest(d.tool.requestId))}},reset:()=>{let d=l();d.tool.requestId&&d.cancelRequest(d.tool.requestId)},setPolygonState:d=>a({polygonState:typeof d=="function"?d(l().polygonState):d}),getRequestId:()=>{let d=Math.random().toString(36).slice(2);return a(m=>({validRequestIds:[...m.validRequestIds,d]})),{requestId:d,clear:()=>{l().tool.requestId,a(m=>({tool:m.tool.requestId===d?{enabled:!1,requestId:null,canvasId:null}:m.tool,validRequestIds:m.validRequestIds.filter(y=>y!==d)}))}}},cancelRequest:d=>{let m=d||l().tool.requestId;m&&(a(y=>({mode:"explore",tool:y.tool.requestId===m?{enabled:!1,requestId:null,canvasId:null}:y.tool,validRequestIds:y.validRequestIds.filter(g=>g!==m)})),e.emit("atlas.request-cancelled",{id:m}))},requestAnnotation:async(d,m)=>{let g={...l().requests,[m.requestId]:d},S=qn(d);s&&console.log("requestAnnotation",{response:S,request:d});try{let{points:v=[],open:f=!0}=S.polygon||{},{requestId:h,canvasId:b=null,toolId:x}=m,C=x,R=l(),A=R.validRequestIds.includes(h),L=S.requestType;return s&&console.log("setting points",{requestType:L,points:v,open:f}),!A||R.tool.enabled?null:(c.setShape({id:h,points:v,open:f}),L==="polygon"&&(C=C||"pen",c.tools.setTool("pen")),L==="draw"&&(C=C||"draw",c.tools.setTool("pencil")),L==="box"&&(C=C||"box",c.tools.setTool("box")),L==="target"?(C=C||"box",c.tools.setTool("box"),c.lockAspectRatio(),c.tools.lockToolSwitching(),c.tools.setCanDeselect(!1),c.tools.setCanDelete(!1)):(c.tools.unlockToolSwitching(),c.tools.setCanDeselect(!0),c.tools.setCanDelete(!0)),d.bounds&&c.setBounds(d.bounds),e.emit("atlas.annotation-request",{id:h}),a({polygon:{id:h,points:v,open:f},mode:"sketch",requestType:L,tool:{enabled:!0,requestId:h,canvasId:b},requests:g}),C?R.switchTool[C]?.():v.length===0&&R.switchTool.box(),(typeof d.selectByDefault>"u"&&v.length&&L==="box"||d.selectByDefault)&&R.switchTool.pointer(),new Promise(Q=>{let T=w=>{w.id===h&&(a(I=>({mode:"explore",tool:{requestId:null,enabled:!1,canvasId:null},requests:Object.fromEntries(Object.entries(I.requests).filter(([E])=>E!==h))})),e.off("atlas.request-cancelled",T),e.off("atlas.annotation-completed",z),Q(null))},z=w=>{w.id===h&&(a(I=>({mode:"explore",tool:{requestId:null,enabled:!1,canvasId:null},requests:Object.fromEntries(Object.entries(I.requests).filter(([E])=>E!==h))})),e.off("atlas.annotation-completed",z),e.off("atlas.request-cancelled",T),Q(w))};e.on("atlas.request-cancelled",T),e.on("atlas.annotation-completed",z)}))}catch(v){return console.error(v),null}},completeRequest:d=>{let m=l().tool.requestId;if(typeof d=="string"&&d&&d!==m)return;let y=m?l().requests[m]?.arguments||{}:{},g=m?l().metadata[m]||{}:{},S=l().polygonState.bounds,v=l().polygon;v&&(e.emit("atlas.annotation-completed",{id:v.id,polygon:v,requestType:l().requestType,target:Tt(v,S),canvasId:l().tool.canvasId,boundingBox:xe(v),metadata:g,arguments:{...y}}),c.setShape(null))},setAtlasRuntime:d=>{u=d,e.emit("atlas.ready",{runtime:d}),r.setScale(1/u._lastGoodScale),u.world.addLayoutSubscriber((m,y)=>{(m==="event-activation"||m==="zoom-to"||m==="go-home")&&u?._lastGoodScale&&!Number.isNaN(u._lastGoodScale)&&r.setScale(1/u._lastGoodScale)}),a({runtime:u})},clearAtlasRuntime:()=>{u=null,a({stableViewport:null,runtime:null})},setCanvasRelativePosition:(d,m)=>{a(y=>({canvasRelativePositions:{...y.canvasRelativePositions,[d]:m}}))},clearCanvasRelativePosition:d=>{a(m=>{let y={...m.canvasRelativePositions};return delete y[d],{canvasRelativePositions:y}})},changeMode:d=>{a({mode:d})},nudgeLeft:d=>{if(!u)return;let m=u.getViewport(),y=d??m.width*.1;u.world.gotoRegion({x:m.x-y,y:m.y,width:m.width,height:m.height,nudge:!0})},nudgeRight:d=>{if(!u)return;let m=u.getViewport(),y=d??m.width*.1;u.world.gotoRegion({x:m.x+y,y:m.y,width:m.width,height:m.height,nudge:!0})},nudgeUp:d=>{if(!u)return;let m=u.getViewport(),y=d??m.height*.1;u.world.gotoRegion({x:m.x,y:m.y-y,width:m.width,height:m.height,nudge:!0})},nudgeDown:d=>{if(!u)return;let m=u.getViewport(),y=d??m.height*.1;u.world.gotoRegion({x:m.x,y:m.y+y,width:m.width,height:m.height,nudge:!0})},zoomIn:()=>{u?.world?.zoomIn()},zoomOut:()=>{u?.world?.zoomOut()},goHome:()=>{u?.world?.goHome()},goToRegion:d=>{u?.world?.gotoRegion(d)},getRuntime:()=>u}}),r=i.getState().polygons;return e.on("atlas.annotation-request",()=>{r.clock.start((a,l,u)=>{e.emit("atlas.polygon-render",{state:a,slowState:l,dt:u})},a=>{typeof a=="object"?i.setState({polygonState:a}):i.setState(l=>({polygonState:a(l.polygonState)}))})}),e.on("atlas.annotation-completed",()=>{r.clock.stop()}),e.on("atlas.request-cancelled",()=>{r.clock.stop()}),i}import{jsx as $n}from"react/jsx-runtime";var be=Oi(null);function q(){return Wn(be)}var It={};function Un(e="atlas"){return It[e]?.getState()}function Oe({children:e,name:t="atlas",existing:n,atlasStoreConfig:o}){let s=Hn(),i=Wn(be),r=Hi(()=>n||i||Fn({events:s,...o||{}}),[s,n,i]),a=Di(r,l=>l.mode);return Bi(()=>{let l=t;return l&&(It[l]=r),()=>{l&&delete It[l]}},[r,t]),$n(be.Provider,{value:r,children:$n(zi.Provider,{value:a||"explore",children:e})})}import{mergeStyles as Ye}from"@atlas-viewer/atlas";import{useMemo as ra}from"react";import{createContext as qi,useContext as Fi,useMemo as $i}from"react";import{jsx as Wi}from"react/jsx-runtime";function _n(){return{default:{backgroundColor:"rgba(0,0,0,0)",borderWidth:"2px",borderColor:"rgba(252,0,98, .5)"},highlighted:{backgroundColor:"rgba(75, 103, 225, 0.4)",borderWidth:"1px",borderColor:"rgba(75,103,225,0.99)"},hidden:{borderWidth:"0px",borderColor:"rgba(0,0,0,0)",backgroundColor:"rgba(0,0,0,0)",hidden:!0}}}var Mt=qi(_n());Mt.displayName="AnnotationStyle";function jn(){return Fi(Mt)}function Ld({theme:e,children:t}){let n=$i(()=>e||_n(),[e]);return Wi(Mt.Provider,{value:n,children:t})}import{expandTarget as Gi}from"@iiif/helpers/annotation-targets";import{useMemo as Qi}from"react";import{useEffect as Ui,useMemo as _i,useState as ji}from"react";import{create as Ki}from"zustand";var Yi=Ki()((e,t)=>{let n=new Map,o=()=>Math.random().toString(36).substring(2,15),s=i=>{let r=n.get(i);if(r)return r;let a=o();return n.set(i,a),a};return{stylesheets:{},loading:[],errors:[],async parseStylesheet(i){let{loadStylesheet:r,setStylesheet:a}=t();if(!i)return null;if(typeof i=="string")return i.startsWith("http")?{id:i,type:"CssStylesheet",value:await r(i)}:{id:a(i),type:"CssStylesheet",value:i};if(i.type==="CssStylesheet"){let l=i.id;if("value"in i){let u=Array.isArray(i.value)?i.value.join(`
2
- `):i.value;if(u)return{id:a(u,l),type:"CssStylesheet",value:u}}if("id"in i&&i.id){let u=await r(i.id);return{id:i.id,type:"CssStylesheet",value:u}}}return null},async loadStylesheet(i){if(t().loading.includes(i))return"";try{let a=await fetch(i);if(!a.ok)throw new Error(`Failed to load stylesheet from ${i}`);let l=await a.text();return e(u=>({stylesheets:{...u.stylesheets,[i]:l}})),l}catch(a){return e(l=>({errors:[...l.errors,{url:i,error:a}]})),""}},setStylesheet(i,r){let a=r||s(i);return e(l=>({stylesheets:{...l.stylesheets,[a]:i}})),a}}});function Kn(e){let[t,n]=ji(""),{loading:o,errors:s,stylesheets:i,parseStylesheet:r}=Yi();return Ui(()=>{e&&r(e).then(l=>{l?.id&&n(l.id)})},[e,r]),[_i(()=>{let l={};return t&&i[t]&&(l[t]=i[t]),l},[t,i]),{id:t,stylesheets:i,loading:o,errors:s}]}function je(e={},t=[]){let{id:n,selector:o}=e,s=_(),i=M(),r=n||s.annotation,a=k(p=>r?p.iiif.entities.Annotation[r]:void 0,[r]),[l]=Kn(a?.stylesheet),u=k(p=>a&&a.body?a.body.map(c=>c?c.type==="SpecificResource"?{...c,source:i.get(c)}:c?p.iiif.entities[c.type][c.id]:null:null).filter(Boolean):[],[a]);return Qi(()=>{if(!a)return;let p={...a,body:u,target:Gi(a.target,{typeMap:i.getState().iiif.mapping,loadedStylesheets:l})};return o?o(p):p},[a,o,u,l,...t])}import{useMemo as Xi}from"react";function P(e={},t=[]){let{id:n,selector:o}=e,s=_(),i=n||s.canvas,r=k(a=>i?a.iiif.entities.Canvas[i]:void 0,[i]);return Xi(()=>{if(r)return o?o(r):r},[r,o,...t])}import{useMemo as Yn}from"react";import{createEventsHelper as Zi}from"@iiif/helpers/events";function Ke(e,t){let n=M(),o=Yn(()=>Zi(n),[n]),s=k(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return Yn(()=>e?o.getListenersAsProps(e,t):{},[s,e,n,t])}import{useMemo as Ji}from"react";import{createStylesHelper as ea}from"@iiif/helpers/styles";function Ce(e,t){let n=M(),o=Ji(()=>ea(n),[n]);return k(()=>{if(!e)return null;let s=o.getAppliedStyles(e.id);return s?t?s[t]:s:void 0},[e,t])}import{useCallback as oa}from"react";import{HTMLPortal as ta,useResizeWorldItem as na}from"@atlas-viewer/atlas";import{useMemo as ne}from"react";import{Fragment as kt,jsx as K,jsxs as Et}from"react/jsx-runtime";function Gn({handleSize:e,resizable:t,onSave:n,children:o,maintainAspectRatio:s,disableCardinalControls:i,aspectRatio:r,...a}){let l=typeof e>"u"?s?12:8:e,{portalRef:u,mode:p,mouseEvent:c,isEditing:d}=na({x:a.x||0,y:a.y||0,width:a.width,height:a.height,aspectRatio:r,maintainAspectRatio:s},n),m=ne(()=>c("translate"),[c]),y=ne(()=>c("east"),[c]),g=ne(()=>c("west"),[c]),S=ne(()=>c("south"),[c]),v=ne(()=>c("north"),[c]),f=ne(()=>c("south-east"),[c]),h=ne(()=>c("south-west"),[c]),b=ne(()=>c("north-east"),[c]),x=ne(()=>c("north-west"),[c]),C=p==="sketch",R={zIndex:999,boxShadow:"0px 2px 3px 0 rgba(0,0,0,0.2)",outline:"2px solid rgba(155,155,155,.7)",borderRadius:s||i?"50%":2,position:"absolute",background:"#fff",pointerEvents:d?"none":C?"initial":"none"};return K(kt,{children:Et("world-object",{...a,children:[o,C&&t?K(ta,{ref:u,target:{x:0,y:0,height:a.height,width:a.width},relative:!0,interactive:!1,children:C&&t?Et(kt,{children:[K("div",{onMouseDown:m,onTouchStart:m,style:{display:"block",width:"100%",height:"100%",cursor:"move",border:"1px solid rgba(255,255,255, .7)",outline:"2px solid rgba(155,155,155, .7)",boxSizing:"border-box",pointerEvents:d?"none":C?"initial":"none"}}),s?null:Et(kt,{children:[K("div",{title:"east",onTouchStart:y,onMouseDown:y,style:{...R,cursor:"e-resize",height:l*2,width:l,right:0,top:"50%",opacity:i?0:1,transform:`translate(${l/2}px, -${l}px)`}}),K("div",{title:"west",onMouseDown:g,style:{...R,cursor:"w-resize",position:"absolute",height:l*2,width:l,left:0,top:"50%",opacity:i?0:1,transform:`translate(-${l/2}px, -${l}px)`}}),K("div",{title:"north",onMouseDown:v,style:{...R,cursor:"n-resize",position:"absolute",height:l,width:l*2,left:"50%",top:0,opacity:i?0:1,transform:`translate(-${l}px, -${l/2}px)`}}),K("div",{title:"south",onMouseDown:S,style:{...R,cursor:"s-resize",position:"absolute",height:l,width:l*2,left:"50%",bottom:0,opacity:i?0:1,transform:`translate(-${l}px, ${l/2}px)`}})]}),K("div",{title:"north-east",onMouseDown:b,style:{...R,cursor:"ne-resize",position:"absolute",height:l,width:l,right:0,top:0,transform:`translate(${l/2}px, -${l/2}px)`}}),K("div",{title:"south-east",onMouseDown:f,style:{...R,cursor:"se-resize",position:"absolute",height:l,width:l,bottom:0,right:0,transform:`translate(${l/2}px, ${l/2}px)`}}),K("div",{title:"south-west",onMouseDown:h,style:{...R,cursor:"sw-resize",position:"absolute",height:l,width:l,bottom:0,left:0,transform:`translate(-${l/2}px, ${l/2}px)`}}),K("div",{title:"north-west",onMouseDown:x,style:{...R,cursor:"nw-resize",position:"absolute",height:l,width:l,top:0,left:0,transform:`translate(-${l/2}px, -${l/2}px)`}})]}):null}):null]})})}import{jsx as Qn}from"react/jsx-runtime";function Xn({id:e,interactive:t,region:n,onClick:o,onHover:s,onSave:i,aspectRatio:r,maintainAspectRatio:a,disableCardinalControls:l,isEditing:u,style:p={backgroundColor:"rgba(0,0,0,.5)"}}){let c=oa(d=>{u&&i?.({id:n.id,x:n.x,y:n.y,height:n.height,width:n.width,...d})},[i,u,n.id,n.x,n.y,n.height,n.width]);return Qn(Gn,{id:e,x:n.x,y:n.y,width:n.width,aspectRatio:r,height:n.height,resizable:u,onSave:c,maintainAspectRatio:a,disableCardinalControls:l,children:Qn("box",{interactive:t,onClick:d=>{d.preventDefault(),d.stopPropagation(),o?.(n)},relativeStyle:!0,onMouseEnter:()=>{s?.(n)},target:{x:0,y:0,width:n.width,height:n.height},style:p})})}import{jsx as ia}from"react/jsx-runtime";var Re=({id:e,style:t,className:n,interactive:o,targetId:s,ignoreTargetId:i})=>{let r=je({id:e}),a=Ce(r,"atlas"),l=Ce(r,"html"),u=Ke(r,["atlas"]),p=P(),c=jn(),d=ra(()=>Ye(Ye(Ye(Ye(t,a),r?.motivation?.includes("highlighting")?c.highlighted:c.default),r?.target?.selector?.boxStyle||{})),[t,a,c,r?.motivation,r?.target]),m=s||p?.id;return p&&r&&r.target&&r.target.selector&&(r.target.selector.type==="BoxSelector"||r.target.selector.type==="SvgSelector")&&r.target.source&&(i?!0:r.target.source.id===m||r.target.source===m)?ia(Xn,{id:r.id,isEditing:!0,region:r.target.selector.spatial,style:d,className:l?.className||n,interactive:!!(l?.href||o),href:l?.href||null,title:l?.title||null,hrefTarget:l?.target||null,onClick:()=>{},...u}):null};import{Fragment as sa}from"react";import{useMemo as aa}from"react";function Zn(e={},t=[]){let{id:n,selector:o}=e,s=_(),i=n||s.annotationPage,r=k(a=>i?a.iiif.entities.AnnotationPage[i]:void 0,[i]);return aa(()=>{if(r)return o?o(r):r},[r,...t])}import{jsx as Jn}from"react/jsx-runtime";var ue=({className:e,page:t,targetId:n,ignoreTargetId:o})=>{let s=Zn({id:t.id})||t,i=Ce(s,"atlas"),r=Ce(s,"html");return k(a=>s.id?a.iiif.entities.AnnotationPage[s.id]:null,[]),Jn(sa,{children:s.items?.map(a=>Jn(Re,{id:a.id,style:i,className:r?.className||e,targetId:n,ignoreTargetId:o},a.id))})};import{createContext as Nt,useContext as Lt}from"react";import{jsx as Vt}from"react/jsx-runtime";var eo=Nt(null),to=Nt(null),no=Nt(null);function Hm(){let e=Lt(eo);if(!e)throw new Error("Ctx not found");return e}function Dm(){let e=Lt(to);if(!e)throw new Error("Ctx not found");return e}function qm(){let e=Lt(no);if(!e)throw new Error("Ctx not found");return e}function Ge({actions:e,state:t,children:n,currentTime:o,progress:s,element:i}){return Vt(no.Provider,{value:{currentTime:o,progress:s,element:i},children:Vt(to.Provider,{value:e,children:Vt(eo.Provider,{value:t,children:n})})})}import{useMemo as la}from"react";import{expandTarget as ua}from"@iiif/helpers";function Qe(){let e=B(),t=P();return la(()=>{if(!e||!t||!e.start)return null;let n=ua(e.start);return!n||n.source.id!==t.id||!n||!n.selector||n.selector.type!=="TemporalSelector"?null:n.selector.temporal},[e,t])}import{useCallback as X,useEffect as zt,useReducer as ca,useRef as Xe}from"react";function oo(e){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:e}}function da(e,t){switch(t.type){case"RESET":return t.state;case"FINISHED":return{...e,isFinished:!0,isPlaying:!1,playRequested:!1};case"PLAY_PAUSE":return{...e,isFinished:!1,isPlaying:!e.isPlaying};case"PLAY_REQUESTED":return{...e,isFinished:!1,playRequested:!0};case"PAUSE":return{...e,isPlaying:!1};case"PLAY":return{...e,isFinished:!1,playRequested:!1,isPlaying:!0};case"MUTE":return{...e,isMuted:!0};case"SET_VOLUME":return{...e,volume:t.volume,isMuted:t.volume===0};case"TOGGLE_MUTE":return{...e,isMuted:!e.isMuted};case"UNMUTE":return{...e,isMuted:!1}}return e}function Ot(e){let t=Math.round(e);return`${Math.floor(t/60)}:${`${t%60}`.padStart(2,"0")}`}function Ae(e){let[t,n]=ca(da,oo(e.duration));zt(()=>{n({type:"RESET",state:oo(e.duration)})},[e.duration]);let o=Xe(null),s=Xe(null),i=Xe(null),r=Xe(!1),a=X(()=>{s.current&&o.current&&(s.current.innerHTML=Ot(o.current.currentTime),i.current&&(i.current.style.width=`${o.current.currentTime/e.duration*100}%`),r.current!==o.current.muted&&(r.current=o.current.muted,n(o.current.muted?{type:"MUTE"}:{type:"UNMUTE"})))},[e.duration]),l=X(()=>{o.current&&(n({type:"PLAY_REQUESTED"}),o.current.play().then(()=>{n({type:"PLAY"})}),a())},[a]),u=X(()=>{o.current&&(o.current.duration>0&&o.current.paused?l():p())},[a]),p=X(()=>{o.current&&(o.current.pause(),n({type:"PAUSE"}),a())},[a]),c=X(()=>{o.current&&(o.current.muted=!o.current.muted,n(o.current.muted?{type:"MUTE"}:{type:"UNMUTE"}))},[]),d=X(()=>{o.current&&(o.current.muted=!0,n({type:"MUTE"}))},[]),m=X(()=>{o.current&&(o.current.muted=!1,n({type:"UNMUTE"}))},[]),y=X(v=>{o.current&&(o.current.muted=!1,o.current.volume=v/100,n({type:"SET_VOLUME",volume:v}))},[]),g=X(v=>{o.current&&(o.current.currentTime=Math.max(0,Math.min(v*e.duration,e.duration)),a())},[]),S=X(v=>{if(o.current){let f=typeof v=="function"?v(o.current.currentTime):v;o.current.currentTime=Math.max(0,Math.min(f,e.duration)),a()}},[]);return zt(()=>{let v=setInterval(()=>{a()},350);return()=>clearInterval(v)},[a,e.duration]),zt(()=>{let v=()=>{n({type:"FINISHED"})},f=o.current;return f?.addEventListener("ended",v),()=>f?.removeEventListener("ended",v)},[]),[{element:o,currentTime:s,progress:i},t,{play:l,pause:p,playPause:u,mute:d,unmute:m,toggleMute:c,setVolume:y,setDurationPercent:g,setTime:S}]}import{createContext as ro,useContext as ma,useEffect as pa}from"react";var Bt=ro(()=>{}),Ht=ro(()=>{});function D(e,t,n,o,s=[]){let i=ma(e==="portal"?Ht:Bt);pa(()=>(e!=="none"&&i(t,n,o),()=>{i(t,null)}),[t,e,i,...s])}import{jsx as fa,jsxs as ga}from"react/jsx-runtime";function Dt({media:e,startTime:t,children:n}){let[{element:o,currentTime:s,progress:i},r,a]=Ae({duration:e.duration}),l=t?`${e.url}#t=${t}`:e.url;return ga(Ge,{state:r,actions:a,currentTime:s,progress:i,element:o,children:[fa("audio",{ref:o,src:l}),n]},e.url)}function Ze({media:e,mediaControlsDeps:t,audioCopmonent:n=Dt,children:o}){let s=Qe();return D("portal","audio",n,{media:e,startTime:s?s.startTime:null,children:o},[e,s,...t||[]]),null}import{createContext as ha,useContext as ya}from"react";var ce=ha(null);ce.displayName="Strategy";function V(){let e=ya(ce);if(!e)throw new Error("useStrategy must be used within a StrategyProvider");return e}import{Fragment as va,jsx as qt,jsxs as Sa}from"react/jsx-runtime";function Ft({model:e}){return Sa(va,{children:[qt("style",{children:`
3
- .model-container {
4
- position: absolute;
5
- top: 0;
6
- bottom: 0;
7
- left: 0;
8
- right: 0;
9
- background: #000;
10
- z-index: 13;
11
- display: flex;
12
- justify-content: center;
13
- pointer-events: visible;
14
- }
15
- `}),qt("div",{className:"model-container",children:qt("model-viewer",{"interaction-prompt":"none",style:{width:"100%",height:"100%"},"camera-controls":"","ar-status":"not-presenting",src:e.id})})]})}function Je({model:e,name:t}){return D("overlay",`model-${t}`,Ft,{model:e},[e]),null}import{jsx as xa}from"react/jsx-runtime";function io(){let{strategy:e}=V();return e.type!=="3d-model"?null:xa(Je,{model:e.model})}import{createContext as ba,useContext as Ca}from"react";var et=ba(null);et.displayName="Controls";function F(){let e=Ca(et);if(!e)throw new Error("useStrategy must be used within a StrategyProvider");return e}import{Fragment as Ra,jsx as tt,jsxs as Aa}from"react/jsx-runtime";function ao(){let{strategy:e}=V(),{renderViewerControls:t,viewControlsDeps:n}=F(),o=P(),s=o?.accompanyingCanvas,i=o?.placeholderCanvas;return Aa(Ra,{children:[e.type==="media"&&e.media.type==="Sound"&&s?tt(te,{canvas:s.id,children:tt(de,{renderViewerControls:t,viewControlsDeps:n})}):null,e.type==="media"&&e.media.type==="Sound"&&i&&!s?tt(te,{canvas:i.id,children:tt(de,{renderViewerControls:t,viewControlsDeps:n})}):null]})}import{createContext as Ma,useContext as ka,useMemo as Ea}from"react";import{useCallback as lo,useLayoutEffect as wa,useMemo as Ta,useRef as Ia}from"react";import{entityActions as $t}from"@iiif/helpers/vault/actions";import{useMemo as Pa}from"react";function so(){let t=M().getStore();return Pa(()=>n=>t.dispatch(n),[t])}function uo(e){return typeof e!="string"&&e&&e.bindToVault}function co(){let e=M(),t=Ia([]),n=so(),o=Ta(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);wa(()=>{let a={id:o,type:"AnnotationPage",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],rendering:[],service:[]};n($t.importEntities({entities:{AnnotationPage:{[a.id]:a}}}))},[o]);let s=k(a=>o&&a.iiif.entities.AnnotationPage[o]||null,[o]),i=lo((a,l)=>{if(o){if(uo(a)){let c=a;c.__vault||c.bindToVault(e),a=typeof c.source=="string"?c.source:c.source.id,t.current[a]=c}else typeof a!="string"&&(a=a.id);let u=e.get({id:o,type:"AnnotationPage"}),p=e.get({id:a,type:"Annotation"});u&&p&&(u.items.find(c=>c.id===p.id)||n($t.addReference({id:o,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"},index:l})))}},[o]),r=lo(a=>{o&&(uo(a)?a=typeof a.source=="string"?a.source:a.source.id:typeof a!="string"&&(a=a.id),t.current[a]&&t.current[a].beforeRemove(),e.get({id:o,type:"AnnotationPage"})&&n($t.removeReference({id:o,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"}})))},[o]);return[s,{addAnnotation:i,removeAnnotation:r}]}import{jsx as Va}from"react/jsx-runtime";var mo=Ma(null);function po(){let e=ka(mo);return[e.fullPage,{addAnnotation:e.addAnnotation,removeAnnotation:e.removeAnnotation}]}function fo({children:e}){let[t,{addAnnotation:n,removeAnnotation:o}]=co();return Va(mo.Provider,{value:Ea(()=>({fullPage:t,addAnnotation:n,removeAnnotation:o}),[t]),children:e})}import{Fragment as Na,jsx as go,jsxs as La}from"react/jsx-runtime";function ho({children:e}){let{strategy:t}=V(),[n]=po();return t.type!=="images"?null:La(Na,{children:[n?go(ue,{page:n}):null,t.annotations&&t.annotations.pages?t.annotations.pages.map(o=>go(ue,{page:o},o.id)):null,e]})}import{useEffect as qa,useMemo as Fa,useRef as $a,useState as Wa}from"react";import{useEffect as za}from"react";var yo=(e,t=[])=>{let n=M();za(()=>{e(n)},[n,...t])};import Oa,{useContext as Ba}from"react";import{ImageServiceLoader as Ha}from"@iiif/helpers/image-service";var Da=Oa.createContext(new Ha);function vo(){return Ba(Da)}import{createThumbnailHelper as Ua}from"@iiif/helpers/thumbnail";function Pe(e,t,{canvasId:n,manifestId:o}={}){let s=M(),i=vo(),r=Fa(()=>Ua(s,{imageServiceLoader:i}),[s,i]),[a,l]=Wa(),u=B(o?{id:o}:void 0),p=P(n?{id:n}:void 0),c=p||u,d=$a(!1);if(qa(()=>(d.current=!1,()=>{d.current=!0}),[]),!c)throw new Error("Must be called under a manifest or canvas context.");return yo(m=>{r.getBestThumbnailAtSize(c,e,t).then(y=>{y.best&&!d.current&&l(y.best)})},[c]),a}import{jsx as So}from"react/jsx-runtime";function we({x:e=0,y:t=0}){let n=P(),o=Pe({maxWidth:256,maxHeight:256});return!n||!o||o.type!=="fixed"?null:So("world-object",{height:n.height,width:n.width,x:e,y:t,children:So("world-image",{uri:o.id,target:{x:0,y:0,width:n.width,height:n.height},display:o.width&&o.height?{width:o.width,height:o.height}:void 0,crop:void 0})})}import{jsx as _a,jsxs as ja}from"react/jsx-runtime";function xo({as:e}){let{strategy:t}=V(),{renderMediaControls:n,mediaControlsDeps:o}=F();return t.type!=="media"||t.media.type!=="Sound"?null:ja(Ze,{media:t.media,mediaControlsDeps:o,audioCopmonent:e,children:[_a(we,{}),n?n(t):null]},t.media.url)}import{HTMLPortal as Do}from"@atlas-viewer/atlas";import{useLayoutEffect as ds,useMemo as ms}from"react";import{useStore as qo}from"zustand";import{createContext as Ka,useContext as Ya}from"react";import{useStore as Ga}from"zustand";import{jsx as Qa}from"react/jsx-runtime";var Wt=Ka(null);Wt.displayName="ComplexTimeline";function bo({children:e,store:t}){return Qa(Wt.Provider,{value:t,children:e})}function yf(e){let t=Ya(Wt);if(!t)throw new Error("useComplexTimeline must be used within a ComplexTimelineProvider");return Ga(t,e)}import Xa from"mitt";import{createStore as Za}from"zustand/vanilla";function Co({currentKeyFrameIndex:e,keyframes:t,targetTime:n,currentTime:o}){if(o<=n){let s=t.findIndex(a=>a.time>n);if(s===-1)return[e,[]];let i={},r=t.slice(e,s);for(let a of r)a.type==="enter"&&(i[a.id]=a),a.type==="exit"&&(i[a.id]?delete i[a.id]:i[a.id]=a);return[s,Object.values(i)]}return[e,[]]}function Ro({complexTimeline:e,startTime:t=0}){let n=Xa(),o={},s={progress:null,currentTime:null},i=0,r=null,a=0,l=null;function u(){let f=S.getState().visibleElements,h=o,b=[],x=Object.keys(h);for(let C of x){let R=h[C],A=f[C];R&&A&&b.push(R)}return b}function p(){return Object.keys(o).map(f=>o[f])}function c(v){s.currentTime&&(s.currentTime.innerHTML=Ot(v),s.progress&&(s.progress.style.width=`${v/e.duration*100}%`))}let d=()=>{let v=S.getState(),f=v.currentPrime;if(!f)return;let h=o,b=v.visibleElements,x=Object.keys(h);for(let C of x){let R=h[C],A=b[C];if(R&&C!==f.id&&A){let L=a-A.time*1e3;Math.abs(a-A.time*1e3-R.currentTime*1e3)>300&&(R.currentTime=L/1e3)}}},m=(v=0)=>{let f=v-i,h=S.getState();if(h.isPlaying){let b=h.currentPrime;if(b){let A=o[b.id];A&&(A.paused?a+=f:a=(b.time+A.currentTime)*1e3)}else a+=f;let x=a/1e3;if(x>h.duration){S.getState().setTime(0),S.setState({isPlaying:!1}),y(),c(0);return}c(x);let[C,R]=Co({currentTime:x,currentKeyFrameIndex:h.nextKeyframeIndex,keyframes:h.complexTimeline.keyframes,targetTime:x});R.length&&h.applyKeyframes(C,R)}i=v,r=requestAnimationFrame(m)},y=()=>{r&&cancelAnimationFrame(r)},g=(v,f)=>{},S=Za((v,f)=>({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:()=>{f().clockRunning||(m(),l=setInterval(d,500)),v({clockRunning:!0,clockStartRequests:f().clockStartRequests+1})},applyKeyframes(h,b){let x=f(),C={...x.visibleElements},R=x.currentPrime;for(let A of b)A.type==="enter"&&(C[A.id]=A,n.emit("complex-timeline.enter",{id:A.id})),A.type==="exit"&&(C[A.id]=null,n.emit("complex-timeline.exit",{id:A.id})),A.isPrime&&(R=A);v({nextKeyframeIndex:h,visibleElements:C,currentPrime:R})},stopClock:()=>{let h=f().clockStartRequests;if(h!==0){if(h===1){y(),l&&clearInterval(l),v({clockRunning:!1,clockStartRequests:0});return}v({clockStartRequests:h-1})}},setElement:(h,b)=>{o[h]=b;let x=Object.keys(o),C=f().complexTimeline;g(b,h),C.items.filter(A=>A.type!=="Image"&&A.type!=="Text").every(A=>x.includes(A.annotationId))&&!f().isReady&&(n.emit("complex-timeline.ready",{complexTimeline:C}),v({isReady:!0}))},removeElement:h=>{delete o[h]},mute(){for(let h of p())h.muted=!0;v({isMuted:!0})},unmute(){for(let h of p())h.muted=!1;v({isMuted:!1})},play(){if(!f().isPlaying){for(let b of u())b.play();v({isPlaying:!0})}},pause(){if(f().isPlaying){for(let b of u())b.pause();v({isPlaying:!1})}},playPause(){let h=f();h.isPlaying?h.pause():h.play()},setDurationPercent(h){let x=f().duration*h;f().setTime(x)},setTime(h){let b=f(),x=a/1e3,C=typeof h=="function"?h(x):h,R=b.nextKeyframeIndex;if(x>C){v({visibleElements:{},currentPrime:null});let I=Object.keys(b.visibleElements);for(let E of I)n.emit("complex-timeline.exit",{id:E});x=0,R=0}let[A,L]=Co({currentTime:x,currentKeyFrameIndex:R,keyframes:b.complexTimeline.keyframes,targetTime:C});b.applyKeyframes(A,L),a=C*1e3;let T=S.getState().visibleElements,z=o,w=Object.keys(T);for(let I of w){let E=T[I];if(E){let Ee=z[I];Ee&&(Ee.currentTime=(a-E.time*1e3)/1e3)}}c(C)},setVolume(h){for(let b of p())b.volume=Math.min(1,Math.max(0,h/100));v({volume:h})},toggleMute(){let h=f();h.isMuted?(h.unmute(),v({isMuted:!1})):(h.mute(),v({isMuted:!0}))},clearProgressElement(){s.progress=null},setProgressElement(h){s.progress=h},setCurrentTimeElement(h){s.currentTime=h},clearCurrentTimeElement(){s.currentTime=null}}));return n.on("complex-timeline.enter",v=>{let f=S.getState(),h=v.id,b=o[h];b&&f.isPlaying&&b.play()}),n.on("complex-timeline.exit",v=>{let f=S.getState(),h=v.id,b=o[h];b&&(b.currentTime=0,b.pause())}),S.getState().setTime(t),{store:S,emitter:n}}import{Fragment as Oo,useMemo as Bo}from"react";import{HTMLPortal as as}from"@atlas-viewer/atlas";import{getId as ss}from"@iiif/parser/image-3";import Ja,{useContext as es}from"react";import{imageServices as ts}from"@iiif/helpers/image-service";import{useStore as nt}from"zustand";var Ao=Ja.createContext(ts.store);Ao.displayName="ImageServicesHelper";function ot(){return es(Ao)}function Po(e){let t=ot();return nt(t,({loaded:n})=>n[e])}function rt(){let e=ot();return nt(e,({loadServiceSync:t})=>t)}function wo(){let e=ot();return nt(e,({loaded:t})=>t)}function If(){let e=ot();return nt(e,({loadService:t})=>t)}import Te,{useMemo as Ut}from"react";import{jsx as Z}from"react/jsx-runtime";var Io=Te.createContext("en"),Mo=Te.createContext({}),ko=Te.createContext(null);function Vf(e){return Z(Mo.Provider,{value:e.translations,children:e.children})}function Nf(e){return Z(Io.Provider,{value:e.language,children:e.children})}function Lf(e){return Z(ko.Provider,{value:e.convert,children:e.children})}function Eo(){return Te.useContext(ko)}function _t(){return Te.useContext(Io)}function Vo(){return Te.useContext(Mo)}function To(e){return e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):e}function ns({as:e,language:t,children:n,viewingDirection:o,...s}){let i=_t();return Ut(()=>To(i)===To(t),[i,t])?e?Z(e,{...s,children:n}):Z("span",{...s,children:n}):e?Z(e,{...s,lang:t,dir:o,children:n}):Z("span",{...s,lang:t,dir:o,children:n})}function No(e,t,n){if(t.length===0)return;if(t.length===1)return t[0];if(t.indexOf(e)!==-1)return e;let o=e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):null;if(o&&t.indexOf(o)!==-1)return o;for(let s of n)if(t.indexOf(s)!==-1)return s;return t.indexOf("none")!==-1?"none":t.indexOf("@none")!==-1?"@none":t[0]}var os=(e,t=[])=>{let n=_t();return Ut(()=>{let o=e();return No(n,o,[])},[n,...t])};function me(e,t,n,o){return t?n?n(e[t]||t,o||"none"):e[t]||t:""}function rs(e,t,n=`
16
- `,o={}){let s=Eo(),i=os(()=>Object.keys(e||{}),[e]);return[Ut(()=>{if(!e)return me(o,t,s)||"";if(typeof e=="string")return me(o,e,s);let r=i?e[i]:void 0;return r?typeof r=="string"?r:r.map(a=>me(o,a,s,i)).join(n):""},[i,t,e]),i]}function zf(){let e=_t(),t=Vo(),n=Eo();return function(s,i="",r=`
17
- `,a=t){let l=Object.keys(s||{}),u=No(e,l,[]);if(!s)return me(a,i,n)||"";if(typeof s=="string")return me(a,s,n);let p=u?s[u]:void 0;return p?typeof p=="string"?me(a,p,n,u):p.map(c=>me(a,c,n,u)).join(typeof r<"u"?r:`
18
- `):""}}function Be({as:e,defaultText:t,enableDangerouslySetInnerHTML:n,children:o,separator:s,...i}){let r=Vo(),[a,l]=rs(o,t,s,r);return l?Z(ns,{...i,as:e,language:l,title:n?void 0:a,dangerouslySetInnerHTML:n?{__html:a}:void 0,children:n?void 0:a}):e?Z(e,{...i,children:a}):Z("span",{...i,title:n?void 0:a,dangerouslySetInnerHTML:n?{__html:a}:void 0,children:n?void 0:a})}import{isImageServiceLevel as Lo}from"@iiif/parser/image-3";import{useMemo as jt}from"react";import{jsx as it,jsxs as is}from"react/jsx-runtime";var Kt=e=>{let t=e.format||"jpg",n=e.width/(e.crop?.width||e.tiles.width),o=e.tiles.imageService.sizes||[],s=e.enableThumbnail,i=e.enableSizes,r=jt(()=>{let u=e.tiles.imageService.id||e.tiles.imageService["@id"];return u?.endsWith("/info.json")?u.slice(0,-1*10):u},[e.tiles.imageService.id,e.tiles.imageService["@id"]]),a=jt(()=>{let u=e.tiles.imageService.tiles||[];if(!u.length){let p=e.width,c=[1],d=1;for(;2**d<p;)d=d*2,c.push(d);return(e.tiles.imageService.maxArea||e.tiles.imageService.maxWidth||e.tiles.imageService.maxHeight)&&Lo(2,e.tiles.imageService)?[{width:256,height:256,scaleFactors:c}]:Lo(2,e.tiles.imageService)?[{width:256,height:256,scaleFactors:c}]:[]}return u},[e.tiles.imageService,e.width]),l=jt(()=>{let u=e.tiles.imageService;return(u?u["@context"]?Array.isArray(u["@context"])?u["@context"]:[u["@context"]]:[]:[]).indexOf("http://iiif.io/api/image/3/context.json")!==-1},[e.tiles.imageService.id,e.tiles.imageService]);return it("world-object",{rotation:e.rotation,scale:n,height:e.crop?.height||e.tiles.height,width:e.crop?.width||e.tiles.width,x:e.x,y:e.y,onClick:e.onClick,children:is("composite-image",{id:e.tiles.imageService.id,width:e.crop?.width||e.tiles.width,height:e.crop?.height||e.tiles.height,crop:e.crop,renderOptions:e.renderOptions,children:[s&&e.tiles.thumbnail?it("world-image",{priority:!0,uri:e.tiles.thumbnail.id,target:{width:e.tiles.width,height:e.tiles.height},display:{width:e.tiles.thumbnail.width,height:e.tiles.thumbnail.height},crop:e.crop}):null,i&&o.map((u,p)=>it("world-image",{uri:`${r}/full/${u.width},${l?u.height:""}/0/default.${t}`,target:{width:e.tiles.width,height:e.tiles.height},display:{width:u.width,height:u.height},crop:e.crop},p)),a.map(u=>(u.scaleFactors||[]).map(p=>it("tiled-image",{uri:e.tiles.imageService.id,display:{width:e.tiles.width,height:e.tiles.height},format:t,tile:u,scaleFactor:p,crop:e.crop,version3:l},`${e.tiles.imageService.id}-tile-${p}`)))]},e.tiles.imageService.id)},e.tiles.imageService.id)};import{jsx as oe,jsxs as us}from"react/jsx-runtime";function ls({resource:e,heading:t,note:n,extra:o}){return o?oe(as,{target:{x:0,y:0,width:o.target?.spatial.width,height:o.target?.spatial.height},backgroundColor:"#333",relative:!0,children:oe("div",{style:{display:"flex",alignContent:"center",justifyContent:"center",alignItems:"center",height:"100%",width:"100%",background:"#444",color:"#BBB"},children:us("div",{children:[oe(Be,{children:t||"Not authorised"}),n&&oe("p",{children:oe(Be,{children:n})}),oe("p",{children:e.id||e["@id"]||"unknown"})]})})}):null}function zo({image:e,thumbnail:t,crop:n,enableSizes:o,enableThumbnail:s,renderOptions:i,rotation:r,manualRotation:a}){let l=En(),u=ss(e.service),p=Po(u),c=rt(),d=p?.service;c(e.service,e);let m=d&&p?.status==="done",y=(d?.preferredFormats||[])[0],g=t&&t.type==="fixed"&&t.id&&!t.id.includes("/full/full/")&&!t.id.includes("/max/")?t:void 0;if(m===!1)return null;if(!l){let S=e.service,v=S.width||e.width||0,f=S.height||e.height||0,h=0,b=0,x=e.target?.spatial.width||v,C=e.target?.spatial.height||f,R=x,A=C;return(r===90||r===270)&&!a&&([x,C]=[C,x],h=(R-x)/2,b=(A-C)/2),a&&([x,C]=[C,x]),oe(Kt,{enableThumbnail:s,renderOptions:i,rotation:r,tiles:{id:S.id||S["@id"]||"unknown",height:f,width:v,imageService:S,thumbnail:g},enableSizes:o,x:h,y:b,format:y,width:x,height:C,crop:n})}return oe(Vn,{resource:e.service,errorComponent:ls,extra:e,children:S=>{let v=S.width||e.width||0,f=S.height||e.height||0,h=0,b=0,x=e.target?.spatial.width||v,C=e.target?.spatial.height||f,R=x,A=C;return(r===90||r===270)&&!a&&([x,C]=[C,x],h=(R-x)/2,b=(A-C)/2),oe(Kt,{enableThumbnail:s,renderOptions:i,tiles:{id:S.id||S["@id"]||"unknown",height:f,width:v,imageService:S,thumbnail:g},rotation:r,format:y,enableSizes:o,x:h,y:b,width:x,height:C,crop:n})}},e.id)}import{jsx as Yt,jsxs as Gt}from"react/jsx-runtime";function Ie({id:e,image:t,thumbnail:n,isStatic:o,x:s=0,y:i=0,children:r,selector:a,onClick:l,rotation:u,enableSizes:p,enableAnnotations:c}){let d=Bo(()=>{if(!(!a||a.spatial.x===0&&a.spatial.y===0))return a.spatial},[a]),m=Bo(()=>{if(typeof t.rotation<"u")return t.rotation;if(!t.annotation)return 0;let x=Array.isArray(t.annotation.body)?t.annotation.body?.[0]:t.annotation.body;if(x&&x.selector?.type==="ImageApiSelector")return Number(x.selector.rotation)},[t]),y=!!t.service,g=s+t.target.spatial.x,S=i+t.target.spatial.y,v=t.target.spatial.width,f=t.target.spatial.height,h=t.target.spatial.width,b=t.target.spatial.height;return(m===90||m===270)&&([h,b]=[b,h],y||([v,f]=[f,v],g+=(t.target.spatial.width-v)/2,S+=(t.target.spatial.height-f)/2)),Gt("world-object",{x:g,y:S,width:v,height:f,onClick:l,rotation:t.service?void 0:typeof u<"u"?u:m,children:[t.service?Gt(Oo,{children:[Yt(zo,{image:t,thumbnail:n,crop:d,enableSizes:p,rotation:typeof u<"u"?u:m,manualRotation:typeof u<"u"}),r]},"service"):Gt(Oo,{children:[Yt("world-image",{onClick:l,uri:t.id,target:{x:0,y:0,width:h,height:b},display:h&&b?{width:h,height:b}:void 0,crop:d}),r]},"no-service"),c&&t.annotationPages?t.annotationPages.map(x=>Yt(ue,{page:x,className:"image-service-annotation",ignoreTargetId:!0},x.id)):null]},e+(y?"server":"no-service")+u)}import{HTMLPortal as cs}from"@atlas-viewer/atlas";import{Fragment as Ho,jsx as He}from"react/jsx-runtime";function at({strategy:e,onClickPaintingAnnotation:t}){return He(Ho,{children:e.items.map((n,o)=>He(Ho,{children:He(cs,{onClick:t?s=>{s.stopPropagation(),t(n.annotationId,n,s)}:void 0,target:n.target?.spatial||void 0,children:He("div",{"data-textual-content":!0,children:He(Be,{enableDangerouslySetInnerHTML:!0,children:n.text})})},o)}))})}import{Fragment as ps,jsx as pe,jsxs as fs}from"react/jsx-runtime";function Fo({strategy:e,children:t}){let{store:n}=ms(()=>Ro({complexTimeline:e}),[e]),o=qo(n,r=>r.isReady),s=qo(n,r=>r.visibleElements);function i(r){return a=>{a&&n.getState().setElement(r,a)}}return ds(()=>{if(o){let{startClock:r,stopClock:a}=n.getState();return r(),()=>{a()}}},[e,o]),D("portal","custom-controls",bo,{store:n,children:t},[o]),fs(ps,{children:[e.items.map(r=>r.type!=="Image"||!s[r.annotationId]?null:pe(Ie,{image:r,id:r.annotationId},r.id)),e.items.map((r,a)=>r.type!=="Text"||!s[r.annotationId]?null:pe(at,{strategy:{type:"textual-content",items:[r]}},a)),e.items.map((r,a)=>r.type!=="Video"||!r.target.spatial?null:pe(Do,{target:r.target.spatial,children:pe("video",{ref:i(r.annotationId),src:r.url,style:{height:"100%",width:"100%",opacity:s[r.annotationId]?1:0}})},a)),e.items.map((r,a)=>r.type!=="Sound"?null:pe(Do,{children:pe("audio",{ref:i(r.annotationId),src:r.url})},a)),e.highlights.map(({annotation:r})=>s[r.id]?pe(Re,{id:r.id,ignoreTargetId:!0,style:{outline:"3px solid red"},className:"image-service-annotation"},r.id):null)]})}import{jsx as gs}from"react/jsx-runtime";function $o(){let{strategy:e}=V(),{renderComplexTimelineControls:t}=F();return e.type!=="complex-timeline"?null:gs(Fo,{strategy:e,children:t?t(e):null})}import{jsx as hs}from"react/jsx-runtime";function st({style:e}){let t=P();return!t||!t.height||!t.width?null:hs("box",{interactive:!1,target:{x:0,y:0,width:Number(t.width),height:Number(t.height)},style:e})}import{jsx as ys}from"react/jsx-runtime";function Wo({backgroundStyle:e,alwaysShowBackground:t}){let{strategy:n}=V();return n.type!=="empty"&&!t?null:ys(st,{style:e})}import{createContext as vs,useContext as Ss}from"react";var fe=vs(null);function lt(){return Ss(fe)}import{Fragment as bs,jsx as xs,jsxs as Cs}from"react/jsx-runtime";function Uo({isStatic:e=!1,enableSizes:t=!1,enableAnnotations:n=!0,onClickPaintingAnnotation:o,rotation:s,children:i}){let{strategy:r}=V(),{renderViewerControls:a,viewControlsDeps:l}=F(),u=P(),p=lt(),c=Pe({maxWidth:256,maxHeight:256});if(D(p&&r.type==="images"&&a?"overlay":"none",`canvas-portal-controls-${u?.id}`,fe.Provider,a?{value:p||null,children:a(r)}:{},[u,p,r,...l||[]]),r.type!=="images")return null;let d=r.images.length===1?s:0;return Cs(bs,{children:[r.images.map((m,y)=>xs(Ie,{isStatic:e,image:m,id:m.id,thumbnail:y===0?c:void 0,selector:m.selector,enableSizes:t,enableAnnotations:n,rotation:d,onClick:o?g=>{o(m.annotationId,m,g)}:void 0},m.id+y)),i]})}import{Fragment as As,jsx as Rs,jsxs as Ps}from"react/jsx-runtime";function _o({onClickPaintingAnnotation:e,children:t}){let{strategy:n}=V(),{renderViewerControls:o,viewControlsDeps:s}=F(),i=lt(),r=P();return D(i&&n.type==="textual-content"&&o?"overlay":"none",`canvas-portal-controls-${r?.id}`,fe.Provider,o?{value:i||null,children:o(n)}:{},[r,i,n,...s||[]]),n.type!=="textual-content"?null:Ps(As,{children:[Rs(at,{strategy:n,onClickPaintingAnnotation:e}),t]})}import{jsx as jo,jsxs as ws}from"react/jsx-runtime";function Qt({element:e,media:t,startTime:n,playPause:o,poster:s}){let i="div",r=n?`${t.url}#t=${n}`:t.url;return ws(i,{className:"video-container",part:"video-container",onClick:o,children:[jo("style",{children:`
19
- .video-container {
20
- position: absolute;
21
- top: 0;
22
- bottom: 0;
23
- left: 0;
24
- right: 0;
25
- background: #000;
26
- z-index: 13;
27
- display: flex;
28
- justify-content: center;
29
- pointer-events: visible;
30
- }
31
- `}),jo("video",{poster:s,ref:e,src:r,style:{width:"100%",objectFit:"contain"}})]})}function ut({media:e,mediaControlsDeps:t,children:n,videoComponent:o=Qt,captions:s}){let i=P(),r=Qe(),a=i&&i.placeholderCanvas&&i.placeholderCanvas.id||void 0,l=Pe({},!1,{canvasId:a}),[{element:u,currentTime:p,progress:c},d,m]=Ae({duration:e.duration});return D("overlay","video-element",o,{element:u,media:e,playPause:m.playPause,poster:l?.id,canvas:i,startTime:r?r.startTime:null,captions:s},[l]),D("portal","custom-controls",Ge,{state:d,actions:m,currentTime:p,progress:c,element:u,children:n},[p,d,e,...t||[]]),null}import{jsx as Ts,jsxs as Is}from"react/jsx-runtime";function Ko({as:e}){let{strategy:t}=V(),{renderMediaControls:n,mediaControlsDeps:o}=F();return t.type!=="media"||t.media.type!=="Video"?null:Is(ut,{captions:t.captions,media:t.media,mediaControlsDeps:o,videoComponent:e,children:[Ts(we,{}),n?n(t):null]},t.media.url)}import{useRef as Ms}from"react";import{jsx as Yo,jsxs as Es}from"react/jsx-runtime";function ks({element:e,media:t,playPause:n}){let o=Ms(null);return t.youTubeId?Es("div",{className:"video-container",part:"video-container",onClick:n,children:[Yo("style",{children:`
32
- .video-container {
33
- position: absolute;
34
- top: 0;
35
- bottom: 0;
36
- left: 0;
37
- right: 0;
38
- background: #000;
39
- z-index: 13;
40
- display: flex;
41
- justify-content: center;
42
- pointer-events: visible;
43
- }
44
- .video-yt {
45
- border: none;
46
- width: 100%;
47
- object-fit: contain;
48
- }
49
- `}),Yo("iframe",{className:"video-yt",ref:o,src:`https://www.youtube.com/embed/${t.youTubeId}?enablejsapi=1&origin=${window.location.host}`,referrerPolicy:"no-referrer",sandbox:"allow-scripts allow-same-origin allow-presentation"})]}):null}function Go({media:e,mediaControlsDeps:t,children:n}){let[{element:o,currentTime:s,progress:i},r,a]=Ae({duration:e.duration});return D("overlay","video-element",ks,{element:o,media:e,playPause:a.playPause}),null}import{jsx as Vs,jsxs as Ns}from"react/jsx-runtime";function Qo(){let{strategy:e}=V(),{renderMediaControls:t,mediaControlsDeps:n}=F();return e.type!=="media"||e.media.type!=="VideoYouTube"?null:Ns(Go,{media:e.media,mediaControlsDeps:n,children:[Vs(we,{}),t?t(e):null]})}import{startTransition as fl,useMemo as gl}from"react";import{useStore as ee}from"zustand";import{HTMLPortal as Bs,useAtlas as Hs}from"@atlas-viewer/atlas";import{useCallback as Jt,useEffect as en}from"react";import{createSvgHelpers as Ls}from"polygon-editor";import{useEffect as zs,useRef as J,useState as Zo}from"react";import{useStore as Xt}from"zustand";function Xo(e){let t=q(),n=Xt(t,i=>i.polygons),o=Xt(t,i=>i.polygonState),s=Xt(t,i=>i.polygon);return Dn("atlas.polygon-render",({state:i,slowState:r,dt:a})=>{e(i,r,a)}),{currentShape:s,state:o,helper:n}}import{Fragment as Zt,jsx as N,jsxs as Me}from"react/jsx-runtime";var re=Ls(),Os={shapeFill:"#ffffff33",shapeStroke:"#000",lineStroke:"#000",ghostLineStroke:"#0F0",activeLineStroke:"#4D7EEA",boundingBoxDottedStroke:"#0007",boundingBoxStroke:"#fffA",controlFill:"#fff"};function Jo(e){let{image:t}=e,n={...Os,...e.theme||{}},o=J(),s=J(),i=J(),r=J(),a=J(),l=J(),u=J(),p=J(),c=J(),d=J(),[m,y]=Zo(null),[g,S]=Zo(!1),{helper:v,state:f,currentShape:h}=Xo((T,z)=>{if(T.closestLineIndex,re.updateTransitionBoundingBox(i.current,T,z),re.updateBoundingBoxPolygon(o.current,T,z),re.updateBoundingBoxPolygon(s.current,T,z),re.updateTransitionShape(u.current,T,z),re.updateClosestLinePointTransform(a.current,T,z),re.updateSelectBox(r.current,T,z),re.updatePointLine(p.current,T,z),re.updateDrawPreview(l.current,T,z,3),re.updateLineBox(c.current,T),y(T.transitionDirection),S(T.transitionRotate),T.closestLineIndex!==-1&&d.current){let w=T.polygon,I=w.points[T.closestLineIndex],E=w.points[(T.closestLineIndex+1)%w.points.length];I&&E&&d.current.setAttribute("points",`${I[0]},${I[1]} ${E[0]},${E[1]}`)}});zs(()=>{let T=()=>{v.modifiers.reset()};return document.addEventListener("mouseleave",T),()=>{document.removeEventListener("mouseleave",T)}},[]);let b=Me(Zt,{children:[Me("marker",{id:"dot",viewBox:"0 0 10 10",refX:"5",refY:"5",markerWidth:"5",markerHeight:"5",children:[N("circle",{cx:"5",cy:"5",r:"5",fill:n.lineStroke,className:"marker"}),N("circle",{cx:"5",cy:"5",r:"3",fill:n.controlFill})]}),N("marker",{id:"newdot",viewBox:"0 0 10 10",refX:"5",refY:"5",markerWidth:"5",markerHeight:"5",children:N("circle",{cx:"5",cy:"5",r:"5",fill:n.activeLineStroke,className:"marker"})}),Me("marker",{id:"selected",viewBox:"0 0 10 10",refX:"5",refY:"5",markerWidth:"5",markerHeight:"5",children:[N("circle",{cx:"5",cy:"5",r:"5",fill:n.lineStroke}),N("circle",{cx:"5",cy:"5",r:"3",fill:n.activeLineStroke})]}),Me("marker",{id:"resizer",viewBox:"0 0 10 10",refX:"5",refY:"5",markerWidth:"6",markerHeight:"6",children:[N("rect",{width:"10",height:"10",fill:n.lineStroke}),N("rect",{x:"1",y:"1",width:"8",height:"8",fill:n.controlFill})]})]}),x=h?h.open?"polyline":"polygon":null,C=!f.showBoundingBox&&f.closestPoint!==null&&f.actionIntentType==="select-point",R=f.actionIntentType==="add-open-point",A=f.transitionIntentType==="split-line",L=f.transitioning&&f.selectedStamp&&f.transitionIntentType==="stamp-shape",Q=h&&x?Me(Zt,{children:[N(x,{fill:(!f.transitioning||f.transitionIntentType==="select-multiple-points")&&!h.open?n.shapeFill:"none",strokeWidth:L||f.showBoundingBox&&f.boxMode||f.transitioning&&f.transitionIntentType==="split-line"||f.transitioning&&f.transitionIntentType==="move-point"?0:2,stroke:n.shapeStroke,points:h.points.map(T=>T.join(",")).join(" "),vectorEffect:"non-scaling-stroke",markerStart:f.showBoundingBox?void 0:f.boxMode?"url(#resizer)":"url(#dot)",markerMid:f.showBoundingBox?void 0:f.boxMode?"url(#resizer)":"url(#dot)",markerEnd:f.showBoundingBox?void 0:f.boxMode?"url(#resizer)":"url(#dot)",style:{pointerEvents:"none"},opacity:f.transitioning&&f.transitionIntentType==="move-shape"?0:1}),f.currentTool==="lineBox"&&f.actionIntentType==="close-line-box"?N("polygon",{fill:n.shapeFill,ref:c,stroke:n.lineStroke,strokeWidth:2,vectorEffect:"non-scaling-stroke"}):null,f.transitionIntentType==="draw-shape"&&f.transitioning?N("polyline",{ref:l,fill:"none",stroke:n.activeLineStroke,strokeWidth:2,vectorEffect:"non-scaling-stroke"}):null,!(f.transitioning&&f.transitionIntentType==="move-point")&&!(f.transitioning&&f.transitionIntentType==="stamp-shape")&&!f.showBoundingBox&&f.selectedPoints&&f.selectedPoints.length?N("polyline",{strokeWidth:2,vectorEffect:"non-scaling-stroke",stroke:"transparent",markerStart:"url(#selected)",markerMid:"url(#selected)",markerEnd:"url(#selected)",fill:"transparent",points:h.points.filter((T,z)=>f.selectedPoints?.includes(z)).map(T=>T.join(",")).join(" "),opacity:f.transitioning&&f.transitionIntentType==="move-shape"?0:1}):null,C&&!f.transitioning&&f.closestPoint!==null&&h.points[f.closestPoint]?N("polyline",{strokeWidth:2,vectorEffect:"non-scaling-stroke",stroke:"transparent",markerStart:"url(#selected)",markerMid:"url(#selected)",markerEnd:"url(#selected)",fill:n.activeLineStroke,points:`${h.points[f.closestPoint][0]},${h.points[f.closestPoint][1]}`,opacity:f.transitioning&&f.transitionIntentType==="move-shape"?0:1}):null,!f.transitioning&&(f.actionIntentType==="add-open-point"||f.actionIntentType==="close-shape"||f.actionIntentType==="close-shape-line")?N("polyline",{stroke:n.activeLineStroke,ref:p,strokeWidth:f.actionIntentType==="add-open-point"?1:2,vectorEffect:"non-scaling-stroke"}):null,f.hasClosestLine&&!f.showBoundingBox&&!f.transitioning&&f.currentTool!=="box"&&f.transitionIntentType==="split-line"?N("g",{children:N("polyline",{ref:d,vectorEffect:"non-scaling-stroke",fill:"transparent",stroke:n.activeLineStroke,strokeWidth:3})}):null,f.hasClosestLine&&!f.showBoundingBox&&!f.transitioning&&f.currentTool!=="box"&&f.transitionIntentType==="split-line"?N("g",{ref:a,children:N("polyline",{markerStart:"url(#newdot)",points:"0,0 1,1",vectorEffect:"non-scaling-stroke",stroke:"transparent",fill:"transparent",strokeWidth:2})}):null,f.transitioning?N(x,{ref:u,fill:h.open?"none":n.shapeFill,stroke:f.transitionIntentType==="stamp-shape"?n.activeLineStroke:n.shapeStroke,vectorEffect:"non-scaling-stroke",strokeWidth:(h.open,2)}):null,f.transitioning&&f.transitionIntentType==="select-multiple-points"?N("rect",{ref:r,fill:"rgba(255, 255, 255, .3)",strokeWidth:1,stroke:"rgba(0,0,0,.2)",vectorEffect:"non-scaling-stroke"}):null,f.showBoundingBox&&!L?Me(Zt,{children:[N("polygon",{ref:o,strokeWidth:2,stroke:n.boundingBoxStroke,fill:"none",markerStart:"url(#resizer)",markerMid:"url(#resizer)",markerEnd:"url(#resizer)",vectorEffect:"non-scaling-stroke"}),N("polygon",{ref:s,strokeWidth:2,stroke:n.boundingBoxDottedStroke,fill:"none",strokeDasharray:"4 4",markerStart:"url(#resizer)",markerMid:"url(#resizer)",markerEnd:"url(#resizer)",vectorEffect:"non-scaling-stroke"})]}):null]}):null;return{currentTool:v.state.slowState.currentTool,setCurrentTool:v.tools.setTool,helper:v,currentShape:h,state:f,isAddingPoint:R,isSplitting:A,isStamping:L,isHoveringPoint:C,transitionDirection:m,transitionRotate:g,defs:b,editor:Q}}import{jsx as De,jsxs as Ds}from"react/jsx-runtime";function er(e){let t=Hs(),{image:n}=e,{helper:o,defs:s,editor:i,state:r,transitionDirection:a,isSplitting:l,transitionRotate:u,isHoveringPoint:p,isAddingPoint:c}=Jo({image:e.image,theme:e.theme}),d=Jt(g=>{g.button!==2&&o.pointer([[~~g.atlas.x,~~g.atlas.y]])},[o]),m=Jt(g=>{g.button!==2&&o.pointerDown()},[o]),y=Jt(g=>{g.button!==2&&o.pointerUp()},[o]);return en(()=>{let g=S=>{o.key.up(S.key)};return document.addEventListener("keyup",g),()=>{document.removeEventListener("keyup",g)}},[o]),en(()=>{let g=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",g),()=>{document.removeEventListener("keydown",g)}},[o]),en(()=>{let g=[];return a&&g.push(`atlas-cursor-${a}`),r.actionIntentType==="cut-line"&&r.modifiers?.Shift&&g.push("atlas-cursor-cut"),(p||r.transitionIntentType==="move-shape"||r.transitionIntentType==="move-point")&&g.push("atlas-cursor-move"),c&&g.push("atlas-cursor-crosshair"),l&&g.push("atlas-cursor-copy"),u&&g.push("atlas-cursor-rotate"),r.transitionIntentType==="draw-shape"&&g.push("atlas-cursor-draw"),t?.canvas&&t.canvas.classList.add(...g),()=>{t?.canvas&&t.canvas.classList.remove(...g)}},[t?.canvas,c,p,l,r.modifiers?.Shift,r.actionIntentType,r.transitionIntentType,a,u]),De("world-object",{height:n.height,width:n.width,onMouseMove:d,onMouseDown:m,onMouseUp:y,onMouseLeave:o.blur,children:De(Bs,{relative:!0,interactive:!1,children:De("div",{className:"absolute top-0 right-0 left-0 bottom-0",children:Ds("svg",{width:"100%",height:"100%",viewBox:`0 0 ${n.width} ${n.height}`,tabIndex:-1,children:[De("title",{children:"Annotation Editor"}),De("defs",{children:s}),i]})})})})}import{useCallback as ul}from"react";import{create as cl}from"zustand";import{HTMLPortal as Gs}from"@atlas-viewer/atlas";import{autoUpdate as Qs,detectOverflow as Xs,flip as Zs,offset as Js,shift as el,useDismiss as tl,useFloating as nl,useInteractions as ol}from"@floating-ui/react";import{createPortal as rl}from"react-dom";import js,{useContext as W,useMemo as Ks}from"react";import qs from"react";import{createContext as Fs,useMemo as $s}from"react";import Ws from"mitt";import{jsx as _s}from"react/jsx-runtime";var Us=Ws(),ke=Fs({emitter:Us});ke.displayName="Events";function tr(){return qs.useContext(ke).emitter}function Fh({emitter:e,children:t}){return _s(ke.Provider,{value:$s(()=>({emitter:e}),[e]),children:t})}import{jsx as U}from"react/jsx-runtime";var qe=js.createContext({});function ct(){let e=W(qe),t=Object.keys(e),n={};for(let o of t)e[o].Provider&&(n[o]={value:W(e[o]),Provider:e[o].Provider});return n}function Ys(e){let t=Object.keys(e),n=e.children;for(let o of t){if(o==="children")continue;let{value:s,Provider:i}=e[o];n=U(i,{value:s,children:n})}return n}function ey(e){let t=W(qe),n=Ks(()=>({...t,...e.providers}),[e.providers]);return U(qe.Provider,{value:n,children:e.children})}function dt(){return{VaultContext:W(le),ResourceContext:W(Fe),SimpleViewerReactContext:W(ze),VisibleCanvasReactContext:W(he),AuthRContext:W(ve),SearchReactContext:W(Se),ReactEventContext:W(ke),ContextBridgeReactContext:W(qe),StrategyReactContext:W(ce),AtlasStoreReactContext:W(be)}}function mt(e){return U(ge,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext,children:U(he.Provider,{value:e.bridge.VisibleCanvasReactContext,children:U(ze.Provider,{value:e.bridge.SimpleViewerReactContext,children:U(ke.Provider,{value:e.bridge.ReactEventContext,children:U(be.Provider,{value:e.bridge.AtlasStoreReactContext,children:U(ve.Provider,{value:e.bridge.AuthRContext,children:U(Se.Provider,{value:e.bridge.SearchReactContext,children:U(qe.Provider,{value:e.bridge.ContextBridgeReactContext,children:U(ce.Provider,{value:e.bridge.StrategyReactContext,children:e.custom?U(Ys,{...e.custom,children:e.children}):e.children})})})})})})})})})}import{jsx as tn,jsxs as ll}from"react/jsx-runtime";var rr=10,nr=1;function il(e){let[t,n]=e.split("-");return[t,n]}function or(e,t,n){return t>n?e:Math.min(Math.max(e,t),n)}function al(e){return e.top>0||e.right>0||e.bottom>0||e.left>0}function sl(e){return{name:"insideHighlightFallback",options:e,async fn(t){if(e.width<=nr||e.height<=nr)return{};let n=await Xs(t,{altBoundary:!0});if(!al(n))return{};let{reference:o,floating:s}=t.rects,[i,r]=il(t.initialPlacement),a=Math.min(rr,o.width/2,o.height/2),l=o.x+(o.width-s.width)/2,u=o.y+(o.height-s.height)/2,p=t.x,c=t.y;return i==="top"||i==="bottom"?(c=i==="top"?o.y+a:o.y+o.height-s.height-a,r==="start"?p=o.x+a:r==="end"?p=o.x+o.width-s.width-a:p=l,p=or(p,o.x+a,o.x+o.width-s.width-a)):(p=i==="left"?o.x+a:o.x+o.width-s.width-a,r==="start"?c=o.y+a:r==="end"?c=o.y+o.height-s.height-a:c=u,c=or(c,o.y+a,o.y+o.height-s.height-a)),{x:p,y:c}}}}function pt({annotation:e,target:t,children:n,dismissable:o,isOpen:s,onOpenChange:i,placement:r}){let a=dt(),l=ct(),{refs:u,floatingStyles:p,context:c}=nl({open:s,onOpenChange:i,nodeId:e.id,placement:r||"bottom",middleware:[Js(rr),Zs({mainAxis:!0,fallbackStrategy:"bestFit",altBoundary:!0}),el({altBoundary:!0}),sl(t)],whileElementsMounted:Qs}),d=tl(c),{getReferenceProps:m,getFloatingProps:y}=ol([o?d:null].filter(g=>g!==null));return ll(Gs,{relative:!0,target:t,interactive:!1,children:[tn("div",{ref:u.setReference,...m(),style:{position:"absolute",top:0,left:0,right:0,bottom:0,pointerEvents:"none"}}),rl(tn(mt,{bridge:a,custom:l,children:tn("div",{ref:u.setFloating,style:p,...y(),children:n})}),document.getElementById("atlas-floating-ui"))]})}import{Fragment as ml,jsx as ir}from"react/jsx-runtime";var dl=cl()(e=>({isMenuOpen:!1,menuPosition:{x:0,y:0},setMenuPosition(t){e({menuPosition:t})},toggle(t){e(n=>({isMenuOpen:!n.isMenuOpen,menuPosition:t}))},open(t){e({isMenuOpen:!0,menuPosition:t})},setIsMenuOpen(t){e(typeof t=="function"?n=>({isMenuOpen:t(n.isMenuOpen)}):{isMenuOpen:t})},close(){e({isMenuOpen:!1})}}));function ft(e,t,n){let{isMenuOpen:o,setIsMenuOpen:s,close:i,open:r,menuPosition:a,setMenuPosition:l,toggle:u}=dl(),p=ul(m=>{n&&(m.preventDefault(),m.stopPropagation(),u(m.atlas))},[u,n]);return[ir(ml,{children:n&&o&&ir(pt,{dismissable:!0,placement:"bottom-start",isOpen:o,onOpenChange:s,annotation:{id:e},target:{x:a.x,y:a.y,height:1,width:1},children:o&&n({canvasId:t,position:a,close:()=>s(!1)})})}),{onContextMenu:p},{open:r,close:i,toggle:u,isMenuOpen:o,setIsMenuOpen:s,menuPosition:a,setMenuPosition:l}]}import{useStore as pl}from"zustand";function ar(){let e=q();return pl(e,t=>t.tool.requestId&&t.requests[t.tool.requestId]||null)}import{Fragment as sr,jsx as ae,jsxs as nn}from"react/jsx-runtime";function lr({theme:e,renderContextMenu:t,children:n}){let o=q(),s=P(),i=ee(o,x=>x.polygon),r=ee(o,x=>x.polygonState.currentTool),a=ee(o,x=>x.mode),l=ee(o,x=>x.changeMode),u=ee(o,x=>x.polygonState.transitioning),{enabled:p,requestId:c}=ee(o,x=>x.tool),d=gl(()=>xe(i),[i]),m=ar(),[y,g]=ft("editing-annotation",s?.id,t),S=m?.annotationPopup||n||ae(hl,{}),v=m?.svgTheme||e,f=()=>{l("sketch")};if(!p||!s||!c||!i)return null;let h=d&&i.id&&!u&&(r==="pointer"||r==="hand"||!i.open)?ae(pt,{annotation:i,target:d,children:S}):null,b="shape";return a==="explore"?nn(sr,{children:[ae(b,{id:`shape-${i.id}`,points:i.points,open:i.open,onClick:f,relativeStyle:!0,target:{x:0,y:0,width:s.width,height:s.height},style:{":hover":{backgroundColor:"rgba(0,0,0,0.2)"},backgroundColor:"rgba(0,0,0,0)",borderWidth:"4px",borderColor:"rgba(255, 255, 255, .4)"},...g}),ae(b,{id:`shape-${i.id}`,points:i.points,open:i.open,onClick:f,relativeStyle:!0,target:{x:0,y:0,width:s.width,height:s.height},style:{backgroundColor:"rgba(0,0,0,0)",borderWidth:"2px",borderColor:"rgba(0, 0, 0, .4)"}}),h]}):nn(sr,{children:[t?ae(b,{id:`shape-${i.id}`,points:i.points,open:i.open,target:{x:0,y:0,width:s.width,height:s.height},...g}):null,ae(er,{image:s,theme:v}),h,y]})}function hl(){let e=q(),t=ee(e,r=>r.changeMode),n=ee(e,r=>r.mode),o=ee(e,r=>r.completeRequest),s=ee(e,r=>r.tool),i=()=>{fl(()=>{o()})};return s.enabled?nn("div",{className:"svg-tools-container animate-fadeIn",children:[n!=="sketch"&&ae("button",{className:"svg-tools-button",onClick:()=>{t("sketch")},children:"Edit"}),ae("button",{className:"svg-tools-button",onClick:i,children:"Save"})]}):null}import{useEffect as on,useMemo as rn}from"react";import{useEffect as vr,useMemo as Sr}from"react";import{useCallback as dr,useMemo as vl}from"react";function yl(e,t){let n=e?.iiif?.meta[t];return n?n.annotationPageManager:null}function ur(e,t){return k(n=>{let o=[];if(!e)return o;let s=Object.keys(n.iiif.entities.AnnotationPage);for(let i of s)if(!t||t.indexOf(i)!==-1){let r=yl(n,i);r&&r.views&&r.views[e]&&o.push(i)}return o},[e,t])}function cr({canvas:e,manifest:t,all:n,canvases:o}){let s=[];if(t)for(let i of t.annotations)s.indexOf(i.id)===-1&&s.push(i.id);if(n){if(o&&o.length)for(let i of o)for(let r of i.annotations)s.indexOf(r.id)===-1&&s.push(r.id)}else if(e)for(let i of e.annotations)s.indexOf(i.id)===-1&&s.push(i.id);return s}function Sl(e,t){let n=e?.iiif?.meta[t];return n?n.annotationPageManager:null}function mr(e,t={}){let n=M(),o=B(),s=P(),i=$e(),r=vl(()=>cr({all:t.all,manifest:o,canvas:s,canvases:i}),[t.all,s,i,o]),a=ur(e,t.all?void 0:r),l=dr(p=>{e&&n.setMetaValue([p,"annotationPageManager","views"],c=>c&&!c[e]?c:{...c||{},[e]:!1})},[e,n]),u=dr((p,c={})=>{if(!e)return;let d=n.getState(),m=[];if(c?.deselectOthers){let y=Object.keys(d.iiif.entities.AnnotationPage);for(let g of y){let S=Sl(d,g);S&&S.views&&S.views[e]&&m.push(g)}}for(let y of m)l(y);n.setMetaValue([p,"annotationPageManager","views"],y=>y&&y[e]?y:{...y||{},[e]:!0})},[e,l,n]);return{availablePageIds:r,enabledPageIds:a,setPageEnabled:u,setPageDisabled:l}}function pr(e,t){return k((n,o)=>o.get(e.map(s=>({id:s,type:t}))),[e,t])}import xl from"mitt";import{useCallback as bl}from"react";import{createStore as Cl}from"zustand";var Rl=Cl((e,t)=>({loaded:{},setLoaded:(n,o="done")=>{e(s=>({loaded:{...s.loaded,[n]:o}}))}})),Al=xl();Al.on("loaded",e=>{Rl.getState().setLoaded(e.imageServiceId)});function fr(){let e=rt(),t=wo();return[bl((o,{height:s,width:i})=>o&&e(o,{height:s,width:i},!0),[e]),t]}import{useCallback as Pl,useMemo as hr,useState as wl}from"react";function gr(e={}){let t=je(),n=P(e.canvasId?{id:e.canvasId}:void 0);return k((o,s)=>{if(!n)return[];if(t&&e.enableSingleAnnotation)return[t];let i=s.get(n.items),r=[];for(let a of i)r.push(...s.get(a.items));return r},[n])}import{createPaintingAnnotationsHelper as Tl}from"@iiif/helpers/painting-annotations";function yr(e,t=[]){let n=M(),o=hr(()=>Tl(n),[]),s=gr({enableSingleAnnotation:e?.enableSingleAnnotation}),[i,r]=wl(e?.defaultChoices||[]),a=hr(()=>o.getPaintables(s,i),[n,s,i,...t]),u={makeChoice:Pl((p,{deselectOthers:c=!0,deselect:d=!1}={})=>{a.choice&&r(m=>{if(d){let g=m.filter(S=>S!==p);if(g.length===0){let S=a.items[0].resource.id;return S?[S]:[]}return g}if(c)return[p];let y=[...m];if(y.length===0&&a.items.length){let g=a.items[0].resource.id;g&&y.push(g)}return m.indexOf(p)!==-1?m:[...m,p]})},[a.choice])};return[a,u]}function xr(e){let t=B(),n=P(),o=M(),s=tr(),i=e?.emitter||s,[r,a]=fr(),{enabledPageIds:l}=mr(e?.annotationPageManagerId||t?.id||n?.id,{all:!1}),u=pr(l,"AnnotationPage"),p=e?.strategies||["empty","images","media","textual-content","complex-timeline"],[c,d]=yr(e,[a]);vr(()=>{let y=g=>{d.makeChoice(g.choiceId,{deselectOthers:g.deselectOthers,deselect:g.deselect})};return i.on("make-choice",y),()=>{i.off("make-choice",y)}},[]);let m=Sr(()=>un({canvas:n,paintables:c,supports:p,loadImageService:r,vault:o}),[n,c,o,d.makeChoice]);return vr(()=>{let y=c.allChoices,g={canvasId:n?.id,manifestId:t?.id};y&&i.emit("choice-change",{choice:y,partOf:g})},[n?.id,c.allChoices]),Sr(()=>m.type==="unknown"?[m,ln]:[{...m,annotations:{pages:u}},d],[m,u])}import{createStylesHelper as Il}from"@iiif/helpers";import{jsx as br}from"react/jsx-runtime";function Cr({strategies:e,registerActions:t,defaultChoices:n,onChoiceChange:o,mediaControlsDeps:s,renderMediaControls:i,renderViewerControls:r,viewControlsDeps:a,renderComplexTimelineControls:l,complexTimelineControlsDeps:u,throwOnUnknown:p,children:c}){let d=P(),m=M(),y=rn(()=>Il(m),[m]),[g,S]=xr({strategies:e||["images"],defaultChoices:n?.map(({id:b})=>b)}),v="choice"in g?g.choice:void 0;if(on(()=>{t&&t(S)},[g.annotations]),on(()=>{o&&o(v)},[v]),on(()=>{if(n)for(let b of n)typeof b.opacity<"u"&&y.applyStyles({id:b.id},"atlas",{opacity:b.opacity})},[n]),g.type==="unknown"&&p)throw new Error(g.reason||"Unknown strategy");let f=rn(()=>({renderMediaControls:i,mediaControlsDeps:s||[],renderViewerControls:r,viewControlsDeps:a||[],renderComplexTimelineControls:l,complexTimelineControlsDeps:u||[]}),[s,i,r,a,l,u]),h=rn(()=>({strategy:g,actions:S,choices:"choice"in g?g.choice:[]}),[g,d]);return br(et.Provider,{value:f,children:br(ce.Provider,{value:h,children:c})})}import{useEffect as Ar,useMemo as Vl}from"react";import{useStore as Pr}from"zustand";import{createContext as Ml,useContext as kl,useEffect as El}from"react";var an=Ml(()=>{});function Rr(e){let t=P(),n=kl(an);El(()=>t&&t.id?(n(t.id,e),()=>n(t.id,-1)):()=>{},[t,e])}import{jsxs as Nl}from"react/jsx-runtime";function wr({x:e=0,y:t=0,keepCanvasScale:n=!0,renderContextMenu:o,children:s}){let{strategy:i}=V(),r=P(),a=q(),l=Ke(r,["deep-zoom"]),u=Pr(a,g=>g.setCanvasRelativePosition),p=Pr(a,g=>g.clearCanvasRelativePosition),[c,d]=ft(`context-menu/${r?.id}`,r?.id,o),m=Vl(()=>n?1:Math.max(1,...i.type==="images"?i.images.map(g=>(g.width||0)/g.target?.spatial.width):[]),[n,i]);Ar(()=>{if(r)return u(r.id,{x:e,y:t,width:r.width,height:r.height}),()=>{p(r.id)}},[e,t,r,p,u]),Ar(()=>{r&&a.getState().reset()},[a,r]),Rr(m);let y=i.type==="images"?i.images.length:0;return r?Nl("world-object",{height:r.height,width:r.width,x:e,y:t,...d,...l,children:[c,s]},`${r.id}/${i.type}/${y}`):null}import{jsx as Y,jsxs as Tr}from"react/jsx-runtime";function de({x:e,y:t,onChoiceChange:n,registerActions:o,defaultChoices:s,isStatic:i,renderViewerControls:r,renderMediaControls:a,renderComplexTimelineControls:l,complexTimelineControlsDeps:u,viewControlsDeps:p,mediaControlsDeps:c,strategies:d,throwOnUnknown:m,rotation:y,backgroundStyle:g,alwaysShowBackground:S,keepCanvasScale:v=!1,enableSizes:f=!1,enableYouTube:h=!0,onClickPaintingAnnotation:b,components:x={},children:C,annotationPopup:R,svgTheme:A,renderContextMenu:L,renderAnnotationContextMenu:Q}){return Tr(Cr,{throwOnUnknown:m,onChoiceChange:n,registerActions:o,strategies:d,defaultChoices:s,mediaControlsDeps:c,renderMediaControls:a,renderViewerControls:r,renderComplexTimelineControls:l,complexTimelineControlsDeps:u,viewControlsDeps:p,children:[Tr(wr,{keepCanvasScale:v,x:e,y:t,renderContextMenu:L,children:[Y(Wo,{alwaysShowBackground:S,backgroundStyle:g}),Y($o,{}),Y(_o,{}),Y(Uo,{isStatic:i,enableSizes:f,onClickPaintingAnnotation:b,rotation:y}),Y(ho,{}),Y(io,{}),Y(xo,{as:x.Audio}),Y(Ko,{as:x.Video}),h?Y(Qo,{}):null,Y(lr,{theme:A,renderContextMenu:Q,children:R}),C]}),Y(ao,{})]})}import{jsx as Ir}from"react/jsx-runtime";function Mr(e){let t=P();return!t||!t.placeholderCanvas?null:Ir(te,{canvas:t.placeholderCanvas.id,children:Ir(de,{renderViewerControls:e.renderViewerControls})})}import{AtlasAuto as Bl}from"@atlas-viewer/atlas";import Vr,{useCallback as gt,useMemo as Hl,useState as ht}from"react";import{ErrorBoundary as Dl}from"react-error-boundary";import{useStore as Nr}from"zustand";import{useEffect as Ll,useMemo as zl}from"react";function kr(e,t=2e3){let{currentSequenceIndex:n,sequence:o,items:s}=_e(),i=P(),r=zl(()=>{let l=o[n]||[];return l.length===0&&i?[{id:i.id,type:"Canvas"}]:l.map(u=>s[u])},[o,n,i,s]),a=q();Ll(()=>{let u=setInterval(()=>{if(e&&t!==-1){let p={x:e.x,y:e.y,width:e.width,height:e.height},c=a.getState().canvasRelativePositions,d={};for(let m of r){let y=c[m.id];if(y){let g=y.x,S=y.y,v=y.width,f=y.height,h={x:Math.max(g,p.x),y:Math.max(S,p.y),width:Math.min(g+v,p.x+p.width)-Math.max(g,p.x),height:Math.min(S+f,p.y+p.height)-Math.max(S,p.y)};h.width<=0||h.height<=0||(d[m.id]={x:h.x-y.x,y:h.y-y.y,width:h.width,height:h.height}),a.setState({canvasViewports:d})}}}},t);return()=>{clearTimeout(u)}},[r,e,a,t])}import{jsx as sn,jsxs as Ol}from"react/jsx-runtime";function Er({width:e,style:t,height:n,error:o,resetErrorBoundary:s}){return Ol("div",{style:{width:e,height:n,minHeight:500,...t||{},background:"#f9f9f9"},children:[sn("h3",{children:"Error occurred"}),sn("p",{children:o.message}),sn("button",{type:"button",onClick:s,children:"Reset"})]})}import{Fragment as Fl,jsx as O,jsxs as $l}from"react/jsx-runtime";function Lr(e){let t=q();return O(Oe,{name:e.name,existing:t,children:O(ql,{...e})})}function ql({name:e,children:t,errorFallback:n,outerContainerProps:o={},worldScale:s,updateViewportTimeout:i,...r}){let a=q(),l=Nr(a,w=>w.mode),u=Nr(a,w=>w.setAtlasRuntime),[p,c]=ht(),d=ct(),m=dt(),y=n||Er,[g,S]=ht({}),v=Object.entries(g),[f,h]=ht({}),b=Object.entries(f),[x,C]=ht({}),{worldScale:R,runtimeOptions:A}=Hl(()=>{if(Object.values(x).length===0)return{worldScale:1,runtimeOptions:r.runtimeOptions||{maxOverZoom:1}};let I=Math.max(...Object.values(x));return{worldScale:I,runtimeOptions:{maxOverZoom:I||1,...r.runtimeOptions||{}}}},[x,r.runtimeOptions]);kr(p?.runtime,i);let L=gt((w,I)=>{C(E=>{if(I===-1){let{[w]:Ee,...se}=E;return se}return{...E,[w]:I}})},[]),Q=gt((w,I,E)=>{S(({[w]:Ee,...se})=>I?{...se,[w]:{element:I,props:E}}:se)},[]),T=gt((w,I,E)=>{h(({[w]:Ee,...se})=>I?{...se,[w]:{element:I,props:E}}:se)},[]),z=gt(w=>{c(w),u(w.runtime),r.onCreated&&r.onCreated(w)},[r.onCreated,u]);return $l(Dl,{resetKeys:[],fallbackRender:w=>O(y,{...r,...w}),children:[O(Bl,{...r,mode:l,containerProps:{style:{position:"relative"},...r.containerProps||{}},htmlChildren:O(Fl,{children:v.map(([w,{element:I,props:E}])=>O(Vr.Fragment,{children:O(I,{...E||{}})},w))}),onCreated:z,runtimeOptions:A,children:O(Oe,{name:e,existing:a,children:O(fe.Provider,{value:p,children:O(an.Provider,{value:L,children:O(Bt.Provider,{value:Q,children:O(Ht.Provider,{value:T,children:O(mt,{bridge:m,custom:d,children:O(fo,{children:t})})})})})})})}),O("div",{children:b.map(([w,{element:I,props:E}])=>O(Vr.Fragment,{children:O(I,{...E||{}})},w))}),O("div",{id:"atlas-floating-ui",style:{position:"relative",zIndex:999999}})]})}import{Fragment as jl,jsx as G,jsxs as Kl}from"react/jsx-runtime";var _l=zr(function(t,n){let o=B(),s=$e(),i=_e(),{ViewerControls:r,MediaControls:a,ComplexTimelineControls:l}=t.components||{};if(Wl(n,()=>i,[i]),!o)return G("div",{});let u=0,p=o.viewingDirection==="top-to-bottom",c=o.viewingDirection==="bottom-to-top",d=o.viewingDirection==="left-to-right",m=o.viewingDirection==="right-to-left",g=o.behavior.includes("continuous")?0:t.spacing||0,S=c||m,v=Ul(()=>S?[...s].reverse():s,[s,S]);return Kl(jl,{children:[t.header,G(H.Viewer,{height:t.height,mode:t.mode,renderPreset:t.renderPreset,runtimeOptions:t.runtimeOptions,updateViewportTimeout:t.updateViewportTimeout,homePaddingPx:t.padding,children:v.map((f,h)=>{let b=0,x=0;return!p&&!c?(b=u,u+=f.width+g):(x=u,u+=f.height+g),G(te,{canvas:f.id,children:G(H.RenderCanvas,{strategies:["3d-model","media","images","empty","textual-content","complex-timeline"],renderViewerControls:h===0&&r?()=>G(r,{}):void 0,renderMediaControls:h===0&&a?()=>G(a,{}):void 0,annotationPopup:t.annotationPopup,renderContextMenu:t.renderContextMenu,keepCanvasScale:t.keepCanvasScale,renderComplexTimelineControls:h===0&&l?()=>G(l,{}):void 0,renderAnnotationContextMenu:t.renderAnnotationContextMenu,x:b,y:x,svgTheme:t.svgTheme,rotation:t.rotation,...t.canvasProps||{},children:t.annotations},f.id)},f.id)})},t.reuseAtlas?"":i.currentSequenceIndex),t.children]})}),H=zr(function({children:t,height:n,annotations:o,canvasProps:s,spacing:i,header:r,components:a,mode:l,reuseAtlas:u,renderPreset:p,runtimeOptions:c,annotationPopup:d,name:m,svgTheme:y,updateViewportTimeout:g,renderContextMenu:S,keepCanvasScale:v,renderAnnotationContextMenu:f,padding:h,rotation:b,...x},C){let R=ye();return G(Oe,{name:m,children:G(ge,{vault:R,children:G(On,{...x,children:G(_l,{ref:C,height:n,components:a,spacing:i,canvasProps:s,annotations:o,header:r,mode:l,reuseAtlas:u,renderPreset:p,runtimeOptions:c,annotationPopup:d,svgTheme:y,updateViewportTimeout:g,renderContextMenu:S,keepCanvasScale:v,renderAnnotationContextMenu:f,padding:h,rotation:b,children:t})})})})});H.RenderImage=Ie;H.RenderCanvas=de;H.RenderAnnotationPage=ue;H.RenderAnnotation=Re;H.Viewer=Lr;H.CanvasBackground=st;H.Audio=Ze;H.Video=ut;H.Model=Je;H.AudioHTML=Dt;H.VideoHTML=Qt;H.ModelHTML=Ft;H.PlaceholderCanvas=Mr;H.getAtlasStoreByName=Un;export{Fe as a,_ as b,ie as c,te as d,le as e,ge as f,M as g,k as h,he as i,$e as j,ye as k,B as l,mn as m,pn as n,fn as o,gn as p,oi as q,vt as r,Wu as s,hn as t,ju as u,St as v,yn as w,vn as x,ic as y,bn as z,Cn as A,Rn as B,xt as C,Sn as D,ve as E,di as F,mi as G,kn as H,En as I,Ne as J,pi as K,Rc as L,fi as M,In as N,Ac as O,Vn as P,Ln as Q,ze as R,Pi as S,On as T,_e as U,At as V,md as W,Hn as X,Dn as Y,Pt as Z,xe as _,Ei as $,yd as aa,wt as ba,Tt as ca,qn as da,Fn as ea,be as fa,q as ga,Un as ha,Oe as ia,_n as ja,jn as ka,Ld as la,Yi as ma,Kn as na,je as oa,P as pa,Ke as qa,Ce as ra,Gn as sa,Xn as ta,Re as ua,Zn as va,ue as wa,Hm as xa,Dm as ya,qm as za,Ge as Aa,Qe as Ba,Ot as Ca,Ae as Da,D as Ea,ce as Fa,V as Ga,io as Ha,et as Ia,F as Ja,ao as Ka,so as La,co as Ma,po as Na,fo as Oa,ho as Pa,yo as Qa,Da as Ra,vo as Sa,Pe as Ta,we as Ua,xo as Va,bo as Wa,yf as Xa,rt as Ya,If as Za,Vf as _a,Nf as $a,Lf as ab,Eo as bb,_t as cb,Vo as db,ns as eb,os as fb,rs as gb,zf as hb,Be as ib,Ie as jb,$o as kb,Wo as lb,fe as mb,lt as nb,Uo as ob,_o as pb,Ko as qb,Qo as rb,Xo as sb,Os as tb,Jo as ub,Us as vb,ke as wb,tr as xb,Fh as yb,ct as zb,Ys as Ab,ey as Bb,dt as Cb,mt as Db,dl as Eb,ft as Fb,ar as Gb,lr as Hb,hl as Ib,cr as Jb,mr as Kb,pr as Lb,fr as Mb,gr as Nb,yr as Ob,xr as Pb,Cr as Qb,wr as Rb,Er as Sb,Lr as Tb,H as Ub};