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"),F=require("@atlas-viewer/atlas"),K=require("@iiif/helpers/vault"),pe=require("@iiif/helpers/styles"),ne=require("@iiif/helpers/annotation-targets"),ze=require("@iiif/helpers"),ve=require("@atlas-viewer/iiif-image-api"),Ke=require("@iiif/helpers/thumbnail");function We(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 X=We(u);function re(e,t){return re=Object.setPrototypeOf||function(r,o){return r.__proto__=o,r},re(e,t)}function Ge(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,re(e,t)}var Qe=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])})},ge={error:null},Je=function(e){Ge(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=ge,r.resetErrorBoundary=function(){for(var a,d=arguments.length,f=new Array(d),l=0;l<d;l++)f[l]=arguments[l];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(ge)},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&&Qe(o.resetKeys,a)){var d,f;(d=(f=this.props).onResetKeysChange)==null||d.call(f,o.resetKeys,a),this.reset()}},n.render=function(){var o=this.state.error,i=this.props,s=i.fallbackRender,a=i.FallbackComponent,d=i.fallback;if(o!==null){var f={error:o,resetErrorBoundary:this.resetErrorBoundary};if(X.isValidElement(d))return d;if(typeof s=="function")return s(f);if(a)return X.createElement(a,f);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},t}(X.Component);const Ze={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},ie=u.createContext(Ze),D=()=>u.useContext(ie);function G({value:e,children:t}){const n=D(),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 ye({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:o}){const[i,s]=u.useState(()=>e||(n?K.globalVault(t):t?new K.Vault(t):new K.Vault));return c.jsx(Q.Provider,{value:{vault:i,setVaultInstance:s},children:c.jsx(G,{value:r||{},children:o})})}const A=()=>{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 Xe(e,{noCache:t=!1}={}){const n=typeof e=="string"?e:e.id,r=A(),[o,i]=u.useState(n),[s,a]=u.useState(void 0),d=u.useMemo(()=>r.get(n,{skipSelfReturn:!0})||void 0,[n,r]),[f,l]=u.useState(d);return u.useEffect(()=>{(async()=>{try{const g=d&&!t?d:await r.load(n),v=g?g.id||g["@id"]:null;g&&o!==v&&i(v),l(g)}catch(g){a(g)}})()},[n,t]),{isLoaded:!!f,id:o,requestId:n,error:s,resource:f,cached:!!(f&&f===d)}}function et(e,t){const{id:n,isLoaded:r,error:o,resource:i,requestId:s,cached:a}=Xe(e,t);return{id:n,isLoaded:r,error:o,manifest:i,requestId:s,cached:a}}function tt({manifest:e,children:t}){return c.jsx(G,{value:{manifest:e},children:t})}function se({canvas:e,children:t}){return c.jsx(G,{value:{canvas:e},children:t})}function I(e,t=[]){const n=A(),[r,o]=u.useState(()=>e(n.getState(),n));return u.useEffect(()=>n.subscribe(i=>e(i,n),i=>{o(i)},!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 _(e={},t=[]){const{id:n,selector:r}=e,o=D();A();const i=n||o.manifest,s=I(a=>i?a.iiif.entities.Manifest[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}function nt({range:e,children:t}){return c.jsx(G,{value:{range:e},children:t})}function be(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(...be(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 rt(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"),d=t.type==="Manifest"?t.items:be(e,t);if(s)return[d,[d.map((p,m)=>m)]];if(a||!i||n)return[d,d.map((p,m)=>[m])];const f=[];let l=[];const g=()=>{l.length&&(f.push([...l]),l=[])};let v=0,y=!1;for(let p=0;p<d.length;p++){const m=e.get(d[p]);if(m.behavior.includes("non-paged")){p===v&&v++,r||(g(),f.push([p]),g());continue}if(p===v||m.behavior.includes("facing-pages")){l.length&&(y=!0),g(),f.push([p]),g();continue}if(l.push(p),y){g(),y=!1;continue}l.length>1&&g()}return l.length&&g(),[d,f]}function ot(e={},t=[]){const{id:n,selector:r}=e,o=D(),i=n||o.range,s=I(a=>i?a.iiif.entities.Range[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}function it({startCanvas:e,disablePaging:t}){var p;const n=A(),r=_(),o=ot(),[i,s]=u.useState(void 0),a=o||r;if(!a)throw new Error("Nothing selected");const[d,f]=u.useMemo(()=>rt(n,a,{disablePaging:t}),[n,a]),l=u.useCallback(m=>{const b=f.findIndex(x=>x.includes(m));s(b===-1?0:b)},[d,f]),g=u.useCallback(m=>{const b=d.findIndex(x=>x.id===m);b!==-1?l(b):s(0)},[d,f]),v=u.useCallback(()=>{s(m=>m>=f.length?m:m+1)},[f]),y=u.useCallback(()=>{s(m=>m<=0?0:m-1)},[f]);return typeof i>"u"&&(e?g(e):s(0)),{visibleItems:((p=f[i])==null?void 0:p.map(m=>d[m].id))||[],cursor:i,items:d,sequence:f,setSequenceIndex:s,setCanvasIndex:l,setCanvasId:g,next:v,previous:y}}const B=()=>{},Z=u.createContext({setCurrentCanvasId:B,setCurrentCanvasIndex:B,nextCanvas:B,previousCanvas:B,items:[],sequence:[],setSequenceIndex:B,currentSequenceIndex:0});function st(e){const t=_(),{cursor:n,visibleItems:r,next:o,sequence:i,items:s,setCanvasIndex:a,setCanvasId:d,previous:f,setSequenceIndex:l}=it({startCanvas:e.startCanvas,disablePaging:e.pagingEnabled===!1}),g=u.useMemo(()=>({sequence:i,items:s,setCurrentCanvasId:d,nextCanvas:o,previousCanvas:f,totalCanvases:s.length,setCurrentCanvasIndex:a,setSequenceIndex:l,currentSequenceIndex:n}),[i,s,d,o,f,s,a,l,n]);return t?r.length===0?null:c.jsx(Z.Provider,{value:g,children:c.jsx(J.Provider,{value:r,children:c.jsx(se,{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 at(e){const t=et(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(st,{...e,children:e.children});return c.jsx(tt,{manifest:t.id,children:e.rangeId?c.jsx(nt,{range:e.rangeId,children:n}):n})}function ut(){return u.useContext(Z)}function ct(){return{VaultContext:u.useContext(Q),ResourceContext:u.useContext(ie),SimpleViewerReactContext:u.useContext(Z),VisibleCanvasReactContext:u.useContext(J)}}function lt(e){return c.jsx(ye,{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}})}},dt="@iiif/IMPORT_ENTITIES",ft="@iiif/MODIFY_ENTITY_FIELD",gt="@iiif/REORDER_ENTITY_FIELD",ht="@iiif/ADD_REFERENCE",mt="@iiif/UPDATE_REFERENCE",pt="@iiif/REMOVE_REFERENCE",vt="@iiif/ADD_METADATA",yt="@iiif/REMOVE_METADATA",xt="@iiif/UPDATE_METADATA",bt="@iiif/REORDER_METADATA",Ct=R(dt)(),St=R(ft)(),wt=R(gt)(),Mt=R(ht)(),jt=R(pt)(),Pt=R(mt)(),Et=R(vt)(),At=R(xt)(),It=R(yt)(),Tt=R(bt)(),ee={importEntities:Ct,modifyEntityField:St,reorderEntityField:wt,addReference:Mt,removeReference:jt,updateReference:Pt,addMetadata:Et,removeMetadata:It,updateMetadata:At,reorderMetadata:Tt};function Rt(){const t=A().getStore();return u.useMemo(()=>n=>t.dispatch(n),[t])}function he(e){return typeof e!="string"&&e&&e.bindToVault}function Vt(){const e=A(),t=u.useRef([]),n=Rt(),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 o=I(a=>r?a.iiif.entities.AnnotationPage[r]:null,[r]),i=u.useCallback((a,d)=>{if(r){if(he(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"}),l=e.get({id:a,type:"Annotation"});f&&l&&(f.items.find(g=>g.id===l.id)||n(ee.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"},index:d})))}},[r]),s=u.useCallback(a=>{r&&(he(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[o,{addAnnotation:i,removeAnnotation:s}]}const Ce=u.createContext(null);function kt(){const e=u.useContext(Ce);return[e.fullPage,{addAnnotation:e.addAnnotation,removeAnnotation:e.removeAnnotation}]}function Ot({children:e}){const[t,{addAnnotation:n,removeAnnotation:r}]=Vt();return c.jsx(Ce.Provider,{value:u.useMemo(()=>({fullPage:t,addAnnotation:n,removeAnnotation:r}),[t]),children:e})}function Lt({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 ae=u.createContext(null);function Ft(){return u.useContext(ae)}const Se=u.createContext(()=>{}),we=u.createContext(()=>{});function N(e,t,n,r,o=[]){const i=u.useContext(e==="portal"?we:Se);u.useEffect(()=>(e!=="none"&&i(t,n,r),()=>{i(t,null)}),[t,e,i,...o])}function O(e={},t=[]){const{id:n,selector:r}=e,o=D(),i=n||o.canvas,s=I(a=>i?a.iiif.entities.Canvas[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}const Me=u.createContext(()=>{});function Nt(e){const t=O(),n=u.useContext(Me);u.useEffect(()=>t&&t.id?(n(t.id,e),()=>n(t.id,-1)):()=>{},[t,e])}function Dt({children:e,errorFallback:t,outerContainerProps:n={},worldScale:r,...o}){const[i,s]=u.useState(),a=ct(),d=t||Lt,[f,l]=u.useState({}),g=Object.entries(f),[v,y]=u.useState({}),p=Object.entries(v),[m,b]=u.useState({}),x=u.useMemo(()=>r||Math.max(...Object.values(m)),[m]),j=u.useMemo(()=>({maxOverZoom:x||1,...o.runtimeOptions||{}}),[x,o.runtimeOptions]),S=u.useCallback((w,P)=>{b(T=>{if(P===-1){const{[w]:h,...V}=T;return V}return{...T,[w]:P}})},[]),U=u.useCallback((w,P,T)=>{l(({[w]:h,...V})=>P?{...V,[w]:{element:P,props:T}}:V)},[]),H=u.useCallback((w,P,T)=>{y(({[w]:h,...V})=>P?{...V,[w]:{element:P,props:T}}:V)},[]);return c.jsxs(Je,{resetKeys:[],fallbackRender:w=>c.jsx(d,{...o,...w}),children:[c.jsx(F.AtlasAuto,{...o,containerProps:{style:{position:"relative"},...o.containerProps||{}},htmlChildren:c.jsx(c.Fragment,{children:g.map(([w,{element:P,props:T}])=>c.jsx(u.Fragment,{children:c.jsx(P,{...T||{}})},w))}),onCreated:w=>{s(w),o.onCreated&&o.onCreated(w)},runtimeOptions:j,children:c.jsx(ae.Provider,{value:i,children:c.jsx(Me.Provider,{value:S,children:c.jsx(Se.Provider,{value:U,children:c.jsx(we.Provider,{value:H,children:c.jsx(lt,{bridge:a,children:c.jsx(F.ModeContext.Provider,{value:o.mode||"explore",children:c.jsx(Ot,{children:e})})})})})})})}),c.jsx("div",{children:p.map(([w,{element:P,props:T}])=>c.jsx(u.Fragment,{children:c.jsx(P,{...T||{}})},w))})]})}const Y={},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;Y[e]={...Y[e]||{},[t]:{...(Y[e]||{})[t]||{},[n]:s}}},getResourceMeta:(e,t)=>{const n=Y[e];if(n)return t?n[t]:n}};function _t(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 d=e.get(r);for(const{callback:f,scope:l}of o[s]||[])(!l||n&&l.indexOf(n)!==-1)&&f(a,d)};return i}}}function Pe(e,t){const n=A(),r=u.useMemo(()=>_t(n),[n]),o=I(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return u.useMemo(()=>e?r.getListenersAsProps(e,t):{},[o,e,n,t])}function W(e,t){const n=A(),r=u.useMemo(()=>pe.createStylesHelper(n),[n]);return I(()=>{if(!e)return null;const o=r.getAppliedStyles(e.id);return o?t?o[t]:o:void 0},[e,t])}function Ee(e={},t=[]){const{id:n,selector:r}=e,o=D(),i=A(),s=n||o.annotation,a=I(f=>s?f.iiif.entities.Annotation[s]:void 0,[s]),d=I(f=>a&&a.body?a.body.map(l=>l?l.type==="SpecificResource"?{...l,source:i.get(l)}:l?f.iiif.entities[l.type][l.id]:null:null).filter(Boolean):[],[a]);return u.useMemo(()=>{if(!a)return;const f={...a,body:d,target:ne.expandTarget(a.target,{typeMap:i.getState().iiif.mapping})};return r?r(f):f},[a,r,d,...t])}const Ae=({id:e,style:t,className:n,interactive:r})=>{const o=Ee({id:e}),i=W(o,"atlas"),s=W(o,"html"),a=Pe(o,["atlas"]),d=O(),f=u.useMemo(()=>F.mergeStyles(t,i),[t,i]);return d&&o&&o.target&&o.target.selector&&o.target.selector.type==="BoxSelector"&&o.target.source&&(o.target.source.id===d.id||o.target.source===d.id)?c.jsx(F.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 Ut(e={},t=[]){const{id:n,selector:r}=e,o=D(),i=n||o.annotationPage,s=I(a=>i?a.iiif.entities.AnnotationPage[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,...t])}const oe=({className:e,page:t})=>{var i;const n=Ut({id:t.id})||t,r=W(n,"atlas"),o=W(n,"html");return I(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(Ae,{id:s.id,style:r,className:(o==null?void 0:o.className)||e},s.id))})};function Ie({id:e,image:t,thumbnail:n,isStatic:r,x:o=0,y:i=0,children:s,selector:a,onClick:d,enableSizes:f}){var g,v;const l=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:d,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:(g=t.target)==null?void 0:g.spatial.width,height:(v=t.target)==null?void 0:v.spatial.height,crop:l}),s]},"service"):c.jsxs(u.Fragment,{children:[c.jsx("world-image",{onClick:d,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:l}),s]},"no-service")},e+(t.service?"server":"no-service"))}function Te(e,t){const{selector:n,source:r}=ze.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 qt={makeChoice:()=>{}},te={type:"unknown"},M=e=>({type:"unknown",reason:e,annotations:{pages:[]}}),$t=(e,t)=>({type:"empty",width:e,height:t,annotations:{pages:[]},image:null,images:[]});function Bt(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 Ht(e,t){return I(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=Bt(n,i);s&&s.views&&s.views[e]&&r.push(i)}return r},[e,t])}function Yt({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 zt(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 Kt(e,t={}){const n=A(),r=_(),o=O(),i=xe(),s=u.useMemo(()=>Yt({all:t.all,manifest:r,canvas:o,canvases:i}),[t.all,o,i,r]),a=Ht(e,t.all?void 0:s),d=u.useCallback(l=>{e&&n.setMetaValue([l,"annotationPageManager","views"],g=>g&&!g[e]?g:{...g||{},[e]:!1})},[e,n]),f=u.useCallback((l,g={})=>{if(!e)return;const v=n.getState(),y=[];if(g!=null&&g.deselectOthers){const p=Object.keys(v.iiif.entities.AnnotationPage);for(const m of p){const b=zt(v,m);b&&b.views&&b.views[e]&&y.push(m)}}for(const p of y)d(p);n.setMetaValue([l,"annotationPageManager","views"],p=>p&&p[e]?p:{...p||{},[e]:!0})},[e,d,n]);return{availablePageIds:s,enabledPageIds:a,setPageEnabled:f,setPageDisabled:d}}function Wt(e,t){return I((n,r)=>r.get(e.map(o=>({id:o,type:t}))),[e,t])}const Gt=u.createContext(new ve.ImageServiceLoader);function Re(){return u.useContext(Gt)}function Qt(){const e=Re(),[t,n]=u.useState({}),r=u.useRef(!1);return u.useEffect(()=>()=>{r.current=!0},[]),[u.useCallback((i,{height:s,width:a})=>{if(i){const d=i.id||i["@id"],f=e.loadServiceSync({id:d,width:i.width||a,height:i.height||s,source:i});f?i=f:t[d]||(r.current||n(l=>({...l,[d]:"loading"})),e.loadService({id:d,width:i.width||a,height:i.height||s}).then(()=>{r.current||n(l=>({...l,[d]:"done"}))}))}return i},[e,t]),t]}function Jt(e={}){const t=Ee(),n=O(e.canvasId?{id:e.canvasId}:void 0);return I((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 Zt(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}const z={},Ve={get(e){return e},setMetaValue([e,t,n],r){const o=Ve.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 Xt(e=Ve){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 d of s)a.push(...e.get(d.items,{parent:d}));return a}function n(o,i=[]){const s=Array.isArray(o)?o:t(o),a=[];let d=null;const f=[];for(const l of s){if(l.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const g=Array.from(Array.isArray(l.body)?l.body:[l.body]);for(const v of g){const[y,{selector:p}]=Zt(v),m=e.get(y),b=(m.type||"unknown").toLowerCase();if(b==="choice"){const x=e.get(m.items,{parent:m.id}),j=i.length?i.map(S=>x.find(U=>U.id===S)).filter(Boolean):[x[0]];j.length===0&&j.push(x[0]),d={type:"single-choice",items:x.map(S=>({id:S.id,label:S.label,selected:j.indexOf(S)!==-1})),label:y.label},g.push(...j);continue}a.indexOf(b)===-1&&a.push(b),f.push({type:b,annotationId:l.id,resource:m,target:l.target,selector:p})}}return{types:a,items:f,choice:d}}function r(o){const{choice:i}=n(o);return i}return{getAllPaintingAnnotations:t,getPaintables:n,extractChoices:r}}function en(e,t=[]){const n=A(),r=u.useMemo(()=>Xt(n),[]),o=Jt({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((l,{deselectOthers:g=!0,deselect:v=!1}={})=>{if(a.choice){if(a.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");s(y=>{if(v){const m=y.filter(b=>b!==l);if(m.length===0){const b=a.items[0].resource.id;return b?[b]:[]}return m}if(g)return[l];const p=[...y];if(p.length===0&&a.items.length){const m=a.items[0].resource.id;m&&p.push(m)}return y.indexOf(l)!==-1?y:[...y,l]})}},[a.choice])};return[a,f]}const tn=["model/gltf-binary"];function nn(e,t){const r=t.items[0].resource;return r.format?tn.indexOf(r.format)===-1?M(`3D format: ${r.format} is unsupported`):{type:"3d-model",model:r}:M("Unknown format")}function rn(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 on(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 M("No resource Identifier");let s;if(i.service){const y=ve.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)}},[d,f]=Te(e,o.target);if(f.id!==e.id)continue;o.resource.width&&o.resource.height&&(o.resource.width,o.resource.height);let l=o.resource.type==="SpecificResource"?ne.expandTarget(o.resource):null;if(o.selector){const y=ne.expandTarget({type:"SpecificResource",source:o.resource,selector:o.selector});y&&(l=y)}const g=l&&l.selector&&(l.selector.type==="BoxSelector"||l.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:l.selector.spatial.x,y:l.selector.spatial.y,width:l.selector.spatial.width,height:l.selector.spatial.height}}:void 0;s&&!s.id&&(s.id=s["@id"]);const v={id:i.id,type:"Image",annotationId:o.annotationId,width:Number(d||g?i.width:e.width),height:Number(d||g?i.height:e.height),service:s,sizes:s&&s.sizes?s.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:d&&d.type!=="PointSelector"?d:a,selector:g};r.push(v)}return{type:"images",image:r[0],images:r,choice:t.choice}}function ke(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=>ke(o,t,r))}return t}function sn(e,t){const n=[];return t.items.forEach(r=>{if(r.resource){const[o]=Te(e,r.target);n.push({annotationId:r.annotationId,text:ke(r.resource),target:o})}}),{type:"textual-content",items:n}}const an=/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?vi?=|&vi?=))([^#&?]*).*/;function un(e,t){var s;const n=t.items.filter(a=>a.type==="video");if(!e.duration)return M("No duration on canvas");if(n.length>1)return M("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 M("Unknown video");if((!r.format||r.format==="text/html")&&!o)return M("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(an);if(!a[1])return M("Video is not known youtube video");i.youTubeId=a[1]}return{type:"media",media:i,annotations:{pages:[]}}}function cn({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?$t(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(i=>i!=="text");else return n.indexOf("complex-timeline")===-1?M("Complex timeline not supported"):M("ComplexTimelineStrategy not yet supported");const o=t.types[0];return o==="image"?n.indexOf("images")===-1?M("Image not supported"):on(e,t,r):o==="Model"||o==="model"?n.indexOf("3d-model")===-1?M("3D not supported"):nn(e,t):o==="textualbody"?n.indexOf("textual-content")===-1?M("Textual content not supported"):sn(e,t):o==="sound"||o==="audio"?n.indexOf("media")===-1?M("Media not supported"):rn(e,t):o==="video"?n.indexOf("media")===-1?M("Media not supported"):un(e,t):te}function ln(e){const t=_(),n=O(),r=A(),[o,i]=Qt(),{enabledPageIds:s}=Kt((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(n==null?void 0:n.id),{all:!1}),a=Wt(s,"AnnotationPage"),d=(e==null?void 0:e.strategies)||["empty","images","media","textual-content","complex-timeline"],[f,l]=en(e,[i]),g=u.useMemo(()=>cn({canvas:n,paintables:f,supports:d,loadImageService:o}),[n,f,r,l.makeChoice]);return u.useMemo(()=>g.type==="unknown"?[g,qt]:[{...g,annotations:{pages:a}},l],[g,a])}const dn=(e,t=[])=>{const n=A();u.useEffect(()=>{e(n)},[n,...t])};function fn(e,t,{canvasId:n,manifestId:r}={}){const o=A(),i=Re(),s=u.useMemo(()=>Ke.createThumbnailHelper(o,{imageServiceLoader:i}),[o,i]),[a,d]=u.useState(),f=_(r?{id:r}:void 0),l=O(n?{id:n}:void 0),g=l||f,v=u.useRef(!1);if(u.useEffect(()=>(v.current=!1,()=>{v.current=!0}),[]),!g)throw new Error("Must be called under a manifest or canvas context.");return dn(y=>{s.getBestThumbnailAtSize(g,e,t).then(p=>{p.best&&!v.current&&d(p.best)})},[g]),a}function gn(e){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:e}}function hn(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 mn(e){const t=Math.round(e);return`${Math.floor(t/60)}:${`${t%60}`.padStart(2,"0")}`}function ue(e){const[t,n]=u.useReducer(hn,gn(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=mn(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]),d=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?d():l())},[a]),l=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"}))},[]),v=u.useCallback(()=>{r.current&&(r.current.muted=!0,n({type:"MUTE"}))},[]),y=u.useCallback(()=>{r.current&&(r.current.muted=!1,n({type:"UNMUTE"}))},[]),p=u.useCallback(x=>{r.current&&(r.current.muted=!1,r.current.volume=x/100,n({type:"SET_VOLUME",volume:x}))},[]),m=u.useCallback(x=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(x*e.duration,e.duration)),a())},[]),b=u.useCallback(x=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(x,e.duration)),a())},[]);return u.useEffect(()=>{const x=setInterval(()=>{a()},350);return()=>clearInterval(x)},[a,e.duration]),u.useEffect(()=>{const x=()=>{n({type:"FINISHED"})},j=r.current;return j==null||j.addEventListener("ended",x),()=>j==null?void 0:j.removeEventListener("ended",x)},[]),[{element:r,currentTime:o,progress:i},t,{play:d,pause:l,playPause:f,mute:v,unmute:y,toggleMute:g,setVolume:p,setDurationPercent:m,setTime:b}]}const pn=u.createContext(null),vn=u.createContext(null),yn=u.createContext(null);function Oe({actions:e,state:t,children:n,currentTime:r,progress:o,element:i}){return c.jsx(yn.Provider,{value:{currentTime:r,progress:o,element:i},children:c.jsx(vn.Provider,{value:e,children:c.jsx(pn.Provider,{value:t,children:n})})})}function Le({media:e,children:t}){const[{element:n,currentTime:r,progress:o},i,s]=ue({duration:e.duration});return c.jsxs(Oe,{state:i,actions:s,currentTime:r,progress:o,element:n,children:[c.jsx("audio",{ref:n,src:e.url}),t]})}function Fe({media:e,mediaControlsDeps:t,children:n}){return N("portal","audio",Le,{media:e,children:n},[e,...t||[]]),null}function Ne({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"),pe=require("@iiif/helpers/styles"),ne=require("@iiif/helpers/annotation-targets"),ze=require("@iiif/helpers"),ve=require("@atlas-viewer/iiif-image-api"),Ke=require("@iiif/helpers/thumbnail");function We(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 X=We(u);function re(e,t){return re=Object.setPrototypeOf||function(r,o){return r.__proto__=o,r},re(e,t)}function Ge(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,re(e,t)}var Qe=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])})},ge={error:null},Je=function(e){Ge(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=ge,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(ge)},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&&Qe(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(X.isValidElement(l))return l;if(typeof s=="function")return s(f);if(a)return X.createElement(a,f);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},t}(X.Component);const Ze={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},ie=u.createContext(Ze),D=()=>u.useContext(ie);function G({value:e,children:t}){const n=D(),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 ye({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:o}){const[i,s]=u.useState(()=>e||(n?K.globalVault(t):t?new K.Vault(t):new K.Vault));return c.jsx(Q.Provider,{value:{vault:i,setVaultInstance:s},children:c.jsx(G,{value:r||{},children:o})})}const A=()=>{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 Xe(e,{noCache:t=!1}={}){const n=typeof e=="string"?e:e.id,r=A(),[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),v=g?g.id||g["@id"]:null;g&&o!==v&&i(v),d(g)}catch(g){a(g)}})()},[n,t]),{isLoaded:!!f,id:o,requestId:n,error:s,resource:f,cached:!!(f&&f===l)}}function et(e,t){const{id:n,isLoaded:r,error:o,resource:i,requestId:s,cached:a}=Xe(e,t);return{id:n,isLoaded:r,error:o,manifest:i,requestId:s,cached:a}}function tt({manifest:e,children:t}){return c.jsx(G,{value:{manifest:e},children:t})}function se({canvas:e,children:t}){return c.jsx(G,{value:{canvas:e},children:t})}function I(e,t=[]){const n=A(),[r,o]=u.useState(()=>e(n.getState(),n));return u.useEffect(()=>n.subscribe(i=>e(i,n),i=>{o(i)},!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 _(e={},t=[]){const{id:n,selector:r}=e,o=D();A();const i=n||o.manifest,s=I(a=>i?a.iiif.entities.Manifest[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}function nt({range:e,children:t}){return c.jsx(G,{value:{range:e},children:t})}function be(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(...be(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 rt(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:be(e,t);if(s)return[l,[l.map((p,m)=>m)]];if(a||!i||n)return[l,l.map((p,m)=>[m])];const f=[];let d=[];const g=()=>{d.length&&(f.push([...d]),d=[])};let v=0,y=!1;for(let p=0;p<l.length;p++){const m=e.get(l[p]);if(m.behavior.includes("non-paged")){p===v&&v++,r||(g(),f.push([p]),g());continue}if(p===v||m.behavior.includes("facing-pages")){d.length&&(y=!0),g(),f.push([p]),g();continue}if(d.push(p),y){g(),y=!1;continue}d.length>1&&g()}return d.length&&g(),[l,f]}function ot(e={},t=[]){const{id:n,selector:r}=e,o=D(),i=n||o.range,s=I(a=>i?a.iiif.entities.Range[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}function it({startCanvas:e,disablePaging:t}){var p;const n=A(),r=_(),o=ot(),[i,s]=u.useState(void 0),a=o||r;if(!a)throw new Error("Nothing selected");const[l,f]=u.useMemo(()=>rt(n,a,{disablePaging:t}),[n,a]),d=u.useCallback(m=>{const b=f.findIndex(x=>x.includes(m));s(b===-1?0:b)},[l,f]),g=u.useCallback(m=>{const b=l.findIndex(x=>x.id===m);b!==-1?d(b):s(0)},[l,f]),v=u.useCallback(()=>{s(m=>m>=f.length?m:m+1)},[f]),y=u.useCallback(()=>{s(m=>m<=0?0:m-1)},[f]);return typeof i>"u"&&(e?g(e):s(0)),{visibleItems:((p=f[i])==null?void 0:p.map(m=>l[m].id))||[],cursor:i,items:l,sequence:f,setSequenceIndex:s,setCanvasIndex:d,setCanvasId:g,next:v,previous:y}}const B=()=>{},Z=u.createContext({setCurrentCanvasId:B,setCurrentCanvasIndex:B,nextCanvas:B,previousCanvas:B,items:[],sequence:[],setSequenceIndex:B,currentSequenceIndex:0});function st(e){const t=_(),{cursor:n,visibleItems:r,next:o,sequence:i,items:s,setCanvasIndex:a,setCanvasId:l,previous:f,setSequenceIndex:d}=it({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(Z.Provider,{value:g,children:c.jsx(J.Provider,{value:r,children:c.jsx(se,{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 at(e){const t=et(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(st,{...e,children:e.children});return c.jsx(tt,{manifest:t.id,children:e.rangeId?c.jsx(nt,{range:e.rangeId,children:n}):n})}function ut(){return u.useContext(Z)}function ct(){return{VaultContext:u.useContext(Q),ResourceContext:u.useContext(ie),SimpleViewerReactContext:u.useContext(Z),VisibleCanvasReactContext:u.useContext(J)}}function lt(e){return c.jsx(ye,{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}})}},dt="@iiif/IMPORT_ENTITIES",ft="@iiif/MODIFY_ENTITY_FIELD",gt="@iiif/REORDER_ENTITY_FIELD",ht="@iiif/ADD_REFERENCE",mt="@iiif/UPDATE_REFERENCE",pt="@iiif/REMOVE_REFERENCE",vt="@iiif/ADD_METADATA",yt="@iiif/REMOVE_METADATA",xt="@iiif/UPDATE_METADATA",bt="@iiif/REORDER_METADATA",Ct=R(dt)(),St=R(ft)(),wt=R(gt)(),Mt=R(ht)(),jt=R(pt)(),Pt=R(mt)(),Et=R(vt)(),At=R(xt)(),It=R(yt)(),Tt=R(bt)(),ee={importEntities:Ct,modifyEntityField:St,reorderEntityField:wt,addReference:Mt,removeReference:jt,updateReference:Pt,addMetadata:Et,removeMetadata:It,updateMetadata:At,reorderMetadata:Tt};function Rt(){const t=A().getStore();return u.useMemo(()=>n=>t.dispatch(n),[t])}function he(e){return typeof e!="string"&&e&&e.bindToVault}function Vt(){const e=A(),t=u.useRef([]),n=Rt(),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 o=I(a=>r?a.iiif.entities.AnnotationPage[r]:null,[r]),i=u.useCallback((a,l)=>{if(r){if(he(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(ee.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"},index:l})))}},[r]),s=u.useCallback(a=>{r&&(he(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[o,{addAnnotation:i,removeAnnotation:s}]}const Ce=u.createContext(null);function kt(){const e=u.useContext(Ce);return[e.fullPage,{addAnnotation:e.addAnnotation,removeAnnotation:e.removeAnnotation}]}function Ot({children:e}){const[t,{addAnnotation:n,removeAnnotation:r}]=Vt();return c.jsx(Ce.Provider,{value:u.useMemo(()=>({fullPage:t,addAnnotation:n,removeAnnotation:r}),[t]),children:e})}function Lt({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 ae=u.createContext(null);function Ft(){return u.useContext(ae)}const Se=u.createContext(()=>{}),we=u.createContext(()=>{});function N(e,t,n,r,o=[]){const i=u.useContext(e==="portal"?we:Se);u.useEffect(()=>(e!=="none"&&i(t,n,r),()=>{i(t,null)}),[t,e,i,...o])}function O(e={},t=[]){const{id:n,selector:r}=e,o=D(),i=n||o.canvas,s=I(a=>i?a.iiif.entities.Canvas[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}const Me=u.createContext(()=>{});function Nt(e){const t=O(),n=u.useContext(Me);u.useEffect(()=>t&&t.id?(n(t.id,e),()=>n(t.id,-1)):()=>{},[t,e])}function Dt({children:e,errorFallback:t,outerContainerProps:n={},worldScale:r,...o}){const[i,s]=u.useState(),a=ct(),l=t||Lt,[f,d]=u.useState({}),g=Object.entries(f),[v,y]=u.useState({}),p=Object.entries(v),[m,b]=u.useState({}),x=u.useMemo(()=>r||Math.max(...Object.values(m)),[m]),j=u.useMemo(()=>({maxOverZoom:x||1,...o.runtimeOptions||{}}),[x,o.runtimeOptions]),S=u.useCallback((w,P)=>{b(T=>{if(P===-1){const{[w]:h,...V}=T;return V}return{...T,[w]:P}})},[]),U=u.useCallback((w,P,T)=>{d(({[w]:h,...V})=>P?{...V,[w]:{element:P,props:T}}:V)},[]),H=u.useCallback((w,P,T)=>{y(({[w]:h,...V})=>P?{...V,[w]:{element:P,props:T}}:V)},[]);return c.jsxs(Je,{resetKeys:[],fallbackRender:w=>c.jsx(l,{...o,...w}),children:[c.jsx(F.AtlasAuto,{...o,containerProps:{style:{position:"relative"},...o.containerProps||{}},htmlChildren:c.jsx(c.Fragment,{children:g.map(([w,{element:P,props:T}])=>c.jsx(u.Fragment,{children:c.jsx(P,{...T||{}})},w))}),onCreated:w=>{s(w),o.onCreated&&o.onCreated(w)},runtimeOptions:j,children:c.jsx(ae.Provider,{value:i,children:c.jsx(Me.Provider,{value:S,children:c.jsx(Se.Provider,{value:U,children:c.jsx(we.Provider,{value:H,children:c.jsx(lt,{bridge:a,children:c.jsx(F.ModeContext.Provider,{value:o.mode||"explore",children:c.jsx(Ot,{children:e})})})})})})})}),c.jsx("div",{children:p.map(([w,{element:P,props:T}])=>c.jsx(u.Fragment,{children:c.jsx(P,{...T||{}})},w))})]})}const Y={},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;Y[e]={...Y[e]||{},[t]:{...(Y[e]||{})[t]||{},[n]:s}}},getResourceMeta:(e,t)=>{const n=Y[e];if(n)return t?n[t]:n}};function _t(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 Pe(e,t){const n=A(),r=u.useMemo(()=>_t(n),[n]),o=I(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return u.useMemo(()=>e?r.getListenersAsProps(e,t):{},[o,e,n,t])}function W(e,t){const n=A(),r=u.useMemo(()=>pe.createStylesHelper(n),[n]);return I(()=>{if(!e)return null;const o=r.getAppliedStyles(e.id);return o?t?o[t]:o:void 0},[e,t])}function Ee(e={},t=[]){const{id:n,selector:r}=e,o=D(),i=A(),s=n||o.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: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:ne.expandTarget(a.target,{typeMap:i.getState().iiif.mapping})};return r?r(f):f},[a,r,l,...t])}const Ae=({id:e,style:t,className:n,interactive:r})=>{const o=Ee({id:e}),i=W(o,"atlas"),s=W(o,"html"),a=Pe(o,["atlas"]),l=O(),f=u.useMemo(()=>F.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(F.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 Ut(e={},t=[]){const{id:n,selector:r}=e,o=D(),i=n||o.annotationPage,s=I(a=>i?a.iiif.entities.AnnotationPage[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,...t])}const oe=({className:e,page:t})=>{var i;const n=Ut({id:t.id})||t,r=W(n,"atlas"),o=W(n,"html");return I(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(Ae,{id:s.id,style:r,className:(o==null?void 0:o.className)||e},s.id))})};function Ie({id:e,image:t,thumbnail:n,isStatic:r,x:o=0,y:i=0,children:s,selector:a,onClick:l,enableSizes:f}){var g,v;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(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:(g=t.target)==null?void 0:g.spatial.width,height:(v=t.target)==null?void 0:v.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}=ze.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 qt={makeChoice:()=>{}},te={type:"unknown"},M=e=>({type:"unknown",reason:e,annotations:{pages:[]}}),$t=(e,t)=>({type:"empty",width:e,height:t,annotations:{pages:[]},image:null,images:[]});function Bt(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 Ht(e,t){return I(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=Bt(n,i);s&&s.views&&s.views[e]&&r.push(i)}return r},[e,t])}function Yt({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 zt(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 Kt(e,t={}){const n=A(),r=_(),o=O(),i=xe(),s=u.useMemo(()=>Yt({all:t.all,manifest:r,canvas:o,canvases:i}),[t.all,o,i,r]),a=Ht(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 v=n.getState(),y=[];if(g!=null&&g.deselectOthers){const p=Object.keys(v.iiif.entities.AnnotationPage);for(const m of p){const b=zt(v,m);b&&b.views&&b.views[e]&&y.push(m)}}for(const p of y)l(p);n.setMetaValue([d,"annotationPageManager","views"],p=>p&&p[e]?p:{...p||{},[e]:!0})},[e,l,n]);return{availablePageIds:s,enabledPageIds:a,setPageEnabled:f,setPageDisabled:l}}function Wt(e,t){return I((n,r)=>r.get(e.map(o=>({id:o,type:t}))),[e,t])}const Gt=u.createContext(new ve.ImageServiceLoader);function Re(){return u.useContext(Gt)}function Qt(){const e=Re(),[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 Jt(e={}){const t=Ee(),n=O(e.canvasId?{id:e.canvasId}:void 0);return I((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 Zt(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}const z={},Ve={get(e){return e},setMetaValue([e,t,n],r){const o=Ve.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 Xt(e=Ve){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 v of g){const[y,{selector:p}]=Zt(v),m=e.get(y),b=(m.type||"unknown").toLowerCase();if(b==="choice"){const x=e.get(m.items,{parent:m.id}),j=i.length?i.map(S=>x.find(U=>U.id===S)).filter(Boolean):[x[0]];j.length===0&&j.push(x[0]),l={type:"single-choice",items:x.map(S=>({id:S.id,label:S.label,selected:j.indexOf(S)!==-1})),label:y.label},g.push(...j);continue}a.indexOf(b)===-1&&a.push(b),f.push({type:b,annotationId:d.id,resource:m,target:d.target,selector:p})}}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 en(e,t=[]){const n=A(),r=u.useMemo(()=>Xt(n),[]),o=Jt({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:v=!1}={})=>{if(a.choice){if(a.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");s(y=>{if(v){const m=y.filter(b=>b!==d);if(m.length===0){const b=a.items[0].resource.id;return b?[b]:[]}return m}if(g)return[d];const p=[...y];if(p.length===0&&a.items.length){const m=a.items[0].resource.id;m&&p.push(m)}return y.indexOf(d)!==-1?y:[...y,d]})}},[a.choice])};return[a,f]}const tn=["model/gltf-binary"];function nn(e,t){const r=t.items[0].resource;return r.format?tn.indexOf(r.format)===-1?M(`3D format: ${r.format} is unsupported`):{type:"3d-model",model:r}:M("Unknown format")}function rn(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 on(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 M("No resource Identifier");let s;if(i.service){const y=ve.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]=Te(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"?ne.expandTarget(o.resource):null;if(o.selector){const y=ne.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 v={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(v)}return{type:"images",image:r[0],images:r,choice:t.choice}}function ke(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=>ke(o,t,r))}return t}function sn(e,t){const n=[];return t.items.forEach(r=>{if(r.resource){const[o]=Te(e,r.target);n.push({annotationId:r.annotationId,text:ke(r.resource),target:o})}}),{type:"textual-content",items:n}}const an=/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?vi?=|&vi?=))([^#&?]*).*/;function un(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 o=(a=n[0])==null?void 0:a.resource,i=!!(o.service||[]).find(l=>(l.profile||"").includes("youtube.com"));if(!i&&r)return M("Video does not have duration");if(!o)return M("Unknown video");if((!o.format||o.format==="text/html")&&!i)return M("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(an);if(!l[1])return M("Video is not known youtube video");s.youTubeId=l[1]}return{type:"media",media:s,annotations:{pages:[]}}}function cn({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?$t(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(i=>i!=="text");else return n.indexOf("complex-timeline")===-1?M("Complex timeline not supported"):M("ComplexTimelineStrategy not yet supported");const o=t.types[0];return o==="image"?n.indexOf("images")===-1?M("Image not supported"):on(e,t,r):o==="Model"||o==="model"?n.indexOf("3d-model")===-1?M("3D not supported"):nn(e,t):o==="textualbody"?n.indexOf("textual-content")===-1?M("Textual content not supported"):sn(e,t):o==="sound"||o==="audio"?n.indexOf("media")===-1?M("Media not supported"):rn(e,t):o==="video"?n.indexOf("media")===-1?M("Media not supported"):un(e,t):te}function ln(e){const t=_(),n=O(),r=A(),[o,i]=Qt(),{enabledPageIds:s}=Kt((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(n==null?void 0:n.id),{all:!1}),a=Wt(s,"AnnotationPage"),l=(e==null?void 0:e.strategies)||["empty","images","media","textual-content","complex-timeline"],[f,d]=en(e,[i]),g=u.useMemo(()=>cn({canvas:n,paintables:f,supports:l,loadImageService:o}),[n,f,r,d.makeChoice]);return u.useMemo(()=>g.type==="unknown"?[g,qt]:[{...g,annotations:{pages:a}},d],[g,a])}const dn=(e,t=[])=>{const n=A();u.useEffect(()=>{e(n)},[n,...t])};function fn(e,t,{canvasId:n,manifestId:r}={}){const o=A(),i=Re(),s=u.useMemo(()=>Ke.createThumbnailHelper(o,{imageServiceLoader:i}),[o,i]),[a,l]=u.useState(),f=_(r?{id:r}:void 0),d=O(n?{id:n}:void 0),g=d||f,v=u.useRef(!1);if(u.useEffect(()=>(v.current=!1,()=>{v.current=!0}),[]),!g)throw new Error("Must be called under a manifest or canvas context.");return dn(y=>{s.getBestThumbnailAtSize(g,e,t).then(p=>{p.best&&!v.current&&l(p.best)})},[g]),a}function gn(e){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:e}}function hn(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 mn(e){const t=Math.round(e);return`${Math.floor(t/60)}:${`${t%60}`.padStart(2,"0")}`}function ue(e){const[t,n]=u.useReducer(hn,gn(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=mn(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"}))},[]),v=u.useCallback(()=>{r.current&&(r.current.muted=!0,n({type:"MUTE"}))},[]),y=u.useCallback(()=>{r.current&&(r.current.muted=!1,n({type:"UNMUTE"}))},[]),p=u.useCallback(x=>{r.current&&(r.current.muted=!1,r.current.volume=x/100,n({type:"SET_VOLUME",volume:x}))},[]),m=u.useCallback(x=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(x*e.duration,e.duration)),a())},[]),b=u.useCallback(x=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(x,e.duration)),a())},[]);return u.useEffect(()=>{const x=setInterval(()=>{a()},350);return()=>clearInterval(x)},[a,e.duration]),u.useEffect(()=>{const x=()=>{n({type:"FINISHED"})},j=r.current;return j==null||j.addEventListener("ended",x),()=>j==null?void 0:j.removeEventListener("ended",x)},[]),[{element:r,currentTime:o,progress:i},t,{play:l,pause:d,playPause:f,mute:v,unmute:y,toggleMute:g,setVolume:p,setDurationPercent:m,setTime:b}]}const pn=u.createContext(null),vn=u.createContext(null),yn=u.createContext(null);function Oe({actions:e,state:t,children:n,currentTime:r,progress:o,element:i}){return c.jsx(yn.Provider,{value:{currentTime:r,progress:o,element:i},children:c.jsx(vn.Provider,{value:e,children:c.jsx(pn.Provider,{value:t,children:n})})})}function Le({media:e,children:t}){const[{element:n,currentTime:r,progress:o},i,s]=ue({duration:e.duration});return c.jsxs(Oe,{state:i,actions:s,currentTime:r,progress:o,element:n,children:[c.jsx("audio",{ref:n,src:e.url}),t]})}function Fe({media:e,mediaControlsDeps:t,children:n}){return N("portal","audio",Le,{media:e,children:n},[e,...t||[]]),null}function Ne({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;
@@ -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 Pn({media:e,mediaControlsDeps:t,children:n}){const[{element:r,currentTime:o,progress:i},s,a]=ue({duration:e.duration});return N("overlay","video-element",jn,{element:r,media:e,playPause:a.playPause}),null}function Be({x:e,y:t,onChoiceChange:n,registerActions:r,defaultChoices:o,isStatic:i,renderViewerControls:s,renderMediaControls:a,viewControlsDeps:d,mediaControlsDeps:f,strategies:l,throwOnUnknown:g,backgroundStyle:v,alwaysShowBackground:y,keepCanvasScale:p=!1,enableSizes:m=!1,enableYouTube:b=!0,onClickPaintingAnnotation:x,children:j}){const S=O(),U=Pe(S,["deep-zoom"]),[H]=kt(),w=Ft(),P=A(),T=u.useMemo(()=>pe.createStylesHelper(P),[P]),[h,V]=ln({strategies:l||["images"],defaultChoices:o==null?void 0:o.map(({id:C})=>C)}),ce=h.type==="images"?h.choice:void 0,He=u.useMemo(()=>p?1:Math.max(1,...h.type==="images"?h.images.map(C=>{var L;return(C.width||0)/((L=C.target)==null?void 0:L.spatial.width)}):[]),[p,h]);Nt(He),u.useEffect(()=>{r&&r(V)},[h.annotations]),u.useEffect(()=>{if(o)for(const C of o)typeof C.opacity<"u"&&T.applyStyles({id:C.id},"atlas",{opacity:C.opacity})},[o]),u.useLayoutEffect(()=>{n&&n(ce)},[ce]),N(w&&(h.type==="images"||h.type==="empty"||h.type==="textual-content"&&s)?"overlay":"none",`canvas-portal-controls-${S==null?void 0:S.id}`,ae.Provider,s?{value:w||null,children:s(h)}:{},[S,w,h,...d||[]]);const k=fn({maxWidth:256,maxHeight:256});if(!S)return null;const le=S.accompanyingCanvas,q=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(h.type==="unknown"){if(q)return q;if(g)throw new Error(h.reason||"Unknown image strategy");return null}const de=c.jsxs(u.Fragment,{children:[H?c.jsx(oe,{page:H}):null,h.annotations&&h.annotations.pages?h.annotations.pages.map(C=>c.jsx(oe,{page:C},C.id)):null,j]}),Ye=h.type==="images"?h.images.length:0;return c.jsxs(c.Fragment,{children:[c.jsxs("world-object",{height:S.height,width:S.width,x:e,y:t,...U,children:[h.type==="empty"||y?c.jsx(qe,{style:v}):null,h.type==="textual-content"?h.items.map((C,L)=>{var $;return c.jsxs(c.Fragment,{children:[c.jsx(F.HTMLPortal,{onClick:x?fe=>{fe.stopPropagation(),x(C.annotationId,C,fe)}:void 0,target:(($=C.target)==null?void 0:$.spatial)||void 0,children:c.jsx("div",{"data-textual-content":!0,children:c.jsx(Mn,{enableDangerouslySetInnerHTML:!0,children:C.text})})},L),de]})}):null,h.type==="images"?c.jsxs(c.Fragment,{children:[h.images.map((C,L)=>c.jsx(Ie,{isStatic:i,image:C,id:C.id,thumbnail:L===0?k:void 0,selector:C.selector,enableSizes:m,onClick:x?$=>{$.stopPropagation(),x(C.annotationId,C,$)}:void 0},C.id+L)),de]}):null,h.type==="3d-model"?c.jsx(Ue,{model:h.model}):null,h.type==="media"?c.jsx(c.Fragment,{children:h.media.type==="Sound"?c.jsxs(Fe,{media:h.media,mediaControlsDeps:f,children:[q,a?a(h):null]}):h.media.type==="Video"?c.jsxs(De,{media:h.media,mediaControlsDeps:f,children:[q,a?a(h):null]}):h.media.type==="VideoYouTube"&&b?c.jsxs(Pn,{media:h.media,mediaControlsDeps:f,children:[q,a?a(h):null]}):null}):null]},`${S.id}/${h.type}/${Ye}`),h.type==="media"&&h.media.type==="Sound"&&le?c.jsx(se,{canvas:le.id,children:c.jsx(Be,{renderViewerControls:s})}):null]})}function En(){const e=u.useContext(Q);return e&&e.vault?e.vault:K.globalVault()}const An=u.forwardRef(function(t,n){const r=_(),o=xe(),i=ut(),{ViewerControls:s,MediaControls:a}=t.components||{};if(u.useImperativeHandle(n,()=>i,[i]),!r)return c.jsx("div",{});let d=0;return c.jsxs(c.Fragment,{children:[t.header,c.jsx(E.Viewer,{height:t.height,mode:t.mode,children:o.map((f,l)=>{const g=d;return d+=f.width+(t.spacing||0),c.jsx(se,{canvas:f.id,children:c.jsx(E.RenderCanvas,{strategies:["3d-model","media","images","empty","textual-content"],renderViewerControls:l===0&&s?()=>c.jsx(s,{}):void 0,renderMediaControls:l===0&&a?()=>c.jsx(a,{}):void 0,x:g,...t.canvasProps||{},children:t.annotations},f.id)},f.id)})},t.reuseAtlas?"":i.currentSequenceIndex),t.children]})}),E=u.forwardRef(function({children:t,height:n,annotations:r,canvasProps:o,spacing:i,header:s,components:a,mode:d,...f},l){const g=En();return c.jsx(ye,{vault:g,children:c.jsx(at,{...f,children:c.jsx(An,{ref:l,height:n,components:a,spacing:i,canvasProps:o,annotations:r,header:s,mode:d,children:t})})})});E.RenderImage=Ie;E.RenderCanvas=Be;E.RenderAnnotationPage=oe;E.RenderAnnotation=Ae;E.Viewer=Dt;E.CanvasBackground=qe;E.Audio=Fe;E.Video=De;E.Model=Ue;E.AudioHTML=Le;E.VideoHTML=Ne;E.ModelHTML=_e;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 Pn({media:e,mediaControlsDeps:t,children:n}){const[{element:r,currentTime:o,progress:i},s,a]=ue({duration:e.duration});return N("overlay","video-element",jn,{element:r,media:e,playPause:a.playPause}),null}function Be({x:e,y:t,onChoiceChange:n,registerActions:r,defaultChoices:o,isStatic:i,renderViewerControls:s,renderMediaControls:a,viewControlsDeps:l,mediaControlsDeps:f,strategies:d,throwOnUnknown:g,backgroundStyle:v,alwaysShowBackground:y,keepCanvasScale:p=!1,enableSizes:m=!1,enableYouTube:b=!0,onClickPaintingAnnotation:x,children:j}){const S=O(),U=Pe(S,["deep-zoom"]),[H]=kt(),w=Ft(),P=A(),T=u.useMemo(()=>pe.createStylesHelper(P),[P]),[h,V]=ln({strategies:d||["images"],defaultChoices:o==null?void 0:o.map(({id:C})=>C)}),ce=h.type==="images"?h.choice:void 0,He=u.useMemo(()=>p?1:Math.max(1,...h.type==="images"?h.images.map(C=>{var L;return(C.width||0)/((L=C.target)==null?void 0:L.spatial.width)}):[]),[p,h]);Nt(He),u.useEffect(()=>{r&&r(V)},[h.annotations]),u.useEffect(()=>{if(o)for(const C of o)typeof C.opacity<"u"&&T.applyStyles({id:C.id},"atlas",{opacity:C.opacity})},[o]),u.useLayoutEffect(()=>{n&&n(ce)},[ce]),N(w&&(h.type==="images"||h.type==="empty"||h.type==="textual-content"&&s)?"overlay":"none",`canvas-portal-controls-${S==null?void 0:S.id}`,ae.Provider,s?{value:w||null,children:s(h)}:{},[S,w,h,...l||[]]);const k=fn({maxWidth:256,maxHeight:256});if(!S)return null;const le=S.accompanyingCanvas,q=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(h.type==="unknown"){if(q)return q;if(g)throw new Error(h.reason||"Unknown image strategy");return null}const de=c.jsxs(u.Fragment,{children:[H?c.jsx(oe,{page:H}):null,h.annotations&&h.annotations.pages?h.annotations.pages.map(C=>c.jsx(oe,{page:C},C.id)):null,j]}),Ye=h.type==="images"?h.images.length:0;return c.jsxs(c.Fragment,{children:[c.jsxs("world-object",{height:S.height,width:S.width,x:e,y:t,...U,children:[h.type==="empty"||y?c.jsx(qe,{style:v}):null,h.type==="textual-content"?h.items.map((C,L)=>{var $;return c.jsxs(c.Fragment,{children:[c.jsx(F.HTMLPortal,{onClick:x?fe=>{fe.stopPropagation(),x(C.annotationId,C,fe)}:void 0,target:(($=C.target)==null?void 0:$.spatial)||void 0,children:c.jsx("div",{"data-textual-content":!0,children:c.jsx(Mn,{enableDangerouslySetInnerHTML:!0,children:C.text})})},L),de]})}):null,h.type==="images"?c.jsxs(c.Fragment,{children:[h.images.map((C,L)=>c.jsx(Ie,{isStatic:i,image:C,id:C.id,thumbnail:L===0?k:void 0,selector:C.selector,enableSizes:m,onClick:x?$=>{$.stopPropagation(),x(C.annotationId,C,$)}:void 0},C.id+L)),de]}):null,h.type==="3d-model"?c.jsx(Ue,{model:h.model}):null,h.type==="media"?c.jsx(c.Fragment,{children:h.media.type==="Sound"?c.jsxs(Fe,{media:h.media,mediaControlsDeps:f,children:[q,a?a(h):null]}):h.media.type==="Video"?c.jsxs(De,{media:h.media,mediaControlsDeps:f,children:[q,a?a(h):null]}):h.media.type==="VideoYouTube"&&b?c.jsxs(Pn,{media:h.media,mediaControlsDeps:f,children:[q,a?a(h):null]}):null}):null]},`${S.id}/${h.type}/${Ye}`),h.type==="media"&&h.media.type==="Sound"&&le?c.jsx(se,{canvas:le.id,children:c.jsx(Be,{renderViewerControls:s})}):null]})}function En(){const e=u.useContext(Q);return e&&e.vault?e.vault:K.globalVault()}const An=u.forwardRef(function(t,n){const r=_(),o=xe(),i=ut(),{ViewerControls:s,MediaControls:a}=t.components||{};if(u.useImperativeHandle(n,()=>i,[i]),!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:o.map((f,d)=>{const g=l;return l+=f.width+(t.spacing||0),c.jsx(se,{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:g,...t.canvasProps||{},children:t.annotations},f.id)},f.id)})},t.reuseAtlas?"":i.currentSequenceIndex),t.children]})}),E=u.forwardRef(function({children:t,height:n,annotations:r,canvasProps:o,spacing:i,header:s,components:a,mode:l,...f},d){const g=En();return c.jsx(ye,{vault:g,children:c.jsx(at,{...f,children:c.jsx(An,{ref:d,height:n,components:a,spacing:i,canvasProps:o,annotations:r,header:s,mode:l,children:t})})})});E.RenderImage=Ie;E.RenderCanvas=Be;E.RenderAnnotationPage=oe;E.RenderAnnotation=Ae;E.Viewer=Dt;E.CanvasBackground=qe;E.Audio=Fe;E.Video=De;E.Model=Ue;E.AudioHTML=Le;E.VideoHTML=Ne;E.ModelHTML=_e;exports.CanvasPanel=E;
47
47
  //# sourceMappingURL=canvas-panel.js.map