react-iiif-vault 1.0.2 → 1.0.3
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/bundle/cjs/index.js +9 -9
- package/dist/bundle/cjs/index.js.map +1 -1
- package/dist/bundle/esm/index.mjs +886 -858
- package/dist/bundle/esm/index.mjs.map +1 -1
- package/dist/canvas-panel/cjs/canvas-panel.js +8 -8
- package/dist/canvas-panel/cjs/canvas-panel.js.map +1 -1
- package/dist/canvas-panel/esm/canvas-panel.mjs +713 -685
- package/dist/canvas-panel/esm/canvas-panel.mjs.map +1 -1
- package/dist/index.umd.js +51 -51
- package/dist/index.umd.js.map +1 -1
- package/dist/react17/cjs/index.js +9 -9
- package/dist/react17/cjs/index.js.map +1 -1
- package/dist/react17/esm/index.mjs +886 -858
- package/dist/react17/esm/index.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),v=require("react"),Re=require("@atlas-viewer/atlas"),W=require("@iiif/parser"),Se=require("@atlas-viewer/iiif-image-api");function ji(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const at=ji(v);function yt(e,t){return yt=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},yt(e,t)}function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),v=require("react"),Re=require("@atlas-viewer/atlas"),W=require("@iiif/parser"),Se=require("@atlas-viewer/iiif-image-api");function ji(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const at=ji(v);function yt(e,t){return yt=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},yt(e,t)}function Pi(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,yt(e,t)}var Ei=function(t,r){return t===void 0&&(t=[]),r===void 0&&(r=[]),t.length!==r.length||t.some(function(n,i){return!Object.is(n,r[i])})},Gt={error:null},Oi=function(e){Pi(t,e);function t(){for(var n,i=arguments.length,s=new Array(i),a=0;a<i;a++)s[a]=arguments[a];return n=e.call.apply(e,[this].concat(s))||this,n.state=Gt,n.resetErrorBoundary=function(){for(var o,u=arguments.length,f=new Array(u),l=0;l<u;l++)f[l]=arguments[l];n.props.onReset==null||(o=n.props).onReset.apply(o,f),n.reset()},n}t.getDerivedStateFromError=function(i){return{error:i}};var r=t.prototype;return r.reset=function(){this.setState(Gt)},r.componentDidCatch=function(i,s){var a,o;(a=(o=this.props).onError)==null||a.call(o,i,s)},r.componentDidUpdate=function(i,s){var a=this.state.error,o=this.props.resetKeys;if(a!==null&&s.error!==null&&Ei(i.resetKeys,o)){var u,f;(u=(f=this.props).onResetKeysChange)==null||u.call(f,i.resetKeys,o),this.reset()}},r.render=function(){var i=this.state.error,s=this.props,a=s.fallbackRender,o=s.FallbackComponent,u=s.fallback;if(i!==null){var f={error:i,resetErrorBoundary:this.resetErrorBoundary};if(at.isValidElement(u))return u;if(typeof a=="function")return a(f);if(o)return at.createElement(o,f);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},t}(at.Component);const Li={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},Je=v.createContext(Li),se=()=>v.useContext(Je);function he({value:e,children:t}){const r=se(),n=v.useMemo(()=>({...r,...e}),[e,r]);return m.jsx(Je.Provider,{value:n,children:t})}var Fi=Object.defineProperty,$i=(e,t,r)=>t in e?Fi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,pe=(e,t,r)=>($i(e,typeof t!="symbol"?t+"":t,r),r);const q=function(e){return function(){const t={type:e,getType:()=>e,toString:()=>e};return(r,n)=>({...t,...r!==void 0&&{payload:r},...n!==void 0&&{meta:n}})}},hr="@iiif/IMPORT_ENTITIES",vr="@iiif/MODIFY_ENTITY_FIELD",yr="@iiif/REORDER_ENTITY_FIELD",gr="@iiif/ADD_REFERENCE",gt="@iiif/UPDATE_REFERENCE",mr="@iiif/REMOVE_REFERENCE",xr="@iiif/ADD_METADATA",br="@iiif/REMOVE_METADATA",mt="@iiif/UPDATE_METADATA",Ar="@iiif/REORDER_METADATA",Sr=q(hr)(),Di=q(vr)(),qi=q(yr)(),Vi=q(gr)(),_i=q(mr)(),Ui=q(gt)(),Hi=q(xr)(),Ni=q(mt)(),Bi=q(br)(),zi=q(Ar)(),Wi={importEntities:Sr,modifyEntityField:Di,reorderEntityField:qi,addReference:Vi,removeReference:_i,updateReference:Ui,addMetadata:Hi,removeMetadata:Bi,updateMetadata:Ni,reorderMetadata:zi},wr="@iiif/ADD_MAPPING",Cr="@iiif/ADD_MAPPINGS",Qi=q(wr)(),Yi=q(Cr)(),Mr="@iiif/SET_META_VALUE",Rr="@iiif/SET_META_VALUE_DYNAMIC",Ir="@iiif/UNSET_META_VALUE",Gi=q(Mr)(),Ji=q(Rr)(),Ki=q(Ir)(),Jt={setMetaValue:Gi,setMetaValueDynamic:Ji,unsetMetaValue:Ki},xt="RESOURCE_ERROR",kr="RESOURCE_LOADING",bt="RESOURCE_READY",Tr="@iiif/REQUEST_RESOURCE",jr="@iiif/REQUEST_ERROR",Pr="@iiif/REQUEST_MISMATCH",Er="@iiif/REQUEST_COMPLETE",Zi="@iiif/REQUEST_OFFLINE_RESOURCE",Xi=q(Tr)(),At=q(jr)(),es=q(Pr)(),ts=q(Er)(),Tt="@iiif/BATCH",rs="@iiif/BATCH_IMPORT",St=q(Tt)(),ns=(e,t)=>{const{entities:r,resource:n,mapping:i}=W.normalize(t);if(n.id===void 0)return[At({id:e,message:"ID is not defined in resource."})];const s=[Sr({entities:r}),Yi({mapping:i})];return n.id!==e&&(s.push(Qi({id:e,type:n.type})),s.push(es({requestId:e,actualId:n.id}))),s.push(ts({id:e})),s},Kt=Number.isNaN||function(e){return typeof e=="number"&&e!==e};function is(e,t){return!!(e===t||Kt(e)&&Kt(t))}function Zt(e,t){if(!Array.isArray(e)||!Array.isArray(t))return e===t;if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!is(e[r],t[r]))return!1;return!0}function ot(e,t,r){const n=e.iiif.requests[t],i=e.iiif.mapping[t];if(!i||!e.iiif.entities[i][n.resourceUri])return;const s=e.iiif.entities[i][n.resourceUri];if(s&&s[W.HAS_PART]){const a=s[W.HAS_PART].find(o=>r?o[W.PART_OF]===r.id:o[W.PART_OF]===s.id);return W.frameResource(s,a)}return s}function ss(e){return e&&typeof e.then=="function"}function Xt(e,t,{waitTimeout:r=30}={}){return(n,i)=>{const s=e.getStore(),a=s.getState(),o=a.iiif.requests[n];if(o){if(o.loadingState===bt){const f=ot(a,n);if(f)return f}switch(o.loadingState){case xt:break;case kr:return(async()=>{let f,l=!1;try{const d=await Promise.race([new Promise((g,b)=>{l||(f=s.subscribe(()=>{const h=s.getState();if(h.iiif.requests[n].loadingState===xt){b();return}if(h.iiif.requests[n].loadingState===bt){const x=ot(h,n);x?g(x):b()}}))}),new Promise((g,b)=>setTimeout(()=>{l=!0,b()},r*60*1e3))]);if(f&&f(),d)return d}catch{f&&f()}})()}}e.dispatch(Xi({id:n}));const u=f=>{if(!f)return;!f.id&&!f["@id"]&&(f["@type"]&&(f["@id"]=n),f.id=n);const l=ns(n,f);return e.dispatch(St({actions:l})),ot(s.getState(),n)};try{const f=t(n,i);return ss(f)?(async()=>{try{return u(await f)}catch(l){throw e.dispatch(At({id:n,message:l.toString()})),l}})():u(f)}catch(f){throw e.dispatch(At({id:n,message:f.toString()})),f}}}function Or(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}const er=e=>{let t;const r=new Set,n=(a,o)=>{const u=typeof a=="function"?a(t):a;if(!Object.is(u,t)){const f=t;t=o??typeof u!="object"?u:Object.assign({},t,u),r.forEach(l=>l(t,f))}},i=()=>t,s={setState:n,getState:i,subscribe:a=>(r.add(a),()=>r.delete(a)),destroy:()=>{r.clear()}};return t=e(n,i,s),s},as=e=>e?er(e):er,os=(e,t)=>(r,n,i)=>(i.dispatch=s=>(r(a=>e(a,s),!1,s),s),i.dispatchFromDevtools=!0,{dispatch:(...s)=>i.dispatch(...s),...t}),cs=os,wt=new Map,Ue=e=>{const t=wt.get(e);return t?Object.fromEntries(Object.entries(t.stores).map(([r,n])=>[r,n.getState()])):{}},us=(e,t,r)=>{if(e===void 0)return{type:"untracked",connection:t.connect(r)};const n=wt.get(r.name);if(n)return{type:"tracked",store:e,...n};const i={connection:t.connect(r),stores:{}};return wt.set(r.name,i),{type:"tracked",store:e,...i}},ls=(e,t={})=>(r,n,i)=>{const{enabled:s,anonymousActionType:a,store:o,...u}=t;let f;try{f=(s??!1)&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!f)return e(r,n,i);const{connection:l,...d}=us(o,f,u);let g=!0;i.setState=(x,A,S)=>{const w=r(x,A);if(!g)return w;const M=S===void 0?{type:a||"anonymous"}:typeof S=="string"?{type:S}:S;return o===void 0?(l==null||l.send(M,n()),w):(l==null||l.send({...M,type:`${o}/${M.type}`},{...Ue(u.name),[o]:i.getState()}),w)};const b=(...x)=>{const A=g;g=!1,r(...x),g=A},h=e(i.setState,n,i);if(d.type==="untracked"?l==null||l.init(h):(d.stores[d.store]=i,l==null||l.init(Object.fromEntries(Object.entries(d.stores).map(([x,A])=>[x,x===d.store?h:A.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){const x=i.dispatch;i.dispatch=(...A)=>{x(...A)}}return l.subscribe(x=>{var A;switch(x.type){case"ACTION":if(typeof x.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return ct(x.payload,S=>{if(S.type==="__setState"){if(o===void 0){b(S.state);return}Object.keys(S.state).length!==1&&console.error(`
|
|
2
2
|
[zustand devtools middleware] Unsupported __setState action format.
|
|
3
3
|
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
|
|
4
4
|
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
|
|
5
|
-
`);const w=S.state[o];if(w==null)return;JSON.stringify(i.getState())!==JSON.stringify(w)&&b(w);return}i.dispatchFromDevtools&&typeof i.dispatch=="function"&&i.dispatch(S)});case"DISPATCH":switch(x.payload.type){case"RESET":return b(h),o===void 0?l==null?void 0:l.init(i.getState()):l==null?void 0:l.init(Ue(u.name));case"COMMIT":if(o===void 0){l==null||l.init(i.getState());return}return l==null?void 0:l.init(Ue(u.name));case"ROLLBACK":return ct(x.state,S=>{if(o===void 0){b(S),l==null||l.init(i.getState());return}b(S[o]),l==null||l.init(Ue(u.name))});case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return ct(x.state,S=>{if(o===void 0){b(S);return}JSON.stringify(i.getState())!==JSON.stringify(S[o])&&b(S[o])});case"IMPORT_STATE":{const{nextLiftedState:S}=x.payload,w=(A=S.computedStates.slice(-1)[0])==null?void 0:A.state;if(!w)return;b(o===void 0?w:w[o]),l==null||l.send(null,S);return}case"PAUSE_RECORDING":return g=!g}return}}),h},ls=us,ct=(e,t)=>{let r;try{r=JSON.parse(e)}catch(n){console.error("[zustand devtools middleware] Could not parse the received json",n)}r!==void 0&&t(r)},fs=e=>(t,r,n)=>{const i=n.subscribe;return n.subscribe=(s,a,o)=>{let u=s;if(a){const d=(o==null?void 0:o.equalityFn)||Object.is;let l=s(n.getState());u=p=>{const g=s(p);if(!d(l,g)){const b=l;a(l=g,b)}},o!=null&&o.fireImmediately&&a(l,l)}return i(u)},e(t,r,n)},ps=fs,ds=(e={},t)=>{switch(t.type){case Sr:return{...e,[t.payload.id]:t.payload.type};case wr:return{...e,...t.payload.mapping};default:return e}};function ut(e,t,r,n){return!(!e[r]||!e[r][t]||!e[r][t][n]||!Array.isArray(e[r][t][n]))}function hs(e,t){const r={},n=[];for(const[i,s]of Object.entries(e||{})){n.push(i);const a=(t||{})[i];if(!a||a.length===0){r[i]=s;continue}r[i]=a}for(const[i,s]of Object.entries(t||{}))n.indexOf(i)===-1&&(r[i]=s);return r}function I(e){return e.payload}function lt(e,t){return typeof e>"u"?t:e}const vs=(e=Or(),t)=>{var r;const n=(i,s)=>({...e,[I(t).type]:{...e[I(t).type],[I(t).id]:{...i,...s}}});switch(t.type){case hr:{if(!e[I(t).type]||!e[I(t).type][I(t).id])return e;const i=e[I(t).type][I(t).id];return typeof i=="string"?e:n(i,{[I(t).key]:I(t).value})}case vr:{if(!ut(e,I(t).id,I(t).type,I(t).key))return e;const i=e[I(t).type][I(t).id];if(typeof i=="string")return e;const s=Array.from(i[I(t).key]),[a]=s.splice(I(t).startIndex,1);return s.splice(I(t).endIndex,0,a),n(i,{[I(t).key]:s})}case dr:{const i=Object.keys(I(t).entities),s={...e};for(const a of i){const o=I(t).entities[a],u={...e[a]||{}};let d=!1;const l=Object.keys(o||{})||[];if(o&&l){for(const p of l)d=!0,u[p]=e[a][p]?hs(e[a][p],o[p]):o[p];d&&(s[a]=u)}}return s}case yr:{if(!ut(e,I(t).id,I(t).type,I(t).key))return e;const i=e[I(t).type][I(t).id],s=Array.from(i[I(t).key]);return s.splice(lt(I(t).index,s.length+1),0,I(t).reference),n(i,{[I(t).key]:s})}case gt:case gr:{if(!ut(e,I(t).id,I(t).type,I(t).key))return e;const i=e[I(t).type][I(t).id],s=Array.from(i[I(t).key]),a=lt(I(t).index,s.findIndex(o=>o&&o.id===I(t).reference.id));return a===-1||((r=s[a])==null?void 0:r.id)!==I(t).reference.id?e:(t.type===gt?s.splice(a,1,I(t).reference):s.splice(a,1),n(i,{[I(t).key]:s}))}case mr:{const i=e[I(t).type][I(t).id];if(!i)return e;const s=Array.from(i.metadata||[]),a=I(t);return s.splice(lt(t.payload.beforeIndex,s.length+1),0,{label:a.label,value:a.label}),n(i,{metadata:s})}case br:{const i=e[I(t).type][I(t).id];if(typeof i=="string"||!i)return e;const s=Array.from(i.metadata||[]),[a]=s.splice(I(t).startIndex,1);return s.splice(I(t).endIndex,0,a),n(i,{metadata:s})}case mt:case xr:{const i=e[I(t).type][I(t).id],s=Array.from(i.metadata||[]),a=I(t).atIndex;return typeof a>"u"||a===-1||!s[a]?e:(t.type===mt?s.splice(a,1,{label:I(t).label,value:I(t).value}):s.splice(a,1),n(i,{metadata:s}))}default:return e}},ys=(e={},t)=>{switch(t.type){case kr:case Zi:return{...e,[t.payload.id]:{requestUri:t.payload.id,loadingState:Ir,uriMismatch:!1,resourceUri:t.payload.id}};case jr:return{...e,[t.payload.requestId]:{...e[t.payload.requestId]||{},uriMismatch:!0,resourceUri:t.payload.actualId},[t.payload.actualId]:{requestUri:t.payload.requestId,loadingState:e[t.payload.requestId].loadingState,uriMismatch:!0,resourceUri:t.payload.actualId}};case Tr:return{...e,[t.payload.id]:{...e[t.payload.id]||{},loadingState:xt,error:t.payload.message}};case Er:return{...e,[t.payload.id]:{...e[t.payload.id]||{},loadingState:bt,error:void 0}}}return e},gs=(e={},t)=>{const{id:r,updateValue:n,value:i,meta:s,key:a}=t&&t.payload||{};switch(t.type){case Cr:return{...e,[r]:{...e[r]||{},[s]:{...e[r]?e[r][s]||{}:{},[a]:i}}};case Mr:return{...e,[r]:{...e[r]||{},[s]:{...e[r]?e[r][s]||{}:{},[a]:e[r]&&e[r][s]?n(e[r][s][a]):n(void 0)}}};case Rr:return e[r]&&e[r][s]&&e[r][s][a]?{...e,[r]:{...e[r]||{},[s]:{...e[r]?e[r][s]||{}:{},[a]:void 0}}}:e;default:return e}};function Lr(e={}){const t=Object.keys(e);return function(r={},n){let i=!1;const s={};for(let a=0;a<t.length;a++){const o=t[a];s[o]=e[o](r[o],n),i=i||s[o]!==r[o]}return i?s:r}}function ms(e){return(t,r)=>r&&r.type===kt?r.payload.actions.reduce(e,t):r&&r.type===rs?{...t,iiif:{...t.iiif,...r.payload.state}}:e(t,r)}const xs=Lr({mapping:ds,entities:vs,requests:ys,meta:gs});function bs(){return{iiif:{entities:Or(),meta:{},mapping:{},requests:{}}}}function As(e={}){const{enableDevtools:t=!1,iiifStoreName:r="iiif",defaultState:n=bs(),customReducers:i={}}=e,s=ms(Lr({[r]:xs,...i}));return ss(ps(ls(os(s,n),{enabled:t})))}function Ss(e){return{all:e=e||new Map,on:function(t,r){var n=e.get(t);n?n.push(r):e.set(t,[r])},off:function(t,r){var n=e.get(t);n&&(r?n.splice(n.indexOf(r)>>>0,1):e.set(t,[]))},emit:function(t,r){var n=e.get(t);n&&n.slice().map(function(i){i(r)}),(n=e.get("*"))&&n.slice().map(function(i){i(t,r)})}}}function z(e,t,r,n=!0){t[we]=t[we]||[],t[we].push(e);const i=new Map;Object.defineProperty(t,e,{enumerable:n,get(){if(typeof t[xe][e]>"u")return;const s=t[xe][e];if(!s)return s;const a=r.get(t[xe][e],{parent:this.id?{id:this.id,type:this.type}:void 0});return i.has(a)||(i.clear(),i.set(a,be(a,r))),i.get(a)},set(s){t[xe][e]!==s&&(this[me]?r.modifyEntityField({id:this.id,type:this.type},e,Fr(s)):this[xe][e]=s)}})}const xe=Symbol.for("_refs_"),me=Symbol.for("_reactive_"),we=Symbol.for("_defined_"),er=Symbol.for("_parent_");function ws(e,t=!1,r){const n={id:"",type:"unknown",[we]:[],[xe]:{},[er]:r||null,[me]:null,is(i){return typeof i=="string"?this.id===i:i.id?i.id===this.id:!1},reactive(){if(!this[me])return this[me]=this.subscribe(()=>this.refresh(),!0),()=>{this.unreactive()}},refresh(){if(this.id){const i=this.unwrap();for(const s of Object.keys(i||{}))this[we].includes(s)?this[xe][s]=i[s]:this[s]=i[s]}},unreactive(){this[me]&&(this[me](),this[me]=null)},unwrap(){if(!this.id)throw new Error("Invalid object");const i=this[er];return e.get(this.id,{parent:i?{id:i,type:"unknown"}:void 0})},toPresentation3(){return e.toPresentation3(this.unwrap())},toPresentation2(){return e.toPresentation2(this.unwrap())},valueOf(){return this.unwrap()},toJSON(){const i=this;return{...i,items:i.items,annotations:i.annotations,structures:i.structures,seeAlso:i.seeAlso,service:i.service,services:i.services,rendering:i.rendering,partOf:i.partOf,start:i.start,supplementary:i.supplementary,homepage:i.homepage,thumbnail:i.thumbnail,placeholderCanvas:i.placeholderCanvas,accompanyingCanvas:i.accompanyingCanvas,provider:i.provider}},subscribe(i,s=!0){return e.subscribe(()=>this.id?e.get(this.id):null,i,s)}};return z("items",n,e),z("annotations",n,e),z("structures",n,e),z("seeAlso",n,e),z("rendering",n,e),z("partOf",n,e),z("start",n,e,!1),z("supplementary",n,e),z("homepage",n,e),z("thumbnail",n,e),z("placeholderCanvas",n,e,!1),z("accompanyingCanvas",n,e,!1),z("provider",n,e),z("body",n,e),z("logo",n,e),n}function Cs(e){return!!e[we]}function Fr(e){return Array.isArray(e)?e.map(t=>Fr(t)):!e||!e.type?e:{id:e.id,type:e.type}}function be(e,t,r=!1,n){if(Array.isArray(e))return e.map(o=>be(o,t,r));if(!e||!e.type||!e.id)return e;const i=ws(t,r),s=Object.create(i),a=Object.assign(s,e);return r&&a.reactive(),a}function tr(e){switch(e){case"Image":case"Video":case"Sound":case"Dataset":case"Text":case"Composite":case"List":case"Independents":case"Audience":return"ContentResource";case"ImageService1":case"ImageService2":case"ImageService3":return"Service"}return e}let wt=class{constructor(t,r){pe(this,"options"),pe(this,"store"),pe(this,"emitter"),pe(this,"isBatching",!1),pe(this,"batchQueue",[]),pe(this,"remoteFetcher"),pe(this,"staticFetcher"),pe(this,"defaultFetcher",n=>fetch(n).then(i=>i.json())),this.options=Object.assign({reducers:{},customFetcher:this.defaultFetcher,enableDevtools:!0},t||{}),this.store=r||As({customReducers:this.options.reducers,defaultState:this.options.defaultState,enableDevtools:this.options.enableDevtools}),this.emitter=Ss(),this.remoteFetcher=Zt(this,this.options.customFetcher),this.staticFetcher=Zt(this,(n,i)=>i)}batch(t){this.isBatching=!0;try{t(this),this.isBatching=!1,this.dispatch(At({actions:this.batchQueue}))}catch(r){throw this.batchQueue=[],this.isBatching=!1,r}this.batchQueue=[]}async asyncBatch(t){this.isBatching=!0;try{await t(this),this.isBatching=!1,this.dispatch(At({actions:this.batchQueue}))}catch(r){throw this.batchQueue=[],this.isBatching=!1,r}this.batchQueue=[]}modifyEntityField(t,r,n){this.dispatch(Wi.modifyEntityField({id:t.id,type:t.type,key:r,value:n}))}dispatch(t){if(this.isBatching)this.batchQueue.push(t);else{if(t.type===kt){for(const i of t.payload.actions)this.emitter.emit(i.type,{action:i,state:this.store.getState()});this.store.dispatch(t);const n=this.getState();for(const i of t.payload.actions)this.emitter.emit(`after:${i.type}`,{action:i,state:n});return}this.emitter.emit(t.type,{action:t,state:this.store.getState()}),this.store.dispatch(t);const r=this.store.getState();this.emitter.emit(`after:${t.type}`,{action:t,state:r});return}}on(t,r){return this.emitter.on(t,r),()=>{this.emitter.off(t,r)}}serialize(t,r){return W.serialize(this.getState().iiif,t,r)}toPresentation2(t){return this.serialize(t,W.serializeConfigPresentation2)}toPresentation3(t){return this.serialize(t,W.serializeConfigPresentation3)}hydrate(t,r,n={}){return this.get(t,r,{...n,skipSelfReturn:!1})}get(t,r,n={}){typeof r!="string"&&(n=r||{},r=void 0);const{skipSelfReturn:i=!0}=n||{};let s=n.parent?typeof n.parent=="string"?n.parent:n.parent.id:void 0;if(Array.isArray(t))return t.map(p=>this.get(p,n));const a=this.getState();if(W.isSpecificResource(t)&&!n.preserveSpecificResources&&(t=t.source),typeof t=="string"){const p=tr(r||a.iiif.mapping[t]);if(!p)return i?null:{id:t,type:"unknown"};t={id:t,type:p}}if(t&&t.partOf&&!s&&!n.skipPartOfCheck){const p=Array.isArray(t.partOf)?t.partOf[0]:t.partOf;p&&(typeof p=="string"&&(s=p),typeof p.id=="string"&&(s=p.id))}const o=tr(r||(t==null?void 0:t.type)),u=t==null?void 0:t.id,d=a.iiif.entities[o];if(!d){const p=a.iiif.requests[u];return p&&p.resourceUri!==u?this.get(p.resourceUri,n):i?null:t}const l=d[t.id];if(l&&l[W.HAS_PART]){const p=l[W.HAS_PART].find(g=>s?g[W.PART_OF]===s:g[W.PART_OF]===l.id);return W.frameResource(l,p)}return d[t.id]||(i?null:t)}select(t){return t(this.getState())}getStore(){return this.store}getState(){return this.store.getState()}deep(t,r){if(typeof t>"u")return this.get(r,{skipSelfReturn:!1});if(typeof t=="function")try{const i=t(this.get(r,{skipSelfReturn:!1})),s=a=>this.deep(a,i);return s.size=Array.isArray(i)?i.length:1,s}catch{const i=s=>this.deep(s,void 0);return i.size=0,i}const n=i=>this.deep(i,t);return n.size=Array.isArray(t)?t.length:1,n}loadManifest(t,r){const n=typeof t=="string"?t:t.id;return this.load(n,r)}loadCollection(t,r){const n=typeof t=="string"?t:t.id;return this.load(n,r)}load(t,r){const n=typeof t=="string"?t:t.id;return r?this.staticFetcher(n,r):this.remoteFetcher(n)}areInputsEqual(t,r){return Kt(t,r)}subscribe(t,r,n){return typeof n>"u"&&(typeof r>"u"||r===!1||r===!0)&&(n=r,r=t,t=i=>i),this.store.subscribe(t,i=>r(i,this),{equalityFn:Kt,fireImmediately:!n})}async ensureLoaded(t){const r=typeof t=="string"?t:t.id;this.requestStatus(r)||await this.load(r)}requestStatus(t){return this.select(r=>r.iiif.requests[t])}getResourceMeta(t,r){const n=this.getState().iiif.meta[t];if(n)return r?n[r]:n}getObject(t,r,n={}){const{reactive:i,...s}=n;return be(this.get(t,r,s),this,i)}async loadObject(t,r){return be(await this.load(t,r),this)}async loadManifestObject(t,r){return be(await this.loadManifest(t,r),this)}async loadCollectionObject(t,r){return be(await this.loadCollection(t,r),this)}wrapObject(t){return be(this.get(t,{skipSelfReturn:!1}),this)}isWrapped(t){return Cs(t)}setMetaValue([t,r,n],i){this.dispatch(typeof i=="function"?Gt.setMetaValueDynamic({id:t,meta:r,key:n,updateValue:i}):Gt.setMetaValue({id:t,meta:r,key:n,value:i}))}};function Ms(){return typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{}}function $r(e){const t=Ms();try{const n=t.IIIF_VAULT;if(n)return n}catch{}const r=new wt(e);try{t.IIIF_VAULT=r}catch{}return r}const $e=v.createContext({vault:null,setVaultInstance:e=>{}});function Tt({vault:e,vaultOptions:t,useGlobal:r,resources:n,children:i}){const[s,a]=v.useState(()=>e||(r?$r(t):t?new wt(t):new wt));return m.jsx($e.Provider,{value:{vault:s,setVaultInstance:a},children:m.jsx(he,{value:n||{},children:i})})}const V=()=>{const{vault:e}=v.useContext($e);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};function jt(e,{noCache:t=!1}={}){const r=typeof e=="string"?e:e.id,n=V(),[i,s]=v.useState(r),[a,o]=v.useState(void 0),u=v.useMemo(()=>n.get(r,{skipSelfReturn:!0})||void 0,[r,n]),[d,l]=v.useState(u);return v.useEffect(()=>{(async()=>{try{const p=u&&!t?u:await n.load(r),g=p?p.id||p["@id"]:null;p&&i!==g&&s(g),l(p)}catch(p){o(p)}})()},[r,t]),{isLoaded:!!d,id:i,requestId:r,error:a,resource:d,cached:!!(d&&d===u)}}function Dr(e,t){const{id:r,isLoaded:n,error:i,resource:s,requestId:a,cached:o}=jt(e,t);return{id:r,isLoaded:n,error:i,manifest:s,requestId:a,cached:o}}function qr({manifest:e,children:t}){return m.jsx(he,{value:{manifest:e},children:t})}function Ke({canvas:e,children:t}){return m.jsx(he,{value:{canvas:e},children:t})}function U(e,t=[]){const r=V(),[n,i]=v.useState(()=>e(r.getState(),r));return v.useEffect(()=>r.subscribe(s=>e(s,r),s=>{i(s)},!1),t),n}const De=v.createContext([]);function Et(){const e=v.useContext(De);return U(t=>e.map(r=>t.iiif.entities.Canvas[r]).filter(Boolean),[e])}function ve(e={},t=[]){const{id:r,selector:n}=e,i=se();V();const s=r||i.manifest,a=U(o=>s?o.iiif.entities.Manifest[s]:void 0,[s]);return v.useMemo(()=>{if(a)return n?n(a):a},[a,n,...t])}function Vr({range:e,children:t}){return m.jsx(he,{value:{range:e},children:t})}function _r(e,t){for(const r of t.items){if(r.type==="Canvas")return r;if(r.type==="SpecificResource")return r.source;if(r.type==="Range"){const n=_r(e,e.get(r));if(n)return n}}return null}function Pt(e,t){var n;const r=[];for(const i of t.items)if(i.type==="SpecificResource"&&((n=i.source)==null?void 0:n.type)==="Canvas"&&(i.source.id.indexOf("#")!==-1?r.push({id:i.source.id.split("#")[0],type:"Canvas"}):r.push(i.source)),i.type==="Range"&&r.push(...Pt(e,e.get(i))),i.type==="SpecificResource"){const s=typeof i.source=="string"?i.source:i.source.id;r.push({id:s,type:"Canvas"})}return r}function Rs(e,t,r){for(const n of t.structures){const i=Ot(e,e.get(n),r);if(i)return i}return null}function Ot(e,t,r){var n,i,s;for(const a of t.items){const o=(i=(n=a==null?void 0:a.source)==null?void 0:n.id)==null?void 0:i.split("#")[0];if(a.type==="SpecificResource"&&a.source===r||a.type==="SpecificResource"&&((s=a.source)==null?void 0:s.type)==="Canvas"&&r===o)return t;if(a.type==="Range"){const u=Ot(e,e.get(a),r);if(u)return u}}return null}function Is(e,t,r,n=!1){const i=t.behavior,s=r?e.get(r):null;if(!s)return[];const a=s.behavior,o=n?!1:i.includes("paged"),u=o?!1:i.includes("continuous"),d=o||u?!1:i.includes("individuals"),l=a.includes("facing-pages"),p=a.includes("non-paged");if(l||p||d||n)return[{id:s.id,type:"Canvas"}];const[g,b]=Lt(e,t);if(u)return g;const h=g.findIndex(x=>x.id===r);if(h===-1)return[];for(const x of b)if(x.includes(h))return x.map(A=>g[A]);return[{id:s.id,type:"Canvas"}]}function Lt(e,t,{disablePaging:r,skipNonPaged:n}={}){const i=t.behavior,s=i.includes("paged"),a=s?!1:i.includes("continuous"),o=s||a?!1:i.includes("individuals"),u=t.type==="Manifest"?t.items:Pt(e,t);if(a)return[u,[u.map((h,x)=>x)]];if(o||!s||r)return[u,u.map((h,x)=>[x])];const d=[];let l=[];const p=()=>{l.length&&(d.push([...l]),l=[])};let g=0,b=!1;for(let h=0;h<u.length;h++){const x=e.get(u[h]);if(x.behavior.includes("non-paged")){h===g&&g++,n||(p(),d.push([h]),p());continue}if(h===g||x.behavior.includes("facing-pages")){l.length&&(b=!0),p(),d.push([h]),p();continue}if(l.push(h),b){p(),b=!1;continue}l.length>1&&p()}return l.length&&p(),[u,d]}function Ur(e={},t=[]){const{id:r,selector:n}=e,i=se(),s=r||i.range,a=U(o=>s?o.iiif.entities.Range[s]:void 0,[s]);return v.useMemo(()=>{if(a)return n?n(a):a},[a,n,...t])}function Hr({startCanvas:e,disablePaging:t}){var h;const r=V(),n=ve(),i=Ur(),[s,a]=v.useState(void 0),o=i||n;if(!o)throw new Error("Nothing selected");const[u,d]=v.useMemo(()=>Lt(r,o,{disablePaging:t}),[r,o]),l=v.useCallback(x=>{const A=d.findIndex(S=>S.includes(x));a(A===-1?0:A)},[u,d]),p=v.useCallback(x=>{const A=u.findIndex(S=>S.id===x);A!==-1?l(A):a(0)},[u,d]),g=v.useCallback(()=>{a(x=>x>=d.length?x:x+1)},[d]),b=v.useCallback(()=>{a(x=>x<=0?0:x-1)},[d]);return typeof s>"u"&&(e?p(e):a(0)),{visibleItems:((h=d[s])==null?void 0:h.map(x=>u[x].id))||[],cursor:s,items:u,sequence:d,setSequenceIndex:a,setCanvasIndex:l,setCanvasId:p,next:g,previous:b}}const ke=()=>{},qe=v.createContext({setCurrentCanvasId:ke,setCurrentCanvasIndex:ke,nextCanvas:ke,previousCanvas:ke,items:[],sequence:[],setSequenceIndex:ke,currentSequenceIndex:0});function Nr(e){const t=ve(),{cursor:r,visibleItems:n,next:i,sequence:s,items:a,setCanvasIndex:o,setCanvasId:u,previous:d,setSequenceIndex:l}=Hr({startCanvas:e.startCanvas,disablePaging:e.pagingEnabled===!1}),p=v.useMemo(()=>({sequence:s,items:a,setCurrentCanvasId:u,nextCanvas:i,previousCanvas:d,totalCanvases:a.length,setCurrentCanvasIndex:o,setSequenceIndex:l,currentSequenceIndex:r}),[s,a,u,i,d,a,o,l,r]);return t?m.jsx(qe.Provider,{value:p,children:m.jsx(De.Provider,{value:n,children:m.jsx(Ke,{canvas:n[0],children:e.children})})}):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),m.jsx("div",{children:"Sorry, something went wrong."}))}function Br(e){const t=Dr(e.manifest);if(!t)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),m.jsx("div",{children:"Sorry, something went wrong."});if(t.error)return m.jsx("div",{children:t.error.toString()});if(!t.isLoaded)return m.jsx("div",{children:"Loading..."});const r=m.jsx(Nr,{...e,children:e.children});return m.jsx(qr,{manifest:t.id,children:e.rangeId?m.jsx(Vr,{range:e.rangeId,children:r}):r})}function zr(){return v.useContext(qe)}function Wr(){return{VaultContext:v.useContext($e),ResourceContext:v.useContext(Je),SimpleViewerReactContext:v.useContext(qe),VisibleCanvasReactContext:v.useContext(De)}}function Qr(e){return m.jsx(Tt,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext,children:m.jsx(De.Provider,{value:e.bridge.VisibleCanvasReactContext,children:m.jsx(qe.Provider,{value:e.bridge.SimpleViewerReactContext,children:e.children})})})}const te=function(e){return function(){const t={type:e,getType:()=>e,toString:()=>e};return(r,n)=>({...t,...r!==void 0&&{payload:r},...n!==void 0&&{meta:n}})}},ks="@iiif/IMPORT_ENTITIES",Ts="@iiif/MODIFY_ENTITY_FIELD",js="@iiif/REORDER_ENTITY_FIELD",Es="@iiif/ADD_REFERENCE",Ps="@iiif/UPDATE_REFERENCE",Os="@iiif/REMOVE_REFERENCE",Ls="@iiif/ADD_METADATA",Fs="@iiif/REMOVE_METADATA",$s="@iiif/UPDATE_METADATA",Ds="@iiif/REORDER_METADATA",qs=te(ks)(),Vs=te(Ts)(),_s=te(js)(),Us=te(Es)(),Hs=te(Os)(),Ns=te(Ps)(),Bs=te(Ls)(),zs=te($s)(),Ws=te(Fs)(),Qs=te(Ds)(),ft={importEntities:qs,modifyEntityField:Vs,reorderEntityField:_s,addReference:Us,removeReference:Hs,updateReference:Ns,addMetadata:Bs,removeMetadata:Ws,updateMetadata:zs,reorderMetadata:Qs};function Yr(){const t=V().getStore();return v.useMemo(()=>r=>t.dispatch(r),[t])}function rr(e){return typeof e!="string"&&e&&e.bindToVault}function Gr(){const e=V(),t=v.useRef([]),r=Yr(),n=v.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);v.useLayoutEffect(()=>{const o={id:n,type:"AnnotationPage",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],rendering:[],service:[]};r(ft.importEntities({entities:{AnnotationPage:{[o.id]:o}}}))},[n]);const i=U(o=>n?o.iiif.entities.AnnotationPage[n]:null,[n]),s=v.useCallback((o,u)=>{if(n){if(rr(o)){const p=o;p.__vault||p.bindToVault(e),o=typeof p.source=="string"?p.source:p.source.id,t.current[o]=p}else typeof o!="string"&&(o=o.id);const d=e.get({id:n,type:"AnnotationPage"}),l=e.get({id:o,type:"Annotation"});d&&l&&(d.items.find(p=>p.id===l.id)||r(ft.addReference({id:n,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"},index:u})))}},[n]),a=v.useCallback(o=>{n&&(rr(o)?o=typeof o.source=="string"?o.source:o.source.id:typeof o!="string"&&(o=o.id),t.current[o]&&t.current[o].beforeRemove(),e.get({id:n,type:"AnnotationPage"})&&r(ft.removeReference({id:n,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"}})))},[n]);return[i,{addAnnotation:s,removeAnnotation:a}]}const Jr=v.createContext(null);function Kr(){const e=v.useContext(Jr);return[e.fullPage,{addAnnotation:e.addAnnotation,removeAnnotation:e.removeAnnotation}]}function Zr({children:e}){const[t,{addAnnotation:r,removeAnnotation:n}]=Gr();return m.jsx(Jr.Provider,{value:v.useMemo(()=>({fullPage:t,addAnnotation:r,removeAnnotation:n}),[t]),children:e})}function Ys({width:e,style:t,height:r,error:n,resetErrorBoundary:i}){return m.jsxs("div",{style:{width:e,height:r,minHeight:500,...t||{},background:"#f9f9f9"},children:[m.jsx("h3",{children:"Error occurred"}),m.jsx("p",{children:n.message}),m.jsx("button",{onClick:i,children:"Reset"})]})}const Ze=v.createContext(null);function Xr(){return v.useContext(Ze)}const en=v.createContext(()=>{}),tn=v.createContext(()=>{});function Ie(e,t,r,n,i=[]){const s=v.useContext(e==="portal"?tn:en);v.useEffect(()=>(e!=="none"&&s(t,r,n),()=>{s(t,null)}),[t,e,s,...i])}function re(e={},t=[]){const{id:r,selector:n}=e,i=se(),s=r||i.canvas,a=U(o=>s?o.iiif.entities.Canvas[s]:void 0,[s]);return v.useMemo(()=>{if(a)return n?n(a):a},[a,n,...t])}const rn=v.createContext(()=>{});function Gs(e){const t=re(),r=v.useContext(rn);v.useEffect(()=>t&&t.id?(r(t.id,e),()=>r(t.id,-1)):()=>{},[t,e])}function Js({children:e,errorFallback:t,outerContainerProps:r={},worldScale:n,...i}){const[s,a]=v.useState(),o=Wr(),u=t||Ys,[d,l]=v.useState({}),p=Object.entries(d),[g,b]=v.useState({}),h=Object.entries(g),[x,A]=v.useState({}),S=v.useMemo(()=>n||Math.max(...Object.values(x)),[x]),w=v.useMemo(()=>({maxOverZoom:S||1,...i.runtimeOptions||{}}),[S,i.runtimeOptions]),M=v.useCallback((k,O)=>{A(P=>{if(O===-1){const{[k]:R,...$}=P;return $}return{...P,[k]:O}})},[]),T=v.useCallback((k,O,P)=>{l(({[k]:R,...$})=>O?{...$,[k]:{element:O,props:P}}:$)},[]),F=v.useCallback((k,O,P)=>{b(({[k]:R,...$})=>O?{...$,[k]:{element:O,props:P}}:$)},[]);return m.jsxs(Oi,{resetKeys:[],fallbackRender:k=>m.jsx(u,{...i,...k}),children:[m.jsx(Re.AtlasAuto,{...i,containerProps:{style:{position:"relative"},...i.containerProps||{}},htmlChildren:m.jsx(m.Fragment,{children:p.map(([k,{element:O,props:P}])=>m.jsx(v.Fragment,{children:m.jsx(O,{...P||{}})},k))}),onCreated:k=>{a(k),i.onCreated&&i.onCreated(k)},runtimeOptions:w,children:m.jsx(Ze.Provider,{value:s,children:m.jsx(rn.Provider,{value:M,children:m.jsx(en.Provider,{value:T,children:m.jsx(tn.Provider,{value:F,children:m.jsx(Qr,{bridge:o,children:m.jsx(Re.ModeContext.Provider,{value:i.mode||"explore",children:m.jsx(Zr,{children:e})})})})})})})}),m.jsx("div",{children:h.map(([k,{element:O,props:P}])=>m.jsx(v.Fragment,{children:m.jsx(O,{...P||{}})},k))})]})}const He={},nn={get(e){return e},setMetaValue([e,t,r],n){const i=nn.getResourceMeta(e,t),s=i?i[r]:void 0,a=typeof n=="function"?n(s):n;He[e]={...He[e]||{},[t]:{...(He[e]||{})[t]||{},[r]:a}}},getResourceMeta:(e,t)=>{const r=He[e];if(r)return t?r[t]:r}};function sn(e=nn){return{addEventListener(t,r,n,i){if(t)return e.setMetaValue([t.id,"eventManager",r],s=>{const a=s||[];for(const o of a)if(o.callback===n)return a;return[...a,{callback:n,scope:i}]}),n},removeEventListener(t,r,n){t&&e.setMetaValue([t.id,"eventManager",r],i=>(i||[]).filter(s=>s.callback!==n))},getListenersAsProps(t,r){const n=typeof t=="string"?{id:t}:t;if(!n||!n.id)return{};const i=e.getResourceMeta(n.id,"eventManager"),s={};if(i&&n)for(const a of Object.keys(i))s[a]=o=>{const u=e.get(n);for(const{callback:d,scope:l}of i[a]||[])(!l||r&&l.indexOf(r)!==-1)&&d(o,u)};return s}}}function Ft(e,t){const r=V(),n=v.useMemo(()=>sn(r),[r]),i=U(()=>e&&e.id?r.getResourceMeta(e.id,"eventManager"):null,[e]);return v.useMemo(()=>e?n.getListenersAsProps(e,t):{},[i,e,r,t])}const Ne={},an={get(e){return e},setMetaValue([e,t,r],n){const i=an.getResourceMeta(e,t),s=i?i[r]:void 0,a=typeof n=="function"?n(s):n;Ne[e]={...Ne[e]||{},[t]:{...(Ne[e]||{})[t]||{},[r]:a}}},getResourceMeta:(e,t)=>{const r=Ne[e];if(r)return t?r[t]:r}};function $t(e=an){return{applyStyles(t,r,n){const i=typeof t=="string"?t:t.id;return e.setMetaValue([i,"styles",r],n)},getAppliedStyles(t){const r=typeof t=="string"?t:t.id;return e.getResourceMeta(r,"styles")}}}function Fe(e,t){const r=V(),n=v.useMemo(()=>$t(r),[r]);return U(()=>{if(!e)return null;const i=n.getAppliedStyles(e.id);return i?t?i[t]:i:void 0},[e,t])}var Ks=Object.defineProperty,Zs=(e,t,r)=>t in e?Ks(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,We=(e,t,r)=>(Zs(e,typeof t!="symbol"?t+"":t,r),r),Xs=function(){function e(t,r){var n=[],i=!0,s=!1,a=void 0;try{for(var o=t[Symbol.iterator](),u;!(i=(u=o.next()).done)&&(n.push(u.value),!(r&&n.length===r));i=!0);}catch(d){s=!0,a=d}finally{try{!i&&o.return&&o.return()}finally{if(s)throw a}}return n}return function(t,r){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),je=Math.PI*2,pt=function(e,t,r,n,i,s,a){var o=e.x,u=e.y;o*=t,u*=r;var d=n*o-i*u,l=i*o+n*u;return{x:d+s,y:l+a}},ea=function(e,t){var r=t===1.5707963267948966?.551915024494:t===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(t/4),n=Math.cos(e),i=Math.sin(e),s=Math.cos(e+t),a=Math.sin(e+t);return[{x:n-i*r,y:i+n*r},{x:s+a*r,y:a-s*r},{x:s,y:a}]},nr=function(e,t,r,n){var i=e*n-t*r<0?-1:1,s=e*r+t*n;return s>1&&(s=1),s<-1&&(s=-1),i*Math.acos(s)},ta=function(e,t,r,n,i,s,a,o,u,d,l,p){var g=Math.pow(i,2),b=Math.pow(s,2),h=Math.pow(l,2),x=Math.pow(p,2),A=g*b-g*x-b*h;A<0&&(A=0),A/=g*x+b*h,A=Math.sqrt(A)*(a===o?-1:1);var S=A*i/s*p,w=A*-s/i*l,M=d*S-u*w+(e+r)/2,T=u*S+d*w+(t+n)/2,F=(l-S)/i,k=(p-w)/s,O=(-l-S)/i,P=(-p-w)/s,R=nr(1,0,F,k),$=nr(F,k,O,P);return o===0&&$>0&&($-=je),o===1&&$<0&&($+=je),[M,T,R,$]},ra=function(e){var t=e.px,r=e.py,n=e.cx,i=e.cy,s=e.rx,a=e.ry,o=e.xAxisRotation,u=o===void 0?0:o,d=e.largeArcFlag,l=d===void 0?0:d,p=e.sweepFlag,g=p===void 0?0:p,b=[];if(s===0||a===0)return[];var h=Math.sin(u*je/360),x=Math.cos(u*je/360),A=x*(t-n)/2+h*(r-i)/2,S=-h*(t-n)/2+x*(r-i)/2;if(A===0&&S===0)return[];s=Math.abs(s),a=Math.abs(a);var w=Math.pow(A,2)/Math.pow(s,2)+Math.pow(S,2)/Math.pow(a,2);w>1&&(s*=Math.sqrt(w),a*=Math.sqrt(w));var M=ta(t,r,n,i,s,a,l,g,h,x,A,S),T=Xs(M,4),F=T[0],k=T[1],O=T[2],P=T[3],R=Math.abs(P)/(je/4);Math.abs(1-R)<1e-7&&(R=1);var $=Math.max(Math.ceil(R),1);P/=$;for(var X=0;X<$;X++)b.push(ea(O,P)),O+=P;return b.map(function(Y){var _=pt(Y[0],s,a,x,h,F,k),H=_.x,J=_.y,ee=pt(Y[1],s,a,x,h,F,k),ge=ee.x,E=ee.y,N=pt(Y[2],s,a,x,h,F,k),G=N.x,ue=N.y;return{x1:H,y1:J,x2:ge,y2:E,x:G,y:ue}})};function on(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var na=sa,dt={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},ia=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function sa(e){var t=[];return e.replace(ia,function(r,n,i){var s=n.toLowerCase();for(i=oa(i),s=="m"&&i.length>2&&(t.push([n].concat(i.splice(0,2))),s="l",n=n=="m"?"l":"L");;){if(i.length==dt[s])return i.unshift(n),t.push(i);if(i.length<dt[s])throw new Error("malformed path data");t.push([n].concat(i.splice(0,dt[s])))}}),t}var aa=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function oa(e){var t=e.match(aa);return t?t.map(Number):[]}const ca=on(na);var ua=la;function la(e){var t=0,r=0,n=0,i=0;return e.map(function(s){s=s.slice();var a=s[0],o=a.toUpperCase();if(a!=o)switch(s[0]=o,a){case"a":s[6]+=n,s[7]+=i;break;case"v":s[1]+=i;break;case"h":s[1]+=n;break;default:for(var u=1;u<s.length;)s[u++]+=n,s[u++]+=i}switch(o){case"Z":n=t,i=r;break;case"H":n=s[1];break;case"V":i=s[1];break;case"M":n=t=s[1],i=r=s[2];break;default:n=s[s.length-2],i=s[s.length-1]}return s})}const fa=on(ua);function pa(e){const t=ca(e),r=fa(t);let n,i=0,s=0,a=0,o=0,u,d,l=0,p=0;const g=[];for(let b=0;b<r.length;b++){let h=r[b];const x=h[0];switch(x){case"M":i=h[1],s=h[2];break;case"H":h=["L",h[1],s];break;case"V":h=["L",i,h[1]];break;case"S":{let A=l,S=p;(n==="C"||n=="S")&&(A+=A-a,S+=S-o),h=["C",A,S,h[1],h[2],h[3],h[4]]}break;case"T":n==="Q"||n=="T"?(u=l*2-u,d=p*2-d):(u=l,d=p),h=["Q",u,d,h[1],h[2]];break;case"Q":u=h[1],d=h[2];break;case"A":{const A=ra({px:l,py:p,cx:h[6],cy:h[7],rx:h[1],ry:h[2],xAxisRotation:h[3],largeArcFlag:h[4],sweepFlag:h[5]});if(!A.length)continue;for(const[S,w]of A.entries())h=["C",w.x1,w.y1,w.x2,w.y2,w.x,w.y],S<A.length-1&&g.push(h);h=h}break;case"Z":h=["L",i,s];break}n=x,l=h[h.length-2],p=h[h.length-1],["C","Q","A"].indexOf(x)>-1?(a=h[h.length-4],o=h[h.length-3]):(a=l,o=p),g.push(h)}return g}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
|
|
5
|
+
`);const w=S.state[o];if(w==null)return;JSON.stringify(i.getState())!==JSON.stringify(w)&&b(w);return}i.dispatchFromDevtools&&typeof i.dispatch=="function"&&i.dispatch(S)});case"DISPATCH":switch(x.payload.type){case"RESET":return b(h),o===void 0?l==null?void 0:l.init(i.getState()):l==null?void 0:l.init(Ue(u.name));case"COMMIT":if(o===void 0){l==null||l.init(i.getState());return}return l==null?void 0:l.init(Ue(u.name));case"ROLLBACK":return ct(x.state,S=>{if(o===void 0){b(S),l==null||l.init(i.getState());return}b(S[o]),l==null||l.init(Ue(u.name))});case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return ct(x.state,S=>{if(o===void 0){b(S);return}JSON.stringify(i.getState())!==JSON.stringify(S[o])&&b(S[o])});case"IMPORT_STATE":{const{nextLiftedState:S}=x.payload,w=(A=S.computedStates.slice(-1)[0])==null?void 0:A.state;if(!w)return;b(o===void 0?w:w[o]),l==null||l.send(null,S);return}case"PAUSE_RECORDING":return g=!g}return}}),h},fs=ls,ct=(e,t)=>{let r;try{r=JSON.parse(e)}catch(n){console.error("[zustand devtools middleware] Could not parse the received json",n)}r!==void 0&&t(r)},ps=e=>(t,r,n)=>{const i=n.subscribe;return n.subscribe=(s,a,o)=>{let u=s;if(a){const f=(o==null?void 0:o.equalityFn)||Object.is;let l=s(n.getState());u=d=>{const g=s(d);if(!f(l,g)){const b=l;a(l=g,b)}},o!=null&&o.fireImmediately&&a(l,l)}return i(u)},e(t,r,n)},ds=ps,hs=(e={},t)=>{switch(t.type){case wr:return{...e,[t.payload.id]:t.payload.type};case Cr:return{...e,...t.payload.mapping};default:return e}};function ut(e,t,r,n){return!(!e[r]||!e[r][t]||!e[r][t][n]||!Array.isArray(e[r][t][n]))}function vs(e,t){const r={},n=[];for(const[i,s]of Object.entries(e||{})){n.push(i);const a=(t||{})[i];if(!a||a.length===0){r[i]=s;continue}r[i]=a}for(const[i,s]of Object.entries(t||{}))n.indexOf(i)===-1&&(r[i]=s);return r}function I(e){return e.payload}function lt(e,t){return typeof e>"u"?t:e}const ys=(e=Or(),t)=>{var r;const n=(i,s)=>({...e,[I(t).type]:{...e[I(t).type],[I(t).id]:{...i,...s}}});switch(t.type){case vr:{if(!e[I(t).type]||!e[I(t).type][I(t).id])return e;const i=e[I(t).type][I(t).id];return typeof i=="string"?e:n(i,{[I(t).key]:I(t).value})}case yr:{if(!ut(e,I(t).id,I(t).type,I(t).key))return e;const i=e[I(t).type][I(t).id];if(typeof i=="string")return e;const s=Array.from(i[I(t).key]),[a]=s.splice(I(t).startIndex,1);return s.splice(I(t).endIndex,0,a),n(i,{[I(t).key]:s})}case hr:{const i=Object.keys(I(t).entities),s={...e};for(const a of i){const o=I(t).entities[a],u={...e[a]||{}};let f=!1;const l=Object.keys(o||{})||[];if(o&&l){for(const d of l)f=!0,u[d]=e[a][d]?vs(e[a][d],o[d]):o[d];f&&(s[a]=u)}}return s}case gr:{if(!ut(e,I(t).id,I(t).type,I(t).key))return e;const i=e[I(t).type][I(t).id],s=Array.from(i[I(t).key]);return s.splice(lt(I(t).index,s.length+1),0,I(t).reference),n(i,{[I(t).key]:s})}case gt:case mr:{if(!ut(e,I(t).id,I(t).type,I(t).key))return e;const i=e[I(t).type][I(t).id],s=Array.from(i[I(t).key]),a=lt(I(t).index,s.findIndex(o=>o&&o.id===I(t).reference.id));return a===-1||((r=s[a])==null?void 0:r.id)!==I(t).reference.id?e:(t.type===gt?s.splice(a,1,I(t).reference):s.splice(a,1),n(i,{[I(t).key]:s}))}case xr:{const i=e[I(t).type][I(t).id];if(!i)return e;const s=Array.from(i.metadata||[]),a=I(t);return s.splice(lt(t.payload.beforeIndex,s.length+1),0,{label:a.label,value:a.label}),n(i,{metadata:s})}case Ar:{const i=e[I(t).type][I(t).id];if(typeof i=="string"||!i)return e;const s=Array.from(i.metadata||[]),[a]=s.splice(I(t).startIndex,1);return s.splice(I(t).endIndex,0,a),n(i,{metadata:s})}case mt:case br:{const i=e[I(t).type][I(t).id],s=Array.from(i.metadata||[]),a=I(t).atIndex;return typeof a>"u"||a===-1||!s[a]?e:(t.type===mt?s.splice(a,1,{label:I(t).label,value:I(t).value}):s.splice(a,1),n(i,{metadata:s}))}default:return e}},gs=(e={},t)=>{switch(t.type){case Tr:case Zi:return{...e,[t.payload.id]:{requestUri:t.payload.id,loadingState:kr,uriMismatch:!1,resourceUri:t.payload.id}};case Pr:return{...e,[t.payload.requestId]:{...e[t.payload.requestId]||{},uriMismatch:!0,resourceUri:t.payload.actualId},[t.payload.actualId]:{requestUri:t.payload.requestId,loadingState:e[t.payload.requestId].loadingState,uriMismatch:!0,resourceUri:t.payload.actualId}};case jr:return{...e,[t.payload.id]:{...e[t.payload.id]||{},loadingState:xt,error:t.payload.message}};case Er:return{...e,[t.payload.id]:{...e[t.payload.id]||{},loadingState:bt,error:void 0}}}return e},ms=(e={},t)=>{const{id:r,updateValue:n,value:i,meta:s,key:a}=t&&t.payload||{};switch(t.type){case Mr:return{...e,[r]:{...e[r]||{},[s]:{...e[r]?e[r][s]||{}:{},[a]:i}}};case Rr:return{...e,[r]:{...e[r]||{},[s]:{...e[r]?e[r][s]||{}:{},[a]:e[r]&&e[r][s]?n(e[r][s][a]):n(void 0)}}};case Ir:return e[r]&&e[r][s]&&e[r][s][a]?{...e,[r]:{...e[r]||{},[s]:{...e[r]?e[r][s]||{}:{},[a]:void 0}}}:e;default:return e}};function Lr(e={}){const t=Object.keys(e);return function(r={},n){let i=!1;const s={};for(let a=0;a<t.length;a++){const o=t[a];s[o]=e[o](r[o],n),i=i||s[o]!==r[o]}return i?s:r}}function xs(e){return(t,r)=>r&&r.type===Tt?r.payload.actions.reduce(e,t):r&&r.type===rs?{...t,iiif:{...t.iiif,...r.payload.state}}:e(t,r)}const bs=Lr({mapping:hs,entities:ys,requests:gs,meta:ms});function As(){return{iiif:{entities:Or(),meta:{},mapping:{},requests:{}}}}function Ss(e={}){const{enableDevtools:t=!1,iiifStoreName:r="iiif",defaultState:n=As(),customReducers:i={}}=e,s=xs(Lr({[r]:bs,...i}));return as(ds(fs(cs(s,n),{enabled:t})))}function ws(e){return{all:e=e||new Map,on:function(t,r){var n=e.get(t);n?n.push(r):e.set(t,[r])},off:function(t,r){var n=e.get(t);n&&(r?n.splice(n.indexOf(r)>>>0,1):e.set(t,[]))},emit:function(t,r){var n=e.get(t);n&&n.slice().map(function(i){i(r)}),(n=e.get("*"))&&n.slice().map(function(i){i(t,r)})}}}function z(e,t,r,n=!0){t[we]=t[we]||[],t[we].push(e);const i=new Map;Object.defineProperty(t,e,{enumerable:n,get(){if(typeof t[xe][e]>"u")return;const s=t[xe][e];if(!s)return s;const a=r.get(t[xe][e],{parent:this.id?{id:this.id,type:this.type}:void 0});return i.has(a)||(i.clear(),i.set(a,be(a,r))),i.get(a)},set(s){t[xe][e]!==s&&(this[me]?r.modifyEntityField({id:this.id,type:this.type},e,Fr(s)):this[xe][e]=s)}})}const xe=Symbol.for("_refs_"),me=Symbol.for("_reactive_"),we=Symbol.for("_defined_"),tr=Symbol.for("_parent_");function Cs(e,t=!1,r){const n={id:"",type:"unknown",[we]:[],[xe]:{},[tr]:r||null,[me]:null,is(i){return typeof i=="string"?this.id===i:i.id?i.id===this.id:!1},reactive(){if(!this[me])return this[me]=this.subscribe(()=>this.refresh(),!0),()=>{this.unreactive()}},refresh(){if(this.id){const i=this.unwrap();for(const s of Object.keys(i||{}))this[we].includes(s)?this[xe][s]=i[s]:this[s]=i[s]}},unreactive(){this[me]&&(this[me](),this[me]=null)},unwrap(){if(!this.id)throw new Error("Invalid object");const i=this[tr];return e.get(this.id,{parent:i?{id:i,type:"unknown"}:void 0})},toPresentation3(){return e.toPresentation3(this.unwrap())},toPresentation2(){return e.toPresentation2(this.unwrap())},valueOf(){return this.unwrap()},toJSON(){const i=this;return{...i,items:i.items,annotations:i.annotations,structures:i.structures,seeAlso:i.seeAlso,service:i.service,services:i.services,rendering:i.rendering,partOf:i.partOf,start:i.start,supplementary:i.supplementary,homepage:i.homepage,thumbnail:i.thumbnail,placeholderCanvas:i.placeholderCanvas,accompanyingCanvas:i.accompanyingCanvas,provider:i.provider}},subscribe(i,s=!0){return e.subscribe(()=>this.id?e.get(this.id):null,i,s)}};return z("items",n,e),z("annotations",n,e),z("structures",n,e),z("seeAlso",n,e),z("rendering",n,e),z("partOf",n,e),z("start",n,e,!1),z("supplementary",n,e),z("homepage",n,e),z("thumbnail",n,e),z("placeholderCanvas",n,e,!1),z("accompanyingCanvas",n,e,!1),z("provider",n,e),z("body",n,e),z("logo",n,e),n}function Ms(e){return!!e[we]}function Fr(e){return Array.isArray(e)?e.map(t=>Fr(t)):!e||!e.type?e:{id:e.id,type:e.type}}function be(e,t,r=!1,n){if(Array.isArray(e))return e.map(o=>be(o,t,r));if(!e||!e.type||!e.id)return e;const i=Cs(t,r),s=Object.create(i),a=Object.assign(s,e);return r&&a.reactive(),a}function rr(e){switch(e){case"Image":case"Video":case"Sound":case"Dataset":case"Text":case"Composite":case"List":case"Independents":case"Audience":return"ContentResource";case"ImageService1":case"ImageService2":case"ImageService3":return"Service"}return e}let Ct=class{constructor(t,r){pe(this,"options"),pe(this,"store"),pe(this,"emitter"),pe(this,"isBatching",!1),pe(this,"batchQueue",[]),pe(this,"remoteFetcher"),pe(this,"staticFetcher"),pe(this,"defaultFetcher",n=>fetch(n).then(i=>i.json())),this.options=Object.assign({reducers:{},customFetcher:this.defaultFetcher,enableDevtools:!0},t||{}),this.store=r||Ss({customReducers:this.options.reducers,defaultState:this.options.defaultState,enableDevtools:this.options.enableDevtools}),this.emitter=ws(),this.remoteFetcher=Xt(this,this.options.customFetcher),this.staticFetcher=Xt(this,(n,i)=>i)}batch(t){this.isBatching=!0;try{t(this),this.isBatching=!1,this.dispatch(St({actions:this.batchQueue}))}catch(r){throw this.batchQueue=[],this.isBatching=!1,r}this.batchQueue=[]}async asyncBatch(t){this.isBatching=!0;try{await t(this),this.isBatching=!1,this.dispatch(St({actions:this.batchQueue}))}catch(r){throw this.batchQueue=[],this.isBatching=!1,r}this.batchQueue=[]}modifyEntityField(t,r,n){this.dispatch(Wi.modifyEntityField({id:t.id,type:t.type,key:r,value:n}))}dispatch(t){if(this.isBatching)this.batchQueue.push(t);else{if(t.type===Tt){for(const i of t.payload.actions)this.emitter.emit(i.type,{action:i,state:this.store.getState()});this.store.dispatch(t);const n=this.getState();for(const i of t.payload.actions)this.emitter.emit(`after:${i.type}`,{action:i,state:n});return}this.emitter.emit(t.type,{action:t,state:this.store.getState()}),this.store.dispatch(t);const r=this.store.getState();this.emitter.emit(`after:${t.type}`,{action:t,state:r});return}}on(t,r){return this.emitter.on(t,r),()=>{this.emitter.off(t,r)}}serialize(t,r){return W.serialize(this.getState().iiif,t,r)}toPresentation2(t){return this.serialize(t,W.serializeConfigPresentation2)}toPresentation3(t){return this.serialize(t,W.serializeConfigPresentation3)}hydrate(t,r,n={}){return this.get(t,r,{...n,skipSelfReturn:!1})}get(t,r,n={}){typeof r!="string"&&(n=r||{},r=void 0);const{skipSelfReturn:i=!0}=n||{};let s=n.parent?typeof n.parent=="string"?n.parent:n.parent.id:void 0;if(Array.isArray(t))return t.map(d=>this.get(d,n));const a=this.getState();if(W.isSpecificResource(t)&&!n.preserveSpecificResources&&(t=t.source),typeof t=="string"){const d=rr(r||a.iiif.mapping[t]);if(!d)return i?null:{id:t,type:"unknown"};t={id:t,type:d}}if(t&&t.partOf&&!s&&!n.skipPartOfCheck){const d=Array.isArray(t.partOf)?t.partOf[0]:t.partOf;d&&(typeof d=="string"&&(s=d),typeof d.id=="string"&&(s=d.id))}const o=rr(r||(t==null?void 0:t.type)),u=t==null?void 0:t.id,f=a.iiif.entities[o];if(!f){const d=a.iiif.requests[u];return d&&d.resourceUri!==u?this.get(d.resourceUri,n):i?null:t}const l=f[t.id];if(l&&l[W.HAS_PART]){const d=l[W.HAS_PART].find(g=>s?g[W.PART_OF]===s:g[W.PART_OF]===l.id);return W.frameResource(l,d)}return f[t.id]||(i?null:t)}select(t){return t(this.getState())}getStore(){return this.store}getState(){return this.store.getState()}deep(t,r){if(typeof t>"u")return this.get(r,{skipSelfReturn:!1});if(typeof t=="function")try{const i=t(this.get(r,{skipSelfReturn:!1})),s=a=>this.deep(a,i);return s.size=Array.isArray(i)?i.length:1,s}catch{const i=s=>this.deep(s,void 0);return i.size=0,i}const n=i=>this.deep(i,t);return n.size=Array.isArray(t)?t.length:1,n}loadManifest(t,r){const n=typeof t=="string"?t:t.id;return this.load(n,r)}loadCollection(t,r){const n=typeof t=="string"?t:t.id;return this.load(n,r)}load(t,r){const n=typeof t=="string"?t:t.id;return r?Promise.resolve(this.staticFetcher(n,r)):Promise.resolve(this.remoteFetcher(n))}loadSync(t,r){const n=typeof t=="string"?t:t.id;return this.staticFetcher(n,r)}loadManifestSync(t,r){const n=typeof t=="string"?t:t.id;return this.loadSync(n,r)}loadCollectionSync(t,r){const n=typeof t=="string"?t:t.id;return this.loadSync(n,r)}areInputsEqual(t,r){return Zt(t,r)}subscribe(t,r,n){return typeof n>"u"&&(typeof r>"u"||r===!1||r===!0)&&(n=r,r=t,t=i=>i),this.store.subscribe(t,i=>r(i,this),{equalityFn:Zt,fireImmediately:!n})}async ensureLoaded(t){const r=typeof t=="string"?t:t.id;this.requestStatus(r)||await this.load(r)}requestStatus(t){return this.select(r=>r.iiif.requests[t])}getResourceMeta(t,r){const n=this.getState().iiif.meta[t];if(n)return r?n[r]:n}getObject(t,r,n={}){const{reactive:i,...s}=n;return be(this.get(t,r,s),this,i)}async loadObject(t,r){return be(await this.load(t,r),this)}async loadManifestObject(t,r){return be(await this.loadManifest(t,r),this)}async loadCollectionObject(t,r){return be(await this.loadCollection(t,r),this)}wrapObject(t){return be(this.get(t,{skipSelfReturn:!1}),this)}isWrapped(t){return Ms(t)}setMetaValue([t,r,n],i){this.dispatch(typeof i=="function"?Jt.setMetaValueDynamic({id:t,meta:r,key:n,updateValue:i}):Jt.setMetaValue({id:t,meta:r,key:n,value:i}))}};function Rs(){return typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{}}function $r(e){const t=Rs();try{const n=t.IIIF_VAULT;if(n)return n}catch{}const r=new Ct(e);try{t.IIIF_VAULT=r}catch{}return r}const $e=v.createContext({vault:null,setVaultInstance:e=>{}});function jt({vault:e,vaultOptions:t,useGlobal:r,resources:n,children:i}){const[s,a]=v.useState(()=>e||(r?$r(t):t?new Ct(t):new Ct));return m.jsx($e.Provider,{value:{vault:s,setVaultInstance:a},children:m.jsx(he,{value:n||{},children:i})})}const V=()=>{const{vault:e}=v.useContext($e);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};function Pt(e,{noCache:t=!1}={}){const r=typeof e=="string"?e:e.id,n=V(),[i,s]=v.useState(r),[a,o]=v.useState(void 0),u=v.useMemo(()=>n.get(r,{skipSelfReturn:!0})||void 0,[r,n]),[f,l]=v.useState(u);return v.useEffect(()=>{(async()=>{try{const d=u&&!t?u:await n.load(r),g=d?d.id||d["@id"]:null;d&&i!==g&&s(g),l(d)}catch(d){o(d)}})()},[r,t]),{isLoaded:!!f,id:i,requestId:r,error:a,resource:f,cached:!!(f&&f===u)}}function Dr(e,t){const{id:r,isLoaded:n,error:i,resource:s,requestId:a,cached:o}=Pt(e,t);return{id:r,isLoaded:n,error:i,manifest:s,requestId:a,cached:o}}function qr({manifest:e,children:t}){return m.jsx(he,{value:{manifest:e},children:t})}function Ke({canvas:e,children:t}){return m.jsx(he,{value:{canvas:e},children:t})}function U(e,t=[]){const r=V(),[n,i]=v.useState(()=>e(r.getState(),r));return v.useEffect(()=>r.subscribe(s=>e(s,r),s=>{i(s)},!1),t),n}const De=v.createContext([]);function Et(){const e=v.useContext(De);return U(t=>e.map(r=>t.iiif.entities.Canvas[r]).filter(Boolean),[e])}function ve(e={},t=[]){const{id:r,selector:n}=e,i=se();V();const s=r||i.manifest,a=U(o=>s?o.iiif.entities.Manifest[s]:void 0,[s]);return v.useMemo(()=>{if(a)return n?n(a):a},[a,n,...t])}function Vr({range:e,children:t}){return m.jsx(he,{value:{range:e},children:t})}function _r(e,t){for(const r of t.items){if(r.type==="Canvas")return r;if(r.type==="SpecificResource")return r.source;if(r.type==="Range"){const n=_r(e,e.get(r));if(n)return n}}return null}function Ot(e,t){var n;const r=[];for(const i of t.items)if(i.type==="SpecificResource"&&((n=i.source)==null?void 0:n.type)==="Canvas"&&(i.source.id.indexOf("#")!==-1?r.push({id:i.source.id.split("#")[0],type:"Canvas"}):r.push(i.source)),i.type==="Range"&&r.push(...Ot(e,e.get(i))),i.type==="SpecificResource"){const s=typeof i.source=="string"?i.source:i.source.id;r.push({id:s,type:"Canvas"})}return r}function Is(e,t,r){for(const n of t.structures){const i=Lt(e,e.get(n),r);if(i)return i}return null}function Lt(e,t,r){var n,i,s;for(const a of t.items){const o=(i=(n=a==null?void 0:a.source)==null?void 0:n.id)==null?void 0:i.split("#")[0];if(a.type==="SpecificResource"&&a.source===r||a.type==="SpecificResource"&&((s=a.source)==null?void 0:s.type)==="Canvas"&&r===o)return t;if(a.type==="Range"){const u=Lt(e,e.get(a),r);if(u)return u}}return null}function ks(e,t,r,n=!1){const i=t.behavior,s=r?e.get(r):null;if(!s)return[];const a=s.behavior,o=n?!1:i.includes("paged"),u=o?!1:i.includes("continuous"),f=o||u?!1:i.includes("individuals"),l=a.includes("facing-pages"),d=a.includes("non-paged");if(l||d||f||n)return[{id:s.id,type:"Canvas"}];const[g,b]=Ft(e,t);if(u)return g;const h=g.findIndex(x=>x.id===r);if(h===-1)return[];for(const x of b)if(x.includes(h))return x.map(A=>g[A]);return[{id:s.id,type:"Canvas"}]}function Ft(e,t,{disablePaging:r,skipNonPaged:n}={}){const i=t.behavior,s=i.includes("paged"),a=s?!1:i.includes("continuous"),o=s||a?!1:i.includes("individuals"),u=t.type==="Manifest"?t.items:Ot(e,t);if(a)return[u,[u.map((h,x)=>x)]];if(o||!s||r)return[u,u.map((h,x)=>[x])];const f=[];let l=[];const d=()=>{l.length&&(f.push([...l]),l=[])};let g=0,b=!1;for(let h=0;h<u.length;h++){const x=e.get(u[h]);if(x.behavior.includes("non-paged")){h===g&&g++,n||(d(),f.push([h]),d());continue}if(h===g||x.behavior.includes("facing-pages")){l.length&&(b=!0),d(),f.push([h]),d();continue}if(l.push(h),b){d(),b=!1;continue}l.length>1&&d()}return l.length&&d(),[u,f]}function Ur(e={},t=[]){const{id:r,selector:n}=e,i=se(),s=r||i.range,a=U(o=>s?o.iiif.entities.Range[s]:void 0,[s]);return v.useMemo(()=>{if(a)return n?n(a):a},[a,n,...t])}function Hr({startCanvas:e,disablePaging:t}){var h;const r=V(),n=ve(),i=Ur(),[s,a]=v.useState(void 0),o=i||n;if(!o)throw new Error("Nothing selected");const[u,f]=v.useMemo(()=>Ft(r,o,{disablePaging:t}),[r,o]),l=v.useCallback(x=>{const A=f.findIndex(S=>S.includes(x));a(A===-1?0:A)},[u,f]),d=v.useCallback(x=>{const A=u.findIndex(S=>S.id===x);A!==-1?l(A):a(0)},[u,f]),g=v.useCallback(()=>{a(x=>x>=f.length?x:x+1)},[f]),b=v.useCallback(()=>{a(x=>x<=0?0:x-1)},[f]);return typeof s>"u"&&(e?d(e):a(0)),{visibleItems:((h=f[s])==null?void 0:h.map(x=>u[x].id))||[],cursor:s,items:u,sequence:f,setSequenceIndex:a,setCanvasIndex:l,setCanvasId:d,next:g,previous:b}}const ke=()=>{},qe=v.createContext({setCurrentCanvasId:ke,setCurrentCanvasIndex:ke,nextCanvas:ke,previousCanvas:ke,items:[],sequence:[],setSequenceIndex:ke,currentSequenceIndex:0});function Nr(e){const t=ve(),{cursor:r,visibleItems:n,next:i,sequence:s,items:a,setCanvasIndex:o,setCanvasId:u,previous:f,setSequenceIndex:l}=Hr({startCanvas:e.startCanvas,disablePaging:e.pagingEnabled===!1}),d=v.useMemo(()=>({sequence:s,items:a,setCurrentCanvasId:u,nextCanvas:i,previousCanvas:f,totalCanvases:a.length,setCurrentCanvasIndex:o,setSequenceIndex:l,currentSequenceIndex:r}),[s,a,u,i,f,a,o,l,r]);return t?m.jsx(qe.Provider,{value:d,children:m.jsx(De.Provider,{value:n,children:m.jsx(Ke,{canvas:n[0],children:e.children})})}):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),m.jsx("div",{children:"Sorry, something went wrong."}))}function Br(e){const t=Dr(e.manifest);if(!t)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),m.jsx("div",{children:"Sorry, something went wrong."});if(t.error)return m.jsx("div",{children:t.error.toString()});if(!t.isLoaded)return m.jsx("div",{children:"Loading..."});const r=m.jsx(Nr,{...e,children:e.children});return m.jsx(qr,{manifest:t.id,children:e.rangeId?m.jsx(Vr,{range:e.rangeId,children:r}):r})}function zr(){return v.useContext(qe)}function Wr(){return{VaultContext:v.useContext($e),ResourceContext:v.useContext(Je),SimpleViewerReactContext:v.useContext(qe),VisibleCanvasReactContext:v.useContext(De)}}function Qr(e){return m.jsx(jt,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext,children:m.jsx(De.Provider,{value:e.bridge.VisibleCanvasReactContext,children:m.jsx(qe.Provider,{value:e.bridge.SimpleViewerReactContext,children:e.children})})})}const te=function(e){return function(){const t={type:e,getType:()=>e,toString:()=>e};return(r,n)=>({...t,...r!==void 0&&{payload:r},...n!==void 0&&{meta:n}})}},Ts="@iiif/IMPORT_ENTITIES",js="@iiif/MODIFY_ENTITY_FIELD",Ps="@iiif/REORDER_ENTITY_FIELD",Es="@iiif/ADD_REFERENCE",Os="@iiif/UPDATE_REFERENCE",Ls="@iiif/REMOVE_REFERENCE",Fs="@iiif/ADD_METADATA",$s="@iiif/REMOVE_METADATA",Ds="@iiif/UPDATE_METADATA",qs="@iiif/REORDER_METADATA",Vs=te(Ts)(),_s=te(js)(),Us=te(Ps)(),Hs=te(Es)(),Ns=te(Ls)(),Bs=te(Os)(),zs=te(Fs)(),Ws=te(Ds)(),Qs=te($s)(),Ys=te(qs)(),ft={importEntities:Vs,modifyEntityField:_s,reorderEntityField:Us,addReference:Hs,removeReference:Ns,updateReference:Bs,addMetadata:zs,removeMetadata:Qs,updateMetadata:Ws,reorderMetadata:Ys};function Yr(){const t=V().getStore();return v.useMemo(()=>r=>t.dispatch(r),[t])}function nr(e){return typeof e!="string"&&e&&e.bindToVault}function Gr(){const e=V(),t=v.useRef([]),r=Yr(),n=v.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);v.useLayoutEffect(()=>{const o={id:n,type:"AnnotationPage",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],rendering:[],service:[]};r(ft.importEntities({entities:{AnnotationPage:{[o.id]:o}}}))},[n]);const i=U(o=>n?o.iiif.entities.AnnotationPage[n]:null,[n]),s=v.useCallback((o,u)=>{if(n){if(nr(o)){const d=o;d.__vault||d.bindToVault(e),o=typeof d.source=="string"?d.source:d.source.id,t.current[o]=d}else typeof o!="string"&&(o=o.id);const f=e.get({id:n,type:"AnnotationPage"}),l=e.get({id:o,type:"Annotation"});f&&l&&(f.items.find(d=>d.id===l.id)||r(ft.addReference({id:n,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"},index:u})))}},[n]),a=v.useCallback(o=>{n&&(nr(o)?o=typeof o.source=="string"?o.source:o.source.id:typeof o!="string"&&(o=o.id),t.current[o]&&t.current[o].beforeRemove(),e.get({id:n,type:"AnnotationPage"})&&r(ft.removeReference({id:n,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"}})))},[n]);return[i,{addAnnotation:s,removeAnnotation:a}]}const Jr=v.createContext(null);function Kr(){const e=v.useContext(Jr);return[e.fullPage,{addAnnotation:e.addAnnotation,removeAnnotation:e.removeAnnotation}]}function Zr({children:e}){const[t,{addAnnotation:r,removeAnnotation:n}]=Gr();return m.jsx(Jr.Provider,{value:v.useMemo(()=>({fullPage:t,addAnnotation:r,removeAnnotation:n}),[t]),children:e})}function Gs({width:e,style:t,height:r,error:n,resetErrorBoundary:i}){return m.jsxs("div",{style:{width:e,height:r,minHeight:500,...t||{},background:"#f9f9f9"},children:[m.jsx("h3",{children:"Error occurred"}),m.jsx("p",{children:n.message}),m.jsx("button",{onClick:i,children:"Reset"})]})}const Ze=v.createContext(null);function Xr(){return v.useContext(Ze)}const en=v.createContext(()=>{}),tn=v.createContext(()=>{});function Ie(e,t,r,n,i=[]){const s=v.useContext(e==="portal"?tn:en);v.useEffect(()=>(e!=="none"&&s(t,r,n),()=>{s(t,null)}),[t,e,s,...i])}function re(e={},t=[]){const{id:r,selector:n}=e,i=se(),s=r||i.canvas,a=U(o=>s?o.iiif.entities.Canvas[s]:void 0,[s]);return v.useMemo(()=>{if(a)return n?n(a):a},[a,n,...t])}const rn=v.createContext(()=>{});function Js(e){const t=re(),r=v.useContext(rn);v.useEffect(()=>t&&t.id?(r(t.id,e),()=>r(t.id,-1)):()=>{},[t,e])}function Ks({children:e,errorFallback:t,outerContainerProps:r={},worldScale:n,...i}){const[s,a]=v.useState(),o=Wr(),u=t||Gs,[f,l]=v.useState({}),d=Object.entries(f),[g,b]=v.useState({}),h=Object.entries(g),[x,A]=v.useState({}),S=v.useMemo(()=>n||Math.max(...Object.values(x)),[x]),w=v.useMemo(()=>({maxOverZoom:S||1,...i.runtimeOptions||{}}),[S,i.runtimeOptions]),M=v.useCallback((k,O)=>{A(E=>{if(O===-1){const{[k]:R,...$}=E;return $}return{...E,[k]:O}})},[]),T=v.useCallback((k,O,E)=>{l(({[k]:R,...$})=>O?{...$,[k]:{element:O,props:E}}:$)},[]),F=v.useCallback((k,O,E)=>{b(({[k]:R,...$})=>O?{...$,[k]:{element:O,props:E}}:$)},[]);return m.jsxs(Oi,{resetKeys:[],fallbackRender:k=>m.jsx(u,{...i,...k}),children:[m.jsx(Re.AtlasAuto,{...i,containerProps:{style:{position:"relative"},...i.containerProps||{}},htmlChildren:m.jsx(m.Fragment,{children:d.map(([k,{element:O,props:E}])=>m.jsx(v.Fragment,{children:m.jsx(O,{...E||{}})},k))}),onCreated:k=>{a(k),i.onCreated&&i.onCreated(k)},runtimeOptions:w,children:m.jsx(Ze.Provider,{value:s,children:m.jsx(rn.Provider,{value:M,children:m.jsx(en.Provider,{value:T,children:m.jsx(tn.Provider,{value:F,children:m.jsx(Qr,{bridge:o,children:m.jsx(Re.ModeContext.Provider,{value:i.mode||"explore",children:m.jsx(Zr,{children:e})})})})})})})}),m.jsx("div",{children:h.map(([k,{element:O,props:E}])=>m.jsx(v.Fragment,{children:m.jsx(O,{...E||{}})},k))})]})}const He={},nn={get(e){return e},setMetaValue([e,t,r],n){const i=nn.getResourceMeta(e,t),s=i?i[r]:void 0,a=typeof n=="function"?n(s):n;He[e]={...He[e]||{},[t]:{...(He[e]||{})[t]||{},[r]:a}}},getResourceMeta:(e,t)=>{const r=He[e];if(r)return t?r[t]:r}};function sn(e=nn){return{addEventListener(t,r,n,i){if(t)return e.setMetaValue([t.id,"eventManager",r],s=>{const a=s||[];for(const o of a)if(o.callback===n)return a;return[...a,{callback:n,scope:i}]}),n},removeEventListener(t,r,n){t&&e.setMetaValue([t.id,"eventManager",r],i=>(i||[]).filter(s=>s.callback!==n))},getListenersAsProps(t,r){const n=typeof t=="string"?{id:t}:t;if(!n||!n.id)return{};const i=e.getResourceMeta(n.id,"eventManager"),s={};if(i&&n)for(const a of Object.keys(i))s[a]=o=>{const u=e.get(n);for(const{callback:f,scope:l}of i[a]||[])(!l||r&&l.indexOf(r)!==-1)&&f(o,u)};return s}}}function $t(e,t){const r=V(),n=v.useMemo(()=>sn(r),[r]),i=U(()=>e&&e.id?r.getResourceMeta(e.id,"eventManager"):null,[e]);return v.useMemo(()=>e?n.getListenersAsProps(e,t):{},[i,e,r,t])}const Ne={},an={get(e){return e},setMetaValue([e,t,r],n){const i=an.getResourceMeta(e,t),s=i?i[r]:void 0,a=typeof n=="function"?n(s):n;Ne[e]={...Ne[e]||{},[t]:{...(Ne[e]||{})[t]||{},[r]:a}}},getResourceMeta:(e,t)=>{const r=Ne[e];if(r)return t?r[t]:r}};function Dt(e=an){return{applyStyles(t,r,n){const i=typeof t=="string"?t:t.id;return e.setMetaValue([i,"styles",r],n)},getAppliedStyles(t){const r=typeof t=="string"?t:t.id;return e.getResourceMeta(r,"styles")}}}function Fe(e,t){const r=V(),n=v.useMemo(()=>Dt(r),[r]);return U(()=>{if(!e)return null;const i=n.getAppliedStyles(e.id);return i?t?i[t]:i:void 0},[e,t])}var Zs=Object.defineProperty,Xs=(e,t,r)=>t in e?Zs(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,We=(e,t,r)=>(Xs(e,typeof t!="symbol"?t+"":t,r),r),ea=function(){function e(t,r){var n=[],i=!0,s=!1,a=void 0;try{for(var o=t[Symbol.iterator](),u;!(i=(u=o.next()).done)&&(n.push(u.value),!(r&&n.length===r));i=!0);}catch(f){s=!0,a=f}finally{try{!i&&o.return&&o.return()}finally{if(s)throw a}}return n}return function(t,r){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),je=Math.PI*2,pt=function(e,t,r,n,i,s,a){var o=e.x,u=e.y;o*=t,u*=r;var f=n*o-i*u,l=i*o+n*u;return{x:f+s,y:l+a}},ta=function(e,t){var r=t===1.5707963267948966?.551915024494:t===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(t/4),n=Math.cos(e),i=Math.sin(e),s=Math.cos(e+t),a=Math.sin(e+t);return[{x:n-i*r,y:i+n*r},{x:s+a*r,y:a-s*r},{x:s,y:a}]},ir=function(e,t,r,n){var i=e*n-t*r<0?-1:1,s=e*r+t*n;return s>1&&(s=1),s<-1&&(s=-1),i*Math.acos(s)},ra=function(e,t,r,n,i,s,a,o,u,f,l,d){var g=Math.pow(i,2),b=Math.pow(s,2),h=Math.pow(l,2),x=Math.pow(d,2),A=g*b-g*x-b*h;A<0&&(A=0),A/=g*x+b*h,A=Math.sqrt(A)*(a===o?-1:1);var S=A*i/s*d,w=A*-s/i*l,M=f*S-u*w+(e+r)/2,T=u*S+f*w+(t+n)/2,F=(l-S)/i,k=(d-w)/s,O=(-l-S)/i,E=(-d-w)/s,R=ir(1,0,F,k),$=ir(F,k,O,E);return o===0&&$>0&&($-=je),o===1&&$<0&&($+=je),[M,T,R,$]},na=function(e){var t=e.px,r=e.py,n=e.cx,i=e.cy,s=e.rx,a=e.ry,o=e.xAxisRotation,u=o===void 0?0:o,f=e.largeArcFlag,l=f===void 0?0:f,d=e.sweepFlag,g=d===void 0?0:d,b=[];if(s===0||a===0)return[];var h=Math.sin(u*je/360),x=Math.cos(u*je/360),A=x*(t-n)/2+h*(r-i)/2,S=-h*(t-n)/2+x*(r-i)/2;if(A===0&&S===0)return[];s=Math.abs(s),a=Math.abs(a);var w=Math.pow(A,2)/Math.pow(s,2)+Math.pow(S,2)/Math.pow(a,2);w>1&&(s*=Math.sqrt(w),a*=Math.sqrt(w));var M=ra(t,r,n,i,s,a,l,g,h,x,A,S),T=ea(M,4),F=T[0],k=T[1],O=T[2],E=T[3],R=Math.abs(E)/(je/4);Math.abs(1-R)<1e-7&&(R=1);var $=Math.max(Math.ceil(R),1);E/=$;for(var X=0;X<$;X++)b.push(ta(O,E)),O+=E;return b.map(function(Y){var _=pt(Y[0],s,a,x,h,F,k),H=_.x,J=_.y,ee=pt(Y[1],s,a,x,h,F,k),ge=ee.x,P=ee.y,N=pt(Y[2],s,a,x,h,F,k),G=N.x,ue=N.y;return{x1:H,y1:J,x2:ge,y2:P,x:G,y:ue}})};function on(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ia=aa,dt={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},sa=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function aa(e){var t=[];return e.replace(sa,function(r,n,i){var s=n.toLowerCase();for(i=ca(i),s=="m"&&i.length>2&&(t.push([n].concat(i.splice(0,2))),s="l",n=n=="m"?"l":"L");;){if(i.length==dt[s])return i.unshift(n),t.push(i);if(i.length<dt[s])throw new Error("malformed path data");t.push([n].concat(i.splice(0,dt[s])))}}),t}var oa=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function ca(e){var t=e.match(oa);return t?t.map(Number):[]}const ua=on(ia);var la=fa;function fa(e){var t=0,r=0,n=0,i=0;return e.map(function(s){s=s.slice();var a=s[0],o=a.toUpperCase();if(a!=o)switch(s[0]=o,a){case"a":s[6]+=n,s[7]+=i;break;case"v":s[1]+=i;break;case"h":s[1]+=n;break;default:for(var u=1;u<s.length;)s[u++]+=n,s[u++]+=i}switch(o){case"Z":n=t,i=r;break;case"H":n=s[1];break;case"V":i=s[1];break;case"M":n=t=s[1],i=r=s[2];break;default:n=s[s.length-2],i=s[s.length-1]}return s})}const pa=on(la);function da(e){const t=ua(e),r=pa(t);let n,i=0,s=0,a=0,o=0,u,f,l=0,d=0;const g=[];for(let b=0;b<r.length;b++){let h=r[b];const x=h[0];switch(x){case"M":i=h[1],s=h[2];break;case"H":h=["L",h[1],s];break;case"V":h=["L",i,h[1]];break;case"S":{let A=l,S=d;(n==="C"||n=="S")&&(A+=A-a,S+=S-o),h=["C",A,S,h[1],h[2],h[3],h[4]]}break;case"T":n==="Q"||n=="T"?(u=l*2-u,f=d*2-f):(u=l,f=d),h=["Q",u,f,h[1],h[2]];break;case"Q":u=h[1],f=h[2];break;case"A":{const A=na({px:l,py:d,cx:h[6],cy:h[7],rx:h[1],ry:h[2],xAxisRotation:h[3],largeArcFlag:h[4],sweepFlag:h[5]});if(!A.length)continue;for(const[S,w]of A.entries())h=["C",w.x1,w.y1,w.x2,w.y2,w.x,w.y],S<A.length-1&&g.push(h);h=h}break;case"Z":h=["L",i,s];break}n=x,l=h[h.length-2],d=h[h.length-1],["C","Q","A"].indexOf(x)>-1?(a=h[h.length-4],o=h[h.length-3]):(a=l,o=d),g.push(h)}return g}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
|
|
6
6
|
*
|
|
7
7
|
* All code in this module is based on JavaScript code by Raph Levien, published on his blog at
|
|
8
8
|
* https://raphlinus.github.io/.
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
33
33
|
* See the License for the specific language governing permissions and
|
|
34
34
|
* limitations under the License.
|
|
35
|
-
*/function da(e,t,r,n=1){return new cn(e,t,r).subdivide(n)}function ha(e,t,r,n,i=1){return new Dt(new Float64Array([e.x,e.y,t.x,t.y,r.x,r.y,n.x,n.y])).subdivide(i)}function va(e){return e.x*e.x+e.y*e.y}function Ee(e){return e/(1-.67+Math.pow(Math.pow(.67,4)+.25*e*e,.25))}function Ce(e){return e*(1-.39+Math.sqrt(.39*.39+.25*e*e))}class cn{constructor(t,r,n){We(this,"start"),We(this,"control"),We(this,"end"),this.start=t,this.control=r,this.end=n}eval(t){const r=1-t;return{x:this.start.x*r*r+2*this.control.x*r*t+this.end.x*t*t,y:this.start.y*r*r+2*this.control.y*r*t+this.end.y*t*t}}mapToBasic(){const{x:t,y:r}=this.start,{x:n,y:i}=this.control,{x:s,y:a}=this.end,o=2*n-t-s,u=2*i-r-a,d=(n-t)*o+(i-r)*u,l=(s-n)*o+(a-i)*u,p=(s-t)*u-(a-r)*o,g=d/p,b=l/p,h=Math.abs(p)/(Math.hypot(o,u)*Math.abs(b-g));return{x0:t,x2:s,scale:h,cross:p}}subdivide(t){const r=this.mapToBasic(),n=Ee(r.x0),i=Ee(r.x2),s=.5*Math.abs(i-n)*Math.sqrt(r.scale/t),a=Math.ceil(s),o=Ce(n),u=Ce(i),d=[0];for(let l=1;l<a;l++){const p=(Ce(n+(i-n)*l/a)-o)/(u-o);d.push(p)}return d.push(1),d.map(l=>this.eval(l))}}class Dt{constructor(t){We(this,"c"),this.c=t}weightsum(t,r,n,i){const s=t*this.c[0]+r*this.c[2]+n*this.c[4]+i*this.c[6],a=t*this.c[1]+r*this.c[3]+n*this.c[5]+i*this.c[7];return{x:s,y:a}}eval(t){const r=1-t,n=r*r*r,i=3*r*r*t,s=3*r*t*t,a=t*t*t;return this.weightsum(n,i,s,a)}deriv(t){const r=1-t,n=-3*r*r,i=3*t*t,s=-6*t*r-n,a=6*t*r-i;return this.weightsum(n,s,a,i)}midpoint_quadbez(){const t=this.weightsum(-.25,.75,.75,-.25);return new cn({x:this.c[0],y:this.c[1]},t,{x:this.c[6],y:this.c[7]})}subsegment(t,r){const n=new Float64Array(8),i=this.eval(t),s=this.eval(r);n[0]=i.x,n[1]=i.y;const a=(r-t)/3,o=this.deriv(t);n[2]=i.x+a*o.x,n[3]=i.y+a*o.y;const u=this.deriv(r);return n[4]=s.x-a*u.x,n[5]=s.y-a*u.y,n[6]=s.x,n[7]=s.y,new Dt(n)}subdivide(t){const r=.1*t,n=t-r,i=Math.sqrt(n),s=va(this.weightsum(1,-3,3,-1)),a=Math.ceil(Math.pow(s/(432*r*r),1/6)),o=[];let u=0;for(let h=0;h<a;h++){const x=h/a,A=(h+1)/a,S=this.subsegment(x,A).midpoint_quadbez(),w=S.mapToBasic(),M=Ee(w.x0),T=Ee(w.x2),F=Math.sqrt(w.scale);let k=Math.abs(T-M)*F;if(Math.sign(w.x0)!=Math.sign(w.x2)){const O=i/F,P=i*Math.abs(T-M)/Ee(O);k=Math.max(k,P)}o.push({quad:S,a0:M,a2:T,val:k}),u+=k}const d=.5*u/i,l=Math.ceil(d),p=[{x:this.c[0],y:this.c[1]}];let g=0,b=0;for(let h=1;h<l;h++){const x=u*h/l;for(;g+o[b].val<x;)g+=o[b].val,b++;const A=o[b].a0,S=o[b].a2,w=Ce(A),M=Ce(S),T=A+(S-A)*(x-g)/o[b].val,F=(Ce(T)-w)/(M-w);p.push(o[b].quad.eval(F))}return p.push({x:this.c[6],y:this.c[7]}),p}}const ya=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,ga=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,ir=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function Pe(e,{domParser:t,svgPreprocessor:r,iiifRenderingHints:n}={}){if(Array.isArray(e))return K(e.reduce((i,s)=>{const{selector:a,selectors:o,iiifRenderingHints:u}=Pe(s,{domParser:t,svgPreprocessor:r,iiifRenderingHints:n});return a&&(i.selector||(i.selector=a),i.selectors.push(...o)),u&&(i.iiifRenderingHints=i.iiifRenderingHints||{type:"ImageApiSelector"},Object.assign(i.iiifRenderingHints,u)),i},{selector:null,selectors:[],iiifRenderingHints:n}));if(!e)return K({selector:null,selectors:[],iiifRenderingHints:n});if(typeof e=="string"){const[i,s]=e.split("#");return s?Pe({type:"FragmentSelector",value:s},{svgPreprocessor:r,iiifRenderingHints:n,domParser:t}):K({selector:null,selectors:[],iiifRenderingHints:n})}if(e.type&&e.type==="PointSelector"&&(e.t||e.t===0)){const i={type:"TemporalSelector",temporal:{startTime:e.t}};return K({selector:i,selectors:[i],iiifRenderingHints:n})}if(ln(e)){const i=[];if(e.region){const s=Pe({type:"FragmentSelector",value:"xywh="+e.region},{domParser:t,svgPreprocessor:r,iiifRenderingHints:n});i.push(...s.selectors)}return K({selector:i[0],selectors:i,iiifRenderingHints:n?{...n,...e}:e})}if(e.type==="FragmentSelector"){const i=ya.exec(e.value);if(i){const a={type:"BoxSelector",spatial:{unit:i[2]==="percent:"||i[2]==="pct:"?"percent":"pixel",x:parseFloat(i[3]),y:parseFloat(i[4]),width:parseFloat(i[5]),height:parseFloat(i[6])}};return K({selector:a,selectors:[a],iiifRenderingHints:n})}const s=e.value.match(ga);if(s){const a={type:"TemporalSelector",temporal:{startTime:s[4]?parseFloat(s[4]):0,endTime:s[7]?parseFloat(s[7]):void 0}};return K({selector:a,selectors:[a],iiifRenderingHints:n})}return K({selector:null,selectors:[],iiifRenderingHints:n})}if(e.type==="SvgSelector"&&"value"in e){t||(typeof window<"u"?t=new window.DOMParser:console.warn("No DOMParser available, cannot parse SVG selector, `points`, `spatial` and `style` will be unavailable and the SVG will not be normalized."));let i=[],s,a,o=(r==null?void 0:r(e.value))??e.value,u;if(t){const l=t.parseFromString(e.value,"image/svg+xml").querySelector("svg");if(!l)return console.warn(`Illegal SVG selector: ${e.value}`),K({selector:null,selectors:[],iiifRenderingHints:n});const p=un(l);p&&(i=p.points,u=p.shapeType,s=[Math.min(...i.map(g=>g[0])),Math.min(...i.map(g=>g[1])),Math.max(...i.map(g=>g[0])),Math.max(...i.map(g=>g[1]))],{style:a,svg:o}=ba(p.element)??{svg:o})}const d={type:"SvgSelector",svg:o,svgShape:u,style:a,points:i.length?i:void 0,spatial:s?{unit:"pixel",x:s[0],y:s[1],width:s[2]-s[0],height:s[3]-s[1]}:void 0};return K({selector:d,selectors:[d],iiifRenderingHints:n})}return K({selector:null,selectors:[],iiifRenderingHints:n})}function ma(e){const t=e.map(n=>n[0]).reduce((n,i)=>(n[i]+=1,n),{C:0,Q:0,L:0,M:0}),r=new Set(e.map(n=>n[0]));if(t.C>0||t.Q>0)return"path";if(t.L>0&&(r.size===1||r.size===2&&r.has("M"))){if(t.L===4)return"rect";const n=e.slice(-1)[0];return e[0][0]==="M"&&n[0]==="L"&&n[1]==e[0][1]&&n[2]===e[0][2]||n[1]===0&&n[2]===0?"polygon":"polyline"}return"path"}function un(e){var t;for(const r of Array.from(e.children))switch(r==null?void 0:r.tagName.toLowerCase()){case"g":{const n=un(r);if(n)return n}continue;case"path":{const n=r.getAttribute("d");if(!n)continue;const i=pa(n);return{element:r,points:xa(i),shapeType:ma(i)}}case"circle":{const n=parseFloat(r.getAttribute("cx")??"0"),i=parseFloat(r.getAttribute("cy")??"0"),s=parseFloat(r.getAttribute("r")??"0");if(!s)continue;const a=[];for(let o=0;o<=360;o+=12){const u=o*Math.PI/180;a.push([n+s*Math.cos(u),i+s*Math.sin(u)])}return{element:r,points:a,shapeType:"circle"}}case"ellipse":{const n=parseFloat(r.getAttribute("cx")??"0"),i=parseFloat(r.getAttribute("cy")??"0"),s=parseFloat(r.getAttribute("rx")??"0"),a=parseFloat(r.getAttribute("ry")??"0");if(!s&&!a)continue;const o=[];for(let u=0;u<=360;u+=12){const d=Math.tan(u/360*Math.PI),l=s*(1-d**2)/(1+d**2),p=a*2*d/(1+d**2);o.push([n+l,i+p])}return{element:r,points:o,shapeType:"ellipse"}}case"line":{const n=parseFloat(r.getAttribute("x0")??"0"),i=parseFloat(r.getAttribute("y0")??"0"),s=parseFloat(r.getAttribute("x1")??"0"),a=parseFloat(r.getAttribute("y1")??"0");if(n===s&&i===a)continue;return{element:r,points:[[n,i],[s,a]],shapeType:"polyline"}}case"polygon":case"polyline":{const n=((t=r.getAttribute("points"))==null?void 0:t.split(" ").map(s=>s.split(",").map(parseFloat)))??[];if(!n.length)continue;let i="polyline";return r.tagName.toLowerCase()==="polygon"&&(n.push(n[0]),i="polygon"),{element:r,points:n,shapeType:i}}case"rect":{const n=parseFloat(r.getAttribute("x")??"0"),i=parseFloat(r.getAttribute("y")??"0"),s=parseFloat(r.getAttribute("width")??"0"),a=parseFloat(r.getAttribute("height")??"0");if(!s||!a)continue;return{element:r,points:[[n,i],[n+s,i],[n+s,i+a],[n,i+a],[n,i]],shapeType:"rect"}}default:continue}return null}function xa(e){const t=[];for(let r=0;r<e.length;r++){const n=t[t.length-1]??[0,0],i=e[r];switch(i[0]){case"M":case"L":t.push([i[1],i[2]]);continue;case"C":t.push(...ha({x:n[0],y:n[1]},{x:i[1],y:i[2]},{x:i[3],y:i[4]},{x:i[5],y:i[6]}).map(s=>[s.x,s.y]).slice(1));continue;case"Q":t.push(...da({x:n[0],y:n[1]},{x:i[1],y:i[2]},{x:i[3],y:i[4]}).map(s=>[s.x,s.y]).slice(1));continue}}return t}function ba(e){const t={};if(e.hasAttribute("fill")?(t.fill=e.getAttribute("fill"),e.removeAttribute("fill")):e.style.fill&&(t.fill=e.style.fill),t.fill){const n=ir.exec(t.fill);n&&(t.fillOpacity=parseFloat(n[4]),t.fill=`rgb(${n[1]}, ${n[2]}, ${n[3]})`)}if(e.hasAttribute("fill-opacity")?(t.fillOpacity=parseFloat(e.getAttribute("fill-opacity")),e.removeAttribute("fill-opacity")):e.style.fillOpacity&&(t.fillOpacity=parseFloat(e.style.fillOpacity)),e.hasAttribute("stroke")?(t.stroke=e.getAttribute("stroke"),e.removeAttribute("stroke")):e.style.stroke&&(t.stroke=e.style.stroke),t.stroke){const n=ir.exec(t.stroke);n&&(t.strokeOpacity=parseFloat(n[4]),t.stroke=`rgb(${n[1]}, ${n[2]}, ${n[3]})`)}e.hasAttribute("stroke-opacity")?(t.strokeOpacity=parseFloat(e.getAttribute("stroke-opacity")),e.removeAttribute("stroke-opacity")):e.style.strokeOpacity&&(t.strokeOpacity=parseFloat(e.style.strokeOpacity)),e.hasAttribute("stroke-width")?(t.strokeWidth=e.getAttribute("stroke-width"),e.removeAttribute("stroke-width")):e.style.strokeWidth&&(t.strokeWidth=e.style.strokeWidth),e.hasAttribute("stroke-dasharray")?(t.strokeDasharray=e.getAttribute("stroke-dasharray"),e.removeAttribute("stroke-dasharray")):e.style.strokeDasharray&&(t.strokeDasharray=e.style.strokeDasharray);let r=e;for(;r.tagName.toLowerCase()!=="svg";)if(r=r.parentElement,r===null)throw new Error("Could not find root SVG element");return{svg:r.outerHTML,style:Object.keys(t).length>0?t:void 0}}function ln(e){return!!e&&e.type==="iiif:ImageApiSelector"&&e.type==="iiif:ImageApiSelector"}function K(e){if(e.iiifRenderingHints){const t=e.iiifRenderingHints;if(t.rotation){const r=fn(t.rotation);if(r)if(e.selectors.length)for(const n of e.selectors)n.rotation=r;else e.selectors.push({type:"RotationSelector",rotation:r})}}else delete e.iiifRenderingHints;return e}function fn(e){let t=parseFloat(e);return t&&e.startsWith("!")&&(t=360-t),t&&(t=t%360),t!==t?0:t||0}function de(e,t={}){if(Array.isArray(e))return de(e[0]);if(typeof e=="string"){const[r,n]=e.split("#");return n?de({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{id:r,type:t.typeMap&&t.typeMap[r]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return de(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:r,selectors:n}=e.selector?Pe(e.selector,t):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:r,selectors:n}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[r,n]=e.id.split("#");return n?de({type:"SpecificResource",source:{...e,id:r},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{...e,id:r},selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function qt(e={},t=[]){const{id:r,selector:n}=e,i=se(),s=V(),a=r||i.annotation,o=U(d=>a?d.iiif.entities.Annotation[a]:void 0,[a]),u=U(d=>o&&o.body?o.body.map(l=>l?l.type==="SpecificResource"?{...l,source:s.get(l)}:l?d.iiif.entities[l.type][l.id]:null:null).filter(Boolean):[],[o]);return v.useMemo(()=>{if(!o)return;const d={...o,body:u,target:de(o.target,{typeMap:s.getState().iiif.mapping})};return n?n(d):d},[o,n,u,...t])}const pn=({id:e,style:t,className:r,interactive:n})=>{const i=qt({id:e}),s=Fe(i,"atlas"),a=Fe(i,"html"),o=Ft(i,["atlas"]),u=re(),d=v.useMemo(()=>Re.mergeStyles(t,s),[t,s]);return u&&i&&i.target&&i.target.selector&&i.target.selector.type==="BoxSelector"&&i.target.source&&(i.target.source.id===u.id||i.target.source===u.id)?m.jsx(Re.RegionHighlight,{id:i.id,isEditing:!0,region:i.target.selector.spatial,style:d,className:(a==null?void 0:a.className)||r,interactive:!!(a!=null&&a.href||n),href:(a==null?void 0:a.href)||null,title:(a==null?void 0:a.title)||null,hrefTarget:(a==null?void 0:a.target)||null,onClick:()=>{},...o}):null};function dn(e={},t=[]){const{id:r,selector:n}=e,i=se(),s=r||i.annotationPage,a=U(o=>s?o.iiif.entities.AnnotationPage[s]:void 0,[s]);return v.useMemo(()=>{if(a)return n?n(a):a},[a,...t])}const Ct=({className:e,page:t})=>{var s;const r=dn({id:t.id})||t,n=Fe(r,"atlas"),i=Fe(r,"html");return U(a=>r.id?a.iiif.entities.AnnotationPage[r.id]:null,[]),m.jsx(v.Fragment,{children:(s=r.items)==null?void 0:s.map(a=>m.jsx(pn,{id:a.id,style:n,className:(i==null?void 0:i.className)||e},a.id))})};function hn({id:e,image:t,thumbnail:r,isStatic:n,x:i=0,y:s=0,children:a,selector:o,onClick:u,enableSizes:d}){var p,g;const l=v.useMemo(()=>{if(!(!o||o.spatial.x===0&&o.spatial.y===0))return o.spatial},[o]);return m.jsx("world-object",{x:i+t.target.spatial.x,y:s+t.target.spatial.y,width:t.target.spatial.width,height:t.target.spatial.height,onClick:u,children:t.service?m.jsxs(v.Fragment,{children:[m.jsx(Re.TileSet,{tiles:{id:t.service.id||t.service["@id"]||"unknown",height:t.height,width:t.width,imageService:t.service,thumbnail:r&&r.type==="fixed"?r:void 0},enableSizes:d,x:0,y:0,width:(p=t.target)==null?void 0:p.spatial.width,height:(g=t.target)==null?void 0:g.spatial.height,crop:l}),a]},"service"):m.jsxs(v.Fragment,{children:[m.jsx("world-image",{onClick:u,uri:t.id,target:{x:0,y:0,width:t.target.spatial.width,height:t.target.spatial.height},display:t.width&&t.height?{width:t.width,height:t.height}:void 0,crop:l}),a]},"no-service")},e+(t.service?"server":"no-service"))}var Aa=Object.defineProperty,Sa=(e,t,r)=>t in e?Aa(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Qe=(e,t,r)=>(Sa(e,typeof t!="symbol"?t+"":t,r),r),wa=function(){function e(t,r){var n=[],i=!0,s=!1,a=void 0;try{for(var o=t[Symbol.iterator](),u;!(i=(u=o.next()).done)&&(n.push(u.value),!(r&&n.length===r));i=!0);}catch(d){s=!0,a=d}finally{try{!i&&o.return&&o.return()}finally{if(s)throw a}}return n}return function(t,r){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),Oe=Math.PI*2,ht=function(e,t,r,n,i,s,a){var o=e.x,u=e.y;o*=t,u*=r;var d=n*o-i*u,l=i*o+n*u;return{x:d+s,y:l+a}},Ca=function(e,t){var r=t===1.5707963267948966?.551915024494:t===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(t/4),n=Math.cos(e),i=Math.sin(e),s=Math.cos(e+t),a=Math.sin(e+t);return[{x:n-i*r,y:i+n*r},{x:s+a*r,y:a-s*r},{x:s,y:a}]},sr=function(e,t,r,n){var i=e*n-t*r<0?-1:1,s=e*r+t*n;return s>1&&(s=1),s<-1&&(s=-1),i*Math.acos(s)},Ma=function(e,t,r,n,i,s,a,o,u,d,l,p){var g=Math.pow(i,2),b=Math.pow(s,2),h=Math.pow(l,2),x=Math.pow(p,2),A=g*b-g*x-b*h;A<0&&(A=0),A/=g*x+b*h,A=Math.sqrt(A)*(a===o?-1:1);var S=A*i/s*p,w=A*-s/i*l,M=d*S-u*w+(e+r)/2,T=u*S+d*w+(t+n)/2,F=(l-S)/i,k=(p-w)/s,O=(-l-S)/i,P=(-p-w)/s,R=sr(1,0,F,k),$=sr(F,k,O,P);return o===0&&$>0&&($-=Oe),o===1&&$<0&&($+=Oe),[M,T,R,$]},Ra=function(e){var t=e.px,r=e.py,n=e.cx,i=e.cy,s=e.rx,a=e.ry,o=e.xAxisRotation,u=o===void 0?0:o,d=e.largeArcFlag,l=d===void 0?0:d,p=e.sweepFlag,g=p===void 0?0:p,b=[];if(s===0||a===0)return[];var h=Math.sin(u*Oe/360),x=Math.cos(u*Oe/360),A=x*(t-n)/2+h*(r-i)/2,S=-h*(t-n)/2+x*(r-i)/2;if(A===0&&S===0)return[];s=Math.abs(s),a=Math.abs(a);var w=Math.pow(A,2)/Math.pow(s,2)+Math.pow(S,2)/Math.pow(a,2);w>1&&(s*=Math.sqrt(w),a*=Math.sqrt(w));var M=Ma(t,r,n,i,s,a,l,g,h,x,A,S),T=wa(M,4),F=T[0],k=T[1],O=T[2],P=T[3],R=Math.abs(P)/(Oe/4);Math.abs(1-R)<1e-7&&(R=1);var $=Math.max(Math.ceil(R),1);P/=$;for(var X=0;X<$;X++)b.push(Ca(O,P)),O+=P;return b.map(function(Y){var _=ht(Y[0],s,a,x,h,F,k),H=_.x,J=_.y,ee=ht(Y[1],s,a,x,h,F,k),ge=ee.x,E=ee.y,N=ht(Y[2],s,a,x,h,F,k),G=N.x,ue=N.y;return{x1:H,y1:J,x2:ge,y2:E,x:G,y:ue}})},Ia=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function vn(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ka=ja,vt={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},Ta=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function ja(e){var t=[];return e.replace(Ta,function(r,n,i){var s=n.toLowerCase();for(i=Pa(i),s=="m"&&i.length>2&&(t.push([n].concat(i.splice(0,2))),s="l",n=n=="m"?"l":"L");;){if(i.length==vt[s])return i.unshift(n),t.push(i);if(i.length<vt[s])throw new Error("malformed path data");t.push([n].concat(i.splice(0,vt[s])))}}),t}var Ea=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function Pa(e){var t=e.match(Ea);return t?t.map(Number):[]}const Oa=vn(ka);var La=Fa;function Fa(e){var t=0,r=0,n=0,i=0;return e.map(function(s){s=s.slice();var a=s[0],o=a.toUpperCase();if(a!=o)switch(s[0]=o,a){case"a":s[6]+=n,s[7]+=i;break;case"v":s[1]+=i;break;case"h":s[1]+=n;break;default:for(var u=1;u<s.length;)s[u++]+=n,s[u++]+=i}switch(o){case"Z":n=t,i=r;break;case"H":n=s[1];break;case"V":i=s[1];break;case"M":n=t=s[1],i=r=s[2];break;default:n=s[s.length-2],i=s[s.length-1]}return s})}const $a=vn(La);function Da(e){const t=Oa(e),r=$a(t);let n,i=0,s=0,a=0,o=0,u,d,l=0,p=0;const g=[];for(let b=0;b<r.length;b++){let h=r[b];const x=h[0];switch(x){case"M":i=h[1],s=h[2];break;case"H":h=["L",h[1],s];break;case"V":h=["L",i,h[1]];break;case"S":{let A=l,S=p;(n==="C"||n=="S")&&(A+=A-a,S+=S-o),h=["C",A,S,h[1],h[2],h[3],h[4]]}break;case"T":n==="Q"||n=="T"?(u=l*2-u,d=p*2-d):(u=l,d=p),h=["Q",u,d,h[1],h[2]];break;case"Q":u=h[1],d=h[2];break;case"A":{const A=Ra({px:l,py:p,cx:h[6],cy:h[7],rx:h[1],ry:h[2],xAxisRotation:h[3],largeArcFlag:h[4],sweepFlag:h[5]});if(!A.length)continue;for(const[S,w]of A.entries())h=["C",w.x1,w.y1,w.x2,w.y2,w.x,w.y],S<A.length-1&&g.push(h);h=h}break;case"Z":h=["L",i,s];break}n=x,l=h[h.length-2],p=h[h.length-1],["C","Q","A"].indexOf(x)>-1?(a=h[h.length-4],o=h[h.length-3]):(a=l,o=p),g.push(h)}return g}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
|
|
35
|
+
*/function ha(e,t,r,n=1){return new cn(e,t,r).subdivide(n)}function va(e,t,r,n,i=1){return new qt(new Float64Array([e.x,e.y,t.x,t.y,r.x,r.y,n.x,n.y])).subdivide(i)}function ya(e){return e.x*e.x+e.y*e.y}function Pe(e){return e/(1-.67+Math.pow(Math.pow(.67,4)+.25*e*e,.25))}function Ce(e){return e*(1-.39+Math.sqrt(.39*.39+.25*e*e))}class cn{constructor(t,r,n){We(this,"start"),We(this,"control"),We(this,"end"),this.start=t,this.control=r,this.end=n}eval(t){const r=1-t;return{x:this.start.x*r*r+2*this.control.x*r*t+this.end.x*t*t,y:this.start.y*r*r+2*this.control.y*r*t+this.end.y*t*t}}mapToBasic(){const{x:t,y:r}=this.start,{x:n,y:i}=this.control,{x:s,y:a}=this.end,o=2*n-t-s,u=2*i-r-a,f=(n-t)*o+(i-r)*u,l=(s-n)*o+(a-i)*u,d=(s-t)*u-(a-r)*o,g=f/d,b=l/d,h=Math.abs(d)/(Math.hypot(o,u)*Math.abs(b-g));return{x0:t,x2:s,scale:h,cross:d}}subdivide(t){const r=this.mapToBasic(),n=Pe(r.x0),i=Pe(r.x2),s=.5*Math.abs(i-n)*Math.sqrt(r.scale/t),a=Math.ceil(s),o=Ce(n),u=Ce(i),f=[0];for(let l=1;l<a;l++){const d=(Ce(n+(i-n)*l/a)-o)/(u-o);f.push(d)}return f.push(1),f.map(l=>this.eval(l))}}class qt{constructor(t){We(this,"c"),this.c=t}weightsum(t,r,n,i){const s=t*this.c[0]+r*this.c[2]+n*this.c[4]+i*this.c[6],a=t*this.c[1]+r*this.c[3]+n*this.c[5]+i*this.c[7];return{x:s,y:a}}eval(t){const r=1-t,n=r*r*r,i=3*r*r*t,s=3*r*t*t,a=t*t*t;return this.weightsum(n,i,s,a)}deriv(t){const r=1-t,n=-3*r*r,i=3*t*t,s=-6*t*r-n,a=6*t*r-i;return this.weightsum(n,s,a,i)}midpoint_quadbez(){const t=this.weightsum(-.25,.75,.75,-.25);return new cn({x:this.c[0],y:this.c[1]},t,{x:this.c[6],y:this.c[7]})}subsegment(t,r){const n=new Float64Array(8),i=this.eval(t),s=this.eval(r);n[0]=i.x,n[1]=i.y;const a=(r-t)/3,o=this.deriv(t);n[2]=i.x+a*o.x,n[3]=i.y+a*o.y;const u=this.deriv(r);return n[4]=s.x-a*u.x,n[5]=s.y-a*u.y,n[6]=s.x,n[7]=s.y,new qt(n)}subdivide(t){const r=.1*t,n=t-r,i=Math.sqrt(n),s=ya(this.weightsum(1,-3,3,-1)),a=Math.ceil(Math.pow(s/(432*r*r),1/6)),o=[];let u=0;for(let h=0;h<a;h++){const x=h/a,A=(h+1)/a,S=this.subsegment(x,A).midpoint_quadbez(),w=S.mapToBasic(),M=Pe(w.x0),T=Pe(w.x2),F=Math.sqrt(w.scale);let k=Math.abs(T-M)*F;if(Math.sign(w.x0)!=Math.sign(w.x2)){const O=i/F,E=i*Math.abs(T-M)/Pe(O);k=Math.max(k,E)}o.push({quad:S,a0:M,a2:T,val:k}),u+=k}const f=.5*u/i,l=Math.ceil(f),d=[{x:this.c[0],y:this.c[1]}];let g=0,b=0;for(let h=1;h<l;h++){const x=u*h/l;for(;g+o[b].val<x;)g+=o[b].val,b++;const A=o[b].a0,S=o[b].a2,w=Ce(A),M=Ce(S),T=A+(S-A)*(x-g)/o[b].val,F=(Ce(T)-w)/(M-w);d.push(o[b].quad.eval(F))}return d.push({x:this.c[6],y:this.c[7]}),d}}const ga=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,ma=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,sr=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function Ee(e,{domParser:t,svgPreprocessor:r,iiifRenderingHints:n}={}){if(Array.isArray(e))return K(e.reduce((i,s)=>{const{selector:a,selectors:o,iiifRenderingHints:u}=Ee(s,{domParser:t,svgPreprocessor:r,iiifRenderingHints:n});return a&&(i.selector||(i.selector=a),i.selectors.push(...o)),u&&(i.iiifRenderingHints=i.iiifRenderingHints||{type:"ImageApiSelector"},Object.assign(i.iiifRenderingHints,u)),i},{selector:null,selectors:[],iiifRenderingHints:n}));if(!e)return K({selector:null,selectors:[],iiifRenderingHints:n});if(typeof e=="string"){const[i,s]=e.split("#");return s?Ee({type:"FragmentSelector",value:s},{svgPreprocessor:r,iiifRenderingHints:n,domParser:t}):K({selector:null,selectors:[],iiifRenderingHints:n})}if(e.type&&e.type==="PointSelector"&&(e.t||e.t===0)){const i={type:"TemporalSelector",temporal:{startTime:e.t}};return K({selector:i,selectors:[i],iiifRenderingHints:n})}if(ln(e)){const i=[];if(e.region){const s=Ee({type:"FragmentSelector",value:"xywh="+e.region},{domParser:t,svgPreprocessor:r,iiifRenderingHints:n});i.push(...s.selectors)}return K({selector:i[0],selectors:i,iiifRenderingHints:n?{...n,...e}:e})}if(e.type==="FragmentSelector"){const i=ga.exec(e.value);if(i){const a={type:"BoxSelector",spatial:{unit:i[2]==="percent:"||i[2]==="pct:"?"percent":"pixel",x:parseFloat(i[3]),y:parseFloat(i[4]),width:parseFloat(i[5]),height:parseFloat(i[6])}};return K({selector:a,selectors:[a],iiifRenderingHints:n})}const s=e.value.match(ma);if(s){const a={type:"TemporalSelector",temporal:{startTime:s[4]?parseFloat(s[4]):0,endTime:s[7]?parseFloat(s[7]):void 0}};return K({selector:a,selectors:[a],iiifRenderingHints:n})}return K({selector:null,selectors:[],iiifRenderingHints:n})}if(e.type==="SvgSelector"&&"value"in e){t||(typeof window<"u"?t=new window.DOMParser:console.warn("No DOMParser available, cannot parse SVG selector, `points`, `spatial` and `style` will be unavailable and the SVG will not be normalized."));let i=[],s,a,o=(r==null?void 0:r(e.value))??e.value,u;if(t){const l=t.parseFromString(e.value,"image/svg+xml").querySelector("svg");if(!l)return console.warn(`Illegal SVG selector: ${e.value}`),K({selector:null,selectors:[],iiifRenderingHints:n});const d=un(l);d&&(i=d.points,u=d.shapeType,s=[Math.min(...i.map(g=>g[0])),Math.min(...i.map(g=>g[1])),Math.max(...i.map(g=>g[0])),Math.max(...i.map(g=>g[1]))],{style:a,svg:o}=Aa(d.element)??{svg:o})}const f={type:"SvgSelector",svg:o,svgShape:u,style:a,points:i.length?i:void 0,spatial:s?{unit:"pixel",x:s[0],y:s[1],width:s[2]-s[0],height:s[3]-s[1]}:void 0};return K({selector:f,selectors:[f],iiifRenderingHints:n})}return K({selector:null,selectors:[],iiifRenderingHints:n})}function xa(e){const t=e.map(n=>n[0]).reduce((n,i)=>(n[i]+=1,n),{C:0,Q:0,L:0,M:0}),r=new Set(e.map(n=>n[0]));if(t.C>0||t.Q>0)return"path";if(t.L>0&&(r.size===1||r.size===2&&r.has("M"))){if(t.L===4)return"rect";const n=e.slice(-1)[0];return e[0][0]==="M"&&n[0]==="L"&&n[1]==e[0][1]&&n[2]===e[0][2]||n[1]===0&&n[2]===0?"polygon":"polyline"}return"path"}function un(e){var t;for(const r of Array.from(e.children))switch(r==null?void 0:r.tagName.toLowerCase()){case"g":{const n=un(r);if(n)return n}continue;case"path":{const n=r.getAttribute("d");if(!n)continue;const i=da(n);return{element:r,points:ba(i),shapeType:xa(i)}}case"circle":{const n=parseFloat(r.getAttribute("cx")??"0"),i=parseFloat(r.getAttribute("cy")??"0"),s=parseFloat(r.getAttribute("r")??"0");if(!s)continue;const a=[];for(let o=0;o<=360;o+=12){const u=o*Math.PI/180;a.push([n+s*Math.cos(u),i+s*Math.sin(u)])}return{element:r,points:a,shapeType:"circle"}}case"ellipse":{const n=parseFloat(r.getAttribute("cx")??"0"),i=parseFloat(r.getAttribute("cy")??"0"),s=parseFloat(r.getAttribute("rx")??"0"),a=parseFloat(r.getAttribute("ry")??"0");if(!s&&!a)continue;const o=[];for(let u=0;u<=360;u+=12){const f=Math.tan(u/360*Math.PI),l=s*(1-f**2)/(1+f**2),d=a*2*f/(1+f**2);o.push([n+l,i+d])}return{element:r,points:o,shapeType:"ellipse"}}case"line":{const n=parseFloat(r.getAttribute("x0")??"0"),i=parseFloat(r.getAttribute("y0")??"0"),s=parseFloat(r.getAttribute("x1")??"0"),a=parseFloat(r.getAttribute("y1")??"0");if(n===s&&i===a)continue;return{element:r,points:[[n,i],[s,a]],shapeType:"polyline"}}case"polygon":case"polyline":{const n=((t=r.getAttribute("points"))==null?void 0:t.split(" ").map(s=>s.split(",").map(parseFloat)))??[];if(!n.length)continue;let i="polyline";return r.tagName.toLowerCase()==="polygon"&&(n.push(n[0]),i="polygon"),{element:r,points:n,shapeType:i}}case"rect":{const n=parseFloat(r.getAttribute("x")??"0"),i=parseFloat(r.getAttribute("y")??"0"),s=parseFloat(r.getAttribute("width")??"0"),a=parseFloat(r.getAttribute("height")??"0");if(!s||!a)continue;return{element:r,points:[[n,i],[n+s,i],[n+s,i+a],[n,i+a],[n,i]],shapeType:"rect"}}default:continue}return null}function ba(e){const t=[];for(let r=0;r<e.length;r++){const n=t[t.length-1]??[0,0],i=e[r];switch(i[0]){case"M":case"L":t.push([i[1],i[2]]);continue;case"C":t.push(...va({x:n[0],y:n[1]},{x:i[1],y:i[2]},{x:i[3],y:i[4]},{x:i[5],y:i[6]}).map(s=>[s.x,s.y]).slice(1));continue;case"Q":t.push(...ha({x:n[0],y:n[1]},{x:i[1],y:i[2]},{x:i[3],y:i[4]}).map(s=>[s.x,s.y]).slice(1));continue}}return t}function Aa(e){const t={};if(e.hasAttribute("fill")?(t.fill=e.getAttribute("fill"),e.removeAttribute("fill")):e.style.fill&&(t.fill=e.style.fill),t.fill){const n=sr.exec(t.fill);n&&(t.fillOpacity=parseFloat(n[4]),t.fill=`rgb(${n[1]}, ${n[2]}, ${n[3]})`)}if(e.hasAttribute("fill-opacity")?(t.fillOpacity=parseFloat(e.getAttribute("fill-opacity")),e.removeAttribute("fill-opacity")):e.style.fillOpacity&&(t.fillOpacity=parseFloat(e.style.fillOpacity)),e.hasAttribute("stroke")?(t.stroke=e.getAttribute("stroke"),e.removeAttribute("stroke")):e.style.stroke&&(t.stroke=e.style.stroke),t.stroke){const n=sr.exec(t.stroke);n&&(t.strokeOpacity=parseFloat(n[4]),t.stroke=`rgb(${n[1]}, ${n[2]}, ${n[3]})`)}e.hasAttribute("stroke-opacity")?(t.strokeOpacity=parseFloat(e.getAttribute("stroke-opacity")),e.removeAttribute("stroke-opacity")):e.style.strokeOpacity&&(t.strokeOpacity=parseFloat(e.style.strokeOpacity)),e.hasAttribute("stroke-width")?(t.strokeWidth=e.getAttribute("stroke-width"),e.removeAttribute("stroke-width")):e.style.strokeWidth&&(t.strokeWidth=e.style.strokeWidth),e.hasAttribute("stroke-dasharray")?(t.strokeDasharray=e.getAttribute("stroke-dasharray"),e.removeAttribute("stroke-dasharray")):e.style.strokeDasharray&&(t.strokeDasharray=e.style.strokeDasharray);let r=e;for(;r.tagName.toLowerCase()!=="svg";)if(r=r.parentElement,r===null)throw new Error("Could not find root SVG element");return{svg:r.outerHTML,style:Object.keys(t).length>0?t:void 0}}function ln(e){return!!e&&e.type==="iiif:ImageApiSelector"&&e.type==="iiif:ImageApiSelector"}function K(e){if(e.iiifRenderingHints){const t=e.iiifRenderingHints;if(t.rotation){const r=fn(t.rotation);if(r)if(e.selectors.length)for(const n of e.selectors)n.rotation=r;else e.selectors.push({type:"RotationSelector",rotation:r})}}else delete e.iiifRenderingHints;return e}function fn(e){let t=parseFloat(e);return t&&e.startsWith("!")&&(t=360-t),t&&(t=t%360),t!==t?0:t||0}function de(e,t={}){if(Array.isArray(e))return de(e[0]);if(typeof e=="string"){const[r,n]=e.split("#");return n?de({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{id:r,type:t.typeMap&&t.typeMap[r]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return de(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:r,selectors:n}=e.selector?Ee(e.selector,t):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:r,selectors:n}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[r,n]=e.id.split("#");return n?de({type:"SpecificResource",source:{...e,id:r},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{...e,id:r},selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}function Vt(e={},t=[]){const{id:r,selector:n}=e,i=se(),s=V(),a=r||i.annotation,o=U(f=>a?f.iiif.entities.Annotation[a]:void 0,[a]),u=U(f=>o&&o.body?o.body.map(l=>l?l.type==="SpecificResource"?{...l,source:s.get(l)}:l?f.iiif.entities[l.type][l.id]:null:null).filter(Boolean):[],[o]);return v.useMemo(()=>{if(!o)return;const f={...o,body:u,target:de(o.target,{typeMap:s.getState().iiif.mapping})};return n?n(f):f},[o,n,u,...t])}const pn=({id:e,style:t,className:r,interactive:n})=>{const i=Vt({id:e}),s=Fe(i,"atlas"),a=Fe(i,"html"),o=$t(i,["atlas"]),u=re(),f=v.useMemo(()=>Re.mergeStyles(t,s),[t,s]);return u&&i&&i.target&&i.target.selector&&i.target.selector.type==="BoxSelector"&&i.target.source&&(i.target.source.id===u.id||i.target.source===u.id)?m.jsx(Re.RegionHighlight,{id:i.id,isEditing:!0,region:i.target.selector.spatial,style:f,className:(a==null?void 0:a.className)||r,interactive:!!(a!=null&&a.href||n),href:(a==null?void 0:a.href)||null,title:(a==null?void 0:a.title)||null,hrefTarget:(a==null?void 0:a.target)||null,onClick:()=>{},...o}):null};function dn(e={},t=[]){const{id:r,selector:n}=e,i=se(),s=r||i.annotationPage,a=U(o=>s?o.iiif.entities.AnnotationPage[s]:void 0,[s]);return v.useMemo(()=>{if(a)return n?n(a):a},[a,...t])}const Mt=({className:e,page:t})=>{var s;const r=dn({id:t.id})||t,n=Fe(r,"atlas"),i=Fe(r,"html");return U(a=>r.id?a.iiif.entities.AnnotationPage[r.id]:null,[]),m.jsx(v.Fragment,{children:(s=r.items)==null?void 0:s.map(a=>m.jsx(pn,{id:a.id,style:n,className:(i==null?void 0:i.className)||e},a.id))})};function hn({id:e,image:t,thumbnail:r,isStatic:n,x:i=0,y:s=0,children:a,selector:o,onClick:u,enableSizes:f}){var d,g;const l=v.useMemo(()=>{if(!(!o||o.spatial.x===0&&o.spatial.y===0))return o.spatial},[o]);return m.jsx("world-object",{x:i+t.target.spatial.x,y:s+t.target.spatial.y,width:t.target.spatial.width,height:t.target.spatial.height,onClick:u,children:t.service?m.jsxs(v.Fragment,{children:[m.jsx(Re.TileSet,{tiles:{id:t.service.id||t.service["@id"]||"unknown",height:t.height,width:t.width,imageService:t.service,thumbnail:r&&r.type==="fixed"?r:void 0},enableSizes:f,x:0,y:0,width:(d=t.target)==null?void 0:d.spatial.width,height:(g=t.target)==null?void 0:g.spatial.height,crop:l}),a]},"service"):m.jsxs(v.Fragment,{children:[m.jsx("world-image",{onClick:u,uri:t.id,target:{x:0,y:0,width:t.target.spatial.width,height:t.target.spatial.height},display:t.width&&t.height?{width:t.width,height:t.height}:void 0,crop:l}),a]},"no-service")},e+(t.service?"server":"no-service"))}var Sa=Object.defineProperty,wa=(e,t,r)=>t in e?Sa(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Qe=(e,t,r)=>(wa(e,typeof t!="symbol"?t+"":t,r),r),Ca=function(){function e(t,r){var n=[],i=!0,s=!1,a=void 0;try{for(var o=t[Symbol.iterator](),u;!(i=(u=o.next()).done)&&(n.push(u.value),!(r&&n.length===r));i=!0);}catch(f){s=!0,a=f}finally{try{!i&&o.return&&o.return()}finally{if(s)throw a}}return n}return function(t,r){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),Oe=Math.PI*2,ht=function(e,t,r,n,i,s,a){var o=e.x,u=e.y;o*=t,u*=r;var f=n*o-i*u,l=i*o+n*u;return{x:f+s,y:l+a}},Ma=function(e,t){var r=t===1.5707963267948966?.551915024494:t===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(t/4),n=Math.cos(e),i=Math.sin(e),s=Math.cos(e+t),a=Math.sin(e+t);return[{x:n-i*r,y:i+n*r},{x:s+a*r,y:a-s*r},{x:s,y:a}]},ar=function(e,t,r,n){var i=e*n-t*r<0?-1:1,s=e*r+t*n;return s>1&&(s=1),s<-1&&(s=-1),i*Math.acos(s)},Ra=function(e,t,r,n,i,s,a,o,u,f,l,d){var g=Math.pow(i,2),b=Math.pow(s,2),h=Math.pow(l,2),x=Math.pow(d,2),A=g*b-g*x-b*h;A<0&&(A=0),A/=g*x+b*h,A=Math.sqrt(A)*(a===o?-1:1);var S=A*i/s*d,w=A*-s/i*l,M=f*S-u*w+(e+r)/2,T=u*S+f*w+(t+n)/2,F=(l-S)/i,k=(d-w)/s,O=(-l-S)/i,E=(-d-w)/s,R=ar(1,0,F,k),$=ar(F,k,O,E);return o===0&&$>0&&($-=Oe),o===1&&$<0&&($+=Oe),[M,T,R,$]},Ia=function(e){var t=e.px,r=e.py,n=e.cx,i=e.cy,s=e.rx,a=e.ry,o=e.xAxisRotation,u=o===void 0?0:o,f=e.largeArcFlag,l=f===void 0?0:f,d=e.sweepFlag,g=d===void 0?0:d,b=[];if(s===0||a===0)return[];var h=Math.sin(u*Oe/360),x=Math.cos(u*Oe/360),A=x*(t-n)/2+h*(r-i)/2,S=-h*(t-n)/2+x*(r-i)/2;if(A===0&&S===0)return[];s=Math.abs(s),a=Math.abs(a);var w=Math.pow(A,2)/Math.pow(s,2)+Math.pow(S,2)/Math.pow(a,2);w>1&&(s*=Math.sqrt(w),a*=Math.sqrt(w));var M=Ra(t,r,n,i,s,a,l,g,h,x,A,S),T=Ca(M,4),F=T[0],k=T[1],O=T[2],E=T[3],R=Math.abs(E)/(Oe/4);Math.abs(1-R)<1e-7&&(R=1);var $=Math.max(Math.ceil(R),1);E/=$;for(var X=0;X<$;X++)b.push(Ma(O,E)),O+=E;return b.map(function(Y){var _=ht(Y[0],s,a,x,h,F,k),H=_.x,J=_.y,ee=ht(Y[1],s,a,x,h,F,k),ge=ee.x,P=ee.y,N=ht(Y[2],s,a,x,h,F,k),G=N.x,ue=N.y;return{x1:H,y1:J,x2:ge,y2:P,x:G,y:ue}})},ka=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function vn(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Ta=Pa,vt={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},ja=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function Pa(e){var t=[];return e.replace(ja,function(r,n,i){var s=n.toLowerCase();for(i=Oa(i),s=="m"&&i.length>2&&(t.push([n].concat(i.splice(0,2))),s="l",n=n=="m"?"l":"L");;){if(i.length==vt[s])return i.unshift(n),t.push(i);if(i.length<vt[s])throw new Error("malformed path data");t.push([n].concat(i.splice(0,vt[s])))}}),t}var Ea=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function Oa(e){var t=e.match(Ea);return t?t.map(Number):[]}const La=vn(Ta);var Fa=$a;function $a(e){var t=0,r=0,n=0,i=0;return e.map(function(s){s=s.slice();var a=s[0],o=a.toUpperCase();if(a!=o)switch(s[0]=o,a){case"a":s[6]+=n,s[7]+=i;break;case"v":s[1]+=i;break;case"h":s[1]+=n;break;default:for(var u=1;u<s.length;)s[u++]+=n,s[u++]+=i}switch(o){case"Z":n=t,i=r;break;case"H":n=s[1];break;case"V":i=s[1];break;case"M":n=t=s[1],i=r=s[2];break;default:n=s[s.length-2],i=s[s.length-1]}return s})}const Da=vn(Fa);function qa(e){const t=La(e),r=Da(t);let n,i=0,s=0,a=0,o=0,u,f,l=0,d=0;const g=[];for(let b=0;b<r.length;b++){let h=r[b];const x=h[0];switch(x){case"M":i=h[1],s=h[2];break;case"H":h=["L",h[1],s];break;case"V":h=["L",i,h[1]];break;case"S":{let A=l,S=d;(n==="C"||n=="S")&&(A+=A-a,S+=S-o),h=["C",A,S,h[1],h[2],h[3],h[4]]}break;case"T":n==="Q"||n=="T"?(u=l*2-u,f=d*2-f):(u=l,f=d),h=["Q",u,f,h[1],h[2]];break;case"Q":u=h[1],f=h[2];break;case"A":{const A=Ia({px:l,py:d,cx:h[6],cy:h[7],rx:h[1],ry:h[2],xAxisRotation:h[3],largeArcFlag:h[4],sweepFlag:h[5]});if(!A.length)continue;for(const[S,w]of A.entries())h=["C",w.x1,w.y1,w.x2,w.y2,w.x,w.y],S<A.length-1&&g.push(h);h=h}break;case"Z":h=["L",i,s];break}n=x,l=h[h.length-2],d=h[h.length-1],["C","Q","A"].indexOf(x)>-1?(a=h[h.length-4],o=h[h.length-3]):(a=l,o=d),g.push(h)}return g}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
|
|
36
36
|
*
|
|
37
37
|
* All code in this module is based on JavaScript code by Raph Levien, published on his blog at
|
|
38
38
|
* https://raphlinus.github.io/.
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
63
63
|
* See the License for the specific language governing permissions and
|
|
64
64
|
* limitations under the License.
|
|
65
|
-
*/function qa(e,t,r,n=1){return new yn(e,t,r).subdivide(n)}function Va(e,t,r,n,i=1){return new Vt(new Float64Array([e.x,e.y,t.x,t.y,r.x,r.y,n.x,n.y])).subdivide(i)}function _a(e){return e.x*e.x+e.y*e.y}function Le(e){return e/(1-.67+Math.pow(Math.pow(.67,4)+.25*e*e,.25))}function Me(e){return e*(1-.39+Math.sqrt(.39*.39+.25*e*e))}class yn{constructor(t,r,n){Qe(this,"start"),Qe(this,"control"),Qe(this,"end"),this.start=t,this.control=r,this.end=n}eval(t){const r=1-t;return{x:this.start.x*r*r+2*this.control.x*r*t+this.end.x*t*t,y:this.start.y*r*r+2*this.control.y*r*t+this.end.y*t*t}}mapToBasic(){const{x:t,y:r}=this.start,{x:n,y:i}=this.control,{x:s,y:a}=this.end,o=2*n-t-s,u=2*i-r-a,d=(n-t)*o+(i-r)*u,l=(s-n)*o+(a-i)*u,p=(s-t)*u-(a-r)*o,g=d/p,b=l/p,h=Math.abs(p)/(Math.hypot(o,u)*Math.abs(b-g));return{x0:t,x2:s,scale:h,cross:p}}subdivide(t){const r=this.mapToBasic(),n=Le(r.x0),i=Le(r.x2),s=.5*Math.abs(i-n)*Math.sqrt(r.scale/t),a=Math.ceil(s),o=Me(n),u=Me(i),d=[0];for(let l=1;l<a;l++){const p=(Me(n+(i-n)*l/a)-o)/(u-o);d.push(p)}return d.push(1),d.map(l=>this.eval(l))}}class Vt{constructor(t){Qe(this,"c"),this.c=t}weightsum(t,r,n,i){const s=t*this.c[0]+r*this.c[2]+n*this.c[4]+i*this.c[6],a=t*this.c[1]+r*this.c[3]+n*this.c[5]+i*this.c[7];return{x:s,y:a}}eval(t){const r=1-t,n=r*r*r,i=3*r*r*t,s=3*r*t*t,a=t*t*t;return this.weightsum(n,i,s,a)}deriv(t){const r=1-t,n=-3*r*r,i=3*t*t,s=-6*t*r-n,a=6*t*r-i;return this.weightsum(n,s,a,i)}midpoint_quadbez(){const t=this.weightsum(-.25,.75,.75,-.25);return new yn({x:this.c[0],y:this.c[1]},t,{x:this.c[6],y:this.c[7]})}subsegment(t,r){const n=new Float64Array(8),i=this.eval(t),s=this.eval(r);n[0]=i.x,n[1]=i.y;const a=(r-t)/3,o=this.deriv(t);n[2]=i.x+a*o.x,n[3]=i.y+a*o.y;const u=this.deriv(r);return n[4]=s.x-a*u.x,n[5]=s.y-a*u.y,n[6]=s.x,n[7]=s.y,new Vt(n)}subdivide(t){const r=.1*t,n=t-r,i=Math.sqrt(n),s=_a(this.weightsum(1,-3,3,-1)),a=Math.ceil(Math.pow(s/(432*r*r),1/6)),o=[];let u=0;for(let h=0;h<a;h++){const x=h/a,A=(h+1)/a,S=this.subsegment(x,A).midpoint_quadbez(),w=S.mapToBasic(),M=Le(w.x0),T=Le(w.x2),F=Math.sqrt(w.scale);let k=Math.abs(T-M)*F;if(Math.sign(w.x0)!=Math.sign(w.x2)){const O=i/F,P=i*Math.abs(T-M)/Le(O);k=Math.max(k,P)}o.push({quad:S,a0:M,a2:T,val:k}),u+=k}const d=.5*u/i,l=Math.ceil(d),p=[{x:this.c[0],y:this.c[1]}];let g=0,b=0;for(let h=1;h<l;h++){const x=u*h/l;for(;g+o[b].val<x;)g+=o[b].val,b++;const A=o[b].a0,S=o[b].a2,w=Me(A),M=Me(S),T=A+(S-A)*(x-g)/o[b].val,F=(Me(T)-w)/(M-w);p.push(o[b].quad.eval(F))}return p.push({x:this.c[6],y:this.c[7]}),p}}const Ua=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,Ha=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,ar=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function Ye(e,{domParser:t,svgPreprocessor:r,iiifRenderingHints:n}={}){if(Array.isArray(e))return Z(e.reduce((i,s)=>{const{selector:a,selectors:o,iiifRenderingHints:u}=Ye(s,{domParser:t,svgPreprocessor:r,iiifRenderingHints:n});return a&&(i.selector||(i.selector=a),i.selectors.push(...o)),u&&(i.iiifRenderingHints=i.iiifRenderingHints||{type:"ImageApiSelector"},Object.assign(i.iiifRenderingHints,u)),i},{selector:null,selectors:[],iiifRenderingHints:n}));if(!e)return Z({selector:null,selectors:[],iiifRenderingHints:n});if(typeof e=="string"){const[i,s]=e.split("#");return s?Ye({type:"FragmentSelector",value:s},{svgPreprocessor:r,iiifRenderingHints:n,domParser:t}):Z({selector:null,selectors:[],iiifRenderingHints:n})}if(e.type&&e.type==="PointSelector"&&(e.t||e.t===0)){const i={type:"TemporalSelector",temporal:{startTime:e.t}};return Z({selector:i,selectors:[i],iiifRenderingHints:n})}if(Wa(e)){const i=[];if(e.region){const s=Ye({type:"FragmentSelector",value:"xywh="+e.region},{domParser:t,svgPreprocessor:r,iiifRenderingHints:n});i.push(...s.selectors)}return Z({selector:i[0],selectors:i,iiifRenderingHints:n?{...n,...e}:e})}if(e.type==="FragmentSelector"){const i=Ua.exec(e.value);if(i){const a={type:"BoxSelector",spatial:{unit:i[2]==="percent:"||i[2]==="pct:"?"percent":"pixel",x:parseFloat(i[3]),y:parseFloat(i[4]),width:parseFloat(i[5]),height:parseFloat(i[6])}};return Z({selector:a,selectors:[a],iiifRenderingHints:n})}const s=e.value.match(Ha);if(s){const a={type:"TemporalSelector",temporal:{startTime:s[4]?parseFloat(s[4]):0,endTime:s[7]?parseFloat(s[7]):void 0}};return Z({selector:a,selectors:[a],iiifRenderingHints:n})}return Z({selector:null,selectors:[],iiifRenderingHints:n})}if(e.type==="SvgSelector"&&"value"in e){t||(typeof window<"u"?t=new window.DOMParser:console.warn("No DOMParser available, cannot parse SVG selector, `points`, `spatial` and `style` will be unavailable and the SVG will not be normalized."));let i=[],s,a,o=(r==null?void 0:r(e.value))??e.value,u;if(t){const l=t.parseFromString(e.value,"image/svg+xml").querySelector("svg");if(!l)return console.warn(`Illegal SVG selector: ${e.value}`),Z({selector:null,selectors:[],iiifRenderingHints:n});const p=gn(l);p&&(i=p.points,u=p.shapeType,s=[Math.min(...i.map(g=>g[0])),Math.min(...i.map(g=>g[1])),Math.max(...i.map(g=>g[0])),Math.max(...i.map(g=>g[1]))],{style:a,svg:o}=za(p.element)??{svg:o})}const d={type:"SvgSelector",svg:o,svgShape:u,style:a,points:i.length?i:void 0,spatial:s?{unit:"pixel",x:s[0],y:s[1],width:s[2]-s[0],height:s[3]-s[1]}:void 0};return Z({selector:d,selectors:[d],iiifRenderingHints:n})}return Z({selector:null,selectors:[],iiifRenderingHints:n})}function Na(e){const t=e.map(n=>n[0]).reduce((n,i)=>(n[i]+=1,n),{C:0,Q:0,L:0,M:0}),r=new Set(e.map(n=>n[0]));if(t.C>0||t.Q>0)return"path";if(t.L>0&&(r.size===1||r.size===2&&r.has("M"))){if(t.L===4)return"rect";const n=e.slice(-1)[0];return e[0][0]==="M"&&n[0]==="L"&&n[1]==e[0][1]&&n[2]===e[0][2]||n[1]===0&&n[2]===0?"polygon":"polyline"}return"path"}function gn(e){var t;for(const r of Array.from(e.children))switch(r==null?void 0:r.tagName.toLowerCase()){case"g":{const n=gn(r);if(n)return n}continue;case"path":{const n=r.getAttribute("d");if(!n)continue;const i=Da(n);return{element:r,points:Ba(i),shapeType:Na(i)}}case"circle":{const n=parseFloat(r.getAttribute("cx")??"0"),i=parseFloat(r.getAttribute("cy")??"0"),s=parseFloat(r.getAttribute("r")??"0");if(!s)continue;const a=[];for(let o=0;o<=360;o+=12){const u=o*Math.PI/180;a.push([n+s*Math.cos(u),i+s*Math.sin(u)])}return{element:r,points:a,shapeType:"circle"}}case"ellipse":{const n=parseFloat(r.getAttribute("cx")??"0"),i=parseFloat(r.getAttribute("cy")??"0"),s=parseFloat(r.getAttribute("rx")??"0"),a=parseFloat(r.getAttribute("ry")??"0");if(!s&&!a)continue;const o=[];for(let u=0;u<=360;u+=12){const d=Math.tan(u/360*Math.PI),l=s*(1-d**2)/(1+d**2),p=a*2*d/(1+d**2);o.push([n+l,i+p])}return{element:r,points:o,shapeType:"ellipse"}}case"line":{const n=parseFloat(r.getAttribute("x0")??"0"),i=parseFloat(r.getAttribute("y0")??"0"),s=parseFloat(r.getAttribute("x1")??"0"),a=parseFloat(r.getAttribute("y1")??"0");if(n===s&&i===a)continue;return{element:r,points:[[n,i],[s,a]],shapeType:"polyline"}}case"polygon":case"polyline":{const n=((t=r.getAttribute("points"))==null?void 0:t.split(" ").map(s=>s.split(",").map(parseFloat)))??[];if(!n.length)continue;let i="polyline";return r.tagName.toLowerCase()==="polygon"&&(n.push(n[0]),i="polygon"),{element:r,points:n,shapeType:i}}case"rect":{const n=parseFloat(r.getAttribute("x")??"0"),i=parseFloat(r.getAttribute("y")??"0"),s=parseFloat(r.getAttribute("width")??"0"),a=parseFloat(r.getAttribute("height")??"0");if(!s||!a)continue;return{element:r,points:[[n,i],[n+s,i],[n+s,i+a],[n,i+a],[n,i]],shapeType:"rect"}}default:continue}return null}function Ba(e){const t=[];for(let r=0;r<e.length;r++){const n=t[t.length-1]??[0,0],i=e[r];switch(i[0]){case"M":case"L":t.push([i[1],i[2]]);continue;case"C":t.push(...Va({x:n[0],y:n[1]},{x:i[1],y:i[2]},{x:i[3],y:i[4]},{x:i[5],y:i[6]}).map(s=>[s.x,s.y]).slice(1));continue;case"Q":t.push(...qa({x:n[0],y:n[1]},{x:i[1],y:i[2]},{x:i[3],y:i[4]}).map(s=>[s.x,s.y]).slice(1));continue}}return t}function za(e){const t={};if(e.hasAttribute("fill")?(t.fill=e.getAttribute("fill"),e.removeAttribute("fill")):e.style.fill&&(t.fill=e.style.fill),t.fill){const n=ar.exec(t.fill);n&&(t.fillOpacity=parseFloat(n[4]),t.fill=`rgb(${n[1]}, ${n[2]}, ${n[3]})`)}if(e.hasAttribute("fill-opacity")?(t.fillOpacity=parseFloat(e.getAttribute("fill-opacity")),e.removeAttribute("fill-opacity")):e.style.fillOpacity&&(t.fillOpacity=parseFloat(e.style.fillOpacity)),e.hasAttribute("stroke")?(t.stroke=e.getAttribute("stroke"),e.removeAttribute("stroke")):e.style.stroke&&(t.stroke=e.style.stroke),t.stroke){const n=ar.exec(t.stroke);n&&(t.strokeOpacity=parseFloat(n[4]),t.stroke=`rgb(${n[1]}, ${n[2]}, ${n[3]})`)}e.hasAttribute("stroke-opacity")?(t.strokeOpacity=parseFloat(e.getAttribute("stroke-opacity")),e.removeAttribute("stroke-opacity")):e.style.strokeOpacity&&(t.strokeOpacity=parseFloat(e.style.strokeOpacity)),e.hasAttribute("stroke-width")?(t.strokeWidth=e.getAttribute("stroke-width"),e.removeAttribute("stroke-width")):e.style.strokeWidth&&(t.strokeWidth=e.style.strokeWidth),e.hasAttribute("stroke-dasharray")?(t.strokeDasharray=e.getAttribute("stroke-dasharray"),e.removeAttribute("stroke-dasharray")):e.style.strokeDasharray&&(t.strokeDasharray=e.style.strokeDasharray);let r=e;for(;r.tagName.toLowerCase()!=="svg";)if(r=r.parentElement,r===null)throw new Error("Could not find root SVG element");return{svg:r.outerHTML,style:Object.keys(t).length>0?t:void 0}}function Wa(e){return!!e&&e.type==="iiif:ImageApiSelector"&&e.type==="iiif:ImageApiSelector"}function Z(e){if(e.iiifRenderingHints){const t=e.iiifRenderingHints;if(t.rotation){const r=Qa(t.rotation);if(r)if(e.selectors.length)for(const n of e.selectors)n.rotation=r;else e.selectors.push({type:"RotationSelector",rotation:r})}}else delete e.iiifRenderingHints;return e}function Qa(e){let t=parseFloat(e);return t&&e.startsWith("!")&&(t=360-t),t&&(t=t%360),t!==t?0:t||0}function Te(e,t={}){if(Array.isArray(e))return Te(e[0]);if(typeof e=="string"){const[r,n]=e.split("#");return n?Te({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{id:r,type:t.typeMap&&t.typeMap[r]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return Te(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:r,selectors:n}=e.selector?Ye(e.selector,t):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:r,selectors:n}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[r,n]=e.id.split("#");return n?Te({type:"SpecificResource",source:{...e,id:r},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{...e,id:r},selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}var Ya=Object.defineProperty,Ga=(e,t,r)=>t in e?Ya(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,or=(e,t,r)=>(Ga(e,typeof t!="symbol"?t+"":t,r),r);function Ja(e){return Array.isArray(e)?e:e?[e]:[]}const cr=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function Ka(e){if(typeof e>"u"||e===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(e))throw new Error("Array is not a valid entity");if(typeof e!="object")throw new Error(`${typeof e} is not a valid entity`);if(typeof e["@type"]=="string"){const t=cr.indexOf(e["@type"]);if(t!==-1)return cr[t]}if(e.profile)return"Service";if(e.format||e["@type"])return"ContentResource";throw new Error("Resource type is not known")}class _t{constructor(t,r={}){or(this,"traversals"),or(this,"options"),this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...t},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...r}}static all(t){return new _t({collection:[t],manifest:[t],canvas:[t],annotationList:[t],sequence:[t],annotation:[t],contentResource:[t],choice:[t],range:[t],service:[t],layer:[t]})}traverseCollection(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(t))),this.traversals.collection)}traverseCollectionItems(t){if(this.options.mergeMemberProperties){const r=[...(t.manifests||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n),...(t.collections||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n),...t.members||[]];delete t.collections,delete t.manifests,t.members=r}return t.manifests&&(t.manifests=t.manifests.map(r=>this.traverseManifest(typeof r=="string"?{"@id":r,"@type":"sc:Manifest"}:r))),t.collections&&(t.collections=t.collections.map(r=>this.traverseCollection(typeof r=="string"?{"@id":r,"@type":"sc:Collection"}:r))),t.members&&(t.members=t.members.map(r=>typeof r=="string"?r:this.traverseUnknown(r))),t}traverseManifest(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(t))),this.traversals.manifest)}traverseManifestItems(t){return t.sequences&&(t.sequences=t.sequences.map(r=>this.traverseSequence(r))),t.structures&&(t.structures=t.structures.map(r=>this.traverseRange(r))),t}traverseSequence(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(t))),this.traversals.sequence)}traverseSequenceItems(t){return t.canvases&&(t.canvases=t.canvases.map(r=>this.traverseCanvas(r))),t}traverseCanvas(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(t))),this.traversals.canvas)}traverseCanvasItems(t){return t.images&&(t.images=t.images.map(r=>this.traverseAnnotation(r))),t.otherContent&&(t.otherContent=t.otherContent.map(r=>this.traverseAnnotationList(r))),t}traverseRange(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(t))),this.traversals.range)}traverseRangeItems(t){if(this.options.mergeMemberProperties){const r=[...(t.ranges||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Range"}:n),...(t.canvases||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Canvas"}:n),...t.members||[]];delete t.ranges,delete t.canvases,t.members=r.length?r.map(n=>this.traverseUnknown(n)):void 0}return t}traverseAnnotationList(t){const r=typeof t=="string"?{"@id":t,"@type":"sc:AnnotationList"}:t;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(r)),this.traversals.annotationList)}traverseAnnotationListItems(t){return t.resources&&(t.resources=t.resources.map(r=>this.traverseAnnotation(r))),t}traverseAnnotation(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(t))),this.traversals.annotation)}traverseAnnotationItems(t){return t.resource&&(Array.isArray(t.resource)?t.resource=t.resource.map(r=>this.traverseContentResource(r)):t.resource=this.traverseContentResource(t.resource)),t.on,t}traverseLayer(t){return this.traverseType(this.traverseLinking(this.traverseLayerItems(t)),this.traversals.layer)}traverseLayerItems(t){return t.otherContent&&(t.otherContent=t.otherContent.map(r=>this.traverseAnnotationList(r))),t}traverseChoice(t){return this.traverseType(this.traverseChoiceItems(t),this.traversals.choice)}traverseChoiceItems(t){return t.default&&t.default!=="rdf:nil"&&(t.default=this.traverseContentResource(t.default)),t.item&&t.item!=="rdf:nil"&&(t.item=t.item.map(r=>this.traverseContentResource(r))),t}traverseService(t){return this.traverseType(this.traverseLinking(t),this.traversals.service)}traverseContentResource(t){return t["@type"]==="oa:Choice"?this.traverseChoice(t):this.traverseType(this.traverseDescriptive(this.traverseLinking(t)),this.traversals.contentResource)}traverseUnknown(t){if(!t["@type"]||typeof t=="string")return t;switch(Ka(t)){case"sc:Collection":return this.traverseCollection(t);case"sc:Manifest":return this.traverseManifest(t);case"sc:Canvas":return this.traverseCanvas(t);case"sc:Sequence":return this.traverseSequence(t);case"sc:Range":return this.traverseRange(t);case"oa:Annotation":return this.traverseAnnotation(t);case"sc:AnnotationList":return this.traverseAnnotationList(t);case"sc:Layer":return this.traverseLayer(t);case"Service":return this.traverseService(t);case"oa:Choice":return this.traverseChoice(t);case"ContentResource":return this.traverseContentResource(t)}return t.profile?this.traverseService(t):t}traverseImageResource(t){const r=Array.isArray(t),n=Array.isArray(t)?t:[t],i=[];for(const s of n)typeof s=="string"?i.push(this.traverseContentResource({"@id":s,"@type":"dctypes:Image"})):i.push(this.traverseContentResource(s));return!r&&!this.options.convertPropsToArray?i[0]:i}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=this.traverseImageResource(t.thumbnail)),t.logo&&(t.logo=this.traverseImageResource(t.logo)),t}traverseOneOrMoreServices(t){const r=Array.isArray(t),n=Array.isArray(t)?t:[t],i=[];for(const s of n)i.push(this.traverseService(s));return!r&&!this.options.convertPropsToArray?i[0]:i}traverseLinking(t){return t.related&&(t.related=this.traverseOneOrManyType(t.related,this.traversals.contentResource)),t.rendering&&(t.rendering=this.traverseOneOrManyType(t.rendering,this.traversals.contentResource)),t.service&&(t.service=this.traverseOneOrMoreServices(t.service)),t.seeAlso&&(t.seeAlso=this.traverseOneOrManyType(t.seeAlso,this.traversals.contentResource)),t.within&&(typeof t.within=="string"||(t.within=this.traverseOneOrManyType(t.within,this.traversals.contentResource))),t.startCanvas&&(typeof t.startCanvas=="string"?t.startCanvas=this.traverseType({"@id":t.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):t.startCanvas&&this.traverseType(t.startCanvas,this.traversals.canvas)),t.contentLayer&&(typeof t.contentLayer=="string"?t.contentLayer=this.traverseLayer({"@id":t.contentLayer,"@type":"sc:Layer"}):t.contentLayer=this.traverseLayer(t.contentLayer)),t}traverseOneOrManyType(t,r){if(!Array.isArray(t))if(this.options.convertPropsToArray)t=[t];else return this.traverseType(t,r);return t.map(n=>this.traverseType(n,r))}traverseType(t,r){return r.reduce((n,i)=>{const s=i(n);return typeof s>"u"&&!this.options.allowUndefinedReturn?n:s},t)}}const Za="http://library.stanford.edu/iiif/image-api/compliance.html#level0",mn="http://library.stanford.edu/iiif/image-api/compliance.html#level1",xn="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Xa="http://library.stanford.edu/iiif/image-api/conformance.html#level0",bn="http://library.stanford.edu/iiif/image-api/conformance.html#level1",An="http://library.stanford.edu/iiif/image-api/conformance.html#level2",eo="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Sn="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",wn="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",to="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Cn="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Mn="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",ro="http://iiif.io/api/image/1/level0.json",no="http://iiif.io/api/image/1/profiles/level0.json",Rn="http://iiif.io/api/image/1/level1.json",In="http://iiif.io/api/image/1/profiles/level1.json",kn="http://iiif.io/api/image/1/level2.json",Tn="http://iiif.io/api/image/1/profiles/level2.json",io="http://iiif.io/api/image/2/level0.json",so="http://iiif.io/api/image/2/profiles/level0.json",jn="http://iiif.io/api/image/2/level1.json",En="http://iiif.io/api/image/2/profiles/level1.json",Pn="http://iiif.io/api/image/2/level2.json",On="http://iiif.io/api/image/2/profiles/level2.json",ao="level0",Ln="level1",Fn="level2",oo="http://iiif.io/api/image/2/level0",$n="http://iiif.io/api/image/2/level1",Dn="http://iiif.io/api/image/2/level2",co=[$n,Dn,mn,xn,bn,An,Sn,wn,Cn,Mn,Rn,In,kn,Tn,jn,En,Pn,On,Ln,Fn],uo=[oo,$n,Dn,Za,mn,xn,Xa,bn,An,eo,Sn,wn,to,Cn,Mn,ro,no,Rn,In,kn,Tn,io,so,jn,En,Pn,On,ao,Ln,Fn];function ae(e){for(const t in e)(typeof e[t]>"u"||e[t]===null)&&delete e[t];return e}const Mt={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function Ae(e,t="none"){if(!e)return{};const r=Array.isArray(e)?e:[e],n={};for(const i of r){if(typeof i=="string"){n[t]=n[t]?n[t]:[],n[t].push(i||"");continue}if(!i["@language"]){n[t]=n[t]?n[t]:[],n[t].push(i["@value"]||"");continue}const s=i["@language"];n[s]=n[s]?n[s]:[],n[s].push(i["@value"]||"")}return n}function qn(e){if(Array.isArray(e))return qn(e.find(t=>typeof t=="string"));if(uo.indexOf(e)!==-1)return"level2";if(co.indexOf(e)!==-1)return"level1";if(typeof e=="string")return e}function lo(e){const t=Array.isArray(e)?e:[e];for(const r of t)switch(r){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function fo(e){switch(e){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}function ur(e){for(const t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}const po=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function Ut(e){const t=e["@id"]||e.id;let r=e["@type"]||e.type;const n=e.profile||void 0,i=e["@context"]||void 0;if(n){const s=fo(n);if(s)return s}if(i){const s=lo(i);if(s)return s}if(r){if(Array.isArray(r)){if(r.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(r.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";r=r[0]}for(const s of["sc","oa","dcterms","dctypes","iiif"])if(r.startsWith(`${s}:`)){r=r.slice(s.length+1);break}switch(r){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(r&&po.indexOf(r)!==-1)return r;if(e.format){if(e.format.startsWith("image/"))return"Image";if(e.format.startsWith("text/")||e.format==="application/pdf")return"Text";if(e.format.startsWith("application/"))return"Dataset"}return t&&(t.endsWith(".jpg")||t.endsWith(".png")||t.endsWith(".jpeg"))?"Image":r||"unknown"}const ho=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function vo(e){const t=e.match(ho);return t?t[0]:e}function yo(e,t="Rights/License",r="none"){let n=null;const i=[],s=Array.isArray(e)?e:[e];for(const a of s){const o=a?vo(a):void 0;if(o&&(o.indexOf("creativecommons.org")!==-1||o.indexOf("rightsstatements.org")!==-1)){o.startsWith("https://")?n=`http://${o.slice(8)}`:n=o;continue}o&&i.push({label:{[r]:[t]},value:{[r]:[o]}})}return[n,i]}const go=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function mo(e){if(e){const t=Array.isArray(e)?e:[e],r=[];for(const n of t)n==="http://iiif.io/api/presentation/2/context.json"&&r.push("http://iiif.io/api/presentation/3/context.json"),go.indexOf(n)===-1&&r.push(n);if(t.length)return r.length===1?r[0]:r}}function xo(e){return e?e.map(t=>({label:Ae(t.label),value:Ae(t.value)})):[]}let lr=0;function Vn(e,t){const r=encodeURI(e.id||e["@id"]||"").trim();return r&&t?`${r}/${t}`:r||(lr++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${lr}`)}function oe(e){const t=[...e.behavior||[]];e.viewingHint&&t.push(e.viewingHint);let r;return Array.isArray(e.motivation)?r=e.motivation.map(ur):e.motivation&&(r=ur(e.motivation)),{"@context":e["@context"]?mo(e["@context"]):void 0,id:(e["@id"]||Vn(e)).trim(),type:Ut(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:r,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function ce(e){const[t,r]=yo(e.license),n=[...e.metadata?xo(e.metadata):[],...r];return{rights:t,metadata:n.length?n:void 0,label:e.label?Ae(e.label):void 0,requiredStatement:e.attribution?{label:Ae(Mt.attributionLabel),value:Ae(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?Ae(e.description):void 0,thumbnail:bo(e.thumbnail)}}function bo(e){return e&&(Array.isArray(e)?e:[e]).map(t=>typeof t=="string"?{id:t,type:"Image"}:(t.type==="unknown"&&(t.type="Image"),t))}function Ao(e){if(!e.within)return;const t=Array.isArray(e.within)?e.within:[e.within],r=[];for(const n of t)if(typeof n=="string"){if(n)switch(e["@type"]){case"sc:Manifest":r.push({id:n,type:"Collection"});break}}else n["@id"]&&r.push({id:n["@id"],type:Ut(n)});return r.length?r:void 0}function ye(e){const t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],r=e.contentLayer;return{provider:e.logo||t.length?[{id:Mt.providerId,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:Ae(Mt.providerName)}]:void 0,partOf:Ao(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?Ja(e.service):void 0,supplementary:r?[r]:void 0}}function So(e){return{chars:e.chars,format:e.format?e.format:void 0,language:e.language}}function wo(e){return ae({...oe(e),...ce(e),...ye(e),items:e.members})}function Co(e){const t=[],r=[];let n;for(const s of e.sequences||[])s.canvases.length&&t.push(...s.canvases),s.behavior&&r.push(...s.behavior),s.startCanvas&&(n=s.startCanvas);const i=oe(e);return r.length&&(i.behavior?i.behavior.push(...r):i.behavior=r),ae({...i,...ce(e),...ye(e),start:n,items:t,structures:e.structures})}function Mo(e){return ae({...oe(e),...ce(e),...ye(e),annotations:e.otherContent&&e.otherContent.length?e.otherContent:void 0,items:e.images&&e.images.length?[{id:Vn(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}function Ro(e){return ae({...oe(e),...ce(e),...ye(e),items:e.resources&&e.resources.length?e.resources:void 0})}function Io(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}}function ko(e){function t(r){if(Array.isArray(r)){if(r.length>1)return{type:"List",items:r.map(t)};r=r[0]}if(typeof r=="string")return encodeURI(r).trim();if("@type"in r){let n;if(typeof r.full=="string")n=r.full;else if(r.full["@type"]==="dctypes:Image")n={id:r.full["@id"],type:"Image"};else if(r.full["@type"]==="sc:Canvas")n={id:r.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${r.full["@type"]}`);return{type:"SpecificResource",source:n,selector:It(r.selector)}}else return encodeURI(r["@id"]).trim()}return ae({...oe(e),...ce(e),...ye(e),target:t(e.on),body:Array.isArray(e.resource)?e.resource.map(Rt):Rt(e.resource)})}function Rt(e){const t=e;return ae({...oe(t),...ce(t),...ye(t),...So(t)})}function To(e){const t=[];return e.default&&e.default!=="rdf:nil"&&t.push(e.default),e.item&&e.item!=="rdf:nil"&&t.push(...e.item),{...oe(e),...ce(e),items:t}}function jo(e){return ae({...oe(e),...ce(e),...ye(e),items:e.members})}function Eo(e){const{"@id":t,"@type":r,"@context":n,profile:i,...s}=e,a={};return t&&(a["@id"]=t),a["@type"]=Ut(e),a["@type"]==="unknown"&&(n&&n.length&&(a["@context"]=n),a["@type"]="Service"),i&&(a.profile=qn(i)),ae({...a,...s})}function Po(e){return ae({...oe(e),...ce(e),...ye(e)})}new _t({collection:[wo],manifest:[Co],canvas:[Mo],annotationList:[Ro],sequence:[Io],annotation:[ko],contentResource:[Rt],choice:[To],range:[jo],service:[Eo],layer:[Po]});function It(e){if((Array.isArray(e["@type"])&&e["@type"].includes("oa:SvgSelector")||e["@type"]=="oa:SvgSelector")&&("chars"in e||"value"in e))return{type:"SvgSelector",value:"chars"in e?e.chars:e.value};if(e["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:e.value};if(e["@type"]==="oa:Choice")return[It(e.default),...(Array.isArray(e.item)?e.item:[e.item]).map(It)];if(e["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in e?e.region:void 0,rotation:"rotation"in e?e.rotation:void 0};throw new Error(`Unsupported selector type: ${e["@type"]}`)}var fr={exports:{}};(function(e,t){var r=Object.defineProperty,n=(s,a,o)=>a in s?r(s,a,{enumerable:!0,configurable:!0,writable:!0,value:o}):s[a]=o,i=(s,a,o)=>(n(s,typeof a!="symbol"?a+"":a,o),o);(function(s,a){a(t)})(Ia,function(s){const a="http://library.stanford.edu/iiif/image-api/compliance.html#level1",o="http://library.stanford.edu/iiif/image-api/compliance.html#level2",u="http://library.stanford.edu/iiif/image-api/conformance.html#level1",d="http://library.stanford.edu/iiif/image-api/conformance.html#level2",l="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",p="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",g="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",b="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",h="http://iiif.io/api/image/1/level1.json",x="http://iiif.io/api/image/1/profiles/level1.json",A="http://iiif.io/api/image/1/level2.json",S="http://iiif.io/api/image/1/profiles/level2.json",w="http://iiif.io/api/image/2/level1.json",M="http://iiif.io/api/image/2/profiles/level1.json",T="http://iiif.io/api/image/2/level2.json",F="http://iiif.io/api/image/2/profiles/level2.json",k="level1",O="level2",P="http://iiif.io/api/image/2/level1",R="http://iiif.io/api/image/2/level2",$=[P,R,a,o,u,d,l,p,g,b,h,x,A,S,w,M,T,F,k,O],X=["http://iiif.io/api/image/2/level0",P,R,"http://library.stanford.edu/iiif/image-api/compliance.html#level0",a,o,"http://library.stanford.edu/iiif/image-api/conformance.html#level0",u,d,"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",l,p,"http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",g,b,"http://iiif.io/api/image/1/level0.json","http://iiif.io/api/image/1/profiles/level0.json",h,x,A,S,"http://iiif.io/api/image/2/level0.json","http://iiif.io/api/image/2/profiles/level0.json",w,M,T,F,"level0",k,O],Y=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];class _{constructor(c,y={}){i(this,"traversals"),i(this,"options"),this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...c},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...y}}static all(c){return new _({collection:[c],manifest:[c],canvas:[c],annotationList:[c],sequence:[c],annotation:[c],contentResource:[c],choice:[c],range:[c],service:[c],layer:[c]})}traverseCollection(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(c))),this.traversals.collection)}traverseCollectionItems(c){if(this.options.mergeMemberProperties){const y=[...(c.manifests||[]).map(C=>typeof C=="string"?{"@id":C,"@type":"sc:Manifest"}:C),...(c.collections||[]).map(C=>typeof C=="string"?{"@id":C,"@type":"sc:Collection"}:C),...c.members||[]];delete c.collections,delete c.manifests,c.members=y}return c.manifests&&(c.manifests=c.manifests.map(y=>this.traverseManifest(typeof y=="string"?{"@id":y,"@type":"sc:Manifest"}:y))),c.collections&&(c.collections=c.collections.map(y=>this.traverseCollection(typeof y=="string"?{"@id":y,"@type":"sc:Collection"}:y))),c.members&&(c.members=c.members.map(y=>typeof y=="string"?y:this.traverseUnknown(y))),c}traverseManifest(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(c))),this.traversals.manifest)}traverseManifestItems(c){return c.sequences&&(c.sequences=c.sequences.map(y=>this.traverseSequence(y))),c.structures&&(c.structures=c.structures.map(y=>this.traverseRange(y))),c}traverseSequence(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(c))),this.traversals.sequence)}traverseSequenceItems(c){return c.canvases&&(c.canvases=c.canvases.map(y=>this.traverseCanvas(y))),c}traverseCanvas(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(c))),this.traversals.canvas)}traverseCanvasItems(c){return c.images&&(c.images=c.images.map(y=>this.traverseAnnotation(y))),c.otherContent&&(c.otherContent=c.otherContent.map(y=>this.traverseAnnotationList(y))),c}traverseRange(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(c))),this.traversals.range)}traverseRangeItems(c){if(this.options.mergeMemberProperties){const y=[...(c.ranges||[]).map(C=>typeof C=="string"?{"@id":C,"@type":"sc:Range"}:C),...(c.canvases||[]).map(C=>typeof C=="string"?{"@id":C,"@type":"sc:Canvas"}:C),...c.members||[]];delete c.ranges,delete c.canvases,c.members=y.length?y.map(C=>this.traverseUnknown(C)):void 0}return c}traverseAnnotationList(c){const y=typeof c=="string"?{"@id":c,"@type":"sc:AnnotationList"}:c;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(y)),this.traversals.annotationList)}traverseAnnotationListItems(c){return c.resources&&(c.resources=c.resources.map(y=>this.traverseAnnotation(y))),c}traverseAnnotation(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(c))),this.traversals.annotation)}traverseAnnotationItems(c){return c.resource&&(Array.isArray(c.resource)?c.resource=c.resource.map(y=>this.traverseContentResource(y)):c.resource=this.traverseContentResource(c.resource)),c.on,c}traverseLayer(c){return this.traverseType(this.traverseLinking(this.traverseLayerItems(c)),this.traversals.layer)}traverseLayerItems(c){return c.otherContent&&(c.otherContent=c.otherContent.map(y=>this.traverseAnnotationList(y))),c}traverseChoice(c){return this.traverseType(this.traverseChoiceItems(c),this.traversals.choice)}traverseChoiceItems(c){return c.default&&c.default!=="rdf:nil"&&(c.default=this.traverseContentResource(c.default)),c.item&&c.item!=="rdf:nil"&&(c.item=c.item.map(y=>this.traverseContentResource(y))),c}traverseService(c){return this.traverseType(this.traverseLinking(c),this.traversals.service)}traverseContentResource(c){return c["@type"]==="oa:Choice"?this.traverseChoice(c):this.traverseType(this.traverseDescriptive(this.traverseLinking(c)),this.traversals.contentResource)}traverseUnknown(c){if(!c["@type"]||typeof c=="string")return c;switch(function(y){if(y==null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(y))throw new Error("Array is not a valid entity");if(typeof y!="object")throw new Error(typeof y+" is not a valid entity");if(typeof y["@type"]=="string"){const C=Y.indexOf(y["@type"]);if(C!==-1)return Y[C]}if(y.profile)return"Service";if(y.format||y["@type"])return"ContentResource";throw new Error("Resource type is not known")}(c)){case"sc:Collection":return this.traverseCollection(c);case"sc:Manifest":return this.traverseManifest(c);case"sc:Canvas":return this.traverseCanvas(c);case"sc:Sequence":return this.traverseSequence(c);case"sc:Range":return this.traverseRange(c);case"oa:Annotation":return this.traverseAnnotation(c);case"sc:AnnotationList":return this.traverseAnnotationList(c);case"sc:Layer":return this.traverseLayer(c);case"Service":return this.traverseService(c);case"oa:Choice":return this.traverseChoice(c);case"ContentResource":return this.traverseContentResource(c)}return c.profile?this.traverseService(c):c}traverseImageResource(c){const y=Array.isArray(c),C=Array.isArray(c)?c:[c],L=[];for(const j of C)typeof j=="string"?L.push(this.traverseContentResource({"@id":j,"@type":"dctypes:Image"})):L.push(this.traverseContentResource(j));return y||this.options.convertPropsToArray?L:L[0]}traverseDescriptive(c){return c.thumbnail&&(c.thumbnail=this.traverseImageResource(c.thumbnail)),c.logo&&(c.logo=this.traverseImageResource(c.logo)),c}traverseOneOrMoreServices(c){const y=Array.isArray(c),C=Array.isArray(c)?c:[c],L=[];for(const j of C)L.push(this.traverseService(j));return y||this.options.convertPropsToArray?L:L[0]}traverseLinking(c){return c.related&&(c.related=this.traverseOneOrManyType(c.related,this.traversals.contentResource)),c.rendering&&(c.rendering=this.traverseOneOrManyType(c.rendering,this.traversals.contentResource)),c.service&&(c.service=this.traverseOneOrMoreServices(c.service)),c.seeAlso&&(c.seeAlso=this.traverseOneOrManyType(c.seeAlso,this.traversals.contentResource)),c.within&&(typeof c.within=="string"||(c.within=this.traverseOneOrManyType(c.within,this.traversals.contentResource))),c.startCanvas&&(typeof c.startCanvas=="string"?c.startCanvas=this.traverseType({"@id":c.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):c.startCanvas&&this.traverseType(c.startCanvas,this.traversals.canvas)),c.contentLayer&&(typeof c.contentLayer=="string"?c.contentLayer=this.traverseLayer({"@id":c.contentLayer,"@type":"sc:Layer"}):c.contentLayer=this.traverseLayer(c.contentLayer)),c}traverseOneOrManyType(c,y){if(!Array.isArray(c)){if(!this.options.convertPropsToArray)return this.traverseType(c,y);c=[c]}return c.map(C=>this.traverseType(C,y))}traverseType(c,y){return y.reduce((C,L)=>{const j=L(C);return j!==void 0||this.options.allowUndefinedReturn?j:C},c)}}function H(f){for(const c in f)f[c]!==void 0&&f[c]!==null||delete f[c];return f}const J="Attribution",ee="http://example.org/provider",ge="Unknown";function E(f,c="none"){if(!f)return{};const y=Array.isArray(f)?f:[f],C={};for(const L of y){if(typeof L=="string"){C[c]=C[c]?C[c]:[],C[c].push(L||"");continue}if(!L["@language"]){C[c]=C[c]?C[c]:[],C[c].push(L["@value"]||"");continue}const j=L["@language"];C[j]=C[j]?C[j]:[],C[j].push(L["@value"]||"")}return C}function N(f){return Array.isArray(f)?N(f.find(c=>typeof c=="string")):X.indexOf(f)!==-1?"level2":$.indexOf(f)!==-1?"level1":typeof f=="string"?f:void 0}function G(f){for(const c of["sc","oa","dcterms","dctypes","iiif"])if(f.startsWith(`${c}:`))return f.slice(c.length+1);return f}const ue=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function nt(f){const c=f["@id"]||f.id;let y=f["@type"]||f.type;const C=f.profile||void 0,L=f["@context"]||void 0;if(C){const j=function(B){switch(B){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}(C);if(j)return j}if(L){const j=function(B){const Ve=Array.isArray(B)?B:[B];for(const _e of Ve)switch(_e){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}(L);if(j)return j}if(y){if(Array.isArray(y)){if(y.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(y.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";y=y[0]}for(const j of["sc","oa","dcterms","dctypes","iiif"])if(y.startsWith(`${j}:`)){y=y.slice(j.length+1);break}switch(y){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(y&&ue.indexOf(y)!==-1)return y;if(f.format){if(f.format.startsWith("image/"))return"Image";if(f.format.startsWith("text/")||f.format==="application/pdf")return"Text";if(f.format.startsWith("application/"))return"Dataset"}return c&&(c.endsWith(".jpg")||c.endsWith(".png")||c.endsWith(".jpeg"))?"Image":y||"unknown"}const Ai=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Si(f){const c=f.match(Ai);return c?c[0]:f}const wi=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function Ci(f){if(f){const c=Array.isArray(f)?f:[f],y=[];for(const C of c)C==="http://iiif.io/api/presentation/2/context.json"&&y.push("http://iiif.io/api/presentation/3/context.json"),wi.indexOf(C)===-1&&y.push(C);if(c.length)return y.length===1?y[0]:y}}let Bt=0;function zt(f,c){const y=encodeURI(f.id||f["@id"]||"").trim();return y&&c?`${y}/${c}`:y||(Bt++,`http://example.org/${f["@type"]}${c?`/${c}`:""}/${Bt}`)}function ne(f){const c=[...f.behavior||[]];let y;return f.viewingHint&&c.push(f.viewingHint),Array.isArray(f.motivation)?y=f.motivation.map(G):f.motivation&&(y=G(f.motivation)),{"@context":f["@context"]?Ci(f["@context"]):void 0,id:(f["@id"]||zt(f)).trim(),type:nt(f),behavior:c.length?c:void 0,height:f.height?f.height:void 0,width:f.width?f.width:void 0,motivation:y,viewingDirection:f.viewingDirection,profile:f.profile,format:f.format?f.format:void 0,duration:void 0,timeMode:void 0}}function ie(f){const[c,y]=function(j,B="Rights/License",Ve="none"){let _e=null;const Wt=[],Ti=Array.isArray(j)?j:[j];for(const Qt of Ti){const fe=Qt?Si(Qt):void 0;!fe||fe.indexOf("creativecommons.org")===-1&&fe.indexOf("rightsstatements.org")===-1?fe&&Wt.push({label:{[Ve]:[B]},value:{[Ve]:[fe]}}):_e=fe.startsWith("https://")?`http://${fe.slice(8)}`:fe}return[_e,Wt]}(f.license),C=[...f.metadata?(L=f.metadata,L?L.map(j=>({label:E(j.label),value:E(j.value)})):[]):[],...y];var L;return{rights:c,metadata:C.length?C:void 0,label:f.label?E(f.label):void 0,requiredStatement:f.attribution?{label:E(J),value:E(f.attribution)}:void 0,navDate:f.navDate,summary:f.description?E(f.description):void 0,thumbnail:Mi(f.thumbnail)}}function Mi(f){return f&&(Array.isArray(f)?f:[f]).map(c=>typeof c=="string"?{id:c,type:"Image"}:(c.type==="unknown"&&(c.type="Image"),c))}function Ri(f){if(!f.within)return;const c=Array.isArray(f.within)?f.within:[f.within],y=[];for(const C of c)typeof C=="string"?C&&f["@type"]==="sc:Manifest"&&y.push({id:C,type:"Collection"}):C["@id"]&&y.push({id:C["@id"],type:nt(C)});return y.length?y:void 0}function le(f){const c=f.related?Array.isArray(f.related)?f.related:[f.related]:[],y=f.contentLayer;return{provider:f.logo||c.length?[{id:ee,type:"Agent",homepage:c.length?[c[0]]:void 0,logo:f.logo?Array.isArray(f.logo)?f.logo:[f.logo]:void 0,label:E(ge)}]:void 0,partOf:Ri(f),rendering:f.rendering,seeAlso:f.seeAlso,start:f.startCanvas,service:f.service?(C=f.service,Array.isArray(C)?C:C?[C]:[]):void 0,supplementary:y?[y]:void 0};var C}function it(f){const c=f;return H({...ne(c),...ie(c),...le(c),...(y=c,{chars:y.chars,format:y.format?y.format:void 0,language:y.language})});var y}const Ii=new _({collection:[function(f){return H({...ne(f),...ie(f),...le(f),items:f.members})}],manifest:[function(f){const c=[],y=[];let C;for(const j of f.sequences||[])j.canvases.length&&c.push(...j.canvases),j.behavior&&y.push(...j.behavior),j.startCanvas&&(C=j.startCanvas);const L=ne(f);return y.length&&(L.behavior?L.behavior.push(...y):L.behavior=y),H({...L,...ie(f),...le(f),start:C,items:c,structures:f.structures})}],canvas:[function(f){return H({...ne(f),...ie(f),...le(f),annotations:f.otherContent&&f.otherContent.length?f.otherContent:void 0,items:f.images&&f.images.length?[{id:zt(f,"annotation-page"),type:"AnnotationPage",items:f.images}]:void 0})}],annotationList:[function(f){return H({...ne(f),...ie(f),...le(f),items:f.resources&&f.resources.length?f.resources:void 0})}],sequence:[function(f){return f.canvases&&f.canvases.length!==0?{canvases:f.canvases,behavior:f.viewingHint?[f.viewingHint]:[],startCanvas:f.startCanvas}:{canvases:[],behavior:[]}}],annotation:[function(f){return H({...ne(f),...ie(f),...le(f),target:function c(y){if(Array.isArray(y)){if(y.length>1)return{type:"List",items:y.map(c)};y=y[0]}if(typeof y=="string")return encodeURI(y).trim();if("@type"in y){let C;if(typeof y.full=="string")C=y.full;else if(y.full["@type"]==="dctypes:Image")C={id:y.full["@id"],type:"Image"};else{if(y.full["@type"]!=="sc:Canvas")throw new Error(`Unsupported source type on annotation: ${y.full["@type"]}`);C={id:y.full["@id"],type:"Canvas"}}return{type:"SpecificResource",source:C,selector:st(y.selector)}}return encodeURI(y["@id"]).trim()}(f.on),body:Array.isArray(f.resource)?f.resource.map(it):it(f.resource)})}],contentResource:[it],choice:[function(f){const c=[];return f.default&&f.default!=="rdf:nil"&&c.push(f.default),f.item&&f.item!=="rdf:nil"&&c.push(...f.item),{...ne(f),...ie(f),items:c}}],range:[function(f){return H({...ne(f),...ie(f),...le(f),items:f.members})}],service:[function(f){const{"@id":c,"@type":y,"@context":C,profile:L,...j}=f,B={};return c&&(B["@id"]=c),B["@type"]=nt(f),B["@type"]==="unknown"&&(C&&C.length&&(B["@context"]=C),B["@type"]="Service"),L&&(B.profile=N(L)),H({...B,...j})}],layer:[function(f){return H({...ne(f),...ie(f),...le(f)})}]});function st(f){if((Array.isArray(f["@type"])&&f["@type"].includes("oa:SvgSelector")||f["@type"]=="oa:SvgSelector")&&("chars"in f||"value"in f))return{type:"SvgSelector",value:"chars"in f?f.chars:f.value};if(f["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:f.value};if(f["@type"]==="oa:Choice")return[st(f.default),...(Array.isArray(f.item)?f.item:[f.item]).map(st)];if(f["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in f?f.region:void 0,rotation:"rotation"in f?f.rotation:void 0};throw new Error(`Unsupported selector type: ${f["@type"]}`)}const ki=function(f){return f&&f["@context"]&&(f["@context"]==="http://iiif.io/api/presentation/2/context.json"||f["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")!==-1||f["@context"]==="http://www.shared-canvas.org/ns/context.json")||f["@context"]==="http://iiif.io/api/image/2/context.json"?Ii.traverseUnknown(f):f};s.upgrade=ki,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})})})(fr,fr.exports);function Oo(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function Ht(e,t){const{selector:r,source:n}=Te(t);if(n.id!==e.id)return[null,n];const i={type:"BoxSelector",spatial:{x:0,y:0,width:Number(e.width),height:Number(e.height)}};return[r?r.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:r.temporal,spatial:i.spatial}:r:null,n]}const _n={makeChoice:()=>{}},Ge={type:"unknown"},D=e=>({type:"unknown",reason:e,annotations:{pages:[]}}),Un=(e,t)=>({type:"empty",width:e,height:t,annotations:{pages:[]},image:null,images:[]});function Lo(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function Fo(e,t){return U(r=>{const n=[];if(!e)return n;const i=Object.keys(r.iiif.entities.AnnotationPage);for(const s of i)if(!t||t.indexOf(s)!==-1){const a=Lo(r,s);a&&a.views&&a.views[e]&&n.push(s)}return n},[e,t])}function Hn({canvas:e,manifest:t,all:r,canvases:n}){const i=[];if(t)for(const s of t.annotations)i.indexOf(s.id)===-1&&i.push(s.id);if(r){if(n&&n.length)for(const s of n)for(const a of s.annotations)i.indexOf(a.id)===-1&&i.push(a.id)}else if(e)for(const s of e.annotations)i.indexOf(s.id)===-1&&i.push(s.id);return i}function $o(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function Nn(e,t={}){const r=V(),n=ve(),i=re(),s=Et(),a=v.useMemo(()=>Hn({all:t.all,manifest:n,canvas:i,canvases:s}),[t.all,i,s,n]),o=Fo(e,t.all?void 0:a),u=v.useCallback(l=>{e&&r.setMetaValue([l,"annotationPageManager","views"],p=>p&&!p[e]?p:{...p||{},[e]:!1})},[e,r]),d=v.useCallback((l,p={})=>{if(!e)return;const g=r.getState(),b=[];if(p!=null&&p.deselectOthers){const h=Object.keys(g.iiif.entities.AnnotationPage);for(const x of h){const A=$o(g,x);A&&A.views&&A.views[e]&&b.push(x)}}for(const h of b)u(h);r.setMetaValue([l,"annotationPageManager","views"],h=>h&&h[e]?h:{...h||{},[e]:!0})},[e,u,r]);return{availablePageIds:a,enabledPageIds:o,setPageEnabled:d,setPageDisabled:u}}function Bn(e,t){return U((r,n)=>n.get(e.map(i=>({id:i,type:t}))),[e,t])}const zn=v.createContext(new Se.ImageServiceLoader);function Xe(){return v.useContext(zn)}function Wn(){const e=Xe(),[t,r]=v.useState({}),n=v.useRef(!1);return v.useEffect(()=>()=>{n.current=!0},[]),[v.useCallback((s,{height:a,width:o})=>{if(s){const u=s.id||s["@id"],d=e.loadServiceSync({id:u,width:s.width||o,height:s.height||a,source:s});d?s=d:t[u]||(n.current||r(l=>({...l,[u]:"loading"})),e.loadService({id:u,width:s.width||o,height:s.height||a}).then(()=>{n.current||r(l=>({...l,[u]:"done"}))}))}return s},[e,t]),t]}function et(e={}){const t=qt(),r=re(e.canvasId?{id:e.canvasId}:void 0);return U((n,i)=>{if(!r)return[];if(t&&e.enableSingleAnnotation)return[t];const s=i.get(r.items),a=[];for(const o of s)a.push(...i.get(o.items));return a},[r])}function Do(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}const Be={},Qn={get(e){return e},setMetaValue([e,t,r],n){const i=Qn.getResourceMeta(e,t),s=i?i[r]:void 0,a=typeof n=="function"?n(s):n;Be[e]={...Be[e]||{},[t]:{...(Be[e]||{})[t]||{},[r]:a}}},getResourceMeta:(e,t)=>{const r=Be[e];if(r)return t?r[t]:r}};function qo(e=Qn){function t(i){const s=i?typeof i=="string"?e.get(i):i:null;if(!s)return[];const a=e.get(s.items,{parent:s}),o=[];for(const u of a)o.push(...e.get(u.items,{parent:u}));return o}function r(i,s=[]){const a=Array.isArray(i)?i:t(i),o=[];let u=null;const d=[];for(const l of a){if(l.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const p=Array.from(Array.isArray(l.body)?l.body:[l.body]);for(const g of p){const[b,{selector:h}]=Do(g),x=e.get(b),A=(x.type||"unknown").toLowerCase();if(A==="choice"){const S=e.get(x.items,{parent:x.id}),w=s.length?s.map(M=>S.find(T=>T.id===M)).filter(Boolean):[S[0]];w.length===0&&w.push(S[0]),u={type:"single-choice",items:S.map(M=>({id:M.id,label:M.label,selected:w.indexOf(M)!==-1})),label:b.label},p.push(...w);continue}o.indexOf(A)===-1&&o.push(A),d.push({type:A,annotationId:l.id,resource:x,target:l.target,selector:h})}}return{types:o,items:d,choice:u}}function n(i){const{choice:s}=r(i);return s}return{getAllPaintingAnnotations:t,getPaintables:r,extractChoices:n}}function Yn(e,t=[]){const r=V(),n=v.useMemo(()=>qo(r),[]),i=et({enableSingleAnnotation:e==null?void 0:e.enableSingleAnnotation}),[s,a]=v.useState((e==null?void 0:e.defaultChoices)||[]),o=v.useMemo(()=>n.getPaintables(i,s),[r,i,s,...t]),d={makeChoice:v.useCallback((l,{deselectOthers:p=!0,deselect:g=!1}={})=>{if(o.choice){if(o.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");a(b=>{if(g){const x=b.filter(A=>A!==l);if(x.length===0){const A=o.items[0].resource.id;return A?[A]:[]}return x}if(p)return[l];const h=[...b];if(h.length===0&&o.items.length){const x=o.items[0].resource.id;x&&h.push(x)}return b.indexOf(l)!==-1?b:[...b,l]})}},[o.choice])};return[o,d]}function Gn(e,t,r){const n=[];for(const i of t.items){const s=i.resource&&i.resource.type==="SpecificResource"?i.resource.source:i.resource;if(!s.id)return D("No resource Identifier");let a;if(s.service){const b=Se.getImageServices(s);b[0]&&(a=r(b[0],e))}const o={type:"BoxSelector",spatial:{x:0,y:0,width:Number(e.width),height:Number(e.height)}},[u,d]=Ht(e,i.target);if(d.id!==e.id)continue;i.resource.width&&i.resource.height&&(i.resource.width,i.resource.height);let l=i.resource.type==="SpecificResource"?de(i.resource):null;if(i.selector){const b=de({type:"SpecificResource",source:i.resource,selector:i.selector});b&&(l=b)}const p=l&&l.selector&&(l.selector.type==="BoxSelector"||l.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:l.selector.spatial.x,y:l.selector.spatial.y,width:l.selector.spatial.width,height:l.selector.spatial.height}}:void 0;a&&!a.id&&(a.id=a["@id"]);const g={id:s.id,type:"Image",annotationId:i.annotationId,width:Number(u||p?s.width:e.width),height:Number(u||p?s.height:e.height),service:a,sizes:a&&a.sizes?a.sizes:s.width&&s.height?[{width:s.width,height:s.height}]:[],target:u&&u.type!=="PointSelector"?u:o,selector:p};n.push(g)}return{type:"images",image:n[0],images:n,choice:t.choice}}const Vo=["model/gltf-binary"];function _o(e,t){const n=t.items[0].resource;return n.format?Vo.indexOf(n.format)===-1?D(`3D format: ${n.format} is unsupported`):{type:"3d-model",model:n}:D("Unknown format")}function Uo(e,t){var n;if(!e.duration)return D("No duration on canvas");if(t.items.length>1)return D("Only one audio source supported");const r=(n=t.items[0])==null?void 0:n.resource;return r?r.format?{type:"media",media:{annotationId:t.items[0].annotationId,duration:e.duration,url:r.id,type:"Sound",target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:r.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}},annotations:{pages:[]}}:D("Audio does not have format"):D("Unknown audio")}const Ho=/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?vi?=|&vi?=))([^#&?]*).*/;function No(e,t){var a;const r=t.items.filter(o=>o.type==="video");if(!e.duration)return D("No duration on canvas");if(r.length>1)return D("Only one video source supported");const n=(a=r[0])==null?void 0:a.resource,i=!!(n.service||[]).find(o=>(o.profile||"").includes("youtube.com"));if(!n)return D("Unknown video");if((!n.format||n.format==="text/html")&&!i)return D("Video does not have format");const s={annotationId:t.items[0].annotationId,duration:e.duration,url:n.id,type:"Video",items:[],target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:n.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}};if(i){s.type="VideoYouTube";const o=n.id.match(Ho);if(!o[1])return D("Video is not known youtube video");s.youTubeId=o[1]}return{type:"media",media:s,annotations:{pages:[]}}}function Jn(e,t={},r){const n=e.language||r||"none";switch(e.type){case"TextualBody":{typeof e.value<"u"&&(t[n]=e.value);break}case"List":case"Composite":case"Choice":e.items&&e.items.forEach(i=>Jn(i,t,n))}return t}function Bo(e,t){const r=[];return t.items.forEach(n=>{if(n.resource){const[i]=Ht(e,n.target);r.push({annotationId:n.annotationId,text:Jn(n.resource),target:i})}}),{type:"textual-content",items:r}}function Kn(e){const t=ve(),r=re(),n=V(),[i,s]=Wn(),{enabledPageIds:a}=Nn((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(r==null?void 0:r.id),{all:!1}),o=Bn(a,"AnnotationPage"),u=(e==null?void 0:e.strategies)||["empty","images","media","textual-content","complex-timeline"],[d,l]=Yn(e,[s]),p=v.useMemo(()=>{if(!r)return console.log("No canvas"),Ge;if(d.types.length===0)return u.indexOf("empty")!==-1?Un(r.width,r.height):(console.log("No paintables"),Ge);if(d.types.length!==1)if(d.types.length===2&&d.types.indexOf("text")!==-1)d.types=d.types.filter(b=>b!=="text");else return u.indexOf("complex-timeline")===-1?D("Complex timeline not supported"):D("ComplexTimelineStrategy not yet supported");const g=d.types[0];return g==="image"?u.indexOf("images")===-1?D("Image not supported"):Gn(r,d,i):g==="Model"||g==="model"?u.indexOf("3d-model")===-1?D("3D not supported"):_o(r,d):g==="textualbody"?u.indexOf("textual-content")===-1?D("Textual content not supported"):Bo(r,d):g==="sound"||g==="audio"?u.indexOf("media")===-1?D("Media not supported"):Uo(r,d):g==="video"?u.indexOf("media")===-1?D("Media not supported"):No(r,d):(console.log("No idea"),Ge)},[r,d,n,l.makeChoice]);return v.useMemo(()=>p.type==="unknown"?[p,_n]:[{...p,annotations:{pages:o}},l],[p,o])}const Zn=(e,t=[])=>{const r=V();v.useEffect(()=>{e(r)},[r,...t])},ze={},Xn={get(e){return e},setMetaValue([e,t,r],n){const i=Xn.getResourceMeta(e,t),s=i?i[r]:void 0,a=typeof n=="function"?n(s):n;ze[e]={...ze[e]||{},[t]:{...(ze[e]||{})[t]||{},[r]:a}}},getResourceMeta:(e,t)=>{const r=ze[e];if(r)return t?r[t]:r}},zo=new Se.ImageServiceLoader;function Wo(e=Xn,t={}){const r=t.imageServiceLoader||zo;async function n(i,s,a=!1,o=[],u){const d=()=>r.getThumbnailFromResource(void 0,s,a,o);if(!i)return await r.getThumbnailFromResource(void 0,s,a,o);if(typeof i=="string"){const p=Se.getFixedSizeFromImage(i);return p&&o.push(p),await r.getThumbnailFromResource(void 0,s,a,o)}const l=e.get(i,{skipSelfReturn:!1});if(typeof l=="string")return{best:Se.getFixedSizeFromImage(l),fallback:[],log:[]};if(!l)return await d();switch(await(async p=>{if(p&&p.thumbnail&&p.thumbnail.length){const g=e.get(p.thumbnail[0]),b=await r.getImageCandidates(g,a);b&&b.length&&o.push(...b)}})(l),l.type){case"Annotation":{const p=Array.isArray(l.body)?l.body:[l.body],g=e.get(p[0]);return u&&!g.width&&(g.width=u.width,g.height=u.height),await r.getThumbnailFromResource(g,s,a,o)}case"Canvas":{const p=l;return n(p.items[0],s,a,o,{width:p.width,height:p.height})}case"AnnotationPage":return n(l.items[0],s,a,o,u);case"Choice":{const p=l;return!p.items||p.items[0]?await d():n(p.items[0],s,a,o,u)}case"Collection":{const p=l.items[0];return p?n(p,s,a,o,u):await d()}case"Manifest":{const p=l.items[0];return p?n(p,s,a,o,u):await d()}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return u&&!l.width&&(l.width=u.width,l.height=u.height),r.getThumbnailFromResource(l,s,a,o)}return await d()}return{getBestThumbnailAtSize:n}}function ei(e,t,{canvasId:r,manifestId:n}={}){const i=V(),s=Xe(),a=v.useMemo(()=>Wo(i,{imageServiceLoader:s}),[i,s]),[o,u]=v.useState(),d=ve(n?{id:n}:void 0),l=re(r?{id:r}:void 0),p=l||d,g=v.useRef(!1);if(v.useEffect(()=>(g.current=!1,()=>{g.current=!0}),[]),!p)throw new Error("Must be called under a manifest or canvas context.");return Zn(b=>{a.getBestThumbnailAtSize(p,e,t).then(h=>{h.best&&!g.current&&u(h.best)})},[p]),o}function Qo(e){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:e}}function Yo(e,t){switch(t.type){case"FINISHED":return{...e,isFinished:!0,isPlaying:!1,playRequested:!1};case"PLAY_PAUSE":return{...e,isFinished:!1,isPlaying:!e.isPlaying};case"PLAY_REQUESTED":return{...e,isFinished:!1,playRequested:!0};case"PAUSE":return{...e,isPlaying:!1};case"PLAY":return{...e,isFinished:!1,playRequested:!1,isPlaying:!0};case"MUTE":return{...e,isMuted:!0};case"SET_VOLUME":return{...e,volume:t.volume,isMuted:t.volume===0};case"TOGGLE_MUTE":return{...e,isMuted:!e.isMuted};case"UNMUTE":return{...e,isMuted:!1}}return e}function ti(e){const t=Math.round(e);return`${Math.floor(t/60)}:${`${t%60}`.padStart(2,"0")}`}function tt(e){const[t,r]=v.useReducer(Yo,Qo(e.duration)),n=v.useRef(null),i=v.useRef(null),s=v.useRef(null),a=v.useRef(!1),o=v.useCallback(()=>{i.current&&n.current&&(i.current.innerHTML=ti(n.current.currentTime),s.current&&(s.current.style.width=`${n.current.currentTime/e.duration*100}%`),a.current!==n.current.muted&&(a.current=n.current.muted,r(n.current.muted?{type:"MUTE"}:{type:"UNMUTE"})))},[e.duration]),u=v.useCallback(()=>{n.current&&(r({type:"PLAY_REQUESTED"}),n.current.play().then(()=>{r({type:"PLAY"})}),o())},[o]),d=v.useCallback(()=>{n.current&&(n.current.duration>0&&n.current.paused?u():l())},[o]),l=v.useCallback(()=>{n.current&&(n.current.pause(),r({type:"PAUSE"}),o())},[o]),p=v.useCallback(()=>{n.current&&(n.current.muted=!n.current.muted,r(n.current.muted?{type:"MUTE"}:{type:"UNMUTE"}))},[]),g=v.useCallback(()=>{n.current&&(n.current.muted=!0,r({type:"MUTE"}))},[]),b=v.useCallback(()=>{n.current&&(n.current.muted=!1,r({type:"UNMUTE"}))},[]),h=v.useCallback(S=>{n.current&&(n.current.muted=!1,n.current.volume=S/100,r({type:"SET_VOLUME",volume:S}))},[]),x=v.useCallback(S=>{n.current&&(n.current.currentTime=Math.max(0,Math.min(S*e.duration,e.duration)),o())},[]),A=v.useCallback(S=>{n.current&&(n.current.currentTime=Math.max(0,Math.min(S,e.duration)),o())},[]);return v.useEffect(()=>{const S=setInterval(()=>{o()},350);return()=>clearInterval(S)},[o,e.duration]),v.useEffect(()=>{const S=()=>{r({type:"FINISHED"})},w=n.current;return w==null||w.addEventListener("ended",S),()=>w==null?void 0:w.removeEventListener("ended",S)},[]),[{element:n,currentTime:i,progress:s},t,{play:u,pause:l,playPause:d,mute:g,unmute:b,toggleMute:p,setVolume:h,setDurationPercent:x,setTime:A}]}const ri=v.createContext(null),ni=v.createContext(null),ii=v.createContext(null);function Go(){const e=v.useContext(ri);if(!e)throw new Error("Ctx not found");return e}function Jo(){const e=v.useContext(ni);if(!e)throw new Error("Ctx not found");return e}function Ko(){const e=v.useContext(ii);if(!e)throw new Error("Ctx not found");return e}function Nt({actions:e,state:t,children:r,currentTime:n,progress:i,element:s}){return m.jsx(ii.Provider,{value:{currentTime:n,progress:i,element:s},children:m.jsx(ni.Provider,{value:e,children:m.jsx(ri.Provider,{value:t,children:r})})})}function si({media:e,children:t}){const[{element:r,currentTime:n,progress:i},s,a]=tt({duration:e.duration});return m.jsxs(Nt,{state:s,actions:a,currentTime:n,progress:i,element:r,children:[m.jsx("audio",{ref:r,src:e.url}),t]})}function ai({media:e,mediaControlsDeps:t,children:r}){return Ie("portal","audio",si,{media:e,children:r},[e,...t||[]]),null}function oi({element:e,media:t,playPause:r}){return m.jsxs("div",{className:"video-container",part:"video-container",onClick:r,children:[m.jsx("style",{children:`
|
|
65
|
+
*/function Va(e,t,r,n=1){return new yn(e,t,r).subdivide(n)}function _a(e,t,r,n,i=1){return new _t(new Float64Array([e.x,e.y,t.x,t.y,r.x,r.y,n.x,n.y])).subdivide(i)}function Ua(e){return e.x*e.x+e.y*e.y}function Le(e){return e/(1-.67+Math.pow(Math.pow(.67,4)+.25*e*e,.25))}function Me(e){return e*(1-.39+Math.sqrt(.39*.39+.25*e*e))}class yn{constructor(t,r,n){Qe(this,"start"),Qe(this,"control"),Qe(this,"end"),this.start=t,this.control=r,this.end=n}eval(t){const r=1-t;return{x:this.start.x*r*r+2*this.control.x*r*t+this.end.x*t*t,y:this.start.y*r*r+2*this.control.y*r*t+this.end.y*t*t}}mapToBasic(){const{x:t,y:r}=this.start,{x:n,y:i}=this.control,{x:s,y:a}=this.end,o=2*n-t-s,u=2*i-r-a,f=(n-t)*o+(i-r)*u,l=(s-n)*o+(a-i)*u,d=(s-t)*u-(a-r)*o,g=f/d,b=l/d,h=Math.abs(d)/(Math.hypot(o,u)*Math.abs(b-g));return{x0:t,x2:s,scale:h,cross:d}}subdivide(t){const r=this.mapToBasic(),n=Le(r.x0),i=Le(r.x2),s=.5*Math.abs(i-n)*Math.sqrt(r.scale/t),a=Math.ceil(s),o=Me(n),u=Me(i),f=[0];for(let l=1;l<a;l++){const d=(Me(n+(i-n)*l/a)-o)/(u-o);f.push(d)}return f.push(1),f.map(l=>this.eval(l))}}class _t{constructor(t){Qe(this,"c"),this.c=t}weightsum(t,r,n,i){const s=t*this.c[0]+r*this.c[2]+n*this.c[4]+i*this.c[6],a=t*this.c[1]+r*this.c[3]+n*this.c[5]+i*this.c[7];return{x:s,y:a}}eval(t){const r=1-t,n=r*r*r,i=3*r*r*t,s=3*r*t*t,a=t*t*t;return this.weightsum(n,i,s,a)}deriv(t){const r=1-t,n=-3*r*r,i=3*t*t,s=-6*t*r-n,a=6*t*r-i;return this.weightsum(n,s,a,i)}midpoint_quadbez(){const t=this.weightsum(-.25,.75,.75,-.25);return new yn({x:this.c[0],y:this.c[1]},t,{x:this.c[6],y:this.c[7]})}subsegment(t,r){const n=new Float64Array(8),i=this.eval(t),s=this.eval(r);n[0]=i.x,n[1]=i.y;const a=(r-t)/3,o=this.deriv(t);n[2]=i.x+a*o.x,n[3]=i.y+a*o.y;const u=this.deriv(r);return n[4]=s.x-a*u.x,n[5]=s.y-a*u.y,n[6]=s.x,n[7]=s.y,new _t(n)}subdivide(t){const r=.1*t,n=t-r,i=Math.sqrt(n),s=Ua(this.weightsum(1,-3,3,-1)),a=Math.ceil(Math.pow(s/(432*r*r),1/6)),o=[];let u=0;for(let h=0;h<a;h++){const x=h/a,A=(h+1)/a,S=this.subsegment(x,A).midpoint_quadbez(),w=S.mapToBasic(),M=Le(w.x0),T=Le(w.x2),F=Math.sqrt(w.scale);let k=Math.abs(T-M)*F;if(Math.sign(w.x0)!=Math.sign(w.x2)){const O=i/F,E=i*Math.abs(T-M)/Le(O);k=Math.max(k,E)}o.push({quad:S,a0:M,a2:T,val:k}),u+=k}const f=.5*u/i,l=Math.ceil(f),d=[{x:this.c[0],y:this.c[1]}];let g=0,b=0;for(let h=1;h<l;h++){const x=u*h/l;for(;g+o[b].val<x;)g+=o[b].val,b++;const A=o[b].a0,S=o[b].a2,w=Me(A),M=Me(S),T=A+(S-A)*(x-g)/o[b].val,F=(Me(T)-w)/(M-w);d.push(o[b].quad.eval(F))}return d.push({x:this.c[6],y:this.c[7]}),d}}const Ha=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,Na=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,or=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function Ye(e,{domParser:t,svgPreprocessor:r,iiifRenderingHints:n}={}){if(Array.isArray(e))return Z(e.reduce((i,s)=>{const{selector:a,selectors:o,iiifRenderingHints:u}=Ye(s,{domParser:t,svgPreprocessor:r,iiifRenderingHints:n});return a&&(i.selector||(i.selector=a),i.selectors.push(...o)),u&&(i.iiifRenderingHints=i.iiifRenderingHints||{type:"ImageApiSelector"},Object.assign(i.iiifRenderingHints,u)),i},{selector:null,selectors:[],iiifRenderingHints:n}));if(!e)return Z({selector:null,selectors:[],iiifRenderingHints:n});if(typeof e=="string"){const[i,s]=e.split("#");return s?Ye({type:"FragmentSelector",value:s},{svgPreprocessor:r,iiifRenderingHints:n,domParser:t}):Z({selector:null,selectors:[],iiifRenderingHints:n})}if(e.type&&e.type==="PointSelector"&&(e.t||e.t===0)){const i={type:"TemporalSelector",temporal:{startTime:e.t}};return Z({selector:i,selectors:[i],iiifRenderingHints:n})}if(Qa(e)){const i=[];if(e.region){const s=Ye({type:"FragmentSelector",value:"xywh="+e.region},{domParser:t,svgPreprocessor:r,iiifRenderingHints:n});i.push(...s.selectors)}return Z({selector:i[0],selectors:i,iiifRenderingHints:n?{...n,...e}:e})}if(e.type==="FragmentSelector"){const i=Ha.exec(e.value);if(i){const a={type:"BoxSelector",spatial:{unit:i[2]==="percent:"||i[2]==="pct:"?"percent":"pixel",x:parseFloat(i[3]),y:parseFloat(i[4]),width:parseFloat(i[5]),height:parseFloat(i[6])}};return Z({selector:a,selectors:[a],iiifRenderingHints:n})}const s=e.value.match(Na);if(s){const a={type:"TemporalSelector",temporal:{startTime:s[4]?parseFloat(s[4]):0,endTime:s[7]?parseFloat(s[7]):void 0}};return Z({selector:a,selectors:[a],iiifRenderingHints:n})}return Z({selector:null,selectors:[],iiifRenderingHints:n})}if(e.type==="SvgSelector"&&"value"in e){t||(typeof window<"u"?t=new window.DOMParser:console.warn("No DOMParser available, cannot parse SVG selector, `points`, `spatial` and `style` will be unavailable and the SVG will not be normalized."));let i=[],s,a,o=(r==null?void 0:r(e.value))??e.value,u;if(t){const l=t.parseFromString(e.value,"image/svg+xml").querySelector("svg");if(!l)return console.warn(`Illegal SVG selector: ${e.value}`),Z({selector:null,selectors:[],iiifRenderingHints:n});const d=gn(l);d&&(i=d.points,u=d.shapeType,s=[Math.min(...i.map(g=>g[0])),Math.min(...i.map(g=>g[1])),Math.max(...i.map(g=>g[0])),Math.max(...i.map(g=>g[1]))],{style:a,svg:o}=Wa(d.element)??{svg:o})}const f={type:"SvgSelector",svg:o,svgShape:u,style:a,points:i.length?i:void 0,spatial:s?{unit:"pixel",x:s[0],y:s[1],width:s[2]-s[0],height:s[3]-s[1]}:void 0};return Z({selector:f,selectors:[f],iiifRenderingHints:n})}return Z({selector:null,selectors:[],iiifRenderingHints:n})}function Ba(e){const t=e.map(n=>n[0]).reduce((n,i)=>(n[i]+=1,n),{C:0,Q:0,L:0,M:0}),r=new Set(e.map(n=>n[0]));if(t.C>0||t.Q>0)return"path";if(t.L>0&&(r.size===1||r.size===2&&r.has("M"))){if(t.L===4)return"rect";const n=e.slice(-1)[0];return e[0][0]==="M"&&n[0]==="L"&&n[1]==e[0][1]&&n[2]===e[0][2]||n[1]===0&&n[2]===0?"polygon":"polyline"}return"path"}function gn(e){var t;for(const r of Array.from(e.children))switch(r==null?void 0:r.tagName.toLowerCase()){case"g":{const n=gn(r);if(n)return n}continue;case"path":{const n=r.getAttribute("d");if(!n)continue;const i=qa(n);return{element:r,points:za(i),shapeType:Ba(i)}}case"circle":{const n=parseFloat(r.getAttribute("cx")??"0"),i=parseFloat(r.getAttribute("cy")??"0"),s=parseFloat(r.getAttribute("r")??"0");if(!s)continue;const a=[];for(let o=0;o<=360;o+=12){const u=o*Math.PI/180;a.push([n+s*Math.cos(u),i+s*Math.sin(u)])}return{element:r,points:a,shapeType:"circle"}}case"ellipse":{const n=parseFloat(r.getAttribute("cx")??"0"),i=parseFloat(r.getAttribute("cy")??"0"),s=parseFloat(r.getAttribute("rx")??"0"),a=parseFloat(r.getAttribute("ry")??"0");if(!s&&!a)continue;const o=[];for(let u=0;u<=360;u+=12){const f=Math.tan(u/360*Math.PI),l=s*(1-f**2)/(1+f**2),d=a*2*f/(1+f**2);o.push([n+l,i+d])}return{element:r,points:o,shapeType:"ellipse"}}case"line":{const n=parseFloat(r.getAttribute("x0")??"0"),i=parseFloat(r.getAttribute("y0")??"0"),s=parseFloat(r.getAttribute("x1")??"0"),a=parseFloat(r.getAttribute("y1")??"0");if(n===s&&i===a)continue;return{element:r,points:[[n,i],[s,a]],shapeType:"polyline"}}case"polygon":case"polyline":{const n=((t=r.getAttribute("points"))==null?void 0:t.split(" ").map(s=>s.split(",").map(parseFloat)))??[];if(!n.length)continue;let i="polyline";return r.tagName.toLowerCase()==="polygon"&&(n.push(n[0]),i="polygon"),{element:r,points:n,shapeType:i}}case"rect":{const n=parseFloat(r.getAttribute("x")??"0"),i=parseFloat(r.getAttribute("y")??"0"),s=parseFloat(r.getAttribute("width")??"0"),a=parseFloat(r.getAttribute("height")??"0");if(!s||!a)continue;return{element:r,points:[[n,i],[n+s,i],[n+s,i+a],[n,i+a],[n,i]],shapeType:"rect"}}default:continue}return null}function za(e){const t=[];for(let r=0;r<e.length;r++){const n=t[t.length-1]??[0,0],i=e[r];switch(i[0]){case"M":case"L":t.push([i[1],i[2]]);continue;case"C":t.push(..._a({x:n[0],y:n[1]},{x:i[1],y:i[2]},{x:i[3],y:i[4]},{x:i[5],y:i[6]}).map(s=>[s.x,s.y]).slice(1));continue;case"Q":t.push(...Va({x:n[0],y:n[1]},{x:i[1],y:i[2]},{x:i[3],y:i[4]}).map(s=>[s.x,s.y]).slice(1));continue}}return t}function Wa(e){const t={};if(e.hasAttribute("fill")?(t.fill=e.getAttribute("fill"),e.removeAttribute("fill")):e.style.fill&&(t.fill=e.style.fill),t.fill){const n=or.exec(t.fill);n&&(t.fillOpacity=parseFloat(n[4]),t.fill=`rgb(${n[1]}, ${n[2]}, ${n[3]})`)}if(e.hasAttribute("fill-opacity")?(t.fillOpacity=parseFloat(e.getAttribute("fill-opacity")),e.removeAttribute("fill-opacity")):e.style.fillOpacity&&(t.fillOpacity=parseFloat(e.style.fillOpacity)),e.hasAttribute("stroke")?(t.stroke=e.getAttribute("stroke"),e.removeAttribute("stroke")):e.style.stroke&&(t.stroke=e.style.stroke),t.stroke){const n=or.exec(t.stroke);n&&(t.strokeOpacity=parseFloat(n[4]),t.stroke=`rgb(${n[1]}, ${n[2]}, ${n[3]})`)}e.hasAttribute("stroke-opacity")?(t.strokeOpacity=parseFloat(e.getAttribute("stroke-opacity")),e.removeAttribute("stroke-opacity")):e.style.strokeOpacity&&(t.strokeOpacity=parseFloat(e.style.strokeOpacity)),e.hasAttribute("stroke-width")?(t.strokeWidth=e.getAttribute("stroke-width"),e.removeAttribute("stroke-width")):e.style.strokeWidth&&(t.strokeWidth=e.style.strokeWidth),e.hasAttribute("stroke-dasharray")?(t.strokeDasharray=e.getAttribute("stroke-dasharray"),e.removeAttribute("stroke-dasharray")):e.style.strokeDasharray&&(t.strokeDasharray=e.style.strokeDasharray);let r=e;for(;r.tagName.toLowerCase()!=="svg";)if(r=r.parentElement,r===null)throw new Error("Could not find root SVG element");return{svg:r.outerHTML,style:Object.keys(t).length>0?t:void 0}}function Qa(e){return!!e&&e.type==="iiif:ImageApiSelector"&&e.type==="iiif:ImageApiSelector"}function Z(e){if(e.iiifRenderingHints){const t=e.iiifRenderingHints;if(t.rotation){const r=Ya(t.rotation);if(r)if(e.selectors.length)for(const n of e.selectors)n.rotation=r;else e.selectors.push({type:"RotationSelector",rotation:r})}}else delete e.iiifRenderingHints;return e}function Ya(e){let t=parseFloat(e);return t&&e.startsWith("!")&&(t=360-t),t&&(t=t%360),t!==t?0:t||0}function Te(e,t={}){if(Array.isArray(e))return Te(e[0]);if(typeof e=="string"){const[r,n]=e.split("#");return n?Te({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{id:r,type:t.typeMap&&t.typeMap[r]||"Unknown"},selector:null,selectors:[]}}if(e.type==="Choice"||e.type==="List"||e.type==="Composite"||e.type==="Independents")return Te(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:r,selectors:n}=e.selector?Ye(e.selector,t):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:r,selectors:n}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[r,n]=e.id.split("#");return n?Te({type:"SpecificResource",source:{...e,id:r},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{...e,id:r},selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}var Ga=Object.defineProperty,Ja=(e,t,r)=>t in e?Ga(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,cr=(e,t,r)=>(Ja(e,typeof t!="symbol"?t+"":t,r),r);function Ka(e){return Array.isArray(e)?e:e?[e]:[]}const ur=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function Za(e){if(typeof e>"u"||e===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(e))throw new Error("Array is not a valid entity");if(typeof e!="object")throw new Error(`${typeof e} is not a valid entity`);if(typeof e["@type"]=="string"){const t=ur.indexOf(e["@type"]);if(t!==-1)return ur[t]}if(e.profile)return"Service";if(e.format||e["@type"])return"ContentResource";throw new Error("Resource type is not known")}class Ut{constructor(t,r={}){cr(this,"traversals"),cr(this,"options"),this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...t},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...r}}static all(t){return new Ut({collection:[t],manifest:[t],canvas:[t],annotationList:[t],sequence:[t],annotation:[t],contentResource:[t],choice:[t],range:[t],service:[t],layer:[t]})}traverseCollection(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(t))),this.traversals.collection)}traverseCollectionItems(t){if(this.options.mergeMemberProperties){const r=[...(t.manifests||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n),...(t.collections||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n),...t.members||[]];delete t.collections,delete t.manifests,t.members=r}return t.manifests&&(t.manifests=t.manifests.map(r=>this.traverseManifest(typeof r=="string"?{"@id":r,"@type":"sc:Manifest"}:r))),t.collections&&(t.collections=t.collections.map(r=>this.traverseCollection(typeof r=="string"?{"@id":r,"@type":"sc:Collection"}:r))),t.members&&(t.members=t.members.map(r=>typeof r=="string"?r:this.traverseUnknown(r))),t}traverseManifest(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(t))),this.traversals.manifest)}traverseManifestItems(t){return t.sequences&&(t.sequences=t.sequences.map(r=>this.traverseSequence(r))),t.structures&&(t.structures=t.structures.map(r=>this.traverseRange(r))),t}traverseSequence(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(t))),this.traversals.sequence)}traverseSequenceItems(t){return t.canvases&&(t.canvases=t.canvases.map(r=>this.traverseCanvas(r))),t}traverseCanvas(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(t))),this.traversals.canvas)}traverseCanvasItems(t){return t.images&&(t.images=t.images.map(r=>this.traverseAnnotation(r))),t.otherContent&&(t.otherContent=t.otherContent.map(r=>this.traverseAnnotationList(r))),t}traverseRange(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(t))),this.traversals.range)}traverseRangeItems(t){if(this.options.mergeMemberProperties){const r=[...(t.ranges||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Range"}:n),...(t.canvases||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Canvas"}:n),...t.members||[]];delete t.ranges,delete t.canvases,t.members=r.length?r.map(n=>this.traverseUnknown(n)):void 0}return t}traverseAnnotationList(t){const r=typeof t=="string"?{"@id":t,"@type":"sc:AnnotationList"}:t;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(r)),this.traversals.annotationList)}traverseAnnotationListItems(t){return t.resources&&(t.resources=t.resources.map(r=>this.traverseAnnotation(r))),t}traverseAnnotation(t){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(t))),this.traversals.annotation)}traverseAnnotationItems(t){return t.resource&&(Array.isArray(t.resource)?t.resource=t.resource.map(r=>this.traverseContentResource(r)):t.resource=this.traverseContentResource(t.resource)),t.on,t}traverseLayer(t){return this.traverseType(this.traverseLinking(this.traverseLayerItems(t)),this.traversals.layer)}traverseLayerItems(t){return t.otherContent&&(t.otherContent=t.otherContent.map(r=>this.traverseAnnotationList(r))),t}traverseChoice(t){return this.traverseType(this.traverseChoiceItems(t),this.traversals.choice)}traverseChoiceItems(t){return t.default&&t.default!=="rdf:nil"&&(t.default=this.traverseContentResource(t.default)),t.item&&t.item!=="rdf:nil"&&(t.item=t.item.map(r=>this.traverseContentResource(r))),t}traverseService(t){return this.traverseType(this.traverseLinking(t),this.traversals.service)}traverseContentResource(t){return t["@type"]==="oa:Choice"?this.traverseChoice(t):this.traverseType(this.traverseDescriptive(this.traverseLinking(t)),this.traversals.contentResource)}traverseUnknown(t){if(!t["@type"]||typeof t=="string")return t;switch(Za(t)){case"sc:Collection":return this.traverseCollection(t);case"sc:Manifest":return this.traverseManifest(t);case"sc:Canvas":return this.traverseCanvas(t);case"sc:Sequence":return this.traverseSequence(t);case"sc:Range":return this.traverseRange(t);case"oa:Annotation":return this.traverseAnnotation(t);case"sc:AnnotationList":return this.traverseAnnotationList(t);case"sc:Layer":return this.traverseLayer(t);case"Service":return this.traverseService(t);case"oa:Choice":return this.traverseChoice(t);case"ContentResource":return this.traverseContentResource(t)}return t.profile?this.traverseService(t):t}traverseImageResource(t){const r=Array.isArray(t),n=Array.isArray(t)?t:[t],i=[];for(const s of n)typeof s=="string"?i.push(this.traverseContentResource({"@id":s,"@type":"dctypes:Image"})):i.push(this.traverseContentResource(s));return!r&&!this.options.convertPropsToArray?i[0]:i}traverseDescriptive(t){return t.thumbnail&&(t.thumbnail=this.traverseImageResource(t.thumbnail)),t.logo&&(t.logo=this.traverseImageResource(t.logo)),t}traverseOneOrMoreServices(t){const r=Array.isArray(t),n=Array.isArray(t)?t:[t],i=[];for(const s of n)i.push(this.traverseService(s));return!r&&!this.options.convertPropsToArray?i[0]:i}traverseLinking(t){return t.related&&(t.related=this.traverseOneOrManyType(t.related,this.traversals.contentResource)),t.rendering&&(t.rendering=this.traverseOneOrManyType(t.rendering,this.traversals.contentResource)),t.service&&(t.service=this.traverseOneOrMoreServices(t.service)),t.seeAlso&&(t.seeAlso=this.traverseOneOrManyType(t.seeAlso,this.traversals.contentResource)),t.within&&(typeof t.within=="string"||(t.within=this.traverseOneOrManyType(t.within,this.traversals.contentResource))),t.startCanvas&&(typeof t.startCanvas=="string"?t.startCanvas=this.traverseType({"@id":t.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):t.startCanvas&&this.traverseType(t.startCanvas,this.traversals.canvas)),t.contentLayer&&(typeof t.contentLayer=="string"?t.contentLayer=this.traverseLayer({"@id":t.contentLayer,"@type":"sc:Layer"}):t.contentLayer=this.traverseLayer(t.contentLayer)),t}traverseOneOrManyType(t,r){if(!Array.isArray(t))if(this.options.convertPropsToArray)t=[t];else return this.traverseType(t,r);return t.map(n=>this.traverseType(n,r))}traverseType(t,r){return r.reduce((n,i)=>{const s=i(n);return typeof s>"u"&&!this.options.allowUndefinedReturn?n:s},t)}}const Xa="http://library.stanford.edu/iiif/image-api/compliance.html#level0",mn="http://library.stanford.edu/iiif/image-api/compliance.html#level1",xn="http://library.stanford.edu/iiif/image-api/compliance.html#level2",eo="http://library.stanford.edu/iiif/image-api/conformance.html#level0",bn="http://library.stanford.edu/iiif/image-api/conformance.html#level1",An="http://library.stanford.edu/iiif/image-api/conformance.html#level2",to="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Sn="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",wn="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",ro="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Cn="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Mn="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",no="http://iiif.io/api/image/1/level0.json",io="http://iiif.io/api/image/1/profiles/level0.json",Rn="http://iiif.io/api/image/1/level1.json",In="http://iiif.io/api/image/1/profiles/level1.json",kn="http://iiif.io/api/image/1/level2.json",Tn="http://iiif.io/api/image/1/profiles/level2.json",so="http://iiif.io/api/image/2/level0.json",ao="http://iiif.io/api/image/2/profiles/level0.json",jn="http://iiif.io/api/image/2/level1.json",Pn="http://iiif.io/api/image/2/profiles/level1.json",En="http://iiif.io/api/image/2/level2.json",On="http://iiif.io/api/image/2/profiles/level2.json",oo="level0",Ln="level1",Fn="level2",co="http://iiif.io/api/image/2/level0",$n="http://iiif.io/api/image/2/level1",Dn="http://iiif.io/api/image/2/level2",uo=[$n,Dn,mn,xn,bn,An,Sn,wn,Cn,Mn,Rn,In,kn,Tn,jn,Pn,En,On,Ln,Fn],lo=[co,$n,Dn,Xa,mn,xn,eo,bn,An,to,Sn,wn,ro,Cn,Mn,no,io,Rn,In,kn,Tn,so,ao,jn,Pn,En,On,oo,Ln,Fn];function ae(e){for(const t in e)(typeof e[t]>"u"||e[t]===null)&&delete e[t];return e}const Rt={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function Ae(e,t="none"){if(!e)return{};const r=Array.isArray(e)?e:[e],n={};for(const i of r){if(typeof i=="string"){n[t]=n[t]?n[t]:[],n[t].push(i||"");continue}if(!i["@language"]){n[t]=n[t]?n[t]:[],n[t].push(i["@value"]||"");continue}const s=i["@language"];n[s]=n[s]?n[s]:[],n[s].push(i["@value"]||"")}return n}function qn(e){if(Array.isArray(e))return qn(e.find(t=>typeof t=="string"));if(lo.indexOf(e)!==-1)return"level2";if(uo.indexOf(e)!==-1)return"level1";if(typeof e=="string")return e}function fo(e){const t=Array.isArray(e)?e:[e];for(const r of t)switch(r){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function po(e){switch(e){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}function lr(e){for(const t of["sc","oa","dcterms","dctypes","iiif"])if(e.startsWith(`${t}:`))return e.slice(t.length+1);return e}const ho=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function Ht(e){const t=e["@id"]||e.id;let r=e["@type"]||e.type;const n=e.profile||void 0,i=e["@context"]||void 0;if(n){const s=po(n);if(s)return s}if(i){const s=fo(i);if(s)return s}if(r){if(Array.isArray(r)){if(r.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(r.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";r=r[0]}for(const s of["sc","oa","dcterms","dctypes","iiif"])if(r.startsWith(`${s}:`)){r=r.slice(s.length+1);break}switch(r){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(r&&ho.indexOf(r)!==-1)return r;if(e.format){if(e.format.startsWith("image/"))return"Image";if(e.format.startsWith("text/")||e.format==="application/pdf")return"Text";if(e.format.startsWith("application/"))return"Dataset"}return t&&(t.endsWith(".jpg")||t.endsWith(".png")||t.endsWith(".jpeg"))?"Image":r||"unknown"}const vo=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function yo(e){const t=e.match(vo);return t?t[0]:e}function go(e,t="Rights/License",r="none"){let n=null;const i=[],s=Array.isArray(e)?e:[e];for(const a of s){const o=a?yo(a):void 0;if(o&&(o.indexOf("creativecommons.org")!==-1||o.indexOf("rightsstatements.org")!==-1)){o.startsWith("https://")?n=`http://${o.slice(8)}`:n=o;continue}o&&i.push({label:{[r]:[t]},value:{[r]:[o]}})}return[n,i]}const mo=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function xo(e){if(e){const t=Array.isArray(e)?e:[e],r=[];for(const n of t)n==="http://iiif.io/api/presentation/2/context.json"&&r.push("http://iiif.io/api/presentation/3/context.json"),mo.indexOf(n)===-1&&r.push(n);if(t.length)return r.length===1?r[0]:r}}function bo(e){return e?e.map(t=>({label:Ae(t.label),value:Ae(t.value)})):[]}let fr=0;function Vn(e,t){const r=encodeURI(e.id||e["@id"]||"").trim();return r&&t?`${r}/${t}`:r||(fr++,`http://example.org/${e["@type"]}${t?`/${t}`:""}/${fr}`)}function oe(e){const t=[...e.behavior||[]];e.viewingHint&&t.push(e.viewingHint);let r;return Array.isArray(e.motivation)?r=e.motivation.map(lr):e.motivation&&(r=lr(e.motivation)),{"@context":e["@context"]?xo(e["@context"]):void 0,id:(e["@id"]||Vn(e)).trim(),type:Ht(e),behavior:t.length?t:void 0,height:e.height?e.height:void 0,width:e.width?e.width:void 0,motivation:r,viewingDirection:e.viewingDirection,profile:e.profile,format:e.format?e.format:void 0,duration:void 0,timeMode:void 0}}function ce(e){const[t,r]=go(e.license),n=[...e.metadata?bo(e.metadata):[],...r];return{rights:t,metadata:n.length?n:void 0,label:e.label?Ae(e.label):void 0,requiredStatement:e.attribution?{label:Ae(Rt.attributionLabel),value:Ae(e.attribution)}:void 0,navDate:e.navDate,summary:e.description?Ae(e.description):void 0,thumbnail:Ao(e.thumbnail)}}function Ao(e){return e&&(Array.isArray(e)?e:[e]).map(t=>typeof t=="string"?{id:t,type:"Image"}:(t.type==="unknown"&&(t.type="Image"),t))}function So(e){if(!e.within)return;const t=Array.isArray(e.within)?e.within:[e.within],r=[];for(const n of t)if(typeof n=="string"){if(n)switch(e["@type"]){case"sc:Manifest":r.push({id:n,type:"Collection"});break}}else n["@id"]&&r.push({id:n["@id"],type:Ht(n)});return r.length?r:void 0}function ye(e){const t=e.related?Array.isArray(e.related)?e.related:[e.related]:[],r=e.contentLayer;return{provider:e.logo||t.length?[{id:Rt.providerId,type:"Agent",homepage:t.length?[t[0]]:void 0,logo:e.logo?Array.isArray(e.logo)?e.logo:[e.logo]:void 0,label:Ae(Rt.providerName)}]:void 0,partOf:So(e),rendering:e.rendering,seeAlso:e.seeAlso,start:e.startCanvas,service:e.service?Ka(e.service):void 0,supplementary:r?[r]:void 0}}function wo(e){return{chars:e.chars,format:e.format?e.format:void 0,language:e.language}}function Co(e){return ae({...oe(e),...ce(e),...ye(e),items:e.members})}function Mo(e){const t=[],r=[];let n;for(const s of e.sequences||[])s.canvases.length&&t.push(...s.canvases),s.behavior&&r.push(...s.behavior),s.startCanvas&&(n=s.startCanvas);const i=oe(e);return r.length&&(i.behavior?i.behavior.push(...r):i.behavior=r),ae({...i,...ce(e),...ye(e),start:n,items:t,structures:e.structures})}function Ro(e){return ae({...oe(e),...ce(e),...ye(e),annotations:e.otherContent&&e.otherContent.length?e.otherContent:void 0,items:e.images&&e.images.length?[{id:Vn(e,"annotation-page"),type:"AnnotationPage",items:e.images}]:void 0})}function Io(e){return ae({...oe(e),...ce(e),...ye(e),items:e.resources&&e.resources.length?e.resources:void 0})}function ko(e){return!e.canvases||e.canvases.length===0?{canvases:[],behavior:[]}:{canvases:e.canvases,behavior:e.viewingHint?[e.viewingHint]:[],startCanvas:e.startCanvas}}function To(e){function t(r){if(Array.isArray(r)){if(r.length>1)return{type:"List",items:r.map(t)};r=r[0]}if(typeof r=="string")return encodeURI(r).trim();if("@type"in r){let n;if(typeof r.full=="string")n=r.full;else if(r.full["@type"]==="dctypes:Image")n={id:r.full["@id"],type:"Image"};else if(r.full["@type"]==="sc:Canvas")n={id:r.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${r.full["@type"]}`);return{type:"SpecificResource",source:n,selector:kt(r.selector)}}else return encodeURI(r["@id"]).trim()}return ae({...oe(e),...ce(e),...ye(e),target:t(e.on),body:Array.isArray(e.resource)?e.resource.map(It):It(e.resource)})}function It(e){const t=e;return ae({...oe(t),...ce(t),...ye(t),...wo(t)})}function jo(e){const t=[];return e.default&&e.default!=="rdf:nil"&&t.push(e.default),e.item&&e.item!=="rdf:nil"&&t.push(...e.item),{...oe(e),...ce(e),items:t}}function Po(e){return ae({...oe(e),...ce(e),...ye(e),items:e.members})}function Eo(e){const{"@id":t,"@type":r,"@context":n,profile:i,...s}=e,a={};return t&&(a["@id"]=t),a["@type"]=Ht(e),a["@type"]==="unknown"&&(n&&n.length&&(a["@context"]=n),a["@type"]="Service"),i&&(a.profile=qn(i)),ae({...a,...s})}function Oo(e){return ae({...oe(e),...ce(e),...ye(e)})}new Ut({collection:[Co],manifest:[Mo],canvas:[Ro],annotationList:[Io],sequence:[ko],annotation:[To],contentResource:[It],choice:[jo],range:[Po],service:[Eo],layer:[Oo]});function kt(e){if((Array.isArray(e["@type"])&&e["@type"].includes("oa:SvgSelector")||e["@type"]=="oa:SvgSelector")&&("chars"in e||"value"in e))return{type:"SvgSelector",value:"chars"in e?e.chars:e.value};if(e["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:e.value};if(e["@type"]==="oa:Choice")return[kt(e.default),...(Array.isArray(e.item)?e.item:[e.item]).map(kt)];if(e["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in e?e.region:void 0,rotation:"rotation"in e?e.rotation:void 0};throw new Error(`Unsupported selector type: ${e["@type"]}`)}var pr={exports:{}};(function(e,t){var r=Object.defineProperty,n=(s,a,o)=>a in s?r(s,a,{enumerable:!0,configurable:!0,writable:!0,value:o}):s[a]=o,i=(s,a,o)=>(n(s,typeof a!="symbol"?a+"":a,o),o);(function(s,a){a(t)})(ka,function(s){const a="http://library.stanford.edu/iiif/image-api/compliance.html#level1",o="http://library.stanford.edu/iiif/image-api/compliance.html#level2",u="http://library.stanford.edu/iiif/image-api/conformance.html#level1",f="http://library.stanford.edu/iiif/image-api/conformance.html#level2",l="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",d="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",g="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",b="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",h="http://iiif.io/api/image/1/level1.json",x="http://iiif.io/api/image/1/profiles/level1.json",A="http://iiif.io/api/image/1/level2.json",S="http://iiif.io/api/image/1/profiles/level2.json",w="http://iiif.io/api/image/2/level1.json",M="http://iiif.io/api/image/2/profiles/level1.json",T="http://iiif.io/api/image/2/level2.json",F="http://iiif.io/api/image/2/profiles/level2.json",k="level1",O="level2",E="http://iiif.io/api/image/2/level1",R="http://iiif.io/api/image/2/level2",$=[E,R,a,o,u,f,l,d,g,b,h,x,A,S,w,M,T,F,k,O],X=["http://iiif.io/api/image/2/level0",E,R,"http://library.stanford.edu/iiif/image-api/compliance.html#level0",a,o,"http://library.stanford.edu/iiif/image-api/conformance.html#level0",u,f,"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",l,d,"http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",g,b,"http://iiif.io/api/image/1/level0.json","http://iiif.io/api/image/1/profiles/level0.json",h,x,A,S,"http://iiif.io/api/image/2/level0.json","http://iiif.io/api/image/2/profiles/level0.json",w,M,T,F,"level0",k,O],Y=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];class _{constructor(c,y={}){i(this,"traversals"),i(this,"options"),this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...c},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...y}}static all(c){return new _({collection:[c],manifest:[c],canvas:[c],annotationList:[c],sequence:[c],annotation:[c],contentResource:[c],choice:[c],range:[c],service:[c],layer:[c]})}traverseCollection(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(c))),this.traversals.collection)}traverseCollectionItems(c){if(this.options.mergeMemberProperties){const y=[...(c.manifests||[]).map(C=>typeof C=="string"?{"@id":C,"@type":"sc:Manifest"}:C),...(c.collections||[]).map(C=>typeof C=="string"?{"@id":C,"@type":"sc:Collection"}:C),...c.members||[]];delete c.collections,delete c.manifests,c.members=y}return c.manifests&&(c.manifests=c.manifests.map(y=>this.traverseManifest(typeof y=="string"?{"@id":y,"@type":"sc:Manifest"}:y))),c.collections&&(c.collections=c.collections.map(y=>this.traverseCollection(typeof y=="string"?{"@id":y,"@type":"sc:Collection"}:y))),c.members&&(c.members=c.members.map(y=>typeof y=="string"?y:this.traverseUnknown(y))),c}traverseManifest(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(c))),this.traversals.manifest)}traverseManifestItems(c){return c.sequences&&(c.sequences=c.sequences.map(y=>this.traverseSequence(y))),c.structures&&(c.structures=c.structures.map(y=>this.traverseRange(y))),c}traverseSequence(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(c))),this.traversals.sequence)}traverseSequenceItems(c){return c.canvases&&(c.canvases=c.canvases.map(y=>this.traverseCanvas(y))),c}traverseCanvas(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(c))),this.traversals.canvas)}traverseCanvasItems(c){return c.images&&(c.images=c.images.map(y=>this.traverseAnnotation(y))),c.otherContent&&(c.otherContent=c.otherContent.map(y=>this.traverseAnnotationList(y))),c}traverseRange(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(c))),this.traversals.range)}traverseRangeItems(c){if(this.options.mergeMemberProperties){const y=[...(c.ranges||[]).map(C=>typeof C=="string"?{"@id":C,"@type":"sc:Range"}:C),...(c.canvases||[]).map(C=>typeof C=="string"?{"@id":C,"@type":"sc:Canvas"}:C),...c.members||[]];delete c.ranges,delete c.canvases,c.members=y.length?y.map(C=>this.traverseUnknown(C)):void 0}return c}traverseAnnotationList(c){const y=typeof c=="string"?{"@id":c,"@type":"sc:AnnotationList"}:c;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(y)),this.traversals.annotationList)}traverseAnnotationListItems(c){return c.resources&&(c.resources=c.resources.map(y=>this.traverseAnnotation(y))),c}traverseAnnotation(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(c))),this.traversals.annotation)}traverseAnnotationItems(c){return c.resource&&(Array.isArray(c.resource)?c.resource=c.resource.map(y=>this.traverseContentResource(y)):c.resource=this.traverseContentResource(c.resource)),c.on,c}traverseLayer(c){return this.traverseType(this.traverseLinking(this.traverseLayerItems(c)),this.traversals.layer)}traverseLayerItems(c){return c.otherContent&&(c.otherContent=c.otherContent.map(y=>this.traverseAnnotationList(y))),c}traverseChoice(c){return this.traverseType(this.traverseChoiceItems(c),this.traversals.choice)}traverseChoiceItems(c){return c.default&&c.default!=="rdf:nil"&&(c.default=this.traverseContentResource(c.default)),c.item&&c.item!=="rdf:nil"&&(c.item=c.item.map(y=>this.traverseContentResource(y))),c}traverseService(c){return this.traverseType(this.traverseLinking(c),this.traversals.service)}traverseContentResource(c){return c["@type"]==="oa:Choice"?this.traverseChoice(c):this.traverseType(this.traverseDescriptive(this.traverseLinking(c)),this.traversals.contentResource)}traverseUnknown(c){if(!c["@type"]||typeof c=="string")return c;switch(function(y){if(y==null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(y))throw new Error("Array is not a valid entity");if(typeof y!="object")throw new Error(typeof y+" is not a valid entity");if(typeof y["@type"]=="string"){const C=Y.indexOf(y["@type"]);if(C!==-1)return Y[C]}if(y.profile)return"Service";if(y.format||y["@type"])return"ContentResource";throw new Error("Resource type is not known")}(c)){case"sc:Collection":return this.traverseCollection(c);case"sc:Manifest":return this.traverseManifest(c);case"sc:Canvas":return this.traverseCanvas(c);case"sc:Sequence":return this.traverseSequence(c);case"sc:Range":return this.traverseRange(c);case"oa:Annotation":return this.traverseAnnotation(c);case"sc:AnnotationList":return this.traverseAnnotationList(c);case"sc:Layer":return this.traverseLayer(c);case"Service":return this.traverseService(c);case"oa:Choice":return this.traverseChoice(c);case"ContentResource":return this.traverseContentResource(c)}return c.profile?this.traverseService(c):c}traverseImageResource(c){const y=Array.isArray(c),C=Array.isArray(c)?c:[c],L=[];for(const j of C)typeof j=="string"?L.push(this.traverseContentResource({"@id":j,"@type":"dctypes:Image"})):L.push(this.traverseContentResource(j));return y||this.options.convertPropsToArray?L:L[0]}traverseDescriptive(c){return c.thumbnail&&(c.thumbnail=this.traverseImageResource(c.thumbnail)),c.logo&&(c.logo=this.traverseImageResource(c.logo)),c}traverseOneOrMoreServices(c){const y=Array.isArray(c),C=Array.isArray(c)?c:[c],L=[];for(const j of C)L.push(this.traverseService(j));return y||this.options.convertPropsToArray?L:L[0]}traverseLinking(c){return c.related&&(c.related=this.traverseOneOrManyType(c.related,this.traversals.contentResource)),c.rendering&&(c.rendering=this.traverseOneOrManyType(c.rendering,this.traversals.contentResource)),c.service&&(c.service=this.traverseOneOrMoreServices(c.service)),c.seeAlso&&(c.seeAlso=this.traverseOneOrManyType(c.seeAlso,this.traversals.contentResource)),c.within&&(typeof c.within=="string"||(c.within=this.traverseOneOrManyType(c.within,this.traversals.contentResource))),c.startCanvas&&(typeof c.startCanvas=="string"?c.startCanvas=this.traverseType({"@id":c.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):c.startCanvas&&this.traverseType(c.startCanvas,this.traversals.canvas)),c.contentLayer&&(typeof c.contentLayer=="string"?c.contentLayer=this.traverseLayer({"@id":c.contentLayer,"@type":"sc:Layer"}):c.contentLayer=this.traverseLayer(c.contentLayer)),c}traverseOneOrManyType(c,y){if(!Array.isArray(c)){if(!this.options.convertPropsToArray)return this.traverseType(c,y);c=[c]}return c.map(C=>this.traverseType(C,y))}traverseType(c,y){return y.reduce((C,L)=>{const j=L(C);return j!==void 0||this.options.allowUndefinedReturn?j:C},c)}}function H(p){for(const c in p)p[c]!==void 0&&p[c]!==null||delete p[c];return p}const J="Attribution",ee="http://example.org/provider",ge="Unknown";function P(p,c="none"){if(!p)return{};const y=Array.isArray(p)?p:[p],C={};for(const L of y){if(typeof L=="string"){C[c]=C[c]?C[c]:[],C[c].push(L||"");continue}if(!L["@language"]){C[c]=C[c]?C[c]:[],C[c].push(L["@value"]||"");continue}const j=L["@language"];C[j]=C[j]?C[j]:[],C[j].push(L["@value"]||"")}return C}function N(p){return Array.isArray(p)?N(p.find(c=>typeof c=="string")):X.indexOf(p)!==-1?"level2":$.indexOf(p)!==-1?"level1":typeof p=="string"?p:void 0}function G(p){for(const c of["sc","oa","dcterms","dctypes","iiif"])if(p.startsWith(`${c}:`))return p.slice(c.length+1);return p}const ue=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function nt(p){const c=p["@id"]||p.id;let y=p["@type"]||p.type;const C=p.profile||void 0,L=p["@context"]||void 0;if(C){const j=function(B){switch(B){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}(C);if(j)return j}if(L){const j=function(B){const Ve=Array.isArray(B)?B:[B];for(const _e of Ve)switch(_e){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}(L);if(j)return j}if(y){if(Array.isArray(y)){if(y.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(y.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";y=y[0]}for(const j of["sc","oa","dcterms","dctypes","iiif"])if(y.startsWith(`${j}:`)){y=y.slice(j.length+1);break}switch(y){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(y&&ue.indexOf(y)!==-1)return y;if(p.format){if(p.format.startsWith("image/"))return"Image";if(p.format.startsWith("text/")||p.format==="application/pdf")return"Text";if(p.format.startsWith("application/"))return"Dataset"}return c&&(c.endsWith(".jpg")||c.endsWith(".png")||c.endsWith(".jpeg"))?"Image":y||"unknown"}const Ai=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Si(p){const c=p.match(Ai);return c?c[0]:p}const wi=["http://iiif.io/api/presentation/2/context.json","http://iiif.io/api/image/2/context.json","http://iiif.io/api/image/1/context.json","http://library.stanford.edu/iiif/image-api/1.1/context.json","http://iiif.io/api/search/1/context.json","http://iiif.io/api/search/0/context.json","http://iiif.io/api/auth/1/context.json","http://iiif.io/api/auth/0/context.json","http://iiif.io/api/annex/openannotation/context.json"];function Ci(p){if(p){const c=Array.isArray(p)?p:[p],y=[];for(const C of c)C==="http://iiif.io/api/presentation/2/context.json"&&y.push("http://iiif.io/api/presentation/3/context.json"),wi.indexOf(C)===-1&&y.push(C);if(c.length)return y.length===1?y[0]:y}}let zt=0;function Wt(p,c){const y=encodeURI(p.id||p["@id"]||"").trim();return y&&c?`${y}/${c}`:y||(zt++,`http://example.org/${p["@type"]}${c?`/${c}`:""}/${zt}`)}function ne(p){const c=[...p.behavior||[]];let y;return p.viewingHint&&c.push(p.viewingHint),Array.isArray(p.motivation)?y=p.motivation.map(G):p.motivation&&(y=G(p.motivation)),{"@context":p["@context"]?Ci(p["@context"]):void 0,id:(p["@id"]||Wt(p)).trim(),type:nt(p),behavior:c.length?c:void 0,height:p.height?p.height:void 0,width:p.width?p.width:void 0,motivation:y,viewingDirection:p.viewingDirection,profile:p.profile,format:p.format?p.format:void 0,duration:void 0,timeMode:void 0}}function ie(p){const[c,y]=function(j,B="Rights/License",Ve="none"){let _e=null;const Qt=[],Ti=Array.isArray(j)?j:[j];for(const Yt of Ti){const fe=Yt?Si(Yt):void 0;!fe||fe.indexOf("creativecommons.org")===-1&&fe.indexOf("rightsstatements.org")===-1?fe&&Qt.push({label:{[Ve]:[B]},value:{[Ve]:[fe]}}):_e=fe.startsWith("https://")?`http://${fe.slice(8)}`:fe}return[_e,Qt]}(p.license),C=[...p.metadata?(L=p.metadata,L?L.map(j=>({label:P(j.label),value:P(j.value)})):[]):[],...y];var L;return{rights:c,metadata:C.length?C:void 0,label:p.label?P(p.label):void 0,requiredStatement:p.attribution?{label:P(J),value:P(p.attribution)}:void 0,navDate:p.navDate,summary:p.description?P(p.description):void 0,thumbnail:Mi(p.thumbnail)}}function Mi(p){return p&&(Array.isArray(p)?p:[p]).map(c=>typeof c=="string"?{id:c,type:"Image"}:(c.type==="unknown"&&(c.type="Image"),c))}function Ri(p){if(!p.within)return;const c=Array.isArray(p.within)?p.within:[p.within],y=[];for(const C of c)typeof C=="string"?C&&p["@type"]==="sc:Manifest"&&y.push({id:C,type:"Collection"}):C["@id"]&&y.push({id:C["@id"],type:nt(C)});return y.length?y:void 0}function le(p){const c=p.related?Array.isArray(p.related)?p.related:[p.related]:[],y=p.contentLayer;return{provider:p.logo||c.length?[{id:ee,type:"Agent",homepage:c.length?[c[0]]:void 0,logo:p.logo?Array.isArray(p.logo)?p.logo:[p.logo]:void 0,label:P(ge)}]:void 0,partOf:Ri(p),rendering:p.rendering,seeAlso:p.seeAlso,start:p.startCanvas,service:p.service?(C=p.service,Array.isArray(C)?C:C?[C]:[]):void 0,supplementary:y?[y]:void 0};var C}function it(p){const c=p;return H({...ne(c),...ie(c),...le(c),...(y=c,{chars:y.chars,format:y.format?y.format:void 0,language:y.language})});var y}const Ii=new _({collection:[function(p){return H({...ne(p),...ie(p),...le(p),items:p.members})}],manifest:[function(p){const c=[],y=[];let C;for(const j of p.sequences||[])j.canvases.length&&c.push(...j.canvases),j.behavior&&y.push(...j.behavior),j.startCanvas&&(C=j.startCanvas);const L=ne(p);return y.length&&(L.behavior?L.behavior.push(...y):L.behavior=y),H({...L,...ie(p),...le(p),start:C,items:c,structures:p.structures})}],canvas:[function(p){return H({...ne(p),...ie(p),...le(p),annotations:p.otherContent&&p.otherContent.length?p.otherContent:void 0,items:p.images&&p.images.length?[{id:Wt(p,"annotation-page"),type:"AnnotationPage",items:p.images}]:void 0})}],annotationList:[function(p){return H({...ne(p),...ie(p),...le(p),items:p.resources&&p.resources.length?p.resources:void 0})}],sequence:[function(p){return p.canvases&&p.canvases.length!==0?{canvases:p.canvases,behavior:p.viewingHint?[p.viewingHint]:[],startCanvas:p.startCanvas}:{canvases:[],behavior:[]}}],annotation:[function(p){return H({...ne(p),...ie(p),...le(p),target:function c(y){if(Array.isArray(y)){if(y.length>1)return{type:"List",items:y.map(c)};y=y[0]}if(typeof y=="string")return encodeURI(y).trim();if("@type"in y){let C;if(typeof y.full=="string")C=y.full;else if(y.full["@type"]==="dctypes:Image")C={id:y.full["@id"],type:"Image"};else{if(y.full["@type"]!=="sc:Canvas")throw new Error(`Unsupported source type on annotation: ${y.full["@type"]}`);C={id:y.full["@id"],type:"Canvas"}}return{type:"SpecificResource",source:C,selector:st(y.selector)}}return encodeURI(y["@id"]).trim()}(p.on),body:Array.isArray(p.resource)?p.resource.map(it):it(p.resource)})}],contentResource:[it],choice:[function(p){const c=[];return p.default&&p.default!=="rdf:nil"&&c.push(p.default),p.item&&p.item!=="rdf:nil"&&c.push(...p.item),{...ne(p),...ie(p),items:c}}],range:[function(p){return H({...ne(p),...ie(p),...le(p),items:p.members})}],service:[function(p){const{"@id":c,"@type":y,"@context":C,profile:L,...j}=p,B={};return c&&(B["@id"]=c),B["@type"]=nt(p),B["@type"]==="unknown"&&(C&&C.length&&(B["@context"]=C),B["@type"]="Service"),L&&(B.profile=N(L)),H({...B,...j})}],layer:[function(p){return H({...ne(p),...ie(p),...le(p)})}]});function st(p){if((Array.isArray(p["@type"])&&p["@type"].includes("oa:SvgSelector")||p["@type"]=="oa:SvgSelector")&&("chars"in p||"value"in p))return{type:"SvgSelector",value:"chars"in p?p.chars:p.value};if(p["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:p.value};if(p["@type"]==="oa:Choice")return[st(p.default),...(Array.isArray(p.item)?p.item:[p.item]).map(st)];if(p["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in p?p.region:void 0,rotation:"rotation"in p?p.rotation:void 0};throw new Error(`Unsupported selector type: ${p["@type"]}`)}const ki=function(p){return p&&p["@context"]&&(p["@context"]==="http://iiif.io/api/presentation/2/context.json"||p["@context"].indexOf("http://iiif.io/api/presentation/2/context.json")!==-1||p["@context"]==="http://www.shared-canvas.org/ns/context.json")||p["@context"]==="http://iiif.io/api/image/2/context.json"?Ii.traverseUnknown(p):p};s.upgrade=ki,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})})})(pr,pr.exports);function Lo(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function Nt(e,t){const{selector:r,source:n}=Te(t);if(n.id!==e.id)return[null,n];const i={type:"BoxSelector",spatial:{x:0,y:0,width:Number(e.width),height:Number(e.height)}};return[r?r.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:r.temporal,spatial:i.spatial}:r:null,n]}const _n={makeChoice:()=>{}},Ge={type:"unknown"},D=e=>({type:"unknown",reason:e,annotations:{pages:[]}}),Un=(e,t)=>({type:"empty",width:e,height:t,annotations:{pages:[]},image:null,images:[]});function Fo(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function $o(e,t){return U(r=>{const n=[];if(!e)return n;const i=Object.keys(r.iiif.entities.AnnotationPage);for(const s of i)if(!t||t.indexOf(s)!==-1){const a=Fo(r,s);a&&a.views&&a.views[e]&&n.push(s)}return n},[e,t])}function Hn({canvas:e,manifest:t,all:r,canvases:n}){const i=[];if(t)for(const s of t.annotations)i.indexOf(s.id)===-1&&i.push(s.id);if(r){if(n&&n.length)for(const s of n)for(const a of s.annotations)i.indexOf(a.id)===-1&&i.push(a.id)}else if(e)for(const s of e.annotations)i.indexOf(s.id)===-1&&i.push(s.id);return i}function Do(e,t){var n;const r=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return r?r.annotationPageManager:null}function Nn(e,t={}){const r=V(),n=ve(),i=re(),s=Et(),a=v.useMemo(()=>Hn({all:t.all,manifest:n,canvas:i,canvases:s}),[t.all,i,s,n]),o=$o(e,t.all?void 0:a),u=v.useCallback(l=>{e&&r.setMetaValue([l,"annotationPageManager","views"],d=>d&&!d[e]?d:{...d||{},[e]:!1})},[e,r]),f=v.useCallback((l,d={})=>{if(!e)return;const g=r.getState(),b=[];if(d!=null&&d.deselectOthers){const h=Object.keys(g.iiif.entities.AnnotationPage);for(const x of h){const A=Do(g,x);A&&A.views&&A.views[e]&&b.push(x)}}for(const h of b)u(h);r.setMetaValue([l,"annotationPageManager","views"],h=>h&&h[e]?h:{...h||{},[e]:!0})},[e,u,r]);return{availablePageIds:a,enabledPageIds:o,setPageEnabled:f,setPageDisabled:u}}function Bn(e,t){return U((r,n)=>n.get(e.map(i=>({id:i,type:t}))),[e,t])}const zn=v.createContext(new Se.ImageServiceLoader);function Xe(){return v.useContext(zn)}function Wn(){const e=Xe(),[t,r]=v.useState({}),n=v.useRef(!1);return v.useEffect(()=>()=>{n.current=!0},[]),[v.useCallback((s,{height:a,width:o})=>{if(s){const u=s.id||s["@id"],f=e.loadServiceSync({id:u,width:s.width||o,height:s.height||a,source:s});f?s=f:t[u]||(n.current||r(l=>({...l,[u]:"loading"})),e.loadService({id:u,width:s.width||o,height:s.height||a}).then(()=>{n.current||r(l=>({...l,[u]:"done"}))}))}return s},[e,t]),t]}function et(e={}){const t=Vt(),r=re(e.canvasId?{id:e.canvasId}:void 0);return U((n,i)=>{if(!r)return[];if(t&&e.enableSingleAnnotation)return[t];const s=i.get(r.items),a=[];for(const o of s)a.push(...i.get(o.items));return a},[r])}function qo(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}const Be={},Qn={get(e){return e},setMetaValue([e,t,r],n){const i=Qn.getResourceMeta(e,t),s=i?i[r]:void 0,a=typeof n=="function"?n(s):n;Be[e]={...Be[e]||{},[t]:{...(Be[e]||{})[t]||{},[r]:a}}},getResourceMeta:(e,t)=>{const r=Be[e];if(r)return t?r[t]:r}};function Vo(e=Qn){function t(i){const s=i?typeof i=="string"?e.get(i):i:null;if(!s)return[];const a=e.get(s.items,{parent:s}),o=[];for(const u of a)o.push(...e.get(u.items,{parent:u}));return o}function r(i,s=[]){const a=Array.isArray(i)?i:t(i),o=[];let u=null;const f=[];for(const l of a){if(l.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const d=Array.from(Array.isArray(l.body)?l.body:[l.body]);for(const g of d){const[b,{selector:h}]=qo(g),x=e.get(b),A=(x.type||"unknown").toLowerCase();if(A==="choice"){const S=e.get(x.items,{parent:x.id}),w=s.length?s.map(M=>S.find(T=>T.id===M)).filter(Boolean):[S[0]];w.length===0&&w.push(S[0]),u={type:"single-choice",items:S.map(M=>({id:M.id,label:M.label,selected:w.indexOf(M)!==-1})),label:b.label},d.push(...w);continue}o.indexOf(A)===-1&&o.push(A),f.push({type:A,annotationId:l.id,resource:x,target:l.target,selector:h})}}return{types:o,items:f,choice:u}}function n(i){const{choice:s}=r(i);return s}return{getAllPaintingAnnotations:t,getPaintables:r,extractChoices:n}}function Yn(e,t=[]){const r=V(),n=v.useMemo(()=>Vo(r),[]),i=et({enableSingleAnnotation:e==null?void 0:e.enableSingleAnnotation}),[s,a]=v.useState((e==null?void 0:e.defaultChoices)||[]),o=v.useMemo(()=>n.getPaintables(i,s),[r,i,s,...t]),f={makeChoice:v.useCallback((l,{deselectOthers:d=!0,deselect:g=!1}={})=>{if(o.choice){if(o.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");a(b=>{if(g){const x=b.filter(A=>A!==l);if(x.length===0){const A=o.items[0].resource.id;return A?[A]:[]}return x}if(d)return[l];const h=[...b];if(h.length===0&&o.items.length){const x=o.items[0].resource.id;x&&h.push(x)}return b.indexOf(l)!==-1?b:[...b,l]})}},[o.choice])};return[o,f]}function Gn(e,t,r){const n=[];for(const i of t.items){const s=i.resource&&i.resource.type==="SpecificResource"?i.resource.source:i.resource;if(!s.id)return D("No resource Identifier");let a;if(s.service){const b=Se.getImageServices(s);b[0]&&(a=r(b[0],e))}const o={type:"BoxSelector",spatial:{x:0,y:0,width:Number(e.width),height:Number(e.height)}},[u,f]=Nt(e,i.target);if(f.id!==e.id)continue;i.resource.width&&i.resource.height&&(i.resource.width,i.resource.height);let l=i.resource.type==="SpecificResource"?de(i.resource):null;if(i.selector){const b=de({type:"SpecificResource",source:i.resource,selector:i.selector});b&&(l=b)}const d=l&&l.selector&&(l.selector.type==="BoxSelector"||l.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:l.selector.spatial.x,y:l.selector.spatial.y,width:l.selector.spatial.width,height:l.selector.spatial.height}}:void 0;a&&!a.id&&(a.id=a["@id"]);const g={id:s.id,type:"Image",annotationId:i.annotationId,width:Number(u||d?s.width:e.width),height:Number(u||d?s.height:e.height),service:a,sizes:a&&a.sizes?a.sizes:s.width&&s.height?[{width:s.width,height:s.height}]:[],target:u&&u.type!=="PointSelector"?u:o,selector:d};n.push(g)}return{type:"images",image:n[0],images:n,choice:t.choice}}const _o=["model/gltf-binary"];function Uo(e,t){const n=t.items[0].resource;return n.format?_o.indexOf(n.format)===-1?D(`3D format: ${n.format} is unsupported`):{type:"3d-model",model:n}:D("Unknown format")}function Ho(e,t){var n;if(!e.duration)return D("No duration on canvas");if(t.items.length>1)return D("Only one audio source supported");const r=(n=t.items[0])==null?void 0:n.resource;return r?r.format?{type:"media",media:{annotationId:t.items[0].annotationId,duration:e.duration,url:r.id,type:"Sound",target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:r.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}},annotations:{pages:[]}}:D("Audio does not have format"):D("Unknown audio")}const No=/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?vi?=|&vi?=))([^#&?]*).*/;function Bo(e,t){var a;const r=t.items.filter(o=>o.type==="video");if(!e.duration)return D("No duration on canvas");if(r.length>1)return D("Only one video source supported");const n=(a=r[0])==null?void 0:a.resource,i=!!(n.service||[]).find(o=>(o.profile||"").includes("youtube.com"));if(!n)return D("Unknown video");if((!n.format||n.format==="text/html")&&!i)return D("Video does not have format");const s={annotationId:t.items[0].annotationId,duration:e.duration,url:n.id,type:"Video",items:[],target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:n.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}};if(i){s.type="VideoYouTube";const o=n.id.match(No);if(!o[1])return D("Video is not known youtube video");s.youTubeId=o[1]}return{type:"media",media:s,annotations:{pages:[]}}}function Jn(e,t={},r){const n=e.language||r||"none";switch(e.type){case"TextualBody":{typeof e.value<"u"&&(t[n]=e.value);break}case"List":case"Composite":case"Choice":e.items&&e.items.forEach(i=>Jn(i,t,n))}return t}function zo(e,t){const r=[];return t.items.forEach(n=>{if(n.resource){const[i]=Nt(e,n.target);r.push({annotationId:n.annotationId,text:Jn(n.resource),target:i})}}),{type:"textual-content",items:r}}function Kn(e){const t=ve(),r=re(),n=V(),[i,s]=Wn(),{enabledPageIds:a}=Nn((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(r==null?void 0:r.id),{all:!1}),o=Bn(a,"AnnotationPage"),u=(e==null?void 0:e.strategies)||["empty","images","media","textual-content","complex-timeline"],[f,l]=Yn(e,[s]),d=v.useMemo(()=>{if(!r)return console.log("No canvas"),Ge;if(f.types.length===0)return u.indexOf("empty")!==-1?Un(r.width,r.height):(console.log("No paintables"),Ge);if(f.types.length!==1)if(f.types.length===2&&f.types.indexOf("text")!==-1)f.types=f.types.filter(b=>b!=="text");else return u.indexOf("complex-timeline")===-1?D("Complex timeline not supported"):D("ComplexTimelineStrategy not yet supported");const g=f.types[0];return g==="image"?u.indexOf("images")===-1?D("Image not supported"):Gn(r,f,i):g==="Model"||g==="model"?u.indexOf("3d-model")===-1?D("3D not supported"):Uo(r,f):g==="textualbody"?u.indexOf("textual-content")===-1?D("Textual content not supported"):zo(r,f):g==="sound"||g==="audio"?u.indexOf("media")===-1?D("Media not supported"):Ho(r,f):g==="video"?u.indexOf("media")===-1?D("Media not supported"):Bo(r,f):(console.log("No idea"),Ge)},[r,f,n,l.makeChoice]);return v.useMemo(()=>d.type==="unknown"?[d,_n]:[{...d,annotations:{pages:o}},l],[d,o])}const Zn=(e,t=[])=>{const r=V();v.useEffect(()=>{e(r)},[r,...t])},ze={},Xn={get(e){return e},setMetaValue([e,t,r],n){const i=Xn.getResourceMeta(e,t),s=i?i[r]:void 0,a=typeof n=="function"?n(s):n;ze[e]={...ze[e]||{},[t]:{...(ze[e]||{})[t]||{},[r]:a}}},getResourceMeta:(e,t)=>{const r=ze[e];if(r)return t?r[t]:r}},Wo=new Se.ImageServiceLoader;function Qo(e=Xn,t={}){const r=t.imageServiceLoader||Wo;async function n(i,s,a=!1,o=[],u){const f=()=>r.getThumbnailFromResource(void 0,s,a,o);if(!i)return await r.getThumbnailFromResource(void 0,s,a,o);if(typeof i=="string"){const d=Se.getFixedSizeFromImage(i);return d&&o.push(d),await r.getThumbnailFromResource(void 0,s,a,o)}const l=e.get(i,{skipSelfReturn:!1});if(typeof l=="string")return{best:Se.getFixedSizeFromImage(l),fallback:[],log:[]};if(!l)return await f();switch(await(async d=>{if(d&&d.thumbnail&&d.thumbnail.length){const g=e.get(d.thumbnail[0]),b=await r.getImageCandidates(g,a);b&&b.length&&o.push(...b)}})(l),l.type){case"Annotation":{const d=Array.isArray(l.body)?l.body:[l.body],g=e.get(d[0]);return u&&!g.width&&(g.width=u.width,g.height=u.height),await r.getThumbnailFromResource(g,s,a,o)}case"Canvas":{const d=l;return n(d.items[0],s,a,o,{width:d.width,height:d.height})}case"AnnotationPage":return n(l.items[0],s,a,o,u);case"Choice":{const d=l;return!d.items||d.items[0]?await f():n(d.items[0],s,a,o,u)}case"Collection":{const d=l.items[0];return d?n(d,s,a,o,u):await f()}case"Manifest":{const d=l.items[0];return d?n(d,s,a,o,u):await f()}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return u&&!l.width&&(l.width=u.width,l.height=u.height),r.getThumbnailFromResource(l,s,a,o)}return await f()}return{getBestThumbnailAtSize:n}}function ei(e,t,{canvasId:r,manifestId:n}={}){const i=V(),s=Xe(),a=v.useMemo(()=>Qo(i,{imageServiceLoader:s}),[i,s]),[o,u]=v.useState(),f=ve(n?{id:n}:void 0),l=re(r?{id:r}:void 0),d=l||f,g=v.useRef(!1);if(v.useEffect(()=>(g.current=!1,()=>{g.current=!0}),[]),!d)throw new Error("Must be called under a manifest or canvas context.");return Zn(b=>{a.getBestThumbnailAtSize(d,e,t).then(h=>{h.best&&!g.current&&u(h.best)})},[d]),o}function Yo(e){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:e}}function Go(e,t){switch(t.type){case"FINISHED":return{...e,isFinished:!0,isPlaying:!1,playRequested:!1};case"PLAY_PAUSE":return{...e,isFinished:!1,isPlaying:!e.isPlaying};case"PLAY_REQUESTED":return{...e,isFinished:!1,playRequested:!0};case"PAUSE":return{...e,isPlaying:!1};case"PLAY":return{...e,isFinished:!1,playRequested:!1,isPlaying:!0};case"MUTE":return{...e,isMuted:!0};case"SET_VOLUME":return{...e,volume:t.volume,isMuted:t.volume===0};case"TOGGLE_MUTE":return{...e,isMuted:!e.isMuted};case"UNMUTE":return{...e,isMuted:!1}}return e}function ti(e){const t=Math.round(e);return`${Math.floor(t/60)}:${`${t%60}`.padStart(2,"0")}`}function tt(e){const[t,r]=v.useReducer(Go,Yo(e.duration)),n=v.useRef(null),i=v.useRef(null),s=v.useRef(null),a=v.useRef(!1),o=v.useCallback(()=>{i.current&&n.current&&(i.current.innerHTML=ti(n.current.currentTime),s.current&&(s.current.style.width=`${n.current.currentTime/e.duration*100}%`),a.current!==n.current.muted&&(a.current=n.current.muted,r(n.current.muted?{type:"MUTE"}:{type:"UNMUTE"})))},[e.duration]),u=v.useCallback(()=>{n.current&&(r({type:"PLAY_REQUESTED"}),n.current.play().then(()=>{r({type:"PLAY"})}),o())},[o]),f=v.useCallback(()=>{n.current&&(n.current.duration>0&&n.current.paused?u():l())},[o]),l=v.useCallback(()=>{n.current&&(n.current.pause(),r({type:"PAUSE"}),o())},[o]),d=v.useCallback(()=>{n.current&&(n.current.muted=!n.current.muted,r(n.current.muted?{type:"MUTE"}:{type:"UNMUTE"}))},[]),g=v.useCallback(()=>{n.current&&(n.current.muted=!0,r({type:"MUTE"}))},[]),b=v.useCallback(()=>{n.current&&(n.current.muted=!1,r({type:"UNMUTE"}))},[]),h=v.useCallback(S=>{n.current&&(n.current.muted=!1,n.current.volume=S/100,r({type:"SET_VOLUME",volume:S}))},[]),x=v.useCallback(S=>{n.current&&(n.current.currentTime=Math.max(0,Math.min(S*e.duration,e.duration)),o())},[]),A=v.useCallback(S=>{n.current&&(n.current.currentTime=Math.max(0,Math.min(S,e.duration)),o())},[]);return v.useEffect(()=>{const S=setInterval(()=>{o()},350);return()=>clearInterval(S)},[o,e.duration]),v.useEffect(()=>{const S=()=>{r({type:"FINISHED"})},w=n.current;return w==null||w.addEventListener("ended",S),()=>w==null?void 0:w.removeEventListener("ended",S)},[]),[{element:n,currentTime:i,progress:s},t,{play:u,pause:l,playPause:f,mute:g,unmute:b,toggleMute:d,setVolume:h,setDurationPercent:x,setTime:A}]}const ri=v.createContext(null),ni=v.createContext(null),ii=v.createContext(null);function Jo(){const e=v.useContext(ri);if(!e)throw new Error("Ctx not found");return e}function Ko(){const e=v.useContext(ni);if(!e)throw new Error("Ctx not found");return e}function Zo(){const e=v.useContext(ii);if(!e)throw new Error("Ctx not found");return e}function Bt({actions:e,state:t,children:r,currentTime:n,progress:i,element:s}){return m.jsx(ii.Provider,{value:{currentTime:n,progress:i,element:s},children:m.jsx(ni.Provider,{value:e,children:m.jsx(ri.Provider,{value:t,children:r})})})}function si({media:e,children:t}){const[{element:r,currentTime:n,progress:i},s,a]=tt({duration:e.duration});return m.jsxs(Bt,{state:s,actions:a,currentTime:n,progress:i,element:r,children:[m.jsx("audio",{ref:r,src:e.url}),t]})}function ai({media:e,mediaControlsDeps:t,children:r}){return Ie("portal","audio",si,{media:e,children:r},[e,...t||[]]),null}function oi({element:e,media:t,playPause:r}){return m.jsxs("div",{className:"video-container",part:"video-container",onClick:r,children:[m.jsx("style",{children:`
|
|
66
66
|
.video-container {
|
|
67
67
|
position: absolute;
|
|
68
68
|
top: 0;
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
justify-content: center;
|
|
76
76
|
pointer-events: visible;
|
|
77
77
|
}
|
|
78
|
-
`}),m.jsx("video",{ref:e,src:t.url,style:{width:"100%",objectFit:"contain"}})]})}function ci({media:e,mediaControlsDeps:t,children:r}){const[{element:n,currentTime:i,progress:s},a,o]=tt({duration:e.duration});return Ie("overlay","video-element",oi,{element:n,media:e,playPause:o.playPause}),Ie("portal","custom-controls",
|
|
78
|
+
`}),m.jsx("video",{ref:e,src:t.url,style:{width:"100%",objectFit:"contain"}})]})}function ci({media:e,mediaControlsDeps:t,children:r}){const[{element:n,currentTime:i,progress:s},a,o]=tt({duration:e.duration});return Ie("overlay","video-element",oi,{element:n,media:e,playPause:o.playPause}),Ie("portal","custom-controls",Bt,{state:a,actions:o,currentTime:i,progress:s,element:n,children:r},[i,a,e,...t||[]]),null}function ui({model:e}){return m.jsxs(m.Fragment,{children:[m.jsx("style",{children:`
|
|
79
79
|
.model-container {
|
|
80
80
|
position: absolute;
|
|
81
81
|
top: 0;
|
|
@@ -88,9 +88,9 @@
|
|
|
88
88
|
justify-content: center;
|
|
89
89
|
pointer-events: visible;
|
|
90
90
|
}
|
|
91
|
-
`}),m.jsx("div",{className:"model-container",children:m.jsx("model-viewer",{"interaction-prompt":"none",style:{width:"100%",height:"100%"},"camera-controls":"","ar-status":"not-presenting",src:e.id})})]})}function li({model:e,name:t}){return Ie("overlay",`model-${t}`,ui,{model:e},[e]),null}function fi({style:e}){const t=re();return!t||!t.height||!t.width?null:m.jsx("box",{interactive:!1,target:{x:0,y:0,width:Number(t.width),height:Number(t.height)},style:e})}const pi=v.createContext("en");function
|
|
92
|
-
`):""},[r,t,e]),r]}function
|
|
93
|
-
`):""}}const gi=({as:e,defaultText:t,enableDangerouslySetInnerHTML:r,children:n,...i})=>{const[s,a]=yi(n,t);return a?m.jsx(di,{...i,as:e,language:a,title:r?void 0:s,dangerouslySetInnerHTML:r?{__html:s}:void 0,children:r?void 0:s}):e?m.jsx(e,{...i,children:s}):m.jsx("span",{...i,title:r?void 0:s,dangerouslySetInnerHTML:r?{__html:s}:void 0,children:r?void 0:s})};function
|
|
91
|
+
`}),m.jsx("div",{className:"model-container",children:m.jsx("model-viewer",{"interaction-prompt":"none",style:{width:"100%",height:"100%"},"camera-controls":"","ar-status":"not-presenting",src:e.id})})]})}function li({model:e,name:t}){return Ie("overlay",`model-${t}`,ui,{model:e},[e]),null}function fi({style:e}){const t=re();return!t||!t.height||!t.width?null:m.jsx("box",{interactive:!1,target:{x:0,y:0,width:Number(t.width),height:Number(t.height)},style:e})}const pi=v.createContext("en");function Xo(e){return m.jsx(pi.Provider,{value:e.language,children:e.children})}function rt(){return v.useContext(pi)}function dr(e){return e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):e}function di({as:e,language:t,children:r,viewingDirection:n,...i}){const s=rt();return v.useMemo(()=>dr(s)===dr(t),[s,t])?e?m.jsx(e,{...i,children:r}):m.jsx("span",{...i,children:r}):e?m.jsx(e,{...i,lang:t,dir:n,children:r}):m.jsx("span",{...i,lang:t,dir:n,children:r})}function hi(e,t,r){if(t.length===0)return;if(t.length===1)return t[0];if(t.indexOf(e)!==-1)return e;const n=e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):null;if(n&&t.indexOf(n)!==-1)return n;for(const i of r)if(t.indexOf(i)!==-1)return i;return t.indexOf("none")!==-1?"none":t.indexOf("@none")!==-1?"@none":t[0]}const vi=(e,t=[])=>{const r=rt();return v.useMemo(()=>{const n=e();return hi(r,n,[])},[r,...t])};function yi(e,t){const r=vi(()=>Object.keys(e||{}),[e]);return[v.useMemo(()=>{if(!e)return t||"";if(typeof e=="string")return e;const n=r?e[r]:void 0;return n?typeof n=="string"?n:n.join(`
|
|
92
|
+
`):""},[r,t,e]),r]}function ec(){const e=rt();return function(r,n,i){const s=Object.keys(r||{}),a=hi(e,s,[]);if(!r)return n||"";if(typeof r=="string")return r;const o=a?r[a]:void 0;return o?typeof o=="string"?o:o.join(typeof i<"u"?i:`
|
|
93
|
+
`):""}}const gi=({as:e,defaultText:t,enableDangerouslySetInnerHTML:r,children:n,...i})=>{const[s,a]=yi(n,t);return a?m.jsx(di,{...i,as:e,language:a,title:r?void 0:s,dangerouslySetInnerHTML:r?{__html:s}:void 0,children:r?void 0:s}):e?m.jsx(e,{...i,children:s}):m.jsx("span",{...i,title:r?void 0:s,dangerouslySetInnerHTML:r?{__html:s}:void 0,children:r?void 0:s})};function tc({element:e,media:t,playPause:r}){const n=v.useRef(null);return t.youTubeId?m.jsxs("div",{className:"video-container",part:"video-container",onClick:r,children:[m.jsx("style",{children:`
|
|
94
94
|
.video-container {
|
|
95
95
|
position: absolute;
|
|
96
96
|
top: 0;
|
|
@@ -108,5 +108,5 @@
|
|
|
108
108
|
width: 100%;
|
|
109
109
|
object-fit: contain;
|
|
110
110
|
}
|
|
111
|
-
`}),m.jsx("iframe",{className:"video-yt",ref:n,src:`https://www.youtube.com/embed/${t.youTubeId}?enablejsapi=1&origin=${window.location.host}`,referrerPolicy:"no-referrer",sandbox:"allow-scripts allow-same-origin allow-presentation"})]}):null}function
|
|
111
|
+
`}),m.jsx("iframe",{className:"video-yt",ref:n,src:`https://www.youtube.com/embed/${t.youTubeId}?enablejsapi=1&origin=${window.location.host}`,referrerPolicy:"no-referrer",sandbox:"allow-scripts allow-same-origin allow-presentation"})]}):null}function rc({media:e,mediaControlsDeps:t,children:r}){const[{element:n,currentTime:i,progress:s},a,o]=tt({duration:e.duration});return Ie("overlay","video-element",tc,{element:n,media:e,playPause:o.playPause}),null}function mi({x:e,y:t,onChoiceChange:r,registerActions:n,defaultChoices:i,isStatic:s,renderViewerControls:a,renderMediaControls:o,viewControlsDeps:u,mediaControlsDeps:f,strategies:l,throwOnUnknown:d,backgroundStyle:g,alwaysShowBackground:b,keepCanvasScale:h=!1,enableSizes:x=!1,enableYouTube:A=!0,onClickPaintingAnnotation:S,children:w}){const M=re(),T=$t(M,["deep-zoom"]),[F]=Kr(),k=Xr(),O=V(),E=v.useMemo(()=>Dt(O),[O]),[R,$]=Kn({strategies:l||["images"],defaultChoices:i==null?void 0:i.map(({id:P})=>P)}),X=R.type==="images"?R.choice:void 0,Y=v.useMemo(()=>h?1:Math.max(1,...R.type==="images"?R.images.map(P=>{var N;return(P.width||0)/((N=P.target)==null?void 0:N.spatial.width)}):[]),[h,R]);Js(Y),v.useEffect(()=>{n&&n($)},[R.annotations]),v.useEffect(()=>{if(i)for(const P of i)typeof P.opacity<"u"&&E.applyStyles({id:P.id},"atlas",{opacity:P.opacity})},[i]),v.useLayoutEffect(()=>{r&&r(X)},[X]),Ie(k&&(R.type==="images"||R.type==="empty"||R.type==="textual-content"&&a)?"overlay":"none",`canvas-portal-controls-${M==null?void 0:M.id}`,Ze.Provider,a?{value:k||null,children:a(R)}:{},[M,k,R,...u||[]]);const _=ei({maxWidth:256,maxHeight:256});if(!M)return null;const H=M.accompanyingCanvas,J=_&&_.type==="fixed"?m.jsx("world-object",{height:M.height,width:M.width,x:e,y:t,children:m.jsx("world-image",{uri:_.id,target:{x:0,y:0,width:M.width,height:M.height},display:_.width&&_.height?{width:_.width,height:_.height}:void 0,crop:void 0})}):null;if(R.type==="unknown"){if(J)return J;if(d)throw new Error(R.reason||"Unknown image strategy");return null}const ee=m.jsxs(v.Fragment,{children:[F?m.jsx(Mt,{page:F}):null,R.annotations&&R.annotations.pages?R.annotations.pages.map(P=>m.jsx(Mt,{page:P},P.id)):null,w]}),ge=R.type==="images"?R.images.length:0;return m.jsxs(m.Fragment,{children:[m.jsxs("world-object",{height:M.height,width:M.width,x:e,y:t,...T,children:[R.type==="empty"||b?m.jsx(fi,{style:g}):null,R.type==="textual-content"?R.items.map((P,N)=>{var G;return m.jsxs(m.Fragment,{children:[m.jsx(Re.HTMLPortal,{onClick:S?ue=>{ue.stopPropagation(),S(P.annotationId,P,ue)}:void 0,target:((G=P.target)==null?void 0:G.spatial)||void 0,children:m.jsx("div",{"data-textual-content":!0,children:m.jsx(gi,{enableDangerouslySetInnerHTML:!0,children:P.text})})},N),ee]})}):null,R.type==="images"?m.jsxs(m.Fragment,{children:[R.images.map((P,N)=>m.jsx(hn,{isStatic:s,image:P,id:P.id,thumbnail:N===0?_:void 0,selector:P.selector,enableSizes:x,onClick:S?G=>{G.stopPropagation(),S(P.annotationId,P,G)}:void 0},P.id+N)),ee]}):null,R.type==="3d-model"?m.jsx(li,{model:R.model}):null,R.type==="media"?m.jsx(m.Fragment,{children:R.media.type==="Sound"?m.jsxs(ai,{media:R.media,mediaControlsDeps:f,children:[J,o?o(R):null]}):R.media.type==="Video"?m.jsxs(ci,{media:R.media,mediaControlsDeps:f,children:[J,o?o(R):null]}):R.media.type==="VideoYouTube"&&A?m.jsxs(rc,{media:R.media,mediaControlsDeps:f,children:[J,o?o(R):null]}):null}):null]},`${M.id}/${R.type}/${ge}`),R.type==="media"&&R.media.type==="Sound"&&H?m.jsx(Ke,{canvas:H.id,children:m.jsx(mi,{renderViewerControls:a})}):null]})}function xi(){const e=v.useContext($e);return e&&e.vault?e.vault:$r()}const nc=v.forwardRef(function(t,r){const n=ve(),i=Et(),s=zr(),{ViewerControls:a,MediaControls:o}=t.components||{};if(v.useImperativeHandle(r,()=>s,[s]),!n)return m.jsx("div",{});let u=0;return m.jsxs(m.Fragment,{children:[t.header,m.jsx(Q.Viewer,{height:t.height,mode:t.mode,children:i.map((f,l)=>{const d=u;return u+=f.width+(t.spacing||0),m.jsx(Ke,{canvas:f.id,children:m.jsx(Q.RenderCanvas,{strategies:["3d-model","media","images","empty","textual-content"],renderViewerControls:l===0&&a?()=>m.jsx(a,{}):void 0,renderMediaControls:l===0&&o?()=>m.jsx(o,{}):void 0,x:d,...t.canvasProps||{},children:t.annotations},f.id)},f.id)})},t.reuseAtlas?"":s.currentSequenceIndex),t.children]})}),Q=v.forwardRef(function({children:t,height:r,annotations:n,canvasProps:i,spacing:s,header:a,components:o,mode:u,...f},l){const d=xi();return m.jsx(jt,{vault:d,children:m.jsx(Br,{...f,children:m.jsx(nc,{ref:l,height:r,components:o,spacing:s,canvasProps:i,annotations:n,header:a,mode:u,children:t})})})});Q.RenderImage=hn;Q.RenderCanvas=mi;Q.RenderAnnotationPage=Mt;Q.RenderAnnotation=pn;Q.Viewer=Ks;Q.CanvasBackground=fi;Q.Audio=ai;Q.Video=ci;Q.Model=li;Q.AudioHTML=si;Q.VideoHTML=oi;Q.ModelHTML=ui;function ic({annotation:e,children:t}){return m.jsx(he,{value:{annotation:e},children:t})}function sc({annotationPage:e,children:t}){return m.jsx(he,{value:{annotationPage:e},children:t})}function ac({collection:e,children:t}){return m.jsx(he,{value:{collection:e},children:t})}function oc(e,t={}){return et(t)}function cc(e,t=!1){}function uc(e){const r=se().manifest,n=e?e.map(i=>typeof i=="string"?i:i==null?void 0:i.id):[];return U(i=>{const s=r?i.iiif.entities.Manifest[r]:void 0,a=(s==null?void 0:s.items)||[];if(typeof e>"u")return a;const o=[];for(const u of(s==null?void 0:s.items)||[])n.indexOf(u.id)!==-1&&o.push(u);return o},[n.join("/")])}function lc(e,t=[]){const{id:r,selector:n}=e,i=se(),s=r||i.collection,a=U(o=>s?o.iiif.entities.Collection[s]:void 0,[s]);return v.useMemo(()=>{if(a)return n?n(a):a},[a,n,...t])}function fc(e,t,r,n,i=[]){const s=V(),a=v.useMemo(()=>sn(s),[s]);v.useEffect(()=>{const o=e;return o?(a.addEventListener(o,t,r,n),()=>{a.removeEventListener(o,t,r)}):()=>{}},[a,e,t,...i])}function pc(e,t){const{id:r,isLoaded:n,error:i,resource:s,requestId:a,cached:o}=Pt(e,t);return{id:r,isLoaded:n,error:i,manifest:s,requestId:a,cached:o}}function bi({cacheKey:e}={}){const t=re(),r=et(),n=V(),i=Xe(),[s,a]=v.useState(void 0),[o,u]=v.useState(!1),[f,l]=v.useState("idle"),[d,g]=v.useState(void 0),b=t?t.id:"undefined",h=v.useMemo(()=>{try{if(t&&r.length){const A=r[0],S=n.get(A.body[0]),M=Se.getImageServices(S)[0];return M&&i.loadServiceSync({id:M.id||M["@id"],width:M.width||t.width,height:M.height||t.height})||void 0}}catch(A){console.error(A)}},[b,e,t]),x=f==="success"&&s?s:h;return v.useEffect(()=>{(async()=>{try{if(t&&r.length){const A=r[0],S=n.get(A.body[0]),M=Se.getImageServices(S)[0];if(!M)return;u(!0),l("loading");try{const T=await i.loadService({id:M.id||M["@id"],width:M.width||t.width,height:M.height||t.height})||void 0;a(T),l("success"),u(!1)}catch(T){l("error"),g(T)}}}catch(A){l("error"),g(A)}})()},[b,e]),v.useMemo(()=>({data:x,isFetching:o,status:f,error:d}),[x,o,f,d])}function dc(){const e=bi();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 hc(){const e=ve();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function vc(){const e=V();return v.useMemo(()=>Dt(e),[e])}exports.AnnotationContext=ic;exports.AnnotationPageContext=sc;exports.CanvasContext=Ke;exports.CanvasPanel=Q;exports.CollectionContext=ac;exports.ContextBridge=Qr;exports.ImageServiceLoaderContext=zn;exports.InnerViewerProvider=Nr;exports.LanguageProvider=Xo;exports.LanguageString=di;exports.LocaleString=gi;exports.ManifestContext=qr;exports.MediaPlayerProvider=Bt;exports.RangeContext=Vr;exports.ReactVaultContext=$e;exports.ResourceProvider=he;exports.ResourceReactContext=Je;exports.SimpleViewerProvider=Br;exports.SimpleViewerReactContext=qe;exports.VaultProvider=jt;exports.ViewerPresetContext=Ze;exports.VirtualAnnotationProvider=Zr;exports.VisibleCanvasReactContext=De;exports.emptyActions=_n;exports.emptyStrategy=Un;exports.expandTarget=de;exports.findAllCanvasesInRange=Ot;exports.findFirstCanvasFromRange=_r;exports.findManifestSelectedRange=Is;exports.findSelectedRange=Lt;exports.flattenAnnotationPageIds=Hn;exports.formatTime=ti;exports.getImageStrategy=Gn;exports.getManifestSequence=Ft;exports.getParsedTargetSelector=Nt;exports.getVisibleCanvasesFromCanvasId=ks;exports.isImageApiSelector=ln;exports.parseRotation=fn;exports.parseSelector=Ee;exports.parseSpecificResource=Lo;exports.unknownResponse=Ge;exports.unsupportedStrategy=D;exports.useAnnotation=Vt;exports.useAnnotationPage=dn;exports.useAnnotationPageManager=Nn;exports.useAnnotationsAtTime=oc;exports.useCanvas=re;exports.useCanvasClock=cc;exports.useCanvasSequence=Hr;exports.useCanvasSubset=uc;exports.useClosestLanguage=vi;exports.useCollection=lc;exports.useContextBridge=Wr;exports.useCreateLocaleString=ec;exports.useDispatch=Yr;exports.useEventListener=fc;exports.useExistingVault=xi;exports.useExternalCollection=pc;exports.useExternalManifest=Dr;exports.useExternalResource=Pt;exports.useIIIFLanguage=rt;exports.useImageService=bi;exports.useImageServiceLoader=Xe;exports.useImageTile=dc;exports.useLoadImageService=Wn;exports.useLocaleString=yi;exports.useManifest=ve;exports.useMediaActions=Ko;exports.useMediaElements=Zo;exports.useMediaState=Jo;exports.usePaintables=Yn;exports.usePaintingAnnotations=et;exports.useRange=Ur;exports.useRenderingStrategy=Kn;exports.useResourceContext=se;exports.useResourceEvents=$t;exports.useResources=Bn;exports.useSearchService=hc;exports.useSimpleMediaPlayer=tt;exports.useSimpleViewer=zr;exports.useStyleHelper=vc;exports.useStyles=Fe;exports.useThumbnail=ei;exports.useVault=V;exports.useVaultEffect=Zn;exports.useVaultSelector=U;exports.useViewerPreset=Xr;exports.useVirtualAnnotationPage=Gr;exports.useVirtualAnnotationPageContext=Kr;exports.useVisibleCanvases=Et;
|
|
112
112
|
//# sourceMappingURL=index.js.map
|