react-iiif-vault 0.9.6 → 0.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,23 @@
1
- import React, { useContext, useMemo, useState, useEffect, createContext, useCallback, useRef, useLayoutEffect } from 'react';
1
+ import React, { useContext, useMemo, useState, useEffect, createContext, useCallback, useRef, useLayoutEffect, Fragment } from 'react';
2
2
  import { globalVault, Vault } from '@iiif/vault';
3
- import { ImageServiceLoader, getImageServices } from '@atlas-viewer/iiif-image-api';
4
- import { createEventsHelper, createStylesHelper, createThumbnailHelper } from '@iiif/vault-helpers';
3
+ import { AtlasAuto, mergeStyles, RegionHighlight, TileSet as TileSet$1 } from '@atlas-viewer/atlas';
5
4
  import { createAction } from 'typesafe-actions';
5
+ import { createEventsHelper, createStylesHelper, createThumbnailHelper } from '@iiif/vault-helpers';
6
+ import { ImageServiceLoader, getImageServices } from '@atlas-viewer/iiif-image-api';
6
7
 
7
- var __defProp$5 = Object.defineProperty;
8
- var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
9
- var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
10
- var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues$5 = (a, b) => {
8
+ var __defProp$8 = Object.defineProperty;
9
+ var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
10
+ var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues$8 = (a, b) => {
13
14
  for (var prop in b || (b = {}))
14
- if (__hasOwnProp$5.call(b, prop))
15
- __defNormalProp$5(a, prop, b[prop]);
16
- if (__getOwnPropSymbols$5)
17
- for (var prop of __getOwnPropSymbols$5(b)) {
18
- if (__propIsEnum$5.call(b, prop))
19
- __defNormalProp$5(a, prop, b[prop]);
15
+ if (__hasOwnProp$8.call(b, prop))
16
+ __defNormalProp$8(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols$8)
18
+ for (var prop of __getOwnPropSymbols$8(b)) {
19
+ if (__propIsEnum$8.call(b, prop))
20
+ __defNormalProp$8(a, prop, b[prop]);
20
21
  }
21
22
  return a;
22
23
  };
@@ -34,43 +35,13 @@ const useResourceContext = () => {
34
35
  const ResourceProvider = ({ value, children }) => {
35
36
  const parentContext = useResourceContext();
36
37
  const newContext = useMemo(() => {
37
- return __spreadValues$5(__spreadValues$5({}, parentContext), value);
38
+ return __spreadValues$8(__spreadValues$8({}, parentContext), value);
38
39
  }, [value, parentContext]);
39
40
  return /* @__PURE__ */ React.createElement(ResourceReactContext.Provider, {
40
41
  value: newContext
41
42
  }, children);
42
43
  };
43
44
 
44
- const AnnotationContext = ({ annotation, children }) => {
45
- return /* @__PURE__ */ React.createElement(ResourceProvider, {
46
- value: { annotation }
47
- }, children);
48
- };
49
-
50
- const CanvasContext = ({ canvas, children }) => {
51
- return /* @__PURE__ */ React.createElement(ResourceProvider, {
52
- value: { canvas }
53
- }, children);
54
- };
55
-
56
- const CollectionContext = ({ collection, children }) => {
57
- return /* @__PURE__ */ React.createElement(ResourceProvider, {
58
- value: { collection }
59
- }, children);
60
- };
61
-
62
- const ManifestContext = ({ manifest, children }) => {
63
- return /* @__PURE__ */ React.createElement(ResourceProvider, {
64
- value: { manifest }
65
- }, children);
66
- };
67
-
68
- const RangeContext = ({ range, children }) => {
69
- return /* @__PURE__ */ React.createElement(ResourceProvider, {
70
- value: { range }
71
- }, children);
72
- };
73
-
74
45
  const ReactVaultContext = React.createContext({
75
46
  vault: null,
76
47
  setVaultInstance: (vault) => {
@@ -162,13 +133,23 @@ function useExternalManifest(idOrRef, options) {
162
133
  return { id, isLoaded, error, manifest: resource, requestId, cached };
163
134
  }
164
135
 
136
+ const ManifestContext = ({ manifest, children }) => {
137
+ return /* @__PURE__ */ React.createElement(ResourceProvider, {
138
+ value: { manifest }
139
+ }, children);
140
+ };
141
+
142
+ const CanvasContext = ({ canvas, children }) => {
143
+ return /* @__PURE__ */ React.createElement(ResourceProvider, {
144
+ value: { canvas }
145
+ }, children);
146
+ };
147
+
165
148
  function useVaultSelector(selector, deps = []) {
166
149
  const vault = useVault();
167
150
  const [selectedState, setSelectedState] = useState(() => selector(vault.getState(), vault));
168
151
  useEffect(() => {
169
- return vault.subscribe((s) => selector(s, vault), (state) => {
170
- setSelectedState(state);
171
- }, false);
152
+ return vault.subscribe((s) => selector(s, vault), setSelectedState, false);
172
153
  }, deps);
173
154
  return selectedState;
174
155
  }
@@ -313,9 +294,237 @@ const ContextBridge = (props) => {
313
294
  }, props.children)));
314
295
  };
315
296
 
316
- const ImageServiceLoaderContext = React.createContext(new ImageServiceLoader());
317
- function useImageServiceLoader() {
318
- return useContext(ImageServiceLoaderContext);
297
+ const IMPORT_ENTITIES = "@iiif/IMPORT_ENTITIES";
298
+ const MODIFY_ENTITY_FIELD = "@iiif/MODIFY_ENTITY_FIELD";
299
+ const REORDER_ENTITY_FIELD = "@iiif/REORDER_ENTITY_FIELD";
300
+ const ADD_REFERENCE = "@iiif/ADD_REFERENCE";
301
+ const REMOVE_REFERENCE = "@iiif/REMOVE_REFERENCE";
302
+ const importEntities = createAction(IMPORT_ENTITIES)();
303
+ const modifyEntityField = createAction(MODIFY_ENTITY_FIELD)();
304
+ const reorderEntityField = createAction(REORDER_ENTITY_FIELD)();
305
+ const addReference = createAction(ADD_REFERENCE)();
306
+ const removeReference = createAction(REMOVE_REFERENCE)();
307
+ const entityActions = { importEntities, modifyEntityField, reorderEntityField, addReference, removeReference };
308
+
309
+ const ADD_MAPPING = "@iiif/ADD_MAPPING";
310
+ const ADD_MAPPINGS = "@iiif/ADD_MAPPINGS";
311
+ createAction(ADD_MAPPING)();
312
+ createAction(ADD_MAPPINGS)();
313
+
314
+ const SET_META_VALUE = "@iiif/SET_META_VALUE";
315
+ const SET_META_VALUE_DYNAMIC = "@iiif/SET_META_VALUE_DYNAMIC";
316
+ const UNSET_META_VALUE = "@iiif/UNSET_META_VALUE";
317
+ createAction(SET_META_VALUE)();
318
+ createAction(SET_META_VALUE_DYNAMIC)();
319
+ createAction(UNSET_META_VALUE)();
320
+ const REQUEST_RESOURCE = "@iiif/REQUEST_RESOURCE";
321
+ const REQUEST_ERROR = "@iiif/REQUEST_ERROR";
322
+ const REQUEST_MISMATCH = "@iiif/REQUEST_MISMATCH";
323
+ const REQUEST_COMPLETE = "@iiif/REQUEST_COMPLETE";
324
+ const REQUEST_OFFLINE_RESOURCE = "@iiif/REQUEST_OFFLINE_RESOURCE";
325
+ createAction(REQUEST_RESOURCE)();
326
+ createAction(REQUEST_ERROR)();
327
+ createAction(REQUEST_MISMATCH)();
328
+ createAction(REQUEST_COMPLETE)();
329
+ createAction(REQUEST_OFFLINE_RESOURCE)();
330
+
331
+ const BATCH_ACTIONS = "@iiif/BATCH";
332
+ const BATCH_IMPORT = "@iiif/BATCH_IMPORT";
333
+ createAction(BATCH_ACTIONS)();
334
+ createAction(BATCH_IMPORT)();
335
+
336
+ function useDispatch() {
337
+ const vault = useVault();
338
+ const store = vault.getStore();
339
+ return useMemo(() => {
340
+ return (action) => store.dispatch(action);
341
+ }, [store]);
342
+ }
343
+
344
+ function isVaultActivated(obj) {
345
+ return typeof obj !== "string" && obj && obj.bindToVault;
346
+ }
347
+ function useVirtualAnnotationPage() {
348
+ const vault = useVault();
349
+ const sources = useRef([]);
350
+ const dispatch = useDispatch();
351
+ const virtualId = useMemo(() => {
352
+ return `vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random() * 1e9).toString(16)}`;
353
+ }, []);
354
+ useLayoutEffect(() => {
355
+ const page = {
356
+ id: virtualId,
357
+ type: "AnnotationPage",
358
+ behavior: [],
359
+ motivation: null,
360
+ label: null,
361
+ thumbnail: [],
362
+ summary: null,
363
+ requiredStatement: null,
364
+ metadata: [],
365
+ rights: null,
366
+ provider: [],
367
+ items: [],
368
+ seeAlso: [],
369
+ homepage: [],
370
+ logo: [],
371
+ rendering: [],
372
+ service: []
373
+ };
374
+ dispatch(entityActions.importEntities({
375
+ entities: {
376
+ AnnotationPage: {
377
+ [page.id]: page
378
+ }
379
+ }
380
+ }));
381
+ }, [virtualId]);
382
+ const fullPage = useVaultSelector((state) => virtualId ? state.iiif.entities.AnnotationPage[virtualId] : null, [virtualId]);
383
+ const addAnnotation = useCallback((id, atIndex) => {
384
+ if (virtualId) {
385
+ if (isVaultActivated(id)) {
386
+ const display = id;
387
+ if (!display.__vault) {
388
+ display.bindToVault(vault);
389
+ }
390
+ id = typeof display.source === "string" ? display.source : display.source.id;
391
+ sources.current[id] = display;
392
+ } else if (typeof id !== "string") {
393
+ id = id.id;
394
+ }
395
+ const full = vault.get({ id: virtualId, type: "AnnotationPage" });
396
+ const annotation = vault.get({ id, type: "Annotation" });
397
+ if (full && annotation) {
398
+ if (!full.items.find((r) => r.id === annotation.id)) {
399
+ dispatch(entityActions.addReference({
400
+ id: virtualId,
401
+ type: "AnnotationPage",
402
+ key: "items",
403
+ reference: {
404
+ id,
405
+ type: "Annotation"
406
+ },
407
+ index: atIndex
408
+ }));
409
+ }
410
+ }
411
+ }
412
+ }, [virtualId]);
413
+ const removeAnnotation = useCallback((id) => {
414
+ if (virtualId) {
415
+ if (isVaultActivated(id)) {
416
+ id = typeof id.source === "string" ? id.source : id.source.id;
417
+ } else if (typeof id !== "string") {
418
+ id = id.id;
419
+ }
420
+ if (sources.current[id]) {
421
+ sources.current[id].beforeRemove();
422
+ }
423
+ const full = vault.get({ id: virtualId, type: "AnnotationPage" });
424
+ if (full) {
425
+ dispatch(entityActions.removeReference({
426
+ id: virtualId,
427
+ type: "AnnotationPage",
428
+ key: "items",
429
+ reference: {
430
+ id,
431
+ type: "Annotation"
432
+ }
433
+ }));
434
+ }
435
+ }
436
+ }, [virtualId]);
437
+ return [
438
+ fullPage,
439
+ {
440
+ addAnnotation,
441
+ removeAnnotation
442
+ }
443
+ ];
444
+ }
445
+
446
+ const VirtualAnnotationPageContext = createContext(null);
447
+ function useVirtualAnnotationPageContext() {
448
+ const ctx = useContext(VirtualAnnotationPageContext);
449
+ return [
450
+ ctx.fullPage,
451
+ {
452
+ addAnnotation: ctx.addAnnotation,
453
+ removeAnnotation: ctx.removeAnnotation
454
+ }
455
+ ];
456
+ }
457
+ function VirtualAnnotationProvider({ children }) {
458
+ const [fullPage, { addAnnotation, removeAnnotation }] = useVirtualAnnotationPage();
459
+ return /* @__PURE__ */ React.createElement(VirtualAnnotationPageContext.Provider, {
460
+ value: useMemo(() => ({ fullPage, addAnnotation, removeAnnotation }), [fullPage])
461
+ }, children);
462
+ }
463
+
464
+ var __defProp$7 = Object.defineProperty;
465
+ var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
466
+ var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
467
+ var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
468
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
469
+ var __spreadValues$7 = (a, b) => {
470
+ for (var prop in b || (b = {}))
471
+ if (__hasOwnProp$7.call(b, prop))
472
+ __defNormalProp$7(a, prop, b[prop]);
473
+ if (__getOwnPropSymbols$7)
474
+ for (var prop of __getOwnPropSymbols$7(b)) {
475
+ if (__propIsEnum$7.call(b, prop))
476
+ __defNormalProp$7(a, prop, b[prop]);
477
+ }
478
+ return a;
479
+ };
480
+ var __objRest = (source, exclude) => {
481
+ var target = {};
482
+ for (var prop in source)
483
+ if (__hasOwnProp$7.call(source, prop) && exclude.indexOf(prop) < 0)
484
+ target[prop] = source[prop];
485
+ if (source != null && __getOwnPropSymbols$7)
486
+ for (var prop of __getOwnPropSymbols$7(source)) {
487
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$7.call(source, prop))
488
+ target[prop] = source[prop];
489
+ }
490
+ return target;
491
+ };
492
+ function Viewer(_a) {
493
+ var _b = _a, {
494
+ children
495
+ } = _b, props = __objRest(_b, [
496
+ "children"
497
+ ]);
498
+ const bridge = useContextBridge();
499
+ return /* @__PURE__ */ React.createElement(AtlasAuto, __spreadValues$7({}, props), /* @__PURE__ */ React.createElement(ContextBridge, {
500
+ bridge
501
+ }, /* @__PURE__ */ React.createElement(VirtualAnnotationProvider, null, children)));
502
+ }
503
+
504
+ function useResourceEvents(resource, scope) {
505
+ const vault = useVault();
506
+ const helper = useMemo(() => createEventsHelper(vault), [vault]);
507
+ const hooks = useVaultSelector(() => {
508
+ if (resource && resource.id) {
509
+ return vault.getResourceMeta(resource.id, "eventManager");
510
+ }
511
+ return null;
512
+ }, [resource]);
513
+ return useMemo(() => {
514
+ return resource ? helper.getListenersAsProps(resource, scope) : {};
515
+ }, [hooks, resource, vault, scope]);
516
+ }
517
+
518
+ function useStyles(resource, scope) {
519
+ const vault = useVault();
520
+ const helper = useMemo(() => createStylesHelper(vault), [vault]);
521
+ return useVaultSelector(() => {
522
+ if (!resource) {
523
+ return null;
524
+ }
525
+ const styles = helper.getAppliedStyles(resource.id);
526
+ return styles ? scope ? styles[scope] : styles : void 0;
527
+ }, [resource, scope]);
319
528
  }
320
529
 
321
530
  const BOX_SELECTOR = /&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/;
@@ -407,21 +616,21 @@ function parseSelector(source) {
407
616
  };
408
617
  }
409
618
 
410
- var __defProp$4 = Object.defineProperty;
619
+ var __defProp$6 = Object.defineProperty;
411
620
  var __defProps$4 = Object.defineProperties;
412
621
  var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
413
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
414
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
415
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
416
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
417
- var __spreadValues$4 = (a, b) => {
622
+ var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
623
+ var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
624
+ var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
625
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
626
+ var __spreadValues$6 = (a, b) => {
418
627
  for (var prop in b || (b = {}))
419
- if (__hasOwnProp$4.call(b, prop))
420
- __defNormalProp$4(a, prop, b[prop]);
421
- if (__getOwnPropSymbols$4)
422
- for (var prop of __getOwnPropSymbols$4(b)) {
423
- if (__propIsEnum$4.call(b, prop))
424
- __defNormalProp$4(a, prop, b[prop]);
628
+ if (__hasOwnProp$6.call(b, prop))
629
+ __defNormalProp$6(a, prop, b[prop]);
630
+ if (__getOwnPropSymbols$6)
631
+ for (var prop of __getOwnPropSymbols$6(b)) {
632
+ if (__propIsEnum$6.call(b, prop))
633
+ __defNormalProp$6(a, prop, b[prop]);
425
634
  }
426
635
  return a;
427
636
  };
@@ -482,7 +691,7 @@ function expandTarget(target, options = {}) {
482
691
  if (!fragment) {
483
692
  return {
484
693
  type: "SpecificResource",
485
- source: __spreadProps$4(__spreadValues$4({}, target), {
694
+ source: __spreadProps$4(__spreadValues$6({}, target), {
486
695
  id
487
696
  }),
488
697
  selector: null,
@@ -491,7 +700,7 @@ function expandTarget(target, options = {}) {
491
700
  }
492
701
  return expandTarget({
493
702
  type: "SpecificResource",
494
- source: __spreadProps$4(__spreadValues$4({}, target), {
703
+ source: __spreadProps$4(__spreadValues$6({}, target), {
495
704
  id
496
705
  }),
497
706
  selector: {
@@ -508,6 +717,168 @@ function expandTarget(target, options = {}) {
508
717
  };
509
718
  }
510
719
 
720
+ var __defProp$5 = Object.defineProperty;
721
+ var __defProps$3 = Object.defineProperties;
722
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
723
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
724
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
725
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
726
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
727
+ var __spreadValues$5 = (a, b) => {
728
+ for (var prop in b || (b = {}))
729
+ if (__hasOwnProp$5.call(b, prop))
730
+ __defNormalProp$5(a, prop, b[prop]);
731
+ if (__getOwnPropSymbols$5)
732
+ for (var prop of __getOwnPropSymbols$5(b)) {
733
+ if (__propIsEnum$5.call(b, prop))
734
+ __defNormalProp$5(a, prop, b[prop]);
735
+ }
736
+ return a;
737
+ };
738
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
739
+ function useAnnotation(options = {}, deps = []) {
740
+ const { id, selector } = options;
741
+ const ctx = useResourceContext();
742
+ const vault = useVault();
743
+ const annotationId = id ? id : ctx.annotation;
744
+ const annotation = useVaultSelector((s) => annotationId ? s.iiif.entities.Annotation[annotationId] : void 0, [annotationId]);
745
+ const body = useVaultSelector((s) => annotation && annotation.body ? annotation.body.map((singleBody) => singleBody ? s.iiif.entities[singleBody.type][singleBody.id] : null).filter(Boolean) : [], [annotation]);
746
+ return useMemo(() => {
747
+ if (!annotation) {
748
+ return void 0;
749
+ }
750
+ const newAnnotation = __spreadProps$3(__spreadValues$5({}, annotation), {
751
+ body,
752
+ target: expandTarget(annotation.target, { typeMap: vault.getState().iiif.mapping })
753
+ });
754
+ if (selector) {
755
+ return selector(newAnnotation);
756
+ }
757
+ return newAnnotation;
758
+ }, [annotation, selector, body, ...deps]);
759
+ }
760
+
761
+ function useCanvas(options = {}, deps = []) {
762
+ const { id, selector } = options;
763
+ const ctx = useResourceContext();
764
+ const canvasId = id ? id : ctx.canvas;
765
+ const canvas = useVaultSelector((s) => canvasId ? s.iiif.entities.Canvas[canvasId] : void 0, [canvasId]);
766
+ return useMemo(() => {
767
+ if (!canvas) {
768
+ return void 0;
769
+ }
770
+ if (selector) {
771
+ return selector(canvas);
772
+ }
773
+ return canvas;
774
+ }, [canvas, selector, ...deps]);
775
+ }
776
+
777
+ var __defProp$4 = Object.defineProperty;
778
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
779
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
780
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
781
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
782
+ var __spreadValues$4 = (a, b) => {
783
+ for (var prop in b || (b = {}))
784
+ if (__hasOwnProp$4.call(b, prop))
785
+ __defNormalProp$4(a, prop, b[prop]);
786
+ if (__getOwnPropSymbols$4)
787
+ for (var prop of __getOwnPropSymbols$4(b)) {
788
+ if (__propIsEnum$4.call(b, prop))
789
+ __defNormalProp$4(a, prop, b[prop]);
790
+ }
791
+ return a;
792
+ };
793
+ const RenderAnnotation = ({
794
+ id,
795
+ style: defaultStyle,
796
+ className,
797
+ interactive
798
+ }) => {
799
+ const annotation = useAnnotation({ id });
800
+ const style = useStyles(annotation, "atlas");
801
+ const html = useStyles(annotation, "html");
802
+ const events = useResourceEvents(annotation, ["atlas"]);
803
+ const canvas = useCanvas();
804
+ const allStyles = useMemo(() => {
805
+ return mergeStyles(defaultStyle, style);
806
+ }, [defaultStyle, style]);
807
+ const isValid = canvas && annotation && annotation.target && annotation.target.selector && annotation.target.selector.type === "BoxSelector" && annotation.target.source && annotation.target.source.id === canvas.id;
808
+ if (!isValid) {
809
+ return null;
810
+ }
811
+ return /* @__PURE__ */ React.createElement(RegionHighlight, __spreadValues$4({
812
+ id: annotation.id,
813
+ isEditing: true,
814
+ region: annotation.target.selector.spatial,
815
+ style: allStyles,
816
+ className: (html == null ? void 0 : html.className) || className,
817
+ interactive: !!((html == null ? void 0 : html.href) || interactive),
818
+ href: (html == null ? void 0 : html.href) || null,
819
+ title: (html == null ? void 0 : html.title) || null,
820
+ hrefTarget: (html == null ? void 0 : html.target) || null
821
+ }, events));
822
+ };
823
+
824
+ const RenderAnnotationPage = ({
825
+ className,
826
+ page
827
+ }) => {
828
+ var _a;
829
+ const style = useStyles(page, "atlas");
830
+ const html = useStyles(page, "html");
831
+ useVaultSelector((state) => page.id ? state.iiif.entities.AnnotationPage[page.id] : null, []);
832
+ return /* @__PURE__ */ React.createElement(Fragment, null, (_a = page.items) == null ? void 0 : _a.map((annotation) => {
833
+ return /* @__PURE__ */ React.createElement(RenderAnnotation, {
834
+ key: annotation.id,
835
+ id: annotation.id,
836
+ style,
837
+ className: (html == null ? void 0 : html.className) || className
838
+ });
839
+ }));
840
+ };
841
+
842
+ const TileSet = TileSet$1;
843
+ function RenderImage({
844
+ id,
845
+ image,
846
+ thumbnail,
847
+ isStatic,
848
+ x = 0,
849
+ y = 0,
850
+ annotations
851
+ }) {
852
+ var _a, _b, _c, _d;
853
+ return /* @__PURE__ */ React.createElement(Fragment, {
854
+ key: id
855
+ }, !image.service ? /* @__PURE__ */ React.createElement(Fragment, {
856
+ key: "no-service"
857
+ }, /* @__PURE__ */ React.createElement("world-image", {
858
+ uri: image.id,
859
+ target: image.target.spatial,
860
+ display: image.width && image.height ? {
861
+ width: image.width,
862
+ height: image.height
863
+ } : void 0
864
+ }), annotations) : /* @__PURE__ */ React.createElement(Fragment, {
865
+ key: "service"
866
+ }, /* @__PURE__ */ React.createElement(TileSet, {
867
+ viewport: isStatic,
868
+ tiles: {
869
+ id: image.service.id,
870
+ height: image.height,
871
+ width: image.width,
872
+ imageService: image.service,
873
+ thumbnail: thumbnail && thumbnail.type === "fixed" ? thumbnail : void 0
874
+ },
875
+ x: ((_a = image.target) == null ? void 0 : _a.spatial.x) + x,
876
+ y: ((_b = image.target) == null ? void 0 : _b.spatial.y) + y,
877
+ width: (_c = image.target) == null ? void 0 : _c.spatial.width,
878
+ height: (_d = image.target) == null ? void 0 : _d.spatial.height
879
+ }), annotations));
880
+ }
881
+
511
882
  function parseSpecificResource(resource) {
512
883
  if (resource.type === "SpecificResource") {
513
884
  return [resource.source, { selector: resource.selector }];
@@ -567,118 +938,6 @@ const unsupportedStrategy = (reason) => {
567
938
  return { type: "unknown", reason, annotations: { pages: [] } };
568
939
  };
569
940
 
570
- function getImageStrategy(canvas, paintables, loadImageService) {
571
- const imageTypes = [];
572
- for (const singleImage of paintables.items) {
573
- const resource = singleImage.resource && singleImage.resource.type === "SpecificResource" ? singleImage.resource.source : singleImage.resource;
574
- if (!resource.id) {
575
- return unsupportedStrategy("No resource Identifier");
576
- }
577
- let imageService = void 0;
578
- if (resource.service) {
579
- const imageServices = getImageServices(resource);
580
- if (imageServices[0]) {
581
- imageService = loadImageService(imageServices[0], canvas);
582
- }
583
- }
584
- const { selector: imageTarget, source } = expandTarget(singleImage.target);
585
- if (source.id !== canvas.id) {
586
- continue;
587
- }
588
- const defaultTarget = {
589
- type: "BoxSelector",
590
- spatial: {
591
- x: 0,
592
- y: 0,
593
- width: canvas.width,
594
- height: canvas.height
595
- }
596
- };
597
- const target = imageTarget ? imageTarget.type === "TemporalSelector" ? {
598
- type: "TemporalBoxSelector",
599
- temporal: imageTarget.temporal,
600
- spatial: defaultTarget.spatial
601
- } : imageTarget : null;
602
- const defaultImageSelector = {
603
- type: "BoxSelector",
604
- spatial: {
605
- x: 0,
606
- y: 0,
607
- width: canvas.width,
608
- height: canvas.height
609
- }
610
- };
611
- const imageSelector = singleImage.resource.type === "SpecificResource" ? expandTarget(singleImage.resource) : null;
612
- const selector = imageSelector && imageSelector.selector && (imageSelector.selector.type === "BoxSelector" || imageSelector.selector.type === "TemporalBoxSelector") ? {
613
- type: "BoxSelector",
614
- spatial: {
615
- x: imageSelector.selector.spatial.x,
616
- y: imageSelector.selector.spatial.y,
617
- width: imageSelector.selector.spatial.width,
618
- height: imageSelector.selector.spatial.height
619
- }
620
- } : defaultImageSelector;
621
- const imageType = {
622
- id: resource.id,
623
- type: "Image",
624
- width: target ? resource.width : canvas.width,
625
- height: target ? resource.height : canvas.height,
626
- service: imageService,
627
- sizes: imageService && imageService.sizes ? imageService.sizes : resource.width && resource.height ? [{ width: resource.width, height: resource.height }] : [],
628
- target: target && target.type !== "PointSelector" ? target : defaultTarget,
629
- selector
630
- };
631
- imageTypes.push(imageType);
632
- }
633
- return {
634
- type: "images",
635
- image: imageTypes[0],
636
- images: imageTypes,
637
- choice: paintables.choice
638
- };
639
- }
640
-
641
- var __defProp$3 = Object.defineProperty;
642
- var __defProps$3 = Object.defineProperties;
643
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
644
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
645
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
646
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
647
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
648
- var __spreadValues$3 = (a, b) => {
649
- for (var prop in b || (b = {}))
650
- if (__hasOwnProp$3.call(b, prop))
651
- __defNormalProp$3(a, prop, b[prop]);
652
- if (__getOwnPropSymbols$3)
653
- for (var prop of __getOwnPropSymbols$3(b)) {
654
- if (__propIsEnum$3.call(b, prop))
655
- __defNormalProp$3(a, prop, b[prop]);
656
- }
657
- return a;
658
- };
659
- var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
660
- function useAnnotation(options = {}, deps = []) {
661
- const { id, selector } = options;
662
- const ctx = useResourceContext();
663
- const vault = useVault();
664
- const annotationId = id ? id : ctx.annotation;
665
- const annotation = useVaultSelector((s) => annotationId ? s.iiif.entities.Annotation[annotationId] : void 0, [annotationId]);
666
- const body = useVaultSelector((s) => annotation && annotation.body ? annotation.body.map((singleBody) => singleBody ? s.iiif.entities[singleBody.type][singleBody.id] : null).filter(Boolean) : [], [annotation]);
667
- return useMemo(() => {
668
- if (!annotation) {
669
- return void 0;
670
- }
671
- const newAnnotation = __spreadProps$3(__spreadValues$3({}, annotation), {
672
- body,
673
- target: expandTarget(annotation.target, { typeMap: vault.getState().iiif.mapping })
674
- });
675
- if (selector) {
676
- return selector(newAnnotation);
677
- }
678
- return newAnnotation;
679
- }, [annotation, selector, body, ...deps]);
680
- }
681
-
682
941
  function useManifest(options = {}, deps = []) {
683
942
  const { id, selector } = options;
684
943
  const ctx = useResourceContext();
@@ -696,22 +955,6 @@ function useManifest(options = {}, deps = []) {
696
955
  }, [manifest, selector, ...deps]);
697
956
  }
698
957
 
699
- function useCanvas(options = {}, deps = []) {
700
- const { id, selector } = options;
701
- const ctx = useResourceContext();
702
- const canvasId = id ? id : ctx.canvas;
703
- const canvas = useVaultSelector((s) => canvasId ? s.iiif.entities.Canvas[canvasId] : void 0, [canvasId]);
704
- return useMemo(() => {
705
- if (!canvas) {
706
- return void 0;
707
- }
708
- if (selector) {
709
- return selector(canvas);
710
- }
711
- return canvas;
712
- }, [canvas, selector, ...deps]);
713
- }
714
-
715
958
  function getMeta$1(state, resourceId) {
716
959
  var _a;
717
960
  const resourceMeta = (_a = state == null ? void 0 : state.iiif) == null ? void 0 : _a.meta[resourceId];
@@ -773,21 +1016,21 @@ function flattenAnnotationPageIds({
773
1016
  return foundIds;
774
1017
  }
775
1018
 
776
- var __defProp$2 = Object.defineProperty;
1019
+ var __defProp$3 = Object.defineProperty;
777
1020
  var __defProps$2 = Object.defineProperties;
778
1021
  var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
779
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
780
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
781
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
782
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
783
- var __spreadValues$2 = (a, b) => {
1022
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
1023
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
1024
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
1025
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1026
+ var __spreadValues$3 = (a, b) => {
784
1027
  for (var prop in b || (b = {}))
785
- if (__hasOwnProp$2.call(b, prop))
786
- __defNormalProp$2(a, prop, b[prop]);
787
- if (__getOwnPropSymbols$2)
788
- for (var prop of __getOwnPropSymbols$2(b)) {
789
- if (__propIsEnum$2.call(b, prop))
790
- __defNormalProp$2(a, prop, b[prop]);
1028
+ if (__hasOwnProp$3.call(b, prop))
1029
+ __defNormalProp$3(a, prop, b[prop]);
1030
+ if (__getOwnPropSymbols$3)
1031
+ for (var prop of __getOwnPropSymbols$3(b)) {
1032
+ if (__propIsEnum$3.call(b, prop))
1033
+ __defNormalProp$3(a, prop, b[prop]);
791
1034
  }
792
1035
  return a;
793
1036
  };
@@ -822,7 +1065,7 @@ function useAnnotationPageManager(resourceId, options = {}) {
822
1065
  if (existingResources && !existingResources[resourceId]) {
823
1066
  return existingResources;
824
1067
  }
825
- return __spreadProps$2(__spreadValues$2({}, existingResources || {}), {
1068
+ return __spreadProps$2(__spreadValues$3({}, existingResources || {}), {
826
1069
  [resourceId]: false
827
1070
  });
828
1071
  });
@@ -849,7 +1092,7 @@ function useAnnotationPageManager(resourceId, options = {}) {
849
1092
  if (existingResources && existingResources[resourceId]) {
850
1093
  return existingResources;
851
1094
  }
852
- return __spreadProps$2(__spreadValues$2({}, existingResources || {}), {
1095
+ return __spreadProps$2(__spreadValues$3({}, existingResources || {}), {
853
1096
  [resourceId]: true
854
1097
  });
855
1098
  });
@@ -862,186 +1105,94 @@ function useAnnotationPageManager(resourceId, options = {}) {
862
1105
  };
863
1106
  }
864
1107
 
865
- function usePaintingAnnotations(options = {}) {
866
- const canvas = useCanvas(options.canvasId ? { id: options.canvasId } : void 0);
867
- return useVaultSelector((state, vault) => {
868
- if (!canvas) {
869
- return [];
870
- }
871
- const annotationPages = vault.get(canvas.items);
872
- const flatAnnotations = [];
873
- for (const page of annotationPages) {
874
- flatAnnotations.push(...vault.get(page.items));
875
- }
876
- return flatAnnotations;
877
- }, [canvas]);
1108
+ function useResources(ids, type) {
1109
+ return useVaultSelector((state, vault) => vault.get(ids.map((id) => ({ id, type }))), [ids, type]);
878
1110
  }
879
1111
 
880
- function useAnnotationsAtTime(time, options = {}) {
881
- const allAnnotations = usePaintingAnnotations(options);
882
- return allAnnotations;
883
- }
884
-
885
- function useCanvasClock(canvasId, autoplay = false) {
1112
+ const ImageServiceLoaderContext = React.createContext(new ImageServiceLoader());
1113
+ function useImageServiceLoader() {
1114
+ return useContext(ImageServiceLoaderContext);
886
1115
  }
887
1116
 
888
- function useCollection(options, deps = []) {
889
- const { id, selector } = options;
890
- const ctx = useResourceContext();
891
- const collectionId = id ? id : ctx.collection;
892
- const collection = useVaultSelector((s) => collectionId ? s.iiif.entities.Collection[collectionId] : void 0, [collectionId]);
893
- return useMemo(() => {
894
- if (!collection) {
895
- return void 0;
896
- }
897
- if (selector) {
898
- return selector(collection);
1117
+ var __defProp$2 = Object.defineProperty;
1118
+ var __defProps$1 = Object.defineProperties;
1119
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
1120
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
1121
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
1122
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
1123
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1124
+ var __spreadValues$2 = (a, b) => {
1125
+ for (var prop in b || (b = {}))
1126
+ if (__hasOwnProp$2.call(b, prop))
1127
+ __defNormalProp$2(a, prop, b[prop]);
1128
+ if (__getOwnPropSymbols$2)
1129
+ for (var prop of __getOwnPropSymbols$2(b)) {
1130
+ if (__propIsEnum$2.call(b, prop))
1131
+ __defNormalProp$2(a, prop, b[prop]);
899
1132
  }
900
- return collection;
901
- }, [collection, selector, ...deps]);
902
- }
903
-
904
- function useDispatch() {
905
- const vault = useVault();
906
- const store = vault.getStore();
907
- return useMemo(() => {
908
- return (action) => store.dispatch(action);
909
- }, [store]);
910
- }
911
-
912
- function useEventListener(resource, name, listener, scope, deps = []) {
913
- const vault = useVault();
914
- const helper = useMemo(() => createEventsHelper(vault), [vault]);
1133
+ return a;
1134
+ };
1135
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
1136
+ function useLoadImageService() {
1137
+ const loader = useImageServiceLoader();
1138
+ const [imageServiceStatus, setImageServiceStatus] = useState({});
1139
+ const didUnmount = useRef(false);
915
1140
  useEffect(() => {
916
- const currentResource = resource;
917
- if (!currentResource) {
918
- return () => {
919
- };
920
- }
921
- helper.addEventListener(currentResource, name, listener, scope);
922
1141
  return () => {
923
- helper.removeEventListener(currentResource, name, listener);
924
- };
925
- }, [helper, resource, name, ...deps]);
926
- }
927
-
928
- function useExistingVault() {
929
- const oldContext = useContext(ReactVaultContext);
930
- return oldContext && oldContext.vault ? oldContext.vault : globalVault();
931
- }
932
-
933
- function useExternalCollection(idOrRef, options) {
934
- const { id, isLoaded, error, resource, requestId, cached } = useExternalResource(idOrRef, options);
935
- return { id, isLoaded, error, manifest: resource, requestId, cached };
936
- }
937
-
938
- var __async = (__this, __arguments, generator) => {
939
- return new Promise((resolve, reject) => {
940
- var fulfilled = (value) => {
941
- try {
942
- step(generator.next(value));
943
- } catch (e) {
944
- reject(e);
945
- }
946
- };
947
- var rejected = (value) => {
948
- try {
949
- step(generator.throw(value));
950
- } catch (e) {
951
- reject(e);
952
- }
1142
+ didUnmount.current = true;
953
1143
  };
954
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
955
- step((generator = generator.apply(__this, __arguments)).next());
956
- });
957
- };
958
- function useImageService({ cacheKey } = {}) {
959
- const canvas = useCanvas();
960
- const annotations = usePaintingAnnotations();
961
- const vault = useVault();
962
- const imageService = useImageServiceLoader();
963
- const [_data, setData] = useState(void 0);
964
- const [isFetching, setIsFetching] = useState(false);
965
- const [status, setStatus] = useState("idle");
966
- const [error, setError] = useState(void 0);
967
- const key = canvas ? canvas.id : "undefined";
968
- const initialData = useMemo(() => {
969
- try {
970
- if (canvas && annotations.length) {
971
- const annotation = annotations[0];
972
- const resource = vault.get(annotation.body[0]);
973
- const imageServices = getImageServices(resource);
974
- const firstImageService = imageServices[0];
975
- if (!firstImageService) {
976
- return void 0;
1144
+ }, []);
1145
+ const loadImageService = useCallback((imageService, { height, width }) => {
1146
+ if (imageService) {
1147
+ const imageServiceId = imageService.id || imageService["@id"];
1148
+ const syncLoaded = loader.loadServiceSync({
1149
+ id: imageServiceId,
1150
+ width: imageService.width || width,
1151
+ height: imageService.height || height
1152
+ });
1153
+ if (syncLoaded) {
1154
+ imageService = syncLoaded;
1155
+ } else if (!imageServiceStatus[imageServiceId]) {
1156
+ if (!didUnmount.current) {
1157
+ setImageServiceStatus((r) => {
1158
+ return __spreadProps$1(__spreadValues$2({}, r), {
1159
+ [imageServiceId]: "loading"
1160
+ });
1161
+ });
977
1162
  }
978
- return imageService.loadServiceSync({
979
- id: firstImageService.id || firstImageService["@id"],
980
- width: firstImageService.width || canvas.width,
981
- height: firstImageService.height || canvas.height
982
- }) || void 0;
983
- }
984
- } catch (e) {
985
- console.error(e);
986
- }
987
- return void 0;
988
- }, [key, cacheKey, canvas]);
989
- const data = status === "success" && _data ? _data : initialData;
990
- useEffect(() => {
991
- (() => __async(this, null, function* () {
992
- try {
993
- if (canvas && annotations.length) {
994
- const annotation = annotations[0];
995
- const resource = vault.get(annotation.body[0]);
996
- const imageServices = getImageServices(resource);
997
- const firstImageService = imageServices[0];
998
- if (!firstImageService) {
999
- return;
1000
- }
1001
- setIsFetching(true);
1002
- setStatus("loading");
1003
- try {
1004
- const loadedService = (yield imageService.loadService({
1005
- id: firstImageService.id || firstImageService["@id"],
1006
- width: firstImageService.width || canvas.width,
1007
- height: firstImageService.height || canvas.height
1008
- })) || void 0;
1009
- setData(loadedService);
1010
- setStatus("success");
1011
- setIsFetching(false);
1012
- } catch (err) {
1013
- setStatus("error");
1014
- setError(err);
1163
+ loader.loadService({
1164
+ id: imageServiceId,
1165
+ width: imageService.width || width,
1166
+ height: imageService.height || height
1167
+ }).then(() => {
1168
+ if (!didUnmount.current) {
1169
+ setImageServiceStatus((r) => {
1170
+ return __spreadProps$1(__spreadValues$2({}, r), {
1171
+ [imageServiceId]: "done"
1172
+ });
1173
+ });
1015
1174
  }
1016
- }
1017
- } catch (err) {
1018
- setStatus("error");
1019
- setError(err);
1175
+ });
1020
1176
  }
1021
- }))();
1022
- }, [key, cacheKey]);
1023
- return useMemo(() => {
1024
- return {
1025
- data,
1026
- isFetching,
1027
- status,
1028
- error
1029
- };
1030
- }, [data, isFetching, status, error]);
1177
+ }
1178
+ return imageService;
1179
+ }, [loader, imageServiceStatus]);
1180
+ return [loadImageService, imageServiceStatus];
1031
1181
  }
1032
1182
 
1033
- function useImageTile() {
1034
- const imageService = useImageService();
1035
- return {
1036
- isLoading: imageService.isFetching,
1037
- tile: imageService.data ? {
1038
- id: imageService.data.id || imageService.data["@id"],
1039
- width: imageService.data.width,
1040
- height: imageService.data.height,
1041
- imageService: imageService.data,
1042
- thumbnail: void 0
1043
- } : null
1044
- };
1183
+ function usePaintingAnnotations(options = {}) {
1184
+ const canvas = useCanvas(options.canvasId ? { id: options.canvasId } : void 0);
1185
+ return useVaultSelector((state, vault) => {
1186
+ if (!canvas) {
1187
+ return [];
1188
+ }
1189
+ const annotationPages = vault.get(canvas.items);
1190
+ const flatAnnotations = [];
1191
+ for (const page of annotationPages) {
1192
+ flatAnnotations.push(...vault.get(page.items));
1193
+ }
1194
+ return flatAnnotations;
1195
+ }, [canvas]);
1045
1196
  }
1046
1197
 
1047
1198
  function usePaintables(options, deps = []) {
@@ -1088,60 +1239,149 @@ function usePaintables(options, deps = []) {
1088
1239
  return [paintables, actions];
1089
1240
  }
1090
1241
 
1091
- function useRange(options = {}, deps = []) {
1092
- const { id, selector } = options;
1093
- const ctx = useResourceContext();
1094
- const rangeId = id ? id : ctx.range;
1095
- const range = useVaultSelector((s) => rangeId ? s.iiif.entities.Range[rangeId] : void 0, [rangeId]);
1096
- return useMemo(() => {
1097
- if (!range) {
1098
- return void 0;
1242
+ function getImageStrategy(canvas, paintables, loadImageService) {
1243
+ const imageTypes = [];
1244
+ for (const singleImage of paintables.items) {
1245
+ const resource = singleImage.resource && singleImage.resource.type === "SpecificResource" ? singleImage.resource.source : singleImage.resource;
1246
+ if (!resource.id) {
1247
+ return unsupportedStrategy("No resource Identifier");
1099
1248
  }
1100
- if (selector) {
1101
- return selector(range);
1249
+ let imageService = void 0;
1250
+ if (resource.service) {
1251
+ const imageServices = getImageServices(resource);
1252
+ if (imageServices[0]) {
1253
+ imageService = loadImageService(imageServices[0], canvas);
1254
+ }
1102
1255
  }
1103
- return range;
1104
- }, [range, selector, ...deps]);
1105
- }
1106
-
1107
- function useResourceEvents(resource, scope) {
1108
- const vault = useVault();
1109
- const helper = useMemo(() => createEventsHelper(vault), [vault]);
1110
- const hooks = useVaultSelector(() => {
1111
- if (resource && resource.id) {
1112
- return vault.getResourceMeta(resource.id, "eventManager");
1256
+ const { selector: imageTarget, source } = expandTarget(singleImage.target);
1257
+ if (source.id !== canvas.id) {
1258
+ continue;
1113
1259
  }
1114
- return null;
1115
- }, [resource]);
1116
- return useMemo(() => {
1117
- return resource ? helper.getListenersAsProps(resource, scope) : {};
1118
- }, [hooks, resource, vault, scope]);
1119
- }
1120
-
1121
- function useResources(ids, type) {
1122
- return useVaultSelector((state, vault) => vault.get(ids.map((id) => ({ id, type }))), [ids, type]);
1260
+ const defaultTarget = {
1261
+ type: "BoxSelector",
1262
+ spatial: {
1263
+ x: 0,
1264
+ y: 0,
1265
+ width: canvas.width,
1266
+ height: canvas.height
1267
+ }
1268
+ };
1269
+ const target = imageTarget ? imageTarget.type === "TemporalSelector" ? {
1270
+ type: "TemporalBoxSelector",
1271
+ temporal: imageTarget.temporal,
1272
+ spatial: defaultTarget.spatial
1273
+ } : imageTarget : null;
1274
+ const defaultImageSelector = {
1275
+ type: "BoxSelector",
1276
+ spatial: {
1277
+ x: 0,
1278
+ y: 0,
1279
+ width: canvas.width,
1280
+ height: canvas.height
1281
+ }
1282
+ };
1283
+ const imageSelector = singleImage.resource.type === "SpecificResource" ? expandTarget(singleImage.resource) : null;
1284
+ const selector = imageSelector && imageSelector.selector && (imageSelector.selector.type === "BoxSelector" || imageSelector.selector.type === "TemporalBoxSelector") ? {
1285
+ type: "BoxSelector",
1286
+ spatial: {
1287
+ x: imageSelector.selector.spatial.x,
1288
+ y: imageSelector.selector.spatial.y,
1289
+ width: imageSelector.selector.spatial.width,
1290
+ height: imageSelector.selector.spatial.height
1291
+ }
1292
+ } : defaultImageSelector;
1293
+ const imageType = {
1294
+ id: resource.id,
1295
+ type: "Image",
1296
+ width: target ? resource.width : canvas.width,
1297
+ height: target ? resource.height : canvas.height,
1298
+ service: imageService,
1299
+ sizes: imageService && imageService.sizes ? imageService.sizes : resource.width && resource.height ? [{ width: resource.width, height: resource.height }] : [],
1300
+ target: target && target.type !== "PointSelector" ? target : defaultTarget,
1301
+ selector
1302
+ };
1303
+ imageTypes.push(imageType);
1304
+ }
1305
+ return {
1306
+ type: "images",
1307
+ image: imageTypes[0],
1308
+ images: imageTypes,
1309
+ choice: paintables.choice
1310
+ };
1123
1311
  }
1124
1312
 
1125
- function useSearchService() {
1313
+ var __defProp$1 = Object.defineProperty;
1314
+ var __defProps = Object.defineProperties;
1315
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
1316
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
1317
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
1318
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
1319
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1320
+ var __spreadValues$1 = (a, b) => {
1321
+ for (var prop in b || (b = {}))
1322
+ if (__hasOwnProp$1.call(b, prop))
1323
+ __defNormalProp$1(a, prop, b[prop]);
1324
+ if (__getOwnPropSymbols$1)
1325
+ for (var prop of __getOwnPropSymbols$1(b)) {
1326
+ if (__propIsEnum$1.call(b, prop))
1327
+ __defNormalProp$1(a, prop, b[prop]);
1328
+ }
1329
+ return a;
1330
+ };
1331
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1332
+ function useRenderingStrategy(options) {
1126
1333
  const manifest = useManifest();
1127
- return manifest ? manifest.service.find((service) => service.profile === "SearchService1" || service.profile === "http://iiif.io/api/search/1/search") : void 0;
1128
- }
1129
-
1130
- function useStyleHelper() {
1131
- const vault = useVault();
1132
- return useMemo(() => createStylesHelper(vault), [vault]);
1133
- }
1134
-
1135
- function useStyles(resource, scope) {
1334
+ const canvas = useCanvas();
1136
1335
  const vault = useVault();
1137
- const helper = useMemo(() => createStylesHelper(vault), [vault]);
1138
- return useVaultSelector(() => {
1139
- if (!resource) {
1140
- return null;
1336
+ const [loadImageService, imageServiceStatus] = useLoadImageService();
1337
+ const { enabledPageIds } = useAnnotationPageManager((options == null ? void 0 : options.annotationPageManagerId) || (manifest == null ? void 0 : manifest.id) || (canvas == null ? void 0 : canvas.id), {
1338
+ all: false
1339
+ });
1340
+ const enabledPages = useResources(enabledPageIds, "AnnotationPage");
1341
+ const supports = (options == null ? void 0 : options.strategies) || ["images", "media", "complex-timeline"];
1342
+ const [paintables, actions] = usePaintables(options, [imageServiceStatus]);
1343
+ const strategy = useMemo(() => {
1344
+ if (!canvas || paintables.types.length === 0) {
1345
+ return unknownResponse;
1141
1346
  }
1142
- const styles = helper.getAppliedStyles(resource.id);
1143
- return styles ? scope ? styles[scope] : styles : void 0;
1144
- }, [resource, scope]);
1347
+ if (paintables.types.length !== 1) {
1348
+ if (supports.indexOf("complex-timeline") === -1) {
1349
+ return unsupportedStrategy("Complex timeline not supported");
1350
+ }
1351
+ return unsupportedStrategy("ComplexTimelineStrategy not yet supported");
1352
+ }
1353
+ const mainType = paintables.types[0];
1354
+ if (mainType === "image") {
1355
+ if (supports.indexOf("images") === -1) {
1356
+ return unsupportedStrategy("Image not supported");
1357
+ }
1358
+ return getImageStrategy(canvas, paintables, loadImageService);
1359
+ }
1360
+ if (mainType === "audio") {
1361
+ if (supports.indexOf("media") === -1) {
1362
+ return unsupportedStrategy("Media not supported");
1363
+ }
1364
+ return unsupportedStrategy("Audio strategy not yet supported");
1365
+ }
1366
+ if (mainType === "video") {
1367
+ if (supports.indexOf("media") === -1) {
1368
+ return unsupportedStrategy("Media not supported");
1369
+ }
1370
+ return unsupportedStrategy("Video strategy not yet supported");
1371
+ }
1372
+ return unknownResponse;
1373
+ }, [canvas, paintables, vault, actions.makeChoice]);
1374
+ return useMemo(() => {
1375
+ if (strategy.type === "unknown") {
1376
+ return [strategy, emptyActions];
1377
+ }
1378
+ return [
1379
+ __spreadProps(__spreadValues$1({}, strategy), {
1380
+ annotations: { pages: enabledPages }
1381
+ }),
1382
+ actions
1383
+ ];
1384
+ }, [strategy, enabledPages]);
1145
1385
  }
1146
1386
 
1147
1387
  const useVaultEffect = (callback, deps = []) => {
@@ -1178,285 +1418,311 @@ function useThumbnail(request, dereference, { canvasId, manifestId } = {}) {
1178
1418
  return thumbnail;
1179
1419
  }
1180
1420
 
1181
- var __defProp$1 = Object.defineProperty;
1182
- var __defProps$1 = Object.defineProperties;
1183
- var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
1184
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
1185
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
1186
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
1187
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1188
- var __spreadValues$1 = (a, b) => {
1421
+ var __defProp = Object.defineProperty;
1422
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1423
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
1424
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
1425
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1426
+ var __spreadValues = (a, b) => {
1189
1427
  for (var prop in b || (b = {}))
1190
- if (__hasOwnProp$1.call(b, prop))
1191
- __defNormalProp$1(a, prop, b[prop]);
1192
- if (__getOwnPropSymbols$1)
1193
- for (var prop of __getOwnPropSymbols$1(b)) {
1194
- if (__propIsEnum$1.call(b, prop))
1195
- __defNormalProp$1(a, prop, b[prop]);
1428
+ if (__hasOwnProp.call(b, prop))
1429
+ __defNormalProp(a, prop, b[prop]);
1430
+ if (__getOwnPropSymbols)
1431
+ for (var prop of __getOwnPropSymbols(b)) {
1432
+ if (__propIsEnum.call(b, prop))
1433
+ __defNormalProp(a, prop, b[prop]);
1196
1434
  }
1197
1435
  return a;
1198
1436
  };
1199
- var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
1200
- function useLoadImageService() {
1201
- const loader = useImageServiceLoader();
1202
- const [imageServiceStatus, setImageServiceStatus] = useState({});
1203
- const didUnmount = useRef(false);
1437
+ function RenderCanvas({ x, y, onChoiceChange, registerActions, defaultChoices, isStatic }) {
1438
+ const canvas = useCanvas();
1439
+ const elementProps = useResourceEvents(canvas, ["deep-zoom"]);
1440
+ const [virtualPage] = useVirtualAnnotationPageContext();
1441
+ const vault = useVault();
1442
+ const helper = useMemo(() => createStylesHelper(vault), [vault]);
1443
+ const [strategy, actions] = useRenderingStrategy({
1444
+ strategies: ["images"],
1445
+ defaultChoices: defaultChoices == null ? void 0 : defaultChoices.map(({ id }) => id)
1446
+ });
1447
+ const choice = strategy.type === "images" ? strategy.choice : void 0;
1204
1448
  useEffect(() => {
1205
- return () => {
1206
- didUnmount.current = true;
1207
- };
1208
- }, []);
1209
- const loadImageService = useCallback((imageService, { height, width }) => {
1210
- if (imageService) {
1211
- const imageServiceId = imageService.id || imageService["@id"];
1212
- const syncLoaded = loader.loadServiceSync({
1213
- id: imageServiceId,
1214
- width: imageService.width || width,
1215
- height: imageService.height || height
1216
- });
1217
- if (syncLoaded) {
1218
- imageService = syncLoaded;
1219
- } else if (!imageServiceStatus[imageServiceId]) {
1220
- if (!didUnmount.current) {
1221
- setImageServiceStatus((r) => {
1222
- return __spreadProps$1(__spreadValues$1({}, r), {
1223
- [imageServiceId]: "loading"
1224
- });
1449
+ if (registerActions) {
1450
+ registerActions(actions);
1451
+ }
1452
+ }, [strategy.annotations]);
1453
+ useEffect(() => {
1454
+ if (defaultChoices) {
1455
+ for (const choice2 of defaultChoices) {
1456
+ if (typeof choice2.opacity !== "undefined") {
1457
+ helper.applyStyles({ id: choice2.id }, "atlas", {
1458
+ opacity: choice2.opacity
1225
1459
  });
1226
1460
  }
1227
- loader.loadService({
1228
- id: imageServiceId,
1229
- width: imageService.width || width,
1230
- height: imageService.height || height
1231
- }).then(() => {
1232
- if (!didUnmount.current) {
1233
- setImageServiceStatus((r) => {
1234
- return __spreadProps$1(__spreadValues$1({}, r), {
1235
- [imageServiceId]: "done"
1236
- });
1237
- });
1238
- }
1239
- });
1240
1461
  }
1241
1462
  }
1242
- return imageService;
1243
- }, [loader, imageServiceStatus]);
1244
- return [loadImageService, imageServiceStatus];
1463
+ }, [defaultChoices]);
1464
+ useLayoutEffect(() => {
1465
+ if (onChoiceChange) {
1466
+ onChoiceChange(choice);
1467
+ }
1468
+ }, [choice]);
1469
+ const thumbnail = useThumbnail({ maxWidth: 256, maxHeight: 256 });
1470
+ if (!canvas) {
1471
+ return null;
1472
+ }
1473
+ if (strategy.type === "unknown") {
1474
+ if (thumbnail && thumbnail.type === "fixed") {
1475
+ return /* @__PURE__ */ React.createElement("world-object", {
1476
+ height: canvas.height,
1477
+ width: canvas.width,
1478
+ x,
1479
+ y
1480
+ }, /* @__PURE__ */ React.createElement("world-image", {
1481
+ uri: thumbnail.id,
1482
+ target: { x: 0, y: 0, width: canvas.width, height: canvas.height },
1483
+ display: thumbnail.width && thumbnail.height ? {
1484
+ width: thumbnail.width,
1485
+ height: thumbnail.height
1486
+ } : void 0
1487
+ }));
1488
+ }
1489
+ throw new Error("Unknown image strategy");
1490
+ }
1491
+ const annotations = /* @__PURE__ */ React.createElement(Fragment, null, virtualPage ? /* @__PURE__ */ React.createElement(RenderAnnotationPage, {
1492
+ page: virtualPage
1493
+ }) : null, strategy.annotations && strategy.annotations.pages ? strategy.annotations.pages.map((page) => {
1494
+ return /* @__PURE__ */ React.createElement(RenderAnnotationPage, {
1495
+ key: page.id,
1496
+ page
1497
+ });
1498
+ }) : null);
1499
+ return /* @__PURE__ */ React.createElement("world-object", __spreadValues({
1500
+ key: strategy.type,
1501
+ height: canvas.height,
1502
+ width: canvas.width,
1503
+ x,
1504
+ y
1505
+ }, elementProps), strategy.type === "images" ? strategy.images.map((image, idx) => {
1506
+ return /* @__PURE__ */ React.createElement(RenderImage, {
1507
+ isStatic,
1508
+ key: image.id,
1509
+ image,
1510
+ id: image.id,
1511
+ thumbnail: idx === 0 ? thumbnail : void 0,
1512
+ annotations
1513
+ });
1514
+ }) : null);
1245
1515
  }
1246
1516
 
1247
- const IMPORT_ENTITIES = "@iiif/IMPORT_ENTITIES";
1248
- const MODIFY_ENTITY_FIELD = "@iiif/MODIFY_ENTITY_FIELD";
1249
- const REORDER_ENTITY_FIELD = "@iiif/REORDER_ENTITY_FIELD";
1250
- const ADD_REFERENCE = "@iiif/ADD_REFERENCE";
1251
- const REMOVE_REFERENCE = "@iiif/REMOVE_REFERENCE";
1252
- const importEntities = createAction(IMPORT_ENTITIES)();
1253
- const modifyEntityField = createAction(MODIFY_ENTITY_FIELD)();
1254
- const reorderEntityField = createAction(REORDER_ENTITY_FIELD)();
1255
- const addReference = createAction(ADD_REFERENCE)();
1256
- const removeReference = createAction(REMOVE_REFERENCE)();
1257
- const entityActions = { importEntities, modifyEntityField, reorderEntityField, addReference, removeReference };
1517
+ const CanvasPanel = {
1518
+ RenderImage,
1519
+ RenderCanvas,
1520
+ RenderAnnotationPage,
1521
+ RenderAnnotation,
1522
+ Viewer
1523
+ };
1258
1524
 
1259
- const ADD_MAPPING = "@iiif/ADD_MAPPING";
1260
- const ADD_MAPPINGS = "@iiif/ADD_MAPPINGS";
1261
- createAction(ADD_MAPPING)();
1262
- createAction(ADD_MAPPINGS)();
1525
+ const AnnotationContext = ({ annotation, children }) => {
1526
+ return /* @__PURE__ */ React.createElement(ResourceProvider, {
1527
+ value: { annotation }
1528
+ }, children);
1529
+ };
1263
1530
 
1264
- const SET_META_VALUE = "@iiif/SET_META_VALUE";
1265
- const SET_META_VALUE_DYNAMIC = "@iiif/SET_META_VALUE_DYNAMIC";
1266
- const UNSET_META_VALUE = "@iiif/UNSET_META_VALUE";
1267
- createAction(SET_META_VALUE)();
1268
- createAction(SET_META_VALUE_DYNAMIC)();
1269
- createAction(UNSET_META_VALUE)();
1270
- const REQUEST_RESOURCE = "@iiif/REQUEST_RESOURCE";
1271
- const REQUEST_ERROR = "@iiif/REQUEST_ERROR";
1272
- const REQUEST_MISMATCH = "@iiif/REQUEST_MISMATCH";
1273
- const REQUEST_COMPLETE = "@iiif/REQUEST_COMPLETE";
1274
- const REQUEST_OFFLINE_RESOURCE = "@iiif/REQUEST_OFFLINE_RESOURCE";
1275
- createAction(REQUEST_RESOURCE)();
1276
- createAction(REQUEST_ERROR)();
1277
- createAction(REQUEST_MISMATCH)();
1278
- createAction(REQUEST_COMPLETE)();
1279
- createAction(REQUEST_OFFLINE_RESOURCE)();
1531
+ const CollectionContext = ({ collection, children }) => {
1532
+ return /* @__PURE__ */ React.createElement(ResourceProvider, {
1533
+ value: { collection }
1534
+ }, children);
1535
+ };
1280
1536
 
1281
- const BATCH_ACTIONS = "@iiif/BATCH";
1282
- const BATCH_IMPORT = "@iiif/BATCH_IMPORT";
1283
- createAction(BATCH_ACTIONS)();
1284
- createAction(BATCH_IMPORT)();
1537
+ const RangeContext = ({ range, children }) => {
1538
+ return /* @__PURE__ */ React.createElement(ResourceProvider, {
1539
+ value: { range }
1540
+ }, children);
1541
+ };
1285
1542
 
1286
- function isVaultActivated(obj) {
1287
- return typeof obj !== "string" && obj && obj.bindToVault;
1543
+ function useAnnotationsAtTime(time, options = {}) {
1544
+ const allAnnotations = usePaintingAnnotations(options);
1545
+ return allAnnotations;
1288
1546
  }
1289
- function useVirtualAnnotationPage() {
1547
+
1548
+ function useCanvasClock(canvasId, autoplay = false) {
1549
+ }
1550
+
1551
+ function useCollection(options, deps = []) {
1552
+ const { id, selector } = options;
1553
+ const ctx = useResourceContext();
1554
+ const collectionId = id ? id : ctx.collection;
1555
+ const collection = useVaultSelector((s) => collectionId ? s.iiif.entities.Collection[collectionId] : void 0, [collectionId]);
1556
+ return useMemo(() => {
1557
+ if (!collection) {
1558
+ return void 0;
1559
+ }
1560
+ if (selector) {
1561
+ return selector(collection);
1562
+ }
1563
+ return collection;
1564
+ }, [collection, selector, ...deps]);
1565
+ }
1566
+
1567
+ function useEventListener(resource, name, listener, scope, deps = []) {
1290
1568
  const vault = useVault();
1291
- const sources = useRef([]);
1292
- const dispatch = useDispatch();
1293
- const virtualId = useMemo(() => {
1294
- return `vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random() * 1e9).toString(16)}`;
1295
- }, []);
1296
- useLayoutEffect(() => {
1297
- const page = {
1298
- id: virtualId,
1299
- type: "AnnotationPage",
1300
- behavior: [],
1301
- motivation: null,
1302
- label: null,
1303
- thumbnail: [],
1304
- summary: null,
1305
- requiredStatement: null,
1306
- metadata: [],
1307
- rights: null,
1308
- provider: [],
1309
- items: [],
1310
- seeAlso: [],
1311
- homepage: [],
1312
- logo: [],
1313
- rendering: [],
1314
- service: []
1569
+ const helper = useMemo(() => createEventsHelper(vault), [vault]);
1570
+ useEffect(() => {
1571
+ const currentResource = resource;
1572
+ if (!currentResource) {
1573
+ return () => {
1574
+ };
1575
+ }
1576
+ helper.addEventListener(currentResource, name, listener, scope);
1577
+ return () => {
1578
+ helper.removeEventListener(currentResource, name, listener);
1315
1579
  };
1316
- dispatch(entityActions.importEntities({
1317
- entities: {
1318
- AnnotationPage: {
1319
- [page.id]: page
1320
- }
1580
+ }, [helper, resource, name, ...deps]);
1581
+ }
1582
+
1583
+ function useExistingVault() {
1584
+ const oldContext = useContext(ReactVaultContext);
1585
+ return oldContext && oldContext.vault ? oldContext.vault : globalVault();
1586
+ }
1587
+
1588
+ function useExternalCollection(idOrRef, options) {
1589
+ const { id, isLoaded, error, resource, requestId, cached } = useExternalResource(idOrRef, options);
1590
+ return { id, isLoaded, error, manifest: resource, requestId, cached };
1591
+ }
1592
+
1593
+ var __async = (__this, __arguments, generator) => {
1594
+ return new Promise((resolve, reject) => {
1595
+ var fulfilled = (value) => {
1596
+ try {
1597
+ step(generator.next(value));
1598
+ } catch (e) {
1599
+ reject(e);
1321
1600
  }
1322
- }));
1323
- }, [virtualId]);
1324
- const fullPage = useVaultSelector((state) => virtualId ? state.iiif.entities.AnnotationPage[virtualId] : null, [virtualId]);
1325
- const addAnnotation = useCallback((id, atIndex) => {
1326
- if (virtualId) {
1327
- if (isVaultActivated(id)) {
1328
- const display = id;
1329
- if (!display.__vault) {
1330
- display.bindToVault(vault);
1331
- }
1332
- id = typeof display.source === "string" ? display.source : display.source.id;
1333
- sources.current[id] = display;
1334
- } else if (typeof id !== "string") {
1335
- id = id.id;
1601
+ };
1602
+ var rejected = (value) => {
1603
+ try {
1604
+ step(generator.throw(value));
1605
+ } catch (e) {
1606
+ reject(e);
1336
1607
  }
1337
- const full = vault.get({ id: virtualId, type: "AnnotationPage" });
1338
- const annotation = vault.get({ id, type: "Annotation" });
1339
- if (full && annotation) {
1340
- if (!full.items.find((r) => r.id === annotation.id)) {
1341
- dispatch(entityActions.addReference({
1342
- id: virtualId,
1343
- type: "AnnotationPage",
1344
- key: "items",
1345
- reference: {
1346
- id,
1347
- type: "Annotation"
1348
- },
1349
- index: atIndex
1350
- }));
1608
+ };
1609
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
1610
+ step((generator = generator.apply(__this, __arguments)).next());
1611
+ });
1612
+ };
1613
+ function useImageService({ cacheKey } = {}) {
1614
+ const canvas = useCanvas();
1615
+ const annotations = usePaintingAnnotations();
1616
+ const vault = useVault();
1617
+ const imageService = useImageServiceLoader();
1618
+ const [_data, setData] = useState(void 0);
1619
+ const [isFetching, setIsFetching] = useState(false);
1620
+ const [status, setStatus] = useState("idle");
1621
+ const [error, setError] = useState(void 0);
1622
+ const key = canvas ? canvas.id : "undefined";
1623
+ const initialData = useMemo(() => {
1624
+ try {
1625
+ if (canvas && annotations.length) {
1626
+ const annotation = annotations[0];
1627
+ const resource = vault.get(annotation.body[0]);
1628
+ const imageServices = getImageServices(resource);
1629
+ const firstImageService = imageServices[0];
1630
+ if (!firstImageService) {
1631
+ return void 0;
1351
1632
  }
1633
+ return imageService.loadServiceSync({
1634
+ id: firstImageService.id || firstImageService["@id"],
1635
+ width: firstImageService.width || canvas.width,
1636
+ height: firstImageService.height || canvas.height
1637
+ }) || void 0;
1352
1638
  }
1639
+ } catch (e) {
1640
+ console.error(e);
1353
1641
  }
1354
- }, [virtualId]);
1355
- const removeAnnotation = useCallback((id) => {
1356
- if (virtualId) {
1357
- if (isVaultActivated(id)) {
1358
- id = typeof id.source === "string" ? id.source : id.source.id;
1359
- } else if (typeof id !== "string") {
1360
- id = id.id;
1361
- }
1362
- if (sources.current[id]) {
1363
- sources.current[id].beforeRemove();
1364
- }
1365
- const full = vault.get({ id: virtualId, type: "AnnotationPage" });
1366
- if (full) {
1367
- dispatch(entityActions.removeReference({
1368
- id: virtualId,
1369
- type: "AnnotationPage",
1370
- key: "items",
1371
- reference: {
1372
- id,
1373
- type: "Annotation"
1642
+ return void 0;
1643
+ }, [key, cacheKey, canvas]);
1644
+ const data = status === "success" && _data ? _data : initialData;
1645
+ useEffect(() => {
1646
+ (() => __async(this, null, function* () {
1647
+ try {
1648
+ if (canvas && annotations.length) {
1649
+ const annotation = annotations[0];
1650
+ const resource = vault.get(annotation.body[0]);
1651
+ const imageServices = getImageServices(resource);
1652
+ const firstImageService = imageServices[0];
1653
+ if (!firstImageService) {
1654
+ return;
1374
1655
  }
1375
- }));
1656
+ setIsFetching(true);
1657
+ setStatus("loading");
1658
+ try {
1659
+ const loadedService = (yield imageService.loadService({
1660
+ id: firstImageService.id || firstImageService["@id"],
1661
+ width: firstImageService.width || canvas.width,
1662
+ height: firstImageService.height || canvas.height
1663
+ })) || void 0;
1664
+ setData(loadedService);
1665
+ setStatus("success");
1666
+ setIsFetching(false);
1667
+ } catch (err) {
1668
+ setStatus("error");
1669
+ setError(err);
1670
+ }
1671
+ }
1672
+ } catch (err) {
1673
+ setStatus("error");
1674
+ setError(err);
1376
1675
  }
1676
+ }))();
1677
+ }, [key, cacheKey]);
1678
+ return useMemo(() => {
1679
+ return {
1680
+ data,
1681
+ isFetching,
1682
+ status,
1683
+ error
1684
+ };
1685
+ }, [data, isFetching, status, error]);
1686
+ }
1687
+
1688
+ function useImageTile() {
1689
+ const imageService = useImageService();
1690
+ return {
1691
+ isLoading: imageService.isFetching,
1692
+ tile: imageService.data ? {
1693
+ id: imageService.data.id || imageService.data["@id"],
1694
+ width: imageService.data.width,
1695
+ height: imageService.data.height,
1696
+ imageService: imageService.data,
1697
+ thumbnail: void 0
1698
+ } : null
1699
+ };
1700
+ }
1701
+
1702
+ function useRange(options = {}, deps = []) {
1703
+ const { id, selector } = options;
1704
+ const ctx = useResourceContext();
1705
+ const rangeId = id ? id : ctx.range;
1706
+ const range = useVaultSelector((s) => rangeId ? s.iiif.entities.Range[rangeId] : void 0, [rangeId]);
1707
+ return useMemo(() => {
1708
+ if (!range) {
1709
+ return void 0;
1377
1710
  }
1378
- }, [virtualId]);
1379
- return [
1380
- fullPage,
1381
- {
1382
- addAnnotation,
1383
- removeAnnotation
1711
+ if (selector) {
1712
+ return selector(range);
1384
1713
  }
1385
- ];
1714
+ return range;
1715
+ }, [range, selector, ...deps]);
1386
1716
  }
1387
1717
 
1388
- var __defProp = Object.defineProperty;
1389
- var __defProps = Object.defineProperties;
1390
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
1391
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1392
- var __hasOwnProp = Object.prototype.hasOwnProperty;
1393
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
1394
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1395
- var __spreadValues = (a, b) => {
1396
- for (var prop in b || (b = {}))
1397
- if (__hasOwnProp.call(b, prop))
1398
- __defNormalProp(a, prop, b[prop]);
1399
- if (__getOwnPropSymbols)
1400
- for (var prop of __getOwnPropSymbols(b)) {
1401
- if (__propIsEnum.call(b, prop))
1402
- __defNormalProp(a, prop, b[prop]);
1403
- }
1404
- return a;
1405
- };
1406
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1407
- function useRenderingStrategy(options) {
1718
+ function useSearchService() {
1408
1719
  const manifest = useManifest();
1409
- const canvas = useCanvas();
1720
+ return manifest ? manifest.service.find((service) => service.profile === "SearchService1" || service.profile === "http://iiif.io/api/search/1/search") : void 0;
1721
+ }
1722
+
1723
+ function useStyleHelper() {
1410
1724
  const vault = useVault();
1411
- const [loadImageService, imageServiceStatus] = useLoadImageService();
1412
- const { enabledPageIds } = useAnnotationPageManager((options == null ? void 0 : options.annotationPageManagerId) || (manifest == null ? void 0 : manifest.id) || (canvas == null ? void 0 : canvas.id), {
1413
- all: false
1414
- });
1415
- const enabledPages = useResources(enabledPageIds, "AnnotationPage");
1416
- const supports = (options == null ? void 0 : options.strategies) || ["images", "media", "complex-timeline"];
1417
- const [paintables, actions] = usePaintables(options, [imageServiceStatus]);
1418
- const strategy = useMemo(() => {
1419
- if (!canvas || paintables.types.length === 0) {
1420
- return unknownResponse;
1421
- }
1422
- if (paintables.types.length !== 1) {
1423
- if (supports.indexOf("complex-timeline") === -1) {
1424
- return unsupportedStrategy("Complex timeline not supported");
1425
- }
1426
- return unsupportedStrategy("ComplexTimelineStrategy not yet supported");
1427
- }
1428
- const mainType = paintables.types[0];
1429
- if (mainType === "image") {
1430
- if (supports.indexOf("images") === -1) {
1431
- return unsupportedStrategy("Image not supported");
1432
- }
1433
- return getImageStrategy(canvas, paintables, loadImageService);
1434
- }
1435
- if (mainType === "audio") {
1436
- if (supports.indexOf("media") === -1) {
1437
- return unsupportedStrategy("Media not supported");
1438
- }
1439
- return unsupportedStrategy("Audio strategy not yet supported");
1440
- }
1441
- if (mainType === "video") {
1442
- if (supports.indexOf("media") === -1) {
1443
- return unsupportedStrategy("Media not supported");
1444
- }
1445
- return unsupportedStrategy("Video strategy not yet supported");
1446
- }
1447
- return unknownResponse;
1448
- }, [canvas, paintables, vault, actions.makeChoice]);
1449
- return useMemo(() => {
1450
- if (strategy.type === "unknown") {
1451
- return [strategy, emptyActions];
1452
- }
1453
- return [
1454
- __spreadProps(__spreadValues({}, strategy), {
1455
- annotations: { pages: enabledPages }
1456
- }),
1457
- actions
1458
- ];
1459
- }, [strategy, enabledPages]);
1725
+ return useMemo(() => createStylesHelper(vault), [vault]);
1460
1726
  }
1461
1727
 
1462
- export { AnnotationContext, CanvasContext, CollectionContext, ContextBridge, ImageServiceLoaderContext, ManifestContext, RangeContext, ReactVaultContext, ResourceProvider, ResourceReactContext, SimpleViewerProvider, SimpleViewerReactContext, VaultProvider, VisibleCanvasReactContext, emptyActions, expandTarget, flattenAnnotationPageIds, getImageStrategy, getPaintables, parseSelector, parseSpecificResource, unknownResponse, unsupportedStrategy, useAnnotation, useAnnotationPageManager, useAnnotationsAtTime, useCanvas, useCanvasClock, useCollection, useContextBridge, useDispatch, useEventListener, useExistingVault, useExternalCollection, useExternalManifest, useExternalResource, useImageService, useImageServiceLoader, useImageTile, useLoadImageService, useManifest, usePaintables, usePaintingAnnotations, useRange, useRenderingStrategy, useResourceContext, useResourceEvents, useResources, useSearchService, useSimpleViewer, useStyleHelper, useStyles, useThumbnail, useVault, useVaultEffect, useVaultSelector, useVirtualAnnotationPage, useVisibleCanvases };
1728
+ export { AnnotationContext, CanvasContext, CanvasPanel, CollectionContext, ContextBridge, ImageServiceLoaderContext, ManifestContext, RangeContext, ReactVaultContext, ResourceProvider, ResourceReactContext, SimpleViewerProvider, SimpleViewerReactContext, VaultProvider, VirtualAnnotationProvider, VisibleCanvasReactContext, emptyActions, expandTarget, flattenAnnotationPageIds, getImageStrategy, getPaintables, parseSelector, parseSpecificResource, unknownResponse, unsupportedStrategy, useAnnotation, useAnnotationPageManager, useAnnotationsAtTime, useCanvas, useCanvasClock, useCollection, useContextBridge, useDispatch, useEventListener, useExistingVault, useExternalCollection, useExternalManifest, useExternalResource, useImageService, useImageServiceLoader, useImageTile, useLoadImageService, useManifest, usePaintables, usePaintingAnnotations, useRange, useRenderingStrategy, useResourceContext, useResourceEvents, useResources, useSearchService, useSimpleViewer, useStyleHelper, useStyles, useThumbnail, useVault, useVaultEffect, useVaultSelector, useVirtualAnnotationPage, useVirtualAnnotationPageContext, useVisibleCanvases };