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