react-iiif-vault 0.9.16 → 0.9.19

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.
@@ -0,0 +1,5 @@
1
+ import { ReactNode } from 'react';
2
+ export declare function AnnotationPageContext({ annotationPage, children }: {
3
+ annotationPage: string;
4
+ children: ReactNode;
5
+ }): JSX.Element;
@@ -5,6 +5,7 @@ export declare type ResourceContextType = {
5
5
  range?: string;
6
6
  canvas?: string;
7
7
  annotation?: string;
8
+ annotationPage?: string;
8
9
  };
9
10
  export declare const ResourceReactContext: React.Context<ResourceContextType>;
10
11
  export declare const useResourceContext: () => ResourceContextType;
@@ -0,0 +1,8 @@
1
+ import { AnnotationPageNormalized } from '@iiif/presentation-3';
2
+ export declare function useAnnotationPage(options?: {
3
+ id: string;
4
+ }): AnnotationPageNormalized | undefined;
5
+ export declare function useAnnotationPage<T>(options?: {
6
+ id: string;
7
+ selector: (annotation: AnnotationPageNormalized) => T;
8
+ }, deps?: any[]): T | undefined;
@@ -1,5 +1,6 @@
1
1
  export declare function usePaintables(options?: {
2
2
  defaultChoices?: string[];
3
+ enableSingleAnnotation?: boolean;
3
4
  }, deps?: any[]): readonly [import("../features/rendering-strategy/rendering-utils").Paintables, {
4
5
  makeChoice: (id: string, { deselectOthers, deselect }?: {
5
6
  deselectOthers?: boolean | undefined;
@@ -1,4 +1,5 @@
1
1
  import { AnnotationNormalized } from '@iiif/presentation-3';
2
2
  export declare function usePaintingAnnotations(options?: {
3
3
  canvasId?: string;
4
+ enableSingleAnnotation?: boolean;
4
5
  }): AnnotationNormalized[];
@@ -9,6 +9,7 @@ export declare type UseRenderingStrategy = [RenderingStrategy, StrategyActions];
9
9
  export declare type UseRenderingStrategyOptions = {
10
10
  strategies?: Array<RenderingStrategy['type']>;
11
11
  annotationPageManagerId?: string;
12
+ enableSingleAnnotation?: boolean;
12
13
  defaultChoices?: string[];
13
14
  };
14
15
  export declare function useRenderingStrategy(options?: UseRenderingStrategyOptions): UseRenderingStrategy;
@@ -1,5 +1,6 @@
1
1
  export * from './canvas-panel';
2
2
  export * from './context/AnnotationContext';
3
+ export * from './context/AnnotationPageContext';
3
4
  export * from './context/CanvasContext';
4
5
  export * from './context/CollectionContext';
5
6
  export * from './context/ManifestContext';
@@ -18,6 +19,7 @@ export * from './features/rendering-strategy/rendering-utils';
18
19
  export * from './features/rendering-strategy/resource-types';
19
20
  export * from './features/rendering-strategy/strategies';
20
21
  export * from './hooks/useAnnotation';
22
+ export * from './hooks/useAnnotationPage';
21
23
  export * from './hooks/useAnnotationPageManager';
22
24
  export * from './hooks/useAnnotationsAtTime';
23
25
  export * from './hooks/useCanvas';
@@ -1,4 +1,4 @@
1
- "use strict";var Vt=Object.defineProperty,kt=Object.defineProperties;var Nt=Object.getOwnPropertyDescriptors;var W=Object.getOwnPropertySymbols;var Ie=Object.prototype.hasOwnProperty,Re=Object.prototype.propertyIsEnumerable;var Pe=(e,t,n)=>t in e?Vt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,S=(e,t)=>{for(var n in t||(t={}))Ie.call(t,n)&&Pe(e,n,t[n]);if(W)for(var n of W(t))Re.call(t,n)&&Pe(e,n,t[n]);return e},b=(e,t)=>kt(e,Nt(t));var Me=(e,t)=>{var n={};for(var r in e)Ie.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&W)for(var r of W(e))t.indexOf(r)<0&&Re.call(e,r)&&(n[r]=e[r]);return n};Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var c=require("react"),z=require("@atlas-viewer/atlas"),d=require("react/jsx-runtime"),X=require("@iiif/vault"),R=require("typesafe-actions"),Ae=require("react-dom/client"),Ut=require("@iiif/vault-helpers"),N=require("@atlas-viewer/iiif-image-api");function Dt(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}function Bt(e){if(e&&e.__esModule)return e;var t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});return e&&Object.keys(e).forEach(function(n){if(n!=="default"){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,Object.freeze(t)}var ae=Bt(c),U=Dt(c);function le(e,t){return le=Object.setPrototypeOf||function(r,o){return r.__proto__=o,r},le(e,t)}function Ht(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,le(e,t)}var qt=function(t,n){return t===void 0&&(t=[]),n===void 0&&(n=[]),t.length!==n.length||t.some(function(r,o){return!Object.is(r,n[o])})},Te={error:null},$t=function(e){Ht(t,e);function t(){for(var r,o=arguments.length,s=new Array(o),i=0;i<o;i++)s[i]=arguments[i];return r=e.call.apply(e,[this].concat(s))||this,r.state=Te,r.resetErrorBoundary=function(){for(var a,l=arguments.length,u=new Array(l),p=0;p<l;p++)u[p]=arguments[p];r.props.onReset==null||(a=r.props).onReset.apply(a,u),r.reset()},r}t.getDerivedStateFromError=function(o){return{error:o}};var n=t.prototype;return n.reset=function(){this.setState(Te)},n.componentDidCatch=function(o,s){var i,a;(i=(a=this.props).onError)==null||i.call(a,o,s)},n.componentDidUpdate=function(o,s){var i=this.state.error,a=this.props.resetKeys;if(i!==null&&s.error!==null&&qt(o.resetKeys,a)){var l,u;(l=(u=this.props).onResetKeysChange)==null||l.call(u,o.resetKeys,a),this.reset()}},n.render=function(){var o=this.state.error,s=this.props,i=s.fallbackRender,a=s.FallbackComponent,l=s.fallback;if(o!==null){var u={error:o,resetErrorBoundary:this.resetErrorBoundary};if(ae.isValidElement(l))return l;if(typeof i=="function")return i(u);if(a)return ae.createElement(a,u);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},t}(ae.Component);const zt={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},ne=U.default.createContext(zt),L=()=>c.useContext(ne);function D({value:e,children:t}){const n=L(),r=c.useMemo(()=>S(S({},n),e),[e,n]);return d.jsx(ne.Provider,{value:r,children:t})}const Q=U.default.createContext({vault:null,setVaultInstance:e=>{}});function He({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:o}){const[s,i]=c.useState(()=>e||(n?X.globalVault(t):t?new X.Vault(t):new X.Vault));return d.jsx(Q.Provider,{value:{vault:s,setVaultInstance:i},children:d.jsx(D,{value:r||{},children:o})})}const I=()=>{const{vault:e}=c.useContext(Q);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};function pe(e,{noCache:t=!1}={}){const n=typeof e=="string"?e:e.id,r=I(),[o,s]=c.useState(n),[i,a]=c.useState(void 0),l=c.useMemo(()=>r.get(n,{skipSelfReturn:!0})||void 0,[n,r]),[u,p]=c.useState(l);return c.useEffect(()=>{(async()=>{try{const f=l&&!t?l:await r.load(n),g=f?f.id||f["@id"]:null;f&&o!==g&&s(g),p(f)}catch(f){a(f)}})()},[n,t]),{isLoaded:!!u,id:o,requestId:n,error:i,resource:u,cached:!!(u&&u===l)}}function qe(e,t){const{id:n,isLoaded:r,error:o,resource:s,requestId:i,cached:a}=pe(e,t);return{id:n,isLoaded:r,error:o,manifest:s,requestId:i,cached:a}}function $e({manifest:e,children:t}){return d.jsx(D,{value:{manifest:e},children:t})}function ge({canvas:e,children:t}){return d.jsx(D,{value:{canvas:e},children:t})}function M(e,t=[]){const n=I(),[r,o]=c.useState(()=>e(n.getState(),n));return c.useEffect(()=>n.subscribe(s=>e(s,n),s=>{o(s)},!1),t),r}const G=U.default.createContext([]);function ze(){const e=c.useContext(G);return M(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}function B(e={},t=[]){const{id:n,selector:r}=e,o=L();I();const s=n||o.manifest,i=M(a=>s?a.iiif.entities.Manifest[s]:void 0,[s]);return c.useMemo(()=>{if(!!i)return r?r(i):i},[i,r,...t])}function Ye({range:e,children:t}){return d.jsx(D,{value:{range:e},children:t})}function Qe(e,t){for(const n of t.items){if(n.type==="Canvas")return n;if(n.type==="Range"){const r=Qe(e,e.get(n));if(r)return r}}return null}function he(e,t){const n=[];for(const r of t.items)if(r.type==="Canvas"&&(r.id.indexOf("#")!==-1?n.push({id:r.id.split("#")[0],type:"Canvas"}):n.push(r)),r.type==="Range"&&n.push(...he(e,e.get(r))),r.type==="SpecificResource"){const o=typeof r.source=="string"?r.source:r.source.id;n.push({id:o,type:"Canvas"})}return n}function Yt(e,t,n){for(const r of t.structures){const o=me(e,e.get(r),n);if(o)return o}return null}function me(e,t,n){var r;for(const o of t.items){const s=(r=o.id)==null?void 0:r.split("#")[0];if(o.type==="SpecificResource"&&o.source===n||o.type==="Canvas"&&n===s)return t;if(o.type==="Range"){const i=me(e,e.get(o),n);if(i)return i}}return null}function Qt(e,t,n,r=!1){const o=t.behavior,s=n?e.get(n):null;if(!s)return[];const i=s.behavior,a=r?!1:o.includes("paged"),l=a?!1:o.includes("continuous"),u=a||l?!1:o.includes("individuals"),p=i.includes("facing-pages"),f=i.includes("non-paged");if(p||f||u||r)return[{id:s.id,type:"Canvas"}];const[g,m]=ve(e,t);if(l)return g;const h=g.findIndex(y=>y.id===n);if(h===-1)return[];for(const y of m)if(y.includes(h))return y.map(x=>g[x]);return[{id:s.id,type:"Canvas"}]}function ve(e,t,{disablePaging:n}={}){const r=t.behavior,o=r.includes("paged"),s=o?!1:r.includes("continuous"),i=o||s?!1:r.includes("individuals"),a=t.type==="Manifest"?t.items:he(e,t);if(s)return[a,[a.map((f,g)=>g)]];if(i||!o||n)return[a,a.map((f,g)=>[g])];const l=[];let u=[];const p=()=>{u.length&&(l.push([...u]),u=[])};for(let f=0;f<a.length;f++){const g=e.get(a[f]);if(f===0||g.behavior.includes("facing-pages")){p(),l.push([f]);continue}g.behavior.includes("non-paged")||(u.push(f),u.length>1&&p())}return u.length&&p(),[a,l]}function Ge(e={},t=[]){const{id:n,selector:r}=e,o=L(),s=n||o.range,i=M(a=>s?a.iiif.entities.Range[s]:void 0,[s]);return c.useMemo(()=>{if(!!i)return r?r(i):i},[i,r,...t])}function Ke({startCanvas:e,disablePaging:t}){var h;const n=I(),r=B(),o=Ge(),[s,i]=c.useState(void 0),a=o||r;if(!a)throw new Error("Nothing selected");const[l,u]=c.useMemo(()=>ve(n,a,{disablePaging:t}),[n,a]),p=c.useCallback(y=>{const x=u.findIndex(C=>C.includes(y));i(x===-1?0:x)},[l,u]),f=c.useCallback(y=>{const x=l.findIndex(C=>C.id===y);x!==-1?p(x):i(0)},[l,u]),g=c.useCallback(()=>{i(y=>y>=u.length?y:y+1)},[u]),m=c.useCallback(()=>{i(y=>y<=0?0:y-1)},[u]);return typeof s=="undefined"&&(e?f(e):i(0)),{visibleItems:((h=u[s])==null?void 0:h.map(y=>l[y].id))||[],cursor:s,items:l,sequence:u,setSequenceIndex:i,setCanvasIndex:p,setCanvasId:f,next:g,previous:m}}const $=()=>{},K=c.createContext({setCurrentCanvasId:$,setCurrentCanvasIndex:$,nextCanvas:$,previousCanvas:$,items:[],sequence:[],setSequenceIndex:$,currentSequenceIndex:0});function We(e){const t=B(),{cursor:n,visibleItems:r,next:o,sequence:s,items:i,setCanvasIndex:a,setCanvasId:l,previous:u,setSequenceIndex:p}=Ke({startCanvas:e.startCanvas,disablePaging:e.pagingEnabled===!1}),f=c.useMemo(()=>({sequence:s,items:i,setCurrentCanvasId:l,nextCanvas:o,previousCanvas:u,totalCanvases:i.length,setCurrentCanvasIndex:a,setSequenceIndex:p,currentSequenceIndex:n}),[s,i,l,o,u,i,a,p,n]);return t?d.jsx(K.Provider,{value:f,children:d.jsx(G.Provider,{value:r,children:d.jsx(ge,{canvas:r[0],children:e.children})})}):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),d.jsx("div",{children:"Sorry, something went wrong."}))}function Gt(e){const t=qe(e.manifest);if(!t)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),d.jsx("div",{children:"Sorry, something went wrong."});if(!t.isLoaded)return d.jsx("div",{children:"Loading..."});const n=d.jsx(We,b(S({},e),{children:e.children}));return d.jsx($e,{manifest:t.id,children:e.rangeId?d.jsx(Ye,{range:e.rangeId,children:n}):n})}function Kt(){return c.useContext(K)}function Xe(){return{VaultContext:c.useContext(Q),ResourceContext:c.useContext(ne),SimpleViewerReactContext:c.useContext(K),VisibleCanvasReactContext:c.useContext(G)}}function Je(e){return d.jsx(He,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext,children:d.jsx(G.Provider,{value:e.bridge.VisibleCanvasReactContext,children:d.jsx(K.Provider,{value:e.bridge.SimpleViewerReactContext,children:e.children})})})}const Wt="@iiif/IMPORT_ENTITIES",Xt="@iiif/MODIFY_ENTITY_FIELD",Jt="@iiif/REORDER_ENTITY_FIELD",Zt="@iiif/ADD_REFERENCE",en="@iiif/REMOVE_REFERENCE",tn=R.createAction(Wt)(),nn=R.createAction(Xt)(),rn=R.createAction(Jt)(),on=R.createAction(Zt)(),sn=R.createAction(en)(),ce={importEntities:tn,modifyEntityField:nn,reorderEntityField:rn,addReference:on,removeReference:sn},an="@iiif/ADD_MAPPING",cn="@iiif/ADD_MAPPINGS";R.createAction(an)();R.createAction(cn)();const un="@iiif/SET_META_VALUE",ln="@iiif/SET_META_VALUE_DYNAMIC",fn="@iiif/UNSET_META_VALUE";R.createAction(un)();R.createAction(ln)();R.createAction(fn)();const dn="@iiif/REQUEST_RESOURCE",pn="@iiif/REQUEST_ERROR",gn="@iiif/REQUEST_MISMATCH",hn="@iiif/REQUEST_COMPLETE",mn="@iiif/REQUEST_OFFLINE_RESOURCE";R.createAction(dn)();R.createAction(pn)();R.createAction(gn)();R.createAction(hn)();R.createAction(mn)();const vn="@iiif/BATCH",yn="@iiif/BATCH_IMPORT";R.createAction(vn)();R.createAction(yn)();function Ze(){const t=I().getStore();return c.useMemo(()=>n=>t.dispatch(n),[t])}function Oe(e){return typeof e!="string"&&e&&e.bindToVault}function et(){const e=I(),t=c.useRef([]),n=Ze(),r=c.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);c.useLayoutEffect(()=>{const a={id:r,type:"AnnotationPage",behavior:[],motivation:null,label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[]};n(ce.importEntities({entities:{AnnotationPage:{[a.id]:a}}}))},[r]);const o=M(a=>r?a.iiif.entities.AnnotationPage[r]:null,[r]),s=c.useCallback((a,l)=>{if(r){if(Oe(a)){const f=a;f.__vault||f.bindToVault(e),a=typeof f.source=="string"?f.source:f.source.id,t.current[a]=f}else typeof a!="string"&&(a=a.id);const u=e.get({id:r,type:"AnnotationPage"}),p=e.get({id:a,type:"Annotation"});u&&p&&(u.items.find(f=>f.id===p.id)||n(ce.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"},index:l})))}},[r]),i=c.useCallback(a=>{r&&(Oe(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:r,type:"AnnotationPage"})&&n(ce.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"}})))},[r]);return[o,{addAnnotation:s,removeAnnotation:i}]}const tt=c.createContext(null);function nt(){const e=c.useContext(tt);return[e.fullPage,{addAnnotation:e.addAnnotation,removeAnnotation:e.removeAnnotation}]}function rt({children:e}){const[t,{addAnnotation:n,removeAnnotation:r}]=et();return d.jsx(tt.Provider,{value:c.useMemo(()=>({fullPage:t,addAnnotation:n,removeAnnotation:r}),[t]),children:e})}function xn({width:e,style:t,height:n}){return d.jsx("div",{style:b(S({width:e,height:n,minHeight:500},t||{}),{background:"#f9f9f9"}),children:"Unknown error"})}const re=c.createContext(null);function it(){return c.useContext(re)}const ye=U.default.createContext(null),xe=U.default.createContext(null);function H({children:e,overlay:t}){const n=c.useContext(t?xe:ye),r=it();return c.useLayoutEffect(()=>{if(n)try{n.render(d.jsx(re.Provider,{value:r,children:e}))}catch{}},[e,r]),null}function Sn(o){var s=o,{children:e,errorFallback:t,outerContainerProps:n={}}=s,r=Me(s,["children","errorFallback","outerContainerProps"]);const i=c.useRef(null),[a,l]=c.useState(),[u,p]=c.useState(),f=c.useRef(null),[g,m]=c.useState(),h=Xe(),y=t||xn;return c.useLayoutEffect(()=>{const x={};if(i.current){const C=document.createElement("div");i.current.appendChild(C),x.portal=Ae.createRoot(C),l(x.portal)}if(f.current){const C=document.createElement("div");f.current.appendChild(C),x.overlayPortal=Ae.createRoot(C),m(x.overlayPortal)}return()=>{l(null),m(null),setTimeout(()=>{x.portal&&x.portal.unmount(),x.overlayPortal&&x.overlayPortal.unmount()},0)}},[]),d.jsxs($t,{fallbackRender:()=>d.jsx(y,S({},r)),children:[d.jsx(z.AtlasAuto,b(S({},r),{containerProps:S({style:{position:"relative"}},r.containerProps||{}),htmlChildren:d.jsx("div",{ref:f}),onCreated:x=>{p(x),r.onCreated&&r.onCreated(x)},children:d.jsx(re.Provider,{value:u,children:d.jsx(ye.Provider,{value:a,children:d.jsx(xe.Provider,{value:g,children:d.jsx(Je,{bridge:h,children:d.jsx(rt,{children:e})})})})})})),d.jsx("div",{ref:i})]})}function ot(e){return{addEventListener(t,n,r,o){if(!!t)return e.setMetaValue([t.id,"eventManager",n],s=>{const i=s||[];for(const a of i)if(a.callback===r)return i;return[...i,{callback:r,scope:o}]}),r},removeEventListener(t,n,r){!t||e.setMetaValue([t.id,"eventManager",n],o=>(o||[]).filter(s=>s.callback!==r))},getListenersAsProps(t,n){const r=typeof t=="string"?{id:t}:t;if(!r||!r.id)return{};const o=e.getResourceMeta(r.id,"eventManager"),s={};if(o&&r)for(const i of Object.keys(o))s[i]=a=>{const l=e.get(r);for(const{callback:u,scope:p}of o[i]||[])(!p||n&&p.indexOf(n)!==-1)&&u(a,l)};return s}}}function Se(e,t){const n=I(),r=c.useMemo(()=>ot(n),[n]),o=M(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return c.useMemo(()=>e?r.getListenersAsProps(e,t):{},[o,e,n,t])}function Ce(e){return{applyStyles(t,n,r){const o=typeof t=="string"?t:t.id;return e.setMetaValue([o,"styles",n],r)},getAppliedStyles(t){const n=typeof t=="string"?t:t.id;return e.getResourceMeta(n,"styles")}}}function Y(e,t){const n=I(),r=c.useMemo(()=>Ce(n),[n]);return M(()=>{if(!e)return null;const o=r.getAppliedStyles(e.id);return o?t?o[t]:o:void 0},[e,t])}var Cn=Object.defineProperty,bn=Object.defineProperties,En=Object.getOwnPropertyDescriptors,je=Object.getOwnPropertySymbols,wn=Object.prototype.hasOwnProperty,Pn=Object.prototype.propertyIsEnumerable,_e=(e,t,n)=>t in e?Cn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Le=(e,t)=>{for(var n in t||(t={}))wn.call(t,n)&&_e(e,n,t[n]);if(je)for(var n of je(t))Pn.call(t,n)&&_e(e,n,t[n]);return e},Fe=(e,t)=>bn(e,En(t));const In=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,Rn=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function Z(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:r,selectors:o}=Z(n);return r&&(t.selector||(t.selector=r),t.selectors.push(...o)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,n]=e.split("#");return n?Z({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=In.exec(e.value);if(t){const r={type:"BoxSelector",spatial:{unit:t[2]==="percent:"||t[2]==="pct:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:r,selectors:[r]}}const n=e.value.match(Rn);if(n){const r={type:"TemporalSelector",temporal:{startTime:n[4]?parseFloat(n[4]):0,endTime:n[7]?parseFloat(n[7]):void 0}};return{selector:r,selectors:[r]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}function V(e,t={}){if(Array.isArray(e))return V(e[0]);if(typeof e=="string"){const[n,r]=e.split("#");return r?V({type:"SpecificResource",source:{id:n,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return V(e.items[0]);if(e.type==="SpecificResource"){e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]);const{selector:n,selectors:r}=e.selector?Z(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:n,selectors:r}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[n,r]=e.id.split("#");return r?V({type:"SpecificResource",source:Fe(Le({},e),{id:n}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:Fe(Le({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function st(e={},t=[]){const{id:n,selector:r}=e,o=L(),s=I(),i=n||o.annotation,a=M(u=>i?u.iiif.entities.Annotation[i]:void 0,[i]),l=M(u=>a&&a.body?a.body.map(p=>p?u.iiif.entities[p.type][p.id]:null).filter(Boolean):[],[a]);return c.useMemo(()=>{if(!a)return;const u=b(S({},a),{body:l,target:V(a.target,{typeMap:s.getState().iiif.mapping})});return r?r(u):u},[a,r,l,...t])}function _(e={},t=[]){const{id:n,selector:r}=e,o=L(),s=n||o.canvas,i=M(a=>s?a.iiif.entities.Canvas[s]:void 0,[s]);return c.useMemo(()=>{if(!!i)return r?r(i):i},[i,r,...t])}const at=({id:e,style:t,className:n,interactive:r})=>{const o=st({id:e}),s=Y(o,"atlas"),i=Y(o,"html"),a=Se(o,["atlas"]),l=_(),u=c.useMemo(()=>z.mergeStyles(t,s),[t,s]);return l&&o&&o.target&&o.target.selector&&o.target.selector.type==="BoxSelector"&&o.target.source&&o.target.source.id===l.id?d.jsx(z.RegionHighlight,S({id:o.id,isEditing:!0,region:o.target.selector.spatial,style:u,className:(i==null?void 0:i.className)||n,interactive:!!((i==null?void 0:i.href)||r),href:(i==null?void 0:i.href)||null,title:(i==null?void 0:i.title)||null,hrefTarget:(i==null?void 0:i.target)||null},a)):null},fe=({className:e,page:t})=>{var o;const n=Y(t,"atlas"),r=Y(t,"html");return M(s=>t.id?s.iiif.entities.AnnotationPage[t.id]:null,[]),d.jsx(c.Fragment,{children:(o=t.items)==null?void 0:o.map(s=>d.jsx(at,{id:s.id,style:n,className:(r==null?void 0:r.className)||e},s.id))})};function ct({id:e,image:t,thumbnail:n,isStatic:r,x:o=0,y:s=0,children:i,onClick:a}){var l,u,p,f;return d.jsx(c.Fragment,{children:t.service?d.jsxs(c.Fragment,{children:[d.jsx(z.TileSet,{tiles:{id:t.service.id||t.service["@id"]||"unknown",height:t.height,width:t.width,imageService:t.service,thumbnail:n&&n.type==="fixed"?n:void 0},x:((l=t.target)==null?void 0:l.spatial.x)+o,y:((u=t.target)==null?void 0:u.spatial.y)+s,width:(p=t.target)==null?void 0:p.spatial.width,height:(f=t.target)==null?void 0:f.spatial.height,onClick:a}),i]},"service"):d.jsxs(c.Fragment,{children:[d.jsx("world-image",{onClick:a,uri:t.id,target:t.target.spatial,display:t.width&&t.height?{width:t.width,height:t.height}:void 0}),i]},"no-service")},e)}function ut(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function lt(e,t,n){const r=[];let o=null;const s=[];for(const i of t){const a=e.get(i.body);for(const l of a){const[u,{selector:p}]=ut(l),f=(u.type||"unknown").toLowerCase();if(f==="choice"){const g=e.get(u.items),m=n.length?n.map(h=>g.find(y=>y.id===h)).filter(Boolean):[g[0]];m.length===0&&m.push(g[0]),o={type:"single-choice",items:g.map(h=>({id:h.id,label:h.label,selected:m.indexOf(h)!==-1})),label:l.label},a.push(...m);continue}r.indexOf(f)===-1&&r.push(f),s.push({annotationId:i.id,type:f,resource:u,target:i.target,selector:p})}}return{types:r,items:s,choice:o}}function be(e,t){const{selector:n,source:r}=Ut.expandTarget(t);if(r.id!==e.id)return[null,r];const o={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}};return[n?n.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:n.temporal,spatial:o.spatial}:n:null,r]}const ft={makeChoice:()=>{}},J={type:"unknown"},P=e=>({type:"unknown",reason:e,annotations:{pages:[]}}),dt=(e,t)=>({type:"empty",width:e,height:t,annotations:{pages:[]},image:null,images:[]});function Mn(e,t){var r;const n=(r=e==null?void 0:e.iiif)==null?void 0:r.meta[t];return n?n.annotationPageManager:null}function An(e,t){return M(n=>{const r=[];if(!e)return r;const o=Object.keys(n.iiif.entities.AnnotationPage);for(const s of o)if(!t||t.indexOf(s)!==-1){const i=Mn(n,s);i&&i.views&&i.views[e]&&r.push(s)}return r},[e,t])}function pt({canvas:e,manifest:t,all:n,canvases:r}){const o=[];if(t)for(const s of t.annotations)o.indexOf(s.id)===-1&&o.push(s.id);if(n){if(r&&r.length)for(const s of r)for(const i of s.annotations)o.indexOf(i.id)===-1&&o.push(i.id)}else if(e)for(const s of e.annotations)o.indexOf(s.id)===-1&&o.push(s.id);return o}function Tn(e,t){var r;const n=(r=e==null?void 0:e.iiif)==null?void 0:r.meta[t];return n?n.annotationPageManager:null}function gt(e,t={}){const n=I(),r=B(),o=_(),s=ze(),i=c.useMemo(()=>pt({all:t.all,manifest:r,canvas:o,canvases:s}),[t.all,o,s,r]),a=An(e,t.all?void 0:i),l=c.useCallback(p=>{!e||n.setMetaValue([p,"annotationPageManager","views"],f=>f&&!f[e]?f:b(S({},f||{}),{[e]:!1}))},[e,n]),u=c.useCallback((p,f={})=>{if(!e)return;const g=n.getState(),m=[];if(f!=null&&f.deselectOthers){const h=Object.keys(g.iiif.entities.AnnotationPage);for(const y of h){const x=Tn(g,y);x&&x.views&&x.views[e]&&m.push(y)}}for(const h of m)l(h);n.setMetaValue([p,"annotationPageManager","views"],h=>h&&h[e]?h:b(S({},h||{}),{[e]:!0}))},[e,l,n]);return{availablePageIds:i,enabledPageIds:a,setPageEnabled:u,setPageDisabled:l}}function ht(e,t){return M((n,r)=>r.get(e.map(o=>({id:o,type:t}))),[e,t])}const mt=U.default.createContext(new N.ImageServiceLoader);function ie(){return c.useContext(mt)}function vt(){const e=ie(),[t,n]=c.useState({}),r=c.useRef(!1);return c.useEffect(()=>()=>{r.current=!0},[]),[c.useCallback((s,{height:i,width:a})=>{if(s){const l=s.id||s["@id"],u=e.loadServiceSync({id:l,width:s.width||a,height:s.height||i,source:s});u?s=u:t[l]||(r.current||n(p=>b(S({},p),{[l]:"loading"})),e.loadService({id:l,width:s.width||a,height:s.height||i}).then(()=>{r.current||n(p=>b(S({},p),{[l]:"done"}))}))}return s},[e,t]),t]}function oe(e={}){const t=_(e.canvasId?{id:e.canvasId}:void 0);return M((n,r)=>{if(!t)return[];const o=r.get(t.items),s=[];for(const i of o)s.push(...r.get(i.items));return s},[t])}function yt(e,t=[]){const n=I(),r=oe(),[o,s]=c.useState((e==null?void 0:e.defaultChoices)||[]),i=c.useMemo(()=>lt(n,r,o),[n,r,o,...t]),l={makeChoice:c.useCallback((u,{deselectOthers:p=!0,deselect:f=!1}={})=>{if(i.choice){if(i.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");s(g=>{if(f){const h=g.filter(y=>y!==u);if(h.length===0){const y=i.items[0].resource.id;return y?[y]:[]}return h}if(p)return[u];const m=[...g];if(m.length===0&&i.items.length){const h=i.items[0].resource.id;h&&m.push(h)}return g.indexOf(u)!==-1?g:[...g,u]})}},[i.choice])};return[i,l]}function xt(e,t,n){const r=[];for(const o of t.items){const s=o.resource&&o.resource.type==="SpecificResource"?o.resource.source:o.resource;if(!s.id)return P("No resource Identifier");let i;if(s.service){const h=N.getImageServices(s);h[0]&&(i=n(h[0],e))}const a={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},[l,u]=be(e,o.target);if(u.id!==e.id)continue;const p={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},f=o.resource.type==="SpecificResource"?V(o.resource):null,g=f&&f.selector&&(f.selector.type==="BoxSelector"||f.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:f.selector.spatial.x,y:f.selector.spatial.y,width:f.selector.spatial.width,height:f.selector.spatial.height}}:p;i&&!i.id&&(i.id=i["@id"]);const m={id:s.id,type:"Image",annotationId:o.annotationId,width:l?s.width:e.width,height:l?s.height:e.height,service:i,sizes:i&&i.sizes?i.sizes:s.width&&s.height?[{width:s.width,height:s.height}]:[],target:l&&l.type!=="PointSelector"?l:a,selector:g};r.push(m)}return{type:"images",image:r[0],images:r,choice:t.choice}}const On=["model/gltf-binary"];function jn(e,t){const r=t.items[0].resource;return r.format?On.indexOf(r.format)===-1?P(`3D format: ${r.format} is unsupported`):{type:"3d-model",model:r}:P("Unknown format")}function _n(e,t){var r;if(!e.duration)return P("No duration on canvas");if(t.items.length>1)return P("Only one audio source supported");const n=(r=t.items[0])==null?void 0:r.resource;return n?n.format?{type:"media",media:{annotationId:t.items[0].annotationId,duration:e.duration,url:n.id,type:"Sound",target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:n.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}},annotations:{pages:[]}}:P("Audio does not have format"):P("Unknown audio")}function Ln(e,t){var o;const n=t.items.filter(s=>s.type==="video");if(!e.duration)return P("No duration on canvas");if(n.length>1)return P("Only one video source supported");const r=(o=n[0])==null?void 0:o.resource;return r?r.format?{type:"media",media:{annotationId:t.items[0].annotationId,duration:e.duration,url:r.id,type:"Video",items:[],target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:r.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}},annotations:{pages:[]}}:P("Video does not have format"):P("Unknown video")}function St(e,t={},n){const r=e.language||n||"none";switch(e.type){case"TextualBody":{typeof e.value!="undefined"&&(t[r]=e.value);break}case"List":case"Composite":case"Choice":e.items&&e.items.forEach(o=>St(o,t,r))}return t}function Fn(e,t){const n=[];return t.items.forEach(r=>{if(r.resource){const[o]=be(e,r.target);n.push({annotationId:r.annotationId,text:St(r.resource),target:o})}}),{type:"textual-content",items:n}}function Ct(e){const t=B(),n=_(),r=I(),[o,s]=vt(),{enabledPageIds:i}=gt((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(n==null?void 0:n.id),{all:!1}),a=ht(i,"AnnotationPage"),l=(e==null?void 0:e.strategies)||["empty","images","media","textual-content","complex-timeline"],[u,p]=yt(e,[s]),f=c.useMemo(()=>{if(!n)return J;if(u.types.length===0)return l.indexOf("empty")!==-1?dt(n.width,n.height):J;if(u.types.length!==1)if(u.types.length===2&&u.types.indexOf("text")!==-1)u.types=u.types.filter(m=>m!=="text");else return l.indexOf("complex-timeline")===-1?P("Complex timeline not supported"):P("ComplexTimelineStrategy not yet supported");const g=u.types[0];return g==="image"?l.indexOf("images")===-1?P("Image not supported"):xt(n,u,o):g==="Model"||g==="model"?l.indexOf("3d-model")===-1?P("3D not supported"):jn(n,u):g==="textualbody"?l.indexOf("textual-content")===-1?P("Textual content not supported"):Fn(n,u):g==="sound"||g==="audio"?l.indexOf("media")===-1?P("Media not supported"):_n(n,u):g==="video"?l.indexOf("media")===-1?P("Media not supported"):Ln(n,u):J},[n,u,r,p.makeChoice]);return c.useMemo(()=>f.type==="unknown"?[f,ft]:[b(S({},f),{annotations:{pages:a}}),p],[f,a])}const bt=(e,t=[])=>{const n=I();c.useEffect(()=>{e(n)},[n,...t])};function Vn(e,t={}){const n=t.imageServiceLoader||new N.ImageServiceLoader;async function r(o,s,i,a=[],l){if(typeof o=="string")return{best:N.getFixedSizeFromImage(o),fallback:[],log:[]};const u=e.get(o);if(typeof u=="string")return{best:N.getFixedSizeFromImage(u),fallback:[],log:[]};switch(u.type){case"Annotation":{const p=u.body,f=e.get(p[0]);return l&&!f.width&&(f.width=l.width,f.height=l.height),await n.getThumbnailFromResource(f,s,i,a)}case"Canvas":{const p=u;if(p.thumbnail&&p.thumbnail.length){const f=e.get(p.thumbnail[0]),g=await n.getImageCandidates(f,i);g&&g.length&&a.push(...g)}return r(p.items[0],s,i,a,{width:p.width,height:p.height})}case"AnnotationPage":return r(u.items[0],s,i,a,l);case"Choice":return r(u.items[0],s,i,a,l);case"Collection":{const f=u.items[0];return r(f,s,i,a,l)}case"Manifest":{const f=u.items[0];return r(f,s,i,a,l)}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return l&&!u.width&&(u.width=l.width,u.height=l.height),n.getThumbnailFromResource(u,s,i,a);case"Service":case"Range":case"AnnotationCollection":case"CanvasReference":case"ContentResource":return{best:void 0,fallback:[],log:[]}}return{best:void 0,fallback:[],log:[]}}return{getBestThumbnailAtSize:r}}function Et(e,t,{canvasId:n,manifestId:r}={}){const o=I(),s=ie(),i=c.useMemo(()=>Vn(o,{imageServiceLoader:s}),[o,s]),[a,l]=c.useState(),u=B(r?{id:r}:void 0),p=_(n?{id:n}:void 0),f=p||u,g=c.useRef(!1);if(c.useEffect(()=>(g.current=!1,()=>{g.current=!0}),[]),!f)throw new Error("Must be called under a manifest or canvas context.");return bt(m=>{i.getBestThumbnailAtSize(f,e,t).then(h=>{h.best&&!g.current&&l(h.best)})},[f]),a}function kn(e){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:e}}function Nn(e,t){switch(t.type){case"FINISHED":return b(S({},e),{isFinished:!0,isPlaying:!1,playRequested:!1});case"PLAY_PAUSE":return b(S({},e),{isFinished:!1,isPlaying:!e.isPlaying});case"PLAY_REQUESTED":return b(S({},e),{isFinished:!1,playRequested:!0});case"PAUSE":return b(S({},e),{isPlaying:!1});case"PLAY":return b(S({},e),{isFinished:!1,playRequested:!1,isPlaying:!0});case"MUTE":return b(S({},e),{isMuted:!0});case"SET_VOLUME":return b(S({},e),{volume:t.volume,isMuted:t.volume===0});case"TOGGLE_MUTE":return b(S({},e),{isMuted:!e.isMuted});case"UNMUTE":return b(S({},e),{isMuted:!1})}return e}function wt(e){const t=Math.round(e);return`${Math.floor(t/60)}:${`${t%60}`.padStart(2,"0")}`}function Ee(e){const[t,n]=c.useReducer(Nn,kn(e.duration)),r=c.useRef(null),o=c.useRef(null),s=c.useRef(null),i=c.useRef(!1),a=c.useCallback(()=>{o.current&&r.current&&(o.current.innerHTML=wt(r.current.currentTime),s.current&&(s.current.style.width=`${r.current.currentTime/e.duration*100}%`),i.current!==r.current.muted&&(i.current=r.current.muted,n(r.current.muted?{type:"MUTE"}:{type:"UNMUTE"})))},[e.duration]),l=c.useCallback(()=>{r.current&&(n({type:"PLAY_REQUESTED"}),r.current.play().then(()=>{n({type:"PLAY"})}),a())},[a]),u=c.useCallback(()=>{r.current&&(r.current.duration>0&&r.current.paused?l():p())},[a]),p=c.useCallback(()=>{r.current&&(r.current.pause(),n({type:"PAUSE"}),a())},[a]),f=c.useCallback(()=>{r.current&&(r.current.muted=!r.current.muted,n(r.current.muted?{type:"MUTE"}:{type:"UNMUTE"}))},[]),g=c.useCallback(()=>{r.current&&(r.current.muted=!0,n({type:"MUTE"}))},[]),m=c.useCallback(()=>{r.current&&(r.current.muted=!1,n({type:"UNMUTE"}))},[]),h=c.useCallback(C=>{r.current&&(r.current.muted=!1,r.current.volume=C/100,n({type:"SET_VOLUME",volume:C}))},[]),y=c.useCallback(C=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(C*e.duration,e.duration)),a())},[]),x=c.useCallback(C=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(C,e.duration)),a())},[]);return c.useEffect(()=>{const C=setInterval(()=>{a()},350);return()=>clearInterval(C)},[a,e.duration]),c.useEffect(()=>{const C=()=>{n({type:"FINISHED"})},v=r.current;return v==null||v.addEventListener("ended",C),()=>v==null?void 0:v.removeEventListener("ended",C)},[]),[{element:r,currentTime:o,progress:s},t,{play:l,pause:p,playPause:u,mute:g,unmute:m,toggleMute:f,setVolume:h,setDurationPercent:y,setTime:x}]}const Pt=c.createContext(null),It=c.createContext(null),Rt=c.createContext(null);function Un(){const e=c.useContext(Pt);if(!e)throw new Error("Ctx not found");return e}function Dn(){const e=c.useContext(It);if(!e)throw new Error("Ctx not found");return e}function Bn(){const e=c.useContext(Rt);if(!e)throw new Error("Ctx not found");return e}function we({actions:e,state:t,children:n,currentTime:r,progress:o,element:s}){return d.jsx(Rt.Provider,{value:{currentTime:r,progress:o,element:s},children:d.jsx(It.Provider,{value:e,children:d.jsx(Pt.Provider,{value:t,children:n})})})}function Hn({media:e,children:t}){const[{element:n,currentTime:r,progress:o},s,i]=Ee({duration:e.duration});return d.jsx(d.Fragment,{children:d.jsx(H,{children:d.jsxs(we,{state:s,actions:i,currentTime:r,progress:o,element:n,children:[d.jsx("audio",{ref:n,src:e.url}),t]})})})}function qn({media:e,children:t}){const[{element:n,currentTime:r,progress:o},s,i]=Ee({duration:e.duration}),a="div";return d.jsxs(d.Fragment,{children:[d.jsxs(H,{overlay:!0,children:[d.jsx("style",{children:`
1
+ "use strict";var Vt=Object.defineProperty,kt=Object.defineProperties;var Nt=Object.getOwnPropertyDescriptors;var W=Object.getOwnPropertySymbols;var Ae=Object.prototype.hasOwnProperty,Re=Object.prototype.propertyIsEnumerable;var Ie=(e,t,n)=>t in e?Vt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,S=(e,t)=>{for(var n in t||(t={}))Ae.call(t,n)&&Ie(e,n,t[n]);if(W)for(var n of W(t))Re.call(t,n)&&Ie(e,n,t[n]);return e},b=(e,t)=>kt(e,Nt(t));var Me=(e,t)=>{var n={};for(var r in e)Ae.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&W)for(var r of W(e))t.indexOf(r)<0&&Re.call(e,r)&&(n[r]=e[r]);return n};Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var c=require("react"),z=require("@atlas-viewer/atlas"),d=require("react/jsx-runtime"),X=require("@iiif/vault"),R=require("typesafe-actions"),Te=require("react-dom/client"),Ut=require("@iiif/vault-helpers"),U=require("@atlas-viewer/iiif-image-api");function Dt(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}function Bt(e){if(e&&e.__esModule)return e;var t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});return e&&Object.keys(e).forEach(function(n){if(n!=="default"){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,Object.freeze(t)}var ae=Bt(c),D=Dt(c);function le(e,t){return le=Object.setPrototypeOf||function(r,o){return r.__proto__=o,r},le(e,t)}function Ht(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,le(e,t)}var qt=function(t,n){return t===void 0&&(t=[]),n===void 0&&(n=[]),t.length!==n.length||t.some(function(r,o){return!Object.is(r,n[o])})},Oe={error:null},$t=function(e){Ht(t,e);function t(){for(var r,o=arguments.length,s=new Array(o),i=0;i<o;i++)s[i]=arguments[i];return r=e.call.apply(e,[this].concat(s))||this,r.state=Oe,r.resetErrorBoundary=function(){for(var a,l=arguments.length,u=new Array(l),p=0;p<l;p++)u[p]=arguments[p];r.props.onReset==null||(a=r.props).onReset.apply(a,u),r.reset()},r}t.getDerivedStateFromError=function(o){return{error:o}};var n=t.prototype;return n.reset=function(){this.setState(Oe)},n.componentDidCatch=function(o,s){var i,a;(i=(a=this.props).onError)==null||i.call(a,o,s)},n.componentDidUpdate=function(o,s){var i=this.state.error,a=this.props.resetKeys;if(i!==null&&s.error!==null&&qt(o.resetKeys,a)){var l,u;(l=(u=this.props).onResetKeysChange)==null||l.call(u,o.resetKeys,a),this.reset()}},n.render=function(){var o=this.state.error,s=this.props,i=s.fallbackRender,a=s.FallbackComponent,l=s.fallback;if(o!==null){var u={error:o,resetErrorBoundary:this.resetErrorBoundary};if(ae.isValidElement(l))return l;if(typeof i=="function")return i(u);if(a)return ae.createElement(a,u);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},t}(ae.Component);const zt={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},ne=D.default.createContext(zt),_=()=>c.useContext(ne);function F({value:e,children:t}){const n=_(),r=c.useMemo(()=>S(S({},n),e),[e,n]);return d.jsx(ne.Provider,{value:r,children:t})}const Q=D.default.createContext({vault:null,setVaultInstance:e=>{}});function qe({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:o}){const[s,i]=c.useState(()=>e||(n?X.globalVault(t):t?new X.Vault(t):new X.Vault));return d.jsx(Q.Provider,{value:{vault:s,setVaultInstance:i},children:d.jsx(F,{value:r||{},children:o})})}const I=()=>{const{vault:e}=c.useContext(Q);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};function pe(e,{noCache:t=!1}={}){const n=typeof e=="string"?e:e.id,r=I(),[o,s]=c.useState(n),[i,a]=c.useState(void 0),l=c.useMemo(()=>r.get(n,{skipSelfReturn:!0})||void 0,[n,r]),[u,p]=c.useState(l);return c.useEffect(()=>{(async()=>{try{const f=l&&!t?l:await r.load(n),g=f?f.id||f["@id"]:null;f&&o!==g&&s(g),p(f)}catch(f){a(f)}})()},[n,t]),{isLoaded:!!u,id:o,requestId:n,error:i,resource:u,cached:!!(u&&u===l)}}function $e(e,t){const{id:n,isLoaded:r,error:o,resource:s,requestId:i,cached:a}=pe(e,t);return{id:n,isLoaded:r,error:o,manifest:s,requestId:i,cached:a}}function ze({manifest:e,children:t}){return d.jsx(F,{value:{manifest:e},children:t})}function ge({canvas:e,children:t}){return d.jsx(F,{value:{canvas:e},children:t})}function A(e,t=[]){const n=I(),[r,o]=c.useState(()=>e(n.getState(),n));return c.useEffect(()=>n.subscribe(s=>e(s,n),s=>{o(s)},!1),t),r}const G=D.default.createContext([]);function Ye(){const e=c.useContext(G);return A(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}function B(e={},t=[]){const{id:n,selector:r}=e,o=_();I();const s=n||o.manifest,i=A(a=>s?a.iiif.entities.Manifest[s]:void 0,[s]);return c.useMemo(()=>{if(!!i)return r?r(i):i},[i,r,...t])}function Qe({range:e,children:t}){return d.jsx(F,{value:{range:e},children:t})}function Ge(e,t){for(const n of t.items){if(n.type==="Canvas")return n;if(n.type==="Range"){const r=Ge(e,e.get(n));if(r)return r}}return null}function he(e,t){const n=[];for(const r of t.items)if(r.type==="Canvas"&&(r.id.indexOf("#")!==-1?n.push({id:r.id.split("#")[0],type:"Canvas"}):n.push(r)),r.type==="Range"&&n.push(...he(e,e.get(r))),r.type==="SpecificResource"){const o=typeof r.source=="string"?r.source:r.source.id;n.push({id:o,type:"Canvas"})}return n}function Yt(e,t,n){for(const r of t.structures){const o=ve(e,e.get(r),n);if(o)return o}return null}function ve(e,t,n){var r;for(const o of t.items){const s=(r=o.id)==null?void 0:r.split("#")[0];if(o.type==="SpecificResource"&&o.source===n||o.type==="Canvas"&&n===s)return t;if(o.type==="Range"){const i=ve(e,e.get(o),n);if(i)return i}}return null}function Qt(e,t,n,r=!1){const o=t.behavior,s=n?e.get(n):null;if(!s)return[];const i=s.behavior,a=r?!1:o.includes("paged"),l=a?!1:o.includes("continuous"),u=a||l?!1:o.includes("individuals"),p=i.includes("facing-pages"),f=i.includes("non-paged");if(p||f||u||r)return[{id:s.id,type:"Canvas"}];const[g,v]=me(e,t);if(l)return g;const h=g.findIndex(y=>y.id===n);if(h===-1)return[];for(const y of v)if(y.includes(h))return y.map(x=>g[x]);return[{id:s.id,type:"Canvas"}]}function me(e,t,{disablePaging:n}={}){const r=t.behavior,o=r.includes("paged"),s=o?!1:r.includes("continuous"),i=o||s?!1:r.includes("individuals"),a=t.type==="Manifest"?t.items:he(e,t);if(s)return[a,[a.map((f,g)=>g)]];if(i||!o||n)return[a,a.map((f,g)=>[g])];const l=[];let u=[];const p=()=>{u.length&&(l.push([...u]),u=[])};for(let f=0;f<a.length;f++){const g=e.get(a[f]);if(f===0||g.behavior.includes("facing-pages")){p(),l.push([f]);continue}g.behavior.includes("non-paged")||(u.push(f),u.length>1&&p())}return u.length&&p(),[a,l]}function Ke(e={},t=[]){const{id:n,selector:r}=e,o=_(),s=n||o.range,i=A(a=>s?a.iiif.entities.Range[s]:void 0,[s]);return c.useMemo(()=>{if(!!i)return r?r(i):i},[i,r,...t])}function We({startCanvas:e,disablePaging:t}){var h;const n=I(),r=B(),o=Ke(),[s,i]=c.useState(void 0),a=o||r;if(!a)throw new Error("Nothing selected");const[l,u]=c.useMemo(()=>me(n,a,{disablePaging:t}),[n,a]),p=c.useCallback(y=>{const x=u.findIndex(C=>C.includes(y));i(x===-1?0:x)},[l,u]),f=c.useCallback(y=>{const x=l.findIndex(C=>C.id===y);x!==-1?p(x):i(0)},[l,u]),g=c.useCallback(()=>{i(y=>y>=u.length?y:y+1)},[u]),v=c.useCallback(()=>{i(y=>y<=0?0:y-1)},[u]);return typeof s=="undefined"&&(e?f(e):i(0)),{visibleItems:((h=u[s])==null?void 0:h.map(y=>l[y].id))||[],cursor:s,items:l,sequence:u,setSequenceIndex:i,setCanvasIndex:p,setCanvasId:f,next:g,previous:v}}const $=()=>{},K=c.createContext({setCurrentCanvasId:$,setCurrentCanvasIndex:$,nextCanvas:$,previousCanvas:$,items:[],sequence:[],setSequenceIndex:$,currentSequenceIndex:0});function Xe(e){const t=B(),{cursor:n,visibleItems:r,next:o,sequence:s,items:i,setCanvasIndex:a,setCanvasId:l,previous:u,setSequenceIndex:p}=We({startCanvas:e.startCanvas,disablePaging:e.pagingEnabled===!1}),f=c.useMemo(()=>({sequence:s,items:i,setCurrentCanvasId:l,nextCanvas:o,previousCanvas:u,totalCanvases:i.length,setCurrentCanvasIndex:a,setSequenceIndex:p,currentSequenceIndex:n}),[s,i,l,o,u,i,a,p,n]);return t?d.jsx(K.Provider,{value:f,children:d.jsx(G.Provider,{value:r,children:d.jsx(ge,{canvas:r[0],children:e.children})})}):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),d.jsx("div",{children:"Sorry, something went wrong."}))}function Gt(e){const t=$e(e.manifest);if(!t)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),d.jsx("div",{children:"Sorry, something went wrong."});if(!t.isLoaded)return d.jsx("div",{children:"Loading..."});const n=d.jsx(Xe,b(S({},e),{children:e.children}));return d.jsx(ze,{manifest:t.id,children:e.rangeId?d.jsx(Qe,{range:e.rangeId,children:n}):n})}function Kt(){return c.useContext(K)}function Je(){return{VaultContext:c.useContext(Q),ResourceContext:c.useContext(ne),SimpleViewerReactContext:c.useContext(K),VisibleCanvasReactContext:c.useContext(G)}}function Ze(e){return d.jsx(qe,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext,children:d.jsx(G.Provider,{value:e.bridge.VisibleCanvasReactContext,children:d.jsx(K.Provider,{value:e.bridge.SimpleViewerReactContext,children:e.children})})})}const Wt="@iiif/IMPORT_ENTITIES",Xt="@iiif/MODIFY_ENTITY_FIELD",Jt="@iiif/REORDER_ENTITY_FIELD",Zt="@iiif/ADD_REFERENCE",en="@iiif/REMOVE_REFERENCE",tn=R.createAction(Wt)(),nn=R.createAction(Xt)(),rn=R.createAction(Jt)(),on=R.createAction(Zt)(),sn=R.createAction(en)(),ce={importEntities:tn,modifyEntityField:nn,reorderEntityField:rn,addReference:on,removeReference:sn},an="@iiif/ADD_MAPPING",cn="@iiif/ADD_MAPPINGS";R.createAction(an)();R.createAction(cn)();const un="@iiif/SET_META_VALUE",ln="@iiif/SET_META_VALUE_DYNAMIC",fn="@iiif/UNSET_META_VALUE";R.createAction(un)();R.createAction(ln)();R.createAction(fn)();const dn="@iiif/REQUEST_RESOURCE",pn="@iiif/REQUEST_ERROR",gn="@iiif/REQUEST_MISMATCH",hn="@iiif/REQUEST_COMPLETE",vn="@iiif/REQUEST_OFFLINE_RESOURCE";R.createAction(dn)();R.createAction(pn)();R.createAction(gn)();R.createAction(hn)();R.createAction(vn)();const mn="@iiif/BATCH",yn="@iiif/BATCH_IMPORT";R.createAction(mn)();R.createAction(yn)();function et(){const t=I().getStore();return c.useMemo(()=>n=>t.dispatch(n),[t])}function je(e){return typeof e!="string"&&e&&e.bindToVault}function tt(){const e=I(),t=c.useRef([]),n=et(),r=c.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);c.useLayoutEffect(()=>{const a={id:r,type:"AnnotationPage",behavior:[],motivation:null,label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[]};n(ce.importEntities({entities:{AnnotationPage:{[a.id]:a}}}))},[r]);const o=A(a=>r?a.iiif.entities.AnnotationPage[r]:null,[r]),s=c.useCallback((a,l)=>{if(r){if(je(a)){const f=a;f.__vault||f.bindToVault(e),a=typeof f.source=="string"?f.source:f.source.id,t.current[a]=f}else typeof a!="string"&&(a=a.id);const u=e.get({id:r,type:"AnnotationPage"}),p=e.get({id:a,type:"Annotation"});u&&p&&(u.items.find(f=>f.id===p.id)||n(ce.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"},index:l})))}},[r]),i=c.useCallback(a=>{r&&(je(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:r,type:"AnnotationPage"})&&n(ce.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"}})))},[r]);return[o,{addAnnotation:s,removeAnnotation:i}]}const nt=c.createContext(null);function rt(){const e=c.useContext(nt);return[e.fullPage,{addAnnotation:e.addAnnotation,removeAnnotation:e.removeAnnotation}]}function it({children:e}){const[t,{addAnnotation:n,removeAnnotation:r}]=tt();return d.jsx(nt.Provider,{value:c.useMemo(()=>({fullPage:t,addAnnotation:n,removeAnnotation:r}),[t]),children:e})}function xn({width:e,style:t,height:n}){return d.jsx("div",{style:b(S({width:e,height:n,minHeight:500},t||{}),{background:"#f9f9f9"}),children:"Unknown error"})}const re=c.createContext(null);function ot(){return c.useContext(re)}const ye=D.default.createContext(null),xe=D.default.createContext(null);function H({children:e,overlay:t}){const n=c.useContext(t?xe:ye),r=ot();return c.useLayoutEffect(()=>{if(n)try{n.render(d.jsx(re.Provider,{value:r,children:e}))}catch{}},[e,r]),null}function Sn(o){var s=o,{children:e,errorFallback:t,outerContainerProps:n={}}=s,r=Me(s,["children","errorFallback","outerContainerProps"]);const i=c.useRef(null),[a,l]=c.useState(),[u,p]=c.useState(),f=c.useRef(null),[g,v]=c.useState(),h=Je(),y=t||xn;return c.useLayoutEffect(()=>{const x={};if(i.current){const C=document.createElement("div");i.current.appendChild(C),x.portal=Te.createRoot(C),l(x.portal)}if(f.current){const C=document.createElement("div");f.current.appendChild(C),x.overlayPortal=Te.createRoot(C),v(x.overlayPortal)}return()=>{l(null),v(null),setTimeout(()=>{x.portal&&x.portal.unmount(),x.overlayPortal&&x.overlayPortal.unmount()},0)}},[]),d.jsxs($t,{fallbackRender:()=>d.jsx(y,S({},r)),children:[d.jsx(z.AtlasAuto,b(S({},r),{containerProps:S({style:{position:"relative"}},r.containerProps||{}),htmlChildren:d.jsx("div",{ref:f}),onCreated:x=>{p(x),r.onCreated&&r.onCreated(x)},children:d.jsx(re.Provider,{value:u,children:d.jsx(ye.Provider,{value:a,children:d.jsx(xe.Provider,{value:g,children:d.jsx(Ze,{bridge:h,children:d.jsx(it,{children:e})})})})})})),d.jsx("div",{ref:i})]})}function st(e){return{addEventListener(t,n,r,o){if(!!t)return e.setMetaValue([t.id,"eventManager",n],s=>{const i=s||[];for(const a of i)if(a.callback===r)return i;return[...i,{callback:r,scope:o}]}),r},removeEventListener(t,n,r){!t||e.setMetaValue([t.id,"eventManager",n],o=>(o||[]).filter(s=>s.callback!==r))},getListenersAsProps(t,n){const r=typeof t=="string"?{id:t}:t;if(!r||!r.id)return{};const o=e.getResourceMeta(r.id,"eventManager"),s={};if(o&&r)for(const i of Object.keys(o))s[i]=a=>{const l=e.get(r);for(const{callback:u,scope:p}of o[i]||[])(!p||n&&p.indexOf(n)!==-1)&&u(a,l)};return s}}}function Se(e,t){const n=I(),r=c.useMemo(()=>st(n),[n]),o=A(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return c.useMemo(()=>e?r.getListenersAsProps(e,t):{},[o,e,n,t])}function Ce(e){return{applyStyles(t,n,r){const o=typeof t=="string"?t:t.id;return e.setMetaValue([o,"styles",n],r)},getAppliedStyles(t){const n=typeof t=="string"?t:t.id;return e.getResourceMeta(n,"styles")}}}function Y(e,t){const n=I(),r=c.useMemo(()=>Ce(n),[n]);return A(()=>{if(!e)return null;const o=r.getAppliedStyles(e.id);return o?t?o[t]:o:void 0},[e,t])}var Cn=Object.defineProperty,bn=Object.defineProperties,En=Object.getOwnPropertyDescriptors,_e=Object.getOwnPropertySymbols,Pn=Object.prototype.hasOwnProperty,wn=Object.prototype.propertyIsEnumerable,Le=(e,t,n)=>t in e?Cn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Fe=(e,t)=>{for(var n in t||(t={}))Pn.call(t,n)&&Le(e,n,t[n]);if(_e)for(var n of _e(t))wn.call(t,n)&&Le(e,n,t[n]);return e},Ve=(e,t)=>bn(e,En(t));const In=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,An=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function Z(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:r,selectors:o}=Z(n);return r&&(t.selector||(t.selector=r),t.selectors.push(...o)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,n]=e.split("#");return n?Z({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=In.exec(e.value);if(t){const r={type:"BoxSelector",spatial:{unit:t[2]==="percent:"||t[2]==="pct:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:r,selectors:[r]}}const n=e.value.match(An);if(n){const r={type:"TemporalSelector",temporal:{startTime:n[4]?parseFloat(n[4]):0,endTime:n[7]?parseFloat(n[7]):void 0}};return{selector:r,selectors:[r]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}function k(e,t={}){if(Array.isArray(e))return k(e[0]);if(typeof e=="string"){const[n,r]=e.split("#");return r?k({type:"SpecificResource",source:{id:n,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return k(e.items[0]);if(e.type==="SpecificResource"){e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]);const{selector:n,selectors:r}=e.selector?Z(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:n,selectors:r}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[n,r]=e.id.split("#");return r?k({type:"SpecificResource",source:Ve(Fe({},e),{id:n}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:Ve(Fe({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function be(e={},t=[]){const{id:n,selector:r}=e,o=_(),s=I(),i=n||o.annotation,a=A(u=>i?u.iiif.entities.Annotation[i]:void 0,[i]),l=A(u=>a&&a.body?a.body.map(p=>p?u.iiif.entities[p.type][p.id]:null).filter(Boolean):[],[a]);return c.useMemo(()=>{if(!a)return;const u=b(S({},a),{body:l,target:k(a.target,{typeMap:s.getState().iiif.mapping})});return r?r(u):u},[a,r,l,...t])}function L(e={},t=[]){const{id:n,selector:r}=e,o=_(),s=n||o.canvas,i=A(a=>s?a.iiif.entities.Canvas[s]:void 0,[s]);return c.useMemo(()=>{if(!!i)return r?r(i):i},[i,r,...t])}const at=({id:e,style:t,className:n,interactive:r})=>{const o=be({id:e}),s=Y(o,"atlas"),i=Y(o,"html"),a=Se(o,["atlas"]),l=L(),u=c.useMemo(()=>z.mergeStyles(t,s),[t,s]);return l&&o&&o.target&&o.target.selector&&o.target.selector.type==="BoxSelector"&&o.target.source&&o.target.source.id===l.id?d.jsx(z.RegionHighlight,S({id:o.id,isEditing:!0,region:o.target.selector.spatial,style:u,className:(i==null?void 0:i.className)||n,interactive:!!((i==null?void 0:i.href)||r),href:(i==null?void 0:i.href)||null,title:(i==null?void 0:i.title)||null,hrefTarget:(i==null?void 0:i.target)||null},a)):null},fe=({className:e,page:t})=>{var o;const n=Y(t,"atlas"),r=Y(t,"html");return A(s=>t.id?s.iiif.entities.AnnotationPage[t.id]:null,[]),d.jsx(c.Fragment,{children:(o=t.items)==null?void 0:o.map(s=>d.jsx(at,{id:s.id,style:n,className:(r==null?void 0:r.className)||e},s.id))})};function ct({id:e,image:t,thumbnail:n,isStatic:r,x:o=0,y:s=0,children:i,onClick:a}){var l,u,p,f;return d.jsx(c.Fragment,{children:t.service?d.jsxs(c.Fragment,{children:[d.jsx(z.TileSet,{tiles:{id:t.service.id||t.service["@id"]||"unknown",height:t.height,width:t.width,imageService:t.service,thumbnail:n&&n.type==="fixed"?n:void 0},x:((l=t.target)==null?void 0:l.spatial.x)+o,y:((u=t.target)==null?void 0:u.spatial.y)+s,width:(p=t.target)==null?void 0:p.spatial.width,height:(f=t.target)==null?void 0:f.spatial.height,onClick:a}),i]},"service"):d.jsxs(c.Fragment,{children:[d.jsx("world-image",{onClick:a,uri:t.id,target:t.target.spatial,display:t.width&&t.height?{width:t.width,height:t.height}:void 0}),i]},"no-service")},e)}function ut(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function lt(e,t,n){const r=[];let o=null;const s=[];for(const i of t){const a=e.get(i.body,{skipSelfReturn:!1});for(const l of a){if(!l)continue;const[u,{selector:p}]=ut(l),f=(u.type||"unknown").toLowerCase();if(f==="choice"){const g=e.get(u.items),v=n.length?n.map(h=>g.find(y=>y.id===h)).filter(Boolean):[g[0]];v.length===0&&v.push(g[0]),o={type:"single-choice",items:g.map(h=>({id:h.id,label:h.label,selected:v.indexOf(h)!==-1})),label:l.label},a.push(...v);continue}r.indexOf(f)===-1&&r.push(f),s.push({annotationId:i.id,type:f,resource:u,target:i.target,selector:p})}}return{types:r,items:s,choice:o}}function Ee(e,t){const{selector:n,source:r}=Ut.expandTarget(t);if(r.id!==e.id)return[null,r];const o={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}};return[n?n.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:n.temporal,spatial:o.spatial}:n:null,r]}const ft={makeChoice:()=>{}},J={type:"unknown"},w=e=>({type:"unknown",reason:e,annotations:{pages:[]}}),dt=(e,t)=>({type:"empty",width:e,height:t,annotations:{pages:[]},image:null,images:[]});function Rn(e,t){var r;const n=(r=e==null?void 0:e.iiif)==null?void 0:r.meta[t];return n?n.annotationPageManager:null}function Mn(e,t){return A(n=>{const r=[];if(!e)return r;const o=Object.keys(n.iiif.entities.AnnotationPage);for(const s of o)if(!t||t.indexOf(s)!==-1){const i=Rn(n,s);i&&i.views&&i.views[e]&&r.push(s)}return r},[e,t])}function pt({canvas:e,manifest:t,all:n,canvases:r}){const o=[];if(t)for(const s of t.annotations)o.indexOf(s.id)===-1&&o.push(s.id);if(n){if(r&&r.length)for(const s of r)for(const i of s.annotations)o.indexOf(i.id)===-1&&o.push(i.id)}else if(e)for(const s of e.annotations)o.indexOf(s.id)===-1&&o.push(s.id);return o}function Tn(e,t){var r;const n=(r=e==null?void 0:e.iiif)==null?void 0:r.meta[t];return n?n.annotationPageManager:null}function gt(e,t={}){const n=I(),r=B(),o=L(),s=Ye(),i=c.useMemo(()=>pt({all:t.all,manifest:r,canvas:o,canvases:s}),[t.all,o,s,r]),a=Mn(e,t.all?void 0:i),l=c.useCallback(p=>{!e||n.setMetaValue([p,"annotationPageManager","views"],f=>f&&!f[e]?f:b(S({},f||{}),{[e]:!1}))},[e,n]),u=c.useCallback((p,f={})=>{if(!e)return;const g=n.getState(),v=[];if(f!=null&&f.deselectOthers){const h=Object.keys(g.iiif.entities.AnnotationPage);for(const y of h){const x=Tn(g,y);x&&x.views&&x.views[e]&&v.push(y)}}for(const h of v)l(h);n.setMetaValue([p,"annotationPageManager","views"],h=>h&&h[e]?h:b(S({},h||{}),{[e]:!0}))},[e,l,n]);return{availablePageIds:i,enabledPageIds:a,setPageEnabled:u,setPageDisabled:l}}function ht(e,t){return A((n,r)=>r.get(e.map(o=>({id:o,type:t}))),[e,t])}const vt=D.default.createContext(new U.ImageServiceLoader);function ie(){return c.useContext(vt)}function mt(){const e=ie(),[t,n]=c.useState({}),r=c.useRef(!1);return c.useEffect(()=>()=>{r.current=!0},[]),[c.useCallback((s,{height:i,width:a})=>{if(s){const l=s.id||s["@id"],u=e.loadServiceSync({id:l,width:s.width||a,height:s.height||i,source:s});u?s=u:t[l]||(r.current||n(p=>b(S({},p),{[l]:"loading"})),e.loadService({id:l,width:s.width||a,height:s.height||i}).then(()=>{r.current||n(p=>b(S({},p),{[l]:"done"}))}))}return s},[e,t]),t]}function oe(e={}){const t=be(),n=L(e.canvasId?{id:e.canvasId}:void 0);return A((r,o)=>{if(!n)return[];if(t&&e.enableSingleAnnotation)return[t];const s=o.get(n.items),i=[];for(const a of s)i.push(...o.get(a.items));return i},[n])}function yt(e,t=[]){const n=I(),r=oe({enableSingleAnnotation:e==null?void 0:e.enableSingleAnnotation}),[o,s]=c.useState((e==null?void 0:e.defaultChoices)||[]),i=c.useMemo(()=>lt(n,r,o),[n,r,o,...t]),l={makeChoice:c.useCallback((u,{deselectOthers:p=!0,deselect:f=!1}={})=>{if(i.choice){if(i.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");s(g=>{if(f){const h=g.filter(y=>y!==u);if(h.length===0){const y=i.items[0].resource.id;return y?[y]:[]}return h}if(p)return[u];const v=[...g];if(v.length===0&&i.items.length){const h=i.items[0].resource.id;h&&v.push(h)}return g.indexOf(u)!==-1?g:[...g,u]})}},[i.choice])};return[i,l]}function xt(e,t,n){const r=[];for(const o of t.items){const s=o.resource&&o.resource.type==="SpecificResource"?o.resource.source:o.resource;if(!s.id)return w("No resource Identifier");let i;if(s.service){const h=U.getImageServices(s);h[0]&&(i=n(h[0],e))}const a={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},[l,u]=Ee(e,o.target);if(u.id!==e.id)continue;const p={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},f=o.resource.type==="SpecificResource"?k(o.resource):null,g=f&&f.selector&&(f.selector.type==="BoxSelector"||f.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:f.selector.spatial.x,y:f.selector.spatial.y,width:f.selector.spatial.width,height:f.selector.spatial.height}}:p;i&&!i.id&&(i.id=i["@id"]);const v={id:s.id,type:"Image",annotationId:o.annotationId,width:l?s.width:e.width,height:l?s.height:e.height,service:i,sizes:i&&i.sizes?i.sizes:s.width&&s.height?[{width:s.width,height:s.height}]:[],target:l&&l.type!=="PointSelector"?l:a,selector:g};r.push(v)}return{type:"images",image:r[0],images:r,choice:t.choice}}const On=["model/gltf-binary"];function jn(e,t){const r=t.items[0].resource;return r.format?On.indexOf(r.format)===-1?w(`3D format: ${r.format} is unsupported`):{type:"3d-model",model:r}:w("Unknown format")}function _n(e,t){var r;if(!e.duration)return w("No duration on canvas");if(t.items.length>1)return w("Only one audio source supported");const n=(r=t.items[0])==null?void 0:r.resource;return n?n.format?{type:"media",media:{annotationId:t.items[0].annotationId,duration:e.duration,url:n.id,type:"Sound",target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:n.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}},annotations:{pages:[]}}:w("Audio does not have format"):w("Unknown audio")}function Ln(e,t){var o;const n=t.items.filter(s=>s.type==="video");if(!e.duration)return w("No duration on canvas");if(n.length>1)return w("Only one video source supported");const r=(o=n[0])==null?void 0:o.resource;return r?r.format?{type:"media",media:{annotationId:t.items[0].annotationId,duration:e.duration,url:r.id,type:"Video",items:[],target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:r.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}},annotations:{pages:[]}}:w("Video does not have format"):w("Unknown video")}function St(e,t={},n){const r=e.language||n||"none";switch(e.type){case"TextualBody":{typeof e.value!="undefined"&&(t[r]=e.value);break}case"List":case"Composite":case"Choice":e.items&&e.items.forEach(o=>St(o,t,r))}return t}function Fn(e,t){const n=[];return t.items.forEach(r=>{if(r.resource){const[o]=Ee(e,r.target);n.push({annotationId:r.annotationId,text:St(r.resource),target:o})}}),{type:"textual-content",items:n}}function Ct(e){const t=B(),n=L(),r=I(),[o,s]=mt(),{enabledPageIds:i}=gt((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(n==null?void 0:n.id),{all:!1}),a=ht(i,"AnnotationPage"),l=(e==null?void 0:e.strategies)||["empty","images","media","textual-content","complex-timeline"],[u,p]=yt(e,[s]),f=c.useMemo(()=>{if(!n)return J;if(u.types.length===0)return l.indexOf("empty")!==-1?dt(n.width,n.height):J;if(u.types.length!==1)if(u.types.length===2&&u.types.indexOf("text")!==-1)u.types=u.types.filter(v=>v!=="text");else return l.indexOf("complex-timeline")===-1?w("Complex timeline not supported"):w("ComplexTimelineStrategy not yet supported");const g=u.types[0];return g==="image"?l.indexOf("images")===-1?w("Image not supported"):xt(n,u,o):g==="Model"||g==="model"?l.indexOf("3d-model")===-1?w("3D not supported"):jn(n,u):g==="textualbody"?l.indexOf("textual-content")===-1?w("Textual content not supported"):Fn(n,u):g==="sound"||g==="audio"?l.indexOf("media")===-1?w("Media not supported"):_n(n,u):g==="video"?l.indexOf("media")===-1?w("Media not supported"):Ln(n,u):J},[n,u,r,p.makeChoice]);return c.useMemo(()=>f.type==="unknown"?[f,ft]:[b(S({},f),{annotations:{pages:a}}),p],[f,a])}const bt=(e,t=[])=>{const n=I();c.useEffect(()=>{e(n)},[n,...t])};function Vn(e,t={}){const n=t.imageServiceLoader||new U.ImageServiceLoader;async function r(o,s,i,a=[],l){if(typeof o=="string")return{best:U.getFixedSizeFromImage(o),fallback:[],log:[]};const u=e.get(o);if(typeof u=="string")return{best:U.getFixedSizeFromImage(u),fallback:[],log:[]};switch(u.type){case"Annotation":{const p=u.body,f=e.get(p[0]);return l&&!f.width&&(f.width=l.width,f.height=l.height),await n.getThumbnailFromResource(f,s,i,a)}case"Canvas":{const p=u;if(p.thumbnail&&p.thumbnail.length){const f=e.get(p.thumbnail[0]),g=await n.getImageCandidates(f,i);g&&g.length&&a.push(...g)}return r(p.items[0],s,i,a,{width:p.width,height:p.height})}case"AnnotationPage":return r(u.items[0],s,i,a,l);case"Choice":return r(u.items[0],s,i,a,l);case"Collection":{const f=u.items[0];return r(f,s,i,a,l)}case"Manifest":{const f=u.items[0];return r(f,s,i,a,l)}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return l&&!u.width&&(u.width=l.width,u.height=l.height),n.getThumbnailFromResource(u,s,i,a);case"Service":case"Range":case"AnnotationCollection":case"CanvasReference":case"ContentResource":return{best:void 0,fallback:[],log:[]}}return{best:void 0,fallback:[],log:[]}}return{getBestThumbnailAtSize:r}}function Et(e,t,{canvasId:n,manifestId:r}={}){const o=I(),s=ie(),i=c.useMemo(()=>Vn(o,{imageServiceLoader:s}),[o,s]),[a,l]=c.useState(),u=B(r?{id:r}:void 0),p=L(n?{id:n}:void 0),f=p||u,g=c.useRef(!1);if(c.useEffect(()=>(g.current=!1,()=>{g.current=!0}),[]),!f)throw new Error("Must be called under a manifest or canvas context.");return bt(v=>{i.getBestThumbnailAtSize(f,e,t).then(h=>{h.best&&!g.current&&l(h.best)})},[f]),a}function kn(e){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:e}}function Nn(e,t){switch(t.type){case"FINISHED":return b(S({},e),{isFinished:!0,isPlaying:!1,playRequested:!1});case"PLAY_PAUSE":return b(S({},e),{isFinished:!1,isPlaying:!e.isPlaying});case"PLAY_REQUESTED":return b(S({},e),{isFinished:!1,playRequested:!0});case"PAUSE":return b(S({},e),{isPlaying:!1});case"PLAY":return b(S({},e),{isFinished:!1,playRequested:!1,isPlaying:!0});case"MUTE":return b(S({},e),{isMuted:!0});case"SET_VOLUME":return b(S({},e),{volume:t.volume,isMuted:t.volume===0});case"TOGGLE_MUTE":return b(S({},e),{isMuted:!e.isMuted});case"UNMUTE":return b(S({},e),{isMuted:!1})}return e}function Pt(e){const t=Math.round(e);return`${Math.floor(t/60)}:${`${t%60}`.padStart(2,"0")}`}function Pe(e){const[t,n]=c.useReducer(Nn,kn(e.duration)),r=c.useRef(null),o=c.useRef(null),s=c.useRef(null),i=c.useRef(!1),a=c.useCallback(()=>{o.current&&r.current&&(o.current.innerHTML=Pt(r.current.currentTime),s.current&&(s.current.style.width=`${r.current.currentTime/e.duration*100}%`),i.current!==r.current.muted&&(i.current=r.current.muted,n(r.current.muted?{type:"MUTE"}:{type:"UNMUTE"})))},[e.duration]),l=c.useCallback(()=>{r.current&&(n({type:"PLAY_REQUESTED"}),r.current.play().then(()=>{n({type:"PLAY"})}),a())},[a]),u=c.useCallback(()=>{r.current&&(r.current.duration>0&&r.current.paused?l():p())},[a]),p=c.useCallback(()=>{r.current&&(r.current.pause(),n({type:"PAUSE"}),a())},[a]),f=c.useCallback(()=>{r.current&&(r.current.muted=!r.current.muted,n(r.current.muted?{type:"MUTE"}:{type:"UNMUTE"}))},[]),g=c.useCallback(()=>{r.current&&(r.current.muted=!0,n({type:"MUTE"}))},[]),v=c.useCallback(()=>{r.current&&(r.current.muted=!1,n({type:"UNMUTE"}))},[]),h=c.useCallback(C=>{r.current&&(r.current.muted=!1,r.current.volume=C/100,n({type:"SET_VOLUME",volume:C}))},[]),y=c.useCallback(C=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(C*e.duration,e.duration)),a())},[]),x=c.useCallback(C=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(C,e.duration)),a())},[]);return c.useEffect(()=>{const C=setInterval(()=>{a()},350);return()=>clearInterval(C)},[a,e.duration]),c.useEffect(()=>{const C=()=>{n({type:"FINISHED"})},m=r.current;return m==null||m.addEventListener("ended",C),()=>m==null?void 0:m.removeEventListener("ended",C)},[]),[{element:r,currentTime:o,progress:s},t,{play:l,pause:p,playPause:u,mute:g,unmute:v,toggleMute:f,setVolume:h,setDurationPercent:y,setTime:x}]}const wt=c.createContext(null),It=c.createContext(null),At=c.createContext(null);function Un(){const e=c.useContext(wt);if(!e)throw new Error("Ctx not found");return e}function Dn(){const e=c.useContext(It);if(!e)throw new Error("Ctx not found");return e}function Bn(){const e=c.useContext(At);if(!e)throw new Error("Ctx not found");return e}function we({actions:e,state:t,children:n,currentTime:r,progress:o,element:s}){return d.jsx(At.Provider,{value:{currentTime:r,progress:o,element:s},children:d.jsx(It.Provider,{value:e,children:d.jsx(wt.Provider,{value:t,children:n})})})}function Hn({media:e,children:t}){const[{element:n,currentTime:r,progress:o},s,i]=Pe({duration:e.duration});return d.jsx(d.Fragment,{children:d.jsx(H,{children:d.jsxs(we,{state:s,actions:i,currentTime:r,progress:o,element:n,children:[d.jsx("audio",{ref:n,src:e.url}),t]})})})}function qn({media:e,children:t}){const[{element:n,currentTime:r,progress:o},s,i]=Pe({duration:e.duration}),a="div";return d.jsxs(d.Fragment,{children:[d.jsxs(H,{overlay:!0,children:[d.jsx("style",{children:`
2
2
  .video-container {
3
3
  position: absolute;
4
4
  top: 0;
@@ -24,7 +24,7 @@
24
24
  justify-content: center;
25
25
  pointer-events: visible;
26
26
  }
27
- `}),d.jsx("div",{className:"model-container",children:d.jsx("model-viewer",{"interaction-prompt":"none",style:{width:"100%",height:"100%"},"camera-controls":"","ar-status":"not-presenting",src:e.id})})]})}function Mt({style:e}){const t=_();return!t||!t.height||!t.width?null:d.jsx("box",{interactive:!1,target:{x:0,y:0,width:t.width,height:t.height},style:e})}var zn=Object.defineProperty,Yn=Object.defineProperties,Qn=Object.getOwnPropertyDescriptors,ee=Object.getOwnPropertySymbols,At=Object.prototype.hasOwnProperty,Tt=Object.prototype.propertyIsEnumerable,Ve=(e,t,n)=>t in e?zn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,k=(e,t)=>{for(var n in t||(t={}))At.call(t,n)&&Ve(e,n,t[n]);if(ee)for(var n of ee(t))Tt.call(t,n)&&Ve(e,n,t[n]);return e},te=(e,t)=>Yn(e,Qn(t)),Ot=(e,t)=>{var n={};for(var r in e)At.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&ee)for(var r of ee(e))t.indexOf(r)<0&&Tt.call(e,r)&&(n[r]=e[r]);return n};function Gn(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Kn(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function ke(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function Wn(e,t,n){return t&&ke(e.prototype,t),n&&ke(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}var Xn={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},Jn,Zn=U.default.createContext();function er(){return Xn}var tr=function(){function e(){Kn(this,e),this.usedNamespaces={}}return Wn(e,[{key:"addUsedNamespaces",value:function(n){var r=this;n.forEach(function(o){r.usedNamespaces[o]||(r.usedNamespaces[o]=!0)})}},{key:"getUsedNamespaces",value:function(){return Object.keys(this.usedNamespaces)}}]),e}();function nr(){return Jn}function rr(){if(console&&console.warn){for(var e,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];typeof n[0]=="string"&&(n[0]="react-i18next:: ".concat(n[0])),(e=console).warn.apply(e,n)}}var Ne={};function de(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];typeof t[0]=="string"&&Ne[t[0]]||(typeof t[0]=="string"&&(Ne[t[0]]=new Date),rr.apply(void 0,t))}function Ue(e,t,n){e.loadNamespaces(t,function(){if(e.isInitialized)n();else{var r=function o(){setTimeout(function(){e.off("initialized",o)},0),n()};e.on("initialized",r)}})}function ir(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(!t.languages||!t.languages.length)return de("i18n.languages were undefined or empty",t.languages),!0;var r=t.languages[0],o=t.options?t.options.fallbackLng:!1,s=t.languages[t.languages.length-1];if(r.toLowerCase()==="cimode")return!0;var i=function(l,u){var p=t.services.backendConnector.state["".concat(l,"|").concat(u)];return p===-1||p===2};return n.bindI18n&&n.bindI18n.indexOf("languageChanging")>-1&&t.services.backendConnector.backend&&t.isLanguageChangingTo&&!i(t.isLanguageChangingTo,e)?!1:!!(t.hasResourceBundle(r,e)||!t.services.backendConnector.backend||i(r,e)&&(!o||i(s,e)))}function or(e){if(Array.isArray(e))return e}function sr(e,t){var n=e==null?null:typeof Symbol!="undefined"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r=[],o=!0,s=!1,i,a;try{for(n=n.call(e);!(o=(i=n.next()).done)&&(r.push(i.value),!(t&&r.length===t));o=!0);}catch(l){s=!0,a=l}finally{try{!o&&n.return!=null&&n.return()}finally{if(s)throw a}}return r}}function De(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function ar(e,t){if(!!e){if(typeof e=="string")return De(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return De(e,t)}}function cr(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
28
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ur(e,t){return or(e)||sr(e,t)||ar(e,t)||cr()}function Be(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),n.push.apply(n,r)}return n}function ue(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?Be(Object(n),!0).forEach(function(r){Gn(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Be(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function jt(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=t.i18n,r=c.useContext(Zn)||{},o=r.i18n,s=r.defaultNS,i=n||o||nr();if(i&&!i.reportNamespaces&&(i.reportNamespaces=new tr),!i){de("You will need to pass in an i18next instance by using initReactI18next");var a=function(T){return Array.isArray(T)?T[T.length-1]:T},l=[a,{},!1];return l.t=a,l.i18n={},l.ready=!1,l}i.options.react&&i.options.react.wait!==void 0&&de("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");var u=ue(ue(ue({},er()),i.options.react),t),p=u.useSuspense,f=u.keyPrefix,g=e||s||i.options&&i.options.defaultNS;g=typeof g=="string"?[g]:g||["translation"],i.reportNamespaces.addUsedNamespaces&&i.reportNamespaces.addUsedNamespaces(g);var m=(i.isInitialized||i.initializedStoreOnce)&&g.every(function(O){return ir(O,i,u)});function h(){return i.getFixedT(null,u.nsMode==="fallback"?g:g[0],f)}var y=c.useState(h),x=ur(y,2),C=x[0],v=x[1],w=c.useRef(!0);c.useEffect(function(){var O=u.bindI18n,T=u.bindI18nStore;w.current=!0,!m&&!p&&Ue(i,g,function(){w.current&&v(h)});function F(){w.current&&v(h)}return O&&i&&i.on(O,F),T&&i&&i.store.on(T,F),function(){w.current=!1,O&&i&&O.split(" ").forEach(function(E){return i.off(E,F)}),T&&i&&T.split(" ").forEach(function(E){return i.store.off(E,F)})}},[i,g.join()]);var j=c.useRef(!0);c.useEffect(function(){w.current&&!j.current&&v(h),j.current=!1},[i]);var A=[C,i,m];if(A.t=C,A.i18n=i,A.ready=m,m||!m&&!p)return A;throw new Promise(function(O){Ue(i,g,function(){O()})})}function lr(e){var t=e,{as:n,language:r,children:o}=t,s=Ot(t,["as","language","children"]);const{i18n:i}=jt(),a=c.useMemo(()=>i.dir?i.dir(r):"ltr",[r]);return c.useMemo(()=>i.services?i.services.languageUtils.getLanguagePartFromCode(i.language)===i.services.languageUtils.getLanguagePartFromCode(r):!1,[i.language,r])?n?d.jsx(n,b(S({},k({},s)),{children:o})):d.jsx("span",b(S({},k({},s)),{children:o})):n?d.jsx(n,b(S({},te(k({},s),{lang:r,dir:a})),{children:o})):d.jsx("span",b(S({},te(k({},s),{lang:r,dir:a})),{children:o}))}function _t(e,t,n=[],r=!1){if(!e||!t||t.length===0)return;if(t.length===1)return t[0];if(t.indexOf(e)!==-1)return e;const o=e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):null;if(o&&t.indexOf(o)!==-1)return o;for(const s of n)if(t.indexOf(s)!==-1)return s;if(!r){const i=t.map(a=>a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null).indexOf(e);if(i!==-1)return t[i];for(const a of n){const l=a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null,u=l?t.indexOf(l):-1;if(u!==-1)return t[u]}}return t.indexOf("none")!==-1?"none":t.indexOf("@none")!==-1?"@none":t[0]}function fr(e,t,n={}){const{strictFallback:r=!1,defaultText:o="",separator:s=`
29
- `,fallbackLanguages:i=[],closest:a}=n,l=Object.keys(e||{}),u=a?t:_t(t,l,i,r);if(!e)return o;if(typeof e=="string")return e;const p=u?e[u]:void 0;return p?typeof p=="string"?p:p.join(s):""}function dr(e,t=[]){const{i18n:n}=jt(),r=n&&n.languages?n.languages:[],o=n&&n.language?n.language:"en";return c.useMemo(()=>{const s=e();return _t(o,s,r)},[r,o,...t])}function pr(e,t){const n=dr(()=>Object.keys(e||{}),[e]);return[c.useMemo(()=>fr(e,n,{defaultText:t,closest:!0}),[n,t,e]),n]}const gr=e=>{var t=e,{as:n,defaultText:r,enableDangerouslySetInnerHTML:o,children:s}=t,i=Ot(t,["as","defaultText","enableDangerouslySetInnerHTML","children"]);const[a,l]=pr(s,r);return l?d.jsx(lr,b(S({},te(k({},i),{as:n,language:l,title:o?void 0:a,dangerouslySetInnerHTML:o?{__html:a}:void 0})),{children:o?void 0:a})):n?d.jsx(n,b(S({},k({},i)),{children:a})):d.jsx("span",b(S({},te(k({},i),{title:o?void 0:a,dangerouslySetInnerHTML:o?{__html:a}:void 0})),{children:o?void 0:a}))};function Lt({x:e,y:t,onChoiceChange:n,registerActions:r,defaultChoices:o,isStatic:s,renderViewerControls:i,renderMediaControls:a,strategies:l,backgroundStyle:u,alwaysShowBackground:p,onClickPaintingAnnotation:f,children:g}){const m=_(),h=Se(m,["deep-zoom"]),[y]=nt(),x=I(),C=c.useMemo(()=>Ce(x),[x]),[v,w]=Ct({strategies:l||["images"],defaultChoices:o==null?void 0:o.map(({id:E})=>E)}),j=v.type==="images"?v.choice:void 0;c.useEffect(()=>{r&&r(w)},[v.annotations]),c.useEffect(()=>{if(o)for(const E of o)typeof E.opacity!="undefined"&&C.applyStyles({id:E.id},"atlas",{opacity:E.opacity})},[o]),c.useLayoutEffect(()=>{n&&n(j)},[j]);const A=Et({maxWidth:256,maxHeight:256});if(!m)return null;const O=m.accompanyingCanvas,T=A&&A.type==="fixed"?d.jsx("world-object",{height:m.height,width:m.width,x:e,y:t,children:d.jsx("world-image",{uri:A.id,target:{x:0,y:0,width:m.width,height:m.height},display:A.width&&A.height?{width:A.width,height:A.height}:void 0})}):null;if(v.type==="unknown"){if(T)return T;throw new Error(v.reason||"Unknown image strategy")}const F=d.jsxs(c.Fragment,{children:[y?d.jsx(fe,{page:y}):null,v.annotations&&v.annotations.pages?v.annotations.pages.map(E=>d.jsx(fe,{page:E},E.id)):null,g]});return d.jsxs(d.Fragment,{children:[d.jsxs("world-object",b(S({height:m.height,width:m.width,x:e,y:t},h),{children:[v.type==="empty"||p?d.jsx(Mt,{style:u}):null,v.type==="textual-content"?v.items.map((E,se)=>d.jsxs(d.Fragment,{children:[d.jsx(z.HTMLPortal,{onClick:f?q=>{q.stopPropagation(),f(E.annotationId,E,q)}:void 0,target:E.target.spatial||void 0,children:d.jsx(gr,{children:E.text})},se),F]})):null,v.type==="images"?d.jsxs(d.Fragment,{children:[v.images.map((E,se)=>d.jsx(ct,{isStatic:s,image:E,id:E.id,thumbnail:se===0?A:void 0,onClick:f?q=>{q.stopPropagation(),f(E.annotationId,E,q)}:void 0},E.id)),F]}):null,(v.type==="images"||v.type==="empty"||v.type==="textual-content")&&i?d.jsx(H,{overlay:!0,children:i(v)}):null,v.type==="3d-model"?d.jsx($n,{model:v.model}):null,v.type==="media"?d.jsx(d.Fragment,{children:v.media.type==="Sound"?d.jsxs(Hn,{media:v.media,children:[T,a?a(v):null]}):v.media.type==="Video"?d.jsxs(qn,{media:v.media,children:[T,a?a(v):null]}):null}):null]}),`${m.id}/${v.type}`),v.type==="media"&&v.media.type==="Sound"&&O?d.jsx(ge,{canvas:O.id,children:d.jsx(Lt,{renderViewerControls:i})}):null]})}const hr={RenderImage:ct,RenderCanvas:Lt,RenderAnnotationPage:fe,RenderAnnotation:at,Viewer:Sn,CanvasBackground:Mt};function mr({annotation:e,children:t}){return d.jsx(D,{value:{annotation:e},children:t})}function vr({collection:e,children:t}){return d.jsx(D,{value:{collection:e},children:t})}function yr(e,t={}){return oe(t)}function xr(e,t=!1){}function Sr(e){const n=L().manifest,r=e?e.map(o=>typeof o=="string"?o:o==null?void 0:o.id):[];return M(o=>{const s=n?o.iiif.entities.Manifest[n]:void 0,i=(s==null?void 0:s.items)||[];if(typeof e=="undefined")return i;const a=[];for(const l of(s==null?void 0:s.items)||[])r.indexOf(l.id)!==-1&&a.push(l);return a},[r.join("/")])}function Cr(e,t=[]){const{id:n,selector:r}=e,o=L(),s=n||o.collection,i=M(a=>s?a.iiif.entities.Collection[s]:void 0,[s]);return c.useMemo(()=>{if(!!i)return r?r(i):i},[i,r,...t])}function br(e,t,n,r,o=[]){const s=I(),i=c.useMemo(()=>ot(s),[s]);c.useEffect(()=>{const a=e;return a?(i.addEventListener(a,t,n,r),()=>{i.removeEventListener(a,t,n)}):()=>{}},[i,e,t,...o])}function Er(){const e=c.useContext(Q);return e&&e.vault?e.vault:X.globalVault()}function wr(e,t){const{id:n,isLoaded:r,error:o,resource:s,requestId:i,cached:a}=pe(e,t);return{id:n,isLoaded:r,error:o,manifest:s,requestId:i,cached:a}}function Ft({cacheKey:e}={}){const t=_(),n=oe(),r=I(),o=ie(),[s,i]=c.useState(void 0),[a,l]=c.useState(!1),[u,p]=c.useState("idle"),[f,g]=c.useState(void 0),m=t?t.id:"undefined",h=c.useMemo(()=>{try{if(t&&n.length){const x=n[0],C=r.get(x.body[0]),w=N.getImageServices(C)[0];return w&&o.loadServiceSync({id:w.id||w["@id"],width:w.width||t.width,height:w.height||t.height})||void 0}}catch(x){console.error(x)}},[m,e,t]),y=u==="success"&&s?s:h;return c.useEffect(()=>{(async()=>{try{if(t&&n.length){const x=n[0],C=r.get(x.body[0]),w=N.getImageServices(C)[0];if(!w)return;l(!0),p("loading");try{const j=await o.loadService({id:w.id||w["@id"],width:w.width||t.width,height:w.height||t.height})||void 0;i(j),p("success"),l(!1)}catch(j){p("error"),g(j)}}}catch(x){p("error"),g(x)}})()},[m,e]),c.useMemo(()=>({data:y,isFetching:a,status:u,error:f}),[y,a,u,f])}function Pr(){const e=Ft();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}}function Ir(){const e=B();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function Rr(){const e=I();return c.useMemo(()=>Ce(e),[e])}exports.AnnotationContext=mr;exports.CanvasContext=ge;exports.CanvasPanel=hr;exports.CanvasPortal=H;exports.CollectionContext=vr;exports.ContextBridge=Je;exports.ImageServiceLoaderContext=mt;exports.InnerViewerProvider=We;exports.ManifestContext=$e;exports.MediaPlayerProvider=we;exports.OverlayPortalContext=xe;exports.PortalContext=ye;exports.RangeContext=Ye;exports.ReactVaultContext=Q;exports.ResourceProvider=D;exports.ResourceReactContext=ne;exports.SimpleViewerProvider=Gt;exports.SimpleViewerReactContext=K;exports.VaultProvider=He;exports.ViewerPresetContext=re;exports.VirtualAnnotationProvider=rt;exports.VisibleCanvasReactContext=G;exports.emptyActions=ft;exports.emptyStrategy=dt;exports.expandTarget=V;exports.findAllCanvasesInRange=he;exports.findFirstCanvasFromRange=Qe;exports.findManifestSelectedRange=Yt;exports.findSelectedRange=me;exports.flattenAnnotationPageIds=pt;exports.formatTime=wt;exports.getImageStrategy=xt;exports.getManifestSequence=ve;exports.getPaintables=lt;exports.getParsedTargetSelector=be;exports.getVisibleCanvasesFromCanvasId=Qt;exports.parseSelector=Z;exports.parseSpecificResource=ut;exports.unknownResponse=J;exports.unsupportedStrategy=P;exports.useAnnotation=st;exports.useAnnotationPageManager=gt;exports.useAnnotationsAtTime=yr;exports.useCanvas=_;exports.useCanvasClock=xr;exports.useCanvasSequence=Ke;exports.useCanvasSubset=Sr;exports.useCollection=Cr;exports.useContextBridge=Xe;exports.useDispatch=Ze;exports.useEventListener=br;exports.useExistingVault=Er;exports.useExternalCollection=wr;exports.useExternalManifest=qe;exports.useExternalResource=pe;exports.useImageService=Ft;exports.useImageServiceLoader=ie;exports.useImageTile=Pr;exports.useLoadImageService=vt;exports.useManifest=B;exports.useMediaActions=Dn;exports.useMediaElements=Bn;exports.useMediaState=Un;exports.usePaintables=yt;exports.usePaintingAnnotations=oe;exports.useRange=Ge;exports.useRenderingStrategy=Ct;exports.useResourceContext=L;exports.useResourceEvents=Se;exports.useResources=ht;exports.useSearchService=Ir;exports.useSimpleMediaPlayer=Ee;exports.useSimpleViewer=Kt;exports.useStyleHelper=Rr;exports.useStyles=Y;exports.useThumbnail=Et;exports.useVault=I;exports.useVaultEffect=bt;exports.useVaultSelector=M;exports.useViewerPreset=it;exports.useVirtualAnnotationPage=et;exports.useVirtualAnnotationPageContext=nt;exports.useVisibleCanvases=ze;
27
+ `}),d.jsx("div",{className:"model-container",children:d.jsx("model-viewer",{"interaction-prompt":"none",style:{width:"100%",height:"100%"},"camera-controls":"","ar-status":"not-presenting",src:e.id})})]})}function Rt({style:e}){const t=L();return!t||!t.height||!t.width?null:d.jsx("box",{interactive:!1,target:{x:0,y:0,width:t.width,height:t.height},style:e})}var zn=Object.defineProperty,Yn=Object.defineProperties,Qn=Object.getOwnPropertyDescriptors,ee=Object.getOwnPropertySymbols,Mt=Object.prototype.hasOwnProperty,Tt=Object.prototype.propertyIsEnumerable,ke=(e,t,n)=>t in e?zn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,N=(e,t)=>{for(var n in t||(t={}))Mt.call(t,n)&&ke(e,n,t[n]);if(ee)for(var n of ee(t))Tt.call(t,n)&&ke(e,n,t[n]);return e},te=(e,t)=>Yn(e,Qn(t)),Ot=(e,t)=>{var n={};for(var r in e)Mt.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&ee)for(var r of ee(e))t.indexOf(r)<0&&Tt.call(e,r)&&(n[r]=e[r]);return n};function Gn(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Kn(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Ne(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function Wn(e,t,n){return t&&Ne(e.prototype,t),n&&Ne(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}var Xn={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},Jn,Zn=D.default.createContext();function er(){return Xn}var tr=function(){function e(){Kn(this,e),this.usedNamespaces={}}return Wn(e,[{key:"addUsedNamespaces",value:function(n){var r=this;n.forEach(function(o){r.usedNamespaces[o]||(r.usedNamespaces[o]=!0)})}},{key:"getUsedNamespaces",value:function(){return Object.keys(this.usedNamespaces)}}]),e}();function nr(){return Jn}function rr(){if(console&&console.warn){for(var e,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];typeof n[0]=="string"&&(n[0]="react-i18next:: ".concat(n[0])),(e=console).warn.apply(e,n)}}var Ue={};function de(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];typeof t[0]=="string"&&Ue[t[0]]||(typeof t[0]=="string"&&(Ue[t[0]]=new Date),rr.apply(void 0,t))}function De(e,t,n){e.loadNamespaces(t,function(){if(e.isInitialized)n();else{var r=function o(){setTimeout(function(){e.off("initialized",o)},0),n()};e.on("initialized",r)}})}function ir(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(!t.languages||!t.languages.length)return de("i18n.languages were undefined or empty",t.languages),!0;var r=t.languages[0],o=t.options?t.options.fallbackLng:!1,s=t.languages[t.languages.length-1];if(r.toLowerCase()==="cimode")return!0;var i=function(l,u){var p=t.services.backendConnector.state["".concat(l,"|").concat(u)];return p===-1||p===2};return n.bindI18n&&n.bindI18n.indexOf("languageChanging")>-1&&t.services.backendConnector.backend&&t.isLanguageChangingTo&&!i(t.isLanguageChangingTo,e)?!1:!!(t.hasResourceBundle(r,e)||!t.services.backendConnector.backend||i(r,e)&&(!o||i(s,e)))}function or(e){if(Array.isArray(e))return e}function sr(e,t){var n=e==null?null:typeof Symbol!="undefined"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r=[],o=!0,s=!1,i,a;try{for(n=n.call(e);!(o=(i=n.next()).done)&&(r.push(i.value),!(t&&r.length===t));o=!0);}catch(l){s=!0,a=l}finally{try{!o&&n.return!=null&&n.return()}finally{if(s)throw a}}return r}}function Be(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function ar(e,t){if(!!e){if(typeof e=="string")return Be(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Be(e,t)}}function cr(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
28
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ur(e,t){return or(e)||sr(e,t)||ar(e,t)||cr()}function He(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),n.push.apply(n,r)}return n}function ue(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?He(Object(n),!0).forEach(function(r){Gn(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):He(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function jt(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=t.i18n,r=c.useContext(Zn)||{},o=r.i18n,s=r.defaultNS,i=n||o||nr();if(i&&!i.reportNamespaces&&(i.reportNamespaces=new tr),!i){de("You will need to pass in an i18next instance by using initReactI18next");var a=function(T){return Array.isArray(T)?T[T.length-1]:T},l=[a,{},!1];return l.t=a,l.i18n={},l.ready=!1,l}i.options.react&&i.options.react.wait!==void 0&&de("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");var u=ue(ue(ue({},er()),i.options.react),t),p=u.useSuspense,f=u.keyPrefix,g=e||s||i.options&&i.options.defaultNS;g=typeof g=="string"?[g]:g||["translation"],i.reportNamespaces.addUsedNamespaces&&i.reportNamespaces.addUsedNamespaces(g);var v=(i.isInitialized||i.initializedStoreOnce)&&g.every(function(O){return ir(O,i,u)});function h(){return i.getFixedT(null,u.nsMode==="fallback"?g:g[0],f)}var y=c.useState(h),x=ur(y,2),C=x[0],m=x[1],P=c.useRef(!0);c.useEffect(function(){var O=u.bindI18n,T=u.bindI18nStore;P.current=!0,!v&&!p&&De(i,g,function(){P.current&&m(h)});function V(){P.current&&m(h)}return O&&i&&i.on(O,V),T&&i&&i.store.on(T,V),function(){P.current=!1,O&&i&&O.split(" ").forEach(function(E){return i.off(E,V)}),T&&i&&T.split(" ").forEach(function(E){return i.store.off(E,V)})}},[i,g.join()]);var j=c.useRef(!0);c.useEffect(function(){P.current&&!j.current&&m(h),j.current=!1},[i]);var M=[C,i,v];if(M.t=C,M.i18n=i,M.ready=v,v||!v&&!p)return M;throw new Promise(function(O){De(i,g,function(){O()})})}function lr(e){var t=e,{as:n,language:r,children:o}=t,s=Ot(t,["as","language","children"]);const{i18n:i}=jt(),a=c.useMemo(()=>i.dir?i.dir(r):"ltr",[r]);return c.useMemo(()=>i.services?i.services.languageUtils.getLanguagePartFromCode(i.language)===i.services.languageUtils.getLanguagePartFromCode(r):!1,[i.language,r])?n?d.jsx(n,b(S({},N({},s)),{children:o})):d.jsx("span",b(S({},N({},s)),{children:o})):n?d.jsx(n,b(S({},te(N({},s),{lang:r,dir:a})),{children:o})):d.jsx("span",b(S({},te(N({},s),{lang:r,dir:a})),{children:o}))}function _t(e,t,n=[],r=!1){if(!e||!t||t.length===0)return;if(t.length===1)return t[0];if(t.indexOf(e)!==-1)return e;const o=e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):null;if(o&&t.indexOf(o)!==-1)return o;for(const s of n)if(t.indexOf(s)!==-1)return s;if(!r){const i=t.map(a=>a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null).indexOf(e);if(i!==-1)return t[i];for(const a of n){const l=a.indexOf("-")!==-1?a.slice(0,a.indexOf("-")):null,u=l?t.indexOf(l):-1;if(u!==-1)return t[u]}}return t.indexOf("none")!==-1?"none":t.indexOf("@none")!==-1?"@none":t[0]}function fr(e,t,n={}){const{strictFallback:r=!1,defaultText:o="",separator:s=`
29
+ `,fallbackLanguages:i=[],closest:a}=n,l=Object.keys(e||{}),u=a?t:_t(t,l,i,r);if(!e)return o;if(typeof e=="string")return e;const p=u?e[u]:void 0;return p?typeof p=="string"?p:p.join(s):""}function dr(e,t=[]){const{i18n:n}=jt(),r=n&&n.languages?n.languages:[],o=n&&n.language?n.language:"en";return c.useMemo(()=>{const s=e();return _t(o,s,r)},[r,o,...t])}function pr(e,t){const n=dr(()=>Object.keys(e||{}),[e]);return[c.useMemo(()=>fr(e,n,{defaultText:t,closest:!0}),[n,t,e]),n]}const gr=e=>{var t=e,{as:n,defaultText:r,enableDangerouslySetInnerHTML:o,children:s}=t,i=Ot(t,["as","defaultText","enableDangerouslySetInnerHTML","children"]);const[a,l]=pr(s,r);return l?d.jsx(lr,b(S({},te(N({},i),{as:n,language:l,title:o?void 0:a,dangerouslySetInnerHTML:o?{__html:a}:void 0})),{children:o?void 0:a})):n?d.jsx(n,b(S({},N({},i)),{children:a})):d.jsx("span",b(S({},te(N({},i),{title:o?void 0:a,dangerouslySetInnerHTML:o?{__html:a}:void 0})),{children:o?void 0:a}))};function Lt({x:e,y:t,onChoiceChange:n,registerActions:r,defaultChoices:o,isStatic:s,renderViewerControls:i,renderMediaControls:a,strategies:l,backgroundStyle:u,alwaysShowBackground:p,onClickPaintingAnnotation:f,children:g}){const v=L(),h=Se(v,["deep-zoom"]),[y]=rt(),x=I(),C=c.useMemo(()=>Ce(x),[x]),[m,P]=Ct({strategies:l||["images"],defaultChoices:o==null?void 0:o.map(({id:E})=>E)}),j=m.type==="images"?m.choice:void 0;c.useEffect(()=>{r&&r(P)},[m.annotations]),c.useEffect(()=>{if(o)for(const E of o)typeof E.opacity!="undefined"&&C.applyStyles({id:E.id},"atlas",{opacity:E.opacity})},[o]),c.useLayoutEffect(()=>{n&&n(j)},[j]);const M=Et({maxWidth:256,maxHeight:256});if(!v)return null;const O=v.accompanyingCanvas,T=M&&M.type==="fixed"?d.jsx("world-object",{height:v.height,width:v.width,x:e,y:t,children:d.jsx("world-image",{uri:M.id,target:{x:0,y:0,width:v.width,height:v.height},display:M.width&&M.height?{width:M.width,height:M.height}:void 0})}):null;if(m.type==="unknown"){if(T)return T;throw new Error(m.reason||"Unknown image strategy")}const V=d.jsxs(c.Fragment,{children:[y?d.jsx(fe,{page:y}):null,m.annotations&&m.annotations.pages?m.annotations.pages.map(E=>d.jsx(fe,{page:E},E.id)):null,g]});return d.jsxs(d.Fragment,{children:[d.jsxs("world-object",b(S({height:v.height,width:v.width,x:e,y:t},h),{children:[m.type==="empty"||p?d.jsx(Rt,{style:u}):null,m.type==="textual-content"?m.items.map((E,se)=>d.jsxs(d.Fragment,{children:[d.jsx(z.HTMLPortal,{onClick:f?q=>{q.stopPropagation(),f(E.annotationId,E,q)}:void 0,target:E.target.spatial||void 0,children:d.jsx(gr,{children:E.text})},se),V]})):null,m.type==="images"?d.jsxs(d.Fragment,{children:[m.images.map((E,se)=>d.jsx(ct,{isStatic:s,image:E,id:E.id,thumbnail:se===0?M:void 0,onClick:f?q=>{q.stopPropagation(),f(E.annotationId,E,q)}:void 0},E.id)),V]}):null,(m.type==="images"||m.type==="empty"||m.type==="textual-content")&&i?d.jsx(H,{overlay:!0,children:i(m)}):null,m.type==="3d-model"?d.jsx($n,{model:m.model}):null,m.type==="media"?d.jsx(d.Fragment,{children:m.media.type==="Sound"?d.jsxs(Hn,{media:m.media,children:[T,a?a(m):null]}):m.media.type==="Video"?d.jsxs(qn,{media:m.media,children:[T,a?a(m):null]}):null}):null]}),`${v.id}/${m.type}`),m.type==="media"&&m.media.type==="Sound"&&O?d.jsx(ge,{canvas:O.id,children:d.jsx(Lt,{renderViewerControls:i})}):null]})}const hr={RenderImage:ct,RenderCanvas:Lt,RenderAnnotationPage:fe,RenderAnnotation:at,Viewer:Sn,CanvasBackground:Rt};function vr({annotation:e,children:t}){return d.jsx(F,{value:{annotation:e},children:t})}function mr({annotationPage:e,children:t}){return d.jsx(F,{value:{annotationPage:e},children:t})}function yr({collection:e,children:t}){return d.jsx(F,{value:{collection:e},children:t})}function xr(e={},t=[]){const{id:n,selector:r}=e,o=_(),s=n||o.annotationPage,i=A(a=>s?a.iiif.entities.AnnotationPage[s]:void 0,[s]);return c.useMemo(()=>{if(!!i)return r?r(i):i},[i,...t])}function Sr(e,t={}){return oe(t)}function Cr(e,t=!1){}function br(e){const n=_().manifest,r=e?e.map(o=>typeof o=="string"?o:o==null?void 0:o.id):[];return A(o=>{const s=n?o.iiif.entities.Manifest[n]:void 0,i=(s==null?void 0:s.items)||[];if(typeof e=="undefined")return i;const a=[];for(const l of(s==null?void 0:s.items)||[])r.indexOf(l.id)!==-1&&a.push(l);return a},[r.join("/")])}function Er(e,t=[]){const{id:n,selector:r}=e,o=_(),s=n||o.collection,i=A(a=>s?a.iiif.entities.Collection[s]:void 0,[s]);return c.useMemo(()=>{if(!!i)return r?r(i):i},[i,r,...t])}function Pr(e,t,n,r,o=[]){const s=I(),i=c.useMemo(()=>st(s),[s]);c.useEffect(()=>{const a=e;return a?(i.addEventListener(a,t,n,r),()=>{i.removeEventListener(a,t,n)}):()=>{}},[i,e,t,...o])}function wr(){const e=c.useContext(Q);return e&&e.vault?e.vault:X.globalVault()}function Ir(e,t){const{id:n,isLoaded:r,error:o,resource:s,requestId:i,cached:a}=pe(e,t);return{id:n,isLoaded:r,error:o,manifest:s,requestId:i,cached:a}}function Ft({cacheKey:e}={}){const t=L(),n=oe(),r=I(),o=ie(),[s,i]=c.useState(void 0),[a,l]=c.useState(!1),[u,p]=c.useState("idle"),[f,g]=c.useState(void 0),v=t?t.id:"undefined",h=c.useMemo(()=>{try{if(t&&n.length){const x=n[0],C=r.get(x.body[0]),P=U.getImageServices(C)[0];return P&&o.loadServiceSync({id:P.id||P["@id"],width:P.width||t.width,height:P.height||t.height})||void 0}}catch(x){console.error(x)}},[v,e,t]),y=u==="success"&&s?s:h;return c.useEffect(()=>{(async()=>{try{if(t&&n.length){const x=n[0],C=r.get(x.body[0]),P=U.getImageServices(C)[0];if(!P)return;l(!0),p("loading");try{const j=await o.loadService({id:P.id||P["@id"],width:P.width||t.width,height:P.height||t.height})||void 0;i(j),p("success"),l(!1)}catch(j){p("error"),g(j)}}}catch(x){p("error"),g(x)}})()},[v,e]),c.useMemo(()=>({data:y,isFetching:a,status:u,error:f}),[y,a,u,f])}function Ar(){const e=Ft();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}}function Rr(){const e=B();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function Mr(){const e=I();return c.useMemo(()=>Ce(e),[e])}exports.AnnotationContext=vr;exports.AnnotationPageContext=mr;exports.CanvasContext=ge;exports.CanvasPanel=hr;exports.CanvasPortal=H;exports.CollectionContext=yr;exports.ContextBridge=Ze;exports.ImageServiceLoaderContext=vt;exports.InnerViewerProvider=Xe;exports.ManifestContext=ze;exports.MediaPlayerProvider=we;exports.OverlayPortalContext=xe;exports.PortalContext=ye;exports.RangeContext=Qe;exports.ReactVaultContext=Q;exports.ResourceProvider=F;exports.ResourceReactContext=ne;exports.SimpleViewerProvider=Gt;exports.SimpleViewerReactContext=K;exports.VaultProvider=qe;exports.ViewerPresetContext=re;exports.VirtualAnnotationProvider=it;exports.VisibleCanvasReactContext=G;exports.emptyActions=ft;exports.emptyStrategy=dt;exports.expandTarget=k;exports.findAllCanvasesInRange=he;exports.findFirstCanvasFromRange=Ge;exports.findManifestSelectedRange=Yt;exports.findSelectedRange=ve;exports.flattenAnnotationPageIds=pt;exports.formatTime=Pt;exports.getImageStrategy=xt;exports.getManifestSequence=me;exports.getPaintables=lt;exports.getParsedTargetSelector=Ee;exports.getVisibleCanvasesFromCanvasId=Qt;exports.parseSelector=Z;exports.parseSpecificResource=ut;exports.unknownResponse=J;exports.unsupportedStrategy=w;exports.useAnnotation=be;exports.useAnnotationPage=xr;exports.useAnnotationPageManager=gt;exports.useAnnotationsAtTime=Sr;exports.useCanvas=L;exports.useCanvasClock=Cr;exports.useCanvasSequence=We;exports.useCanvasSubset=br;exports.useCollection=Er;exports.useContextBridge=Je;exports.useDispatch=et;exports.useEventListener=Pr;exports.useExistingVault=wr;exports.useExternalCollection=Ir;exports.useExternalManifest=$e;exports.useExternalResource=pe;exports.useImageService=Ft;exports.useImageServiceLoader=ie;exports.useImageTile=Ar;exports.useLoadImageService=mt;exports.useManifest=B;exports.useMediaActions=Dn;exports.useMediaElements=Bn;exports.useMediaState=Un;exports.usePaintables=yt;exports.usePaintingAnnotations=oe;exports.useRange=Ke;exports.useRenderingStrategy=Ct;exports.useResourceContext=_;exports.useResourceEvents=Se;exports.useResources=ht;exports.useSearchService=Rr;exports.useSimpleMediaPlayer=Pe;exports.useSimpleViewer=Kt;exports.useStyleHelper=Mr;exports.useStyles=Y;exports.useThumbnail=Et;exports.useVault=I;exports.useVaultEffect=bt;exports.useVaultSelector=A;exports.useViewerPreset=ot;exports.useVirtualAnnotationPage=tt;exports.useVirtualAnnotationPageContext=rt;exports.useVisibleCanvases=Ye;
30
30
  //# sourceMappingURL=index.js.map