react-iiif-vault 0.9.4 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/index.d.ts +38 -8
- package/dist/index.umd.js +2 -2
- package/package.json +15 -15
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)},!1),t),r}const R=g.default.createContext([]);function te(){const e=u.useContext(R);return P(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}const D=()=>{},M=u.createContext({setCurrentCanvasId:D,setCurrentCanvasIndex:D,nextCanvas:D,previousCanvas:D,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),Xe=e=>{const t=ee(e.manifest),[n,r]=u.useState(""),[c,i]=u.useState([]),a=(typeof e.pagingEnabled>"u"||e.pagingEnabled)&&t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");u.useEffect(()=>{var f,m;t.manifest&&(r((f=t.manifest.items[0])==null?void 0:f.id),i([(m=t.manifest.items[0])==null?void 0:m.id]))},[t.manifest,e.manifest]);const o=u.useMemo(()=>{var f;return((f=t.manifest)==null?void 0:f.items.map(m=>m.id))||[]},[t.manifest,e.manifest]),s=u.useMemo(()=>o.indexOf(n),[o,n]),l=u.useCallback(()=>{if(o.length&&n){if(s===-1||(o[s+2]?s+2===o.length:s===o.length))return;const f=a&&s!==0?o[s+2]:o[s+1],m=a?s!==0?o[s+3]:o[s+2]:null;f&&(r(f),i(m?[f,m]:[f]))}},[a,o,n,s]),p=u.useCallback(()=>{if(o.length&&n){if(s===0||s===-1)return;const f=a&&s!==1?o[s-2]:o[s-1],m=a&&s!==1?o[s-1]:null;f&&(r(f),i(m?[f,m]:[f]))}},[a,o,n,s]),d=u.useCallback(f=>{const m=a&&f%2===1?f-1:f,w=o[m],q=a&&m!==0?o[m+1]:null;w&&(r(w),i(I=>{const U=q?[w,q]:[w];if(I.length===I.length){for(let V=0;V<I.length;V++)if(I[V]!==U[V])return U;return I}return U}))},[a,o]),v=u.useCallback(f=>{const m=o.indexOf(f);m!==-1&&d(m)},[o,d]),_=u.useMemo(()=>({setCurrentCanvasId:v,nextCanvas:l,previousCanvas:p,currentCanvasIndex:s,totalCanvases:o.length,setCurrentCanvasIndex:d,pagingView:!0}),[l,p,s,o,d,v]);return!t.isLoaded||!t.manifest?g.default.createElement("div",null,"Loading..."):g.default.createElement(M.Provider,{value:_},g.default.createElement(R.Provider,{value:c},g.default.createElement(X,{manifest:t.manifest.id},g.default.createElement(G,{canvas:n},e.children))))};function Je(){return u.useContext(M)}function Ke(){return{VaultContext:u.useContext(A),ResourceContext:u.useContext(j),SimpleViewerReactContext:u.useContext(M),VisibleCanvasReactContext:u.useContext(R)}}const Ze=e=>g.default.createElement(J,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},g.default.createElement(R.Provider,{value:e.bridge.VisibleCanvasReactContext},g.default.createElement(M.Provider,{value:e.bridge.SimpleViewerReactContext},e.children))),ne=g.default.createContext(new L.ImageServiceLoader);function F(){return u.useContext(ne)}const et=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,tt=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function N(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:r,selectors:c}=N(n);return r&&(t.selector||(t.selector=r),t.selectors.push(...c)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,n]=e.split("#");return n?N({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=et.exec(e.value);if(t){const r={type:"BoxSelector",spatial:{unit:t[2]==="percent:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:r,selectors:[r]}}const n=e.value.match(tt);if(n){const r={type:"TemporalSelector",temporal:{startTime:n[4]?parseFloat(n[4]):0,endTime:n[7]?parseFloat(n[7]):void 0}};return{selector:r,selectors:[r]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}var nt=Object.defineProperty,rt=Object.defineProperties,ot=Object.getOwnPropertyDescriptors,re=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,at=Object.prototype.propertyIsEnumerable,oe=(e,t,n)=>t in e?nt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ie=(e,t)=>{for(var n in t||(t={}))it.call(t,n)&&oe(e,n,t[n]);if(re)for(var n of re(t))at.call(t,n)&&oe(e,n,t[n]);return e},ae=(e,t)=>rt(e,ot(t));function O(e,t={}){if(Array.isArray(e))return O(e[0]);if(typeof e=="string"){const[n,r]=e.split("#");return r?O({type:"SpecificResource",source:{id:n,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return O(e.items[0]);if(e.type==="SpecificResource"){e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]);const{selector:n,selectors:r}=e.selector?N(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:n,selectors:r}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[n,r]=e.id.split("#");return r?O({type:"SpecificResource",source:ae(ie({},e),{id:n}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:ae(ie({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function se(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function ce(e,t,n){const r=[];let c=null;const i=[];for(const a of t){const o=e.get(a.body);for(const s of o){const[l,{selector:p}]=se(s),d=(l.type||"unknown").toLowerCase();if(d==="choice"){const v=e.get(l.items),_=n.length?n.map(f=>v.find(m=>m.id===f)).filter(Boolean):[v[0]];_.length===0&&_.push(v[0]),c={type:"single-choice",items:v.map(f=>({id:f.id,label:f.label,selected:_.indexOf(f)!==-1})),label:s.label},o.push(..._);continue}r.indexOf(d)===-1&&r.push(d),i.push({type:d,resource:l,target:a.target,selector:p})}}return{types:r,items:i,choice:c}}const ue={makeChoice:()=>{}},H={type:"unknown"},S=e=>({type:"unknown",reason:e,annotations:{pages:[]}});function le(e,t,n){const r=[];for(const c of t.items){const i=c.resource&&c.resource.type==="SpecificResource"?c.resource.source:c.resource;if(!i.id)return S("No resource Identifier");let a;if(i.service){const m=L.getImageServices(i);m[0]&&(a=n(m[0],e))}const{selector:o,source:s}=O(c.target);if(s.id!==e.id)continue;const l={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},p=o?o.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:o.temporal,spatial:l.spatial}:o:null,d={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},v=c.resource.type==="SpecificResource"?O(c.resource):null,_=v&&v.selector&&(v.selector.type==="BoxSelector"||v.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:v.selector.spatial.x,y:v.selector.spatial.y,width:v.selector.spatial.width,height:v.selector.spatial.height}}:d,f={id:i.id,type:"Image",width:p?i.width:e.width,height:p?i.height:e.height,service:a,sizes:a&&a.sizes?a.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:p&&p.type!=="PointSelector"?p:l,selector:_};r.push(f)}return{type:"images",image:r[0],images:r,choice:t.choice}}var st=Object.defineProperty,ct=Object.defineProperties,ut=Object.getOwnPropertyDescriptors,fe=Object.getOwnPropertySymbols,lt=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable,de=(e,t,n)=>t in e?st(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,dt=(e,t)=>{for(var n in t||(t={}))lt.call(t,n)&&de(e,n,t[n]);if(fe)for(var n of fe(t))ft.call(t,n)&&de(e,n,t[n]);return e},pt=(e,t)=>ct(e,ut(t));function vt(e={},t=[]){const{id:n,selector:r}=e,c=C(),i=y(),a=n||c.annotation,o=P(l=>a?l.iiif.entities.Annotation[a]:void 0,[a]),s=P(l=>o&&o.body?o.body.map(p=>p?l.iiif.entities[p.type][p.id]:null).filter(Boolean):[],[o]);return u.useMemo(()=>{if(!o)return;const l=pt(dt({},o),{body:s,target:O(o.target,{typeMap:i.getState().iiif.mapping})});return r?r(l):l},[o,r,s,...t])}function $(e={},t=[]){const{id:n,selector:r}=e,c=C();y();const i=n||c.manifest,a=P(o=>i?o.iiif.entities.Manifest[i]:void 0,[i]);return u.useMemo(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function x(e={},t=[]){const{id:n,selector:r}=e,c=C(),i=n||c.canvas,a=P(o=>i?o.iiif.entities.Canvas[i]:void 0,[i]);return u.useMemo(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function mt(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function gt(e,t){return P(n=>{const r=[];if(!e)return r;const c=Object.keys(n.iiif.entities.AnnotationPage);for(const i of c)if(!t||t.indexOf(i)!==-1){const a=mt(n,i);a&&a.views&&a.views[e]&&r.push(i)}return r},[e])}function pe({canvas:e,manifest:t,all:n,canvases:r}){const c=[];if(t)for(const i of t.annotations)c.indexOf(i.id)===-1&&c.push(i.id);if(n){if(r&&r.length)for(const i of r)for(const a of i.annotations)c.indexOf(a.id)===-1&&c.push(a.id)}else if(e)for(const i of e.annotations)c.indexOf(i.id)===-1&&c.push(i.id);return c}var yt=Object.defineProperty,ht=Object.defineProperties,_t=Object.getOwnPropertyDescriptors,ve=Object.getOwnPropertySymbols,Pt=Object.prototype.hasOwnProperty,St=Object.prototype.propertyIsEnumerable,me=(e,t,n)=>t in e?yt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ge=(e,t)=>{for(var n in t||(t={}))Pt.call(t,n)&&me(e,n,t[n]);if(ve)for(var n of ve(t))St.call(t,n)&&me(e,n,t[n]);return e},ye=(e,t)=>ht(e,_t(t));function wt(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function he(e,t={}){const n=y(),r=$(),c=x(),i=te(),a=u.useMemo(()=>pe({all:t.all,manifest:r,canvas:c,canvases:i}),[t.all,c,i,r]),o=gt(e,t.all?void 0:a),s=u.useCallback(p=>{!e||n.setMetaValue([p,"annotationPageManager","views"],d=>d&&!d[e]?d:ye(ge({},d||{}),{[e]:!1}))},[e,n]),l=u.useCallback((p,d={})=>{if(!e)return;const v=n.getState(),_=[];if(d==null?void 0:d.deselectOthers){const f=Object.keys(v.iiif.entities.AnnotationPage);for(const m of f){const w=wt(v,m);w&&w.views&&w.views[e]&&_.push(m)}}for(const f of _)s(f);n.setMetaValue([p,"annotationPageManager","views"],f=>f&&f[e]?f:ye(ge({},f||{}),{[e]:!0}))},[e,s,n]);return{availablePageIds:a,enabledPageIds:o,setPageEnabled:l,setPageDisabled:s}}function B(e={}){const t=x(e.canvasId?{id:e.canvasId}:void 0);return P((n,r)=>{if(!t)return[];const c=r.get(t.items),i=[];for(const a of c)i.push(...r.get(a.items));return i},[t])}function Ot(e,t={}){return B(t)}function Ct(e,t=!1){}function Et(e,t=[]){const{id:n,selector:r}=e,c=C(),i=n||c.collection,a=P(o=>i?o.iiif.entities.Collection[i]:void 0,[i]);return u.useMemo(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function _e(){const t=y().getStore();return u.useMemo(()=>n=>t.dispatch(n),[t])}function xt(e,t,n,r,c=[]){const i=y(),a=u.useMemo(()=>b.createEventsHelper(i),[i]);u.useEffect(()=>{const o=e;return o?(a.addEventListener(o,t,n,r),()=>{a.removeEventListener(o,t,n)}):()=>{}},[a,e,t,...c])}function It(){const e=u.useContext(A);return e&&e.vault?e.vault:T.globalVault()}var bt=Object.defineProperty,Pe=Object.getOwnPropertySymbols,At=Object.prototype.hasOwnProperty,Rt=Object.prototype.propertyIsEnumerable,Se=(e,t,n)=>t in e?bt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Mt=(e,t)=>{for(var n in t||(t={}))At.call(t,n)&&Se(e,n,t[n]);if(Pe)for(var n of Pe(t))Rt.call(t,n)&&Se(e,n,t[n]);return e},$t=(e,t,n)=>new Promise((r,c)=>{var i=s=>{try{o(n.next(s))}catch(l){c(l)}},a=s=>{try{o(n.throw(s))}catch(l){c(l)}},o=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);o((n=n.apply(e,t)).next())});const Vt=(e,t={})=>{const n=y(),[r,c]=u.useState(e),i=u.useMemo(()=>n.get(e),[e,n]),{data:a,isFetching:o}=k.useQuery(`collection:${e}`,()=>$t(void 0,null,function*(){const s=i||(yield n.loadCollection(e));return s&&c(s.id),s}),Mt({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,initialData:i},t));return{isLoaded:!o,id:r,collection:a}};var Tt=(e,t,n)=>new Promise((r,c)=>{var i=s=>{try{o(n.next(s))}catch(l){c(l)}},a=s=>{try{o(n.throw(s))}catch(l){c(l)}},o=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);o((n=n.apply(e,t)).next())});function we(){const e=x(),t=B(),n=y(),r=F();return k.useQuery(`canvas-first-image-service:${e?e.id:"undefined"}`,()=>Tt(this,null,function*(){if(e&&t.length){const c=t[0],i=n.get(c.body[0]),o=L.getImageServices(i)[0];return o&&(yield r.loadService({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height}))||void 0}}),{refetchOnWindowFocus:!1,refetchOnMount:!1,refetchIntervalInBackground:!1,refetchInterval:!1,initialData:()=>{if(e&&t.length){const c=t[0],i=n.get(c.body[0]),o=L.getImageServices(i)[0];return o&&r.loadServiceSync({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height})||void 0}}})}function Lt(){const e=we();return{isLoading:e.isFetching,tile:e.data?{id:e.data.id||e.data["@id"],width:e.data.width,height:e.data.height,imageService:e.data,thumbnail:void 0}:null}}function Oe(e,t=[]){const n=y(),r=B(),[c,i]=u.useState((e==null?void 0:e.defaultChoices)||[]),a=u.useMemo(()=>ce(n,r,c),[n,r,c,...t]),s={makeChoice:u.useCallback((l,{deselectOthers:p=!0,deselect:d=!1}={})=>{if(a.choice){if(a.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");i(v=>{if(d){const f=v.filter(m=>m!==l);if(f.length===0){const m=a.items[0].resource.id;return m?[m]:[]}return f}if(p)return[l];const _=[...v];if(_.length===0&&a.items.length){const f=a.items[0].resource.id;f&&_.push(f)}return v.indexOf(l)!==-1?v:[...v,l]})}},[a.choice])};return[a,s]}function jt(e={},t=[]){const{id:n,selector:r}=e,c=C(),i=n||c.range,a=P(o=>i?o.iiif.entities.Range[i]:void 0,[i]);return u.useMemo(()=>{if(!!a)return r?r(a):a},[a,r,...t])}function Dt(e,t){const n=y(),r=u.useMemo(()=>b.createEventsHelper(n),[n]),c=P(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return u.useMemo(()=>e?r.getListenersAsProps(e,t):{},[c,e,n,t])}function Ce(e,t){return P((n,r)=>r.get(e.map(c=>({id:c,type:t}))),[e,t])}function Ft(){const e=$();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function Nt(){const e=y();return u.useMemo(()=>b.createStylesHelper(e),[e])}function Bt(e,t){const n=y(),r=u.useMemo(()=>b.createStylesHelper(n),[n]);return P(()=>{if(!e)return null;const c=r.getAppliedStyles(e.id);return c?t?c[t]:c:void 0},[e,t])}const Ee=(e,t=[])=>{const n=y();u.useEffect(()=>{e(n)},[n,...t])};function Ut(e,t,{canvasId:n,manifestId:r}={}){const c=y(),i=F(),a=u.useMemo(()=>b.createThumbnailHelper(c,{imageServiceLoader:i}),[c,i]),[o,s]=u.useState(),l=$(r?{id:r}:void 0),p=x(n?{id:n}:void 0),d=p||l,v=u.useRef(!1);if(u.useEffect(()=>()=>{v.current=!0},[]),!d)throw new Error("Must be called under a manifest or canvas context.");return Ee(_=>{a.getBestThumbnailAtSize(d,e,t).then(f=>{f.best&&!v.current&&s(f.best)})},[d]),o}var kt=Object.defineProperty,Ht=Object.defineProperties,Qt=Object.getOwnPropertyDescriptors,xe=Object.getOwnPropertySymbols,qt=Object.prototype.hasOwnProperty,zt=Object.prototype.propertyIsEnumerable,Ie=(e,t,n)=>t in e?kt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,be=(e,t)=>{for(var n in t||(t={}))qt.call(t,n)&&Ie(e,n,t[n]);if(xe)for(var n of xe(t))zt.call(t,n)&&Ie(e,n,t[n]);return e},Ae=(e,t)=>Ht(e,Qt(t));function Re(){const e=F(),[t,n]=u.useState({}),r=u.useRef(!1);return u.useEffect(()=>()=>{r.current=!0},[]),[u.useCallback((i,{height:a,width:o})=>{if(i){const s=i.id||i["@id"],l=e.loadServiceSync({id:s,width:i.width||o,height:i.height||a});l?i=l:t[s]||(r.current||n(p=>Ae(be({},p),{[s]:"loading"})),e.loadService({id:s,width:i.width||o,height:i.height||a}).then(()=>{r.current||n(p=>Ae(be({},p),{[s]:"done"}))}))}return i},[e,t]),t]}const Yt="@iiif/IMPORT_ENTITIES",Wt="@iiif/MODIFY_ENTITY_FIELD",Gt="@iiif/REORDER_ENTITY_FIELD",Xt="@iiif/ADD_REFERENCE",Jt="@iiif/REMOVE_REFERENCE",Kt=h.createAction(Yt)(),Zt=h.createAction(Wt)(),en=h.createAction(Gt)(),tn=h.createAction(Xt)(),nn=h.createAction(Jt)(),Q={importEntities:Kt,modifyEntityField:Zt,reorderEntityField:en,addReference:tn,removeReference:nn},rn="@iiif/ADD_MAPPING",on="@iiif/ADD_MAPPINGS";h.createAction(rn)(),h.createAction(on)();const an="@iiif/SET_META_VALUE",sn="@iiif/SET_META_VALUE_DYNAMIC",cn="@iiif/UNSET_META_VALUE";h.createAction(an)(),h.createAction(sn)(),h.createAction(cn)();const un="@iiif/REQUEST_RESOURCE",ln="@iiif/REQUEST_ERROR",fn="@iiif/REQUEST_MISMATCH",dn="@iiif/REQUEST_COMPLETE",pn="@iiif/REQUEST_OFFLINE_RESOURCE";h.createAction(un)(),h.createAction(ln)(),h.createAction(fn)(),h.createAction(dn)(),h.createAction(pn)();const vn="@iiif/BATCH";h.createAction(vn)();var mn=Object.defineProperty,gn=Object.defineProperties,yn=Object.getOwnPropertyDescriptors,Me=Object.getOwnPropertySymbols,hn=Object.prototype.hasOwnProperty,_n=Object.prototype.propertyIsEnumerable,$e=(e,t,n)=>t in e?mn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Pn=(e,t)=>{for(var n in t||(t={}))hn.call(t,n)&&$e(e,n,t[n]);if(Me)for(var n of Me(t))_n.call(t,n)&&$e(e,n,t[n]);return e},Sn=(e,t)=>gn(e,yn(t));function Ve(e){return typeof e!="string"&&e&&e.bindToVault}function wn(){const e=y(),t=u.useRef([]),n=_e(),r=u.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);u.useLayoutEffect(()=>{const o=Sn(Pn({},je.emptyAnnotationPage),{id:r,items:[]});n(Q.importEntities({entities:{AnnotationPage:{[o.id]:o}}}))},[r]);const c=P(o=>r?o.iiif.entities.AnnotationPage[r]:null,[r]),i=u.useCallback((o,s)=>{if(r){if(Ve(o)){const d=o;d.__vault||d.bindToVault(e),o=typeof d.source=="string"?d.source:d.source.id,t.current[o]=d}else typeof o!="string"&&(o=o.id);const l=e.get({id:r,type:"AnnotationPage"}),p=e.get({id:o,type:"Annotation"});l&&p&&(l.items.find(d=>d.id===p.id)||n(Q.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"},index:s})))}},[r]),a=u.useCallback(o=>{r&&(Ve(o)?o=typeof o.source=="string"?o.source:o.source.id:typeof o!="string"&&(o=o.id),t.current[o]&&t.current[o].beforeRemove(),e.get({id:r,type:"AnnotationPage"})&&n(Q.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"}})))},[r]);return[c,{addAnnotation:i,removeAnnotation:a}]}var On=Object.defineProperty,Cn=Object.defineProperties,En=Object.getOwnPropertyDescriptors,Te=Object.getOwnPropertySymbols,xn=Object.prototype.hasOwnProperty,In=Object.prototype.propertyIsEnumerable,Le=(e,t,n)=>t in e?On(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,bn=(e,t)=>{for(var n in t||(t={}))xn.call(t,n)&&Le(e,n,t[n]);if(Te)for(var n of Te(t))In.call(t,n)&&Le(e,n,t[n]);return e},An=(e,t)=>Cn(e,En(t));function Rn(e){const t=$(),n=x(),r=y(),[c,i]=Re(),{enabledPageIds:a}=he((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id),{all:!1}),o=Ce(a,"AnnotationPage"),s=(e==null?void 0:e.strategies)||["images","media","complex-timeline"],[l,p]=Oe(e,[i]),d=u.useMemo(()=>{if(!n||l.types.length===0)return H;if(l.types.length!==1)return s.indexOf("complex-timeline")===-1?S("Complex timeline not supported"):S("ComplexTimelineStrategy not yet supported");const v=l.types[0];return v==="image"?s.indexOf("images")===-1?S("Image not supported"):le(n,l,c):v==="audio"?s.indexOf("media")===-1?S("Media not supported"):S("Audio strategy not yet supported"):v==="video"?s.indexOf("media")===-1?S("Media not supported"):S("Video strategy not yet supported"):H},[n,l,r,p.makeChoice]);return u.useMemo(()=>d.type==="unknown"?[d,ue]:[An(bn({},d),{annotations:{pages:o}}),p],[d,o])}exports.AnnotationContext=ke,exports.CanvasContext=G,exports.CollectionContext=He,exports.ContextBridge=Ze,exports.ImageServiceLoaderContext=ne,exports.ManifestContext=X,exports.RangeContext=Qe,exports.ReactVaultContext=A,exports.ResourceProvider=E,exports.ResourceReactContext=j,exports.SimpleViewerProvider=Xe,exports.SimpleViewerReactContext=M,exports.VaultProvider=J,exports.VisibleCanvasReactContext=R,exports.emptyActions=ue,exports.expandTarget=O,exports.flattenAnnotationPageIds=pe,exports.getImageStrategy=le,exports.getPaintables=ce,exports.parseSelector=N,exports.parseSpecificResource=se,exports.unknownResponse=H,exports.unsupportedStrategy=S,exports.useAnnotation=vt,exports.useAnnotationPageManager=he,exports.useAnnotationsAtTime=Ot,exports.useCanvas=x,exports.useCanvasClock=Ct,exports.useCollection=Et,exports.useContextBridge=Ke,exports.useDispatch=_e,exports.useEventListener=xt,exports.useExistingVault=It,exports.useExternalCollection=Vt,exports.useExternalManifest=ee,exports.useImageService=we,exports.useImageServiceLoader=F,exports.useImageTile=Lt,exports.useLoadImageService=Re,exports.useManifest=$,exports.usePaintables=Oe,exports.usePaintingAnnotations=B,exports.useRange=jt,exports.useRenderingStrategy=Rn,exports.useResourceContext=C,exports.useResourceEvents=Dt,exports.useResources=Ce,exports.useSearchService=Ft,exports.useSimpleViewer=Je,exports.useStyleHelper=Nt,exports.useStyles=Bt,exports.useThumbnail=Ut,exports.useVault=y,exports.useVaultEffect=Ee,exports.useVaultSelector=P,exports.useVirtualAnnotationPage=wn,exports.useVisibleCanvases=te;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var u=require("react"),D=require("@iiif/vault"),j=require("@atlas-viewer/iiif-image-api"),M=require("@iiif/vault-helpers"),y=require("typesafe-actions");function Re(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var g=Re(u),Me=Object.defineProperty,z=Object.getOwnPropertySymbols,Te=Object.prototype.hasOwnProperty,Ve=Object.prototype.propertyIsEnumerable,Y=(e,t,n)=>t in e?Me(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,G=(e,t)=>{for(var n in t||(t={}))Te.call(t,n)&&Y(e,n,t[n]);if(z)for(var n of z(t))Ve.call(t,n)&&Y(e,n,t[n]);return e};const $e={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},F=g.default.createContext($e),b=()=>u.useContext(F),I=({value:e,children:t})=>{const n=b(),r=u.useMemo(()=>G(G({},n),e),[e,n]);return g.default.createElement(F.Provider,{value:r},t)},Le=({annotation:e,children:t})=>g.default.createElement(I,{value:{annotation:e}},t),X=({canvas:e,children:t})=>g.default.createElement(I,{value:{canvas:e}},t),De=({collection:e,children:t})=>g.default.createElement(I,{value:{collection:e}},t),J=({manifest:e,children:t})=>g.default.createElement(I,{value:{manifest:e}},t),je=({range:e,children:t})=>g.default.createElement(I,{value:{range:e}},t),T=g.default.createContext({vault:null,setVaultInstance:e=>{}}),W=({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:a})=>{const[i,s]=u.useState(()=>e||(n?D.globalVault(t):t?new D.Vault(t):new D.Vault));return g.default.createElement(T.Provider,{value:{vault:i,setVaultInstance:s}},g.default.createElement(I,{value:r||{}},a))},S=()=>{const{vault:e}=u.useContext(T);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var Fe=(e,t,n)=>new Promise((r,a)=>{var i=c=>{try{o(n.next(c))}catch(l){a(l)}},s=c=>{try{o(n.throw(c))}catch(l){a(l)}},o=c=>c.done?r(c.value):Promise.resolve(c.value).then(i,s);o((n=n.apply(e,t)).next())});function H(e,{noCache:t=!1}={}){const n=typeof e=="string"?e:e.id,r=S(),[a,i]=u.useState(n),[s,o]=u.useState(void 0),c=u.useMemo(()=>r.get(n,{skipSelfReturn:!0})||void 0,[n,r]),[l,p]=u.useState(c);return u.useEffect(()=>{Fe(this,null,function*(){try{const f=c&&!t?c:yield r.load(n),v=f?f.id||f["@id"]:null;f&&a!==v&&i(v),p(f)}catch(f){o(f)}})},[n,t]),{isLoaded:!!l,id:a,requestId:n,error:s,resource:l,cached:!!(l&&l===c)}}function Z(e,t){const{id:n,isLoaded:r,error:a,resource:i,requestId:s,cached:o}=H(e,t);return{id:n,isLoaded:r,error:a,manifest:i,requestId:s,cached:o}}function P(e,t=[]){const n=S(),[r,a]=u.useState(()=>e(n.getState(),n));return u.useEffect(()=>n.subscribe(i=>e(i,n),i=>{a(i)},!1),t),r}const V=g.default.createContext([]);function K(){const e=u.useContext(V);return P(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}const k=()=>{},$=u.createContext({setCurrentCanvasId:k,setCurrentCanvasIndex:k,nextCanvas:k,previousCanvas:k,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),ke=e=>{const t=Z(e.manifest),[n,r]=u.useState(""),[a,i]=u.useState([]),s=(typeof e.pagingEnabled>"u"||e.pagingEnabled)&&t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");u.useEffect(()=>{var d,m;t.manifest&&(r((d=t.manifest.items[0])==null?void 0:d.id),i([(m=t.manifest.items[0])==null?void 0:m.id]))},[t.manifest,e.manifest]);const o=u.useMemo(()=>{var d;return((d=t.manifest)==null?void 0:d.items.map(m=>m.id))||[]},[t.manifest,e.manifest]),c=u.useMemo(()=>o.indexOf(n),[o,n]),l=u.useCallback(()=>{if(o.length&&n){if(c===-1||(o[c+2]?c+2===o.length:c===o.length))return;const d=s&&c!==0?o[c+2]:o[c+1],m=s?c!==0?o[c+3]:o[c+2]:null;d&&(r(d),i(m?[d,m]:[d]))}},[s,o,n,c]),p=u.useCallback(()=>{if(o.length&&n){if(c===0||c===-1)return;const d=s&&c!==1?o[c-2]:o[c-1],m=s&&c!==1?o[c-1]:null;d&&(r(d),i(m?[d,m]:[d]))}},[s,o,n,c]),f=u.useCallback(d=>{const m=s&&d%2===1?d-1:d,_=o[m],A=s&&m!==0?o[m+1]:null;_&&(r(_),i(O=>{const C=A?[_,A]:[_];if(O.length===O.length){for(let w=0;w<O.length;w++)if(O[w]!==C[w])return C;return O}return C}))},[s,o]),v=u.useCallback(d=>{const m=o.indexOf(d);m!==-1&&f(m)},[o,f]),h=u.useMemo(()=>({setCurrentCanvasId:v,nextCanvas:l,previousCanvas:p,currentCanvasIndex:c,totalCanvases:o.length,setCurrentCanvasIndex:f,pagingView:!0}),[l,p,c,o,f,v]);return t.manifest?t.isLoaded?g.default.createElement($.Provider,{value:h},g.default.createElement(V.Provider,{value:a},g.default.createElement(J,{manifest:t.manifest.id},g.default.createElement(X,{canvas:n},e.children)))):g.default.createElement("div",null,"Loading..."):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),g.default.createElement("div",null,"Sorry, something went wrong."))};function Be(){return u.useContext($)}function Ne(){return{VaultContext:u.useContext(T),ResourceContext:u.useContext(F),SimpleViewerReactContext:u.useContext($),VisibleCanvasReactContext:u.useContext(V)}}const Ue=e=>g.default.createElement(W,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},g.default.createElement(V.Provider,{value:e.bridge.VisibleCanvasReactContext},g.default.createElement($.Provider,{value:e.bridge.SimpleViewerReactContext},e.children))),ee=g.default.createContext(new j.ImageServiceLoader);function B(){return u.useContext(ee)}const He=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,qe=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function N(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:r,selectors:a}=N(n);return r&&(t.selector||(t.selector=r),t.selectors.push(...a)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,n]=e.split("#");return n?N({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=He.exec(e.value);if(t){const r={type:"BoxSelector",spatial:{unit:t[2]==="percent:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:r,selectors:[r]}}const n=e.value.match(qe);if(n){const r={type:"TemporalSelector",temporal:{startTime:n[4]?parseFloat(n[4]):0,endTime:n[7]?parseFloat(n[7]):void 0}};return{selector:r,selectors:[r]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}var Qe=Object.defineProperty,ze=Object.defineProperties,Ye=Object.getOwnPropertyDescriptors,te=Object.getOwnPropertySymbols,Ge=Object.prototype.hasOwnProperty,Xe=Object.prototype.propertyIsEnumerable,ne=(e,t,n)=>t in e?Qe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,re=(e,t)=>{for(var n in t||(t={}))Ge.call(t,n)&&ne(e,n,t[n]);if(te)for(var n of te(t))Xe.call(t,n)&&ne(e,n,t[n]);return e},oe=(e,t)=>ze(e,Ye(t));function x(e,t={}){if(Array.isArray(e))return x(e[0]);if(typeof e=="string"){const[n,r]=e.split("#");return r?x({type:"SpecificResource",source:{id:n,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return x(e.items[0]);if(e.type==="SpecificResource"){e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]);const{selector:n,selectors:r}=e.selector?N(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:n,selectors:r}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[n,r]=e.id.split("#");return r?x({type:"SpecificResource",source:oe(re({},e),{id:n}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:oe(re({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function ie(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function se(e,t,n){const r=[];let a=null;const i=[];for(const s of t){const o=e.get(s.body);for(const c of o){const[l,{selector:p}]=ie(c),f=(l.type||"unknown").toLowerCase();if(f==="choice"){const v=e.get(l.items),h=n.length?n.map(d=>v.find(m=>m.id===d)).filter(Boolean):[v[0]];h.length===0&&h.push(v[0]),a={type:"single-choice",items:v.map(d=>({id:d.id,label:d.label,selected:h.indexOf(d)!==-1})),label:c.label},o.push(...h);continue}r.indexOf(f)===-1&&r.push(f),i.push({type:f,resource:l,target:s.target,selector:p})}}return{types:r,items:i,choice:a}}const ae={makeChoice:()=>{}},q={type:"unknown"},E=e=>({type:"unknown",reason:e,annotations:{pages:[]}});function ce(e,t,n){const r=[];for(const a of t.items){const i=a.resource&&a.resource.type==="SpecificResource"?a.resource.source:a.resource;if(!i.id)return E("No resource Identifier");let s;if(i.service){const m=j.getImageServices(i);m[0]&&(s=n(m[0],e))}const{selector:o,source:c}=x(a.target);if(c.id!==e.id)continue;const l={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},p=o?o.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:o.temporal,spatial:l.spatial}:o:null,f={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},v=a.resource.type==="SpecificResource"?x(a.resource):null,h=v&&v.selector&&(v.selector.type==="BoxSelector"||v.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:v.selector.spatial.x,y:v.selector.spatial.y,width:v.selector.spatial.width,height:v.selector.spatial.height}}:f,d={id:i.id,type:"Image",width:p?i.width:e.width,height:p?i.height:e.height,service:s,sizes:s&&s.sizes?s.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:p&&p.type!=="PointSelector"?p:l,selector:h};r.push(d)}return{type:"images",image:r[0],images:r,choice:t.choice}}var Je=Object.defineProperty,We=Object.defineProperties,Ze=Object.getOwnPropertyDescriptors,ue=Object.getOwnPropertySymbols,Ke=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable,le=(e,t,n)=>t in e?Je(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,tt=(e,t)=>{for(var n in t||(t={}))Ke.call(t,n)&&le(e,n,t[n]);if(ue)for(var n of ue(t))et.call(t,n)&&le(e,n,t[n]);return e},nt=(e,t)=>We(e,Ze(t));function rt(e={},t=[]){const{id:n,selector:r}=e,a=b(),i=S(),s=n||a.annotation,o=P(l=>s?l.iiif.entities.Annotation[s]:void 0,[s]),c=P(l=>o&&o.body?o.body.map(p=>p?l.iiif.entities[p.type][p.id]:null).filter(Boolean):[],[o]);return u.useMemo(()=>{if(!o)return;const l=nt(tt({},o),{body:c,target:x(o.target,{typeMap:i.getState().iiif.mapping})});return r?r(l):l},[o,r,c,...t])}function L(e={},t=[]){const{id:n,selector:r}=e,a=b();S();const i=n||a.manifest,s=P(o=>i?o.iiif.entities.Manifest[i]:void 0,[i]);return u.useMemo(()=>{if(!!s)return r?r(s):s},[s,r,...t])}function R(e={},t=[]){const{id:n,selector:r}=e,a=b(),i=n||a.canvas,s=P(o=>i?o.iiif.entities.Canvas[i]:void 0,[i]);return u.useMemo(()=>{if(!!s)return r?r(s):s},[s,r,...t])}function ot(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function it(e,t){return P(n=>{const r=[];if(!e)return r;const a=Object.keys(n.iiif.entities.AnnotationPage);for(const i of a)if(!t||t.indexOf(i)!==-1){const s=ot(n,i);s&&s.views&&s.views[e]&&r.push(i)}return r},[e,t])}function fe({canvas:e,manifest:t,all:n,canvases:r}){const a=[];if(t)for(const i of t.annotations)a.indexOf(i.id)===-1&&a.push(i.id);if(n){if(r&&r.length)for(const i of r)for(const s of i.annotations)a.indexOf(s.id)===-1&&a.push(s.id)}else if(e)for(const i of e.annotations)a.indexOf(i.id)===-1&&a.push(i.id);return a}var st=Object.defineProperty,at=Object.defineProperties,ct=Object.getOwnPropertyDescriptors,de=Object.getOwnPropertySymbols,ut=Object.prototype.hasOwnProperty,lt=Object.prototype.propertyIsEnumerable,pe=(e,t,n)=>t in e?st(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ve=(e,t)=>{for(var n in t||(t={}))ut.call(t,n)&&pe(e,n,t[n]);if(de)for(var n of de(t))lt.call(t,n)&&pe(e,n,t[n]);return e},me=(e,t)=>at(e,ct(t));function ft(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function ge(e,t={}){const n=S(),r=L(),a=R(),i=K(),s=u.useMemo(()=>fe({all:t.all,manifest:r,canvas:a,canvases:i}),[t.all,a,i,r]),o=it(e,t.all?void 0:s),c=u.useCallback(p=>{!e||n.setMetaValue([p,"annotationPageManager","views"],f=>f&&!f[e]?f:me(ve({},f||{}),{[e]:!1}))},[e,n]),l=u.useCallback((p,f={})=>{if(!e)return;const v=n.getState(),h=[];if(f==null?void 0:f.deselectOthers){const d=Object.keys(v.iiif.entities.AnnotationPage);for(const m of d){const _=ft(v,m);_&&_.views&&_.views[e]&&h.push(m)}}for(const d of h)c(d);n.setMetaValue([p,"annotationPageManager","views"],d=>d&&d[e]?d:me(ve({},d||{}),{[e]:!0}))},[e,c,n]);return{availablePageIds:s,enabledPageIds:o,setPageEnabled:l,setPageDisabled:c}}function U(e={}){const t=R(e.canvasId?{id:e.canvasId}:void 0);return P((n,r)=>{if(!t)return[];const a=r.get(t.items),i=[];for(const s of a)i.push(...r.get(s.items));return i},[t])}function dt(e,t={}){return U(t)}function pt(e,t=!1){}function vt(e,t=[]){const{id:n,selector:r}=e,a=b(),i=n||a.collection,s=P(o=>i?o.iiif.entities.Collection[i]:void 0,[i]);return u.useMemo(()=>{if(!!s)return r?r(s):s},[s,r,...t])}function he(){const t=S().getStore();return u.useMemo(()=>n=>t.dispatch(n),[t])}function mt(e,t,n,r,a=[]){const i=S(),s=u.useMemo(()=>M.createEventsHelper(i),[i]);u.useEffect(()=>{const o=e;return o?(s.addEventListener(o,t,n,r),()=>{s.removeEventListener(o,t,n)}):()=>{}},[s,e,t,...a])}function gt(){const e=u.useContext(T);return e&&e.vault?e.vault:D.globalVault()}function ht(e,t){const{id:n,isLoaded:r,error:a,resource:i,requestId:s,cached:o}=H(e,t);return{id:n,isLoaded:r,error:a,manifest:i,requestId:s,cached:o}}var yt=(e,t,n)=>new Promise((r,a)=>{var i=c=>{try{o(n.next(c))}catch(l){a(l)}},s=c=>{try{o(n.throw(c))}catch(l){a(l)}},o=c=>c.done?r(c.value):Promise.resolve(c.value).then(i,s);o((n=n.apply(e,t)).next())});function ye({cacheKey:e}={}){const t=R(),n=U(),r=S(),a=B(),[i,s]=u.useState(void 0),[o,c]=u.useState(!1),[l,p]=u.useState("idle"),[f,v]=u.useState(void 0),h=t?t.id:"undefined",d=u.useMemo(()=>{try{if(t&&n.length){const _=n[0],A=r.get(_.body[0]),C=j.getImageServices(A)[0];return C&&a.loadServiceSync({id:C.id||C["@id"],width:C.width||t.width,height:C.height||t.height})||void 0}}catch(_){console.error(_)}},[h,e,t]),m=l==="success"&&i?i:d;return u.useEffect(()=>{yt(this,null,function*(){try{if(t&&n.length){const _=n[0],A=r.get(_.body[0]),C=j.getImageServices(A)[0];if(!C)return;c(!0),p("loading");try{const w=(yield a.loadService({id:C.id||C["@id"],width:C.width||t.width,height:C.height||t.height}))||void 0;s(w),p("success"),c(!1)}catch(w){p("error"),v(w)}}}catch(_){p("error"),v(_)}})},[h,e]),u.useMemo(()=>({data:m,isFetching:o,status:l,error:f}),[m,o,l,f])}function St(){const e=ye();return{isLoading:e.isFetching,tile:e.data?{id:e.data.id||e.data["@id"],width:e.data.width,height:e.data.height,imageService:e.data,thumbnail:void 0}:null}}function Se(e,t=[]){const n=S(),r=U(),[a,i]=u.useState((e==null?void 0:e.defaultChoices)||[]),s=u.useMemo(()=>se(n,r,a),[n,r,a,...t]),c={makeChoice:u.useCallback((l,{deselectOthers:p=!0,deselect:f=!1}={})=>{if(s.choice){if(s.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");i(v=>{if(f){const d=v.filter(m=>m!==l);if(d.length===0){const m=s.items[0].resource.id;return m?[m]:[]}return d}if(p)return[l];const h=[...v];if(h.length===0&&s.items.length){const d=s.items[0].resource.id;d&&h.push(d)}return v.indexOf(l)!==-1?v:[...v,l]})}},[s.choice])};return[s,c]}function _t(e={},t=[]){const{id:n,selector:r}=e,a=b(),i=n||a.range,s=P(o=>i?o.iiif.entities.Range[i]:void 0,[i]);return u.useMemo(()=>{if(!!s)return r?r(s):s},[s,r,...t])}function Ct(e,t){const n=S(),r=u.useMemo(()=>M.createEventsHelper(n),[n]),a=P(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return u.useMemo(()=>e?r.getListenersAsProps(e,t):{},[a,e,n,t])}function _e(e,t){return P((n,r)=>r.get(e.map(a=>({id:a,type:t}))),[e,t])}function Pt(){const e=L();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function Et(){const e=S();return u.useMemo(()=>M.createStylesHelper(e),[e])}function wt(e,t){const n=S(),r=u.useMemo(()=>M.createStylesHelper(n),[n]);return P(()=>{if(!e)return null;const a=r.getAppliedStyles(e.id);return a?t?a[t]:a:void 0},[e,t])}const Ce=(e,t=[])=>{const n=S();u.useEffect(()=>{e(n)},[n,...t])};function xt(e,t,{canvasId:n,manifestId:r}={}){const a=S(),i=B(),s=u.useMemo(()=>M.createThumbnailHelper(a,{imageServiceLoader:i}),[a,i]),[o,c]=u.useState(),l=L(r?{id:r}:void 0),p=R(n?{id:n}:void 0),f=p||l,v=u.useRef(!1);if(u.useEffect(()=>()=>{v.current=!0},[]),!f)throw new Error("Must be called under a manifest or canvas context.");return Ce(h=>{s.getBestThumbnailAtSize(f,e,t).then(d=>{d.best&&!v.current&&c(d.best)})},[f]),o}var Ot=Object.defineProperty,bt=Object.defineProperties,It=Object.getOwnPropertyDescriptors,Pe=Object.getOwnPropertySymbols,At=Object.prototype.hasOwnProperty,Rt=Object.prototype.propertyIsEnumerable,Ee=(e,t,n)=>t in e?Ot(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,we=(e,t)=>{for(var n in t||(t={}))At.call(t,n)&&Ee(e,n,t[n]);if(Pe)for(var n of Pe(t))Rt.call(t,n)&&Ee(e,n,t[n]);return e},xe=(e,t)=>bt(e,It(t));function Oe(){const e=B(),[t,n]=u.useState({}),r=u.useRef(!1);return u.useEffect(()=>()=>{r.current=!0},[]),[u.useCallback((i,{height:s,width:o})=>{if(i){const c=i.id||i["@id"],l=e.loadServiceSync({id:c,width:i.width||o,height:i.height||s});l?i=l:t[c]||(r.current||n(p=>xe(we({},p),{[c]:"loading"})),e.loadService({id:c,width:i.width||o,height:i.height||s}).then(()=>{r.current||n(p=>xe(we({},p),{[c]:"done"}))}))}return i},[e,t]),t]}const Mt="@iiif/IMPORT_ENTITIES",Tt="@iiif/MODIFY_ENTITY_FIELD",Vt="@iiif/REORDER_ENTITY_FIELD",$t="@iiif/ADD_REFERENCE",Lt="@iiif/REMOVE_REFERENCE",Dt=y.createAction(Mt)(),jt=y.createAction(Tt)(),Ft=y.createAction(Vt)(),kt=y.createAction($t)(),Bt=y.createAction(Lt)(),Q={importEntities:Dt,modifyEntityField:jt,reorderEntityField:Ft,addReference:kt,removeReference:Bt},Nt="@iiif/ADD_MAPPING",Ut="@iiif/ADD_MAPPINGS";y.createAction(Nt)(),y.createAction(Ut)();const Ht="@iiif/SET_META_VALUE",qt="@iiif/SET_META_VALUE_DYNAMIC",Qt="@iiif/UNSET_META_VALUE";y.createAction(Ht)(),y.createAction(qt)(),y.createAction(Qt)();const zt="@iiif/REQUEST_RESOURCE",Yt="@iiif/REQUEST_ERROR",Gt="@iiif/REQUEST_MISMATCH",Xt="@iiif/REQUEST_COMPLETE",Jt="@iiif/REQUEST_OFFLINE_RESOURCE";y.createAction(zt)(),y.createAction(Yt)(),y.createAction(Gt)(),y.createAction(Xt)(),y.createAction(Jt)();const Wt="@iiif/BATCH",Zt="@iiif/BATCH_IMPORT";y.createAction(Wt)(),y.createAction(Zt)();function be(e){return typeof e!="string"&&e&&e.bindToVault}function Kt(){const e=S(),t=u.useRef([]),n=he(),r=u.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);u.useLayoutEffect(()=>{const o={id:r,type:"AnnotationPage",behavior:[],motivation:null,label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[]};n(Q.importEntities({entities:{AnnotationPage:{[o.id]:o}}}))},[r]);const a=P(o=>r?o.iiif.entities.AnnotationPage[r]:null,[r]),i=u.useCallback((o,c)=>{if(r){if(be(o)){const f=o;f.__vault||f.bindToVault(e),o=typeof f.source=="string"?f.source:f.source.id,t.current[o]=f}else typeof o!="string"&&(o=o.id);const l=e.get({id:r,type:"AnnotationPage"}),p=e.get({id:o,type:"Annotation"});l&&p&&(l.items.find(f=>f.id===p.id)||n(Q.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"},index:c})))}},[r]),s=u.useCallback(o=>{r&&(be(o)?o=typeof o.source=="string"?o.source:o.source.id:typeof o!="string"&&(o=o.id),t.current[o]&&t.current[o].beforeRemove(),e.get({id:r,type:"AnnotationPage"})&&n(Q.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"}})))},[r]);return[a,{addAnnotation:i,removeAnnotation:s}]}var en=Object.defineProperty,tn=Object.defineProperties,nn=Object.getOwnPropertyDescriptors,Ie=Object.getOwnPropertySymbols,rn=Object.prototype.hasOwnProperty,on=Object.prototype.propertyIsEnumerable,Ae=(e,t,n)=>t in e?en(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,sn=(e,t)=>{for(var n in t||(t={}))rn.call(t,n)&&Ae(e,n,t[n]);if(Ie)for(var n of Ie(t))on.call(t,n)&&Ae(e,n,t[n]);return e},an=(e,t)=>tn(e,nn(t));function cn(e){const t=L(),n=R(),r=S(),[a,i]=Oe(),{enabledPageIds:s}=ge((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(n==null?void 0:n.id),{all:!1}),o=_e(s,"AnnotationPage"),c=(e==null?void 0:e.strategies)||["images","media","complex-timeline"],[l,p]=Se(e,[i]),f=u.useMemo(()=>{if(!n||l.types.length===0)return q;if(l.types.length!==1)return c.indexOf("complex-timeline")===-1?E("Complex timeline not supported"):E("ComplexTimelineStrategy not yet supported");const v=l.types[0];return v==="image"?c.indexOf("images")===-1?E("Image not supported"):ce(n,l,a):v==="audio"?c.indexOf("media")===-1?E("Media not supported"):E("Audio strategy not yet supported"):v==="video"?c.indexOf("media")===-1?E("Media not supported"):E("Video strategy not yet supported"):q},[n,l,r,p.makeChoice]);return u.useMemo(()=>f.type==="unknown"?[f,ae]:[an(sn({},f),{annotations:{pages:o}}),p],[f,o])}exports.AnnotationContext=Le,exports.CanvasContext=X,exports.CollectionContext=De,exports.ContextBridge=Ue,exports.ImageServiceLoaderContext=ee,exports.ManifestContext=J,exports.RangeContext=je,exports.ReactVaultContext=T,exports.ResourceProvider=I,exports.ResourceReactContext=F,exports.SimpleViewerProvider=ke,exports.SimpleViewerReactContext=$,exports.VaultProvider=W,exports.VisibleCanvasReactContext=V,exports.emptyActions=ae,exports.expandTarget=x,exports.flattenAnnotationPageIds=fe,exports.getImageStrategy=ce,exports.getPaintables=se,exports.parseSelector=N,exports.parseSpecificResource=ie,exports.unknownResponse=q,exports.unsupportedStrategy=E,exports.useAnnotation=rt,exports.useAnnotationPageManager=ge,exports.useAnnotationsAtTime=dt,exports.useCanvas=R,exports.useCanvasClock=pt,exports.useCollection=vt,exports.useContextBridge=Ne,exports.useDispatch=he,exports.useEventListener=mt,exports.useExistingVault=gt,exports.useExternalCollection=ht,exports.useExternalManifest=Z,exports.useExternalResource=H,exports.useImageService=ye,exports.useImageServiceLoader=B,exports.useImageTile=St,exports.useLoadImageService=Oe,exports.useManifest=L,exports.usePaintables=Se,exports.usePaintingAnnotations=U,exports.useRange=_t,exports.useRenderingStrategy=cn,exports.useResourceContext=b,exports.useResourceEvents=Ct,exports.useResources=_e,exports.useSearchService=Pt,exports.useSimpleViewer=Be,exports.useStyleHelper=Et,exports.useStyles=wt,exports.useThumbnail=xt,exports.useVault=S,exports.useVaultEffect=Ce,exports.useVaultSelector=P,exports.useVirtualAnnotationPage=Kt,exports.useVisibleCanvases=K;
|
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)},!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};
|
|
1
|
+
import g,{useContext as O,useMemo as m,useState as w,useEffect as b,createContext as je,useCallback as C,useRef as Q,useLayoutEffect as Fe}from"react";import{globalVault as X,Vault as J}from"@iiif/vault";import{ImageServiceLoader as Ne,getImageServices as q}from"@atlas-viewer/iiif-image-api";import{createEventsHelper as W,createStylesHelper as Z,createThumbnailHelper as Be}from"@iiif/vault-helpers";import{createAction as y}from"typesafe-actions";var Ue=Object.defineProperty,K=Object.getOwnPropertySymbols,ke=Object.prototype.hasOwnProperty,He=Object.prototype.propertyIsEnumerable,ee=(e,t,n)=>t in e?Ue(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,te=(e,t)=>{for(var n in t||(t={}))ke.call(t,n)&&ee(e,n,t[n]);if(K)for(var n of K(t))He.call(t,n)&&ee(e,n,t[n]);return e};const Qe={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},N=g.createContext(Qe),T=()=>O(N),$=({value:e,children:t})=>{const n=T(),r=m(()=>te(te({},n),e),[e,n]);return g.createElement(N.Provider,{value:r},t)},qe=({annotation:e,children:t})=>g.createElement($,{value:{annotation:e}},t),ne=({canvas:e,children:t})=>g.createElement($,{value:{canvas:e}},t),ze=({collection:e,children:t})=>g.createElement($,{value:{collection:e}},t),re=({manifest:e,children:t})=>g.createElement($,{value:{manifest:e}},t),Ye=({range:e,children:t})=>g.createElement($,{value:{range:e}},t),L=g.createContext({vault:null,setVaultInstance:e=>{}}),oe=({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:a})=>{const[i,s]=w(()=>e||(n?X(t):t?new J(t):new J));return g.createElement(L.Provider,{value:{vault:i,setVaultInstance:s}},g.createElement($,{value:r||{}},a))},_=()=>{const{vault:e}=O(L);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var Ge=(e,t,n)=>new Promise((r,a)=>{var i=c=>{try{o(n.next(c))}catch(l){a(l)}},s=c=>{try{o(n.throw(c))}catch(l){a(l)}},o=c=>c.done?r(c.value):Promise.resolve(c.value).then(i,s);o((n=n.apply(e,t)).next())});function z(e,{noCache:t=!1}={}){const n=typeof e=="string"?e:e.id,r=_(),[a,i]=w(n),[s,o]=w(void 0),c=m(()=>r.get(n,{skipSelfReturn:!0})||void 0,[n,r]),[l,d]=w(c);return b(()=>{Ge(this,null,function*(){try{const u=c&&!t?c:yield r.load(n),p=u?u.id||u["@id"]:null;u&&a!==p&&i(p),d(u)}catch(u){o(u)}})},[n,t]),{isLoaded:!!l,id:a,requestId:n,error:s,resource:l,cached:!!(l&&l===c)}}function ie(e,t){const{id:n,isLoaded:r,error:a,resource:i,requestId:s,cached:o}=z(e,t);return{id:n,isLoaded:r,error:a,manifest:i,requestId:s,cached:o}}function E(e,t=[]){const n=_(),[r,a]=w(()=>e(n.getState(),n));return b(()=>n.subscribe(i=>e(i,n),i=>{a(i)},!1),t),r}const D=g.createContext([]);function se(){const e=O(D);return E(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}const B=()=>{},j=je({setCurrentCanvasId:B,setCurrentCanvasIndex:B,nextCanvas:B,previousCanvas:B,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),Xe=e=>{const t=ie(e.manifest),[n,r]=w(""),[a,i]=w([]),s=(typeof e.pagingEnabled>"u"||e.pagingEnabled)&&t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");b(()=>{var f,v;t.manifest&&(r((f=t.manifest.items[0])==null?void 0:f.id),i([(v=t.manifest.items[0])==null?void 0:v.id]))},[t.manifest,e.manifest]);const o=m(()=>{var f;return((f=t.manifest)==null?void 0:f.items.map(v=>v.id))||[]},[t.manifest,e.manifest]),c=m(()=>o.indexOf(n),[o,n]),l=C(()=>{if(o.length&&n){if(c===-1||(o[c+2]?c+2===o.length:c===o.length))return;const f=s&&c!==0?o[c+2]:o[c+1],v=s?c!==0?o[c+3]:o[c+2]:null;f&&(r(f),i(v?[f,v]:[f]))}},[s,o,n,c]),d=C(()=>{if(o.length&&n){if(c===0||c===-1)return;const f=s&&c!==1?o[c-2]:o[c-1],v=s&&c!==1?o[c-1]:null;f&&(r(f),i(v?[f,v]:[f]))}},[s,o,n,c]),u=C(f=>{const v=s&&f%2===1?f-1:f,P=o[v],M=s&&v!==0?o[v+1]:null;P&&(r(P),i(A=>{const S=M?[P,M]:[P];if(A.length===A.length){for(let I=0;I<A.length;I++)if(A[I]!==S[I])return S;return A}return S}))},[s,o]),p=C(f=>{const v=o.indexOf(f);v!==-1&&u(v)},[o,u]),h=m(()=>({setCurrentCanvasId:p,nextCanvas:l,previousCanvas:d,currentCanvasIndex:c,totalCanvases:o.length,setCurrentCanvasIndex:u,pagingView:!0}),[l,d,c,o,u,p]);return t.manifest?t.isLoaded?g.createElement(j.Provider,{value:h},g.createElement(D.Provider,{value:a},g.createElement(re,{manifest:t.manifest.id},g.createElement(ne,{canvas:n},e.children)))):g.createElement("div",null,"Loading..."):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),g.createElement("div",null,"Sorry, something went wrong."))};function Je(){return O(j)}function We(){return{VaultContext:O(L),ResourceContext:O(N),SimpleViewerReactContext:O(j),VisibleCanvasReactContext:O(D)}}const Ze=e=>g.createElement(oe,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},g.createElement(D.Provider,{value:e.bridge.VisibleCanvasReactContext},g.createElement(j.Provider,{value:e.bridge.SimpleViewerReactContext},e.children))),ae=g.createContext(new Ne);function U(){return O(ae)}const Ke=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,et=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function k(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:r,selectors:a}=k(n);return r&&(t.selector||(t.selector=r),t.selectors.push(...a)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,n]=e.split("#");return n?k({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=Ke.exec(e.value);if(t){const r={type:"BoxSelector",spatial:{unit:t[2]==="percent:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:r,selectors:[r]}}const n=e.value.match(et);if(n){const r={type:"TemporalSelector",temporal:{startTime:n[4]?parseFloat(n[4]):0,endTime:n[7]?parseFloat(n[7]):void 0}};return{selector:r,selectors:[r]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}var tt=Object.defineProperty,nt=Object.defineProperties,rt=Object.getOwnPropertyDescriptors,ce=Object.getOwnPropertySymbols,ot=Object.prototype.hasOwnProperty,it=Object.prototype.propertyIsEnumerable,le=(e,t,n)=>t in e?tt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ue=(e,t)=>{for(var n in t||(t={}))ot.call(t,n)&&le(e,n,t[n]);if(ce)for(var n of ce(t))it.call(t,n)&&le(e,n,t[n]);return e},fe=(e,t)=>nt(e,rt(t));function R(e,t={}){if(Array.isArray(e))return R(e[0]);if(typeof e=="string"){const[n,r]=e.split("#");return r?R({type:"SpecificResource",source:{id:n,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return R(e.items[0]);if(e.type==="SpecificResource"){e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]);const{selector:n,selectors:r}=e.selector?k(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:n,selectors:r}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[n,r]=e.id.split("#");return r?R({type:"SpecificResource",source:fe(ue({},e),{id:n}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:fe(ue({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function de(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function pe(e,t,n){const r=[];let a=null;const i=[];for(const s of t){const o=e.get(s.body);for(const c of o){const[l,{selector:d}]=de(c),u=(l.type||"unknown").toLowerCase();if(u==="choice"){const p=e.get(l.items),h=n.length?n.map(f=>p.find(v=>v.id===f)).filter(Boolean):[p[0]];h.length===0&&h.push(p[0]),a={type:"single-choice",items:p.map(f=>({id:f.id,label:f.label,selected:h.indexOf(f)!==-1})),label:c.label},o.push(...h);continue}r.indexOf(u)===-1&&r.push(u),i.push({type:u,resource:l,target:s.target,selector:d})}}return{types:r,items:i,choice:a}}const ve={makeChoice:()=>{}},Y={type:"unknown"},x=e=>({type:"unknown",reason:e,annotations:{pages:[]}});function me(e,t,n){const r=[];for(const a of t.items){const i=a.resource&&a.resource.type==="SpecificResource"?a.resource.source:a.resource;if(!i.id)return x("No resource Identifier");let s;if(i.service){const v=q(i);v[0]&&(s=n(v[0],e))}const{selector:o,source:c}=R(a.target);if(c.id!==e.id)continue;const l={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},d=o?o.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:o.temporal,spatial:l.spatial}:o:null,u={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},p=a.resource.type==="SpecificResource"?R(a.resource):null,h=p&&p.selector&&(p.selector.type==="BoxSelector"||p.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:p.selector.spatial.x,y:p.selector.spatial.y,width:p.selector.spatial.width,height:p.selector.spatial.height}}:u,f={id:i.id,type:"Image",width:d?i.width:e.width,height:d?i.height:e.height,service:s,sizes:s&&s.sizes?s.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:d&&d.type!=="PointSelector"?d:l,selector:h};r.push(f)}return{type:"images",image:r[0],images:r,choice:t.choice}}var st=Object.defineProperty,at=Object.defineProperties,ct=Object.getOwnPropertyDescriptors,ge=Object.getOwnPropertySymbols,lt=Object.prototype.hasOwnProperty,ut=Object.prototype.propertyIsEnumerable,he=(e,t,n)=>t in e?st(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ft=(e,t)=>{for(var n in t||(t={}))lt.call(t,n)&&he(e,n,t[n]);if(ge)for(var n of ge(t))ut.call(t,n)&&he(e,n,t[n]);return e},dt=(e,t)=>at(e,ct(t));function pt(e={},t=[]){const{id:n,selector:r}=e,a=T(),i=_(),s=n||a.annotation,o=E(l=>s?l.iiif.entities.Annotation[s]:void 0,[s]),c=E(l=>o&&o.body?o.body.map(d=>d?l.iiif.entities[d.type][d.id]:null).filter(Boolean):[],[o]);return m(()=>{if(!o)return;const l=dt(ft({},o),{body:c,target:R(o.target,{typeMap:i.getState().iiif.mapping})});return r?r(l):l},[o,r,c,...t])}function F(e={},t=[]){const{id:n,selector:r}=e,a=T();_();const i=n||a.manifest,s=E(o=>i?o.iiif.entities.Manifest[i]:void 0,[i]);return m(()=>{if(!!s)return r?r(s):s},[s,r,...t])}function V(e={},t=[]){const{id:n,selector:r}=e,a=T(),i=n||a.canvas,s=E(o=>i?o.iiif.entities.Canvas[i]:void 0,[i]);return m(()=>{if(!!s)return r?r(s):s},[s,r,...t])}function vt(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function mt(e,t){return E(n=>{const r=[];if(!e)return r;const a=Object.keys(n.iiif.entities.AnnotationPage);for(const i of a)if(!t||t.indexOf(i)!==-1){const s=vt(n,i);s&&s.views&&s.views[e]&&r.push(i)}return r},[e,t])}function ye({canvas:e,manifest:t,all:n,canvases:r}){const a=[];if(t)for(const i of t.annotations)a.indexOf(i.id)===-1&&a.push(i.id);if(n){if(r&&r.length)for(const i of r)for(const s of i.annotations)a.indexOf(s.id)===-1&&a.push(s.id)}else if(e)for(const i of e.annotations)a.indexOf(i.id)===-1&&a.push(i.id);return a}var gt=Object.defineProperty,ht=Object.defineProperties,yt=Object.getOwnPropertyDescriptors,_e=Object.getOwnPropertySymbols,_t=Object.prototype.hasOwnProperty,Pt=Object.prototype.propertyIsEnumerable,Pe=(e,t,n)=>t in e?gt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Se=(e,t)=>{for(var n in t||(t={}))_t.call(t,n)&&Pe(e,n,t[n]);if(_e)for(var n of _e(t))Pt.call(t,n)&&Pe(e,n,t[n]);return e},we=(e,t)=>ht(e,yt(t));function St(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function Ee(e,t={}){const n=_(),r=F(),a=V(),i=se(),s=m(()=>ye({all:t.all,manifest:r,canvas:a,canvases:i}),[t.all,a,i,r]),o=mt(e,t.all?void 0:s),c=C(d=>{!e||n.setMetaValue([d,"annotationPageManager","views"],u=>u&&!u[e]?u:we(Se({},u||{}),{[e]:!1}))},[e,n]),l=C((d,u={})=>{if(!e)return;const p=n.getState(),h=[];if(u==null?void 0:u.deselectOthers){const f=Object.keys(p.iiif.entities.AnnotationPage);for(const v of f){const P=St(p,v);P&&P.views&&P.views[e]&&h.push(v)}}for(const f of h)c(f);n.setMetaValue([d,"annotationPageManager","views"],f=>f&&f[e]?f:we(Se({},f||{}),{[e]:!0}))},[e,c,n]);return{availablePageIds:s,enabledPageIds:o,setPageEnabled:l,setPageDisabled:c}}function H(e={}){const t=V(e.canvasId?{id:e.canvasId}:void 0);return E((n,r)=>{if(!t)return[];const a=r.get(t.items),i=[];for(const s of a)i.push(...r.get(s.items));return i},[t])}function wt(e,t={}){return H(t)}function Et(e,t=!1){}function Ot(e,t=[]){const{id:n,selector:r}=e,a=T(),i=n||a.collection,s=E(o=>i?o.iiif.entities.Collection[i]:void 0,[i]);return m(()=>{if(!!s)return r?r(s):s},[s,r,...t])}function Oe(){const t=_().getStore();return m(()=>n=>t.dispatch(n),[t])}function Ct(e,t,n,r,a=[]){const i=_(),s=m(()=>W(i),[i]);b(()=>{const o=e;return o?(s.addEventListener(o,t,n,r),()=>{s.removeEventListener(o,t,n)}):()=>{}},[s,e,t,...a])}function xt(){const e=O(L);return e&&e.vault?e.vault:X()}function It(e,t){const{id:n,isLoaded:r,error:a,resource:i,requestId:s,cached:o}=z(e,t);return{id:n,isLoaded:r,error:a,manifest:i,requestId:s,cached:o}}var bt=(e,t,n)=>new Promise((r,a)=>{var i=c=>{try{o(n.next(c))}catch(l){a(l)}},s=c=>{try{o(n.throw(c))}catch(l){a(l)}},o=c=>c.done?r(c.value):Promise.resolve(c.value).then(i,s);o((n=n.apply(e,t)).next())});function Ce({cacheKey:e}={}){const t=V(),n=H(),r=_(),a=U(),[i,s]=w(void 0),[o,c]=w(!1),[l,d]=w("idle"),[u,p]=w(void 0),h=t?t.id:"undefined",f=m(()=>{try{if(t&&n.length){const P=n[0],M=r.get(P.body[0]),S=q(M)[0];return S&&a.loadServiceSync({id:S.id||S["@id"],width:S.width||t.width,height:S.height||t.height})||void 0}}catch(P){console.error(P)}},[h,e,t]),v=l==="success"&&i?i:f;return b(()=>{bt(this,null,function*(){try{if(t&&n.length){const P=n[0],M=r.get(P.body[0]),S=q(M)[0];if(!S)return;c(!0),d("loading");try{const I=(yield a.loadService({id:S.id||S["@id"],width:S.width||t.width,height:S.height||t.height}))||void 0;s(I),d("success"),c(!1)}catch(I){d("error"),p(I)}}}catch(P){d("error"),p(P)}})},[h,e]),m(()=>({data:v,isFetching:o,status:l,error:u}),[v,o,l,u])}function Rt(){const e=Ce();return{isLoading:e.isFetching,tile:e.data?{id:e.data.id||e.data["@id"],width:e.data.width,height:e.data.height,imageService:e.data,thumbnail:void 0}:null}}function xe(e,t=[]){const n=_(),r=H(),[a,i]=w((e==null?void 0:e.defaultChoices)||[]),s=m(()=>pe(n,r,a),[n,r,a,...t]),c={makeChoice:C((l,{deselectOthers:d=!0,deselect:u=!1}={})=>{if(s.choice){if(s.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");i(p=>{if(u){const f=p.filter(v=>v!==l);if(f.length===0){const v=s.items[0].resource.id;return v?[v]:[]}return f}if(d)return[l];const h=[...p];if(h.length===0&&s.items.length){const f=s.items[0].resource.id;f&&h.push(f)}return p.indexOf(l)!==-1?p:[...p,l]})}},[s.choice])};return[s,c]}function At(e={},t=[]){const{id:n,selector:r}=e,a=T(),i=n||a.range,s=E(o=>i?o.iiif.entities.Range[i]:void 0,[i]);return m(()=>{if(!!s)return r?r(s):s},[s,r,...t])}function Tt(e,t){const n=_(),r=m(()=>W(n),[n]),a=E(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return m(()=>e?r.getListenersAsProps(e,t):{},[a,e,n,t])}function Ie(e,t){return E((n,r)=>r.get(e.map(a=>({id:a,type:t}))),[e,t])}function $t(){const e=F();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function Mt(){const e=_();return m(()=>Z(e),[e])}function Vt(e,t){const n=_(),r=m(()=>Z(n),[n]);return E(()=>{if(!e)return null;const a=r.getAppliedStyles(e.id);return a?t?a[t]:a:void 0},[e,t])}const be=(e,t=[])=>{const n=_();b(()=>{e(n)},[n,...t])};function Lt(e,t,{canvasId:n,manifestId:r}={}){const a=_(),i=U(),s=m(()=>Be(a,{imageServiceLoader:i}),[a,i]),[o,c]=w(),l=F(r?{id:r}:void 0),d=V(n?{id:n}:void 0),u=d||l,p=Q(!1);if(b(()=>()=>{p.current=!0},[]),!u)throw new Error("Must be called under a manifest or canvas context.");return be(h=>{s.getBestThumbnailAtSize(u,e,t).then(f=>{f.best&&!p.current&&c(f.best)})},[u]),o}var Dt=Object.defineProperty,jt=Object.defineProperties,Ft=Object.getOwnPropertyDescriptors,Re=Object.getOwnPropertySymbols,Nt=Object.prototype.hasOwnProperty,Bt=Object.prototype.propertyIsEnumerable,Ae=(e,t,n)=>t in e?Dt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Te=(e,t)=>{for(var n in t||(t={}))Nt.call(t,n)&&Ae(e,n,t[n]);if(Re)for(var n of Re(t))Bt.call(t,n)&&Ae(e,n,t[n]);return e},$e=(e,t)=>jt(e,Ft(t));function Me(){const e=U(),[t,n]=w({}),r=Q(!1);return b(()=>()=>{r.current=!0},[]),[C((i,{height:s,width:o})=>{if(i){const c=i.id||i["@id"],l=e.loadServiceSync({id:c,width:i.width||o,height:i.height||s});l?i=l:t[c]||(r.current||n(d=>$e(Te({},d),{[c]:"loading"})),e.loadService({id:c,width:i.width||o,height:i.height||s}).then(()=>{r.current||n(d=>$e(Te({},d),{[c]:"done"}))}))}return i},[e,t]),t]}const Ut="@iiif/IMPORT_ENTITIES",kt="@iiif/MODIFY_ENTITY_FIELD",Ht="@iiif/REORDER_ENTITY_FIELD",Qt="@iiif/ADD_REFERENCE",qt="@iiif/REMOVE_REFERENCE",zt=y(Ut)(),Yt=y(kt)(),Gt=y(Ht)(),Xt=y(Qt)(),Jt=y(qt)(),G={importEntities:zt,modifyEntityField:Yt,reorderEntityField:Gt,addReference:Xt,removeReference:Jt},Wt="@iiif/ADD_MAPPING",Zt="@iiif/ADD_MAPPINGS";y(Wt)(),y(Zt)();const Kt="@iiif/SET_META_VALUE",en="@iiif/SET_META_VALUE_DYNAMIC",tn="@iiif/UNSET_META_VALUE";y(Kt)(),y(en)(),y(tn)();const nn="@iiif/REQUEST_RESOURCE",rn="@iiif/REQUEST_ERROR",on="@iiif/REQUEST_MISMATCH",sn="@iiif/REQUEST_COMPLETE",an="@iiif/REQUEST_OFFLINE_RESOURCE";y(nn)(),y(rn)(),y(on)(),y(sn)(),y(an)();const cn="@iiif/BATCH",ln="@iiif/BATCH_IMPORT";y(cn)(),y(ln)();function Ve(e){return typeof e!="string"&&e&&e.bindToVault}function un(){const e=_(),t=Q([]),n=Oe(),r=m(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);Fe(()=>{const o={id:r,type:"AnnotationPage",behavior:[],motivation:null,label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[]};n(G.importEntities({entities:{AnnotationPage:{[o.id]:o}}}))},[r]);const a=E(o=>r?o.iiif.entities.AnnotationPage[r]:null,[r]),i=C((o,c)=>{if(r){if(Ve(o)){const u=o;u.__vault||u.bindToVault(e),o=typeof u.source=="string"?u.source:u.source.id,t.current[o]=u}else typeof o!="string"&&(o=o.id);const l=e.get({id:r,type:"AnnotationPage"}),d=e.get({id:o,type:"Annotation"});l&&d&&(l.items.find(u=>u.id===d.id)||n(G.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"},index:c})))}},[r]),s=C(o=>{r&&(Ve(o)?o=typeof o.source=="string"?o.source:o.source.id:typeof o!="string"&&(o=o.id),t.current[o]&&t.current[o].beforeRemove(),e.get({id:r,type:"AnnotationPage"})&&n(G.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"}})))},[r]);return[a,{addAnnotation:i,removeAnnotation:s}]}var fn=Object.defineProperty,dn=Object.defineProperties,pn=Object.getOwnPropertyDescriptors,Le=Object.getOwnPropertySymbols,vn=Object.prototype.hasOwnProperty,mn=Object.prototype.propertyIsEnumerable,De=(e,t,n)=>t in e?fn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,gn=(e,t)=>{for(var n in t||(t={}))vn.call(t,n)&&De(e,n,t[n]);if(Le)for(var n of Le(t))mn.call(t,n)&&De(e,n,t[n]);return e},hn=(e,t)=>dn(e,pn(t));function yn(e){const t=F(),n=V(),r=_(),[a,i]=Me(),{enabledPageIds:s}=Ee((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(n==null?void 0:n.id),{all:!1}),o=Ie(s,"AnnotationPage"),c=(e==null?void 0:e.strategies)||["images","media","complex-timeline"],[l,d]=xe(e,[i]),u=m(()=>{if(!n||l.types.length===0)return Y;if(l.types.length!==1)return c.indexOf("complex-timeline")===-1?x("Complex timeline not supported"):x("ComplexTimelineStrategy not yet supported");const p=l.types[0];return p==="image"?c.indexOf("images")===-1?x("Image not supported"):me(n,l,a):p==="audio"?c.indexOf("media")===-1?x("Media not supported"):x("Audio strategy not yet supported"):p==="video"?c.indexOf("media")===-1?x("Media not supported"):x("Video strategy not yet supported"):Y},[n,l,r,d.makeChoice]);return m(()=>u.type==="unknown"?[u,ve]:[hn(gn({},u),{annotations:{pages:o}}),d],[u,o])}export{qe as AnnotationContext,ne as CanvasContext,ze as CollectionContext,Ze as ContextBridge,ae as ImageServiceLoaderContext,re as ManifestContext,Ye as RangeContext,L as ReactVaultContext,$ as ResourceProvider,N as ResourceReactContext,Xe as SimpleViewerProvider,j as SimpleViewerReactContext,oe as VaultProvider,D as VisibleCanvasReactContext,ve as emptyActions,R as expandTarget,ye as flattenAnnotationPageIds,me as getImageStrategy,pe as getPaintables,k as parseSelector,de as parseSpecificResource,Y as unknownResponse,x as unsupportedStrategy,pt as useAnnotation,Ee as useAnnotationPageManager,wt as useAnnotationsAtTime,V as useCanvas,Et as useCanvasClock,Ot as useCollection,We as useContextBridge,Oe as useDispatch,Ct as useEventListener,xt as useExistingVault,It as useExternalCollection,ie as useExternalManifest,z as useExternalResource,Ce as useImageService,U as useImageServiceLoader,Rt as useImageTile,Me as useLoadImageService,F as useManifest,xe as usePaintables,H as usePaintingAnnotations,At as useRange,yn as useRenderingStrategy,T as useResourceContext,Tt as useResourceEvents,Ie as useResources,$t as useSearchService,Je as useSimpleViewer,Mt as useStyleHelper,Vt as useStyles,Lt as useThumbnail,_ as useVault,be as useVaultEffect,E as useVaultSelector,un as useVirtualAnnotationPage,se as useVisibleCanvases};
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { Vault, VaultOptions, ReduxStore, NormalizedEntity, IIIFStore } from '@i
|
|
|
3
3
|
import * as _iiif_vault__ from '@iiif/vault/*';
|
|
4
4
|
import { CanvasNormalized, InternationalString, ImageService, AnnotationPageNormalized, ContentResource, IIIFExternalWebResource, SpecificResource, AnnotationNormalized, CollectionNormalized, Reference, ManifestNormalized, RangeNormalized, SearchService, Annotation, ExternalWebResource, W3CAnnotationTarget, Selector } from '@iiif/presentation-3';
|
|
5
5
|
import { ImageServiceLoader, ImageCandidateRequest, ImageCandidate } from '@atlas-viewer/iiif-image-api';
|
|
6
|
-
import { QueryOptions } from 'react-query';
|
|
7
6
|
import * as _iiif_vault_helpers from '@iiif/vault-helpers';
|
|
8
7
|
|
|
9
8
|
declare const AnnotationContext: React.FC<{
|
|
@@ -301,23 +300,54 @@ declare function useEventListener<T>(resource: Reference, name: SupportedEvents,
|
|
|
301
300
|
|
|
302
301
|
declare function useExistingVault(): any;
|
|
303
302
|
|
|
304
|
-
declare
|
|
303
|
+
declare type ResourceRequestOptions = {
|
|
304
|
+
noCache?: boolean;
|
|
305
|
+
};
|
|
306
|
+
declare function useExternalResource<T extends {
|
|
307
|
+
id: string;
|
|
308
|
+
}>(idOrRef: string | {
|
|
309
|
+
id: string;
|
|
310
|
+
type: string;
|
|
311
|
+
}, { noCache }?: ResourceRequestOptions): {
|
|
312
|
+
id: string;
|
|
313
|
+
requestId: string;
|
|
314
|
+
isLoaded: boolean;
|
|
315
|
+
error: any;
|
|
316
|
+
cached: boolean;
|
|
317
|
+
resource?: T;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
declare function useExternalCollection(idOrRef: string | {
|
|
321
|
+
id: string;
|
|
322
|
+
type: string;
|
|
323
|
+
}, options?: ResourceRequestOptions): {
|
|
305
324
|
id: string;
|
|
325
|
+
requestId: string;
|
|
306
326
|
isLoaded: boolean;
|
|
307
|
-
|
|
327
|
+
cached?: boolean;
|
|
328
|
+
error: any;
|
|
329
|
+
manifest?: CollectionNormalized;
|
|
308
330
|
};
|
|
309
331
|
|
|
310
|
-
declare
|
|
332
|
+
declare function useExternalManifest(idOrRef: string | {
|
|
311
333
|
id: string;
|
|
334
|
+
type: string;
|
|
335
|
+
}, options?: ResourceRequestOptions): {
|
|
336
|
+
id: string;
|
|
337
|
+
requestId: string;
|
|
312
338
|
isLoaded: boolean;
|
|
339
|
+
cached?: boolean;
|
|
313
340
|
error: any;
|
|
314
|
-
manifest?: ManifestNormalized
|
|
341
|
+
manifest?: ManifestNormalized;
|
|
315
342
|
};
|
|
316
343
|
|
|
317
|
-
|
|
344
|
+
interface ImageServiceRequestOptions {
|
|
345
|
+
cacheKey?: string;
|
|
346
|
+
}
|
|
347
|
+
declare function useImageService({ cacheKey }?: ImageServiceRequestOptions): {
|
|
318
348
|
data: ImageService | undefined;
|
|
319
349
|
isFetching: boolean;
|
|
320
|
-
status: 'error' | 'success' | 'loading';
|
|
350
|
+
status: 'error' | 'success' | 'loading' | 'idle';
|
|
321
351
|
};
|
|
322
352
|
|
|
323
353
|
declare function useImageTile(): {
|
|
@@ -441,4 +471,4 @@ declare const SimpleViewerProvider: FC<{
|
|
|
441
471
|
}>;
|
|
442
472
|
declare function useSimpleViewer(): SimpleViewerContext;
|
|
443
473
|
|
|
444
|
-
export { AnnotationContext, AnnotationPageDescription, AudioSequence, BoxSelector, CanvasContext, ChoiceDescription, CollectionContext, ComplexChoice, ComplexTimelineStrategy, ContextBridge, ImageServiceLoaderContext, ImageServiceLoaderType, ImageWithOptionalService, ManifestContext, MediaStrategy, Paintables, ParsedSelector, PointSelector, RangeContext, ReactVaultContext, RenderingStrategy, ResourceContextType, ResourceProvider, ResourceReactContext, SimpleViewerProvider, SimpleViewerReactContext, SingleAudio, SingleChoice, SingleImageStrategy, SingleVideo, StrategyActions, SupportedSelector, SupportedSelectors, SupportedTarget, TemporalBoxSelector, TemporalSelector, UnknownStrategy, UseRenderingStrategy, UseRenderingStrategyOptions, VaultActivatedAnnotation, VaultProvider, VideoSequence, VisibleCanvasReactContext, emptyActions, expandTarget, flattenAnnotationPageIds, getImageStrategy, getPaintables, parseSelector, parseSpecificResource, unknownResponse, unsupportedStrategy, useAnnotation, useAnnotationPageManager, useAnnotationsAtTime, useCanvas, useCanvasClock, useCollection, useContextBridge, useDispatch, useEventListener, useExistingVault, useExternalCollection, useExternalManifest, useImageService, useImageServiceLoader, useImageTile, useLoadImageService, useManifest, usePaintables, usePaintingAnnotations, useRange, useRenderingStrategy, useResourceContext, useResourceEvents, useResources, useSearchService, useSimpleViewer, useStyleHelper, useStyles, useThumbnail, useVault, useVaultEffect, useVaultSelector, useVirtualAnnotationPage, useVisibleCanvases };
|
|
474
|
+
export { AnnotationContext, AnnotationPageDescription, AudioSequence, BoxSelector, CanvasContext, ChoiceDescription, CollectionContext, ComplexChoice, ComplexTimelineStrategy, ContextBridge, ImageServiceLoaderContext, ImageServiceLoaderType, ImageServiceRequestOptions, ImageWithOptionalService, ManifestContext, MediaStrategy, Paintables, ParsedSelector, PointSelector, RangeContext, ReactVaultContext, RenderingStrategy, ResourceContextType, ResourceProvider, ResourceReactContext, ResourceRequestOptions, SimpleViewerProvider, SimpleViewerReactContext, SingleAudio, SingleChoice, SingleImageStrategy, SingleVideo, StrategyActions, SupportedSelector, SupportedSelectors, SupportedTarget, TemporalBoxSelector, TemporalSelector, UnknownStrategy, UseRenderingStrategy, UseRenderingStrategyOptions, VaultActivatedAnnotation, VaultProvider, VideoSequence, VisibleCanvasReactContext, emptyActions, expandTarget, flattenAnnotationPageIds, getImageStrategy, getPaintables, parseSelector, parseSpecificResource, unknownResponse, unsupportedStrategy, useAnnotation, useAnnotationPageManager, useAnnotationsAtTime, useCanvas, useCanvasClock, useCollection, useContextBridge, useDispatch, useEventListener, useExistingVault, useExternalCollection, useExternalManifest, useExternalResource, useImageService, useImageServiceLoader, useImageTile, useLoadImageService, useManifest, usePaintables, usePaintingAnnotations, useRange, useRenderingStrategy, useResourceContext, useResourceEvents, useResources, useSearchService, useSimpleViewer, useStyleHelper, useStyles, useThumbnail, useVault, useVaultEffect, useVaultSelector, useVirtualAnnotationPage, useVisibleCanvases };
|
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(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}/*! *****************************************************************************
|
|
1
|
+
(function(g,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("react"),require("@iiif/vault")):typeof define=="function"&&define.amd?define(["exports","react","@iiif/vault"],h):(g=typeof globalThis<"u"?globalThis:g||self,h(g.ReactIIIFVault={},g.React,g.IIIFVault))})(this,function(g,h,K){"use strict";function Kt(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var A=Kt(h),ei=Object.defineProperty,de=Object.getOwnPropertySymbols,ti=Object.prototype.hasOwnProperty,ii=Object.prototype.propertyIsEnumerable,pe=(e,t,i)=>t in e?ei(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,ge=(e,t)=>{for(var i in t||(t={}))ti.call(t,i)&&pe(e,i,t[i]);if(de)for(var i of de(t))ii.call(t,i)&&pe(e,i,t[i]);return e};const ni={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},ee=A.default.createContext(ni),k=()=>h.useContext(ee),V=({value:e,children:t})=>{const i=k(),n=h.useMemo(()=>ge(ge({},i),e),[e,i]);return A.default.createElement(ee.Provider,{value:n},t)},ri=({annotation:e,children:t})=>A.default.createElement(V,{value:{annotation:e}},t),me=({canvas:e,children:t})=>A.default.createElement(V,{value:{canvas:e}},t),oi=({collection:e,children:t})=>A.default.createElement(V,{value:{collection:e}},t),ve=({manifest:e,children:t})=>A.default.createElement(V,{value:{manifest:e}},t),si=({range:e,children:t})=>A.default.createElement(V,{value:{range:e}},t),U=A.default.createContext({vault:null,setVaultInstance:e=>{}}),ye=({vault:e,vaultOptions:t,useGlobal:i,resources:n,children:o})=>{const[r,s]=h.useState(()=>e||(i?K.globalVault(t):t?new K.Vault(t):new K.Vault));return A.default.createElement(U.Provider,{value:{vault:r,setVaultInstance:s}},A.default.createElement(V,{value:n||{}},o))},I=()=>{const{vault:e}=h.useContext(U);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var ai=(e,t,i)=>new Promise((n,o)=>{var r=l=>{try{a(i.next(l))}catch(c){o(c)}},s=l=>{try{a(i.throw(l))}catch(c){o(c)}},a=l=>l.done?n(l.value):Promise.resolve(l.value).then(r,s);a((i=i.apply(e,t)).next())});function oe(e,{noCache:t=!1}={}){const i=typeof e=="string"?e:e.id,n=I(),[o,r]=h.useState(i),[s,a]=h.useState(void 0),l=h.useMemo(()=>n.get(i,{skipSelfReturn:!0})||void 0,[i,n]),[c,u]=h.useState(l);return h.useEffect(()=>{ai(this,null,function*(){try{const d=l&&!t?l:yield n.load(i),v=d?d.id||d["@id"]:null;d&&o!==v&&r(v),u(d)}catch(d){a(d)}})},[i,t]),{isLoaded:!!c,id:o,requestId:i,error:s,resource:c,cached:!!(c&&c===l)}}function we(e,t){const{id:i,isLoaded:n,error:o,resource:r,requestId:s,cached:a}=oe(e,t);return{id:i,isLoaded:n,error:o,manifest:r,requestId:s,cached:a}}function $(e,t=[]){const i=I(),[n,o]=h.useState(()=>e(i.getState(),i));return h.useEffect(()=>i.subscribe(r=>e(r,i),r=>{o(r)},!1),t),n}const Q=A.default.createContext([]);function xe(){const e=h.useContext(Q);return $(t=>e.map(i=>t.iiif.entities.Canvas[i]).filter(Boolean),[e])}const te=()=>{},Y=h.createContext({setCurrentCanvasId:te,setCurrentCanvasIndex:te,nextCanvas:te,previousCanvas:te,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),li=e=>{const t=we(e.manifest),[i,n]=h.useState(""),[o,r]=h.useState([]),s=(typeof e.pagingEnabled>"u"||e.pagingEnabled)&&t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");h.useEffect(()=>{var p,w;t.manifest&&(n((p=t.manifest.items[0])==null?void 0:p.id),r([(w=t.manifest.items[0])==null?void 0:w.id]))},[t.manifest,e.manifest]);const a=h.useMemo(()=>{var p;return((p=t.manifest)==null?void 0:p.items.map(w=>w.id))||[]},[t.manifest,e.manifest]),l=h.useMemo(()=>a.indexOf(i),[a,i]),c=h.useCallback(()=>{if(a.length&&i){if(l===-1||(a[l+2]?l+2===a.length:l===a.length))return;const p=s&&l!==0?a[l+2]:a[l+1],w=s?l!==0?a[l+3]:a[l+2]:null;p&&(n(p),r(w?[p,w]:[p]))}},[s,a,i,l]),u=h.useCallback(()=>{if(a.length&&i){if(l===0||l===-1)return;const p=s&&l!==1?a[l-2]:a[l-1],w=s&&l!==1?a[l-1]:null;p&&(n(p),r(w?[p,w]:[p]))}},[s,a,i,l]),d=h.useCallback(p=>{const w=s&&p%2===1?p-1:p,C=a[w],F=s&&w!==0?a[w+1]:null;C&&(n(C),r(f=>{const y=F?[C,F]:[C];if(f.length===f.length){for(let x=0;x<f.length;x++)if(f[x]!==y[x])return y;return f}return y}))},[s,a]),v=h.useCallback(p=>{const w=a.indexOf(p);w!==-1&&d(w)},[a,d]),m=h.useMemo(()=>({setCurrentCanvasId:v,nextCanvas:c,previousCanvas:u,currentCanvasIndex:l,totalCanvases:a.length,setCurrentCanvasIndex:d,pagingView:!0}),[c,u,l,a,d,v]);return t.manifest?t.isLoaded?A.default.createElement(Y.Provider,{value:m},A.default.createElement(Q.Provider,{value:o},A.default.createElement(ve,{manifest:t.manifest.id},A.default.createElement(me,{canvas:i},e.children)))):A.default.createElement("div",null,"Loading..."):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),A.default.createElement("div",null,"Sorry, something went wrong."))};function ci(){return h.useContext(Y)}function ui(){return{VaultContext:h.useContext(U),ResourceContext:h.useContext(ee),SimpleViewerReactContext:h.useContext(Y),VisibleCanvasReactContext:h.useContext(Q)}}const fi=e=>A.default.createElement(ye,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},A.default.createElement(Q.Provider,{value:e.bridge.VisibleCanvasReactContext},A.default.createElement(Y.Provider,{value:e.bridge.SimpleViewerReactContext},e.children)));function W(e){return e.endsWith("info.json")?e:e.endsWith("/")?`${e}info.json`:`${e}/info.json`}const hi="http://library.stanford.edu/iiif/image-api/compliance.html#level0",Se="http://library.stanford.edu/iiif/image-api/compliance.html#level1",be="http://library.stanford.edu/iiif/image-api/compliance.html#level2",di="http://library.stanford.edu/iiif/image-api/conformance.html#level0",Oe="http://library.stanford.edu/iiif/image-api/conformance.html#level1",Ae="http://library.stanford.edu/iiif/image-api/conformance.html#level2",pi="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Ce="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Pe="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",gi="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",_e="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Ie="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",mi="http://iiif.io/api/image/1/level0.json",vi="http://iiif.io/api/image/1/profiles/level0.json",Ee="http://iiif.io/api/image/1/level1.json",$e="http://iiif.io/api/image/1/profiles/level1.json",je="http://iiif.io/api/image/1/level2.json",Me="http://iiif.io/api/image/1/profiles/level2.json",yi="http://iiif.io/api/image/2/level0.json",wi="http://iiif.io/api/image/2/profiles/level0.json",Te="http://iiif.io/api/image/2/level1.json",Fe="http://iiif.io/api/image/2/profiles/level1.json",ke="http://iiif.io/api/image/2/level2.json",Ve="http://iiif.io/api/image/2/profiles/level2.json",xi="level0",We="level1",Le="level2",Si="http://iiif.io/api/image/2/level0",ze="http://iiif.io/api/image/2/level1",Re="http://iiif.io/api/image/2/level2",Be=[Re,be,Ae,Pe,Ie,je,Me,ke,Ve,Le],He=[...Be,ze,Se,Oe,Ce,_e,Ee,$e,Te,Fe,We],bi=[Si,ze,Re,hi,Se,be,di,Oe,Ae,pi,Ce,Pe,gi,_e,Ie,mi,vi,Ee,$e,je,Me,yi,wi,Te,Fe,ke,Ve,xi,We,Le],Oi={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},Ai={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},Ci={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function Pi(e){return Be.indexOf(e)!==-1?Ci:He.indexOf(e)!==-1?Ai:Oi}function _i(e){const t=e?Array.isArray(e.profile)?e.profile:[e.profile]:[],i={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let n of t)if(typeof n=="string"&&(n=Pi(n)),!!n){if(n.formats)for(const o of n.formats)i.extraFormats.indexOf(o)===-1&&i.extraFormats.push(o);if(n.qualities)for(const o of n.qualities)i.extraQualities.indexOf(o)===-1&&i.extraQualities.push(o);if(n.supports)for(const o of n.supports)i.extraFeatures.indexOf(o)===-1&&i.extraFeatures.push(o);if(n.maxHeight&&(i.maxHeight=n.maxHeight),n.maxWidth&&(i.maxWidth=n.maxWidth),n.maxArea&&(i.maxArea=n.maxArea),n.extraFormats)for(const o of n.extraFormats)i.extraFormats.indexOf(o)===-1&&i.extraFormats.push(o);if(n.extraQualities)for(const o of n.extraQualities)i.extraQualities.indexOf(o)===-1&&i.extraQualities.push(o);if(n.extraFeatures)for(const o of n.extraFeatures)i.extraFeatures.indexOf(o)===-1&&i.extraFeatures.push(o);n.maxHeight&&(i.maxHeight=n.maxHeight),n.maxWidth&&(i.maxWidth=n.maxWidth),n.maxArea&&(i.maxArea=n.maxArea)}if(e.extraFormats)for(const n of e.extraFormats)i.extraFormats.indexOf(n)===-1&&i.extraFormats.push(n);if(e.extraFeatures)for(const n of e.extraFeatures)i.extraFeatures.indexOf(n)===-1&&i.extraFeatures.push(n);if(e.extraQualities)for(const n of e.extraQualities)i.extraQualities.indexOf(n)===-1&&i.extraQualities.push(n);return i}function Ii(e){try{if(e==="full")return{full:!0};if(e==="square")return{square:!0};const t=e.startsWith("pct:"),i=e.substr(t?4:0).split(",").map(n=>parseFloat(n));return{x:i[0],y:i[1],w:i[2],h:i[3],percent:t}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+e)}}function Ei(e){const t={upscaled:!1,max:!1,confined:!1};if(e[0]==="^"&&(t.upscaled=!0,e=e.slice(1)),e==="max"||e==="full")return t.max=!0,t.serialiseAsFull=e==="full",t;if(e[0]==="!"&&(t.confined=!0,e=e.slice(1)),e[0]==="p")return t.percentScale=parseFloat(e.slice(4)),t;const i=e.split(",").map(n=>n.trim());return i.length&&(i[0]!==""&&(t.width=parseInt(i[0],10)),i[1]!==""&&(t.height=parseInt(i[1],10))),t}function $i(e){const t={angle:0};if(e[0]==="!"&&(t.mirror=!0,e=e.substr(1)),t.angle=parseFloat(e)%360,Number.isNaN(t.angle))throw new Error(`Invalid rotation ${e}`);return t}function ji(e,t=""){const i=e.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!i)throw new Error(`Invalid or unknown input ${e}`);const n=i[2],o=i[3];let r=i[4];if(r[0]==="/"&&(r=r.substr(1)),t.length>0){if(t[0]==="/"&&(t=t.substr(1)),t!==r.substr(0,t.length))throw new Error(`Path does not start with prefix (path: ${r}, prefix: ${t})`);r=r.substr(t.length)}return{scheme:n,server:o,path:r,prefix:t}}function Mi(e,t=""){const{path:i,scheme:n,server:o,prefix:r}=ji(e,t),s=i.split("/").reverse(),[a,l,c,u,...d]=s,v=d.reverse().filter(Boolean).join("/");if(s.length===1||a==="")return{type:"base",scheme:n,server:o,prefix:r,identifier:v};if(a==="info.json"){const[,...p]=s;return{type:"info",scheme:n,server:o,prefix:r,identifier:p.reverse().filter(Boolean).join("/")}}const m=a.split(".");return{type:"image",scheme:n,server:o,prefix:r,identifier:v,originalPath:i,region:Ii(u),size:Ei(c),rotation:$i(l),quality:m[0],format:m[1]}}function Ti(e){const t=Mi(W(e.id));if(t.type!=="info")throw new Error("Invalid service URL");const i=_i(e);return{identifier:t.identifier,originalPath:"",server:t.server,prefix:t.prefix,scheme:t.scheme,type:"image",quality:i.extraQualities.indexOf("default")===-1?i.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}}function Fi(e,t,i){const n=i.length,o=[];for(let r=0;r<n;r++){const s=i[r].width;o.push(e/s)}return o}function ki(e,t,i){const n=i.length,o=[];for(let r=0;r<n;r++){const s=i[r];o.push({width:Math.floor(e/s),height:Math.floor(t/s)})}return o}function S(e){if(e["@id"])return e["@id"];if(e.id)return e.id}function se(e){if(!e||!e.profile||!S(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if(typeof i=="string"&&bi.indexOf(i)!==-1)return!0;return!1}function Vi(e){if(!se(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if(typeof i=="string"){if(He.indexOf(i)!==-1)return!0}else{const n=[...i.supports||[],...i.extraFeatures||[]];if(n.indexOf("regionByPx")!==-1&&(n.indexOf("sizeByW")!==-1||n.indexOf("sizeByWh")!==-1))return!0}return!1}function Wi(e){if(!Vi(e))return[];const t=[],i=Array.isArray(e.profile)?e.profile:[e.profile],n=i.length;for(let o=0;o<n;o++){const r=i[o];if(typeof r!="string"&&(r.maxHeight||r.maxWidth))return[{id:S(e),type:"variable",minWidth:0,minHeight:0,maxHeight:r.maxHeight||r.maxWidth,maxWidth:r.maxWidth||r.maxHeight}]}if(e.tiles){const o=e.tiles.length;for(let r=0;r<o;r++){const s=e.tiles[r];(s.height||s.width)&&t.push({id:S(e),type:"variable",minHeight:0,minWidth:0,maxHeight:s.height||s.width,maxWidth:s.width})}}return t}function De(e){const t=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,i=e.match(t);if(i){const n=i[1],o=parseInt(i[4],10),r=parseInt(i[5],10),s=i[7];if((n==="max"||n==="full")&&o&&r&&s)return{type:"fixed",id:e,height:r,width:o}}return{type:"unknown",id:e}}function Li(e){if(e["@type"])return e["@type"];if(e.type)return e.type}function zi(e){if(typeof e=="string")return De(e);const t=Li(e);if(t!=="Image"&&t!=="sc:Image")return null;const i=e,n=S(i);return n?n&&i.width&&i.height?{id:n,type:"fixed",width:i.width,height:i.height,unsafe:!0}:De(n):null}function Ri(e){return se(e)?(e&&e.sizes?e.sizes:[]).map(t=>({id:S(e),type:"fixed-service",height:t.height,width:t.width})):[]}function qe(e){const t=[],i=e.length;for(let n=0;n<i;n++){const o=Ri(e[n]);o.length&&t.push(...o);const r=Wi(e[n]);r.length&&t.push(...r)}return t}function G(e){const t=e.service?Array.isArray(e.service)?e.service:[e.service]:[],i=t.length,n=[];for(let o=0;o<i;o++)se(t[o])&&n.push(t[o]);return n}function Bi(e,t=!0,i){const n=[],o=zi(e);if(o===null)return n;const r=e;if(n.push(o),t&&r.width&&r.height){const s=[],a=G(r);for(const l of a){const c={id:S(l),width:r.width,height:r.height};if(i.canLoadSync(c)){const u=i.loadServiceSync(c);u&&(u.height||(u.height=r.height),u.width||(u.width=r.width),s.push(...qe([u])))}}if(s.length)return n.push(...s),n}return r.service&&n.push(...qe(r.service)),n}function Hi({x:e=0,y:t=0,w:i,h:n,full:o,square:r,percent:s}){if(o)return"full";if(r)return"square";if(typeof i>"u"||typeof n>"u")throw new Error("RegionParameter: invalid region");const a=`${e},${t},${i},${n}`;return s?`pct:${a}`:a}function Di({max:e,percentScale:t,upscaled:i,confined:n,width:o,height:r,serialiseAsFull:s}){const a=[];return i&&a.push("^"),e?(a.push(s?"full":"max"),a.join("")):(n&&a.push("!"),t&&a.push(`pct:${t}`),o&&a.push(`${o}`),a.push(","),r&&a.push(`${r}`),a.join(""))}function qi(e){return`${e.mirror?"!":""}${(e.angle||0)%360}`}var Ni=Object.defineProperty,Ui=Object.defineProperties,Qi=Object.getOwnPropertyDescriptors,Ne=Object.getOwnPropertySymbols,Yi=Object.prototype.hasOwnProperty,Gi=Object.prototype.propertyIsEnumerable,Ue=(e,t,i)=>t in e?Ni(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Z=(e,t)=>{for(var i in t||(t={}))Yi.call(t,i)&&Ue(e,i,t[i]);if(Ne)for(var i of Ne(t))Gi.call(t,i)&&Ue(e,i,t[i]);return e},J=(e,t)=>Ui(e,Qi(t));function Zi(e,t){const i=e.prefix.startsWith("/")?e.prefix.substr(1):e.prefix,n=`${e.scheme}://${e.server}/${i?`${i}/`:""}${e.identifier}`;if(e.type==="base")return n;if(e.type==="info")return`${n}/info.json`;let{region:o,size:r,rotation:s,format:a,quality:l}=e;if(t){const c=t["@context"]?Array.isArray(t["@context"])?t["@context"]:[t["@context"]]:[],u=c.indexOf("http://iiif.io/api/image/2/context.json")!==-1,d=c.indexOf("http://iiif.io/api/image/3/context.json")!==-1;if((r.width===t.width&&!r.height||r.height===t.height&&!r.width||r.width===t.width&&r.height===t.height)&&(r=J(Z({},r),{max:!0})),u&&(r.max&&!r.serialiseAsFull&&(r=J(Z({},r),{serialiseAsFull:!0})),!r.max&&r.width&&r.height&&(r=J(Z({},r),{height:void 0}))),d&&(r.max&&r.serialiseAsFull&&(r=J(Z({},r),{serialiseAsFull:!1})),r.width&&!r.height&&t.width&&t.height)){const v=t.height/t.width;r=J(Z({},r),{height:Math.ceil(r.width*v)})}}return[n,Hi(o),Di(r),qi(s),`${l}.${a}`].filter(Boolean).join("/")}function ae(e,t,i){const n=Ti({id:W(S(e)),profile:"level2",type:"ImageService2"});if(n.type!=="image")throw new Error("Invalid service");return n.size.max=!1,n.size.width=t,n.size.height=i,{id:Zi(n),type:"fixed",width:t,height:i||e.height/(e.width||1)*t,unsafe:e.width>t}}function z(e){const t=e.replace(/(https?:\/\/)?(www.)?/i,"");return t.indexOf("/")!==-1?t.split("/")[0]:t}function Ji(e,t,i){const n=e.width?e.width:e.maxWidth;return i.height<=e.maxHeight&&i.width<=e.maxWidth&&i.height>=e.minHeight&&i.width>=e.minWidth&&(!t||Math.abs(i.width-n)<Math.abs(t.width-n))}function Xi(e,t){const i=[],n=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},e),o=[],r=[];let s=null;const a=(c,u)=>{if(Ji(n,u,c)){if(n.preferFixedSize&&c.unsafe){r.push(c);return}n.returnAllOptions&&u&&r.push(u),s=c}else n.returnAllOptions&&r.push(c)},l=t.length;for(let c=0;c<l;c++){const u=t[c](),d=u.length;for(let v=0;v<d;v++){const m=u[v];if(m.type==="unknown"&&n.atAnyCost&&o.push(m),m.type==="fixed"&&(m.unsafe?o.push(m):a(m,s)),m.type==="fixed-service")if(n.unsafeImageService){const p=ae(m,n.width,n.height);a(p,s)}else{const p=ae(m,m.width,m.height);a(p,s)}if(m.type==="variable"&&m.maxWidth){const p=ae({id:m.id,type:"fixed-service",width:m.maxWidth,height:m.maxWidth},m.maxWidth);a(p,s)}}if(s&&!n.returnAllOptions){if(s.unsafe||n.allowUnsafe)continue;break}}return n.atAnyCost&&r.length===0?{best:s||o[0],fallback:o.slice(1),log:i}:n.returnAllOptions?{best:n.atAnyCost?s||r[0]||o[0]:s||r[0],fallback:[...r,...o],log:i}:{best:s||r[0]||null,fallback:s?r:r.slice(1),log:i}}var Ki=Object.defineProperty,en=Object.defineProperties,tn=Object.getOwnPropertyDescriptors,Qe=Object.getOwnPropertySymbols,nn=Object.prototype.hasOwnProperty,rn=Object.prototype.propertyIsEnumerable,Ye=(e,t,i)=>t in e?Ki(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,on=(e,t)=>{for(var i in t||(t={}))nn.call(t,i)&&Ye(e,i,t[i]);if(Qe)for(var i of Qe(t))rn.call(t,i)&&Ye(e,i,t[i]);return e},sn=(e,t)=>en(e,tn(t));function an(e,t,i){const n=e>t?e:t,o=i.length,r=[];for(let s=0;s<o;s++){const a=i[s];let l=a.scaleFactors[0],c=n/l;const u=[l];for(;c>=a.width;)l=l*2,u.push(l),c=c/2;r.push(sn(on({},a),{scaleFactors:u}))}return r}function ln(e,t){if(e.length!==t.length)return!1;if(e.length===0&&t.length===0)return!0;const i=e.length;let n=!0;for(let r=0;r<i;r++){const s=e[r],a=t[r];if(s.width!==a.width||s.height!==a.height){n=!1;break}}if(n)return!0;let o=0;for(let r=0;r<i;r++)for(let s=0;s<i;s++)if(e[r].width===t[s].width&&e[r].height===t[s].height){o++;break}return o===i}var L=(e,t,i)=>new Promise((n,o)=>{var r=l=>{try{a(i.next(l))}catch(c){o(c)}},s=l=>{try{a(i.throw(l))}catch(c){o(c)}},a=l=>l.done?n(l.value):Promise.resolve(l.value).then(r,s);a((i=i.apply(e,t)).next())});class Ge{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(t){Object.assign(this.config,t)}sample(t,i,n=!0){const o=z(S(t)),r=W(S(t)),s=this.knownImageServers[o];return this.imageServices[r]=Object.assign(t,{real:!0}),s?this.verify(t):(this.knownImageServers[o]={verifications:0,malformed:!1,root:o,preLoaded:n,sampledId:S(t),verified:!1,server:null,result:{context:t["@context"]||[],sampledProfile:t.profile,resourceServiceRatio:i&&t.height?i.height/t.height:1,sampledSizes:t.sizes||[],sizeRatios:Fi(t.width,t.height,t.sizes||[]),sampledTiles:t.tiles||[]}},!0)}preLoad(t,i=!0){this.knownImageServers[t.root]=t,i&&(this.knownImageServers[t.root].malformed=!1,this.knownImageServers[t.root].verifications=this.config.verificationsRequired)}predict(t,i=!1,n=!1){const o=z(S(t)),r=this.knownImageServers[o];if(!r||!r.result||!n&&(r.malformed||r.verifications<this.config.verificationsRequired))return null;const s=W(S(t));return this.imageServices[s]||(this.imageServices[s]={"@context":r.result.context,"@id":S(t),id:S(t),protocol:"http://iiif.io/api/image",tiles:an(t.width,t.height,r.result.sampledTiles),sizes:ki(Math.floor(t.width/r.result.resourceServiceRatio),Math.floor(t.height/r.result.resourceServiceRatio),r.result.sizeRatios),profile:r.result.sampledProfile,height:t.height,width:t.width,real:!1}),this.imageServices[s]}getThumbnailFromResource(t,i){return L(this,arguments,function*(n,o,r=!0,s=[]){const a=yield this.getImageCandidates(n,r);return Xi(o,[()=>s,()=>a])})}getImageCandidates(t,i=!0){return L(this,null,function*(){const n=t;if(i&&n.height&&n.width){const o=G(n);for(const r of o){const s={id:S(r),width:r.width?r.width:n.width,height:r.height?r.height:n.height};yield this.loadService(s)}}return Bi(t,i,this)})}verify(t){return L(this,null,function*(){const i=this.predict(t,!1,!0),n=yield this.fetchService(S(t));if(!i)return!1;const o=i.height===n.height&&i.width===n.width&&i["@context"]===n["@context"]&&ln(i.sizes||[],n.sizes||[]);if(o){const r=z(S(t));this.knownImageServers[r].verifications+=1,this.knownImageServers[r].verifications>=this.config.verificationsRequired&&(this.knownImageServers[r].verified=!0)}return o})}canLoadSync(t){const i=typeof t=="string"?t:S(t),n=W(i);if(this.imageServices[n])return!0;const o=this.knownImageServers[z(i)];return o&&!o.malformed&&o.verifications>=this.config.verificationsRequired}markAsMalformed(t){return L(this,null,function*(){return this.knownImageServers[z(S(t))].malformed=!0,this.loadService(t,!0)})}fetchService(t,i=!1){return L(this,null,function*(){const n=W(t);if(this.imageServices[n]&&(!i||this.imageServices[n].real))return this.imageServices[n];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const o=yield this.fetch(n).then(r=>r.json());return!o.id&&o["@id"]&&(o.id=o["@id"]),o.id!==t&&(o.id=t,o["@id"]&&(o["@id"]=t)),this.imageServices[n]=Object.assign(o,{real:!0}),this.imageServices[n]})}fetch(t,i){return L(this,null,function*(){return fetch(t,i)})}loadService(t,i=!1){return L(this,null,function*(){if(!this.config.disableThrottling){let r=!0;for(;r;)if(this.fetchingCount>=this.config.verificationsRequired)yield new Promise(s=>setTimeout(s,500));else{r=!1;break}}const n=this.knownImageServers[z(S(t))];if(n&&!n.malformed&&!i){yield n.result;const r=this.loadServiceSync(t);if(r)return r}this.fetchingCount++;const o=yield this.fetchService(S(t),i);return this.fetchingCount--,o.real&&this.sample(o,t),o})}loadServiceSync(t){const i=W(S(t));return this.imageServices[i]?this.imageServices[i]:this.predict(t)}}new Ge;const Ze=A.default.createContext(new Ge);function ie(){return h.useContext(Ze)}const cn=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,un=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function ne(e){if(Array.isArray(e))return e.reduce((t,i)=>{const{selector:n,selectors:o}=ne(i);return n&&(t.selector||(t.selector=n),t.selectors.push(...o)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,i]=e.split("#");return i?ne({type:"FragmentSelector",value:i}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=cn.exec(e.value);if(t){const n={type:"BoxSelector",spatial:{unit:t[2]==="percent:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:n,selectors:[n]}}const i=e.value.match(un);if(i){const n={type:"TemporalSelector",temporal:{startTime:i[4]?parseFloat(i[4]):0,endTime:i[7]?parseFloat(i[7]):void 0}};return{selector:n,selectors:[n]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}var fn=Object.defineProperty,hn=Object.defineProperties,dn=Object.getOwnPropertyDescriptors,Je=Object.getOwnPropertySymbols,pn=Object.prototype.hasOwnProperty,gn=Object.prototype.propertyIsEnumerable,Xe=(e,t,i)=>t in e?fn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Ke=(e,t)=>{for(var i in t||(t={}))pn.call(t,i)&&Xe(e,i,t[i]);if(Je)for(var i of Je(t))gn.call(t,i)&&Xe(e,i,t[i]);return e},et=(e,t)=>hn(e,dn(t));function T(e,t={}){if(Array.isArray(e))return T(e[0]);if(typeof e=="string"){const[i,n]=e.split("#");return n?T({type:"SpecificResource",source:{id:i,type:"Unknown"},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{id:i,type:t.typeMap&&t.typeMap[i]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return T(e.items[0]);if(e.type==="SpecificResource"){e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]);const{selector:i,selectors:n}=e.selector?ne(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:i,selectors:n}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[i,n]=e.id.split("#");return n?T({type:"SpecificResource",source:et(Ke({},e),{id:i}),selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:et(Ke({},e),{id:i}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function tt(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function it(e,t,i){const n=[];let o=null;const r=[];for(const s of t){const a=e.get(s.body);for(const l of a){const[c,{selector:u}]=tt(l),d=(c.type||"unknown").toLowerCase();if(d==="choice"){const v=e.get(c.items),m=i.length?i.map(p=>v.find(w=>w.id===p)).filter(Boolean):[v[0]];m.length===0&&m.push(v[0]),o={type:"single-choice",items:v.map(p=>({id:p.id,label:p.label,selected:m.indexOf(p)!==-1})),label:l.label},a.push(...m);continue}n.indexOf(d)===-1&&n.push(d),r.push({type:d,resource:c,target:s.target,selector:u})}}return{types:n,items:r,choice:o}}const nt={makeChoice:()=>{}},le={type:"unknown"},j=e=>({type:"unknown",reason:e,annotations:{pages:[]}});function rt(e,t,i){const n=[];for(const o of t.items){const r=o.resource&&o.resource.type==="SpecificResource"?o.resource.source:o.resource;if(!r.id)return j("No resource Identifier");let s;if(r.service){const w=G(r);w[0]&&(s=i(w[0],e))}const{selector:a,source:l}=T(o.target);if(l.id!==e.id)continue;const c={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},u=a?a.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:a.temporal,spatial:c.spatial}:a:null,d={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},v=o.resource.type==="SpecificResource"?T(o.resource):null,m=v&&v.selector&&(v.selector.type==="BoxSelector"||v.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:v.selector.spatial.x,y:v.selector.spatial.y,width:v.selector.spatial.width,height:v.selector.spatial.height}}:d,p={id:r.id,type:"Image",width:u?r.width:e.width,height:u?r.height:e.height,service:s,sizes:s&&s.sizes?s.sizes:r.width&&r.height?[{width:r.width,height:r.height}]:[],target:u&&u.type!=="PointSelector"?u:c,selector:m};n.push(p)}return{type:"images",image:n[0],images:n,choice:t.choice}}var mn=Object.defineProperty,vn=Object.defineProperties,yn=Object.getOwnPropertyDescriptors,ot=Object.getOwnPropertySymbols,wn=Object.prototype.hasOwnProperty,xn=Object.prototype.propertyIsEnumerable,st=(e,t,i)=>t in e?mn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Sn=(e,t)=>{for(var i in t||(t={}))wn.call(t,i)&&st(e,i,t[i]);if(ot)for(var i of ot(t))xn.call(t,i)&&st(e,i,t[i]);return e},bn=(e,t)=>vn(e,yn(t));function On(e={},t=[]){const{id:i,selector:n}=e,o=k(),r=I(),s=i||o.annotation,a=$(c=>s?c.iiif.entities.Annotation[s]:void 0,[s]),l=$(c=>a&&a.body?a.body.map(u=>u?c.iiif.entities[u.type][u.id]:null).filter(Boolean):[],[a]);return h.useMemo(()=>{if(!a)return;const c=bn(Sn({},a),{body:l,target:T(a.target,{typeMap:r.getState().iiif.mapping})});return n?n(c):c},[a,n,l,...t])}function X(e={},t=[]){const{id:i,selector:n}=e,o=k();I();const r=i||o.manifest,s=$(a=>r?a.iiif.entities.Manifest[r]:void 0,[r]);return h.useMemo(()=>{if(!!s)return n?n(s):s},[s,n,...t])}function R(e={},t=[]){const{id:i,selector:n}=e,o=k(),r=i||o.canvas,s=$(a=>r?a.iiif.entities.Canvas[r]:void 0,[r]);return h.useMemo(()=>{if(!!s)return n?n(s):s},[s,n,...t])}function An(e,t){var i;const n=(i=e==null?void 0:e.iiif)==null?void 0:i.meta[t];return n?n.annotationPageManager:null}function Cn(e,t){return $(i=>{const n=[];if(!e)return n;const o=Object.keys(i.iiif.entities.AnnotationPage);for(const r of o)if(!t||t.indexOf(r)!==-1){const s=An(i,r);s&&s.views&&s.views[e]&&n.push(r)}return n},[e,t])}function at({canvas:e,manifest:t,all:i,canvases:n}){const o=[];if(t)for(const r of t.annotations)o.indexOf(r.id)===-1&&o.push(r.id);if(i){if(n&&n.length)for(const r of n)for(const s of r.annotations)o.indexOf(s.id)===-1&&o.push(s.id)}else if(e)for(const r of e.annotations)o.indexOf(r.id)===-1&&o.push(r.id);return o}var Pn=Object.defineProperty,_n=Object.defineProperties,In=Object.getOwnPropertyDescriptors,lt=Object.getOwnPropertySymbols,En=Object.prototype.hasOwnProperty,$n=Object.prototype.propertyIsEnumerable,ct=(e,t,i)=>t in e?Pn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,ut=(e,t)=>{for(var i in t||(t={}))En.call(t,i)&&ct(e,i,t[i]);if(lt)for(var i of lt(t))$n.call(t,i)&&ct(e,i,t[i]);return e},ft=(e,t)=>_n(e,In(t));function jn(e,t){var i;const n=(i=e==null?void 0:e.iiif)==null?void 0:i.meta[t];return n?n.annotationPageManager:null}function ht(e,t={}){const i=I(),n=X(),o=R(),r=xe(),s=h.useMemo(()=>at({all:t.all,manifest:n,canvas:o,canvases:r}),[t.all,o,r,n]),a=Cn(e,t.all?void 0:s),l=h.useCallback(u=>{!e||i.setMetaValue([u,"annotationPageManager","views"],d=>d&&!d[e]?d:ft(ut({},d||{}),{[e]:!1}))},[e,i]),c=h.useCallback((u,d={})=>{if(!e)return;const v=i.getState(),m=[];if(d==null?void 0:d.deselectOthers){const p=Object.keys(v.iiif.entities.AnnotationPage);for(const w of p){const C=jn(v,w);C&&C.views&&C.views[e]&&m.push(w)}}for(const p of m)l(p);i.setMetaValue([u,"annotationPageManager","views"],p=>p&&p[e]?p:ft(ut({},p||{}),{[e]:!0}))},[e,l,i]);return{availablePageIds:s,enabledPageIds:a,setPageEnabled:c,setPageDisabled:l}}function re(e={}){const t=R(e.canvasId?{id:e.canvasId}:void 0);return $((i,n)=>{if(!t)return[];const o=n.get(t.items),r=[];for(const s of o)r.push(...n.get(s.items));return r},[t])}function Mn(e,t={}){return re(t)}function Tn(e,t=!1){}function Fn(e,t=[]){const{id:i,selector:n}=e,o=k(),r=i||o.collection,s=$(a=>r?a.iiif.entities.Collection[r]:void 0,[r]);return h.useMemo(()=>{if(!!s)return n?n(s):s},[s,n,...t])}function dt(){const t=I().getStore();return h.useMemo(()=>i=>t.dispatch(i),[t])}function pt(e){return{addEventListener(t,i,n,o){if(t)return e.setMetaValue([t.id,"eventManager",i],r=>{const s=r||[];for(const a of s)if(a.callback===n)return s;return[...s,{callback:n,scope:o}]}),n},removeEventListener(t,i,n){!t||e.setMetaValue([t.id,"eventManager",i],o=>(o||[]).filter(r=>r.callback!==n))},getListenersAsProps(t,i){const n=typeof t=="string"?{id:t}:t;if(!n||!n.id)return{};const o=e.getResourceMeta(n.id,"eventManager"),r={};if(o&&n)for(const s of Object.keys(o))r[s]=a=>{const l=e.get(n);for(const{callback:c,scope:u}of o[s]||[])(!u||i&&u.indexOf(i)!==-1)&&c(a,l)};return r}}}function gt(e){return{applyStyles(t,i,n){const o=typeof t=="string"?t:t.id;return e.setMetaValue([o,"styles",i],n)},getAppliedStyles(t){const i=typeof t=="string"?t:t.id;return e.getResourceMeta(i,"styles")}}}function B(e){return e.endsWith("info.json")?e:e.endsWith("/")?`${e}info.json`:`${e}/info.json`}function kn(e,t,i){const n=i.length,o=[];for(let r=0;r<n;r++){const s=i[r].width;o.push(e/s)}return o}function Vn(e,t,i){const n=i.length,o=[];for(let r=0;r<n;r++){const s=i[r];o.push({width:Math.floor(e/s),height:Math.floor(t/s)})}return o}const Wn="http://library.stanford.edu/iiif/image-api/compliance.html#level0",mt="http://library.stanford.edu/iiif/image-api/compliance.html#level1",vt="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Ln="http://library.stanford.edu/iiif/image-api/conformance.html#level0",yt="http://library.stanford.edu/iiif/image-api/conformance.html#level1",wt="http://library.stanford.edu/iiif/image-api/conformance.html#level2",zn="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",xt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",St="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Rn="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",bt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Ot="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Bn="http://iiif.io/api/image/1/level0.json",Hn="http://iiif.io/api/image/1/profiles/level0.json",At="http://iiif.io/api/image/1/level1.json",Ct="http://iiif.io/api/image/1/profiles/level1.json",Pt="http://iiif.io/api/image/1/level2.json",_t="http://iiif.io/api/image/1/profiles/level2.json",Dn="http://iiif.io/api/image/2/level0.json",qn="http://iiif.io/api/image/2/profiles/level0.json",It="http://iiif.io/api/image/2/level1.json",Et="http://iiif.io/api/image/2/profiles/level1.json",$t="http://iiif.io/api/image/2/level2.json",jt="http://iiif.io/api/image/2/profiles/level2.json",Nn="level0",Mt="level1",Tt="level2",Un="http://iiif.io/api/image/2/level0",Ft="http://iiif.io/api/image/2/level1",kt="http://iiif.io/api/image/2/level2",Qn=[Ft,kt,mt,vt,yt,wt,xt,St,bt,Ot,At,Ct,Pt,_t,It,Et,$t,jt,Mt,Tt],Yn=[Un,Ft,kt,Wn,mt,vt,Ln,yt,wt,zn,xt,St,Rn,bt,Ot,Bn,Hn,At,Ct,Pt,_t,Dn,qn,It,Et,$t,jt,Nn,Mt,Tt];function b(e){if(e["@id"])return e["@id"];if(e.id)return e.id}function ce(e){if(!e||!e.profile||!b(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if(typeof i=="string"&&Yn.indexOf(i)!==-1)return!0;return!1}function Gn(e){if(!ce(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if(typeof i=="string"){if(Qn.indexOf(i)!==-1)return!0}else{const n=i.supports||[];if(n.indexOf("regionByPx")!==-1&&(n.indexOf("sizeByW")!==-1||n.indexOf("sizeByWh")!==-1))return!0}return!1}function Zn(e){if(!Gn(e))return[];const t=[],i=Array.isArray(e.profile)?e.profile:[e.profile],n=i.length;for(let o=0;o<n;o++){const r=i[o];if(typeof r!="string"&&(r.maxHeight||r.maxWidth))return[{id:b(e),type:"variable",minWidth:0,minHeight:0,maxHeight:r.maxHeight||r.maxWidth,maxWidth:r.maxWidth||r.maxHeight}]}if(e.tiles){const o=e.tiles.length;for(let r=0;r<o;r++){const s=e.tiles[r];(s.height||s.width)&&t.push({id:b(e),type:"variable",minHeight:0,minWidth:0,maxHeight:s.height||s.width,maxWidth:s.width})}}return t}function Vt(e){const t=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,i=e.match(t);if(i){const n=i[1],o=parseInt(i[4],10),r=parseInt(i[5],10),s=i[7];if((n==="max"||n==="full")&&o&&r&&s)return{type:"fixed",id:e,height:r,width:o}}return{type:"unknown",id:e}}function Jn(e){if(e["@type"])return e["@type"];if(e.type)return e.type}function ue(e){if(typeof e=="string")return Vt(e);const t=Jn(e);if(t!=="Image"&&t!=="sc:Image")return null;const i=e,n=b(i);return n?n&&i.width&&i.height?{id:n,type:"fixed",width:i.width,height:i.height,unsafe:!0}:Vt(n):null}function Xn(e){return ce(e)?(e&&e.sizes?e.sizes:[]).map(t=>({id:b(e),type:"fixed-service",height:t.height,width:t.width})):[]}function Wt(e){const t=[],i=e.length;for(let n=0;n<i;n++){const o=Xn(e[n]);o.length&&t.push(...o);const r=Zn(e[n]);r.length&&t.push(...r)}return t}function Lt(e){const t=e.service?Array.isArray(e.service)?e.service:[e.service]:[],i=t.length,n=[];for(let o=0;o<i;o++)ce(t[o])&&n.push(t[o]);return n}function Kn(e,t=!0,i){const n=[],o=ue(e);if(o===null)return n;const r=e;if(n.push(o),t&&r.width&&r.height){const s=[],a=Lt(r);for(const l of a){const c={id:b(l),width:r.width,height:r.height};if(i.canLoadSync(c)){const u=i.loadServiceSync(c);u&&(u.height||(u.height=r.height),u.width||(u.width=r.width),s.push(...Wt([u])))}}if(s.length)return n.push(...s),n}return r.service&&n.push(...Wt(r.service)),n}function fe(e,t,i){return{id:[B(b(e)).slice(0,-10),"full",[t,i||""].join(","),0,"default.jpg"].join("/"),type:"fixed",width:t,height:i||e.height/e.width*t,unsafe:e.width>t}}function H(e){const t=e.replace(/(https?:\/\/)?(www.)?/i,"");return t.indexOf("/")!==-1?t.split("/")[0]:t}function er(e,t,i){const n=e.width?e.width:e.maxWidth;return i.height<=e.maxHeight&&i.width<=e.maxWidth&&i.height>=e.minHeight&&i.width>=e.minWidth&&(!t||Math.abs(i.width-n)<Math.abs(t.width-n))}function tr(e,t){const i=[],n=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},e),o=[],r=[];let s=null;const a=(c,u)=>{if(er(n,u,c)){if(n.preferFixedSize&&c.unsafe){r.push(c);return}n.returnAllOptions&&u&&r.push(u),s=c}else n.returnAllOptions&&r.push(c)},l=t.length;for(let c=0;c<l;c++){const u=t[c](),d=u.length;for(let v=0;v<d;v++){const m=u[v];if(m.type==="unknown"&&n.atAnyCost&&o.push(m),m.type==="fixed"&&(m.unsafe?o.push(m):a(m,s)),m.type==="fixed-service")if(n.unsafeImageService){const p=fe(m,n.width,n.height);a(p,s)}else{const p=fe(m,m.width,m.height);a(p,s)}if(m.type==="variable"&&m.maxWidth){const p=fe({id:m.id,type:"fixed-service",width:m.maxWidth,height:m.maxWidth},m.maxWidth);a(p,s)}}if(s&&!n.returnAllOptions){if(s.unsafe||n.allowUnsafe)continue;break}}return n.atAnyCost&&r.length===0?{best:s||o[0],fallback:o.slice(1),log:i}:n.returnAllOptions?{best:n.atAnyCost?s||r[0]||o[0]:s||r[0],fallback:[...r,...o],log:i}:{best:s||r[0]||null,fallback:s?r:r.slice(1),log:i}}function ir(e,t,i){const n=e>t?e:t,o=i.length,r=[];for(let s=0;s<o;s++){const a=i[s];let l=a.scaleFactors[0],c=n/l;const u=[l];for(;c>=a.width;)l=l*2,u.push(l),c=c/2;r.push(Object.assign(Object.assign({},a),{scaleFactors:u}))}return r}function nr(e,t){if(e.length!==t.length)return!1;if(e.length===0&&t.length===0)return!0;const i=e.length;let n=!0;for(let r=0;r<i;r++){const s=e[r],a=t[r];if(s.width!==a.width||s.height!==a.height){n=!1;break}}if(n)return!0;let o=0;for(let r=0;r<i;r++)for(let s=0;s<i;s++)if(e[r].width===t[s].width&&e[r].height===t[s].height){o++;break}return o===i}/*! *****************************************************************************
|
|
2
2
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
3
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
4
4
|
this file except in compliance with the License. You may obtain a copy of the
|
|
@@ -11,4 +11,4 @@
|
|
|
11
11
|
|
|
12
12
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
13
13
|
and limitations under the License.
|
|
14
|
-
***************************************************************************** */function X(t,e,r,n){function o(i){return i instanceof r?i:new r(function(a){a(i)})}return new(r||(r=Promise))(function(i,a){function s(f){try{l(n.next(f))}catch(p){a(p)}}function u(f){try{l(n.throw(f))}catch(p){a(p)}}function l(f){f.done?i(f.value):o(f.value).then(s,u)}l((n=n.apply(t,e||[])).next())})}class $r{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(e){Object.assign(this.config,e)}sample(e,r,n=!0){const o=Z(_(e)),i=J(_(e)),a=this.knownImageServers[o];return this.imageServices[i]=Object.assign(e,{real:!0}),a?this.verify(e):(this.knownImageServers[o]={verifications:0,malformed:!1,root:o,preLoaded:n,sampledId:_(e),verified:!1,server:null,result:{context:e["@context"]||[],sampledProfile:e.profile,resourceServiceRatio:r&&e.height?r.height/e.height:1,sampledSizes:e.sizes||[],sizeRatios:Io(e.width,e.height,e.sizes||[]),sampledTiles:e.tiles||[]}},!0)}preLoad(e,r=!0){this.knownImageServers[e.root]=e,r&&(this.knownImageServers[e.root].malformed=!1,this.knownImageServers[e.root].verifications=this.config.verificationsRequired)}predict(e,r=!1,n=!1){const o=Z(_(e)),i=this.knownImageServers[o];if(!i||!i.result||!n&&(i.malformed||i.verifications<this.config.verificationsRequired))return null;const a=J(_(e));return this.imageServices[a]||(this.imageServices[a]={"@context":i.result.context,"@id":_(e),id:_(e),protocol:"http://iiif.io/api/image",tiles:Go(e.width,e.height,i.result.sampledTiles),sizes:$o(Math.floor(e.width/i.result.resourceServiceRatio),Math.floor(e.height/i.result.resourceServiceRatio),i.result.sizeRatios),profile:i.result.sampledProfile,height:e.height,width:e.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(e,r,n=!0,o=[]){return X(this,void 0,void 0,function*(){const i=yield this.getImageCandidates(e,n);return No(r,[()=>o,()=>i])})}getImageCandidates(e,r=!0){return X(this,void 0,void 0,function*(){const n=e;if(r&&n.height&&n.width){const o=Ir(n);for(const i of o){const a={id:_(i),width:i.width?i.width:n.width,height:i.height?i.height:n.height};yield this.loadService(a)}}return Ho(e,r,this)})}verify(e){return X(this,void 0,void 0,function*(){const r=this.predict(e,!1,!0),n=yield this.fetchService(_(e));if(!r)return!1;const o=r.height===n.height&&r.width===n.width&&r["@context"]===n["@context"]&&Ko(r.sizes||[],n.sizes||[]);if(o){const i=Z(_(e));this.knownImageServers[i].verifications+=1,this.knownImageServers[i].verifications>=this.config.verificationsRequired&&(this.knownImageServers[i].verified=!0)}return o})}canLoadSync(e){const r=typeof e=="string"?e:_(e),n=J(r);if(this.imageServices[n])return!0;const o=this.knownImageServers[Z(r)];return o&&!o.malformed&&o.verifications>=this.config.verificationsRequired}markAsMalformed(e){return X(this,void 0,void 0,function*(){return this.knownImageServers[Z(_(e))].malformed=!0,this.loadService(e,!0)})}fetchService(e,r=!1){return X(this,void 0,void 0,function*(){const n=J(e);if(this.imageServices[n]&&(!r||this.imageServices[n].real))return this.imageServices[n];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const o=yield fetch(n).then(i=>i.json());return!o.id&&o["@id"]&&(o.id=o["@id"]),o.id!==e&&(o.id=e,o["@id"]&&(o["@id"]=e)),this.imageServices[n]=Object.assign(o,{real:!0}),this.imageServices[n]})}loadService(e,r=!1){return X(this,void 0,void 0,function*(){if(!this.config.disableThrottling)for(;this.fetchingCount>=this.config.verificationsRequired;)yield new Promise(i=>setTimeout(i,500));const n=this.knownImageServers[Z(_(e))];if(n&&!n.malformed&&!r){yield n.result;const i=this.loadServiceSync(e);if(i)return i}this.fetchingCount++;const o=yield this.fetchService(_(e),r);return this.fetchingCount--,o.real&&this.sample(o,e),o})}loadServiceSync(e){const r=J(_(e));return this.imageServices[r]?this.imageServices[r]:this.predict(e)}}new $r;function Yo(t,e={}){const r=e.imageServiceLoader||new $r;async function n(o,i,a,s=[],u){if(typeof o=="string")return{best:je(o),fallback:[],log:[]};const l=t.get(o);if(typeof l=="string")return{best:je(l),fallback:[],log:[]};switch(l.type){case"Annotation":{const f=l.body,p=t.get(f[0]);return u&&!p.width&&(p.width=u.width,p.height=u.height),await r.getThumbnailFromResource(p,i,a,s)}case"Canvas":{const f=l;if(f.thumbnail&&f.thumbnail.length){const p=t.get(f.thumbnail[0]),d=await r.getImageCandidates(p,a);d&&d.length&&s.push(...d)}return n(f.items[0],i,a,s,{width:f.width,height:f.height})}case"AnnotationPage":return n(l.items[0],i,a,s,u);case"Choice":return n(l.items[0],i,a,s,u);case"Collection":{const f=l.items[0];return n(f,i,a,s,u)}case"Manifest":{const f=l.items[0];return n(f,i,a,s,u)}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return u&&!l.width&&(l.width=u.width,l.height=u.height),r.getThumbnailFromResource(l,i,a,s);case"Service":case"Range":case"AnnotationCollection":case"CanvasReference":case"ContentResource":return{best:void 0,fallback:[],log:[]}}return{best:void 0,fallback:[],log:[]}}return{getBestThumbnailAtSize:n}}function Jo(t,e,r,n,o=[]){const i=E(),a=m.useMemo(()=>nr(i),[i]);m.useEffect(()=>{const s=t;return s?(a.addEventListener(s,e,r,n),()=>{a.removeEventListener(s,e,r)}):()=>{}},[a,t,e,...o])}function Zo(){const t=m.useContext(re);return t&&t.vault?t.vault:fe.globalVault()}var Xo=Object.defineProperty,_r=Object.getOwnPropertySymbols,ea=Object.prototype.hasOwnProperty,ta=Object.prototype.propertyIsEnumerable,Er=(t,e,r)=>e in t?Xo(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ra=(t,e)=>{for(var r in e||(e={}))ea.call(e,r)&&Er(t,r,e[r]);if(_r)for(var r of _r(e))ta.call(e,r)&&Er(t,r,e[r]);return t},na=(t,e,r)=>new Promise((n,o)=>{var i=u=>{try{s(r.next(u))}catch(l){o(l)}},a=u=>{try{s(r.throw(u))}catch(l){o(l)}},s=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);s((r=r.apply(t,e)).next())});const ia=(t,e={})=>{const r=E(),[n,o]=m.useState(t),i=m.useMemo(()=>r.get(t),[t,r]),{data:a,isFetching:s}=Pe(`collection:${t}`,()=>na(void 0,null,function*(){const u=i||(yield r.loadCollection(t));return u&&o(u.id),u}),ra({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,initialData:i},e));return{isLoaded:!s,id:n,collection:a}};var oa=(t,e,r)=>new Promise((n,o)=>{var i=u=>{try{s(r.next(u))}catch(l){o(l)}},a=u=>{try{s(r.throw(u))}catch(l){o(l)}},s=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);s((r=r.apply(t,e)).next())});function jr(){const t=Y(),e=ge(),r=E(),n=ve();return Pe(`canvas-first-image-service:${t?t.id:"undefined"}`,()=>oa(this,null,function*(){if(t&&e.length){const o=e[0],i=r.get(o.body[0]),s=se(i)[0];return s&&(yield n.loadService({id:s.id||s["@id"],width:s.width||t.width,height:s.height||t.height}))||void 0}}),{refetchOnWindowFocus:!1,refetchOnMount:!1,refetchIntervalInBackground:!1,refetchInterval:!1,initialData:()=>{if(t&&e.length){const o=e[0],i=r.get(o.body[0]),s=se(i)[0];return s&&n.loadServiceSync({id:s.id||s["@id"],width:s.width||t.width,height:s.height||t.height})||void 0}}})}function aa(){const t=jr();return{isLoading:t.isFetching,tile:t.data?{id:t.data.id||t.data["@id"],width:t.data.width,height:t.data.height,imageService:t.data,thumbnail:void 0}:null}}function Tr(t,e=[]){const r=E(),n=ge(),[o,i]=m.useState((t==null?void 0:t.defaultChoices)||[]),a=m.useMemo(()=>Ht(r,n,o),[r,n,o,...e]),u={makeChoice:m.useCallback((l,{deselectOthers:f=!0,deselect:p=!1}={})=>{if(a.choice){if(a.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");i(d=>{if(p){const c=d.filter(g=>g!==l);if(c.length===0){const g=a.items[0].resource.id;return g?[g]:[]}return c}if(f)return[l];const v=[...d];if(v.length===0&&a.items.length){const c=a.items[0].resource.id;c&&v.push(c)}return d.indexOf(l)!==-1?d:[...d,l]})}},[a.choice])};return[a,u]}function sa(t={},e=[]){const{id:r,selector:n}=t,o=Q(),i=r||o.range,a=M(s=>i?s.iiif.entities.Range[i]:void 0,[i]);return m.useMemo(()=>{if(!!a)return n?n(a):a},[a,n,...e])}function ca(t,e){const r=E(),n=m.useMemo(()=>nr(r),[r]),o=M(()=>t&&t.id?r.getResourceMeta(t.id,"eventManager"):null,[t]);return m.useMemo(()=>t?n.getListenersAsProps(t,e):{},[o,t,r,e])}function Mr(t,e){return M((r,n)=>n.get(t.map(o=>({id:o,type:e}))),[t,e])}function ua(){const t=le();return t?t.service.find(e=>e.profile==="SearchService1"||e.profile==="http://iiif.io/api/search/1/search"):void 0}function la(){const t=E();return m.useMemo(()=>ir(t),[t])}function fa(t,e){const r=E(),n=m.useMemo(()=>ir(r),[r]);return M(()=>{if(!t)return null;const o=n.getAppliedStyles(t.id);return o?e?o[e]:o:void 0},[t,e])}const Fr=(t,e=[])=>{const r=E();m.useEffect(()=>{t(r)},[r,...e])};function ha(t,e,{canvasId:r,manifestId:n}={}){const o=E(),i=ve(),a=m.useMemo(()=>Yo(o,{imageServiceLoader:i}),[o,i]),[s,u]=m.useState(),l=le(n?{id:n}:void 0),f=Y(r?{id:r}:void 0),p=f||l,d=m.useRef(!1);if(m.useEffect(()=>()=>{d.current=!0},[]),!p)throw new Error("Must be called under a manifest or canvas context.");return Fr(v=>{a.getBestThumbnailAtSize(p,t,e).then(c=>{c.best&&!d.current&&u(c.best)})},[p]),s}var da=Object.defineProperty,pa=Object.defineProperties,va=Object.getOwnPropertyDescriptors,Lr=Object.getOwnPropertySymbols,ma=Object.prototype.hasOwnProperty,ga=Object.prototype.propertyIsEnumerable,kr=(t,e,r)=>e in t?da(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Rr=(t,e)=>{for(var r in e||(e={}))ma.call(e,r)&&kr(t,r,e[r]);if(Lr)for(var r of Lr(e))ga.call(e,r)&&kr(t,r,e[r]);return t},qr=(t,e)=>pa(t,va(e));function Wr(){const t=ve(),[e,r]=m.useState({}),n=m.useRef(!1);return m.useEffect(()=>()=>{n.current=!0},[]),[m.useCallback((i,{height:a,width:s})=>{if(i){const u=i.id||i["@id"],l=t.loadServiceSync({id:u,width:i.width||s,height:i.height||a});l?i=l:e[u]||(n.current||r(f=>qr(Rr({},f),{[u]:"loading"})),t.loadService({id:u,width:i.width||s,height:i.height||a}).then(()=>{n.current||r(f=>qr(Rr({},f),{[u]:"done"}))}))}return i},[t,e]),e]}var ya=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},j={exports:{}};(function(t,e){(function(r,n){n(e)})(ya,function(r){function n(h){return h==null}function o(h){throw new Error("Argument "+h+" is empty.")}function i(h){return typeof h=="function"&&"getType"in h}function a(h){throw new Error("Argument "+h+' is invalid, it should be an action-creator instance from "typesafe-actions"')}function s(h,w){if(h==null)throw new Error("Argument contains array with empty element at index "+w);if(h.getType==null)throw new Error("Argument contains array with invalid element at index "+w+', it should be an action-creator instance from "typesafe-actions"')}function u(h){return typeof h=="string"||typeof h=="symbol"}function l(h){return!u(h)}function f(h){throw new Error("Argument "+h+" is invalid, it should be an action type of type: string | symbol")}function p(h,w){if(h==null)throw new Error("Argument contains array with empty element at index "+w);if(typeof h!="string"&&typeof h!="symbol")throw new Error("Argument contains array with invalid element at index "+w+", it should be of type: string | symbol")}function d(h,w,b,A){return n(h)&&o(1),l(h)&&a(1),{type:h,payload:w,meta:b,error:A}}function v(h,w){return n(h)&&o(1),l(h)&&f(1),Object.assign(function(){var b=w!=null?w.apply(void 0,arguments):void 0;return Object.assign({type:h},b)},{getType:function(){return h},toString:function(){return h}})}function c(h,w,b){return n(h)&&o(1),l(h)&&f(1),function(){return v(h,function(){var A=arguments.length<=0?void 0:arguments[0],P=arguments.length<=1?void 0:arguments[1];return w==null&&b==null||(A=w!=null?w.apply(void 0,arguments):void 0,P=b!=null?b.apply(void 0,arguments):void 0),Object.assign({},A!==void 0&&{payload:A},{},P!==void 0&&{meta:P})})}}function g(h){return n(h)&&o(1),i(h)||a(1),h.getType()}function x(h,w){n(h)&&o(1),l(h)&&f(1);var b=w!=null?w(h):function(){return{type:h}};return Object.assign(b,{getType:function(){return h},toString:function(){return h}})}var S={createAction:function(h,w){var b=w==null?function(){return d(h)}:w(d.bind(null,h));return Object.assign(b,{getType:function(){return h},toString:function(){return h}})},createCustomAction:x,createStandardAction:function(h){return n(h)&&o(1),l(h)&&f(1),Object.assign(function(){return x(h,function(w){return function(b,A){return{type:w,payload:b,meta:A}}})},{map:function(w){return x(h,function(b){return function(A,P){return Object.assign(w(A,P),{type:b})}})}})}};r.action=d,r.createAction=c,r.createAsyncAction=function(h,w,b,A){return function(){var P=[h,w,b,A].map(function(C,I){return Array.isArray(C)?c(C[0],C[1],C[2])():typeof C=="string"||typeof C=="symbol"?c(C)():void(I<3&&function(F){throw new Error("Argument "+F+' is invalid, it should be an action type of "string | symbol" or a tuple of "[string | symbol, Function, Function?]"')}(I))});return{request:P[0],success:P[1],failure:P[2],cancel:P[3]}}},r.createCustomAction=v,r.createReducer=function h(w,b){b===void 0&&(b={});var A=Object.assign({},b),P=function(C,I){var F=Array.isArray(C)?C:[C],ee={};return F.map(function(te,qs){return i(te)?g(te):u(te)?te:function(Ws){throw new Error("Argument "+Ws+' is invalid, it should be an action-creator instance from "typesafe-actions" or action type of type: string | symbol')}(qs+1)}).forEach(function(te){return ee[te]=I}),h(w,Object.assign({},A,{},ee))};return Object.assign(function(C,I){if(C===void 0&&(C=w),A.hasOwnProperty(I.type)){var F=A[I.type];if(typeof F!="function")throw Error('Reducer under "'+I.type+'" key is not a valid reducer');return F(C,I)}return C},{handlers:Object.assign({},A),handleAction:P,handleType:P})},r.deprecated=S,r.getType=g,r.isActionOf=function(h,w){n(h)&&o(1);var b=Array.isArray(h)?h:[h];b.forEach(s);var A=function(P){return b.some(function(C){return P.type===C.getType()})};return w===void 0?A:A(w)},r.isOfType=function(h,w){n(h)&&o(1);var b=Array.isArray(h)?h:[h];b.forEach(p);var A=function(P){return b.includes(P.type)};return w===void 0?A:A(w)}})})(j,j.exports);const wa="@iiif/IMPORT_ENTITIES",ba="@iiif/MODIFY_ENTITY_FIELD",Sa="@iiif/REORDER_ENTITY_FIELD",xa="@iiif/ADD_REFERENCE",Oa="@iiif/REMOVE_REFERENCE",Ca=j.exports.createAction(wa)(),Aa=j.exports.createAction(ba)(),Pa=j.exports.createAction(Sa)(),Ia=j.exports.createAction(xa)(),$a=j.exports.createAction(Oa)(),Me={importEntities:Ca,modifyEntityField:Aa,reorderEntityField:Pa,addReference:Ia,removeReference:$a},_a="@iiif/ADD_MAPPING",Ea="@iiif/ADD_MAPPINGS";j.exports.createAction(_a)(),j.exports.createAction(Ea)();const ja="@iiif/SET_META_VALUE",Ta="@iiif/SET_META_VALUE_DYNAMIC",Ma="@iiif/UNSET_META_VALUE";j.exports.createAction(ja)(),j.exports.createAction(Ta)(),j.exports.createAction(Ma)();const Fa="@iiif/REQUEST_RESOURCE",La="@iiif/REQUEST_ERROR",ka="@iiif/REQUEST_MISMATCH",Ra="@iiif/REQUEST_COMPLETE",qa="@iiif/REQUEST_OFFLINE_RESOURCE";j.exports.createAction(Fa)(),j.exports.createAction(La)(),j.exports.createAction(ka)(),j.exports.createAction(Ra)(),j.exports.createAction(qa)();const Wa="@iiif/BATCH";j.exports.createAction(Wa)();const Da={id:"https://iiif-parser/annotation-page",type:"AnnotationPage",behavior:[],motivation:null,label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[]},Dr=["sc:Collection","sc:Manifest","sc:Canvas","oa:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function Va(t){if(typeof t>"u"||t===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(t))throw new Error("Array is not a valid entity");if(typeof t!="object")throw new Error(`${typeof t} is not a valid entity`);if(typeof t["@type"]=="string"){const e=Dr.indexOf(t["@type"]);if(e!==-1)return Dr[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}class Fe{traversals;options;constructor(e,r={}){this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...r}}static all(e){return new Fe({collection:[e],manifest:[e],canvas:[e],annotationList:[e],sequence:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],layer:[e]})}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))),this.traversals.collection)}traverseCollectionItems(e){if(this.options.mergeMemberProperties){const r=[...(e.manifests||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n),...(e.collections||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n),...e.members||[]];delete e.collections,delete e.manifests,e.members=r}return e.manifests&&(e.manifests=e.manifests.map(r=>this.traverseManifest(typeof r=="string"?{"@id":r,"@type":"sc:Manifest"}:r))),e.collections&&(e.collections=e.collections.map(r=>this.traverseCollection(typeof r=="string"?{"@id":r,"@type":"sc:Collection"}:r))),e.members&&(e.members=e.members.map(r=>typeof r=="string"?r:this.traverseUnknown(r))),e}traverseManifest(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))),this.traversals.manifest)}traverseManifestItems(e){return e.sequences&&(e.sequences=e.sequences.map(r=>this.traverseSequence(r))),e.structures&&(e.structures=e.structures.map(r=>this.traverseRange(r))),e}traverseSequence(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))),this.traversals.sequence)}traverseSequenceItems(e){return e.canvases&&(e.canvases=e.canvases.map(r=>this.traverseCanvas(r))),e}traverseCanvas(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))),this.traversals.canvas)}traverseCanvasItems(e){return e.images&&(e.images=e.images.map(r=>this.traverseAnnotation(r))),e.otherContent&&(e.otherContent=e.otherContent.map(r=>this.traverseAnnotationList(r))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const r=[...(e.ranges||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Range"}:n),...(e.canvases||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Canvas"}:n),...e.members||[]];delete e.ranges,delete e.canvases,e.members=r.length?r.map(n=>this.traverseUnknown(n)):void 0}return e}traverseAnnotationList(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationListItems(e))),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map(r=>this.traverseAnnotation(r))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(e.resource=this.traverseContentResource(e.resource)),e.on,e}traverseLayer(e){return this.traverseType(this.traverseLinking(this.traverseLayerItems(e)),this.traversals.layer)}traverseLayerItems(e){return e.otherContent&&(e.otherContent=e.otherContent.map(r=>this.traverseAnnotationList(r))),e}traverseChoice(e){return this.traverseType(this.traverseChoiceItems(e),this.traversals.choice)}traverseChoiceItems(e){return e.default&&e.default!=="rdf:nil"&&(e.default=this.traverseContentResource(e.default)),e.item&&e.item!=="rdf:nil"&&(e.item=e.item.map(r=>this.traverseContentResource(r))),e}traverseService(e){return this.traverseType(this.traverseLinking(e),this.traversals.service)}traverseContentResource(e){return e["@type"]==="oa:Choice"?this.traverseChoice(e):this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.contentResource)}traverseUnknown(e){if(!e["@type"]||typeof e=="string")return e;switch(Va(e)){case"sc:Collection":return this.traverseCollection(e);case"sc:Manifest":return this.traverseManifest(e);case"sc:Canvas":return this.traverseCanvas(e);case"sc:Sequence":return this.traverseSequence(e);case"sc:Range":return this.traverseRange(e);case"oa:Annotation":return this.traverseAnnotation(e);case"oa:AnnotationList":return this.traverseAnnotationList(e);case"sc:Layer":return this.traverseLayer(e);case"Service":return this.traverseService(e);case"oa:Choice":return this.traverseChoice(e);case"ContentResource":return this.traverseContentResource(e)}return e.profile?this.traverseService(e):e}traverseImageResource(e){const r=Array.isArray(e),n=Array.isArray(e)?e:[e],o=[];for(const i of n)typeof i=="string"?o.push(this.traverseContentResource({"@id":i,"@type":"dctypes:Image"})):o.push(this.traverseContentResource(i));return!r&&!this.options.convertPropsToArray?o[0]:o}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){const r=Array.isArray(e),n=Array.isArray(e)?e:[e],o=[];for(const i of n)o.push(this.traverseService(i));return!r&&!this.options.convertPropsToArray?o[0]:o}traverseLinking(e){return e.related&&(e.related=this.traverseOneOrManyType(e.related,this.traversals.contentResource)),e.rendering&&(e.rendering=this.traverseOneOrManyType(e.rendering,this.traversals.contentResource)),e.service&&(e.service=this.traverseOneOrMoreServices(e.service)),e.seeAlso&&(e.seeAlso=this.traverseOneOrManyType(e.seeAlso,this.traversals.contentResource)),e.within&&(typeof e.within=="string"||(e.within=this.traverseOneOrManyType(e.within,this.traversals.contentResource))),e.startCanvas&&(typeof e.startCanvas=="string"?e.startCanvas=this.traverseType({"@id":e.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):e.startCanvas&&this.traverseType(e.startCanvas,this.traversals.canvas)),e.contentLayer&&(typeof e.contentLayer=="string"?e.contentLayer=this.traverseLayer({"@id":e.contentLayer,"@type":"sc:Layer"}):e.contentLayer=this.traverseLayer(e.contentLayer)),e}traverseOneOrManyType(e,r){if(!Array.isArray(e))if(this.options.convertPropsToArray)e=[e];else return this.traverseType(e,r);return e.map(n=>this.traverseType(n,r))}traverseType(e,r){return r.reduce((n,o)=>{const i=o(n);return typeof i>"u"&&!this.options.allowUndefinedReturn?n:i},e)}}const Qa="http://library.stanford.edu/iiif/image-api/compliance.html#level0",Vr="http://library.stanford.edu/iiif/image-api/compliance.html#level1",Qr="http://library.stanford.edu/iiif/image-api/compliance.html#level2",za="http://library.stanford.edu/iiif/image-api/conformance.html#level0",zr="http://library.stanford.edu/iiif/image-api/conformance.html#level1",Br="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Ba="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Hr="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Ur="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Ha="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Nr="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Gr="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Ua="http://iiif.io/api/image/1/level0.json",Na="http://iiif.io/api/image/1/profiles/level0.json",Kr="http://iiif.io/api/image/1/level1.json",Yr="http://iiif.io/api/image/1/profiles/level1.json",Jr="http://iiif.io/api/image/1/level2.json",Zr="http://iiif.io/api/image/1/profiles/level2.json",Ga="http://iiif.io/api/image/2/level0.json",Ka="http://iiif.io/api/image/2/profiles/level0.json",Xr="http://iiif.io/api/image/2/level1.json",en="http://iiif.io/api/image/2/profiles/level1.json",tn="http://iiif.io/api/image/2/level2.json",rn="http://iiif.io/api/image/2/profiles/level2.json",Ya="level0",nn="level1",on="level2",Ja="http://iiif.io/api/image/2/level0",an="http://iiif.io/api/image/2/level1",sn="http://iiif.io/api/image/2/level2",Za=[an,sn,Vr,Qr,zr,Br,Hr,Ur,Nr,Gr,Kr,Yr,Jr,Zr,Xr,en,tn,rn,nn,on],Xa=[Ja,an,sn,Qa,Vr,Qr,za,zr,Br,Ba,Hr,Ur,Ha,Nr,Gr,Ua,Na,Kr,Yr,Jr,Zr,Ga,Ka,Xr,en,tn,rn,Ya,nn,on],Le={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function U(t,e="none"){if(!t)return{};const r=Array.isArray(t)?t:[t],n={};for(const o of r){if(typeof o=="string"){n[e]=n[e]?n[e]:[],n[e].push(o||"");continue}if(!o["@language"]){n[e]=n[e]?n[e]:[],n[e].push(o["@value"]||"");continue}const i=o["@language"];n[i]=n[i]?n[i]:[],n[i].push(o["@value"]||"")}return n}function cn(t){if(Array.isArray(t))return cn(t.find(e=>typeof e=="string"));if(Xa.indexOf(t)!==-1)return"level2";if(Za.indexOf(t)!==-1)return"level1";if(typeof t=="string")return t}function es(t){const e=Array.isArray(t)?t:[t];for(const r of e)switch(r){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function ts(t){switch(t){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}function rs(t){return Array.isArray(t)?t:[t]}function ns(t){for(const e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}function ke(t){const e=t["@id"]||t.id;let r=t["@type"]||t.type;const n=t.profile||void 0,o=t["@context"]||void 0;if(n){const i=ts(n);if(i)return i}if(o){const i=es(o);if(i)return i}if(r){if(Array.isArray(r)){if(r.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(r.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";r=r[0]}for(const i of["sc","oa","dcterms","dctypes","iiif"])if(r.startsWith(`${i}:`)){r=r.slice(i.length+1);break}switch(r){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(t.format){if(t.format.startsWith("image/"))return"Image";if(t.format.startsWith("text/")||t.format==="application/pdf")return"Text";if(t.format.startsWith("application/"))return"Dataset"}return e&&(e.endsWith(".jpg")||e.endsWith(".png")||e.endsWith(".jpeg"))?"Image":r||"unknown"}const is=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function os(t){const e=t.match(is);return e?e[0]:t}function as(t,e="Rights/License",r="none"){let n=null;const o=[],i=Array.isArray(t)?t:[t];for(const a of i){const s=a?os(a):void 0;if(s&&(s.indexOf("creativecommons.org")!==-1||s.indexOf("rightsstatements.org")!==-1)){s.startsWith("https://")?n=`http://${s.slice(8)}`:n=s;continue}s&&o.push({label:{[r]:[e]},value:{[r]:[s]}})}return[n,o]}const ss=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function cs(t){if(t){const e=Array.isArray(t)?t:[t],r=[];for(const n of e)n==="http://iiif.io/api/presentation/2/context.json"&&r.push("http://iiif.io/api/presentation/3/context.json"),ss.indexOf(n)===-1&&r.push(n);if(e.length)return r.length===1?r[0]:r}}function us(t){return t?t.map(e=>({label:U(e.label),value:U(e.value)})):[]}function q(t){for(const e in t)(typeof t[e]>"u"||t[e]===null)&&delete t[e];return t}let un=0;function ln(t,e){const r=encodeURI(t.id||t["@id"]||"").trim();return r&&e?`${r}/${e}`:r||(un++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${un}`)}function W(t){const e=[...t.behavior||[]];return t.viewingHint&&e.push(t.viewingHint),{"@context":t["@context"]?cs(t["@context"]):void 0,id:(t["@id"]||ln(t)).trim(),type:ke(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:t.motivation?ns(t.motivation):void 0,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function L(t){const[e,r]=as(t.license),n=[...t.metadata?us(t.metadata):[],...r];return{rights:e,metadata:n.length?n:void 0,label:t.label?U(t.label):void 0,requiredStatement:t.attribution?{label:U(Le.attributionLabel),value:U(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?U(t.description):void 0,thumbnail:t.thumbnail}}function ls(t){if(!t.within)return;const e=Array.isArray(t.within)?t.within:[t.within],r=[];for(const n of e)if(typeof n=="string"){if(n)switch(t["@type"]){case"sc:Manifest":r.push({id:n,type:"Collection"});break}}else n["@id"]&&r.push({id:n["@id"],type:ke(n)});return r.length?r:void 0}function V(t){const e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],r=t.contentLayer;return{provider:t.logo||e.length?[{id:Le.providerId,type:"Agent",homepage:e.length?[e[0]]:void 0,logo:t.logo?Array.isArray(t.logo)?t.logo:[t.logo]:void 0,label:U(Le.providerName)}]:void 0,partOf:ls(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?rs(t.service):void 0,supplementary:r?[r]:void 0}}function fs(t){return q({...W(t),...L(t),...V(t),items:t.members})}function hs(t){const e=[],r=[];for(const o of t.sequences||[])o.canvases.length&&e.push(...o.canvases),o.behavior&&r.push(...o.behavior);const n=W(t);return r.length&&(n.behavior?n.behavior.push(...r):n.behavior=r),q({...n,...L(t),...V(t),items:e,structures:t.structures})}function ds(t){return q({...W(t),...L(t),...V(t),items:t.images&&t.images.length?[{id:ln(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function ps(t){return q({...W(t),...L(t),...V(t),items:t.resources})}function vs(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[]}}function ms(t){return q({...W(t),...L(t),...V(t),target:typeof t.on=="string"?encodeURI(t.on).trim():t.on,body:t.resource})}function gs(t){const e=t;return q({...W(e),...L(e),...V(e)})}function ys(t){const e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),{...W(t),...L(t),items:e}}function ws(t){return q({...W(t),...L(t),...V(t),items:t.members})}function bs(t){const{"@id":e,"@type":r,"@context":n,profile:o,...i}=t;return e&&(i.id=e),i.type=ke(t),i.type==="unknown"&&(i.type="Service"),o&&(i.profile=cn(o)),q({...i,...L(i)})}function Ss(t){return q({...W(t),...L(t),...V(t)})}new Fe({collection:[fs],manifest:[hs],canvas:[ds],annotationList:[ps],sequence:[vs],annotation:[ms],contentResource:[gs],choice:[ys],range:[ws],service:[bs],layer:[Ss]});var xs=Object.defineProperty,Os=Object.defineProperties,Cs=Object.getOwnPropertyDescriptors,fn=Object.getOwnPropertySymbols,As=Object.prototype.hasOwnProperty,Ps=Object.prototype.propertyIsEnumerable,hn=(t,e,r)=>e in t?xs(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Is=(t,e)=>{for(var r in e||(e={}))As.call(e,r)&&hn(t,r,e[r]);if(fn)for(var r of fn(e))Ps.call(e,r)&&hn(t,r,e[r]);return t},$s=(t,e)=>Os(t,Cs(e));function dn(t){return typeof t!="string"&&t&&t.bindToVault}function _s(){const t=E(),e=m.useRef([]),r=rr(),n=m.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);m.useLayoutEffect(()=>{const s=$s(Is({},Da),{id:n,items:[]});r(Me.importEntities({entities:{AnnotationPage:{[s.id]:s}}}))},[n]);const o=M(s=>n?s.iiif.entities.AnnotationPage[n]:null,[n]),i=m.useCallback((s,u)=>{if(n){if(dn(s)){const p=s;p.__vault||p.bindToVault(t),s=typeof p.source=="string"?p.source:p.source.id,e.current[s]=p}else typeof s!="string"&&(s=s.id);const l=t.get({id:n,type:"AnnotationPage"}),f=t.get({id:s,type:"Annotation"});l&&f&&(l.items.find(p=>p.id===f.id)||r(Me.addReference({id:n,type:"AnnotationPage",key:"items",reference:{id:s,type:"Annotation"},index:u})))}},[n]),a=m.useCallback(s=>{n&&(dn(s)?s=typeof s.source=="string"?s.source:s.source.id:typeof s!="string"&&(s=s.id),e.current[s]&&e.current[s].beforeRemove(),t.get({id:n,type:"AnnotationPage"})&&r(Me.removeReference({id:n,type:"AnnotationPage",key:"items",reference:{id:s,type:"Annotation"}})))},[n]);return[o,{addAnnotation:i,removeAnnotation:a}]}var Es=Object.defineProperty,js=Object.defineProperties,Ts=Object.getOwnPropertyDescriptors,pn=Object.getOwnPropertySymbols,Ms=Object.prototype.hasOwnProperty,Fs=Object.prototype.propertyIsEnumerable,vn=(t,e,r)=>e in t?Es(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ls=(t,e)=>{for(var r in e||(e={}))Ms.call(e,r)&&vn(t,r,e[r]);if(pn)for(var r of pn(e))Fs.call(e,r)&&vn(t,r,e[r]);return t},ks=(t,e)=>js(t,Ts(e));function Rs(t){const e=le(),r=Y(),n=E(),[o,i]=Wr(),{enabledPageIds:a}=tr((t==null?void 0:t.annotationPageManagerId)||(e==null?void 0:e.id),{all:!1}),s=Mr(a,"AnnotationPage"),u=(t==null?void 0:t.strategies)||["images","media","complex-timeline"],[l,f]=Tr(t,[i]),p=m.useMemo(()=>{if(!r||l.types.length===0)return _e;if(l.types.length!==1)return u.indexOf("complex-timeline")===-1?R("Complex timeline not supported"):R("ComplexTimelineStrategy not yet supported");const d=l.types[0];return d==="image"?u.indexOf("images")===-1?R("Image not supported"):Nt(r,l,o):d==="audio"?u.indexOf("media")===-1?R("Media not supported"):R("Audio strategy not yet supported"):d==="video"?u.indexOf("media")===-1?R("Media not supported"):R("Video strategy not yet supported"):_e},[r,l,n,f.makeChoice]);return m.useMemo(()=>p.type==="unknown"?[p,Ut]:[ks(Ls({},p),{annotations:{pages:s}}),f],[p,s])}y.AnnotationContext=Sn,y.CanvasContext=De,y.CollectionContext=xn,y.ContextBridge=ni,y.ImageServiceLoaderContext=Wt,y.ManifestContext=Ve,y.RangeContext=On,y.ReactVaultContext=re,y.ResourceProvider=z,y.ResourceReactContext=he,y.SimpleViewerProvider=ei,y.SimpleViewerReactContext=ae,y.VaultProvider=Qe,y.VisibleCanvasReactContext=oe,y.emptyActions=Ut,y.expandTarget=D,y.flattenAnnotationPageIds=Yt,y.getImageStrategy=Nt,y.getPaintables=Ht,y.parseSelector=me,y.parseSpecificResource=Bt,y.unknownResponse=_e,y.unsupportedStrategy=R,y.useAnnotation=vo,y.useAnnotationPageManager=tr,y.useAnnotationsAtTime=Co,y.useCanvas=Y,y.useCanvasClock=Ao,y.useCollection=Po,y.useContextBridge=ri,y.useDispatch=rr,y.useEventListener=Jo,y.useExistingVault=Zo,y.useExternalCollection=ia,y.useExternalManifest=ct,y.useImageService=jr,y.useImageServiceLoader=ve,y.useImageTile=aa,y.useLoadImageService=Wr,y.useManifest=le,y.usePaintables=Tr,y.usePaintingAnnotations=ge,y.useRange=sa,y.useRenderingStrategy=Rs,y.useResourceContext=Q,y.useResourceEvents=ca,y.useResources=Mr,y.useSearchService=ua,y.useSimpleViewer=ti,y.useStyleHelper=la,y.useStyles=fa,y.useThumbnail=ha,y.useVault=E,y.useVaultEffect=Fr,y.useVaultSelector=M,y.useVirtualAnnotationPage=_s,y.useVisibleCanvases=ut,Object.defineProperty(y,"__esModule",{value:!0})});
|
|
14
|
+
***************************************************************************** */function D(e,t,i,n){function o(r){return r instanceof i?r:new i(function(s){s(r)})}return new(i||(i=Promise))(function(r,s){function a(u){try{c(n.next(u))}catch(d){s(d)}}function l(u){try{c(n.throw(u))}catch(d){s(d)}}function c(u){u.done?r(u.value):o(u.value).then(a,l)}c((n=n.apply(e,t||[])).next())})}class zt{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(t){Object.assign(this.config,t)}sample(t,i,n=!0){const o=H(b(t)),r=B(b(t)),s=this.knownImageServers[o];return this.imageServices[r]=Object.assign(t,{real:!0}),s?this.verify(t):(this.knownImageServers[o]={verifications:0,malformed:!1,root:o,preLoaded:n,sampledId:b(t),verified:!1,server:null,result:{context:t["@context"]||[],sampledProfile:t.profile,resourceServiceRatio:i&&t.height?i.height/t.height:1,sampledSizes:t.sizes||[],sizeRatios:kn(t.width,t.height,t.sizes||[]),sampledTiles:t.tiles||[]}},!0)}preLoad(t,i=!0){this.knownImageServers[t.root]=t,i&&(this.knownImageServers[t.root].malformed=!1,this.knownImageServers[t.root].verifications=this.config.verificationsRequired)}predict(t,i=!1,n=!1){const o=H(b(t)),r=this.knownImageServers[o];if(!r||!r.result||!n&&(r.malformed||r.verifications<this.config.verificationsRequired))return null;const s=B(b(t));return this.imageServices[s]||(this.imageServices[s]={"@context":r.result.context,"@id":b(t),id:b(t),protocol:"http://iiif.io/api/image",tiles:ir(t.width,t.height,r.result.sampledTiles),sizes:Vn(Math.floor(t.width/r.result.resourceServiceRatio),Math.floor(t.height/r.result.resourceServiceRatio),r.result.sizeRatios),profile:r.result.sampledProfile,height:t.height,width:t.width,real:!1}),this.imageServices[s]}getThumbnailFromResource(t,i,n=!0,o=[]){return D(this,void 0,void 0,function*(){const r=yield this.getImageCandidates(t,n);return tr(i,[()=>o,()=>r])})}getImageCandidates(t,i=!0){return D(this,void 0,void 0,function*(){const n=t;if(i&&n.height&&n.width){const o=Lt(n);for(const r of o){const s={id:b(r),width:r.width?r.width:n.width,height:r.height?r.height:n.height};yield this.loadService(s)}}return Kn(t,i,this)})}verify(t){return D(this,void 0,void 0,function*(){const i=this.predict(t,!1,!0),n=yield this.fetchService(b(t));if(!i)return!1;const o=i.height===n.height&&i.width===n.width&&i["@context"]===n["@context"]&&nr(i.sizes||[],n.sizes||[]);if(o){const r=H(b(t));this.knownImageServers[r].verifications+=1,this.knownImageServers[r].verifications>=this.config.verificationsRequired&&(this.knownImageServers[r].verified=!0)}return o})}canLoadSync(t){const i=typeof t=="string"?t:b(t),n=B(i);if(this.imageServices[n])return!0;const o=this.knownImageServers[H(i)];return o&&!o.malformed&&o.verifications>=this.config.verificationsRequired}markAsMalformed(t){return D(this,void 0,void 0,function*(){return this.knownImageServers[H(b(t))].malformed=!0,this.loadService(t,!0)})}fetchService(t,i=!1){return D(this,void 0,void 0,function*(){const n=B(t);if(this.imageServices[n]&&(!i||this.imageServices[n].real))return this.imageServices[n];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const o=yield fetch(n).then(r=>r.json());return!o.id&&o["@id"]&&(o.id=o["@id"]),o.id!==t&&(o.id=t,o["@id"]&&(o["@id"]=t)),this.imageServices[n]=Object.assign(o,{real:!0}),this.imageServices[n]})}loadService(t,i=!1){return D(this,void 0,void 0,function*(){if(!this.config.disableThrottling)for(;this.fetchingCount>=this.config.verificationsRequired;)yield new Promise(r=>setTimeout(r,500));const n=this.knownImageServers[H(b(t))];if(n&&!n.malformed&&!i){yield n.result;const r=this.loadServiceSync(t);if(r)return r}this.fetchingCount++;const o=yield this.fetchService(b(t),i);return this.fetchingCount--,o.real&&this.sample(o,t),o})}loadServiceSync(t){const i=B(b(t));return this.imageServices[i]?this.imageServices[i]:this.predict(t)}}new zt;function rr(e,t={}){const i=t.imageServiceLoader||new zt;async function n(o,r,s,a=[],l){if(typeof o=="string")return{best:ue(o),fallback:[],log:[]};const c=e.get(o);if(typeof c=="string")return{best:ue(c),fallback:[],log:[]};switch(c.type){case"Annotation":{const u=c.body,d=e.get(u[0]);return l&&!d.width&&(d.width=l.width,d.height=l.height),await i.getThumbnailFromResource(d,r,s,a)}case"Canvas":{const u=c;if(u.thumbnail&&u.thumbnail.length){const d=e.get(u.thumbnail[0]),v=await i.getImageCandidates(d,s);v&&v.length&&a.push(...v)}return n(u.items[0],r,s,a,{width:u.width,height:u.height})}case"AnnotationPage":return n(c.items[0],r,s,a,l);case"Choice":return n(c.items[0],r,s,a,l);case"Collection":{const u=c.items[0];return n(u,r,s,a,l)}case"Manifest":{const u=c.items[0];return n(u,r,s,a,l)}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return l&&!c.width&&(c.width=l.width,c.height=l.height),i.getThumbnailFromResource(c,r,s,a);case"Service":case"Range":case"AnnotationCollection":case"CanvasReference":case"ContentResource":return{best:void 0,fallback:[],log:[]}}return{best:void 0,fallback:[],log:[]}}return{getBestThumbnailAtSize:n}}function or(e,t,i,n,o=[]){const r=I(),s=h.useMemo(()=>pt(r),[r]);h.useEffect(()=>{const a=e;return a?(s.addEventListener(a,t,i,n),()=>{s.removeEventListener(a,t,i)}):()=>{}},[s,e,t,...o])}function sr(){const e=h.useContext(U);return e&&e.vault?e.vault:K.globalVault()}function ar(e,t){const{id:i,isLoaded:n,error:o,resource:r,requestId:s,cached:a}=oe(e,t);return{id:i,isLoaded:n,error:o,manifest:r,requestId:s,cached:a}}var lr=(e,t,i)=>new Promise((n,o)=>{var r=l=>{try{a(i.next(l))}catch(c){o(c)}},s=l=>{try{a(i.throw(l))}catch(c){o(c)}},a=l=>l.done?n(l.value):Promise.resolve(l.value).then(r,s);a((i=i.apply(e,t)).next())});function Rt({cacheKey:e}={}){const t=R(),i=re(),n=I(),o=ie(),[r,s]=h.useState(void 0),[a,l]=h.useState(!1),[c,u]=h.useState("idle"),[d,v]=h.useState(void 0),m=t?t.id:"undefined",p=h.useMemo(()=>{try{if(t&&i.length){const C=i[0],F=n.get(C.body[0]),y=G(F)[0];return y&&o.loadServiceSync({id:y.id||y["@id"],width:y.width||t.width,height:y.height||t.height})||void 0}}catch(C){console.error(C)}},[m,e,t]),w=c==="success"&&r?r:p;return h.useEffect(()=>{lr(this,null,function*(){try{if(t&&i.length){const C=i[0],F=n.get(C.body[0]),y=G(F)[0];if(!y)return;l(!0),u("loading");try{const x=(yield o.loadService({id:y.id||y["@id"],width:y.width||t.width,height:y.height||t.height}))||void 0;s(x),u("success"),l(!1)}catch(x){u("error"),v(x)}}}catch(C){u("error"),v(C)}})},[m,e]),h.useMemo(()=>({data:w,isFetching:a,status:c,error:d}),[w,a,c,d])}function cr(){const e=Rt();return{isLoading:e.isFetching,tile:e.data?{id:e.data.id||e.data["@id"],width:e.data.width,height:e.data.height,imageService:e.data,thumbnail:void 0}:null}}function Bt(e,t=[]){const i=I(),n=re(),[o,r]=h.useState((e==null?void 0:e.defaultChoices)||[]),s=h.useMemo(()=>it(i,n,o),[i,n,o,...t]),l={makeChoice:h.useCallback((c,{deselectOthers:u=!0,deselect:d=!1}={})=>{if(s.choice){if(s.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");r(v=>{if(d){const p=v.filter(w=>w!==c);if(p.length===0){const w=s.items[0].resource.id;return w?[w]:[]}return p}if(u)return[c];const m=[...v];if(m.length===0&&s.items.length){const p=s.items[0].resource.id;p&&m.push(p)}return v.indexOf(c)!==-1?v:[...v,c]})}},[s.choice])};return[s,l]}function ur(e={},t=[]){const{id:i,selector:n}=e,o=k(),r=i||o.range,s=$(a=>r?a.iiif.entities.Range[r]:void 0,[r]);return h.useMemo(()=>{if(!!s)return n?n(s):s},[s,n,...t])}function fr(e,t){const i=I(),n=h.useMemo(()=>pt(i),[i]),o=$(()=>e&&e.id?i.getResourceMeta(e.id,"eventManager"):null,[e]);return h.useMemo(()=>e?n.getListenersAsProps(e,t):{},[o,e,i,t])}function Ht(e,t){return $((i,n)=>n.get(e.map(o=>({id:o,type:t}))),[e,t])}function hr(){const e=X();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function dr(){const e=I();return h.useMemo(()=>gt(e),[e])}function pr(e,t){const i=I(),n=h.useMemo(()=>gt(i),[i]);return $(()=>{if(!e)return null;const o=n.getAppliedStyles(e.id);return o?t?o[t]:o:void 0},[e,t])}const Dt=(e,t=[])=>{const i=I();h.useEffect(()=>{e(i)},[i,...t])};function gr(e,t,{canvasId:i,manifestId:n}={}){const o=I(),r=ie(),s=h.useMemo(()=>rr(o,{imageServiceLoader:r}),[o,r]),[a,l]=h.useState(),c=X(n?{id:n}:void 0),u=R(i?{id:i}:void 0),d=u||c,v=h.useRef(!1);if(h.useEffect(()=>()=>{v.current=!0},[]),!d)throw new Error("Must be called under a manifest or canvas context.");return Dt(m=>{s.getBestThumbnailAtSize(d,e,t).then(p=>{p.best&&!v.current&&l(p.best)})},[d]),a}var mr=Object.defineProperty,vr=Object.defineProperties,yr=Object.getOwnPropertyDescriptors,qt=Object.getOwnPropertySymbols,wr=Object.prototype.hasOwnProperty,xr=Object.prototype.propertyIsEnumerable,Nt=(e,t,i)=>t in e?mr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Ut=(e,t)=>{for(var i in t||(t={}))wr.call(t,i)&&Nt(e,i,t[i]);if(qt)for(var i of qt(t))xr.call(t,i)&&Nt(e,i,t[i]);return e},Qt=(e,t)=>vr(e,yr(t));function Yt(){const e=ie(),[t,i]=h.useState({}),n=h.useRef(!1);return h.useEffect(()=>()=>{n.current=!0},[]),[h.useCallback((r,{height:s,width:a})=>{if(r){const l=r.id||r["@id"],c=e.loadServiceSync({id:l,width:r.width||a,height:r.height||s});c?r=c:t[l]||(n.current||i(u=>Qt(Ut({},u),{[l]:"loading"})),e.loadService({id:l,width:r.width||a,height:r.height||s}).then(()=>{n.current||i(u=>Qt(Ut({},u),{[l]:"done"}))}))}return r},[e,t]),t]}var Sr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},P={exports:{}};(function(e,t){(function(i,n){n(t)})(Sr,function(i){function n(f){return f==null}function o(f){throw new Error("Argument "+f+" is empty.")}function r(f){return typeof f=="function"&&"getType"in f}function s(f){throw new Error("Argument "+f+' is invalid, it should be an action-creator instance from "typesafe-actions"')}function a(f,y){if(f==null)throw new Error("Argument contains array with empty element at index "+y);if(f.getType==null)throw new Error("Argument contains array with invalid element at index "+y+', it should be an action-creator instance from "typesafe-actions"')}function l(f){return typeof f=="string"||typeof f=="symbol"}function c(f){return!l(f)}function u(f){throw new Error("Argument "+f+" is invalid, it should be an action type of type: string | symbol")}function d(f,y){if(f==null)throw new Error("Argument contains array with empty element at index "+y);if(typeof f!="string"&&typeof f!="symbol")throw new Error("Argument contains array with invalid element at index "+y+", it should be of type: string | symbol")}function v(f,y,x,O){return n(f)&&o(1),c(f)&&s(1),{type:f,payload:y,meta:x,error:O}}function m(f,y){return n(f)&&o(1),c(f)&&u(1),Object.assign(function(){var x=y!=null?y.apply(void 0,arguments):void 0;return Object.assign({type:f},x)},{getType:function(){return f},toString:function(){return f}})}function p(f,y,x){return n(f)&&o(1),c(f)&&u(1),function(){return m(f,function(){var O=arguments.length<=0?void 0:arguments[0],E=arguments.length<=1?void 0:arguments[1];return y==null&&x==null||(O=y!=null?y.apply(void 0,arguments):void 0,E=x!=null?x.apply(void 0,arguments):void 0),Object.assign({},O!==void 0&&{payload:O},{},E!==void 0&&{meta:E})})}}function w(f){return n(f)&&o(1),r(f)||s(1),f.getType()}function C(f,y){n(f)&&o(1),c(f)&&u(1);var x=y!=null?y(f):function(){return{type:f}};return Object.assign(x,{getType:function(){return f},toString:function(){return f}})}var F={createAction:function(f,y){var x=y==null?function(){return v(f)}:y(v.bind(null,f));return Object.assign(x,{getType:function(){return f},toString:function(){return f}})},createCustomAction:C,createStandardAction:function(f){return n(f)&&o(1),c(f)&&u(1),Object.assign(function(){return C(f,function(y){return function(x,O){return{type:y,payload:x,meta:O}}})},{map:function(y){return C(f,function(x){return function(O,E){return Object.assign(y(O,E),{type:x})}})}})}};i.action=v,i.createAction=p,i.createAsyncAction=function(f,y,x,O){return function(){var E=[f,y,x,O].map(function(_,M){return Array.isArray(_)?p(_[0],_[1],_[2])():typeof _=="string"||typeof _=="symbol"?p(_)():void(M<3&&function(q){throw new Error("Argument "+q+' is invalid, it should be an action type of "string | symbol" or a tuple of "[string | symbol, Function, Function?]"')}(M))});return{request:E[0],success:E[1],failure:E[2],cancel:E[3]}}},i.createCustomAction=m,i.createReducer=function f(y,x){x===void 0&&(x={});var O=Object.assign({},x),E=function(_,M){var q=Array.isArray(_)?_:[_],Xt={};return q.map(function(N,Kr){return r(N)?w(N):l(N)?N:function(eo){throw new Error("Argument "+eo+' is invalid, it should be an action-creator instance from "typesafe-actions" or action type of type: string | symbol')}(Kr+1)}).forEach(function(N){return Xt[N]=M}),f(y,Object.assign({},O,{},Xt))};return Object.assign(function(_,M){if(_===void 0&&(_=y),O.hasOwnProperty(M.type)){var q=O[M.type];if(typeof q!="function")throw Error('Reducer under "'+M.type+'" key is not a valid reducer');return q(_,M)}return _},{handlers:Object.assign({},O),handleAction:E,handleType:E})},i.deprecated=F,i.getType=w,i.isActionOf=function(f,y){n(f)&&o(1);var x=Array.isArray(f)?f:[f];x.forEach(a);var O=function(E){return x.some(function(_){return E.type===_.getType()})};return y===void 0?O:O(y)},i.isOfType=function(f,y){n(f)&&o(1);var x=Array.isArray(f)?f:[f];x.forEach(d);var O=function(E){return x.includes(E.type)};return y===void 0?O:O(y)}})})(P,P.exports);const br="@iiif/IMPORT_ENTITIES",Or="@iiif/MODIFY_ENTITY_FIELD",Ar="@iiif/REORDER_ENTITY_FIELD",Cr="@iiif/ADD_REFERENCE",Pr="@iiif/REMOVE_REFERENCE",_r=P.exports.createAction(br)(),Ir=P.exports.createAction(Or)(),Er=P.exports.createAction(Ar)(),$r=P.exports.createAction(Cr)(),jr=P.exports.createAction(Pr)(),he={importEntities:_r,modifyEntityField:Ir,reorderEntityField:Er,addReference:$r,removeReference:jr},Mr="@iiif/ADD_MAPPING",Tr="@iiif/ADD_MAPPINGS";P.exports.createAction(Mr)(),P.exports.createAction(Tr)();const Fr="@iiif/SET_META_VALUE",kr="@iiif/SET_META_VALUE_DYNAMIC",Vr="@iiif/UNSET_META_VALUE";P.exports.createAction(Fr)(),P.exports.createAction(kr)(),P.exports.createAction(Vr)();const Wr="@iiif/REQUEST_RESOURCE",Lr="@iiif/REQUEST_ERROR",zr="@iiif/REQUEST_MISMATCH",Rr="@iiif/REQUEST_COMPLETE",Br="@iiif/REQUEST_OFFLINE_RESOURCE";P.exports.createAction(Wr)(),P.exports.createAction(Lr)(),P.exports.createAction(zr)(),P.exports.createAction(Rr)(),P.exports.createAction(Br)();const Hr="@iiif/BATCH",Dr="@iiif/BATCH_IMPORT";P.exports.createAction(Hr)(),P.exports.createAction(Dr)();function Gt(e){return typeof e!="string"&&e&&e.bindToVault}function qr(){const e=I(),t=h.useRef([]),i=dt(),n=h.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);h.useLayoutEffect(()=>{const a={id:n,type:"AnnotationPage",behavior:[],motivation:null,label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[]};i(he.importEntities({entities:{AnnotationPage:{[a.id]:a}}}))},[n]);const o=$(a=>n?a.iiif.entities.AnnotationPage[n]:null,[n]),r=h.useCallback((a,l)=>{if(n){if(Gt(a)){const d=a;d.__vault||d.bindToVault(e),a=typeof d.source=="string"?d.source:d.source.id,t.current[a]=d}else typeof a!="string"&&(a=a.id);const c=e.get({id:n,type:"AnnotationPage"}),u=e.get({id:a,type:"Annotation"});c&&u&&(c.items.find(d=>d.id===u.id)||i(he.addReference({id:n,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"},index:l})))}},[n]),s=h.useCallback(a=>{n&&(Gt(a)?a=typeof a.source=="string"?a.source:a.source.id:typeof a!="string"&&(a=a.id),t.current[a]&&t.current[a].beforeRemove(),e.get({id:n,type:"AnnotationPage"})&&i(he.removeReference({id:n,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"}})))},[n]);return[o,{addAnnotation:r,removeAnnotation:s}]}var Nr=Object.defineProperty,Ur=Object.defineProperties,Qr=Object.getOwnPropertyDescriptors,Zt=Object.getOwnPropertySymbols,Yr=Object.prototype.hasOwnProperty,Gr=Object.prototype.propertyIsEnumerable,Jt=(e,t,i)=>t in e?Nr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Zr=(e,t)=>{for(var i in t||(t={}))Yr.call(t,i)&&Jt(e,i,t[i]);if(Zt)for(var i of Zt(t))Gr.call(t,i)&&Jt(e,i,t[i]);return e},Jr=(e,t)=>Ur(e,Qr(t));function Xr(e){const t=X(),i=R(),n=I(),[o,r]=Yt(),{enabledPageIds:s}=ht((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(i==null?void 0:i.id),{all:!1}),a=Ht(s,"AnnotationPage"),l=(e==null?void 0:e.strategies)||["images","media","complex-timeline"],[c,u]=Bt(e,[r]),d=h.useMemo(()=>{if(!i||c.types.length===0)return le;if(c.types.length!==1)return l.indexOf("complex-timeline")===-1?j("Complex timeline not supported"):j("ComplexTimelineStrategy not yet supported");const v=c.types[0];return v==="image"?l.indexOf("images")===-1?j("Image not supported"):rt(i,c,o):v==="audio"?l.indexOf("media")===-1?j("Media not supported"):j("Audio strategy not yet supported"):v==="video"?l.indexOf("media")===-1?j("Media not supported"):j("Video strategy not yet supported"):le},[i,c,n,u.makeChoice]);return h.useMemo(()=>d.type==="unknown"?[d,nt]:[Jr(Zr({},d),{annotations:{pages:a}}),u],[d,a])}g.AnnotationContext=ri,g.CanvasContext=me,g.CollectionContext=oi,g.ContextBridge=fi,g.ImageServiceLoaderContext=Ze,g.ManifestContext=ve,g.RangeContext=si,g.ReactVaultContext=U,g.ResourceProvider=V,g.ResourceReactContext=ee,g.SimpleViewerProvider=li,g.SimpleViewerReactContext=Y,g.VaultProvider=ye,g.VisibleCanvasReactContext=Q,g.emptyActions=nt,g.expandTarget=T,g.flattenAnnotationPageIds=at,g.getImageStrategy=rt,g.getPaintables=it,g.parseSelector=ne,g.parseSpecificResource=tt,g.unknownResponse=le,g.unsupportedStrategy=j,g.useAnnotation=On,g.useAnnotationPageManager=ht,g.useAnnotationsAtTime=Mn,g.useCanvas=R,g.useCanvasClock=Tn,g.useCollection=Fn,g.useContextBridge=ui,g.useDispatch=dt,g.useEventListener=or,g.useExistingVault=sr,g.useExternalCollection=ar,g.useExternalManifest=we,g.useExternalResource=oe,g.useImageService=Rt,g.useImageServiceLoader=ie,g.useImageTile=cr,g.useLoadImageService=Yt,g.useManifest=X,g.usePaintables=Bt,g.usePaintingAnnotations=re,g.useRange=ur,g.useRenderingStrategy=Xr,g.useResourceContext=k,g.useResourceEvents=fr,g.useResources=Ht,g.useSearchService=hr,g.useSimpleViewer=ci,g.useStyleHelper=dr,g.useStyles=pr,g.useThumbnail=gr,g.useVault=I,g.useVaultEffect=Dt,g.useVaultSelector=$,g.useVirtualAnnotationPage=qr,g.useVisibleCanvases=xe,Object.defineProperty(g,"__esModule",{value:!0})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-iiif-vault",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
4
4
|
"main": "./dist/cjs/index.js",
|
|
5
5
|
"module": "./dist/esm/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -25,39 +25,39 @@
|
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"resolutions": {
|
|
27
27
|
"@atlas-viewer/iiif-image-api": "^2.0.2",
|
|
28
|
-
"@iiif/vault": "^0.9.
|
|
28
|
+
"@iiif/vault": "^0.9.15",
|
|
29
|
+
"@iiif/parser": "^1.0.6",
|
|
29
30
|
"@iiif/presentation-3": "^1.0.4"
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
33
|
"@atlas-viewer/iiif-image-api": "^2.0.2",
|
|
33
34
|
"@iiif/presentation-2": "^1.0.1",
|
|
34
35
|
"@iiif/presentation-3": "^1.0.4",
|
|
35
|
-
"@iiif/vault": "^0.9.
|
|
36
|
+
"@iiif/vault": "^0.9.15",
|
|
36
37
|
"@iiif/vault-helpers": "^0.9.4",
|
|
37
|
-
"react": "^16.10.2 || ^17.0.
|
|
38
|
-
"react-dom": "^16.10.2 || ^17.0.
|
|
39
|
-
"react-query": "^1.5.10",
|
|
38
|
+
"react": "^16.10.2 || ^17.0.2",
|
|
39
|
+
"react-dom": "^16.10.2 || ^17.0.2",
|
|
40
40
|
"redux": "^4.1.2",
|
|
41
|
-
"rollup": "^2.
|
|
42
|
-
"typescript": "^4.
|
|
41
|
+
"rollup": "^2.70.0",
|
|
42
|
+
"typescript": "^4.6.2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@rollup/plugin-replace": "^4.0.0",
|
|
46
|
-
"@testing-library/react": "^12.1.
|
|
46
|
+
"@testing-library/react": "^12.1.3",
|
|
47
47
|
"@testing-library/react-hooks": "^7.0.2",
|
|
48
48
|
"@types/jest": "^27.4.1",
|
|
49
49
|
"@types/react": "^17.0.39",
|
|
50
|
-
"@types/react-dom": "^17.0.
|
|
51
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
52
|
-
"@typescript-eslint/parser": "^5.
|
|
53
|
-
"eslint": "^8.
|
|
50
|
+
"@types/react-dom": "^17.0.13",
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^5.14.0",
|
|
52
|
+
"@typescript-eslint/parser": "^5.14.0",
|
|
53
|
+
"eslint": "^8.10.0",
|
|
54
54
|
"eslint-plugin-json": "^3.1.0",
|
|
55
55
|
"eslint-plugin-prettier": "^4.0.0",
|
|
56
56
|
"jest": "^27.5.1",
|
|
57
57
|
"jest-environment-jsdom": "^27.5.1",
|
|
58
58
|
"prettier": "^2.5.1",
|
|
59
|
-
"react": "^16.10.2 || ^17.0.
|
|
60
|
-
"react-dom": "^16.10.2 || ^17.0.
|
|
59
|
+
"react": "^16.10.2 || ^17.0.2",
|
|
60
|
+
"react-dom": "^16.10.2 || ^17.0.2",
|
|
61
61
|
"react-use": "^17.3.2",
|
|
62
62
|
"redux": "^4.1.2",
|
|
63
63
|
"rollup-library-template": "^1.0.4",
|