react-iiif-vault 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- import { CanvasNormalized } from '@iiif/presentation-3-normalized';
2
- import { Paintables } from '@iiif/helpers/painting-annotations';
3
- import { ImageServiceLoaderType } from '../../hooks/useLoadImageService';
1
+ import type { CanvasNormalized } from '@iiif/presentation-3-normalized';
2
+ import type { Paintables } from '@iiif/helpers/painting-annotations';
3
+ import type { ImageServiceLoaderType } from '../../hooks/useLoadImageService';
4
4
  interface GetRenderStrategyOptions {
5
5
  canvas: CanvasNormalized | null | undefined;
6
6
  paintables: Paintables;
@@ -0,0 +1,2 @@
1
+ export * from './features/rendering-strategy/get-rendering-strategy';
2
+ export * from './features/rendering-strategy/rendering-utils';
@@ -1,68 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react/jsx-runtime"),y=require("react"),Re=require("@atlas-viewer/atlas"),W=require("@iiif/parser"),Se=require("@atlas-viewer/iiif-image-api");function Li(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:()=>t[r]})}}return e.default=t,Object.freeze(e)}const at=Li(y);function vt(t,e){return vt=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},vt(t,e)}function Fi(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,vt(t,e)}var $i=function(e,r){return e===void 0&&(e=[]),r===void 0&&(r=[]),e.length!==r.length||e.some(function(n,i){return!Object.is(n,r[i])})},Gt={error:null},Di=function(t){Fi(e,t);function e(){for(var n,i=arguments.length,s=new Array(i),a=0;a<i;a++)s[a]=arguments[a];return n=t.call.apply(t,[this].concat(s))||this,n.state=Gt,n.resetErrorBoundary=function(){for(var o,u=arguments.length,d=new Array(u),l=0;l<u;l++)d[l]=arguments[l];n.props.onReset==null||(o=n.props).onReset.apply(o,d),n.reset()},n}e.getDerivedStateFromError=function(i){return{error:i}};var r=e.prototype;return r.reset=function(){this.setState(Gt)},r.componentDidCatch=function(i,s){var a,o;(a=(o=this.props).onError)==null||a.call(o,i,s)},r.componentDidUpdate=function(i,s){var a=this.state.error,o=this.props.resetKeys;if(a!==null&&s.error!==null&&$i(i.resetKeys,o)){var u,d;(u=(d=this.props).onResetKeysChange)==null||u.call(d,i.resetKeys,o),this.reset()}},r.render=function(){var i=this.state.error,s=this.props,a=s.fallbackRender,o=s.FallbackComponent,u=s.fallback;if(i!==null){var d={error:i,resetErrorBoundary:this.resetErrorBoundary};if(at.isValidElement(u))return u;if(typeof a=="function")return a(d);if(o)return at.createElement(o,d);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},e}(at.Component);const qi={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},Je=y.createContext(qi),se=()=>y.useContext(Je);function he({value:t,children:e}){const r=se(),n=y.useMemo(()=>({...r,...t}),[t,r]);return g.jsx(Je.Provider,{value:n,children:e})}var Vi=Object.defineProperty,_i=(t,e,r)=>e in t?Vi(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,pe=(t,e,r)=>(_i(t,typeof e!="symbol"?e+"":e,r),r);const q=function(t){return function(){const e={type:t,getType:()=>t,toString:()=>t};return(r,n)=>({...e,...r!==void 0&&{payload:r},...n!==void 0&&{meta:n}})}},hr="@iiif/IMPORT_ENTITIES",yr="@iiif/MODIFY_ENTITY_FIELD",vr="@iiif/REORDER_ENTITY_FIELD",gr="@iiif/ADD_REFERENCE",gt="@iiif/UPDATE_REFERENCE",mr="@iiif/REMOVE_REFERENCE",xr="@iiif/ADD_METADATA",br="@iiif/REMOVE_METADATA",mt="@iiif/UPDATE_METADATA",Ar="@iiif/REORDER_METADATA",Sr=q(hr)(),Ui=q(yr)(),Hi=q(vr)(),Ni=q(gr)(),Bi=q(mr)(),zi=q(gt)(),Wi=q(xr)(),Qi=q(mt)(),Yi=q(br)(),Gi=q(Ar)(),Ji={importEntities:Sr,modifyEntityField:Ui,reorderEntityField:Hi,addReference:Ni,removeReference:Bi,updateReference:zi,addMetadata:Wi,removeMetadata:Yi,updateMetadata:Qi,reorderMetadata:Gi},wr="@iiif/ADD_MAPPING",Cr="@iiif/ADD_MAPPINGS",Ki=q(wr)(),Zi=q(Cr)(),Mr="@iiif/SET_META_VALUE",Rr="@iiif/SET_META_VALUE_DYNAMIC",Ir="@iiif/UNSET_META_VALUE",Xi=q(Mr)(),es=q(Rr)(),ts=q(Ir)(),Jt={setMetaValue:Xi,setMetaValueDynamic:es,unsetMetaValue:ts},xt="RESOURCE_ERROR",kr="RESOURCE_LOADING",bt="RESOURCE_READY",Tr="@iiif/REQUEST_RESOURCE",jr="@iiif/REQUEST_ERROR",Pr="@iiif/REQUEST_MISMATCH",Er="@iiif/REQUEST_COMPLETE",rs="@iiif/REQUEST_OFFLINE_RESOURCE",ns=q(Tr)(),At=q(jr)(),is=q(Pr)(),ss=q(Er)(),Tt="@iiif/BATCH",as="@iiif/BATCH_IMPORT",St=q(Tt)(),os=(t,e)=>{const{entities:r,resource:n,mapping:i}=W.normalize(e);if(n.id===void 0)return[At({id:t,message:"ID is not defined in resource."})];const s=[Sr({entities:r}),Zi({mapping:i})];return n.id!==t&&(s.push(Ki({id:t,type:n.type})),s.push(is({requestId:t,actualId:n.id}))),s.push(ss({id:t})),s},Kt=Number.isNaN||function(t){return typeof t=="number"&&t!==t};function cs(t,e){return!!(t===e||Kt(t)&&Kt(e))}function Zt(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(!cs(t[r],e[r]))return!1;return!0}function ot(t,e,r){const n=t.iiif.requests[e],i=t.iiif.mapping[e];if(!i||!t.iiif.entities[i][n.resourceUri])return;const s=t.iiif.entities[i][n.resourceUri];if(s&&s[W.HAS_PART]){const a=s[W.HAS_PART].find(o=>r?o[W.PART_OF]===r.id:o[W.PART_OF]===s.id);return W.frameResource(s,a)}return s}function us(t){return t&&typeof t.then=="function"}function Xt(t,e,{waitTimeout:r=30}={}){return(n,i)=>{const s=t.getStore(),a=s.getState(),o=a.iiif.requests[n];if(o){if(o.loadingState===bt){const d=ot(a,n);if(d)return d}switch(o.loadingState){case xt:break;case kr:return(async()=>{let d,l=!1;try{const p=await Promise.race([new Promise((m,A)=>{l||(d=s.subscribe(()=>{const h=s.getState();if(h.iiif.requests[n].loadingState===xt){A();return}if(h.iiif.requests[n].loadingState===bt){const x=ot(h,n);x?m(x):A()}}))}),new Promise((m,A)=>setTimeout(()=>{l=!0,A()},r*60*1e3))]);if(d&&d(),p)return p}catch{d&&d()}})()}}t.dispatch(ns({id:n}));const u=d=>{if(!d)return;!d.id&&!d["@id"]&&(d["@type"]&&(d["@id"]=n),d.id=n);const l=os(n,d);return t.dispatch(St({actions:l})),ot(s.getState(),n)};try{const d=e(n,i);return us(d)?(async()=>{try{return u(await d)}catch(l){throw t.dispatch(At({id:n,message:l.toString()})),l}})():u(d)}catch(d){throw t.dispatch(At({id:n,message:d.toString()})),d}}}function Or(){return{Collection:{},Manifest:{},Canvas:{},AnnotationPage:{},AnnotationCollection:{},Annotation:{},ContentResource:{},Range:{},Service:{},Selector:{},Agent:{}}}const er=t=>{let e;const r=new Set,n=(a,o)=>{const u=typeof a=="function"?a(e):a;if(!Object.is(u,e)){const d=e;e=o??typeof u!="object"?u:Object.assign({},e,u),r.forEach(l=>l(e,d))}},i=()=>e,s={setState:n,getState:i,subscribe:a=>(r.add(a),()=>r.delete(a)),destroy:()=>{r.clear()}};return e=t(n,i,s),s},ls=t=>t?er(t):er,fs=(t,e)=>(r,n,i)=>(i.dispatch=s=>(r(a=>t(a,s),!1,s),s),i.dispatchFromDevtools=!0,{dispatch:(...s)=>i.dispatch(...s),...e}),ps=fs,wt=new Map,Ue=t=>{const e=wt.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([r,n])=>[r,n.getState()])):{}},ds=(t,e,r)=>{if(t===void 0)return{type:"untracked",connection:e.connect(r)};const n=wt.get(r.name);if(n)return{type:"tracked",store:t,...n};const i={connection:e.connect(r),stores:{}};return wt.set(r.name,i),{type:"tracked",store:t,...i}},hs=(t,e={})=>(r,n,i)=>{const{enabled:s,anonymousActionType:a,store:o,...u}=e;let d;try{d=(s??!1)&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!d)return t(r,n,i);const{connection:l,...p}=ds(o,d,u);let m=!0;i.setState=(x,b,S)=>{const w=r(x,b);if(!m)return w;const M=S===void 0?{type:a||"anonymous"}:typeof S=="string"?{type:S}:S;return o===void 0?(l==null||l.send(M,n()),w):(l==null||l.send({...M,type:`${o}/${M.type}`},{...Ue(u.name),[o]:i.getState()}),w)};const A=(...x)=>{const b=m;m=!1,r(...x),m=b},h=t(i.setState,n,i);if(p.type==="untracked"?l==null||l.init(h):(p.stores[p.store]=i,l==null||l.init(Object.fromEntries(Object.entries(p.stores).map(([x,b])=>[x,x===p.store?h:b.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){const x=i.dispatch;i.dispatch=(...b)=>{x(...b)}}return l.subscribe(x=>{var b;switch(x.type){case"ACTION":if(typeof x.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return ct(x.payload,S=>{if(S.type==="__setState"){if(o===void 0){A(S.state);return}Object.keys(S.state).length!==1&&console.error(`
2
- [zustand devtools middleware] Unsupported __setState action format.
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
- and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
5
- `);const w=S.state[o];if(w==null)return;JSON.stringify(i.getState())!==JSON.stringify(w)&&A(w);return}i.dispatchFromDevtools&&typeof i.dispatch=="function"&&i.dispatch(S)});case"DISPATCH":switch(x.payload.type){case"RESET":return A(h),o===void 0?l==null?void 0:l.init(i.getState()):l==null?void 0:l.init(Ue(u.name));case"COMMIT":if(o===void 0){l==null||l.init(i.getState());return}return l==null?void 0:l.init(Ue(u.name));case"ROLLBACK":return ct(x.state,S=>{if(o===void 0){A(S),l==null||l.init(i.getState());return}A(S[o]),l==null||l.init(Ue(u.name))});case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return ct(x.state,S=>{if(o===void 0){A(S);return}JSON.stringify(i.getState())!==JSON.stringify(S[o])&&A(S[o])});case"IMPORT_STATE":{const{nextLiftedState:S}=x.payload,w=(b=S.computedStates.slice(-1)[0])==null?void 0:b.state;if(!w)return;A(o===void 0?w:w[o]),l==null||l.send(null,S);return}case"PAUSE_RECORDING":return m=!m}return}}),h},ys=hs,ct=(t,e)=>{let r;try{r=JSON.parse(t)}catch(n){console.error("[zustand devtools middleware] Could not parse the received json",n)}r!==void 0&&e(r)},vs=t=>(e,r,n)=>{const i=n.subscribe;return n.subscribe=(s,a,o)=>{let u=s;if(a){const d=(o==null?void 0:o.equalityFn)||Object.is;let l=s(n.getState());u=p=>{const m=s(p);if(!d(l,m)){const A=l;a(l=m,A)}},o!=null&&o.fireImmediately&&a(l,l)}return i(u)},t(e,r,n)},gs=vs,ms=(t={},e)=>{switch(e.type){case wr:return{...t,[e.payload.id]:e.payload.type};case Cr:return{...t,...e.payload.mapping};default:return t}};function ut(t,e,r,n){return!(!t[r]||!t[r][e]||!t[r][e][n]||!Array.isArray(t[r][e][n]))}function xs(t,e){const r={},n=[];for(const[i,s]of Object.entries(t||{})){n.push(i);const a=(e||{})[i];if(!a||a.length===0){r[i]=s;continue}r[i]=a}for(const[i,s]of Object.entries(e||{}))n.indexOf(i)===-1&&(r[i]=s);return r}function I(t){return t.payload}function lt(t,e){return typeof t>"u"?e:t}const bs=(t=Or(),e)=>{var r;const n=(i,s)=>({...t,[I(e).type]:{...t[I(e).type],[I(e).id]:{...i,...s}}});switch(e.type){case yr:{if(!t[I(e).type]||!t[I(e).type][I(e).id])return t;const i=t[I(e).type][I(e).id];return typeof i=="string"?t:n(i,{[I(e).key]:I(e).value})}case vr:{if(!ut(t,I(e).id,I(e).type,I(e).key))return t;const i=t[I(e).type][I(e).id];if(typeof i=="string")return t;const s=Array.from(i[I(e).key]),[a]=s.splice(I(e).startIndex,1);return s.splice(I(e).endIndex,0,a),n(i,{[I(e).key]:s})}case hr:{const i=Object.keys(I(e).entities),s={...t};for(const a of i){const o=I(e).entities[a],u={...t[a]||{}};let d=!1;const l=Object.keys(o||{})||[];if(o&&l){for(const p of l)d=!0,u[p]=t[a][p]?xs(t[a][p],o[p]):o[p];d&&(s[a]=u)}}return s}case gr:{if(!ut(t,I(e).id,I(e).type,I(e).key))return t;const i=t[I(e).type][I(e).id],s=Array.from(i[I(e).key]);return s.splice(lt(I(e).index,s.length+1),0,I(e).reference),n(i,{[I(e).key]:s})}case gt:case mr:{if(!ut(t,I(e).id,I(e).type,I(e).key))return t;const i=t[I(e).type][I(e).id],s=Array.from(i[I(e).key]),a=lt(I(e).index,s.findIndex(o=>o&&o.id===I(e).reference.id));return a===-1||((r=s[a])==null?void 0:r.id)!==I(e).reference.id?t:(e.type===gt?s.splice(a,1,I(e).reference):s.splice(a,1),n(i,{[I(e).key]:s}))}case xr:{const i=t[I(e).type][I(e).id];if(!i)return t;const s=Array.from(i.metadata||[]),a=I(e);return s.splice(lt(e.payload.beforeIndex,s.length+1),0,{label:a.label,value:a.label}),n(i,{metadata:s})}case Ar:{const i=t[I(e).type][I(e).id];if(typeof i=="string"||!i)return t;const s=Array.from(i.metadata||[]),[a]=s.splice(I(e).startIndex,1);return s.splice(I(e).endIndex,0,a),n(i,{metadata:s})}case mt:case br:{const i=t[I(e).type][I(e).id],s=Array.from(i.metadata||[]),a=I(e).atIndex;return typeof a>"u"||a===-1||!s[a]?t:(e.type===mt?s.splice(a,1,{label:I(e).label,value:I(e).value}):s.splice(a,1),n(i,{metadata:s}))}default:return t}},As=(t={},e)=>{switch(e.type){case Tr:case rs:return{...t,[e.payload.id]:{requestUri:e.payload.id,loadingState:kr,uriMismatch:!1,resourceUri:e.payload.id}};case Pr: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 jr:return{...t,[e.payload.id]:{...t[e.payload.id]||{},loadingState:xt,error:e.payload.message}};case Er:return{...t,[e.payload.id]:{...t[e.payload.id]||{},loadingState:bt,error:void 0}}}return t},Ss=(t={},e)=>{const{id:r,updateValue:n,value:i,meta:s,key:a}=e&&e.payload||{};switch(e.type){case Mr:return{...t,[r]:{...t[r]||{},[s]:{...t[r]?t[r][s]||{}:{},[a]:i}}};case Rr:return{...t,[r]:{...t[r]||{},[s]:{...t[r]?t[r][s]||{}:{},[a]:t[r]&&t[r][s]?n(t[r][s][a]):n(void 0)}}};case Ir: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 Lr(t={}){const e=Object.keys(t);return function(r={},n){let i=!1;const s={};for(let a=0;a<e.length;a++){const o=e[a];s[o]=t[o](r[o],n),i=i||s[o]!==r[o]}return i?s:r}}function ws(t){return(e,r)=>r&&r.type===Tt?r.payload.actions.reduce(t,e):r&&r.type===as?{...e,iiif:{...e.iiif,...r.payload.state}}:t(e,r)}const Cs=Lr({mapping:ms,entities:bs,requests:As,meta:Ss});function Ms(){return{iiif:{entities:Or(),meta:{},mapping:{},requests:{}}}}function Rs(t={}){const{enableDevtools:e=!1,iiifStoreName:r="iiif",defaultState:n=Ms(),customReducers:i={}}=t,s=ws(Lr({[r]:Cs,...i}));return ls(gs(ys(ps(s,n),{enabled:e})))}function Is(t){return{all:t=t||new Map,on:function(e,r){var n=t.get(e);n?n.push(r):t.set(e,[r])},off:function(e,r){var n=t.get(e);n&&(r?n.splice(n.indexOf(r)>>>0,1):t.set(e,[]))},emit:function(e,r){var n=t.get(e);n&&n.slice().map(function(i){i(r)}),(n=t.get("*"))&&n.slice().map(function(i){i(e,r)})}}}function z(t,e,r,n=!0){e[we]=e[we]||[],e[we].push(t);const i=new Map;Object.defineProperty(e,t,{enumerable:n,get(){if(typeof e[xe][t]>"u")return;const s=e[xe][t];if(!s)return s;const a=r.get(e[xe][t],{parent:this.id?{id:this.id,type:this.type}:void 0});return i.has(a)||(i.clear(),i.set(a,be(a,r))),i.get(a)},set(s){e[xe][t]!==s&&(this[me]?r.modifyEntityField({id:this.id,type:this.type},t,Fr(s)):this[xe][t]=s)}})}const xe=Symbol.for("_refs_"),me=Symbol.for("_reactive_"),we=Symbol.for("_defined_"),tr=Symbol.for("_parent_");function ks(t,e=!1,r){const n={id:"",type:"unknown",[we]:[],[xe]:{},[tr]:r||null,[me]:null,is(i){return typeof i=="string"?this.id===i:i.id?i.id===this.id:!1},reactive(){if(!this[me])return this[me]=this.subscribe(()=>this.refresh(),!0),()=>{this.unreactive()}},refresh(){if(this.id){const i=this.unwrap();for(const s of Object.keys(i||{}))this[we].includes(s)?this[xe][s]=i[s]:this[s]=i[s]}},unreactive(){this[me]&&(this[me](),this[me]=null)},unwrap(){if(!this.id)throw new Error("Invalid object");const i=this[tr];return t.get(this.id,{parent:i?{id:i,type:"unknown"}:void 0})},toPresentation3(){return t.toPresentation3(this.unwrap())},toPresentation2(){return t.toPresentation2(this.unwrap())},valueOf(){return this.unwrap()},toJSON(){const i=this;return{...i,items:i.items,annotations:i.annotations,structures:i.structures,seeAlso:i.seeAlso,service:i.service,services:i.services,rendering:i.rendering,partOf:i.partOf,start:i.start,supplementary:i.supplementary,homepage:i.homepage,thumbnail:i.thumbnail,placeholderCanvas:i.placeholderCanvas,accompanyingCanvas:i.accompanyingCanvas,provider:i.provider}},subscribe(i,s=!0){return t.subscribe(()=>this.id?t.get(this.id):null,i,s)}};return z("items",n,t),z("annotations",n,t),z("structures",n,t),z("seeAlso",n,t),z("rendering",n,t),z("partOf",n,t),z("start",n,t,!1),z("supplementary",n,t),z("homepage",n,t),z("thumbnail",n,t),z("placeholderCanvas",n,t,!1),z("accompanyingCanvas",n,t,!1),z("provider",n,t),z("body",n,t),z("logo",n,t),n}function Ts(t){return!!t[we]}function Fr(t){return Array.isArray(t)?t.map(e=>Fr(e)):!t||!t.type?t:{id:t.id,type:t.type}}function be(t,e,r=!1,n){if(Array.isArray(t))return t.map(o=>be(o,e,r));if(!t||!t.type||!t.id)return t;const i=ks(e,r),s=Object.create(i),a=Object.assign(s,t);return r&&a.reactive(),a}function rr(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 Ct=class{constructor(e,r){pe(this,"options"),pe(this,"store"),pe(this,"emitter"),pe(this,"isBatching",!1),pe(this,"batchQueue",[]),pe(this,"remoteFetcher"),pe(this,"staticFetcher"),pe(this,"defaultFetcher",n=>fetch(n).then(i=>i.json())),this.options=Object.assign({reducers:{},customFetcher:this.defaultFetcher,enableDevtools:!0},e||{}),this.store=r||Rs({customReducers:this.options.reducers,defaultState:this.options.defaultState,enableDevtools:this.options.enableDevtools}),this.emitter=Is(),this.remoteFetcher=Xt(this,this.options.customFetcher),this.staticFetcher=Xt(this,(n,i)=>i)}batch(e){this.isBatching=!0;try{e(this),this.isBatching=!1,this.dispatch(St({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(St({actions:this.batchQueue}))}catch(r){throw this.batchQueue=[],this.isBatching=!1,r}this.batchQueue=[]}modifyEntityField(e,r,n){this.dispatch(Ji.modifyEntityField({id:e.id,type:e.type,key:r,value:n}))}dispatch(e){if(this.isBatching)this.batchQueue.push(e);else{if(e.type===Tt){for(const i of e.payload.actions)this.emitter.emit(i.type,{action:i,state:this.store.getState()});this.store.dispatch(e);const n=this.getState();for(const i of e.payload.actions)this.emitter.emit(`after:${i.type}`,{action:i,state:n});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 W.serialize(this.getState().iiif,e,r)}toPresentation2(e){return this.serialize(e,W.serializeConfigPresentation2)}toPresentation3(e){return this.serialize(e,W.serializeConfigPresentation3)}hydrate(e,r,n={}){return this.get(e,r,{...n,skipSelfReturn:!1})}get(e,r,n={}){typeof r!="string"&&(n=r||{},r=void 0);const{skipSelfReturn:i=!0}=n||{};let s=n.parent?typeof n.parent=="string"?n.parent:n.parent.id:void 0;if(Array.isArray(e))return e.map(p=>this.get(p,n));const a=this.getState();if(W.isSpecificResource(e)&&!n.preserveSpecificResources&&(e=e.source),typeof e=="string"){const p=rr(r||a.iiif.mapping[e]);if(!p)return i?null:{id:e,type:"unknown"};e={id:e,type:p}}if(e&&e.partOf&&!s&&!n.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=rr(r||(e==null?void 0:e.type)),u=e==null?void 0:e.id,d=a.iiif.entities[o];if(!d){const p=a.iiif.requests[u];return p&&p.resourceUri!==u?this.get(p.resourceUri,n):i?null:e}const l=d[e.id];if(l&&l[W.HAS_PART]){const p=l[W.HAS_PART].find(m=>s?m[W.PART_OF]===s:m[W.PART_OF]===l.id);return W.frameResource(l,p)}return d[e.id]||(i?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 i=e(this.get(r,{skipSelfReturn:!1})),s=a=>this.deep(a,i);return s.size=Array.isArray(i)?i.length:1,s}catch{const i=s=>this.deep(s,void 0);return i.size=0,i}const n=i=>this.deep(i,e);return n.size=Array.isArray(e)?e.length:1,n}loadManifest(e,r){const n=typeof e=="string"?e:e.id;return this.load(n,r)}loadCollection(e,r){const n=typeof e=="string"?e:e.id;return this.load(n,r)}load(e,r){const n=typeof e=="string"?e:e.id;return r?Promise.resolve(this.staticFetcher(n,r)):Promise.resolve(this.remoteFetcher(n))}loadSync(e,r){const n=typeof e=="string"?e:e.id;return this.staticFetcher(n,r)}loadManifestSync(e,r){const n=typeof e=="string"?e:e.id;return this.loadSync(n,r)}loadCollectionSync(e,r){const n=typeof e=="string"?e:e.id;return this.loadSync(n,r)}areInputsEqual(e,r){return Zt(e,r)}subscribe(e,r,n){return typeof n>"u"&&(typeof r>"u"||r===!1||r===!0)&&(n=r,r=e,e=i=>i),this.store.subscribe(e,i=>r(i,this),{equalityFn:Zt,fireImmediately:!n})}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 n=this.getState().iiif.meta[e];if(n)return r?n[r]:n}getObject(e,r,n={}){const{reactive:i,...s}=n;return be(this.get(e,r,s),this,i)}async loadObject(e,r){return be(await this.load(e,r),this)}async loadManifestObject(e,r){return be(await this.loadManifest(e,r),this)}async loadCollectionObject(e,r){return be(await this.loadCollection(e,r),this)}wrapObject(e){return be(this.get(e,{skipSelfReturn:!1}),this)}isWrapped(e){return Ts(e)}setMetaValue([e,r,n],i){this.dispatch(typeof i=="function"?Jt.setMetaValueDynamic({id:e,meta:r,key:n,updateValue:i}):Jt.setMetaValue({id:e,meta:r,key:n,value:i}))}};function js(){return typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{}}function $r(t){const e=js();try{const n=e.IIIF_VAULT;if(n)return n}catch{}const r=new Ct(t);try{e.IIIF_VAULT=r}catch{}return r}const $e=y.createContext({vault:null,setVaultInstance:t=>{}});function jt({vault:t,vaultOptions:e,useGlobal:r,resources:n,children:i}){const[s,a]=y.useState(()=>t||(r?$r(e):e?new Ct(e):new Ct));return g.jsx($e.Provider,{value:{vault:s,setVaultInstance:a},children:g.jsx(he,{value:n||{},children:i})})}const V=()=>{const{vault:t}=y.useContext($e);if(t===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return t};function Pt(t,{noCache:e=!1}={}){const r=typeof t=="string"?t:t.id,n=V(),[i,s]=y.useState(r),[a,o]=y.useState(void 0),u=y.useMemo(()=>n.get(r,{skipSelfReturn:!0})||void 0,[r,n]),[d,l]=y.useState(u);return y.useEffect(()=>{(async()=>{try{const p=u&&!e?u:await n.load(r),m=p?p.id||p["@id"]:null;p&&i!==m&&s(m),l(p)}catch(p){o(p)}})()},[r,e]),{isLoaded:!!d,id:i,requestId:r,error:a,resource:d,cached:!!(d&&d===u)}}function Dr(t,e){const{id:r,isLoaded:n,error:i,resource:s,requestId:a,cached:o}=Pt(t,e);return{id:r,isLoaded:n,error:i,manifest:s,requestId:a,cached:o}}function qr({manifest:t,children:e}){return g.jsx(he,{value:{manifest:t},children:e})}function Ke({canvas:t,children:e}){return g.jsx(he,{value:{canvas:t},children:e})}function U(t,e=[]){const r=V(),[n,i]=y.useState(()=>t(r.getState(),r));return y.useEffect(()=>r.subscribe(s=>t(s,r),s=>{i(s)},!1),e),n}const De=y.createContext([]);function Et(){const t=y.useContext(De);return U(e=>t.map(r=>e.iiif.entities.Canvas[r]).filter(Boolean),[t])}function ye(t={},e=[]){const{id:r,selector:n}=t,i=se();V();const s=r||i.manifest,a=U(o=>s?o.iiif.entities.Manifest[s]:void 0,[s]);return y.useMemo(()=>{if(a)return n?n(a):a},[a,n,...e])}function Vr({range:t,children:e}){return g.jsx(he,{value:{range:t},children:e})}function _r(t,e){for(const r of e.items){if(r.type==="Canvas")return r;if(r.type==="SpecificResource")return r.source;if(r.type==="Range"){const n=_r(t,t.get(r));if(n)return n}}return null}function Ot(t,e){var n;const r=[];for(const i of e.items)if(i.type==="SpecificResource"&&((n=i.source)==null?void 0:n.type)==="Canvas"&&(i.source.id.indexOf("#")!==-1?r.push({id:i.source.id.split("#")[0],type:"Canvas"}):r.push(i.source)),i.type==="Range"&&r.push(...Ot(t,t.get(i))),i.type==="SpecificResource"){const s=typeof i.source=="string"?i.source:i.source.id;r.push({id:s,type:"Canvas"})}return r}function Ps(t,e,r){for(const n of e.structures){const i=Lt(t,t.get(n),r);if(i)return i}return null}function Lt(t,e,r){var n,i,s;for(const a of e.items){const o=(i=(n=a==null?void 0:a.source)==null?void 0:n.id)==null?void 0:i.split("#")[0];if(a.type==="SpecificResource"&&a.source===r||a.type==="SpecificResource"&&((s=a.source)==null?void 0:s.type)==="Canvas"&&r===o)return e;if(a.type==="Range"){const u=Lt(t,t.get(a),r);if(u)return u}}return null}function Es(t,e,r,n=!1){const i=e.behavior,s=r?t.get(r):null;if(!s)return[];const a=s.behavior,o=n?!1:i.includes("paged"),u=o?!1:i.includes("continuous"),d=o||u?!1:i.includes("individuals"),l=a.includes("facing-pages"),p=a.includes("non-paged");if(l||p||d||n)return[{id:s.id,type:"Canvas"}];const[m,A]=Ft(t,e);if(u)return m;const h=m.findIndex(x=>x.id===r);if(h===-1)return[];for(const x of A)if(x.includes(h))return x.map(b=>m[b]);return[{id:s.id,type:"Canvas"}]}function Ft(t,e,{disablePaging:r,skipNonPaged:n}={}){const i=e.behavior,s=i.includes("paged"),a=s?!1:i.includes("continuous"),o=s||a?!1:i.includes("individuals"),u=e.type==="Manifest"?e.items:Ot(t,e);if(a)return[u,[u.map((h,x)=>x)]];if(o||!s||r)return[u,u.map((h,x)=>[x])];const d=[];let l=[];const p=()=>{l.length&&(d.push([...l]),l=[])};let m=0,A=!1;for(let h=0;h<u.length;h++){const x=t.get(u[h]);if(x.behavior.includes("non-paged")){h===m&&m++,n||(p(),d.push([h]),p());continue}if(h===m||x.behavior.includes("facing-pages")){l.length&&(A=!0),p(),d.push([h]),p();continue}if(l.push(h),A){p(),A=!1;continue}l.length>1&&p()}return l.length&&p(),[u,d]}function Ur(t={},e=[]){const{id:r,selector:n}=t,i=se(),s=r||i.range,a=U(o=>s?o.iiif.entities.Range[s]:void 0,[s]);return y.useMemo(()=>{if(a)return n?n(a):a},[a,n,...e])}function Hr({startCanvas:t,disablePaging:e}){var h;const r=V(),n=ye(),i=Ur(),[s,a]=y.useState(void 0),o=i||n;if(!o)throw new Error("Nothing selected");const[u,d]=y.useMemo(()=>Ft(r,o,{disablePaging:e}),[r,o]),l=y.useCallback(x=>{const b=d.findIndex(S=>S.includes(x));a(b===-1?0:b)},[u,d]),p=y.useCallback(x=>{const b=u.findIndex(S=>S.id===x);b!==-1?l(b):a(0)},[u,d]),m=y.useCallback(()=>{a(x=>x>=d.length?x:x+1)},[d]),A=y.useCallback(()=>{a(x=>x<=0?0:x-1)},[d]);return typeof s>"u"&&(t?p(t):a(0)),{visibleItems:((h=d[s])==null?void 0:h.map(x=>u[x].id))||[],cursor:s,items:u,sequence:d,setSequenceIndex:a,setCanvasIndex:l,setCanvasId:p,next:m,previous:A}}const ke=()=>{},qe=y.createContext({setCurrentCanvasId:ke,setCurrentCanvasIndex:ke,nextCanvas:ke,previousCanvas:ke,items:[],sequence:[],setSequenceIndex:ke,currentSequenceIndex:0});function Nr(t){const e=ye(),{cursor:r,visibleItems:n,next:i,sequence:s,items:a,setCanvasIndex:o,setCanvasId:u,previous:d,setSequenceIndex:l}=Hr({startCanvas:t.startCanvas,disablePaging:t.pagingEnabled===!1}),p=y.useMemo(()=>({sequence:s,items:a,setCurrentCanvasId:u,nextCanvas:i,previousCanvas:d,totalCanvases:a.length,setCurrentCanvasIndex:o,setSequenceIndex:l,currentSequenceIndex:r}),[s,a,u,i,d,a,o,l,r]);return e?n.length===0?null:g.jsx(qe.Provider,{value:p,children:g.jsx(De.Provider,{value:n,children:g.jsx(Ke,{canvas:n[0],children:t.children})})}):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),g.jsx("div",{children:"Sorry, something went wrong."}))}function Br(t){const e=Dr(t.manifest);if(!e)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),g.jsx("div",{children:"Sorry, something went wrong."});if(e.error)return g.jsx("div",{children:e.error.toString()});if(!e.isLoaded)return g.jsx("div",{children:"Loading..."});const r=g.jsx(Nr,{...t,children:t.children});return g.jsx(qr,{manifest:e.id,children:t.rangeId?g.jsx(Vr,{range:t.rangeId,children:r}):r})}function zr(){return y.useContext(qe)}function Wr(){return{VaultContext:y.useContext($e),ResourceContext:y.useContext(Je),SimpleViewerReactContext:y.useContext(qe),VisibleCanvasReactContext:y.useContext(De)}}function Qr(t){return g.jsx(jt,{vault:t.bridge.VaultContext.vault||void 0,resources:t.bridge.ResourceContext,children:g.jsx(De.Provider,{value:t.bridge.VisibleCanvasReactContext,children:g.jsx(qe.Provider,{value:t.bridge.SimpleViewerReactContext,children:t.children})})})}const te=function(t){return function(){const e={type:t,getType:()=>t,toString:()=>t};return(r,n)=>({...e,...r!==void 0&&{payload:r},...n!==void 0&&{meta:n}})}},Os="@iiif/IMPORT_ENTITIES",Ls="@iiif/MODIFY_ENTITY_FIELD",Fs="@iiif/REORDER_ENTITY_FIELD",$s="@iiif/ADD_REFERENCE",Ds="@iiif/UPDATE_REFERENCE",qs="@iiif/REMOVE_REFERENCE",Vs="@iiif/ADD_METADATA",_s="@iiif/REMOVE_METADATA",Us="@iiif/UPDATE_METADATA",Hs="@iiif/REORDER_METADATA",Ns=te(Os)(),Bs=te(Ls)(),zs=te(Fs)(),Ws=te($s)(),Qs=te(qs)(),Ys=te(Ds)(),Gs=te(Vs)(),Js=te(Us)(),Ks=te(_s)(),Zs=te(Hs)(),ft={importEntities:Ns,modifyEntityField:Bs,reorderEntityField:zs,addReference:Ws,removeReference:Qs,updateReference:Ys,addMetadata:Gs,removeMetadata:Ks,updateMetadata:Js,reorderMetadata:Zs};function Yr(){const e=V().getStore();return y.useMemo(()=>r=>e.dispatch(r),[e])}function nr(t){return typeof t!="string"&&t&&t.bindToVault}function Gr(){const t=V(),e=y.useRef([]),r=Yr(),n=y.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);y.useLayoutEffect(()=>{const o={id:n,type:"AnnotationPage",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],rendering:[],service:[]};r(ft.importEntities({entities:{AnnotationPage:{[o.id]:o}}}))},[n]);const i=U(o=>n?o.iiif.entities.AnnotationPage[n]:null,[n]),s=y.useCallback((o,u)=>{if(n){if(nr(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 d=t.get({id:n,type:"AnnotationPage"}),l=t.get({id:o,type:"Annotation"});d&&l&&(d.items.find(p=>p.id===l.id)||r(ft.addReference({id:n,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"},index:u})))}},[n]),a=y.useCallback(o=>{n&&(nr(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:n,type:"AnnotationPage"})&&r(ft.removeReference({id:n,type:"AnnotationPage",key:"items",reference:{id:o,type:"Annotation"}})))},[n]);return[i,{addAnnotation:s,removeAnnotation:a}]}const Jr=y.createContext(null);function Kr(){const t=y.useContext(Jr);return[t.fullPage,{addAnnotation:t.addAnnotation,removeAnnotation:t.removeAnnotation}]}function Zr({children:t}){const[e,{addAnnotation:r,removeAnnotation:n}]=Gr();return g.jsx(Jr.Provider,{value:y.useMemo(()=>({fullPage:e,addAnnotation:r,removeAnnotation:n}),[e]),children:t})}function Xs({width:t,style:e,height:r,error:n,resetErrorBoundary:i}){return g.jsxs("div",{style:{width:t,height:r,minHeight:500,...e||{},background:"#f9f9f9"},children:[g.jsx("h3",{children:"Error occurred"}),g.jsx("p",{children:n.message}),g.jsx("button",{onClick:i,children:"Reset"})]})}const Ze=y.createContext(null);function Xr(){return y.useContext(Ze)}const en=y.createContext(()=>{}),tn=y.createContext(()=>{});function Ie(t,e,r,n,i=[]){const s=y.useContext(t==="portal"?tn:en);y.useEffect(()=>(t!=="none"&&s(e,r,n),()=>{s(e,null)}),[e,t,s,...i])}function re(t={},e=[]){const{id:r,selector:n}=t,i=se(),s=r||i.canvas,a=U(o=>s?o.iiif.entities.Canvas[s]:void 0,[s]);return y.useMemo(()=>{if(a)return n?n(a):a},[a,n,...e])}const rn=y.createContext(()=>{});function ea(t){const e=re(),r=y.useContext(rn);y.useEffect(()=>e&&e.id?(r(e.id,t),()=>r(e.id,-1)):()=>{},[e,t])}function ta({children:t,errorFallback:e,outerContainerProps:r={},worldScale:n,...i}){const[s,a]=y.useState(),o=Wr(),u=e||Xs,[d,l]=y.useState({}),p=Object.entries(d),[m,A]=y.useState({}),h=Object.entries(m),[x,b]=y.useState({}),S=y.useMemo(()=>n||Math.max(...Object.values(x)),[x]),w=y.useMemo(()=>({maxOverZoom:S||1,...i.runtimeOptions||{}}),[S,i.runtimeOptions]),M=y.useCallback((k,O)=>{b(E=>{if(O===-1){const{[k]:R,...$}=E;return $}return{...E,[k]:O}})},[]),T=y.useCallback((k,O,E)=>{l(({[k]:R,...$})=>O?{...$,[k]:{element:O,props:E}}:$)},[]),F=y.useCallback((k,O,E)=>{A(({[k]:R,...$})=>O?{...$,[k]:{element:O,props:E}}:$)},[]);return g.jsxs(Di,{resetKeys:[],fallbackRender:k=>g.jsx(u,{...i,...k}),children:[g.jsx(Re.AtlasAuto,{...i,containerProps:{style:{position:"relative"},...i.containerProps||{}},htmlChildren:g.jsx(g.Fragment,{children:p.map(([k,{element:O,props:E}])=>g.jsx(y.Fragment,{children:g.jsx(O,{...E||{}})},k))}),onCreated:k=>{a(k),i.onCreated&&i.onCreated(k)},runtimeOptions:w,children:g.jsx(Ze.Provider,{value:s,children:g.jsx(rn.Provider,{value:M,children:g.jsx(en.Provider,{value:T,children:g.jsx(tn.Provider,{value:F,children:g.jsx(Qr,{bridge:o,children:g.jsx(Re.ModeContext.Provider,{value:i.mode||"explore",children:g.jsx(Zr,{children:t})})})})})})})}),g.jsx("div",{children:h.map(([k,{element:O,props:E}])=>g.jsx(y.Fragment,{children:g.jsx(O,{...E||{}})},k))})]})}const He={},nn={get(t){return t},setMetaValue([t,e,r],n){const i=nn.getResourceMeta(t,e),s=i?i[r]:void 0,a=typeof n=="function"?n(s):n;He[t]={...He[t]||{},[e]:{...(He[t]||{})[e]||{},[r]:a}}},getResourceMeta:(t,e)=>{const r=He[t];if(r)return e?r[e]:r}};function sn(t=nn){return{addEventListener(e,r,n,i){if(e)return t.setMetaValue([e.id,"eventManager",r],s=>{const a=s||[];for(const o of a)if(o.callback===n)return a;return[...a,{callback:n,scope:i}]}),n},removeEventListener(e,r,n){e&&t.setMetaValue([e.id,"eventManager",r],i=>(i||[]).filter(s=>s.callback!==n))},getListenersAsProps(e,r){const n=typeof e=="string"?{id:e}:e;if(!n||!n.id)return{};const i=t.getResourceMeta(n.id,"eventManager"),s={};if(i&&n)for(const a of Object.keys(i))s[a]=o=>{const u=t.get(n);for(const{callback:d,scope:l}of i[a]||[])(!l||r&&l.indexOf(r)!==-1)&&d(o,u)};return s}}}function $t(t,e){const r=V(),n=y.useMemo(()=>sn(r),[r]),i=U(()=>t&&t.id?r.getResourceMeta(t.id,"eventManager"):null,[t]);return y.useMemo(()=>t?n.getListenersAsProps(t,e):{},[i,t,r,e])}const Ne={},an={get(t){return t},setMetaValue([t,e,r],n){const i=an.getResourceMeta(t,e),s=i?i[r]:void 0,a=typeof n=="function"?n(s):n;Ne[t]={...Ne[t]||{},[e]:{...(Ne[t]||{})[e]||{},[r]:a}}},getResourceMeta:(t,e)=>{const r=Ne[t];if(r)return e?r[e]:r}};function Dt(t=an){return{applyStyles(e,r,n){const i=typeof e=="string"?e:e.id;return t.setMetaValue([i,"styles",r],n)},getAppliedStyles(e){const r=typeof e=="string"?e:e.id;return t.getResourceMeta(r,"styles")}}}function Fe(t,e){const r=V(),n=y.useMemo(()=>Dt(r),[r]);return U(()=>{if(!t)return null;const i=n.getAppliedStyles(t.id);return i?e?i[e]:i:void 0},[t,e])}var ra=Object.defineProperty,na=(t,e,r)=>e in t?ra(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,We=(t,e,r)=>(na(t,typeof e!="symbol"?e+"":e,r),r),ia=function(){function t(e,r){var n=[],i=!0,s=!1,a=void 0;try{for(var o=e[Symbol.iterator](),u;!(i=(u=o.next()).done)&&(n.push(u.value),!(r&&n.length===r));i=!0);}catch(d){s=!0,a=d}finally{try{!i&&o.return&&o.return()}finally{if(s)throw a}}return n}return function(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,pt=function(t,e,r,n,i,s,a){var o=t.x,u=t.y;o*=e,u*=r;var d=n*o-i*u,l=i*o+n*u;return{x:d+s,y:l+a}},sa=function(t,e){var r=e===1.5707963267948966?.551915024494:e===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(e/4),n=Math.cos(t),i=Math.sin(t),s=Math.cos(t+e),a=Math.sin(t+e);return[{x:n-i*r,y:i+n*r},{x:s+a*r,y:a-s*r},{x:s,y:a}]},ir=function(t,e,r,n){var i=t*n-e*r<0?-1:1,s=t*r+e*n;return s>1&&(s=1),s<-1&&(s=-1),i*Math.acos(s)},aa=function(t,e,r,n,i,s,a,o,u,d,l,p){var m=Math.pow(i,2),A=Math.pow(s,2),h=Math.pow(l,2),x=Math.pow(p,2),b=m*A-m*x-A*h;b<0&&(b=0),b/=m*x+A*h,b=Math.sqrt(b)*(a===o?-1:1);var S=b*i/s*p,w=b*-s/i*l,M=d*S-u*w+(t+r)/2,T=u*S+d*w+(e+n)/2,F=(l-S)/i,k=(p-w)/s,O=(-l-S)/i,E=(-p-w)/s,R=ir(1,0,F,k),$=ir(F,k,O,E);return o===0&&$>0&&($-=je),o===1&&$<0&&($+=je),[M,T,R,$]},oa=function(t){var e=t.px,r=t.py,n=t.cx,i=t.cy,s=t.rx,a=t.ry,o=t.xAxisRotation,u=o===void 0?0:o,d=t.largeArcFlag,l=d===void 0?0:d,p=t.sweepFlag,m=p===void 0?0:p,A=[];if(s===0||a===0)return[];var h=Math.sin(u*je/360),x=Math.cos(u*je/360),b=x*(e-n)/2+h*(r-i)/2,S=-h*(e-n)/2+x*(r-i)/2;if(b===0&&S===0)return[];s=Math.abs(s),a=Math.abs(a);var w=Math.pow(b,2)/Math.pow(s,2)+Math.pow(S,2)/Math.pow(a,2);w>1&&(s*=Math.sqrt(w),a*=Math.sqrt(w));var M=aa(e,r,n,i,s,a,l,m,h,x,b,S),T=ia(M,4),F=T[0],k=T[1],O=T[2],E=T[3],R=Math.abs(E)/(je/4);Math.abs(1-R)<1e-7&&(R=1);var $=Math.max(Math.ceil(R),1);E/=$;for(var X=0;X<$;X++)A.push(sa(O,E)),O+=E;return A.map(function(Y){var _=pt(Y[0],s,a,x,h,F,k),H=_.x,J=_.y,ee=pt(Y[1],s,a,x,h,F,k),ge=ee.x,P=ee.y,N=pt(Y[2],s,a,x,h,F,k),G=N.x,ue=N.y;return{x1:H,y1:J,x2:ge,y2:P,x:G,y:ue}})};function on(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var ca=la,dt={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},ua=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function la(t){var e=[];return t.replace(ua,function(r,n,i){var s=n.toLowerCase();for(i=pa(i),s=="m"&&i.length>2&&(e.push([n].concat(i.splice(0,2))),s="l",n=n=="m"?"l":"L");;){if(i.length==dt[s])return i.unshift(n),e.push(i);if(i.length<dt[s])throw new Error("malformed path data");e.push([n].concat(i.splice(0,dt[s])))}}),e}var fa=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function pa(t){var e=t.match(fa);return e?e.map(Number):[]}const da=on(ca);var ha=ya;function ya(t){var e=0,r=0,n=0,i=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]+=n,s[7]+=i;break;case"v":s[1]+=i;break;case"h":s[1]+=n;break;default:for(var u=1;u<s.length;)s[u++]+=n,s[u++]+=i}switch(o){case"Z":n=e,i=r;break;case"H":n=s[1];break;case"V":i=s[1];break;case"M":n=e=s[1],i=r=s[2];break;default:n=s[s.length-2],i=s[s.length-1]}return s})}const va=on(ha);function ga(t){const e=da(t),r=va(e);let n,i=0,s=0,a=0,o=0,u,d,l=0,p=0;const m=[];for(let A=0;A<r.length;A++){let h=r[A];const x=h[0];switch(x){case"M":i=h[1],s=h[2];break;case"H":h=["L",h[1],s];break;case"V":h=["L",i,h[1]];break;case"S":{let b=l,S=p;(n==="C"||n=="S")&&(b+=b-a,S+=S-o),h=["C",b,S,h[1],h[2],h[3],h[4]]}break;case"T":n==="Q"||n=="T"?(u=l*2-u,d=p*2-d):(u=l,d=p),h=["Q",u,d,h[1],h[2]];break;case"Q":u=h[1],d=h[2];break;case"A":{const b=oa({px:l,py:p,cx:h[6],cy:h[7],rx:h[1],ry:h[2],xAxisRotation:h[3],largeArcFlag:h[4],sweepFlag:h[5]});if(!b.length)continue;for(const[S,w]of b.entries())h=["C",w.x1,w.y1,w.x2,w.y2,w.x,w.y],S<b.length-1&&m.push(h);h=h}break;case"Z":h=["L",i,s];break}n=x,l=h[h.length-2],p=h[h.length-1],["C","Q","A"].indexOf(x)>-1?(a=h[h.length-4],o=h[h.length-3]):(a=l,o=p),m.push(h)}return m}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
6
- *
7
- * All code in this module is based on JavaScript code by Raph Levien, published on his blog at
8
- * https://raphlinus.github.io/.
9
- * I merely changed the structure a bit, removed some unneeded parts and added some comments and type hints.
10
- *
11
- * Flattening of quadratic Bézier curves:
12
- * - Article: https://raphlinus.github.io/graphics/curves/2019/12/23/flatten-quadbez.html
13
- * - Code: https://github.com/raphlinus/raphlinus.github.io/blob/master/_posts/2019-12-23-flatten-quadbez.md?plain=1#L73-L212
14
- *
15
- * Flattening of cubic Bézier curves: https://levien.com/tmp/flatten.html
16
- *
17
- * Note that the code in this module has a different license than the rest of the package,
18
- * due to the inclusion of Apache-licensed third party code.
19
- *
20
- * @license
21
- * Copyright 2022 Johannes Baiter <johannes.baiter@gmail.com>
22
- * Copyright 2019, 2022 Raph Levien <raph.levien@gmail.com>
23
- *
24
- * Licensed under the Apache License, Version 2.0 (the "License");
25
- * you may not use this file except in compliance with the License.
26
- * You may obtain a copy of the License at
27
- *
28
- * http://www.apache.org/licenses/LICENSE-2.0
29
- *
30
- * Unless required by applicable law or agreed to in writing, software
31
- * distributed under the License is distributed on an "AS IS" BASIS,
32
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33
- * See the License for the specific language governing permissions and
34
- * limitations under the License.
35
- */function ma(t,e,r,n=1){return new cn(t,e,r).subdivide(n)}function xa(t,e,r,n,i=1){return new qt(new Float64Array([t.x,t.y,e.x,e.y,r.x,r.y,n.x,n.y])).subdivide(i)}function ba(t){return t.x*t.x+t.y*t.y}function Pe(t){return t/(1-.67+Math.pow(Math.pow(.67,4)+.25*t*t,.25))}function Ce(t){return t*(1-.39+Math.sqrt(.39*.39+.25*t*t))}class cn{constructor(e,r,n){We(this,"start"),We(this,"control"),We(this,"end"),this.start=e,this.control=r,this.end=n}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:n,y:i}=this.control,{x:s,y:a}=this.end,o=2*n-e-s,u=2*i-r-a,d=(n-e)*o+(i-r)*u,l=(s-n)*o+(a-i)*u,p=(s-e)*u-(a-r)*o,m=d/p,A=l/p,h=Math.abs(p)/(Math.hypot(o,u)*Math.abs(A-m));return{x0:e,x2:s,scale:h,cross:p}}subdivide(e){const r=this.mapToBasic(),n=Pe(r.x0),i=Pe(r.x2),s=.5*Math.abs(i-n)*Math.sqrt(r.scale/e),a=Math.ceil(s),o=Ce(n),u=Ce(i),d=[0];for(let l=1;l<a;l++){const p=(Ce(n+(i-n)*l/a)-o)/(u-o);d.push(p)}return d.push(1),d.map(l=>this.eval(l))}}class qt{constructor(e){We(this,"c"),this.c=e}weightsum(e,r,n,i){const s=e*this.c[0]+r*this.c[2]+n*this.c[4]+i*this.c[6],a=e*this.c[1]+r*this.c[3]+n*this.c[5]+i*this.c[7];return{x:s,y:a}}eval(e){const r=1-e,n=r*r*r,i=3*r*r*e,s=3*r*e*e,a=e*e*e;return this.weightsum(n,i,s,a)}deriv(e){const r=1-e,n=-3*r*r,i=3*e*e,s=-6*e*r-n,a=6*e*r-i;return this.weightsum(n,s,a,i)}midpoint_quadbez(){const e=this.weightsum(-.25,.75,.75,-.25);return new cn({x:this.c[0],y:this.c[1]},e,{x:this.c[6],y:this.c[7]})}subsegment(e,r){const n=new Float64Array(8),i=this.eval(e),s=this.eval(r);n[0]=i.x,n[1]=i.y;const a=(r-e)/3,o=this.deriv(e);n[2]=i.x+a*o.x,n[3]=i.y+a*o.y;const u=this.deriv(r);return n[4]=s.x-a*u.x,n[5]=s.y-a*u.y,n[6]=s.x,n[7]=s.y,new qt(n)}subdivide(e){const r=.1*e,n=e-r,i=Math.sqrt(n),s=ba(this.weightsum(1,-3,3,-1)),a=Math.ceil(Math.pow(s/(432*r*r),1/6)),o=[];let u=0;for(let h=0;h<a;h++){const x=h/a,b=(h+1)/a,S=this.subsegment(x,b).midpoint_quadbez(),w=S.mapToBasic(),M=Pe(w.x0),T=Pe(w.x2),F=Math.sqrt(w.scale);let k=Math.abs(T-M)*F;if(Math.sign(w.x0)!=Math.sign(w.x2)){const O=i/F,E=i*Math.abs(T-M)/Pe(O);k=Math.max(k,E)}o.push({quad:S,a0:M,a2:T,val:k}),u+=k}const d=.5*u/i,l=Math.ceil(d),p=[{x:this.c[0],y:this.c[1]}];let m=0,A=0;for(let h=1;h<l;h++){const x=u*h/l;for(;m+o[A].val<x;)m+=o[A].val,A++;const b=o[A].a0,S=o[A].a2,w=Ce(b),M=Ce(S),T=b+(S-b)*(x-m)/o[A].val,F=(Ce(T)-w)/(M-w);p.push(o[A].quad.eval(F))}return p.push({x:this.c[6],y:this.c[7]}),p}}const Aa=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,Sa=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,sr=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function Ee(t,{domParser:e,svgPreprocessor:r,iiifRenderingHints:n}={}){if(Array.isArray(t))return K(t.reduce((i,s)=>{const{selector:a,selectors:o,iiifRenderingHints:u}=Ee(s,{domParser:e,svgPreprocessor:r,iiifRenderingHints:n});return a&&(i.selector||(i.selector=a),i.selectors.push(...o)),u&&(i.iiifRenderingHints=i.iiifRenderingHints||{type:"ImageApiSelector"},Object.assign(i.iiifRenderingHints,u)),i},{selector:null,selectors:[],iiifRenderingHints:n}));if(!t)return K({selector:null,selectors:[],iiifRenderingHints:n});if(typeof t=="string"){const[i,s]=t.split("#");return s?Ee({type:"FragmentSelector",value:s},{svgPreprocessor:r,iiifRenderingHints:n,domParser:e}):K({selector:null,selectors:[],iiifRenderingHints:n})}if(t.type&&t.type==="PointSelector"&&(t.t||t.t===0)){const i={type:"TemporalSelector",temporal:{startTime:t.t}};return K({selector:i,selectors:[i],iiifRenderingHints:n})}if(ln(t)){const i=[];if(t.region){const s=Ee({type:"FragmentSelector",value:"xywh="+t.region},{domParser:e,svgPreprocessor:r,iiifRenderingHints:n});i.push(...s.selectors)}return K({selector:i[0],selectors:i,iiifRenderingHints:n?{...n,...t}:t})}if(t.type==="FragmentSelector"){const i=Aa.exec(t.value);if(i){const a={type:"BoxSelector",spatial:{unit:i[2]==="percent:"||i[2]==="pct:"?"percent":"pixel",x:parseFloat(i[3]),y:parseFloat(i[4]),width:parseFloat(i[5]),height:parseFloat(i[6])}};return K({selector:a,selectors:[a],iiifRenderingHints:n})}const s=t.value.match(Sa);if(s){const a={type:"TemporalSelector",temporal:{startTime:s[4]?parseFloat(s[4]):0,endTime:s[7]?parseFloat(s[7]):void 0}};return K({selector:a,selectors:[a],iiifRenderingHints:n})}return K({selector:null,selectors:[],iiifRenderingHints:n})}if(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 i=[],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:n});const p=un(l);p&&(i=p.points,u=p.shapeType,s=[Math.min(...i.map(m=>m[0])),Math.min(...i.map(m=>m[1])),Math.max(...i.map(m=>m[0])),Math.max(...i.map(m=>m[1]))],{style:a,svg:o}=Ma(p.element)??{svg:o})}const d={type:"SvgSelector",svg:o,svgShape:u,style:a,points:i.length?i:void 0,spatial:s?{unit:"pixel",x:s[0],y:s[1],width:s[2]-s[0],height:s[3]-s[1]}:void 0};return K({selector:d,selectors:[d],iiifRenderingHints:n})}return K({selector:null,selectors:[],iiifRenderingHints:n})}function wa(t){const e=t.map(n=>n[0]).reduce((n,i)=>(n[i]+=1,n),{C:0,Q:0,L:0,M:0}),r=new Set(t.map(n=>n[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 n=t.slice(-1)[0];return t[0][0]==="M"&&n[0]==="L"&&n[1]==t[0][1]&&n[2]===t[0][2]||n[1]===0&&n[2]===0?"polygon":"polyline"}return"path"}function un(t){var e;for(const r of Array.from(t.children))switch(r==null?void 0:r.tagName.toLowerCase()){case"g":{const n=un(r);if(n)return n}continue;case"path":{const n=r.getAttribute("d");if(!n)continue;const i=ga(n);return{element:r,points:Ca(i),shapeType:wa(i)}}case"circle":{const n=parseFloat(r.getAttribute("cx")??"0"),i=parseFloat(r.getAttribute("cy")??"0"),s=parseFloat(r.getAttribute("r")??"0");if(!s)continue;const a=[];for(let o=0;o<=360;o+=12){const u=o*Math.PI/180;a.push([n+s*Math.cos(u),i+s*Math.sin(u)])}return{element:r,points:a,shapeType:"circle"}}case"ellipse":{const n=parseFloat(r.getAttribute("cx")??"0"),i=parseFloat(r.getAttribute("cy")??"0"),s=parseFloat(r.getAttribute("rx")??"0"),a=parseFloat(r.getAttribute("ry")??"0");if(!s&&!a)continue;const o=[];for(let u=0;u<=360;u+=12){const d=Math.tan(u/360*Math.PI),l=s*(1-d**2)/(1+d**2),p=a*2*d/(1+d**2);o.push([n+l,i+p])}return{element:r,points:o,shapeType:"ellipse"}}case"line":{const n=parseFloat(r.getAttribute("x0")??"0"),i=parseFloat(r.getAttribute("y0")??"0"),s=parseFloat(r.getAttribute("x1")??"0"),a=parseFloat(r.getAttribute("y1")??"0");if(n===s&&i===a)continue;return{element:r,points:[[n,i],[s,a]],shapeType:"polyline"}}case"polygon":case"polyline":{const n=((e=r.getAttribute("points"))==null?void 0:e.split(" ").map(s=>s.split(",").map(parseFloat)))??[];if(!n.length)continue;let i="polyline";return r.tagName.toLowerCase()==="polygon"&&(n.push(n[0]),i="polygon"),{element:r,points:n,shapeType:i}}case"rect":{const n=parseFloat(r.getAttribute("x")??"0"),i=parseFloat(r.getAttribute("y")??"0"),s=parseFloat(r.getAttribute("width")??"0"),a=parseFloat(r.getAttribute("height")??"0");if(!s||!a)continue;return{element:r,points:[[n,i],[n+s,i],[n+s,i+a],[n,i+a],[n,i]],shapeType:"rect"}}default:continue}return null}function Ca(t){const e=[];for(let r=0;r<t.length;r++){const n=e[e.length-1]??[0,0],i=t[r];switch(i[0]){case"M":case"L":e.push([i[1],i[2]]);continue;case"C":e.push(...xa({x:n[0],y:n[1]},{x:i[1],y:i[2]},{x:i[3],y:i[4]},{x:i[5],y:i[6]}).map(s=>[s.x,s.y]).slice(1));continue;case"Q":e.push(...ma({x:n[0],y:n[1]},{x:i[1],y:i[2]},{x:i[3],y:i[4]}).map(s=>[s.x,s.y]).slice(1));continue}}return e}function Ma(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 n=sr.exec(e.fill);n&&(e.fillOpacity=parseFloat(n[4]),e.fill=`rgb(${n[1]}, ${n[2]}, ${n[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 n=sr.exec(e.stroke);n&&(e.strokeOpacity=parseFloat(n[4]),e.stroke=`rgb(${n[1]}, ${n[2]}, ${n[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 ln(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=fn(e.rotation);if(r)if(t.selectors.length)for(const n of t.selectors)n.rotation=r;else t.selectors.push({type:"RotationSelector",rotation:r})}}else delete t.iiifRenderingHints;return t}function fn(t){let e=parseFloat(t);return e&&t.startsWith("!")&&(e=360-e),e&&(e=e%360),e!==e?0:e||0}function de(t,e={}){if(Array.isArray(t))return de(t[0]);if(typeof t=="string"){const[r,n]=t.split("#");return n?de({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{id:r,type:e.typeMap&&e.typeMap[r]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return de(t.items[0]);if(t.type==="SpecificResource"){t.source.type==="Canvas"&&t.source.partOf&&typeof t.source.partOf=="string"&&(t.source.partOf=[{id:t.source.partOf,type:"Manifest"}]);const{selector:r,selectors:n}=t.selector?Ee(t.selector,e):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:r,selectors:n}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[r,n]=t.id.split("#");return n?de({type:"SpecificResource",source:{...t,id:r},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{...t,id:r},selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}function Vt(t={},e=[]){const{id:r,selector:n}=t,i=se(),s=V(),a=r||i.annotation,o=U(d=>a?d.iiif.entities.Annotation[a]:void 0,[a]),u=U(d=>o&&o.body?o.body.map(l=>l?l.type==="SpecificResource"?{...l,source:s.get(l)}:l?d.iiif.entities[l.type][l.id]:null:null).filter(Boolean):[],[o]);return y.useMemo(()=>{if(!o)return;const d={...o,body:u,target:de(o.target,{typeMap:s.getState().iiif.mapping})};return n?n(d):d},[o,n,u,...e])}const pn=({id:t,style:e,className:r,interactive:n})=>{const i=Vt({id:t}),s=Fe(i,"atlas"),a=Fe(i,"html"),o=$t(i,["atlas"]),u=re(),d=y.useMemo(()=>Re.mergeStyles(e,s),[e,s]);return u&&i&&i.target&&i.target.selector&&i.target.selector.type==="BoxSelector"&&i.target.source&&(i.target.source.id===u.id||i.target.source===u.id)?g.jsx(Re.RegionHighlight,{id:i.id,isEditing:!0,region:i.target.selector.spatial,style:d,className:(a==null?void 0:a.className)||r,interactive:!!(a!=null&&a.href||n),href:(a==null?void 0:a.href)||null,title:(a==null?void 0:a.title)||null,hrefTarget:(a==null?void 0:a.target)||null,onClick:()=>{},...o}):null};function dn(t={},e=[]){const{id:r,selector:n}=t,i=se(),s=r||i.annotationPage,a=U(o=>s?o.iiif.entities.AnnotationPage[s]:void 0,[s]);return y.useMemo(()=>{if(a)return n?n(a):a},[a,...e])}const Mt=({className:t,page:e})=>{var s;const r=dn({id:e.id})||e,n=Fe(r,"atlas"),i=Fe(r,"html");return U(a=>r.id?a.iiif.entities.AnnotationPage[r.id]:null,[]),g.jsx(y.Fragment,{children:(s=r.items)==null?void 0:s.map(a=>g.jsx(pn,{id:a.id,style:n,className:(i==null?void 0:i.className)||t},a.id))})};function hn({id:t,image:e,thumbnail:r,isStatic:n,x:i=0,y:s=0,children:a,selector:o,onClick:u,enableSizes:d}){var p,m;const l=y.useMemo(()=>{if(!(!o||o.spatial.x===0&&o.spatial.y===0))return o.spatial},[o]);return g.jsx("world-object",{x:i+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?g.jsxs(y.Fragment,{children:[g.jsx(Re.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:d,x:0,y:0,width:(p=e.target)==null?void 0:p.spatial.width,height:(m=e.target)==null?void 0:m.spatial.height,crop:l}),a]},"service"):g.jsxs(y.Fragment,{children:[g.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 Ra=Object.defineProperty,Ia=(t,e,r)=>e in t?Ra(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Qe=(t,e,r)=>(Ia(t,typeof e!="symbol"?e+"":e,r),r),ka=function(){function t(e,r){var n=[],i=!0,s=!1,a=void 0;try{for(var o=e[Symbol.iterator](),u;!(i=(u=o.next()).done)&&(n.push(u.value),!(r&&n.length===r));i=!0);}catch(d){s=!0,a=d}finally{try{!i&&o.return&&o.return()}finally{if(s)throw a}}return n}return function(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")}}(),Oe=Math.PI*2,ht=function(t,e,r,n,i,s,a){var o=t.x,u=t.y;o*=e,u*=r;var d=n*o-i*u,l=i*o+n*u;return{x:d+s,y:l+a}},Ta=function(t,e){var r=e===1.5707963267948966?.551915024494:e===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(e/4),n=Math.cos(t),i=Math.sin(t),s=Math.cos(t+e),a=Math.sin(t+e);return[{x:n-i*r,y:i+n*r},{x:s+a*r,y:a-s*r},{x:s,y:a}]},ar=function(t,e,r,n){var i=t*n-e*r<0?-1:1,s=t*r+e*n;return s>1&&(s=1),s<-1&&(s=-1),i*Math.acos(s)},ja=function(t,e,r,n,i,s,a,o,u,d,l,p){var m=Math.pow(i,2),A=Math.pow(s,2),h=Math.pow(l,2),x=Math.pow(p,2),b=m*A-m*x-A*h;b<0&&(b=0),b/=m*x+A*h,b=Math.sqrt(b)*(a===o?-1:1);var S=b*i/s*p,w=b*-s/i*l,M=d*S-u*w+(t+r)/2,T=u*S+d*w+(e+n)/2,F=(l-S)/i,k=(p-w)/s,O=(-l-S)/i,E=(-p-w)/s,R=ar(1,0,F,k),$=ar(F,k,O,E);return o===0&&$>0&&($-=Oe),o===1&&$<0&&($+=Oe),[M,T,R,$]},Pa=function(t){var e=t.px,r=t.py,n=t.cx,i=t.cy,s=t.rx,a=t.ry,o=t.xAxisRotation,u=o===void 0?0:o,d=t.largeArcFlag,l=d===void 0?0:d,p=t.sweepFlag,m=p===void 0?0:p,A=[];if(s===0||a===0)return[];var h=Math.sin(u*Oe/360),x=Math.cos(u*Oe/360),b=x*(e-n)/2+h*(r-i)/2,S=-h*(e-n)/2+x*(r-i)/2;if(b===0&&S===0)return[];s=Math.abs(s),a=Math.abs(a);var w=Math.pow(b,2)/Math.pow(s,2)+Math.pow(S,2)/Math.pow(a,2);w>1&&(s*=Math.sqrt(w),a*=Math.sqrt(w));var M=ja(e,r,n,i,s,a,l,m,h,x,b,S),T=ka(M,4),F=T[0],k=T[1],O=T[2],E=T[3],R=Math.abs(E)/(Oe/4);Math.abs(1-R)<1e-7&&(R=1);var $=Math.max(Math.ceil(R),1);E/=$;for(var X=0;X<$;X++)A.push(Ta(O,E)),O+=E;return A.map(function(Y){var _=ht(Y[0],s,a,x,h,F,k),H=_.x,J=_.y,ee=ht(Y[1],s,a,x,h,F,k),ge=ee.x,P=ee.y,N=ht(Y[2],s,a,x,h,F,k),G=N.x,ue=N.y;return{x1:H,y1:J,x2:ge,y2:P,x:G,y:ue}})},Ea=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function yn(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Oa=Fa,yt={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},La=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function Fa(t){var e=[];return t.replace(La,function(r,n,i){var s=n.toLowerCase();for(i=Da(i),s=="m"&&i.length>2&&(e.push([n].concat(i.splice(0,2))),s="l",n=n=="m"?"l":"L");;){if(i.length==yt[s])return i.unshift(n),e.push(i);if(i.length<yt[s])throw new Error("malformed path data");e.push([n].concat(i.splice(0,yt[s])))}}),e}var $a=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function Da(t){var e=t.match($a);return e?e.map(Number):[]}const qa=yn(Oa);var Va=_a;function _a(t){var e=0,r=0,n=0,i=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]+=n,s[7]+=i;break;case"v":s[1]+=i;break;case"h":s[1]+=n;break;default:for(var u=1;u<s.length;)s[u++]+=n,s[u++]+=i}switch(o){case"Z":n=e,i=r;break;case"H":n=s[1];break;case"V":i=s[1];break;case"M":n=e=s[1],i=r=s[2];break;default:n=s[s.length-2],i=s[s.length-1]}return s})}const Ua=yn(Va);function Ha(t){const e=qa(t),r=Ua(e);let n,i=0,s=0,a=0,o=0,u,d,l=0,p=0;const m=[];for(let A=0;A<r.length;A++){let h=r[A];const x=h[0];switch(x){case"M":i=h[1],s=h[2];break;case"H":h=["L",h[1],s];break;case"V":h=["L",i,h[1]];break;case"S":{let b=l,S=p;(n==="C"||n=="S")&&(b+=b-a,S+=S-o),h=["C",b,S,h[1],h[2],h[3],h[4]]}break;case"T":n==="Q"||n=="T"?(u=l*2-u,d=p*2-d):(u=l,d=p),h=["Q",u,d,h[1],h[2]];break;case"Q":u=h[1],d=h[2];break;case"A":{const b=Pa({px:l,py:p,cx:h[6],cy:h[7],rx:h[1],ry:h[2],xAxisRotation:h[3],largeArcFlag:h[4],sweepFlag:h[5]});if(!b.length)continue;for(const[S,w]of b.entries())h=["C",w.x1,w.y1,w.x2,w.y2,w.x,w.y],S<b.length-1&&m.push(h);h=h}break;case"Z":h=["L",i,s];break}n=x,l=h[h.length-2],p=h[h.length-1],["C","Q","A"].indexOf(x)>-1?(a=h[h.length-4],o=h[h.length-3]):(a=l,o=p),m.push(h)}return m}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
36
- *
37
- * All code in this module is based on JavaScript code by Raph Levien, published on his blog at
38
- * https://raphlinus.github.io/.
39
- * I merely changed the structure a bit, removed some unneeded parts and added some comments and type hints.
40
- *
41
- * Flattening of quadratic Bézier curves:
42
- * - Article: https://raphlinus.github.io/graphics/curves/2019/12/23/flatten-quadbez.html
43
- * - Code: https://github.com/raphlinus/raphlinus.github.io/blob/master/_posts/2019-12-23-flatten-quadbez.md?plain=1#L73-L212
44
- *
45
- * Flattening of cubic Bézier curves: https://levien.com/tmp/flatten.html
46
- *
47
- * Note that the code in this module has a different license than the rest of the package,
48
- * due to the inclusion of Apache-licensed third party code.
49
- *
50
- * @license
51
- * Copyright 2022 Johannes Baiter <johannes.baiter@gmail.com>
52
- * Copyright 2019, 2022 Raph Levien <raph.levien@gmail.com>
53
- *
54
- * Licensed under the Apache License, Version 2.0 (the "License");
55
- * you may not use this file except in compliance with the License.
56
- * You may obtain a copy of the License at
57
- *
58
- * http://www.apache.org/licenses/LICENSE-2.0
59
- *
60
- * Unless required by applicable law or agreed to in writing, software
61
- * distributed under the License is distributed on an "AS IS" BASIS,
62
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
63
- * See the License for the specific language governing permissions and
64
- * limitations under the License.
65
- */function Na(t,e,r,n=1){return new vn(t,e,r).subdivide(n)}function Ba(t,e,r,n,i=1){return new _t(new Float64Array([t.x,t.y,e.x,e.y,r.x,r.y,n.x,n.y])).subdivide(i)}function za(t){return t.x*t.x+t.y*t.y}function Le(t){return t/(1-.67+Math.pow(Math.pow(.67,4)+.25*t*t,.25))}function Me(t){return t*(1-.39+Math.sqrt(.39*.39+.25*t*t))}class vn{constructor(e,r,n){Qe(this,"start"),Qe(this,"control"),Qe(this,"end"),this.start=e,this.control=r,this.end=n}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:n,y:i}=this.control,{x:s,y:a}=this.end,o=2*n-e-s,u=2*i-r-a,d=(n-e)*o+(i-r)*u,l=(s-n)*o+(a-i)*u,p=(s-e)*u-(a-r)*o,m=d/p,A=l/p,h=Math.abs(p)/(Math.hypot(o,u)*Math.abs(A-m));return{x0:e,x2:s,scale:h,cross:p}}subdivide(e){const r=this.mapToBasic(),n=Le(r.x0),i=Le(r.x2),s=.5*Math.abs(i-n)*Math.sqrt(r.scale/e),a=Math.ceil(s),o=Me(n),u=Me(i),d=[0];for(let l=1;l<a;l++){const p=(Me(n+(i-n)*l/a)-o)/(u-o);d.push(p)}return d.push(1),d.map(l=>this.eval(l))}}class _t{constructor(e){Qe(this,"c"),this.c=e}weightsum(e,r,n,i){const s=e*this.c[0]+r*this.c[2]+n*this.c[4]+i*this.c[6],a=e*this.c[1]+r*this.c[3]+n*this.c[5]+i*this.c[7];return{x:s,y:a}}eval(e){const r=1-e,n=r*r*r,i=3*r*r*e,s=3*r*e*e,a=e*e*e;return this.weightsum(n,i,s,a)}deriv(e){const r=1-e,n=-3*r*r,i=3*e*e,s=-6*e*r-n,a=6*e*r-i;return this.weightsum(n,s,a,i)}midpoint_quadbez(){const e=this.weightsum(-.25,.75,.75,-.25);return new vn({x:this.c[0],y:this.c[1]},e,{x:this.c[6],y:this.c[7]})}subsegment(e,r){const n=new Float64Array(8),i=this.eval(e),s=this.eval(r);n[0]=i.x,n[1]=i.y;const a=(r-e)/3,o=this.deriv(e);n[2]=i.x+a*o.x,n[3]=i.y+a*o.y;const u=this.deriv(r);return n[4]=s.x-a*u.x,n[5]=s.y-a*u.y,n[6]=s.x,n[7]=s.y,new _t(n)}subdivide(e){const r=.1*e,n=e-r,i=Math.sqrt(n),s=za(this.weightsum(1,-3,3,-1)),a=Math.ceil(Math.pow(s/(432*r*r),1/6)),o=[];let u=0;for(let h=0;h<a;h++){const x=h/a,b=(h+1)/a,S=this.subsegment(x,b).midpoint_quadbez(),w=S.mapToBasic(),M=Le(w.x0),T=Le(w.x2),F=Math.sqrt(w.scale);let k=Math.abs(T-M)*F;if(Math.sign(w.x0)!=Math.sign(w.x2)){const O=i/F,E=i*Math.abs(T-M)/Le(O);k=Math.max(k,E)}o.push({quad:S,a0:M,a2:T,val:k}),u+=k}const d=.5*u/i,l=Math.ceil(d),p=[{x:this.c[0],y:this.c[1]}];let m=0,A=0;for(let h=1;h<l;h++){const x=u*h/l;for(;m+o[A].val<x;)m+=o[A].val,A++;const b=o[A].a0,S=o[A].a2,w=Me(b),M=Me(S),T=b+(S-b)*(x-m)/o[A].val,F=(Me(T)-w)/(M-w);p.push(o[A].quad.eval(F))}return p.push({x:this.c[6],y:this.c[7]}),p}}const Wa=/&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,Qa=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/,or=/^rgba\((\d+),(\d+),(\d+),([0-9.]+)\)$/;function Ye(t,{domParser:e,svgPreprocessor:r,iiifRenderingHints:n}={}){if(Array.isArray(t))return Z(t.reduce((i,s)=>{const{selector:a,selectors:o,iiifRenderingHints:u}=Ye(s,{domParser:e,svgPreprocessor:r,iiifRenderingHints:n});return a&&(i.selector||(i.selector=a),i.selectors.push(...o)),u&&(i.iiifRenderingHints=i.iiifRenderingHints||{type:"ImageApiSelector"},Object.assign(i.iiifRenderingHints,u)),i},{selector:null,selectors:[],iiifRenderingHints:n}));if(!t)return Z({selector:null,selectors:[],iiifRenderingHints:n});if(typeof t=="string"){const[i,s]=t.split("#");return s?Ye({type:"FragmentSelector",value:s},{svgPreprocessor:r,iiifRenderingHints:n,domParser:e}):Z({selector:null,selectors:[],iiifRenderingHints:n})}if(t.type&&t.type==="PointSelector"&&(t.t||t.t===0)){const i={type:"TemporalSelector",temporal:{startTime:t.t}};return Z({selector:i,selectors:[i],iiifRenderingHints:n})}if(Ka(t)){const i=[];if(t.region){const s=Ye({type:"FragmentSelector",value:"xywh="+t.region},{domParser:e,svgPreprocessor:r,iiifRenderingHints:n});i.push(...s.selectors)}return Z({selector:i[0],selectors:i,iiifRenderingHints:n?{...n,...t}:t})}if(t.type==="FragmentSelector"){const i=Wa.exec(t.value);if(i){const a={type:"BoxSelector",spatial:{unit:i[2]==="percent:"||i[2]==="pct:"?"percent":"pixel",x:parseFloat(i[3]),y:parseFloat(i[4]),width:parseFloat(i[5]),height:parseFloat(i[6])}};return Z({selector:a,selectors:[a],iiifRenderingHints:n})}const s=t.value.match(Qa);if(s){const a={type:"TemporalSelector",temporal:{startTime:s[4]?parseFloat(s[4]):0,endTime:s[7]?parseFloat(s[7]):void 0}};return Z({selector:a,selectors:[a],iiifRenderingHints:n})}return Z({selector:null,selectors:[],iiifRenderingHints:n})}if(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 i=[],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:n});const p=gn(l);p&&(i=p.points,u=p.shapeType,s=[Math.min(...i.map(m=>m[0])),Math.min(...i.map(m=>m[1])),Math.max(...i.map(m=>m[0])),Math.max(...i.map(m=>m[1]))],{style:a,svg:o}=Ja(p.element)??{svg:o})}const d={type:"SvgSelector",svg:o,svgShape:u,style:a,points:i.length?i:void 0,spatial:s?{unit:"pixel",x:s[0],y:s[1],width:s[2]-s[0],height:s[3]-s[1]}:void 0};return Z({selector:d,selectors:[d],iiifRenderingHints:n})}return Z({selector:null,selectors:[],iiifRenderingHints:n})}function Ya(t){const e=t.map(n=>n[0]).reduce((n,i)=>(n[i]+=1,n),{C:0,Q:0,L:0,M:0}),r=new Set(t.map(n=>n[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 n=t.slice(-1)[0];return t[0][0]==="M"&&n[0]==="L"&&n[1]==t[0][1]&&n[2]===t[0][2]||n[1]===0&&n[2]===0?"polygon":"polyline"}return"path"}function gn(t){var e;for(const r of Array.from(t.children))switch(r==null?void 0:r.tagName.toLowerCase()){case"g":{const n=gn(r);if(n)return n}continue;case"path":{const n=r.getAttribute("d");if(!n)continue;const i=Ha(n);return{element:r,points:Ga(i),shapeType:Ya(i)}}case"circle":{const n=parseFloat(r.getAttribute("cx")??"0"),i=parseFloat(r.getAttribute("cy")??"0"),s=parseFloat(r.getAttribute("r")??"0");if(!s)continue;const a=[];for(let o=0;o<=360;o+=12){const u=o*Math.PI/180;a.push([n+s*Math.cos(u),i+s*Math.sin(u)])}return{element:r,points:a,shapeType:"circle"}}case"ellipse":{const n=parseFloat(r.getAttribute("cx")??"0"),i=parseFloat(r.getAttribute("cy")??"0"),s=parseFloat(r.getAttribute("rx")??"0"),a=parseFloat(r.getAttribute("ry")??"0");if(!s&&!a)continue;const o=[];for(let u=0;u<=360;u+=12){const d=Math.tan(u/360*Math.PI),l=s*(1-d**2)/(1+d**2),p=a*2*d/(1+d**2);o.push([n+l,i+p])}return{element:r,points:o,shapeType:"ellipse"}}case"line":{const n=parseFloat(r.getAttribute("x0")??"0"),i=parseFloat(r.getAttribute("y0")??"0"),s=parseFloat(r.getAttribute("x1")??"0"),a=parseFloat(r.getAttribute("y1")??"0");if(n===s&&i===a)continue;return{element:r,points:[[n,i],[s,a]],shapeType:"polyline"}}case"polygon":case"polyline":{const n=((e=r.getAttribute("points"))==null?void 0:e.split(" ").map(s=>s.split(",").map(parseFloat)))??[];if(!n.length)continue;let i="polyline";return r.tagName.toLowerCase()==="polygon"&&(n.push(n[0]),i="polygon"),{element:r,points:n,shapeType:i}}case"rect":{const n=parseFloat(r.getAttribute("x")??"0"),i=parseFloat(r.getAttribute("y")??"0"),s=parseFloat(r.getAttribute("width")??"0"),a=parseFloat(r.getAttribute("height")??"0");if(!s||!a)continue;return{element:r,points:[[n,i],[n+s,i],[n+s,i+a],[n,i+a],[n,i]],shapeType:"rect"}}default:continue}return null}function Ga(t){const e=[];for(let r=0;r<t.length;r++){const n=e[e.length-1]??[0,0],i=t[r];switch(i[0]){case"M":case"L":e.push([i[1],i[2]]);continue;case"C":e.push(...Ba({x:n[0],y:n[1]},{x:i[1],y:i[2]},{x:i[3],y:i[4]},{x:i[5],y:i[6]}).map(s=>[s.x,s.y]).slice(1));continue;case"Q":e.push(...Na({x:n[0],y:n[1]},{x:i[1],y:i[2]},{x:i[3],y:i[4]}).map(s=>[s.x,s.y]).slice(1));continue}}return e}function Ja(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 n=or.exec(e.fill);n&&(e.fillOpacity=parseFloat(n[4]),e.fill=`rgb(${n[1]}, ${n[2]}, ${n[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 n=or.exec(e.stroke);n&&(e.strokeOpacity=parseFloat(n[4]),e.stroke=`rgb(${n[1]}, ${n[2]}, ${n[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 Ka(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=Za(e.rotation);if(r)if(t.selectors.length)for(const n of t.selectors)n.rotation=r;else t.selectors.push({type:"RotationSelector",rotation:r})}}else delete t.iiifRenderingHints;return t}function Za(t){let e=parseFloat(t);return e&&t.startsWith("!")&&(e=360-e),e&&(e=e%360),e!==e?0:e||0}function Te(t,e={}){if(Array.isArray(t))return Te(t[0]);if(typeof t=="string"){const[r,n]=t.split("#");return n?Te({type:"SpecificResource",source:{id:r,type:"Unknown"},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{id:r,type:e.typeMap&&e.typeMap[r]||"Unknown"},selector:null,selectors:[]}}if(t.type==="Choice"||t.type==="List"||t.type==="Composite"||t.type==="Independents")return Te(t.items[0]);if(t.type==="SpecificResource"){t.source.type==="Canvas"&&t.source.partOf&&typeof t.source.partOf=="string"&&(t.source.partOf=[{id:t.source.partOf,type:"Manifest"}]);const{selector:r,selectors:n}=t.selector?Ye(t.selector,e):{selector:null,selectors:[]};return{type:"SpecificResource",source:t.source,selector:r,selectors:n}}if(t.id){t.type==="Canvas"&&t.partOf&&typeof t.partOf=="string"&&(t.partOf=[{id:t.partOf,type:"Manifest"}]);const[r,n]=t.id.split("#");return n?Te({type:"SpecificResource",source:{...t,id:r},selector:{type:"FragmentSelector",value:n}}):{type:"SpecificResource",source:{...t,id:r},selector:null,selectors:[]}}return{type:"SpecificResource",source:t,selector:null,selectors:[]}}var Xa=Object.defineProperty,eo=(t,e,r)=>e in t?Xa(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,cr=(t,e,r)=>(eo(t,typeof e!="symbol"?e+"":e,r),r);function to(t){return Array.isArray(t)?t:t?[t]:[]}const ur=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];function ro(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=ur.indexOf(t["@type"]);if(e!==-1)return ur[e]}if(t.profile)return"Service";if(t.format||t["@type"])return"ContentResource";throw new Error("Resource type is not known")}class Ut{constructor(e,r={}){cr(this,"traversals"),cr(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 Ut({collection:[e],manifest:[e],canvas:[e],annotationList:[e],sequence:[e],annotation:[e],contentResource:[e],choice:[e],range:[e],service:[e],layer:[e]})}traverseCollection(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))),this.traversals.collection)}traverseCollectionItems(e){if(this.options.mergeMemberProperties){const r=[...(e.manifests||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Manifest"}:n),...(e.collections||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Collection"}:n),...e.members||[]];delete e.collections,delete e.manifests,e.members=r}return e.manifests&&(e.manifests=e.manifests.map(r=>this.traverseManifest(typeof r=="string"?{"@id":r,"@type":"sc:Manifest"}:r))),e.collections&&(e.collections=e.collections.map(r=>this.traverseCollection(typeof r=="string"?{"@id":r,"@type":"sc:Collection"}:r))),e.members&&(e.members=e.members.map(r=>typeof r=="string"?r:this.traverseUnknown(r))),e}traverseManifest(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))),this.traversals.manifest)}traverseManifestItems(e){return e.sequences&&(e.sequences=e.sequences.map(r=>this.traverseSequence(r))),e.structures&&(e.structures=e.structures.map(r=>this.traverseRange(r))),e}traverseSequence(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseSequenceItems(e))),this.traversals.sequence)}traverseSequenceItems(e){return e.canvases&&(e.canvases=e.canvases.map(r=>this.traverseCanvas(r))),e}traverseCanvas(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCanvasItems(e))),this.traversals.canvas)}traverseCanvasItems(e){return e.images&&(e.images=e.images.map(r=>this.traverseAnnotation(r))),e.otherContent&&(e.otherContent=e.otherContent.map(r=>this.traverseAnnotationList(r))),e}traverseRange(e){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(e))),this.traversals.range)}traverseRangeItems(e){if(this.options.mergeMemberProperties){const r=[...(e.ranges||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Range"}:n),...(e.canvases||[]).map(n=>typeof n=="string"?{"@id":n,"@type":"sc:Canvas"}:n),...e.members||[]];delete e.ranges,delete e.canvases,e.members=r.length?r.map(n=>this.traverseUnknown(n)):void 0}return e}traverseAnnotationList(e){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(ro(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),n=Array.isArray(e)?e:[e],i=[];for(const s of n)typeof s=="string"?i.push(this.traverseContentResource({"@id":s,"@type":"dctypes:Image"})):i.push(this.traverseContentResource(s));return!r&&!this.options.convertPropsToArray?i[0]:i}traverseDescriptive(e){return e.thumbnail&&(e.thumbnail=this.traverseImageResource(e.thumbnail)),e.logo&&(e.logo=this.traverseImageResource(e.logo)),e}traverseOneOrMoreServices(e){const r=Array.isArray(e),n=Array.isArray(e)?e:[e],i=[];for(const s of n)i.push(this.traverseService(s));return!r&&!this.options.convertPropsToArray?i[0]:i}traverseLinking(e){return e.related&&(e.related=this.traverseOneOrManyType(e.related,this.traversals.contentResource)),e.rendering&&(e.rendering=this.traverseOneOrManyType(e.rendering,this.traversals.contentResource)),e.service&&(e.service=this.traverseOneOrMoreServices(e.service)),e.seeAlso&&(e.seeAlso=this.traverseOneOrManyType(e.seeAlso,this.traversals.contentResource)),e.within&&(typeof e.within=="string"||(e.within=this.traverseOneOrManyType(e.within,this.traversals.contentResource))),e.startCanvas&&(typeof e.startCanvas=="string"?e.startCanvas=this.traverseType({"@id":e.startCanvas,"@type":"sc:Canvas"},this.traversals.canvas):e.startCanvas&&this.traverseType(e.startCanvas,this.traversals.canvas)),e.contentLayer&&(typeof e.contentLayer=="string"?e.contentLayer=this.traverseLayer({"@id":e.contentLayer,"@type":"sc:Layer"}):e.contentLayer=this.traverseLayer(e.contentLayer)),e}traverseOneOrManyType(e,r){if(!Array.isArray(e))if(this.options.convertPropsToArray)e=[e];else return this.traverseType(e,r);return e.map(n=>this.traverseType(n,r))}traverseType(e,r){return r.reduce((n,i)=>{const s=i(n);return typeof s>"u"&&!this.options.allowUndefinedReturn?n:s},e)}}const no="http://library.stanford.edu/iiif/image-api/compliance.html#level0",mn="http://library.stanford.edu/iiif/image-api/compliance.html#level1",xn="http://library.stanford.edu/iiif/image-api/compliance.html#level2",io="http://library.stanford.edu/iiif/image-api/conformance.html#level0",bn="http://library.stanford.edu/iiif/image-api/conformance.html#level1",An="http://library.stanford.edu/iiif/image-api/conformance.html#level2",so="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Sn="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",wn="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",ao="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Cn="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Mn="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",oo="http://iiif.io/api/image/1/level0.json",co="http://iiif.io/api/image/1/profiles/level0.json",Rn="http://iiif.io/api/image/1/level1.json",In="http://iiif.io/api/image/1/profiles/level1.json",kn="http://iiif.io/api/image/1/level2.json",Tn="http://iiif.io/api/image/1/profiles/level2.json",uo="http://iiif.io/api/image/2/level0.json",lo="http://iiif.io/api/image/2/profiles/level0.json",jn="http://iiif.io/api/image/2/level1.json",Pn="http://iiif.io/api/image/2/profiles/level1.json",En="http://iiif.io/api/image/2/level2.json",On="http://iiif.io/api/image/2/profiles/level2.json",fo="level0",Ln="level1",Fn="level2",po="http://iiif.io/api/image/2/level0",$n="http://iiif.io/api/image/2/level1",Dn="http://iiif.io/api/image/2/level2",ho=[$n,Dn,mn,xn,bn,An,Sn,wn,Cn,Mn,Rn,In,kn,Tn,jn,Pn,En,On,Ln,Fn],yo=[po,$n,Dn,no,mn,xn,io,bn,An,so,Sn,wn,ao,Cn,Mn,oo,co,Rn,In,kn,Tn,uo,lo,jn,Pn,En,On,fo,Ln,Fn];function ae(t){for(const e in t)(typeof t[e]>"u"||t[e]===null)&&delete t[e];return t}const Rt={attributionLabel:"Attribution",lang:"none",providerId:"http://example.org/provider",providerName:"Unknown"};function Ae(t,e="none"){if(!t)return{};const r=Array.isArray(t)?t:[t],n={};for(const i of r){if(typeof i=="string"){n[e]=n[e]?n[e]:[],n[e].push(i||"");continue}if(!i["@language"]){n[e]=n[e]?n[e]:[],n[e].push(i["@value"]||"");continue}const s=i["@language"];n[s]=n[s]?n[s]:[],n[s].push(i["@value"]||"")}return n}function qn(t){if(Array.isArray(t))return qn(t.find(e=>typeof e=="string"));if(yo.indexOf(t)!==-1)return"level2";if(ho.indexOf(t)!==-1)return"level1";if(typeof t=="string")return t}function vo(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 go(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 lr(t){for(const e of["sc","oa","dcterms","dctypes","iiif"])if(t.startsWith(`${e}:`))return t.slice(e.length+1);return t}const mo=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function Ht(t){const e=t["@id"]||t.id;let r=t["@type"]||t.type;const n=t.profile||void 0,i=t["@context"]||void 0;if(n){const s=go(n);if(s)return s}if(i){const s=vo(i);if(s)return s}if(r){if(Array.isArray(r)){if(r.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(r.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";r=r[0]}for(const s of["sc","oa","dcterms","dctypes","iiif"])if(r.startsWith(`${s}:`)){r=r.slice(s.length+1);break}switch(r){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(r&&mo.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 xo=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function bo(t){const e=t.match(xo);return e?e[0]:t}function Ao(t,e="Rights/License",r="none"){let n=null;const i=[],s=Array.isArray(t)?t:[t];for(const a of s){const o=a?bo(a):void 0;if(o&&(o.indexOf("creativecommons.org")!==-1||o.indexOf("rightsstatements.org")!==-1)){o.startsWith("https://")?n=`http://${o.slice(8)}`:n=o;continue}o&&i.push({label:{[r]:[e]},value:{[r]:[o]}})}return[n,i]}const So=["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 wo(t){if(t){const e=Array.isArray(t)?t:[t],r=[];for(const n of e)n==="http://iiif.io/api/presentation/2/context.json"&&r.push("http://iiif.io/api/presentation/3/context.json"),So.indexOf(n)===-1&&r.push(n);if(e.length)return r.length===1?r[0]:r}}function Co(t){return t?t.map(e=>({label:Ae(e.label),value:Ae(e.value)})):[]}let fr=0;function Vn(t,e){const r=encodeURI(t.id||t["@id"]||"").trim();return r&&e?`${r}/${e}`:r||(fr++,`http://example.org/${t["@type"]}${e?`/${e}`:""}/${fr}`)}function oe(t){const e=[...t.behavior||[]];t.viewingHint&&e.push(t.viewingHint);let r;return Array.isArray(t.motivation)?r=t.motivation.map(lr):t.motivation&&(r=lr(t.motivation)),{"@context":t["@context"]?wo(t["@context"]):void 0,id:(t["@id"]||Vn(t)).trim(),type:Ht(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 ce(t){const[e,r]=Ao(t.license),n=[...t.metadata?Co(t.metadata):[],...r];return{rights:e,metadata:n.length?n:void 0,label:t.label?Ae(t.label):void 0,requiredStatement:t.attribution?{label:Ae(Rt.attributionLabel),value:Ae(t.attribution)}:void 0,navDate:t.navDate,summary:t.description?Ae(t.description):void 0,thumbnail:Mo(t.thumbnail)}}function Mo(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 Ro(t){if(!t.within)return;const e=Array.isArray(t.within)?t.within:[t.within],r=[];for(const n of e)if(typeof n=="string"){if(n)switch(t["@type"]){case"sc:Manifest":r.push({id:n,type:"Collection"});break}}else n["@id"]&&r.push({id:n["@id"],type:Ht(n)});return r.length?r:void 0}function ve(t){const e=t.related?Array.isArray(t.related)?t.related:[t.related]:[],r=t.contentLayer;return{provider:t.logo||e.length?[{id:Rt.providerId,type:"Agent",homepage:e.length?[e[0]]:void 0,logo:t.logo?Array.isArray(t.logo)?t.logo:[t.logo]:void 0,label:Ae(Rt.providerName)}]:void 0,partOf:Ro(t),rendering:t.rendering,seeAlso:t.seeAlso,start:t.startCanvas,service:t.service?to(t.service):void 0,supplementary:r?[r]:void 0}}function Io(t){return{chars:t.chars,format:t.format?t.format:void 0,language:t.language}}function ko(t){return ae({...oe(t),...ce(t),...ve(t),items:t.members})}function To(t){const e=[],r=[];let n;for(const s of t.sequences||[])s.canvases.length&&e.push(...s.canvases),s.behavior&&r.push(...s.behavior),s.startCanvas&&(n=s.startCanvas);const i=oe(t);return r.length&&(i.behavior?i.behavior.push(...r):i.behavior=r),ae({...i,...ce(t),...ve(t),start:n,items:e,structures:t.structures})}function jo(t){return ae({...oe(t),...ce(t),...ve(t),annotations:t.otherContent&&t.otherContent.length?t.otherContent:void 0,items:t.images&&t.images.length?[{id:Vn(t,"annotation-page"),type:"AnnotationPage",items:t.images}]:void 0})}function Po(t){return ae({...oe(t),...ce(t),...ve(t),items:t.resources&&t.resources.length?t.resources:void 0})}function Eo(t){return!t.canvases||t.canvases.length===0?{canvases:[],behavior:[]}:{canvases:t.canvases,behavior:t.viewingHint?[t.viewingHint]:[],startCanvas:t.startCanvas}}function Oo(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 n;if(typeof r.full=="string")n=r.full;else if(r.full["@type"]==="dctypes:Image")n={id:r.full["@id"],type:"Image"};else if(r.full["@type"]==="sc:Canvas")n={id:r.full["@id"],type:"Canvas"};else throw new Error(`Unsupported source type on annotation: ${r.full["@type"]}`);return{type:"SpecificResource",source:n,selector:kt(r.selector)}}else return encodeURI(r["@id"]).trim()}return ae({...oe(t),...ce(t),...ve(t),target:e(t.on),body:Array.isArray(t.resource)?t.resource.map(It):It(t.resource)})}function It(t){const e=t;return ae({...oe(e),...ce(e),...ve(e),...Io(e)})}function Lo(t){const e=[];return t.default&&t.default!=="rdf:nil"&&e.push(t.default),t.item&&t.item!=="rdf:nil"&&e.push(...t.item),{...oe(t),...ce(t),items:e}}function Fo(t){return ae({...oe(t),...ce(t),...ve(t),items:t.members})}function $o(t){const{"@id":e,"@type":r,"@context":n,profile:i,...s}=t,a={};return e&&(a["@id"]=e),a["@type"]=Ht(t),a["@type"]==="unknown"&&(n&&n.length&&(a["@context"]=n),a["@type"]="Service"),i&&(a.profile=qn(i)),ae({...a,...s})}function Do(t){return ae({...oe(t),...ce(t),...ve(t)})}new Ut({collection:[ko],manifest:[To],canvas:[jo],annotationList:[Po],sequence:[Eo],annotation:[Oo],contentResource:[It],choice:[Lo],range:[Fo],service:[$o],layer:[Do]});function kt(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[kt(t.default),...(Array.isArray(t.item)?t.item:[t.item]).map(kt)];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 pr={exports:{}};(function(t,e){var r=Object.defineProperty,n=(s,a,o)=>a in s?r(s,a,{enumerable:!0,configurable:!0,writable:!0,value:o}):s[a]=o,i=(s,a,o)=>(n(s,typeof a!="symbol"?a+"":a,o),o);(function(s,a){a(e)})(Ea,function(s){const a="http://library.stanford.edu/iiif/image-api/compliance.html#level1",o="http://library.stanford.edu/iiif/image-api/compliance.html#level2",u="http://library.stanford.edu/iiif/image-api/conformance.html#level1",d="http://library.stanford.edu/iiif/image-api/conformance.html#level2",l="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",p="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",m="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",A="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",h="http://iiif.io/api/image/1/level1.json",x="http://iiif.io/api/image/1/profiles/level1.json",b="http://iiif.io/api/image/1/level2.json",S="http://iiif.io/api/image/1/profiles/level2.json",w="http://iiif.io/api/image/2/level1.json",M="http://iiif.io/api/image/2/profiles/level1.json",T="http://iiif.io/api/image/2/level2.json",F="http://iiif.io/api/image/2/profiles/level2.json",k="level1",O="level2",E="http://iiif.io/api/image/2/level1",R="http://iiif.io/api/image/2/level2",$=[E,R,a,o,u,d,l,p,m,A,h,x,b,S,w,M,T,F,k,O],X=["http://iiif.io/api/image/2/level0",E,R,"http://library.stanford.edu/iiif/image-api/compliance.html#level0",a,o,"http://library.stanford.edu/iiif/image-api/conformance.html#level0",u,d,"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",l,p,"http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",m,A,"http://iiif.io/api/image/1/level0.json","http://iiif.io/api/image/1/profiles/level0.json",h,x,b,S,"http://iiif.io/api/image/2/level0.json","http://iiif.io/api/image/2/profiles/level0.json",w,M,T,F,"level0",k,O],Y=["sc:Collection","sc:Manifest","sc:Canvas","sc:AnnotationList","oa:Annotation","sc:Range","sc:Layer","sc:Sequence","oa:Choice","Service","ContentResource"];class _{constructor(c,v={}){i(this,"traversals"),i(this,"options"),this.traversals={collection:[],manifest:[],canvas:[],annotationList:[],sequence:[],annotation:[],contentResource:[],choice:[],range:[],service:[],layer:[],...c},this.options={convertPropsToArray:!0,mergeMemberProperties:!0,allowUndefinedReturn:!1,...v}}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 v=[...(c.manifests||[]).map(C=>typeof C=="string"?{"@id":C,"@type":"sc:Manifest"}:C),...(c.collections||[]).map(C=>typeof C=="string"?{"@id":C,"@type":"sc:Collection"}:C),...c.members||[]];delete c.collections,delete c.manifests,c.members=v}return c.manifests&&(c.manifests=c.manifests.map(v=>this.traverseManifest(typeof v=="string"?{"@id":v,"@type":"sc:Manifest"}:v))),c.collections&&(c.collections=c.collections.map(v=>this.traverseCollection(typeof v=="string"?{"@id":v,"@type":"sc:Collection"}:v))),c.members&&(c.members=c.members.map(v=>typeof v=="string"?v:this.traverseUnknown(v))),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(v=>this.traverseSequence(v))),c.structures&&(c.structures=c.structures.map(v=>this.traverseRange(v))),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(v=>this.traverseCanvas(v))),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(v=>this.traverseAnnotation(v))),c.otherContent&&(c.otherContent=c.otherContent.map(v=>this.traverseAnnotationList(v))),c}traverseRange(c){return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseRangeItems(c))),this.traversals.range)}traverseRangeItems(c){if(this.options.mergeMemberProperties){const v=[...(c.ranges||[]).map(C=>typeof C=="string"?{"@id":C,"@type":"sc:Range"}:C),...(c.canvases||[]).map(C=>typeof C=="string"?{"@id":C,"@type":"sc:Canvas"}:C),...c.members||[]];delete c.ranges,delete c.canvases,c.members=v.length?v.map(C=>this.traverseUnknown(C)):void 0}return c}traverseAnnotationList(c){const v=typeof c=="string"?{"@id":c,"@type":"sc:AnnotationList"}:c;return this.traverseType(this.traverseDescriptive(this.traverseAnnotationListItems(v)),this.traversals.annotationList)}traverseAnnotationListItems(c){return c.resources&&(c.resources=c.resources.map(v=>this.traverseAnnotation(v))),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(v=>this.traverseContentResource(v)):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(v=>this.traverseAnnotationList(v))),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(v=>this.traverseContentResource(v))),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(v){if(v==null)throw new Error("Null or undefined is not a valid entity.");if(Array.isArray(v))throw new Error("Array is not a valid entity");if(typeof v!="object")throw new Error(typeof v+" is not a valid entity");if(typeof v["@type"]=="string"){const C=Y.indexOf(v["@type"]);if(C!==-1)return Y[C]}if(v.profile)return"Service";if(v.format||v["@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 v=Array.isArray(c),C=Array.isArray(c)?c:[c],L=[];for(const j of C)typeof j=="string"?L.push(this.traverseContentResource({"@id":j,"@type":"dctypes:Image"})):L.push(this.traverseContentResource(j));return v||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 v=Array.isArray(c),C=Array.isArray(c)?c:[c],L=[];for(const j of C)L.push(this.traverseService(j));return v||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,v){if(!Array.isArray(c)){if(!this.options.convertPropsToArray)return this.traverseType(c,v);c=[c]}return c.map(C=>this.traverseType(C,v))}traverseType(c,v){return v.reduce((C,L)=>{const j=L(C);return j!==void 0||this.options.allowUndefinedReturn?j:C},c)}}function H(f){for(const c in f)f[c]!==void 0&&f[c]!==null||delete f[c];return f}const J="Attribution",ee="http://example.org/provider",ge="Unknown";function P(f,c="none"){if(!f)return{};const v=Array.isArray(f)?f:[f],C={};for(const L of v){if(typeof L=="string"){C[c]=C[c]?C[c]:[],C[c].push(L||"");continue}if(!L["@language"]){C[c]=C[c]?C[c]:[],C[c].push(L["@value"]||"");continue}const j=L["@language"];C[j]=C[j]?C[j]:[],C[j].push(L["@value"]||"")}return C}function N(f){return Array.isArray(f)?N(f.find(c=>typeof c=="string")):X.indexOf(f)!==-1?"level2":$.indexOf(f)!==-1?"level1":typeof f=="string"?f:void 0}function G(f){for(const c of["sc","oa","dcterms","dctypes","iiif"])if(f.startsWith(`${c}:`))return f.slice(c.length+1);return f}const ue=["Collection","Manifest","Annotation","AnnotationPage","Range","Service"];function nt(f){const c=f["@id"]||f.id;let v=f["@type"]||f.type;const C=f.profile||void 0,L=f["@context"]||void 0;if(C){const j=function(B){switch(B){case"http://iiif.io/api/image/2/level0.json":case"http://iiif.io/api/image/2/level1.json":case"http://iiif.io/api/image/2/level2.json":return"ImageService2";case"http://iiif.io/api/auth/1/kiosk":case"http://iiif.io/api/auth/1/login":case"http://iiif.io/api/auth/1/clickthrough":case"http://iiif.io/api/auth/1/external":case"http://iiif.io/api/auth/0/kiosk":case"http://iiif.io/api/auth/0/login":case"http://iiif.io/api/auth/0/clickthrough":case"http://iiif.io/api/auth/0/external":return"AuthCookieService1";case"http://iiif.io/api/auth/1/token":case"http://iiif.io/api/auth/0/token":return"AuthTokenService1";case"http://iiif.io/api/auth/1/logout":case"http://iiif.io/api/auth/0/logout":return"AuthLogoutService1";case"http://iiif.io/api/search/1/search":case"http://iiif.io/api/search/0/search":return"SearchService1";case"http://iiif.io/api/search/1/autocomplete":case"http://iiif.io/api/search/0/autocomplete":return"AutoCompleteService1"}}(C);if(j)return j}if(L){const j=function(B){const Ve=Array.isArray(B)?B:[B];for(const _e of Ve)switch(_e){case"http://iiif.io/api/image/2/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2":return"ImageService2";case"http://iiif.io/api/image/1/context.json":case"http://library.stanford.edu/iiif/image-api/1.1/context.json":return"ImageService1";case"http://iiif.io/api/annex/openannotation/context.json":return"ImageApiSelector"}}(L);if(j)return j}if(v){if(Array.isArray(v)){if(v.indexOf("oa:CssStylesheet")!==-1)return"CssStylesheet";if(v.indexOf("cnt:ContentAsText")!==-1)return"TextualBody";v=v[0]}for(const j of["sc","oa","dcterms","dctypes","iiif"])if(v.startsWith(`${j}:`)){v=v.slice(j.length+1);break}switch(v){case"Layer":return"AnnotationCollection";case"AnnotationList":return"AnnotationPage";case"cnt:ContentAsText":return"TextualBody"}}if(v&&ue.indexOf(v)!==-1)return v;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":v||"unknown"}const Mi=/http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;function Ri(f){const c=f.match(Mi);return c?c[0]:f}const Ii=["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 ki(f){if(f){const c=Array.isArray(f)?f:[f],v=[];for(const C of c)C==="http://iiif.io/api/presentation/2/context.json"&&v.push("http://iiif.io/api/presentation/3/context.json"),Ii.indexOf(C)===-1&&v.push(C);if(c.length)return v.length===1?v[0]:v}}let zt=0;function Wt(f,c){const v=encodeURI(f.id||f["@id"]||"").trim();return v&&c?`${v}/${c}`:v||(zt++,`http://example.org/${f["@type"]}${c?`/${c}`:""}/${zt}`)}function ne(f){const c=[...f.behavior||[]];let v;return f.viewingHint&&c.push(f.viewingHint),Array.isArray(f.motivation)?v=f.motivation.map(G):f.motivation&&(v=G(f.motivation)),{"@context":f["@context"]?ki(f["@context"]):void 0,id:(f["@id"]||Wt(f)).trim(),type:nt(f),behavior:c.length?c:void 0,height:f.height?f.height:void 0,width:f.width?f.width:void 0,motivation:v,viewingDirection:f.viewingDirection,profile:f.profile,format:f.format?f.format:void 0,duration:void 0,timeMode:void 0}}function ie(f){const[c,v]=function(j,B="Rights/License",Ve="none"){let _e=null;const Qt=[],Oi=Array.isArray(j)?j:[j];for(const Yt of Oi){const fe=Yt?Ri(Yt):void 0;!fe||fe.indexOf("creativecommons.org")===-1&&fe.indexOf("rightsstatements.org")===-1?fe&&Qt.push({label:{[Ve]:[B]},value:{[Ve]:[fe]}}):_e=fe.startsWith("https://")?`http://${fe.slice(8)}`:fe}return[_e,Qt]}(f.license),C=[...f.metadata?(L=f.metadata,L?L.map(j=>({label:P(j.label),value:P(j.value)})):[]):[],...v];var L;return{rights:c,metadata:C.length?C:void 0,label:f.label?P(f.label):void 0,requiredStatement:f.attribution?{label:P(J),value:P(f.attribution)}:void 0,navDate:f.navDate,summary:f.description?P(f.description):void 0,thumbnail:Ti(f.thumbnail)}}function Ti(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 ji(f){if(!f.within)return;const c=Array.isArray(f.within)?f.within:[f.within],v=[];for(const C of c)typeof C=="string"?C&&f["@type"]==="sc:Manifest"&&v.push({id:C,type:"Collection"}):C["@id"]&&v.push({id:C["@id"],type:nt(C)});return v.length?v:void 0}function le(f){const c=f.related?Array.isArray(f.related)?f.related:[f.related]:[],v=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:P(ge)}]:void 0,partOf:ji(f),rendering:f.rendering,seeAlso:f.seeAlso,start:f.startCanvas,service:f.service?(C=f.service,Array.isArray(C)?C:C?[C]:[]):void 0,supplementary:v?[v]:void 0};var C}function it(f){const c=f;return H({...ne(c),...ie(c),...le(c),...(v=c,{chars:v.chars,format:v.format?v.format:void 0,language:v.language})});var v}const Pi=new _({collection:[function(f){return H({...ne(f),...ie(f),...le(f),items:f.members})}],manifest:[function(f){const c=[],v=[];let C;for(const j of f.sequences||[])j.canvases.length&&c.push(...j.canvases),j.behavior&&v.push(...j.behavior),j.startCanvas&&(C=j.startCanvas);const L=ne(f);return v.length&&(L.behavior?L.behavior.push(...v):L.behavior=v),H({...L,...ie(f),...le(f),start:C,items:c,structures:f.structures})}],canvas:[function(f){return H({...ne(f),...ie(f),...le(f),annotations:f.otherContent&&f.otherContent.length?f.otherContent:void 0,items:f.images&&f.images.length?[{id:Wt(f,"annotation-page"),type:"AnnotationPage",items:f.images}]:void 0})}],annotationList:[function(f){return H({...ne(f),...ie(f),...le(f),items:f.resources&&f.resources.length?f.resources:void 0})}],sequence:[function(f){return f.canvases&&f.canvases.length!==0?{canvases:f.canvases,behavior:f.viewingHint?[f.viewingHint]:[],startCanvas:f.startCanvas}:{canvases:[],behavior:[]}}],annotation:[function(f){return H({...ne(f),...ie(f),...le(f),target:function c(v){if(Array.isArray(v)){if(v.length>1)return{type:"List",items:v.map(c)};v=v[0]}if(typeof v=="string")return encodeURI(v).trim();if("@type"in v){let C;if(typeof v.full=="string")C=v.full;else if(v.full["@type"]==="dctypes:Image")C={id:v.full["@id"],type:"Image"};else{if(v.full["@type"]!=="sc:Canvas")throw new Error(`Unsupported source type on annotation: ${v.full["@type"]}`);C={id:v.full["@id"],type:"Canvas"}}return{type:"SpecificResource",source:C,selector:st(v.selector)}}return encodeURI(v["@id"]).trim()}(f.on),body:Array.isArray(f.resource)?f.resource.map(it):it(f.resource)})}],contentResource:[it],choice:[function(f){const c=[];return f.default&&f.default!=="rdf:nil"&&c.push(f.default),f.item&&f.item!=="rdf:nil"&&c.push(...f.item),{...ne(f),...ie(f),items:c}}],range:[function(f){return H({...ne(f),...ie(f),...le(f),items:f.members})}],service:[function(f){const{"@id":c,"@type":v,"@context":C,profile:L,...j}=f,B={};return c&&(B["@id"]=c),B["@type"]=nt(f),B["@type"]==="unknown"&&(C&&C.length&&(B["@context"]=C),B["@type"]="Service"),L&&(B.profile=N(L)),H({...B,...j})}],layer:[function(f){return H({...ne(f),...ie(f),...le(f)})}]});function st(f){if((Array.isArray(f["@type"])&&f["@type"].includes("oa:SvgSelector")||f["@type"]=="oa:SvgSelector")&&("chars"in f||"value"in f))return{type:"SvgSelector",value:"chars"in f?f.chars:f.value};if(f["@type"]==="oa:FragmentSelector")return{type:"FragmentSelector",value:f.value};if(f["@type"]==="oa:Choice")return[st(f.default),...(Array.isArray(f.item)?f.item:[f.item]).map(st)];if(f["@type"]=="iiif:ImageApiSelector")return{type:"ImageApiSelector",region:"region"in f?f.region:void 0,rotation:"rotation"in f?f.rotation:void 0};throw new Error(`Unsupported selector type: ${f["@type"]}`)}const Ei=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"?Pi.traverseUnknown(f):f};s.upgrade=Ei,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})})})(pr,pr.exports);function qo(t){return t.type==="SpecificResource"?[t.source,{selector:t.selector}]:[t,{selector:null}]}function Nt(t,e){const{selector:r,source:n}=Te(e);if(n.id!==t.id)return[null,n];const i={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:i.spatial}:r:null,n]}const _n={makeChoice:()=>{}},Ge={type:"unknown"},D=t=>({type:"unknown",reason:t,annotations:{pages:[]}}),Un=(t,e)=>({type:"empty",width:t,height:e,annotations:{pages:[]},image:null,images:[]});function Vo(t,e){var n;const r=(n=t==null?void 0:t.iiif)==null?void 0:n.meta[e];return r?r.annotationPageManager:null}function _o(t,e){return U(r=>{const n=[];if(!t)return n;const i=Object.keys(r.iiif.entities.AnnotationPage);for(const s of i)if(!e||e.indexOf(s)!==-1){const a=Vo(r,s);a&&a.views&&a.views[t]&&n.push(s)}return n},[t,e])}function Hn({canvas:t,manifest:e,all:r,canvases:n}){const i=[];if(e)for(const s of e.annotations)i.indexOf(s.id)===-1&&i.push(s.id);if(r){if(n&&n.length)for(const s of n)for(const a of s.annotations)i.indexOf(a.id)===-1&&i.push(a.id)}else if(t)for(const s of t.annotations)i.indexOf(s.id)===-1&&i.push(s.id);return i}function Uo(t,e){var n;const r=(n=t==null?void 0:t.iiif)==null?void 0:n.meta[e];return r?r.annotationPageManager:null}function Nn(t,e={}){const r=V(),n=ye(),i=re(),s=Et(),a=y.useMemo(()=>Hn({all:e.all,manifest:n,canvas:i,canvases:s}),[e.all,i,s,n]),o=_o(t,e.all?void 0:a),u=y.useCallback(l=>{t&&r.setMetaValue([l,"annotationPageManager","views"],p=>p&&!p[t]?p:{...p||{},[t]:!1})},[t,r]),d=y.useCallback((l,p={})=>{if(!t)return;const m=r.getState(),A=[];if(p!=null&&p.deselectOthers){const h=Object.keys(m.iiif.entities.AnnotationPage);for(const x of h){const b=Uo(m,x);b&&b.views&&b.views[t]&&A.push(x)}}for(const h of A)u(h);r.setMetaValue([l,"annotationPageManager","views"],h=>h&&h[t]?h:{...h||{},[t]:!0})},[t,u,r]);return{availablePageIds:a,enabledPageIds:o,setPageEnabled:d,setPageDisabled:u}}function Bn(t,e){return U((r,n)=>n.get(t.map(i=>({id:i,type:e}))),[t,e])}const zn=y.createContext(new Se.ImageServiceLoader);function Xe(){return y.useContext(zn)}function Wn(){const t=Xe(),[e,r]=y.useState({}),n=y.useRef(!1);return y.useEffect(()=>()=>{n.current=!0},[]),[y.useCallback((s,{height:a,width:o})=>{if(s){const u=s.id||s["@id"],d=t.loadServiceSync({id:u,width:s.width||o,height:s.height||a,source:s});d?s=d:e[u]||(n.current||r(l=>({...l,[u]:"loading"})),t.loadService({id:u,width:s.width||o,height:s.height||a}).then(()=>{n.current||r(l=>({...l,[u]:"done"}))}))}return s},[t,e]),e]}function et(t={}){const e=Vt(),r=re(t.canvasId?{id:t.canvasId}:void 0);return U((n,i)=>{if(!r)return[];if(e&&t.enableSingleAnnotation)return[e];const s=i.get(r.items),a=[];for(const o of s)a.push(...i.get(o.items));return a},[r])}function Ho(t){return t.type==="SpecificResource"?[t.source,{selector:t.selector}]:[t,{selector:null}]}const Be={},Qn={get(t){return t},setMetaValue([t,e,r],n){const i=Qn.getResourceMeta(t,e),s=i?i[r]:void 0,a=typeof n=="function"?n(s):n;Be[t]={...Be[t]||{},[e]:{...(Be[t]||{})[e]||{},[r]:a}}},getResourceMeta:(t,e)=>{const r=Be[t];if(r)return e?r[e]:r}};function No(t=Qn){function e(i){const s=i?typeof i=="string"?t.get(i):i: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(i,s=[]){const a=Array.isArray(i)?i:e(i),o=[];let u=null;const d=[];for(const l of a){if(l.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const p=Array.from(Array.isArray(l.body)?l.body:[l.body]);for(const m of p){const[A,{selector:h}]=Ho(m),x=t.get(A),b=(x.type||"unknown").toLowerCase();if(b==="choice"){const S=t.get(x.items,{parent:x.id}),w=s.length?s.map(M=>S.find(T=>T.id===M)).filter(Boolean):[S[0]];w.length===0&&w.push(S[0]),u={type:"single-choice",items:S.map(M=>({id:M.id,label:M.label,selected:w.indexOf(M)!==-1})),label:A.label},p.push(...w);continue}o.indexOf(b)===-1&&o.push(b),d.push({type:b,annotationId:l.id,resource:x,target:l.target,selector:h})}}return{types:o,items:d,choice:u}}function n(i){const{choice:s}=r(i);return s}return{getAllPaintingAnnotations:e,getPaintables:r,extractChoices:n}}function Yn(t,e=[]){const r=V(),n=y.useMemo(()=>No(r),[]),i=et({enableSingleAnnotation:t==null?void 0:t.enableSingleAnnotation}),[s,a]=y.useState((t==null?void 0:t.defaultChoices)||[]),o=y.useMemo(()=>n.getPaintables(i,s),[r,i,s,...e]),d={makeChoice:y.useCallback((l,{deselectOthers:p=!0,deselect:m=!1}={})=>{if(o.choice){if(o.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");a(A=>{if(m){const x=A.filter(b=>b!==l);if(x.length===0){const b=o.items[0].resource.id;return b?[b]:[]}return x}if(p)return[l];const h=[...A];if(h.length===0&&o.items.length){const x=o.items[0].resource.id;x&&h.push(x)}return A.indexOf(l)!==-1?A:[...A,l]})}},[o.choice])};return[o,d]}const Bo=["model/gltf-binary"];function Gn(t,e){const n=e.items[0].resource;return n.format?Bo.indexOf(n.format)===-1?D(`3D format: ${n.format} is unsupported`):{type:"3d-model",model:n}:D("Unknown format")}function zo(t,e){var n;if(!t.duration)return D("No duration on canvas");if(e.items.length>1)return D("Only one audio source supported");const r=(n=e.items[0])==null?void 0:n.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:[]}}:D("Audio does not have format"):D("Unknown audio")}function Jn(t,e,r){const n=[];for(const i of e.items){const s=i.resource&&i.resource.type==="SpecificResource"?i.resource.source:i.resource;if(!s.id)return D("No resource Identifier");let a;if(s.service){const A=Se.getImageServices(s);A[0]&&(a=r(A[0],t))}const o={type:"BoxSelector",spatial:{x:0,y:0,width:Number(t.width),height:Number(t.height)}},[u,d]=Nt(t,i.target);if(d.id!==t.id)continue;i.resource.width&&i.resource.height&&(i.resource.width,i.resource.height);let l=i.resource.type==="SpecificResource"?de(i.resource):null;if(i.selector){const A=de({type:"SpecificResource",source:i.resource,selector:i.selector});A&&(l=A)}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 m={id:s.id,type:"Image",annotationId:i.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};n.push(m)}return{type:"images",image:n[0],images:n,choice:e.choice}}function Kn(t,e={},r){const n=t.language||r||"none";switch(t.type){case"TextualBody":{typeof t.value<"u"&&(e[n]=t.value);break}case"List":case"Composite":case"Choice":t.items&&t.items.forEach(i=>Kn(i,e,n))}return e}function Zn(t,e){const r=[];return e.items.forEach(n=>{if(n.resource){const[i]=Nt(t,n.target);r.push({annotationId:n.annotationId,text:Kn(n.resource),target:i})}}),{type:"textual-content",items:r}}const Wo=/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?vi?=|&vi?=))([^#&?]*).*/;function Xn(t,e){var a;const r=e.items.filter(o=>o.type==="video");if(!t.duration)return D("No duration on canvas");if(r.length>1)return D("Only one video source supported");const n=(a=r[0])==null?void 0:a.resource,i=!!(n.service||[]).find(o=>(o.profile||"").includes("youtube.com"));if(!n)return D("Unknown video");if((!n.format||n.format==="text/html")&&!i)return D("Video does not have format");const s={annotationId:e.items[0].annotationId,duration:t.duration,url:n.id,type:"Video",items:[],target:{type:"TemporalSelector",temporal:{startTime:0,endTime:t.duration}},format:n.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:t.duration}}};if(i){s.type="VideoYouTube";const o=n.id.match(Wo);if(!o[1])return D("Video is not known youtube video");s.youTubeId=o[1]}return{type:"media",media:s,annotations:{pages:[]}}}function ei({canvas:t,paintables:e,supports:r,loadImageService:n}){if(!t)return console.log("No canvas"),Ge;if(e.types.length===0)return r.indexOf("empty")!==-1?Un(t.width,t.height):(console.log("No paintables"),Ge);if(e.types.length!==1)if(e.types.length===2&&e.types.indexOf("text")!==-1)e.types=e.types.filter(s=>s!=="text");else return r.indexOf("complex-timeline")===-1?D("Complex timeline not supported"):D("ComplexTimelineStrategy not yet supported");const i=e.types[0];return i==="image"?r.indexOf("images")===-1?D("Image not supported"):Jn(t,e,n):i==="Model"||i==="model"?r.indexOf("3d-model")===-1?D("3D not supported"):Gn(t,e):i==="textualbody"?r.indexOf("textual-content")===-1?D("Textual content not supported"):Zn(t,e):i==="sound"||i==="audio"?r.indexOf("media")===-1?D("Media not supported"):zo(t,e):i==="video"?r.indexOf("media")===-1?D("Media not supported"):Xn(t,e):Ge}function ti(t){const e=ye(),r=re(),n=V(),[i,s]=Wn(),{enabledPageIds:a}=Nn((t==null?void 0:t.annotationPageManagerId)||(e==null?void 0:e.id)||(r==null?void 0:r.id),{all:!1}),o=Bn(a,"AnnotationPage"),u=(t==null?void 0:t.strategies)||["empty","images","media","textual-content","complex-timeline"],[d,l]=Yn(t,[s]),p=y.useMemo(()=>ei({canvas:r,paintables:d,supports:u,loadImageService:i}),[r,d,n,l.makeChoice]);return y.useMemo(()=>p.type==="unknown"?[p,_n]:[{...p,annotations:{pages:o}},l],[p,o])}const ri=(t,e=[])=>{const r=V();y.useEffect(()=>{t(r)},[r,...e])},ze={},ni={get(t){return t},setMetaValue([t,e,r],n){const i=ni.getResourceMeta(t,e),s=i?i[r]:void 0,a=typeof n=="function"?n(s):n;ze[t]={...ze[t]||{},[e]:{...(ze[t]||{})[e]||{},[r]:a}}},getResourceMeta:(t,e)=>{const r=ze[t];if(r)return e?r[e]:r}},Qo=new Se.ImageServiceLoader;function Yo(t=ni,e={}){const r=e.imageServiceLoader||Qo;async function n(i,s,a=!1,o=[],u){const d=()=>r.getThumbnailFromResource(void 0,s,a,o);if(!i)return await r.getThumbnailFromResource(void 0,s,a,o);if(typeof i=="string"){const p=Se.getFixedSizeFromImage(i);return p&&o.push(p),await r.getThumbnailFromResource(void 0,s,a,o)}const l=t.get(i,{skipSelfReturn:!1});if(typeof l=="string")return{best:Se.getFixedSizeFromImage(l),fallback:[],log:[]};if(!l)return await d();switch(await(async p=>{if(p&&p.thumbnail&&p.thumbnail.length){const m=t.get(p.thumbnail[0]),A=await r.getImageCandidates(m,a);A&&A.length&&o.push(...A)}})(l),l.type){case"Annotation":{const p=Array.isArray(l.body)?l.body:[l.body],m=t.get(p[0]);return u&&!m.width&&(m.width=u.width,m.height=u.height),await r.getThumbnailFromResource(m,s,a,o)}case"Canvas":{const p=l;return n(p.items[0],s,a,o,{width:p.width,height:p.height})}case"AnnotationPage":return n(l.items[0],s,a,o,u);case"Choice":{const p=l;return!p.items||p.items[0]?await d():n(p.items[0],s,a,o,u)}case"Collection":{const p=l.items[0];return p?n(p,s,a,o,u):await d()}case"Manifest":{const p=l.items[0];return p?n(p,s,a,o,u):await d()}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return u&&!l.width&&(l.width=u.width,l.height=u.height),r.getThumbnailFromResource(l,s,a,o)}return await d()}return{getBestThumbnailAtSize:n}}function ii(t,e,{canvasId:r,manifestId:n}={}){const i=V(),s=Xe(),a=y.useMemo(()=>Yo(i,{imageServiceLoader:s}),[i,s]),[o,u]=y.useState(),d=ye(n?{id:n}:void 0),l=re(r?{id:r}:void 0),p=l||d,m=y.useRef(!1);if(y.useEffect(()=>(m.current=!1,()=>{m.current=!0}),[]),!p)throw new Error("Must be called under a manifest or canvas context.");return ri(A=>{a.getBestThumbnailAtSize(p,t,e).then(h=>{h.best&&!m.current&&u(h.best)})},[p]),o}function Go(t){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:t}}function Jo(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 si(t){const e=Math.round(t);return`${Math.floor(e/60)}:${`${e%60}`.padStart(2,"0")}`}function tt(t){const[e,r]=y.useReducer(Jo,Go(t.duration)),n=y.useRef(null),i=y.useRef(null),s=y.useRef(null),a=y.useRef(!1),o=y.useCallback(()=>{i.current&&n.current&&(i.current.innerHTML=si(n.current.currentTime),s.current&&(s.current.style.width=`${n.current.currentTime/t.duration*100}%`),a.current!==n.current.muted&&(a.current=n.current.muted,r(n.current.muted?{type:"MUTE"}:{type:"UNMUTE"})))},[t.duration]),u=y.useCallback(()=>{n.current&&(r({type:"PLAY_REQUESTED"}),n.current.play().then(()=>{r({type:"PLAY"})}),o())},[o]),d=y.useCallback(()=>{n.current&&(n.current.duration>0&&n.current.paused?u():l())},[o]),l=y.useCallback(()=>{n.current&&(n.current.pause(),r({type:"PAUSE"}),o())},[o]),p=y.useCallback(()=>{n.current&&(n.current.muted=!n.current.muted,r(n.current.muted?{type:"MUTE"}:{type:"UNMUTE"}))},[]),m=y.useCallback(()=>{n.current&&(n.current.muted=!0,r({type:"MUTE"}))},[]),A=y.useCallback(()=>{n.current&&(n.current.muted=!1,r({type:"UNMUTE"}))},[]),h=y.useCallback(S=>{n.current&&(n.current.muted=!1,n.current.volume=S/100,r({type:"SET_VOLUME",volume:S}))},[]),x=y.useCallback(S=>{n.current&&(n.current.currentTime=Math.max(0,Math.min(S*t.duration,t.duration)),o())},[]),b=y.useCallback(S=>{n.current&&(n.current.currentTime=Math.max(0,Math.min(S,t.duration)),o())},[]);return y.useEffect(()=>{const S=setInterval(()=>{o()},350);return()=>clearInterval(S)},[o,t.duration]),y.useEffect(()=>{const S=()=>{r({type:"FINISHED"})},w=n.current;return w==null||w.addEventListener("ended",S),()=>w==null?void 0:w.removeEventListener("ended",S)},[]),[{element:n,currentTime:i,progress:s},e,{play:u,pause:l,playPause:d,mute:m,unmute:A,toggleMute:p,setVolume:h,setDurationPercent:x,setTime:b}]}const ai=y.createContext(null),oi=y.createContext(null),ci=y.createContext(null);function Ko(){const t=y.useContext(ai);if(!t)throw new Error("Ctx not found");return t}function Zo(){const t=y.useContext(oi);if(!t)throw new Error("Ctx not found");return t}function Xo(){const t=y.useContext(ci);if(!t)throw new Error("Ctx not found");return t}function Bt({actions:t,state:e,children:r,currentTime:n,progress:i,element:s}){return g.jsx(ci.Provider,{value:{currentTime:n,progress:i,element:s},children:g.jsx(oi.Provider,{value:t,children:g.jsx(ai.Provider,{value:e,children:r})})})}function ui({media:t,children:e}){const[{element:r,currentTime:n,progress:i},s,a]=tt({duration:t.duration});return g.jsxs(Bt,{state:s,actions:a,currentTime:n,progress:i,element:r,children:[g.jsx("audio",{ref:r,src:t.url}),e]})}function li({media:t,mediaControlsDeps:e,children:r}){return Ie("portal","audio",ui,{media:t,children:r},[t,...e||[]]),null}function fi({element:t,media:e,playPause:r}){return g.jsxs("div",{className:"video-container",part:"video-container",onClick:r,children:[g.jsx("style",{children:`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),u=require("react"),_=require("@atlas-viewer/atlas"),X=require("@iiif/helpers/vault"),ge=require("@iiif/helpers/styles"),Y=require("@iiif/helpers/annotation-targets"),Bt=require("@iiif/helpers"),te=require("@atlas-viewer/iiif-image-api"),Ht=require("@iiif/helpers/thumbnail");function $t(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const ce=$t(u);function de(e,t){return de=Object.setPrototypeOf||function(r,o){return r.__proto__=o,r},de(e,t)}function Yt(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,de(e,t)}var zt=function(t,n){return t===void 0&&(t=[]),n===void 0&&(n=[]),t.length!==n.length||t.some(function(r,o){return!Object.is(r,n[o])})},Ie={error:null},Kt=function(e){Yt(t,e);function t(){for(var r,o=arguments.length,i=new Array(o),s=0;s<o;s++)i[s]=arguments[s];return r=e.call.apply(e,[this].concat(i))||this,r.state=Ie,r.resetErrorBoundary=function(){for(var a,l=arguments.length,f=new Array(l),d=0;d<l;d++)f[d]=arguments[d];r.props.onReset==null||(a=r.props).onReset.apply(a,f),r.reset()},r}t.getDerivedStateFromError=function(o){return{error:o}};var n=t.prototype;return n.reset=function(){this.setState(Ie)},n.componentDidCatch=function(o,i){var s,a;(s=(a=this.props).onError)==null||s.call(a,o,i)},n.componentDidUpdate=function(o,i){var s=this.state.error,a=this.props.resetKeys;if(s!==null&&i.error!==null&&zt(o.resetKeys,a)){var l,f;(l=(f=this.props).onResetKeysChange)==null||l.call(f,o.resetKeys,a),this.reset()}},n.render=function(){var o=this.state.error,i=this.props,s=i.fallbackRender,a=i.FallbackComponent,l=i.fallback;if(o!==null){var f={error:o,resetErrorBoundary:this.resetErrorBoundary};if(ce.isValidElement(l))return l;if(typeof s=="function")return s(f);if(a)return ce.createElement(a,f);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},t}(ce.Component);const Wt={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0,annotationPage:void 0},ne=u.createContext(Wt),O=()=>u.useContext(ne);function N({value:e,children:t}){const n=O(),r=u.useMemo(()=>({...n,...e}),[e,n]);return c.jsx(ne.Provider,{value:r,children:t})}const K=u.createContext({vault:null,setVaultInstance:e=>{}});function he({vault:e,vaultOptions:t,useGlobal:n,resources:r,children:o}){const[i,s]=u.useState(()=>e||(n?X.globalVault(t):t?new X.Vault(t):new X.Vault));return c.jsx(K.Provider,{value:{vault:i,setVaultInstance:s},children:c.jsx(N,{value:r||{},children:o})})}const M=()=>{const{vault:e}=u.useContext(K);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};function me(e,{noCache:t=!1}={}){const n=typeof e=="string"?e:e.id,r=M(),[o,i]=u.useState(n),[s,a]=u.useState(void 0),l=u.useMemo(()=>r.get(n,{skipSelfReturn:!0})||void 0,[n,r]),[f,d]=u.useState(l);return u.useEffect(()=>{(async()=>{try{const g=l&&!t?l:await r.load(n),p=g?g.id||g["@id"]:null;g&&o!==p&&i(p),d(g)}catch(g){a(g)}})()},[n,t]),{isLoaded:!!f,id:o,requestId:n,error:s,resource:f,cached:!!(f&&f===l)}}function Te(e,t){const{id:n,isLoaded:r,error:o,resource:i,requestId:s,cached:a}=me(e,t);return{id:n,isLoaded:r,error:o,manifest:i,requestId:s,cached:a}}function Ve({manifest:e,children:t}){return c.jsx(N,{value:{manifest:e},children:t})}function re({canvas:e,children:t}){return c.jsx(N,{value:{canvas:e},children:t})}function E(e,t=[]){const n=M(),[r,o]=u.useState(()=>e(n.getState(),n));return u.useEffect(()=>n.subscribe(i=>e(i,n),i=>{o(i)},!1),t),r}const W=u.createContext([]);function ve(){const e=u.useContext(W);return E(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}function D(e={},t=[]){const{id:n,selector:r}=e,o=O();M();const i=n||o.manifest,s=E(a=>i?a.iiif.entities.Manifest[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}function Le({range:e,children:t}){return c.jsx(N,{value:{range:e},children:t})}function ke(e,t){for(const n of t.items){if(n.type==="Canvas")return n;if(n.type==="SpecificResource")return n.source;if(n.type==="Range"){const r=ke(e,e.get(n));if(r)return r}}return null}function pe(e,t){var r;const n=[];for(const o of t.items)if(o.type==="SpecificResource"&&((r=o.source)==null?void 0:r.type)==="Canvas"&&(o.source.id.indexOf("#")!==-1?n.push({id:o.source.id.split("#")[0],type:"Canvas"}):n.push(o.source)),o.type==="Range"&&n.push(...pe(e,e.get(o))),o.type==="SpecificResource"){const i=typeof o.source=="string"?o.source:o.source.id;n.push({id:i,type:"Canvas"})}return n}function Gt(e,t,n){for(const r of t.structures){const o=ye(e,e.get(r),n);if(o)return o}return null}function ye(e,t,n){var r,o,i;for(const s of t.items){const a=(o=(r=s==null?void 0:s.source)==null?void 0:r.id)==null?void 0:o.split("#")[0];if(s.type==="SpecificResource"&&s.source===n||s.type==="SpecificResource"&&((i=s.source)==null?void 0:i.type)==="Canvas"&&n===a)return t;if(s.type==="Range"){const l=ye(e,e.get(s),n);if(l)return l}}return null}function Qt(e,t,n,r=!1){const o=t.behavior,i=n?e.get(n):null;if(!i)return[];const s=i.behavior,a=r?!1:o.includes("paged"),l=a?!1:o.includes("continuous"),f=a||l?!1:o.includes("individuals"),d=s.includes("facing-pages"),g=s.includes("non-paged");if(d||g||f||r)return[{id:i.id,type:"Canvas"}];const[p,y]=xe(e,t);if(l)return p;const m=p.findIndex(h=>h.id===n);if(m===-1)return[];for(const h of y)if(h.includes(m))return h.map(x=>p[x]);return[{id:i.id,type:"Canvas"}]}function xe(e,t,{disablePaging:n,skipNonPaged:r}={}){const o=t.behavior,i=o.includes("paged"),s=i?!1:o.includes("continuous"),a=i||s?!1:o.includes("individuals"),l=t.type==="Manifest"?t.items:pe(e,t);if(s)return[l,[l.map((m,h)=>h)]];if(a||!i||n)return[l,l.map((m,h)=>[h])];const f=[];let d=[];const g=()=>{d.length&&(f.push([...d]),d=[])};let p=0,y=!1;for(let m=0;m<l.length;m++){const h=e.get(l[m]);if(h.behavior.includes("non-paged")){m===p&&p++,r||(g(),f.push([m]),g());continue}if(m===p||h.behavior.includes("facing-pages")){d.length&&(y=!0),g(),f.push([m]),g();continue}if(d.push(m),y){g(),y=!1;continue}d.length>1&&g()}return d.length&&g(),[l,f]}function Oe(e={},t=[]){const{id:n,selector:r}=e,o=O(),i=n||o.range,s=E(a=>i?a.iiif.entities.Range[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}function Fe({startCanvas:e,disablePaging:t}){var m;const n=M(),r=D(),o=Oe(),[i,s]=u.useState(void 0),a=o||r;if(!a)throw new Error("Nothing selected");const[l,f]=u.useMemo(()=>xe(n,a,{disablePaging:t}),[n,a]),d=u.useCallback(h=>{const x=f.findIndex(C=>C.includes(h));s(x===-1?0:x)},[l,f]),g=u.useCallback(h=>{const x=l.findIndex(C=>C.id===h);x!==-1?d(x):s(0)},[l,f]),p=u.useCallback(()=>{s(h=>h>=f.length?h:h+1)},[f]),y=u.useCallback(()=>{s(h=>h<=0?0:h-1)},[f]);return typeof i>"u"&&(e?g(e):s(0)),{visibleItems:((m=f[i])==null?void 0:m.map(h=>l[h].id))||[],cursor:i,items:l,sequence:f,setSequenceIndex:s,setCanvasIndex:d,setCanvasId:g,next:p,previous:y}}const $=()=>{},G=u.createContext({setCurrentCanvasId:$,setCurrentCanvasIndex:$,nextCanvas:$,previousCanvas:$,items:[],sequence:[],setSequenceIndex:$,currentSequenceIndex:0});function Ne(e){const t=D(),{cursor:n,visibleItems:r,next:o,sequence:i,items:s,setCanvasIndex:a,setCanvasId:l,previous:f,setSequenceIndex:d}=Fe({startCanvas:e.startCanvas,disablePaging:e.pagingEnabled===!1}),g=u.useMemo(()=>({sequence:i,items:s,setCurrentCanvasId:l,nextCanvas:o,previousCanvas:f,totalCanvases:s.length,setCurrentCanvasIndex:a,setSequenceIndex:d,currentSequenceIndex:n}),[i,s,l,o,f,s,a,d,n]);return t?r.length===0?null:c.jsx(G.Provider,{value:g,children:c.jsx(W.Provider,{value:r,children:c.jsx(re,{canvas:r[0],children:e.children})})}):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),c.jsx("div",{children:"Sorry, something went wrong."}))}function De(e){const t=Te(e.manifest);if(!t)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),c.jsx("div",{children:"Sorry, something went wrong."});if(t.error)return c.jsx("div",{children:t.error.toString()});if(!t.isLoaded)return c.jsx("div",{children:"Loading..."});const n=c.jsx(Ne,{...e,children:e.children});return c.jsx(Ve,{manifest:t.id,children:e.rangeId?c.jsx(Le,{range:e.rangeId,children:n}):n})}function qe(){return u.useContext(G)}function _e(){return{VaultContext:u.useContext(K),ResourceContext:u.useContext(ne),SimpleViewerReactContext:u.useContext(G),VisibleCanvasReactContext:u.useContext(W)}}function Ue(e){return c.jsx(he,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext,children:c.jsx(W.Provider,{value:e.bridge.VisibleCanvasReactContext,children:c.jsx(G.Provider,{value:e.bridge.SimpleViewerReactContext,children:e.children})})})}const T=function(e){return function(){const t={type:e,getType:()=>e,toString:()=>e};return(n,r)=>({...t,...n!==void 0&&{payload:n},...r!==void 0&&{meta:r}})}},Jt="@iiif/IMPORT_ENTITIES",Zt="@iiif/MODIFY_ENTITY_FIELD",Xt="@iiif/REORDER_ENTITY_FIELD",en="@iiif/ADD_REFERENCE",tn="@iiif/UPDATE_REFERENCE",nn="@iiif/REMOVE_REFERENCE",rn="@iiif/ADD_METADATA",on="@iiif/REMOVE_METADATA",sn="@iiif/UPDATE_METADATA",an="@iiif/REORDER_METADATA",un=T(Jt)(),cn=T(Zt)(),ln=T(Xt)(),dn=T(en)(),fn=T(nn)(),gn=T(tn)(),hn=T(rn)(),mn=T(sn)(),vn=T(on)(),pn=T(an)(),le={importEntities:un,modifyEntityField:cn,reorderEntityField:ln,addReference:dn,removeReference:fn,updateReference:gn,addMetadata:hn,removeMetadata:vn,updateMetadata:mn,reorderMetadata:pn};function Be(){const t=M().getStore();return u.useMemo(()=>n=>t.dispatch(n),[t])}function Re(e){return typeof e!="string"&&e&&e.bindToVault}function He(){const e=M(),t=u.useRef([]),n=Be(),r=u.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);u.useLayoutEffect(()=>{const a={id:r,type:"AnnotationPage",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],rendering:[],service:[]};n(le.importEntities({entities:{AnnotationPage:{[a.id]:a}}}))},[r]);const o=E(a=>r?a.iiif.entities.AnnotationPage[r]:null,[r]),i=u.useCallback((a,l)=>{if(r){if(Re(a)){const g=a;g.__vault||g.bindToVault(e),a=typeof g.source=="string"?g.source:g.source.id,t.current[a]=g}else typeof a!="string"&&(a=a.id);const f=e.get({id:r,type:"AnnotationPage"}),d=e.get({id:a,type:"Annotation"});f&&d&&(f.items.find(g=>g.id===d.id)||n(le.addReference({id:r,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"},index:l})))}},[r]),s=u.useCallback(a=>{r&&(Re(a)?a=typeof a.source=="string"?a.source:a.source.id:typeof a!="string"&&(a=a.id),t.current[a]&&t.current[a].beforeRemove(),e.get({id:r,type:"AnnotationPage"})&&n(le.removeReference({id:r,type:"AnnotationPage",key:"items",reference:{id:a,type:"Annotation"}})))},[r]);return[o,{addAnnotation:i,removeAnnotation:s}]}const $e=u.createContext(null);function Ye(){const e=u.useContext($e);return[e.fullPage,{addAnnotation:e.addAnnotation,removeAnnotation:e.removeAnnotation}]}function ze({children:e}){const[t,{addAnnotation:n,removeAnnotation:r}]=He();return c.jsx($e.Provider,{value:u.useMemo(()=>({fullPage:t,addAnnotation:n,removeAnnotation:r}),[t]),children:e})}function yn({width:e,style:t,height:n,error:r,resetErrorBoundary:o}){return c.jsxs("div",{style:{width:e,height:n,minHeight:500,...t||{},background:"#f9f9f9"},children:[c.jsx("h3",{children:"Error occurred"}),c.jsx("p",{children:r.message}),c.jsx("button",{onClick:o,children:"Reset"})]})}const oe=u.createContext(null);function Ke(){return u.useContext(oe)}const We=u.createContext(()=>{}),Ge=u.createContext(()=>{});function U(e,t,n,r,o=[]){const i=u.useContext(e==="portal"?Ge:We);u.useEffect(()=>(e!=="none"&&i(t,n,r),()=>{i(t,null)}),[t,e,i,...o])}function V(e={},t=[]){const{id:n,selector:r}=e,o=O(),i=n||o.canvas,s=E(a=>i?a.iiif.entities.Canvas[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}const Qe=u.createContext(()=>{});function xn(e){const t=V(),n=u.useContext(Qe);u.useEffect(()=>t&&t.id?(n(t.id,e),()=>n(t.id,-1)):()=>{},[t,e])}function Sn({children:e,errorFallback:t,outerContainerProps:n={},worldScale:r,...o}){const[i,s]=u.useState(),a=_e(),l=t||yn,[f,d]=u.useState({}),g=Object.entries(f),[p,y]=u.useState({}),m=Object.entries(p),[h,x]=u.useState({}),C=u.useMemo(()=>r||Math.max(...Object.values(h)),[h]),j=u.useMemo(()=>({maxOverZoom:C||1,...o.runtimeOptions||{}}),[C,o.runtimeOptions]),S=u.useCallback((w,I)=>{x(A=>{if(I===-1){const{[w]:v,...k}=A;return k}return{...A,[w]:I}})},[]),L=u.useCallback((w,I,A)=>{d(({[w]:v,...k})=>I?{...k,[w]:{element:I,props:A}}:k)},[]),Q=u.useCallback((w,I,A)=>{y(({[w]:v,...k})=>I?{...k,[w]:{element:I,props:A}}:k)},[]);return c.jsxs(Kt,{resetKeys:[],fallbackRender:w=>c.jsx(l,{...o,...w}),children:[c.jsx(_.AtlasAuto,{...o,containerProps:{style:{position:"relative"},...o.containerProps||{}},htmlChildren:c.jsx(c.Fragment,{children:g.map(([w,{element:I,props:A}])=>c.jsx(u.Fragment,{children:c.jsx(I,{...A||{}})},w))}),onCreated:w=>{s(w),o.onCreated&&o.onCreated(w)},runtimeOptions:j,children:c.jsx(oe.Provider,{value:i,children:c.jsx(Qe.Provider,{value:S,children:c.jsx(We.Provider,{value:L,children:c.jsx(Ge.Provider,{value:Q,children:c.jsx(Ue,{bridge:a,children:c.jsx(_.ModeContext.Provider,{value:o.mode||"explore",children:c.jsx(ze,{children:e})})})})})})})}),c.jsx("div",{children:m.map(([w,{element:I,props:A}])=>c.jsx(u.Fragment,{children:c.jsx(I,{...A||{}})},w))})]})}const J={},Je={get(e){return e},setMetaValue([e,t,n],r){const o=Je.getResourceMeta(e,t),i=o?o[n]:void 0,s=typeof r=="function"?r(i):r;J[e]={...J[e]||{},[t]:{...(J[e]||{})[t]||{},[n]:s}}},getResourceMeta:(e,t)=>{const n=J[e];if(n)return t?n[t]:n}};function Ze(e=Je){return{addEventListener(t,n,r,o){if(t)return e.setMetaValue([t.id,"eventManager",n],i=>{const s=i||[];for(const a of s)if(a.callback===r)return s;return[...s,{callback:r,scope:o}]}),r},removeEventListener(t,n,r){t&&e.setMetaValue([t.id,"eventManager",n],o=>(o||[]).filter(i=>i.callback!==r))},getListenersAsProps(t,n){const r=typeof t=="string"?{id:t}:t;if(!r||!r.id)return{};const o=e.getResourceMeta(r.id,"eventManager"),i={};if(o&&r)for(const s of Object.keys(o))i[s]=a=>{const l=e.get(r);for(const{callback:f,scope:d}of o[s]||[])(!d||n&&d.indexOf(n)!==-1)&&f(a,l)};return i}}}function Se(e,t){const n=M(),r=u.useMemo(()=>Ze(n),[n]),o=E(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return u.useMemo(()=>e?r.getListenersAsProps(e,t):{},[o,e,n,t])}function z(e,t){const n=M(),r=u.useMemo(()=>ge.createStylesHelper(n),[n]);return E(()=>{if(!e)return null;const o=r.getAppliedStyles(e.id);return o?t?o[t]:o:void 0},[e,t])}function Ce(e={},t=[]){const{id:n,selector:r}=e,o=O(),i=M(),s=n||o.annotation,a=E(f=>s?f.iiif.entities.Annotation[s]:void 0,[s]),l=E(f=>a&&a.body?a.body.map(d=>d?d.type==="SpecificResource"?{...d,source:i.get(d)}:d?f.iiif.entities[d.type][d.id]:null:null).filter(Boolean):[],[a]);return u.useMemo(()=>{if(!a)return;const f={...a,body:l,target:Y.expandTarget(a.target,{typeMap:i.getState().iiif.mapping})};return r?r(f):f},[a,r,l,...t])}const Xe=({id:e,style:t,className:n,interactive:r})=>{const o=Ce({id:e}),i=z(o,"atlas"),s=z(o,"html"),a=Se(o,["atlas"]),l=V(),f=u.useMemo(()=>_.mergeStyles(t,i),[t,i]);return l&&o&&o.target&&o.target.selector&&o.target.selector.type==="BoxSelector"&&o.target.source&&(o.target.source.id===l.id||o.target.source===l.id)?c.jsx(_.RegionHighlight,{id:o.id,isEditing:!0,region:o.target.selector.spatial,style:f,className:(s==null?void 0:s.className)||n,interactive:!!(s!=null&&s.href||r),href:(s==null?void 0:s.href)||null,title:(s==null?void 0:s.title)||null,hrefTarget:(s==null?void 0:s.target)||null,onClick:()=>{},...a}):null};function et(e={},t=[]){const{id:n,selector:r}=e,o=O(),i=n||o.annotationPage,s=E(a=>i?a.iiif.entities.AnnotationPage[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,...t])}const fe=({className:e,page:t})=>{var i;const n=et({id:t.id})||t,r=z(n,"atlas"),o=z(n,"html");return E(s=>n.id?s.iiif.entities.AnnotationPage[n.id]:null,[]),c.jsx(u.Fragment,{children:(i=n.items)==null?void 0:i.map(s=>c.jsx(Xe,{id:s.id,style:r,className:(o==null?void 0:o.className)||e},s.id))})};function tt({id:e,image:t,thumbnail:n,isStatic:r,x:o=0,y:i=0,children:s,selector:a,onClick:l,enableSizes:f}){var g,p;const d=u.useMemo(()=>{if(!(!a||a.spatial.x===0&&a.spatial.y===0))return a.spatial},[a]);return c.jsx("world-object",{x:o+t.target.spatial.x,y:i+t.target.spatial.y,width:t.target.spatial.width,height:t.target.spatial.height,onClick:l,children:t.service?c.jsxs(u.Fragment,{children:[c.jsx(_.TileSet,{tiles:{id:t.service.id||t.service["@id"]||"unknown",height:t.height,width:t.width,imageService:t.service,thumbnail:n&&n.type==="fixed"?n:void 0},enableSizes:f,x:0,y:0,width:(g=t.target)==null?void 0:g.spatial.width,height:(p=t.target)==null?void 0:p.spatial.height,crop:d}),s]},"service"):c.jsxs(u.Fragment,{children:[c.jsx("world-image",{onClick:l,uri:t.id,target:{x:0,y:0,width:t.target.spatial.width,height:t.target.spatial.height},display:t.width&&t.height?{width:t.width,height:t.height}:void 0,crop:d}),s]},"no-service")},e+(t.service?"server":"no-service"))}function Cn(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function be(e,t){const{selector:n,source:r}=Bt.expandTarget(t);if(r.id!==e.id)return[null,r];const o={type:"BoxSelector",spatial:{x:0,y:0,width:Number(e.width),height:Number(e.height)}};return[n?n.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:n.temporal,spatial:o.spatial}:n:null,r]}const nt={makeChoice:()=>{}},ee={type:"unknown"},P=e=>({type:"unknown",reason:e,annotations:{pages:[]}}),rt=(e,t)=>({type:"empty",width:e,height:t,annotations:{pages:[]},image:null,images:[]});function bn(e,t){var r;const n=(r=e==null?void 0:e.iiif)==null?void 0:r.meta[t];return n?n.annotationPageManager:null}function wn(e,t){return E(n=>{const r=[];if(!e)return r;const o=Object.keys(n.iiif.entities.AnnotationPage);for(const i of o)if(!t||t.indexOf(i)!==-1){const s=bn(n,i);s&&s.views&&s.views[e]&&r.push(i)}return r},[e,t])}function ot({canvas:e,manifest:t,all:n,canvases:r}){const o=[];if(t)for(const i of t.annotations)o.indexOf(i.id)===-1&&o.push(i.id);if(n){if(r&&r.length)for(const i of r)for(const s of i.annotations)o.indexOf(s.id)===-1&&o.push(s.id)}else if(e)for(const i of e.annotations)o.indexOf(i.id)===-1&&o.push(i.id);return o}function Pn(e,t){var r;const n=(r=e==null?void 0:e.iiif)==null?void 0:r.meta[t];return n?n.annotationPageManager:null}function it(e,t={}){const n=M(),r=D(),o=V(),i=ve(),s=u.useMemo(()=>ot({all:t.all,manifest:r,canvas:o,canvases:i}),[t.all,o,i,r]),a=wn(e,t.all?void 0:s),l=u.useCallback(d=>{e&&n.setMetaValue([d,"annotationPageManager","views"],g=>g&&!g[e]?g:{...g||{},[e]:!1})},[e,n]),f=u.useCallback((d,g={})=>{if(!e)return;const p=n.getState(),y=[];if(g!=null&&g.deselectOthers){const m=Object.keys(p.iiif.entities.AnnotationPage);for(const h of m){const x=Pn(p,h);x&&x.views&&x.views[e]&&y.push(h)}}for(const m of y)l(m);n.setMetaValue([d,"annotationPageManager","views"],m=>m&&m[e]?m:{...m||{},[e]:!0})},[e,l,n]);return{availablePageIds:s,enabledPageIds:a,setPageEnabled:f,setPageDisabled:l}}function st(e,t){return E((n,r)=>r.get(e.map(o=>({id:o,type:t}))),[e,t])}const at=u.createContext(new te.ImageServiceLoader);function ie(){return u.useContext(at)}function ut(){const e=ie(),[t,n]=u.useState({}),r=u.useRef(!1);return u.useEffect(()=>()=>{r.current=!0},[]),[u.useCallback((i,{height:s,width:a})=>{if(i){const l=i.id||i["@id"],f=e.loadServiceSync({id:l,width:i.width||a,height:i.height||s,source:i});f?i=f:t[l]||(r.current||n(d=>({...d,[l]:"loading"})),e.loadService({id:l,width:i.width||a,height:i.height||s}).then(()=>{r.current||n(d=>({...d,[l]:"done"}))}))}return i},[e,t]),t]}function se(e={}){const t=Ce(),n=V(e.canvasId?{id:e.canvasId}:void 0);return E((r,o)=>{if(!n)return[];if(t&&e.enableSingleAnnotation)return[t];const i=o.get(n.items),s=[];for(const a of i)s.push(...o.get(a.items));return s},[n])}function Mn(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}const Z={},ct={get(e){return e},setMetaValue([e,t,n],r){const o=ct.getResourceMeta(e,t),i=o?o[n]:void 0,s=typeof r=="function"?r(i):r;Z[e]={...Z[e]||{},[t]:{...(Z[e]||{})[t]||{},[n]:s}}},getResourceMeta:(e,t)=>{const n=Z[e];if(n)return t?n[t]:n}};function jn(e=ct){function t(o){const i=o?typeof o=="string"?e.get(o):o:null;if(!i)return[];const s=e.get(i.items,{parent:i}),a=[];for(const l of s)a.push(...e.get(l.items,{parent:l}));return a}function n(o,i=[]){const s=Array.isArray(o)?o:t(o),a=[];let l=null;const f=[];for(const d of s){if(d.type!=="Annotation")throw new Error("getPaintables() accept either a canvas or list of annotations");const g=Array.from(Array.isArray(d.body)?d.body:[d.body]);for(const p of g){const[y,{selector:m}]=Mn(p),h=e.get(y),x=(h.type||"unknown").toLowerCase();if(x==="choice"){const C=e.get(h.items,{parent:h.id}),j=i.length?i.map(S=>C.find(L=>L.id===S)).filter(Boolean):[C[0]];j.length===0&&j.push(C[0]),l={type:"single-choice",items:C.map(S=>({id:S.id,label:S.label,selected:j.indexOf(S)!==-1})),label:y.label},g.push(...j);continue}a.indexOf(x)===-1&&a.push(x),f.push({type:x,annotationId:d.id,resource:h,target:d.target,selector:m})}}return{types:a,items:f,choice:l}}function r(o){const{choice:i}=n(o);return i}return{getAllPaintingAnnotations:t,getPaintables:n,extractChoices:r}}function lt(e,t=[]){const n=M(),r=u.useMemo(()=>jn(n),[]),o=se({enableSingleAnnotation:e==null?void 0:e.enableSingleAnnotation}),[i,s]=u.useState((e==null?void 0:e.defaultChoices)||[]),a=u.useMemo(()=>r.getPaintables(o,i),[n,o,i,...t]),f={makeChoice:u.useCallback((d,{deselectOthers:g=!0,deselect:p=!1}={})=>{if(a.choice){if(a.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");s(y=>{if(p){const h=y.filter(x=>x!==d);if(h.length===0){const x=a.items[0].resource.id;return x?[x]:[]}return h}if(g)return[d];const m=[...y];if(m.length===0&&a.items.length){const h=a.items[0].resource.id;h&&m.push(h)}return y.indexOf(d)!==-1?y:[...y,d]})}},[a.choice])};return[a,f]}const En=["model/gltf-binary"];function dt(e,t){const r=t.items[0].resource;return r.format?En.indexOf(r.format)===-1?P(`3D format: ${r.format} is unsupported`):{type:"3d-model",model:r}:P("Unknown format")}function In(e,t){var r;if(!e.duration)return P("No duration on canvas");if(t.items.length>1)return P("Only one audio source supported");const n=(r=t.items[0])==null?void 0:r.resource;return n?n.format?{type:"media",media:{annotationId:t.items[0].annotationId,duration:e.duration,url:n.id,type:"Sound",target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:n.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}},annotations:{pages:[]}}:P("Audio does not have format"):P("Unknown audio")}function ft(e,t,n){const r=[];for(const o of t.items){const i=o.resource&&o.resource.type==="SpecificResource"?o.resource.source:o.resource;if(!i.id)return P("No resource Identifier");let s;if(i.service){const y=te.getImageServices(i);y[0]&&(s=n(y[0],e))}const a={type:"BoxSelector",spatial:{x:0,y:0,width:Number(e.width),height:Number(e.height)}},[l,f]=be(e,o.target);if(f.id!==e.id)continue;o.resource.width&&o.resource.height&&(o.resource.width,o.resource.height);let d=o.resource.type==="SpecificResource"?Y.expandTarget(o.resource):null;if(o.selector){const y=Y.expandTarget({type:"SpecificResource",source:o.resource,selector:o.selector});y&&(d=y)}const g=d&&d.selector&&(d.selector.type==="BoxSelector"||d.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:d.selector.spatial.x,y:d.selector.spatial.y,width:d.selector.spatial.width,height:d.selector.spatial.height}}:void 0;s&&!s.id&&(s.id=s["@id"]);const p={id:i.id,type:"Image",annotationId:o.annotationId,width:Number(l||g?i.width:e.width),height:Number(l||g?i.height:e.height),service:s,sizes:s&&s.sizes?s.sizes:i.width&&i.height?[{width:i.width,height:i.height}]:[],target:l&&l.type!=="PointSelector"?l:a,selector:g};r.push(p)}return{type:"images",image:r[0],images:r,choice:t.choice}}function gt(e,t={},n){const r=e.language||n||"none";switch(e.type){case"TextualBody":{typeof e.value<"u"&&(t[r]=e.value);break}case"List":case"Composite":case"Choice":e.items&&e.items.forEach(o=>gt(o,t,r))}return t}function ht(e,t){const n=[];return t.items.forEach(r=>{if(r.resource){const[o]=be(e,r.target);n.push({annotationId:r.annotationId,text:gt(r.resource),target:o})}}),{type:"textual-content",items:n}}const Rn=/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?vi?=|&vi?=))([^#&?]*).*/;function mt(e,t){var s;const n=t.items.filter(a=>a.type==="video");if(!e.duration)return P("No duration on canvas");if(n.length>1)return P("Only one video source supported");const r=(s=n[0])==null?void 0:s.resource,o=!!(r.service||[]).find(a=>(a.profile||"").includes("youtube.com"));if(!r)return P("Unknown video");if((!r.format||r.format==="text/html")&&!o)return P("Video does not have format");const i={annotationId:t.items[0].annotationId,duration:e.duration,url:r.id,type:"Video",items:[],target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:r.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}};if(o){i.type="VideoYouTube";const a=r.id.match(Rn);if(!a[1])return P("Video is not known youtube video");i.youTubeId=a[1]}return{type:"media",media:i,annotations:{pages:[]}}}function vt({canvas:e,paintables:t,supports:n,loadImageService:r}){if(!e)return console.log("No canvas"),ee;if(t.types.length===0)return n.indexOf("empty")!==-1?rt(e.width,e.height):(console.log("No paintables"),ee);if(t.types.length!==1)if(t.types.length===2&&t.types.indexOf("text")!==-1)t.types=t.types.filter(i=>i!=="text");else return n.indexOf("complex-timeline")===-1?P("Complex timeline not supported"):P("ComplexTimelineStrategy not yet supported");const o=t.types[0];return o==="image"?n.indexOf("images")===-1?P("Image not supported"):ft(e,t,r):o==="Model"||o==="model"?n.indexOf("3d-model")===-1?P("3D not supported"):dt(e,t):o==="textualbody"?n.indexOf("textual-content")===-1?P("Textual content not supported"):ht(e,t):o==="sound"||o==="audio"?n.indexOf("media")===-1?P("Media not supported"):In(e,t):o==="video"?n.indexOf("media")===-1?P("Media not supported"):mt(e,t):ee}function pt(e){const t=D(),n=V(),r=M(),[o,i]=ut(),{enabledPageIds:s}=it((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id)||(n==null?void 0:n.id),{all:!1}),a=st(s,"AnnotationPage"),l=(e==null?void 0:e.strategies)||["empty","images","media","textual-content","complex-timeline"],[f,d]=lt(e,[i]),g=u.useMemo(()=>vt({canvas:n,paintables:f,supports:l,loadImageService:o}),[n,f,r,d.makeChoice]);return u.useMemo(()=>g.type==="unknown"?[g,nt]:[{...g,annotations:{pages:a}},d],[g,a])}const yt=(e,t=[])=>{const n=M();u.useEffect(()=>{e(n)},[n,...t])};function xt(e,t,{canvasId:n,manifestId:r}={}){const o=M(),i=ie(),s=u.useMemo(()=>Ht.createThumbnailHelper(o,{imageServiceLoader:i}),[o,i]),[a,l]=u.useState(),f=D(r?{id:r}:void 0),d=V(n?{id:n}:void 0),g=d||f,p=u.useRef(!1);if(u.useEffect(()=>(p.current=!1,()=>{p.current=!0}),[]),!g)throw new Error("Must be called under a manifest or canvas context.");return yt(y=>{s.getBestThumbnailAtSize(g,e,t).then(m=>{m.best&&!p.current&&l(m.best)})},[g]),a}function An(e){return{isMuted:!1,playRequested:!1,isPlaying:!1,isFinished:!1,volume:100,duration:e}}function Tn(e,t){switch(t.type){case"FINISHED":return{...e,isFinished:!0,isPlaying:!1,playRequested:!1};case"PLAY_PAUSE":return{...e,isFinished:!1,isPlaying:!e.isPlaying};case"PLAY_REQUESTED":return{...e,isFinished:!1,playRequested:!0};case"PAUSE":return{...e,isPlaying:!1};case"PLAY":return{...e,isFinished:!1,playRequested:!1,isPlaying:!0};case"MUTE":return{...e,isMuted:!0};case"SET_VOLUME":return{...e,volume:t.volume,isMuted:t.volume===0};case"TOGGLE_MUTE":return{...e,isMuted:!e.isMuted};case"UNMUTE":return{...e,isMuted:!1}}return e}function St(e){const t=Math.round(e);return`${Math.floor(t/60)}:${`${t%60}`.padStart(2,"0")}`}function ae(e){const[t,n]=u.useReducer(Tn,An(e.duration)),r=u.useRef(null),o=u.useRef(null),i=u.useRef(null),s=u.useRef(!1),a=u.useCallback(()=>{o.current&&r.current&&(o.current.innerHTML=St(r.current.currentTime),i.current&&(i.current.style.width=`${r.current.currentTime/e.duration*100}%`),s.current!==r.current.muted&&(s.current=r.current.muted,n(r.current.muted?{type:"MUTE"}:{type:"UNMUTE"})))},[e.duration]),l=u.useCallback(()=>{r.current&&(n({type:"PLAY_REQUESTED"}),r.current.play().then(()=>{n({type:"PLAY"})}),a())},[a]),f=u.useCallback(()=>{r.current&&(r.current.duration>0&&r.current.paused?l():d())},[a]),d=u.useCallback(()=>{r.current&&(r.current.pause(),n({type:"PAUSE"}),a())},[a]),g=u.useCallback(()=>{r.current&&(r.current.muted=!r.current.muted,n(r.current.muted?{type:"MUTE"}:{type:"UNMUTE"}))},[]),p=u.useCallback(()=>{r.current&&(r.current.muted=!0,n({type:"MUTE"}))},[]),y=u.useCallback(()=>{r.current&&(r.current.muted=!1,n({type:"UNMUTE"}))},[]),m=u.useCallback(C=>{r.current&&(r.current.muted=!1,r.current.volume=C/100,n({type:"SET_VOLUME",volume:C}))},[]),h=u.useCallback(C=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(C*e.duration,e.duration)),a())},[]),x=u.useCallback(C=>{r.current&&(r.current.currentTime=Math.max(0,Math.min(C,e.duration)),a())},[]);return u.useEffect(()=>{const C=setInterval(()=>{a()},350);return()=>clearInterval(C)},[a,e.duration]),u.useEffect(()=>{const C=()=>{n({type:"FINISHED"})},j=r.current;return j==null||j.addEventListener("ended",C),()=>j==null?void 0:j.removeEventListener("ended",C)},[]),[{element:r,currentTime:o,progress:i},t,{play:l,pause:d,playPause:f,mute:p,unmute:y,toggleMute:g,setVolume:m,setDurationPercent:h,setTime:x}]}const Ct=u.createContext(null),bt=u.createContext(null),wt=u.createContext(null);function Vn(){const e=u.useContext(Ct);if(!e)throw new Error("Ctx not found");return e}function Ln(){const e=u.useContext(bt);if(!e)throw new Error("Ctx not found");return e}function kn(){const e=u.useContext(wt);if(!e)throw new Error("Ctx not found");return e}function we({actions:e,state:t,children:n,currentTime:r,progress:o,element:i}){return c.jsx(wt.Provider,{value:{currentTime:r,progress:o,element:i},children:c.jsx(bt.Provider,{value:e,children:c.jsx(Ct.Provider,{value:t,children:n})})})}function Pt({media:e,children:t}){const[{element:n,currentTime:r,progress:o},i,s]=ae({duration:e.duration});return c.jsxs(we,{state:i,actions:s,currentTime:r,progress:o,element:n,children:[c.jsx("audio",{ref:n,src:e.url}),t]})}function Mt({media:e,mediaControlsDeps:t,children:n}){return U("portal","audio",Pt,{media:e,children:n},[e,...t||[]]),null}function jt({element:e,media:t,playPause:n}){return c.jsxs("div",{className:"video-container",part:"video-container",onClick:n,children:[c.jsx("style",{children:`
66
2
  .video-container {
67
3
  position: absolute;
68
4
  top: 0;
@@ -75,7 +11,7 @@
75
11
  justify-content: center;
76
12
  pointer-events: visible;
77
13
  }
78
- `}),g.jsx("video",{ref:t,src:e.url,style:{width:"100%",objectFit:"contain"}})]})}function pi({media:t,mediaControlsDeps:e,children:r}){const[{element:n,currentTime:i,progress:s},a,o]=tt({duration:t.duration});return Ie("overlay","video-element",fi,{element:n,media:t,playPause:o.playPause}),Ie("portal","custom-controls",Bt,{state:a,actions:o,currentTime:i,progress:s,element:n,children:r},[i,a,t,...e||[]]),null}function di({model:t}){return g.jsxs(g.Fragment,{children:[g.jsx("style",{children:`
14
+ `}),c.jsx("video",{ref:e,src:t.url,style:{width:"100%",objectFit:"contain"}})]})}function Et({media:e,mediaControlsDeps:t,children:n}){const[{element:r,currentTime:o,progress:i},s,a]=ae({duration:e.duration});return U("overlay","video-element",jt,{element:r,media:e,playPause:a.playPause}),U("portal","custom-controls",we,{state:s,actions:a,currentTime:o,progress:i,element:r,children:n},[o,s,e,...t||[]]),null}function It({model:e}){return c.jsxs(c.Fragment,{children:[c.jsx("style",{children:`
79
15
  .model-container {
80
16
  position: absolute;
81
17
  top: 0;
@@ -88,9 +24,9 @@
88
24
  justify-content: center;
89
25
  pointer-events: visible;
90
26
  }
91
- `}),g.jsx("div",{className:"model-container",children:g.jsx("model-viewer",{"interaction-prompt":"none",style:{width:"100%",height:"100%"},"camera-controls":"","ar-status":"not-presenting",src:t.id})})]})}function hi({model:t,name:e}){return Ie("overlay",`model-${e}`,di,{model:t},[t]),null}function yi({style:t}){const e=re();return!e||!e.height||!e.width?null:g.jsx("box",{interactive:!1,target:{x:0,y:0,width:Number(e.width),height:Number(e.height)},style:t})}const vi=y.createContext("en");function ec(t){return g.jsx(vi.Provider,{value:t.language,children:t.children})}function rt(){return y.useContext(vi)}function dr(t){return t.indexOf("-")!==-1?t.slice(0,t.indexOf("-")):t}function gi({as:t,language:e,children:r,viewingDirection:n,...i}){const s=rt();return y.useMemo(()=>dr(s)===dr(e),[s,e])?t?g.jsx(t,{...i,children:r}):g.jsx("span",{...i,children:r}):t?g.jsx(t,{...i,lang:e,dir:n,children:r}):g.jsx("span",{...i,lang:e,dir:n,children:r})}function mi(t,e,r){if(e.length===0)return;if(e.length===1)return e[0];if(e.indexOf(t)!==-1)return t;const n=t.indexOf("-")!==-1?t.slice(0,t.indexOf("-")):null;if(n&&e.indexOf(n)!==-1)return n;for(const i of r)if(e.indexOf(i)!==-1)return i;return e.indexOf("none")!==-1?"none":e.indexOf("@none")!==-1?"@none":e[0]}const xi=(t,e=[])=>{const r=rt();return y.useMemo(()=>{const n=t();return mi(r,n,[])},[r,...e])};function bi(t,e){const r=xi(()=>Object.keys(t||{}),[t]);return[y.useMemo(()=>{if(!t)return e||"";if(typeof t=="string")return t;const n=r?t[r]:void 0;return n?typeof n=="string"?n:n.join(`
92
- `):""},[r,e,t]),r]}function tc(){const t=rt();return function(r,n,i){const s=Object.keys(r||{}),a=mi(t,s,[]);if(!r)return n||"";if(typeof r=="string")return r;const o=a?r[a]:void 0;return o?typeof o=="string"?o:o.join(typeof i<"u"?i:`
93
- `):""}}const Ai=({as:t,defaultText:e,enableDangerouslySetInnerHTML:r,children:n,...i})=>{const[s,a]=bi(n,e);return a?g.jsx(gi,{...i,as:t,language:a,title:r?void 0:s,dangerouslySetInnerHTML:r?{__html:s}:void 0,children:r?void 0:s}):t?g.jsx(t,{...i,children:s}):g.jsx("span",{...i,title:r?void 0:s,dangerouslySetInnerHTML:r?{__html:s}:void 0,children:r?void 0:s})};function rc({element:t,media:e,playPause:r}){const n=y.useRef(null);return e.youTubeId?g.jsxs("div",{className:"video-container",part:"video-container",onClick:r,children:[g.jsx("style",{children:`
27
+ `}),c.jsx("div",{className:"model-container",children:c.jsx("model-viewer",{"interaction-prompt":"none",style:{width:"100%",height:"100%"},"camera-controls":"","ar-status":"not-presenting",src:e.id})})]})}function Rt({model:e,name:t}){return U("overlay",`model-${t}`,It,{model:e},[e]),null}function At({style:e}){const t=V();return!t||!t.height||!t.width?null:c.jsx("box",{interactive:!1,target:{x:0,y:0,width:Number(t.width),height:Number(t.height)},style:e})}const Tt=u.createContext("en");function On(e){return c.jsx(Tt.Provider,{value:e.language,children:e.children})}function ue(){return u.useContext(Tt)}function Ae(e){return e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):e}function Vt({as:e,language:t,children:n,viewingDirection:r,...o}){const i=ue();return u.useMemo(()=>Ae(i)===Ae(t),[i,t])?e?c.jsx(e,{...o,children:n}):c.jsx("span",{...o,children:n}):e?c.jsx(e,{...o,lang:t,dir:r,children:n}):c.jsx("span",{...o,lang:t,dir:r,children:n})}function Lt(e,t,n){if(t.length===0)return;if(t.length===1)return t[0];if(t.indexOf(e)!==-1)return e;const r=e.indexOf("-")!==-1?e.slice(0,e.indexOf("-")):null;if(r&&t.indexOf(r)!==-1)return r;for(const o of n)if(t.indexOf(o)!==-1)return o;return t.indexOf("none")!==-1?"none":t.indexOf("@none")!==-1?"@none":t[0]}const kt=(e,t=[])=>{const n=ue();return u.useMemo(()=>{const r=e();return Lt(n,r,[])},[n,...t])};function Ot(e,t){const n=kt(()=>Object.keys(e||{}),[e]);return[u.useMemo(()=>{if(!e)return t||"";if(typeof e=="string")return e;const r=n?e[n]:void 0;return r?typeof r=="string"?r:r.join(`
28
+ `):""},[n,t,e]),n]}function Fn(){const e=ue();return function(n,r,o){const i=Object.keys(n||{}),s=Lt(e,i,[]);if(!n)return r||"";if(typeof n=="string")return n;const a=s?n[s]:void 0;return a?typeof a=="string"?a:a.join(typeof o<"u"?o:`
29
+ `):""}}const Ft=({as:e,defaultText:t,enableDangerouslySetInnerHTML:n,children:r,...o})=>{const[i,s]=Ot(r,t);return s?c.jsx(Vt,{...o,as:e,language:s,title:n?void 0:i,dangerouslySetInnerHTML:n?{__html:i}:void 0,children:n?void 0:i}):e?c.jsx(e,{...o,children:i}):c.jsx("span",{...o,title:n?void 0:i,dangerouslySetInnerHTML:n?{__html:i}:void 0,children:n?void 0:i})};function Nn({element:e,media:t,playPause:n}){const r=u.useRef(null);return t.youTubeId?c.jsxs("div",{className:"video-container",part:"video-container",onClick:n,children:[c.jsx("style",{children:`
94
30
  .video-container {
95
31
  position: absolute;
96
32
  top: 0;
@@ -108,5 +44,5 @@
108
44
  width: 100%;
109
45
  object-fit: contain;
110
46
  }
111
- `}),g.jsx("iframe",{className:"video-yt",ref:n,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 nc({media:t,mediaControlsDeps:e,children:r}){const[{element:n,currentTime:i,progress:s},a,o]=tt({duration:t.duration});return Ie("overlay","video-element",rc,{element:n,media:t,playPause:o.playPause}),null}function Si({x:t,y:e,onChoiceChange:r,registerActions:n,defaultChoices:i,isStatic:s,renderViewerControls:a,renderMediaControls:o,viewControlsDeps:u,mediaControlsDeps:d,strategies:l,throwOnUnknown:p,backgroundStyle:m,alwaysShowBackground:A,keepCanvasScale:h=!1,enableSizes:x=!1,enableYouTube:b=!0,onClickPaintingAnnotation:S,children:w}){const M=re(),T=$t(M,["deep-zoom"]),[F]=Kr(),k=Xr(),O=V(),E=y.useMemo(()=>Dt(O),[O]),[R,$]=ti({strategies:l||["images"],defaultChoices:i==null?void 0:i.map(({id:P})=>P)}),X=R.type==="images"?R.choice:void 0,Y=y.useMemo(()=>h?1:Math.max(1,...R.type==="images"?R.images.map(P=>{var N;return(P.width||0)/((N=P.target)==null?void 0:N.spatial.width)}):[]),[h,R]);ea(Y),y.useEffect(()=>{n&&n($)},[R.annotations]),y.useEffect(()=>{if(i)for(const P of i)typeof P.opacity<"u"&&E.applyStyles({id:P.id},"atlas",{opacity:P.opacity})},[i]),y.useLayoutEffect(()=>{r&&r(X)},[X]),Ie(k&&(R.type==="images"||R.type==="empty"||R.type==="textual-content"&&a)?"overlay":"none",`canvas-portal-controls-${M==null?void 0:M.id}`,Ze.Provider,a?{value:k||null,children:a(R)}:{},[M,k,R,...u||[]]);const _=ii({maxWidth:256,maxHeight:256});if(!M)return null;const H=M.accompanyingCanvas,J=_&&_.type==="fixed"?g.jsx("world-object",{height:M.height,width:M.width,x:t,y:e,children:g.jsx("world-image",{uri:_.id,target:{x:0,y:0,width:M.width,height:M.height},display:_.width&&_.height?{width:_.width,height:_.height}:void 0,crop:void 0})}):null;if(R.type==="unknown"){if(J)return J;if(p)throw new Error(R.reason||"Unknown image strategy");return null}const ee=g.jsxs(y.Fragment,{children:[F?g.jsx(Mt,{page:F}):null,R.annotations&&R.annotations.pages?R.annotations.pages.map(P=>g.jsx(Mt,{page:P},P.id)):null,w]}),ge=R.type==="images"?R.images.length:0;return g.jsxs(g.Fragment,{children:[g.jsxs("world-object",{height:M.height,width:M.width,x:t,y:e,...T,children:[R.type==="empty"||A?g.jsx(yi,{style:m}):null,R.type==="textual-content"?R.items.map((P,N)=>{var G;return g.jsxs(g.Fragment,{children:[g.jsx(Re.HTMLPortal,{onClick:S?ue=>{ue.stopPropagation(),S(P.annotationId,P,ue)}:void 0,target:((G=P.target)==null?void 0:G.spatial)||void 0,children:g.jsx("div",{"data-textual-content":!0,children:g.jsx(Ai,{enableDangerouslySetInnerHTML:!0,children:P.text})})},N),ee]})}):null,R.type==="images"?g.jsxs(g.Fragment,{children:[R.images.map((P,N)=>g.jsx(hn,{isStatic:s,image:P,id:P.id,thumbnail:N===0?_:void 0,selector:P.selector,enableSizes:x,onClick:S?G=>{G.stopPropagation(),S(P.annotationId,P,G)}:void 0},P.id+N)),ee]}):null,R.type==="3d-model"?g.jsx(hi,{model:R.model}):null,R.type==="media"?g.jsx(g.Fragment,{children:R.media.type==="Sound"?g.jsxs(li,{media:R.media,mediaControlsDeps:d,children:[J,o?o(R):null]}):R.media.type==="Video"?g.jsxs(pi,{media:R.media,mediaControlsDeps:d,children:[J,o?o(R):null]}):R.media.type==="VideoYouTube"&&b?g.jsxs(nc,{media:R.media,mediaControlsDeps:d,children:[J,o?o(R):null]}):null}):null]},`${M.id}/${R.type}/${ge}`),R.type==="media"&&R.media.type==="Sound"&&H?g.jsx(Ke,{canvas:H.id,children:g.jsx(Si,{renderViewerControls:a})}):null]})}function wi(){const t=y.useContext($e);return t&&t.vault?t.vault:$r()}const ic=y.forwardRef(function(e,r){const n=ye(),i=Et(),s=zr(),{ViewerControls:a,MediaControls:o}=e.components||{};if(y.useImperativeHandle(r,()=>s,[s]),!n)return g.jsx("div",{});let u=0;return g.jsxs(g.Fragment,{children:[e.header,g.jsx(Q.Viewer,{height:e.height,mode:e.mode,children:i.map((d,l)=>{const p=u;return u+=d.width+(e.spacing||0),g.jsx(Ke,{canvas:d.id,children:g.jsx(Q.RenderCanvas,{strategies:["3d-model","media","images","empty","textual-content"],renderViewerControls:l===0&&a?()=>g.jsx(a,{}):void 0,renderMediaControls:l===0&&o?()=>g.jsx(o,{}):void 0,x:p,...e.canvasProps||{},children:e.annotations},d.id)},d.id)})},e.reuseAtlas?"":s.currentSequenceIndex),e.children]})}),Q=y.forwardRef(function({children:e,height:r,annotations:n,canvasProps:i,spacing:s,header:a,components:o,mode:u,...d},l){const p=wi();return g.jsx(jt,{vault:p,children:g.jsx(Br,{...d,children:g.jsx(ic,{ref:l,height:r,components:o,spacing:s,canvasProps:i,annotations:n,header:a,mode:u,children:e})})})});Q.RenderImage=hn;Q.RenderCanvas=Si;Q.RenderAnnotationPage=Mt;Q.RenderAnnotation=pn;Q.Viewer=ta;Q.CanvasBackground=yi;Q.Audio=li;Q.Video=pi;Q.Model=hi;Q.AudioHTML=ui;Q.VideoHTML=fi;Q.ModelHTML=di;function sc({annotation:t,children:e}){return g.jsx(he,{value:{annotation:t},children:e})}function ac({annotationPage:t,children:e}){return g.jsx(he,{value:{annotationPage:t},children:e})}function oc({collection:t,children:e}){return g.jsx(he,{value:{collection:t},children:e})}function cc(t,e={}){return et(e)}function uc(t,e=!1){}function lc(t){const r=se().manifest,n=t?t.map(i=>typeof i=="string"?i:i==null?void 0:i.id):[];return U(i=>{const s=r?i.iiif.entities.Manifest[r]:void 0,a=(s==null?void 0:s.items)||[];if(typeof t>"u")return a;const o=[];for(const u of(s==null?void 0:s.items)||[])n.indexOf(u.id)!==-1&&o.push(u);return o},[n.join("/")])}function fc(t,e=[]){const{id:r,selector:n}=t,i=se(),s=r||i.collection,a=U(o=>s?o.iiif.entities.Collection[s]:void 0,[s]);return y.useMemo(()=>{if(a)return n?n(a):a},[a,n,...e])}function pc(t,e,r,n,i=[]){const s=V(),a=y.useMemo(()=>sn(s),[s]);y.useEffect(()=>{const o=t;return o?(a.addEventListener(o,e,r,n),()=>{a.removeEventListener(o,e,r)}):()=>{}},[a,t,e,...i])}function dc(t,e){const{id:r,isLoaded:n,error:i,resource:s,requestId:a,cached:o}=Pt(t,e);return{id:r,isLoaded:n,error:i,manifest:s,requestId:a,cached:o}}function Ci({cacheKey:t}={}){const e=re(),r=et(),n=V(),i=Xe(),[s,a]=y.useState(void 0),[o,u]=y.useState(!1),[d,l]=y.useState("idle"),[p,m]=y.useState(void 0),A=e?e.id:"undefined",h=y.useMemo(()=>{try{if(e&&r.length){const b=r[0],S=n.get(b.body[0]),M=Se.getImageServices(S)[0];return M&&i.loadServiceSync({id:M.id||M["@id"],width:M.width||e.width,height:M.height||e.height})||void 0}}catch(b){console.error(b)}},[A,t,e]),x=d==="success"&&s?s:h;return y.useEffect(()=>{(async()=>{try{if(e&&r.length){const b=r[0],S=n.get(b.body[0]),M=Se.getImageServices(S)[0];if(!M)return;u(!0),l("loading");try{const T=await i.loadService({id:M.id||M["@id"],width:M.width||e.width,height:M.height||e.height})||void 0;a(T),l("success"),u(!1)}catch(T){l("error"),m(T)}}}catch(b){l("error"),m(b)}})()},[A,t]),y.useMemo(()=>({data:x,isFetching:o,status:d,error:p}),[x,o,d,p])}function hc(){const t=Ci();return{isLoading:t.isFetching,tile:t.data?{id:t.data.id||t.data["@id"],width:t.data.width,height:t.data.height,imageService:t.data,thumbnail:void 0}:null}}function yc(){const t=ye();return t?t.service.find(e=>e.profile==="SearchService1"||e.profile==="http://iiif.io/api/search/1/search"):void 0}function vc(){const t=V();return y.useMemo(()=>Dt(t),[t])}exports.AnnotationContext=sc;exports.AnnotationPageContext=ac;exports.CanvasContext=Ke;exports.CanvasPanel=Q;exports.CollectionContext=oc;exports.ContextBridge=Qr;exports.ImageServiceLoaderContext=zn;exports.InnerViewerProvider=Nr;exports.LanguageProvider=ec;exports.LanguageString=gi;exports.LocaleString=Ai;exports.ManifestContext=qr;exports.MediaPlayerProvider=Bt;exports.RangeContext=Vr;exports.ReactVaultContext=$e;exports.ResourceProvider=he;exports.ResourceReactContext=Je;exports.SimpleViewerProvider=Br;exports.SimpleViewerReactContext=qe;exports.VaultProvider=jt;exports.ViewerPresetContext=Ze;exports.VirtualAnnotationProvider=Zr;exports.VisibleCanvasReactContext=De;exports.emptyActions=_n;exports.emptyStrategy=Un;exports.expandTarget=de;exports.findAllCanvasesInRange=Ot;exports.findFirstCanvasFromRange=_r;exports.findManifestSelectedRange=Ps;exports.findSelectedRange=Lt;exports.flattenAnnotationPageIds=Hn;exports.formatTime=si;exports.get3dStrategy=Gn;exports.getImageStrategy=Jn;exports.getManifestSequence=Ft;exports.getParsedTargetSelector=Nt;exports.getRenderingStrategy=ei;exports.getTextualContentStrategy=Zn;exports.getVideoStrategy=Xn;exports.getVisibleCanvasesFromCanvasId=Es;exports.isImageApiSelector=ln;exports.parseRotation=fn;exports.parseSelector=Ee;exports.parseSpecificResource=qo;exports.unknownResponse=Ge;exports.unsupportedStrategy=D;exports.useAnnotation=Vt;exports.useAnnotationPage=dn;exports.useAnnotationPageManager=Nn;exports.useAnnotationsAtTime=cc;exports.useCanvas=re;exports.useCanvasClock=uc;exports.useCanvasSequence=Hr;exports.useCanvasSubset=lc;exports.useClosestLanguage=xi;exports.useCollection=fc;exports.useContextBridge=Wr;exports.useCreateLocaleString=tc;exports.useDispatch=Yr;exports.useEventListener=pc;exports.useExistingVault=wi;exports.useExternalCollection=dc;exports.useExternalManifest=Dr;exports.useExternalResource=Pt;exports.useIIIFLanguage=rt;exports.useImageService=Ci;exports.useImageServiceLoader=Xe;exports.useImageTile=hc;exports.useLoadImageService=Wn;exports.useLocaleString=bi;exports.useManifest=ye;exports.useMediaActions=Zo;exports.useMediaElements=Xo;exports.useMediaState=Ko;exports.usePaintables=Yn;exports.usePaintingAnnotations=et;exports.useRange=Ur;exports.useRenderingStrategy=ti;exports.useResourceContext=se;exports.useResourceEvents=$t;exports.useResources=Bn;exports.useSearchService=yc;exports.useSimpleMediaPlayer=tt;exports.useSimpleViewer=zr;exports.useStyleHelper=vc;exports.useStyles=Fe;exports.useThumbnail=ii;exports.useVault=V;exports.useVaultEffect=ri;exports.useVaultSelector=U;exports.useViewerPreset=Xr;exports.useVirtualAnnotationPage=Gr;exports.useVirtualAnnotationPageContext=Kr;exports.useVisibleCanvases=Et;
47
+ `}),c.jsx("iframe",{className:"video-yt",ref:r,src:`https://www.youtube.com/embed/${t.youTubeId}?enablejsapi=1&origin=${window.location.host}`,referrerPolicy:"no-referrer",sandbox:"allow-scripts allow-same-origin allow-presentation"})]}):null}function Dn({media:e,mediaControlsDeps:t,children:n}){const[{element:r,currentTime:o,progress:i},s,a]=ae({duration:e.duration});return U("overlay","video-element",Nn,{element:r,media:e,playPause:a.playPause}),null}function Nt({x:e,y:t,onChoiceChange:n,registerActions:r,defaultChoices:o,isStatic:i,renderViewerControls:s,renderMediaControls:a,viewControlsDeps:l,mediaControlsDeps:f,strategies:d,throwOnUnknown:g,backgroundStyle:p,alwaysShowBackground:y,keepCanvasScale:m=!1,enableSizes:h=!1,enableYouTube:x=!0,onClickPaintingAnnotation:C,children:j}){const S=V(),L=Se(S,["deep-zoom"]),[Q]=Ye(),w=Ke(),I=M(),A=u.useMemo(()=>ge.createStylesHelper(I),[I]),[v,k]=pt({strategies:d||["images"],defaultChoices:o==null?void 0:o.map(({id:b})=>b)}),Pe=v.type==="images"?v.choice:void 0,_t=u.useMemo(()=>m?1:Math.max(1,...v.type==="images"?v.images.map(b=>{var q;return(b.width||0)/((q=b.target)==null?void 0:q.spatial.width)}):[]),[m,v]);xn(_t),u.useEffect(()=>{r&&r(k)},[v.annotations]),u.useEffect(()=>{if(o)for(const b of o)typeof b.opacity<"u"&&A.applyStyles({id:b.id},"atlas",{opacity:b.opacity})},[o]),u.useLayoutEffect(()=>{n&&n(Pe)},[Pe]),U(w&&(v.type==="images"||v.type==="empty"||v.type==="textual-content"&&s)?"overlay":"none",`canvas-portal-controls-${S==null?void 0:S.id}`,oe.Provider,s?{value:w||null,children:s(v)}:{},[S,w,v,...l||[]]);const F=xt({maxWidth:256,maxHeight:256});if(!S)return null;const Me=S.accompanyingCanvas,B=F&&F.type==="fixed"?c.jsx("world-object",{height:S.height,width:S.width,x:e,y:t,children:c.jsx("world-image",{uri:F.id,target:{x:0,y:0,width:S.width,height:S.height},display:F.width&&F.height?{width:F.width,height:F.height}:void 0,crop:void 0})}):null;if(v.type==="unknown"){if(B)return B;if(g)throw new Error(v.reason||"Unknown image strategy");return null}const je=c.jsxs(u.Fragment,{children:[Q?c.jsx(fe,{page:Q}):null,v.annotations&&v.annotations.pages?v.annotations.pages.map(b=>c.jsx(fe,{page:b},b.id)):null,j]}),Ut=v.type==="images"?v.images.length:0;return c.jsxs(c.Fragment,{children:[c.jsxs("world-object",{height:S.height,width:S.width,x:e,y:t,...L,children:[v.type==="empty"||y?c.jsx(At,{style:p}):null,v.type==="textual-content"?v.items.map((b,q)=>{var H;return c.jsxs(c.Fragment,{children:[c.jsx(_.HTMLPortal,{onClick:C?Ee=>{Ee.stopPropagation(),C(b.annotationId,b,Ee)}:void 0,target:((H=b.target)==null?void 0:H.spatial)||void 0,children:c.jsx("div",{"data-textual-content":!0,children:c.jsx(Ft,{enableDangerouslySetInnerHTML:!0,children:b.text})})},q),je]})}):null,v.type==="images"?c.jsxs(c.Fragment,{children:[v.images.map((b,q)=>c.jsx(tt,{isStatic:i,image:b,id:b.id,thumbnail:q===0?F:void 0,selector:b.selector,enableSizes:h,onClick:C?H=>{H.stopPropagation(),C(b.annotationId,b,H)}:void 0},b.id+q)),je]}):null,v.type==="3d-model"?c.jsx(Rt,{model:v.model}):null,v.type==="media"?c.jsx(c.Fragment,{children:v.media.type==="Sound"?c.jsxs(Mt,{media:v.media,mediaControlsDeps:f,children:[B,a?a(v):null]}):v.media.type==="Video"?c.jsxs(Et,{media:v.media,mediaControlsDeps:f,children:[B,a?a(v):null]}):v.media.type==="VideoYouTube"&&x?c.jsxs(Dn,{media:v.media,mediaControlsDeps:f,children:[B,a?a(v):null]}):null}):null]},`${S.id}/${v.type}/${Ut}`),v.type==="media"&&v.media.type==="Sound"&&Me?c.jsx(re,{canvas:Me.id,children:c.jsx(Nt,{renderViewerControls:s})}):null]})}function Dt(){const e=u.useContext(K);return e&&e.vault?e.vault:X.globalVault()}const qn=u.forwardRef(function(t,n){const r=D(),o=ve(),i=qe(),{ViewerControls:s,MediaControls:a}=t.components||{};if(u.useImperativeHandle(n,()=>i,[i]),!r)return c.jsx("div",{});let l=0;return c.jsxs(c.Fragment,{children:[t.header,c.jsx(R.Viewer,{height:t.height,mode:t.mode,children:o.map((f,d)=>{const g=l;return l+=f.width+(t.spacing||0),c.jsx(re,{canvas:f.id,children:c.jsx(R.RenderCanvas,{strategies:["3d-model","media","images","empty","textual-content"],renderViewerControls:d===0&&s?()=>c.jsx(s,{}):void 0,renderMediaControls:d===0&&a?()=>c.jsx(a,{}):void 0,x:g,...t.canvasProps||{},children:t.annotations},f.id)},f.id)})},t.reuseAtlas?"":i.currentSequenceIndex),t.children]})}),R=u.forwardRef(function({children:t,height:n,annotations:r,canvasProps:o,spacing:i,header:s,components:a,mode:l,...f},d){const g=Dt();return c.jsx(he,{vault:g,children:c.jsx(De,{...f,children:c.jsx(qn,{ref:d,height:n,components:a,spacing:i,canvasProps:o,annotations:r,header:s,mode:l,children:t})})})});R.RenderImage=tt;R.RenderCanvas=Nt;R.RenderAnnotationPage=fe;R.RenderAnnotation=Xe;R.Viewer=Sn;R.CanvasBackground=At;R.Audio=Mt;R.Video=Et;R.Model=Rt;R.AudioHTML=Pt;R.VideoHTML=jt;R.ModelHTML=It;function _n({annotation:e,children:t}){return c.jsx(N,{value:{annotation:e},children:t})}function Un({annotationPage:e,children:t}){return c.jsx(N,{value:{annotationPage:e},children:t})}function Bn({collection:e,children:t}){return c.jsx(N,{value:{collection:e},children:t})}function Hn(e,t={}){return se(t)}function $n(e,t=!1){}function Yn(e){const n=O().manifest,r=e?e.map(o=>typeof o=="string"?o:o==null?void 0:o.id):[];return E(o=>{const i=n?o.iiif.entities.Manifest[n]:void 0,s=(i==null?void 0:i.items)||[];if(typeof e>"u")return s;const a=[];for(const l of(i==null?void 0:i.items)||[])r.indexOf(l.id)!==-1&&a.push(l);return a},[r.join("/")])}function zn(e,t=[]){const{id:n,selector:r}=e,o=O(),i=n||o.collection,s=E(a=>i?a.iiif.entities.Collection[i]:void 0,[i]);return u.useMemo(()=>{if(s)return r?r(s):s},[s,r,...t])}function Kn(e,t,n,r,o=[]){const i=M(),s=u.useMemo(()=>Ze(i),[i]);u.useEffect(()=>{const a=e;return a?(s.addEventListener(a,t,n,r),()=>{s.removeEventListener(a,t,n)}):()=>{}},[s,e,t,...o])}function Wn(e,t){const{id:n,isLoaded:r,error:o,resource:i,requestId:s,cached:a}=me(e,t);return{id:n,isLoaded:r,error:o,manifest:i,requestId:s,cached:a}}function qt({cacheKey:e}={}){const t=V(),n=se(),r=M(),o=ie(),[i,s]=u.useState(void 0),[a,l]=u.useState(!1),[f,d]=u.useState("idle"),[g,p]=u.useState(void 0),y=t?t.id:"undefined",m=u.useMemo(()=>{try{if(t&&n.length){const x=n[0],C=r.get(x.body[0]),S=te.getImageServices(C)[0];return S&&o.loadServiceSync({id:S.id||S["@id"],width:S.width||t.width,height:S.height||t.height})||void 0}}catch(x){console.error(x)}},[y,e,t]),h=f==="success"&&i?i:m;return u.useEffect(()=>{(async()=>{try{if(t&&n.length){const x=n[0],C=r.get(x.body[0]),S=te.getImageServices(C)[0];if(!S)return;l(!0),d("loading");try{const L=await o.loadService({id:S.id||S["@id"],width:S.width||t.width,height:S.height||t.height})||void 0;s(L),d("success"),l(!1)}catch(L){d("error"),p(L)}}}catch(x){d("error"),p(x)}})()},[y,e]),u.useMemo(()=>({data:h,isFetching:a,status:f,error:g}),[h,a,f,g])}function Gn(){const e=qt();return{isLoading:e.isFetching,tile:e.data?{id:e.data.id||e.data["@id"],width:e.data.width,height:e.data.height,imageService:e.data,thumbnail:void 0}:null}}function Qn(){const e=D();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function Jn(){const e=M();return u.useMemo(()=>ge.createStylesHelper(e),[e])}exports.AnnotationContext=_n;exports.AnnotationPageContext=Un;exports.CanvasContext=re;exports.CanvasPanel=R;exports.CollectionContext=Bn;exports.ContextBridge=Ue;exports.ImageServiceLoaderContext=at;exports.InnerViewerProvider=Ne;exports.LanguageProvider=On;exports.LanguageString=Vt;exports.LocaleString=Ft;exports.ManifestContext=Ve;exports.MediaPlayerProvider=we;exports.RangeContext=Le;exports.ReactVaultContext=K;exports.ResourceProvider=N;exports.ResourceReactContext=ne;exports.SimpleViewerProvider=De;exports.SimpleViewerReactContext=G;exports.VaultProvider=he;exports.ViewerPresetContext=oe;exports.VirtualAnnotationProvider=ze;exports.VisibleCanvasReactContext=W;exports.emptyActions=nt;exports.emptyStrategy=rt;exports.findAllCanvasesInRange=pe;exports.findFirstCanvasFromRange=ke;exports.findManifestSelectedRange=Gt;exports.findSelectedRange=ye;exports.flattenAnnotationPageIds=ot;exports.formatTime=St;exports.get3dStrategy=dt;exports.getImageStrategy=ft;exports.getManifestSequence=xe;exports.getParsedTargetSelector=be;exports.getRenderingStrategy=vt;exports.getTextualContentStrategy=ht;exports.getVideoStrategy=mt;exports.getVisibleCanvasesFromCanvasId=Qt;exports.parseSpecificResource=Cn;exports.unknownResponse=ee;exports.unsupportedStrategy=P;exports.useAnnotation=Ce;exports.useAnnotationPage=et;exports.useAnnotationPageManager=it;exports.useAnnotationsAtTime=Hn;exports.useCanvas=V;exports.useCanvasClock=$n;exports.useCanvasSequence=Fe;exports.useCanvasSubset=Yn;exports.useClosestLanguage=kt;exports.useCollection=zn;exports.useContextBridge=_e;exports.useCreateLocaleString=Fn;exports.useDispatch=Be;exports.useEventListener=Kn;exports.useExistingVault=Dt;exports.useExternalCollection=Wn;exports.useExternalManifest=Te;exports.useExternalResource=me;exports.useIIIFLanguage=ue;exports.useImageService=qt;exports.useImageServiceLoader=ie;exports.useImageTile=Gn;exports.useLoadImageService=ut;exports.useLocaleString=Ot;exports.useManifest=D;exports.useMediaActions=Ln;exports.useMediaElements=kn;exports.useMediaState=Vn;exports.usePaintables=lt;exports.usePaintingAnnotations=se;exports.useRange=Oe;exports.useRenderingStrategy=pt;exports.useResourceContext=O;exports.useResourceEvents=Se;exports.useResources=st;exports.useSearchService=Qn;exports.useSimpleMediaPlayer=ae;exports.useSimpleViewer=qe;exports.useStyleHelper=Jn;exports.useStyles=z;exports.useThumbnail=xt;exports.useVault=M;exports.useVaultEffect=yt;exports.useVaultSelector=E;exports.useViewerPreset=Ke;exports.useVirtualAnnotationPage=He;exports.useVirtualAnnotationPageContext=Ye;exports.useVisibleCanvases=ve;Object.keys(Y).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:()=>Y[e]})});
112
48
  //# sourceMappingURL=index.js.map