react-iiif-vault 0.9.2 → 0.9.5

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 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
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var u=require("react"),D=require("@iiif/vault"),j=require("@atlas-viewer/iiif-image-api"),M=require("@iiif/vault-helpers"),y=require("typesafe-actions");function Re(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var g=Re(u),Me=Object.defineProperty,z=Object.getOwnPropertySymbols,Te=Object.prototype.hasOwnProperty,Ve=Object.prototype.propertyIsEnumerable,Y=(e,t,n)=>t in e?Me(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,G=(e,t)=>{for(var n in t||(t={}))Te.call(t,n)&&Y(e,n,t[n]);if(z)for(var n of z(t))Ve.call(t,n)&&Y(e,n,t[n]);return e};const $e={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},F=g.default.createContext($e),b=()=>u.useContext(F),I=({value:e,children:t})=>{const n=b(),r=u.useMemo(()=>G(G({},n),e),[e,n]);return g.default.createElement(F.Provider,{value:r},t)},Le=({annotation:e,children:t})=>g.default.createElement(I,{value:{annotation:e}},t),X=({canvas:e,children:t})=>g.default.createElement(I,{value:{canvas:e}},t),De=({collection:e,children:t})=>g.default.createElement(I,{value:{collection:e}},t),J=({manifest:e,children:t})=>g.default.createElement(I,{value:{manifest:e}},t),je=({range:e,children:t})=>g.default.createElement(I,{value:{range:e}},t),T=g.default.createContext({vault:null,setVaultInstance:e=>{}}),W=({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:a})=>{const[i,s]=u.useState(()=>e||(n?D.globalVault(t):t?new D.Vault(t):new D.Vault));return g.default.createElement(T.Provider,{value:{vault:i,setVaultInstance:s}},g.default.createElement(I,{value:r||{}},a))},S=()=>{const{vault:e}=u.useContext(T);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var Fe=(e,t,n)=>new Promise((r,a)=>{var i=c=>{try{o(n.next(c))}catch(l){a(l)}},s=c=>{try{o(n.throw(c))}catch(l){a(l)}},o=c=>c.done?r(c.value):Promise.resolve(c.value).then(i,s);o((n=n.apply(e,t)).next())});function H(e,{noCache:t=!1}={}){const n=typeof e=="string"?e:e.id,r=S(),[a,i]=u.useState(n),[s,o]=u.useState(void 0),c=u.useMemo(()=>r.get(n,{skipSelfReturn:!0})||void 0,[n,r]),[l,p]=u.useState(c);return u.useEffect(()=>{Fe(this,null,function*(){try{const f=c&&!t?c:yield r.load(n),v=f?f.id||f["@id"]:null;f&&a!==v&&i(v),p(f)}catch(f){o(f)}})},[n,t]),{isLoaded:!!l,id:a,requestId:n,error:s,resource:l,cached:!!(l&&l===c)}}function Z(e,t){const{id:n,isLoaded:r,error:a,resource:i,requestId:s,cached:o}=H(e,t);return{id:n,isLoaded:r,error:a,manifest:i,requestId:s,cached:o}}function P(e,t=[]){const n=S(),[r,a]=u.useState(()=>e(n.getState(),n));return u.useEffect(()=>n.subscribe(i=>e(i,n),i=>{a(i)},!1),t),r}const V=g.default.createContext([]);function K(){const e=u.useContext(V);return P(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}const k=()=>{},$=u.createContext({setCurrentCanvasId:k,setCurrentCanvasIndex:k,nextCanvas:k,previousCanvas:k,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),ke=e=>{const t=Z(e.manifest),[n,r]=u.useState(""),[a,i]=u.useState([]),s=(typeof e.pagingEnabled>"u"||e.pagingEnabled)&&t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");u.useEffect(()=>{var d,m;t.manifest&&(r((d=t.manifest.items[0])==null?void 0:d.id),i([(m=t.manifest.items[0])==null?void 0:m.id]))},[t.manifest,e.manifest]);const o=u.useMemo(()=>{var d;return((d=t.manifest)==null?void 0:d.items.map(m=>m.id))||[]},[t.manifest,e.manifest]),c=u.useMemo(()=>o.indexOf(n),[o,n]),l=u.useCallback(()=>{if(o.length&&n){if(c===-1||(o[c+2]?c+2===o.length:c===o.length))return;const d=s&&c!==0?o[c+2]:o[c+1],m=s?c!==0?o[c+3]:o[c+2]:null;d&&(r(d),i(m?[d,m]:[d]))}},[s,o,n,c]),p=u.useCallback(()=>{if(o.length&&n){if(c===0||c===-1)return;const d=s&&c!==1?o[c-2]:o[c-1],m=s&&c!==1?o[c-1]:null;d&&(r(d),i(m?[d,m]:[d]))}},[s,o,n,c]),f=u.useCallback(d=>{const m=s&&d%2===1?d-1:d,_=o[m],A=s&&m!==0?o[m+1]:null;_&&(r(_),i(O=>{const C=A?[_,A]:[_];if(O.length===O.length){for(let w=0;w<O.length;w++)if(O[w]!==C[w])return C;return O}return C}))},[s,o]),v=u.useCallback(d=>{const m=o.indexOf(d);m!==-1&&f(m)},[o,f]),h=u.useMemo(()=>({setCurrentCanvasId:v,nextCanvas:l,previousCanvas:p,currentCanvasIndex:c,totalCanvases:o.length,setCurrentCanvasIndex:f,pagingView:!0}),[l,p,c,o,f,v]);return t.manifest?t.isLoaded?g.default.createElement($.Provider,{value:h},g.default.createElement(V.Provider,{value:a},g.default.createElement(J,{manifest:t.manifest.id},g.default.createElement(X,{canvas:n},e.children)))):g.default.createElement("div",null,"Loading..."):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),g.default.createElement("div",null,"Sorry, something went wrong."))};function Be(){return u.useContext($)}function Ne(){return{VaultContext:u.useContext(T),ResourceContext:u.useContext(F),SimpleViewerReactContext:u.useContext($),VisibleCanvasReactContext:u.useContext(V)}}const Ue=e=>g.default.createElement(W,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},g.default.createElement(V.Provider,{value:e.bridge.VisibleCanvasReactContext},g.default.createElement($.Provider,{value:e.bridge.SimpleViewerReactContext},e.children))),ee=g.default.createContext(new j.ImageServiceLoader);function B(){return u.useContext(ee)}const He=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,qe=/&?(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:a}=N(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?N({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=He.exec(e.value);if(t){const r={type:"BoxSelector",spatial:{unit:t[2]==="percent:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:r,selectors:[r]}}const n=e.value.match(qe);if(n){const r={type:"TemporalSelector",temporal:{startTime:n[4]?parseFloat(n[4]):0,endTime:n[7]?parseFloat(n[7]):void 0}};return{selector:r,selectors:[r]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}var Qe=Object.defineProperty,ze=Object.defineProperties,Ye=Object.getOwnPropertyDescriptors,te=Object.getOwnPropertySymbols,Ge=Object.prototype.hasOwnProperty,Xe=Object.prototype.propertyIsEnumerable,ne=(e,t,n)=>t in e?Qe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,re=(e,t)=>{for(var n in t||(t={}))Ge.call(t,n)&&ne(e,n,t[n]);if(te)for(var n of te(t))Xe.call(t,n)&&ne(e,n,t[n]);return e},oe=(e,t)=>ze(e,Ye(t));function x(e,t={}){if(Array.isArray(e))return x(e[0]);if(typeof e=="string"){const[n,r]=e.split("#");return r?x({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 x(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?x({type:"SpecificResource",source:oe(re({},e),{id:n}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:oe(re({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function ie(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function se(e,t,n){const r=[];let a=null;const i=[];for(const s of t){const o=e.get(s.body);for(const c of o){const[l,{selector:p}]=ie(c),f=(l.type||"unknown").toLowerCase();if(f==="choice"){const v=e.get(l.items),h=n.length?n.map(d=>v.find(m=>m.id===d)).filter(Boolean):[v[0]];h.length===0&&h.push(v[0]),a={type:"single-choice",items:v.map(d=>({id:d.id,label:d.label,selected:h.indexOf(d)!==-1})),label:c.label},o.push(...h);continue}r.indexOf(f)===-1&&r.push(f),i.push({type:f,resource:l,target:s.target,selector:p})}}return{types:r,items:i,choice:a}}const ae={makeChoice:()=>{}},q={type:"unknown"},E=e=>({type:"unknown",reason:e,annotations:{pages:[]}});function ce(e,t,n){const r=[];for(const a of t.items){const i=a.resource&&a.resource.type==="SpecificResource"?a.resource.source:a.resource;if(!i.id)return E("No resource Identifier");let s;if(i.service){const m=j.getImageServices(i);m[0]&&(s=n(m[0],e))}const{selector:o,source:c}=x(a.target);if(c.id!==e.id)continue;const l={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},p=o?o.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:o.temporal,spatial:l.spatial}:o:null,f={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},v=a.resource.type==="SpecificResource"?x(a.resource):null,h=v&&v.selector&&(v.selector.type==="BoxSelector"||v.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:v.selector.spatial.x,y:v.selector.spatial.y,width:v.selector.spatial.width,height:v.selector.spatial.height}}:f,d={id:i.id,type:"Image",width:p?i.width:e.width,height:p?i.height:e.height,service:s,sizes:s&&s.sizes?s.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:p&&p.type!=="PointSelector"?p:l,selector:h};r.push(d)}return{type:"images",image:r[0],images:r,choice:t.choice}}var Je=Object.defineProperty,We=Object.defineProperties,Ze=Object.getOwnPropertyDescriptors,ue=Object.getOwnPropertySymbols,Ke=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable,le=(e,t,n)=>t in e?Je(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,tt=(e,t)=>{for(var n in t||(t={}))Ke.call(t,n)&&le(e,n,t[n]);if(ue)for(var n of ue(t))et.call(t,n)&&le(e,n,t[n]);return e},nt=(e,t)=>We(e,Ze(t));function rt(e={},t=[]){const{id:n,selector:r}=e,a=b(),i=S(),s=n||a.annotation,o=P(l=>s?l.iiif.entities.Annotation[s]:void 0,[s]),c=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=nt(tt({},o),{body:c,target:x(o.target,{typeMap:i.getState().iiif.mapping})});return r?r(l):l},[o,r,c,...t])}function L(e={},t=[]){const{id:n,selector:r}=e,a=b();S();const i=n||a.manifest,s=P(o=>i?o.iiif.entities.Manifest[i]:void 0,[i]);return u.useMemo(()=>{if(!!s)return r?r(s):s},[s,r,...t])}function R(e={},t=[]){const{id:n,selector:r}=e,a=b(),i=n||a.canvas,s=P(o=>i?o.iiif.entities.Canvas[i]:void 0,[i]);return u.useMemo(()=>{if(!!s)return r?r(s):s},[s,r,...t])}function ot(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 a=Object.keys(n.iiif.entities.AnnotationPage);for(const i of a)if(!t||t.indexOf(i)!==-1){const s=ot(n,i);s&&s.views&&s.views[e]&&r.push(i)}return r},[e,t])}function fe({canvas:e,manifest:t,all:n,canvases:r}){const a=[];if(t)for(const i of t.annotations)a.indexOf(i.id)===-1&&a.push(i.id);if(n){if(r&&r.length)for(const i of r)for(const s of i.annotations)a.indexOf(s.id)===-1&&a.push(s.id)}else if(e)for(const i of e.annotations)a.indexOf(i.id)===-1&&a.push(i.id);return a}var st=Object.defineProperty,at=Object.defineProperties,ct=Object.getOwnPropertyDescriptors,de=Object.getOwnPropertySymbols,ut=Object.prototype.hasOwnProperty,lt=Object.prototype.propertyIsEnumerable,pe=(e,t,n)=>t in e?st(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ve=(e,t)=>{for(var n in t||(t={}))ut.call(t,n)&&pe(e,n,t[n]);if(de)for(var n of de(t))lt.call(t,n)&&pe(e,n,t[n]);return e},me=(e,t)=>at(e,ct(t));function ft(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 ge(e,t={}){const n=S(),r=L(),a=R(),i=K(),s=u.useMemo(()=>fe({all:t.all,manifest:r,canvas:a,canvases:i}),[t.all,a,i,r]),o=it(e,t.all?void 0:s),c=u.useCallback(p=>{!e||n.setMetaValue([p,"annotationPageManager","views"],f=>f&&!f[e]?f:me(ve({},f||{}),{[e]:!1}))},[e,n]),l=u.useCallback((p,f={})=>{if(!e)return;const v=n.getState(),h=[];if(f==null?void 0:f.deselectOthers){const d=Object.keys(v.iiif.entities.AnnotationPage);for(const m of d){const _=ft(v,m);_&&_.views&&_.views[e]&&h.push(m)}}for(const d of h)c(d);n.setMetaValue([p,"annotationPageManager","views"],d=>d&&d[e]?d:me(ve({},d||{}),{[e]:!0}))},[e,c,n]);return{availablePageIds:s,enabledPageIds:o,setPageEnabled:l,setPageDisabled:c}}function U(e={}){const t=R(e.canvasId?{id:e.canvasId}:void 0);return P((n,r)=>{if(!t)return[];const a=r.get(t.items),i=[];for(const s of a)i.push(...r.get(s.items));return i},[t])}function dt(e,t={}){return U(t)}function pt(e,t=!1){}function vt(e,t=[]){const{id:n,selector:r}=e,a=b(),i=n||a.collection,s=P(o=>i?o.iiif.entities.Collection[i]:void 0,[i]);return u.useMemo(()=>{if(!!s)return r?r(s):s},[s,r,...t])}function he(){const t=S().getStore();return u.useMemo(()=>n=>t.dispatch(n),[t])}function mt(e,t,n,r,a=[]){const i=S(),s=u.useMemo(()=>M.createEventsHelper(i),[i]);u.useEffect(()=>{const o=e;return o?(s.addEventListener(o,t,n,r),()=>{s.removeEventListener(o,t,n)}):()=>{}},[s,e,t,...a])}function gt(){const e=u.useContext(T);return e&&e.vault?e.vault:D.globalVault()}function ht(e,t){const{id:n,isLoaded:r,error:a,resource:i,requestId:s,cached:o}=H(e,t);return{id:n,isLoaded:r,error:a,manifest:i,requestId:s,cached:o}}var yt=(e,t,n)=>new Promise((r,a)=>{var i=c=>{try{o(n.next(c))}catch(l){a(l)}},s=c=>{try{o(n.throw(c))}catch(l){a(l)}},o=c=>c.done?r(c.value):Promise.resolve(c.value).then(i,s);o((n=n.apply(e,t)).next())});function ye({cacheKey:e}={}){const t=R(),n=U(),r=S(),a=B(),[i,s]=u.useState(void 0),[o,c]=u.useState(!1),[l,p]=u.useState("idle"),[f,v]=u.useState(void 0),h=t?t.id:"undefined",d=u.useMemo(()=>{try{if(t&&n.length){const _=n[0],A=r.get(_.body[0]),C=j.getImageServices(A)[0];return C&&a.loadServiceSync({id:C.id||C["@id"],width:C.width||t.width,height:C.height||t.height})||void 0}}catch(_){console.error(_)}},[h,e,t]),m=l==="success"&&i?i:d;return u.useEffect(()=>{yt(this,null,function*(){try{if(t&&n.length){const _=n[0],A=r.get(_.body[0]),C=j.getImageServices(A)[0];if(!C)return;c(!0),p("loading");try{const w=(yield a.loadService({id:C.id||C["@id"],width:C.width||t.width,height:C.height||t.height}))||void 0;s(w),p("success"),c(!1)}catch(w){p("error"),v(w)}}}catch(_){p("error"),v(_)}})},[h,e]),u.useMemo(()=>({data:m,isFetching:o,status:l,error:f}),[m,o,l,f])}function St(){const e=ye();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 Se(e,t=[]){const n=S(),r=U(),[a,i]=u.useState((e==null?void 0:e.defaultChoices)||[]),s=u.useMemo(()=>se(n,r,a),[n,r,a,...t]),c={makeChoice:u.useCallback((l,{deselectOthers:p=!0,deselect:f=!1}={})=>{if(s.choice){if(s.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");i(v=>{if(f){const d=v.filter(m=>m!==l);if(d.length===0){const m=s.items[0].resource.id;return m?[m]:[]}return d}if(p)return[l];const h=[...v];if(h.length===0&&s.items.length){const d=s.items[0].resource.id;d&&h.push(d)}return v.indexOf(l)!==-1?v:[...v,l]})}},[s.choice])};return[s,c]}function _t(e={},t=[]){const{id:n,selector:r}=e,a=b(),i=n||a.range,s=P(o=>i?o.iiif.entities.Range[i]:void 0,[i]);return u.useMemo(()=>{if(!!s)return r?r(s):s},[s,r,...t])}function Ct(e,t){const n=S(),r=u.useMemo(()=>M.createEventsHelper(n),[n]),a=P(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return u.useMemo(()=>e?r.getListenersAsProps(e,t):{},[a,e,n,t])}function _e(e,t){return P((n,r)=>r.get(e.map(a=>({id:a,type:t}))),[e,t])}function Pt(){const e=L();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function Et(){const e=S();return u.useMemo(()=>M.createStylesHelper(e),[e])}function wt(e,t){const n=S(),r=u.useMemo(()=>M.createStylesHelper(n),[n]);return P(()=>{if(!e)return null;const a=r.getAppliedStyles(e.id);return a?t?a[t]:a:void 0},[e,t])}const Ce=(e,t=[])=>{const n=S();u.useEffect(()=>{e(n)},[n,...t])};function xt(e,t,{canvasId:n,manifestId:r}={}){const a=S(),i=B(),s=u.useMemo(()=>M.createThumbnailHelper(a,{imageServiceLoader:i}),[a,i]),[o,c]=u.useState(),l=L(r?{id:r}:void 0),p=R(n?{id:n}:void 0),f=p||l,v=u.useRef(!1);if(u.useEffect(()=>()=>{v.current=!0},[]),!f)throw new Error("Must be called under a manifest or canvas context.");return Ce(h=>{s.getBestThumbnailAtSize(f,e,t).then(d=>{d.best&&!v.current&&c(d.best)})},[f]),o}var Ot=Object.defineProperty,bt=Object.defineProperties,It=Object.getOwnPropertyDescriptors,Pe=Object.getOwnPropertySymbols,At=Object.prototype.hasOwnProperty,Rt=Object.prototype.propertyIsEnumerable,Ee=(e,t,n)=>t in e?Ot(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,we=(e,t)=>{for(var n in t||(t={}))At.call(t,n)&&Ee(e,n,t[n]);if(Pe)for(var n of Pe(t))Rt.call(t,n)&&Ee(e,n,t[n]);return e},xe=(e,t)=>bt(e,It(t));function Oe(){const e=B(),[t,n]=u.useState({}),r=u.useRef(!1);return u.useEffect(()=>()=>{r.current=!0},[]),[u.useCallback((i,{height:s,width:o})=>{if(i){const c=i.id||i["@id"],l=e.loadServiceSync({id:c,width:i.width||o,height:i.height||s});l?i=l:t[c]||(r.current||n(p=>xe(we({},p),{[c]:"loading"})),e.loadService({id:c,width:i.width||o,height:i.height||s}).then(()=>{r.current||n(p=>xe(we({},p),{[c]:"done"}))}))}return i},[e,t]),t]}const Mt="@iiif/IMPORT_ENTITIES",Tt="@iiif/MODIFY_ENTITY_FIELD",Vt="@iiif/REORDER_ENTITY_FIELD",$t="@iiif/ADD_REFERENCE",Lt="@iiif/REMOVE_REFERENCE",Dt=y.createAction(Mt)(),jt=y.createAction(Tt)(),Ft=y.createAction(Vt)(),kt=y.createAction($t)(),Bt=y.createAction(Lt)(),Q={importEntities:Dt,modifyEntityField:jt,reorderEntityField:Ft,addReference:kt,removeReference:Bt},Nt="@iiif/ADD_MAPPING",Ut="@iiif/ADD_MAPPINGS";y.createAction(Nt)(),y.createAction(Ut)();const Ht="@iiif/SET_META_VALUE",qt="@iiif/SET_META_VALUE_DYNAMIC",Qt="@iiif/UNSET_META_VALUE";y.createAction(Ht)(),y.createAction(qt)(),y.createAction(Qt)();const zt="@iiif/REQUEST_RESOURCE",Yt="@iiif/REQUEST_ERROR",Gt="@iiif/REQUEST_MISMATCH",Xt="@iiif/REQUEST_COMPLETE",Jt="@iiif/REQUEST_OFFLINE_RESOURCE";y.createAction(zt)(),y.createAction(Yt)(),y.createAction(Gt)(),y.createAction(Xt)(),y.createAction(Jt)();const Wt="@iiif/BATCH",Zt="@iiif/BATCH_IMPORT";y.createAction(Wt)(),y.createAction(Zt)();function be(e){return typeof e!="string"&&e&&e.bindToVault}function Kt(){const e=S(),t=u.useRef([]),n=he(),r=u.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);u.useLayoutEffect(()=>{const o={id:r,type:"AnnotationPage",behavior:[],motivation:null,label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[]};n(Q.importEntities({entities:{AnnotationPage:{[o.id]:o}}}))},[r]);const a=P(o=>r?o.iiif.entities.AnnotationPage[r]:null,[r]),i=u.useCallback((o,c)=>{if(r){if(be(o)){const f=o;f.__vault||f.bindToVault(e),o=typeof f.source=="string"?f.source:f.source.id,t.current[o]=f}else typeof o!="string"&&(o=o.id);const l=e.get({id:r,type:"AnnotationPage"}),p=e.get({id:o,type:"Annotation"});l&&p&&(l.items.find(f=>f.id===p.id)||n(Q.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"},index:c})))}},[r]),s=u.useCallback(o=>{r&&(be(o)?o=typeof o.source=="string"?o.source:o.source.id:typeof o!="string"&&(o=o.id),t.current[o]&&t.current[o].beforeRemove(),e.get({id:r,type:"AnnotationPage"})&&n(Q.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"}})))},[r]);return[a,{addAnnotation:i,removeAnnotation:s}]}var en=Object.defineProperty,tn=Object.defineProperties,nn=Object.getOwnPropertyDescriptors,Ie=Object.getOwnPropertySymbols,rn=Object.prototype.hasOwnProperty,on=Object.prototype.propertyIsEnumerable,Ae=(e,t,n)=>t in e?en(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,sn=(e,t)=>{for(var n in t||(t={}))rn.call(t,n)&&Ae(e,n,t[n]);if(Ie)for(var n of Ie(t))on.call(t,n)&&Ae(e,n,t[n]);return e},an=(e,t)=>tn(e,nn(t));function cn(e){const t=L(),n=R(),r=S(),[a,i]=Oe(),{enabledPageIds:s}=ge((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(n==null?void 0:n.id),{all:!1}),o=_e(s,"AnnotationPage"),c=(e==null?void 0:e.strategies)||["images","media","complex-timeline"],[l,p]=Se(e,[i]),f=u.useMemo(()=>{if(!n||l.types.length===0)return q;if(l.types.length!==1)return c.indexOf("complex-timeline")===-1?E("Complex timeline not supported"):E("ComplexTimelineStrategy not yet supported");const v=l.types[0];return v==="image"?c.indexOf("images")===-1?E("Image not supported"):ce(n,l,a):v==="audio"?c.indexOf("media")===-1?E("Media not supported"):E("Audio strategy not yet supported"):v==="video"?c.indexOf("media")===-1?E("Media not supported"):E("Video strategy not yet supported"):q},[n,l,r,p.makeChoice]);return u.useMemo(()=>f.type==="unknown"?[f,ae]:[an(sn({},f),{annotations:{pages:o}}),p],[f,o])}exports.AnnotationContext=Le,exports.CanvasContext=X,exports.CollectionContext=De,exports.ContextBridge=Ue,exports.ImageServiceLoaderContext=ee,exports.ManifestContext=J,exports.RangeContext=je,exports.ReactVaultContext=T,exports.ResourceProvider=I,exports.ResourceReactContext=F,exports.SimpleViewerProvider=ke,exports.SimpleViewerReactContext=$,exports.VaultProvider=W,exports.VisibleCanvasReactContext=V,exports.emptyActions=ae,exports.expandTarget=x,exports.flattenAnnotationPageIds=fe,exports.getImageStrategy=ce,exports.getPaintables=se,exports.parseSelector=N,exports.parseSpecificResource=ie,exports.unknownResponse=q,exports.unsupportedStrategy=E,exports.useAnnotation=rt,exports.useAnnotationPageManager=ge,exports.useAnnotationsAtTime=dt,exports.useCanvas=R,exports.useCanvasClock=pt,exports.useCollection=vt,exports.useContextBridge=Ne,exports.useDispatch=he,exports.useEventListener=mt,exports.useExistingVault=gt,exports.useExternalCollection=ht,exports.useExternalManifest=Z,exports.useExternalResource=H,exports.useImageService=ye,exports.useImageServiceLoader=B,exports.useImageTile=St,exports.useLoadImageService=Oe,exports.useManifest=L,exports.usePaintables=Se,exports.usePaintingAnnotations=U,exports.useRange=_t,exports.useRenderingStrategy=cn,exports.useResourceContext=b,exports.useResourceEvents=Ct,exports.useResources=_e,exports.useSearchService=Pt,exports.useSimpleViewer=Be,exports.useStyleHelper=Et,exports.useStyles=wt,exports.useThumbnail=xt,exports.useVault=S,exports.useVaultEffect=Ce,exports.useVaultSelector=P,exports.useVirtualAnnotationPage=Kt,exports.useVisibleCanvases=K;
@@ -1 +1 @@
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};
1
+ import g,{useContext as O,useMemo as m,useState as w,useEffect as b,createContext as je,useCallback as C,useRef as Q,useLayoutEffect as Fe}from"react";import{globalVault as X,Vault as J}from"@iiif/vault";import{ImageServiceLoader as Ne,getImageServices as q}from"@atlas-viewer/iiif-image-api";import{createEventsHelper as W,createStylesHelper as Z,createThumbnailHelper as Be}from"@iiif/vault-helpers";import{createAction as y}from"typesafe-actions";var Ue=Object.defineProperty,K=Object.getOwnPropertySymbols,ke=Object.prototype.hasOwnProperty,He=Object.prototype.propertyIsEnumerable,ee=(e,t,n)=>t in e?Ue(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,te=(e,t)=>{for(var n in t||(t={}))ke.call(t,n)&&ee(e,n,t[n]);if(K)for(var n of K(t))He.call(t,n)&&ee(e,n,t[n]);return e};const Qe={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},N=g.createContext(Qe),T=()=>O(N),$=({value:e,children:t})=>{const n=T(),r=m(()=>te(te({},n),e),[e,n]);return g.createElement(N.Provider,{value:r},t)},qe=({annotation:e,children:t})=>g.createElement($,{value:{annotation:e}},t),ne=({canvas:e,children:t})=>g.createElement($,{value:{canvas:e}},t),ze=({collection:e,children:t})=>g.createElement($,{value:{collection:e}},t),re=({manifest:e,children:t})=>g.createElement($,{value:{manifest:e}},t),Ye=({range:e,children:t})=>g.createElement($,{value:{range:e}},t),L=g.createContext({vault:null,setVaultInstance:e=>{}}),oe=({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:a})=>{const[i,s]=w(()=>e||(n?X(t):t?new J(t):new J));return g.createElement(L.Provider,{value:{vault:i,setVaultInstance:s}},g.createElement($,{value:r||{}},a))},_=()=>{const{vault:e}=O(L);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var Ge=(e,t,n)=>new Promise((r,a)=>{var i=c=>{try{o(n.next(c))}catch(l){a(l)}},s=c=>{try{o(n.throw(c))}catch(l){a(l)}},o=c=>c.done?r(c.value):Promise.resolve(c.value).then(i,s);o((n=n.apply(e,t)).next())});function z(e,{noCache:t=!1}={}){const n=typeof e=="string"?e:e.id,r=_(),[a,i]=w(n),[s,o]=w(void 0),c=m(()=>r.get(n,{skipSelfReturn:!0})||void 0,[n,r]),[l,d]=w(c);return b(()=>{Ge(this,null,function*(){try{const u=c&&!t?c:yield r.load(n),p=u?u.id||u["@id"]:null;u&&a!==p&&i(p),d(u)}catch(u){o(u)}})},[n,t]),{isLoaded:!!l,id:a,requestId:n,error:s,resource:l,cached:!!(l&&l===c)}}function ie(e,t){const{id:n,isLoaded:r,error:a,resource:i,requestId:s,cached:o}=z(e,t);return{id:n,isLoaded:r,error:a,manifest:i,requestId:s,cached:o}}function E(e,t=[]){const n=_(),[r,a]=w(()=>e(n.getState(),n));return b(()=>n.subscribe(i=>e(i,n),i=>{a(i)},!1),t),r}const D=g.createContext([]);function se(){const e=O(D);return E(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}const B=()=>{},j=je({setCurrentCanvasId:B,setCurrentCanvasIndex:B,nextCanvas:B,previousCanvas:B,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),Xe=e=>{const t=ie(e.manifest),[n,r]=w(""),[a,i]=w([]),s=(typeof e.pagingEnabled>"u"||e.pagingEnabled)&&t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");b(()=>{var f,v;t.manifest&&(r((f=t.manifest.items[0])==null?void 0:f.id),i([(v=t.manifest.items[0])==null?void 0:v.id]))},[t.manifest,e.manifest]);const o=m(()=>{var f;return((f=t.manifest)==null?void 0:f.items.map(v=>v.id))||[]},[t.manifest,e.manifest]),c=m(()=>o.indexOf(n),[o,n]),l=C(()=>{if(o.length&&n){if(c===-1||(o[c+2]?c+2===o.length:c===o.length))return;const f=s&&c!==0?o[c+2]:o[c+1],v=s?c!==0?o[c+3]:o[c+2]:null;f&&(r(f),i(v?[f,v]:[f]))}},[s,o,n,c]),d=C(()=>{if(o.length&&n){if(c===0||c===-1)return;const f=s&&c!==1?o[c-2]:o[c-1],v=s&&c!==1?o[c-1]:null;f&&(r(f),i(v?[f,v]:[f]))}},[s,o,n,c]),u=C(f=>{const v=s&&f%2===1?f-1:f,P=o[v],M=s&&v!==0?o[v+1]:null;P&&(r(P),i(A=>{const S=M?[P,M]:[P];if(A.length===A.length){for(let I=0;I<A.length;I++)if(A[I]!==S[I])return S;return A}return S}))},[s,o]),p=C(f=>{const v=o.indexOf(f);v!==-1&&u(v)},[o,u]),h=m(()=>({setCurrentCanvasId:p,nextCanvas:l,previousCanvas:d,currentCanvasIndex:c,totalCanvases:o.length,setCurrentCanvasIndex:u,pagingView:!0}),[l,d,c,o,u,p]);return t.manifest?t.isLoaded?g.createElement(j.Provider,{value:h},g.createElement(D.Provider,{value:a},g.createElement(re,{manifest:t.manifest.id},g.createElement(ne,{canvas:n},e.children)))):g.createElement("div",null,"Loading..."):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),g.createElement("div",null,"Sorry, something went wrong."))};function Je(){return O(j)}function We(){return{VaultContext:O(L),ResourceContext:O(N),SimpleViewerReactContext:O(j),VisibleCanvasReactContext:O(D)}}const Ze=e=>g.createElement(oe,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},g.createElement(D.Provider,{value:e.bridge.VisibleCanvasReactContext},g.createElement(j.Provider,{value:e.bridge.SimpleViewerReactContext},e.children))),ae=g.createContext(new Ne);function U(){return O(ae)}const Ke=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,et=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function k(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:r,selectors:a}=k(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?k({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=Ke.exec(e.value);if(t){const r={type:"BoxSelector",spatial:{unit:t[2]==="percent:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:r,selectors:[r]}}const n=e.value.match(et);if(n){const r={type:"TemporalSelector",temporal:{startTime:n[4]?parseFloat(n[4]):0,endTime:n[7]?parseFloat(n[7]):void 0}};return{selector:r,selectors:[r]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}var tt=Object.defineProperty,nt=Object.defineProperties,rt=Object.getOwnPropertyDescriptors,ce=Object.getOwnPropertySymbols,ot=Object.prototype.hasOwnProperty,it=Object.prototype.propertyIsEnumerable,le=(e,t,n)=>t in e?tt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ue=(e,t)=>{for(var n in t||(t={}))ot.call(t,n)&&le(e,n,t[n]);if(ce)for(var n of ce(t))it.call(t,n)&&le(e,n,t[n]);return e},fe=(e,t)=>nt(e,rt(t));function R(e,t={}){if(Array.isArray(e))return R(e[0]);if(typeof e=="string"){const[n,r]=e.split("#");return r?R({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 R(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?k(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?R({type:"SpecificResource",source:fe(ue({},e),{id:n}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:fe(ue({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function de(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function pe(e,t,n){const r=[];let a=null;const i=[];for(const s of t){const o=e.get(s.body);for(const c of o){const[l,{selector:d}]=de(c),u=(l.type||"unknown").toLowerCase();if(u==="choice"){const p=e.get(l.items),h=n.length?n.map(f=>p.find(v=>v.id===f)).filter(Boolean):[p[0]];h.length===0&&h.push(p[0]),a={type:"single-choice",items:p.map(f=>({id:f.id,label:f.label,selected:h.indexOf(f)!==-1})),label:c.label},o.push(...h);continue}r.indexOf(u)===-1&&r.push(u),i.push({type:u,resource:l,target:s.target,selector:d})}}return{types:r,items:i,choice:a}}const ve={makeChoice:()=>{}},Y={type:"unknown"},x=e=>({type:"unknown",reason:e,annotations:{pages:[]}});function me(e,t,n){const r=[];for(const a of t.items){const i=a.resource&&a.resource.type==="SpecificResource"?a.resource.source:a.resource;if(!i.id)return x("No resource Identifier");let s;if(i.service){const v=q(i);v[0]&&(s=n(v[0],e))}const{selector:o,source:c}=R(a.target);if(c.id!==e.id)continue;const l={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},d=o?o.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:o.temporal,spatial:l.spatial}:o:null,u={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},p=a.resource.type==="SpecificResource"?R(a.resource):null,h=p&&p.selector&&(p.selector.type==="BoxSelector"||p.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:p.selector.spatial.x,y:p.selector.spatial.y,width:p.selector.spatial.width,height:p.selector.spatial.height}}:u,f={id:i.id,type:"Image",width:d?i.width:e.width,height:d?i.height:e.height,service:s,sizes:s&&s.sizes?s.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:d&&d.type!=="PointSelector"?d:l,selector:h};r.push(f)}return{type:"images",image:r[0],images:r,choice:t.choice}}var st=Object.defineProperty,at=Object.defineProperties,ct=Object.getOwnPropertyDescriptors,ge=Object.getOwnPropertySymbols,lt=Object.prototype.hasOwnProperty,ut=Object.prototype.propertyIsEnumerable,he=(e,t,n)=>t in e?st(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ft=(e,t)=>{for(var n in t||(t={}))lt.call(t,n)&&he(e,n,t[n]);if(ge)for(var n of ge(t))ut.call(t,n)&&he(e,n,t[n]);return e},dt=(e,t)=>at(e,ct(t));function pt(e={},t=[]){const{id:n,selector:r}=e,a=T(),i=_(),s=n||a.annotation,o=E(l=>s?l.iiif.entities.Annotation[s]:void 0,[s]),c=E(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=dt(ft({},o),{body:c,target:R(o.target,{typeMap:i.getState().iiif.mapping})});return r?r(l):l},[o,r,c,...t])}function F(e={},t=[]){const{id:n,selector:r}=e,a=T();_();const i=n||a.manifest,s=E(o=>i?o.iiif.entities.Manifest[i]:void 0,[i]);return m(()=>{if(!!s)return r?r(s):s},[s,r,...t])}function V(e={},t=[]){const{id:n,selector:r}=e,a=T(),i=n||a.canvas,s=E(o=>i?o.iiif.entities.Canvas[i]:void 0,[i]);return m(()=>{if(!!s)return r?r(s):s},[s,r,...t])}function vt(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 mt(e,t){return E(n=>{const r=[];if(!e)return r;const a=Object.keys(n.iiif.entities.AnnotationPage);for(const i of a)if(!t||t.indexOf(i)!==-1){const s=vt(n,i);s&&s.views&&s.views[e]&&r.push(i)}return r},[e,t])}function ye({canvas:e,manifest:t,all:n,canvases:r}){const a=[];if(t)for(const i of t.annotations)a.indexOf(i.id)===-1&&a.push(i.id);if(n){if(r&&r.length)for(const i of r)for(const s of i.annotations)a.indexOf(s.id)===-1&&a.push(s.id)}else if(e)for(const i of e.annotations)a.indexOf(i.id)===-1&&a.push(i.id);return a}var gt=Object.defineProperty,ht=Object.defineProperties,yt=Object.getOwnPropertyDescriptors,_e=Object.getOwnPropertySymbols,_t=Object.prototype.hasOwnProperty,Pt=Object.prototype.propertyIsEnumerable,Pe=(e,t,n)=>t in e?gt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Se=(e,t)=>{for(var n in t||(t={}))_t.call(t,n)&&Pe(e,n,t[n]);if(_e)for(var n of _e(t))Pt.call(t,n)&&Pe(e,n,t[n]);return e},we=(e,t)=>ht(e,yt(t));function St(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=_(),r=F(),a=V(),i=se(),s=m(()=>ye({all:t.all,manifest:r,canvas:a,canvases:i}),[t.all,a,i,r]),o=mt(e,t.all?void 0:s),c=C(d=>{!e||n.setMetaValue([d,"annotationPageManager","views"],u=>u&&!u[e]?u:we(Se({},u||{}),{[e]:!1}))},[e,n]),l=C((d,u={})=>{if(!e)return;const p=n.getState(),h=[];if(u==null?void 0:u.deselectOthers){const f=Object.keys(p.iiif.entities.AnnotationPage);for(const v of f){const P=St(p,v);P&&P.views&&P.views[e]&&h.push(v)}}for(const f of h)c(f);n.setMetaValue([d,"annotationPageManager","views"],f=>f&&f[e]?f:we(Se({},f||{}),{[e]:!0}))},[e,c,n]);return{availablePageIds:s,enabledPageIds:o,setPageEnabled:l,setPageDisabled:c}}function H(e={}){const t=V(e.canvasId?{id:e.canvasId}:void 0);return E((n,r)=>{if(!t)return[];const a=r.get(t.items),i=[];for(const s of a)i.push(...r.get(s.items));return i},[t])}function wt(e,t={}){return H(t)}function Et(e,t=!1){}function Ot(e,t=[]){const{id:n,selector:r}=e,a=T(),i=n||a.collection,s=E(o=>i?o.iiif.entities.Collection[i]:void 0,[i]);return m(()=>{if(!!s)return r?r(s):s},[s,r,...t])}function Oe(){const t=_().getStore();return m(()=>n=>t.dispatch(n),[t])}function Ct(e,t,n,r,a=[]){const i=_(),s=m(()=>W(i),[i]);b(()=>{const o=e;return o?(s.addEventListener(o,t,n,r),()=>{s.removeEventListener(o,t,n)}):()=>{}},[s,e,t,...a])}function xt(){const e=O(L);return e&&e.vault?e.vault:X()}function It(e,t){const{id:n,isLoaded:r,error:a,resource:i,requestId:s,cached:o}=z(e,t);return{id:n,isLoaded:r,error:a,manifest:i,requestId:s,cached:o}}var bt=(e,t,n)=>new Promise((r,a)=>{var i=c=>{try{o(n.next(c))}catch(l){a(l)}},s=c=>{try{o(n.throw(c))}catch(l){a(l)}},o=c=>c.done?r(c.value):Promise.resolve(c.value).then(i,s);o((n=n.apply(e,t)).next())});function Ce({cacheKey:e}={}){const t=V(),n=H(),r=_(),a=U(),[i,s]=w(void 0),[o,c]=w(!1),[l,d]=w("idle"),[u,p]=w(void 0),h=t?t.id:"undefined",f=m(()=>{try{if(t&&n.length){const P=n[0],M=r.get(P.body[0]),S=q(M)[0];return S&&a.loadServiceSync({id:S.id||S["@id"],width:S.width||t.width,height:S.height||t.height})||void 0}}catch(P){console.error(P)}},[h,e,t]),v=l==="success"&&i?i:f;return b(()=>{bt(this,null,function*(){try{if(t&&n.length){const P=n[0],M=r.get(P.body[0]),S=q(M)[0];if(!S)return;c(!0),d("loading");try{const I=(yield a.loadService({id:S.id||S["@id"],width:S.width||t.width,height:S.height||t.height}))||void 0;s(I),d("success"),c(!1)}catch(I){d("error"),p(I)}}}catch(P){d("error"),p(P)}})},[h,e]),m(()=>({data:v,isFetching:o,status:l,error:u}),[v,o,l,u])}function Rt(){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 xe(e,t=[]){const n=_(),r=H(),[a,i]=w((e==null?void 0:e.defaultChoices)||[]),s=m(()=>pe(n,r,a),[n,r,a,...t]),c={makeChoice:C((l,{deselectOthers:d=!0,deselect:u=!1}={})=>{if(s.choice){if(s.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");i(p=>{if(u){const f=p.filter(v=>v!==l);if(f.length===0){const v=s.items[0].resource.id;return v?[v]:[]}return f}if(d)return[l];const h=[...p];if(h.length===0&&s.items.length){const f=s.items[0].resource.id;f&&h.push(f)}return p.indexOf(l)!==-1?p:[...p,l]})}},[s.choice])};return[s,c]}function At(e={},t=[]){const{id:n,selector:r}=e,a=T(),i=n||a.range,s=E(o=>i?o.iiif.entities.Range[i]:void 0,[i]);return m(()=>{if(!!s)return r?r(s):s},[s,r,...t])}function Tt(e,t){const n=_(),r=m(()=>W(n),[n]),a=E(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return m(()=>e?r.getListenersAsProps(e,t):{},[a,e,n,t])}function Ie(e,t){return E((n,r)=>r.get(e.map(a=>({id:a,type:t}))),[e,t])}function $t(){const e=F();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function Mt(){const e=_();return m(()=>Z(e),[e])}function Vt(e,t){const n=_(),r=m(()=>Z(n),[n]);return E(()=>{if(!e)return null;const a=r.getAppliedStyles(e.id);return a?t?a[t]:a:void 0},[e,t])}const be=(e,t=[])=>{const n=_();b(()=>{e(n)},[n,...t])};function Lt(e,t,{canvasId:n,manifestId:r}={}){const a=_(),i=U(),s=m(()=>Be(a,{imageServiceLoader:i}),[a,i]),[o,c]=w(),l=F(r?{id:r}:void 0),d=V(n?{id:n}:void 0),u=d||l,p=Q(!1);if(b(()=>()=>{p.current=!0},[]),!u)throw new Error("Must be called under a manifest or canvas context.");return be(h=>{s.getBestThumbnailAtSize(u,e,t).then(f=>{f.best&&!p.current&&c(f.best)})},[u]),o}var Dt=Object.defineProperty,jt=Object.defineProperties,Ft=Object.getOwnPropertyDescriptors,Re=Object.getOwnPropertySymbols,Nt=Object.prototype.hasOwnProperty,Bt=Object.prototype.propertyIsEnumerable,Ae=(e,t,n)=>t in e?Dt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Te=(e,t)=>{for(var n in t||(t={}))Nt.call(t,n)&&Ae(e,n,t[n]);if(Re)for(var n of Re(t))Bt.call(t,n)&&Ae(e,n,t[n]);return e},$e=(e,t)=>jt(e,Ft(t));function Me(){const e=U(),[t,n]=w({}),r=Q(!1);return b(()=>()=>{r.current=!0},[]),[C((i,{height:s,width:o})=>{if(i){const c=i.id||i["@id"],l=e.loadServiceSync({id:c,width:i.width||o,height:i.height||s});l?i=l:t[c]||(r.current||n(d=>$e(Te({},d),{[c]:"loading"})),e.loadService({id:c,width:i.width||o,height:i.height||s}).then(()=>{r.current||n(d=>$e(Te({},d),{[c]:"done"}))}))}return i},[e,t]),t]}const Ut="@iiif/IMPORT_ENTITIES",kt="@iiif/MODIFY_ENTITY_FIELD",Ht="@iiif/REORDER_ENTITY_FIELD",Qt="@iiif/ADD_REFERENCE",qt="@iiif/REMOVE_REFERENCE",zt=y(Ut)(),Yt=y(kt)(),Gt=y(Ht)(),Xt=y(Qt)(),Jt=y(qt)(),G={importEntities:zt,modifyEntityField:Yt,reorderEntityField:Gt,addReference:Xt,removeReference:Jt},Wt="@iiif/ADD_MAPPING",Zt="@iiif/ADD_MAPPINGS";y(Wt)(),y(Zt)();const Kt="@iiif/SET_META_VALUE",en="@iiif/SET_META_VALUE_DYNAMIC",tn="@iiif/UNSET_META_VALUE";y(Kt)(),y(en)(),y(tn)();const nn="@iiif/REQUEST_RESOURCE",rn="@iiif/REQUEST_ERROR",on="@iiif/REQUEST_MISMATCH",sn="@iiif/REQUEST_COMPLETE",an="@iiif/REQUEST_OFFLINE_RESOURCE";y(nn)(),y(rn)(),y(on)(),y(sn)(),y(an)();const cn="@iiif/BATCH",ln="@iiif/BATCH_IMPORT";y(cn)(),y(ln)();function Ve(e){return typeof e!="string"&&e&&e.bindToVault}function un(){const e=_(),t=Q([]),n=Oe(),r=m(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);Fe(()=>{const o={id:r,type:"AnnotationPage",behavior:[],motivation:null,label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[]};n(G.importEntities({entities:{AnnotationPage:{[o.id]:o}}}))},[r]);const a=E(o=>r?o.iiif.entities.AnnotationPage[r]:null,[r]),i=C((o,c)=>{if(r){if(Ve(o)){const u=o;u.__vault||u.bindToVault(e),o=typeof u.source=="string"?u.source:u.source.id,t.current[o]=u}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(u=>u.id===d.id)||n(G.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"},index:c})))}},[r]),s=C(o=>{r&&(Ve(o)?o=typeof o.source=="string"?o.source:o.source.id:typeof o!="string"&&(o=o.id),t.current[o]&&t.current[o].beforeRemove(),e.get({id:r,type:"AnnotationPage"})&&n(G.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"}})))},[r]);return[a,{addAnnotation:i,removeAnnotation:s}]}var fn=Object.defineProperty,dn=Object.defineProperties,pn=Object.getOwnPropertyDescriptors,Le=Object.getOwnPropertySymbols,vn=Object.prototype.hasOwnProperty,mn=Object.prototype.propertyIsEnumerable,De=(e,t,n)=>t in e?fn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,gn=(e,t)=>{for(var n in t||(t={}))vn.call(t,n)&&De(e,n,t[n]);if(Le)for(var n of Le(t))mn.call(t,n)&&De(e,n,t[n]);return e},hn=(e,t)=>dn(e,pn(t));function yn(e){const t=F(),n=V(),r=_(),[a,i]=Me(),{enabledPageIds:s}=Ee((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(n==null?void 0:n.id),{all:!1}),o=Ie(s,"AnnotationPage"),c=(e==null?void 0:e.strategies)||["images","media","complex-timeline"],[l,d]=xe(e,[i]),u=m(()=>{if(!n||l.types.length===0)return Y;if(l.types.length!==1)return c.indexOf("complex-timeline")===-1?x("Complex timeline not supported"):x("ComplexTimelineStrategy not yet supported");const p=l.types[0];return p==="image"?c.indexOf("images")===-1?x("Image not supported"):me(n,l,a):p==="audio"?c.indexOf("media")===-1?x("Media not supported"):x("Audio strategy not yet supported"):p==="video"?c.indexOf("media")===-1?x("Media not supported"):x("Video strategy not yet supported"):Y},[n,l,r,d.makeChoice]);return m(()=>u.type==="unknown"?[u,ve]:[hn(gn({},u),{annotations:{pages:o}}),d],[u,o])}export{qe as AnnotationContext,ne as CanvasContext,ze as CollectionContext,Ze as ContextBridge,ae as ImageServiceLoaderContext,re as ManifestContext,Ye as RangeContext,L as ReactVaultContext,$ as ResourceProvider,N as ResourceReactContext,Xe as SimpleViewerProvider,j as SimpleViewerReactContext,oe as VaultProvider,D as VisibleCanvasReactContext,ve as emptyActions,R as expandTarget,ye as flattenAnnotationPageIds,me as getImageStrategy,pe as getPaintables,k as parseSelector,de as parseSpecificResource,Y as unknownResponse,x as unsupportedStrategy,pt as useAnnotation,Ee as useAnnotationPageManager,wt as useAnnotationsAtTime,V as useCanvas,Et as useCanvasClock,Ot as useCollection,We as useContextBridge,Oe as useDispatch,Ct as useEventListener,xt as useExistingVault,It as useExternalCollection,ie as useExternalManifest,z as useExternalResource,Ce as useImageService,U as useImageServiceLoader,Rt as useImageTile,Me as useLoadImageService,F as useManifest,xe as usePaintables,H as usePaintingAnnotations,At as useRange,yn as useRenderingStrategy,T as useResourceContext,Tt as useResourceEvents,Ie as useResources,$t as useSearchService,Je as useSimpleViewer,Mt as useStyleHelper,Vt as useStyles,Lt as useThumbnail,_ as useVault,be as useVaultEffect,E as useVaultSelector,un as useVirtualAnnotationPage,se as useVisibleCanvases};
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import { Vault, VaultOptions, ReduxStore, NormalizedEntity, IIIFStore } from '@i
3
3
  import * as _iiif_vault__ from '@iiif/vault/*';
4
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
- import { QueryOptions } from 'react-query';
6
+ import * as _iiif_vault_helpers from '@iiif/vault-helpers';
7
7
 
8
8
  declare const AnnotationContext: React.FC<{
9
9
  annotation: string;
@@ -91,29 +91,59 @@ interface ComplexChoice {
91
91
  }
92
92
  declare type ChoiceDescription = SingleChoice | ComplexChoice;
93
93
 
94
- declare type BoxSelector = {
94
+ interface SupportedSelector {
95
+ type: string;
96
+ temporal?: {
97
+ startTime: number;
98
+ endTime?: number;
99
+ };
100
+ spatial?: {
101
+ unit?: 'percent' | 'pixel';
102
+ x: number;
103
+ y: number;
104
+ width?: number;
105
+ height?: number;
106
+ };
107
+ }
108
+ interface BoxSelector extends SupportedSelector {
95
109
  type: 'BoxSelector';
96
- unit?: 'percent' | 'pixel';
97
- x: number;
98
- y: number;
99
- width: number;
100
- height: number;
101
- };
102
- declare type TemporalSelector = {
110
+ spatial: {
111
+ unit?: 'percent' | 'pixel';
112
+ x: number;
113
+ y: number;
114
+ width: number;
115
+ height: number;
116
+ };
117
+ }
118
+ interface PointSelector extends SupportedSelector {
119
+ type: 'PointSelector';
120
+ spatial: {
121
+ x: number;
122
+ y: number;
123
+ };
124
+ }
125
+ interface TemporalSelector extends SupportedSelector {
103
126
  type: 'TemporalSelector';
104
- startTime: number;
105
- endTime?: number;
106
- };
107
- declare type TemporalBoxSelector = {
127
+ temporal: {
128
+ startTime: number;
129
+ endTime?: number;
130
+ };
131
+ }
132
+ interface TemporalBoxSelector extends SupportedSelector {
108
133
  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;
134
+ spatial: {
135
+ unit?: 'percent' | 'pixel';
136
+ x: number;
137
+ y: number;
138
+ width: number;
139
+ height: number;
140
+ };
141
+ temporal: {
142
+ startTime: number;
143
+ endTime?: number;
144
+ };
145
+ }
146
+ declare type SupportedSelectors = TemporalSelector | BoxSelector | TemporalBoxSelector | PointSelector;
117
147
 
118
148
  declare type ImageWithOptionalService = {
119
149
  id: string;
@@ -270,23 +300,54 @@ declare function useEventListener<T>(resource: Reference, name: SupportedEvents,
270
300
 
271
301
  declare function useExistingVault(): any;
272
302
 
273
- declare const useExternalCollection: (id: string, config?: QueryOptions<CollectionNormalized>) => {
303
+ declare type ResourceRequestOptions = {
304
+ noCache?: boolean;
305
+ };
306
+ declare function useExternalResource<T extends {
307
+ id: string;
308
+ }>(idOrRef: string | {
309
+ id: string;
310
+ type: string;
311
+ }, { noCache }?: ResourceRequestOptions): {
312
+ id: string;
313
+ requestId: string;
314
+ isLoaded: boolean;
315
+ error: any;
316
+ cached: boolean;
317
+ resource?: T;
318
+ };
319
+
320
+ declare function useExternalCollection(idOrRef: string | {
274
321
  id: string;
322
+ type: string;
323
+ }, options?: ResourceRequestOptions): {
324
+ id: string;
325
+ requestId: string;
275
326
  isLoaded: boolean;
276
- collection?: CollectionNormalized | undefined;
327
+ cached?: boolean;
328
+ error: any;
329
+ manifest?: CollectionNormalized;
277
330
  };
278
331
 
279
- declare const useExternalManifest: (id: string, config?: QueryOptions<ManifestNormalized>) => {
332
+ declare function useExternalManifest(idOrRef: string | {
280
333
  id: string;
334
+ type: string;
335
+ }, options?: ResourceRequestOptions): {
336
+ id: string;
337
+ requestId: string;
281
338
  isLoaded: boolean;
339
+ cached?: boolean;
282
340
  error: any;
283
- manifest?: ManifestNormalized | undefined;
341
+ manifest?: ManifestNormalized;
284
342
  };
285
343
 
286
- declare function useImageService(): {
344
+ interface ImageServiceRequestOptions {
345
+ cacheKey?: string;
346
+ }
347
+ declare function useImageService({ cacheKey }?: ImageServiceRequestOptions): {
287
348
  data: ImageService | undefined;
288
349
  isFetching: boolean;
289
- status: 'error' | 'success' | 'loading';
350
+ status: 'error' | 'success' | 'loading' | 'idle';
290
351
  };
291
352
 
292
353
  declare function useImageTile(): {
@@ -335,6 +396,8 @@ declare function useResources<Type>(ids: string[], type: string): Type[];
335
396
 
336
397
  declare function useSearchService(): SearchService | undefined;
337
398
 
399
+ declare function useStyleHelper(): _iiif_vault_helpers.StyledHelper<_iiif_vault_helpers.StyleDefinition>;
400
+
338
401
  declare function useStyles<Style extends Record<string, Record<string, any>>>(resource: undefined | Reference<any>): Style;
339
402
  declare function useStyles<Style extends Record<string, any>>(resource: undefined | Reference<any>, scope: string): Style;
340
403
 
@@ -408,4 +471,4 @@ declare const SimpleViewerProvider: FC<{
408
471
  }>;
409
472
  declare function useSimpleViewer(): SimpleViewerContext;
410
473
 
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 };
474
+ export { AnnotationContext, AnnotationPageDescription, AudioSequence, BoxSelector, CanvasContext, ChoiceDescription, CollectionContext, ComplexChoice, ComplexTimelineStrategy, ContextBridge, ImageServiceLoaderContext, ImageServiceLoaderType, ImageServiceRequestOptions, ImageWithOptionalService, ManifestContext, MediaStrategy, Paintables, ParsedSelector, PointSelector, RangeContext, ReactVaultContext, RenderingStrategy, ResourceContextType, ResourceProvider, ResourceReactContext, ResourceRequestOptions, SimpleViewerProvider, SimpleViewerReactContext, SingleAudio, SingleChoice, SingleImageStrategy, SingleVideo, StrategyActions, SupportedSelector, SupportedSelectors, SupportedTarget, TemporalBoxSelector, TemporalSelector, UnknownStrategy, UseRenderingStrategy, UseRenderingStrategyOptions, VaultActivatedAnnotation, VaultProvider, VideoSequence, VisibleCanvasReactContext, emptyActions, expandTarget, flattenAnnotationPageIds, getImageStrategy, getPaintables, parseSelector, parseSpecificResource, unknownResponse, unsupportedStrategy, useAnnotation, useAnnotationPageManager, useAnnotationsAtTime, useCanvas, useCanvasClock, useCollection, useContextBridge, useDispatch, useEventListener, useExistingVault, useExternalCollection, useExternalManifest, useExternalResource, useImageService, useImageServiceLoader, useImageTile, useLoadImageService, useManifest, usePaintables, usePaintingAnnotations, useRange, useRenderingStrategy, useResourceContext, useResourceEvents, useResources, useSearchService, useSimpleViewer, useStyleHelper, useStyles, useThumbnail, useVault, useVaultEffect, useVaultSelector, useVirtualAnnotationPage, useVisibleCanvases };
package/dist/index.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(g,v){typeof exports=="object"&&typeof module<"u"?v(exports,require("react"),require("@iiif/vault")):typeof define=="function"&&define.amd?define(["exports","react","@iiif/vault"],v):(g=typeof globalThis<"u"?globalThis:g||self,v(g.ReactIIIFVault={},g.React,g.IIIFVault))})(this,function(g,v,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}/*! *****************************************************************************
1
+ (function(g,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("react"),require("@iiif/vault")):typeof define=="function"&&define.amd?define(["exports","react","@iiif/vault"],h):(g=typeof globalThis<"u"?globalThis:g||self,h(g.ReactIIIFVault={},g.React,g.IIIFVault))})(this,function(g,h,K){"use strict";function Kt(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var A=Kt(h),ei=Object.defineProperty,de=Object.getOwnPropertySymbols,ti=Object.prototype.hasOwnProperty,ii=Object.prototype.propertyIsEnumerable,pe=(e,t,i)=>t in e?ei(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,ge=(e,t)=>{for(var i in t||(t={}))ti.call(t,i)&&pe(e,i,t[i]);if(de)for(var i of de(t))ii.call(t,i)&&pe(e,i,t[i]);return e};const ni={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},ee=A.default.createContext(ni),k=()=>h.useContext(ee),V=({value:e,children:t})=>{const i=k(),n=h.useMemo(()=>ge(ge({},i),e),[e,i]);return A.default.createElement(ee.Provider,{value:n},t)},ri=({annotation:e,children:t})=>A.default.createElement(V,{value:{annotation:e}},t),me=({canvas:e,children:t})=>A.default.createElement(V,{value:{canvas:e}},t),oi=({collection:e,children:t})=>A.default.createElement(V,{value:{collection:e}},t),ve=({manifest:e,children:t})=>A.default.createElement(V,{value:{manifest:e}},t),si=({range:e,children:t})=>A.default.createElement(V,{value:{range:e}},t),U=A.default.createContext({vault:null,setVaultInstance:e=>{}}),ye=({vault:e,vaultOptions:t,useGlobal:i,resources:n,children:o})=>{const[r,s]=h.useState(()=>e||(i?K.globalVault(t):t?new K.Vault(t):new K.Vault));return A.default.createElement(U.Provider,{value:{vault:r,setVaultInstance:s}},A.default.createElement(V,{value:n||{}},o))},I=()=>{const{vault:e}=h.useContext(U);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var ai=(e,t,i)=>new Promise((n,o)=>{var r=l=>{try{a(i.next(l))}catch(c){o(c)}},s=l=>{try{a(i.throw(l))}catch(c){o(c)}},a=l=>l.done?n(l.value):Promise.resolve(l.value).then(r,s);a((i=i.apply(e,t)).next())});function oe(e,{noCache:t=!1}={}){const i=typeof e=="string"?e:e.id,n=I(),[o,r]=h.useState(i),[s,a]=h.useState(void 0),l=h.useMemo(()=>n.get(i,{skipSelfReturn:!0})||void 0,[i,n]),[c,u]=h.useState(l);return h.useEffect(()=>{ai(this,null,function*(){try{const d=l&&!t?l:yield n.load(i),v=d?d.id||d["@id"]:null;d&&o!==v&&r(v),u(d)}catch(d){a(d)}})},[i,t]),{isLoaded:!!c,id:o,requestId:i,error:s,resource:c,cached:!!(c&&c===l)}}function we(e,t){const{id:i,isLoaded:n,error:o,resource:r,requestId:s,cached:a}=oe(e,t);return{id:i,isLoaded:n,error:o,manifest:r,requestId:s,cached:a}}function $(e,t=[]){const i=I(),[n,o]=h.useState(()=>e(i.getState(),i));return h.useEffect(()=>i.subscribe(r=>e(r,i),r=>{o(r)},!1),t),n}const Q=A.default.createContext([]);function xe(){const e=h.useContext(Q);return $(t=>e.map(i=>t.iiif.entities.Canvas[i]).filter(Boolean),[e])}const te=()=>{},Y=h.createContext({setCurrentCanvasId:te,setCurrentCanvasIndex:te,nextCanvas:te,previousCanvas:te,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),li=e=>{const t=we(e.manifest),[i,n]=h.useState(""),[o,r]=h.useState([]),s=(typeof e.pagingEnabled>"u"||e.pagingEnabled)&&t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");h.useEffect(()=>{var p,w;t.manifest&&(n((p=t.manifest.items[0])==null?void 0:p.id),r([(w=t.manifest.items[0])==null?void 0:w.id]))},[t.manifest,e.manifest]);const a=h.useMemo(()=>{var p;return((p=t.manifest)==null?void 0:p.items.map(w=>w.id))||[]},[t.manifest,e.manifest]),l=h.useMemo(()=>a.indexOf(i),[a,i]),c=h.useCallback(()=>{if(a.length&&i){if(l===-1||(a[l+2]?l+2===a.length:l===a.length))return;const p=s&&l!==0?a[l+2]:a[l+1],w=s?l!==0?a[l+3]:a[l+2]:null;p&&(n(p),r(w?[p,w]:[p]))}},[s,a,i,l]),u=h.useCallback(()=>{if(a.length&&i){if(l===0||l===-1)return;const p=s&&l!==1?a[l-2]:a[l-1],w=s&&l!==1?a[l-1]:null;p&&(n(p),r(w?[p,w]:[p]))}},[s,a,i,l]),d=h.useCallback(p=>{const w=s&&p%2===1?p-1:p,C=a[w],F=s&&w!==0?a[w+1]:null;C&&(n(C),r(f=>{const y=F?[C,F]:[C];if(f.length===f.length){for(let x=0;x<f.length;x++)if(f[x]!==y[x])return y;return f}return y}))},[s,a]),v=h.useCallback(p=>{const w=a.indexOf(p);w!==-1&&d(w)},[a,d]),m=h.useMemo(()=>({setCurrentCanvasId:v,nextCanvas:c,previousCanvas:u,currentCanvasIndex:l,totalCanvases:a.length,setCurrentCanvasIndex:d,pagingView:!0}),[c,u,l,a,d,v]);return t.manifest?t.isLoaded?A.default.createElement(Y.Provider,{value:m},A.default.createElement(Q.Provider,{value:o},A.default.createElement(ve,{manifest:t.manifest.id},A.default.createElement(me,{canvas:i},e.children)))):A.default.createElement("div",null,"Loading..."):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),A.default.createElement("div",null,"Sorry, something went wrong."))};function ci(){return h.useContext(Y)}function ui(){return{VaultContext:h.useContext(U),ResourceContext:h.useContext(ee),SimpleViewerReactContext:h.useContext(Y),VisibleCanvasReactContext:h.useContext(Q)}}const fi=e=>A.default.createElement(ye,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},A.default.createElement(Q.Provider,{value:e.bridge.VisibleCanvasReactContext},A.default.createElement(Y.Provider,{value:e.bridge.SimpleViewerReactContext},e.children)));function W(e){return e.endsWith("info.json")?e:e.endsWith("/")?`${e}info.json`:`${e}/info.json`}const hi="http://library.stanford.edu/iiif/image-api/compliance.html#level0",Se="http://library.stanford.edu/iiif/image-api/compliance.html#level1",be="http://library.stanford.edu/iiif/image-api/compliance.html#level2",di="http://library.stanford.edu/iiif/image-api/conformance.html#level0",Oe="http://library.stanford.edu/iiif/image-api/conformance.html#level1",Ae="http://library.stanford.edu/iiif/image-api/conformance.html#level2",pi="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Ce="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Pe="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",gi="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",_e="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Ie="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",mi="http://iiif.io/api/image/1/level0.json",vi="http://iiif.io/api/image/1/profiles/level0.json",Ee="http://iiif.io/api/image/1/level1.json",$e="http://iiif.io/api/image/1/profiles/level1.json",je="http://iiif.io/api/image/1/level2.json",Me="http://iiif.io/api/image/1/profiles/level2.json",yi="http://iiif.io/api/image/2/level0.json",wi="http://iiif.io/api/image/2/profiles/level0.json",Te="http://iiif.io/api/image/2/level1.json",Fe="http://iiif.io/api/image/2/profiles/level1.json",ke="http://iiif.io/api/image/2/level2.json",Ve="http://iiif.io/api/image/2/profiles/level2.json",xi="level0",We="level1",Le="level2",Si="http://iiif.io/api/image/2/level0",ze="http://iiif.io/api/image/2/level1",Re="http://iiif.io/api/image/2/level2",Be=[Re,be,Ae,Pe,Ie,je,Me,ke,Ve,Le],He=[...Be,ze,Se,Oe,Ce,_e,Ee,$e,Te,Fe,We],bi=[Si,ze,Re,hi,Se,be,di,Oe,Ae,pi,Ce,Pe,gi,_e,Ie,mi,vi,Ee,$e,je,Me,yi,wi,Te,Fe,ke,Ve,xi,We,Le],Oi={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},Ai={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},Ci={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function Pi(e){return Be.indexOf(e)!==-1?Ci:He.indexOf(e)!==-1?Ai:Oi}function _i(e){const t=e?Array.isArray(e.profile)?e.profile:[e.profile]:[],i={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let n of t)if(typeof n=="string"&&(n=Pi(n)),!!n){if(n.formats)for(const o of n.formats)i.extraFormats.indexOf(o)===-1&&i.extraFormats.push(o);if(n.qualities)for(const o of n.qualities)i.extraQualities.indexOf(o)===-1&&i.extraQualities.push(o);if(n.supports)for(const o of n.supports)i.extraFeatures.indexOf(o)===-1&&i.extraFeatures.push(o);if(n.maxHeight&&(i.maxHeight=n.maxHeight),n.maxWidth&&(i.maxWidth=n.maxWidth),n.maxArea&&(i.maxArea=n.maxArea),n.extraFormats)for(const o of n.extraFormats)i.extraFormats.indexOf(o)===-1&&i.extraFormats.push(o);if(n.extraQualities)for(const o of n.extraQualities)i.extraQualities.indexOf(o)===-1&&i.extraQualities.push(o);if(n.extraFeatures)for(const o of n.extraFeatures)i.extraFeatures.indexOf(o)===-1&&i.extraFeatures.push(o);n.maxHeight&&(i.maxHeight=n.maxHeight),n.maxWidth&&(i.maxWidth=n.maxWidth),n.maxArea&&(i.maxArea=n.maxArea)}if(e.extraFormats)for(const n of e.extraFormats)i.extraFormats.indexOf(n)===-1&&i.extraFormats.push(n);if(e.extraFeatures)for(const n of e.extraFeatures)i.extraFeatures.indexOf(n)===-1&&i.extraFeatures.push(n);if(e.extraQualities)for(const n of e.extraQualities)i.extraQualities.indexOf(n)===-1&&i.extraQualities.push(n);return i}function Ii(e){try{if(e==="full")return{full:!0};if(e==="square")return{square:!0};const t=e.startsWith("pct:"),i=e.substr(t?4:0).split(",").map(n=>parseFloat(n));return{x:i[0],y:i[1],w:i[2],h:i[3],percent:t}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+e)}}function Ei(e){const t={upscaled:!1,max:!1,confined:!1};if(e[0]==="^"&&(t.upscaled=!0,e=e.slice(1)),e==="max"||e==="full")return t.max=!0,t.serialiseAsFull=e==="full",t;if(e[0]==="!"&&(t.confined=!0,e=e.slice(1)),e[0]==="p")return t.percentScale=parseFloat(e.slice(4)),t;const i=e.split(",").map(n=>n.trim());return i.length&&(i[0]!==""&&(t.width=parseInt(i[0],10)),i[1]!==""&&(t.height=parseInt(i[1],10))),t}function $i(e){const t={angle:0};if(e[0]==="!"&&(t.mirror=!0,e=e.substr(1)),t.angle=parseFloat(e)%360,Number.isNaN(t.angle))throw new Error(`Invalid rotation ${e}`);return t}function ji(e,t=""){const i=e.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!i)throw new Error(`Invalid or unknown input ${e}`);const n=i[2],o=i[3];let r=i[4];if(r[0]==="/"&&(r=r.substr(1)),t.length>0){if(t[0]==="/"&&(t=t.substr(1)),t!==r.substr(0,t.length))throw new Error(`Path does not start with prefix (path: ${r}, prefix: ${t})`);r=r.substr(t.length)}return{scheme:n,server:o,path:r,prefix:t}}function Mi(e,t=""){const{path:i,scheme:n,server:o,prefix:r}=ji(e,t),s=i.split("/").reverse(),[a,l,c,u,...d]=s,v=d.reverse().filter(Boolean).join("/");if(s.length===1||a==="")return{type:"base",scheme:n,server:o,prefix:r,identifier:v};if(a==="info.json"){const[,...p]=s;return{type:"info",scheme:n,server:o,prefix:r,identifier:p.reverse().filter(Boolean).join("/")}}const m=a.split(".");return{type:"image",scheme:n,server:o,prefix:r,identifier:v,originalPath:i,region:Ii(u),size:Ei(c),rotation:$i(l),quality:m[0],format:m[1]}}function Ti(e){const t=Mi(W(e.id));if(t.type!=="info")throw new Error("Invalid service URL");const i=_i(e);return{identifier:t.identifier,originalPath:"",server:t.server,prefix:t.prefix,scheme:t.scheme,type:"image",quality:i.extraQualities.indexOf("default")===-1?i.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}}function Fi(e,t,i){const n=i.length,o=[];for(let r=0;r<n;r++){const s=i[r].width;o.push(e/s)}return o}function ki(e,t,i){const n=i.length,o=[];for(let r=0;r<n;r++){const s=i[r];o.push({width:Math.floor(e/s),height:Math.floor(t/s)})}return o}function S(e){if(e["@id"])return e["@id"];if(e.id)return e.id}function se(e){if(!e||!e.profile||!S(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if(typeof i=="string"&&bi.indexOf(i)!==-1)return!0;return!1}function Vi(e){if(!se(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if(typeof i=="string"){if(He.indexOf(i)!==-1)return!0}else{const n=[...i.supports||[],...i.extraFeatures||[]];if(n.indexOf("regionByPx")!==-1&&(n.indexOf("sizeByW")!==-1||n.indexOf("sizeByWh")!==-1))return!0}return!1}function Wi(e){if(!Vi(e))return[];const t=[],i=Array.isArray(e.profile)?e.profile:[e.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:S(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 s=e.tiles[r];(s.height||s.width)&&t.push({id:S(e),type:"variable",minHeight:0,minWidth:0,maxHeight:s.height||s.width,maxWidth:s.width})}}return t}function De(e){const t=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,i=e.match(t);if(i){const n=i[1],o=parseInt(i[4],10),r=parseInt(i[5],10),s=i[7];if((n==="max"||n==="full")&&o&&r&&s)return{type:"fixed",id:e,height:r,width:o}}return{type:"unknown",id:e}}function Li(e){if(e["@type"])return e["@type"];if(e.type)return e.type}function zi(e){if(typeof e=="string")return De(e);const t=Li(e);if(t!=="Image"&&t!=="sc:Image")return null;const i=e,n=S(i);return n?n&&i.width&&i.height?{id:n,type:"fixed",width:i.width,height:i.height,unsafe:!0}:De(n):null}function Ri(e){return se(e)?(e&&e.sizes?e.sizes:[]).map(t=>({id:S(e),type:"fixed-service",height:t.height,width:t.width})):[]}function qe(e){const t=[],i=e.length;for(let n=0;n<i;n++){const o=Ri(e[n]);o.length&&t.push(...o);const r=Wi(e[n]);r.length&&t.push(...r)}return t}function G(e){const t=e.service?Array.isArray(e.service)?e.service:[e.service]:[],i=t.length,n=[];for(let o=0;o<i;o++)se(t[o])&&n.push(t[o]);return n}function Bi(e,t=!0,i){const n=[],o=zi(e);if(o===null)return n;const r=e;if(n.push(o),t&&r.width&&r.height){const s=[],a=G(r);for(const l of a){const c={id:S(l),width:r.width,height:r.height};if(i.canLoadSync(c)){const u=i.loadServiceSync(c);u&&(u.height||(u.height=r.height),u.width||(u.width=r.width),s.push(...qe([u])))}}if(s.length)return n.push(...s),n}return r.service&&n.push(...qe(r.service)),n}function Hi({x:e=0,y:t=0,w:i,h:n,full:o,square:r,percent:s}){if(o)return"full";if(r)return"square";if(typeof i>"u"||typeof n>"u")throw new Error("RegionParameter: invalid region");const a=`${e},${t},${i},${n}`;return s?`pct:${a}`:a}function Di({max:e,percentScale:t,upscaled:i,confined:n,width:o,height:r,serialiseAsFull:s}){const a=[];return i&&a.push("^"),e?(a.push(s?"full":"max"),a.join("")):(n&&a.push("!"),t&&a.push(`pct:${t}`),o&&a.push(`${o}`),a.push(","),r&&a.push(`${r}`),a.join(""))}function qi(e){return`${e.mirror?"!":""}${(e.angle||0)%360}`}var Ni=Object.defineProperty,Ui=Object.defineProperties,Qi=Object.getOwnPropertyDescriptors,Ne=Object.getOwnPropertySymbols,Yi=Object.prototype.hasOwnProperty,Gi=Object.prototype.propertyIsEnumerable,Ue=(e,t,i)=>t in e?Ni(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Z=(e,t)=>{for(var i in t||(t={}))Yi.call(t,i)&&Ue(e,i,t[i]);if(Ne)for(var i of Ne(t))Gi.call(t,i)&&Ue(e,i,t[i]);return e},J=(e,t)=>Ui(e,Qi(t));function Zi(e,t){const i=e.prefix.startsWith("/")?e.prefix.substr(1):e.prefix,n=`${e.scheme}://${e.server}/${i?`${i}/`:""}${e.identifier}`;if(e.type==="base")return n;if(e.type==="info")return`${n}/info.json`;let{region:o,size:r,rotation:s,format:a,quality:l}=e;if(t){const c=t["@context"]?Array.isArray(t["@context"])?t["@context"]:[t["@context"]]:[],u=c.indexOf("http://iiif.io/api/image/2/context.json")!==-1,d=c.indexOf("http://iiif.io/api/image/3/context.json")!==-1;if((r.width===t.width&&!r.height||r.height===t.height&&!r.width||r.width===t.width&&r.height===t.height)&&(r=J(Z({},r),{max:!0})),u&&(r.max&&!r.serialiseAsFull&&(r=J(Z({},r),{serialiseAsFull:!0})),!r.max&&r.width&&r.height&&(r=J(Z({},r),{height:void 0}))),d&&(r.max&&r.serialiseAsFull&&(r=J(Z({},r),{serialiseAsFull:!1})),r.width&&!r.height&&t.width&&t.height)){const v=t.height/t.width;r=J(Z({},r),{height:Math.ceil(r.width*v)})}}return[n,Hi(o),Di(r),qi(s),`${l}.${a}`].filter(Boolean).join("/")}function ae(e,t,i){const n=Ti({id:W(S(e)),profile:"level2",type:"ImageService2"});if(n.type!=="image")throw new Error("Invalid service");return n.size.max=!1,n.size.width=t,n.size.height=i,{id:Zi(n),type:"fixed",width:t,height:i||e.height/(e.width||1)*t,unsafe:e.width>t}}function z(e){const t=e.replace(/(https?:\/\/)?(www.)?/i,"");return t.indexOf("/")!==-1?t.split("/")[0]:t}function Ji(e,t,i){const n=e.width?e.width:e.maxWidth;return i.height<=e.maxHeight&&i.width<=e.maxWidth&&i.height>=e.minHeight&&i.width>=e.minWidth&&(!t||Math.abs(i.width-n)<Math.abs(t.width-n))}function Xi(e,t){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},e),o=[],r=[];let s=null;const a=(c,u)=>{if(Ji(n,u,c)){if(n.preferFixedSize&&c.unsafe){r.push(c);return}n.returnAllOptions&&u&&r.push(u),s=c}else n.returnAllOptions&&r.push(c)},l=t.length;for(let c=0;c<l;c++){const u=t[c](),d=u.length;for(let v=0;v<d;v++){const m=u[v];if(m.type==="unknown"&&n.atAnyCost&&o.push(m),m.type==="fixed"&&(m.unsafe?o.push(m):a(m,s)),m.type==="fixed-service")if(n.unsafeImageService){const p=ae(m,n.width,n.height);a(p,s)}else{const p=ae(m,m.width,m.height);a(p,s)}if(m.type==="variable"&&m.maxWidth){const p=ae({id:m.id,type:"fixed-service",width:m.maxWidth,height:m.maxWidth},m.maxWidth);a(p,s)}}if(s&&!n.returnAllOptions){if(s.unsafe||n.allowUnsafe)continue;break}}return n.atAnyCost&&r.length===0?{best:s||o[0],fallback:o.slice(1),log:i}:n.returnAllOptions?{best:n.atAnyCost?s||r[0]||o[0]:s||r[0],fallback:[...r,...o],log:i}:{best:s||r[0]||null,fallback:s?r:r.slice(1),log:i}}var Ki=Object.defineProperty,en=Object.defineProperties,tn=Object.getOwnPropertyDescriptors,Qe=Object.getOwnPropertySymbols,nn=Object.prototype.hasOwnProperty,rn=Object.prototype.propertyIsEnumerable,Ye=(e,t,i)=>t in e?Ki(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,on=(e,t)=>{for(var i in t||(t={}))nn.call(t,i)&&Ye(e,i,t[i]);if(Qe)for(var i of Qe(t))rn.call(t,i)&&Ye(e,i,t[i]);return e},sn=(e,t)=>en(e,tn(t));function an(e,t,i){const n=e>t?e:t,o=i.length,r=[];for(let s=0;s<o;s++){const a=i[s];let l=a.scaleFactors[0],c=n/l;const u=[l];for(;c>=a.width;)l=l*2,u.push(l),c=c/2;r.push(sn(on({},a),{scaleFactors:u}))}return r}function ln(e,t){if(e.length!==t.length)return!1;if(e.length===0&&t.length===0)return!0;const i=e.length;let n=!0;for(let r=0;r<i;r++){const s=e[r],a=t[r];if(s.width!==a.width||s.height!==a.height){n=!1;break}}if(n)return!0;let o=0;for(let r=0;r<i;r++)for(let s=0;s<i;s++)if(e[r].width===t[s].width&&e[r].height===t[s].height){o++;break}return o===i}var L=(e,t,i)=>new Promise((n,o)=>{var r=l=>{try{a(i.next(l))}catch(c){o(c)}},s=l=>{try{a(i.throw(l))}catch(c){o(c)}},a=l=>l.done?n(l.value):Promise.resolve(l.value).then(r,s);a((i=i.apply(e,t)).next())});class Ge{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,i,n=!0){const o=z(S(t)),r=W(S(t)),s=this.knownImageServers[o];return this.imageServices[r]=Object.assign(t,{real:!0}),s?this.verify(t):(this.knownImageServers[o]={verifications:0,malformed:!1,root:o,preLoaded:n,sampledId:S(t),verified:!1,server:null,result:{context:t["@context"]||[],sampledProfile:t.profile,resourceServiceRatio:i&&t.height?i.height/t.height:1,sampledSizes:t.sizes||[],sizeRatios:Fi(t.width,t.height,t.sizes||[]),sampledTiles:t.tiles||[]}},!0)}preLoad(t,i=!0){this.knownImageServers[t.root]=t,i&&(this.knownImageServers[t.root].malformed=!1,this.knownImageServers[t.root].verifications=this.config.verificationsRequired)}predict(t,i=!1,n=!1){const o=z(S(t)),r=this.knownImageServers[o];if(!r||!r.result||!n&&(r.malformed||r.verifications<this.config.verificationsRequired))return null;const s=W(S(t));return this.imageServices[s]||(this.imageServices[s]={"@context":r.result.context,"@id":S(t),id:S(t),protocol:"http://iiif.io/api/image",tiles:an(t.width,t.height,r.result.sampledTiles),sizes:ki(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[s]}getThumbnailFromResource(t,i){return L(this,arguments,function*(n,o,r=!0,s=[]){const a=yield this.getImageCandidates(n,r);return Xi(o,[()=>s,()=>a])})}getImageCandidates(t,i=!0){return L(this,null,function*(){const n=t;if(i&&n.height&&n.width){const o=G(n);for(const r of o){const s={id:S(r),width:r.width?r.width:n.width,height:r.height?r.height:n.height};yield this.loadService(s)}}return Bi(t,i,this)})}verify(t){return L(this,null,function*(){const i=this.predict(t,!1,!0),n=yield this.fetchService(S(t));if(!i)return!1;const o=i.height===n.height&&i.width===n.width&&i["@context"]===n["@context"]&&ln(i.sizes||[],n.sizes||[]);if(o){const r=z(S(t));this.knownImageServers[r].verifications+=1,this.knownImageServers[r].verifications>=this.config.verificationsRequired&&(this.knownImageServers[r].verified=!0)}return o})}canLoadSync(t){const i=typeof t=="string"?t:S(t),n=W(i);if(this.imageServices[n])return!0;const o=this.knownImageServers[z(i)];return o&&!o.malformed&&o.verifications>=this.config.verificationsRequired}markAsMalformed(t){return L(this,null,function*(){return this.knownImageServers[z(S(t))].malformed=!0,this.loadService(t,!0)})}fetchService(t,i=!1){return L(this,null,function*(){const n=W(t);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 this.fetch(n).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[n]=Object.assign(o,{real:!0}),this.imageServices[n]})}fetch(t,i){return L(this,null,function*(){return fetch(t,i)})}loadService(t,i=!1){return L(this,null,function*(){if(!this.config.disableThrottling){let r=!0;for(;r;)if(this.fetchingCount>=this.config.verificationsRequired)yield new Promise(s=>setTimeout(s,500));else{r=!1;break}}const n=this.knownImageServers[z(S(t))];if(n&&!n.malformed&&!i){yield n.result;const r=this.loadServiceSync(t);if(r)return r}this.fetchingCount++;const o=yield this.fetchService(S(t),i);return this.fetchingCount--,o.real&&this.sample(o,t),o})}loadServiceSync(t){const i=W(S(t));return this.imageServices[i]?this.imageServices[i]:this.predict(t)}}new Ge;const Ze=A.default.createContext(new Ge);function ie(){return h.useContext(Ze)}const cn=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,un=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function ne(e){if(Array.isArray(e))return e.reduce((t,i)=>{const{selector:n,selectors:o}=ne(i);return n&&(t.selector||(t.selector=n),t.selectors.push(...o)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,i]=e.split("#");return i?ne({type:"FragmentSelector",value:i}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=cn.exec(e.value);if(t){const n={type:"BoxSelector",spatial:{unit:t[2]==="percent:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:n,selectors:[n]}}const i=e.value.match(un);if(i){const n={type:"TemporalSelector",temporal:{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 fn=Object.defineProperty,hn=Object.defineProperties,dn=Object.getOwnPropertyDescriptors,Je=Object.getOwnPropertySymbols,pn=Object.prototype.hasOwnProperty,gn=Object.prototype.propertyIsEnumerable,Xe=(e,t,i)=>t in e?fn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Ke=(e,t)=>{for(var i in t||(t={}))pn.call(t,i)&&Xe(e,i,t[i]);if(Je)for(var i of Je(t))gn.call(t,i)&&Xe(e,i,t[i]);return e},et=(e,t)=>hn(e,dn(t));function T(e,t={}){if(Array.isArray(e))return T(e[0]);if(typeof e=="string"){const[i,n]=e.split("#");return n?T({type:"SpecificResource",source:{id:i,type:"Unknown"},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{id:i,type:t.typeMap&&t.typeMap[i]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return T(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:i,selectors:n}=e.selector?ne(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:i,selectors:n}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[i,n]=e.id.split("#");return n?T({type:"SpecificResource",source:et(Ke({},e),{id:i}),selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:et(Ke({},e),{id:i}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function tt(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function it(e,t,i){const n=[];let o=null;const r=[];for(const s of t){const a=e.get(s.body);for(const l of a){const[c,{selector:u}]=tt(l),d=(c.type||"unknown").toLowerCase();if(d==="choice"){const v=e.get(c.items),m=i.length?i.map(p=>v.find(w=>w.id===p)).filter(Boolean):[v[0]];m.length===0&&m.push(v[0]),o={type:"single-choice",items:v.map(p=>({id:p.id,label:p.label,selected:m.indexOf(p)!==-1})),label:l.label},a.push(...m);continue}n.indexOf(d)===-1&&n.push(d),r.push({type:d,resource:c,target:s.target,selector:u})}}return{types:n,items:r,choice:o}}const nt={makeChoice:()=>{}},le={type:"unknown"},j=e=>({type:"unknown",reason:e,annotations:{pages:[]}});function rt(e,t,i){const n=[];for(const o of t.items){const r=o.resource&&o.resource.type==="SpecificResource"?o.resource.source:o.resource;if(!r.id)return j("No resource Identifier");let s;if(r.service){const w=G(r);w[0]&&(s=i(w[0],e))}const{selector:a,source:l}=T(o.target);if(l.id!==e.id)continue;const c={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},u=a?a.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:a.temporal,spatial:c.spatial}:a:null,d={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},v=o.resource.type==="SpecificResource"?T(o.resource):null,m=v&&v.selector&&(v.selector.type==="BoxSelector"||v.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:v.selector.spatial.x,y:v.selector.spatial.y,width:v.selector.spatial.width,height:v.selector.spatial.height}}:d,p={id:r.id,type:"Image",width:u?r.width:e.width,height:u?r.height:e.height,service:s,sizes:s&&s.sizes?s.sizes:r.width&&r.height?[{width:r.width,height:r.height}]:[],target:u&&u.type!=="PointSelector"?u:c,selector:m};n.push(p)}return{type:"images",image:n[0],images:n,choice:t.choice}}var mn=Object.defineProperty,vn=Object.defineProperties,yn=Object.getOwnPropertyDescriptors,ot=Object.getOwnPropertySymbols,wn=Object.prototype.hasOwnProperty,xn=Object.prototype.propertyIsEnumerable,st=(e,t,i)=>t in e?mn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Sn=(e,t)=>{for(var i in t||(t={}))wn.call(t,i)&&st(e,i,t[i]);if(ot)for(var i of ot(t))xn.call(t,i)&&st(e,i,t[i]);return e},bn=(e,t)=>vn(e,yn(t));function On(e={},t=[]){const{id:i,selector:n}=e,o=k(),r=I(),s=i||o.annotation,a=$(c=>s?c.iiif.entities.Annotation[s]:void 0,[s]),l=$(c=>a&&a.body?a.body.map(u=>u?c.iiif.entities[u.type][u.id]:null).filter(Boolean):[],[a]);return h.useMemo(()=>{if(!a)return;const c=bn(Sn({},a),{body:l,target:T(a.target,{typeMap:r.getState().iiif.mapping})});return n?n(c):c},[a,n,l,...t])}function X(e={},t=[]){const{id:i,selector:n}=e,o=k();I();const r=i||o.manifest,s=$(a=>r?a.iiif.entities.Manifest[r]:void 0,[r]);return h.useMemo(()=>{if(!!s)return n?n(s):s},[s,n,...t])}function R(e={},t=[]){const{id:i,selector:n}=e,o=k(),r=i||o.canvas,s=$(a=>r?a.iiif.entities.Canvas[r]:void 0,[r]);return h.useMemo(()=>{if(!!s)return n?n(s):s},[s,n,...t])}function An(e,t){var i;const n=(i=e==null?void 0:e.iiif)==null?void 0:i.meta[t];return n?n.annotationPageManager:null}function Cn(e,t){return $(i=>{const n=[];if(!e)return n;const o=Object.keys(i.iiif.entities.AnnotationPage);for(const r of o)if(!t||t.indexOf(r)!==-1){const s=An(i,r);s&&s.views&&s.views[e]&&n.push(r)}return n},[e,t])}function at({canvas:e,manifest:t,all:i,canvases:n}){const o=[];if(t)for(const r of t.annotations)o.indexOf(r.id)===-1&&o.push(r.id);if(i){if(n&&n.length)for(const r of n)for(const s of r.annotations)o.indexOf(s.id)===-1&&o.push(s.id)}else if(e)for(const r of e.annotations)o.indexOf(r.id)===-1&&o.push(r.id);return o}var Pn=Object.defineProperty,_n=Object.defineProperties,In=Object.getOwnPropertyDescriptors,lt=Object.getOwnPropertySymbols,En=Object.prototype.hasOwnProperty,$n=Object.prototype.propertyIsEnumerable,ct=(e,t,i)=>t in e?Pn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,ut=(e,t)=>{for(var i in t||(t={}))En.call(t,i)&&ct(e,i,t[i]);if(lt)for(var i of lt(t))$n.call(t,i)&&ct(e,i,t[i]);return e},ft=(e,t)=>_n(e,In(t));function jn(e,t){var i;const n=(i=e==null?void 0:e.iiif)==null?void 0:i.meta[t];return n?n.annotationPageManager:null}function ht(e,t={}){const i=I(),n=X(),o=R(),r=xe(),s=h.useMemo(()=>at({all:t.all,manifest:n,canvas:o,canvases:r}),[t.all,o,r,n]),a=Cn(e,t.all?void 0:s),l=h.useCallback(u=>{!e||i.setMetaValue([u,"annotationPageManager","views"],d=>d&&!d[e]?d:ft(ut({},d||{}),{[e]:!1}))},[e,i]),c=h.useCallback((u,d={})=>{if(!e)return;const v=i.getState(),m=[];if(d==null?void 0:d.deselectOthers){const p=Object.keys(v.iiif.entities.AnnotationPage);for(const w of p){const C=jn(v,w);C&&C.views&&C.views[e]&&m.push(w)}}for(const p of m)l(p);i.setMetaValue([u,"annotationPageManager","views"],p=>p&&p[e]?p:ft(ut({},p||{}),{[e]:!0}))},[e,l,i]);return{availablePageIds:s,enabledPageIds:a,setPageEnabled:c,setPageDisabled:l}}function re(e={}){const t=R(e.canvasId?{id:e.canvasId}:void 0);return $((i,n)=>{if(!t)return[];const o=n.get(t.items),r=[];for(const s of o)r.push(...n.get(s.items));return r},[t])}function Mn(e,t={}){return re(t)}function Tn(e,t=!1){}function Fn(e,t=[]){const{id:i,selector:n}=e,o=k(),r=i||o.collection,s=$(a=>r?a.iiif.entities.Collection[r]:void 0,[r]);return h.useMemo(()=>{if(!!s)return n?n(s):s},[s,n,...t])}function dt(){const t=I().getStore();return h.useMemo(()=>i=>t.dispatch(i),[t])}function pt(e){return{addEventListener(t,i,n,o){if(t)return e.setMetaValue([t.id,"eventManager",i],r=>{const s=r||[];for(const a of s)if(a.callback===n)return s;return[...s,{callback:n,scope:o}]}),n},removeEventListener(t,i,n){!t||e.setMetaValue([t.id,"eventManager",i],o=>(o||[]).filter(r=>r.callback!==n))},getListenersAsProps(t,i){const n=typeof t=="string"?{id:t}:t;if(!n||!n.id)return{};const o=e.getResourceMeta(n.id,"eventManager"),r={};if(o&&n)for(const s of Object.keys(o))r[s]=a=>{const l=e.get(n);for(const{callback:c,scope:u}of o[s]||[])(!u||i&&u.indexOf(i)!==-1)&&c(a,l)};return r}}}function gt(e){return{applyStyles(t,i,n){const o=typeof t=="string"?t:t.id;return e.setMetaValue([o,"styles",i],n)},getAppliedStyles(t){const i=typeof t=="string"?t:t.id;return e.getResourceMeta(i,"styles")}}}function B(e){return e.endsWith("info.json")?e:e.endsWith("/")?`${e}info.json`:`${e}/info.json`}function kn(e,t,i){const n=i.length,o=[];for(let r=0;r<n;r++){const s=i[r].width;o.push(e/s)}return o}function Vn(e,t,i){const n=i.length,o=[];for(let r=0;r<n;r++){const s=i[r];o.push({width:Math.floor(e/s),height:Math.floor(t/s)})}return o}const Wn="http://library.stanford.edu/iiif/image-api/compliance.html#level0",mt="http://library.stanford.edu/iiif/image-api/compliance.html#level1",vt="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Ln="http://library.stanford.edu/iiif/image-api/conformance.html#level0",yt="http://library.stanford.edu/iiif/image-api/conformance.html#level1",wt="http://library.stanford.edu/iiif/image-api/conformance.html#level2",zn="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",xt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",St="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Rn="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",bt="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",Bn="http://iiif.io/api/image/1/level0.json",Hn="http://iiif.io/api/image/1/profiles/level0.json",At="http://iiif.io/api/image/1/level1.json",Ct="http://iiif.io/api/image/1/profiles/level1.json",Pt="http://iiif.io/api/image/1/level2.json",_t="http://iiif.io/api/image/1/profiles/level2.json",Dn="http://iiif.io/api/image/2/level0.json",qn="http://iiif.io/api/image/2/profiles/level0.json",It="http://iiif.io/api/image/2/level1.json",Et="http://iiif.io/api/image/2/profiles/level1.json",$t="http://iiif.io/api/image/2/level2.json",jt="http://iiif.io/api/image/2/profiles/level2.json",Nn="level0",Mt="level1",Tt="level2",Un="http://iiif.io/api/image/2/level0",Ft="http://iiif.io/api/image/2/level1",kt="http://iiif.io/api/image/2/level2",Qn=[Ft,kt,mt,vt,yt,wt,xt,St,bt,Ot,At,Ct,Pt,_t,It,Et,$t,jt,Mt,Tt],Yn=[Un,Ft,kt,Wn,mt,vt,Ln,yt,wt,zn,xt,St,Rn,bt,Ot,Bn,Hn,At,Ct,Pt,_t,Dn,qn,It,Et,$t,jt,Nn,Mt,Tt];function b(e){if(e["@id"])return e["@id"];if(e.id)return e.id}function ce(e){if(!e||!e.profile||!b(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if(typeof i=="string"&&Yn.indexOf(i)!==-1)return!0;return!1}function Gn(e){if(!ce(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if(typeof i=="string"){if(Qn.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 Zn(e){if(!Gn(e))return[];const t=[],i=Array.isArray(e.profile)?e.profile:[e.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:b(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 s=e.tiles[r];(s.height||s.width)&&t.push({id:b(e),type:"variable",minHeight:0,minWidth:0,maxHeight:s.height||s.width,maxWidth:s.width})}}return t}function Vt(e){const t=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,i=e.match(t);if(i){const n=i[1],o=parseInt(i[4],10),r=parseInt(i[5],10),s=i[7];if((n==="max"||n==="full")&&o&&r&&s)return{type:"fixed",id:e,height:r,width:o}}return{type:"unknown",id:e}}function Jn(e){if(e["@type"])return e["@type"];if(e.type)return e.type}function ue(e){if(typeof e=="string")return Vt(e);const t=Jn(e);if(t!=="Image"&&t!=="sc:Image")return null;const i=e,n=b(i);return n?n&&i.width&&i.height?{id:n,type:"fixed",width:i.width,height:i.height,unsafe:!0}:Vt(n):null}function Xn(e){return ce(e)?(e&&e.sizes?e.sizes:[]).map(t=>({id:b(e),type:"fixed-service",height:t.height,width:t.width})):[]}function Wt(e){const t=[],i=e.length;for(let n=0;n<i;n++){const o=Xn(e[n]);o.length&&t.push(...o);const r=Zn(e[n]);r.length&&t.push(...r)}return t}function Lt(e){const t=e.service?Array.isArray(e.service)?e.service:[e.service]:[],i=t.length,n=[];for(let o=0;o<i;o++)ce(t[o])&&n.push(t[o]);return n}function Kn(e,t=!0,i){const n=[],o=ue(e);if(o===null)return n;const r=e;if(n.push(o),t&&r.width&&r.height){const s=[],a=Lt(r);for(const l of a){const c={id:b(l),width:r.width,height:r.height};if(i.canLoadSync(c)){const u=i.loadServiceSync(c);u&&(u.height||(u.height=r.height),u.width||(u.width=r.width),s.push(...Wt([u])))}}if(s.length)return n.push(...s),n}return r.service&&n.push(...Wt(r.service)),n}function fe(e,t,i){return{id:[B(b(e)).slice(0,-10),"full",[t,i||""].join(","),0,"default.jpg"].join("/"),type:"fixed",width:t,height:i||e.height/e.width*t,unsafe:e.width>t}}function H(e){const t=e.replace(/(https?:\/\/)?(www.)?/i,"");return t.indexOf("/")!==-1?t.split("/")[0]:t}function er(e,t,i){const n=e.width?e.width:e.maxWidth;return i.height<=e.maxHeight&&i.width<=e.maxWidth&&i.height>=e.minHeight&&i.width>=e.minWidth&&(!t||Math.abs(i.width-n)<Math.abs(t.width-n))}function tr(e,t){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},e),o=[],r=[];let s=null;const a=(c,u)=>{if(er(n,u,c)){if(n.preferFixedSize&&c.unsafe){r.push(c);return}n.returnAllOptions&&u&&r.push(u),s=c}else n.returnAllOptions&&r.push(c)},l=t.length;for(let c=0;c<l;c++){const u=t[c](),d=u.length;for(let v=0;v<d;v++){const m=u[v];if(m.type==="unknown"&&n.atAnyCost&&o.push(m),m.type==="fixed"&&(m.unsafe?o.push(m):a(m,s)),m.type==="fixed-service")if(n.unsafeImageService){const p=fe(m,n.width,n.height);a(p,s)}else{const p=fe(m,m.width,m.height);a(p,s)}if(m.type==="variable"&&m.maxWidth){const p=fe({id:m.id,type:"fixed-service",width:m.maxWidth,height:m.maxWidth},m.maxWidth);a(p,s)}}if(s&&!n.returnAllOptions){if(s.unsafe||n.allowUnsafe)continue;break}}return n.atAnyCost&&r.length===0?{best:s||o[0],fallback:o.slice(1),log:i}:n.returnAllOptions?{best:n.atAnyCost?s||r[0]||o[0]:s||r[0],fallback:[...r,...o],log:i}:{best:s||r[0]||null,fallback:s?r:r.slice(1),log:i}}function ir(e,t,i){const n=e>t?e:t,o=i.length,r=[];for(let s=0;s<o;s++){const a=i[s];let l=a.scaleFactors[0],c=n/l;const u=[l];for(;c>=a.width;)l=l*2,u.push(l),c=c/2;r.push(Object.assign(Object.assign({},a),{scaleFactors:u}))}return r}function nr(e,t){if(e.length!==t.length)return!1;if(e.length===0&&t.length===0)return!0;const i=e.length;let n=!0;for(let r=0;r<i;r++){const s=e[r],a=t[r];if(s.width!==a.width||s.height!==a.height){n=!1;break}}if(n)return!0;let o=0;for(let r=0;r<i;r++)for(let s=0;s<i;s++)if(e[r].width===t[s].width&&e[r].height===t[s].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,17 +11,4 @@
11
11
 
12
12
  See the Apache Version 2.0 License for specific language governing permissions
13
13
  and limitations under the License.
14
- ***************************************************************************** */function 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
- Copyright (c) Microsoft Corporation. All rights reserved.
16
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
17
- this file except in compliance with the License. You may obtain a copy of the
18
- License at http://www.apache.org/licenses/LICENSE-2.0
19
-
20
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
22
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
23
- MERCHANTABLITY OR NON-INFRINGEMENT.
24
-
25
- See the Apache Version 2.0 License for specific language governing permissions
26
- and limitations under the License.
27
- ***************************************************************************** */function 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})});
14
+ ***************************************************************************** */function D(e,t,i,n){function o(r){return r instanceof i?r:new i(function(s){s(r)})}return new(i||(i=Promise))(function(r,s){function a(u){try{c(n.next(u))}catch(d){s(d)}}function l(u){try{c(n.throw(u))}catch(d){s(d)}}function c(u){u.done?r(u.value):o(u.value).then(a,l)}c((n=n.apply(e,t||[])).next())})}class zt{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,i,n=!0){const o=H(b(t)),r=B(b(t)),s=this.knownImageServers[o];return this.imageServices[r]=Object.assign(t,{real:!0}),s?this.verify(t):(this.knownImageServers[o]={verifications:0,malformed:!1,root:o,preLoaded:n,sampledId:b(t),verified:!1,server:null,result:{context:t["@context"]||[],sampledProfile:t.profile,resourceServiceRatio:i&&t.height?i.height/t.height:1,sampledSizes:t.sizes||[],sizeRatios:kn(t.width,t.height,t.sizes||[]),sampledTiles:t.tiles||[]}},!0)}preLoad(t,i=!0){this.knownImageServers[t.root]=t,i&&(this.knownImageServers[t.root].malformed=!1,this.knownImageServers[t.root].verifications=this.config.verificationsRequired)}predict(t,i=!1,n=!1){const o=H(b(t)),r=this.knownImageServers[o];if(!r||!r.result||!n&&(r.malformed||r.verifications<this.config.verificationsRequired))return null;const s=B(b(t));return this.imageServices[s]||(this.imageServices[s]={"@context":r.result.context,"@id":b(t),id:b(t),protocol:"http://iiif.io/api/image",tiles:ir(t.width,t.height,r.result.sampledTiles),sizes:Vn(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[s]}getThumbnailFromResource(t,i,n=!0,o=[]){return D(this,void 0,void 0,function*(){const r=yield this.getImageCandidates(t,n);return tr(i,[()=>o,()=>r])})}getImageCandidates(t,i=!0){return D(this,void 0,void 0,function*(){const n=t;if(i&&n.height&&n.width){const o=Lt(n);for(const r of o){const s={id:b(r),width:r.width?r.width:n.width,height:r.height?r.height:n.height};yield this.loadService(s)}}return Kn(t,i,this)})}verify(t){return D(this,void 0,void 0,function*(){const i=this.predict(t,!1,!0),n=yield this.fetchService(b(t));if(!i)return!1;const o=i.height===n.height&&i.width===n.width&&i["@context"]===n["@context"]&&nr(i.sizes||[],n.sizes||[]);if(o){const r=H(b(t));this.knownImageServers[r].verifications+=1,this.knownImageServers[r].verifications>=this.config.verificationsRequired&&(this.knownImageServers[r].verified=!0)}return o})}canLoadSync(t){const i=typeof t=="string"?t:b(t),n=B(i);if(this.imageServices[n])return!0;const o=this.knownImageServers[H(i)];return o&&!o.malformed&&o.verifications>=this.config.verificationsRequired}markAsMalformed(t){return D(this,void 0,void 0,function*(){return this.knownImageServers[H(b(t))].malformed=!0,this.loadService(t,!0)})}fetchService(t,i=!1){return D(this,void 0,void 0,function*(){const n=B(t);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!==t&&(o.id=t,o["@id"]&&(o["@id"]=t)),this.imageServices[n]=Object.assign(o,{real:!0}),this.imageServices[n]})}loadService(t,i=!1){return D(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[H(b(t))];if(n&&!n.malformed&&!i){yield n.result;const r=this.loadServiceSync(t);if(r)return r}this.fetchingCount++;const o=yield this.fetchService(b(t),i);return this.fetchingCount--,o.real&&this.sample(o,t),o})}loadServiceSync(t){const i=B(b(t));return this.imageServices[i]?this.imageServices[i]:this.predict(t)}}new zt;function rr(e,t={}){const i=t.imageServiceLoader||new zt;async function n(o,r,s,a=[],l){if(typeof o=="string")return{best:ue(o),fallback:[],log:[]};const c=e.get(o);if(typeof c=="string")return{best:ue(c),fallback:[],log:[]};switch(c.type){case"Annotation":{const u=c.body,d=e.get(u[0]);return l&&!d.width&&(d.width=l.width,d.height=l.height),await i.getThumbnailFromResource(d,r,s,a)}case"Canvas":{const u=c;if(u.thumbnail&&u.thumbnail.length){const d=e.get(u.thumbnail[0]),v=await i.getImageCandidates(d,s);v&&v.length&&a.push(...v)}return n(u.items[0],r,s,a,{width:u.width,height:u.height})}case"AnnotationPage":return n(c.items[0],r,s,a,l);case"Choice":return n(c.items[0],r,s,a,l);case"Collection":{const u=c.items[0];return n(u,r,s,a,l)}case"Manifest":{const u=c.items[0];return n(u,r,s,a,l)}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return l&&!c.width&&(c.width=l.width,c.height=l.height),i.getThumbnailFromResource(c,r,s,a);case"Service":case"Range":case"AnnotationCollection":case"CanvasReference":case"ContentResource":return{best:void 0,fallback:[],log:[]}}return{best:void 0,fallback:[],log:[]}}return{getBestThumbnailAtSize:n}}function or(e,t,i,n,o=[]){const r=I(),s=h.useMemo(()=>pt(r),[r]);h.useEffect(()=>{const a=e;return a?(s.addEventListener(a,t,i,n),()=>{s.removeEventListener(a,t,i)}):()=>{}},[s,e,t,...o])}function sr(){const e=h.useContext(U);return e&&e.vault?e.vault:K.globalVault()}function ar(e,t){const{id:i,isLoaded:n,error:o,resource:r,requestId:s,cached:a}=oe(e,t);return{id:i,isLoaded:n,error:o,manifest:r,requestId:s,cached:a}}var lr=(e,t,i)=>new Promise((n,o)=>{var r=l=>{try{a(i.next(l))}catch(c){o(c)}},s=l=>{try{a(i.throw(l))}catch(c){o(c)}},a=l=>l.done?n(l.value):Promise.resolve(l.value).then(r,s);a((i=i.apply(e,t)).next())});function Rt({cacheKey:e}={}){const t=R(),i=re(),n=I(),o=ie(),[r,s]=h.useState(void 0),[a,l]=h.useState(!1),[c,u]=h.useState("idle"),[d,v]=h.useState(void 0),m=t?t.id:"undefined",p=h.useMemo(()=>{try{if(t&&i.length){const C=i[0],F=n.get(C.body[0]),y=G(F)[0];return y&&o.loadServiceSync({id:y.id||y["@id"],width:y.width||t.width,height:y.height||t.height})||void 0}}catch(C){console.error(C)}},[m,e,t]),w=c==="success"&&r?r:p;return h.useEffect(()=>{lr(this,null,function*(){try{if(t&&i.length){const C=i[0],F=n.get(C.body[0]),y=G(F)[0];if(!y)return;l(!0),u("loading");try{const x=(yield o.loadService({id:y.id||y["@id"],width:y.width||t.width,height:y.height||t.height}))||void 0;s(x),u("success"),l(!1)}catch(x){u("error"),v(x)}}}catch(C){u("error"),v(C)}})},[m,e]),h.useMemo(()=>({data:w,isFetching:a,status:c,error:d}),[w,a,c,d])}function cr(){const e=Rt();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 Bt(e,t=[]){const i=I(),n=re(),[o,r]=h.useState((e==null?void 0:e.defaultChoices)||[]),s=h.useMemo(()=>it(i,n,o),[i,n,o,...t]),l={makeChoice:h.useCallback((c,{deselectOthers:u=!0,deselect:d=!1}={})=>{if(s.choice){if(s.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");r(v=>{if(d){const p=v.filter(w=>w!==c);if(p.length===0){const w=s.items[0].resource.id;return w?[w]:[]}return p}if(u)return[c];const m=[...v];if(m.length===0&&s.items.length){const p=s.items[0].resource.id;p&&m.push(p)}return v.indexOf(c)!==-1?v:[...v,c]})}},[s.choice])};return[s,l]}function ur(e={},t=[]){const{id:i,selector:n}=e,o=k(),r=i||o.range,s=$(a=>r?a.iiif.entities.Range[r]:void 0,[r]);return h.useMemo(()=>{if(!!s)return n?n(s):s},[s,n,...t])}function fr(e,t){const i=I(),n=h.useMemo(()=>pt(i),[i]),o=$(()=>e&&e.id?i.getResourceMeta(e.id,"eventManager"):null,[e]);return h.useMemo(()=>e?n.getListenersAsProps(e,t):{},[o,e,i,t])}function Ht(e,t){return $((i,n)=>n.get(e.map(o=>({id:o,type:t}))),[e,t])}function hr(){const e=X();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function dr(){const e=I();return h.useMemo(()=>gt(e),[e])}function pr(e,t){const i=I(),n=h.useMemo(()=>gt(i),[i]);return $(()=>{if(!e)return null;const o=n.getAppliedStyles(e.id);return o?t?o[t]:o:void 0},[e,t])}const Dt=(e,t=[])=>{const i=I();h.useEffect(()=>{e(i)},[i,...t])};function gr(e,t,{canvasId:i,manifestId:n}={}){const o=I(),r=ie(),s=h.useMemo(()=>rr(o,{imageServiceLoader:r}),[o,r]),[a,l]=h.useState(),c=X(n?{id:n}:void 0),u=R(i?{id:i}:void 0),d=u||c,v=h.useRef(!1);if(h.useEffect(()=>()=>{v.current=!0},[]),!d)throw new Error("Must be called under a manifest or canvas context.");return Dt(m=>{s.getBestThumbnailAtSize(d,e,t).then(p=>{p.best&&!v.current&&l(p.best)})},[d]),a}var mr=Object.defineProperty,vr=Object.defineProperties,yr=Object.getOwnPropertyDescriptors,qt=Object.getOwnPropertySymbols,wr=Object.prototype.hasOwnProperty,xr=Object.prototype.propertyIsEnumerable,Nt=(e,t,i)=>t in e?mr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Ut=(e,t)=>{for(var i in t||(t={}))wr.call(t,i)&&Nt(e,i,t[i]);if(qt)for(var i of qt(t))xr.call(t,i)&&Nt(e,i,t[i]);return e},Qt=(e,t)=>vr(e,yr(t));function Yt(){const e=ie(),[t,i]=h.useState({}),n=h.useRef(!1);return h.useEffect(()=>()=>{n.current=!0},[]),[h.useCallback((r,{height:s,width:a})=>{if(r){const l=r.id||r["@id"],c=e.loadServiceSync({id:l,width:r.width||a,height:r.height||s});c?r=c:t[l]||(n.current||i(u=>Qt(Ut({},u),{[l]:"loading"})),e.loadService({id:l,width:r.width||a,height:r.height||s}).then(()=>{n.current||i(u=>Qt(Ut({},u),{[l]:"done"}))}))}return r},[e,t]),t]}var Sr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},P={exports:{}};(function(e,t){(function(i,n){n(t)})(Sr,function(i){function n(f){return f==null}function o(f){throw new Error("Argument "+f+" is empty.")}function r(f){return typeof f=="function"&&"getType"in f}function s(f){throw new Error("Argument "+f+' is invalid, it should be an action-creator instance from "typesafe-actions"')}function a(f,y){if(f==null)throw new Error("Argument contains array with empty element at index "+y);if(f.getType==null)throw new Error("Argument contains array with invalid element at index "+y+', it should be an action-creator instance from "typesafe-actions"')}function l(f){return typeof f=="string"||typeof f=="symbol"}function c(f){return!l(f)}function u(f){throw new Error("Argument "+f+" is invalid, it should be an action type of type: string | symbol")}function d(f,y){if(f==null)throw new Error("Argument contains array with empty element at index "+y);if(typeof f!="string"&&typeof f!="symbol")throw new Error("Argument contains array with invalid element at index "+y+", it should be of type: string | symbol")}function v(f,y,x,O){return n(f)&&o(1),c(f)&&s(1),{type:f,payload:y,meta:x,error:O}}function m(f,y){return n(f)&&o(1),c(f)&&u(1),Object.assign(function(){var x=y!=null?y.apply(void 0,arguments):void 0;return Object.assign({type:f},x)},{getType:function(){return f},toString:function(){return f}})}function p(f,y,x){return n(f)&&o(1),c(f)&&u(1),function(){return m(f,function(){var O=arguments.length<=0?void 0:arguments[0],E=arguments.length<=1?void 0:arguments[1];return y==null&&x==null||(O=y!=null?y.apply(void 0,arguments):void 0,E=x!=null?x.apply(void 0,arguments):void 0),Object.assign({},O!==void 0&&{payload:O},{},E!==void 0&&{meta:E})})}}function w(f){return n(f)&&o(1),r(f)||s(1),f.getType()}function C(f,y){n(f)&&o(1),c(f)&&u(1);var x=y!=null?y(f):function(){return{type:f}};return Object.assign(x,{getType:function(){return f},toString:function(){return f}})}var F={createAction:function(f,y){var x=y==null?function(){return v(f)}:y(v.bind(null,f));return Object.assign(x,{getType:function(){return f},toString:function(){return f}})},createCustomAction:C,createStandardAction:function(f){return n(f)&&o(1),c(f)&&u(1),Object.assign(function(){return C(f,function(y){return function(x,O){return{type:y,payload:x,meta:O}}})},{map:function(y){return C(f,function(x){return function(O,E){return Object.assign(y(O,E),{type:x})}})}})}};i.action=v,i.createAction=p,i.createAsyncAction=function(f,y,x,O){return function(){var E=[f,y,x,O].map(function(_,M){return Array.isArray(_)?p(_[0],_[1],_[2])():typeof _=="string"||typeof _=="symbol"?p(_)():void(M<3&&function(q){throw new Error("Argument "+q+' is invalid, it should be an action type of "string | symbol" or a tuple of "[string | symbol, Function, Function?]"')}(M))});return{request:E[0],success:E[1],failure:E[2],cancel:E[3]}}},i.createCustomAction=m,i.createReducer=function f(y,x){x===void 0&&(x={});var O=Object.assign({},x),E=function(_,M){var q=Array.isArray(_)?_:[_],Xt={};return q.map(function(N,Kr){return r(N)?w(N):l(N)?N:function(eo){throw new Error("Argument "+eo+' is invalid, it should be an action-creator instance from "typesafe-actions" or action type of type: string | symbol')}(Kr+1)}).forEach(function(N){return Xt[N]=M}),f(y,Object.assign({},O,{},Xt))};return Object.assign(function(_,M){if(_===void 0&&(_=y),O.hasOwnProperty(M.type)){var q=O[M.type];if(typeof q!="function")throw Error('Reducer under "'+M.type+'" key is not a valid reducer');return q(_,M)}return _},{handlers:Object.assign({},O),handleAction:E,handleType:E})},i.deprecated=F,i.getType=w,i.isActionOf=function(f,y){n(f)&&o(1);var x=Array.isArray(f)?f:[f];x.forEach(a);var O=function(E){return x.some(function(_){return E.type===_.getType()})};return y===void 0?O:O(y)},i.isOfType=function(f,y){n(f)&&o(1);var x=Array.isArray(f)?f:[f];x.forEach(d);var O=function(E){return x.includes(E.type)};return y===void 0?O:O(y)}})})(P,P.exports);const br="@iiif/IMPORT_ENTITIES",Or="@iiif/MODIFY_ENTITY_FIELD",Ar="@iiif/REORDER_ENTITY_FIELD",Cr="@iiif/ADD_REFERENCE",Pr="@iiif/REMOVE_REFERENCE",_r=P.exports.createAction(br)(),Ir=P.exports.createAction(Or)(),Er=P.exports.createAction(Ar)(),$r=P.exports.createAction(Cr)(),jr=P.exports.createAction(Pr)(),he={importEntities:_r,modifyEntityField:Ir,reorderEntityField:Er,addReference:$r,removeReference:jr},Mr="@iiif/ADD_MAPPING",Tr="@iiif/ADD_MAPPINGS";P.exports.createAction(Mr)(),P.exports.createAction(Tr)();const Fr="@iiif/SET_META_VALUE",kr="@iiif/SET_META_VALUE_DYNAMIC",Vr="@iiif/UNSET_META_VALUE";P.exports.createAction(Fr)(),P.exports.createAction(kr)(),P.exports.createAction(Vr)();const Wr="@iiif/REQUEST_RESOURCE",Lr="@iiif/REQUEST_ERROR",zr="@iiif/REQUEST_MISMATCH",Rr="@iiif/REQUEST_COMPLETE",Br="@iiif/REQUEST_OFFLINE_RESOURCE";P.exports.createAction(Wr)(),P.exports.createAction(Lr)(),P.exports.createAction(zr)(),P.exports.createAction(Rr)(),P.exports.createAction(Br)();const Hr="@iiif/BATCH",Dr="@iiif/BATCH_IMPORT";P.exports.createAction(Hr)(),P.exports.createAction(Dr)();function Gt(e){return typeof e!="string"&&e&&e.bindToVault}function qr(){const e=I(),t=h.useRef([]),i=dt(),n=h.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);h.useLayoutEffect(()=>{const a={id:n,type:"AnnotationPage",behavior:[],motivation:null,label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[]};i(he.importEntities({entities:{AnnotationPage:{[a.id]:a}}}))},[n]);const o=$(a=>n?a.iiif.entities.AnnotationPage[n]:null,[n]),r=h.useCallback((a,l)=>{if(n){if(Gt(a)){const d=a;d.__vault||d.bindToVault(e),a=typeof d.source=="string"?d.source:d.source.id,t.current[a]=d}else typeof a!="string"&&(a=a.id);const c=e.get({id:n,type:"AnnotationPage"}),u=e.get({id:a,type:"Annotation"});c&&u&&(c.items.find(d=>d.id===u.id)||i(he.addReference({id:n,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"},index:l})))}},[n]),s=h.useCallback(a=>{n&&(Gt(a)?a=typeof a.source=="string"?a.source:a.source.id:typeof a!="string"&&(a=a.id),t.current[a]&&t.current[a].beforeRemove(),e.get({id:n,type:"AnnotationPage"})&&i(he.removeReference({id:n,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"}})))},[n]);return[o,{addAnnotation:r,removeAnnotation:s}]}var Nr=Object.defineProperty,Ur=Object.defineProperties,Qr=Object.getOwnPropertyDescriptors,Zt=Object.getOwnPropertySymbols,Yr=Object.prototype.hasOwnProperty,Gr=Object.prototype.propertyIsEnumerable,Jt=(e,t,i)=>t in e?Nr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Zr=(e,t)=>{for(var i in t||(t={}))Yr.call(t,i)&&Jt(e,i,t[i]);if(Zt)for(var i of Zt(t))Gr.call(t,i)&&Jt(e,i,t[i]);return e},Jr=(e,t)=>Ur(e,Qr(t));function Xr(e){const t=X(),i=R(),n=I(),[o,r]=Yt(),{enabledPageIds:s}=ht((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(i==null?void 0:i.id),{all:!1}),a=Ht(s,"AnnotationPage"),l=(e==null?void 0:e.strategies)||["images","media","complex-timeline"],[c,u]=Bt(e,[r]),d=h.useMemo(()=>{if(!i||c.types.length===0)return le;if(c.types.length!==1)return l.indexOf("complex-timeline")===-1?j("Complex timeline not supported"):j("ComplexTimelineStrategy not yet supported");const v=c.types[0];return v==="image"?l.indexOf("images")===-1?j("Image not supported"):rt(i,c,o):v==="audio"?l.indexOf("media")===-1?j("Media not supported"):j("Audio strategy not yet supported"):v==="video"?l.indexOf("media")===-1?j("Media not supported"):j("Video strategy not yet supported"):le},[i,c,n,u.makeChoice]);return h.useMemo(()=>d.type==="unknown"?[d,nt]:[Jr(Zr({},d),{annotations:{pages:a}}),u],[d,a])}g.AnnotationContext=ri,g.CanvasContext=me,g.CollectionContext=oi,g.ContextBridge=fi,g.ImageServiceLoaderContext=Ze,g.ManifestContext=ve,g.RangeContext=si,g.ReactVaultContext=U,g.ResourceProvider=V,g.ResourceReactContext=ee,g.SimpleViewerProvider=li,g.SimpleViewerReactContext=Y,g.VaultProvider=ye,g.VisibleCanvasReactContext=Q,g.emptyActions=nt,g.expandTarget=T,g.flattenAnnotationPageIds=at,g.getImageStrategy=rt,g.getPaintables=it,g.parseSelector=ne,g.parseSpecificResource=tt,g.unknownResponse=le,g.unsupportedStrategy=j,g.useAnnotation=On,g.useAnnotationPageManager=ht,g.useAnnotationsAtTime=Mn,g.useCanvas=R,g.useCanvasClock=Tn,g.useCollection=Fn,g.useContextBridge=ui,g.useDispatch=dt,g.useEventListener=or,g.useExistingVault=sr,g.useExternalCollection=ar,g.useExternalManifest=we,g.useExternalResource=oe,g.useImageService=Rt,g.useImageServiceLoader=ie,g.useImageTile=cr,g.useLoadImageService=Yt,g.useManifest=X,g.usePaintables=Bt,g.usePaintingAnnotations=re,g.useRange=ur,g.useRenderingStrategy=Xr,g.useResourceContext=k,g.useResourceEvents=fr,g.useResources=Ht,g.useSearchService=hr,g.useSimpleViewer=ci,g.useStyleHelper=dr,g.useStyles=pr,g.useThumbnail=gr,g.useVault=I,g.useVaultEffect=Dt,g.useVaultSelector=$,g.useVirtualAnnotationPage=qr,g.useVisibleCanvases=xe,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.2",
3
+ "version": "0.9.5",
4
4
  "main": "./dist/cjs/index.js",
5
5
  "module": "./dist/esm/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -24,42 +24,43 @@
24
24
  },
25
25
  "license": "MIT",
26
26
  "resolutions": {
27
- "@iiif/vault": "^0.9.14",
27
+ "@atlas-viewer/iiif-image-api": "^2.0.2",
28
+ "@iiif/vault": "^0.9.15",
29
+ "@iiif/parser": "^1.0.6",
28
30
  "@iiif/presentation-3": "^1.0.4"
29
31
  },
30
32
  "dependencies": {
31
- "@atlas-viewer/iiif-image-api": "^1.2.6",
33
+ "@atlas-viewer/iiif-image-api": "^2.0.2",
32
34
  "@iiif/presentation-2": "^1.0.1",
33
35
  "@iiif/presentation-3": "^1.0.4",
34
- "@iiif/vault": "^0.9.14",
36
+ "@iiif/vault": "^0.9.15",
35
37
  "@iiif/vault-helpers": "^0.9.4",
36
- "react": "^16.10.2 || ^17.0.1",
37
- "react-dom": "^16.10.2 || ^17.0.1",
38
- "react-query": "^1.5.10",
38
+ "react": "^16.10.2 || ^17.0.2",
39
+ "react-dom": "^16.10.2 || ^17.0.2",
39
40
  "redux": "^4.1.2",
40
- "rollup": "^2.67.1",
41
- "typescript": "^4.5.5"
41
+ "rollup": "^2.70.0",
42
+ "typescript": "^4.6.2"
42
43
  },
43
44
  "devDependencies": {
44
- "@rollup/plugin-replace": "^3.0.1",
45
- "@testing-library/react": "^12.1.2",
45
+ "@rollup/plugin-replace": "^4.0.0",
46
+ "@testing-library/react": "^12.1.3",
46
47
  "@testing-library/react-hooks": "^7.0.2",
47
48
  "@types/jest": "^27.4.1",
48
49
  "@types/react": "^17.0.39",
49
- "@types/react-dom": "^17.0.11",
50
- "@typescript-eslint/eslint-plugin": "^5.11.0",
51
- "@typescript-eslint/parser": "^5.11.0",
52
- "eslint": "^8.8.0",
50
+ "@types/react-dom": "^17.0.13",
51
+ "@typescript-eslint/eslint-plugin": "^5.14.0",
52
+ "@typescript-eslint/parser": "^5.14.0",
53
+ "eslint": "^8.10.0",
53
54
  "eslint-plugin-json": "^3.1.0",
54
55
  "eslint-plugin-prettier": "^4.0.0",
55
56
  "jest": "^27.5.1",
56
57
  "jest-environment-jsdom": "^27.5.1",
57
58
  "prettier": "^2.5.1",
58
- "react": "^16.10.2 || ^17.0.1",
59
- "react-dom": "^16.10.2 || ^17.0.1",
59
+ "react": "^16.10.2 || ^17.0.2",
60
+ "react-dom": "^16.10.2 || ^17.0.2",
60
61
  "react-use": "^17.3.2",
61
62
  "redux": "^4.1.2",
62
- "rollup-library-template": "^1.0.3",
63
+ "rollup-library-template": "^1.0.4",
63
64
  "ts-jest": "^27.1.3",
64
65
  "tslib": "^2.3.1"
65
66
  },