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/index.umd.js
CHANGED
|
@@ -1,4 +1,921 @@
|
|
|
1
|
-
(function(g,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("react"),require("@iiif/vault")):typeof define=="function"&&define.amd?define(["exports","react","@iiif/vault"],h):(g=typeof globalThis<"u"?globalThis:g||self,h(g.ReactIIIFVault={},g.React,g.IIIFVault))})(this,function(g,h,K){"use strict";function Kt(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var A=Kt(h),ei=Object.defineProperty,de=Object.getOwnPropertySymbols,ti=Object.prototype.hasOwnProperty,ii=Object.prototype.propertyIsEnumerable,pe=(e,t,i)=>t in e?ei(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,ge=(e,t)=>{for(var i in t||(t={}))ti.call(t,i)&&pe(e,i,t[i]);if(de)for(var i of de(t))ii.call(t,i)&&pe(e,i,t[i]);return e};const ni={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},ee=A.default.createContext(ni),k=()=>h.useContext(ee),V=({value:e,children:t})=>{const i=k(),n=h.useMemo(()=>ge(ge({},i),e),[e,i]);return A.default.createElement(ee.Provider,{value:n},t)},ri=({annotation:e,children:t})=>A.default.createElement(V,{value:{annotation:e}},t),me=({canvas:e,children:t})=>A.default.createElement(V,{value:{canvas:e}},t),oi=({collection:e,children:t})=>A.default.createElement(V,{value:{collection:e}},t),ve=({manifest:e,children:t})=>A.default.createElement(V,{value:{manifest:e}},t),si=({range:e,children:t})=>A.default.createElement(V,{value:{range:e}},t),U=A.default.createContext({vault:null,setVaultInstance:e=>{}}),ye=({vault:e,vaultOptions:t,useGlobal:i,resources:n,children:o})=>{const[r,s]=h.useState(()=>e||(i?K.globalVault(t):t?new K.Vault(t):new K.Vault));return A.default.createElement(U.Provider,{value:{vault:r,setVaultInstance:s}},A.default.createElement(V,{value:n||{}},o))},I=()=>{const{vault:e}=h.useContext(U);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var ai=(e,t,i)=>new Promise((n,o)=>{var r=l=>{try{a(i.next(l))}catch(c){o(c)}},s=l=>{try{a(i.throw(l))}catch(c){o(c)}},a=l=>l.done?n(l.value):Promise.resolve(l.value).then(r,s);a((i=i.apply(e,t)).next())});function oe(e,{noCache:t=!1}={}){const i=typeof e=="string"?e:e.id,n=I(),[o,r]=h.useState(i),[s,a]=h.useState(void 0),l=h.useMemo(()=>n.get(i,{skipSelfReturn:!0})||void 0,[i,n]),[c,u]=h.useState(l);return h.useEffect(()=>{ai(this,null,function*(){try{const d=l&&!t?l:yield n.load(i),v=d?d.id||d["@id"]:null;d&&o!==v&&r(v),u(d)}catch(d){a(d)}})},[i,t]),{isLoaded:!!c,id:o,requestId:i,error:s,resource:c,cached:!!(c&&c===l)}}function we(e,t){const{id:i,isLoaded:n,error:o,resource:r,requestId:s,cached:a}=oe(e,t);return{id:i,isLoaded:n,error:o,manifest:r,requestId:s,cached:a}}function $(e,t=[]){const i=I(),[n,o]=h.useState(()=>e(i.getState(),i));return h.useEffect(()=>i.subscribe(r=>e(r,i),r=>{o(r)},!1),t),n}const Q=A.default.createContext([]);function xe(){const e=h.useContext(Q);return $(t=>e.map(i=>t.iiif.entities.Canvas[i]).filter(Boolean),[e])}const te=()=>{},Y=h.createContext({setCurrentCanvasId:te,setCurrentCanvasIndex:te,nextCanvas:te,previousCanvas:te,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),li=e=>{const t=we(e.manifest),[i,n]=h.useState(""),[o,r]=h.useState([]),s=(typeof e.pagingEnabled>"u"||e.pagingEnabled)&&t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");h.useEffect(()=>{var p,w;t.manifest&&(n((p=t.manifest.items[0])==null?void 0:p.id),r([(w=t.manifest.items[0])==null?void 0:w.id]))},[t.manifest,e.manifest]);const a=h.useMemo(()=>{var p;return((p=t.manifest)==null?void 0:p.items.map(w=>w.id))||[]},[t.manifest,e.manifest]),l=h.useMemo(()=>a.indexOf(i),[a,i]),c=h.useCallback(()=>{if(a.length&&i){if(l===-1||(a[l+2]?l+2===a.length:l===a.length))return;const p=s&&l!==0?a[l+2]:a[l+1],w=s?l!==0?a[l+3]:a[l+2]:null;p&&(n(p),r(w?[p,w]:[p]))}},[s,a,i,l]),u=h.useCallback(()=>{if(a.length&&i){if(l===0||l===-1)return;const p=s&&l!==1?a[l-2]:a[l-1],w=s&&l!==1?a[l-1]:null;p&&(n(p),r(w?[p,w]:[p]))}},[s,a,i,l]),d=h.useCallback(p=>{const w=s&&p%2===1?p-1:p,C=a[w],F=s&&w!==0?a[w+1]:null;C&&(n(C),r(f=>{const y=F?[C,F]:[C];if(f.length===f.length){for(let x=0;x<f.length;x++)if(f[x]!==y[x])return y;return f}return y}))},[s,a]),v=h.useCallback(p=>{const w=a.indexOf(p);w!==-1&&d(w)},[a,d]),m=h.useMemo(()=>({setCurrentCanvasId:v,nextCanvas:c,previousCanvas:u,currentCanvasIndex:l,totalCanvases:a.length,setCurrentCanvasIndex:d,pagingView:!0}),[c,u,l,a,d,v]);return t.manifest?t.isLoaded?A.default.createElement(Y.Provider,{value:m},A.default.createElement(Q.Provider,{value:o},A.default.createElement(ve,{manifest:t.manifest.id},A.default.createElement(me,{canvas:i},e.children)))):A.default.createElement("div",null,"Loading..."):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),A.default.createElement("div",null,"Sorry, something went wrong."))};function ci(){return h.useContext(Y)}function ui(){return{VaultContext:h.useContext(U),ResourceContext:h.useContext(ee),SimpleViewerReactContext:h.useContext(Y),VisibleCanvasReactContext:h.useContext(Q)}}const fi=e=>A.default.createElement(ye,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},A.default.createElement(Q.Provider,{value:e.bridge.VisibleCanvasReactContext},A.default.createElement(Y.Provider,{value:e.bridge.SimpleViewerReactContext},e.children)));function W(e){return e.endsWith("info.json")?e:e.endsWith("/")?`${e}info.json`:`${e}/info.json`}const hi="http://library.stanford.edu/iiif/image-api/compliance.html#level0",Se="http://library.stanford.edu/iiif/image-api/compliance.html#level1",be="http://library.stanford.edu/iiif/image-api/compliance.html#level2",di="http://library.stanford.edu/iiif/image-api/conformance.html#level0",Oe="http://library.stanford.edu/iiif/image-api/conformance.html#level1",Ae="http://library.stanford.edu/iiif/image-api/conformance.html#level2",pi="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Ce="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Pe="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",gi="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",_e="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Ie="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",mi="http://iiif.io/api/image/1/level0.json",vi="http://iiif.io/api/image/1/profiles/level0.json",Ee="http://iiif.io/api/image/1/level1.json",$e="http://iiif.io/api/image/1/profiles/level1.json",je="http://iiif.io/api/image/1/level2.json",Me="http://iiif.io/api/image/1/profiles/level2.json",yi="http://iiif.io/api/image/2/level0.json",wi="http://iiif.io/api/image/2/profiles/level0.json",Te="http://iiif.io/api/image/2/level1.json",Fe="http://iiif.io/api/image/2/profiles/level1.json",ke="http://iiif.io/api/image/2/level2.json",Ve="http://iiif.io/api/image/2/profiles/level2.json",xi="level0",We="level1",Le="level2",Si="http://iiif.io/api/image/2/level0",ze="http://iiif.io/api/image/2/level1",Re="http://iiif.io/api/image/2/level2",Be=[Re,be,Ae,Pe,Ie,je,Me,ke,Ve,Le],He=[...Be,ze,Se,Oe,Ce,_e,Ee,$e,Te,Fe,We],bi=[Si,ze,Re,hi,Se,be,di,Oe,Ae,pi,Ce,Pe,gi,_e,Ie,mi,vi,Ee,$e,je,Me,yi,wi,Te,Fe,ke,Ve,xi,We,Le],Oi={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},Ai={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},Ci={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function Pi(e){return Be.indexOf(e)!==-1?Ci:He.indexOf(e)!==-1?Ai:Oi}function _i(e){const t=e?Array.isArray(e.profile)?e.profile:[e.profile]:[],i={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let n of t)if(typeof n=="string"&&(n=Pi(n)),!!n){if(n.formats)for(const o of n.formats)i.extraFormats.indexOf(o)===-1&&i.extraFormats.push(o);if(n.qualities)for(const o of n.qualities)i.extraQualities.indexOf(o)===-1&&i.extraQualities.push(o);if(n.supports)for(const o of n.supports)i.extraFeatures.indexOf(o)===-1&&i.extraFeatures.push(o);if(n.maxHeight&&(i.maxHeight=n.maxHeight),n.maxWidth&&(i.maxWidth=n.maxWidth),n.maxArea&&(i.maxArea=n.maxArea),n.extraFormats)for(const o of n.extraFormats)i.extraFormats.indexOf(o)===-1&&i.extraFormats.push(o);if(n.extraQualities)for(const o of n.extraQualities)i.extraQualities.indexOf(o)===-1&&i.extraQualities.push(o);if(n.extraFeatures)for(const o of n.extraFeatures)i.extraFeatures.indexOf(o)===-1&&i.extraFeatures.push(o);n.maxHeight&&(i.maxHeight=n.maxHeight),n.maxWidth&&(i.maxWidth=n.maxWidth),n.maxArea&&(i.maxArea=n.maxArea)}if(e.extraFormats)for(const n of e.extraFormats)i.extraFormats.indexOf(n)===-1&&i.extraFormats.push(n);if(e.extraFeatures)for(const n of e.extraFeatures)i.extraFeatures.indexOf(n)===-1&&i.extraFeatures.push(n);if(e.extraQualities)for(const n of e.extraQualities)i.extraQualities.indexOf(n)===-1&&i.extraQualities.push(n);return i}function Ii(e){try{if(e==="full")return{full:!0};if(e==="square")return{square:!0};const t=e.startsWith("pct:"),i=e.substr(t?4:0).split(",").map(n=>parseFloat(n));return{x:i[0],y:i[1],w:i[2],h:i[3],percent:t}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+e)}}function Ei(e){const t={upscaled:!1,max:!1,confined:!1};if(e[0]==="^"&&(t.upscaled=!0,e=e.slice(1)),e==="max"||e==="full")return t.max=!0,t.serialiseAsFull=e==="full",t;if(e[0]==="!"&&(t.confined=!0,e=e.slice(1)),e[0]==="p")return t.percentScale=parseFloat(e.slice(4)),t;const i=e.split(",").map(n=>n.trim());return i.length&&(i[0]!==""&&(t.width=parseInt(i[0],10)),i[1]!==""&&(t.height=parseInt(i[1],10))),t}function $i(e){const t={angle:0};if(e[0]==="!"&&(t.mirror=!0,e=e.substr(1)),t.angle=parseFloat(e)%360,Number.isNaN(t.angle))throw new Error(`Invalid rotation ${e}`);return t}function ji(e,t=""){const i=e.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!i)throw new Error(`Invalid or unknown input ${e}`);const n=i[2],o=i[3];let r=i[4];if(r[0]==="/"&&(r=r.substr(1)),t.length>0){if(t[0]==="/"&&(t=t.substr(1)),t!==r.substr(0,t.length))throw new Error(`Path does not start with prefix (path: ${r}, prefix: ${t})`);r=r.substr(t.length)}return{scheme:n,server:o,path:r,prefix:t}}function Mi(e,t=""){const{path:i,scheme:n,server:o,prefix:r}=ji(e,t),s=i.split("/").reverse(),[a,l,c,u,...d]=s,v=d.reverse().filter(Boolean).join("/");if(s.length===1||a==="")return{type:"base",scheme:n,server:o,prefix:r,identifier:v};if(a==="info.json"){const[,...p]=s;return{type:"info",scheme:n,server:o,prefix:r,identifier:p.reverse().filter(Boolean).join("/")}}const m=a.split(".");return{type:"image",scheme:n,server:o,prefix:r,identifier:v,originalPath:i,region:Ii(u),size:Ei(c),rotation:$i(l),quality:m[0],format:m[1]}}function Ti(e){const t=Mi(W(e.id));if(t.type!=="info")throw new Error("Invalid service URL");const i=_i(e);return{identifier:t.identifier,originalPath:"",server:t.server,prefix:t.prefix,scheme:t.scheme,type:"image",quality:i.extraQualities.indexOf("default")===-1?i.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}}function Fi(e,t,i){const n=i.length,o=[];for(let r=0;r<n;r++){const s=i[r].width;o.push(e/s)}return o}function ki(e,t,i){const n=i.length,o=[];for(let r=0;r<n;r++){const s=i[r];o.push({width:Math.floor(e/s),height:Math.floor(t/s)})}return o}function S(e){if(e["@id"])return e["@id"];if(e.id)return e.id}function se(e){if(!e||!e.profile||!S(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if(typeof i=="string"&&bi.indexOf(i)!==-1)return!0;return!1}function Vi(e){if(!se(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if(typeof i=="string"){if(He.indexOf(i)!==-1)return!0}else{const n=[...i.supports||[],...i.extraFeatures||[]];if(n.indexOf("regionByPx")!==-1&&(n.indexOf("sizeByW")!==-1||n.indexOf("sizeByWh")!==-1))return!0}return!1}function Wi(e){if(!Vi(e))return[];const t=[],i=Array.isArray(e.profile)?e.profile:[e.profile],n=i.length;for(let o=0;o<n;o++){const r=i[o];if(typeof r!="string"&&(r.maxHeight||r.maxWidth))return[{id:S(e),type:"variable",minWidth:0,minHeight:0,maxHeight:r.maxHeight||r.maxWidth,maxWidth:r.maxWidth||r.maxHeight}]}if(e.tiles){const o=e.tiles.length;for(let r=0;r<o;r++){const s=e.tiles[r];(s.height||s.width)&&t.push({id:S(e),type:"variable",minHeight:0,minWidth:0,maxHeight:s.height||s.width,maxWidth:s.width})}}return t}function De(e){const t=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,i=e.match(t);if(i){const n=i[1],o=parseInt(i[4],10),r=parseInt(i[5],10),s=i[7];if((n==="max"||n==="full")&&o&&r&&s)return{type:"fixed",id:e,height:r,width:o}}return{type:"unknown",id:e}}function Li(e){if(e["@type"])return e["@type"];if(e.type)return e.type}function zi(e){if(typeof e=="string")return De(e);const t=Li(e);if(t!=="Image"&&t!=="sc:Image")return null;const i=e,n=S(i);return n?n&&i.width&&i.height?{id:n,type:"fixed",width:i.width,height:i.height,unsafe:!0}:De(n):null}function Ri(e){return se(e)?(e&&e.sizes?e.sizes:[]).map(t=>({id:S(e),type:"fixed-service",height:t.height,width:t.width})):[]}function qe(e){const t=[],i=e.length;for(let n=0;n<i;n++){const o=Ri(e[n]);o.length&&t.push(...o);const r=Wi(e[n]);r.length&&t.push(...r)}return t}function G(e){const t=e.service?Array.isArray(e.service)?e.service:[e.service]:[],i=t.length,n=[];for(let o=0;o<i;o++)se(t[o])&&n.push(t[o]);return n}function Bi(e,t=!0,i){const n=[],o=zi(e);if(o===null)return n;const r=e;if(n.push(o),t&&r.width&&r.height){const s=[],a=G(r);for(const l of a){const c={id:S(l),width:r.width,height:r.height};if(i.canLoadSync(c)){const u=i.loadServiceSync(c);u&&(u.height||(u.height=r.height),u.width||(u.width=r.width),s.push(...qe([u])))}}if(s.length)return n.push(...s),n}return r.service&&n.push(...qe(r.service)),n}function Hi({x:e=0,y:t=0,w:i,h:n,full:o,square:r,percent:s}){if(o)return"full";if(r)return"square";if(typeof i>"u"||typeof n>"u")throw new Error("RegionParameter: invalid region");const a=`${e},${t},${i},${n}`;return s?`pct:${a}`:a}function Di({max:e,percentScale:t,upscaled:i,confined:n,width:o,height:r,serialiseAsFull:s}){const a=[];return i&&a.push("^"),e?(a.push(s?"full":"max"),a.join("")):(n&&a.push("!"),t&&a.push(`pct:${t}`),o&&a.push(`${o}`),a.push(","),r&&a.push(`${r}`),a.join(""))}function qi(e){return`${e.mirror?"!":""}${(e.angle||0)%360}`}var Ni=Object.defineProperty,Ui=Object.defineProperties,Qi=Object.getOwnPropertyDescriptors,Ne=Object.getOwnPropertySymbols,Yi=Object.prototype.hasOwnProperty,Gi=Object.prototype.propertyIsEnumerable,Ue=(e,t,i)=>t in e?Ni(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Z=(e,t)=>{for(var i in t||(t={}))Yi.call(t,i)&&Ue(e,i,t[i]);if(Ne)for(var i of Ne(t))Gi.call(t,i)&&Ue(e,i,t[i]);return e},J=(e,t)=>Ui(e,Qi(t));function Zi(e,t){const i=e.prefix.startsWith("/")?e.prefix.substr(1):e.prefix,n=`${e.scheme}://${e.server}/${i?`${i}/`:""}${e.identifier}`;if(e.type==="base")return n;if(e.type==="info")return`${n}/info.json`;let{region:o,size:r,rotation:s,format:a,quality:l}=e;if(t){const c=t["@context"]?Array.isArray(t["@context"])?t["@context"]:[t["@context"]]:[],u=c.indexOf("http://iiif.io/api/image/2/context.json")!==-1,d=c.indexOf("http://iiif.io/api/image/3/context.json")!==-1;if((r.width===t.width&&!r.height||r.height===t.height&&!r.width||r.width===t.width&&r.height===t.height)&&(r=J(Z({},r),{max:!0})),u&&(r.max&&!r.serialiseAsFull&&(r=J(Z({},r),{serialiseAsFull:!0})),!r.max&&r.width&&r.height&&(r=J(Z({},r),{height:void 0}))),d&&(r.max&&r.serialiseAsFull&&(r=J(Z({},r),{serialiseAsFull:!1})),r.width&&!r.height&&t.width&&t.height)){const v=t.height/t.width;r=J(Z({},r),{height:Math.ceil(r.width*v)})}}return[n,Hi(o),Di(r),qi(s),`${l}.${a}`].filter(Boolean).join("/")}function ae(e,t,i){const n=Ti({id:W(S(e)),profile:"level2",type:"ImageService2"});if(n.type!=="image")throw new Error("Invalid service");return n.size.max=!1,n.size.width=t,n.size.height=i,{id:Zi(n),type:"fixed",width:t,height:i||e.height/(e.width||1)*t,unsafe:e.width>t}}function z(e){const t=e.replace(/(https?:\/\/)?(www.)?/i,"");return t.indexOf("/")!==-1?t.split("/")[0]:t}function Ji(e,t,i){const n=e.width?e.width:e.maxWidth;return i.height<=e.maxHeight&&i.width<=e.maxWidth&&i.height>=e.minHeight&&i.width>=e.minWidth&&(!t||Math.abs(i.width-n)<Math.abs(t.width-n))}function Xi(e,t){const i=[],n=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},e),o=[],r=[];let s=null;const a=(c,u)=>{if(Ji(n,u,c)){if(n.preferFixedSize&&c.unsafe){r.push(c);return}n.returnAllOptions&&u&&r.push(u),s=c}else n.returnAllOptions&&r.push(c)},l=t.length;for(let c=0;c<l;c++){const u=t[c](),d=u.length;for(let v=0;v<d;v++){const m=u[v];if(m.type==="unknown"&&n.atAnyCost&&o.push(m),m.type==="fixed"&&(m.unsafe?o.push(m):a(m,s)),m.type==="fixed-service")if(n.unsafeImageService){const p=ae(m,n.width,n.height);a(p,s)}else{const p=ae(m,m.width,m.height);a(p,s)}if(m.type==="variable"&&m.maxWidth){const p=ae({id:m.id,type:"fixed-service",width:m.maxWidth,height:m.maxWidth},m.maxWidth);a(p,s)}}if(s&&!n.returnAllOptions){if(s.unsafe||n.allowUnsafe)continue;break}}return n.atAnyCost&&r.length===0?{best:s||o[0],fallback:o.slice(1),log:i}:n.returnAllOptions?{best:n.atAnyCost?s||r[0]||o[0]:s||r[0],fallback:[...r,...o],log:i}:{best:s||r[0]||null,fallback:s?r:r.slice(1),log:i}}var Ki=Object.defineProperty,en=Object.defineProperties,tn=Object.getOwnPropertyDescriptors,Qe=Object.getOwnPropertySymbols,nn=Object.prototype.hasOwnProperty,rn=Object.prototype.propertyIsEnumerable,Ye=(e,t,i)=>t in e?Ki(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,on=(e,t)=>{for(var i in t||(t={}))nn.call(t,i)&&Ye(e,i,t[i]);if(Qe)for(var i of Qe(t))rn.call(t,i)&&Ye(e,i,t[i]);return e},sn=(e,t)=>en(e,tn(t));function an(e,t,i){const n=e>t?e:t,o=i.length,r=[];for(let s=0;s<o;s++){const a=i[s];let l=a.scaleFactors[0],c=n/l;const u=[l];for(;c>=a.width;)l=l*2,u.push(l),c=c/2;r.push(sn(on({},a),{scaleFactors:u}))}return r}function ln(e,t){if(e.length!==t.length)return!1;if(e.length===0&&t.length===0)return!0;const i=e.length;let n=!0;for(let r=0;r<i;r++){const s=e[r],a=t[r];if(s.width!==a.width||s.height!==a.height){n=!1;break}}if(n)return!0;let o=0;for(let r=0;r<i;r++)for(let s=0;s<i;s++)if(e[r].width===t[s].width&&e[r].height===t[s].height){o++;break}return o===i}var L=(e,t,i)=>new Promise((n,o)=>{var r=l=>{try{a(i.next(l))}catch(c){o(c)}},s=l=>{try{a(i.throw(l))}catch(c){o(c)}},a=l=>l.done?n(l.value):Promise.resolve(l.value).then(r,s);a((i=i.apply(e,t)).next())});class Ge{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(t){Object.assign(this.config,t)}sample(t,i,n=!0){const o=z(S(t)),r=W(S(t)),s=this.knownImageServers[o];return this.imageServices[r]=Object.assign(t,{real:!0}),s?this.verify(t):(this.knownImageServers[o]={verifications:0,malformed:!1,root:o,preLoaded:n,sampledId:S(t),verified:!1,server:null,result:{context:t["@context"]||[],sampledProfile:t.profile,resourceServiceRatio:i&&t.height?i.height/t.height:1,sampledSizes:t.sizes||[],sizeRatios:Fi(t.width,t.height,t.sizes||[]),sampledTiles:t.tiles||[]}},!0)}preLoad(t,i=!0){this.knownImageServers[t.root]=t,i&&(this.knownImageServers[t.root].malformed=!1,this.knownImageServers[t.root].verifications=this.config.verificationsRequired)}predict(t,i=!1,n=!1){const o=z(S(t)),r=this.knownImageServers[o];if(!r||!r.result||!n&&(r.malformed||r.verifications<this.config.verificationsRequired))return null;const s=W(S(t));return this.imageServices[s]||(this.imageServices[s]={"@context":r.result.context,"@id":S(t),id:S(t),protocol:"http://iiif.io/api/image",tiles:an(t.width,t.height,r.result.sampledTiles),sizes:ki(Math.floor(t.width/r.result.resourceServiceRatio),Math.floor(t.height/r.result.resourceServiceRatio),r.result.sizeRatios),profile:r.result.sampledProfile,height:t.height,width:t.width,real:!1}),this.imageServices[s]}getThumbnailFromResource(t,i){return L(this,arguments,function*(n,o,r=!0,s=[]){const a=yield this.getImageCandidates(n,r);return Xi(o,[()=>s,()=>a])})}getImageCandidates(t,i=!0){return L(this,null,function*(){const n=t;if(i&&n.height&&n.width){const o=G(n);for(const r of o){const s={id:S(r),width:r.width?r.width:n.width,height:r.height?r.height:n.height};yield this.loadService(s)}}return Bi(t,i,this)})}verify(t){return L(this,null,function*(){const i=this.predict(t,!1,!0),n=yield this.fetchService(S(t));if(!i)return!1;const o=i.height===n.height&&i.width===n.width&&i["@context"]===n["@context"]&&ln(i.sizes||[],n.sizes||[]);if(o){const r=z(S(t));this.knownImageServers[r].verifications+=1,this.knownImageServers[r].verifications>=this.config.verificationsRequired&&(this.knownImageServers[r].verified=!0)}return o})}canLoadSync(t){const i=typeof t=="string"?t:S(t),n=W(i);if(this.imageServices[n])return!0;const o=this.knownImageServers[z(i)];return o&&!o.malformed&&o.verifications>=this.config.verificationsRequired}markAsMalformed(t){return L(this,null,function*(){return this.knownImageServers[z(S(t))].malformed=!0,this.loadService(t,!0)})}fetchService(t,i=!1){return L(this,null,function*(){const n=W(t);if(this.imageServices[n]&&(!i||this.imageServices[n].real))return this.imageServices[n];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const o=yield this.fetch(n).then(r=>r.json());return!o.id&&o["@id"]&&(o.id=o["@id"]),o.id!==t&&(o.id=t,o["@id"]&&(o["@id"]=t)),this.imageServices[n]=Object.assign(o,{real:!0}),this.imageServices[n]})}fetch(t,i){return L(this,null,function*(){return fetch(t,i)})}loadService(t,i=!1){return L(this,null,function*(){if(!this.config.disableThrottling){let r=!0;for(;r;)if(this.fetchingCount>=this.config.verificationsRequired)yield new Promise(s=>setTimeout(s,500));else{r=!1;break}}const n=this.knownImageServers[z(S(t))];if(n&&!n.malformed&&!i){yield n.result;const r=this.loadServiceSync(t);if(r)return r}this.fetchingCount++;const o=yield this.fetchService(S(t),i);return this.fetchingCount--,o.real&&this.sample(o,t),o})}loadServiceSync(t){const i=W(S(t));return this.imageServices[i]?this.imageServices[i]:this.predict(t)}}new Ge;const Ze=A.default.createContext(new Ge);function ie(){return h.useContext(Ze)}const cn=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,un=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function ne(e){if(Array.isArray(e))return e.reduce((t,i)=>{const{selector:n,selectors:o}=ne(i);return n&&(t.selector||(t.selector=n),t.selectors.push(...o)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,i]=e.split("#");return i?ne({type:"FragmentSelector",value:i}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",temporal:{startTime:e.t}};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=cn.exec(e.value);if(t){const n={type:"BoxSelector",spatial:{unit:t[2]==="percent:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])}};return{selector:n,selectors:[n]}}const i=e.value.match(un);if(i){const n={type:"TemporalSelector",temporal:{startTime:i[4]?parseFloat(i[4]):0,endTime:i[7]?parseFloat(i[7]):void 0}};return{selector:n,selectors:[n]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}var fn=Object.defineProperty,hn=Object.defineProperties,dn=Object.getOwnPropertyDescriptors,Je=Object.getOwnPropertySymbols,pn=Object.prototype.hasOwnProperty,gn=Object.prototype.propertyIsEnumerable,Xe=(e,t,i)=>t in e?fn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Ke=(e,t)=>{for(var i in t||(t={}))pn.call(t,i)&&Xe(e,i,t[i]);if(Je)for(var i of Je(t))gn.call(t,i)&&Xe(e,i,t[i]);return e},et=(e,t)=>hn(e,dn(t));function T(e,t={}){if(Array.isArray(e))return T(e[0]);if(typeof e=="string"){const[i,n]=e.split("#");return n?T({type:"SpecificResource",source:{id:i,type:"Unknown"},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{id:i,type:t.typeMap&&t.typeMap[i]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return T(e.items[0]);if(e.type==="SpecificResource"){e.source.type==="Canvas"&&e.source.partOf&&typeof e.source.partOf=="string"&&(e.source.partOf=[{id:e.source.partOf,type:"Manifest"}]);const{selector:i,selectors:n}=e.selector?ne(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:i,selectors:n}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[i,n]=e.id.split("#");return n?T({type:"SpecificResource",source:et(Ke({},e),{id:i}),selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:et(Ke({},e),{id:i}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function tt(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function it(e,t,i){const n=[];let o=null;const r=[];for(const s of t){const a=e.get(s.body);for(const l of a){const[c,{selector:u}]=tt(l),d=(c.type||"unknown").toLowerCase();if(d==="choice"){const v=e.get(c.items),m=i.length?i.map(p=>v.find(w=>w.id===p)).filter(Boolean):[v[0]];m.length===0&&m.push(v[0]),o={type:"single-choice",items:v.map(p=>({id:p.id,label:p.label,selected:m.indexOf(p)!==-1})),label:l.label},a.push(...m);continue}n.indexOf(d)===-1&&n.push(d),r.push({type:d,resource:c,target:s.target,selector:u})}}return{types:n,items:r,choice:o}}const nt={makeChoice:()=>{}},le={type:"unknown"},j=e=>({type:"unknown",reason:e,annotations:{pages:[]}});function rt(e,t,i){const n=[];for(const o of t.items){const r=o.resource&&o.resource.type==="SpecificResource"?o.resource.source:o.resource;if(!r.id)return j("No resource Identifier");let s;if(r.service){const w=G(r);w[0]&&(s=i(w[0],e))}const{selector:a,source:l}=T(o.target);if(l.id!==e.id)continue;const c={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},u=a?a.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:a.temporal,spatial:c.spatial}:a:null,d={type:"BoxSelector",spatial:{x:0,y:0,width:e.width,height:e.height}},v=o.resource.type==="SpecificResource"?T(o.resource):null,m=v&&v.selector&&(v.selector.type==="BoxSelector"||v.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:v.selector.spatial.x,y:v.selector.spatial.y,width:v.selector.spatial.width,height:v.selector.spatial.height}}:d,p={id:r.id,type:"Image",width:u?r.width:e.width,height:u?r.height:e.height,service:s,sizes:s&&s.sizes?s.sizes:r.width&&r.height?[{width:r.width,height:r.height}]:[],target:u&&u.type!=="PointSelector"?u:c,selector:m};n.push(p)}return{type:"images",image:n[0],images:n,choice:t.choice}}var mn=Object.defineProperty,vn=Object.defineProperties,yn=Object.getOwnPropertyDescriptors,ot=Object.getOwnPropertySymbols,wn=Object.prototype.hasOwnProperty,xn=Object.prototype.propertyIsEnumerable,st=(e,t,i)=>t in e?mn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Sn=(e,t)=>{for(var i in t||(t={}))wn.call(t,i)&&st(e,i,t[i]);if(ot)for(var i of ot(t))xn.call(t,i)&&st(e,i,t[i]);return e},bn=(e,t)=>vn(e,yn(t));function On(e={},t=[]){const{id:i,selector:n}=e,o=k(),r=I(),s=i||o.annotation,a=$(c=>s?c.iiif.entities.Annotation[s]:void 0,[s]),l=$(c=>a&&a.body?a.body.map(u=>u?c.iiif.entities[u.type][u.id]:null).filter(Boolean):[],[a]);return h.useMemo(()=>{if(!a)return;const c=bn(Sn({},a),{body:l,target:T(a.target,{typeMap:r.getState().iiif.mapping})});return n?n(c):c},[a,n,l,...t])}function X(e={},t=[]){const{id:i,selector:n}=e,o=k();I();const r=i||o.manifest,s=$(a=>r?a.iiif.entities.Manifest[r]:void 0,[r]);return h.useMemo(()=>{if(!!s)return n?n(s):s},[s,n,...t])}function R(e={},t=[]){const{id:i,selector:n}=e,o=k(),r=i||o.canvas,s=$(a=>r?a.iiif.entities.Canvas[r]:void 0,[r]);return h.useMemo(()=>{if(!!s)return n?n(s):s},[s,n,...t])}function An(e,t){var i;const n=(i=e==null?void 0:e.iiif)==null?void 0:i.meta[t];return n?n.annotationPageManager:null}function Cn(e,t){return $(i=>{const n=[];if(!e)return n;const o=Object.keys(i.iiif.entities.AnnotationPage);for(const r of o)if(!t||t.indexOf(r)!==-1){const s=An(i,r);s&&s.views&&s.views[e]&&n.push(r)}return n},[e,t])}function at({canvas:e,manifest:t,all:i,canvases:n}){const o=[];if(t)for(const r of t.annotations)o.indexOf(r.id)===-1&&o.push(r.id);if(i){if(n&&n.length)for(const r of n)for(const s of r.annotations)o.indexOf(s.id)===-1&&o.push(s.id)}else if(e)for(const r of e.annotations)o.indexOf(r.id)===-1&&o.push(r.id);return o}var Pn=Object.defineProperty,_n=Object.defineProperties,In=Object.getOwnPropertyDescriptors,lt=Object.getOwnPropertySymbols,En=Object.prototype.hasOwnProperty,$n=Object.prototype.propertyIsEnumerable,ct=(e,t,i)=>t in e?Pn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,ut=(e,t)=>{for(var i in t||(t={}))En.call(t,i)&&ct(e,i,t[i]);if(lt)for(var i of lt(t))$n.call(t,i)&&ct(e,i,t[i]);return e},ft=(e,t)=>_n(e,In(t));function jn(e,t){var i;const n=(i=e==null?void 0:e.iiif)==null?void 0:i.meta[t];return n?n.annotationPageManager:null}function ht(e,t={}){const i=I(),n=X(),o=R(),r=xe(),s=h.useMemo(()=>at({all:t.all,manifest:n,canvas:o,canvases:r}),[t.all,o,r,n]),a=Cn(e,t.all?void 0:s),l=h.useCallback(u=>{!e||i.setMetaValue([u,"annotationPageManager","views"],d=>d&&!d[e]?d:ft(ut({},d||{}),{[e]:!1}))},[e,i]),c=h.useCallback((u,d={})=>{if(!e)return;const v=i.getState(),m=[];if(d==null?void 0:d.deselectOthers){const p=Object.keys(v.iiif.entities.AnnotationPage);for(const w of p){const C=jn(v,w);C&&C.views&&C.views[e]&&m.push(w)}}for(const p of m)l(p);i.setMetaValue([u,"annotationPageManager","views"],p=>p&&p[e]?p:ft(ut({},p||{}),{[e]:!0}))},[e,l,i]);return{availablePageIds:s,enabledPageIds:a,setPageEnabled:c,setPageDisabled:l}}function re(e={}){const t=R(e.canvasId?{id:e.canvasId}:void 0);return $((i,n)=>{if(!t)return[];const o=n.get(t.items),r=[];for(const s of o)r.push(...n.get(s.items));return r},[t])}function Mn(e,t={}){return re(t)}function Tn(e,t=!1){}function Fn(e,t=[]){const{id:i,selector:n}=e,o=k(),r=i||o.collection,s=$(a=>r?a.iiif.entities.Collection[r]:void 0,[r]);return h.useMemo(()=>{if(!!s)return n?n(s):s},[s,n,...t])}function dt(){const t=I().getStore();return h.useMemo(()=>i=>t.dispatch(i),[t])}function pt(e){return{addEventListener(t,i,n,o){if(t)return e.setMetaValue([t.id,"eventManager",i],r=>{const s=r||[];for(const a of s)if(a.callback===n)return s;return[...s,{callback:n,scope:o}]}),n},removeEventListener(t,i,n){!t||e.setMetaValue([t.id,"eventManager",i],o=>(o||[]).filter(r=>r.callback!==n))},getListenersAsProps(t,i){const n=typeof t=="string"?{id:t}:t;if(!n||!n.id)return{};const o=e.getResourceMeta(n.id,"eventManager"),r={};if(o&&n)for(const s of Object.keys(o))r[s]=a=>{const l=e.get(n);for(const{callback:c,scope:u}of o[s]||[])(!u||i&&u.indexOf(i)!==-1)&&c(a,l)};return r}}}function gt(e){return{applyStyles(t,i,n){const o=typeof t=="string"?t:t.id;return e.setMetaValue([o,"styles",i],n)},getAppliedStyles(t){const i=typeof t=="string"?t:t.id;return e.getResourceMeta(i,"styles")}}}function B(e){return e.endsWith("info.json")?e:e.endsWith("/")?`${e}info.json`:`${e}/info.json`}function kn(e,t,i){const n=i.length,o=[];for(let r=0;r<n;r++){const s=i[r].width;o.push(e/s)}return o}function Vn(e,t,i){const n=i.length,o=[];for(let r=0;r<n;r++){const s=i[r];o.push({width:Math.floor(e/s),height:Math.floor(t/s)})}return o}const Wn="http://library.stanford.edu/iiif/image-api/compliance.html#level0",mt="http://library.stanford.edu/iiif/image-api/compliance.html#level1",vt="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Ln="http://library.stanford.edu/iiif/image-api/conformance.html#level0",yt="http://library.stanford.edu/iiif/image-api/conformance.html#level1",wt="http://library.stanford.edu/iiif/image-api/conformance.html#level2",zn="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",xt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",St="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Rn="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",bt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Ot="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Bn="http://iiif.io/api/image/1/level0.json",Hn="http://iiif.io/api/image/1/profiles/level0.json",At="http://iiif.io/api/image/1/level1.json",Ct="http://iiif.io/api/image/1/profiles/level1.json",Pt="http://iiif.io/api/image/1/level2.json",_t="http://iiif.io/api/image/1/profiles/level2.json",Dn="http://iiif.io/api/image/2/level0.json",qn="http://iiif.io/api/image/2/profiles/level0.json",It="http://iiif.io/api/image/2/level1.json",Et="http://iiif.io/api/image/2/profiles/level1.json",$t="http://iiif.io/api/image/2/level2.json",jt="http://iiif.io/api/image/2/profiles/level2.json",Nn="level0",Mt="level1",Tt="level2",Un="http://iiif.io/api/image/2/level0",Ft="http://iiif.io/api/image/2/level1",kt="http://iiif.io/api/image/2/level2",Qn=[Ft,kt,mt,vt,yt,wt,xt,St,bt,Ot,At,Ct,Pt,_t,It,Et,$t,jt,Mt,Tt],Yn=[Un,Ft,kt,Wn,mt,vt,Ln,yt,wt,zn,xt,St,Rn,bt,Ot,Bn,Hn,At,Ct,Pt,_t,Dn,qn,It,Et,$t,jt,Nn,Mt,Tt];function b(e){if(e["@id"])return e["@id"];if(e.id)return e.id}function ce(e){if(!e||!e.profile||!b(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if(typeof i=="string"&&Yn.indexOf(i)!==-1)return!0;return!1}function Gn(e){if(!ce(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const i of t)if(typeof i=="string"){if(Qn.indexOf(i)!==-1)return!0}else{const n=i.supports||[];if(n.indexOf("regionByPx")!==-1&&(n.indexOf("sizeByW")!==-1||n.indexOf("sizeByWh")!==-1))return!0}return!1}function Zn(e){if(!Gn(e))return[];const t=[],i=Array.isArray(e.profile)?e.profile:[e.profile],n=i.length;for(let o=0;o<n;o++){const r=i[o];if(typeof r!="string"&&(r.maxHeight||r.maxWidth))return[{id:b(e),type:"variable",minWidth:0,minHeight:0,maxHeight:r.maxHeight||r.maxWidth,maxWidth:r.maxWidth||r.maxHeight}]}if(e.tiles){const o=e.tiles.length;for(let r=0;r<o;r++){const s=e.tiles[r];(s.height||s.width)&&t.push({id:b(e),type:"variable",minHeight:0,minWidth:0,maxHeight:s.height||s.width,maxWidth:s.width})}}return t}function Vt(e){const t=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,i=e.match(t);if(i){const n=i[1],o=parseInt(i[4],10),r=parseInt(i[5],10),s=i[7];if((n==="max"||n==="full")&&o&&r&&s)return{type:"fixed",id:e,height:r,width:o}}return{type:"unknown",id:e}}function Jn(e){if(e["@type"])return e["@type"];if(e.type)return e.type}function ue(e){if(typeof e=="string")return Vt(e);const t=Jn(e);if(t!=="Image"&&t!=="sc:Image")return null;const i=e,n=b(i);return n?n&&i.width&&i.height?{id:n,type:"fixed",width:i.width,height:i.height,unsafe:!0}:Vt(n):null}function Xn(e){return ce(e)?(e&&e.sizes?e.sizes:[]).map(t=>({id:b(e),type:"fixed-service",height:t.height,width:t.width})):[]}function Wt(e){const t=[],i=e.length;for(let n=0;n<i;n++){const o=Xn(e[n]);o.length&&t.push(...o);const r=Zn(e[n]);r.length&&t.push(...r)}return t}function Lt(e){const t=e.service?Array.isArray(e.service)?e.service:[e.service]:[],i=t.length,n=[];for(let o=0;o<i;o++)ce(t[o])&&n.push(t[o]);return n}function Kn(e,t=!0,i){const n=[],o=ue(e);if(o===null)return n;const r=e;if(n.push(o),t&&r.width&&r.height){const s=[],a=Lt(r);for(const l of a){const c={id:b(l),width:r.width,height:r.height};if(i.canLoadSync(c)){const u=i.loadServiceSync(c);u&&(u.height||(u.height=r.height),u.width||(u.width=r.width),s.push(...Wt([u])))}}if(s.length)return n.push(...s),n}return r.service&&n.push(...Wt(r.service)),n}function fe(e,t,i){return{id:[B(b(e)).slice(0,-10),"full",[t,i||""].join(","),0,"default.jpg"].join("/"),type:"fixed",width:t,height:i||e.height/e.width*t,unsafe:e.width>t}}function H(e){const t=e.replace(/(https?:\/\/)?(www.)?/i,"");return t.indexOf("/")!==-1?t.split("/")[0]:t}function er(e,t,i){const n=e.width?e.width:e.maxWidth;return i.height<=e.maxHeight&&i.width<=e.maxWidth&&i.height>=e.minHeight&&i.width>=e.minWidth&&(!t||Math.abs(i.width-n)<Math.abs(t.width-n))}function tr(e,t){const i=[],n=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},e),o=[],r=[];let s=null;const a=(c,u)=>{if(er(n,u,c)){if(n.preferFixedSize&&c.unsafe){r.push(c);return}n.returnAllOptions&&u&&r.push(u),s=c}else n.returnAllOptions&&r.push(c)},l=t.length;for(let c=0;c<l;c++){const u=t[c](),d=u.length;for(let v=0;v<d;v++){const m=u[v];if(m.type==="unknown"&&n.atAnyCost&&o.push(m),m.type==="fixed"&&(m.unsafe?o.push(m):a(m,s)),m.type==="fixed-service")if(n.unsafeImageService){const p=fe(m,n.width,n.height);a(p,s)}else{const p=fe(m,m.width,m.height);a(p,s)}if(m.type==="variable"&&m.maxWidth){const p=fe({id:m.id,type:"fixed-service",width:m.maxWidth,height:m.maxWidth},m.maxWidth);a(p,s)}}if(s&&!n.returnAllOptions){if(s.unsafe||n.allowUnsafe)continue;break}}return n.atAnyCost&&r.length===0?{best:s||o[0],fallback:o.slice(1),log:i}:n.returnAllOptions?{best:n.atAnyCost?s||r[0]||o[0]:s||r[0],fallback:[...r,...o],log:i}:{best:s||r[0]||null,fallback:s?r:r.slice(1),log:i}}function ir(e,t,i){const n=e>t?e:t,o=i.length,r=[];for(let s=0;s<o;s++){const a=i[s];let l=a.scaleFactors[0],c=n/l;const u=[l];for(;c>=a.width;)l=l*2,u.push(l),c=c/2;r.push(Object.assign(Object.assign({},a),{scaleFactors:u}))}return r}function nr(e,t){if(e.length!==t.length)return!1;if(e.length===0&&t.length===0)return!0;const i=e.length;let n=!0;for(let r=0;r<i;r++){const s=e[r],a=t[r];if(s.width!==a.width||s.height!==a.height){n=!1;break}}if(n)return!0;let o=0;for(let r=0;r<i;r++)for(let s=0;s<i;s++)if(e[r].width===t[s].width&&e[r].height===t[s].height){o++;break}return o===i}/*! *****************************************************************************
|
|
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 D(e,t,i,n){function o(r){return r instanceof i?r:new i(function(s){s(r)})}return new(i||(i=Promise))(function(r,s){function a(u){try{c(n.next(u))}catch(d){s(d)}}function l(u){try{c(n.throw(u))}catch(d){s(d)}}function c(u){u.done?r(u.value):o(u.value).then(a,l)}c((n=n.apply(e,t||[])).next())})}class zt{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(t){Object.assign(this.config,t)}sample(t,i,n=!0){const o=H(b(t)),r=B(b(t)),s=this.knownImageServers[o];return this.imageServices[r]=Object.assign(t,{real:!0}),s?this.verify(t):(this.knownImageServers[o]={verifications:0,malformed:!1,root:o,preLoaded:n,sampledId:b(t),verified:!1,server:null,result:{context:t["@context"]||[],sampledProfile:t.profile,resourceServiceRatio:i&&t.height?i.height/t.height:1,sampledSizes:t.sizes||[],sizeRatios:kn(t.width,t.height,t.sizes||[]),sampledTiles:t.tiles||[]}},!0)}preLoad(t,i=!0){this.knownImageServers[t.root]=t,i&&(this.knownImageServers[t.root].malformed=!1,this.knownImageServers[t.root].verifications=this.config.verificationsRequired)}predict(t,i=!1,n=!1){const o=H(b(t)),r=this.knownImageServers[o];if(!r||!r.result||!n&&(r.malformed||r.verifications<this.config.verificationsRequired))return null;const s=B(b(t));return this.imageServices[s]||(this.imageServices[s]={"@context":r.result.context,"@id":b(t),id:b(t),protocol:"http://iiif.io/api/image",tiles:ir(t.width,t.height,r.result.sampledTiles),sizes:Vn(Math.floor(t.width/r.result.resourceServiceRatio),Math.floor(t.height/r.result.resourceServiceRatio),r.result.sizeRatios),profile:r.result.sampledProfile,height:t.height,width:t.width,real:!1}),this.imageServices[s]}getThumbnailFromResource(t,i,n=!0,o=[]){return D(this,void 0,void 0,function*(){const r=yield this.getImageCandidates(t,n);return tr(i,[()=>o,()=>r])})}getImageCandidates(t,i=!0){return D(this,void 0,void 0,function*(){const n=t;if(i&&n.height&&n.width){const o=Lt(n);for(const r of o){const s={id:b(r),width:r.width?r.width:n.width,height:r.height?r.height:n.height};yield this.loadService(s)}}return Kn(t,i,this)})}verify(t){return D(this,void 0,void 0,function*(){const i=this.predict(t,!1,!0),n=yield this.fetchService(b(t));if(!i)return!1;const o=i.height===n.height&&i.width===n.width&&i["@context"]===n["@context"]&&nr(i.sizes||[],n.sizes||[]);if(o){const r=H(b(t));this.knownImageServers[r].verifications+=1,this.knownImageServers[r].verifications>=this.config.verificationsRequired&&(this.knownImageServers[r].verified=!0)}return o})}canLoadSync(t){const i=typeof t=="string"?t:b(t),n=B(i);if(this.imageServices[n])return!0;const o=this.knownImageServers[H(i)];return o&&!o.malformed&&o.verifications>=this.config.verificationsRequired}markAsMalformed(t){return D(this,void 0,void 0,function*(){return this.knownImageServers[H(b(t))].malformed=!0,this.loadService(t,!0)})}fetchService(t,i=!1){return D(this,void 0,void 0,function*(){const n=B(t);if(this.imageServices[n]&&(!i||this.imageServices[n].real))return this.imageServices[n];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const o=yield fetch(n).then(r=>r.json());return!o.id&&o["@id"]&&(o.id=o["@id"]),o.id!==t&&(o.id=t,o["@id"]&&(o["@id"]=t)),this.imageServices[n]=Object.assign(o,{real:!0}),this.imageServices[n]})}loadService(t,i=!1){return D(this,void 0,void 0,function*(){if(!this.config.disableThrottling)for(;this.fetchingCount>=this.config.verificationsRequired;)yield new Promise(r=>setTimeout(r,500));const n=this.knownImageServers[H(b(t))];if(n&&!n.malformed&&!i){yield n.result;const r=this.loadServiceSync(t);if(r)return r}this.fetchingCount++;const o=yield this.fetchService(b(t),i);return this.fetchingCount--,o.real&&this.sample(o,t),o})}loadServiceSync(t){const i=B(b(t));return this.imageServices[i]?this.imageServices[i]:this.predict(t)}}new zt;function rr(e,t={}){const i=t.imageServiceLoader||new zt;async function n(o,r,s,a=[],l){if(typeof o=="string")return{best:ue(o),fallback:[],log:[]};const c=e.get(o);if(typeof c=="string")return{best:ue(c),fallback:[],log:[]};switch(c.type){case"Annotation":{const u=c.body,d=e.get(u[0]);return l&&!d.width&&(d.width=l.width,d.height=l.height),await i.getThumbnailFromResource(d,r,s,a)}case"Canvas":{const u=c;if(u.thumbnail&&u.thumbnail.length){const d=e.get(u.thumbnail[0]),v=await i.getImageCandidates(d,s);v&&v.length&&a.push(...v)}return n(u.items[0],r,s,a,{width:u.width,height:u.height})}case"AnnotationPage":return n(c.items[0],r,s,a,l);case"Choice":return n(c.items[0],r,s,a,l);case"Collection":{const u=c.items[0];return n(u,r,s,a,l)}case"Manifest":{const u=c.items[0];return n(u,r,s,a,l)}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return l&&!c.width&&(c.width=l.width,c.height=l.height),i.getThumbnailFromResource(c,r,s,a);case"Service":case"Range":case"AnnotationCollection":case"CanvasReference":case"ContentResource":return{best:void 0,fallback:[],log:[]}}return{best:void 0,fallback:[],log:[]}}return{getBestThumbnailAtSize:n}}function or(e,t,i,n,o=[]){const r=I(),s=h.useMemo(()=>pt(r),[r]);h.useEffect(()=>{const a=e;return a?(s.addEventListener(a,t,i,n),()=>{s.removeEventListener(a,t,i)}):()=>{}},[s,e,t,...o])}function sr(){const e=h.useContext(U);return e&&e.vault?e.vault:K.globalVault()}function ar(e,t){const{id:i,isLoaded:n,error:o,resource:r,requestId:s,cached:a}=oe(e,t);return{id:i,isLoaded:n,error:o,manifest:r,requestId:s,cached:a}}var lr=(e,t,i)=>new Promise((n,o)=>{var r=l=>{try{a(i.next(l))}catch(c){o(c)}},s=l=>{try{a(i.throw(l))}catch(c){o(c)}},a=l=>l.done?n(l.value):Promise.resolve(l.value).then(r,s);a((i=i.apply(e,t)).next())});function Rt({cacheKey:e}={}){const t=R(),i=re(),n=I(),o=ie(),[r,s]=h.useState(void 0),[a,l]=h.useState(!1),[c,u]=h.useState("idle"),[d,v]=h.useState(void 0),m=t?t.id:"undefined",p=h.useMemo(()=>{try{if(t&&i.length){const C=i[0],F=n.get(C.body[0]),y=G(F)[0];return y&&o.loadServiceSync({id:y.id||y["@id"],width:y.width||t.width,height:y.height||t.height})||void 0}}catch(C){console.error(C)}},[m,e,t]),w=c==="success"&&r?r:p;return h.useEffect(()=>{lr(this,null,function*(){try{if(t&&i.length){const C=i[0],F=n.get(C.body[0]),y=G(F)[0];if(!y)return;l(!0),u("loading");try{const x=(yield o.loadService({id:y.id||y["@id"],width:y.width||t.width,height:y.height||t.height}))||void 0;s(x),u("success"),l(!1)}catch(x){u("error"),v(x)}}}catch(C){u("error"),v(C)}})},[m,e]),h.useMemo(()=>({data:w,isFetching:a,status:c,error:d}),[w,a,c,d])}function cr(){const e=Rt();return{isLoading:e.isFetching,tile:e.data?{id:e.data.id||e.data["@id"],width:e.data.width,height:e.data.height,imageService:e.data,thumbnail:void 0}:null}}function Bt(e,t=[]){const i=I(),n=re(),[o,r]=h.useState((e==null?void 0:e.defaultChoices)||[]),s=h.useMemo(()=>it(i,n,o),[i,n,o,...t]),l={makeChoice:h.useCallback((c,{deselectOthers:u=!0,deselect:d=!1}={})=>{if(s.choice){if(s.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");r(v=>{if(d){const p=v.filter(w=>w!==c);if(p.length===0){const w=s.items[0].resource.id;return w?[w]:[]}return p}if(u)return[c];const m=[...v];if(m.length===0&&s.items.length){const p=s.items[0].resource.id;p&&m.push(p)}return v.indexOf(c)!==-1?v:[...v,c]})}},[s.choice])};return[s,l]}function ur(e={},t=[]){const{id:i,selector:n}=e,o=k(),r=i||o.range,s=$(a=>r?a.iiif.entities.Range[r]:void 0,[r]);return h.useMemo(()=>{if(!!s)return n?n(s):s},[s,n,...t])}function fr(e,t){const i=I(),n=h.useMemo(()=>pt(i),[i]),o=$(()=>e&&e.id?i.getResourceMeta(e.id,"eventManager"):null,[e]);return h.useMemo(()=>e?n.getListenersAsProps(e,t):{},[o,e,i,t])}function Ht(e,t){return $((i,n)=>n.get(e.map(o=>({id:o,type:t}))),[e,t])}function hr(){const e=X();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function dr(){const e=I();return h.useMemo(()=>gt(e),[e])}function pr(e,t){const i=I(),n=h.useMemo(()=>gt(i),[i]);return $(()=>{if(!e)return null;const o=n.getAppliedStyles(e.id);return o?t?o[t]:o:void 0},[e,t])}const Dt=(e,t=[])=>{const i=I();h.useEffect(()=>{e(i)},[i,...t])};function gr(e,t,{canvasId:i,manifestId:n}={}){const o=I(),r=ie(),s=h.useMemo(()=>rr(o,{imageServiceLoader:r}),[o,r]),[a,l]=h.useState(),c=X(n?{id:n}:void 0),u=R(i?{id:i}:void 0),d=u||c,v=h.useRef(!1);if(h.useEffect(()=>()=>{v.current=!0},[]),!d)throw new Error("Must be called under a manifest or canvas context.");return Dt(m=>{s.getBestThumbnailAtSize(d,e,t).then(p=>{p.best&&!v.current&&l(p.best)})},[d]),a}var mr=Object.defineProperty,vr=Object.defineProperties,yr=Object.getOwnPropertyDescriptors,qt=Object.getOwnPropertySymbols,wr=Object.prototype.hasOwnProperty,xr=Object.prototype.propertyIsEnumerable,Nt=(e,t,i)=>t in e?mr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Ut=(e,t)=>{for(var i in t||(t={}))wr.call(t,i)&&Nt(e,i,t[i]);if(qt)for(var i of qt(t))xr.call(t,i)&&Nt(e,i,t[i]);return e},Qt=(e,t)=>vr(e,yr(t));function Yt(){const e=ie(),[t,i]=h.useState({}),n=h.useRef(!1);return h.useEffect(()=>()=>{n.current=!0},[]),[h.useCallback((r,{height:s,width:a})=>{if(r){const l=r.id||r["@id"],c=e.loadServiceSync({id:l,width:r.width||a,height:r.height||s});c?r=c:t[l]||(n.current||i(u=>Qt(Ut({},u),{[l]:"loading"})),e.loadService({id:l,width:r.width||a,height:r.height||s}).then(()=>{n.current||i(u=>Qt(Ut({},u),{[l]:"done"}))}))}return r},[e,t]),t]}var Sr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},P={exports:{}};(function(e,t){(function(i,n){n(t)})(Sr,function(i){function n(f){return f==null}function o(f){throw new Error("Argument "+f+" is empty.")}function r(f){return typeof f=="function"&&"getType"in f}function s(f){throw new Error("Argument "+f+' is invalid, it should be an action-creator instance from "typesafe-actions"')}function a(f,y){if(f==null)throw new Error("Argument contains array with empty element at index "+y);if(f.getType==null)throw new Error("Argument contains array with invalid element at index "+y+', it should be an action-creator instance from "typesafe-actions"')}function l(f){return typeof f=="string"||typeof f=="symbol"}function c(f){return!l(f)}function u(f){throw new Error("Argument "+f+" is invalid, it should be an action type of type: string | symbol")}function d(f,y){if(f==null)throw new Error("Argument contains array with empty element at index "+y);if(typeof f!="string"&&typeof f!="symbol")throw new Error("Argument contains array with invalid element at index "+y+", it should be of type: string | symbol")}function v(f,y,x,O){return n(f)&&o(1),c(f)&&s(1),{type:f,payload:y,meta:x,error:O}}function m(f,y){return n(f)&&o(1),c(f)&&u(1),Object.assign(function(){var x=y!=null?y.apply(void 0,arguments):void 0;return Object.assign({type:f},x)},{getType:function(){return f},toString:function(){return f}})}function p(f,y,x){return n(f)&&o(1),c(f)&&u(1),function(){return m(f,function(){var O=arguments.length<=0?void 0:arguments[0],E=arguments.length<=1?void 0:arguments[1];return y==null&&x==null||(O=y!=null?y.apply(void 0,arguments):void 0,E=x!=null?x.apply(void 0,arguments):void 0),Object.assign({},O!==void 0&&{payload:O},{},E!==void 0&&{meta:E})})}}function w(f){return n(f)&&o(1),r(f)||s(1),f.getType()}function C(f,y){n(f)&&o(1),c(f)&&u(1);var x=y!=null?y(f):function(){return{type:f}};return Object.assign(x,{getType:function(){return f},toString:function(){return f}})}var F={createAction:function(f,y){var x=y==null?function(){return v(f)}:y(v.bind(null,f));return Object.assign(x,{getType:function(){return f},toString:function(){return f}})},createCustomAction:C,createStandardAction:function(f){return n(f)&&o(1),c(f)&&u(1),Object.assign(function(){return C(f,function(y){return function(x,O){return{type:y,payload:x,meta:O}}})},{map:function(y){return C(f,function(x){return function(O,E){return Object.assign(y(O,E),{type:x})}})}})}};i.action=v,i.createAction=p,i.createAsyncAction=function(f,y,x,O){return function(){var E=[f,y,x,O].map(function(_,M){return Array.isArray(_)?p(_[0],_[1],_[2])():typeof _=="string"||typeof _=="symbol"?p(_)():void(M<3&&function(q){throw new Error("Argument "+q+' is invalid, it should be an action type of "string | symbol" or a tuple of "[string | symbol, Function, Function?]"')}(M))});return{request:E[0],success:E[1],failure:E[2],cancel:E[3]}}},i.createCustomAction=m,i.createReducer=function f(y,x){x===void 0&&(x={});var O=Object.assign({},x),E=function(_,M){var q=Array.isArray(_)?_:[_],Xt={};return q.map(function(N,Kr){return r(N)?w(N):l(N)?N:function(eo){throw new Error("Argument "+eo+' is invalid, it should be an action-creator instance from "typesafe-actions" or action type of type: string | symbol')}(Kr+1)}).forEach(function(N){return Xt[N]=M}),f(y,Object.assign({},O,{},Xt))};return Object.assign(function(_,M){if(_===void 0&&(_=y),O.hasOwnProperty(M.type)){var q=O[M.type];if(typeof q!="function")throw Error('Reducer under "'+M.type+'" key is not a valid reducer');return q(_,M)}return _},{handlers:Object.assign({},O),handleAction:E,handleType:E})},i.deprecated=F,i.getType=w,i.isActionOf=function(f,y){n(f)&&o(1);var x=Array.isArray(f)?f:[f];x.forEach(a);var O=function(E){return x.some(function(_){return E.type===_.getType()})};return y===void 0?O:O(y)},i.isOfType=function(f,y){n(f)&&o(1);var x=Array.isArray(f)?f:[f];x.forEach(d);var O=function(E){return x.includes(E.type)};return y===void 0?O:O(y)}})})(P,P.exports);const br="@iiif/IMPORT_ENTITIES",Or="@iiif/MODIFY_ENTITY_FIELD",Ar="@iiif/REORDER_ENTITY_FIELD",Cr="@iiif/ADD_REFERENCE",Pr="@iiif/REMOVE_REFERENCE",_r=P.exports.createAction(br)(),Ir=P.exports.createAction(Or)(),Er=P.exports.createAction(Ar)(),$r=P.exports.createAction(Cr)(),jr=P.exports.createAction(Pr)(),he={importEntities:_r,modifyEntityField:Ir,reorderEntityField:Er,addReference:$r,removeReference:jr},Mr="@iiif/ADD_MAPPING",Tr="@iiif/ADD_MAPPINGS";P.exports.createAction(Mr)(),P.exports.createAction(Tr)();const Fr="@iiif/SET_META_VALUE",kr="@iiif/SET_META_VALUE_DYNAMIC",Vr="@iiif/UNSET_META_VALUE";P.exports.createAction(Fr)(),P.exports.createAction(kr)(),P.exports.createAction(Vr)();const Wr="@iiif/REQUEST_RESOURCE",Lr="@iiif/REQUEST_ERROR",zr="@iiif/REQUEST_MISMATCH",Rr="@iiif/REQUEST_COMPLETE",Br="@iiif/REQUEST_OFFLINE_RESOURCE";P.exports.createAction(Wr)(),P.exports.createAction(Lr)(),P.exports.createAction(zr)(),P.exports.createAction(Rr)(),P.exports.createAction(Br)();const Hr="@iiif/BATCH",Dr="@iiif/BATCH_IMPORT";P.exports.createAction(Hr)(),P.exports.createAction(Dr)();function Gt(e){return typeof e!="string"&&e&&e.bindToVault}function qr(){const e=I(),t=h.useRef([]),i=dt(),n=h.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);h.useLayoutEffect(()=>{const a={id:n,type:"AnnotationPage",behavior:[],motivation:null,label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],logo:[],rendering:[],service:[]};i(he.importEntities({entities:{AnnotationPage:{[a.id]:a}}}))},[n]);const o=$(a=>n?a.iiif.entities.AnnotationPage[n]:null,[n]),r=h.useCallback((a,l)=>{if(n){if(Gt(a)){const d=a;d.__vault||d.bindToVault(e),a=typeof d.source=="string"?d.source:d.source.id,t.current[a]=d}else typeof a!="string"&&(a=a.id);const c=e.get({id:n,type:"AnnotationPage"}),u=e.get({id:a,type:"Annotation"});c&&u&&(c.items.find(d=>d.id===u.id)||i(he.addReference({id:n,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"},index:l})))}},[n]),s=h.useCallback(a=>{n&&(Gt(a)?a=typeof a.source=="string"?a.source:a.source.id:typeof a!="string"&&(a=a.id),t.current[a]&&t.current[a].beforeRemove(),e.get({id:n,type:"AnnotationPage"})&&i(he.removeReference({id:n,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"}})))},[n]);return[o,{addAnnotation:r,removeAnnotation:s}]}var Nr=Object.defineProperty,Ur=Object.defineProperties,Qr=Object.getOwnPropertyDescriptors,Zt=Object.getOwnPropertySymbols,Yr=Object.prototype.hasOwnProperty,Gr=Object.prototype.propertyIsEnumerable,Jt=(e,t,i)=>t in e?Nr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Zr=(e,t)=>{for(var i in t||(t={}))Yr.call(t,i)&&Jt(e,i,t[i]);if(Zt)for(var i of Zt(t))Gr.call(t,i)&&Jt(e,i,t[i]);return e},Jr=(e,t)=>Ur(e,Qr(t));function Xr(e){const t=X(),i=R(),n=I(),[o,r]=Yt(),{enabledPageIds:s}=ht((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(i==null?void 0:i.id),{all:!1}),a=Ht(s,"AnnotationPage"),l=(e==null?void 0:e.strategies)||["images","media","complex-timeline"],[c,u]=Bt(e,[r]),d=h.useMemo(()=>{if(!i||c.types.length===0)return le;if(c.types.length!==1)return l.indexOf("complex-timeline")===-1?j("Complex timeline not supported"):j("ComplexTimelineStrategy not yet supported");const v=c.types[0];return v==="image"?l.indexOf("images")===-1?j("Image not supported"):rt(i,c,o):v==="audio"?l.indexOf("media")===-1?j("Media not supported"):j("Audio strategy not yet supported"):v==="video"?l.indexOf("media")===-1?j("Media not supported"):j("Video strategy not yet supported"):le},[i,c,n,u.makeChoice]);return h.useMemo(()=>d.type==="unknown"?[d,nt]:[Jr(Zr({},d),{annotations:{pages:a}}),u],[d,a])}g.AnnotationContext=ri,g.CanvasContext=me,g.CollectionContext=oi,g.ContextBridge=fi,g.ImageServiceLoaderContext=Ze,g.ManifestContext=ve,g.RangeContext=si,g.ReactVaultContext=U,g.ResourceProvider=V,g.ResourceReactContext=ee,g.SimpleViewerProvider=li,g.SimpleViewerReactContext=Y,g.VaultProvider=ye,g.VisibleCanvasReactContext=Q,g.emptyActions=nt,g.expandTarget=T,g.flattenAnnotationPageIds=at,g.getImageStrategy=rt,g.getPaintables=it,g.parseSelector=ne,g.parseSpecificResource=tt,g.unknownResponse=le,g.unsupportedStrategy=j,g.useAnnotation=On,g.useAnnotationPageManager=ht,g.useAnnotationsAtTime=Mn,g.useCanvas=R,g.useCanvasClock=Tn,g.useCollection=Fn,g.useContextBridge=ui,g.useDispatch=dt,g.useEventListener=or,g.useExistingVault=sr,g.useExternalCollection=ar,g.useExternalManifest=we,g.useExternalResource=oe,g.useImageService=Rt,g.useImageServiceLoader=ie,g.useImageTile=cr,g.useLoadImageService=Yt,g.useManifest=X,g.usePaintables=Bt,g.usePaintingAnnotations=re,g.useRange=ur,g.useRenderingStrategy=Xr,g.useResourceContext=k,g.useResourceEvents=fr,g.useResources=Ht,g.useSearchService=hr,g.useSimpleViewer=ci,g.useStyleHelper=dr,g.useStyles=pr,g.useThumbnail=gr,g.useVault=I,g.useVaultEffect=Dt,g.useVaultSelector=$,g.useVirtualAnnotationPage=qr,g.useVisibleCanvases=xe,Object.defineProperty(g,"__esModule",{value:!0})});
|
|
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
|
+
}));
|