react-iiif-vault 0.9.3 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
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"),L=require("@atlas-viewer/iiif-image-api"),b=require("@iiif/vault-helpers"),h=require("typesafe-actions"),je=require("@iiif/parser");function De(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var g=De(u),Fe=Object.defineProperty,z=Object.getOwnPropertySymbols,Ne=Object.prototype.hasOwnProperty,Be=Object.prototype.propertyIsEnumerable,Y=(e,t,n)=>t in e?Fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,W=(e,t)=>{for(var n in t||(t={}))Ne.call(t,n)&&Y(e,n,t[n]);if(z)for(var n of z(t))Be.call(t,n)&&Y(e,n,t[n]);return e};const Ue={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},j=g.default.createContext(Ue),C=()=>u.useContext(j),E=({value:e,children:t})=>{const n=C(),r=u.useMemo(()=>W(W({},n),e),[e,n]);return g.default.createElement(j.Provider,{value:r},t)},ke=({annotation:e,children:t})=>g.default.createElement(E,{value:{annotation:e}},t),G=({canvas:e,children:t})=>g.default.createElement(E,{value:{canvas:e}},t),He=({collection:e,children:t})=>g.default.createElement(E,{value:{collection:e}},t),X=({manifest:e,children:t})=>g.default.createElement(E,{value:{manifest:e}},t),Qe=({range:e,children:t})=>g.default.createElement(E,{value:{range:e}},t),A=g.default.createContext({vault:null,setVaultInstance:e=>{}}),J=({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:c})=>{const[i,a]=u.useState(()=>e||(n?T.globalVault(t):t?new T.Vault(t):new T.Vault));return g.default.createElement(A.Provider,{value:{vault:i,setVaultInstance:a}},g.default.createElement(E,{value:r||{}},c))},y=()=>{const{vault:e}=u.useContext(A);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var qe=Object.defineProperty,K=Object.getOwnPropertySymbols,ze=Object.prototype.hasOwnProperty,Ye=Object.prototype.propertyIsEnumerable,Z=(e,t,n)=>t in e?qe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,We=(e,t)=>{for(var n in t||(t={}))ze.call(t,n)&&Z(e,n,t[n]);if(K)for(var n of K(t))Ye.call(t,n)&&Z(e,n,t[n]);return e},Ge=(e,t,n)=>new Promise((r,c)=>{var i=s=>{try{o(n.next(s))}catch(l){c(l)}},a=s=>{try{o(n.throw(s))}catch(l){c(l)}},o=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);o((n=n.apply(e,t)).next())});const ee=(e,t={})=>{const n=y(),[r,c]=u.useState(e),i=u.useMemo(()=>n.get(e)||void 0,[e,n]),{data:a,error:o}=k.useQuery(["manifest",e],()=>Ge(void 0,null,function*(){const s=i||(yield n.load(e));return s&&r!==s.id&&c(s.id),s}),We({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,retry:!1,initialData:i},t));return{isLoaded:!!a,id:r,error:o,manifest:a}};function P(e,t=[]){const n=y(),[r,c]=u.useState(()=>e(n.getState(),n));return u.useEffect(()=>n.subscribe(i=>e(i,n),i=>{c(i)},!0),t),r}const R=g.default.createContext([]);function te(){const e=u.useContext(R);return P(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}const D=()=>{},M=u.createContext({setCurrentCanvasId:D,setCurrentCanvasIndex:D,nextCanvas:D,previousCanvas:D,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),Xe=e=>{const t=ee(e.manifest),[n,r]=u.useState(""),[c,i]=u.useState([]),a=(typeof e.pagingEnabled>"u"||e.pagingEnabled)&&t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");u.useEffect(()=>{var f,m;t.manifest&&(r((f=t.manifest.items[0])==null?void 0:f.id),i([(m=t.manifest.items[0])==null?void 0:m.id]))},[t.manifest,e.manifest]);const o=u.useMemo(()=>{var f;return((f=t.manifest)==null?void 0:f.items.map(m=>m.id))||[]},[t.manifest,e.manifest]),s=u.useMemo(()=>o.indexOf(n),[o,n]),l=u.useCallback(()=>{if(o.length&&n){if(s===-1||(o[s+2]?s+2===o.length:s===o.length))return;const f=a&&s!==0?o[s+2]:o[s+1],m=a?s!==0?o[s+3]:o[s+2]:null;f&&(r(f),i(m?[f,m]:[f]))}},[a,o,n,s]),p=u.useCallback(()=>{if(o.length&&n){if(s===0||s===-1)return;const f=a&&s!==1?o[s-2]:o[s-1],m=a&&s!==1?o[s-1]:null;f&&(r(f),i(m?[f,m]:[f]))}},[a,o,n,s]),d=u.useCallback(f=>{const m=a&&f%2===1?f-1:f,w=o[m],q=a&&m!==0?o[m+1]:null;w&&(r(w),i(I=>{const U=q?[w,q]:[w];if(I.length===I.length){for(let V=0;V<I.length;V++)if(I[V]!==U[V])return U;return I}return U}))},[a,o]),v=u.useCallback(f=>{const m=o.indexOf(f);m!==-1&&d(m)},[o,d]),_=u.useMemo(()=>({setCurrentCanvasId:v,nextCanvas:l,previousCanvas:p,currentCanvasIndex:s,totalCanvases:o.length,setCurrentCanvasIndex:d,pagingView:!0}),[l,p,s,o,d,v]);return!t.isLoaded||!t.manifest?g.default.createElement("div",null,"Loading..."):g.default.createElement(M.Provider,{value:_},g.default.createElement(R.Provider,{value:c},g.default.createElement(X,{manifest:t.manifest.id},g.default.createElement(G,{canvas:n},e.children))))};function Je(){return u.useContext(M)}function Ke(){return{VaultContext:u.useContext(A),ResourceContext:u.useContext(j),SimpleViewerReactContext:u.useContext(M),VisibleCanvasReactContext:u.useContext(R)}}const Ze=e=>g.default.createElement(J,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},g.default.createElement(R.Provider,{value:e.bridge.VisibleCanvasReactContext},g.default.createElement(M.Provider,{value:e.bridge.SimpleViewerReactContext},e.children))),ne=g.default.createContext(new L.ImageServiceLoader);function F(){return u.useContext(ne)}const et=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,tt=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function N(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:r,selectors:c}=N(n);return r&&(t.selector||(t.selector=r),t.selectors.push(...c)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,n]=e.split("#");return n?N({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=et.exec(e.value);if(t){const r={type:"BoxSelector",spatial:{unit:t[2]==="percent:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:r,selectors:[r]}}const n=e.value.match(tt);if(n){const r={type:"TemporalSelector",temporal:{startTime:n[4]?parseFloat(n[4]):0,endTime:n[7]?parseFloat(n[7]):void 0}};return{selector:r,selectors:[r]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}var nt=Object.defineProperty,rt=Object.defineProperties,ot=Object.getOwnPropertyDescriptors,re=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,at=Object.prototype.propertyIsEnumerable,oe=(e,t,n)=>t in e?nt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ie=(e,t)=>{for(var n in t||(t={}))it.call(t,n)&&oe(e,n,t[n]);if(re)for(var n of re(t))at.call(t,n)&&oe(e,n,t[n]);return e},ae=(e,t)=>rt(e,ot(t));function O(e,t={}){if(Array.isArray(e))return O(e[0]);if(typeof e=="string"){const[n,r]=e.split("#");return r?O({type:"SpecificResource",source:{id:n,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return O(e.items[0]);if(e.type==="SpecificResource"){e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]);const{selector:n,selectors:r}=e.selector?N(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:n,selectors:r}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[n,r]=e.id.split("#");return r?O({type:"SpecificResource",source:ae(ie({},e),{id:n}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:ae(ie({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function se(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function ce(e,t,n){const r=[];let c=null;const i=[];for(const a of t){const o=e.get(a.body);for(const s of o){const[l,{selector:p}]=se(s),d=(l.type||"unknown").toLowerCase();if(d==="choice"){const v=e.get(l.items),_=n.length?n.map(f=>v.find(m=>m.id===f)).filter(Boolean):[v[0]];_.length===0&&_.push(v[0]),c={type:"single-choice",items:v.map(f=>({id:f.id,label:f.label,selected:_.indexOf(f)!==-1})),label:s.label},o.push(..._);continue}r.indexOf(d)===-1&&r.push(d),i.push({type:d,resource:l,target:a.target,selector:p})}}return{types:r,items:i,choice:c}}const ue={makeChoice:()=>{}},H={type:"unknown"},S=e=>({type:"unknown",reason:e,annotations:{pages:[]}});function le(e,t,n){const r=[];for(const c of t.items){const i=c.resource&&c.resource.type==="SpecificResource"?c.resource.source:c.resource;if(!i.id)return S("No resource Identifier");let a;if(i.service){const m=L.getImageServices(i);m[0]&&(a=n(m[0],e))}const{selector:o,source:s}=O(c.target);if(s.id!==e.id)continue;const l={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},p=o?o.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:o.temporal,spatial:l.spatial}:o:null,d={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},v=c.resource.type==="SpecificResource"?O(c.resource):null,_=v&&v.selector&&(v.selector.type==="BoxSelector"||v.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:v.selector.spatial.x,y:v.selector.spatial.y,width:v.selector.spatial.width,height:v.selector.spatial.height}}:d,f={id:i.id,type:"Image",width:p?i.width:e.width,height:p?i.height:e.height,service:a,sizes:a&&a.sizes?a.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:p&&p.type!=="PointSelector"?p:l,selector:_};r.push(f)}return{type:"images",image:r[0],images:r,choice:t.choice}}var st=Object.defineProperty,ct=Object.defineProperties,ut=Object.getOwnPropertyDescriptors,fe=Object.getOwnPropertySymbols,lt=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable,de=(e,t,n)=>t in e?st(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,dt=(e,t)=>{for(var n in t||(t={}))lt.call(t,n)&&de(e,n,t[n]);if(fe)for(var n of fe(t))ft.call(t,n)&&de(e,n,t[n]);return e},pt=(e,t)=>ct(e,ut(t));function vt(e={},t=[]){const{id:n,selector:r}=e,c=C(),i=y(),a=n||c.annotation,o=P(l=>a?l.iiif.entities.Annotation[a]:void 0,[a]),s=P(l=>o&&o.body?o.body.map(p=>p?l.iiif.entities[p.type][p.id]:null).filter(Boolean):[],[o]);return u.useMemo(()=>{if(!o)return;const l=pt(dt({},o),{body:s,target:O(o.target,{typeMap:i.getState().iiif.mapping})});return r?r(l):l},[o,r,s,...t])}function $(e={},t=[]){const{id:n,selector:r}=e,c=C();y();const i=n||c.manifest,a=P(o=>i?o.iiif.entities.Manifest[i]:void 0,[i]);return u.useMemo(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function x(e={},t=[]){const{id:n,selector:r}=e,c=C(),i=n||c.canvas,a=P(o=>i?o.iiif.entities.Canvas[i]:void 0,[i]);return u.useMemo(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function mt(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function gt(e,t){return P(n=>{const r=[];if(!e)return r;const c=Object.keys(n.iiif.entities.AnnotationPage);for(const i of c)if(!t||t.indexOf(i)!==-1){const a=mt(n,i);a&&a.views&&a.views[e]&&r.push(i)}return r},[e])}function pe({canvas:e,manifest:t,all:n,canvases:r}){const c=[];if(t)for(const i of t.annotations)c.indexOf(i.id)===-1&&c.push(i.id);if(n){if(r&&r.length)for(const i of r)for(const a of i.annotations)c.indexOf(a.id)===-1&&c.push(a.id)}else if(e)for(const i of e.annotations)c.indexOf(i.id)===-1&&c.push(i.id);return c}var yt=Object.defineProperty,ht=Object.defineProperties,_t=Object.getOwnPropertyDescriptors,ve=Object.getOwnPropertySymbols,Pt=Object.prototype.hasOwnProperty,St=Object.prototype.propertyIsEnumerable,me=(e,t,n)=>t in e?yt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ge=(e,t)=>{for(var n in t||(t={}))Pt.call(t,n)&&me(e,n,t[n]);if(ve)for(var n of ve(t))St.call(t,n)&&me(e,n,t[n]);return e},ye=(e,t)=>ht(e,_t(t));function wt(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function he(e,t={}){const n=y(),r=$(),c=x(),i=te(),a=u.useMemo(()=>pe({all:t.all,manifest:r,canvas:c,canvases:i}),[t.all,c,i,r]),o=gt(e,t.all?void 0:a),s=u.useCallback(p=>{!e||n.setMetaValue([p,"annotationPageManager","views"],d=>d&&!d[e]?d:ye(ge({},d||{}),{[e]:!1}))},[e,n]),l=u.useCallback((p,d={})=>{if(!e)return;const v=n.getState(),_=[];if(d==null?void 0:d.deselectOthers){const f=Object.keys(v.iiif.entities.AnnotationPage);for(const m of f){const w=wt(v,m);w&&w.views&&w.views[e]&&_.push(m)}}for(const f of _)s(f);n.setMetaValue([p,"annotationPageManager","views"],f=>f&&f[e]?f:ye(ge({},f||{}),{[e]:!0}))},[e,s,n]);return{availablePageIds:a,enabledPageIds:o,setPageEnabled:l,setPageDisabled:s}}function B(e={}){const t=x(e.canvasId?{id:e.canvasId}:void 0);return P((n,r)=>{if(!t)return[];const c=r.get(t.items),i=[];for(const a of c)i.push(...r.get(a.items));return i},[t])}function Ot(e,t={}){return B(t)}function Ct(e,t=!1){}function Et(e,t=[]){const{id:n,selector:r}=e,c=C(),i=n||c.collection,a=P(o=>i?o.iiif.entities.Collection[i]:void 0,[i]);return u.useMemo(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function _e(){const t=y().getStore();return u.useMemo(()=>n=>t.dispatch(n),[t])}function xt(e,t,n,r,c=[]){const i=y(),a=u.useMemo(()=>b.createEventsHelper(i),[i]);u.useEffect(()=>{const o=e;return o?(a.addEventListener(o,t,n,r),()=>{a.removeEventListener(o,t,n)}):()=>{}},[a,e,t,...c])}function It(){const e=u.useContext(A);return e&&e.vault?e.vault:T.globalVault()}var bt=Object.defineProperty,Pe=Object.getOwnPropertySymbols,At=Object.prototype.hasOwnProperty,Rt=Object.prototype.propertyIsEnumerable,Se=(e,t,n)=>t in e?bt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Mt=(e,t)=>{for(var n in t||(t={}))At.call(t,n)&&Se(e,n,t[n]);if(Pe)for(var n of Pe(t))Rt.call(t,n)&&Se(e,n,t[n]);return e},$t=(e,t,n)=>new Promise((r,c)=>{var i=s=>{try{o(n.next(s))}catch(l){c(l)}},a=s=>{try{o(n.throw(s))}catch(l){c(l)}},o=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);o((n=n.apply(e,t)).next())});const Vt=(e,t={})=>{const n=y(),[r,c]=u.useState(e),i=u.useMemo(()=>n.get(e),[e,n]),{data:a,isFetching:o}=k.useQuery(`collection:${e}`,()=>$t(void 0,null,function*(){const s=i||(yield n.loadCollection(e));return s&&c(s.id),s}),Mt({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,initialData:i},t));return{isLoaded:!o,id:r,collection:a}};var Tt=(e,t,n)=>new Promise((r,c)=>{var i=s=>{try{o(n.next(s))}catch(l){c(l)}},a=s=>{try{o(n.throw(s))}catch(l){c(l)}},o=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);o((n=n.apply(e,t)).next())});function we(){const e=x(),t=B(),n=y(),r=F();return k.useQuery(`canvas-first-image-service:${e?e.id:"undefined"}`,()=>Tt(this,null,function*(){if(e&&t.length){const c=t[0],i=n.get(c.body[0]),o=L.getImageServices(i)[0];return o&&(yield r.loadService({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height}))||void 0}}),{refetchOnWindowFocus:!1,refetchOnMount:!1,refetchIntervalInBackground:!1,refetchInterval:!1,initialData:()=>{if(e&&t.length){const c=t[0],i=n.get(c.body[0]),o=L.getImageServices(i)[0];return o&&r.loadServiceSync({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height})||void 0}}})}function Lt(){const e=we();return{isLoading:e.isFetching,tile:e.data?{id:e.data.id||e.data["@id"],width:e.data.width,height:e.data.height,imageService:e.data,thumbnail:void 0}:null}}function Oe(e,t=[]){const n=y(),r=B(),[c,i]=u.useState((e==null?void 0:e.defaultChoices)||[]),a=u.useMemo(()=>ce(n,r,c),[n,r,c,...t]),s={makeChoice:u.useCallback((l,{deselectOthers:p=!0,deselect:d=!1}={})=>{if(a.choice){if(a.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");i(v=>{if(d){const f=v.filter(m=>m!==l);if(f.length===0){const m=a.items[0].resource.id;return m?[m]:[]}return f}if(p)return[l];const _=[...v];if(_.length===0&&a.items.length){const f=a.items[0].resource.id;f&&_.push(f)}return v.indexOf(l)!==-1?v:[...v,l]})}},[a.choice])};return[a,s]}function jt(e={},t=[]){const{id:n,selector:r}=e,c=C(),i=n||c.range,a=P(o=>i?o.iiif.entities.Range[i]:void 0,[i]);return u.useMemo(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function Dt(e,t){const n=y(),r=u.useMemo(()=>b.createEventsHelper(n),[n]),c=P(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return u.useMemo(()=>e?r.getListenersAsProps(e,t):{},[c,e,n,t])}function Ce(e,t){return P((n,r)=>r.get(e.map(c=>({id:c,type:t}))),[e,t])}function Ft(){const e=$();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function Nt(){const e=y();return u.useMemo(()=>b.createStylesHelper(e),[e])}function Bt(e,t){const n=y(),r=u.useMemo(()=>b.createStylesHelper(n),[n]);return P(()=>{if(!e)return null;const c=r.getAppliedStyles(e.id);return c?t?c[t]:c:void 0},[e,t])}const Ee=(e,t=[])=>{const n=y();u.useEffect(()=>{e(n)},[n,...t])};function Ut(e,t,{canvasId:n,manifestId:r}={}){const c=y(),i=F(),a=u.useMemo(()=>b.createThumbnailHelper(c,{imageServiceLoader:i}),[c,i]),[o,s]=u.useState(),l=$(r?{id:r}:void 0),p=x(n?{id:n}:void 0),d=p||l,v=u.useRef(!1);if(u.useEffect(()=>()=>{v.current=!0},[]),!d)throw new Error("Must be called under a manifest or canvas context.");return Ee(_=>{a.getBestThumbnailAtSize(d,e,t).then(f=>{f.best&&!v.current&&s(f.best)})},[d]),o}var kt=Object.defineProperty,Ht=Object.defineProperties,Qt=Object.getOwnPropertyDescriptors,xe=Object.getOwnPropertySymbols,qt=Object.prototype.hasOwnProperty,zt=Object.prototype.propertyIsEnumerable,Ie=(e,t,n)=>t in e?kt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,be=(e,t)=>{for(var n in t||(t={}))qt.call(t,n)&&Ie(e,n,t[n]);if(xe)for(var n of xe(t))zt.call(t,n)&&Ie(e,n,t[n]);return e},Ae=(e,t)=>Ht(e,Qt(t));function Re(){const e=F(),[t,n]=u.useState({}),r=u.useRef(!1);return u.useEffect(()=>()=>{r.current=!0},[]),[u.useCallback((i,{height:a,width:o})=>{if(i){const s=i.id||i["@id"],l=e.loadServiceSync({id:s,width:i.width||o,height:i.height||a});l?i=l:t[s]||(r.current||n(p=>Ae(be({},p),{[s]:"loading"})),e.loadService({id:s,width:i.width||o,height:i.height||a}).then(()=>{r.current||n(p=>Ae(be({},p),{[s]:"done"}))}))}return i},[e,t]),t]}const Yt="@iiif/IMPORT_ENTITIES",Wt="@iiif/MODIFY_ENTITY_FIELD",Gt="@iiif/REORDER_ENTITY_FIELD",Xt="@iiif/ADD_REFERENCE",Jt="@iiif/REMOVE_REFERENCE",Kt=h.createAction(Yt)(),Zt=h.createAction(Wt)(),en=h.createAction(Gt)(),tn=h.createAction(Xt)(),nn=h.createAction(Jt)(),Q={importEntities:Kt,modifyEntityField:Zt,reorderEntityField:en,addReference:tn,removeReference:nn},rn="@iiif/ADD_MAPPING",on="@iiif/ADD_MAPPINGS";h.createAction(rn)(),h.createAction(on)();const an="@iiif/SET_META_VALUE",sn="@iiif/SET_META_VALUE_DYNAMIC",cn="@iiif/UNSET_META_VALUE";h.createAction(an)(),h.createAction(sn)(),h.createAction(cn)();const un="@iiif/REQUEST_RESOURCE",ln="@iiif/REQUEST_ERROR",fn="@iiif/REQUEST_MISMATCH",dn="@iiif/REQUEST_COMPLETE",pn="@iiif/REQUEST_OFFLINE_RESOURCE";h.createAction(un)(),h.createAction(ln)(),h.createAction(fn)(),h.createAction(dn)(),h.createAction(pn)();const vn="@iiif/BATCH";h.createAction(vn)();var mn=Object.defineProperty,gn=Object.defineProperties,yn=Object.getOwnPropertyDescriptors,Me=Object.getOwnPropertySymbols,hn=Object.prototype.hasOwnProperty,_n=Object.prototype.propertyIsEnumerable,$e=(e,t,n)=>t in e?mn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Pn=(e,t)=>{for(var n in t||(t={}))hn.call(t,n)&&$e(e,n,t[n]);if(Me)for(var n of Me(t))_n.call(t,n)&&$e(e,n,t[n]);return e},Sn=(e,t)=>gn(e,yn(t));function Ve(e){return typeof e!="string"&&e&&e.bindToVault}function wn(){const e=y(),t=u.useRef([]),n=_e(),r=u.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);u.useLayoutEffect(()=>{const o=Sn(Pn({},je.emptyAnnotationPage),{id:r,items:[]});n(Q.importEntities({entities:{AnnotationPage:{[o.id]:o}}}))},[r]);const c=P(o=>r?o.iiif.entities.AnnotationPage[r]:null,[r]),i=u.useCallback((o,s)=>{if(r){if(Ve(o)){const d=o;d.__vault||d.bindToVault(e),o=typeof d.source=="string"?d.source:d.source.id,t.current[o]=d}else typeof o!="string"&&(o=o.id);const l=e.get({id:r,type:"AnnotationPage"}),p=e.get({id:o,type:"Annotation"});l&&p&&(l.items.find(d=>d.id===p.id)||n(Q.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"},index:s})))}},[r]),a=u.useCallback(o=>{r&&(Ve(o)?o=typeof o.source=="string"?o.source:o.source.id:typeof o!="string"&&(o=o.id),t.current[o]&&t.current[o].beforeRemove(),e.get({id:r,type:"AnnotationPage"})&&n(Q.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"}})))},[r]);return[c,{addAnnotation:i,removeAnnotation:a}]}var On=Object.defineProperty,Cn=Object.defineProperties,En=Object.getOwnPropertyDescriptors,Te=Object.getOwnPropertySymbols,xn=Object.prototype.hasOwnProperty,In=Object.prototype.propertyIsEnumerable,Le=(e,t,n)=>t in e?On(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,bn=(e,t)=>{for(var n in t||(t={}))xn.call(t,n)&&Le(e,n,t[n]);if(Te)for(var n of Te(t))In.call(t,n)&&Le(e,n,t[n]);return e},An=(e,t)=>Cn(e,En(t));function Rn(e){const t=$(),n=x(),r=y(),[c,i]=Re(),{enabledPageIds:a}=he((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id),{all:!1}),o=Ce(a,"AnnotationPage"),s=(e==null?void 0:e.strategies)||["images","media","complex-timeline"],[l,p]=Oe(e,[i]),d=u.useMemo(()=>{if(!n||l.types.length===0)return H;if(l.types.length!==1)return s.indexOf("complex-timeline")===-1?S("Complex timeline not supported"):S("ComplexTimelineStrategy not yet supported");const v=l.types[0];return v==="image"?s.indexOf("images")===-1?S("Image not supported"):le(n,l,c):v==="audio"?s.indexOf("media")===-1?S("Media not supported"):S("Audio strategy not yet supported"):v==="video"?s.indexOf("media")===-1?S("Media not supported"):S("Video strategy not yet supported"):H},[n,l,r,p.makeChoice]);return u.useMemo(()=>d.type==="unknown"?[d,ue]:[An(bn({},d),{annotations:{pages:o}}),p],[d,o])}exports.AnnotationContext=ke,exports.CanvasContext=G,exports.CollectionContext=He,exports.ContextBridge=Ze,exports.ImageServiceLoaderContext=ne,exports.ManifestContext=X,exports.RangeContext=Qe,exports.ReactVaultContext=A,exports.ResourceProvider=E,exports.ResourceReactContext=j,exports.SimpleViewerProvider=Xe,exports.SimpleViewerReactContext=M,exports.VaultProvider=J,exports.VisibleCanvasReactContext=R,exports.emptyActions=ue,exports.expandTarget=O,exports.flattenAnnotationPageIds=pe,exports.getImageStrategy=le,exports.getPaintables=ce,exports.parseSelector=N,exports.parseSpecificResource=se,exports.unknownResponse=H,exports.unsupportedStrategy=S,exports.useAnnotation=vt,exports.useAnnotationPageManager=he,exports.useAnnotationsAtTime=Ot,exports.useCanvas=x,exports.useCanvasClock=Ct,exports.useCollection=Et,exports.useContextBridge=Ke,exports.useDispatch=_e,exports.useEventListener=xt,exports.useExistingVault=It,exports.useExternalCollection=Vt,exports.useExternalManifest=ee,exports.useImageService=we,exports.useImageServiceLoader=F,exports.useImageTile=Lt,exports.useLoadImageService=Re,exports.useManifest=$,exports.usePaintables=Oe,exports.usePaintingAnnotations=B,exports.useRange=jt,exports.useRenderingStrategy=Rn,exports.useResourceContext=C,exports.useResourceEvents=Dt,exports.useResources=Ce,exports.useSearchService=Ft,exports.useSimpleViewer=Je,exports.useStyleHelper=Nt,exports.useStyles=Bt,exports.useThumbnail=Ut,exports.useVault=y,exports.useVaultEffect=Ee,exports.useVaultSelector=P,exports.useVirtualAnnotationPage=wn,exports.useVisibleCanvases=te;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var u=require("react"),T=require("@iiif/vault"),k=require("react-query"),L=require("@atlas-viewer/iiif-image-api"),b=require("@iiif/vault-helpers"),h=require("typesafe-actions"),je=require("@iiif/parser");function De(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var g=De(u),Fe=Object.defineProperty,z=Object.getOwnPropertySymbols,Ne=Object.prototype.hasOwnProperty,Be=Object.prototype.propertyIsEnumerable,Y=(e,t,n)=>t in e?Fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,W=(e,t)=>{for(var n in t||(t={}))Ne.call(t,n)&&Y(e,n,t[n]);if(z)for(var n of z(t))Be.call(t,n)&&Y(e,n,t[n]);return e};const Ue={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},j=g.default.createContext(Ue),C=()=>u.useContext(j),E=({value:e,children:t})=>{const n=C(),r=u.useMemo(()=>W(W({},n),e),[e,n]);return g.default.createElement(j.Provider,{value:r},t)},ke=({annotation:e,children:t})=>g.default.createElement(E,{value:{annotation:e}},t),G=({canvas:e,children:t})=>g.default.createElement(E,{value:{canvas:e}},t),He=({collection:e,children:t})=>g.default.createElement(E,{value:{collection:e}},t),X=({manifest:e,children:t})=>g.default.createElement(E,{value:{manifest:e}},t),Qe=({range:e,children:t})=>g.default.createElement(E,{value:{range:e}},t),A=g.default.createContext({vault:null,setVaultInstance:e=>{}}),J=({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:c})=>{const[i,a]=u.useState(()=>e||(n?T.globalVault(t):t?new T.Vault(t):new T.Vault));return g.default.createElement(A.Provider,{value:{vault:i,setVaultInstance:a}},g.default.createElement(E,{value:r||{}},c))},y=()=>{const{vault:e}=u.useContext(A);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var qe=Object.defineProperty,K=Object.getOwnPropertySymbols,ze=Object.prototype.hasOwnProperty,Ye=Object.prototype.propertyIsEnumerable,Z=(e,t,n)=>t in e?qe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,We=(e,t)=>{for(var n in t||(t={}))ze.call(t,n)&&Z(e,n,t[n]);if(K)for(var n of K(t))Ye.call(t,n)&&Z(e,n,t[n]);return e},Ge=(e,t,n)=>new Promise((r,c)=>{var i=s=>{try{o(n.next(s))}catch(l){c(l)}},a=s=>{try{o(n.throw(s))}catch(l){c(l)}},o=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);o((n=n.apply(e,t)).next())});const ee=(e,t={})=>{const n=y(),[r,c]=u.useState(e),i=u.useMemo(()=>n.get(e)||void 0,[e,n]),{data:a,error:o}=k.useQuery(["manifest",e],()=>Ge(void 0,null,function*(){const s=i||(yield n.load(e));return s&&r!==s.id&&c(s.id),s}),We({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,retry:!1,initialData:i},t));return{isLoaded:!!a,id:r,error:o,manifest:a}};function P(e,t=[]){const n=y(),[r,c]=u.useState(()=>e(n.getState(),n));return u.useEffect(()=>n.subscribe(i=>e(i,n),i=>{c(i)},!1),t),r}const R=g.default.createContext([]);function te(){const e=u.useContext(R);return P(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}const D=()=>{},M=u.createContext({setCurrentCanvasId:D,setCurrentCanvasIndex:D,nextCanvas:D,previousCanvas:D,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),Xe=e=>{const t=ee(e.manifest),[n,r]=u.useState(""),[c,i]=u.useState([]),a=(typeof e.pagingEnabled>"u"||e.pagingEnabled)&&t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");u.useEffect(()=>{var f,m;t.manifest&&(r((f=t.manifest.items[0])==null?void 0:f.id),i([(m=t.manifest.items[0])==null?void 0:m.id]))},[t.manifest,e.manifest]);const o=u.useMemo(()=>{var f;return((f=t.manifest)==null?void 0:f.items.map(m=>m.id))||[]},[t.manifest,e.manifest]),s=u.useMemo(()=>o.indexOf(n),[o,n]),l=u.useCallback(()=>{if(o.length&&n){if(s===-1||(o[s+2]?s+2===o.length:s===o.length))return;const f=a&&s!==0?o[s+2]:o[s+1],m=a?s!==0?o[s+3]:o[s+2]:null;f&&(r(f),i(m?[f,m]:[f]))}},[a,o,n,s]),p=u.useCallback(()=>{if(o.length&&n){if(s===0||s===-1)return;const f=a&&s!==1?o[s-2]:o[s-1],m=a&&s!==1?o[s-1]:null;f&&(r(f),i(m?[f,m]:[f]))}},[a,o,n,s]),d=u.useCallback(f=>{const m=a&&f%2===1?f-1:f,w=o[m],q=a&&m!==0?o[m+1]:null;w&&(r(w),i(I=>{const U=q?[w,q]:[w];if(I.length===I.length){for(let V=0;V<I.length;V++)if(I[V]!==U[V])return U;return I}return U}))},[a,o]),v=u.useCallback(f=>{const m=o.indexOf(f);m!==-1&&d(m)},[o,d]),_=u.useMemo(()=>({setCurrentCanvasId:v,nextCanvas:l,previousCanvas:p,currentCanvasIndex:s,totalCanvases:o.length,setCurrentCanvasIndex:d,pagingView:!0}),[l,p,s,o,d,v]);return!t.isLoaded||!t.manifest?g.default.createElement("div",null,"Loading..."):g.default.createElement(M.Provider,{value:_},g.default.createElement(R.Provider,{value:c},g.default.createElement(X,{manifest:t.manifest.id},g.default.createElement(G,{canvas:n},e.children))))};function Je(){return u.useContext(M)}function Ke(){return{VaultContext:u.useContext(A),ResourceContext:u.useContext(j),SimpleViewerReactContext:u.useContext(M),VisibleCanvasReactContext:u.useContext(R)}}const Ze=e=>g.default.createElement(J,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},g.default.createElement(R.Provider,{value:e.bridge.VisibleCanvasReactContext},g.default.createElement(M.Provider,{value:e.bridge.SimpleViewerReactContext},e.children))),ne=g.default.createContext(new L.ImageServiceLoader);function F(){return u.useContext(ne)}const et=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,tt=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function N(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:r,selectors:c}=N(n);return r&&(t.selector||(t.selector=r),t.selectors.push(...c)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,n]=e.split("#");return n?N({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=et.exec(e.value);if(t){const r={type:"BoxSelector",spatial:{unit:t[2]==="percent:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:r,selectors:[r]}}const n=e.value.match(tt);if(n){const r={type:"TemporalSelector",temporal:{startTime:n[4]?parseFloat(n[4]):0,endTime:n[7]?parseFloat(n[7]):void 0}};return{selector:r,selectors:[r]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}var nt=Object.defineProperty,rt=Object.defineProperties,ot=Object.getOwnPropertyDescriptors,re=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,at=Object.prototype.propertyIsEnumerable,oe=(e,t,n)=>t in e?nt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ie=(e,t)=>{for(var n in t||(t={}))it.call(t,n)&&oe(e,n,t[n]);if(re)for(var n of re(t))at.call(t,n)&&oe(e,n,t[n]);return e},ae=(e,t)=>rt(e,ot(t));function O(e,t={}){if(Array.isArray(e))return O(e[0]);if(typeof e=="string"){const[n,r]=e.split("#");return r?O({type:"SpecificResource",source:{id:n,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return O(e.items[0]);if(e.type==="SpecificResource"){e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]);const{selector:n,selectors:r}=e.selector?N(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:n,selectors:r}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[n,r]=e.id.split("#");return r?O({type:"SpecificResource",source:ae(ie({},e),{id:n}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:ae(ie({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function se(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function ce(e,t,n){const r=[];let c=null;const i=[];for(const a of t){const o=e.get(a.body);for(const s of o){const[l,{selector:p}]=se(s),d=(l.type||"unknown").toLowerCase();if(d==="choice"){const v=e.get(l.items),_=n.length?n.map(f=>v.find(m=>m.id===f)).filter(Boolean):[v[0]];_.length===0&&_.push(v[0]),c={type:"single-choice",items:v.map(f=>({id:f.id,label:f.label,selected:_.indexOf(f)!==-1})),label:s.label},o.push(..._);continue}r.indexOf(d)===-1&&r.push(d),i.push({type:d,resource:l,target:a.target,selector:p})}}return{types:r,items:i,choice:c}}const ue={makeChoice:()=>{}},H={type:"unknown"},S=e=>({type:"unknown",reason:e,annotations:{pages:[]}});function le(e,t,n){const r=[];for(const c of t.items){const i=c.resource&&c.resource.type==="SpecificResource"?c.resource.source:c.resource;if(!i.id)return S("No resource Identifier");let a;if(i.service){const m=L.getImageServices(i);m[0]&&(a=n(m[0],e))}const{selector:o,source:s}=O(c.target);if(s.id!==e.id)continue;const l={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},p=o?o.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:o.temporal,spatial:l.spatial}:o:null,d={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},v=c.resource.type==="SpecificResource"?O(c.resource):null,_=v&&v.selector&&(v.selector.type==="BoxSelector"||v.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:v.selector.spatial.x,y:v.selector.spatial.y,width:v.selector.spatial.width,height:v.selector.spatial.height}}:d,f={id:i.id,type:"Image",width:p?i.width:e.width,height:p?i.height:e.height,service:a,sizes:a&&a.sizes?a.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:p&&p.type!=="PointSelector"?p:l,selector:_};r.push(f)}return{type:"images",image:r[0],images:r,choice:t.choice}}var st=Object.defineProperty,ct=Object.defineProperties,ut=Object.getOwnPropertyDescriptors,fe=Object.getOwnPropertySymbols,lt=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable,de=(e,t,n)=>t in e?st(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,dt=(e,t)=>{for(var n in t||(t={}))lt.call(t,n)&&de(e,n,t[n]);if(fe)for(var n of fe(t))ft.call(t,n)&&de(e,n,t[n]);return e},pt=(e,t)=>ct(e,ut(t));function vt(e={},t=[]){const{id:n,selector:r}=e,c=C(),i=y(),a=n||c.annotation,o=P(l=>a?l.iiif.entities.Annotation[a]:void 0,[a]),s=P(l=>o&&o.body?o.body.map(p=>p?l.iiif.entities[p.type][p.id]:null).filter(Boolean):[],[o]);return u.useMemo(()=>{if(!o)return;const l=pt(dt({},o),{body:s,target:O(o.target,{typeMap:i.getState().iiif.mapping})});return r?r(l):l},[o,r,s,...t])}function $(e={},t=[]){const{id:n,selector:r}=e,c=C();y();const i=n||c.manifest,a=P(o=>i?o.iiif.entities.Manifest[i]:void 0,[i]);return u.useMemo(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function x(e={},t=[]){const{id:n,selector:r}=e,c=C(),i=n||c.canvas,a=P(o=>i?o.iiif.entities.Canvas[i]:void 0,[i]);return u.useMemo(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function mt(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function gt(e,t){return P(n=>{const r=[];if(!e)return r;const c=Object.keys(n.iiif.entities.AnnotationPage);for(const i of c)if(!t||t.indexOf(i)!==-1){const a=mt(n,i);a&&a.views&&a.views[e]&&r.push(i)}return r},[e])}function pe({canvas:e,manifest:t,all:n,canvases:r}){const c=[];if(t)for(const i of t.annotations)c.indexOf(i.id)===-1&&c.push(i.id);if(n){if(r&&r.length)for(const i of r)for(const a of i.annotations)c.indexOf(a.id)===-1&&c.push(a.id)}else if(e)for(const i of e.annotations)c.indexOf(i.id)===-1&&c.push(i.id);return c}var yt=Object.defineProperty,ht=Object.defineProperties,_t=Object.getOwnPropertyDescriptors,ve=Object.getOwnPropertySymbols,Pt=Object.prototype.hasOwnProperty,St=Object.prototype.propertyIsEnumerable,me=(e,t,n)=>t in e?yt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ge=(e,t)=>{for(var n in t||(t={}))Pt.call(t,n)&&me(e,n,t[n]);if(ve)for(var n of ve(t))St.call(t,n)&&me(e,n,t[n]);return e},ye=(e,t)=>ht(e,_t(t));function wt(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function he(e,t={}){const n=y(),r=$(),c=x(),i=te(),a=u.useMemo(()=>pe({all:t.all,manifest:r,canvas:c,canvases:i}),[t.all,c,i,r]),o=gt(e,t.all?void 0:a),s=u.useCallback(p=>{!e||n.setMetaValue([p,"annotationPageManager","views"],d=>d&&!d[e]?d:ye(ge({},d||{}),{[e]:!1}))},[e,n]),l=u.useCallback((p,d={})=>{if(!e)return;const v=n.getState(),_=[];if(d==null?void 0:d.deselectOthers){const f=Object.keys(v.iiif.entities.AnnotationPage);for(const m of f){const w=wt(v,m);w&&w.views&&w.views[e]&&_.push(m)}}for(const f of _)s(f);n.setMetaValue([p,"annotationPageManager","views"],f=>f&&f[e]?f:ye(ge({},f||{}),{[e]:!0}))},[e,s,n]);return{availablePageIds:a,enabledPageIds:o,setPageEnabled:l,setPageDisabled:s}}function B(e={}){const t=x(e.canvasId?{id:e.canvasId}:void 0);return P((n,r)=>{if(!t)return[];const c=r.get(t.items),i=[];for(const a of c)i.push(...r.get(a.items));return i},[t])}function Ot(e,t={}){return B(t)}function Ct(e,t=!1){}function Et(e,t=[]){const{id:n,selector:r}=e,c=C(),i=n||c.collection,a=P(o=>i?o.iiif.entities.Collection[i]:void 0,[i]);return u.useMemo(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function _e(){const t=y().getStore();return u.useMemo(()=>n=>t.dispatch(n),[t])}function xt(e,t,n,r,c=[]){const i=y(),a=u.useMemo(()=>b.createEventsHelper(i),[i]);u.useEffect(()=>{const o=e;return o?(a.addEventListener(o,t,n,r),()=>{a.removeEventListener(o,t,n)}):()=>{}},[a,e,t,...c])}function It(){const e=u.useContext(A);return e&&e.vault?e.vault:T.globalVault()}var bt=Object.defineProperty,Pe=Object.getOwnPropertySymbols,At=Object.prototype.hasOwnProperty,Rt=Object.prototype.propertyIsEnumerable,Se=(e,t,n)=>t in e?bt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Mt=(e,t)=>{for(var n in t||(t={}))At.call(t,n)&&Se(e,n,t[n]);if(Pe)for(var n of Pe(t))Rt.call(t,n)&&Se(e,n,t[n]);return e},$t=(e,t,n)=>new Promise((r,c)=>{var i=s=>{try{o(n.next(s))}catch(l){c(l)}},a=s=>{try{o(n.throw(s))}catch(l){c(l)}},o=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);o((n=n.apply(e,t)).next())});const Vt=(e,t={})=>{const n=y(),[r,c]=u.useState(e),i=u.useMemo(()=>n.get(e),[e,n]),{data:a,isFetching:o}=k.useQuery(`collection:${e}`,()=>$t(void 0,null,function*(){const s=i||(yield n.loadCollection(e));return s&&c(s.id),s}),Mt({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,initialData:i},t));return{isLoaded:!o,id:r,collection:a}};var Tt=(e,t,n)=>new Promise((r,c)=>{var i=s=>{try{o(n.next(s))}catch(l){c(l)}},a=s=>{try{o(n.throw(s))}catch(l){c(l)}},o=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);o((n=n.apply(e,t)).next())});function we(){const e=x(),t=B(),n=y(),r=F();return k.useQuery(`canvas-first-image-service:${e?e.id:"undefined"}`,()=>Tt(this,null,function*(){if(e&&t.length){const c=t[0],i=n.get(c.body[0]),o=L.getImageServices(i)[0];return o&&(yield r.loadService({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height}))||void 0}}),{refetchOnWindowFocus:!1,refetchOnMount:!1,refetchIntervalInBackground:!1,refetchInterval:!1,initialData:()=>{if(e&&t.length){const c=t[0],i=n.get(c.body[0]),o=L.getImageServices(i)[0];return o&&r.loadServiceSync({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height})||void 0}}})}function Lt(){const e=we();return{isLoading:e.isFetching,tile:e.data?{id:e.data.id||e.data["@id"],width:e.data.width,height:e.data.height,imageService:e.data,thumbnail:void 0}:null}}function Oe(e,t=[]){const n=y(),r=B(),[c,i]=u.useState((e==null?void 0:e.defaultChoices)||[]),a=u.useMemo(()=>ce(n,r,c),[n,r,c,...t]),s={makeChoice:u.useCallback((l,{deselectOthers:p=!0,deselect:d=!1}={})=>{if(a.choice){if(a.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");i(v=>{if(d){const f=v.filter(m=>m!==l);if(f.length===0){const m=a.items[0].resource.id;return m?[m]:[]}return f}if(p)return[l];const _=[...v];if(_.length===0&&a.items.length){const f=a.items[0].resource.id;f&&_.push(f)}return v.indexOf(l)!==-1?v:[...v,l]})}},[a.choice])};return[a,s]}function jt(e={},t=[]){const{id:n,selector:r}=e,c=C(),i=n||c.range,a=P(o=>i?o.iiif.entities.Range[i]:void 0,[i]);return u.useMemo(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function Dt(e,t){const n=y(),r=u.useMemo(()=>b.createEventsHelper(n),[n]),c=P(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return u.useMemo(()=>e?r.getListenersAsProps(e,t):{},[c,e,n,t])}function Ce(e,t){return P((n,r)=>r.get(e.map(c=>({id:c,type:t}))),[e,t])}function Ft(){const e=$();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function Nt(){const e=y();return u.useMemo(()=>b.createStylesHelper(e),[e])}function Bt(e,t){const n=y(),r=u.useMemo(()=>b.createStylesHelper(n),[n]);return P(()=>{if(!e)return null;const c=r.getAppliedStyles(e.id);return c?t?c[t]:c:void 0},[e,t])}const Ee=(e,t=[])=>{const n=y();u.useEffect(()=>{e(n)},[n,...t])};function Ut(e,t,{canvasId:n,manifestId:r}={}){const c=y(),i=F(),a=u.useMemo(()=>b.createThumbnailHelper(c,{imageServiceLoader:i}),[c,i]),[o,s]=u.useState(),l=$(r?{id:r}:void 0),p=x(n?{id:n}:void 0),d=p||l,v=u.useRef(!1);if(u.useEffect(()=>()=>{v.current=!0},[]),!d)throw new Error("Must be called under a manifest or canvas context.");return Ee(_=>{a.getBestThumbnailAtSize(d,e,t).then(f=>{f.best&&!v.current&&s(f.best)})},[d]),o}var kt=Object.defineProperty,Ht=Object.defineProperties,Qt=Object.getOwnPropertyDescriptors,xe=Object.getOwnPropertySymbols,qt=Object.prototype.hasOwnProperty,zt=Object.prototype.propertyIsEnumerable,Ie=(e,t,n)=>t in e?kt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,be=(e,t)=>{for(var n in t||(t={}))qt.call(t,n)&&Ie(e,n,t[n]);if(xe)for(var n of xe(t))zt.call(t,n)&&Ie(e,n,t[n]);return e},Ae=(e,t)=>Ht(e,Qt(t));function Re(){const e=F(),[t,n]=u.useState({}),r=u.useRef(!1);return u.useEffect(()=>()=>{r.current=!0},[]),[u.useCallback((i,{height:a,width:o})=>{if(i){const s=i.id||i["@id"],l=e.loadServiceSync({id:s,width:i.width||o,height:i.height||a});l?i=l:t[s]||(r.current||n(p=>Ae(be({},p),{[s]:"loading"})),e.loadService({id:s,width:i.width||o,height:i.height||a}).then(()=>{r.current||n(p=>Ae(be({},p),{[s]:"done"}))}))}return i},[e,t]),t]}const Yt="@iiif/IMPORT_ENTITIES",Wt="@iiif/MODIFY_ENTITY_FIELD",Gt="@iiif/REORDER_ENTITY_FIELD",Xt="@iiif/ADD_REFERENCE",Jt="@iiif/REMOVE_REFERENCE",Kt=h.createAction(Yt)(),Zt=h.createAction(Wt)(),en=h.createAction(Gt)(),tn=h.createAction(Xt)(),nn=h.createAction(Jt)(),Q={importEntities:Kt,modifyEntityField:Zt,reorderEntityField:en,addReference:tn,removeReference:nn},rn="@iiif/ADD_MAPPING",on="@iiif/ADD_MAPPINGS";h.createAction(rn)(),h.createAction(on)();const an="@iiif/SET_META_VALUE",sn="@iiif/SET_META_VALUE_DYNAMIC",cn="@iiif/UNSET_META_VALUE";h.createAction(an)(),h.createAction(sn)(),h.createAction(cn)();const un="@iiif/REQUEST_RESOURCE",ln="@iiif/REQUEST_ERROR",fn="@iiif/REQUEST_MISMATCH",dn="@iiif/REQUEST_COMPLETE",pn="@iiif/REQUEST_OFFLINE_RESOURCE";h.createAction(un)(),h.createAction(ln)(),h.createAction(fn)(),h.createAction(dn)(),h.createAction(pn)();const vn="@iiif/BATCH";h.createAction(vn)();var mn=Object.defineProperty,gn=Object.defineProperties,yn=Object.getOwnPropertyDescriptors,Me=Object.getOwnPropertySymbols,hn=Object.prototype.hasOwnProperty,_n=Object.prototype.propertyIsEnumerable,$e=(e,t,n)=>t in e?mn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Pn=(e,t)=>{for(var n in t||(t={}))hn.call(t,n)&&$e(e,n,t[n]);if(Me)for(var n of Me(t))_n.call(t,n)&&$e(e,n,t[n]);return e},Sn=(e,t)=>gn(e,yn(t));function Ve(e){return typeof e!="string"&&e&&e.bindToVault}function wn(){const e=y(),t=u.useRef([]),n=_e(),r=u.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);u.useLayoutEffect(()=>{const o=Sn(Pn({},je.emptyAnnotationPage),{id:r,items:[]});n(Q.importEntities({entities:{AnnotationPage:{[o.id]:o}}}))},[r]);const c=P(o=>r?o.iiif.entities.AnnotationPage[r]:null,[r]),i=u.useCallback((o,s)=>{if(r){if(Ve(o)){const d=o;d.__vault||d.bindToVault(e),o=typeof d.source=="string"?d.source:d.source.id,t.current[o]=d}else typeof o!="string"&&(o=o.id);const l=e.get({id:r,type:"AnnotationPage"}),p=e.get({id:o,type:"Annotation"});l&&p&&(l.items.find(d=>d.id===p.id)||n(Q.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"},index:s})))}},[r]),a=u.useCallback(o=>{r&&(Ve(o)?o=typeof o.source=="string"?o.source:o.source.id:typeof o!="string"&&(o=o.id),t.current[o]&&t.current[o].beforeRemove(),e.get({id:r,type:"AnnotationPage"})&&n(Q.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"}})))},[r]);return[c,{addAnnotation:i,removeAnnotation:a}]}var On=Object.defineProperty,Cn=Object.defineProperties,En=Object.getOwnPropertyDescriptors,Te=Object.getOwnPropertySymbols,xn=Object.prototype.hasOwnProperty,In=Object.prototype.propertyIsEnumerable,Le=(e,t,n)=>t in e?On(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,bn=(e,t)=>{for(var n in t||(t={}))xn.call(t,n)&&Le(e,n,t[n]);if(Te)for(var n of Te(t))In.call(t,n)&&Le(e,n,t[n]);return e},An=(e,t)=>Cn(e,En(t));function Rn(e){const t=$(),n=x(),r=y(),[c,i]=Re(),{enabledPageIds:a}=he((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id),{all:!1}),o=Ce(a,"AnnotationPage"),s=(e==null?void 0:e.strategies)||["images","media","complex-timeline"],[l,p]=Oe(e,[i]),d=u.useMemo(()=>{if(!n||l.types.length===0)return H;if(l.types.length!==1)return s.indexOf("complex-timeline")===-1?S("Complex timeline not supported"):S("ComplexTimelineStrategy not yet supported");const v=l.types[0];return v==="image"?s.indexOf("images")===-1?S("Image not supported"):le(n,l,c):v==="audio"?s.indexOf("media")===-1?S("Media not supported"):S("Audio strategy not yet supported"):v==="video"?s.indexOf("media")===-1?S("Media not supported"):S("Video strategy not yet supported"):H},[n,l,r,p.makeChoice]);return u.useMemo(()=>d.type==="unknown"?[d,ue]:[An(bn({},d),{annotations:{pages:o}}),p],[d,o])}exports.AnnotationContext=ke,exports.CanvasContext=G,exports.CollectionContext=He,exports.ContextBridge=Ze,exports.ImageServiceLoaderContext=ne,exports.ManifestContext=X,exports.RangeContext=Qe,exports.ReactVaultContext=A,exports.ResourceProvider=E,exports.ResourceReactContext=j,exports.SimpleViewerProvider=Xe,exports.SimpleViewerReactContext=M,exports.VaultProvider=J,exports.VisibleCanvasReactContext=R,exports.emptyActions=ue,exports.expandTarget=O,exports.flattenAnnotationPageIds=pe,exports.getImageStrategy=le,exports.getPaintables=ce,exports.parseSelector=N,exports.parseSpecificResource=se,exports.unknownResponse=H,exports.unsupportedStrategy=S,exports.useAnnotation=vt,exports.useAnnotationPageManager=he,exports.useAnnotationsAtTime=Ot,exports.useCanvas=x,exports.useCanvasClock=Ct,exports.useCollection=Et,exports.useContextBridge=Ke,exports.useDispatch=_e,exports.useEventListener=xt,exports.useExistingVault=It,exports.useExternalCollection=Vt,exports.useExternalManifest=ee,exports.useImageService=we,exports.useImageServiceLoader=F,exports.useImageTile=Lt,exports.useLoadImageService=Re,exports.useManifest=$,exports.usePaintables=Oe,exports.usePaintingAnnotations=B,exports.useRange=jt,exports.useRenderingStrategy=Rn,exports.useResourceContext=C,exports.useResourceEvents=Dt,exports.useResources=Ce,exports.useSearchService=Ft,exports.useSimpleViewer=Je,exports.useStyleHelper=Nt,exports.useStyles=Bt,exports.useThumbnail=Ut,exports.useVault=y,exports.useVaultEffect=Ee,exports.useVaultSelector=P,exports.useVirtualAnnotationPage=wn,exports.useVisibleCanvases=te;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import g,{useContext as O,useMemo as m,useState as S,useEffect as $,createContext as Qe,useCallback as w,useRef as Q,useLayoutEffect as ke}from"react";import{globalVault as X,Vault as q}from"@iiif/vault";import{useQuery as k}from"react-query";import{ImageServiceLoader as ze,getImageServices as z}from"@atlas-viewer/iiif-image-api";import{createEventsHelper as J,createStylesHelper as K,createThumbnailHelper as Ye}from"@iiif/vault-helpers";import{createAction as y}from"typesafe-actions";import{emptyAnnotationPage as We}from"@iiif/parser";var Ge=Object.defineProperty,Z=Object.getOwnPropertySymbols,Xe=Object.prototype.hasOwnProperty,qe=Object.prototype.propertyIsEnumerable,ee=(e,t,n)=>t in e?Ge(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,te=(e,t)=>{for(var n in t||(t={}))Xe.call(t,n)&&ee(e,n,t[n]);if(Z)for(var n of Z(t))qe.call(t,n)&&ee(e,n,t[n]);return e};const Je={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},D=g.createContext(Je),b=()=>O(D),x=({value:e,children:t})=>{const n=b(),r=m(()=>te(te({},n),e),[e,n]);return g.createElement(D.Provider,{value:r},t)},Ke=({annotation:e,children:t})=>g.createElement(x,{value:{annotation:e}},t),ne=({canvas:e,children:t})=>g.createElement(x,{value:{canvas:e}},t),Ze=({collection:e,children:t})=>g.createElement(x,{value:{collection:e}},t),re=({manifest:e,children:t})=>g.createElement(x,{value:{manifest:e}},t),et=({range:e,children:t})=>g.createElement(x,{value:{range:e}},t),T=g.createContext({vault:null,setVaultInstance:e=>{}}),oe=({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:c})=>{const[i,a]=S(()=>e||(n?X(t):t?new q(t):new q));return g.createElement(T.Provider,{value:{vault:i,setVaultInstance:a}},g.createElement(x,{value:r||{}},c))},h=()=>{const{vault:e}=O(T);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var tt=Object.defineProperty,ie=Object.getOwnPropertySymbols,nt=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,ae=(e,t,n)=>t in e?tt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ot=(e,t)=>{for(var n in t||(t={}))nt.call(t,n)&&ae(e,n,t[n]);if(ie)for(var n of ie(t))rt.call(t,n)&&ae(e,n,t[n]);return e},it=(e,t,n)=>new Promise((r,c)=>{var i=s=>{try{o(n.next(s))}catch(l){c(l)}},a=s=>{try{o(n.throw(s))}catch(l){c(l)}},o=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);o((n=n.apply(e,t)).next())});const se=(e,t={})=>{const n=h(),[r,c]=S(e),i=m(()=>n.get(e)||void 0,[e,n]),{data:a,error:o}=k(["manifest",e],()=>it(void 0,null,function*(){const s=i||(yield n.load(e));return s&&r!==s.id&&c(s.id),s}),ot({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,retry:!1,initialData:i},t));return{isLoaded:!!a,id:r,error:o,manifest:a}};function P(e,t=[]){const n=h(),[r,c]=S(()=>e(n.getState(),n));return $(()=>n.subscribe(i=>e(i,n),i=>{c(i)},!0),t),r}const M=g.createContext([]);function ce(){const e=O(M);return P(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}const F=()=>{},V=Qe({setCurrentCanvasId:F,setCurrentCanvasIndex:F,nextCanvas:F,previousCanvas:F,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),at=e=>{const t=se(e.manifest),[n,r]=S(""),[c,i]=S([]),a=(typeof e.pagingEnabled>"u"||e.pagingEnabled)&&t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");$(()=>{var u,v;t.manifest&&(r((u=t.manifest.items[0])==null?void 0:u.id),i([(v=t.manifest.items[0])==null?void 0:v.id]))},[t.manifest,e.manifest]);const o=m(()=>{var u;return((u=t.manifest)==null?void 0:u.items.map(v=>v.id))||[]},[t.manifest,e.manifest]),s=m(()=>o.indexOf(n),[o,n]),l=w(()=>{if(o.length&&n){if(s===-1||(o[s+2]?s+2===o.length:s===o.length))return;const u=a&&s!==0?o[s+2]:o[s+1],v=a?s!==0?o[s+3]:o[s+2]:null;u&&(r(u),i(v?[u,v]:[u]))}},[a,o,n,s]),p=w(()=>{if(o.length&&n){if(s===0||s===-1)return;const u=a&&s!==1?o[s-2]:o[s-1],v=a&&s!==1?o[s-1]:null;u&&(r(u),i(v?[u,v]:[u]))}},[a,o,n,s]),f=w(u=>{const v=a&&u%2===1?u-1:u,C=o[v],G=a&&v!==0?o[v+1]:null;C&&(r(C),i(A=>{const H=G?[C,G]:[C];if(A.length===A.length){for(let j=0;j<A.length;j++)if(A[j]!==H[j])return H;return A}return H}))},[a,o]),d=w(u=>{const v=o.indexOf(u);v!==-1&&f(v)},[o,f]),_=m(()=>({setCurrentCanvasId:d,nextCanvas:l,previousCanvas:p,currentCanvasIndex:s,totalCanvases:o.length,setCurrentCanvasIndex:f,pagingView:!0}),[l,p,s,o,f,d]);return!t.isLoaded||!t.manifest?g.createElement("div",null,"Loading..."):g.createElement(V.Provider,{value:_},g.createElement(M.Provider,{value:c},g.createElement(re,{manifest:t.manifest.id},g.createElement(ne,{canvas:n},e.children))))};function st(){return O(V)}function ct(){return{VaultContext:O(T),ResourceContext:O(D),SimpleViewerReactContext:O(V),VisibleCanvasReactContext:O(M)}}const lt=e=>g.createElement(oe,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},g.createElement(M.Provider,{value:e.bridge.VisibleCanvasReactContext},g.createElement(V.Provider,{value:e.bridge.SimpleViewerReactContext},e.children))),le=g.createContext(new ze);function N(){return O(le)}const ut=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,ft=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function B(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:r,selectors:c}=B(n);return r&&(t.selector||(t.selector=r),t.selectors.push(...c)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,n]=e.split("#");return n?B({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=ut.exec(e.value);if(t){const r={type:"BoxSelector",spatial:{unit:t[2]==="percent:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:r,selectors:[r]}}const n=e.value.match(ft);if(n){const r={type:"TemporalSelector",temporal:{startTime:n[4]?parseFloat(n[4]):0,endTime:n[7]?parseFloat(n[7]):void 0}};return{selector:r,selectors:[r]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}var pt=Object.defineProperty,dt=Object.defineProperties,vt=Object.getOwnPropertyDescriptors,ue=Object.getOwnPropertySymbols,mt=Object.prototype.hasOwnProperty,gt=Object.prototype.propertyIsEnumerable,fe=(e,t,n)=>t in e?pt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,pe=(e,t)=>{for(var n in t||(t={}))mt.call(t,n)&&fe(e,n,t[n]);if(ue)for(var n of ue(t))gt.call(t,n)&&fe(e,n,t[n]);return e},de=(e,t)=>dt(e,vt(t));function I(e,t={}){if(Array.isArray(e))return I(e[0]);if(typeof e=="string"){const[n,r]=e.split("#");return r?I({type:"SpecificResource",source:{id:n,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return I(e.items[0]);if(e.type==="SpecificResource"){e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]);const{selector:n,selectors:r}=e.selector?B(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:n,selectors:r}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[n,r]=e.id.split("#");return r?I({type:"SpecificResource",source:de(pe({},e),{id:n}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:de(pe({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function ve(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function me(e,t,n){const r=[];let c=null;const i=[];for(const a of t){const o=e.get(a.body);for(const s of o){const[l,{selector:p}]=ve(s),f=(l.type||"unknown").toLowerCase();if(f==="choice"){const d=e.get(l.items),_=n.length?n.map(u=>d.find(v=>v.id===u)).filter(Boolean):[d[0]];_.length===0&&_.push(d[0]),c={type:"single-choice",items:d.map(u=>({id:u.id,label:u.label,selected:_.indexOf(u)!==-1})),label:s.label},o.push(..._);continue}r.indexOf(f)===-1&&r.push(f),i.push({type:f,resource:l,target:a.target,selector:p})}}return{types:r,items:i,choice:c}}const ge={makeChoice:()=>{}},Y={type:"unknown"},E=e=>({type:"unknown",reason:e,annotations:{pages:[]}});function he(e,t,n){const r=[];for(const c of t.items){const i=c.resource&&c.resource.type==="SpecificResource"?c.resource.source:c.resource;if(!i.id)return E("No resource Identifier");let a;if(i.service){const v=z(i);v[0]&&(a=n(v[0],e))}const{selector:o,source:s}=I(c.target);if(s.id!==e.id)continue;const l={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},p=o?o.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:o.temporal,spatial:l.spatial}:o:null,f={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},d=c.resource.type==="SpecificResource"?I(c.resource):null,_=d&&d.selector&&(d.selector.type==="BoxSelector"||d.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:d.selector.spatial.x,y:d.selector.spatial.y,width:d.selector.spatial.width,height:d.selector.spatial.height}}:f,u={id:i.id,type:"Image",width:p?i.width:e.width,height:p?i.height:e.height,service:a,sizes:a&&a.sizes?a.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:p&&p.type!=="PointSelector"?p:l,selector:_};r.push(u)}return{type:"images",image:r[0],images:r,choice:t.choice}}var ht=Object.defineProperty,yt=Object.defineProperties,_t=Object.getOwnPropertyDescriptors,ye=Object.getOwnPropertySymbols,Pt=Object.prototype.hasOwnProperty,Ot=Object.prototype.propertyIsEnumerable,_e=(e,t,n)=>t in e?ht(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,wt=(e,t)=>{for(var n in t||(t={}))Pt.call(t,n)&&_e(e,n,t[n]);if(ye)for(var n of ye(t))Ot.call(t,n)&&_e(e,n,t[n]);return e},St=(e,t)=>yt(e,_t(t));function Et(e={},t=[]){const{id:n,selector:r}=e,c=b(),i=h(),a=n||c.annotation,o=P(l=>a?l.iiif.entities.Annotation[a]:void 0,[a]),s=P(l=>o&&o.body?o.body.map(p=>p?l.iiif.entities[p.type][p.id]:null).filter(Boolean):[],[o]);return m(()=>{if(!o)return;const l=St(wt({},o),{body:s,target:I(o.target,{typeMap:i.getState().iiif.mapping})});return r?r(l):l},[o,r,s,...t])}function L(e={},t=[]){const{id:n,selector:r}=e,c=b();h();const i=n||c.manifest,a=P(o=>i?o.iiif.entities.Manifest[i]:void 0,[i]);return m(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function R(e={},t=[]){const{id:n,selector:r}=e,c=b(),i=n||c.canvas,a=P(o=>i?o.iiif.entities.Canvas[i]:void 0,[i]);return m(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function Ct(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function It(e,t){return P(n=>{const r=[];if(!e)return r;const c=Object.keys(n.iiif.entities.AnnotationPage);for(const i of c)if(!t||t.indexOf(i)!==-1){const a=Ct(n,i);a&&a.views&&a.views[e]&&r.push(i)}return r},[e])}function Pe({canvas:e,manifest:t,all:n,canvases:r}){const c=[];if(t)for(const i of t.annotations)c.indexOf(i.id)===-1&&c.push(i.id);if(n){if(r&&r.length)for(const i of r)for(const a of i.annotations)c.indexOf(a.id)===-1&&c.push(a.id)}else if(e)for(const i of e.annotations)c.indexOf(i.id)===-1&&c.push(i.id);return c}var bt=Object.defineProperty,xt=Object.defineProperties,$t=Object.getOwnPropertyDescriptors,Oe=Object.getOwnPropertySymbols,Rt=Object.prototype.hasOwnProperty,At=Object.prototype.propertyIsEnumerable,we=(e,t,n)=>t in e?bt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Se=(e,t)=>{for(var n in t||(t={}))Rt.call(t,n)&&we(e,n,t[n]);if(Oe)for(var n of Oe(t))At.call(t,n)&&we(e,n,t[n]);return e},Ee=(e,t)=>xt(e,$t(t));function Tt(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function Ce(e,t={}){const n=h(),r=L(),c=R(),i=ce(),a=m(()=>Pe({all:t.all,manifest:r,canvas:c,canvases:i}),[t.all,c,i,r]),o=It(e,t.all?void 0:a),s=w(p=>{!e||n.setMetaValue([p,"annotationPageManager","views"],f=>f&&!f[e]?f:Ee(Se({},f||{}),{[e]:!1}))},[e,n]),l=w((p,f={})=>{if(!e)return;const d=n.getState(),_=[];if(f==null?void 0:f.deselectOthers){const u=Object.keys(d.iiif.entities.AnnotationPage);for(const v of u){const C=Tt(d,v);C&&C.views&&C.views[e]&&_.push(v)}}for(const u of _)s(u);n.setMetaValue([p,"annotationPageManager","views"],u=>u&&u[e]?u:Ee(Se({},u||{}),{[e]:!0}))},[e,s,n]);return{availablePageIds:a,enabledPageIds:o,setPageEnabled:l,setPageDisabled:s}}function U(e={}){const t=R(e.canvasId?{id:e.canvasId}:void 0);return P((n,r)=>{if(!t)return[];const c=r.get(t.items),i=[];for(const a of c)i.push(...r.get(a.items));return i},[t])}function Mt(e,t={}){return U(t)}function Vt(e,t=!1){}function Lt(e,t=[]){const{id:n,selector:r}=e,c=b(),i=n||c.collection,a=P(o=>i?o.iiif.entities.Collection[i]:void 0,[i]);return m(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function Ie(){const t=h().getStore();return m(()=>n=>t.dispatch(n),[t])}function jt(e,t,n,r,c=[]){const i=h(),a=m(()=>J(i),[i]);$(()=>{const o=e;return o?(a.addEventListener(o,t,n,r),()=>{a.removeEventListener(o,t,n)}):()=>{}},[a,e,t,...c])}function Dt(){const e=O(T);return e&&e.vault?e.vault:X()}var Ft=Object.defineProperty,be=Object.getOwnPropertySymbols,Nt=Object.prototype.hasOwnProperty,Bt=Object.prototype.propertyIsEnumerable,xe=(e,t,n)=>t in e?Ft(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ut=(e,t)=>{for(var n in t||(t={}))Nt.call(t,n)&&xe(e,n,t[n]);if(be)for(var n of be(t))Bt.call(t,n)&&xe(e,n,t[n]);return e},Ht=(e,t,n)=>new Promise((r,c)=>{var i=s=>{try{o(n.next(s))}catch(l){c(l)}},a=s=>{try{o(n.throw(s))}catch(l){c(l)}},o=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);o((n=n.apply(e,t)).next())});const Qt=(e,t={})=>{const n=h(),[r,c]=S(e),i=m(()=>n.get(e),[e,n]),{data:a,isFetching:o}=k(`collection:${e}`,()=>Ht(void 0,null,function*(){const s=i||(yield n.loadCollection(e));return s&&c(s.id),s}),Ut({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,initialData:i},t));return{isLoaded:!o,id:r,collection:a}};var kt=(e,t,n)=>new Promise((r,c)=>{var i=s=>{try{o(n.next(s))}catch(l){c(l)}},a=s=>{try{o(n.throw(s))}catch(l){c(l)}},o=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);o((n=n.apply(e,t)).next())});function $e(){const e=R(),t=U(),n=h(),r=N();return k(`canvas-first-image-service:${e?e.id:"undefined"}`,()=>kt(this,null,function*(){if(e&&t.length){const c=t[0],i=n.get(c.body[0]),o=z(i)[0];return o&&(yield r.loadService({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height}))||void 0}}),{refetchOnWindowFocus:!1,refetchOnMount:!1,refetchIntervalInBackground:!1,refetchInterval:!1,initialData:()=>{if(e&&t.length){const c=t[0],i=n.get(c.body[0]),o=z(i)[0];return o&&r.loadServiceSync({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height})||void 0}}})}function zt(){const e=$e();return{isLoading:e.isFetching,tile:e.data?{id:e.data.id||e.data["@id"],width:e.data.width,height:e.data.height,imageService:e.data,thumbnail:void 0}:null}}function Re(e,t=[]){const n=h(),r=U(),[c,i]=S((e==null?void 0:e.defaultChoices)||[]),a=m(()=>me(n,r,c),[n,r,c,...t]),s={makeChoice:w((l,{deselectOthers:p=!0,deselect:f=!1}={})=>{if(a.choice){if(a.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");i(d=>{if(f){const u=d.filter(v=>v!==l);if(u.length===0){const v=a.items[0].resource.id;return v?[v]:[]}return u}if(p)return[l];const _=[...d];if(_.length===0&&a.items.length){const u=a.items[0].resource.id;u&&_.push(u)}return d.indexOf(l)!==-1?d:[...d,l]})}},[a.choice])};return[a,s]}function Yt(e={},t=[]){const{id:n,selector:r}=e,c=b(),i=n||c.range,a=P(o=>i?o.iiif.entities.Range[i]:void 0,[i]);return m(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function Wt(e,t){const n=h(),r=m(()=>J(n),[n]),c=P(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return m(()=>e?r.getListenersAsProps(e,t):{},[c,e,n,t])}function Ae(e,t){return P((n,r)=>r.get(e.map(c=>({id:c,type:t}))),[e,t])}function Gt(){const e=L();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function Xt(){const e=h();return m(()=>K(e),[e])}function qt(e,t){const n=h(),r=m(()=>K(n),[n]);return P(()=>{if(!e)return null;const c=r.getAppliedStyles(e.id);return c?t?c[t]:c:void 0},[e,t])}const Te=(e,t=[])=>{const n=h();$(()=>{e(n)},[n,...t])};function Jt(e,t,{canvasId:n,manifestId:r}={}){const c=h(),i=N(),a=m(()=>Ye(c,{imageServiceLoader:i}),[c,i]),[o,s]=S(),l=L(r?{id:r}:void 0),p=R(n?{id:n}:void 0),f=p||l,d=Q(!1);if($(()=>()=>{d.current=!0},[]),!f)throw new Error("Must be called under a manifest or canvas context.");return Te(_=>{a.getBestThumbnailAtSize(f,e,t).then(u=>{u.best&&!d.current&&s(u.best)})},[f]),o}var Kt=Object.defineProperty,Zt=Object.defineProperties,en=Object.getOwnPropertyDescriptors,Me=Object.getOwnPropertySymbols,tn=Object.prototype.hasOwnProperty,nn=Object.prototype.propertyIsEnumerable,Ve=(e,t,n)=>t in e?Kt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Le=(e,t)=>{for(var n in t||(t={}))tn.call(t,n)&&Ve(e,n,t[n]);if(Me)for(var n of Me(t))nn.call(t,n)&&Ve(e,n,t[n]);return e},je=(e,t)=>Zt(e,en(t));function De(){const e=N(),[t,n]=S({}),r=Q(!1);return $(()=>()=>{r.current=!0},[]),[w((i,{height:a,width:o})=>{if(i){const s=i.id||i["@id"],l=e.loadServiceSync({id:s,width:i.width||o,height:i.height||a});l?i=l:t[s]||(r.current||n(p=>je(Le({},p),{[s]:"loading"})),e.loadService({id:s,width:i.width||o,height:i.height||a}).then(()=>{r.current||n(p=>je(Le({},p),{[s]:"done"}))}))}return i},[e,t]),t]}const rn="@iiif/IMPORT_ENTITIES",on="@iiif/MODIFY_ENTITY_FIELD",an="@iiif/REORDER_ENTITY_FIELD",sn="@iiif/ADD_REFERENCE",cn="@iiif/REMOVE_REFERENCE",ln=y(rn)(),un=y(on)(),fn=y(an)(),pn=y(sn)(),dn=y(cn)(),W={importEntities:ln,modifyEntityField:un,reorderEntityField:fn,addReference:pn,removeReference:dn},vn="@iiif/ADD_MAPPING",mn="@iiif/ADD_MAPPINGS";y(vn)(),y(mn)();const gn="@iiif/SET_META_VALUE",hn="@iiif/SET_META_VALUE_DYNAMIC",yn="@iiif/UNSET_META_VALUE";y(gn)(),y(hn)(),y(yn)();const _n="@iiif/REQUEST_RESOURCE",Pn="@iiif/REQUEST_ERROR",On="@iiif/REQUEST_MISMATCH",wn="@iiif/REQUEST_COMPLETE",Sn="@iiif/REQUEST_OFFLINE_RESOURCE";y(_n)(),y(Pn)(),y(On)(),y(wn)(),y(Sn)();const En="@iiif/BATCH";y(En)();var Cn=Object.defineProperty,In=Object.defineProperties,bn=Object.getOwnPropertyDescriptors,Fe=Object.getOwnPropertySymbols,xn=Object.prototype.hasOwnProperty,$n=Object.prototype.propertyIsEnumerable,Ne=(e,t,n)=>t in e?Cn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Rn=(e,t)=>{for(var n in t||(t={}))xn.call(t,n)&&Ne(e,n,t[n]);if(Fe)for(var n of Fe(t))$n.call(t,n)&&Ne(e,n,t[n]);return e},An=(e,t)=>In(e,bn(t));function Be(e){return typeof e!="string"&&e&&e.bindToVault}function Tn(){const e=h(),t=Q([]),n=Ie(),r=m(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);ke(()=>{const o=An(Rn({},We),{id:r,items:[]});n(W.importEntities({entities:{AnnotationPage:{[o.id]:o}}}))},[r]);const c=P(o=>r?o.iiif.entities.AnnotationPage[r]:null,[r]),i=w((o,s)=>{if(r){if(Be(o)){const f=o;f.__vault||f.bindToVault(e),o=typeof f.source=="string"?f.source:f.source.id,t.current[o]=f}else typeof o!="string"&&(o=o.id);const l=e.get({id:r,type:"AnnotationPage"}),p=e.get({id:o,type:"Annotation"});l&&p&&(l.items.find(f=>f.id===p.id)||n(W.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"},index:s})))}},[r]),a=w(o=>{r&&(Be(o)?o=typeof o.source=="string"?o.source:o.source.id:typeof o!="string"&&(o=o.id),t.current[o]&&t.current[o].beforeRemove(),e.get({id:r,type:"AnnotationPage"})&&n(W.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"}})))},[r]);return[c,{addAnnotation:i,removeAnnotation:a}]}var Mn=Object.defineProperty,Vn=Object.defineProperties,Ln=Object.getOwnPropertyDescriptors,Ue=Object.getOwnPropertySymbols,jn=Object.prototype.hasOwnProperty,Dn=Object.prototype.propertyIsEnumerable,He=(e,t,n)=>t in e?Mn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Fn=(e,t)=>{for(var n in t||(t={}))jn.call(t,n)&&He(e,n,t[n]);if(Ue)for(var n of Ue(t))Dn.call(t,n)&&He(e,n,t[n]);return e},Nn=(e,t)=>Vn(e,Ln(t));function Bn(e){const t=L(),n=R(),r=h(),[c,i]=De(),{enabledPageIds:a}=Ce((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id),{all:!1}),o=Ae(a,"AnnotationPage"),s=(e==null?void 0:e.strategies)||["images","media","complex-timeline"],[l,p]=Re(e,[i]),f=m(()=>{if(!n||l.types.length===0)return Y;if(l.types.length!==1)return s.indexOf("complex-timeline")===-1?E("Complex timeline not supported"):E("ComplexTimelineStrategy not yet supported");const d=l.types[0];return d==="image"?s.indexOf("images")===-1?E("Image not supported"):he(n,l,c):d==="audio"?s.indexOf("media")===-1?E("Media not supported"):E("Audio strategy not yet supported"):d==="video"?s.indexOf("media")===-1?E("Media not supported"):E("Video strategy not yet supported"):Y},[n,l,r,p.makeChoice]);return m(()=>f.type==="unknown"?[f,ge]:[Nn(Fn({},f),{annotations:{pages:o}}),p],[f,o])}export{Ke as AnnotationContext,ne as CanvasContext,Ze as CollectionContext,lt as ContextBridge,le as ImageServiceLoaderContext,re as ManifestContext,et as RangeContext,T as ReactVaultContext,x as ResourceProvider,D as ResourceReactContext,at as SimpleViewerProvider,V as SimpleViewerReactContext,oe as VaultProvider,M as VisibleCanvasReactContext,ge as emptyActions,I as expandTarget,Pe as flattenAnnotationPageIds,he as getImageStrategy,me as getPaintables,B as parseSelector,ve as parseSpecificResource,Y as unknownResponse,E as unsupportedStrategy,Et as useAnnotation,Ce as useAnnotationPageManager,Mt as useAnnotationsAtTime,R as useCanvas,Vt as useCanvasClock,Lt as useCollection,ct as useContextBridge,Ie as useDispatch,jt as useEventListener,Dt as useExistingVault,Qt as useExternalCollection,se as useExternalManifest,$e as useImageService,N as useImageServiceLoader,zt as useImageTile,De as useLoadImageService,L as useManifest,Re as usePaintables,U as usePaintingAnnotations,Yt as useRange,Bn as useRenderingStrategy,b as useResourceContext,Wt as useResourceEvents,Ae as useResources,Gt as useSearchService,st as useSimpleViewer,Xt as useStyleHelper,qt as useStyles,Jt as useThumbnail,h as useVault,Te as useVaultEffect,P as useVaultSelector,Tn as useVirtualAnnotationPage,ce as useVisibleCanvases};
|
|
1
|
+
import g,{useContext as O,useMemo as m,useState as S,useEffect as $,createContext as Qe,useCallback as w,useRef as Q,useLayoutEffect as ke}from"react";import{globalVault as X,Vault as q}from"@iiif/vault";import{useQuery as k}from"react-query";import{ImageServiceLoader as ze,getImageServices as z}from"@atlas-viewer/iiif-image-api";import{createEventsHelper as J,createStylesHelper as K,createThumbnailHelper as Ye}from"@iiif/vault-helpers";import{createAction as y}from"typesafe-actions";import{emptyAnnotationPage as We}from"@iiif/parser";var Ge=Object.defineProperty,Z=Object.getOwnPropertySymbols,Xe=Object.prototype.hasOwnProperty,qe=Object.prototype.propertyIsEnumerable,ee=(e,t,n)=>t in e?Ge(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,te=(e,t)=>{for(var n in t||(t={}))Xe.call(t,n)&&ee(e,n,t[n]);if(Z)for(var n of Z(t))qe.call(t,n)&&ee(e,n,t[n]);return e};const Je={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},D=g.createContext(Je),b=()=>O(D),x=({value:e,children:t})=>{const n=b(),r=m(()=>te(te({},n),e),[e,n]);return g.createElement(D.Provider,{value:r},t)},Ke=({annotation:e,children:t})=>g.createElement(x,{value:{annotation:e}},t),ne=({canvas:e,children:t})=>g.createElement(x,{value:{canvas:e}},t),Ze=({collection:e,children:t})=>g.createElement(x,{value:{collection:e}},t),re=({manifest:e,children:t})=>g.createElement(x,{value:{manifest:e}},t),et=({range:e,children:t})=>g.createElement(x,{value:{range:e}},t),T=g.createContext({vault:null,setVaultInstance:e=>{}}),oe=({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:c})=>{const[i,a]=S(()=>e||(n?X(t):t?new q(t):new q));return g.createElement(T.Provider,{value:{vault:i,setVaultInstance:a}},g.createElement(x,{value:r||{}},c))},h=()=>{const{vault:e}=O(T);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var tt=Object.defineProperty,ie=Object.getOwnPropertySymbols,nt=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,ae=(e,t,n)=>t in e?tt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ot=(e,t)=>{for(var n in t||(t={}))nt.call(t,n)&&ae(e,n,t[n]);if(ie)for(var n of ie(t))rt.call(t,n)&&ae(e,n,t[n]);return e},it=(e,t,n)=>new Promise((r,c)=>{var i=s=>{try{o(n.next(s))}catch(l){c(l)}},a=s=>{try{o(n.throw(s))}catch(l){c(l)}},o=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);o((n=n.apply(e,t)).next())});const se=(e,t={})=>{const n=h(),[r,c]=S(e),i=m(()=>n.get(e)||void 0,[e,n]),{data:a,error:o}=k(["manifest",e],()=>it(void 0,null,function*(){const s=i||(yield n.load(e));return s&&r!==s.id&&c(s.id),s}),ot({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,retry:!1,initialData:i},t));return{isLoaded:!!a,id:r,error:o,manifest:a}};function P(e,t=[]){const n=h(),[r,c]=S(()=>e(n.getState(),n));return $(()=>n.subscribe(i=>e(i,n),i=>{c(i)},!1),t),r}const M=g.createContext([]);function ce(){const e=O(M);return P(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}const F=()=>{},V=Qe({setCurrentCanvasId:F,setCurrentCanvasIndex:F,nextCanvas:F,previousCanvas:F,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),at=e=>{const t=se(e.manifest),[n,r]=S(""),[c,i]=S([]),a=(typeof e.pagingEnabled>"u"||e.pagingEnabled)&&t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");$(()=>{var u,v;t.manifest&&(r((u=t.manifest.items[0])==null?void 0:u.id),i([(v=t.manifest.items[0])==null?void 0:v.id]))},[t.manifest,e.manifest]);const o=m(()=>{var u;return((u=t.manifest)==null?void 0:u.items.map(v=>v.id))||[]},[t.manifest,e.manifest]),s=m(()=>o.indexOf(n),[o,n]),l=w(()=>{if(o.length&&n){if(s===-1||(o[s+2]?s+2===o.length:s===o.length))return;const u=a&&s!==0?o[s+2]:o[s+1],v=a?s!==0?o[s+3]:o[s+2]:null;u&&(r(u),i(v?[u,v]:[u]))}},[a,o,n,s]),p=w(()=>{if(o.length&&n){if(s===0||s===-1)return;const u=a&&s!==1?o[s-2]:o[s-1],v=a&&s!==1?o[s-1]:null;u&&(r(u),i(v?[u,v]:[u]))}},[a,o,n,s]),f=w(u=>{const v=a&&u%2===1?u-1:u,C=o[v],G=a&&v!==0?o[v+1]:null;C&&(r(C),i(A=>{const H=G?[C,G]:[C];if(A.length===A.length){for(let j=0;j<A.length;j++)if(A[j]!==H[j])return H;return A}return H}))},[a,o]),d=w(u=>{const v=o.indexOf(u);v!==-1&&f(v)},[o,f]),_=m(()=>({setCurrentCanvasId:d,nextCanvas:l,previousCanvas:p,currentCanvasIndex:s,totalCanvases:o.length,setCurrentCanvasIndex:f,pagingView:!0}),[l,p,s,o,f,d]);return!t.isLoaded||!t.manifest?g.createElement("div",null,"Loading..."):g.createElement(V.Provider,{value:_},g.createElement(M.Provider,{value:c},g.createElement(re,{manifest:t.manifest.id},g.createElement(ne,{canvas:n},e.children))))};function st(){return O(V)}function ct(){return{VaultContext:O(T),ResourceContext:O(D),SimpleViewerReactContext:O(V),VisibleCanvasReactContext:O(M)}}const lt=e=>g.createElement(oe,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},g.createElement(M.Provider,{value:e.bridge.VisibleCanvasReactContext},g.createElement(V.Provider,{value:e.bridge.SimpleViewerReactContext},e.children))),le=g.createContext(new ze);function N(){return O(le)}const ut=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,ft=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function B(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:r,selectors:c}=B(n);return r&&(t.selector||(t.selector=r),t.selectors.push(...c)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,n]=e.split("#");return n?B({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=ut.exec(e.value);if(t){const r={type:"BoxSelector",spatial:{unit:t[2]==="percent:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:r,selectors:[r]}}const n=e.value.match(ft);if(n){const r={type:"TemporalSelector",temporal:{startTime:n[4]?parseFloat(n[4]):0,endTime:n[7]?parseFloat(n[7]):void 0}};return{selector:r,selectors:[r]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}var pt=Object.defineProperty,dt=Object.defineProperties,vt=Object.getOwnPropertyDescriptors,ue=Object.getOwnPropertySymbols,mt=Object.prototype.hasOwnProperty,gt=Object.prototype.propertyIsEnumerable,fe=(e,t,n)=>t in e?pt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,pe=(e,t)=>{for(var n in t||(t={}))mt.call(t,n)&&fe(e,n,t[n]);if(ue)for(var n of ue(t))gt.call(t,n)&&fe(e,n,t[n]);return e},de=(e,t)=>dt(e,vt(t));function I(e,t={}){if(Array.isArray(e))return I(e[0]);if(typeof e=="string"){const[n,r]=e.split("#");return r?I({type:"SpecificResource",source:{id:n,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return I(e.items[0]);if(e.type==="SpecificResource"){e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]);const{selector:n,selectors:r}=e.selector?B(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:n,selectors:r}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[n,r]=e.id.split("#");return r?I({type:"SpecificResource",source:de(pe({},e),{id:n}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:de(pe({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function ve(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function me(e,t,n){const r=[];let c=null;const i=[];for(const a of t){const o=e.get(a.body);for(const s of o){const[l,{selector:p}]=ve(s),f=(l.type||"unknown").toLowerCase();if(f==="choice"){const d=e.get(l.items),_=n.length?n.map(u=>d.find(v=>v.id===u)).filter(Boolean):[d[0]];_.length===0&&_.push(d[0]),c={type:"single-choice",items:d.map(u=>({id:u.id,label:u.label,selected:_.indexOf(u)!==-1})),label:s.label},o.push(..._);continue}r.indexOf(f)===-1&&r.push(f),i.push({type:f,resource:l,target:a.target,selector:p})}}return{types:r,items:i,choice:c}}const ge={makeChoice:()=>{}},Y={type:"unknown"},E=e=>({type:"unknown",reason:e,annotations:{pages:[]}});function he(e,t,n){const r=[];for(const c of t.items){const i=c.resource&&c.resource.type==="SpecificResource"?c.resource.source:c.resource;if(!i.id)return E("No resource Identifier");let a;if(i.service){const v=z(i);v[0]&&(a=n(v[0],e))}const{selector:o,source:s}=I(c.target);if(s.id!==e.id)continue;const l={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},p=o?o.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:o.temporal,spatial:l.spatial}:o:null,f={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},d=c.resource.type==="SpecificResource"?I(c.resource):null,_=d&&d.selector&&(d.selector.type==="BoxSelector"||d.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:d.selector.spatial.x,y:d.selector.spatial.y,width:d.selector.spatial.width,height:d.selector.spatial.height}}:f,u={id:i.id,type:"Image",width:p?i.width:e.width,height:p?i.height:e.height,service:a,sizes:a&&a.sizes?a.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:p&&p.type!=="PointSelector"?p:l,selector:_};r.push(u)}return{type:"images",image:r[0],images:r,choice:t.choice}}var ht=Object.defineProperty,yt=Object.defineProperties,_t=Object.getOwnPropertyDescriptors,ye=Object.getOwnPropertySymbols,Pt=Object.prototype.hasOwnProperty,Ot=Object.prototype.propertyIsEnumerable,_e=(e,t,n)=>t in e?ht(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,wt=(e,t)=>{for(var n in t||(t={}))Pt.call(t,n)&&_e(e,n,t[n]);if(ye)for(var n of ye(t))Ot.call(t,n)&&_e(e,n,t[n]);return e},St=(e,t)=>yt(e,_t(t));function Et(e={},t=[]){const{id:n,selector:r}=e,c=b(),i=h(),a=n||c.annotation,o=P(l=>a?l.iiif.entities.Annotation[a]:void 0,[a]),s=P(l=>o&&o.body?o.body.map(p=>p?l.iiif.entities[p.type][p.id]:null).filter(Boolean):[],[o]);return m(()=>{if(!o)return;const l=St(wt({},o),{body:s,target:I(o.target,{typeMap:i.getState().iiif.mapping})});return r?r(l):l},[o,r,s,...t])}function L(e={},t=[]){const{id:n,selector:r}=e,c=b();h();const i=n||c.manifest,a=P(o=>i?o.iiif.entities.Manifest[i]:void 0,[i]);return m(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function R(e={},t=[]){const{id:n,selector:r}=e,c=b(),i=n||c.canvas,a=P(o=>i?o.iiif.entities.Canvas[i]:void 0,[i]);return m(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function Ct(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function It(e,t){return P(n=>{const r=[];if(!e)return r;const c=Object.keys(n.iiif.entities.AnnotationPage);for(const i of c)if(!t||t.indexOf(i)!==-1){const a=Ct(n,i);a&&a.views&&a.views[e]&&r.push(i)}return r},[e])}function Pe({canvas:e,manifest:t,all:n,canvases:r}){const c=[];if(t)for(const i of t.annotations)c.indexOf(i.id)===-1&&c.push(i.id);if(n){if(r&&r.length)for(const i of r)for(const a of i.annotations)c.indexOf(a.id)===-1&&c.push(a.id)}else if(e)for(const i of e.annotations)c.indexOf(i.id)===-1&&c.push(i.id);return c}var bt=Object.defineProperty,xt=Object.defineProperties,$t=Object.getOwnPropertyDescriptors,Oe=Object.getOwnPropertySymbols,Rt=Object.prototype.hasOwnProperty,At=Object.prototype.propertyIsEnumerable,we=(e,t,n)=>t in e?bt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Se=(e,t)=>{for(var n in t||(t={}))Rt.call(t,n)&&we(e,n,t[n]);if(Oe)for(var n of Oe(t))At.call(t,n)&&we(e,n,t[n]);return e},Ee=(e,t)=>xt(e,$t(t));function Tt(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function Ce(e,t={}){const n=h(),r=L(),c=R(),i=ce(),a=m(()=>Pe({all:t.all,manifest:r,canvas:c,canvases:i}),[t.all,c,i,r]),o=It(e,t.all?void 0:a),s=w(p=>{!e||n.setMetaValue([p,"annotationPageManager","views"],f=>f&&!f[e]?f:Ee(Se({},f||{}),{[e]:!1}))},[e,n]),l=w((p,f={})=>{if(!e)return;const d=n.getState(),_=[];if(f==null?void 0:f.deselectOthers){const u=Object.keys(d.iiif.entities.AnnotationPage);for(const v of u){const C=Tt(d,v);C&&C.views&&C.views[e]&&_.push(v)}}for(const u of _)s(u);n.setMetaValue([p,"annotationPageManager","views"],u=>u&&u[e]?u:Ee(Se({},u||{}),{[e]:!0}))},[e,s,n]);return{availablePageIds:a,enabledPageIds:o,setPageEnabled:l,setPageDisabled:s}}function U(e={}){const t=R(e.canvasId?{id:e.canvasId}:void 0);return P((n,r)=>{if(!t)return[];const c=r.get(t.items),i=[];for(const a of c)i.push(...r.get(a.items));return i},[t])}function Mt(e,t={}){return U(t)}function Vt(e,t=!1){}function Lt(e,t=[]){const{id:n,selector:r}=e,c=b(),i=n||c.collection,a=P(o=>i?o.iiif.entities.Collection[i]:void 0,[i]);return m(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function Ie(){const t=h().getStore();return m(()=>n=>t.dispatch(n),[t])}function jt(e,t,n,r,c=[]){const i=h(),a=m(()=>J(i),[i]);$(()=>{const o=e;return o?(a.addEventListener(o,t,n,r),()=>{a.removeEventListener(o,t,n)}):()=>{}},[a,e,t,...c])}function Dt(){const e=O(T);return e&&e.vault?e.vault:X()}var Ft=Object.defineProperty,be=Object.getOwnPropertySymbols,Nt=Object.prototype.hasOwnProperty,Bt=Object.prototype.propertyIsEnumerable,xe=(e,t,n)=>t in e?Ft(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ut=(e,t)=>{for(var n in t||(t={}))Nt.call(t,n)&&xe(e,n,t[n]);if(be)for(var n of be(t))Bt.call(t,n)&&xe(e,n,t[n]);return e},Ht=(e,t,n)=>new Promise((r,c)=>{var i=s=>{try{o(n.next(s))}catch(l){c(l)}},a=s=>{try{o(n.throw(s))}catch(l){c(l)}},o=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);o((n=n.apply(e,t)).next())});const Qt=(e,t={})=>{const n=h(),[r,c]=S(e),i=m(()=>n.get(e),[e,n]),{data:a,isFetching:o}=k(`collection:${e}`,()=>Ht(void 0,null,function*(){const s=i||(yield n.loadCollection(e));return s&&c(s.id),s}),Ut({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,initialData:i},t));return{isLoaded:!o,id:r,collection:a}};var kt=(e,t,n)=>new Promise((r,c)=>{var i=s=>{try{o(n.next(s))}catch(l){c(l)}},a=s=>{try{o(n.throw(s))}catch(l){c(l)}},o=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);o((n=n.apply(e,t)).next())});function $e(){const e=R(),t=U(),n=h(),r=N();return k(`canvas-first-image-service:${e?e.id:"undefined"}`,()=>kt(this,null,function*(){if(e&&t.length){const c=t[0],i=n.get(c.body[0]),o=z(i)[0];return o&&(yield r.loadService({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height}))||void 0}}),{refetchOnWindowFocus:!1,refetchOnMount:!1,refetchIntervalInBackground:!1,refetchInterval:!1,initialData:()=>{if(e&&t.length){const c=t[0],i=n.get(c.body[0]),o=z(i)[0];return o&&r.loadServiceSync({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height})||void 0}}})}function zt(){const e=$e();return{isLoading:e.isFetching,tile:e.data?{id:e.data.id||e.data["@id"],width:e.data.width,height:e.data.height,imageService:e.data,thumbnail:void 0}:null}}function Re(e,t=[]){const n=h(),r=U(),[c,i]=S((e==null?void 0:e.defaultChoices)||[]),a=m(()=>me(n,r,c),[n,r,c,...t]),s={makeChoice:w((l,{deselectOthers:p=!0,deselect:f=!1}={})=>{if(a.choice){if(a.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");i(d=>{if(f){const u=d.filter(v=>v!==l);if(u.length===0){const v=a.items[0].resource.id;return v?[v]:[]}return u}if(p)return[l];const _=[...d];if(_.length===0&&a.items.length){const u=a.items[0].resource.id;u&&_.push(u)}return d.indexOf(l)!==-1?d:[...d,l]})}},[a.choice])};return[a,s]}function Yt(e={},t=[]){const{id:n,selector:r}=e,c=b(),i=n||c.range,a=P(o=>i?o.iiif.entities.Range[i]:void 0,[i]);return m(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function Wt(e,t){const n=h(),r=m(()=>J(n),[n]),c=P(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return m(()=>e?r.getListenersAsProps(e,t):{},[c,e,n,t])}function Ae(e,t){return P((n,r)=>r.get(e.map(c=>({id:c,type:t}))),[e,t])}function Gt(){const e=L();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function Xt(){const e=h();return m(()=>K(e),[e])}function qt(e,t){const n=h(),r=m(()=>K(n),[n]);return P(()=>{if(!e)return null;const c=r.getAppliedStyles(e.id);return c?t?c[t]:c:void 0},[e,t])}const Te=(e,t=[])=>{const n=h();$(()=>{e(n)},[n,...t])};function Jt(e,t,{canvasId:n,manifestId:r}={}){const c=h(),i=N(),a=m(()=>Ye(c,{imageServiceLoader:i}),[c,i]),[o,s]=S(),l=L(r?{id:r}:void 0),p=R(n?{id:n}:void 0),f=p||l,d=Q(!1);if($(()=>()=>{d.current=!0},[]),!f)throw new Error("Must be called under a manifest or canvas context.");return Te(_=>{a.getBestThumbnailAtSize(f,e,t).then(u=>{u.best&&!d.current&&s(u.best)})},[f]),o}var Kt=Object.defineProperty,Zt=Object.defineProperties,en=Object.getOwnPropertyDescriptors,Me=Object.getOwnPropertySymbols,tn=Object.prototype.hasOwnProperty,nn=Object.prototype.propertyIsEnumerable,Ve=(e,t,n)=>t in e?Kt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Le=(e,t)=>{for(var n in t||(t={}))tn.call(t,n)&&Ve(e,n,t[n]);if(Me)for(var n of Me(t))nn.call(t,n)&&Ve(e,n,t[n]);return e},je=(e,t)=>Zt(e,en(t));function De(){const e=N(),[t,n]=S({}),r=Q(!1);return $(()=>()=>{r.current=!0},[]),[w((i,{height:a,width:o})=>{if(i){const s=i.id||i["@id"],l=e.loadServiceSync({id:s,width:i.width||o,height:i.height||a});l?i=l:t[s]||(r.current||n(p=>je(Le({},p),{[s]:"loading"})),e.loadService({id:s,width:i.width||o,height:i.height||a}).then(()=>{r.current||n(p=>je(Le({},p),{[s]:"done"}))}))}return i},[e,t]),t]}const rn="@iiif/IMPORT_ENTITIES",on="@iiif/MODIFY_ENTITY_FIELD",an="@iiif/REORDER_ENTITY_FIELD",sn="@iiif/ADD_REFERENCE",cn="@iiif/REMOVE_REFERENCE",ln=y(rn)(),un=y(on)(),fn=y(an)(),pn=y(sn)(),dn=y(cn)(),W={importEntities:ln,modifyEntityField:un,reorderEntityField:fn,addReference:pn,removeReference:dn},vn="@iiif/ADD_MAPPING",mn="@iiif/ADD_MAPPINGS";y(vn)(),y(mn)();const gn="@iiif/SET_META_VALUE",hn="@iiif/SET_META_VALUE_DYNAMIC",yn="@iiif/UNSET_META_VALUE";y(gn)(),y(hn)(),y(yn)();const _n="@iiif/REQUEST_RESOURCE",Pn="@iiif/REQUEST_ERROR",On="@iiif/REQUEST_MISMATCH",wn="@iiif/REQUEST_COMPLETE",Sn="@iiif/REQUEST_OFFLINE_RESOURCE";y(_n)(),y(Pn)(),y(On)(),y(wn)(),y(Sn)();const En="@iiif/BATCH";y(En)();var Cn=Object.defineProperty,In=Object.defineProperties,bn=Object.getOwnPropertyDescriptors,Fe=Object.getOwnPropertySymbols,xn=Object.prototype.hasOwnProperty,$n=Object.prototype.propertyIsEnumerable,Ne=(e,t,n)=>t in e?Cn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Rn=(e,t)=>{for(var n in t||(t={}))xn.call(t,n)&&Ne(e,n,t[n]);if(Fe)for(var n of Fe(t))$n.call(t,n)&&Ne(e,n,t[n]);return e},An=(e,t)=>In(e,bn(t));function Be(e){return typeof e!="string"&&e&&e.bindToVault}function Tn(){const e=h(),t=Q([]),n=Ie(),r=m(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);ke(()=>{const o=An(Rn({},We),{id:r,items:[]});n(W.importEntities({entities:{AnnotationPage:{[o.id]:o}}}))},[r]);const c=P(o=>r?o.iiif.entities.AnnotationPage[r]:null,[r]),i=w((o,s)=>{if(r){if(Be(o)){const f=o;f.__vault||f.bindToVault(e),o=typeof f.source=="string"?f.source:f.source.id,t.current[o]=f}else typeof o!="string"&&(o=o.id);const l=e.get({id:r,type:"AnnotationPage"}),p=e.get({id:o,type:"Annotation"});l&&p&&(l.items.find(f=>f.id===p.id)||n(W.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"},index:s})))}},[r]),a=w(o=>{r&&(Be(o)?o=typeof o.source=="string"?o.source:o.source.id:typeof o!="string"&&(o=o.id),t.current[o]&&t.current[o].beforeRemove(),e.get({id:r,type:"AnnotationPage"})&&n(W.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"}})))},[r]);return[c,{addAnnotation:i,removeAnnotation:a}]}var Mn=Object.defineProperty,Vn=Object.defineProperties,Ln=Object.getOwnPropertyDescriptors,Ue=Object.getOwnPropertySymbols,jn=Object.prototype.hasOwnProperty,Dn=Object.prototype.propertyIsEnumerable,He=(e,t,n)=>t in e?Mn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Fn=(e,t)=>{for(var n in t||(t={}))jn.call(t,n)&&He(e,n,t[n]);if(Ue)for(var n of Ue(t))Dn.call(t,n)&&He(e,n,t[n]);return e},Nn=(e,t)=>Vn(e,Ln(t));function Bn(e){const t=L(),n=R(),r=h(),[c,i]=De(),{enabledPageIds:a}=Ce((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id),{all:!1}),o=Ae(a,"AnnotationPage"),s=(e==null?void 0:e.strategies)||["images","media","complex-timeline"],[l,p]=Re(e,[i]),f=m(()=>{if(!n||l.types.length===0)return Y;if(l.types.length!==1)return s.indexOf("complex-timeline")===-1?E("Complex timeline not supported"):E("ComplexTimelineStrategy not yet supported");const d=l.types[0];return d==="image"?s.indexOf("images")===-1?E("Image not supported"):he(n,l,c):d==="audio"?s.indexOf("media")===-1?E("Media not supported"):E("Audio strategy not yet supported"):d==="video"?s.indexOf("media")===-1?E("Media not supported"):E("Video strategy not yet supported"):Y},[n,l,r,p.makeChoice]);return m(()=>f.type==="unknown"?[f,ge]:[Nn(Fn({},f),{annotations:{pages:o}}),p],[f,o])}export{Ke as AnnotationContext,ne as CanvasContext,Ze as CollectionContext,lt as ContextBridge,le as ImageServiceLoaderContext,re as ManifestContext,et as RangeContext,T as ReactVaultContext,x as ResourceProvider,D as ResourceReactContext,at as SimpleViewerProvider,V as SimpleViewerReactContext,oe as VaultProvider,M as VisibleCanvasReactContext,ge as emptyActions,I as expandTarget,Pe as flattenAnnotationPageIds,he as getImageStrategy,me as getPaintables,B as parseSelector,ve as parseSpecificResource,Y as unknownResponse,E as unsupportedStrategy,Et as useAnnotation,Ce as useAnnotationPageManager,Mt as useAnnotationsAtTime,R as useCanvas,Vt as useCanvasClock,Lt as useCollection,ct as useContextBridge,Ie as useDispatch,jt as useEventListener,Dt as useExistingVault,Qt as useExternalCollection,se as useExternalManifest,$e as useImageService,N as useImageServiceLoader,zt as useImageTile,De as useLoadImageService,L as useManifest,Re as usePaintables,U as usePaintingAnnotations,Yt as useRange,Bn as useRenderingStrategy,b as useResourceContext,Wt as useResourceEvents,Ae as useResources,Gt as useSearchService,st as useSimpleViewer,Xt as useStyleHelper,qt as useStyles,Jt as useThumbnail,h as useVault,Te as useVaultEffect,P as useVaultSelector,Tn as useVirtualAnnotationPage,ce as useVisibleCanvases};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(y,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("react"),require("@iiif/vault")):typeof define=="function"&&define.amd?define(["exports","react","@iiif/vault"],m):(y=typeof globalThis<"u"?globalThis:y||self,m(y.ReactIIIFVault={},y.React,y.IIIFVault))})(this,function(y,m,fe){"use strict";function mn(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var O=mn(m),gn=Object.defineProperty,Re=Object.getOwnPropertySymbols,yn=Object.prototype.hasOwnProperty,wn=Object.prototype.propertyIsEnumerable,qe=(t,e,r)=>e in t?gn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,We=(t,e)=>{for(var r in e||(e={}))yn.call(e,r)&&qe(t,r,e[r]);if(Re)for(var r of Re(e))wn.call(e,r)&&qe(t,r,e[r]);return t};const bn={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},he=O.default.createContext(bn),Q=()=>m.useContext(he),z=({value:t,children:e})=>{const r=Q(),n=m.useMemo(()=>We(We({},r),t),[t,r]);return O.default.createElement(he.Provider,{value:n},e)},Sn=({annotation:t,children:e})=>O.default.createElement(z,{value:{annotation:t}},e),De=({canvas:t,children:e})=>O.default.createElement(z,{value:{canvas:t}},e),xn=({collection:t,children:e})=>O.default.createElement(z,{value:{collection:t}},e),Ve=({manifest:t,children:e})=>O.default.createElement(z,{value:{manifest:t}},e),On=({range:t,children:e})=>O.default.createElement(z,{value:{range:t}},e),re=O.default.createContext({vault:null,setVaultInstance:t=>{}}),Qe=({vault:t,vaultOptions:e,useGlobal:r,resources:n,children:o})=>{const[i,a]=m.useState(()=>t||(r?fe.globalVault(e):e?new fe.Vault(e):new fe.Vault));return O.default.createElement(re.Provider,{value:{vault:i,setVaultInstance:a}},O.default.createElement(z,{value:n||{}},o))};function T(){return T=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},T.apply(this,arguments)}function ye(t,e){if(t==null)return{};var r={},n=Object.keys(t),o,i;for(i=0;i<n.length;i++)o=n[i],!(e.indexOf(o)>=0)&&(r[o]=t[o]);return r}var we="loading",be="error",ze="success",Cn=0,An=function(){return Cn++},Pn={},de=typeof window>"u",k=function(){},In=function(e){return e},Se=console||{error:k,warn:k,log:k};function $n(){var t=O.default.useRef(null);return t.current===null&&(t.current=An()),t.current}function _n(t){var e=O.default.useRef();return e.current=t,O.default.useCallback(function(){return e.current},[])}function xe(t,e){return typeof t=="function"?t(e):t}function En(t,e){return Be(e)?Object.assign.apply(Object,[{}].concat(Object.keys(e).sort().map(function(r){var n;return n={},n[r]=e[r],n}))):e}function jn(t){return JSON.stringify(t,En)}function Be(t){return t&&typeof t=="object"&&!Array.isArray(t)}function He(t,e){return t===e?!0:typeof t!=typeof e?!1:typeof t=="object"?!Object.keys(e).some(function(r){return!He(t[r],e[r])}):!1}function Oe(){return typeof document>"u"||document.visibilityState===void 0||document.visibilityState==="visible"||document.visibilityState==="prerender"}function Tn(){return navigator.onLine===void 0||navigator.onLine}function Ue(t){if(Be(t[0]))if(t[0].hasOwnProperty("queryKey")&&t[0].hasOwnProperty("queryFn")){var e=t[0],r=e.queryKey,n=e.variables,o=n===void 0?[]:n,i=e.queryFn,a=e.config,s=a===void 0?{}:a;return[r,o,i,s]}else throw new Error("queryKey and queryFn keys are required.");if(typeof t[2]=="function"){var u=t[0],l=t[1],f=l===void 0?[]:l,p=t[2],d=t[3],v=d===void 0?{}:d;return[u,f,p,v]}var c=t[0],g=t[1],x=t[2],S=x===void 0?{}:x;return[c,[],g,S]}function Mn(t){var e=O.default.useRef(!1);return O.default[de?"useEffect":"useLayoutEffect"](function(){return e.current=!0,function(){return e.current=!1}},[]),O.default.useCallback(function(){return e.current?t.apply(void 0,arguments):void 0},[t])}function Fn(t){if((t.config.suspense||t.config.useErrorBoundary)&&t.status===be)throw setTimeout(function(){t.query.state.status="loading"}),t.error;if(t.config.suspense&&t.status===we)throw t.query.wasSuspended=!0,t.refetch()}function Ce(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var r,n,o;if(Array.isArray(t)){if(r=t.length,r!=e.length)return!1;for(n=r;n--!==0;)if(!Ce(t[n],e[n]))return!1;return!0}if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===e.valueOf();if(o=Object.keys(t),r=o.length,r!==Object.keys(e).length)return!1;for(n=r;n--!==0;)if(!Object.prototype.hasOwnProperty.call(e,o[n]))return!1;for(n=r;n--!==0;){var i=o[n];if(!Ce(t[i],e[i]))return!1}return!0}return t!==t&&e!==e}var Ln=O.default.createContext(),kn={retry:3,retryDelay:function(e){return Math.min(1e3*Math.pow(2,e),3e4)},staleTime:0,cacheTime:5*60*1e3,refetchAllOnWindowFocus:!0,refetchInterval:!1,suspense:!1,queryKeySerializerFn:Ne,queryFnParamsFilter:In,throwOnError:!1,useErrorBoundary:void 0,onMutate:k,onSuccess:k,onError:k,onSettled:k,refetchOnMount:!0,isDataEqual:Ce},ne={current:kn};function Rn(){return O.default.useContext(Ln)||ne.current}function Ne(t){if(!t)return[];if(typeof t=="function")try{return Ne(t())}catch{return[]}typeof t=="string"&&(t=[t]);var e=jn(t);return t=JSON.parse(e),[e,t]}function N(t,e,r){return r?e?e(t):t:((!t||!t.then)&&(t=Promise.resolve(t)),e?t.then(e):t)}function ie(t,e){try{var r=t()}catch(n){return e(n)}return r&&r.then?r.then(void 0,e):r}function G(t){return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];try{return Promise.resolve(t.apply(this,e))}catch(n){return Promise.reject(n)}}}function Ge(t,e){var r=t();return r&&r.then?r.then(e):e(r)}var Ke=Vn(),qn=O.default.createContext(Ke),Wn=[Ke];function Dn(){return O.default.useContext(qn)}var Ye={},Je={},Ze={},Xe={},et={},tt={},rt={},nt={};function Vn(){var t=[],e={queries:{},isFetching:0},r=function(){e.isFetching=Object.values(e.queries).reduce(function(a,s){return s.state.isFetching?a+1:a},0),t.forEach(function(a){return a(e)})};e.subscribe=function(i){return t.push(i),function(){t.splice(t.indexOf(i),1)}},e.clear=function(){Object.values(e.queries).forEach(function(i){return i.clear()}),e.queries={},r()};var n=function(a,s){var u=s===void 0?{}:s,l=u.exact;if(typeof a!="function"){var f=ne.current.queryKeySerializerFn(a),p=f[0],d=f[1];a=function(c){return l?c.queryHash===p:He(c.queryKey,d)}}return Object.values(e.queries).filter(a)};e.getQueries=n,e.getQuery=function(i){return n(i,{exact:!0})[0]},e.getQueryData=function(i){var a;return(a=e.getQuery(i))==null?void 0:a.state.data},e.removeQueries=function(i,a){var s=a===void 0?{}:a,u=s.exact,l=n(i,{exact:u});l.forEach(function(f){clearTimeout(f.staleTimeout),delete e.queries[f.queryHash]}),l.length&&r()},e.cancelQueries=function(i,a){var s=a===void 0?{}:a,u=s.exact,l=n(i,{exact:u});l.forEach(function(f){f.cancel()}),l.length&&r()},e.refetchQueries=G(function(i,a){var s=a===void 0?{}:a,u=s.exact,l=s.throwOnError,f=s.force,p=i===!0?Object.values(e.queries):n(i,{exact:u});return ie(function(){return N(Promise.all(p.map(function(d){return d.fetch({force:f})})))},function(d){if(l)throw d})}),e._buildQuery=function(i,a,s,u){var l=u.queryKeySerializerFn(i),f=l[0],p=l[1],d=e.queries[f];return d?(Object.assign(d,{queryVariables:a,queryFn:s}),d.config=T({},d.config,u)):(d=o({cache:e,queryKey:p,queryHash:f,queryVariables:a,queryFn:s,config:u}),!de&&d.state.data&&(d.scheduleStaleTimeout(),d.heal(),d.scheduleGarbageCollection()),d.queryHash&&(de||(e.queries[f]=d,setTimeout(function(){r()})))),d},e.prefetchQuery=G(function(){for(var i=!1,a=arguments.length,s=new Array(a),u=0;u<a;u++)s[u]=arguments[u];var l=Ue(s),f=l[0],p=l[1],d=l[2],v=l[3],c=v.force,g=ye(v,["force"]);g=T({},ne.current,g);var x=e._buildQuery(f,p,d,g);return Ge(function(){if(x.state.isStale||c)return ie(function(){return N(x.fetch({force:c}),function(S){return x.wasPrefetched=!0,i=!0,S})},function(S){if(g.throwOnError)throw S})},function(S){return i?S:x.state.data})}),e.setQueryData=function(i,a,s){var u=s===void 0?{}:s,l=u.exact,f=ye(u,["exact"]),p=n(i,{exact:l});!p.length&&typeof i!="function"&&(p=[e._buildQuery(i,void 0,function(){return Promise.resolve()},T({},ne.current,f))]),p.forEach(function(d){return d.setData(a)})};function o(i){var a=i.cache,s=i.config.queryReducer||Qn,u=typeof i.queryHash>"u",l=typeof i.config.initialData=="function"?i.config.initialData():i.config.initialData,f=typeof l<"u",p=u?!0:!f,d=i.config.manual,v=u||d||f?ze:we,c=T({},i,{instances:[],state:s(void 0,{type:Ye,initialStatus:v,initialData:l,hasInitialData:f,isStale:p,manual:d})}),g=function(h){c.state=s(c.state,h),c.instances.forEach(function(w){return w.onStateUpdate(c.state)}),r()};c.scheduleStaleTimeout=function(){c.config.staleTime!==1/0&&(c.staleTimeout=setTimeout(function(){a.getQuery(c.queryKey)&&g({type:Ze})},c.config.staleTime))},c.scheduleGarbageCollection=function(){c.config.cacheTime!==1/0&&(g({type:Xe}),c.cacheTimeout=setTimeout(function(){e.removeQueries(function(S){return S.state.markedForGarbageCollection&&S.queryHash===c.queryHash})},typeof c.state.data>"u"&&c.state.status!=="error"?0:c.config.cacheTime))},c.heal=function(){clearTimeout(c.cacheTimeout),c.cancelled=null},c.cancel=function(){c.cancelled=Pn,c.cancelPromises&&c.cancelPromises(),delete c.promise,r()},c.updateInstance=function(S){var h=c.instances.find(function(w){return w.id===S.id});h?Object.assign(h,S):(h=T({onStateUpdate:k},S),c.instances.push(S))},c.subscribe=function(S){return c.heal(),function(){c.instances=c.instances.filter(function(h){return h.id!==S}),c.instances.length||(c.cancel(),c.scheduleGarbageCollection())}};var x=G(function(S){for(var h=arguments.length,w=new Array(h>1?h-1:0),b=1;b<h;b++)w[b-1]=arguments[b];return ie(function(){var A=S.apply(void 0,c.config.queryFnParamsFilter(w));return c.cancelPromises=function(){return A.cancel==null?void 0:A.cancel()},N(A,function(P){if(delete c.shouldContinueRetryOnFocus,delete c.cancelPromises,c.cancelled)throw c.cancelled;return P})},function(A){var P=!1;if(delete c.cancelPromises,c.cancelled)throw c.cancelled;return g({type:Je}),Ge(function(){if(c.config.retry===!0||c.state.failureCount<=c.config.retry||typeof c.config.retry=="function"&&c.config.retry(c.state.failureCount,A)){if(!Oe())return c.shouldContinueRetryOnFocus=!0,P=!0,new Promise(k);delete c.shouldContinueRetryOnFocus;var C=xe(c.config.retryDelay,c.state.failureCount);return P=!0,N(new Promise(function(I,F){setTimeout(G(function(){return c.cancelled?F(c.cancelled):ie(function(){return N(x.apply(void 0,[S].concat(w)),function(ee){if(c.cancelled)return F(c.cancelled);I(ee)})},function(ee){if(c.cancelled)return F(c.cancelled);F(ee)})}),C)}))}},function(C){if(P)return C;throw A})})});return c.fetch=G(function(S){var h=S===void 0?{}:S,w=h.force,b=h.__queryFn,A=b===void 0?c.queryFn:b;if(!(!c.queryHash||!c.state.isStale&&!w))return c.promise||(c.promise=G(function(){c.cancelled=null;var P=[].concat(c.instances);return c.wasSuspended&&P.unshift(c.suspenseInstance),ie(function(){return g({type:et}),N(x.apply(void 0,[A].concat(c.queryKey,c.queryVariables)),function(C){return c.setData(function(I){return c.config.isDataEqual(I,C)?I:C}),P.forEach(function(I){return I.onSuccess&&I.onSuccess(c.state.data)}),P.forEach(function(I){return I.onSettled&&I.onSettled(c.state.data,null)}),delete c.promise,C})},function(C){if(g({type:rt,cancelled:C===c.cancelled,error:C}),delete c.promise,C!==c.cancelled)throw P.forEach(function(I){return I.onError&&I.onError(C)}),P.forEach(function(I){return I.onSettled&&I.onSettled(void 0,C)}),C})})()),c.promise}),c.setState=function(S){return g({type:nt,updater:S})},c.setData=function(S){g({type:tt,updater:S}),clearTimeout(c.staleTimeout),c.scheduleStaleTimeout()},c.clear=function(){clearTimeout(c.staleTimeout),clearTimeout(c.cacheTimeout),c.cancel()},c}return e}function Qn(t,e){switch(e.type){case Ye:return{status:e.initialStatus,error:null,isFetching:e.hasInitialData||e.manual?!1:e.initialStatus==="loading",canFetchMore:!1,failureCount:0,isStale:e.isStale,markedForGarbageCollection:!1,data:e.initialData,updatedAt:e.hasInitialData?Date.now():0};case Je:return T({},t,{failureCount:t.failureCount+1});case Ze:return T({},t,{isStale:!0});case Xe:return T({},t,{markedForGarbageCollection:!0});case et:return T({},t,{status:t.status===be?we:t.status,isFetching:!0,failureCount:0});case tt:return T({},t,{status:ze,data:xe(e.updater,t.data),error:null,isStale:!1,isFetching:!1,canFetchMore:e.canFetchMore,updatedAt:Date.now(),failureCount:0});case rt:return T({},t,{isFetching:!1,isStale:!0},!e.cancelled&&{status:be,error:e.error});case nt:return xe(e.updater,t);default:throw new Error}}var it="visibilitychange",ot="focus",zn=function(){var e=ne.current.refetchAllOnWindowFocus;Oe()&&Tn()&&Wn.forEach(function(r){return r.refetchQueries(function(n){return!n.instances.length||n.config.manual===!0?!1:n.shouldContinueRetryOnFocus?(delete n.promise,!0):typeof n.config.refetchOnWindowFocus>"u"?e:n.config.refetchOnWindowFocus}).catch(Se.error)})},Ae;function Bn(t){Ae&&Ae(),Ae=t(zn)}Bn(function(t){var e;if(!de&&((e=window)==null?void 0:e.addEventListener))return window.addEventListener(it,t,!1),window.addEventListener(ot,t,!1),function(){window.removeEventListener(it,t),window.removeEventListener(ot,t)}});function Hn(t,e,r){return r?e?e(t):t:((!t||!t.then)&&(t=Promise.resolve(t)),e?t.then(e):t)}function Un(t,e){try{var r=t()}catch(n){return e(n)}return r&&r.then?r.then(void 0,e):r}function Nn(t){return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];try{return Promise.resolve(t.apply(this,e))}catch(n){return Promise.reject(n)}}}function Gn(t,e,r,n){n===void 0&&(n={});var o=$n();n=T({},Rn(),n);var i=Dn(),a=O.default.useRef(),s=i._buildQuery(t,e,r,n),u=a.current&&typeof a.current.queryHash>"u"&&typeof s.queryHash>"u";u||(a.current=s);var l=a.current,f=O.default.useState(),p=f[1],d=Mn(p),v=_n(n),c=O.default.useCallback(Nn(function(g){var x=g===void 0?{}:g,S=x.throwOnError,h=ye(x,["throwOnError"]);return Un(function(){return Hn(l.fetch(h))},function(w){if(S)throw w})}),[l]);return l.suspenseInstance={onSuccess:function(x){return v().onSuccess(x)},onError:function(x){return v().onError(x)},onSettled:function(x,S){return v().onSettled(x,S)}},O.default.useEffect(function(){return l.updateInstance({id:o,onStateUpdate:function(){return d({})},onSuccess:function(x){return v().onSuccess(x)},onError:function(x){return v().onError(x)},onSettled:function(x,S){return v().onSettled(x,S)}}),l.subscribe(o)},[v,o,l,d]),O.default.useEffect(function(){!v().manual&&!l.wasPrefetched&&!l.wasSuspended&&l.state.isStale&&(v().refetchOnMount||l.instances.length===1)&&c().catch(Se.error),l.wasPrefetched=!1,l.wasSuspended=!1},[v,l,c]),O.default.useEffect(function(){var g=a.current;if(n.refetchInterval&&(!g.currentRefetchInterval||n.refetchInterval<g.currentRefetchInterval))return g.currentRefetchInterval=n.refetchInterval,clearInterval(g.refetchIntervalId),g.refetchIntervalId=setInterval(function(){(Oe()||n.refetchIntervalInBackground)&&c().catch(Se.error)},n.refetchInterval),function(){clearInterval(g.refetchIntervalId),delete g.refetchIntervalId,delete g.currentRefetchInterval}},[n.refetchInterval,n.refetchIntervalInBackground,c]),T({},l.state,{config:n,query:l,refetch:c})}function Pe(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];var n=Gn.apply(void 0,Ue(e));return Fn(n),n}const E=()=>{const{vault:t}=m.useContext(re);if(t===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return t};var Kn=Object.defineProperty,at=Object.getOwnPropertySymbols,Yn=Object.prototype.hasOwnProperty,Jn=Object.prototype.propertyIsEnumerable,st=(t,e,r)=>e in t?Kn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Zn=(t,e)=>{for(var r in e||(e={}))Yn.call(e,r)&&st(t,r,e[r]);if(at)for(var r of at(e))Jn.call(e,r)&&st(t,r,e[r]);return t},Xn=(t,e,r)=>new Promise((n,o)=>{var i=u=>{try{s(r.next(u))}catch(l){o(l)}},a=u=>{try{s(r.throw(u))}catch(l){o(l)}},s=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);s((r=r.apply(t,e)).next())});const ct=(t,e={})=>{const r=E(),[n,o]=m.useState(t),i=m.useMemo(()=>r.get(t)||void 0,[t,r]),{data:a,error:s}=Pe(["manifest",t],()=>Xn(void 0,null,function*(){const u=i||(yield r.load(t));return u&&n!==u.id&&o(u.id),u}),Zn({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,retry:!1,initialData:i},e));return{isLoaded:!!a,id:n,error:s,manifest:a}};function M(t,e=[]){const r=E(),[n,o]=m.useState(()=>t(r.getState(),r));return m.useEffect(()=>r.subscribe(i=>t(i,r),i=>{o(i)},!0),e),n}const oe=O.default.createContext([]);function ut(){const t=m.useContext(oe);return M(e=>t.map(r=>e.iiif.entities.Canvas[r]).filter(Boolean),[t])}const pe=()=>{},ae=m.createContext({setCurrentCanvasId:pe,setCurrentCanvasIndex:pe,nextCanvas:pe,previousCanvas:pe,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),ei=t=>{const e=ct(t.manifest),[r,n]=m.useState(""),[o,i]=m.useState([]),a=(typeof t.pagingEnabled>"u"||t.pagingEnabled)&&e.manifest&&e.manifest.behavior&&e.manifest.behavior.includes("paged");m.useEffect(()=>{var c,g;e.manifest&&(n((c=e.manifest.items[0])==null?void 0:c.id),i([(g=e.manifest.items[0])==null?void 0:g.id]))},[e.manifest,t.manifest]);const s=m.useMemo(()=>{var c;return((c=e.manifest)==null?void 0:c.items.map(g=>g.id))||[]},[e.manifest,t.manifest]),u=m.useMemo(()=>s.indexOf(r),[s,r]),l=m.useCallback(()=>{if(s.length&&r){if(u===-1||(s[u+2]?u+2===s.length:u===s.length))return;const c=a&&u!==0?s[u+2]:s[u+1],g=a?u!==0?s[u+3]:s[u+2]:null;c&&(n(c),i(g?[c,g]:[c]))}},[a,s,r,u]),f=m.useCallback(()=>{if(s.length&&r){if(u===0||u===-1)return;const c=a&&u!==1?s[u-2]:s[u-1],g=a&&u!==1?s[u-1]:null;c&&(n(c),i(g?[c,g]:[c]))}},[a,s,r,u]),p=m.useCallback(c=>{const g=a&&c%2===1?c-1:c,x=s[g],S=a&&g!==0?s[g+1]:null;x&&(n(x),i(h=>{const w=S?[x,S]:[x];if(h.length===h.length){for(let b=0;b<h.length;b++)if(h[b]!==w[b])return w;return h}return w}))},[a,s]),d=m.useCallback(c=>{const g=s.indexOf(c);g!==-1&&p(g)},[s,p]),v=m.useMemo(()=>({setCurrentCanvasId:d,nextCanvas:l,previousCanvas:f,currentCanvasIndex:u,totalCanvases:s.length,setCurrentCanvasIndex:p,pagingView:!0}),[l,f,u,s,p,d]);return!e.isLoaded||!e.manifest?O.default.createElement("div",null,"Loading..."):O.default.createElement(ae.Provider,{value:v},O.default.createElement(oe.Provider,{value:o},O.default.createElement(Ve,{manifest:e.manifest.id},O.default.createElement(De,{canvas:r},t.children))))};function ti(){return m.useContext(ae)}function ri(){return{VaultContext:m.useContext(re),ResourceContext:m.useContext(he),SimpleViewerReactContext:m.useContext(ae),VisibleCanvasReactContext:m.useContext(oe)}}const ni=t=>O.default.createElement(Qe,{vault:t.bridge.VaultContext.vault||void 0,resources:t.bridge.ResourceContext},O.default.createElement(oe.Provider,{value:t.bridge.VisibleCanvasReactContext},O.default.createElement(ae.Provider,{value:t.bridge.SimpleViewerReactContext},t.children)));function B(t){return t.endsWith("info.json")?t:t.endsWith("/")?`${t}info.json`:`${t}/info.json`}const ii="http://library.stanford.edu/iiif/image-api/compliance.html#level0",lt="http://library.stanford.edu/iiif/image-api/compliance.html#level1",ft="http://library.stanford.edu/iiif/image-api/compliance.html#level2",oi="http://library.stanford.edu/iiif/image-api/conformance.html#level0",ht="http://library.stanford.edu/iiif/image-api/conformance.html#level1",dt="http://library.stanford.edu/iiif/image-api/conformance.html#level2",ai="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",pt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",vt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",si="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",mt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",gt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",ci="http://iiif.io/api/image/1/level0.json",ui="http://iiif.io/api/image/1/profiles/level0.json",yt="http://iiif.io/api/image/1/level1.json",wt="http://iiif.io/api/image/1/profiles/level1.json",bt="http://iiif.io/api/image/1/level2.json",St="http://iiif.io/api/image/1/profiles/level2.json",li="http://iiif.io/api/image/2/level0.json",fi="http://iiif.io/api/image/2/profiles/level0.json",xt="http://iiif.io/api/image/2/level1.json",Ot="http://iiif.io/api/image/2/profiles/level1.json",Ct="http://iiif.io/api/image/2/level2.json",At="http://iiif.io/api/image/2/profiles/level2.json",hi="level0",Pt="level1",It="level2",di="http://iiif.io/api/image/2/level0",$t="http://iiif.io/api/image/2/level1",_t="http://iiif.io/api/image/2/level2",Et=[_t,ft,dt,vt,gt,bt,St,Ct,At,It],jt=[...Et,$t,lt,ht,pt,mt,yt,wt,xt,Ot,Pt],pi=[di,$t,_t,ii,lt,ft,oi,ht,dt,ai,pt,vt,si,mt,gt,ci,ui,yt,wt,bt,St,li,fi,xt,Ot,Ct,At,hi,Pt,It],vi={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},mi={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},gi={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function yi(t){return Et.indexOf(t)!==-1?gi:jt.indexOf(t)!==-1?mi:vi}function wi(t){const e=t?Array.isArray(t.profile)?t.profile:[t.profile]:[],r={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let n of e)if(typeof n=="string"&&(n=yi(n)),!!n){if(n.formats)for(const o of n.formats)r.extraFormats.indexOf(o)===-1&&r.extraFormats.push(o);if(n.qualities)for(const o of n.qualities)r.extraQualities.indexOf(o)===-1&&r.extraQualities.push(o);if(n.supports)for(const o of n.supports)r.extraFeatures.indexOf(o)===-1&&r.extraFeatures.push(o);if(n.maxHeight&&(r.maxHeight=n.maxHeight),n.maxWidth&&(r.maxWidth=n.maxWidth),n.maxArea&&(r.maxArea=n.maxArea),n.extraFormats)for(const o of n.extraFormats)r.extraFormats.indexOf(o)===-1&&r.extraFormats.push(o);if(n.extraQualities)for(const o of n.extraQualities)r.extraQualities.indexOf(o)===-1&&r.extraQualities.push(o);if(n.extraFeatures)for(const o of n.extraFeatures)r.extraFeatures.indexOf(o)===-1&&r.extraFeatures.push(o);n.maxHeight&&(r.maxHeight=n.maxHeight),n.maxWidth&&(r.maxWidth=n.maxWidth),n.maxArea&&(r.maxArea=n.maxArea)}if(t.extraFormats)for(const n of t.extraFormats)r.extraFormats.indexOf(n)===-1&&r.extraFormats.push(n);if(t.extraFeatures)for(const n of t.extraFeatures)r.extraFeatures.indexOf(n)===-1&&r.extraFeatures.push(n);if(t.extraQualities)for(const n of t.extraQualities)r.extraQualities.indexOf(n)===-1&&r.extraQualities.push(n);return r}function bi(t){try{if(t==="full")return{full:!0};if(t==="square")return{square:!0};const e=t.startsWith("pct:"),r=t.substr(e?4:0).split(",").map(n=>parseFloat(n));return{x:r[0],y:r[1],w:r[2],h:r[3],percent:e}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+t)}}function Si(t){const e={upscaled:!1,max:!1,confined:!1};if(t[0]==="^"&&(e.upscaled=!0,t=t.slice(1)),t==="max"||t==="full")return e.max=!0,e.serialiseAsFull=t==="full",e;if(t[0]==="!"&&(e.confined=!0,t=t.slice(1)),t[0]==="p")return e.percentScale=parseFloat(t.slice(4)),e;const r=t.split(",").map(n=>n.trim());return r.length&&(r[0]!==""&&(e.width=parseInt(r[0],10)),r[1]!==""&&(e.height=parseInt(r[1],10))),e}function xi(t){const e={angle:0};if(t[0]==="!"&&(e.mirror=!0,t=t.substr(1)),e.angle=parseFloat(t)%360,Number.isNaN(e.angle))throw new Error(`Invalid rotation ${t}`);return e}function Oi(t,e=""){const r=t.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!r)throw new Error(`Invalid or unknown input ${t}`);const n=r[2],o=r[3];let i=r[4];if(i[0]==="/"&&(i=i.substr(1)),e.length>0){if(e[0]==="/"&&(e=e.substr(1)),e!==i.substr(0,e.length))throw new Error(`Path does not start with prefix (path: ${i}, prefix: ${e})`);i=i.substr(e.length)}return{scheme:n,server:o,path:i,prefix:e}}function Ci(t,e=""){const{path:r,scheme:n,server:o,prefix:i}=Oi(t,e),a=r.split("/").reverse(),[s,u,l,f,...p]=a,d=p.reverse().filter(Boolean).join("/");if(a.length===1||s==="")return{type:"base",scheme:n,server:o,prefix:i,identifier:d};if(s==="info.json"){const[,...c]=a;return{type:"info",scheme:n,server:o,prefix:i,identifier:c.reverse().filter(Boolean).join("/")}}const v=s.split(".");return{type:"image",scheme:n,server:o,prefix:i,identifier:d,originalPath:r,region:bi(f),size:Si(l),rotation:xi(u),quality:v[0],format:v[1]}}function Ai(t){const e=Ci(B(t.id));if(e.type!=="info")throw new Error("Invalid service URL");const r=wi(t);return{identifier:e.identifier,originalPath:"",server:e.server,prefix:e.prefix,scheme:e.scheme,type:"image",quality:r.extraQualities.indexOf("default")===-1?r.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}}function Pi(t,e,r){const n=r.length,o=[];for(let i=0;i<n;i++){const a=r[i].width;o.push(t/a)}return o}function Ii(t,e,r){const n=r.length,o=[];for(let i=0;i<n;i++){const a=r[i];o.push({width:Math.floor(t/a),height:Math.floor(e/a)})}return o}function $(t){if(t["@id"])return t["@id"];if(t.id)return t.id}function Ie(t){if(!t||!t.profile||!$(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const r of e)if(typeof r=="string"&&pi.indexOf(r)!==-1)return!0;return!1}function $i(t){if(!Ie(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const r of e)if(typeof r=="string"){if(jt.indexOf(r)!==-1)return!0}else{const n=[...r.supports||[],...r.extraFeatures||[]];if(n.indexOf("regionByPx")!==-1&&(n.indexOf("sizeByW")!==-1||n.indexOf("sizeByWh")!==-1))return!0}return!1}function _i(t){if(!$i(t))return[];const e=[],r=Array.isArray(t.profile)?t.profile:[t.profile],n=r.length;for(let o=0;o<n;o++){const i=r[o];if(typeof i!="string"&&(i.maxHeight||i.maxWidth))return[{id:$(t),type:"variable",minWidth:0,minHeight:0,maxHeight:i.maxHeight||i.maxWidth,maxWidth:i.maxWidth||i.maxHeight}]}if(t.tiles){const o=t.tiles.length;for(let i=0;i<o;i++){const a=t.tiles[i];(a.height||a.width)&&e.push({id:$(t),type:"variable",minHeight:0,minWidth:0,maxHeight:a.height||a.width,maxWidth:a.width})}}return e}function Tt(t){const e=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,r=t.match(e);if(r){const n=r[1],o=parseInt(r[4],10),i=parseInt(r[5],10),a=r[7];if((n==="max"||n==="full")&&o&&i&&a)return{type:"fixed",id:t,height:i,width:o}}return{type:"unknown",id:t}}function Ei(t){if(t["@type"])return t["@type"];if(t.type)return t.type}function ji(t){if(typeof t=="string")return Tt(t);const e=Ei(t);if(e!=="Image"&&e!=="sc:Image")return null;const r=t,n=$(r);return n?n&&r.width&&r.height?{id:n,type:"fixed",width:r.width,height:r.height,unsafe:!0}:Tt(n):null}function Ti(t){return Ie(t)?(t&&t.sizes?t.sizes:[]).map(e=>({id:$(t),type:"fixed-service",height:e.height,width:e.width})):[]}function Mt(t){const e=[],r=t.length;for(let n=0;n<r;n++){const o=Ti(t[n]);o.length&&e.push(...o);const i=_i(t[n]);i.length&&e.push(...i)}return e}function se(t){const e=t.service?Array.isArray(t.service)?t.service:[t.service]:[],r=e.length,n=[];for(let o=0;o<r;o++)Ie(e[o])&&n.push(e[o]);return n}function Mi(t,e=!0,r){const n=[],o=ji(t);if(o===null)return n;const i=t;if(n.push(o),e&&i.width&&i.height){const a=[],s=se(i);for(const u of s){const l={id:$(u),width:i.width,height:i.height};if(r.canLoadSync(l)){const f=r.loadServiceSync(l);f&&(f.height||(f.height=i.height),f.width||(f.width=i.width),a.push(...Mt([f])))}}if(a.length)return n.push(...a),n}return i.service&&n.push(...Mt(i.service)),n}function Fi({x:t=0,y:e=0,w:r,h:n,full:o,square:i,percent:a}){if(o)return"full";if(i)return"square";if(typeof r>"u"||typeof n>"u")throw new Error("RegionParameter: invalid region");const s=`${t},${e},${r},${n}`;return a?`pct:${s}`:s}function Li({max:t,percentScale:e,upscaled:r,confined:n,width:o,height:i,serialiseAsFull:a}){const s=[];return r&&s.push("^"),t?(s.push(a?"full":"max"),s.join("")):(n&&s.push("!"),e&&s.push(`pct:${e}`),o&&s.push(`${o}`),s.push(","),i&&s.push(`${i}`),s.join(""))}function ki(t){return`${t.mirror?"!":""}${(t.angle||0)%360}`}var Ri=Object.defineProperty,qi=Object.defineProperties,Wi=Object.getOwnPropertyDescriptors,Ft=Object.getOwnPropertySymbols,Di=Object.prototype.hasOwnProperty,Vi=Object.prototype.propertyIsEnumerable,Lt=(t,e,r)=>e in t?Ri(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ce=(t,e)=>{for(var r in e||(e={}))Di.call(e,r)&&Lt(t,r,e[r]);if(Ft)for(var r of Ft(e))Vi.call(e,r)&&Lt(t,r,e[r]);return t},ue=(t,e)=>qi(t,Wi(e));function Qi(t,e){const r=t.prefix.startsWith("/")?t.prefix.substr(1):t.prefix,n=`${t.scheme}://${t.server}/${r?`${r}/`:""}${t.identifier}`;if(t.type==="base")return n;if(t.type==="info")return`${n}/info.json`;let{region:o,size:i,rotation:a,format:s,quality:u}=t;if(e){const l=e["@context"]?Array.isArray(e["@context"])?e["@context"]:[e["@context"]]:[],f=l.indexOf("http://iiif.io/api/image/2/context.json")!==-1,p=l.indexOf("http://iiif.io/api/image/3/context.json")!==-1;if((i.width===e.width&&!i.height||i.height===e.height&&!i.width||i.width===e.width&&i.height===e.height)&&(i=ue(ce({},i),{max:!0})),f&&(i.max&&!i.serialiseAsFull&&(i=ue(ce({},i),{serialiseAsFull:!0})),!i.max&&i.width&&i.height&&(i=ue(ce({},i),{height:void 0}))),p&&(i.max&&i.serialiseAsFull&&(i=ue(ce({},i),{serialiseAsFull:!1})),i.width&&!i.height&&e.width&&e.height)){const d=e.height/e.width;i=ue(ce({},i),{height:Math.ceil(i.width*d)})}}return[n,Fi(o),Li(i),ki(a),`${u}.${s}`].filter(Boolean).join("/")}function $e(t,e,r){const n=Ai({id:B($(t)),profile:"level2",type:"ImageService2"});if(n.type!=="image")throw new Error("Invalid service");return n.size.max=!1,n.size.width=e,n.size.height=r,{id:Qi(n),type:"fixed",width:e,height:r||t.height/(t.width||1)*e,unsafe:t.width>e}}function K(t){const e=t.replace(/(https?:\/\/)?(www.)?/i,"");return e.indexOf("/")!==-1?e.split("/")[0]:e}function zi(t,e,r){const n=t.width?t.width:t.maxWidth;return r.height<=t.maxHeight&&r.width<=t.maxWidth&&r.height>=t.minHeight&&r.width>=t.minWidth&&(!e||Math.abs(r.width-n)<Math.abs(e.width-n))}function Bi(t,e){const r=[],n=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},t),o=[],i=[];let a=null;const s=(l,f)=>{if(zi(n,f,l)){if(n.preferFixedSize&&l.unsafe){i.push(l);return}n.returnAllOptions&&f&&i.push(f),a=l}else n.returnAllOptions&&i.push(l)},u=e.length;for(let l=0;l<u;l++){const f=e[l](),p=f.length;for(let d=0;d<p;d++){const v=f[d];if(v.type==="unknown"&&n.atAnyCost&&o.push(v),v.type==="fixed"&&(v.unsafe?o.push(v):s(v,a)),v.type==="fixed-service")if(n.unsafeImageService){const c=$e(v,n.width,n.height);s(c,a)}else{const c=$e(v,v.width,v.height);s(c,a)}if(v.type==="variable"&&v.maxWidth){const c=$e({id:v.id,type:"fixed-service",width:v.maxWidth,height:v.maxWidth},v.maxWidth);s(c,a)}}if(a&&!n.returnAllOptions){if(a.unsafe||n.allowUnsafe)continue;break}}return n.atAnyCost&&i.length===0?{best:a||o[0],fallback:o.slice(1),log:r}:n.returnAllOptions?{best:n.atAnyCost?a||i[0]||o[0]:a||i[0],fallback:[...i,...o],log:r}:{best:a||i[0]||null,fallback:a?i:i.slice(1),log:r}}var Hi=Object.defineProperty,Ui=Object.defineProperties,Ni=Object.getOwnPropertyDescriptors,kt=Object.getOwnPropertySymbols,Gi=Object.prototype.hasOwnProperty,Ki=Object.prototype.propertyIsEnumerable,Rt=(t,e,r)=>e in t?Hi(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Yi=(t,e)=>{for(var r in e||(e={}))Gi.call(e,r)&&Rt(t,r,e[r]);if(kt)for(var r of kt(e))Ki.call(e,r)&&Rt(t,r,e[r]);return t},Ji=(t,e)=>Ui(t,Ni(e));function Zi(t,e,r){const n=t>e?t:e,o=r.length,i=[];for(let a=0;a<o;a++){const s=r[a];let u=s.scaleFactors[0],l=n/u;const f=[u];for(;l>=s.width;)u=u*2,f.push(u),l=l/2;i.push(Ji(Yi({},s),{scaleFactors:f}))}return i}function Xi(t,e){if(t.length!==e.length)return!1;if(t.length===0&&e.length===0)return!0;const r=t.length;let n=!0;for(let i=0;i<r;i++){const a=t[i],s=e[i];if(a.width!==s.width||a.height!==s.height){n=!1;break}}if(n)return!0;let o=0;for(let i=0;i<r;i++)for(let a=0;a<r;a++)if(t[i].width===e[a].width&&t[i].height===e[a].height){o++;break}return o===r}var H=(t,e,r)=>new Promise((n,o)=>{var i=u=>{try{s(r.next(u))}catch(l){o(l)}},a=u=>{try{s(r.throw(u))}catch(l){o(l)}},s=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);s((r=r.apply(t,e)).next())});class qt{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(e){Object.assign(this.config,e)}sample(e,r,n=!0){const o=K($(e)),i=B($(e)),a=this.knownImageServers[o];return this.imageServices[i]=Object.assign(e,{real:!0}),a?this.verify(e):(this.knownImageServers[o]={verifications:0,malformed:!1,root:o,preLoaded:n,sampledId:$(e),verified:!1,server:null,result:{context:e["@context"]||[],sampledProfile:e.profile,resourceServiceRatio:r&&e.height?r.height/e.height:1,sampledSizes:e.sizes||[],sizeRatios:Pi(e.width,e.height,e.sizes||[]),sampledTiles:e.tiles||[]}},!0)}preLoad(e,r=!0){this.knownImageServers[e.root]=e,r&&(this.knownImageServers[e.root].malformed=!1,this.knownImageServers[e.root].verifications=this.config.verificationsRequired)}predict(e,r=!1,n=!1){const o=K($(e)),i=this.knownImageServers[o];if(!i||!i.result||!n&&(i.malformed||i.verifications<this.config.verificationsRequired))return null;const a=B($(e));return this.imageServices[a]||(this.imageServices[a]={"@context":i.result.context,"@id":$(e),id:$(e),protocol:"http://iiif.io/api/image",tiles:Zi(e.width,e.height,i.result.sampledTiles),sizes:Ii(Math.floor(e.width/i.result.resourceServiceRatio),Math.floor(e.height/i.result.resourceServiceRatio),i.result.sizeRatios),profile:i.result.sampledProfile,height:e.height,width:e.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(e,r){return H(this,arguments,function*(n,o,i=!0,a=[]){const s=yield this.getImageCandidates(n,i);return Bi(o,[()=>a,()=>s])})}getImageCandidates(e,r=!0){return H(this,null,function*(){const n=e;if(r&&n.height&&n.width){const o=se(n);for(const i of o){const a={id:$(i),width:i.width?i.width:n.width,height:i.height?i.height:n.height};yield this.loadService(a)}}return Mi(e,r,this)})}verify(e){return H(this,null,function*(){const r=this.predict(e,!1,!0),n=yield this.fetchService($(e));if(!r)return!1;const o=r.height===n.height&&r.width===n.width&&r["@context"]===n["@context"]&&Xi(r.sizes||[],n.sizes||[]);if(o){const i=K($(e));this.knownImageServers[i].verifications+=1,this.knownImageServers[i].verifications>=this.config.verificationsRequired&&(this.knownImageServers[i].verified=!0)}return o})}canLoadSync(e){const r=typeof e=="string"?e:$(e),n=B(r);if(this.imageServices[n])return!0;const o=this.knownImageServers[K(r)];return o&&!o.malformed&&o.verifications>=this.config.verificationsRequired}markAsMalformed(e){return H(this,null,function*(){return this.knownImageServers[K($(e))].malformed=!0,this.loadService(e,!0)})}fetchService(e,r=!1){return H(this,null,function*(){const n=B(e);if(this.imageServices[n]&&(!r||this.imageServices[n].real))return this.imageServices[n];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const o=yield this.fetch(n).then(i=>i.json());return!o.id&&o["@id"]&&(o.id=o["@id"]),o.id!==e&&(o.id=e,o["@id"]&&(o["@id"]=e)),this.imageServices[n]=Object.assign(o,{real:!0}),this.imageServices[n]})}fetch(e,r){return H(this,null,function*(){return fetch(e,r)})}loadService(e,r=!1){return H(this,null,function*(){if(!this.config.disableThrottling){let i=!0;for(;i;)if(this.fetchingCount>=this.config.verificationsRequired)yield new Promise(a=>setTimeout(a,500));else{i=!1;break}}const n=this.knownImageServers[K($(e))];if(n&&!n.malformed&&!r){yield n.result;const i=this.loadServiceSync(e);if(i)return i}this.fetchingCount++;const o=yield this.fetchService($(e),r);return this.fetchingCount--,o.real&&this.sample(o,e),o})}loadServiceSync(e){const r=B($(e));return this.imageServices[r]?this.imageServices[r]:this.predict(e)}}new qt;const Wt=O.default.createContext(new qt);function ve(){return m.useContext(Wt)}const eo=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,to=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function me(t){if(Array.isArray(t))return t.reduce((e,r)=>{const{selector:n,selectors:o}=me(r);return n&&(e.selector||(e.selector=n),e.selectors.push(...o)),e},{selector:null,selectors:[]});if(!t)return{selector:null,selectors:[]};if(typeof t=="string"){const[e,r]=t.split("#");return r?me({type:"FragmentSelector",value:r}):{selector:null,selectors:[]}}if(t.type==="PointSelector"&&(t.t||t.t===0)){const e={type:"TemporalSelector",temporal:{startTime:t.t}};return{selector:e,selectors:[e]}}if(t.type==="FragmentSelector"){const e=eo.exec(t.value);if(e){const n={type:"BoxSelector",spatial:{unit:e[2]==="percent:"?"percent":"pixel",x:parseFloat(e[3]),y:parseFloat(e[4]),width:parseFloat(e[5]),height:parseFloat(e[6])}};return{selector:n,selectors:[n]}}const r=t.value.match(to);if(r){const n={type:"TemporalSelector",temporal:{startTime:r[4]?parseFloat(r[4]):0,endTime:r[7]?parseFloat(r[7]):void 0}};return{selector:n,selectors:[n]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}var ro=Object.defineProperty,no=Object.defineProperties,io=Object.getOwnPropertyDescriptors,Dt=Object.getOwnPropertySymbols,oo=Object.prototype.hasOwnProperty,ao=Object.prototype.propertyIsEnumerable,Vt=(t,e,r)=>e in t?ro(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Qt=(t,e)=>{for(var r in e||(e={}))oo.call(e,r)&&Vt(t,r,e[r]);if(Dt)for(var r of Dt(e))ao.call(e,r)&&Vt(t,r,e[r]);return t},zt=(t,e)=>no(t,io(e));function D(t,e={}){if(Array.isArray(t))return D(t[0]);if(typeof t=="string"){const[r,n]=t.split("#");return n?D({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{id:r,type:e.typeMap&&e.typeMap[r]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return D(t.items[0]);if(t.type==="SpecificResource"){t.source.type==="Canvas"&&t.source.partOf&&typeof t.source.partOf=="string"&&(t.source.partOf=[{id:t.source.partOf,type:"Manifest"}]);const{selector:r,selectors:n}=t.selector?me(t.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:r,selectors:n}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[r,n]=t.id.split("#");return n?D({type:"SpecificResource",source:zt(Qt({},t),{id:r}),selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:zt(Qt({},t),{id:r}),selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}function Bt(t){return t.type==="SpecificResource"?[t.source,{selector:t.selector}]:[t,{selector:null}]}function Ht(t,e,r){const n=[];let o=null;const i=[];for(const a of e){const s=t.get(a.body);for(const u of s){const[l,{selector:f}]=Bt(u),p=(l.type||"unknown").toLowerCase();if(p==="choice"){const d=t.get(l.items),v=r.length?r.map(c=>d.find(g=>g.id===c)).filter(Boolean):[d[0]];v.length===0&&v.push(d[0]),o={type:"single-choice",items:d.map(c=>({id:c.id,label:c.label,selected:v.indexOf(c)!==-1})),label:u.label},s.push(...v);continue}n.indexOf(p)===-1&&n.push(p),i.push({type:p,resource:l,target:a.target,selector:f})}}return{types:n,items:i,choice:o}}const Ut={makeChoice:()=>{}},_e={type:"unknown"},R=t=>({type:"unknown",reason:t,annotations:{pages:[]}});function Nt(t,e,r){const n=[];for(const o of e.items){const i=o.resource&&o.resource.type==="SpecificResource"?o.resource.source:o.resource;if(!i.id)return R("No resource Identifier");let a;if(i.service){const g=se(i);g[0]&&(a=r(g[0],t))}const{selector:s,source:u}=D(o.target);if(u.id!==t.id)continue;const l={type:"BoxSelector",spatial:{x:0,y:0,width:t.width,height:t.height}},f=s?s.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:s.temporal,spatial:l.spatial}:s:null,p={type:"BoxSelector",spatial:{x:0,y:0,width:t.width,height:t.height}},d=o.resource.type==="SpecificResource"?D(o.resource):null,v=d&&d.selector&&(d.selector.type==="BoxSelector"||d.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:d.selector.spatial.x,y:d.selector.spatial.y,width:d.selector.spatial.width,height:d.selector.spatial.height}}:p,c={id:i.id,type:"Image",width:f?i.width:t.width,height:f?i.height:t.height,service:a,sizes:a&&a.sizes?a.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:f&&f.type!=="PointSelector"?f:l,selector:v};n.push(c)}return{type:"images",image:n[0],images:n,choice:e.choice}}var so=Object.defineProperty,co=Object.defineProperties,uo=Object.getOwnPropertyDescriptors,Gt=Object.getOwnPropertySymbols,lo=Object.prototype.hasOwnProperty,fo=Object.prototype.propertyIsEnumerable,Kt=(t,e,r)=>e in t?so(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ho=(t,e)=>{for(var r in e||(e={}))lo.call(e,r)&&Kt(t,r,e[r]);if(Gt)for(var r of Gt(e))fo.call(e,r)&&Kt(t,r,e[r]);return t},po=(t,e)=>co(t,uo(e));function vo(t={},e=[]){const{id:r,selector:n}=t,o=Q(),i=E(),a=r||o.annotation,s=M(l=>a?l.iiif.entities.Annotation[a]:void 0,[a]),u=M(l=>s&&s.body?s.body.map(f=>f?l.iiif.entities[f.type][f.id]:null).filter(Boolean):[],[s]);return m.useMemo(()=>{if(!s)return;const l=po(ho({},s),{body:u,target:D(s.target,{typeMap:i.getState().iiif.mapping})});return n?n(l):l},[s,n,u,...e])}function le(t={},e=[]){const{id:r,selector:n}=t,o=Q();E();const i=r||o.manifest,a=M(s=>i?s.iiif.entities.Manifest[i]:void 0,[i]);return m.useMemo(()=>{if(!!a)return n?n(a):a},[a,n,...e])}function Y(t={},e=[]){const{id:r,selector:n}=t,o=Q(),i=r||o.canvas,a=M(s=>i?s.iiif.entities.Canvas[i]:void 0,[i]);return m.useMemo(()=>{if(!!a)return n?n(a):a},[a,n,...e])}function mo(t,e){var r;const n=(r=t==null?void 0:t.iiif)==null?void 0:r.meta[e];return n?n.annotationPageManager:null}function go(t,e){return M(r=>{const n=[];if(!t)return n;const o=Object.keys(r.iiif.entities.AnnotationPage);for(const i of o)if(!e||e.indexOf(i)!==-1){const a=mo(r,i);a&&a.views&&a.views[t]&&n.push(i)}return n},[t])}function Yt({canvas:t,manifest:e,all:r,canvases:n}){const o=[];if(e)for(const i of e.annotations)o.indexOf(i.id)===-1&&o.push(i.id);if(r){if(n&&n.length)for(const i of n)for(const a of i.annotations)o.indexOf(a.id)===-1&&o.push(a.id)}else if(t)for(const i of t.annotations)o.indexOf(i.id)===-1&&o.push(i.id);return o}var yo=Object.defineProperty,wo=Object.defineProperties,bo=Object.getOwnPropertyDescriptors,Jt=Object.getOwnPropertySymbols,So=Object.prototype.hasOwnProperty,xo=Object.prototype.propertyIsEnumerable,Zt=(t,e,r)=>e in t?yo(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Xt=(t,e)=>{for(var r in e||(e={}))So.call(e,r)&&Zt(t,r,e[r]);if(Jt)for(var r of Jt(e))xo.call(e,r)&&Zt(t,r,e[r]);return t},er=(t,e)=>wo(t,bo(e));function Oo(t,e){var r;const n=(r=t==null?void 0:t.iiif)==null?void 0:r.meta[e];return n?n.annotationPageManager:null}function tr(t,e={}){const r=E(),n=le(),o=Y(),i=ut(),a=m.useMemo(()=>Yt({all:e.all,manifest:n,canvas:o,canvases:i}),[e.all,o,i,n]),s=go(t,e.all?void 0:a),u=m.useCallback(f=>{!t||r.setMetaValue([f,"annotationPageManager","views"],p=>p&&!p[t]?p:er(Xt({},p||{}),{[t]:!1}))},[t,r]),l=m.useCallback((f,p={})=>{if(!t)return;const d=r.getState(),v=[];if(p==null?void 0:p.deselectOthers){const c=Object.keys(d.iiif.entities.AnnotationPage);for(const g of c){const x=Oo(d,g);x&&x.views&&x.views[t]&&v.push(g)}}for(const c of v)u(c);r.setMetaValue([f,"annotationPageManager","views"],c=>c&&c[t]?c:er(Xt({},c||{}),{[t]:!0}))},[t,u,r]);return{availablePageIds:a,enabledPageIds:s,setPageEnabled:l,setPageDisabled:u}}function ge(t={}){const e=Y(t.canvasId?{id:t.canvasId}:void 0);return M((r,n)=>{if(!e)return[];const o=n.get(e.items),i=[];for(const a of o)i.push(...n.get(a.items));return i},[e])}function Co(t,e={}){return ge(e)}function Ao(t,e=!1){}function Po(t,e=[]){const{id:r,selector:n}=t,o=Q(),i=r||o.collection,a=M(s=>i?s.iiif.entities.Collection[i]:void 0,[i]);return m.useMemo(()=>{if(!!a)return n?n(a):a},[a,n,...e])}function rr(){const e=E().getStore();return m.useMemo(()=>r=>e.dispatch(r),[e])}function nr(t){return{addEventListener(e,r,n,o){if(e)return t.setMetaValue([e.id,"eventManager",r],i=>{const a=i||[];for(const s of a)if(s.callback===n)return a;return[...a,{callback:n,scope:o}]}),n},removeEventListener(e,r,n){!e||t.setMetaValue([e.id,"eventManager",r],o=>(o||[]).filter(i=>i.callback!==n))},getListenersAsProps(e,r){const n=typeof e=="string"?{id:e}:e;if(!n||!n.id)return{};const o=t.getResourceMeta(n.id,"eventManager"),i={};if(o&&n)for(const a of Object.keys(o))i[a]=s=>{const u=t.get(n);for(const{callback:l,scope:f}of o[a]||[])(!f||r&&f.indexOf(r)!==-1)&&l(s,u)};return i}}}function ir(t){return{applyStyles(e,r,n){const o=typeof e=="string"?e:e.id;return t.setMetaValue([o,"styles",r],n)},getAppliedStyles(e){const r=typeof e=="string"?e:e.id;return t.getResourceMeta(r,"styles")}}}function J(t){return t.endsWith("info.json")?t:t.endsWith("/")?`${t}info.json`:`${t}/info.json`}function Io(t,e,r){const n=r.length,o=[];for(let i=0;i<n;i++){const a=r[i].width;o.push(t/a)}return o}function $o(t,e,r){const n=r.length,o=[];for(let i=0;i<n;i++){const a=r[i];o.push({width:Math.floor(t/a),height:Math.floor(e/a)})}return o}const _o="http://library.stanford.edu/iiif/image-api/compliance.html#level0",or="http://library.stanford.edu/iiif/image-api/compliance.html#level1",ar="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Eo="http://library.stanford.edu/iiif/image-api/conformance.html#level0",sr="http://library.stanford.edu/iiif/image-api/conformance.html#level1",cr="http://library.stanford.edu/iiif/image-api/conformance.html#level2",jo="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",ur="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",lr="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",To="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",fr="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",hr="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Mo="http://iiif.io/api/image/1/level0.json",Fo="http://iiif.io/api/image/1/profiles/level0.json",dr="http://iiif.io/api/image/1/level1.json",pr="http://iiif.io/api/image/1/profiles/level1.json",vr="http://iiif.io/api/image/1/level2.json",mr="http://iiif.io/api/image/1/profiles/level2.json",Lo="http://iiif.io/api/image/2/level0.json",ko="http://iiif.io/api/image/2/profiles/level0.json",gr="http://iiif.io/api/image/2/level1.json",yr="http://iiif.io/api/image/2/profiles/level1.json",wr="http://iiif.io/api/image/2/level2.json",br="http://iiif.io/api/image/2/profiles/level2.json",Ro="level0",Sr="level1",xr="level2",qo="http://iiif.io/api/image/2/level0",Or="http://iiif.io/api/image/2/level1",Cr="http://iiif.io/api/image/2/level2",Wo=[Or,Cr,or,ar,sr,cr,ur,lr,fr,hr,dr,pr,vr,mr,gr,yr,wr,br,Sr,xr],Do=[qo,Or,Cr,_o,or,ar,Eo,sr,cr,jo,ur,lr,To,fr,hr,Mo,Fo,dr,pr,vr,mr,Lo,ko,gr,yr,wr,br,Ro,Sr,xr];function _(t){if(t["@id"])return t["@id"];if(t.id)return t.id}function Ee(t){if(!t||!t.profile||!_(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const r of e)if(typeof r=="string"&&Do.indexOf(r)!==-1)return!0;return!1}function Vo(t){if(!Ee(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const r of e)if(typeof r=="string"){if(Wo.indexOf(r)!==-1)return!0}else{const n=r.supports||[];if(n.indexOf("regionByPx")!==-1&&(n.indexOf("sizeByW")!==-1||n.indexOf("sizeByWh")!==-1))return!0}return!1}function Qo(t){if(!Vo(t))return[];const e=[],r=Array.isArray(t.profile)?t.profile:[t.profile],n=r.length;for(let o=0;o<n;o++){const i=r[o];if(typeof i!="string"&&(i.maxHeight||i.maxWidth))return[{id:_(t),type:"variable",minWidth:0,minHeight:0,maxHeight:i.maxHeight||i.maxWidth,maxWidth:i.maxWidth||i.maxHeight}]}if(t.tiles){const o=t.tiles.length;for(let i=0;i<o;i++){const a=t.tiles[i];(a.height||a.width)&&e.push({id:_(t),type:"variable",minHeight:0,minWidth:0,maxHeight:a.height||a.width,maxWidth:a.width})}}return e}function Ar(t){const e=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,r=t.match(e);if(r){const n=r[1],o=parseInt(r[4],10),i=parseInt(r[5],10),a=r[7];if((n==="max"||n==="full")&&o&&i&&a)return{type:"fixed",id:t,height:i,width:o}}return{type:"unknown",id:t}}function zo(t){if(t["@type"])return t["@type"];if(t.type)return t.type}function je(t){if(typeof t=="string")return Ar(t);const e=zo(t);if(e!=="Image"&&e!=="sc:Image")return null;const r=t,n=_(r);return n?n&&r.width&&r.height?{id:n,type:"fixed",width:r.width,height:r.height,unsafe:!0}:Ar(n):null}function Bo(t){return Ee(t)?(t&&t.sizes?t.sizes:[]).map(e=>({id:_(t),type:"fixed-service",height:e.height,width:e.width})):[]}function Pr(t){const e=[],r=t.length;for(let n=0;n<r;n++){const o=Bo(t[n]);o.length&&e.push(...o);const i=Qo(t[n]);i.length&&e.push(...i)}return e}function Ir(t){const e=t.service?Array.isArray(t.service)?t.service:[t.service]:[],r=e.length,n=[];for(let o=0;o<r;o++)Ee(e[o])&&n.push(e[o]);return n}function Ho(t,e=!0,r){const n=[],o=je(t);if(o===null)return n;const i=t;if(n.push(o),e&&i.width&&i.height){const a=[],s=Ir(i);for(const u of s){const l={id:_(u),width:i.width,height:i.height};if(r.canLoadSync(l)){const f=r.loadServiceSync(l);f&&(f.height||(f.height=i.height),f.width||(f.width=i.width),a.push(...Pr([f])))}}if(a.length)return n.push(...a),n}return i.service&&n.push(...Pr(i.service)),n}function Te(t,e,r){return{id:[J(_(t)).slice(0,-10),"full",[e,r||""].join(","),0,"default.jpg"].join("/"),type:"fixed",width:e,height:r||t.height/t.width*e,unsafe:t.width>e}}function Z(t){const e=t.replace(/(https?:\/\/)?(www.)?/i,"");return e.indexOf("/")!==-1?e.split("/")[0]:e}function Uo(t,e,r){const n=t.width?t.width:t.maxWidth;return r.height<=t.maxHeight&&r.width<=t.maxWidth&&r.height>=t.minHeight&&r.width>=t.minWidth&&(!e||Math.abs(r.width-n)<Math.abs(e.width-n))}function No(t,e){const r=[],n=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},t),o=[],i=[];let a=null;const s=(l,f)=>{if(Uo(n,f,l)){if(n.preferFixedSize&&l.unsafe){i.push(l);return}n.returnAllOptions&&f&&i.push(f),a=l}else n.returnAllOptions&&i.push(l)},u=e.length;for(let l=0;l<u;l++){const f=e[l](),p=f.length;for(let d=0;d<p;d++){const v=f[d];if(v.type==="unknown"&&n.atAnyCost&&o.push(v),v.type==="fixed"&&(v.unsafe?o.push(v):s(v,a)),v.type==="fixed-service")if(n.unsafeImageService){const c=Te(v,n.width,n.height);s(c,a)}else{const c=Te(v,v.width,v.height);s(c,a)}if(v.type==="variable"&&v.maxWidth){const c=Te({id:v.id,type:"fixed-service",width:v.maxWidth,height:v.maxWidth},v.maxWidth);s(c,a)}}if(a&&!n.returnAllOptions){if(a.unsafe||n.allowUnsafe)continue;break}}return n.atAnyCost&&i.length===0?{best:a||o[0],fallback:o.slice(1),log:r}:n.returnAllOptions?{best:n.atAnyCost?a||i[0]||o[0]:a||i[0],fallback:[...i,...o],log:r}:{best:a||i[0]||null,fallback:a?i:i.slice(1),log:r}}function Go(t,e,r){const n=t>e?t:e,o=r.length,i=[];for(let a=0;a<o;a++){const s=r[a];let u=s.scaleFactors[0],l=n/u;const f=[u];for(;l>=s.width;)u=u*2,f.push(u),l=l/2;i.push(Object.assign(Object.assign({},s),{scaleFactors:f}))}return i}function Ko(t,e){if(t.length!==e.length)return!1;if(t.length===0&&e.length===0)return!0;const r=t.length;let n=!0;for(let i=0;i<r;i++){const a=t[i],s=e[i];if(a.width!==s.width||a.height!==s.height){n=!1;break}}if(n)return!0;let o=0;for(let i=0;i<r;i++)for(let a=0;a<r;a++)if(t[i].width===e[a].width&&t[i].height===e[a].height){o++;break}return o===r}/*! *****************************************************************************
|
|
1
|
+
(function(y,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("react"),require("@iiif/vault")):typeof define=="function"&&define.amd?define(["exports","react","@iiif/vault"],m):(y=typeof globalThis<"u"?globalThis:y||self,m(y.ReactIIIFVault={},y.React,y.IIIFVault))})(this,function(y,m,fe){"use strict";function mn(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var O=mn(m),gn=Object.defineProperty,Re=Object.getOwnPropertySymbols,yn=Object.prototype.hasOwnProperty,wn=Object.prototype.propertyIsEnumerable,qe=(t,e,r)=>e in t?gn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,We=(t,e)=>{for(var r in e||(e={}))yn.call(e,r)&&qe(t,r,e[r]);if(Re)for(var r of Re(e))wn.call(e,r)&&qe(t,r,e[r]);return t};const bn={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},he=O.default.createContext(bn),Q=()=>m.useContext(he),z=({value:t,children:e})=>{const r=Q(),n=m.useMemo(()=>We(We({},r),t),[t,r]);return O.default.createElement(he.Provider,{value:n},e)},Sn=({annotation:t,children:e})=>O.default.createElement(z,{value:{annotation:t}},e),De=({canvas:t,children:e})=>O.default.createElement(z,{value:{canvas:t}},e),xn=({collection:t,children:e})=>O.default.createElement(z,{value:{collection:t}},e),Ve=({manifest:t,children:e})=>O.default.createElement(z,{value:{manifest:t}},e),On=({range:t,children:e})=>O.default.createElement(z,{value:{range:t}},e),re=O.default.createContext({vault:null,setVaultInstance:t=>{}}),Qe=({vault:t,vaultOptions:e,useGlobal:r,resources:n,children:o})=>{const[i,a]=m.useState(()=>t||(r?fe.globalVault(e):e?new fe.Vault(e):new fe.Vault));return O.default.createElement(re.Provider,{value:{vault:i,setVaultInstance:a}},O.default.createElement(z,{value:n||{}},o))};function T(){return T=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},T.apply(this,arguments)}function ye(t,e){if(t==null)return{};var r={},n=Object.keys(t),o,i;for(i=0;i<n.length;i++)o=n[i],!(e.indexOf(o)>=0)&&(r[o]=t[o]);return r}var we="loading",be="error",ze="success",Cn=0,An=function(){return Cn++},Pn={},de=typeof window>"u",k=function(){},In=function(e){return e},Se=console||{error:k,warn:k,log:k};function $n(){var t=O.default.useRef(null);return t.current===null&&(t.current=An()),t.current}function _n(t){var e=O.default.useRef();return e.current=t,O.default.useCallback(function(){return e.current},[])}function xe(t,e){return typeof t=="function"?t(e):t}function En(t,e){return Be(e)?Object.assign.apply(Object,[{}].concat(Object.keys(e).sort().map(function(r){var n;return n={},n[r]=e[r],n}))):e}function jn(t){return JSON.stringify(t,En)}function Be(t){return t&&typeof t=="object"&&!Array.isArray(t)}function He(t,e){return t===e?!0:typeof t!=typeof e?!1:typeof t=="object"?!Object.keys(e).some(function(r){return!He(t[r],e[r])}):!1}function Oe(){return typeof document>"u"||document.visibilityState===void 0||document.visibilityState==="visible"||document.visibilityState==="prerender"}function Tn(){return navigator.onLine===void 0||navigator.onLine}function Ue(t){if(Be(t[0]))if(t[0].hasOwnProperty("queryKey")&&t[0].hasOwnProperty("queryFn")){var e=t[0],r=e.queryKey,n=e.variables,o=n===void 0?[]:n,i=e.queryFn,a=e.config,s=a===void 0?{}:a;return[r,o,i,s]}else throw new Error("queryKey and queryFn keys are required.");if(typeof t[2]=="function"){var u=t[0],l=t[1],f=l===void 0?[]:l,p=t[2],d=t[3],v=d===void 0?{}:d;return[u,f,p,v]}var c=t[0],g=t[1],x=t[2],S=x===void 0?{}:x;return[c,[],g,S]}function Mn(t){var e=O.default.useRef(!1);return O.default[de?"useEffect":"useLayoutEffect"](function(){return e.current=!0,function(){return e.current=!1}},[]),O.default.useCallback(function(){return e.current?t.apply(void 0,arguments):void 0},[t])}function Fn(t){if((t.config.suspense||t.config.useErrorBoundary)&&t.status===be)throw setTimeout(function(){t.query.state.status="loading"}),t.error;if(t.config.suspense&&t.status===we)throw t.query.wasSuspended=!0,t.refetch()}function Ce(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var r,n,o;if(Array.isArray(t)){if(r=t.length,r!=e.length)return!1;for(n=r;n--!==0;)if(!Ce(t[n],e[n]))return!1;return!0}if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===e.valueOf();if(o=Object.keys(t),r=o.length,r!==Object.keys(e).length)return!1;for(n=r;n--!==0;)if(!Object.prototype.hasOwnProperty.call(e,o[n]))return!1;for(n=r;n--!==0;){var i=o[n];if(!Ce(t[i],e[i]))return!1}return!0}return t!==t&&e!==e}var Ln=O.default.createContext(),kn={retry:3,retryDelay:function(e){return Math.min(1e3*Math.pow(2,e),3e4)},staleTime:0,cacheTime:5*60*1e3,refetchAllOnWindowFocus:!0,refetchInterval:!1,suspense:!1,queryKeySerializerFn:Ne,queryFnParamsFilter:In,throwOnError:!1,useErrorBoundary:void 0,onMutate:k,onSuccess:k,onError:k,onSettled:k,refetchOnMount:!0,isDataEqual:Ce},ne={current:kn};function Rn(){return O.default.useContext(Ln)||ne.current}function Ne(t){if(!t)return[];if(typeof t=="function")try{return Ne(t())}catch{return[]}typeof t=="string"&&(t=[t]);var e=jn(t);return t=JSON.parse(e),[e,t]}function N(t,e,r){return r?e?e(t):t:((!t||!t.then)&&(t=Promise.resolve(t)),e?t.then(e):t)}function ie(t,e){try{var r=t()}catch(n){return e(n)}return r&&r.then?r.then(void 0,e):r}function G(t){return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];try{return Promise.resolve(t.apply(this,e))}catch(n){return Promise.reject(n)}}}function Ge(t,e){var r=t();return r&&r.then?r.then(e):e(r)}var Ke=Vn(),qn=O.default.createContext(Ke),Wn=[Ke];function Dn(){return O.default.useContext(qn)}var Ye={},Je={},Ze={},Xe={},et={},tt={},rt={},nt={};function Vn(){var t=[],e={queries:{},isFetching:0},r=function(){e.isFetching=Object.values(e.queries).reduce(function(a,s){return s.state.isFetching?a+1:a},0),t.forEach(function(a){return a(e)})};e.subscribe=function(i){return t.push(i),function(){t.splice(t.indexOf(i),1)}},e.clear=function(){Object.values(e.queries).forEach(function(i){return i.clear()}),e.queries={},r()};var n=function(a,s){var u=s===void 0?{}:s,l=u.exact;if(typeof a!="function"){var f=ne.current.queryKeySerializerFn(a),p=f[0],d=f[1];a=function(c){return l?c.queryHash===p:He(c.queryKey,d)}}return Object.values(e.queries).filter(a)};e.getQueries=n,e.getQuery=function(i){return n(i,{exact:!0})[0]},e.getQueryData=function(i){var a;return(a=e.getQuery(i))==null?void 0:a.state.data},e.removeQueries=function(i,a){var s=a===void 0?{}:a,u=s.exact,l=n(i,{exact:u});l.forEach(function(f){clearTimeout(f.staleTimeout),delete e.queries[f.queryHash]}),l.length&&r()},e.cancelQueries=function(i,a){var s=a===void 0?{}:a,u=s.exact,l=n(i,{exact:u});l.forEach(function(f){f.cancel()}),l.length&&r()},e.refetchQueries=G(function(i,a){var s=a===void 0?{}:a,u=s.exact,l=s.throwOnError,f=s.force,p=i===!0?Object.values(e.queries):n(i,{exact:u});return ie(function(){return N(Promise.all(p.map(function(d){return d.fetch({force:f})})))},function(d){if(l)throw d})}),e._buildQuery=function(i,a,s,u){var l=u.queryKeySerializerFn(i),f=l[0],p=l[1],d=e.queries[f];return d?(Object.assign(d,{queryVariables:a,queryFn:s}),d.config=T({},d.config,u)):(d=o({cache:e,queryKey:p,queryHash:f,queryVariables:a,queryFn:s,config:u}),!de&&d.state.data&&(d.scheduleStaleTimeout(),d.heal(),d.scheduleGarbageCollection()),d.queryHash&&(de||(e.queries[f]=d,setTimeout(function(){r()})))),d},e.prefetchQuery=G(function(){for(var i=!1,a=arguments.length,s=new Array(a),u=0;u<a;u++)s[u]=arguments[u];var l=Ue(s),f=l[0],p=l[1],d=l[2],v=l[3],c=v.force,g=ye(v,["force"]);g=T({},ne.current,g);var x=e._buildQuery(f,p,d,g);return Ge(function(){if(x.state.isStale||c)return ie(function(){return N(x.fetch({force:c}),function(S){return x.wasPrefetched=!0,i=!0,S})},function(S){if(g.throwOnError)throw S})},function(S){return i?S:x.state.data})}),e.setQueryData=function(i,a,s){var u=s===void 0?{}:s,l=u.exact,f=ye(u,["exact"]),p=n(i,{exact:l});!p.length&&typeof i!="function"&&(p=[e._buildQuery(i,void 0,function(){return Promise.resolve()},T({},ne.current,f))]),p.forEach(function(d){return d.setData(a)})};function o(i){var a=i.cache,s=i.config.queryReducer||Qn,u=typeof i.queryHash>"u",l=typeof i.config.initialData=="function"?i.config.initialData():i.config.initialData,f=typeof l<"u",p=u?!0:!f,d=i.config.manual,v=u||d||f?ze:we,c=T({},i,{instances:[],state:s(void 0,{type:Ye,initialStatus:v,initialData:l,hasInitialData:f,isStale:p,manual:d})}),g=function(h){c.state=s(c.state,h),c.instances.forEach(function(w){return w.onStateUpdate(c.state)}),r()};c.scheduleStaleTimeout=function(){c.config.staleTime!==1/0&&(c.staleTimeout=setTimeout(function(){a.getQuery(c.queryKey)&&g({type:Ze})},c.config.staleTime))},c.scheduleGarbageCollection=function(){c.config.cacheTime!==1/0&&(g({type:Xe}),c.cacheTimeout=setTimeout(function(){e.removeQueries(function(S){return S.state.markedForGarbageCollection&&S.queryHash===c.queryHash})},typeof c.state.data>"u"&&c.state.status!=="error"?0:c.config.cacheTime))},c.heal=function(){clearTimeout(c.cacheTimeout),c.cancelled=null},c.cancel=function(){c.cancelled=Pn,c.cancelPromises&&c.cancelPromises(),delete c.promise,r()},c.updateInstance=function(S){var h=c.instances.find(function(w){return w.id===S.id});h?Object.assign(h,S):(h=T({onStateUpdate:k},S),c.instances.push(S))},c.subscribe=function(S){return c.heal(),function(){c.instances=c.instances.filter(function(h){return h.id!==S}),c.instances.length||(c.cancel(),c.scheduleGarbageCollection())}};var x=G(function(S){for(var h=arguments.length,w=new Array(h>1?h-1:0),b=1;b<h;b++)w[b-1]=arguments[b];return ie(function(){var A=S.apply(void 0,c.config.queryFnParamsFilter(w));return c.cancelPromises=function(){return A.cancel==null?void 0:A.cancel()},N(A,function(P){if(delete c.shouldContinueRetryOnFocus,delete c.cancelPromises,c.cancelled)throw c.cancelled;return P})},function(A){var P=!1;if(delete c.cancelPromises,c.cancelled)throw c.cancelled;return g({type:Je}),Ge(function(){if(c.config.retry===!0||c.state.failureCount<=c.config.retry||typeof c.config.retry=="function"&&c.config.retry(c.state.failureCount,A)){if(!Oe())return c.shouldContinueRetryOnFocus=!0,P=!0,new Promise(k);delete c.shouldContinueRetryOnFocus;var C=xe(c.config.retryDelay,c.state.failureCount);return P=!0,N(new Promise(function(I,F){setTimeout(G(function(){return c.cancelled?F(c.cancelled):ie(function(){return N(x.apply(void 0,[S].concat(w)),function(ee){if(c.cancelled)return F(c.cancelled);I(ee)})},function(ee){if(c.cancelled)return F(c.cancelled);F(ee)})}),C)}))}},function(C){if(P)return C;throw A})})});return c.fetch=G(function(S){var h=S===void 0?{}:S,w=h.force,b=h.__queryFn,A=b===void 0?c.queryFn:b;if(!(!c.queryHash||!c.state.isStale&&!w))return c.promise||(c.promise=G(function(){c.cancelled=null;var P=[].concat(c.instances);return c.wasSuspended&&P.unshift(c.suspenseInstance),ie(function(){return g({type:et}),N(x.apply(void 0,[A].concat(c.queryKey,c.queryVariables)),function(C){return c.setData(function(I){return c.config.isDataEqual(I,C)?I:C}),P.forEach(function(I){return I.onSuccess&&I.onSuccess(c.state.data)}),P.forEach(function(I){return I.onSettled&&I.onSettled(c.state.data,null)}),delete c.promise,C})},function(C){if(g({type:rt,cancelled:C===c.cancelled,error:C}),delete c.promise,C!==c.cancelled)throw P.forEach(function(I){return I.onError&&I.onError(C)}),P.forEach(function(I){return I.onSettled&&I.onSettled(void 0,C)}),C})})()),c.promise}),c.setState=function(S){return g({type:nt,updater:S})},c.setData=function(S){g({type:tt,updater:S}),clearTimeout(c.staleTimeout),c.scheduleStaleTimeout()},c.clear=function(){clearTimeout(c.staleTimeout),clearTimeout(c.cacheTimeout),c.cancel()},c}return e}function Qn(t,e){switch(e.type){case Ye:return{status:e.initialStatus,error:null,isFetching:e.hasInitialData||e.manual?!1:e.initialStatus==="loading",canFetchMore:!1,failureCount:0,isStale:e.isStale,markedForGarbageCollection:!1,data:e.initialData,updatedAt:e.hasInitialData?Date.now():0};case Je:return T({},t,{failureCount:t.failureCount+1});case Ze:return T({},t,{isStale:!0});case Xe:return T({},t,{markedForGarbageCollection:!0});case et:return T({},t,{status:t.status===be?we:t.status,isFetching:!0,failureCount:0});case tt:return T({},t,{status:ze,data:xe(e.updater,t.data),error:null,isStale:!1,isFetching:!1,canFetchMore:e.canFetchMore,updatedAt:Date.now(),failureCount:0});case rt:return T({},t,{isFetching:!1,isStale:!0},!e.cancelled&&{status:be,error:e.error});case nt:return xe(e.updater,t);default:throw new Error}}var it="visibilitychange",ot="focus",zn=function(){var e=ne.current.refetchAllOnWindowFocus;Oe()&&Tn()&&Wn.forEach(function(r){return r.refetchQueries(function(n){return!n.instances.length||n.config.manual===!0?!1:n.shouldContinueRetryOnFocus?(delete n.promise,!0):typeof n.config.refetchOnWindowFocus>"u"?e:n.config.refetchOnWindowFocus}).catch(Se.error)})},Ae;function Bn(t){Ae&&Ae(),Ae=t(zn)}Bn(function(t){var e;if(!de&&((e=window)==null?void 0:e.addEventListener))return window.addEventListener(it,t,!1),window.addEventListener(ot,t,!1),function(){window.removeEventListener(it,t),window.removeEventListener(ot,t)}});function Hn(t,e,r){return r?e?e(t):t:((!t||!t.then)&&(t=Promise.resolve(t)),e?t.then(e):t)}function Un(t,e){try{var r=t()}catch(n){return e(n)}return r&&r.then?r.then(void 0,e):r}function Nn(t){return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];try{return Promise.resolve(t.apply(this,e))}catch(n){return Promise.reject(n)}}}function Gn(t,e,r,n){n===void 0&&(n={});var o=$n();n=T({},Rn(),n);var i=Dn(),a=O.default.useRef(),s=i._buildQuery(t,e,r,n),u=a.current&&typeof a.current.queryHash>"u"&&typeof s.queryHash>"u";u||(a.current=s);var l=a.current,f=O.default.useState(),p=f[1],d=Mn(p),v=_n(n),c=O.default.useCallback(Nn(function(g){var x=g===void 0?{}:g,S=x.throwOnError,h=ye(x,["throwOnError"]);return Un(function(){return Hn(l.fetch(h))},function(w){if(S)throw w})}),[l]);return l.suspenseInstance={onSuccess:function(x){return v().onSuccess(x)},onError:function(x){return v().onError(x)},onSettled:function(x,S){return v().onSettled(x,S)}},O.default.useEffect(function(){return l.updateInstance({id:o,onStateUpdate:function(){return d({})},onSuccess:function(x){return v().onSuccess(x)},onError:function(x){return v().onError(x)},onSettled:function(x,S){return v().onSettled(x,S)}}),l.subscribe(o)},[v,o,l,d]),O.default.useEffect(function(){!v().manual&&!l.wasPrefetched&&!l.wasSuspended&&l.state.isStale&&(v().refetchOnMount||l.instances.length===1)&&c().catch(Se.error),l.wasPrefetched=!1,l.wasSuspended=!1},[v,l,c]),O.default.useEffect(function(){var g=a.current;if(n.refetchInterval&&(!g.currentRefetchInterval||n.refetchInterval<g.currentRefetchInterval))return g.currentRefetchInterval=n.refetchInterval,clearInterval(g.refetchIntervalId),g.refetchIntervalId=setInterval(function(){(Oe()||n.refetchIntervalInBackground)&&c().catch(Se.error)},n.refetchInterval),function(){clearInterval(g.refetchIntervalId),delete g.refetchIntervalId,delete g.currentRefetchInterval}},[n.refetchInterval,n.refetchIntervalInBackground,c]),T({},l.state,{config:n,query:l,refetch:c})}function Pe(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];var n=Gn.apply(void 0,Ue(e));return Fn(n),n}const E=()=>{const{vault:t}=m.useContext(re);if(t===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return t};var Kn=Object.defineProperty,at=Object.getOwnPropertySymbols,Yn=Object.prototype.hasOwnProperty,Jn=Object.prototype.propertyIsEnumerable,st=(t,e,r)=>e in t?Kn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Zn=(t,e)=>{for(var r in e||(e={}))Yn.call(e,r)&&st(t,r,e[r]);if(at)for(var r of at(e))Jn.call(e,r)&&st(t,r,e[r]);return t},Xn=(t,e,r)=>new Promise((n,o)=>{var i=u=>{try{s(r.next(u))}catch(l){o(l)}},a=u=>{try{s(r.throw(u))}catch(l){o(l)}},s=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);s((r=r.apply(t,e)).next())});const ct=(t,e={})=>{const r=E(),[n,o]=m.useState(t),i=m.useMemo(()=>r.get(t)||void 0,[t,r]),{data:a,error:s}=Pe(["manifest",t],()=>Xn(void 0,null,function*(){const u=i||(yield r.load(t));return u&&n!==u.id&&o(u.id),u}),Zn({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,retry:!1,initialData:i},e));return{isLoaded:!!a,id:n,error:s,manifest:a}};function M(t,e=[]){const r=E(),[n,o]=m.useState(()=>t(r.getState(),r));return m.useEffect(()=>r.subscribe(i=>t(i,r),i=>{o(i)},!1),e),n}const oe=O.default.createContext([]);function ut(){const t=m.useContext(oe);return M(e=>t.map(r=>e.iiif.entities.Canvas[r]).filter(Boolean),[t])}const pe=()=>{},ae=m.createContext({setCurrentCanvasId:pe,setCurrentCanvasIndex:pe,nextCanvas:pe,previousCanvas:pe,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),ei=t=>{const e=ct(t.manifest),[r,n]=m.useState(""),[o,i]=m.useState([]),a=(typeof t.pagingEnabled>"u"||t.pagingEnabled)&&e.manifest&&e.manifest.behavior&&e.manifest.behavior.includes("paged");m.useEffect(()=>{var c,g;e.manifest&&(n((c=e.manifest.items[0])==null?void 0:c.id),i([(g=e.manifest.items[0])==null?void 0:g.id]))},[e.manifest,t.manifest]);const s=m.useMemo(()=>{var c;return((c=e.manifest)==null?void 0:c.items.map(g=>g.id))||[]},[e.manifest,t.manifest]),u=m.useMemo(()=>s.indexOf(r),[s,r]),l=m.useCallback(()=>{if(s.length&&r){if(u===-1||(s[u+2]?u+2===s.length:u===s.length))return;const c=a&&u!==0?s[u+2]:s[u+1],g=a?u!==0?s[u+3]:s[u+2]:null;c&&(n(c),i(g?[c,g]:[c]))}},[a,s,r,u]),f=m.useCallback(()=>{if(s.length&&r){if(u===0||u===-1)return;const c=a&&u!==1?s[u-2]:s[u-1],g=a&&u!==1?s[u-1]:null;c&&(n(c),i(g?[c,g]:[c]))}},[a,s,r,u]),p=m.useCallback(c=>{const g=a&&c%2===1?c-1:c,x=s[g],S=a&&g!==0?s[g+1]:null;x&&(n(x),i(h=>{const w=S?[x,S]:[x];if(h.length===h.length){for(let b=0;b<h.length;b++)if(h[b]!==w[b])return w;return h}return w}))},[a,s]),d=m.useCallback(c=>{const g=s.indexOf(c);g!==-1&&p(g)},[s,p]),v=m.useMemo(()=>({setCurrentCanvasId:d,nextCanvas:l,previousCanvas:f,currentCanvasIndex:u,totalCanvases:s.length,setCurrentCanvasIndex:p,pagingView:!0}),[l,f,u,s,p,d]);return!e.isLoaded||!e.manifest?O.default.createElement("div",null,"Loading..."):O.default.createElement(ae.Provider,{value:v},O.default.createElement(oe.Provider,{value:o},O.default.createElement(Ve,{manifest:e.manifest.id},O.default.createElement(De,{canvas:r},t.children))))};function ti(){return m.useContext(ae)}function ri(){return{VaultContext:m.useContext(re),ResourceContext:m.useContext(he),SimpleViewerReactContext:m.useContext(ae),VisibleCanvasReactContext:m.useContext(oe)}}const ni=t=>O.default.createElement(Qe,{vault:t.bridge.VaultContext.vault||void 0,resources:t.bridge.ResourceContext},O.default.createElement(oe.Provider,{value:t.bridge.VisibleCanvasReactContext},O.default.createElement(ae.Provider,{value:t.bridge.SimpleViewerReactContext},t.children)));function B(t){return t.endsWith("info.json")?t:t.endsWith("/")?`${t}info.json`:`${t}/info.json`}const ii="http://library.stanford.edu/iiif/image-api/compliance.html#level0",lt="http://library.stanford.edu/iiif/image-api/compliance.html#level1",ft="http://library.stanford.edu/iiif/image-api/compliance.html#level2",oi="http://library.stanford.edu/iiif/image-api/conformance.html#level0",ht="http://library.stanford.edu/iiif/image-api/conformance.html#level1",dt="http://library.stanford.edu/iiif/image-api/conformance.html#level2",ai="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",pt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",vt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",si="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",mt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",gt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",ci="http://iiif.io/api/image/1/level0.json",ui="http://iiif.io/api/image/1/profiles/level0.json",yt="http://iiif.io/api/image/1/level1.json",wt="http://iiif.io/api/image/1/profiles/level1.json",bt="http://iiif.io/api/image/1/level2.json",St="http://iiif.io/api/image/1/profiles/level2.json",li="http://iiif.io/api/image/2/level0.json",fi="http://iiif.io/api/image/2/profiles/level0.json",xt="http://iiif.io/api/image/2/level1.json",Ot="http://iiif.io/api/image/2/profiles/level1.json",Ct="http://iiif.io/api/image/2/level2.json",At="http://iiif.io/api/image/2/profiles/level2.json",hi="level0",Pt="level1",It="level2",di="http://iiif.io/api/image/2/level0",$t="http://iiif.io/api/image/2/level1",_t="http://iiif.io/api/image/2/level2",Et=[_t,ft,dt,vt,gt,bt,St,Ct,At,It],jt=[...Et,$t,lt,ht,pt,mt,yt,wt,xt,Ot,Pt],pi=[di,$t,_t,ii,lt,ft,oi,ht,dt,ai,pt,vt,si,mt,gt,ci,ui,yt,wt,bt,St,li,fi,xt,Ot,Ct,At,hi,Pt,It],vi={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},mi={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},gi={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function yi(t){return Et.indexOf(t)!==-1?gi:jt.indexOf(t)!==-1?mi:vi}function wi(t){const e=t?Array.isArray(t.profile)?t.profile:[t.profile]:[],r={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let n of e)if(typeof n=="string"&&(n=yi(n)),!!n){if(n.formats)for(const o of n.formats)r.extraFormats.indexOf(o)===-1&&r.extraFormats.push(o);if(n.qualities)for(const o of n.qualities)r.extraQualities.indexOf(o)===-1&&r.extraQualities.push(o);if(n.supports)for(const o of n.supports)r.extraFeatures.indexOf(o)===-1&&r.extraFeatures.push(o);if(n.maxHeight&&(r.maxHeight=n.maxHeight),n.maxWidth&&(r.maxWidth=n.maxWidth),n.maxArea&&(r.maxArea=n.maxArea),n.extraFormats)for(const o of n.extraFormats)r.extraFormats.indexOf(o)===-1&&r.extraFormats.push(o);if(n.extraQualities)for(const o of n.extraQualities)r.extraQualities.indexOf(o)===-1&&r.extraQualities.push(o);if(n.extraFeatures)for(const o of n.extraFeatures)r.extraFeatures.indexOf(o)===-1&&r.extraFeatures.push(o);n.maxHeight&&(r.maxHeight=n.maxHeight),n.maxWidth&&(r.maxWidth=n.maxWidth),n.maxArea&&(r.maxArea=n.maxArea)}if(t.extraFormats)for(const n of t.extraFormats)r.extraFormats.indexOf(n)===-1&&r.extraFormats.push(n);if(t.extraFeatures)for(const n of t.extraFeatures)r.extraFeatures.indexOf(n)===-1&&r.extraFeatures.push(n);if(t.extraQualities)for(const n of t.extraQualities)r.extraQualities.indexOf(n)===-1&&r.extraQualities.push(n);return r}function bi(t){try{if(t==="full")return{full:!0};if(t==="square")return{square:!0};const e=t.startsWith("pct:"),r=t.substr(e?4:0).split(",").map(n=>parseFloat(n));return{x:r[0],y:r[1],w:r[2],h:r[3],percent:e}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+t)}}function Si(t){const e={upscaled:!1,max:!1,confined:!1};if(t[0]==="^"&&(e.upscaled=!0,t=t.slice(1)),t==="max"||t==="full")return e.max=!0,e.serialiseAsFull=t==="full",e;if(t[0]==="!"&&(e.confined=!0,t=t.slice(1)),t[0]==="p")return e.percentScale=parseFloat(t.slice(4)),e;const r=t.split(",").map(n=>n.trim());return r.length&&(r[0]!==""&&(e.width=parseInt(r[0],10)),r[1]!==""&&(e.height=parseInt(r[1],10))),e}function xi(t){const e={angle:0};if(t[0]==="!"&&(e.mirror=!0,t=t.substr(1)),e.angle=parseFloat(t)%360,Number.isNaN(e.angle))throw new Error(`Invalid rotation ${t}`);return e}function Oi(t,e=""){const r=t.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!r)throw new Error(`Invalid or unknown input ${t}`);const n=r[2],o=r[3];let i=r[4];if(i[0]==="/"&&(i=i.substr(1)),e.length>0){if(e[0]==="/"&&(e=e.substr(1)),e!==i.substr(0,e.length))throw new Error(`Path does not start with prefix (path: ${i}, prefix: ${e})`);i=i.substr(e.length)}return{scheme:n,server:o,path:i,prefix:e}}function Ci(t,e=""){const{path:r,scheme:n,server:o,prefix:i}=Oi(t,e),a=r.split("/").reverse(),[s,u,l,f,...p]=a,d=p.reverse().filter(Boolean).join("/");if(a.length===1||s==="")return{type:"base",scheme:n,server:o,prefix:i,identifier:d};if(s==="info.json"){const[,...c]=a;return{type:"info",scheme:n,server:o,prefix:i,identifier:c.reverse().filter(Boolean).join("/")}}const v=s.split(".");return{type:"image",scheme:n,server:o,prefix:i,identifier:d,originalPath:r,region:bi(f),size:Si(l),rotation:xi(u),quality:v[0],format:v[1]}}function Ai(t){const e=Ci(B(t.id));if(e.type!=="info")throw new Error("Invalid service URL");const r=wi(t);return{identifier:e.identifier,originalPath:"",server:e.server,prefix:e.prefix,scheme:e.scheme,type:"image",quality:r.extraQualities.indexOf("default")===-1?r.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}}function Pi(t,e,r){const n=r.length,o=[];for(let i=0;i<n;i++){const a=r[i].width;o.push(t/a)}return o}function Ii(t,e,r){const n=r.length,o=[];for(let i=0;i<n;i++){const a=r[i];o.push({width:Math.floor(t/a),height:Math.floor(e/a)})}return o}function $(t){if(t["@id"])return t["@id"];if(t.id)return t.id}function Ie(t){if(!t||!t.profile||!$(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const r of e)if(typeof r=="string"&&pi.indexOf(r)!==-1)return!0;return!1}function $i(t){if(!Ie(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const r of e)if(typeof r=="string"){if(jt.indexOf(r)!==-1)return!0}else{const n=[...r.supports||[],...r.extraFeatures||[]];if(n.indexOf("regionByPx")!==-1&&(n.indexOf("sizeByW")!==-1||n.indexOf("sizeByWh")!==-1))return!0}return!1}function _i(t){if(!$i(t))return[];const e=[],r=Array.isArray(t.profile)?t.profile:[t.profile],n=r.length;for(let o=0;o<n;o++){const i=r[o];if(typeof i!="string"&&(i.maxHeight||i.maxWidth))return[{id:$(t),type:"variable",minWidth:0,minHeight:0,maxHeight:i.maxHeight||i.maxWidth,maxWidth:i.maxWidth||i.maxHeight}]}if(t.tiles){const o=t.tiles.length;for(let i=0;i<o;i++){const a=t.tiles[i];(a.height||a.width)&&e.push({id:$(t),type:"variable",minHeight:0,minWidth:0,maxHeight:a.height||a.width,maxWidth:a.width})}}return e}function Tt(t){const e=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,r=t.match(e);if(r){const n=r[1],o=parseInt(r[4],10),i=parseInt(r[5],10),a=r[7];if((n==="max"||n==="full")&&o&&i&&a)return{type:"fixed",id:t,height:i,width:o}}return{type:"unknown",id:t}}function Ei(t){if(t["@type"])return t["@type"];if(t.type)return t.type}function ji(t){if(typeof t=="string")return Tt(t);const e=Ei(t);if(e!=="Image"&&e!=="sc:Image")return null;const r=t,n=$(r);return n?n&&r.width&&r.height?{id:n,type:"fixed",width:r.width,height:r.height,unsafe:!0}:Tt(n):null}function Ti(t){return Ie(t)?(t&&t.sizes?t.sizes:[]).map(e=>({id:$(t),type:"fixed-service",height:e.height,width:e.width})):[]}function Mt(t){const e=[],r=t.length;for(let n=0;n<r;n++){const o=Ti(t[n]);o.length&&e.push(...o);const i=_i(t[n]);i.length&&e.push(...i)}return e}function se(t){const e=t.service?Array.isArray(t.service)?t.service:[t.service]:[],r=e.length,n=[];for(let o=0;o<r;o++)Ie(e[o])&&n.push(e[o]);return n}function Mi(t,e=!0,r){const n=[],o=ji(t);if(o===null)return n;const i=t;if(n.push(o),e&&i.width&&i.height){const a=[],s=se(i);for(const u of s){const l={id:$(u),width:i.width,height:i.height};if(r.canLoadSync(l)){const f=r.loadServiceSync(l);f&&(f.height||(f.height=i.height),f.width||(f.width=i.width),a.push(...Mt([f])))}}if(a.length)return n.push(...a),n}return i.service&&n.push(...Mt(i.service)),n}function Fi({x:t=0,y:e=0,w:r,h:n,full:o,square:i,percent:a}){if(o)return"full";if(i)return"square";if(typeof r>"u"||typeof n>"u")throw new Error("RegionParameter: invalid region");const s=`${t},${e},${r},${n}`;return a?`pct:${s}`:s}function Li({max:t,percentScale:e,upscaled:r,confined:n,width:o,height:i,serialiseAsFull:a}){const s=[];return r&&s.push("^"),t?(s.push(a?"full":"max"),s.join("")):(n&&s.push("!"),e&&s.push(`pct:${e}`),o&&s.push(`${o}`),s.push(","),i&&s.push(`${i}`),s.join(""))}function ki(t){return`${t.mirror?"!":""}${(t.angle||0)%360}`}var Ri=Object.defineProperty,qi=Object.defineProperties,Wi=Object.getOwnPropertyDescriptors,Ft=Object.getOwnPropertySymbols,Di=Object.prototype.hasOwnProperty,Vi=Object.prototype.propertyIsEnumerable,Lt=(t,e,r)=>e in t?Ri(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ce=(t,e)=>{for(var r in e||(e={}))Di.call(e,r)&&Lt(t,r,e[r]);if(Ft)for(var r of Ft(e))Vi.call(e,r)&&Lt(t,r,e[r]);return t},ue=(t,e)=>qi(t,Wi(e));function Qi(t,e){const r=t.prefix.startsWith("/")?t.prefix.substr(1):t.prefix,n=`${t.scheme}://${t.server}/${r?`${r}/`:""}${t.identifier}`;if(t.type==="base")return n;if(t.type==="info")return`${n}/info.json`;let{region:o,size:i,rotation:a,format:s,quality:u}=t;if(e){const l=e["@context"]?Array.isArray(e["@context"])?e["@context"]:[e["@context"]]:[],f=l.indexOf("http://iiif.io/api/image/2/context.json")!==-1,p=l.indexOf("http://iiif.io/api/image/3/context.json")!==-1;if((i.width===e.width&&!i.height||i.height===e.height&&!i.width||i.width===e.width&&i.height===e.height)&&(i=ue(ce({},i),{max:!0})),f&&(i.max&&!i.serialiseAsFull&&(i=ue(ce({},i),{serialiseAsFull:!0})),!i.max&&i.width&&i.height&&(i=ue(ce({},i),{height:void 0}))),p&&(i.max&&i.serialiseAsFull&&(i=ue(ce({},i),{serialiseAsFull:!1})),i.width&&!i.height&&e.width&&e.height)){const d=e.height/e.width;i=ue(ce({},i),{height:Math.ceil(i.width*d)})}}return[n,Fi(o),Li(i),ki(a),`${u}.${s}`].filter(Boolean).join("/")}function $e(t,e,r){const n=Ai({id:B($(t)),profile:"level2",type:"ImageService2"});if(n.type!=="image")throw new Error("Invalid service");return n.size.max=!1,n.size.width=e,n.size.height=r,{id:Qi(n),type:"fixed",width:e,height:r||t.height/(t.width||1)*e,unsafe:t.width>e}}function K(t){const e=t.replace(/(https?:\/\/)?(www.)?/i,"");return e.indexOf("/")!==-1?e.split("/")[0]:e}function zi(t,e,r){const n=t.width?t.width:t.maxWidth;return r.height<=t.maxHeight&&r.width<=t.maxWidth&&r.height>=t.minHeight&&r.width>=t.minWidth&&(!e||Math.abs(r.width-n)<Math.abs(e.width-n))}function Bi(t,e){const r=[],n=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},t),o=[],i=[];let a=null;const s=(l,f)=>{if(zi(n,f,l)){if(n.preferFixedSize&&l.unsafe){i.push(l);return}n.returnAllOptions&&f&&i.push(f),a=l}else n.returnAllOptions&&i.push(l)},u=e.length;for(let l=0;l<u;l++){const f=e[l](),p=f.length;for(let d=0;d<p;d++){const v=f[d];if(v.type==="unknown"&&n.atAnyCost&&o.push(v),v.type==="fixed"&&(v.unsafe?o.push(v):s(v,a)),v.type==="fixed-service")if(n.unsafeImageService){const c=$e(v,n.width,n.height);s(c,a)}else{const c=$e(v,v.width,v.height);s(c,a)}if(v.type==="variable"&&v.maxWidth){const c=$e({id:v.id,type:"fixed-service",width:v.maxWidth,height:v.maxWidth},v.maxWidth);s(c,a)}}if(a&&!n.returnAllOptions){if(a.unsafe||n.allowUnsafe)continue;break}}return n.atAnyCost&&i.length===0?{best:a||o[0],fallback:o.slice(1),log:r}:n.returnAllOptions?{best:n.atAnyCost?a||i[0]||o[0]:a||i[0],fallback:[...i,...o],log:r}:{best:a||i[0]||null,fallback:a?i:i.slice(1),log:r}}var Hi=Object.defineProperty,Ui=Object.defineProperties,Ni=Object.getOwnPropertyDescriptors,kt=Object.getOwnPropertySymbols,Gi=Object.prototype.hasOwnProperty,Ki=Object.prototype.propertyIsEnumerable,Rt=(t,e,r)=>e in t?Hi(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Yi=(t,e)=>{for(var r in e||(e={}))Gi.call(e,r)&&Rt(t,r,e[r]);if(kt)for(var r of kt(e))Ki.call(e,r)&&Rt(t,r,e[r]);return t},Ji=(t,e)=>Ui(t,Ni(e));function Zi(t,e,r){const n=t>e?t:e,o=r.length,i=[];for(let a=0;a<o;a++){const s=r[a];let u=s.scaleFactors[0],l=n/u;const f=[u];for(;l>=s.width;)u=u*2,f.push(u),l=l/2;i.push(Ji(Yi({},s),{scaleFactors:f}))}return i}function Xi(t,e){if(t.length!==e.length)return!1;if(t.length===0&&e.length===0)return!0;const r=t.length;let n=!0;for(let i=0;i<r;i++){const a=t[i],s=e[i];if(a.width!==s.width||a.height!==s.height){n=!1;break}}if(n)return!0;let o=0;for(let i=0;i<r;i++)for(let a=0;a<r;a++)if(t[i].width===e[a].width&&t[i].height===e[a].height){o++;break}return o===r}var H=(t,e,r)=>new Promise((n,o)=>{var i=u=>{try{s(r.next(u))}catch(l){o(l)}},a=u=>{try{s(r.throw(u))}catch(l){o(l)}},s=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);s((r=r.apply(t,e)).next())});class qt{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(e){Object.assign(this.config,e)}sample(e,r,n=!0){const o=K($(e)),i=B($(e)),a=this.knownImageServers[o];return this.imageServices[i]=Object.assign(e,{real:!0}),a?this.verify(e):(this.knownImageServers[o]={verifications:0,malformed:!1,root:o,preLoaded:n,sampledId:$(e),verified:!1,server:null,result:{context:e["@context"]||[],sampledProfile:e.profile,resourceServiceRatio:r&&e.height?r.height/e.height:1,sampledSizes:e.sizes||[],sizeRatios:Pi(e.width,e.height,e.sizes||[]),sampledTiles:e.tiles||[]}},!0)}preLoad(e,r=!0){this.knownImageServers[e.root]=e,r&&(this.knownImageServers[e.root].malformed=!1,this.knownImageServers[e.root].verifications=this.config.verificationsRequired)}predict(e,r=!1,n=!1){const o=K($(e)),i=this.knownImageServers[o];if(!i||!i.result||!n&&(i.malformed||i.verifications<this.config.verificationsRequired))return null;const a=B($(e));return this.imageServices[a]||(this.imageServices[a]={"@context":i.result.context,"@id":$(e),id:$(e),protocol:"http://iiif.io/api/image",tiles:Zi(e.width,e.height,i.result.sampledTiles),sizes:Ii(Math.floor(e.width/i.result.resourceServiceRatio),Math.floor(e.height/i.result.resourceServiceRatio),i.result.sizeRatios),profile:i.result.sampledProfile,height:e.height,width:e.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(e,r){return H(this,arguments,function*(n,o,i=!0,a=[]){const s=yield this.getImageCandidates(n,i);return Bi(o,[()=>a,()=>s])})}getImageCandidates(e,r=!0){return H(this,null,function*(){const n=e;if(r&&n.height&&n.width){const o=se(n);for(const i of o){const a={id:$(i),width:i.width?i.width:n.width,height:i.height?i.height:n.height};yield this.loadService(a)}}return Mi(e,r,this)})}verify(e){return H(this,null,function*(){const r=this.predict(e,!1,!0),n=yield this.fetchService($(e));if(!r)return!1;const o=r.height===n.height&&r.width===n.width&&r["@context"]===n["@context"]&&Xi(r.sizes||[],n.sizes||[]);if(o){const i=K($(e));this.knownImageServers[i].verifications+=1,this.knownImageServers[i].verifications>=this.config.verificationsRequired&&(this.knownImageServers[i].verified=!0)}return o})}canLoadSync(e){const r=typeof e=="string"?e:$(e),n=B(r);if(this.imageServices[n])return!0;const o=this.knownImageServers[K(r)];return o&&!o.malformed&&o.verifications>=this.config.verificationsRequired}markAsMalformed(e){return H(this,null,function*(){return this.knownImageServers[K($(e))].malformed=!0,this.loadService(e,!0)})}fetchService(e,r=!1){return H(this,null,function*(){const n=B(e);if(this.imageServices[n]&&(!r||this.imageServices[n].real))return this.imageServices[n];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const o=yield this.fetch(n).then(i=>i.json());return!o.id&&o["@id"]&&(o.id=o["@id"]),o.id!==e&&(o.id=e,o["@id"]&&(o["@id"]=e)),this.imageServices[n]=Object.assign(o,{real:!0}),this.imageServices[n]})}fetch(e,r){return H(this,null,function*(){return fetch(e,r)})}loadService(e,r=!1){return H(this,null,function*(){if(!this.config.disableThrottling){let i=!0;for(;i;)if(this.fetchingCount>=this.config.verificationsRequired)yield new Promise(a=>setTimeout(a,500));else{i=!1;break}}const n=this.knownImageServers[K($(e))];if(n&&!n.malformed&&!r){yield n.result;const i=this.loadServiceSync(e);if(i)return i}this.fetchingCount++;const o=yield this.fetchService($(e),r);return this.fetchingCount--,o.real&&this.sample(o,e),o})}loadServiceSync(e){const r=B($(e));return this.imageServices[r]?this.imageServices[r]:this.predict(e)}}new qt;const Wt=O.default.createContext(new qt);function ve(){return m.useContext(Wt)}const eo=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,to=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function me(t){if(Array.isArray(t))return t.reduce((e,r)=>{const{selector:n,selectors:o}=me(r);return n&&(e.selector||(e.selector=n),e.selectors.push(...o)),e},{selector:null,selectors:[]});if(!t)return{selector:null,selectors:[]};if(typeof t=="string"){const[e,r]=t.split("#");return r?me({type:"FragmentSelector",value:r}):{selector:null,selectors:[]}}if(t.type==="PointSelector"&&(t.t||t.t===0)){const e={type:"TemporalSelector",temporal:{startTime:t.t}};return{selector:e,selectors:[e]}}if(t.type==="FragmentSelector"){const e=eo.exec(t.value);if(e){const n={type:"BoxSelector",spatial:{unit:e[2]==="percent:"?"percent":"pixel",x:parseFloat(e[3]),y:parseFloat(e[4]),width:parseFloat(e[5]),height:parseFloat(e[6])}};return{selector:n,selectors:[n]}}const r=t.value.match(to);if(r){const n={type:"TemporalSelector",temporal:{startTime:r[4]?parseFloat(r[4]):0,endTime:r[7]?parseFloat(r[7]):void 0}};return{selector:n,selectors:[n]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}var ro=Object.defineProperty,no=Object.defineProperties,io=Object.getOwnPropertyDescriptors,Dt=Object.getOwnPropertySymbols,oo=Object.prototype.hasOwnProperty,ao=Object.prototype.propertyIsEnumerable,Vt=(t,e,r)=>e in t?ro(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Qt=(t,e)=>{for(var r in e||(e={}))oo.call(e,r)&&Vt(t,r,e[r]);if(Dt)for(var r of Dt(e))ao.call(e,r)&&Vt(t,r,e[r]);return t},zt=(t,e)=>no(t,io(e));function D(t,e={}){if(Array.isArray(t))return D(t[0]);if(typeof t=="string"){const[r,n]=t.split("#");return n?D({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{id:r,type:e.typeMap&&e.typeMap[r]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return D(t.items[0]);if(t.type==="SpecificResource"){t.source.type==="Canvas"&&t.source.partOf&&typeof t.source.partOf=="string"&&(t.source.partOf=[{id:t.source.partOf,type:"Manifest"}]);const{selector:r,selectors:n}=t.selector?me(t.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:r,selectors:n}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[r,n]=t.id.split("#");return n?D({type:"SpecificResource",source:zt(Qt({},t),{id:r}),selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:zt(Qt({},t),{id:r}),selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}function Bt(t){return t.type==="SpecificResource"?[t.source,{selector:t.selector}]:[t,{selector:null}]}function Ht(t,e,r){const n=[];let o=null;const i=[];for(const a of e){const s=t.get(a.body);for(const u of s){const[l,{selector:f}]=Bt(u),p=(l.type||"unknown").toLowerCase();if(p==="choice"){const d=t.get(l.items),v=r.length?r.map(c=>d.find(g=>g.id===c)).filter(Boolean):[d[0]];v.length===0&&v.push(d[0]),o={type:"single-choice",items:d.map(c=>({id:c.id,label:c.label,selected:v.indexOf(c)!==-1})),label:u.label},s.push(...v);continue}n.indexOf(p)===-1&&n.push(p),i.push({type:p,resource:l,target:a.target,selector:f})}}return{types:n,items:i,choice:o}}const Ut={makeChoice:()=>{}},_e={type:"unknown"},R=t=>({type:"unknown",reason:t,annotations:{pages:[]}});function Nt(t,e,r){const n=[];for(const o of e.items){const i=o.resource&&o.resource.type==="SpecificResource"?o.resource.source:o.resource;if(!i.id)return R("No resource Identifier");let a;if(i.service){const g=se(i);g[0]&&(a=r(g[0],t))}const{selector:s,source:u}=D(o.target);if(u.id!==t.id)continue;const l={type:"BoxSelector",spatial:{x:0,y:0,width:t.width,height:t.height}},f=s?s.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:s.temporal,spatial:l.spatial}:s:null,p={type:"BoxSelector",spatial:{x:0,y:0,width:t.width,height:t.height}},d=o.resource.type==="SpecificResource"?D(o.resource):null,v=d&&d.selector&&(d.selector.type==="BoxSelector"||d.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:d.selector.spatial.x,y:d.selector.spatial.y,width:d.selector.spatial.width,height:d.selector.spatial.height}}:p,c={id:i.id,type:"Image",width:f?i.width:t.width,height:f?i.height:t.height,service:a,sizes:a&&a.sizes?a.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:f&&f.type!=="PointSelector"?f:l,selector:v};n.push(c)}return{type:"images",image:n[0],images:n,choice:e.choice}}var so=Object.defineProperty,co=Object.defineProperties,uo=Object.getOwnPropertyDescriptors,Gt=Object.getOwnPropertySymbols,lo=Object.prototype.hasOwnProperty,fo=Object.prototype.propertyIsEnumerable,Kt=(t,e,r)=>e in t?so(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ho=(t,e)=>{for(var r in e||(e={}))lo.call(e,r)&&Kt(t,r,e[r]);if(Gt)for(var r of Gt(e))fo.call(e,r)&&Kt(t,r,e[r]);return t},po=(t,e)=>co(t,uo(e));function vo(t={},e=[]){const{id:r,selector:n}=t,o=Q(),i=E(),a=r||o.annotation,s=M(l=>a?l.iiif.entities.Annotation[a]:void 0,[a]),u=M(l=>s&&s.body?s.body.map(f=>f?l.iiif.entities[f.type][f.id]:null).filter(Boolean):[],[s]);return m.useMemo(()=>{if(!s)return;const l=po(ho({},s),{body:u,target:D(s.target,{typeMap:i.getState().iiif.mapping})});return n?n(l):l},[s,n,u,...e])}function le(t={},e=[]){const{id:r,selector:n}=t,o=Q();E();const i=r||o.manifest,a=M(s=>i?s.iiif.entities.Manifest[i]:void 0,[i]);return m.useMemo(()=>{if(!!a)return n?n(a):a},[a,n,...e])}function Y(t={},e=[]){const{id:r,selector:n}=t,o=Q(),i=r||o.canvas,a=M(s=>i?s.iiif.entities.Canvas[i]:void 0,[i]);return m.useMemo(()=>{if(!!a)return n?n(a):a},[a,n,...e])}function mo(t,e){var r;const n=(r=t==null?void 0:t.iiif)==null?void 0:r.meta[e];return n?n.annotationPageManager:null}function go(t,e){return M(r=>{const n=[];if(!t)return n;const o=Object.keys(r.iiif.entities.AnnotationPage);for(const i of o)if(!e||e.indexOf(i)!==-1){const a=mo(r,i);a&&a.views&&a.views[t]&&n.push(i)}return n},[t])}function Yt({canvas:t,manifest:e,all:r,canvases:n}){const o=[];if(e)for(const i of e.annotations)o.indexOf(i.id)===-1&&o.push(i.id);if(r){if(n&&n.length)for(const i of n)for(const a of i.annotations)o.indexOf(a.id)===-1&&o.push(a.id)}else if(t)for(const i of t.annotations)o.indexOf(i.id)===-1&&o.push(i.id);return o}var yo=Object.defineProperty,wo=Object.defineProperties,bo=Object.getOwnPropertyDescriptors,Jt=Object.getOwnPropertySymbols,So=Object.prototype.hasOwnProperty,xo=Object.prototype.propertyIsEnumerable,Zt=(t,e,r)=>e in t?yo(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Xt=(t,e)=>{for(var r in e||(e={}))So.call(e,r)&&Zt(t,r,e[r]);if(Jt)for(var r of Jt(e))xo.call(e,r)&&Zt(t,r,e[r]);return t},er=(t,e)=>wo(t,bo(e));function Oo(t,e){var r;const n=(r=t==null?void 0:t.iiif)==null?void 0:r.meta[e];return n?n.annotationPageManager:null}function tr(t,e={}){const r=E(),n=le(),o=Y(),i=ut(),a=m.useMemo(()=>Yt({all:e.all,manifest:n,canvas:o,canvases:i}),[e.all,o,i,n]),s=go(t,e.all?void 0:a),u=m.useCallback(f=>{!t||r.setMetaValue([f,"annotationPageManager","views"],p=>p&&!p[t]?p:er(Xt({},p||{}),{[t]:!1}))},[t,r]),l=m.useCallback((f,p={})=>{if(!t)return;const d=r.getState(),v=[];if(p==null?void 0:p.deselectOthers){const c=Object.keys(d.iiif.entities.AnnotationPage);for(const g of c){const x=Oo(d,g);x&&x.views&&x.views[t]&&v.push(g)}}for(const c of v)u(c);r.setMetaValue([f,"annotationPageManager","views"],c=>c&&c[t]?c:er(Xt({},c||{}),{[t]:!0}))},[t,u,r]);return{availablePageIds:a,enabledPageIds:s,setPageEnabled:l,setPageDisabled:u}}function ge(t={}){const e=Y(t.canvasId?{id:t.canvasId}:void 0);return M((r,n)=>{if(!e)return[];const o=n.get(e.items),i=[];for(const a of o)i.push(...n.get(a.items));return i},[e])}function Co(t,e={}){return ge(e)}function Ao(t,e=!1){}function Po(t,e=[]){const{id:r,selector:n}=t,o=Q(),i=r||o.collection,a=M(s=>i?s.iiif.entities.Collection[i]:void 0,[i]);return m.useMemo(()=>{if(!!a)return n?n(a):a},[a,n,...e])}function rr(){const e=E().getStore();return m.useMemo(()=>r=>e.dispatch(r),[e])}function nr(t){return{addEventListener(e,r,n,o){if(e)return t.setMetaValue([e.id,"eventManager",r],i=>{const a=i||[];for(const s of a)if(s.callback===n)return a;return[...a,{callback:n,scope:o}]}),n},removeEventListener(e,r,n){!e||t.setMetaValue([e.id,"eventManager",r],o=>(o||[]).filter(i=>i.callback!==n))},getListenersAsProps(e,r){const n=typeof e=="string"?{id:e}:e;if(!n||!n.id)return{};const o=t.getResourceMeta(n.id,"eventManager"),i={};if(o&&n)for(const a of Object.keys(o))i[a]=s=>{const u=t.get(n);for(const{callback:l,scope:f}of o[a]||[])(!f||r&&f.indexOf(r)!==-1)&&l(s,u)};return i}}}function ir(t){return{applyStyles(e,r,n){const o=typeof e=="string"?e:e.id;return t.setMetaValue([o,"styles",r],n)},getAppliedStyles(e){const r=typeof e=="string"?e:e.id;return t.getResourceMeta(r,"styles")}}}function J(t){return t.endsWith("info.json")?t:t.endsWith("/")?`${t}info.json`:`${t}/info.json`}function Io(t,e,r){const n=r.length,o=[];for(let i=0;i<n;i++){const a=r[i].width;o.push(t/a)}return o}function $o(t,e,r){const n=r.length,o=[];for(let i=0;i<n;i++){const a=r[i];o.push({width:Math.floor(t/a),height:Math.floor(e/a)})}return o}const _o="http://library.stanford.edu/iiif/image-api/compliance.html#level0",or="http://library.stanford.edu/iiif/image-api/compliance.html#level1",ar="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Eo="http://library.stanford.edu/iiif/image-api/conformance.html#level0",sr="http://library.stanford.edu/iiif/image-api/conformance.html#level1",cr="http://library.stanford.edu/iiif/image-api/conformance.html#level2",jo="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",ur="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",lr="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",To="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",fr="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",hr="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Mo="http://iiif.io/api/image/1/level0.json",Fo="http://iiif.io/api/image/1/profiles/level0.json",dr="http://iiif.io/api/image/1/level1.json",pr="http://iiif.io/api/image/1/profiles/level1.json",vr="http://iiif.io/api/image/1/level2.json",mr="http://iiif.io/api/image/1/profiles/level2.json",Lo="http://iiif.io/api/image/2/level0.json",ko="http://iiif.io/api/image/2/profiles/level0.json",gr="http://iiif.io/api/image/2/level1.json",yr="http://iiif.io/api/image/2/profiles/level1.json",wr="http://iiif.io/api/image/2/level2.json",br="http://iiif.io/api/image/2/profiles/level2.json",Ro="level0",Sr="level1",xr="level2",qo="http://iiif.io/api/image/2/level0",Or="http://iiif.io/api/image/2/level1",Cr="http://iiif.io/api/image/2/level2",Wo=[Or,Cr,or,ar,sr,cr,ur,lr,fr,hr,dr,pr,vr,mr,gr,yr,wr,br,Sr,xr],Do=[qo,Or,Cr,_o,or,ar,Eo,sr,cr,jo,ur,lr,To,fr,hr,Mo,Fo,dr,pr,vr,mr,Lo,ko,gr,yr,wr,br,Ro,Sr,xr];function _(t){if(t["@id"])return t["@id"];if(t.id)return t.id}function Ee(t){if(!t||!t.profile||!_(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const r of e)if(typeof r=="string"&&Do.indexOf(r)!==-1)return!0;return!1}function Vo(t){if(!Ee(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const r of e)if(typeof r=="string"){if(Wo.indexOf(r)!==-1)return!0}else{const n=r.supports||[];if(n.indexOf("regionByPx")!==-1&&(n.indexOf("sizeByW")!==-1||n.indexOf("sizeByWh")!==-1))return!0}return!1}function Qo(t){if(!Vo(t))return[];const e=[],r=Array.isArray(t.profile)?t.profile:[t.profile],n=r.length;for(let o=0;o<n;o++){const i=r[o];if(typeof i!="string"&&(i.maxHeight||i.maxWidth))return[{id:_(t),type:"variable",minWidth:0,minHeight:0,maxHeight:i.maxHeight||i.maxWidth,maxWidth:i.maxWidth||i.maxHeight}]}if(t.tiles){const o=t.tiles.length;for(let i=0;i<o;i++){const a=t.tiles[i];(a.height||a.width)&&e.push({id:_(t),type:"variable",minHeight:0,minWidth:0,maxHeight:a.height||a.width,maxWidth:a.width})}}return e}function Ar(t){const e=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,r=t.match(e);if(r){const n=r[1],o=parseInt(r[4],10),i=parseInt(r[5],10),a=r[7];if((n==="max"||n==="full")&&o&&i&&a)return{type:"fixed",id:t,height:i,width:o}}return{type:"unknown",id:t}}function zo(t){if(t["@type"])return t["@type"];if(t.type)return t.type}function je(t){if(typeof t=="string")return Ar(t);const e=zo(t);if(e!=="Image"&&e!=="sc:Image")return null;const r=t,n=_(r);return n?n&&r.width&&r.height?{id:n,type:"fixed",width:r.width,height:r.height,unsafe:!0}:Ar(n):null}function Bo(t){return Ee(t)?(t&&t.sizes?t.sizes:[]).map(e=>({id:_(t),type:"fixed-service",height:e.height,width:e.width})):[]}function Pr(t){const e=[],r=t.length;for(let n=0;n<r;n++){const o=Bo(t[n]);o.length&&e.push(...o);const i=Qo(t[n]);i.length&&e.push(...i)}return e}function Ir(t){const e=t.service?Array.isArray(t.service)?t.service:[t.service]:[],r=e.length,n=[];for(let o=0;o<r;o++)Ee(e[o])&&n.push(e[o]);return n}function Ho(t,e=!0,r){const n=[],o=je(t);if(o===null)return n;const i=t;if(n.push(o),e&&i.width&&i.height){const a=[],s=Ir(i);for(const u of s){const l={id:_(u),width:i.width,height:i.height};if(r.canLoadSync(l)){const f=r.loadServiceSync(l);f&&(f.height||(f.height=i.height),f.width||(f.width=i.width),a.push(...Pr([f])))}}if(a.length)return n.push(...a),n}return i.service&&n.push(...Pr(i.service)),n}function Te(t,e,r){return{id:[J(_(t)).slice(0,-10),"full",[e,r||""].join(","),0,"default.jpg"].join("/"),type:"fixed",width:e,height:r||t.height/t.width*e,unsafe:t.width>e}}function Z(t){const e=t.replace(/(https?:\/\/)?(www.)?/i,"");return e.indexOf("/")!==-1?e.split("/")[0]:e}function Uo(t,e,r){const n=t.width?t.width:t.maxWidth;return r.height<=t.maxHeight&&r.width<=t.maxWidth&&r.height>=t.minHeight&&r.width>=t.minWidth&&(!e||Math.abs(r.width-n)<Math.abs(e.width-n))}function No(t,e){const r=[],n=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},t),o=[],i=[];let a=null;const s=(l,f)=>{if(Uo(n,f,l)){if(n.preferFixedSize&&l.unsafe){i.push(l);return}n.returnAllOptions&&f&&i.push(f),a=l}else n.returnAllOptions&&i.push(l)},u=e.length;for(let l=0;l<u;l++){const f=e[l](),p=f.length;for(let d=0;d<p;d++){const v=f[d];if(v.type==="unknown"&&n.atAnyCost&&o.push(v),v.type==="fixed"&&(v.unsafe?o.push(v):s(v,a)),v.type==="fixed-service")if(n.unsafeImageService){const c=Te(v,n.width,n.height);s(c,a)}else{const c=Te(v,v.width,v.height);s(c,a)}if(v.type==="variable"&&v.maxWidth){const c=Te({id:v.id,type:"fixed-service",width:v.maxWidth,height:v.maxWidth},v.maxWidth);s(c,a)}}if(a&&!n.returnAllOptions){if(a.unsafe||n.allowUnsafe)continue;break}}return n.atAnyCost&&i.length===0?{best:a||o[0],fallback:o.slice(1),log:r}:n.returnAllOptions?{best:n.atAnyCost?a||i[0]||o[0]:a||i[0],fallback:[...i,...o],log:r}:{best:a||i[0]||null,fallback:a?i:i.slice(1),log:r}}function Go(t,e,r){const n=t>e?t:e,o=r.length,i=[];for(let a=0;a<o;a++){const s=r[a];let u=s.scaleFactors[0],l=n/u;const f=[u];for(;l>=s.width;)u=u*2,f.push(u),l=l/2;i.push(Object.assign(Object.assign({},s),{scaleFactors:f}))}return i}function Ko(t,e){if(t.length!==e.length)return!1;if(t.length===0&&e.length===0)return!0;const r=t.length;let n=!0;for(let i=0;i<r;i++){const a=t[i],s=e[i];if(a.width!==s.width||a.height!==s.height){n=!1;break}}if(n)return!0;let o=0;for(let i=0;i<r;i++)for(let a=0;a<r;a++)if(t[i].width===e[a].width&&t[i].height===e[a].height){o++;break}return o===r}/*! *****************************************************************************
|
|
2
2
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
3
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
4
4
|
this file except in compliance with the License. You may obtain a copy of the
|