react-iiif-vault 1.0.9 → 1.0.10

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"),F=require("@atlas-viewer/atlas"),K=require("@iiif/helpers/vault"),ge=require("@iiif/helpers/styles"),ne=require("@iiif/helpers/annotation-targets"),Ye=require("@iiif/helpers"),me=require("@atlas-viewer/iiif-image-api"),$e=require("@iiif/helpers/thumbnail"),ze=u.createContext(null),X={didCatch:!1,error:null};class Ke extends u.Component{constructor(t){super(t),this.resetErrorBoundary=this.resetErrorBoundary.bind(this),this.state=X}static getDerivedStateFromError(t){return{didCatch:!0,error:t}}resetErrorBoundary(){const{error:t}=this.state;if(t!==null){for(var n,r,i=arguments.length,o=new Array(i),s=0;s<i;s++)o[s]=arguments[s];(n=(r=this.props).onReset)===null||n===void 0||n.call(r,{args:o,reason:"imperative-api"}),this.setState(X)}}componentDidCatch(t,n){var r,i;(r=(i=this.props).onError)===null||r===void 0||r.call(i,t,n)}componentDidUpdate(t,n){const{didCatch:r}=this.state,{resetKeys:i}=this.props;if(r&&n.error!==null&&We(t.resetKeys,i)){var o,s;(o=(s=this.props).onReset)===null||o===void 0||o.call(s,{next:i,prev:t.resetKeys,reason:"keys"}),this.setState(X)}}render(){const{children:t,fallbackRender:n,FallbackComponent:r,fallback:i}=this.props,{didCatch:o,error:s}=this.state;let a=t;if(o){const l={error:s,resetErrorBoundary:this.resetErrorBoundary};if(typeof n=="function")a=n(l);else if(r)a=u.createElement(r,l);else if(i===null||u.isValidElement(i))a=i;else throw s}return u.createElement(ze.Provider,{value:{didCatch:o,error:s,resetErrorBoundary:this.resetErrorBoundary}},a)}}function We(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[];return e.length!==t.length||e.some((n,r)=>!Object.is(n,t[r]))}const Ge={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},ie=u.createContext(Ge),U=()=>u.useContext(ie);function G({value:e,children:t}){const n=U(),r=u.useMemo(()=>({...n,...e}),[e,n]);return c.jsx(ie.Provider,{value:r,children:t})}const Q=u.createContext({vault:null,setVaultInstance:e=>{}});function ve({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:i}){const[o,s]=u.useState(()=>e||(n?K.globalVault(t):t?new K.Vault(t):new K.Vault));return c.jsx(Q.Provider,{value:{vault:o,setVaultInstance:s},children:c.jsx(G,{value:r||{},children:i})})}const I=()=>{const{vault:e}=u.useContext(Q);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};function Qe(e,{noCache:t=!1}={}){const n=typeof e=="string"?e:e.id,r=I(),[i,o]=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 h=l&&!t?l:await r.load(n),p=h?h.id||h["@id"]:null;h&&i!==p&&o(p),d(h)}catch(h){a(h)}})()},[n,t]),{isLoaded:!!f,id:i,requestId:n,error:s,resource:f,cached:!!(f&&f===l)}}function Je(e,t){const{id:n,isLoaded:r,error:i,resource:o,requestId:s,cached:a}=Qe(e,t);return{id:n,isLoaded:r,error:i,manifest:o,requestId:s,cached:a}}function Ze({manifest:e,children:t}){return c.jsx(G,{value:{manifest:e},children:t})}function oe({canvas:e,children:t}){return c.jsx(G,{value:{canvas:e},children:t})}function T(e,t=[]){const n=I(),[r,i]=u.useState(()=>e(n.getState(),n));return u.useEffect(()=>n.subscribe(o=>e(o,n),o=>{i(o)},!1),t),r}const J=u.createContext([]);function pe(){const e=u.useContext(J);return T(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}function q(e={},t=[]){const{id:n,selector:r}=e,i=U();I();const o=n||i.manifest,s=T(a=>o?a.iiif.entities.Manifest[o]:void 0,[o]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}function Xe({range:e,children:t}){return c.jsx(G,{value:{range:e},children:t})}function xe(e,t){var r;const n=[];for(const i of t.items)if(i.type==="SpecificResource"&&((r=i.source)==null?void 0:r.type)==="Canvas"&&(i.source.id.indexOf("#")!==-1?n.push({id:i.source.id.split("#")[0],type:"Canvas"}):n.push(i.source)),i.type==="Range"&&n.push(...xe(e,e.get(i))),i.type==="SpecificResource"){const o=typeof i.source=="string"?i.source:i.source.id;n.push({id:o,type:"Canvas"})}return n}function et(e,t,{disablePaging:n,skipNonPaged:r}={}){const i=t.behavior,o=i.includes("paged"),s=o?!1:i.includes("continuous"),a=o||s?!1:i.includes("individuals"),l=t.type==="Manifest"?t.items:xe(e,t);if(s)return[l,[l.map((v,m)=>m)]];if(a||!o||n)return[l,l.map((v,m)=>[m])];const f=[];let d=[];const h=()=>{d.length&&(f.push([...d]),d=[])};let p=0,x=!1;for(let v=0;v<l.length;v++){const m=e.get(l[v]);if(m.behavior.includes("non-paged")){v===p&&p++,r||(h(),f.push([v]),h());continue}if(v===p||m.behavior.includes("facing-pages")){d.length&&(x=!0),h(),f.push([v]),h();continue}if(d.push(v),x){h(),x=!1;continue}d.length>1&&h()}return d.length&&h(),[l,f]}function tt(e={},t=[]){const{id:n,selector:r}=e,i=U(),o=n||i.range,s=T(a=>o?a.iiif.entities.Range[o]:void 0,[o]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}function nt({startCanvas:e,disablePaging:t}){var v;const n=I(),r=q(),i=tt(),[o,s]=u.useState(void 0),a=i||r;if(!a)throw new Error("Nothing selected");const[l,f]=u.useMemo(()=>et(n,a,{disablePaging:t}),[n,a]),d=u.useCallback(m=>{const C=f.findIndex(y=>y.includes(m));s(C===-1?0:C)},[l,f]),h=u.useCallback(m=>{const C=l.findIndex(y=>y.id===m);C!==-1?d(C):s(0)},[l,f]),p=u.useCallback(()=>{s(m=>m>=f.length-1?m:m+1)},[f]),x=u.useCallback(()=>{s(m=>m<=0?0:m-1)},[f]);return typeof o>"u"&&(e?h(e):s(0)),{visibleItems:((v=f[o])==null?void 0:v.map(m=>l[m].id))||[],cursor:o,items:l,sequence:f,hasPrevious:o>0,hasNext:o<f.length-1,setSequenceIndex:s,setCanvasIndex:d,setCanvasId:h,next:p,previous:x}}const H=()=>{},Z=u.createContext({setCurrentCanvasId:H,setCurrentCanvasIndex:H,nextCanvas:H,previousCanvas:H,items:[],sequence:[],setSequenceIndex:H,currentSequenceIndex:0,hasNext:!1,hasPrevious:!1});function rt(e){const t=q(),{cursor:n,visibleItems:r,next:i,sequence:o,items:s,setCanvasIndex:a,setCanvasId:l,previous:f,setSequenceIndex:d,hasNext:h,hasPrevious:p}=nt({startCanvas:e.startCanvas,disablePaging:e.pagingEnabled===!1}),x=u.useMemo(()=>({sequence:o,items:s,setCurrentCanvasId:l,nextCanvas:i,previousCanvas:f,totalCanvases:s.length,setCurrentCanvasIndex:a,setSequenceIndex:d,currentSequenceIndex:n,hasNext:h,hasPrevious:p}),[o,s,l,i,f,s,a,d,n]);return t?r.length===0?null:c.jsx(Z.Provider,{value:x,children:c.jsx(J.Provider,{value:r,children:c.jsx(oe,{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 it(e){const t=Je(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(rt,{...e,children:e.children});return c.jsx(Ze,{manifest:t.id,children:e.rangeId?c.jsx(Xe,{range:e.rangeId,children:n}):n})}function ot(){return u.useContext(Z)}function st(){return{VaultContext:u.useContext(Q),ResourceContext:u.useContext(ie),SimpleViewerReactContext:u.useContext(Z),VisibleCanvasReactContext:u.useContext(J)}}function at(e){return c.jsx(ve,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext,children:c.jsx(J.Provider,{value:e.bridge.VisibleCanvasReactContext,children:c.jsx(Z.Provider,{value:e.bridge.SimpleViewerReactContext,children:e.children})})})}const R=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}})}},ut="@iiif/IMPORT_ENTITIES",ct="@iiif/MODIFY_ENTITY_FIELD",lt="@iiif/REORDER_ENTITY_FIELD",dt="@iiif/ADD_REFERENCE",ft="@iiif/UPDATE_REFERENCE",ht="@iiif/REMOVE_REFERENCE",gt="@iiif/ADD_METADATA",mt="@iiif/REMOVE_METADATA",vt="@iiif/UPDATE_METADATA",pt="@iiif/REORDER_METADATA",xt=R(ut)(),yt=R(ct)(),Ct=R(lt)(),bt=R(dt)(),St=R(ht)(),wt=R(ft)(),Mt=R(gt)(),Pt=R(vt)(),jt=R(mt)(),Et=R(pt)(),ee={importEntities:xt,modifyEntityField:yt,reorderEntityField:Ct,addReference:bt,removeReference:St,updateReference:wt,addMetadata:Mt,removeMetadata:jt,updateMetadata:Pt,reorderMetadata:Et};function It(){const t=I().getStore();return u.useMemo(()=>n=>t.dispatch(n),[t])}function fe(e){return typeof e!="string"&&e&&e.bindToVault}function Tt(){const e=I(),t=u.useRef([]),n=It(),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(ee.importEntities({entities:{AnnotationPage:{[a.id]:a}}}))},[r]);const i=T(a=>r?a.iiif.entities.AnnotationPage[r]:null,[r]),o=u.useCallback((a,l)=>{if(r){if(fe(a)){const h=a;h.__vault||h.bindToVault(e),a=typeof h.source=="string"?h.source:h.source.id,t.current[a]=h}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(h=>h.id===d.id)||n(ee.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"},index:l})))}},[r]),s=u.useCallback(a=>{r&&(fe(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(ee.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"}})))},[r]);return[i,{addAnnotation:o,removeAnnotation:s}]}const ye=u.createContext(null);function At(){const e=u.useContext(ye);return[e.fullPage,{addAnnotation:e.addAnnotation,removeAnnotation:e.removeAnnotation}]}function Rt({children:e}){const[t,{addAnnotation:n,removeAnnotation:r}]=Tt();return c.jsx(ye.Provider,{value:u.useMemo(()=>({fullPage:t,addAnnotation:n,removeAnnotation:r}),[t]),children:e})}function Vt({width:e,style:t,height:n,error:r,resetErrorBoundary:i}){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:i,children:"Reset"})]})}const se=u.createContext(null);function kt(){return u.useContext(se)}const Ce=u.createContext(()=>{}),be=u.createContext(()=>{});function N(e,t,n,r,i=[]){const o=u.useContext(e==="portal"?be:Ce);u.useEffect(()=>(e!=="none"&&o(t,n,r),()=>{o(t,null)}),[t,e,o,...i])}function O(e={},t=[]){const{id:n,selector:r}=e,i=U(),o=n||i.canvas,s=T(a=>o?a.iiif.entities.Canvas[o]:void 0,[o]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}const Se=u.createContext(()=>{});function Ot(e){const t=O(),n=u.useContext(Se);u.useEffect(()=>t&&t.id?(n(t.id,e),()=>n(t.id,-1)):()=>{},[t,e])}function Lt({children:e,errorFallback:t,outerContainerProps:n={},worldScale:r,...i}){const[o,s]=u.useState(),a=st(),l=t||Vt,[f,d]=u.useState({}),h=Object.entries(f),[p,x]=u.useState({}),v=Object.entries(p),[m,C]=u.useState({}),y=u.useMemo(()=>r||Math.max(...Object.values(m)),[m]),P=u.useMemo(()=>({maxOverZoom:y||1,...i.runtimeOptions||{}}),[y,i.runtimeOptions]),S=u.useCallback((w,j)=>{C(A=>{if(j===-1){const{[w]:g,...V}=A;return V}return{...A,[w]:j}})},[]),D=u.useCallback((w,j,A)=>{d(({[w]:g,...V})=>j?{...V,[w]:{element:j,props:A}}:V)},[]),Y=u.useCallback((w,j,A)=>{x(({[w]:g,...V})=>j?{...V,[w]:{element:j,props:A}}:V)},[]);return c.jsxs(Ke,{resetKeys:[],fallbackRender:w=>c.jsx(l,{...i,...w}),children:[c.jsx(F.AtlasAuto,{...i,containerProps:{style:{position:"relative"},...i.containerProps||{}},htmlChildren:c.jsx(c.Fragment,{children:h.map(([w,{element:j,props:A}])=>c.jsx(u.Fragment,{children:c.jsx(j,{...A||{}})},w))}),onCreated:w=>{s(w),i.onCreated&&i.onCreated(w)},runtimeOptions:P,children:c.jsx(se.Provider,{value:o,children:c.jsx(Se.Provider,{value:S,children:c.jsx(Ce.Provider,{value:D,children:c.jsx(be.Provider,{value:Y,children:c.jsx(at,{bridge:a,children:c.jsx(F.ModeContext.Provider,{value:i.mode||"explore",children:c.jsx(Rt,{children:e})})})})})})})}),c.jsx("div",{children:v.map(([w,{element:j,props:A}])=>c.jsx(u.Fragment,{children:c.jsx(j,{...A||{}})},w))})]})}const $={},we={get(e){return e},setMetaValue([e,t,n],r){const i=we.getResourceMeta(e,t),o=i?i[n]:void 0,s=typeof r=="function"?r(o):r;$[e]={...$[e]||{},[t]:{...($[e]||{})[t]||{},[n]:s}}},getResourceMeta:(e,t)=>{const n=$[e];if(n)return t?n[t]:n}};function Ft(e=we){return{addEventListener(t,n,r,i){if(t)return e.setMetaValue([t.id,"eventManager",n],o=>{const s=o||[];for(const a of s)if(a.callback===r)return s;return[...s,{callback:r,scope:i}]}),r},removeEventListener(t,n,r){t&&e.setMetaValue([t.id,"eventManager",n],i=>(i||[]).filter(o=>o.callback!==r))},getListenersAsProps(t,n){const r=typeof t=="string"?{id:t}:t;if(!r||!r.id)return{};const i=e.getResourceMeta(r.id,"eventManager"),o={};if(i&&r)for(const s of Object.keys(i))o[s]=a=>{const l=e.get(r);for(const{callback:f,scope:d}of i[s]||[])(!d||n&&d.indexOf(n)!==-1)&&f(a,l)};return o}}}function Me(e,t){const n=I(),r=u.useMemo(()=>Ft(n),[n]),i=T(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return u.useMemo(()=>e?r.getListenersAsProps(e,t):{},[i,e,n,t])}function W(e,t){const n=I(),r=u.useMemo(()=>ge.createStylesHelper(n),[n]);return T(()=>{if(!e)return null;const i=r.getAppliedStyles(e.id);return i?t?i[t]:i:void 0},[e,t])}function Pe(e={},t=[]){const{id:n,selector:r}=e,i=U(),o=I(),s=n||i.annotation,a=T(f=>s?f.iiif.entities.Annotation[s]:void 0,[s]),l=T(f=>a&&a.body?a.body.map(d=>d?d.type==="SpecificResource"?{...d,source:o.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:ne.expandTarget(a.target,{typeMap:o.getState().iiif.mapping})};return r?r(f):f},[a,r,l,...t])}const je=({id:e,style:t,className:n,interactive:r})=>{const i=Pe({id:e}),o=W(i,"atlas"),s=W(i,"html"),a=Me(i,["atlas"]),l=O(),f=u.useMemo(()=>F.mergeStyles(t,o),[t,o]);return l&&i&&i.target&&i.target.selector&&i.target.selector.type==="BoxSelector"&&i.target.source&&(i.target.source.id===l.id||i.target.source===l.id)?c.jsx(F.RegionHighlight,{id:i.id,isEditing:!0,region:i.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 Nt(e={},t=[]){const{id:n,selector:r}=e,i=U(),o=n||i.annotationPage,s=T(a=>o?a.iiif.entities.AnnotationPage[o]:void 0,[o]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,...t])}const re=({className:e,page:t})=>{var o;const n=Nt({id:t.id})||t,r=W(n,"atlas"),i=W(n,"html");return T(s=>n.id?s.iiif.entities.AnnotationPage[n.id]:null,[]),c.jsx(u.Fragment,{children:(o=n.items)==null?void 0:o.map(s=>c.jsx(je,{id:s.id,style:r,className:(i==null?void 0:i.className)||e},s.id))})};function Ee({id:e,image:t,thumbnail:n,isStatic:r,x:i=0,y:o=0,children:s,selector:a,onClick:l,enableSizes:f}){var h,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:i+t.target.spatial.x,y:o+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(F.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:(h=t.target)==null?void 0:h.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 Ie(e,t){const{selector:n,source:r}=Ye.expandTarget(t);if(r.id!==e.id)return[null,r];const i={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:i.spatial}:n:null,r]}const Ut={makeChoice:()=>{}},te={type:"unknown"},M=e=>({type:"unknown",reason:e,annotations:{pages:[]}}),qt=(e,t)=>({type:"empty",width:e,height:t,annotations:{pages:[]},image:null,images:[]});function Dt(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 _t(e,t){return T(n=>{const r=[];if(!e)return r;const i=Object.keys(n.iiif.entities.AnnotationPage);for(const o of i)if(!t||t.indexOf(o)!==-1){const s=Dt(n,o);s&&s.views&&s.views[e]&&r.push(o)}return r},[e,t])}function Bt({canvas:e,manifest:t,all:n,canvases:r}){const i=[];if(t)for(const o of t.annotations)i.indexOf(o.id)===-1&&i.push(o.id);if(n){if(r&&r.length)for(const o of r)for(const s of o.annotations)i.indexOf(s.id)===-1&&i.push(s.id)}else if(e)for(const o of e.annotations)i.indexOf(o.id)===-1&&i.push(o.id);return i}function Ht(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 Yt(e,t={}){const n=I(),r=q(),i=O(),o=pe(),s=u.useMemo(()=>Bt({all:t.all,manifest:r,canvas:i,canvases:o}),[t.all,i,o,r]),a=_t(e,t.all?void 0:s),l=u.useCallback(d=>{e&&n.setMetaValue([d,"annotationPageManager","views"],h=>h&&!h[e]?h:{...h||{},[e]:!1})},[e,n]),f=u.useCallback((d,h={})=>{if(!e)return;const p=n.getState(),x=[];if(h!=null&&h.deselectOthers){const v=Object.keys(p.iiif.entities.AnnotationPage);for(const m of v){const C=Ht(p,m);C&&C.views&&C.views[e]&&x.push(m)}}for(const v of x)l(v);n.setMetaValue([d,"annotationPageManager","views"],v=>v&&v[e]?v:{...v||{},[e]:!0})},[e,l,n]);return{availablePageIds:s,enabledPageIds:a,setPageEnabled:f,setPageDisabled:l}}function $t(e,t){return T((n,r)=>r.get(e.map(i=>({id:i,type:t}))),[e,t])}const zt=u.createContext(new me.ImageServiceLoader);function Te(){return u.useContext(zt)}function Kt(){const e=Te(),[t,n]=u.useState({}),r=u.useRef(!1);return u.useEffect(()=>()=>{r.current=!0},[]),[u.useCallback((o,{height:s,width:a})=>{if(o){const l=o.id||o["@id"],f=e.loadServiceSync({id:l,width:o.width||a,height:o.height||s,source:o});f?o=f:t[l]||(r.current||n(d=>({...d,[l]:"loading"})),e.loadService({id:l,width:o.width||a,height:o.height||s}).then(()=>{r.current||n(d=>({...d,[l]:"done"}))}))}return o},[e,t]),t]}function Wt(e={}){const t=Pe(),n=O(e.canvasId?{id:e.canvasId}:void 0);return T((r,i)=>{if(!n)return[];if(t&&e.enableSingleAnnotation)return[t];const o=i.get(n.items),s=[];for(const a of o)s.push(...i.get(a.items));return s},[n])}function Gt(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}const z={},Ae={get(e){return e},setMetaValue([e,t,n],r){const i=Ae.getResourceMeta(e,t),o=i?i[n]:void 0,s=typeof r=="function"?r(o):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 Qt(e=Ae){function t(i){const o=i?typeof i=="string"?e.get(i):i:null;if(!o)return[];const s=e.get(o.items,{parent:o}),a=[];for(const l of s)a.push(...e.get(l.items,{parent:l}));return a}function n(i,o=[]){const s=Array.isArray(i)?i:t(i),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 h=Array.from(Array.isArray(d.body)?d.body:[d.body]);for(const p of h){const[x,{selector:v}]=Gt(p),m=e.get(x),C=(m.type||"unknown").toLowerCase();if(C==="choice"){const y=e.get(m.items,{parent:m.id}),P=o.length?o.map(S=>y.find(D=>D.id===S)).filter(Boolean):[y[0]];P.length===0&&P.push(y[0]),l={type:"single-choice",items:y.map(S=>({id:S.id,label:S.label,selected:P.indexOf(S)!==-1})),label:x.label},h.push(...P);continue}a.indexOf(C)===-1&&a.push(C),f.push({type:C,annotationId:d.id,resource:m,target:d.target,selector:v})}}return{types:a,items:f,choice:l}}function r(i){const{choice:o}=n(i);return o}return{getAllPaintingAnnotations:t,getPaintables:n,extractChoices:r}}function Jt(e,t=[]){const n=I(),r=u.useMemo(()=>Qt(n),[]),i=Wt({enableSingleAnnotation:e==null?void 0:e.enableSingleAnnotation}),[o,s]=u.useState((e==null?void 0:e.defaultChoices)||[]),a=u.useMemo(()=>r.getPaintables(i,o),[n,i,o,...t]),f={makeChoice:u.useCallback((d,{deselectOthers:h=!0,deselect:p=!1}={})=>{if(a.choice){if(a.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");s(x=>{if(p){const m=x.filter(C=>C!==d);if(m.length===0){const C=a.items[0].resource.id;return C?[C]:[]}return m}if(h)return[d];const v=[...x];if(v.length===0&&a.items.length){const m=a.items[0].resource.id;m&&v.push(m)}return x.indexOf(d)!==-1?x:[...x,d]})}},[a.choice])};return[a,f]}const Zt=["model/gltf-binary"];function Xt(e,t){const r=t.items[0].resource;return r.format?Zt.indexOf(r.format)===-1?M(`3D format: ${r.format} is unsupported`):{type:"3d-model",model:r}:M("Unknown format")}function en(e,t){var r;if(!e.duration)return M("No duration on canvas");if(t.items.length>1)return M("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:[]}}:M("Audio does not have format"):M("Unknown audio")}function tn(e,t,n){const r=[];for(const i of t.items){const o=i.resource&&i.resource.type==="SpecificResource"?i.resource.source:i.resource;if(!o.id)return M("No resource Identifier");let s;if(o.service){const x=me.getImageServices(o);x[0]&&(s=n(x[0],e))}const a={type:"BoxSelector",spatial:{x:0,y:0,width:Number(e.width),height:Number(e.height)}},[l,f]=Ie(e,i.target);if(!(f.id===e.id||decodeURIComponent(f.id||"")===(e.id||"")))continue;i.resource.width&&i.resource.height&&(i.resource.width,i.resource.height);let d=i.resource.type==="SpecificResource"?ne.expandTarget(i.resource):null;if(i.selector){const x=ne.expandTarget({type:"SpecificResource",source:i.resource,selector:i.selector});x&&(d=x)}const h=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:o.id,type:"Image",annotationId:i.annotationId,width:Number(l||h?o.width:e.width),height:Number(l||h?o.height:e.height),service:s,sizes:s&&s.sizes?s.sizes:o.width&&o.height?[{width:o.width,height:o.height}]:[],target:l&&l.type!=="PointSelector"?l:a,selector:h};r.push(p)}return{type:"images",image:r[0],images:r,choice:t.choice}}function Re(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(i=>Re(i,t,r))}return t}function nn(e,t){const n=[];return t.items.forEach(r=>{if(r.resource){const[i]=Ie(e,r.target);n.push({annotationId:r.annotationId,text:Re(r.resource),target:i})}}),{type:"textual-content",items:n}}const rn=/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?vi?=|&vi?=))([^#&?]*).*/;function on(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 M("Only one video source supported");const i=(a=n[0])==null?void 0:a.resource,o=!!(i.service||[]).find(l=>(l.profile||"").includes("youtube.com"));if(!o&&r)return M("Video does not have duration");if(!i)return M("Unknown video");if((!i.format||i.format==="text/html")&&!o)return M("Video does not have format");const s={annotationId:t.items[0].annotationId,duration:e.duration,url:i.id,type:"Video",items:[],target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:i.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}};if(o){s.type="VideoYouTube";const l=i.id.match(rn);if(!l[1])return M("Video is not known youtube video");s.youTubeId=l[1]}return{type:"media",media:s,annotations:{pages:[]}}}function sn({canvas:e,paintables:t,supports:n,loadImageService:r}){if(!e)return console.log("No canvas"),te;if(t.types.length===0)return n.indexOf("empty")!==-1?qt(e.width,e.height):(console.log("No paintables"),te);if(t.types.length!==1)if(t.types.length===2&&t.types.indexOf("text")!==-1)t.types=t.types.filter(o=>o!=="text");else return n.indexOf("complex-timeline")===-1?M("Complex timeline not supported"):M("ComplexTimelineStrategy not yet supported");const i=t.types[0];return i==="image"?n.indexOf("images")===-1?M("Image not supported"):tn(e,t,r):i==="Model"||i==="model"?n.indexOf("3d-model")===-1?M("3D not supported"):Xt(e,t):i==="textualbody"?n.indexOf("textual-content")===-1?M("Textual content not supported"):nn(e,t):i==="sound"||i==="audio"?n.indexOf("media")===-1?M("Media not supported"):en(e,t):i==="video"?n.indexOf("media")===-1?M("Media not supported"):on(e,t):te}function an(e){const t=q(),n=O(),r=I(),[i,o]=Kt(),{enabledPageIds:s}=Yt((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(n==null?void 0:n.id),{all:!1}),a=$t(s,"AnnotationPage"),l=(e==null?void 0:e.strategies)||["empty","images","media","textual-content","complex-timeline"],[f,d]=Jt(e,[o]),h=u.useMemo(()=>sn({canvas:n,paintables:f,supports:l,loadImageService:i}),[n,f,r,d.makeChoice]);return u.useMemo(()=>h.type==="unknown"?[h,Ut]:[{...h,annotations:{pages:a}},d],[h,a])}const un=(e,t=[])=>{const n=I();u.useEffect(()=>{e(n)},[n,...t])};function cn(e,t,{canvasId:n,manifestId:r}={}){const i=I(),o=Te(),s=u.useMemo(()=>$e.createThumbnailHelper(i,{imageServiceLoader:o}),[i,o]),[a,l]=u.useState(),f=q(r?{id:r}:void 0),d=O(n?{id:n}:void 0),h=d||f,p=u.useRef(!1);if(u.useEffect(()=>(p.current=!1,()=>{p.current=!0}),[]),!h)throw new Error("Must be called under a manifest or canvas context.");return un(x=>{s.getBestThumbnailAtSize(h,e,t).then(v=>{v.best&&!p.current&&l(v.best)})},[h]),a}function ln(e){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:e}}function dn(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 fn(e){const t=Math.round(e);return`${Math.floor(t/60)}:${`${t%60}`.padStart(2,"0")}`}function ae(e){const[t,n]=u.useReducer(dn,ln(e.duration)),r=u.useRef(null),i=u.useRef(null),o=u.useRef(null),s=u.useRef(!1),a=u.useCallback(()=>{i.current&&r.current&&(i.current.innerHTML=fn(r.current.currentTime),o.current&&(o.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]),h=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"}))},[]),x=u.useCallback(()=>{r.current&&(r.current.muted=!1,n({type:"UNMUTE"}))},[]),v=u.useCallback(y=>{r.current&&(r.current.muted=!1,r.current.volume=y/100,n({type:"SET_VOLUME",volume:y}))},[]),m=u.useCallback(y=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(y*e.duration,e.duration)),a())},[]),C=u.useCallback(y=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(y,e.duration)),a())},[]);return u.useEffect(()=>{const y=setInterval(()=>{a()},350);return()=>clearInterval(y)},[a,e.duration]),u.useEffect(()=>{const y=()=>{n({type:"FINISHED"})},P=r.current;return P==null||P.addEventListener("ended",y),()=>P==null?void 0:P.removeEventListener("ended",y)},[]),[{element:r,currentTime:i,progress:o},t,{play:l,pause:d,playPause:f,mute:p,unmute:x,toggleMute:h,setVolume:v,setDurationPercent:m,setTime:C}]}const hn=u.createContext(null),gn=u.createContext(null),mn=u.createContext(null);function Ve({actions:e,state:t,children:n,currentTime:r,progress:i,element:o}){return c.jsx(mn.Provider,{value:{currentTime:r,progress:i,element:o},children:c.jsx(gn.Provider,{value:e,children:c.jsx(hn.Provider,{value:t,children:n})})})}function ke({media:e,children:t}){const[{element:n,currentTime:r,progress:i},o,s]=ae({duration:e.duration});return c.jsxs(Ve,{state:o,actions:s,currentTime:r,progress:i,element:n,children:[c.jsx("audio",{ref:n,src:e.url}),t]})}function Oe({media:e,mediaControlsDeps:t,children:n}){return N("portal","audio",ke,{media:e,children:n},[e,...t||[]]),null}function Le({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"),F=require("@atlas-viewer/atlas"),K=require("@iiif/helpers/vault"),ve=require("@iiif/helpers/styles"),ne=require("@iiif/helpers/annotation-targets"),$e=require("@iiif/helpers"),pe=require("@atlas-viewer/iiif-image-api"),ze=require("@iiif/helpers/thumbnail"),Ke=u.createContext(null),X={didCatch:!1,error:null};class We extends u.Component{constructor(t){super(t),this.resetErrorBoundary=this.resetErrorBoundary.bind(this),this.state=X}static getDerivedStateFromError(t){return{didCatch:!0,error:t}}resetErrorBoundary(){const{error:t}=this.state;if(t!==null){for(var n,r,i=arguments.length,o=new Array(i),s=0;s<i;s++)o[s]=arguments[s];(n=(r=this.props).onReset)===null||n===void 0||n.call(r,{args:o,reason:"imperative-api"}),this.setState(X)}}componentDidCatch(t,n){var r,i;(r=(i=this.props).onError)===null||r===void 0||r.call(i,t,n)}componentDidUpdate(t,n){const{didCatch:r}=this.state,{resetKeys:i}=this.props;if(r&&n.error!==null&&Ge(t.resetKeys,i)){var o,s;(o=(s=this.props).onReset)===null||o===void 0||o.call(s,{next:i,prev:t.resetKeys,reason:"keys"}),this.setState(X)}}render(){const{children:t,fallbackRender:n,FallbackComponent:r,fallback:i}=this.props,{didCatch:o,error:s}=this.state;let a=t;if(o){const l={error:s,resetErrorBoundary:this.resetErrorBoundary};if(typeof n=="function")a=n(l);else if(r)a=u.createElement(r,l);else if(i===null||u.isValidElement(i))a=i;else throw s}return u.createElement(Ke.Provider,{value:{didCatch:o,error:s,resetErrorBoundary:this.resetErrorBoundary}},a)}}function Ge(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[];return e.length!==t.length||e.some((n,r)=>!Object.is(n,t[r]))}const Qe={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},ie=u.createContext(Qe),U=()=>u.useContext(ie);function G({value:e,children:t}){const n=U(),r=u.useMemo(()=>({...n,...e}),[e,n]);return c.jsx(ie.Provider,{value:r,children:t})}const Q=u.createContext({vault:null,setVaultInstance:e=>{}});function oe({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:i}){const[o,s]=u.useState(()=>e||(n?K.globalVault(t):t?new K.Vault(t):new K.Vault));return c.jsx(Q.Provider,{value:{vault:o,setVaultInstance:s},children:c.jsx(G,{value:r||{},children:i})})}function se(e){const t=u.useContext(Q);return e||(t&&t.vault?t.vault:K.globalVault())}function Je(e,{noCache:t=!1}={}){const n=typeof e=="string"?e:e.id,r=se(),[i,o]=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 h=l&&!t?l:await r.load(n),p=h?h.id||h["@id"]:null;h&&i!==p&&o(p),d(h)}catch(h){a(h)}})()},[n,t]),{isLoaded:!!f,id:i,requestId:n,error:s,resource:f,cached:!!(f&&f===l)}}function Ze(e,t){const{id:n,isLoaded:r,error:i,resource:o,requestId:s,cached:a}=Je(e,t);return{id:n,isLoaded:r,error:i,manifest:o,requestId:s,cached:a}}function Xe({manifest:e,children:t}){return c.jsx(G,{value:{manifest:e},children:t})}function ae({canvas:e,children:t}){return c.jsx(G,{value:{canvas:e},children:t})}const T=()=>{const{vault:e}=u.useContext(Q);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};function I(e,t=[]){const n=T(),[r,i]=u.useState(()=>e(n.getState(),n));return u.useEffect(()=>n.subscribe(o=>e(o,n),o=>{i(o)},!1),t),r}const J=u.createContext([]);function xe(){const e=u.useContext(J);return I(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}function q(e={},t=[]){const{id:n,selector:r}=e,i=U();T();const o=n||i.manifest,s=I(a=>o?a.iiif.entities.Manifest[o]:void 0,[o]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}function et({range:e,children:t}){return c.jsx(G,{value:{range:e},children:t})}function ye(e,t){var r;const n=[];for(const i of t.items)if(i.type==="SpecificResource"&&((r=i.source)==null?void 0:r.type)==="Canvas"&&(i.source.id.indexOf("#")!==-1?n.push({id:i.source.id.split("#")[0],type:"Canvas"}):n.push(i.source)),i.type==="Range"&&n.push(...ye(e,e.get(i))),i.type==="SpecificResource"){const o=typeof i.source=="string"?i.source:i.source.id;n.push({id:o,type:"Canvas"})}return n}function tt(e,t,{disablePaging:n,skipNonPaged:r}={}){const i=t.behavior,o=i.includes("paged"),s=o?!1:i.includes("continuous"),a=o||s?!1:i.includes("individuals"),l=t.type==="Manifest"?t.items:ye(e,t);if(s)return[l,[l.map((v,m)=>m)]];if(a||!o||n)return[l,l.map((v,m)=>[m])];const f=[];let d=[];const h=()=>{d.length&&(f.push([...d]),d=[])};let p=0,x=!1;for(let v=0;v<l.length;v++){const m=e.get(l[v]);if(m.behavior.includes("non-paged")){v===p&&p++,r||(h(),f.push([v]),h());continue}if(v===p||m.behavior.includes("facing-pages")){d.length&&(x=!0),h(),f.push([v]),h();continue}if(d.push(v),x){h(),x=!1;continue}d.length>1&&h()}return d.length&&h(),[l,f]}function nt(e={},t=[]){const{id:n,selector:r}=e,i=U(),o=n||i.range,s=I(a=>o?a.iiif.entities.Range[o]:void 0,[o]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}function rt({startCanvas:e,disablePaging:t}){var v;const n=T(),r=q(),i=nt(),[o,s]=u.useState(void 0),a=i||r;if(!a)throw new Error("Nothing selected");const[l,f]=u.useMemo(()=>tt(n,a,{disablePaging:t}),[n,a,t]),d=u.useCallback(m=>{const C=f.findIndex(y=>y.includes(m));s(C===-1?0:C)},[l,f]),h=u.useCallback(m=>{const C=l.findIndex(y=>y.id===m);C!==-1?d(C):s(0)},[l,f]),p=u.useCallback(()=>{s(m=>m>=f.length-1?m:m+1)},[f]),x=u.useCallback(()=>{s(m=>m<=0?0:m-1)},[f]);return typeof o>"u"&&(e?h(e):s(0)),{visibleItems:((v=f[o])==null?void 0:v.map(m=>l[m].id))||[],cursor:o,items:l,sequence:f,hasPrevious:o>0,hasNext:o<f.length-1,setSequenceIndex:s,setCanvasIndex:d,setCanvasId:h,next:p,previous:x}}const H=()=>{},Z=u.createContext({setCurrentCanvasId:H,setCurrentCanvasIndex:H,nextCanvas:H,previousCanvas:H,items:[],sequence:[],setSequenceIndex:H,currentSequenceIndex:0,hasNext:!1,hasPrevious:!1});function it(e){const t=q(),{cursor:n,visibleItems:r,next:i,sequence:o,items:s,setCanvasIndex:a,setCanvasId:l,previous:f,setSequenceIndex:d,hasNext:h,hasPrevious:p}=rt({startCanvas:e.startCanvas,disablePaging:e.pagingEnabled===!1}),x=u.useMemo(()=>({sequence:o,items:s,setCurrentCanvasId:l,nextCanvas:i,previousCanvas:f,totalCanvases:s.length,setCurrentCanvasIndex:a,setSequenceIndex:d,currentSequenceIndex:n,hasNext:h,hasPrevious:p}),[o,s,l,i,f,s,a,d,n]);return t?r.length===0?null:c.jsx(Z.Provider,{value:x,children:c.jsx(J.Provider,{value:r,children:c.jsx(ae,{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 ot(e){const t=se(e.vault),n=Ze(e.manifest);if(!n)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),c.jsx("div",{children:"Sorry, something went wrong."});if(n.error)return c.jsx("div",{children:n.error.toString()});if(!n.isLoaded)return c.jsx("div",{children:"Loading..."});const r=c.jsx(it,{...e,children:e.children});return c.jsx(oe,{vault:t,children:c.jsx(Xe,{manifest:n.id,children:e.rangeId?c.jsx(et,{range:e.rangeId,children:r}):r})})}function st(){return u.useContext(Z)}function at(){return{VaultContext:u.useContext(Q),ResourceContext:u.useContext(ie),SimpleViewerReactContext:u.useContext(Z),VisibleCanvasReactContext:u.useContext(J)}}function ut(e){return c.jsx(oe,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext,children:c.jsx(J.Provider,{value:e.bridge.VisibleCanvasReactContext,children:c.jsx(Z.Provider,{value:e.bridge.SimpleViewerReactContext,children:e.children})})})}const R=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}})}},ct="@iiif/IMPORT_ENTITIES",lt="@iiif/MODIFY_ENTITY_FIELD",dt="@iiif/REORDER_ENTITY_FIELD",ft="@iiif/ADD_REFERENCE",ht="@iiif/UPDATE_REFERENCE",gt="@iiif/REMOVE_REFERENCE",mt="@iiif/ADD_METADATA",vt="@iiif/REMOVE_METADATA",pt="@iiif/UPDATE_METADATA",xt="@iiif/REORDER_METADATA",yt=R(ct)(),Ct=R(lt)(),bt=R(dt)(),St=R(ft)(),wt=R(gt)(),Mt=R(ht)(),jt=R(mt)(),Pt=R(pt)(),Et=R(vt)(),It=R(xt)(),ee={importEntities:yt,modifyEntityField:Ct,reorderEntityField:bt,addReference:St,removeReference:wt,updateReference:Mt,addMetadata:jt,removeMetadata:Et,updateMetadata:Pt,reorderMetadata:It};function Tt(){const t=T().getStore();return u.useMemo(()=>n=>t.dispatch(n),[t])}function ge(e){return typeof e!="string"&&e&&e.bindToVault}function At(){const e=T(),t=u.useRef([]),n=Tt(),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(ee.importEntities({entities:{AnnotationPage:{[a.id]:a}}}))},[r]);const i=I(a=>r?a.iiif.entities.AnnotationPage[r]:null,[r]),o=u.useCallback((a,l)=>{if(r){if(ge(a)){const h=a;h.__vault||h.bindToVault(e),a=typeof h.source=="string"?h.source:h.source.id,t.current[a]=h}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(h=>h.id===d.id)||n(ee.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"},index:l})))}},[r]),s=u.useCallback(a=>{r&&(ge(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(ee.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"}})))},[r]);return[i,{addAnnotation:o,removeAnnotation:s}]}const Ce=u.createContext(null);function Rt(){const e=u.useContext(Ce);return[e.fullPage,{addAnnotation:e.addAnnotation,removeAnnotation:e.removeAnnotation}]}function Vt({children:e}){const[t,{addAnnotation:n,removeAnnotation:r}]=At();return c.jsx(Ce.Provider,{value:u.useMemo(()=>({fullPage:t,addAnnotation:n,removeAnnotation:r}),[t]),children:e})}function kt({width:e,style:t,height:n,error:r,resetErrorBoundary:i}){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:i,children:"Reset"})]})}const ue=u.createContext(null);function Ot(){return u.useContext(ue)}const be=u.createContext(()=>{}),Se=u.createContext(()=>{});function N(e,t,n,r,i=[]){const o=u.useContext(e==="portal"?Se:be);u.useEffect(()=>(e!=="none"&&o(t,n,r),()=>{o(t,null)}),[t,e,o,...i])}function O(e={},t=[]){const{id:n,selector:r}=e,i=U(),o=n||i.canvas,s=I(a=>o?a.iiif.entities.Canvas[o]:void 0,[o]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}const we=u.createContext(()=>{});function Lt(e){const t=O(),n=u.useContext(we);u.useEffect(()=>t&&t.id?(n(t.id,e),()=>n(t.id,-1)):()=>{},[t,e])}function Ft({children:e,errorFallback:t,outerContainerProps:n={},worldScale:r,...i}){const[o,s]=u.useState(),a=at(),l=t||kt,[f,d]=u.useState({}),h=Object.entries(f),[p,x]=u.useState({}),v=Object.entries(p),[m,C]=u.useState({}),y=u.useMemo(()=>r||Math.max(...Object.values(m)),[m]),j=u.useMemo(()=>({maxOverZoom:y||1,...i.runtimeOptions||{}}),[y,i.runtimeOptions]),S=u.useCallback((w,P)=>{C(A=>{if(P===-1){const{[w]:g,...V}=A;return V}return{...A,[w]:P}})},[]),D=u.useCallback((w,P,A)=>{d(({[w]:g,...V})=>P?{...V,[w]:{element:P,props:A}}:V)},[]),Y=u.useCallback((w,P,A)=>{x(({[w]:g,...V})=>P?{...V,[w]:{element:P,props:A}}:V)},[]);return c.jsxs(We,{resetKeys:[],fallbackRender:w=>c.jsx(l,{...i,...w}),children:[c.jsx(F.AtlasAuto,{...i,containerProps:{style:{position:"relative"},...i.containerProps||{}},htmlChildren:c.jsx(c.Fragment,{children:h.map(([w,{element:P,props:A}])=>c.jsx(u.Fragment,{children:c.jsx(P,{...A||{}})},w))}),onCreated:w=>{s(w),i.onCreated&&i.onCreated(w)},runtimeOptions:j,children:c.jsx(ue.Provider,{value:o,children:c.jsx(we.Provider,{value:S,children:c.jsx(be.Provider,{value:D,children:c.jsx(Se.Provider,{value:Y,children:c.jsx(ut,{bridge:a,children:c.jsx(F.ModeContext.Provider,{value:i.mode||"explore",children:c.jsx(Vt,{children:e})})})})})})})}),c.jsx("div",{children:v.map(([w,{element:P,props:A}])=>c.jsx(u.Fragment,{children:c.jsx(P,{...A||{}})},w))})]})}const $={},Me={get(e){return e},setMetaValue([e,t,n],r){const i=Me.getResourceMeta(e,t),o=i?i[n]:void 0,s=typeof r=="function"?r(o):r;$[e]={...$[e]||{},[t]:{...($[e]||{})[t]||{},[n]:s}}},getResourceMeta:(e,t)=>{const n=$[e];if(n)return t?n[t]:n}};function Nt(e=Me){return{addEventListener(t,n,r,i){if(t)return e.setMetaValue([t.id,"eventManager",n],o=>{const s=o||[];for(const a of s)if(a.callback===r)return s;return[...s,{callback:r,scope:i}]}),r},removeEventListener(t,n,r){t&&e.setMetaValue([t.id,"eventManager",n],i=>(i||[]).filter(o=>o.callback!==r))},getListenersAsProps(t,n){const r=typeof t=="string"?{id:t}:t;if(!r||!r.id)return{};const i=e.getResourceMeta(r.id,"eventManager"),o={};if(i&&r)for(const s of Object.keys(i))o[s]=a=>{const l=e.get(r);for(const{callback:f,scope:d}of i[s]||[])(!d||n&&d.indexOf(n)!==-1)&&f(a,l)};return o}}}function je(e,t){const n=T(),r=u.useMemo(()=>Nt(n),[n]),i=I(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return u.useMemo(()=>e?r.getListenersAsProps(e,t):{},[i,e,n,t])}function W(e,t){const n=T(),r=u.useMemo(()=>ve.createStylesHelper(n),[n]);return I(()=>{if(!e)return null;const i=r.getAppliedStyles(e.id);return i?t?i[t]:i:void 0},[e,t])}function Pe(e={},t=[]){const{id:n,selector:r}=e,i=U(),o=T(),s=n||i.annotation,a=I(f=>s?f.iiif.entities.Annotation[s]:void 0,[s]),l=I(f=>a&&a.body?a.body.map(d=>d?d.type==="SpecificResource"?{...d,source:o.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:ne.expandTarget(a.target,{typeMap:o.getState().iiif.mapping})};return r?r(f):f},[a,r,l,...t])}const Ee=({id:e,style:t,className:n,interactive:r})=>{const i=Pe({id:e}),o=W(i,"atlas"),s=W(i,"html"),a=je(i,["atlas"]),l=O(),f=u.useMemo(()=>F.mergeStyles(t,o),[t,o]);return l&&i&&i.target&&i.target.selector&&i.target.selector.type==="BoxSelector"&&i.target.source&&(i.target.source.id===l.id||i.target.source===l.id)?c.jsx(F.RegionHighlight,{id:i.id,isEditing:!0,region:i.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 Ut(e={},t=[]){const{id:n,selector:r}=e,i=U(),o=n||i.annotationPage,s=I(a=>o?a.iiif.entities.AnnotationPage[o]:void 0,[o]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,...t])}const re=({className:e,page:t})=>{var o;const n=Ut({id:t.id})||t,r=W(n,"atlas"),i=W(n,"html");return I(s=>n.id?s.iiif.entities.AnnotationPage[n.id]:null,[]),c.jsx(u.Fragment,{children:(o=n.items)==null?void 0:o.map(s=>c.jsx(Ee,{id:s.id,style:r,className:(i==null?void 0:i.className)||e},s.id))})};function Ie({id:e,image:t,thumbnail:n,isStatic:r,x:i=0,y:o=0,children:s,selector:a,onClick:l,enableSizes:f}){var h,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:i+t.target.spatial.x,y:o+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(F.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:(h=t.target)==null?void 0:h.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 Te(e,t){const{selector:n,source:r}=$e.expandTarget(t);if(r.id!==e.id)return[null,r];const i={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:i.spatial}:n:null,r]}const qt={makeChoice:()=>{}},te={type:"unknown"},M=e=>({type:"unknown",reason:e,annotations:{pages:[]}}),Dt=(e,t)=>({type:"empty",width:e,height:t,annotations:{pages:[]},image:null,images:[]});function _t(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 Bt(e,t){return I(n=>{const r=[];if(!e)return r;const i=Object.keys(n.iiif.entities.AnnotationPage);for(const o of i)if(!t||t.indexOf(o)!==-1){const s=_t(n,o);s&&s.views&&s.views[e]&&r.push(o)}return r},[e,t])}function Ht({canvas:e,manifest:t,all:n,canvases:r}){const i=[];if(t)for(const o of t.annotations)i.indexOf(o.id)===-1&&i.push(o.id);if(n){if(r&&r.length)for(const o of r)for(const s of o.annotations)i.indexOf(s.id)===-1&&i.push(s.id)}else if(e)for(const o of e.annotations)i.indexOf(o.id)===-1&&i.push(o.id);return i}function Yt(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 $t(e,t={}){const n=T(),r=q(),i=O(),o=xe(),s=u.useMemo(()=>Ht({all:t.all,manifest:r,canvas:i,canvases:o}),[t.all,i,o,r]),a=Bt(e,t.all?void 0:s),l=u.useCallback(d=>{e&&n.setMetaValue([d,"annotationPageManager","views"],h=>h&&!h[e]?h:{...h||{},[e]:!1})},[e,n]),f=u.useCallback((d,h={})=>{if(!e)return;const p=n.getState(),x=[];if(h!=null&&h.deselectOthers){const v=Object.keys(p.iiif.entities.AnnotationPage);for(const m of v){const C=Yt(p,m);C&&C.views&&C.views[e]&&x.push(m)}}for(const v of x)l(v);n.setMetaValue([d,"annotationPageManager","views"],v=>v&&v[e]?v:{...v||{},[e]:!0})},[e,l,n]);return{availablePageIds:s,enabledPageIds:a,setPageEnabled:f,setPageDisabled:l}}function zt(e,t){return I((n,r)=>r.get(e.map(i=>({id:i,type:t}))),[e,t])}const Kt=u.createContext(new pe.ImageServiceLoader);function Ae(){return u.useContext(Kt)}function Wt(){const e=Ae(),[t,n]=u.useState({}),r=u.useRef(!1);return u.useEffect(()=>()=>{r.current=!0},[]),[u.useCallback((o,{height:s,width:a})=>{if(o){const l=o.id||o["@id"],f=e.loadServiceSync({id:l,width:o.width||a,height:o.height||s,source:o});f?o=f:t[l]||(r.current||n(d=>({...d,[l]:"loading"})),e.loadService({id:l,width:o.width||a,height:o.height||s}).then(()=>{r.current||n(d=>({...d,[l]:"done"}))}))}return o},[e,t]),t]}function Gt(e={}){const t=Pe(),n=O(e.canvasId?{id:e.canvasId}:void 0);return I((r,i)=>{if(!n)return[];if(t&&e.enableSingleAnnotation)return[t];const o=i.get(n.items),s=[];for(const a of o)s.push(...i.get(a.items));return s},[n])}function Qt(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}const z={},Re={get(e){return e},setMetaValue([e,t,n],r){const i=Re.getResourceMeta(e,t),o=i?i[n]:void 0,s=typeof r=="function"?r(o):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 Jt(e=Re){function t(i){const o=i?typeof i=="string"?e.get(i):i:null;if(!o)return[];const s=e.get(o.items,{parent:o}),a=[];for(const l of s)a.push(...e.get(l.items,{parent:l}));return a}function n(i,o=[]){const s=Array.isArray(i)?i:t(i),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 h=Array.from(Array.isArray(d.body)?d.body:[d.body]);for(const p of h){const[x,{selector:v}]=Qt(p),m=e.get(x),C=(m.type||"unknown").toLowerCase();if(C==="choice"){const y=e.get(m.items,{parent:m.id}),j=o.length?o.map(S=>y.find(D=>D.id===S)).filter(Boolean):[y[0]];j.length===0&&j.push(y[0]),l={type:"single-choice",items:y.map(S=>({id:S.id,label:S.label,selected:j.indexOf(S)!==-1})),label:x.label},h.push(...j);continue}a.indexOf(C)===-1&&a.push(C),f.push({type:C,annotationId:d.id,resource:m,target:d.target,selector:v})}}return{types:a,items:f,choice:l}}function r(i){const{choice:o}=n(i);return o}return{getAllPaintingAnnotations:t,getPaintables:n,extractChoices:r}}function Zt(e,t=[]){const n=T(),r=u.useMemo(()=>Jt(n),[]),i=Gt({enableSingleAnnotation:e==null?void 0:e.enableSingleAnnotation}),[o,s]=u.useState((e==null?void 0:e.defaultChoices)||[]),a=u.useMemo(()=>r.getPaintables(i,o),[n,i,o,...t]),f={makeChoice:u.useCallback((d,{deselectOthers:h=!0,deselect:p=!1}={})=>{if(a.choice){if(a.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");s(x=>{if(p){const m=x.filter(C=>C!==d);if(m.length===0){const C=a.items[0].resource.id;return C?[C]:[]}return m}if(h)return[d];const v=[...x];if(v.length===0&&a.items.length){const m=a.items[0].resource.id;m&&v.push(m)}return x.indexOf(d)!==-1?x:[...x,d]})}},[a.choice])};return[a,f]}const Xt=["model/gltf-binary"];function en(e,t){const r=t.items[0].resource;return r.format?Xt.indexOf(r.format)===-1?M(`3D format: ${r.format} is unsupported`):{type:"3d-model",model:r}:M("Unknown format")}function tn(e,t){var r;if(!e.duration)return M("No duration on canvas");if(t.items.length>1)return M("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:[]}}:M("Audio does not have format"):M("Unknown audio")}function nn(e,t,n){const r=[];for(const i of t.items){const o=i.resource&&i.resource.type==="SpecificResource"?i.resource.source:i.resource;if(!o.id)return M("No resource Identifier");let s;if(o.service){const x=pe.getImageServices(o);x[0]&&(s=n(x[0],e))}const a={type:"BoxSelector",spatial:{x:0,y:0,width:Number(e.width),height:Number(e.height)}},[l,f]=Te(e,i.target);if(!(f.id===e.id||decodeURIComponent(f.id||"")===(e.id||"")))continue;i.resource.width&&i.resource.height&&(i.resource.width,i.resource.height);let d=i.resource.type==="SpecificResource"?ne.expandTarget(i.resource):null;if(i.selector){const x=ne.expandTarget({type:"SpecificResource",source:i.resource,selector:i.selector});x&&(d=x)}const h=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:o.id,type:"Image",annotationId:i.annotationId,width:Number(l||h?o.width:e.width),height:Number(l||h?o.height:e.height),service:s,sizes:s&&s.sizes?s.sizes:o.width&&o.height?[{width:o.width,height:o.height}]:[],target:l&&l.type!=="PointSelector"?l:a,selector:h};r.push(p)}return{type:"images",image:r[0],images:r,choice:t.choice}}function Ve(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(i=>Ve(i,t,r))}return t}function rn(e,t){const n=[];return t.items.forEach(r=>{if(r.resource){const[i]=Te(e,r.target);n.push({annotationId:r.annotationId,text:Ve(r.resource),target:i})}}),{type:"textual-content",items:n}}const on=/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?vi?=|&vi?=))([^#&?]*).*/;function sn(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 M("Only one video source supported");const i=(a=n[0])==null?void 0:a.resource,o=!!(i.service||[]).find(l=>(l.profile||"").includes("youtube.com"));if(!o&&r)return M("Video does not have duration");if(!i)return M("Unknown video");if((!i.format||i.format==="text/html")&&!o)return M("Video does not have format");const s={annotationId:t.items[0].annotationId,duration:e.duration,url:i.id,type:"Video",items:[],target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:i.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}};if(o){s.type="VideoYouTube";const l=i.id.match(on);if(!l[1])return M("Video is not known youtube video");s.youTubeId=l[1]}return{type:"media",media:s,annotations:{pages:[]}}}function an({canvas:e,paintables:t,supports:n,loadImageService:r}){if(!e)return console.log("No canvas"),te;if(t.types.length===0)return n.indexOf("empty")!==-1?Dt(e.width,e.height):(console.log("No paintables"),te);if(t.types.length!==1)if(t.types.length===2&&t.types.indexOf("text")!==-1)t.types=t.types.filter(o=>o!=="text");else return n.indexOf("complex-timeline")===-1?M("Complex timeline not supported"):M("ComplexTimelineStrategy not yet supported");const i=t.types[0];return i==="image"?n.indexOf("images")===-1?M("Image not supported"):nn(e,t,r):i==="Model"||i==="model"?n.indexOf("3d-model")===-1?M("3D not supported"):en(e,t):i==="textualbody"?n.indexOf("textual-content")===-1?M("Textual content not supported"):rn(e,t):i==="sound"||i==="audio"?n.indexOf("media")===-1?M("Media not supported"):tn(e,t):i==="video"?n.indexOf("media")===-1?M("Media not supported"):sn(e,t):te}function un(e){const t=q(),n=O(),r=T(),[i,o]=Wt(),{enabledPageIds:s}=$t((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(n==null?void 0:n.id),{all:!1}),a=zt(s,"AnnotationPage"),l=(e==null?void 0:e.strategies)||["empty","images","media","textual-content","complex-timeline"],[f,d]=Zt(e,[o]),h=u.useMemo(()=>an({canvas:n,paintables:f,supports:l,loadImageService:i}),[n,f,r,d.makeChoice]);return u.useMemo(()=>h.type==="unknown"?[h,qt]:[{...h,annotations:{pages:a}},d],[h,a])}const cn=(e,t=[])=>{const n=T();u.useEffect(()=>{e(n)},[n,...t])};function ln(e,t,{canvasId:n,manifestId:r}={}){const i=T(),o=Ae(),s=u.useMemo(()=>ze.createThumbnailHelper(i,{imageServiceLoader:o}),[i,o]),[a,l]=u.useState(),f=q(r?{id:r}:void 0),d=O(n?{id:n}:void 0),h=d||f,p=u.useRef(!1);if(u.useEffect(()=>(p.current=!1,()=>{p.current=!0}),[]),!h)throw new Error("Must be called under a manifest or canvas context.");return cn(x=>{s.getBestThumbnailAtSize(h,e,t).then(v=>{v.best&&!p.current&&l(v.best)})},[h]),a}function dn(e){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:e}}function fn(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 hn(e){const t=Math.round(e);return`${Math.floor(t/60)}:${`${t%60}`.padStart(2,"0")}`}function ce(e){const[t,n]=u.useReducer(fn,dn(e.duration)),r=u.useRef(null),i=u.useRef(null),o=u.useRef(null),s=u.useRef(!1),a=u.useCallback(()=>{i.current&&r.current&&(i.current.innerHTML=hn(r.current.currentTime),o.current&&(o.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]),h=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"}))},[]),x=u.useCallback(()=>{r.current&&(r.current.muted=!1,n({type:"UNMUTE"}))},[]),v=u.useCallback(y=>{r.current&&(r.current.muted=!1,r.current.volume=y/100,n({type:"SET_VOLUME",volume:y}))},[]),m=u.useCallback(y=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(y*e.duration,e.duration)),a())},[]),C=u.useCallback(y=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(y,e.duration)),a())},[]);return u.useEffect(()=>{const y=setInterval(()=>{a()},350);return()=>clearInterval(y)},[a,e.duration]),u.useEffect(()=>{const y=()=>{n({type:"FINISHED"})},j=r.current;return j==null||j.addEventListener("ended",y),()=>j==null?void 0:j.removeEventListener("ended",y)},[]),[{element:r,currentTime:i,progress:o},t,{play:l,pause:d,playPause:f,mute:p,unmute:x,toggleMute:h,setVolume:v,setDurationPercent:m,setTime:C}]}const gn=u.createContext(null),mn=u.createContext(null),vn=u.createContext(null);function ke({actions:e,state:t,children:n,currentTime:r,progress:i,element:o}){return c.jsx(vn.Provider,{value:{currentTime:r,progress:i,element:o},children:c.jsx(mn.Provider,{value:e,children:c.jsx(gn.Provider,{value:t,children:n})})})}function Oe({media:e,children:t}){const[{element:n,currentTime:r,progress:i},o,s]=ce({duration:e.duration});return c.jsxs(ke,{state:o,actions:s,currentTime:r,progress:i,element:n,children:[c.jsx("audio",{ref:n,src:e.url}),t]})}function Le({media:e,mediaControlsDeps:t,children:n}){return N("portal","audio",Oe,{media:e,children:n},[e,...t||[]]),null}function Fe({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;
@@ -11,7 +11,7 @@
11
11
  justify-content: center;
