react-iiif-vault 0.9.18 → 0.9.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- "use strict";var qe=Object.defineProperty,Ge=Object.defineProperties;var Ke=Object.getOwnPropertyDescriptors;var $=Object.getOwnPropertySymbols;var le=Object.prototype.hasOwnProperty,fe=Object.prototype.propertyIsEnumerable;var ue=(e,t,n)=>t in e?qe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,v=(e,t)=>{for(var n in t||(t={}))le.call(t,n)&&ue(e,n,t[n]);if($)for(var n of $(t))fe.call(t,n)&&ue(e,n,t[n]);return e},x=(e,t)=>Ge(e,Ke(t));var de=(e,t)=>{var n={};for(var r in e)le.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&$)for(var r of $(e))t.indexOf(r)<0&&fe.call(e,r)&&(n[r]=e[r]);return n};Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var c=require("react"),B=require("@atlas-viewer/atlas"),f=require("react/jsx-runtime"),K=require("@iiif/vault"),C=require("typesafe-actions"),pe=require("react-dom/client"),We=require("@iiif/vault-helpers"),V=require("@atlas-viewer/iiif-image-api");function Xe(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}function Je(e){if(e&&e.__esModule)return e;var t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});return e&&Object.keys(e).forEach(function(n){if(n!=="default"){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,Object.freeze(t)}var W=Je(c),L=Xe(c);function ee(e,t){return ee=Object.setPrototypeOf||function(r,i){return r.__proto__=i,r},ee(e,t)}function Ze(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,ee(e,t)}var et=function(t,n){return t===void 0&&(t=[]),n===void 0&&(n=[]),t.length!==n.length||t.some(function(r,i){return!Object.is(r,n[i])})},ge={error:null},tt=function(e){Ze(t,e);function t(){for(var r,i=arguments.length,a=new Array(i),o=0;o<i;o++)a[o]=arguments[o];return r=e.call.apply(e,[this].concat(a))||this,r.state=ge,r.resetErrorBoundary=function(){for(var s,l=arguments.length,u=new Array(l),d=0;d<l;d++)u[d]=arguments[d];r.props.onReset==null||(s=r.props).onReset.apply(s,u),r.reset()},r}t.getDerivedStateFromError=function(i){return{error:i}};var n=t.prototype;return n.reset=function(){this.setState(ge)},n.componentDidCatch=function(i,a){var o,s;(o=(s=this.props).onError)==null||o.call(s,i,a)},n.componentDidUpdate=function(i,a){var o=this.state.error,s=this.props.resetKeys;if(o!==null&&a.error!==null&&et(i.resetKeys,s)){var l,u;(l=(u=this.props).onResetKeysChange)==null||l.call(u,i.resetKeys,s),this.reset()}},n.render=function(){var i=this.state.error,a=this.props,o=a.fallbackRender,s=a.FallbackComponent,l=a.fallback;if(i!==null){var u={error:i,resetErrorBoundary:this.resetErrorBoundary};if(W.isValidElement(l))return l;if(typeof o=="function")return o(u);if(s)return W.createElement(s,u);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},t}(W.Component);const nt={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},oe=L.default.createContext(nt),q=()=>c.useContext(oe);function Te({value:e,children:t}){const n=q(),r=c.useMemo(()=>v(v({},n),e),[e,n]);return f.jsx(oe.Provider,{value:r,children:t})}const ie=L.default.createContext({vault:null,setVaultInstance:e=>{}});function rt({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:i}){const[a,o]=c.useState(()=>e||(n?K.globalVault(t):t?new K.Vault(t):new K.Vault));return f.jsx(ie.Provider,{value:{vault:a,setVaultInstance:o},children:f.jsx(Te,{value:r||{},children:i})})}const A=()=>{const{vault:e}=c.useContext(ie);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};function ot({canvas:e,children:t}){return f.jsx(Te,{value:{canvas:e},children:t})}function M(e,t=[]){const n=A(),[r,i]=c.useState(()=>e(n.getState(),n));return c.useEffect(()=>n.subscribe(a=>e(a,n),a=>{i(a)},!1),t),r}const ae=L.default.createContext([]);function it(){const e=c.useContext(ae);return M(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}function se(e={},t=[]){const{id:n,selector:r}=e,i=q();A();const a=n||i.manifest,o=M(s=>a?s.iiif.entities.Manifest[a]:void 0,[a]);return c.useMemo(()=>{if(!!o)return r?r(o):o},[o,r,...t])}const D=()=>{},Oe=c.createContext({setCurrentCanvasId:D,setCurrentCanvasIndex:D,nextCanvas:D,previousCanvas:D,items:[],sequence:[],setSequenceIndex:D,currentSequenceIndex:0});function at(){return{VaultContext:c.useContext(ie),ResourceContext:c.useContext(oe),SimpleViewerReactContext:c.useContext(Oe),VisibleCanvasReactContext:c.useContext(ae)}}function st(e){return f.jsx(rt,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext,children:f.jsx(ae.Provider,{value:e.bridge.VisibleCanvasReactContext,children:f.jsx(Oe.Provider,{value:e.bridge.SimpleViewerReactContext,children:e.children})})})}const ct="@iiif/IMPORT_ENTITIES",ut="@iiif/MODIFY_ENTITY_FIELD",lt="@iiif/REORDER_ENTITY_FIELD",ft="@iiif/ADD_REFERENCE",dt="@iiif/REMOVE_REFERENCE",pt=C.createAction(ct)(),gt=C.createAction(ut)(),mt=C.createAction(lt)(),ht=C.createAction(ft)(),yt=C.createAction(dt)(),X={importEntities:pt,modifyEntityField:gt,reorderEntityField:mt,addReference:ht,removeReference:yt},vt="@iiif/ADD_MAPPING",xt="@iiif/ADD_MAPPINGS";C.createAction(vt)();C.createAction(xt)();const St="@iiif/SET_META_VALUE",Et="@iiif/SET_META_VALUE_DYNAMIC",bt="@iiif/UNSET_META_VALUE";C.createAction(St)();C.createAction(Et)();C.createAction(bt)();const Pt="@iiif/REQUEST_RESOURCE",wt="@iiif/REQUEST_ERROR",Ct="@iiif/REQUEST_MISMATCH",Tt="@iiif/REQUEST_COMPLETE",Ot="@iiif/REQUEST_OFFLINE_RESOURCE";C.createAction(Pt)();C.createAction(wt)();C.createAction(Ct)();C.createAction(Tt)();C.createAction(Ot)();const At="@iiif/BATCH",Rt="@iiif/BATCH_IMPORT";C.createAction(At)();C.createAction(Rt)();function Mt(){const t=A().getStore();return c.useMemo(()=>n=>t.dispatch(n),[t])}function me(e){return typeof e!="string"&&e&&e.bindToVault}function _t(){const e=A(),t=c.useRef([]),n=Mt(),r=c.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);c.useLayoutEffect(()=>{const s={id:r,type:"AnnotationPage",behavior:[],motivation:null,label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[]};n(X.importEntities({entities:{AnnotationPage:{[s.id]:s}}}))},[r]);const i=M(s=>r?s.iiif.entities.AnnotationPage[r]:null,[r]),a=c.useCallback((s,l)=>{if(r){if(me(s)){const p=s;p.__vault||p.bindToVault(e),s=typeof p.source=="string"?p.source:p.source.id,t.current[s]=p}else typeof s!="string"&&(s=s.id);const u=e.get({id:r,type:"AnnotationPage"}),d=e.get({id:s,type:"Annotation"});u&&d&&(u.items.find(p=>p.id===d.id)||n(X.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:s,type:"Annotation"},index:l})))}},[r]),o=c.useCallback(s=>{r&&(me(s)?s=typeof s.source=="string"?s.source:s.source.id:typeof s!="string"&&(s=s.id),t.current[s]&&t.current[s].beforeRemove(),e.get({id:r,type:"AnnotationPage"})&&n(X.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:s,type:"Annotation"}})))},[r]);return[i,{addAnnotation:a,removeAnnotation:o}]}const Ae=c.createContext(null);function jt(){const e=c.useContext(Ae);return[e.fullPage,{addAnnotation:e.addAnnotation,removeAnnotation:e.removeAnnotation}]}function It({children:e}){const[t,{addAnnotation:n,removeAnnotation:r}]=_t();return f.jsx(Ae.Provider,{value:c.useMemo(()=>({fullPage:t,addAnnotation:n,removeAnnotation:r}),[t]),children:e})}function Lt({width:e,style:t,height:n}){return f.jsx("div",{style:x(v({width:e,height:n,minHeight:500},t||{}),{background:"#f9f9f9"}),children:"Unknown error"})}const ce=c.createContext(null);function Ft(){return c.useContext(ce)}const Re=L.default.createContext(null),Me=L.default.createContext(null);function H({children:e,overlay:t}){const n=c.useContext(t?Me:Re),r=Ft();return c.useLayoutEffect(()=>{if(n)try{n.render(f.jsx(ce.Provider,{value:r,children:e}))}catch{}},[e,r]),null}function kt(i){var a=i,{children:e,errorFallback:t,outerContainerProps:n={}}=a,r=de(a,["children","errorFallback","outerContainerProps"]);const o=c.useRef(null),[s,l]=c.useState(),[u,d]=c.useState(),p=c.useRef(null),[g,h]=c.useState(),y=at(),P=t||Lt;return c.useLayoutEffect(()=>{const S={};if(o.current){const b=document.createElement("div");o.current.appendChild(b),S.portal=pe.createRoot(b),l(S.portal)}if(p.current){const b=document.createElement("div");p.current.appendChild(b),S.overlayPortal=pe.createRoot(b),h(S.overlayPortal)}return()=>{l(null),h(null),setTimeout(()=>{S.portal&&S.portal.unmount(),S.overlayPortal&&S.overlayPortal.unmount()},0)}},[]),f.jsxs(tt,{fallbackRender:()=>f.jsx(P,v({},r)),children:[f.jsx(B.AtlasAuto,x(v({},r),{containerProps:v({style:{position:"relative"}},r.containerProps||{}),htmlChildren:f.jsx("div",{ref:p}),onCreated:S=>{d(S),r.onCreated&&r.onCreated(S)},children:f.jsx(ce.Provider,{value:u,children:f.jsx(Re.Provider,{value:s,children:f.jsx(Me.Provider,{value:g,children:f.jsx(st,{bridge:y,children:f.jsx(It,{children:e})})})})})})),f.jsx("div",{ref:o})]})}function Nt(e){return{addEventListener(t,n,r,i){if(!!t)return e.setMetaValue([t.id,"eventManager",n],a=>{const o=a||[];for(const s of o)if(s.callback===r)return o;return[...o,{callback:r,scope:i}]}),r},removeEventListener(t,n,r){!t||e.setMetaValue([t.id,"eventManager",n],i=>(i||[]).filter(a=>a.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"),a={};if(i&&r)for(const o of Object.keys(i))a[o]=s=>{const l=e.get(r);for(const{callback:u,scope:d}of i[o]||[])(!d||n&&d.indexOf(n)!==-1)&&u(s,l)};return a}}}function _e(e,t){const n=A(),r=c.useMemo(()=>Nt(n),[n]),i=M(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return c.useMemo(()=>e?r.getListenersAsProps(e,t):{},[i,e,n,t])}function je(e){return{applyStyles(t,n,r){const i=typeof t=="string"?t:t.id;return e.setMetaValue([i,"styles",n],r)},getAppliedStyles(t){const n=typeof t=="string"?t:t.id;return e.getResourceMeta(n,"styles")}}}function z(e,t){const n=A(),r=c.useMemo(()=>je(n),[n]);return M(()=>{if(!e)return null;const i=r.getAppliedStyles(e.id);return i?t?i[t]:i:void 0},[e,t])}var Ut=Object.defineProperty,Dt=Object.defineProperties,Vt=Object.getOwnPropertyDescriptors,he=Object.getOwnPropertySymbols,Bt=Object.prototype.hasOwnProperty,Ht=Object.prototype.propertyIsEnumerable,ye=(e,t,n)=>t in e?Ut(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ve=(e,t)=>{for(var n in t||(t={}))Bt.call(t,n)&&ye(e,n,t[n]);if(he)for(var n of he(t))Ht.call(t,n)&&ye(e,n,t[n]);return e},xe=(e,t)=>Dt(e,Vt(t));const $t=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,zt=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function te(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:r,selectors:i}=te(n);return r&&(t.selector||(t.selector=r),t.selectors.push(...i)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,n]=e.split("#");return n?te({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=$t.exec(e.value);if(t){const r={type:"BoxSelector",spatial:{unit:t[2]==="percent:"||t[2]==="pct:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:r,selectors:[r]}}const n=e.value.match(zt);if(n){const r={type:"TemporalSelector",temporal:{startTime:n[4]?parseFloat(n[4]):0,endTime:n[7]?parseFloat(n[7]):void 0}};return{selector:r,selectors:[r]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}function k(e,t={}){if(Array.isArray(e))return k(e[0]);if(typeof e=="string"){const[n,r]=e.split("#");return r?k({type:"SpecificResource",source:{id:n,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return k(e.items[0]);if(e.type==="SpecificResource"){e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]);const{selector:n,selectors:r}=e.selector?te(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:n,selectors:r}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[n,r]=e.id.split("#");return r?k({type:"SpecificResource",source:xe(ve({},e),{id:n}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:xe(ve({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function Yt(e={},t=[]){const{id:n,selector:r}=e,i=q(),a=A(),o=n||i.annotation,s=M(u=>o?u.iiif.entities.Annotation[o]:void 0,[o]),l=M(u=>s&&s.body?s.body.map(d=>d?u.iiif.entities[d.type][d.id]:null).filter(Boolean):[],[s]);return c.useMemo(()=>{if(!s)return;const u=x(v({},s),{body:l,target:k(s.target,{typeMap:a.getState().iiif.mapping})});return r?r(u):u},[s,r,l,...t])}function F(e={},t=[]){const{id:n,selector:r}=e,i=q(),a=n||i.canvas,o=M(s=>a?s.iiif.entities.Canvas[a]:void 0,[a]);return c.useMemo(()=>{if(!!o)return r?r(o):o},[o,r,...t])}const Ie=({id:e,style:t,className:n,interactive:r})=>{const i=Yt({id:e}),a=z(i,"atlas"),o=z(i,"html"),s=_e(i,["atlas"]),l=F(),u=c.useMemo(()=>B.mergeStyles(t,a),[t,a]);return l&&i&&i.target&&i.target.selector&&i.target.selector.type==="BoxSelector"&&i.target.source&&i.target.source.id===l.id?f.jsx(B.RegionHighlight,v({id:i.id,isEditing:!0,region:i.target.selector.spatial,style:u,className:(o==null?void 0:o.className)||n,interactive:!!((o==null?void 0:o.href)||r),href:(o==null?void 0:o.href)||null,title:(o==null?void 0:o.title)||null,hrefTarget:(o==null?void 0:o.target)||null},s)):null},ne=({className:e,page:t})=>{var i;const n=z(t,"atlas"),r=z(t,"html");return M(a=>t.id?a.iiif.entities.AnnotationPage[t.id]:null,[]),f.jsx(c.Fragment,{children:(i=t.items)==null?void 0:i.map(a=>f.jsx(Ie,{id:a.id,style:n,className:(r==null?void 0:r.className)||e},a.id))})};function Le({id:e,image:t,thumbnail:n,isStatic:r,x:i=0,y:a=0,children:o,onClick:s}){var l,u,d,p;return f.jsx(c.Fragment,{children:t.service?f.jsxs(c.Fragment,{children:[f.jsx(B.TileSet,{tiles:{id:t.service.id||t.service["@id"]||"unknown",height:t.height,width:t.width,imageService:t.service,thumbnail:n&&n.type==="fixed"?n:void 0},x:((l=t.target)==null?void 0:l.spatial.x)+i,y:((u=t.target)==null?void 0:u.spatial.y)+a,width:(d=t.target)==null?void 0:d.spatial.width,height:(p=t.target)==null?void 0:p.spatial.height,onClick:s}),o]},"service"):f.jsxs(c.Fragment,{children:[f.jsx("world-image",{onClick:s,uri:t.id,target:t.target.spatial,display:t.width&&t.height?{width:t.width,height:t.height}:void 0}),o]},"no-service")},e)}function Qt(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function qt(e,t,n){const r=[];let i=null;const a=[];for(const o of t){const s=e.get(o.body);for(const l of s){const[u,{selector:d}]=Qt(l),p=(u.type||"unknown").toLowerCase();if(p==="choice"){const g=e.get(u.items),h=n.length?n.map(y=>g.find(P=>P.id===y)).filter(Boolean):[g[0]];h.length===0&&h.push(g[0]),i={type:"single-choice",items:g.map(y=>({id:y.id,label:y.label,selected:h.indexOf(y)!==-1})),label:l.label},s.push(...h);continue}r.indexOf(p)===-1&&r.push(p),a.push({annotationId:o.id,type:p,resource:u,target:o.target,selector:d})}}return{types:r,items:a,choice:i}}function Fe(e,t){const{selector:n,source:r}=We.expandTarget(t);if(r.id!==e.id)return[null,r];const i={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}};return[n?n.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:n.temporal,spatial:i.spatial}:n:null,r]}const Gt={makeChoice:()=>{}},J={type:"unknown"},w=e=>({type:"unknown",reason:e,annotations:{pages:[]}}),Kt=(e,t)=>({type:"empty",width:e,height:t,annotations:{pages:[]},image:null,images:[]});function Wt(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 Xt(e,t){return M(n=>{const r=[];if(!e)return r;const i=Object.keys(n.iiif.entities.AnnotationPage);for(const a of i)if(!t||t.indexOf(a)!==-1){const o=Wt(n,a);o&&o.views&&o.views[e]&&r.push(a)}return r},[e,t])}function Jt({canvas:e,manifest:t,all:n,canvases:r}){const i=[];if(t)for(const a of t.annotations)i.indexOf(a.id)===-1&&i.push(a.id);if(n){if(r&&r.length)for(const a of r)for(const o of a.annotations)i.indexOf(o.id)===-1&&i.push(o.id)}else if(e)for(const a of e.annotations)i.indexOf(a.id)===-1&&i.push(a.id);return i}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 en(e,t={}){const n=A(),r=se(),i=F(),a=it(),o=c.useMemo(()=>Jt({all:t.all,manifest:r,canvas:i,canvases:a}),[t.all,i,a,r]),s=Xt(e,t.all?void 0:o),l=c.useCallback(d=>{!e||n.setMetaValue([d,"annotationPageManager","views"],p=>p&&!p[e]?p:x(v({},p||{}),{[e]:!1}))},[e,n]),u=c.useCallback((d,p={})=>{if(!e)return;const g=n.getState(),h=[];if(p!=null&&p.deselectOthers){const y=Object.keys(g.iiif.entities.AnnotationPage);for(const P of y){const S=Zt(g,P);S&&S.views&&S.views[e]&&h.push(P)}}for(const y of h)l(y);n.setMetaValue([d,"annotationPageManager","views"],y=>y&&y[e]?y:x(v({},y||{}),{[e]:!0}))},[e,l,n]);return{availablePageIds:o,enabledPageIds:s,setPageEnabled:u,setPageDisabled:l}}function tn(e,t){return M((n,r)=>r.get(e.map(i=>({id:i,type:t}))),[e,t])}const nn=L.default.createContext(new V.ImageServiceLoader);function ke(){return c.useContext(nn)}function rn(){const e=ke(),[t,n]=c.useState({}),r=c.useRef(!1);return c.useEffect(()=>()=>{r.current=!0},[]),[c.useCallback((a,{height:o,width:s})=>{if(a){const l=a.id||a["@id"],u=e.loadServiceSync({id:l,width:a.width||s,height:a.height||o,source:a});u?a=u:t[l]||(r.current||n(d=>x(v({},d),{[l]:"loading"})),e.loadService({id:l,width:a.width||s,height:a.height||o}).then(()=>{r.current||n(d=>x(v({},d),{[l]:"done"}))}))}return a},[e,t]),t]}function on(e={}){const t=F(e.canvasId?{id:e.canvasId}:void 0);return M((n,r)=>{if(!t)return[];const i=r.get(t.items),a=[];for(const o of i)a.push(...r.get(o.items));return a},[t])}function an(e,t=[]){const n=A(),r=on(),[i,a]=c.useState((e==null?void 0:e.defaultChoices)||[]),o=c.useMemo(()=>qt(n,r,i),[n,r,i,...t]),l={makeChoice:c.useCallback((u,{deselectOthers:d=!0,deselect:p=!1}={})=>{if(o.choice){if(o.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");a(g=>{if(p){const y=g.filter(P=>P!==u);if(y.length===0){const P=o.items[0].resource.id;return P?[P]:[]}return y}if(d)return[u];const h=[...g];if(h.length===0&&o.items.length){const y=o.items[0].resource.id;y&&h.push(y)}return g.indexOf(u)!==-1?g:[...g,u]})}},[o.choice])};return[o,l]}function sn(e,t,n){const r=[];for(const i of t.items){const a=i.resource&&i.resource.type==="SpecificResource"?i.resource.source:i.resource;if(!a.id)return w("No resource Identifier");let o;if(a.service){const y=V.getImageServices(a);y[0]&&(o=n(y[0],e))}const s={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},[l,u]=Fe(e,i.target);if(u.id!==e.id)continue;const d={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},p=i.resource.type==="SpecificResource"?k(i.resource):null,g=p&&p.selector&&(p.selector.type==="BoxSelector"||p.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:p.selector.spatial.x,y:p.selector.spatial.y,width:p.selector.spatial.width,height:p.selector.spatial.height}}:d;o&&!o.id&&(o.id=o["@id"]);const h={id:a.id,type:"Image",annotationId:i.annotationId,width:l?a.width:e.width,height:l?a.height:e.height,service:o,sizes:o&&o.sizes?o.sizes:a.width&&a.height?[{width:a.width,height:a.height}]:[],target:l&&l.type!=="PointSelector"?l:s,selector:g};r.push(h)}return{type:"images",image:r[0],images:r,choice:t.choice}}const cn=["model/gltf-binary"];function un(e,t){const r=t.items[0].resource;return r.format?cn.indexOf(r.format)===-1?w(`3D format: ${r.format} is unsupported`):{type:"3d-model",model:r}:w("Unknown format")}function ln(e,t){var r;if(!e.duration)return w("No duration on canvas");if(t.items.length>1)return w("Only one audio source supported");const n=(r=t.items[0])==null?void 0:r.resource;return n?n.format?{type:"media",media:{annotationId:t.items[0].annotationId,duration:e.duration,url:n.id,type:"Sound",target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:n.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}},annotations:{pages:[]}}:w("Audio does not have format"):w("Unknown audio")}function fn(e,t){var i;const n=t.items.filter(a=>a.type==="video");if(!e.duration)return w("No duration on canvas");if(n.length>1)return w("Only one video source supported");const r=(i=n[0])==null?void 0:i.resource;return r?r.format?{type:"media",media:{annotationId:t.items[0].annotationId,duration:e.duration,url:r.id,type:"Video",items:[],target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:r.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}},annotations:{pages:[]}}:w("Video does not have format"):w("Unknown video")}function Ne(e,t={},n){const r=e.language||n||"none";switch(e.type){case"TextualBody":{typeof e.value!="undefined"&&(t[r]=e.value);break}case"List":case"Composite":case"Choice":e.items&&e.items.forEach(i=>Ne(i,t,r))}return t}function dn(e,t){const n=[];return t.items.forEach(r=>{if(r.resource){const[i]=Fe(e,r.target);n.push({annotationId:r.annotationId,text:Ne(r.resource),target:i})}}),{type:"textual-content",items:n}}function pn(e){const t=se(),n=F(),r=A(),[i,a]=rn(),{enabledPageIds:o}=en((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(n==null?void 0:n.id),{all:!1}),s=tn(o,"AnnotationPage"),l=(e==null?void 0:e.strategies)||["empty","images","media","textual-content","complex-timeline"],[u,d]=an(e,[a]),p=c.useMemo(()=>{if(!n)return J;if(u.types.length===0)return l.indexOf("empty")!==-1?Kt(n.width,n.height):J;if(u.types.length!==1)if(u.types.length===2&&u.types.indexOf("text")!==-1)u.types=u.types.filter(h=>h!=="text");else return l.indexOf("complex-timeline")===-1?w("Complex timeline not supported"):w("ComplexTimelineStrategy not yet supported");const g=u.types[0];return g==="image"?l.indexOf("images")===-1?w("Image not supported"):sn(n,u,i):g==="Model"||g==="model"?l.indexOf("3d-model")===-1?w("3D not supported"):un(n,u):g==="textualbody"?l.indexOf("textual-content")===-1?w("Textual content not supported"):dn(n,u):g==="sound"||g==="audio"?l.indexOf("media")===-1?w("Media not supported"):ln(n,u):g==="video"?l.indexOf("media")===-1?w("Media not supported"):fn(n,u):J},[n,u,r,d.makeChoice]);return c.useMemo(()=>p.type==="unknown"?[p,Gt]:[x(v({},p),{annotations:{pages:s}}),d],[p,s])}const gn=(e,t=[])=>{const n=A();c.useEffect(()=>{e(n)},[n,...t])};function mn(e,t={}){const n=t.imageServiceLoader||new V.ImageServiceLoader;async function r(i,a,o,s=[],l){if(typeof i=="string")return{best:V.getFixedSizeFromImage(i),fallback:[],log:[]};const u=e.get(i);if(typeof u=="string")return{best:V.getFixedSizeFromImage(u),fallback:[],log:[]};switch(u.type){case"Annotation":{const d=u.body,p=e.get(d[0]);return l&&!p.width&&(p.width=l.width,p.height=l.height),await n.getThumbnailFromResource(p,a,o,s)}case"Canvas":{const d=u;if(d.thumbnail&&d.thumbnail.length){const p=e.get(d.thumbnail[0]),g=await n.getImageCandidates(p,o);g&&g.length&&s.push(...g)}return r(d.items[0],a,o,s,{width:d.width,height:d.height})}case"AnnotationPage":return r(u.items[0],a,o,s,l);case"Choice":return r(u.items[0],a,o,s,l);case"Collection":{const p=u.items[0];return r(p,a,o,s,l)}case"Manifest":{const p=u.items[0];return r(p,a,o,s,l)}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return l&&!u.width&&(u.width=l.width,u.height=l.height),n.getThumbnailFromResource(u,a,o,s);case"Service":case"Range":case"AnnotationCollection":case"CanvasReference":case"ContentResource":return{best:void 0,fallback:[],log:[]}}return{best:void 0,fallback:[],log:[]}}return{getBestThumbnailAtSize:r}}function hn(e,t,{canvasId:n,manifestId:r}={}){const i=A(),a=ke(),o=c.useMemo(()=>mn(i,{imageServiceLoader:a}),[i,a]),[s,l]=c.useState(),u=se(r?{id:r}:void 0),d=F(n?{id:n}:void 0),p=d||u,g=c.useRef(!1);if(c.useEffect(()=>(g.current=!1,()=>{g.current=!0}),[]),!p)throw new Error("Must be called under a manifest or canvas context.");return gn(h=>{o.getBestThumbnailAtSize(p,e,t).then(y=>{y.best&&!g.current&&l(y.best)})},[p]),s}function yn(e){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:e}}function vn(e,t){switch(t.type){case"FINISHED":return x(v({},e),{isFinished:!0,isPlaying:!1,playRequested:!1});case"PLAY_PAUSE":return x(v({},e),{isFinished:!1,isPlaying:!e.isPlaying});case"PLAY_REQUESTED":return x(v({},e),{isFinished:!1,playRequested:!0});case"PAUSE":return x(v({},e),{isPlaying:!1});case"PLAY":return x(v({},e),{isFinished:!1,playRequested:!1,isPlaying:!0});case"MUTE":return x(v({},e),{isMuted:!0});case"SET_VOLUME":return x(v({},e),{volume:t.volume,isMuted:t.volume===0});case"TOGGLE_MUTE":return x(v({},e),{isMuted:!e.isMuted});case"UNMUTE":return x(v({},e),{isMuted:!1})}return e}function xn(e){const t=Math.round(e);return`${Math.floor(t/60)}:${`${t%60}`.padStart(2,"0")}`}function Ue(e){const[t,n]=c.useReducer(vn,yn(e.duration)),r=c.useRef(null),i=c.useRef(null),a=c.useRef(null),o=c.useRef(!1),s=c.useCallback(()=>{i.current&&r.current&&(i.current.innerHTML=xn(r.current.currentTime),a.current&&(a.current.style.width=`${r.current.currentTime/e.duration*100}%`),o.current!==r.current.muted&&(o.current=r.current.muted,n(r.current.muted?{type:"MUTE"}:{type:"UNMUTE"})))},[e.duration]),l=c.useCallback(()=>{r.current&&(n({type:"PLAY_REQUESTED"}),r.current.play().then(()=>{n({type:"PLAY"})}),s())},[s]),u=c.useCallback(()=>{r.current&&(r.current.duration>0&&r.current.paused?l():d())},[s]),d=c.useCallback(()=>{r.current&&(r.current.pause(),n({type:"PAUSE"}),s())},[s]),p=c.useCallback(()=>{r.current&&(r.current.muted=!r.current.muted,n(r.current.muted?{type:"MUTE"}:{type:"UNMUTE"}))},[]),g=c.useCallback(()=>{r.current&&(r.current.muted=!0,n({type:"MUTE"}))},[]),h=c.useCallback(()=>{r.current&&(r.current.muted=!1,n({type:"UNMUTE"}))},[]),y=c.useCallback(b=>{r.current&&(r.current.muted=!1,r.current.volume=b/100,n({type:"SET_VOLUME",volume:b}))},[]),P=c.useCallback(b=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(b*e.duration,e.duration)),s())},[]),S=c.useCallback(b=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(b,e.duration)),s())},[]);return c.useEffect(()=>{const b=setInterval(()=>{s()},350);return()=>clearInterval(b)},[s,e.duration]),c.useEffect(()=>{const b=()=>{n({type:"FINISHED"})},m=r.current;return m==null||m.addEventListener("ended",b),()=>m==null?void 0:m.removeEventListener("ended",b)},[]),[{element:r,currentTime:i,progress:a},t,{play:l,pause:d,playPause:u,mute:g,unmute:h,toggleMute:p,setVolume:y,setDurationPercent:P,setTime:S}]}const Sn=c.createContext(null),En=c.createContext(null),bn=c.createContext(null);function De({actions:e,state:t,children:n,currentTime:r,progress:i,element:a}){return f.jsx(bn.Provider,{value:{currentTime:r,progress:i,element:a},children:f.jsx(En.Provider,{value:e,children:f.jsx(Sn.Provider,{value:t,children:n})})})}function Pn({media:e,children:t}){const[{element:n,currentTime:r,progress:i},a,o]=Ue({duration:e.duration});return f.jsx(f.Fragment,{children:f.jsx(H,{children:f.jsxs(De,{state:a,actions:o,currentTime:r,progress:i,element:n,children:[f.jsx("audio",{ref:n,src:e.url}),t]})})})}function wn({media:e,children:t}){const[{element:n,currentTime:r,progress:i},a,o]=Ue({duration:e.duration}),s="div";return f.jsxs(f.Fragment,{children:[f.jsxs(H,{overlay:!0,children:[f.jsx("style",{children:`
1
+ "use strict";var Ge=Object.defineProperty,Ke=Object.defineProperties;var We=Object.getOwnPropertyDescriptors;var $=Object.getOwnPropertySymbols;var le=Object.prototype.hasOwnProperty,fe=Object.prototype.propertyIsEnumerable;var ue=(e,t,n)=>t in e?Ge(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,v=(e,t)=>{for(var n in t||(t={}))le.call(t,n)&&ue(e,n,t[n]);if($)for(var n of $(t))fe.call(t,n)&&ue(e,n,t[n]);return e},x=(e,t)=>Ke(e,We(t));var de=(e,t)=>{var n={};for(var r in e)le.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&$)for(var r of $(e))t.indexOf(r)<0&&fe.call(e,r)&&(n[r]=e[r]);return n};Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var c=require("react"),B=require("@atlas-viewer/atlas"),f=require("react/jsx-runtime"),K=require("@iiif/vault"),C=require("typesafe-actions"),pe=require("react-dom/client"),Xe=require("@iiif/vault-helpers"),V=require("@atlas-viewer/iiif-image-api");function Je(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}function Ze(e){if(e&&e.__esModule)return e;var t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});return e&&Object.keys(e).forEach(function(n){if(n!=="default"){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,Object.freeze(t)}var W=Ze(c),L=Je(c);function ee(e,t){return ee=Object.setPrototypeOf||function(r,i){return r.__proto__=i,r},ee(e,t)}function et(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,ee(e,t)}var tt=function(t,n){return t===void 0&&(t=[]),n===void 0&&(n=[]),t.length!==n.length||t.some(function(r,i){return!Object.is(r,n[i])})},ge={error:null},nt=function(e){et(t,e);function t(){for(var r,i=arguments.length,a=new Array(i),o=0;o<i;o++)a[o]=arguments[o];return r=e.call.apply(e,[this].concat(a))||this,r.state=ge,r.resetErrorBoundary=function(){for(var s,l=arguments.length,u=new Array(l),d=0;d<l;d++)u[d]=arguments[d];r.props.onReset==null||(s=r.props).onReset.apply(s,u),r.reset()},r}t.getDerivedStateFromError=function(i){return{error:i}};var n=t.prototype;return n.reset=function(){this.setState(ge)},n.componentDidCatch=function(i,a){var o,s;(o=(s=this.props).onError)==null||o.call(s,i,a)},n.componentDidUpdate=function(i,a){var o=this.state.error,s=this.props.resetKeys;if(o!==null&&a.error!==null&&tt(i.resetKeys,s)){var l,u;(l=(u=this.props).onResetKeysChange)==null||l.call(u,i.resetKeys,s),this.reset()}},n.render=function(){var i=this.state.error,a=this.props,o=a.fallbackRender,s=a.FallbackComponent,l=a.fallback;if(i!==null){var u={error:i,resetErrorBoundary:this.resetErrorBoundary};if(W.isValidElement(l))return l;if(typeof o=="function")return o(u);if(s)return W.createElement(s,u);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},t}(W.Component);const rt={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},oe=L.default.createContext(rt),q=()=>c.useContext(oe);function Te({value:e,children:t}){const n=q(),r=c.useMemo(()=>v(v({},n),e),[e,n]);return f.jsx(oe.Provider,{value:r,children:t})}const ie=L.default.createContext({vault:null,setVaultInstance:e=>{}});function ot({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:i}){const[a,o]=c.useState(()=>e||(n?K.globalVault(t):t?new K.Vault(t):new K.Vault));return f.jsx(ie.Provider,{value:{vault:a,setVaultInstance:o},children:f.jsx(Te,{value:r||{},children:i})})}const A=()=>{const{vault:e}=c.useContext(ie);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};function it({canvas:e,children:t}){return f.jsx(Te,{value:{canvas:e},children:t})}function M(e,t=[]){const n=A(),[r,i]=c.useState(()=>e(n.getState(),n));return c.useEffect(()=>n.subscribe(a=>e(a,n),a=>{i(a)},!1),t),r}const ae=L.default.createContext([]);function at(){const e=c.useContext(ae);return M(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}function se(e={},t=[]){const{id:n,selector:r}=e,i=q();A();const a=n||i.manifest,o=M(s=>a?s.iiif.entities.Manifest[a]:void 0,[a]);return c.useMemo(()=>{if(!!o)return r?r(o):o},[o,r,...t])}const D=()=>{},Oe=c.createContext({setCurrentCanvasId:D,setCurrentCanvasIndex:D,nextCanvas:D,previousCanvas:D,items:[],sequence:[],setSequenceIndex:D,currentSequenceIndex:0});function st(){return{VaultContext:c.useContext(ie),ResourceContext:c.useContext(oe),SimpleViewerReactContext:c.useContext(Oe),VisibleCanvasReactContext:c.useContext(ae)}}function ct(e){return f.jsx(ot,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext,children:f.jsx(ae.Provider,{value:e.bridge.VisibleCanvasReactContext,children:f.jsx(Oe.Provider,{value:e.bridge.SimpleViewerReactContext,children:e.children})})})}const ut="@iiif/IMPORT_ENTITIES",lt="@iiif/MODIFY_ENTITY_FIELD",ft="@iiif/REORDER_ENTITY_FIELD",dt="@iiif/ADD_REFERENCE",pt="@iiif/REMOVE_REFERENCE",gt=C.createAction(ut)(),mt=C.createAction(lt)(),ht=C.createAction(ft)(),yt=C.createAction(dt)(),vt=C.createAction(pt)(),X={importEntities:gt,modifyEntityField:mt,reorderEntityField:ht,addReference:yt,removeReference:vt},xt="@iiif/ADD_MAPPING",St="@iiif/ADD_MAPPINGS";C.createAction(xt)();C.createAction(St)();const bt="@iiif/SET_META_VALUE",Et="@iiif/SET_META_VALUE_DYNAMIC",Pt="@iiif/UNSET_META_VALUE";C.createAction(bt)();C.createAction(Et)();C.createAction(Pt)();const wt="@iiif/REQUEST_RESOURCE",Ct="@iiif/REQUEST_ERROR",Tt="@iiif/REQUEST_MISMATCH",Ot="@iiif/REQUEST_COMPLETE",At="@iiif/REQUEST_OFFLINE_RESOURCE";C.createAction(wt)();C.createAction(Ct)();C.createAction(Tt)();C.createAction(Ot)();C.createAction(At)();const Rt="@iiif/BATCH",Mt="@iiif/BATCH_IMPORT";C.createAction(Rt)();C.createAction(Mt)();function _t(){const t=A().getStore();return c.useMemo(()=>n=>t.dispatch(n),[t])}function me(e){return typeof e!="string"&&e&&e.bindToVault}function jt(){const e=A(),t=c.useRef([]),n=_t(),r=c.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);c.useLayoutEffect(()=>{const s={id:r,type:"AnnotationPage",behavior:[],motivation:null,label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[]};n(X.importEntities({entities:{AnnotationPage:{[s.id]:s}}}))},[r]);const i=M(s=>r?s.iiif.entities.AnnotationPage[r]:null,[r]),a=c.useCallback((s,l)=>{if(r){if(me(s)){const p=s;p.__vault||p.bindToVault(e),s=typeof p.source=="string"?p.source:p.source.id,t.current[s]=p}else typeof s!="string"&&(s=s.id);const u=e.get({id:r,type:"AnnotationPage"}),d=e.get({id:s,type:"Annotation"});u&&d&&(u.items.find(p=>p.id===d.id)||n(X.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:s,type:"Annotation"},index:l})))}},[r]),o=c.useCallback(s=>{r&&(me(s)?s=typeof s.source=="string"?s.source:s.source.id:typeof s!="string"&&(s=s.id),t.current[s]&&t.current[s].beforeRemove(),e.get({id:r,type:"AnnotationPage"})&&n(X.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:s,type:"Annotation"}})))},[r]);return[i,{addAnnotation:a,removeAnnotation:o}]}const Ae=c.createContext(null);function It(){const e=c.useContext(Ae);return[e.fullPage,{addAnnotation:e.addAnnotation,removeAnnotation:e.removeAnnotation}]}function Lt({children:e}){const[t,{addAnnotation:n,removeAnnotation:r}]=jt();return f.jsx(Ae.Provider,{value:c.useMemo(()=>({fullPage:t,addAnnotation:n,removeAnnotation:r}),[t]),children:e})}function kt({width:e,style:t,height:n}){return f.jsx("div",{style:x(v({width:e,height:n,minHeight:500},t||{}),{background:"#f9f9f9"}),children:"Unknown error"})}const ce=c.createContext(null);function Ft(){return c.useContext(ce)}const Re=L.default.createContext(null),Me=L.default.createContext(null);function H({children:e,overlay:t}){const n=c.useContext(t?Me:Re),r=Ft();return c.useLayoutEffect(()=>{if(n)try{n.render(f.jsx(ce.Provider,{value:r,children:e}))}catch{}},[e,r]),null}function Nt(i){var a=i,{children:e,errorFallback:t,outerContainerProps:n={}}=a,r=de(a,["children","errorFallback","outerContainerProps"]);const o=c.useRef(null),[s,l]=c.useState(),[u,d]=c.useState(),p=c.useRef(null),[g,h]=c.useState(),y=st(),P=t||kt;return c.useLayoutEffect(()=>{const S={};if(o.current){const E=document.createElement("div");o.current.appendChild(E),S.portal=pe.createRoot(E),l(S.portal)}if(p.current){const E=document.createElement("div");p.current.appendChild(E),S.overlayPortal=pe.createRoot(E),h(S.overlayPortal)}return()=>{l(null),h(null),setTimeout(()=>{S.portal&&S.portal.unmount(),S.overlayPortal&&S.overlayPortal.unmount()},0)}},[]),f.jsxs(nt,{fallbackRender:()=>f.jsx(P,v({},r)),children:[f.jsx(B.AtlasAuto,x(v({},r),{containerProps:v({style:{position:"relative"}},r.containerProps||{}),htmlChildren:f.jsx("div",{ref:p}),onCreated:S=>{d(S),r.onCreated&&r.onCreated(S)},children:f.jsx(ce.Provider,{value:u,children:f.jsx(Re.Provider,{value:s,children:f.jsx(Me.Provider,{value:g,children:f.jsx(ct,{bridge:y,children:f.jsx(Lt,{children:e})})})})})})),f.jsx("div",{ref:o})]})}function Ut(e){return{addEventListener(t,n,r,i){if(!!t)return e.setMetaValue([t.id,"eventManager",n],a=>{const o=a||[];for(const s of o)if(s.callback===r)return o;return[...o,{callback:r,scope:i}]}),r},removeEventListener(t,n,r){!t||e.setMetaValue([t.id,"eventManager",n],i=>(i||[]).filter(a=>a.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"),a={};if(i&&r)for(const o of Object.keys(i))a[o]=s=>{const l=e.get(r);for(const{callback:u,scope:d}of i[o]||[])(!d||n&&d.indexOf(n)!==-1)&&u(s,l)};return a}}}function _e(e,t){const n=A(),r=c.useMemo(()=>Ut(n),[n]),i=M(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return c.useMemo(()=>e?r.getListenersAsProps(e,t):{},[i,e,n,t])}function je(e){return{applyStyles(t,n,r){const i=typeof t=="string"?t:t.id;return e.setMetaValue([i,"styles",n],r)},getAppliedStyles(t){const n=typeof t=="string"?t:t.id;return e.getResourceMeta(n,"styles")}}}function z(e,t){const n=A(),r=c.useMemo(()=>je(n),[n]);return M(()=>{if(!e)return null;const i=r.getAppliedStyles(e.id);return i?t?i[t]:i:void 0},[e,t])}var Dt=Object.defineProperty,Vt=Object.defineProperties,Bt=Object.getOwnPropertyDescriptors,he=Object.getOwnPropertySymbols,Ht=Object.prototype.hasOwnProperty,$t=Object.prototype.propertyIsEnumerable,ye=(e,t,n)=>t in e?Dt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ve=(e,t)=>{for(var n in t||(t={}))Ht.call(t,n)&&ye(e,n,t[n]);if(he)for(var n of he(t))$t.call(t,n)&&ye(e,n,t[n]);return e},xe=(e,t)=>Vt(e,Bt(t));const zt=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,Yt=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function te(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:r,selectors:i}=te(n);return r&&(t.selector||(t.selector=r),t.selectors.push(...i)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,n]=e.split("#");return n?te({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=zt.exec(e.value);if(t){const r={type:"BoxSelector",spatial:{unit:t[2]==="percent:"||t[2]==="pct:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:r,selectors:[r]}}const n=e.value.match(Yt);if(n){const r={type:"TemporalSelector",temporal:{startTime:n[4]?parseFloat(n[4]):0,endTime:n[7]?parseFloat(n[7]):void 0}};return{selector:r,selectors:[r]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}function F(e,t={}){if(Array.isArray(e))return F(e[0]);if(typeof e=="string"){const[n,r]=e.split("#");return r?F({type:"SpecificResource",source:{id:n,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return F(e.items[0]);if(e.type==="SpecificResource"){e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]);const{selector:n,selectors:r}=e.selector?te(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:n,selectors:r}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[n,r]=e.id.split("#");return r?F({type:"SpecificResource",source:xe(ve({},e),{id:n}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:xe(ve({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function Ie(e={},t=[]){const{id:n,selector:r}=e,i=q(),a=A(),o=n||i.annotation,s=M(u=>o?u.iiif.entities.Annotation[o]:void 0,[o]),l=M(u=>s&&s.body?s.body.map(d=>d?u.iiif.entities[d.type][d.id]:null).filter(Boolean):[],[s]);return c.useMemo(()=>{if(!s)return;const u=x(v({},s),{body:l,target:F(s.target,{typeMap:a.getState().iiif.mapping})});return r?r(u):u},[s,r,l,...t])}function k(e={},t=[]){const{id:n,selector:r}=e,i=q(),a=n||i.canvas,o=M(s=>a?s.iiif.entities.Canvas[a]:void 0,[a]);return c.useMemo(()=>{if(!!o)return r?r(o):o},[o,r,...t])}const Le=({id:e,style:t,className:n,interactive:r})=>{const i=Ie({id:e}),a=z(i,"atlas"),o=z(i,"html"),s=_e(i,["atlas"]),l=k(),u=c.useMemo(()=>B.mergeStyles(t,a),[t,a]);return l&&i&&i.target&&i.target.selector&&i.target.selector.type==="BoxSelector"&&i.target.source&&i.target.source.id===l.id?f.jsx(B.RegionHighlight,v({id:i.id,isEditing:!0,region:i.target.selector.spatial,style:u,className:(o==null?void 0:o.className)||n,interactive:!!((o==null?void 0:o.href)||r),href:(o==null?void 0:o.href)||null,title:(o==null?void 0:o.title)||null,hrefTarget:(o==null?void 0:o.target)||null},s)):null},ne=({className:e,page:t})=>{var i;const n=z(t,"atlas"),r=z(t,"html");return M(a=>t.id?a.iiif.entities.AnnotationPage[t.id]:null,[]),f.jsx(c.Fragment,{children:(i=t.items)==null?void 0:i.map(a=>f.jsx(Le,{id:a.id,style:n,className:(r==null?void 0:r.className)||e},a.id))})};function ke({id:e,image:t,thumbnail:n,isStatic:r,x:i=0,y:a=0,children:o,onClick:s}){var l,u,d,p;return f.jsx(c.Fragment,{children:t.service?f.jsxs(c.Fragment,{children:[f.jsx(B.TileSet,{tiles:{id:t.service.id||t.service["@id"]||"unknown",height:t.height,width:t.width,imageService:t.service,thumbnail:n&&n.type==="fixed"?n:void 0},x:((l=t.target)==null?void 0:l.spatial.x)+i,y:((u=t.target)==null?void 0:u.spatial.y)+a,width:(d=t.target)==null?void 0:d.spatial.width,height:(p=t.target)==null?void 0:p.spatial.height,onClick:s}),o]},"service"):f.jsxs(c.Fragment,{children:[f.jsx("world-image",{onClick:s,uri:t.id,target:t.target.spatial,display:t.width&&t.height?{width:t.width,height:t.height}:void 0}),o]},"no-service")},e)}function Qt(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function qt(e,t,n){const r=[];let i=null;const a=[];for(const o of t){const s=e.get(o.body,{skipSelfReturn:!1});for(const l of s){if(!l)continue;const[u,{selector:d}]=Qt(l),p=(u.type||"unknown").toLowerCase();if(p==="choice"){const g=e.get(u.items),h=n.length?n.map(y=>g.find(P=>P.id===y)).filter(Boolean):[g[0]];h.length===0&&h.push(g[0]),i={type:"single-choice",items:g.map(y=>({id:y.id,label:y.label,selected:h.indexOf(y)!==-1})),label:l.label},s.push(...h);continue}r.indexOf(p)===-1&&r.push(p),a.push({annotationId:o.id,type:p,resource:u,target:o.target,selector:d})}}return{types:r,items:a,choice:i}}function Fe(e,t){const{selector:n,source:r}=Xe.expandTarget(t);if(r.id!==e.id)return[null,r];const i={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}};return[n?n.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:n.temporal,spatial:i.spatial}:n:null,r]}const Gt={makeChoice:()=>{}},J={type:"unknown"},w=e=>({type:"unknown",reason:e,annotations:{pages:[]}}),Kt=(e,t)=>({type:"empty",width:e,height:t,annotations:{pages:[]},image:null,images:[]});function Wt(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 Xt(e,t){return M(n=>{const r=[];if(!e)return r;const i=Object.keys(n.iiif.entities.AnnotationPage);for(const a of i)if(!t||t.indexOf(a)!==-1){const o=Wt(n,a);o&&o.views&&o.views[e]&&r.push(a)}return r},[e,t])}function Jt({canvas:e,manifest:t,all:n,canvases:r}){const i=[];if(t)for(const a of t.annotations)i.indexOf(a.id)===-1&&i.push(a.id);if(n){if(r&&r.length)for(const a of r)for(const o of a.annotations)i.indexOf(o.id)===-1&&i.push(o.id)}else if(e)for(const a of e.annotations)i.indexOf(a.id)===-1&&i.push(a.id);return i}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 en(e,t={}){const n=A(),r=se(),i=k(),a=at(),o=c.useMemo(()=>Jt({all:t.all,manifest:r,canvas:i,canvases:a}),[t.all,i,a,r]),s=Xt(e,t.all?void 0:o),l=c.useCallback(d=>{!e||n.setMetaValue([d,"annotationPageManager","views"],p=>p&&!p[e]?p:x(v({},p||{}),{[e]:!1}))},[e,n]),u=c.useCallback((d,p={})=>{if(!e)return;const g=n.getState(),h=[];if(p!=null&&p.deselectOthers){const y=Object.keys(g.iiif.entities.AnnotationPage);for(const P of y){const S=Zt(g,P);S&&S.views&&S.views[e]&&h.push(P)}}for(const y of h)l(y);n.setMetaValue([d,"annotationPageManager","views"],y=>y&&y[e]?y:x(v({},y||{}),{[e]:!0}))},[e,l,n]);return{availablePageIds:o,enabledPageIds:s,setPageEnabled:u,setPageDisabled:l}}function tn(e,t){return M((n,r)=>r.get(e.map(i=>({id:i,type:t}))),[e,t])}const nn=L.default.createContext(new V.ImageServiceLoader);function Ne(){return c.useContext(nn)}function rn(){const e=Ne(),[t,n]=c.useState({}),r=c.useRef(!1);return c.useEffect(()=>()=>{r.current=!0},[]),[c.useCallback((a,{height:o,width:s})=>{if(a){const l=a.id||a["@id"],u=e.loadServiceSync({id:l,width:a.width||s,height:a.height||o,source:a});u?a=u:t[l]||(r.current||n(d=>x(v({},d),{[l]:"loading"})),e.loadService({id:l,width:a.width||s,height:a.height||o}).then(()=>{r.current||n(d=>x(v({},d),{[l]:"done"}))}))}return a},[e,t]),t]}function on(e={}){const t=Ie(),n=k(e.canvasId?{id:e.canvasId}:void 0);return M((r,i)=>{if(!n)return[];if(t&&e.enableSingleAnnotation)return[t];const a=i.get(n.items),o=[];for(const s of a)o.push(...i.get(s.items));return o},[n])}function an(e,t=[]){const n=A(),r=on({enableSingleAnnotation:e==null?void 0:e.enableSingleAnnotation}),[i,a]=c.useState((e==null?void 0:e.defaultChoices)||[]),o=c.useMemo(()=>qt(n,r,i),[n,r,i,...t]),l={makeChoice:c.useCallback((u,{deselectOthers:d=!0,deselect:p=!1}={})=>{if(o.choice){if(o.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");a(g=>{if(p){const y=g.filter(P=>P!==u);if(y.length===0){const P=o.items[0].resource.id;return P?[P]:[]}return y}if(d)return[u];const h=[...g];if(h.length===0&&o.items.length){const y=o.items[0].resource.id;y&&h.push(y)}return g.indexOf(u)!==-1?g:[...g,u]})}},[o.choice])};return[o,l]}function sn(e,t,n){const r=[];for(const i of t.items){const a=i.resource&&i.resource.type==="SpecificResource"?i.resource.source:i.resource;if(!a.id)return w("No resource Identifier");let o;if(a.service){const y=V.getImageServices(a);y[0]&&(o=n(y[0],e))}const s={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},[l,u]=Fe(e,i.target);if(u.id!==e.id)continue;const d={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},p=i.resource.type==="SpecificResource"?F(i.resource):null,g=p&&p.selector&&(p.selector.type==="BoxSelector"||p.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:p.selector.spatial.x,y:p.selector.spatial.y,width:p.selector.spatial.width,height:p.selector.spatial.height}}:d;o&&!o.id&&(o.id=o["@id"]);const h={id:a.id,type:"Image",annotationId:i.annotationId,width:l?a.width:e.width,height:l?a.height:e.height,service:o,sizes:o&&o.sizes?o.sizes:a.width&&a.height?[{width:a.width,height:a.height}]:[],target:l&&l.type!=="PointSelector"?l:s,selector:g};r.push(h)}return{type:"images",image:r[0],images:r,choice:t.choice}}const cn=["model/gltf-binary"];function un(e,t){const r=t.items[0].resource;return r.format?cn.indexOf(r.format)===-1?w(`3D format: ${r.format} is unsupported`):{type:"3d-model",model:r}:w("Unknown format")}function ln(e,t){var r;if(!e.duration)return w("No duration on canvas");if(t.items.length>1)return w("Only one audio source supported");const n=(r=t.items[0])==null?void 0:r.resource;return n?n.format?{type:"media",media:{annotationId:t.items[0].annotationId,duration:e.duration,url:n.id,type:"Sound",target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:n.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}},annotations:{pages:[]}}:w("Audio does not have format"):w("Unknown audio")}function fn(e,t){var i;const n=t.items.filter(a=>a.type==="video");if(!e.duration)return w("No duration on canvas");if(n.length>1)return w("Only one video source supported");const r=(i=n[0])==null?void 0:i.resource;return r?r.format?{type:"media",media:{annotationId:t.items[0].annotationId,duration:e.duration,url:r.id,type:"Video",items:[],target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:r.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}},annotations:{pages:[]}}:w("Video does not have format"):w("Unknown video")}function Ue(e,t={},n){const r=e.language||n||"none";switch(e.type){case"TextualBody":{typeof e.value!="undefined"&&(t[r]=e.value);break}case"List":case"Composite":case"Choice":e.items&&e.items.forEach(i=>Ue(i,t,r))}return t}function dn(e,t){const n=[];return t.items.forEach(r=>{if(r.resource){const[i]=Fe(e,r.target);n.push({annotationId:r.annotationId,text:Ue(r.resource),target:i})}}),{type:"textual-content",items:n}}function pn(e){const t=se(),n=k(),r=A(),[i,a]=rn(),{enabledPageIds:o}=en((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(n==null?void 0:n.id),{all:!1}),s=tn(o,"AnnotationPage"),l=(e==null?void 0:e.strategies)||["empty","images","media","textual-content","complex-timeline"],[u,d]=an(e,[a]),p=c.useMemo(()=>{if(!n)return J;if(u.types.length===0)return l.indexOf("empty")!==-1?Kt(n.width,n.height):J;if(u.types.length!==1)if(u.types.length===2&&u.types.indexOf("text")!==-1)u.types=u.types.filter(h=>h!=="text");else return l.indexOf("complex-timeline")===-1?w("Complex timeline not supported"):w("ComplexTimelineStrategy not yet supported");const g=u.types[0];return g==="image"?l.indexOf("images")===-1?w("Image not supported"):sn(n,u,i):g==="Model"||g==="model"?l.indexOf("3d-model")===-1?w("3D not supported"):un(n,u):g==="textualbody"?l.indexOf("textual-content")===-1?w("Textual content not supported"):dn(n,u):g==="sound"||g==="audio"?l.indexOf("media")===-1?w("Media not supported"):ln(n,u):g==="video"?l.indexOf("media")===-1?w("Media not supported"):fn(n,u):J},[n,u,r,d.makeChoice]);return c.useMemo(()=>p.type==="unknown"?[p,Gt]:[x(v({},p),{annotations:{pages:s}}),d],[p,s])}const gn=(e,t=[])=>{const n=A();c.useEffect(()=>{e(n)},[n,...t])};function mn(e,t={}){const n=t.imageServiceLoader||new V.ImageServiceLoader;async function r(i,a,o,s=[],l){if(typeof i=="string")return{best:V.getFixedSizeFromImage(i),fallback:[],log:[]};const u=e.get(i);if(typeof u=="string")return{best:V.getFixedSizeFromImage(u),fallback:[],log:[]};switch(u.type){case"Annotation":{const d=u.body,p=e.get(d[0]);return l&&!p.width&&(p.width=l.width,p.height=l.height),await n.getThumbnailFromResource(p,a,o,s)}case"Canvas":{const d=u;if(d.thumbnail&&d.thumbnail.length){const p=e.get(d.thumbnail[0]),g=await n.getImageCandidates(p,o);g&&g.length&&s.push(...g)}return r(d.items[0],a,o,s,{width:d.width,height:d.height})}case"AnnotationPage":return r(u.items[0],a,o,s,l);case"Choice":return r(u.items[0],a,o,s,l);case"Collection":{const p=u.items[0];return r(p,a,o,s,l)}case"Manifest":{const p=u.items[0];return r(p,a,o,s,l)}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return l&&!u.width&&(u.width=l.width,u.height=l.height),n.getThumbnailFromResource(u,a,o,s);case"Service":case"Range":case"AnnotationCollection":case"CanvasReference":case"ContentResource":return{best:void 0,fallback:[],log:[]}}return{best:void 0,fallback:[],log:[]}}return{getBestThumbnailAtSize:r}}function hn(e,t,{canvasId:n,manifestId:r}={}){const i=A(),a=Ne(),o=c.useMemo(()=>mn(i,{imageServiceLoader:a}),[i,a]),[s,l]=c.useState(),u=se(r?{id:r}:void 0),d=k(n?{id:n}:void 0),p=d||u,g=c.useRef(!1);if(c.useEffect(()=>(g.current=!1,()=>{g.current=!0}),[]),!p)throw new Error("Must be called under a manifest or canvas context.");return gn(h=>{o.getBestThumbnailAtSize(p,e,t).then(y=>{y.best&&!g.current&&l(y.best)})},[p]),s}function yn(e){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:e}}function vn(e,t){switch(t.type){case"FINISHED":return x(v({},e),{isFinished:!0,isPlaying:!1,playRequested:!1});case"PLAY_PAUSE":return x(v({},e),{isFinished:!1,isPlaying:!e.isPlaying});case"PLAY_REQUESTED":return x(v({},e),{isFinished:!1,playRequested:!0});case"PAUSE":return x(v({},e),{isPlaying:!1});case"PLAY":return x(v({},e),{isFinished:!1,playRequested:!1,isPlaying:!0});case"MUTE":return x(v({},e),{isMuted:!0});case"SET_VOLUME":return x(v({},e),{volume:t.volume,isMuted:t.volume===0});case"TOGGLE_MUTE":return x(v({},e),{isMuted:!e.isMuted});case"UNMUTE":return x(v({},e),{isMuted:!1})}return e}function xn(e){const t=Math.round(e);return`${Math.floor(t/60)}:${`${t%60}`.padStart(2,"0")}`}function De(e){const[t,n]=c.useReducer(vn,yn(e.duration)),r=c.useRef(null),i=c.useRef(null),a=c.useRef(null),o=c.useRef(!1),s=c.useCallback(()=>{i.current&&r.current&&(i.current.innerHTML=xn(r.current.currentTime),a.current&&(a.current.style.width=`${r.current.currentTime/e.duration*100}%`),o.current!==r.current.muted&&(o.current=r.current.muted,n(r.current.muted?{type:"MUTE"}:{type:"UNMUTE"})))},[e.duration]),l=c.useCallback(()=>{r.current&&(n({type:"PLAY_REQUESTED"}),r.current.play().then(()=>{n({type:"PLAY"})}),s())},[s]),u=c.useCallback(()=>{r.current&&(r.current.duration>0&&r.current.paused?l():d())},[s]),d=c.useCallback(()=>{r.current&&(r.current.pause(),n({type:"PAUSE"}),s())},[s]),p=c.useCallback(()=>{r.current&&(r.current.muted=!r.current.muted,n(r.current.muted?{type:"MUTE"}:{type:"UNMUTE"}))},[]),g=c.useCallback(()=>{r.current&&(r.current.muted=!0,n({type:"MUTE"}))},[]),h=c.useCallback(()=>{r.current&&(r.current.muted=!1,n({type:"UNMUTE"}))},[]),y=c.useCallback(E=>{r.current&&(r.current.muted=!1,r.current.volume=E/100,n({type:"SET_VOLUME",volume:E}))},[]),P=c.useCallback(E=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(E*e.duration,e.duration)),s())},[]),S=c.useCallback(E=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(E,e.duration)),s())},[]);return c.useEffect(()=>{const E=setInterval(()=>{s()},350);return()=>clearInterval(E)},[s,e.duration]),c.useEffect(()=>{const E=()=>{n({type:"FINISHED"})},m=r.current;return m==null||m.addEventListener("ended",E),()=>m==null?void 0:m.removeEventListener("ended",E)},[]),[{element:r,currentTime:i,progress:a},t,{play:l,pause:d,playPause:u,mute:g,unmute:h,toggleMute:p,setVolume:y,setDurationPercent:P,setTime:S}]}const Sn=c.createContext(null),bn=c.createContext(null),En=c.createContext(null);function Ve({actions:e,state:t,children:n,currentTime:r,progress:i,element:a}){return f.jsx(En.Provider,{value:{currentTime:r,progress:i,element:a},children:f.jsx(bn.Provider,{value:e,children:f.jsx(Sn.Provider,{value:t,children:n})})})}function Pn({media:e,children:t}){const[{element:n,currentTime:r,progress:i},a,o]=De({duration:e.duration});return f.jsx(f.Fragment,{children:f.jsx(H,{children:f.jsxs(Ve,{state:a,actions:o,currentTime:r,progress:i,element:n,children:[f.jsx("audio",{ref:n,src:e.url}),t]})})})}function wn({media:e,children:t}){const[{element:n,currentTime:r,progress:i},a,o]=De({duration:e.duration}),s="div";return f.jsxs(f.Fragment,{children:[f.jsxs(H,{overlay:!0,children:[f.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
- `}),f.jsx(s,{className:"video-container",part:"video-container",onClick:()=>o.playPause(),children:f.jsx("video",{ref:n,src:e.url,style:{width:"100%",objectFit:"contain"}})})]}),f.jsx(H,{children:f.jsx(De,{state:a,actions:o,currentTime:r,progress:i,element:n,children:t})})]})}function Cn({model:e}){return f.jsxs(H,{overlay:!0,children:[f.jsx("style",{children:`
14
+ `}),f.jsx(s,{className:"video-container",part:"video-container",onClick:()=>o.playPause(),children:f.jsx("video",{ref:n,src:e.url,style:{width:"100%",objectFit:"contain"}})})]}),f.jsx(H,{children:f.jsx(Ve,{state:a,actions:o,currentTime:r,progress:i,element:n,children:t})})]})}function Cn({model:e}){return f.jsxs(H,{overlay:!0,children:[f.jsx("style",{children:`
15
15
  .model-container {
16
16
  position: absolute;
17
17
  top: 0;
@@ -24,7 +24,7 @@
24
24
  justify-content: center;
25
25
  pointer-events: visible;
26
26
  }
27
- `}),f.jsx("div",{className:"model-container",children:f.jsx("model-viewer",{"interaction-prompt":"none",style:{width:"100%",height:"100%"},"camera-controls":"","ar-status":"not-presenting",src:e.id})})]})}function Ve({style:e}){const t=F();return!t||!t.height||!t.width?null:f.jsx("box",{interactive:!1,target:{x:0,y:0,width:t.width,height:t.height},style:e})}var Tn=Object.defineProperty,On=Object.defineProperties,An=Object.getOwnPropertyDescriptors,Y=Object.getOwnPropertySymbols,Be=Object.prototype.hasOwnProperty,He=Object.prototype.propertyIsEnumerable,Se=(e,t,n)=>t in e?Tn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,I=(e,t)=>{for(var n in t||(t={}))Be.call(t,n)&&Se(e,n,t[n]);if(Y)for(var n of Y(t))He.call(t,n)&&Se(e,n,t[n]);return e},Q=(e,t)=>On(e,An(t)),$e=(e,t)=>{var n={};for(var r in e)Be.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Y)for(var r of Y(e))t.indexOf(r)<0&&He.call(e,r)&&(n[r]=e[r]);return n};function Rn(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Mn(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Ee(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _n(e,t,n){return t&&Ee(e.prototype,t),n&&Ee(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}var jn={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},In,Ln=L.default.createContext();function Fn(){return jn}var kn=function(){function e(){Mn(this,e),this.usedNamespaces={}}return _n(e,[{key:"addUsedNamespaces",value:function(n){var r=this;n.forEach(function(i){r.usedNamespaces[i]||(r.usedNamespaces[i]=!0)})}},{key:"getUsedNamespaces",value:function(){return Object.keys(this.usedNamespaces)}}]),e}();function Nn(){return In}function Un(){if(console&&console.warn){for(var e,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];typeof n[0]=="string"&&(n[0]="react-i18next:: ".concat(n[0])),(e=console).warn.apply(e,n)}}var be={};function re(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];typeof t[0]=="string"&&be[t[0]]||(typeof t[0]=="string"&&(be[t[0]]=new Date),Un.apply(void 0,t))}function Pe(e,t,n){e.loadNamespaces(t,function(){if(e.isInitialized)n();else{var r=function i(){setTimeout(function(){e.off("initialized",i)},0),n()};e.on("initialized",r)}})}function Dn(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(!t.languages||!t.languages.length)return re("i18n.languages were undefined or empty",t.languages),!0;var r=t.languages[0],i=t.options?t.options.fallbackLng:!1,a=t.languages[t.languages.length-1];if(r.toLowerCase()==="cimode")return!0;var o=function(l,u){var d=t.services.backendConnector.state["".concat(l,"|").concat(u)];return d===-1||d===2};return n.bindI18n&&n.bindI18n.indexOf("languageChanging")>-1&&t.services.backendConnector.backend&&t.isLanguageChangingTo&&!o(t.isLanguageChangingTo,e)?!1:!!(t.hasResourceBundle(r,e)||!t.services.backendConnector.backend||o(r,e)&&(!i||o(a,e)))}function Vn(e){if(Array.isArray(e))return e}function Bn(e,t){var n=e==null?null:typeof Symbol!="undefined"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r=[],i=!0,a=!1,o,s;try{for(n=n.call(e);!(i=(o=n.next()).done)&&(r.push(o.value),!(t&&r.length===t));i=!0);}catch(l){a=!0,s=l}finally{try{!i&&n.return!=null&&n.return()}finally{if(a)throw s}}return r}}function we(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function Hn(e,t){if(!!e){if(typeof e=="string")return we(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return we(e,t)}}function $n(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
28
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function zn(e,t){return Vn(e)||Bn(e,t)||Hn(e,t)||$n()}function Ce(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function Z(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?Ce(Object(n),!0).forEach(function(r){Rn(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ce(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function ze(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=t.i18n,r=c.useContext(Ln)||{},i=r.i18n,a=r.defaultNS,o=n||i||Nn();if(o&&!o.reportNamespaces&&(o.reportNamespaces=new kn),!o){re("You will need to pass in an i18next instance by using initReactI18next");var s=function(O){return Array.isArray(O)?O[O.length-1]:O},l=[s,{},!1];return l.t=s,l.i18n={},l.ready=!1,l}o.options.react&&o.options.react.wait!==void 0&&re("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");var u=Z(Z(Z({},Fn()),o.options.react),t),d=u.useSuspense,p=u.keyPrefix,g=e||a||o.options&&o.options.defaultNS;g=typeof g=="string"?[g]:g||["translation"],o.reportNamespaces.addUsedNamespaces&&o.reportNamespaces.addUsedNamespaces(g);var h=(o.isInitialized||o.initializedStoreOnce)&&g.every(function(R){return Dn(R,o,u)});function y(){return o.getFixedT(null,u.nsMode==="fallback"?g:g[0],p)}var P=c.useState(y),S=zn(P,2),b=S[0],m=S[1],_=c.useRef(!0);c.useEffect(function(){var R=u.bindI18n,O=u.bindI18nStore;_.current=!0,!h&&!d&&Pe(o,g,function(){_.current&&m(y)});function j(){_.current&&m(y)}return R&&o&&o.on(R,j),O&&o&&o.store.on(O,j),function(){_.current=!1,R&&o&&R.split(" ").forEach(function(E){return o.off(E,j)}),O&&o&&O.split(" ").forEach(function(E){return o.store.off(E,j)})}},[o,g.join()]);var N=c.useRef(!0);c.useEffect(function(){_.current&&!N.current&&m(y),N.current=!1},[o]);var T=[b,o,h];if(T.t=b,T.i18n=o,T.ready=h,h||!h&&!d)return T;throw new Promise(function(R){Pe(o,g,function(){R()})})}function Yn(e){var t=e,{as:n,language:r,children:i}=t,a=$e(t,["as","language","children"]);const{i18n:o}=ze(),s=c.useMemo(()=>o.dir?o.dir(r):"ltr",[r]);return c.useMemo(()=>o.services?o.services.languageUtils.getLanguagePartFromCode(o.language)===o.services.languageUtils.getLanguagePartFromCode(r):!1,[o.language,r])?n?f.jsx(n,x(v({},I({},a)),{children:i})):f.jsx("span",x(v({},I({},a)),{children:i})):n?f.jsx(n,x(v({},Q(I({},a),{lang:r,dir:s})),{children:i})):f.jsx("span",x(v({},Q(I({},a),{lang:r,dir:s})),{children:i}))}function Ye(e,t,n=[],r=!1){if(!e||!t||t.length===0)return;if(t.length===1)return t[0];if(t.indexOf(e)!==-1)return e;const i=e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):null;if(i&&t.indexOf(i)!==-1)return i;for(const a of n)if(t.indexOf(a)!==-1)return a;if(!r){const o=t.map(s=>s.indexOf("-")!==-1?s.slice(0,s.indexOf("-")):null).indexOf(e);if(o!==-1)return t[o];for(const s of n){const l=s.indexOf("-")!==-1?s.slice(0,s.indexOf("-")):null,u=l?t.indexOf(l):-1;if(u!==-1)return t[u]}}return t.indexOf("none")!==-1?"none":t.indexOf("@none")!==-1?"@none":t[0]}function Qn(e,t,n={}){const{strictFallback:r=!1,defaultText:i="",separator:a=`
29
- `,fallbackLanguages:o=[],closest:s}=n,l=Object.keys(e||{}),u=s?t:Ye(t,l,o,r);if(!e)return i;if(typeof e=="string")return e;const d=u?e[u]:void 0;return d?typeof d=="string"?d:d.join(a):""}function qn(e,t=[]){const{i18n:n}=ze(),r=n&&n.languages?n.languages:[],i=n&&n.language?n.language:"en";return c.useMemo(()=>{const a=e();return Ye(i,a,r)},[r,i,...t])}function Gn(e,t){const n=qn(()=>Object.keys(e||{}),[e]);return[c.useMemo(()=>Qn(e,n,{defaultText:t,closest:!0}),[n,t,e]),n]}const Kn=e=>{var t=e,{as:n,defaultText:r,enableDangerouslySetInnerHTML:i,children:a}=t,o=$e(t,["as","defaultText","enableDangerouslySetInnerHTML","children"]);const[s,l]=Gn(a,r);return l?f.jsx(Yn,x(v({},Q(I({},o),{as:n,language:l,title:i?void 0:s,dangerouslySetInnerHTML:i?{__html:s}:void 0})),{children:i?void 0:s})):n?f.jsx(n,x(v({},I({},o)),{children:s})):f.jsx("span",x(v({},Q(I({},o),{title:i?void 0:s,dangerouslySetInnerHTML:i?{__html:s}:void 0})),{children:i?void 0:s}))};function Qe({x:e,y:t,onChoiceChange:n,registerActions:r,defaultChoices:i,isStatic:a,renderViewerControls:o,renderMediaControls:s,strategies:l,backgroundStyle:u,alwaysShowBackground:d,onClickPaintingAnnotation:p,children:g}){const h=F(),y=_e(h,["deep-zoom"]),[P]=jt(),S=A(),b=c.useMemo(()=>je(S),[S]),[m,_]=pn({strategies:l||["images"],defaultChoices:i==null?void 0:i.map(({id:E})=>E)}),N=m.type==="images"?m.choice:void 0;c.useEffect(()=>{r&&r(_)},[m.annotations]),c.useEffect(()=>{if(i)for(const E of i)typeof E.opacity!="undefined"&&b.applyStyles({id:E.id},"atlas",{opacity:E.opacity})},[i]),c.useLayoutEffect(()=>{n&&n(N)},[N]);const T=hn({maxWidth:256,maxHeight:256});if(!h)return null;const R=h.accompanyingCanvas,O=T&&T.type==="fixed"?f.jsx("world-object",{height:h.height,width:h.width,x:e,y:t,children:f.jsx("world-image",{uri:T.id,target:{x:0,y:0,width:h.width,height:h.height},display:T.width&&T.height?{width:T.width,height:T.height}:void 0})}):null;if(m.type==="unknown"){if(O)return O;throw new Error(m.reason||"Unknown image strategy")}const j=f.jsxs(c.Fragment,{children:[P?f.jsx(ne,{page:P}):null,m.annotations&&m.annotations.pages?m.annotations.pages.map(E=>f.jsx(ne,{page:E},E.id)):null,g]});return f.jsxs(f.Fragment,{children:[f.jsxs("world-object",x(v({height:h.height,width:h.width,x:e,y:t},y),{children:[m.type==="empty"||d?f.jsx(Ve,{style:u}):null,m.type==="textual-content"?m.items.map((E,G)=>f.jsxs(f.Fragment,{children:[f.jsx(B.HTMLPortal,{onClick:p?U=>{U.stopPropagation(),p(E.annotationId,E,U)}:void 0,target:E.target.spatial||void 0,children:f.jsx(Kn,{children:E.text})},G),j]})):null,m.type==="images"?f.jsxs(f.Fragment,{children:[m.images.map((E,G)=>f.jsx(Le,{isStatic:a,image:E,id:E.id,thumbnail:G===0?T:void 0,onClick:p?U=>{U.stopPropagation(),p(E.annotationId,E,U)}:void 0},E.id)),j]}):null,(m.type==="images"||m.type==="empty"||m.type==="textual-content")&&o?f.jsx(H,{overlay:!0,children:o(m)}):null,m.type==="3d-model"?f.jsx(Cn,{model:m.model}):null,m.type==="media"?f.jsx(f.Fragment,{children:m.media.type==="Sound"?f.jsxs(Pn,{media:m.media,children:[O,s?s(m):null]}):m.media.type==="Video"?f.jsxs(wn,{media:m.media,children:[O,s?s(m):null]}):null}):null]}),`${h.id}/${m.type}`),m.type==="media"&&m.media.type==="Sound"&&R?f.jsx(ot,{canvas:R.id,children:f.jsx(Qe,{renderViewerControls:o})}):null]})}const Wn={RenderImage:Le,RenderCanvas:Qe,RenderAnnotationPage:ne,RenderAnnotation:Ie,Viewer:kt,CanvasBackground:Ve};exports.CanvasPanel=Wn;
27
+ `}),f.jsx("div",{className:"model-container",children:f.jsx("model-viewer",{"interaction-prompt":"none",style:{width:"100%",height:"100%"},"camera-controls":"","ar-status":"not-presenting",src:e.id})})]})}function Be({style:e}){const t=k();return!t||!t.height||!t.width?null:f.jsx("box",{interactive:!1,target:{x:0,y:0,width:t.width,height:t.height},style:e})}var Tn=Object.defineProperty,On=Object.defineProperties,An=Object.getOwnPropertyDescriptors,Y=Object.getOwnPropertySymbols,He=Object.prototype.hasOwnProperty,$e=Object.prototype.propertyIsEnumerable,Se=(e,t,n)=>t in e?Tn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,I=(e,t)=>{for(var n in t||(t={}))He.call(t,n)&&Se(e,n,t[n]);if(Y)for(var n of Y(t))$e.call(t,n)&&Se(e,n,t[n]);return e},Q=(e,t)=>On(e,An(t)),ze=(e,t)=>{var n={};for(var r in e)He.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Y)for(var r of Y(e))t.indexOf(r)<0&&$e.call(e,r)&&(n[r]=e[r]);return n};function Rn(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Mn(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function be(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _n(e,t,n){return t&&be(e.prototype,t),n&&be(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}var jn={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},In,Ln=L.default.createContext();function kn(){return jn}var Fn=function(){function e(){Mn(this,e),this.usedNamespaces={}}return _n(e,[{key:"addUsedNamespaces",value:function(n){var r=this;n.forEach(function(i){r.usedNamespaces[i]||(r.usedNamespaces[i]=!0)})}},{key:"getUsedNamespaces",value:function(){return Object.keys(this.usedNamespaces)}}]),e}();function Nn(){return In}function Un(){if(console&&console.warn){for(var e,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];typeof n[0]=="string"&&(n[0]="react-i18next:: ".concat(n[0])),(e=console).warn.apply(e,n)}}var Ee={};function re(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];typeof t[0]=="string"&&Ee[t[0]]||(typeof t[0]=="string"&&(Ee[t[0]]=new Date),Un.apply(void 0,t))}function Pe(e,t,n){e.loadNamespaces(t,function(){if(e.isInitialized)n();else{var r=function i(){setTimeout(function(){e.off("initialized",i)},0),n()};e.on("initialized",r)}})}function Dn(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(!t.languages||!t.languages.length)return re("i18n.languages were undefined or empty",t.languages),!0;var r=t.languages[0],i=t.options?t.options.fallbackLng:!1,a=t.languages[t.languages.length-1];if(r.toLowerCase()==="cimode")return!0;var o=function(l,u){var d=t.services.backendConnector.state["".concat(l,"|").concat(u)];return d===-1||d===2};return n.bindI18n&&n.bindI18n.indexOf("languageChanging")>-1&&t.services.backendConnector.backend&&t.isLanguageChangingTo&&!o(t.isLanguageChangingTo,e)?!1:!!(t.hasResourceBundle(r,e)||!t.services.backendConnector.backend||o(r,e)&&(!i||o(a,e)))}function Vn(e){if(Array.isArray(e))return e}function Bn(e,t){var n=e==null?null:typeof Symbol!="undefined"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r=[],i=!0,a=!1,o,s;try{for(n=n.call(e);!(i=(o=n.next()).done)&&(r.push(o.value),!(t&&r.length===t));i=!0);}catch(l){a=!0,s=l}finally{try{!i&&n.return!=null&&n.return()}finally{if(a)throw s}}return r}}function we(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function Hn(e,t){if(!!e){if(typeof e=="string")return we(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return we(e,t)}}function $n(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
28
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function zn(e,t){return Vn(e)||Bn(e,t)||Hn(e,t)||$n()}function Ce(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function Z(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?Ce(Object(n),!0).forEach(function(r){Rn(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ce(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function Ye(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=t.i18n,r=c.useContext(Ln)||{},i=r.i18n,a=r.defaultNS,o=n||i||Nn();if(o&&!o.reportNamespaces&&(o.reportNamespaces=new Fn),!o){re("You will need to pass in an i18next instance by using initReactI18next");var s=function(O){return Array.isArray(O)?O[O.length-1]:O},l=[s,{},!1];return l.t=s,l.i18n={},l.ready=!1,l}o.options.react&&o.options.react.wait!==void 0&&re("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");var u=Z(Z(Z({},kn()),o.options.react),t),d=u.useSuspense,p=u.keyPrefix,g=e||a||o.options&&o.options.defaultNS;g=typeof g=="string"?[g]:g||["translation"],o.reportNamespaces.addUsedNamespaces&&o.reportNamespaces.addUsedNamespaces(g);var h=(o.isInitialized||o.initializedStoreOnce)&&g.every(function(R){return Dn(R,o,u)});function y(){return o.getFixedT(null,u.nsMode==="fallback"?g:g[0],p)}var P=c.useState(y),S=zn(P,2),E=S[0],m=S[1],_=c.useRef(!0);c.useEffect(function(){var R=u.bindI18n,O=u.bindI18nStore;_.current=!0,!h&&!d&&Pe(o,g,function(){_.current&&m(y)});function j(){_.current&&m(y)}return R&&o&&o.on(R,j),O&&o&&o.store.on(O,j),function(){_.current=!1,R&&o&&R.split(" ").forEach(function(b){return o.off(b,j)}),O&&o&&O.split(" ").forEach(function(b){return o.store.off(b,j)})}},[o,g.join()]);var N=c.useRef(!0);c.useEffect(function(){_.current&&!N.current&&m(y),N.current=!1},[o]);var T=[E,o,h];if(T.t=E,T.i18n=o,T.ready=h,h||!h&&!d)return T;throw new Promise(function(R){Pe(o,g,function(){R()})})}function Yn(e){var t=e,{as:n,language:r,children:i}=t,a=ze(t,["as","language","children"]);const{i18n:o}=Ye(),s=c.useMemo(()=>o.dir?o.dir(r):"ltr",[r]);return c.useMemo(()=>o.services?o.services.languageUtils.getLanguagePartFromCode(o.language)===o.services.languageUtils.getLanguagePartFromCode(r):!1,[o.language,r])?n?f.jsx(n,x(v({},I({},a)),{children:i})):f.jsx("span",x(v({},I({},a)),{children:i})):n?f.jsx(n,x(v({},Q(I({},a),{lang:r,dir:s})),{children:i})):f.jsx("span",x(v({},Q(I({},a),{lang:r,dir:s})),{children:i}))}function Qe(e,t,n=[],r=!1){if(!e||!t||t.length===0)return;if(t.length===1)return t[0];if(t.indexOf(e)!==-1)return e;const i=e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):null;if(i&&t.indexOf(i)!==-1)return i;for(const a of n)if(t.indexOf(a)!==-1)return a;if(!r){const o=t.map(s=>s.indexOf("-")!==-1?s.slice(0,s.indexOf("-")):null).indexOf(e);if(o!==-1)return t[o];for(const s of n){const l=s.indexOf("-")!==-1?s.slice(0,s.indexOf("-")):null,u=l?t.indexOf(l):-1;if(u!==-1)return t[u]}}return t.indexOf("none")!==-1?"none":t.indexOf("@none")!==-1?"@none":t[0]}function Qn(e,t,n={}){const{strictFallback:r=!1,defaultText:i="",separator:a=`
29
+ `,fallbackLanguages:o=[],closest:s}=n,l=Object.keys(e||{}),u=s?t:Qe(t,l,o,r);if(!e)return i;if(typeof e=="string")return e;const d=u?e[u]:void 0;return d?typeof d=="string"?d:d.join(a):""}function qn(e,t=[]){const{i18n:n}=Ye(),r=n&&n.languages?n.languages:[],i=n&&n.language?n.language:"en";return c.useMemo(()=>{const a=e();return Qe(i,a,r)},[r,i,...t])}function Gn(e,t){const n=qn(()=>Object.keys(e||{}),[e]);return[c.useMemo(()=>Qn(e,n,{defaultText:t,closest:!0}),[n,t,e]),n]}const Kn=e=>{var t=e,{as:n,defaultText:r,enableDangerouslySetInnerHTML:i,children:a}=t,o=ze(t,["as","defaultText","enableDangerouslySetInnerHTML","children"]);const[s,l]=Gn(a,r);return l?f.jsx(Yn,x(v({},Q(I({},o),{as:n,language:l,title:i?void 0:s,dangerouslySetInnerHTML:i?{__html:s}:void 0})),{children:i?void 0:s})):n?f.jsx(n,x(v({},I({},o)),{children:s})):f.jsx("span",x(v({},Q(I({},o),{title:i?void 0:s,dangerouslySetInnerHTML:i?{__html:s}:void 0})),{children:i?void 0:s}))};function qe({x:e,y:t,onChoiceChange:n,registerActions:r,defaultChoices:i,isStatic:a,renderViewerControls:o,renderMediaControls:s,strategies:l,backgroundStyle:u,alwaysShowBackground:d,onClickPaintingAnnotation:p,children:g}){const h=k(),y=_e(h,["deep-zoom"]),[P]=It(),S=A(),E=c.useMemo(()=>je(S),[S]),[m,_]=pn({strategies:l||["images"],defaultChoices:i==null?void 0:i.map(({id:b})=>b)}),N=m.type==="images"?m.choice:void 0;c.useEffect(()=>{r&&r(_)},[m.annotations]),c.useEffect(()=>{if(i)for(const b of i)typeof b.opacity!="undefined"&&E.applyStyles({id:b.id},"atlas",{opacity:b.opacity})},[i]),c.useLayoutEffect(()=>{n&&n(N)},[N]);const T=hn({maxWidth:256,maxHeight:256});if(!h)return null;const R=h.accompanyingCanvas,O=T&&T.type==="fixed"?f.jsx("world-object",{height:h.height,width:h.width,x:e,y:t,children:f.jsx("world-image",{uri:T.id,target:{x:0,y:0,width:h.width,height:h.height},display:T.width&&T.height?{width:T.width,height:T.height}:void 0})}):null;if(m.type==="unknown"){if(O)return O;throw new Error(m.reason||"Unknown image strategy")}const j=f.jsxs(c.Fragment,{children:[P?f.jsx(ne,{page:P}):null,m.annotations&&m.annotations.pages?m.annotations.pages.map(b=>f.jsx(ne,{page:b},b.id)):null,g]});return f.jsxs(f.Fragment,{children:[f.jsxs("world-object",x(v({height:h.height,width:h.width,x:e,y:t},y),{children:[m.type==="empty"||d?f.jsx(Be,{style:u}):null,m.type==="textual-content"?m.items.map((b,G)=>f.jsxs(f.Fragment,{children:[f.jsx(B.HTMLPortal,{onClick:p?U=>{U.stopPropagation(),p(b.annotationId,b,U)}:void 0,target:b.target.spatial||void 0,children:f.jsx(Kn,{children:b.text})},G),j]})):null,m.type==="images"?f.jsxs(f.Fragment,{children:[m.images.map((b,G)=>f.jsx(ke,{isStatic:a,image:b,id:b.id,thumbnail:G===0?T:void 0,onClick:p?U=>{U.stopPropagation(),p(b.annotationId,b,U)}:void 0},b.id)),j]}):null,(m.type==="images"||m.type==="empty"||m.type==="textual-content")&&o?f.jsx(H,{overlay:!0,children:o(m)}):null,m.type==="3d-model"?f.jsx(Cn,{model:m.model}):null,m.type==="media"?f.jsx(f.Fragment,{children:m.media.type==="Sound"?f.jsxs(Pn,{media:m.media,children:[O,s?s(m):null]}):m.media.type==="Video"?f.jsxs(wn,{media:m.media,children:[O,s?s(m):null]}):null}):null]}),`${h.id}/${m.type}`),m.type==="media"&&m.media.type==="Sound"&&R?f.jsx(it,{canvas:R.id,children:f.jsx(qe,{renderViewerControls:o})}):null]})}const Wn={RenderImage:ke,RenderCanvas:qe,RenderAnnotationPage:ne,RenderAnnotation:Le,Viewer:Nt,CanvasBackground:Be};exports.CanvasPanel=Wn;
30
30
  //# sourceMappingURL=canvas-panel.js.map