react-iiif-vault 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -285,7 +285,7 @@ No matching component was found for:
285
285
  [zustand devtools middleware] Unsupported __setState action format.
286
286
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
287
287
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
288
- `);const O=D.state[p];if(O==null)return;JSON.stringify(a.getState())!==JSON.stringify(O)&&_(O);return}a.dispatchFromDevtools&&typeof a.dispatch=="function"&&a.dispatch(D)});case"DISPATCH":switch(k.payload.type){case"RESET":return _(M),p===void 0?m==null?void 0:m.init(a.getState()):m==null?void 0:m.init(Nd(g.name));case"COMMIT":if(p===void 0){m==null||m.init(a.getState());return}return m==null?void 0:m.init(Nd(g.name));case"ROLLBACK":return Iv(k.state,D=>{if(p===void 0){_(D),m==null||m.init(a.getState());return}_(D[p]),m==null||m.init(Nd(g.name))});case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return Iv(k.state,D=>{if(p===void 0){_(D);return}JSON.stringify(a.getState())!==JSON.stringify(D[p])&&_(D[p])});case"IMPORT_STATE":{const{nextLiftedState:D}=k.payload,O=(L=D.computedStates.slice(-1)[0])==null?void 0:L.state;if(!O)return;_(p===void 0?O:O[p]),m==null||m.send(null,D);return}case"PAUSE_RECORDING":return T=!T}return}}),M},A_=R_,Iv=(t,e)=>{let n;try{n=JSON.parse(t)}catch(i){console.error("[zustand devtools middleware] Could not parse the received json",i)}n!==void 0&&e(n)},M_=t=>(e,n,i)=>{const a=i.subscribe;return i.subscribe=(u,f,p)=>{let g=u;if(f){const S=(p==null?void 0:p.equalityFn)||Object.is;let m=u(i.getState());g=x=>{const T=u(x);if(!S(m,T)){const _=m;f(m=T,_)}},p!=null&&p.fireImmediately&&f(m,m)}return a(g)},t(e,n,i)},O_=M_,__=(t={},e)=>{switch(e.type){case TS:return{...t,[e.payload.id]:e.payload.type};case RS:return{...t,...e.payload.mapping};default:return t}};function Nv(t,e,n,i){return!(!t[n]||!t[n][e]||!t[n][e][i]||!Array.isArray(t[n][e][i]))}function L_(t,e){const n={},i=[];for(const[a,u]of Object.entries(t||{})){i.push(a);const f=(e||{})[a];if(!f||f.length===0){n[a]=u;continue}n[a]=f}for(const[a,u]of Object.entries(e||{}))i.indexOf(a)===-1&&(n[a]=u);return n}function Ge(t){return t.payload}function zv(t,e){return typeof t>"u"?e:t}const D_=(t=FS(),e)=>{var n;const i=(a,u)=>({...t,[Ge(e).type]:{...t[Ge(e).type],[Ge(e).id]:{...a,...u}}});switch(e.type){case gS:{if(!t[Ge(e).type]||!t[Ge(e).type][Ge(e).id])return t;const a=t[Ge(e).type][Ge(e).id];return typeof a=="string"?t:i(a,{[Ge(e).key]:Ge(e).value})}case yS:{if(!Nv(t,Ge(e).id,Ge(e).type,Ge(e).key))return t;const a=t[Ge(e).type][Ge(e).id];if(typeof a=="string")return t;const u=Array.from(a[Ge(e).key]),[f]=u.splice(Ge(e).startIndex,1);return u.splice(Ge(e).endIndex,0,f),i(a,{[Ge(e).key]:u})}case mS:{const a=Object.keys(Ge(e).entities),u={...t};for(const f of a){const p=Ge(e).entities[f],g={...t[f]||{}};let S=!1;const m=Object.keys(p||{})||[];if(p&&m){for(const x of m)S=!0,g[x]=t[f][x]?L_(t[f][x],p[x]):p[x];S&&(u[f]=g)}}return u}case SS:{if(!Nv(t,Ge(e).id,Ge(e).type,Ge(e).key))return t;const a=t[Ge(e).type][Ge(e).id],u=Array.from(a[Ge(e).key]);return u.splice(zv(Ge(e).index,u.length+1),0,Ge(e).reference),i(a,{[Ge(e).key]:u})}case Av:case bS:{if(!Nv(t,Ge(e).id,Ge(e).type,Ge(e).key))return t;const a=t[Ge(e).type][Ge(e).id],u=Array.from(a[Ge(e).key]),f=zv(Ge(e).index,u.findIndex(p=>p&&p.id===Ge(e).reference.id));return f===-1||((n=u[f])==null?void 0:n.id)!==Ge(e).reference.id?t:(e.type===Av?u.splice(f,1,Ge(e).reference):u.splice(f,1),i(a,{[Ge(e).key]:u}))}case ES:{const a=t[Ge(e).type][Ge(e).id];if(!a)return t;const u=Array.from(a.metadata||[]),f=Ge(e);return u.splice(zv(e.payload.beforeIndex,u.length+1),0,{label:f.label,value:f.label}),i(a,{metadata:u})}case wS:{const a=t[Ge(e).type][Ge(e).id];if(typeof a=="string"||!a)return t;const u=Array.from(a.metadata||[]),[f]=u.splice(Ge(e).startIndex,1);return u.splice(Ge(e).endIndex,0,f),i(a,{metadata:u})}case Mv:case xS:{const a=t[Ge(e).type][Ge(e).id],u=Array.from(a.metadata||[]),f=Ge(e).atIndex;return typeof f>"u"||f===-1||!u[f]?t:(e.type===Mv?u.splice(f,1,{label:Ge(e).label,value:Ge(e).value}):u.splice(f,1),i(a,{metadata:u}))}default:return t}},P_=(t={},e)=>{switch(e.type){case DS:case v_:return{...t,[e.payload.id]:{requestUri:e.payload.id,loadingState:LS,uriMismatch:!1,resourceUri:e.payload.id}};case kS: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 PS:return{...t,[e.payload.id]:{...t[e.payload.id]||{},loadingState:Ov,error:e.payload.message}};case IS:return{...t,[e.payload.id]:{...t[e.payload.id]||{},loadingState:_v,error:void 0}}}return t},k_=(t={},e)=>{const{id:n,updateValue:i,value:a,meta:u,key:f}=e&&e.payload||{};switch(e.type){case AS:return{...t,[n]:{...t[n]||{},[u]:{...t[n]?t[n][u]||{}:{},[f]:a}}};case MS:return{...t,[n]:{...t[n]||{},[u]:{...t[n]?t[n][u]||{}:{},[f]:t[n]&&t[n][u]?i(t[n][u][f]):i(void 0)}}};case OS:return t[n]&&t[n][u]&&t[n][u][f]?{...t,[n]:{...t[n]||{},[u]:{...t[n]?t[n][u]||{}:{},[f]:void 0}}}:t;default:return t}};function HS(t={}){const e=Object.keys(t);return function(n={},i){let a=!1;const u={};for(let f=0;f<e.length;f++){const p=e[f];u[p]=t[p](n[p],i),a=a||u[p]!==n[p]}return a?u:n}}function I_(t){return(e,n)=>n&&n.type===Lv?n.payload.actions.reduce(t,e):n&&n.type===S_?{...e,iiif:{...e.iiif,...n.payload.state}}:t(e,n)}const N_=HS({mapping:__,entities:D_,requests:P_,meta:k_});function z_(){return{iiif:{entities:FS(),meta:{},mapping:{},requests:{}}}}function U_(t={}){const{enableDevtools:e=!1,iiifStoreName:n="iiif",defaultState:i=z_(),customReducers:a={}}=t,u=I_(HS({[n]:N_,...a}));return x_(O_(A_(C_(u,i),{enabled:e})))}function j_(t){return{all:t=t||new Map,on:function(e,n){var i=t.get(e);i?i.push(n):t.set(e,[n])},off:function(e,n){var i=t.get(e);i&&(n?i.splice(i.indexOf(n)>>>0,1):t.set(e,[]))},emit:function(e,n){var i=t.get(e);i&&i.slice().map(function(a){a(n)}),(i=t.get("*"))&&i.slice().map(function(a){a(e,n)})}}}function Ci(t,e,n,i=!0){e[jl]=e[jl]||[],e[jl].push(t);const a=new Map;Object.defineProperty(e,t,{enumerable:i,get(){if(typeof e[uo][t]>"u")return;const u=e[uo][t];if(!u)return u;const f=n.get(e[uo][t],{parent:this.id?{id:this.id,type:this.type}:void 0});return a.has(f)||(a.clear(),a.set(f,fo(f,n))),a.get(f)},set(u){e[uo][t]!==u&&(this[co]?n.modifyEntityField({id:this.id,type:this.type},t,$S(u)):this[uo][t]=u)}})}const uo=Symbol.for("_refs_"),co=Symbol.for("_reactive_"),jl=Symbol.for("_defined_"),VS=Symbol.for("_parent_");function F_(t,e=!1,n){const i={id:"",type:"unknown",[jl]:[],[uo]:{},[VS]:n||null,[co]:null,is(a){return typeof a=="string"?this.id===a:a.id?a.id===this.id:!1},reactive(){if(!this[co])return this[co]=this.subscribe(()=>this.refresh(),!0),()=>{this.unreactive()}},refresh(){if(this.id){const a=this.unwrap();for(const u of Object.keys(a||{}))this[jl].includes(u)?this[uo][u]=a[u]:this[u]=a[u]}},unreactive(){this[co]&&(this[co](),this[co]=null)},unwrap(){if(!this.id)throw new Error("Invalid object");const a=this[VS];return t.get(this.id,{parent:a?{id:a,type:"unknown"}:void 0})},toPresentation3(){return t.toPresentation3(this.unwrap())},toPresentation2(){return t.toPresentation2(this.unwrap())},valueOf(){return this.unwrap()},toJSON(){const a=this;return{...a,items:a.items,annotations:a.annotations,structures:a.structures,seeAlso:a.seeAlso,service:a.service,services:a.services,rendering:a.rendering,partOf:a.partOf,start:a.start,supplementary:a.supplementary,homepage:a.homepage,thumbnail:a.thumbnail,placeholderCanvas:a.placeholderCanvas,accompanyingCanvas:a.accompanyingCanvas,provider:a.provider}},subscribe(a,u=!0){return t.subscribe(()=>this.id?t.get(this.id):null,a,u)}};return Ci("items",i,t),Ci("annotations",i,t),Ci("structures",i,t),Ci("seeAlso",i,t),Ci("rendering",i,t),Ci("partOf",i,t),Ci("start",i,t,!1),Ci("supplementary",i,t),Ci("homepage",i,t),Ci("thumbnail",i,t),Ci("placeholderCanvas",i,t,!1),Ci("accompanyingCanvas",i,t,!1),Ci("provider",i,t),Ci("body",i,t),Ci("logo",i,t),i}function B_(t){return!!t[jl]}function $S(t){return Array.isArray(t)?t.map(e=>$S(e)):!t||!t.type?t:{id:t.id,type:t.type}}function fo(t,e,n=!1,i){if(Array.isArray(t))return t.map(p=>fo(p,e,n));if(!t||!t.type||!t.id)return t;const a=F_(e,n),u=Object.create(a),f=Object.assign(u,t);return n&&f.reactive(),f}function WS(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 Uv=class{constructor(e,n){ga(this,"options"),ga(this,"store"),ga(this,"emitter"),ga(this,"isBatching",!1),ga(this,"batchQueue",[]),ga(this,"remoteFetcher"),ga(this,"staticFetcher"),ga(this,"defaultFetcher",i=>fetch(i).then(a=>a.json())),this.options=Object.assign({reducers:{},customFetcher:this.defaultFetcher,enableDevtools:!0},e||{}),this.store=n||U_({customReducers:this.options.reducers,defaultState:this.options.defaultState,enableDevtools:this.options.enableDevtools}),this.emitter=j_(),this.remoteFetcher=jS(this,this.options.customFetcher),this.staticFetcher=jS(this,(i,a)=>a)}batch(e){this.isBatching=!0;try{e(this),this.isBatching=!1,this.dispatch(Dv({actions:this.batchQueue}))}catch(n){throw this.batchQueue=[],this.isBatching=!1,n}this.batchQueue=[]}async asyncBatch(e){this.isBatching=!0;try{await e(this),this.isBatching=!1,this.dispatch(Dv({actions:this.batchQueue}))}catch(n){throw this.batchQueue=[],this.isBatching=!1,n}this.batchQueue=[]}modifyEntityField(e,n,i){this.dispatch(u_.modifyEntityField({id:e.id,type:e.type,key:n,value:i}))}dispatch(e){if(this.isBatching)this.batchQueue.push(e);else{if(e.type===Lv){for(const a of e.payload.actions)this.emitter.emit(a.type,{action:a,state:this.store.getState()});this.store.dispatch(e);const i=this.getState();for(const a of e.payload.actions)this.emitter.emit(`after:${a.type}`,{action:a,state:i});return}this.emitter.emit(e.type,{action:e,state:this.store.getState()}),this.store.dispatch(e);const n=this.store.getState();this.emitter.emit(`after:${e.type}`,{action:e,state:n});return}}on(e,n){return this.emitter.on(e,n),()=>{this.emitter.off(e,n)}}serialize(e,n){return $O(this.getState().iiif,e,n)}toPresentation2(e){return this.serialize(e,GO)}toPresentation3(e){return this.serialize(e,XO)}hydrate(e,n,i={}){return this.get(e,n,{...i,skipSelfReturn:!1})}get(e,n,i={}){typeof n!="string"&&(i=n||{},n=void 0);const{skipSelfReturn:a=!0}=i||{};let u=i.parent?typeof i.parent=="string"?i.parent:i.parent.id:void 0;if(Array.isArray(e))return e.map(x=>this.get(x,i));const f=this.getState();if(da(e)&&!i.preserveSpecificResources&&(e=e.source),typeof e=="string"){const x=WS(n||f.iiif.mapping[e]);if(!x)return a?null:{id:e,type:"unknown"};e={id:e,type:x}}if(e&&e.partOf&&!u&&!i.skipPartOfCheck){const x=Array.isArray(e.partOf)?e.partOf[0]:e.partOf;x&&(typeof x=="string"&&(u=x),typeof x.id=="string"&&(u=x.id))}const p=WS(n||(e==null?void 0:e.type)),g=e==null?void 0:e.id,S=f.iiif.entities[p];if(!S){const x=f.iiif.requests[g];return x&&x.resourceUri!==g?this.get(x.resourceUri,i):a?null:e}const m=S[e.id];if(m&&m[zn]){const x=m[zn].find(T=>u?T[Kr]===u:T[Kr]===m.id);return vv(m,x)}return S[e.id]||(a?null:e)}select(e){return e(this.getState())}getStore(){return this.store}getState(){return this.store.getState()}deep(e,n){if(typeof e>"u")return this.get(n,{skipSelfReturn:!1});if(typeof e=="function")try{const a=e(this.get(n,{skipSelfReturn:!1})),u=f=>this.deep(f,a);return u.size=Array.isArray(a)?a.length:1,u}catch{const a=u=>this.deep(u,void 0);return a.size=0,a}const i=a=>this.deep(a,e);return i.size=Array.isArray(e)?e.length:1,i}loadManifest(e,n){const i=typeof e=="string"?e:e.id;return this.load(i,n)}loadCollection(e,n){const i=typeof e=="string"?e:e.id;return this.load(i,n)}load(e,n){const i=typeof e=="string"?e:e.id;return n?this.staticFetcher(i,n):this.remoteFetcher(i)}areInputsEqual(e,n){return US(e,n)}subscribe(e,n,i){return typeof i>"u"&&(typeof n>"u"||n===!1||n===!0)&&(i=n,n=e,e=a=>a),this.store.subscribe(e,a=>n(a,this),{equalityFn:US,fireImmediately:!i})}async ensureLoaded(e){const n=typeof e=="string"?e:e.id;this.requestStatus(n)||await this.load(n)}requestStatus(e){return this.select(n=>n.iiif.requests[e])}getResourceMeta(e,n){const i=this.getState().iiif.meta[e];if(i)return n?i[n]:i}getObject(e,n,i={}){const{reactive:a,...u}=i;return fo(this.get(e,n,u),this,a)}async loadObject(e,n){return fo(await this.load(e,n),this)}async loadManifestObject(e,n){return fo(await this.loadManifest(e,n),this)}async loadCollectionObject(e,n){return fo(await this.loadCollection(e,n),this)}wrapObject(e){return fo(this.get(e,{skipSelfReturn:!1}),this)}isWrapped(e){return B_(e)}setMetaValue([e,n,i],a){this.dispatch(typeof a=="function"?_S.setMetaValueDynamic({id:e,meta:n,key:i,updateValue:a}):_S.setMetaValue({id:e,meta:n,key:i,value:a}))}};function H_(){return typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{}}function qS(t){const e=H_();try{const i=e.IIIF_VAULT;if(i)return i}catch{}const n=new Uv(t);try{e.IIIF_VAULT=n}catch{}return n}const bc=R.createContext({vault:null,setVaultInstance:t=>{}});function jv({vault:t,vaultOptions:e,useGlobal:n,resources:i,children:a}){const[u,f]=R.useState(()=>t||(n?qS(e):e?new Uv(e):new Uv));return oe.jsx(bc.Provider,{value:{vault:u,setVaultInstance:f},children:oe.jsx(ca,{value:i||{},children:a})})}const Un=()=>{const{vault:t}=R.useContext(bc);if(t===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return t};function Fv(t,{noCache:e=!1}={}){const n=typeof t=="string"?t:t.id,i=Un(),[a,u]=R.useState(n),[f,p]=R.useState(void 0),g=R.useMemo(()=>i.get(n,{skipSelfReturn:!0})||void 0,[n,i]),[S,m]=R.useState(g);return R.useEffect(()=>{(async()=>{try{const x=g&&!e?g:await i.load(n),T=x?x.id||x["@id"]:null;x&&a!==T&&u(T),m(x)}catch(x){p(x)}})()},[n,e]),{isLoaded:!!S,id:a,requestId:n,error:f,resource:S,cached:!!(S&&S===g)}}function YS(t,e){const{id:n,isLoaded:i,error:a,resource:u,requestId:f,cached:p}=Fv(t,e);return{id:n,isLoaded:i,error:a,manifest:u,requestId:f,cached:p}}function QS({manifest:t,children:e}){return oe.jsx(ca,{value:{manifest:t},children:e})}function zd({canvas:t,children:e}){return oe.jsx(ca,{value:{canvas:t},children:e})}function ni(t,e=[]){const n=Un(),[i,a]=R.useState(()=>t(n.getState(),n));return R.useEffect(()=>n.subscribe(u=>t(u,n),u=>{a(u)},!1),e),i}const Ec=R.createContext([]);function Bv(){const t=R.useContext(Ec);return ni(e=>t.map(n=>e.iiif.entities.Canvas[n]).filter(Boolean),[t])}function ya(t={},e=[]){const{id:n,selector:i}=t,a=As();Un();const u=n||a.manifest,f=ni(p=>u?p.iiif.entities.Manifest[u]:void 0,[u]);return R.useMemo(()=>{if(f)return i?i(f):f},[f,i,...e])}function GS({range:t,children:e}){return oe.jsx(ca,{value:{range:t},children:e})}function XS(t,e){for(const n of e.items){if(n.type==="Canvas")return n;if(n.type==="SpecificResource")return n.source;if(n.type==="Range"){const i=XS(t,t.get(n));if(i)return i}}return null}function Hv(t,e){var i;const n=[];for(const a of e.items)if(a.type==="SpecificResource"&&((i=a.source)==null?void 0:i.type)==="Canvas"&&(a.source.id.indexOf("#")!==-1?n.push({id:a.source.id.split("#")[0],type:"Canvas"}):n.push(a.source)),a.type==="Range"&&n.push(...Hv(t,t.get(a))),a.type==="SpecificResource"){const u=typeof a.source=="string"?a.source:a.source.id;n.push({id:u,type:"Canvas"})}return n}function V_(t,e,n){for(const i of e.structures){const a=Vv(t,t.get(i),n);if(a)return a}return null}function Vv(t,e,n){var i,a,u;for(const f of e.items){const p=(a=(i=f==null?void 0:f.source)==null?void 0:i.id)==null?void 0:a.split("#")[0];if(f.type==="SpecificResource"&&f.source===n||f.type==="SpecificResource"&&((u=f.source)==null?void 0:u.type)==="Canvas"&&n===p)return e;if(f.type==="Range"){const g=Vv(t,t.get(f),n);if(g)return g}}return null}function $_(t,e,n,i=!1){const a=e.behavior,u=n?t.get(n):null;if(!u)return[];const f=u.behavior,p=i?!1:a.includes("paged"),g=p?!1:a.includes("continuous"),S=p||g?!1:a.includes("individuals"),m=f.includes("facing-pages"),x=f.includes("non-paged");if(m||x||S||i)return[{id:u.id,type:"Canvas"}];const[T,_]=$v(t,e);if(g)return T;const M=T.findIndex(k=>k.id===n);if(M===-1)return[];for(const k of _)if(k.includes(M))return k.map(L=>T[L]);return[{id:u.id,type:"Canvas"}]}function $v(t,e,{disablePaging:n,skipNonPaged:i}={}){const a=e.behavior,u=a.includes("paged"),f=u?!1:a.includes("continuous"),p=u||f?!1:a.includes("individuals"),g=e.type==="Manifest"?e.items:Hv(t,e);if(f)return[g,[g.map((M,k)=>k)]];if(p||!u||n)return[g,g.map((M,k)=>[k])];const S=[];let m=[];const x=()=>{m.length&&(S.push([...m]),m=[])};let T=0,_=!1;for(let M=0;M<g.length;M++){const k=t.get(g[M]);if(k.behavior.includes("non-paged")){M===T&&T++,i||(x(),S.push([M]),x());continue}if(M===T||k.behavior.includes("facing-pages")){m.length&&(_=!0),x(),S.push([M]),x();continue}if(m.push(M),_){x(),_=!1;continue}m.length>1&&x()}return m.length&&x(),[g,S]}function KS(t={},e=[]){const{id:n,selector:i}=t,a=As(),u=n||a.range,f=ni(p=>u?p.iiif.entities.Range[u]:void 0,[u]);return R.useMemo(()=>{if(f)return i?i(f):f},[f,i,...e])}function ZS({startCanvas:t,disablePaging:e}){var M;const n=Un(),i=ya(),a=KS(),[u,f]=R.useState(void 0),p=a||i;if(!p)throw new Error("Nothing selected");const[g,S]=R.useMemo(()=>$v(n,p,{disablePaging:e}),[n,p]),m=R.useCallback(k=>{const L=S.findIndex(D=>D.includes(k));f(L===-1?0:L)},[g,S]),x=R.useCallback(k=>{const L=g.findIndex(D=>D.id===k);L!==-1?m(L):f(0)},[g,S]),T=R.useCallback(()=>{f(k=>k>=S.length?k:k+1)},[S]),_=R.useCallback(()=>{f(k=>k<=0?0:k-1)},[S]);return typeof u>"u"&&(t?x(t):f(0)),{visibleItems:((M=S[u])==null?void 0:M.map(k=>g[k].id))||[],cursor:u,items:g,sequence:S,setSequenceIndex:f,setCanvasIndex:m,setCanvasId:x,next:T,previous:_}}const xc=()=>{},wc=R.createContext({setCurrentCanvasId:xc,setCurrentCanvasIndex:xc,nextCanvas:xc,previousCanvas:xc,items:[],sequence:[],setSequenceIndex:xc,currentSequenceIndex:0});function JS(t){const e=ya(),{cursor:n,visibleItems:i,next:a,sequence:u,items:f,setCanvasIndex:p,setCanvasId:g,previous:S,setSequenceIndex:m}=ZS({startCanvas:t.startCanvas,disablePaging:t.pagingEnabled===!1}),x=R.useMemo(()=>({sequence:u,items:f,setCurrentCanvasId:g,nextCanvas:a,previousCanvas:S,totalCanvases:f.length,setCurrentCanvasIndex:p,setSequenceIndex:m,currentSequenceIndex:n}),[u,f,g,a,S,f,p,m,n]);return e?oe.jsx(wc.Provider,{value:x,children:oe.jsx(Ec.Provider,{value:i,children:oe.jsx(zd,{canvas:i[0],children:t.children})})}):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),oe.jsx("div",{children:"Sorry, something went wrong."}))}function eb(t){const e=YS(t.manifest);if(!e)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),oe.jsx("div",{children:"Sorry, something went wrong."});if(e.error)return oe.jsx("div",{children:e.error.toString()});if(!e.isLoaded)return oe.jsx("div",{children:"Loading..."});const n=oe.jsx(JS,{...t,children:t.children});return oe.jsx(QS,{manifest:e.id,children:t.rangeId?oe.jsx(GS,{range:t.rangeId,children:n}):n})}function tb(){return R.useContext(wc)}function nb(){return{VaultContext:R.useContext(bc),ResourceContext:R.useContext(kd),SimpleViewerReactContext:R.useContext(wc),VisibleCanvasReactContext:R.useContext(Ec)}}function ib(t){return oe.jsx(jv,{vault:t.bridge.VaultContext.vault||void 0,resources:t.bridge.ResourceContext,children:oe.jsx(Ec.Provider,{value:t.bridge.VisibleCanvasReactContext,children:oe.jsx(wc.Provider,{value:t.bridge.SimpleViewerReactContext,children:t.children})})})}const Zr=function(t){return function(){const e={type:t,getType:()=>t,toString:()=>t};return(n,i)=>({...e,...n!==void 0&&{payload:n},...i!==void 0&&{meta:i}})}},W_="@iiif/IMPORT_ENTITIES",q_="@iiif/MODIFY_ENTITY_FIELD",Y_="@iiif/REORDER_ENTITY_FIELD",Q_="@iiif/ADD_REFERENCE",G_="@iiif/UPDATE_REFERENCE",X_="@iiif/REMOVE_REFERENCE",K_="@iiif/ADD_METADATA",Z_="@iiif/REMOVE_METADATA",J_="@iiif/UPDATE_METADATA",eL="@iiif/REORDER_METADATA",tL=Zr(W_)(),nL=Zr(q_)(),iL=Zr(Y_)(),rL=Zr(Q_)(),sL=Zr(X_)(),aL=Zr(G_)(),oL=Zr(K_)(),lL=Zr(J_)(),uL=Zr(Z_)(),cL=Zr(eL)(),Wv={importEntities:tL,modifyEntityField:nL,reorderEntityField:iL,addReference:rL,removeReference:sL,updateReference:aL,addMetadata:oL,removeMetadata:uL,updateMetadata:lL,reorderMetadata:cL};function rb(){const e=Un().getStore();return R.useMemo(()=>n=>e.dispatch(n),[e])}function sb(t){return typeof t!="string"&&t&&t.bindToVault}function ab(){const t=Un(),e=R.useRef([]),n=rb(),i=R.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);R.useLayoutEffect(()=>{const p={id:i,type:"AnnotationPage",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],rendering:[],service:[]};n(Wv.importEntities({entities:{AnnotationPage:{[p.id]:p}}}))},[i]);const a=ni(p=>i?p.iiif.entities.AnnotationPage[i]:null,[i]),u=R.useCallback((p,g)=>{if(i){if(sb(p)){const x=p;x.__vault||x.bindToVault(t),p=typeof x.source=="string"?x.source:x.source.id,e.current[p]=x}else typeof p!="string"&&(p=p.id);const S=t.get({id:i,type:"AnnotationPage"}),m=t.get({id:p,type:"Annotation"});S&&m&&(S.items.find(x=>x.id===m.id)||n(Wv.addReference({id:i,type:"AnnotationPage",key:"items",reference:{id:p,type:"Annotation"},index:g})))}},[i]),f=R.useCallback(p=>{i&&(sb(p)?p=typeof p.source=="string"?p.source:p.source.id:typeof p!="string"&&(p=p.id),e.current[p]&&e.current[p].beforeRemove(),t.get({id:i,type:"AnnotationPage"})&&n(Wv.removeReference({id:i,type:"AnnotationPage",key:"items",reference:{id:p,type:"Annotation"}})))},[i]);return[a,{addAnnotation:u,removeAnnotation:f}]}const ob=R.createContext(null);function lb(){const t=R.useContext(ob);return[t.fullPage,{addAnnotation:t.addAnnotation,removeAnnotation:t.removeAnnotation}]}function ub({children:t}){const[e,{addAnnotation:n,removeAnnotation:i}]=ab();return oe.jsx(ob.Provider,{value:R.useMemo(()=>({fullPage:e,addAnnotation:n,removeAnnotation:i}),[e]),children:t})}function fL({width:t,style:e,height:n,error:i,resetErrorBoundary:a}){return oe.jsxs("div",{style:{width:t,height:n,minHeight:500,...e||{},background:"#f9f9f9"},children:[oe.jsx("h3",{children:"Error occurred"}),oe.jsx("p",{children:i.message}),oe.jsx("button",{onClick:a,children:"Reset"})]})}const Ud=R.createContext(null);function cb(){return R.useContext(Ud)}const fb=R.createContext(()=>{}),db=R.createContext(()=>{});function Fl(t,e,n,i,a=[]){const u=R.useContext(t==="portal"?db:fb);R.useEffect(()=>(t!=="none"&&u(e,n,i),()=>{u(e,null)}),[e,t,u,...a])}function Jr(t={},e=[]){const{id:n,selector:i}=t,a=As(),u=n||a.canvas,f=ni(p=>u?p.iiif.entities.Canvas[u]:void 0,[u]);return R.useMemo(()=>{if(f)return i?i(f):f},[f,i,...e])}const hb=R.createContext(()=>{});function dL(t){const e=Jr(),n=R.useContext(hb);R.useEffect(()=>e&&e.id?(n(e.id,t),()=>n(e.id,-1)):()=>{},[e,t])}function hL({children:t,errorFallback:e,outerContainerProps:n={},worldScale:i,...a}){const[u,f]=R.useState(),p=nb(),g=e||fL,[S,m]=R.useState({}),x=Object.entries(S),[T,_]=R.useState({}),M=Object.entries(T),[k,L]=R.useState({}),D=R.useMemo(()=>i||Math.max(...Object.values(k)),[k]),O=R.useMemo(()=>({maxOverZoom:D||1}),[D]),j=R.useCallback((H,Z)=>{L(ie=>{if(Z===-1){const{[H]:W,...re}=ie;return re}return{...ie,[H]:Z}})},[]),q=R.useCallback((H,Z,ie)=>{m(({[H]:W,...re})=>Z?{...re,[H]:{element:Z,props:ie}}:re)},[]),ee=R.useCallback((H,Z,ie)=>{_(({[H]:W,...re})=>Z?{...re,[H]:{element:Z,props:ie}}:re)},[]);return oe.jsxs(IM,{resetKeys:[],fallbackRender:H=>oe.jsx(g,{...a,...H}),children:[oe.jsx(wM,{...a,containerProps:{style:{position:"relative"},...a.containerProps||{}},htmlChildren:oe.jsx(oe.Fragment,{children:x.map(([H,{element:Z,props:ie}])=>oe.jsx(R.Fragment,{children:oe.jsx(Z,{...ie||{}})},H))}),onCreated:H=>{f(H),a.onCreated&&a.onCreated(H)},runtimeOptions:O,children:oe.jsx(Ud.Provider,{value:u,children:oe.jsx(hb.Provider,{value:j,children:oe.jsx(fb.Provider,{value:q,children:oe.jsx(db.Provider,{value:ee,children:oe.jsx(ib,{bridge:p,children:oe.jsx(Od.Provider,{value:a.mode||"explore",children:oe.jsx(ub,{children:t})})})})})})})}),oe.jsx("div",{children:M.map(([H,{element:Z,props:ie}])=>oe.jsx(R.Fragment,{children:oe.jsx(Z,{...ie||{}})},H))})]})}const jd={},pb={get(t){return t},setMetaValue([t,e,n],i){const a=pb.getResourceMeta(t,e),u=a?a[n]:void 0,f=typeof i=="function"?i(u):i;jd[t]={...jd[t]||{},[e]:{...(jd[t]||{})[e]||{},[n]:f}}},getResourceMeta:(t,e)=>{const n=jd[t];if(n)return e?n[e]:n}};function vb(t=pb){return{addEventListener(e,n,i,a){if(e)return t.setMetaValue([e.id,"eventManager",n],u=>{const f=u||[];for(const p of f)if(p.callback===i)return f;return[...f,{callback:i,scope:a}]}),i},removeEventListener(e,n,i){e&&t.setMetaValue([e.id,"eventManager",n],a=>(a||[]).filter(u=>u.callback!==i))},getListenersAsProps(e,n){const i=typeof e=="string"?{id:e}:e;if(!i||!i.id)return{};const a=t.getResourceMeta(i.id,"eventManager"),u={};if(a&&i)for(const f of Object.keys(a))u[f]=p=>{const g=t.get(i);for(const{callback:S,scope:m}of a[f]||[])(!m||n&&m.indexOf(n)!==-1)&&S(p,g)};return u}}}function qv(t,e){const n=Un(),i=R.useMemo(()=>vb(n),[n]),a=ni(()=>t&&t.id?n.getResourceMeta(t.id,"eventManager"):null,[t]);return R.useMemo(()=>t?i.getListenersAsProps(t,e):{},[a,t,n,e])}const Fd={},mb={get(t){return t},setMetaValue([t,e,n],i){const a=mb.getResourceMeta(t,e),u=a?a[n]:void 0,f=typeof i=="function"?i(u):i;Fd[t]={...Fd[t]||{},[e]:{...(Fd[t]||{})[e]||{},[n]:f}}},getResourceMeta:(t,e)=>{const n=Fd[t];if(n)return e?n[e]:n}};function Yv(t=mb){return{applyStyles(e,n,i){const a=typeof e=="string"?e:e.id;return t.setMetaValue([a,"styles",n],i)},getAppliedStyles(e){const n=typeof e=="string"?e:e.id;return t.getResourceMeta(n,"styles")}}}function Cc(t,e){const n=Un(),i=R.useMemo(()=>Yv(n),[n]);return ni(()=>{if(!t)return null;const a=i.getAppliedStyles(t.id);return a?e?a[e]:a:void 0},[t,e])}var pL=Object.defineProperty,vL=(t,e,n)=>e in t?pL(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Bd=(t,e,n)=>(vL(t,typeof e!="symbol"?e+"":e,n),n),mL=function(){function t(e,n){var i=[],a=!0,u=!1,f=void 0;try{for(var p=e[Symbol.iterator](),g;!(a=(g=p.next()).done)&&(i.push(g.value),!(n&&i.length===n));a=!0);}catch(S){u=!0,f=S}finally{try{!a&&p.return&&p.return()}finally{if(u)throw f}}return i}return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),Tc=Math.PI*2,Qv=function(t,e,n,i,a,u,f){var p=t.x,g=t.y;p*=e,g*=n;var S=i*p-a*g,m=a*p+i*g;return{x:S+u,y:m+f}},gL=function(t,e){var n=e===1.5707963267948966?.551915024494:e===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(e/4),i=Math.cos(t),a=Math.sin(t),u=Math.cos(t+e),f=Math.sin(t+e);return[{x:i-a*n,y:a+i*n},{x:u+f*n,y:f-u*n},{x:u,y:f}]},gb=function(t,e,n,i){var a=t*i-e*n<0?-1:1,u=t*n+e*i;return u>1&&(u=1),u<-1&&(u=-1),a*Math.acos(u)},yL=function(t,e,n,i,a,u,f,p,g,S,m,x){var T=Math.pow(a,2),_=Math.pow(u,2),M=Math.pow(m,2),k=Math.pow(x,2),L=T*_-T*k-_*M;L<0&&(L=0),L/=T*k+_*M,L=Math.sqrt(L)*(f===p?-1:1);var D=L*a/u*x,O=L*-u/a*m,j=S*D-g*O+(t+n)/2,q=g*D+S*O+(e+i)/2,ee=(m-D)/a,H=(x-O)/u,Z=(-m-D)/a,ie=(-x-O)/u,W=gb(1,0,ee,H),re=gb(ee,H,Z,ie);return p===0&&re>0&&(re-=Tc),p===1&&re<0&&(re+=Tc),[j,q,W,re]},SL=function(t){var e=t.px,n=t.py,i=t.cx,a=t.cy,u=t.rx,f=t.ry,p=t.xAxisRotation,g=p===void 0?0:p,S=t.largeArcFlag,m=S===void 0?0:S,x=t.sweepFlag,T=x===void 0?0:x,_=[];if(u===0||f===0)return[];var M=Math.sin(g*Tc/360),k=Math.cos(g*Tc/360),L=k*(e-i)/2+M*(n-a)/2,D=-M*(e-i)/2+k*(n-a)/2;if(L===0&&D===0)return[];u=Math.abs(u),f=Math.abs(f);var O=Math.pow(L,2)/Math.pow(u,2)+Math.pow(D,2)/Math.pow(f,2);O>1&&(u*=Math.sqrt(O),f*=Math.sqrt(O));var j=yL(e,n,i,a,u,f,m,T,M,k,L,D),q=mL(j,4),ee=q[0],H=q[1],Z=q[2],ie=q[3],W=Math.abs(ie)/(Tc/4);Math.abs(1-W)<1e-7&&(W=1);var re=Math.max(Math.ceil(W),1);ie/=re;for(var ge=0;ge<re;ge++)_.push(gL(Z,ie)),Z+=ie;return _.map(function(be){var Ee=Qv(be[0],u,f,k,M,ee,H),Ue=Ee.x,je=Ee.y,Xe=Qv(be[1],u,f,k,M,ee,H),ce=Xe.x,me=Xe.y,tt=Qv(be[2],u,f,k,M,ee,H),mt=tt.x,he=tt.y;return{x1:Ue,y1:je,x2:ce,y2:me,x:mt,y:he}})};function yb(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var bL=xL,Gv={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},EL=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function xL(t){var e=[];return t.replace(EL,function(n,i,a){var u=i.toLowerCase();for(a=CL(a),u=="m"&&a.length>2&&(e.push([i].concat(a.splice(0,2))),u="l",i=i=="m"?"l":"L");;){if(a.length==Gv[u])return a.unshift(i),e.push(a);if(a.length<Gv[u])throw new Error("malformed path data");e.push([i].concat(a.splice(0,Gv[u])))}}),e}var wL=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function CL(t){var e=t.match(wL);return e?e.map(Number):[]}const TL=yb(bL);var RL=AL;function AL(t){var e=0,n=0,i=0,a=0;return t.map(function(u){u=u.slice();var f=u[0],p=f.toUpperCase();if(f!=p)switch(u[0]=p,f){case"a":u[6]+=i,u[7]+=a;break;case"v":u[1]+=a;break;case"h":u[1]+=i;break;default:for(var g=1;g<u.length;)u[g++]+=i,u[g++]+=a}switch(p){case"Z":i=e,a=n;break;case"H":i=u[1];break;case"V":a=u[1];break;case"M":i=e=u[1],a=n=u[2];break;default:i=u[u.length-2],a=u[u.length-1]}return u})}const ML=yb(RL);function OL(t){const e=TL(t),n=ML(e);let i,a=0,u=0,f=0,p=0,g,S,m=0,x=0;const T=[];for(let _=0;_<n.length;_++){let M=n[_];const k=M[0];switch(k){case"M":a=M[1],u=M[2];break;case"H":M=["L",M[1],u];break;case"V":M=["L",a,M[1]];break;case"S":{let L=m,D=x;(i==="C"||i=="S")&&(L+=L-f,D+=D-p),M=["C",L,D,M[1],M[2],M[3],M[4]]}break;case"T":i==="Q"||i=="T"?(g=m*2-g,S=x*2-S):(g=m,S=x),M=["Q",g,S,M[1],M[2]];break;case"Q":g=M[1],S=M[2];break;case"A":{const L=SL({px:m,py:x,cx:M[6],cy:M[7],rx:M[1],ry:M[2],xAxisRotation:M[3],largeArcFlag:M[4],sweepFlag:M[5]});if(!L.length)continue;for(const[D,O]of L.entries())M=["C",O.x1,O.y1,O.x2,O.y2,O.x,O.y],D<L.length-1&&T.push(M);M=M}break;case"Z":M=["L",a,u];break}i=k,m=M[M.length-2],x=M[M.length-1],["C","Q","A"].indexOf(k)>-1?(f=M[M.length-4],p=M[M.length-3]):(f=m,p=x),T.push(M)}return T}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
288
+ `);const O=D.state[p];if(O==null)return;JSON.stringify(a.getState())!==JSON.stringify(O)&&_(O);return}a.dispatchFromDevtools&&typeof a.dispatch=="function"&&a.dispatch(D)});case"DISPATCH":switch(k.payload.type){case"RESET":return _(M),p===void 0?m==null?void 0:m.init(a.getState()):m==null?void 0:m.init(Nd(g.name));case"COMMIT":if(p===void 0){m==null||m.init(a.getState());return}return m==null?void 0:m.init(Nd(g.name));case"ROLLBACK":return Iv(k.state,D=>{if(p===void 0){_(D),m==null||m.init(a.getState());return}_(D[p]),m==null||m.init(Nd(g.name))});case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return Iv(k.state,D=>{if(p===void 0){_(D);return}JSON.stringify(a.getState())!==JSON.stringify(D[p])&&_(D[p])});case"IMPORT_STATE":{const{nextLiftedState:D}=k.payload,O=(L=D.computedStates.slice(-1)[0])==null?void 0:L.state;if(!O)return;_(p===void 0?O:O[p]),m==null||m.send(null,D);return}case"PAUSE_RECORDING":return T=!T}return}}),M},A_=R_,Iv=(t,e)=>{let n;try{n=JSON.parse(t)}catch(i){console.error("[zustand devtools middleware] Could not parse the received json",i)}n!==void 0&&e(n)},M_=t=>(e,n,i)=>{const a=i.subscribe;return i.subscribe=(u,f,p)=>{let g=u;if(f){const S=(p==null?void 0:p.equalityFn)||Object.is;let m=u(i.getState());g=x=>{const T=u(x);if(!S(m,T)){const _=m;f(m=T,_)}},p!=null&&p.fireImmediately&&f(m,m)}return a(g)},t(e,n,i)},O_=M_,__=(t={},e)=>{switch(e.type){case TS:return{...t,[e.payload.id]:e.payload.type};case RS:return{...t,...e.payload.mapping};default:return t}};function Nv(t,e,n,i){return!(!t[n]||!t[n][e]||!t[n][e][i]||!Array.isArray(t[n][e][i]))}function L_(t,e){const n={},i=[];for(const[a,u]of Object.entries(t||{})){i.push(a);const f=(e||{})[a];if(!f||f.length===0){n[a]=u;continue}n[a]=f}for(const[a,u]of Object.entries(e||{}))i.indexOf(a)===-1&&(n[a]=u);return n}function Ge(t){return t.payload}function zv(t,e){return typeof t>"u"?e:t}const D_=(t=FS(),e)=>{var n;const i=(a,u)=>({...t,[Ge(e).type]:{...t[Ge(e).type],[Ge(e).id]:{...a,...u}}});switch(e.type){case gS:{if(!t[Ge(e).type]||!t[Ge(e).type][Ge(e).id])return t;const a=t[Ge(e).type][Ge(e).id];return typeof a=="string"?t:i(a,{[Ge(e).key]:Ge(e).value})}case yS:{if(!Nv(t,Ge(e).id,Ge(e).type,Ge(e).key))return t;const a=t[Ge(e).type][Ge(e).id];if(typeof a=="string")return t;const u=Array.from(a[Ge(e).key]),[f]=u.splice(Ge(e).startIndex,1);return u.splice(Ge(e).endIndex,0,f),i(a,{[Ge(e).key]:u})}case mS:{const a=Object.keys(Ge(e).entities),u={...t};for(const f of a){const p=Ge(e).entities[f],g={...t[f]||{}};let S=!1;const m=Object.keys(p||{})||[];if(p&&m){for(const x of m)S=!0,g[x]=t[f][x]?L_(t[f][x],p[x]):p[x];S&&(u[f]=g)}}return u}case SS:{if(!Nv(t,Ge(e).id,Ge(e).type,Ge(e).key))return t;const a=t[Ge(e).type][Ge(e).id],u=Array.from(a[Ge(e).key]);return u.splice(zv(Ge(e).index,u.length+1),0,Ge(e).reference),i(a,{[Ge(e).key]:u})}case Av:case bS:{if(!Nv(t,Ge(e).id,Ge(e).type,Ge(e).key))return t;const a=t[Ge(e).type][Ge(e).id],u=Array.from(a[Ge(e).key]),f=zv(Ge(e).index,u.findIndex(p=>p&&p.id===Ge(e).reference.id));return f===-1||((n=u[f])==null?void 0:n.id)!==Ge(e).reference.id?t:(e.type===Av?u.splice(f,1,Ge(e).reference):u.splice(f,1),i(a,{[Ge(e).key]:u}))}case ES:{const a=t[Ge(e).type][Ge(e).id];if(!a)return t;const u=Array.from(a.metadata||[]),f=Ge(e);return u.splice(zv(e.payload.beforeIndex,u.length+1),0,{label:f.label,value:f.label}),i(a,{metadata:u})}case wS:{const a=t[Ge(e).type][Ge(e).id];if(typeof a=="string"||!a)return t;const u=Array.from(a.metadata||[]),[f]=u.splice(Ge(e).startIndex,1);return u.splice(Ge(e).endIndex,0,f),i(a,{metadata:u})}case Mv:case xS:{const a=t[Ge(e).type][Ge(e).id],u=Array.from(a.metadata||[]),f=Ge(e).atIndex;return typeof f>"u"||f===-1||!u[f]?t:(e.type===Mv?u.splice(f,1,{label:Ge(e).label,value:Ge(e).value}):u.splice(f,1),i(a,{metadata:u}))}default:return t}},P_=(t={},e)=>{switch(e.type){case DS:case v_:return{...t,[e.payload.id]:{requestUri:e.payload.id,loadingState:LS,uriMismatch:!1,resourceUri:e.payload.id}};case kS: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 PS:return{...t,[e.payload.id]:{...t[e.payload.id]||{},loadingState:Ov,error:e.payload.message}};case IS:return{...t,[e.payload.id]:{...t[e.payload.id]||{},loadingState:_v,error:void 0}}}return t},k_=(t={},e)=>{const{id:n,updateValue:i,value:a,meta:u,key:f}=e&&e.payload||{};switch(e.type){case AS:return{...t,[n]:{...t[n]||{},[u]:{...t[n]?t[n][u]||{}:{},[f]:a}}};case MS:return{...t,[n]:{...t[n]||{},[u]:{...t[n]?t[n][u]||{}:{},[f]:t[n]&&t[n][u]?i(t[n][u][f]):i(void 0)}}};case OS:return t[n]&&t[n][u]&&t[n][u][f]?{...t,[n]:{...t[n]||{},[u]:{...t[n]?t[n][u]||{}:{},[f]:void 0}}}:t;default:return t}};function HS(t={}){const e=Object.keys(t);return function(n={},i){let a=!1;const u={};for(let f=0;f<e.length;f++){const p=e[f];u[p]=t[p](n[p],i),a=a||u[p]!==n[p]}return a?u:n}}function I_(t){return(e,n)=>n&&n.type===Lv?n.payload.actions.reduce(t,e):n&&n.type===S_?{...e,iiif:{...e.iiif,...n.payload.state}}:t(e,n)}const N_=HS({mapping:__,entities:D_,requests:P_,meta:k_});function z_(){return{iiif:{entities:FS(),meta:{},mapping:{},requests:{}}}}function U_(t={}){const{enableDevtools:e=!1,iiifStoreName:n="iiif",defaultState:i=z_(),customReducers:a={}}=t,u=I_(HS({[n]:N_,...a}));return x_(O_(A_(C_(u,i),{enabled:e})))}function j_(t){return{all:t=t||new Map,on:function(e,n){var i=t.get(e);i?i.push(n):t.set(e,[n])},off:function(e,n){var i=t.get(e);i&&(n?i.splice(i.indexOf(n)>>>0,1):t.set(e,[]))},emit:function(e,n){var i=t.get(e);i&&i.slice().map(function(a){a(n)}),(i=t.get("*"))&&i.slice().map(function(a){a(e,n)})}}}function Ci(t,e,n,i=!0){e[jl]=e[jl]||[],e[jl].push(t);const a=new Map;Object.defineProperty(e,t,{enumerable:i,get(){if(typeof e[uo][t]>"u")return;const u=e[uo][t];if(!u)return u;const f=n.get(e[uo][t],{parent:this.id?{id:this.id,type:this.type}:void 0});return a.has(f)||(a.clear(),a.set(f,fo(f,n))),a.get(f)},set(u){e[uo][t]!==u&&(this[co]?n.modifyEntityField({id:this.id,type:this.type},t,$S(u)):this[uo][t]=u)}})}const uo=Symbol.for("_refs_"),co=Symbol.for("_reactive_"),jl=Symbol.for("_defined_"),VS=Symbol.for("_parent_");function F_(t,e=!1,n){const i={id:"",type:"unknown",[jl]:[],[uo]:{},[VS]:n||null,[co]:null,is(a){return typeof a=="string"?this.id===a:a.id?a.id===this.id:!1},reactive(){if(!this[co])return this[co]=this.subscribe(()=>this.refresh(),!0),()=>{this.unreactive()}},refresh(){if(this.id){const a=this.unwrap();for(const u of Object.keys(a||{}))this[jl].includes(u)?this[uo][u]=a[u]:this[u]=a[u]}},unreactive(){this[co]&&(this[co](),this[co]=null)},unwrap(){if(!this.id)throw new Error("Invalid object");const a=this[VS];return t.get(this.id,{parent:a?{id:a,type:"unknown"}:void 0})},toPresentation3(){return t.toPresentation3(this.unwrap())},toPresentation2(){return t.toPresentation2(this.unwrap())},valueOf(){return this.unwrap()},toJSON(){const a=this;return{...a,items:a.items,annotations:a.annotations,structures:a.structures,seeAlso:a.seeAlso,service:a.service,services:a.services,rendering:a.rendering,partOf:a.partOf,start:a.start,supplementary:a.supplementary,homepage:a.homepage,thumbnail:a.thumbnail,placeholderCanvas:a.placeholderCanvas,accompanyingCanvas:a.accompanyingCanvas,provider:a.provider}},subscribe(a,u=!0){return t.subscribe(()=>this.id?t.get(this.id):null,a,u)}};return Ci("items",i,t),Ci("annotations",i,t),Ci("structures",i,t),Ci("seeAlso",i,t),Ci("rendering",i,t),Ci("partOf",i,t),Ci("start",i,t,!1),Ci("supplementary",i,t),Ci("homepage",i,t),Ci("thumbnail",i,t),Ci("placeholderCanvas",i,t,!1),Ci("accompanyingCanvas",i,t,!1),Ci("provider",i,t),Ci("body",i,t),Ci("logo",i,t),i}function B_(t){return!!t[jl]}function $S(t){return Array.isArray(t)?t.map(e=>$S(e)):!t||!t.type?t:{id:t.id,type:t.type}}function fo(t,e,n=!1,i){if(Array.isArray(t))return t.map(p=>fo(p,e,n));if(!t||!t.type||!t.id)return t;const a=F_(e,n),u=Object.create(a),f=Object.assign(u,t);return n&&f.reactive(),f}function WS(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 Uv=class{constructor(e,n){ga(this,"options"),ga(this,"store"),ga(this,"emitter"),ga(this,"isBatching",!1),ga(this,"batchQueue",[]),ga(this,"remoteFetcher"),ga(this,"staticFetcher"),ga(this,"defaultFetcher",i=>fetch(i).then(a=>a.json())),this.options=Object.assign({reducers:{},customFetcher:this.defaultFetcher,enableDevtools:!0},e||{}),this.store=n||U_({customReducers:this.options.reducers,defaultState:this.options.defaultState,enableDevtools:this.options.enableDevtools}),this.emitter=j_(),this.remoteFetcher=jS(this,this.options.customFetcher),this.staticFetcher=jS(this,(i,a)=>a)}batch(e){this.isBatching=!0;try{e(this),this.isBatching=!1,this.dispatch(Dv({actions:this.batchQueue}))}catch(n){throw this.batchQueue=[],this.isBatching=!1,n}this.batchQueue=[]}async asyncBatch(e){this.isBatching=!0;try{await e(this),this.isBatching=!1,this.dispatch(Dv({actions:this.batchQueue}))}catch(n){throw this.batchQueue=[],this.isBatching=!1,n}this.batchQueue=[]}modifyEntityField(e,n,i){this.dispatch(u_.modifyEntityField({id:e.id,type:e.type,key:n,value:i}))}dispatch(e){if(this.isBatching)this.batchQueue.push(e);else{if(e.type===Lv){for(const a of e.payload.actions)this.emitter.emit(a.type,{action:a,state:this.store.getState()});this.store.dispatch(e);const i=this.getState();for(const a of e.payload.actions)this.emitter.emit(`after:${a.type}`,{action:a,state:i});return}this.emitter.emit(e.type,{action:e,state:this.store.getState()}),this.store.dispatch(e);const n=this.store.getState();this.emitter.emit(`after:${e.type}`,{action:e,state:n});return}}on(e,n){return this.emitter.on(e,n),()=>{this.emitter.off(e,n)}}serialize(e,n){return $O(this.getState().iiif,e,n)}toPresentation2(e){return this.serialize(e,GO)}toPresentation3(e){return this.serialize(e,XO)}hydrate(e,n,i={}){return this.get(e,n,{...i,skipSelfReturn:!1})}get(e,n,i={}){typeof n!="string"&&(i=n||{},n=void 0);const{skipSelfReturn:a=!0}=i||{};let u=i.parent?typeof i.parent=="string"?i.parent:i.parent.id:void 0;if(Array.isArray(e))return e.map(x=>this.get(x,i));const f=this.getState();if(da(e)&&!i.preserveSpecificResources&&(e=e.source),typeof e=="string"){const x=WS(n||f.iiif.mapping[e]);if(!x)return a?null:{id:e,type:"unknown"};e={id:e,type:x}}if(e&&e.partOf&&!u&&!i.skipPartOfCheck){const x=Array.isArray(e.partOf)?e.partOf[0]:e.partOf;x&&(typeof x=="string"&&(u=x),typeof x.id=="string"&&(u=x.id))}const p=WS(n||(e==null?void 0:e.type)),g=e==null?void 0:e.id,S=f.iiif.entities[p];if(!S){const x=f.iiif.requests[g];return x&&x.resourceUri!==g?this.get(x.resourceUri,i):a?null:e}const m=S[e.id];if(m&&m[zn]){const x=m[zn].find(T=>u?T[Kr]===u:T[Kr]===m.id);return vv(m,x)}return S[e.id]||(a?null:e)}select(e){return e(this.getState())}getStore(){return this.store}getState(){return this.store.getState()}deep(e,n){if(typeof e>"u")return this.get(n,{skipSelfReturn:!1});if(typeof e=="function")try{const a=e(this.get(n,{skipSelfReturn:!1})),u=f=>this.deep(f,a);return u.size=Array.isArray(a)?a.length:1,u}catch{const a=u=>this.deep(u,void 0);return a.size=0,a}const i=a=>this.deep(a,e);return i.size=Array.isArray(e)?e.length:1,i}loadManifest(e,n){const i=typeof e=="string"?e:e.id;return this.load(i,n)}loadCollection(e,n){const i=typeof e=="string"?e:e.id;return this.load(i,n)}load(e,n){const i=typeof e=="string"?e:e.id;return n?this.staticFetcher(i,n):this.remoteFetcher(i)}areInputsEqual(e,n){return US(e,n)}subscribe(e,n,i){return typeof i>"u"&&(typeof n>"u"||n===!1||n===!0)&&(i=n,n=e,e=a=>a),this.store.subscribe(e,a=>n(a,this),{equalityFn:US,fireImmediately:!i})}async ensureLoaded(e){const n=typeof e=="string"?e:e.id;this.requestStatus(n)||await this.load(n)}requestStatus(e){return this.select(n=>n.iiif.requests[e])}getResourceMeta(e,n){const i=this.getState().iiif.meta[e];if(i)return n?i[n]:i}getObject(e,n,i={}){const{reactive:a,...u}=i;return fo(this.get(e,n,u),this,a)}async loadObject(e,n){return fo(await this.load(e,n),this)}async loadManifestObject(e,n){return fo(await this.loadManifest(e,n),this)}async loadCollectionObject(e,n){return fo(await this.loadCollection(e,n),this)}wrapObject(e){return fo(this.get(e,{skipSelfReturn:!1}),this)}isWrapped(e){return B_(e)}setMetaValue([e,n,i],a){this.dispatch(typeof a=="function"?_S.setMetaValueDynamic({id:e,meta:n,key:i,updateValue:a}):_S.setMetaValue({id:e,meta:n,key:i,value:a}))}};function H_(){return typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{}}function qS(t){const e=H_();try{const i=e.IIIF_VAULT;if(i)return i}catch{}const n=new Uv(t);try{e.IIIF_VAULT=n}catch{}return n}const bc=R.createContext({vault:null,setVaultInstance:t=>{}});function jv({vault:t,vaultOptions:e,useGlobal:n,resources:i,children:a}){const[u,f]=R.useState(()=>t||(n?qS(e):e?new Uv(e):new Uv));return oe.jsx(bc.Provider,{value:{vault:u,setVaultInstance:f},children:oe.jsx(ca,{value:i||{},children:a})})}const Un=()=>{const{vault:t}=R.useContext(bc);if(t===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return t};function Fv(t,{noCache:e=!1}={}){const n=typeof t=="string"?t:t.id,i=Un(),[a,u]=R.useState(n),[f,p]=R.useState(void 0),g=R.useMemo(()=>i.get(n,{skipSelfReturn:!0})||void 0,[n,i]),[S,m]=R.useState(g);return R.useEffect(()=>{(async()=>{try{const x=g&&!e?g:await i.load(n),T=x?x.id||x["@id"]:null;x&&a!==T&&u(T),m(x)}catch(x){p(x)}})()},[n,e]),{isLoaded:!!S,id:a,requestId:n,error:f,resource:S,cached:!!(S&&S===g)}}function YS(t,e){const{id:n,isLoaded:i,error:a,resource:u,requestId:f,cached:p}=Fv(t,e);return{id:n,isLoaded:i,error:a,manifest:u,requestId:f,cached:p}}function QS({manifest:t,children:e}){return oe.jsx(ca,{value:{manifest:t},children:e})}function zd({canvas:t,children:e}){return oe.jsx(ca,{value:{canvas:t},children:e})}function ni(t,e=[]){const n=Un(),[i,a]=R.useState(()=>t(n.getState(),n));return R.useEffect(()=>n.subscribe(u=>t(u,n),u=>{a(u)},!1),e),i}const Ec=R.createContext([]);function Bv(){const t=R.useContext(Ec);return ni(e=>t.map(n=>e.iiif.entities.Canvas[n]).filter(Boolean),[t])}function ya(t={},e=[]){const{id:n,selector:i}=t,a=As();Un();const u=n||a.manifest,f=ni(p=>u?p.iiif.entities.Manifest[u]:void 0,[u]);return R.useMemo(()=>{if(f)return i?i(f):f},[f,i,...e])}function GS({range:t,children:e}){return oe.jsx(ca,{value:{range:t},children:e})}function XS(t,e){for(const n of e.items){if(n.type==="Canvas")return n;if(n.type==="SpecificResource")return n.source;if(n.type==="Range"){const i=XS(t,t.get(n));if(i)return i}}return null}function Hv(t,e){var i;const n=[];for(const a of e.items)if(a.type==="SpecificResource"&&((i=a.source)==null?void 0:i.type)==="Canvas"&&(a.source.id.indexOf("#")!==-1?n.push({id:a.source.id.split("#")[0],type:"Canvas"}):n.push(a.source)),a.type==="Range"&&n.push(...Hv(t,t.get(a))),a.type==="SpecificResource"){const u=typeof a.source=="string"?a.source:a.source.id;n.push({id:u,type:"Canvas"})}return n}function V_(t,e,n){for(const i of e.structures){const a=Vv(t,t.get(i),n);if(a)return a}return null}function Vv(t,e,n){var i,a,u;for(const f of e.items){const p=(a=(i=f==null?void 0:f.source)==null?void 0:i.id)==null?void 0:a.split("#")[0];if(f.type==="SpecificResource"&&f.source===n||f.type==="SpecificResource"&&((u=f.source)==null?void 0:u.type)==="Canvas"&&n===p)return e;if(f.type==="Range"){const g=Vv(t,t.get(f),n);if(g)return g}}return null}function $_(t,e,n,i=!1){const a=e.behavior,u=n?t.get(n):null;if(!u)return[];const f=u.behavior,p=i?!1:a.includes("paged"),g=p?!1:a.includes("continuous"),S=p||g?!1:a.includes("individuals"),m=f.includes("facing-pages"),x=f.includes("non-paged");if(m||x||S||i)return[{id:u.id,type:"Canvas"}];const[T,_]=$v(t,e);if(g)return T;const M=T.findIndex(k=>k.id===n);if(M===-1)return[];for(const k of _)if(k.includes(M))return k.map(L=>T[L]);return[{id:u.id,type:"Canvas"}]}function $v(t,e,{disablePaging:n,skipNonPaged:i}={}){const a=e.behavior,u=a.includes("paged"),f=u?!1:a.includes("continuous"),p=u||f?!1:a.includes("individuals"),g=e.type==="Manifest"?e.items:Hv(t,e);if(f)return[g,[g.map((M,k)=>k)]];if(p||!u||n)return[g,g.map((M,k)=>[k])];const S=[];let m=[];const x=()=>{m.length&&(S.push([...m]),m=[])};let T=0,_=!1;for(let M=0;M<g.length;M++){const k=t.get(g[M]);if(k.behavior.includes("non-paged")){M===T&&T++,i||(x(),S.push([M]),x());continue}if(M===T||k.behavior.includes("facing-pages")){m.length&&(_=!0),x(),S.push([M]),x();continue}if(m.push(M),_){x(),_=!1;continue}m.length>1&&x()}return m.length&&x(),[g,S]}function KS(t={},e=[]){const{id:n,selector:i}=t,a=As(),u=n||a.range,f=ni(p=>u?p.iiif.entities.Range[u]:void 0,[u]);return R.useMemo(()=>{if(f)return i?i(f):f},[f,i,...e])}function ZS({startCanvas:t,disablePaging:e}){var M;const n=Un(),i=ya(),a=KS(),[u,f]=R.useState(void 0),p=a||i;if(!p)throw new Error("Nothing selected");const[g,S]=R.useMemo(()=>$v(n,p,{disablePaging:e}),[n,p]),m=R.useCallback(k=>{const L=S.findIndex(D=>D.includes(k));f(L===-1?0:L)},[g,S]),x=R.useCallback(k=>{const L=g.findIndex(D=>D.id===k);L!==-1?m(L):f(0)},[g,S]),T=R.useCallback(()=>{f(k=>k>=S.length?k:k+1)},[S]),_=R.useCallback(()=>{f(k=>k<=0?0:k-1)},[S]);return typeof u>"u"&&(t?x(t):f(0)),{visibleItems:((M=S[u])==null?void 0:M.map(k=>g[k].id))||[],cursor:u,items:g,sequence:S,setSequenceIndex:f,setCanvasIndex:m,setCanvasId:x,next:T,previous:_}}const xc=()=>{},wc=R.createContext({setCurrentCanvasId:xc,setCurrentCanvasIndex:xc,nextCanvas:xc,previousCanvas:xc,items:[],sequence:[],setSequenceIndex:xc,currentSequenceIndex:0});function JS(t){const e=ya(),{cursor:n,visibleItems:i,next:a,sequence:u,items:f,setCanvasIndex:p,setCanvasId:g,previous:S,setSequenceIndex:m}=ZS({startCanvas:t.startCanvas,disablePaging:t.pagingEnabled===!1}),x=R.useMemo(()=>({sequence:u,items:f,setCurrentCanvasId:g,nextCanvas:a,previousCanvas:S,totalCanvases:f.length,setCurrentCanvasIndex:p,setSequenceIndex:m,currentSequenceIndex:n}),[u,f,g,a,S,f,p,m,n]);return e?oe.jsx(wc.Provider,{value:x,children:oe.jsx(Ec.Provider,{value:i,children:oe.jsx(zd,{canvas:i[0],children:t.children})})}):(console.warn("The manifest passed to the provider is not a valid IIIF manifest."),oe.jsx("div",{children:"Sorry, something went wrong."}))}function eb(t){const e=YS(t.manifest);if(!e)return console.warn("The manifest passed to the provider is not a valid IIIF manifest."),oe.jsx("div",{children:"Sorry, something went wrong."});if(e.error)return oe.jsx("div",{children:e.error.toString()});if(!e.isLoaded)return oe.jsx("div",{children:"Loading..."});const n=oe.jsx(JS,{...t,children:t.children});return oe.jsx(QS,{manifest:e.id,children:t.rangeId?oe.jsx(GS,{range:t.rangeId,children:n}):n})}function tb(){return R.useContext(wc)}function nb(){return{VaultContext:R.useContext(bc),ResourceContext:R.useContext(kd),SimpleViewerReactContext:R.useContext(wc),VisibleCanvasReactContext:R.useContext(Ec)}}function ib(t){return oe.jsx(jv,{vault:t.bridge.VaultContext.vault||void 0,resources:t.bridge.ResourceContext,children:oe.jsx(Ec.Provider,{value:t.bridge.VisibleCanvasReactContext,children:oe.jsx(wc.Provider,{value:t.bridge.SimpleViewerReactContext,children:t.children})})})}const Zr=function(t){return function(){const e={type:t,getType:()=>t,toString:()=>t};return(n,i)=>({...e,...n!==void 0&&{payload:n},...i!==void 0&&{meta:i}})}},W_="@iiif/IMPORT_ENTITIES",q_="@iiif/MODIFY_ENTITY_FIELD",Y_="@iiif/REORDER_ENTITY_FIELD",Q_="@iiif/ADD_REFERENCE",G_="@iiif/UPDATE_REFERENCE",X_="@iiif/REMOVE_REFERENCE",K_="@iiif/ADD_METADATA",Z_="@iiif/REMOVE_METADATA",J_="@iiif/UPDATE_METADATA",eL="@iiif/REORDER_METADATA",tL=Zr(W_)(),nL=Zr(q_)(),iL=Zr(Y_)(),rL=Zr(Q_)(),sL=Zr(X_)(),aL=Zr(G_)(),oL=Zr(K_)(),lL=Zr(J_)(),uL=Zr(Z_)(),cL=Zr(eL)(),Wv={importEntities:tL,modifyEntityField:nL,reorderEntityField:iL,addReference:rL,removeReference:sL,updateReference:aL,addMetadata:oL,removeMetadata:uL,updateMetadata:lL,reorderMetadata:cL};function rb(){const e=Un().getStore();return R.useMemo(()=>n=>e.dispatch(n),[e])}function sb(t){return typeof t!="string"&&t&&t.bindToVault}function ab(){const t=Un(),e=R.useRef([]),n=rb(),i=R.useMemo(()=>`vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random()*1e9).toString(16)}`,[]);R.useLayoutEffect(()=>{const p={id:i,type:"AnnotationPage",behavior:[],label:null,thumbnail:[],summary:null,requiredStatement:null,metadata:[],rights:null,provider:[],items:[],seeAlso:[],homepage:[],rendering:[],service:[]};n(Wv.importEntities({entities:{AnnotationPage:{[p.id]:p}}}))},[i]);const a=ni(p=>i?p.iiif.entities.AnnotationPage[i]:null,[i]),u=R.useCallback((p,g)=>{if(i){if(sb(p)){const x=p;x.__vault||x.bindToVault(t),p=typeof x.source=="string"?x.source:x.source.id,e.current[p]=x}else typeof p!="string"&&(p=p.id);const S=t.get({id:i,type:"AnnotationPage"}),m=t.get({id:p,type:"Annotation"});S&&m&&(S.items.find(x=>x.id===m.id)||n(Wv.addReference({id:i,type:"AnnotationPage",key:"items",reference:{id:p,type:"Annotation"},index:g})))}},[i]),f=R.useCallback(p=>{i&&(sb(p)?p=typeof p.source=="string"?p.source:p.source.id:typeof p!="string"&&(p=p.id),e.current[p]&&e.current[p].beforeRemove(),t.get({id:i,type:"AnnotationPage"})&&n(Wv.removeReference({id:i,type:"AnnotationPage",key:"items",reference:{id:p,type:"Annotation"}})))},[i]);return[a,{addAnnotation:u,removeAnnotation:f}]}const ob=R.createContext(null);function lb(){const t=R.useContext(ob);return[t.fullPage,{addAnnotation:t.addAnnotation,removeAnnotation:t.removeAnnotation}]}function ub({children:t}){const[e,{addAnnotation:n,removeAnnotation:i}]=ab();return oe.jsx(ob.Provider,{value:R.useMemo(()=>({fullPage:e,addAnnotation:n,removeAnnotation:i}),[e]),children:t})}function fL({width:t,style:e,height:n,error:i,resetErrorBoundary:a}){return oe.jsxs("div",{style:{width:t,height:n,minHeight:500,...e||{},background:"#f9f9f9"},children:[oe.jsx("h3",{children:"Error occurred"}),oe.jsx("p",{children:i.message}),oe.jsx("button",{onClick:a,children:"Reset"})]})}const Ud=R.createContext(null);function cb(){return R.useContext(Ud)}const fb=R.createContext(()=>{}),db=R.createContext(()=>{});function Fl(t,e,n,i,a=[]){const u=R.useContext(t==="portal"?db:fb);R.useEffect(()=>(t!=="none"&&u(e,n,i),()=>{u(e,null)}),[e,t,u,...a])}function Jr(t={},e=[]){const{id:n,selector:i}=t,a=As(),u=n||a.canvas,f=ni(p=>u?p.iiif.entities.Canvas[u]:void 0,[u]);return R.useMemo(()=>{if(f)return i?i(f):f},[f,i,...e])}const hb=R.createContext(()=>{});function dL(t){const e=Jr(),n=R.useContext(hb);R.useEffect(()=>e&&e.id?(n(e.id,t),()=>n(e.id,-1)):()=>{},[e,t])}function hL({children:t,errorFallback:e,outerContainerProps:n={},worldScale:i,...a}){const[u,f]=R.useState(),p=nb(),g=e||fL,[S,m]=R.useState({}),x=Object.entries(S),[T,_]=R.useState({}),M=Object.entries(T),[k,L]=R.useState({}),D=R.useMemo(()=>i||Math.max(...Object.values(k)),[k]),O=R.useMemo(()=>({maxOverZoom:D||1,...a.runtimeOptions||{}}),[D,a.runtimeOptions]),j=R.useCallback((H,Z)=>{L(ie=>{if(Z===-1){const{[H]:W,...re}=ie;return re}return{...ie,[H]:Z}})},[]),q=R.useCallback((H,Z,ie)=>{m(({[H]:W,...re})=>Z?{...re,[H]:{element:Z,props:ie}}:re)},[]),ee=R.useCallback((H,Z,ie)=>{_(({[H]:W,...re})=>Z?{...re,[H]:{element:Z,props:ie}}:re)},[]);return oe.jsxs(IM,{resetKeys:[],fallbackRender:H=>oe.jsx(g,{...a,...H}),children:[oe.jsx(wM,{...a,containerProps:{style:{position:"relative"},...a.containerProps||{}},htmlChildren:oe.jsx(oe.Fragment,{children:x.map(([H,{element:Z,props:ie}])=>oe.jsx(R.Fragment,{children:oe.jsx(Z,{...ie||{}})},H))}),onCreated:H=>{f(H),a.onCreated&&a.onCreated(H)},runtimeOptions:O,children:oe.jsx(Ud.Provider,{value:u,children:oe.jsx(hb.Provider,{value:j,children:oe.jsx(fb.Provider,{value:q,children:oe.jsx(db.Provider,{value:ee,children:oe.jsx(ib,{bridge:p,children:oe.jsx(Od.Provider,{value:a.mode||"explore",children:oe.jsx(ub,{children:t})})})})})})})}),oe.jsx("div",{children:M.map(([H,{element:Z,props:ie}])=>oe.jsx(R.Fragment,{children:oe.jsx(Z,{...ie||{}})},H))})]})}const jd={},pb={get(t){return t},setMetaValue([t,e,n],i){const a=pb.getResourceMeta(t,e),u=a?a[n]:void 0,f=typeof i=="function"?i(u):i;jd[t]={...jd[t]||{},[e]:{...(jd[t]||{})[e]||{},[n]:f}}},getResourceMeta:(t,e)=>{const n=jd[t];if(n)return e?n[e]:n}};function vb(t=pb){return{addEventListener(e,n,i,a){if(e)return t.setMetaValue([e.id,"eventManager",n],u=>{const f=u||[];for(const p of f)if(p.callback===i)return f;return[...f,{callback:i,scope:a}]}),i},removeEventListener(e,n,i){e&&t.setMetaValue([e.id,"eventManager",n],a=>(a||[]).filter(u=>u.callback!==i))},getListenersAsProps(e,n){const i=typeof e=="string"?{id:e}:e;if(!i||!i.id)return{};const a=t.getResourceMeta(i.id,"eventManager"),u={};if(a&&i)for(const f of Object.keys(a))u[f]=p=>{const g=t.get(i);for(const{callback:S,scope:m}of a[f]||[])(!m||n&&m.indexOf(n)!==-1)&&S(p,g)};return u}}}function qv(t,e){const n=Un(),i=R.useMemo(()=>vb(n),[n]),a=ni(()=>t&&t.id?n.getResourceMeta(t.id,"eventManager"):null,[t]);return R.useMemo(()=>t?i.getListenersAsProps(t,e):{},[a,t,n,e])}const Fd={},mb={get(t){return t},setMetaValue([t,e,n],i){const a=mb.getResourceMeta(t,e),u=a?a[n]:void 0,f=typeof i=="function"?i(u):i;Fd[t]={...Fd[t]||{},[e]:{...(Fd[t]||{})[e]||{},[n]:f}}},getResourceMeta:(t,e)=>{const n=Fd[t];if(n)return e?n[e]:n}};function Yv(t=mb){return{applyStyles(e,n,i){const a=typeof e=="string"?e:e.id;return t.setMetaValue([a,"styles",n],i)},getAppliedStyles(e){const n=typeof e=="string"?e:e.id;return t.getResourceMeta(n,"styles")}}}function Cc(t,e){const n=Un(),i=R.useMemo(()=>Yv(n),[n]);return ni(()=>{if(!t)return null;const a=i.getAppliedStyles(t.id);return a?e?a[e]:a:void 0},[t,e])}var pL=Object.defineProperty,vL=(t,e,n)=>e in t?pL(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Bd=(t,e,n)=>(vL(t,typeof e!="symbol"?e+"":e,n),n),mL=function(){function t(e,n){var i=[],a=!0,u=!1,f=void 0;try{for(var p=e[Symbol.iterator](),g;!(a=(g=p.next()).done)&&(i.push(g.value),!(n&&i.length===n));a=!0);}catch(S){u=!0,f=S}finally{try{!a&&p.return&&p.return()}finally{if(u)throw f}}return i}return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),Tc=Math.PI*2,Qv=function(t,e,n,i,a,u,f){var p=t.x,g=t.y;p*=e,g*=n;var S=i*p-a*g,m=a*p+i*g;return{x:S+u,y:m+f}},gL=function(t,e){var n=e===1.5707963267948966?.551915024494:e===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(e/4),i=Math.cos(t),a=Math.sin(t),u=Math.cos(t+e),f=Math.sin(t+e);return[{x:i-a*n,y:a+i*n},{x:u+f*n,y:f-u*n},{x:u,y:f}]},gb=function(t,e,n,i){var a=t*i-e*n<0?-1:1,u=t*n+e*i;return u>1&&(u=1),u<-1&&(u=-1),a*Math.acos(u)},yL=function(t,e,n,i,a,u,f,p,g,S,m,x){var T=Math.pow(a,2),_=Math.pow(u,2),M=Math.pow(m,2),k=Math.pow(x,2),L=T*_-T*k-_*M;L<0&&(L=0),L/=T*k+_*M,L=Math.sqrt(L)*(f===p?-1:1);var D=L*a/u*x,O=L*-u/a*m,j=S*D-g*O+(t+n)/2,q=g*D+S*O+(e+i)/2,ee=(m-D)/a,H=(x-O)/u,Z=(-m-D)/a,ie=(-x-O)/u,W=gb(1,0,ee,H),re=gb(ee,H,Z,ie);return p===0&&re>0&&(re-=Tc),p===1&&re<0&&(re+=Tc),[j,q,W,re]},SL=function(t){var e=t.px,n=t.py,i=t.cx,a=t.cy,u=t.rx,f=t.ry,p=t.xAxisRotation,g=p===void 0?0:p,S=t.largeArcFlag,m=S===void 0?0:S,x=t.sweepFlag,T=x===void 0?0:x,_=[];if(u===0||f===0)return[];var M=Math.sin(g*Tc/360),k=Math.cos(g*Tc/360),L=k*(e-i)/2+M*(n-a)/2,D=-M*(e-i)/2+k*(n-a)/2;if(L===0&&D===0)return[];u=Math.abs(u),f=Math.abs(f);var O=Math.pow(L,2)/Math.pow(u,2)+Math.pow(D,2)/Math.pow(f,2);O>1&&(u*=Math.sqrt(O),f*=Math.sqrt(O));var j=yL(e,n,i,a,u,f,m,T,M,k,L,D),q=mL(j,4),ee=q[0],H=q[1],Z=q[2],ie=q[3],W=Math.abs(ie)/(Tc/4);Math.abs(1-W)<1e-7&&(W=1);var re=Math.max(Math.ceil(W),1);ie/=re;for(var ge=0;ge<re;ge++)_.push(gL(Z,ie)),Z+=ie;return _.map(function(be){var Ee=Qv(be[0],u,f,k,M,ee,H),Ue=Ee.x,je=Ee.y,Xe=Qv(be[1],u,f,k,M,ee,H),ce=Xe.x,me=Xe.y,tt=Qv(be[2],u,f,k,M,ee,H),mt=tt.x,he=tt.y;return{x1:Ue,y1:je,x2:ce,y2:me,x:mt,y:he}})};function yb(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var bL=xL,Gv={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},EL=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function xL(t){var e=[];return t.replace(EL,function(n,i,a){var u=i.toLowerCase();for(a=CL(a),u=="m"&&a.length>2&&(e.push([i].concat(a.splice(0,2))),u="l",i=i=="m"?"l":"L");;){if(a.length==Gv[u])return a.unshift(i),e.push(a);if(a.length<Gv[u])throw new Error("malformed path data");e.push([i].concat(a.splice(0,Gv[u])))}}),e}var wL=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function CL(t){var e=t.match(wL);return e?e.map(Number):[]}const TL=yb(bL);var RL=AL;function AL(t){var e=0,n=0,i=0,a=0;return t.map(function(u){u=u.slice();var f=u[0],p=f.toUpperCase();if(f!=p)switch(u[0]=p,f){case"a":u[6]+=i,u[7]+=a;break;case"v":u[1]+=a;break;case"h":u[1]+=i;break;default:for(var g=1;g<u.length;)u[g++]+=i,u[g++]+=a}switch(p){case"Z":i=e,a=n;break;case"H":i=u[1];break;case"V":a=u[1];break;case"M":i=e=u[1],a=n=u[2];break;default:i=u[u.length-2],a=u[u.length-1]}return u})}const ML=yb(RL);function OL(t){const e=TL(t),n=ML(e);let i,a=0,u=0,f=0,p=0,g,S,m=0,x=0;const T=[];for(let _=0;_<n.length;_++){let M=n[_];const k=M[0];switch(k){case"M":a=M[1],u=M[2];break;case"H":M=["L",M[1],u];break;case"V":M=["L",a,M[1]];break;case"S":{let L=m,D=x;(i==="C"||i=="S")&&(L+=L-f,D+=D-p),M=["C",L,D,M[1],M[2],M[3],M[4]]}break;case"T":i==="Q"||i=="T"?(g=m*2-g,S=x*2-S):(g=m,S=x),M=["Q",g,S,M[1],M[2]];break;case"Q":g=M[1],S=M[2];break;case"A":{const L=SL({px:m,py:x,cx:M[6],cy:M[7],rx:M[1],ry:M[2],xAxisRotation:M[3],largeArcFlag:M[4],sweepFlag:M[5]});if(!L.length)continue;for(const[D,O]of L.entries())M=["C",O.x1,O.y1,O.x2,O.y2,O.x,O.y],D<L.length-1&&T.push(M);M=M}break;case"Z":M=["L",a,u];break}i=k,m=M[M.length-2],x=M[M.length-1],["C","Q","A"].indexOf(k)>-1?(f=M[M.length-4],p=M[M.length-3]):(f=m,p=x),T.push(M)}return T}/** Code to "flatten" quadratic and cubic Bézier curves to polylines.
289
289
  *
290
290
  * All code in this module is based on JavaScript code by Raph Levien, published on his blog at
291
291
  * https://raphlinus.github.io/.