12
12
  pointer-events: visible;
13
13
  }
14
- `}),c.jsx("video",{ref:e,src:t.url,style:{width:"100%",objectFit:"contain"}})]})}function Fe({media:e,mediaControlsDeps:t,children:n}){const[{element:r,currentTime:i,progress:o},s,a]=ae({duration:e.duration});return N("overlay","video-element",Le,{element:r,media:e,playPause:a.playPause}),N("portal","custom-controls",Ve,{state:s,actions:a,currentTime:i,progress:o,element:r,children:n},[i,s,e,...t||[]]),null}function Ne({model:e}){return c.jsxs(c.Fragment,{children:[c.jsx("style",{children:`
14
+ `}),c.jsx("video",{ref:e,src:t.url,style:{width:"100%",objectFit:"contain"}})]})}function Ne({media:e,mediaControlsDeps:t,children:n}){const[{element:r,currentTime:i,progress:o},s,a]=ce({duration:e.duration});return N("overlay","video-element",Fe,{element:r,media:e,playPause:a.playPause}),N("portal","custom-controls",ke,{state:s,actions:a,currentTime:i,progress:o,element:r,children:n},[i,s,e,...t||[]]),null}function Ue({model:e}){return c.jsxs(c.Fragment,{children:[c.jsx("style",{children:`
15
15
  .model-container {
16
16
  position: absolute;
17
17
  top: 0;
@@ -24,8 +24,8 @@
24
24
  justify-content: center;
25
25
  pointer-events: visible;
26
26
  }
