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