react-iiif-vault 0.9.6 → 0.9.9

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,215 @@
1
- import React, { useContext, useMemo, useState, useEffect, createContext, useCallback, useRef, useLayoutEffect } from 'react';
1
+ import React$1, { useContext, useMemo, useState, useEffect, createContext, useCallback, useRef, useLayoutEffect, Fragment, useReducer } from 'react';
2
+ import { AtlasAuto as AtlasAuto$1, mergeStyles, RegionHighlight, TileSet as TileSet$1 } from '@atlas-viewer/atlas';
2
3
  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';
5
4
  import { createAction } from 'typesafe-actions';
5
+ import require$$0 from 'react-dom';
6
+ import { createEventsHelper, createStylesHelper, createThumbnailHelper } from '@iiif/vault-helpers';
7
+ import { ImageServiceLoader, getImageServices } from '@atlas-viewer/iiif-image-api';
6
8
 
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) => {
9
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
10
+
11
+ var reactErrorBoundary_umd = {exports: {}};
12
+
13
+ (function (module, exports) {
14
+ (function (global, factory) {
15
+ factory(exports, React$1) ;
16
+ })(commonjsGlobal, (function (exports, React) {
17
+ function _interopNamespace(e) {
18
+ if (e && e.__esModule) return e;
19
+ var n = Object.create(null);
20
+ if (e) {
21
+ Object.keys(e).forEach(function (k) {
22
+ if (k !== 'default') {
23
+ var d = Object.getOwnPropertyDescriptor(e, k);
24
+ Object.defineProperty(n, k, d.get ? d : {
25
+ enumerable: true,
26
+ get: function () { return e[k]; }
27
+ });
28
+ }
29
+ });
30
+ }
31
+ n["default"] = e;
32
+ return Object.freeze(n);
33
+ }
34
+
35
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
36
+
37
+ function _setPrototypeOf(o, p) {
38
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
39
+ o.__proto__ = p;
40
+ return o;
41
+ };
42
+
43
+ return _setPrototypeOf(o, p);
44
+ }
45
+
46
+ function _inheritsLoose(subClass, superClass) {
47
+ subClass.prototype = Object.create(superClass.prototype);
48
+ subClass.prototype.constructor = subClass;
49
+ _setPrototypeOf(subClass, superClass);
50
+ }
51
+
52
+ var changedArray = function changedArray(a, b) {
53
+ if (a === void 0) {
54
+ a = [];
55
+ }
56
+
57
+ if (b === void 0) {
58
+ b = [];
59
+ }
60
+
61
+ return a.length !== b.length || a.some(function (item, index) {
62
+ return !Object.is(item, b[index]);
63
+ });
64
+ };
65
+
66
+ var initialState = {
67
+ error: null
68
+ };
69
+
70
+ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
71
+ _inheritsLoose(ErrorBoundary, _React$Component);
72
+
73
+ function ErrorBoundary() {
74
+ var _this;
75
+
76
+ for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
77
+ _args[_key] = arguments[_key];
78
+ }
79
+
80
+ _this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
81
+ _this.state = initialState;
82
+
83
+ _this.resetErrorBoundary = function () {
84
+ var _this$props;
85
+
86
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
87
+ args[_key2] = arguments[_key2];
88
+ }
89
+
90
+ _this.props.onReset == null ? void 0 : (_this$props = _this.props).onReset.apply(_this$props, args);
91
+
92
+ _this.reset();
93
+ };
94
+
95
+ return _this;
96
+ }
97
+
98
+ ErrorBoundary.getDerivedStateFromError = function getDerivedStateFromError(error) {
99
+ return {
100
+ error: error
101
+ };
102
+ };
103
+
104
+ var _proto = ErrorBoundary.prototype;
105
+
106
+ _proto.reset = function reset() {
107
+ this.setState(initialState);
108
+ };
109
+
110
+ _proto.componentDidCatch = function componentDidCatch(error, info) {
111
+ var _this$props$onError, _this$props2;
112
+
113
+ (_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info);
114
+ };
115
+
116
+ _proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
117
+ var error = this.state.error;
118
+ var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
119
+ // happens to *also* be in the resetKeys array, we'd end up resetting
120
+ // the error boundary immediately. This would likely trigger a second
121
+ // error to be thrown.
122
+ // So we make sure that we don't check the resetKeys on the first call
123
+ // of cDU after the error is set
124
+
125
+ if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
126
+ var _this$props$onResetKe, _this$props3;
127
+
128
+ (_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
129
+ this.reset();
130
+ }
131
+ };
132
+
133
+ _proto.render = function render() {
134
+ var error = this.state.error;
135
+ var _this$props4 = this.props,
136
+ fallbackRender = _this$props4.fallbackRender,
137
+ FallbackComponent = _this$props4.FallbackComponent,
138
+ fallback = _this$props4.fallback;
139
+
140
+ if (error !== null) {
141
+ var _props = {
142
+ error: error,
143
+ resetErrorBoundary: this.resetErrorBoundary
144
+ };
145
+
146
+ if ( /*#__PURE__*/React__namespace.isValidElement(fallback)) {
147
+ return fallback;
148
+ } else if (typeof fallbackRender === 'function') {
149
+ return fallbackRender(_props);
150
+ } else if (FallbackComponent) {
151
+ return /*#__PURE__*/React__namespace.createElement(FallbackComponent, _props);
152
+ } else {
153
+ throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
154
+ }
155
+ }
156
+
157
+ return this.props.children;
158
+ };
159
+
160
+ return ErrorBoundary;
161
+ }(React__namespace.Component);
162
+
163
+ function withErrorBoundary(Component, errorBoundaryProps) {
164
+ var Wrapped = function Wrapped(props) {
165
+ return /*#__PURE__*/React__namespace.createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React__namespace.createElement(Component, props));
166
+ }; // Format for display in DevTools
167
+
168
+
169
+ var name = Component.displayName || Component.name || 'Unknown';
170
+ Wrapped.displayName = "withErrorBoundary(" + name + ")";
171
+ return Wrapped;
172
+ }
173
+
174
+ function useErrorHandler(givenError) {
175
+ var _React$useState = React__namespace.useState(null),
176
+ error = _React$useState[0],
177
+ setError = _React$useState[1];
178
+
179
+ if (givenError != null) throw givenError;
180
+ if (error != null) throw error;
181
+ return setError;
182
+ }
183
+ /*
184
+ eslint
185
+ @typescript-eslint/sort-type-union-intersection-members: "off",
186
+ @typescript-eslint/no-throw-literal: "off",
187
+ @typescript-eslint/prefer-nullish-coalescing: "off"
188
+ */
189
+
190
+ exports.ErrorBoundary = ErrorBoundary;
191
+ exports.useErrorHandler = useErrorHandler;
192
+ exports.withErrorBoundary = withErrorBoundary;
193
+
194
+ Object.defineProperty(exports, '__esModule', { value: true });
195
+
196
+ }));
197
+
198
+ }(reactErrorBoundary_umd, reactErrorBoundary_umd.exports));
199
+
200
+ var __defProp$a = Object.defineProperty;
201
+ var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
202
+ var __hasOwnProp$a = Object.prototype.hasOwnProperty;
203
+ var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
204
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
205
+ var __spreadValues$a = (a, b) => {
13
206
  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]);
207
+ if (__hasOwnProp$a.call(b, prop))
208
+ __defNormalProp$a(a, prop, b[prop]);
209
+ if (__getOwnPropSymbols$a)
210
+ for (var prop of __getOwnPropSymbols$a(b)) {
211
+ if (__propIsEnum$a.call(b, prop))
212
+ __defNormalProp$a(a, prop, b[prop]);
20
213
  }
21
214
  return a;
22
215
  };
@@ -27,56 +220,32 @@ const defaultResourceContext = {
27
220
  canvas: void 0,
28
221
  annotation: void 0
29
222
  };
30
- const ResourceReactContext = React.createContext(defaultResourceContext);
223
+ const ResourceReactContext = React$1.createContext(defaultResourceContext);
31
224
  const useResourceContext = () => {
32
225
  return useContext(ResourceReactContext);
33
226
  };