27
- `}),c.jsx("div",{className:"model-container",children:c.jsx("model-viewer",{"interaction-prompt":"none",style:{width:"100%",height:"100%"},"camera-controls":"","ar-status":"not-presenting",src:e.id})})]})}function Ue({model:e,name:t}){return N("overlay",`model-${t}`,Ne,{model:e},[e]),null}function qe({style:e}){const t=O();return!t||!t.height||!t.width?null:c.jsx("box",{interactive:!1,target:{x:0,y:0,width:Number(t.width),height:Number(t.height)},style:e})}const vn=u.createContext("en");function De(){return u.useContext(vn)}function he(e){return e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):e}function pn({as:e,language:t,children:n,viewingDirection:r,...i}){const o=De();return u.useMemo(()=>he(o)===he(t),[o,t])?e?c.jsx(e,{...i,children:n}):c.jsx("span",{...i,children:n}):e?c.jsx(e,{...i,lang:t,dir:r,children:n}):c.jsx("span",{...i,lang:t,dir:r,children:n})}function xn(e,t,n){if(t.length===0)return;if(t.length===1)return t[0];if(t.indexOf(e)!==-1)return e;const r=e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):null;if(r&&t.indexOf(r)!==-1)return r;for(const i of n)if(t.indexOf(i)!==-1)return i;return t.indexOf("none")!==-1?"none":t.indexOf("@none")!==-1?"@none":t[0]}const yn=(e,t=[])=>{const n=De();return u.useMemo(()=>{const r=e();return xn(n,r,[])},[n,...t])};function Cn(e,t,n=`
28
- `){const r=yn(()=>Object.keys(e||{}),[e]);return[u.useMemo(()=>{if(!e)return t||"";if(typeof e=="string")return e;const i=r?e[r]:void 0;return i?typeof i=="string"?i:i.join(n):""},[r,t,e]),r]}function bn({as:e,defaultText:t,enableDangerouslySetInnerHTML:n,children:r,separator:i,...o}){const[s,a]=Cn(r,t,i);return a?c.jsx(pn,{...o,as:e,language:a,title:n?void 0:s,dangerouslySetInnerHTML:n?{__html:s}:void 0,children:n?void 0:s}):e?c.jsx(e,{...o,children:s}):c.jsx("span",{...o,title:n?void 0:s,dangerouslySetInnerHTML:n?{__html:s}:void 0,children:n?void 0:s})}function Sn({element:e,media:t,playPause:n}){const r=u.useRef(null);return t.youTubeId?c.jsxs("div",{className:"video-container",part:"video-container",onClick:n,children:[c.jsx("style",{children:`
27
+ `}),c.jsx("div",{className:"model-container",children:c.jsx("model-viewer",{"interaction-prompt":"none",style:{width:"100%",height:"100%"},"camera-controls":"","ar-status":"not-presenting",src:e.id})})]})}function qe({model:e,name:t}){return N("overlay",`model-${t}`,Ue,{model:e},[e]),null}function De({style:e}){const t=O();return!t||!t.height||!t.width?null:c.jsx("box",{interactive:!1,target:{x:0,y:0,width:Number(t.width),height:Number(t.height)},style:e})}const pn=u.createContext("en");function _e(){return u.useContext(pn)}function me(e){return e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):e}function xn({as:e,language:t,children:n,viewingDirection:r,...i}){const o=_e();return u.useMemo(()=>me(o)===me(t),[o,t])?e?c.jsx(e,{...i,children:n}):c.jsx("span",{...i,children:n}):e?c.jsx(e,{...i,lang:t,dir:r,children:n}):c.jsx("span",{...i,lang:t,dir:r,children:n})}function yn(e,t,n){if(t.length===0)return;if(t.length===1)return t[0];if(t.indexOf(e)!==-1)return e;const r=e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):null;if(r&&t.indexOf(r)!==-1)return r;for(const i of n)if(t.indexOf(i)!==-1)return i;return t.indexOf("none")!==-1?"none":t.indexOf("@none")!==-1?"@none":t[0]}const Cn=(e,t=[])=>{const n=_e();return u.useMemo(()=>{const r=e();return yn(n,r,[])},[n,...t])};function bn(e,t,n=`
28
+ `){const r=Cn(()=>Object.keys(e||{}),[e]);return[u.useMemo(()=>{if(!e)return t||"";if(typeof e=="string")return e;const i=r?e[r]:void 0;return i?typeof i=="string"?i:i.join(n):""},[r,t,e]),r]}function Sn({as:e,defaultText:t,enableDangerouslySetInnerHTML:n,children:r,separator:i,...o}){const[s,a]=bn(r,t,i);return a?c.jsx(xn,{...o,as:e,language:a,title:n?void 0:s,dangerouslySetInnerHTML:n?{__html:s}:void 0,children:n?void 0:s}):e?c.jsx(e,{...o,children:s}):c.jsx("span",{...o,title:n?void 0:s,dangerouslySetInnerHTML:n?{__html:s}:void 0,children:n?void 0:s})}function wn({element:e,media:t,playPause:n}){const r=u.useRef(null);return t.youTubeId?c.jsxs("div",{className:"video-container",part:"video-container",onClick:n,children:[c.jsx("style",{children:`
29
29
  .video-container {
30
30
  position: absolute;
31
31
  top: 0;
@@ -43,5 +43,5 @@
43
43
  width: 100%;
44
44
  object-fit: contain;
45
45
  }
