react-iiif-vault 0.9.9 → 0.9.12

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