react-iiif-vault 0.9.3 → 0.9.6
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 +1527 -1
- package/dist/esm/index.mjs +1462 -1
- package/dist/index.d.ts +38 -8
- package/dist/index.umd.js +1541 -2
- package/package.json +15 -15
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,921 @@
|
|
|
1
|
-
(function(y,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("react"),require("@iiif/vault")):typeof define=="function"&&define.amd?define(["exports","react","@iiif/vault"],m):(y=typeof globalThis<"u"?globalThis:y||self,m(y.ReactIIIFVault={},y.React,y.IIIFVault))})(this,function(y,m,fe){"use strict";function mn(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var O=mn(m),gn=Object.defineProperty,Re=Object.getOwnPropertySymbols,yn=Object.prototype.hasOwnProperty,wn=Object.prototype.propertyIsEnumerable,qe=(t,e,r)=>e in t?gn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,We=(t,e)=>{for(var r in e||(e={}))yn.call(e,r)&&qe(t,r,e[r]);if(Re)for(var r of Re(e))wn.call(e,r)&&qe(t,r,e[r]);return t};const bn={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},he=O.default.createContext(bn),Q=()=>m.useContext(he),z=({value:t,children:e})=>{const r=Q(),n=m.useMemo(()=>We(We({},r),t),[t,r]);return O.default.createElement(he.Provider,{value:n},e)},Sn=({annotation:t,children:e})=>O.default.createElement(z,{value:{annotation:t}},e),De=({canvas:t,children:e})=>O.default.createElement(z,{value:{canvas:t}},e),xn=({collection:t,children:e})=>O.default.createElement(z,{value:{collection:t}},e),Ve=({manifest:t,children:e})=>O.default.createElement(z,{value:{manifest:t}},e),On=({range:t,children:e})=>O.default.createElement(z,{value:{range:t}},e),re=O.default.createContext({vault:null,setVaultInstance:t=>{}}),Qe=({vault:t,vaultOptions:e,useGlobal:r,resources:n,children:o})=>{const[i,a]=m.useState(()=>t||(r?fe.globalVault(e):e?new fe.Vault(e):new fe.Vault));return O.default.createElement(re.Provider,{value:{vault:i,setVaultInstance:a}},O.default.createElement(z,{value:n||{}},o))};function T(){return T=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},T.apply(this,arguments)}function ye(t,e){if(t==null)return{};var r={},n=Object.keys(t),o,i;for(i=0;i<n.length;i++)o=n[i],!(e.indexOf(o)>=0)&&(r[o]=t[o]);return r}var we="loading",be="error",ze="success",Cn=0,An=function(){return Cn++},Pn={},de=typeof window>"u",k=function(){},In=function(e){return e},Se=console||{error:k,warn:k,log:k};function $n(){var t=O.default.useRef(null);return t.current===null&&(t.current=An()),t.current}function _n(t){var e=O.default.useRef();return e.current=t,O.default.useCallback(function(){return e.current},[])}function xe(t,e){return typeof t=="function"?t(e):t}function En(t,e){return Be(e)?Object.assign.apply(Object,[{}].concat(Object.keys(e).sort().map(function(r){var n;return n={},n[r]=e[r],n}))):e}function jn(t){return JSON.stringify(t,En)}function Be(t){return t&&typeof t=="object"&&!Array.isArray(t)}function He(t,e){return t===e?!0:typeof t!=typeof e?!1:typeof t=="object"?!Object.keys(e).some(function(r){return!He(t[r],e[r])}):!1}function Oe(){return typeof document>"u"||document.visibilityState===void 0||document.visibilityState==="visible"||document.visibilityState==="prerender"}function Tn(){return navigator.onLine===void 0||navigator.onLine}function Ue(t){if(Be(t[0]))if(t[0].hasOwnProperty("queryKey")&&t[0].hasOwnProperty("queryFn")){var e=t[0],r=e.queryKey,n=e.variables,o=n===void 0?[]:n,i=e.queryFn,a=e.config,s=a===void 0?{}:a;return[r,o,i,s]}else throw new Error("queryKey and queryFn keys are required.");if(typeof t[2]=="function"){var u=t[0],l=t[1],f=l===void 0?[]:l,p=t[2],d=t[3],v=d===void 0?{}:d;return[u,f,p,v]}var c=t[0],g=t[1],x=t[2],S=x===void 0?{}:x;return[c,[],g,S]}function Mn(t){var e=O.default.useRef(!1);return O.default[de?"useEffect":"useLayoutEffect"](function(){return e.current=!0,function(){return e.current=!1}},[]),O.default.useCallback(function(){return e.current?t.apply(void 0,arguments):void 0},[t])}function Fn(t){if((t.config.suspense||t.config.useErrorBoundary)&&t.status===be)throw setTimeout(function(){t.query.state.status="loading"}),t.error;if(t.config.suspense&&t.status===we)throw t.query.wasSuspended=!0,t.refetch()}function Ce(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var r,n,o;if(Array.isArray(t)){if(r=t.length,r!=e.length)return!1;for(n=r;n--!==0;)if(!Ce(t[n],e[n]))return!1;return!0}if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===e.valueOf();if(o=Object.keys(t),r=o.length,r!==Object.keys(e).length)return!1;for(n=r;n--!==0;)if(!Object.prototype.hasOwnProperty.call(e,o[n]))return!1;for(n=r;n--!==0;){var i=o[n];if(!Ce(t[i],e[i]))return!1}return!0}return t!==t&&e!==e}var Ln=O.default.createContext(),kn={retry:3,retryDelay:function(e){return Math.min(1e3*Math.pow(2,e),3e4)},staleTime:0,cacheTime:5*60*1e3,refetchAllOnWindowFocus:!0,refetchInterval:!1,suspense:!1,queryKeySerializerFn:Ne,queryFnParamsFilter:In,throwOnError:!1,useErrorBoundary:void 0,onMutate:k,onSuccess:k,onError:k,onSettled:k,refetchOnMount:!0,isDataEqual:Ce},ne={current:kn};function Rn(){return O.default.useContext(Ln)||ne.current}function Ne(t){if(!t)return[];if(typeof t=="function")try{return Ne(t())}catch{return[]}typeof t=="string"&&(t=[t]);var e=jn(t);return t=JSON.parse(e),[e,t]}function N(t,e,r){return r?e?e(t):t:((!t||!t.then)&&(t=Promise.resolve(t)),e?t.then(e):t)}function ie(t,e){try{var r=t()}catch(n){return e(n)}return r&&r.then?r.then(void 0,e):r}function G(t){return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];try{return Promise.resolve(t.apply(this,e))}catch(n){return Promise.reject(n)}}}function Ge(t,e){var r=t();return r&&r.then?r.then(e):e(r)}var Ke=Vn(),qn=O.default.createContext(Ke),Wn=[Ke];function Dn(){return O.default.useContext(qn)}var Ye={},Je={},Ze={},Xe={},et={},tt={},rt={},nt={};function Vn(){var t=[],e={queries:{},isFetching:0},r=function(){e.isFetching=Object.values(e.queries).reduce(function(a,s){return s.state.isFetching?a+1:a},0),t.forEach(function(a){return a(e)})};e.subscribe=function(i){return t.push(i),function(){t.splice(t.indexOf(i),1)}},e.clear=function(){Object.values(e.queries).forEach(function(i){return i.clear()}),e.queries={},r()};var n=function(a,s){var u=s===void 0?{}:s,l=u.exact;if(typeof a!="function"){var f=ne.current.queryKeySerializerFn(a),p=f[0],d=f[1];a=function(c){return l?c.queryHash===p:He(c.queryKey,d)}}return Object.values(e.queries).filter(a)};e.getQueries=n,e.getQuery=function(i){return n(i,{exact:!0})[0]},e.getQueryData=function(i){var a;return(a=e.getQuery(i))==null?void 0:a.state.data},e.removeQueries=function(i,a){var s=a===void 0?{}:a,u=s.exact,l=n(i,{exact:u});l.forEach(function(f){clearTimeout(f.staleTimeout),delete e.queries[f.queryHash]}),l.length&&r()},e.cancelQueries=function(i,a){var s=a===void 0?{}:a,u=s.exact,l=n(i,{exact:u});l.forEach(function(f){f.cancel()}),l.length&&r()},e.refetchQueries=G(function(i,a){var s=a===void 0?{}:a,u=s.exact,l=s.throwOnError,f=s.force,p=i===!0?Object.values(e.queries):n(i,{exact:u});return ie(function(){return N(Promise.all(p.map(function(d){return d.fetch({force:f})})))},function(d){if(l)throw d})}),e._buildQuery=function(i,a,s,u){var l=u.queryKeySerializerFn(i),f=l[0],p=l[1],d=e.queries[f];return d?(Object.assign(d,{queryVariables:a,queryFn:s}),d.config=T({},d.config,u)):(d=o({cache:e,queryKey:p,queryHash:f,queryVariables:a,queryFn:s,config:u}),!de&&d.state.data&&(d.scheduleStaleTimeout(),d.heal(),d.scheduleGarbageCollection()),d.queryHash&&(de||(e.queries[f]=d,setTimeout(function(){r()})))),d},e.prefetchQuery=G(function(){for(var i=!1,a=arguments.length,s=new Array(a),u=0;u<a;u++)s[u]=arguments[u];var l=Ue(s),f=l[0],p=l[1],d=l[2],v=l[3],c=v.force,g=ye(v,["force"]);g=T({},ne.current,g);var x=e._buildQuery(f,p,d,g);return Ge(function(){if(x.state.isStale||c)return ie(function(){return N(x.fetch({force:c}),function(S){return x.wasPrefetched=!0,i=!0,S})},function(S){if(g.throwOnError)throw S})},function(S){return i?S:x.state.data})}),e.setQueryData=function(i,a,s){var u=s===void 0?{}:s,l=u.exact,f=ye(u,["exact"]),p=n(i,{exact:l});!p.length&&typeof i!="function"&&(p=[e._buildQuery(i,void 0,function(){return Promise.resolve()},T({},ne.current,f))]),p.forEach(function(d){return d.setData(a)})};function o(i){var a=i.cache,s=i.config.queryReducer||Qn,u=typeof i.queryHash>"u",l=typeof i.config.initialData=="function"?i.config.initialData():i.config.initialData,f=typeof l<"u",p=u?!0:!f,d=i.config.manual,v=u||d||f?ze:we,c=T({},i,{instances:[],state:s(void 0,{type:Ye,initialStatus:v,initialData:l,hasInitialData:f,isStale:p,manual:d})}),g=function(h){c.state=s(c.state,h),c.instances.forEach(function(w){return w.onStateUpdate(c.state)}),r()};c.scheduleStaleTimeout=function(){c.config.staleTime!==1/0&&(c.staleTimeout=setTimeout(function(){a.getQuery(c.queryKey)&&g({type:Ze})},c.config.staleTime))},c.scheduleGarbageCollection=function(){c.config.cacheTime!==1/0&&(g({type:Xe}),c.cacheTimeout=setTimeout(function(){e.removeQueries(function(S){return S.state.markedForGarbageCollection&&S.queryHash===c.queryHash})},typeof c.state.data>"u"&&c.state.status!=="error"?0:c.config.cacheTime))},c.heal=function(){clearTimeout(c.cacheTimeout),c.cancelled=null},c.cancel=function(){c.cancelled=Pn,c.cancelPromises&&c.cancelPromises(),delete c.promise,r()},c.updateInstance=function(S){var h=c.instances.find(function(w){return w.id===S.id});h?Object.assign(h,S):(h=T({onStateUpdate:k},S),c.instances.push(S))},c.subscribe=function(S){return c.heal(),function(){c.instances=c.instances.filter(function(h){return h.id!==S}),c.instances.length||(c.cancel(),c.scheduleGarbageCollection())}};var x=G(function(S){for(var h=arguments.length,w=new Array(h>1?h-1:0),b=1;b<h;b++)w[b-1]=arguments[b];return ie(function(){var A=S.apply(void 0,c.config.queryFnParamsFilter(w));return c.cancelPromises=function(){return A.cancel==null?void 0:A.cancel()},N(A,function(P){if(delete c.shouldContinueRetryOnFocus,delete c.cancelPromises,c.cancelled)throw c.cancelled;return P})},function(A){var P=!1;if(delete c.cancelPromises,c.cancelled)throw c.cancelled;return g({type:Je}),Ge(function(){if(c.config.retry===!0||c.state.failureCount<=c.config.retry||typeof c.config.retry=="function"&&c.config.retry(c.state.failureCount,A)){if(!Oe())return c.shouldContinueRetryOnFocus=!0,P=!0,new Promise(k);delete c.shouldContinueRetryOnFocus;var C=xe(c.config.retryDelay,c.state.failureCount);return P=!0,N(new Promise(function(I,F){setTimeout(G(function(){return c.cancelled?F(c.cancelled):ie(function(){return N(x.apply(void 0,[S].concat(w)),function(ee){if(c.cancelled)return F(c.cancelled);I(ee)})},function(ee){if(c.cancelled)return F(c.cancelled);F(ee)})}),C)}))}},function(C){if(P)return C;throw A})})});return c.fetch=G(function(S){var h=S===void 0?{}:S,w=h.force,b=h.__queryFn,A=b===void 0?c.queryFn:b;if(!(!c.queryHash||!c.state.isStale&&!w))return c.promise||(c.promise=G(function(){c.cancelled=null;var P=[].concat(c.instances);return c.wasSuspended&&P.unshift(c.suspenseInstance),ie(function(){return g({type:et}),N(x.apply(void 0,[A].concat(c.queryKey,c.queryVariables)),function(C){return c.setData(function(I){return c.config.isDataEqual(I,C)?I:C}),P.forEach(function(I){return I.onSuccess&&I.onSuccess(c.state.data)}),P.forEach(function(I){return I.onSettled&&I.onSettled(c.state.data,null)}),delete c.promise,C})},function(C){if(g({type:rt,cancelled:C===c.cancelled,error:C}),delete c.promise,C!==c.cancelled)throw P.forEach(function(I){return I.onError&&I.onError(C)}),P.forEach(function(I){return I.onSettled&&I.onSettled(void 0,C)}),C})})()),c.promise}),c.setState=function(S){return g({type:nt,updater:S})},c.setData=function(S){g({type:tt,updater:S}),clearTimeout(c.staleTimeout),c.scheduleStaleTimeout()},c.clear=function(){clearTimeout(c.staleTimeout),clearTimeout(c.cacheTimeout),c.cancel()},c}return e}function Qn(t,e){switch(e.type){case Ye:return{status:e.initialStatus,error:null,isFetching:e.hasInitialData||e.manual?!1:e.initialStatus==="loading",canFetchMore:!1,failureCount:0,isStale:e.isStale,markedForGarbageCollection:!1,data:e.initialData,updatedAt:e.hasInitialData?Date.now():0};case Je:return T({},t,{failureCount:t.failureCount+1});case Ze:return T({},t,{isStale:!0});case Xe:return T({},t,{markedForGarbageCollection:!0});case et:return T({},t,{status:t.status===be?we:t.status,isFetching:!0,failureCount:0});case tt:return T({},t,{status:ze,data:xe(e.updater,t.data),error:null,isStale:!1,isFetching:!1,canFetchMore:e.canFetchMore,updatedAt:Date.now(),failureCount:0});case rt:return T({},t,{isFetching:!1,isStale:!0},!e.cancelled&&{status:be,error:e.error});case nt:return xe(e.updater,t);default:throw new Error}}var it="visibilitychange",ot="focus",zn=function(){var e=ne.current.refetchAllOnWindowFocus;Oe()&&Tn()&&Wn.forEach(function(r){return r.refetchQueries(function(n){return!n.instances.length||n.config.manual===!0?!1:n.shouldContinueRetryOnFocus?(delete n.promise,!0):typeof n.config.refetchOnWindowFocus>"u"?e:n.config.refetchOnWindowFocus}).catch(Se.error)})},Ae;function Bn(t){Ae&&Ae(),Ae=t(zn)}Bn(function(t){var e;if(!de&&((e=window)==null?void 0:e.addEventListener))return window.addEventListener(it,t,!1),window.addEventListener(ot,t,!1),function(){window.removeEventListener(it,t),window.removeEventListener(ot,t)}});function Hn(t,e,r){return r?e?e(t):t:((!t||!t.then)&&(t=Promise.resolve(t)),e?t.then(e):t)}function Un(t,e){try{var r=t()}catch(n){return e(n)}return r&&r.then?r.then(void 0,e):r}function Nn(t){return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];try{return Promise.resolve(t.apply(this,e))}catch(n){return Promise.reject(n)}}}function Gn(t,e,r,n){n===void 0&&(n={});var o=$n();n=T({},Rn(),n);var i=Dn(),a=O.default.useRef(),s=i._buildQuery(t,e,r,n),u=a.current&&typeof a.current.queryHash>"u"&&typeof s.queryHash>"u";u||(a.current=s);var l=a.current,f=O.default.useState(),p=f[1],d=Mn(p),v=_n(n),c=O.default.useCallback(Nn(function(g){var x=g===void 0?{}:g,S=x.throwOnError,h=ye(x,["throwOnError"]);return Un(function(){return Hn(l.fetch(h))},function(w){if(S)throw w})}),[l]);return l.suspenseInstance={onSuccess:function(x){return v().onSuccess(x)},onError:function(x){return v().onError(x)},onSettled:function(x,S){return v().onSettled(x,S)}},O.default.useEffect(function(){return l.updateInstance({id:o,onStateUpdate:function(){return d({})},onSuccess:function(x){return v().onSuccess(x)},onError:function(x){return v().onError(x)},onSettled:function(x,S){return v().onSettled(x,S)}}),l.subscribe(o)},[v,o,l,d]),O.default.useEffect(function(){!v().manual&&!l.wasPrefetched&&!l.wasSuspended&&l.state.isStale&&(v().refetchOnMount||l.instances.length===1)&&c().catch(Se.error),l.wasPrefetched=!1,l.wasSuspended=!1},[v,l,c]),O.default.useEffect(function(){var g=a.current;if(n.refetchInterval&&(!g.currentRefetchInterval||n.refetchInterval<g.currentRefetchInterval))return g.currentRefetchInterval=n.refetchInterval,clearInterval(g.refetchIntervalId),g.refetchIntervalId=setInterval(function(){(Oe()||n.refetchIntervalInBackground)&&c().catch(Se.error)},n.refetchInterval),function(){clearInterval(g.refetchIntervalId),delete g.refetchIntervalId,delete g.currentRefetchInterval}},[n.refetchInterval,n.refetchIntervalInBackground,c]),T({},l.state,{config:n,query:l,refetch:c})}function Pe(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];var n=Gn.apply(void 0,Ue(e));return Fn(n),n}const E=()=>{const{vault:t}=m.useContext(re);if(t===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return t};var Kn=Object.defineProperty,at=Object.getOwnPropertySymbols,Yn=Object.prototype.hasOwnProperty,Jn=Object.prototype.propertyIsEnumerable,st=(t,e,r)=>e in t?Kn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Zn=(t,e)=>{for(var r in e||(e={}))Yn.call(e,r)&&st(t,r,e[r]);if(at)for(var r of at(e))Jn.call(e,r)&&st(t,r,e[r]);return t},Xn=(t,e,r)=>new Promise((n,o)=>{var i=u=>{try{s(r.next(u))}catch(l){o(l)}},a=u=>{try{s(r.throw(u))}catch(l){o(l)}},s=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);s((r=r.apply(t,e)).next())});const ct=(t,e={})=>{const r=E(),[n,o]=m.useState(t),i=m.useMemo(()=>r.get(t)||void 0,[t,r]),{data:a,error:s}=Pe(["manifest",t],()=>Xn(void 0,null,function*(){const u=i||(yield r.load(t));return u&&n!==u.id&&o(u.id),u}),Zn({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,retry:!1,initialData:i},e));return{isLoaded:!!a,id:n,error:s,manifest:a}};function M(t,e=[]){const r=E(),[n,o]=m.useState(()=>t(r.getState(),r));return m.useEffect(()=>r.subscribe(i=>t(i,r),i=>{o(i)},!0),e),n}const oe=O.default.createContext([]);function ut(){const t=m.useContext(oe);return M(e=>t.map(r=>e.iiif.entities.Canvas[r]).filter(Boolean),[t])}const pe=()=>{},ae=m.createContext({setCurrentCanvasId:pe,setCurrentCanvasIndex:pe,nextCanvas:pe,previousCanvas:pe,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),ei=t=>{const e=ct(t.manifest),[r,n]=m.useState(""),[o,i]=m.useState([]),a=(typeof t.pagingEnabled>"u"||t.pagingEnabled)&&e.manifest&&e.manifest.behavior&&e.manifest.behavior.includes("paged");m.useEffect(()=>{var c,g;e.manifest&&(n((c=e.manifest.items[0])==null?void 0:c.id),i([(g=e.manifest.items[0])==null?void 0:g.id]))},[e.manifest,t.manifest]);const s=m.useMemo(()=>{var c;return((c=e.manifest)==null?void 0:c.items.map(g=>g.id))||[]},[e.manifest,t.manifest]),u=m.useMemo(()=>s.indexOf(r),[s,r]),l=m.useCallback(()=>{if(s.length&&r){if(u===-1||(s[u+2]?u+2===s.length:u===s.length))return;const c=a&&u!==0?s[u+2]:s[u+1],g=a?u!==0?s[u+3]:s[u+2]:null;c&&(n(c),i(g?[c,g]:[c]))}},[a,s,r,u]),f=m.useCallback(()=>{if(s.length&&r){if(u===0||u===-1)return;const c=a&&u!==1?s[u-2]:s[u-1],g=a&&u!==1?s[u-1]:null;c&&(n(c),i(g?[c,g]:[c]))}},[a,s,r,u]),p=m.useCallback(c=>{const g=a&&c%2===1?c-1:c,x=s[g],S=a&&g!==0?s[g+1]:null;x&&(n(x),i(h=>{const w=S?[x,S]:[x];if(h.length===h.length){for(let b=0;b<h.length;b++)if(h[b]!==w[b])return w;return h}return w}))},[a,s]),d=m.useCallback(c=>{const g=s.indexOf(c);g!==-1&&p(g)},[s,p]),v=m.useMemo(()=>({setCurrentCanvasId:d,nextCanvas:l,previousCanvas:f,currentCanvasIndex:u,totalCanvases:s.length,setCurrentCanvasIndex:p,pagingView:!0}),[l,f,u,s,p,d]);return!e.isLoaded||!e.manifest?O.default.createElement("div",null,"Loading..."):O.default.createElement(ae.Provider,{value:v},O.default.createElement(oe.Provider,{value:o},O.default.createElement(Ve,{manifest:e.manifest.id},O.default.createElement(De,{canvas:r},t.children))))};function ti(){return m.useContext(ae)}function ri(){return{VaultContext:m.useContext(re),ResourceContext:m.useContext(he),SimpleViewerReactContext:m.useContext(ae),VisibleCanvasReactContext:m.useContext(oe)}}const ni=t=>O.default.createElement(Qe,{vault:t.bridge.VaultContext.vault||void 0,resources:t.bridge.ResourceContext},O.default.createElement(oe.Provider,{value:t.bridge.VisibleCanvasReactContext},O.default.createElement(ae.Provider,{value:t.bridge.SimpleViewerReactContext},t.children)));function B(t){return t.endsWith("info.json")?t:t.endsWith("/")?`${t}info.json`:`${t}/info.json`}const ii="http://library.stanford.edu/iiif/image-api/compliance.html#level0",lt="http://library.stanford.edu/iiif/image-api/compliance.html#level1",ft="http://library.stanford.edu/iiif/image-api/compliance.html#level2",oi="http://library.stanford.edu/iiif/image-api/conformance.html#level0",ht="http://library.stanford.edu/iiif/image-api/conformance.html#level1",dt="http://library.stanford.edu/iiif/image-api/conformance.html#level2",ai="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",pt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",vt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",si="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",mt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",gt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",ci="http://iiif.io/api/image/1/level0.json",ui="http://iiif.io/api/image/1/profiles/level0.json",yt="http://iiif.io/api/image/1/level1.json",wt="http://iiif.io/api/image/1/profiles/level1.json",bt="http://iiif.io/api/image/1/level2.json",St="http://iiif.io/api/image/1/profiles/level2.json",li="http://iiif.io/api/image/2/level0.json",fi="http://iiif.io/api/image/2/profiles/level0.json",xt="http://iiif.io/api/image/2/level1.json",Ot="http://iiif.io/api/image/2/profiles/level1.json",Ct="http://iiif.io/api/image/2/level2.json",At="http://iiif.io/api/image/2/profiles/level2.json",hi="level0",Pt="level1",It="level2",di="http://iiif.io/api/image/2/level0",$t="http://iiif.io/api/image/2/level1",_t="http://iiif.io/api/image/2/level2",Et=[_t,ft,dt,vt,gt,bt,St,Ct,At,It],jt=[...Et,$t,lt,ht,pt,mt,yt,wt,xt,Ot,Pt],pi=[di,$t,_t,ii,lt,ft,oi,ht,dt,ai,pt,vt,si,mt,gt,ci,ui,yt,wt,bt,St,li,fi,xt,Ot,Ct,At,hi,Pt,It],vi={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},mi={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},gi={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function yi(t){return Et.indexOf(t)!==-1?gi:jt.indexOf(t)!==-1?mi:vi}function wi(t){const e=t?Array.isArray(t.profile)?t.profile:[t.profile]:[],r={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let n of e)if(typeof n=="string"&&(n=yi(n)),!!n){if(n.formats)for(const o of n.formats)r.extraFormats.indexOf(o)===-1&&r.extraFormats.push(o);if(n.qualities)for(const o of n.qualities)r.extraQualities.indexOf(o)===-1&&r.extraQualities.push(o);if(n.supports)for(const o of n.supports)r.extraFeatures.indexOf(o)===-1&&r.extraFeatures.push(o);if(n.maxHeight&&(r.maxHeight=n.maxHeight),n.maxWidth&&(r.maxWidth=n.maxWidth),n.maxArea&&(r.maxArea=n.maxArea),n.extraFormats)for(const o of n.extraFormats)r.extraFormats.indexOf(o)===-1&&r.extraFormats.push(o);if(n.extraQualities)for(const o of n.extraQualities)r.extraQualities.indexOf(o)===-1&&r.extraQualities.push(o);if(n.extraFeatures)for(const o of n.extraFeatures)r.extraFeatures.indexOf(o)===-1&&r.extraFeatures.push(o);n.maxHeight&&(r.maxHeight=n.maxHeight),n.maxWidth&&(r.maxWidth=n.maxWidth),n.maxArea&&(r.maxArea=n.maxArea)}if(t.extraFormats)for(const n of t.extraFormats)r.extraFormats.indexOf(n)===-1&&r.extraFormats.push(n);if(t.extraFeatures)for(const n of t.extraFeatures)r.extraFeatures.indexOf(n)===-1&&r.extraFeatures.push(n);if(t.extraQualities)for(const n of t.extraQualities)r.extraQualities.indexOf(n)===-1&&r.extraQualities.push(n);return r}function bi(t){try{if(t==="full")return{full:!0};if(t==="square")return{square:!0};const e=t.startsWith("pct:"),r=t.substr(e?4:0).split(",").map(n=>parseFloat(n));return{x:r[0],y:r[1],w:r[2],h:r[3],percent:e}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+t)}}function Si(t){const e={upscaled:!1,max:!1,confined:!1};if(t[0]==="^"&&(e.upscaled=!0,t=t.slice(1)),t==="max"||t==="full")return e.max=!0,e.serialiseAsFull=t==="full",e;if(t[0]==="!"&&(e.confined=!0,t=t.slice(1)),t[0]==="p")return e.percentScale=parseFloat(t.slice(4)),e;const r=t.split(",").map(n=>n.trim());return r.length&&(r[0]!==""&&(e.width=parseInt(r[0],10)),r[1]!==""&&(e.height=parseInt(r[1],10))),e}function xi(t){const e={angle:0};if(t[0]==="!"&&(e.mirror=!0,t=t.substr(1)),e.angle=parseFloat(t)%360,Number.isNaN(e.angle))throw new Error(`Invalid rotation ${t}`);return e}function Oi(t,e=""){const r=t.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!r)throw new Error(`Invalid or unknown input ${t}`);const n=r[2],o=r[3];let i=r[4];if(i[0]==="/"&&(i=i.substr(1)),e.length>0){if(e[0]==="/"&&(e=e.substr(1)),e!==i.substr(0,e.length))throw new Error(`Path does not start with prefix (path: ${i}, prefix: ${e})`);i=i.substr(e.length)}return{scheme:n,server:o,path:i,prefix:e}}function Ci(t,e=""){const{path:r,scheme:n,server:o,prefix:i}=Oi(t,e),a=r.split("/").reverse(),[s,u,l,f,...p]=a,d=p.reverse().filter(Boolean).join("/");if(a.length===1||s==="")return{type:"base",scheme:n,server:o,prefix:i,identifier:d};if(s==="info.json"){const[,...c]=a;return{type:"info",scheme:n,server:o,prefix:i,identifier:c.reverse().filter(Boolean).join("/")}}const v=s.split(".");return{type:"image",scheme:n,server:o,prefix:i,identifier:d,originalPath:r,region:bi(f),size:Si(l),rotation:xi(u),quality:v[0],format:v[1]}}function Ai(t){const e=Ci(B(t.id));if(e.type!=="info")throw new Error("Invalid service URL");const r=wi(t);return{identifier:e.identifier,originalPath:"",server:e.server,prefix:e.prefix,scheme:e.scheme,type:"image",quality:r.extraQualities.indexOf("default")===-1?r.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}}function Pi(t,e,r){const n=r.length,o=[];for(let i=0;i<n;i++){const a=r[i].width;o.push(t/a)}return o}function Ii(t,e,r){const n=r.length,o=[];for(let i=0;i<n;i++){const a=r[i];o.push({width:Math.floor(t/a),height:Math.floor(e/a)})}return o}function $(t){if(t["@id"])return t["@id"];if(t.id)return t.id}function Ie(t){if(!t||!t.profile||!$(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const r of e)if(typeof r=="string"&&pi.indexOf(r)!==-1)return!0;return!1}function $i(t){if(!Ie(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const r of e)if(typeof r=="string"){if(jt.indexOf(r)!==-1)return!0}else{const n=[...r.supports||[],...r.extraFeatures||[]];if(n.indexOf("regionByPx")!==-1&&(n.indexOf("sizeByW")!==-1||n.indexOf("sizeByWh")!==-1))return!0}return!1}function _i(t){if(!$i(t))return[];const e=[],r=Array.isArray(t.profile)?t.profile:[t.profile],n=r.length;for(let o=0;o<n;o++){const i=r[o];if(typeof i!="string"&&(i.maxHeight||i.maxWidth))return[{id:$(t),type:"variable",minWidth:0,minHeight:0,maxHeight:i.maxHeight||i.maxWidth,maxWidth:i.maxWidth||i.maxHeight}]}if(t.tiles){const o=t.tiles.length;for(let i=0;i<o;i++){const a=t.tiles[i];(a.height||a.width)&&e.push({id:$(t),type:"variable",minHeight:0,minWidth:0,maxHeight:a.height||a.width,maxWidth:a.width})}}return e}function Tt(t){const e=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,r=t.match(e);if(r){const n=r[1],o=parseInt(r[4],10),i=parseInt(r[5],10),a=r[7];if((n==="max"||n==="full")&&o&&i&&a)return{type:"fixed",id:t,height:i,width:o}}return{type:"unknown",id:t}}function Ei(t){if(t["@type"])return t["@type"];if(t.type)return t.type}function ji(t){if(typeof t=="string")return Tt(t);const e=Ei(t);if(e!=="Image"&&e!=="sc:Image")return null;const r=t,n=$(r);return n?n&&r.width&&r.height?{id:n,type:"fixed",width:r.width,height:r.height,unsafe:!0}:Tt(n):null}function Ti(t){return Ie(t)?(t&&t.sizes?t.sizes:[]).map(e=>({id:$(t),type:"fixed-service",height:e.height,width:e.width})):[]}function Mt(t){const e=[],r=t.length;for(let n=0;n<r;n++){const o=Ti(t[n]);o.length&&e.push(...o);const i=_i(t[n]);i.length&&e.push(...i)}return e}function se(t){const e=t.service?Array.isArray(t.service)?t.service:[t.service]:[],r=e.length,n=[];for(let o=0;o<r;o++)Ie(e[o])&&n.push(e[o]);return n}function Mi(t,e=!0,r){const n=[],o=ji(t);if(o===null)return n;const i=t;if(n.push(o),e&&i.width&&i.height){const a=[],s=se(i);for(const u of s){const l={id:$(u),width:i.width,height:i.height};if(r.canLoadSync(l)){const f=r.loadServiceSync(l);f&&(f.height||(f.height=i.height),f.width||(f.width=i.width),a.push(...Mt([f])))}}if(a.length)return n.push(...a),n}return i.service&&n.push(...Mt(i.service)),n}function Fi({x:t=0,y:e=0,w:r,h:n,full:o,square:i,percent:a}){if(o)return"full";if(i)return"square";if(typeof r>"u"||typeof n>"u")throw new Error("RegionParameter: invalid region");const s=`${t},${e},${r},${n}`;return a?`pct:${s}`:s}function Li({max:t,percentScale:e,upscaled:r,confined:n,width:o,height:i,serialiseAsFull:a}){const s=[];return r&&s.push("^"),t?(s.push(a?"full":"max"),s.join("")):(n&&s.push("!"),e&&s.push(`pct:${e}`),o&&s.push(`${o}`),s.push(","),i&&s.push(`${i}`),s.join(""))}function ki(t){return`${t.mirror?"!":""}${(t.angle||0)%360}`}var Ri=Object.defineProperty,qi=Object.defineProperties,Wi=Object.getOwnPropertyDescriptors,Ft=Object.getOwnPropertySymbols,Di=Object.prototype.hasOwnProperty,Vi=Object.prototype.propertyIsEnumerable,Lt=(t,e,r)=>e in t?Ri(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ce=(t,e)=>{for(var r in e||(e={}))Di.call(e,r)&&Lt(t,r,e[r]);if(Ft)for(var r of Ft(e))Vi.call(e,r)&&Lt(t,r,e[r]);return t},ue=(t,e)=>qi(t,Wi(e));function Qi(t,e){const r=t.prefix.startsWith("/")?t.prefix.substr(1):t.prefix,n=`${t.scheme}://${t.server}/${r?`${r}/`:""}${t.identifier}`;if(t.type==="base")return n;if(t.type==="info")return`${n}/info.json`;let{region:o,size:i,rotation:a,format:s,quality:u}=t;if(e){const l=e["@context"]?Array.isArray(e["@context"])?e["@context"]:[e["@context"]]:[],f=l.indexOf("http://iiif.io/api/image/2/context.json")!==-1,p=l.indexOf("http://iiif.io/api/image/3/context.json")!==-1;if((i.width===e.width&&!i.height||i.height===e.height&&!i.width||i.width===e.width&&i.height===e.height)&&(i=ue(ce({},i),{max:!0})),f&&(i.max&&!i.serialiseAsFull&&(i=ue(ce({},i),{serialiseAsFull:!0})),!i.max&&i.width&&i.height&&(i=ue(ce({},i),{height:void 0}))),p&&(i.max&&i.serialiseAsFull&&(i=ue(ce({},i),{serialiseAsFull:!1})),i.width&&!i.height&&e.width&&e.height)){const d=e.height/e.width;i=ue(ce({},i),{height:Math.ceil(i.width*d)})}}return[n,Fi(o),Li(i),ki(a),`${u}.${s}`].filter(Boolean).join("/")}function $e(t,e,r){const n=Ai({id:B($(t)),profile:"level2",type:"ImageService2"});if(n.type!=="image")throw new Error("Invalid service");return n.size.max=!1,n.size.width=e,n.size.height=r,{id:Qi(n),type:"fixed",width:e,height:r||t.height/(t.width||1)*e,unsafe:t.width>e}}function K(t){const e=t.replace(/(https?:\/\/)?(www.)?/i,"");return e.indexOf("/")!==-1?e.split("/")[0]:e}function zi(t,e,r){const n=t.width?t.width:t.maxWidth;return r.height<=t.maxHeight&&r.width<=t.maxWidth&&r.height>=t.minHeight&&r.width>=t.minWidth&&(!e||Math.abs(r.width-n)<Math.abs(e.width-n))}function Bi(t,e){const r=[],n=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},t),o=[],i=[];let a=null;const s=(l,f)=>{if(zi(n,f,l)){if(n.preferFixedSize&&l.unsafe){i.push(l);return}n.returnAllOptions&&f&&i.push(f),a=l}else n.returnAllOptions&&i.push(l)},u=e.length;for(let l=0;l<u;l++){const f=e[l](),p=f.length;for(let d=0;d<p;d++){const v=f[d];if(v.type==="unknown"&&n.atAnyCost&&o.push(v),v.type==="fixed"&&(v.unsafe?o.push(v):s(v,a)),v.type==="fixed-service")if(n.unsafeImageService){const c=$e(v,n.width,n.height);s(c,a)}else{const c=$e(v,v.width,v.height);s(c,a)}if(v.type==="variable"&&v.maxWidth){const c=$e({id:v.id,type:"fixed-service",width:v.maxWidth,height:v.maxWidth},v.maxWidth);s(c,a)}}if(a&&!n.returnAllOptions){if(a.unsafe||n.allowUnsafe)continue;break}}return n.atAnyCost&&i.length===0?{best:a||o[0],fallback:o.slice(1),log:r}:n.returnAllOptions?{best:n.atAnyCost?a||i[0]||o[0]:a||i[0],fallback:[...i,...o],log:r}:{best:a||i[0]||null,fallback:a?i:i.slice(1),log:r}}var Hi=Object.defineProperty,Ui=Object.defineProperties,Ni=Object.getOwnPropertyDescriptors,kt=Object.getOwnPropertySymbols,Gi=Object.prototype.hasOwnProperty,Ki=Object.prototype.propertyIsEnumerable,Rt=(t,e,r)=>e in t?Hi(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Yi=(t,e)=>{for(var r in e||(e={}))Gi.call(e,r)&&Rt(t,r,e[r]);if(kt)for(var r of kt(e))Ki.call(e,r)&&Rt(t,r,e[r]);return t},Ji=(t,e)=>Ui(t,Ni(e));function Zi(t,e,r){const n=t>e?t:e,o=r.length,i=[];for(let a=0;a<o;a++){const s=r[a];let u=s.scaleFactors[0],l=n/u;const f=[u];for(;l>=s.width;)u=u*2,f.push(u),l=l/2;i.push(Ji(Yi({},s),{scaleFactors:f}))}return i}function Xi(t,e){if(t.length!==e.length)return!1;if(t.length===0&&e.length===0)return!0;const r=t.length;let n=!0;for(let i=0;i<r;i++){const a=t[i],s=e[i];if(a.width!==s.width||a.height!==s.height){n=!1;break}}if(n)return!0;let o=0;for(let i=0;i<r;i++)for(let a=0;a<r;a++)if(t[i].width===e[a].width&&t[i].height===e[a].height){o++;break}return o===r}var H=(t,e,r)=>new Promise((n,o)=>{var i=u=>{try{s(r.next(u))}catch(l){o(l)}},a=u=>{try{s(r.throw(u))}catch(l){o(l)}},s=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);s((r=r.apply(t,e)).next())});class qt{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(e){Object.assign(this.config,e)}sample(e,r,n=!0){const o=K($(e)),i=B($(e)),a=this.knownImageServers[o];return this.imageServices[i]=Object.assign(e,{real:!0}),a?this.verify(e):(this.knownImageServers[o]={verifications:0,malformed:!1,root:o,preLoaded:n,sampledId:$(e),verified:!1,server:null,result:{context:e["@context"]||[],sampledProfile:e.profile,resourceServiceRatio:r&&e.height?r.height/e.height:1,sampledSizes:e.sizes||[],sizeRatios:Pi(e.width,e.height,e.sizes||[]),sampledTiles:e.tiles||[]}},!0)}preLoad(e,r=!0){this.knownImageServers[e.root]=e,r&&(this.knownImageServers[e.root].malformed=!1,this.knownImageServers[e.root].verifications=this.config.verificationsRequired)}predict(e,r=!1,n=!1){const o=K($(e)),i=this.knownImageServers[o];if(!i||!i.result||!n&&(i.malformed||i.verifications<this.config.verificationsRequired))return null;const a=B($(e));return this.imageServices[a]||(this.imageServices[a]={"@context":i.result.context,"@id":$(e),id:$(e),protocol:"http://iiif.io/api/image",tiles:Zi(e.width,e.height,i.result.sampledTiles),sizes:Ii(Math.floor(e.width/i.result.resourceServiceRatio),Math.floor(e.height/i.result.resourceServiceRatio),i.result.sizeRatios),profile:i.result.sampledProfile,height:e.height,width:e.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(e,r){return H(this,arguments,function*(n,o,i=!0,a=[]){const s=yield this.getImageCandidates(n,i);return Bi(o,[()=>a,()=>s])})}getImageCandidates(e,r=!0){return H(this,null,function*(){const n=e;if(r&&n.height&&n.width){const o=se(n);for(const i of o){const a={id:$(i),width:i.width?i.width:n.width,height:i.height?i.height:n.height};yield this.loadService(a)}}return Mi(e,r,this)})}verify(e){return H(this,null,function*(){const r=this.predict(e,!1,!0),n=yield this.fetchService($(e));if(!r)return!1;const o=r.height===n.height&&r.width===n.width&&r["@context"]===n["@context"]&&Xi(r.sizes||[],n.sizes||[]);if(o){const i=K($(e));this.knownImageServers[i].verifications+=1,this.knownImageServers[i].verifications>=this.config.verificationsRequired&&(this.knownImageServers[i].verified=!0)}return o})}canLoadSync(e){const r=typeof e=="string"?e:$(e),n=B(r);if(this.imageServices[n])return!0;const o=this.knownImageServers[K(r)];return o&&!o.malformed&&o.verifications>=this.config.verificationsRequired}markAsMalformed(e){return H(this,null,function*(){return this.knownImageServers[K($(e))].malformed=!0,this.loadService(e,!0)})}fetchService(e,r=!1){return H(this,null,function*(){const n=B(e);if(this.imageServices[n]&&(!r||this.imageServices[n].real))return this.imageServices[n];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const o=yield this.fetch(n).then(i=>i.json());return!o.id&&o["@id"]&&(o.id=o["@id"]),o.id!==e&&(o.id=e,o["@id"]&&(o["@id"]=e)),this.imageServices[n]=Object.assign(o,{real:!0}),this.imageServices[n]})}fetch(e,r){return H(this,null,function*(){return fetch(e,r)})}loadService(e,r=!1){return H(this,null,function*(){if(!this.config.disableThrottling){let i=!0;for(;i;)if(this.fetchingCount>=this.config.verificationsRequired)yield new Promise(a=>setTimeout(a,500));else{i=!1;break}}const n=this.knownImageServers[K($(e))];if(n&&!n.malformed&&!r){yield n.result;const i=this.loadServiceSync(e);if(i)return i}this.fetchingCount++;const o=yield this.fetchService($(e),r);return this.fetchingCount--,o.real&&this.sample(o,e),o})}loadServiceSync(e){const r=B($(e));return this.imageServices[r]?this.imageServices[r]:this.predict(e)}}new qt;const Wt=O.default.createContext(new qt);function ve(){return m.useContext(Wt)}const eo=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,to=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function me(t){if(Array.isArray(t))return t.reduce((e,r)=>{const{selector:n,selectors:o}=me(r);return n&&(e.selector||(e.selector=n),e.selectors.push(...o)),e},{selector:null,selectors:[]});if(!t)return{selector:null,selectors:[]};if(typeof t=="string"){const[e,r]=t.split("#");return r?me({type:"FragmentSelector",value:r}):{selector:null,selectors:[]}}if(t.type==="PointSelector"&&(t.t||t.t===0)){const e={type:"TemporalSelector",temporal:{startTime:t.t}};return{selector:e,selectors:[e]}}if(t.type==="FragmentSelector"){const e=eo.exec(t.value);if(e){const n={type:"BoxSelector",spatial:{unit:e[2]==="percent:"?"percent":"pixel",x:parseFloat(e[3]),y:parseFloat(e[4]),width:parseFloat(e[5]),height:parseFloat(e[6])}};return{selector:n,selectors:[n]}}const r=t.value.match(to);if(r){const n={type:"TemporalSelector",temporal:{startTime:r[4]?parseFloat(r[4]):0,endTime:r[7]?parseFloat(r[7]):void 0}};return{selector:n,selectors:[n]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}var ro=Object.defineProperty,no=Object.defineProperties,io=Object.getOwnPropertyDescriptors,Dt=Object.getOwnPropertySymbols,oo=Object.prototype.hasOwnProperty,ao=Object.prototype.propertyIsEnumerable,Vt=(t,e,r)=>e in t?ro(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Qt=(t,e)=>{for(var r in e||(e={}))oo.call(e,r)&&Vt(t,r,e[r]);if(Dt)for(var r of Dt(e))ao.call(e,r)&&Vt(t,r,e[r]);return t},zt=(t,e)=>no(t,io(e));function D(t,e={}){if(Array.isArray(t))return D(t[0]);if(typeof t=="string"){const[r,n]=t.split("#");return n?D({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{id:r,type:e.typeMap&&e.typeMap[r]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return D(t.items[0]);if(t.type==="SpecificResource"){t.source.type==="Canvas"&&t.source.partOf&&typeof t.source.partOf=="string"&&(t.source.partOf=[{id:t.source.partOf,type:"Manifest"}]);const{selector:r,selectors:n}=t.selector?me(t.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:r,selectors:n}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[r,n]=t.id.split("#");return n?D({type:"SpecificResource",source:zt(Qt({},t),{id:r}),selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:zt(Qt({},t),{id:r}),selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}function Bt(t){return t.type==="SpecificResource"?[t.source,{selector:t.selector}]:[t,{selector:null}]}function Ht(t,e,r){const n=[];let o=null;const i=[];for(const a of e){const s=t.get(a.body);for(const u of s){const[l,{selector:f}]=Bt(u),p=(l.type||"unknown").toLowerCase();if(p==="choice"){const d=t.get(l.items),v=r.length?r.map(c=>d.find(g=>g.id===c)).filter(Boolean):[d[0]];v.length===0&&v.push(d[0]),o={type:"single-choice",items:d.map(c=>({id:c.id,label:c.label,selected:v.indexOf(c)!==-1})),label:u.label},s.push(...v);continue}n.indexOf(p)===-1&&n.push(p),i.push({type:p,resource:l,target:a.target,selector:f})}}return{types:n,items:i,choice:o}}const Ut={makeChoice:()=>{}},_e={type:"unknown"},R=t=>({type:"unknown",reason:t,annotations:{pages:[]}});function Nt(t,e,r){const n=[];for(const o of e.items){const i=o.resource&&o.resource.type==="SpecificResource"?o.resource.source:o.resource;if(!i.id)return R("No resource Identifier");let a;if(i.service){const g=se(i);g[0]&&(a=r(g[0],t))}const{selector:s,source:u}=D(o.target);if(u.id!==t.id)continue;const l={type:"BoxSelector",spatial:{x:0,y:0,width:t.width,height:t.height}},f=s?s.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:s.temporal,spatial:l.spatial}:s:null,p={type:"BoxSelector",spatial:{x:0,y:0,width:t.width,height:t.height}},d=o.resource.type==="SpecificResource"?D(o.resource):null,v=d&&d.selector&&(d.selector.type==="BoxSelector"||d.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:d.selector.spatial.x,y:d.selector.spatial.y,width:d.selector.spatial.width,height:d.selector.spatial.height}}:p,c={id:i.id,type:"Image",width:f?i.width:t.width,height:f?i.height:t.height,service:a,sizes:a&&a.sizes?a.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:f&&f.type!=="PointSelector"?f:l,selector:v};n.push(c)}return{type:"images",image:n[0],images:n,choice:e.choice}}var so=Object.defineProperty,co=Object.defineProperties,uo=Object.getOwnPropertyDescriptors,Gt=Object.getOwnPropertySymbols,lo=Object.prototype.hasOwnProperty,fo=Object.prototype.propertyIsEnumerable,Kt=(t,e,r)=>e in t?so(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ho=(t,e)=>{for(var r in e||(e={}))lo.call(e,r)&&Kt(t,r,e[r]);if(Gt)for(var r of Gt(e))fo.call(e,r)&&Kt(t,r,e[r]);return t},po=(t,e)=>co(t,uo(e));function vo(t={},e=[]){const{id:r,selector:n}=t,o=Q(),i=E(),a=r||o.annotation,s=M(l=>a?l.iiif.entities.Annotation[a]:void 0,[a]),u=M(l=>s&&s.body?s.body.map(f=>f?l.iiif.entities[f.type][f.id]:null).filter(Boolean):[],[s]);return m.useMemo(()=>{if(!s)return;const l=po(ho({},s),{body:u,target:D(s.target,{typeMap:i.getState().iiif.mapping})});return n?n(l):l},[s,n,u,...e])}function le(t={},e=[]){const{id:r,selector:n}=t,o=Q();E();const i=r||o.manifest,a=M(s=>i?s.iiif.entities.Manifest[i]:void 0,[i]);return m.useMemo(()=>{if(!!a)return n?n(a):a},[a,n,...e])}function Y(t={},e=[]){const{id:r,selector:n}=t,o=Q(),i=r||o.canvas,a=M(s=>i?s.iiif.entities.Canvas[i]:void 0,[i]);return m.useMemo(()=>{if(!!a)return n?n(a):a},[a,n,...e])}function mo(t,e){var r;const n=(r=t==null?void 0:t.iiif)==null?void 0:r.meta[e];return n?n.annotationPageManager:null}function go(t,e){return M(r=>{const n=[];if(!t)return n;const o=Object.keys(r.iiif.entities.AnnotationPage);for(const i of o)if(!e||e.indexOf(i)!==-1){const a=mo(r,i);a&&a.views&&a.views[t]&&n.push(i)}return n},[t])}function Yt({canvas:t,manifest:e,all:r,canvases:n}){const o=[];if(e)for(const i of e.annotations)o.indexOf(i.id)===-1&&o.push(i.id);if(r){if(n&&n.length)for(const i of n)for(const a of i.annotations)o.indexOf(a.id)===-1&&o.push(a.id)}else if(t)for(const i of t.annotations)o.indexOf(i.id)===-1&&o.push(i.id);return o}var yo=Object.defineProperty,wo=Object.defineProperties,bo=Object.getOwnPropertyDescriptors,Jt=Object.getOwnPropertySymbols,So=Object.prototype.hasOwnProperty,xo=Object.prototype.propertyIsEnumerable,Zt=(t,e,r)=>e in t?yo(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Xt=(t,e)=>{for(var r in e||(e={}))So.call(e,r)&&Zt(t,r,e[r]);if(Jt)for(var r of Jt(e))xo.call(e,r)&&Zt(t,r,e[r]);return t},er=(t,e)=>wo(t,bo(e));function Oo(t,e){var r;const n=(r=t==null?void 0:t.iiif)==null?void 0:r.meta[e];return n?n.annotationPageManager:null}function tr(t,e={}){const r=E(),n=le(),o=Y(),i=ut(),a=m.useMemo(()=>Yt({all:e.all,manifest:n,canvas:o,canvases:i}),[e.all,o,i,n]),s=go(t,e.all?void 0:a),u=m.useCallback(f=>{!t||r.setMetaValue([f,"annotationPageManager","views"],p=>p&&!p[t]?p:er(Xt({},p||{}),{[t]:!1}))},[t,r]),l=m.useCallback((f,p={})=>{if(!t)return;const d=r.getState(),v=[];if(p==null?void 0:p.deselectOthers){const c=Object.keys(d.iiif.entities.AnnotationPage);for(const g of c){const x=Oo(d,g);x&&x.views&&x.views[t]&&v.push(g)}}for(const c of v)u(c);r.setMetaValue([f,"annotationPageManager","views"],c=>c&&c[t]?c:er(Xt({},c||{}),{[t]:!0}))},[t,u,r]);return{availablePageIds:a,enabledPageIds:s,setPageEnabled:l,setPageDisabled:u}}function ge(t={}){const e=Y(t.canvasId?{id:t.canvasId}:void 0);return M((r,n)=>{if(!e)return[];const o=n.get(e.items),i=[];for(const a of o)i.push(...n.get(a.items));return i},[e])}function Co(t,e={}){return ge(e)}function Ao(t,e=!1){}function Po(t,e=[]){const{id:r,selector:n}=t,o=Q(),i=r||o.collection,a=M(s=>i?s.iiif.entities.Collection[i]:void 0,[i]);return m.useMemo(()=>{if(!!a)return n?n(a):a},[a,n,...e])}function rr(){const e=E().getStore();return m.useMemo(()=>r=>e.dispatch(r),[e])}function nr(t){return{addEventListener(e,r,n,o){if(e)return t.setMetaValue([e.id,"eventManager",r],i=>{const a=i||[];for(const s of a)if(s.callback===n)return a;return[...a,{callback:n,scope:o}]}),n},removeEventListener(e,r,n){!e||t.setMetaValue([e.id,"eventManager",r],o=>(o||[]).filter(i=>i.callback!==n))},getListenersAsProps(e,r){const n=typeof e=="string"?{id:e}:e;if(!n||!n.id)return{};const o=t.getResourceMeta(n.id,"eventManager"),i={};if(o&&n)for(const a of Object.keys(o))i[a]=s=>{const u=t.get(n);for(const{callback:l,scope:f}of o[a]||[])(!f||r&&f.indexOf(r)!==-1)&&l(s,u)};return i}}}function ir(t){return{applyStyles(e,r,n){const o=typeof e=="string"?e:e.id;return t.setMetaValue([o,"styles",r],n)},getAppliedStyles(e){const r=typeof e=="string"?e:e.id;return t.getResourceMeta(r,"styles")}}}function J(t){return t.endsWith("info.json")?t:t.endsWith("/")?`${t}info.json`:`${t}/info.json`}function Io(t,e,r){const n=r.length,o=[];for(let i=0;i<n;i++){const a=r[i].width;o.push(t/a)}return o}function $o(t,e,r){const n=r.length,o=[];for(let i=0;i<n;i++){const a=r[i];o.push({width:Math.floor(t/a),height:Math.floor(e/a)})}return o}const _o="http://library.stanford.edu/iiif/image-api/compliance.html#level0",or="http://library.stanford.edu/iiif/image-api/compliance.html#level1",ar="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Eo="http://library.stanford.edu/iiif/image-api/conformance.html#level0",sr="http://library.stanford.edu/iiif/image-api/conformance.html#level1",cr="http://library.stanford.edu/iiif/image-api/conformance.html#level2",jo="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",ur="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",lr="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",To="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",fr="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",hr="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Mo="http://iiif.io/api/image/1/level0.json",Fo="http://iiif.io/api/image/1/profiles/level0.json",dr="http://iiif.io/api/image/1/level1.json",pr="http://iiif.io/api/image/1/profiles/level1.json",vr="http://iiif.io/api/image/1/level2.json",mr="http://iiif.io/api/image/1/profiles/level2.json",Lo="http://iiif.io/api/image/2/level0.json",ko="http://iiif.io/api/image/2/profiles/level0.json",gr="http://iiif.io/api/image/2/level1.json",yr="http://iiif.io/api/image/2/profiles/level1.json",wr="http://iiif.io/api/image/2/level2.json",br="http://iiif.io/api/image/2/profiles/level2.json",Ro="level0",Sr="level1",xr="level2",qo="http://iiif.io/api/image/2/level0",Or="http://iiif.io/api/image/2/level1",Cr="http://iiif.io/api/image/2/level2",Wo=[Or,Cr,or,ar,sr,cr,ur,lr,fr,hr,dr,pr,vr,mr,gr,yr,wr,br,Sr,xr],Do=[qo,Or,Cr,_o,or,ar,Eo,sr,cr,jo,ur,lr,To,fr,hr,Mo,Fo,dr,pr,vr,mr,Lo,ko,gr,yr,wr,br,Ro,Sr,xr];function _(t){if(t["@id"])return t["@id"];if(t.id)return t.id}function Ee(t){if(!t||!t.profile||!_(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const r of e)if(typeof r=="string"&&Do.indexOf(r)!==-1)return!0;return!1}function Vo(t){if(!Ee(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const r of e)if(typeof r=="string"){if(Wo.indexOf(r)!==-1)return!0}else{const n=r.supports||[];if(n.indexOf("regionByPx")!==-1&&(n.indexOf("sizeByW")!==-1||n.indexOf("sizeByWh")!==-1))return!0}return!1}function Qo(t){if(!Vo(t))return[];const e=[],r=Array.isArray(t.profile)?t.profile:[t.profile],n=r.length;for(let o=0;o<n;o++){const i=r[o];if(typeof i!="string"&&(i.maxHeight||i.maxWidth))return[{id:_(t),type:"variable",minWidth:0,minHeight:0,maxHeight:i.maxHeight||i.maxWidth,maxWidth:i.maxWidth||i.maxHeight}]}if(t.tiles){const o=t.tiles.length;for(let i=0;i<o;i++){const a=t.tiles[i];(a.height||a.width)&&e.push({id:_(t),type:"variable",minHeight:0,minWidth:0,maxHeight:a.height||a.width,maxWidth:a.width})}}return e}function Ar(t){const e=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,r=t.match(e);if(r){const n=r[1],o=parseInt(r[4],10),i=parseInt(r[5],10),a=r[7];if((n==="max"||n==="full")&&o&&i&&a)return{type:"fixed",id:t,height:i,width:o}}return{type:"unknown",id:t}}function zo(t){if(t["@type"])return t["@type"];if(t.type)return t.type}function je(t){if(typeof t=="string")return Ar(t);const e=zo(t);if(e!=="Image"&&e!=="sc:Image")return null;const r=t,n=_(r);return n?n&&r.width&&r.height?{id:n,type:"fixed",width:r.width,height:r.height,unsafe:!0}:Ar(n):null}function Bo(t){return Ee(t)?(t&&t.sizes?t.sizes:[]).map(e=>({id:_(t),type:"fixed-service",height:e.height,width:e.width})):[]}function Pr(t){const e=[],r=t.length;for(let n=0;n<r;n++){const o=Bo(t[n]);o.length&&e.push(...o);const i=Qo(t[n]);i.length&&e.push(...i)}return e}function Ir(t){const e=t.service?Array.isArray(t.service)?t.service:[t.service]:[],r=e.length,n=[];for(let o=0;o<r;o++)Ee(e[o])&&n.push(e[o]);return n}function Ho(t,e=!0,r){const n=[],o=je(t);if(o===null)return n;const i=t;if(n.push(o),e&&i.width&&i.height){const a=[],s=Ir(i);for(const u of s){const l={id:_(u),width:i.width,height:i.height};if(r.canLoadSync(l)){const f=r.loadServiceSync(l);f&&(f.height||(f.height=i.height),f.width||(f.width=i.width),a.push(...Pr([f])))}}if(a.length)return n.push(...a),n}return i.service&&n.push(...Pr(i.service)),n}function Te(t,e,r){return{id:[J(_(t)).slice(0,-10),"full",[e,r||""].join(","),0,"default.jpg"].join("/"),type:"fixed",width:e,height:r||t.height/t.width*e,unsafe:t.width>e}}function Z(t){const e=t.replace(/(https?:\/\/)?(www.)?/i,"");return e.indexOf("/")!==-1?e.split("/")[0]:e}function Uo(t,e,r){const n=t.width?t.width:t.maxWidth;return r.height<=t.maxHeight&&r.width<=t.maxWidth&&r.height>=t.minHeight&&r.width>=t.minWidth&&(!e||Math.abs(r.width-n)<Math.abs(e.width-n))}function No(t,e){const r=[],n=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},t),o=[],i=[];let a=null;const s=(l,f)=>{if(Uo(n,f,l)){if(n.preferFixedSize&&l.unsafe){i.push(l);return}n.returnAllOptions&&f&&i.push(f),a=l}else n.returnAllOptions&&i.push(l)},u=e.length;for(let l=0;l<u;l++){const f=e[l](),p=f.length;for(let d=0;d<p;d++){const v=f[d];if(v.type==="unknown"&&n.atAnyCost&&o.push(v),v.type==="fixed"&&(v.unsafe?o.push(v):s(v,a)),v.type==="fixed-service")if(n.unsafeImageService){const c=Te(v,n.width,n.height);s(c,a)}else{const c=Te(v,v.width,v.height);s(c,a)}if(v.type==="variable"&&v.maxWidth){const c=Te({id:v.id,type:"fixed-service",width:v.maxWidth,height:v.maxWidth},v.maxWidth);s(c,a)}}if(a&&!n.returnAllOptions){if(a.unsafe||n.allowUnsafe)continue;break}}return n.atAnyCost&&i.length===0?{best:a||o[0],fallback:o.slice(1),log:r}:n.returnAllOptions?{best:n.atAnyCost?a||i[0]||o[0]:a||i[0],fallback:[...i,...o],log:r}:{best:a||i[0]||null,fallback:a?i:i.slice(1),log:r}}function Go(t,e,r){const n=t>e?t:e,o=r.length,i=[];for(let a=0;a<o;a++){const s=r[a];let u=s.scaleFactors[0],l=n/u;const f=[u];for(;l>=s.width;)u=u*2,f.push(u),l=l/2;i.push(Object.assign(Object.assign({},s),{scaleFactors:f}))}return i}function Ko(t,e){if(t.length!==e.length)return!1;if(t.length===0&&e.length===0)return!0;const r=t.length;let n=!0;for(let i=0;i<r;i++){const a=t[i],s=e[i];if(a.width!==s.width||a.height!==s.height){n=!1;break}}if(n)return!0;let o=0;for(let i=0;i<r;i++)for(let a=0;a<r;a++)if(t[i].width===e[a].width&&t[i].height===e[a].height){o++;break}return o===r}/*! *****************************************************************************
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@iiif/vault')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'react', '@iiif/vault'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactIIIFVault = {}, global.React, global.IIIFVault));
|
|
5
|
+
})(this, (function (exports, React, vault) { 'use strict';
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
10
|
+
|
|
11
|
+
var __defProp$5 = Object.defineProperty;
|
|
12
|
+
var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
|
|
13
|
+
var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
|
|
15
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
16
|
+
var __spreadValues$5 = (a, b) => {
|
|
17
|
+
for (var prop in b || (b = {}))
|
|
18
|
+
if (__hasOwnProp$5.call(b, prop))
|
|
19
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
20
|
+
if (__getOwnPropSymbols$5)
|
|
21
|
+
for (var prop of __getOwnPropSymbols$5(b)) {
|
|
22
|
+
if (__propIsEnum$5.call(b, prop))
|
|
23
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
24
|
+
}
|
|
25
|
+
return a;
|
|
26
|
+
};
|
|
27
|
+
const defaultResourceContext = {
|
|
28
|
+
collection: void 0,
|
|
29
|
+
manifest: void 0,
|
|
30
|
+
range: void 0,
|
|
31
|
+
canvas: void 0,
|
|
32
|
+
annotation: void 0
|
|
33
|
+
};
|
|
34
|
+
const ResourceReactContext = React__default["default"].createContext(defaultResourceContext);
|
|
35
|
+
const useResourceContext = () => {
|
|
36
|
+
return React.useContext(ResourceReactContext);
|
|
37
|
+
};
|
|
38
|
+
const ResourceProvider = ({ value, children }) => {
|
|
39
|
+
const parentContext = useResourceContext();
|
|
40
|
+
const newContext = React.useMemo(() => {
|
|
41
|
+
return __spreadValues$5(__spreadValues$5({}, parentContext), value);
|
|
42
|
+
}, [value, parentContext]);
|
|
43
|
+
return /* @__PURE__ */ React__default["default"].createElement(ResourceReactContext.Provider, {
|
|
44
|
+
value: newContext
|
|
45
|
+
}, children);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const AnnotationContext = ({ annotation, children }) => {
|
|
49
|
+
return /* @__PURE__ */ React__default["default"].createElement(ResourceProvider, {
|
|
50
|
+
value: { annotation }
|
|
51
|
+
}, children);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const CanvasContext = ({ canvas, children }) => {
|
|
55
|
+
return /* @__PURE__ */ React__default["default"].createElement(ResourceProvider, {
|
|
56
|
+
value: { canvas }
|
|
57
|
+
}, children);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const CollectionContext = ({ collection, children }) => {
|
|
61
|
+
return /* @__PURE__ */ React__default["default"].createElement(ResourceProvider, {
|
|
62
|
+
value: { collection }
|
|
63
|
+
}, children);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const ManifestContext = ({ manifest, children }) => {
|
|
67
|
+
return /* @__PURE__ */ React__default["default"].createElement(ResourceProvider, {
|
|
68
|
+
value: { manifest }
|
|
69
|
+
}, children);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const RangeContext = ({ range, children }) => {
|
|
73
|
+
return /* @__PURE__ */ React__default["default"].createElement(ResourceProvider, {
|
|
74
|
+
value: { range }
|
|
75
|
+
}, children);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const ReactVaultContext = React__default["default"].createContext({
|
|
79
|
+
vault: null,
|
|
80
|
+
setVaultInstance: (vault) => {
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
const VaultProvider = ({ vault: vault$1, vaultOptions, useGlobal, resources, children }) => {
|
|
84
|
+
const [vaultInstance, setVaultInstance] = React.useState(() => {
|
|
85
|
+
if (vault$1) {
|
|
86
|
+
return vault$1;
|
|
87
|
+
}
|
|
88
|
+
if (useGlobal) {
|
|
89
|
+
return vault.globalVault(vaultOptions);
|
|
90
|
+
}
|
|
91
|
+
if (vaultOptions) {
|
|
92
|
+
return new vault.Vault(vaultOptions);
|
|
93
|
+
}
|
|
94
|
+
return new vault.Vault();
|
|
95
|
+
});
|
|
96
|
+
return /* @__PURE__ */ React__default["default"].createElement(ReactVaultContext.Provider, {
|
|
97
|
+
value: { vault: vaultInstance, setVaultInstance }
|
|
98
|
+
}, /* @__PURE__ */ React__default["default"].createElement(ResourceProvider, {
|
|
99
|
+
value: resources || {}
|
|
100
|
+
}, children));
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const useVault = () => {
|
|
104
|
+
const { vault } = React.useContext(ReactVaultContext);
|
|
105
|
+
if (vault === null) {
|
|
106
|
+
throw new Error("Vault not found. Ensure you have your provider set up correctly.");
|
|
107
|
+
}
|
|
108
|
+
return vault;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
var __async$1 = (__this, __arguments, generator) => {
|
|
112
|
+
return new Promise((resolve, reject) => {
|
|
113
|
+
var fulfilled = (value) => {
|
|
114
|
+
try {
|
|
115
|
+
step(generator.next(value));
|
|
116
|
+
} catch (e) {
|
|
117
|
+
reject(e);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
var rejected = (value) => {
|
|
121
|
+
try {
|
|
122
|
+
step(generator.throw(value));
|
|
123
|
+
} catch (e) {
|
|
124
|
+
reject(e);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
128
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
function useExternalResource(idOrRef, { noCache = false } = {}) {
|
|
132
|
+
const id = typeof idOrRef === "string" ? idOrRef : idOrRef.id;
|
|
133
|
+
const vault = useVault();
|
|
134
|
+
const [realId, setRealId] = React.useState(id);
|
|
135
|
+
const [error, setError] = React.useState(void 0);
|
|
136
|
+
const initialData = React.useMemo(() => {
|
|
137
|
+
return vault.get(id, { skipSelfReturn: true }) || void 0;
|
|
138
|
+
}, [id, vault]);
|
|
139
|
+
const [resource, setResource] = React.useState(initialData);
|
|
140
|
+
React.useEffect(() => {
|
|
141
|
+
(() => __async$1(this, null, function* () {
|
|
142
|
+
try {
|
|
143
|
+
const fetchedResource = initialData && !noCache ? initialData : yield vault.load(id);
|
|
144
|
+
const _realId = fetchedResource ? fetchedResource.id || fetchedResource["@id"] : null;
|
|
145
|
+
if (fetchedResource && realId !== _realId) {
|
|
146
|
+
setRealId(_realId);
|
|
147
|
+
}
|
|
148
|
+
setResource(fetchedResource);
|
|
149
|
+
} catch (err) {
|
|
150
|
+
setError(err);
|
|
151
|
+
}
|
|
152
|
+
}))();
|
|
153
|
+
}, [id, noCache]);
|
|
154
|
+
return {
|
|
155
|
+
isLoaded: !!resource,
|
|
156
|
+
id: realId,
|
|
157
|
+
requestId: id,
|
|
158
|
+
error,
|
|
159
|
+
resource,
|
|
160
|
+
cached: !!(resource && resource === initialData)
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function useExternalManifest(idOrRef, options) {
|
|
165
|
+
const { id, isLoaded, error, resource, requestId, cached } = useExternalResource(idOrRef, options);
|
|
166
|
+
return { id, isLoaded, error, manifest: resource, requestId, cached };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function useVaultSelector(selector, deps = []) {
|
|
170
|
+
const vault = useVault();
|
|
171
|
+
const [selectedState, setSelectedState] = React.useState(() => selector(vault.getState(), vault));
|
|
172
|
+
React.useEffect(() => {
|
|
173
|
+
return vault.subscribe((s) => selector(s, vault), (state) => {
|
|
174
|
+
setSelectedState(state);
|
|
175
|
+
}, false);
|
|
176
|
+
}, deps);
|
|
177
|
+
return selectedState;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const VisibleCanvasReactContext = React__default["default"].createContext([]);
|
|
181
|
+
function useVisibleCanvases() {
|
|
182
|
+
const ids = React.useContext(VisibleCanvasReactContext);
|
|
183
|
+
return useVaultSelector((state) => {
|
|
184
|
+
return ids.map((id) => state.iiif.entities.Canvas[id]).filter(Boolean);
|
|
185
|
+
}, [ids]);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const noop = () => {
|
|
189
|
+
};
|
|
190
|
+
const SimpleViewerReactContext = React.createContext({
|
|
191
|
+
setCurrentCanvasId: noop,
|
|
192
|
+
setCurrentCanvasIndex: noop,
|
|
193
|
+
nextCanvas: noop,
|
|
194
|
+
previousCanvas: noop,
|
|
195
|
+
currentCanvasIndex: -1,
|
|
196
|
+
totalCanvases: 0,
|
|
197
|
+
pagingView: true
|
|
198
|
+
});
|
|
199
|
+
const SimpleViewerProvider = (props) => {
|
|
200
|
+
const manifest = useExternalManifest(props.manifest);
|
|
201
|
+
const [currentCanvasId, setCurrentCanvasId] = React.useState("");
|
|
202
|
+
const [visible, setVisible] = React.useState([]);
|
|
203
|
+
const pagingView = (typeof props.pagingEnabled === "undefined" || props.pagingEnabled) && manifest.manifest && manifest.manifest.behavior && manifest.manifest.behavior.includes("paged");
|
|
204
|
+
React.useEffect(() => {
|
|
205
|
+
var _a, _b;
|
|
206
|
+
if (manifest.manifest) {
|
|
207
|
+
setCurrentCanvasId((_a = manifest.manifest.items[0]) == null ? void 0 : _a.id);
|
|
208
|
+
setVisible([(_b = manifest.manifest.items[0]) == null ? void 0 : _b.id]);
|
|
209
|
+
}
|
|
210
|
+
}, [manifest.manifest, props.manifest]);
|
|
211
|
+
const canvasList = React.useMemo(() => {
|
|
212
|
+
var _a;
|
|
213
|
+
return ((_a = manifest.manifest) == null ? void 0 : _a.items.map((c) => c.id)) || [];
|
|
214
|
+
}, [manifest.manifest, props.manifest]);
|
|
215
|
+
const currentCanvasIndex = React.useMemo(() => canvasList.indexOf(currentCanvasId), [canvasList, currentCanvasId]);
|
|
216
|
+
const nextCanvas = React.useCallback(() => {
|
|
217
|
+
if (canvasList.length && currentCanvasId) {
|
|
218
|
+
if (currentCanvasIndex === -1) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (canvasList[currentCanvasIndex + 2] ? currentCanvasIndex + 2 === canvasList.length : currentCanvasIndex === canvasList.length) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const newCanvas = pagingView && currentCanvasIndex !== 0 ? canvasList[currentCanvasIndex + 2] : canvasList[currentCanvasIndex + 1];
|
|
225
|
+
const pageCanvas = pagingView ? currentCanvasIndex !== 0 ? canvasList[currentCanvasIndex + 3] : canvasList[currentCanvasIndex + 2] : null;
|
|
226
|
+
if (newCanvas) {
|
|
227
|
+
setCurrentCanvasId(newCanvas);
|
|
228
|
+
setVisible(pageCanvas ? [newCanvas, pageCanvas] : [newCanvas]);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}, [pagingView, canvasList, currentCanvasId, currentCanvasIndex]);
|
|
232
|
+
const previousCanvas = React.useCallback(() => {
|
|
233
|
+
if (canvasList.length && currentCanvasId) {
|
|
234
|
+
if (currentCanvasIndex === 0 || currentCanvasIndex === -1) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const newCanvas = pagingView && currentCanvasIndex !== 1 ? canvasList[currentCanvasIndex - 2] : canvasList[currentCanvasIndex - 1];
|
|
238
|
+
const pageCanvas = pagingView && currentCanvasIndex !== 1 ? canvasList[currentCanvasIndex - 1] : null;
|
|
239
|
+
if (newCanvas) {
|
|
240
|
+
setCurrentCanvasId(newCanvas);
|
|
241
|
+
setVisible(pageCanvas ? [newCanvas, pageCanvas] : [newCanvas]);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}, [pagingView, canvasList, currentCanvasId, currentCanvasIndex]);
|
|
245
|
+
const setCurrentCanvasIndex = React.useCallback((idx) => {
|
|
246
|
+
const realIdx = pagingView && idx % 2 === 1 ? idx - 1 : idx;
|
|
247
|
+
const newId = canvasList[realIdx];
|
|
248
|
+
const newNextId = pagingView && realIdx !== 0 ? canvasList[realIdx + 1] : null;
|
|
249
|
+
if (newId) {
|
|
250
|
+
setCurrentCanvasId(newId);
|
|
251
|
+
setVisible((prevValue) => {
|
|
252
|
+
const newValue = newNextId ? [newId, newNextId] : [newId];
|
|
253
|
+
if (prevValue.length === prevValue.length) {
|
|
254
|
+
for (let i = 0; i < prevValue.length; i++) {
|
|
255
|
+
if (prevValue[i] !== newValue[i]) {
|
|
256
|
+
return newValue;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return prevValue;
|
|
260
|
+
}
|
|
261
|
+
return newValue;
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}, [pagingView, canvasList]);
|
|
265
|
+
const internalSetCurrentCanvasId = React.useCallback((nextId) => {
|
|
266
|
+
const idx = canvasList.indexOf(nextId);
|
|
267
|
+
if (idx !== -1) {
|
|
268
|
+
setCurrentCanvasIndex(idx);
|
|
269
|
+
}
|
|
270
|
+
}, [canvasList, setCurrentCanvasIndex]);
|
|
271
|
+
const ctx = React.useMemo(() => ({
|
|
272
|
+
setCurrentCanvasId: internalSetCurrentCanvasId,
|
|
273
|
+
nextCanvas,
|
|
274
|
+
previousCanvas,
|
|
275
|
+
currentCanvasIndex,
|
|
276
|
+
totalCanvases: canvasList.length,
|
|
277
|
+
setCurrentCanvasIndex,
|
|
278
|
+
pagingView: true
|
|
279
|
+
}), [nextCanvas, previousCanvas, currentCanvasIndex, canvasList, setCurrentCanvasIndex, internalSetCurrentCanvasId]);
|
|
280
|
+
if (!manifest.manifest) {
|
|
281
|
+
console.warn("The manifest passed to the provider is not a valid IIIF manifest.");
|
|
282
|
+
return /* @__PURE__ */ React__default["default"].createElement("div", null, "Sorry, something went wrong.");
|
|
283
|
+
}
|
|
284
|
+
if (!manifest.isLoaded) {
|
|
285
|
+
return /* @__PURE__ */ React__default["default"].createElement("div", null, "Loading...");
|
|
286
|
+
}
|
|
287
|
+
return /* @__PURE__ */ React__default["default"].createElement(SimpleViewerReactContext.Provider, {
|
|
288
|
+
value: ctx
|
|
289
|
+
}, /* @__PURE__ */ React__default["default"].createElement(VisibleCanvasReactContext.Provider, {
|
|
290
|
+
value: visible
|
|
291
|
+
}, /* @__PURE__ */ React__default["default"].createElement(ManifestContext, {
|
|
292
|
+
manifest: manifest.manifest.id
|
|
293
|
+
}, /* @__PURE__ */ React__default["default"].createElement(CanvasContext, {
|
|
294
|
+
canvas: currentCanvasId
|
|
295
|
+
}, props.children))));
|
|
296
|
+
};
|
|
297
|
+
function useSimpleViewer() {
|
|
298
|
+
return React.useContext(SimpleViewerReactContext);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function useContextBridge() {
|
|
302
|
+
return {
|
|
303
|
+
VaultContext: React.useContext(ReactVaultContext),
|
|
304
|
+
ResourceContext: React.useContext(ResourceReactContext),
|
|
305
|
+
SimpleViewerReactContext: React.useContext(SimpleViewerReactContext),
|
|
306
|
+
VisibleCanvasReactContext: React.useContext(VisibleCanvasReactContext)
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
const ContextBridge = (props) => {
|
|
310
|
+
return /* @__PURE__ */ React__default["default"].createElement(VaultProvider, {
|
|
311
|
+
vault: props.bridge.VaultContext.vault || void 0,
|
|
312
|
+
resources: props.bridge.ResourceContext
|
|
313
|
+
}, /* @__PURE__ */ React__default["default"].createElement(VisibleCanvasReactContext.Provider, {
|
|
314
|
+
value: props.bridge.VisibleCanvasReactContext
|
|
315
|
+
}, /* @__PURE__ */ React__default["default"].createElement(SimpleViewerReactContext.Provider, {
|
|
316
|
+
value: props.bridge.SimpleViewerReactContext
|
|
317
|
+
}, props.children)));
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
function g(i){return i.endsWith("info.json")?i:i.endsWith("/")?`${i}info.json`:`${i}/info.json`}const Y$1="http://library.stanford.edu/iiif/image-api/compliance.html#level0",F$1="http://library.stanford.edu/iiif/image-api/compliance.html#level1",v$1="http://library.stanford.edu/iiif/image-api/compliance.html#level2",q$1="http://library.stanford.edu/iiif/image-api/conformance.html#level0",O$1="http://library.stanford.edu/iiif/image-api/conformance.html#level1",z$1="http://library.stanford.edu/iiif/image-api/conformance.html#level2",ee="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",E$1="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",A$1="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",ie="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",b$1="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",L$1="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",te="http://iiif.io/api/image/1/level0.json",re="http://iiif.io/api/image/1/profiles/level0.json",M$1="http://iiif.io/api/image/1/level1.json",W$1="http://iiif.io/api/image/1/profiles/level1.json",j$1="http://iiif.io/api/image/1/level2.json",P$1="http://iiif.io/api/image/1/profiles/level2.json",ne="http://iiif.io/api/image/2/level0.json",se="http://iiif.io/api/image/2/profiles/level0.json",C$1="http://iiif.io/api/image/2/level1.json",B="http://iiif.io/api/image/2/profiles/level1.json",N$1="http://iiif.io/api/image/2/level2.json",R$1="http://iiif.io/api/image/2/profiles/level2.json",ae="level0",$="level1",H$1="level2",oe="http://iiif.io/api/image/2/level0",G$1="http://iiif.io/api/image/2/level1",T$1="http://iiif.io/api/image/2/level2",k$1=[T$1,v$1,z$1,A$1,L$1,j$1,P$1,N$1,R$1,H$1],Q$1=[...k$1,G$1,F$1,O$1,E$1,b$1,M$1,W$1,C$1,B,$],V$1=[oe,G$1,T$1,Y$1,F$1,v$1,q$1,O$1,z$1,ee,E$1,A$1,ie,b$1,L$1,te,re,M$1,W$1,j$1,P$1,ne,se,C$1,B,N$1,R$1,ae,$,H$1],fe={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},le={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},he={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function ce(i){return k$1.indexOf(i)!==-1?he:Q$1.indexOf(i)!==-1?le:fe}function U$1(i){const e=i?Array.isArray(i.profile)?i.profile:[i.profile]:[],t={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let r of e)if(typeof r=="string"&&(r=ce(r)),!!r){if(r.formats)for(const s of r.formats)t.extraFormats.indexOf(s)===-1&&t.extraFormats.push(s);if(r.qualities)for(const s of r.qualities)t.extraQualities.indexOf(s)===-1&&t.extraQualities.push(s);if(r.supports)for(const s of r.supports)t.extraFeatures.indexOf(s)===-1&&t.extraFeatures.push(s);if(r.maxHeight&&(t.maxHeight=r.maxHeight),r.maxWidth&&(t.maxWidth=r.maxWidth),r.maxArea&&(t.maxArea=r.maxArea),r.extraFormats)for(const s of r.extraFormats)t.extraFormats.indexOf(s)===-1&&t.extraFormats.push(s);if(r.extraQualities)for(const s of r.extraQualities)t.extraQualities.indexOf(s)===-1&&t.extraQualities.push(s);if(r.extraFeatures)for(const s of r.extraFeatures)t.extraFeatures.indexOf(s)===-1&&t.extraFeatures.push(s);r.maxHeight&&(t.maxHeight=r.maxHeight),r.maxWidth&&(t.maxWidth=r.maxWidth),r.maxArea&&(t.maxArea=r.maxArea);}if(i.extraFormats)for(const r of i.extraFormats)t.extraFormats.indexOf(r)===-1&&t.extraFormats.push(r);if(i.extraFeatures)for(const r of i.extraFeatures)t.extraFeatures.indexOf(r)===-1&&t.extraFeatures.push(r);if(i.extraQualities)for(const r of i.extraQualities)t.extraQualities.indexOf(r)===-1&&t.extraQualities.push(r);return t}function ue(i){try{if(i==="full")return {full:!0};if(i==="square")return {square:!0};const e=i.startsWith("pct:"),r=i.substr(e?4:0).split(",").map(s=>parseFloat(s));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 "+i)}}function de(i){const e={upscaled:!1,max:!1,confined:!1};if(i[0]==="^"&&(e.upscaled=!0,i=i.slice(1)),i==="max"||i==="full")return e.max=!0,e.serialiseAsFull=i==="full",e;if(i[0]==="!"&&(e.confined=!0,i=i.slice(1)),i[0]==="p")return e.percentScale=parseFloat(i.slice(4)),e;const t=i.split(",").map(r=>r.trim());return t.length&&(t[0]!==""&&(e.width=parseInt(t[0],10)),t[1]!==""&&(e.height=parseInt(t[1],10))),e}function ge(i){const e={angle:0};if(i[0]==="!"&&(e.mirror=!0,i=i.substr(1)),e.angle=parseFloat(i)%360,Number.isNaN(e.angle))throw new Error(`Invalid rotation ${i}`);return e}function me(i,e=""){const t=i.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!t)throw new Error(`Invalid or unknown input ${i}`);const r=t[2],s=t[3];let n=t[4];if(n[0]==="/"&&(n=n.substr(1)),e.length>0){if(e[0]==="/"&&(e=e.substr(1)),e!==n.substr(0,e.length))throw new Error(`Path does not start with prefix (path: ${n}, prefix: ${e})`);n=n.substr(e.length);}return {scheme:r,server:s,path:n,prefix:e}}function pe(i,e=""){const{path:t,scheme:r,server:s,prefix:n}=me(i,e),a=t.split("/").reverse(),[o,l,f,c,...I]=a,d=I.reverse().filter(Boolean).join("/");if(a.length===1||o==="")return {type:"base",scheme:r,server:s,prefix:n,identifier:d};if(o==="info.json"){const[,...m]=a;return {type:"info",scheme:r,server:s,prefix:n,identifier:m.reverse().filter(Boolean).join("/")}}const u=o.split(".");return {type:"image",scheme:r,server:s,prefix:n,identifier:d,originalPath:t,region:ue(c),size:de(f),rotation:ge(l),quality:u[0],format:u[1]}}function xe(i){const e=pe(g(i.id));if(e.type!=="info")throw new Error("Invalid service URL");const t=U$1(i);return {identifier:e.identifier,originalPath:"",server:e.server,prefix:e.prefix,scheme:e.scheme,type:"image",quality:t.extraQualities.indexOf("default")===-1?t.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}}function Ie(i,e,t){const r=t.length,s=[];for(let n=0;n<r;n++){const o=t[n].width;s.push(i/o);}return s}function _e(i,e,t){const r=t.length,s=[];for(let n=0;n<r;n++){const a=t[n];s.push({width:Math.floor(i/a),height:Math.floor(e/a)});}return s}function h(i){if(i["@id"])return i["@id"];if(i.id)return i.id}function _(i){if(!i||!i.profile||!h(i))return !1;const e=Array.isArray(i.profile)?i.profile:[i.profile];for(const t of e)if(typeof t=="string"&&V$1.indexOf(t)!==-1)return !0;return !1}function ye(i){if(!_(i))return !1;const e=Array.isArray(i.profile)?i.profile:[i.profile];for(const t of e)if(typeof t=="string"){if(Q$1.indexOf(t)!==-1)return !0}else {const r=[...t.supports||[],...t.extraFeatures||[]];if(r.indexOf("regionByPx")!==-1&&(r.indexOf("sizeByW")!==-1||r.indexOf("sizeByWh")!==-1))return !0}return !1}function we(i){if(!ye(i))return [];const e=[],t=Array.isArray(i.profile)?i.profile:[i.profile],r=t.length;for(let s=0;s<r;s++){const n=t[s];if(typeof n!="string"&&(n.maxHeight||n.maxWidth))return [{id:h(i),type:"variable",minWidth:0,minHeight:0,maxHeight:n.maxHeight||n.maxWidth,maxWidth:n.maxWidth||n.maxHeight}]}if(i.tiles){const s=i.tiles.length;for(let n=0;n<s;n++){const a=i.tiles[n];(a.height||a.width)&&e.push({id:h(i),type:"variable",minHeight:0,minWidth:0,maxHeight:a.height||a.width,maxWidth:a.width});}}return e}function J$1(i){const e=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,t=i.match(e);if(t){const r=t[1],s=parseInt(t[4],10),n=parseInt(t[5],10),a=t[7];if((r==="max"||r==="full")&&s&&n&&a)return {type:"fixed",id:i,height:n,width:s}}return {type:"unknown",id:i}}function Se(i){if(i["@type"])return i["@type"];if(i.type)return i.type}function Fe(i){if(typeof i=="string")return J$1(i);const e=Se(i);if(e!=="Image"&&e!=="sc:Image")return null;const t=i,r=h(t);return r?r&&t.width&&t.height?{id:r,type:"fixed",width:t.width,height:t.height,unsafe:!0}:J$1(r):null}function ve(i){return _(i)?(i&&i.sizes?i.sizes:[]).map(e=>({id:h(i),type:"fixed-service",height:e.height,width:e.width})):[]}function Z$1(i){const e=[],t=i.length;for(let r=0;r<t;r++){const s=ve(i[r]);s.length&&e.push(...s);const n=we(i[r]);n.length&&e.push(...n);}return e}function K$1(i){const e=i.service?Array.isArray(i.service)?i.service:[i.service]:[],t=e.length,r=[];for(let s=0;s<t;s++)_(e[s])&&r.push(e[s]);return r}function Oe(i,e=!0,t){const r=[],s=Fe(i);if(s===null)return r;const n=i;if(r.push(s),e&&n.width&&n.height){const a=[],o=K$1(n);for(const l of o){const f={id:h(l),width:n.width,height:n.height};if(t.canLoadSync(f)){const c=t.loadServiceSync(f);c&&(c.height||(c.height=n.height),c.width||(c.width=n.width),a.push(...Z$1([c])));}}if(a.length)return r.push(...a),r}return n.service&&r.push(...Z$1(n.service)),r}function ze({x:i=0,y:e=0,w:t,h:r,full:s,square:n,percent:a}){if(s)return "full";if(n)return "square";if(typeof t>"u"||typeof r>"u")throw new Error("RegionParameter: invalid region");const o=`${i},${e},${t},${r}`;return a?`pct:${o}`:o}function Ee({max:i,percentScale:e,upscaled:t,confined:r,width:s,height:n,serialiseAsFull:a}){const o=[];return t&&o.push("^"),i?(o.push(a?"full":"max"),o.join("")):(r&&o.push("!"),e&&o.push(`pct:${e}`),s&&o.push(`${s}`),o.push(","),n&&o.push(`${n}`),o.join(""))}function Ae(i){return `${i.mirror?"!":""}${(i.angle||0)%360}`}var He=Object.defineProperty,Ge=Object.defineProperties,Te=Object.getOwnPropertyDescriptors,be=Object.getOwnPropertySymbols,ke=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable,Le=(i,e,t)=>e in i?He(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,y$1=(i,e)=>{for(var t in e||(e={}))ke.call(e,t)&&Le(i,t,e[t]);if(be)for(var t of be(e))Qe.call(e,t)&&Le(i,t,e[t]);return i},w$1=(i,e)=>Ge(i,Te(e));function Me(i,e){const t=i.prefix.startsWith("/")?i.prefix.substr(1):i.prefix,r=`${i.scheme}://${i.server}/${t?`${t}/`:""}${i.identifier}`;if(i.type==="base")return r;if(i.type==="info")return `${r}/info.json`;let{region:s,size:n,rotation:a,format:o,quality:l}=i;if(e){const f=e["@context"]?Array.isArray(e["@context"])?e["@context"]:[e["@context"]]:[],c=f.indexOf("http://iiif.io/api/image/2/context.json")!==-1,I=f.indexOf("http://iiif.io/api/image/3/context.json")!==-1;if((n.width===e.width&&!n.height||n.height===e.height&&!n.width||n.width===e.width&&n.height===e.height)&&(n=w$1(y$1({},n),{max:!0})),c&&(n.max&&!n.serialiseAsFull&&(n=w$1(y$1({},n),{serialiseAsFull:!0})),!n.max&&n.width&&n.height&&(n=w$1(y$1({},n),{height:void 0}))),I&&(n.max&&n.serialiseAsFull&&(n=w$1(y$1({},n),{serialiseAsFull:!1})),n.width&&!n.height&&e.width&&e.height)){const d=e.height/e.width;n=w$1(y$1({},n),{height:Math.ceil(n.width*d)});}}return [r,ze(s),Ee(n),Ae(a),`${l}.${o}`].filter(Boolean).join("/")}function S$1(i,e,t){const r=xe({id:g(h(i)),profile:"level2",type:"ImageService2"});if(r.type!=="image")throw new Error("Invalid service");return r.size.max=!1,r.size.width=e,r.size.height=t,{id:Me(r),type:"fixed",width:e,height:t||i.height/(i.width||1)*e,unsafe:i.width>e}}function p$1(i){const e=i.replace(/(https?:\/\/)?(www.)?/i,"");return e.indexOf("/")!==-1?e.split("/")[0]:e}function We(i,e,t){const r=i.width?i.width:i.maxWidth;return t.height<=i.maxHeight&&t.width<=i.maxWidth&&t.height>=i.minHeight&&t.width>=i.minWidth&&(!e||Math.abs(t.width-r)<Math.abs(e.width-r))}function je(i,e){const t=[],r=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},i),s=[],n=[];let a=null;const o=(f,c)=>{if(We(r,c,f)){if(r.preferFixedSize&&f.unsafe){n.push(f);return}r.returnAllOptions&&c&&n.push(c),a=f;}else r.returnAllOptions&&n.push(f);},l=e.length;for(let f=0;f<l;f++){const c=e[f](),I=c.length;for(let d=0;d<I;d++){const u=c[d];if(u.type==="unknown"&&r.atAnyCost&&s.push(u),u.type==="fixed"&&(u.unsafe?s.push(u):o(u,a)),u.type==="fixed-service")if(r.unsafeImageService){const m=S$1(u,r.width,r.height);o(m,a);}else {const m=S$1(u,u.width,u.height);o(m,a);}if(u.type==="variable"&&u.maxWidth){const m=S$1({id:u.id,type:"fixed-service",width:u.maxWidth,height:u.maxWidth},u.maxWidth);o(m,a);}}if(a&&!r.returnAllOptions){if(a.unsafe||r.allowUnsafe)continue;break}}return r.atAnyCost&&n.length===0?{best:a||s[0],fallback:s.slice(1),log:t}:r.returnAllOptions?{best:r.atAnyCost?a||n[0]||s[0]:a||n[0],fallback:[...n,...s],log:t}:{best:a||n[0]||null,fallback:a?n:n.slice(1),log:t}}var Je=Object.defineProperty,Ze=Object.defineProperties,Ke=Object.getOwnPropertyDescriptors,Pe=Object.getOwnPropertySymbols,Xe=Object.prototype.hasOwnProperty,Ye=Object.prototype.propertyIsEnumerable,Ce=(i,e,t)=>e in i?Je(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,qe=(i,e)=>{for(var t in e||(e={}))Xe.call(e,t)&&Ce(i,t,e[t]);if(Pe)for(var t of Pe(e))Ye.call(e,t)&&Ce(i,t,e[t]);return i},ei=(i,e)=>Ze(i,Ke(e));function Be(i,e,t){const r=i>e?i:e,s=t.length,n=[];for(let a=0;a<s;a++){const o=t[a];let l=o.scaleFactors[0],f=r/l;const c=[l];for(;f>=o.width;)l=l*2,c.push(l),f=f/2;n.push(ei(qe({},o),{scaleFactors:c}));}return n}function Ne(i,e){if(i.length!==e.length)return !1;if(i.length===0&&e.length===0)return !0;const t=i.length;let r=!0;for(let n=0;n<t;n++){const a=i[n],o=e[n];if(a.width!==o.width||a.height!==o.height){r=!1;break}}if(r)return !0;let s=0;for(let n=0;n<t;n++)for(let a=0;a<t;a++)if(i[n].width===e[a].width&&i[n].height===e[a].height){s++;break}return s===t}var x$1=(i,e,t)=>new Promise((r,s)=>{var n=l=>{try{o(t.next(l));}catch(f){s(f);}},a=l=>{try{o(t.throw(l));}catch(f){s(f);}},o=l=>l.done?r(l.value):Promise.resolve(l.value).then(n,a);o((t=t.apply(i,e)).next());});class Re{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,t,r=!0){const s=p$1(h(e)),n=g(h(e)),a=this.knownImageServers[s];return this.imageServices[n]=Object.assign(e,{real:!0}),a?this.verify(e):(this.knownImageServers[s]={verifications:0,malformed:!1,root:s,preLoaded:r,sampledId:h(e),verified:!1,server:null,result:{context:e["@context"]||[],sampledProfile:e.profile,resourceServiceRatio:t&&e.height?t.height/e.height:1,sampledSizes:e.sizes||[],sizeRatios:Ie(e.width,e.height,e.sizes||[]),sampledTiles:e.tiles||[]}},!0)}preLoad(e,t=!0){this.knownImageServers[e.root]=e,t&&(this.knownImageServers[e.root].malformed=!1,this.knownImageServers[e.root].verifications=this.config.verificationsRequired);}predict(e,t=!1,r=!1){const s=p$1(h(e)),n=this.knownImageServers[s];if(!n||!n.result||!r&&(n.malformed||n.verifications<this.config.verificationsRequired))return null;const a=g(h(e));return this.imageServices[a]||(this.imageServices[a]={"@context":n.result.context,"@id":h(e),id:h(e),protocol:"http://iiif.io/api/image",tiles:Be(e.width,e.height,n.result.sampledTiles),sizes:_e(Math.floor(e.width/n.result.resourceServiceRatio),Math.floor(e.height/n.result.resourceServiceRatio),n.result.sizeRatios),profile:n.result.sampledProfile,height:e.height,width:e.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(e,t){return x$1(this,arguments,function*(r,s,n=!0,a=[]){const o=yield this.getImageCandidates(r,n);return je(s,[()=>a,()=>o])})}getImageCandidates(e,t=!0){return x$1(this,null,function*(){const r=e;if(t&&r.height&&r.width){const s=K$1(r);for(const n of s){const a={id:h(n),width:n.width?n.width:r.width,height:n.height?n.height:r.height};yield this.loadService(a);}}return Oe(e,t,this)})}verify(e){return x$1(this,null,function*(){const t=this.predict(e,!1,!0),r=yield this.fetchService(h(e));if(!t)return !1;const s=t.height===r.height&&t.width===r.width&&t["@context"]===r["@context"]&&Ne(t.sizes||[],r.sizes||[]);if(s){const n=p$1(h(e));this.knownImageServers[n].verifications+=1,this.knownImageServers[n].verifications>=this.config.verificationsRequired&&(this.knownImageServers[n].verified=!0);}return s})}canLoadSync(e){const t=typeof e=="string"?e:h(e),r=g(t);if(this.imageServices[r])return !0;const s=this.knownImageServers[p$1(t)];return s&&!s.malformed&&s.verifications>=this.config.verificationsRequired}markAsMalformed(e){return x$1(this,null,function*(){return this.knownImageServers[p$1(h(e))].malformed=!0,this.loadService(e,!0)})}fetchService(e,t=!1){return x$1(this,null,function*(){const r=g(e);if(this.imageServices[r]&&(!t||this.imageServices[r].real))return this.imageServices[r];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const s=yield this.fetch(r).then(n=>n.json());return !s.id&&s["@id"]&&(s.id=s["@id"]),s.id!==e&&(s.id=e,s["@id"]&&(s["@id"]=e)),this.imageServices[r]=Object.assign(s,{real:!0}),this.imageServices[r]})}fetch(e,t){return x$1(this,null,function*(){return fetch(e,t)})}loadService(e,t=!1){return x$1(this,null,function*(){if(!this.config.disableThrottling){let n=!0;for(;n;)if(this.fetchingCount>=this.config.verificationsRequired)yield new Promise(a=>setTimeout(a,500));else {n=!1;break}}const r=this.knownImageServers[p$1(h(e))];if(r&&!r.malformed&&!t){yield r.result;const n=this.loadServiceSync(e);if(n)return n}this.fetchingCount++;const s=yield this.fetchService(h(e),t);return this.fetchingCount--,s.real&&this.sample(s,e),s})}loadServiceSync(e){const t=g(h(e));return this.imageServices[t]?this.imageServices[t]:this.predict(e)}}new Re;
|
|
321
|
+
|
|
322
|
+
const ImageServiceLoaderContext = React__default["default"].createContext(new Re());
|
|
323
|
+
function useImageServiceLoader() {
|
|
324
|
+
return React.useContext(ImageServiceLoaderContext);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const BOX_SELECTOR = /&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/;
|
|
328
|
+
const TEMPORAL_SELECTOR = /&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;
|
|
329
|
+
function parseSelector(source) {
|
|
330
|
+
if (Array.isArray(source)) {
|
|
331
|
+
return source.reduce((data, nextSource) => {
|
|
332
|
+
const { selector, selectors } = parseSelector(nextSource);
|
|
333
|
+
if (selector) {
|
|
334
|
+
if (!data.selector) {
|
|
335
|
+
data.selector = selector;
|
|
336
|
+
}
|
|
337
|
+
data.selectors.push(...selectors);
|
|
338
|
+
}
|
|
339
|
+
return data;
|
|
340
|
+
}, {
|
|
341
|
+
selector: null,
|
|
342
|
+
selectors: []
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
if (!source) {
|
|
346
|
+
return {
|
|
347
|
+
selector: null,
|
|
348
|
+
selectors: []
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
if (typeof source === "string") {
|
|
352
|
+
const [id, fragment] = source.split("#");
|
|
353
|
+
if (!fragment) {
|
|
354
|
+
return {
|
|
355
|
+
selector: null,
|
|
356
|
+
selectors: []
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
return parseSelector({ type: "FragmentSelector", value: fragment });
|
|
360
|
+
}
|
|
361
|
+
if (source.type === "PointSelector" && (source.t || source.t === 0)) {
|
|
362
|
+
const selector = {
|
|
363
|
+
type: "TemporalSelector",
|
|
364
|
+
temporal: {
|
|
365
|
+
startTime: source.t
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
return {
|
|
369
|
+
selector,
|
|
370
|
+
selectors: [selector]
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
if (source.type === "FragmentSelector") {
|
|
374
|
+
const matchBoxSelector = BOX_SELECTOR.exec(source.value);
|
|
375
|
+
if (matchBoxSelector) {
|
|
376
|
+
const selector = {
|
|
377
|
+
type: "BoxSelector",
|
|
378
|
+
spatial: {
|
|
379
|
+
unit: matchBoxSelector[2] === "percent:" ? "percent" : "pixel",
|
|
380
|
+
x: parseFloat(matchBoxSelector[3]),
|
|
381
|
+
y: parseFloat(matchBoxSelector[4]),
|
|
382
|
+
width: parseFloat(matchBoxSelector[5]),
|
|
383
|
+
height: parseFloat(matchBoxSelector[6])
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
return {
|
|
387
|
+
selector,
|
|
388
|
+
selectors: [selector]
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
const matchTimeSelector = source.value.match(TEMPORAL_SELECTOR);
|
|
392
|
+
if (matchTimeSelector) {
|
|
393
|
+
const selector = {
|
|
394
|
+
type: "TemporalSelector",
|
|
395
|
+
temporal: {
|
|
396
|
+
startTime: matchTimeSelector[4] ? parseFloat(matchTimeSelector[4]) : 0,
|
|
397
|
+
endTime: matchTimeSelector[7] ? parseFloat(matchTimeSelector[7]) : void 0
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
return {
|
|
401
|
+
selector,
|
|
402
|
+
selectors: [selector]
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
return {
|
|
406
|
+
selector: null,
|
|
407
|
+
selectors: []
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
return {
|
|
411
|
+
selector: null,
|
|
412
|
+
selectors: []
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
var __defProp$4 = Object.defineProperty;
|
|
417
|
+
var __defProps$4 = Object.defineProperties;
|
|
418
|
+
var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
|
|
419
|
+
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
420
|
+
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
421
|
+
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
422
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
423
|
+
var __spreadValues$4 = (a, b) => {
|
|
424
|
+
for (var prop in b || (b = {}))
|
|
425
|
+
if (__hasOwnProp$4.call(b, prop))
|
|
426
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
427
|
+
if (__getOwnPropSymbols$4)
|
|
428
|
+
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
429
|
+
if (__propIsEnum$4.call(b, prop))
|
|
430
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
431
|
+
}
|
|
432
|
+
return a;
|
|
433
|
+
};
|
|
434
|
+
var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
|
|
435
|
+
function expandTarget(target, options = {}) {
|
|
436
|
+
if (Array.isArray(target)) {
|
|
437
|
+
return expandTarget(target[0]);
|
|
438
|
+
}
|
|
439
|
+
if (typeof target === "string") {
|
|
440
|
+
const [id, fragment] = target.split("#");
|
|
441
|
+
if (!fragment) {
|
|
442
|
+
return {
|
|
443
|
+
type: "SpecificResource",
|
|
444
|
+
source: { id, type: options.typeMap && options.typeMap[id] || "Unknown" },
|
|
445
|
+
selector: null,
|
|
446
|
+
selectors: []
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
return expandTarget({
|
|
450
|
+
type: "SpecificResource",
|
|
451
|
+
source: { id, type: "Unknown" },
|
|
452
|
+
selector: {
|
|
453
|
+
type: "FragmentSelector",
|
|
454
|
+
value: fragment
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
if (target.type === "Choice" || target.type === "List" || target.type === "Composite" || target.type === "Independents") {
|
|
459
|
+
return expandTarget(target.items[0]);
|
|
460
|
+
}
|
|
461
|
+
if (target.type === "SpecificResource") {
|
|
462
|
+
if (target.source.type === "Canvas" && target.source.partOf && typeof target.source.partOf === "string") {
|
|
463
|
+
target.source.partOf = [
|
|
464
|
+
{
|
|
465
|
+
id: target.source.partOf,
|
|
466
|
+
type: "Manifest"
|
|
467
|
+
}
|
|
468
|
+
];
|
|
469
|
+
}
|
|
470
|
+
const { selector, selectors } = target.selector ? parseSelector(target.selector) : { selector: null, selectors: [] };
|
|
471
|
+
return {
|
|
472
|
+
type: "SpecificResource",
|
|
473
|
+
source: target.source,
|
|
474
|
+
selector,
|
|
475
|
+
selectors
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
if (target.id) {
|
|
479
|
+
if (target.type === "Canvas" && target.partOf && typeof target.partOf === "string") {
|
|
480
|
+
target.partOf = [
|
|
481
|
+
{
|
|
482
|
+
id: target.partOf,
|
|
483
|
+
type: "Manifest"
|
|
484
|
+
}
|
|
485
|
+
];
|
|
486
|
+
}
|
|
487
|
+
const [id, fragment] = target.id.split("#");
|
|
488
|
+
if (!fragment) {
|
|
489
|
+
return {
|
|
490
|
+
type: "SpecificResource",
|
|
491
|
+
source: __spreadProps$4(__spreadValues$4({}, target), {
|
|
492
|
+
id
|
|
493
|
+
}),
|
|
494
|
+
selector: null,
|
|
495
|
+
selectors: []
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
return expandTarget({
|
|
499
|
+
type: "SpecificResource",
|
|
500
|
+
source: __spreadProps$4(__spreadValues$4({}, target), {
|
|
501
|
+
id
|
|
502
|
+
}),
|
|
503
|
+
selector: {
|
|
504
|
+
type: "FragmentSelector",
|
|
505
|
+
value: fragment
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
return {
|
|
510
|
+
type: "SpecificResource",
|
|
511
|
+
source: target,
|
|
512
|
+
selector: null,
|
|
513
|
+
selectors: []
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function parseSpecificResource(resource) {
|
|
518
|
+
if (resource.type === "SpecificResource") {
|
|
519
|
+
return [resource.source, { selector: resource.selector }];
|
|
520
|
+
}
|
|
521
|
+
return [resource, { selector: null }];
|
|
522
|
+
}
|
|
523
|
+
function getPaintables(vault, paintingAnnotations, enabledChoices) {
|
|
524
|
+
const types = [];
|
|
525
|
+
let choice = null;
|
|
526
|
+
const items = [];
|
|
527
|
+
for (const annotation of paintingAnnotations) {
|
|
528
|
+
const bodies = vault.get(annotation.body);
|
|
529
|
+
for (const unknownBody of bodies) {
|
|
530
|
+
const [body, { selector }] = parseSpecificResource(unknownBody);
|
|
531
|
+
const type = (body.type || "unknown").toLowerCase();
|
|
532
|
+
if (type === "choice") {
|
|
533
|
+
const nestedBodies = vault.get(body.items);
|
|
534
|
+
const selected = enabledChoices.length ? enabledChoices.map((cid) => nestedBodies.find((b) => b.id === cid)).filter(Boolean) : [nestedBodies[0]];
|
|
535
|
+
if (selected.length === 0) {
|
|
536
|
+
selected.push(nestedBodies[0]);
|
|
537
|
+
}
|
|
538
|
+
choice = {
|
|
539
|
+
type: "single-choice",
|
|
540
|
+
items: nestedBodies.map((b) => ({
|
|
541
|
+
id: b.id,
|
|
542
|
+
label: b.label,
|
|
543
|
+
selected: selected.indexOf(b) !== -1
|
|
544
|
+
})),
|
|
545
|
+
label: unknownBody.label
|
|
546
|
+
};
|
|
547
|
+
bodies.push(...selected);
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
if (types.indexOf(type) === -1) {
|
|
551
|
+
types.push(type);
|
|
552
|
+
}
|
|
553
|
+
items.push({
|
|
554
|
+
type,
|
|
555
|
+
resource: body,
|
|
556
|
+
target: annotation.target,
|
|
557
|
+
selector
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return {
|
|
562
|
+
types,
|
|
563
|
+
items,
|
|
564
|
+
choice
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
const emptyActions = {
|
|
568
|
+
makeChoice: () => {
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
const unknownResponse = { type: "unknown" };
|
|
572
|
+
const unsupportedStrategy = (reason) => {
|
|
573
|
+
return { type: "unknown", reason, annotations: { pages: [] } };
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
function getImageStrategy(canvas, paintables, loadImageService) {
|
|
577
|
+
const imageTypes = [];
|
|
578
|
+
for (const singleImage of paintables.items) {
|
|
579
|
+
const resource = singleImage.resource && singleImage.resource.type === "SpecificResource" ? singleImage.resource.source : singleImage.resource;
|
|
580
|
+
if (!resource.id) {
|
|
581
|
+
return unsupportedStrategy("No resource Identifier");
|
|
582
|
+
}
|
|
583
|
+
let imageService = void 0;
|
|
584
|
+
if (resource.service) {
|
|
585
|
+
const imageServices = K$1(resource);
|
|
586
|
+
if (imageServices[0]) {
|
|
587
|
+
imageService = loadImageService(imageServices[0], canvas);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
const { selector: imageTarget, source } = expandTarget(singleImage.target);
|
|
591
|
+
if (source.id !== canvas.id) {
|
|
592
|
+
continue;
|
|
593
|
+
}
|
|
594
|
+
const defaultTarget = {
|
|
595
|
+
type: "BoxSelector",
|
|
596
|
+
spatial: {
|
|
597
|
+
x: 0,
|
|
598
|
+
y: 0,
|
|
599
|
+
width: canvas.width,
|
|
600
|
+
height: canvas.height
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
const target = imageTarget ? imageTarget.type === "TemporalSelector" ? {
|
|
604
|
+
type: "TemporalBoxSelector",
|
|
605
|
+
temporal: imageTarget.temporal,
|
|
606
|
+
spatial: defaultTarget.spatial
|
|
607
|
+
} : imageTarget : null;
|
|
608
|
+
const defaultImageSelector = {
|
|
609
|
+
type: "BoxSelector",
|
|
610
|
+
spatial: {
|
|
611
|
+
x: 0,
|
|
612
|
+
y: 0,
|
|
613
|
+
width: canvas.width,
|
|
614
|
+
height: canvas.height
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
const imageSelector = singleImage.resource.type === "SpecificResource" ? expandTarget(singleImage.resource) : null;
|
|
618
|
+
const selector = imageSelector && imageSelector.selector && (imageSelector.selector.type === "BoxSelector" || imageSelector.selector.type === "TemporalBoxSelector") ? {
|
|
619
|
+
type: "BoxSelector",
|
|
620
|
+
spatial: {
|
|
621
|
+
x: imageSelector.selector.spatial.x,
|
|
622
|
+
y: imageSelector.selector.spatial.y,
|
|
623
|
+
width: imageSelector.selector.spatial.width,
|
|
624
|
+
height: imageSelector.selector.spatial.height
|
|
625
|
+
}
|
|
626
|
+
} : defaultImageSelector;
|
|
627
|
+
const imageType = {
|
|
628
|
+
id: resource.id,
|
|
629
|
+
type: "Image",
|
|
630
|
+
width: target ? resource.width : canvas.width,
|
|
631
|
+
height: target ? resource.height : canvas.height,
|
|
632
|
+
service: imageService,
|
|
633
|
+
sizes: imageService && imageService.sizes ? imageService.sizes : resource.width && resource.height ? [{ width: resource.width, height: resource.height }] : [],
|
|
634
|
+
target: target && target.type !== "PointSelector" ? target : defaultTarget,
|
|
635
|
+
selector
|
|
636
|
+
};
|
|
637
|
+
imageTypes.push(imageType);
|
|
638
|
+
}
|
|
639
|
+
return {
|
|
640
|
+
type: "images",
|
|
641
|
+
image: imageTypes[0],
|
|
642
|
+
images: imageTypes,
|
|
643
|
+
choice: paintables.choice
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
var __defProp$3 = Object.defineProperty;
|
|
648
|
+
var __defProps$3 = Object.defineProperties;
|
|
649
|
+
var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
|
|
650
|
+
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
651
|
+
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
652
|
+
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
653
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
654
|
+
var __spreadValues$3 = (a, b) => {
|
|
655
|
+
for (var prop in b || (b = {}))
|
|
656
|
+
if (__hasOwnProp$3.call(b, prop))
|
|
657
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
658
|
+
if (__getOwnPropSymbols$3)
|
|
659
|
+
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
660
|
+
if (__propIsEnum$3.call(b, prop))
|
|
661
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
662
|
+
}
|
|
663
|
+
return a;
|
|
664
|
+
};
|
|
665
|
+
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
|
|
666
|
+
function useAnnotation(options = {}, deps = []) {
|
|
667
|
+
const { id, selector } = options;
|
|
668
|
+
const ctx = useResourceContext();
|
|
669
|
+
const vault = useVault();
|
|
670
|
+
const annotationId = id ? id : ctx.annotation;
|
|
671
|
+
const annotation = useVaultSelector((s) => annotationId ? s.iiif.entities.Annotation[annotationId] : void 0, [annotationId]);
|
|
672
|
+
const body = useVaultSelector((s) => annotation && annotation.body ? annotation.body.map((singleBody) => singleBody ? s.iiif.entities[singleBody.type][singleBody.id] : null).filter(Boolean) : [], [annotation]);
|
|
673
|
+
return React.useMemo(() => {
|
|
674
|
+
if (!annotation) {
|
|
675
|
+
return void 0;
|
|
676
|
+
}
|
|
677
|
+
const newAnnotation = __spreadProps$3(__spreadValues$3({}, annotation), {
|
|
678
|
+
body,
|
|
679
|
+
target: expandTarget(annotation.target, { typeMap: vault.getState().iiif.mapping })
|
|
680
|
+
});
|
|
681
|
+
if (selector) {
|
|
682
|
+
return selector(newAnnotation);
|
|
683
|
+
}
|
|
684
|
+
return newAnnotation;
|
|
685
|
+
}, [annotation, selector, body, ...deps]);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
function useManifest(options = {}, deps = []) {
|
|
689
|
+
const { id, selector } = options;
|
|
690
|
+
const ctx = useResourceContext();
|
|
691
|
+
useVault();
|
|
692
|
+
const manifestId = id ? id : ctx.manifest;
|
|
693
|
+
const manifest = useVaultSelector((s) => manifestId ? s.iiif.entities.Manifest[manifestId] : void 0, [manifestId]);
|
|
694
|
+
return React.useMemo(() => {
|
|
695
|
+
if (!manifest) {
|
|
696
|
+
return void 0;
|
|
697
|
+
}
|
|
698
|
+
if (selector) {
|
|
699
|
+
return selector(manifest);
|
|
700
|
+
}
|
|
701
|
+
return manifest;
|
|
702
|
+
}, [manifest, selector, ...deps]);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
function useCanvas(options = {}, deps = []) {
|
|
706
|
+
const { id, selector } = options;
|
|
707
|
+
const ctx = useResourceContext();
|
|
708
|
+
const canvasId = id ? id : ctx.canvas;
|
|
709
|
+
const canvas = useVaultSelector((s) => canvasId ? s.iiif.entities.Canvas[canvasId] : void 0, [canvasId]);
|
|
710
|
+
return React.useMemo(() => {
|
|
711
|
+
if (!canvas) {
|
|
712
|
+
return void 0;
|
|
713
|
+
}
|
|
714
|
+
if (selector) {
|
|
715
|
+
return selector(canvas);
|
|
716
|
+
}
|
|
717
|
+
return canvas;
|
|
718
|
+
}, [canvas, selector, ...deps]);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
function getMeta$1(state, resourceId) {
|
|
722
|
+
var _a;
|
|
723
|
+
const resourceMeta = (_a = state == null ? void 0 : state.iiif) == null ? void 0 : _a.meta[resourceId];
|
|
724
|
+
if (!resourceMeta) {
|
|
725
|
+
return null;
|
|
726
|
+
}
|
|
727
|
+
return resourceMeta.annotationPageManager;
|
|
728
|
+
}
|
|
729
|
+
function useEnabledAnnotationPageIds(resourceId, availablePageIds) {
|
|
730
|
+
return useVaultSelector((state) => {
|
|
731
|
+
const pageIds = [];
|
|
732
|
+
if (!resourceId) {
|
|
733
|
+
return pageIds;
|
|
734
|
+
}
|
|
735
|
+
const allAnnotationListIds = Object.keys(state.iiif.entities.AnnotationPage);
|
|
736
|
+
for (const annotationListId of allAnnotationListIds) {
|
|
737
|
+
if (!availablePageIds || availablePageIds.indexOf(annotationListId) !== -1) {
|
|
738
|
+
const annotationListMeta = getMeta$1(state, annotationListId);
|
|
739
|
+
if (annotationListMeta && annotationListMeta.views && annotationListMeta.views[resourceId]) {
|
|
740
|
+
pageIds.push(annotationListId);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
return pageIds;
|
|
745
|
+
}, [resourceId, availablePageIds]);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
function flattenAnnotationPageIds({
|
|
749
|
+
canvas,
|
|
750
|
+
manifest,
|
|
751
|
+
all,
|
|
752
|
+
canvases
|
|
753
|
+
}) {
|
|
754
|
+
const foundIds = [];
|
|
755
|
+
if (manifest) {
|
|
756
|
+
for (const page of manifest.annotations) {
|
|
757
|
+
if (foundIds.indexOf(page.id) === -1) {
|
|
758
|
+
foundIds.push(page.id);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
if (all) {
|
|
763
|
+
if (canvases && canvases.length) {
|
|
764
|
+
for (const canvas_ of canvases) {
|
|
765
|
+
for (const page of canvas_.annotations) {
|
|
766
|
+
if (foundIds.indexOf(page.id) === -1) {
|
|
767
|
+
foundIds.push(page.id);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
} else if (canvas) {
|
|
773
|
+
for (const page of canvas.annotations) {
|
|
774
|
+
if (foundIds.indexOf(page.id) === -1) {
|
|
775
|
+
foundIds.push(page.id);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
return foundIds;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
var __defProp$2 = Object.defineProperty;
|
|
783
|
+
var __defProps$2 = Object.defineProperties;
|
|
784
|
+
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
785
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
786
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
787
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
788
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
789
|
+
var __spreadValues$2 = (a, b) => {
|
|
790
|
+
for (var prop in b || (b = {}))
|
|
791
|
+
if (__hasOwnProp$2.call(b, prop))
|
|
792
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
793
|
+
if (__getOwnPropSymbols$2)
|
|
794
|
+
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
795
|
+
if (__propIsEnum$2.call(b, prop))
|
|
796
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
797
|
+
}
|
|
798
|
+
return a;
|
|
799
|
+
};
|
|
800
|
+
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
801
|
+
function getMeta(state, resourceId) {
|
|
802
|
+
var _a;
|
|
803
|
+
const resourceMeta = (_a = state == null ? void 0 : state.iiif) == null ? void 0 : _a.meta[resourceId];
|
|
804
|
+
if (!resourceMeta) {
|
|
805
|
+
return null;
|
|
806
|
+
}
|
|
807
|
+
return resourceMeta.annotationPageManager;
|
|
808
|
+
}
|
|
809
|
+
function useAnnotationPageManager(resourceId, options = {}) {
|
|
810
|
+
const vault = useVault();
|
|
811
|
+
const manifest = useManifest();
|
|
812
|
+
const canvas = useCanvas();
|
|
813
|
+
const canvases = useVisibleCanvases();
|
|
814
|
+
const availablePageIds = React.useMemo(() => {
|
|
815
|
+
return flattenAnnotationPageIds({
|
|
816
|
+
all: options.all,
|
|
817
|
+
manifest,
|
|
818
|
+
canvas,
|
|
819
|
+
canvases
|
|
820
|
+
});
|
|
821
|
+
}, [options.all, canvas, canvases, manifest]);
|
|
822
|
+
const enabledPageIds = useEnabledAnnotationPageIds(resourceId, options.all ? void 0 : availablePageIds);
|
|
823
|
+
const setPageDisabled = React.useCallback((deselectId) => {
|
|
824
|
+
if (!resourceId) {
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
vault.setMetaValue([deselectId, "annotationPageManager", "views"], (existingResources) => {
|
|
828
|
+
if (existingResources && !existingResources[resourceId]) {
|
|
829
|
+
return existingResources;
|
|
830
|
+
}
|
|
831
|
+
return __spreadProps$2(__spreadValues$2({}, existingResources || {}), {
|
|
832
|
+
[resourceId]: false
|
|
833
|
+
});
|
|
834
|
+
});
|
|
835
|
+
}, [resourceId, vault]);
|
|
836
|
+
const setPageEnabled = React.useCallback((id, opt = {}) => {
|
|
837
|
+
if (!resourceId) {
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
const state = vault.getState();
|
|
841
|
+
const toDeselect = [];
|
|
842
|
+
if (opt == null ? void 0 : opt.deselectOthers) {
|
|
843
|
+
const allAnnotationListIds = Object.keys(state.iiif.entities.AnnotationPage);
|
|
844
|
+
for (const annotationPageId of allAnnotationListIds) {
|
|
845
|
+
const annotationListMeta = getMeta(state, annotationPageId);
|
|
846
|
+
if (annotationListMeta && annotationListMeta.views && annotationListMeta.views[resourceId]) {
|
|
847
|
+
toDeselect.push(annotationPageId);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
for (const deselectId of toDeselect) {
|
|
852
|
+
setPageDisabled(deselectId);
|
|
853
|
+
}
|
|
854
|
+
vault.setMetaValue([id, "annotationPageManager", "views"], (existingResources) => {
|
|
855
|
+
if (existingResources && existingResources[resourceId]) {
|
|
856
|
+
return existingResources;
|
|
857
|
+
}
|
|
858
|
+
return __spreadProps$2(__spreadValues$2({}, existingResources || {}), {
|
|
859
|
+
[resourceId]: true
|
|
860
|
+
});
|
|
861
|
+
});
|
|
862
|
+
}, [resourceId, setPageDisabled, vault]);
|
|
863
|
+
return {
|
|
864
|
+
availablePageIds,
|
|
865
|
+
enabledPageIds,
|
|
866
|
+
setPageEnabled,
|
|
867
|
+
setPageDisabled
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
function usePaintingAnnotations(options = {}) {
|
|
872
|
+
const canvas = useCanvas(options.canvasId ? { id: options.canvasId } : void 0);
|
|
873
|
+
return useVaultSelector((state, vault) => {
|
|
874
|
+
if (!canvas) {
|
|
875
|
+
return [];
|
|
876
|
+
}
|
|
877
|
+
const annotationPages = vault.get(canvas.items);
|
|
878
|
+
const flatAnnotations = [];
|
|
879
|
+
for (const page of annotationPages) {
|
|
880
|
+
flatAnnotations.push(...vault.get(page.items));
|
|
881
|
+
}
|
|
882
|
+
return flatAnnotations;
|
|
883
|
+
}, [canvas]);
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
function useAnnotationsAtTime(time, options = {}) {
|
|
887
|
+
const allAnnotations = usePaintingAnnotations(options);
|
|
888
|
+
return allAnnotations;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
function useCanvasClock(canvasId, autoplay = false) {
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
function useCollection(options, deps = []) {
|
|
895
|
+
const { id, selector } = options;
|
|
896
|
+
const ctx = useResourceContext();
|
|
897
|
+
const collectionId = id ? id : ctx.collection;
|
|
898
|
+
const collection = useVaultSelector((s) => collectionId ? s.iiif.entities.Collection[collectionId] : void 0, [collectionId]);
|
|
899
|
+
return React.useMemo(() => {
|
|
900
|
+
if (!collection) {
|
|
901
|
+
return void 0;
|
|
902
|
+
}
|
|
903
|
+
if (selector) {
|
|
904
|
+
return selector(collection);
|
|
905
|
+
}
|
|
906
|
+
return collection;
|
|
907
|
+
}, [collection, selector, ...deps]);
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
function useDispatch() {
|
|
911
|
+
const vault = useVault();
|
|
912
|
+
const store = vault.getStore();
|
|
913
|
+
return React.useMemo(() => {
|
|
914
|
+
return (action) => store.dispatch(action);
|
|
915
|
+
}, [store]);
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
function K(i){return {addEventListener(t,o,n,r){if(!!t)return i.setMetaValue([t.id,"eventManager",o],e=>{const s=e||[];for(const l of s)if(l.callback===n)return s;return [...s,{callback:n,scope:r}]}),n},removeEventListener(t,o,n){!t||i.setMetaValue([t.id,"eventManager",o],r=>(r||[]).filter(e=>e.callback!==n));},getListenersAsProps(t,o){const n=typeof t=="string"?{id:t}:t;if(!n||!n.id)return {};const r=i.getResourceMeta(n.id,"eventManager"),e={};if(r&&n)for(const s of Object.keys(r))e[s]=l=>{const h=i.get(n);for(const{callback:f,scope:a}of r[s]||[])(!a||o&&a.indexOf(o)!==-1)&&f(l,h);};return e}}}function Q(i){return {applyStyles(t,o,n){const r=typeof t=="string"?t:t.id;return i.setMetaValue([r,"styles",o],n)},getAppliedStyles(t){const o=typeof t=="string"?t:t.id;return i.getResourceMeta(o,"styles")}}}function p(i){return i.endsWith("info.json")?i:i.endsWith("/")?`${i}info.json`:`${i}/info.json`}function X(i,t,o){const n=o.length,r=[];for(let e=0;e<n;e++){const l=o[e].width;r.push(i/l);}return r}function Y(i,t,o){const n=o.length,r=[];for(let e=0;e<n;e++){const s=o[e];r.push({width:Math.floor(i/s),height:Math.floor(t/s)});}return r}const Z="http://library.stanford.edu/iiif/image-api/compliance.html#level0",w="http://library.stanford.edu/iiif/image-api/compliance.html#level1",E="http://library.stanford.edu/iiif/image-api/compliance.html#level2",q="http://library.stanford.edu/iiif/image-api/conformance.html#level0",x="http://library.stanford.edu/iiif/image-api/conformance.html#level1",F="http://library.stanford.edu/iiif/image-api/conformance.html#level2",tt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",O="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",A="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",it="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",b="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",M="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",et="http://iiif.io/api/image/1/level0.json",nt="http://iiif.io/api/image/1/profiles/level0.json",L="http://iiif.io/api/image/1/level1.json",C="http://iiif.io/api/image/1/profiles/level1.json",R="http://iiif.io/api/image/1/level2.json",k="http://iiif.io/api/image/1/profiles/level2.json",ot="http://iiif.io/api/image/2/level0.json",rt="http://iiif.io/api/image/2/profiles/level0.json",N="http://iiif.io/api/image/2/level1.json",j="http://iiif.io/api/image/2/profiles/level1.json",G="http://iiif.io/api/image/2/level2.json",T="http://iiif.io/api/image/2/profiles/level2.json",st="level0",V="level1",z="level2",at="http://iiif.io/api/image/2/level0",P="http://iiif.io/api/image/2/level1",W="http://iiif.io/api/image/2/level2",ft=[P,W,w,E,x,F,O,A,b,M,L,C,R,k,N,j,G,T,V,z],lt=[at,P,W,Z,w,E,q,x,F,tt,O,A,it,b,M,et,nt,L,C,R,k,ot,rt,N,j,G,T,st,V,z];function c(i){if(i["@id"])return i["@id"];if(i.id)return i.id}function v(i){if(!i||!i.profile||!c(i))return !1;const t=Array.isArray(i.profile)?i.profile:[i.profile];for(const o of t)if(typeof o=="string"&<.indexOf(o)!==-1)return !0;return !1}function ht(i){if(!v(i))return !1;const t=Array.isArray(i.profile)?i.profile:[i.profile];for(const o of t)if(typeof o=="string"){if(ft.indexOf(o)!==-1)return !0}else {const n=o.supports||[];if(n.indexOf("regionByPx")!==-1&&(n.indexOf("sizeByW")!==-1||n.indexOf("sizeByWh")!==-1))return !0}return !1}function ct(i){if(!ht(i))return [];const t=[],o=Array.isArray(i.profile)?i.profile:[i.profile],n=o.length;for(let r=0;r<n;r++){const e=o[r];if(typeof e!="string"&&(e.maxHeight||e.maxWidth))return [{id:c(i),type:"variable",minWidth:0,minHeight:0,maxHeight:e.maxHeight||e.maxWidth,maxWidth:e.maxWidth||e.maxHeight}]}if(i.tiles){const r=i.tiles.length;for(let e=0;e<r;e++){const s=i.tiles[e];(s.height||s.width)&&t.push({id:c(i),type:"variable",minHeight:0,minWidth:0,maxHeight:s.height||s.width,maxWidth:s.width});}}return t}function D(i){const t=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,o=i.match(t);if(o){const n=o[1],r=parseInt(o[4],10),e=parseInt(o[5],10),s=o[7];if((n==="max"||n==="full")&&r&&e&&s)return {type:"fixed",id:i,height:e,width:r}}return {type:"unknown",id:i}}function dt(i){if(i["@type"])return i["@type"];if(i.type)return i.type}function S(i){if(typeof i=="string")return D(i);const t=dt(i);if(t!=="Image"&&t!=="sc:Image")return null;const o=i,n=c(o);return n?n&&o.width&&o.height?{id:n,type:"fixed",width:o.width,height:o.height,unsafe:!0}:D(n):null}function ut(i){return v(i)?(i&&i.sizes?i.sizes:[]).map(t=>({id:c(i),type:"fixed-service",height:t.height,width:t.width})):[]}function H(i){const t=[],o=i.length;for(let n=0;n<o;n++){const r=ut(i[n]);r.length&&t.push(...r);const e=ct(i[n]);e.length&&t.push(...e);}return t}function U(i){const t=i.service?Array.isArray(i.service)?i.service:[i.service]:[],o=t.length,n=[];for(let r=0;r<o;r++)v(t[r])&&n.push(t[r]);return n}function gt(i,t=!0,o){const n=[],r=S(i);if(r===null)return n;const e=i;if(n.push(r),t&&e.width&&e.height){const s=[],l=U(e);for(const h of l){const f={id:c(h),width:e.width,height:e.height};if(o.canLoadSync(f)){const a=o.loadServiceSync(f);a&&(a.height||(a.height=e.height),a.width||(a.width=e.width),s.push(...H([a])));}}if(s.length)return n.push(...s),n}return e.service&&n.push(...H(e.service)),n}function y(i,t,o){return {id:[p(c(i)).slice(0,-10),"full",[t,o||""].join(","),0,"default.jpg"].join("/"),type:"fixed",width:t,height:o||i.height/i.width*t,unsafe:i.width>t}}function m(i){const t=i.replace(/(https?:\/\/)?(www.)?/i,"");return t.indexOf("/")!==-1?t.split("/")[0]:t}function pt(i,t,o){const n=i.width?i.width:i.maxWidth;return o.height<=i.maxHeight&&o.width<=i.maxWidth&&o.height>=i.minHeight&&o.width>=i.minWidth&&(!t||Math.abs(o.width-n)<Math.abs(t.width-n))}function mt(i,t){const o=[],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},i),r=[],e=[];let s=null;const l=(f,a)=>{if(pt(n,a,f)){if(n.preferFixedSize&&f.unsafe){e.push(f);return}n.returnAllOptions&&a&&e.push(a),s=f;}else n.returnAllOptions&&e.push(f);},h=t.length;for(let f=0;f<h;f++){const a=t[f](),u=a.length;for(let g=0;g<u;g++){const d=a[g];if(d.type==="unknown"&&n.atAnyCost&&r.push(d),d.type==="fixed"&&(d.unsafe?r.push(d):l(d,s)),d.type==="fixed-service")if(n.unsafeImageService){const _=y(d,n.width,n.height);l(_,s);}else {const _=y(d,d.width,d.height);l(_,s);}if(d.type==="variable"&&d.maxWidth){const _=y({id:d.id,type:"fixed-service",width:d.maxWidth,height:d.maxWidth},d.maxWidth);l(_,s);}}if(s&&!n.returnAllOptions){if(s.unsafe||n.allowUnsafe)continue;break}}return n.atAnyCost&&e.length===0?{best:s||r[0],fallback:r.slice(1),log:o}:n.returnAllOptions?{best:n.atAnyCost?s||e[0]||r[0]:s||e[0],fallback:[...e,...r],log:o}:{best:s||e[0]||null,fallback:s?e:e.slice(1),log:o}}function It(i,t,o){const n=i>t?i:t,r=o.length,e=[];for(let s=0;s<r;s++){const l=o[s];let h=l.scaleFactors[0],f=n/h;const a=[h];for(;f>=l.width;)h=h*2,a.push(h),f=f/2;e.push(Object.assign(Object.assign({},l),{scaleFactors:a}));}return e}function _t(i,t){if(i.length!==t.length)return !1;if(i.length===0&&t.length===0)return !0;const o=i.length;let n=!0;for(let e=0;e<o;e++){const s=i[e],l=t[e];if(s.width!==l.width||s.height!==l.height){n=!1;break}}if(n)return !0;let r=0;for(let e=0;e<o;e++)for(let s=0;s<o;s++)if(i[e].width===t[s].width&&i[e].height===t[s].height){r++;break}return r===o}/*! *****************************************************************************
|
|
2
919
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
920
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
4
921
|
this file except in compliance with the License. You may obtain a copy of the
|
|
@@ -11,4 +928,626 @@
|
|
|
11
928
|
|
|
12
929
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
13
930
|
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})});
|
|
931
|
+
***************************************************************************** */function I(i,t,o,n){function r(e){return e instanceof o?e:new o(function(s){s(e);})}return new(o||(o=Promise))(function(e,s){function l(a){try{f(n.next(a));}catch(u){s(u);}}function h(a){try{f(n.throw(a));}catch(u){s(u);}}function f(a){a.done?e(a.value):r(a.value).then(l,h);}f((n=n.apply(i,t||[])).next());})}class J{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,o,n=!0){const r=m(c(t)),e=p(c(t)),s=this.knownImageServers[r];return this.imageServices[e]=Object.assign(t,{real:!0}),s?this.verify(t):(this.knownImageServers[r]={verifications:0,malformed:!1,root:r,preLoaded:n,sampledId:c(t),verified:!1,server:null,result:{context:t["@context"]||[],sampledProfile:t.profile,resourceServiceRatio:o&&t.height?o.height/t.height:1,sampledSizes:t.sizes||[],sizeRatios:X(t.width,t.height,t.sizes||[]),sampledTiles:t.tiles||[]}},!0)}preLoad(t,o=!0){this.knownImageServers[t.root]=t,o&&(this.knownImageServers[t.root].malformed=!1,this.knownImageServers[t.root].verifications=this.config.verificationsRequired);}predict(t,o=!1,n=!1){const r=m(c(t)),e=this.knownImageServers[r];if(!e||!e.result||!n&&(e.malformed||e.verifications<this.config.verificationsRequired))return null;const s=p(c(t));return this.imageServices[s]||(this.imageServices[s]={"@context":e.result.context,"@id":c(t),id:c(t),protocol:"http://iiif.io/api/image",tiles:It(t.width,t.height,e.result.sampledTiles),sizes:Y(Math.floor(t.width/e.result.resourceServiceRatio),Math.floor(t.height/e.result.resourceServiceRatio),e.result.sizeRatios),profile:e.result.sampledProfile,height:t.height,width:t.width,real:!1}),this.imageServices[s]}getThumbnailFromResource(t,o,n=!0,r=[]){return I(this,void 0,void 0,function*(){const e=yield this.getImageCandidates(t,n);return mt(o,[()=>r,()=>e])})}getImageCandidates(t,o=!0){return I(this,void 0,void 0,function*(){const n=t;if(o&&n.height&&n.width){const r=U(n);for(const e of r){const s={id:c(e),width:e.width?e.width:n.width,height:e.height?e.height:n.height};yield this.loadService(s);}}return gt(t,o,this)})}verify(t){return I(this,void 0,void 0,function*(){const o=this.predict(t,!1,!0),n=yield this.fetchService(c(t));if(!o)return !1;const r=o.height===n.height&&o.width===n.width&&o["@context"]===n["@context"]&&_t(o.sizes||[],n.sizes||[]);if(r){const e=m(c(t));this.knownImageServers[e].verifications+=1,this.knownImageServers[e].verifications>=this.config.verificationsRequired&&(this.knownImageServers[e].verified=!0);}return r})}canLoadSync(t){const o=typeof t=="string"?t:c(t),n=p(o);if(this.imageServices[n])return !0;const r=this.knownImageServers[m(o)];return r&&!r.malformed&&r.verifications>=this.config.verificationsRequired}markAsMalformed(t){return I(this,void 0,void 0,function*(){return this.knownImageServers[m(c(t))].malformed=!0,this.loadService(t,!0)})}fetchService(t,o=!1){return I(this,void 0,void 0,function*(){const n=p(t);if(this.imageServices[n]&&(!o||this.imageServices[n].real))return this.imageServices[n];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const r=yield fetch(n).then(e=>e.json());return !r.id&&r["@id"]&&(r.id=r["@id"]),r.id!==t&&(r.id=t,r["@id"]&&(r["@id"]=t)),this.imageServices[n]=Object.assign(r,{real:!0}),this.imageServices[n]})}loadService(t,o=!1){return I(this,void 0,void 0,function*(){if(!this.config.disableThrottling)for(;this.fetchingCount>=this.config.verificationsRequired;)yield new Promise(e=>setTimeout(e,500));const n=this.knownImageServers[m(c(t))];if(n&&!n.malformed&&!o){yield n.result;const e=this.loadServiceSync(t);if(e)return e}this.fetchingCount++;const r=yield this.fetchService(c(t),o);return this.fetchingCount--,r.real&&this.sample(r,t),r})}loadServiceSync(t){const o=p(c(t));return this.imageServices[o]?this.imageServices[o]:this.predict(t)}}new J;function vt(i,t={}){const o=t.imageServiceLoader||new J;async function n(r,e,s,l=[],h){if(typeof r=="string")return {best:S(r),fallback:[],log:[]};const f=i.get(r);if(typeof f=="string")return {best:S(f),fallback:[],log:[]};switch(f.type){case"Annotation":{const a=f.body,u=i.get(a[0]);return h&&!u.width&&(u.width=h.width,u.height=h.height),await o.getThumbnailFromResource(u,e,s,l)}case"Canvas":{const a=f;if(a.thumbnail&&a.thumbnail.length){const u=i.get(a.thumbnail[0]),g=await o.getImageCandidates(u,s);g&&g.length&&l.push(...g);}return n(a.items[0],e,s,l,{width:a.width,height:a.height})}case"AnnotationPage":return n(f.items[0],e,s,l,h);case"Choice":return n(f.items[0],e,s,l,h);case"Collection":{const u=f.items[0];return n(u,e,s,l,h)}case"Manifest":{const u=f.items[0];return n(u,e,s,l,h)}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return h&&!f.width&&(f.width=h.width,f.height=h.height),o.getThumbnailFromResource(f,e,s,l);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}}
|
|
932
|
+
|
|
933
|
+
function useEventListener(resource, name, listener, scope, deps = []) {
|
|
934
|
+
const vault = useVault();
|
|
935
|
+
const helper = React.useMemo(() => K(vault), [vault]);
|
|
936
|
+
React.useEffect(() => {
|
|
937
|
+
const currentResource = resource;
|
|
938
|
+
if (!currentResource) {
|
|
939
|
+
return () => {
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
helper.addEventListener(currentResource, name, listener, scope);
|
|
943
|
+
return () => {
|
|
944
|
+
helper.removeEventListener(currentResource, name, listener);
|
|
945
|
+
};
|
|
946
|
+
}, [helper, resource, name, ...deps]);
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
function useExistingVault() {
|
|
950
|
+
const oldContext = React.useContext(ReactVaultContext);
|
|
951
|
+
return oldContext && oldContext.vault ? oldContext.vault : vault.globalVault();
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
function useExternalCollection(idOrRef, options) {
|
|
955
|
+
const { id, isLoaded, error, resource, requestId, cached } = useExternalResource(idOrRef, options);
|
|
956
|
+
return { id, isLoaded, error, manifest: resource, requestId, cached };
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
var __async = (__this, __arguments, generator) => {
|
|
960
|
+
return new Promise((resolve, reject) => {
|
|
961
|
+
var fulfilled = (value) => {
|
|
962
|
+
try {
|
|
963
|
+
step(generator.next(value));
|
|
964
|
+
} catch (e) {
|
|
965
|
+
reject(e);
|
|
966
|
+
}
|
|
967
|
+
};
|
|
968
|
+
var rejected = (value) => {
|
|
969
|
+
try {
|
|
970
|
+
step(generator.throw(value));
|
|
971
|
+
} catch (e) {
|
|
972
|
+
reject(e);
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
976
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
977
|
+
});
|
|
978
|
+
};
|
|
979
|
+
function useImageService({ cacheKey } = {}) {
|
|
980
|
+
const canvas = useCanvas();
|
|
981
|
+
const annotations = usePaintingAnnotations();
|
|
982
|
+
const vault = useVault();
|
|
983
|
+
const imageService = useImageServiceLoader();
|
|
984
|
+
const [_data, setData] = React.useState(void 0);
|
|
985
|
+
const [isFetching, setIsFetching] = React.useState(false);
|
|
986
|
+
const [status, setStatus] = React.useState("idle");
|
|
987
|
+
const [error, setError] = React.useState(void 0);
|
|
988
|
+
const key = canvas ? canvas.id : "undefined";
|
|
989
|
+
const initialData = React.useMemo(() => {
|
|
990
|
+
try {
|
|
991
|
+
if (canvas && annotations.length) {
|
|
992
|
+
const annotation = annotations[0];
|
|
993
|
+
const resource = vault.get(annotation.body[0]);
|
|
994
|
+
const imageServices = K$1(resource);
|
|
995
|
+
const firstImageService = imageServices[0];
|
|
996
|
+
if (!firstImageService) {
|
|
997
|
+
return void 0;
|
|
998
|
+
}
|
|
999
|
+
return imageService.loadServiceSync({
|
|
1000
|
+
id: firstImageService.id || firstImageService["@id"],
|
|
1001
|
+
width: firstImageService.width || canvas.width,
|
|
1002
|
+
height: firstImageService.height || canvas.height
|
|
1003
|
+
}) || void 0;
|
|
1004
|
+
}
|
|
1005
|
+
} catch (e) {
|
|
1006
|
+
console.error(e);
|
|
1007
|
+
}
|
|
1008
|
+
return void 0;
|
|
1009
|
+
}, [key, cacheKey, canvas]);
|
|
1010
|
+
const data = status === "success" && _data ? _data : initialData;
|
|
1011
|
+
React.useEffect(() => {
|
|
1012
|
+
(() => __async(this, null, function* () {
|
|
1013
|
+
try {
|
|
1014
|
+
if (canvas && annotations.length) {
|
|
1015
|
+
const annotation = annotations[0];
|
|
1016
|
+
const resource = vault.get(annotation.body[0]);
|
|
1017
|
+
const imageServices = K$1(resource);
|
|
1018
|
+
const firstImageService = imageServices[0];
|
|
1019
|
+
if (!firstImageService) {
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
setIsFetching(true);
|
|
1023
|
+
setStatus("loading");
|
|
1024
|
+
try {
|
|
1025
|
+
const loadedService = (yield imageService.loadService({
|
|
1026
|
+
id: firstImageService.id || firstImageService["@id"],
|
|
1027
|
+
width: firstImageService.width || canvas.width,
|
|
1028
|
+
height: firstImageService.height || canvas.height
|
|
1029
|
+
})) || void 0;
|
|
1030
|
+
setData(loadedService);
|
|
1031
|
+
setStatus("success");
|
|
1032
|
+
setIsFetching(false);
|
|
1033
|
+
} catch (err) {
|
|
1034
|
+
setStatus("error");
|
|
1035
|
+
setError(err);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
} catch (err) {
|
|
1039
|
+
setStatus("error");
|
|
1040
|
+
setError(err);
|
|
1041
|
+
}
|
|
1042
|
+
}))();
|
|
1043
|
+
}, [key, cacheKey]);
|
|
1044
|
+
return React.useMemo(() => {
|
|
1045
|
+
return {
|
|
1046
|
+
data,
|
|
1047
|
+
isFetching,
|
|
1048
|
+
status,
|
|
1049
|
+
error
|
|
1050
|
+
};
|
|
1051
|
+
}, [data, isFetching, status, error]);
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
function useImageTile() {
|
|
1055
|
+
const imageService = useImageService();
|
|
1056
|
+
return {
|
|
1057
|
+
isLoading: imageService.isFetching,
|
|
1058
|
+
tile: imageService.data ? {
|
|
1059
|
+
id: imageService.data.id || imageService.data["@id"],
|
|
1060
|
+
width: imageService.data.width,
|
|
1061
|
+
height: imageService.data.height,
|
|
1062
|
+
imageService: imageService.data,
|
|
1063
|
+
thumbnail: void 0
|
|
1064
|
+
} : null
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
function usePaintables(options, deps = []) {
|
|
1069
|
+
const vault = useVault();
|
|
1070
|
+
const paintingAnnotations = usePaintingAnnotations();
|
|
1071
|
+
const [enabledChoices, setEnabledChoices] = React.useState((options == null ? void 0 : options.defaultChoices) || []);
|
|
1072
|
+
const paintables = React.useMemo(() => getPaintables(vault, paintingAnnotations, enabledChoices), [vault, paintingAnnotations, enabledChoices, ...deps]);
|
|
1073
|
+
const makeChoice = React.useCallback((id, { deselectOthers = true, deselect = false } = {}) => {
|
|
1074
|
+
if (paintables.choice) {
|
|
1075
|
+
if (paintables.choice.type !== "single-choice") {
|
|
1076
|
+
throw new Error("Complex choice not supported yet");
|
|
1077
|
+
}
|
|
1078
|
+
setEnabledChoices((prevChoices) => {
|
|
1079
|
+
if (deselect) {
|
|
1080
|
+
const without = prevChoices.filter((e) => e !== id);
|
|
1081
|
+
if (without.length === 0) {
|
|
1082
|
+
const defaultId = paintables.items[0].resource.id;
|
|
1083
|
+
if (defaultId) {
|
|
1084
|
+
return [defaultId];
|
|
1085
|
+
} else {
|
|
1086
|
+
return [];
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
return without;
|
|
1090
|
+
}
|
|
1091
|
+
if (deselectOthers) {
|
|
1092
|
+
return [id];
|
|
1093
|
+
}
|
|
1094
|
+
const newChoices = [...prevChoices];
|
|
1095
|
+
if (newChoices.length === 0 && paintables.items.length) {
|
|
1096
|
+
const defaultId = paintables.items[0].resource.id;
|
|
1097
|
+
if (defaultId) {
|
|
1098
|
+
newChoices.push(defaultId);
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
if (prevChoices.indexOf(id) !== -1) {
|
|
1102
|
+
return prevChoices;
|
|
1103
|
+
}
|
|
1104
|
+
return [...prevChoices, id];
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
}, [paintables.choice]);
|
|
1108
|
+
const actions = { makeChoice };
|
|
1109
|
+
return [paintables, actions];
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
function useRange(options = {}, deps = []) {
|
|
1113
|
+
const { id, selector } = options;
|
|
1114
|
+
const ctx = useResourceContext();
|
|
1115
|
+
const rangeId = id ? id : ctx.range;
|
|
1116
|
+
const range = useVaultSelector((s) => rangeId ? s.iiif.entities.Range[rangeId] : void 0, [rangeId]);
|
|
1117
|
+
return React.useMemo(() => {
|
|
1118
|
+
if (!range) {
|
|
1119
|
+
return void 0;
|
|
1120
|
+
}
|
|
1121
|
+
if (selector) {
|
|
1122
|
+
return selector(range);
|
|
1123
|
+
}
|
|
1124
|
+
return range;
|
|
1125
|
+
}, [range, selector, ...deps]);
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
function useResourceEvents(resource, scope) {
|
|
1129
|
+
const vault = useVault();
|
|
1130
|
+
const helper = React.useMemo(() => K(vault), [vault]);
|
|
1131
|
+
const hooks = useVaultSelector(() => {
|
|
1132
|
+
if (resource && resource.id) {
|
|
1133
|
+
return vault.getResourceMeta(resource.id, "eventManager");
|
|
1134
|
+
}
|
|
1135
|
+
return null;
|
|
1136
|
+
}, [resource]);
|
|
1137
|
+
return React.useMemo(() => {
|
|
1138
|
+
return resource ? helper.getListenersAsProps(resource, scope) : {};
|
|
1139
|
+
}, [hooks, resource, vault, scope]);
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
function useResources(ids, type) {
|
|
1143
|
+
return useVaultSelector((state, vault) => vault.get(ids.map((id) => ({ id, type }))), [ids, type]);
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
function useSearchService() {
|
|
1147
|
+
const manifest = useManifest();
|
|
1148
|
+
return manifest ? manifest.service.find((service) => service.profile === "SearchService1" || service.profile === "http://iiif.io/api/search/1/search") : void 0;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
function useStyleHelper() {
|
|
1152
|
+
const vault = useVault();
|
|
1153
|
+
return React.useMemo(() => Q(vault), [vault]);
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
function useStyles(resource, scope) {
|
|
1157
|
+
const vault = useVault();
|
|
1158
|
+
const helper = React.useMemo(() => Q(vault), [vault]);
|
|
1159
|
+
return useVaultSelector(() => {
|
|
1160
|
+
if (!resource) {
|
|
1161
|
+
return null;
|
|
1162
|
+
}
|
|
1163
|
+
const styles = helper.getAppliedStyles(resource.id);
|
|
1164
|
+
return styles ? scope ? styles[scope] : styles : void 0;
|
|
1165
|
+
}, [resource, scope]);
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
const useVaultEffect = (callback, deps = []) => {
|
|
1169
|
+
const vault = useVault();
|
|
1170
|
+
React.useEffect(() => {
|
|
1171
|
+
callback(vault);
|
|
1172
|
+
}, [vault, ...deps]);
|
|
1173
|
+
};
|
|
1174
|
+
|
|
1175
|
+
function useThumbnail(request, dereference, { canvasId, manifestId } = {}) {
|
|
1176
|
+
const vault = useVault();
|
|
1177
|
+
const loader = useImageServiceLoader();
|
|
1178
|
+
const helper = React.useMemo(() => vt(vault, { imageServiceLoader: loader }), [vault, loader]);
|
|
1179
|
+
const [thumbnail, setThumbnail] = React.useState();
|
|
1180
|
+
const manifest = useManifest(manifestId ? { id: manifestId } : void 0);
|
|
1181
|
+
const canvas = useCanvas(canvasId ? { id: canvasId } : void 0);
|
|
1182
|
+
const subject = canvas ? canvas : manifest;
|
|
1183
|
+
const didUnmount = React.useRef(false);
|
|
1184
|
+
React.useEffect(() => {
|
|
1185
|
+
return () => {
|
|
1186
|
+
didUnmount.current = true;
|
|
1187
|
+
};
|
|
1188
|
+
}, []);
|
|
1189
|
+
if (!subject) {
|
|
1190
|
+
throw new Error("Must be called under a manifest or canvas context.");
|
|
1191
|
+
}
|
|
1192
|
+
useVaultEffect((v) => {
|
|
1193
|
+
helper.getBestThumbnailAtSize(subject, request, dereference).then((thumb) => {
|
|
1194
|
+
if (thumb.best && !didUnmount.current) {
|
|
1195
|
+
setThumbnail(thumb.best);
|
|
1196
|
+
}
|
|
1197
|
+
});
|
|
1198
|
+
}, [subject]);
|
|
1199
|
+
return thumbnail;
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
var __defProp$1 = Object.defineProperty;
|
|
1203
|
+
var __defProps$1 = Object.defineProperties;
|
|
1204
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
1205
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
1206
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
1207
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
1208
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1209
|
+
var __spreadValues$1 = (a, b) => {
|
|
1210
|
+
for (var prop in b || (b = {}))
|
|
1211
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
1212
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
1213
|
+
if (__getOwnPropSymbols$1)
|
|
1214
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
1215
|
+
if (__propIsEnum$1.call(b, prop))
|
|
1216
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
1217
|
+
}
|
|
1218
|
+
return a;
|
|
1219
|
+
};
|
|
1220
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
1221
|
+
function useLoadImageService() {
|
|
1222
|
+
const loader = useImageServiceLoader();
|
|
1223
|
+
const [imageServiceStatus, setImageServiceStatus] = React.useState({});
|
|
1224
|
+
const didUnmount = React.useRef(false);
|
|
1225
|
+
React.useEffect(() => {
|
|
1226
|
+
return () => {
|
|
1227
|
+
didUnmount.current = true;
|
|
1228
|
+
};
|
|
1229
|
+
}, []);
|
|
1230
|
+
const loadImageService = React.useCallback((imageService, { height, width }) => {
|
|
1231
|
+
if (imageService) {
|
|
1232
|
+
const imageServiceId = imageService.id || imageService["@id"];
|
|
1233
|
+
const syncLoaded = loader.loadServiceSync({
|
|
1234
|
+
id: imageServiceId,
|
|
1235
|
+
width: imageService.width || width,
|
|
1236
|
+
height: imageService.height || height
|
|
1237
|
+
});
|
|
1238
|
+
if (syncLoaded) {
|
|
1239
|
+
imageService = syncLoaded;
|
|
1240
|
+
} else if (!imageServiceStatus[imageServiceId]) {
|
|
1241
|
+
if (!didUnmount.current) {
|
|
1242
|
+
setImageServiceStatus((r) => {
|
|
1243
|
+
return __spreadProps$1(__spreadValues$1({}, r), {
|
|
1244
|
+
[imageServiceId]: "loading"
|
|
1245
|
+
});
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
loader.loadService({
|
|
1249
|
+
id: imageServiceId,
|
|
1250
|
+
width: imageService.width || width,
|
|
1251
|
+
height: imageService.height || height
|
|
1252
|
+
}).then(() => {
|
|
1253
|
+
if (!didUnmount.current) {
|
|
1254
|
+
setImageServiceStatus((r) => {
|
|
1255
|
+
return __spreadProps$1(__spreadValues$1({}, r), {
|
|
1256
|
+
[imageServiceId]: "done"
|
|
1257
|
+
});
|
|
1258
|
+
});
|
|
1259
|
+
}
|
|
1260
|
+
});
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
return imageService;
|
|
1264
|
+
}, [loader, imageServiceStatus]);
|
|
1265
|
+
return [loadImageService, imageServiceStatus];
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
1269
|
+
|
|
1270
|
+
var typesafeActions_umd_production = {exports: {}};
|
|
1271
|
+
|
|
1272
|
+
(function (module, exports) {
|
|
1273
|
+
!function(n,t){t(exports);}(commonjsGlobal,(function(n){function t(n){return null==n}function r(n){throw new Error("Argument "+n+" is empty.")}function e(n){return "function"==typeof n&&"getType"in n}function i(n){throw new Error("Argument "+n+' is invalid, it should be an action-creator instance from "typesafe-actions"')}function o(n,t){if(null==n)throw new Error("Argument contains array with empty element at index "+t);if(null==n.getType)throw new Error("Argument contains array with invalid element at index "+t+', it should be an action-creator instance from "typesafe-actions"')}function u(n){return "string"==typeof n||"symbol"==typeof n}function a(n){return !u(n)}function c(n){throw new Error("Argument "+n+" is invalid, it should be an action type of type: string | symbol")}function f(n,t){if(null==n)throw new Error("Argument contains array with empty element at index "+t);if("string"!=typeof n&&"symbol"!=typeof n)throw new Error("Argument contains array with invalid element at index "+t+", it should be of type: string | symbol")}function s(n,e,o,u){return t(n)&&r(1),a(n)&&i(1),{type:n,payload:e,meta:o,error:u}}function y(n,e){t(n)&&r(1),a(n)&&c(1);return Object.assign((function(){var t=null!=e?e.apply(void 0,arguments):void 0;return Object.assign({type:n},t)}),{getType:function(){return n},toString:function(){return n}})}function l(n,e,i){return t(n)&&r(1),a(n)&&c(1),function(){return y(n,(function(){var n=arguments.length<=0?void 0:arguments[0],t=arguments.length<=1?void 0:arguments[1];return null==e&&null==i||(n=null!=e?e.apply(void 0,arguments):void 0,t=null!=i?i.apply(void 0,arguments):void 0),Object.assign({},void 0!==n&&{payload:n},{},void 0!==t&&{meta:t})}))}}function p(n){return t(n)&&r(1),e(n)||i(1),n.getType()}function d(n,e){t(n)&&r(1),a(n)&&c(1);var i=null!=e?e(n):function(){return {type:n}};return Object.assign(i,{getType:function(){return n},toString:function(){return n}})}var g={createAction:function(n,t){var r=null==t?function(){return s(n)}:t(s.bind(null,n));return Object.assign(r,{getType:function(){return n},toString:function(){return n}})},createCustomAction:d,createStandardAction:function(n){return t(n)&&r(1),a(n)&&c(1),Object.assign((function(){return d(n,(function(n){return function(t,r){return {type:n,payload:t,meta:r}}}))}),{map:function(t){return d(n,(function(n){return function(r,e){return Object.assign(t(r,e),{type:n})}}))}})}};n.action=s,n.createAction=l,n.createAsyncAction=function(n,t,r,e){return function(){var i=[n,t,r,e].map((function(n,t){return Array.isArray(n)?l(n[0],n[1],n[2])():"string"==typeof n||"symbol"==typeof n?l(n)():void(t<3&&function(n){throw new Error("Argument "+n+' is invalid, it should be an action type of "string | symbol" or a tuple of "[string | symbol, Function, Function?]"')}(t))}));return {request:i[0],success:i[1],failure:i[2],cancel:i[3]}}},n.createCustomAction=y,n.createReducer=function n(t,r){void 0===r&&(r={});var i=Object.assign({},r),o=function(r,o){var a=Array.isArray(r)?r:[r],c={};return a.map((function(n,t){return e(n)?p(n):u(n)?n:function(n){throw new Error("Argument "+n+' is invalid, it should be an action-creator instance from "typesafe-actions" or action type of type: string | symbol')}(t+1)})).forEach((function(n){return c[n]=o})),n(t,Object.assign({},i,{},c))};return Object.assign((function(n,r){if(void 0===n&&(n=t),i.hasOwnProperty(r.type)){var e=i[r.type];if("function"!=typeof e)throw Error('Reducer under "'+r.type+'" key is not a valid reducer');return e(n,r)}return n}),{handlers:Object.assign({},i),handleAction:o,handleType:o})},n.deprecated=g,n.getType=p,n.isActionOf=function(n,e){t(n)&&r(1);var i=Array.isArray(n)?n:[n];i.forEach(o);var u=function(n){return i.some((function(t){return n.type===t.getType()}))};return void 0===e?u:u(e)},n.isOfType=function(n,e){t(n)&&r(1);var i=Array.isArray(n)?n:[n];i.forEach(f);var o=function(n){return i.includes(n.type)};return void 0===e?o:o(e)};}));
|
|
1274
|
+
|
|
1275
|
+
}(typesafeActions_umd_production, typesafeActions_umd_production.exports));
|
|
1276
|
+
|
|
1277
|
+
const IMPORT_ENTITIES = "@iiif/IMPORT_ENTITIES";
|
|
1278
|
+
const MODIFY_ENTITY_FIELD = "@iiif/MODIFY_ENTITY_FIELD";
|
|
1279
|
+
const REORDER_ENTITY_FIELD = "@iiif/REORDER_ENTITY_FIELD";
|
|
1280
|
+
const ADD_REFERENCE = "@iiif/ADD_REFERENCE";
|
|
1281
|
+
const REMOVE_REFERENCE = "@iiif/REMOVE_REFERENCE";
|
|
1282
|
+
const importEntities = typesafeActions_umd_production.exports.createAction(IMPORT_ENTITIES)();
|
|
1283
|
+
const modifyEntityField = typesafeActions_umd_production.exports.createAction(MODIFY_ENTITY_FIELD)();
|
|
1284
|
+
const reorderEntityField = typesafeActions_umd_production.exports.createAction(REORDER_ENTITY_FIELD)();
|
|
1285
|
+
const addReference = typesafeActions_umd_production.exports.createAction(ADD_REFERENCE)();
|
|
1286
|
+
const removeReference = typesafeActions_umd_production.exports.createAction(REMOVE_REFERENCE)();
|
|
1287
|
+
const entityActions = { importEntities, modifyEntityField, reorderEntityField, addReference, removeReference };
|
|
1288
|
+
|
|
1289
|
+
const ADD_MAPPING = "@iiif/ADD_MAPPING";
|
|
1290
|
+
const ADD_MAPPINGS = "@iiif/ADD_MAPPINGS";
|
|
1291
|
+
typesafeActions_umd_production.exports.createAction(ADD_MAPPING)();
|
|
1292
|
+
typesafeActions_umd_production.exports.createAction(ADD_MAPPINGS)();
|
|
1293
|
+
|
|
1294
|
+
const SET_META_VALUE = "@iiif/SET_META_VALUE";
|
|
1295
|
+
const SET_META_VALUE_DYNAMIC = "@iiif/SET_META_VALUE_DYNAMIC";
|
|
1296
|
+
const UNSET_META_VALUE = "@iiif/UNSET_META_VALUE";
|
|
1297
|
+
typesafeActions_umd_production.exports.createAction(SET_META_VALUE)();
|
|
1298
|
+
typesafeActions_umd_production.exports.createAction(SET_META_VALUE_DYNAMIC)();
|
|
1299
|
+
typesafeActions_umd_production.exports.createAction(UNSET_META_VALUE)();
|
|
1300
|
+
const REQUEST_RESOURCE = "@iiif/REQUEST_RESOURCE";
|
|
1301
|
+
const REQUEST_ERROR = "@iiif/REQUEST_ERROR";
|
|
1302
|
+
const REQUEST_MISMATCH = "@iiif/REQUEST_MISMATCH";
|
|
1303
|
+
const REQUEST_COMPLETE = "@iiif/REQUEST_COMPLETE";
|
|
1304
|
+
const REQUEST_OFFLINE_RESOURCE = "@iiif/REQUEST_OFFLINE_RESOURCE";
|
|
1305
|
+
typesafeActions_umd_production.exports.createAction(REQUEST_RESOURCE)();
|
|
1306
|
+
typesafeActions_umd_production.exports.createAction(REQUEST_ERROR)();
|
|
1307
|
+
typesafeActions_umd_production.exports.createAction(REQUEST_MISMATCH)();
|
|
1308
|
+
typesafeActions_umd_production.exports.createAction(REQUEST_COMPLETE)();
|
|
1309
|
+
typesafeActions_umd_production.exports.createAction(REQUEST_OFFLINE_RESOURCE)();
|
|
1310
|
+
|
|
1311
|
+
const BATCH_ACTIONS = "@iiif/BATCH";
|
|
1312
|
+
const BATCH_IMPORT = "@iiif/BATCH_IMPORT";
|
|
1313
|
+
typesafeActions_umd_production.exports.createAction(BATCH_ACTIONS)();
|
|
1314
|
+
typesafeActions_umd_production.exports.createAction(BATCH_IMPORT)();
|
|
1315
|
+
|
|
1316
|
+
function isVaultActivated(obj) {
|
|
1317
|
+
return typeof obj !== "string" && obj && obj.bindToVault;
|
|
1318
|
+
}
|
|
1319
|
+
function useVirtualAnnotationPage() {
|
|
1320
|
+
const vault = useVault();
|
|
1321
|
+
const sources = React.useRef([]);
|
|
1322
|
+
const dispatch = useDispatch();
|
|
1323
|
+
const virtualId = React.useMemo(() => {
|
|
1324
|
+
return `vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random() * 1e9).toString(16)}`;
|
|
1325
|
+
}, []);
|
|
1326
|
+
React.useLayoutEffect(() => {
|
|
1327
|
+
const page = {
|
|
1328
|
+
id: virtualId,
|
|
1329
|
+
type: "AnnotationPage",
|
|
1330
|
+
behavior: [],
|
|
1331
|
+
motivation: null,
|
|
1332
|
+
label: null,
|
|
1333
|
+
thumbnail: [],
|
|
1334
|
+
summary: null,
|
|
1335
|
+
requiredStatement: null,
|
|
1336
|
+
metadata: [],
|
|
1337
|
+
rights: null,
|
|
1338
|
+
provider: [],
|
|
1339
|
+
items: [],
|
|
1340
|
+
seeAlso: [],
|
|
1341
|
+
homepage: [],
|
|
1342
|
+
logo: [],
|
|
1343
|
+
rendering: [],
|
|
1344
|
+
service: []
|
|
1345
|
+
};
|
|
1346
|
+
dispatch(entityActions.importEntities({
|
|
1347
|
+
entities: {
|
|
1348
|
+
AnnotationPage: {
|
|
1349
|
+
[page.id]: page
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
}));
|
|
1353
|
+
}, [virtualId]);
|
|
1354
|
+
const fullPage = useVaultSelector((state) => virtualId ? state.iiif.entities.AnnotationPage[virtualId] : null, [virtualId]);
|
|
1355
|
+
const addAnnotation = React.useCallback((id, atIndex) => {
|
|
1356
|
+
if (virtualId) {
|
|
1357
|
+
if (isVaultActivated(id)) {
|
|
1358
|
+
const display = id;
|
|
1359
|
+
if (!display.__vault) {
|
|
1360
|
+
display.bindToVault(vault);
|
|
1361
|
+
}
|
|
1362
|
+
id = typeof display.source === "string" ? display.source : display.source.id;
|
|
1363
|
+
sources.current[id] = display;
|
|
1364
|
+
} else if (typeof id !== "string") {
|
|
1365
|
+
id = id.id;
|
|
1366
|
+
}
|
|
1367
|
+
const full = vault.get({ id: virtualId, type: "AnnotationPage" });
|
|
1368
|
+
const annotation = vault.get({ id, type: "Annotation" });
|
|
1369
|
+
if (full && annotation) {
|
|
1370
|
+
if (!full.items.find((r) => r.id === annotation.id)) {
|
|
1371
|
+
dispatch(entityActions.addReference({
|
|
1372
|
+
id: virtualId,
|
|
1373
|
+
type: "AnnotationPage",
|
|
1374
|
+
key: "items",
|
|
1375
|
+
reference: {
|
|
1376
|
+
id,
|
|
1377
|
+
type: "Annotation"
|
|
1378
|
+
},
|
|
1379
|
+
index: atIndex
|
|
1380
|
+
}));
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
}, [virtualId]);
|
|
1385
|
+
const removeAnnotation = React.useCallback((id) => {
|
|
1386
|
+
if (virtualId) {
|
|
1387
|
+
if (isVaultActivated(id)) {
|
|
1388
|
+
id = typeof id.source === "string" ? id.source : id.source.id;
|
|
1389
|
+
} else if (typeof id !== "string") {
|
|
1390
|
+
id = id.id;
|
|
1391
|
+
}
|
|
1392
|
+
if (sources.current[id]) {
|
|
1393
|
+
sources.current[id].beforeRemove();
|
|
1394
|
+
}
|
|
1395
|
+
const full = vault.get({ id: virtualId, type: "AnnotationPage" });
|
|
1396
|
+
if (full) {
|
|
1397
|
+
dispatch(entityActions.removeReference({
|
|
1398
|
+
id: virtualId,
|
|
1399
|
+
type: "AnnotationPage",
|
|
1400
|
+
key: "items",
|
|
1401
|
+
reference: {
|
|
1402
|
+
id,
|
|
1403
|
+
type: "Annotation"
|
|
1404
|
+
}
|
|
1405
|
+
}));
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
}, [virtualId]);
|
|
1409
|
+
return [
|
|
1410
|
+
fullPage,
|
|
1411
|
+
{
|
|
1412
|
+
addAnnotation,
|
|
1413
|
+
removeAnnotation
|
|
1414
|
+
}
|
|
1415
|
+
];
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
var __defProp = Object.defineProperty;
|
|
1419
|
+
var __defProps = Object.defineProperties;
|
|
1420
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
1421
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
1422
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1423
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
1424
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1425
|
+
var __spreadValues = (a, b) => {
|
|
1426
|
+
for (var prop in b || (b = {}))
|
|
1427
|
+
if (__hasOwnProp.call(b, prop))
|
|
1428
|
+
__defNormalProp(a, prop, b[prop]);
|
|
1429
|
+
if (__getOwnPropSymbols)
|
|
1430
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
1431
|
+
if (__propIsEnum.call(b, prop))
|
|
1432
|
+
__defNormalProp(a, prop, b[prop]);
|
|
1433
|
+
}
|
|
1434
|
+
return a;
|
|
1435
|
+
};
|
|
1436
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1437
|
+
function useRenderingStrategy(options) {
|
|
1438
|
+
const manifest = useManifest();
|
|
1439
|
+
const canvas = useCanvas();
|
|
1440
|
+
const vault = useVault();
|
|
1441
|
+
const [loadImageService, imageServiceStatus] = useLoadImageService();
|
|
1442
|
+
const { enabledPageIds } = useAnnotationPageManager((options == null ? void 0 : options.annotationPageManagerId) || (manifest == null ? void 0 : manifest.id) || (canvas == null ? void 0 : canvas.id), {
|
|
1443
|
+
all: false
|
|
1444
|
+
});
|
|
1445
|
+
const enabledPages = useResources(enabledPageIds, "AnnotationPage");
|
|
1446
|
+
const supports = (options == null ? void 0 : options.strategies) || ["images", "media", "complex-timeline"];
|
|
1447
|
+
const [paintables, actions] = usePaintables(options, [imageServiceStatus]);
|
|
1448
|
+
const strategy = React.useMemo(() => {
|
|
1449
|
+
if (!canvas || paintables.types.length === 0) {
|
|
1450
|
+
return unknownResponse;
|
|
1451
|
+
}
|
|
1452
|
+
if (paintables.types.length !== 1) {
|
|
1453
|
+
if (supports.indexOf("complex-timeline") === -1) {
|
|
1454
|
+
return unsupportedStrategy("Complex timeline not supported");
|
|
1455
|
+
}
|
|
1456
|
+
return unsupportedStrategy("ComplexTimelineStrategy not yet supported");
|
|
1457
|
+
}
|
|
1458
|
+
const mainType = paintables.types[0];
|
|
1459
|
+
if (mainType === "image") {
|
|
1460
|
+
if (supports.indexOf("images") === -1) {
|
|
1461
|
+
return unsupportedStrategy("Image not supported");
|
|
1462
|
+
}
|
|
1463
|
+
return getImageStrategy(canvas, paintables, loadImageService);
|
|
1464
|
+
}
|
|
1465
|
+
if (mainType === "audio") {
|
|
1466
|
+
if (supports.indexOf("media") === -1) {
|
|
1467
|
+
return unsupportedStrategy("Media not supported");
|
|
1468
|
+
}
|
|
1469
|
+
return unsupportedStrategy("Audio strategy not yet supported");
|
|
1470
|
+
}
|
|
1471
|
+
if (mainType === "video") {
|
|
1472
|
+
if (supports.indexOf("media") === -1) {
|
|
1473
|
+
return unsupportedStrategy("Media not supported");
|
|
1474
|
+
}
|
|
1475
|
+
return unsupportedStrategy("Video strategy not yet supported");
|
|
1476
|
+
}
|
|
1477
|
+
return unknownResponse;
|
|
1478
|
+
}, [canvas, paintables, vault, actions.makeChoice]);
|
|
1479
|
+
return React.useMemo(() => {
|
|
1480
|
+
if (strategy.type === "unknown") {
|
|
1481
|
+
return [strategy, emptyActions];
|
|
1482
|
+
}
|
|
1483
|
+
return [
|
|
1484
|
+
__spreadProps(__spreadValues({}, strategy), {
|
|
1485
|
+
annotations: { pages: enabledPages }
|
|
1486
|
+
}),
|
|
1487
|
+
actions
|
|
1488
|
+
];
|
|
1489
|
+
}, [strategy, enabledPages]);
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
exports.AnnotationContext = AnnotationContext;
|
|
1493
|
+
exports.CanvasContext = CanvasContext;
|
|
1494
|
+
exports.CollectionContext = CollectionContext;
|
|
1495
|
+
exports.ContextBridge = ContextBridge;
|
|
1496
|
+
exports.ImageServiceLoaderContext = ImageServiceLoaderContext;
|
|
1497
|
+
exports.ManifestContext = ManifestContext;
|
|
1498
|
+
exports.RangeContext = RangeContext;
|
|
1499
|
+
exports.ReactVaultContext = ReactVaultContext;
|
|
1500
|
+
exports.ResourceProvider = ResourceProvider;
|
|
1501
|
+
exports.ResourceReactContext = ResourceReactContext;
|
|
1502
|
+
exports.SimpleViewerProvider = SimpleViewerProvider;
|
|
1503
|
+
exports.SimpleViewerReactContext = SimpleViewerReactContext;
|
|
1504
|
+
exports.VaultProvider = VaultProvider;
|
|
1505
|
+
exports.VisibleCanvasReactContext = VisibleCanvasReactContext;
|
|
1506
|
+
exports.emptyActions = emptyActions;
|
|
1507
|
+
exports.expandTarget = expandTarget;
|
|
1508
|
+
exports.flattenAnnotationPageIds = flattenAnnotationPageIds;
|
|
1509
|
+
exports.getImageStrategy = getImageStrategy;
|
|
1510
|
+
exports.getPaintables = getPaintables;
|
|
1511
|
+
exports.parseSelector = parseSelector;
|
|
1512
|
+
exports.parseSpecificResource = parseSpecificResource;
|
|
1513
|
+
exports.unknownResponse = unknownResponse;
|
|
1514
|
+
exports.unsupportedStrategy = unsupportedStrategy;
|
|
1515
|
+
exports.useAnnotation = useAnnotation;
|
|
1516
|
+
exports.useAnnotationPageManager = useAnnotationPageManager;
|
|
1517
|
+
exports.useAnnotationsAtTime = useAnnotationsAtTime;
|
|
1518
|
+
exports.useCanvas = useCanvas;
|
|
1519
|
+
exports.useCanvasClock = useCanvasClock;
|
|
1520
|
+
exports.useCollection = useCollection;
|
|
1521
|
+
exports.useContextBridge = useContextBridge;
|
|
1522
|
+
exports.useDispatch = useDispatch;
|
|
1523
|
+
exports.useEventListener = useEventListener;
|
|
1524
|
+
exports.useExistingVault = useExistingVault;
|
|
1525
|
+
exports.useExternalCollection = useExternalCollection;
|
|
1526
|
+
exports.useExternalManifest = useExternalManifest;
|
|
1527
|
+
exports.useExternalResource = useExternalResource;
|
|
1528
|
+
exports.useImageService = useImageService;
|
|
1529
|
+
exports.useImageServiceLoader = useImageServiceLoader;
|
|
1530
|
+
exports.useImageTile = useImageTile;
|
|
1531
|
+
exports.useLoadImageService = useLoadImageService;
|
|
1532
|
+
exports.useManifest = useManifest;
|
|
1533
|
+
exports.usePaintables = usePaintables;
|
|
1534
|
+
exports.usePaintingAnnotations = usePaintingAnnotations;
|
|
1535
|
+
exports.useRange = useRange;
|
|
1536
|
+
exports.useRenderingStrategy = useRenderingStrategy;
|
|
1537
|
+
exports.useResourceContext = useResourceContext;
|
|
1538
|
+
exports.useResourceEvents = useResourceEvents;
|
|
1539
|
+
exports.useResources = useResources;
|
|
1540
|
+
exports.useSearchService = useSearchService;
|
|
1541
|
+
exports.useSimpleViewer = useSimpleViewer;
|
|
1542
|
+
exports.useStyleHelper = useStyleHelper;
|
|
1543
|
+
exports.useStyles = useStyles;
|
|
1544
|
+
exports.useThumbnail = useThumbnail;
|
|
1545
|
+
exports.useVault = useVault;
|
|
1546
|
+
exports.useVaultEffect = useVaultEffect;
|
|
1547
|
+
exports.useVaultSelector = useVaultSelector;
|
|
1548
|
+
exports.useVirtualAnnotationPage = useVirtualAnnotationPage;
|
|
1549
|
+
exports.useVisibleCanvases = useVisibleCanvases;
|
|
1550
|
+
|
|
1551
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1552
|
+
|
|
1553
|
+
}));
|