react-iiif-vault 0.9.5 → 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.umd.js +1541 -2
- package/package.json +3 -3
package/dist/esm/index.mjs
CHANGED
|
@@ -1 +1,1462 @@
|
|
|
1
|
-
import g,{useContext as O,useMemo as m,useState as w,useEffect as b,createContext as je,useCallback as C,useRef as Q,useLayoutEffect as Fe}from"react";import{globalVault as X,Vault as J}from"@iiif/vault";import{ImageServiceLoader as Ne,getImageServices as q}from"@atlas-viewer/iiif-image-api";import{createEventsHelper as W,createStylesHelper as Z,createThumbnailHelper as Be}from"@iiif/vault-helpers";import{createAction as y}from"typesafe-actions";var Ue=Object.defineProperty,K=Object.getOwnPropertySymbols,ke=Object.prototype.hasOwnProperty,He=Object.prototype.propertyIsEnumerable,ee=(e,t,n)=>t in e?Ue(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,te=(e,t)=>{for(var n in t||(t={}))ke.call(t,n)&&ee(e,n,t[n]);if(K)for(var n of K(t))He.call(t,n)&&ee(e,n,t[n]);return e};const Qe={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},N=g.createContext(Qe),T=()=>O(N),$=({value:e,children:t})=>{const n=T(),r=m(()=>te(te({},n),e),[e,n]);return g.createElement(N.Provider,{value:r},t)},qe=({annotation:e,children:t})=>g.createElement($,{value:{annotation:e}},t),ne=({canvas:e,children:t})=>g.createElement($,{value:{canvas:e}},t),ze=({collection:e,children:t})=>g.createElement($,{value:{collection:e}},t),re=({manifest:e,children:t})=>g.createElement($,{value:{manifest:e}},t),Ye=({range:e,children:t})=>g.createElement($,{value:{range:e}},t),L=g.createContext({vault:null,setVaultInstance:e=>{}}),oe=({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:a})=>{const[i,s]=w(()=>e||(n?X(t):t?new J(t):new J));return g.createElement(L.Provider,{value:{vault:i,setVaultInstance:s}},g.createElement($,{value:r||{}},a))},_=()=>{const{vault:e}=O(L);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var Ge=(e,t,n)=>new Promise((r,a)=>{var i=c=>{try{o(n.next(c))}catch(l){a(l)}},s=c=>{try{o(n.throw(c))}catch(l){a(l)}},o=c=>c.done?r(c.value):Promise.resolve(c.value).then(i,s);o((n=n.apply(e,t)).next())});function z(e,{noCache:t=!1}={}){const n=typeof e=="string"?e:e.id,r=_(),[a,i]=w(n),[s,o]=w(void 0),c=m(()=>r.get(n,{skipSelfReturn:!0})||void 0,[n,r]),[l,d]=w(c);return b(()=>{Ge(this,null,function*(){try{const u=c&&!t?c:yield r.load(n),p=u?u.id||u["@id"]:null;u&&a!==p&&i(p),d(u)}catch(u){o(u)}})},[n,t]),{isLoaded:!!l,id:a,requestId:n,error:s,resource:l,cached:!!(l&&l===c)}}function ie(e,t){const{id:n,isLoaded:r,error:a,resource:i,requestId:s,cached:o}=z(e,t);return{id:n,isLoaded:r,error:a,manifest:i,requestId:s,cached:o}}function E(e,t=[]){const n=_(),[r,a]=w(()=>e(n.getState(),n));return b(()=>n.subscribe(i=>e(i,n),i=>{a(i)},!1),t),r}const D=g.createContext([]);function se(){const e=O(D);return E(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}const B=()=>{},j=je({setCurrentCanvasId:B,setCurrentCanvasIndex:B,nextCanvas:B,previousCanvas:B,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),Xe=e=>{const t=ie(e.manifest),[n,r]=w(""),[a,i]=w([]),s=(typeof e.pagingEnabled>"u"||e.pagingEnabled)&&t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");b(()=>{var f,v;t.manifest&&(r((f=t.manifest.items[0])==null?void 0:f.id),i([(v=t.manifest.items[0])==null?void 0:v.id]))},[t.manifest,e.manifest]);const o=m(()=>{var f;return((f=t.manifest)==null?void 0:f.items.map(v=>v.id))||[]},[t.manifest,e.manifest]),c=m(()=>o.indexOf(n),[o,n]),l=C(()=>{if(o.length&&n){if(c===-1||(o[c+2]?c+2===o.length:c===o.length))return;const f=s&&c!==0?o[c+2]:o[c+1],v=s?c!==0?o[c+3]:o[c+2]:null;f&&(r(f),i(v?[f,v]:[f]))}},[s,o,n,c]),d=C(()=>{if(o.length&&n){if(c===0||c===-1)return;const f=s&&c!==1?o[c-2]:o[c-1],v=s&&c!==1?o[c-1]:null;f&&(r(f),i(v?[f,v]:[f]))}},[s,o,n,c]),u=C(f=>{const v=s&&f%2===1?f-1:f,P=o[v],M=s&&v!==0?o[v+1]:null;P&&(r(P),i(A=>{const S=M?[P,M]:[P];if(A.length===A.length){for(let I=0;I<A.length;I++)if(A[I]!==S[I])return S;return A}return S}))},[s,o]),p=C(f=>{const v=o.indexOf(f);v!==-1&&u(v)},[o,u]),h=m(()=>({setCurrentCanvasId:p,nextCanvas:l,previousCanvas:d,currentCanvasIndex:c,totalCanvases:o.length,setCurrentCanvasIndex:u,pagingView:!0}),[l,d,c,o,u,p]);return t.manifest?t.isLoaded?g.createElement(j.Provider,{value:h},g.createElement(D.Provider,{value:a},g.createElement(re,{manifest:t.manifest.id},g.createElement(ne,{canvas:n},e.children)))):g.createElement("div",null,"Loading..."):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),g.createElement("div",null,"Sorry, something went wrong."))};function Je(){return O(j)}function We(){return{VaultContext:O(L),ResourceContext:O(N),SimpleViewerReactContext:O(j),VisibleCanvasReactContext:O(D)}}const Ze=e=>g.createElement(oe,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},g.createElement(D.Provider,{value:e.bridge.VisibleCanvasReactContext},g.createElement(j.Provider,{value:e.bridge.SimpleViewerReactContext},e.children))),ae=g.createContext(new Ne);function U(){return O(ae)}const Ke=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,et=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function k(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:r,selectors:a}=k(n);return r&&(t.selector||(t.selector=r),t.selectors.push(...a)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,n]=e.split("#");return n?k({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=Ke.exec(e.value);if(t){const r={type:"BoxSelector",spatial:{unit:t[2]==="percent:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:r,selectors:[r]}}const n=e.value.match(et);if(n){const r={type:"TemporalSelector",temporal:{startTime:n[4]?parseFloat(n[4]):0,endTime:n[7]?parseFloat(n[7]):void 0}};return{selector:r,selectors:[r]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}var tt=Object.defineProperty,nt=Object.defineProperties,rt=Object.getOwnPropertyDescriptors,ce=Object.getOwnPropertySymbols,ot=Object.prototype.hasOwnProperty,it=Object.prototype.propertyIsEnumerable,le=(e,t,n)=>t in e?tt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ue=(e,t)=>{for(var n in t||(t={}))ot.call(t,n)&&le(e,n,t[n]);if(ce)for(var n of ce(t))it.call(t,n)&&le(e,n,t[n]);return e},fe=(e,t)=>nt(e,rt(t));function R(e,t={}){if(Array.isArray(e))return R(e[0]);if(typeof e=="string"){const[n,r]=e.split("#");return r?R({type:"SpecificResource",source:{id:n,type:"Unknown"},selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:{id:n,type:t.typeMap&&t.typeMap[n]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return R(e.items[0]);if(e.type==="SpecificResource"){e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]);const{selector:n,selectors:r}=e.selector?k(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:n,selectors:r}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[n,r]=e.id.split("#");return r?R({type:"SpecificResource",source:fe(ue({},e),{id:n}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:fe(ue({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function de(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function pe(e,t,n){const r=[];let a=null;const i=[];for(const s of t){const o=e.get(s.body);for(const c of o){const[l,{selector:d}]=de(c),u=(l.type||"unknown").toLowerCase();if(u==="choice"){const p=e.get(l.items),h=n.length?n.map(f=>p.find(v=>v.id===f)).filter(Boolean):[p[0]];h.length===0&&h.push(p[0]),a={type:"single-choice",items:p.map(f=>({id:f.id,label:f.label,selected:h.indexOf(f)!==-1})),label:c.label},o.push(...h);continue}r.indexOf(u)===-1&&r.push(u),i.push({type:u,resource:l,target:s.target,selector:d})}}return{types:r,items:i,choice:a}}const ve={makeChoice:()=>{}},Y={type:"unknown"},x=e=>({type:"unknown",reason:e,annotations:{pages:[]}});function me(e,t,n){const r=[];for(const a of t.items){const i=a.resource&&a.resource.type==="SpecificResource"?a.resource.source:a.resource;if(!i.id)return x("No resource Identifier");let s;if(i.service){const v=q(i);v[0]&&(s=n(v[0],e))}const{selector:o,source:c}=R(a.target);if(c.id!==e.id)continue;const l={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},d=o?o.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:o.temporal,spatial:l.spatial}:o:null,u={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},p=a.resource.type==="SpecificResource"?R(a.resource):null,h=p&&p.selector&&(p.selector.type==="BoxSelector"||p.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:p.selector.spatial.x,y:p.selector.spatial.y,width:p.selector.spatial.width,height:p.selector.spatial.height}}:u,f={id:i.id,type:"Image",width:d?i.width:e.width,height:d?i.height:e.height,service:s,sizes:s&&s.sizes?s.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:d&&d.type!=="PointSelector"?d:l,selector:h};r.push(f)}return{type:"images",image:r[0],images:r,choice:t.choice}}var st=Object.defineProperty,at=Object.defineProperties,ct=Object.getOwnPropertyDescriptors,ge=Object.getOwnPropertySymbols,lt=Object.prototype.hasOwnProperty,ut=Object.prototype.propertyIsEnumerable,he=(e,t,n)=>t in e?st(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ft=(e,t)=>{for(var n in t||(t={}))lt.call(t,n)&&he(e,n,t[n]);if(ge)for(var n of ge(t))ut.call(t,n)&&he(e,n,t[n]);return e},dt=(e,t)=>at(e,ct(t));function pt(e={},t=[]){const{id:n,selector:r}=e,a=T(),i=_(),s=n||a.annotation,o=E(l=>s?l.iiif.entities.Annotation[s]:void 0,[s]),c=E(l=>o&&o.body?o.body.map(d=>d?l.iiif.entities[d.type][d.id]:null).filter(Boolean):[],[o]);return m(()=>{if(!o)return;const l=dt(ft({},o),{body:c,target:R(o.target,{typeMap:i.getState().iiif.mapping})});return r?r(l):l},[o,r,c,...t])}function F(e={},t=[]){const{id:n,selector:r}=e,a=T();_();const i=n||a.manifest,s=E(o=>i?o.iiif.entities.Manifest[i]:void 0,[i]);return m(()=>{if(!!s)return r?r(s):s},[s,r,...t])}function V(e={},t=[]){const{id:n,selector:r}=e,a=T(),i=n||a.canvas,s=E(o=>i?o.iiif.entities.Canvas[i]:void 0,[i]);return m(()=>{if(!!s)return r?r(s):s},[s,r,...t])}function vt(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function mt(e,t){return E(n=>{const r=[];if(!e)return r;const a=Object.keys(n.iiif.entities.AnnotationPage);for(const i of a)if(!t||t.indexOf(i)!==-1){const s=vt(n,i);s&&s.views&&s.views[e]&&r.push(i)}return r},[e,t])}function ye({canvas:e,manifest:t,all:n,canvases:r}){const a=[];if(t)for(const i of t.annotations)a.indexOf(i.id)===-1&&a.push(i.id);if(n){if(r&&r.length)for(const i of r)for(const s of i.annotations)a.indexOf(s.id)===-1&&a.push(s.id)}else if(e)for(const i of e.annotations)a.indexOf(i.id)===-1&&a.push(i.id);return a}var gt=Object.defineProperty,ht=Object.defineProperties,yt=Object.getOwnPropertyDescriptors,_e=Object.getOwnPropertySymbols,_t=Object.prototype.hasOwnProperty,Pt=Object.prototype.propertyIsEnumerable,Pe=(e,t,n)=>t in e?gt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Se=(e,t)=>{for(var n in t||(t={}))_t.call(t,n)&&Pe(e,n,t[n]);if(_e)for(var n of _e(t))Pt.call(t,n)&&Pe(e,n,t[n]);return e},we=(e,t)=>ht(e,yt(t));function St(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function Ee(e,t={}){const n=_(),r=F(),a=V(),i=se(),s=m(()=>ye({all:t.all,manifest:r,canvas:a,canvases:i}),[t.all,a,i,r]),o=mt(e,t.all?void 0:s),c=C(d=>{!e||n.setMetaValue([d,"annotationPageManager","views"],u=>u&&!u[e]?u:we(Se({},u||{}),{[e]:!1}))},[e,n]),l=C((d,u={})=>{if(!e)return;const p=n.getState(),h=[];if(u==null?void 0:u.deselectOthers){const f=Object.keys(p.iiif.entities.AnnotationPage);for(const v of f){const P=St(p,v);P&&P.views&&P.views[e]&&h.push(v)}}for(const f of h)c(f);n.setMetaValue([d,"annotationPageManager","views"],f=>f&&f[e]?f:we(Se({},f||{}),{[e]:!0}))},[e,c,n]);return{availablePageIds:s,enabledPageIds:o,setPageEnabled:l,setPageDisabled:c}}function H(e={}){const t=V(e.canvasId?{id:e.canvasId}:void 0);return E((n,r)=>{if(!t)return[];const a=r.get(t.items),i=[];for(const s of a)i.push(...r.get(s.items));return i},[t])}function wt(e,t={}){return H(t)}function Et(e,t=!1){}function Ot(e,t=[]){const{id:n,selector:r}=e,a=T(),i=n||a.collection,s=E(o=>i?o.iiif.entities.Collection[i]:void 0,[i]);return m(()=>{if(!!s)return r?r(s):s},[s,r,...t])}function Oe(){const t=_().getStore();return m(()=>n=>t.dispatch(n),[t])}function Ct(e,t,n,r,a=[]){const i=_(),s=m(()=>W(i),[i]);b(()=>{const o=e;return o?(s.addEventListener(o,t,n,r),()=>{s.removeEventListener(o,t,n)}):()=>{}},[s,e,t,...a])}function xt(){const e=O(L);return e&&e.vault?e.vault:X()}function It(e,t){const{id:n,isLoaded:r,error:a,resource:i,requestId:s,cached:o}=z(e,t);return{id:n,isLoaded:r,error:a,manifest:i,requestId:s,cached:o}}var bt=(e,t,n)=>new Promise((r,a)=>{var i=c=>{try{o(n.next(c))}catch(l){a(l)}},s=c=>{try{o(n.throw(c))}catch(l){a(l)}},o=c=>c.done?r(c.value):Promise.resolve(c.value).then(i,s);o((n=n.apply(e,t)).next())});function Ce({cacheKey:e}={}){const t=V(),n=H(),r=_(),a=U(),[i,s]=w(void 0),[o,c]=w(!1),[l,d]=w("idle"),[u,p]=w(void 0),h=t?t.id:"undefined",f=m(()=>{try{if(t&&n.length){const P=n[0],M=r.get(P.body[0]),S=q(M)[0];return S&&a.loadServiceSync({id:S.id||S["@id"],width:S.width||t.width,height:S.height||t.height})||void 0}}catch(P){console.error(P)}},[h,e,t]),v=l==="success"&&i?i:f;return b(()=>{bt(this,null,function*(){try{if(t&&n.length){const P=n[0],M=r.get(P.body[0]),S=q(M)[0];if(!S)return;c(!0),d("loading");try{const I=(yield a.loadService({id:S.id||S["@id"],width:S.width||t.width,height:S.height||t.height}))||void 0;s(I),d("success"),c(!1)}catch(I){d("error"),p(I)}}}catch(P){d("error"),p(P)}})},[h,e]),m(()=>({data:v,isFetching:o,status:l,error:u}),[v,o,l,u])}function Rt(){const e=Ce();return{isLoading:e.isFetching,tile:e.data?{id:e.data.id||e.data["@id"],width:e.data.width,height:e.data.height,imageService:e.data,thumbnail:void 0}:null}}function xe(e,t=[]){const n=_(),r=H(),[a,i]=w((e==null?void 0:e.defaultChoices)||[]),s=m(()=>pe(n,r,a),[n,r,a,...t]),c={makeChoice:C((l,{deselectOthers:d=!0,deselect:u=!1}={})=>{if(s.choice){if(s.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");i(p=>{if(u){const f=p.filter(v=>v!==l);if(f.length===0){const v=s.items[0].resource.id;return v?[v]:[]}return f}if(d)return[l];const h=[...p];if(h.length===0&&s.items.length){const f=s.items[0].resource.id;f&&h.push(f)}return p.indexOf(l)!==-1?p:[...p,l]})}},[s.choice])};return[s,c]}function At(e={},t=[]){const{id:n,selector:r}=e,a=T(),i=n||a.range,s=E(o=>i?o.iiif.entities.Range[i]:void 0,[i]);return m(()=>{if(!!s)return r?r(s):s},[s,r,...t])}function Tt(e,t){const n=_(),r=m(()=>W(n),[n]),a=E(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return m(()=>e?r.getListenersAsProps(e,t):{},[a,e,n,t])}function Ie(e,t){return E((n,r)=>r.get(e.map(a=>({id:a,type:t}))),[e,t])}function $t(){const e=F();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function Mt(){const e=_();return m(()=>Z(e),[e])}function Vt(e,t){const n=_(),r=m(()=>Z(n),[n]);return E(()=>{if(!e)return null;const a=r.getAppliedStyles(e.id);return a?t?a[t]:a:void 0},[e,t])}const be=(e,t=[])=>{const n=_();b(()=>{e(n)},[n,...t])};function Lt(e,t,{canvasId:n,manifestId:r}={}){const a=_(),i=U(),s=m(()=>Be(a,{imageServiceLoader:i}),[a,i]),[o,c]=w(),l=F(r?{id:r}:void 0),d=V(n?{id:n}:void 0),u=d||l,p=Q(!1);if(b(()=>()=>{p.current=!0},[]),!u)throw new Error("Must be called under a manifest or canvas context.");return be(h=>{s.getBestThumbnailAtSize(u,e,t).then(f=>{f.best&&!p.current&&c(f.best)})},[u]),o}var Dt=Object.defineProperty,jt=Object.defineProperties,Ft=Object.getOwnPropertyDescriptors,Re=Object.getOwnPropertySymbols,Nt=Object.prototype.hasOwnProperty,Bt=Object.prototype.propertyIsEnumerable,Ae=(e,t,n)=>t in e?Dt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Te=(e,t)=>{for(var n in t||(t={}))Nt.call(t,n)&&Ae(e,n,t[n]);if(Re)for(var n of Re(t))Bt.call(t,n)&&Ae(e,n,t[n]);return e},$e=(e,t)=>jt(e,Ft(t));function Me(){const e=U(),[t,n]=w({}),r=Q(!1);return b(()=>()=>{r.current=!0},[]),[C((i,{height:s,width:o})=>{if(i){const c=i.id||i["@id"],l=e.loadServiceSync({id:c,width:i.width||o,height:i.height||s});l?i=l:t[c]||(r.current||n(d=>$e(Te({},d),{[c]:"loading"})),e.loadService({id:c,width:i.width||o,height:i.height||s}).then(()=>{r.current||n(d=>$e(Te({},d),{[c]:"done"}))}))}return i},[e,t]),t]}const Ut="@iiif/IMPORT_ENTITIES",kt="@iiif/MODIFY_ENTITY_FIELD",Ht="@iiif/REORDER_ENTITY_FIELD",Qt="@iiif/ADD_REFERENCE",qt="@iiif/REMOVE_REFERENCE",zt=y(Ut)(),Yt=y(kt)(),Gt=y(Ht)(),Xt=y(Qt)(),Jt=y(qt)(),G={importEntities:zt,modifyEntityField:Yt,reorderEntityField:Gt,addReference:Xt,removeReference:Jt},Wt="@iiif/ADD_MAPPING",Zt="@iiif/ADD_MAPPINGS";y(Wt)(),y(Zt)();const Kt="@iiif/SET_META_VALUE",en="@iiif/SET_META_VALUE_DYNAMIC",tn="@iiif/UNSET_META_VALUE";y(Kt)(),y(en)(),y(tn)();const nn="@iiif/REQUEST_RESOURCE",rn="@iiif/REQUEST_ERROR",on="@iiif/REQUEST_MISMATCH",sn="@iiif/REQUEST_COMPLETE",an="@iiif/REQUEST_OFFLINE_RESOURCE";y(nn)(),y(rn)(),y(on)(),y(sn)(),y(an)();const cn="@iiif/BATCH",ln="@iiif/BATCH_IMPORT";y(cn)(),y(ln)();function Ve(e){return typeof e!="string"&&e&&e.bindToVault}function un(){const e=_(),t=Q([]),n=Oe(),r=m(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);Fe(()=>{const o={id:r,type:"AnnotationPage",behavior:[],motivation:null,label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[]};n(G.importEntities({entities:{AnnotationPage:{[o.id]:o}}}))},[r]);const a=E(o=>r?o.iiif.entities.AnnotationPage[r]:null,[r]),i=C((o,c)=>{if(r){if(Ve(o)){const u=o;u.__vault||u.bindToVault(e),o=typeof u.source=="string"?u.source:u.source.id,t.current[o]=u}else typeof o!="string"&&(o=o.id);const l=e.get({id:r,type:"AnnotationPage"}),d=e.get({id:o,type:"Annotation"});l&&d&&(l.items.find(u=>u.id===d.id)||n(G.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"},index:c})))}},[r]),s=C(o=>{r&&(Ve(o)?o=typeof o.source=="string"?o.source:o.source.id:typeof o!="string"&&(o=o.id),t.current[o]&&t.current[o].beforeRemove(),e.get({id:r,type:"AnnotationPage"})&&n(G.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"}})))},[r]);return[a,{addAnnotation:i,removeAnnotation:s}]}var fn=Object.defineProperty,dn=Object.defineProperties,pn=Object.getOwnPropertyDescriptors,Le=Object.getOwnPropertySymbols,vn=Object.prototype.hasOwnProperty,mn=Object.prototype.propertyIsEnumerable,De=(e,t,n)=>t in e?fn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,gn=(e,t)=>{for(var n in t||(t={}))vn.call(t,n)&&De(e,n,t[n]);if(Le)for(var n of Le(t))mn.call(t,n)&&De(e,n,t[n]);return e},hn=(e,t)=>dn(e,pn(t));function yn(e){const t=F(),n=V(),r=_(),[a,i]=Me(),{enabledPageIds:s}=Ee((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(n==null?void 0:n.id),{all:!1}),o=Ie(s,"AnnotationPage"),c=(e==null?void 0:e.strategies)||["images","media","complex-timeline"],[l,d]=xe(e,[i]),u=m(()=>{if(!n||l.types.length===0)return Y;if(l.types.length!==1)return c.indexOf("complex-timeline")===-1?x("Complex timeline not supported"):x("ComplexTimelineStrategy not yet supported");const p=l.types[0];return p==="image"?c.indexOf("images")===-1?x("Image not supported"):me(n,l,a):p==="audio"?c.indexOf("media")===-1?x("Media not supported"):x("Audio strategy not yet supported"):p==="video"?c.indexOf("media")===-1?x("Media not supported"):x("Video strategy not yet supported"):Y},[n,l,r,d.makeChoice]);return m(()=>u.type==="unknown"?[u,ve]:[hn(gn({},u),{annotations:{pages:o}}),d],[u,o])}export{qe as AnnotationContext,ne as CanvasContext,ze as CollectionContext,Ze as ContextBridge,ae as ImageServiceLoaderContext,re as ManifestContext,Ye as RangeContext,L as ReactVaultContext,$ as ResourceProvider,N as ResourceReactContext,Xe as SimpleViewerProvider,j as SimpleViewerReactContext,oe as VaultProvider,D as VisibleCanvasReactContext,ve as emptyActions,R as expandTarget,ye as flattenAnnotationPageIds,me as getImageStrategy,pe as getPaintables,k as parseSelector,de as parseSpecificResource,Y as unknownResponse,x as unsupportedStrategy,pt as useAnnotation,Ee as useAnnotationPageManager,wt as useAnnotationsAtTime,V as useCanvas,Et as useCanvasClock,Ot as useCollection,We as useContextBridge,Oe as useDispatch,Ct as useEventListener,xt as useExistingVault,It as useExternalCollection,ie as useExternalManifest,z as useExternalResource,Ce as useImageService,U as useImageServiceLoader,Rt as useImageTile,Me as useLoadImageService,F as useManifest,xe as usePaintables,H as usePaintingAnnotations,At as useRange,yn as useRenderingStrategy,T as useResourceContext,Tt as useResourceEvents,Ie as useResources,$t as useSearchService,Je as useSimpleViewer,Mt as useStyleHelper,Vt as useStyles,Lt as useThumbnail,_ as useVault,be as useVaultEffect,E as useVaultSelector,un as useVirtualAnnotationPage,se as useVisibleCanvases};
|
|
1
|
+
import React, { useContext, useMemo, useState, useEffect, createContext, useCallback, useRef, useLayoutEffect } from 'react';
|
|
2
|
+
import { globalVault, Vault } from '@iiif/vault';
|
|
3
|
+
import { ImageServiceLoader, getImageServices } from '@atlas-viewer/iiif-image-api';
|
|
4
|
+
import { createEventsHelper, createStylesHelper, createThumbnailHelper } from '@iiif/vault-helpers';
|
|
5
|
+
import { createAction } from 'typesafe-actions';
|
|
6
|
+
|
|
7
|
+
var __defProp$5 = Object.defineProperty;
|
|
8
|
+
var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
|
|
9
|
+
var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues$5 = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp$5.call(b, prop))
|
|
15
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols$5)
|
|
17
|
+
for (var prop of __getOwnPropSymbols$5(b)) {
|
|
18
|
+
if (__propIsEnum$5.call(b, prop))
|
|
19
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
const defaultResourceContext = {
|
|
24
|
+
collection: void 0,
|
|
25
|
+
manifest: void 0,
|
|
26
|
+
range: void 0,
|
|
27
|
+
canvas: void 0,
|
|
28
|
+
annotation: void 0
|
|
29
|
+
};
|
|
30
|
+
const ResourceReactContext = React.createContext(defaultResourceContext);
|
|
31
|
+
const useResourceContext = () => {
|
|
32
|
+
return useContext(ResourceReactContext);
|
|
33
|
+
};
|
|
34
|
+
const ResourceProvider = ({ value, children }) => {
|
|
35
|
+
const parentContext = useResourceContext();
|
|
36
|
+
const newContext = useMemo(() => {
|
|
37
|
+
return __spreadValues$5(__spreadValues$5({}, parentContext), value);
|
|
38
|
+
}, [value, parentContext]);
|
|
39
|
+
return /* @__PURE__ */ React.createElement(ResourceReactContext.Provider, {
|
|
40
|
+
value: newContext
|
|
41
|
+
}, children);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const AnnotationContext = ({ annotation, children }) => {
|
|
45
|
+
return /* @__PURE__ */ React.createElement(ResourceProvider, {
|
|
46
|
+
value: { annotation }
|
|
47
|
+
}, children);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const CanvasContext = ({ canvas, children }) => {
|
|
51
|
+
return /* @__PURE__ */ React.createElement(ResourceProvider, {
|
|
52
|
+
value: { canvas }
|
|
53
|
+
}, children);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const CollectionContext = ({ collection, children }) => {
|
|
57
|
+
return /* @__PURE__ */ React.createElement(ResourceProvider, {
|
|
58
|
+
value: { collection }
|
|
59
|
+
}, children);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const ManifestContext = ({ manifest, children }) => {
|
|
63
|
+
return /* @__PURE__ */ React.createElement(ResourceProvider, {
|
|
64
|
+
value: { manifest }
|
|
65
|
+
}, children);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const RangeContext = ({ range, children }) => {
|
|
69
|
+
return /* @__PURE__ */ React.createElement(ResourceProvider, {
|
|
70
|
+
value: { range }
|
|
71
|
+
}, children);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const ReactVaultContext = React.createContext({
|
|
75
|
+
vault: null,
|
|
76
|
+
setVaultInstance: (vault) => {
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
const VaultProvider = ({ vault, vaultOptions, useGlobal, resources, children }) => {
|
|
80
|
+
const [vaultInstance, setVaultInstance] = useState(() => {
|
|
81
|
+
if (vault) {
|
|
82
|
+
return vault;
|
|
83
|
+
}
|
|
84
|
+
if (useGlobal) {
|
|
85
|
+
return globalVault(vaultOptions);
|
|
86
|
+
}
|
|
87
|
+
if (vaultOptions) {
|
|
88
|
+
return new Vault(vaultOptions);
|
|
89
|
+
}
|
|
90
|
+
return new Vault();
|
|
91
|
+
});
|
|
92
|
+
return /* @__PURE__ */ React.createElement(ReactVaultContext.Provider, {
|
|
93
|
+
value: { vault: vaultInstance, setVaultInstance }
|
|
94
|
+
}, /* @__PURE__ */ React.createElement(ResourceProvider, {
|
|
95
|
+
value: resources || {}
|
|
96
|
+
}, children));
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const useVault = () => {
|
|
100
|
+
const { vault } = useContext(ReactVaultContext);
|
|
101
|
+
if (vault === null) {
|
|
102
|
+
throw new Error("Vault not found. Ensure you have your provider set up correctly.");
|
|
103
|
+
}
|
|
104
|
+
return vault;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
var __async$1 = (__this, __arguments, generator) => {
|
|
108
|
+
return new Promise((resolve, reject) => {
|
|
109
|
+
var fulfilled = (value) => {
|
|
110
|
+
try {
|
|
111
|
+
step(generator.next(value));
|
|
112
|
+
} catch (e) {
|
|
113
|
+
reject(e);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
var rejected = (value) => {
|
|
117
|
+
try {
|
|
118
|
+
step(generator.throw(value));
|
|
119
|
+
} catch (e) {
|
|
120
|
+
reject(e);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
124
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
function useExternalResource(idOrRef, { noCache = false } = {}) {
|
|
128
|
+
const id = typeof idOrRef === "string" ? idOrRef : idOrRef.id;
|
|
129
|
+
const vault = useVault();
|
|
130
|
+
const [realId, setRealId] = useState(id);
|
|
131
|
+
const [error, setError] = useState(void 0);
|
|
132
|
+
const initialData = useMemo(() => {
|
|
133
|
+
return vault.get(id, { skipSelfReturn: true }) || void 0;
|
|
134
|
+
}, [id, vault]);
|
|
135
|
+
const [resource, setResource] = useState(initialData);
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
(() => __async$1(this, null, function* () {
|
|
138
|
+
try {
|
|
139
|
+
const fetchedResource = initialData && !noCache ? initialData : yield vault.load(id);
|
|
140
|
+
const _realId = fetchedResource ? fetchedResource.id || fetchedResource["@id"] : null;
|
|
141
|
+
if (fetchedResource && realId !== _realId) {
|
|
142
|
+
setRealId(_realId);
|
|
143
|
+
}
|
|
144
|
+
setResource(fetchedResource);
|
|
145
|
+
} catch (err) {
|
|
146
|
+
setError(err);
|
|
147
|
+
}
|
|
148
|
+
}))();
|
|
149
|
+
}, [id, noCache]);
|
|
150
|
+
return {
|
|
151
|
+
isLoaded: !!resource,
|
|
152
|
+
id: realId,
|
|
153
|
+
requestId: id,
|
|
154
|
+
error,
|
|
155
|
+
resource,
|
|
156
|
+
cached: !!(resource && resource === initialData)
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function useExternalManifest(idOrRef, options) {
|
|
161
|
+
const { id, isLoaded, error, resource, requestId, cached } = useExternalResource(idOrRef, options);
|
|
162
|
+
return { id, isLoaded, error, manifest: resource, requestId, cached };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function useVaultSelector(selector, deps = []) {
|
|
166
|
+
const vault = useVault();
|
|
167
|
+
const [selectedState, setSelectedState] = useState(() => selector(vault.getState(), vault));
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
return vault.subscribe((s) => selector(s, vault), (state) => {
|
|
170
|
+
setSelectedState(state);
|
|
171
|
+
}, false);
|
|
172
|
+
}, deps);
|
|
173
|
+
return selectedState;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const VisibleCanvasReactContext = React.createContext([]);
|
|
177
|
+
function useVisibleCanvases() {
|
|
178
|
+
const ids = useContext(VisibleCanvasReactContext);
|
|
179
|
+
return useVaultSelector((state) => {
|
|
180
|
+
return ids.map((id) => state.iiif.entities.Canvas[id]).filter(Boolean);
|
|
181
|
+
}, [ids]);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const noop = () => {
|
|
185
|
+
};
|
|
186
|
+
const SimpleViewerReactContext = createContext({
|
|
187
|
+
setCurrentCanvasId: noop,
|
|
188
|
+
setCurrentCanvasIndex: noop,
|
|
189
|
+
nextCanvas: noop,
|
|
190
|
+
previousCanvas: noop,
|
|
191
|
+
currentCanvasIndex: -1,
|
|
192
|
+
totalCanvases: 0,
|
|
193
|
+
pagingView: true
|
|
194
|
+
});
|
|
195
|
+
const SimpleViewerProvider = (props) => {
|
|
196
|
+
const manifest = useExternalManifest(props.manifest);
|
|
197
|
+
const [currentCanvasId, setCurrentCanvasId] = useState("");
|
|
198
|
+
const [visible, setVisible] = useState([]);
|
|
199
|
+
const pagingView = (typeof props.pagingEnabled === "undefined" || props.pagingEnabled) && manifest.manifest && manifest.manifest.behavior && manifest.manifest.behavior.includes("paged");
|
|
200
|
+
useEffect(() => {
|
|
201
|
+
var _a, _b;
|
|
202
|
+
if (manifest.manifest) {
|
|
203
|
+
setCurrentCanvasId((_a = manifest.manifest.items[0]) == null ? void 0 : _a.id);
|
|
204
|
+
setVisible([(_b = manifest.manifest.items[0]) == null ? void 0 : _b.id]);
|
|
205
|
+
}
|
|
206
|
+
}, [manifest.manifest, props.manifest]);
|
|
207
|
+
const canvasList = useMemo(() => {
|
|
208
|
+
var _a;
|
|
209
|
+
return ((_a = manifest.manifest) == null ? void 0 : _a.items.map((c) => c.id)) || [];
|
|
210
|
+
}, [manifest.manifest, props.manifest]);
|
|
211
|
+
const currentCanvasIndex = useMemo(() => canvasList.indexOf(currentCanvasId), [canvasList, currentCanvasId]);
|
|
212
|
+
const nextCanvas = useCallback(() => {
|
|
213
|
+
if (canvasList.length && currentCanvasId) {
|
|
214
|
+
if (currentCanvasIndex === -1) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (canvasList[currentCanvasIndex + 2] ? currentCanvasIndex + 2 === canvasList.length : currentCanvasIndex === canvasList.length) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const newCanvas = pagingView && currentCanvasIndex !== 0 ? canvasList[currentCanvasIndex + 2] : canvasList[currentCanvasIndex + 1];
|
|
221
|
+
const pageCanvas = pagingView ? currentCanvasIndex !== 0 ? canvasList[currentCanvasIndex + 3] : canvasList[currentCanvasIndex + 2] : null;
|
|
222
|
+
if (newCanvas) {
|
|
223
|
+
setCurrentCanvasId(newCanvas);
|
|
224
|
+
setVisible(pageCanvas ? [newCanvas, pageCanvas] : [newCanvas]);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}, [pagingView, canvasList, currentCanvasId, currentCanvasIndex]);
|
|
228
|
+
const previousCanvas = useCallback(() => {
|
|
229
|
+
if (canvasList.length && currentCanvasId) {
|
|
230
|
+
if (currentCanvasIndex === 0 || currentCanvasIndex === -1) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const newCanvas = pagingView && currentCanvasIndex !== 1 ? canvasList[currentCanvasIndex - 2] : canvasList[currentCanvasIndex - 1];
|
|
234
|
+
const pageCanvas = pagingView && currentCanvasIndex !== 1 ? canvasList[currentCanvasIndex - 1] : null;
|
|
235
|
+
if (newCanvas) {
|
|
236
|
+
setCurrentCanvasId(newCanvas);
|
|
237
|
+
setVisible(pageCanvas ? [newCanvas, pageCanvas] : [newCanvas]);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}, [pagingView, canvasList, currentCanvasId, currentCanvasIndex]);
|
|
241
|
+
const setCurrentCanvasIndex = useCallback((idx) => {
|
|
242
|
+
const realIdx = pagingView && idx % 2 === 1 ? idx - 1 : idx;
|
|
243
|
+
const newId = canvasList[realIdx];
|
|
244
|
+
const newNextId = pagingView && realIdx !== 0 ? canvasList[realIdx + 1] : null;
|
|
245
|
+
if (newId) {
|
|
246
|
+
setCurrentCanvasId(newId);
|
|
247
|
+
setVisible((prevValue) => {
|
|
248
|
+
const newValue = newNextId ? [newId, newNextId] : [newId];
|
|
249
|
+
if (prevValue.length === prevValue.length) {
|
|
250
|
+
for (let i = 0; i < prevValue.length; i++) {
|
|
251
|
+
if (prevValue[i] !== newValue[i]) {
|
|
252
|
+
return newValue;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return prevValue;
|
|
256
|
+
}
|
|
257
|
+
return newValue;
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}, [pagingView, canvasList]);
|
|
261
|
+
const internalSetCurrentCanvasId = useCallback((nextId) => {
|
|
262
|
+
const idx = canvasList.indexOf(nextId);
|
|
263
|
+
if (idx !== -1) {
|
|
264
|
+
setCurrentCanvasIndex(idx);
|
|
265
|
+
}
|
|
266
|
+
}, [canvasList, setCurrentCanvasIndex]);
|
|
267
|
+
const ctx = useMemo(() => ({
|
|
268
|
+
setCurrentCanvasId: internalSetCurrentCanvasId,
|
|
269
|
+
nextCanvas,
|
|
270
|
+
previousCanvas,
|
|
271
|
+
currentCanvasIndex,
|
|
272
|
+
totalCanvases: canvasList.length,
|
|
273
|
+
setCurrentCanvasIndex,
|
|
274
|
+
pagingView: true
|
|
275
|
+
}), [nextCanvas, previousCanvas, currentCanvasIndex, canvasList, setCurrentCanvasIndex, internalSetCurrentCanvasId]);
|
|
276
|
+
if (!manifest.manifest) {
|
|
277
|
+
console.warn("The manifest passed to the provider is not a valid IIIF manifest.");
|
|
278
|
+
return /* @__PURE__ */ React.createElement("div", null, "Sorry, something went wrong.");
|
|
279
|
+
}
|
|
280
|
+
if (!manifest.isLoaded) {
|
|
281
|
+
return /* @__PURE__ */ React.createElement("div", null, "Loading...");
|
|
282
|
+
}
|
|
283
|
+
return /* @__PURE__ */ React.createElement(SimpleViewerReactContext.Provider, {
|
|
284
|
+
value: ctx
|
|
285
|
+
}, /* @__PURE__ */ React.createElement(VisibleCanvasReactContext.Provider, {
|
|
286
|
+
value: visible
|
|
287
|
+
}, /* @__PURE__ */ React.createElement(ManifestContext, {
|
|
288
|
+
manifest: manifest.manifest.id
|
|
289
|
+
}, /* @__PURE__ */ React.createElement(CanvasContext, {
|
|
290
|
+
canvas: currentCanvasId
|
|
291
|
+
}, props.children))));
|
|
292
|
+
};
|
|
293
|
+
function useSimpleViewer() {
|
|
294
|
+
return useContext(SimpleViewerReactContext);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function useContextBridge() {
|
|
298
|
+
return {
|
|
299
|
+
VaultContext: useContext(ReactVaultContext),
|
|
300
|
+
ResourceContext: useContext(ResourceReactContext),
|
|
301
|
+
SimpleViewerReactContext: useContext(SimpleViewerReactContext),
|
|
302
|
+
VisibleCanvasReactContext: useContext(VisibleCanvasReactContext)
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
const ContextBridge = (props) => {
|
|
306
|
+
return /* @__PURE__ */ React.createElement(VaultProvider, {
|
|
307
|
+
vault: props.bridge.VaultContext.vault || void 0,
|
|
308
|
+
resources: props.bridge.ResourceContext
|
|
309
|
+
}, /* @__PURE__ */ React.createElement(VisibleCanvasReactContext.Provider, {
|
|
310
|
+
value: props.bridge.VisibleCanvasReactContext
|
|
311
|
+
}, /* @__PURE__ */ React.createElement(SimpleViewerReactContext.Provider, {
|
|
312
|
+
value: props.bridge.SimpleViewerReactContext
|
|
313
|
+
}, props.children)));
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
const ImageServiceLoaderContext = React.createContext(new ImageServiceLoader());
|
|
317
|
+
function useImageServiceLoader() {
|
|
318
|
+
return useContext(ImageServiceLoaderContext);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const BOX_SELECTOR = /&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/;
|
|
322
|
+
const TEMPORAL_SELECTOR = /&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;
|
|
323
|
+
function parseSelector(source) {
|
|
324
|
+
if (Array.isArray(source)) {
|
|
325
|
+
return source.reduce((data, nextSource) => {
|
|
326
|
+
const { selector, selectors } = parseSelector(nextSource);
|
|
327
|
+
if (selector) {
|
|
328
|
+
if (!data.selector) {
|
|
329
|
+
data.selector = selector;
|
|
330
|
+
}
|
|
331
|
+
data.selectors.push(...selectors);
|
|
332
|
+
}
|
|
333
|
+
return data;
|
|
334
|
+
}, {
|
|
335
|
+
selector: null,
|
|
336
|
+
selectors: []
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
if (!source) {
|
|
340
|
+
return {
|
|
341
|
+
selector: null,
|
|
342
|
+
selectors: []
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
if (typeof source === "string") {
|
|
346
|
+
const [id, fragment] = source.split("#");
|
|
347
|
+
if (!fragment) {
|
|
348
|
+
return {
|
|
349
|
+
selector: null,
|
|
350
|
+
selectors: []
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
return parseSelector({ type: "FragmentSelector", value: fragment });
|
|
354
|
+
}
|
|
355
|
+
if (source.type === "PointSelector" && (source.t || source.t === 0)) {
|
|
356
|
+
const selector = {
|
|
357
|
+
type: "TemporalSelector",
|
|
358
|
+
temporal: {
|
|
359
|
+
startTime: source.t
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
return {
|
|
363
|
+
selector,
|
|
364
|
+
selectors: [selector]
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
if (source.type === "FragmentSelector") {
|
|
368
|
+
const matchBoxSelector = BOX_SELECTOR.exec(source.value);
|
|
369
|
+
if (matchBoxSelector) {
|
|
370
|
+
const selector = {
|
|
371
|
+
type: "BoxSelector",
|
|
372
|
+
spatial: {
|
|
373
|
+
unit: matchBoxSelector[2] === "percent:" ? "percent" : "pixel",
|
|
374
|
+
x: parseFloat(matchBoxSelector[3]),
|
|
375
|
+
y: parseFloat(matchBoxSelector[4]),
|
|
376
|
+
width: parseFloat(matchBoxSelector[5]),
|
|
377
|
+
height: parseFloat(matchBoxSelector[6])
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
return {
|
|
381
|
+
selector,
|
|
382
|
+
selectors: [selector]
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
const matchTimeSelector = source.value.match(TEMPORAL_SELECTOR);
|
|
386
|
+
if (matchTimeSelector) {
|
|
387
|
+
const selector = {
|
|
388
|
+
type: "TemporalSelector",
|
|
389
|
+
temporal: {
|
|
390
|
+
startTime: matchTimeSelector[4] ? parseFloat(matchTimeSelector[4]) : 0,
|
|
391
|
+
endTime: matchTimeSelector[7] ? parseFloat(matchTimeSelector[7]) : void 0
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
return {
|
|
395
|
+
selector,
|
|
396
|
+
selectors: [selector]
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
return {
|
|
400
|
+
selector: null,
|
|
401
|
+
selectors: []
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
return {
|
|
405
|
+
selector: null,
|
|
406
|
+
selectors: []
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
var __defProp$4 = Object.defineProperty;
|
|
411
|
+
var __defProps$4 = Object.defineProperties;
|
|
412
|
+
var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
|
|
413
|
+
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
414
|
+
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
415
|
+
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
416
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
417
|
+
var __spreadValues$4 = (a, b) => {
|
|
418
|
+
for (var prop in b || (b = {}))
|
|
419
|
+
if (__hasOwnProp$4.call(b, prop))
|
|
420
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
421
|
+
if (__getOwnPropSymbols$4)
|
|
422
|
+
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
423
|
+
if (__propIsEnum$4.call(b, prop))
|
|
424
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
425
|
+
}
|
|
426
|
+
return a;
|
|
427
|
+
};
|
|
428
|
+
var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
|
|
429
|
+
function expandTarget(target, options = {}) {
|
|
430
|
+
if (Array.isArray(target)) {
|
|
431
|
+
return expandTarget(target[0]);
|
|
432
|
+
}
|
|
433
|
+
if (typeof target === "string") {
|
|
434
|
+
const [id, fragment] = target.split("#");
|
|
435
|
+
if (!fragment) {
|
|
436
|
+
return {
|
|
437
|
+
type: "SpecificResource",
|
|
438
|
+
source: { id, type: options.typeMap && options.typeMap[id] || "Unknown" },
|
|
439
|
+
selector: null,
|
|
440
|
+
selectors: []
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
return expandTarget({
|
|
444
|
+
type: "SpecificResource",
|
|
445
|
+
source: { id, type: "Unknown" },
|
|
446
|
+
selector: {
|
|
447
|
+
type: "FragmentSelector",
|
|
448
|
+
value: fragment
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
if (target.type === "Choice" || target.type === "List" || target.type === "Composite" || target.type === "Independents") {
|
|
453
|
+
return expandTarget(target.items[0]);
|
|
454
|
+
}
|
|
455
|
+
if (target.type === "SpecificResource") {
|
|
456
|
+
if (target.source.type === "Canvas" && target.source.partOf && typeof target.source.partOf === "string") {
|
|
457
|
+
target.source.partOf = [
|
|
458
|
+
{
|
|
459
|
+
id: target.source.partOf,
|
|
460
|
+
type: "Manifest"
|
|
461
|
+
}
|
|
462
|
+
];
|
|
463
|
+
}
|
|
464
|
+
const { selector, selectors } = target.selector ? parseSelector(target.selector) : { selector: null, selectors: [] };
|
|
465
|
+
return {
|
|
466
|
+
type: "SpecificResource",
|
|
467
|
+
source: target.source,
|
|
468
|
+
selector,
|
|
469
|
+
selectors
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
if (target.id) {
|
|
473
|
+
if (target.type === "Canvas" && target.partOf && typeof target.partOf === "string") {
|
|
474
|
+
target.partOf = [
|
|
475
|
+
{
|
|
476
|
+
id: target.partOf,
|
|
477
|
+
type: "Manifest"
|
|
478
|
+
}
|
|
479
|
+
];
|
|
480
|
+
}
|
|
481
|
+
const [id, fragment] = target.id.split("#");
|
|
482
|
+
if (!fragment) {
|
|
483
|
+
return {
|
|
484
|
+
type: "SpecificResource",
|
|
485
|
+
source: __spreadProps$4(__spreadValues$4({}, target), {
|
|
486
|
+
id
|
|
487
|
+
}),
|
|
488
|
+
selector: null,
|
|
489
|
+
selectors: []
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
return expandTarget({
|
|
493
|
+
type: "SpecificResource",
|
|
494
|
+
source: __spreadProps$4(__spreadValues$4({}, target), {
|
|
495
|
+
id
|
|
496
|
+
}),
|
|
497
|
+
selector: {
|
|
498
|
+
type: "FragmentSelector",
|
|
499
|
+
value: fragment
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
return {
|
|
504
|
+
type: "SpecificResource",
|
|
505
|
+
source: target,
|
|
506
|
+
selector: null,
|
|
507
|
+
selectors: []
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
function parseSpecificResource(resource) {
|
|
512
|
+
if (resource.type === "SpecificResource") {
|
|
513
|
+
return [resource.source, { selector: resource.selector }];
|
|
514
|
+
}
|
|
515
|
+
return [resource, { selector: null }];
|
|
516
|
+
}
|
|
517
|
+
function getPaintables(vault, paintingAnnotations, enabledChoices) {
|
|
518
|
+
const types = [];
|
|
519
|
+
let choice = null;
|
|
520
|
+
const items = [];
|
|
521
|
+
for (const annotation of paintingAnnotations) {
|
|
522
|
+
const bodies = vault.get(annotation.body);
|
|
523
|
+
for (const unknownBody of bodies) {
|
|
524
|
+
const [body, { selector }] = parseSpecificResource(unknownBody);
|
|
525
|
+
const type = (body.type || "unknown").toLowerCase();
|
|
526
|
+
if (type === "choice") {
|
|
527
|
+
const nestedBodies = vault.get(body.items);
|
|
528
|
+
const selected = enabledChoices.length ? enabledChoices.map((cid) => nestedBodies.find((b) => b.id === cid)).filter(Boolean) : [nestedBodies[0]];
|
|
529
|
+
if (selected.length === 0) {
|
|
530
|
+
selected.push(nestedBodies[0]);
|
|
531
|
+
}
|
|
532
|
+
choice = {
|
|
533
|
+
type: "single-choice",
|
|
534
|
+
items: nestedBodies.map((b) => ({
|
|
535
|
+
id: b.id,
|
|
536
|
+
label: b.label,
|
|
537
|
+
selected: selected.indexOf(b) !== -1
|
|
538
|
+
})),
|
|
539
|
+
label: unknownBody.label
|
|
540
|
+
};
|
|
541
|
+
bodies.push(...selected);
|
|
542
|
+
continue;
|
|
543
|
+
}
|
|
544
|
+
if (types.indexOf(type) === -1) {
|
|
545
|
+
types.push(type);
|
|
546
|
+
}
|
|
547
|
+
items.push({
|
|
548
|
+
type,
|
|
549
|
+
resource: body,
|
|
550
|
+
target: annotation.target,
|
|
551
|
+
selector
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return {
|
|
556
|
+
types,
|
|
557
|
+
items,
|
|
558
|
+
choice
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
const emptyActions = {
|
|
562
|
+
makeChoice: () => {
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
const unknownResponse = { type: "unknown" };
|
|
566
|
+
const unsupportedStrategy = (reason) => {
|
|
567
|
+
return { type: "unknown", reason, annotations: { pages: [] } };
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
function getImageStrategy(canvas, paintables, loadImageService) {
|
|
571
|
+
const imageTypes = [];
|
|
572
|
+
for (const singleImage of paintables.items) {
|
|
573
|
+
const resource = singleImage.resource && singleImage.resource.type === "SpecificResource" ? singleImage.resource.source : singleImage.resource;
|
|
574
|
+
if (!resource.id) {
|
|
575
|
+
return unsupportedStrategy("No resource Identifier");
|
|
576
|
+
}
|
|
577
|
+
let imageService = void 0;
|
|
578
|
+
if (resource.service) {
|
|
579
|
+
const imageServices = getImageServices(resource);
|
|
580
|
+
if (imageServices[0]) {
|
|
581
|
+
imageService = loadImageService(imageServices[0], canvas);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
const { selector: imageTarget, source } = expandTarget(singleImage.target);
|
|
585
|
+
if (source.id !== canvas.id) {
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
const defaultTarget = {
|
|
589
|
+
type: "BoxSelector",
|
|
590
|
+
spatial: {
|
|
591
|
+
x: 0,
|
|
592
|
+
y: 0,
|
|
593
|
+
width: canvas.width,
|
|
594
|
+
height: canvas.height
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
const target = imageTarget ? imageTarget.type === "TemporalSelector" ? {
|
|
598
|
+
type: "TemporalBoxSelector",
|
|
599
|
+
temporal: imageTarget.temporal,
|
|
600
|
+
spatial: defaultTarget.spatial
|
|
601
|
+
} : imageTarget : null;
|
|
602
|
+
const defaultImageSelector = {
|
|
603
|
+
type: "BoxSelector",
|
|
604
|
+
spatial: {
|
|
605
|
+
x: 0,
|
|
606
|
+
y: 0,
|
|
607
|
+
width: canvas.width,
|
|
608
|
+
height: canvas.height
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
const imageSelector = singleImage.resource.type === "SpecificResource" ? expandTarget(singleImage.resource) : null;
|
|
612
|
+
const selector = imageSelector && imageSelector.selector && (imageSelector.selector.type === "BoxSelector" || imageSelector.selector.type === "TemporalBoxSelector") ? {
|
|
613
|
+
type: "BoxSelector",
|
|
614
|
+
spatial: {
|
|
615
|
+
x: imageSelector.selector.spatial.x,
|
|
616
|
+
y: imageSelector.selector.spatial.y,
|
|
617
|
+
width: imageSelector.selector.spatial.width,
|
|
618
|
+
height: imageSelector.selector.spatial.height
|
|
619
|
+
}
|
|
620
|
+
} : defaultImageSelector;
|
|
621
|
+
const imageType = {
|
|
622
|
+
id: resource.id,
|
|
623
|
+
type: "Image",
|
|
624
|
+
width: target ? resource.width : canvas.width,
|
|
625
|
+
height: target ? resource.height : canvas.height,
|
|
626
|
+
service: imageService,
|
|
627
|
+
sizes: imageService && imageService.sizes ? imageService.sizes : resource.width && resource.height ? [{ width: resource.width, height: resource.height }] : [],
|
|
628
|
+
target: target && target.type !== "PointSelector" ? target : defaultTarget,
|
|
629
|
+
selector
|
|
630
|
+
};
|
|
631
|
+
imageTypes.push(imageType);
|
|
632
|
+
}
|
|
633
|
+
return {
|
|
634
|
+
type: "images",
|
|
635
|
+
image: imageTypes[0],
|
|
636
|
+
images: imageTypes,
|
|
637
|
+
choice: paintables.choice
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
var __defProp$3 = Object.defineProperty;
|
|
642
|
+
var __defProps$3 = Object.defineProperties;
|
|
643
|
+
var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
|
|
644
|
+
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
645
|
+
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
646
|
+
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
647
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
648
|
+
var __spreadValues$3 = (a, b) => {
|
|
649
|
+
for (var prop in b || (b = {}))
|
|
650
|
+
if (__hasOwnProp$3.call(b, prop))
|
|
651
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
652
|
+
if (__getOwnPropSymbols$3)
|
|
653
|
+
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
654
|
+
if (__propIsEnum$3.call(b, prop))
|
|
655
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
656
|
+
}
|
|
657
|
+
return a;
|
|
658
|
+
};
|
|
659
|
+
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
|
|
660
|
+
function useAnnotation(options = {}, deps = []) {
|
|
661
|
+
const { id, selector } = options;
|
|
662
|
+
const ctx = useResourceContext();
|
|
663
|
+
const vault = useVault();
|
|
664
|
+
const annotationId = id ? id : ctx.annotation;
|
|
665
|
+
const annotation = useVaultSelector((s) => annotationId ? s.iiif.entities.Annotation[annotationId] : void 0, [annotationId]);
|
|
666
|
+
const body = useVaultSelector((s) => annotation && annotation.body ? annotation.body.map((singleBody) => singleBody ? s.iiif.entities[singleBody.type][singleBody.id] : null).filter(Boolean) : [], [annotation]);
|
|
667
|
+
return useMemo(() => {
|
|
668
|
+
if (!annotation) {
|
|
669
|
+
return void 0;
|
|
670
|
+
}
|
|
671
|
+
const newAnnotation = __spreadProps$3(__spreadValues$3({}, annotation), {
|
|
672
|
+
body,
|
|
673
|
+
target: expandTarget(annotation.target, { typeMap: vault.getState().iiif.mapping })
|
|
674
|
+
});
|
|
675
|
+
if (selector) {
|
|
676
|
+
return selector(newAnnotation);
|
|
677
|
+
}
|
|
678
|
+
return newAnnotation;
|
|
679
|
+
}, [annotation, selector, body, ...deps]);
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
function useManifest(options = {}, deps = []) {
|
|
683
|
+
const { id, selector } = options;
|
|
684
|
+
const ctx = useResourceContext();
|
|
685
|
+
useVault();
|
|
686
|
+
const manifestId = id ? id : ctx.manifest;
|
|
687
|
+
const manifest = useVaultSelector((s) => manifestId ? s.iiif.entities.Manifest[manifestId] : void 0, [manifestId]);
|
|
688
|
+
return useMemo(() => {
|
|
689
|
+
if (!manifest) {
|
|
690
|
+
return void 0;
|
|
691
|
+
}
|
|
692
|
+
if (selector) {
|
|
693
|
+
return selector(manifest);
|
|
694
|
+
}
|
|
695
|
+
return manifest;
|
|
696
|
+
}, [manifest, selector, ...deps]);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
function useCanvas(options = {}, deps = []) {
|
|
700
|
+
const { id, selector } = options;
|
|
701
|
+
const ctx = useResourceContext();
|
|
702
|
+
const canvasId = id ? id : ctx.canvas;
|
|
703
|
+
const canvas = useVaultSelector((s) => canvasId ? s.iiif.entities.Canvas[canvasId] : void 0, [canvasId]);
|
|
704
|
+
return useMemo(() => {
|
|
705
|
+
if (!canvas) {
|
|
706
|
+
return void 0;
|
|
707
|
+
}
|
|
708
|
+
if (selector) {
|
|
709
|
+
return selector(canvas);
|
|
710
|
+
}
|
|
711
|
+
return canvas;
|
|
712
|
+
}, [canvas, selector, ...deps]);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
function getMeta$1(state, resourceId) {
|
|
716
|
+
var _a;
|
|
717
|
+
const resourceMeta = (_a = state == null ? void 0 : state.iiif) == null ? void 0 : _a.meta[resourceId];
|
|
718
|
+
if (!resourceMeta) {
|
|
719
|
+
return null;
|
|
720
|
+
}
|
|
721
|
+
return resourceMeta.annotationPageManager;
|
|
722
|
+
}
|
|
723
|
+
function useEnabledAnnotationPageIds(resourceId, availablePageIds) {
|
|
724
|
+
return useVaultSelector((state) => {
|
|
725
|
+
const pageIds = [];
|
|
726
|
+
if (!resourceId) {
|
|
727
|
+
return pageIds;
|
|
728
|
+
}
|
|
729
|
+
const allAnnotationListIds = Object.keys(state.iiif.entities.AnnotationPage);
|
|
730
|
+
for (const annotationListId of allAnnotationListIds) {
|
|
731
|
+
if (!availablePageIds || availablePageIds.indexOf(annotationListId) !== -1) {
|
|
732
|
+
const annotationListMeta = getMeta$1(state, annotationListId);
|
|
733
|
+
if (annotationListMeta && annotationListMeta.views && annotationListMeta.views[resourceId]) {
|
|
734
|
+
pageIds.push(annotationListId);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return pageIds;
|
|
739
|
+
}, [resourceId, availablePageIds]);
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
function flattenAnnotationPageIds({
|
|
743
|
+
canvas,
|
|
744
|
+
manifest,
|
|
745
|
+
all,
|
|
746
|
+
canvases
|
|
747
|
+
}) {
|
|
748
|
+
const foundIds = [];
|
|
749
|
+
if (manifest) {
|
|
750
|
+
for (const page of manifest.annotations) {
|
|
751
|
+
if (foundIds.indexOf(page.id) === -1) {
|
|
752
|
+
foundIds.push(page.id);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
if (all) {
|
|
757
|
+
if (canvases && canvases.length) {
|
|
758
|
+
for (const canvas_ of canvases) {
|
|
759
|
+
for (const page of canvas_.annotations) {
|
|
760
|
+
if (foundIds.indexOf(page.id) === -1) {
|
|
761
|
+
foundIds.push(page.id);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
} else if (canvas) {
|
|
767
|
+
for (const page of canvas.annotations) {
|
|
768
|
+
if (foundIds.indexOf(page.id) === -1) {
|
|
769
|
+
foundIds.push(page.id);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
return foundIds;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
var __defProp$2 = Object.defineProperty;
|
|
777
|
+
var __defProps$2 = Object.defineProperties;
|
|
778
|
+
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
779
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
780
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
781
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
782
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
783
|
+
var __spreadValues$2 = (a, b) => {
|
|
784
|
+
for (var prop in b || (b = {}))
|
|
785
|
+
if (__hasOwnProp$2.call(b, prop))
|
|
786
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
787
|
+
if (__getOwnPropSymbols$2)
|
|
788
|
+
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
789
|
+
if (__propIsEnum$2.call(b, prop))
|
|
790
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
791
|
+
}
|
|
792
|
+
return a;
|
|
793
|
+
};
|
|
794
|
+
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
795
|
+
function getMeta(state, resourceId) {
|
|
796
|
+
var _a;
|
|
797
|
+
const resourceMeta = (_a = state == null ? void 0 : state.iiif) == null ? void 0 : _a.meta[resourceId];
|
|
798
|
+
if (!resourceMeta) {
|
|
799
|
+
return null;
|
|
800
|
+
}
|
|
801
|
+
return resourceMeta.annotationPageManager;
|
|
802
|
+
}
|
|
803
|
+
function useAnnotationPageManager(resourceId, options = {}) {
|
|
804
|
+
const vault = useVault();
|
|
805
|
+
const manifest = useManifest();
|
|
806
|
+
const canvas = useCanvas();
|
|
807
|
+
const canvases = useVisibleCanvases();
|
|
808
|
+
const availablePageIds = useMemo(() => {
|
|
809
|
+
return flattenAnnotationPageIds({
|
|
810
|
+
all: options.all,
|
|
811
|
+
manifest,
|
|
812
|
+
canvas,
|
|
813
|
+
canvases
|
|
814
|
+
});
|
|
815
|
+
}, [options.all, canvas, canvases, manifest]);
|
|
816
|
+
const enabledPageIds = useEnabledAnnotationPageIds(resourceId, options.all ? void 0 : availablePageIds);
|
|
817
|
+
const setPageDisabled = useCallback((deselectId) => {
|
|
818
|
+
if (!resourceId) {
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
vault.setMetaValue([deselectId, "annotationPageManager", "views"], (existingResources) => {
|
|
822
|
+
if (existingResources && !existingResources[resourceId]) {
|
|
823
|
+
return existingResources;
|
|
824
|
+
}
|
|
825
|
+
return __spreadProps$2(__spreadValues$2({}, existingResources || {}), {
|
|
826
|
+
[resourceId]: false
|
|
827
|
+
});
|
|
828
|
+
});
|
|
829
|
+
}, [resourceId, vault]);
|
|
830
|
+
const setPageEnabled = useCallback((id, opt = {}) => {
|
|
831
|
+
if (!resourceId) {
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
const state = vault.getState();
|
|
835
|
+
const toDeselect = [];
|
|
836
|
+
if (opt == null ? void 0 : opt.deselectOthers) {
|
|
837
|
+
const allAnnotationListIds = Object.keys(state.iiif.entities.AnnotationPage);
|
|
838
|
+
for (const annotationPageId of allAnnotationListIds) {
|
|
839
|
+
const annotationListMeta = getMeta(state, annotationPageId);
|
|
840
|
+
if (annotationListMeta && annotationListMeta.views && annotationListMeta.views[resourceId]) {
|
|
841
|
+
toDeselect.push(annotationPageId);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
for (const deselectId of toDeselect) {
|
|
846
|
+
setPageDisabled(deselectId);
|
|
847
|
+
}
|
|
848
|
+
vault.setMetaValue([id, "annotationPageManager", "views"], (existingResources) => {
|
|
849
|
+
if (existingResources && existingResources[resourceId]) {
|
|
850
|
+
return existingResources;
|
|
851
|
+
}
|
|
852
|
+
return __spreadProps$2(__spreadValues$2({}, existingResources || {}), {
|
|
853
|
+
[resourceId]: true
|
|
854
|
+
});
|
|
855
|
+
});
|
|
856
|
+
}, [resourceId, setPageDisabled, vault]);
|
|
857
|
+
return {
|
|
858
|
+
availablePageIds,
|
|
859
|
+
enabledPageIds,
|
|
860
|
+
setPageEnabled,
|
|
861
|
+
setPageDisabled
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
function usePaintingAnnotations(options = {}) {
|
|
866
|
+
const canvas = useCanvas(options.canvasId ? { id: options.canvasId } : void 0);
|
|
867
|
+
return useVaultSelector((state, vault) => {
|
|
868
|
+
if (!canvas) {
|
|
869
|
+
return [];
|
|
870
|
+
}
|
|
871
|
+
const annotationPages = vault.get(canvas.items);
|
|
872
|
+
const flatAnnotations = [];
|
|
873
|
+
for (const page of annotationPages) {
|
|
874
|
+
flatAnnotations.push(...vault.get(page.items));
|
|
875
|
+
}
|
|
876
|
+
return flatAnnotations;
|
|
877
|
+
}, [canvas]);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
function useAnnotationsAtTime(time, options = {}) {
|
|
881
|
+
const allAnnotations = usePaintingAnnotations(options);
|
|
882
|
+
return allAnnotations;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
function useCanvasClock(canvasId, autoplay = false) {
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
function useCollection(options, deps = []) {
|
|
889
|
+
const { id, selector } = options;
|
|
890
|
+
const ctx = useResourceContext();
|
|
891
|
+
const collectionId = id ? id : ctx.collection;
|
|
892
|
+
const collection = useVaultSelector((s) => collectionId ? s.iiif.entities.Collection[collectionId] : void 0, [collectionId]);
|
|
893
|
+
return useMemo(() => {
|
|
894
|
+
if (!collection) {
|
|
895
|
+
return void 0;
|
|
896
|
+
}
|
|
897
|
+
if (selector) {
|
|
898
|
+
return selector(collection);
|
|
899
|
+
}
|
|
900
|
+
return collection;
|
|
901
|
+
}, [collection, selector, ...deps]);
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
function useDispatch() {
|
|
905
|
+
const vault = useVault();
|
|
906
|
+
const store = vault.getStore();
|
|
907
|
+
return useMemo(() => {
|
|
908
|
+
return (action) => store.dispatch(action);
|
|
909
|
+
}, [store]);
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
function useEventListener(resource, name, listener, scope, deps = []) {
|
|
913
|
+
const vault = useVault();
|
|
914
|
+
const helper = useMemo(() => createEventsHelper(vault), [vault]);
|
|
915
|
+
useEffect(() => {
|
|
916
|
+
const currentResource = resource;
|
|
917
|
+
if (!currentResource) {
|
|
918
|
+
return () => {
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
helper.addEventListener(currentResource, name, listener, scope);
|
|
922
|
+
return () => {
|
|
923
|
+
helper.removeEventListener(currentResource, name, listener);
|
|
924
|
+
};
|
|
925
|
+
}, [helper, resource, name, ...deps]);
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
function useExistingVault() {
|
|
929
|
+
const oldContext = useContext(ReactVaultContext);
|
|
930
|
+
return oldContext && oldContext.vault ? oldContext.vault : globalVault();
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
function useExternalCollection(idOrRef, options) {
|
|
934
|
+
const { id, isLoaded, error, resource, requestId, cached } = useExternalResource(idOrRef, options);
|
|
935
|
+
return { id, isLoaded, error, manifest: resource, requestId, cached };
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
var __async = (__this, __arguments, generator) => {
|
|
939
|
+
return new Promise((resolve, reject) => {
|
|
940
|
+
var fulfilled = (value) => {
|
|
941
|
+
try {
|
|
942
|
+
step(generator.next(value));
|
|
943
|
+
} catch (e) {
|
|
944
|
+
reject(e);
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
var rejected = (value) => {
|
|
948
|
+
try {
|
|
949
|
+
step(generator.throw(value));
|
|
950
|
+
} catch (e) {
|
|
951
|
+
reject(e);
|
|
952
|
+
}
|
|
953
|
+
};
|
|
954
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
955
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
956
|
+
});
|
|
957
|
+
};
|
|
958
|
+
function useImageService({ cacheKey } = {}) {
|
|
959
|
+
const canvas = useCanvas();
|
|
960
|
+
const annotations = usePaintingAnnotations();
|
|
961
|
+
const vault = useVault();
|
|
962
|
+
const imageService = useImageServiceLoader();
|
|
963
|
+
const [_data, setData] = useState(void 0);
|
|
964
|
+
const [isFetching, setIsFetching] = useState(false);
|
|
965
|
+
const [status, setStatus] = useState("idle");
|
|
966
|
+
const [error, setError] = useState(void 0);
|
|
967
|
+
const key = canvas ? canvas.id : "undefined";
|
|
968
|
+
const initialData = useMemo(() => {
|
|
969
|
+
try {
|
|
970
|
+
if (canvas && annotations.length) {
|
|
971
|
+
const annotation = annotations[0];
|
|
972
|
+
const resource = vault.get(annotation.body[0]);
|
|
973
|
+
const imageServices = getImageServices(resource);
|
|
974
|
+
const firstImageService = imageServices[0];
|
|
975
|
+
if (!firstImageService) {
|
|
976
|
+
return void 0;
|
|
977
|
+
}
|
|
978
|
+
return imageService.loadServiceSync({
|
|
979
|
+
id: firstImageService.id || firstImageService["@id"],
|
|
980
|
+
width: firstImageService.width || canvas.width,
|
|
981
|
+
height: firstImageService.height || canvas.height
|
|
982
|
+
}) || void 0;
|
|
983
|
+
}
|
|
984
|
+
} catch (e) {
|
|
985
|
+
console.error(e);
|
|
986
|
+
}
|
|
987
|
+
return void 0;
|
|
988
|
+
}, [key, cacheKey, canvas]);
|
|
989
|
+
const data = status === "success" && _data ? _data : initialData;
|
|
990
|
+
useEffect(() => {
|
|
991
|
+
(() => __async(this, null, function* () {
|
|
992
|
+
try {
|
|
993
|
+
if (canvas && annotations.length) {
|
|
994
|
+
const annotation = annotations[0];
|
|
995
|
+
const resource = vault.get(annotation.body[0]);
|
|
996
|
+
const imageServices = getImageServices(resource);
|
|
997
|
+
const firstImageService = imageServices[0];
|
|
998
|
+
if (!firstImageService) {
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
setIsFetching(true);
|
|
1002
|
+
setStatus("loading");
|
|
1003
|
+
try {
|
|
1004
|
+
const loadedService = (yield imageService.loadService({
|
|
1005
|
+
id: firstImageService.id || firstImageService["@id"],
|
|
1006
|
+
width: firstImageService.width || canvas.width,
|
|
1007
|
+
height: firstImageService.height || canvas.height
|
|
1008
|
+
})) || void 0;
|
|
1009
|
+
setData(loadedService);
|
|
1010
|
+
setStatus("success");
|
|
1011
|
+
setIsFetching(false);
|
|
1012
|
+
} catch (err) {
|
|
1013
|
+
setStatus("error");
|
|
1014
|
+
setError(err);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
} catch (err) {
|
|
1018
|
+
setStatus("error");
|
|
1019
|
+
setError(err);
|
|
1020
|
+
}
|
|
1021
|
+
}))();
|
|
1022
|
+
}, [key, cacheKey]);
|
|
1023
|
+
return useMemo(() => {
|
|
1024
|
+
return {
|
|
1025
|
+
data,
|
|
1026
|
+
isFetching,
|
|
1027
|
+
status,
|
|
1028
|
+
error
|
|
1029
|
+
};
|
|
1030
|
+
}, [data, isFetching, status, error]);
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
function useImageTile() {
|
|
1034
|
+
const imageService = useImageService();
|
|
1035
|
+
return {
|
|
1036
|
+
isLoading: imageService.isFetching,
|
|
1037
|
+
tile: imageService.data ? {
|
|
1038
|
+
id: imageService.data.id || imageService.data["@id"],
|
|
1039
|
+
width: imageService.data.width,
|
|
1040
|
+
height: imageService.data.height,
|
|
1041
|
+
imageService: imageService.data,
|
|
1042
|
+
thumbnail: void 0
|
|
1043
|
+
} : null
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
function usePaintables(options, deps = []) {
|
|
1048
|
+
const vault = useVault();
|
|
1049
|
+
const paintingAnnotations = usePaintingAnnotations();
|
|
1050
|
+
const [enabledChoices, setEnabledChoices] = useState((options == null ? void 0 : options.defaultChoices) || []);
|
|
1051
|
+
const paintables = useMemo(() => getPaintables(vault, paintingAnnotations, enabledChoices), [vault, paintingAnnotations, enabledChoices, ...deps]);
|
|
1052
|
+
const makeChoice = useCallback((id, { deselectOthers = true, deselect = false } = {}) => {
|
|
1053
|
+
if (paintables.choice) {
|
|
1054
|
+
if (paintables.choice.type !== "single-choice") {
|
|
1055
|
+
throw new Error("Complex choice not supported yet");
|
|
1056
|
+
}
|
|
1057
|
+
setEnabledChoices((prevChoices) => {
|
|
1058
|
+
if (deselect) {
|
|
1059
|
+
const without = prevChoices.filter((e) => e !== id);
|
|
1060
|
+
if (without.length === 0) {
|
|
1061
|
+
const defaultId = paintables.items[0].resource.id;
|
|
1062
|
+
if (defaultId) {
|
|
1063
|
+
return [defaultId];
|
|
1064
|
+
} else {
|
|
1065
|
+
return [];
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
return without;
|
|
1069
|
+
}
|
|
1070
|
+
if (deselectOthers) {
|
|
1071
|
+
return [id];
|
|
1072
|
+
}
|
|
1073
|
+
const newChoices = [...prevChoices];
|
|
1074
|
+
if (newChoices.length === 0 && paintables.items.length) {
|
|
1075
|
+
const defaultId = paintables.items[0].resource.id;
|
|
1076
|
+
if (defaultId) {
|
|
1077
|
+
newChoices.push(defaultId);
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
if (prevChoices.indexOf(id) !== -1) {
|
|
1081
|
+
return prevChoices;
|
|
1082
|
+
}
|
|
1083
|
+
return [...prevChoices, id];
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
}, [paintables.choice]);
|
|
1087
|
+
const actions = { makeChoice };
|
|
1088
|
+
return [paintables, actions];
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
function useRange(options = {}, deps = []) {
|
|
1092
|
+
const { id, selector } = options;
|
|
1093
|
+
const ctx = useResourceContext();
|
|
1094
|
+
const rangeId = id ? id : ctx.range;
|
|
1095
|
+
const range = useVaultSelector((s) => rangeId ? s.iiif.entities.Range[rangeId] : void 0, [rangeId]);
|
|
1096
|
+
return useMemo(() => {
|
|
1097
|
+
if (!range) {
|
|
1098
|
+
return void 0;
|
|
1099
|
+
}
|
|
1100
|
+
if (selector) {
|
|
1101
|
+
return selector(range);
|
|
1102
|
+
}
|
|
1103
|
+
return range;
|
|
1104
|
+
}, [range, selector, ...deps]);
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
function useResourceEvents(resource, scope) {
|
|
1108
|
+
const vault = useVault();
|
|
1109
|
+
const helper = useMemo(() => createEventsHelper(vault), [vault]);
|
|
1110
|
+
const hooks = useVaultSelector(() => {
|
|
1111
|
+
if (resource && resource.id) {
|
|
1112
|
+
return vault.getResourceMeta(resource.id, "eventManager");
|
|
1113
|
+
}
|
|
1114
|
+
return null;
|
|
1115
|
+
}, [resource]);
|
|
1116
|
+
return useMemo(() => {
|
|
1117
|
+
return resource ? helper.getListenersAsProps(resource, scope) : {};
|
|
1118
|
+
}, [hooks, resource, vault, scope]);
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
function useResources(ids, type) {
|
|
1122
|
+
return useVaultSelector((state, vault) => vault.get(ids.map((id) => ({ id, type }))), [ids, type]);
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
function useSearchService() {
|
|
1126
|
+
const manifest = useManifest();
|
|
1127
|
+
return manifest ? manifest.service.find((service) => service.profile === "SearchService1" || service.profile === "http://iiif.io/api/search/1/search") : void 0;
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
function useStyleHelper() {
|
|
1131
|
+
const vault = useVault();
|
|
1132
|
+
return useMemo(() => createStylesHelper(vault), [vault]);
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
function useStyles(resource, scope) {
|
|
1136
|
+
const vault = useVault();
|
|
1137
|
+
const helper = useMemo(() => createStylesHelper(vault), [vault]);
|
|
1138
|
+
return useVaultSelector(() => {
|
|
1139
|
+
if (!resource) {
|
|
1140
|
+
return null;
|
|
1141
|
+
}
|
|
1142
|
+
const styles = helper.getAppliedStyles(resource.id);
|
|
1143
|
+
return styles ? scope ? styles[scope] : styles : void 0;
|
|
1144
|
+
}, [resource, scope]);
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
const useVaultEffect = (callback, deps = []) => {
|
|
1148
|
+
const vault = useVault();
|
|
1149
|
+
useEffect(() => {
|
|
1150
|
+
callback(vault);
|
|
1151
|
+
}, [vault, ...deps]);
|
|
1152
|
+
};
|
|
1153
|
+
|
|
1154
|
+
function useThumbnail(request, dereference, { canvasId, manifestId } = {}) {
|
|
1155
|
+
const vault = useVault();
|
|
1156
|
+
const loader = useImageServiceLoader();
|
|
1157
|
+
const helper = useMemo(() => createThumbnailHelper(vault, { imageServiceLoader: loader }), [vault, loader]);
|
|
1158
|
+
const [thumbnail, setThumbnail] = useState();
|
|
1159
|
+
const manifest = useManifest(manifestId ? { id: manifestId } : void 0);
|
|
1160
|
+
const canvas = useCanvas(canvasId ? { id: canvasId } : void 0);
|
|
1161
|
+
const subject = canvas ? canvas : manifest;
|
|
1162
|
+
const didUnmount = useRef(false);
|
|
1163
|
+
useEffect(() => {
|
|
1164
|
+
return () => {
|
|
1165
|
+
didUnmount.current = true;
|
|
1166
|
+
};
|
|
1167
|
+
}, []);
|
|
1168
|
+
if (!subject) {
|
|
1169
|
+
throw new Error("Must be called under a manifest or canvas context.");
|
|
1170
|
+
}
|
|
1171
|
+
useVaultEffect((v) => {
|
|
1172
|
+
helper.getBestThumbnailAtSize(subject, request, dereference).then((thumb) => {
|
|
1173
|
+
if (thumb.best && !didUnmount.current) {
|
|
1174
|
+
setThumbnail(thumb.best);
|
|
1175
|
+
}
|
|
1176
|
+
});
|
|
1177
|
+
}, [subject]);
|
|
1178
|
+
return thumbnail;
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
var __defProp$1 = Object.defineProperty;
|
|
1182
|
+
var __defProps$1 = Object.defineProperties;
|
|
1183
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
1184
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
1185
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
1186
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
1187
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1188
|
+
var __spreadValues$1 = (a, b) => {
|
|
1189
|
+
for (var prop in b || (b = {}))
|
|
1190
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
1191
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
1192
|
+
if (__getOwnPropSymbols$1)
|
|
1193
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
1194
|
+
if (__propIsEnum$1.call(b, prop))
|
|
1195
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
1196
|
+
}
|
|
1197
|
+
return a;
|
|
1198
|
+
};
|
|
1199
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
1200
|
+
function useLoadImageService() {
|
|
1201
|
+
const loader = useImageServiceLoader();
|
|
1202
|
+
const [imageServiceStatus, setImageServiceStatus] = useState({});
|
|
1203
|
+
const didUnmount = useRef(false);
|
|
1204
|
+
useEffect(() => {
|
|
1205
|
+
return () => {
|
|
1206
|
+
didUnmount.current = true;
|
|
1207
|
+
};
|
|
1208
|
+
}, []);
|
|
1209
|
+
const loadImageService = useCallback((imageService, { height, width }) => {
|
|
1210
|
+
if (imageService) {
|
|
1211
|
+
const imageServiceId = imageService.id || imageService["@id"];
|
|
1212
|
+
const syncLoaded = loader.loadServiceSync({
|
|
1213
|
+
id: imageServiceId,
|
|
1214
|
+
width: imageService.width || width,
|
|
1215
|
+
height: imageService.height || height
|
|
1216
|
+
});
|
|
1217
|
+
if (syncLoaded) {
|
|
1218
|
+
imageService = syncLoaded;
|
|
1219
|
+
} else if (!imageServiceStatus[imageServiceId]) {
|
|
1220
|
+
if (!didUnmount.current) {
|
|
1221
|
+
setImageServiceStatus((r) => {
|
|
1222
|
+
return __spreadProps$1(__spreadValues$1({}, r), {
|
|
1223
|
+
[imageServiceId]: "loading"
|
|
1224
|
+
});
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
loader.loadService({
|
|
1228
|
+
id: imageServiceId,
|
|
1229
|
+
width: imageService.width || width,
|
|
1230
|
+
height: imageService.height || height
|
|
1231
|
+
}).then(() => {
|
|
1232
|
+
if (!didUnmount.current) {
|
|
1233
|
+
setImageServiceStatus((r) => {
|
|
1234
|
+
return __spreadProps$1(__spreadValues$1({}, r), {
|
|
1235
|
+
[imageServiceId]: "done"
|
|
1236
|
+
});
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
});
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
return imageService;
|
|
1243
|
+
}, [loader, imageServiceStatus]);
|
|
1244
|
+
return [loadImageService, imageServiceStatus];
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
const IMPORT_ENTITIES = "@iiif/IMPORT_ENTITIES";
|
|
1248
|
+
const MODIFY_ENTITY_FIELD = "@iiif/MODIFY_ENTITY_FIELD";
|
|
1249
|
+
const REORDER_ENTITY_FIELD = "@iiif/REORDER_ENTITY_FIELD";
|
|
1250
|
+
const ADD_REFERENCE = "@iiif/ADD_REFERENCE";
|
|
1251
|
+
const REMOVE_REFERENCE = "@iiif/REMOVE_REFERENCE";
|
|
1252
|
+
const importEntities = createAction(IMPORT_ENTITIES)();
|
|
1253
|
+
const modifyEntityField = createAction(MODIFY_ENTITY_FIELD)();
|
|
1254
|
+
const reorderEntityField = createAction(REORDER_ENTITY_FIELD)();
|
|
1255
|
+
const addReference = createAction(ADD_REFERENCE)();
|
|
1256
|
+
const removeReference = createAction(REMOVE_REFERENCE)();
|
|
1257
|
+
const entityActions = { importEntities, modifyEntityField, reorderEntityField, addReference, removeReference };
|
|
1258
|
+
|
|
1259
|
+
const ADD_MAPPING = "@iiif/ADD_MAPPING";
|
|
1260
|
+
const ADD_MAPPINGS = "@iiif/ADD_MAPPINGS";
|
|
1261
|
+
createAction(ADD_MAPPING)();
|
|
1262
|
+
createAction(ADD_MAPPINGS)();
|
|
1263
|
+
|
|
1264
|
+
const SET_META_VALUE = "@iiif/SET_META_VALUE";
|
|
1265
|
+
const SET_META_VALUE_DYNAMIC = "@iiif/SET_META_VALUE_DYNAMIC";
|
|
1266
|
+
const UNSET_META_VALUE = "@iiif/UNSET_META_VALUE";
|
|
1267
|
+
createAction(SET_META_VALUE)();
|
|
1268
|
+
createAction(SET_META_VALUE_DYNAMIC)();
|
|
1269
|
+
createAction(UNSET_META_VALUE)();
|
|
1270
|
+
const REQUEST_RESOURCE = "@iiif/REQUEST_RESOURCE";
|
|
1271
|
+
const REQUEST_ERROR = "@iiif/REQUEST_ERROR";
|
|
1272
|
+
const REQUEST_MISMATCH = "@iiif/REQUEST_MISMATCH";
|
|
1273
|
+
const REQUEST_COMPLETE = "@iiif/REQUEST_COMPLETE";
|
|
1274
|
+
const REQUEST_OFFLINE_RESOURCE = "@iiif/REQUEST_OFFLINE_RESOURCE";
|
|
1275
|
+
createAction(REQUEST_RESOURCE)();
|
|
1276
|
+
createAction(REQUEST_ERROR)();
|
|
1277
|
+
createAction(REQUEST_MISMATCH)();
|
|
1278
|
+
createAction(REQUEST_COMPLETE)();
|
|
1279
|
+
createAction(REQUEST_OFFLINE_RESOURCE)();
|
|
1280
|
+
|
|
1281
|
+
const BATCH_ACTIONS = "@iiif/BATCH";
|
|
1282
|
+
const BATCH_IMPORT = "@iiif/BATCH_IMPORT";
|
|
1283
|
+
createAction(BATCH_ACTIONS)();
|
|
1284
|
+
createAction(BATCH_IMPORT)();
|
|
1285
|
+
|
|
1286
|
+
function isVaultActivated(obj) {
|
|
1287
|
+
return typeof obj !== "string" && obj && obj.bindToVault;
|
|
1288
|
+
}
|
|
1289
|
+
function useVirtualAnnotationPage() {
|
|
1290
|
+
const vault = useVault();
|
|
1291
|
+
const sources = useRef([]);
|
|
1292
|
+
const dispatch = useDispatch();
|
|
1293
|
+
const virtualId = useMemo(() => {
|
|
1294
|
+
return `vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random() * 1e9).toString(16)}`;
|
|
1295
|
+
}, []);
|
|
1296
|
+
useLayoutEffect(() => {
|
|
1297
|
+
const page = {
|
|
1298
|
+
id: virtualId,
|
|
1299
|
+
type: "AnnotationPage",
|
|
1300
|
+
behavior: [],
|
|
1301
|
+
motivation: null,
|
|
1302
|
+
label: null,
|
|
1303
|
+
thumbnail: [],
|
|
1304
|
+
summary: null,
|
|
1305
|
+
requiredStatement: null,
|
|
1306
|
+
metadata: [],
|
|
1307
|
+
rights: null,
|
|
1308
|
+
provider: [],
|
|
1309
|
+
items: [],
|
|
1310
|
+
seeAlso: [],
|
|
1311
|
+
homepage: [],
|
|
1312
|
+
logo: [],
|
|
1313
|
+
rendering: [],
|
|
1314
|
+
service: []
|
|
1315
|
+
};
|
|
1316
|
+
dispatch(entityActions.importEntities({
|
|
1317
|
+
entities: {
|
|
1318
|
+
AnnotationPage: {
|
|
1319
|
+
[page.id]: page
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
}));
|
|
1323
|
+
}, [virtualId]);
|
|
1324
|
+
const fullPage = useVaultSelector((state) => virtualId ? state.iiif.entities.AnnotationPage[virtualId] : null, [virtualId]);
|
|
1325
|
+
const addAnnotation = useCallback((id, atIndex) => {
|
|
1326
|
+
if (virtualId) {
|
|
1327
|
+
if (isVaultActivated(id)) {
|
|
1328
|
+
const display = id;
|
|
1329
|
+
if (!display.__vault) {
|
|
1330
|
+
display.bindToVault(vault);
|
|
1331
|
+
}
|
|
1332
|
+
id = typeof display.source === "string" ? display.source : display.source.id;
|
|
1333
|
+
sources.current[id] = display;
|
|
1334
|
+
} else if (typeof id !== "string") {
|
|
1335
|
+
id = id.id;
|
|
1336
|
+
}
|
|
1337
|
+
const full = vault.get({ id: virtualId, type: "AnnotationPage" });
|
|
1338
|
+
const annotation = vault.get({ id, type: "Annotation" });
|
|
1339
|
+
if (full && annotation) {
|
|
1340
|
+
if (!full.items.find((r) => r.id === annotation.id)) {
|
|
1341
|
+
dispatch(entityActions.addReference({
|
|
1342
|
+
id: virtualId,
|
|
1343
|
+
type: "AnnotationPage",
|
|
1344
|
+
key: "items",
|
|
1345
|
+
reference: {
|
|
1346
|
+
id,
|
|
1347
|
+
type: "Annotation"
|
|
1348
|
+
},
|
|
1349
|
+
index: atIndex
|
|
1350
|
+
}));
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
}, [virtualId]);
|
|
1355
|
+
const removeAnnotation = useCallback((id) => {
|
|
1356
|
+
if (virtualId) {
|
|
1357
|
+
if (isVaultActivated(id)) {
|
|
1358
|
+
id = typeof id.source === "string" ? id.source : id.source.id;
|
|
1359
|
+
} else if (typeof id !== "string") {
|
|
1360
|
+
id = id.id;
|
|
1361
|
+
}
|
|
1362
|
+
if (sources.current[id]) {
|
|
1363
|
+
sources.current[id].beforeRemove();
|
|
1364
|
+
}
|
|
1365
|
+
const full = vault.get({ id: virtualId, type: "AnnotationPage" });
|
|
1366
|
+
if (full) {
|
|
1367
|
+
dispatch(entityActions.removeReference({
|
|
1368
|
+
id: virtualId,
|
|
1369
|
+
type: "AnnotationPage",
|
|
1370
|
+
key: "items",
|
|
1371
|
+
reference: {
|
|
1372
|
+
id,
|
|
1373
|
+
type: "Annotation"
|
|
1374
|
+
}
|
|
1375
|
+
}));
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
}, [virtualId]);
|
|
1379
|
+
return [
|
|
1380
|
+
fullPage,
|
|
1381
|
+
{
|
|
1382
|
+
addAnnotation,
|
|
1383
|
+
removeAnnotation
|
|
1384
|
+
}
|
|
1385
|
+
];
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
var __defProp = Object.defineProperty;
|
|
1389
|
+
var __defProps = Object.defineProperties;
|
|
1390
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
1391
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
1392
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1393
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
1394
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1395
|
+
var __spreadValues = (a, b) => {
|
|
1396
|
+
for (var prop in b || (b = {}))
|
|
1397
|
+
if (__hasOwnProp.call(b, prop))
|
|
1398
|
+
__defNormalProp(a, prop, b[prop]);
|
|
1399
|
+
if (__getOwnPropSymbols)
|
|
1400
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
1401
|
+
if (__propIsEnum.call(b, prop))
|
|
1402
|
+
__defNormalProp(a, prop, b[prop]);
|
|
1403
|
+
}
|
|
1404
|
+
return a;
|
|
1405
|
+
};
|
|
1406
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1407
|
+
function useRenderingStrategy(options) {
|
|
1408
|
+
const manifest = useManifest();
|
|
1409
|
+
const canvas = useCanvas();
|
|
1410
|
+
const vault = useVault();
|
|
1411
|
+
const [loadImageService, imageServiceStatus] = useLoadImageService();
|
|
1412
|
+
const { enabledPageIds } = useAnnotationPageManager((options == null ? void 0 : options.annotationPageManagerId) || (manifest == null ? void 0 : manifest.id) || (canvas == null ? void 0 : canvas.id), {
|
|
1413
|
+
all: false
|
|
1414
|
+
});
|
|
1415
|
+
const enabledPages = useResources(enabledPageIds, "AnnotationPage");
|
|
1416
|
+
const supports = (options == null ? void 0 : options.strategies) || ["images", "media", "complex-timeline"];
|
|
1417
|
+
const [paintables, actions] = usePaintables(options, [imageServiceStatus]);
|
|
1418
|
+
const strategy = useMemo(() => {
|
|
1419
|
+
if (!canvas || paintables.types.length === 0) {
|
|
1420
|
+
return unknownResponse;
|
|
1421
|
+
}
|
|
1422
|
+
if (paintables.types.length !== 1) {
|
|
1423
|
+
if (supports.indexOf("complex-timeline") === -1) {
|
|
1424
|
+
return unsupportedStrategy("Complex timeline not supported");
|
|
1425
|
+
}
|
|
1426
|
+
return unsupportedStrategy("ComplexTimelineStrategy not yet supported");
|
|
1427
|
+
}
|
|
1428
|
+
const mainType = paintables.types[0];
|
|
1429
|
+
if (mainType === "image") {
|
|
1430
|
+
if (supports.indexOf("images") === -1) {
|
|
1431
|
+
return unsupportedStrategy("Image not supported");
|
|
1432
|
+
}
|
|
1433
|
+
return getImageStrategy(canvas, paintables, loadImageService);
|
|
1434
|
+
}
|
|
1435
|
+
if (mainType === "audio") {
|
|
1436
|
+
if (supports.indexOf("media") === -1) {
|
|
1437
|
+
return unsupportedStrategy("Media not supported");
|
|
1438
|
+
}
|
|
1439
|
+
return unsupportedStrategy("Audio strategy not yet supported");
|
|
1440
|
+
}
|
|
1441
|
+
if (mainType === "video") {
|
|
1442
|
+
if (supports.indexOf("media") === -1) {
|
|
1443
|
+
return unsupportedStrategy("Media not supported");
|
|
1444
|
+
}
|
|
1445
|
+
return unsupportedStrategy("Video strategy not yet supported");
|
|
1446
|
+
}
|
|
1447
|
+
return unknownResponse;
|
|
1448
|
+
}, [canvas, paintables, vault, actions.makeChoice]);
|
|
1449
|
+
return useMemo(() => {
|
|
1450
|
+
if (strategy.type === "unknown") {
|
|
1451
|
+
return [strategy, emptyActions];
|
|
1452
|
+
}
|
|
1453
|
+
return [
|
|
1454
|
+
__spreadProps(__spreadValues({}, strategy), {
|
|
1455
|
+
annotations: { pages: enabledPages }
|
|
1456
|
+
}),
|
|
1457
|
+
actions
|
|
1458
|
+
];
|
|
1459
|
+
}, [strategy, enabledPages]);
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
export { AnnotationContext, CanvasContext, CollectionContext, ContextBridge, ImageServiceLoaderContext, ManifestContext, RangeContext, ReactVaultContext, ResourceProvider, ResourceReactContext, SimpleViewerProvider, SimpleViewerReactContext, VaultProvider, VisibleCanvasReactContext, emptyActions, expandTarget, flattenAnnotationPageIds, getImageStrategy, getPaintables, parseSelector, parseSpecificResource, unknownResponse, unsupportedStrategy, useAnnotation, useAnnotationPageManager, useAnnotationsAtTime, useCanvas, useCanvasClock, useCollection, useContextBridge, useDispatch, useEventListener, useExistingVault, useExternalCollection, useExternalManifest, useExternalResource, useImageService, useImageServiceLoader, useImageTile, useLoadImageService, useManifest, usePaintables, usePaintingAnnotations, useRange, useRenderingStrategy, useResourceContext, useResourceEvents, useResources, useSearchService, useSimpleViewer, useStyleHelper, useStyles, useThumbnail, useVault, useVaultEffect, useVaultSelector, useVirtualAnnotationPage, useVisibleCanvases };
|