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