react-iiif-vault 0.9.0 → 0.9.2

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"),V=require("@atlas-viewer/iiif-image-api"),L=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),Qe=({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),b=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(b.Provider,{value:{vault:i,setVaultInstance:a}},g.default.createElement(E,{value:r||{}},c))},y=()=>{const{vault:e}=u.useContext(b);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var He=Object.defineProperty,K=Object.getOwnPropertySymbols,ze=Object.prototype.hasOwnProperty,Ye=Object.prototype.propertyIsEnumerable,Z=(e,t,n)=>t in e?He(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)},!0),t),r}const A=g.default.createContext([]);function te(){const e=u.useContext(A);return P(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}const D=()=>{},R=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],H=a&&m!==0?o[m+1]:null;w&&(r(w),i(I=>{const U=H?[w,H]:[w];if(I.length===I.length){for(let $=0;$<I.length;$++)if(I[$]!==U[$])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(R.Provider,{value:_},g.default.createElement(A.Provider,{value:c},g.default.createElement(X,{manifest:t.manifest.id},g.default.createElement(G,{canvas:n},e.children))))};function Je(){return u.useContext(R)}function Ke(){return{VaultContext:u.useContext(b),ResourceContext:u.useContext(j),SimpleViewerReactContext:u.useContext(R),VisibleCanvasReactContext:u.useContext(A)}}const Ze=e=>g.default.createElement(J,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},g.default.createElement(A.Provider,{value:e.bridge.VisibleCanvasReactContext},g.default.createElement(R.Provider,{value:e.bridge.SimpleViewerReactContext},e.children))),ne=g.default.createContext(new V.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",startTime:e.t};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=et.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(tt);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 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:()=>{}},Q={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=V.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",x:0,y:0,width:e.width,height:e.height},p=o?o.type==="TemporalSelector"?{type:"TemporalBoxSelector",startTime:o.startTime,endTime:o.endTime,x:l.x,y:l.y,width:l.width,height:l.height}:o:null,d={type:"BoxSelector",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",x:v.selector.x,y:v.selector.y,width:v.selector.width,height:v.selector.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||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 M(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=M(),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(()=>L.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(b);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 Tt=(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 Vt=(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"}`,()=>Vt(this,null,function*(){if(e&&t.length){const c=t[0],i=n.get(c.body[0]),o=V.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=V.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(()=>L.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=M();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function Nt(e,t){const n=y(),r=u.useMemo(()=>L.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 Bt(e,t,{canvasId:n,manifestId:r}={}){const c=y(),i=F(),a=u.useMemo(()=>L.createThumbnailHelper(c,{imageServiceLoader:i}),[c,i]),[o,s]=u.useState(),l=M(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 Ut=Object.defineProperty,kt=Object.defineProperties,Qt=Object.getOwnPropertyDescriptors,xe=Object.getOwnPropertySymbols,qt=Object.prototype.hasOwnProperty,Ht=Object.prototype.propertyIsEnumerable,Ie=(e,t,n)=>t in e?Ut(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))Ht.call(t,n)&&Ie(e,n,t[n]);return e},Ae=(e,t)=>kt(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 zt="@iiif/IMPORT_ENTITIES",Yt="@iiif/MODIFY_ENTITY_FIELD",Wt="@iiif/REORDER_ENTITY_FIELD",Gt="@iiif/ADD_REFERENCE",Xt="@iiif/REMOVE_REFERENCE",Jt=h.createAction(zt)(),Kt=h.createAction(Yt)(),Zt=h.createAction(Wt)(),en=h.createAction(Gt)(),tn=h.createAction(Xt)(),q={importEntities:Jt,modifyEntityField:Kt,reorderEntityField:Zt,addReference:en,removeReference:tn},nn="@iiif/ADD_MAPPING",rn="@iiif/ADD_MAPPINGS";h.createAction(nn)(),h.createAction(rn)();const on="@iiif/SET_META_VALUE",an="@iiif/SET_META_VALUE_DYNAMIC",sn="@iiif/UNSET_META_VALUE";h.createAction(on)(),h.createAction(an)(),h.createAction(sn)();const cn="@iiif/REQUEST_RESOURCE",un="@iiif/REQUEST_ERROR",ln="@iiif/REQUEST_MISMATCH",fn="@iiif/REQUEST_COMPLETE",dn="@iiif/REQUEST_OFFLINE_RESOURCE";h.createAction(cn)(),h.createAction(un)(),h.createAction(ln)(),h.createAction(fn)(),h.createAction(dn)();const pn="@iiif/BATCH";h.createAction(pn)();var vn=Object.defineProperty,mn=Object.defineProperties,gn=Object.getOwnPropertyDescriptors,Me=Object.getOwnPropertySymbols,yn=Object.prototype.hasOwnProperty,hn=Object.prototype.propertyIsEnumerable,$e=(e,t,n)=>t in e?vn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_n=(e,t)=>{for(var n in t||(t={}))yn.call(t,n)&&$e(e,n,t[n]);if(Me)for(var n of Me(t))hn.call(t,n)&&$e(e,n,t[n]);return e},Pn=(e,t)=>mn(e,gn(t));function Te(e){return typeof e!="string"&&e&&e.bindToVault}function Sn(){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=Pn(_n({},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(Te(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&&(Te(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 wn=Object.defineProperty,On=Object.defineProperties,Cn=Object.getOwnPropertyDescriptors,Ve=Object.getOwnPropertySymbols,En=Object.prototype.hasOwnProperty,xn=Object.prototype.propertyIsEnumerable,Le=(e,t,n)=>t in e?wn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,In=(e,t)=>{for(var n in t||(t={}))En.call(t,n)&&Le(e,n,t[n]);if(Ve)for(var n of Ve(t))xn.call(t,n)&&Le(e,n,t[n]);return e},bn=(e,t)=>On(e,Cn(t));function An(e){const t=M(),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 Q;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"):Q},[n,l,r,p.makeChoice]);return u.useMemo(()=>d.type==="unknown"?[d,ue]:[bn(In({},d),{annotations:{pages:o}}),p],[d,o])}exports.AnnotationContext=ke,exports.CanvasContext=G,exports.CollectionContext=Qe,exports.ContextBridge=Ze,exports.ImageServiceLoaderContext=ne,exports.ManifestContext=X,exports.RangeContext=qe,exports.ReactVaultContext=b,exports.ResourceProvider=E,exports.ResourceReactContext=j,exports.SimpleViewerProvider=Xe,exports.SimpleViewerReactContext=R,exports.VaultProvider=J,exports.VisibleCanvasReactContext=A,exports.emptyActions=ue,exports.expandTarget=O,exports.flattenAnnotationPageIds=pe,exports.getImageStrategy=le,exports.getPaintables=ce,exports.parseSelector=N,exports.parseSpecificResource=se,exports.unknownResponse=Q,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=Tt,exports.useExternalManifest=ee,exports.useImageService=we,exports.useImageServiceLoader=F,exports.useImageTile=Lt,exports.useLoadImageService=Re,exports.useManifest=M,exports.usePaintables=Oe,exports.usePaintingAnnotations=B,exports.useRange=jt,exports.useRenderingStrategy=An,exports.useResourceContext=C,exports.useResourceEvents=Dt,exports.useResources=Ce,exports.useSearchService=Ft,exports.useSimpleViewer=Je,exports.useStyles=Nt,exports.useThumbnail=Bt,exports.useVault=y,exports.useVaultEffect=Ee,exports.useVaultSelector=P,exports.useVirtualAnnotationPage=Sn,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 H,useLayoutEffect as He}from"react";import{globalVault as X,Vault as q}from"@iiif/vault";import{useQuery as k}from"react-query";import{ImageServiceLoader as ke,getImageServices as z}from"@atlas-viewer/iiif-image-api";import{createEventsHelper as J,createStylesHelper as ze,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,K=Object.getOwnPropertySymbols,Xe=Object.prototype.hasOwnProperty,qe=Object.prototype.propertyIsEnumerable,Z=(e,t,n)=>t in e?Ge(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ee=(e,t)=>{for(var n in t||(t={}))Xe.call(t,n)&&Z(e,n,t[n]);if(K)for(var n of K(t))qe.call(t,n)&&Z(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),x=()=>O(D),b=({value:e,children:t})=>{const n=x(),r=m(()=>ee(ee({},n),e),[e,n]);return g.createElement(D.Provider,{value:r},t)},Ke=({annotation:e,children:t})=>g.createElement(b,{value:{annotation:e}},t),te=({canvas:e,children:t})=>g.createElement(b,{value:{canvas:e}},t),Ze=({collection:e,children:t})=>g.createElement(b,{value:{collection:e}},t),ne=({manifest:e,children:t})=>g.createElement(b,{value:{manifest:e}},t),et=({range:e,children:t})=>g.createElement(b,{value:{range:e}},t),T=g.createContext({vault:null,setVaultInstance:e=>{}}),re=({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(b,{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,oe=Object.getOwnPropertySymbols,nt=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,ie=(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)&&ie(e,n,t[n]);if(oe)for(var n of oe(t))rt.call(t,n)&&ie(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 ae=(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)},!0),t),r}const M=g.createContext([]);function se(){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=ae(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]),d=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 Q=G?[C,G]:[C];if(A.length===A.length){for(let j=0;j<A.length;j++)if(A[j]!==Q[j])return Q;return A}return Q}))},[a,o]),p=w(u=>{const v=o.indexOf(u);v!==-1&&f(v)},[o,f]),_=m(()=>({setCurrentCanvasId:p,nextCanvas:l,previousCanvas:d,currentCanvasIndex:s,totalCanvases:o.length,setCurrentCanvasIndex:f,pagingView:!0}),[l,d,s,o,f,p]);return!t.isLoaded||!t.manifest?g.createElement("div",null,"Loading..."):g.createElement(V.Provider,{value:_},g.createElement(M.Provider,{value:c},g.createElement(ne,{manifest:t.manifest.id},g.createElement(te,{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(re,{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))),ce=g.createContext(new ke);function N(){return O(ce)}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",startTime:e.t};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=ut.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(ft);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 dt=Object.defineProperty,pt=Object.defineProperties,vt=Object.getOwnPropertyDescriptors,le=Object.getOwnPropertySymbols,mt=Object.prototype.hasOwnProperty,gt=Object.prototype.propertyIsEnumerable,ue=(e,t,n)=>t in e?dt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,fe=(e,t)=>{for(var n in t||(t={}))mt.call(t,n)&&ue(e,n,t[n]);if(le)for(var n of le(t))gt.call(t,n)&&ue(e,n,t[n]);return e},de=(e,t)=>pt(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(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:[]}}function pe(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function ve(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:d}]=pe(s),f=(l.type||"unknown").toLowerCase();if(f==="choice"){const p=e.get(l.items),_=n.length?n.map(u=>p.find(v=>v.id===u)).filter(Boolean):[p[0]];_.length===0&&_.push(p[0]),c={type:"single-choice",items:p.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:d})}}return{types:r,items:i,choice:c}}const me={makeChoice:()=>{}},Y={type:"unknown"},E=e=>({type:"unknown",reason:e,annotations:{pages:[]}});function ge(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",x:0,y:0,width:e.width,height:e.height},d=o?o.type==="TemporalSelector"?{type:"TemporalBoxSelector",startTime:o.startTime,endTime:o.endTime,x:l.x,y:l.y,width:l.width,height:l.height}:o:null,f={type:"BoxSelector",x:0,y:0,width:e.width,height:e.height},p=c.resource.type==="SpecificResource"?I(c.resource):null,_=p&&p.selector&&(p.selector.type==="BoxSelector"||p.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",x:p.selector.x,y:p.selector.y,width:p.selector.width,height:p.selector.height}:f,u={id:i.id,type:"Image",width:d?i.width:e.width,height:d?i.height:e.height,service:a,sizes:a&&a.sizes?a.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:d||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,he=Object.getOwnPropertySymbols,Pt=Object.prototype.hasOwnProperty,Ot=Object.prototype.propertyIsEnumerable,ye=(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)&&ye(e,n,t[n]);if(he)for(var n of he(t))Ot.call(t,n)&&ye(e,n,t[n]);return e},St=(e,t)=>yt(e,_t(t));function Et(e={},t=[]){const{id:n,selector:r}=e,c=x(),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(d=>d?l.iiif.entities[d.type][d.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=x();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=x(),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 _e({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 xt=Object.defineProperty,bt=Object.defineProperties,$t=Object.getOwnPropertyDescriptors,Pe=Object.getOwnPropertySymbols,Rt=Object.prototype.hasOwnProperty,At=Object.prototype.propertyIsEnumerable,Oe=(e,t,n)=>t in e?xt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,we=(e,t)=>{for(var n in t||(t={}))Rt.call(t,n)&&Oe(e,n,t[n]);if(Pe)for(var n of Pe(t))At.call(t,n)&&Oe(e,n,t[n]);return e},Se=(e,t)=>bt(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 Ee(e,t={}){const n=h(),r=L(),c=R(),i=se(),a=m(()=>_e({all:t.all,manifest:r,canvas:c,canvases:i}),[t.all,c,i,r]),o=It(e,t.all?void 0:a),s=w(d=>{!e||n.setMetaValue([d,"annotationPageManager","views"],f=>f&&!f[e]?f:Se(we({},f||{}),{[e]:!1}))},[e,n]),l=w((d,f={})=>{if(!e)return;const p=n.getState(),_=[];if(f==null?void 0:f.deselectOthers){const u=Object.keys(p.iiif.entities.AnnotationPage);for(const v of u){const C=Tt(p,v);C&&C.views&&C.views[e]&&_.push(v)}}for(const u of _)s(u);n.setMetaValue([d,"annotationPageManager","views"],u=>u&&u[e]?u:Se(we({},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=x(),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 Ce(){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,Ie=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(Ie)for(var n of Ie(t))Bt.call(t,n)&&xe(e,n,t[n]);return e},Qt=(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 Ht=(e,t={})=>{const n=h(),[r,c]=S(e),i=m(()=>n.get(e),[e,n]),{data:a,isFetching:o}=k(`collection:${e}`,()=>Qt(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 be(){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=be();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 $e(e,t=[]){const n=h(),r=U(),[c,i]=S((e==null?void 0:e.defaultChoices)||[]),a=m(()=>ve(n,r,c),[n,r,c,...t]),s={makeChoice:w((l,{deselectOthers:d=!0,deselect:f=!1}={})=>{if(a.choice){if(a.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");i(p=>{if(f){const u=p.filter(v=>v!==l);if(u.length===0){const v=a.items[0].resource.id;return v?[v]:[]}return u}if(d)return[l];const _=[...p];if(_.length===0&&a.items.length){const u=a.items[0].resource.id;u&&_.push(u)}return p.indexOf(l)!==-1?p:[...p,l]})}},[a.choice])};return[a,s]}function Yt(e={},t=[]){const{id:n,selector:r}=e,c=x(),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 Re(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(e,t){const n=h(),r=m(()=>ze(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 Ae=(e,t=[])=>{const n=h();$(()=>{e(n)},[n,...t])};function qt(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),d=R(n?{id:n}:void 0),f=d||l,p=H(!1);if($(()=>()=>{p.current=!0},[]),!f)throw new Error("Must be called under a manifest or canvas context.");return Ae(_=>{a.getBestThumbnailAtSize(f,e,t).then(u=>{u.best&&!p.current&&s(u.best)})},[f]),o}var Jt=Object.defineProperty,Kt=Object.defineProperties,Zt=Object.getOwnPropertyDescriptors,Te=Object.getOwnPropertySymbols,en=Object.prototype.hasOwnProperty,tn=Object.prototype.propertyIsEnumerable,Me=(e,t,n)=>t in e?Jt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ve=(e,t)=>{for(var n in t||(t={}))en.call(t,n)&&Me(e,n,t[n]);if(Te)for(var n of Te(t))tn.call(t,n)&&Me(e,n,t[n]);return e},Le=(e,t)=>Kt(e,Zt(t));function je(){const e=N(),[t,n]=S({}),r=H(!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(d=>Le(Ve({},d),{[s]:"loading"})),e.loadService({id:s,width:i.width||o,height:i.height||a}).then(()=>{r.current||n(d=>Le(Ve({},d),{[s]:"done"}))}))}return i},[e,t]),t]}const nn="@iiif/IMPORT_ENTITIES",rn="@iiif/MODIFY_ENTITY_FIELD",on="@iiif/REORDER_ENTITY_FIELD",an="@iiif/ADD_REFERENCE",sn="@iiif/REMOVE_REFERENCE",cn=y(nn)(),ln=y(rn)(),un=y(on)(),fn=y(an)(),dn=y(sn)(),W={importEntities:cn,modifyEntityField:ln,reorderEntityField:un,addReference:fn,removeReference:dn},pn="@iiif/ADD_MAPPING",vn="@iiif/ADD_MAPPINGS";y(pn)(),y(vn)();const mn="@iiif/SET_META_VALUE",gn="@iiif/SET_META_VALUE_DYNAMIC",hn="@iiif/UNSET_META_VALUE";y(mn)(),y(gn)(),y(hn)();const yn="@iiif/REQUEST_RESOURCE",_n="@iiif/REQUEST_ERROR",Pn="@iiif/REQUEST_MISMATCH",On="@iiif/REQUEST_COMPLETE",wn="@iiif/REQUEST_OFFLINE_RESOURCE";y(yn)(),y(_n)(),y(Pn)(),y(On)(),y(wn)();const Sn="@iiif/BATCH";y(Sn)();var En=Object.defineProperty,Cn=Object.defineProperties,In=Object.getOwnPropertyDescriptors,De=Object.getOwnPropertySymbols,xn=Object.prototype.hasOwnProperty,bn=Object.prototype.propertyIsEnumerable,Fe=(e,t,n)=>t in e?En(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,$n=(e,t)=>{for(var n in t||(t={}))xn.call(t,n)&&Fe(e,n,t[n]);if(De)for(var n of De(t))bn.call(t,n)&&Fe(e,n,t[n]);return e},Rn=(e,t)=>Cn(e,In(t));function Ne(e){return typeof e!="string"&&e&&e.bindToVault}function An(){const e=h(),t=H([]),n=Ce(),r=m(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);He(()=>{const o=Rn($n({},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(Ne(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"}),d=e.get({id:o,type:"Annotation"});l&&d&&(l.items.find(f=>f.id===d.id)||n(W.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"},index:s})))}},[r]),a=w(o=>{r&&(Ne(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 Tn=Object.defineProperty,Mn=Object.defineProperties,Vn=Object.getOwnPropertyDescriptors,Be=Object.getOwnPropertySymbols,Ln=Object.prototype.hasOwnProperty,jn=Object.prototype.propertyIsEnumerable,Ue=(e,t,n)=>t in e?Tn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Dn=(e,t)=>{for(var n in t||(t={}))Ln.call(t,n)&&Ue(e,n,t[n]);if(Be)for(var n of Be(t))jn.call(t,n)&&Ue(e,n,t[n]);return e},Fn=(e,t)=>Mn(e,Vn(t));function Nn(e){const t=L(),n=R(),r=h(),[c,i]=je(),{enabledPageIds:a}=Ee((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id),{all:!1}),o=Re(a,"AnnotationPage"),s=(e==null?void 0:e.strategies)||["images","media","complex-timeline"],[l,d]=$e(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 p=l.types[0];return p==="image"?s.indexOf("images")===-1?E("Image not supported"):ge(n,l,c):p==="audio"?s.indexOf("media")===-1?E("Media not supported"):E("Audio strategy not yet supported"):p==="video"?s.indexOf("media")===-1?E("Media not supported"):E("Video strategy not yet supported"):Y},[n,l,r,d.makeChoice]);return m(()=>f.type==="unknown"?[f,me]:[Fn(Dn({},f),{annotations:{pages:o}}),d],[f,o])}export{Ke as AnnotationContext,te as CanvasContext,Ze as CollectionContext,lt as ContextBridge,ce as ImageServiceLoaderContext,ne as ManifestContext,et as RangeContext,T as ReactVaultContext,b as ResourceProvider,D as ResourceReactContext,at as SimpleViewerProvider,V as SimpleViewerReactContext,re as VaultProvider,M as VisibleCanvasReactContext,me as emptyActions,I as expandTarget,_e as flattenAnnotationPageIds,ge as getImageStrategy,ve as getPaintables,B as parseSelector,pe as parseSpecificResource,Y as unknownResponse,E as unsupportedStrategy,Et as useAnnotation,Ee as useAnnotationPageManager,Mt as useAnnotationsAtTime,R as useCanvas,Vt as useCanvasClock,Lt as useCollection,ct as useContextBridge,Ce as useDispatch,jt as useEventListener,Dt as useExistingVault,Ht as useExternalCollection,ae as useExternalManifest,be as useImageService,N as useImageServiceLoader,zt as useImageTile,je as useLoadImageService,L as useManifest,$e as usePaintables,U as usePaintingAnnotations,Yt as useRange,Nn as useRenderingStrategy,x as useResourceContext,Wt as useResourceEvents,Re as useResources,Gt as useSearchService,st as useSimpleViewer,Xt as useStyles,qt as useThumbnail,h as useVault,Ae as useVaultEffect,P as useVaultSelector,An as useVirtualAnnotationPage,se as useVisibleCanvases};
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
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
7
 
@@ -44,14 +44,15 @@ declare const ReactVaultContext: React.Context<{
44
44
  }>;
45
45
  declare const VaultProvider: React.FC<{
46
46
  vault?: Vault;
47
+ useGlobal?: boolean;
47
48
  vaultOptions?: VaultOptions;
48
49
  resources?: ResourceContextType;
49
50
  }>;
50
51
 
51
52
  declare function useContextBridge(): {
52
53
  VaultContext: {
53
- vault: _iiif_vault.Vault | null;
54
- setVaultInstance: (vault: _iiif_vault.Vault) => void;
54
+ vault: _iiif_vault__.Vault | null;
55
+ setVaultInstance: (vault: _iiif_vault__.Vault) => void;
55
56
  };
56
57
  ResourceContext: ResourceContextType;
57
58
  SimpleViewerReactContext: {
@@ -75,6 +76,152 @@ declare function useVisibleCanvases(): CanvasNormalized[];
75
76
  declare const ImageServiceLoaderContext: React.Context<ImageServiceLoader>;
76
77
  declare function useImageServiceLoader(): ImageServiceLoader;
77
78
 
79
+ interface SingleChoice {
80
+ type: 'single-choice';
81
+ label?: InternationalString;
82
+ items: Array<{
83
+ id: string;
84
+ label?: InternationalString;
85
+ selected?: true;
86
+ }>;
87
+ }
88
+ interface ComplexChoice {
89
+ type: 'complex-choice';
90
+ items: SingleChoice[];
91
+ }
92
+ declare type ChoiceDescription = SingleChoice | ComplexChoice;
93
+
94
+ declare type BoxSelector = {
95
+ type: 'BoxSelector';
96
+ unit?: 'percent' | 'pixel';
97
+ x: number;
98
+ y: number;
99
+ width: number;
100
+ height: number;
101
+ };
102
+ declare type TemporalSelector = {
103
+ type: 'TemporalSelector';
104
+ startTime: number;
105
+ endTime?: number;
106
+ };
107
+ declare type TemporalBoxSelector = {
108
+ type: 'TemporalBoxSelector';
109
+ x: number;
110
+ y: number;
111
+ width: number;
112
+ height: number;
113
+ startTime: number;
114
+ endTime?: number;
115
+ };
116
+ declare type SupportedSelectors = TemporalSelector | BoxSelector | TemporalBoxSelector;
117
+
118
+ declare type ImageWithOptionalService = {
119
+ id: string;
120
+ type: 'Image';
121
+ service?: ImageService;
122
+ width?: number;
123
+ height?: number;
124
+ sizes?: Array<{
125
+ width: number;
126
+ height: number;
127
+ }>;
128
+ target: BoxSelector | TemporalBoxSelector;
129
+ selector: BoxSelector;
130
+ };
131
+ declare type SingleAudio = {
132
+ type: 'Sound';
133
+ url: string;
134
+ format: string;
135
+ duration: number;
136
+ target: TemporalSelector;
137
+ selector: TemporalSelector;
138
+ };
139
+ declare type SingleVideo = {
140
+ type: 'Video';
141
+ url: string;
142
+ format: string;
143
+ duration: number;
144
+ target: TemporalBoxSelector;
145
+ selector: TemporalBoxSelector;
146
+ };
147
+ declare type AudioSequence = {
148
+ type: 'SoundSequence';
149
+ items: SingleAudio[];
150
+ };
151
+ declare type VideoSequence = {
152
+ type: 'VideoSequence';
153
+ items: SingleVideo[];
154
+ };
155
+ declare type AnnotationPageDescription = {
156
+ pages: AnnotationPageNormalized[];
157
+ };
158
+
159
+ declare type MediaStrategy = {
160
+ type: 'media';
161
+ media: SingleAudio | SingleVideo | AudioSequence | VideoSequence;
162
+ choice?: ChoiceDescription;
163
+ annotations?: AnnotationPageDescription;
164
+ };
165
+ declare type ComplexTimelineStrategy = {
166
+ type: 'complex-timeline';
167
+ items: Array<ImageWithOptionalService | SingleAudio | SingleVideo>;
168
+ choice?: ChoiceDescription;
169
+ annotations?: AnnotationPageDescription;
170
+ };
171
+ declare type UnknownStrategy = {
172
+ type: 'unknown';
173
+ reason?: string;
174
+ annotations?: AnnotationPageDescription;
175
+ };
176
+ declare type RenderingStrategy = SingleImageStrategy | MediaStrategy | ComplexTimelineStrategy | UnknownStrategy;
177
+
178
+ declare type ImageServiceLoaderType = (imageService: any | undefined, { height, width }: {
179
+ height: number;
180
+ width: number;
181
+ }) => ImageService | undefined;
182
+ declare function useLoadImageService(): readonly [ImageServiceLoaderType, Record<string, string>];
183
+
184
+ declare type StrategyActions = {
185
+ makeChoice: (id: string, options?: {
186
+ deselectOthers?: boolean;
187
+ deselect?: boolean;
188
+ }) => void;
189
+ };
190
+ declare type UseRenderingStrategy = [RenderingStrategy, StrategyActions];
191
+ declare type UseRenderingStrategyOptions = {
192
+ strategies?: Array<RenderingStrategy['type']>;
193
+ annotationPageManagerId?: string;
194
+ defaultChoices?: string[];
195
+ };
196
+ declare function useRenderingStrategy(options?: UseRenderingStrategyOptions): UseRenderingStrategy;
197
+
198
+ declare function parseSpecificResource(resource: ContentResource): any[];
199
+ interface Paintables {
200
+ choice: ChoiceDescription | null;
201
+ types: string[];
202
+ items: Array<{
203
+ type: string;
204
+ resource: IIIFExternalWebResource | SpecificResource;
205
+ target: any;
206
+ selector: any;
207
+ }>;
208
+ }
209
+ declare function getPaintables(vault: Vault, paintingAnnotations: AnnotationNormalized[], enabledChoices: string[]): Paintables;
210
+ declare const emptyActions: {
211
+ makeChoice: () => void;
212
+ };
213
+ declare const unknownResponse: UseRenderingStrategy[0];
214
+ declare const unsupportedStrategy: (reason: string) => UseRenderingStrategy[0];
215
+
216
+ declare type SingleImageStrategy = {
217
+ type: 'images';
218
+ image: ImageWithOptionalService;
219
+ images: Array<ImageWithOptionalService>;
220
+ choice?: ChoiceDescription;
221
+ annotations?: AnnotationPageDescription;
222
+ };
223
+ declare function getImageStrategy(canvas: CanvasNormalized, paintables: Paintables, loadImageService: ImageServiceLoaderType): RenderingStrategy;
224
+
78
225
  declare function useAnnotation(options?: {
79
226
  id: string;
80
227
  }): AnnotationNormalized | undefined;
@@ -121,6 +268,8 @@ declare function useDispatch(): ReduxStore['dispatch'];
121
268
  declare type SupportedEvents = 'onClick';
122
269
  declare function useEventListener<T>(resource: Reference, name: SupportedEvents, listener: (e: any, resource: T) => void, scope?: string[], deps?: any[]): void;
123
270
 
271
+ declare function useExistingVault(): any;
272
+
124
273
  declare const useExternalCollection: (id: string, config?: QueryOptions<CollectionNormalized>) => {
125
274
  id: string;
126
275
  isLoaded: boolean;
@@ -159,6 +308,15 @@ declare function useManifest<T>(options?: {
159
308
  selector: (manifest: ManifestNormalized) => T;
160
309
  }, deps?: any[]): T | undefined;
161
310
 
311
+ declare function usePaintables(options?: {
312
+ defaultChoices?: string[];
313
+ }, deps?: any[]): readonly [Paintables, {
314
+ makeChoice: (id: string, { deselectOthers, deselect }?: {
315
+ deselectOthers?: boolean | undefined;
316
+ deselect?: boolean | undefined;
317
+ }) => void;
318
+ }];
319
+
162
320
  declare function usePaintingAnnotations(options?: {
163
321
  canvasId?: string;
164
322
  }): AnnotationNormalized[];
@@ -185,151 +343,23 @@ declare function useThumbnail(request: ImageCandidateRequest, dereference?: bool
185
343
  manifestId?: string;
186
344
  }): ImageCandidate | undefined;
187
345
 
188
- declare function useLoadImageService(): readonly [(imageService: any | undefined, { height, width }: {
189
- height: number;
190
- width: number;
191
- }) => ImageService | undefined, Record<string, string>];
192
-
193
346
  declare const useVault: () => Vault;
194
347
 
195
348
  declare const useVaultEffect: (callback: (vault: Vault) => void, deps?: any[]) => void;
196
349
 
197
350
  declare function useVaultSelector<T>(selector: (state: IIIFStore, vault: Vault) => T, deps?: any[]): T;
198
351
 
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<{
352
+ interface VaultActivatedAnnotation {
353
+ __vault?: Vault;
354
+ bindToVault(vault: Vault): void;
355
+ source: string | {
268
356
  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;
357
+ };
358
+ }
359
+ declare function useVirtualAnnotationPage(): readonly [AnnotationPageNormalized | null, {
360
+ readonly addAnnotation: (id: string | Annotation | VaultActivatedAnnotation | AnnotationNormalized, atIndex?: number | undefined) => void;
361
+ readonly removeAnnotation: (id: string | Annotation | VaultActivatedAnnotation | AnnotationNormalized) => void;
362
+ }];
333
363
 
334
364
  declare type SupportedTarget = {
335
365
  type: 'SpecificResource';
@@ -362,15 +392,20 @@ declare type ParsedSelector = {
362
392
  };
363
393
  declare function parseSelector(source: Selector | Selector[]): ParsedSelector;
364
394
 
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
- }[];
395
+ declare type SimpleViewerContext = {
396
+ setCurrentCanvasId: (newId: string | ((prev: string) => string)) => void;
397
+ setCurrentCanvasIndex: (newId: number | ((prev: number) => number)) => void;
398
+ currentCanvasIndex: number;
399
+ pagingView: boolean;
400
+ totalCanvases: number;
401
+ nextCanvas: () => void;
402
+ previousCanvas: () => void;
374
403
  };
404
+ declare const SimpleViewerReactContext: React.Context<SimpleViewerContext>;
405
+ declare const SimpleViewerProvider: FC<{
406
+ manifest: string;
407
+ pagingEnabled?: boolean;
408
+ }>;
409
+ declare function useSimpleViewer(): SimpleViewerContext;
375
410
 
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 };
411
+ export { AnnotationContext, AnnotationPageDescription, AudioSequence, BoxSelector, CanvasContext, ChoiceDescription, CollectionContext, ComplexChoice, ComplexTimelineStrategy, ContextBridge, ImageServiceLoaderContext, ImageServiceLoaderType, ImageWithOptionalService, ManifestContext, MediaStrategy, Paintables, ParsedSelector, RangeContext, ReactVaultContext, RenderingStrategy, ResourceContextType, ResourceProvider, ResourceReactContext, SimpleViewerProvider, SimpleViewerReactContext, SingleAudio, SingleChoice, SingleImageStrategy, SingleVideo, StrategyActions, 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, 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(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,ae){"use strict";function ln(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var w=ln(v),fn=Object.defineProperty,je=Object.getOwnPropertySymbols,hn=Object.prototype.hasOwnProperty,dn=Object.prototype.propertyIsEnumerable,Re=(t,e,i)=>e in t?fn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,$e=(t,e)=>{for(var i in e||(e={}))hn.call(e,i)&&Re(t,i,e[i]);if(je)for(var i of je(e))dn.call(e,i)&&Re(t,i,e[i]);return t};const pn={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},se=w.default.createContext(pn),N=()=>v.useContext(se),W=({value:t,children:e})=>{const i=N(),n=v.useMemo(()=>$e($e({},i),t),[t,i]);return w.default.createElement(se.Provider,{value:n},e)},vn=({annotation:t,children:e})=>w.default.createElement(W,{value:{annotation:t}},e),ke=({canvas:t,children:e})=>w.default.createElement(W,{value:{canvas:t}},e),mn=({collection:t,children:e})=>w.default.createElement(W,{value:{collection:t}},e),Ve=({manifest:t,children:e})=>w.default.createElement(W,{value:{manifest:t}},e),gn=({range:t,children:e})=>w.default.createElement(W,{value:{range:t}},e),Z=w.default.createContext({vault:null,setVaultInstance:t=>{}}),De=({vault:t,vaultOptions:e,useGlobal:i,resources:n,children:o})=>{const[r,a]=v.useState(()=>t||(i?ae.globalVault(e):e?new ae.Vault(e):new ae.Vault));return w.default.createElement(Z.Provider,{value:{vault:r,setVaultInstance:a}},w.default.createElement(W,{value:n||{}},o))};function A(){return A=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},A.apply(this,arguments)}function pe(t,e){if(t==null)return{};var i={},n=Object.keys(t),o,r;for(r=0;r<n.length;r++)o=n[r],!(e.indexOf(o)>=0)&&(i[o]=t[o]);return i}var ve="loading",me="error",qe="success",yn=0,wn=function(){return yn++},Sn={},ce=typeof window>"u",j=function(){},In=function(e){return e},ge=console||{error:j,warn:j,log:j};function _n(){var t=w.default.useRef(null);return t.current===null&&(t.current=wn()),t.current}function bn(t){var e=w.default.useRef();return e.current=t,w.default.useCallback(function(){return e.current},[])}function ye(t,e){return typeof t=="function"?t(e):t}function Cn(t,e){return Ne(e)?Object.assign.apply(Object,[{}].concat(Object.keys(e).sort().map(function(i){var n;return n={},n[i]=e[i],n}))):e}function On(t){return JSON.stringify(t,Cn)}function Ne(t){return t&&typeof t=="object"&&!Array.isArray(t)}function We(t,e){return t===e?!0:typeof t!=typeof e?!1:typeof t=="object"?!Object.keys(e).some(function(i){return!We(t[i],e[i])}):!1}function we(){return typeof document>"u"||document.visibilityState===void 0||document.visibilityState==="visible"||document.visibilityState==="prerender"}function En(){return navigator.onLine===void 0||navigator.onLine}function ze(t){if(Ne(t[0]))if(t[0].hasOwnProperty("queryKey")&&t[0].hasOwnProperty("queryFn")){var e=t[0],i=e.queryKey,n=e.variables,o=n===void 0?[]:n,r=e.queryFn,a=e.config,s=a===void 0?{}:a;return[i,o,r,s]}else throw new Error("queryKey and queryFn keys are required.");if(typeof t[2]=="function"){var l=t[0],u=t[1],f=u===void 0?[]:u,h=t[2],d=t[3],p=d===void 0?{}:d;return[l,f,h,p]}var c=t[0],m=t[1],S=t[2],y=S===void 0?{}:S;return[c,[],m,y]}function An(t){var e=w.default.useRef(!1);return w.default[ce?"useEffect":"useLayoutEffect"](function(){return e.current=!0,function(){return e.current=!1}},[]),w.default.useCallback(function(){return e.current?t.apply(void 0,arguments):void 0},[t])}function xn(t){if((t.config.suspense||t.config.useErrorBoundary)&&t.status===me)throw setTimeout(function(){t.query.state.status="loading"}),t.error;if(t.config.suspense&&t.status===ve)throw t.query.wasSuspended=!0,t.refetch()}function Se(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var i,n,o;if(Array.isArray(t)){if(i=t.length,i!=e.length)return!1;for(n=i;n--!==0;)if(!Se(t[n],e[n]))return!1;return!0}if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===e.valueOf();if(o=Object.keys(t),i=o.length,i!==Object.keys(e).length)return!1;for(n=i;n--!==0;)if(!Object.prototype.hasOwnProperty.call(e,o[n]))return!1;for(n=i;n--!==0;){var r=o[n];if(!Se(t[r],e[r]))return!1}return!0}return t!==t&&e!==e}var Pn=w.default.createContext(),Mn={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:Ge,queryFnParamsFilter:In,throwOnError:!1,useErrorBoundary:void 0,onMutate:j,onSuccess:j,onError:j,onSettled:j,refetchOnMount:!0,isDataEqual:Se},ee={current:Mn};function Ln(){return w.default.useContext(Pn)||ee.current}function Ge(t){if(!t)return[];if(typeof t=="function")try{return Ge(t())}catch{return[]}typeof t=="string"&&(t=[t]);var e=On(t);return t=JSON.parse(e),[e,t]}function G(t,e,i){return i?e?e(t):t:((!t||!t.then)&&(t=Promise.resolve(t)),e?t.then(e):t)}function te(t,e){try{var i=t()}catch(n){return e(n)}return i&&i.then?i.then(void 0,e):i}function H(t){return function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];try{return Promise.resolve(t.apply(this,e))}catch(n){return Promise.reject(n)}}}function He(t,e){var i=t();return i&&i.then?i.then(e):e(i)}var Qe=Rn(),Fn=w.default.createContext(Qe),Tn=[Qe];function jn(){return w.default.useContext(Fn)}var Ue={},Be={},Je={},Ke={},Ye={},Xe={},Ze={},et={};function Rn(){var t=[],e={queries:{},isFetching:0},i=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(r){return t.push(r),function(){t.splice(t.indexOf(r),1)}},e.clear=function(){Object.values(e.queries).forEach(function(r){return r.clear()}),e.queries={},i()};var n=function(a,s){var l=s===void 0?{}:s,u=l.exact;if(typeof a!="function"){var f=ee.current.queryKeySerializerFn(a),h=f[0],d=f[1];a=function(c){return u?c.queryHash===h:We(c.queryKey,d)}}return Object.values(e.queries).filter(a)};e.getQueries=n,e.getQuery=function(r){return n(r,{exact:!0})[0]},e.getQueryData=function(r){var a;return(a=e.getQuery(r))==null?void 0:a.state.data},e.removeQueries=function(r,a){var s=a===void 0?{}:a,l=s.exact,u=n(r,{exact:l});u.forEach(function(f){clearTimeout(f.staleTimeout),delete e.queries[f.queryHash]}),u.length&&i()},e.cancelQueries=function(r,a){var s=a===void 0?{}:a,l=s.exact,u=n(r,{exact:l});u.forEach(function(f){f.cancel()}),u.length&&i()},e.refetchQueries=H(function(r,a){var s=a===void 0?{}:a,l=s.exact,u=s.throwOnError,f=s.force,h=r===!0?Object.values(e.queries):n(r,{exact:l});return te(function(){return G(Promise.all(h.map(function(d){return d.fetch({force:f})})))},function(d){if(u)throw d})}),e._buildQuery=function(r,a,s,l){var u=l.queryKeySerializerFn(r),f=u[0],h=u[1],d=e.queries[f];return d?(Object.assign(d,{queryVariables:a,queryFn:s}),d.config=A({},d.config,l)):(d=o({cache:e,queryKey:h,queryHash:f,queryVariables:a,queryFn:s,config:l}),!ce&&d.state.data&&(d.scheduleStaleTimeout(),d.heal(),d.scheduleGarbageCollection()),d.queryHash&&(ce||(e.queries[f]=d,setTimeout(function(){i()})))),d},e.prefetchQuery=H(function(){for(var r=!1,a=arguments.length,s=new Array(a),l=0;l<a;l++)s[l]=arguments[l];var u=ze(s),f=u[0],h=u[1],d=u[2],p=u[3],c=p.force,m=pe(p,["force"]);m=A({},ee.current,m);var S=e._buildQuery(f,h,d,m);return He(function(){if(S.state.isStale||c)return te(function(){return G(S.fetch({force:c}),function(y){return S.wasPrefetched=!0,r=!0,y})},function(y){if(m.throwOnError)throw y})},function(y){return r?y:S.state.data})}),e.setQueryData=function(r,a,s){var l=s===void 0?{}:s,u=l.exact,f=pe(l,["exact"]),h=n(r,{exact:u});!h.length&&typeof r!="function"&&(h=[e._buildQuery(r,void 0,function(){return Promise.resolve()},A({},ee.current,f))]),h.forEach(function(d){return d.setData(a)})};function o(r){var a=r.cache,s=r.config.queryReducer||$n,l=typeof r.queryHash>"u",u=typeof r.config.initialData=="function"?r.config.initialData():r.config.initialData,f=typeof u<"u",h=l?!0:!f,d=r.config.manual,p=l||d||f?qe:ve,c=A({},r,{instances:[],state:s(void 0,{type:Ue,initialStatus:p,initialData:u,hasInitialData:f,isStale:h,manual:d})}),m=function(b){c.state=s(c.state,b),c.instances.forEach(function(x){return x.onStateUpdate(c.state)}),i()};c.scheduleStaleTimeout=function(){c.config.staleTime!==1/0&&(c.staleTimeout=setTimeout(function(){a.getQuery(c.queryKey)&&m({type:Je})},c.config.staleTime))},c.scheduleGarbageCollection=function(){c.config.cacheTime!==1/0&&(m({type:Ke}),c.cacheTimeout=setTimeout(function(){e.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=Sn,c.cancelPromises&&c.cancelPromises(),delete c.promise,i()},c.updateInstance=function(y){var b=c.instances.find(function(x){return x.id===y.id});b?Object.assign(b,y):(b=A({onStateUpdate:j},y),c.instances.push(y))},c.subscribe=function(y){return c.heal(),function(){c.instances=c.instances.filter(function(b){return b.id!==y}),c.instances.length||(c.cancel(),c.scheduleGarbageCollection())}};var S=H(function(y){for(var b=arguments.length,x=new Array(b>1?b-1:0),L=1;L<b;L++)x[L-1]=arguments[L];return te(function(){var q=y.apply(void 0,c.config.queryFnParamsFilter(x));return c.cancelPromises=function(){return q.cancel==null?void 0:q.cancel()},G(q,function(F){if(delete c.shouldContinueRetryOnFocus,delete c.cancelPromises,c.cancelled)throw c.cancelled;return F})},function(q){var F=!1;if(delete c.cancelPromises,c.cancelled)throw c.cancelled;return m({type:Be}),He(function(){if(c.config.retry===!0||c.state.failureCount<=c.config.retry||typeof c.config.retry=="function"&&c.config.retry(c.state.failureCount,q)){if(!we())return c.shouldContinueRetryOnFocus=!0,F=!0,new Promise(j);delete c.shouldContinueRetryOnFocus;var M=ye(c.config.retryDelay,c.state.failureCount);return F=!0,G(new Promise(function(E,de){setTimeout(H(function(){return c.cancelled?de(c.cancelled):te(function(){return G(S.apply(void 0,[y].concat(x)),function(Te){if(c.cancelled)return de(c.cancelled);E(Te)})},function(Te){if(c.cancelled)return de(c.cancelled);de(Te)})}),M)}))}},function(M){if(F)return M;throw q})})});return c.fetch=H(function(y){var b=y===void 0?{}:y,x=b.force,L=b.__queryFn,q=L===void 0?c.queryFn:L;if(!(!c.queryHash||!c.state.isStale&&!x))return c.promise||(c.promise=H(function(){c.cancelled=null;var F=[].concat(c.instances);return c.wasSuspended&&F.unshift(c.suspenseInstance),te(function(){return m({type:Ye}),G(S.apply(void 0,[q].concat(c.queryKey,c.queryVariables)),function(M){return c.setData(function(E){return c.config.isDataEqual(E,M)?E:M}),F.forEach(function(E){return E.onSuccess&&E.onSuccess(c.state.data)}),F.forEach(function(E){return E.onSettled&&E.onSettled(c.state.data,null)}),delete c.promise,M})},function(M){if(m({type:Ze,cancelled:M===c.cancelled,error:M}),delete c.promise,M!==c.cancelled)throw F.forEach(function(E){return E.onError&&E.onError(M)}),F.forEach(function(E){return E.onSettled&&E.onSettled(void 0,M)}),M})})()),c.promise}),c.setState=function(y){return m({type:et,updater:y})},c.setData=function(y){m({type:Xe,updater:y}),clearTimeout(c.staleTimeout),c.scheduleStaleTimeout()},c.clear=function(){clearTimeout(c.staleTimeout),clearTimeout(c.cacheTimeout),c.cancel()},c}return e}function $n(t,e){switch(e.type){case Ue: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 Be:return A({},t,{failureCount:t.failureCount+1});case Je:return A({},t,{isStale:!0});case Ke:return A({},t,{markedForGarbageCollection:!0});case Ye:return A({},t,{status:t.status===me?ve:t.status,isFetching:!0,failureCount:0});case Xe:return A({},t,{status:qe,data:ye(e.updater,t.data),error:null,isStale:!1,isFetching:!1,canFetchMore:e.canFetchMore,updatedAt:Date.now(),failureCount:0});case Ze:return A({},t,{isFetching:!1,isStale:!0},!e.cancelled&&{status:me,error:e.error});case et:return ye(e.updater,t);default:throw new Error}}var tt="visibilitychange",it="focus",kn=function(){var e=ee.current.refetchAllOnWindowFocus;we()&&En()&&Tn.forEach(function(i){return i.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(ge.error)})},Ie;function Vn(t){Ie&&Ie(),Ie=t(kn)}Vn(function(t){var e;if(!ce&&((e=window)==null?void 0:e.addEventListener))return window.addEventListener(tt,t,!1),window.addEventListener(it,t,!1),function(){window.removeEventListener(tt,t),window.removeEventListener(it,t)}});function Dn(t,e,i){return i?e?e(t):t:((!t||!t.then)&&(t=Promise.resolve(t)),e?t.then(e):t)}function qn(t,e){try{var i=t()}catch(n){return e(n)}return i&&i.then?i.then(void 0,e):i}function Nn(t){return function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];try{return Promise.resolve(t.apply(this,e))}catch(n){return Promise.reject(n)}}}function Wn(t,e,i,n){n===void 0&&(n={});var o=_n();n=A({},Ln(),n);var r=jn(),a=w.default.useRef(),s=r._buildQuery(t,e,i,n),l=a.current&&typeof a.current.queryHash>"u"&&typeof s.queryHash>"u";l||(a.current=s);var u=a.current,f=w.default.useState(),h=f[1],d=An(h),p=bn(n),c=w.default.useCallback(Nn(function(m){var S=m===void 0?{}:m,y=S.throwOnError,b=pe(S,["throwOnError"]);return qn(function(){return Dn(u.fetch(b))},function(x){if(y)throw x})}),[u]);return u.suspenseInstance={onSuccess:function(S){return p().onSuccess(S)},onError:function(S){return p().onError(S)},onSettled:function(S,y){return p().onSettled(S,y)}},w.default.useEffect(function(){return u.updateInstance({id:o,onStateUpdate:function(){return d({})},onSuccess:function(S){return p().onSuccess(S)},onError:function(S){return p().onError(S)},onSettled:function(S,y){return p().onSettled(S,y)}}),u.subscribe(o)},[p,o,u,d]),w.default.useEffect(function(){!p().manual&&!u.wasPrefetched&&!u.wasSuspended&&u.state.isStale&&(p().refetchOnMount||u.instances.length===1)&&c().catch(ge.error),u.wasPrefetched=!1,u.wasSuspended=!1},[p,u,c]),w.default.useEffect(function(){var m=a.current;if(n.refetchInterval&&(!m.currentRefetchInterval||n.refetchInterval<m.currentRefetchInterval))return m.currentRefetchInterval=n.refetchInterval,clearInterval(m.refetchIntervalId),m.refetchIntervalId=setInterval(function(){(we()||n.refetchIntervalInBackground)&&c().catch(ge.error)},n.refetchInterval),function(){clearInterval(m.refetchIntervalId),delete m.refetchIntervalId,delete m.currentRefetchInterval}},[n.refetchInterval,n.refetchIntervalInBackground,c]),A({},u.state,{config:n,query:u,refetch:c})}function _e(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];var n=Wn.apply(void 0,ze(e));return xn(n),n}const C=()=>{const{vault:t}=v.useContext(Z);if(t===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return t};var zn=Object.defineProperty,nt=Object.getOwnPropertySymbols,Gn=Object.prototype.hasOwnProperty,Hn=Object.prototype.propertyIsEnumerable,rt=(t,e,i)=>e in t?zn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Qn=(t,e)=>{for(var i in e||(e={}))Gn.call(e,i)&&rt(t,i,e[i]);if(nt)for(var i of nt(e))Hn.call(e,i)&&rt(t,i,e[i]);return t},Un=(t,e,i)=>new Promise((n,o)=>{var r=l=>{try{s(i.next(l))}catch(u){o(u)}},a=l=>{try{s(i.throw(l))}catch(u){o(u)}},s=l=>l.done?n(l.value):Promise.resolve(l.value).then(r,a);s((i=i.apply(t,e)).next())});const ot=(t,e={})=>{const i=C(),[n,o]=v.useState(t),r=v.useMemo(()=>i.get(t)||void 0,[t,i]),{data:a,error:s}=_e(["manifest",t],()=>Un(void 0,null,function*(){const l=r||(yield i.load(t));return l&&n!==l.id&&o(l.id),l}),Qn({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,retry:!1,initialData:r},e));return{isLoaded:!!a,id:n,error:s,manifest:a}};function P(t,e=[]){const i=C(),[n,o]=v.useState(()=>t(i.getState(),i));return v.useEffect(()=>i.subscribe(r=>t(r,i),r=>{o(r)},!0),e),n}const ie=w.default.createContext([]);function at(){const t=v.useContext(ie);return P(e=>t.map(i=>e.iiif.entities.Canvas[i]).filter(Boolean),[t])}const ue=()=>{},ne=v.createContext({setCurrentCanvasId:ue,setCurrentCanvasIndex:ue,nextCanvas:ue,previousCanvas:ue,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),Bn=t=>{const e=ot(t.manifest),[i,n]=v.useState(""),[o,r]=v.useState([]),a=(typeof t.pagingEnabled>"u"||t.pagingEnabled)&&e.manifest&&e.manifest.behavior&&e.manifest.behavior.includes("paged");v.useEffect(()=>{var c,m;e.manifest&&(n((c=e.manifest.items[0])==null?void 0:c.id),r([(m=e.manifest.items[0])==null?void 0:m.id]))},[e.manifest,t.manifest]);const s=v.useMemo(()=>{var c;return((c=e.manifest)==null?void 0:c.items.map(m=>m.id))||[]},[e.manifest,t.manifest]),l=v.useMemo(()=>s.indexOf(i),[s,i]),u=v.useCallback(()=>{if(s.length&&i){if(l===-1||(s[l+2]?l+2===s.length:l===s.length))return;const c=a&&l!==0?s[l+2]:s[l+1],m=a?l!==0?s[l+3]:s[l+2]:null;c&&(n(c),r(m?[c,m]:[c]))}},[a,s,i,l]),f=v.useCallback(()=>{if(s.length&&i){if(l===0||l===-1)return;const c=a&&l!==1?s[l-2]:s[l-1],m=a&&l!==1?s[l-1]:null;c&&(n(c),r(m?[c,m]:[c]))}},[a,s,i,l]),h=v.useCallback(c=>{const m=a&&c%2===1?c-1:c,S=s[m],y=a&&m!==0?s[m+1]:null;S&&(n(S),r(b=>{const x=y?[S,y]:[S];if(b.length===b.length){for(let L=0;L<b.length;L++)if(b[L]!==x[L])return x;return b}return x}))},[a,s]),d=v.useCallback(c=>{const m=s.indexOf(c);m!==-1&&h(m)},[s,h]),p=v.useMemo(()=>({setCurrentCanvasId:d,nextCanvas:u,previousCanvas:f,currentCanvasIndex:l,totalCanvases:s.length,setCurrentCanvasIndex:h,pagingView:!0}),[u,f,l,s,h,d]);return!e.isLoaded||!e.manifest?w.default.createElement("div",null,"Loading..."):w.default.createElement(ne.Provider,{value:p},w.default.createElement(ie.Provider,{value:o},w.default.createElement(Ve,{manifest:e.manifest.id},w.default.createElement(ke,{canvas:i},t.children))))};function Jn(){return v.useContext(ne)}function Kn(){return{VaultContext:v.useContext(Z),ResourceContext:v.useContext(se),SimpleViewerReactContext:v.useContext(ne),VisibleCanvasReactContext:v.useContext(ie)}}const Yn=t=>w.default.createElement(De,{vault:t.bridge.VaultContext.vault||void 0,resources:t.bridge.ResourceContext},w.default.createElement(ie.Provider,{value:t.bridge.VisibleCanvasReactContext},w.default.createElement(ne.Provider,{value:t.bridge.SimpleViewerReactContext},t.children)));function Q(t){return t.endsWith("info.json")?t:t.endsWith("/")?`${t}info.json`:`${t}/info.json`}function Xn(t,e,i){const n=i.length,o=[];for(let r=0;r<n;r++){const s=i[r].width;o.push(t/s)}return o}function Zn(t,e,i){const n=i.length,o=[];for(let r=0;r<n;r++){const a=i[r];o.push({width:Math.floor(t/a),height:Math.floor(e/a)})}return o}const er="http://library.stanford.edu/iiif/image-api/compliance.html#level0",st="http://library.stanford.edu/iiif/image-api/compliance.html#level1",ct="http://library.stanford.edu/iiif/image-api/compliance.html#level2",tr="http://library.stanford.edu/iiif/image-api/conformance.html#level0",ut="http://library.stanford.edu/iiif/image-api/conformance.html#level1",lt="http://library.stanford.edu/iiif/image-api/conformance.html#level2",ir="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",ft="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",ht="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",nr="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",dt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",pt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",rr="http://iiif.io/api/image/1/level0.json",or="http://iiif.io/api/image/1/profiles/level0.json",vt="http://iiif.io/api/image/1/level1.json",mt="http://iiif.io/api/image/1/profiles/level1.json",gt="http://iiif.io/api/image/1/level2.json",yt="http://iiif.io/api/image/1/profiles/level2.json",ar="http://iiif.io/api/image/2/level0.json",sr="http://iiif.io/api/image/2/profiles/level0.json",wt="http://iiif.io/api/image/2/level1.json",St="http://iiif.io/api/image/2/profiles/level1.json",It="http://iiif.io/api/image/2/level2.json",_t="http://iiif.io/api/image/2/profiles/level2.json",cr="level0",bt="level1",Ct="level2",ur="http://iiif.io/api/image/2/level0",Ot="http://iiif.io/api/image/2/level1",Et="http://iiif.io/api/image/2/level2",lr=[Ot,Et,st,ct,ut,lt,ft,ht,dt,pt,vt,mt,gt,yt,wt,St,It,_t,bt,Ct],fr=[ur,Ot,Et,er,st,ct,tr,ut,lt,ir,ft,ht,nr,dt,pt,rr,or,vt,mt,gt,yt,ar,sr,wt,St,It,_t,cr,bt,Ct];function I(t){if(t["@id"])return t["@id"];if(t.id)return t.id}function be(t){if(!t||!t.profile||!I(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if(typeof i=="string"&&fr.indexOf(i)!==-1)return!0;return!1}function hr(t){if(!be(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if(typeof i=="string"){if(lr.indexOf(i)!==-1)return!0}else{const n=i.supports||[];if(n.indexOf("regionByPx")!==-1&&(n.indexOf("sizeByW")!==-1||n.indexOf("sizeByWh")!==-1))return!0}return!1}function dr(t){if(!hr(t))return[];const e=[],i=Array.isArray(t.profile)?t.profile:[t.profile],n=i.length;for(let o=0;o<n;o++){const r=i[o];if(typeof r!="string"&&(r.maxHeight||r.maxWidth))return[{id:I(t),type:"variable",minWidth:0,minHeight:0,maxHeight:r.maxHeight||r.maxWidth,maxWidth:r.maxWidth||r.maxHeight}]}if(t.tiles){const o=t.tiles.length;for(let r=0;r<o;r++){const a=t.tiles[r];(a.height||a.width)&&e.push({id:I(t),type:"variable",minHeight:0,minWidth:0,maxHeight:a.height||a.width,maxWidth:a.width})}}return e}function At(t){const e=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,i=t.match(e);if(i){const n=i[1],o=parseInt(i[4],10),r=parseInt(i[5],10),a=i[7];if((n==="max"||n==="full")&&o&&r&&a)return{type:"fixed",id:t,height:r,width:o}}return{type:"unknown",id:t}}function pr(t){if(t["@type"])return t["@type"];if(t.type)return t.type}function vr(t){if(typeof t=="string")return At(t);const e=pr(t);if(e!=="Image"&&e!=="sc:Image")return null;const i=t,n=I(i);return n?n&&i.width&&i.height?{id:n,type:"fixed",width:i.width,height:i.height,unsafe:!0}:At(n):null}function mr(t){return be(t)?(t&&t.sizes?t.sizes:[]).map(e=>({id:I(t),type:"fixed-service",height:e.height,width:e.width})):[]}function xt(t){const e=[],i=t.length;for(let n=0;n<i;n++){const o=mr(t[n]);o.length&&e.push(...o);const r=dr(t[n]);r.length&&e.push(...r)}return e}function re(t){const e=t.service?Array.isArray(t.service)?t.service:[t.service]:[],i=e.length,n=[];for(let o=0;o<i;o++)be(e[o])&&n.push(e[o]);return n}function gr(t,e=!0,i){const n=[],o=vr(t);if(o===null)return n;const r=t;if(n.push(o),e&&r.width&&r.height){const a=[],s=re(r);for(const l of s){const u={id:I(l),width:r.width,height:r.height};if(i.canLoadSync(u)){const f=i.loadServiceSync(u);f&&(f.height||(f.height=r.height),f.width||(f.width=r.width),a.push(...xt([f])))}}if(a.length)return n.push(...a),n}return r.service&&n.push(...xt(r.service)),n}function Ce(t,e,i){return{id:[Q(I(t)).slice(0,-10),"full",[e,i||""].join(","),0,"default.jpg"].join("/"),type:"fixed",width:e,height:i||t.height/t.width*e,unsafe:t.width>e}}function U(t){const e=t.replace(/(https?:\/\/)?(www.)?/i,"");return e.indexOf("/")!==-1?e.split("/")[0]:e}function yr(t,e,i){const n=t.width?t.width:t.maxWidth;return i.height<=t.maxHeight&&i.width<=t.maxWidth&&i.height>=t.minHeight&&i.width>=t.minWidth&&(!e||Math.abs(i.width-n)<Math.abs(e.width-n))}function wr(t,e){const i=[],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=[],r=[];let a=null;const s=(u,f)=>{if(yr(n,f,u)){if(n.preferFixedSize&&u.unsafe){r.push(u);return}n.returnAllOptions&&f&&r.push(f),a=u}else n.returnAllOptions&&r.push(u)},l=e.length;for(let u=0;u<l;u++){const f=e[u](),h=f.length;for(let d=0;d<h;d++){const p=f[d];if(p.type==="unknown"&&n.atAnyCost&&o.push(p),p.type==="fixed"&&(p.unsafe?o.push(p):s(p,a)),p.type==="fixed-service")if(n.unsafeImageService){const c=Ce(p,n.width,n.height);s(c,a)}else{const c=Ce(p,p.width,p.height);s(c,a)}if(p.type==="variable"&&p.maxWidth){const c=Ce({id:p.id,type:"fixed-service",width:p.maxWidth,height:p.maxWidth},p.maxWidth);s(c,a)}}if(a&&!n.returnAllOptions){if(a.unsafe||n.allowUnsafe)continue;break}}return n.atAnyCost&&r.length===0?{best:a||o[0],fallback:o.slice(1),log:i}:n.returnAllOptions?{best:n.atAnyCost?a||r[0]||o[0]:a||r[0],fallback:[...r,...o],log:i}:{best:a||r[0]||null,fallback:a?r:r.slice(1),log:i}}function Sr(t,e,i){const n=t>e?t:e,o=i.length,r=[];for(let a=0;a<o;a++){const s=i[a];let l=s.scaleFactors[0],u=n/l;const f=[l];for(;u>=s.width;)l=l*2,f.push(l),u=u/2;r.push(Object.assign(Object.assign({},s),{scaleFactors:f}))}return r}function Ir(t,e){if(t.length!==e.length)return!1;if(t.length===0&&e.length===0)return!0;const i=t.length;let n=!0;for(let r=0;r<i;r++){const a=t[r],s=e[r];if(a.width!==s.width||a.height!==s.height){n=!1;break}}if(n)return!0;let o=0;for(let r=0;r<i;r++)for(let a=0;a<i;a++)if(t[r].width===e[a].width&&t[r].height===e[a].height){o++;break}return o===i}/*! *****************************************************************************
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,7 +11,7 @@
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}/*! *****************************************************************************
14
+ ***************************************************************************** */function B(t,e,i,n){function o(r){return r instanceof i?r:new i(function(a){a(r)})}return new(i||(i=Promise))(function(r,a){function s(f){try{u(n.next(f))}catch(h){a(h)}}function l(f){try{u(n.throw(f))}catch(h){a(h)}}function u(f){f.done?r(f.value):o(f.value).then(s,l)}u((n=n.apply(t,e||[])).next())})}class Pt{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,i,n=!0){const o=U(I(e)),r=Q(I(e)),a=this.knownImageServers[o];return this.imageServices[r]=Object.assign(e,{real:!0}),a?this.verify(e):(this.knownImageServers[o]={verifications:0,malformed:!1,root:o,preLoaded:n,sampledId:I(e),verified:!1,server:null,result:{context:e["@context"]||[],sampledProfile:e.profile,resourceServiceRatio:i&&e.height?i.height/e.height:1,sampledSizes:e.sizes||[],sizeRatios:Xn(e.width,e.height,e.sizes||[]),sampledTiles:e.tiles||[]}},!0)}preLoad(e,i=!0){this.knownImageServers[e.root]=e,i&&(this.knownImageServers[e.root].malformed=!1,this.knownImageServers[e.root].verifications=this.config.verificationsRequired)}predict(e,i=!1,n=!1){const o=U(I(e)),r=this.knownImageServers[o];if(!r||!r.result||!n&&(r.malformed||r.verifications<this.config.verificationsRequired))return null;const a=Q(I(e));return this.imageServices[a]||(this.imageServices[a]={"@context":r.result.context,"@id":I(e),id:I(e),protocol:"http://iiif.io/api/image",tiles:Sr(e.width,e.height,r.result.sampledTiles),sizes:Zn(Math.floor(e.width/r.result.resourceServiceRatio),Math.floor(e.height/r.result.resourceServiceRatio),r.result.sizeRatios),profile:r.result.sampledProfile,height:e.height,width:e.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(e,i,n=!0,o=[]){return B(this,void 0,void 0,function*(){const r=yield this.getImageCandidates(e,n);return wr(i,[()=>o,()=>r])})}getImageCandidates(e,i=!0){return B(this,void 0,void 0,function*(){const n=e;if(i&&n.height&&n.width){const o=re(n);for(const r of o){const a={id:I(r),width:r.width?r.width:n.width,height:r.height?r.height:n.height};yield this.loadService(a)}}return gr(e,i,this)})}verify(e){return B(this,void 0,void 0,function*(){const i=this.predict(e,!1,!0),n=yield this.fetchService(I(e));if(!i)return!1;const o=i.height===n.height&&i.width===n.width&&i["@context"]===n["@context"]&&Ir(i.sizes||[],n.sizes||[]);if(o){const r=U(I(e));this.knownImageServers[r].verifications+=1,this.knownImageServers[r].verifications>=this.config.verificationsRequired&&(this.knownImageServers[r].verified=!0)}return o})}canLoadSync(e){const i=typeof e=="string"?e:I(e),n=Q(i);if(this.imageServices[n])return!0;const o=this.knownImageServers[U(i)];return o&&!o.malformed&&o.verifications>=this.config.verificationsRequired}markAsMalformed(e){return B(this,void 0,void 0,function*(){return this.knownImageServers[U(I(e))].malformed=!0,this.loadService(e,!0)})}fetchService(e,i=!1){return B(this,void 0,void 0,function*(){const n=Q(e);if(this.imageServices[n]&&(!i||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(r=>r.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,i=!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 n=this.knownImageServers[U(I(e))];if(n&&!n.malformed&&!i){yield n.result;const r=this.loadServiceSync(e);if(r)return r}this.fetchingCount++;const o=yield this.fetchService(I(e),i);return this.fetchingCount--,o.real&&this.sample(o,e),o})}loadServiceSync(e){const i=Q(I(e));return this.imageServices[i]?this.imageServices[i]:this.predict(e)}}new Pt;const Mt=w.default.createContext(new Pt);function le(){return v.useContext(Mt)}const _r=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,br=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function fe(t){if(Array.isArray(t))return t.reduce((e,i)=>{const{selector:n,selectors:o}=fe(i);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,i]=t.split("#");return i?fe({type:"FragmentSelector",value:i}):{selector:null,selectors:[]}}if(t.type==="PointSelector"&&(t.t||t.t===0)){const e={type:"TemporalSelector",startTime:t.t};return{selector:e,selectors:[e]}}if(t.type==="FragmentSelector"){const e=_r.exec(t.value);if(e){const n={type:"BoxSelector",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 i=t.value.match(br);if(i){const n={type:"TemporalSelector",startTime:i[4]?parseFloat(i[4]):0,endTime:i[7]?parseFloat(i[7]):void 0};return{selector:n,selectors:[n]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}var Cr=Object.defineProperty,Or=Object.defineProperties,Er=Object.getOwnPropertyDescriptors,Lt=Object.getOwnPropertySymbols,Ar=Object.prototype.hasOwnProperty,xr=Object.prototype.propertyIsEnumerable,Ft=(t,e,i)=>e in t?Cr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Tt=(t,e)=>{for(var i in e||(e={}))Ar.call(e,i)&&Ft(t,i,e[i]);if(Lt)for(var i of Lt(e))xr.call(e,i)&&Ft(t,i,e[i]);return t},jt=(t,e)=>Or(t,Er(e));function V(t,e={}){if(Array.isArray(t))return V(t[0]);if(typeof t=="string"){const[i,n]=t.split("#");return n?V({type:"SpecificResource",source:{id:i,type:"Unknown"},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{id:i,type:e.typeMap&&e.typeMap[i]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return V(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:i,selectors:n}=t.selector?fe(t.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:i,selectors:n}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[i,n]=t.id.split("#");return n?V({type:"SpecificResource",source:jt(Tt({},t),{id:i}),selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:jt(Tt({},t),{id:i}),selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}function Rt(t){return t.type==="SpecificResource"?[t.source,{selector:t.selector}]:[t,{selector:null}]}function $t(t,e,i){const n=[];let o=null;const r=[];for(const a of e){const s=t.get(a.body);for(const l of s){const[u,{selector:f}]=Rt(l),h=(u.type||"unknown").toLowerCase();if(h==="choice"){const d=t.get(u.items),p=i.length?i.map(c=>d.find(m=>m.id===c)).filter(Boolean):[d[0]];p.length===0&&p.push(d[0]),o={type:"single-choice",items:d.map(c=>({id:c.id,label:c.label,selected:p.indexOf(c)!==-1})),label:l.label},s.push(...p);continue}n.indexOf(h)===-1&&n.push(h),r.push({type:h,resource:u,target:a.target,selector:f})}}return{types:n,items:r,choice:o}}const kt={makeChoice:()=>{}},Oe={type:"unknown"},R=t=>({type:"unknown",reason:t,annotations:{pages:[]}});function Vt(t,e,i){const n=[];for(const o of e.items){const r=o.resource&&o.resource.type==="SpecificResource"?o.resource.source:o.resource;if(!r.id)return R("No resource Identifier");let a;if(r.service){const m=re(r);m[0]&&(a=i(m[0],t))}const{selector:s,source:l}=V(o.target);if(l.id!==t.id)continue;const u={type:"BoxSelector",x:0,y:0,width:t.width,height:t.height},f=s?s.type==="TemporalSelector"?{type:"TemporalBoxSelector",startTime:s.startTime,endTime:s.endTime,x:u.x,y:u.y,width:u.width,height:u.height}:s:null,h={type:"BoxSelector",x:0,y:0,width:t.width,height:t.height},d=o.resource.type==="SpecificResource"?V(o.resource):null,p=d&&d.selector&&(d.selector.type==="BoxSelector"||d.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",x:d.selector.x,y:d.selector.y,width:d.selector.width,height:d.selector.height}:h,c={id:r.id,type:"Image",width:f?r.width:t.width,height:f?r.height:t.height,service:a,sizes:a&&a.sizes?a.sizes:r.width&&r.height?[{width:r.width,height:r.height}]:[],target:f||u,selector:p};n.push(c)}return{type:"images",image:n[0],images:n,choice:e.choice}}var Pr=Object.defineProperty,Mr=Object.defineProperties,Lr=Object.getOwnPropertyDescriptors,Dt=Object.getOwnPropertySymbols,Fr=Object.prototype.hasOwnProperty,Tr=Object.prototype.propertyIsEnumerable,qt=(t,e,i)=>e in t?Pr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,jr=(t,e)=>{for(var i in e||(e={}))Fr.call(e,i)&&qt(t,i,e[i]);if(Dt)for(var i of Dt(e))Tr.call(e,i)&&qt(t,i,e[i]);return t},Rr=(t,e)=>Mr(t,Lr(e));function $r(t={},e=[]){const{id:i,selector:n}=t,o=N(),r=C(),a=i||o.annotation,s=P(u=>a?u.iiif.entities.Annotation[a]:void 0,[a]),l=P(u=>s&&s.body?s.body.map(f=>f?u.iiif.entities[f.type][f.id]:null).filter(Boolean):[],[s]);return v.useMemo(()=>{if(!s)return;const u=Rr(jr({},s),{body:l,target:V(s.target,{typeMap:r.getState().iiif.mapping})});return n?n(u):u},[s,n,l,...e])}function oe(t={},e=[]){const{id:i,selector:n}=t,o=N();C();const r=i||o.manifest,a=P(s=>r?s.iiif.entities.Manifest[r]:void 0,[r]);return v.useMemo(()=>{if(!!a)return n?n(a):a},[a,n,...e])}function J(t={},e=[]){const{id:i,selector:n}=t,o=N(),r=i||o.canvas,a=P(s=>r?s.iiif.entities.Canvas[r]:void 0,[r]);return v.useMemo(()=>{if(!!a)return n?n(a):a},[a,n,...e])}function kr(t,e){var i;const n=(i=t==null?void 0:t.iiif)==null?void 0:i.meta[e];return n?n.annotationPageManager:null}function Vr(t,e){return P(i=>{const n=[];if(!t)return n;const o=Object.keys(i.iiif.entities.AnnotationPage);for(const r of o)if(!e||e.indexOf(r)!==-1){const a=kr(i,r);a&&a.views&&a.views[t]&&n.push(r)}return n},[t])}function Nt({canvas:t,manifest:e,all:i,canvases:n}){const o=[];if(e)for(const r of e.annotations)o.indexOf(r.id)===-1&&o.push(r.id);if(i){if(n&&n.length)for(const r of n)for(const a of r.annotations)o.indexOf(a.id)===-1&&o.push(a.id)}else if(t)for(const r of t.annotations)o.indexOf(r.id)===-1&&o.push(r.id);return o}var Dr=Object.defineProperty,qr=Object.defineProperties,Nr=Object.getOwnPropertyDescriptors,Wt=Object.getOwnPropertySymbols,Wr=Object.prototype.hasOwnProperty,zr=Object.prototype.propertyIsEnumerable,zt=(t,e,i)=>e in t?Dr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Gt=(t,e)=>{for(var i in e||(e={}))Wr.call(e,i)&&zt(t,i,e[i]);if(Wt)for(var i of Wt(e))zr.call(e,i)&&zt(t,i,e[i]);return t},Ht=(t,e)=>qr(t,Nr(e));function Gr(t,e){var i;const n=(i=t==null?void 0:t.iiif)==null?void 0:i.meta[e];return n?n.annotationPageManager:null}function Qt(t,e={}){const i=C(),n=oe(),o=J(),r=at(),a=v.useMemo(()=>Nt({all:e.all,manifest:n,canvas:o,canvases:r}),[e.all,o,r,n]),s=Vr(t,e.all?void 0:a),l=v.useCallback(f=>{!t||i.setMetaValue([f,"annotationPageManager","views"],h=>h&&!h[t]?h:Ht(Gt({},h||{}),{[t]:!1}))},[t,i]),u=v.useCallback((f,h={})=>{if(!t)return;const d=i.getState(),p=[];if(h==null?void 0:h.deselectOthers){const c=Object.keys(d.iiif.entities.AnnotationPage);for(const m of c){const S=Gr(d,m);S&&S.views&&S.views[t]&&p.push(m)}}for(const c of p)l(c);i.setMetaValue([f,"annotationPageManager","views"],c=>c&&c[t]?c:Ht(Gt({},c||{}),{[t]:!0}))},[t,l,i]);return{availablePageIds:a,enabledPageIds:s,setPageEnabled:u,setPageDisabled:l}}function he(t={}){const e=J(t.canvasId?{id:t.canvasId}:void 0);return P((i,n)=>{if(!e)return[];const o=n.get(e.items),r=[];for(const a of o)r.push(...n.get(a.items));return r},[e])}function Hr(t,e={}){return he(e)}function Qr(t,e=!1){}function Ur(t,e=[]){const{id:i,selector:n}=t,o=N(),r=i||o.collection,a=P(s=>r?s.iiif.entities.Collection[r]:void 0,[r]);return v.useMemo(()=>{if(!!a)return n?n(a):a},[a,n,...e])}function Ut(){const e=C().getStore();return v.useMemo(()=>i=>e.dispatch(i),[e])}function Bt(t){return{addEventListener(e,i,n,o){if(e)return t.setMetaValue([e.id,"eventManager",i],r=>{const a=r||[];for(const s of a)if(s.callback===n)return a;return[...a,{callback:n,scope:o}]}),n},removeEventListener(e,i,n){!e||t.setMetaValue([e.id,"eventManager",i],o=>(o||[]).filter(r=>r.callback!==n))},getListenersAsProps(e,i){const n=typeof e=="string"?{id:e}:e;if(!n||!n.id)return{};const o=t.getResourceMeta(n.id,"eventManager"),r={};if(o&&n)for(const a of Object.keys(o))r[a]=s=>{const l=t.get(n);for(const{callback:u,scope:f}of o[a]||[])(!f||i&&f.indexOf(i)!==-1)&&u(s,l)};return r}}}function Br(t){return{applyStyles(e,i,n){const o=typeof e=="string"?e:e.id;return t.setMetaValue([o,"styles",i],n)},getAppliedStyles(e){const i=typeof e=="string"?e:e.id;return t.getResourceMeta(i,"styles")}}}function K(t){return t.endsWith("info.json")?t:t.endsWith("/")?`${t}info.json`:`${t}/info.json`}function Jr(t,e,i){const n=i.length,o=[];for(let r=0;r<n;r++){const a=i[r].width;o.push(t/a)}return o}function Kr(t,e,i){const n=i.length,o=[];for(let r=0;r<n;r++){const a=i[r];o.push({width:Math.floor(t/a),height:Math.floor(e/a)})}return o}const Yr="http://library.stanford.edu/iiif/image-api/compliance.html#level0",Jt="http://library.stanford.edu/iiif/image-api/compliance.html#level1",Kt="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Xr="http://library.stanford.edu/iiif/image-api/conformance.html#level0",Yt="http://library.stanford.edu/iiif/image-api/conformance.html#level1",Xt="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Zr="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Zt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",ei="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",eo="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",ti="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",ii="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",to="http://iiif.io/api/image/1/level0.json",io="http://iiif.io/api/image/1/profiles/level0.json",ni="http://iiif.io/api/image/1/level1.json",ri="http://iiif.io/api/image/1/profiles/level1.json",oi="http://iiif.io/api/image/1/level2.json",ai="http://iiif.io/api/image/1/profiles/level2.json",no="http://iiif.io/api/image/2/level0.json",ro="http://iiif.io/api/image/2/profiles/level0.json",si="http://iiif.io/api/image/2/level1.json",ci="http://iiif.io/api/image/2/profiles/level1.json",ui="http://iiif.io/api/image/2/level2.json",li="http://iiif.io/api/image/2/profiles/level2.json",oo="level0",fi="level1",hi="level2",ao="http://iiif.io/api/image/2/level0",di="http://iiif.io/api/image/2/level1",pi="http://iiif.io/api/image/2/level2",so=[di,pi,Jt,Kt,Yt,Xt,Zt,ei,ti,ii,ni,ri,oi,ai,si,ci,ui,li,fi,hi],co=[ao,di,pi,Yr,Jt,Kt,Xr,Yt,Xt,Zr,Zt,ei,eo,ti,ii,to,io,ni,ri,oi,ai,no,ro,si,ci,ui,li,oo,fi,hi];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 i of e)if(typeof i=="string"&&co.indexOf(i)!==-1)return!0;return!1}function uo(t){if(!Ee(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if(typeof i=="string"){if(so.indexOf(i)!==-1)return!0}else{const n=i.supports||[];if(n.indexOf("regionByPx")!==-1&&(n.indexOf("sizeByW")!==-1||n.indexOf("sizeByWh")!==-1))return!0}return!1}function lo(t){if(!uo(t))return[];const e=[],i=Array.isArray(t.profile)?t.profile:[t.profile],n=i.length;for(let o=0;o<n;o++){const r=i[o];if(typeof r!="string"&&(r.maxHeight||r.maxWidth))return[{id:_(t),type:"variable",minWidth:0,minHeight:0,maxHeight:r.maxHeight||r.maxWidth,maxWidth:r.maxWidth||r.maxHeight}]}if(t.tiles){const o=t.tiles.length;for(let r=0;r<o;r++){const a=t.tiles[r];(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 vi(t){const e=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,i=t.match(e);if(i){const n=i[1],o=parseInt(i[4],10),r=parseInt(i[5],10),a=i[7];if((n==="max"||n==="full")&&o&&r&&a)return{type:"fixed",id:t,height:r,width:o}}return{type:"unknown",id:t}}function fo(t){if(t["@type"])return t["@type"];if(t.type)return t.type}function Ae(t){if(typeof t=="string")return vi(t);const e=fo(t);if(e!=="Image"&&e!=="sc:Image")return null;const i=t,n=_(i);return n?n&&i.width&&i.height?{id:n,type:"fixed",width:i.width,height:i.height,unsafe:!0}:vi(n):null}function ho(t){return Ee(t)?(t&&t.sizes?t.sizes:[]).map(e=>({id:_(t),type:"fixed-service",height:e.height,width:e.width})):[]}function mi(t){const e=[],i=t.length;for(let n=0;n<i;n++){const o=ho(t[n]);o.length&&e.push(...o);const r=lo(t[n]);r.length&&e.push(...r)}return e}function gi(t){const e=t.service?Array.isArray(t.service)?t.service:[t.service]:[],i=e.length,n=[];for(let o=0;o<i;o++)Ee(e[o])&&n.push(e[o]);return n}function po(t,e=!0,i){const n=[],o=Ae(t);if(o===null)return n;const r=t;if(n.push(o),e&&r.width&&r.height){const a=[],s=gi(r);for(const l of s){const u={id:_(l),width:r.width,height:r.height};if(i.canLoadSync(u)){const f=i.loadServiceSync(u);f&&(f.height||(f.height=r.height),f.width||(f.width=r.width),a.push(...mi([f])))}}if(a.length)return n.push(...a),n}return r.service&&n.push(...mi(r.service)),n}function xe(t,e,i){return{id:[K(_(t)).slice(0,-10),"full",[e,i||""].join(","),0,"default.jpg"].join("/"),type:"fixed",width:e,height:i||t.height/t.width*e,unsafe:t.width>e}}function Y(t){const e=t.replace(/(https?:\/\/)?(www.)?/i,"");return e.indexOf("/")!==-1?e.split("/")[0]:e}function vo(t,e,i){const n=t.width?t.width:t.maxWidth;return i.height<=t.maxHeight&&i.width<=t.maxWidth&&i.height>=t.minHeight&&i.width>=t.minWidth&&(!e||Math.abs(i.width-n)<Math.abs(e.width-n))}function mo(t,e){const i=[],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=[],r=[];let a=null;const s=(u,f)=>{if(vo(n,f,u)){if(n.preferFixedSize&&u.unsafe){r.push(u);return}n.returnAllOptions&&f&&r.push(f),a=u}else n.returnAllOptions&&r.push(u)},l=e.length;for(let u=0;u<l;u++){const f=e[u](),h=f.length;for(let d=0;d<h;d++){const p=f[d];if(p.type==="unknown"&&n.atAnyCost&&o.push(p),p.type==="fixed"&&(p.unsafe?o.push(p):s(p,a)),p.type==="fixed-service")if(n.unsafeImageService){const c=xe(p,n.width,n.height);s(c,a)}else{const c=xe(p,p.width,p.height);s(c,a)}if(p.type==="variable"&&p.maxWidth){const c=xe({id:p.id,type:"fixed-service",width:p.maxWidth,height:p.maxWidth},p.maxWidth);s(c,a)}}if(a&&!n.returnAllOptions){if(a.unsafe||n.allowUnsafe)continue;break}}return n.atAnyCost&&r.length===0?{best:a||o[0],fallback:o.slice(1),log:i}:n.returnAllOptions?{best:n.atAnyCost?a||r[0]||o[0]:a||r[0],fallback:[...r,...o],log:i}:{best:a||r[0]||null,fallback:a?r:r.slice(1),log:i}}function go(t,e,i){const n=t>e?t:e,o=i.length,r=[];for(let a=0;a<o;a++){const s=i[a];let l=s.scaleFactors[0],u=n/l;const f=[l];for(;u>=s.width;)l=l*2,f.push(l),u=u/2;r.push(Object.assign(Object.assign({},s),{scaleFactors:f}))}return r}function yo(t,e){if(t.length!==e.length)return!1;if(t.length===0&&e.length===0)return!0;const i=t.length;let n=!0;for(let r=0;r<i;r++){const a=t[r],s=e[r];if(a.width!==s.width||a.height!==s.height){n=!1;break}}if(n)return!0;let o=0;for(let r=0;r<i;r++)for(let a=0;a<i;a++)if(t[r].width===e[a].width&&t[r].height===e[a].height){o++;break}return o===i}/*! *****************************************************************************
15
15
  Copyright (c) Microsoft Corporation. All rights reserved.
16
16
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use
17
17
  this file except in compliance with the License. You may obtain a copy of the
@@ -24,4 +24,4 @@
24
24
 
25
25
  See the Apache Version 2.0 License for specific language governing permissions
26
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})});
27
+ ***************************************************************************** */function X(t,e,i,n){function o(r){return r instanceof i?r:new i(function(a){a(r)})}return new(i||(i=Promise))(function(r,a){function s(f){try{u(n.next(f))}catch(h){a(h)}}function l(f){try{u(n.throw(f))}catch(h){a(h)}}function u(f){f.done?r(f.value):o(f.value).then(s,l)}u((n=n.apply(t,e||[])).next())})}class yi{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,i,n=!0){const o=Y(_(e)),r=K(_(e)),a=this.knownImageServers[o];return this.imageServices[r]=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:i&&e.height?i.height/e.height:1,sampledSizes:e.sizes||[],sizeRatios:Jr(e.width,e.height,e.sizes||[]),sampledTiles:e.tiles||[]}},!0)}preLoad(e,i=!0){this.knownImageServers[e.root]=e,i&&(this.knownImageServers[e.root].malformed=!1,this.knownImageServers[e.root].verifications=this.config.verificationsRequired)}predict(e,i=!1,n=!1){const o=Y(_(e)),r=this.knownImageServers[o];if(!r||!r.result||!n&&(r.malformed||r.verifications<this.config.verificationsRequired))return null;const a=K(_(e));return this.imageServices[a]||(this.imageServices[a]={"@context":r.result.context,"@id":_(e),id:_(e),protocol:"http://iiif.io/api/image",tiles:go(e.width,e.height,r.result.sampledTiles),sizes:Kr(Math.floor(e.width/r.result.resourceServiceRatio),Math.floor(e.height/r.result.resourceServiceRatio),r.result.sizeRatios),profile:r.result.sampledProfile,height:e.height,width:e.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(e,i,n=!0,o=[]){return X(this,void 0,void 0,function*(){const r=yield this.getImageCandidates(e,n);return mo(i,[()=>o,()=>r])})}getImageCandidates(e,i=!0){return X(this,void 0,void 0,function*(){const n=e;if(i&&n.height&&n.width){const o=gi(n);for(const r of o){const a={id:_(r),width:r.width?r.width:n.width,height:r.height?r.height:n.height};yield this.loadService(a)}}return po(e,i,this)})}verify(e){return X(this,void 0,void 0,function*(){const i=this.predict(e,!1,!0),n=yield this.fetchService(_(e));if(!i)return!1;const o=i.height===n.height&&i.width===n.width&&i["@context"]===n["@context"]&&yo(i.sizes||[],n.sizes||[]);if(o){const r=Y(_(e));this.knownImageServers[r].verifications+=1,this.knownImageServers[r].verifications>=this.config.verificationsRequired&&(this.knownImageServers[r].verified=!0)}return o})}canLoadSync(e){const i=typeof e=="string"?e:_(e),n=K(i);if(this.imageServices[n])return!0;const o=this.knownImageServers[Y(i)];return o&&!o.malformed&&o.verifications>=this.config.verificationsRequired}markAsMalformed(e){return X(this,void 0,void 0,function*(){return this.knownImageServers[Y(_(e))].malformed=!0,this.loadService(e,!0)})}fetchService(e,i=!1){return X(this,void 0,void 0,function*(){const n=K(e);if(this.imageServices[n]&&(!i||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(r=>r.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,i=!1){return X(this,void 0,void 0,function*(){if(!this.config.disableThrottling)for(;this.fetchingCount>=this.config.verificationsRequired;)yield new Promise(r=>setTimeout(r,500));const n=this.knownImageServers[Y(_(e))];if(n&&!n.malformed&&!i){yield n.result;const r=this.loadServiceSync(e);if(r)return r}this.fetchingCount++;const o=yield this.fetchService(_(e),i);return this.fetchingCount--,o.real&&this.sample(o,e),o})}loadServiceSync(e){const i=K(_(e));return this.imageServices[i]?this.imageServices[i]:this.predict(e)}}new yi;function wo(t,e={}){const i=e.imageServiceLoader||new yi;async function n(o,r,a,s=[],l){if(typeof o=="string")return{best:Ae(o),fallback:[],log:[]};const u=t.get(o);if(typeof u=="string")return{best:Ae(u),fallback:[],log:[]};switch(u.type){case"Annotation":{const f=u.body,h=t.get(f[0]);return l&&!h.width&&(h.width=l.width,h.height=l.height),await i.getThumbnailFromResource(h,r,a,s)}case"Canvas":{const f=u;if(f.thumbnail&&f.thumbnail.length){const h=t.get(f.thumbnail[0]),d=await i.getImageCandidates(h,a);d&&d.length&&s.push(...d)}return n(f.items[0],r,a,s,{width:f.width,height:f.height})}case"AnnotationPage":return n(u.items[0],r,a,s,l);case"Choice":return n(u.items[0],r,a,s,l);case"Collection":{const f=u.items[0];return n(f,r,a,s,l)}case"Manifest":{const f=u.items[0];return n(f,r,a,s,l)}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return l&&!u.width&&(u.width=l.width,u.height=l.height),i.getThumbnailFromResource(u,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:n}}function So(t,e,i,n,o=[]){const r=C(),a=v.useMemo(()=>Bt(r),[r]);v.useEffect(()=>{const s=t;return s?(a.addEventListener(s,e,i,n),()=>{a.removeEventListener(s,e,i)}):()=>{}},[a,t,e,...o])}function Io(){const t=v.useContext(Z);return t&&t.vault?t.vault:ae.globalVault()}var _o=Object.defineProperty,wi=Object.getOwnPropertySymbols,bo=Object.prototype.hasOwnProperty,Co=Object.prototype.propertyIsEnumerable,Si=(t,e,i)=>e in t?_o(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Oo=(t,e)=>{for(var i in e||(e={}))bo.call(e,i)&&Si(t,i,e[i]);if(wi)for(var i of wi(e))Co.call(e,i)&&Si(t,i,e[i]);return t},Eo=(t,e,i)=>new Promise((n,o)=>{var r=l=>{try{s(i.next(l))}catch(u){o(u)}},a=l=>{try{s(i.throw(l))}catch(u){o(u)}},s=l=>l.done?n(l.value):Promise.resolve(l.value).then(r,a);s((i=i.apply(t,e)).next())});const Ao=(t,e={})=>{const i=C(),[n,o]=v.useState(t),r=v.useMemo(()=>i.get(t),[t,i]),{data:a,isFetching:s}=_e(`collection:${t}`,()=>Eo(void 0,null,function*(){const l=r||(yield i.loadCollection(t));return l&&o(l.id),l}),Oo({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,initialData:r},e));return{isLoaded:!s,id:n,collection:a}};var xo=(t,e,i)=>new Promise((n,o)=>{var r=l=>{try{s(i.next(l))}catch(u){o(u)}},a=l=>{try{s(i.throw(l))}catch(u){o(u)}},s=l=>l.done?n(l.value):Promise.resolve(l.value).then(r,a);s((i=i.apply(t,e)).next())});function Ii(){const t=J(),e=he(),i=C(),n=le();return _e(`canvas-first-image-service:${t?t.id:"undefined"}`,()=>xo(this,null,function*(){if(t&&e.length){const o=e[0],r=i.get(o.body[0]),s=re(r)[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],r=i.get(o.body[0]),s=re(r)[0];return s&&n.loadServiceSync({id:s.id||s["@id"],width:s.width||t.width,height:s.height||t.height})||void 0}}})}function Po(){const t=Ii();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 _i(t,e=[]){const i=C(),n=he(),[o,r]=v.useState((t==null?void 0:t.defaultChoices)||[]),a=v.useMemo(()=>$t(i,n,o),[i,n,o,...e]),l={makeChoice:v.useCallback((u,{deselectOthers:f=!0,deselect:h=!1}={})=>{if(a.choice){if(a.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");r(d=>{if(h){const c=d.filter(m=>m!==u);if(c.length===0){const m=a.items[0].resource.id;return m?[m]:[]}return c}if(f)return[u];const p=[...d];if(p.length===0&&a.items.length){const c=a.items[0].resource.id;c&&p.push(c)}return d.indexOf(u)!==-1?d:[...d,u]})}},[a.choice])};return[a,l]}function Mo(t={},e=[]){const{id:i,selector:n}=t,o=N(),r=i||o.range,a=P(s=>r?s.iiif.entities.Range[r]:void 0,[r]);return v.useMemo(()=>{if(!!a)return n?n(a):a},[a,n,...e])}function Lo(t,e){const i=C(),n=v.useMemo(()=>Bt(i),[i]),o=P(()=>t&&t.id?i.getResourceMeta(t.id,"eventManager"):null,[t]);return v.useMemo(()=>t?n.getListenersAsProps(t,e):{},[o,t,i,e])}function bi(t,e){return P((i,n)=>n.get(t.map(o=>({id:o,type:e}))),[t,e])}function Fo(){const t=oe();return t?t.service.find(e=>e.profile==="SearchService1"||e.profile==="http://iiif.io/api/search/1/search"):void 0}function To(t,e){const i=C(),n=v.useMemo(()=>Br(i),[i]);return P(()=>{if(!t)return null;const o=n.getAppliedStyles(t.id);return o?e?o[e]:o:void 0},[t,e])}const Ci=(t,e=[])=>{const i=C();v.useEffect(()=>{t(i)},[i,...e])};function jo(t,e,{canvasId:i,manifestId:n}={}){const o=C(),r=le(),a=v.useMemo(()=>wo(o,{imageServiceLoader:r}),[o,r]),[s,l]=v.useState(),u=oe(n?{id:n}:void 0),f=J(i?{id:i}:void 0),h=f||u,d=v.useRef(!1);if(v.useEffect(()=>()=>{d.current=!0},[]),!h)throw new Error("Must be called under a manifest or canvas context.");return Ci(p=>{a.getBestThumbnailAtSize(h,t,e).then(c=>{c.best&&!d.current&&l(c.best)})},[h]),s}var Ro=Object.defineProperty,$o=Object.defineProperties,ko=Object.getOwnPropertyDescriptors,Oi=Object.getOwnPropertySymbols,Vo=Object.prototype.hasOwnProperty,Do=Object.prototype.propertyIsEnumerable,Ei=(t,e,i)=>e in t?Ro(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ai=(t,e)=>{for(var i in e||(e={}))Vo.call(e,i)&&Ei(t,i,e[i]);if(Oi)for(var i of Oi(e))Do.call(e,i)&&Ei(t,i,e[i]);return t},xi=(t,e)=>$o(t,ko(e));function Pi(){const t=le(),[e,i]=v.useState({}),n=v.useRef(!1);return v.useEffect(()=>()=>{n.current=!0},[]),[v.useCallback((r,{height:a,width:s})=>{if(r){const l=r.id||r["@id"],u=t.loadServiceSync({id:l,width:r.width||s,height:r.height||a});u?r=u:e[l]||(n.current||i(f=>xi(Ai({},f),{[l]:"loading"})),t.loadService({id:l,width:r.width||s,height:r.height||a}).then(()=>{n.current||i(f=>xi(Ai({},f),{[l]:"done"}))}))}return r},[t,e]),e]}function Mi(t){return t==null}function Li(t){throw new Error("Argument "+t+" is empty.")}function qo(t){return typeof t=="string"||typeof t=="symbol"}function Fi(t){return!qo(t)}function Ti(t){throw new Error("Argument "+t+" is invalid, it should be an action type of type: string | symbol")}function No(t,e){return Mi(t)&&Li(1),Fi(t)&&Ti(1),Object.assign(function(){var i=e!=null?e.apply(void 0,arguments):void 0;return Object.assign({type:t},i)},{getType:function(){return t},toString:function(){return t}})}function O(t,e,i){return Mi(t)&&Li(1),Fi(t)&&Ti(1),function(){return No(t,function(){var n=arguments.length<=0?void 0:arguments[0],o=arguments.length<=1?void 0:arguments[1];return e==null&&i==null||(n=e!=null?e.apply(void 0,arguments):void 0,o=i!=null?i.apply(void 0,arguments):void 0),Object.assign({},n!==void 0&&{payload:n},{},o!==void 0&&{meta:o})})}}const Wo="@iiif/IMPORT_ENTITIES",zo="@iiif/MODIFY_ENTITY_FIELD",Go="@iiif/REORDER_ENTITY_FIELD",Ho="@iiif/ADD_REFERENCE",Qo="@iiif/REMOVE_REFERENCE",Uo=O(Wo)(),Bo=O(zo)(),Jo=O(Go)(),Ko=O(Ho)(),Yo=O(Qo)(),Pe={importEntities:Uo,modifyEntityField:Bo,reorderEntityField:Jo,addReference:Ko,removeReference:Yo},Xo="@iiif/ADD_MAPPING",Zo="@iiif/ADD_MAPPINGS";O(Xo)(),O(Zo)();const ea="@iiif/SET_META_VALUE",ta="@iiif/SET_META_VALUE_DYNAMIC",ia="@iiif/UNSET_META_VALUE";O(ea)(),O(ta)(),O(ia)();const na="@iiif/REQUEST_RESOURCE",ra="@iiif/REQUEST_ERROR",oa="@iiif/REQUEST_MISMATCH",aa="@iiif/REQUEST_COMPLETE",sa="@iiif/REQUEST_OFFLINE_RESOURCE";O(na)(),O(ra)(),O(oa)(),O(aa)(),O(sa)(),O("@iiif/BATCH")();const ca={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:[]},ji=["sc:Collection","sc:Manifest","sc:Canvas","oa:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function ua(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=ji.indexOf(t["@type"]);if(e!==-1)return ji[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}class Me{traversals;options;constructor(e,i={}){this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...i}}static all(e){return new Me({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 i=[...(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=i}return e.manifests&&(e.manifests=e.manifests.map(i=>this.traverseManifest(typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i))),e.collections&&(e.collections=e.collections.map(i=>this.traverseCollection(typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i))),e.members&&(e.members=e.members.map(i=>typeof i=="string"?i:this.traverseUnknown(i))),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(i=>this.traverseSequence(i))),e.structures&&(e.structures=e.structures.map(i=>this.traverseRange(i))),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(i=>this.traverseCanvas(i))),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(i=>this.traverseAnnotation(i))),e.otherContent&&(e.otherContent=e.otherContent.map(i=>this.traverseAnnotationList(i))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const i=[...(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=i.length?i.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(i=>this.traverseAnnotation(i))),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(i=>this.traverseAnnotationList(i))),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(i=>this.traverseContentResource(i))),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(ua(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 i=Array.isArray(e),n=Array.isArray(e)?e:[e],o=[];for(const r of n)typeof r=="string"?o.push(this.traverseContentResource({"@id":r,"@type":"dctypes:Image"})):o.push(this.traverseContentResource(r));return!i&&!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 i=Array.isArray(e),n=Array.isArray(e)?e:[e],o=[];for(const r of n)o.push(this.traverseService(r));return!i&&!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,i){if(!Array.isArray(e))if(this.options.convertPropsToArray)e=[e];else return this.traverseType(e,i);return e.map(n=>this.traverseType(n,i))}traverseType(e,i){return i.reduce((n,o)=>{const r=o(n);return typeof r>"u"&&!this.options.allowUndefinedReturn?n:r},e)}}const la="http://library.stanford.edu/iiif/image-api/compliance.html#level0",Ri="http://library.stanford.edu/iiif/image-api/compliance.html#level1",$i="http://library.stanford.edu/iiif/image-api/compliance.html#level2",fa="http://library.stanford.edu/iiif/image-api/conformance.html#level0",ki="http://library.stanford.edu/iiif/image-api/conformance.html#level1",Vi="http://library.stanford.edu/iiif/image-api/conformance.html#level2",ha="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Di="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",qi="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",da="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Ni="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Wi="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",pa="http://iiif.io/api/image/1/level0.json",va="http://iiif.io/api/image/1/profiles/level0.json",zi="http://iiif.io/api/image/1/level1.json",Gi="http://iiif.io/api/image/1/profiles/level1.json",Hi="http://iiif.io/api/image/1/level2.json",Qi="http://iiif.io/api/image/1/profiles/level2.json",ma="http://iiif.io/api/image/2/level0.json",ga="http://iiif.io/api/image/2/profiles/level0.json",Ui="http://iiif.io/api/image/2/level1.json",Bi="http://iiif.io/api/image/2/profiles/level1.json",Ji="http://iiif.io/api/image/2/level2.json",Ki="http://iiif.io/api/image/2/profiles/level2.json",ya="level0",Yi="level1",Xi="level2",wa="http://iiif.io/api/image/2/level0",Zi="http://iiif.io/api/image/2/level1",en="http://iiif.io/api/image/2/level2",Sa=[Zi,en,Ri,$i,ki,Vi,Di,qi,Ni,Wi,zi,Gi,Hi,Qi,Ui,Bi,Ji,Ki,Yi,Xi],Ia=[wa,Zi,en,la,Ri,$i,fa,ki,Vi,ha,Di,qi,da,Ni,Wi,pa,va,zi,Gi,Hi,Qi,ma,ga,Ui,Bi,Ji,Ki,ya,Yi,Xi],Le={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function z(t,e="none"){if(!t)return{};const i=Array.isArray(t)?t:[t],n={};for(const o of i){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 r=o["@language"];n[r]=n[r]?n[r]:[],n[r].push(o["@value"]||"")}return n}function tn(t){if(Array.isArray(t))return tn(t.find(e=>typeof e=="string"));if(Ia.indexOf(t)!==-1)return"level2";if(Sa.indexOf(t)!==-1)return"level1";if(typeof t=="string")return t}function _a(t){const e=Array.isArray(t)?t:[t];for(const i of e)switch(i){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 ba(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 Ca(t){return Array.isArray(t)?t:[t]}function Oa(t){for(const e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}function Fe(t){const e=t["@id"]||t.id;let i=t["@type"]||t.type;const n=t.profile||void 0,o=t["@context"]||void 0;if(n){const r=ba(n);if(r)return r}if(o){const r=_a(o);if(r)return r}if(i){if(Array.isArray(i)){if(i.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(i.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";i=i[0]}for(const r of["sc","oa","dcterms","dctypes","iiif"])if(i.startsWith(`${r}:`)){i=i.slice(r.length+1);break}switch(i){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":i||"unknown"}const Ea=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Aa(t){const e=t.match(Ea);return e?e[0]:t}function xa(t,e="Rights/License",i="none"){let n=null;const o=[],r=Array.isArray(t)?t:[t];for(const a of r){const s=a?Aa(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:{[i]:[e]},value:{[i]:[s]}})}return[n,o]}const Pa=["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 Ma(t){if(t){const e=Array.isArray(t)?t:[t],i=[];for(const n of e)n==="http://iiif.io/api/presentation/2/context.json"&&i.push("http://iiif.io/api/presentation/3/context.json"),Pa.indexOf(n)===-1&&i.push(n);if(e.length)return i.length===1?i[0]:i}}function La(t){return t?t.map(e=>({label:z(e.label),value:z(e.value)})):[]}function $(t){for(const e in t)(typeof t[e]>"u"||t[e]===null)&&delete t[e];return t}let nn=0;function rn(t,e){const i=encodeURI(t.id||t["@id"]||"").trim();return i&&e?`${i}/${e}`:i||(nn++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${nn}`)}function k(t){const e=[...t.behavior||[]];return t.viewingHint&&e.push(t.viewingHint),{"@context":t["@context"]?Ma(t["@context"]):void 0,id:(t["@id"]||rn(t)).trim(),type:Fe(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:t.motivation?Oa(t.motivation):void 0,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function T(t){const[e,i]=xa(t.license),n=[...t.metadata?La(t.metadata):[],...i];return{rights:e,metadata:n.length?n:void 0,label:t.label?z(t.label):void 0,requiredStatement:t.attribution?{label:z(Le.attributionLabel),value:z(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?z(t.description):void 0,thumbnail:t.thumbnail}}function Fa(t){if(!t.within)return;const e=Array.isArray(t.within)?t.within:[t.within],i=[];for(const n of e)if(typeof n=="string"){if(n)switch(t["@type"]){case"sc:Manifest":i.push({id:n,type:"Collection"});break}}else n["@id"]&&i.push({id:n["@id"],type:Fe(n)});return i.length?i:void 0}function D(t){const e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],i=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:z(Le.providerName)}]:void 0,partOf:Fa(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?Ca(t.service):void 0,supplementary:i?[i]:void 0}}function Ta(t){return $({...k(t),...T(t),...D(t),items:t.members})}function ja(t){const e=[],i=[];for(const o of t.sequences||[])o.canvases.length&&e.push(...o.canvases),o.behavior&&i.push(...o.behavior);const n=k(t);return i.length&&(n.behavior?n.behavior.push(...i):n.behavior=i),$({...n,...T(t),...D(t),items:e,structures:t.structures})}function Ra(t){return $({...k(t),...T(t),...D(t),items:t.images&&t.images.length?[{id:rn(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function $a(t){return $({...k(t),...T(t),...D(t),items:t.resources})}function ka(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[]}}function Va(t){return $({...k(t),...T(t),...D(t),target:typeof t.on=="string"?encodeURI(t.on).trim():t.on,body:t.resource})}function Da(t){const e=t;return $({...k(e),...T(e),...D(e)})}function qa(t){const e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),{...k(t),...T(t),items:e}}function Na(t){return $({...k(t),...T(t),...D(t),items:t.members})}function Wa(t){const{"@id":e,"@type":i,"@context":n,profile:o,...r}=t;return e&&(r.id=e),r.type=Fe(t),r.type==="unknown"&&(r.type="Service"),o&&(r.profile=tn(o)),$({...r,...T(r)})}function za(t){return $({...k(t),...T(t),...D(t)})}new Me({collection:[Ta],manifest:[ja],canvas:[Ra],annotationList:[$a],sequence:[ka],annotation:[Va],contentResource:[Da],choice:[qa],range:[Na],service:[Wa],layer:[za]});var Ga=Object.defineProperty,Ha=Object.defineProperties,Qa=Object.getOwnPropertyDescriptors,on=Object.getOwnPropertySymbols,Ua=Object.prototype.hasOwnProperty,Ba=Object.prototype.propertyIsEnumerable,an=(t,e,i)=>e in t?Ga(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ja=(t,e)=>{for(var i in e||(e={}))Ua.call(e,i)&&an(t,i,e[i]);if(on)for(var i of on(e))Ba.call(e,i)&&an(t,i,e[i]);return t},Ka=(t,e)=>Ha(t,Qa(e));function sn(t){return typeof t!="string"&&t&&t.bindToVault}function Ya(){const t=C(),e=v.useRef([]),i=Ut(),n=v.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);v.useLayoutEffect(()=>{const s=Ka(Ja({},ca),{id:n,items:[]});i(Pe.importEntities({entities:{AnnotationPage:{[s.id]:s}}}))},[n]);const o=P(s=>n?s.iiif.entities.AnnotationPage[n]:null,[n]),r=v.useCallback((s,l)=>{if(n){if(sn(s)){const h=s;h.__vault||h.bindToVault(t),s=typeof h.source=="string"?h.source:h.source.id,e.current[s]=h}else typeof s!="string"&&(s=s.id);const u=t.get({id:n,type:"AnnotationPage"}),f=t.get({id:s,type:"Annotation"});u&&f&&(u.items.find(h=>h.id===f.id)||i(Pe.addReference({id:n,type:"AnnotationPage",key:"items",reference:{id:s,type:"Annotation"},index:l})))}},[n]),a=v.useCallback(s=>{n&&(sn(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"})&&i(Pe.removeReference({id:n,type:"AnnotationPage",key:"items",reference:{id:s,type:"Annotation"}})))},[n]);return[o,{addAnnotation:r,removeAnnotation:a}]}var Xa=Object.defineProperty,Za=Object.defineProperties,es=Object.getOwnPropertyDescriptors,cn=Object.getOwnPropertySymbols,ts=Object.prototype.hasOwnProperty,is=Object.prototype.propertyIsEnumerable,un=(t,e,i)=>e in t?Xa(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,ns=(t,e)=>{for(var i in e||(e={}))ts.call(e,i)&&un(t,i,e[i]);if(cn)for(var i of cn(e))is.call(e,i)&&un(t,i,e[i]);return t},rs=(t,e)=>Za(t,es(e));function os(t){const e=oe(),i=J(),n=C(),[o,r]=Pi(),{enabledPageIds:a}=Qt((t==null?void 0:t.annotationPageManagerId)||(e==null?void 0:e.id),{all:!1}),s=bi(a,"AnnotationPage"),l=(t==null?void 0:t.strategies)||["images","media","complex-timeline"],[u,f]=_i(t,[r]),h=v.useMemo(()=>{if(!i||u.types.length===0)return Oe;if(u.types.length!==1)return l.indexOf("complex-timeline")===-1?R("Complex timeline not supported"):R("ComplexTimelineStrategy not yet supported");const d=u.types[0];return d==="image"?l.indexOf("images")===-1?R("Image not supported"):Vt(i,u,o):d==="audio"?l.indexOf("media")===-1?R("Media not supported"):R("Audio strategy not yet supported"):d==="video"?l.indexOf("media")===-1?R("Media not supported"):R("Video strategy not yet supported"):Oe},[i,u,n,f.makeChoice]);return v.useMemo(()=>h.type==="unknown"?[h,kt]:[rs(ns({},h),{annotations:{pages:s}}),f],[h,s])}g.AnnotationContext=vn,g.CanvasContext=ke,g.CollectionContext=mn,g.ContextBridge=Yn,g.ImageServiceLoaderContext=Mt,g.ManifestContext=Ve,g.RangeContext=gn,g.ReactVaultContext=Z,g.ResourceProvider=W,g.ResourceReactContext=se,g.SimpleViewerProvider=Bn,g.SimpleViewerReactContext=ne,g.VaultProvider=De,g.VisibleCanvasReactContext=ie,g.emptyActions=kt,g.expandTarget=V,g.flattenAnnotationPageIds=Nt,g.getImageStrategy=Vt,g.getPaintables=$t,g.parseSelector=fe,g.parseSpecificResource=Rt,g.unknownResponse=Oe,g.unsupportedStrategy=R,g.useAnnotation=$r,g.useAnnotationPageManager=Qt,g.useAnnotationsAtTime=Hr,g.useCanvas=J,g.useCanvasClock=Qr,g.useCollection=Ur,g.useContextBridge=Kn,g.useDispatch=Ut,g.useEventListener=So,g.useExistingVault=Io,g.useExternalCollection=Ao,g.useExternalManifest=ot,g.useImageService=Ii,g.useImageServiceLoader=le,g.useImageTile=Po,g.useLoadImageService=Pi,g.useManifest=oe,g.usePaintables=_i,g.usePaintingAnnotations=he,g.useRange=Mo,g.useRenderingStrategy=os,g.useResourceContext=N,g.useResourceEvents=Lo,g.useResources=bi,g.useSearchService=Fo,g.useSimpleViewer=Jn,g.useStyles=To,g.useThumbnail=jo,g.useVault=C,g.useVaultEffect=Ci,g.useVaultSelector=P,g.useVirtualAnnotationPage=Ya,g.useVisibleCanvases=at,Object.defineProperty(g,"__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.2",
4
4
  "main": "./dist/cjs/index.js",
5
5
  "module": "./dist/esm/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -24,14 +24,14 @@
24
24
  },
25
25
  "license": "MIT",
26
26
  "resolutions": {
27
- "@iiif/vault": "^0.9.9",
27
+ "@iiif/vault": "^0.9.14",
28
28
  "@iiif/presentation-3": "^1.0.4"
29
29
  },
30
30
  "dependencies": {
31
31
  "@atlas-viewer/iiif-image-api": "^1.2.6",
32
32
  "@iiif/presentation-2": "^1.0.1",
33
33
  "@iiif/presentation-3": "^1.0.4",
34
- "@iiif/vault": "^0.9.9",
34
+ "@iiif/vault": "^0.9.14",
35
35
  "@iiif/vault-helpers": "^0.9.4",
36
36
  "react": "^16.10.2 || ^17.0.1",
37
37
  "react-dom": "^16.10.2 || ^17.0.1",
@@ -44,7 +44,7 @@
44
44
  "@rollup/plugin-replace": "^3.0.1",
45
45
  "@testing-library/react": "^12.1.2",
46
46
  "@testing-library/react-hooks": "^7.0.2",
47
- "@types/jest": "^27.4.0",
47
+ "@types/jest": "^27.4.1",
48
48
  "@types/react": "^17.0.39",
49
49
  "@types/react-dom": "^17.0.11",
50
50
  "@typescript-eslint/eslint-plugin": "^5.11.0",
@@ -52,7 +52,8 @@
52
52
  "eslint": "^8.8.0",
53
53
  "eslint-plugin-json": "^3.1.0",
54
54
  "eslint-plugin-prettier": "^4.0.0",
55
- "jest": "^27.5.0",
55
+ "jest": "^27.5.1",
56
+ "jest-environment-jsdom": "^27.5.1",
56
57
  "prettier": "^2.5.1",
57
58
  "react": "^16.10.2 || ^17.0.1",
58
59
  "react-dom": "^16.10.2 || ^17.0.1",