46
- `}),c.jsx("iframe",{className:"video-yt",ref:r,src:`https://www.youtube.com/embed/${t.youTubeId}?enablejsapi=1&origin=${window.location.host}`,referrerPolicy:"no-referrer",sandbox:"allow-scripts allow-same-origin allow-presentation"})]}):null}function wn({media:e,mediaControlsDeps:t,children:n}){const[{element:r,currentTime:i,progress:o},s,a]=ae({duration:e.duration});return N("overlay","video-element",Sn,{element:r,media:e,playPause:a.playPause}),null}function _e({x:e,y:t,onChoiceChange:n,registerActions:r,defaultChoices:i,isStatic:o,renderViewerControls:s,renderMediaControls:a,viewControlsDeps:l,mediaControlsDeps:f,strategies:d,throwOnUnknown:h,backgroundStyle:p,alwaysShowBackground:x,keepCanvasScale:v=!1,enableSizes:m=!1,enableYouTube:C=!0,onClickPaintingAnnotation:y,children:P}){const S=O(),D=Me(S,["deep-zoom"]),[Y]=At(),w=kt(),j=I(),A=u.useMemo(()=>ge.createStylesHelper(j),[j]),[g,V]=an({strategies:d||["images"],defaultChoices:i==null?void 0:i.map(({id:b})=>b)}),ue=g.type==="images"?g.choice:void 0,Be=u.useMemo(()=>v?1:Math.max(1,...g.type==="images"?g.images.map(b=>{var L;return(b.width||0)/((L=b.target)==null?void 0:L.spatial.width)}):[]),[v,g]);Ot(Be),u.useEffect(()=>{r&&r(V)},[g.annotations]),u.useEffect(()=>{if(i)for(const b of i)typeof b.opacity<"u"&&A.applyStyles({id:b.id},"atlas",{opacity:b.opacity})},[i]),u.useLayoutEffect(()=>{n&&n(ue)},[ue]),N(w&&(g.type==="images"||g.type==="empty"||g.type==="textual-content"&&s)?"overlay":"none",`canvas-portal-controls-${S==null?void 0:S.id}`,se.Provider,s?{value:w||null,children:s(g)}:{},[S,w,g,...l||[]]);const k=cn({maxWidth:256,maxHeight:256});if(!S)return null;const ce=S.accompanyingCanvas,_=k&&k.type==="fixed"?c.jsx("world-object",{height:S.height,width:S.width,x:e,y:t,children:c.jsx("world-image",{uri:k.id,target:{x:0,y:0,width:S.width,height:S.height},display:k.width&&k.height?{width:k.width,height:k.height}:void 0,crop:void 0})}):null;if(g.type==="unknown"){if(_)return _;if(h)throw new Error(g.reason||"Unknown image strategy");return null}const le=c.jsxs(u.Fragment,{children:[Y?c.jsx(re,{page:Y}):null,g.annotations&&g.annotations.pages?g.annotations.pages.map(b=>c.jsx(re,{page:b},b.id)):null,P]}),He=g.type==="images"?g.images.length:0;return c.jsxs(c.Fragment,{children:[c.jsxs("world-object",{height:S.height,width:S.width,x:e,y:t,...D,children:[g.type==="empty"||x?c.jsx(qe,{style:p}):null,g.type==="textual-content"?g.items.map((b,L)=>{var B;return c.jsxs(c.Fragment,{children:[c.jsx(F.HTMLPortal,{onClick:y?de=>{de.stopPropagation(),y(b.annotationId,b,de)}:void 0,target:((B=b.target)==null?void 0:B.spatial)||void 0,children:c.jsx("div",{"data-textual-content":!0,children:c.jsx(bn,{enableDangerouslySetInnerHTML:!0,children:b.text})})},L),le]})}):null,g.type==="images"?c.jsxs(c.Fragment,{children:[g.images.map((b,L)=>c.jsx(Ee,{isStatic:o,image:b,id:b.id,thumbnail:L===0?k:void 0,selector:b.selector,enableSizes:m,onClick:y?B=>{B.stopPropagation(),y(b.annotationId,b,B)}:void 0},b.id+L)),le]}):null,g.type==="3d-model"?c.jsx(Ue,{model:g.model}):null,g.type==="media"?c.jsx(c.Fragment,{children:g.media.type==="Sound"?c.jsxs(Oe,{media:g.media,mediaControlsDeps:f,children:[_,a?a(g):null]}):g.media.type==="Video"?c.jsxs(Fe,{media:g.media,mediaControlsDeps:f,children:[_,a?a(g):null]}):g.media.type==="VideoYouTube"&&C?c.jsxs(wn,{media:g.media,mediaControlsDeps:f,children:[_,a?a(g):null]}):null}):null]},`${S.id}/${g.type}/${He}`),g.type==="media"&&g.media.type==="Sound"&&ce?c.jsx(oe,{canvas:ce.id,children:c.jsx(_e,{renderViewerControls:s})}):null]})}function Mn(){const e=u.useContext(Q);return e&&e.vault?e.vault:K.globalVault()}const Pn=u.forwardRef(function(t,n){const r=q(),i=pe(),o=ot(),{ViewerControls:s,MediaControls:a}=t.components||{};if(u.useImperativeHandle(n,()=>o,[o]),!r)return c.jsx("div",{});let l=0;return c.jsxs(c.Fragment,{children:[t.header,c.jsx(E.Viewer,{height:t.height,mode:t.mode,children:i.map((f,d)=>{const h=l;return l+=f.width+(t.spacing||0),c.jsx(oe,{canvas:f.id,children:c.jsx(E.RenderCanvas,{strategies:["3d-model","media","images","empty","textual-content"],renderViewerControls:d===0&&s?()=>c.jsx(s,{}):void 0,renderMediaControls:d===0&&a?()=>c.jsx(a,{}):void 0,x:h,...t.canvasProps||{},children:t.annotations},f.id)},f.id)})},t.reuseAtlas?"":o.currentSequenceIndex),t.children]})}),E=u.forwardRef(function({children:t,height:n,annotations:r,canvasProps:i,spacing:o,header:s,components:a,mode:l,reuseAtlas:f,...d},h){const p=Mn();return c.jsx(ve,{vault:p,children:c.jsx(it,{...d,children:c.jsx(Pn,{ref:h,height:n,components:a,spacing:o,canvasProps:i,annotations:r,header:s,mode:l,reuseAtlas:f,children:t})})})});E.RenderImage=Ee;E.RenderCanvas=_e;E.RenderAnnotationPage=re;E.RenderAnnotation=je;E.Viewer=Lt;E.CanvasBackground=qe;E.Audio=Oe;E.Video=Fe;E.Model=Ue;E.AudioHTML=ke;E.VideoHTML=Le;E.ModelHTML=Ne;exports.CanvasPanel=E;
46
+ `}),c.jsx("iframe",{className:"video-yt",ref:r,src:`https://www.youtube.com/embed/${t.youTubeId}?enablejsapi=1&origin=${window.location.host}`,referrerPolicy:"no-referrer",sandbox:"allow-scripts allow-same-origin allow-presentation"})]}):null}function Mn({media:e,mediaControlsDeps:t,children:n}){const[{element:r,currentTime:i,progress:o},s,a]=ce({duration:e.duration});return N("overlay","video-element",wn,{element:r,media:e,playPause:a.playPause}),null}function Be({x:e,y:t,onChoiceChange:n,registerActions:r,defaultChoices:i,isStatic:o,renderViewerControls:s,renderMediaControls:a,viewControlsDeps:l,mediaControlsDeps:f,strategies:d,throwOnUnknown:h,backgroundStyle:p,alwaysShowBackground:x,keepCanvasScale:v=!1,enableSizes:m=!1,enableYouTube:C=!0,onClickPaintingAnnotation:y,children:j}){const S=O(),D=je(S,["deep-zoom"]),[Y]=Rt(),w=Ot(),P=T(),A=u.useMemo(()=>ve.createStylesHelper(P),[P]),[g,V]=un({strategies:d||["images"],defaultChoices:i==null?void 0:i.map(({id:b})=>b)}),le=g.type==="images"?g.choice:void 0,He=u.useMemo(()=>v?1:Math.max(1,...g.type==="images"?g.images.map(b=>{var L;return(b.width||0)/((L=b.target)==null?void 0:L.spatial.width)}):[]),[v,g]);Lt(He),u.useEffect(()=>{r&&r(V)},[g.annotations]),u.useEffect(()=>{if(i)for(const b of i)typeof b.opacity<"u"&&A.applyStyles({id:b.id},"atlas",{opacity:b.opacity})},[i]),u.useLayoutEffect(()=>{n&&n(le)},[le]),N(w&&(g.type==="images"||g.type==="empty"||g.type==="textual-content"&&s)?"overlay":"none",`canvas-portal-controls-${S==null?void 0:S.id}`,ue.Provider,s?{value:w||null,children:s(g)}:{},[S,w,g,...l||[]]);const k=ln({maxWidth:256,maxHeight:256});if(!S)return null;const de=S.accompanyingCanvas,_=k&&k.type==="fixed"?c.jsx("world-object",{height:S.height,width:S.width,x:e,y:t,children:c.jsx("world-image",{uri:k.id,target:{x:0,y:0,width:S.width,height:S.height},display:k.width&&k.height?{width:k.width,height:k.height}:void 0,crop:void 0})}):null;if(g.type==="unknown"){if(_)return _;if(h)throw new Error(g.reason||"Unknown image strategy");return null}const fe=c.jsxs(u.Fragment,{children:[Y?c.jsx(re,{page:Y}):null,g.annotations&&g.annotations.pages?g.annotations.pages.map(b=>c.jsx(re,{page:b},b.id)):null,j]}),Ye=g.type==="images"?g.images.length:0;return c.jsxs(c.Fragment,{children:[c.jsxs("world-object",{height:S.height,width:S.width,x:e,y:t,...D,children:[g.type==="empty"||x?c.jsx(De,{style:p}):null,g.type==="textual-content"?g.items.map((b,L)=>{var B;return c.jsxs(c.Fragment,{children:[c.jsx(F.HTMLPortal,{onClick:y?he=>{he.stopPropagation(),y(b.annotationId,b,he)}:void 0,target:((B=b.target)==null?void 0:B.spatial)||void 0,children:c.jsx("div",{"data-textual-content":!0,children:c.jsx(Sn,{enableDangerouslySetInnerHTML:!0,children:b.text})})},L),fe]})}):null,g.type==="images"?c.jsxs(c.Fragment,{children:[g.images.map((b,L)=>c.jsx(Ie,{isStatic:o,image:b,id:b.id,thumbnail:L===0?k:void 0,selector:b.selector,enableSizes:m,onClick:y?B=>{B.stopPropagation(),y(b.annotationId,b,B)}:void 0},b.id+L)),fe]}):null,g.type==="3d-model"?c.jsx(qe,{model:g.model}):null,g.type==="media"?c.jsx(c.Fragment,{children:g.media.type==="Sound"?c.jsxs(Le,{media:g.media,mediaControlsDeps:f,children:[_,a?a(g):null]}):g.media.type==="Video"?c.jsxs(Ne,{media:g.media,mediaControlsDeps:f,children:[_,a?a(g):null]}):g.media.type==="VideoYouTube"&&C?c.jsxs(Mn,{media:g.media,mediaControlsDeps:f,children:[_,a?a(g):null]}):null}):null]},`${S.id}/${g.type}/${Ye}`),g.type==="media"&&g.media.type==="Sound"&&de?c.jsx(ae,{canvas:de.id,children:c.jsx(Be,{renderViewerControls:s})}):null]})}const jn=u.forwardRef(function(t,n){const r=q(),i=xe(),o=st(),{ViewerControls:s,MediaControls:a}=t.components||{};if(u.useImperativeHandle(n,()=>o,[o]),!r)return c.jsx("div",{});let l=0;return c.jsxs(c.Fragment,{children:[t.header,c.jsx(E.Viewer,{height:t.height,mode:t.mode,children:i.map((f,d)=>{const h=l;return l+=f.width+(t.spacing||0),c.jsx(ae,{canvas:f.id,children:c.jsx(E.RenderCanvas,{strategies:["3d-model","media","images","empty","textual-content"],renderViewerControls:d===0&&s?()=>c.jsx(s,{}):void 0,renderMediaControls:d===0&&a?()=>c.jsx(a,{}):void 0,x:h,...t.canvasProps||{},children:t.annotations},f.id)},f.id)})},t.reuseAtlas?"":o.currentSequenceIndex),t.children]})}),E=u.forwardRef(function({children:t,height:n,annotations:r,canvasProps:i,spacing:o,header:s,components:a,mode:l,reuseAtlas:f,...d},h){const p=se();return c.jsx(oe,{vault:p,children:c.jsx(ot,{...d,children:c.jsx(jn,{ref:h,height:n,components:a,spacing:o,canvasProps:i,annotations:r,header:s,mode:l,reuseAtlas:f,children:t})})})});E.RenderImage=Ie;E.RenderCanvas=Be;E.RenderAnnotationPage=re;E.RenderAnnotation=Ee;E.Viewer=Ft;E.CanvasBackground=De;E.Audio=Le;E.Video=Ne;E.Model=qe;E.AudioHTML=Oe;E.VideoHTML=Fe;E.ModelHTML=Ue;exports.CanvasPanel=E;
47
47
  //# sourceMappingURL=canvas-panel.js.map