34
- const ResourceProvider = ({ value, children }) => {
227
+ function ResourceProvider({ value, children }) {
35
228
  const parentContext = useResourceContext();
36
229
  const newContext = useMemo(() => {
37
- return __spreadValues$5(__spreadValues$5({}, parentContext), value);
230
+ return __spreadValues$a(__spreadValues$a({}, parentContext), value);
38
231
  }, [value, parentContext]);
39
- return /* @__PURE__ */ React.createElement(ResourceReactContext.Provider, {
232
+ return /* @__PURE__ */ React$1.createElement(ResourceReactContext.Provider, {
40
233
  value: newContext
41
234
  }, children);
42
- };
43
-
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
- };
235
+ }
73
236
 
74
- const ReactVaultContext = React.createContext({
237
+ const ReactVaultContext = React$1.createContext({
75
238
  vault: null,
76
239
  setVaultInstance: (vault) => {
77
240
  }
78
241
  });
79
- const VaultProvider = ({ vault, vaultOptions, useGlobal, resources, children }) => {
242
+ function VaultProvider({
243
+ vault,
244
+ vaultOptions,
245
+ useGlobal,
246
+ resources,
247
+ children
248
+ }) {
80
249
  const [vaultInstance, setVaultInstance] = useState(() => {
81
250
  if (vault) {
82
251
  return vault;
@@ -89,12 +258,12 @@ const VaultProvider = ({ vault, vaultOptions, useGlobal, resources, children })
89
258
  }
90
259
  return new Vault();
91
260
  });
92
- return /* @__PURE__ */ React.createElement(ReactVaultContext.Provider, {
261
+ return /* @__PURE__ */ React$1.createElement(ReactVaultContext.Provider, {
93
262
  value: { vault: vaultInstance, setVaultInstance }
94
- }, /* @__PURE__ */ React.createElement(ResourceProvider, {
263
+ }, /* @__PURE__ */ React$1.createElement(ResourceProvider, {
95
264
  value: resources || {}
96
265
  }, children));
97
- };
266
+ }
98
267
 
99
268
  const useVault = () => {
100
269
  const { vault } = useContext(ReactVaultContext);
@@ -162,18 +331,30 @@ function useExternalManifest(idOrRef, options) {
162
331
  return { id, isLoaded, error, manifest: resource, requestId, cached };
163
332
  }
164
333
 
334
+ function ManifestContext({ manifest, children }) {
335
+ return /* @__PURE__ */ React$1.createElement(ResourceProvider, {
336
+ value: { manifest }
337
+ }, children);
338
+ }
339
+
340
+ function CanvasContext({ canvas, children }) {
341
+ return /* @__PURE__ */ React$1.createElement(ResourceProvider, {
342
+ value: { canvas }
343
+ }, children);
344
+ }
345
+
165
346
  function useVaultSelector(selector, deps = []) {
166
347
  const vault = useVault();
167
348
  const [selectedState, setSelectedState] = useState(() => selector(vault.getState(), vault));
168
349
  useEffect(() => {
169
- return vault.subscribe((s) => selector(s, vault), (state) => {
170
- setSelectedState(state);
350
+ return vault.subscribe((s) => selector(s, vault), (s) => {
351
+ setSelectedState(s);
171
352
  }, false);
172
353
  }, deps);
173
354
  return selectedState;
174
355
  }
175
356
 
176
- const VisibleCanvasReactContext = React.createContext([]);
357
+ const VisibleCanvasReactContext = React$1.createContext([]);
177
358
  function useVisibleCanvases() {
178
359
  const ids = useContext(VisibleCanvasReactContext);
179
360
  return useVaultSelector((state) => {
@@ -192,7 +373,7 @@ const SimpleViewerReactContext = createContext({
192
373
  totalCanvases: 0,
193
374
  pagingView: true
194
375
  });
195
- const SimpleViewerProvider = (props) => {
376
+ function SimpleViewerProvider(props) {
196
377
  const manifest = useExternalManifest(props.manifest);
197
378
  const [currentCanvasId, setCurrentCanvasId] = useState("");
198
379
  const [visible, setVisible] = useState([]);
@@ -275,21 +456,21 @@ const SimpleViewerProvider = (props) => {
275
456
  }), [nextCanvas, previousCanvas, currentCanvasIndex, canvasList, setCurrentCanvasIndex, internalSetCurrentCanvasId]);
276
457
  if (!manifest.manifest) {
277
458
  console.warn("The manifest passed to the provider is not a valid IIIF manifest.");
278
- return /* @__PURE__ */ React.createElement("div", null, "Sorry, something went wrong.");
459
+ return /* @__PURE__ */ React$1.createElement("div", null, "Sorry, something went wrong.");
279
460
  }
280
461
  if (!manifest.isLoaded) {
281
- return /* @__PURE__ */ React.createElement("div", null, "Loading...");
462
+ return /* @__PURE__ */ React$1.createElement("div", null, "Loading...");
282
463
  }
283
- return /* @__PURE__ */ React.createElement(SimpleViewerReactContext.Provider, {
464
+ return /* @__PURE__ */ React$1.createElement(SimpleViewerReactContext.Provider, {
284
465
  value: ctx
285
- }, /* @__PURE__ */ React.createElement(VisibleCanvasReactContext.Provider, {
466
+ }, /* @__PURE__ */ React$1.createElement(VisibleCanvasReactContext.Provider, {
286
467
  value: visible
287
- }, /* @__PURE__ */ React.createElement(ManifestContext, {
468
+ }, /* @__PURE__ */ React$1.createElement(ManifestContext, {
288
469
  manifest: manifest.manifest.id
289
- }, /* @__PURE__ */ React.createElement(CanvasContext, {
470
+ }, /* @__PURE__ */ React$1.createElement(CanvasContext, {
290
471
  canvas: currentCanvasId
291
472
  }, props.children))));
292
- };
473
+ }
293
474
  function useSimpleViewer() {
294
475
  return useContext(SimpleViewerReactContext);
295
476
  }
@@ -302,74 +483,405 @@ function useContextBridge() {
302
483
  VisibleCanvasReactContext: useContext(VisibleCanvasReactContext)
303
484
  };
304
485
  }
305
- const ContextBridge = (props) => {
306
- return /* @__PURE__ */ React.createElement(VaultProvider, {
486
+ function ContextBridge(props) {
487
+ return /* @__PURE__ */ React$1.createElement(VaultProvider, {
307
488
  vault: props.bridge.VaultContext.vault || void 0,
308
489
  resources: props.bridge.ResourceContext
309
- }, /* @__PURE__ */ React.createElement(VisibleCanvasReactContext.Provider, {
490
+ }, /* @__PURE__ */ React$1.createElement(VisibleCanvasReactContext.Provider, {
310
491
  value: props.bridge.VisibleCanvasReactContext
311
- }, /* @__PURE__ */ React.createElement(SimpleViewerReactContext.Provider, {
492
+ }, /* @__PURE__ */ React$1.createElement(SimpleViewerReactContext.Provider, {
312
493
  value: props.bridge.SimpleViewerReactContext
313
494
  }, props.children)));
314
- };
495
+ }
315
496
 
316
- const ImageServiceLoaderContext = React.createContext(new ImageServiceLoader());
317
- function useImageServiceLoader() {
318
- return useContext(ImageServiceLoaderContext);
497
+ const IMPORT_ENTITIES = "@iiif/IMPORT_ENTITIES";
498
+ const MODIFY_ENTITY_FIELD = "@iiif/MODIFY_ENTITY_FIELD";
499
+ const REORDER_ENTITY_FIELD = "@iiif/REORDER_ENTITY_FIELD";
500
+ const ADD_REFERENCE = "@iiif/ADD_REFERENCE";
501
+ const REMOVE_REFERENCE = "@iiif/REMOVE_REFERENCE";
502
+ const importEntities = createAction(IMPORT_ENTITIES)();
503
+ const modifyEntityField = createAction(MODIFY_ENTITY_FIELD)();
504
+ const reorderEntityField = createAction(REORDER_ENTITY_FIELD)();
505
+ const addReference = createAction(ADD_REFERENCE)();
506
+ const removeReference = createAction(REMOVE_REFERENCE)();
507
+ const entityActions = { importEntities, modifyEntityField, reorderEntityField, addReference, removeReference };
508
+
509
+ const ADD_MAPPING = "@iiif/ADD_MAPPING";
510
+ const ADD_MAPPINGS = "@iiif/ADD_MAPPINGS";
511
+ createAction(ADD_MAPPING)();
512
+ createAction(ADD_MAPPINGS)();
513
+
514
+ const SET_META_VALUE = "@iiif/SET_META_VALUE";
515
+ const SET_META_VALUE_DYNAMIC = "@iiif/SET_META_VALUE_DYNAMIC";
516
+ const UNSET_META_VALUE = "@iiif/UNSET_META_VALUE";
517
+ createAction(SET_META_VALUE)();
518
+ createAction(SET_META_VALUE_DYNAMIC)();
519
+ createAction(UNSET_META_VALUE)();
520
+ const REQUEST_RESOURCE = "@iiif/REQUEST_RESOURCE";
521
+ const REQUEST_ERROR = "@iiif/REQUEST_ERROR";
522
+ const REQUEST_MISMATCH = "@iiif/REQUEST_MISMATCH";
523
+ const REQUEST_COMPLETE = "@iiif/REQUEST_COMPLETE";
524
+ const REQUEST_OFFLINE_RESOURCE = "@iiif/REQUEST_OFFLINE_RESOURCE";
525
+ createAction(REQUEST_RESOURCE)();
526
+ createAction(REQUEST_ERROR)();
527
+ createAction(REQUEST_MISMATCH)();
528
+ createAction(REQUEST_COMPLETE)();
529
+ createAction(REQUEST_OFFLINE_RESOURCE)();
530
+
531
+ const BATCH_ACTIONS = "@iiif/BATCH";
532
+ const BATCH_IMPORT = "@iiif/BATCH_IMPORT";
533
+ createAction(BATCH_ACTIONS)();
534
+ createAction(BATCH_IMPORT)();
535
+
536
+ function useDispatch() {
537
+ const vault = useVault();
538
+ const store = vault.getStore();
539
+ return useMemo(() => {
540
+ return (action) => store.dispatch(action);
541
+ }, [store]);
319
542
  }
320
543
 
321
- const BOX_SELECTOR = /&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/;
322
- const TEMPORAL_SELECTOR = /&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;
323
- function parseSelector(source) {
324
- if (Array.isArray(source)) {
325
- return source.reduce((data, nextSource) => {
326
- const { selector, selectors } = parseSelector(nextSource);
327
- if (selector) {
328
- if (!data.selector) {
329
- data.selector = selector;
330
- }
331
- data.selectors.push(...selectors);
332
- }
333
- return data;
334
- }, {
335
- selector: null,
336
- selectors: []
337
- });
338
- }
339
- if (!source) {
340
- return {
341
- selector: null,
342
- selectors: []
544
+ function isVaultActivated(obj) {
545
+ return typeof obj !== "string" && obj && obj.bindToVault;
546
+ }
547
+ function useVirtualAnnotationPage() {
548
+ const vault = useVault();
549
+ const sources = useRef([]);
550
+ const dispatch = useDispatch();
551
+ const virtualId = useMemo(() => {
552
+ return `vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random() * 1e9).toString(16)}`;
553
+ }, []);
554
+ useLayoutEffect(() => {
555
+ const page = {
556
+ id: virtualId,
557
+ type: "AnnotationPage",
558
+ behavior: [],
559
+ motivation: null,
560
+ label: null,
561
+ thumbnail: [],
562
+ summary: null,
563
+ requiredStatement: null,
564
+ metadata: [],
565
+ rights: null,
566
+ provider: [],
567
+ items: [],
568
+ seeAlso: [],
569
+ homepage: [],
570
+ logo: [],
571
+ rendering: [],
572
+ service: []
343
573
  };
344
- }
345
- if (typeof source === "string") {
346
- const [id, fragment] = source.split("#");
347
- if (!fragment) {
348
- return {
349
- selector: null,
350
- selectors: []
351
- };
352
- }
353
- return parseSelector({ type: "FragmentSelector", value: fragment });
354
- }
355
- if (source.type === "PointSelector" && (source.t || source.t === 0)) {
356
- const selector = {
357
- type: "TemporalSelector",
358
- temporal: {
359
- startTime: source.t
574
+ dispatch(entityActions.importEntities({
575
+ entities: {
576
+ AnnotationPage: {
577
+ [page.id]: page
578
+ }
360
579
  }
361
- };
362
- return {
363
- selector,
364
- selectors: [selector]
365
- };
366
- }
367
- if (source.type === "FragmentSelector") {
368
- const matchBoxSelector = BOX_SELECTOR.exec(source.value);
369
- if (matchBoxSelector) {
370
- const selector = {
371
- type: "BoxSelector",
372
- spatial: {
580
+ }));
581
+ }, [virtualId]);
582
+ const fullPage = useVaultSelector((state) => virtualId ? state.iiif.entities.AnnotationPage[virtualId] : null, [virtualId]);
583
+ const addAnnotation = useCallback((id, atIndex) => {
584
+ if (virtualId) {
585
+ if (isVaultActivated(id)) {
586
+ const display = id;
587
+ if (!display.__vault) {
588
+ display.bindToVault(vault);
589
+ }
590
+ id = typeof display.source === "string" ? display.source : display.source.id;
591
+ sources.current[id] = display;
592
+ } else if (typeof id !== "string") {
593
+ id = id.id;
594
+ }
595
+ const full = vault.get({ id: virtualId, type: "AnnotationPage" });
596
+ const annotation = vault.get({ id, type: "Annotation" });
597
+ if (full && annotation) {
598
+ if (!full.items.find((r) => r.id === annotation.id)) {
599
+ dispatch(entityActions.addReference({
600
+ id: virtualId,
601
+ type: "AnnotationPage",
602
+ key: "items",
603
+ reference: {
604
+ id,
605
+ type: "Annotation"
606
+ },
607
+ index: atIndex
608
+ }));
609
+ }
610
+ }
611
+ }
612
+ }, [virtualId]);
613
+ const removeAnnotation = useCallback((id) => {
614
+ if (virtualId) {
615
+ if (isVaultActivated(id)) {
616
+ id = typeof id.source === "string" ? id.source : id.source.id;
617
+ } else if (typeof id !== "string") {
618
+ id = id.id;
619
+ }
620
+ if (sources.current[id]) {
621
+ sources.current[id].beforeRemove();
622
+ }
623
+ const full = vault.get({ id: virtualId, type: "AnnotationPage" });
624
+ if (full) {
625
+ dispatch(entityActions.removeReference({
626
+ id: virtualId,
627
+ type: "AnnotationPage",
628
+ key: "items",
629
+ reference: {
630
+ id,
631
+ type: "Annotation"
632
+ }
633
+ }));
634
+ }
635
+ }
636
+ }, [virtualId]);
637
+ return [
638
+ fullPage,
639
+ {
640
+ addAnnotation,
641
+ removeAnnotation
642
+ }
643
+ ];
644
+ }
645
+
646
+ const VirtualAnnotationPageContext = createContext(null);
647
+ function useVirtualAnnotationPageContext() {
648
+ const ctx = useContext(VirtualAnnotationPageContext);
649
+ return [
650
+ ctx.fullPage,
651
+ {
652
+ addAnnotation: ctx.addAnnotation,
653
+ removeAnnotation: ctx.removeAnnotation
654
+ }
655
+ ];
656
+ }
657
+ function VirtualAnnotationProvider({ children }) {
658
+ const [fullPage, { addAnnotation, removeAnnotation }] = useVirtualAnnotationPage();
659
+ return /* @__PURE__ */ React$1.createElement(VirtualAnnotationPageContext.Provider, {
660
+ value: useMemo(() => ({ fullPage, addAnnotation, removeAnnotation }), [fullPage])
661
+ }, children);
662
+ }
663
+
664
+ var __defProp$9 = Object.defineProperty;
665
+ var __defProps$7 = Object.defineProperties;
666
+ var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
667
+ var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
668
+ var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
669
+ var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
670
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
671
+ var __spreadValues$9 = (a, b) => {
672
+ for (var prop in b || (b = {}))
673
+ if (__hasOwnProp$9.call(b, prop))
674
+ __defNormalProp$9(a, prop, b[prop]);
675
+ if (__getOwnPropSymbols$9)
676
+ for (var prop of __getOwnPropSymbols$9(b)) {
677
+ if (__propIsEnum$9.call(b, prop))
678
+ __defNormalProp$9(a, prop, b[prop]);
679
+ }
680
+ return a;
681
+ };
682
+ var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
683
+ function DefaultCanvasFallback({ width, style, height }) {
684
+ return /* @__PURE__ */ React$1.createElement("div", {
685
+ style: __spreadProps$7(__spreadValues$9({ width, height, minHeight: 500 }, style || {}), { background: "#f9f9f9" })
686
+ }, "Unknown error");
687
+ }
688
+
689
+ var createRoot;
690
+
691
+ var m = require$$0;
692
+ {
693
+ var i = m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
694
+ createRoot = function(c, o) {
695
+ i.usingClientEntryPoint = true;
696
+ try {
697
+ return m.createRoot(c, o);
698
+ } finally {
699
+ i.usingClientEntryPoint = false;
700
+ }
701
+ };
702
+ }
703
+
704
+ const ViewerPresetContext = createContext(null);
705
+ function useViewerPreset() {
706
+ return useContext(ViewerPresetContext);
707
+ }
708
+
709
+ const PortalContext = React$1.createContext(null);
710
+ const OverlayPortalContext = React$1.createContext(null);
711
+ function CanvasPortal({ children, overlay }) {
712
+ const htmlElement = useContext(overlay ? OverlayPortalContext : PortalContext);
713
+ const root = useMemo(() => htmlElement ? createRoot(htmlElement) : null, [htmlElement]);
714
+ const preset = useViewerPreset();
715
+ useLayoutEffect(() => {
716
+ return () => root == null ? void 0 : root.unmount();
717
+ }, [root]);
718
+ useLayoutEffect(() => {
719
+ if (root) {
720
+ root.render(/* @__PURE__ */ React$1.createElement(ViewerPresetContext.Provider, {
721
+ value: preset
722
+ }, children));
723
+ }
724
+ }, [children, preset]);
725
+ return null;
726
+ }
727
+
728
+ var __defProp$8 = Object.defineProperty;
729
+ var __defProps$6 = Object.defineProperties;
730
+ var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
731
+ var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
732
+ var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
733
+ var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
734
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
735
+ var __spreadValues$8 = (a, b) => {
736
+ for (var prop in b || (b = {}))
737
+ if (__hasOwnProp$8.call(b, prop))
738
+ __defNormalProp$8(a, prop, b[prop]);
739
+ if (__getOwnPropSymbols$8)
740
+ for (var prop of __getOwnPropSymbols$8(b)) {
741
+ if (__propIsEnum$8.call(b, prop))
742
+ __defNormalProp$8(a, prop, b[prop]);
743
+ }
744
+ return a;
745
+ };
746
+ var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
747
+ var __objRest = (source, exclude) => {
748
+ var target = {};
749
+ for (var prop in source)
750
+ if (__hasOwnProp$8.call(source, prop) && exclude.indexOf(prop) < 0)
751
+ target[prop] = source[prop];
752
+ if (source != null && __getOwnPropSymbols$8)
753
+ for (var prop of __getOwnPropSymbols$8(source)) {
754
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$8.call(source, prop))
755
+ target[prop] = source[prop];
756
+ }
757
+ return target;
758
+ };
759
+ const AtlasAuto = AtlasAuto$1;
760
+ function Viewer(_a) {
761
+ var _b = _a, {
762
+ children,
763
+ errorFallback,
764
+ outerContainerProps = {}
765
+ } = _b, props = __objRest(_b, [
766
+ "children",
767
+ "errorFallback",
768
+ "outerContainerProps"
769
+ ]);
770
+ const portal = useRef(null);
771
+ const [portalElement, setPortalElement] = useState();
772
+ const [viewerPreset, setViewerPreset] = useState();
773
+ const overlayPortal = useRef(null);
774
+ const [overlayPortalElement, setOverlayPortalElement] = useState();
775
+ const bridge = useContextBridge();
776
+ const ErrorFallback = errorFallback || DefaultCanvasFallback;
777
+ useLayoutEffect(() => {
778
+ setPortalElement(portal.current);
779
+ setOverlayPortalElement(overlayPortal.current);
780
+ }, []);
781
+ return /* @__PURE__ */ React$1.createElement(reactErrorBoundary_umd.exports.ErrorBoundary, {
782
+ fallbackRender: () => /* @__PURE__ */ React$1.createElement(ErrorFallback, __spreadValues$8({}, props))
783
+ }, /* @__PURE__ */ React$1.createElement("div", __spreadValues$8({
784
+ style: { position: "relative" }
785
+ }, outerContainerProps), /* @__PURE__ */ React$1.createElement(AtlasAuto, __spreadProps$6(__spreadValues$8({}, props), {
786
+ onCreated: (preset) => {
787
+ setViewerPreset(preset);
788
+ if (props.onCreated) {
789
+ props.onCreated(preset);
790
+ }
791
+ }
792
+ }), /* @__PURE__ */ React$1.createElement(ViewerPresetContext.Provider, {
793
+ value: viewerPreset
794
+ }, /* @__PURE__ */ React$1.createElement(PortalContext.Provider, {
795
+ value: portalElement
796
+ }, /* @__PURE__ */ React$1.createElement(OverlayPortalContext.Provider, {
797
+ value: overlayPortalElement
798
+ }, /* @__PURE__ */ React$1.createElement(ContextBridge, {
799
+ bridge
800
+ }, /* @__PURE__ */ React$1.createElement(VirtualAnnotationProvider, null, children)))))), /* @__PURE__ */ React$1.createElement("div", {
801
+ ref: overlayPortal
802
+ })), /* @__PURE__ */ React$1.createElement("div", {
803
+ ref: portal
804
+ }));
805
+ }
806
+
807
+ function useResourceEvents(resource, scope) {
808
+ const vault = useVault();
809
+ const helper = useMemo(() => createEventsHelper(vault), [vault]);
810
+ const hooks = useVaultSelector(() => {
811
+ if (resource && resource.id) {
812
+ return vault.getResourceMeta(resource.id, "eventManager");
813
+ }
814
+ return null;
815
+ }, [resource]);
816
+ return useMemo(() => {
817
+ return resource ? helper.getListenersAsProps(resource, scope) : {};
818
+ }, [hooks, resource, vault, scope]);
819
+ }
820
+
821
+ function useStyles(resource, scope) {
822
+ const vault = useVault();
823
+ const helper = useMemo(() => createStylesHelper(vault), [vault]);
824
+ return useVaultSelector(() => {
825
+ if (!resource) {
826
+ return null;
827
+ }
828
+ const styles = helper.getAppliedStyles(resource.id);
829
+ return styles ? scope ? styles[scope] : styles : void 0;
830
+ }, [resource, scope]);
831
+ }
832
+
833
+ const BOX_SELECTOR = /&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/;
834
+ const TEMPORAL_SELECTOR = /&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;
835
+ function parseSelector(source) {
836
+ if (Array.isArray(source)) {
837
+ return source.reduce((data, nextSource) => {
838
+ const { selector, selectors } = parseSelector(nextSource);
839
+ if (selector) {
840
+ if (!data.selector) {
841
+ data.selector = selector;
842
+ }
843
+ data.selectors.push(...selectors);
844
+ }
845
+ return data;
846
+ }, {
847
+ selector: null,
848
+ selectors: []
849
+ });
850
+ }
851
+ if (!source) {
852
+ return {
853
+ selector: null,
854
+ selectors: []
855
+ };
856
+ }
857
+ if (typeof source === "string") {
858
+ const [id, fragment] = source.split("#");
859
+ if (!fragment) {
860
+ return {
861
+ selector: null,
862
+ selectors: []
863
+ };
864
+ }
865
+ return parseSelector({ type: "FragmentSelector", value: fragment });
866
+ }
867
+ if (source.type === "PointSelector" && (source.t || source.t === 0)) {
868
+ const selector = {
869
+ type: "TemporalSelector",
870
+ temporal: {
871
+ startTime: source.t
872
+ }
873
+ };
874
+ return {
875
+ selector,
876
+ selectors: [selector]
877
+ };
878
+ }
879
+ if (source.type === "FragmentSelector") {
880
+ const matchBoxSelector = BOX_SELECTOR.exec(source.value);
881
+ if (matchBoxSelector) {
882
+ const selector = {
883
+ type: "BoxSelector",
884
+ spatial: {
373
885
  unit: matchBoxSelector[2] === "percent:" ? "percent" : "pixel",
374
886
  x: parseFloat(matchBoxSelector[3]),
375
887
  y: parseFloat(matchBoxSelector[4]),
@@ -407,25 +919,25 @@ function parseSelector(source) {
407
919
  };
408
920
  }
409
921
 
410
- var __defProp$4 = Object.defineProperty;
411
- var __defProps$4 = Object.defineProperties;
412
- 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) => {
922
+ var __defProp$7 = Object.defineProperty;
923
+ var __defProps$5 = Object.defineProperties;
924
+ var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
925
+ var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
926
+ var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
927
+ var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
928
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
929
+ var __spreadValues$7 = (a, b) => {
418
930
  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]);
931
+ if (__hasOwnProp$7.call(b, prop))
932
+ __defNormalProp$7(a, prop, b[prop]);
933
+ if (__getOwnPropSymbols$7)
934
+ for (var prop of __getOwnPropSymbols$7(b)) {
935
+ if (__propIsEnum$7.call(b, prop))
936
+ __defNormalProp$7(a, prop, b[prop]);
425
937
  }
426
938
  return a;
427
939
  };
428
- var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
940
+ var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
429
941
  function expandTarget(target, options = {}) {
430
942
  if (Array.isArray(target)) {
431
943
  return expandTarget(target[0]);
@@ -482,7 +994,7 @@ function expandTarget(target, options = {}) {
482
994
  if (!fragment) {
483
995
  return {
484
996
  type: "SpecificResource",
485
- source: __spreadProps$4(__spreadValues$4({}, target), {
997
+ source: __spreadProps$5(__spreadValues$7({}, target), {
486
998
  id
487
999
  }),
488
1000
  selector: null,
@@ -491,7 +1003,7 @@ function expandTarget(target, options = {}) {
491
1003
  }
492
1004
  return expandTarget({
493
1005
  type: "SpecificResource",
494
- source: __spreadProps$4(__spreadValues$4({}, target), {
1006
+ source: __spreadProps$5(__spreadValues$7({}, target), {
495
1007
  id
496
1008
  }),
497
1009
  selector: {
@@ -508,155 +1020,25 @@ function expandTarget(target, options = {}) {
508
1020
  };
509
1021
  }
510
1022
 
511
- function parseSpecificResource(resource) {
512
- if (resource.type === "SpecificResource") {
513
- return [resource.source, { selector: resource.selector }];
514
- }
515
- return [resource, { selector: null }];
516
- }
517
- function getPaintables(vault, paintingAnnotations, enabledChoices) {
518
- const types = [];
519
- let choice = null;
520
- const items = [];
521
- for (const annotation of paintingAnnotations) {
522
- const bodies = vault.get(annotation.body);
523
- for (const unknownBody of bodies) {
524
- const [body, { selector }] = parseSpecificResource(unknownBody);
525
- const type = (body.type || "unknown").toLowerCase();
526
- if (type === "choice") {
527
- const nestedBodies = vault.get(body.items);
528
- const selected = enabledChoices.length ? enabledChoices.map((cid) => nestedBodies.find((b) => b.id === cid)).filter(Boolean) : [nestedBodies[0]];
529
- if (selected.length === 0) {
530
- selected.push(nestedBodies[0]);
531
- }
532
- choice = {
533
- type: "single-choice",
534
- items: nestedBodies.map((b) => ({
535
- id: b.id,
536
- label: b.label,
537
- selected: selected.indexOf(b) !== -1
538
- })),
539
- label: unknownBody.label
540
- };
541
- bodies.push(...selected);
542
- continue;
543
- }
544
- if (types.indexOf(type) === -1) {
545
- types.push(type);
546
- }
547
- items.push({
548
- type,
549
- resource: body,
550
- target: annotation.target,
551
- selector
552
- });
1023
+ var __defProp$6 = Object.defineProperty;
1024
+ var __defProps$4 = Object.defineProperties;
1025
+ var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
1026
+ var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
1027
+ var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
1028
+ var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
1029
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1030
+ var __spreadValues$6 = (a, b) => {
1031
+ for (var prop in b || (b = {}))
1032
+ if (__hasOwnProp$6.call(b, prop))
1033
+ __defNormalProp$6(a, prop, b[prop]);
1034
+ if (__getOwnPropSymbols$6)
1035
+ for (var prop of __getOwnPropSymbols$6(b)) {
1036
+ if (__propIsEnum$6.call(b, prop))
1037
+ __defNormalProp$6(a, prop, b[prop]);
553
1038
  }
554
- }
555
- return {
556
- types,
557
- items,
558
- choice
559
- };
560
- }
561
- const emptyActions = {
562
- makeChoice: () => {
563
- }
1039
+ return a;
564
1040
  };
565
- const unknownResponse = { type: "unknown" };
566
- const unsupportedStrategy = (reason) => {
567
- return { type: "unknown", reason, annotations: { pages: [] } };
568
- };
569
-
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));
1041
+ var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
660
1042
  function useAnnotation(options = {}, deps = []) {
661
1043
  const { id, selector } = options;
662
1044
  const ctx = useResourceContext();
@@ -668,7 +1050,7 @@ function useAnnotation(options = {}, deps = []) {
668
1050
  if (!annotation) {
669
1051
  return void 0;
670
1052
  }
671
- const newAnnotation = __spreadProps$3(__spreadValues$3({}, annotation), {
1053
+ const newAnnotation = __spreadProps$4(__spreadValues$6({}, annotation), {
672
1054
  body,
673
1055
  target: expandTarget(annotation.target, { typeMap: vault.getState().iiif.mapping })
674
1056
  });
@@ -679,37 +1061,202 @@ function useAnnotation(options = {}, deps = []) {
679
1061
  }, [annotation, selector, body, ...deps]);
680
1062
  }
681
1063
 
682
- function useManifest(options = {}, deps = []) {
1064
+ function useCanvas(options = {}, deps = []) {
683
1065
  const { id, selector } = options;
684
1066
  const ctx = useResourceContext();
685
- useVault();
686
- const manifestId = id ? id : ctx.manifest;
687
- const manifest = useVaultSelector((s) => manifestId ? s.iiif.entities.Manifest[manifestId] : void 0, [manifestId]);
1067
+ const canvasId = id ? id : ctx.canvas;
1068
+ const canvas = useVaultSelector((s) => canvasId ? s.iiif.entities.Canvas[canvasId] : void 0, [canvasId]);
688
1069
  return useMemo(() => {
689
- if (!manifest) {
1070
+ if (!canvas) {
690
1071
  return void 0;
691
1072
  }
692
1073
  if (selector) {
693
- return selector(manifest);
1074
+ return selector(canvas);
694
1075
  }
695
- return manifest;
696
- }, [manifest, selector, ...deps]);
1076
+ return canvas;
1077
+ }, [canvas, selector, ...deps]);
697
1078
  }
698
1079
 
699
- function useCanvas(options = {}, deps = []) {
1080
+ var __defProp$5 = Object.defineProperty;
1081
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
1082
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
1083
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
1084
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1085
+ var __spreadValues$5 = (a, b) => {
1086
+ for (var prop in b || (b = {}))
1087
+ if (__hasOwnProp$5.call(b, prop))
1088
+ __defNormalProp$5(a, prop, b[prop]);
1089
+ if (__getOwnPropSymbols$5)
1090
+ for (var prop of __getOwnPropSymbols$5(b)) {
1091
+ if (__propIsEnum$5.call(b, prop))
1092
+ __defNormalProp$5(a, prop, b[prop]);
1093
+ }
1094
+ return a;
1095
+ };
1096
+ const RenderAnnotation = ({
1097
+ id,
1098
+ style: defaultStyle,
1099
+ className,
1100
+ interactive
1101
+ }) => {
1102
+ const annotation = useAnnotation({ id });
1103
+ const style = useStyles(annotation, "atlas");
1104
+ const html = useStyles(annotation, "html");
1105
+ const events = useResourceEvents(annotation, ["atlas"]);
1106
+ const canvas = useCanvas();
1107
+ const allStyles = useMemo(() => {
1108
+ return mergeStyles(defaultStyle, style);
1109
+ }, [defaultStyle, style]);
1110
+ const isValid = canvas && annotation && annotation.target && annotation.target.selector && annotation.target.selector.type === "BoxSelector" && annotation.target.source && annotation.target.source.id === canvas.id;
1111
+ if (!isValid) {
1112
+ return null;
1113
+ }
1114
+ return /* @__PURE__ */ React$1.createElement(RegionHighlight, __spreadValues$5({
1115
+ id: annotation.id,
1116
+ isEditing: true,
1117
+ region: annotation.target.selector.spatial,
1118
+ style: allStyles,
1119
+ className: (html == null ? void 0 : html.className) || className,
1120
+ interactive: !!((html == null ? void 0 : html.href) || interactive),
1121
+ href: (html == null ? void 0 : html.href) || null,
1122
+ title: (html == null ? void 0 : html.title) || null,
1123
+ hrefTarget: (html == null ? void 0 : html.target) || null
1124
+ }, events));
1125
+ };
1126
+
1127
+ const RenderAnnotationPage = ({
1128
+ className,
1129
+ page
1130
+ }) => {
1131
+ var _a;
1132
+ const style = useStyles(page, "atlas");
1133
+ const html = useStyles(page, "html");
1134
+ useVaultSelector((state) => page.id ? state.iiif.entities.AnnotationPage[page.id] : null, []);
1135
+ return /* @__PURE__ */ React$1.createElement(Fragment, null, (_a = page.items) == null ? void 0 : _a.map((annotation) => {
1136
+ return /* @__PURE__ */ React$1.createElement(RenderAnnotation, {
1137
+ key: annotation.id,
1138
+ id: annotation.id,
1139
+ style,
1140
+ className: (html == null ? void 0 : html.className) || className
1141
+ });
1142
+ }));
1143
+ };
1144
+
1145
+ const TileSet = TileSet$1;
1146
+ function RenderImage({
1147
+ id,
1148
+ image,
1149
+ thumbnail,
1150
+ isStatic,
1151
+ x = 0,
1152
+ y = 0,
1153
+ annotations,
1154
+ children
1155
+ }) {
1156
+ var _a, _b, _c, _d;
1157
+ return /* @__PURE__ */ React$1.createElement(Fragment, {
1158
+ key: id
1159
+ }, !image.service ? /* @__PURE__ */ React$1.createElement(Fragment, {
1160
+ key: "no-service"
1161
+ }, /* @__PURE__ */ React$1.createElement("world-image", {
1162
+ uri: image.id,
1163
+ target: image.target.spatial,
1164
+ display: image.width && image.height ? {
1165
+ width: image.width,
1166
+ height: image.height
1167
+ } : void 0
1168
+ }), annotations, children) : /* @__PURE__ */ React$1.createElement(Fragment, {
1169
+ key: "service"
1170
+ }, /* @__PURE__ */ React$1.createElement(TileSet, {
1171
+ viewport: isStatic,
1172
+ tiles: {
1173
+ id: image.service.id || image.service["@id"],
1174
+ height: image.height,
1175
+ width: image.width,
1176
+ imageService: image.service,
1177
+ thumbnail: thumbnail && thumbnail.type === "fixed" ? thumbnail : void 0
1178
+ },
1179
+ x: ((_a = image.target) == null ? void 0 : _a.spatial.x) + x,
1180
+ y: ((_b = image.target) == null ? void 0 : _b.spatial.y) + y,
1181
+ width: (_c = image.target) == null ? void 0 : _c.spatial.width,
1182
+ height: (_d = image.target) == null ? void 0 : _d.spatial.height
1183
+ }), annotations, children));
1184
+ }
1185
+
1186
+ function parseSpecificResource(resource) {
1187
+ if (resource.type === "SpecificResource") {
1188
+ return [resource.source, { selector: resource.selector }];
1189
+ }
1190
+ return [resource, { selector: null }];
1191
+ }
1192
+ function getPaintables(vault, paintingAnnotations, enabledChoices) {
1193
+ const types = [];
1194
+ let choice = null;
1195
+ const items = [];
1196
+ for (const annotation of paintingAnnotations) {
1197
+ const bodies = vault.get(annotation.body);
1198
+ for (const unknownBody of bodies) {
1199
+ const [body, { selector }] = parseSpecificResource(unknownBody);
1200
+ const type = (body.type || "unknown").toLowerCase();
1201
+ if (type === "choice") {
1202
+ const nestedBodies = vault.get(body.items);
1203
+ const selected = enabledChoices.length ? enabledChoices.map((cid) => nestedBodies.find((b) => b.id === cid)).filter(Boolean) : [nestedBodies[0]];
1204
+ if (selected.length === 0) {
1205
+ selected.push(nestedBodies[0]);
1206
+ }
1207
+ choice = {
1208
+ type: "single-choice",
1209
+ items: nestedBodies.map((b) => ({
1210
+ id: b.id,
1211
+ label: b.label,
1212
+ selected: selected.indexOf(b) !== -1
1213
+ })),
1214
+ label: unknownBody.label
1215
+ };
1216
+ bodies.push(...selected);
1217
+ continue;
1218
+ }
1219
+ if (types.indexOf(type) === -1) {
1220
+ types.push(type);
1221
+ }
1222
+ items.push({
1223
+ type,
1224
+ resource: body,
1225
+ target: annotation.target,
1226
+ selector
1227
+ });
1228
+ }
1229
+ }
1230
+ return {
1231
+ types,
1232
+ items,
1233
+ choice
1234
+ };
1235
+ }
1236
+ const emptyActions = {
1237
+ makeChoice: () => {
1238
+ }
1239
+ };
1240
+ const unknownResponse = { type: "unknown" };
1241
+ const unsupportedStrategy = (reason) => {
1242
+ return { type: "unknown", reason, annotations: { pages: [] } };
1243
+ };
1244
+
1245
+ function useManifest(options = {}, deps = []) {
700
1246
  const { id, selector } = options;
701
1247
  const ctx = useResourceContext();
702
- const canvasId = id ? id : ctx.canvas;
703
- const canvas = useVaultSelector((s) => canvasId ? s.iiif.entities.Canvas[canvasId] : void 0, [canvasId]);
1248
+ useVault();
1249
+ const manifestId = id ? id : ctx.manifest;
1250
+ const manifest = useVaultSelector((s) => manifestId ? s.iiif.entities.Manifest[manifestId] : void 0, [manifestId]);
704
1251
  return useMemo(() => {
705
- if (!canvas) {
1252
+ if (!manifest) {
706
1253
  return void 0;
707
1254
  }
708
1255
  if (selector) {
709
- return selector(canvas);
1256
+ return selector(manifest);
710
1257
  }
711
- return canvas;
712
- }, [canvas, selector, ...deps]);
1258
+ return manifest;
1259
+ }, [manifest, selector, ...deps]);
713
1260
  }
714
1261
 
715
1262
  function getMeta$1(state, resourceId) {
@@ -773,25 +1320,25 @@ function flattenAnnotationPageIds({
773
1320
  return foundIds;
774
1321
  }
775
1322
 
776
- var __defProp$2 = Object.defineProperty;
777
- var __defProps$2 = Object.defineProperties;
778
- 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) => {
1323
+ var __defProp$4 = Object.defineProperty;
1324
+ var __defProps$3 = Object.defineProperties;
1325
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
1326
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
1327
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
1328
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
1329
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1330
+ var __spreadValues$4 = (a, b) => {
784
1331
  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]);
1332
+ if (__hasOwnProp$4.call(b, prop))
1333
+ __defNormalProp$4(a, prop, b[prop]);
1334
+ if (__getOwnPropSymbols$4)
1335
+ for (var prop of __getOwnPropSymbols$4(b)) {
1336
+ if (__propIsEnum$4.call(b, prop))
1337
+ __defNormalProp$4(a, prop, b[prop]);
791
1338
  }
792
1339
  return a;
793
1340
  };
794
- var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
1341
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
795
1342
  function getMeta(state, resourceId) {
796
1343
  var _a;
797
1344
  const resourceMeta = (_a = state == null ? void 0 : state.iiif) == null ? void 0 : _a.meta[resourceId];
@@ -822,7 +1369,7 @@ function useAnnotationPageManager(resourceId, options = {}) {
822
1369
  if (existingResources && !existingResources[resourceId]) {
823
1370
  return existingResources;
824
1371
  }
825
- return __spreadProps$2(__spreadValues$2({}, existingResources || {}), {
1372
+ return __spreadProps$3(__spreadValues$4({}, existingResources || {}), {
826
1373
  [resourceId]: false
827
1374
  });
828
1375
  });
@@ -849,7 +1396,7 @@ function useAnnotationPageManager(resourceId, options = {}) {
849
1396
  if (existingResources && existingResources[resourceId]) {
850
1397
  return existingResources;
851
1398
  }
852
- return __spreadProps$2(__spreadValues$2({}, existingResources || {}), {
1399
+ return __spreadProps$3(__spreadValues$4({}, existingResources || {}), {
853
1400
  [resourceId]: true
854
1401
  });
855
1402
  });
@@ -862,186 +1409,95 @@ function useAnnotationPageManager(resourceId, options = {}) {
862
1409
  };
863
1410
  }
864
1411
 
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]);
1412
+ function useResources(ids, type) {
1413
+ return useVaultSelector((state, vault) => vault.get(ids.map((id) => ({ id, type }))), [ids, type]);
878
1414
  }
879
1415
 
880
- function useAnnotationsAtTime(time, options = {}) {
881
- const allAnnotations = usePaintingAnnotations(options);
882
- return allAnnotations;
883
- }
884
-
885
- function useCanvasClock(canvasId, autoplay = false) {
1416
+ const ImageServiceLoaderContext = React$1.createContext(new ImageServiceLoader());
1417
+ function useImageServiceLoader() {
1418
+ return useContext(ImageServiceLoaderContext);
886
1419
  }
887
1420
 
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);
1421
+ var __defProp$3 = Object.defineProperty;
1422
+ var __defProps$2 = Object.defineProperties;
1423
+ var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
1424
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
1425
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
1426
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
1427
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1428
+ var __spreadValues$3 = (a, b) => {
1429
+ for (var prop in b || (b = {}))
1430
+ if (__hasOwnProp$3.call(b, prop))
1431
+ __defNormalProp$3(a, prop, b[prop]);
1432
+ if (__getOwnPropSymbols$3)
1433
+ for (var prop of __getOwnPropSymbols$3(b)) {
1434
+ if (__propIsEnum$3.call(b, prop))
1435
+ __defNormalProp$3(a, prop, b[prop]);
899
1436
  }
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]);
1437
+ return a;
1438
+ };
1439
+ var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
1440
+ function useLoadImageService() {
1441
+ const loader = useImageServiceLoader();
1442
+ const [imageServiceStatus, setImageServiceStatus] = useState({});
1443
+ const didUnmount = useRef(false);
915
1444
  useEffect(() => {
916
- const currentResource = resource;
917
- if (!currentResource) {
918
- return () => {
919
- };
920
- }
921
- helper.addEventListener(currentResource, name, listener, scope);
922
1445
  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
- }
1446
+ didUnmount.current = true;
953
1447
  };
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;
1448
+ }, []);
1449
+ const loadImageService = useCallback((imageService, { height, width }) => {
1450
+ if (imageService) {
1451
+ const imageServiceId = imageService.id || imageService["@id"];
1452
+ const syncLoaded = loader.loadServiceSync({
1453
+ id: imageServiceId,
1454
+ width: imageService.width || width,
1455
+ height: imageService.height || height,
1456
+ source: imageService
1457
+ });
1458
+ if (syncLoaded) {
1459
+ imageService = syncLoaded;
1460
+ } else if (!imageServiceStatus[imageServiceId]) {
1461
+ if (!didUnmount.current) {
1462
+ setImageServiceStatus((r) => {
1463
+ return __spreadProps$2(__spreadValues$3({}, r), {
1464
+ [imageServiceId]: "loading"
1465
+ });
1466
+ });
977
1467
  }
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);
1468
+ loader.loadService({
1469
+ id: imageServiceId,
1470
+ width: imageService.width || width,
1471
+ height: imageService.height || height
1472
+ }).then(() => {
1473
+ if (!didUnmount.current) {
1474
+ setImageServiceStatus((r) => {
1475
+ return __spreadProps$2(__spreadValues$3({}, r), {
1476
+ [imageServiceId]: "done"
1477
+ });
1478
+ });
1015
1479
  }
1016
- }
1017
- } catch (err) {
1018
- setStatus("error");
1019
- setError(err);
1480
+ });
1020
1481
  }
1021
- }))();
1022
- }, [key, cacheKey]);
1023
- return useMemo(() => {
1024
- return {
1025
- data,
1026
- isFetching,
1027
- status,
1028
- error
1029
- };
1030
- }, [data, isFetching, status, error]);
1482
+ }
1483
+ return imageService;
1484
+ }, [loader, imageServiceStatus]);
1485
+ return [loadImageService, imageServiceStatus];
1031
1486
  }
1032
1487
 
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
- };
1488
+ function usePaintingAnnotations(options = {}) {
1489
+ const canvas = useCanvas(options.canvasId ? { id: options.canvasId } : void 0);
1490
+ return useVaultSelector((state, vault) => {
1491
+ if (!canvas) {
1492
+ return [];
1493
+ }
1494
+ const annotationPages = vault.get(canvas.items);
1495
+ const flatAnnotations = [];
1496
+ for (const page of annotationPages) {
1497
+ flatAnnotations.push(...vault.get(page.items));
1498
+ }
1499
+ return flatAnnotations;
1500
+ }, [canvas]);
1045
1501
  }
1046
1502
 
1047
1503
  function usePaintables(options, deps = []) {
@@ -1088,60 +1544,266 @@ function usePaintables(options, deps = []) {
1088
1544
  return [paintables, actions];
1089
1545
  }
1090
1546
 
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;
1099
- }
1100
- if (selector) {
1101
- return selector(range);
1547
+ function getImageStrategy(canvas, paintables, loadImageService) {
1548
+ const imageTypes = [];
1549
+ for (const singleImage of paintables.items) {
1550
+ const resource = singleImage.resource && singleImage.resource.type === "SpecificResource" ? singleImage.resource.source : singleImage.resource;
1551
+ if (!resource.id) {
1552
+ return unsupportedStrategy("No resource Identifier");
1102
1553
  }
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");
1554
+ let imageService = void 0;
1555
+ if (resource.service) {
1556
+ const imageServices = getImageServices(resource);
1557
+ if (imageServices[0]) {
1558
+ imageService = loadImageService(imageServices[0], canvas);
1559
+ }
1113
1560
  }
1114
- return null;
1115
- }, [resource]);
1116
- return useMemo(() => {
1117
- return resource ? helper.getListenersAsProps(resource, scope) : {};
1118
- }, [hooks, resource, vault, scope]);
1561
+ const { selector: imageTarget, source } = expandTarget(singleImage.target);
1562
+ if (source.id !== canvas.id) {
1563
+ continue;
1564
+ }
1565
+ const defaultTarget = {
1566
+ type: "BoxSelector",
1567
+ spatial: {
1568
+ x: 0,
1569
+ y: 0,
1570
+ width: canvas.width,
1571
+ height: canvas.height
1572
+ }
1573
+ };
1574
+ const target = imageTarget ? imageTarget.type === "TemporalSelector" ? {
1575
+ type: "TemporalBoxSelector",
1576
+ temporal: imageTarget.temporal,
1577
+ spatial: defaultTarget.spatial
1578
+ } : imageTarget : null;
1579
+ const defaultImageSelector = {
1580
+ type: "BoxSelector",
1581
+ spatial: {
1582
+ x: 0,
1583
+ y: 0,
1584
+ width: canvas.width,
1585
+ height: canvas.height
1586
+ }
1587
+ };
1588
+ const imageSelector = singleImage.resource.type === "SpecificResource" ? expandTarget(singleImage.resource) : null;
1589
+ const selector = imageSelector && imageSelector.selector && (imageSelector.selector.type === "BoxSelector" || imageSelector.selector.type === "TemporalBoxSelector") ? {
1590
+ type: "BoxSelector",
1591
+ spatial: {
1592
+ x: imageSelector.selector.spatial.x,
1593
+ y: imageSelector.selector.spatial.y,
1594
+ width: imageSelector.selector.spatial.width,
1595
+ height: imageSelector.selector.spatial.height
1596
+ }
1597
+ } : defaultImageSelector;
1598
+ if (imageService && !imageService.id) {
1599
+ imageService.id = imageService["@id"];
1600
+ }
1601
+ const imageType = {
1602
+ id: resource.id,
1603
+ type: "Image",
1604
+ width: target ? resource.width : canvas.width,
1605
+ height: target ? resource.height : canvas.height,
1606
+ service: imageService,
1607
+ sizes: imageService && imageService.sizes ? imageService.sizes : resource.width && resource.height ? [{ width: resource.width, height: resource.height }] : [],
1608
+ target: target && target.type !== "PointSelector" ? target : defaultTarget,
1609
+ selector
1610
+ };
1611
+ imageTypes.push(imageType);
1612
+ }
1613
+ return {
1614
+ type: "images",
1615
+ image: imageTypes[0],
1616
+ images: imageTypes,
1617
+ choice: paintables.choice
1618
+ };
1119
1619
  }
1120
1620
 
1121
- function useResources(ids, type) {
1122
- return useVaultSelector((state, vault) => vault.get(ids.map((id) => ({ id, type }))), [ids, type]);
1621
+ const supportedFormats = ["model/gltf-binary"];
1622
+ function get3dStrategy(canvas, paintables) {
1623
+ const first = paintables.items[0];
1624
+ const resource = first.resource;
1625
+ if (!resource.format) {
1626
+ return unsupportedStrategy("Unknown format");
1627
+ }
1628
+ if (supportedFormats.indexOf(resource.format) === -1) {
1629
+ return unsupportedStrategy(`3D format: ${resource.format} is unsupported`);
1630
+ }
1631
+ return {
1632
+ type: "3d-model",
1633
+ model: resource
1634
+ };
1123
1635
  }
1124
1636
 
1125
- function useSearchService() {
1126
- const manifest = useManifest();
1127
- return manifest ? manifest.service.find((service) => service.profile === "SearchService1" || service.profile === "http://iiif.io/api/search/1/search") : void 0;
1637
+ function getAudioStrategy(canvas, paintables) {
1638
+ var _a;
1639
+ if (!canvas.duration) {
1640
+ return unsupportedStrategy("No duration on canvas");
1641
+ }
1642
+ if (paintables.items.length > 1) {
1643
+ return unsupportedStrategy("Only one audio source supported");
1644
+ }
1645
+ const audioResource = (_a = paintables.items[0]) == null ? void 0 : _a.resource;
1646
+ if (!audioResource) {
1647
+ return unsupportedStrategy("Unknown audio");
1648
+ }
1649
+ if (!audioResource.format) {
1650
+ return unsupportedStrategy("Audio does not have format");
1651
+ }
1652
+ return {
1653
+ type: "media",
1654
+ media: {
1655
+ duration: canvas.duration,
1656
+ url: audioResource.id,
1657
+ type: "Sound",
1658
+ target: {
1659
+ type: "TemporalSelector",
1660
+ temporal: {
1661
+ startTime: 0,
1662
+ endTime: canvas.duration
1663
+ }
1664
+ },
1665
+ format: audioResource.format,
1666
+ selector: {
1667
+ type: "TemporalSelector",
1668
+ temporal: {
1669
+ startTime: 0,
1670
+ endTime: canvas.duration
1671
+ }
1672
+ }
1673
+ },
1674
+ annotations: {
1675
+ pages: []
1676
+ }
1677
+ };
1128
1678
  }
1129
1679
 
1130
- function useStyleHelper() {
1131
- const vault = useVault();
1132
- return useMemo(() => createStylesHelper(vault), [vault]);
1680
+ function getVideoStrategy(canvas, paintables) {
1681
+ var _a;
1682
+ const videoPaintables = paintables.items.filter((t) => t.type === "video");
1683
+ if (!canvas.duration) {
1684
+ return unsupportedStrategy("No duration on canvas");
1685
+ }
1686
+ if (videoPaintables.length > 1) {
1687
+ return unsupportedStrategy("Only one video source supported");
1688
+ }
1689
+ const audioResource = (_a = videoPaintables[0]) == null ? void 0 : _a.resource;
1690
+ if (!audioResource) {
1691
+ return unsupportedStrategy("Unknown video");
1692
+ }
1693
+ if (!audioResource.format) {
1694
+ return unsupportedStrategy("Video does not have format");
1695
+ }
1696
+ return {
1697
+ type: "media",
1698
+ media: {
1699
+ duration: canvas.duration,
1700
+ url: audioResource.id,
1701
+ type: "Video",
1702
+ items: [],
1703
+ target: {
1704
+ type: "TemporalSelector",
1705
+ temporal: {
1706
+ startTime: 0,
1707
+ endTime: canvas.duration
1708
+ }
1709
+ },
1710
+ format: audioResource.format,
1711
+ selector: {
1712
+ type: "TemporalSelector",
1713
+ temporal: {
1714
+ startTime: 0,
1715
+ endTime: canvas.duration
1716
+ }
1717
+ }
1718
+ },
1719
+ annotations: {
1720
+ pages: []
1721
+ }
1722
+ };
1133
1723
  }
1134
1724
 
1135
- function useStyles(resource, scope) {
1725
+ var __defProp$2 = Object.defineProperty;
1726
+ var __defProps$1 = Object.defineProperties;
1727
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
1728
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
1729
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
1730
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
1731
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1732
+ var __spreadValues$2 = (a, b) => {
1733
+ for (var prop in b || (b = {}))
1734
+ if (__hasOwnProp$2.call(b, prop))
1735
+ __defNormalProp$2(a, prop, b[prop]);
1736
+ if (__getOwnPropSymbols$2)
1737
+ for (var prop of __getOwnPropSymbols$2(b)) {
1738
+ if (__propIsEnum$2.call(b, prop))
1739
+ __defNormalProp$2(a, prop, b[prop]);
1740
+ }
1741
+ return a;
1742
+ };
1743
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
1744
+ function useRenderingStrategy(options) {
1745
+ const manifest = useManifest();
1746
+ const canvas = useCanvas();
1136
1747
  const vault = useVault();
1137
- const helper = useMemo(() => createStylesHelper(vault), [vault]);
1138
- return useVaultSelector(() => {
1139
- if (!resource) {
1140
- return null;
1748
+ const [loadImageService, imageServiceStatus] = useLoadImageService();
1749
+ const { enabledPageIds } = useAnnotationPageManager((options == null ? void 0 : options.annotationPageManagerId) || (manifest == null ? void 0 : manifest.id) || (canvas == null ? void 0 : canvas.id), {
1750
+ all: false
1751
+ });
1752
+ const enabledPages = useResources(enabledPageIds, "AnnotationPage");
1753
+ const supports = (options == null ? void 0 : options.strategies) || ["images", "media", "complex-timeline"];
1754
+ const [paintables, actions] = usePaintables(options, [imageServiceStatus]);
1755
+ const strategy = useMemo(() => {
1756
+ if (!canvas || paintables.types.length === 0) {
1757
+ return unknownResponse;
1141
1758
  }
1142
- const styles = helper.getAppliedStyles(resource.id);
1143
- return styles ? scope ? styles[scope] : styles : void 0;
1144
- }, [resource, scope]);
1759
+ if (paintables.types.length !== 1) {
1760
+ if (paintables.types.length === 2 && paintables.types.indexOf("text") !== -1) {
1761
+ paintables.types = paintables.types.filter((t) => t !== "text");
1762
+ } else {
1763
+ if (supports.indexOf("complex-timeline") === -1) {
1764
+ return unsupportedStrategy("Complex timeline not supported");
1765
+ }
1766
+ return unsupportedStrategy("ComplexTimelineStrategy not yet supported");
1767
+ }
1768
+ }
1769
+ const mainType = paintables.types[0];
1770
+ if (mainType === "image") {
1771
+ if (supports.indexOf("images") === -1) {
1772
+ return unsupportedStrategy("Image not supported");
1773
+ }
1774
+ return getImageStrategy(canvas, paintables, loadImageService);
1775
+ }
1776
+ if (mainType === "Model" || mainType === "model") {
1777
+ if (supports.indexOf("3d-model") === -1) {
1778
+ return unsupportedStrategy("3D not supported");
1779
+ }
1780
+ return get3dStrategy(canvas, paintables);
1781
+ }
1782
+ if (mainType === "sound" || mainType === "audio") {
1783
+ if (supports.indexOf("media") === -1) {
1784
+ return unsupportedStrategy("Media not supported");
1785
+ }
1786
+ return getAudioStrategy(canvas, paintables);
1787
+ }
1788
+ if (mainType === "video") {
1789
+ if (supports.indexOf("media") === -1) {
1790
+ return unsupportedStrategy("Media not supported");
1791
+ }
1792
+ return getVideoStrategy(canvas, paintables);
1793
+ }
1794
+ return unknownResponse;
1795
+ }, [canvas, paintables, vault, actions.makeChoice]);
1796
+ return useMemo(() => {
1797
+ if (strategy.type === "unknown") {
1798
+ return [strategy, emptyActions];
1799
+ }
1800
+ return [
1801
+ __spreadProps$1(__spreadValues$2({}, strategy), {
1802
+ annotations: { pages: enabledPages }
1803
+ }),
1804
+ actions
1805
+ ];
1806
+ }, [strategy, enabledPages]);
1145
1807
  }
1146
1808
 
1147
1809
  const useVaultEffect = (callback, deps = []) => {
@@ -1179,8 +1841,8 @@ function useThumbnail(request, dereference, { canvasId, manifestId } = {}) {
1179
1841
  }
1180
1842
 
1181
1843
  var __defProp$1 = Object.defineProperty;
1182
- var __defProps$1 = Object.defineProperties;
1183
- var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
1844
+ var __defProps = Object.defineProperties;
1845
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
1184
1846
  var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
1185
1847
  var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
1186
1848
  var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
@@ -1196,198 +1858,266 @@ var __spreadValues$1 = (a, b) => {
1196
1858
  }
1197
1859
  return a;
1198
1860
  };
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);
1861
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1862
+ function getDefaultState(duration) {
1863
+ return { isMuted: false, playRequested: false, isPlaying: false, isFinished: false, volume: 100, duration };
1864
+ }
1865
+ function reducer(state, action) {
1866
+ switch (action.type) {
1867
+ case "FINISHED":
1868
+ return __spreadProps(__spreadValues$1({}, state), { isFinished: true, isPlaying: false, playRequested: false });
1869
+ case "PLAY_PAUSE":
1870
+ return __spreadProps(__spreadValues$1({}, state), { isFinished: false, isPlaying: !state.isPlaying });
1871
+ case "PLAY_REQUESTED":
1872
+ return __spreadProps(__spreadValues$1({}, state), { isFinished: false, playRequested: true });
1873
+ case "PAUSE":
1874
+ return __spreadProps(__spreadValues$1({}, state), { isPlaying: false });
1875
+ case "PLAY":
1876
+ return __spreadProps(__spreadValues$1({}, state), { isFinished: false, playRequested: false, isPlaying: true });
1877
+ case "MUTE":
1878
+ return __spreadProps(__spreadValues$1({}, state), { isMuted: true });
1879
+ case "SET_VOLUME":
1880
+ return __spreadProps(__spreadValues$1({}, state), { volume: action.volume, isMuted: action.volume === 0 });
1881
+ case "TOGGLE_MUTE":
1882
+ return __spreadProps(__spreadValues$1({}, state), { isMuted: !state.isMuted });
1883
+ case "UNMUTE":
1884
+ return __spreadProps(__spreadValues$1({}, state), { isMuted: false });
1885
+ }
1886
+ return state;
1887
+ }
1888
+ function formatTime(time) {
1889
+ const seconds = Math.round(time);
1890
+ return `${Math.floor(seconds / 60)}:${`${seconds % 60}`.padStart(2, "0")}`;
1891
+ }
1892
+ function useSimpleMediaPlayer(props) {
1893
+ const [state, dispatch] = useReducer(reducer, getDefaultState(props.duration));
1894
+ const media = useRef(null);
1895
+ const currentTime = useRef(null);
1896
+ const progress = useRef(null);
1897
+ const _isMuted = useRef(false);
1898
+ const _updateCurrentTime = useCallback(() => {
1899
+ if (currentTime.current && media.current) {
1900
+ currentTime.current.innerHTML = formatTime(media.current.currentTime);
1901
+ if (progress.current) {
1902
+ progress.current.style.width = `${media.current.currentTime / props.duration * 100}%`;
1903
+ }
1904
+ if (_isMuted.current !== media.current.muted) {
1905
+ _isMuted.current = media.current.muted;
1906
+ dispatch(media.current.muted ? { type: "MUTE" } : { type: "UNMUTE" });
1907
+ }
1908
+ }
1909
+ }, [props.duration]);
1910
+ const play = useCallback(() => {
1911
+ if (media.current) {
1912
+ dispatch({ type: "PLAY_REQUESTED" });
1913
+ media.current.play().then(() => {
1914
+ dispatch({ type: "PLAY" });
1915
+ });
1916
+ _updateCurrentTime();
1917
+ }
1918
+ }, [_updateCurrentTime]);
1919
+ const playPause = useCallback(() => {
1920
+ if (media.current) {
1921
+ if (media.current.duration > 0 && media.current.paused) {
1922
+ play();
1923
+ } else {
1924
+ pause();
1925
+ }
1926
+ }
1927
+ }, [_updateCurrentTime]);
1928
+ const pause = useCallback(() => {
1929
+ if (media.current) {
1930
+ media.current.pause();
1931
+ dispatch({ type: "PAUSE" });
1932
+ _updateCurrentTime();
1933
+ }
1934
+ }, [_updateCurrentTime]);
1935
+ const toggleMute = useCallback(() => {
1936
+ if (media.current) {
1937
+ media.current.muted = !media.current.muted;
1938
+ dispatch(media.current.muted ? { type: "MUTE" } : { type: "UNMUTE" });
1939
+ }
1940
+ }, []);
1941
+ const mute = useCallback(() => {
1942
+ if (media.current) {
1943
+ media.current.muted = true;
1944
+ dispatch({ type: "MUTE" });
1945
+ }
1946
+ }, []);
1947
+ const unmute = useCallback(() => {
1948
+ if (media.current) {
1949
+ media.current.muted = false;
1950
+ dispatch({ type: "UNMUTE" });
1951
+ }
1952
+ }, []);
1953
+ const setVolume = useCallback((newVolume) => {
1954
+ if (media.current) {
1955
+ media.current.muted = false;
1956
+ media.current.volume = newVolume / 100;
1957
+ dispatch({ type: "SET_VOLUME", volume: newVolume });
1958
+ }
1959
+ }, []);
1960
+ const setDurationPercent = useCallback((percent) => {
1961
+ if (media.current) {
1962
+ media.current.currentTime = Math.max(0, Math.min(percent * props.duration, props.duration));
1963
+ _updateCurrentTime();
1964
+ }
1965
+ }, []);
1966
+ const setTime = useCallback((time) => {
1967
+ if (media.current) {
1968
+ media.current.currentTime = Math.max(0, Math.min(time, props.duration));
1969
+ _updateCurrentTime();
1970
+ }
1971
+ }, []);
1204
1972
  useEffect(() => {
1205
- return () => {
1206
- didUnmount.current = true;
1973
+ const interval = setInterval(() => {
1974
+ _updateCurrentTime();
1975
+ }, 350);
1976
+ return () => clearInterval(interval);
1977
+ }, [_updateCurrentTime, props.duration]);
1978
+ useEffect(() => {
1979
+ const ended = () => {
1980
+ dispatch({ type: "FINISHED" });
1207
1981
  };
1982
+ const _media = media.current;
1983
+ _media == null ? void 0 : _media.addEventListener("ended", ended);
1984
+ return () => _media == null ? void 0 : _media.removeEventListener("ended", ended);
1208
1985
  }, []);
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
- });
1225
- });
1226
- }
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
- }
1986
+ return [
1987
+ { element: media, currentTime, progress },
1988
+ state,
1989
+ {
1990
+ play,
1991
+ pause,
1992
+ playPause,
1993
+ mute,
1994
+ unmute,
1995
+ toggleMute,
1996
+ setVolume,
1997
+ setDurationPercent,
1998
+ setTime
1241
1999
  }
1242
- return imageService;
1243
- }, [loader, imageServiceStatus]);
1244
- return [loadImageService, imageServiceStatus];
2000
+ ];
1245
2001
  }
1246
2002
 
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 };
1258
-
1259
- const ADD_MAPPING = "@iiif/ADD_MAPPING";
1260
- const ADD_MAPPINGS = "@iiif/ADD_MAPPINGS";
1261
- createAction(ADD_MAPPING)();
1262
- createAction(ADD_MAPPINGS)();
1263
-
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)();
2003
+ const MediaReactContextState = createContext(null);
2004
+ const MediaReactContextActions = createContext(null);
2005
+ const MediaReactContextElements = createContext(null);
2006
+ function useMediaState() {
2007
+ const ctx = useContext(MediaReactContextState);
2008
+ if (!ctx) {
2009
+ throw new Error("Ctx not found");
2010
+ }
2011
+ return ctx;
2012
+ }
2013
+ function useMediaActions() {
2014
+ const ctx = useContext(MediaReactContextActions);
2015
+ if (!ctx) {
2016
+ throw new Error("Ctx not found");
2017
+ }
2018
+ return ctx;
2019
+ }
2020
+ function useMediaElements() {
2021
+ const ctx = useContext(MediaReactContextElements);
2022
+ if (!ctx) {
2023
+ throw new Error("Ctx not found");
2024
+ }
2025
+ return ctx;
2026
+ }
2027
+ function MediaPlayerProvider({
2028
+ actions,
2029
+ state,
2030
+ children,
2031
+ currentTime,
2032
+ progress,
2033
+ element
2034
+ }) {
2035
+ return /* @__PURE__ */ React.createElement(MediaReactContextElements.Provider, {
2036
+ value: { currentTime, progress, element }
2037
+ }, /* @__PURE__ */ React.createElement(MediaReactContextActions.Provider, {
2038
+ value: actions
2039
+ }, /* @__PURE__ */ React.createElement(MediaReactContextState.Provider, {
2040
+ value: state
2041
+ }, children)));
2042
+ }
1280
2043
 
1281
- const BATCH_ACTIONS = "@iiif/BATCH";
1282
- const BATCH_IMPORT = "@iiif/BATCH_IMPORT";
1283
- createAction(BATCH_ACTIONS)();
1284
- createAction(BATCH_IMPORT)();
2044
+ function Audio({ media, children }) {
2045
+ const [{ element, currentTime, progress }, state, actions] = useSimpleMediaPlayer({ duration: media.duration });
2046
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(CanvasPortal, null, /* @__PURE__ */ React.createElement(MediaPlayerProvider, {
2047
+ state,
2048
+ actions,
2049
+ currentTime,
2050
+ progress,
2051
+ element
2052
+ }, /* @__PURE__ */ React.createElement("audio", {
2053
+ ref: element,
2054
+ src: media.url
2055
+ }), children)));
2056
+ }
1285
2057
 
1286
- function isVaultActivated(obj) {
1287
- return typeof obj !== "string" && obj && obj.bindToVault;
2058
+ function Video({ media, children }) {
2059
+ const [{ element, currentTime, progress }, state, actions] = useSimpleMediaPlayer({ duration: media.duration });
2060
+ const Component = "div";
2061
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(CanvasPortal, {
2062
+ overlay: true
2063
+ }, /* @__PURE__ */ React.createElement("style", null, `
2064
+ .video-container {
2065
+ position: absolute;
2066
+ top: 0;
2067
+ bottom: 0;
2068
+ left: 0;
2069
+ right: 0;
2070
+ background: #000;
2071
+ z-index: 13;
2072
+ display: flex;
2073
+ justify-content: center;
2074
+ pointer-events: visible;
2075
+ }
2076
+ `), /* @__PURE__ */ React.createElement(Component, {
2077
+ className: "video-container",
2078
+ part: "video-container",
2079
+ onClick: () => actions.playPause()
2080
+ }, /* @__PURE__ */ React.createElement("video", {
2081
+ ref: element,
2082
+ src: media.url,
2083
+ style: { width: "100%", objectFit: "contain" }
2084
+ }))), /* @__PURE__ */ React.createElement(CanvasPortal, null, /* @__PURE__ */ React.createElement(MediaPlayerProvider, {
2085
+ state,
2086
+ actions,
2087
+ currentTime,
2088
+ progress,
2089
+ element
2090
+ }, children)));
1288
2091
  }
1289
- function useVirtualAnnotationPage() {
1290
- 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: []
1315
- };
1316
- dispatch(entityActions.importEntities({
1317
- entities: {
1318
- AnnotationPage: {
1319
- [page.id]: page
1320
- }
1321
- }
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;
1336
- }
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
- }));
1351
- }
1352
- }
1353
- }
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"
1374
- }
1375
- }));
1376
- }
1377
- }
1378
- }, [virtualId]);
1379
- return [
1380
- fullPage,
1381
- {
1382
- addAnnotation,
1383
- removeAnnotation
1384
- }
1385
- ];
2092
+
2093
+ function Model({ model }) {
2094
+ return /* @__PURE__ */ React.createElement(CanvasPortal, {
2095
+ overlay: true
2096
+ }, /* @__PURE__ */ React.createElement("style", null, `
2097
+ .model-container {
2098
+ position: absolute;
2099
+ top: 0;
2100
+ bottom: 0;
2101
+ left: 0;
2102
+ right: 0;
2103
+ background: #000;
2104
+ z-index: 13;
2105
+ display: flex;
2106
+ justify-content: center;
2107
+ pointer-events: visible;
2108
+ }
2109
+ `), /* @__PURE__ */ React.createElement("div", {
2110
+ className: "model-container"
2111
+ }, /* @__PURE__ */ React.createElement("model-viewer", {
2112
+ "interaction-prompt": "none",
2113
+ style: { width: "100%", height: "100%" },
2114
+ "camera-controls": "",
2115
+ "ar-status": "not-presenting",
2116
+ src: model.id
2117
+ })));
1386
2118
  }
1387
2119
 
1388
2120
  var __defProp = Object.defineProperty;
1389
- var __defProps = Object.defineProperties;
1390
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
1391
2121
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1392
2122
  var __hasOwnProp = Object.prototype.hasOwnProperty;
1393
2123
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -1403,60 +2133,318 @@ var __spreadValues = (a, b) => {
1403
2133
  }
1404
2134
  return a;
1405
2135
  };
1406
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1407
- function useRenderingStrategy(options) {
1408
- const manifest = useManifest();
2136
+ function RenderCanvas({
2137
+ x,
2138
+ y,
2139
+ onChoiceChange,
2140
+ registerActions,
2141
+ defaultChoices,
2142
+ isStatic,
2143
+ renderViewerControls,
2144
+ renderMediaControls,
2145
+ strategies,
2146
+ children
2147
+ }) {
1409
2148
  const canvas = useCanvas();
2149
+ const elementProps = useResourceEvents(canvas, ["deep-zoom"]);
2150
+ const [virtualPage] = useVirtualAnnotationPageContext();
1410
2151
  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
2152
+ const helper = useMemo(() => createStylesHelper(vault), [vault]);
2153
+ const [strategy, actions] = useRenderingStrategy({
2154
+ strategies: strategies || ["images"],
2155
+ defaultChoices: defaultChoices == null ? void 0 : defaultChoices.map(({ id }) => id)
1414
2156
  });
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;
2157
+ const choice = strategy.type === "images" ? strategy.choice : void 0;
2158
+ useEffect(() => {
2159
+ if (registerActions) {
2160
+ registerActions(actions);
1421
2161
  }
1422
- if (paintables.types.length !== 1) {
1423
- if (supports.indexOf("complex-timeline") === -1) {
1424
- return unsupportedStrategy("Complex timeline not supported");
2162
+ }, [strategy.annotations]);
2163
+ useEffect(() => {
2164
+ if (defaultChoices) {
2165
+ for (const choice2 of defaultChoices) {
2166
+ if (typeof choice2.opacity !== "undefined") {
2167
+ helper.applyStyles({ id: choice2.id }, "atlas", {
2168
+ opacity: choice2.opacity
2169
+ });
2170
+ }
1425
2171
  }
1426
- return unsupportedStrategy("ComplexTimelineStrategy not yet supported");
1427
2172
  }
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);
2173
+ }, [defaultChoices]);
2174
+ useLayoutEffect(() => {
2175
+ if (onChoiceChange) {
2176
+ onChoiceChange(choice);
1434
2177
  }
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");
2178
+ }, [choice]);
2179
+ const thumbnail = useThumbnail({ maxWidth: 256, maxHeight: 256 });
2180
+ if (!canvas) {
2181
+ return null;
2182
+ }
2183
+ const accompanyingCanvas = canvas.accompanyingCanvas;
2184
+ const thumbnailFallbackImage = thumbnail && thumbnail.type === "fixed" ? /* @__PURE__ */ React$1.createElement("world-object", {
2185
+ height: canvas.height,
2186
+ width: canvas.width,
2187
+ x,
2188
+ y
2189
+ }, /* @__PURE__ */ React$1.createElement("world-image", {
2190
+ uri: thumbnail.id,
2191
+ target: { x: 0, y: 0, width: canvas.width, height: canvas.height },
2192
+ display: thumbnail.width && thumbnail.height ? {
2193
+ width: thumbnail.width,
2194
+ height: thumbnail.height
2195
+ } : void 0
2196
+ })) : null;
2197
+ if (strategy.type === "unknown") {
2198
+ if (thumbnailFallbackImage) {
2199
+ return thumbnailFallbackImage;
1440
2200
  }
1441
- if (mainType === "video") {
1442
- if (supports.indexOf("media") === -1) {
1443
- return unsupportedStrategy("Media not supported");
2201
+ throw new Error(strategy.reason || "Unknown image strategy");
2202
+ }
2203
+ const annotations = /* @__PURE__ */ React$1.createElement(Fragment, null, virtualPage ? /* @__PURE__ */ React$1.createElement(RenderAnnotationPage, {
2204
+ page: virtualPage
2205
+ }) : null, strategy.annotations && strategy.annotations.pages ? strategy.annotations.pages.map((page) => {
2206
+ return /* @__PURE__ */ React$1.createElement(RenderAnnotationPage, {
2207
+ key: page.id,
2208
+ page
2209
+ });
2210
+ }) : null, children);
2211
+ return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, /* @__PURE__ */ React$1.createElement("world-object", __spreadValues({
2212
+ key: strategy.type,
2213
+ height: canvas.height,
2214
+ width: canvas.width,
2215
+ x,
2216
+ y
2217
+ }, elementProps), strategy.type === "images" ? /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, strategy.images.map((image, idx) => {
2218
+ return /* @__PURE__ */ React$1.createElement(RenderImage, {
2219
+ isStatic,
2220
+ key: image.id,
2221
+ image,
2222
+ id: image.id,
2223
+ thumbnail: idx === 0 ? thumbnail : void 0,
2224
+ annotations
2225
+ });
2226
+ }), renderViewerControls ? /* @__PURE__ */ React$1.createElement(CanvasPortal, {
2227
+ overlay: true
2228
+ }, renderViewerControls(strategy)) : null) : null, strategy.type === "3d-model" ? /* @__PURE__ */ React$1.createElement(Model, {
2229
+ model: strategy.model
2230
+ }) : null, strategy.type === "media" ? /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, strategy.media.type === "Sound" ? /* @__PURE__ */ React$1.createElement(Audio, {
2231
+ media: strategy.media
2232
+ }, thumbnailFallbackImage, renderMediaControls ? renderMediaControls(strategy) : null) : strategy.media.type === "Video" ? /* @__PURE__ */ React$1.createElement(Video, {
2233
+ media: strategy.media
2234
+ }, thumbnailFallbackImage, renderMediaControls ? renderMediaControls(strategy) : null) : null) : null), strategy.type === "media" && strategy.media.type === "Sound" && accompanyingCanvas ? /* @__PURE__ */ React$1.createElement(CanvasContext, {
2235
+ canvas: accompanyingCanvas.id
2236
+ }, /* @__PURE__ */ React$1.createElement(RenderCanvas, null)) : null);
2237
+ }
2238
+
2239
+ const CanvasPanel = {
2240
+ RenderImage,
2241
+ RenderCanvas,
2242
+ RenderAnnotationPage,
2243
+ RenderAnnotation,
2244
+ Viewer
2245
+ };
2246
+
2247
+ function AnnotationContext({ annotation, children }) {
2248
+ return /* @__PURE__ */ React$1.createElement(ResourceProvider, {
2249
+ value: { annotation }
2250
+ }, children);
2251
+ }
2252
+
2253
+ function CollectionContext({ collection, children }) {
2254
+ return /* @__PURE__ */ React$1.createElement(ResourceProvider, {
2255
+ value: { collection }
2256
+ }, children);
2257
+ }
2258
+
2259
+ function RangeContext({ range, children }) {
2260
+ return /* @__PURE__ */ React$1.createElement(ResourceProvider, {
2261
+ value: { range }
2262
+ }, children);
2263
+ }
2264
+
2265
+ function useAnnotationsAtTime(time, options = {}) {
2266
+ const allAnnotations = usePaintingAnnotations(options);
2267
+ return allAnnotations;
2268
+ }
2269
+
2270
+ function useCanvasClock(canvasId, autoplay = false) {
2271
+ }
2272
+
2273
+ function useCollection(options, deps = []) {
2274
+ const { id, selector } = options;
2275
+ const ctx = useResourceContext();
2276
+ const collectionId = id ? id : ctx.collection;
2277
+ const collection = useVaultSelector((s) => collectionId ? s.iiif.entities.Collection[collectionId] : void 0, [collectionId]);
2278
+ return useMemo(() => {
2279
+ if (!collection) {
2280
+ return void 0;
2281
+ }
2282
+ if (selector) {
2283
+ return selector(collection);
2284
+ }
2285
+ return collection;
2286
+ }, [collection, selector, ...deps]);
2287
+ }
2288
+
2289
+ function useEventListener(resource, name, listener, scope, deps = []) {
2290
+ const vault = useVault();
2291
+ const helper = useMemo(() => createEventsHelper(vault), [vault]);
2292
+ useEffect(() => {
2293
+ const currentResource = resource;
2294
+ if (!currentResource) {
2295
+ return () => {
2296
+ };
2297
+ }
2298
+ helper.addEventListener(currentResource, name, listener, scope);
2299
+ return () => {
2300
+ helper.removeEventListener(currentResource, name, listener);
2301
+ };
2302
+ }, [helper, resource, name, ...deps]);
2303
+ }
2304
+
2305
+ function useExistingVault() {
2306
+ const oldContext = useContext(ReactVaultContext);
2307
+ return oldContext && oldContext.vault ? oldContext.vault : globalVault();
2308
+ }
2309
+
2310
+ function useExternalCollection(idOrRef, options) {
2311
+ const { id, isLoaded, error, resource, requestId, cached } = useExternalResource(idOrRef, options);
2312
+ return { id, isLoaded, error, manifest: resource, requestId, cached };
2313
+ }
2314
+
2315
+ var __async = (__this, __arguments, generator) => {
2316
+ return new Promise((resolve, reject) => {
2317
+ var fulfilled = (value) => {
2318
+ try {
2319
+ step(generator.next(value));
2320
+ } catch (e) {
2321
+ reject(e);
2322
+ }
2323
+ };
2324
+ var rejected = (value) => {
2325
+ try {
2326
+ step(generator.throw(value));
2327
+ } catch (e) {
2328
+ reject(e);
2329
+ }
2330
+ };
2331
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
2332
+ step((generator = generator.apply(__this, __arguments)).next());
2333
+ });
2334
+ };
2335
+ function useImageService({ cacheKey } = {}) {
2336
+ const canvas = useCanvas();
2337
+ const annotations = usePaintingAnnotations();
2338
+ const vault = useVault();
2339
+ const imageService = useImageServiceLoader();
2340
+ const [_data, setData] = useState(void 0);
2341
+ const [isFetching, setIsFetching] = useState(false);
2342
+ const [status, setStatus] = useState("idle");
2343
+ const [error, setError] = useState(void 0);
2344
+ const key = canvas ? canvas.id : "undefined";
2345
+ const initialData = useMemo(() => {
2346
+ try {
2347
+ if (canvas && annotations.length) {
2348
+ const annotation = annotations[0];
2349
+ const resource = vault.get(annotation.body[0]);
2350
+ const imageServices = getImageServices(resource);
2351
+ const firstImageService = imageServices[0];
2352
+ if (!firstImageService) {
2353
+ return void 0;
2354
+ }
2355
+ return imageService.loadServiceSync({
2356
+ id: firstImageService.id || firstImageService["@id"],
2357
+ width: firstImageService.width || canvas.width,
2358
+ height: firstImageService.height || canvas.height
2359
+ }) || void 0;
1444
2360
  }
1445
- return unsupportedStrategy("Video strategy not yet supported");
2361
+ } catch (e) {
2362
+ console.error(e);
1446
2363
  }
1447
- return unknownResponse;
1448
- }, [canvas, paintables, vault, actions.makeChoice]);
2364
+ return void 0;
2365
+ }, [key, cacheKey, canvas]);
2366
+ const data = status === "success" && _data ? _data : initialData;
2367
+ useEffect(() => {
2368
+ (() => __async(this, null, function* () {
2369
+ try {
2370
+ if (canvas && annotations.length) {
2371
+ const annotation = annotations[0];
2372
+ const resource = vault.get(annotation.body[0]);
2373
+ const imageServices = getImageServices(resource);
2374
+ const firstImageService = imageServices[0];
2375
+ if (!firstImageService) {
2376
+ return;
2377
+ }
2378
+ setIsFetching(true);
2379
+ setStatus("loading");
2380
+ try {
2381
+ const loadedService = (yield imageService.loadService({
2382
+ id: firstImageService.id || firstImageService["@id"],
2383
+ width: firstImageService.width || canvas.width,
2384
+ height: firstImageService.height || canvas.height
2385
+ })) || void 0;
2386
+ setData(loadedService);
2387
+ setStatus("success");
2388
+ setIsFetching(false);
2389
+ } catch (err) {
2390
+ setStatus("error");
2391
+ setError(err);
2392
+ }
2393
+ }
2394
+ } catch (err) {
2395
+ setStatus("error");
2396
+ setError(err);
2397
+ }
2398
+ }))();
2399
+ }, [key, cacheKey]);
1449
2400
  return useMemo(() => {
1450
- if (strategy.type === "unknown") {
1451
- return [strategy, emptyActions];
2401
+ return {
2402
+ data,
2403
+ isFetching,
2404
+ status,
2405
+ error
2406
+ };
2407
+ }, [data, isFetching, status, error]);
2408
+ }
2409
+
2410
+ function useImageTile() {
2411
+ const imageService = useImageService();
2412
+ return {
2413
+ isLoading: imageService.isFetching,
2414
+ tile: imageService.data ? {
2415
+ id: imageService.data.id || imageService.data["@id"],
2416
+ width: imageService.data.width,
2417
+ height: imageService.data.height,
2418
+ imageService: imageService.data,
2419
+ thumbnail: void 0
2420
+ } : null
2421
+ };
2422
+ }
2423
+
2424
+ function useRange(options = {}, deps = []) {
2425
+ const { id, selector } = options;
2426
+ const ctx = useResourceContext();
2427
+ const rangeId = id ? id : ctx.range;
2428
+ const range = useVaultSelector((s) => rangeId ? s.iiif.entities.Range[rangeId] : void 0, [rangeId]);
2429
+ return useMemo(() => {
2430
+ if (!range) {
2431
+ return void 0;
1452
2432
  }
1453
- return [
1454
- __spreadProps(__spreadValues({}, strategy), {
1455
- annotations: { pages: enabledPages }
1456
- }),
1457
- actions
1458
- ];
1459
- }, [strategy, enabledPages]);
2433
+ if (selector) {
2434
+ return selector(range);
2435
+ }
2436
+ return range;
2437
+ }, [range, selector, ...deps]);
2438
+ }
2439
+
2440
+ function useSearchService() {
2441
+ const manifest = useManifest();
2442
+ return manifest ? manifest.service.find((service) => service.profile === "SearchService1" || service.profile === "http://iiif.io/api/search/1/search") : void 0;
2443
+ }
2444
+
2445
+ function useStyleHelper() {
2446
+ const vault = useVault();
2447
+ return useMemo(() => createStylesHelper(vault), [vault]);
1460
2448
  }
1461
2449
 
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 };
2450
+ export { AnnotationContext, CanvasContext, CanvasPanel, CanvasPortal, CollectionContext, ContextBridge, ImageServiceLoaderContext, ManifestContext, MediaPlayerProvider, OverlayPortalContext, PortalContext, RangeContext, ReactVaultContext, ResourceProvider, ResourceReactContext, SimpleViewerProvider, SimpleViewerReactContext, VaultProvider, VirtualAnnotationProvider, VisibleCanvasReactContext, emptyActions, expandTarget, flattenAnnotationPageIds, formatTime, getImageStrategy, getPaintables, parseSelector, parseSpecificResource, unknownResponse, unsupportedStrategy, useAnnotation, useAnnotationPageManager, useAnnotationsAtTime, useCanvas, useCanvasClock, useCollection, useContextBridge, useDispatch, useEventListener, useExistingVault, useExternalCollection, useExternalManifest, useExternalResource, useImageService, useImageServiceLoader, useImageTile, useLoadImageService, useManifest, useMediaActions, useMediaElements, useMediaState, usePaintables, usePaintingAnnotations, useRange, useRenderingStrategy, useResourceContext, useResourceEvents, useResources, useSearchService, useSimpleMediaPlayer, useSimpleViewer, useStyleHelper, useStyles, useThumbnail, useVault, useVaultEffect, useVaultSelector, useVirtualAnnotationPage, useVirtualAnnotationPageContext, useVisibleCanvases };