react-iiif-vault 0.9.0 → 0.9.4

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/dist/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var l=require("react"),K=require("@iiif/vault"),X=require("react-query"),D=require("@atlas-viewer/iiif-image-api"),F=require("@iiif/vault-helpers");function je(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var g=je(l),Le=Object.defineProperty,Y=Object.getOwnPropertySymbols,Be=Object.prototype.hasOwnProperty,De=Object.prototype.propertyIsEnumerable,Z=(e,t,n)=>t in e?Le(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ee=(e,t)=>{for(var n in t||(t={}))Be.call(t,n)&&Z(e,n,t[n]);if(Y)for(var n of Y(t))De.call(t,n)&&Z(e,n,t[n]);return e};const Fe={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},k=g.default.createContext(Fe),R=()=>l.useContext(k),V=({value:e,children:t})=>{const n=R(),r=l.useMemo(()=>ee(ee({},n),e),[e,n]);return g.default.createElement(k.Provider,{value:r},t)},ke=({annotation:e,children:t})=>g.default.createElement(V,{value:{annotation:e}},t),te=({canvas:e,children:t})=>g.default.createElement(V,{value:{canvas:e}},t),Ne=({collection:e,children:t})=>g.default.createElement(V,{value:{collection:e}},t),ne=({manifest:e,children:t})=>g.default.createElement(V,{value:{manifest:e}},t),qe=({range:e,children:t})=>g.default.createElement(V,{value:{range:e}},t),N=g.default.createContext({vault:null,setVaultInstance:e=>{}}),re=({vault:e,vaultOptions:t,resources:n,children:r})=>{const[i,s]=l.useState(()=>e||(t?new K.Vault(t):new K.Vault));return g.default.createElement(N.Provider,{value:{vault:i,setVaultInstance:s}},g.default.createElement(V,{value:n||{}},r))},_=()=>{const{vault:e}=l.useContext(N);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var ze=Object.defineProperty,oe=Object.getOwnPropertySymbols,He=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable,ae=(e,t,n)=>t in e?ze(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ue=(e,t)=>{for(var n in t||(t={}))He.call(t,n)&&ae(e,n,t[n]);if(oe)for(var n of oe(t))Qe.call(t,n)&&ae(e,n,t[n]);return e},We=(e,t,n)=>new Promise((r,i)=>{var s=a=>{try{o(n.next(a))}catch(u){i(u)}},c=a=>{try{o(n.throw(a))}catch(u){i(u)}},o=a=>a.done?r(a.value):Promise.resolve(a.value).then(s,c);o((n=n.apply(e,t)).next())});const se=(e,t={})=>{const n=_(),[r,i]=l.useState(e),s=l.useMemo(()=>n.get(e)||void 0,[e,n]),{data:c,error:o}=X.useQuery(["manifest",e],()=>We(void 0,null,function*(){const a=s||(yield n.load(e));return a&&r!==a.id&&i(a.id),a}),Ue({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,retry:!1,initialData:s},t));return{isLoaded:!!c,id:r,error:o,manifest:c}};function b(e,t=[]){const n=_(),[r,i]=l.useState(()=>e(n.getState(),n));return l.useEffect(()=>n.subscribe(s=>e(s,n),s=>{i(s)},!0),t),r}const j=g.default.createContext([]);function ie(){const e=l.useContext(j);return b(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}const q=()=>{},L=l.createContext({setCurrentCanvasId:q,setCurrentCanvasIndex:q,nextCanvas:q,previousCanvas:q,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),Xe=e=>{const t=se(e.manifest),[n,r]=l.useState(""),[i,s]=l.useState([]),c=t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");l.useEffect(()=>{var f,d;t.manifest&&(r((f=t.manifest.items[0])==null?void 0:f.id),s([(d=t.manifest.items[0])==null?void 0:d.id]))},[t.manifest,e.manifest]);const o=l.useMemo(()=>{var f;return((f=t.manifest)==null?void 0:f.items.map(d=>d.id))||[]},[t.manifest,e.manifest]),a=l.useMemo(()=>o.indexOf(n),[o,n]),u=l.useCallback(()=>{if(o.length&&n){if(a===-1||(o[a+2]?a+2===o.length:a===o.length))return;const f=c&&a!==0?o[a+2]:o[a+1],d=c?a!==0?o[a+3]:o[a+2]:null;f&&(r(f),s(d?[f,d]:[f]))}},[c,o,n,a]),h=l.useCallback(()=>{if(o.length&&n){if(a===0||a===-1)return;const f=c&&a!==1?o[a-2]:o[a-1],d=c&&a!==1?o[a-1]:null;f&&(r(f),s(d?[f,d]:[f]))}},[c,o,n,a]),p=l.useCallback(f=>{const d=c&&f%2===1?f-1:f,w=o[d],P=c&&d!==0?o[d+1]:null;w&&(r(w),s(v=>{const m=P?[w,P]:[w];if(v.length===v.length){for(let y=0;y<v.length;y++)if(v[y]!==m[y])return m;return v}return m}))},[c,o]),O=l.useCallback(f=>{const d=o.indexOf(f);d!==-1&&p(d)},[o,p]),I=l.useMemo(()=>({setCurrentCanvasId:O,nextCanvas:u,previousCanvas:h,currentCanvasIndex:a,totalCanvases:o.length,setCurrentCanvasIndex:p,pagingView:!0}),[u,h,a,o,p,O]);return!t.isLoaded||!t.manifest?g.default.createElement("div",null,"Loading..."):g.default.createElement(L.Provider,{value:I},g.default.createElement(j.Provider,{value:i},g.default.createElement(ne,{manifest:t.manifest.id},g.default.createElement(te,{canvas:n},e.children))))};function Ge(){return l.useContext(L)}function Je(){return{VaultContext:l.useContext(N),ResourceContext:l.useContext(k),SimpleViewerReactContext:l.useContext(L),VisibleCanvasReactContext:l.useContext(j)}}const Ke=e=>g.default.createElement(re,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},g.default.createElement(j.Provider,{value:e.bridge.VisibleCanvasReactContext},g.default.createElement(L.Provider,{value:e.bridge.SimpleViewerReactContext},e.children))),ce=g.default.createContext(new D.ImageServiceLoader);function z(){return l.useContext(ce)}const Ye=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,Ze=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function H(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:r,selectors:i}=H(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?H({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",startTime:e.t};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=Ye.exec(e.value);if(t){const r={type:"BoxSelector",unit:t[2]==="percent:"?"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(Ze);if(n){const r={type:"TemporalSelector",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:[]}}var et=Object.defineProperty,tt=Object.defineProperties,nt=Object.getOwnPropertyDescriptors,le=Object.getOwnPropertySymbols,rt=Object.prototype.hasOwnProperty,ot=Object.prototype.propertyIsEnumerable,ue=(e,t,n)=>t in e?et(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,fe=(e,t)=>{for(var n in t||(t={}))rt.call(t,n)&&ue(e,n,t[n]);if(le)for(var n of le(t))ot.call(t,n)&&ue(e,n,t[n]);return e},de=(e,t)=>tt(e,nt(t));function E(e,t={}){if(Array.isArray(e))return E(e[0]);if(typeof e=="string"){const[n,r]=e.split("#");return r?E({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 E(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?H(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?E({type:"SpecificResource",source:de(fe({},e),{id:n}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:de(fe({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}var at=Object.defineProperty,st=Object.defineProperties,it=Object.getOwnPropertyDescriptors,pe=Object.getOwnPropertySymbols,ct=Object.prototype.hasOwnProperty,lt=Object.prototype.propertyIsEnumerable,ve=(e,t,n)=>t in e?at(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ut=(e,t)=>{for(var n in t||(t={}))ct.call(t,n)&&ve(e,n,t[n]);if(pe)for(var n of pe(t))lt.call(t,n)&&ve(e,n,t[n]);return e},ft=(e,t)=>st(e,it(t));function dt(e={},t=[]){const{id:n,selector:r}=e,i=R(),s=_(),c=n||i.annotation,o=b(u=>c?u.iiif.entities.Annotation[c]:void 0,[c]),a=b(u=>o&&o.body?o.body.map(h=>h?u.iiif.entities[h.type][h.id]:null).filter(Boolean):[],[o]);return l.useMemo(()=>{if(!o)return;const u=ft(ut({},o),{body:a,target:E(o.target,{typeMap:s.getState().iiif.mapping})});return r?r(u):u},[o,r,a,...t])}function B(e={},t=[]){const{id:n,selector:r}=e,i=R(),s=_(),c=n||i.manifest,o=c?s.select(a=>a.iiif.entities.Manifest[c]):void 0;return l.useMemo(()=>{if(!!o)return r?r(o):o},[o,r,...t])}function T(e={},t=[]){const{id:n,selector:r}=e,i=R(),s=_(),c=n||i.canvas,o=c?s.select(a=>a.iiif.entities.Canvas[c]):void 0;return l.useMemo(()=>{if(!!o)return r?r(o):o},[o,r,...t])}function pt(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function vt(e,t){return b(n=>{const r=[];if(!e)return r;const i=Object.keys(n.iiif.entities.AnnotationPage);for(const s of i)if(!t||t.indexOf(s)!==-1){const c=pt(n,s);c&&c.views&&c.views[e]&&r.push(s)}return r},[e])}function me({canvas:e,manifest:t,all:n,canvases:r}){const i=[];if(t)for(const s of t.annotations)i.indexOf(s.id)===-1&&i.push(s.id);if(n){if(r&&r.length)for(const s of r)for(const c of s.annotations)i.indexOf(c.id)===-1&&i.push(c.id)}else if(e)for(const s of e.annotations)i.indexOf(s.id)===-1&&i.push(s.id);return i}var mt=Object.defineProperty,ht=Object.defineProperties,gt=Object.getOwnPropertyDescriptors,he=Object.getOwnPropertySymbols,yt=Object.prototype.hasOwnProperty,_t=Object.prototype.propertyIsEnumerable,ge=(e,t,n)=>t in e?mt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ye=(e,t)=>{for(var n in t||(t={}))yt.call(t,n)&&ge(e,n,t[n]);if(he)for(var n of he(t))_t.call(t,n)&&ge(e,n,t[n]);return e},_e=(e,t)=>ht(e,gt(t));function wt(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function we(e,t={}){const n=_(),r=B(),i=T(),s=ie(),c=l.useMemo(()=>me({all:t.all,manifest:r,canvas:i,canvases:s}),[t.all,i,s,r]),o=vt(e,t.all?void 0:c),a=l.useCallback(h=>{!e||n.setMetaValue([h,"annotationPageManager","views"],p=>p&&!p[e]?p:_e(ye({},p||{}),{[e]:!1}))},[e,n]),u=l.useCallback((h,p={})=>{if(!e)return;const O=n.getState(),I=[];if(p==null?void 0:p.deselectOthers){const f=Object.keys(O.iiif.entities.AnnotationPage);for(const d of f){const w=wt(O,d);w&&w.views&&w.views[e]&&I.push(d)}}for(const f of I)a(f);n.setMetaValue([h,"annotationPageManager","views"],f=>f&&f[e]?f:_e(ye({},f||{}),{[e]:!0}))},[e,a,n]);return{availablePageIds:c,enabledPageIds:o,setPageEnabled:u,setPageDisabled:a}}function Q(e={}){const t=T(e.canvasId?{id:e.canvasId}:void 0);return b((n,r)=>{if(!t)return[];const i=r.get(t.items),s=[];for(const c of i)s.push(...r.get(c.items));return s},[t])}function Pt(e,t={}){return Q(t)}function St(e,t=!1){}function Ct(e,t=[]){const{id:n,selector:r}=e,i=R(),s=_(),c=n||i.collection,o=c?s.select(a=>a.iiif.entities.Collection[c]):void 0;return l.useMemo(()=>{if(!!o)return r?r(o):o},[o,r,...t])}function Ot(){const t=_().getStore();return l.useMemo(()=>n=>t.dispatch(n),[t])}function xt(e,t,n,r,i=[]){const s=_(),c=l.useMemo(()=>F.createEventsHelper(s),[s]);l.useEffect(()=>{const o=e;return o?(c.addEventListener(o,t,n,r),()=>{c.removeEventListener(o,t,n)}):()=>{}},[c,e,t,...i])}var bt=Object.defineProperty,Pe=Object.getOwnPropertySymbols,It=Object.prototype.hasOwnProperty,Et=Object.prototype.propertyIsEnumerable,Se=(e,t,n)=>t in e?bt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,$t=(e,t)=>{for(var n in t||(t={}))It.call(t,n)&&Se(e,n,t[n]);if(Pe)for(var n of Pe(t))Et.call(t,n)&&Se(e,n,t[n]);return e},Mt=(e,t,n)=>new Promise((r,i)=>{var s=a=>{try{o(n.next(a))}catch(u){i(u)}},c=a=>{try{o(n.throw(a))}catch(u){i(u)}},o=a=>a.done?r(a.value):Promise.resolve(a.value).then(s,c);o((n=n.apply(e,t)).next())});const Rt=(e,t={})=>{const n=_(),[r,i]=l.useState(e),s=l.useMemo(()=>n.get(e),[e,n]),{data:c,isFetching:o}=X.useQuery(`collection:${e}`,()=>Mt(void 0,null,function*(){const a=s||(yield n.loadCollection(e));return a&&i(a.id),a}),$t({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,initialData:s},t));return{isLoaded:!o,id:r,collection:c}};var Vt=(e,t,n)=>new Promise((r,i)=>{var s=a=>{try{o(n.next(a))}catch(u){i(u)}},c=a=>{try{o(n.throw(a))}catch(u){i(u)}},o=a=>a.done?r(a.value):Promise.resolve(a.value).then(s,c);o((n=n.apply(e,t)).next())});function Ce(){const e=T(),t=Q(),n=_(),r=z();return X.useQuery(`canvas-first-image-service:${e?e.id:"undefined"}`,()=>Vt(this,null,function*(){if(e&&t.length){const i=t[0],s=n.get(i.body[0]),o=D.getImageServices(s)[0];return o&&(yield r.loadService({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height}))||void 0}}),{refetchOnWindowFocus:!1,refetchOnMount:!1,refetchIntervalInBackground:!1,refetchInterval:!1,initialData:()=>{if(e&&t.length){const i=t[0],s=n.get(i.body[0]),o=D.getImageServices(s)[0];return o&&r.loadServiceSync({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height})||void 0}}})}function At(){const e=Ce();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 Tt(e={},t=[]){const{id:n,selector:r}=e,i=R(),s=_(),c=n||i.range,o=c?s.select(a=>a.iiif.entities.Range[c]):void 0;return l.useMemo(()=>{if(!!o)return r?r(o):o},[o,r,...t])}function jt(e,t){const n=_(),r=l.useMemo(()=>F.createEventsHelper(n),[n]),i=b(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return l.useMemo(()=>e?r.getListenersAsProps(e,t):{},[i,e,n,t])}function Oe(e,t){return b((n,r)=>r.get(e.map(i=>({id:i,type:t}))),[e,t])}function Lt(){const e=B();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function Bt(e,t){const n=_(),r=l.useMemo(()=>F.createStylesHelper(n),[n]);return b(()=>{if(!e)return null;const i=r.getAppliedStyles(e.id);return i?t?i[t]:i:void 0},[e,t])}const xe=(e,t=[])=>{const n=_();l.useEffect(()=>{e(n)},[n,...t])};function Dt(e,t,{canvasId:n,manifestId:r}={}){const i=_(),s=z(),c=l.useMemo(()=>F.createThumbnailHelper(i,{imageServiceLoader:s}),[i,s]),[o,a]=l.useState(),u=B(r?{id:r}:void 0),h=T(n?{id:n}:void 0),p=h||u,O=l.useRef(!1);if(l.useEffect(()=>()=>{O.current=!0},[]),!p)throw new Error("Must be called under a manifest or canvas context.");return xe(I=>{c.getBestThumbnailAtSize(p,e,t).then(f=>{f.best&&!O.current&&a(f.best)})},[p]),o}var Ft=Object.defineProperty,kt=Object.defineProperties,Nt=Object.getOwnPropertyDescriptors,be=Object.getOwnPropertySymbols,qt=Object.prototype.hasOwnProperty,zt=Object.prototype.propertyIsEnumerable,Ie=(e,t,n)=>t in e?Ft(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ee=(e,t)=>{for(var n in t||(t={}))qt.call(t,n)&&Ie(e,n,t[n]);if(be)for(var n of be(t))zt.call(t,n)&&Ie(e,n,t[n]);return e},$e=(e,t)=>kt(e,Nt(t));function Me(){const e=z(),[t,n]=l.useState({}),r=l.useRef(!1);return l.useEffect(()=>()=>{r.current=!0},[]),[l.useCallback((s,{height:c,width:o})=>{if(s){const a=s.id||s["@id"],u=e.loadServiceSync({id:a,width:s.width||o,height:s.height||c});u?s=u:t[a]||(r.current||n(h=>$e(Ee({},h),{[a]:"loading"})),e.loadService({id:a,width:s.width||o,height:s.height||c}).then(()=>{r.current||n(h=>$e(Ee({},h),{[a]:"done"}))}))}return s},[e,t]),t]}function G(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function Ht(e,t){const n=[],r=[];for(const i of t){const s=e.get(i.body);for(const c of s){const[o,{selector:a}]=G(c),u=(o.type||"unknown").toLowerCase();if(u==="choice"){const h=e.get(o.items);s.push(h[0]);continue}n.indexOf(u)===-1&&n.push(u),r.push({type:u,resource:o,target:i.target,selector:a})}}return{types:n,items:r}}var Qt=Object.defineProperty,Ut=Object.defineProperties,Wt=Object.getOwnPropertyDescriptors,Re=Object.getOwnPropertySymbols,Xt=Object.prototype.hasOwnProperty,Gt=Object.prototype.propertyIsEnumerable,Ve=(e,t,n)=>t in e?Qt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Jt=(e,t)=>{for(var n in t||(t={}))Xt.call(t,n)&&Ve(e,n,t[n]);if(Re)for(var n of Re(t))Gt.call(t,n)&&Ve(e,n,t[n]);return e},Kt=(e,t)=>Ut(e,Wt(t));const Ae={makeChoice:()=>{}},Te=[{type:"unknown"},Ae],U=e=>[{type:"unknown",reason:e,annotations:{pages:[]}},Ae];function Yt(e){const t=B(),n=T(),r=Q(),i=_(),[s,c]=Me(),{enabledPageIds:o}=we((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id),{all:!1}),a=Oe(o,"AnnotationPage"),[u,h]=l.useState((e==null?void 0:e.defaultChoices)||[]);e==null||e.strategies;const p=l.useMemo(()=>{const d=[];let w=null;const P=[];i.getState();for(const v of r){const m=i.get(v.body);for(const y of m){const[C,{selector:$}]=G(y),x=(C.type||"unknown").toLowerCase();if(x==="choice"){const A=i.get(C.items),S=u.length?u.map(M=>A.find(W=>W.id===M)).filter(Boolean):[A[0]];S.length===0&&S.push(A[0]),w={type:"single-choice",items:A.map(M=>({id:M.id,label:M.label,selected:S.indexOf(M)!==-1})),label:y.label},m.push(...S);continue}d.indexOf(x)===-1&&d.push(x),P.push({type:x,resource:C,target:v.target,selector:$})}}return{types:d,items:P,choice:w}},[i,c,r,u]),I={makeChoice:l.useCallback((d,{deselectOthers:w=!0,deselect:P=!1}={})=>{if(p.choice){if(p.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");h(v=>{if(P){const y=v.filter(C=>C!==d);if(y.length===0){const C=p.items[0].resource.id;return C?[C]:[]}return y}if(w)return[d];const m=[...v];if(m.length===0&&p.items.length){const y=p.items[0].resource.id;y&&m.push(y)}return v.indexOf(d)!==-1?v:[...v,d]})}},[p.choice])},f=l.useMemo(()=>{if(!n)return Te;if(p.types.length!==1)return U("ComplexTimelineStrategy not yet supported");const d=p.types[0];if(d==="image"){const w=[];for(const P of p.items){const v=P.resource&&P.resource.type==="SpecificResource"?P.resource.source:P.resource;if(!v.id)return U("No resource Identifier");let m;if(v.service){const J=D.getImageServices(v);J[0]&&(m=s(J[0],n))}P.target==="https://bvmm.irht.cnrs.fr/iiif/2309/canvas/canvas-981394#xywh=3949,994,1091,1232"&&(P.target="https://bvmm.irht.cnrs.fr/iiif/4490/canvas/canvas-981394#xywh=3949,994,1091,1232"),m&&m.width&&m.height&&m.profile==="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2"&&(m.profile="http://iiif.io/api/image/2/level2.json",m.sizes=[{width:m.width,height:m.height}],m.tiles=[{width:256,height:256,scaleFactors:[1,2,4,8,16,32]}]);const{selector:y,source:C}=E(P.target);if(C.id!==n.id)continue;const $={type:"BoxSelector",x:0,y:0,width:n.width,height:n.height},x=y?y.type==="TemporalSelector"?{type:"TemporalBoxSelector",startTime:y.startTime,endTime:y.endTime,x:$.x,y:$.y,width:$.width,height:$.height}:y:null,A={type:"BoxSelector",x:0,y:0,width:n.width,height:n.height},S=P.resource.type==="SpecificResource"?E(P.resource):null,M=S&&S.selector&&(S.selector.type==="BoxSelector"||S.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",x:S.selector.x,y:S.selector.y,width:S.selector.width,height:S.selector.height}:A,W={id:v.id,type:"Image",width:x?v.width:n.width,height:x?v.height:n.height,service:m,sizes:m&&m.sizes?m.sizes:v.width&&v.height?[{width:v.width,height:v.height}]:[],target:x||$,selector:M};w.push(W)}return[{type:"images",image:w[0],images:w,choice:p.choice},I]}return d==="audio"?U("Audio strategy not yet supported"):d==="video"?U("Video strategy not yet supported"):Te},[n,p,i,I.makeChoice]);return l.useMemo(()=>[Kt(Jt({},f[0]),{annotations:{pages:a}}),f[1]],[f,a])}exports.AnnotationContext=ke,exports.CanvasContext=te,exports.CollectionContext=Ne,exports.ContextBridge=Ke,exports.ImageServiceLoaderContext=ce,exports.ManifestContext=ne,exports.RangeContext=qe,exports.ReactVaultContext=N,exports.ResourceProvider=V,exports.ResourceReactContext=k,exports.SimpleViewerProvider=Xe,exports.SimpleViewerReactContext=L,exports.VaultProvider=re,exports.VisibleCanvasReactContext=j,exports.expandTarget=E,exports.flattenAnnotationPageIds=me,exports.getPaintables=Ht,exports.parseSelector=H,exports.parseSpecificResource=G,exports.useAnnotation=dt,exports.useAnnotationPageManager=we,exports.useAnnotationsAtTime=Pt,exports.useCanvas=T,exports.useCanvasClock=St,exports.useCollection=Ct,exports.useContextBridge=Je,exports.useDispatch=Ot,exports.useEventListener=xt,exports.useExternalCollection=Rt,exports.useExternalManifest=se,exports.useImageService=Ce,exports.useImageServiceLoader=z,exports.useImageTile=At,exports.useLoadImageService=Me,exports.useManifest=B,exports.usePaintingAnnotations=Q,exports.useRange=Tt,exports.useRenderingStrategy=Yt,exports.useResourceContext=R,exports.useResourceEvents=jt,exports.useResources=Oe,exports.useSearchService=Lt,exports.useSimpleViewer=Ge,exports.useStyles=Bt,exports.useThumbnail=Dt,exports.useVault=_,exports.useVaultEffect=xe,exports.useVaultSelector=b,exports.useVisibleCanvases=ie;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var u=require("react"),T=require("@iiif/vault"),k=require("react-query"),L=require("@atlas-viewer/iiif-image-api"),b=require("@iiif/vault-helpers"),h=require("typesafe-actions"),je=require("@iiif/parser");function De(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var g=De(u),Fe=Object.defineProperty,z=Object.getOwnPropertySymbols,Ne=Object.prototype.hasOwnProperty,Be=Object.prototype.propertyIsEnumerable,Y=(e,t,n)=>t in e?Fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,W=(e,t)=>{for(var n in t||(t={}))Ne.call(t,n)&&Y(e,n,t[n]);if(z)for(var n of z(t))Be.call(t,n)&&Y(e,n,t[n]);return e};const Ue={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},j=g.default.createContext(Ue),C=()=>u.useContext(j),E=({value:e,children:t})=>{const n=C(),r=u.useMemo(()=>W(W({},n),e),[e,n]);return g.default.createElement(j.Provider,{value:r},t)},ke=({annotation:e,children:t})=>g.default.createElement(E,{value:{annotation:e}},t),G=({canvas:e,children:t})=>g.default.createElement(E,{value:{canvas:e}},t),He=({collection:e,children:t})=>g.default.createElement(E,{value:{collection:e}},t),X=({manifest:e,children:t})=>g.default.createElement(E,{value:{manifest:e}},t),Qe=({range:e,children:t})=>g.default.createElement(E,{value:{range:e}},t),A=g.default.createContext({vault:null,setVaultInstance:e=>{}}),J=({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:c})=>{const[i,a]=u.useState(()=>e||(n?T.globalVault(t):t?new T.Vault(t):new T.Vault));return g.default.createElement(A.Provider,{value:{vault:i,setVaultInstance:a}},g.default.createElement(E,{value:r||{}},c))},y=()=>{const{vault:e}=u.useContext(A);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var qe=Object.defineProperty,K=Object.getOwnPropertySymbols,ze=Object.prototype.hasOwnProperty,Ye=Object.prototype.propertyIsEnumerable,Z=(e,t,n)=>t in e?qe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,We=(e,t)=>{for(var n in t||(t={}))ze.call(t,n)&&Z(e,n,t[n]);if(K)for(var n of K(t))Ye.call(t,n)&&Z(e,n,t[n]);return e},Ge=(e,t,n)=>new Promise((r,c)=>{var i=s=>{try{o(n.next(s))}catch(l){c(l)}},a=s=>{try{o(n.throw(s))}catch(l){c(l)}},o=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);o((n=n.apply(e,t)).next())});const ee=(e,t={})=>{const n=y(),[r,c]=u.useState(e),i=u.useMemo(()=>n.get(e)||void 0,[e,n]),{data:a,error:o}=k.useQuery(["manifest",e],()=>Ge(void 0,null,function*(){const s=i||(yield n.load(e));return s&&r!==s.id&&c(s.id),s}),We({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,retry:!1,initialData:i},t));return{isLoaded:!!a,id:r,error:o,manifest:a}};function P(e,t=[]){const n=y(),[r,c]=u.useState(()=>e(n.getState(),n));return u.useEffect(()=>n.subscribe(i=>e(i,n),i=>{c(i)},!1),t),r}const R=g.default.createContext([]);function te(){const e=u.useContext(R);return P(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}const D=()=>{},M=u.createContext({setCurrentCanvasId:D,setCurrentCanvasIndex:D,nextCanvas:D,previousCanvas:D,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),Xe=e=>{const t=ee(e.manifest),[n,r]=u.useState(""),[c,i]=u.useState([]),a=(typeof e.pagingEnabled>"u"||e.pagingEnabled)&&t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");u.useEffect(()=>{var f,m;t.manifest&&(r((f=t.manifest.items[0])==null?void 0:f.id),i([(m=t.manifest.items[0])==null?void 0:m.id]))},[t.manifest,e.manifest]);const o=u.useMemo(()=>{var f;return((f=t.manifest)==null?void 0:f.items.map(m=>m.id))||[]},[t.manifest,e.manifest]),s=u.useMemo(()=>o.indexOf(n),[o,n]),l=u.useCallback(()=>{if(o.length&&n){if(s===-1||(o[s+2]?s+2===o.length:s===o.length))return;const f=a&&s!==0?o[s+2]:o[s+1],m=a?s!==0?o[s+3]:o[s+2]:null;f&&(r(f),i(m?[f,m]:[f]))}},[a,o,n,s]),p=u.useCallback(()=>{if(o.length&&n){if(s===0||s===-1)return;const f=a&&s!==1?o[s-2]:o[s-1],m=a&&s!==1?o[s-1]:null;f&&(r(f),i(m?[f,m]:[f]))}},[a,o,n,s]),d=u.useCallback(f=>{const m=a&&f%2===1?f-1:f,w=o[m],q=a&&m!==0?o[m+1]:null;w&&(r(w),i(I=>{const U=q?[w,q]:[w];if(I.length===I.length){for(let V=0;V<I.length;V++)if(I[V]!==U[V])return U;return I}return U}))},[a,o]),v=u.useCallback(f=>{const m=o.indexOf(f);m!==-1&&d(m)},[o,d]),_=u.useMemo(()=>({setCurrentCanvasId:v,nextCanvas:l,previousCanvas:p,currentCanvasIndex:s,totalCanvases:o.length,setCurrentCanvasIndex:d,pagingView:!0}),[l,p,s,o,d,v]);return!t.isLoaded||!t.manifest?g.default.createElement("div",null,"Loading..."):g.default.createElement(M.Provider,{value:_},g.default.createElement(R.Provider,{value:c},g.default.createElement(X,{manifest:t.manifest.id},g.default.createElement(G,{canvas:n},e.children))))};function Je(){return u.useContext(M)}function Ke(){return{VaultContext:u.useContext(A),ResourceContext:u.useContext(j),SimpleViewerReactContext:u.useContext(M),VisibleCanvasReactContext:u.useContext(R)}}const Ze=e=>g.default.createElement(J,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},g.default.createElement(R.Provider,{value:e.bridge.VisibleCanvasReactContext},g.default.createElement(M.Provider,{value:e.bridge.SimpleViewerReactContext},e.children))),ne=g.default.createContext(new L.ImageServiceLoader);function F(){return u.useContext(ne)}const et=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,tt=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function N(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:r,selectors:c}=N(n);return r&&(t.selector||(t.selector=r),t.selectors.push(...c)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,n]=e.split("#");return n?N({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=et.exec(e.value);if(t){const r={type:"BoxSelector",spatial:{unit:t[2]==="percent:"?"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(tt);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:[]}}var nt=Object.defineProperty,rt=Object.defineProperties,ot=Object.getOwnPropertyDescriptors,re=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,at=Object.prototype.propertyIsEnumerable,oe=(e,t,n)=>t in e?nt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ie=(e,t)=>{for(var n in t||(t={}))it.call(t,n)&&oe(e,n,t[n]);if(re)for(var n of re(t))at.call(t,n)&&oe(e,n,t[n]);return e},ae=(e,t)=>rt(e,ot(t));function O(e,t={}){if(Array.isArray(e))return O(e[0]);if(typeof e=="string"){const[n,r]=e.split("#");return r?O({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 O(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?N(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?O({type:"SpecificResource",source:ae(ie({},e),{id:n}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:ae(ie({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function se(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function ce(e,t,n){const r=[];let c=null;const i=[];for(const a of t){const o=e.get(a.body);for(const s of o){const[l,{selector:p}]=se(s),d=(l.type||"unknown").toLowerCase();if(d==="choice"){const v=e.get(l.items),_=n.length?n.map(f=>v.find(m=>m.id===f)).filter(Boolean):[v[0]];_.length===0&&_.push(v[0]),c={type:"single-choice",items:v.map(f=>({id:f.id,label:f.label,selected:_.indexOf(f)!==-1})),label:s.label},o.push(..._);continue}r.indexOf(d)===-1&&r.push(d),i.push({type:d,resource:l,target:a.target,selector:p})}}return{types:r,items:i,choice:c}}const ue={makeChoice:()=>{}},H={type:"unknown"},S=e=>({type:"unknown",reason:e,annotations:{pages:[]}});function le(e,t,n){const r=[];for(const c of t.items){const i=c.resource&&c.resource.type==="SpecificResource"?c.resource.source:c.resource;if(!i.id)return S("No resource Identifier");let a;if(i.service){const m=L.getImageServices(i);m[0]&&(a=n(m[0],e))}const{selector:o,source:s}=O(c.target);if(s.id!==e.id)continue;const l={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},p=o?o.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:o.temporal,spatial:l.spatial}:o:null,d={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},v=c.resource.type==="SpecificResource"?O(c.resource):null,_=v&&v.selector&&(v.selector.type==="BoxSelector"||v.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:v.selector.spatial.x,y:v.selector.spatial.y,width:v.selector.spatial.width,height:v.selector.spatial.height}}:d,f={id:i.id,type:"Image",width:p?i.width:e.width,height:p?i.height:e.height,service:a,sizes:a&&a.sizes?a.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:p&&p.type!=="PointSelector"?p:l,selector:_};r.push(f)}return{type:"images",image:r[0],images:r,choice:t.choice}}var st=Object.defineProperty,ct=Object.defineProperties,ut=Object.getOwnPropertyDescriptors,fe=Object.getOwnPropertySymbols,lt=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable,de=(e,t,n)=>t in e?st(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,dt=(e,t)=>{for(var n in t||(t={}))lt.call(t,n)&&de(e,n,t[n]);if(fe)for(var n of fe(t))ft.call(t,n)&&de(e,n,t[n]);return e},pt=(e,t)=>ct(e,ut(t));function vt(e={},t=[]){const{id:n,selector:r}=e,c=C(),i=y(),a=n||c.annotation,o=P(l=>a?l.iiif.entities.Annotation[a]:void 0,[a]),s=P(l=>o&&o.body?o.body.map(p=>p?l.iiif.entities[p.type][p.id]:null).filter(Boolean):[],[o]);return u.useMemo(()=>{if(!o)return;const l=pt(dt({},o),{body:s,target:O(o.target,{typeMap:i.getState().iiif.mapping})});return r?r(l):l},[o,r,s,...t])}function $(e={},t=[]){const{id:n,selector:r}=e,c=C();y();const i=n||c.manifest,a=P(o=>i?o.iiif.entities.Manifest[i]:void 0,[i]);return u.useMemo(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function x(e={},t=[]){const{id:n,selector:r}=e,c=C(),i=n||c.canvas,a=P(o=>i?o.iiif.entities.Canvas[i]:void 0,[i]);return u.useMemo(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function mt(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function gt(e,t){return P(n=>{const r=[];if(!e)return r;const c=Object.keys(n.iiif.entities.AnnotationPage);for(const i of c)if(!t||t.indexOf(i)!==-1){const a=mt(n,i);a&&a.views&&a.views[e]&&r.push(i)}return r},[e])}function pe({canvas:e,manifest:t,all:n,canvases:r}){const c=[];if(t)for(const i of t.annotations)c.indexOf(i.id)===-1&&c.push(i.id);if(n){if(r&&r.length)for(const i of r)for(const a of i.annotations)c.indexOf(a.id)===-1&&c.push(a.id)}else if(e)for(const i of e.annotations)c.indexOf(i.id)===-1&&c.push(i.id);return c}var yt=Object.defineProperty,ht=Object.defineProperties,_t=Object.getOwnPropertyDescriptors,ve=Object.getOwnPropertySymbols,Pt=Object.prototype.hasOwnProperty,St=Object.prototype.propertyIsEnumerable,me=(e,t,n)=>t in e?yt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ge=(e,t)=>{for(var n in t||(t={}))Pt.call(t,n)&&me(e,n,t[n]);if(ve)for(var n of ve(t))St.call(t,n)&&me(e,n,t[n]);return e},ye=(e,t)=>ht(e,_t(t));function wt(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function he(e,t={}){const n=y(),r=$(),c=x(),i=te(),a=u.useMemo(()=>pe({all:t.all,manifest:r,canvas:c,canvases:i}),[t.all,c,i,r]),o=gt(e,t.all?void 0:a),s=u.useCallback(p=>{!e||n.setMetaValue([p,"annotationPageManager","views"],d=>d&&!d[e]?d:ye(ge({},d||{}),{[e]:!1}))},[e,n]),l=u.useCallback((p,d={})=>{if(!e)return;const v=n.getState(),_=[];if(d==null?void 0:d.deselectOthers){const f=Object.keys(v.iiif.entities.AnnotationPage);for(const m of f){const w=wt(v,m);w&&w.views&&w.views[e]&&_.push(m)}}for(const f of _)s(f);n.setMetaValue([p,"annotationPageManager","views"],f=>f&&f[e]?f:ye(ge({},f||{}),{[e]:!0}))},[e,s,n]);return{availablePageIds:a,enabledPageIds:o,setPageEnabled:l,setPageDisabled:s}}function B(e={}){const t=x(e.canvasId?{id:e.canvasId}:void 0);return P((n,r)=>{if(!t)return[];const c=r.get(t.items),i=[];for(const a of c)i.push(...r.get(a.items));return i},[t])}function Ot(e,t={}){return B(t)}function Ct(e,t=!1){}function Et(e,t=[]){const{id:n,selector:r}=e,c=C(),i=n||c.collection,a=P(o=>i?o.iiif.entities.Collection[i]:void 0,[i]);return u.useMemo(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function _e(){const t=y().getStore();return u.useMemo(()=>n=>t.dispatch(n),[t])}function xt(e,t,n,r,c=[]){const i=y(),a=u.useMemo(()=>b.createEventsHelper(i),[i]);u.useEffect(()=>{const o=e;return o?(a.addEventListener(o,t,n,r),()=>{a.removeEventListener(o,t,n)}):()=>{}},[a,e,t,...c])}function It(){const e=u.useContext(A);return e&&e.vault?e.vault:T.globalVault()}var bt=Object.defineProperty,Pe=Object.getOwnPropertySymbols,At=Object.prototype.hasOwnProperty,Rt=Object.prototype.propertyIsEnumerable,Se=(e,t,n)=>t in e?bt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Mt=(e,t)=>{for(var n in t||(t={}))At.call(t,n)&&Se(e,n,t[n]);if(Pe)for(var n of Pe(t))Rt.call(t,n)&&Se(e,n,t[n]);return e},$t=(e,t,n)=>new Promise((r,c)=>{var i=s=>{try{o(n.next(s))}catch(l){c(l)}},a=s=>{try{o(n.throw(s))}catch(l){c(l)}},o=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);o((n=n.apply(e,t)).next())});const Vt=(e,t={})=>{const n=y(),[r,c]=u.useState(e),i=u.useMemo(()=>n.get(e),[e,n]),{data:a,isFetching:o}=k.useQuery(`collection:${e}`,()=>$t(void 0,null,function*(){const s=i||(yield n.loadCollection(e));return s&&c(s.id),s}),Mt({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,initialData:i},t));return{isLoaded:!o,id:r,collection:a}};var Tt=(e,t,n)=>new Promise((r,c)=>{var i=s=>{try{o(n.next(s))}catch(l){c(l)}},a=s=>{try{o(n.throw(s))}catch(l){c(l)}},o=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);o((n=n.apply(e,t)).next())});function we(){const e=x(),t=B(),n=y(),r=F();return k.useQuery(`canvas-first-image-service:${e?e.id:"undefined"}`,()=>Tt(this,null,function*(){if(e&&t.length){const c=t[0],i=n.get(c.body[0]),o=L.getImageServices(i)[0];return o&&(yield r.loadService({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height}))||void 0}}),{refetchOnWindowFocus:!1,refetchOnMount:!1,refetchIntervalInBackground:!1,refetchInterval:!1,initialData:()=>{if(e&&t.length){const c=t[0],i=n.get(c.body[0]),o=L.getImageServices(i)[0];return o&&r.loadServiceSync({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height})||void 0}}})}function Lt(){const e=we();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 Oe(e,t=[]){const n=y(),r=B(),[c,i]=u.useState((e==null?void 0:e.defaultChoices)||[]),a=u.useMemo(()=>ce(n,r,c),[n,r,c,...t]),s={makeChoice:u.useCallback((l,{deselectOthers:p=!0,deselect:d=!1}={})=>{if(a.choice){if(a.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");i(v=>{if(d){const f=v.filter(m=>m!==l);if(f.length===0){const m=a.items[0].resource.id;return m?[m]:[]}return f}if(p)return[l];const _=[...v];if(_.length===0&&a.items.length){const f=a.items[0].resource.id;f&&_.push(f)}return v.indexOf(l)!==-1?v:[...v,l]})}},[a.choice])};return[a,s]}function jt(e={},t=[]){const{id:n,selector:r}=e,c=C(),i=n||c.range,a=P(o=>i?o.iiif.entities.Range[i]:void 0,[i]);return u.useMemo(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function Dt(e,t){const n=y(),r=u.useMemo(()=>b.createEventsHelper(n),[n]),c=P(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return u.useMemo(()=>e?r.getListenersAsProps(e,t):{},[c,e,n,t])}function Ce(e,t){return P((n,r)=>r.get(e.map(c=>({id:c,type:t}))),[e,t])}function Ft(){const e=$();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function Nt(){const e=y();return u.useMemo(()=>b.createStylesHelper(e),[e])}function Bt(e,t){const n=y(),r=u.useMemo(()=>b.createStylesHelper(n),[n]);return P(()=>{if(!e)return null;const c=r.getAppliedStyles(e.id);return c?t?c[t]:c:void 0},[e,t])}const Ee=(e,t=[])=>{const n=y();u.useEffect(()=>{e(n)},[n,...t])};function Ut(e,t,{canvasId:n,manifestId:r}={}){const c=y(),i=F(),a=u.useMemo(()=>b.createThumbnailHelper(c,{imageServiceLoader:i}),[c,i]),[o,s]=u.useState(),l=$(r?{id:r}:void 0),p=x(n?{id:n}:void 0),d=p||l,v=u.useRef(!1);if(u.useEffect(()=>()=>{v.current=!0},[]),!d)throw new Error("Must be called under a manifest or canvas context.");return Ee(_=>{a.getBestThumbnailAtSize(d,e,t).then(f=>{f.best&&!v.current&&s(f.best)})},[d]),o}var kt=Object.defineProperty,Ht=Object.defineProperties,Qt=Object.getOwnPropertyDescriptors,xe=Object.getOwnPropertySymbols,qt=Object.prototype.hasOwnProperty,zt=Object.prototype.propertyIsEnumerable,Ie=(e,t,n)=>t in e?kt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,be=(e,t)=>{for(var n in t||(t={}))qt.call(t,n)&&Ie(e,n,t[n]);if(xe)for(var n of xe(t))zt.call(t,n)&&Ie(e,n,t[n]);return e},Ae=(e,t)=>Ht(e,Qt(t));function Re(){const e=F(),[t,n]=u.useState({}),r=u.useRef(!1);return u.useEffect(()=>()=>{r.current=!0},[]),[u.useCallback((i,{height:a,width:o})=>{if(i){const s=i.id||i["@id"],l=e.loadServiceSync({id:s,width:i.width||o,height:i.height||a});l?i=l:t[s]||(r.current||n(p=>Ae(be({},p),{[s]:"loading"})),e.loadService({id:s,width:i.width||o,height:i.height||a}).then(()=>{r.current||n(p=>Ae(be({},p),{[s]:"done"}))}))}return i},[e,t]),t]}const Yt="@iiif/IMPORT_ENTITIES",Wt="@iiif/MODIFY_ENTITY_FIELD",Gt="@iiif/REORDER_ENTITY_FIELD",Xt="@iiif/ADD_REFERENCE",Jt="@iiif/REMOVE_REFERENCE",Kt=h.createAction(Yt)(),Zt=h.createAction(Wt)(),en=h.createAction(Gt)(),tn=h.createAction(Xt)(),nn=h.createAction(Jt)(),Q={importEntities:Kt,modifyEntityField:Zt,reorderEntityField:en,addReference:tn,removeReference:nn},rn="@iiif/ADD_MAPPING",on="@iiif/ADD_MAPPINGS";h.createAction(rn)(),h.createAction(on)();const an="@iiif/SET_META_VALUE",sn="@iiif/SET_META_VALUE_DYNAMIC",cn="@iiif/UNSET_META_VALUE";h.createAction(an)(),h.createAction(sn)(),h.createAction(cn)();const un="@iiif/REQUEST_RESOURCE",ln="@iiif/REQUEST_ERROR",fn="@iiif/REQUEST_MISMATCH",dn="@iiif/REQUEST_COMPLETE",pn="@iiif/REQUEST_OFFLINE_RESOURCE";h.createAction(un)(),h.createAction(ln)(),h.createAction(fn)(),h.createAction(dn)(),h.createAction(pn)();const vn="@iiif/BATCH";h.createAction(vn)();var mn=Object.defineProperty,gn=Object.defineProperties,yn=Object.getOwnPropertyDescriptors,Me=Object.getOwnPropertySymbols,hn=Object.prototype.hasOwnProperty,_n=Object.prototype.propertyIsEnumerable,$e=(e,t,n)=>t in e?mn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Pn=(e,t)=>{for(var n in t||(t={}))hn.call(t,n)&&$e(e,n,t[n]);if(Me)for(var n of Me(t))_n.call(t,n)&&$e(e,n,t[n]);return e},Sn=(e,t)=>gn(e,yn(t));function Ve(e){return typeof e!="string"&&e&&e.bindToVault}function wn(){const e=y(),t=u.useRef([]),n=_e(),r=u.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);u.useLayoutEffect(()=>{const o=Sn(Pn({},je.emptyAnnotationPage),{id:r,items:[]});n(Q.importEntities({entities:{AnnotationPage:{[o.id]:o}}}))},[r]);const c=P(o=>r?o.iiif.entities.AnnotationPage[r]:null,[r]),i=u.useCallback((o,s)=>{if(r){if(Ve(o)){const d=o;d.__vault||d.bindToVault(e),o=typeof d.source=="string"?d.source:d.source.id,t.current[o]=d}else typeof o!="string"&&(o=o.id);const l=e.get({id:r,type:"AnnotationPage"}),p=e.get({id:o,type:"Annotation"});l&&p&&(l.items.find(d=>d.id===p.id)||n(Q.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"},index:s})))}},[r]),a=u.useCallback(o=>{r&&(Ve(o)?o=typeof o.source=="string"?o.source:o.source.id:typeof o!="string"&&(o=o.id),t.current[o]&&t.current[o].beforeRemove(),e.get({id:r,type:"AnnotationPage"})&&n(Q.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"}})))},[r]);return[c,{addAnnotation:i,removeAnnotation:a}]}var On=Object.defineProperty,Cn=Object.defineProperties,En=Object.getOwnPropertyDescriptors,Te=Object.getOwnPropertySymbols,xn=Object.prototype.hasOwnProperty,In=Object.prototype.propertyIsEnumerable,Le=(e,t,n)=>t in e?On(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,bn=(e,t)=>{for(var n in t||(t={}))xn.call(t,n)&&Le(e,n,t[n]);if(Te)for(var n of Te(t))In.call(t,n)&&Le(e,n,t[n]);return e},An=(e,t)=>Cn(e,En(t));function Rn(e){const t=$(),n=x(),r=y(),[c,i]=Re(),{enabledPageIds:a}=he((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id),{all:!1}),o=Ce(a,"AnnotationPage"),s=(e==null?void 0:e.strategies)||["images","media","complex-timeline"],[l,p]=Oe(e,[i]),d=u.useMemo(()=>{if(!n||l.types.length===0)return H;if(l.types.length!==1)return s.indexOf("complex-timeline")===-1?S("Complex timeline not supported"):S("ComplexTimelineStrategy not yet supported");const v=l.types[0];return v==="image"?s.indexOf("images")===-1?S("Image not supported"):le(n,l,c):v==="audio"?s.indexOf("media")===-1?S("Media not supported"):S("Audio strategy not yet supported"):v==="video"?s.indexOf("media")===-1?S("Media not supported"):S("Video strategy not yet supported"):H},[n,l,r,p.makeChoice]);return u.useMemo(()=>d.type==="unknown"?[d,ue]:[An(bn({},d),{annotations:{pages:o}}),p],[d,o])}exports.AnnotationContext=ke,exports.CanvasContext=G,exports.CollectionContext=He,exports.ContextBridge=Ze,exports.ImageServiceLoaderContext=ne,exports.ManifestContext=X,exports.RangeContext=Qe,exports.ReactVaultContext=A,exports.ResourceProvider=E,exports.ResourceReactContext=j,exports.SimpleViewerProvider=Xe,exports.SimpleViewerReactContext=M,exports.VaultProvider=J,exports.VisibleCanvasReactContext=R,exports.emptyActions=ue,exports.expandTarget=O,exports.flattenAnnotationPageIds=pe,exports.getImageStrategy=le,exports.getPaintables=ce,exports.parseSelector=N,exports.parseSpecificResource=se,exports.unknownResponse=H,exports.unsupportedStrategy=S,exports.useAnnotation=vt,exports.useAnnotationPageManager=he,exports.useAnnotationsAtTime=Ot,exports.useCanvas=x,exports.useCanvasClock=Ct,exports.useCollection=Et,exports.useContextBridge=Ke,exports.useDispatch=_e,exports.useEventListener=xt,exports.useExistingVault=It,exports.useExternalCollection=Vt,exports.useExternalManifest=ee,exports.useImageService=we,exports.useImageServiceLoader=F,exports.useImageTile=Lt,exports.useLoadImageService=Re,exports.useManifest=$,exports.usePaintables=Oe,exports.usePaintingAnnotations=B,exports.useRange=jt,exports.useRenderingStrategy=Rn,exports.useResourceContext=C,exports.useResourceEvents=Dt,exports.useResources=Ce,exports.useSearchService=Ft,exports.useSimpleViewer=Je,exports.useStyleHelper=Nt,exports.useStyles=Bt,exports.useThumbnail=Ut,exports.useVault=y,exports.useVaultEffect=Ee,exports.useVaultSelector=P,exports.useVirtualAnnotationPage=wn,exports.useVisibleCanvases=te;
@@ -1 +1 @@
1
- import g,{useContext as x,useMemo as m,useState as I,useEffect as B,createContext as Ne,useCallback as R,useRef as ee}from"react";import{Vault as te}from"@iiif/vault";import{useQuery as J}from"react-query";import{ImageServiceLoader as ke,getImageServices as K}from"@atlas-viewer/iiif-image-api";import{createEventsHelper as ne,createStylesHelper as ze,createThumbnailHelper as Ue}from"@iiif/vault-helpers";var He=Object.defineProperty,re=Object.getOwnPropertySymbols,We=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable,oe=(e,t,n)=>t in e?He(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ie=(e,t)=>{for(var n in t||(t={}))We.call(t,n)&&oe(e,n,t[n]);if(re)for(var n of re(t))Qe.call(t,n)&&oe(e,n,t[n]);return e};const Xe={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},z=g.createContext(Xe),A=()=>x(z),T=({value:e,children:t})=>{const n=A(),r=m(()=>ie(ie({},n),e),[e,n]);return g.createElement(z.Provider,{value:r},t)},qe=({annotation:e,children:t})=>g.createElement(T,{value:{annotation:e}},t),se=({canvas:e,children:t})=>g.createElement(T,{value:{canvas:e}},t),Ge=({collection:e,children:t})=>g.createElement(T,{value:{collection:e}},t),ae=({manifest:e,children:t})=>g.createElement(T,{value:{manifest:e}},t),Je=({range:e,children:t})=>g.createElement(T,{value:{range:e}},t),U=g.createContext({vault:null,setVaultInstance:e=>{}}),ce=({vault:e,vaultOptions:t,resources:n,children:r})=>{const[a,s]=I(()=>e||(t?new te(t):new te));return g.createElement(U.Provider,{value:{vault:a,setVaultInstance:s}},g.createElement(T,{value:n||{}},r))},_=()=>{const{vault:e}=x(U);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var Ke=Object.defineProperty,le=Object.getOwnPropertySymbols,Ye=Object.prototype.hasOwnProperty,Ze=Object.prototype.propertyIsEnumerable,ue=(e,t,n)=>t in e?Ke(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,et=(e,t)=>{for(var n in t||(t={}))Ye.call(t,n)&&ue(e,n,t[n]);if(le)for(var n of le(t))Ze.call(t,n)&&ue(e,n,t[n]);return e},tt=(e,t,n)=>new Promise((r,a)=>{var s=i=>{try{o(n.next(i))}catch(l){a(l)}},c=i=>{try{o(n.throw(i))}catch(l){a(l)}},o=i=>i.done?r(i.value):Promise.resolve(i.value).then(s,c);o((n=n.apply(e,t)).next())});const fe=(e,t={})=>{const n=_(),[r,a]=I(e),s=m(()=>n.get(e)||void 0,[e,n]),{data:c,error:o}=J(["manifest",e],()=>tt(void 0,null,function*(){const i=s||(yield n.load(e));return i&&r!==i.id&&a(i.id),i}),et({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,retry:!1,initialData:s},t));return{isLoaded:!!c,id:r,error:o,manifest:c}};function $(e,t=[]){const n=_(),[r,a]=I(()=>e(n.getState(),n));return B(()=>n.subscribe(s=>e(s,n),s=>{a(s)},!0),t),r}const F=g.createContext([]);function de(){const e=x(F);return $(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}const H=()=>{},N=Ne({setCurrentCanvasId:H,setCurrentCanvasIndex:H,nextCanvas:H,previousCanvas:H,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),nt=e=>{const t=fe(e.manifest),[n,r]=I(""),[a,s]=I([]),c=t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");B(()=>{var u,f;t.manifest&&(r((u=t.manifest.items[0])==null?void 0:u.id),s([(f=t.manifest.items[0])==null?void 0:f.id]))},[t.manifest,e.manifest]);const o=m(()=>{var u;return((u=t.manifest)==null?void 0:u.items.map(f=>f.id))||[]},[t.manifest,e.manifest]),i=m(()=>o.indexOf(n),[o,n]),l=R(()=>{if(o.length&&n){if(i===-1||(o[i+2]?i+2===o.length:i===o.length))return;const u=c&&i!==0?o[i+2]:o[i+1],f=c?i!==0?o[i+3]:o[i+2]:null;u&&(r(u),s(f?[u,f]:[u]))}},[c,o,n,i]),h=R(()=>{if(o.length&&n){if(i===0||i===-1)return;const u=c&&i!==1?o[i-2]:o[i-1],f=c&&i!==1?o[i-1]:null;u&&(r(u),s(f?[u,f]:[u]))}},[c,o,n,i]),d=R(u=>{const f=c&&u%2===1?u-1:u,w=o[f],P=c&&f!==0?o[f+1]:null;w&&(r(w),s(p=>{const v=P?[w,P]:[w];if(p.length===p.length){for(let y=0;y<p.length;y++)if(p[y]!==v[y])return v;return p}return v}))},[c,o]),C=R(u=>{const f=o.indexOf(u);f!==-1&&d(f)},[o,d]),E=m(()=>({setCurrentCanvasId:C,nextCanvas:l,previousCanvas:h,currentCanvasIndex:i,totalCanvases:o.length,setCurrentCanvasIndex:d,pagingView:!0}),[l,h,i,o,d,C]);return!t.isLoaded||!t.manifest?g.createElement("div",null,"Loading..."):g.createElement(N.Provider,{value:E},g.createElement(F.Provider,{value:a},g.createElement(ae,{manifest:t.manifest.id},g.createElement(se,{canvas:n},e.children))))};function rt(){return x(N)}function ot(){return{VaultContext:x(U),ResourceContext:x(z),SimpleViewerReactContext:x(N),VisibleCanvasReactContext:x(F)}}const it=e=>g.createElement(ce,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},g.createElement(F.Provider,{value:e.bridge.VisibleCanvasReactContext},g.createElement(N.Provider,{value:e.bridge.SimpleViewerReactContext},e.children))),pe=g.createContext(new ke);function W(){return x(pe)}const st=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,at=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function Q(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:r,selectors:a}=Q(n);return r&&(t.selector||(t.selector=r),t.selectors.push(...a)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,n]=e.split("#");return n?Q({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",startTime:e.t};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=st.exec(e.value);if(t){const r={type:"BoxSelector",unit:t[2]==="percent:"?"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(at);if(n){const r={type:"TemporalSelector",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:[]}}var ct=Object.defineProperty,lt=Object.defineProperties,ut=Object.getOwnPropertyDescriptors,ve=Object.getOwnPropertySymbols,ft=Object.prototype.hasOwnProperty,dt=Object.prototype.propertyIsEnumerable,he=(e,t,n)=>t in e?ct(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,me=(e,t)=>{for(var n in t||(t={}))ft.call(t,n)&&he(e,n,t[n]);if(ve)for(var n of ve(t))dt.call(t,n)&&he(e,n,t[n]);return e},ge=(e,t)=>lt(e,ut(t));function M(e,t={}){if(Array.isArray(e))return M(e[0]);if(typeof e=="string"){const[n,r]=e.split("#");return r?M({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 M(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?Q(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?M({type:"SpecificResource",source:ge(me({},e),{id:n}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:ge(me({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}var pt=Object.defineProperty,vt=Object.defineProperties,ht=Object.getOwnPropertyDescriptors,ye=Object.getOwnPropertySymbols,mt=Object.prototype.hasOwnProperty,gt=Object.prototype.propertyIsEnumerable,_e=(e,t,n)=>t in e?pt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,yt=(e,t)=>{for(var n in t||(t={}))mt.call(t,n)&&_e(e,n,t[n]);if(ye)for(var n of ye(t))gt.call(t,n)&&_e(e,n,t[n]);return e},_t=(e,t)=>vt(e,ht(t));function wt(e={},t=[]){const{id:n,selector:r}=e,a=A(),s=_(),c=n||a.annotation,o=$(l=>c?l.iiif.entities.Annotation[c]:void 0,[c]),i=$(l=>o&&o.body?o.body.map(h=>h?l.iiif.entities[h.type][h.id]:null).filter(Boolean):[],[o]);return m(()=>{if(!o)return;const l=_t(yt({},o),{body:i,target:M(o.target,{typeMap:s.getState().iiif.mapping})});return r?r(l):l},[o,r,i,...t])}function k(e={},t=[]){const{id:n,selector:r}=e,a=A(),s=_(),c=n||a.manifest,o=c?s.select(i=>i.iiif.entities.Manifest[c]):void 0;return m(()=>{if(!!o)return r?r(o):o},[o,r,...t])}function D(e={},t=[]){const{id:n,selector:r}=e,a=A(),s=_(),c=n||a.canvas,o=c?s.select(i=>i.iiif.entities.Canvas[c]):void 0;return m(()=>{if(!!o)return r?r(o):o},[o,r,...t])}function Pt(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function Ot(e,t){return $(n=>{const r=[];if(!e)return r;const a=Object.keys(n.iiif.entities.AnnotationPage);for(const s of a)if(!t||t.indexOf(s)!==-1){const c=Pt(n,s);c&&c.views&&c.views[e]&&r.push(s)}return r},[e])}function we({canvas:e,manifest:t,all:n,canvases:r}){const a=[];if(t)for(const s of t.annotations)a.indexOf(s.id)===-1&&a.push(s.id);if(n){if(r&&r.length)for(const s of r)for(const c of s.annotations)a.indexOf(c.id)===-1&&a.push(c.id)}else if(e)for(const s of e.annotations)a.indexOf(s.id)===-1&&a.push(s.id);return a}var St=Object.defineProperty,Ct=Object.defineProperties,bt=Object.getOwnPropertyDescriptors,Pe=Object.getOwnPropertySymbols,xt=Object.prototype.hasOwnProperty,It=Object.prototype.propertyIsEnumerable,Oe=(e,t,n)=>t in e?St(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Se=(e,t)=>{for(var n in t||(t={}))xt.call(t,n)&&Oe(e,n,t[n]);if(Pe)for(var n of Pe(t))It.call(t,n)&&Oe(e,n,t[n]);return e},Ce=(e,t)=>Ct(e,bt(t));function $t(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function be(e,t={}){const n=_(),r=k(),a=D(),s=de(),c=m(()=>we({all:t.all,manifest:r,canvas:a,canvases:s}),[t.all,a,s,r]),o=Ot(e,t.all?void 0:c),i=R(h=>{!e||n.setMetaValue([h,"annotationPageManager","views"],d=>d&&!d[e]?d:Ce(Se({},d||{}),{[e]:!1}))},[e,n]),l=R((h,d={})=>{if(!e)return;const C=n.getState(),E=[];if(d==null?void 0:d.deselectOthers){const u=Object.keys(C.iiif.entities.AnnotationPage);for(const f of u){const w=$t(C,f);w&&w.views&&w.views[e]&&E.push(f)}}for(const u of E)i(u);n.setMetaValue([h,"annotationPageManager","views"],u=>u&&u[e]?u:Ce(Se({},u||{}),{[e]:!0}))},[e,i,n]);return{availablePageIds:c,enabledPageIds:o,setPageEnabled:l,setPageDisabled:i}}function X(e={}){const t=D(e.canvasId?{id:e.canvasId}:void 0);return $((n,r)=>{if(!t)return[];const a=r.get(t.items),s=[];for(const c of a)s.push(...r.get(c.items));return s},[t])}function Et(e,t={}){return X(t)}function Rt(e,t=!1){}function Mt(e,t=[]){const{id:n,selector:r}=e,a=A(),s=_(),c=n||a.collection,o=c?s.select(i=>i.iiif.entities.Collection[c]):void 0;return m(()=>{if(!!o)return r?r(o):o},[o,r,...t])}function Vt(){const t=_().getStore();return m(()=>n=>t.dispatch(n),[t])}function jt(e,t,n,r,a=[]){const s=_(),c=m(()=>ne(s),[s]);B(()=>{const o=e;return o?(c.addEventListener(o,t,n,r),()=>{c.removeEventListener(o,t,n)}):()=>{}},[c,e,t,...a])}var At=Object.defineProperty,xe=Object.getOwnPropertySymbols,Tt=Object.prototype.hasOwnProperty,Lt=Object.prototype.propertyIsEnumerable,Ie=(e,t,n)=>t in e?At(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Bt=(e,t)=>{for(var n in t||(t={}))Tt.call(t,n)&&Ie(e,n,t[n]);if(xe)for(var n of xe(t))Lt.call(t,n)&&Ie(e,n,t[n]);return e},Dt=(e,t,n)=>new Promise((r,a)=>{var s=i=>{try{o(n.next(i))}catch(l){a(l)}},c=i=>{try{o(n.throw(i))}catch(l){a(l)}},o=i=>i.done?r(i.value):Promise.resolve(i.value).then(s,c);o((n=n.apply(e,t)).next())});const Ft=(e,t={})=>{const n=_(),[r,a]=I(e),s=m(()=>n.get(e),[e,n]),{data:c,isFetching:o}=J(`collection:${e}`,()=>Dt(void 0,null,function*(){const i=s||(yield n.loadCollection(e));return i&&a(i.id),i}),Bt({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,initialData:s},t));return{isLoaded:!o,id:r,collection:c}};var Nt=(e,t,n)=>new Promise((r,a)=>{var s=i=>{try{o(n.next(i))}catch(l){a(l)}},c=i=>{try{o(n.throw(i))}catch(l){a(l)}},o=i=>i.done?r(i.value):Promise.resolve(i.value).then(s,c);o((n=n.apply(e,t)).next())});function $e(){const e=D(),t=X(),n=_(),r=W();return J(`canvas-first-image-service:${e?e.id:"undefined"}`,()=>Nt(this,null,function*(){if(e&&t.length){const a=t[0],s=n.get(a.body[0]),o=K(s)[0];return o&&(yield r.loadService({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height}))||void 0}}),{refetchOnWindowFocus:!1,refetchOnMount:!1,refetchIntervalInBackground:!1,refetchInterval:!1,initialData:()=>{if(e&&t.length){const a=t[0],s=n.get(a.body[0]),o=K(s)[0];return o&&r.loadServiceSync({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height})||void 0}}})}function kt(){const e=$e();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 zt(e={},t=[]){const{id:n,selector:r}=e,a=A(),s=_(),c=n||a.range,o=c?s.select(i=>i.iiif.entities.Range[c]):void 0;return m(()=>{if(!!o)return r?r(o):o},[o,r,...t])}function Ut(e,t){const n=_(),r=m(()=>ne(n),[n]),a=$(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return m(()=>e?r.getListenersAsProps(e,t):{},[a,e,n,t])}function Ee(e,t){return $((n,r)=>r.get(e.map(a=>({id:a,type:t}))),[e,t])}function Ht(){const e=k();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function Wt(e,t){const n=_(),r=m(()=>ze(n),[n]);return $(()=>{if(!e)return null;const a=r.getAppliedStyles(e.id);return a?t?a[t]:a:void 0},[e,t])}const Re=(e,t=[])=>{const n=_();B(()=>{e(n)},[n,...t])};function Qt(e,t,{canvasId:n,manifestId:r}={}){const a=_(),s=W(),c=m(()=>Ue(a,{imageServiceLoader:s}),[a,s]),[o,i]=I(),l=k(r?{id:r}:void 0),h=D(n?{id:n}:void 0),d=h||l,C=ee(!1);if(B(()=>()=>{C.current=!0},[]),!d)throw new Error("Must be called under a manifest or canvas context.");return Re(E=>{c.getBestThumbnailAtSize(d,e,t).then(u=>{u.best&&!C.current&&i(u.best)})},[d]),o}var Xt=Object.defineProperty,qt=Object.defineProperties,Gt=Object.getOwnPropertyDescriptors,Me=Object.getOwnPropertySymbols,Jt=Object.prototype.hasOwnProperty,Kt=Object.prototype.propertyIsEnumerable,Ve=(e,t,n)=>t in e?Xt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,je=(e,t)=>{for(var n in t||(t={}))Jt.call(t,n)&&Ve(e,n,t[n]);if(Me)for(var n of Me(t))Kt.call(t,n)&&Ve(e,n,t[n]);return e},Ae=(e,t)=>qt(e,Gt(t));function Te(){const e=W(),[t,n]=I({}),r=ee(!1);return B(()=>()=>{r.current=!0},[]),[R((s,{height:c,width:o})=>{if(s){const i=s.id||s["@id"],l=e.loadServiceSync({id:i,width:s.width||o,height:s.height||c});l?s=l:t[i]||(r.current||n(h=>Ae(je({},h),{[i]:"loading"})),e.loadService({id:i,width:s.width||o,height:s.height||c}).then(()=>{r.current||n(h=>Ae(je({},h),{[i]:"done"}))}))}return s},[e,t]),t]}function Y(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function Yt(e,t){const n=[],r=[];for(const a of t){const s=e.get(a.body);for(const c of s){const[o,{selector:i}]=Y(c),l=(o.type||"unknown").toLowerCase();if(l==="choice"){const h=e.get(o.items);s.push(h[0]);continue}n.indexOf(l)===-1&&n.push(l),r.push({type:l,resource:o,target:a.target,selector:i})}}return{types:n,items:r}}var Zt=Object.defineProperty,en=Object.defineProperties,tn=Object.getOwnPropertyDescriptors,Le=Object.getOwnPropertySymbols,nn=Object.prototype.hasOwnProperty,rn=Object.prototype.propertyIsEnumerable,Be=(e,t,n)=>t in e?Zt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,on=(e,t)=>{for(var n in t||(t={}))nn.call(t,n)&&Be(e,n,t[n]);if(Le)for(var n of Le(t))rn.call(t,n)&&Be(e,n,t[n]);return e},sn=(e,t)=>en(e,tn(t));const De={makeChoice:()=>{}},Fe=[{type:"unknown"},De],q=e=>[{type:"unknown",reason:e,annotations:{pages:[]}},De];function an(e){const t=k(),n=D(),r=X(),a=_(),[s,c]=Te(),{enabledPageIds:o}=be((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id),{all:!1}),i=Ee(o,"AnnotationPage"),[l,h]=I((e==null?void 0:e.defaultChoices)||[]);e==null||e.strategies;const d=m(()=>{const f=[];let w=null;const P=[];a.getState();for(const p of r){const v=a.get(p.body);for(const y of v){const[S,{selector:V}]=Y(y),b=(S.type||"unknown").toLowerCase();if(b==="choice"){const L=a.get(S.items),O=l.length?l.map(j=>L.find(G=>G.id===j)).filter(Boolean):[L[0]];O.length===0&&O.push(L[0]),w={type:"single-choice",items:L.map(j=>({id:j.id,label:j.label,selected:O.indexOf(j)!==-1})),label:y.label},v.push(...O);continue}f.indexOf(b)===-1&&f.push(b),P.push({type:b,resource:S,target:p.target,selector:V})}}return{types:f,items:P,choice:w}},[a,c,r,l]),E={makeChoice:R((f,{deselectOthers:w=!0,deselect:P=!1}={})=>{if(d.choice){if(d.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");h(p=>{if(P){const y=p.filter(S=>S!==f);if(y.length===0){const S=d.items[0].resource.id;return S?[S]:[]}return y}if(w)return[f];const v=[...p];if(v.length===0&&d.items.length){const y=d.items[0].resource.id;y&&v.push(y)}return p.indexOf(f)!==-1?p:[...p,f]})}},[d.choice])},u=m(()=>{if(!n)return Fe;if(d.types.length!==1)return q("ComplexTimelineStrategy not yet supported");const f=d.types[0];if(f==="image"){const w=[];for(const P of d.items){const p=P.resource&&P.resource.type==="SpecificResource"?P.resource.source:P.resource;if(!p.id)return q("No resource Identifier");let v;if(p.service){const Z=K(p);Z[0]&&(v=s(Z[0],n))}P.target==="https://bvmm.irht.cnrs.fr/iiif/2309/canvas/canvas-981394#xywh=3949,994,1091,1232"&&(P.target="https://bvmm.irht.cnrs.fr/iiif/4490/canvas/canvas-981394#xywh=3949,994,1091,1232"),v&&v.width&&v.height&&v.profile==="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2"&&(v.profile="http://iiif.io/api/image/2/level2.json",v.sizes=[{width:v.width,height:v.height}],v.tiles=[{width:256,height:256,scaleFactors:[1,2,4,8,16,32]}]);const{selector:y,source:S}=M(P.target);if(S.id!==n.id)continue;const V={type:"BoxSelector",x:0,y:0,width:n.width,height:n.height},b=y?y.type==="TemporalSelector"?{type:"TemporalBoxSelector",startTime:y.startTime,endTime:y.endTime,x:V.x,y:V.y,width:V.width,height:V.height}:y:null,L={type:"BoxSelector",x:0,y:0,width:n.width,height:n.height},O=P.resource.type==="SpecificResource"?M(P.resource):null,j=O&&O.selector&&(O.selector.type==="BoxSelector"||O.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",x:O.selector.x,y:O.selector.y,width:O.selector.width,height:O.selector.height}:L,G={id:p.id,type:"Image",width:b?p.width:n.width,height:b?p.height:n.height,service:v,sizes:v&&v.sizes?v.sizes:p.width&&p.height?[{width:p.width,height:p.height}]:[],target:b||V,selector:j};w.push(G)}return[{type:"images",image:w[0],images:w,choice:d.choice},E]}return f==="audio"?q("Audio strategy not yet supported"):f==="video"?q("Video strategy not yet supported"):Fe},[n,d,a,E.makeChoice]);return m(()=>[sn(on({},u[0]),{annotations:{pages:i}}),u[1]],[u,i])}export{qe as AnnotationContext,se as CanvasContext,Ge as CollectionContext,it as ContextBridge,pe as ImageServiceLoaderContext,ae as ManifestContext,Je as RangeContext,U as ReactVaultContext,T as ResourceProvider,z as ResourceReactContext,nt as SimpleViewerProvider,N as SimpleViewerReactContext,ce as VaultProvider,F as VisibleCanvasReactContext,M as expandTarget,we as flattenAnnotationPageIds,Yt as getPaintables,Q as parseSelector,Y as parseSpecificResource,wt as useAnnotation,be as useAnnotationPageManager,Et as useAnnotationsAtTime,D as useCanvas,Rt as useCanvasClock,Mt as useCollection,ot as useContextBridge,Vt as useDispatch,jt as useEventListener,Ft as useExternalCollection,fe as useExternalManifest,$e as useImageService,W as useImageServiceLoader,kt as useImageTile,Te as useLoadImageService,k as useManifest,X as usePaintingAnnotations,zt as useRange,an as useRenderingStrategy,A as useResourceContext,Ut as useResourceEvents,Ee as useResources,Ht as useSearchService,rt as useSimpleViewer,Wt as useStyles,Qt as useThumbnail,_ as useVault,Re as useVaultEffect,$ as useVaultSelector,de as useVisibleCanvases};
1
+ import g,{useContext as O,useMemo as m,useState as S,useEffect as $,createContext as Qe,useCallback as w,useRef as Q,useLayoutEffect as ke}from"react";import{globalVault as X,Vault as q}from"@iiif/vault";import{useQuery as k}from"react-query";import{ImageServiceLoader as ze,getImageServices as z}from"@atlas-viewer/iiif-image-api";import{createEventsHelper as J,createStylesHelper as K,createThumbnailHelper as Ye}from"@iiif/vault-helpers";import{createAction as y}from"typesafe-actions";import{emptyAnnotationPage as We}from"@iiif/parser";var Ge=Object.defineProperty,Z=Object.getOwnPropertySymbols,Xe=Object.prototype.hasOwnProperty,qe=Object.prototype.propertyIsEnumerable,ee=(e,t,n)=>t in e?Ge(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,te=(e,t)=>{for(var n in t||(t={}))Xe.call(t,n)&&ee(e,n,t[n]);if(Z)for(var n of Z(t))qe.call(t,n)&&ee(e,n,t[n]);return e};const Je={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},D=g.createContext(Je),b=()=>O(D),x=({value:e,children:t})=>{const n=b(),r=m(()=>te(te({},n),e),[e,n]);return g.createElement(D.Provider,{value:r},t)},Ke=({annotation:e,children:t})=>g.createElement(x,{value:{annotation:e}},t),ne=({canvas:e,children:t})=>g.createElement(x,{value:{canvas:e}},t),Ze=({collection:e,children:t})=>g.createElement(x,{value:{collection:e}},t),re=({manifest:e,children:t})=>g.createElement(x,{value:{manifest:e}},t),et=({range:e,children:t})=>g.createElement(x,{value:{range:e}},t),T=g.createContext({vault:null,setVaultInstance:e=>{}}),oe=({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:c})=>{const[i,a]=S(()=>e||(n?X(t):t?new q(t):new q));return g.createElement(T.Provider,{value:{vault:i,setVaultInstance:a}},g.createElement(x,{value:r||{}},c))},h=()=>{const{vault:e}=O(T);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var tt=Object.defineProperty,ie=Object.getOwnPropertySymbols,nt=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,ae=(e,t,n)=>t in e?tt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ot=(e,t)=>{for(var n in t||(t={}))nt.call(t,n)&&ae(e,n,t[n]);if(ie)for(var n of ie(t))rt.call(t,n)&&ae(e,n,t[n]);return e},it=(e,t,n)=>new Promise((r,c)=>{var i=s=>{try{o(n.next(s))}catch(l){c(l)}},a=s=>{try{o(n.throw(s))}catch(l){c(l)}},o=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);o((n=n.apply(e,t)).next())});const se=(e,t={})=>{const n=h(),[r,c]=S(e),i=m(()=>n.get(e)||void 0,[e,n]),{data:a,error:o}=k(["manifest",e],()=>it(void 0,null,function*(){const s=i||(yield n.load(e));return s&&r!==s.id&&c(s.id),s}),ot({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,retry:!1,initialData:i},t));return{isLoaded:!!a,id:r,error:o,manifest:a}};function P(e,t=[]){const n=h(),[r,c]=S(()=>e(n.getState(),n));return $(()=>n.subscribe(i=>e(i,n),i=>{c(i)},!1),t),r}const M=g.createContext([]);function ce(){const e=O(M);return P(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}const F=()=>{},V=Qe({setCurrentCanvasId:F,setCurrentCanvasIndex:F,nextCanvas:F,previousCanvas:F,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),at=e=>{const t=se(e.manifest),[n,r]=S(""),[c,i]=S([]),a=(typeof e.pagingEnabled>"u"||e.pagingEnabled)&&t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");$(()=>{var u,v;t.manifest&&(r((u=t.manifest.items[0])==null?void 0:u.id),i([(v=t.manifest.items[0])==null?void 0:v.id]))},[t.manifest,e.manifest]);const o=m(()=>{var u;return((u=t.manifest)==null?void 0:u.items.map(v=>v.id))||[]},[t.manifest,e.manifest]),s=m(()=>o.indexOf(n),[o,n]),l=w(()=>{if(o.length&&n){if(s===-1||(o[s+2]?s+2===o.length:s===o.length))return;const u=a&&s!==0?o[s+2]:o[s+1],v=a?s!==0?o[s+3]:o[s+2]:null;u&&(r(u),i(v?[u,v]:[u]))}},[a,o,n,s]),p=w(()=>{if(o.length&&n){if(s===0||s===-1)return;const u=a&&s!==1?o[s-2]:o[s-1],v=a&&s!==1?o[s-1]:null;u&&(r(u),i(v?[u,v]:[u]))}},[a,o,n,s]),f=w(u=>{const v=a&&u%2===1?u-1:u,C=o[v],G=a&&v!==0?o[v+1]:null;C&&(r(C),i(A=>{const H=G?[C,G]:[C];if(A.length===A.length){for(let j=0;j<A.length;j++)if(A[j]!==H[j])return H;return A}return H}))},[a,o]),d=w(u=>{const v=o.indexOf(u);v!==-1&&f(v)},[o,f]),_=m(()=>({setCurrentCanvasId:d,nextCanvas:l,previousCanvas:p,currentCanvasIndex:s,totalCanvases:o.length,setCurrentCanvasIndex:f,pagingView:!0}),[l,p,s,o,f,d]);return!t.isLoaded||!t.manifest?g.createElement("div",null,"Loading..."):g.createElement(V.Provider,{value:_},g.createElement(M.Provider,{value:c},g.createElement(re,{manifest:t.manifest.id},g.createElement(ne,{canvas:n},e.children))))};function st(){return O(V)}function ct(){return{VaultContext:O(T),ResourceContext:O(D),SimpleViewerReactContext:O(V),VisibleCanvasReactContext:O(M)}}const lt=e=>g.createElement(oe,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},g.createElement(M.Provider,{value:e.bridge.VisibleCanvasReactContext},g.createElement(V.Provider,{value:e.bridge.SimpleViewerReactContext},e.children))),le=g.createContext(new ze);function N(){return O(le)}const ut=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,ft=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function B(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:r,selectors:c}=B(n);return r&&(t.selector||(t.selector=r),t.selectors.push(...c)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,n]=e.split("#");return n?B({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=ut.exec(e.value);if(t){const r={type:"BoxSelector",spatial:{unit:t[2]==="percent:"?"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(ft);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:[]}}var pt=Object.defineProperty,dt=Object.defineProperties,vt=Object.getOwnPropertyDescriptors,ue=Object.getOwnPropertySymbols,mt=Object.prototype.hasOwnProperty,gt=Object.prototype.propertyIsEnumerable,fe=(e,t,n)=>t in e?pt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,pe=(e,t)=>{for(var n in t||(t={}))mt.call(t,n)&&fe(e,n,t[n]);if(ue)for(var n of ue(t))gt.call(t,n)&&fe(e,n,t[n]);return e},de=(e,t)=>dt(e,vt(t));function I(e,t={}){if(Array.isArray(e))return I(e[0]);if(typeof e=="string"){const[n,r]=e.split("#");return r?I({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 I(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?B(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?I({type:"SpecificResource",source:de(pe({},e),{id:n}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:de(pe({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function ve(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function me(e,t,n){const r=[];let c=null;const i=[];for(const a of t){const o=e.get(a.body);for(const s of o){const[l,{selector:p}]=ve(s),f=(l.type||"unknown").toLowerCase();if(f==="choice"){const d=e.get(l.items),_=n.length?n.map(u=>d.find(v=>v.id===u)).filter(Boolean):[d[0]];_.length===0&&_.push(d[0]),c={type:"single-choice",items:d.map(u=>({id:u.id,label:u.label,selected:_.indexOf(u)!==-1})),label:s.label},o.push(..._);continue}r.indexOf(f)===-1&&r.push(f),i.push({type:f,resource:l,target:a.target,selector:p})}}return{types:r,items:i,choice:c}}const ge={makeChoice:()=>{}},Y={type:"unknown"},E=e=>({type:"unknown",reason:e,annotations:{pages:[]}});function he(e,t,n){const r=[];for(const c of t.items){const i=c.resource&&c.resource.type==="SpecificResource"?c.resource.source:c.resource;if(!i.id)return E("No resource Identifier");let a;if(i.service){const v=z(i);v[0]&&(a=n(v[0],e))}const{selector:o,source:s}=I(c.target);if(s.id!==e.id)continue;const l={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},p=o?o.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:o.temporal,spatial:l.spatial}:o:null,f={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},d=c.resource.type==="SpecificResource"?I(c.resource):null,_=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}}:f,u={id:i.id,type:"Image",width:p?i.width:e.width,height:p?i.height:e.height,service:a,sizes:a&&a.sizes?a.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:p&&p.type!=="PointSelector"?p:l,selector:_};r.push(u)}return{type:"images",image:r[0],images:r,choice:t.choice}}var ht=Object.defineProperty,yt=Object.defineProperties,_t=Object.getOwnPropertyDescriptors,ye=Object.getOwnPropertySymbols,Pt=Object.prototype.hasOwnProperty,Ot=Object.prototype.propertyIsEnumerable,_e=(e,t,n)=>t in e?ht(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,wt=(e,t)=>{for(var n in t||(t={}))Pt.call(t,n)&&_e(e,n,t[n]);if(ye)for(var n of ye(t))Ot.call(t,n)&&_e(e,n,t[n]);return e},St=(e,t)=>yt(e,_t(t));function Et(e={},t=[]){const{id:n,selector:r}=e,c=b(),i=h(),a=n||c.annotation,o=P(l=>a?l.iiif.entities.Annotation[a]:void 0,[a]),s=P(l=>o&&o.body?o.body.map(p=>p?l.iiif.entities[p.type][p.id]:null).filter(Boolean):[],[o]);return m(()=>{if(!o)return;const l=St(wt({},o),{body:s,target:I(o.target,{typeMap:i.getState().iiif.mapping})});return r?r(l):l},[o,r,s,...t])}function L(e={},t=[]){const{id:n,selector:r}=e,c=b();h();const i=n||c.manifest,a=P(o=>i?o.iiif.entities.Manifest[i]:void 0,[i]);return m(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function R(e={},t=[]){const{id:n,selector:r}=e,c=b(),i=n||c.canvas,a=P(o=>i?o.iiif.entities.Canvas[i]:void 0,[i]);return m(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function Ct(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function It(e,t){return P(n=>{const r=[];if(!e)return r;const c=Object.keys(n.iiif.entities.AnnotationPage);for(const i of c)if(!t||t.indexOf(i)!==-1){const a=Ct(n,i);a&&a.views&&a.views[e]&&r.push(i)}return r},[e])}function Pe({canvas:e,manifest:t,all:n,canvases:r}){const c=[];if(t)for(const i of t.annotations)c.indexOf(i.id)===-1&&c.push(i.id);if(n){if(r&&r.length)for(const i of r)for(const a of i.annotations)c.indexOf(a.id)===-1&&c.push(a.id)}else if(e)for(const i of e.annotations)c.indexOf(i.id)===-1&&c.push(i.id);return c}var bt=Object.defineProperty,xt=Object.defineProperties,$t=Object.getOwnPropertyDescriptors,Oe=Object.getOwnPropertySymbols,Rt=Object.prototype.hasOwnProperty,At=Object.prototype.propertyIsEnumerable,we=(e,t,n)=>t in e?bt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Se=(e,t)=>{for(var n in t||(t={}))Rt.call(t,n)&&we(e,n,t[n]);if(Oe)for(var n of Oe(t))At.call(t,n)&&we(e,n,t[n]);return e},Ee=(e,t)=>xt(e,$t(t));function Tt(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function Ce(e,t={}){const n=h(),r=L(),c=R(),i=ce(),a=m(()=>Pe({all:t.all,manifest:r,canvas:c,canvases:i}),[t.all,c,i,r]),o=It(e,t.all?void 0:a),s=w(p=>{!e||n.setMetaValue([p,"annotationPageManager","views"],f=>f&&!f[e]?f:Ee(Se({},f||{}),{[e]:!1}))},[e,n]),l=w((p,f={})=>{if(!e)return;const d=n.getState(),_=[];if(f==null?void 0:f.deselectOthers){const u=Object.keys(d.iiif.entities.AnnotationPage);for(const v of u){const C=Tt(d,v);C&&C.views&&C.views[e]&&_.push(v)}}for(const u of _)s(u);n.setMetaValue([p,"annotationPageManager","views"],u=>u&&u[e]?u:Ee(Se({},u||{}),{[e]:!0}))},[e,s,n]);return{availablePageIds:a,enabledPageIds:o,setPageEnabled:l,setPageDisabled:s}}function U(e={}){const t=R(e.canvasId?{id:e.canvasId}:void 0);return P((n,r)=>{if(!t)return[];const c=r.get(t.items),i=[];for(const a of c)i.push(...r.get(a.items));return i},[t])}function Mt(e,t={}){return U(t)}function Vt(e,t=!1){}function Lt(e,t=[]){const{id:n,selector:r}=e,c=b(),i=n||c.collection,a=P(o=>i?o.iiif.entities.Collection[i]:void 0,[i]);return m(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function Ie(){const t=h().getStore();return m(()=>n=>t.dispatch(n),[t])}function jt(e,t,n,r,c=[]){const i=h(),a=m(()=>J(i),[i]);$(()=>{const o=e;return o?(a.addEventListener(o,t,n,r),()=>{a.removeEventListener(o,t,n)}):()=>{}},[a,e,t,...c])}function Dt(){const e=O(T);return e&&e.vault?e.vault:X()}var Ft=Object.defineProperty,be=Object.getOwnPropertySymbols,Nt=Object.prototype.hasOwnProperty,Bt=Object.prototype.propertyIsEnumerable,xe=(e,t,n)=>t in e?Ft(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ut=(e,t)=>{for(var n in t||(t={}))Nt.call(t,n)&&xe(e,n,t[n]);if(be)for(var n of be(t))Bt.call(t,n)&&xe(e,n,t[n]);return e},Ht=(e,t,n)=>new Promise((r,c)=>{var i=s=>{try{o(n.next(s))}catch(l){c(l)}},a=s=>{try{o(n.throw(s))}catch(l){c(l)}},o=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);o((n=n.apply(e,t)).next())});const Qt=(e,t={})=>{const n=h(),[r,c]=S(e),i=m(()=>n.get(e),[e,n]),{data:a,isFetching:o}=k(`collection:${e}`,()=>Ht(void 0,null,function*(){const s=i||(yield n.loadCollection(e));return s&&c(s.id),s}),Ut({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,initialData:i},t));return{isLoaded:!o,id:r,collection:a}};var kt=(e,t,n)=>new Promise((r,c)=>{var i=s=>{try{o(n.next(s))}catch(l){c(l)}},a=s=>{try{o(n.throw(s))}catch(l){c(l)}},o=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);o((n=n.apply(e,t)).next())});function $e(){const e=R(),t=U(),n=h(),r=N();return k(`canvas-first-image-service:${e?e.id:"undefined"}`,()=>kt(this,null,function*(){if(e&&t.length){const c=t[0],i=n.get(c.body[0]),o=z(i)[0];return o&&(yield r.loadService({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height}))||void 0}}),{refetchOnWindowFocus:!1,refetchOnMount:!1,refetchIntervalInBackground:!1,refetchInterval:!1,initialData:()=>{if(e&&t.length){const c=t[0],i=n.get(c.body[0]),o=z(i)[0];return o&&r.loadServiceSync({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height})||void 0}}})}function zt(){const e=$e();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 Re(e,t=[]){const n=h(),r=U(),[c,i]=S((e==null?void 0:e.defaultChoices)||[]),a=m(()=>me(n,r,c),[n,r,c,...t]),s={makeChoice:w((l,{deselectOthers:p=!0,deselect:f=!1}={})=>{if(a.choice){if(a.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");i(d=>{if(f){const u=d.filter(v=>v!==l);if(u.length===0){const v=a.items[0].resource.id;return v?[v]:[]}return u}if(p)return[l];const _=[...d];if(_.length===0&&a.items.length){const u=a.items[0].resource.id;u&&_.push(u)}return d.indexOf(l)!==-1?d:[...d,l]})}},[a.choice])};return[a,s]}function Yt(e={},t=[]){const{id:n,selector:r}=e,c=b(),i=n||c.range,a=P(o=>i?o.iiif.entities.Range[i]:void 0,[i]);return m(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function Wt(e,t){const n=h(),r=m(()=>J(n),[n]),c=P(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return m(()=>e?r.getListenersAsProps(e,t):{},[c,e,n,t])}function Ae(e,t){return P((n,r)=>r.get(e.map(c=>({id:c,type:t}))),[e,t])}function Gt(){const e=L();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function Xt(){const e=h();return m(()=>K(e),[e])}function qt(e,t){const n=h(),r=m(()=>K(n),[n]);return P(()=>{if(!e)return null;const c=r.getAppliedStyles(e.id);return c?t?c[t]:c:void 0},[e,t])}const Te=(e,t=[])=>{const n=h();$(()=>{e(n)},[n,...t])};function Jt(e,t,{canvasId:n,manifestId:r}={}){const c=h(),i=N(),a=m(()=>Ye(c,{imageServiceLoader:i}),[c,i]),[o,s]=S(),l=L(r?{id:r}:void 0),p=R(n?{id:n}:void 0),f=p||l,d=Q(!1);if($(()=>()=>{d.current=!0},[]),!f)throw new Error("Must be called under a manifest or canvas context.");return Te(_=>{a.getBestThumbnailAtSize(f,e,t).then(u=>{u.best&&!d.current&&s(u.best)})},[f]),o}var Kt=Object.defineProperty,Zt=Object.defineProperties,en=Object.getOwnPropertyDescriptors,Me=Object.getOwnPropertySymbols,tn=Object.prototype.hasOwnProperty,nn=Object.prototype.propertyIsEnumerable,Ve=(e,t,n)=>t in e?Kt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Le=(e,t)=>{for(var n in t||(t={}))tn.call(t,n)&&Ve(e,n,t[n]);if(Me)for(var n of Me(t))nn.call(t,n)&&Ve(e,n,t[n]);return e},je=(e,t)=>Zt(e,en(t));function De(){const e=N(),[t,n]=S({}),r=Q(!1);return $(()=>()=>{r.current=!0},[]),[w((i,{height:a,width:o})=>{if(i){const s=i.id||i["@id"],l=e.loadServiceSync({id:s,width:i.width||o,height:i.height||a});l?i=l:t[s]||(r.current||n(p=>je(Le({},p),{[s]:"loading"})),e.loadService({id:s,width:i.width||o,height:i.height||a}).then(()=>{r.current||n(p=>je(Le({},p),{[s]:"done"}))}))}return i},[e,t]),t]}const rn="@iiif/IMPORT_ENTITIES",on="@iiif/MODIFY_ENTITY_FIELD",an="@iiif/REORDER_ENTITY_FIELD",sn="@iiif/ADD_REFERENCE",cn="@iiif/REMOVE_REFERENCE",ln=y(rn)(),un=y(on)(),fn=y(an)(),pn=y(sn)(),dn=y(cn)(),W={importEntities:ln,modifyEntityField:un,reorderEntityField:fn,addReference:pn,removeReference:dn},vn="@iiif/ADD_MAPPING",mn="@iiif/ADD_MAPPINGS";y(vn)(),y(mn)();const gn="@iiif/SET_META_VALUE",hn="@iiif/SET_META_VALUE_DYNAMIC",yn="@iiif/UNSET_META_VALUE";y(gn)(),y(hn)(),y(yn)();const _n="@iiif/REQUEST_RESOURCE",Pn="@iiif/REQUEST_ERROR",On="@iiif/REQUEST_MISMATCH",wn="@iiif/REQUEST_COMPLETE",Sn="@iiif/REQUEST_OFFLINE_RESOURCE";y(_n)(),y(Pn)(),y(On)(),y(wn)(),y(Sn)();const En="@iiif/BATCH";y(En)();var Cn=Object.defineProperty,In=Object.defineProperties,bn=Object.getOwnPropertyDescriptors,Fe=Object.getOwnPropertySymbols,xn=Object.prototype.hasOwnProperty,$n=Object.prototype.propertyIsEnumerable,Ne=(e,t,n)=>t in e?Cn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Rn=(e,t)=>{for(var n in t||(t={}))xn.call(t,n)&&Ne(e,n,t[n]);if(Fe)for(var n of Fe(t))$n.call(t,n)&&Ne(e,n,t[n]);return e},An=(e,t)=>In(e,bn(t));function Be(e){return typeof e!="string"&&e&&e.bindToVault}function Tn(){const e=h(),t=Q([]),n=Ie(),r=m(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);ke(()=>{const o=An(Rn({},We),{id:r,items:[]});n(W.importEntities({entities:{AnnotationPage:{[o.id]:o}}}))},[r]);const c=P(o=>r?o.iiif.entities.AnnotationPage[r]:null,[r]),i=w((o,s)=>{if(r){if(Be(o)){const f=o;f.__vault||f.bindToVault(e),o=typeof f.source=="string"?f.source:f.source.id,t.current[o]=f}else typeof o!="string"&&(o=o.id);const l=e.get({id:r,type:"AnnotationPage"}),p=e.get({id:o,type:"Annotation"});l&&p&&(l.items.find(f=>f.id===p.id)||n(W.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"},index:s})))}},[r]),a=w(o=>{r&&(Be(o)?o=typeof o.source=="string"?o.source:o.source.id:typeof o!="string"&&(o=o.id),t.current[o]&&t.current[o].beforeRemove(),e.get({id:r,type:"AnnotationPage"})&&n(W.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"}})))},[r]);return[c,{addAnnotation:i,removeAnnotation:a}]}var Mn=Object.defineProperty,Vn=Object.defineProperties,Ln=Object.getOwnPropertyDescriptors,Ue=Object.getOwnPropertySymbols,jn=Object.prototype.hasOwnProperty,Dn=Object.prototype.propertyIsEnumerable,He=(e,t,n)=>t in e?Mn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Fn=(e,t)=>{for(var n in t||(t={}))jn.call(t,n)&&He(e,n,t[n]);if(Ue)for(var n of Ue(t))Dn.call(t,n)&&He(e,n,t[n]);return e},Nn=(e,t)=>Vn(e,Ln(t));function Bn(e){const t=L(),n=R(),r=h(),[c,i]=De(),{enabledPageIds:a}=Ce((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id),{all:!1}),o=Ae(a,"AnnotationPage"),s=(e==null?void 0:e.strategies)||["images","media","complex-timeline"],[l,p]=Re(e,[i]),f=m(()=>{if(!n||l.types.length===0)return Y;if(l.types.length!==1)return s.indexOf("complex-timeline")===-1?E("Complex timeline not supported"):E("ComplexTimelineStrategy not yet supported");const d=l.types[0];return d==="image"?s.indexOf("images")===-1?E("Image not supported"):he(n,l,c):d==="audio"?s.indexOf("media")===-1?E("Media not supported"):E("Audio strategy not yet supported"):d==="video"?s.indexOf("media")===-1?E("Media not supported"):E("Video strategy not yet supported"):Y},[n,l,r,p.makeChoice]);return m(()=>f.type==="unknown"?[f,ge]:[Nn(Fn({},f),{annotations:{pages:o}}),p],[f,o])}export{Ke as AnnotationContext,ne as CanvasContext,Ze as CollectionContext,lt as ContextBridge,le as ImageServiceLoaderContext,re as ManifestContext,et as RangeContext,T as ReactVaultContext,x as ResourceProvider,D as ResourceReactContext,at as SimpleViewerProvider,V as SimpleViewerReactContext,oe as VaultProvider,M as VisibleCanvasReactContext,ge as emptyActions,I as expandTarget,Pe as flattenAnnotationPageIds,he as getImageStrategy,me as getPaintables,B as parseSelector,ve as parseSpecificResource,Y as unknownResponse,E as unsupportedStrategy,Et as useAnnotation,Ce as useAnnotationPageManager,Mt as useAnnotationsAtTime,R as useCanvas,Vt as useCanvasClock,Lt as useCollection,ct as useContextBridge,Ie as useDispatch,jt as useEventListener,Dt as useExistingVault,Qt as useExternalCollection,se as useExternalManifest,$e as useImageService,N as useImageServiceLoader,zt as useImageTile,De as useLoadImageService,L as useManifest,Re as usePaintables,U as usePaintingAnnotations,Yt as useRange,Bn as useRenderingStrategy,b as useResourceContext,Wt as useResourceEvents,Ae as useResources,Gt as useSearchService,st as useSimpleViewer,Xt as useStyleHelper,qt as useStyles,Jt as useThumbnail,h as useVault,Te as useVaultEffect,P as useVaultSelector,Tn as useVirtualAnnotationPage,ce as useVisibleCanvases};
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import React, { FC } from 'react';
2
- import * as _iiif_vault from '@iiif/vault';
3
2
  import { Vault, VaultOptions, ReduxStore, NormalizedEntity, IIIFStore } from '@iiif/vault';
4
- import { CanvasNormalized, AnnotationNormalized, CollectionNormalized, Reference, ManifestNormalized, ImageService, RangeNormalized, SearchService, AnnotationPage, InternationalString, ExternalWebResource, W3CAnnotationTarget, Selector, ContentResource, IIIFExternalWebResource, SpecificResource } from '@iiif/presentation-3';
3
+ import * as _iiif_vault__ from '@iiif/vault/*';
4
+ import { CanvasNormalized, InternationalString, ImageService, AnnotationPageNormalized, ContentResource, IIIFExternalWebResource, SpecificResource, AnnotationNormalized, CollectionNormalized, Reference, ManifestNormalized, RangeNormalized, SearchService, Annotation, ExternalWebResource, W3CAnnotationTarget, Selector } from '@iiif/presentation-3';
5
5
  import { ImageServiceLoader, ImageCandidateRequest, ImageCandidate } from '@atlas-viewer/iiif-image-api';
6
6
  import { QueryOptions } from 'react-query';
7
+ import * as _iiif_vault_helpers from '@iiif/vault-helpers';
7
8
 
8
9
  declare const AnnotationContext: React.FC<{
9
10
  annotation: string;
@@ -44,14 +45,15 @@ declare const ReactVaultContext: React.Context<{
44
45
  }>;
45
46
  declare const VaultProvider: React.FC<{
46
47
  vault?: Vault;
48
+ useGlobal?: boolean;
47
49
  vaultOptions?: VaultOptions;
48
50
  resources?: ResourceContextType;
49
51
  }>;
50
52
 
51
53
  declare function useContextBridge(): {
52
54
  VaultContext: {
53
- vault: _iiif_vault.Vault | null;
54
- setVaultInstance: (vault: _iiif_vault.Vault) => void;
55
+ vault: _iiif_vault__.Vault | null;
56
+ setVaultInstance: (vault: _iiif_vault__.Vault) => void;
55
57
  };
56
58
  ResourceContext: ResourceContextType;
57
59
  SimpleViewerReactContext: {
@@ -75,6 +77,182 @@ declare function useVisibleCanvases(): CanvasNormalized[];
75
77
  declare const ImageServiceLoaderContext: React.Context<ImageServiceLoader>;
76
78
  declare function useImageServiceLoader(): ImageServiceLoader;
77
79
 
80
+ interface SingleChoice {
81
+ type: 'single-choice';
82
+ label?: InternationalString;
83
+ items: Array<{
84
+ id: string;
85
+ label?: InternationalString;
86
+ selected?: true;
87
+ }>;
88
+ }
89
+ interface ComplexChoice {
90
+ type: 'complex-choice';
91
+ items: SingleChoice[];
92
+ }
93
+ declare type ChoiceDescription = SingleChoice | ComplexChoice;
94
+
95
+ interface SupportedSelector {
96
+ type: string;
97
+ temporal?: {
98
+ startTime: number;
99
+ endTime?: number;
100
+ };
101
+ spatial?: {
102
+ unit?: 'percent' | 'pixel';
103
+ x: number;
104
+ y: number;
105
+ width?: number;
106
+ height?: number;
107
+ };
108
+ }
109
+ interface BoxSelector extends SupportedSelector {
110
+ type: 'BoxSelector';
111
+ spatial: {
112
+ unit?: 'percent' | 'pixel';
113
+ x: number;
114
+ y: number;
115
+ width: number;
116
+ height: number;
117
+ };
118
+ }
119
+ interface PointSelector extends SupportedSelector {
120
+ type: 'PointSelector';
121
+ spatial: {
122
+ x: number;
123
+ y: number;
124
+ };
125
+ }
126
+ interface TemporalSelector extends SupportedSelector {
127
+ type: 'TemporalSelector';
128
+ temporal: {
129
+ startTime: number;
130
+ endTime?: number;
131
+ };
132
+ }
133
+ interface TemporalBoxSelector extends SupportedSelector {
134
+ type: 'TemporalBoxSelector';
135
+ spatial: {
136
+ unit?: 'percent' | 'pixel';
137
+ x: number;
138
+ y: number;
139
+ width: number;
140
+ height: number;
141
+ };
142
+ temporal: {
143
+ startTime: number;
144
+ endTime?: number;
145
+ };
146
+ }
147
+ declare type SupportedSelectors = TemporalSelector | BoxSelector | TemporalBoxSelector | PointSelector;
148
+
149
+ declare type ImageWithOptionalService = {
150
+ id: string;
151
+ type: 'Image';
152
+ service?: ImageService;
153
+ width?: number;
154
+ height?: number;
155
+ sizes?: Array<{
156
+ width: number;
157
+ height: number;
158
+ }>;
159
+ target: BoxSelector | TemporalBoxSelector;
160
+ selector: BoxSelector;
161
+ };
162
+ declare type SingleAudio = {
163
+ type: 'Sound';
164
+ url: string;
165
+ format: string;
166
+ duration: number;
167
+ target: TemporalSelector;
168
+ selector: TemporalSelector;
169
+ };
170
+ declare type SingleVideo = {
171
+ type: 'Video';
172
+ url: string;
173
+ format: string;
174
+ duration: number;
175
+ target: TemporalBoxSelector;
176
+ selector: TemporalBoxSelector;
177
+ };
178
+ declare type AudioSequence = {
179
+ type: 'SoundSequence';
180
+ items: SingleAudio[];
181
+ };
182
+ declare type VideoSequence = {
183
+ type: 'VideoSequence';
184
+ items: SingleVideo[];
185
+ };
186
+ declare type AnnotationPageDescription = {
187
+ pages: AnnotationPageNormalized[];
188
+ };
189
+
190
+ declare type MediaStrategy = {
191
+ type: 'media';
192
+ media: SingleAudio | SingleVideo | AudioSequence | VideoSequence;
193
+ choice?: ChoiceDescription;
194
+ annotations?: AnnotationPageDescription;
195
+ };
196
+ declare type ComplexTimelineStrategy = {
197
+ type: 'complex-timeline';
198
+ items: Array<ImageWithOptionalService | SingleAudio | SingleVideo>;
199
+ choice?: ChoiceDescription;
200
+ annotations?: AnnotationPageDescription;
201
+ };
202
+ declare type UnknownStrategy = {
203
+ type: 'unknown';
204
+ reason?: string;
205
+ annotations?: AnnotationPageDescription;
206
+ };
207
+ declare type RenderingStrategy = SingleImageStrategy | MediaStrategy | ComplexTimelineStrategy | UnknownStrategy;
208
+
209
+ declare type ImageServiceLoaderType = (imageService: any | undefined, { height, width }: {
210
+ height: number;
211
+ width: number;
212
+ }) => ImageService | undefined;
213
+ declare function useLoadImageService(): readonly [ImageServiceLoaderType, Record<string, string>];
214
+
215
+ declare type StrategyActions = {
216
+ makeChoice: (id: string, options?: {
217
+ deselectOthers?: boolean;
218
+ deselect?: boolean;
219
+ }) => void;
220
+ };
221
+ declare type UseRenderingStrategy = [RenderingStrategy, StrategyActions];
222
+ declare type UseRenderingStrategyOptions = {
223
+ strategies?: Array<RenderingStrategy['type']>;
224
+ annotationPageManagerId?: string;
225
+ defaultChoices?: string[];
226
+ };
227
+ declare function useRenderingStrategy(options?: UseRenderingStrategyOptions): UseRenderingStrategy;
228
+
229
+ declare function parseSpecificResource(resource: ContentResource): any[];
230
+ interface Paintables {
231
+ choice: ChoiceDescription | null;
232
+ types: string[];
233
+ items: Array<{
234
+ type: string;
235
+ resource: IIIFExternalWebResource | SpecificResource;
236
+ target: any;
237
+ selector: any;
238
+ }>;
239
+ }
240
+ declare function getPaintables(vault: Vault, paintingAnnotations: AnnotationNormalized[], enabledChoices: string[]): Paintables;
241
+ declare const emptyActions: {
242
+ makeChoice: () => void;
243
+ };
244
+ declare const unknownResponse: UseRenderingStrategy[0];
245
+ declare const unsupportedStrategy: (reason: string) => UseRenderingStrategy[0];
246
+
247
+ declare type SingleImageStrategy = {
248
+ type: 'images';
249
+ image: ImageWithOptionalService;
250
+ images: Array<ImageWithOptionalService>;
251
+ choice?: ChoiceDescription;
252
+ annotations?: AnnotationPageDescription;
253
+ };
254
+ declare function getImageStrategy(canvas: CanvasNormalized, paintables: Paintables, loadImageService: ImageServiceLoaderType): RenderingStrategy;
255
+
78
256
  declare function useAnnotation(options?: {
79
257
  id: string;
80
258
  }): AnnotationNormalized | undefined;
@@ -121,6 +299,8 @@ declare function useDispatch(): ReduxStore['dispatch'];
121
299
  declare type SupportedEvents = 'onClick';
122
300
  declare function useEventListener<T>(resource: Reference, name: SupportedEvents, listener: (e: any, resource: T) => void, scope?: string[], deps?: any[]): void;
123
301
 
302
+ declare function useExistingVault(): any;
303
+
124
304
  declare const useExternalCollection: (id: string, config?: QueryOptions<CollectionNormalized>) => {
125
305
  id: string;
126
306
  isLoaded: boolean;
@@ -159,6 +339,15 @@ declare function useManifest<T>(options?: {
159
339
  selector: (manifest: ManifestNormalized) => T;
160
340
  }, deps?: any[]): T | undefined;
161
341
 
342
+ declare function usePaintables(options?: {
343
+ defaultChoices?: string[];
344
+ }, deps?: any[]): readonly [Paintables, {
345
+ makeChoice: (id: string, { deselectOthers, deselect }?: {
346
+ deselectOthers?: boolean | undefined;
347
+ deselect?: boolean | undefined;
348
+ }) => void;
349
+ }];
350
+
162
351
  declare function usePaintingAnnotations(options?: {
163
352
  canvasId?: string;
164
353
  }): AnnotationNormalized[];
@@ -177,6 +366,8 @@ declare function useResources<Type>(ids: string[], type: string): Type[];
177
366
 
178
367
  declare function useSearchService(): SearchService | undefined;
179
368
 
369
+ declare function useStyleHelper(): _iiif_vault_helpers.StyledHelper<_iiif_vault_helpers.StyleDefinition>;
370
+
180
371
  declare function useStyles<Style extends Record<string, Record<string, any>>>(resource: undefined | Reference<any>): Style;
181
372
  declare function useStyles<Style extends Record<string, any>>(resource: undefined | Reference<any>, scope: string): Style;
182
373
 
@@ -185,151 +376,23 @@ declare function useThumbnail(request: ImageCandidateRequest, dereference?: bool
185
376
  manifestId?: string;
186
377
  }): ImageCandidate | undefined;
187
378
 
188
- declare function useLoadImageService(): readonly [(imageService: any | undefined, { height, width }: {
189
- height: number;
190
- width: number;
191
- }) => ImageService | undefined, Record<string, string>];
192
-
193
379
  declare const useVault: () => Vault;
194
380
 
195
381
  declare const useVaultEffect: (callback: (vault: Vault) => void, deps?: any[]) => void;
196
382
 
197
383
  declare function useVaultSelector<T>(selector: (state: IIIFStore, vault: Vault) => T, deps?: any[]): T;
198
384
 
199
- declare type BoxSelector = {
200
- type: 'BoxSelector';
201
- unit?: 'percent' | 'pixel';
202
- x: number;
203
- y: number;
204
- width: number;
205
- height: number;
206
- };
207
- declare type TemporalSelector = {
208
- type: 'TemporalSelector';
209
- startTime: number;
210
- endTime?: number;
211
- };
212
- declare type TemporalBoxSelector = {
213
- type: 'TemporalBoxSelector';
214
- x: number;
215
- y: number;
216
- width: number;
217
- height: number;
218
- startTime: number;
219
- endTime?: number;
220
- };
221
- declare type SupportedSelectors = TemporalSelector | BoxSelector | TemporalBoxSelector;
222
-
223
- declare type ImageWithOptionalService = {
224
- id: string;
225
- type: 'Image';
226
- service?: ImageService;
227
- width?: number;
228
- height?: number;
229
- sizes?: Array<{
230
- width: number;
231
- height: number;
232
- }>;
233
- target: BoxSelector | TemporalBoxSelector;
234
- selector: BoxSelector;
235
- };
236
- declare type SingleAudio = {
237
- type: 'Sound';
238
- url: string;
239
- format: string;
240
- duration: number;
241
- target: TemporalSelector;
242
- selector: TemporalSelector;
243
- };
244
- declare type SingleVideo = {
245
- type: 'Video';
246
- url: string;
247
- format: string;
248
- duration: number;
249
- target: TemporalBoxSelector;
250
- selector: TemporalBoxSelector;
251
- };
252
- declare type AudioSequence = {
253
- type: 'SoundSequence';
254
- items: SingleAudio[];
255
- };
256
- declare type VideoSequence = {
257
- type: 'VideoSequence';
258
- items: SingleVideo[];
259
- };
260
- declare type AnnotationPageDescription = {
261
- pages: AnnotationPage[];
262
- };
263
-
264
- declare type SingleChoice = {
265
- type: 'single-choice';
266
- label?: InternationalString;
267
- items: Array<{
385
+ interface VaultActivatedAnnotation {
386
+ __vault?: Vault;
387
+ bindToVault(vault: Vault): void;
388
+ source: string | {
268
389
  id: string;
269
- label?: InternationalString;
270
- selected?: true;
271
- }>;
272
- };
273
- declare type ComplexChoice = {
274
- type: 'complex-choice';
275
- items: SingleChoice[];
276
- };
277
- declare type ChoiceDescription = SingleChoice | ComplexChoice;
278
-
279
- declare type SingleImageStrategy = {
280
- type: 'images';
281
- image: ImageWithOptionalService;
282
- images: Array<ImageWithOptionalService>;
283
- choice?: ChoiceDescription;
284
- annotations?: AnnotationPageDescription;
285
- };
286
- declare type MediaStrategy = {
287
- type: 'media';
288
- media: SingleAudio | SingleVideo | AudioSequence | VideoSequence;
289
- choice?: ChoiceDescription;
290
- annotations?: AnnotationPageDescription;
291
- };
292
- declare type ComplexTimelineStrategy = {
293
- type: 'complex-timeline';
294
- items: Array<ImageWithOptionalService | SingleAudio | SingleVideo>;
295
- choice?: ChoiceDescription;
296
- annotations?: AnnotationPageDescription;
297
- };
298
- declare type UnknownStrategy = {
299
- type: 'unknown';
300
- reason?: string;
301
- annotations?: AnnotationPageDescription;
302
- };
303
- declare type RenderingStrategy = SingleImageStrategy | MediaStrategy | ComplexTimelineStrategy | UnknownStrategy;
304
-
305
- declare type StrategyActions = {
306
- makeChoice: (id: string, options?: {
307
- deselectOthers?: boolean;
308
- deselect?: boolean;
309
- }) => void;
310
- };
311
- declare type UseRenderingStrategy = [RenderingStrategy, StrategyActions];
312
- declare type UseRenderingStrategyOptions = {
313
- strategies?: Array<RenderingStrategy['type']>;
314
- annotationPageManagerId?: string;
315
- defaultChoices?: string[];
316
- };
317
- declare function useRenderingStrategy(options?: UseRenderingStrategyOptions): UseRenderingStrategy;
318
-
319
- declare type SimpleViewerContext = {
320
- setCurrentCanvasId: (newId: string | ((prev: string) => string)) => void;
321
- setCurrentCanvasIndex: (newId: number | ((prev: number) => number)) => void;
322
- currentCanvasIndex: number;
323
- pagingView: boolean;
324
- totalCanvases: number;
325
- nextCanvas: () => void;
326
- previousCanvas: () => void;
327
- };
328
- declare const SimpleViewerReactContext: React.Context<SimpleViewerContext>;
329
- declare const SimpleViewerProvider: FC<{
330
- manifest: string;
331
- }>;
332
- declare function useSimpleViewer(): SimpleViewerContext;
390
+ };
391
+ }
392
+ declare function useVirtualAnnotationPage(): readonly [AnnotationPageNormalized | null, {
393
+ readonly addAnnotation: (id: string | Annotation | VaultActivatedAnnotation | AnnotationNormalized, atIndex?: number | undefined) => void;
394
+ readonly removeAnnotation: (id: string | Annotation | VaultActivatedAnnotation | AnnotationNormalized) => void;
395
+ }];
333
396
 
334
397
  declare type SupportedTarget = {
335
398
  type: 'SpecificResource';
@@ -362,15 +425,20 @@ declare type ParsedSelector = {
362
425
  };
363
426
  declare function parseSelector(source: Selector | Selector[]): ParsedSelector;
364
427
 
365
- declare function parseSpecificResource(resource: ContentResource): any[];
366
- declare function getPaintables(vault: Vault, paintingAnnotations: AnnotationNormalized[]): {
367
- types: string[];
368
- items: {
369
- type: string;
370
- resource: IIIFExternalWebResource | SpecificResource;
371
- target: any;
372
- selector: any;
373
- }[];
428
+ declare type SimpleViewerContext = {
429
+ setCurrentCanvasId: (newId: string | ((prev: string) => string)) => void;
430
+ setCurrentCanvasIndex: (newId: number | ((prev: number) => number)) => void;
431
+ currentCanvasIndex: number;
432
+ pagingView: boolean;
433
+ totalCanvases: number;
434
+ nextCanvas: () => void;
435
+ previousCanvas: () => void;
374
436
  };
437
+ declare const SimpleViewerReactContext: React.Context<SimpleViewerContext>;
438
+ declare const SimpleViewerProvider: FC<{
439
+ manifest: string;
440
+ pagingEnabled?: boolean;
441
+ }>;
442
+ declare function useSimpleViewer(): SimpleViewerContext;
375
443
 
376
- export { AnnotationContext, AnnotationPageDescription, AudioSequence, BoxSelector, CanvasContext, ChoiceDescription, CollectionContext, ComplexChoice, ComplexTimelineStrategy, ContextBridge, ImageServiceLoaderContext, ImageWithOptionalService, ManifestContext, MediaStrategy, ParsedSelector, RangeContext, ReactVaultContext, RenderingStrategy, ResourceContextType, ResourceProvider, ResourceReactContext, SimpleViewerProvider, SimpleViewerReactContext, SingleAudio, SingleChoice, SingleImageStrategy, SingleVideo, StrategyActions, SupportedSelectors, SupportedTarget, TemporalBoxSelector, TemporalSelector, UnknownStrategy, UseRenderingStrategy, UseRenderingStrategyOptions, VaultProvider, VideoSequence, VisibleCanvasReactContext, expandTarget, flattenAnnotationPageIds, getPaintables, parseSelector, parseSpecificResource, useAnnotation, useAnnotationPageManager, useAnnotationsAtTime, useCanvas, useCanvasClock, useCollection, useContextBridge, useDispatch, useEventListener, useExternalCollection, useExternalManifest, useImageService, useImageServiceLoader, useImageTile, useLoadImageService, useManifest, usePaintingAnnotations, useRange, useRenderingStrategy, useResourceContext, useResourceEvents, useResources, useSearchService, useSimpleViewer, useStyles, useThumbnail, useVault, useVaultEffect, useVaultSelector, useVisibleCanvases };
444
+ export { AnnotationContext, AnnotationPageDescription, AudioSequence, BoxSelector, CanvasContext, ChoiceDescription, CollectionContext, ComplexChoice, ComplexTimelineStrategy, ContextBridge, ImageServiceLoaderContext, ImageServiceLoaderType, ImageWithOptionalService, ManifestContext, MediaStrategy, Paintables, ParsedSelector, PointSelector, RangeContext, ReactVaultContext, RenderingStrategy, ResourceContextType, ResourceProvider, ResourceReactContext, SimpleViewerProvider, SimpleViewerReactContext, SingleAudio, SingleChoice, SingleImageStrategy, SingleVideo, StrategyActions, SupportedSelector, SupportedSelectors, SupportedTarget, TemporalBoxSelector, TemporalSelector, UnknownStrategy, UseRenderingStrategy, UseRenderingStrategyOptions, VaultActivatedAnnotation, VaultProvider, VideoSequence, VisibleCanvasReactContext, emptyActions, expandTarget, flattenAnnotationPageIds, getImageStrategy, getPaintables, parseSelector, parseSpecificResource, unknownResponse, unsupportedStrategy, useAnnotation, useAnnotationPageManager, useAnnotationsAtTime, useCanvas, useCanvasClock, useCollection, useContextBridge, useDispatch, useEventListener, useExistingVault, useExternalCollection, useExternalManifest, useImageService, useImageServiceLoader, useImageTile, useLoadImageService, useManifest, usePaintables, usePaintingAnnotations, useRange, useRenderingStrategy, useResourceContext, useResourceEvents, useResources, useSearchService, useSimpleViewer, useStyleHelper, useStyles, useThumbnail, useVault, useVaultEffect, useVaultSelector, useVirtualAnnotationPage, useVisibleCanvases };
package/dist/index.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(g,v){typeof exports=="object"&&typeof module<"u"?v(exports,require("react"),require("@iiif/vault")):typeof define=="function"&&define.amd?define(["exports","react","@iiif/vault"],v):(g=typeof globalThis<"u"?globalThis:g||self,v(g.ReactIIIFVault={},g.React,g.IIIFVault))})(this,function(g,v,be){"use strict";function In(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var I=In(v),_n=Object.defineProperty,Ce=Object.getOwnPropertySymbols,On=Object.prototype.hasOwnProperty,bn=Object.prototype.propertyIsEnumerable,Ee=(e,t,n)=>t in e?_n(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,xe=(e,t)=>{for(var n in t||(t={}))On.call(t,n)&&Ee(e,n,t[n]);if(Ce)for(var n of Ce(t))bn.call(t,n)&&Ee(e,n,t[n]);return e};const Cn={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},ee=I.default.createContext(Cn),R=()=>v.useContext(ee),$=({value:e,children:t})=>{const n=R(),i=v.useMemo(()=>xe(xe({},n),e),[e,n]);return I.default.createElement(ee.Provider,{value:i},t)},En=({annotation:e,children:t})=>I.default.createElement($,{value:{annotation:e}},t),Pe=({canvas:e,children:t})=>I.default.createElement($,{value:{canvas:e}},t),xn=({collection:e,children:t})=>I.default.createElement($,{value:{collection:e}},t),Fe=({manifest:e,children:t})=>I.default.createElement($,{value:{manifest:e}},t),Pn=({range:e,children:t})=>I.default.createElement($,{value:{range:e}},t),te=I.default.createContext({vault:null,setVaultInstance:e=>{}}),Ae=({vault:e,vaultOptions:t,resources:n,children:i})=>{const[o,r]=v.useState(()=>e||(t?new be.Vault(t):new be.Vault));return I.default.createElement(te.Provider,{value:{vault:o,setVaultInstance:r}},I.default.createElement($,{value:n||{}},i))};function j(){return j=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},j.apply(this,arguments)}function ce(e,t){if(e==null)return{};var n={},i=Object.keys(e),o,r;for(r=0;r<i.length;r++)o=i[r],!(t.indexOf(o)>=0)&&(n[o]=e[o]);return n}var ue="loading",le="error",Me="success",Fn=0,An=function(){return Fn++},Mn={},ne=typeof window>"u",T=function(){},jn=function(t){return t},fe=console||{error:T,warn:T,log:T};function Ln(){var e=I.default.useRef(null);return e.current===null&&(e.current=An()),e.current}function Tn(e){var t=I.default.useRef();return t.current=e,I.default.useCallback(function(){return t.current},[])}function he(e,t){return typeof e=="function"?e(t):e}function kn(e,t){return je(t)?Object.assign.apply(Object,[{}].concat(Object.keys(t).sort().map(function(n){var i;return i={},i[n]=t[n],i}))):t}function Vn(e){return JSON.stringify(e,kn)}function je(e){return e&&typeof e=="object"&&!Array.isArray(e)}function Le(e,t){return e===t?!0:typeof e!=typeof t?!1:typeof e=="object"?!Object.keys(t).some(function(n){return!Le(e[n],t[n])}):!1}function de(){return typeof document>"u"||document.visibilityState===void 0||document.visibilityState==="visible"||document.visibilityState==="prerender"}function Rn(){return navigator.onLine===void 0||navigator.onLine}function Te(e){if(je(e[0]))if(e[0].hasOwnProperty("queryKey")&&e[0].hasOwnProperty("queryFn")){var t=e[0],n=t.queryKey,i=t.variables,o=i===void 0?[]:i,r=t.queryFn,a=t.config,s=a===void 0?{}:a;return[n,o,r,s]}else throw new Error("queryKey and queryFn keys are required.");if(typeof e[2]=="function"){var u=e[0],l=e[1],f=l===void 0?[]:l,d=e[2],m=e[3],p=m===void 0?{}:m;return[u,f,d,p]}var c=e[0],h=e[1],w=e[2],y=w===void 0?{}:w;return[c,[],h,y]}function $n(e){var t=I.default.useRef(!1);return I.default[ne?"useEffect":"useLayoutEffect"](function(){return t.current=!0,function(){return t.current=!1}},[]),I.default.useCallback(function(){return t.current?e.apply(void 0,arguments):void 0},[e])}function Dn(e){if((e.config.suspense||e.config.useErrorBoundary)&&e.status===le)throw setTimeout(function(){e.query.state.status="loading"}),e.error;if(e.config.suspense&&e.status===ue)throw e.query.wasSuspended=!0,e.refetch()}function pe(e,t){if(e===t)return!0;if(e&&t&&typeof e=="object"&&typeof t=="object"){var n,i,o;if(Array.isArray(e)){if(n=e.length,n!=t.length)return!1;for(i=n;i--!==0;)if(!pe(e[i],t[i]))return!1;return!0}if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===t.valueOf();if(o=Object.keys(e),n=o.length,n!==Object.keys(t).length)return!1;for(i=n;i--!==0;)if(!Object.prototype.hasOwnProperty.call(t,o[i]))return!1;for(i=n;i--!==0;){var r=o[i];if(!pe(e[r],t[r]))return!1}return!0}return e!==e&&t!==t}var qn=I.default.createContext(),Wn={retry:3,retryDelay:function(t){return Math.min(1e3*Math.pow(2,t),3e4)},staleTime:0,cacheTime:5*60*1e3,refetchAllOnWindowFocus:!0,refetchInterval:!1,suspense:!1,queryKeySerializerFn:ke,queryFnParamsFilter:jn,throwOnError:!1,useErrorBoundary:void 0,onMutate:T,onSuccess:T,onError:T,onSettled:T,refetchOnMount:!0,isDataEqual:pe},U={current:Wn};function Nn(){return I.default.useContext(qn)||U.current}function ke(e){if(!e)return[];if(typeof e=="function")try{return ke(e())}catch{return[]}typeof e=="string"&&(e=[e]);var t=Vn(e);return e=JSON.parse(t),[t,e]}function D(e,t,n){return n?t?t(e):e:((!e||!e.then)&&(e=Promise.resolve(e)),t?e.then(t):e)}function J(e,t){try{var n=e()}catch(i){return t(i)}return n&&n.then?n.then(void 0,t):n}function q(e){return function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];try{return Promise.resolve(e.apply(this,t))}catch(i){return Promise.reject(i)}}}function Ve(e,t){var n=e();return n&&n.then?n.then(t):t(n)}var Re=Qn(),zn=I.default.createContext(Re),Gn=[Re];function Hn(){return I.default.useContext(zn)}var $e={},De={},qe={},We={},Ne={},ze={},Ge={},He={};function Qn(){var e=[],t={queries:{},isFetching:0},n=function(){t.isFetching=Object.values(t.queries).reduce(function(a,s){return s.state.isFetching?a+1:a},0),e.forEach(function(a){return a(t)})};t.subscribe=function(r){return e.push(r),function(){e.splice(e.indexOf(r),1)}},t.clear=function(){Object.values(t.queries).forEach(function(r){return r.clear()}),t.queries={},n()};var i=function(a,s){var u=s===void 0?{}:s,l=u.exact;if(typeof a!="function"){var f=U.current.queryKeySerializerFn(a),d=f[0],m=f[1];a=function(c){return l?c.queryHash===d:Le(c.queryKey,m)}}return Object.values(t.queries).filter(a)};t.getQueries=i,t.getQuery=function(r){return i(r,{exact:!0})[0]},t.getQueryData=function(r){var a;return(a=t.getQuery(r))==null?void 0:a.state.data},t.removeQueries=function(r,a){var s=a===void 0?{}:a,u=s.exact,l=i(r,{exact:u});l.forEach(function(f){clearTimeout(f.staleTimeout),delete t.queries[f.queryHash]}),l.length&&n()},t.cancelQueries=function(r,a){var s=a===void 0?{}:a,u=s.exact,l=i(r,{exact:u});l.forEach(function(f){f.cancel()}),l.length&&n()},t.refetchQueries=q(function(r,a){var s=a===void 0?{}:a,u=s.exact,l=s.throwOnError,f=s.force,d=r===!0?Object.values(t.queries):i(r,{exact:u});return J(function(){return D(Promise.all(d.map(function(m){return m.fetch({force:f})})))},function(m){if(l)throw m})}),t._buildQuery=function(r,a,s,u){var l=u.queryKeySerializerFn(r),f=l[0],d=l[1],m=t.queries[f];return m?(Object.assign(m,{queryVariables:a,queryFn:s}),m.config=j({},m.config,u)):(m=o({cache:t,queryKey:d,queryHash:f,queryVariables:a,queryFn:s,config:u}),!ne&&m.state.data&&(m.scheduleStaleTimeout(),m.heal(),m.scheduleGarbageCollection()),m.queryHash&&(ne||(t.queries[f]=m,setTimeout(function(){n()})))),m},t.prefetchQuery=q(function(){for(var r=!1,a=arguments.length,s=new Array(a),u=0;u<a;u++)s[u]=arguments[u];var l=Te(s),f=l[0],d=l[1],m=l[2],p=l[3],c=p.force,h=ce(p,["force"]);h=j({},U.current,h);var w=t._buildQuery(f,d,m,h);return Ve(function(){if(w.state.isStale||c)return J(function(){return D(w.fetch({force:c}),function(y){return w.wasPrefetched=!0,r=!0,y})},function(y){if(h.throwOnError)throw y})},function(y){return r?y:w.state.data})}),t.setQueryData=function(r,a,s){var u=s===void 0?{}:s,l=u.exact,f=ce(u,["exact"]),d=i(r,{exact:l});!d.length&&typeof r!="function"&&(d=[t._buildQuery(r,void 0,function(){return Promise.resolve()},j({},U.current,f))]),d.forEach(function(m){return m.setData(a)})};function o(r){var a=r.cache,s=r.config.queryReducer||Bn,u=typeof r.queryHash>"u",l=typeof r.config.initialData=="function"?r.config.initialData():r.config.initialData,f=typeof l<"u",d=u?!0:!f,m=r.config.manual,p=u||m||f?Me:ue,c=j({},r,{instances:[],state:s(void 0,{type:$e,initialStatus:p,initialData:l,hasInitialData:f,isStale:d,manual:m})}),h=function(S){c.state=s(c.state,S),c.instances.forEach(function(_){return _.onStateUpdate(c.state)}),n()};c.scheduleStaleTimeout=function(){c.config.staleTime!==1/0&&(c.staleTimeout=setTimeout(function(){a.getQuery(c.queryKey)&&h({type:qe})},c.config.staleTime))},c.scheduleGarbageCollection=function(){c.config.cacheTime!==1/0&&(h({type:We}),c.cacheTimeout=setTimeout(function(){t.removeQueries(function(y){return y.state.markedForGarbageCollection&&y.queryHash===c.queryHash})},typeof c.state.data>"u"&&c.state.status!=="error"?0:c.config.cacheTime))},c.heal=function(){clearTimeout(c.cacheTimeout),c.cancelled=null},c.cancel=function(){c.cancelled=Mn,c.cancelPromises&&c.cancelPromises(),delete c.promise,n()},c.updateInstance=function(y){var S=c.instances.find(function(_){return _.id===y.id});S?Object.assign(S,y):(S=j({onStateUpdate:T},y),c.instances.push(y))},c.subscribe=function(y){return c.heal(),function(){c.instances=c.instances.filter(function(S){return S.id!==y}),c.instances.length||(c.cancel(),c.scheduleGarbageCollection())}};var w=q(function(y){for(var S=arguments.length,_=new Array(S>1?S-1:0),O=1;O<S;O++)_[O-1]=arguments[O];return J(function(){var P=y.apply(void 0,c.config.queryFnParamsFilter(_));return c.cancelPromises=function(){return P.cancel==null?void 0:P.cancel()},D(P,function(F){if(delete c.shouldContinueRetryOnFocus,delete c.cancelPromises,c.cancelled)throw c.cancelled;return F})},function(P){var F=!1;if(delete c.cancelPromises,c.cancelled)throw c.cancelled;return h({type:De}),Ve(function(){if(c.config.retry===!0||c.state.failureCount<=c.config.retry||typeof c.config.retry=="function"&&c.config.retry(c.state.failureCount,P)){if(!de())return c.shouldContinueRetryOnFocus=!0,F=!0,new Promise(T);delete c.shouldContinueRetryOnFocus;var b=he(c.config.retryDelay,c.state.failureCount);return F=!0,D(new Promise(function(C,M){setTimeout(q(function(){return c.cancelled?M(c.cancelled):J(function(){return D(w.apply(void 0,[y].concat(_)),function(L){if(c.cancelled)return M(c.cancelled);C(L)})},function(L){if(c.cancelled)return M(c.cancelled);M(L)})}),b)}))}},function(b){if(F)return b;throw P})})});return c.fetch=q(function(y){var S=y===void 0?{}:y,_=S.force,O=S.__queryFn,P=O===void 0?c.queryFn:O;if(!(!c.queryHash||!c.state.isStale&&!_))return c.promise||(c.promise=q(function(){c.cancelled=null;var F=[].concat(c.instances);return c.wasSuspended&&F.unshift(c.suspenseInstance),J(function(){return h({type:Ne}),D(w.apply(void 0,[P].concat(c.queryKey,c.queryVariables)),function(b){return c.setData(function(C){return c.config.isDataEqual(C,b)?C:b}),F.forEach(function(C){return C.onSuccess&&C.onSuccess(c.state.data)}),F.forEach(function(C){return C.onSettled&&C.onSettled(c.state.data,null)}),delete c.promise,b})},function(b){if(h({type:Ge,cancelled:b===c.cancelled,error:b}),delete c.promise,b!==c.cancelled)throw F.forEach(function(C){return C.onError&&C.onError(b)}),F.forEach(function(C){return C.onSettled&&C.onSettled(void 0,b)}),b})})()),c.promise}),c.setState=function(y){return h({type:He,updater:y})},c.setData=function(y){h({type:ze,updater:y}),clearTimeout(c.staleTimeout),c.scheduleStaleTimeout()},c.clear=function(){clearTimeout(c.staleTimeout),clearTimeout(c.cacheTimeout),c.cancel()},c}return t}function Bn(e,t){switch(t.type){case $e:return{status:t.initialStatus,error:null,isFetching:t.hasInitialData||t.manual?!1:t.initialStatus==="loading",canFetchMore:!1,failureCount:0,isStale:t.isStale,markedForGarbageCollection:!1,data:t.initialData,updatedAt:t.hasInitialData?Date.now():0};case De:return j({},e,{failureCount:e.failureCount+1});case qe:return j({},e,{isStale:!0});case We:return j({},e,{markedForGarbageCollection:!0});case Ne:return j({},e,{status:e.status===le?ue:e.status,isFetching:!0,failureCount:0});case ze:return j({},e,{status:Me,data:he(t.updater,e.data),error:null,isStale:!1,isFetching:!1,canFetchMore:t.canFetchMore,updatedAt:Date.now(),failureCount:0});case Ge:return j({},e,{isFetching:!1,isStale:!0},!t.cancelled&&{status:le,error:t.error});case He:return he(t.updater,e);default:throw new Error}}var Qe="visibilitychange",Be="focus",Un=function(){var t=U.current.refetchAllOnWindowFocus;de()&&Rn()&&Gn.forEach(function(n){return n.refetchQueries(function(i){return!i.instances.length||i.config.manual===!0?!1:i.shouldContinueRetryOnFocus?(delete i.promise,!0):typeof i.config.refetchOnWindowFocus>"u"?t:i.config.refetchOnWindowFocus}).catch(fe.error)})},ve;function Jn(e){ve&&ve(),ve=e(Un)}Jn(function(e){var t;if(!ne&&((t=window)==null?void 0:t.addEventListener))return window.addEventListener(Qe,e,!1),window.addEventListener(Be,e,!1),function(){window.removeEventListener(Qe,e),window.removeEventListener(Be,e)}});function Kn(e,t,n){return n?t?t(e):e:((!e||!e.then)&&(e=Promise.resolve(e)),t?e.then(t):e)}function Xn(e,t){try{var n=e()}catch(i){return t(i)}return n&&n.then?n.then(void 0,t):n}function Yn(e){return function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];try{return Promise.resolve(e.apply(this,t))}catch(i){return Promise.reject(i)}}}function Zn(e,t,n,i){i===void 0&&(i={});var o=Ln();i=j({},Nn(),i);var r=Hn(),a=I.default.useRef(),s=r._buildQuery(e,t,n,i),u=a.current&&typeof a.current.queryHash>"u"&&typeof s.queryHash>"u";u||(a.current=s);var l=a.current,f=I.default.useState(),d=f[1],m=$n(d),p=Tn(i),c=I.default.useCallback(Yn(function(h){var w=h===void 0?{}:h,y=w.throwOnError,S=ce(w,["throwOnError"]);return Xn(function(){return Kn(l.fetch(S))},function(_){if(y)throw _})}),[l]);return l.suspenseInstance={onSuccess:function(w){return p().onSuccess(w)},onError:function(w){return p().onError(w)},onSettled:function(w,y){return p().onSettled(w,y)}},I.default.useEffect(function(){return l.updateInstance({id:o,onStateUpdate:function(){return m({})},onSuccess:function(w){return p().onSuccess(w)},onError:function(w){return p().onError(w)},onSettled:function(w,y){return p().onSettled(w,y)}}),l.subscribe(o)},[p,o,l,m]),I.default.useEffect(function(){!p().manual&&!l.wasPrefetched&&!l.wasSuspended&&l.state.isStale&&(p().refetchOnMount||l.instances.length===1)&&c().catch(fe.error),l.wasPrefetched=!1,l.wasSuspended=!1},[p,l,c]),I.default.useEffect(function(){var h=a.current;if(i.refetchInterval&&(!h.currentRefetchInterval||i.refetchInterval<h.currentRefetchInterval))return h.currentRefetchInterval=i.refetchInterval,clearInterval(h.refetchIntervalId),h.refetchIntervalId=setInterval(function(){(de()||i.refetchIntervalInBackground)&&c().catch(fe.error)},i.refetchInterval),function(){clearInterval(h.refetchIntervalId),delete h.refetchIntervalId,delete h.currentRefetchInterval}},[i.refetchInterval,i.refetchIntervalInBackground,c]),j({},l.state,{config:i,query:l,refetch:c})}function ge(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var i=Zn.apply(void 0,Te(t));return Dn(i),i}const A=()=>{const{vault:e}=v.useContext(te);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var ei=Object.defineProperty,Ue=Object.getOwnPropertySymbols,ti=Object.prototype.hasOwnProperty,ni=Object.prototype.propertyIsEnumerable,Je=(e,t,n)=>t in e?ei(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ii=(e,t)=>{for(var n in t||(t={}))ti.call(t,n)&&Je(e,n,t[n]);if(Ue)for(var n of Ue(t))ni.call(t,n)&&Je(e,n,t[n]);return e},ri=(e,t,n)=>new Promise((i,o)=>{var r=u=>{try{s(n.next(u))}catch(l){o(l)}},a=u=>{try{s(n.throw(u))}catch(l){o(l)}},s=u=>u.done?i(u.value):Promise.resolve(u.value).then(r,a);s((n=n.apply(e,t)).next())});const Ke=(e,t={})=>{const n=A(),[i,o]=v.useState(e),r=v.useMemo(()=>n.get(e)||void 0,[e,n]),{data:a,error:s}=ge(["manifest",e],()=>ri(void 0,null,function*(){const u=r||(yield n.load(e));return u&&i!==u.id&&o(u.id),u}),ii({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,retry:!1,initialData:r},t));return{isLoaded:!!a,id:i,error:s,manifest:a}};function k(e,t=[]){const n=A(),[i,o]=v.useState(()=>e(n.getState(),n));return v.useEffect(()=>n.subscribe(r=>e(r,n),r=>{o(r)},!0),t),i}const K=I.default.createContext([]);function Xe(){const e=v.useContext(K);return k(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}const ie=()=>{},X=v.createContext({setCurrentCanvasId:ie,setCurrentCanvasIndex:ie,nextCanvas:ie,previousCanvas:ie,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),oi=e=>{const t=Ke(e.manifest),[n,i]=v.useState(""),[o,r]=v.useState([]),a=t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");v.useEffect(()=>{var c,h;t.manifest&&(i((c=t.manifest.items[0])==null?void 0:c.id),r([(h=t.manifest.items[0])==null?void 0:h.id]))},[t.manifest,e.manifest]);const s=v.useMemo(()=>{var c;return((c=t.manifest)==null?void 0:c.items.map(h=>h.id))||[]},[t.manifest,e.manifest]),u=v.useMemo(()=>s.indexOf(n),[s,n]),l=v.useCallback(()=>{if(s.length&&n){if(u===-1||(s[u+2]?u+2===s.length:u===s.length))return;const c=a&&u!==0?s[u+2]:s[u+1],h=a?u!==0?s[u+3]:s[u+2]:null;c&&(i(c),r(h?[c,h]:[c]))}},[a,s,n,u]),f=v.useCallback(()=>{if(s.length&&n){if(u===0||u===-1)return;const c=a&&u!==1?s[u-2]:s[u-1],h=a&&u!==1?s[u-1]:null;c&&(i(c),r(h?[c,h]:[c]))}},[a,s,n,u]),d=v.useCallback(c=>{const h=a&&c%2===1?c-1:c,w=s[h],y=a&&h!==0?s[h+1]:null;w&&(i(w),r(S=>{const _=y?[w,y]:[w];if(S.length===S.length){for(let O=0;O<S.length;O++)if(S[O]!==_[O])return _;return S}return _}))},[a,s]),m=v.useCallback(c=>{const h=s.indexOf(c);h!==-1&&d(h)},[s,d]),p=v.useMemo(()=>({setCurrentCanvasId:m,nextCanvas:l,previousCanvas:f,currentCanvasIndex:u,totalCanvases:s.length,setCurrentCanvasIndex:d,pagingView:!0}),[l,f,u,s,d,m]);return!t.isLoaded||!t.manifest?I.default.createElement("div",null,"Loading..."):I.default.createElement(X.Provider,{value:p},I.default.createElement(K.Provider,{value:o},I.default.createElement(Fe,{manifest:t.manifest.id},I.default.createElement(Pe,{canvas:n},e.children))))};function ai(){return v.useContext(X)}function si(){return{VaultContext:v.useContext(te),ResourceContext:v.useContext(ee),SimpleViewerReactContext:v.useContext(X),VisibleCanvasReactContext:v.useContext(K)}}const ci=e=>I.default.createElement(Ae,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},I.default.createElement(K.Provider,{value:e.bridge.VisibleCanvasReactContext},I.default.createElement(X.Provider,{value:e.bridge.SimpleViewerReactContext},e.children)));function W(e){return e.endsWith("info.json")?e:e.endsWith("/")?`${e}info.json`:`${e}/info.json`}function ui(e,t,n){const i=n.length,o=[];for(let r=0;r<i;r++){const s=n[r].width;o.push(e/s)}return o}function li(e,t,n){const i=n.length,o=[];for(let r=0;r<i;r++){const a=n[r];o.push({width:Math.floor(e/a),height:Math.floor(t/a)})}return o}const fi="http://library.stanford.edu/iiif/image-api/compliance.html#level0",Ye="http://library.stanford.edu/iiif/image-api/compliance.html#level1",Ze="http://library.stanford.edu/iiif/image-api/compliance.html#level2",hi="http://library.stanford.edu/iiif/image-api/conformance.html#level0",et="http://library.stanford.edu/iiif/image-api/conformance.html#level1",tt="http://library.stanford.edu/iiif/image-api/conformance.html#level2",di="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",nt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",it="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",pi="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",rt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",ot="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",vi="http://iiif.io/api/image/1/level0.json",gi="http://iiif.io/api/image/1/profiles/level0.json",at="http://iiif.io/api/image/1/level1.json",st="http://iiif.io/api/image/1/profiles/level1.json",ct="http://iiif.io/api/image/1/level2.json",ut="http://iiif.io/api/image/1/profiles/level2.json",mi="http://iiif.io/api/image/2/level0.json",yi="http://iiif.io/api/image/2/profiles/level0.json",lt="http://iiif.io/api/image/2/level1.json",ft="http://iiif.io/api/image/2/profiles/level1.json",ht="http://iiif.io/api/image/2/level2.json",dt="http://iiif.io/api/image/2/profiles/level2.json",wi="level0",pt="level1",vt="level2",Si="http://iiif.io/api/image/2/level0",gt="http://iiif.io/api/image/2/level1",mt="http://iiif.io/api/image/2/level2",Ii=[gt,mt,Ye,Ze,et,tt,nt,it,rt,ot,at,st,ct,ut,lt,ft,ht,dt,pt,vt],_i=[Si,gt,mt,fi,Ye,Ze,hi,et,tt,di,nt,it,pi,rt,ot,vi,gi,at,st,ct,ut,mi,yi,lt,ft,ht,dt,wi,pt,vt];function E(e){if(e["@id"])return e["@id"];if(e.id)return e.id}function me(e){if(!e||!e.profile||!E(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const n of t)if(typeof n=="string"&&_i.indexOf(n)!==-1)return!0;return!1}function Oi(e){if(!me(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const n of t)if(typeof n=="string"){if(Ii.indexOf(n)!==-1)return!0}else{const i=n.supports||[];if(i.indexOf("regionByPx")!==-1&&(i.indexOf("sizeByW")!==-1||i.indexOf("sizeByWh")!==-1))return!0}return!1}function bi(e){if(!Oi(e))return[];const t=[],n=Array.isArray(e.profile)?e.profile:[e.profile],i=n.length;for(let o=0;o<i;o++){const r=n[o];if(typeof r!="string"&&(r.maxHeight||r.maxWidth))return[{id:E(e),type:"variable",minWidth:0,minHeight:0,maxHeight:r.maxHeight||r.maxWidth,maxWidth:r.maxWidth||r.maxHeight}]}if(e.tiles){const o=e.tiles.length;for(let r=0;r<o;r++){const a=e.tiles[r];(a.height||a.width)&&t.push({id:E(e),type:"variable",minHeight:0,minWidth:0,maxHeight:a.height||a.width,maxWidth:a.width})}}return t}function yt(e){const t=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,n=e.match(t);if(n){const i=n[1],o=parseInt(n[4],10),r=parseInt(n[5],10),a=n[7];if((i==="max"||i==="full")&&o&&r&&a)return{type:"fixed",id:e,height:r,width:o}}return{type:"unknown",id:e}}function Ci(e){if(e["@type"])return e["@type"];if(e.type)return e.type}function Ei(e){if(typeof e=="string")return yt(e);const t=Ci(e);if(t!=="Image"&&t!=="sc:Image")return null;const n=e,i=E(n);return i?i&&n.width&&n.height?{id:i,type:"fixed",width:n.width,height:n.height,unsafe:!0}:yt(i):null}function xi(e){return me(e)?(e&&e.sizes?e.sizes:[]).map(t=>({id:E(e),type:"fixed-service",height:t.height,width:t.width})):[]}function wt(e){const t=[],n=e.length;for(let i=0;i<n;i++){const o=xi(e[i]);o.length&&t.push(...o);const r=bi(e[i]);r.length&&t.push(...r)}return t}function Y(e){const t=e.service?Array.isArray(e.service)?e.service:[e.service]:[],n=t.length,i=[];for(let o=0;o<n;o++)me(t[o])&&i.push(t[o]);return i}function Pi(e,t=!0,n){const i=[],o=Ei(e);if(o===null)return i;const r=e;if(i.push(o),t&&r.width&&r.height){const a=[],s=Y(r);for(const u of s){const l={id:E(u),width:r.width,height:r.height};if(n.canLoadSync(l)){const f=n.loadServiceSync(l);f&&(f.height||(f.height=r.height),f.width||(f.width=r.width),a.push(...wt([f])))}}if(a.length)return i.push(...a),i}return r.service&&i.push(...wt(r.service)),i}function ye(e,t,n){return{id:[W(E(e)).slice(0,-10),"full",[t,n||""].join(","),0,"default.jpg"].join("/"),type:"fixed",width:t,height:n||e.height/e.width*t,unsafe:e.width>t}}function N(e){const t=e.replace(/(https?:\/\/)?(www.)?/i,"");return t.indexOf("/")!==-1?t.split("/")[0]:t}function Fi(e,t,n){const i=e.width?e.width:e.maxWidth;return n.height<=e.maxHeight&&n.width<=e.maxWidth&&n.height>=e.minHeight&&n.width>=e.minWidth&&(!t||Math.abs(n.width-i)<Math.abs(t.width-i))}function Ai(e,t){const n=[],i=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},e),o=[],r=[];let a=null;const s=(l,f)=>{if(Fi(i,f,l)){if(i.preferFixedSize&&l.unsafe){r.push(l);return}i.returnAllOptions&&f&&r.push(f),a=l}else i.returnAllOptions&&r.push(l)},u=t.length;for(let l=0;l<u;l++){const f=t[l](),d=f.length;for(let m=0;m<d;m++){const p=f[m];if(p.type==="unknown"&&i.atAnyCost&&o.push(p),p.type==="fixed"&&(p.unsafe?o.push(p):s(p,a)),p.type==="fixed-service")if(i.unsafeImageService){const c=ye(p,i.width,i.height);s(c,a)}else{const c=ye(p,p.width,p.height);s(c,a)}if(p.type==="variable"&&p.maxWidth){const c=ye({id:p.id,type:"fixed-service",width:p.maxWidth,height:p.maxWidth},p.maxWidth);s(c,a)}}if(a&&!i.returnAllOptions){if(a.unsafe||i.allowUnsafe)continue;break}}return i.atAnyCost&&r.length===0?{best:a||o[0],fallback:o.slice(1),log:n}:i.returnAllOptions?{best:i.atAnyCost?a||r[0]||o[0]:a||r[0],fallback:[...r,...o],log:n}:{best:a||r[0]||null,fallback:a?r:r.slice(1),log:n}}function Mi(e,t,n){const i=e>t?e:t,o=n.length,r=[];for(let a=0;a<o;a++){const s=n[a];let u=s.scaleFactors[0],l=i/u;const f=[u];for(;l>=s.width;)u=u*2,f.push(u),l=l/2;r.push(Object.assign(Object.assign({},s),{scaleFactors:f}))}return r}function ji(e,t){if(e.length!==t.length)return!1;if(e.length===0&&t.length===0)return!0;const n=e.length;let i=!0;for(let r=0;r<n;r++){const a=e[r],s=t[r];if(a.width!==s.width||a.height!==s.height){i=!1;break}}if(i)return!0;let o=0;for(let r=0;r<n;r++)for(let a=0;a<n;a++)if(e[r].width===t[a].width&&e[r].height===t[a].height){o++;break}return o===n}/*! *****************************************************************************
1
+ (function(y,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("react"),require("@iiif/vault")):typeof define=="function"&&define.amd?define(["exports","react","@iiif/vault"],m):(y=typeof globalThis<"u"?globalThis:y||self,m(y.ReactIIIFVault={},y.React,y.IIIFVault))})(this,function(y,m,fe){"use strict";function mn(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var O=mn(m),gn=Object.defineProperty,Re=Object.getOwnPropertySymbols,yn=Object.prototype.hasOwnProperty,wn=Object.prototype.propertyIsEnumerable,qe=(t,e,r)=>e in t?gn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,We=(t,e)=>{for(var r in e||(e={}))yn.call(e,r)&&qe(t,r,e[r]);if(Re)for(var r of Re(e))wn.call(e,r)&&qe(t,r,e[r]);return t};const bn={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},he=O.default.createContext(bn),Q=()=>m.useContext(he),z=({value:t,children:e})=>{const r=Q(),n=m.useMemo(()=>We(We({},r),t),[t,r]);return O.default.createElement(he.Provider,{value:n},e)},Sn=({annotation:t,children:e})=>O.default.createElement(z,{value:{annotation:t}},e),De=({canvas:t,children:e})=>O.default.createElement(z,{value:{canvas:t}},e),xn=({collection:t,children:e})=>O.default.createElement(z,{value:{collection:t}},e),Ve=({manifest:t,children:e})=>O.default.createElement(z,{value:{manifest:t}},e),On=({range:t,children:e})=>O.default.createElement(z,{value:{range:t}},e),re=O.default.createContext({vault:null,setVaultInstance:t=>{}}),Qe=({vault:t,vaultOptions:e,useGlobal:r,resources:n,children:o})=>{const[i,a]=m.useState(()=>t||(r?fe.globalVault(e):e?new fe.Vault(e):new fe.Vault));return O.default.createElement(re.Provider,{value:{vault:i,setVaultInstance:a}},O.default.createElement(z,{value:n||{}},o))};function T(){return T=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},T.apply(this,arguments)}function ye(t,e){if(t==null)return{};var r={},n=Object.keys(t),o,i;for(i=0;i<n.length;i++)o=n[i],!(e.indexOf(o)>=0)&&(r[o]=t[o]);return r}var we="loading",be="error",ze="success",Cn=0,An=function(){return Cn++},Pn={},de=typeof window>"u",k=function(){},In=function(e){return e},Se=console||{error:k,warn:k,log:k};function $n(){var t=O.default.useRef(null);return t.current===null&&(t.current=An()),t.current}function _n(t){var e=O.default.useRef();return e.current=t,O.default.useCallback(function(){return e.current},[])}function xe(t,e){return typeof t=="function"?t(e):t}function En(t,e){return Be(e)?Object.assign.apply(Object,[{}].concat(Object.keys(e).sort().map(function(r){var n;return n={},n[r]=e[r],n}))):e}function jn(t){return JSON.stringify(t,En)}function Be(t){return t&&typeof t=="object"&&!Array.isArray(t)}function He(t,e){return t===e?!0:typeof t!=typeof e?!1:typeof t=="object"?!Object.keys(e).some(function(r){return!He(t[r],e[r])}):!1}function Oe(){return typeof document>"u"||document.visibilityState===void 0||document.visibilityState==="visible"||document.visibilityState==="prerender"}function Tn(){return navigator.onLine===void 0||navigator.onLine}function Ue(t){if(Be(t[0]))if(t[0].hasOwnProperty("queryKey")&&t[0].hasOwnProperty("queryFn")){var e=t[0],r=e.queryKey,n=e.variables,o=n===void 0?[]:n,i=e.queryFn,a=e.config,s=a===void 0?{}:a;return[r,o,i,s]}else throw new Error("queryKey and queryFn keys are required.");if(typeof t[2]=="function"){var u=t[0],l=t[1],f=l===void 0?[]:l,p=t[2],d=t[3],v=d===void 0?{}:d;return[u,f,p,v]}var c=t[0],g=t[1],x=t[2],S=x===void 0?{}:x;return[c,[],g,S]}function Mn(t){var e=O.default.useRef(!1);return O.default[de?"useEffect":"useLayoutEffect"](function(){return e.current=!0,function(){return e.current=!1}},[]),O.default.useCallback(function(){return e.current?t.apply(void 0,arguments):void 0},[t])}function Fn(t){if((t.config.suspense||t.config.useErrorBoundary)&&t.status===be)throw setTimeout(function(){t.query.state.status="loading"}),t.error;if(t.config.suspense&&t.status===we)throw t.query.wasSuspended=!0,t.refetch()}function Ce(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var r,n,o;if(Array.isArray(t)){if(r=t.length,r!=e.length)return!1;for(n=r;n--!==0;)if(!Ce(t[n],e[n]))return!1;return!0}if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===e.valueOf();if(o=Object.keys(t),r=o.length,r!==Object.keys(e).length)return!1;for(n=r;n--!==0;)if(!Object.prototype.hasOwnProperty.call(e,o[n]))return!1;for(n=r;n--!==0;){var i=o[n];if(!Ce(t[i],e[i]))return!1}return!0}return t!==t&&e!==e}var Ln=O.default.createContext(),kn={retry:3,retryDelay:function(e){return Math.min(1e3*Math.pow(2,e),3e4)},staleTime:0,cacheTime:5*60*1e3,refetchAllOnWindowFocus:!0,refetchInterval:!1,suspense:!1,queryKeySerializerFn:Ne,queryFnParamsFilter:In,throwOnError:!1,useErrorBoundary:void 0,onMutate:k,onSuccess:k,onError:k,onSettled:k,refetchOnMount:!0,isDataEqual:Ce},ne={current:kn};function Rn(){return O.default.useContext(Ln)||ne.current}function Ne(t){if(!t)return[];if(typeof t=="function")try{return Ne(t())}catch{return[]}typeof t=="string"&&(t=[t]);var e=jn(t);return t=JSON.parse(e),[e,t]}function N(t,e,r){return r?e?e(t):t:((!t||!t.then)&&(t=Promise.resolve(t)),e?t.then(e):t)}function ie(t,e){try{var r=t()}catch(n){return e(n)}return r&&r.then?r.then(void 0,e):r}function G(t){return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];try{return Promise.resolve(t.apply(this,e))}catch(n){return Promise.reject(n)}}}function Ge(t,e){var r=t();return r&&r.then?r.then(e):e(r)}var Ke=Vn(),qn=O.default.createContext(Ke),Wn=[Ke];function Dn(){return O.default.useContext(qn)}var Ye={},Je={},Ze={},Xe={},et={},tt={},rt={},nt={};function Vn(){var t=[],e={queries:{},isFetching:0},r=function(){e.isFetching=Object.values(e.queries).reduce(function(a,s){return s.state.isFetching?a+1:a},0),t.forEach(function(a){return a(e)})};e.subscribe=function(i){return t.push(i),function(){t.splice(t.indexOf(i),1)}},e.clear=function(){Object.values(e.queries).forEach(function(i){return i.clear()}),e.queries={},r()};var n=function(a,s){var u=s===void 0?{}:s,l=u.exact;if(typeof a!="function"){var f=ne.current.queryKeySerializerFn(a),p=f[0],d=f[1];a=function(c){return l?c.queryHash===p:He(c.queryKey,d)}}return Object.values(e.queries).filter(a)};e.getQueries=n,e.getQuery=function(i){return n(i,{exact:!0})[0]},e.getQueryData=function(i){var a;return(a=e.getQuery(i))==null?void 0:a.state.data},e.removeQueries=function(i,a){var s=a===void 0?{}:a,u=s.exact,l=n(i,{exact:u});l.forEach(function(f){clearTimeout(f.staleTimeout),delete e.queries[f.queryHash]}),l.length&&r()},e.cancelQueries=function(i,a){var s=a===void 0?{}:a,u=s.exact,l=n(i,{exact:u});l.forEach(function(f){f.cancel()}),l.length&&r()},e.refetchQueries=G(function(i,a){var s=a===void 0?{}:a,u=s.exact,l=s.throwOnError,f=s.force,p=i===!0?Object.values(e.queries):n(i,{exact:u});return ie(function(){return N(Promise.all(p.map(function(d){return d.fetch({force:f})})))},function(d){if(l)throw d})}),e._buildQuery=function(i,a,s,u){var l=u.queryKeySerializerFn(i),f=l[0],p=l[1],d=e.queries[f];return d?(Object.assign(d,{queryVariables:a,queryFn:s}),d.config=T({},d.config,u)):(d=o({cache:e,queryKey:p,queryHash:f,queryVariables:a,queryFn:s,config:u}),!de&&d.state.data&&(d.scheduleStaleTimeout(),d.heal(),d.scheduleGarbageCollection()),d.queryHash&&(de||(e.queries[f]=d,setTimeout(function(){r()})))),d},e.prefetchQuery=G(function(){for(var i=!1,a=arguments.length,s=new Array(a),u=0;u<a;u++)s[u]=arguments[u];var l=Ue(s),f=l[0],p=l[1],d=l[2],v=l[3],c=v.force,g=ye(v,["force"]);g=T({},ne.current,g);var x=e._buildQuery(f,p,d,g);return Ge(function(){if(x.state.isStale||c)return ie(function(){return N(x.fetch({force:c}),function(S){return x.wasPrefetched=!0,i=!0,S})},function(S){if(g.throwOnError)throw S})},function(S){return i?S:x.state.data})}),e.setQueryData=function(i,a,s){var u=s===void 0?{}:s,l=u.exact,f=ye(u,["exact"]),p=n(i,{exact:l});!p.length&&typeof i!="function"&&(p=[e._buildQuery(i,void 0,function(){return Promise.resolve()},T({},ne.current,f))]),p.forEach(function(d){return d.setData(a)})};function o(i){var a=i.cache,s=i.config.queryReducer||Qn,u=typeof i.queryHash>"u",l=typeof i.config.initialData=="function"?i.config.initialData():i.config.initialData,f=typeof l<"u",p=u?!0:!f,d=i.config.manual,v=u||d||f?ze:we,c=T({},i,{instances:[],state:s(void 0,{type:Ye,initialStatus:v,initialData:l,hasInitialData:f,isStale:p,manual:d})}),g=function(h){c.state=s(c.state,h),c.instances.forEach(function(w){return w.onStateUpdate(c.state)}),r()};c.scheduleStaleTimeout=function(){c.config.staleTime!==1/0&&(c.staleTimeout=setTimeout(function(){a.getQuery(c.queryKey)&&g({type:Ze})},c.config.staleTime))},c.scheduleGarbageCollection=function(){c.config.cacheTime!==1/0&&(g({type:Xe}),c.cacheTimeout=setTimeout(function(){e.removeQueries(function(S){return S.state.markedForGarbageCollection&&S.queryHash===c.queryHash})},typeof c.state.data>"u"&&c.state.status!=="error"?0:c.config.cacheTime))},c.heal=function(){clearTimeout(c.cacheTimeout),c.cancelled=null},c.cancel=function(){c.cancelled=Pn,c.cancelPromises&&c.cancelPromises(),delete c.promise,r()},c.updateInstance=function(S){var h=c.instances.find(function(w){return w.id===S.id});h?Object.assign(h,S):(h=T({onStateUpdate:k},S),c.instances.push(S))},c.subscribe=function(S){return c.heal(),function(){c.instances=c.instances.filter(function(h){return h.id!==S}),c.instances.length||(c.cancel(),c.scheduleGarbageCollection())}};var x=G(function(S){for(var h=arguments.length,w=new Array(h>1?h-1:0),b=1;b<h;b++)w[b-1]=arguments[b];return ie(function(){var A=S.apply(void 0,c.config.queryFnParamsFilter(w));return c.cancelPromises=function(){return A.cancel==null?void 0:A.cancel()},N(A,function(P){if(delete c.shouldContinueRetryOnFocus,delete c.cancelPromises,c.cancelled)throw c.cancelled;return P})},function(A){var P=!1;if(delete c.cancelPromises,c.cancelled)throw c.cancelled;return g({type:Je}),Ge(function(){if(c.config.retry===!0||c.state.failureCount<=c.config.retry||typeof c.config.retry=="function"&&c.config.retry(c.state.failureCount,A)){if(!Oe())return c.shouldContinueRetryOnFocus=!0,P=!0,new Promise(k);delete c.shouldContinueRetryOnFocus;var C=xe(c.config.retryDelay,c.state.failureCount);return P=!0,N(new Promise(function(I,F){setTimeout(G(function(){return c.cancelled?F(c.cancelled):ie(function(){return N(x.apply(void 0,[S].concat(w)),function(ee){if(c.cancelled)return F(c.cancelled);I(ee)})},function(ee){if(c.cancelled)return F(c.cancelled);F(ee)})}),C)}))}},function(C){if(P)return C;throw A})})});return c.fetch=G(function(S){var h=S===void 0?{}:S,w=h.force,b=h.__queryFn,A=b===void 0?c.queryFn:b;if(!(!c.queryHash||!c.state.isStale&&!w))return c.promise||(c.promise=G(function(){c.cancelled=null;var P=[].concat(c.instances);return c.wasSuspended&&P.unshift(c.suspenseInstance),ie(function(){return g({type:et}),N(x.apply(void 0,[A].concat(c.queryKey,c.queryVariables)),function(C){return c.setData(function(I){return c.config.isDataEqual(I,C)?I:C}),P.forEach(function(I){return I.onSuccess&&I.onSuccess(c.state.data)}),P.forEach(function(I){return I.onSettled&&I.onSettled(c.state.data,null)}),delete c.promise,C})},function(C){if(g({type:rt,cancelled:C===c.cancelled,error:C}),delete c.promise,C!==c.cancelled)throw P.forEach(function(I){return I.onError&&I.onError(C)}),P.forEach(function(I){return I.onSettled&&I.onSettled(void 0,C)}),C})})()),c.promise}),c.setState=function(S){return g({type:nt,updater:S})},c.setData=function(S){g({type:tt,updater:S}),clearTimeout(c.staleTimeout),c.scheduleStaleTimeout()},c.clear=function(){clearTimeout(c.staleTimeout),clearTimeout(c.cacheTimeout),c.cancel()},c}return e}function Qn(t,e){switch(e.type){case Ye:return{status:e.initialStatus,error:null,isFetching:e.hasInitialData||e.manual?!1:e.initialStatus==="loading",canFetchMore:!1,failureCount:0,isStale:e.isStale,markedForGarbageCollection:!1,data:e.initialData,updatedAt:e.hasInitialData?Date.now():0};case Je:return T({},t,{failureCount:t.failureCount+1});case Ze:return T({},t,{isStale:!0});case Xe:return T({},t,{markedForGarbageCollection:!0});case et:return T({},t,{status:t.status===be?we:t.status,isFetching:!0,failureCount:0});case tt:return T({},t,{status:ze,data:xe(e.updater,t.data),error:null,isStale:!1,isFetching:!1,canFetchMore:e.canFetchMore,updatedAt:Date.now(),failureCount:0});case rt:return T({},t,{isFetching:!1,isStale:!0},!e.cancelled&&{status:be,error:e.error});case nt:return xe(e.updater,t);default:throw new Error}}var it="visibilitychange",ot="focus",zn=function(){var e=ne.current.refetchAllOnWindowFocus;Oe()&&Tn()&&Wn.forEach(function(r){return r.refetchQueries(function(n){return!n.instances.length||n.config.manual===!0?!1:n.shouldContinueRetryOnFocus?(delete n.promise,!0):typeof n.config.refetchOnWindowFocus>"u"?e:n.config.refetchOnWindowFocus}).catch(Se.error)})},Ae;function Bn(t){Ae&&Ae(),Ae=t(zn)}Bn(function(t){var e;if(!de&&((e=window)==null?void 0:e.addEventListener))return window.addEventListener(it,t,!1),window.addEventListener(ot,t,!1),function(){window.removeEventListener(it,t),window.removeEventListener(ot,t)}});function Hn(t,e,r){return r?e?e(t):t:((!t||!t.then)&&(t=Promise.resolve(t)),e?t.then(e):t)}function Un(t,e){try{var r=t()}catch(n){return e(n)}return r&&r.then?r.then(void 0,e):r}function Nn(t){return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];try{return Promise.resolve(t.apply(this,e))}catch(n){return Promise.reject(n)}}}function Gn(t,e,r,n){n===void 0&&(n={});var o=$n();n=T({},Rn(),n);var i=Dn(),a=O.default.useRef(),s=i._buildQuery(t,e,r,n),u=a.current&&typeof a.current.queryHash>"u"&&typeof s.queryHash>"u";u||(a.current=s);var l=a.current,f=O.default.useState(),p=f[1],d=Mn(p),v=_n(n),c=O.default.useCallback(Nn(function(g){var x=g===void 0?{}:g,S=x.throwOnError,h=ye(x,["throwOnError"]);return Un(function(){return Hn(l.fetch(h))},function(w){if(S)throw w})}),[l]);return l.suspenseInstance={onSuccess:function(x){return v().onSuccess(x)},onError:function(x){return v().onError(x)},onSettled:function(x,S){return v().onSettled(x,S)}},O.default.useEffect(function(){return l.updateInstance({id:o,onStateUpdate:function(){return d({})},onSuccess:function(x){return v().onSuccess(x)},onError:function(x){return v().onError(x)},onSettled:function(x,S){return v().onSettled(x,S)}}),l.subscribe(o)},[v,o,l,d]),O.default.useEffect(function(){!v().manual&&!l.wasPrefetched&&!l.wasSuspended&&l.state.isStale&&(v().refetchOnMount||l.instances.length===1)&&c().catch(Se.error),l.wasPrefetched=!1,l.wasSuspended=!1},[v,l,c]),O.default.useEffect(function(){var g=a.current;if(n.refetchInterval&&(!g.currentRefetchInterval||n.refetchInterval<g.currentRefetchInterval))return g.currentRefetchInterval=n.refetchInterval,clearInterval(g.refetchIntervalId),g.refetchIntervalId=setInterval(function(){(Oe()||n.refetchIntervalInBackground)&&c().catch(Se.error)},n.refetchInterval),function(){clearInterval(g.refetchIntervalId),delete g.refetchIntervalId,delete g.currentRefetchInterval}},[n.refetchInterval,n.refetchIntervalInBackground,c]),T({},l.state,{config:n,query:l,refetch:c})}function Pe(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];var n=Gn.apply(void 0,Ue(e));return Fn(n),n}const E=()=>{const{vault:t}=m.useContext(re);if(t===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return t};var Kn=Object.defineProperty,at=Object.getOwnPropertySymbols,Yn=Object.prototype.hasOwnProperty,Jn=Object.prototype.propertyIsEnumerable,st=(t,e,r)=>e in t?Kn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Zn=(t,e)=>{for(var r in e||(e={}))Yn.call(e,r)&&st(t,r,e[r]);if(at)for(var r of at(e))Jn.call(e,r)&&st(t,r,e[r]);return t},Xn=(t,e,r)=>new Promise((n,o)=>{var i=u=>{try{s(r.next(u))}catch(l){o(l)}},a=u=>{try{s(r.throw(u))}catch(l){o(l)}},s=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);s((r=r.apply(t,e)).next())});const ct=(t,e={})=>{const r=E(),[n,o]=m.useState(t),i=m.useMemo(()=>r.get(t)||void 0,[t,r]),{data:a,error:s}=Pe(["manifest",t],()=>Xn(void 0,null,function*(){const u=i||(yield r.load(t));return u&&n!==u.id&&o(u.id),u}),Zn({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,retry:!1,initialData:i},e));return{isLoaded:!!a,id:n,error:s,manifest:a}};function M(t,e=[]){const r=E(),[n,o]=m.useState(()=>t(r.getState(),r));return m.useEffect(()=>r.subscribe(i=>t(i,r),i=>{o(i)},!1),e),n}const oe=O.default.createContext([]);function ut(){const t=m.useContext(oe);return M(e=>t.map(r=>e.iiif.entities.Canvas[r]).filter(Boolean),[t])}const pe=()=>{},ae=m.createContext({setCurrentCanvasId:pe,setCurrentCanvasIndex:pe,nextCanvas:pe,previousCanvas:pe,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),ei=t=>{const e=ct(t.manifest),[r,n]=m.useState(""),[o,i]=m.useState([]),a=(typeof t.pagingEnabled>"u"||t.pagingEnabled)&&e.manifest&&e.manifest.behavior&&e.manifest.behavior.includes("paged");m.useEffect(()=>{var c,g;e.manifest&&(n((c=e.manifest.items[0])==null?void 0:c.id),i([(g=e.manifest.items[0])==null?void 0:g.id]))},[e.manifest,t.manifest]);const s=m.useMemo(()=>{var c;return((c=e.manifest)==null?void 0:c.items.map(g=>g.id))||[]},[e.manifest,t.manifest]),u=m.useMemo(()=>s.indexOf(r),[s,r]),l=m.useCallback(()=>{if(s.length&&r){if(u===-1||(s[u+2]?u+2===s.length:u===s.length))return;const c=a&&u!==0?s[u+2]:s[u+1],g=a?u!==0?s[u+3]:s[u+2]:null;c&&(n(c),i(g?[c,g]:[c]))}},[a,s,r,u]),f=m.useCallback(()=>{if(s.length&&r){if(u===0||u===-1)return;const c=a&&u!==1?s[u-2]:s[u-1],g=a&&u!==1?s[u-1]:null;c&&(n(c),i(g?[c,g]:[c]))}},[a,s,r,u]),p=m.useCallback(c=>{const g=a&&c%2===1?c-1:c,x=s[g],S=a&&g!==0?s[g+1]:null;x&&(n(x),i(h=>{const w=S?[x,S]:[x];if(h.length===h.length){for(let b=0;b<h.length;b++)if(h[b]!==w[b])return w;return h}return w}))},[a,s]),d=m.useCallback(c=>{const g=s.indexOf(c);g!==-1&&p(g)},[s,p]),v=m.useMemo(()=>({setCurrentCanvasId:d,nextCanvas:l,previousCanvas:f,currentCanvasIndex:u,totalCanvases:s.length,setCurrentCanvasIndex:p,pagingView:!0}),[l,f,u,s,p,d]);return!e.isLoaded||!e.manifest?O.default.createElement("div",null,"Loading..."):O.default.createElement(ae.Provider,{value:v},O.default.createElement(oe.Provider,{value:o},O.default.createElement(Ve,{manifest:e.manifest.id},O.default.createElement(De,{canvas:r},t.children))))};function ti(){return m.useContext(ae)}function ri(){return{VaultContext:m.useContext(re),ResourceContext:m.useContext(he),SimpleViewerReactContext:m.useContext(ae),VisibleCanvasReactContext:m.useContext(oe)}}const ni=t=>O.default.createElement(Qe,{vault:t.bridge.VaultContext.vault||void 0,resources:t.bridge.ResourceContext},O.default.createElement(oe.Provider,{value:t.bridge.VisibleCanvasReactContext},O.default.createElement(ae.Provider,{value:t.bridge.SimpleViewerReactContext},t.children)));function B(t){return t.endsWith("info.json")?t:t.endsWith("/")?`${t}info.json`:`${t}/info.json`}const ii="http://library.stanford.edu/iiif/image-api/compliance.html#level0",lt="http://library.stanford.edu/iiif/image-api/compliance.html#level1",ft="http://library.stanford.edu/iiif/image-api/compliance.html#level2",oi="http://library.stanford.edu/iiif/image-api/conformance.html#level0",ht="http://library.stanford.edu/iiif/image-api/conformance.html#level1",dt="http://library.stanford.edu/iiif/image-api/conformance.html#level2",ai="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",pt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",vt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",si="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",mt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",gt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",ci="http://iiif.io/api/image/1/level0.json",ui="http://iiif.io/api/image/1/profiles/level0.json",yt="http://iiif.io/api/image/1/level1.json",wt="http://iiif.io/api/image/1/profiles/level1.json",bt="http://iiif.io/api/image/1/level2.json",St="http://iiif.io/api/image/1/profiles/level2.json",li="http://iiif.io/api/image/2/level0.json",fi="http://iiif.io/api/image/2/profiles/level0.json",xt="http://iiif.io/api/image/2/level1.json",Ot="http://iiif.io/api/image/2/profiles/level1.json",Ct="http://iiif.io/api/image/2/level2.json",At="http://iiif.io/api/image/2/profiles/level2.json",hi="level0",Pt="level1",It="level2",di="http://iiif.io/api/image/2/level0",$t="http://iiif.io/api/image/2/level1",_t="http://iiif.io/api/image/2/level2",Et=[_t,ft,dt,vt,gt,bt,St,Ct,At,It],jt=[...Et,$t,lt,ht,pt,mt,yt,wt,xt,Ot,Pt],pi=[di,$t,_t,ii,lt,ft,oi,ht,dt,ai,pt,vt,si,mt,gt,ci,ui,yt,wt,bt,St,li,fi,xt,Ot,Ct,At,hi,Pt,It],vi={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},mi={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},gi={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function yi(t){return Et.indexOf(t)!==-1?gi:jt.indexOf(t)!==-1?mi:vi}function wi(t){const e=t?Array.isArray(t.profile)?t.profile:[t.profile]:[],r={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let n of e)if(typeof n=="string"&&(n=yi(n)),!!n){if(n.formats)for(const o of n.formats)r.extraFormats.indexOf(o)===-1&&r.extraFormats.push(o);if(n.qualities)for(const o of n.qualities)r.extraQualities.indexOf(o)===-1&&r.extraQualities.push(o);if(n.supports)for(const o of n.supports)r.extraFeatures.indexOf(o)===-1&&r.extraFeatures.push(o);if(n.maxHeight&&(r.maxHeight=n.maxHeight),n.maxWidth&&(r.maxWidth=n.maxWidth),n.maxArea&&(r.maxArea=n.maxArea),n.extraFormats)for(const o of n.extraFormats)r.extraFormats.indexOf(o)===-1&&r.extraFormats.push(o);if(n.extraQualities)for(const o of n.extraQualities)r.extraQualities.indexOf(o)===-1&&r.extraQualities.push(o);if(n.extraFeatures)for(const o of n.extraFeatures)r.extraFeatures.indexOf(o)===-1&&r.extraFeatures.push(o);n.maxHeight&&(r.maxHeight=n.maxHeight),n.maxWidth&&(r.maxWidth=n.maxWidth),n.maxArea&&(r.maxArea=n.maxArea)}if(t.extraFormats)for(const n of t.extraFormats)r.extraFormats.indexOf(n)===-1&&r.extraFormats.push(n);if(t.extraFeatures)for(const n of t.extraFeatures)r.extraFeatures.indexOf(n)===-1&&r.extraFeatures.push(n);if(t.extraQualities)for(const n of t.extraQualities)r.extraQualities.indexOf(n)===-1&&r.extraQualities.push(n);return r}function bi(t){try{if(t==="full")return{full:!0};if(t==="square")return{square:!0};const e=t.startsWith("pct:"),r=t.substr(e?4:0).split(",").map(n=>parseFloat(n));return{x:r[0],y:r[1],w:r[2],h:r[3],percent:e}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+t)}}function Si(t){const e={upscaled:!1,max:!1,confined:!1};if(t[0]==="^"&&(e.upscaled=!0,t=t.slice(1)),t==="max"||t==="full")return e.max=!0,e.serialiseAsFull=t==="full",e;if(t[0]==="!"&&(e.confined=!0,t=t.slice(1)),t[0]==="p")return e.percentScale=parseFloat(t.slice(4)),e;const r=t.split(",").map(n=>n.trim());return r.length&&(r[0]!==""&&(e.width=parseInt(r[0],10)),r[1]!==""&&(e.height=parseInt(r[1],10))),e}function xi(t){const e={angle:0};if(t[0]==="!"&&(e.mirror=!0,t=t.substr(1)),e.angle=parseFloat(t)%360,Number.isNaN(e.angle))throw new Error(`Invalid rotation ${t}`);return e}function Oi(t,e=""){const r=t.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!r)throw new Error(`Invalid or unknown input ${t}`);const n=r[2],o=r[3];let i=r[4];if(i[0]==="/"&&(i=i.substr(1)),e.length>0){if(e[0]==="/"&&(e=e.substr(1)),e!==i.substr(0,e.length))throw new Error(`Path does not start with prefix (path: ${i}, prefix: ${e})`);i=i.substr(e.length)}return{scheme:n,server:o,path:i,prefix:e}}function Ci(t,e=""){const{path:r,scheme:n,server:o,prefix:i}=Oi(t,e),a=r.split("/").reverse(),[s,u,l,f,...p]=a,d=p.reverse().filter(Boolean).join("/");if(a.length===1||s==="")return{type:"base",scheme:n,server:o,prefix:i,identifier:d};if(s==="info.json"){const[,...c]=a;return{type:"info",scheme:n,server:o,prefix:i,identifier:c.reverse().filter(Boolean).join("/")}}const v=s.split(".");return{type:"image",scheme:n,server:o,prefix:i,identifier:d,originalPath:r,region:bi(f),size:Si(l),rotation:xi(u),quality:v[0],format:v[1]}}function Ai(t){const e=Ci(B(t.id));if(e.type!=="info")throw new Error("Invalid service URL");const r=wi(t);return{identifier:e.identifier,originalPath:"",server:e.server,prefix:e.prefix,scheme:e.scheme,type:"image",quality:r.extraQualities.indexOf("default")===-1?r.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}}function Pi(t,e,r){const n=r.length,o=[];for(let i=0;i<n;i++){const a=r[i].width;o.push(t/a)}return o}function Ii(t,e,r){const n=r.length,o=[];for(let i=0;i<n;i++){const a=r[i];o.push({width:Math.floor(t/a),height:Math.floor(e/a)})}return o}function $(t){if(t["@id"])return t["@id"];if(t.id)return t.id}function Ie(t){if(!t||!t.profile||!$(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const r of e)if(typeof r=="string"&&pi.indexOf(r)!==-1)return!0;return!1}function $i(t){if(!Ie(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const r of e)if(typeof r=="string"){if(jt.indexOf(r)!==-1)return!0}else{const n=[...r.supports||[],...r.extraFeatures||[]];if(n.indexOf("regionByPx")!==-1&&(n.indexOf("sizeByW")!==-1||n.indexOf("sizeByWh")!==-1))return!0}return!1}function _i(t){if(!$i(t))return[];const e=[],r=Array.isArray(t.profile)?t.profile:[t.profile],n=r.length;for(let o=0;o<n;o++){const i=r[o];if(typeof i!="string"&&(i.maxHeight||i.maxWidth))return[{id:$(t),type:"variable",minWidth:0,minHeight:0,maxHeight:i.maxHeight||i.maxWidth,maxWidth:i.maxWidth||i.maxHeight}]}if(t.tiles){const o=t.tiles.length;for(let i=0;i<o;i++){const a=t.tiles[i];(a.height||a.width)&&e.push({id:$(t),type:"variable",minHeight:0,minWidth:0,maxHeight:a.height||a.width,maxWidth:a.width})}}return e}function Tt(t){const e=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,r=t.match(e);if(r){const n=r[1],o=parseInt(r[4],10),i=parseInt(r[5],10),a=r[7];if((n==="max"||n==="full")&&o&&i&&a)return{type:"fixed",id:t,height:i,width:o}}return{type:"unknown",id:t}}function Ei(t){if(t["@type"])return t["@type"];if(t.type)return t.type}function ji(t){if(typeof t=="string")return Tt(t);const e=Ei(t);if(e!=="Image"&&e!=="sc:Image")return null;const r=t,n=$(r);return n?n&&r.width&&r.height?{id:n,type:"fixed",width:r.width,height:r.height,unsafe:!0}:Tt(n):null}function Ti(t){return Ie(t)?(t&&t.sizes?t.sizes:[]).map(e=>({id:$(t),type:"fixed-service",height:e.height,width:e.width})):[]}function Mt(t){const e=[],r=t.length;for(let n=0;n<r;n++){const o=Ti(t[n]);o.length&&e.push(...o);const i=_i(t[n]);i.length&&e.push(...i)}return e}function se(t){const e=t.service?Array.isArray(t.service)?t.service:[t.service]:[],r=e.length,n=[];for(let o=0;o<r;o++)Ie(e[o])&&n.push(e[o]);return n}function Mi(t,e=!0,r){const n=[],o=ji(t);if(o===null)return n;const i=t;if(n.push(o),e&&i.width&&i.height){const a=[],s=se(i);for(const u of s){const l={id:$(u),width:i.width,height:i.height};if(r.canLoadSync(l)){const f=r.loadServiceSync(l);f&&(f.height||(f.height=i.height),f.width||(f.width=i.width),a.push(...Mt([f])))}}if(a.length)return n.push(...a),n}return i.service&&n.push(...Mt(i.service)),n}function Fi({x:t=0,y:e=0,w:r,h:n,full:o,square:i,percent:a}){if(o)return"full";if(i)return"square";if(typeof r>"u"||typeof n>"u")throw new Error("RegionParameter: invalid region");const s=`${t},${e},${r},${n}`;return a?`pct:${s}`:s}function Li({max:t,percentScale:e,upscaled:r,confined:n,width:o,height:i,serialiseAsFull:a}){const s=[];return r&&s.push("^"),t?(s.push(a?"full":"max"),s.join("")):(n&&s.push("!"),e&&s.push(`pct:${e}`),o&&s.push(`${o}`),s.push(","),i&&s.push(`${i}`),s.join(""))}function ki(t){return`${t.mirror?"!":""}${(t.angle||0)%360}`}var Ri=Object.defineProperty,qi=Object.defineProperties,Wi=Object.getOwnPropertyDescriptors,Ft=Object.getOwnPropertySymbols,Di=Object.prototype.hasOwnProperty,Vi=Object.prototype.propertyIsEnumerable,Lt=(t,e,r)=>e in t?Ri(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ce=(t,e)=>{for(var r in e||(e={}))Di.call(e,r)&&Lt(t,r,e[r]);if(Ft)for(var r of Ft(e))Vi.call(e,r)&&Lt(t,r,e[r]);return t},ue=(t,e)=>qi(t,Wi(e));function Qi(t,e){const r=t.prefix.startsWith("/")?t.prefix.substr(1):t.prefix,n=`${t.scheme}://${t.server}/${r?`${r}/`:""}${t.identifier}`;if(t.type==="base")return n;if(t.type==="info")return`${n}/info.json`;let{region:o,size:i,rotation:a,format:s,quality:u}=t;if(e){const l=e["@context"]?Array.isArray(e["@context"])?e["@context"]:[e["@context"]]:[],f=l.indexOf("http://iiif.io/api/image/2/context.json")!==-1,p=l.indexOf("http://iiif.io/api/image/3/context.json")!==-1;if((i.width===e.width&&!i.height||i.height===e.height&&!i.width||i.width===e.width&&i.height===e.height)&&(i=ue(ce({},i),{max:!0})),f&&(i.max&&!i.serialiseAsFull&&(i=ue(ce({},i),{serialiseAsFull:!0})),!i.max&&i.width&&i.height&&(i=ue(ce({},i),{height:void 0}))),p&&(i.max&&i.serialiseAsFull&&(i=ue(ce({},i),{serialiseAsFull:!1})),i.width&&!i.height&&e.width&&e.height)){const d=e.height/e.width;i=ue(ce({},i),{height:Math.ceil(i.width*d)})}}return[n,Fi(o),Li(i),ki(a),`${u}.${s}`].filter(Boolean).join("/")}function $e(t,e,r){const n=Ai({id:B($(t)),profile:"level2",type:"ImageService2"});if(n.type!=="image")throw new Error("Invalid service");return n.size.max=!1,n.size.width=e,n.size.height=r,{id:Qi(n),type:"fixed",width:e,height:r||t.height/(t.width||1)*e,unsafe:t.width>e}}function K(t){const e=t.replace(/(https?:\/\/)?(www.)?/i,"");return e.indexOf("/")!==-1?e.split("/")[0]:e}function zi(t,e,r){const n=t.width?t.width:t.maxWidth;return r.height<=t.maxHeight&&r.width<=t.maxWidth&&r.height>=t.minHeight&&r.width>=t.minWidth&&(!e||Math.abs(r.width-n)<Math.abs(e.width-n))}function Bi(t,e){const r=[],n=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},t),o=[],i=[];let a=null;const s=(l,f)=>{if(zi(n,f,l)){if(n.preferFixedSize&&l.unsafe){i.push(l);return}n.returnAllOptions&&f&&i.push(f),a=l}else n.returnAllOptions&&i.push(l)},u=e.length;for(let l=0;l<u;l++){const f=e[l](),p=f.length;for(let d=0;d<p;d++){const v=f[d];if(v.type==="unknown"&&n.atAnyCost&&o.push(v),v.type==="fixed"&&(v.unsafe?o.push(v):s(v,a)),v.type==="fixed-service")if(n.unsafeImageService){const c=$e(v,n.width,n.height);s(c,a)}else{const c=$e(v,v.width,v.height);s(c,a)}if(v.type==="variable"&&v.maxWidth){const c=$e({id:v.id,type:"fixed-service",width:v.maxWidth,height:v.maxWidth},v.maxWidth);s(c,a)}}if(a&&!n.returnAllOptions){if(a.unsafe||n.allowUnsafe)continue;break}}return n.atAnyCost&&i.length===0?{best:a||o[0],fallback:o.slice(1),log:r}:n.returnAllOptions?{best:n.atAnyCost?a||i[0]||o[0]:a||i[0],fallback:[...i,...o],log:r}:{best:a||i[0]||null,fallback:a?i:i.slice(1),log:r}}var Hi=Object.defineProperty,Ui=Object.defineProperties,Ni=Object.getOwnPropertyDescriptors,kt=Object.getOwnPropertySymbols,Gi=Object.prototype.hasOwnProperty,Ki=Object.prototype.propertyIsEnumerable,Rt=(t,e,r)=>e in t?Hi(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Yi=(t,e)=>{for(var r in e||(e={}))Gi.call(e,r)&&Rt(t,r,e[r]);if(kt)for(var r of kt(e))Ki.call(e,r)&&Rt(t,r,e[r]);return t},Ji=(t,e)=>Ui(t,Ni(e));function Zi(t,e,r){const n=t>e?t:e,o=r.length,i=[];for(let a=0;a<o;a++){const s=r[a];let u=s.scaleFactors[0],l=n/u;const f=[u];for(;l>=s.width;)u=u*2,f.push(u),l=l/2;i.push(Ji(Yi({},s),{scaleFactors:f}))}return i}function Xi(t,e){if(t.length!==e.length)return!1;if(t.length===0&&e.length===0)return!0;const r=t.length;let n=!0;for(let i=0;i<r;i++){const a=t[i],s=e[i];if(a.width!==s.width||a.height!==s.height){n=!1;break}}if(n)return!0;let o=0;for(let i=0;i<r;i++)for(let a=0;a<r;a++)if(t[i].width===e[a].width&&t[i].height===e[a].height){o++;break}return o===r}var H=(t,e,r)=>new Promise((n,o)=>{var i=u=>{try{s(r.next(u))}catch(l){o(l)}},a=u=>{try{s(r.throw(u))}catch(l){o(l)}},s=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);s((r=r.apply(t,e)).next())});class qt{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(e){Object.assign(this.config,e)}sample(e,r,n=!0){const o=K($(e)),i=B($(e)),a=this.knownImageServers[o];return this.imageServices[i]=Object.assign(e,{real:!0}),a?this.verify(e):(this.knownImageServers[o]={verifications:0,malformed:!1,root:o,preLoaded:n,sampledId:$(e),verified:!1,server:null,result:{context:e["@context"]||[],sampledProfile:e.profile,resourceServiceRatio:r&&e.height?r.height/e.height:1,sampledSizes:e.sizes||[],sizeRatios:Pi(e.width,e.height,e.sizes||[]),sampledTiles:e.tiles||[]}},!0)}preLoad(e,r=!0){this.knownImageServers[e.root]=e,r&&(this.knownImageServers[e.root].malformed=!1,this.knownImageServers[e.root].verifications=this.config.verificationsRequired)}predict(e,r=!1,n=!1){const o=K($(e)),i=this.knownImageServers[o];if(!i||!i.result||!n&&(i.malformed||i.verifications<this.config.verificationsRequired))return null;const a=B($(e));return this.imageServices[a]||(this.imageServices[a]={"@context":i.result.context,"@id":$(e),id:$(e),protocol:"http://iiif.io/api/image",tiles:Zi(e.width,e.height,i.result.sampledTiles),sizes:Ii(Math.floor(e.width/i.result.resourceServiceRatio),Math.floor(e.height/i.result.resourceServiceRatio),i.result.sizeRatios),profile:i.result.sampledProfile,height:e.height,width:e.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(e,r){return H(this,arguments,function*(n,o,i=!0,a=[]){const s=yield this.getImageCandidates(n,i);return Bi(o,[()=>a,()=>s])})}getImageCandidates(e,r=!0){return H(this,null,function*(){const n=e;if(r&&n.height&&n.width){const o=se(n);for(const i of o){const a={id:$(i),width:i.width?i.width:n.width,height:i.height?i.height:n.height};yield this.loadService(a)}}return Mi(e,r,this)})}verify(e){return H(this,null,function*(){const r=this.predict(e,!1,!0),n=yield this.fetchService($(e));if(!r)return!1;const o=r.height===n.height&&r.width===n.width&&r["@context"]===n["@context"]&&Xi(r.sizes||[],n.sizes||[]);if(o){const i=K($(e));this.knownImageServers[i].verifications+=1,this.knownImageServers[i].verifications>=this.config.verificationsRequired&&(this.knownImageServers[i].verified=!0)}return o})}canLoadSync(e){const r=typeof e=="string"?e:$(e),n=B(r);if(this.imageServices[n])return!0;const o=this.knownImageServers[K(r)];return o&&!o.malformed&&o.verifications>=this.config.verificationsRequired}markAsMalformed(e){return H(this,null,function*(){return this.knownImageServers[K($(e))].malformed=!0,this.loadService(e,!0)})}fetchService(e,r=!1){return H(this,null,function*(){const n=B(e);if(this.imageServices[n]&&(!r||this.imageServices[n].real))return this.imageServices[n];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const o=yield this.fetch(n).then(i=>i.json());return!o.id&&o["@id"]&&(o.id=o["@id"]),o.id!==e&&(o.id=e,o["@id"]&&(o["@id"]=e)),this.imageServices[n]=Object.assign(o,{real:!0}),this.imageServices[n]})}fetch(e,r){return H(this,null,function*(){return fetch(e,r)})}loadService(e,r=!1){return H(this,null,function*(){if(!this.config.disableThrottling){let i=!0;for(;i;)if(this.fetchingCount>=this.config.verificationsRequired)yield new Promise(a=>setTimeout(a,500));else{i=!1;break}}const n=this.knownImageServers[K($(e))];if(n&&!n.malformed&&!r){yield n.result;const i=this.loadServiceSync(e);if(i)return i}this.fetchingCount++;const o=yield this.fetchService($(e),r);return this.fetchingCount--,o.real&&this.sample(o,e),o})}loadServiceSync(e){const r=B($(e));return this.imageServices[r]?this.imageServices[r]:this.predict(e)}}new qt;const Wt=O.default.createContext(new qt);function ve(){return m.useContext(Wt)}const eo=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,to=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function me(t){if(Array.isArray(t))return t.reduce((e,r)=>{const{selector:n,selectors:o}=me(r);return n&&(e.selector||(e.selector=n),e.selectors.push(...o)),e},{selector:null,selectors:[]});if(!t)return{selector:null,selectors:[]};if(typeof t=="string"){const[e,r]=t.split("#");return r?me({type:"FragmentSelector",value:r}):{selector:null,selectors:[]}}if(t.type==="PointSelector"&&(t.t||t.t===0)){const e={type:"TemporalSelector",temporal:{startTime:t.t}};return{selector:e,selectors:[e]}}if(t.type==="FragmentSelector"){const e=eo.exec(t.value);if(e){const n={type:"BoxSelector",spatial:{unit:e[2]==="percent:"?"percent":"pixel",x:parseFloat(e[3]),y:parseFloat(e[4]),width:parseFloat(e[5]),height:parseFloat(e[6])}};return{selector:n,selectors:[n]}}const r=t.value.match(to);if(r){const n={type:"TemporalSelector",temporal:{startTime:r[4]?parseFloat(r[4]):0,endTime:r[7]?parseFloat(r[7]):void 0}};return{selector:n,selectors:[n]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}var ro=Object.defineProperty,no=Object.defineProperties,io=Object.getOwnPropertyDescriptors,Dt=Object.getOwnPropertySymbols,oo=Object.prototype.hasOwnProperty,ao=Object.prototype.propertyIsEnumerable,Vt=(t,e,r)=>e in t?ro(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Qt=(t,e)=>{for(var r in e||(e={}))oo.call(e,r)&&Vt(t,r,e[r]);if(Dt)for(var r of Dt(e))ao.call(e,r)&&Vt(t,r,e[r]);return t},zt=(t,e)=>no(t,io(e));function D(t,e={}){if(Array.isArray(t))return D(t[0]);if(typeof t=="string"){const[r,n]=t.split("#");return n?D({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{id:r,type:e.typeMap&&e.typeMap[r]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return D(t.items[0]);if(t.type==="SpecificResource"){t.source.type==="Canvas"&&t.source.partOf&&typeof t.source.partOf=="string"&&(t.source.partOf=[{id:t.source.partOf,type:"Manifest"}]);const{selector:r,selectors:n}=t.selector?me(t.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:r,selectors:n}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[r,n]=t.id.split("#");return n?D({type:"SpecificResource",source:zt(Qt({},t),{id:r}),selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:zt(Qt({},t),{id:r}),selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}function Bt(t){return t.type==="SpecificResource"?[t.source,{selector:t.selector}]:[t,{selector:null}]}function Ht(t,e,r){const n=[];let o=null;const i=[];for(const a of e){const s=t.get(a.body);for(const u of s){const[l,{selector:f}]=Bt(u),p=(l.type||"unknown").toLowerCase();if(p==="choice"){const d=t.get(l.items),v=r.length?r.map(c=>d.find(g=>g.id===c)).filter(Boolean):[d[0]];v.length===0&&v.push(d[0]),o={type:"single-choice",items:d.map(c=>({id:c.id,label:c.label,selected:v.indexOf(c)!==-1})),label:u.label},s.push(...v);continue}n.indexOf(p)===-1&&n.push(p),i.push({type:p,resource:l,target:a.target,selector:f})}}return{types:n,items:i,choice:o}}const Ut={makeChoice:()=>{}},_e={type:"unknown"},R=t=>({type:"unknown",reason:t,annotations:{pages:[]}});function Nt(t,e,r){const n=[];for(const o of e.items){const i=o.resource&&o.resource.type==="SpecificResource"?o.resource.source:o.resource;if(!i.id)return R("No resource Identifier");let a;if(i.service){const g=se(i);g[0]&&(a=r(g[0],t))}const{selector:s,source:u}=D(o.target);if(u.id!==t.id)continue;const l={type:"BoxSelector",spatial:{x:0,y:0,width:t.width,height:t.height}},f=s?s.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:s.temporal,spatial:l.spatial}:s:null,p={type:"BoxSelector",spatial:{x:0,y:0,width:t.width,height:t.height}},d=o.resource.type==="SpecificResource"?D(o.resource):null,v=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,c={id:i.id,type:"Image",width:f?i.width:t.width,height:f?i.height:t.height,service:a,sizes:a&&a.sizes?a.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:f&&f.type!=="PointSelector"?f:l,selector:v};n.push(c)}return{type:"images",image:n[0],images:n,choice:e.choice}}var so=Object.defineProperty,co=Object.defineProperties,uo=Object.getOwnPropertyDescriptors,Gt=Object.getOwnPropertySymbols,lo=Object.prototype.hasOwnProperty,fo=Object.prototype.propertyIsEnumerable,Kt=(t,e,r)=>e in t?so(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ho=(t,e)=>{for(var r in e||(e={}))lo.call(e,r)&&Kt(t,r,e[r]);if(Gt)for(var r of Gt(e))fo.call(e,r)&&Kt(t,r,e[r]);return t},po=(t,e)=>co(t,uo(e));function vo(t={},e=[]){const{id:r,selector:n}=t,o=Q(),i=E(),a=r||o.annotation,s=M(l=>a?l.iiif.entities.Annotation[a]:void 0,[a]),u=M(l=>s&&s.body?s.body.map(f=>f?l.iiif.entities[f.type][f.id]:null).filter(Boolean):[],[s]);return m.useMemo(()=>{if(!s)return;const l=po(ho({},s),{body:u,target:D(s.target,{typeMap:i.getState().iiif.mapping})});return n?n(l):l},[s,n,u,...e])}function le(t={},e=[]){const{id:r,selector:n}=t,o=Q();E();const i=r||o.manifest,a=M(s=>i?s.iiif.entities.Manifest[i]:void 0,[i]);return m.useMemo(()=>{if(!!a)return n?n(a):a},[a,n,...e])}function Y(t={},e=[]){const{id:r,selector:n}=t,o=Q(),i=r||o.canvas,a=M(s=>i?s.iiif.entities.Canvas[i]:void 0,[i]);return m.useMemo(()=>{if(!!a)return n?n(a):a},[a,n,...e])}function mo(t,e){var r;const n=(r=t==null?void 0:t.iiif)==null?void 0:r.meta[e];return n?n.annotationPageManager:null}function go(t,e){return M(r=>{const n=[];if(!t)return n;const o=Object.keys(r.iiif.entities.AnnotationPage);for(const i of o)if(!e||e.indexOf(i)!==-1){const a=mo(r,i);a&&a.views&&a.views[t]&&n.push(i)}return n},[t])}function Yt({canvas:t,manifest:e,all:r,canvases:n}){const o=[];if(e)for(const i of e.annotations)o.indexOf(i.id)===-1&&o.push(i.id);if(r){if(n&&n.length)for(const i of n)for(const a of i.annotations)o.indexOf(a.id)===-1&&o.push(a.id)}else if(t)for(const i of t.annotations)o.indexOf(i.id)===-1&&o.push(i.id);return o}var yo=Object.defineProperty,wo=Object.defineProperties,bo=Object.getOwnPropertyDescriptors,Jt=Object.getOwnPropertySymbols,So=Object.prototype.hasOwnProperty,xo=Object.prototype.propertyIsEnumerable,Zt=(t,e,r)=>e in t?yo(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Xt=(t,e)=>{for(var r in e||(e={}))So.call(e,r)&&Zt(t,r,e[r]);if(Jt)for(var r of Jt(e))xo.call(e,r)&&Zt(t,r,e[r]);return t},er=(t,e)=>wo(t,bo(e));function Oo(t,e){var r;const n=(r=t==null?void 0:t.iiif)==null?void 0:r.meta[e];return n?n.annotationPageManager:null}function tr(t,e={}){const r=E(),n=le(),o=Y(),i=ut(),a=m.useMemo(()=>Yt({all:e.all,manifest:n,canvas:o,canvases:i}),[e.all,o,i,n]),s=go(t,e.all?void 0:a),u=m.useCallback(f=>{!t||r.setMetaValue([f,"annotationPageManager","views"],p=>p&&!p[t]?p:er(Xt({},p||{}),{[t]:!1}))},[t,r]),l=m.useCallback((f,p={})=>{if(!t)return;const d=r.getState(),v=[];if(p==null?void 0:p.deselectOthers){const c=Object.keys(d.iiif.entities.AnnotationPage);for(const g of c){const x=Oo(d,g);x&&x.views&&x.views[t]&&v.push(g)}}for(const c of v)u(c);r.setMetaValue([f,"annotationPageManager","views"],c=>c&&c[t]?c:er(Xt({},c||{}),{[t]:!0}))},[t,u,r]);return{availablePageIds:a,enabledPageIds:s,setPageEnabled:l,setPageDisabled:u}}function ge(t={}){const e=Y(t.canvasId?{id:t.canvasId}:void 0);return M((r,n)=>{if(!e)return[];const o=n.get(e.items),i=[];for(const a of o)i.push(...n.get(a.items));return i},[e])}function Co(t,e={}){return ge(e)}function Ao(t,e=!1){}function Po(t,e=[]){const{id:r,selector:n}=t,o=Q(),i=r||o.collection,a=M(s=>i?s.iiif.entities.Collection[i]:void 0,[i]);return m.useMemo(()=>{if(!!a)return n?n(a):a},[a,n,...e])}function rr(){const e=E().getStore();return m.useMemo(()=>r=>e.dispatch(r),[e])}function nr(t){return{addEventListener(e,r,n,o){if(e)return t.setMetaValue([e.id,"eventManager",r],i=>{const a=i||[];for(const s of a)if(s.callback===n)return a;return[...a,{callback:n,scope:o}]}),n},removeEventListener(e,r,n){!e||t.setMetaValue([e.id,"eventManager",r],o=>(o||[]).filter(i=>i.callback!==n))},getListenersAsProps(e,r){const n=typeof e=="string"?{id:e}:e;if(!n||!n.id)return{};const o=t.getResourceMeta(n.id,"eventManager"),i={};if(o&&n)for(const a of Object.keys(o))i[a]=s=>{const u=t.get(n);for(const{callback:l,scope:f}of o[a]||[])(!f||r&&f.indexOf(r)!==-1)&&l(s,u)};return i}}}function ir(t){return{applyStyles(e,r,n){const o=typeof e=="string"?e:e.id;return t.setMetaValue([o,"styles",r],n)},getAppliedStyles(e){const r=typeof e=="string"?e:e.id;return t.getResourceMeta(r,"styles")}}}function J(t){return t.endsWith("info.json")?t:t.endsWith("/")?`${t}info.json`:`${t}/info.json`}function Io(t,e,r){const n=r.length,o=[];for(let i=0;i<n;i++){const a=r[i].width;o.push(t/a)}return o}function $o(t,e,r){const n=r.length,o=[];for(let i=0;i<n;i++){const a=r[i];o.push({width:Math.floor(t/a),height:Math.floor(e/a)})}return o}const _o="http://library.stanford.edu/iiif/image-api/compliance.html#level0",or="http://library.stanford.edu/iiif/image-api/compliance.html#level1",ar="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Eo="http://library.stanford.edu/iiif/image-api/conformance.html#level0",sr="http://library.stanford.edu/iiif/image-api/conformance.html#level1",cr="http://library.stanford.edu/iiif/image-api/conformance.html#level2",jo="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",ur="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",lr="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",To="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",fr="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",hr="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Mo="http://iiif.io/api/image/1/level0.json",Fo="http://iiif.io/api/image/1/profiles/level0.json",dr="http://iiif.io/api/image/1/level1.json",pr="http://iiif.io/api/image/1/profiles/level1.json",vr="http://iiif.io/api/image/1/level2.json",mr="http://iiif.io/api/image/1/profiles/level2.json",Lo="http://iiif.io/api/image/2/level0.json",ko="http://iiif.io/api/image/2/profiles/level0.json",gr="http://iiif.io/api/image/2/level1.json",yr="http://iiif.io/api/image/2/profiles/level1.json",wr="http://iiif.io/api/image/2/level2.json",br="http://iiif.io/api/image/2/profiles/level2.json",Ro="level0",Sr="level1",xr="level2",qo="http://iiif.io/api/image/2/level0",Or="http://iiif.io/api/image/2/level1",Cr="http://iiif.io/api/image/2/level2",Wo=[Or,Cr,or,ar,sr,cr,ur,lr,fr,hr,dr,pr,vr,mr,gr,yr,wr,br,Sr,xr],Do=[qo,Or,Cr,_o,or,ar,Eo,sr,cr,jo,ur,lr,To,fr,hr,Mo,Fo,dr,pr,vr,mr,Lo,ko,gr,yr,wr,br,Ro,Sr,xr];function _(t){if(t["@id"])return t["@id"];if(t.id)return t.id}function Ee(t){if(!t||!t.profile||!_(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const r of e)if(typeof r=="string"&&Do.indexOf(r)!==-1)return!0;return!1}function Vo(t){if(!Ee(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const r of e)if(typeof r=="string"){if(Wo.indexOf(r)!==-1)return!0}else{const n=r.supports||[];if(n.indexOf("regionByPx")!==-1&&(n.indexOf("sizeByW")!==-1||n.indexOf("sizeByWh")!==-1))return!0}return!1}function Qo(t){if(!Vo(t))return[];const e=[],r=Array.isArray(t.profile)?t.profile:[t.profile],n=r.length;for(let o=0;o<n;o++){const i=r[o];if(typeof i!="string"&&(i.maxHeight||i.maxWidth))return[{id:_(t),type:"variable",minWidth:0,minHeight:0,maxHeight:i.maxHeight||i.maxWidth,maxWidth:i.maxWidth||i.maxHeight}]}if(t.tiles){const o=t.tiles.length;for(let i=0;i<o;i++){const a=t.tiles[i];(a.height||a.width)&&e.push({id:_(t),type:"variable",minHeight:0,minWidth:0,maxHeight:a.height||a.width,maxWidth:a.width})}}return e}function Ar(t){const e=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,r=t.match(e);if(r){const n=r[1],o=parseInt(r[4],10),i=parseInt(r[5],10),a=r[7];if((n==="max"||n==="full")&&o&&i&&a)return{type:"fixed",id:t,height:i,width:o}}return{type:"unknown",id:t}}function zo(t){if(t["@type"])return t["@type"];if(t.type)return t.type}function je(t){if(typeof t=="string")return Ar(t);const e=zo(t);if(e!=="Image"&&e!=="sc:Image")return null;const r=t,n=_(r);return n?n&&r.width&&r.height?{id:n,type:"fixed",width:r.width,height:r.height,unsafe:!0}:Ar(n):null}function Bo(t){return Ee(t)?(t&&t.sizes?t.sizes:[]).map(e=>({id:_(t),type:"fixed-service",height:e.height,width:e.width})):[]}function Pr(t){const e=[],r=t.length;for(let n=0;n<r;n++){const o=Bo(t[n]);o.length&&e.push(...o);const i=Qo(t[n]);i.length&&e.push(...i)}return e}function Ir(t){const e=t.service?Array.isArray(t.service)?t.service:[t.service]:[],r=e.length,n=[];for(let o=0;o<r;o++)Ee(e[o])&&n.push(e[o]);return n}function Ho(t,e=!0,r){const n=[],o=je(t);if(o===null)return n;const i=t;if(n.push(o),e&&i.width&&i.height){const a=[],s=Ir(i);for(const u of s){const l={id:_(u),width:i.width,height:i.height};if(r.canLoadSync(l)){const f=r.loadServiceSync(l);f&&(f.height||(f.height=i.height),f.width||(f.width=i.width),a.push(...Pr([f])))}}if(a.length)return n.push(...a),n}return i.service&&n.push(...Pr(i.service)),n}function Te(t,e,r){return{id:[J(_(t)).slice(0,-10),"full",[e,r||""].join(","),0,"default.jpg"].join("/"),type:"fixed",width:e,height:r||t.height/t.width*e,unsafe:t.width>e}}function Z(t){const e=t.replace(/(https?:\/\/)?(www.)?/i,"");return e.indexOf("/")!==-1?e.split("/")[0]:e}function Uo(t,e,r){const n=t.width?t.width:t.maxWidth;return r.height<=t.maxHeight&&r.width<=t.maxWidth&&r.height>=t.minHeight&&r.width>=t.minWidth&&(!e||Math.abs(r.width-n)<Math.abs(e.width-n))}function No(t,e){const r=[],n=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},t),o=[],i=[];let a=null;const s=(l,f)=>{if(Uo(n,f,l)){if(n.preferFixedSize&&l.unsafe){i.push(l);return}n.returnAllOptions&&f&&i.push(f),a=l}else n.returnAllOptions&&i.push(l)},u=e.length;for(let l=0;l<u;l++){const f=e[l](),p=f.length;for(let d=0;d<p;d++){const v=f[d];if(v.type==="unknown"&&n.atAnyCost&&o.push(v),v.type==="fixed"&&(v.unsafe?o.push(v):s(v,a)),v.type==="fixed-service")if(n.unsafeImageService){const c=Te(v,n.width,n.height);s(c,a)}else{const c=Te(v,v.width,v.height);s(c,a)}if(v.type==="variable"&&v.maxWidth){const c=Te({id:v.id,type:"fixed-service",width:v.maxWidth,height:v.maxWidth},v.maxWidth);s(c,a)}}if(a&&!n.returnAllOptions){if(a.unsafe||n.allowUnsafe)continue;break}}return n.atAnyCost&&i.length===0?{best:a||o[0],fallback:o.slice(1),log:r}:n.returnAllOptions?{best:n.atAnyCost?a||i[0]||o[0]:a||i[0],fallback:[...i,...o],log:r}:{best:a||i[0]||null,fallback:a?i:i.slice(1),log:r}}function Go(t,e,r){const n=t>e?t:e,o=r.length,i=[];for(let a=0;a<o;a++){const s=r[a];let u=s.scaleFactors[0],l=n/u;const f=[u];for(;l>=s.width;)u=u*2,f.push(u),l=l/2;i.push(Object.assign(Object.assign({},s),{scaleFactors:f}))}return i}function Ko(t,e){if(t.length!==e.length)return!1;if(t.length===0&&e.length===0)return!0;const r=t.length;let n=!0;for(let i=0;i<r;i++){const a=t[i],s=e[i];if(a.width!==s.width||a.height!==s.height){n=!1;break}}if(n)return!0;let o=0;for(let i=0;i<r;i++)for(let a=0;a<r;a++)if(t[i].width===e[a].width&&t[i].height===e[a].height){o++;break}return o===r}/*! *****************************************************************************
2
2
  Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4
4
  this file except in compliance with the License. You may obtain a copy of the
@@ -11,17 +11,4 @@
11
11
 
12
12
  See the Apache Version 2.0 License for specific language governing permissions
13
13
  and limitations under the License.
14
- ***************************************************************************** */function z(e,t,n,i){function o(r){return r instanceof n?r:new n(function(a){a(r)})}return new(n||(n=Promise))(function(r,a){function s(f){try{l(i.next(f))}catch(d){a(d)}}function u(f){try{l(i.throw(f))}catch(d){a(d)}}function l(f){f.done?r(f.value):o(f.value).then(s,u)}l((i=i.apply(e,t||[])).next())})}class St{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(t){Object.assign(this.config,t)}sample(t,n,i=!0){const o=N(E(t)),r=W(E(t)),a=this.knownImageServers[o];return this.imageServices[r]=Object.assign(t,{real:!0}),a?this.verify(t):(this.knownImageServers[o]={verifications:0,malformed:!1,root:o,preLoaded:i,sampledId:E(t),verified:!1,server:null,result:{context:t["@context"]||[],sampledProfile:t.profile,resourceServiceRatio:n&&t.height?n.height/t.height:1,sampledSizes:t.sizes||[],sizeRatios:ui(t.width,t.height,t.sizes||[]),sampledTiles:t.tiles||[]}},!0)}preLoad(t,n=!0){this.knownImageServers[t.root]=t,n&&(this.knownImageServers[t.root].malformed=!1,this.knownImageServers[t.root].verifications=this.config.verificationsRequired)}predict(t,n=!1,i=!1){const o=N(E(t)),r=this.knownImageServers[o];if(!r||!r.result||!i&&(r.malformed||r.verifications<this.config.verificationsRequired))return null;const a=W(E(t));return this.imageServices[a]||(this.imageServices[a]={"@context":r.result.context,"@id":E(t),id:E(t),protocol:"http://iiif.io/api/image",tiles:Mi(t.width,t.height,r.result.sampledTiles),sizes:li(Math.floor(t.width/r.result.resourceServiceRatio),Math.floor(t.height/r.result.resourceServiceRatio),r.result.sizeRatios),profile:r.result.sampledProfile,height:t.height,width:t.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(t,n,i=!0,o=[]){return z(this,void 0,void 0,function*(){const r=yield this.getImageCandidates(t,i);return Ai(n,[()=>o,()=>r])})}getImageCandidates(t,n=!0){return z(this,void 0,void 0,function*(){const i=t;if(n&&i.height&&i.width){const o=Y(i);for(const r of o){const a={id:E(r),width:r.width?r.width:i.width,height:r.height?r.height:i.height};yield this.loadService(a)}}return Pi(t,n,this)})}verify(t){return z(this,void 0,void 0,function*(){const n=this.predict(t,!1,!0),i=yield this.fetchService(E(t));if(!n)return!1;const o=n.height===i.height&&n.width===i.width&&n["@context"]===i["@context"]&&ji(n.sizes||[],i.sizes||[]);if(o){const r=N(E(t));this.knownImageServers[r].verifications+=1,this.knownImageServers[r].verifications>=this.config.verificationsRequired&&(this.knownImageServers[r].verified=!0)}return o})}canLoadSync(t){const n=typeof t=="string"?t:E(t),i=W(n);if(this.imageServices[i])return!0;const o=this.knownImageServers[N(n)];return o&&!o.malformed&&o.verifications>=this.config.verificationsRequired}markAsMalformed(t){return z(this,void 0,void 0,function*(){return this.knownImageServers[N(E(t))].malformed=!0,this.loadService(t,!0)})}fetchService(t,n=!1){return z(this,void 0,void 0,function*(){const i=W(t);if(this.imageServices[i]&&(!n||this.imageServices[i].real))return this.imageServices[i];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const o=yield fetch(i).then(r=>r.json());return!o.id&&o["@id"]&&(o.id=o["@id"]),o.id!==t&&(o.id=t,o["@id"]&&(o["@id"]=t)),this.imageServices[i]=Object.assign(o,{real:!0}),this.imageServices[i]})}loadService(t,n=!1){return z(this,void 0,void 0,function*(){if(!this.config.disableThrottling)for(;this.fetchingCount>=this.config.verificationsRequired;)yield new Promise(r=>setTimeout(r,500));const i=this.knownImageServers[N(E(t))];if(i&&!i.malformed&&!n){yield i.result;const r=this.loadServiceSync(t);if(r)return r}this.fetchingCount++;const o=yield this.fetchService(E(t),n);return this.fetchingCount--,o.real&&this.sample(o,t),o})}loadServiceSync(t){const n=W(E(t));return this.imageServices[n]?this.imageServices[n]:this.predict(t)}}new St;const It=I.default.createContext(new St);function re(){return v.useContext(It)}const Li=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,Ti=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function oe(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:i,selectors:o}=oe(n);return i&&(t.selector||(t.selector=i),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?oe({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",startTime:e.t};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=Li.exec(e.value);if(t){const i={type:"BoxSelector",unit:t[2]==="percent:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])};return{selector:i,selectors:[i]}}const n=e.value.match(Ti);if(n){const i={type:"TemporalSelector",startTime:n[4]?parseFloat(n[4]):0,endTime:n[7]?parseFloat(n[7]):void 0};return{selector:i,selectors:[i]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}var ki=Object.defineProperty,Vi=Object.defineProperties,Ri=Object.getOwnPropertyDescriptors,_t=Object.getOwnPropertySymbols,$i=Object.prototype.hasOwnProperty,Di=Object.prototype.propertyIsEnumerable,Ot=(e,t,n)=>t in e?ki(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,bt=(e,t)=>{for(var n in t||(t={}))$i.call(t,n)&&Ot(e,n,t[n]);if(_t)for(var n of _t(t))Di.call(t,n)&&Ot(e,n,t[n]);return e},Ct=(e,t)=>Vi(e,Ri(t));function V(e,t={}){if(Array.isArray(e))return V(e[0]);if(typeof e=="string"){const[n,i]=e.split("#");return i?V({type:"SpecificResource",source:{id:n,type:"Unknown"},selector:{type:"FragmentSelector",value:i}}):{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 V(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:i}=e.selector?oe(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:n,selectors:i}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[n,i]=e.id.split("#");return i?V({type:"SpecificResource",source:Ct(bt({},e),{id:n}),selector:{type:"FragmentSelector",value:i}}):{type:"SpecificResource",source:Ct(bt({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}var qi=Object.defineProperty,Wi=Object.defineProperties,Ni=Object.getOwnPropertyDescriptors,Et=Object.getOwnPropertySymbols,zi=Object.prototype.hasOwnProperty,Gi=Object.prototype.propertyIsEnumerable,xt=(e,t,n)=>t in e?qi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Hi=(e,t)=>{for(var n in t||(t={}))zi.call(t,n)&&xt(e,n,t[n]);if(Et)for(var n of Et(t))Gi.call(t,n)&&xt(e,n,t[n]);return e},Qi=(e,t)=>Wi(e,Ni(t));function Bi(e={},t=[]){const{id:n,selector:i}=e,o=R(),r=A(),a=n||o.annotation,s=k(l=>a?l.iiif.entities.Annotation[a]:void 0,[a]),u=k(l=>s&&s.body?s.body.map(f=>f?l.iiif.entities[f.type][f.id]:null).filter(Boolean):[],[s]);return v.useMemo(()=>{if(!s)return;const l=Qi(Hi({},s),{body:u,target:V(s.target,{typeMap:r.getState().iiif.mapping})});return i?i(l):l},[s,i,u,...t])}function Z(e={},t=[]){const{id:n,selector:i}=e,o=R(),r=A(),a=n||o.manifest,s=a?r.select(u=>u.iiif.entities.Manifest[a]):void 0;return v.useMemo(()=>{if(!!s)return i?i(s):s},[s,i,...t])}function G(e={},t=[]){const{id:n,selector:i}=e,o=R(),r=A(),a=n||o.canvas,s=a?r.select(u=>u.iiif.entities.Canvas[a]):void 0;return v.useMemo(()=>{if(!!s)return i?i(s):s},[s,i,...t])}function Ui(e,t){var n;const i=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return i?i.annotationPageManager:null}function Ji(e,t){return k(n=>{const i=[];if(!e)return i;const o=Object.keys(n.iiif.entities.AnnotationPage);for(const r of o)if(!t||t.indexOf(r)!==-1){const a=Ui(n,r);a&&a.views&&a.views[e]&&i.push(r)}return i},[e])}function Pt({canvas:e,manifest:t,all:n,canvases:i}){const o=[];if(t)for(const r of t.annotations)o.indexOf(r.id)===-1&&o.push(r.id);if(n){if(i&&i.length)for(const r of i)for(const a of r.annotations)o.indexOf(a.id)===-1&&o.push(a.id)}else if(e)for(const r of e.annotations)o.indexOf(r.id)===-1&&o.push(r.id);return o}var Ki=Object.defineProperty,Xi=Object.defineProperties,Yi=Object.getOwnPropertyDescriptors,Ft=Object.getOwnPropertySymbols,Zi=Object.prototype.hasOwnProperty,er=Object.prototype.propertyIsEnumerable,At=(e,t,n)=>t in e?Ki(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Mt=(e,t)=>{for(var n in t||(t={}))Zi.call(t,n)&&At(e,n,t[n]);if(Ft)for(var n of Ft(t))er.call(t,n)&&At(e,n,t[n]);return e},jt=(e,t)=>Xi(e,Yi(t));function tr(e,t){var n;const i=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return i?i.annotationPageManager:null}function Lt(e,t={}){const n=A(),i=Z(),o=G(),r=Xe(),a=v.useMemo(()=>Pt({all:t.all,manifest:i,canvas:o,canvases:r}),[t.all,o,r,i]),s=Ji(e,t.all?void 0:a),u=v.useCallback(f=>{!e||n.setMetaValue([f,"annotationPageManager","views"],d=>d&&!d[e]?d:jt(Mt({},d||{}),{[e]:!1}))},[e,n]),l=v.useCallback((f,d={})=>{if(!e)return;const m=n.getState(),p=[];if(d==null?void 0:d.deselectOthers){const c=Object.keys(m.iiif.entities.AnnotationPage);for(const h of c){const w=tr(m,h);w&&w.views&&w.views[e]&&p.push(h)}}for(const c of p)u(c);n.setMetaValue([f,"annotationPageManager","views"],c=>c&&c[e]?c:jt(Mt({},c||{}),{[e]:!0}))},[e,u,n]);return{availablePageIds:a,enabledPageIds:s,setPageEnabled:l,setPageDisabled:u}}function ae(e={}){const t=G(e.canvasId?{id:e.canvasId}:void 0);return k((n,i)=>{if(!t)return[];const o=i.get(t.items),r=[];for(const a of o)r.push(...i.get(a.items));return r},[t])}function nr(e,t={}){return ae(t)}function ir(e,t=!1){}function rr(e,t=[]){const{id:n,selector:i}=e,o=R(),r=A(),a=n||o.collection,s=a?r.select(u=>u.iiif.entities.Collection[a]):void 0;return v.useMemo(()=>{if(!!s)return i?i(s):s},[s,i,...t])}function or(){const t=A().getStore();return v.useMemo(()=>n=>t.dispatch(n),[t])}function Tt(e){return{addEventListener(t,n,i,o){if(t)return e.setMetaValue([t.id,"eventManager",n],r=>{const a=r||[];for(const s of a)if(s.callback===i)return a;return[...a,{callback:i,scope:o}]}),i},removeEventListener(t,n,i){!t||e.setMetaValue([t.id,"eventManager",n],o=>(o||[]).filter(r=>r.callback!==i))},getListenersAsProps(t,n){const i=typeof t=="string"?{id:t}:t;if(!i||!i.id)return{};const o=e.getResourceMeta(i.id,"eventManager"),r={};if(o&&i)for(const a of Object.keys(o))r[a]=s=>{const u=e.get(i);for(const{callback:l,scope:f}of o[a]||[])(!f||n&&f.indexOf(n)!==-1)&&l(s,u)};return r}}}function ar(e){return{applyStyles(t,n,i){const o=typeof t=="string"?t:t.id;return e.setMetaValue([o,"styles",n],i)},getAppliedStyles(t){const n=typeof t=="string"?t:t.id;return e.getResourceMeta(n,"styles")}}}function H(e){return e.endsWith("info.json")?e:e.endsWith("/")?`${e}info.json`:`${e}/info.json`}function sr(e,t,n){const i=n.length,o=[];for(let r=0;r<i;r++){const a=n[r].width;o.push(e/a)}return o}function cr(e,t,n){const i=n.length,o=[];for(let r=0;r<i;r++){const a=n[r];o.push({width:Math.floor(e/a),height:Math.floor(t/a)})}return o}const ur="http://library.stanford.edu/iiif/image-api/compliance.html#level0",kt="http://library.stanford.edu/iiif/image-api/compliance.html#level1",Vt="http://library.stanford.edu/iiif/image-api/compliance.html#level2",lr="http://library.stanford.edu/iiif/image-api/conformance.html#level0",Rt="http://library.stanford.edu/iiif/image-api/conformance.html#level1",$t="http://library.stanford.edu/iiif/image-api/conformance.html#level2",fr="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Dt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",qt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",hr="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Wt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Nt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",dr="http://iiif.io/api/image/1/level0.json",pr="http://iiif.io/api/image/1/profiles/level0.json",zt="http://iiif.io/api/image/1/level1.json",Gt="http://iiif.io/api/image/1/profiles/level1.json",Ht="http://iiif.io/api/image/1/level2.json",Qt="http://iiif.io/api/image/1/profiles/level2.json",vr="http://iiif.io/api/image/2/level0.json",gr="http://iiif.io/api/image/2/profiles/level0.json",Bt="http://iiif.io/api/image/2/level1.json",Ut="http://iiif.io/api/image/2/profiles/level1.json",Jt="http://iiif.io/api/image/2/level2.json",Kt="http://iiif.io/api/image/2/profiles/level2.json",mr="level0",Xt="level1",Yt="level2",yr="http://iiif.io/api/image/2/level0",Zt="http://iiif.io/api/image/2/level1",en="http://iiif.io/api/image/2/level2",wr=[Zt,en,kt,Vt,Rt,$t,Dt,qt,Wt,Nt,zt,Gt,Ht,Qt,Bt,Ut,Jt,Kt,Xt,Yt],Sr=[yr,Zt,en,ur,kt,Vt,lr,Rt,$t,fr,Dt,qt,hr,Wt,Nt,dr,pr,zt,Gt,Ht,Qt,vr,gr,Bt,Ut,Jt,Kt,mr,Xt,Yt];function x(e){if(e["@id"])return e["@id"];if(e.id)return e.id}function we(e){if(!e||!e.profile||!x(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const n of t)if(typeof n=="string"&&Sr.indexOf(n)!==-1)return!0;return!1}function Ir(e){if(!we(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const n of t)if(typeof n=="string"){if(wr.indexOf(n)!==-1)return!0}else{const i=n.supports||[];if(i.indexOf("regionByPx")!==-1&&(i.indexOf("sizeByW")!==-1||i.indexOf("sizeByWh")!==-1))return!0}return!1}function _r(e){if(!Ir(e))return[];const t=[],n=Array.isArray(e.profile)?e.profile:[e.profile],i=n.length;for(let o=0;o<i;o++){const r=n[o];if(typeof r!="string"&&(r.maxHeight||r.maxWidth))return[{id:x(e),type:"variable",minWidth:0,minHeight:0,maxHeight:r.maxHeight||r.maxWidth,maxWidth:r.maxWidth||r.maxHeight}]}if(e.tiles){const o=e.tiles.length;for(let r=0;r<o;r++){const a=e.tiles[r];(a.height||a.width)&&t.push({id:x(e),type:"variable",minHeight:0,minWidth:0,maxHeight:a.height||a.width,maxWidth:a.width})}}return t}function tn(e){const t=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,n=e.match(t);if(n){const i=n[1],o=parseInt(n[4],10),r=parseInt(n[5],10),a=n[7];if((i==="max"||i==="full")&&o&&r&&a)return{type:"fixed",id:e,height:r,width:o}}return{type:"unknown",id:e}}function Or(e){if(e["@type"])return e["@type"];if(e.type)return e.type}function Se(e){if(typeof e=="string")return tn(e);const t=Or(e);if(t!=="Image"&&t!=="sc:Image")return null;const n=e,i=x(n);return i?i&&n.width&&n.height?{id:i,type:"fixed",width:n.width,height:n.height,unsafe:!0}:tn(i):null}function br(e){return we(e)?(e&&e.sizes?e.sizes:[]).map(t=>({id:x(e),type:"fixed-service",height:t.height,width:t.width})):[]}function nn(e){const t=[],n=e.length;for(let i=0;i<n;i++){const o=br(e[i]);o.length&&t.push(...o);const r=_r(e[i]);r.length&&t.push(...r)}return t}function rn(e){const t=e.service?Array.isArray(e.service)?e.service:[e.service]:[],n=t.length,i=[];for(let o=0;o<n;o++)we(t[o])&&i.push(t[o]);return i}function Cr(e,t=!0,n){const i=[],o=Se(e);if(o===null)return i;const r=e;if(i.push(o),t&&r.width&&r.height){const a=[],s=rn(r);for(const u of s){const l={id:x(u),width:r.width,height:r.height};if(n.canLoadSync(l)){const f=n.loadServiceSync(l);f&&(f.height||(f.height=r.height),f.width||(f.width=r.width),a.push(...nn([f])))}}if(a.length)return i.push(...a),i}return r.service&&i.push(...nn(r.service)),i}function Ie(e,t,n){return{id:[H(x(e)).slice(0,-10),"full",[t,n||""].join(","),0,"default.jpg"].join("/"),type:"fixed",width:t,height:n||e.height/e.width*t,unsafe:e.width>t}}function Q(e){const t=e.replace(/(https?:\/\/)?(www.)?/i,"");return t.indexOf("/")!==-1?t.split("/")[0]:t}function Er(e,t,n){const i=e.width?e.width:e.maxWidth;return n.height<=e.maxHeight&&n.width<=e.maxWidth&&n.height>=e.minHeight&&n.width>=e.minWidth&&(!t||Math.abs(n.width-i)<Math.abs(t.width-i))}function xr(e,t){const n=[],i=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},e),o=[],r=[];let a=null;const s=(l,f)=>{if(Er(i,f,l)){if(i.preferFixedSize&&l.unsafe){r.push(l);return}i.returnAllOptions&&f&&r.push(f),a=l}else i.returnAllOptions&&r.push(l)},u=t.length;for(let l=0;l<u;l++){const f=t[l](),d=f.length;for(let m=0;m<d;m++){const p=f[m];if(p.type==="unknown"&&i.atAnyCost&&o.push(p),p.type==="fixed"&&(p.unsafe?o.push(p):s(p,a)),p.type==="fixed-service")if(i.unsafeImageService){const c=Ie(p,i.width,i.height);s(c,a)}else{const c=Ie(p,p.width,p.height);s(c,a)}if(p.type==="variable"&&p.maxWidth){const c=Ie({id:p.id,type:"fixed-service",width:p.maxWidth,height:p.maxWidth},p.maxWidth);s(c,a)}}if(a&&!i.returnAllOptions){if(a.unsafe||i.allowUnsafe)continue;break}}return i.atAnyCost&&r.length===0?{best:a||o[0],fallback:o.slice(1),log:n}:i.returnAllOptions?{best:i.atAnyCost?a||r[0]||o[0]:a||r[0],fallback:[...r,...o],log:n}:{best:a||r[0]||null,fallback:a?r:r.slice(1),log:n}}function Pr(e,t,n){const i=e>t?e:t,o=n.length,r=[];for(let a=0;a<o;a++){const s=n[a];let u=s.scaleFactors[0],l=i/u;const f=[u];for(;l>=s.width;)u=u*2,f.push(u),l=l/2;r.push(Object.assign(Object.assign({},s),{scaleFactors:f}))}return r}function Fr(e,t){if(e.length!==t.length)return!1;if(e.length===0&&t.length===0)return!0;const n=e.length;let i=!0;for(let r=0;r<n;r++){const a=e[r],s=t[r];if(a.width!==s.width||a.height!==s.height){i=!1;break}}if(i)return!0;let o=0;for(let r=0;r<n;r++)for(let a=0;a<n;a++)if(e[r].width===t[a].width&&e[r].height===t[a].height){o++;break}return o===n}/*! *****************************************************************************
15
- Copyright (c) Microsoft Corporation. All rights reserved.
16
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
17
- this file except in compliance with the License. You may obtain a copy of the
18
- License at http://www.apache.org/licenses/LICENSE-2.0
19
-
20
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
22
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
23
- MERCHANTABLITY OR NON-INFRINGEMENT.
24
-
25
- See the Apache Version 2.0 License for specific language governing permissions
26
- and limitations under the License.
27
- ***************************************************************************** */function B(e,t,n,i){function o(r){return r instanceof n?r:new n(function(a){a(r)})}return new(n||(n=Promise))(function(r,a){function s(f){try{l(i.next(f))}catch(d){a(d)}}function u(f){try{l(i.throw(f))}catch(d){a(d)}}function l(f){f.done?r(f.value):o(f.value).then(s,u)}l((i=i.apply(e,t||[])).next())})}class on{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(t){Object.assign(this.config,t)}sample(t,n,i=!0){const o=Q(x(t)),r=H(x(t)),a=this.knownImageServers[o];return this.imageServices[r]=Object.assign(t,{real:!0}),a?this.verify(t):(this.knownImageServers[o]={verifications:0,malformed:!1,root:o,preLoaded:i,sampledId:x(t),verified:!1,server:null,result:{context:t["@context"]||[],sampledProfile:t.profile,resourceServiceRatio:n&&t.height?n.height/t.height:1,sampledSizes:t.sizes||[],sizeRatios:sr(t.width,t.height,t.sizes||[]),sampledTiles:t.tiles||[]}},!0)}preLoad(t,n=!0){this.knownImageServers[t.root]=t,n&&(this.knownImageServers[t.root].malformed=!1,this.knownImageServers[t.root].verifications=this.config.verificationsRequired)}predict(t,n=!1,i=!1){const o=Q(x(t)),r=this.knownImageServers[o];if(!r||!r.result||!i&&(r.malformed||r.verifications<this.config.verificationsRequired))return null;const a=H(x(t));return this.imageServices[a]||(this.imageServices[a]={"@context":r.result.context,"@id":x(t),id:x(t),protocol:"http://iiif.io/api/image",tiles:Pr(t.width,t.height,r.result.sampledTiles),sizes:cr(Math.floor(t.width/r.result.resourceServiceRatio),Math.floor(t.height/r.result.resourceServiceRatio),r.result.sizeRatios),profile:r.result.sampledProfile,height:t.height,width:t.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(t,n,i=!0,o=[]){return B(this,void 0,void 0,function*(){const r=yield this.getImageCandidates(t,i);return xr(n,[()=>o,()=>r])})}getImageCandidates(t,n=!0){return B(this,void 0,void 0,function*(){const i=t;if(n&&i.height&&i.width){const o=rn(i);for(const r of o){const a={id:x(r),width:r.width?r.width:i.width,height:r.height?r.height:i.height};yield this.loadService(a)}}return Cr(t,n,this)})}verify(t){return B(this,void 0,void 0,function*(){const n=this.predict(t,!1,!0),i=yield this.fetchService(x(t));if(!n)return!1;const o=n.height===i.height&&n.width===i.width&&n["@context"]===i["@context"]&&Fr(n.sizes||[],i.sizes||[]);if(o){const r=Q(x(t));this.knownImageServers[r].verifications+=1,this.knownImageServers[r].verifications>=this.config.verificationsRequired&&(this.knownImageServers[r].verified=!0)}return o})}canLoadSync(t){const n=typeof t=="string"?t:x(t),i=H(n);if(this.imageServices[i])return!0;const o=this.knownImageServers[Q(n)];return o&&!o.malformed&&o.verifications>=this.config.verificationsRequired}markAsMalformed(t){return B(this,void 0,void 0,function*(){return this.knownImageServers[Q(x(t))].malformed=!0,this.loadService(t,!0)})}fetchService(t,n=!1){return B(this,void 0,void 0,function*(){const i=H(t);if(this.imageServices[i]&&(!n||this.imageServices[i].real))return this.imageServices[i];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const o=yield fetch(i).then(r=>r.json());return!o.id&&o["@id"]&&(o.id=o["@id"]),o.id!==t&&(o.id=t,o["@id"]&&(o["@id"]=t)),this.imageServices[i]=Object.assign(o,{real:!0}),this.imageServices[i]})}loadService(t,n=!1){return B(this,void 0,void 0,function*(){if(!this.config.disableThrottling)for(;this.fetchingCount>=this.config.verificationsRequired;)yield new Promise(r=>setTimeout(r,500));const i=this.knownImageServers[Q(x(t))];if(i&&!i.malformed&&!n){yield i.result;const r=this.loadServiceSync(t);if(r)return r}this.fetchingCount++;const o=yield this.fetchService(x(t),n);return this.fetchingCount--,o.real&&this.sample(o,t),o})}loadServiceSync(t){const n=H(x(t));return this.imageServices[n]?this.imageServices[n]:this.predict(t)}}new on;function Ar(e,t={}){const n=t.imageServiceLoader||new on;async function i(o,r,a,s=[],u){if(typeof o=="string")return{best:Se(o),fallback:[],log:[]};const l=e.get(o);if(typeof l=="string")return{best:Se(l),fallback:[],log:[]};switch(l.type){case"Annotation":{const f=l.body,d=e.get(f[0]);return u&&!d.width&&(d.width=u.width,d.height=u.height),await n.getThumbnailFromResource(d,r,a,s)}case"Canvas":{const f=l;if(f.thumbnail&&f.thumbnail.length){const d=e.get(f.thumbnail[0]),m=await n.getImageCandidates(d,a);m&&m.length&&s.push(...m)}return i(f.items[0],r,a,s,{width:f.width,height:f.height})}case"AnnotationPage":return i(l.items[0],r,a,s,u);case"Choice":return i(l.items[0],r,a,s,u);case"Collection":{const f=l.items[0];return i(f,r,a,s,u)}case"Manifest":{const f=l.items[0];return i(f,r,a,s,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,r,a,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:i}}function Mr(e,t,n,i,o=[]){const r=A(),a=v.useMemo(()=>Tt(r),[r]);v.useEffect(()=>{const s=e;return s?(a.addEventListener(s,t,n,i),()=>{a.removeEventListener(s,t,n)}):()=>{}},[a,e,t,...o])}var jr=Object.defineProperty,an=Object.getOwnPropertySymbols,Lr=Object.prototype.hasOwnProperty,Tr=Object.prototype.propertyIsEnumerable,sn=(e,t,n)=>t in e?jr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,kr=(e,t)=>{for(var n in t||(t={}))Lr.call(t,n)&&sn(e,n,t[n]);if(an)for(var n of an(t))Tr.call(t,n)&&sn(e,n,t[n]);return e},Vr=(e,t,n)=>new Promise((i,o)=>{var r=u=>{try{s(n.next(u))}catch(l){o(l)}},a=u=>{try{s(n.throw(u))}catch(l){o(l)}},s=u=>u.done?i(u.value):Promise.resolve(u.value).then(r,a);s((n=n.apply(e,t)).next())});const Rr=(e,t={})=>{const n=A(),[i,o]=v.useState(e),r=v.useMemo(()=>n.get(e),[e,n]),{data:a,isFetching:s}=ge(`collection:${e}`,()=>Vr(void 0,null,function*(){const u=r||(yield n.loadCollection(e));return u&&o(u.id),u}),kr({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,initialData:r},t));return{isLoaded:!s,id:i,collection:a}};var $r=(e,t,n)=>new Promise((i,o)=>{var r=u=>{try{s(n.next(u))}catch(l){o(l)}},a=u=>{try{s(n.throw(u))}catch(l){o(l)}},s=u=>u.done?i(u.value):Promise.resolve(u.value).then(r,a);s((n=n.apply(e,t)).next())});function cn(){const e=G(),t=ae(),n=A(),i=re();return ge(`canvas-first-image-service:${e?e.id:"undefined"}`,()=>$r(this,null,function*(){if(e&&t.length){const o=t[0],r=n.get(o.body[0]),s=Y(r)[0];return s&&(yield i.loadService({id:s.id||s["@id"],width:s.width||e.width,height:s.height||e.height}))||void 0}}),{refetchOnWindowFocus:!1,refetchOnMount:!1,refetchIntervalInBackground:!1,refetchInterval:!1,initialData:()=>{if(e&&t.length){const o=t[0],r=n.get(o.body[0]),s=Y(r)[0];return s&&i.loadServiceSync({id:s.id||s["@id"],width:s.width||e.width,height:s.height||e.height})||void 0}}})}function Dr(){const e=cn();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 qr(e={},t=[]){const{id:n,selector:i}=e,o=R(),r=A(),a=n||o.range,s=a?r.select(u=>u.iiif.entities.Range[a]):void 0;return v.useMemo(()=>{if(!!s)return i?i(s):s},[s,i,...t])}function Wr(e,t){const n=A(),i=v.useMemo(()=>Tt(n),[n]),o=k(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return v.useMemo(()=>e?i.getListenersAsProps(e,t):{},[o,e,n,t])}function un(e,t){return k((n,i)=>i.get(e.map(o=>({id:o,type:t}))),[e,t])}function Nr(){const e=Z();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function zr(e,t){const n=A(),i=v.useMemo(()=>ar(n),[n]);return k(()=>{if(!e)return null;const o=i.getAppliedStyles(e.id);return o?t?o[t]:o:void 0},[e,t])}const ln=(e,t=[])=>{const n=A();v.useEffect(()=>{e(n)},[n,...t])};function Gr(e,t,{canvasId:n,manifestId:i}={}){const o=A(),r=re(),a=v.useMemo(()=>Ar(o,{imageServiceLoader:r}),[o,r]),[s,u]=v.useState(),l=Z(i?{id:i}:void 0),f=G(n?{id:n}:void 0),d=f||l,m=v.useRef(!1);if(v.useEffect(()=>()=>{m.current=!0},[]),!d)throw new Error("Must be called under a manifest or canvas context.");return ln(p=>{a.getBestThumbnailAtSize(d,e,t).then(c=>{c.best&&!m.current&&u(c.best)})},[d]),s}var Hr=Object.defineProperty,Qr=Object.defineProperties,Br=Object.getOwnPropertyDescriptors,fn=Object.getOwnPropertySymbols,Ur=Object.prototype.hasOwnProperty,Jr=Object.prototype.propertyIsEnumerable,hn=(e,t,n)=>t in e?Hr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,dn=(e,t)=>{for(var n in t||(t={}))Ur.call(t,n)&&hn(e,n,t[n]);if(fn)for(var n of fn(t))Jr.call(t,n)&&hn(e,n,t[n]);return e},pn=(e,t)=>Qr(e,Br(t));function vn(){const e=re(),[t,n]=v.useState({}),i=v.useRef(!1);return v.useEffect(()=>()=>{i.current=!0},[]),[v.useCallback((r,{height:a,width:s})=>{if(r){const u=r.id||r["@id"],l=e.loadServiceSync({id:u,width:r.width||s,height:r.height||a});l?r=l:t[u]||(i.current||n(f=>pn(dn({},f),{[u]:"loading"})),e.loadService({id:u,width:r.width||s,height:r.height||a}).then(()=>{i.current||n(f=>pn(dn({},f),{[u]:"done"}))}))}return r},[e,t]),t]}function _e(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function Kr(e,t){const n=[],i=[];for(const o of t){const r=e.get(o.body);for(const a of r){const[s,{selector:u}]=_e(a),l=(s.type||"unknown").toLowerCase();if(l==="choice"){const f=e.get(s.items);r.push(f[0]);continue}n.indexOf(l)===-1&&n.push(l),i.push({type:l,resource:s,target:o.target,selector:u})}}return{types:n,items:i}}var Xr=Object.defineProperty,Yr=Object.defineProperties,Zr=Object.getOwnPropertyDescriptors,gn=Object.getOwnPropertySymbols,eo=Object.prototype.hasOwnProperty,to=Object.prototype.propertyIsEnumerable,mn=(e,t,n)=>t in e?Xr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,no=(e,t)=>{for(var n in t||(t={}))eo.call(t,n)&&mn(e,n,t[n]);if(gn)for(var n of gn(t))to.call(t,n)&&mn(e,n,t[n]);return e},io=(e,t)=>Yr(e,Zr(t));const yn={makeChoice:()=>{}},wn=[{type:"unknown"},yn],se=e=>[{type:"unknown",reason:e,annotations:{pages:[]}},yn];function ro(e){const t=Z(),n=G(),i=ae(),o=A(),[r,a]=vn(),{enabledPageIds:s}=Lt((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id),{all:!1}),u=un(s,"AnnotationPage"),[l,f]=v.useState((e==null?void 0:e.defaultChoices)||[]);e==null||e.strategies;const d=v.useMemo(()=>{const h=[];let w=null;const y=[];o.getState();for(const S of i){const _=o.get(S.body);for(const O of _){const[P,{selector:F}]=_e(O),b=(P.type||"unknown").toLowerCase();if(b==="choice"){const C=o.get(P.items),M=l.length?l.map(L=>C.find(Oe=>Oe.id===L)).filter(Boolean):[C[0]];M.length===0&&M.push(C[0]),w={type:"single-choice",items:C.map(L=>({id:L.id,label:L.label,selected:M.indexOf(L)!==-1})),label:O.label},_.push(...M);continue}h.indexOf(b)===-1&&h.push(b),y.push({type:b,resource:P,target:S.target,selector:F})}}return{types:h,items:y,choice:w}},[o,a,i,l]),p={makeChoice:v.useCallback((h,{deselectOthers:w=!0,deselect:y=!1}={})=>{if(d.choice){if(d.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");f(S=>{if(y){const O=S.filter(P=>P!==h);if(O.length===0){const P=d.items[0].resource.id;return P?[P]:[]}return O}if(w)return[h];const _=[...S];if(_.length===0&&d.items.length){const O=d.items[0].resource.id;O&&_.push(O)}return S.indexOf(h)!==-1?S:[...S,h]})}},[d.choice])},c=v.useMemo(()=>{if(!n)return wn;if(d.types.length!==1)return se("ComplexTimelineStrategy not yet supported");const h=d.types[0];if(h==="image"){const w=[];for(const y of d.items){const S=y.resource&&y.resource.type==="SpecificResource"?y.resource.source:y.resource;if(!S.id)return se("No resource Identifier");let _;if(S.service){const Sn=Y(S);Sn[0]&&(_=r(Sn[0],n))}y.target==="https://bvmm.irht.cnrs.fr/iiif/2309/canvas/canvas-981394#xywh=3949,994,1091,1232"&&(y.target="https://bvmm.irht.cnrs.fr/iiif/4490/canvas/canvas-981394#xywh=3949,994,1091,1232"),_&&_.width&&_.height&&_.profile==="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2"&&(_.profile="http://iiif.io/api/image/2/level2.json",_.sizes=[{width:_.width,height:_.height}],_.tiles=[{width:256,height:256,scaleFactors:[1,2,4,8,16,32]}]);const{selector:O,source:P}=V(y.target);if(P.id!==n.id)continue;const F={type:"BoxSelector",x:0,y:0,width:n.width,height:n.height},b=O?O.type==="TemporalSelector"?{type:"TemporalBoxSelector",startTime:O.startTime,endTime:O.endTime,x:F.x,y:F.y,width:F.width,height:F.height}:O:null,C={type:"BoxSelector",x:0,y:0,width:n.width,height:n.height},M=y.resource.type==="SpecificResource"?V(y.resource):null,L=M&&M.selector&&(M.selector.type==="BoxSelector"||M.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",x:M.selector.x,y:M.selector.y,width:M.selector.width,height:M.selector.height}:C,Oe={id:S.id,type:"Image",width:b?S.width:n.width,height:b?S.height:n.height,service:_,sizes:_&&_.sizes?_.sizes:S.width&&S.height?[{width:S.width,height:S.height}]:[],target:b||F,selector:L};w.push(Oe)}return[{type:"images",image:w[0],images:w,choice:d.choice},p]}return h==="audio"?se("Audio strategy not yet supported"):h==="video"?se("Video strategy not yet supported"):wn},[n,d,o,p.makeChoice]);return v.useMemo(()=>[io(no({},c[0]),{annotations:{pages:u}}),c[1]],[c,u])}g.AnnotationContext=En,g.CanvasContext=Pe,g.CollectionContext=xn,g.ContextBridge=ci,g.ImageServiceLoaderContext=It,g.ManifestContext=Fe,g.RangeContext=Pn,g.ReactVaultContext=te,g.ResourceProvider=$,g.ResourceReactContext=ee,g.SimpleViewerProvider=oi,g.SimpleViewerReactContext=X,g.VaultProvider=Ae,g.VisibleCanvasReactContext=K,g.expandTarget=V,g.flattenAnnotationPageIds=Pt,g.getPaintables=Kr,g.parseSelector=oe,g.parseSpecificResource=_e,g.useAnnotation=Bi,g.useAnnotationPageManager=Lt,g.useAnnotationsAtTime=nr,g.useCanvas=G,g.useCanvasClock=ir,g.useCollection=rr,g.useContextBridge=si,g.useDispatch=or,g.useEventListener=Mr,g.useExternalCollection=Rr,g.useExternalManifest=Ke,g.useImageService=cn,g.useImageServiceLoader=re,g.useImageTile=Dr,g.useLoadImageService=vn,g.useManifest=Z,g.usePaintingAnnotations=ae,g.useRange=qr,g.useRenderingStrategy=ro,g.useResourceContext=R,g.useResourceEvents=Wr,g.useResources=un,g.useSearchService=Nr,g.useSimpleViewer=ai,g.useStyles=zr,g.useThumbnail=Gr,g.useVault=A,g.useVaultEffect=ln,g.useVaultSelector=k,g.useVisibleCanvases=Xe,Object.defineProperty(g,"__esModule",{value:!0})});
14
+ ***************************************************************************** */function X(t,e,r,n){function o(i){return i instanceof r?i:new r(function(a){a(i)})}return new(r||(r=Promise))(function(i,a){function s(f){try{l(n.next(f))}catch(p){a(p)}}function u(f){try{l(n.throw(f))}catch(p){a(p)}}function l(f){f.done?i(f.value):o(f.value).then(s,u)}l((n=n.apply(t,e||[])).next())})}class $r{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(e){Object.assign(this.config,e)}sample(e,r,n=!0){const o=Z(_(e)),i=J(_(e)),a=this.knownImageServers[o];return this.imageServices[i]=Object.assign(e,{real:!0}),a?this.verify(e):(this.knownImageServers[o]={verifications:0,malformed:!1,root:o,preLoaded:n,sampledId:_(e),verified:!1,server:null,result:{context:e["@context"]||[],sampledProfile:e.profile,resourceServiceRatio:r&&e.height?r.height/e.height:1,sampledSizes:e.sizes||[],sizeRatios:Io(e.width,e.height,e.sizes||[]),sampledTiles:e.tiles||[]}},!0)}preLoad(e,r=!0){this.knownImageServers[e.root]=e,r&&(this.knownImageServers[e.root].malformed=!1,this.knownImageServers[e.root].verifications=this.config.verificationsRequired)}predict(e,r=!1,n=!1){const o=Z(_(e)),i=this.knownImageServers[o];if(!i||!i.result||!n&&(i.malformed||i.verifications<this.config.verificationsRequired))return null;const a=J(_(e));return this.imageServices[a]||(this.imageServices[a]={"@context":i.result.context,"@id":_(e),id:_(e),protocol:"http://iiif.io/api/image",tiles:Go(e.width,e.height,i.result.sampledTiles),sizes:$o(Math.floor(e.width/i.result.resourceServiceRatio),Math.floor(e.height/i.result.resourceServiceRatio),i.result.sizeRatios),profile:i.result.sampledProfile,height:e.height,width:e.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(e,r,n=!0,o=[]){return X(this,void 0,void 0,function*(){const i=yield this.getImageCandidates(e,n);return No(r,[()=>o,()=>i])})}getImageCandidates(e,r=!0){return X(this,void 0,void 0,function*(){const n=e;if(r&&n.height&&n.width){const o=Ir(n);for(const i of o){const a={id:_(i),width:i.width?i.width:n.width,height:i.height?i.height:n.height};yield this.loadService(a)}}return Ho(e,r,this)})}verify(e){return X(this,void 0,void 0,function*(){const r=this.predict(e,!1,!0),n=yield this.fetchService(_(e));if(!r)return!1;const o=r.height===n.height&&r.width===n.width&&r["@context"]===n["@context"]&&Ko(r.sizes||[],n.sizes||[]);if(o){const i=Z(_(e));this.knownImageServers[i].verifications+=1,this.knownImageServers[i].verifications>=this.config.verificationsRequired&&(this.knownImageServers[i].verified=!0)}return o})}canLoadSync(e){const r=typeof e=="string"?e:_(e),n=J(r);if(this.imageServices[n])return!0;const o=this.knownImageServers[Z(r)];return o&&!o.malformed&&o.verifications>=this.config.verificationsRequired}markAsMalformed(e){return X(this,void 0,void 0,function*(){return this.knownImageServers[Z(_(e))].malformed=!0,this.loadService(e,!0)})}fetchService(e,r=!1){return X(this,void 0,void 0,function*(){const n=J(e);if(this.imageServices[n]&&(!r||this.imageServices[n].real))return this.imageServices[n];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const o=yield fetch(n).then(i=>i.json());return!o.id&&o["@id"]&&(o.id=o["@id"]),o.id!==e&&(o.id=e,o["@id"]&&(o["@id"]=e)),this.imageServices[n]=Object.assign(o,{real:!0}),this.imageServices[n]})}loadService(e,r=!1){return X(this,void 0,void 0,function*(){if(!this.config.disableThrottling)for(;this.fetchingCount>=this.config.verificationsRequired;)yield new Promise(i=>setTimeout(i,500));const n=this.knownImageServers[Z(_(e))];if(n&&!n.malformed&&!r){yield n.result;const i=this.loadServiceSync(e);if(i)return i}this.fetchingCount++;const o=yield this.fetchService(_(e),r);return this.fetchingCount--,o.real&&this.sample(o,e),o})}loadServiceSync(e){const r=J(_(e));return this.imageServices[r]?this.imageServices[r]:this.predict(e)}}new $r;function Yo(t,e={}){const r=e.imageServiceLoader||new $r;async function n(o,i,a,s=[],u){if(typeof o=="string")return{best:je(o),fallback:[],log:[]};const l=t.get(o);if(typeof l=="string")return{best:je(l),fallback:[],log:[]};switch(l.type){case"Annotation":{const f=l.body,p=t.get(f[0]);return u&&!p.width&&(p.width=u.width,p.height=u.height),await r.getThumbnailFromResource(p,i,a,s)}case"Canvas":{const f=l;if(f.thumbnail&&f.thumbnail.length){const p=t.get(f.thumbnail[0]),d=await r.getImageCandidates(p,a);d&&d.length&&s.push(...d)}return n(f.items[0],i,a,s,{width:f.width,height:f.height})}case"AnnotationPage":return n(l.items[0],i,a,s,u);case"Choice":return n(l.items[0],i,a,s,u);case"Collection":{const f=l.items[0];return n(f,i,a,s,u)}case"Manifest":{const f=l.items[0];return n(f,i,a,s,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),r.getThumbnailFromResource(l,i,a,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:n}}function Jo(t,e,r,n,o=[]){const i=E(),a=m.useMemo(()=>nr(i),[i]);m.useEffect(()=>{const s=t;return s?(a.addEventListener(s,e,r,n),()=>{a.removeEventListener(s,e,r)}):()=>{}},[a,t,e,...o])}function Zo(){const t=m.useContext(re);return t&&t.vault?t.vault:fe.globalVault()}var Xo=Object.defineProperty,_r=Object.getOwnPropertySymbols,ea=Object.prototype.hasOwnProperty,ta=Object.prototype.propertyIsEnumerable,Er=(t,e,r)=>e in t?Xo(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ra=(t,e)=>{for(var r in e||(e={}))ea.call(e,r)&&Er(t,r,e[r]);if(_r)for(var r of _r(e))ta.call(e,r)&&Er(t,r,e[r]);return t},na=(t,e,r)=>new Promise((n,o)=>{var i=u=>{try{s(r.next(u))}catch(l){o(l)}},a=u=>{try{s(r.throw(u))}catch(l){o(l)}},s=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);s((r=r.apply(t,e)).next())});const ia=(t,e={})=>{const r=E(),[n,o]=m.useState(t),i=m.useMemo(()=>r.get(t),[t,r]),{data:a,isFetching:s}=Pe(`collection:${t}`,()=>na(void 0,null,function*(){const u=i||(yield r.loadCollection(t));return u&&o(u.id),u}),ra({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,initialData:i},e));return{isLoaded:!s,id:n,collection:a}};var oa=(t,e,r)=>new Promise((n,o)=>{var i=u=>{try{s(r.next(u))}catch(l){o(l)}},a=u=>{try{s(r.throw(u))}catch(l){o(l)}},s=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);s((r=r.apply(t,e)).next())});function jr(){const t=Y(),e=ge(),r=E(),n=ve();return Pe(`canvas-first-image-service:${t?t.id:"undefined"}`,()=>oa(this,null,function*(){if(t&&e.length){const o=e[0],i=r.get(o.body[0]),s=se(i)[0];return s&&(yield n.loadService({id:s.id||s["@id"],width:s.width||t.width,height:s.height||t.height}))||void 0}}),{refetchOnWindowFocus:!1,refetchOnMount:!1,refetchIntervalInBackground:!1,refetchInterval:!1,initialData:()=>{if(t&&e.length){const o=e[0],i=r.get(o.body[0]),s=se(i)[0];return s&&n.loadServiceSync({id:s.id||s["@id"],width:s.width||t.width,height:s.height||t.height})||void 0}}})}function aa(){const t=jr();return{isLoading:t.isFetching,tile:t.data?{id:t.data.id||t.data["@id"],width:t.data.width,height:t.data.height,imageService:t.data,thumbnail:void 0}:null}}function Tr(t,e=[]){const r=E(),n=ge(),[o,i]=m.useState((t==null?void 0:t.defaultChoices)||[]),a=m.useMemo(()=>Ht(r,n,o),[r,n,o,...e]),u={makeChoice:m.useCallback((l,{deselectOthers:f=!0,deselect:p=!1}={})=>{if(a.choice){if(a.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");i(d=>{if(p){const c=d.filter(g=>g!==l);if(c.length===0){const g=a.items[0].resource.id;return g?[g]:[]}return c}if(f)return[l];const v=[...d];if(v.length===0&&a.items.length){const c=a.items[0].resource.id;c&&v.push(c)}return d.indexOf(l)!==-1?d:[...d,l]})}},[a.choice])};return[a,u]}function sa(t={},e=[]){const{id:r,selector:n}=t,o=Q(),i=r||o.range,a=M(s=>i?s.iiif.entities.Range[i]:void 0,[i]);return m.useMemo(()=>{if(!!a)return n?n(a):a},[a,n,...e])}function ca(t,e){const r=E(),n=m.useMemo(()=>nr(r),[r]),o=M(()=>t&&t.id?r.getResourceMeta(t.id,"eventManager"):null,[t]);return m.useMemo(()=>t?n.getListenersAsProps(t,e):{},[o,t,r,e])}function Mr(t,e){return M((r,n)=>n.get(t.map(o=>({id:o,type:e}))),[t,e])}function ua(){const t=le();return t?t.service.find(e=>e.profile==="SearchService1"||e.profile==="http://iiif.io/api/search/1/search"):void 0}function la(){const t=E();return m.useMemo(()=>ir(t),[t])}function fa(t,e){const r=E(),n=m.useMemo(()=>ir(r),[r]);return M(()=>{if(!t)return null;const o=n.getAppliedStyles(t.id);return o?e?o[e]:o:void 0},[t,e])}const Fr=(t,e=[])=>{const r=E();m.useEffect(()=>{t(r)},[r,...e])};function ha(t,e,{canvasId:r,manifestId:n}={}){const o=E(),i=ve(),a=m.useMemo(()=>Yo(o,{imageServiceLoader:i}),[o,i]),[s,u]=m.useState(),l=le(n?{id:n}:void 0),f=Y(r?{id:r}:void 0),p=f||l,d=m.useRef(!1);if(m.useEffect(()=>()=>{d.current=!0},[]),!p)throw new Error("Must be called under a manifest or canvas context.");return Fr(v=>{a.getBestThumbnailAtSize(p,t,e).then(c=>{c.best&&!d.current&&u(c.best)})},[p]),s}var da=Object.defineProperty,pa=Object.defineProperties,va=Object.getOwnPropertyDescriptors,Lr=Object.getOwnPropertySymbols,ma=Object.prototype.hasOwnProperty,ga=Object.prototype.propertyIsEnumerable,kr=(t,e,r)=>e in t?da(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Rr=(t,e)=>{for(var r in e||(e={}))ma.call(e,r)&&kr(t,r,e[r]);if(Lr)for(var r of Lr(e))ga.call(e,r)&&kr(t,r,e[r]);return t},qr=(t,e)=>pa(t,va(e));function Wr(){const t=ve(),[e,r]=m.useState({}),n=m.useRef(!1);return m.useEffect(()=>()=>{n.current=!0},[]),[m.useCallback((i,{height:a,width:s})=>{if(i){const u=i.id||i["@id"],l=t.loadServiceSync({id:u,width:i.width||s,height:i.height||a});l?i=l:e[u]||(n.current||r(f=>qr(Rr({},f),{[u]:"loading"})),t.loadService({id:u,width:i.width||s,height:i.height||a}).then(()=>{n.current||r(f=>qr(Rr({},f),{[u]:"done"}))}))}return i},[t,e]),e]}var ya=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},j={exports:{}};(function(t,e){(function(r,n){n(e)})(ya,function(r){function n(h){return h==null}function o(h){throw new Error("Argument "+h+" is empty.")}function i(h){return typeof h=="function"&&"getType"in h}function a(h){throw new Error("Argument "+h+' is invalid, it should be an action-creator instance from "typesafe-actions"')}function s(h,w){if(h==null)throw new Error("Argument contains array with empty element at index "+w);if(h.getType==null)throw new Error("Argument contains array with invalid element at index "+w+', it should be an action-creator instance from "typesafe-actions"')}function u(h){return typeof h=="string"||typeof h=="symbol"}function l(h){return!u(h)}function f(h){throw new Error("Argument "+h+" is invalid, it should be an action type of type: string | symbol")}function p(h,w){if(h==null)throw new Error("Argument contains array with empty element at index "+w);if(typeof h!="string"&&typeof h!="symbol")throw new Error("Argument contains array with invalid element at index "+w+", it should be of type: string | symbol")}function d(h,w,b,A){return n(h)&&o(1),l(h)&&a(1),{type:h,payload:w,meta:b,error:A}}function v(h,w){return n(h)&&o(1),l(h)&&f(1),Object.assign(function(){var b=w!=null?w.apply(void 0,arguments):void 0;return Object.assign({type:h},b)},{getType:function(){return h},toString:function(){return h}})}function c(h,w,b){return n(h)&&o(1),l(h)&&f(1),function(){return v(h,function(){var A=arguments.length<=0?void 0:arguments[0],P=arguments.length<=1?void 0:arguments[1];return w==null&&b==null||(A=w!=null?w.apply(void 0,arguments):void 0,P=b!=null?b.apply(void 0,arguments):void 0),Object.assign({},A!==void 0&&{payload:A},{},P!==void 0&&{meta:P})})}}function g(h){return n(h)&&o(1),i(h)||a(1),h.getType()}function x(h,w){n(h)&&o(1),l(h)&&f(1);var b=w!=null?w(h):function(){return{type:h}};return Object.assign(b,{getType:function(){return h},toString:function(){return h}})}var S={createAction:function(h,w){var b=w==null?function(){return d(h)}:w(d.bind(null,h));return Object.assign(b,{getType:function(){return h},toString:function(){return h}})},createCustomAction:x,createStandardAction:function(h){return n(h)&&o(1),l(h)&&f(1),Object.assign(function(){return x(h,function(w){return function(b,A){return{type:w,payload:b,meta:A}}})},{map:function(w){return x(h,function(b){return function(A,P){return Object.assign(w(A,P),{type:b})}})}})}};r.action=d,r.createAction=c,r.createAsyncAction=function(h,w,b,A){return function(){var P=[h,w,b,A].map(function(C,I){return Array.isArray(C)?c(C[0],C[1],C[2])():typeof C=="string"||typeof C=="symbol"?c(C)():void(I<3&&function(F){throw new Error("Argument "+F+' is invalid, it should be an action type of "string | symbol" or a tuple of "[string | symbol, Function, Function?]"')}(I))});return{request:P[0],success:P[1],failure:P[2],cancel:P[3]}}},r.createCustomAction=v,r.createReducer=function h(w,b){b===void 0&&(b={});var A=Object.assign({},b),P=function(C,I){var F=Array.isArray(C)?C:[C],ee={};return F.map(function(te,qs){return i(te)?g(te):u(te)?te:function(Ws){throw new Error("Argument "+Ws+' is invalid, it should be an action-creator instance from "typesafe-actions" or action type of type: string | symbol')}(qs+1)}).forEach(function(te){return ee[te]=I}),h(w,Object.assign({},A,{},ee))};return Object.assign(function(C,I){if(C===void 0&&(C=w),A.hasOwnProperty(I.type)){var F=A[I.type];if(typeof F!="function")throw Error('Reducer under "'+I.type+'" key is not a valid reducer');return F(C,I)}return C},{handlers:Object.assign({},A),handleAction:P,handleType:P})},r.deprecated=S,r.getType=g,r.isActionOf=function(h,w){n(h)&&o(1);var b=Array.isArray(h)?h:[h];b.forEach(s);var A=function(P){return b.some(function(C){return P.type===C.getType()})};return w===void 0?A:A(w)},r.isOfType=function(h,w){n(h)&&o(1);var b=Array.isArray(h)?h:[h];b.forEach(p);var A=function(P){return b.includes(P.type)};return w===void 0?A:A(w)}})})(j,j.exports);const wa="@iiif/IMPORT_ENTITIES",ba="@iiif/MODIFY_ENTITY_FIELD",Sa="@iiif/REORDER_ENTITY_FIELD",xa="@iiif/ADD_REFERENCE",Oa="@iiif/REMOVE_REFERENCE",Ca=j.exports.createAction(wa)(),Aa=j.exports.createAction(ba)(),Pa=j.exports.createAction(Sa)(),Ia=j.exports.createAction(xa)(),$a=j.exports.createAction(Oa)(),Me={importEntities:Ca,modifyEntityField:Aa,reorderEntityField:Pa,addReference:Ia,removeReference:$a},_a="@iiif/ADD_MAPPING",Ea="@iiif/ADD_MAPPINGS";j.exports.createAction(_a)(),j.exports.createAction(Ea)();const ja="@iiif/SET_META_VALUE",Ta="@iiif/SET_META_VALUE_DYNAMIC",Ma="@iiif/UNSET_META_VALUE";j.exports.createAction(ja)(),j.exports.createAction(Ta)(),j.exports.createAction(Ma)();const Fa="@iiif/REQUEST_RESOURCE",La="@iiif/REQUEST_ERROR",ka="@iiif/REQUEST_MISMATCH",Ra="@iiif/REQUEST_COMPLETE",qa="@iiif/REQUEST_OFFLINE_RESOURCE";j.exports.createAction(Fa)(),j.exports.createAction(La)(),j.exports.createAction(ka)(),j.exports.createAction(Ra)(),j.exports.createAction(qa)();const Wa="@iiif/BATCH";j.exports.createAction(Wa)();const Da={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:[],motivation:null,label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[]},Dr=["sc:Collection","sc:Manifest","sc:Canvas","oa:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function Va(t){if(typeof t>"u"||t===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(t))throw new Error("Array is not a valid entity");if(typeof t!="object")throw new Error(`${typeof t} is not a valid entity`);if(typeof t["@type"]=="string"){const e=Dr.indexOf(t["@type"]);if(e!==-1)return Dr[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}class Fe{traversals;options;constructor(e,r={}){this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...r}}static all(e){return new Fe({collection:[e],manifest:[e],canvas:[e],annotationList:[e],sequence:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],layer:[e]})}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))),this.traversals.collection)}traverseCollectionItems(e){if(this.options.mergeMemberProperties){const r=[...(e.manifests||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n),...(e.collections||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n),...e.members||[]];delete e.collections,delete e.manifests,e.members=r}return e.manifests&&(e.manifests=e.manifests.map(r=>this.traverseManifest(typeof r=="string"?{"@id":r,"@type":"sc:Manifest"}:r))),e.collections&&(e.collections=e.collections.map(r=>this.traverseCollection(typeof r=="string"?{"@id":r,"@type":"sc:Collection"}:r))),e.members&&(e.members=e.members.map(r=>typeof r=="string"?r:this.traverseUnknown(r))),e}traverseManifest(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))),this.traversals.manifest)}traverseManifestItems(e){return e.sequences&&(e.sequences=e.sequences.map(r=>this.traverseSequence(r))),e.structures&&(e.structures=e.structures.map(r=>this.traverseRange(r))),e}traverseSequence(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))),this.traversals.sequence)}traverseSequenceItems(e){return e.canvases&&(e.canvases=e.canvases.map(r=>this.traverseCanvas(r))),e}traverseCanvas(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))),this.traversals.canvas)}traverseCanvasItems(e){return e.images&&(e.images=e.images.map(r=>this.traverseAnnotation(r))),e.otherContent&&(e.otherContent=e.otherContent.map(r=>this.traverseAnnotationList(r))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const r=[...(e.ranges||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Range"}:n),...(e.canvases||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Canvas"}:n),...e.members||[]];delete e.ranges,delete e.canvases,e.members=r.length?r.map(n=>this.traverseUnknown(n)):void 0}return e}traverseAnnotationList(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationListItems(e))),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map(r=>this.traverseAnnotation(r))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(e.resource=this.traverseContentResource(e.resource)),e.on,e}traverseLayer(e){return this.traverseType(this.traverseLinking(this.traverseLayerItems(e)),this.traversals.layer)}traverseLayerItems(e){return e.otherContent&&(e.otherContent=e.otherContent.map(r=>this.traverseAnnotationList(r))),e}traverseChoice(e){return this.traverseType(this.traverseChoiceItems(e),this.traversals.choice)}traverseChoiceItems(e){return e.default&&e.default!=="rdf:nil"&&(e.default=this.traverseContentResource(e.default)),e.item&&e.item!=="rdf:nil"&&(e.item=e.item.map(r=>this.traverseContentResource(r))),e}traverseService(e){return this.traverseType(this.traverseLinking(e),this.traversals.service)}traverseContentResource(e){return e["@type"]==="oa:Choice"?this.traverseChoice(e):this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.contentResource)}traverseUnknown(e){if(!e["@type"]||typeof e=="string")return e;switch(Va(e)){case"sc:Collection":return this.traverseCollection(e);case"sc:Manifest":return this.traverseManifest(e);case"sc:Canvas":return this.traverseCanvas(e);case"sc:Sequence":return this.traverseSequence(e);case"sc:Range":return this.traverseRange(e);case"oa:Annotation":return this.traverseAnnotation(e);case"oa:AnnotationList":return this.traverseAnnotationList(e);case"sc:Layer":return this.traverseLayer(e);case"Service":return this.traverseService(e);case"oa:Choice":return this.traverseChoice(e);case"ContentResource":return this.traverseContentResource(e)}return e.profile?this.traverseService(e):e}traverseImageResource(e){const r=Array.isArray(e),n=Array.isArray(e)?e:[e],o=[];for(const i of n)typeof i=="string"?o.push(this.traverseContentResource({"@id":i,"@type":"dctypes:Image"})):o.push(this.traverseContentResource(i));return!r&&!this.options.convertPropsToArray?o[0]:o}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){const r=Array.isArray(e),n=Array.isArray(e)?e:[e],o=[];for(const i of n)o.push(this.traverseService(i));return!r&&!this.options.convertPropsToArray?o[0]:o}traverseLinking(e){return e.related&&(e.related=this.traverseOneOrManyType(e.related,this.traversals.contentResource)),e.rendering&&(e.rendering=this.traverseOneOrManyType(e.rendering,this.traversals.contentResource)),e.service&&(e.service=this.traverseOneOrMoreServices(e.service)),e.seeAlso&&(e.seeAlso=this.traverseOneOrManyType(e.seeAlso,this.traversals.contentResource)),e.within&&(typeof e.within=="string"||(e.within=this.traverseOneOrManyType(e.within,this.traversals.contentResource))),e.startCanvas&&(typeof e.startCanvas=="string"?e.startCanvas=this.traverseType({"@id":e.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):e.startCanvas&&this.traverseType(e.startCanvas,this.traversals.canvas)),e.contentLayer&&(typeof e.contentLayer=="string"?e.contentLayer=this.traverseLayer({"@id":e.contentLayer,"@type":"sc:Layer"}):e.contentLayer=this.traverseLayer(e.contentLayer)),e}traverseOneOrManyType(e,r){if(!Array.isArray(e))if(this.options.convertPropsToArray)e=[e];else return this.traverseType(e,r);return e.map(n=>this.traverseType(n,r))}traverseType(e,r){return r.reduce((n,o)=>{const i=o(n);return typeof i>"u"&&!this.options.allowUndefinedReturn?n:i},e)}}const Qa="http://library.stanford.edu/iiif/image-api/compliance.html#level0",Vr="http://library.stanford.edu/iiif/image-api/compliance.html#level1",Qr="http://library.stanford.edu/iiif/image-api/compliance.html#level2",za="http://library.stanford.edu/iiif/image-api/conformance.html#level0",zr="http://library.stanford.edu/iiif/image-api/conformance.html#level1",Br="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Ba="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Hr="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Ur="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Ha="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Nr="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Gr="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Ua="http://iiif.io/api/image/1/level0.json",Na="http://iiif.io/api/image/1/profiles/level0.json",Kr="http://iiif.io/api/image/1/level1.json",Yr="http://iiif.io/api/image/1/profiles/level1.json",Jr="http://iiif.io/api/image/1/level2.json",Zr="http://iiif.io/api/image/1/profiles/level2.json",Ga="http://iiif.io/api/image/2/level0.json",Ka="http://iiif.io/api/image/2/profiles/level0.json",Xr="http://iiif.io/api/image/2/level1.json",en="http://iiif.io/api/image/2/profiles/level1.json",tn="http://iiif.io/api/image/2/level2.json",rn="http://iiif.io/api/image/2/profiles/level2.json",Ya="level0",nn="level1",on="level2",Ja="http://iiif.io/api/image/2/level0",an="http://iiif.io/api/image/2/level1",sn="http://iiif.io/api/image/2/level2",Za=[an,sn,Vr,Qr,zr,Br,Hr,Ur,Nr,Gr,Kr,Yr,Jr,Zr,Xr,en,tn,rn,nn,on],Xa=[Ja,an,sn,Qa,Vr,Qr,za,zr,Br,Ba,Hr,Ur,Ha,Nr,Gr,Ua,Na,Kr,Yr,Jr,Zr,Ga,Ka,Xr,en,tn,rn,Ya,nn,on],Le={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function U(t,e="none"){if(!t)return{};const r=Array.isArray(t)?t:[t],n={};for(const o of r){if(typeof o=="string"){n[e]=n[e]?n[e]:[],n[e].push(o||"");continue}if(!o["@language"]){n[e]=n[e]?n[e]:[],n[e].push(o["@value"]||"");continue}const i=o["@language"];n[i]=n[i]?n[i]:[],n[i].push(o["@value"]||"")}return n}function cn(t){if(Array.isArray(t))return cn(t.find(e=>typeof e=="string"));if(Xa.indexOf(t)!==-1)return"level2";if(Za.indexOf(t)!==-1)return"level1";if(typeof t=="string")return t}function es(t){const e=Array.isArray(t)?t:[t];for(const r of e)switch(r){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function ts(t){switch(t){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}function rs(t){return Array.isArray(t)?t:[t]}function ns(t){for(const e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}function ke(t){const e=t["@id"]||t.id;let r=t["@type"]||t.type;const n=t.profile||void 0,o=t["@context"]||void 0;if(n){const i=ts(n);if(i)return i}if(o){const i=es(o);if(i)return i}if(r){if(Array.isArray(r)){if(r.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(r.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";r=r[0]}for(const i of["sc","oa","dcterms","dctypes","iiif"])if(r.startsWith(`${i}:`)){r=r.slice(i.length+1);break}switch(r){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(t.format){if(t.format.startsWith("image/"))return"Image";if(t.format.startsWith("text/")||t.format==="application/pdf")return"Text";if(t.format.startsWith("application/"))return"Dataset"}return e&&(e.endsWith(".jpg")||e.endsWith(".png")||e.endsWith(".jpeg"))?"Image":r||"unknown"}const is=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function os(t){const e=t.match(is);return e?e[0]:t}function as(t,e="Rights/License",r="none"){let n=null;const o=[],i=Array.isArray(t)?t:[t];for(const a of i){const s=a?os(a):void 0;if(s&&(s.indexOf("creativecommons.org")!==-1||s.indexOf("rightsstatements.org")!==-1)){s.startsWith("https://")?n=`http://${s.slice(8)}`:n=s;continue}s&&o.push({label:{[r]:[e]},value:{[r]:[s]}})}return[n,o]}const ss=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function cs(t){if(t){const e=Array.isArray(t)?t:[t],r=[];for(const n of e)n==="http://iiif.io/api/presentation/2/context.json"&&r.push("http://iiif.io/api/presentation/3/context.json"),ss.indexOf(n)===-1&&r.push(n);if(e.length)return r.length===1?r[0]:r}}function us(t){return t?t.map(e=>({label:U(e.label),value:U(e.value)})):[]}function q(t){for(const e in t)(typeof t[e]>"u"||t[e]===null)&&delete t[e];return t}let un=0;function ln(t,e){const r=encodeURI(t.id||t["@id"]||"").trim();return r&&e?`${r}/${e}`:r||(un++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${un}`)}function W(t){const e=[...t.behavior||[]];return t.viewingHint&&e.push(t.viewingHint),{"@context":t["@context"]?cs(t["@context"]):void 0,id:(t["@id"]||ln(t)).trim(),type:ke(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:t.motivation?ns(t.motivation):void 0,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function L(t){const[e,r]=as(t.license),n=[...t.metadata?us(t.metadata):[],...r];return{rights:e,metadata:n.length?n:void 0,label:t.label?U(t.label):void 0,requiredStatement:t.attribution?{label:U(Le.attributionLabel),value:U(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?U(t.description):void 0,thumbnail:t.thumbnail}}function ls(t){if(!t.within)return;const e=Array.isArray(t.within)?t.within:[t.within],r=[];for(const n of e)if(typeof n=="string"){if(n)switch(t["@type"]){case"sc:Manifest":r.push({id:n,type:"Collection"});break}}else n["@id"]&&r.push({id:n["@id"],type:ke(n)});return r.length?r:void 0}function V(t){const e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],r=t.contentLayer;return{provider:t.logo||e.length?[{id:Le.providerId,type:"Agent",homepage:e.length?[e[0]]:void 0,logo:t.logo?Array.isArray(t.logo)?t.logo:[t.logo]:void 0,label:U(Le.providerName)}]:void 0,partOf:ls(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?rs(t.service):void 0,supplementary:r?[r]:void 0}}function fs(t){return q({...W(t),...L(t),...V(t),items:t.members})}function hs(t){const e=[],r=[];for(const o of t.sequences||[])o.canvases.length&&e.push(...o.canvases),o.behavior&&r.push(...o.behavior);const n=W(t);return r.length&&(n.behavior?n.behavior.push(...r):n.behavior=r),q({...n,...L(t),...V(t),items:e,structures:t.structures})}function ds(t){return q({...W(t),...L(t),...V(t),items:t.images&&t.images.length?[{id:ln(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function ps(t){return q({...W(t),...L(t),...V(t),items:t.resources})}function vs(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[]}}function ms(t){return q({...W(t),...L(t),...V(t),target:typeof t.on=="string"?encodeURI(t.on).trim():t.on,body:t.resource})}function gs(t){const e=t;return q({...W(e),...L(e),...V(e)})}function ys(t){const e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),{...W(t),...L(t),items:e}}function ws(t){return q({...W(t),...L(t),...V(t),items:t.members})}function bs(t){const{"@id":e,"@type":r,"@context":n,profile:o,...i}=t;return e&&(i.id=e),i.type=ke(t),i.type==="unknown"&&(i.type="Service"),o&&(i.profile=cn(o)),q({...i,...L(i)})}function Ss(t){return q({...W(t),...L(t),...V(t)})}new Fe({collection:[fs],manifest:[hs],canvas:[ds],annotationList:[ps],sequence:[vs],annotation:[ms],contentResource:[gs],choice:[ys],range:[ws],service:[bs],layer:[Ss]});var xs=Object.defineProperty,Os=Object.defineProperties,Cs=Object.getOwnPropertyDescriptors,fn=Object.getOwnPropertySymbols,As=Object.prototype.hasOwnProperty,Ps=Object.prototype.propertyIsEnumerable,hn=(t,e,r)=>e in t?xs(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Is=(t,e)=>{for(var r in e||(e={}))As.call(e,r)&&hn(t,r,e[r]);if(fn)for(var r of fn(e))Ps.call(e,r)&&hn(t,r,e[r]);return t},$s=(t,e)=>Os(t,Cs(e));function dn(t){return typeof t!="string"&&t&&t.bindToVault}function _s(){const t=E(),e=m.useRef([]),r=rr(),n=m.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);m.useLayoutEffect(()=>{const s=$s(Is({},Da),{id:n,items:[]});r(Me.importEntities({entities:{AnnotationPage:{[s.id]:s}}}))},[n]);const o=M(s=>n?s.iiif.entities.AnnotationPage[n]:null,[n]),i=m.useCallback((s,u)=>{if(n){if(dn(s)){const p=s;p.__vault||p.bindToVault(t),s=typeof p.source=="string"?p.source:p.source.id,e.current[s]=p}else typeof s!="string"&&(s=s.id);const l=t.get({id:n,type:"AnnotationPage"}),f=t.get({id:s,type:"Annotation"});l&&f&&(l.items.find(p=>p.id===f.id)||r(Me.addReference({id:n,type:"AnnotationPage",key:"items",reference:{id:s,type:"Annotation"},index:u})))}},[n]),a=m.useCallback(s=>{n&&(dn(s)?s=typeof s.source=="string"?s.source:s.source.id:typeof s!="string"&&(s=s.id),e.current[s]&&e.current[s].beforeRemove(),t.get({id:n,type:"AnnotationPage"})&&r(Me.removeReference({id:n,type:"AnnotationPage",key:"items",reference:{id:s,type:"Annotation"}})))},[n]);return[o,{addAnnotation:i,removeAnnotation:a}]}var Es=Object.defineProperty,js=Object.defineProperties,Ts=Object.getOwnPropertyDescriptors,pn=Object.getOwnPropertySymbols,Ms=Object.prototype.hasOwnProperty,Fs=Object.prototype.propertyIsEnumerable,vn=(t,e,r)=>e in t?Es(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ls=(t,e)=>{for(var r in e||(e={}))Ms.call(e,r)&&vn(t,r,e[r]);if(pn)for(var r of pn(e))Fs.call(e,r)&&vn(t,r,e[r]);return t},ks=(t,e)=>js(t,Ts(e));function Rs(t){const e=le(),r=Y(),n=E(),[o,i]=Wr(),{enabledPageIds:a}=tr((t==null?void 0:t.annotationPageManagerId)||(e==null?void 0:e.id),{all:!1}),s=Mr(a,"AnnotationPage"),u=(t==null?void 0:t.strategies)||["images","media","complex-timeline"],[l,f]=Tr(t,[i]),p=m.useMemo(()=>{if(!r||l.types.length===0)return _e;if(l.types.length!==1)return u.indexOf("complex-timeline")===-1?R("Complex timeline not supported"):R("ComplexTimelineStrategy not yet supported");const d=l.types[0];return d==="image"?u.indexOf("images")===-1?R("Image not supported"):Nt(r,l,o):d==="audio"?u.indexOf("media")===-1?R("Media not supported"):R("Audio strategy not yet supported"):d==="video"?u.indexOf("media")===-1?R("Media not supported"):R("Video strategy not yet supported"):_e},[r,l,n,f.makeChoice]);return m.useMemo(()=>p.type==="unknown"?[p,Ut]:[ks(Ls({},p),{annotations:{pages:s}}),f],[p,s])}y.AnnotationContext=Sn,y.CanvasContext=De,y.CollectionContext=xn,y.ContextBridge=ni,y.ImageServiceLoaderContext=Wt,y.ManifestContext=Ve,y.RangeContext=On,y.ReactVaultContext=re,y.ResourceProvider=z,y.ResourceReactContext=he,y.SimpleViewerProvider=ei,y.SimpleViewerReactContext=ae,y.VaultProvider=Qe,y.VisibleCanvasReactContext=oe,y.emptyActions=Ut,y.expandTarget=D,y.flattenAnnotationPageIds=Yt,y.getImageStrategy=Nt,y.getPaintables=Ht,y.parseSelector=me,y.parseSpecificResource=Bt,y.unknownResponse=_e,y.unsupportedStrategy=R,y.useAnnotation=vo,y.useAnnotationPageManager=tr,y.useAnnotationsAtTime=Co,y.useCanvas=Y,y.useCanvasClock=Ao,y.useCollection=Po,y.useContextBridge=ri,y.useDispatch=rr,y.useEventListener=Jo,y.useExistingVault=Zo,y.useExternalCollection=ia,y.useExternalManifest=ct,y.useImageService=jr,y.useImageServiceLoader=ve,y.useImageTile=aa,y.useLoadImageService=Wr,y.useManifest=le,y.usePaintables=Tr,y.usePaintingAnnotations=ge,y.useRange=sa,y.useRenderingStrategy=Rs,y.useResourceContext=Q,y.useResourceEvents=ca,y.useResources=Mr,y.useSearchService=ua,y.useSimpleViewer=ti,y.useStyleHelper=la,y.useStyles=fa,y.useThumbnail=ha,y.useVault=E,y.useVaultEffect=Fr,y.useVaultSelector=M,y.useVirtualAnnotationPage=_s,y.useVisibleCanvases=ut,Object.defineProperty(y,"__esModule",{value:!0})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-iiif-vault",
3
- "version": "0.9.0",
3
+ "version": "0.9.4",
4
4
  "main": "./dist/cjs/index.js",
5
5
  "module": "./dist/esm/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -24,27 +24,28 @@
24
24
  },
25
25
  "license": "MIT",
26
26
  "resolutions": {
27
- "@iiif/vault": "^0.9.9",
27
+ "@atlas-viewer/iiif-image-api": "^2.0.2",
28
+ "@iiif/vault": "^0.9.14",
28
29
  "@iiif/presentation-3": "^1.0.4"
29
30
  },
30
31
  "dependencies": {
31
- "@atlas-viewer/iiif-image-api": "^1.2.6",
32
+ "@atlas-viewer/iiif-image-api": "^2.0.2",
32
33
  "@iiif/presentation-2": "^1.0.1",
33
34
  "@iiif/presentation-3": "^1.0.4",
34
- "@iiif/vault": "^0.9.9",
35
+ "@iiif/vault": "^0.9.14",
35
36
  "@iiif/vault-helpers": "^0.9.4",
36
37
  "react": "^16.10.2 || ^17.0.1",
37
38
  "react-dom": "^16.10.2 || ^17.0.1",
38
39
  "react-query": "^1.5.10",
39
40
  "redux": "^4.1.2",
40
- "rollup": "^2.67.1",
41
+ "rollup": "^2.68.0",
41
42
  "typescript": "^4.5.5"
42
43
  },
43
44
  "devDependencies": {
44
- "@rollup/plugin-replace": "^3.0.1",
45
+ "@rollup/plugin-replace": "^4.0.0",
45
46
  "@testing-library/react": "^12.1.2",
46
47
  "@testing-library/react-hooks": "^7.0.2",
47
- "@types/jest": "^27.4.0",
48
+ "@types/jest": "^27.4.1",
48
49
  "@types/react": "^17.0.39",
49
50
  "@types/react-dom": "^17.0.11",
50
51
  "@typescript-eslint/eslint-plugin": "^5.11.0",
@@ -52,13 +53,14 @@
52
53
  "eslint": "^8.8.0",
53
54
  "eslint-plugin-json": "^3.1.0",
54
55
  "eslint-plugin-prettier": "^4.0.0",
55
- "jest": "^27.5.0",
56
+ "jest": "^27.5.1",
57
+ "jest-environment-jsdom": "^27.5.1",
56
58
  "prettier": "^2.5.1",
57
59
  "react": "^16.10.2 || ^17.0.1",
58
60
  "react-dom": "^16.10.2 || ^17.0.1",
59
61
  "react-use": "^17.3.2",
60
62
  "redux": "^4.1.2",
61
- "rollup-library-template": "^1.0.3",
63
+ "rollup-library-template": "^1.0.4",
62
64
  "ts-jest": "^27.1.3",
63
65
  "tslib": "^2.3.1"
64
66
  },