react-iiif-vault 1.0.1 → 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.
@@ -1,8 +1,8 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),v=require("react"),we=require("@atlas-viewer/atlas"),B=require("@iiif/parser"),Ee=require("@atlas-viewer/iiif-image-api");function Fi(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const i=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,i.get?i:{enumerable:!0,get:()=>t[r]})}}return e.default=t,Object.freeze(e)}const Ze=Fi(v);function ut(t,e){return ut=Object.setPrototypeOf||function(i,n){return i.__proto__=n,i},ut(t,e)}function $i(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,ut(t,e)}var Di=function(e,r){return e===void 0&&(e=[]),r===void 0&&(r=[]),e.length!==r.length||e.some(function(i,n){return!Object.is(i,r[n])})},Lt={error:null},qi=function(t){$i(e,t);function e(){for(var i,n=arguments.length,s=new Array(n),a=0;a<n;a++)s[a]=arguments[a];return i=t.call.apply(t,[this].concat(s))||this,i.state=Lt,i.resetErrorBoundary=function(){for(var o,u=arguments.length,h=new Array(u),l=0;l<u;l++)h[l]=arguments[l];i.props.onReset==null||(o=i.props).onReset.apply(o,h),i.reset()},i}e.getDerivedStateFromError=function(n){return{error:n}};var r=e.prototype;return r.reset=function(){this.setState(Lt)},r.componentDidCatch=function(n,s){var a,o;(a=(o=this.props).onError)==null||a.call(o,n,s)},r.componentDidUpdate=function(n,s){var a=this.state.error,o=this.props.resetKeys;if(a!==null&&s.error!==null&&Di(n.resetKeys,o)){var u,h;(u=(h=this.props).onResetKeysChange)==null||u.call(h,n.resetKeys,o),this.reset()}},r.render=function(){var n=this.state.error,s=this.props,a=s.fallbackRender,o=s.FallbackComponent,u=s.fallback;if(n!==null){var h={error:n,resetErrorBoundary:this.resetErrorBoundary};if(Ze.isValidElement(u))return u;if(typeof a=="function")return a(h);if(o)return Ze.createElement(o,h);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},e}(Ze.Component);const _i={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},At=v.createContext(_i),Me=()=>v.useContext(At);function ze({value:t,children:e}){const r=Me(),i=v.useMemo(()=>({...r,...t}),[t,r]);return m.jsx(At.Provider,{value:i,children:e})}var Ui=Object.defineProperty,Vi=(t,e,r)=>e in t?Ui(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,le=(t,e,r)=>(Vi(t,typeof e!="symbol"?e+"":e,r),r);const D=function(t){return function(){const e={type:t,getType:()=>t,toString:()=>t};return(r,i)=>({...e,...r!==void 0&&{payload:r},...i!==void 0&&{meta:i}})}},Xt="@iiif/IMPORT_ENTITIES",er="@iiif/MODIFY_ENTITY_FIELD",tr="@iiif/REORDER_ENTITY_FIELD",rr="@iiif/ADD_REFERENCE",lt="@iiif/UPDATE_REFERENCE",ir="@iiif/REMOVE_REFERENCE",nr="@iiif/ADD_METADATA",sr="@iiif/REMOVE_METADATA",ft="@iiif/UPDATE_METADATA",ar="@iiif/REORDER_METADATA",or=D(Xt)(),Hi=D(er)(),Ni=D(tr)(),Bi=D(rr)(),zi=D(ir)(),Wi=D(lt)(),Qi=D(nr)(),Yi=D(ft)(),Gi=D(sr)(),Ji=D(ar)(),Ki={importEntities:or,modifyEntityField:Hi,reorderEntityField:Ni,addReference:Bi,removeReference:zi,updateReference:Wi,addMetadata:Qi,removeMetadata:Gi,updateMetadata:Yi,reorderMetadata:Ji},cr="@iiif/ADD_MAPPING",ur="@iiif/ADD_MAPPINGS",Zi=D(cr)(),Xi=D(ur)(),lr="@iiif/SET_META_VALUE",fr="@iiif/SET_META_VALUE_DYNAMIC",pr="@iiif/UNSET_META_VALUE",en=D(lr)(),tn=D(fr)(),rn=D(pr)(),Ft={setMetaValue:en,setMetaValueDynamic:tn,unsetMetaValue:rn},pt="RESOURCE_ERROR",hr="RESOURCE_LOADING",ht="RESOURCE_READY",dr="@iiif/REQUEST_RESOURCE",yr="@iiif/REQUEST_ERROR",vr="@iiif/REQUEST_MISMATCH",gr="@iiif/REQUEST_COMPLETE",nn="@iiif/REQUEST_OFFLINE_RESOURCE",sn=D(dr)(),mr=D(yr)(),an=D(vr)(),on=D(gr)(),wt="@iiif/BATCH",cn="@iiif/BATCH_IMPORT",dt=D(wt)(),un=(t,e)=>{const{entities:r,resource:i,mapping:n}=B.normalize(e);if(i.id===void 0)return[mr({id:t,message:"ID is not defined in resource."})];const s=[or({entities:r}),Xi({mapping:n})];return i.id!==t&&(s.push(Zi({id:t,type:i.type})),s.push(an({requestId:t,actualId:i.id}))),s.push(on({id:t})),s},$t=Number.isNaN||function(t){return typeof t=="number"&&t!==t};function ln(t,e){return!!(t===e||$t(t)&&$t(e))}function Dt(t,e){if(!Array.isArray(t)||!Array.isArray(e))return t===e;if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(!ln(t[r],e[r]))return!1;return!0}function Xe(t,e,r){const i=t.iiif.requests[e],n=t.iiif.mapping[e];if(!n||!t.iiif.entities[n][i.resourceUri])return;const s=t.iiif.entities[n][i.resourceUri];if(s&&s[B.HAS_PART]){const a=s[B.HAS_PART].find(o=>r?o[B.PART_OF]===r.id:o[B.PART_OF]===s.id);return B.frameResource(s,a)}return s}function qt(t,e,{waitTimeout:r=30}={}){return async(i,n)=>{const s=t.getStore(),a=s.getState(),o=a.iiif.requests[i];if(o)switch(o.loadingState){case pt:break;case hr:{let u,h=!1;try{const l=await Promise.race([new Promise((p,g)=>{h||(u=s.subscribe(()=>{const b=s.getState();if(b.iiif.requests[i].loadingState===pt){g();return}if(b.iiif.requests[i].loadingState===ht){const d=Xe(b,i);d?p(d):g()}}))}),new Promise((p,g)=>setTimeout(()=>{h=!0,g()},r*60*1e3))]);if(u&&u(),l)return l}catch{u&&u();break}break}case ht:{const u=Xe(a,i);if(u)return u;break}}t.dispatch(sn({id:i}));try{const u=await e(i,n);!u.id&&!u["@id"]&&(u["@type"]&&(u["@id"]=i),u.id=i);const h=un(i,u);return t.dispatch(dt({actions:h})),Xe(s.getState(),i)}catch(u){throw t.dispatch(mr({id:i,message:u.toString()})),u}}}function xr(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}const _t=t=>{let e;const r=new Set,i=(a,o)=>{const u=typeof a=="function"?a(e):a;if(!Object.is(u,e)){const h=e;e=o??typeof u!="object"?u:Object.assign({},e,u),r.forEach(l=>l(e,h))}},n=()=>e,s={setState:i,getState:n,subscribe:a=>(r.add(a),()=>r.delete(a)),destroy:()=>{r.clear()}};return e=t(i,n,s),s},fn=t=>t?_t(t):_t,pn=(t,e)=>(r,i,n)=>(n.dispatch=s=>(r(a=>t(a,s),!1,s),s),n.dispatchFromDevtools=!0,{dispatch:(...s)=>n.dispatch(...s),...e}),hn=pn,yt=new Map,Fe=t=>{const e=yt.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([r,i])=>[r,i.getState()])):{}},dn=(t,e,r)=>{if(t===void 0)return{type:"untracked",connection:e.connect(r)};const i=yt.get(r.name);if(i)return{type:"tracked",store:t,...i};const n={connection:e.connect(r),stores:{}};return yt.set(r.name,n),{type:"tracked",store:t,...n}},yn=(t,e={})=>(r,i,n)=>{const{enabled:s,anonymousActionType:a,store:o,...u}=e;let h;try{h=(s??!1)&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!h)return t(r,i,n);const{connection:l,...p}=dn(o,h,u);let g=!0;n.setState=(x,w,A)=>{const S=r(x,w);if(!g)return S;const k=A===void 0?{type:a||"anonymous"}:typeof A=="string"?{type:A}:A;return o===void 0?(l==null||l.send(k,i()),S):(l==null||l.send({...k,type:`${o}/${k.type}`},{...Fe(u.name),[o]:n.getState()}),S)};const b=(...x)=>{const w=g;g=!1,r(...x),g=w},d=t(n.setState,i,n);if(p.type==="untracked"?l==null||l.init(d):(p.stores[p.store]=n,l==null||l.init(Object.fromEntries(Object.entries(p.stores).map(([x,w])=>[x,x===p.store?d:w.getState()])))),n.dispatchFromDevtools&&typeof n.dispatch=="function"){const x=n.dispatch;n.dispatch=(...w)=>{x(...w)}}return l.subscribe(x=>{var w;switch(x.type){case"ACTION":if(typeof x.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return et(x.payload,A=>{if(A.type==="__setState"){if(o===void 0){b(A.state);return}Object.keys(A.state).length!==1&&console.error(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),v=require("react"),we=require("@atlas-viewer/atlas"),B=require("@iiif/parser"),Ee=require("@atlas-viewer/iiif-image-api");function Fi(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const i=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,i.get?i:{enumerable:!0,get:()=>t[r]})}}return e.default=t,Object.freeze(e)}const Ze=Fi(v);function ut(t,e){return ut=Object.setPrototypeOf||function(i,n){return i.__proto__=n,i},ut(t,e)}function $i(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,ut(t,e)}var Di=function(e,r){return e===void 0&&(e=[]),r===void 0&&(r=[]),e.length!==r.length||e.some(function(i,n){return!Object.is(i,r[n])})},Ft={error:null},qi=function(t){$i(e,t);function e(){for(var i,n=arguments.length,s=new Array(n),a=0;a<n;a++)s[a]=arguments[a];return i=t.call.apply(t,[this].concat(s))||this,i.state=Ft,i.resetErrorBoundary=function(){for(var o,u=arguments.length,p=new Array(u),l=0;l<u;l++)p[l]=arguments[l];i.props.onReset==null||(o=i.props).onReset.apply(o,p),i.reset()},i}e.getDerivedStateFromError=function(n){return{error:n}};var r=e.prototype;return r.reset=function(){this.setState(Ft)},r.componentDidCatch=function(n,s){var a,o;(a=(o=this.props).onError)==null||a.call(o,n,s)},r.componentDidUpdate=function(n,s){var a=this.state.error,o=this.props.resetKeys;if(a!==null&&s.error!==null&&Di(n.resetKeys,o)){var u,p;(u=(p=this.props).onResetKeysChange)==null||u.call(p,n.resetKeys,o),this.reset()}},r.render=function(){var n=this.state.error,s=this.props,a=s.fallbackRender,o=s.FallbackComponent,u=s.fallback;if(n!==null){var p={error:n,resetErrorBoundary:this.resetErrorBoundary};if(Ze.isValidElement(u))return u;if(typeof a=="function")return a(p);if(o)return Ze.createElement(o,p);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},e}(Ze.Component);const _i={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},wt=v.createContext(_i),Me=()=>v.useContext(wt);function ze({value:t,children:e}){const r=Me(),i=v.useMemo(()=>({...r,...t}),[t,r]);return m.jsx(wt.Provider,{value:i,children:e})}var Ui=Object.defineProperty,Vi=(t,e,r)=>e in t?Ui(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,le=(t,e,r)=>(Vi(t,typeof e!="symbol"?e+"":e,r),r);const D=function(t){return function(){const e={type:t,getType:()=>t,toString:()=>t};return(r,i)=>({...e,...r!==void 0&&{payload:r},...i!==void 0&&{meta:i}})}},er="@iiif/IMPORT_ENTITIES",tr="@iiif/MODIFY_ENTITY_FIELD",rr="@iiif/REORDER_ENTITY_FIELD",ir="@iiif/ADD_REFERENCE",lt="@iiif/UPDATE_REFERENCE",nr="@iiif/REMOVE_REFERENCE",sr="@iiif/ADD_METADATA",ar="@iiif/REMOVE_METADATA",ft="@iiif/UPDATE_METADATA",or="@iiif/REORDER_METADATA",cr=D(er)(),Hi=D(tr)(),Ni=D(rr)(),Bi=D(ir)(),zi=D(nr)(),Wi=D(lt)(),Qi=D(sr)(),Yi=D(ft)(),Gi=D(ar)(),Ji=D(or)(),Ki={importEntities:cr,modifyEntityField:Hi,reorderEntityField:Ni,addReference:Bi,removeReference:zi,updateReference:Wi,addMetadata:Qi,removeMetadata:Gi,updateMetadata:Yi,reorderMetadata:Ji},ur="@iiif/ADD_MAPPING",lr="@iiif/ADD_MAPPINGS",Zi=D(ur)(),Xi=D(lr)(),fr="@iiif/SET_META_VALUE",pr="@iiif/SET_META_VALUE_DYNAMIC",hr="@iiif/UNSET_META_VALUE",en=D(fr)(),tn=D(pr)(),rn=D(hr)(),$t={setMetaValue:en,setMetaValueDynamic:tn,unsetMetaValue:rn},pt="RESOURCE_ERROR",dr="RESOURCE_LOADING",ht="RESOURCE_READY",yr="@iiif/REQUEST_RESOURCE",vr="@iiif/REQUEST_ERROR",gr="@iiif/REQUEST_MISMATCH",mr="@iiif/REQUEST_COMPLETE",nn="@iiif/REQUEST_OFFLINE_RESOURCE",sn=D(yr)(),dt=D(vr)(),an=D(gr)(),on=D(mr)(),St="@iiif/BATCH",cn="@iiif/BATCH_IMPORT",yt=D(St)(),un=(t,e)=>{const{entities:r,resource:i,mapping:n}=B.normalize(e);if(i.id===void 0)return[dt({id:t,message:"ID is not defined in resource."})];const s=[cr({entities:r}),Xi({mapping:n})];return i.id!==t&&(s.push(Zi({id:t,type:i.type})),s.push(an({requestId:t,actualId:i.id}))),s.push(on({id:t})),s},Dt=Number.isNaN||function(t){return typeof t=="number"&&t!==t};function ln(t,e){return!!(t===e||Dt(t)&&Dt(e))}function qt(t,e){if(!Array.isArray(t)||!Array.isArray(e))return t===e;if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(!ln(t[r],e[r]))return!1;return!0}function Xe(t,e,r){const i=t.iiif.requests[e],n=t.iiif.mapping[e];if(!n||!t.iiif.entities[n][i.resourceUri])return;const s=t.iiif.entities[n][i.resourceUri];if(s&&s[B.HAS_PART]){const a=s[B.HAS_PART].find(o=>r?o[B.PART_OF]===r.id:o[B.PART_OF]===s.id);return B.frameResource(s,a)}return s}function fn(t){return t&&typeof t.then=="function"}function _t(t,e,{waitTimeout:r=30}={}){return(i,n)=>{const s=t.getStore(),a=s.getState(),o=a.iiif.requests[i];if(o){if(o.loadingState===ht){const p=Xe(a,i);if(p)return p}switch(o.loadingState){case pt:break;case dr:return(async()=>{let p,l=!1;try{const h=await Promise.race([new Promise((g,b)=>{l||(p=s.subscribe(()=>{const d=s.getState();if(d.iiif.requests[i].loadingState===pt){b();return}if(d.iiif.requests[i].loadingState===ht){const x=Xe(d,i);x?g(x):b()}}))}),new Promise((g,b)=>setTimeout(()=>{l=!0,b()},r*60*1e3))]);if(p&&p(),h)return h}catch{p&&p()}})()}}t.dispatch(sn({id:i}));const u=p=>{if(!p)return;!p.id&&!p["@id"]&&(p["@type"]&&(p["@id"]=i),p.id=i);const l=un(i,p);return t.dispatch(yt({actions:l})),Xe(s.getState(),i)};try{const p=e(i,n);return fn(p)?(async()=>{try{return u(await p)}catch(l){throw t.dispatch(dt({id:i,message:l.toString()})),l}})():u(p)}catch(p){throw t.dispatch(dt({id:i,message:p.toString()})),p}}}function xr(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}const Ut=t=>{let e;const r=new Set,i=(a,o)=>{const u=typeof a=="function"?a(e):a;if(!Object.is(u,e)){const p=e;e=o??typeof u!="object"?u:Object.assign({},e,u),r.forEach(l=>l(e,p))}},n=()=>e,s={setState:i,getState:n,subscribe:a=>(r.add(a),()=>r.delete(a)),destroy:()=>{r.clear()}};return e=t(i,n,s),s},pn=t=>t?Ut(t):Ut,hn=(t,e)=>(r,i,n)=>(n.dispatch=s=>(r(a=>t(a,s),!1,s),s),n.dispatchFromDevtools=!0,{dispatch:(...s)=>n.dispatch(...s),...e}),dn=hn,vt=new Map,Fe=t=>{const e=vt.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([r,i])=>[r,i.getState()])):{}},yn=(t,e,r)=>{if(t===void 0)return{type:"untracked",connection:e.connect(r)};const i=vt.get(r.name);if(i)return{type:"tracked",store:t,...i};const n={connection:e.connect(r),stores:{}};return vt.set(r.name,n),{type:"tracked",store:t,...n}},vn=(t,e={})=>(r,i,n)=>{const{enabled:s,anonymousActionType:a,store:o,...u}=e;let p;try{p=(s??!1)&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!p)return t(r,i,n);const{connection:l,...h}=yn(o,p,u);let g=!0;n.setState=(x,w,A)=>{const S=r(x,w);if(!g)return S;const k=A===void 0?{type:a||"anonymous"}:typeof A=="string"?{type:A}:A;return o===void 0?(l==null||l.send(k,i()),S):(l==null||l.send({...k,type:`${o}/${k.type}`},{...Fe(u.name),[o]:n.getState()}),S)};const b=(...x)=>{const w=g;g=!1,r(...x),g=w},d=t(n.setState,i,n);if(h.type==="untracked"?l==null||l.init(d):(h.stores[h.store]=n,l==null||l.init(Object.fromEntries(Object.entries(h.stores).map(([x,w])=>[x,x===h.store?d:w.getState()])))),n.dispatchFromDevtools&&typeof n.dispatch=="function"){const x=n.dispatch;n.dispatch=(...w)=>{x(...w)}}return l.subscribe(x=>{var w;switch(x.type){case"ACTION":if(typeof x.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return et(x.payload,A=>{if(A.type==="__setState"){if(o===void 0){b(A.state);return}Object.keys(A.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 S=A.state[o];if(S==null)return;JSON.stringify(n.getState())!==JSON.stringify(S)&&b(S);return}n.dispatchFromDevtools&&typeof n.dispatch=="function"&&n.dispatch(A)});case"DISPATCH":switch(x.payload.type){case"RESET":return b(d),o===void 0?l==null?void 0:l.init(n.getState()):l==null?void 0:l.init(Fe(u.name));case"COMMIT":if(o===void 0){l==null||l.init(n.getState());return}return l==null?void 0:l.init(Fe(u.name));case"ROLLBACK":return et(x.state,A=>{if(o===void 0){b(A),l==null||l.init(n.getState());return}b(A[o]),l==null||l.init(Fe(u.name))});case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return et(x.state,A=>{if(o===void 0){b(A);return}JSON.stringify(n.getState())!==JSON.stringify(A[o])&&b(A[o])});case"IMPORT_STATE":{const{nextLiftedState:A}=x.payload,S=(w=A.computedStates.slice(-1)[0])==null?void 0:w.state;if(!S)return;b(o===void 0?S:S[o]),l==null||l.send(null,A);return}case"PAUSE_RECORDING":return g=!g}return}}),d},vn=yn,et=(t,e)=>{let r;try{r=JSON.parse(t)}catch(i){console.error("[zustand devtools middleware] Could not parse the received json",i)}r!==void 0&&e(r)},gn=t=>(e,r,i)=>{const n=i.subscribe;return i.subscribe=(s,a,o)=>{let u=s;if(a){const h=(o==null?void 0:o.equalityFn)||Object.is;let l=s(i.getState());u=p=>{const g=s(p);if(!h(l,g)){const b=l;a(l=g,b)}},o!=null&&o.fireImmediately&&a(l,l)}return n(u)},t(e,r,i)},mn=gn,xn=(t={},e)=>{switch(e.type){case cr:return{...t,[e.payload.id]:e.payload.type};case ur:return{...t,...e.payload.mapping};default:return t}};function tt(t,e,r,i){return!(!t[r]||!t[r][e]||!t[r][e][i]||!Array.isArray(t[r][e][i]))}function bn(t,e){const r={},i=[];for(const[n,s]of Object.entries(t||{})){i.push(n);const a=(e||{})[n];if(!a||a.length===0){r[n]=s;continue}r[n]=a}for(const[n,s]of Object.entries(e||{}))i.indexOf(n)===-1&&(r[n]=s);return r}function R(t){return t.payload}function rt(t,e){return typeof t>"u"?e:t}const An=(t=xr(),e)=>{var r;const i=(n,s)=>({...t,[R(e).type]:{...t[R(e).type],[R(e).id]:{...n,...s}}});switch(e.type){case er:{if(!t[R(e).type]||!t[R(e).type][R(e).id])return t;const n=t[R(e).type][R(e).id];return typeof n=="string"?t:i(n,{[R(e).key]:R(e).value})}case tr:{if(!tt(t,R(e).id,R(e).type,R(e).key))return t;const n=t[R(e).type][R(e).id];if(typeof n=="string")return t;const s=Array.from(n[R(e).key]),[a]=s.splice(R(e).startIndex,1);return s.splice(R(e).endIndex,0,a),i(n,{[R(e).key]:s})}case Xt:{const n=Object.keys(R(e).entities),s={...t};for(const a of n){const o=R(e).entities[a],u={...t[a]||{}};let h=!1;const l=Object.keys(o||{})||[];if(o&&l){for(const p of l)h=!0,u[p]=t[a][p]?bn(t[a][p],o[p]):o[p];h&&(s[a]=u)}}return s}case rr:{if(!tt(t,R(e).id,R(e).type,R(e).key))return t;const n=t[R(e).type][R(e).id],s=Array.from(n[R(e).key]);return s.splice(rt(R(e).index,s.length+1),0,R(e).reference),i(n,{[R(e).key]:s})}case lt:case ir:{if(!tt(t,R(e).id,R(e).type,R(e).key))return t;const n=t[R(e).type][R(e).id],s=Array.from(n[R(e).key]),a=rt(R(e).index,s.findIndex(o=>o&&o.id===R(e).reference.id));return a===-1||((r=s[a])==null?void 0:r.id)!==R(e).reference.id?t:(e.type===lt?s.splice(a,1,R(e).reference):s.splice(a,1),i(n,{[R(e).key]:s}))}case nr:{const n=t[R(e).type][R(e).id];if(!n)return t;const s=Array.from(n.metadata||[]),a=R(e);return s.splice(rt(e.payload.beforeIndex,s.length+1),0,{label:a.label,value:a.label}),i(n,{metadata:s})}case ar:{const n=t[R(e).type][R(e).id];if(typeof n=="string"||!n)return t;const s=Array.from(n.metadata||[]),[a]=s.splice(R(e).startIndex,1);return s.splice(R(e).endIndex,0,a),i(n,{metadata:s})}case ft:case sr:{const n=t[R(e).type][R(e).id],s=Array.from(n.metadata||[]),a=R(e).atIndex;return typeof a>"u"||a===-1||!s[a]?t:(e.type===ft?s.splice(a,1,{label:R(e).label,value:R(e).value}):s.splice(a,1),i(n,{metadata:s}))}default:return t}},wn=(t={},e)=>{switch(e.type){case dr:case nn:return{...t,[e.payload.id]:{requestUri:e.payload.id,loadingState:hr,uriMismatch:!1,resourceUri:e.payload.id}};case vr:return{...t,[e.payload.requestId]:{...t[e.payload.requestId]||{},uriMismatch:!0,resourceUri:e.payload.actualId},[e.payload.actualId]:{requestUri:e.payload.requestId,loadingState:t[e.payload.requestId].loadingState,uriMismatch:!0,resourceUri:e.payload.actualId}};case yr:return{...t,[e.payload.id]:{...t[e.payload.id]||{},loadingState:pt,error:e.payload.message}};case gr:return{...t,[e.payload.id]:{...t[e.payload.id]||{},loadingState:ht,error:void 0}}}return t},Sn=(t={},e)=>{const{id:r,updateValue:i,value:n,meta:s,key:a}=e&&e.payload||{};switch(e.type){case lr:return{...t,[r]:{...t[r]||{},[s]:{...t[r]?t[r][s]||{}:{},[a]:n}}};case fr:return{...t,[r]:{...t[r]||{},[s]:{...t[r]?t[r][s]||{}:{},[a]:t[r]&&t[r][s]?i(t[r][s][a]):i(void 0)}}};case pr:return t[r]&&t[r][s]&&t[r][s][a]?{...t,[r]:{...t[r]||{},[s]:{...t[r]?t[r][s]||{}:{},[a]:void 0}}}:t;default:return t}};function br(t={}){const e=Object.keys(t);return function(r={},i){let n=!1;const s={};for(let a=0;a<e.length;a++){const o=e[a];s[o]=t[o](r[o],i),n=n||s[o]!==r[o]}return n?s:r}}function Mn(t){return(e,r)=>r&&r.type===wt?r.payload.actions.reduce(t,e):r&&r.type===cn?{...e,iiif:{...e.iiif,...r.payload.state}}:t(e,r)}const Cn=br({mapping:xn,entities:An,requests:wn,meta:Sn});function Rn(){return{iiif:{entities:xr(),meta:{},mapping:{},requests:{}}}}function kn(t={}){const{enableDevtools:e=!1,iiifStoreName:r="iiif",defaultState:i=Rn(),customReducers:n={}}=t,s=Mn(br({[r]:Cn,...n}));return fn(mn(vn(hn(s,i),{enabled:e})))}function Tn(t){return{all:t=t||new Map,on:function(e,r){var i=t.get(e);i?i.push(r):t.set(e,[r])},off:function(e,r){var i=t.get(e);i&&(r?i.splice(i.indexOf(r)>>>0,1):t.set(e,[]))},emit:function(e,r){var i=t.get(e);i&&i.slice().map(function(n){n(r)}),(i=t.get("*"))&&i.slice().map(function(n){n(e,r)})}}}function N(t,e,r,i=!0){e[xe]=e[xe]||[],e[xe].push(t);const n=new Map;Object.defineProperty(e,t,{enumerable:i,get(){if(typeof e[ye][t]>"u")return;const s=e[ye][t];if(!s)return s;const a=r.get(e[ye][t],{parent:this.id?{id:this.id,type:this.type}:void 0});return n.has(a)||(n.clear(),n.set(a,ve(a,r))),n.get(a)},set(s){e[ye][t]!==s&&(this[de]?r.modifyEntityField({id:this.id,type:this.type},t,Ar(s)):this[ye][t]=s)}})}const ye=Symbol.for("_refs_"),de=Symbol.for("_reactive_"),xe=Symbol.for("_defined_"),Ut=Symbol.for("_parent_");function In(t,e=!1,r){const i={id:"",type:"unknown",[xe]:[],[ye]:{},[Ut]:r||null,[de]:null,is(n){return typeof n=="string"?this.id===n:n.id?n.id===this.id:!1},reactive(){if(!this[de])return this[de]=this.subscribe(()=>this.refresh(),!0),()=>{this.unreactive()}},refresh(){if(this.id){const n=this.unwrap();for(const s of Object.keys(n||{}))this[xe].includes(s)?this[ye][s]=n[s]:this[s]=n[s]}},unreactive(){this[de]&&(this[de](),this[de]=null)},unwrap(){if(!this.id)throw new Error("Invalid object");const n=this[Ut];return t.get(this.id,{parent:n?{id:n,type:"unknown"}:void 0})},toPresentation3(){return t.toPresentation3(this.unwrap())},toPresentation2(){return t.toPresentation2(this.unwrap())},valueOf(){return this.unwrap()},toJSON(){const n=this;return{...n,items:n.items,annotations:n.annotations,structures:n.structures,seeAlso:n.seeAlso,service:n.service,services:n.services,rendering:n.rendering,partOf:n.partOf,start:n.start,supplementary:n.supplementary,homepage:n.homepage,thumbnail:n.thumbnail,placeholderCanvas:n.placeholderCanvas,accompanyingCanvas:n.accompanyingCanvas,provider:n.provider}},subscribe(n,s=!0){return t.subscribe(()=>this.id?t.get(this.id):null,n,s)}};return N("items",i,t),N("annotations",i,t),N("structures",i,t),N("seeAlso",i,t),N("rendering",i,t),N("partOf",i,t),N("start",i,t,!1),N("supplementary",i,t),N("homepage",i,t),N("thumbnail",i,t),N("placeholderCanvas",i,t,!1),N("accompanyingCanvas",i,t,!1),N("provider",i,t),N("body",i,t),N("logo",i,t),i}function jn(t){return!!t[xe]}function Ar(t){return Array.isArray(t)?t.map(e=>Ar(e)):!t||!t.type?t:{id:t.id,type:t.type}}function ve(t,e,r=!1,i){if(Array.isArray(t))return t.map(o=>ve(o,e,r));if(!t||!t.type||!t.id)return t;const n=In(e,r),s=Object.create(n),a=Object.assign(s,t);return r&&a.reactive(),a}function Vt(t){switch(t){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 t}let vt=class{constructor(e,r){le(this,"options"),le(this,"store"),le(this,"emitter"),le(this,"isBatching",!1),le(this,"batchQueue",[]),le(this,"remoteFetcher"),le(this,"staticFetcher"),le(this,"defaultFetcher",i=>fetch(i).then(n=>n.json())),this.options=Object.assign({reducers:{},customFetcher:this.defaultFetcher,enableDevtools:!0},e||{}),this.store=r||kn({customReducers:this.options.reducers,defaultState:this.options.defaultState,enableDevtools:this.options.enableDevtools}),this.emitter=Tn(),this.remoteFetcher=qt(this,this.options.customFetcher),this.staticFetcher=qt(this,(i,n)=>n)}batch(e){this.isBatching=!0;try{e(this),this.isBatching=!1,this.dispatch(dt({actions:this.batchQueue}))}catch(r){throw this.batchQueue=[],this.isBatching=!1,r}this.batchQueue=[]}async asyncBatch(e){this.isBatching=!0;try{await e(this),this.isBatching=!1,this.dispatch(dt({actions:this.batchQueue}))}catch(r){throw this.batchQueue=[],this.isBatching=!1,r}this.batchQueue=[]}modifyEntityField(e,r,i){this.dispatch(Ki.modifyEntityField({id:e.id,type:e.type,key:r,value:i}))}dispatch(e){if(this.isBatching)this.batchQueue.push(e);else{if(e.type===wt){for(const n of e.payload.actions)this.emitter.emit(n.type,{action:n,state:this.store.getState()});this.store.dispatch(e);const i=this.getState();for(const n of e.payload.actions)this.emitter.emit(`after:${n.type}`,{action:n,state:i});return}this.emitter.emit(e.type,{action:e,state:this.store.getState()}),this.store.dispatch(e);const r=this.store.getState();this.emitter.emit(`after:${e.type}`,{action:e,state:r});return}}on(e,r){return this.emitter.on(e,r),()=>{this.emitter.off(e,r)}}serialize(e,r){return B.serialize(this.getState().iiif,e,r)}toPresentation2(e){return this.serialize(e,B.serializeConfigPresentation2)}toPresentation3(e){return this.serialize(e,B.serializeConfigPresentation3)}hydrate(e,r,i={}){return this.get(e,r,{...i,skipSelfReturn:!1})}get(e,r,i={}){typeof r!="string"&&(i=r||{},r=void 0);const{skipSelfReturn:n=!0}=i||{};let s=i.parent?typeof i.parent=="string"?i.parent:i.parent.id:void 0;if(Array.isArray(e))return e.map(p=>this.get(p,i));const a=this.getState();if(B.isSpecificResource(e)&&!i.preserveSpecificResources&&(e=e.source),typeof e=="string"){const p=Vt(r||a.iiif.mapping[e]);if(!p)return n?null:{id:e,type:"unknown"};e={id:e,type:p}}if(e&&e.partOf&&!s&&!i.skipPartOfCheck){const p=Array.isArray(e.partOf)?e.partOf[0]:e.partOf;p&&(typeof p=="string"&&(s=p),typeof p.id=="string"&&(s=p.id))}const o=Vt(r||(e==null?void 0:e.type)),u=e==null?void 0:e.id,h=a.iiif.entities[o];if(!h){const p=a.iiif.requests[u];return p&&p.resourceUri!==u?this.get(p.resourceUri,i):n?null:e}const l=h[e.id];if(l&&l[B.HAS_PART]){const p=l[B.HAS_PART].find(g=>s?g[B.PART_OF]===s:g[B.PART_OF]===l.id);return B.frameResource(l,p)}return h[e.id]||(n?null:e)}select(e){return e(this.getState())}getStore(){return this.store}getState(){return this.store.getState()}deep(e,r){if(typeof e>"u")return this.get(r,{skipSelfReturn:!1});if(typeof e=="function")try{const n=e(this.get(r,{skipSelfReturn:!1})),s=a=>this.deep(a,n);return s.size=Array.isArray(n)?n.length:1,s}catch{const n=s=>this.deep(s,void 0);return n.size=0,n}const i=n=>this.deep(n,e);return i.size=Array.isArray(e)?e.length:1,i}loadManifest(e,r){const i=typeof e=="string"?e:e.id;return this.load(i,r)}loadCollection(e,r){const i=typeof e=="string"?e:e.id;return this.load(i,r)}load(e,r){const i=typeof e=="string"?e:e.id;return r?this.staticFetcher(i,r):this.remoteFetcher(i)}areInputsEqual(e,r){return Dt(e,r)}subscribe(e,r,i){return typeof i>"u"&&(typeof r>"u"||r===!1||r===!0)&&(i=r,r=e,e=n=>n),this.store.subscribe(e,n=>r(n,this),{equalityFn:Dt,fireImmediately:!i})}async ensureLoaded(e){const r=typeof e=="string"?e:e.id;this.requestStatus(r)||await this.load(r)}requestStatus(e){return this.select(r=>r.iiif.requests[e])}getResourceMeta(e,r){const i=this.getState().iiif.meta[e];if(i)return r?i[r]:i}getObject(e,r,i={}){const{reactive:n,...s}=i;return ve(this.get(e,r,s),this,n)}async loadObject(e,r){return ve(await this.load(e,r),this)}async loadManifestObject(e,r){return ve(await this.loadManifest(e,r),this)}async loadCollectionObject(e,r){return ve(await this.loadCollection(e,r),this)}wrapObject(e){return ve(this.get(e,{skipSelfReturn:!1}),this)}isWrapped(e){return jn(e)}setMetaValue([e,r,i],n){this.dispatch(typeof n=="function"?Ft.setMetaValueDynamic({id:e,meta:r,key:i,updateValue:n}):Ft.setMetaValue({id:e,meta:r,key:i,value:n}))}};function On(){return typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{}}function wr(t){const e=On();try{const i=e.IIIF_VAULT;if(i)return i}catch{}const r=new vt(t);try{e.IIIF_VAULT=r}catch{}return r}const We=v.createContext({vault:null,setVaultInstance:t=>{}});function Sr({vault:t,vaultOptions:e,useGlobal:r,resources:i,children:n}){const[s,a]=v.useState(()=>t||(r?wr(e):e?new vt(e):new vt));return m.jsx(We.Provider,{value:{vault:s,setVaultInstance:a},children:m.jsx(ze,{value:i||{},children:n})})}const W=()=>{const{vault:t}=v.useContext(We);if(t===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return t};function En(t,{noCache:e=!1}={}){const r=typeof t=="string"?t:t.id,i=W(),[n,s]=v.useState(r),[a,o]=v.useState(void 0),u=v.useMemo(()=>i.get(r,{skipSelfReturn:!0})||void 0,[r,i]),[h,l]=v.useState(u);return v.useEffect(()=>{(async()=>{try{const p=u&&!e?u:await i.load(r),g=p?p.id||p["@id"]:null;p&&n!==g&&s(g),l(p)}catch(p){o(p)}})()},[r,e]),{isLoaded:!!h,id:n,requestId:r,error:a,resource:h,cached:!!(h&&h===u)}}function Pn(t,e){const{id:r,isLoaded:i,error:n,resource:s,requestId:a,cached:o}=En(t,e);return{id:r,isLoaded:i,error:n,manifest:s,requestId:a,cached:o}}function Ln({manifest:t,children:e}){return m.jsx(ze,{value:{manifest:t},children:e})}function St({canvas:t,children:e}){return m.jsx(ze,{value:{canvas:t},children:e})}function Q(t,e=[]){const r=W(),[i,n]=v.useState(()=>t(r.getState(),r));return v.useEffect(()=>r.subscribe(s=>t(s,r),s=>{n(s)},!1),e),i}const Qe=v.createContext([]);function Mr(){const t=v.useContext(Qe);return Q(e=>t.map(r=>e.iiif.entities.Canvas[r]).filter(Boolean),[t])}function Ce(t={},e=[]){const{id:r,selector:i}=t,n=Me();W();const s=r||n.manifest,a=Q(o=>s?o.iiif.entities.Manifest[s]:void 0,[s]);return v.useMemo(()=>{if(a)return i?i(a):a},[a,i,...e])}function Fn({range:t,children:e}){return m.jsx(ze,{value:{range:t},children:e})}function Cr(t,e){var i;const r=[];for(const n of e.items)if(n.type==="SpecificResource"&&((i=n.source)==null?void 0:i.type)==="Canvas"&&(n.source.id.indexOf("#")!==-1?r.push({id:n.source.id.split("#")[0],type:"Canvas"}):r.push(n.source)),n.type==="Range"&&r.push(...Cr(t,t.get(n))),n.type==="SpecificResource"){const s=typeof n.source=="string"?n.source:n.source.id;r.push({id:s,type:"Canvas"})}return r}function $n(t,e,{disablePaging:r,skipNonPaged:i}={}){const n=e.behavior,s=n.includes("paged"),a=s?!1:n.includes("continuous"),o=s||a?!1:n.includes("individuals"),u=e.type==="Manifest"?e.items:Cr(t,e);if(a)return[u,[u.map((d,x)=>x)]];if(o||!s||r)return[u,u.map((d,x)=>[x])];const h=[];let l=[];const p=()=>{l.length&&(h.push([...l]),l=[])};let g=0,b=!1;for(let d=0;d<u.length;d++){const x=t.get(u[d]);if(x.behavior.includes("non-paged")){d===g&&g++,i||(p(),h.push([d]),p());continue}if(d===g||x.behavior.includes("facing-pages")){l.length&&(b=!0),p(),h.push([d]),p();continue}if(l.push(d),b){p(),b=!1;continue}l.length>1&&p()}return l.length&&p(),[u,h]}function Dn(t={},e=[]){const{id:r,selector:i}=t,n=Me(),s=r||n.range,a=Q(o=>s?o.iiif.entities.Range[s]:void 0,[s]);return v.useMemo(()=>{if(a)return i?i(a):a},[a,i,...e])}function qn({startCanvas:t,disablePaging:e}){var d;const r=W(),i=Ce(),n=Dn(),[s,a]=v.useState(void 0),o=n||i;if(!o)throw new Error("Nothing selected");const[u,h]=v.useMemo(()=>$n(r,o,{disablePaging:e}),[r,o]),l=v.useCallback(x=>{const w=h.findIndex(A=>A.includes(x));a(w===-1?0:w)},[u,h]),p=v.useCallback(x=>{const w=u.findIndex(A=>A.id===x);w!==-1?l(w):a(0)},[u,h]),g=v.useCallback(()=>{a(x=>x>=h.length?x:x+1)},[h]),b=v.useCallback(()=>{a(x=>x<=0?0:x-1)},[h]);return typeof s>"u"&&(t?p(t):a(0)),{visibleItems:((d=h[s])==null?void 0:d.map(x=>u[x].id))||[],cursor:s,items:u,sequence:h,setSequenceIndex:a,setCanvasIndex:l,setCanvasId:p,next:g,previous:b}}const Re=()=>{},Ye=v.createContext({setCurrentCanvasId:Re,setCurrentCanvasIndex:Re,nextCanvas:Re,previousCanvas:Re,items:[],sequence:[],setSequenceIndex:Re,currentSequenceIndex:0});function _n(t){const e=Ce(),{cursor:r,visibleItems:i,next:n,sequence:s,items:a,setCanvasIndex:o,setCanvasId:u,previous:h,setSequenceIndex:l}=qn({startCanvas:t.startCanvas,disablePaging:t.pagingEnabled===!1}),p=v.useMemo(()=>({sequence:s,items:a,setCurrentCanvasId:u,nextCanvas:n,previousCanvas:h,totalCanvases:a.length,setCurrentCanvasIndex:o,setSequenceIndex:l,currentSequenceIndex:r}),[s,a,u,n,h,a,o,l,r]);return e?m.jsx(Ye.Provider,{value:p,children:m.jsx(Qe.Provider,{value:i,children:m.jsx(St,{canvas:i[0],children:t.children})})}):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),m.jsx("div",{children:"Sorry, something went wrong."}))}function Un(t){const e=Pn(t.manifest);if(!e)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),m.jsx("div",{children:"Sorry, something went wrong."});if(e.error)return m.jsx("div",{children:e.error.toString()});if(!e.isLoaded)return m.jsx("div",{children:"Loading..."});const r=m.jsx(_n,{...t,children:t.children});return m.jsx(Ln,{manifest:e.id,children:t.rangeId?m.jsx(Fn,{range:t.rangeId,children:r}):r})}function Vn(){return v.useContext(Ye)}function Hn(){return{VaultContext:v.useContext(We),ResourceContext:v.useContext(At),SimpleViewerReactContext:v.useContext(Ye),VisibleCanvasReactContext:v.useContext(Qe)}}function Nn(t){return m.jsx(Sr,{vault:t.bridge.VaultContext.vault||void 0,resources:t.bridge.ResourceContext,children:m.jsx(Qe.Provider,{value:t.bridge.VisibleCanvasReactContext,children:m.jsx(Ye.Provider,{value:t.bridge.SimpleViewerReactContext,children:t.children})})})}const te=function(t){return function(){const e={type:t,getType:()=>t,toString:()=>t};return(r,i)=>({...e,...r!==void 0&&{payload:r},...i!==void 0&&{meta:i}})}},Bn="@iiif/IMPORT_ENTITIES",zn="@iiif/MODIFY_ENTITY_FIELD",Wn="@iiif/REORDER_ENTITY_FIELD",Qn="@iiif/ADD_REFERENCE",Yn="@iiif/UPDATE_REFERENCE",Gn="@iiif/REMOVE_REFERENCE",Jn="@iiif/ADD_METADATA",Kn="@iiif/REMOVE_METADATA",Zn="@iiif/UPDATE_METADATA",Xn="@iiif/REORDER_METADATA",es=te(Bn)(),ts=te(zn)(),rs=te(Wn)(),is=te(Qn)(),ns=te(Gn)(),ss=te(Yn)(),as=te(Jn)(),os=te(Zn)(),cs=te(Kn)(),us=te(Xn)(),it={importEntities:es,modifyEntityField:ts,reorderEntityField:rs,addReference:is,removeReference:ns,updateReference:ss,addMetadata:as,removeMetadata:cs,updateMetadata:os,reorderMetadata:us};function ls(){const e=W().getStore();return v.useMemo(()=>r=>e.dispatch(r),[e])}function Ht(t){return typeof t!="string"&&t&&t.bindToVault}function fs(){const t=W(),e=v.useRef([]),r=ls(),i=v.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);v.useLayoutEffect(()=>{const o={id:i,type:"AnnotationPage",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],rendering:[],service:[]};r(it.importEntities({entities:{AnnotationPage:{[o.id]:o}}}))},[i]);const n=Q(o=>i?o.iiif.entities.AnnotationPage[i]:null,[i]),s=v.useCallback((o,u)=>{if(i){if(Ht(o)){const p=o;p.__vault||p.bindToVault(t),o=typeof p.source=="string"?p.source:p.source.id,e.current[o]=p}else typeof o!="string"&&(o=o.id);const h=t.get({id:i,type:"AnnotationPage"}),l=t.get({id:o,type:"Annotation"});h&&l&&(h.items.find(p=>p.id===l.id)||r(it.addReference({id:i,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"},index:u})))}},[i]),a=v.useCallback(o=>{i&&(Ht(o)?o=typeof o.source=="string"?o.source:o.source.id:typeof o!="string"&&(o=o.id),e.current[o]&&e.current[o].beforeRemove(),t.get({id:i,type:"AnnotationPage"})&&r(it.removeReference({id:i,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"}})))},[i]);return[n,{addAnnotation:s,removeAnnotation:a}]}const Rr=v.createContext(null);function ps(){const t=v.useContext(Rr);return[t.fullPage,{addAnnotation:t.addAnnotation,removeAnnotation:t.removeAnnotation}]}function hs({children:t}){const[e,{addAnnotation:r,removeAnnotation:i}]=fs();return m.jsx(Rr.Provider,{value:v.useMemo(()=>({fullPage:e,addAnnotation:r,removeAnnotation:i}),[e]),children:t})}function ds({width:t,style:e,height:r,error:i,resetErrorBoundary:n}){return m.jsxs("div",{style:{width:t,height:r,minHeight:500,...e||{},background:"#f9f9f9"},children:[m.jsx("h3",{children:"Error occurred"}),m.jsx("p",{children:i.message}),m.jsx("button",{onClick:n,children:"Reset"})]})}const Mt=v.createContext(null);function ys(){return v.useContext(Mt)}const kr=v.createContext(()=>{}),Tr=v.createContext(()=>{});function Se(t,e,r,i,n=[]){const s=v.useContext(t==="portal"?Tr:kr);v.useEffect(()=>(t!=="none"&&s(e,r,i),()=>{s(e,null)}),[e,t,s,...n])}function fe(t={},e=[]){const{id:r,selector:i}=t,n=Me(),s=r||n.canvas,a=Q(o=>s?o.iiif.entities.Canvas[s]:void 0,[s]);return v.useMemo(()=>{if(a)return i?i(a):a},[a,i,...e])}const Ir=v.createContext(()=>{});function vs(t){const e=fe(),r=v.useContext(Ir);v.useEffect(()=>e&&e.id?(r(e.id,t),()=>r(e.id,-1)):()=>{},[e,t])}function gs({children:t,errorFallback:e,outerContainerProps:r={},worldScale:i,...n}){const[s,a]=v.useState(),o=Hn(),u=e||ds,[h,l]=v.useState({}),p=Object.entries(h),[g,b]=v.useState({}),d=Object.entries(g),[x,w]=v.useState({}),A=v.useMemo(()=>i||Math.max(...Object.values(x)),[x]),S=v.useMemo(()=>({maxOverZoom:A||1}),[A]),k=v.useCallback((T,P)=>{w(E=>{if(P===-1){const{[T]:C,...$}=E;return $}return{...E,[T]:P}})},[]),O=v.useCallback((T,P,E)=>{l(({[T]:C,...$})=>P?{...$,[T]:{element:P,props:E}}:$)},[]),F=v.useCallback((T,P,E)=>{b(({[T]:C,...$})=>P?{...$,[T]:{element:P,props:E}}:$)},[]);return m.jsxs(qi,{resetKeys:[],fallbackRender:T=>m.jsx(u,{...n,...T}),children:[m.jsx(we.AtlasAuto,{...n,containerProps:{style:{position:"relative"},...n.containerProps||{}},htmlChildren:m.jsx(m.Fragment,{children:p.map(([T,{element:P,props:E}])=>m.jsx(v.Fragment,{children:m.jsx(P,{...E||{}})},T))}),onCreated:T=>{a(T),n.onCreated&&n.onCreated(T)},runtimeOptions:S,children:m.jsx(Mt.Provider,{value:s,children:m.jsx(Ir.Provider,{value:k,children:m.jsx(kr.Provider,{value:O,children:m.jsx(Tr.Provider,{value:F,children:m.jsx(Nn,{bridge:o,children:m.jsx(we.ModeContext.Provider,{value:n.mode||"explore",children:m.jsx(hs,{children:t})})})})})})})}),m.jsx("div",{children:d.map(([T,{element:P,props:E}])=>m.jsx(v.Fragment,{children:m.jsx(P,{...E||{}})},T))})]})}const $e={},jr={get(t){return t},setMetaValue([t,e,r],i){const n=jr.getResourceMeta(t,e),s=n?n[r]:void 0,a=typeof i=="function"?i(s):i;$e[t]={...$e[t]||{},[e]:{...($e[t]||{})[e]||{},[r]:a}}},getResourceMeta:(t,e)=>{const r=$e[t];if(r)return e?r[e]:r}};function ms(t=jr){return{addEventListener(e,r,i,n){if(e)return t.setMetaValue([e.id,"eventManager",r],s=>{const a=s||[];for(const o of a)if(o.callback===i)return a;return[...a,{callback:i,scope:n}]}),i},removeEventListener(e,r,i){e&&t.setMetaValue([e.id,"eventManager",r],n=>(n||[]).filter(s=>s.callback!==i))},getListenersAsProps(e,r){const i=typeof e=="string"?{id:e}:e;if(!i||!i.id)return{};const n=t.getResourceMeta(i.id,"eventManager"),s={};if(n&&i)for(const a of Object.keys(n))s[a]=o=>{const u=t.get(i);for(const{callback:h,scope:l}of n[a]||[])(!l||r&&l.indexOf(r)!==-1)&&h(o,u)};return s}}}function Or(t,e){const r=W(),i=v.useMemo(()=>ms(r),[r]),n=Q(()=>t&&t.id?r.getResourceMeta(t.id,"eventManager"):null,[t]);return v.useMemo(()=>t?i.getListenersAsProps(t,e):{},[n,t,r,e])}const De={},Er={get(t){return t},setMetaValue([t,e,r],i){const n=Er.getResourceMeta(t,e),s=n?n[r]:void 0,a=typeof i=="function"?i(s):i;De[t]={...De[t]||{},[e]:{...(De[t]||{})[e]||{},[r]:a}}},getResourceMeta:(t,e)=>{const r=De[t];if(r)return e?r[e]:r}};function Pr(t=Er){return{applyStyles(e,r,i){const n=typeof e=="string"?e:e.id;return t.setMetaValue([n,"styles",r],i)},getAppliedStyles(e){const r=typeof e=="string"?e:e.id;return t.getResourceMeta(r,"styles")}}}function Be(t,e){const r=W(),i=v.useMemo(()=>Pr(r),[r]);return Q(()=>{if(!t)return null;const n=i.getAppliedStyles(t.id);return n?e?n[e]:n:void 0},[t,e])}var xs=Object.defineProperty,bs=(t,e,r)=>e in t?xs(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ue=(t,e,r)=>(bs(t,typeof e!="symbol"?e+"":e,r),r),As=function(){function t(e,r){var i=[],n=!0,s=!1,a=void 0;try{for(var o=e[Symbol.iterator](),u;!(n=(u=o.next()).done)&&(i.push(u.value),!(r&&i.length===r));n=!0);}catch(h){s=!0,a=h}finally{try{!n&&o.return&&o.return()}finally{if(s)throw a}}return i}return function(e,r){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),Te=Math.PI*2,nt=function(t,e,r,i,n,s,a){var o=t.x,u=t.y;o*=e,u*=r;var h=i*o-n*u,l=n*o+i*u;return{x:h+s,y:l+a}},ws=function(t,e){var r=e===1.5707963267948966?.551915024494:e===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(e/4),i=Math.cos(t),n=Math.sin(t),s=Math.cos(t+e),a=Math.sin(t+e);return[{x:i-n*r,y:n+i*r},{x:s+a*r,y:a-s*r},{x:s,y:a}]},Nt=function(t,e,r,i){var n=t*i-e*r<0?-1:1,s=t*r+e*i;return s>1&&(s=1),s<-1&&(s=-1),n*Math.acos(s)},Ss=function(t,e,r,i,n,s,a,o,u,h,l,p){var g=Math.pow(n,2),b=Math.pow(s,2),d=Math.pow(l,2),x=Math.pow(p,2),w=g*b-g*x-b*d;w<0&&(w=0),w/=g*x+b*d,w=Math.sqrt(w)*(a===o?-1:1);var A=w*n/s*p,S=w*-s/n*l,k=h*A-u*S+(t+r)/2,O=u*A+h*S+(e+i)/2,F=(l-A)/n,T=(p-S)/s,P=(-l-A)/n,E=(-p-S)/s,C=Nt(1,0,F,T),$=Nt(F,T,P,E);return o===0&&$>0&&($-=Te),o===1&&$<0&&($+=Te),[k,O,C,$]},Ms=function(t){var e=t.px,r=t.py,i=t.cx,n=t.cy,s=t.rx,a=t.ry,o=t.xAxisRotation,u=o===void 0?0:o,h=t.largeArcFlag,l=h===void 0?0:h,p=t.sweepFlag,g=p===void 0?0:p,b=[];if(s===0||a===0)return[];var d=Math.sin(u*Te/360),x=Math.cos(u*Te/360),w=x*(e-i)/2+d*(r-n)/2,A=-d*(e-i)/2+x*(r-n)/2;if(w===0&&A===0)return[];s=Math.abs(s),a=Math.abs(a);var S=Math.pow(w,2)/Math.pow(s,2)+Math.pow(A,2)/Math.pow(a,2);S>1&&(s*=Math.sqrt(S),a*=Math.sqrt(S));var k=Ss(e,r,i,n,s,a,l,g,d,x,w,A),O=As(k,4),F=O[0],T=O[1],P=O[2],E=O[3],C=Math.abs(E)/(Te/4);Math.abs(1-C)<1e-7&&(C=1);var $=Math.max(Math.ceil(C),1);E/=$;for(var X=0;X<$;X++)b.push(ws(P,E)),P+=E;return b.map(function(Y){var _=nt(Y[0],s,a,x,d,F,T),U=_.x,J=_.y,ee=nt(Y[1],s,a,x,d,F,T),he=ee.x,j=ee.y,V=nt(Y[2],s,a,x,d,F,T),G=V.x,oe=V.y;return{x1:U,y1:J,x2:he,y2:j,x:G,y:oe}})};function Lr(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Cs=ks,st={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},Rs=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function ks(t){var e=[];return t.replace(Rs,function(r,i,n){var s=i.toLowerCase();for(n=Is(n),s=="m"&&n.length>2&&(e.push([i].concat(n.splice(0,2))),s="l",i=i=="m"?"l":"L");;){if(n.length==st[s])return n.unshift(i),e.push(n);if(n.length<st[s])throw new Error("malformed path data");e.push([i].concat(n.splice(0,st[s])))}}),e}var Ts=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function Is(t){var e=t.match(Ts);return e?e.map(Number):[]}const js=Lr(Cs);var Os=Es;function Es(t){var e=0,r=0,i=0,n=0;return t.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]+=i,s[7]+=n;break;case"v":s[1]+=n;break;case"h":s[1]+=i;break;default:for(var u=1;u<s.length;)s[u++]+=i,s[u++]+=n}switch(o){case"Z":i=e,n=r;break;case"H":i=s[1];break;case"V":n=s[1];break;case"M":i=e=s[1],n=r=s[2];break;default:i=s[s.length-2],n=s[s.length-1]}return s})}const Ps=Lr(Os);function Ls(t){const e=js(t),r=Ps(e);let i,n=0,s=0,a=0,o=0,u,h,l=0,p=0;const g=[];for(let b=0;b<r.length;b++){let d=r[b];const x=d[0];switch(x){case"M":n=d[1],s=d[2];break;case"H":d=["L",d[1],s];break;case"V":d=["L",n,d[1]];break;case"S":{let w=l,A=p;(i==="C"||i=="S")&&(w+=w-a,A+=A-o),d=["C",w,A,d[1],d[2],d[3],d[4]]}break;case"T":i==="Q"||i=="T"?(u=l*2-u,h=p*2-h):(u=l,h=p),d=["Q",u,h,d[1],d[2]];break;case"Q":u=d[1],h=d[2];break;case"A":{const w=Ms({px:l,py:p,cx:d[6],cy:d[7],rx:d[1],ry:d[2],xAxisRotation:d[3],largeArcFlag:d[4],sweepFlag:d[5]});if(!w.length)continue;for(const[A,S]of w.entries())d=["C",S.x1,S.y1,S.x2,S.y2,S.x,S.y],A<w.length-1&&g.push(d);d=d}break;case"Z":d=["L",n,s];break}i=x,l=d[d.length-2],p=d[d.length-1],["C","Q","A"].indexOf(x)>-1?(a=d[d.length-4],o=d[d.length-3]):(a=l,o=p),g.push(d)}return g}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
5
+ `);const S=A.state[o];if(S==null)return;JSON.stringify(n.getState())!==JSON.stringify(S)&&b(S);return}n.dispatchFromDevtools&&typeof n.dispatch=="function"&&n.dispatch(A)});case"DISPATCH":switch(x.payload.type){case"RESET":return b(d),o===void 0?l==null?void 0:l.init(n.getState()):l==null?void 0:l.init(Fe(u.name));case"COMMIT":if(o===void 0){l==null||l.init(n.getState());return}return l==null?void 0:l.init(Fe(u.name));case"ROLLBACK":return et(x.state,A=>{if(o===void 0){b(A),l==null||l.init(n.getState());return}b(A[o]),l==null||l.init(Fe(u.name))});case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return et(x.state,A=>{if(o===void 0){b(A);return}JSON.stringify(n.getState())!==JSON.stringify(A[o])&&b(A[o])});case"IMPORT_STATE":{const{nextLiftedState:A}=x.payload,S=(w=A.computedStates.slice(-1)[0])==null?void 0:w.state;if(!S)return;b(o===void 0?S:S[o]),l==null||l.send(null,A);return}case"PAUSE_RECORDING":return g=!g}return}}),d},gn=vn,et=(t,e)=>{let r;try{r=JSON.parse(t)}catch(i){console.error("[zustand devtools middleware] Could not parse the received json",i)}r!==void 0&&e(r)},mn=t=>(e,r,i)=>{const n=i.subscribe;return i.subscribe=(s,a,o)=>{let u=s;if(a){const p=(o==null?void 0:o.equalityFn)||Object.is;let l=s(i.getState());u=h=>{const g=s(h);if(!p(l,g)){const b=l;a(l=g,b)}},o!=null&&o.fireImmediately&&a(l,l)}return n(u)},t(e,r,i)},xn=mn,bn=(t={},e)=>{switch(e.type){case ur:return{...t,[e.payload.id]:e.payload.type};case lr:return{...t,...e.payload.mapping};default:return t}};function tt(t,e,r,i){return!(!t[r]||!t[r][e]||!t[r][e][i]||!Array.isArray(t[r][e][i]))}function An(t,e){const r={},i=[];for(const[n,s]of Object.entries(t||{})){i.push(n);const a=(e||{})[n];if(!a||a.length===0){r[n]=s;continue}r[n]=a}for(const[n,s]of Object.entries(e||{}))i.indexOf(n)===-1&&(r[n]=s);return r}function R(t){return t.payload}function rt(t,e){return typeof t>"u"?e:t}const wn=(t=xr(),e)=>{var r;const i=(n,s)=>({...t,[R(e).type]:{...t[R(e).type],[R(e).id]:{...n,...s}}});switch(e.type){case tr:{if(!t[R(e).type]||!t[R(e).type][R(e).id])return t;const n=t[R(e).type][R(e).id];return typeof n=="string"?t:i(n,{[R(e).key]:R(e).value})}case rr:{if(!tt(t,R(e).id,R(e).type,R(e).key))return t;const n=t[R(e).type][R(e).id];if(typeof n=="string")return t;const s=Array.from(n[R(e).key]),[a]=s.splice(R(e).startIndex,1);return s.splice(R(e).endIndex,0,a),i(n,{[R(e).key]:s})}case er:{const n=Object.keys(R(e).entities),s={...t};for(const a of n){const o=R(e).entities[a],u={...t[a]||{}};let p=!1;const l=Object.keys(o||{})||[];if(o&&l){for(const h of l)p=!0,u[h]=t[a][h]?An(t[a][h],o[h]):o[h];p&&(s[a]=u)}}return s}case ir:{if(!tt(t,R(e).id,R(e).type,R(e).key))return t;const n=t[R(e).type][R(e).id],s=Array.from(n[R(e).key]);return s.splice(rt(R(e).index,s.length+1),0,R(e).reference),i(n,{[R(e).key]:s})}case lt:case nr:{if(!tt(t,R(e).id,R(e).type,R(e).key))return t;const n=t[R(e).type][R(e).id],s=Array.from(n[R(e).key]),a=rt(R(e).index,s.findIndex(o=>o&&o.id===R(e).reference.id));return a===-1||((r=s[a])==null?void 0:r.id)!==R(e).reference.id?t:(e.type===lt?s.splice(a,1,R(e).reference):s.splice(a,1),i(n,{[R(e).key]:s}))}case sr:{const n=t[R(e).type][R(e).id];if(!n)return t;const s=Array.from(n.metadata||[]),a=R(e);return s.splice(rt(e.payload.beforeIndex,s.length+1),0,{label:a.label,value:a.label}),i(n,{metadata:s})}case or:{const n=t[R(e).type][R(e).id];if(typeof n=="string"||!n)return t;const s=Array.from(n.metadata||[]),[a]=s.splice(R(e).startIndex,1);return s.splice(R(e).endIndex,0,a),i(n,{metadata:s})}case ft:case ar:{const n=t[R(e).type][R(e).id],s=Array.from(n.metadata||[]),a=R(e).atIndex;return typeof a>"u"||a===-1||!s[a]?t:(e.type===ft?s.splice(a,1,{label:R(e).label,value:R(e).value}):s.splice(a,1),i(n,{metadata:s}))}default:return t}},Sn=(t={},e)=>{switch(e.type){case yr:case nn:return{...t,[e.payload.id]:{requestUri:e.payload.id,loadingState:dr,uriMismatch:!1,resourceUri:e.payload.id}};case gr:return{...t,[e.payload.requestId]:{...t[e.payload.requestId]||{},uriMismatch:!0,resourceUri:e.payload.actualId},[e.payload.actualId]:{requestUri:e.payload.requestId,loadingState:t[e.payload.requestId].loadingState,uriMismatch:!0,resourceUri:e.payload.actualId}};case vr:return{...t,[e.payload.id]:{...t[e.payload.id]||{},loadingState:pt,error:e.payload.message}};case mr:return{...t,[e.payload.id]:{...t[e.payload.id]||{},loadingState:ht,error:void 0}}}return t},Mn=(t={},e)=>{const{id:r,updateValue:i,value:n,meta:s,key:a}=e&&e.payload||{};switch(e.type){case fr:return{...t,[r]:{...t[r]||{},[s]:{...t[r]?t[r][s]||{}:{},[a]:n}}};case pr:return{...t,[r]:{...t[r]||{},[s]:{...t[r]?t[r][s]||{}:{},[a]:t[r]&&t[r][s]?i(t[r][s][a]):i(void 0)}}};case hr:return t[r]&&t[r][s]&&t[r][s][a]?{...t,[r]:{...t[r]||{},[s]:{...t[r]?t[r][s]||{}:{},[a]:void 0}}}:t;default:return t}};function br(t={}){const e=Object.keys(t);return function(r={},i){let n=!1;const s={};for(let a=0;a<e.length;a++){const o=e[a];s[o]=t[o](r[o],i),n=n||s[o]!==r[o]}return n?s:r}}function Cn(t){return(e,r)=>r&&r.type===St?r.payload.actions.reduce(t,e):r&&r.type===cn?{...e,iiif:{...e.iiif,...r.payload.state}}:t(e,r)}const Rn=br({mapping:bn,entities:wn,requests:Sn,meta:Mn});function kn(){return{iiif:{entities:xr(),meta:{},mapping:{},requests:{}}}}function Tn(t={}){const{enableDevtools:e=!1,iiifStoreName:r="iiif",defaultState:i=kn(),customReducers:n={}}=t,s=Cn(br({[r]:Rn,...n}));return pn(xn(gn(dn(s,i),{enabled:e})))}function In(t){return{all:t=t||new Map,on:function(e,r){var i=t.get(e);i?i.push(r):t.set(e,[r])},off:function(e,r){var i=t.get(e);i&&(r?i.splice(i.indexOf(r)>>>0,1):t.set(e,[]))},emit:function(e,r){var i=t.get(e);i&&i.slice().map(function(n){n(r)}),(i=t.get("*"))&&i.slice().map(function(n){n(e,r)})}}}function N(t,e,r,i=!0){e[xe]=e[xe]||[],e[xe].push(t);const n=new Map;Object.defineProperty(e,t,{enumerable:i,get(){if(typeof e[ye][t]>"u")return;const s=e[ye][t];if(!s)return s;const a=r.get(e[ye][t],{parent:this.id?{id:this.id,type:this.type}:void 0});return n.has(a)||(n.clear(),n.set(a,ve(a,r))),n.get(a)},set(s){e[ye][t]!==s&&(this[de]?r.modifyEntityField({id:this.id,type:this.type},t,Ar(s)):this[ye][t]=s)}})}const ye=Symbol.for("_refs_"),de=Symbol.for("_reactive_"),xe=Symbol.for("_defined_"),Vt=Symbol.for("_parent_");function jn(t,e=!1,r){const i={id:"",type:"unknown",[xe]:[],[ye]:{},[Vt]:r||null,[de]:null,is(n){return typeof n=="string"?this.id===n:n.id?n.id===this.id:!1},reactive(){if(!this[de])return this[de]=this.subscribe(()=>this.refresh(),!0),()=>{this.unreactive()}},refresh(){if(this.id){const n=this.unwrap();for(const s of Object.keys(n||{}))this[xe].includes(s)?this[ye][s]=n[s]:this[s]=n[s]}},unreactive(){this[de]&&(this[de](),this[de]=null)},unwrap(){if(!this.id)throw new Error("Invalid object");const n=this[Vt];return t.get(this.id,{parent:n?{id:n,type:"unknown"}:void 0})},toPresentation3(){return t.toPresentation3(this.unwrap())},toPresentation2(){return t.toPresentation2(this.unwrap())},valueOf(){return this.unwrap()},toJSON(){const n=this;return{...n,items:n.items,annotations:n.annotations,structures:n.structures,seeAlso:n.seeAlso,service:n.service,services:n.services,rendering:n.rendering,partOf:n.partOf,start:n.start,supplementary:n.supplementary,homepage:n.homepage,thumbnail:n.thumbnail,placeholderCanvas:n.placeholderCanvas,accompanyingCanvas:n.accompanyingCanvas,provider:n.provider}},subscribe(n,s=!0){return t.subscribe(()=>this.id?t.get(this.id):null,n,s)}};return N("items",i,t),N("annotations",i,t),N("structures",i,t),N("seeAlso",i,t),N("rendering",i,t),N("partOf",i,t),N("start",i,t,!1),N("supplementary",i,t),N("homepage",i,t),N("thumbnail",i,t),N("placeholderCanvas",i,t,!1),N("accompanyingCanvas",i,t,!1),N("provider",i,t),N("body",i,t),N("logo",i,t),i}function On(t){return!!t[xe]}function Ar(t){return Array.isArray(t)?t.map(e=>Ar(e)):!t||!t.type?t:{id:t.id,type:t.type}}function ve(t,e,r=!1,i){if(Array.isArray(t))return t.map(o=>ve(o,e,r));if(!t||!t.type||!t.id)return t;const n=jn(e,r),s=Object.create(n),a=Object.assign(s,t);return r&&a.reactive(),a}function Ht(t){switch(t){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 t}let gt=class{constructor(e,r){le(this,"options"),le(this,"store"),le(this,"emitter"),le(this,"isBatching",!1),le(this,"batchQueue",[]),le(this,"remoteFetcher"),le(this,"staticFetcher"),le(this,"defaultFetcher",i=>fetch(i).then(n=>n.json())),this.options=Object.assign({reducers:{},customFetcher:this.defaultFetcher,enableDevtools:!0},e||{}),this.store=r||Tn({customReducers:this.options.reducers,defaultState:this.options.defaultState,enableDevtools:this.options.enableDevtools}),this.emitter=In(),this.remoteFetcher=_t(this,this.options.customFetcher),this.staticFetcher=_t(this,(i,n)=>n)}batch(e){this.isBatching=!0;try{e(this),this.isBatching=!1,this.dispatch(yt({actions:this.batchQueue}))}catch(r){throw this.batchQueue=[],this.isBatching=!1,r}this.batchQueue=[]}async asyncBatch(e){this.isBatching=!0;try{await e(this),this.isBatching=!1,this.dispatch(yt({actions:this.batchQueue}))}catch(r){throw this.batchQueue=[],this.isBatching=!1,r}this.batchQueue=[]}modifyEntityField(e,r,i){this.dispatch(Ki.modifyEntityField({id:e.id,type:e.type,key:r,value:i}))}dispatch(e){if(this.isBatching)this.batchQueue.push(e);else{if(e.type===St){for(const n of e.payload.actions)this.emitter.emit(n.type,{action:n,state:this.store.getState()});this.store.dispatch(e);const i=this.getState();for(const n of e.payload.actions)this.emitter.emit(`after:${n.type}`,{action:n,state:i});return}this.emitter.emit(e.type,{action:e,state:this.store.getState()}),this.store.dispatch(e);const r=this.store.getState();this.emitter.emit(`after:${e.type}`,{action:e,state:r});return}}on(e,r){return this.emitter.on(e,r),()=>{this.emitter.off(e,r)}}serialize(e,r){return B.serialize(this.getState().iiif,e,r)}toPresentation2(e){return this.serialize(e,B.serializeConfigPresentation2)}toPresentation3(e){return this.serialize(e,B.serializeConfigPresentation3)}hydrate(e,r,i={}){return this.get(e,r,{...i,skipSelfReturn:!1})}get(e,r,i={}){typeof r!="string"&&(i=r||{},r=void 0);const{skipSelfReturn:n=!0}=i||{};let s=i.parent?typeof i.parent=="string"?i.parent:i.parent.id:void 0;if(Array.isArray(e))return e.map(h=>this.get(h,i));const a=this.getState();if(B.isSpecificResource(e)&&!i.preserveSpecificResources&&(e=e.source),typeof e=="string"){const h=Ht(r||a.iiif.mapping[e]);if(!h)return n?null:{id:e,type:"unknown"};e={id:e,type:h}}if(e&&e.partOf&&!s&&!i.skipPartOfCheck){const h=Array.isArray(e.partOf)?e.partOf[0]:e.partOf;h&&(typeof h=="string"&&(s=h),typeof h.id=="string"&&(s=h.id))}const o=Ht(r||(e==null?void 0:e.type)),u=e==null?void 0:e.id,p=a.iiif.entities[o];if(!p){const h=a.iiif.requests[u];return h&&h.resourceUri!==u?this.get(h.resourceUri,i):n?null:e}const l=p[e.id];if(l&&l[B.HAS_PART]){const h=l[B.HAS_PART].find(g=>s?g[B.PART_OF]===s:g[B.PART_OF]===l.id);return B.frameResource(l,h)}return p[e.id]||(n?null:e)}select(e){return e(this.getState())}getStore(){return this.store}getState(){return this.store.getState()}deep(e,r){if(typeof e>"u")return this.get(r,{skipSelfReturn:!1});if(typeof e=="function")try{const n=e(this.get(r,{skipSelfReturn:!1})),s=a=>this.deep(a,n);return s.size=Array.isArray(n)?n.length:1,s}catch{const n=s=>this.deep(s,void 0);return n.size=0,n}const i=n=>this.deep(n,e);return i.size=Array.isArray(e)?e.length:1,i}loadManifest(e,r){const i=typeof e=="string"?e:e.id;return this.load(i,r)}loadCollection(e,r){const i=typeof e=="string"?e:e.id;return this.load(i,r)}load(e,r){const i=typeof e=="string"?e:e.id;return r?Promise.resolve(this.staticFetcher(i,r)):Promise.resolve(this.remoteFetcher(i))}loadSync(e,r){const i=typeof e=="string"?e:e.id;return this.staticFetcher(i,r)}loadManifestSync(e,r){const i=typeof e=="string"?e:e.id;return this.loadSync(i,r)}loadCollectionSync(e,r){const i=typeof e=="string"?e:e.id;return this.loadSync(i,r)}areInputsEqual(e,r){return qt(e,r)}subscribe(e,r,i){return typeof i>"u"&&(typeof r>"u"||r===!1||r===!0)&&(i=r,r=e,e=n=>n),this.store.subscribe(e,n=>r(n,this),{equalityFn:qt,fireImmediately:!i})}async ensureLoaded(e){const r=typeof e=="string"?e:e.id;this.requestStatus(r)||await this.load(r)}requestStatus(e){return this.select(r=>r.iiif.requests[e])}getResourceMeta(e,r){const i=this.getState().iiif.meta[e];if(i)return r?i[r]:i}getObject(e,r,i={}){const{reactive:n,...s}=i;return ve(this.get(e,r,s),this,n)}async loadObject(e,r){return ve(await this.load(e,r),this)}async loadManifestObject(e,r){return ve(await this.loadManifest(e,r),this)}async loadCollectionObject(e,r){return ve(await this.loadCollection(e,r),this)}wrapObject(e){return ve(this.get(e,{skipSelfReturn:!1}),this)}isWrapped(e){return On(e)}setMetaValue([e,r,i],n){this.dispatch(typeof n=="function"?$t.setMetaValueDynamic({id:e,meta:r,key:i,updateValue:n}):$t.setMetaValue({id:e,meta:r,key:i,value:n}))}};function En(){return typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{}}function wr(t){const e=En();try{const i=e.IIIF_VAULT;if(i)return i}catch{}const r=new gt(t);try{e.IIIF_VAULT=r}catch{}return r}const We=v.createContext({vault:null,setVaultInstance:t=>{}});function Sr({vault:t,vaultOptions:e,useGlobal:r,resources:i,children:n}){const[s,a]=v.useState(()=>t||(r?wr(e):e?new gt(e):new gt));return m.jsx(We.Provider,{value:{vault:s,setVaultInstance:a},children:m.jsx(ze,{value:i||{},children:n})})}const W=()=>{const{vault:t}=v.useContext(We);if(t===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return t};function Pn(t,{noCache:e=!1}={}){const r=typeof t=="string"?t:t.id,i=W(),[n,s]=v.useState(r),[a,o]=v.useState(void 0),u=v.useMemo(()=>i.get(r,{skipSelfReturn:!0})||void 0,[r,i]),[p,l]=v.useState(u);return v.useEffect(()=>{(async()=>{try{const h=u&&!e?u:await i.load(r),g=h?h.id||h["@id"]:null;h&&n!==g&&s(g),l(h)}catch(h){o(h)}})()},[r,e]),{isLoaded:!!p,id:n,requestId:r,error:a,resource:p,cached:!!(p&&p===u)}}function Ln(t,e){const{id:r,isLoaded:i,error:n,resource:s,requestId:a,cached:o}=Pn(t,e);return{id:r,isLoaded:i,error:n,manifest:s,requestId:a,cached:o}}function Fn({manifest:t,children:e}){return m.jsx(ze,{value:{manifest:t},children:e})}function Mt({canvas:t,children:e}){return m.jsx(ze,{value:{canvas:t},children:e})}function Q(t,e=[]){const r=W(),[i,n]=v.useState(()=>t(r.getState(),r));return v.useEffect(()=>r.subscribe(s=>t(s,r),s=>{n(s)},!1),e),i}const Qe=v.createContext([]);function Mr(){const t=v.useContext(Qe);return Q(e=>t.map(r=>e.iiif.entities.Canvas[r]).filter(Boolean),[t])}function Ce(t={},e=[]){const{id:r,selector:i}=t,n=Me();W();const s=r||n.manifest,a=Q(o=>s?o.iiif.entities.Manifest[s]:void 0,[s]);return v.useMemo(()=>{if(a)return i?i(a):a},[a,i,...e])}function $n({range:t,children:e}){return m.jsx(ze,{value:{range:t},children:e})}function Cr(t,e){var i;const r=[];for(const n of e.items)if(n.type==="SpecificResource"&&((i=n.source)==null?void 0:i.type)==="Canvas"&&(n.source.id.indexOf("#")!==-1?r.push({id:n.source.id.split("#")[0],type:"Canvas"}):r.push(n.source)),n.type==="Range"&&r.push(...Cr(t,t.get(n))),n.type==="SpecificResource"){const s=typeof n.source=="string"?n.source:n.source.id;r.push({id:s,type:"Canvas"})}return r}function Dn(t,e,{disablePaging:r,skipNonPaged:i}={}){const n=e.behavior,s=n.includes("paged"),a=s?!1:n.includes("continuous"),o=s||a?!1:n.includes("individuals"),u=e.type==="Manifest"?e.items:Cr(t,e);if(a)return[u,[u.map((d,x)=>x)]];if(o||!s||r)return[u,u.map((d,x)=>[x])];const p=[];let l=[];const h=()=>{l.length&&(p.push([...l]),l=[])};let g=0,b=!1;for(let d=0;d<u.length;d++){const x=t.get(u[d]);if(x.behavior.includes("non-paged")){d===g&&g++,i||(h(),p.push([d]),h());continue}if(d===g||x.behavior.includes("facing-pages")){l.length&&(b=!0),h(),p.push([d]),h();continue}if(l.push(d),b){h(),b=!1;continue}l.length>1&&h()}return l.length&&h(),[u,p]}function qn(t={},e=[]){const{id:r,selector:i}=t,n=Me(),s=r||n.range,a=Q(o=>s?o.iiif.entities.Range[s]:void 0,[s]);return v.useMemo(()=>{if(a)return i?i(a):a},[a,i,...e])}function _n({startCanvas:t,disablePaging:e}){var d;const r=W(),i=Ce(),n=qn(),[s,a]=v.useState(void 0),o=n||i;if(!o)throw new Error("Nothing selected");const[u,p]=v.useMemo(()=>Dn(r,o,{disablePaging:e}),[r,o]),l=v.useCallback(x=>{const w=p.findIndex(A=>A.includes(x));a(w===-1?0:w)},[u,p]),h=v.useCallback(x=>{const w=u.findIndex(A=>A.id===x);w!==-1?l(w):a(0)},[u,p]),g=v.useCallback(()=>{a(x=>x>=p.length?x:x+1)},[p]),b=v.useCallback(()=>{a(x=>x<=0?0:x-1)},[p]);return typeof s>"u"&&(t?h(t):a(0)),{visibleItems:((d=p[s])==null?void 0:d.map(x=>u[x].id))||[],cursor:s,items:u,sequence:p,setSequenceIndex:a,setCanvasIndex:l,setCanvasId:h,next:g,previous:b}}const Re=()=>{},Ye=v.createContext({setCurrentCanvasId:Re,setCurrentCanvasIndex:Re,nextCanvas:Re,previousCanvas:Re,items:[],sequence:[],setSequenceIndex:Re,currentSequenceIndex:0});function Un(t){const e=Ce(),{cursor:r,visibleItems:i,next:n,sequence:s,items:a,setCanvasIndex:o,setCanvasId:u,previous:p,setSequenceIndex:l}=_n({startCanvas:t.startCanvas,disablePaging:t.pagingEnabled===!1}),h=v.useMemo(()=>({sequence:s,items:a,setCurrentCanvasId:u,nextCanvas:n,previousCanvas:p,totalCanvases:a.length,setCurrentCanvasIndex:o,setSequenceIndex:l,currentSequenceIndex:r}),[s,a,u,n,p,a,o,l,r]);return e?m.jsx(Ye.Provider,{value:h,children:m.jsx(Qe.Provider,{value:i,children:m.jsx(Mt,{canvas:i[0],children:t.children})})}):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),m.jsx("div",{children:"Sorry, something went wrong."}))}function Vn(t){const e=Ln(t.manifest);if(!e)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),m.jsx("div",{children:"Sorry, something went wrong."});if(e.error)return m.jsx("div",{children:e.error.toString()});if(!e.isLoaded)return m.jsx("div",{children:"Loading..."});const r=m.jsx(Un,{...t,children:t.children});return m.jsx(Fn,{manifest:e.id,children:t.rangeId?m.jsx($n,{range:t.rangeId,children:r}):r})}function Hn(){return v.useContext(Ye)}function Nn(){return{VaultContext:v.useContext(We),ResourceContext:v.useContext(wt),SimpleViewerReactContext:v.useContext(Ye),VisibleCanvasReactContext:v.useContext(Qe)}}function Bn(t){return m.jsx(Sr,{vault:t.bridge.VaultContext.vault||void 0,resources:t.bridge.ResourceContext,children:m.jsx(Qe.Provider,{value:t.bridge.VisibleCanvasReactContext,children:m.jsx(Ye.Provider,{value:t.bridge.SimpleViewerReactContext,children:t.children})})})}const te=function(t){return function(){const e={type:t,getType:()=>t,toString:()=>t};return(r,i)=>({...e,...r!==void 0&&{payload:r},...i!==void 0&&{meta:i}})}},zn="@iiif/IMPORT_ENTITIES",Wn="@iiif/MODIFY_ENTITY_FIELD",Qn="@iiif/REORDER_ENTITY_FIELD",Yn="@iiif/ADD_REFERENCE",Gn="@iiif/UPDATE_REFERENCE",Jn="@iiif/REMOVE_REFERENCE",Kn="@iiif/ADD_METADATA",Zn="@iiif/REMOVE_METADATA",Xn="@iiif/UPDATE_METADATA",es="@iiif/REORDER_METADATA",ts=te(zn)(),rs=te(Wn)(),is=te(Qn)(),ns=te(Yn)(),ss=te(Jn)(),as=te(Gn)(),os=te(Kn)(),cs=te(Xn)(),us=te(Zn)(),ls=te(es)(),it={importEntities:ts,modifyEntityField:rs,reorderEntityField:is,addReference:ns,removeReference:ss,updateReference:as,addMetadata:os,removeMetadata:us,updateMetadata:cs,reorderMetadata:ls};function fs(){const e=W().getStore();return v.useMemo(()=>r=>e.dispatch(r),[e])}function Nt(t){return typeof t!="string"&&t&&t.bindToVault}function ps(){const t=W(),e=v.useRef([]),r=fs(),i=v.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);v.useLayoutEffect(()=>{const o={id:i,type:"AnnotationPage",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],rendering:[],service:[]};r(it.importEntities({entities:{AnnotationPage:{[o.id]:o}}}))},[i]);const n=Q(o=>i?o.iiif.entities.AnnotationPage[i]:null,[i]),s=v.useCallback((o,u)=>{if(i){if(Nt(o)){const h=o;h.__vault||h.bindToVault(t),o=typeof h.source=="string"?h.source:h.source.id,e.current[o]=h}else typeof o!="string"&&(o=o.id);const p=t.get({id:i,type:"AnnotationPage"}),l=t.get({id:o,type:"Annotation"});p&&l&&(p.items.find(h=>h.id===l.id)||r(it.addReference({id:i,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"},index:u})))}},[i]),a=v.useCallback(o=>{i&&(Nt(o)?o=typeof o.source=="string"?o.source:o.source.id:typeof o!="string"&&(o=o.id),e.current[o]&&e.current[o].beforeRemove(),t.get({id:i,type:"AnnotationPage"})&&r(it.removeReference({id:i,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"}})))},[i]);return[n,{addAnnotation:s,removeAnnotation:a}]}const Rr=v.createContext(null);function hs(){const t=v.useContext(Rr);return[t.fullPage,{addAnnotation:t.addAnnotation,removeAnnotation:t.removeAnnotation}]}function ds({children:t}){const[e,{addAnnotation:r,removeAnnotation:i}]=ps();return m.jsx(Rr.Provider,{value:v.useMemo(()=>({fullPage:e,addAnnotation:r,removeAnnotation:i}),[e]),children:t})}function ys({width:t,style:e,height:r,error:i,resetErrorBoundary:n}){return m.jsxs("div",{style:{width:t,height:r,minHeight:500,...e||{},background:"#f9f9f9"},children:[m.jsx("h3",{children:"Error occurred"}),m.jsx("p",{children:i.message}),m.jsx("button",{onClick:n,children:"Reset"})]})}const Ct=v.createContext(null);function vs(){return v.useContext(Ct)}const kr=v.createContext(()=>{}),Tr=v.createContext(()=>{});function Se(t,e,r,i,n=[]){const s=v.useContext(t==="portal"?Tr:kr);v.useEffect(()=>(t!=="none"&&s(e,r,i),()=>{s(e,null)}),[e,t,s,...n])}function fe(t={},e=[]){const{id:r,selector:i}=t,n=Me(),s=r||n.canvas,a=Q(o=>s?o.iiif.entities.Canvas[s]:void 0,[s]);return v.useMemo(()=>{if(a)return i?i(a):a},[a,i,...e])}const Ir=v.createContext(()=>{});function gs(t){const e=fe(),r=v.useContext(Ir);v.useEffect(()=>e&&e.id?(r(e.id,t),()=>r(e.id,-1)):()=>{},[e,t])}function ms({children:t,errorFallback:e,outerContainerProps:r={},worldScale:i,...n}){const[s,a]=v.useState(),o=Nn(),u=e||ys,[p,l]=v.useState({}),h=Object.entries(p),[g,b]=v.useState({}),d=Object.entries(g),[x,w]=v.useState({}),A=v.useMemo(()=>i||Math.max(...Object.values(x)),[x]),S=v.useMemo(()=>({maxOverZoom:A||1,...n.runtimeOptions||{}}),[A,n.runtimeOptions]),k=v.useCallback((T,P)=>{w(E=>{if(P===-1){const{[T]:C,...$}=E;return $}return{...E,[T]:P}})},[]),O=v.useCallback((T,P,E)=>{l(({[T]:C,...$})=>P?{...$,[T]:{element:P,props:E}}:$)},[]),F=v.useCallback((T,P,E)=>{b(({[T]:C,...$})=>P?{...$,[T]:{element:P,props:E}}:$)},[]);return m.jsxs(qi,{resetKeys:[],fallbackRender:T=>m.jsx(u,{...n,...T}),children:[m.jsx(we.AtlasAuto,{...n,containerProps:{style:{position:"relative"},...n.containerProps||{}},htmlChildren:m.jsx(m.Fragment,{children:h.map(([T,{element:P,props:E}])=>m.jsx(v.Fragment,{children:m.jsx(P,{...E||{}})},T))}),onCreated:T=>{a(T),n.onCreated&&n.onCreated(T)},runtimeOptions:S,children:m.jsx(Ct.Provider,{value:s,children:m.jsx(Ir.Provider,{value:k,children:m.jsx(kr.Provider,{value:O,children:m.jsx(Tr.Provider,{value:F,children:m.jsx(Bn,{bridge:o,children:m.jsx(we.ModeContext.Provider,{value:n.mode||"explore",children:m.jsx(ds,{children:t})})})})})})})}),m.jsx("div",{children:d.map(([T,{element:P,props:E}])=>m.jsx(v.Fragment,{children:m.jsx(P,{...E||{}})},T))})]})}const $e={},jr={get(t){return t},setMetaValue([t,e,r],i){const n=jr.getResourceMeta(t,e),s=n?n[r]:void 0,a=typeof i=="function"?i(s):i;$e[t]={...$e[t]||{},[e]:{...($e[t]||{})[e]||{},[r]:a}}},getResourceMeta:(t,e)=>{const r=$e[t];if(r)return e?r[e]:r}};function xs(t=jr){return{addEventListener(e,r,i,n){if(e)return t.setMetaValue([e.id,"eventManager",r],s=>{const a=s||[];for(const o of a)if(o.callback===i)return a;return[...a,{callback:i,scope:n}]}),i},removeEventListener(e,r,i){e&&t.setMetaValue([e.id,"eventManager",r],n=>(n||[]).filter(s=>s.callback!==i))},getListenersAsProps(e,r){const i=typeof e=="string"?{id:e}:e;if(!i||!i.id)return{};const n=t.getResourceMeta(i.id,"eventManager"),s={};if(n&&i)for(const a of Object.keys(n))s[a]=o=>{const u=t.get(i);for(const{callback:p,scope:l}of n[a]||[])(!l||r&&l.indexOf(r)!==-1)&&p(o,u)};return s}}}function Or(t,e){const r=W(),i=v.useMemo(()=>xs(r),[r]),n=Q(()=>t&&t.id?r.getResourceMeta(t.id,"eventManager"):null,[t]);return v.useMemo(()=>t?i.getListenersAsProps(t,e):{},[n,t,r,e])}const De={},Er={get(t){return t},setMetaValue([t,e,r],i){const n=Er.getResourceMeta(t,e),s=n?n[r]:void 0,a=typeof i=="function"?i(s):i;De[t]={...De[t]||{},[e]:{...(De[t]||{})[e]||{},[r]:a}}},getResourceMeta:(t,e)=>{const r=De[t];if(r)return e?r[e]:r}};function Pr(t=Er){return{applyStyles(e,r,i){const n=typeof e=="string"?e:e.id;return t.setMetaValue([n,"styles",r],i)},getAppliedStyles(e){const r=typeof e=="string"?e:e.id;return t.getResourceMeta(r,"styles")}}}function Be(t,e){const r=W(),i=v.useMemo(()=>Pr(r),[r]);return Q(()=>{if(!t)return null;const n=i.getAppliedStyles(t.id);return n?e?n[e]:n:void 0},[t,e])}var bs=Object.defineProperty,As=(t,e,r)=>e in t?bs(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ue=(t,e,r)=>(As(t,typeof e!="symbol"?e+"":e,r),r),ws=function(){function t(e,r){var i=[],n=!0,s=!1,a=void 0;try{for(var o=e[Symbol.iterator](),u;!(n=(u=o.next()).done)&&(i.push(u.value),!(r&&i.length===r));n=!0);}catch(p){s=!0,a=p}finally{try{!n&&o.return&&o.return()}finally{if(s)throw a}}return i}return function(e,r){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),Te=Math.PI*2,nt=function(t,e,r,i,n,s,a){var o=t.x,u=t.y;o*=e,u*=r;var p=i*o-n*u,l=n*o+i*u;return{x:p+s,y:l+a}},Ss=function(t,e){var r=e===1.5707963267948966?.551915024494:e===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(e/4),i=Math.cos(t),n=Math.sin(t),s=Math.cos(t+e),a=Math.sin(t+e);return[{x:i-n*r,y:n+i*r},{x:s+a*r,y:a-s*r},{x:s,y:a}]},Bt=function(t,e,r,i){var n=t*i-e*r<0?-1:1,s=t*r+e*i;return s>1&&(s=1),s<-1&&(s=-1),n*Math.acos(s)},Ms=function(t,e,r,i,n,s,a,o,u,p,l,h){var g=Math.pow(n,2),b=Math.pow(s,2),d=Math.pow(l,2),x=Math.pow(h,2),w=g*b-g*x-b*d;w<0&&(w=0),w/=g*x+b*d,w=Math.sqrt(w)*(a===o?-1:1);var A=w*n/s*h,S=w*-s/n*l,k=p*A-u*S+(t+r)/2,O=u*A+p*S+(e+i)/2,F=(l-A)/n,T=(h-S)/s,P=(-l-A)/n,E=(-h-S)/s,C=Bt(1,0,F,T),$=Bt(F,T,P,E);return o===0&&$>0&&($-=Te),o===1&&$<0&&($+=Te),[k,O,C,$]},Cs=function(t){var e=t.px,r=t.py,i=t.cx,n=t.cy,s=t.rx,a=t.ry,o=t.xAxisRotation,u=o===void 0?0:o,p=t.largeArcFlag,l=p===void 0?0:p,h=t.sweepFlag,g=h===void 0?0:h,b=[];if(s===0||a===0)return[];var d=Math.sin(u*Te/360),x=Math.cos(u*Te/360),w=x*(e-i)/2+d*(r-n)/2,A=-d*(e-i)/2+x*(r-n)/2;if(w===0&&A===0)return[];s=Math.abs(s),a=Math.abs(a);var S=Math.pow(w,2)/Math.pow(s,2)+Math.pow(A,2)/Math.pow(a,2);S>1&&(s*=Math.sqrt(S),a*=Math.sqrt(S));var k=Ms(e,r,i,n,s,a,l,g,d,x,w,A),O=ws(k,4),F=O[0],T=O[1],P=O[2],E=O[3],C=Math.abs(E)/(Te/4);Math.abs(1-C)<1e-7&&(C=1);var $=Math.max(Math.ceil(C),1);E/=$;for(var X=0;X<$;X++)b.push(Ss(P,E)),P+=E;return b.map(function(Y){var _=nt(Y[0],s,a,x,d,F,T),U=_.x,J=_.y,ee=nt(Y[1],s,a,x,d,F,T),he=ee.x,j=ee.y,V=nt(Y[2],s,a,x,d,F,T),G=V.x,oe=V.y;return{x1:U,y1:J,x2:he,y2:j,x:G,y:oe}})};function Lr(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Rs=Ts,st={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},ks=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function Ts(t){var e=[];return t.replace(ks,function(r,i,n){var s=i.toLowerCase();for(n=js(n),s=="m"&&n.length>2&&(e.push([i].concat(n.splice(0,2))),s="l",i=i=="m"?"l":"L");;){if(n.length==st[s])return n.unshift(i),e.push(n);if(n.length<st[s])throw new Error("malformed path data");e.push([i].concat(n.splice(0,st[s])))}}),e}var Is=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function js(t){var e=t.match(Is);return e?e.map(Number):[]}const Os=Lr(Rs);var Es=Ps;function Ps(t){var e=0,r=0,i=0,n=0;return t.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]+=i,s[7]+=n;break;case"v":s[1]+=n;break;case"h":s[1]+=i;break;default:for(var u=1;u<s.length;)s[u++]+=i,s[u++]+=n}switch(o){case"Z":i=e,n=r;break;case"H":i=s[1];break;case"V":n=s[1];break;case"M":i=e=s[1],n=r=s[2];break;default:i=s[s.length-2],n=s[s.length-1]}return s})}const Ls=Lr(Es);function Fs(t){const e=Os(t),r=Ls(e);let i,n=0,s=0,a=0,o=0,u,p,l=0,h=0;const g=[];for(let b=0;b<r.length;b++){let d=r[b];const x=d[0];switch(x){case"M":n=d[1],s=d[2];break;case"H":d=["L",d[1],s];break;case"V":d=["L",n,d[1]];break;case"S":{let w=l,A=h;(i==="C"||i=="S")&&(w+=w-a,A+=A-o),d=["C",w,A,d[1],d[2],d[3],d[4]]}break;case"T":i==="Q"||i=="T"?(u=l*2-u,p=h*2-p):(u=l,p=h),d=["Q",u,p,d[1],d[2]];break;case"Q":u=d[1],p=d[2];break;case"A":{const w=Cs({px:l,py:h,cx:d[6],cy:d[7],rx:d[1],ry:d[2],xAxisRotation:d[3],largeArcFlag:d[4],sweepFlag:d[5]});if(!w.length)continue;for(const[A,S]of w.entries())d=["C",S.x1,S.y1,S.x2,S.y2,S.x,S.y],A<w.length-1&&g.push(d);d=d}break;case"Z":d=["L",n,s];break}i=x,l=d[d.length-2],h=d[d.length-1],["C","Q","A"].indexOf(x)>-1?(a=d[d.length-4],o=d[d.length-3]):(a=l,o=h),g.push(d)}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 Fs(t,e,r,i=1){return new Fr(t,e,r).subdivide(i)}function $s(t,e,r,i,n=1){return new Ct(new Float64Array([t.x,t.y,e.x,e.y,r.x,r.y,i.x,i.y])).subdivide(n)}function Ds(t){return t.x*t.x+t.y*t.y}function Ie(t){return t/(1-.67+Math.pow(Math.pow(.67,4)+.25*t*t,.25))}function be(t){return t*(1-.39+Math.sqrt(.39*.39+.25*t*t))}class Fr{constructor(e,r,i){Ue(this,"start"),Ue(this,"control"),Ue(this,"end"),this.start=e,this.control=r,this.end=i}eval(e){const r=1-e;return{x:this.start.x*r*r+2*this.control.x*r*e+this.end.x*e*e,y:this.start.y*r*r+2*this.control.y*r*e+this.end.y*e*e}}mapToBasic(){const{x:e,y:r}=this.start,{x:i,y:n}=this.control,{x:s,y:a}=this.end,o=2*i-e-s,u=2*n-r-a,h=(i-e)*o+(n-r)*u,l=(s-i)*o+(a-n)*u,p=(s-e)*u-(a-r)*o,g=h/p,b=l/p,d=Math.abs(p)/(Math.hypot(o,u)*Math.abs(b-g));return{x0:e,x2:s,scale:d,cross:p}}subdivide(e){const r=this.mapToBasic(),i=Ie(r.x0),n=Ie(r.x2),s=.5*Math.abs(n-i)*Math.sqrt(r.scale/e),a=Math.ceil(s),o=be(i),u=be(n),h=[0];for(let l=1;l<a;l++){const p=(be(i+(n-i)*l/a)-o)/(u-o);h.push(p)}return h.push(1),h.map(l=>this.eval(l))}}class Ct{constructor(e){Ue(this,"c"),this.c=e}weightsum(e,r,i,n){const s=e*this.c[0]+r*this.c[2]+i*this.c[4]+n*this.c[6],a=e*this.c[1]+r*this.c[3]+i*this.c[5]+n*this.c[7];return{x:s,y:a}}eval(e){const r=1-e,i=r*r*r,n=3*r*r*e,s=3*r*e*e,a=e*e*e;return this.weightsum(i,n,s,a)}deriv(e){const r=1-e,i=-3*r*r,n=3*e*e,s=-6*e*r-i,a=6*e*r-n;return this.weightsum(i,s,a,n)}midpoint_quadbez(){const e=this.weightsum(-.25,.75,.75,-.25);return new Fr({x:this.c[0],y:this.c[1]},e,{x:this.c[6],y:this.c[7]})}subsegment(e,r){const i=new Float64Array(8),n=this.eval(e),s=this.eval(r);i[0]=n.x,i[1]=n.y;const a=(r-e)/3,o=this.deriv(e);i[2]=n.x+a*o.x,i[3]=n.y+a*o.y;const u=this.deriv(r);return i[4]=s.x-a*u.x,i[5]=s.y-a*u.y,i[6]=s.x,i[7]=s.y,new Ct(i)}subdivide(e){const r=.1*e,i=e-r,n=Math.sqrt(i),s=Ds(this.weightsum(1,-3,3,-1)),a=Math.ceil(Math.pow(s/(432*r*r),1/6)),o=[];let u=0;for(let d=0;d<a;d++){const x=d/a,w=(d+1)/a,A=this.subsegment(x,w).midpoint_quadbez(),S=A.mapToBasic(),k=Ie(S.x0),O=Ie(S.x2),F=Math.sqrt(S.scale);let T=Math.abs(O-k)*F;if(Math.sign(S.x0)!=Math.sign(S.x2)){const P=n/F,E=n*Math.abs(O-k)/Ie(P);T=Math.max(T,E)}o.push({quad:A,a0:k,a2:O,val:T}),u+=T}const h=.5*u/n,l=Math.ceil(h),p=[{x:this.c[0],y:this.c[1]}];let g=0,b=0;for(let d=1;d<l;d++){const x=u*d/l;for(;g+o[b].val<x;)g+=o[b].val,b++;const w=o[b].a0,A=o[b].a2,S=be(w),k=be(A),O=w+(A-w)*(x-g)/o[b].val,F=(be(O)-S)/(k-S);p.push(o[b].quad.eval(F))}return p.push({x:this.c[6],y:this.c[7]}),p}}const qs=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,_s=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,Bt=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function Ve(t,{domParser:e,svgPreprocessor:r,iiifRenderingHints:i}={}){if(Array.isArray(t))return K(t.reduce((n,s)=>{const{selector:a,selectors:o,iiifRenderingHints:u}=Ve(s,{domParser:e,svgPreprocessor:r,iiifRenderingHints:i});return a&&(n.selector||(n.selector=a),n.selectors.push(...o)),u&&(n.iiifRenderingHints=n.iiifRenderingHints||{type:"ImageApiSelector"},Object.assign(n.iiifRenderingHints,u)),n},{selector:null,selectors:[],iiifRenderingHints:i}));if(!t)return K({selector:null,selectors:[],iiifRenderingHints:i});if(typeof t=="string"){const[n,s]=t.split("#");return s?Ve({type:"FragmentSelector",value:s},{svgPreprocessor:r,iiifRenderingHints:i,domParser:e}):K({selector:null,selectors:[],iiifRenderingHints:i})}if(t.type&&t.type==="PointSelector"&&(t.t||t.t===0)){const n={type:"TemporalSelector",temporal:{startTime:t.t}};return K({selector:n,selectors:[n],iiifRenderingHints:i})}if(Ns(t)){const n=[];if(t.region){const s=Ve({type:"FragmentSelector",value:"xywh="+t.region},{domParser:e,svgPreprocessor:r,iiifRenderingHints:i});n.push(...s.selectors)}return K({selector:n[0],selectors:n,iiifRenderingHints:i?{...i,...t}:t})}if(t.type==="FragmentSelector"){const n=qs.exec(t.value);if(n){const a={type:"BoxSelector",spatial:{unit:n[2]==="percent:"||n[2]==="pct:"?"percent":"pixel",x:parseFloat(n[3]),y:parseFloat(n[4]),width:parseFloat(n[5]),height:parseFloat(n[6])}};return K({selector:a,selectors:[a],iiifRenderingHints:i})}const s=t.value.match(_s);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:i})}return K({selector:null,selectors:[],iiifRenderingHints:i})}if(t.type==="SvgSelector"&&"value"in t){e||(typeof window<"u"?e=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 n=[],s,a,o=(r==null?void 0:r(t.value))??t.value,u;if(e){const l=e.parseFromString(t.value,"image/svg+xml").querySelector("svg");if(!l)return console.warn(`Illegal SVG selector: ${t.value}`),K({selector:null,selectors:[],iiifRenderingHints:i});const p=$r(l);p&&(n=p.points,u=p.shapeType,s=[Math.min(...n.map(g=>g[0])),Math.min(...n.map(g=>g[1])),Math.max(...n.map(g=>g[0])),Math.max(...n.map(g=>g[1]))],{style:a,svg:o}=Hs(p.element)??{svg:o})}const h={type:"SvgSelector",svg:o,svgShape:u,style:a,points:n.length?n: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:h,selectors:[h],iiifRenderingHints:i})}return K({selector:null,selectors:[],iiifRenderingHints:i})}function Us(t){const e=t.map(i=>i[0]).reduce((i,n)=>(i[n]+=1,i),{C:0,Q:0,L:0,M:0}),r=new Set(t.map(i=>i[0]));if(e.C>0||e.Q>0)return"path";if(e.L>0&&(r.size===1||r.size===2&&r.has("M"))){if(e.L===4)return"rect";const i=t.slice(-1)[0];return t[0][0]==="M"&&i[0]==="L"&&i[1]==t[0][1]&&i[2]===t[0][2]||i[1]===0&&i[2]===0?"polygon":"polyline"}return"path"}function $r(t){var e;for(const r of Array.from(t.children))switch(r==null?void 0:r.tagName.toLowerCase()){case"g":{const i=$r(r);if(i)return i}continue;case"path":{const i=r.getAttribute("d");if(!i)continue;const n=Ls(i);return{element:r,points:Vs(n),shapeType:Us(n)}}case"circle":{const i=parseFloat(r.getAttribute("cx")??"0"),n=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([i+s*Math.cos(u),n+s*Math.sin(u)])}return{element:r,points:a,shapeType:"circle"}}case"ellipse":{const i=parseFloat(r.getAttribute("cx")??"0"),n=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 h=Math.tan(u/360*Math.PI),l=s*(1-h**2)/(1+h**2),p=a*2*h/(1+h**2);o.push([i+l,n+p])}return{element:r,points:o,shapeType:"ellipse"}}case"line":{const i=parseFloat(r.getAttribute("x0")??"0"),n=parseFloat(r.getAttribute("y0")??"0"),s=parseFloat(r.getAttribute("x1")??"0"),a=parseFloat(r.getAttribute("y1")??"0");if(i===s&&n===a)continue;return{element:r,points:[[i,n],[s,a]],shapeType:"polyline"}}case"polygon":case"polyline":{const i=((e=r.getAttribute("points"))==null?void 0:e.split(" ").map(s=>s.split(",").map(parseFloat)))??[];if(!i.length)continue;let n="polyline";return r.tagName.toLowerCase()==="polygon"&&(i.push(i[0]),n="polygon"),{element:r,points:i,shapeType:n}}case"rect":{const i=parseFloat(r.getAttribute("x")??"0"),n=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:[[i,n],[i+s,n],[i+s,n+a],[i,n+a],[i,n]],shapeType:"rect"}}default:continue}return null}function Vs(t){const e=[];for(let r=0;r<t.length;r++){const i=e[e.length-1]??[0,0],n=t[r];switch(n[0]){case"M":case"L":e.push([n[1],n[2]]);continue;case"C":e.push(...$s({x:i[0],y:i[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]},{x:n[5],y:n[6]}).map(s=>[s.x,s.y]).slice(1));continue;case"Q":e.push(...Fs({x:i[0],y:i[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]}).map(s=>[s.x,s.y]).slice(1));continue}}return e}function Hs(t){const e={};if(t.hasAttribute("fill")?(e.fill=t.getAttribute("fill"),t.removeAttribute("fill")):t.style.fill&&(e.fill=t.style.fill),e.fill){const i=Bt.exec(e.fill);i&&(e.fillOpacity=parseFloat(i[4]),e.fill=`rgb(${i[1]}, ${i[2]}, ${i[3]})`)}if(t.hasAttribute("fill-opacity")?(e.fillOpacity=parseFloat(t.getAttribute("fill-opacity")),t.removeAttribute("fill-opacity")):t.style.fillOpacity&&(e.fillOpacity=parseFloat(t.style.fillOpacity)),t.hasAttribute("stroke")?(e.stroke=t.getAttribute("stroke"),t.removeAttribute("stroke")):t.style.stroke&&(e.stroke=t.style.stroke),e.stroke){const i=Bt.exec(e.stroke);i&&(e.strokeOpacity=parseFloat(i[4]),e.stroke=`rgb(${i[1]}, ${i[2]}, ${i[3]})`)}t.hasAttribute("stroke-opacity")?(e.strokeOpacity=parseFloat(t.getAttribute("stroke-opacity")),t.removeAttribute("stroke-opacity")):t.style.strokeOpacity&&(e.strokeOpacity=parseFloat(t.style.strokeOpacity)),t.hasAttribute("stroke-width")?(e.strokeWidth=t.getAttribute("stroke-width"),t.removeAttribute("stroke-width")):t.style.strokeWidth&&(e.strokeWidth=t.style.strokeWidth),t.hasAttribute("stroke-dasharray")?(e.strokeDasharray=t.getAttribute("stroke-dasharray"),t.removeAttribute("stroke-dasharray")):t.style.strokeDasharray&&(e.strokeDasharray=t.style.strokeDasharray);let r=t;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(e).length>0?e:void 0}}function Ns(t){return!!t&&t.type==="iiif:ImageApiSelector"&&t.type==="iiif:ImageApiSelector"}function K(t){if(t.iiifRenderingHints){const e=t.iiifRenderingHints;if(e.rotation){const r=Bs(e.rotation);if(r)if(t.selectors.length)for(const i of t.selectors)i.rotation=r;else t.selectors.push({type:"RotationSelector",rotation:r})}}else delete t.iiifRenderingHints;return t}function Bs(t){let e=parseFloat(t);return e&&t.startsWith("!")&&(e=360-e),e&&(e=e%360),e!==e?0:e||0}function ge(t,e={}){if(Array.isArray(t))return ge(t[0]);if(typeof t=="string"){const[r,i]=t.split("#");return i?ge({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:i}}):{type:"SpecificResource",source:{id:r,type:e.typeMap&&e.typeMap[r]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return ge(t.items[0]);if(t.type==="SpecificResource"){t.source.type==="Canvas"&&t.source.partOf&&typeof t.source.partOf=="string"&&(t.source.partOf=[{id:t.source.partOf,type:"Manifest"}]);const{selector:r,selectors:i}=t.selector?Ve(t.selector,e):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:r,selectors:i}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[r,i]=t.id.split("#");return i?ge({type:"SpecificResource",source:{...t,id:r},selector:{type:"FragmentSelector",value:i}}):{type:"SpecificResource",source:{...t,id:r},selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}function Dr(t={},e=[]){const{id:r,selector:i}=t,n=Me(),s=W(),a=r||n.annotation,o=Q(h=>a?h.iiif.entities.Annotation[a]:void 0,[a]),u=Q(h=>o&&o.body?o.body.map(l=>l?l.type==="SpecificResource"?{...l,source:s.get(l)}:l?h.iiif.entities[l.type][l.id]:null:null).filter(Boolean):[],[o]);return v.useMemo(()=>{if(!o)return;const h={...o,body:u,target:ge(o.target,{typeMap:s.getState().iiif.mapping})};return i?i(h):h},[o,i,u,...e])}const qr=({id:t,style:e,className:r,interactive:i})=>{const n=Dr({id:t}),s=Be(n,"atlas"),a=Be(n,"html"),o=Or(n,["atlas"]),u=fe(),h=v.useMemo(()=>we.mergeStyles(e,s),[e,s]);return u&&n&&n.target&&n.target.selector&&n.target.selector.type==="BoxSelector"&&n.target.source&&(n.target.source.id===u.id||n.target.source===u.id)?m.jsx(we.RegionHighlight,{id:n.id,isEditing:!0,region:n.target.selector.spatial,style:h,className:(a==null?void 0:a.className)||r,interactive:!!(a!=null&&a.href||i),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 zs(t={},e=[]){const{id:r,selector:i}=t,n=Me(),s=r||n.annotationPage,a=Q(o=>s?o.iiif.entities.AnnotationPage[s]:void 0,[s]);return v.useMemo(()=>{if(a)return i?i(a):a},[a,...e])}const gt=({className:t,page:e})=>{var s;const r=zs({id:e.id})||e,i=Be(r,"atlas"),n=Be(r,"html");return Q(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(qr,{id:a.id,style:i,className:(n==null?void 0:n.className)||t},a.id))})};function _r({id:t,image:e,thumbnail:r,isStatic:i,x:n=0,y:s=0,children:a,selector:o,onClick:u,enableSizes:h}){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:n+e.target.spatial.x,y:s+e.target.spatial.y,width:e.target.spatial.width,height:e.target.spatial.height,onClick:u,children:e.service?m.jsxs(v.Fragment,{children:[m.jsx(we.TileSet,{tiles:{id:e.service.id||e.service["@id"]||"unknown",height:e.height,width:e.width,imageService:e.service,thumbnail:r&&r.type==="fixed"?r:void 0},enableSizes:h,x:0,y:0,width:(p=e.target)==null?void 0:p.spatial.width,height:(g=e.target)==null?void 0:g.spatial.height,crop:l}),a]},"service"):m.jsxs(v.Fragment,{children:[m.jsx("world-image",{onClick:u,uri:e.id,target:{x:0,y:0,width:e.target.spatial.width,height:e.target.spatial.height},display:e.width&&e.height?{width:e.width,height:e.height}:void 0,crop:l}),a]},"no-service")},t+(e.service?"server":"no-service"))}var Ws=Object.defineProperty,Qs=(t,e,r)=>e in t?Ws(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,He=(t,e,r)=>(Qs(t,typeof e!="symbol"?e+"":e,r),r),Ys=function(){function t(e,r){var i=[],n=!0,s=!1,a=void 0;try{for(var o=e[Symbol.iterator](),u;!(n=(u=o.next()).done)&&(i.push(u.value),!(r&&i.length===r));n=!0);}catch(h){s=!0,a=h}finally{try{!n&&o.return&&o.return()}finally{if(s)throw a}}return i}return function(e,r){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),je=Math.PI*2,at=function(t,e,r,i,n,s,a){var o=t.x,u=t.y;o*=e,u*=r;var h=i*o-n*u,l=n*o+i*u;return{x:h+s,y:l+a}},Gs=function(t,e){var r=e===1.5707963267948966?.551915024494:e===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(e/4),i=Math.cos(t),n=Math.sin(t),s=Math.cos(t+e),a=Math.sin(t+e);return[{x:i-n*r,y:n+i*r},{x:s+a*r,y:a-s*r},{x:s,y:a}]},zt=function(t,e,r,i){var n=t*i-e*r<0?-1:1,s=t*r+e*i;return s>1&&(s=1),s<-1&&(s=-1),n*Math.acos(s)},Js=function(t,e,r,i,n,s,a,o,u,h,l,p){var g=Math.pow(n,2),b=Math.pow(s,2),d=Math.pow(l,2),x=Math.pow(p,2),w=g*b-g*x-b*d;w<0&&(w=0),w/=g*x+b*d,w=Math.sqrt(w)*(a===o?-1:1);var A=w*n/s*p,S=w*-s/n*l,k=h*A-u*S+(t+r)/2,O=u*A+h*S+(e+i)/2,F=(l-A)/n,T=(p-S)/s,P=(-l-A)/n,E=(-p-S)/s,C=zt(1,0,F,T),$=zt(F,T,P,E);return o===0&&$>0&&($-=je),o===1&&$<0&&($+=je),[k,O,C,$]},Ks=function(t){var e=t.px,r=t.py,i=t.cx,n=t.cy,s=t.rx,a=t.ry,o=t.xAxisRotation,u=o===void 0?0:o,h=t.largeArcFlag,l=h===void 0?0:h,p=t.sweepFlag,g=p===void 0?0:p,b=[];if(s===0||a===0)return[];var d=Math.sin(u*je/360),x=Math.cos(u*je/360),w=x*(e-i)/2+d*(r-n)/2,A=-d*(e-i)/2+x*(r-n)/2;if(w===0&&A===0)return[];s=Math.abs(s),a=Math.abs(a);var S=Math.pow(w,2)/Math.pow(s,2)+Math.pow(A,2)/Math.pow(a,2);S>1&&(s*=Math.sqrt(S),a*=Math.sqrt(S));var k=Js(e,r,i,n,s,a,l,g,d,x,w,A),O=Ys(k,4),F=O[0],T=O[1],P=O[2],E=O[3],C=Math.abs(E)/(je/4);Math.abs(1-C)<1e-7&&(C=1);var $=Math.max(Math.ceil(C),1);E/=$;for(var X=0;X<$;X++)b.push(Gs(P,E)),P+=E;return b.map(function(Y){var _=at(Y[0],s,a,x,d,F,T),U=_.x,J=_.y,ee=at(Y[1],s,a,x,d,F,T),he=ee.x,j=ee.y,V=at(Y[2],s,a,x,d,F,T),G=V.x,oe=V.y;return{x1:U,y1:J,x2:he,y2:j,x:G,y:oe}})},Zs=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ur(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Xs=ta,ot={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},ea=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function ta(t){var e=[];return t.replace(ea,function(r,i,n){var s=i.toLowerCase();for(n=ia(n),s=="m"&&n.length>2&&(e.push([i].concat(n.splice(0,2))),s="l",i=i=="m"?"l":"L");;){if(n.length==ot[s])return n.unshift(i),e.push(n);if(n.length<ot[s])throw new Error("malformed path data");e.push([i].concat(n.splice(0,ot[s])))}}),e}var ra=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function ia(t){var e=t.match(ra);return e?e.map(Number):[]}const na=Ur(Xs);var sa=aa;function aa(t){var e=0,r=0,i=0,n=0;return t.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]+=i,s[7]+=n;break;case"v":s[1]+=n;break;case"h":s[1]+=i;break;default:for(var u=1;u<s.length;)s[u++]+=i,s[u++]+=n}switch(o){case"Z":i=e,n=r;break;case"H":i=s[1];break;case"V":n=s[1];break;case"M":i=e=s[1],n=r=s[2];break;default:i=s[s.length-2],n=s[s.length-1]}return s})}const oa=Ur(sa);function ca(t){const e=na(t),r=oa(e);let i,n=0,s=0,a=0,o=0,u,h,l=0,p=0;const g=[];for(let b=0;b<r.length;b++){let d=r[b];const x=d[0];switch(x){case"M":n=d[1],s=d[2];break;case"H":d=["L",d[1],s];break;case"V":d=["L",n,d[1]];break;case"S":{let w=l,A=p;(i==="C"||i=="S")&&(w+=w-a,A+=A-o),d=["C",w,A,d[1],d[2],d[3],d[4]]}break;case"T":i==="Q"||i=="T"?(u=l*2-u,h=p*2-h):(u=l,h=p),d=["Q",u,h,d[1],d[2]];break;case"Q":u=d[1],h=d[2];break;case"A":{const w=Ks({px:l,py:p,cx:d[6],cy:d[7],rx:d[1],ry:d[2],xAxisRotation:d[3],largeArcFlag:d[4],sweepFlag:d[5]});if(!w.length)continue;for(const[A,S]of w.entries())d=["C",S.x1,S.y1,S.x2,S.y2,S.x,S.y],A<w.length-1&&g.push(d);d=d}break;case"Z":d=["L",n,s];break}i=x,l=d[d.length-2],p=d[d.length-1],["C","Q","A"].indexOf(x)>-1?(a=d[d.length-4],o=d[d.length-3]):(a=l,o=p),g.push(d)}return g}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
35
+ */function $s(t,e,r,i=1){return new Fr(t,e,r).subdivide(i)}function Ds(t,e,r,i,n=1){return new Rt(new Float64Array([t.x,t.y,e.x,e.y,r.x,r.y,i.x,i.y])).subdivide(n)}function qs(t){return t.x*t.x+t.y*t.y}function Ie(t){return t/(1-.67+Math.pow(Math.pow(.67,4)+.25*t*t,.25))}function be(t){return t*(1-.39+Math.sqrt(.39*.39+.25*t*t))}class Fr{constructor(e,r,i){Ue(this,"start"),Ue(this,"control"),Ue(this,"end"),this.start=e,this.control=r,this.end=i}eval(e){const r=1-e;return{x:this.start.x*r*r+2*this.control.x*r*e+this.end.x*e*e,y:this.start.y*r*r+2*this.control.y*r*e+this.end.y*e*e}}mapToBasic(){const{x:e,y:r}=this.start,{x:i,y:n}=this.control,{x:s,y:a}=this.end,o=2*i-e-s,u=2*n-r-a,p=(i-e)*o+(n-r)*u,l=(s-i)*o+(a-n)*u,h=(s-e)*u-(a-r)*o,g=p/h,b=l/h,d=Math.abs(h)/(Math.hypot(o,u)*Math.abs(b-g));return{x0:e,x2:s,scale:d,cross:h}}subdivide(e){const r=this.mapToBasic(),i=Ie(r.x0),n=Ie(r.x2),s=.5*Math.abs(n-i)*Math.sqrt(r.scale/e),a=Math.ceil(s),o=be(i),u=be(n),p=[0];for(let l=1;l<a;l++){const h=(be(i+(n-i)*l/a)-o)/(u-o);p.push(h)}return p.push(1),p.map(l=>this.eval(l))}}class Rt{constructor(e){Ue(this,"c"),this.c=e}weightsum(e,r,i,n){const s=e*this.c[0]+r*this.c[2]+i*this.c[4]+n*this.c[6],a=e*this.c[1]+r*this.c[3]+i*this.c[5]+n*this.c[7];return{x:s,y:a}}eval(e){const r=1-e,i=r*r*r,n=3*r*r*e,s=3*r*e*e,a=e*e*e;return this.weightsum(i,n,s,a)}deriv(e){const r=1-e,i=-3*r*r,n=3*e*e,s=-6*e*r-i,a=6*e*r-n;return this.weightsum(i,s,a,n)}midpoint_quadbez(){const e=this.weightsum(-.25,.75,.75,-.25);return new Fr({x:this.c[0],y:this.c[1]},e,{x:this.c[6],y:this.c[7]})}subsegment(e,r){const i=new Float64Array(8),n=this.eval(e),s=this.eval(r);i[0]=n.x,i[1]=n.y;const a=(r-e)/3,o=this.deriv(e);i[2]=n.x+a*o.x,i[3]=n.y+a*o.y;const u=this.deriv(r);return i[4]=s.x-a*u.x,i[5]=s.y-a*u.y,i[6]=s.x,i[7]=s.y,new Rt(i)}subdivide(e){const r=.1*e,i=e-r,n=Math.sqrt(i),s=qs(this.weightsum(1,-3,3,-1)),a=Math.ceil(Math.pow(s/(432*r*r),1/6)),o=[];let u=0;for(let d=0;d<a;d++){const x=d/a,w=(d+1)/a,A=this.subsegment(x,w).midpoint_quadbez(),S=A.mapToBasic(),k=Ie(S.x0),O=Ie(S.x2),F=Math.sqrt(S.scale);let T=Math.abs(O-k)*F;if(Math.sign(S.x0)!=Math.sign(S.x2)){const P=n/F,E=n*Math.abs(O-k)/Ie(P);T=Math.max(T,E)}o.push({quad:A,a0:k,a2:O,val:T}),u+=T}const p=.5*u/n,l=Math.ceil(p),h=[{x:this.c[0],y:this.c[1]}];let g=0,b=0;for(let d=1;d<l;d++){const x=u*d/l;for(;g+o[b].val<x;)g+=o[b].val,b++;const w=o[b].a0,A=o[b].a2,S=be(w),k=be(A),O=w+(A-w)*(x-g)/o[b].val,F=(be(O)-S)/(k-S);h.push(o[b].quad.eval(F))}return h.push({x:this.c[6],y:this.c[7]}),h}}const _s=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,Us=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,zt=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function Ve(t,{domParser:e,svgPreprocessor:r,iiifRenderingHints:i}={}){if(Array.isArray(t))return K(t.reduce((n,s)=>{const{selector:a,selectors:o,iiifRenderingHints:u}=Ve(s,{domParser:e,svgPreprocessor:r,iiifRenderingHints:i});return a&&(n.selector||(n.selector=a),n.selectors.push(...o)),u&&(n.iiifRenderingHints=n.iiifRenderingHints||{type:"ImageApiSelector"},Object.assign(n.iiifRenderingHints,u)),n},{selector:null,selectors:[],iiifRenderingHints:i}));if(!t)return K({selector:null,selectors:[],iiifRenderingHints:i});if(typeof t=="string"){const[n,s]=t.split("#");return s?Ve({type:"FragmentSelector",value:s},{svgPreprocessor:r,iiifRenderingHints:i,domParser:e}):K({selector:null,selectors:[],iiifRenderingHints:i})}if(t.type&&t.type==="PointSelector"&&(t.t||t.t===0)){const n={type:"TemporalSelector",temporal:{startTime:t.t}};return K({selector:n,selectors:[n],iiifRenderingHints:i})}if(Bs(t)){const n=[];if(t.region){const s=Ve({type:"FragmentSelector",value:"xywh="+t.region},{domParser:e,svgPreprocessor:r,iiifRenderingHints:i});n.push(...s.selectors)}return K({selector:n[0],selectors:n,iiifRenderingHints:i?{...i,...t}:t})}if(t.type==="FragmentSelector"){const n=_s.exec(t.value);if(n){const a={type:"BoxSelector",spatial:{unit:n[2]==="percent:"||n[2]==="pct:"?"percent":"pixel",x:parseFloat(n[3]),y:parseFloat(n[4]),width:parseFloat(n[5]),height:parseFloat(n[6])}};return K({selector:a,selectors:[a],iiifRenderingHints:i})}const s=t.value.match(Us);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:i})}return K({selector:null,selectors:[],iiifRenderingHints:i})}if(t.type==="SvgSelector"&&"value"in t){e||(typeof window<"u"?e=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 n=[],s,a,o=(r==null?void 0:r(t.value))??t.value,u;if(e){const l=e.parseFromString(t.value,"image/svg+xml").querySelector("svg");if(!l)return console.warn(`Illegal SVG selector: ${t.value}`),K({selector:null,selectors:[],iiifRenderingHints:i});const h=$r(l);h&&(n=h.points,u=h.shapeType,s=[Math.min(...n.map(g=>g[0])),Math.min(...n.map(g=>g[1])),Math.max(...n.map(g=>g[0])),Math.max(...n.map(g=>g[1]))],{style:a,svg:o}=Ns(h.element)??{svg:o})}const p={type:"SvgSelector",svg:o,svgShape:u,style:a,points:n.length?n: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:p,selectors:[p],iiifRenderingHints:i})}return K({selector:null,selectors:[],iiifRenderingHints:i})}function Vs(t){const e=t.map(i=>i[0]).reduce((i,n)=>(i[n]+=1,i),{C:0,Q:0,L:0,M:0}),r=new Set(t.map(i=>i[0]));if(e.C>0||e.Q>0)return"path";if(e.L>0&&(r.size===1||r.size===2&&r.has("M"))){if(e.L===4)return"rect";const i=t.slice(-1)[0];return t[0][0]==="M"&&i[0]==="L"&&i[1]==t[0][1]&&i[2]===t[0][2]||i[1]===0&&i[2]===0?"polygon":"polyline"}return"path"}function $r(t){var e;for(const r of Array.from(t.children))switch(r==null?void 0:r.tagName.toLowerCase()){case"g":{const i=$r(r);if(i)return i}continue;case"path":{const i=r.getAttribute("d");if(!i)continue;const n=Fs(i);return{element:r,points:Hs(n),shapeType:Vs(n)}}case"circle":{const i=parseFloat(r.getAttribute("cx")??"0"),n=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([i+s*Math.cos(u),n+s*Math.sin(u)])}return{element:r,points:a,shapeType:"circle"}}case"ellipse":{const i=parseFloat(r.getAttribute("cx")??"0"),n=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 p=Math.tan(u/360*Math.PI),l=s*(1-p**2)/(1+p**2),h=a*2*p/(1+p**2);o.push([i+l,n+h])}return{element:r,points:o,shapeType:"ellipse"}}case"line":{const i=parseFloat(r.getAttribute("x0")??"0"),n=parseFloat(r.getAttribute("y0")??"0"),s=parseFloat(r.getAttribute("x1")??"0"),a=parseFloat(r.getAttribute("y1")??"0");if(i===s&&n===a)continue;return{element:r,points:[[i,n],[s,a]],shapeType:"polyline"}}case"polygon":case"polyline":{const i=((e=r.getAttribute("points"))==null?void 0:e.split(" ").map(s=>s.split(",").map(parseFloat)))??[];if(!i.length)continue;let n="polyline";return r.tagName.toLowerCase()==="polygon"&&(i.push(i[0]),n="polygon"),{element:r,points:i,shapeType:n}}case"rect":{const i=parseFloat(r.getAttribute("x")??"0"),n=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:[[i,n],[i+s,n],[i+s,n+a],[i,n+a],[i,n]],shapeType:"rect"}}default:continue}return null}function Hs(t){const e=[];for(let r=0;r<t.length;r++){const i=e[e.length-1]??[0,0],n=t[r];switch(n[0]){case"M":case"L":e.push([n[1],n[2]]);continue;case"C":e.push(...Ds({x:i[0],y:i[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]},{x:n[5],y:n[6]}).map(s=>[s.x,s.y]).slice(1));continue;case"Q":e.push(...$s({x:i[0],y:i[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]}).map(s=>[s.x,s.y]).slice(1));continue}}return e}function Ns(t){const e={};if(t.hasAttribute("fill")?(e.fill=t.getAttribute("fill"),t.removeAttribute("fill")):t.style.fill&&(e.fill=t.style.fill),e.fill){const i=zt.exec(e.fill);i&&(e.fillOpacity=parseFloat(i[4]),e.fill=`rgb(${i[1]}, ${i[2]}, ${i[3]})`)}if(t.hasAttribute("fill-opacity")?(e.fillOpacity=parseFloat(t.getAttribute("fill-opacity")),t.removeAttribute("fill-opacity")):t.style.fillOpacity&&(e.fillOpacity=parseFloat(t.style.fillOpacity)),t.hasAttribute("stroke")?(e.stroke=t.getAttribute("stroke"),t.removeAttribute("stroke")):t.style.stroke&&(e.stroke=t.style.stroke),e.stroke){const i=zt.exec(e.stroke);i&&(e.strokeOpacity=parseFloat(i[4]),e.stroke=`rgb(${i[1]}, ${i[2]}, ${i[3]})`)}t.hasAttribute("stroke-opacity")?(e.strokeOpacity=parseFloat(t.getAttribute("stroke-opacity")),t.removeAttribute("stroke-opacity")):t.style.strokeOpacity&&(e.strokeOpacity=parseFloat(t.style.strokeOpacity)),t.hasAttribute("stroke-width")?(e.strokeWidth=t.getAttribute("stroke-width"),t.removeAttribute("stroke-width")):t.style.strokeWidth&&(e.strokeWidth=t.style.strokeWidth),t.hasAttribute("stroke-dasharray")?(e.strokeDasharray=t.getAttribute("stroke-dasharray"),t.removeAttribute("stroke-dasharray")):t.style.strokeDasharray&&(e.strokeDasharray=t.style.strokeDasharray);let r=t;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(e).length>0?e:void 0}}function Bs(t){return!!t&&t.type==="iiif:ImageApiSelector"&&t.type==="iiif:ImageApiSelector"}function K(t){if(t.iiifRenderingHints){const e=t.iiifRenderingHints;if(e.rotation){const r=zs(e.rotation);if(r)if(t.selectors.length)for(const i of t.selectors)i.rotation=r;else t.selectors.push({type:"RotationSelector",rotation:r})}}else delete t.iiifRenderingHints;return t}function zs(t){let e=parseFloat(t);return e&&t.startsWith("!")&&(e=360-e),e&&(e=e%360),e!==e?0:e||0}function ge(t,e={}){if(Array.isArray(t))return ge(t[0]);if(typeof t=="string"){const[r,i]=t.split("#");return i?ge({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:i}}):{type:"SpecificResource",source:{id:r,type:e.typeMap&&e.typeMap[r]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return ge(t.items[0]);if(t.type==="SpecificResource"){t.source.type==="Canvas"&&t.source.partOf&&typeof t.source.partOf=="string"&&(t.source.partOf=[{id:t.source.partOf,type:"Manifest"}]);const{selector:r,selectors:i}=t.selector?Ve(t.selector,e):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:r,selectors:i}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[r,i]=t.id.split("#");return i?ge({type:"SpecificResource",source:{...t,id:r},selector:{type:"FragmentSelector",value:i}}):{type:"SpecificResource",source:{...t,id:r},selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}function Dr(t={},e=[]){const{id:r,selector:i}=t,n=Me(),s=W(),a=r||n.annotation,o=Q(p=>a?p.iiif.entities.Annotation[a]:void 0,[a]),u=Q(p=>o&&o.body?o.body.map(l=>l?l.type==="SpecificResource"?{...l,source:s.get(l)}:l?p.iiif.entities[l.type][l.id]:null:null).filter(Boolean):[],[o]);return v.useMemo(()=>{if(!o)return;const p={...o,body:u,target:ge(o.target,{typeMap:s.getState().iiif.mapping})};return i?i(p):p},[o,i,u,...e])}const qr=({id:t,style:e,className:r,interactive:i})=>{const n=Dr({id:t}),s=Be(n,"atlas"),a=Be(n,"html"),o=Or(n,["atlas"]),u=fe(),p=v.useMemo(()=>we.mergeStyles(e,s),[e,s]);return u&&n&&n.target&&n.target.selector&&n.target.selector.type==="BoxSelector"&&n.target.source&&(n.target.source.id===u.id||n.target.source===u.id)?m.jsx(we.RegionHighlight,{id:n.id,isEditing:!0,region:n.target.selector.spatial,style:p,className:(a==null?void 0:a.className)||r,interactive:!!(a!=null&&a.href||i),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 Ws(t={},e=[]){const{id:r,selector:i}=t,n=Me(),s=r||n.annotationPage,a=Q(o=>s?o.iiif.entities.AnnotationPage[s]:void 0,[s]);return v.useMemo(()=>{if(a)return i?i(a):a},[a,...e])}const mt=({className:t,page:e})=>{var s;const r=Ws({id:e.id})||e,i=Be(r,"atlas"),n=Be(r,"html");return Q(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(qr,{id:a.id,style:i,className:(n==null?void 0:n.className)||t},a.id))})};function _r({id:t,image:e,thumbnail:r,isStatic:i,x:n=0,y:s=0,children:a,selector:o,onClick:u,enableSizes:p}){var h,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:n+e.target.spatial.x,y:s+e.target.spatial.y,width:e.target.spatial.width,height:e.target.spatial.height,onClick:u,children:e.service?m.jsxs(v.Fragment,{children:[m.jsx(we.TileSet,{tiles:{id:e.service.id||e.service["@id"]||"unknown",height:e.height,width:e.width,imageService:e.service,thumbnail:r&&r.type==="fixed"?r:void 0},enableSizes:p,x:0,y:0,width:(h=e.target)==null?void 0:h.spatial.width,height:(g=e.target)==null?void 0:g.spatial.height,crop:l}),a]},"service"):m.jsxs(v.Fragment,{children:[m.jsx("world-image",{onClick:u,uri:e.id,target:{x:0,y:0,width:e.target.spatial.width,height:e.target.spatial.height},display:e.width&&e.height?{width:e.width,height:e.height}:void 0,crop:l}),a]},"no-service")},t+(e.service?"server":"no-service"))}var Qs=Object.defineProperty,Ys=(t,e,r)=>e in t?Qs(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,He=(t,e,r)=>(Ys(t,typeof e!="symbol"?e+"":e,r),r),Gs=function(){function t(e,r){var i=[],n=!0,s=!1,a=void 0;try{for(var o=e[Symbol.iterator](),u;!(n=(u=o.next()).done)&&(i.push(u.value),!(r&&i.length===r));n=!0);}catch(p){s=!0,a=p}finally{try{!n&&o.return&&o.return()}finally{if(s)throw a}}return i}return function(e,r){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),je=Math.PI*2,at=function(t,e,r,i,n,s,a){var o=t.x,u=t.y;o*=e,u*=r;var p=i*o-n*u,l=n*o+i*u;return{x:p+s,y:l+a}},Js=function(t,e){var r=e===1.5707963267948966?.551915024494:e===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(e/4),i=Math.cos(t),n=Math.sin(t),s=Math.cos(t+e),a=Math.sin(t+e);return[{x:i-n*r,y:n+i*r},{x:s+a*r,y:a-s*r},{x:s,y:a}]},Wt=function(t,e,r,i){var n=t*i-e*r<0?-1:1,s=t*r+e*i;return s>1&&(s=1),s<-1&&(s=-1),n*Math.acos(s)},Ks=function(t,e,r,i,n,s,a,o,u,p,l,h){var g=Math.pow(n,2),b=Math.pow(s,2),d=Math.pow(l,2),x=Math.pow(h,2),w=g*b-g*x-b*d;w<0&&(w=0),w/=g*x+b*d,w=Math.sqrt(w)*(a===o?-1:1);var A=w*n/s*h,S=w*-s/n*l,k=p*A-u*S+(t+r)/2,O=u*A+p*S+(e+i)/2,F=(l-A)/n,T=(h-S)/s,P=(-l-A)/n,E=(-h-S)/s,C=Wt(1,0,F,T),$=Wt(F,T,P,E);return o===0&&$>0&&($-=je),o===1&&$<0&&($+=je),[k,O,C,$]},Zs=function(t){var e=t.px,r=t.py,i=t.cx,n=t.cy,s=t.rx,a=t.ry,o=t.xAxisRotation,u=o===void 0?0:o,p=t.largeArcFlag,l=p===void 0?0:p,h=t.sweepFlag,g=h===void 0?0:h,b=[];if(s===0||a===0)return[];var d=Math.sin(u*je/360),x=Math.cos(u*je/360),w=x*(e-i)/2+d*(r-n)/2,A=-d*(e-i)/2+x*(r-n)/2;if(w===0&&A===0)return[];s=Math.abs(s),a=Math.abs(a);var S=Math.pow(w,2)/Math.pow(s,2)+Math.pow(A,2)/Math.pow(a,2);S>1&&(s*=Math.sqrt(S),a*=Math.sqrt(S));var k=Ks(e,r,i,n,s,a,l,g,d,x,w,A),O=Gs(k,4),F=O[0],T=O[1],P=O[2],E=O[3],C=Math.abs(E)/(je/4);Math.abs(1-C)<1e-7&&(C=1);var $=Math.max(Math.ceil(C),1);E/=$;for(var X=0;X<$;X++)b.push(Js(P,E)),P+=E;return b.map(function(Y){var _=at(Y[0],s,a,x,d,F,T),U=_.x,J=_.y,ee=at(Y[1],s,a,x,d,F,T),he=ee.x,j=ee.y,V=at(Y[2],s,a,x,d,F,T),G=V.x,oe=V.y;return{x1:U,y1:J,x2:he,y2:j,x:G,y:oe}})},Xs=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ur(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var ea=ra,ot={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 ra(t){var e=[];return t.replace(ta,function(r,i,n){var s=i.toLowerCase();for(n=na(n),s=="m"&&n.length>2&&(e.push([i].concat(n.splice(0,2))),s="l",i=i=="m"?"l":"L");;){if(n.length==ot[s])return n.unshift(i),e.push(n);if(n.length<ot[s])throw new Error("malformed path data");e.push([i].concat(n.splice(0,ot[s])))}}),e}var ia=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function na(t){var e=t.match(ia);return e?e.map(Number):[]}const sa=Ur(ea);var aa=oa;function oa(t){var e=0,r=0,i=0,n=0;return t.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]+=i,s[7]+=n;break;case"v":s[1]+=n;break;case"h":s[1]+=i;break;default:for(var u=1;u<s.length;)s[u++]+=i,s[u++]+=n}switch(o){case"Z":i=e,n=r;break;case"H":i=s[1];break;case"V":n=s[1];break;case"M":i=e=s[1],n=r=s[2];break;default:i=s[s.length-2],n=s[s.length-1]}return s})}const ca=Ur(aa);function ua(t){const e=sa(t),r=ca(e);let i,n=0,s=0,a=0,o=0,u,p,l=0,h=0;const g=[];for(let b=0;b<r.length;b++){let d=r[b];const x=d[0];switch(x){case"M":n=d[1],s=d[2];break;case"H":d=["L",d[1],s];break;case"V":d=["L",n,d[1]];break;case"S":{let w=l,A=h;(i==="C"||i=="S")&&(w+=w-a,A+=A-o),d=["C",w,A,d[1],d[2],d[3],d[4]]}break;case"T":i==="Q"||i=="T"?(u=l*2-u,p=h*2-p):(u=l,p=h),d=["Q",u,p,d[1],d[2]];break;case"Q":u=d[1],p=d[2];break;case"A":{const w=Zs({px:l,py:h,cx:d[6],cy:d[7],rx:d[1],ry:d[2],xAxisRotation:d[3],largeArcFlag:d[4],sweepFlag:d[5]});if(!w.length)continue;for(const[A,S]of w.entries())d=["C",S.x1,S.y1,S.x2,S.y2,S.x,S.y],A<w.length-1&&g.push(d);d=d}break;case"Z":d=["L",n,s];break}i=x,l=d[d.length-2],h=d[d.length-1],["C","Q","A"].indexOf(x)>-1?(a=d[d.length-4],o=d[d.length-3]):(a=l,o=h),g.push(d)}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 ua(t,e,r,i=1){return new Vr(t,e,r).subdivide(i)}function la(t,e,r,i,n=1){return new Rt(new Float64Array([t.x,t.y,e.x,e.y,r.x,r.y,i.x,i.y])).subdivide(n)}function fa(t){return t.x*t.x+t.y*t.y}function Oe(t){return t/(1-.67+Math.pow(Math.pow(.67,4)+.25*t*t,.25))}function Ae(t){return t*(1-.39+Math.sqrt(.39*.39+.25*t*t))}class Vr{constructor(e,r,i){He(this,"start"),He(this,"control"),He(this,"end"),this.start=e,this.control=r,this.end=i}eval(e){const r=1-e;return{x:this.start.x*r*r+2*this.control.x*r*e+this.end.x*e*e,y:this.start.y*r*r+2*this.control.y*r*e+this.end.y*e*e}}mapToBasic(){const{x:e,y:r}=this.start,{x:i,y:n}=this.control,{x:s,y:a}=this.end,o=2*i-e-s,u=2*n-r-a,h=(i-e)*o+(n-r)*u,l=(s-i)*o+(a-n)*u,p=(s-e)*u-(a-r)*o,g=h/p,b=l/p,d=Math.abs(p)/(Math.hypot(o,u)*Math.abs(b-g));return{x0:e,x2:s,scale:d,cross:p}}subdivide(e){const r=this.mapToBasic(),i=Oe(r.x0),n=Oe(r.x2),s=.5*Math.abs(n-i)*Math.sqrt(r.scale/e),a=Math.ceil(s),o=Ae(i),u=Ae(n),h=[0];for(let l=1;l<a;l++){const p=(Ae(i+(n-i)*l/a)-o)/(u-o);h.push(p)}return h.push(1),h.map(l=>this.eval(l))}}class Rt{constructor(e){He(this,"c"),this.c=e}weightsum(e,r,i,n){const s=e*this.c[0]+r*this.c[2]+i*this.c[4]+n*this.c[6],a=e*this.c[1]+r*this.c[3]+i*this.c[5]+n*this.c[7];return{x:s,y:a}}eval(e){const r=1-e,i=r*r*r,n=3*r*r*e,s=3*r*e*e,a=e*e*e;return this.weightsum(i,n,s,a)}deriv(e){const r=1-e,i=-3*r*r,n=3*e*e,s=-6*e*r-i,a=6*e*r-n;return this.weightsum(i,s,a,n)}midpoint_quadbez(){const e=this.weightsum(-.25,.75,.75,-.25);return new Vr({x:this.c[0],y:this.c[1]},e,{x:this.c[6],y:this.c[7]})}subsegment(e,r){const i=new Float64Array(8),n=this.eval(e),s=this.eval(r);i[0]=n.x,i[1]=n.y;const a=(r-e)/3,o=this.deriv(e);i[2]=n.x+a*o.x,i[3]=n.y+a*o.y;const u=this.deriv(r);return i[4]=s.x-a*u.x,i[5]=s.y-a*u.y,i[6]=s.x,i[7]=s.y,new Rt(i)}subdivide(e){const r=.1*e,i=e-r,n=Math.sqrt(i),s=fa(this.weightsum(1,-3,3,-1)),a=Math.ceil(Math.pow(s/(432*r*r),1/6)),o=[];let u=0;for(let d=0;d<a;d++){const x=d/a,w=(d+1)/a,A=this.subsegment(x,w).midpoint_quadbez(),S=A.mapToBasic(),k=Oe(S.x0),O=Oe(S.x2),F=Math.sqrt(S.scale);let T=Math.abs(O-k)*F;if(Math.sign(S.x0)!=Math.sign(S.x2)){const P=n/F,E=n*Math.abs(O-k)/Oe(P);T=Math.max(T,E)}o.push({quad:A,a0:k,a2:O,val:T}),u+=T}const h=.5*u/n,l=Math.ceil(h),p=[{x:this.c[0],y:this.c[1]}];let g=0,b=0;for(let d=1;d<l;d++){const x=u*d/l;for(;g+o[b].val<x;)g+=o[b].val,b++;const w=o[b].a0,A=o[b].a2,S=Ae(w),k=Ae(A),O=w+(A-w)*(x-g)/o[b].val,F=(Ae(O)-S)/(k-S);p.push(o[b].quad.eval(F))}return p.push({x:this.c[6],y:this.c[7]}),p}}const pa=/&?(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]+)?))?/,Wt=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function Ne(t,{domParser:e,svgPreprocessor:r,iiifRenderingHints:i}={}){if(Array.isArray(t))return Z(t.reduce((n,s)=>{const{selector:a,selectors:o,iiifRenderingHints:u}=Ne(s,{domParser:e,svgPreprocessor:r,iiifRenderingHints:i});return a&&(n.selector||(n.selector=a),n.selectors.push(...o)),u&&(n.iiifRenderingHints=n.iiifRenderingHints||{type:"ImageApiSelector"},Object.assign(n.iiifRenderingHints,u)),n},{selector:null,selectors:[],iiifRenderingHints:i}));if(!t)return Z({selector:null,selectors:[],iiifRenderingHints:i});if(typeof t=="string"){const[n,s]=t.split("#");return s?Ne({type:"FragmentSelector",value:s},{svgPreprocessor:r,iiifRenderingHints:i,domParser:e}):Z({selector:null,selectors:[],iiifRenderingHints:i})}if(t.type&&t.type==="PointSelector"&&(t.t||t.t===0)){const n={type:"TemporalSelector",temporal:{startTime:t.t}};return Z({selector:n,selectors:[n],iiifRenderingHints:i})}if(ga(t)){const n=[];if(t.region){const s=Ne({type:"FragmentSelector",value:"xywh="+t.region},{domParser:e,svgPreprocessor:r,iiifRenderingHints:i});n.push(...s.selectors)}return Z({selector:n[0],selectors:n,iiifRenderingHints:i?{...i,...t}:t})}if(t.type==="FragmentSelector"){const n=pa.exec(t.value);if(n){const a={type:"BoxSelector",spatial:{unit:n[2]==="percent:"||n[2]==="pct:"?"percent":"pixel",x:parseFloat(n[3]),y:parseFloat(n[4]),width:parseFloat(n[5]),height:parseFloat(n[6])}};return Z({selector:a,selectors:[a],iiifRenderingHints:i})}const s=t.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:i})}return Z({selector:null,selectors:[],iiifRenderingHints:i})}if(t.type==="SvgSelector"&&"value"in t){e||(typeof window<"u"?e=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 n=[],s,a,o=(r==null?void 0:r(t.value))??t.value,u;if(e){const l=e.parseFromString(t.value,"image/svg+xml").querySelector("svg");if(!l)return console.warn(`Illegal SVG selector: ${t.value}`),Z({selector:null,selectors:[],iiifRenderingHints:i});const p=Hr(l);p&&(n=p.points,u=p.shapeType,s=[Math.min(...n.map(g=>g[0])),Math.min(...n.map(g=>g[1])),Math.max(...n.map(g=>g[0])),Math.max(...n.map(g=>g[1]))],{style:a,svg:o}=va(p.element)??{svg:o})}const h={type:"SvgSelector",svg:o,svgShape:u,style:a,points:n.length?n: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:h,selectors:[h],iiifRenderingHints:i})}return Z({selector:null,selectors:[],iiifRenderingHints:i})}function da(t){const e=t.map(i=>i[0]).reduce((i,n)=>(i[n]+=1,i),{C:0,Q:0,L:0,M:0}),r=new Set(t.map(i=>i[0]));if(e.C>0||e.Q>0)return"path";if(e.L>0&&(r.size===1||r.size===2&&r.has("M"))){if(e.L===4)return"rect";const i=t.slice(-1)[0];return t[0][0]==="M"&&i[0]==="L"&&i[1]==t[0][1]&&i[2]===t[0][2]||i[1]===0&&i[2]===0?"polygon":"polyline"}return"path"}function Hr(t){var e;for(const r of Array.from(t.children))switch(r==null?void 0:r.tagName.toLowerCase()){case"g":{const i=Hr(r);if(i)return i}continue;case"path":{const i=r.getAttribute("d");if(!i)continue;const n=ca(i);return{element:r,points:ya(n),shapeType:da(n)}}case"circle":{const i=parseFloat(r.getAttribute("cx")??"0"),n=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([i+s*Math.cos(u),n+s*Math.sin(u)])}return{element:r,points:a,shapeType:"circle"}}case"ellipse":{const i=parseFloat(r.getAttribute("cx")??"0"),n=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 h=Math.tan(u/360*Math.PI),l=s*(1-h**2)/(1+h**2),p=a*2*h/(1+h**2);o.push([i+l,n+p])}return{element:r,points:o,shapeType:"ellipse"}}case"line":{const i=parseFloat(r.getAttribute("x0")??"0"),n=parseFloat(r.getAttribute("y0")??"0"),s=parseFloat(r.getAttribute("x1")??"0"),a=parseFloat(r.getAttribute("y1")??"0");if(i===s&&n===a)continue;return{element:r,points:[[i,n],[s,a]],shapeType:"polyline"}}case"polygon":case"polyline":{const i=((e=r.getAttribute("points"))==null?void 0:e.split(" ").map(s=>s.split(",").map(parseFloat)))??[];if(!i.length)continue;let n="polyline";return r.tagName.toLowerCase()==="polygon"&&(i.push(i[0]),n="polygon"),{element:r,points:i,shapeType:n}}case"rect":{const i=parseFloat(r.getAttribute("x")??"0"),n=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:[[i,n],[i+s,n],[i+s,n+a],[i,n+a],[i,n]],shapeType:"rect"}}default:continue}return null}function ya(t){const e=[];for(let r=0;r<t.length;r++){const i=e[e.length-1]??[0,0],n=t[r];switch(n[0]){case"M":case"L":e.push([n[1],n[2]]);continue;case"C":e.push(...la({x:i[0],y:i[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]},{x:n[5],y:n[6]}).map(s=>[s.x,s.y]).slice(1));continue;case"Q":e.push(...ua({x:i[0],y:i[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]}).map(s=>[s.x,s.y]).slice(1));continue}}return e}function va(t){const e={};if(t.hasAttribute("fill")?(e.fill=t.getAttribute("fill"),t.removeAttribute("fill")):t.style.fill&&(e.fill=t.style.fill),e.fill){const i=Wt.exec(e.fill);i&&(e.fillOpacity=parseFloat(i[4]),e.fill=`rgb(${i[1]}, ${i[2]}, ${i[3]})`)}if(t.hasAttribute("fill-opacity")?(e.fillOpacity=parseFloat(t.getAttribute("fill-opacity")),t.removeAttribute("fill-opacity")):t.style.fillOpacity&&(e.fillOpacity=parseFloat(t.style.fillOpacity)),t.hasAttribute("stroke")?(e.stroke=t.getAttribute("stroke"),t.removeAttribute("stroke")):t.style.stroke&&(e.stroke=t.style.stroke),e.stroke){const i=Wt.exec(e.stroke);i&&(e.strokeOpacity=parseFloat(i[4]),e.stroke=`rgb(${i[1]}, ${i[2]}, ${i[3]})`)}t.hasAttribute("stroke-opacity")?(e.strokeOpacity=parseFloat(t.getAttribute("stroke-opacity")),t.removeAttribute("stroke-opacity")):t.style.strokeOpacity&&(e.strokeOpacity=parseFloat(t.style.strokeOpacity)),t.hasAttribute("stroke-width")?(e.strokeWidth=t.getAttribute("stroke-width"),t.removeAttribute("stroke-width")):t.style.strokeWidth&&(e.strokeWidth=t.style.strokeWidth),t.hasAttribute("stroke-dasharray")?(e.strokeDasharray=t.getAttribute("stroke-dasharray"),t.removeAttribute("stroke-dasharray")):t.style.strokeDasharray&&(e.strokeDasharray=t.style.strokeDasharray);let r=t;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(e).length>0?e:void 0}}function ga(t){return!!t&&t.type==="iiif:ImageApiSelector"&&t.type==="iiif:ImageApiSelector"}function Z(t){if(t.iiifRenderingHints){const e=t.iiifRenderingHints;if(e.rotation){const r=ma(e.rotation);if(r)if(t.selectors.length)for(const i of t.selectors)i.rotation=r;else t.selectors.push({type:"RotationSelector",rotation:r})}}else delete t.iiifRenderingHints;return t}function ma(t){let e=parseFloat(t);return e&&t.startsWith("!")&&(e=360-e),e&&(e=e%360),e!==e?0:e||0}function ke(t,e={}){if(Array.isArray(t))return ke(t[0]);if(typeof t=="string"){const[r,i]=t.split("#");return i?ke({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:i}}):{type:"SpecificResource",source:{id:r,type:e.typeMap&&e.typeMap[r]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return ke(t.items[0]);if(t.type==="SpecificResource"){t.source.type==="Canvas"&&t.source.partOf&&typeof t.source.partOf=="string"&&(t.source.partOf=[{id:t.source.partOf,type:"Manifest"}]);const{selector:r,selectors:i}=t.selector?Ne(t.selector,e):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:r,selectors:i}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[r,i]=t.id.split("#");return i?ke({type:"SpecificResource",source:{...t,id:r},selector:{type:"FragmentSelector",value:i}}):{type:"SpecificResource",source:{...t,id:r},selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}var xa=Object.defineProperty,ba=(t,e,r)=>e in t?xa(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Qt=(t,e,r)=>(ba(t,typeof e!="symbol"?e+"":e,r),r);function Aa(t){return Array.isArray(t)?t:t?[t]:[]}const Yt=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function wa(t){if(typeof t>"u"||t===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(t))throw new Error("Array is not a valid entity");if(typeof t!="object")throw new Error(`${typeof t} is not a valid entity`);if(typeof t["@type"]=="string"){const e=Yt.indexOf(t["@type"]);if(e!==-1)return Yt[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}class kt{constructor(e,r={}){Qt(this,"traversals"),Qt(this,"options"),this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...r}}static all(e){return new kt({collection:[e],manifest:[e],canvas:[e],annotationList:[e],sequence:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],layer:[e]})}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))),this.traversals.collection)}traverseCollectionItems(e){if(this.options.mergeMemberProperties){const r=[...(e.manifests||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i),...(e.collections||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i),...e.members||[]];delete e.collections,delete e.manifests,e.members=r}return e.manifests&&(e.manifests=e.manifests.map(r=>this.traverseManifest(typeof r=="string"?{"@id":r,"@type":"sc:Manifest"}:r))),e.collections&&(e.collections=e.collections.map(r=>this.traverseCollection(typeof r=="string"?{"@id":r,"@type":"sc:Collection"}:r))),e.members&&(e.members=e.members.map(r=>typeof r=="string"?r:this.traverseUnknown(r))),e}traverseManifest(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))),this.traversals.manifest)}traverseManifestItems(e){return e.sequences&&(e.sequences=e.sequences.map(r=>this.traverseSequence(r))),e.structures&&(e.structures=e.structures.map(r=>this.traverseRange(r))),e}traverseSequence(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))),this.traversals.sequence)}traverseSequenceItems(e){return e.canvases&&(e.canvases=e.canvases.map(r=>this.traverseCanvas(r))),e}traverseCanvas(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))),this.traversals.canvas)}traverseCanvasItems(e){return e.images&&(e.images=e.images.map(r=>this.traverseAnnotation(r))),e.otherContent&&(e.otherContent=e.otherContent.map(r=>this.traverseAnnotationList(r))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const r=[...(e.ranges||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Range"}:i),...(e.canvases||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Canvas"}:i),...e.members||[]];delete e.ranges,delete e.canvases,e.members=r.length?r.map(i=>this.traverseUnknown(i)):void 0}return e}traverseAnnotationList(e){const r=typeof e=="string"?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(r)),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map(r=>this.traverseAnnotation(r))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(Array.isArray(e.resource)?e.resource=e.resource.map(r=>this.traverseContentResource(r)):e.resource=this.traverseContentResource(e.resource)),e.on,e}traverseLayer(e){return this.traverseType(this.traverseLinking(this.traverseLayerItems(e)),this.traversals.layer)}traverseLayerItems(e){return e.otherContent&&(e.otherContent=e.otherContent.map(r=>this.traverseAnnotationList(r))),e}traverseChoice(e){return this.traverseType(this.traverseChoiceItems(e),this.traversals.choice)}traverseChoiceItems(e){return e.default&&e.default!=="rdf:nil"&&(e.default=this.traverseContentResource(e.default)),e.item&&e.item!=="rdf:nil"&&(e.item=e.item.map(r=>this.traverseContentResource(r))),e}traverseService(e){return this.traverseType(this.traverseLinking(e),this.traversals.service)}traverseContentResource(e){return e["@type"]==="oa:Choice"?this.traverseChoice(e):this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.contentResource)}traverseUnknown(e){if(!e["@type"]||typeof e=="string")return e;switch(wa(e)){case"sc:Collection":return this.traverseCollection(e);case"sc:Manifest":return this.traverseManifest(e);case"sc:Canvas":return this.traverseCanvas(e);case"sc:Sequence":return this.traverseSequence(e);case"sc:Range":return this.traverseRange(e);case"oa:Annotation":return this.traverseAnnotation(e);case"sc:AnnotationList":return this.traverseAnnotationList(e);case"sc:Layer":return this.traverseLayer(e);case"Service":return this.traverseService(e);case"oa:Choice":return this.traverseChoice(e);case"ContentResource":return this.traverseContentResource(e)}return e.profile?this.traverseService(e):e}traverseImageResource(e){const r=Array.isArray(e),i=Array.isArray(e)?e:[e],n=[];for(const s of i)typeof s=="string"?n.push(this.traverseContentResource({"@id":s,"@type":"dctypes:Image"})):n.push(this.traverseContentResource(s));return!r&&!this.options.convertPropsToArray?n[0]:n}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){const r=Array.isArray(e),i=Array.isArray(e)?e:[e],n=[];for(const s of i)n.push(this.traverseService(s));return!r&&!this.options.convertPropsToArray?n[0]:n}traverseLinking(e){return e.related&&(e.related=this.traverseOneOrManyType(e.related,this.traversals.contentResource)),e.rendering&&(e.rendering=this.traverseOneOrManyType(e.rendering,this.traversals.contentResource)),e.service&&(e.service=this.traverseOneOrMoreServices(e.service)),e.seeAlso&&(e.seeAlso=this.traverseOneOrManyType(e.seeAlso,this.traversals.contentResource)),e.within&&(typeof e.within=="string"||(e.within=this.traverseOneOrManyType(e.within,this.traversals.contentResource))),e.startCanvas&&(typeof e.startCanvas=="string"?e.startCanvas=this.traverseType({"@id":e.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):e.startCanvas&&this.traverseType(e.startCanvas,this.traversals.canvas)),e.contentLayer&&(typeof e.contentLayer=="string"?e.contentLayer=this.traverseLayer({"@id":e.contentLayer,"@type":"sc:Layer"}):e.contentLayer=this.traverseLayer(e.contentLayer)),e}traverseOneOrManyType(e,r){if(!Array.isArray(e))if(this.options.convertPropsToArray)e=[e];else return this.traverseType(e,r);return e.map(i=>this.traverseType(i,r))}traverseType(e,r){return r.reduce((i,n)=>{const s=n(i);return typeof s>"u"&&!this.options.allowUndefinedReturn?i:s},e)}}const Sa="http://library.stanford.edu/iiif/image-api/compliance.html#level0",Nr="http://library.stanford.edu/iiif/image-api/compliance.html#level1",Br="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Ma="http://library.stanford.edu/iiif/image-api/conformance.html#level0",zr="http://library.stanford.edu/iiif/image-api/conformance.html#level1",Wr="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Ca="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Qr="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Yr="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",Ra="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Gr="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Jr="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",ka="http://iiif.io/api/image/1/level0.json",Ta="http://iiif.io/api/image/1/profiles/level0.json",Kr="http://iiif.io/api/image/1/level1.json",Zr="http://iiif.io/api/image/1/profiles/level1.json",Xr="http://iiif.io/api/image/1/level2.json",ei="http://iiif.io/api/image/1/profiles/level2.json",Ia="http://iiif.io/api/image/2/level0.json",ja="http://iiif.io/api/image/2/profiles/level0.json",ti="http://iiif.io/api/image/2/level1.json",ri="http://iiif.io/api/image/2/profiles/level1.json",ii="http://iiif.io/api/image/2/level2.json",ni="http://iiif.io/api/image/2/profiles/level2.json",Oa="level0",si="level1",ai="level2",Ea="http://iiif.io/api/image/2/level0",oi="http://iiif.io/api/image/2/level1",ci="http://iiif.io/api/image/2/level2",Pa=[oi,ci,Nr,Br,zr,Wr,Qr,Yr,Gr,Jr,Kr,Zr,Xr,ei,ti,ri,ii,ni,si,ai],La=[Ea,oi,ci,Sa,Nr,Br,Ma,zr,Wr,Ca,Qr,Yr,Ra,Gr,Jr,ka,Ta,Kr,Zr,Xr,ei,Ia,ja,ti,ri,ii,ni,Oa,si,ai];function ne(t){for(const e in t)(typeof t[e]>"u"||t[e]===null)&&delete t[e];return t}const mt={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function me(t,e="none"){if(!t)return{};const r=Array.isArray(t)?t:[t],i={};for(const n of r){if(typeof n=="string"){i[e]=i[e]?i[e]:[],i[e].push(n||"");continue}if(!n["@language"]){i[e]=i[e]?i[e]:[],i[e].push(n["@value"]||"");continue}const s=n["@language"];i[s]=i[s]?i[s]:[],i[s].push(n["@value"]||"")}return i}function ui(t){if(Array.isArray(t))return ui(t.find(e=>typeof e=="string"));if(La.indexOf(t)!==-1)return"level2";if(Pa.indexOf(t)!==-1)return"level1";if(typeof t=="string")return t}function Fa(t){const e=Array.isArray(t)?t:[t];for(const r of e)switch(r){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function $a(t){switch(t){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}function Gt(t){for(const e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}const Da=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function Tt(t){const e=t["@id"]||t.id;let r=t["@type"]||t.type;const i=t.profile||void 0,n=t["@context"]||void 0;if(i){const s=$a(i);if(s)return s}if(n){const s=Fa(n);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&&Da.indexOf(r)!==-1)return r;if(t.format){if(t.format.startsWith("image/"))return"Image";if(t.format.startsWith("text/")||t.format==="application/pdf")return"Text";if(t.format.startsWith("application/"))return"Dataset"}return e&&(e.endsWith(".jpg")||e.endsWith(".png")||e.endsWith(".jpeg"))?"Image":r||"unknown"}const qa=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function _a(t){const e=t.match(qa);return e?e[0]:t}function Ua(t,e="Rights/License",r="none"){let i=null;const n=[],s=Array.isArray(t)?t:[t];for(const a of s){const o=a?_a(a):void 0;if(o&&(o.indexOf("creativecommons.org")!==-1||o.indexOf("rightsstatements.org")!==-1)){o.startsWith("https://")?i=`http://${o.slice(8)}`:i=o;continue}o&&n.push({label:{[r]:[e]},value:{[r]:[o]}})}return[i,n]}const Va=["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 Ha(t){if(t){const e=Array.isArray(t)?t:[t],r=[];for(const i of e)i==="http://iiif.io/api/presentation/2/context.json"&&r.push("http://iiif.io/api/presentation/3/context.json"),Va.indexOf(i)===-1&&r.push(i);if(e.length)return r.length===1?r[0]:r}}function Na(t){return t?t.map(e=>({label:me(e.label),value:me(e.value)})):[]}let Jt=0;function li(t,e){const r=encodeURI(t.id||t["@id"]||"").trim();return r&&e?`${r}/${e}`:r||(Jt++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${Jt}`)}function se(t){const e=[...t.behavior||[]];t.viewingHint&&e.push(t.viewingHint);let r;return Array.isArray(t.motivation)?r=t.motivation.map(Gt):t.motivation&&(r=Gt(t.motivation)),{"@context":t["@context"]?Ha(t["@context"]):void 0,id:(t["@id"]||li(t)).trim(),type:Tt(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:r,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function ae(t){const[e,r]=Ua(t.license),i=[...t.metadata?Na(t.metadata):[],...r];return{rights:e,metadata:i.length?i:void 0,label:t.label?me(t.label):void 0,requiredStatement:t.attribution?{label:me(mt.attributionLabel),value:me(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?me(t.description):void 0,thumbnail:Ba(t.thumbnail)}}function Ba(t){return t&&(Array.isArray(t)?t:[t]).map(e=>typeof e=="string"?{id:e,type:"Image"}:(e.type==="unknown"&&(e.type="Image"),e))}function za(t){if(!t.within)return;const e=Array.isArray(t.within)?t.within:[t.within],r=[];for(const i of e)if(typeof i=="string"){if(i)switch(t["@type"]){case"sc:Manifest":r.push({id:i,type:"Collection"});break}}else i["@id"]&&r.push({id:i["@id"],type:Tt(i)});return r.length?r:void 0}function pe(t){const e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],r=t.contentLayer;return{provider:t.logo||e.length?[{id:mt.providerId,type:"Agent",homepage:e.length?[e[0]]:void 0,logo:t.logo?Array.isArray(t.logo)?t.logo:[t.logo]:void 0,label:me(mt.providerName)}]:void 0,partOf:za(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?Aa(t.service):void 0,supplementary:r?[r]:void 0}}function Wa(t){return{chars:t.chars,format:t.format?t.format:void 0,language:t.language}}function Qa(t){return ne({...se(t),...ae(t),...pe(t),items:t.members})}function Ya(t){const e=[],r=[];let i;for(const s of t.sequences||[])s.canvases.length&&e.push(...s.canvases),s.behavior&&r.push(...s.behavior),s.startCanvas&&(i=s.startCanvas);const n=se(t);return r.length&&(n.behavior?n.behavior.push(...r):n.behavior=r),ne({...n,...ae(t),...pe(t),start:i,items:e,structures:t.structures})}function Ga(t){return ne({...se(t),...ae(t),...pe(t),annotations:t.otherContent&&t.otherContent.length?t.otherContent:void 0,items:t.images&&t.images.length?[{id:li(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function Ja(t){return ne({...se(t),...ae(t),...pe(t),items:t.resources&&t.resources.length?t.resources:void 0})}function Ka(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[],startCanvas:t.startCanvas}}function Za(t){function e(r){if(Array.isArray(r)){if(r.length>1)return{type:"List",items:r.map(e)};r=r[0]}if(typeof r=="string")return encodeURI(r).trim();if("@type"in r){let i;if(typeof r.full=="string")i=r.full;else if(r.full["@type"]==="dctypes:Image")i={id:r.full["@id"],type:"Image"};else if(r.full["@type"]==="sc:Canvas")i={id:r.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${r.full["@type"]}`);return{type:"SpecificResource",source:i,selector:bt(r.selector)}}else return encodeURI(r["@id"]).trim()}return ne({...se(t),...ae(t),...pe(t),target:e(t.on),body:Array.isArray(t.resource)?t.resource.map(xt):xt(t.resource)})}function xt(t){const e=t;return ne({...se(e),...ae(e),...pe(e),...Wa(e)})}function Xa(t){const e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),{...se(t),...ae(t),items:e}}function eo(t){return ne({...se(t),...ae(t),...pe(t),items:t.members})}function to(t){const{"@id":e,"@type":r,"@context":i,profile:n,...s}=t,a={};return e&&(a["@id"]=e),a["@type"]=Tt(t),a["@type"]==="unknown"&&(i&&i.length&&(a["@context"]=i),a["@type"]="Service"),n&&(a.profile=ui(n)),ne({...a,...s})}function ro(t){return ne({...se(t),...ae(t),...pe(t)})}new kt({collection:[Qa],manifest:[Ya],canvas:[Ga],annotationList:[Ja],sequence:[Ka],annotation:[Za],contentResource:[xt],choice:[Xa],range:[eo],service:[to],layer:[ro]});function bt(t){if((Array.isArray(t["@type"])&&t["@type"].includes("oa:SvgSelector")||t["@type"]=="oa:SvgSelector")&&("chars"in t||"value"in t))return{type:"SvgSelector",value:"chars"in t?t.chars:t.value};if(t["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:t.value};if(t["@type"]==="oa:Choice")return[bt(t.default),...(Array.isArray(t.item)?t.item:[t.item]).map(bt)];if(t["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in t?t.region:void 0,rotation:"rotation"in t?t.rotation:void 0};throw new Error(`Unsupported selector type: ${t["@type"]}`)}var Kt={exports:{}};(function(t,e){var r=Object.defineProperty,i=(s,a,o)=>a in s?r(s,a,{enumerable:!0,configurable:!0,writable:!0,value:o}):s[a]=o,n=(s,a,o)=>(i(s,typeof a!="symbol"?a+"":a,o),o);(function(s,a){a(e)})(Zs,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",h="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",d="http://iiif.io/api/image/1/level1.json",x="http://iiif.io/api/image/1/profiles/level1.json",w="http://iiif.io/api/image/1/level2.json",A="http://iiif.io/api/image/1/profiles/level2.json",S="http://iiif.io/api/image/2/level1.json",k="http://iiif.io/api/image/2/profiles/level1.json",O="http://iiif.io/api/image/2/level2.json",F="http://iiif.io/api/image/2/profiles/level2.json",T="level1",P="level2",E="http://iiif.io/api/image/2/level1",C="http://iiif.io/api/image/2/level2",$=[E,C,a,o,u,h,l,p,g,b,d,x,w,A,S,k,O,F,T,P],X=["http://iiif.io/api/image/2/level0",E,C,"http://library.stanford.edu/iiif/image-api/compliance.html#level0",a,o,"http://library.stanford.edu/iiif/image-api/conformance.html#level0",u,h,"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",d,x,w,A,"http://iiif.io/api/image/2/level0.json","http://iiif.io/api/image/2/profiles/level0.json",S,k,O,F,"level0",T,P],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={}){n(this,"traversals"),n(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(M=>typeof M=="string"?{"@id":M,"@type":"sc:Manifest"}:M),...(c.collections||[]).map(M=>typeof M=="string"?{"@id":M,"@type":"sc:Collection"}:M),...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(M=>typeof M=="string"?{"@id":M,"@type":"sc:Range"}:M),...(c.canvases||[]).map(M=>typeof M=="string"?{"@id":M,"@type":"sc:Canvas"}:M),...c.members||[]];delete c.ranges,delete c.canvases,c.members=y.length?y.map(M=>this.traverseUnknown(M)):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 M=Y.indexOf(y["@type"]);if(M!==-1)return Y[M]}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),M=Array.isArray(c)?c:[c],L=[];for(const I of M)typeof I=="string"?L.push(this.traverseContentResource({"@id":I,"@type":"dctypes:Image"})):L.push(this.traverseContentResource(I));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),M=Array.isArray(c)?c:[c],L=[];for(const I of M)L.push(this.traverseService(I));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(M=>this.traverseType(M,y))}traverseType(c,y){return y.reduce((M,L)=>{const I=L(M);return I!==void 0||this.options.allowUndefinedReturn?I:M},c)}}function U(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",he="Unknown";function j(f,c="none"){if(!f)return{};const y=Array.isArray(f)?f:[f],M={};for(const L of y){if(typeof L=="string"){M[c]=M[c]?M[c]:[],M[c].push(L||"");continue}if(!L["@language"]){M[c]=M[c]?M[c]:[],M[c].push(L["@value"]||"");continue}const I=L["@language"];M[I]=M[I]?M[I]:[],M[I].push(L["@value"]||"")}return M}function V(f){return Array.isArray(f)?V(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 oe=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function Ge(f){const c=f["@id"]||f.id;let y=f["@type"]||f.type;const M=f.profile||void 0,L=f["@context"]||void 0;if(M){const I=function(H){switch(H){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"}}(M);if(I)return I}if(L){const I=function(H){const Pe=Array.isArray(H)?H:[H];for(const Le of Pe)switch(Le){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(I)return I}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 I of["sc","oa","dcterms","dctypes","iiif"])if(y.startsWith(`${I}:`)){y=y.slice(I.length+1);break}switch(y){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(y&&oe.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 Ri=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function ki(f){const c=f.match(Ri);return c?c[0]:f}const Ti=["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 Ii(f){if(f){const c=Array.isArray(f)?f:[f],y=[];for(const M of c)M==="http://iiif.io/api/presentation/2/context.json"&&y.push("http://iiif.io/api/presentation/3/context.json"),Ti.indexOf(M)===-1&&y.push(M);if(c.length)return y.length===1?y[0]:y}}let jt=0;function Ot(f,c){const y=encodeURI(f.id||f["@id"]||"").trim();return y&&c?`${y}/${c}`:y||(jt++,`http://example.org/${f["@type"]}${c?`/${c}`:""}/${jt}`)}function re(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"]?Ii(f["@context"]):void 0,id:(f["@id"]||Ot(f)).trim(),type:Ge(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(I,H="Rights/License",Pe="none"){let Le=null;const Et=[],Li=Array.isArray(I)?I:[I];for(const Pt of Li){const ue=Pt?ki(Pt):void 0;!ue||ue.indexOf("creativecommons.org")===-1&&ue.indexOf("rightsstatements.org")===-1?ue&&Et.push({label:{[Pe]:[H]},value:{[Pe]:[ue]}}):Le=ue.startsWith("https://")?`http://${ue.slice(8)}`:ue}return[Le,Et]}(f.license),M=[...f.metadata?(L=f.metadata,L?L.map(I=>({label:j(I.label),value:j(I.value)})):[]):[],...y];var L;return{rights:c,metadata:M.length?M:void 0,label:f.label?j(f.label):void 0,requiredStatement:f.attribution?{label:j(J),value:j(f.attribution)}:void 0,navDate:f.navDate,summary:f.description?j(f.description):void 0,thumbnail:ji(f.thumbnail)}}function ji(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 Oi(f){if(!f.within)return;const c=Array.isArray(f.within)?f.within:[f.within],y=[];for(const M of c)typeof M=="string"?M&&f["@type"]==="sc:Manifest"&&y.push({id:M,type:"Collection"}):M["@id"]&&y.push({id:M["@id"],type:Ge(M)});return y.length?y:void 0}function ce(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:j(he)}]:void 0,partOf:Oi(f),rendering:f.rendering,seeAlso:f.seeAlso,start:f.startCanvas,service:f.service?(M=f.service,Array.isArray(M)?M:M?[M]:[]):void 0,supplementary:y?[y]:void 0};var M}function Je(f){const c=f;return U({...re(c),...ie(c),...ce(c),...(y=c,{chars:y.chars,format:y.format?y.format:void 0,language:y.language})});var y}const Ei=new _({collection:[function(f){return U({...re(f),...ie(f),...ce(f),items:f.members})}],manifest:[function(f){const c=[],y=[];let M;for(const I of f.sequences||[])I.canvases.length&&c.push(...I.canvases),I.behavior&&y.push(...I.behavior),I.startCanvas&&(M=I.startCanvas);const L=re(f);return y.length&&(L.behavior?L.behavior.push(...y):L.behavior=y),U({...L,...ie(f),...ce(f),start:M,items:c,structures:f.structures})}],canvas:[function(f){return U({...re(f),...ie(f),...ce(f),annotations:f.otherContent&&f.otherContent.length?f.otherContent:void 0,items:f.images&&f.images.length?[{id:Ot(f,"annotation-page"),type:"AnnotationPage",items:f.images}]:void 0})}],annotationList:[function(f){return U({...re(f),...ie(f),...ce(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 U({...re(f),...ie(f),...ce(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 M;if(typeof y.full=="string")M=y.full;else if(y.full["@type"]==="dctypes:Image")M={id:y.full["@id"],type:"Image"};else{if(y.full["@type"]!=="sc:Canvas")throw new Error(`Unsupported source type on annotation: ${y.full["@type"]}`);M={id:y.full["@id"],type:"Canvas"}}return{type:"SpecificResource",source:M,selector:Ke(y.selector)}}return encodeURI(y["@id"]).trim()}(f.on),body:Array.isArray(f.resource)?f.resource.map(Je):Je(f.resource)})}],contentResource:[Je],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),{...re(f),...ie(f),items:c}}],range:[function(f){return U({...re(f),...ie(f),...ce(f),items:f.members})}],service:[function(f){const{"@id":c,"@type":y,"@context":M,profile:L,...I}=f,H={};return c&&(H["@id"]=c),H["@type"]=Ge(f),H["@type"]==="unknown"&&(M&&M.length&&(H["@context"]=M),H["@type"]="Service"),L&&(H.profile=V(L)),U({...H,...I})}],layer:[function(f){return U({...re(f),...ie(f),...ce(f)})}]});function Ke(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[Ke(f.default),...(Array.isArray(f.item)?f.item:[f.item]).map(Ke)];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 Pi=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"?Ei.traverseUnknown(f):f};s.upgrade=Pi,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})})})(Kt,Kt.exports);function fi(t,e){const{selector:r,source:i}=ke(e);if(i.id!==t.id)return[null,i];const n={type:"BoxSelector",spatial:{x:0,y:0,width:Number(t.width),height:Number(t.height)}};return[r?r.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:r.temporal,spatial:n.spatial}:r:null,i]}const io={makeChoice:()=>{}},ct={type:"unknown"},q=t=>({type:"unknown",reason:t,annotations:{pages:[]}}),no=(t,e)=>({type:"empty",width:t,height:e,annotations:{pages:[]},image:null,images:[]});function so(t,e){var i;const r=(i=t==null?void 0:t.iiif)==null?void 0:i.meta[e];return r?r.annotationPageManager:null}function ao(t,e){return Q(r=>{const i=[];if(!t)return i;const n=Object.keys(r.iiif.entities.AnnotationPage);for(const s of n)if(!e||e.indexOf(s)!==-1){const a=so(r,s);a&&a.views&&a.views[t]&&i.push(s)}return i},[t,e])}function oo({canvas:t,manifest:e,all:r,canvases:i}){const n=[];if(e)for(const s of e.annotations)n.indexOf(s.id)===-1&&n.push(s.id);if(r){if(i&&i.length)for(const s of i)for(const a of s.annotations)n.indexOf(a.id)===-1&&n.push(a.id)}else if(t)for(const s of t.annotations)n.indexOf(s.id)===-1&&n.push(s.id);return n}function co(t,e){var i;const r=(i=t==null?void 0:t.iiif)==null?void 0:i.meta[e];return r?r.annotationPageManager:null}function uo(t,e={}){const r=W(),i=Ce(),n=fe(),s=Mr(),a=v.useMemo(()=>oo({all:e.all,manifest:i,canvas:n,canvases:s}),[e.all,n,s,i]),o=ao(t,e.all?void 0:a),u=v.useCallback(l=>{t&&r.setMetaValue([l,"annotationPageManager","views"],p=>p&&!p[t]?p:{...p||{},[t]:!1})},[t,r]),h=v.useCallback((l,p={})=>{if(!t)return;const g=r.getState(),b=[];if(p!=null&&p.deselectOthers){const d=Object.keys(g.iiif.entities.AnnotationPage);for(const x of d){const w=co(g,x);w&&w.views&&w.views[t]&&b.push(x)}}for(const d of b)u(d);r.setMetaValue([l,"annotationPageManager","views"],d=>d&&d[t]?d:{...d||{},[t]:!0})},[t,u,r]);return{availablePageIds:a,enabledPageIds:o,setPageEnabled:h,setPageDisabled:u}}function lo(t,e){return Q((r,i)=>i.get(t.map(n=>({id:n,type:e}))),[t,e])}const fo=v.createContext(new Ee.ImageServiceLoader);function pi(){return v.useContext(fo)}function po(){const t=pi(),[e,r]=v.useState({}),i=v.useRef(!1);return v.useEffect(()=>()=>{i.current=!0},[]),[v.useCallback((s,{height:a,width:o})=>{if(s){const u=s.id||s["@id"],h=t.loadServiceSync({id:u,width:s.width||o,height:s.height||a,source:s});h?s=h:e[u]||(i.current||r(l=>({...l,[u]:"loading"})),t.loadService({id:u,width:s.width||o,height:s.height||a}).then(()=>{i.current||r(l=>({...l,[u]:"done"}))}))}return s},[t,e]),e]}function ho(t={}){const e=Dr(),r=fe(t.canvasId?{id:t.canvasId}:void 0);return Q((i,n)=>{if(!r)return[];if(e&&t.enableSingleAnnotation)return[e];const s=n.get(r.items),a=[];for(const o of s)a.push(...n.get(o.items));return a},[r])}function yo(t){return t.type==="SpecificResource"?[t.source,{selector:t.selector}]:[t,{selector:null}]}const qe={},hi={get(t){return t},setMetaValue([t,e,r],i){const n=hi.getResourceMeta(t,e),s=n?n[r]:void 0,a=typeof i=="function"?i(s):i;qe[t]={...qe[t]||{},[e]:{...(qe[t]||{})[e]||{},[r]:a}}},getResourceMeta:(t,e)=>{const r=qe[t];if(r)return e?r[e]:r}};function vo(t=hi){function e(n){const s=n?typeof n=="string"?t.get(n):n:null;if(!s)return[];const a=t.get(s.items,{parent:s}),o=[];for(const u of a)o.push(...t.get(u.items,{parent:u}));return o}function r(n,s=[]){const a=Array.isArray(n)?n:e(n),o=[];let u=null;const h=[];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:d}]=yo(g),x=t.get(b),w=(x.type||"unknown").toLowerCase();if(w==="choice"){const A=t.get(x.items,{parent:x.id}),S=s.length?s.map(k=>A.find(O=>O.id===k)).filter(Boolean):[A[0]];S.length===0&&S.push(A[0]),u={type:"single-choice",items:A.map(k=>({id:k.id,label:k.label,selected:S.indexOf(k)!==-1})),label:b.label},p.push(...S);continue}o.indexOf(w)===-1&&o.push(w),h.push({type:w,annotationId:l.id,resource:x,target:l.target,selector:d})}}return{types:o,items:h,choice:u}}function i(n){const{choice:s}=r(n);return s}return{getAllPaintingAnnotations:e,getPaintables:r,extractChoices:i}}function go(t,e=[]){const r=W(),i=v.useMemo(()=>vo(r),[]),n=ho({enableSingleAnnotation:t==null?void 0:t.enableSingleAnnotation}),[s,a]=v.useState((t==null?void 0:t.defaultChoices)||[]),o=v.useMemo(()=>i.getPaintables(n,s),[r,n,s,...e]),h={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(w=>w!==l);if(x.length===0){const w=o.items[0].resource.id;return w?[w]:[]}return x}if(p)return[l];const d=[...b];if(d.length===0&&o.items.length){const x=o.items[0].resource.id;x&&d.push(x)}return b.indexOf(l)!==-1?b:[...b,l]})}},[o.choice])};return[o,h]}function mo(t,e,r){const i=[];for(const n of e.items){const s=n.resource&&n.resource.type==="SpecificResource"?n.resource.source:n.resource;if(!s.id)return q("No resource Identifier");let a;if(s.service){const b=Ee.getImageServices(s);b[0]&&(a=r(b[0],t))}const o={type:"BoxSelector",spatial:{x:0,y:0,width:Number(t.width),height:Number(t.height)}},[u,h]=fi(t,n.target);if(h.id!==t.id)continue;n.resource.width&&n.resource.height&&(n.resource.width,n.resource.height);let l=n.resource.type==="SpecificResource"?ge(n.resource):null;if(n.selector){const b=ge({type:"SpecificResource",source:n.resource,selector:n.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:n.annotationId,width:Number(u||p?s.width:t.width),height:Number(u||p?s.height:t.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};i.push(g)}return{type:"images",image:i[0],images:i,choice:e.choice}}const xo=["model/gltf-binary"];function bo(t,e){const i=e.items[0].resource;return i.format?xo.indexOf(i.format)===-1?q(`3D format: ${i.format} is unsupported`):{type:"3d-model",model:i}:q("Unknown format")}function Ao(t,e){var i;if(!t.duration)return q("No duration on canvas");if(e.items.length>1)return q("Only one audio source supported");const r=(i=e.items[0])==null?void 0:i.resource;return r?r.format?{type:"media",media:{annotationId:e.items[0].annotationId,duration:t.duration,url:r.id,type:"Sound",target:{type:"TemporalSelector",temporal:{startTime:0,endTime:t.duration}},format:r.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:t.duration}}},annotations:{pages:[]}}:q("Audio does not have format"):q("Unknown audio")}const wo=/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?vi?=|&vi?=))([^#&?]*).*/;function So(t,e){var a;const r=e.items.filter(o=>o.type==="video");if(!t.duration)return q("No duration on canvas");if(r.length>1)return q("Only one video source supported");const i=(a=r[0])==null?void 0:a.resource,n=!!(i.service||[]).find(o=>(o.profile||"").includes("youtube.com"));if(!i)return q("Unknown video");if((!i.format||i.format==="text/html")&&!n)return q("Video does not have format");const s={annotationId:e.items[0].annotationId,duration:t.duration,url:i.id,type:"Video",items:[],target:{type:"TemporalSelector",temporal:{startTime:0,endTime:t.duration}},format:i.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:t.duration}}};if(n){s.type="VideoYouTube";const o=i.id.match(wo);if(!o[1])return q("Video is not known youtube video");s.youTubeId=o[1]}return{type:"media",media:s,annotations:{pages:[]}}}function di(t,e={},r){const i=t.language||r||"none";switch(t.type){case"TextualBody":{typeof t.value<"u"&&(e[i]=t.value);break}case"List":case"Composite":case"Choice":t.items&&t.items.forEach(n=>di(n,e,i))}return e}function Mo(t,e){const r=[];return e.items.forEach(i=>{if(i.resource){const[n]=fi(t,i.target);r.push({annotationId:i.annotationId,text:di(i.resource),target:n})}}),{type:"textual-content",items:r}}function Co(t){const e=Ce(),r=fe(),i=W(),[n,s]=po(),{enabledPageIds:a}=uo((t==null?void 0:t.annotationPageManagerId)||(e==null?void 0:e.id)||(r==null?void 0:r.id),{all:!1}),o=lo(a,"AnnotationPage"),u=(t==null?void 0:t.strategies)||["empty","images","media","textual-content","complex-timeline"],[h,l]=go(t,[s]),p=v.useMemo(()=>{if(!r)return console.log("No canvas"),ct;if(h.types.length===0)return u.indexOf("empty")!==-1?no(r.width,r.height):(console.log("No paintables"),ct);if(h.types.length!==1)if(h.types.length===2&&h.types.indexOf("text")!==-1)h.types=h.types.filter(b=>b!=="text");else return u.indexOf("complex-timeline")===-1?q("Complex timeline not supported"):q("ComplexTimelineStrategy not yet supported");const g=h.types[0];return g==="image"?u.indexOf("images")===-1?q("Image not supported"):mo(r,h,n):g==="Model"||g==="model"?u.indexOf("3d-model")===-1?q("3D not supported"):bo(r,h):g==="textualbody"?u.indexOf("textual-content")===-1?q("Textual content not supported"):Mo(r,h):g==="sound"||g==="audio"?u.indexOf("media")===-1?q("Media not supported"):Ao(r,h):g==="video"?u.indexOf("media")===-1?q("Media not supported"):So(r,h):(console.log("No idea"),ct)},[r,h,i,l.makeChoice]);return v.useMemo(()=>p.type==="unknown"?[p,io]:[{...p,annotations:{pages:o}},l],[p,o])}const Ro=(t,e=[])=>{const r=W();v.useEffect(()=>{t(r)},[r,...e])},_e={},yi={get(t){return t},setMetaValue([t,e,r],i){const n=yi.getResourceMeta(t,e),s=n?n[r]:void 0,a=typeof i=="function"?i(s):i;_e[t]={..._e[t]||{},[e]:{...(_e[t]||{})[e]||{},[r]:a}}},getResourceMeta:(t,e)=>{const r=_e[t];if(r)return e?r[e]:r}},ko=new Ee.ImageServiceLoader;function To(t=yi,e={}){const r=e.imageServiceLoader||ko;async function i(n,s,a=!1,o=[],u){const h=()=>r.getThumbnailFromResource(void 0,s,a,o);if(!n)return await r.getThumbnailFromResource(void 0,s,a,o);if(typeof n=="string"){const p=Ee.getFixedSizeFromImage(n);return p&&o.push(p),await r.getThumbnailFromResource(void 0,s,a,o)}const l=t.get(n,{skipSelfReturn:!1});if(typeof l=="string")return{best:Ee.getFixedSizeFromImage(l),fallback:[],log:[]};if(!l)return await h();switch(await(async p=>{if(p&&p.thumbnail&&p.thumbnail.length){const g=t.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=t.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 i(p.items[0],s,a,o,{width:p.width,height:p.height})}case"AnnotationPage":return i(l.items[0],s,a,o,u);case"Choice":{const p=l;return!p.items||p.items[0]?await h():i(p.items[0],s,a,o,u)}case"Collection":{const p=l.items[0];return p?i(p,s,a,o,u):await h()}case"Manifest":{const p=l.items[0];return p?i(p,s,a,o,u):await h()}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 h()}return{getBestThumbnailAtSize:i}}function Io(t,e,{canvasId:r,manifestId:i}={}){const n=W(),s=pi(),a=v.useMemo(()=>To(n,{imageServiceLoader:s}),[n,s]),[o,u]=v.useState(),h=Ce(i?{id:i}:void 0),l=fe(r?{id:r}:void 0),p=l||h,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 Ro(b=>{a.getBestThumbnailAtSize(p,t,e).then(d=>{d.best&&!g.current&&u(d.best)})},[p]),o}function jo(t){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:t}}function Oo(t,e){switch(e.type){case"FINISHED":return{...t,isFinished:!0,isPlaying:!1,playRequested:!1};case"PLAY_PAUSE":return{...t,isFinished:!1,isPlaying:!t.isPlaying};case"PLAY_REQUESTED":return{...t,isFinished:!1,playRequested:!0};case"PAUSE":return{...t,isPlaying:!1};case"PLAY":return{...t,isFinished:!1,playRequested:!1,isPlaying:!0};case"MUTE":return{...t,isMuted:!0};case"SET_VOLUME":return{...t,volume:e.volume,isMuted:e.volume===0};case"TOGGLE_MUTE":return{...t,isMuted:!t.isMuted};case"UNMUTE":return{...t,isMuted:!1}}return t}function Eo(t){const e=Math.round(t);return`${Math.floor(e/60)}:${`${e%60}`.padStart(2,"0")}`}function It(t){const[e,r]=v.useReducer(Oo,jo(t.duration)),i=v.useRef(null),n=v.useRef(null),s=v.useRef(null),a=v.useRef(!1),o=v.useCallback(()=>{n.current&&i.current&&(n.current.innerHTML=Eo(i.current.currentTime),s.current&&(s.current.style.width=`${i.current.currentTime/t.duration*100}%`),a.current!==i.current.muted&&(a.current=i.current.muted,r(i.current.muted?{type:"MUTE"}:{type:"UNMUTE"})))},[t.duration]),u=v.useCallback(()=>{i.current&&(r({type:"PLAY_REQUESTED"}),i.current.play().then(()=>{r({type:"PLAY"})}),o())},[o]),h=v.useCallback(()=>{i.current&&(i.current.duration>0&&i.current.paused?u():l())},[o]),l=v.useCallback(()=>{i.current&&(i.current.pause(),r({type:"PAUSE"}),o())},[o]),p=v.useCallback(()=>{i.current&&(i.current.muted=!i.current.muted,r(i.current.muted?{type:"MUTE"}:{type:"UNMUTE"}))},[]),g=v.useCallback(()=>{i.current&&(i.current.muted=!0,r({type:"MUTE"}))},[]),b=v.useCallback(()=>{i.current&&(i.current.muted=!1,r({type:"UNMUTE"}))},[]),d=v.useCallback(A=>{i.current&&(i.current.muted=!1,i.current.volume=A/100,r({type:"SET_VOLUME",volume:A}))},[]),x=v.useCallback(A=>{i.current&&(i.current.currentTime=Math.max(0,Math.min(A*t.duration,t.duration)),o())},[]),w=v.useCallback(A=>{i.current&&(i.current.currentTime=Math.max(0,Math.min(A,t.duration)),o())},[]);return v.useEffect(()=>{const A=setInterval(()=>{o()},350);return()=>clearInterval(A)},[o,t.duration]),v.useEffect(()=>{const A=()=>{r({type:"FINISHED"})},S=i.current;return S==null||S.addEventListener("ended",A),()=>S==null?void 0:S.removeEventListener("ended",A)},[]),[{element:i,currentTime:n,progress:s},e,{play:u,pause:l,playPause:h,mute:g,unmute:b,toggleMute:p,setVolume:d,setDurationPercent:x,setTime:w}]}const Po=v.createContext(null),Lo=v.createContext(null),Fo=v.createContext(null);function vi({actions:t,state:e,children:r,currentTime:i,progress:n,element:s}){return m.jsx(Fo.Provider,{value:{currentTime:i,progress:n,element:s},children:m.jsx(Lo.Provider,{value:t,children:m.jsx(Po.Provider,{value:e,children:r})})})}function gi({media:t,children:e}){const[{element:r,currentTime:i,progress:n},s,a]=It({duration:t.duration});return m.jsxs(vi,{state:s,actions:a,currentTime:i,progress:n,element:r,children:[m.jsx("audio",{ref:r,src:t.url}),e]})}function mi({media:t,mediaControlsDeps:e,children:r}){return Se("portal","audio",gi,{media:t,children:r},[t,...e||[]]),null}function xi({element:t,media:e,playPause:r}){return m.jsxs("div",{className:"video-container",part:"video-container",onClick:r,children:[m.jsx("style",{children:`
65
+ */function la(t,e,r,i=1){return new Vr(t,e,r).subdivide(i)}function fa(t,e,r,i,n=1){return new kt(new Float64Array([t.x,t.y,e.x,e.y,r.x,r.y,i.x,i.y])).subdivide(n)}function pa(t){return t.x*t.x+t.y*t.y}function Oe(t){return t/(1-.67+Math.pow(Math.pow(.67,4)+.25*t*t,.25))}function Ae(t){return t*(1-.39+Math.sqrt(.39*.39+.25*t*t))}class Vr{constructor(e,r,i){He(this,"start"),He(this,"control"),He(this,"end"),this.start=e,this.control=r,this.end=i}eval(e){const r=1-e;return{x:this.start.x*r*r+2*this.control.x*r*e+this.end.x*e*e,y:this.start.y*r*r+2*this.control.y*r*e+this.end.y*e*e}}mapToBasic(){const{x:e,y:r}=this.start,{x:i,y:n}=this.control,{x:s,y:a}=this.end,o=2*i-e-s,u=2*n-r-a,p=(i-e)*o+(n-r)*u,l=(s-i)*o+(a-n)*u,h=(s-e)*u-(a-r)*o,g=p/h,b=l/h,d=Math.abs(h)/(Math.hypot(o,u)*Math.abs(b-g));return{x0:e,x2:s,scale:d,cross:h}}subdivide(e){const r=this.mapToBasic(),i=Oe(r.x0),n=Oe(r.x2),s=.5*Math.abs(n-i)*Math.sqrt(r.scale/e),a=Math.ceil(s),o=Ae(i),u=Ae(n),p=[0];for(let l=1;l<a;l++){const h=(Ae(i+(n-i)*l/a)-o)/(u-o);p.push(h)}return p.push(1),p.map(l=>this.eval(l))}}class kt{constructor(e){He(this,"c"),this.c=e}weightsum(e,r,i,n){const s=e*this.c[0]+r*this.c[2]+i*this.c[4]+n*this.c[6],a=e*this.c[1]+r*this.c[3]+i*this.c[5]+n*this.c[7];return{x:s,y:a}}eval(e){const r=1-e,i=r*r*r,n=3*r*r*e,s=3*r*e*e,a=e*e*e;return this.weightsum(i,n,s,a)}deriv(e){const r=1-e,i=-3*r*r,n=3*e*e,s=-6*e*r-i,a=6*e*r-n;return this.weightsum(i,s,a,n)}midpoint_quadbez(){const e=this.weightsum(-.25,.75,.75,-.25);return new Vr({x:this.c[0],y:this.c[1]},e,{x:this.c[6],y:this.c[7]})}subsegment(e,r){const i=new Float64Array(8),n=this.eval(e),s=this.eval(r);i[0]=n.x,i[1]=n.y;const a=(r-e)/3,o=this.deriv(e);i[2]=n.x+a*o.x,i[3]=n.y+a*o.y;const u=this.deriv(r);return i[4]=s.x-a*u.x,i[5]=s.y-a*u.y,i[6]=s.x,i[7]=s.y,new kt(i)}subdivide(e){const r=.1*e,i=e-r,n=Math.sqrt(i),s=pa(this.weightsum(1,-3,3,-1)),a=Math.ceil(Math.pow(s/(432*r*r),1/6)),o=[];let u=0;for(let d=0;d<a;d++){const x=d/a,w=(d+1)/a,A=this.subsegment(x,w).midpoint_quadbez(),S=A.mapToBasic(),k=Oe(S.x0),O=Oe(S.x2),F=Math.sqrt(S.scale);let T=Math.abs(O-k)*F;if(Math.sign(S.x0)!=Math.sign(S.x2)){const P=n/F,E=n*Math.abs(O-k)/Oe(P);T=Math.max(T,E)}o.push({quad:A,a0:k,a2:O,val:T}),u+=T}const p=.5*u/n,l=Math.ceil(p),h=[{x:this.c[0],y:this.c[1]}];let g=0,b=0;for(let d=1;d<l;d++){const x=u*d/l;for(;g+o[b].val<x;)g+=o[b].val,b++;const w=o[b].a0,A=o[b].a2,S=Ae(w),k=Ae(A),O=w+(A-w)*(x-g)/o[b].val,F=(Ae(O)-S)/(k-S);h.push(o[b].quad.eval(F))}return h.push({x:this.c[6],y:this.c[7]}),h}}const ha=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,da=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,Qt=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function Ne(t,{domParser:e,svgPreprocessor:r,iiifRenderingHints:i}={}){if(Array.isArray(t))return Z(t.reduce((n,s)=>{const{selector:a,selectors:o,iiifRenderingHints:u}=Ne(s,{domParser:e,svgPreprocessor:r,iiifRenderingHints:i});return a&&(n.selector||(n.selector=a),n.selectors.push(...o)),u&&(n.iiifRenderingHints=n.iiifRenderingHints||{type:"ImageApiSelector"},Object.assign(n.iiifRenderingHints,u)),n},{selector:null,selectors:[],iiifRenderingHints:i}));if(!t)return Z({selector:null,selectors:[],iiifRenderingHints:i});if(typeof t=="string"){const[n,s]=t.split("#");return s?Ne({type:"FragmentSelector",value:s},{svgPreprocessor:r,iiifRenderingHints:i,domParser:e}):Z({selector:null,selectors:[],iiifRenderingHints:i})}if(t.type&&t.type==="PointSelector"&&(t.t||t.t===0)){const n={type:"TemporalSelector",temporal:{startTime:t.t}};return Z({selector:n,selectors:[n],iiifRenderingHints:i})}if(ma(t)){const n=[];if(t.region){const s=Ne({type:"FragmentSelector",value:"xywh="+t.region},{domParser:e,svgPreprocessor:r,iiifRenderingHints:i});n.push(...s.selectors)}return Z({selector:n[0],selectors:n,iiifRenderingHints:i?{...i,...t}:t})}if(t.type==="FragmentSelector"){const n=ha.exec(t.value);if(n){const a={type:"BoxSelector",spatial:{unit:n[2]==="percent:"||n[2]==="pct:"?"percent":"pixel",x:parseFloat(n[3]),y:parseFloat(n[4]),width:parseFloat(n[5]),height:parseFloat(n[6])}};return Z({selector:a,selectors:[a],iiifRenderingHints:i})}const s=t.value.match(da);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:i})}return Z({selector:null,selectors:[],iiifRenderingHints:i})}if(t.type==="SvgSelector"&&"value"in t){e||(typeof window<"u"?e=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 n=[],s,a,o=(r==null?void 0:r(t.value))??t.value,u;if(e){const l=e.parseFromString(t.value,"image/svg+xml").querySelector("svg");if(!l)return console.warn(`Illegal SVG selector: ${t.value}`),Z({selector:null,selectors:[],iiifRenderingHints:i});const h=Hr(l);h&&(n=h.points,u=h.shapeType,s=[Math.min(...n.map(g=>g[0])),Math.min(...n.map(g=>g[1])),Math.max(...n.map(g=>g[0])),Math.max(...n.map(g=>g[1]))],{style:a,svg:o}=ga(h.element)??{svg:o})}const p={type:"SvgSelector",svg:o,svgShape:u,style:a,points:n.length?n: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:p,selectors:[p],iiifRenderingHints:i})}return Z({selector:null,selectors:[],iiifRenderingHints:i})}function ya(t){const e=t.map(i=>i[0]).reduce((i,n)=>(i[n]+=1,i),{C:0,Q:0,L:0,M:0}),r=new Set(t.map(i=>i[0]));if(e.C>0||e.Q>0)return"path";if(e.L>0&&(r.size===1||r.size===2&&r.has("M"))){if(e.L===4)return"rect";const i=t.slice(-1)[0];return t[0][0]==="M"&&i[0]==="L"&&i[1]==t[0][1]&&i[2]===t[0][2]||i[1]===0&&i[2]===0?"polygon":"polyline"}return"path"}function Hr(t){var e;for(const r of Array.from(t.children))switch(r==null?void 0:r.tagName.toLowerCase()){case"g":{const i=Hr(r);if(i)return i}continue;case"path":{const i=r.getAttribute("d");if(!i)continue;const n=ua(i);return{element:r,points:va(n),shapeType:ya(n)}}case"circle":{const i=parseFloat(r.getAttribute("cx")??"0"),n=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([i+s*Math.cos(u),n+s*Math.sin(u)])}return{element:r,points:a,shapeType:"circle"}}case"ellipse":{const i=parseFloat(r.getAttribute("cx")??"0"),n=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 p=Math.tan(u/360*Math.PI),l=s*(1-p**2)/(1+p**2),h=a*2*p/(1+p**2);o.push([i+l,n+h])}return{element:r,points:o,shapeType:"ellipse"}}case"line":{const i=parseFloat(r.getAttribute("x0")??"0"),n=parseFloat(r.getAttribute("y0")??"0"),s=parseFloat(r.getAttribute("x1")??"0"),a=parseFloat(r.getAttribute("y1")??"0");if(i===s&&n===a)continue;return{element:r,points:[[i,n],[s,a]],shapeType:"polyline"}}case"polygon":case"polyline":{const i=((e=r.getAttribute("points"))==null?void 0:e.split(" ").map(s=>s.split(",").map(parseFloat)))??[];if(!i.length)continue;let n="polyline";return r.tagName.toLowerCase()==="polygon"&&(i.push(i[0]),n="polygon"),{element:r,points:i,shapeType:n}}case"rect":{const i=parseFloat(r.getAttribute("x")??"0"),n=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:[[i,n],[i+s,n],[i+s,n+a],[i,n+a],[i,n]],shapeType:"rect"}}default:continue}return null}function va(t){const e=[];for(let r=0;r<t.length;r++){const i=e[e.length-1]??[0,0],n=t[r];switch(n[0]){case"M":case"L":e.push([n[1],n[2]]);continue;case"C":e.push(...fa({x:i[0],y:i[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]},{x:n[5],y:n[6]}).map(s=>[s.x,s.y]).slice(1));continue;case"Q":e.push(...la({x:i[0],y:i[1]},{x:n[1],y:n[2]},{x:n[3],y:n[4]}).map(s=>[s.x,s.y]).slice(1));continue}}return e}function ga(t){const e={};if(t.hasAttribute("fill")?(e.fill=t.getAttribute("fill"),t.removeAttribute("fill")):t.style.fill&&(e.fill=t.style.fill),e.fill){const i=Qt.exec(e.fill);i&&(e.fillOpacity=parseFloat(i[4]),e.fill=`rgb(${i[1]}, ${i[2]}, ${i[3]})`)}if(t.hasAttribute("fill-opacity")?(e.fillOpacity=parseFloat(t.getAttribute("fill-opacity")),t.removeAttribute("fill-opacity")):t.style.fillOpacity&&(e.fillOpacity=parseFloat(t.style.fillOpacity)),t.hasAttribute("stroke")?(e.stroke=t.getAttribute("stroke"),t.removeAttribute("stroke")):t.style.stroke&&(e.stroke=t.style.stroke),e.stroke){const i=Qt.exec(e.stroke);i&&(e.strokeOpacity=parseFloat(i[4]),e.stroke=`rgb(${i[1]}, ${i[2]}, ${i[3]})`)}t.hasAttribute("stroke-opacity")?(e.strokeOpacity=parseFloat(t.getAttribute("stroke-opacity")),t.removeAttribute("stroke-opacity")):t.style.strokeOpacity&&(e.strokeOpacity=parseFloat(t.style.strokeOpacity)),t.hasAttribute("stroke-width")?(e.strokeWidth=t.getAttribute("stroke-width"),t.removeAttribute("stroke-width")):t.style.strokeWidth&&(e.strokeWidth=t.style.strokeWidth),t.hasAttribute("stroke-dasharray")?(e.strokeDasharray=t.getAttribute("stroke-dasharray"),t.removeAttribute("stroke-dasharray")):t.style.strokeDasharray&&(e.strokeDasharray=t.style.strokeDasharray);let r=t;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(e).length>0?e:void 0}}function ma(t){return!!t&&t.type==="iiif:ImageApiSelector"&&t.type==="iiif:ImageApiSelector"}function Z(t){if(t.iiifRenderingHints){const e=t.iiifRenderingHints;if(e.rotation){const r=xa(e.rotation);if(r)if(t.selectors.length)for(const i of t.selectors)i.rotation=r;else t.selectors.push({type:"RotationSelector",rotation:r})}}else delete t.iiifRenderingHints;return t}function xa(t){let e=parseFloat(t);return e&&t.startsWith("!")&&(e=360-e),e&&(e=e%360),e!==e?0:e||0}function ke(t,e={}){if(Array.isArray(t))return ke(t[0]);if(typeof t=="string"){const[r,i]=t.split("#");return i?ke({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:i}}):{type:"SpecificResource",source:{id:r,type:e.typeMap&&e.typeMap[r]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return ke(t.items[0]);if(t.type==="SpecificResource"){t.source.type==="Canvas"&&t.source.partOf&&typeof t.source.partOf=="string"&&(t.source.partOf=[{id:t.source.partOf,type:"Manifest"}]);const{selector:r,selectors:i}=t.selector?Ne(t.selector,e):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:r,selectors:i}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[r,i]=t.id.split("#");return i?ke({type:"SpecificResource",source:{...t,id:r},selector:{type:"FragmentSelector",value:i}}):{type:"SpecificResource",source:{...t,id:r},selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}var ba=Object.defineProperty,Aa=(t,e,r)=>e in t?ba(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Yt=(t,e,r)=>(Aa(t,typeof e!="symbol"?e+"":e,r),r);function wa(t){return Array.isArray(t)?t:t?[t]:[]}const Gt=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function Sa(t){if(typeof t>"u"||t===null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(t))throw new Error("Array is not a valid entity");if(typeof t!="object")throw new Error(`${typeof t} is not a valid entity`);if(typeof t["@type"]=="string"){const e=Gt.indexOf(t["@type"]);if(e!==-1)return Gt[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}class Tt{constructor(e,r={}){Yt(this,"traversals"),Yt(this,"options"),this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...e},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...r}}static all(e){return new Tt({collection:[e],manifest:[e],canvas:[e],annotationList:[e],sequence:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],layer:[e]})}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))),this.traversals.collection)}traverseCollectionItems(e){if(this.options.mergeMemberProperties){const r=[...(e.manifests||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Manifest"}:i),...(e.collections||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Collection"}:i),...e.members||[]];delete e.collections,delete e.manifests,e.members=r}return e.manifests&&(e.manifests=e.manifests.map(r=>this.traverseManifest(typeof r=="string"?{"@id":r,"@type":"sc:Manifest"}:r))),e.collections&&(e.collections=e.collections.map(r=>this.traverseCollection(typeof r=="string"?{"@id":r,"@type":"sc:Collection"}:r))),e.members&&(e.members=e.members.map(r=>typeof r=="string"?r:this.traverseUnknown(r))),e}traverseManifest(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))),this.traversals.manifest)}traverseManifestItems(e){return e.sequences&&(e.sequences=e.sequences.map(r=>this.traverseSequence(r))),e.structures&&(e.structures=e.structures.map(r=>this.traverseRange(r))),e}traverseSequence(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))),this.traversals.sequence)}traverseSequenceItems(e){return e.canvases&&(e.canvases=e.canvases.map(r=>this.traverseCanvas(r))),e}traverseCanvas(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))),this.traversals.canvas)}traverseCanvasItems(e){return e.images&&(e.images=e.images.map(r=>this.traverseAnnotation(r))),e.otherContent&&(e.otherContent=e.otherContent.map(r=>this.traverseAnnotationList(r))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const r=[...(e.ranges||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Range"}:i),...(e.canvases||[]).map(i=>typeof i=="string"?{"@id":i,"@type":"sc:Canvas"}:i),...e.members||[]];delete e.ranges,delete e.canvases,e.members=r.length?r.map(i=>this.traverseUnknown(i)):void 0}return e}traverseAnnotationList(e){const r=typeof e=="string"?{"@id":e,"@type":"sc:AnnotationList"}:e;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(r)),this.traversals.annotationList)}traverseAnnotationListItems(e){return e.resources&&(e.resources=e.resources.map(r=>this.traverseAnnotation(r))),e}traverseAnnotation(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseAnnotationItems(e))),this.traversals.annotation)}traverseAnnotationItems(e){return e.resource&&(Array.isArray(e.resource)?e.resource=e.resource.map(r=>this.traverseContentResource(r)):e.resource=this.traverseContentResource(e.resource)),e.on,e}traverseLayer(e){return this.traverseType(this.traverseLinking(this.traverseLayerItems(e)),this.traversals.layer)}traverseLayerItems(e){return e.otherContent&&(e.otherContent=e.otherContent.map(r=>this.traverseAnnotationList(r))),e}traverseChoice(e){return this.traverseType(this.traverseChoiceItems(e),this.traversals.choice)}traverseChoiceItems(e){return e.default&&e.default!=="rdf:nil"&&(e.default=this.traverseContentResource(e.default)),e.item&&e.item!=="rdf:nil"&&(e.item=e.item.map(r=>this.traverseContentResource(r))),e}traverseService(e){return this.traverseType(this.traverseLinking(e),this.traversals.service)}traverseContentResource(e){return e["@type"]==="oa:Choice"?this.traverseChoice(e):this.traverseType(this.traverseDescriptive(this.traverseLinking(e)),this.traversals.contentResource)}traverseUnknown(e){if(!e["@type"]||typeof e=="string")return e;switch(Sa(e)){case"sc:Collection":return this.traverseCollection(e);case"sc:Manifest":return this.traverseManifest(e);case"sc:Canvas":return this.traverseCanvas(e);case"sc:Sequence":return this.traverseSequence(e);case"sc:Range":return this.traverseRange(e);case"oa:Annotation":return this.traverseAnnotation(e);case"sc:AnnotationList":return this.traverseAnnotationList(e);case"sc:Layer":return this.traverseLayer(e);case"Service":return this.traverseService(e);case"oa:Choice":return this.traverseChoice(e);case"ContentResource":return this.traverseContentResource(e)}return e.profile?this.traverseService(e):e}traverseImageResource(e){const r=Array.isArray(e),i=Array.isArray(e)?e:[e],n=[];for(const s of i)typeof s=="string"?n.push(this.traverseContentResource({"@id":s,"@type":"dctypes:Image"})):n.push(this.traverseContentResource(s));return!r&&!this.options.convertPropsToArray?n[0]:n}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){const r=Array.isArray(e),i=Array.isArray(e)?e:[e],n=[];for(const s of i)n.push(this.traverseService(s));return!r&&!this.options.convertPropsToArray?n[0]:n}traverseLinking(e){return e.related&&(e.related=this.traverseOneOrManyType(e.related,this.traversals.contentResource)),e.rendering&&(e.rendering=this.traverseOneOrManyType(e.rendering,this.traversals.contentResource)),e.service&&(e.service=this.traverseOneOrMoreServices(e.service)),e.seeAlso&&(e.seeAlso=this.traverseOneOrManyType(e.seeAlso,this.traversals.contentResource)),e.within&&(typeof e.within=="string"||(e.within=this.traverseOneOrManyType(e.within,this.traversals.contentResource))),e.startCanvas&&(typeof e.startCanvas=="string"?e.startCanvas=this.traverseType({"@id":e.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):e.startCanvas&&this.traverseType(e.startCanvas,this.traversals.canvas)),e.contentLayer&&(typeof e.contentLayer=="string"?e.contentLayer=this.traverseLayer({"@id":e.contentLayer,"@type":"sc:Layer"}):e.contentLayer=this.traverseLayer(e.contentLayer)),e}traverseOneOrManyType(e,r){if(!Array.isArray(e))if(this.options.convertPropsToArray)e=[e];else return this.traverseType(e,r);return e.map(i=>this.traverseType(i,r))}traverseType(e,r){return r.reduce((i,n)=>{const s=n(i);return typeof s>"u"&&!this.options.allowUndefinedReturn?i:s},e)}}const Ma="http://library.stanford.edu/iiif/image-api/compliance.html#level0",Nr="http://library.stanford.edu/iiif/image-api/compliance.html#level1",Br="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Ca="http://library.stanford.edu/iiif/image-api/conformance.html#level0",zr="http://library.stanford.edu/iiif/image-api/conformance.html#level1",Wr="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Ra="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Qr="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Yr="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",ka="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Gr="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Jr="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Ta="http://iiif.io/api/image/1/level0.json",Ia="http://iiif.io/api/image/1/profiles/level0.json",Kr="http://iiif.io/api/image/1/level1.json",Zr="http://iiif.io/api/image/1/profiles/level1.json",Xr="http://iiif.io/api/image/1/level2.json",ei="http://iiif.io/api/image/1/profiles/level2.json",ja="http://iiif.io/api/image/2/level0.json",Oa="http://iiif.io/api/image/2/profiles/level0.json",ti="http://iiif.io/api/image/2/level1.json",ri="http://iiif.io/api/image/2/profiles/level1.json",ii="http://iiif.io/api/image/2/level2.json",ni="http://iiif.io/api/image/2/profiles/level2.json",Ea="level0",si="level1",ai="level2",Pa="http://iiif.io/api/image/2/level0",oi="http://iiif.io/api/image/2/level1",ci="http://iiif.io/api/image/2/level2",La=[oi,ci,Nr,Br,zr,Wr,Qr,Yr,Gr,Jr,Kr,Zr,Xr,ei,ti,ri,ii,ni,si,ai],Fa=[Pa,oi,ci,Ma,Nr,Br,Ca,zr,Wr,Ra,Qr,Yr,ka,Gr,Jr,Ta,Ia,Kr,Zr,Xr,ei,ja,Oa,ti,ri,ii,ni,Ea,si,ai];function ne(t){for(const e in t)(typeof t[e]>"u"||t[e]===null)&&delete t[e];return t}const xt={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function me(t,e="none"){if(!t)return{};const r=Array.isArray(t)?t:[t],i={};for(const n of r){if(typeof n=="string"){i[e]=i[e]?i[e]:[],i[e].push(n||"");continue}if(!n["@language"]){i[e]=i[e]?i[e]:[],i[e].push(n["@value"]||"");continue}const s=n["@language"];i[s]=i[s]?i[s]:[],i[s].push(n["@value"]||"")}return i}function ui(t){if(Array.isArray(t))return ui(t.find(e=>typeof e=="string"));if(Fa.indexOf(t)!==-1)return"level2";if(La.indexOf(t)!==-1)return"level1";if(typeof t=="string")return t}function $a(t){const e=Array.isArray(t)?t:[t];for(const r of e)switch(r){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}function Da(t){switch(t){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}function Jt(t){for(const e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}const qa=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function It(t){const e=t["@id"]||t.id;let r=t["@type"]||t.type;const i=t.profile||void 0,n=t["@context"]||void 0;if(i){const s=Da(i);if(s)return s}if(n){const s=$a(n);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&&qa.indexOf(r)!==-1)return r;if(t.format){if(t.format.startsWith("image/"))return"Image";if(t.format.startsWith("text/")||t.format==="application/pdf")return"Text";if(t.format.startsWith("application/"))return"Dataset"}return e&&(e.endsWith(".jpg")||e.endsWith(".png")||e.endsWith(".jpeg"))?"Image":r||"unknown"}const _a=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Ua(t){const e=t.match(_a);return e?e[0]:t}function Va(t,e="Rights/License",r="none"){let i=null;const n=[],s=Array.isArray(t)?t:[t];for(const a of s){const o=a?Ua(a):void 0;if(o&&(o.indexOf("creativecommons.org")!==-1||o.indexOf("rightsstatements.org")!==-1)){o.startsWith("https://")?i=`http://${o.slice(8)}`:i=o;continue}o&&n.push({label:{[r]:[e]},value:{[r]:[o]}})}return[i,n]}const Ha=["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 Na(t){if(t){const e=Array.isArray(t)?t:[t],r=[];for(const i of e)i==="http://iiif.io/api/presentation/2/context.json"&&r.push("http://iiif.io/api/presentation/3/context.json"),Ha.indexOf(i)===-1&&r.push(i);if(e.length)return r.length===1?r[0]:r}}function Ba(t){return t?t.map(e=>({label:me(e.label),value:me(e.value)})):[]}let Kt=0;function li(t,e){const r=encodeURI(t.id||t["@id"]||"").trim();return r&&e?`${r}/${e}`:r||(Kt++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${Kt}`)}function se(t){const e=[...t.behavior||[]];t.viewingHint&&e.push(t.viewingHint);let r;return Array.isArray(t.motivation)?r=t.motivation.map(Jt):t.motivation&&(r=Jt(t.motivation)),{"@context":t["@context"]?Na(t["@context"]):void 0,id:(t["@id"]||li(t)).trim(),type:It(t),behavior:e.length?e:void 0,height:t.height?t.height:void 0,width:t.width?t.width:void 0,motivation:r,viewingDirection:t.viewingDirection,profile:t.profile,format:t.format?t.format:void 0,duration:void 0,timeMode:void 0}}function ae(t){const[e,r]=Va(t.license),i=[...t.metadata?Ba(t.metadata):[],...r];return{rights:e,metadata:i.length?i:void 0,label:t.label?me(t.label):void 0,requiredStatement:t.attribution?{label:me(xt.attributionLabel),value:me(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?me(t.description):void 0,thumbnail:za(t.thumbnail)}}function za(t){return t&&(Array.isArray(t)?t:[t]).map(e=>typeof e=="string"?{id:e,type:"Image"}:(e.type==="unknown"&&(e.type="Image"),e))}function Wa(t){if(!t.within)return;const e=Array.isArray(t.within)?t.within:[t.within],r=[];for(const i of e)if(typeof i=="string"){if(i)switch(t["@type"]){case"sc:Manifest":r.push({id:i,type:"Collection"});break}}else i["@id"]&&r.push({id:i["@id"],type:It(i)});return r.length?r:void 0}function pe(t){const e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],r=t.contentLayer;return{provider:t.logo||e.length?[{id:xt.providerId,type:"Agent",homepage:e.length?[e[0]]:void 0,logo:t.logo?Array.isArray(t.logo)?t.logo:[t.logo]:void 0,label:me(xt.providerName)}]:void 0,partOf:Wa(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?wa(t.service):void 0,supplementary:r?[r]:void 0}}function Qa(t){return{chars:t.chars,format:t.format?t.format:void 0,language:t.language}}function Ya(t){return ne({...se(t),...ae(t),...pe(t),items:t.members})}function Ga(t){const e=[],r=[];let i;for(const s of t.sequences||[])s.canvases.length&&e.push(...s.canvases),s.behavior&&r.push(...s.behavior),s.startCanvas&&(i=s.startCanvas);const n=se(t);return r.length&&(n.behavior?n.behavior.push(...r):n.behavior=r),ne({...n,...ae(t),...pe(t),start:i,items:e,structures:t.structures})}function Ja(t){return ne({...se(t),...ae(t),...pe(t),annotations:t.otherContent&&t.otherContent.length?t.otherContent:void 0,items:t.images&&t.images.length?[{id:li(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function Ka(t){return ne({...se(t),...ae(t),...pe(t),items:t.resources&&t.resources.length?t.resources:void 0})}function Za(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[],startCanvas:t.startCanvas}}function Xa(t){function e(r){if(Array.isArray(r)){if(r.length>1)return{type:"List",items:r.map(e)};r=r[0]}if(typeof r=="string")return encodeURI(r).trim();if("@type"in r){let i;if(typeof r.full=="string")i=r.full;else if(r.full["@type"]==="dctypes:Image")i={id:r.full["@id"],type:"Image"};else if(r.full["@type"]==="sc:Canvas")i={id:r.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${r.full["@type"]}`);return{type:"SpecificResource",source:i,selector:At(r.selector)}}else return encodeURI(r["@id"]).trim()}return ne({...se(t),...ae(t),...pe(t),target:e(t.on),body:Array.isArray(t.resource)?t.resource.map(bt):bt(t.resource)})}function bt(t){const e=t;return ne({...se(e),...ae(e),...pe(e),...Qa(e)})}function eo(t){const e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),{...se(t),...ae(t),items:e}}function to(t){return ne({...se(t),...ae(t),...pe(t),items:t.members})}function ro(t){const{"@id":e,"@type":r,"@context":i,profile:n,...s}=t,a={};return e&&(a["@id"]=e),a["@type"]=It(t),a["@type"]==="unknown"&&(i&&i.length&&(a["@context"]=i),a["@type"]="Service"),n&&(a.profile=ui(n)),ne({...a,...s})}function io(t){return ne({...se(t),...ae(t),...pe(t)})}new Tt({collection:[Ya],manifest:[Ga],canvas:[Ja],annotationList:[Ka],sequence:[Za],annotation:[Xa],contentResource:[bt],choice:[eo],range:[to],service:[ro],layer:[io]});function At(t){if((Array.isArray(t["@type"])&&t["@type"].includes("oa:SvgSelector")||t["@type"]=="oa:SvgSelector")&&("chars"in t||"value"in t))return{type:"SvgSelector",value:"chars"in t?t.chars:t.value};if(t["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:t.value};if(t["@type"]==="oa:Choice")return[At(t.default),...(Array.isArray(t.item)?t.item:[t.item]).map(At)];if(t["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in t?t.region:void 0,rotation:"rotation"in t?t.rotation:void 0};throw new Error(`Unsupported selector type: ${t["@type"]}`)}var Zt={exports:{}};(function(t,e){var r=Object.defineProperty,i=(s,a,o)=>a in s?r(s,a,{enumerable:!0,configurable:!0,writable:!0,value:o}):s[a]=o,n=(s,a,o)=>(i(s,typeof a!="symbol"?a+"":a,o),o);(function(s,a){a(e)})(Xs,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",p="http://library.stanford.edu/iiif/image-api/conformance.html#level2",l="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",h="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",d="http://iiif.io/api/image/1/level1.json",x="http://iiif.io/api/image/1/profiles/level1.json",w="http://iiif.io/api/image/1/level2.json",A="http://iiif.io/api/image/1/profiles/level2.json",S="http://iiif.io/api/image/2/level1.json",k="http://iiif.io/api/image/2/profiles/level1.json",O="http://iiif.io/api/image/2/level2.json",F="http://iiif.io/api/image/2/profiles/level2.json",T="level1",P="level2",E="http://iiif.io/api/image/2/level1",C="http://iiif.io/api/image/2/level2",$=[E,C,a,o,u,p,l,h,g,b,d,x,w,A,S,k,O,F,T,P],X=["http://iiif.io/api/image/2/level0",E,C,"http://library.stanford.edu/iiif/image-api/compliance.html#level0",a,o,"http://library.stanford.edu/iiif/image-api/conformance.html#level0",u,p,"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",l,h,"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",d,x,w,A,"http://iiif.io/api/image/2/level0.json","http://iiif.io/api/image/2/profiles/level0.json",S,k,O,F,"level0",T,P],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={}){n(this,"traversals"),n(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(M=>typeof M=="string"?{"@id":M,"@type":"sc:Manifest"}:M),...(c.collections||[]).map(M=>typeof M=="string"?{"@id":M,"@type":"sc:Collection"}:M),...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(M=>typeof M=="string"?{"@id":M,"@type":"sc:Range"}:M),...(c.canvases||[]).map(M=>typeof M=="string"?{"@id":M,"@type":"sc:Canvas"}:M),...c.members||[]];delete c.ranges,delete c.canvases,c.members=y.length?y.map(M=>this.traverseUnknown(M)):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 M=Y.indexOf(y["@type"]);if(M!==-1)return Y[M]}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),M=Array.isArray(c)?c:[c],L=[];for(const I of M)typeof I=="string"?L.push(this.traverseContentResource({"@id":I,"@type":"dctypes:Image"})):L.push(this.traverseContentResource(I));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),M=Array.isArray(c)?c:[c],L=[];for(const I of M)L.push(this.traverseService(I));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(M=>this.traverseType(M,y))}traverseType(c,y){return y.reduce((M,L)=>{const I=L(M);return I!==void 0||this.options.allowUndefinedReturn?I:M},c)}}function U(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",he="Unknown";function j(f,c="none"){if(!f)return{};const y=Array.isArray(f)?f:[f],M={};for(const L of y){if(typeof L=="string"){M[c]=M[c]?M[c]:[],M[c].push(L||"");continue}if(!L["@language"]){M[c]=M[c]?M[c]:[],M[c].push(L["@value"]||"");continue}const I=L["@language"];M[I]=M[I]?M[I]:[],M[I].push(L["@value"]||"")}return M}function V(f){return Array.isArray(f)?V(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 oe=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function Ge(f){const c=f["@id"]||f.id;let y=f["@type"]||f.type;const M=f.profile||void 0,L=f["@context"]||void 0;if(M){const I=function(H){switch(H){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"}}(M);if(I)return I}if(L){const I=function(H){const Pe=Array.isArray(H)?H:[H];for(const Le of Pe)switch(Le){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(I)return I}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 I of["sc","oa","dcterms","dctypes","iiif"])if(y.startsWith(`${I}:`)){y=y.slice(I.length+1);break}switch(y){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(y&&oe.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 Ri=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function ki(f){const c=f.match(Ri);return c?c[0]:f}const Ti=["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 Ii(f){if(f){const c=Array.isArray(f)?f:[f],y=[];for(const M of c)M==="http://iiif.io/api/presentation/2/context.json"&&y.push("http://iiif.io/api/presentation/3/context.json"),Ti.indexOf(M)===-1&&y.push(M);if(c.length)return y.length===1?y[0]:y}}let Ot=0;function Et(f,c){const y=encodeURI(f.id||f["@id"]||"").trim();return y&&c?`${y}/${c}`:y||(Ot++,`http://example.org/${f["@type"]}${c?`/${c}`:""}/${Ot}`)}function re(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"]?Ii(f["@context"]):void 0,id:(f["@id"]||Et(f)).trim(),type:Ge(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(I,H="Rights/License",Pe="none"){let Le=null;const Pt=[],Li=Array.isArray(I)?I:[I];for(const Lt of Li){const ue=Lt?ki(Lt):void 0;!ue||ue.indexOf("creativecommons.org")===-1&&ue.indexOf("rightsstatements.org")===-1?ue&&Pt.push({label:{[Pe]:[H]},value:{[Pe]:[ue]}}):Le=ue.startsWith("https://")?`http://${ue.slice(8)}`:ue}return[Le,Pt]}(f.license),M=[...f.metadata?(L=f.metadata,L?L.map(I=>({label:j(I.label),value:j(I.value)})):[]):[],...y];var L;return{rights:c,metadata:M.length?M:void 0,label:f.label?j(f.label):void 0,requiredStatement:f.attribution?{label:j(J),value:j(f.attribution)}:void 0,navDate:f.navDate,summary:f.description?j(f.description):void 0,thumbnail:ji(f.thumbnail)}}function ji(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 Oi(f){if(!f.within)return;const c=Array.isArray(f.within)?f.within:[f.within],y=[];for(const M of c)typeof M=="string"?M&&f["@type"]==="sc:Manifest"&&y.push({id:M,type:"Collection"}):M["@id"]&&y.push({id:M["@id"],type:Ge(M)});return y.length?y:void 0}function ce(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:j(he)}]:void 0,partOf:Oi(f),rendering:f.rendering,seeAlso:f.seeAlso,start:f.startCanvas,service:f.service?(M=f.service,Array.isArray(M)?M:M?[M]:[]):void 0,supplementary:y?[y]:void 0};var M}function Je(f){const c=f;return U({...re(c),...ie(c),...ce(c),...(y=c,{chars:y.chars,format:y.format?y.format:void 0,language:y.language})});var y}const Ei=new _({collection:[function(f){return U({...re(f),...ie(f),...ce(f),items:f.members})}],manifest:[function(f){const c=[],y=[];let M;for(const I of f.sequences||[])I.canvases.length&&c.push(...I.canvases),I.behavior&&y.push(...I.behavior),I.startCanvas&&(M=I.startCanvas);const L=re(f);return y.length&&(L.behavior?L.behavior.push(...y):L.behavior=y),U({...L,...ie(f),...ce(f),start:M,items:c,structures:f.structures})}],canvas:[function(f){return U({...re(f),...ie(f),...ce(f),annotations:f.otherContent&&f.otherContent.length?f.otherContent:void 0,items:f.images&&f.images.length?[{id:Et(f,"annotation-page"),type:"AnnotationPage",items:f.images}]:void 0})}],annotationList:[function(f){return U({...re(f),...ie(f),...ce(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 U({...re(f),...ie(f),...ce(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 M;if(typeof y.full=="string")M=y.full;else if(y.full["@type"]==="dctypes:Image")M={id:y.full["@id"],type:"Image"};else{if(y.full["@type"]!=="sc:Canvas")throw new Error(`Unsupported source type on annotation: ${y.full["@type"]}`);M={id:y.full["@id"],type:"Canvas"}}return{type:"SpecificResource",source:M,selector:Ke(y.selector)}}return encodeURI(y["@id"]).trim()}(f.on),body:Array.isArray(f.resource)?f.resource.map(Je):Je(f.resource)})}],contentResource:[Je],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),{...re(f),...ie(f),items:c}}],range:[function(f){return U({...re(f),...ie(f),...ce(f),items:f.members})}],service:[function(f){const{"@id":c,"@type":y,"@context":M,profile:L,...I}=f,H={};return c&&(H["@id"]=c),H["@type"]=Ge(f),H["@type"]==="unknown"&&(M&&M.length&&(H["@context"]=M),H["@type"]="Service"),L&&(H.profile=V(L)),U({...H,...I})}],layer:[function(f){return U({...re(f),...ie(f),...ce(f)})}]});function Ke(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[Ke(f.default),...(Array.isArray(f.item)?f.item:[f.item]).map(Ke)];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 Pi=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"?Ei.traverseUnknown(f):f};s.upgrade=Pi,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})})})(Zt,Zt.exports);function fi(t,e){const{selector:r,source:i}=ke(e);if(i.id!==t.id)return[null,i];const n={type:"BoxSelector",spatial:{x:0,y:0,width:Number(t.width),height:Number(t.height)}};return[r?r.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:r.temporal,spatial:n.spatial}:r:null,i]}const no={makeChoice:()=>{}},ct={type:"unknown"},q=t=>({type:"unknown",reason:t,annotations:{pages:[]}}),so=(t,e)=>({type:"empty",width:t,height:e,annotations:{pages:[]},image:null,images:[]});function ao(t,e){var i;const r=(i=t==null?void 0:t.iiif)==null?void 0:i.meta[e];return r?r.annotationPageManager:null}function oo(t,e){return Q(r=>{const i=[];if(!t)return i;const n=Object.keys(r.iiif.entities.AnnotationPage);for(const s of n)if(!e||e.indexOf(s)!==-1){const a=ao(r,s);a&&a.views&&a.views[t]&&i.push(s)}return i},[t,e])}function co({canvas:t,manifest:e,all:r,canvases:i}){const n=[];if(e)for(const s of e.annotations)n.indexOf(s.id)===-1&&n.push(s.id);if(r){if(i&&i.length)for(const s of i)for(const a of s.annotations)n.indexOf(a.id)===-1&&n.push(a.id)}else if(t)for(const s of t.annotations)n.indexOf(s.id)===-1&&n.push(s.id);return n}function uo(t,e){var i;const r=(i=t==null?void 0:t.iiif)==null?void 0:i.meta[e];return r?r.annotationPageManager:null}function lo(t,e={}){const r=W(),i=Ce(),n=fe(),s=Mr(),a=v.useMemo(()=>co({all:e.all,manifest:i,canvas:n,canvases:s}),[e.all,n,s,i]),o=oo(t,e.all?void 0:a),u=v.useCallback(l=>{t&&r.setMetaValue([l,"annotationPageManager","views"],h=>h&&!h[t]?h:{...h||{},[t]:!1})},[t,r]),p=v.useCallback((l,h={})=>{if(!t)return;const g=r.getState(),b=[];if(h!=null&&h.deselectOthers){const d=Object.keys(g.iiif.entities.AnnotationPage);for(const x of d){const w=uo(g,x);w&&w.views&&w.views[t]&&b.push(x)}}for(const d of b)u(d);r.setMetaValue([l,"annotationPageManager","views"],d=>d&&d[t]?d:{...d||{},[t]:!0})},[t,u,r]);return{availablePageIds:a,enabledPageIds:o,setPageEnabled:p,setPageDisabled:u}}function fo(t,e){return Q((r,i)=>i.get(t.map(n=>({id:n,type:e}))),[t,e])}const po=v.createContext(new Ee.ImageServiceLoader);function pi(){return v.useContext(po)}function ho(){const t=pi(),[e,r]=v.useState({}),i=v.useRef(!1);return v.useEffect(()=>()=>{i.current=!0},[]),[v.useCallback((s,{height:a,width:o})=>{if(s){const u=s.id||s["@id"],p=t.loadServiceSync({id:u,width:s.width||o,height:s.height||a,source:s});p?s=p:e[u]||(i.current||r(l=>({...l,[u]:"loading"})),t.loadService({id:u,width:s.width||o,height:s.height||a}).then(()=>{i.current||r(l=>({...l,[u]:"done"}))}))}return s},[t,e]),e]}function yo(t={}){const e=Dr(),r=fe(t.canvasId?{id:t.canvasId}:void 0);return Q((i,n)=>{if(!r)return[];if(e&&t.enableSingleAnnotation)return[e];const s=n.get(r.items),a=[];for(const o of s)a.push(...n.get(o.items));return a},[r])}function vo(t){return t.type==="SpecificResource"?[t.source,{selector:t.selector}]:[t,{selector:null}]}const qe={},hi={get(t){return t},setMetaValue([t,e,r],i){const n=hi.getResourceMeta(t,e),s=n?n[r]:void 0,a=typeof i=="function"?i(s):i;qe[t]={...qe[t]||{},[e]:{...(qe[t]||{})[e]||{},[r]:a}}},getResourceMeta:(t,e)=>{const r=qe[t];if(r)return e?r[e]:r}};function go(t=hi){function e(n){const s=n?typeof n=="string"?t.get(n):n:null;if(!s)return[];const a=t.get(s.items,{parent:s}),o=[];for(const u of a)o.push(...t.get(u.items,{parent:u}));return o}function r(n,s=[]){const a=Array.isArray(n)?n:e(n),o=[];let u=null;const p=[];for(const l of a){if(l.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const h=Array.from(Array.isArray(l.body)?l.body:[l.body]);for(const g of h){const[b,{selector:d}]=vo(g),x=t.get(b),w=(x.type||"unknown").toLowerCase();if(w==="choice"){const A=t.get(x.items,{parent:x.id}),S=s.length?s.map(k=>A.find(O=>O.id===k)).filter(Boolean):[A[0]];S.length===0&&S.push(A[0]),u={type:"single-choice",items:A.map(k=>({id:k.id,label:k.label,selected:S.indexOf(k)!==-1})),label:b.label},h.push(...S);continue}o.indexOf(w)===-1&&o.push(w),p.push({type:w,annotationId:l.id,resource:x,target:l.target,selector:d})}}return{types:o,items:p,choice:u}}function i(n){const{choice:s}=r(n);return s}return{getAllPaintingAnnotations:e,getPaintables:r,extractChoices:i}}function mo(t,e=[]){const r=W(),i=v.useMemo(()=>go(r),[]),n=yo({enableSingleAnnotation:t==null?void 0:t.enableSingleAnnotation}),[s,a]=v.useState((t==null?void 0:t.defaultChoices)||[]),o=v.useMemo(()=>i.getPaintables(n,s),[r,n,s,...e]),p={makeChoice:v.useCallback((l,{deselectOthers:h=!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(w=>w!==l);if(x.length===0){const w=o.items[0].resource.id;return w?[w]:[]}return x}if(h)return[l];const d=[...b];if(d.length===0&&o.items.length){const x=o.items[0].resource.id;x&&d.push(x)}return b.indexOf(l)!==-1?b:[...b,l]})}},[o.choice])};return[o,p]}function xo(t,e,r){const i=[];for(const n of e.items){const s=n.resource&&n.resource.type==="SpecificResource"?n.resource.source:n.resource;if(!s.id)return q("No resource Identifier");let a;if(s.service){const b=Ee.getImageServices(s);b[0]&&(a=r(b[0],t))}const o={type:"BoxSelector",spatial:{x:0,y:0,width:Number(t.width),height:Number(t.height)}},[u,p]=fi(t,n.target);if(p.id!==t.id)continue;n.resource.width&&n.resource.height&&(n.resource.width,n.resource.height);let l=n.resource.type==="SpecificResource"?ge(n.resource):null;if(n.selector){const b=ge({type:"SpecificResource",source:n.resource,selector:n.selector});b&&(l=b)}const h=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:n.annotationId,width:Number(u||h?s.width:t.width),height:Number(u||h?s.height:t.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:h};i.push(g)}return{type:"images",image:i[0],images:i,choice:e.choice}}const bo=["model/gltf-binary"];function Ao(t,e){const i=e.items[0].resource;return i.format?bo.indexOf(i.format)===-1?q(`3D format: ${i.format} is unsupported`):{type:"3d-model",model:i}:q("Unknown format")}function wo(t,e){var i;if(!t.duration)return q("No duration on canvas");if(e.items.length>1)return q("Only one audio source supported");const r=(i=e.items[0])==null?void 0:i.resource;return r?r.format?{type:"media",media:{annotationId:e.items[0].annotationId,duration:t.duration,url:r.id,type:"Sound",target:{type:"TemporalSelector",temporal:{startTime:0,endTime:t.duration}},format:r.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:t.duration}}},annotations:{pages:[]}}:q("Audio does not have format"):q("Unknown audio")}const So=/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?vi?=|&vi?=))([^#&?]*).*/;function Mo(t,e){var a;const r=e.items.filter(o=>o.type==="video");if(!t.duration)return q("No duration on canvas");if(r.length>1)return q("Only one video source supported");const i=(a=r[0])==null?void 0:a.resource,n=!!(i.service||[]).find(o=>(o.profile||"").includes("youtube.com"));if(!i)return q("Unknown video");if((!i.format||i.format==="text/html")&&!n)return q("Video does not have format");const s={annotationId:e.items[0].annotationId,duration:t.duration,url:i.id,type:"Video",items:[],target:{type:"TemporalSelector",temporal:{startTime:0,endTime:t.duration}},format:i.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:t.duration}}};if(n){s.type="VideoYouTube";const o=i.id.match(So);if(!o[1])return q("Video is not known youtube video");s.youTubeId=o[1]}return{type:"media",media:s,annotations:{pages:[]}}}function di(t,e={},r){const i=t.language||r||"none";switch(t.type){case"TextualBody":{typeof t.value<"u"&&(e[i]=t.value);break}case"List":case"Composite":case"Choice":t.items&&t.items.forEach(n=>di(n,e,i))}return e}function Co(t,e){const r=[];return e.items.forEach(i=>{if(i.resource){const[n]=fi(t,i.target);r.push({annotationId:i.annotationId,text:di(i.resource),target:n})}}),{type:"textual-content",items:r}}function Ro(t){const e=Ce(),r=fe(),i=W(),[n,s]=ho(),{enabledPageIds:a}=lo((t==null?void 0:t.annotationPageManagerId)||(e==null?void 0:e.id)||(r==null?void 0:r.id),{all:!1}),o=fo(a,"AnnotationPage"),u=(t==null?void 0:t.strategies)||["empty","images","media","textual-content","complex-timeline"],[p,l]=mo(t,[s]),h=v.useMemo(()=>{if(!r)return console.log("No canvas"),ct;if(p.types.length===0)return u.indexOf("empty")!==-1?so(r.width,r.height):(console.log("No paintables"),ct);if(p.types.length!==1)if(p.types.length===2&&p.types.indexOf("text")!==-1)p.types=p.types.filter(b=>b!=="text");else return u.indexOf("complex-timeline")===-1?q("Complex timeline not supported"):q("ComplexTimelineStrategy not yet supported");const g=p.types[0];return g==="image"?u.indexOf("images")===-1?q("Image not supported"):xo(r,p,n):g==="Model"||g==="model"?u.indexOf("3d-model")===-1?q("3D not supported"):Ao(r,p):g==="textualbody"?u.indexOf("textual-content")===-1?q("Textual content not supported"):Co(r,p):g==="sound"||g==="audio"?u.indexOf("media")===-1?q("Media not supported"):wo(r,p):g==="video"?u.indexOf("media")===-1?q("Media not supported"):Mo(r,p):(console.log("No idea"),ct)},[r,p,i,l.makeChoice]);return v.useMemo(()=>h.type==="unknown"?[h,no]:[{...h,annotations:{pages:o}},l],[h,o])}const ko=(t,e=[])=>{const r=W();v.useEffect(()=>{t(r)},[r,...e])},_e={},yi={get(t){return t},setMetaValue([t,e,r],i){const n=yi.getResourceMeta(t,e),s=n?n[r]:void 0,a=typeof i=="function"?i(s):i;_e[t]={..._e[t]||{},[e]:{...(_e[t]||{})[e]||{},[r]:a}}},getResourceMeta:(t,e)=>{const r=_e[t];if(r)return e?r[e]:r}},To=new Ee.ImageServiceLoader;function Io(t=yi,e={}){const r=e.imageServiceLoader||To;async function i(n,s,a=!1,o=[],u){const p=()=>r.getThumbnailFromResource(void 0,s,a,o);if(!n)return await r.getThumbnailFromResource(void 0,s,a,o);if(typeof n=="string"){const h=Ee.getFixedSizeFromImage(n);return h&&o.push(h),await r.getThumbnailFromResource(void 0,s,a,o)}const l=t.get(n,{skipSelfReturn:!1});if(typeof l=="string")return{best:Ee.getFixedSizeFromImage(l),fallback:[],log:[]};if(!l)return await p();switch(await(async h=>{if(h&&h.thumbnail&&h.thumbnail.length){const g=t.get(h.thumbnail[0]),b=await r.getImageCandidates(g,a);b&&b.length&&o.push(...b)}})(l),l.type){case"Annotation":{const h=Array.isArray(l.body)?l.body:[l.body],g=t.get(h[0]);return u&&!g.width&&(g.width=u.width,g.height=u.height),await r.getThumbnailFromResource(g,s,a,o)}case"Canvas":{const h=l;return i(h.items[0],s,a,o,{width:h.width,height:h.height})}case"AnnotationPage":return i(l.items[0],s,a,o,u);case"Choice":{const h=l;return!h.items||h.items[0]?await p():i(h.items[0],s,a,o,u)}case"Collection":{const h=l.items[0];return h?i(h,s,a,o,u):await p()}case"Manifest":{const h=l.items[0];return h?i(h,s,a,o,u):await p()}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 p()}return{getBestThumbnailAtSize:i}}function jo(t,e,{canvasId:r,manifestId:i}={}){const n=W(),s=pi(),a=v.useMemo(()=>Io(n,{imageServiceLoader:s}),[n,s]),[o,u]=v.useState(),p=Ce(i?{id:i}:void 0),l=fe(r?{id:r}:void 0),h=l||p,g=v.useRef(!1);if(v.useEffect(()=>(g.current=!1,()=>{g.current=!0}),[]),!h)throw new Error("Must be called under a manifest or canvas context.");return ko(b=>{a.getBestThumbnailAtSize(h,t,e).then(d=>{d.best&&!g.current&&u(d.best)})},[h]),o}function Oo(t){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:t}}function Eo(t,e){switch(e.type){case"FINISHED":return{...t,isFinished:!0,isPlaying:!1,playRequested:!1};case"PLAY_PAUSE":return{...t,isFinished:!1,isPlaying:!t.isPlaying};case"PLAY_REQUESTED":return{...t,isFinished:!1,playRequested:!0};case"PAUSE":return{...t,isPlaying:!1};case"PLAY":return{...t,isFinished:!1,playRequested:!1,isPlaying:!0};case"MUTE":return{...t,isMuted:!0};case"SET_VOLUME":return{...t,volume:e.volume,isMuted:e.volume===0};case"TOGGLE_MUTE":return{...t,isMuted:!t.isMuted};case"UNMUTE":return{...t,isMuted:!1}}return t}function Po(t){const e=Math.round(t);return`${Math.floor(e/60)}:${`${e%60}`.padStart(2,"0")}`}function jt(t){const[e,r]=v.useReducer(Eo,Oo(t.duration)),i=v.useRef(null),n=v.useRef(null),s=v.useRef(null),a=v.useRef(!1),o=v.useCallback(()=>{n.current&&i.current&&(n.current.innerHTML=Po(i.current.currentTime),s.current&&(s.current.style.width=`${i.current.currentTime/t.duration*100}%`),a.current!==i.current.muted&&(a.current=i.current.muted,r(i.current.muted?{type:"MUTE"}:{type:"UNMUTE"})))},[t.duration]),u=v.useCallback(()=>{i.current&&(r({type:"PLAY_REQUESTED"}),i.current.play().then(()=>{r({type:"PLAY"})}),o())},[o]),p=v.useCallback(()=>{i.current&&(i.current.duration>0&&i.current.paused?u():l())},[o]),l=v.useCallback(()=>{i.current&&(i.current.pause(),r({type:"PAUSE"}),o())},[o]),h=v.useCallback(()=>{i.current&&(i.current.muted=!i.current.muted,r(i.current.muted?{type:"MUTE"}:{type:"UNMUTE"}))},[]),g=v.useCallback(()=>{i.current&&(i.current.muted=!0,r({type:"MUTE"}))},[]),b=v.useCallback(()=>{i.current&&(i.current.muted=!1,r({type:"UNMUTE"}))},[]),d=v.useCallback(A=>{i.current&&(i.current.muted=!1,i.current.volume=A/100,r({type:"SET_VOLUME",volume:A}))},[]),x=v.useCallback(A=>{i.current&&(i.current.currentTime=Math.max(0,Math.min(A*t.duration,t.duration)),o())},[]),w=v.useCallback(A=>{i.current&&(i.current.currentTime=Math.max(0,Math.min(A,t.duration)),o())},[]);return v.useEffect(()=>{const A=setInterval(()=>{o()},350);return()=>clearInterval(A)},[o,t.duration]),v.useEffect(()=>{const A=()=>{r({type:"FINISHED"})},S=i.current;return S==null||S.addEventListener("ended",A),()=>S==null?void 0:S.removeEventListener("ended",A)},[]),[{element:i,currentTime:n,progress:s},e,{play:u,pause:l,playPause:p,mute:g,unmute:b,toggleMute:h,setVolume:d,setDurationPercent:x,setTime:w}]}const Lo=v.createContext(null),Fo=v.createContext(null),$o=v.createContext(null);function vi({actions:t,state:e,children:r,currentTime:i,progress:n,element:s}){return m.jsx($o.Provider,{value:{currentTime:i,progress:n,element:s},children:m.jsx(Fo.Provider,{value:t,children:m.jsx(Lo.Provider,{value:e,children:r})})})}function gi({media:t,children:e}){const[{element:r,currentTime:i,progress:n},s,a]=jt({duration:t.duration});return m.jsxs(vi,{state:s,actions:a,currentTime:i,progress:n,element:r,children:[m.jsx("audio",{ref:r,src:t.url}),e]})}function mi({media:t,mediaControlsDeps:e,children:r}){return Se("portal","audio",gi,{media:t,children:r},[t,...e||[]]),null}function xi({element:t,media:e,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:t,src:e.url,style:{width:"100%",objectFit:"contain"}})]})}function bi({media:t,mediaControlsDeps:e,children:r}){const[{element:i,currentTime:n,progress:s},a,o]=It({duration:t.duration});return Se("overlay","video-element",xi,{element:i,media:t,playPause:o.playPause}),Se("portal","custom-controls",vi,{state:a,actions:o,currentTime:n,progress:s,element:i,children:r},[n,a,t,...e||[]]),null}function Ai({model:t}){return m.jsxs(m.Fragment,{children:[m.jsx("style",{children:`
78
+ `}),m.jsx("video",{ref:t,src:e.url,style:{width:"100%",objectFit:"contain"}})]})}function bi({media:t,mediaControlsDeps:e,children:r}){const[{element:i,currentTime:n,progress:s},a,o]=jt({duration:t.duration});return Se("overlay","video-element",xi,{element:i,media:t,playPause:o.playPause}),Se("portal","custom-controls",vi,{state:a,actions:o,currentTime:n,progress:s,element:i,children:r},[n,a,t,...e||[]]),null}function Ai({model:t}){return m.jsxs(m.Fragment,{children:[m.jsx("style",{children:`
79
79
  .model-container {
80
80
  position: absolute;
81
81
  top: 0;
@@ -88,8 +88,8 @@
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:t.id})})]})}function wi({model:t,name:e}){return Se("overlay",`model-${e}`,Ai,{model:t},[t]),null}function Si({style:t}){const e=fe();return!e||!e.height||!e.width?null:m.jsx("box",{interactive:!1,target:{x:0,y:0,width:Number(e.width),height:Number(e.height)},style:t})}const $o=v.createContext("en");function Mi(){return v.useContext($o)}function Zt(t){return t.indexOf("-")!==-1?t.slice(0,t.indexOf("-")):t}function Do({as:t,language:e,children:r,viewingDirection:i,...n}){const s=Mi();return v.useMemo(()=>Zt(s)===Zt(e),[s,e])?t?m.jsx(t,{...n,children:r}):m.jsx("span",{...n,children:r}):t?m.jsx(t,{...n,lang:e,dir:i,children:r}):m.jsx("span",{...n,lang:e,dir:i,children:r})}function qo(t,e,r){if(e.length===0)return;if(e.length===1)return e[0];if(e.indexOf(t)!==-1)return t;const i=t.indexOf("-")!==-1?t.slice(0,t.indexOf("-")):null;if(i&&e.indexOf(i)!==-1)return i;for(const n of r)if(e.indexOf(n)!==-1)return n;return e.indexOf("none")!==-1?"none":e.indexOf("@none")!==-1?"@none":e[0]}const _o=(t,e=[])=>{const r=Mi();return v.useMemo(()=>{const i=t();return qo(r,i,[])},[r,...e])};function Uo(t,e){const r=_o(()=>Object.keys(t||{}),[t]);return[v.useMemo(()=>{if(!t)return e||"";if(typeof t=="string")return t;const i=r?t[r]:void 0;return i?typeof i=="string"?i:i.join(`
92
- `):""},[r,e,t]),r]}const Vo=({as:t,defaultText:e,enableDangerouslySetInnerHTML:r,children:i,...n})=>{const[s,a]=Uo(i,e);return a?m.jsx(Do,{...n,as:t,language:a,title:r?void 0:s,dangerouslySetInnerHTML:r?{__html:s}:void 0,children:r?void 0:s}):t?m.jsx(t,{...n,children:s}):m.jsx("span",{...n,title:r?void 0:s,dangerouslySetInnerHTML:r?{__html:s}:void 0,children:r?void 0:s})};function Ho({element:t,media:e,playPause:r}){const i=v.useRef(null);return e.youTubeId?m.jsxs("div",{className:"video-container",part:"video-container",onClick:r,children:[m.jsx("style",{children:`
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:t.id})})]})}function wi({model:t,name:e}){return Se("overlay",`model-${e}`,Ai,{model:t},[t]),null}function Si({style:t}){const e=fe();return!e||!e.height||!e.width?null:m.jsx("box",{interactive:!1,target:{x:0,y:0,width:Number(e.width),height:Number(e.height)},style:t})}const Do=v.createContext("en");function Mi(){return v.useContext(Do)}function Xt(t){return t.indexOf("-")!==-1?t.slice(0,t.indexOf("-")):t}function qo({as:t,language:e,children:r,viewingDirection:i,...n}){const s=Mi();return v.useMemo(()=>Xt(s)===Xt(e),[s,e])?t?m.jsx(t,{...n,children:r}):m.jsx("span",{...n,children:r}):t?m.jsx(t,{...n,lang:e,dir:i,children:r}):m.jsx("span",{...n,lang:e,dir:i,children:r})}function _o(t,e,r){if(e.length===0)return;if(e.length===1)return e[0];if(e.indexOf(t)!==-1)return t;const i=t.indexOf("-")!==-1?t.slice(0,t.indexOf("-")):null;if(i&&e.indexOf(i)!==-1)return i;for(const n of r)if(e.indexOf(n)!==-1)return n;return e.indexOf("none")!==-1?"none":e.indexOf("@none")!==-1?"@none":e[0]}const Uo=(t,e=[])=>{const r=Mi();return v.useMemo(()=>{const i=t();return _o(r,i,[])},[r,...e])};function Vo(t,e){const r=Uo(()=>Object.keys(t||{}),[t]);return[v.useMemo(()=>{if(!t)return e||"";if(typeof t=="string")return t;const i=r?t[r]:void 0;return i?typeof i=="string"?i:i.join(`
92
+ `):""},[r,e,t]),r]}const Ho=({as:t,defaultText:e,enableDangerouslySetInnerHTML:r,children:i,...n})=>{const[s,a]=Vo(i,e);return a?m.jsx(qo,{...n,as:t,language:a,title:r?void 0:s,dangerouslySetInnerHTML:r?{__html:s}:void 0,children:r?void 0:s}):t?m.jsx(t,{...n,children:s}):m.jsx("span",{...n,title:r?void 0:s,dangerouslySetInnerHTML:r?{__html:s}:void 0,children:r?void 0:s})};function No({element:t,media:e,playPause:r}){const i=v.useRef(null);return e.youTubeId?m.jsxs("div",{className:"video-container",part:"video-container",onClick:r,children:[m.jsx("style",{children:`
93
93
  .video-container {
94
94
  position: absolute;
95
95
  top: 0;
@@ -107,5 +107,5 @@
107
107
  width: 100%;
108
108
  object-fit: contain;
109
109
  }
110
- `}),m.jsx("iframe",{className:"video-yt",ref:i,src:`https://www.youtube.com/embed/${e.youTubeId}?enablejsapi=1&origin=${window.location.host}`,referrerPolicy:"no-referrer",sandbox:"allow-scripts allow-same-origin allow-presentation"})]}):null}function No({media:t,mediaControlsDeps:e,children:r}){const[{element:i,currentTime:n,progress:s},a,o]=It({duration:t.duration});return Se("overlay","video-element",Ho,{element:i,media:t,playPause:o.playPause}),null}function Ci({x:t,y:e,onChoiceChange:r,registerActions:i,defaultChoices:n,isStatic:s,renderViewerControls:a,renderMediaControls:o,viewControlsDeps:u,mediaControlsDeps:h,strategies:l,throwOnUnknown:p,backgroundStyle:g,alwaysShowBackground:b,keepCanvasScale:d=!1,enableSizes:x=!1,enableYouTube:w=!0,onClickPaintingAnnotation:A,children:S}){const k=fe(),O=Or(k,["deep-zoom"]),[F]=ps(),T=ys(),P=W(),E=v.useMemo(()=>Pr(P),[P]),[C,$]=Co({strategies:l||["images"],defaultChoices:n==null?void 0:n.map(({id:j})=>j)}),X=C.type==="images"?C.choice:void 0,Y=v.useMemo(()=>d?1:Math.max(1,...C.type==="images"?C.images.map(j=>{var V;return(j.width||0)/((V=j.target)==null?void 0:V.spatial.width)}):[]),[d,C]);vs(Y),v.useEffect(()=>{i&&i($)},[C.annotations]),v.useEffect(()=>{if(n)for(const j of n)typeof j.opacity<"u"&&E.applyStyles({id:j.id},"atlas",{opacity:j.opacity})},[n]),v.useLayoutEffect(()=>{r&&r(X)},[X]),Se(T&&(C.type==="images"||C.type==="empty"||C.type==="textual-content"&&a)?"overlay":"none",`canvas-portal-controls-${k==null?void 0:k.id}`,Mt.Provider,a?{value:T||null,children:a(C)}:{},[k,T,C,...u||[]]);const _=Io({maxWidth:256,maxHeight:256});if(!k)return null;const U=k.accompanyingCanvas,J=_&&_.type==="fixed"?m.jsx("world-object",{height:k.height,width:k.width,x:t,y:e,children:m.jsx("world-image",{uri:_.id,target:{x:0,y:0,width:k.width,height:k.height},display:_.width&&_.height?{width:_.width,height:_.height}:void 0,crop:void 0})}):null;if(C.type==="unknown"){if(J)return J;if(p)throw new Error(C.reason||"Unknown image strategy");return null}const ee=m.jsxs(v.Fragment,{children:[F?m.jsx(gt,{page:F}):null,C.annotations&&C.annotations.pages?C.annotations.pages.map(j=>m.jsx(gt,{page:j},j.id)):null,S]}),he=C.type==="images"?C.images.length:0;return m.jsxs(m.Fragment,{children:[m.jsxs("world-object",{height:k.height,width:k.width,x:t,y:e,...O,children:[C.type==="empty"||b?m.jsx(Si,{style:g}):null,C.type==="textual-content"?C.items.map((j,V)=>{var G;return m.jsxs(m.Fragment,{children:[m.jsx(we.HTMLPortal,{onClick:A?oe=>{oe.stopPropagation(),A(j.annotationId,j,oe)}:void 0,target:((G=j.target)==null?void 0:G.spatial)||void 0,children:m.jsx("div",{"data-textual-content":!0,children:m.jsx(Vo,{enableDangerouslySetInnerHTML:!0,children:j.text})})},V),ee]})}):null,C.type==="images"?m.jsxs(m.Fragment,{children:[C.images.map((j,V)=>m.jsx(_r,{isStatic:s,image:j,id:j.id,thumbnail:V===0?_:void 0,selector:j.selector,enableSizes:x,onClick:A?G=>{G.stopPropagation(),A(j.annotationId,j,G)}:void 0},j.id+V)),ee]}):null,C.type==="3d-model"?m.jsx(wi,{model:C.model}):null,C.type==="media"?m.jsx(m.Fragment,{children:C.media.type==="Sound"?m.jsxs(mi,{media:C.media,mediaControlsDeps:h,children:[J,o?o(C):null]}):C.media.type==="Video"?m.jsxs(bi,{media:C.media,mediaControlsDeps:h,children:[J,o?o(C):null]}):C.media.type==="VideoYouTube"&&w?m.jsxs(No,{media:C.media,mediaControlsDeps:h,children:[J,o?o(C):null]}):null}):null]},`${k.id}/${C.type}/${he}`),C.type==="media"&&C.media.type==="Sound"&&U?m.jsx(St,{canvas:U.id,children:m.jsx(Ci,{renderViewerControls:a})}):null]})}function Bo(){const t=v.useContext(We);return t&&t.vault?t.vault:wr()}const zo=v.forwardRef(function(e,r){const i=Ce(),n=Mr(),s=Vn(),{ViewerControls:a,MediaControls:o}=e.components||{};if(v.useImperativeHandle(r,()=>s,[s]),!i)return m.jsx("div",{});let u=0;return m.jsxs(m.Fragment,{children:[e.header,m.jsx(z.Viewer,{height:e.height,mode:e.mode,children:n.map((h,l)=>{const p=u;return u+=h.width+(e.spacing||0),m.jsx(St,{canvas:h.id,children:m.jsx(z.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:p,...e.canvasProps||{},children:e.annotations},h.id)},h.id)})},e.reuseAtlas?"":s.currentSequenceIndex),e.children]})}),z=v.forwardRef(function({children:e,height:r,annotations:i,canvasProps:n,spacing:s,header:a,components:o,mode:u,...h},l){const p=Bo();return m.jsx(Sr,{vault:p,children:m.jsx(Un,{...h,children:m.jsx(zo,{ref:l,height:r,components:o,spacing:s,canvasProps:n,annotations:i,header:a,mode:u,children:e})})})});z.RenderImage=_r;z.RenderCanvas=Ci;z.RenderAnnotationPage=gt;z.RenderAnnotation=qr;z.Viewer=gs;z.CanvasBackground=Si;z.Audio=mi;z.Video=bi;z.Model=wi;z.AudioHTML=gi;z.VideoHTML=xi;z.ModelHTML=Ai;exports.CanvasPanel=z;
110
+ `}),m.jsx("iframe",{className:"video-yt",ref:i,src:`https://www.youtube.com/embed/${e.youTubeId}?enablejsapi=1&origin=${window.location.host}`,referrerPolicy:"no-referrer",sandbox:"allow-scripts allow-same-origin allow-presentation"})]}):null}function Bo({media:t,mediaControlsDeps:e,children:r}){const[{element:i,currentTime:n,progress:s},a,o]=jt({duration:t.duration});return Se("overlay","video-element",No,{element:i,media:t,playPause:o.playPause}),null}function Ci({x:t,y:e,onChoiceChange:r,registerActions:i,defaultChoices:n,isStatic:s,renderViewerControls:a,renderMediaControls:o,viewControlsDeps:u,mediaControlsDeps:p,strategies:l,throwOnUnknown:h,backgroundStyle:g,alwaysShowBackground:b,keepCanvasScale:d=!1,enableSizes:x=!1,enableYouTube:w=!0,onClickPaintingAnnotation:A,children:S}){const k=fe(),O=Or(k,["deep-zoom"]),[F]=hs(),T=vs(),P=W(),E=v.useMemo(()=>Pr(P),[P]),[C,$]=Ro({strategies:l||["images"],defaultChoices:n==null?void 0:n.map(({id:j})=>j)}),X=C.type==="images"?C.choice:void 0,Y=v.useMemo(()=>d?1:Math.max(1,...C.type==="images"?C.images.map(j=>{var V;return(j.width||0)/((V=j.target)==null?void 0:V.spatial.width)}):[]),[d,C]);gs(Y),v.useEffect(()=>{i&&i($)},[C.annotations]),v.useEffect(()=>{if(n)for(const j of n)typeof j.opacity<"u"&&E.applyStyles({id:j.id},"atlas",{opacity:j.opacity})},[n]),v.useLayoutEffect(()=>{r&&r(X)},[X]),Se(T&&(C.type==="images"||C.type==="empty"||C.type==="textual-content"&&a)?"overlay":"none",`canvas-portal-controls-${k==null?void 0:k.id}`,Ct.Provider,a?{value:T||null,children:a(C)}:{},[k,T,C,...u||[]]);const _=jo({maxWidth:256,maxHeight:256});if(!k)return null;const U=k.accompanyingCanvas,J=_&&_.type==="fixed"?m.jsx("world-object",{height:k.height,width:k.width,x:t,y:e,children:m.jsx("world-image",{uri:_.id,target:{x:0,y:0,width:k.width,height:k.height},display:_.width&&_.height?{width:_.width,height:_.height}:void 0,crop:void 0})}):null;if(C.type==="unknown"){if(J)return J;if(h)throw new Error(C.reason||"Unknown image strategy");return null}const ee=m.jsxs(v.Fragment,{children:[F?m.jsx(mt,{page:F}):null,C.annotations&&C.annotations.pages?C.annotations.pages.map(j=>m.jsx(mt,{page:j},j.id)):null,S]}),he=C.type==="images"?C.images.length:0;return m.jsxs(m.Fragment,{children:[m.jsxs("world-object",{height:k.height,width:k.width,x:t,y:e,...O,children:[C.type==="empty"||b?m.jsx(Si,{style:g}):null,C.type==="textual-content"?C.items.map((j,V)=>{var G;return m.jsxs(m.Fragment,{children:[m.jsx(we.HTMLPortal,{onClick:A?oe=>{oe.stopPropagation(),A(j.annotationId,j,oe)}:void 0,target:((G=j.target)==null?void 0:G.spatial)||void 0,children:m.jsx("div",{"data-textual-content":!0,children:m.jsx(Ho,{enableDangerouslySetInnerHTML:!0,children:j.text})})},V),ee]})}):null,C.type==="images"?m.jsxs(m.Fragment,{children:[C.images.map((j,V)=>m.jsx(_r,{isStatic:s,image:j,id:j.id,thumbnail:V===0?_:void 0,selector:j.selector,enableSizes:x,onClick:A?G=>{G.stopPropagation(),A(j.annotationId,j,G)}:void 0},j.id+V)),ee]}):null,C.type==="3d-model"?m.jsx(wi,{model:C.model}):null,C.type==="media"?m.jsx(m.Fragment,{children:C.media.type==="Sound"?m.jsxs(mi,{media:C.media,mediaControlsDeps:p,children:[J,o?o(C):null]}):C.media.type==="Video"?m.jsxs(bi,{media:C.media,mediaControlsDeps:p,children:[J,o?o(C):null]}):C.media.type==="VideoYouTube"&&w?m.jsxs(Bo,{media:C.media,mediaControlsDeps:p,children:[J,o?o(C):null]}):null}):null]},`${k.id}/${C.type}/${he}`),C.type==="media"&&C.media.type==="Sound"&&U?m.jsx(Mt,{canvas:U.id,children:m.jsx(Ci,{renderViewerControls:a})}):null]})}function zo(){const t=v.useContext(We);return t&&t.vault?t.vault:wr()}const Wo=v.forwardRef(function(e,r){const i=Ce(),n=Mr(),s=Hn(),{ViewerControls:a,MediaControls:o}=e.components||{};if(v.useImperativeHandle(r,()=>s,[s]),!i)return m.jsx("div",{});let u=0;return m.jsxs(m.Fragment,{children:[e.header,m.jsx(z.Viewer,{height:e.height,mode:e.mode,children:n.map((p,l)=>{const h=u;return u+=p.width+(e.spacing||0),m.jsx(Mt,{canvas:p.id,children:m.jsx(z.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:h,...e.canvasProps||{},children:e.annotations},p.id)},p.id)})},e.reuseAtlas?"":s.currentSequenceIndex),e.children]})}),z=v.forwardRef(function({children:e,height:r,annotations:i,canvasProps:n,spacing:s,header:a,components:o,mode:u,...p},l){const h=zo();return m.jsx(Sr,{vault:h,children:m.jsx(Vn,{...p,children:m.jsx(Wo,{ref:l,height:r,components:o,spacing:s,canvasProps:n,annotations:i,header:a,mode:u,children:e})})})});z.RenderImage=_r;z.RenderCanvas=Ci;z.RenderAnnotationPage=mt;z.RenderAnnotation=qr;z.Viewer=ms;z.CanvasBackground=Si;z.Audio=mi;z.Video=bi;z.Model=wi;z.AudioHTML=gi;z.VideoHTML=xi;z.ModelHTML=Ai;exports.CanvasPanel=z;
111
111
  //# sourceMappingURL=canvas-panel.js.map