react-iiif-vault 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),u=require("react"),_=require("@atlas-viewer/atlas"),X=require("@iiif/helpers/vault"),ge=require("@iiif/helpers/styles"),Y=require("@iiif/helpers/annotation-targets"),Bt=require("@iiif/helpers"),te=require("@atlas-viewer/iiif-image-api"),Ht=require("@iiif/helpers/thumbnail");function $t(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const ce=$t(u);function de(e,t){return de=Object.setPrototypeOf||function(r,o){return r.__proto__=o,r},de(e,t)}function Yt(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,de(e,t)}var zt=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])})},Ie={error:null},Kt=function(e){Yt(t,e);function t(){for(var r,o=arguments.length,i=new Array(o),s=0;s<o;s++)i[s]=arguments[s];return r=e.call.apply(e,[this].concat(i))||this,r.state=Ie,r.resetErrorBoundary=function(){for(var a,l=arguments.length,f=new Array(l),d=0;d<l;d++)f[d]=arguments[d];r.props.onReset==null||(a=r.props).onReset.apply(a,f),r.reset()},r}t.getDerivedStateFromError=function(o){return{error:o}};var n=t.prototype;return n.reset=function(){this.setState(Ie)},n.componentDidCatch=function(o,i){var s,a;(s=(a=this.props).onError)==null||s.call(a,o,i)},n.componentDidUpdate=function(o,i){var s=this.state.error,a=this.props.resetKeys;if(s!==null&&i.error!==null&&zt(o.resetKeys,a)){var l,f;(l=(f=this.props).onResetKeysChange)==null||l.call(f,o.resetKeys,a),this.reset()}},n.render=function(){var o=this.state.error,i=this.props,s=i.fallbackRender,a=i.FallbackComponent,l=i.fallback;if(o!==null){var f={error:o,resetErrorBoundary:this.resetErrorBoundary};if(ce.isValidElement(l))return l;if(typeof s=="function")return s(f);if(a)return ce.createElement(a,f);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},t}(ce.Component);const Wt={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},ne=u.createContext(Wt),O=()=>u.useContext(ne);function N({value:e,children:t}){const n=O(),r=u.useMemo(()=>({...n,...e}),[e,n]);return c.jsx(ne.Provider,{value:r,children:t})}const K=u.createContext({vault:null,setVaultInstance:e=>{}});function he({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:o}){const[i,s]=u.useState(()=>e||(n?X.globalVault(t):t?new X.Vault(t):new X.Vault));return c.jsx(K.Provider,{value:{vault:i,setVaultInstance:s},children:c.jsx(N,{value:r||{},children:o})})}const M=()=>{const{vault:e}=u.useContext(K);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};function me(e,{noCache:t=!1}={}){const n=typeof e=="string"?e:e.id,r=M(),[o,i]=u.useState(n),[s,a]=u.useState(void 0),l=u.useMemo(()=>r.get(n,{skipSelfReturn:!0})||void 0,[n,r]),[f,d]=u.useState(l);return u.useEffect(()=>{(async()=>{try{const g=l&&!t?l:await r.load(n),p=g?g.id||g["@id"]:null;g&&o!==p&&i(p),d(g)}catch(g){a(g)}})()},[n,t]),{isLoaded:!!f,id:o,requestId:n,error:s,resource:f,cached:!!(f&&f===l)}}function Te(e,t){const{id:n,isLoaded:r,error:o,resource:i,requestId:s,cached:a}=me(e,t);return{id:n,isLoaded:r,error:o,manifest:i,requestId:s,cached:a}}function Ve({manifest:e,children:t}){return c.jsx(N,{value:{manifest:e},children:t})}function re({canvas:e,children:t}){return c.jsx(N,{value:{canvas:e},children:t})}function E(e,t=[]){const n=M(),[r,o]=u.useState(()=>e(n.getState(),n));return u.useEffect(()=>n.subscribe(i=>e(i,n),i=>{o(i)},!1),t),r}const W=u.createContext([]);function ve(){const e=u.useContext(W);return E(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}function D(e={},t=[]){const{id:n,selector:r}=e,o=O();M();const i=n||o.manifest,s=E(a=>i?a.iiif.entities.Manifest[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}function Le({range:e,children:t}){return c.jsx(N,{value:{range:e},children:t})}function ke(e,t){for(const n of t.items){if(n.type==="Canvas")return n;if(n.type==="SpecificResource")return n.source;if(n.type==="Range"){const r=ke(e,e.get(n));if(r)return r}}return null}function pe(e,t){var r;const n=[];for(const o of t.items)if(o.type==="SpecificResource"&&((r=o.source)==null?void 0:r.type)==="Canvas"&&(o.source.id.indexOf("#")!==-1?n.push({id:o.source.id.split("#")[0],type:"Canvas"}):n.push(o.source)),o.type==="Range"&&n.push(...pe(e,e.get(o))),o.type==="SpecificResource"){const i=typeof o.source=="string"?o.source:o.source.id;n.push({id:i,type:"Canvas"})}return n}function Gt(e,t,n){for(const r of t.structures){const o=ye(e,e.get(r),n);if(o)return o}return null}function ye(e,t,n){var r,o,i;for(const s of t.items){const a=(o=(r=s==null?void 0:s.source)==null?void 0:r.id)==null?void 0:o.split("#")[0];if(s.type==="SpecificResource"&&s.source===n||s.type==="SpecificResource"&&((i=s.source)==null?void 0:i.type)==="Canvas"&&n===a)return t;if(s.type==="Range"){const l=ye(e,e.get(s),n);if(l)return l}}return null}function Qt(e,t,n,r=!1){const o=t.behavior,i=n?e.get(n):null;if(!i)return[];const s=i.behavior,a=r?!1:o.includes("paged"),l=a?!1:o.includes("continuous"),f=a||l?!1:o.includes("individuals"),d=s.includes("facing-pages"),g=s.includes("non-paged");if(d||g||f||r)return[{id:i.id,type:"Canvas"}];const[p,y]=xe(e,t);if(l)return p;const m=p.findIndex(h=>h.id===n);if(m===-1)return[];for(const h of y)if(h.includes(m))return h.map(x=>p[x]);return[{id:i.id,type:"Canvas"}]}function xe(e,t,{disablePaging:n,skipNonPaged:r}={}){const o=t.behavior,i=o.includes("paged"),s=i?!1:o.includes("continuous"),a=i||s?!1:o.includes("individuals"),l=t.type==="Manifest"?t.items:pe(e,t);if(s)return[l,[l.map((m,h)=>h)]];if(a||!i||n)return[l,l.map((m,h)=>[h])];const f=[];let d=[];const g=()=>{d.length&&(f.push([...d]),d=[])};let p=0,y=!1;for(let m=0;m<l.length;m++){const h=e.get(l[m]);if(h.behavior.includes("non-paged")){m===p&&p++,r||(g(),f.push([m]),g());continue}if(m===p||h.behavior.includes("facing-pages")){d.length&&(y=!0),g(),f.push([m]),g();continue}if(d.push(m),y){g(),y=!1;continue}d.length>1&&g()}return d.length&&g(),[l,f]}function Oe(e={},t=[]){const{id:n,selector:r}=e,o=O(),i=n||o.range,s=E(a=>i?a.iiif.entities.Range[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}function Fe({startCanvas:e,disablePaging:t}){var m;const n=M(),r=D(),o=Oe(),[i,s]=u.useState(void 0),a=o||r;if(!a)throw new Error("Nothing selected");const[l,f]=u.useMemo(()=>xe(n,a,{disablePaging:t}),[n,a]),d=u.useCallback(h=>{const x=f.findIndex(C=>C.includes(h));s(x===-1?0:x)},[l,f]),g=u.useCallback(h=>{const x=l.findIndex(C=>C.id===h);x!==-1?d(x):s(0)},[l,f]),p=u.useCallback(()=>{s(h=>h>=f.length?h:h+1)},[f]),y=u.useCallback(()=>{s(h=>h<=0?0:h-1)},[f]);return typeof i>"u"&&(e?g(e):s(0)),{visibleItems:((m=f[i])==null?void 0:m.map(h=>l[h].id))||[],cursor:i,items:l,sequence:f,setSequenceIndex:s,setCanvasIndex:d,setCanvasId:g,next:p,previous:y}}const $=()=>{},G=u.createContext({setCurrentCanvasId:$,setCurrentCanvasIndex:$,nextCanvas:$,previousCanvas:$,items:[],sequence:[],setSequenceIndex:$,currentSequenceIndex:0});function Ne(e){const t=D(),{cursor:n,visibleItems:r,next:o,sequence:i,items:s,setCanvasIndex:a,setCanvasId:l,previous:f,setSequenceIndex:d}=Fe({startCanvas:e.startCanvas,disablePaging:e.pagingEnabled===!1}),g=u.useMemo(()=>({sequence:i,items:s,setCurrentCanvasId:l,nextCanvas:o,previousCanvas:f,totalCanvases:s.length,setCurrentCanvasIndex:a,setSequenceIndex:d,currentSequenceIndex:n}),[i,s,l,o,f,s,a,d,n]);return t?r.length===0?null:c.jsx(G.Provider,{value:g,children:c.jsx(W.Provider,{value:r,children:c.jsx(re,{canvas:r[0],children:e.children})})}):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),c.jsx("div",{children:"Sorry, something went wrong."}))}function De(e){const t=Te(e.manifest);if(!t)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),c.jsx("div",{children:"Sorry, something went wrong."});if(t.error)return c.jsx("div",{children:t.error.toString()});if(!t.isLoaded)return c.jsx("div",{children:"Loading..."});const n=c.jsx(Ne,{...e,children:e.children});return c.jsx(Ve,{manifest:t.id,children:e.rangeId?c.jsx(Le,{range:e.rangeId,children:n}):n})}function qe(){return u.useContext(G)}function _e(){return{VaultContext:u.useContext(K),ResourceContext:u.useContext(ne),SimpleViewerReactContext:u.useContext(G),VisibleCanvasReactContext:u.useContext(W)}}function Ue(e){return c.jsx(he,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext,children:c.jsx(W.Provider,{value:e.bridge.VisibleCanvasReactContext,children:c.jsx(G.Provider,{value:e.bridge.SimpleViewerReactContext,children:e.children})})})}const T=function(e){return function(){const t={type:e,getType:()=>e,toString:()=>e};return(n,r)=>({...t,...n!==void 0&&{payload:n},...r!==void 0&&{meta:r}})}},Jt="@iiif/IMPORT_ENTITIES",Zt="@iiif/MODIFY_ENTITY_FIELD",Xt="@iiif/REORDER_ENTITY_FIELD",en="@iiif/ADD_REFERENCE",tn="@iiif/UPDATE_REFERENCE",nn="@iiif/REMOVE_REFERENCE",rn="@iiif/ADD_METADATA",on="@iiif/REMOVE_METADATA",sn="@iiif/UPDATE_METADATA",an="@iiif/REORDER_METADATA",un=T(Jt)(),cn=T(Zt)(),ln=T(Xt)(),dn=T(en)(),fn=T(nn)(),gn=T(tn)(),hn=T(rn)(),mn=T(sn)(),vn=T(on)(),pn=T(an)(),le={importEntities:un,modifyEntityField:cn,reorderEntityField:ln,addReference:dn,removeReference:fn,updateReference:gn,addMetadata:hn,removeMetadata:vn,updateMetadata:mn,reorderMetadata:pn};function Be(){const t=M().getStore();return u.useMemo(()=>n=>t.dispatch(n),[t])}function Re(e){return typeof e!="string"&&e&&e.bindToVault}function He(){const e=M(),t=u.useRef([]),n=Be(),r=u.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);u.useLayoutEffect(()=>{const a={id:r,type:"AnnotationPage",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],rendering:[],service:[]};n(le.importEntities({entities:{AnnotationPage:{[a.id]:a}}}))},[r]);const o=E(a=>r?a.iiif.entities.AnnotationPage[r]:null,[r]),i=u.useCallback((a,l)=>{if(r){if(Re(a)){const g=a;g.__vault||g.bindToVault(e),a=typeof g.source=="string"?g.source:g.source.id,t.current[a]=g}else typeof a!="string"&&(a=a.id);const f=e.get({id:r,type:"AnnotationPage"}),d=e.get({id:a,type:"Annotation"});f&&d&&(f.items.find(g=>g.id===d.id)||n(le.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"},index:l})))}},[r]),s=u.useCallback(a=>{r&&(Re(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(le.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"}})))},[r]);return[o,{addAnnotation:i,removeAnnotation:s}]}const $e=u.createContext(null);function Ye(){const e=u.useContext($e);return[e.fullPage,{addAnnotation:e.addAnnotation,removeAnnotation:e.removeAnnotation}]}function ze({children:e}){const[t,{addAnnotation:n,removeAnnotation:r}]=He();return c.jsx($e.Provider,{value:u.useMemo(()=>({fullPage:t,addAnnotation:n,removeAnnotation:r}),[t]),children:e})}function yn({width:e,style:t,height:n,error:r,resetErrorBoundary:o}){return c.jsxs("div",{style:{width:e,height:n,minHeight:500,...t||{},background:"#f9f9f9"},children:[c.jsx("h3",{children:"Error occurred"}),c.jsx("p",{children:r.message}),c.jsx("button",{onClick:o,children:"Reset"})]})}const oe=u.createContext(null);function Ke(){return u.useContext(oe)}const We=u.createContext(()=>{}),Ge=u.createContext(()=>{});function U(e,t,n,r,o=[]){const i=u.useContext(e==="portal"?Ge:We);u.useEffect(()=>(e!=="none"&&i(t,n,r),()=>{i(t,null)}),[t,e,i,...o])}function V(e={},t=[]){const{id:n,selector:r}=e,o=O(),i=n||o.canvas,s=E(a=>i?a.iiif.entities.Canvas[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}const Qe=u.createContext(()=>{});function xn(e){const t=V(),n=u.useContext(Qe);u.useEffect(()=>t&&t.id?(n(t.id,e),()=>n(t.id,-1)):()=>{},[t,e])}function Sn({children:e,errorFallback:t,outerContainerProps:n={},worldScale:r,...o}){const[i,s]=u.useState(),a=_e(),l=t||yn,[f,d]=u.useState({}),g=Object.entries(f),[p,y]=u.useState({}),m=Object.entries(p),[h,x]=u.useState({}),C=u.useMemo(()=>r||Math.max(...Object.values(h)),[h]),j=u.useMemo(()=>({maxOverZoom:C||1,...o.runtimeOptions||{}}),[C,o.runtimeOptions]),S=u.useCallback((w,I)=>{x(A=>{if(I===-1){const{[w]:v,...k}=A;return k}return{...A,[w]:I}})},[]),L=u.useCallback((w,I,A)=>{d(({[w]:v,...k})=>I?{...k,[w]:{element:I,props:A}}:k)},[]),Q=u.useCallback((w,I,A)=>{y(({[w]:v,...k})=>I?{...k,[w]:{element:I,props:A}}:k)},[]);return c.jsxs(Kt,{resetKeys:[],fallbackRender:w=>c.jsx(l,{...o,...w}),children:[c.jsx(_.AtlasAuto,{...o,containerProps:{style:{position:"relative"},...o.containerProps||{}},htmlChildren:c.jsx(c.Fragment,{children:g.map(([w,{element:I,props:A}])=>c.jsx(u.Fragment,{children:c.jsx(I,{...A||{}})},w))}),onCreated:w=>{s(w),o.onCreated&&o.onCreated(w)},runtimeOptions:j,children:c.jsx(oe.Provider,{value:i,children:c.jsx(Qe.Provider,{value:S,children:c.jsx(We.Provider,{value:L,children:c.jsx(Ge.Provider,{value:Q,children:c.jsx(Ue,{bridge:a,children:c.jsx(_.ModeContext.Provider,{value:o.mode||"explore",children:c.jsx(ze,{children:e})})})})})})})}),c.jsx("div",{children:m.map(([w,{element:I,props:A}])=>c.jsx(u.Fragment,{children:c.jsx(I,{...A||{}})},w))})]})}const J={},Je={get(e){return e},setMetaValue([e,t,n],r){const o=Je.getResourceMeta(e,t),i=o?o[n]:void 0,s=typeof r=="function"?r(i):r;J[e]={...J[e]||{},[t]:{...(J[e]||{})[t]||{},[n]:s}}},getResourceMeta:(e,t)=>{const n=J[e];if(n)return t?n[t]:n}};function Ze(e=Je){return{addEventListener(t,n,r,o){if(t)return e.setMetaValue([t.id,"eventManager",n],i=>{const s=i||[];for(const a of s)if(a.callback===r)return s;return[...s,{callback:r,scope:o}]}),r},removeEventListener(t,n,r){t&&e.setMetaValue([t.id,"eventManager",n],o=>(o||[]).filter(i=>i.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"),i={};if(o&&r)for(const s of Object.keys(o))i[s]=a=>{const l=e.get(r);for(const{callback:f,scope:d}of o[s]||[])(!d||n&&d.indexOf(n)!==-1)&&f(a,l)};return i}}}function Se(e,t){const n=M(),r=u.useMemo(()=>Ze(n),[n]),o=E(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return u.useMemo(()=>e?r.getListenersAsProps(e,t):{},[o,e,n,t])}function z(e,t){const n=M(),r=u.useMemo(()=>ge.createStylesHelper(n),[n]);return E(()=>{if(!e)return null;const o=r.getAppliedStyles(e.id);return o?t?o[t]:o:void 0},[e,t])}function Ce(e={},t=[]){const{id:n,selector:r}=e,o=O(),i=M(),s=n||o.annotation,a=E(f=>s?f.iiif.entities.Annotation[s]:void 0,[s]),l=E(f=>a&&a.body?a.body.map(d=>d?d.type==="SpecificResource"?{...d,source:i.get(d)}:d?f.iiif.entities[d.type][d.id]:null:null).filter(Boolean):[],[a]);return u.useMemo(()=>{if(!a)return;const f={...a,body:l,target:Y.expandTarget(a.target,{typeMap:i.getState().iiif.mapping})};return r?r(f):f},[a,r,l,...t])}const Xe=({id:e,style:t,className:n,interactive:r})=>{const o=Ce({id:e}),i=z(o,"atlas"),s=z(o,"html"),a=Se(o,["atlas"]),l=V(),f=u.useMemo(()=>_.mergeStyles(t,i),[t,i]);return l&&o&&o.target&&o.target.selector&&o.target.selector.type==="BoxSelector"&&o.target.source&&(o.target.source.id===l.id||o.target.source===l.id)?c.jsx(_.RegionHighlight,{id:o.id,isEditing:!0,region:o.target.selector.spatial,style:f,className:(s==null?void 0:s.className)||n,interactive:!!(s!=null&&s.href||r),href:(s==null?void 0:s.href)||null,title:(s==null?void 0:s.title)||null,hrefTarget:(s==null?void 0:s.target)||null,onClick:()=>{},...a}):null};function et(e={},t=[]){const{id:n,selector:r}=e,o=O(),i=n||o.annotationPage,s=E(a=>i?a.iiif.entities.AnnotationPage[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,...t])}const fe=({className:e,page:t})=>{var i;const n=et({id:t.id})||t,r=z(n,"atlas"),o=z(n,"html");return E(s=>n.id?s.iiif.entities.AnnotationPage[n.id]:null,[]),c.jsx(u.Fragment,{children:(i=n.items)==null?void 0:i.map(s=>c.jsx(Xe,{id:s.id,style:r,className:(o==null?void 0:o.className)||e},s.id))})};function tt({id:e,image:t,thumbnail:n,isStatic:r,x:o=0,y:i=0,children:s,selector:a,onClick:l,enableSizes:f}){var g,p;const d=u.useMemo(()=>{if(!(!a||a.spatial.x===0&&a.spatial.y===0))return a.spatial},[a]);return c.jsx("world-object",{x:o+t.target.spatial.x,y:i+t.target.spatial.y,width:t.target.spatial.width,height:t.target.spatial.height,onClick:l,children:t.service?c.jsxs(u.Fragment,{children:[c.jsx(_.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},enableSizes:f,x:0,y:0,width:(g=t.target)==null?void 0:g.spatial.width,height:(p=t.target)==null?void 0:p.spatial.height,crop:d}),s]},"service"):c.jsxs(u.Fragment,{children:[c.jsx("world-image",{onClick:l,uri:t.id,target:{x:0,y:0,width:t.target.spatial.width,height:t.target.spatial.height},display:t.width&&t.height?{width:t.width,height:t.height}:void 0,crop:d}),s]},"no-service")},e+(t.service?"server":"no-service"))}function Cn(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function be(e,t){const{selector:n,source:r}=Bt.expandTarget(t);if(r.id!==e.id)return[null,r];const o={type:"BoxSelector",spatial:{x:0,y:0,width:Number(e.width),height:Number(e.height)}};return[n?n.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:n.temporal,spatial:o.spatial}:n:null,r]}const nt={makeChoice:()=>{}},ee={type:"unknown"},P=e=>({type:"unknown",reason:e,annotations:{pages:[]}}),rt=(e,t)=>({type:"empty",width:e,height:t,annotations:{pages:[]},image:null,images:[]});function bn(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 wn(e,t){return E(n=>{const r=[];if(!e)return r;const o=Object.keys(n.iiif.entities.AnnotationPage);for(const i of o)if(!t||t.indexOf(i)!==-1){const s=bn(n,i);s&&s.views&&s.views[e]&&r.push(i)}return r},[e,t])}function ot({canvas:e,manifest:t,all:n,canvases:r}){const o=[];if(t)for(const i of t.annotations)o.indexOf(i.id)===-1&&o.push(i.id);if(n){if(r&&r.length)for(const i of r)for(const s of i.annotations)o.indexOf(s.id)===-1&&o.push(s.id)}else if(e)for(const i of e.annotations)o.indexOf(i.id)===-1&&o.push(i.id);return o}function Pn(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 it(e,t={}){const n=M(),r=D(),o=V(),i=ve(),s=u.useMemo(()=>ot({all:t.all,manifest:r,canvas:o,canvases:i}),[t.all,o,i,r]),a=wn(e,t.all?void 0:s),l=u.useCallback(d=>{e&&n.setMetaValue([d,"annotationPageManager","views"],g=>g&&!g[e]?g:{...g||{},[e]:!1})},[e,n]),f=u.useCallback((d,g={})=>{if(!e)return;const p=n.getState(),y=[];if(g!=null&&g.deselectOthers){const m=Object.keys(p.iiif.entities.AnnotationPage);for(const h of m){const x=Pn(p,h);x&&x.views&&x.views[e]&&y.push(h)}}for(const m of y)l(m);n.setMetaValue([d,"annotationPageManager","views"],m=>m&&m[e]?m:{...m||{},[e]:!0})},[e,l,n]);return{availablePageIds:s,enabledPageIds:a,setPageEnabled:f,setPageDisabled:l}}function st(e,t){return E((n,r)=>r.get(e.map(o=>({id:o,type:t}))),[e,t])}const at=u.createContext(new te.ImageServiceLoader);function ie(){return u.useContext(at)}function ut(){const e=ie(),[t,n]=u.useState({}),r=u.useRef(!1);return u.useEffect(()=>()=>{r.current=!0},[]),[u.useCallback((i,{height:s,width:a})=>{if(i){const l=i.id||i["@id"],f=e.loadServiceSync({id:l,width:i.width||a,height:i.height||s,source:i});f?i=f:t[l]||(r.current||n(d=>({...d,[l]:"loading"})),e.loadService({id:l,width:i.width||a,height:i.height||s}).then(()=>{r.current||n(d=>({...d,[l]:"done"}))}))}return i},[e,t]),t]}function se(e={}){const t=Ce(),n=V(e.canvasId?{id:e.canvasId}:void 0);return E((r,o)=>{if(!n)return[];if(t&&e.enableSingleAnnotation)return[t];const i=o.get(n.items),s=[];for(const a of i)s.push(...o.get(a.items));return s},[n])}function Mn(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}const Z={},ct={get(e){return e},setMetaValue([e,t,n],r){const o=ct.getResourceMeta(e,t),i=o?o[n]:void 0,s=typeof r=="function"?r(i):r;Z[e]={...Z[e]||{},[t]:{...(Z[e]||{})[t]||{},[n]:s}}},getResourceMeta:(e,t)=>{const n=Z[e];if(n)return t?n[t]:n}};function jn(e=ct){function t(o){const i=o?typeof o=="string"?e.get(o):o:null;if(!i)return[];const s=e.get(i.items,{parent:i}),a=[];for(const l of s)a.push(...e.get(l.items,{parent:l}));return a}function n(o,i=[]){const s=Array.isArray(o)?o:t(o),a=[];let l=null;const f=[];for(const d of s){if(d.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const g=Array.from(Array.isArray(d.body)?d.body:[d.body]);for(const p of g){const[y,{selector:m}]=Mn(p),h=e.get(y),x=(h.type||"unknown").toLowerCase();if(x==="choice"){const C=e.get(h.items,{parent:h.id}),j=i.length?i.map(S=>C.find(L=>L.id===S)).filter(Boolean):[C[0]];j.length===0&&j.push(C[0]),l={type:"single-choice",items:C.map(S=>({id:S.id,label:S.label,selected:j.indexOf(S)!==-1})),label:y.label},g.push(...j);continue}a.indexOf(x)===-1&&a.push(x),f.push({type:x,annotationId:d.id,resource:h,target:d.target,selector:m})}}return{types:a,items:f,choice:l}}function r(o){const{choice:i}=n(o);return i}return{getAllPaintingAnnotations:t,getPaintables:n,extractChoices:r}}function lt(e,t=[]){const n=M(),r=u.useMemo(()=>jn(n),[]),o=se({enableSingleAnnotation:e==null?void 0:e.enableSingleAnnotation}),[i,s]=u.useState((e==null?void 0:e.defaultChoices)||[]),a=u.useMemo(()=>r.getPaintables(o,i),[n,o,i,...t]),f={makeChoice:u.useCallback((d,{deselectOthers:g=!0,deselect:p=!1}={})=>{if(a.choice){if(a.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");s(y=>{if(p){const h=y.filter(x=>x!==d);if(h.length===0){const x=a.items[0].resource.id;return x?[x]:[]}return h}if(g)return[d];const m=[...y];if(m.length===0&&a.items.length){const h=a.items[0].resource.id;h&&m.push(h)}return y.indexOf(d)!==-1?y:[...y,d]})}},[a.choice])};return[a,f]}const En=["model/gltf-binary"];function dt(e,t){const r=t.items[0].resource;return r.format?En.indexOf(r.format)===-1?P(`3D format: ${r.format} is unsupported`):{type:"3d-model",model:r}:P("Unknown format")}function In(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 ft(e,t,n){const r=[];for(const o of t.items){const i=o.resource&&o.resource.type==="SpecificResource"?o.resource.source:o.resource;if(!i.id)return P("No resource Identifier");let s;if(i.service){const y=te.getImageServices(i);y[0]&&(s=n(y[0],e))}const a={type:"BoxSelector",spatial:{x:0,y:0,width:Number(e.width),height:Number(e.height)}},[l,f]=be(e,o.target);if(f.id!==e.id)continue;o.resource.width&&o.resource.height&&(o.resource.width,o.resource.height);let d=o.resource.type==="SpecificResource"?Y.expandTarget(o.resource):null;if(o.selector){const y=Y.expandTarget({type:"SpecificResource",source:o.resource,selector:o.selector});y&&(d=y)}const g=d&&d.selector&&(d.selector.type==="BoxSelector"||d.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:d.selector.spatial.x,y:d.selector.spatial.y,width:d.selector.spatial.width,height:d.selector.spatial.height}}:void 0;s&&!s.id&&(s.id=s["@id"]);const p={id:i.id,type:"Image",annotationId:o.annotationId,width:Number(l||g?i.width:e.width),height:Number(l||g?i.height:e.height),service:s,sizes:s&&s.sizes?s.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:l&&l.type!=="PointSelector"?l:a,selector:g};r.push(p)}return{type:"images",image:r[0],images:r,choice:t.choice}}function gt(e,t={},n){const r=e.language||n||"none";switch(e.type){case"TextualBody":{typeof e.value<"u"&&(t[r]=e.value);break}case"List":case"Composite":case"Choice":e.items&&e.items.forEach(o=>gt(o,t,r))}return t}function ht(e,t){const n=[];return t.items.forEach(r=>{if(r.resource){const[o]=be(e,r.target);n.push({annotationId:r.annotationId,text:gt(r.resource),target:o})}}),{type:"textual-content",items:n}}const Rn=/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?vi?=|&vi?=))([^#&?]*).*/;function mt(e,t){var s;const n=t.items.filter(a=>a.type==="video");if(!e.duration)return P("No duration on canvas");if(n.length>1)return P("Only one video source supported");const r=(s=n[0])==null?void 0:s.resource,o=!!(r.service||[]).find(a=>(a.profile||"").includes("youtube.com"));if(!r)return P("Unknown video");if((!r.format||r.format==="text/html")&&!o)return P("Video does not have format");const i={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}}};if(o){i.type="VideoYouTube";const a=r.id.match(Rn);if(!a[1])return P("Video is not known youtube video");i.youTubeId=a[1]}return{type:"media",media:i,annotations:{pages:[]}}}function vt({canvas:e,paintables:t,supports:n,loadImageService:r}){if(!e)return console.log("No canvas"),ee;if(t.types.length===0)return n.indexOf("empty")!==-1?rt(e.width,e.height):(console.log("No paintables"),ee);if(t.types.length!==1)if(t.types.length===2&&t.types.indexOf("text")!==-1)t.types=t.types.filter(i=>i!=="text");else return n.indexOf("complex-timeline")===-1?P("Complex timeline not supported"):P("ComplexTimelineStrategy not yet supported");const o=t.types[0];return o==="image"?n.indexOf("images")===-1?P("Image not supported"):ft(e,t,r):o==="Model"||o==="model"?n.indexOf("3d-model")===-1?P("3D not supported"):dt(e,t):o==="textualbody"?n.indexOf("textual-content")===-1?P("Textual content not supported"):ht(e,t):o==="sound"||o==="audio"?n.indexOf("media")===-1?P("Media not supported"):In(e,t):o==="video"?n.indexOf("media")===-1?P("Media not supported"):mt(e,t):ee}function pt(e){const t=D(),n=V(),r=M(),[o,i]=ut(),{enabledPageIds:s}=it((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(n==null?void 0:n.id),{all:!1}),a=st(s,"AnnotationPage"),l=(e==null?void 0:e.strategies)||["empty","images","media","textual-content","complex-timeline"],[f,d]=lt(e,[i]),g=u.useMemo(()=>vt({canvas:n,paintables:f,supports:l,loadImageService:o}),[n,f,r,d.makeChoice]);return u.useMemo(()=>g.type==="unknown"?[g,nt]:[{...g,annotations:{pages:a}},d],[g,a])}const yt=(e,t=[])=>{const n=M();u.useEffect(()=>{e(n)},[n,...t])};function xt(e,t,{canvasId:n,manifestId:r}={}){const o=M(),i=ie(),s=u.useMemo(()=>Ht.createThumbnailHelper(o,{imageServiceLoader:i}),[o,i]),[a,l]=u.useState(),f=D(r?{id:r}:void 0),d=V(n?{id:n}:void 0),g=d||f,p=u.useRef(!1);if(u.useEffect(()=>(p.current=!1,()=>{p.current=!0}),[]),!g)throw new Error("Must be called under a manifest or canvas context.");return yt(y=>{s.getBestThumbnailAtSize(g,e,t).then(m=>{m.best&&!p.current&&l(m.best)})},[g]),a}function An(e){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:e}}function Tn(e,t){switch(t.type){case"FINISHED":return{...e,isFinished:!0,isPlaying:!1,playRequested:!1};case"PLAY_PAUSE":return{...e,isFinished:!1,isPlaying:!e.isPlaying};case"PLAY_REQUESTED":return{...e,isFinished:!1,playRequested:!0};case"PAUSE":return{...e,isPlaying:!1};case"PLAY":return{...e,isFinished:!1,playRequested:!1,isPlaying:!0};case"MUTE":return{...e,isMuted:!0};case"SET_VOLUME":return{...e,volume:t.volume,isMuted:t.volume===0};case"TOGGLE_MUTE":return{...e,isMuted:!e.isMuted};case"UNMUTE":return{...e,isMuted:!1}}return e}function St(e){const t=Math.round(e);return`${Math.floor(t/60)}:${`${t%60}`.padStart(2,"0")}`}function ae(e){const[t,n]=u.useReducer(Tn,An(e.duration)),r=u.useRef(null),o=u.useRef(null),i=u.useRef(null),s=u.useRef(!1),a=u.useCallback(()=>{o.current&&r.current&&(o.current.innerHTML=St(r.current.currentTime),i.current&&(i.current.style.width=`${r.current.currentTime/e.duration*100}%`),s.current!==r.current.muted&&(s.current=r.current.muted,n(r.current.muted?{type:"MUTE"}:{type:"UNMUTE"})))},[e.duration]),l=u.useCallback(()=>{r.current&&(n({type:"PLAY_REQUESTED"}),r.current.play().then(()=>{n({type:"PLAY"})}),a())},[a]),f=u.useCallback(()=>{r.current&&(r.current.duration>0&&r.current.paused?l():d())},[a]),d=u.useCallback(()=>{r.current&&(r.current.pause(),n({type:"PAUSE"}),a())},[a]),g=u.useCallback(()=>{r.current&&(r.current.muted=!r.current.muted,n(r.current.muted?{type:"MUTE"}:{type:"UNMUTE"}))},[]),p=u.useCallback(()=>{r.current&&(r.current.muted=!0,n({type:"MUTE"}))},[]),y=u.useCallback(()=>{r.current&&(r.current.muted=!1,n({type:"UNMUTE"}))},[]),m=u.useCallback(C=>{r.current&&(r.current.muted=!1,r.current.volume=C/100,n({type:"SET_VOLUME",volume:C}))},[]),h=u.useCallback(C=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(C*e.duration,e.duration)),a())},[]),x=u.useCallback(C=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(C,e.duration)),a())},[]);return u.useEffect(()=>{const C=setInterval(()=>{a()},350);return()=>clearInterval(C)},[a,e.duration]),u.useEffect(()=>{const C=()=>{n({type:"FINISHED"})},j=r.current;return j==null||j.addEventListener("ended",C),()=>j==null?void 0:j.removeEventListener("ended",C)},[]),[{element:r,currentTime:o,progress:i},t,{play:l,pause:d,playPause:f,mute:p,unmute:y,toggleMute:g,setVolume:m,setDurationPercent:h,setTime:x}]}const Ct=u.createContext(null),bt=u.createContext(null),wt=u.createContext(null);function Vn(){const e=u.useContext(Ct);if(!e)throw new Error("Ctx not found");return e}function Ln(){const e=u.useContext(bt);if(!e)throw new Error("Ctx not found");return e}function kn(){const e=u.useContext(wt);if(!e)throw new Error("Ctx not found");return e}function we({actions:e,state:t,children:n,currentTime:r,progress:o,element:i}){return c.jsx(wt.Provider,{value:{currentTime:r,progress:o,element:i},children:c.jsx(bt.Provider,{value:e,children:c.jsx(Ct.Provider,{value:t,children:n})})})}function Pt({media:e,children:t}){const[{element:n,currentTime:r,progress:o},i,s]=ae({duration:e.duration});return c.jsxs(we,{state:i,actions:s,currentTime:r,progress:o,element:n,children:[c.jsx("audio",{ref:n,src:e.url}),t]})}function Mt({media:e,mediaControlsDeps:t,children:n}){return U("portal","audio",Pt,{media:e,children:n},[e,...t||[]]),null}function jt({element:e,media:t,playPause:n}){return c.jsxs("div",{className:"video-container",part:"video-container",onClick:n,children:[c.jsx("style",{children:`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),u=require("react"),_=require("@atlas-viewer/atlas"),X=require("@iiif/helpers/vault"),ge=require("@iiif/helpers/styles"),Y=require("@iiif/helpers/annotation-targets"),Bt=require("@iiif/helpers"),te=require("@atlas-viewer/iiif-image-api"),Ht=require("@iiif/helpers/thumbnail");function $t(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const ce=$t(u);function de(e,t){return de=Object.setPrototypeOf||function(r,o){return r.__proto__=o,r},de(e,t)}function Yt(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,de(e,t)}var zt=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])})},Ie={error:null},Kt=function(e){Yt(t,e);function t(){for(var r,o=arguments.length,i=new Array(o),s=0;s<o;s++)i[s]=arguments[s];return r=e.call.apply(e,[this].concat(i))||this,r.state=Ie,r.resetErrorBoundary=function(){for(var a,l=arguments.length,f=new Array(l),d=0;d<l;d++)f[d]=arguments[d];r.props.onReset==null||(a=r.props).onReset.apply(a,f),r.reset()},r}t.getDerivedStateFromError=function(o){return{error:o}};var n=t.prototype;return n.reset=function(){this.setState(Ie)},n.componentDidCatch=function(o,i){var s,a;(s=(a=this.props).onError)==null||s.call(a,o,i)},n.componentDidUpdate=function(o,i){var s=this.state.error,a=this.props.resetKeys;if(s!==null&&i.error!==null&&zt(o.resetKeys,a)){var l,f;(l=(f=this.props).onResetKeysChange)==null||l.call(f,o.resetKeys,a),this.reset()}},n.render=function(){var o=this.state.error,i=this.props,s=i.fallbackRender,a=i.FallbackComponent,l=i.fallback;if(o!==null){var f={error:o,resetErrorBoundary:this.resetErrorBoundary};if(ce.isValidElement(l))return l;if(typeof s=="function")return s(f);if(a)return ce.createElement(a,f);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},t}(ce.Component);const Wt={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},ne=u.createContext(Wt),O=()=>u.useContext(ne);function N({value:e,children:t}){const n=O(),r=u.useMemo(()=>({...n,...e}),[e,n]);return c.jsx(ne.Provider,{value:r,children:t})}const K=u.createContext({vault:null,setVaultInstance:e=>{}});function he({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:o}){const[i,s]=u.useState(()=>e||(n?X.globalVault(t):t?new X.Vault(t):new X.Vault));return c.jsx(K.Provider,{value:{vault:i,setVaultInstance:s},children:c.jsx(N,{value:r||{},children:o})})}const M=()=>{const{vault:e}=u.useContext(K);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};function me(e,{noCache:t=!1}={}){const n=typeof e=="string"?e:e.id,r=M(),[o,i]=u.useState(n),[s,a]=u.useState(void 0),l=u.useMemo(()=>r.get(n,{skipSelfReturn:!0})||void 0,[n,r]),[f,d]=u.useState(l);return u.useEffect(()=>{(async()=>{try{const g=l&&!t?l:await r.load(n),p=g?g.id||g["@id"]:null;g&&o!==p&&i(p),d(g)}catch(g){a(g)}})()},[n,t]),{isLoaded:!!f,id:o,requestId:n,error:s,resource:f,cached:!!(f&&f===l)}}function Te(e,t){const{id:n,isLoaded:r,error:o,resource:i,requestId:s,cached:a}=me(e,t);return{id:n,isLoaded:r,error:o,manifest:i,requestId:s,cached:a}}function Ve({manifest:e,children:t}){return c.jsx(N,{value:{manifest:e},children:t})}function re({canvas:e,children:t}){return c.jsx(N,{value:{canvas:e},children:t})}function E(e,t=[]){const n=M(),[r,o]=u.useState(()=>e(n.getState(),n));return u.useEffect(()=>n.subscribe(i=>e(i,n),i=>{o(i)},!1),t),r}const W=u.createContext([]);function ve(){const e=u.useContext(W);return E(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}function D(e={},t=[]){const{id:n,selector:r}=e,o=O();M();const i=n||o.manifest,s=E(a=>i?a.iiif.entities.Manifest[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}function Le({range:e,children:t}){return c.jsx(N,{value:{range:e},children:t})}function ke(e,t){for(const n of t.items){if(n.type==="Canvas")return n;if(n.type==="SpecificResource")return n.source;if(n.type==="Range"){const r=ke(e,e.get(n));if(r)return r}}return null}function pe(e,t){var r;const n=[];for(const o of t.items)if(o.type==="SpecificResource"&&((r=o.source)==null?void 0:r.type)==="Canvas"&&(o.source.id.indexOf("#")!==-1?n.push({id:o.source.id.split("#")[0],type:"Canvas"}):n.push(o.source)),o.type==="Range"&&n.push(...pe(e,e.get(o))),o.type==="SpecificResource"){const i=typeof o.source=="string"?o.source:o.source.id;n.push({id:i,type:"Canvas"})}return n}function Gt(e,t,n){for(const r of t.structures){const o=ye(e,e.get(r),n);if(o)return o}return null}function ye(e,t,n){var r,o,i;for(const s of t.items){const a=(o=(r=s==null?void 0:s.source)==null?void 0:r.id)==null?void 0:o.split("#")[0];if(s.type==="SpecificResource"&&s.source===n||s.type==="SpecificResource"&&((i=s.source)==null?void 0:i.type)==="Canvas"&&n===a)return t;if(s.type==="Range"){const l=ye(e,e.get(s),n);if(l)return l}}return null}function Qt(e,t,n,r=!1){const o=t.behavior,i=n?e.get(n):null;if(!i)return[];const s=i.behavior,a=r?!1:o.includes("paged"),l=a?!1:o.includes("continuous"),f=a||l?!1:o.includes("individuals"),d=s.includes("facing-pages"),g=s.includes("non-paged");if(d||g||f||r)return[{id:i.id,type:"Canvas"}];const[p,y]=xe(e,t);if(l)return p;const m=p.findIndex(h=>h.id===n);if(m===-1)return[];for(const h of y)if(h.includes(m))return h.map(x=>p[x]);return[{id:i.id,type:"Canvas"}]}function xe(e,t,{disablePaging:n,skipNonPaged:r}={}){const o=t.behavior,i=o.includes("paged"),s=i?!1:o.includes("continuous"),a=i||s?!1:o.includes("individuals"),l=t.type==="Manifest"?t.items:pe(e,t);if(s)return[l,[l.map((m,h)=>h)]];if(a||!i||n)return[l,l.map((m,h)=>[h])];const f=[];let d=[];const g=()=>{d.length&&(f.push([...d]),d=[])};let p=0,y=!1;for(let m=0;m<l.length;m++){const h=e.get(l[m]);if(h.behavior.includes("non-paged")){m===p&&p++,r||(g(),f.push([m]),g());continue}if(m===p||h.behavior.includes("facing-pages")){d.length&&(y=!0),g(),f.push([m]),g();continue}if(d.push(m),y){g(),y=!1;continue}d.length>1&&g()}return d.length&&g(),[l,f]}function Oe(e={},t=[]){const{id:n,selector:r}=e,o=O(),i=n||o.range,s=E(a=>i?a.iiif.entities.Range[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}function Fe({startCanvas:e,disablePaging:t}){var m;const n=M(),r=D(),o=Oe(),[i,s]=u.useState(void 0),a=o||r;if(!a)throw new Error("Nothing selected");const[l,f]=u.useMemo(()=>xe(n,a,{disablePaging:t}),[n,a]),d=u.useCallback(h=>{const x=f.findIndex(C=>C.includes(h));s(x===-1?0:x)},[l,f]),g=u.useCallback(h=>{const x=l.findIndex(C=>C.id===h);x!==-1?d(x):s(0)},[l,f]),p=u.useCallback(()=>{s(h=>h>=f.length?h:h+1)},[f]),y=u.useCallback(()=>{s(h=>h<=0?0:h-1)},[f]);return typeof i>"u"&&(e?g(e):s(0)),{visibleItems:((m=f[i])==null?void 0:m.map(h=>l[h].id))||[],cursor:i,items:l,sequence:f,setSequenceIndex:s,setCanvasIndex:d,setCanvasId:g,next:p,previous:y}}const $=()=>{},G=u.createContext({setCurrentCanvasId:$,setCurrentCanvasIndex:$,nextCanvas:$,previousCanvas:$,items:[],sequence:[],setSequenceIndex:$,currentSequenceIndex:0});function Ne(e){const t=D(),{cursor:n,visibleItems:r,next:o,sequence:i,items:s,setCanvasIndex:a,setCanvasId:l,previous:f,setSequenceIndex:d}=Fe({startCanvas:e.startCanvas,disablePaging:e.pagingEnabled===!1}),g=u.useMemo(()=>({sequence:i,items:s,setCurrentCanvasId:l,nextCanvas:o,previousCanvas:f,totalCanvases:s.length,setCurrentCanvasIndex:a,setSequenceIndex:d,currentSequenceIndex:n}),[i,s,l,o,f,s,a,d,n]);return t?r.length===0?null:c.jsx(G.Provider,{value:g,children:c.jsx(W.Provider,{value:r,children:c.jsx(re,{canvas:r[0],children:e.children})})}):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),c.jsx("div",{children:"Sorry, something went wrong."}))}function De(e){const t=Te(e.manifest);if(!t)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),c.jsx("div",{children:"Sorry, something went wrong."});if(t.error)return c.jsx("div",{children:t.error.toString()});if(!t.isLoaded)return c.jsx("div",{children:"Loading..."});const n=c.jsx(Ne,{...e,children:e.children});return c.jsx(Ve,{manifest:t.id,children:e.rangeId?c.jsx(Le,{range:e.rangeId,children:n}):n})}function qe(){return u.useContext(G)}function _e(){return{VaultContext:u.useContext(K),ResourceContext:u.useContext(ne),SimpleViewerReactContext:u.useContext(G),VisibleCanvasReactContext:u.useContext(W)}}function Ue(e){return c.jsx(he,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext,children:c.jsx(W.Provider,{value:e.bridge.VisibleCanvasReactContext,children:c.jsx(G.Provider,{value:e.bridge.SimpleViewerReactContext,children:e.children})})})}const T=function(e){return function(){const t={type:e,getType:()=>e,toString:()=>e};return(n,r)=>({...t,...n!==void 0&&{payload:n},...r!==void 0&&{meta:r}})}},Jt="@iiif/IMPORT_ENTITIES",Zt="@iiif/MODIFY_ENTITY_FIELD",Xt="@iiif/REORDER_ENTITY_FIELD",en="@iiif/ADD_REFERENCE",tn="@iiif/UPDATE_REFERENCE",nn="@iiif/REMOVE_REFERENCE",rn="@iiif/ADD_METADATA",on="@iiif/REMOVE_METADATA",sn="@iiif/UPDATE_METADATA",an="@iiif/REORDER_METADATA",un=T(Jt)(),cn=T(Zt)(),ln=T(Xt)(),dn=T(en)(),fn=T(nn)(),gn=T(tn)(),hn=T(rn)(),mn=T(sn)(),vn=T(on)(),pn=T(an)(),le={importEntities:un,modifyEntityField:cn,reorderEntityField:ln,addReference:dn,removeReference:fn,updateReference:gn,addMetadata:hn,removeMetadata:vn,updateMetadata:mn,reorderMetadata:pn};function Be(){const t=M().getStore();return u.useMemo(()=>n=>t.dispatch(n),[t])}function Re(e){return typeof e!="string"&&e&&e.bindToVault}function He(){const e=M(),t=u.useRef([]),n=Be(),r=u.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);u.useLayoutEffect(()=>{const a={id:r,type:"AnnotationPage",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],rendering:[],service:[]};n(le.importEntities({entities:{AnnotationPage:{[a.id]:a}}}))},[r]);const o=E(a=>r?a.iiif.entities.AnnotationPage[r]:null,[r]),i=u.useCallback((a,l)=>{if(r){if(Re(a)){const g=a;g.__vault||g.bindToVault(e),a=typeof g.source=="string"?g.source:g.source.id,t.current[a]=g}else typeof a!="string"&&(a=a.id);const f=e.get({id:r,type:"AnnotationPage"}),d=e.get({id:a,type:"Annotation"});f&&d&&(f.items.find(g=>g.id===d.id)||n(le.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"},index:l})))}},[r]),s=u.useCallback(a=>{r&&(Re(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(le.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"}})))},[r]);return[o,{addAnnotation:i,removeAnnotation:s}]}const $e=u.createContext(null);function Ye(){const e=u.useContext($e);return[e.fullPage,{addAnnotation:e.addAnnotation,removeAnnotation:e.removeAnnotation}]}function ze({children:e}){const[t,{addAnnotation:n,removeAnnotation:r}]=He();return c.jsx($e.Provider,{value:u.useMemo(()=>({fullPage:t,addAnnotation:n,removeAnnotation:r}),[t]),children:e})}function yn({width:e,style:t,height:n,error:r,resetErrorBoundary:o}){return c.jsxs("div",{style:{width:e,height:n,minHeight:500,...t||{},background:"#f9f9f9"},children:[c.jsx("h3",{children:"Error occurred"}),c.jsx("p",{children:r.message}),c.jsx("button",{onClick:o,children:"Reset"})]})}const oe=u.createContext(null);function Ke(){return u.useContext(oe)}const We=u.createContext(()=>{}),Ge=u.createContext(()=>{});function U(e,t,n,r,o=[]){const i=u.useContext(e==="portal"?Ge:We);u.useEffect(()=>(e!=="none"&&i(t,n,r),()=>{i(t,null)}),[t,e,i,...o])}function V(e={},t=[]){const{id:n,selector:r}=e,o=O(),i=n||o.canvas,s=E(a=>i?a.iiif.entities.Canvas[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}const Qe=u.createContext(()=>{});function xn(e){const t=V(),n=u.useContext(Qe);u.useEffect(()=>t&&t.id?(n(t.id,e),()=>n(t.id,-1)):()=>{},[t,e])}function Sn({children:e,errorFallback:t,outerContainerProps:n={},worldScale:r,...o}){const[i,s]=u.useState(),a=_e(),l=t||yn,[f,d]=u.useState({}),g=Object.entries(f),[p,y]=u.useState({}),m=Object.entries(p),[h,x]=u.useState({}),C=u.useMemo(()=>r||Math.max(...Object.values(h)),[h]),j=u.useMemo(()=>({maxOverZoom:C||1,...o.runtimeOptions||{}}),[C,o.runtimeOptions]),S=u.useCallback((w,I)=>{x(A=>{if(I===-1){const{[w]:v,...k}=A;return k}return{...A,[w]:I}})},[]),L=u.useCallback((w,I,A)=>{d(({[w]:v,...k})=>I?{...k,[w]:{element:I,props:A}}:k)},[]),Q=u.useCallback((w,I,A)=>{y(({[w]:v,...k})=>I?{...k,[w]:{element:I,props:A}}:k)},[]);return c.jsxs(Kt,{resetKeys:[],fallbackRender:w=>c.jsx(l,{...o,...w}),children:[c.jsx(_.AtlasAuto,{...o,containerProps:{style:{position:"relative"},...o.containerProps||{}},htmlChildren:c.jsx(c.Fragment,{children:g.map(([w,{element:I,props:A}])=>c.jsx(u.Fragment,{children:c.jsx(I,{...A||{}})},w))}),onCreated:w=>{s(w),o.onCreated&&o.onCreated(w)},runtimeOptions:j,children:c.jsx(oe.Provider,{value:i,children:c.jsx(Qe.Provider,{value:S,children:c.jsx(We.Provider,{value:L,children:c.jsx(Ge.Provider,{value:Q,children:c.jsx(Ue,{bridge:a,children:c.jsx(_.ModeContext.Provider,{value:o.mode||"explore",children:c.jsx(ze,{children:e})})})})})})})}),c.jsx("div",{children:m.map(([w,{element:I,props:A}])=>c.jsx(u.Fragment,{children:c.jsx(I,{...A||{}})},w))})]})}const J={},Je={get(e){return e},setMetaValue([e,t,n],r){const o=Je.getResourceMeta(e,t),i=o?o[n]:void 0,s=typeof r=="function"?r(i):r;J[e]={...J[e]||{},[t]:{...(J[e]||{})[t]||{},[n]:s}}},getResourceMeta:(e,t)=>{const n=J[e];if(n)return t?n[t]:n}};function Ze(e=Je){return{addEventListener(t,n,r,o){if(t)return e.setMetaValue([t.id,"eventManager",n],i=>{const s=i||[];for(const a of s)if(a.callback===r)return s;return[...s,{callback:r,scope:o}]}),r},removeEventListener(t,n,r){t&&e.setMetaValue([t.id,"eventManager",n],o=>(o||[]).filter(i=>i.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"),i={};if(o&&r)for(const s of Object.keys(o))i[s]=a=>{const l=e.get(r);for(const{callback:f,scope:d}of o[s]||[])(!d||n&&d.indexOf(n)!==-1)&&f(a,l)};return i}}}function Se(e,t){const n=M(),r=u.useMemo(()=>Ze(n),[n]),o=E(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return u.useMemo(()=>e?r.getListenersAsProps(e,t):{},[o,e,n,t])}function z(e,t){const n=M(),r=u.useMemo(()=>ge.createStylesHelper(n),[n]);return E(()=>{if(!e)return null;const o=r.getAppliedStyles(e.id);return o?t?o[t]:o:void 0},[e,t])}function Ce(e={},t=[]){const{id:n,selector:r}=e,o=O(),i=M(),s=n||o.annotation,a=E(f=>s?f.iiif.entities.Annotation[s]:void 0,[s]),l=E(f=>a&&a.body?a.body.map(d=>d?d.type==="SpecificResource"?{...d,source:i.get(d)}:d?f.iiif.entities[d.type][d.id]:null:null).filter(Boolean):[],[a]);return u.useMemo(()=>{if(!a)return;const f={...a,body:l,target:Y.expandTarget(a.target,{typeMap:i.getState().iiif.mapping})};return r?r(f):f},[a,r,l,...t])}const Xe=({id:e,style:t,className:n,interactive:r})=>{const o=Ce({id:e}),i=z(o,"atlas"),s=z(o,"html"),a=Se(o,["atlas"]),l=V(),f=u.useMemo(()=>_.mergeStyles(t,i),[t,i]);return l&&o&&o.target&&o.target.selector&&o.target.selector.type==="BoxSelector"&&o.target.source&&(o.target.source.id===l.id||o.target.source===l.id)?c.jsx(_.RegionHighlight,{id:o.id,isEditing:!0,region:o.target.selector.spatial,style:f,className:(s==null?void 0:s.className)||n,interactive:!!(s!=null&&s.href||r),href:(s==null?void 0:s.href)||null,title:(s==null?void 0:s.title)||null,hrefTarget:(s==null?void 0:s.target)||null,onClick:()=>{},...a}):null};function et(e={},t=[]){const{id:n,selector:r}=e,o=O(),i=n||o.annotationPage,s=E(a=>i?a.iiif.entities.AnnotationPage[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,...t])}const fe=({className:e,page:t})=>{var i;const n=et({id:t.id})||t,r=z(n,"atlas"),o=z(n,"html");return E(s=>n.id?s.iiif.entities.AnnotationPage[n.id]:null,[]),c.jsx(u.Fragment,{children:(i=n.items)==null?void 0:i.map(s=>c.jsx(Xe,{id:s.id,style:r,className:(o==null?void 0:o.className)||e},s.id))})};function tt({id:e,image:t,thumbnail:n,isStatic:r,x:o=0,y:i=0,children:s,selector:a,onClick:l,enableSizes:f}){var g,p;const d=u.useMemo(()=>{if(!(!a||a.spatial.x===0&&a.spatial.y===0))return a.spatial},[a]);return c.jsx("world-object",{x:o+t.target.spatial.x,y:i+t.target.spatial.y,width:t.target.spatial.width,height:t.target.spatial.height,onClick:l,children:t.service?c.jsxs(u.Fragment,{children:[c.jsx(_.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},enableSizes:f,x:0,y:0,width:(g=t.target)==null?void 0:g.spatial.width,height:(p=t.target)==null?void 0:p.spatial.height,crop:d}),s]},"service"):c.jsxs(u.Fragment,{children:[c.jsx("world-image",{onClick:l,uri:t.id,target:{x:0,y:0,width:t.target.spatial.width,height:t.target.spatial.height},display:t.width&&t.height?{width:t.width,height:t.height}:void 0,crop:d}),s]},"no-service")},e+(t.service?"server":"no-service"))}function Cn(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function be(e,t){const{selector:n,source:r}=Bt.expandTarget(t);if(r.id!==e.id)return[null,r];const o={type:"BoxSelector",spatial:{x:0,y:0,width:Number(e.width),height:Number(e.height)}};return[n?n.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:n.temporal,spatial:o.spatial}:n:null,r]}const nt={makeChoice:()=>{}},ee={type:"unknown"},P=e=>({type:"unknown",reason:e,annotations:{pages:[]}}),rt=(e,t)=>({type:"empty",width:e,height:t,annotations:{pages:[]},image:null,images:[]});function bn(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 wn(e,t){return E(n=>{const r=[];if(!e)return r;const o=Object.keys(n.iiif.entities.AnnotationPage);for(const i of o)if(!t||t.indexOf(i)!==-1){const s=bn(n,i);s&&s.views&&s.views[e]&&r.push(i)}return r},[e,t])}function ot({canvas:e,manifest:t,all:n,canvases:r}){const o=[];if(t)for(const i of t.annotations)o.indexOf(i.id)===-1&&o.push(i.id);if(n){if(r&&r.length)for(const i of r)for(const s of i.annotations)o.indexOf(s.id)===-1&&o.push(s.id)}else if(e)for(const i of e.annotations)o.indexOf(i.id)===-1&&o.push(i.id);return o}function Pn(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 it(e,t={}){const n=M(),r=D(),o=V(),i=ve(),s=u.useMemo(()=>ot({all:t.all,manifest:r,canvas:o,canvases:i}),[t.all,o,i,r]),a=wn(e,t.all?void 0:s),l=u.useCallback(d=>{e&&n.setMetaValue([d,"annotationPageManager","views"],g=>g&&!g[e]?g:{...g||{},[e]:!1})},[e,n]),f=u.useCallback((d,g={})=>{if(!e)return;const p=n.getState(),y=[];if(g!=null&&g.deselectOthers){const m=Object.keys(p.iiif.entities.AnnotationPage);for(const h of m){const x=Pn(p,h);x&&x.views&&x.views[e]&&y.push(h)}}for(const m of y)l(m);n.setMetaValue([d,"annotationPageManager","views"],m=>m&&m[e]?m:{...m||{},[e]:!0})},[e,l,n]);return{availablePageIds:s,enabledPageIds:a,setPageEnabled:f,setPageDisabled:l}}function st(e,t){return E((n,r)=>r.get(e.map(o=>({id:o,type:t}))),[e,t])}const at=u.createContext(new te.ImageServiceLoader);function ie(){return u.useContext(at)}function ut(){const e=ie(),[t,n]=u.useState({}),r=u.useRef(!1);return u.useEffect(()=>()=>{r.current=!0},[]),[u.useCallback((i,{height:s,width:a})=>{if(i){const l=i.id||i["@id"],f=e.loadServiceSync({id:l,width:i.width||a,height:i.height||s,source:i});f?i=f:t[l]||(r.current||n(d=>({...d,[l]:"loading"})),e.loadService({id:l,width:i.width||a,height:i.height||s}).then(()=>{r.current||n(d=>({...d,[l]:"done"}))}))}return i},[e,t]),t]}function se(e={}){const t=Ce(),n=V(e.canvasId?{id:e.canvasId}:void 0);return E((r,o)=>{if(!n)return[];if(t&&e.enableSingleAnnotation)return[t];const i=o.get(n.items),s=[];for(const a of i)s.push(...o.get(a.items));return s},[n])}function Mn(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}const Z={},ct={get(e){return e},setMetaValue([e,t,n],r){const o=ct.getResourceMeta(e,t),i=o?o[n]:void 0,s=typeof r=="function"?r(i):r;Z[e]={...Z[e]||{},[t]:{...(Z[e]||{})[t]||{},[n]:s}}},getResourceMeta:(e,t)=>{const n=Z[e];if(n)return t?n[t]:n}};function jn(e=ct){function t(o){const i=o?typeof o=="string"?e.get(o):o:null;if(!i)return[];const s=e.get(i.items,{parent:i}),a=[];for(const l of s)a.push(...e.get(l.items,{parent:l}));return a}function n(o,i=[]){const s=Array.isArray(o)?o:t(o),a=[];let l=null;const f=[];for(const d of s){if(d.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const g=Array.from(Array.isArray(d.body)?d.body:[d.body]);for(const p of g){const[y,{selector:m}]=Mn(p),h=e.get(y),x=(h.type||"unknown").toLowerCase();if(x==="choice"){const C=e.get(h.items,{parent:h.id}),j=i.length?i.map(S=>C.find(L=>L.id===S)).filter(Boolean):[C[0]];j.length===0&&j.push(C[0]),l={type:"single-choice",items:C.map(S=>({id:S.id,label:S.label,selected:j.indexOf(S)!==-1})),label:y.label},g.push(...j);continue}a.indexOf(x)===-1&&a.push(x),f.push({type:x,annotationId:d.id,resource:h,target:d.target,selector:m})}}return{types:a,items:f,choice:l}}function r(o){const{choice:i}=n(o);return i}return{getAllPaintingAnnotations:t,getPaintables:n,extractChoices:r}}function lt(e,t=[]){const n=M(),r=u.useMemo(()=>jn(n),[]),o=se({enableSingleAnnotation:e==null?void 0:e.enableSingleAnnotation}),[i,s]=u.useState((e==null?void 0:e.defaultChoices)||[]),a=u.useMemo(()=>r.getPaintables(o,i),[n,o,i,...t]),f={makeChoice:u.useCallback((d,{deselectOthers:g=!0,deselect:p=!1}={})=>{if(a.choice){if(a.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");s(y=>{if(p){const h=y.filter(x=>x!==d);if(h.length===0){const x=a.items[0].resource.id;return x?[x]:[]}return h}if(g)return[d];const m=[...y];if(m.length===0&&a.items.length){const h=a.items[0].resource.id;h&&m.push(h)}return y.indexOf(d)!==-1?y:[...y,d]})}},[a.choice])};return[a,f]}const En=["model/gltf-binary"];function dt(e,t){const r=t.items[0].resource;return r.format?En.indexOf(r.format)===-1?P(`3D format: ${r.format} is unsupported`):{type:"3d-model",model:r}:P("Unknown format")}function In(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 ft(e,t,n){const r=[];for(const o of t.items){const i=o.resource&&o.resource.type==="SpecificResource"?o.resource.source:o.resource;if(!i.id)return P("No resource Identifier");let s;if(i.service){const y=te.getImageServices(i);y[0]&&(s=n(y[0],e))}const a={type:"BoxSelector",spatial:{x:0,y:0,width:Number(e.width),height:Number(e.height)}},[l,f]=be(e,o.target);if(f.id!==e.id)continue;o.resource.width&&o.resource.height&&(o.resource.width,o.resource.height);let d=o.resource.type==="SpecificResource"?Y.expandTarget(o.resource):null;if(o.selector){const y=Y.expandTarget({type:"SpecificResource",source:o.resource,selector:o.selector});y&&(d=y)}const g=d&&d.selector&&(d.selector.type==="BoxSelector"||d.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:d.selector.spatial.x,y:d.selector.spatial.y,width:d.selector.spatial.width,height:d.selector.spatial.height}}:void 0;s&&!s.id&&(s.id=s["@id"]);const p={id:i.id,type:"Image",annotationId:o.annotationId,width:Number(l||g?i.width:e.width),height:Number(l||g?i.height:e.height),service:s,sizes:s&&s.sizes?s.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:l&&l.type!=="PointSelector"?l:a,selector:g};r.push(p)}return{type:"images",image:r[0],images:r,choice:t.choice}}function gt(e,t={},n){const r=e.language||n||"none";switch(e.type){case"TextualBody":{typeof e.value<"u"&&(t[r]=e.value);break}case"List":case"Composite":case"Choice":e.items&&e.items.forEach(o=>gt(o,t,r))}return t}function ht(e,t){const n=[];return t.items.forEach(r=>{if(r.resource){const[o]=be(e,r.target);n.push({annotationId:r.annotationId,text:gt(r.resource),target:o})}}),{type:"textual-content",items:n}}const Rn=/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?vi?=|&vi?=))([^#&?]*).*/;function mt(e,t){var a;const n=t.items.filter(l=>l.type==="video");let r=!1;if(e.duration||(r=!0),n.length>1)return P("Only one video source supported");const o=(a=n[0])==null?void 0:a.resource,i=!!(o.service||[]).find(l=>(l.profile||"").includes("youtube.com"));if(!i&&r)return P("Video does not have duration");if(!o)return P("Unknown video");if((!o.format||o.format==="text/html")&&!i)return P("Video does not have format");const s={annotationId:t.items[0].annotationId,duration:e.duration,url:o.id,type:"Video",items:[],target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:o.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}};if(i){s.type="VideoYouTube";const l=o.id.match(Rn);if(!l[1])return P("Video is not known youtube video");s.youTubeId=l[1]}return{type:"media",media:s,annotations:{pages:[]}}}function vt({canvas:e,paintables:t,supports:n,loadImageService:r}){if(!e)return console.log("No canvas"),ee;if(t.types.length===0)return n.indexOf("empty")!==-1?rt(e.width,e.height):(console.log("No paintables"),ee);if(t.types.length!==1)if(t.types.length===2&&t.types.indexOf("text")!==-1)t.types=t.types.filter(i=>i!=="text");else return n.indexOf("complex-timeline")===-1?P("Complex timeline not supported"):P("ComplexTimelineStrategy not yet supported");const o=t.types[0];return o==="image"?n.indexOf("images")===-1?P("Image not supported"):ft(e,t,r):o==="Model"||o==="model"?n.indexOf("3d-model")===-1?P("3D not supported"):dt(e,t):o==="textualbody"?n.indexOf("textual-content")===-1?P("Textual content not supported"):ht(e,t):o==="sound"||o==="audio"?n.indexOf("media")===-1?P("Media not supported"):In(e,t):o==="video"?n.indexOf("media")===-1?P("Media not supported"):mt(e,t):ee}function pt(e){const t=D(),n=V(),r=M(),[o,i]=ut(),{enabledPageIds:s}=it((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(n==null?void 0:n.id),{all:!1}),a=st(s,"AnnotationPage"),l=(e==null?void 0:e.strategies)||["empty","images","media","textual-content","complex-timeline"],[f,d]=lt(e,[i]),g=u.useMemo(()=>vt({canvas:n,paintables:f,supports:l,loadImageService:o}),[n,f,r,d.makeChoice]);return u.useMemo(()=>g.type==="unknown"?[g,nt]:[{...g,annotations:{pages:a}},d],[g,a])}const yt=(e,t=[])=>{const n=M();u.useEffect(()=>{e(n)},[n,...t])};function xt(e,t,{canvasId:n,manifestId:r}={}){const o=M(),i=ie(),s=u.useMemo(()=>Ht.createThumbnailHelper(o,{imageServiceLoader:i}),[o,i]),[a,l]=u.useState(),f=D(r?{id:r}:void 0),d=V(n?{id:n}:void 0),g=d||f,p=u.useRef(!1);if(u.useEffect(()=>(p.current=!1,()=>{p.current=!0}),[]),!g)throw new Error("Must be called under a manifest or canvas context.");return yt(y=>{s.getBestThumbnailAtSize(g,e,t).then(m=>{m.best&&!p.current&&l(m.best)})},[g]),a}function An(e){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:e}}function Tn(e,t){switch(t.type){case"FINISHED":return{...e,isFinished:!0,isPlaying:!1,playRequested:!1};case"PLAY_PAUSE":return{...e,isFinished:!1,isPlaying:!e.isPlaying};case"PLAY_REQUESTED":return{...e,isFinished:!1,playRequested:!0};case"PAUSE":return{...e,isPlaying:!1};case"PLAY":return{...e,isFinished:!1,playRequested:!1,isPlaying:!0};case"MUTE":return{...e,isMuted:!0};case"SET_VOLUME":return{...e,volume:t.volume,isMuted:t.volume===0};case"TOGGLE_MUTE":return{...e,isMuted:!e.isMuted};case"UNMUTE":return{...e,isMuted:!1}}return e}function St(e){const t=Math.round(e);return`${Math.floor(t/60)}:${`${t%60}`.padStart(2,"0")}`}function ae(e){const[t,n]=u.useReducer(Tn,An(e.duration)),r=u.useRef(null),o=u.useRef(null),i=u.useRef(null),s=u.useRef(!1),a=u.useCallback(()=>{o.current&&r.current&&(o.current.innerHTML=St(r.current.currentTime),i.current&&(i.current.style.width=`${r.current.currentTime/e.duration*100}%`),s.current!==r.current.muted&&(s.current=r.current.muted,n(r.current.muted?{type:"MUTE"}:{type:"UNMUTE"})))},[e.duration]),l=u.useCallback(()=>{r.current&&(n({type:"PLAY_REQUESTED"}),r.current.play().then(()=>{n({type:"PLAY"})}),a())},[a]),f=u.useCallback(()=>{r.current&&(r.current.duration>0&&r.current.paused?l():d())},[a]),d=u.useCallback(()=>{r.current&&(r.current.pause(),n({type:"PAUSE"}),a())},[a]),g=u.useCallback(()=>{r.current&&(r.current.muted=!r.current.muted,n(r.current.muted?{type:"MUTE"}:{type:"UNMUTE"}))},[]),p=u.useCallback(()=>{r.current&&(r.current.muted=!0,n({type:"MUTE"}))},[]),y=u.useCallback(()=>{r.current&&(r.current.muted=!1,n({type:"UNMUTE"}))},[]),m=u.useCallback(C=>{r.current&&(r.current.muted=!1,r.current.volume=C/100,n({type:"SET_VOLUME",volume:C}))},[]),h=u.useCallback(C=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(C*e.duration,e.duration)),a())},[]),x=u.useCallback(C=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(C,e.duration)),a())},[]);return u.useEffect(()=>{const C=setInterval(()=>{a()},350);return()=>clearInterval(C)},[a,e.duration]),u.useEffect(()=>{const C=()=>{n({type:"FINISHED"})},j=r.current;return j==null||j.addEventListener("ended",C),()=>j==null?void 0:j.removeEventListener("ended",C)},[]),[{element:r,currentTime:o,progress:i},t,{play:l,pause:d,playPause:f,mute:p,unmute:y,toggleMute:g,setVolume:m,setDurationPercent:h,setTime:x}]}const Ct=u.createContext(null),bt=u.createContext(null),wt=u.createContext(null);function Vn(){const e=u.useContext(Ct);if(!e)throw new Error("Ctx not found");return e}function Ln(){const e=u.useContext(bt);if(!e)throw new Error("Ctx not found");return e}function kn(){const e=u.useContext(wt);if(!e)throw new Error("Ctx not found");return e}function we({actions:e,state:t,children:n,currentTime:r,progress:o,element:i}){return c.jsx(wt.Provider,{value:{currentTime:r,progress:o,element:i},children:c.jsx(bt.Provider,{value:e,children:c.jsx(Ct.Provider,{value:t,children:n})})})}function Pt({media:e,children:t}){const[{element:n,currentTime:r,progress:o},i,s]=ae({duration:e.duration});return c.jsxs(we,{state:i,actions:s,currentTime:r,progress:o,element:n,children:[c.jsx("audio",{ref:n,src:e.url}),t]})}function Mt({media:e,mediaControlsDeps:t,children:n}){return U("portal","audio",Pt,{media:e,children:n},[e,...t||[]]),null}function jt({element:e,media:t,playPause:n}){return c.jsxs("div",{className:"video-container",part:"video-container",onClick:n,children:[c.jsx("style",{children:`
2
2
  .video-container {
3
3
  position: absolute;
4
4
  top: 0;