react-iiif-vault 0.9.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/README.md ADDED
@@ -0,0 +1,213 @@
1
+ # React vault
2
+ React bindings for Hyperion vault.
3
+
4
+ ## Road map
5
+
6
+ Technical proof of concepts
7
+ - Retrieval hooks
8
+ - Selectors that have dependencies on other selectors (typed)
9
+ - memoization of selectors
10
+ - possible move to react-redux-hooks
11
+
12
+ Set of proof of concept Vault bindings/hooks/contexts for:
13
+ - Collections
14
+ - Manifest
15
+ - Canvas
16
+ - Annotation
17
+ - Image service
18
+ - VaultContext
19
+
20
+ Complete the base hooks implementation for setting up contexts and selectors and build up hook collection
21
+ - AnnotationContext
22
+ - AnnotationPageContext
23
+ - CanvasContext
24
+ - CollectionContext
25
+ - ManifestContext
26
+ - useAnnotation
27
+ - useAnnotationPage
28
+ - useCanvas
29
+ - useCollection
30
+ - useDispatch
31
+ - useExternalAnnotationList
32
+ - useExternalCollection
33
+ - useExternalManifest
34
+ - useManifest
35
+ - useVault
36
+ - useVaultEffect
37
+
38
+ Create viewer abstractions
39
+ - SimpleViewerContext
40
+ - SingleCanvasContext
41
+
42
+ Canvas clock implementation
43
+ - useAnnotationsAtTime
44
+ - useCanvasClock
45
+ - useCanvasTimeline
46
+
47
+ Other helpers
48
+ - RangeContext
49
+ - usePaintingAnnotations
50
+ - useRange
51
+ - useSearchService
52
+ - useVirtualCanvas
53
+
54
+
55
+ ### New hooks
56
+
57
+ #### useRenderingStrategy
58
+ There are many ways that a canvas can be rendered, some are easier than others. A hook
59
+ that breaks these down into easier to render chunks will make iteratively supporting
60
+ features easier.
61
+
62
+ This hook will return a type, some data and some actions. The types may be something like:
63
+
64
+ - Single image - A single image or image service.
65
+ - Composite image - A composition of more than one image or image service.
66
+ - Choice - A choice that needs to be given to the user (with functions to make choice)
67
+ - Audio - A single audio file, or sequential audio files
68
+ - Video - A single video file, or sequential video files
69
+ - Complex timeline - A composite of either multiple audio, video and composite images on a timeline.
70
+
71
+ This gives implementations a goal, and can easily let users know that they don't support
72
+ the given canvas without an error.
73
+
74
+ The data models returned from this strategy should be similar to each other. A single image
75
+ should have a way to load an image service, generate tiles or fixed sizes. Composite image
76
+ should be the same as single image but with multiple. A choice should be available from the
77
+ hook regardless of the type, to support a menu-like system for choices even after a choice
78
+ is made. Audio and video should use a similar interface with controls. Complex timeline should
79
+ be very similar to audio/video with the same controls but with additional structure similar
80
+ to composite image.
81
+
82
+ ```typescript
83
+ type UseRenderingStrategy = {
84
+ type: 'single-image' | 'composite-image' | 'audio' | 'video' | 'complex-timeline';
85
+ image: { type: 'fixed-size' } | { type: 'image-service' } | null;
86
+ images: [];
87
+ media: { type: 'audio' } | { type: 'video' } | { type: 'sequence' };
88
+ duration: number;
89
+ choice: {} | null;
90
+ }
91
+ ```
92
+
93
+ ## Querying and indexing
94
+
95
+ ```ts
96
+
97
+ // Builds a memoized query
98
+ const filter = useFilter(() => {
99
+ type: 'Canvas',
100
+ id: id => id.startsWidth(`https://${myDomain}/`),
101
+ }, [myDomain]);
102
+
103
+ // The first time this is called it will build an index based on your query. (label + $contains)
104
+ const search = useVaultSearch([filter, { label: { $contains: `my-query` } }]);
105
+
106
+ //
107
+ search.results // now contains the results.
108
+
109
+ // Imperative example.
110
+ // For this filter to work, it must match reference equality.
111
+ const myFilterObject = vault.createFilter({
112
+ type: 'Canvas',
113
+ id: id => id.startsWidth('https://mydomain/'),
114
+ });
115
+
116
+ const myIndex = vault.createIndex({
117
+ name: 'My index',
118
+ refresh: true,
119
+ filter: myFilterObject,
120
+ indexes: ['viewingHint'],
121
+ });
122
+
123
+ // This is roughly what would be stored.
124
+ const state = {
125
+ indexes: [
126
+ {
127
+ filter: myFilterObject,
128
+ index: {
129
+ viewingHint: {
130
+ individuals: ['http://manifest-1/canvas-1.json'],
131
+ paged: ['http://manifest-1/canvas-2.json', 'http://manifest-1/canvas-3.json'],
132
+ }
133
+ }
134
+ }
135
+ ]
136
+ };
137
+
138
+ // And this is how it would be used.
139
+ const results = vault.query([myFilterObject, {
140
+ // This would be pre-filtered by the index.
141
+ viewingHint: 'individuals',
142
+ // Then this would be executed against the found objects.
143
+ title: { $contains: 'Test' },
144
+ }]);
145
+ ```
146
+
147
+
148
+ ## Vault event manager
149
+
150
+ ```js
151
+
152
+ // desired API:
153
+
154
+ const annotation = getAnnotationFromSomwehere();
155
+ const manager = useEventManager();
156
+
157
+ useEffect(() => {
158
+ const lastAnnotation = annotation;
159
+ const clickHandler = (e, anno) => {
160
+ // ...
161
+ };
162
+
163
+ manager.select(lastAnnotation, 'optional-label').addEventListener('click', clickHandler);
164
+
165
+ return () => {
166
+ manager.select(lastAnnotation).removeEventListener('click', clickHandler);
167
+ }
168
+ }, [annotation]);
169
+
170
+ // ...
171
+
172
+ <MyAnnotationComponent {...mananger.eventsFor(annotation)} />
173
+
174
+ // .. or
175
+
176
+ const annotationEvents = useEvents(annotation, 'optional-label');
177
+
178
+ <MyAnnotationComponent {...annotationEvents} />
179
+
180
+ // .. or
181
+
182
+ const div = useRef();
183
+
184
+ useBindEvents(div, annotation, 'optional-label');
185
+
186
+ <MyAnnotationComponent ref={div} />
187
+
188
+ ```
189
+
190
+
191
+
192
+ ### Storing annotation pages
193
+
194
+ - Annotation pages on canvases
195
+ - Annotation pages on manifests
196
+ - Annotation pages with manifestId in meta
197
+ - Annotation pages with canvasId in meta
198
+
199
+ #### Meta
200
+
201
+ Example state:
202
+ ```js
203
+ const state = {
204
+ meta: {
205
+ 'https://example.org/annotation-list/1': {
206
+ annotationListManager: {
207
+ isActive: true,
208
+ resources: ['https://example.org/manifest-1'],
209
+ }
210
+ },
211
+ }
212
+ };
213
+ ```
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var l=require("react"),K=require("@iiif/vault"),X=require("react-query"),D=require("@atlas-viewer/iiif-image-api"),F=require("@iiif/vault-helpers");function je(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var g=je(l),Le=Object.defineProperty,Y=Object.getOwnPropertySymbols,Be=Object.prototype.hasOwnProperty,De=Object.prototype.propertyIsEnumerable,Z=(e,t,n)=>t in e?Le(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ee=(e,t)=>{for(var n in t||(t={}))Be.call(t,n)&&Z(e,n,t[n]);if(Y)for(var n of Y(t))De.call(t,n)&&Z(e,n,t[n]);return e};const Fe={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},k=g.default.createContext(Fe),R=()=>l.useContext(k),V=({value:e,children:t})=>{const n=R(),r=l.useMemo(()=>ee(ee({},n),e),[e,n]);return g.default.createElement(k.Provider,{value:r},t)},ke=({annotation:e,children:t})=>g.default.createElement(V,{value:{annotation:e}},t),te=({canvas:e,children:t})=>g.default.createElement(V,{value:{canvas:e}},t),Ne=({collection:e,children:t})=>g.default.createElement(V,{value:{collection:e}},t),ne=({manifest:e,children:t})=>g.default.createElement(V,{value:{manifest:e}},t),qe=({range:e,children:t})=>g.default.createElement(V,{value:{range:e}},t),N=g.default.createContext({vault:null,setVaultInstance:e=>{}}),re=({vault:e,vaultOptions:t,resources:n,children:r})=>{const[i,s]=l.useState(()=>e||(t?new K.Vault(t):new K.Vault));return g.default.createElement(N.Provider,{value:{vault:i,setVaultInstance:s}},g.default.createElement(V,{value:n||{}},r))},_=()=>{const{vault:e}=l.useContext(N);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var ze=Object.defineProperty,oe=Object.getOwnPropertySymbols,He=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable,ae=(e,t,n)=>t in e?ze(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ue=(e,t)=>{for(var n in t||(t={}))He.call(t,n)&&ae(e,n,t[n]);if(oe)for(var n of oe(t))Qe.call(t,n)&&ae(e,n,t[n]);return e},We=(e,t,n)=>new Promise((r,i)=>{var s=a=>{try{o(n.next(a))}catch(u){i(u)}},c=a=>{try{o(n.throw(a))}catch(u){i(u)}},o=a=>a.done?r(a.value):Promise.resolve(a.value).then(s,c);o((n=n.apply(e,t)).next())});const se=(e,t={})=>{const n=_(),[r,i]=l.useState(e),s=l.useMemo(()=>n.get(e)||void 0,[e,n]),{data:c,error:o}=X.useQuery(["manifest",e],()=>We(void 0,null,function*(){const a=s||(yield n.load(e));return a&&r!==a.id&&i(a.id),a}),Ue({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,retry:!1,initialData:s},t));return{isLoaded:!!c,id:r,error:o,manifest:c}};function b(e,t=[]){const n=_(),[r,i]=l.useState(()=>e(n.getState(),n));return l.useEffect(()=>n.subscribe(s=>e(s,n),s=>{i(s)},!0),t),r}const j=g.default.createContext([]);function ie(){const e=l.useContext(j);return b(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}const q=()=>{},L=l.createContext({setCurrentCanvasId:q,setCurrentCanvasIndex:q,nextCanvas:q,previousCanvas:q,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),Xe=e=>{const t=se(e.manifest),[n,r]=l.useState(""),[i,s]=l.useState([]),c=t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");l.useEffect(()=>{var f,d;t.manifest&&(r((f=t.manifest.items[0])==null?void 0:f.id),s([(d=t.manifest.items[0])==null?void 0:d.id]))},[t.manifest,e.manifest]);const o=l.useMemo(()=>{var f;return((f=t.manifest)==null?void 0:f.items.map(d=>d.id))||[]},[t.manifest,e.manifest]),a=l.useMemo(()=>o.indexOf(n),[o,n]),u=l.useCallback(()=>{if(o.length&&n){if(a===-1||(o[a+2]?a+2===o.length:a===o.length))return;const f=c&&a!==0?o[a+2]:o[a+1],d=c?a!==0?o[a+3]:o[a+2]:null;f&&(r(f),s(d?[f,d]:[f]))}},[c,o,n,a]),h=l.useCallback(()=>{if(o.length&&n){if(a===0||a===-1)return;const f=c&&a!==1?o[a-2]:o[a-1],d=c&&a!==1?o[a-1]:null;f&&(r(f),s(d?[f,d]:[f]))}},[c,o,n,a]),p=l.useCallback(f=>{const d=c&&f%2===1?f-1:f,w=o[d],P=c&&d!==0?o[d+1]:null;w&&(r(w),s(v=>{const m=P?[w,P]:[w];if(v.length===v.length){for(let y=0;y<v.length;y++)if(v[y]!==m[y])return m;return v}return m}))},[c,o]),O=l.useCallback(f=>{const d=o.indexOf(f);d!==-1&&p(d)},[o,p]),I=l.useMemo(()=>({setCurrentCanvasId:O,nextCanvas:u,previousCanvas:h,currentCanvasIndex:a,totalCanvases:o.length,setCurrentCanvasIndex:p,pagingView:!0}),[u,h,a,o,p,O]);return!t.isLoaded||!t.manifest?g.default.createElement("div",null,"Loading..."):g.default.createElement(L.Provider,{value:I},g.default.createElement(j.Provider,{value:i},g.default.createElement(ne,{manifest:t.manifest.id},g.default.createElement(te,{canvas:n},e.children))))};function Ge(){return l.useContext(L)}function Je(){return{VaultContext:l.useContext(N),ResourceContext:l.useContext(k),SimpleViewerReactContext:l.useContext(L),VisibleCanvasReactContext:l.useContext(j)}}const Ke=e=>g.default.createElement(re,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},g.default.createElement(j.Provider,{value:e.bridge.VisibleCanvasReactContext},g.default.createElement(L.Provider,{value:e.bridge.SimpleViewerReactContext},e.children))),ce=g.default.createContext(new D.ImageServiceLoader);function z(){return l.useContext(ce)}const Ye=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,Ze=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function H(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:r,selectors:i}=H(n);return r&&(t.selector||(t.selector=r),t.selectors.push(...i)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,n]=e.split("#");return n?H({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",startTime:e.t};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=Ye.exec(e.value);if(t){const r={type:"BoxSelector",unit:t[2]==="percent:"?"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(Ze);if(n){const r={type:"TemporalSelector",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:[]}}var et=Object.defineProperty,tt=Object.defineProperties,nt=Object.getOwnPropertyDescriptors,le=Object.getOwnPropertySymbols,rt=Object.prototype.hasOwnProperty,ot=Object.prototype.propertyIsEnumerable,ue=(e,t,n)=>t in e?et(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,fe=(e,t)=>{for(var n in t||(t={}))rt.call(t,n)&&ue(e,n,t[n]);if(le)for(var n of le(t))ot.call(t,n)&&ue(e,n,t[n]);return e},de=(e,t)=>tt(e,nt(t));function E(e,t={}){if(Array.isArray(e))return E(e[0]);if(typeof e=="string"){const[n,r]=e.split("#");return r?E({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 E(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?H(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?E({type:"SpecificResource",source:de(fe({},e),{id:n}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:de(fe({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}var at=Object.defineProperty,st=Object.defineProperties,it=Object.getOwnPropertyDescriptors,pe=Object.getOwnPropertySymbols,ct=Object.prototype.hasOwnProperty,lt=Object.prototype.propertyIsEnumerable,ve=(e,t,n)=>t in e?at(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ut=(e,t)=>{for(var n in t||(t={}))ct.call(t,n)&&ve(e,n,t[n]);if(pe)for(var n of pe(t))lt.call(t,n)&&ve(e,n,t[n]);return e},ft=(e,t)=>st(e,it(t));function dt(e={},t=[]){const{id:n,selector:r}=e,i=R(),s=_(),c=n||i.annotation,o=b(u=>c?u.iiif.entities.Annotation[c]:void 0,[c]),a=b(u=>o&&o.body?o.body.map(h=>h?u.iiif.entities[h.type][h.id]:null).filter(Boolean):[],[o]);return l.useMemo(()=>{if(!o)return;const u=ft(ut({},o),{body:a,target:E(o.target,{typeMap:s.getState().iiif.mapping})});return r?r(u):u},[o,r,a,...t])}function B(e={},t=[]){const{id:n,selector:r}=e,i=R(),s=_(),c=n||i.manifest,o=c?s.select(a=>a.iiif.entities.Manifest[c]):void 0;return l.useMemo(()=>{if(!!o)return r?r(o):o},[o,r,...t])}function T(e={},t=[]){const{id:n,selector:r}=e,i=R(),s=_(),c=n||i.canvas,o=c?s.select(a=>a.iiif.entities.Canvas[c]):void 0;return l.useMemo(()=>{if(!!o)return r?r(o):o},[o,r,...t])}function pt(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 vt(e,t){return b(n=>{const r=[];if(!e)return r;const i=Object.keys(n.iiif.entities.AnnotationPage);for(const s of i)if(!t||t.indexOf(s)!==-1){const c=pt(n,s);c&&c.views&&c.views[e]&&r.push(s)}return r},[e])}function me({canvas:e,manifest:t,all:n,canvases:r}){const i=[];if(t)for(const s of t.annotations)i.indexOf(s.id)===-1&&i.push(s.id);if(n){if(r&&r.length)for(const s of r)for(const c of s.annotations)i.indexOf(c.id)===-1&&i.push(c.id)}else if(e)for(const s of e.annotations)i.indexOf(s.id)===-1&&i.push(s.id);return i}var mt=Object.defineProperty,ht=Object.defineProperties,gt=Object.getOwnPropertyDescriptors,he=Object.getOwnPropertySymbols,yt=Object.prototype.hasOwnProperty,_t=Object.prototype.propertyIsEnumerable,ge=(e,t,n)=>t in e?mt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ye=(e,t)=>{for(var n in t||(t={}))yt.call(t,n)&&ge(e,n,t[n]);if(he)for(var n of he(t))_t.call(t,n)&&ge(e,n,t[n]);return e},_e=(e,t)=>ht(e,gt(t));function wt(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 we(e,t={}){const n=_(),r=B(),i=T(),s=ie(),c=l.useMemo(()=>me({all:t.all,manifest:r,canvas:i,canvases:s}),[t.all,i,s,r]),o=vt(e,t.all?void 0:c),a=l.useCallback(h=>{!e||n.setMetaValue([h,"annotationPageManager","views"],p=>p&&!p[e]?p:_e(ye({},p||{}),{[e]:!1}))},[e,n]),u=l.useCallback((h,p={})=>{if(!e)return;const O=n.getState(),I=[];if(p==null?void 0:p.deselectOthers){const f=Object.keys(O.iiif.entities.AnnotationPage);for(const d of f){const w=wt(O,d);w&&w.views&&w.views[e]&&I.push(d)}}for(const f of I)a(f);n.setMetaValue([h,"annotationPageManager","views"],f=>f&&f[e]?f:_e(ye({},f||{}),{[e]:!0}))},[e,a,n]);return{availablePageIds:c,enabledPageIds:o,setPageEnabled:u,setPageDisabled:a}}function Q(e={}){const t=T(e.canvasId?{id:e.canvasId}:void 0);return b((n,r)=>{if(!t)return[];const i=r.get(t.items),s=[];for(const c of i)s.push(...r.get(c.items));return s},[t])}function Pt(e,t={}){return Q(t)}function St(e,t=!1){}function Ct(e,t=[]){const{id:n,selector:r}=e,i=R(),s=_(),c=n||i.collection,o=c?s.select(a=>a.iiif.entities.Collection[c]):void 0;return l.useMemo(()=>{if(!!o)return r?r(o):o},[o,r,...t])}function Ot(){const t=_().getStore();return l.useMemo(()=>n=>t.dispatch(n),[t])}function xt(e,t,n,r,i=[]){const s=_(),c=l.useMemo(()=>F.createEventsHelper(s),[s]);l.useEffect(()=>{const o=e;return o?(c.addEventListener(o,t,n,r),()=>{c.removeEventListener(o,t,n)}):()=>{}},[c,e,t,...i])}var bt=Object.defineProperty,Pe=Object.getOwnPropertySymbols,It=Object.prototype.hasOwnProperty,Et=Object.prototype.propertyIsEnumerable,Se=(e,t,n)=>t in e?bt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,$t=(e,t)=>{for(var n in t||(t={}))It.call(t,n)&&Se(e,n,t[n]);if(Pe)for(var n of Pe(t))Et.call(t,n)&&Se(e,n,t[n]);return e},Mt=(e,t,n)=>new Promise((r,i)=>{var s=a=>{try{o(n.next(a))}catch(u){i(u)}},c=a=>{try{o(n.throw(a))}catch(u){i(u)}},o=a=>a.done?r(a.value):Promise.resolve(a.value).then(s,c);o((n=n.apply(e,t)).next())});const Rt=(e,t={})=>{const n=_(),[r,i]=l.useState(e),s=l.useMemo(()=>n.get(e),[e,n]),{data:c,isFetching:o}=X.useQuery(`collection:${e}`,()=>Mt(void 0,null,function*(){const a=s||(yield n.loadCollection(e));return a&&i(a.id),a}),$t({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,initialData:s},t));return{isLoaded:!o,id:r,collection:c}};var Vt=(e,t,n)=>new Promise((r,i)=>{var s=a=>{try{o(n.next(a))}catch(u){i(u)}},c=a=>{try{o(n.throw(a))}catch(u){i(u)}},o=a=>a.done?r(a.value):Promise.resolve(a.value).then(s,c);o((n=n.apply(e,t)).next())});function Ce(){const e=T(),t=Q(),n=_(),r=z();return X.useQuery(`canvas-first-image-service:${e?e.id:"undefined"}`,()=>Vt(this,null,function*(){if(e&&t.length){const i=t[0],s=n.get(i.body[0]),o=D.getImageServices(s)[0];return o&&(yield r.loadService({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height}))||void 0}}),{refetchOnWindowFocus:!1,refetchOnMount:!1,refetchIntervalInBackground:!1,refetchInterval:!1,initialData:()=>{if(e&&t.length){const i=t[0],s=n.get(i.body[0]),o=D.getImageServices(s)[0];return o&&r.loadServiceSync({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height})||void 0}}})}function At(){const e=Ce();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 Tt(e={},t=[]){const{id:n,selector:r}=e,i=R(),s=_(),c=n||i.range,o=c?s.select(a=>a.iiif.entities.Range[c]):void 0;return l.useMemo(()=>{if(!!o)return r?r(o):o},[o,r,...t])}function jt(e,t){const n=_(),r=l.useMemo(()=>F.createEventsHelper(n),[n]),i=b(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return l.useMemo(()=>e?r.getListenersAsProps(e,t):{},[i,e,n,t])}function Oe(e,t){return b((n,r)=>r.get(e.map(i=>({id:i,type:t}))),[e,t])}function Lt(){const e=B();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function Bt(e,t){const n=_(),r=l.useMemo(()=>F.createStylesHelper(n),[n]);return b(()=>{if(!e)return null;const i=r.getAppliedStyles(e.id);return i?t?i[t]:i:void 0},[e,t])}const xe=(e,t=[])=>{const n=_();l.useEffect(()=>{e(n)},[n,...t])};function Dt(e,t,{canvasId:n,manifestId:r}={}){const i=_(),s=z(),c=l.useMemo(()=>F.createThumbnailHelper(i,{imageServiceLoader:s}),[i,s]),[o,a]=l.useState(),u=B(r?{id:r}:void 0),h=T(n?{id:n}:void 0),p=h||u,O=l.useRef(!1);if(l.useEffect(()=>()=>{O.current=!0},[]),!p)throw new Error("Must be called under a manifest or canvas context.");return xe(I=>{c.getBestThumbnailAtSize(p,e,t).then(f=>{f.best&&!O.current&&a(f.best)})},[p]),o}var Ft=Object.defineProperty,kt=Object.defineProperties,Nt=Object.getOwnPropertyDescriptors,be=Object.getOwnPropertySymbols,qt=Object.prototype.hasOwnProperty,zt=Object.prototype.propertyIsEnumerable,Ie=(e,t,n)=>t in e?Ft(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ee=(e,t)=>{for(var n in t||(t={}))qt.call(t,n)&&Ie(e,n,t[n]);if(be)for(var n of be(t))zt.call(t,n)&&Ie(e,n,t[n]);return e},$e=(e,t)=>kt(e,Nt(t));function Me(){const e=z(),[t,n]=l.useState({}),r=l.useRef(!1);return l.useEffect(()=>()=>{r.current=!0},[]),[l.useCallback((s,{height:c,width:o})=>{if(s){const a=s.id||s["@id"],u=e.loadServiceSync({id:a,width:s.width||o,height:s.height||c});u?s=u:t[a]||(r.current||n(h=>$e(Ee({},h),{[a]:"loading"})),e.loadService({id:a,width:s.width||o,height:s.height||c}).then(()=>{r.current||n(h=>$e(Ee({},h),{[a]:"done"}))}))}return s},[e,t]),t]}function G(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function Ht(e,t){const n=[],r=[];for(const i of t){const s=e.get(i.body);for(const c of s){const[o,{selector:a}]=G(c),u=(o.type||"unknown").toLowerCase();if(u==="choice"){const h=e.get(o.items);s.push(h[0]);continue}n.indexOf(u)===-1&&n.push(u),r.push({type:u,resource:o,target:i.target,selector:a})}}return{types:n,items:r}}var Qt=Object.defineProperty,Ut=Object.defineProperties,Wt=Object.getOwnPropertyDescriptors,Re=Object.getOwnPropertySymbols,Xt=Object.prototype.hasOwnProperty,Gt=Object.prototype.propertyIsEnumerable,Ve=(e,t,n)=>t in e?Qt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Jt=(e,t)=>{for(var n in t||(t={}))Xt.call(t,n)&&Ve(e,n,t[n]);if(Re)for(var n of Re(t))Gt.call(t,n)&&Ve(e,n,t[n]);return e},Kt=(e,t)=>Ut(e,Wt(t));const Ae={makeChoice:()=>{}},Te=[{type:"unknown"},Ae],U=e=>[{type:"unknown",reason:e,annotations:{pages:[]}},Ae];function Yt(e){const t=B(),n=T(),r=Q(),i=_(),[s,c]=Me(),{enabledPageIds:o}=we((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id),{all:!1}),a=Oe(o,"AnnotationPage"),[u,h]=l.useState((e==null?void 0:e.defaultChoices)||[]);e==null||e.strategies;const p=l.useMemo(()=>{const d=[];let w=null;const P=[];i.getState();for(const v of r){const m=i.get(v.body);for(const y of m){const[C,{selector:$}]=G(y),x=(C.type||"unknown").toLowerCase();if(x==="choice"){const A=i.get(C.items),S=u.length?u.map(M=>A.find(W=>W.id===M)).filter(Boolean):[A[0]];S.length===0&&S.push(A[0]),w={type:"single-choice",items:A.map(M=>({id:M.id,label:M.label,selected:S.indexOf(M)!==-1})),label:y.label},m.push(...S);continue}d.indexOf(x)===-1&&d.push(x),P.push({type:x,resource:C,target:v.target,selector:$})}}return{types:d,items:P,choice:w}},[i,c,r,u]),I={makeChoice:l.useCallback((d,{deselectOthers:w=!0,deselect:P=!1}={})=>{if(p.choice){if(p.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");h(v=>{if(P){const y=v.filter(C=>C!==d);if(y.length===0){const C=p.items[0].resource.id;return C?[C]:[]}return y}if(w)return[d];const m=[...v];if(m.length===0&&p.items.length){const y=p.items[0].resource.id;y&&m.push(y)}return v.indexOf(d)!==-1?v:[...v,d]})}},[p.choice])},f=l.useMemo(()=>{if(!n)return Te;if(p.types.length!==1)return U("ComplexTimelineStrategy not yet supported");const d=p.types[0];if(d==="image"){const w=[];for(const P of p.items){const v=P.resource&&P.resource.type==="SpecificResource"?P.resource.source:P.resource;if(!v.id)return U("No resource Identifier");let m;if(v.service){const J=D.getImageServices(v);J[0]&&(m=s(J[0],n))}P.target==="https://bvmm.irht.cnrs.fr/iiif/2309/canvas/canvas-981394#xywh=3949,994,1091,1232"&&(P.target="https://bvmm.irht.cnrs.fr/iiif/4490/canvas/canvas-981394#xywh=3949,994,1091,1232"),m&&m.width&&m.height&&m.profile==="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2"&&(m.profile="http://iiif.io/api/image/2/level2.json",m.sizes=[{width:m.width,height:m.height}],m.tiles=[{width:256,height:256,scaleFactors:[1,2,4,8,16,32]}]);const{selector:y,source:C}=E(P.target);if(C.id!==n.id)continue;const $={type:"BoxSelector",x:0,y:0,width:n.width,height:n.height},x=y?y.type==="TemporalSelector"?{type:"TemporalBoxSelector",startTime:y.startTime,endTime:y.endTime,x:$.x,y:$.y,width:$.width,height:$.height}:y:null,A={type:"BoxSelector",x:0,y:0,width:n.width,height:n.height},S=P.resource.type==="SpecificResource"?E(P.resource):null,M=S&&S.selector&&(S.selector.type==="BoxSelector"||S.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",x:S.selector.x,y:S.selector.y,width:S.selector.width,height:S.selector.height}:A,W={id:v.id,type:"Image",width:x?v.width:n.width,height:x?v.height:n.height,service:m,sizes:m&&m.sizes?m.sizes:v.width&&v.height?[{width:v.width,height:v.height}]:[],target:x||$,selector:M};w.push(W)}return[{type:"images",image:w[0],images:w,choice:p.choice},I]}return d==="audio"?U("Audio strategy not yet supported"):d==="video"?U("Video strategy not yet supported"):Te},[n,p,i,I.makeChoice]);return l.useMemo(()=>[Kt(Jt({},f[0]),{annotations:{pages:a}}),f[1]],[f,a])}exports.AnnotationContext=ke,exports.CanvasContext=te,exports.CollectionContext=Ne,exports.ContextBridge=Ke,exports.ImageServiceLoaderContext=ce,exports.ManifestContext=ne,exports.RangeContext=qe,exports.ReactVaultContext=N,exports.ResourceProvider=V,exports.ResourceReactContext=k,exports.SimpleViewerProvider=Xe,exports.SimpleViewerReactContext=L,exports.VaultProvider=re,exports.VisibleCanvasReactContext=j,exports.expandTarget=E,exports.flattenAnnotationPageIds=me,exports.getPaintables=Ht,exports.parseSelector=H,exports.parseSpecificResource=G,exports.useAnnotation=dt,exports.useAnnotationPageManager=we,exports.useAnnotationsAtTime=Pt,exports.useCanvas=T,exports.useCanvasClock=St,exports.useCollection=Ct,exports.useContextBridge=Je,exports.useDispatch=Ot,exports.useEventListener=xt,exports.useExternalCollection=Rt,exports.useExternalManifest=se,exports.useImageService=Ce,exports.useImageServiceLoader=z,exports.useImageTile=At,exports.useLoadImageService=Me,exports.useManifest=B,exports.usePaintingAnnotations=Q,exports.useRange=Tt,exports.useRenderingStrategy=Yt,exports.useResourceContext=R,exports.useResourceEvents=jt,exports.useResources=Oe,exports.useSearchService=Lt,exports.useSimpleViewer=Ge,exports.useStyles=Bt,exports.useThumbnail=Dt,exports.useVault=_,exports.useVaultEffect=xe,exports.useVaultSelector=b,exports.useVisibleCanvases=ie;
@@ -0,0 +1 @@
1
+ import g,{useContext as x,useMemo as m,useState as I,useEffect as B,createContext as Ne,useCallback as R,useRef as ee}from"react";import{Vault as te}from"@iiif/vault";import{useQuery as J}from"react-query";import{ImageServiceLoader as ke,getImageServices as K}from"@atlas-viewer/iiif-image-api";import{createEventsHelper as ne,createStylesHelper as ze,createThumbnailHelper as Ue}from"@iiif/vault-helpers";var He=Object.defineProperty,re=Object.getOwnPropertySymbols,We=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable,oe=(e,t,n)=>t in e?He(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ie=(e,t)=>{for(var n in t||(t={}))We.call(t,n)&&oe(e,n,t[n]);if(re)for(var n of re(t))Qe.call(t,n)&&oe(e,n,t[n]);return e};const Xe={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},z=g.createContext(Xe),A=()=>x(z),T=({value:e,children:t})=>{const n=A(),r=m(()=>ie(ie({},n),e),[e,n]);return g.createElement(z.Provider,{value:r},t)},qe=({annotation:e,children:t})=>g.createElement(T,{value:{annotation:e}},t),se=({canvas:e,children:t})=>g.createElement(T,{value:{canvas:e}},t),Ge=({collection:e,children:t})=>g.createElement(T,{value:{collection:e}},t),ae=({manifest:e,children:t})=>g.createElement(T,{value:{manifest:e}},t),Je=({range:e,children:t})=>g.createElement(T,{value:{range:e}},t),U=g.createContext({vault:null,setVaultInstance:e=>{}}),ce=({vault:e,vaultOptions:t,resources:n,children:r})=>{const[a,s]=I(()=>e||(t?new te(t):new te));return g.createElement(U.Provider,{value:{vault:a,setVaultInstance:s}},g.createElement(T,{value:n||{}},r))},_=()=>{const{vault:e}=x(U);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var Ke=Object.defineProperty,le=Object.getOwnPropertySymbols,Ye=Object.prototype.hasOwnProperty,Ze=Object.prototype.propertyIsEnumerable,ue=(e,t,n)=>t in e?Ke(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,et=(e,t)=>{for(var n in t||(t={}))Ye.call(t,n)&&ue(e,n,t[n]);if(le)for(var n of le(t))Ze.call(t,n)&&ue(e,n,t[n]);return e},tt=(e,t,n)=>new Promise((r,a)=>{var s=i=>{try{o(n.next(i))}catch(l){a(l)}},c=i=>{try{o(n.throw(i))}catch(l){a(l)}},o=i=>i.done?r(i.value):Promise.resolve(i.value).then(s,c);o((n=n.apply(e,t)).next())});const fe=(e,t={})=>{const n=_(),[r,a]=I(e),s=m(()=>n.get(e)||void 0,[e,n]),{data:c,error:o}=J(["manifest",e],()=>tt(void 0,null,function*(){const i=s||(yield n.load(e));return i&&r!==i.id&&a(i.id),i}),et({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,retry:!1,initialData:s},t));return{isLoaded:!!c,id:r,error:o,manifest:c}};function $(e,t=[]){const n=_(),[r,a]=I(()=>e(n.getState(),n));return B(()=>n.subscribe(s=>e(s,n),s=>{a(s)},!0),t),r}const F=g.createContext([]);function de(){const e=x(F);return $(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}const H=()=>{},N=Ne({setCurrentCanvasId:H,setCurrentCanvasIndex:H,nextCanvas:H,previousCanvas:H,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),nt=e=>{const t=fe(e.manifest),[n,r]=I(""),[a,s]=I([]),c=t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");B(()=>{var u,f;t.manifest&&(r((u=t.manifest.items[0])==null?void 0:u.id),s([(f=t.manifest.items[0])==null?void 0:f.id]))},[t.manifest,e.manifest]);const o=m(()=>{var u;return((u=t.manifest)==null?void 0:u.items.map(f=>f.id))||[]},[t.manifest,e.manifest]),i=m(()=>o.indexOf(n),[o,n]),l=R(()=>{if(o.length&&n){if(i===-1||(o[i+2]?i+2===o.length:i===o.length))return;const u=c&&i!==0?o[i+2]:o[i+1],f=c?i!==0?o[i+3]:o[i+2]:null;u&&(r(u),s(f?[u,f]:[u]))}},[c,o,n,i]),h=R(()=>{if(o.length&&n){if(i===0||i===-1)return;const u=c&&i!==1?o[i-2]:o[i-1],f=c&&i!==1?o[i-1]:null;u&&(r(u),s(f?[u,f]:[u]))}},[c,o,n,i]),d=R(u=>{const f=c&&u%2===1?u-1:u,w=o[f],P=c&&f!==0?o[f+1]:null;w&&(r(w),s(p=>{const v=P?[w,P]:[w];if(p.length===p.length){for(let y=0;y<p.length;y++)if(p[y]!==v[y])return v;return p}return v}))},[c,o]),C=R(u=>{const f=o.indexOf(u);f!==-1&&d(f)},[o,d]),E=m(()=>({setCurrentCanvasId:C,nextCanvas:l,previousCanvas:h,currentCanvasIndex:i,totalCanvases:o.length,setCurrentCanvasIndex:d,pagingView:!0}),[l,h,i,o,d,C]);return!t.isLoaded||!t.manifest?g.createElement("div",null,"Loading..."):g.createElement(N.Provider,{value:E},g.createElement(F.Provider,{value:a},g.createElement(ae,{manifest:t.manifest.id},g.createElement(se,{canvas:n},e.children))))};function rt(){return x(N)}function ot(){return{VaultContext:x(U),ResourceContext:x(z),SimpleViewerReactContext:x(N),VisibleCanvasReactContext:x(F)}}const it=e=>g.createElement(ce,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},g.createElement(F.Provider,{value:e.bridge.VisibleCanvasReactContext},g.createElement(N.Provider,{value:e.bridge.SimpleViewerReactContext},e.children))),pe=g.createContext(new ke);function W(){return x(pe)}const st=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,at=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function Q(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:r,selectors:a}=Q(n);return r&&(t.selector||(t.selector=r),t.selectors.push(...a)),t},{selector:null,selectors:[]});if(!e)return{selector:null,selectors:[]};if(typeof e=="string"){const[t,n]=e.split("#");return n?Q({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",startTime:e.t};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=st.exec(e.value);if(t){const r={type:"BoxSelector",unit:t[2]==="percent:"?"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(at);if(n){const r={type:"TemporalSelector",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:[]}}var ct=Object.defineProperty,lt=Object.defineProperties,ut=Object.getOwnPropertyDescriptors,ve=Object.getOwnPropertySymbols,ft=Object.prototype.hasOwnProperty,dt=Object.prototype.propertyIsEnumerable,he=(e,t,n)=>t in e?ct(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,me=(e,t)=>{for(var n in t||(t={}))ft.call(t,n)&&he(e,n,t[n]);if(ve)for(var n of ve(t))dt.call(t,n)&&he(e,n,t[n]);return e},ge=(e,t)=>lt(e,ut(t));function M(e,t={}){if(Array.isArray(e))return M(e[0]);if(typeof e=="string"){const[n,r]=e.split("#");return r?M({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 M(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?Q(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?M({type:"SpecificResource",source:ge(me({},e),{id:n}),selector:{type:"FragmentSelector",value:r}}):{type:"SpecificResource",source:ge(me({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}var pt=Object.defineProperty,vt=Object.defineProperties,ht=Object.getOwnPropertyDescriptors,ye=Object.getOwnPropertySymbols,mt=Object.prototype.hasOwnProperty,gt=Object.prototype.propertyIsEnumerable,_e=(e,t,n)=>t in e?pt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,yt=(e,t)=>{for(var n in t||(t={}))mt.call(t,n)&&_e(e,n,t[n]);if(ye)for(var n of ye(t))gt.call(t,n)&&_e(e,n,t[n]);return e},_t=(e,t)=>vt(e,ht(t));function wt(e={},t=[]){const{id:n,selector:r}=e,a=A(),s=_(),c=n||a.annotation,o=$(l=>c?l.iiif.entities.Annotation[c]:void 0,[c]),i=$(l=>o&&o.body?o.body.map(h=>h?l.iiif.entities[h.type][h.id]:null).filter(Boolean):[],[o]);return m(()=>{if(!o)return;const l=_t(yt({},o),{body:i,target:M(o.target,{typeMap:s.getState().iiif.mapping})});return r?r(l):l},[o,r,i,...t])}function k(e={},t=[]){const{id:n,selector:r}=e,a=A(),s=_(),c=n||a.manifest,o=c?s.select(i=>i.iiif.entities.Manifest[c]):void 0;return m(()=>{if(!!o)return r?r(o):o},[o,r,...t])}function D(e={},t=[]){const{id:n,selector:r}=e,a=A(),s=_(),c=n||a.canvas,o=c?s.select(i=>i.iiif.entities.Canvas[c]):void 0;return m(()=>{if(!!o)return r?r(o):o},[o,r,...t])}function Pt(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 Ot(e,t){return $(n=>{const r=[];if(!e)return r;const a=Object.keys(n.iiif.entities.AnnotationPage);for(const s of a)if(!t||t.indexOf(s)!==-1){const c=Pt(n,s);c&&c.views&&c.views[e]&&r.push(s)}return r},[e])}function we({canvas:e,manifest:t,all:n,canvases:r}){const a=[];if(t)for(const s of t.annotations)a.indexOf(s.id)===-1&&a.push(s.id);if(n){if(r&&r.length)for(const s of r)for(const c of s.annotations)a.indexOf(c.id)===-1&&a.push(c.id)}else if(e)for(const s of e.annotations)a.indexOf(s.id)===-1&&a.push(s.id);return a}var St=Object.defineProperty,Ct=Object.defineProperties,bt=Object.getOwnPropertyDescriptors,Pe=Object.getOwnPropertySymbols,xt=Object.prototype.hasOwnProperty,It=Object.prototype.propertyIsEnumerable,Oe=(e,t,n)=>t in e?St(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Se=(e,t)=>{for(var n in t||(t={}))xt.call(t,n)&&Oe(e,n,t[n]);if(Pe)for(var n of Pe(t))It.call(t,n)&&Oe(e,n,t[n]);return e},Ce=(e,t)=>Ct(e,bt(t));function $t(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 be(e,t={}){const n=_(),r=k(),a=D(),s=de(),c=m(()=>we({all:t.all,manifest:r,canvas:a,canvases:s}),[t.all,a,s,r]),o=Ot(e,t.all?void 0:c),i=R(h=>{!e||n.setMetaValue([h,"annotationPageManager","views"],d=>d&&!d[e]?d:Ce(Se({},d||{}),{[e]:!1}))},[e,n]),l=R((h,d={})=>{if(!e)return;const C=n.getState(),E=[];if(d==null?void 0:d.deselectOthers){const u=Object.keys(C.iiif.entities.AnnotationPage);for(const f of u){const w=$t(C,f);w&&w.views&&w.views[e]&&E.push(f)}}for(const u of E)i(u);n.setMetaValue([h,"annotationPageManager","views"],u=>u&&u[e]?u:Ce(Se({},u||{}),{[e]:!0}))},[e,i,n]);return{availablePageIds:c,enabledPageIds:o,setPageEnabled:l,setPageDisabled:i}}function X(e={}){const t=D(e.canvasId?{id:e.canvasId}:void 0);return $((n,r)=>{if(!t)return[];const a=r.get(t.items),s=[];for(const c of a)s.push(...r.get(c.items));return s},[t])}function Et(e,t={}){return X(t)}function Rt(e,t=!1){}function Mt(e,t=[]){const{id:n,selector:r}=e,a=A(),s=_(),c=n||a.collection,o=c?s.select(i=>i.iiif.entities.Collection[c]):void 0;return m(()=>{if(!!o)return r?r(o):o},[o,r,...t])}function Vt(){const t=_().getStore();return m(()=>n=>t.dispatch(n),[t])}function jt(e,t,n,r,a=[]){const s=_(),c=m(()=>ne(s),[s]);B(()=>{const o=e;return o?(c.addEventListener(o,t,n,r),()=>{c.removeEventListener(o,t,n)}):()=>{}},[c,e,t,...a])}var At=Object.defineProperty,xe=Object.getOwnPropertySymbols,Tt=Object.prototype.hasOwnProperty,Lt=Object.prototype.propertyIsEnumerable,Ie=(e,t,n)=>t in e?At(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Bt=(e,t)=>{for(var n in t||(t={}))Tt.call(t,n)&&Ie(e,n,t[n]);if(xe)for(var n of xe(t))Lt.call(t,n)&&Ie(e,n,t[n]);return e},Dt=(e,t,n)=>new Promise((r,a)=>{var s=i=>{try{o(n.next(i))}catch(l){a(l)}},c=i=>{try{o(n.throw(i))}catch(l){a(l)}},o=i=>i.done?r(i.value):Promise.resolve(i.value).then(s,c);o((n=n.apply(e,t)).next())});const Ft=(e,t={})=>{const n=_(),[r,a]=I(e),s=m(()=>n.get(e),[e,n]),{data:c,isFetching:o}=J(`collection:${e}`,()=>Dt(void 0,null,function*(){const i=s||(yield n.loadCollection(e));return i&&a(i.id),i}),Bt({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,initialData:s},t));return{isLoaded:!o,id:r,collection:c}};var Nt=(e,t,n)=>new Promise((r,a)=>{var s=i=>{try{o(n.next(i))}catch(l){a(l)}},c=i=>{try{o(n.throw(i))}catch(l){a(l)}},o=i=>i.done?r(i.value):Promise.resolve(i.value).then(s,c);o((n=n.apply(e,t)).next())});function $e(){const e=D(),t=X(),n=_(),r=W();return J(`canvas-first-image-service:${e?e.id:"undefined"}`,()=>Nt(this,null,function*(){if(e&&t.length){const a=t[0],s=n.get(a.body[0]),o=K(s)[0];return o&&(yield r.loadService({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height}))||void 0}}),{refetchOnWindowFocus:!1,refetchOnMount:!1,refetchIntervalInBackground:!1,refetchInterval:!1,initialData:()=>{if(e&&t.length){const a=t[0],s=n.get(a.body[0]),o=K(s)[0];return o&&r.loadServiceSync({id:o.id||o["@id"],width:o.width||e.width,height:o.height||e.height})||void 0}}})}function kt(){const e=$e();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 zt(e={},t=[]){const{id:n,selector:r}=e,a=A(),s=_(),c=n||a.range,o=c?s.select(i=>i.iiif.entities.Range[c]):void 0;return m(()=>{if(!!o)return r?r(o):o},[o,r,...t])}function Ut(e,t){const n=_(),r=m(()=>ne(n),[n]),a=$(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return m(()=>e?r.getListenersAsProps(e,t):{},[a,e,n,t])}function Ee(e,t){return $((n,r)=>r.get(e.map(a=>({id:a,type:t}))),[e,t])}function Ht(){const e=k();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function Wt(e,t){const n=_(),r=m(()=>ze(n),[n]);return $(()=>{if(!e)return null;const a=r.getAppliedStyles(e.id);return a?t?a[t]:a:void 0},[e,t])}const Re=(e,t=[])=>{const n=_();B(()=>{e(n)},[n,...t])};function Qt(e,t,{canvasId:n,manifestId:r}={}){const a=_(),s=W(),c=m(()=>Ue(a,{imageServiceLoader:s}),[a,s]),[o,i]=I(),l=k(r?{id:r}:void 0),h=D(n?{id:n}:void 0),d=h||l,C=ee(!1);if(B(()=>()=>{C.current=!0},[]),!d)throw new Error("Must be called under a manifest or canvas context.");return Re(E=>{c.getBestThumbnailAtSize(d,e,t).then(u=>{u.best&&!C.current&&i(u.best)})},[d]),o}var Xt=Object.defineProperty,qt=Object.defineProperties,Gt=Object.getOwnPropertyDescriptors,Me=Object.getOwnPropertySymbols,Jt=Object.prototype.hasOwnProperty,Kt=Object.prototype.propertyIsEnumerable,Ve=(e,t,n)=>t in e?Xt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,je=(e,t)=>{for(var n in t||(t={}))Jt.call(t,n)&&Ve(e,n,t[n]);if(Me)for(var n of Me(t))Kt.call(t,n)&&Ve(e,n,t[n]);return e},Ae=(e,t)=>qt(e,Gt(t));function Te(){const e=W(),[t,n]=I({}),r=ee(!1);return B(()=>()=>{r.current=!0},[]),[R((s,{height:c,width:o})=>{if(s){const i=s.id||s["@id"],l=e.loadServiceSync({id:i,width:s.width||o,height:s.height||c});l?s=l:t[i]||(r.current||n(h=>Ae(je({},h),{[i]:"loading"})),e.loadService({id:i,width:s.width||o,height:s.height||c}).then(()=>{r.current||n(h=>Ae(je({},h),{[i]:"done"}))}))}return s},[e,t]),t]}function Y(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function Yt(e,t){const n=[],r=[];for(const a of t){const s=e.get(a.body);for(const c of s){const[o,{selector:i}]=Y(c),l=(o.type||"unknown").toLowerCase();if(l==="choice"){const h=e.get(o.items);s.push(h[0]);continue}n.indexOf(l)===-1&&n.push(l),r.push({type:l,resource:o,target:a.target,selector:i})}}return{types:n,items:r}}var Zt=Object.defineProperty,en=Object.defineProperties,tn=Object.getOwnPropertyDescriptors,Le=Object.getOwnPropertySymbols,nn=Object.prototype.hasOwnProperty,rn=Object.prototype.propertyIsEnumerable,Be=(e,t,n)=>t in e?Zt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,on=(e,t)=>{for(var n in t||(t={}))nn.call(t,n)&&Be(e,n,t[n]);if(Le)for(var n of Le(t))rn.call(t,n)&&Be(e,n,t[n]);return e},sn=(e,t)=>en(e,tn(t));const De={makeChoice:()=>{}},Fe=[{type:"unknown"},De],q=e=>[{type:"unknown",reason:e,annotations:{pages:[]}},De];function an(e){const t=k(),n=D(),r=X(),a=_(),[s,c]=Te(),{enabledPageIds:o}=be((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id),{all:!1}),i=Ee(o,"AnnotationPage"),[l,h]=I((e==null?void 0:e.defaultChoices)||[]);e==null||e.strategies;const d=m(()=>{const f=[];let w=null;const P=[];a.getState();for(const p of r){const v=a.get(p.body);for(const y of v){const[S,{selector:V}]=Y(y),b=(S.type||"unknown").toLowerCase();if(b==="choice"){const L=a.get(S.items),O=l.length?l.map(j=>L.find(G=>G.id===j)).filter(Boolean):[L[0]];O.length===0&&O.push(L[0]),w={type:"single-choice",items:L.map(j=>({id:j.id,label:j.label,selected:O.indexOf(j)!==-1})),label:y.label},v.push(...O);continue}f.indexOf(b)===-1&&f.push(b),P.push({type:b,resource:S,target:p.target,selector:V})}}return{types:f,items:P,choice:w}},[a,c,r,l]),E={makeChoice:R((f,{deselectOthers:w=!0,deselect:P=!1}={})=>{if(d.choice){if(d.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");h(p=>{if(P){const y=p.filter(S=>S!==f);if(y.length===0){const S=d.items[0].resource.id;return S?[S]:[]}return y}if(w)return[f];const v=[...p];if(v.length===0&&d.items.length){const y=d.items[0].resource.id;y&&v.push(y)}return p.indexOf(f)!==-1?p:[...p,f]})}},[d.choice])},u=m(()=>{if(!n)return Fe;if(d.types.length!==1)return q("ComplexTimelineStrategy not yet supported");const f=d.types[0];if(f==="image"){const w=[];for(const P of d.items){const p=P.resource&&P.resource.type==="SpecificResource"?P.resource.source:P.resource;if(!p.id)return q("No resource Identifier");let v;if(p.service){const Z=K(p);Z[0]&&(v=s(Z[0],n))}P.target==="https://bvmm.irht.cnrs.fr/iiif/2309/canvas/canvas-981394#xywh=3949,994,1091,1232"&&(P.target="https://bvmm.irht.cnrs.fr/iiif/4490/canvas/canvas-981394#xywh=3949,994,1091,1232"),v&&v.width&&v.height&&v.profile==="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2"&&(v.profile="http://iiif.io/api/image/2/level2.json",v.sizes=[{width:v.width,height:v.height}],v.tiles=[{width:256,height:256,scaleFactors:[1,2,4,8,16,32]}]);const{selector:y,source:S}=M(P.target);if(S.id!==n.id)continue;const V={type:"BoxSelector",x:0,y:0,width:n.width,height:n.height},b=y?y.type==="TemporalSelector"?{type:"TemporalBoxSelector",startTime:y.startTime,endTime:y.endTime,x:V.x,y:V.y,width:V.width,height:V.height}:y:null,L={type:"BoxSelector",x:0,y:0,width:n.width,height:n.height},O=P.resource.type==="SpecificResource"?M(P.resource):null,j=O&&O.selector&&(O.selector.type==="BoxSelector"||O.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",x:O.selector.x,y:O.selector.y,width:O.selector.width,height:O.selector.height}:L,G={id:p.id,type:"Image",width:b?p.width:n.width,height:b?p.height:n.height,service:v,sizes:v&&v.sizes?v.sizes:p.width&&p.height?[{width:p.width,height:p.height}]:[],target:b||V,selector:j};w.push(G)}return[{type:"images",image:w[0],images:w,choice:d.choice},E]}return f==="audio"?q("Audio strategy not yet supported"):f==="video"?q("Video strategy not yet supported"):Fe},[n,d,a,E.makeChoice]);return m(()=>[sn(on({},u[0]),{annotations:{pages:i}}),u[1]],[u,i])}export{qe as AnnotationContext,se as CanvasContext,Ge as CollectionContext,it as ContextBridge,pe as ImageServiceLoaderContext,ae as ManifestContext,Je as RangeContext,U as ReactVaultContext,T as ResourceProvider,z as ResourceReactContext,nt as SimpleViewerProvider,N as SimpleViewerReactContext,ce as VaultProvider,F as VisibleCanvasReactContext,M as expandTarget,we as flattenAnnotationPageIds,Yt as getPaintables,Q as parseSelector,Y as parseSpecificResource,wt as useAnnotation,be as useAnnotationPageManager,Et as useAnnotationsAtTime,D as useCanvas,Rt as useCanvasClock,Mt as useCollection,ot as useContextBridge,Vt as useDispatch,jt as useEventListener,Ft as useExternalCollection,fe as useExternalManifest,$e as useImageService,W as useImageServiceLoader,kt as useImageTile,Te as useLoadImageService,k as useManifest,X as usePaintingAnnotations,zt as useRange,an as useRenderingStrategy,A as useResourceContext,Ut as useResourceEvents,Ee as useResources,Ht as useSearchService,rt as useSimpleViewer,Wt as useStyles,Qt as useThumbnail,_ as useVault,Re as useVaultEffect,$ as useVaultSelector,de as useVisibleCanvases};
@@ -0,0 +1,376 @@
1
+ import React, { FC } from 'react';
2
+ import * as _iiif_vault from '@iiif/vault';
3
+ import { Vault, VaultOptions, ReduxStore, NormalizedEntity, IIIFStore } from '@iiif/vault';
4
+ import { CanvasNormalized, AnnotationNormalized, CollectionNormalized, Reference, ManifestNormalized, ImageService, RangeNormalized, SearchService, AnnotationPage, InternationalString, ExternalWebResource, W3CAnnotationTarget, Selector, ContentResource, IIIFExternalWebResource, SpecificResource } from '@iiif/presentation-3';
5
+ import { ImageServiceLoader, ImageCandidateRequest, ImageCandidate } from '@atlas-viewer/iiif-image-api';
6
+ import { QueryOptions } from 'react-query';
7
+
8
+ declare const AnnotationContext: React.FC<{
9
+ annotation: string;
10
+ }>;
11
+
12
+ declare const CanvasContext: React.FC<{
13
+ canvas: string;
14
+ }>;
15
+
16
+ declare const CollectionContext: React.FC<{
17
+ collection: string;
18
+ }>;
19
+
20
+ declare const ManifestContext: React.FC<{
21
+ manifest: string;
22
+ }>;
23
+
24
+ declare const RangeContext: React.FC<{
25
+ range: string;
26
+ }>;
27
+
28
+ declare type ResourceContextType = {
29
+ collection?: string;
30
+ manifest?: string;
31
+ range?: string;
32
+ canvas?: string;
33
+ annotation?: string;
34
+ };
35
+ declare const ResourceReactContext: React.Context<ResourceContextType>;
36
+ declare const useResourceContext: () => ResourceContextType;
37
+ declare const ResourceProvider: React.FC<{
38
+ value: ResourceContextType;
39
+ }>;
40
+
41
+ declare const ReactVaultContext: React.Context<{
42
+ vault: Vault | null;
43
+ setVaultInstance: (vault: Vault) => void;
44
+ }>;
45
+ declare const VaultProvider: React.FC<{
46
+ vault?: Vault;
47
+ vaultOptions?: VaultOptions;
48
+ resources?: ResourceContextType;
49
+ }>;
50
+
51
+ declare function useContextBridge(): {
52
+ VaultContext: {
53
+ vault: _iiif_vault.Vault | null;
54
+ setVaultInstance: (vault: _iiif_vault.Vault) => void;
55
+ };
56
+ ResourceContext: ResourceContextType;
57
+ SimpleViewerReactContext: {
58
+ setCurrentCanvasId: (newId: string | ((prev: string) => string)) => void;
59
+ setCurrentCanvasIndex: (newId: number | ((prev: number) => number)) => void;
60
+ currentCanvasIndex: number;
61
+ pagingView: boolean;
62
+ totalCanvases: number;
63
+ nextCanvas: () => void;
64
+ previousCanvas: () => void;
65
+ };
66
+ VisibleCanvasReactContext: string[];
67
+ };
68
+ declare const ContextBridge: React.FC<{
69
+ bridge: ReturnType<typeof useContextBridge>;
70
+ }>;
71
+
72
+ declare const VisibleCanvasReactContext: React.Context<string[]>;
73
+ declare function useVisibleCanvases(): CanvasNormalized[];
74
+
75
+ declare const ImageServiceLoaderContext: React.Context<ImageServiceLoader>;
76
+ declare function useImageServiceLoader(): ImageServiceLoader;
77
+
78
+ declare function useAnnotation(options?: {
79
+ id: string;
80
+ }): AnnotationNormalized | undefined;
81
+ declare function useAnnotation<T>(options?: {
82
+ id: string;
83
+ selector: (annotation: AnnotationNormalized) => T;
84
+ }, deps?: any[]): T | undefined;
85
+
86
+ declare function useAnnotationPageManager(resourceId?: string, options?: {
87
+ all?: boolean;
88
+ }): {
89
+ availablePageIds: string[];
90
+ enabledPageIds: string[];
91
+ setPageEnabled: (id: string, opt?: {
92
+ deselectOthers?: boolean;
93
+ }) => void;
94
+ setPageDisabled: (deselectId: string) => void;
95
+ };
96
+
97
+ declare function useAnnotationsAtTime(time: number, options?: {
98
+ canvasId?: string;
99
+ }): AnnotationNormalized[];
100
+
101
+ declare function useCanvas(options?: {
102
+ id: string;
103
+ }): CanvasNormalized | undefined;
104
+ declare function useCanvas<T>(options?: {
105
+ id: string;
106
+ selector: (canvas: CanvasNormalized) => T;
107
+ }, deps?: any[]): T | undefined;
108
+
109
+ declare function useCanvasClock(canvasId?: string, autoplay?: boolean): void;
110
+
111
+ declare function useCollection(options: {
112
+ id: string;
113
+ }): CollectionNormalized | undefined;
114
+ declare function useCollection<T>(options: {
115
+ id: string;
116
+ selector: (collection: CollectionNormalized) => T;
117
+ }, deps?: any[]): T | undefined;
118
+
119
+ declare function useDispatch(): ReduxStore['dispatch'];
120
+
121
+ declare type SupportedEvents = 'onClick';
122
+ declare function useEventListener<T>(resource: Reference, name: SupportedEvents, listener: (e: any, resource: T) => void, scope?: string[], deps?: any[]): void;
123
+
124
+ declare const useExternalCollection: (id: string, config?: QueryOptions<CollectionNormalized>) => {
125
+ id: string;
126
+ isLoaded: boolean;
127
+ collection?: CollectionNormalized | undefined;
128
+ };
129
+
130
+ declare const useExternalManifest: (id: string, config?: QueryOptions<ManifestNormalized>) => {
131
+ id: string;
132
+ isLoaded: boolean;
133
+ error: any;
134
+ manifest?: ManifestNormalized | undefined;
135
+ };
136
+
137
+ declare function useImageService(): {
138
+ data: ImageService | undefined;
139
+ isFetching: boolean;
140
+ status: 'error' | 'success' | 'loading';
141
+ };
142
+
143
+ declare function useImageTile(): {
144
+ isLoading: boolean;
145
+ tile: {
146
+ id: string | undefined;
147
+ width: number | null | undefined;
148
+ height: number | null | undefined;
149
+ imageService: ImageService;
150
+ thumbnail: undefined;
151
+ } | null;
152
+ };
153
+
154
+ declare function useManifest(options?: {
155
+ id: string;
156
+ }): ManifestNormalized | undefined;
157
+ declare function useManifest<T>(options?: {
158
+ id: string;
159
+ selector: (manifest: ManifestNormalized) => T;
160
+ }, deps?: any[]): T | undefined;
161
+
162
+ declare function usePaintingAnnotations(options?: {
163
+ canvasId?: string;
164
+ }): AnnotationNormalized[];
165
+
166
+ declare function useRange(options?: {
167
+ id: string;
168
+ }): RangeNormalized | undefined;
169
+ declare function useRange<T>(options?: {
170
+ id: string;
171
+ selector: (range: RangeNormalized) => T;
172
+ }, deps?: any[]): T | undefined;
173
+
174
+ declare function useResourceEvents<T extends NormalizedEntity>(resource?: Reference, scope?: string[]): any;
175
+
176
+ declare function useResources<Type>(ids: string[], type: string): Type[];
177
+
178
+ declare function useSearchService(): SearchService | undefined;
179
+
180
+ declare function useStyles<Style extends Record<string, Record<string, any>>>(resource: undefined | Reference<any>): Style;
181
+ declare function useStyles<Style extends Record<string, any>>(resource: undefined | Reference<any>, scope: string): Style;
182
+
183
+ declare function useThumbnail(request: ImageCandidateRequest, dereference?: boolean, { canvasId, manifestId }?: {
184
+ canvasId?: string;
185
+ manifestId?: string;
186
+ }): ImageCandidate | undefined;
187
+
188
+ declare function useLoadImageService(): readonly [(imageService: any | undefined, { height, width }: {
189
+ height: number;
190
+ width: number;
191
+ }) => ImageService | undefined, Record<string, string>];
192
+
193
+ declare const useVault: () => Vault;
194
+
195
+ declare const useVaultEffect: (callback: (vault: Vault) => void, deps?: any[]) => void;
196
+
197
+ declare function useVaultSelector<T>(selector: (state: IIIFStore, vault: Vault) => T, deps?: any[]): T;
198
+
199
+ declare type BoxSelector = {
200
+ type: 'BoxSelector';
201
+ unit?: 'percent' | 'pixel';
202
+ x: number;
203
+ y: number;
204
+ width: number;
205
+ height: number;
206
+ };
207
+ declare type TemporalSelector = {
208
+ type: 'TemporalSelector';
209
+ startTime: number;
210
+ endTime?: number;
211
+ };
212
+ declare type TemporalBoxSelector = {
213
+ type: 'TemporalBoxSelector';
214
+ x: number;
215
+ y: number;
216
+ width: number;
217
+ height: number;
218
+ startTime: number;
219
+ endTime?: number;
220
+ };
221
+ declare type SupportedSelectors = TemporalSelector | BoxSelector | TemporalBoxSelector;
222
+
223
+ declare type ImageWithOptionalService = {
224
+ id: string;
225
+ type: 'Image';
226
+ service?: ImageService;
227
+ width?: number;
228
+ height?: number;
229
+ sizes?: Array<{
230
+ width: number;
231
+ height: number;
232
+ }>;
233
+ target: BoxSelector | TemporalBoxSelector;
234
+ selector: BoxSelector;
235
+ };
236
+ declare type SingleAudio = {
237
+ type: 'Sound';
238
+ url: string;
239
+ format: string;
240
+ duration: number;
241
+ target: TemporalSelector;
242
+ selector: TemporalSelector;
243
+ };
244
+ declare type SingleVideo = {
245
+ type: 'Video';
246
+ url: string;
247
+ format: string;
248
+ duration: number;
249
+ target: TemporalBoxSelector;
250
+ selector: TemporalBoxSelector;
251
+ };
252
+ declare type AudioSequence = {
253
+ type: 'SoundSequence';
254
+ items: SingleAudio[];
255
+ };
256
+ declare type VideoSequence = {
257
+ type: 'VideoSequence';
258
+ items: SingleVideo[];
259
+ };
260
+ declare type AnnotationPageDescription = {
261
+ pages: AnnotationPage[];
262
+ };
263
+
264
+ declare type SingleChoice = {
265
+ type: 'single-choice';
266
+ label?: InternationalString;
267
+ items: Array<{
268
+ id: string;
269
+ label?: InternationalString;
270
+ selected?: true;
271
+ }>;
272
+ };
273
+ declare type ComplexChoice = {
274
+ type: 'complex-choice';
275
+ items: SingleChoice[];
276
+ };
277
+ declare type ChoiceDescription = SingleChoice | ComplexChoice;
278
+
279
+ declare type SingleImageStrategy = {
280
+ type: 'images';
281
+ image: ImageWithOptionalService;
282
+ images: Array<ImageWithOptionalService>;
283
+ choice?: ChoiceDescription;
284
+ annotations?: AnnotationPageDescription;
285
+ };
286
+ declare type MediaStrategy = {
287
+ type: 'media';
288
+ media: SingleAudio | SingleVideo | AudioSequence | VideoSequence;
289
+ choice?: ChoiceDescription;
290
+ annotations?: AnnotationPageDescription;
291
+ };
292
+ declare type ComplexTimelineStrategy = {
293
+ type: 'complex-timeline';
294
+ items: Array<ImageWithOptionalService | SingleAudio | SingleVideo>;
295
+ choice?: ChoiceDescription;
296
+ annotations?: AnnotationPageDescription;
297
+ };
298
+ declare type UnknownStrategy = {
299
+ type: 'unknown';
300
+ reason?: string;
301
+ annotations?: AnnotationPageDescription;
302
+ };
303
+ declare type RenderingStrategy = SingleImageStrategy | MediaStrategy | ComplexTimelineStrategy | UnknownStrategy;
304
+
305
+ declare type StrategyActions = {
306
+ makeChoice: (id: string, options?: {
307
+ deselectOthers?: boolean;
308
+ deselect?: boolean;
309
+ }) => void;
310
+ };
311
+ declare type UseRenderingStrategy = [RenderingStrategy, StrategyActions];
312
+ declare type UseRenderingStrategyOptions = {
313
+ strategies?: Array<RenderingStrategy['type']>;
314
+ annotationPageManagerId?: string;
315
+ defaultChoices?: string[];
316
+ };
317
+ declare function useRenderingStrategy(options?: UseRenderingStrategyOptions): UseRenderingStrategy;
318
+
319
+ declare type SimpleViewerContext = {
320
+ setCurrentCanvasId: (newId: string | ((prev: string) => string)) => void;
321
+ setCurrentCanvasIndex: (newId: number | ((prev: number) => number)) => void;
322
+ currentCanvasIndex: number;
323
+ pagingView: boolean;
324
+ totalCanvases: number;
325
+ nextCanvas: () => void;
326
+ previousCanvas: () => void;
327
+ };
328
+ declare const SimpleViewerReactContext: React.Context<SimpleViewerContext>;
329
+ declare const SimpleViewerProvider: FC<{
330
+ manifest: string;
331
+ }>;
332
+ declare function useSimpleViewer(): SimpleViewerContext;
333
+
334
+ declare type SupportedTarget = {
335
+ type: 'SpecificResource';
336
+ source: ExternalWebResource | {
337
+ id: string;
338
+ type: 'Unknown' | 'Canvas' | 'Range' | 'Manifest';
339
+ partOf?: Array<{
340
+ id: string;
341
+ type: string;
342
+ }>;
343
+ };
344
+ purpose?: string;
345
+ selector: SupportedSelectors | null;
346
+ selectors: SupportedSelectors[];
347
+ };
348
+ declare function expandTarget(target: W3CAnnotationTarget | W3CAnnotationTarget[], options?: {
349
+ typeMap?: Record<string, string>;
350
+ }): SupportedTarget;
351
+
352
+ declare function flattenAnnotationPageIds({ canvas, manifest, all, canvases, }: {
353
+ manifest?: ManifestNormalized;
354
+ canvas?: CanvasNormalized;
355
+ canvases?: CanvasNormalized[];
356
+ all?: boolean;
357
+ }): string[];
358
+
359
+ declare type ParsedSelector = {
360
+ selector: SupportedSelectors | null;
361
+ selectors: SupportedSelectors[];
362
+ };
363
+ declare function parseSelector(source: Selector | Selector[]): ParsedSelector;
364
+
365
+ declare function parseSpecificResource(resource: ContentResource): any[];
366
+ declare function getPaintables(vault: Vault, paintingAnnotations: AnnotationNormalized[]): {
367
+ types: string[];
368
+ items: {
369
+ type: string;
370
+ resource: IIIFExternalWebResource | SpecificResource;
371
+ target: any;
372
+ selector: any;
373
+ }[];
374
+ };
375
+
376
+ export { AnnotationContext, AnnotationPageDescription, AudioSequence, BoxSelector, CanvasContext, ChoiceDescription, CollectionContext, ComplexChoice, ComplexTimelineStrategy, ContextBridge, ImageServiceLoaderContext, ImageWithOptionalService, ManifestContext, MediaStrategy, ParsedSelector, RangeContext, ReactVaultContext, RenderingStrategy, ResourceContextType, ResourceProvider, ResourceReactContext, SimpleViewerProvider, SimpleViewerReactContext, SingleAudio, SingleChoice, SingleImageStrategy, SingleVideo, StrategyActions, SupportedSelectors, SupportedTarget, TemporalBoxSelector, TemporalSelector, UnknownStrategy, UseRenderingStrategy, UseRenderingStrategyOptions, VaultProvider, VideoSequence, VisibleCanvasReactContext, expandTarget, flattenAnnotationPageIds, getPaintables, parseSelector, parseSpecificResource, useAnnotation, useAnnotationPageManager, useAnnotationsAtTime, useCanvas, useCanvasClock, useCollection, useContextBridge, useDispatch, useEventListener, useExternalCollection, useExternalManifest, useImageService, useImageServiceLoader, useImageTile, useLoadImageService, useManifest, usePaintingAnnotations, useRange, useRenderingStrategy, useResourceContext, useResourceEvents, useResources, useSearchService, useSimpleViewer, useStyles, useThumbnail, useVault, useVaultEffect, useVaultSelector, useVisibleCanvases };
@@ -0,0 +1,27 @@
1
+ (function(g,v){typeof exports=="object"&&typeof module<"u"?v(exports,require("react"),require("@iiif/vault")):typeof define=="function"&&define.amd?define(["exports","react","@iiif/vault"],v):(g=typeof globalThis<"u"?globalThis:g||self,v(g.ReactIIIFVault={},g.React,g.IIIFVault))})(this,function(g,v,be){"use strict";function In(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var I=In(v),_n=Object.defineProperty,Ce=Object.getOwnPropertySymbols,On=Object.prototype.hasOwnProperty,bn=Object.prototype.propertyIsEnumerable,Ee=(e,t,n)=>t in e?_n(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,xe=(e,t)=>{for(var n in t||(t={}))On.call(t,n)&&Ee(e,n,t[n]);if(Ce)for(var n of Ce(t))bn.call(t,n)&&Ee(e,n,t[n]);return e};const Cn={collection:void 0,manifest:void 0,range:void 0,canvas:void 0,annotation:void 0},ee=I.default.createContext(Cn),R=()=>v.useContext(ee),$=({value:e,children:t})=>{const n=R(),i=v.useMemo(()=>xe(xe({},n),e),[e,n]);return I.default.createElement(ee.Provider,{value:i},t)},En=({annotation:e,children:t})=>I.default.createElement($,{value:{annotation:e}},t),Pe=({canvas:e,children:t})=>I.default.createElement($,{value:{canvas:e}},t),xn=({collection:e,children:t})=>I.default.createElement($,{value:{collection:e}},t),Fe=({manifest:e,children:t})=>I.default.createElement($,{value:{manifest:e}},t),Pn=({range:e,children:t})=>I.default.createElement($,{value:{range:e}},t),te=I.default.createContext({vault:null,setVaultInstance:e=>{}}),Ae=({vault:e,vaultOptions:t,resources:n,children:i})=>{const[o,r]=v.useState(()=>e||(t?new be.Vault(t):new be.Vault));return I.default.createElement(te.Provider,{value:{vault:o,setVaultInstance:r}},I.default.createElement($,{value:n||{}},i))};function j(){return j=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},j.apply(this,arguments)}function ce(e,t){if(e==null)return{};var n={},i=Object.keys(e),o,r;for(r=0;r<i.length;r++)o=i[r],!(t.indexOf(o)>=0)&&(n[o]=e[o]);return n}var ue="loading",le="error",Me="success",Fn=0,An=function(){return Fn++},Mn={},ne=typeof window>"u",T=function(){},jn=function(t){return t},fe=console||{error:T,warn:T,log:T};function Ln(){var e=I.default.useRef(null);return e.current===null&&(e.current=An()),e.current}function Tn(e){var t=I.default.useRef();return t.current=e,I.default.useCallback(function(){return t.current},[])}function he(e,t){return typeof e=="function"?e(t):e}function kn(e,t){return je(t)?Object.assign.apply(Object,[{}].concat(Object.keys(t).sort().map(function(n){var i;return i={},i[n]=t[n],i}))):t}function Vn(e){return JSON.stringify(e,kn)}function je(e){return e&&typeof e=="object"&&!Array.isArray(e)}function Le(e,t){return e===t?!0:typeof e!=typeof t?!1:typeof e=="object"?!Object.keys(t).some(function(n){return!Le(e[n],t[n])}):!1}function de(){return typeof document>"u"||document.visibilityState===void 0||document.visibilityState==="visible"||document.visibilityState==="prerender"}function Rn(){return navigator.onLine===void 0||navigator.onLine}function Te(e){if(je(e[0]))if(e[0].hasOwnProperty("queryKey")&&e[0].hasOwnProperty("queryFn")){var t=e[0],n=t.queryKey,i=t.variables,o=i===void 0?[]:i,r=t.queryFn,a=t.config,s=a===void 0?{}:a;return[n,o,r,s]}else throw new Error("queryKey and queryFn keys are required.");if(typeof e[2]=="function"){var u=e[0],l=e[1],f=l===void 0?[]:l,d=e[2],m=e[3],p=m===void 0?{}:m;return[u,f,d,p]}var c=e[0],h=e[1],w=e[2],y=w===void 0?{}:w;return[c,[],h,y]}function $n(e){var t=I.default.useRef(!1);return I.default[ne?"useEffect":"useLayoutEffect"](function(){return t.current=!0,function(){return t.current=!1}},[]),I.default.useCallback(function(){return t.current?e.apply(void 0,arguments):void 0},[e])}function Dn(e){if((e.config.suspense||e.config.useErrorBoundary)&&e.status===le)throw setTimeout(function(){e.query.state.status="loading"}),e.error;if(e.config.suspense&&e.status===ue)throw e.query.wasSuspended=!0,e.refetch()}function pe(e,t){if(e===t)return!0;if(e&&t&&typeof e=="object"&&typeof t=="object"){var n,i,o;if(Array.isArray(e)){if(n=e.length,n!=t.length)return!1;for(i=n;i--!==0;)if(!pe(e[i],t[i]))return!1;return!0}if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===t.valueOf();if(o=Object.keys(e),n=o.length,n!==Object.keys(t).length)return!1;for(i=n;i--!==0;)if(!Object.prototype.hasOwnProperty.call(t,o[i]))return!1;for(i=n;i--!==0;){var r=o[i];if(!pe(e[r],t[r]))return!1}return!0}return e!==e&&t!==t}var qn=I.default.createContext(),Wn={retry:3,retryDelay:function(t){return Math.min(1e3*Math.pow(2,t),3e4)},staleTime:0,cacheTime:5*60*1e3,refetchAllOnWindowFocus:!0,refetchInterval:!1,suspense:!1,queryKeySerializerFn:ke,queryFnParamsFilter:jn,throwOnError:!1,useErrorBoundary:void 0,onMutate:T,onSuccess:T,onError:T,onSettled:T,refetchOnMount:!0,isDataEqual:pe},U={current:Wn};function Nn(){return I.default.useContext(qn)||U.current}function ke(e){if(!e)return[];if(typeof e=="function")try{return ke(e())}catch{return[]}typeof e=="string"&&(e=[e]);var t=Vn(e);return e=JSON.parse(t),[t,e]}function D(e,t,n){return n?t?t(e):e:((!e||!e.then)&&(e=Promise.resolve(e)),t?e.then(t):e)}function J(e,t){try{var n=e()}catch(i){return t(i)}return n&&n.then?n.then(void 0,t):n}function q(e){return function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];try{return Promise.resolve(e.apply(this,t))}catch(i){return Promise.reject(i)}}}function Ve(e,t){var n=e();return n&&n.then?n.then(t):t(n)}var Re=Qn(),zn=I.default.createContext(Re),Gn=[Re];function Hn(){return I.default.useContext(zn)}var $e={},De={},qe={},We={},Ne={},ze={},Ge={},He={};function Qn(){var e=[],t={queries:{},isFetching:0},n=function(){t.isFetching=Object.values(t.queries).reduce(function(a,s){return s.state.isFetching?a+1:a},0),e.forEach(function(a){return a(t)})};t.subscribe=function(r){return e.push(r),function(){e.splice(e.indexOf(r),1)}},t.clear=function(){Object.values(t.queries).forEach(function(r){return r.clear()}),t.queries={},n()};var i=function(a,s){var u=s===void 0?{}:s,l=u.exact;if(typeof a!="function"){var f=U.current.queryKeySerializerFn(a),d=f[0],m=f[1];a=function(c){return l?c.queryHash===d:Le(c.queryKey,m)}}return Object.values(t.queries).filter(a)};t.getQueries=i,t.getQuery=function(r){return i(r,{exact:!0})[0]},t.getQueryData=function(r){var a;return(a=t.getQuery(r))==null?void 0:a.state.data},t.removeQueries=function(r,a){var s=a===void 0?{}:a,u=s.exact,l=i(r,{exact:u});l.forEach(function(f){clearTimeout(f.staleTimeout),delete t.queries[f.queryHash]}),l.length&&n()},t.cancelQueries=function(r,a){var s=a===void 0?{}:a,u=s.exact,l=i(r,{exact:u});l.forEach(function(f){f.cancel()}),l.length&&n()},t.refetchQueries=q(function(r,a){var s=a===void 0?{}:a,u=s.exact,l=s.throwOnError,f=s.force,d=r===!0?Object.values(t.queries):i(r,{exact:u});return J(function(){return D(Promise.all(d.map(function(m){return m.fetch({force:f})})))},function(m){if(l)throw m})}),t._buildQuery=function(r,a,s,u){var l=u.queryKeySerializerFn(r),f=l[0],d=l[1],m=t.queries[f];return m?(Object.assign(m,{queryVariables:a,queryFn:s}),m.config=j({},m.config,u)):(m=o({cache:t,queryKey:d,queryHash:f,queryVariables:a,queryFn:s,config:u}),!ne&&m.state.data&&(m.scheduleStaleTimeout(),m.heal(),m.scheduleGarbageCollection()),m.queryHash&&(ne||(t.queries[f]=m,setTimeout(function(){n()})))),m},t.prefetchQuery=q(function(){for(var r=!1,a=arguments.length,s=new Array(a),u=0;u<a;u++)s[u]=arguments[u];var l=Te(s),f=l[0],d=l[1],m=l[2],p=l[3],c=p.force,h=ce(p,["force"]);h=j({},U.current,h);var w=t._buildQuery(f,d,m,h);return Ve(function(){if(w.state.isStale||c)return J(function(){return D(w.fetch({force:c}),function(y){return w.wasPrefetched=!0,r=!0,y})},function(y){if(h.throwOnError)throw y})},function(y){return r?y:w.state.data})}),t.setQueryData=function(r,a,s){var u=s===void 0?{}:s,l=u.exact,f=ce(u,["exact"]),d=i(r,{exact:l});!d.length&&typeof r!="function"&&(d=[t._buildQuery(r,void 0,function(){return Promise.resolve()},j({},U.current,f))]),d.forEach(function(m){return m.setData(a)})};function o(r){var a=r.cache,s=r.config.queryReducer||Bn,u=typeof r.queryHash>"u",l=typeof r.config.initialData=="function"?r.config.initialData():r.config.initialData,f=typeof l<"u",d=u?!0:!f,m=r.config.manual,p=u||m||f?Me:ue,c=j({},r,{instances:[],state:s(void 0,{type:$e,initialStatus:p,initialData:l,hasInitialData:f,isStale:d,manual:m})}),h=function(S){c.state=s(c.state,S),c.instances.forEach(function(_){return _.onStateUpdate(c.state)}),n()};c.scheduleStaleTimeout=function(){c.config.staleTime!==1/0&&(c.staleTimeout=setTimeout(function(){a.getQuery(c.queryKey)&&h({type:qe})},c.config.staleTime))},c.scheduleGarbageCollection=function(){c.config.cacheTime!==1/0&&(h({type:We}),c.cacheTimeout=setTimeout(function(){t.removeQueries(function(y){return y.state.markedForGarbageCollection&&y.queryHash===c.queryHash})},typeof c.state.data>"u"&&c.state.status!=="error"?0:c.config.cacheTime))},c.heal=function(){clearTimeout(c.cacheTimeout),c.cancelled=null},c.cancel=function(){c.cancelled=Mn,c.cancelPromises&&c.cancelPromises(),delete c.promise,n()},c.updateInstance=function(y){var S=c.instances.find(function(_){return _.id===y.id});S?Object.assign(S,y):(S=j({onStateUpdate:T},y),c.instances.push(y))},c.subscribe=function(y){return c.heal(),function(){c.instances=c.instances.filter(function(S){return S.id!==y}),c.instances.length||(c.cancel(),c.scheduleGarbageCollection())}};var w=q(function(y){for(var S=arguments.length,_=new Array(S>1?S-1:0),O=1;O<S;O++)_[O-1]=arguments[O];return J(function(){var P=y.apply(void 0,c.config.queryFnParamsFilter(_));return c.cancelPromises=function(){return P.cancel==null?void 0:P.cancel()},D(P,function(F){if(delete c.shouldContinueRetryOnFocus,delete c.cancelPromises,c.cancelled)throw c.cancelled;return F})},function(P){var F=!1;if(delete c.cancelPromises,c.cancelled)throw c.cancelled;return h({type:De}),Ve(function(){if(c.config.retry===!0||c.state.failureCount<=c.config.retry||typeof c.config.retry=="function"&&c.config.retry(c.state.failureCount,P)){if(!de())return c.shouldContinueRetryOnFocus=!0,F=!0,new Promise(T);delete c.shouldContinueRetryOnFocus;var b=he(c.config.retryDelay,c.state.failureCount);return F=!0,D(new Promise(function(C,M){setTimeout(q(function(){return c.cancelled?M(c.cancelled):J(function(){return D(w.apply(void 0,[y].concat(_)),function(L){if(c.cancelled)return M(c.cancelled);C(L)})},function(L){if(c.cancelled)return M(c.cancelled);M(L)})}),b)}))}},function(b){if(F)return b;throw P})})});return c.fetch=q(function(y){var S=y===void 0?{}:y,_=S.force,O=S.__queryFn,P=O===void 0?c.queryFn:O;if(!(!c.queryHash||!c.state.isStale&&!_))return c.promise||(c.promise=q(function(){c.cancelled=null;var F=[].concat(c.instances);return c.wasSuspended&&F.unshift(c.suspenseInstance),J(function(){return h({type:Ne}),D(w.apply(void 0,[P].concat(c.queryKey,c.queryVariables)),function(b){return c.setData(function(C){return c.config.isDataEqual(C,b)?C:b}),F.forEach(function(C){return C.onSuccess&&C.onSuccess(c.state.data)}),F.forEach(function(C){return C.onSettled&&C.onSettled(c.state.data,null)}),delete c.promise,b})},function(b){if(h({type:Ge,cancelled:b===c.cancelled,error:b}),delete c.promise,b!==c.cancelled)throw F.forEach(function(C){return C.onError&&C.onError(b)}),F.forEach(function(C){return C.onSettled&&C.onSettled(void 0,b)}),b})})()),c.promise}),c.setState=function(y){return h({type:He,updater:y})},c.setData=function(y){h({type:ze,updater:y}),clearTimeout(c.staleTimeout),c.scheduleStaleTimeout()},c.clear=function(){clearTimeout(c.staleTimeout),clearTimeout(c.cacheTimeout),c.cancel()},c}return t}function Bn(e,t){switch(t.type){case $e:return{status:t.initialStatus,error:null,isFetching:t.hasInitialData||t.manual?!1:t.initialStatus==="loading",canFetchMore:!1,failureCount:0,isStale:t.isStale,markedForGarbageCollection:!1,data:t.initialData,updatedAt:t.hasInitialData?Date.now():0};case De:return j({},e,{failureCount:e.failureCount+1});case qe:return j({},e,{isStale:!0});case We:return j({},e,{markedForGarbageCollection:!0});case Ne:return j({},e,{status:e.status===le?ue:e.status,isFetching:!0,failureCount:0});case ze:return j({},e,{status:Me,data:he(t.updater,e.data),error:null,isStale:!1,isFetching:!1,canFetchMore:t.canFetchMore,updatedAt:Date.now(),failureCount:0});case Ge:return j({},e,{isFetching:!1,isStale:!0},!t.cancelled&&{status:le,error:t.error});case He:return he(t.updater,e);default:throw new Error}}var Qe="visibilitychange",Be="focus",Un=function(){var t=U.current.refetchAllOnWindowFocus;de()&&Rn()&&Gn.forEach(function(n){return n.refetchQueries(function(i){return!i.instances.length||i.config.manual===!0?!1:i.shouldContinueRetryOnFocus?(delete i.promise,!0):typeof i.config.refetchOnWindowFocus>"u"?t:i.config.refetchOnWindowFocus}).catch(fe.error)})},ve;function Jn(e){ve&&ve(),ve=e(Un)}Jn(function(e){var t;if(!ne&&((t=window)==null?void 0:t.addEventListener))return window.addEventListener(Qe,e,!1),window.addEventListener(Be,e,!1),function(){window.removeEventListener(Qe,e),window.removeEventListener(Be,e)}});function Kn(e,t,n){return n?t?t(e):e:((!e||!e.then)&&(e=Promise.resolve(e)),t?e.then(t):e)}function Xn(e,t){try{var n=e()}catch(i){return t(i)}return n&&n.then?n.then(void 0,t):n}function Yn(e){return function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];try{return Promise.resolve(e.apply(this,t))}catch(i){return Promise.reject(i)}}}function Zn(e,t,n,i){i===void 0&&(i={});var o=Ln();i=j({},Nn(),i);var r=Hn(),a=I.default.useRef(),s=r._buildQuery(e,t,n,i),u=a.current&&typeof a.current.queryHash>"u"&&typeof s.queryHash>"u";u||(a.current=s);var l=a.current,f=I.default.useState(),d=f[1],m=$n(d),p=Tn(i),c=I.default.useCallback(Yn(function(h){var w=h===void 0?{}:h,y=w.throwOnError,S=ce(w,["throwOnError"]);return Xn(function(){return Kn(l.fetch(S))},function(_){if(y)throw _})}),[l]);return l.suspenseInstance={onSuccess:function(w){return p().onSuccess(w)},onError:function(w){return p().onError(w)},onSettled:function(w,y){return p().onSettled(w,y)}},I.default.useEffect(function(){return l.updateInstance({id:o,onStateUpdate:function(){return m({})},onSuccess:function(w){return p().onSuccess(w)},onError:function(w){return p().onError(w)},onSettled:function(w,y){return p().onSettled(w,y)}}),l.subscribe(o)},[p,o,l,m]),I.default.useEffect(function(){!p().manual&&!l.wasPrefetched&&!l.wasSuspended&&l.state.isStale&&(p().refetchOnMount||l.instances.length===1)&&c().catch(fe.error),l.wasPrefetched=!1,l.wasSuspended=!1},[p,l,c]),I.default.useEffect(function(){var h=a.current;if(i.refetchInterval&&(!h.currentRefetchInterval||i.refetchInterval<h.currentRefetchInterval))return h.currentRefetchInterval=i.refetchInterval,clearInterval(h.refetchIntervalId),h.refetchIntervalId=setInterval(function(){(de()||i.refetchIntervalInBackground)&&c().catch(fe.error)},i.refetchInterval),function(){clearInterval(h.refetchIntervalId),delete h.refetchIntervalId,delete h.currentRefetchInterval}},[i.refetchInterval,i.refetchIntervalInBackground,c]),j({},l.state,{config:i,query:l,refetch:c})}function ge(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var i=Zn.apply(void 0,Te(t));return Dn(i),i}const A=()=>{const{vault:e}=v.useContext(te);if(e===null)throw new Error("Vault not found. Ensure you have your provider set up correctly.");return e};var ei=Object.defineProperty,Ue=Object.getOwnPropertySymbols,ti=Object.prototype.hasOwnProperty,ni=Object.prototype.propertyIsEnumerable,Je=(e,t,n)=>t in e?ei(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ii=(e,t)=>{for(var n in t||(t={}))ti.call(t,n)&&Je(e,n,t[n]);if(Ue)for(var n of Ue(t))ni.call(t,n)&&Je(e,n,t[n]);return e},ri=(e,t,n)=>new Promise((i,o)=>{var r=u=>{try{s(n.next(u))}catch(l){o(l)}},a=u=>{try{s(n.throw(u))}catch(l){o(l)}},s=u=>u.done?i(u.value):Promise.resolve(u.value).then(r,a);s((n=n.apply(e,t)).next())});const Ke=(e,t={})=>{const n=A(),[i,o]=v.useState(e),r=v.useMemo(()=>n.get(e)||void 0,[e,n]),{data:a,error:s}=ge(["manifest",e],()=>ri(void 0,null,function*(){const u=r||(yield n.load(e));return u&&i!==u.id&&o(u.id),u}),ii({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,retry:!1,initialData:r},t));return{isLoaded:!!a,id:i,error:s,manifest:a}};function k(e,t=[]){const n=A(),[i,o]=v.useState(()=>e(n.getState(),n));return v.useEffect(()=>n.subscribe(r=>e(r,n),r=>{o(r)},!0),t),i}const K=I.default.createContext([]);function Xe(){const e=v.useContext(K);return k(t=>e.map(n=>t.iiif.entities.Canvas[n]).filter(Boolean),[e])}const ie=()=>{},X=v.createContext({setCurrentCanvasId:ie,setCurrentCanvasIndex:ie,nextCanvas:ie,previousCanvas:ie,currentCanvasIndex:-1,totalCanvases:0,pagingView:!0}),oi=e=>{const t=Ke(e.manifest),[n,i]=v.useState(""),[o,r]=v.useState([]),a=t.manifest&&t.manifest.behavior&&t.manifest.behavior.includes("paged");v.useEffect(()=>{var c,h;t.manifest&&(i((c=t.manifest.items[0])==null?void 0:c.id),r([(h=t.manifest.items[0])==null?void 0:h.id]))},[t.manifest,e.manifest]);const s=v.useMemo(()=>{var c;return((c=t.manifest)==null?void 0:c.items.map(h=>h.id))||[]},[t.manifest,e.manifest]),u=v.useMemo(()=>s.indexOf(n),[s,n]),l=v.useCallback(()=>{if(s.length&&n){if(u===-1||(s[u+2]?u+2===s.length:u===s.length))return;const c=a&&u!==0?s[u+2]:s[u+1],h=a?u!==0?s[u+3]:s[u+2]:null;c&&(i(c),r(h?[c,h]:[c]))}},[a,s,n,u]),f=v.useCallback(()=>{if(s.length&&n){if(u===0||u===-1)return;const c=a&&u!==1?s[u-2]:s[u-1],h=a&&u!==1?s[u-1]:null;c&&(i(c),r(h?[c,h]:[c]))}},[a,s,n,u]),d=v.useCallback(c=>{const h=a&&c%2===1?c-1:c,w=s[h],y=a&&h!==0?s[h+1]:null;w&&(i(w),r(S=>{const _=y?[w,y]:[w];if(S.length===S.length){for(let O=0;O<S.length;O++)if(S[O]!==_[O])return _;return S}return _}))},[a,s]),m=v.useCallback(c=>{const h=s.indexOf(c);h!==-1&&d(h)},[s,d]),p=v.useMemo(()=>({setCurrentCanvasId:m,nextCanvas:l,previousCanvas:f,currentCanvasIndex:u,totalCanvases:s.length,setCurrentCanvasIndex:d,pagingView:!0}),[l,f,u,s,d,m]);return!t.isLoaded||!t.manifest?I.default.createElement("div",null,"Loading..."):I.default.createElement(X.Provider,{value:p},I.default.createElement(K.Provider,{value:o},I.default.createElement(Fe,{manifest:t.manifest.id},I.default.createElement(Pe,{canvas:n},e.children))))};function ai(){return v.useContext(X)}function si(){return{VaultContext:v.useContext(te),ResourceContext:v.useContext(ee),SimpleViewerReactContext:v.useContext(X),VisibleCanvasReactContext:v.useContext(K)}}const ci=e=>I.default.createElement(Ae,{vault:e.bridge.VaultContext.vault||void 0,resources:e.bridge.ResourceContext},I.default.createElement(K.Provider,{value:e.bridge.VisibleCanvasReactContext},I.default.createElement(X.Provider,{value:e.bridge.SimpleViewerReactContext},e.children)));function W(e){return e.endsWith("info.json")?e:e.endsWith("/")?`${e}info.json`:`${e}/info.json`}function ui(e,t,n){const i=n.length,o=[];for(let r=0;r<i;r++){const s=n[r].width;o.push(e/s)}return o}function li(e,t,n){const i=n.length,o=[];for(let r=0;r<i;r++){const a=n[r];o.push({width:Math.floor(e/a),height:Math.floor(t/a)})}return o}const fi="http://library.stanford.edu/iiif/image-api/compliance.html#level0",Ye="http://library.stanford.edu/iiif/image-api/compliance.html#level1",Ze="http://library.stanford.edu/iiif/image-api/compliance.html#level2",hi="http://library.stanford.edu/iiif/image-api/conformance.html#level0",et="http://library.stanford.edu/iiif/image-api/conformance.html#level1",tt="http://library.stanford.edu/iiif/image-api/conformance.html#level2",di="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",nt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",it="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",pi="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",rt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",ot="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",vi="http://iiif.io/api/image/1/level0.json",gi="http://iiif.io/api/image/1/profiles/level0.json",at="http://iiif.io/api/image/1/level1.json",st="http://iiif.io/api/image/1/profiles/level1.json",ct="http://iiif.io/api/image/1/level2.json",ut="http://iiif.io/api/image/1/profiles/level2.json",mi="http://iiif.io/api/image/2/level0.json",yi="http://iiif.io/api/image/2/profiles/level0.json",lt="http://iiif.io/api/image/2/level1.json",ft="http://iiif.io/api/image/2/profiles/level1.json",ht="http://iiif.io/api/image/2/level2.json",dt="http://iiif.io/api/image/2/profiles/level2.json",wi="level0",pt="level1",vt="level2",Si="http://iiif.io/api/image/2/level0",gt="http://iiif.io/api/image/2/level1",mt="http://iiif.io/api/image/2/level2",Ii=[gt,mt,Ye,Ze,et,tt,nt,it,rt,ot,at,st,ct,ut,lt,ft,ht,dt,pt,vt],_i=[Si,gt,mt,fi,Ye,Ze,hi,et,tt,di,nt,it,pi,rt,ot,vi,gi,at,st,ct,ut,mi,yi,lt,ft,ht,dt,wi,pt,vt];function E(e){if(e["@id"])return e["@id"];if(e.id)return e.id}function me(e){if(!e||!e.profile||!E(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const n of t)if(typeof n=="string"&&_i.indexOf(n)!==-1)return!0;return!1}function Oi(e){if(!me(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const n of t)if(typeof n=="string"){if(Ii.indexOf(n)!==-1)return!0}else{const i=n.supports||[];if(i.indexOf("regionByPx")!==-1&&(i.indexOf("sizeByW")!==-1||i.indexOf("sizeByWh")!==-1))return!0}return!1}function bi(e){if(!Oi(e))return[];const t=[],n=Array.isArray(e.profile)?e.profile:[e.profile],i=n.length;for(let o=0;o<i;o++){const r=n[o];if(typeof r!="string"&&(r.maxHeight||r.maxWidth))return[{id:E(e),type:"variable",minWidth:0,minHeight:0,maxHeight:r.maxHeight||r.maxWidth,maxWidth:r.maxWidth||r.maxHeight}]}if(e.tiles){const o=e.tiles.length;for(let r=0;r<o;r++){const a=e.tiles[r];(a.height||a.width)&&t.push({id:E(e),type:"variable",minHeight:0,minWidth:0,maxHeight:a.height||a.width,maxWidth:a.width})}}return t}function yt(e){const t=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,n=e.match(t);if(n){const i=n[1],o=parseInt(n[4],10),r=parseInt(n[5],10),a=n[7];if((i==="max"||i==="full")&&o&&r&&a)return{type:"fixed",id:e,height:r,width:o}}return{type:"unknown",id:e}}function Ci(e){if(e["@type"])return e["@type"];if(e.type)return e.type}function Ei(e){if(typeof e=="string")return yt(e);const t=Ci(e);if(t!=="Image"&&t!=="sc:Image")return null;const n=e,i=E(n);return i?i&&n.width&&n.height?{id:i,type:"fixed",width:n.width,height:n.height,unsafe:!0}:yt(i):null}function xi(e){return me(e)?(e&&e.sizes?e.sizes:[]).map(t=>({id:E(e),type:"fixed-service",height:t.height,width:t.width})):[]}function wt(e){const t=[],n=e.length;for(let i=0;i<n;i++){const o=xi(e[i]);o.length&&t.push(...o);const r=bi(e[i]);r.length&&t.push(...r)}return t}function Y(e){const t=e.service?Array.isArray(e.service)?e.service:[e.service]:[],n=t.length,i=[];for(let o=0;o<n;o++)me(t[o])&&i.push(t[o]);return i}function Pi(e,t=!0,n){const i=[],o=Ei(e);if(o===null)return i;const r=e;if(i.push(o),t&&r.width&&r.height){const a=[],s=Y(r);for(const u of s){const l={id:E(u),width:r.width,height:r.height};if(n.canLoadSync(l)){const f=n.loadServiceSync(l);f&&(f.height||(f.height=r.height),f.width||(f.width=r.width),a.push(...wt([f])))}}if(a.length)return i.push(...a),i}return r.service&&i.push(...wt(r.service)),i}function ye(e,t,n){return{id:[W(E(e)).slice(0,-10),"full",[t,n||""].join(","),0,"default.jpg"].join("/"),type:"fixed",width:t,height:n||e.height/e.width*t,unsafe:e.width>t}}function N(e){const t=e.replace(/(https?:\/\/)?(www.)?/i,"");return t.indexOf("/")!==-1?t.split("/")[0]:t}function Fi(e,t,n){const i=e.width?e.width:e.maxWidth;return n.height<=e.maxHeight&&n.width<=e.maxWidth&&n.height>=e.minHeight&&n.width>=e.minWidth&&(!t||Math.abs(n.width-i)<Math.abs(t.width-i))}function Ai(e,t){const n=[],i=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},e),o=[],r=[];let a=null;const s=(l,f)=>{if(Fi(i,f,l)){if(i.preferFixedSize&&l.unsafe){r.push(l);return}i.returnAllOptions&&f&&r.push(f),a=l}else i.returnAllOptions&&r.push(l)},u=t.length;for(let l=0;l<u;l++){const f=t[l](),d=f.length;for(let m=0;m<d;m++){const p=f[m];if(p.type==="unknown"&&i.atAnyCost&&o.push(p),p.type==="fixed"&&(p.unsafe?o.push(p):s(p,a)),p.type==="fixed-service")if(i.unsafeImageService){const c=ye(p,i.width,i.height);s(c,a)}else{const c=ye(p,p.width,p.height);s(c,a)}if(p.type==="variable"&&p.maxWidth){const c=ye({id:p.id,type:"fixed-service",width:p.maxWidth,height:p.maxWidth},p.maxWidth);s(c,a)}}if(a&&!i.returnAllOptions){if(a.unsafe||i.allowUnsafe)continue;break}}return i.atAnyCost&&r.length===0?{best:a||o[0],fallback:o.slice(1),log:n}:i.returnAllOptions?{best:i.atAnyCost?a||r[0]||o[0]:a||r[0],fallback:[...r,...o],log:n}:{best:a||r[0]||null,fallback:a?r:r.slice(1),log:n}}function Mi(e,t,n){const i=e>t?e:t,o=n.length,r=[];for(let a=0;a<o;a++){const s=n[a];let u=s.scaleFactors[0],l=i/u;const f=[u];for(;l>=s.width;)u=u*2,f.push(u),l=l/2;r.push(Object.assign(Object.assign({},s),{scaleFactors:f}))}return r}function ji(e,t){if(e.length!==t.length)return!1;if(e.length===0&&t.length===0)return!0;const n=e.length;let i=!0;for(let r=0;r<n;r++){const a=e[r],s=t[r];if(a.width!==s.width||a.height!==s.height){i=!1;break}}if(i)return!0;let o=0;for(let r=0;r<n;r++)for(let a=0;a<n;a++)if(e[r].width===t[a].width&&e[r].height===t[a].height){o++;break}return o===n}/*! *****************************************************************************
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4
+ this file except in compliance with the License. You may obtain a copy of the
5
+ License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9
+ WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10
+ MERCHANTABLITY OR NON-INFRINGEMENT.
11
+
12
+ See the Apache Version 2.0 License for specific language governing permissions
13
+ and limitations under the License.
14
+ ***************************************************************************** */function z(e,t,n,i){function o(r){return r instanceof n?r:new n(function(a){a(r)})}return new(n||(n=Promise))(function(r,a){function s(f){try{l(i.next(f))}catch(d){a(d)}}function u(f){try{l(i.throw(f))}catch(d){a(d)}}function l(f){f.done?r(f.value):o(f.value).then(s,u)}l((i=i.apply(e,t||[])).next())})}class St{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(t){Object.assign(this.config,t)}sample(t,n,i=!0){const o=N(E(t)),r=W(E(t)),a=this.knownImageServers[o];return this.imageServices[r]=Object.assign(t,{real:!0}),a?this.verify(t):(this.knownImageServers[o]={verifications:0,malformed:!1,root:o,preLoaded:i,sampledId:E(t),verified:!1,server:null,result:{context:t["@context"]||[],sampledProfile:t.profile,resourceServiceRatio:n&&t.height?n.height/t.height:1,sampledSizes:t.sizes||[],sizeRatios:ui(t.width,t.height,t.sizes||[]),sampledTiles:t.tiles||[]}},!0)}preLoad(t,n=!0){this.knownImageServers[t.root]=t,n&&(this.knownImageServers[t.root].malformed=!1,this.knownImageServers[t.root].verifications=this.config.verificationsRequired)}predict(t,n=!1,i=!1){const o=N(E(t)),r=this.knownImageServers[o];if(!r||!r.result||!i&&(r.malformed||r.verifications<this.config.verificationsRequired))return null;const a=W(E(t));return this.imageServices[a]||(this.imageServices[a]={"@context":r.result.context,"@id":E(t),id:E(t),protocol:"http://iiif.io/api/image",tiles:Mi(t.width,t.height,r.result.sampledTiles),sizes:li(Math.floor(t.width/r.result.resourceServiceRatio),Math.floor(t.height/r.result.resourceServiceRatio),r.result.sizeRatios),profile:r.result.sampledProfile,height:t.height,width:t.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(t,n,i=!0,o=[]){return z(this,void 0,void 0,function*(){const r=yield this.getImageCandidates(t,i);return Ai(n,[()=>o,()=>r])})}getImageCandidates(t,n=!0){return z(this,void 0,void 0,function*(){const i=t;if(n&&i.height&&i.width){const o=Y(i);for(const r of o){const a={id:E(r),width:r.width?r.width:i.width,height:r.height?r.height:i.height};yield this.loadService(a)}}return Pi(t,n,this)})}verify(t){return z(this,void 0,void 0,function*(){const n=this.predict(t,!1,!0),i=yield this.fetchService(E(t));if(!n)return!1;const o=n.height===i.height&&n.width===i.width&&n["@context"]===i["@context"]&&ji(n.sizes||[],i.sizes||[]);if(o){const r=N(E(t));this.knownImageServers[r].verifications+=1,this.knownImageServers[r].verifications>=this.config.verificationsRequired&&(this.knownImageServers[r].verified=!0)}return o})}canLoadSync(t){const n=typeof t=="string"?t:E(t),i=W(n);if(this.imageServices[i])return!0;const o=this.knownImageServers[N(n)];return o&&!o.malformed&&o.verifications>=this.config.verificationsRequired}markAsMalformed(t){return z(this,void 0,void 0,function*(){return this.knownImageServers[N(E(t))].malformed=!0,this.loadService(t,!0)})}fetchService(t,n=!1){return z(this,void 0,void 0,function*(){const i=W(t);if(this.imageServices[i]&&(!n||this.imageServices[i].real))return this.imageServices[i];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const o=yield fetch(i).then(r=>r.json());return!o.id&&o["@id"]&&(o.id=o["@id"]),o.id!==t&&(o.id=t,o["@id"]&&(o["@id"]=t)),this.imageServices[i]=Object.assign(o,{real:!0}),this.imageServices[i]})}loadService(t,n=!1){return z(this,void 0,void 0,function*(){if(!this.config.disableThrottling)for(;this.fetchingCount>=this.config.verificationsRequired;)yield new Promise(r=>setTimeout(r,500));const i=this.knownImageServers[N(E(t))];if(i&&!i.malformed&&!n){yield i.result;const r=this.loadServiceSync(t);if(r)return r}this.fetchingCount++;const o=yield this.fetchService(E(t),n);return this.fetchingCount--,o.real&&this.sample(o,t),o})}loadServiceSync(t){const n=W(E(t));return this.imageServices[n]?this.imageServices[n]:this.predict(t)}}new St;const It=I.default.createContext(new St);function re(){return v.useContext(It)}const Li=/&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/,Ti=/&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;function oe(e){if(Array.isArray(e))return e.reduce((t,n)=>{const{selector:i,selectors:o}=oe(n);return i&&(t.selector||(t.selector=i),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?oe({type:"FragmentSelector",value:n}):{selector:null,selectors:[]}}if(e.type==="PointSelector"&&(e.t||e.t===0)){const t={type:"TemporalSelector",startTime:e.t};return{selector:t,selectors:[t]}}if(e.type==="FragmentSelector"){const t=Li.exec(e.value);if(t){const i={type:"BoxSelector",unit:t[2]==="percent:"?"percent":"pixel",x:parseFloat(t[3]),y:parseFloat(t[4]),width:parseFloat(t[5]),height:parseFloat(t[6])};return{selector:i,selectors:[i]}}const n=e.value.match(Ti);if(n){const i={type:"TemporalSelector",startTime:n[4]?parseFloat(n[4]):0,endTime:n[7]?parseFloat(n[7]):void 0};return{selector:i,selectors:[i]}}return{selector:null,selectors:[]}}return{selector:null,selectors:[]}}var ki=Object.defineProperty,Vi=Object.defineProperties,Ri=Object.getOwnPropertyDescriptors,_t=Object.getOwnPropertySymbols,$i=Object.prototype.hasOwnProperty,Di=Object.prototype.propertyIsEnumerable,Ot=(e,t,n)=>t in e?ki(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,bt=(e,t)=>{for(var n in t||(t={}))$i.call(t,n)&&Ot(e,n,t[n]);if(_t)for(var n of _t(t))Di.call(t,n)&&Ot(e,n,t[n]);return e},Ct=(e,t)=>Vi(e,Ri(t));function V(e,t={}){if(Array.isArray(e))return V(e[0]);if(typeof e=="string"){const[n,i]=e.split("#");return i?V({type:"SpecificResource",source:{id:n,type:"Unknown"},selector:{type:"FragmentSelector",value:i}}):{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 V(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:i}=e.selector?oe(e.selector):{selector:null,selectors:[]};return{type:"SpecificResource",source:e.source,selector:n,selectors:i}}if(e.id){e.type==="Canvas"&&e.partOf&&typeof e.partOf=="string"&&(e.partOf=[{id:e.partOf,type:"Manifest"}]);const[n,i]=e.id.split("#");return i?V({type:"SpecificResource",source:Ct(bt({},e),{id:n}),selector:{type:"FragmentSelector",value:i}}):{type:"SpecificResource",source:Ct(bt({},e),{id:n}),selector:null,selectors:[]}}return{type:"SpecificResource",source:e,selector:null,selectors:[]}}var qi=Object.defineProperty,Wi=Object.defineProperties,Ni=Object.getOwnPropertyDescriptors,Et=Object.getOwnPropertySymbols,zi=Object.prototype.hasOwnProperty,Gi=Object.prototype.propertyIsEnumerable,xt=(e,t,n)=>t in e?qi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Hi=(e,t)=>{for(var n in t||(t={}))zi.call(t,n)&&xt(e,n,t[n]);if(Et)for(var n of Et(t))Gi.call(t,n)&&xt(e,n,t[n]);return e},Qi=(e,t)=>Wi(e,Ni(t));function Bi(e={},t=[]){const{id:n,selector:i}=e,o=R(),r=A(),a=n||o.annotation,s=k(l=>a?l.iiif.entities.Annotation[a]:void 0,[a]),u=k(l=>s&&s.body?s.body.map(f=>f?l.iiif.entities[f.type][f.id]:null).filter(Boolean):[],[s]);return v.useMemo(()=>{if(!s)return;const l=Qi(Hi({},s),{body:u,target:V(s.target,{typeMap:r.getState().iiif.mapping})});return i?i(l):l},[s,i,u,...t])}function Z(e={},t=[]){const{id:n,selector:i}=e,o=R(),r=A(),a=n||o.manifest,s=a?r.select(u=>u.iiif.entities.Manifest[a]):void 0;return v.useMemo(()=>{if(!!s)return i?i(s):s},[s,i,...t])}function G(e={},t=[]){const{id:n,selector:i}=e,o=R(),r=A(),a=n||o.canvas,s=a?r.select(u=>u.iiif.entities.Canvas[a]):void 0;return v.useMemo(()=>{if(!!s)return i?i(s):s},[s,i,...t])}function Ui(e,t){var n;const i=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return i?i.annotationPageManager:null}function Ji(e,t){return k(n=>{const i=[];if(!e)return i;const o=Object.keys(n.iiif.entities.AnnotationPage);for(const r of o)if(!t||t.indexOf(r)!==-1){const a=Ui(n,r);a&&a.views&&a.views[e]&&i.push(r)}return i},[e])}function Pt({canvas:e,manifest:t,all:n,canvases:i}){const o=[];if(t)for(const r of t.annotations)o.indexOf(r.id)===-1&&o.push(r.id);if(n){if(i&&i.length)for(const r of i)for(const a of r.annotations)o.indexOf(a.id)===-1&&o.push(a.id)}else if(e)for(const r of e.annotations)o.indexOf(r.id)===-1&&o.push(r.id);return o}var Ki=Object.defineProperty,Xi=Object.defineProperties,Yi=Object.getOwnPropertyDescriptors,Ft=Object.getOwnPropertySymbols,Zi=Object.prototype.hasOwnProperty,er=Object.prototype.propertyIsEnumerable,At=(e,t,n)=>t in e?Ki(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Mt=(e,t)=>{for(var n in t||(t={}))Zi.call(t,n)&&At(e,n,t[n]);if(Ft)for(var n of Ft(t))er.call(t,n)&&At(e,n,t[n]);return e},jt=(e,t)=>Xi(e,Yi(t));function tr(e,t){var n;const i=(n=e==null?void 0:e.iiif)==null?void 0:n.meta[t];return i?i.annotationPageManager:null}function Lt(e,t={}){const n=A(),i=Z(),o=G(),r=Xe(),a=v.useMemo(()=>Pt({all:t.all,manifest:i,canvas:o,canvases:r}),[t.all,o,r,i]),s=Ji(e,t.all?void 0:a),u=v.useCallback(f=>{!e||n.setMetaValue([f,"annotationPageManager","views"],d=>d&&!d[e]?d:jt(Mt({},d||{}),{[e]:!1}))},[e,n]),l=v.useCallback((f,d={})=>{if(!e)return;const m=n.getState(),p=[];if(d==null?void 0:d.deselectOthers){const c=Object.keys(m.iiif.entities.AnnotationPage);for(const h of c){const w=tr(m,h);w&&w.views&&w.views[e]&&p.push(h)}}for(const c of p)u(c);n.setMetaValue([f,"annotationPageManager","views"],c=>c&&c[e]?c:jt(Mt({},c||{}),{[e]:!0}))},[e,u,n]);return{availablePageIds:a,enabledPageIds:s,setPageEnabled:l,setPageDisabled:u}}function ae(e={}){const t=G(e.canvasId?{id:e.canvasId}:void 0);return k((n,i)=>{if(!t)return[];const o=i.get(t.items),r=[];for(const a of o)r.push(...i.get(a.items));return r},[t])}function nr(e,t={}){return ae(t)}function ir(e,t=!1){}function rr(e,t=[]){const{id:n,selector:i}=e,o=R(),r=A(),a=n||o.collection,s=a?r.select(u=>u.iiif.entities.Collection[a]):void 0;return v.useMemo(()=>{if(!!s)return i?i(s):s},[s,i,...t])}function or(){const t=A().getStore();return v.useMemo(()=>n=>t.dispatch(n),[t])}function Tt(e){return{addEventListener(t,n,i,o){if(t)return e.setMetaValue([t.id,"eventManager",n],r=>{const a=r||[];for(const s of a)if(s.callback===i)return a;return[...a,{callback:i,scope:o}]}),i},removeEventListener(t,n,i){!t||e.setMetaValue([t.id,"eventManager",n],o=>(o||[]).filter(r=>r.callback!==i))},getListenersAsProps(t,n){const i=typeof t=="string"?{id:t}:t;if(!i||!i.id)return{};const o=e.getResourceMeta(i.id,"eventManager"),r={};if(o&&i)for(const a of Object.keys(o))r[a]=s=>{const u=e.get(i);for(const{callback:l,scope:f}of o[a]||[])(!f||n&&f.indexOf(n)!==-1)&&l(s,u)};return r}}}function ar(e){return{applyStyles(t,n,i){const o=typeof t=="string"?t:t.id;return e.setMetaValue([o,"styles",n],i)},getAppliedStyles(t){const n=typeof t=="string"?t:t.id;return e.getResourceMeta(n,"styles")}}}function H(e){return e.endsWith("info.json")?e:e.endsWith("/")?`${e}info.json`:`${e}/info.json`}function sr(e,t,n){const i=n.length,o=[];for(let r=0;r<i;r++){const a=n[r].width;o.push(e/a)}return o}function cr(e,t,n){const i=n.length,o=[];for(let r=0;r<i;r++){const a=n[r];o.push({width:Math.floor(e/a),height:Math.floor(t/a)})}return o}const ur="http://library.stanford.edu/iiif/image-api/compliance.html#level0",kt="http://library.stanford.edu/iiif/image-api/compliance.html#level1",Vt="http://library.stanford.edu/iiif/image-api/compliance.html#level2",lr="http://library.stanford.edu/iiif/image-api/conformance.html#level0",Rt="http://library.stanford.edu/iiif/image-api/conformance.html#level1",$t="http://library.stanford.edu/iiif/image-api/conformance.html#level2",fr="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Dt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",qt="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",hr="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",Wt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Nt="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",dr="http://iiif.io/api/image/1/level0.json",pr="http://iiif.io/api/image/1/profiles/level0.json",zt="http://iiif.io/api/image/1/level1.json",Gt="http://iiif.io/api/image/1/profiles/level1.json",Ht="http://iiif.io/api/image/1/level2.json",Qt="http://iiif.io/api/image/1/profiles/level2.json",vr="http://iiif.io/api/image/2/level0.json",gr="http://iiif.io/api/image/2/profiles/level0.json",Bt="http://iiif.io/api/image/2/level1.json",Ut="http://iiif.io/api/image/2/profiles/level1.json",Jt="http://iiif.io/api/image/2/level2.json",Kt="http://iiif.io/api/image/2/profiles/level2.json",mr="level0",Xt="level1",Yt="level2",yr="http://iiif.io/api/image/2/level0",Zt="http://iiif.io/api/image/2/level1",en="http://iiif.io/api/image/2/level2",wr=[Zt,en,kt,Vt,Rt,$t,Dt,qt,Wt,Nt,zt,Gt,Ht,Qt,Bt,Ut,Jt,Kt,Xt,Yt],Sr=[yr,Zt,en,ur,kt,Vt,lr,Rt,$t,fr,Dt,qt,hr,Wt,Nt,dr,pr,zt,Gt,Ht,Qt,vr,gr,Bt,Ut,Jt,Kt,mr,Xt,Yt];function x(e){if(e["@id"])return e["@id"];if(e.id)return e.id}function we(e){if(!e||!e.profile||!x(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const n of t)if(typeof n=="string"&&Sr.indexOf(n)!==-1)return!0;return!1}function Ir(e){if(!we(e))return!1;const t=Array.isArray(e.profile)?e.profile:[e.profile];for(const n of t)if(typeof n=="string"){if(wr.indexOf(n)!==-1)return!0}else{const i=n.supports||[];if(i.indexOf("regionByPx")!==-1&&(i.indexOf("sizeByW")!==-1||i.indexOf("sizeByWh")!==-1))return!0}return!1}function _r(e){if(!Ir(e))return[];const t=[],n=Array.isArray(e.profile)?e.profile:[e.profile],i=n.length;for(let o=0;o<i;o++){const r=n[o];if(typeof r!="string"&&(r.maxHeight||r.maxWidth))return[{id:x(e),type:"variable",minWidth:0,minHeight:0,maxHeight:r.maxHeight||r.maxWidth,maxWidth:r.maxWidth||r.maxHeight}]}if(e.tiles){const o=e.tiles.length;for(let r=0;r<o;r++){const a=e.tiles[r];(a.height||a.width)&&t.push({id:x(e),type:"variable",minHeight:0,minWidth:0,maxHeight:a.height||a.width,maxWidth:a.width})}}return t}function tn(e){const t=/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/,n=e.match(t);if(n){const i=n[1],o=parseInt(n[4],10),r=parseInt(n[5],10),a=n[7];if((i==="max"||i==="full")&&o&&r&&a)return{type:"fixed",id:e,height:r,width:o}}return{type:"unknown",id:e}}function Or(e){if(e["@type"])return e["@type"];if(e.type)return e.type}function Se(e){if(typeof e=="string")return tn(e);const t=Or(e);if(t!=="Image"&&t!=="sc:Image")return null;const n=e,i=x(n);return i?i&&n.width&&n.height?{id:i,type:"fixed",width:n.width,height:n.height,unsafe:!0}:tn(i):null}function br(e){return we(e)?(e&&e.sizes?e.sizes:[]).map(t=>({id:x(e),type:"fixed-service",height:t.height,width:t.width})):[]}function nn(e){const t=[],n=e.length;for(let i=0;i<n;i++){const o=br(e[i]);o.length&&t.push(...o);const r=_r(e[i]);r.length&&t.push(...r)}return t}function rn(e){const t=e.service?Array.isArray(e.service)?e.service:[e.service]:[],n=t.length,i=[];for(let o=0;o<n;o++)we(t[o])&&i.push(t[o]);return i}function Cr(e,t=!0,n){const i=[],o=Se(e);if(o===null)return i;const r=e;if(i.push(o),t&&r.width&&r.height){const a=[],s=rn(r);for(const u of s){const l={id:x(u),width:r.width,height:r.height};if(n.canLoadSync(l)){const f=n.loadServiceSync(l);f&&(f.height||(f.height=r.height),f.width||(f.width=r.width),a.push(...nn([f])))}}if(a.length)return i.push(...a),i}return r.service&&i.push(...nn(r.service)),i}function Ie(e,t,n){return{id:[H(x(e)).slice(0,-10),"full",[t,n||""].join(","),0,"default.jpg"].join("/"),type:"fixed",width:t,height:n||e.height/e.width*t,unsafe:e.width>t}}function Q(e){const t=e.replace(/(https?:\/\/)?(www.)?/i,"");return t.indexOf("/")!==-1?t.split("/")[0]:t}function Er(e,t,n){const i=e.width?e.width:e.maxWidth;return n.height<=e.maxHeight&&n.width<=e.maxWidth&&n.height>=e.minHeight&&n.width>=e.minWidth&&(!t||Math.abs(n.width-i)<Math.abs(t.width-i))}function xr(e,t){const n=[],i=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},e),o=[],r=[];let a=null;const s=(l,f)=>{if(Er(i,f,l)){if(i.preferFixedSize&&l.unsafe){r.push(l);return}i.returnAllOptions&&f&&r.push(f),a=l}else i.returnAllOptions&&r.push(l)},u=t.length;for(let l=0;l<u;l++){const f=t[l](),d=f.length;for(let m=0;m<d;m++){const p=f[m];if(p.type==="unknown"&&i.atAnyCost&&o.push(p),p.type==="fixed"&&(p.unsafe?o.push(p):s(p,a)),p.type==="fixed-service")if(i.unsafeImageService){const c=Ie(p,i.width,i.height);s(c,a)}else{const c=Ie(p,p.width,p.height);s(c,a)}if(p.type==="variable"&&p.maxWidth){const c=Ie({id:p.id,type:"fixed-service",width:p.maxWidth,height:p.maxWidth},p.maxWidth);s(c,a)}}if(a&&!i.returnAllOptions){if(a.unsafe||i.allowUnsafe)continue;break}}return i.atAnyCost&&r.length===0?{best:a||o[0],fallback:o.slice(1),log:n}:i.returnAllOptions?{best:i.atAnyCost?a||r[0]||o[0]:a||r[0],fallback:[...r,...o],log:n}:{best:a||r[0]||null,fallback:a?r:r.slice(1),log:n}}function Pr(e,t,n){const i=e>t?e:t,o=n.length,r=[];for(let a=0;a<o;a++){const s=n[a];let u=s.scaleFactors[0],l=i/u;const f=[u];for(;l>=s.width;)u=u*2,f.push(u),l=l/2;r.push(Object.assign(Object.assign({},s),{scaleFactors:f}))}return r}function Fr(e,t){if(e.length!==t.length)return!1;if(e.length===0&&t.length===0)return!0;const n=e.length;let i=!0;for(let r=0;r<n;r++){const a=e[r],s=t[r];if(a.width!==s.width||a.height!==s.height){i=!1;break}}if(i)return!0;let o=0;for(let r=0;r<n;r++)for(let a=0;a<n;a++)if(e[r].width===t[a].width&&e[r].height===t[a].height){o++;break}return o===n}/*! *****************************************************************************
15
+ Copyright (c) Microsoft Corporation. All rights reserved.
16
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
17
+ this file except in compliance with the License. You may obtain a copy of the
18
+ License at http://www.apache.org/licenses/LICENSE-2.0
19
+
20
+ THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
22
+ WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
23
+ MERCHANTABLITY OR NON-INFRINGEMENT.
24
+
25
+ See the Apache Version 2.0 License for specific language governing permissions
26
+ and limitations under the License.
27
+ ***************************************************************************** */function B(e,t,n,i){function o(r){return r instanceof n?r:new n(function(a){a(r)})}return new(n||(n=Promise))(function(r,a){function s(f){try{l(i.next(f))}catch(d){a(d)}}function u(f){try{l(i.throw(f))}catch(d){a(d)}}function l(f){f.done?r(f.value):o(f.value).then(s,u)}l((i=i.apply(e,t||[])).next())})}class on{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(t){Object.assign(this.config,t)}sample(t,n,i=!0){const o=Q(x(t)),r=H(x(t)),a=this.knownImageServers[o];return this.imageServices[r]=Object.assign(t,{real:!0}),a?this.verify(t):(this.knownImageServers[o]={verifications:0,malformed:!1,root:o,preLoaded:i,sampledId:x(t),verified:!1,server:null,result:{context:t["@context"]||[],sampledProfile:t.profile,resourceServiceRatio:n&&t.height?n.height/t.height:1,sampledSizes:t.sizes||[],sizeRatios:sr(t.width,t.height,t.sizes||[]),sampledTiles:t.tiles||[]}},!0)}preLoad(t,n=!0){this.knownImageServers[t.root]=t,n&&(this.knownImageServers[t.root].malformed=!1,this.knownImageServers[t.root].verifications=this.config.verificationsRequired)}predict(t,n=!1,i=!1){const o=Q(x(t)),r=this.knownImageServers[o];if(!r||!r.result||!i&&(r.malformed||r.verifications<this.config.verificationsRequired))return null;const a=H(x(t));return this.imageServices[a]||(this.imageServices[a]={"@context":r.result.context,"@id":x(t),id:x(t),protocol:"http://iiif.io/api/image",tiles:Pr(t.width,t.height,r.result.sampledTiles),sizes:cr(Math.floor(t.width/r.result.resourceServiceRatio),Math.floor(t.height/r.result.resourceServiceRatio),r.result.sizeRatios),profile:r.result.sampledProfile,height:t.height,width:t.width,real:!1}),this.imageServices[a]}getThumbnailFromResource(t,n,i=!0,o=[]){return B(this,void 0,void 0,function*(){const r=yield this.getImageCandidates(t,i);return xr(n,[()=>o,()=>r])})}getImageCandidates(t,n=!0){return B(this,void 0,void 0,function*(){const i=t;if(n&&i.height&&i.width){const o=rn(i);for(const r of o){const a={id:x(r),width:r.width?r.width:i.width,height:r.height?r.height:i.height};yield this.loadService(a)}}return Cr(t,n,this)})}verify(t){return B(this,void 0,void 0,function*(){const n=this.predict(t,!1,!0),i=yield this.fetchService(x(t));if(!n)return!1;const o=n.height===i.height&&n.width===i.width&&n["@context"]===i["@context"]&&Fr(n.sizes||[],i.sizes||[]);if(o){const r=Q(x(t));this.knownImageServers[r].verifications+=1,this.knownImageServers[r].verifications>=this.config.verificationsRequired&&(this.knownImageServers[r].verified=!0)}return o})}canLoadSync(t){const n=typeof t=="string"?t:x(t),i=H(n);if(this.imageServices[i])return!0;const o=this.knownImageServers[Q(n)];return o&&!o.malformed&&o.verifications>=this.config.verificationsRequired}markAsMalformed(t){return B(this,void 0,void 0,function*(){return this.knownImageServers[Q(x(t))].malformed=!0,this.loadService(t,!0)})}fetchService(t,n=!1){return B(this,void 0,void 0,function*(){const i=H(t);if(this.imageServices[i]&&(!n||this.imageServices[i].real))return this.imageServices[i];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const o=yield fetch(i).then(r=>r.json());return!o.id&&o["@id"]&&(o.id=o["@id"]),o.id!==t&&(o.id=t,o["@id"]&&(o["@id"]=t)),this.imageServices[i]=Object.assign(o,{real:!0}),this.imageServices[i]})}loadService(t,n=!1){return B(this,void 0,void 0,function*(){if(!this.config.disableThrottling)for(;this.fetchingCount>=this.config.verificationsRequired;)yield new Promise(r=>setTimeout(r,500));const i=this.knownImageServers[Q(x(t))];if(i&&!i.malformed&&!n){yield i.result;const r=this.loadServiceSync(t);if(r)return r}this.fetchingCount++;const o=yield this.fetchService(x(t),n);return this.fetchingCount--,o.real&&this.sample(o,t),o})}loadServiceSync(t){const n=H(x(t));return this.imageServices[n]?this.imageServices[n]:this.predict(t)}}new on;function Ar(e,t={}){const n=t.imageServiceLoader||new on;async function i(o,r,a,s=[],u){if(typeof o=="string")return{best:Se(o),fallback:[],log:[]};const l=e.get(o);if(typeof l=="string")return{best:Se(l),fallback:[],log:[]};switch(l.type){case"Annotation":{const f=l.body,d=e.get(f[0]);return u&&!d.width&&(d.width=u.width,d.height=u.height),await n.getThumbnailFromResource(d,r,a,s)}case"Canvas":{const f=l;if(f.thumbnail&&f.thumbnail.length){const d=e.get(f.thumbnail[0]),m=await n.getImageCandidates(d,a);m&&m.length&&s.push(...m)}return i(f.items[0],r,a,s,{width:f.width,height:f.height})}case"AnnotationPage":return i(l.items[0],r,a,s,u);case"Choice":return i(l.items[0],r,a,s,u);case"Collection":{const f=l.items[0];return i(f,r,a,s,u)}case"Manifest":{const f=l.items[0];return i(f,r,a,s,u)}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),n.getThumbnailFromResource(l,r,a,s);case"Service":case"Range":case"AnnotationCollection":case"CanvasReference":case"ContentResource":return{best:void 0,fallback:[],log:[]}}return{best:void 0,fallback:[],log:[]}}return{getBestThumbnailAtSize:i}}function Mr(e,t,n,i,o=[]){const r=A(),a=v.useMemo(()=>Tt(r),[r]);v.useEffect(()=>{const s=e;return s?(a.addEventListener(s,t,n,i),()=>{a.removeEventListener(s,t,n)}):()=>{}},[a,e,t,...o])}var jr=Object.defineProperty,an=Object.getOwnPropertySymbols,Lr=Object.prototype.hasOwnProperty,Tr=Object.prototype.propertyIsEnumerable,sn=(e,t,n)=>t in e?jr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,kr=(e,t)=>{for(var n in t||(t={}))Lr.call(t,n)&&sn(e,n,t[n]);if(an)for(var n of an(t))Tr.call(t,n)&&sn(e,n,t[n]);return e},Vr=(e,t,n)=>new Promise((i,o)=>{var r=u=>{try{s(n.next(u))}catch(l){o(l)}},a=u=>{try{s(n.throw(u))}catch(l){o(l)}},s=u=>u.done?i(u.value):Promise.resolve(u.value).then(r,a);s((n=n.apply(e,t)).next())});const Rr=(e,t={})=>{const n=A(),[i,o]=v.useState(e),r=v.useMemo(()=>n.get(e),[e,n]),{data:a,isFetching:s}=ge(`collection:${e}`,()=>Vr(void 0,null,function*(){const u=r||(yield n.loadCollection(e));return u&&o(u.id),u}),kr({refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchInterval:!1,initialData:r},t));return{isLoaded:!s,id:i,collection:a}};var $r=(e,t,n)=>new Promise((i,o)=>{var r=u=>{try{s(n.next(u))}catch(l){o(l)}},a=u=>{try{s(n.throw(u))}catch(l){o(l)}},s=u=>u.done?i(u.value):Promise.resolve(u.value).then(r,a);s((n=n.apply(e,t)).next())});function cn(){const e=G(),t=ae(),n=A(),i=re();return ge(`canvas-first-image-service:${e?e.id:"undefined"}`,()=>$r(this,null,function*(){if(e&&t.length){const o=t[0],r=n.get(o.body[0]),s=Y(r)[0];return s&&(yield i.loadService({id:s.id||s["@id"],width:s.width||e.width,height:s.height||e.height}))||void 0}}),{refetchOnWindowFocus:!1,refetchOnMount:!1,refetchIntervalInBackground:!1,refetchInterval:!1,initialData:()=>{if(e&&t.length){const o=t[0],r=n.get(o.body[0]),s=Y(r)[0];return s&&i.loadServiceSync({id:s.id||s["@id"],width:s.width||e.width,height:s.height||e.height})||void 0}}})}function Dr(){const e=cn();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 qr(e={},t=[]){const{id:n,selector:i}=e,o=R(),r=A(),a=n||o.range,s=a?r.select(u=>u.iiif.entities.Range[a]):void 0;return v.useMemo(()=>{if(!!s)return i?i(s):s},[s,i,...t])}function Wr(e,t){const n=A(),i=v.useMemo(()=>Tt(n),[n]),o=k(()=>e&&e.id?n.getResourceMeta(e.id,"eventManager"):null,[e]);return v.useMemo(()=>e?i.getListenersAsProps(e,t):{},[o,e,n,t])}function un(e,t){return k((n,i)=>i.get(e.map(o=>({id:o,type:t}))),[e,t])}function Nr(){const e=Z();return e?e.service.find(t=>t.profile==="SearchService1"||t.profile==="http://iiif.io/api/search/1/search"):void 0}function zr(e,t){const n=A(),i=v.useMemo(()=>ar(n),[n]);return k(()=>{if(!e)return null;const o=i.getAppliedStyles(e.id);return o?t?o[t]:o:void 0},[e,t])}const ln=(e,t=[])=>{const n=A();v.useEffect(()=>{e(n)},[n,...t])};function Gr(e,t,{canvasId:n,manifestId:i}={}){const o=A(),r=re(),a=v.useMemo(()=>Ar(o,{imageServiceLoader:r}),[o,r]),[s,u]=v.useState(),l=Z(i?{id:i}:void 0),f=G(n?{id:n}:void 0),d=f||l,m=v.useRef(!1);if(v.useEffect(()=>()=>{m.current=!0},[]),!d)throw new Error("Must be called under a manifest or canvas context.");return ln(p=>{a.getBestThumbnailAtSize(d,e,t).then(c=>{c.best&&!m.current&&u(c.best)})},[d]),s}var Hr=Object.defineProperty,Qr=Object.defineProperties,Br=Object.getOwnPropertyDescriptors,fn=Object.getOwnPropertySymbols,Ur=Object.prototype.hasOwnProperty,Jr=Object.prototype.propertyIsEnumerable,hn=(e,t,n)=>t in e?Hr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,dn=(e,t)=>{for(var n in t||(t={}))Ur.call(t,n)&&hn(e,n,t[n]);if(fn)for(var n of fn(t))Jr.call(t,n)&&hn(e,n,t[n]);return e},pn=(e,t)=>Qr(e,Br(t));function vn(){const e=re(),[t,n]=v.useState({}),i=v.useRef(!1);return v.useEffect(()=>()=>{i.current=!0},[]),[v.useCallback((r,{height:a,width:s})=>{if(r){const u=r.id||r["@id"],l=e.loadServiceSync({id:u,width:r.width||s,height:r.height||a});l?r=l:t[u]||(i.current||n(f=>pn(dn({},f),{[u]:"loading"})),e.loadService({id:u,width:r.width||s,height:r.height||a}).then(()=>{i.current||n(f=>pn(dn({},f),{[u]:"done"}))}))}return r},[e,t]),t]}function _e(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function Kr(e,t){const n=[],i=[];for(const o of t){const r=e.get(o.body);for(const a of r){const[s,{selector:u}]=_e(a),l=(s.type||"unknown").toLowerCase();if(l==="choice"){const f=e.get(s.items);r.push(f[0]);continue}n.indexOf(l)===-1&&n.push(l),i.push({type:l,resource:s,target:o.target,selector:u})}}return{types:n,items:i}}var Xr=Object.defineProperty,Yr=Object.defineProperties,Zr=Object.getOwnPropertyDescriptors,gn=Object.getOwnPropertySymbols,eo=Object.prototype.hasOwnProperty,to=Object.prototype.propertyIsEnumerable,mn=(e,t,n)=>t in e?Xr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,no=(e,t)=>{for(var n in t||(t={}))eo.call(t,n)&&mn(e,n,t[n]);if(gn)for(var n of gn(t))to.call(t,n)&&mn(e,n,t[n]);return e},io=(e,t)=>Yr(e,Zr(t));const yn={makeChoice:()=>{}},wn=[{type:"unknown"},yn],se=e=>[{type:"unknown",reason:e,annotations:{pages:[]}},yn];function ro(e){const t=Z(),n=G(),i=ae(),o=A(),[r,a]=vn(),{enabledPageIds:s}=Lt((e==null?void 0:e.annotationPageManagerId)||(t==null?void 0:t.id),{all:!1}),u=un(s,"AnnotationPage"),[l,f]=v.useState((e==null?void 0:e.defaultChoices)||[]);e==null||e.strategies;const d=v.useMemo(()=>{const h=[];let w=null;const y=[];o.getState();for(const S of i){const _=o.get(S.body);for(const O of _){const[P,{selector:F}]=_e(O),b=(P.type||"unknown").toLowerCase();if(b==="choice"){const C=o.get(P.items),M=l.length?l.map(L=>C.find(Oe=>Oe.id===L)).filter(Boolean):[C[0]];M.length===0&&M.push(C[0]),w={type:"single-choice",items:C.map(L=>({id:L.id,label:L.label,selected:M.indexOf(L)!==-1})),label:O.label},_.push(...M);continue}h.indexOf(b)===-1&&h.push(b),y.push({type:b,resource:P,target:S.target,selector:F})}}return{types:h,items:y,choice:w}},[o,a,i,l]),p={makeChoice:v.useCallback((h,{deselectOthers:w=!0,deselect:y=!1}={})=>{if(d.choice){if(d.choice.type!=="single-choice")throw new Error("Complex choice not supported yet");f(S=>{if(y){const O=S.filter(P=>P!==h);if(O.length===0){const P=d.items[0].resource.id;return P?[P]:[]}return O}if(w)return[h];const _=[...S];if(_.length===0&&d.items.length){const O=d.items[0].resource.id;O&&_.push(O)}return S.indexOf(h)!==-1?S:[...S,h]})}},[d.choice])},c=v.useMemo(()=>{if(!n)return wn;if(d.types.length!==1)return se("ComplexTimelineStrategy not yet supported");const h=d.types[0];if(h==="image"){const w=[];for(const y of d.items){const S=y.resource&&y.resource.type==="SpecificResource"?y.resource.source:y.resource;if(!S.id)return se("No resource Identifier");let _;if(S.service){const Sn=Y(S);Sn[0]&&(_=r(Sn[0],n))}y.target==="https://bvmm.irht.cnrs.fr/iiif/2309/canvas/canvas-981394#xywh=3949,994,1091,1232"&&(y.target="https://bvmm.irht.cnrs.fr/iiif/4490/canvas/canvas-981394#xywh=3949,994,1091,1232"),_&&_.width&&_.height&&_.profile==="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2"&&(_.profile="http://iiif.io/api/image/2/level2.json",_.sizes=[{width:_.width,height:_.height}],_.tiles=[{width:256,height:256,scaleFactors:[1,2,4,8,16,32]}]);const{selector:O,source:P}=V(y.target);if(P.id!==n.id)continue;const F={type:"BoxSelector",x:0,y:0,width:n.width,height:n.height},b=O?O.type==="TemporalSelector"?{type:"TemporalBoxSelector",startTime:O.startTime,endTime:O.endTime,x:F.x,y:F.y,width:F.width,height:F.height}:O:null,C={type:"BoxSelector",x:0,y:0,width:n.width,height:n.height},M=y.resource.type==="SpecificResource"?V(y.resource):null,L=M&&M.selector&&(M.selector.type==="BoxSelector"||M.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",x:M.selector.x,y:M.selector.y,width:M.selector.width,height:M.selector.height}:C,Oe={id:S.id,type:"Image",width:b?S.width:n.width,height:b?S.height:n.height,service:_,sizes:_&&_.sizes?_.sizes:S.width&&S.height?[{width:S.width,height:S.height}]:[],target:b||F,selector:L};w.push(Oe)}return[{type:"images",image:w[0],images:w,choice:d.choice},p]}return h==="audio"?se("Audio strategy not yet supported"):h==="video"?se("Video strategy not yet supported"):wn},[n,d,o,p.makeChoice]);return v.useMemo(()=>[io(no({},c[0]),{annotations:{pages:u}}),c[1]],[c,u])}g.AnnotationContext=En,g.CanvasContext=Pe,g.CollectionContext=xn,g.ContextBridge=ci,g.ImageServiceLoaderContext=It,g.ManifestContext=Fe,g.RangeContext=Pn,g.ReactVaultContext=te,g.ResourceProvider=$,g.ResourceReactContext=ee,g.SimpleViewerProvider=oi,g.SimpleViewerReactContext=X,g.VaultProvider=Ae,g.VisibleCanvasReactContext=K,g.expandTarget=V,g.flattenAnnotationPageIds=Pt,g.getPaintables=Kr,g.parseSelector=oe,g.parseSpecificResource=_e,g.useAnnotation=Bi,g.useAnnotationPageManager=Lt,g.useAnnotationsAtTime=nr,g.useCanvas=G,g.useCanvasClock=ir,g.useCollection=rr,g.useContextBridge=si,g.useDispatch=or,g.useEventListener=Mr,g.useExternalCollection=Rr,g.useExternalManifest=Ke,g.useImageService=cn,g.useImageServiceLoader=re,g.useImageTile=Dr,g.useLoadImageService=vn,g.useManifest=Z,g.usePaintingAnnotations=ae,g.useRange=qr,g.useRenderingStrategy=ro,g.useResourceContext=R,g.useResourceEvents=Wr,g.useResources=un,g.useSearchService=Nr,g.useSimpleViewer=ai,g.useStyles=zr,g.useThumbnail=Gr,g.useVault=A,g.useVaultEffect=ln,g.useVaultSelector=k,g.useVisibleCanvases=Xe,Object.defineProperty(g,"__esModule",{value:!0})});
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "react-iiif-vault",
3
+ "version": "0.9.0",
4
+ "main": "./dist/cjs/index.js",
5
+ "module": "./dist/esm/index.mjs",
6
+ "types": "./dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "contributors": [
11
+ "Stephen Fraser <stephen.fraser@digirati.com>"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "require": "./dist/cjs/index.js",
16
+ "import": "./dist/esm/index.mjs",
17
+ "default": "./dist/index.umd.js"
18
+ }
19
+ },
20
+ "scripts": {
21
+ "build": "tsc -p ./tsconfig.types.json --declaration --emitDeclarationOnly && rollup -c",
22
+ "prepublishOnly": "tsc -p ./tsconfig.types.json --declaration --emitDeclarationOnly && rollup -c",
23
+ "test": "jest"
24
+ },
25
+ "license": "MIT",
26
+ "resolutions": {
27
+ "@iiif/vault": "^0.9.9",
28
+ "@iiif/presentation-3": "^1.0.4"
29
+ },
30
+ "dependencies": {
31
+ "@atlas-viewer/iiif-image-api": "^1.2.6",
32
+ "@iiif/presentation-2": "^1.0.1",
33
+ "@iiif/presentation-3": "^1.0.4",
34
+ "@iiif/vault": "^0.9.9",
35
+ "@iiif/vault-helpers": "^0.9.4",
36
+ "react": "^16.10.2 || ^17.0.1",
37
+ "react-dom": "^16.10.2 || ^17.0.1",
38
+ "react-query": "^1.5.10",
39
+ "redux": "^4.1.2",
40
+ "rollup": "^2.67.1",
41
+ "typescript": "^4.5.5"
42
+ },
43
+ "devDependencies": {
44
+ "@rollup/plugin-replace": "^3.0.1",
45
+ "@testing-library/react": "^12.1.2",
46
+ "@testing-library/react-hooks": "^7.0.2",
47
+ "@types/jest": "^27.4.0",
48
+ "@types/react": "^17.0.39",
49
+ "@types/react-dom": "^17.0.11",
50
+ "@typescript-eslint/eslint-plugin": "^5.11.0",
51
+ "@typescript-eslint/parser": "^5.11.0",
52
+ "eslint": "^8.8.0",
53
+ "eslint-plugin-json": "^3.1.0",
54
+ "eslint-plugin-prettier": "^4.0.0",
55
+ "jest": "^27.5.0",
56
+ "prettier": "^2.5.1",
57
+ "react": "^16.10.2 || ^17.0.1",
58
+ "react-dom": "^16.10.2 || ^17.0.1",
59
+ "react-use": "^17.3.2",
60
+ "redux": "^4.1.2",
61
+ "rollup-library-template": "^1.0.3",
62
+ "ts-jest": "^27.1.3",
63
+ "tslib": "^2.3.1"
64
+ },
65
+ "publishConfig": {
66
+ "access": "public"
67
+ }
68
+ }