react-iiif-vault 0.9.15 → 0.9.16

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 (34) hide show
  1. package/.build/types/canvas-panel/Viewer.d.ts +1 -1
  2. package/.build/types/canvas-panel/index.d.ts +2 -0
  3. package/.build/types/canvas-panel/render/Canvas.d.ts +8 -3
  4. package/.build/types/canvas-panel/render/CanvasBackground.d.ts +4 -0
  5. package/.build/types/canvas-panel/render/Image.d.ts +2 -2
  6. package/.build/types/context/ContextBridge.d.ts +1 -9
  7. package/.build/types/context/PortalContext.d.ts +3 -2
  8. package/.build/types/features/rendering-strategy/3d-strategy.d.ts +1 -1
  9. package/.build/types/features/rendering-strategy/rendering-utils.d.ts +5 -1
  10. package/.build/types/features/rendering-strategy/resource-types.d.ts +3 -0
  11. package/.build/types/features/rendering-strategy/strategies.d.ts +10 -1
  12. package/.build/types/features/rendering-strategy/textual-content-strategy.d.ts +17 -0
  13. package/.build/types/future-helpers/ranges.d.ts +6 -0
  14. package/.build/types/future-helpers/sequences.d.ts +6 -0
  15. package/.build/types/hooks/useCanvasSubset.d.ts +2 -0
  16. package/.build/types/index.d.ts +5 -0
  17. package/.build/types/viewers/SimpleViewerContext.d.ts +4 -16
  18. package/.build/types/viewers/SimpleViewerContext.hooks.d.ts +14 -0
  19. package/.build/types/viewers/SimpleViewerContext.types.d.ts +42 -0
  20. package/dist/bundle/cjs/index.js +5 -3
  21. package/dist/bundle/cjs/index.js.map +1 -1
  22. package/dist/bundle/esm/index.mjs +1020 -214
  23. package/dist/bundle/esm/index.mjs.map +1 -1
  24. package/dist/canvas-panel/cjs/canvas-panel.js +5 -3
  25. package/dist/canvas-panel/cjs/canvas-panel.js.map +1 -1
  26. package/dist/canvas-panel/esm/canvas-panel.mjs +729 -94
  27. package/dist/canvas-panel/esm/canvas-panel.mjs.map +1 -1
  28. package/dist/index.umd.js +22 -20
  29. package/dist/index.umd.js.map +1 -1
  30. package/dist/react17/cjs/index.js +30 -0
  31. package/dist/react17/cjs/index.js.map +1 -0
  32. package/dist/react17/esm/index.mjs +3186 -0
  33. package/dist/react17/esm/index.mjs.map +1 -0
  34. package/package.json +13 -8
@@ -30,12 +30,13 @@ var __objRest = (source, exclude) => {
30
30
  return target;
31
31
  };
32
32
  import * as React from "react";
33
- import React__default, { useContext, useMemo, useState, useEffect, createContext, useCallback, useRef, useLayoutEffect, Fragment, useReducer } from "react";
34
- import { AtlasAuto, mergeStyles, RegionHighlight, TileSet } from "@atlas-viewer/atlas";
33
+ import React__default, { useContext, useMemo, useState, useEffect, useCallback, createContext, useRef, useLayoutEffect, Fragment, useReducer } from "react";
34
+ import { AtlasAuto, mergeStyles, RegionHighlight, TileSet, HTMLPortal } from "@atlas-viewer/atlas";
35
35
  import { jsx, jsxs, Fragment as Fragment$1 } from "react/jsx-runtime";
36
36
  import { globalVault, Vault } from "@iiif/vault";
37
37
  import { createAction } from "typesafe-actions";
38
- import require$$0 from "react-dom";
38
+ import { createRoot } from "react-dom/client";
39
+ import { expandTarget as expandTarget$1 } from "@iiif/vault-helpers";
39
40
  import { ImageServiceLoader, getImageServices, getFixedSizeFromImage } from "@atlas-viewer/iiif-image-api";
40
41
  function _setPrototypeOf(o, p) {
41
42
  _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf2(o2, p2) {
@@ -267,6 +268,238 @@ function useVisibleCanvases() {
267
268
  return ids.map((id) => state.iiif.entities.Canvas[id]).filter(Boolean);
268
269
  }, [ids]);
269
270
  }
271
+ function useManifest(options = {}, deps = []) {
272
+ const { id, selector } = options;
273
+ const ctx = useResourceContext();
274
+ useVault();
275
+ const manifestId = id ? id : ctx.manifest;
276
+ const manifest = useVaultSelector((s) => manifestId ? s.iiif.entities.Manifest[manifestId] : void 0, [manifestId]);
277
+ return useMemo(() => {
278
+ if (!manifest) {
279
+ return void 0;
280
+ }
281
+ if (selector) {
282
+ return selector(manifest);
283
+ }
284
+ return manifest;
285
+ }, [manifest, selector, ...deps]);
286
+ }
287
+ function RangeContext({
288
+ range,
289
+ children
290
+ }) {
291
+ return /* @__PURE__ */ jsx(ResourceProvider, {
292
+ value: {
293
+ range
294
+ },
295
+ children
296
+ });
297
+ }
298
+ function findFirstCanvasFromRange(vault, range) {
299
+ for (const inner of range.items) {
300
+ if (inner.type === "Canvas") {
301
+ return inner;
302
+ }
303
+ if (inner.type === "Range") {
304
+ const found = findFirstCanvasFromRange(vault, vault.get(inner));
305
+ if (found) {
306
+ return found;
307
+ }
308
+ }
309
+ }
310
+ return null;
311
+ }
312
+ function findAllCanvasesInRange(vault, range) {
313
+ const found = [];
314
+ for (const inner of range.items) {
315
+ if (inner.type === "Canvas") {
316
+ if (inner.id.indexOf("#") !== -1) {
317
+ found.push({ id: inner.id.split("#")[0], type: "Canvas" });
318
+ } else {
319
+ found.push(inner);
320
+ }
321
+ }
322
+ if (inner.type === "Range") {
323
+ found.push(...findAllCanvasesInRange(vault, vault.get(inner)));
324
+ }
325
+ if (inner.type === "SpecificResource") {
326
+ const sourceId = typeof inner.source === "string" ? inner.source : inner.source.id;
327
+ found.push({ id: sourceId, type: "Canvas" });
328
+ }
329
+ }
330
+ return found;
331
+ }
332
+ function findManifestSelectedRange(vault, manifest, canvasId) {
333
+ for (const range of manifest.structures) {
334
+ const found = findSelectedRange(vault, vault.get(range), canvasId);
335
+ if (found) {
336
+ return found;
337
+ }
338
+ }
339
+ return null;
340
+ }
341
+ function findSelectedRange(vault, range, canvasId) {
342
+ var _a;
343
+ for (const inner of range.items) {
344
+ const parsedId = (_a = inner.id) == null ? void 0 : _a.split("#")[0];
345
+ if (inner.type === "SpecificResource" && inner.source === canvasId) {
346
+ return range;
347
+ }
348
+ if (inner.type === "Canvas" && canvasId === parsedId) {
349
+ return range;
350
+ }
351
+ if (inner.type === "Range") {
352
+ const found = findSelectedRange(vault, vault.get(inner), canvasId);
353
+ if (found) {
354
+ return found;
355
+ }
356
+ }
357
+ }
358
+ return null;
359
+ }
360
+ function getVisibleCanvasesFromCanvasId(vault, manifestOrRange, canvasId, preventPaged = false) {
361
+ const behavior = manifestOrRange.behavior;
362
+ const fullCanvas = canvasId ? vault.get(canvasId) : null;
363
+ if (!fullCanvas) {
364
+ return [];
365
+ }
366
+ const canvasBehavior = fullCanvas.behavior;
367
+ const isPaged = preventPaged ? false : behavior.includes("paged");
368
+ const isContinuous = isPaged ? false : behavior.includes("continuous");
369
+ const isIndividuals = isPaged || isContinuous ? false : behavior.includes("individuals");
370
+ const isCanvasFacingPages = canvasBehavior.includes("facing-pages");
371
+ const isCanvasNonPaged = canvasBehavior.includes("non-paged");
372
+ if (isCanvasFacingPages || isCanvasNonPaged || isIndividuals || preventPaged) {
373
+ return [{ id: fullCanvas.id, type: "Canvas" }];
374
+ }
375
+ const [manifestItems, ordering] = getManifestSequence(vault, manifestOrRange);
376
+ if (isContinuous) {
377
+ return manifestItems;
378
+ }
379
+ const canvasIndex = manifestItems.findIndex((r) => r.id === canvasId);
380
+ if (canvasIndex === -1) {
381
+ return [];
382
+ }
383
+ for (const indexes of ordering) {
384
+ if (indexes.includes(canvasIndex)) {
385
+ return indexes.map((index) => manifestItems[index]);
386
+ }
387
+ }
388
+ return [{ id: fullCanvas.id, type: "Canvas" }];
389
+ }
390
+ function getManifestSequence(vault, manifestOrRange, { disablePaging } = {}) {
391
+ const behavior = manifestOrRange.behavior;
392
+ const isPaged = behavior.includes("paged");
393
+ const isContinuous = isPaged ? false : behavior.includes("continuous");
394
+ const isIndividuals = isPaged || isContinuous ? false : behavior.includes("individuals");
395
+ const manifestItems = manifestOrRange.type === "Manifest" ? manifestOrRange.items : findAllCanvasesInRange(vault, manifestOrRange);
396
+ if (isContinuous) {
397
+ return [manifestItems, [manifestItems.map((_, index) => index)]];
398
+ }
399
+ if (isIndividuals || !isPaged || disablePaging) {
400
+ return [manifestItems, manifestItems.map((_, index) => [index])];
401
+ }
402
+ const ordering = [];
403
+ let currentOrdering = [];
404
+ const flush = () => {
405
+ if (currentOrdering.length) {
406
+ ordering.push([...currentOrdering]);
407
+ currentOrdering = [];
408
+ }
409
+ };
410
+ for (let i = 0; i < manifestItems.length; i++) {
411
+ const canvas = vault.get(manifestItems[i]);
412
+ if (i === 0 || canvas.behavior.includes("facing-pages")) {
413
+ flush();
414
+ ordering.push([i]);
415
+ continue;
416
+ }
417
+ if (canvas.behavior.includes("non-paged")) {
418
+ continue;
419
+ }
420
+ currentOrdering.push(i);
421
+ if (currentOrdering.length > 1) {
422
+ flush();
423
+ }
424
+ }
425
+ if (currentOrdering.length) {
426
+ flush();
427
+ }
428
+ return [manifestItems, ordering];
429
+ }
430
+ function useRange(options = {}, deps = []) {
431
+ const { id, selector } = options;
432
+ const ctx = useResourceContext();
433
+ const rangeId = id ? id : ctx.range;
434
+ const range = useVaultSelector((s) => rangeId ? s.iiif.entities.Range[rangeId] : void 0, [rangeId]);
435
+ return useMemo(() => {
436
+ if (!range) {
437
+ return void 0;
438
+ }
439
+ if (selector) {
440
+ return selector(range);
441
+ }
442
+ return range;
443
+ }, [range, selector, ...deps]);
444
+ }
445
+ function useCanvasSequence({ startCanvas, disablePaging }) {
446
+ var _a;
447
+ const vault = useVault();
448
+ const manifest = useManifest();
449
+ const range = useRange();
450
+ const [cursor, setCursor] = useState(void 0);
451
+ const rangeOrManifest = range ? range : manifest;
452
+ if (!rangeOrManifest) {
453
+ throw new Error("Nothing selected");
454
+ }
455
+ const [items, initialSequence] = useMemo(() => getManifestSequence(vault, rangeOrManifest, { disablePaging }), [vault, rangeOrManifest]);
456
+ const setCanvasIndex = useCallback((index) => {
457
+ const foundSequence = initialSequence.findIndex((i) => i.includes(index));
458
+ setCursor(foundSequence === -1 ? 0 : foundSequence);
459
+ }, [items, initialSequence]);
460
+ const setCanvasId = useCallback((id) => {
461
+ const foundIndex = items.findIndex((i) => i.id === id);
462
+ if (foundIndex !== -1) {
463
+ setCanvasIndex(foundIndex);
464
+ } else {
465
+ setCursor(0);
466
+ }
467
+ }, [items, initialSequence]);
468
+ const next = useCallback(() => {
469
+ setCursor((i) => {
470
+ if (i >= initialSequence.length) {
471
+ return i;
472
+ }
473
+ return i + 1;
474
+ });
475
+ }, [initialSequence]);
476
+ const previous = useCallback(() => {
477
+ setCursor((i) => {
478
+ if (i <= 0) {
479
+ return 0;
480
+ }
481
+ return i - 1;
482
+ });
483
+ }, [initialSequence]);
484
+ if (typeof cursor === "undefined") {
485
+ if (startCanvas) {
486
+ setCanvasId(startCanvas);
487
+ } else {
488
+ setCursor(0);
489
+ }
490
+ }
491
+ return {
492
+ visibleItems: ((_a = initialSequence[cursor]) == null ? void 0 : _a.map((idx) => items[idx].id)) || [],
493
+ cursor,
494
+ items,
495
+ sequence: initialSequence,
496
+ setSequenceIndex: setCursor,
497
+ setCanvasIndex,
498
+ setCanvasId,
499
+ next,
500
+ previous
501
+ };
502
+ }
270
503
  const noop = () => {
271
504
  };
272
505
  const SimpleViewerReactContext = createContext({
@@ -274,92 +507,58 @@ const SimpleViewerReactContext = createContext({
274
507
  setCurrentCanvasIndex: noop,
275
508
  nextCanvas: noop,
276
509
  previousCanvas: noop,
277
- currentCanvasIndex: -1,
278
- totalCanvases: 0,
279
- pagingView: true
510
+ items: [],
511
+ sequence: [],
512
+ setSequenceIndex: noop,
513
+ currentSequenceIndex: 0
280
514
  });
515
+ function InnerViewerProvider(props) {
516
+ const manifest = useManifest();
517
+ const {
518
+ cursor,
519
+ visibleItems,
520
+ next,
521
+ sequence,
522
+ items,
523
+ setCanvasIndex,
524
+ setCanvasId,
525
+ previous,
526
+ setSequenceIndex
527
+ } = useCanvasSequence({
528
+ startCanvas: props.startCanvas,
529
+ disablePaging: props.pagingEnabled === false
530
+ });
531
+ const ctx = useMemo(() => ({
532
+ sequence,
533
+ items,
534
+ setCurrentCanvasId: setCanvasId,
535
+ nextCanvas: next,
536
+ previousCanvas: previous,
537
+ totalCanvases: items.length,
538
+ setCurrentCanvasIndex: setCanvasIndex,
539
+ setSequenceIndex,
540
+ currentSequenceIndex: cursor
541
+ }), [sequence, items, setCanvasId, next, previous, items, setCanvasIndex, setSequenceIndex, cursor]);
542
+ if (!manifest) {
543
+ console.warn("The manifest passed to the provider is not a valid IIIF manifest.");
544
+ return /* @__PURE__ */ jsx("div", {
545
+ children: "Sorry, something went wrong."
546
+ });
547
+ }
548
+ return /* @__PURE__ */ jsx(SimpleViewerReactContext.Provider, {
549
+ value: ctx,
550
+ children: /* @__PURE__ */ jsx(VisibleCanvasReactContext.Provider, {
551
+ value: visibleItems,
552
+ children: /* @__PURE__ */ jsx(CanvasContext, {
553
+ canvas: visibleItems[0],
554
+ children: props.children
555
+ })
556
+ })
557
+ });
558
+ }
281
559
  function SimpleViewerProvider(props) {
282
560
  const manifest = useExternalManifest(props.manifest);
283
- const [currentCanvasId, setCurrentCanvasId] = useState("");
284
- const [visible, setVisible] = useState([]);
285
- const pagingView = (typeof props.pagingEnabled === "undefined" || props.pagingEnabled) && manifest.manifest && manifest.manifest.behavior && manifest.manifest.behavior.includes("paged");
286
- useEffect(() => {
287
- var _a, _b;
288
- if (manifest.manifest) {
289
- setCurrentCanvasId((_a = manifest.manifest.items[0]) == null ? void 0 : _a.id);
290
- setVisible([(_b = manifest.manifest.items[0]) == null ? void 0 : _b.id]);
291
- }
292
- }, [manifest.manifest, props.manifest]);
293
- const canvasList = useMemo(() => {
294
- var _a;
295
- return ((_a = manifest.manifest) == null ? void 0 : _a.items.map((c) => c.id)) || [];
296
- }, [manifest.manifest, props.manifest]);
297
- const currentCanvasIndex = useMemo(() => canvasList.indexOf(currentCanvasId), [canvasList, currentCanvasId]);
298
- const nextCanvas = useCallback(() => {
299
- if (canvasList.length && currentCanvasId) {
300
- if (currentCanvasIndex === -1) {
301
- return;
302
- }
303
- if (canvasList[currentCanvasIndex + 2] ? currentCanvasIndex + 2 === canvasList.length : currentCanvasIndex === canvasList.length) {
304
- return;
305
- }
306
- const newCanvas = pagingView && currentCanvasIndex !== 0 ? canvasList[currentCanvasIndex + 2] : canvasList[currentCanvasIndex + 1];
307
- const pageCanvas = pagingView ? currentCanvasIndex !== 0 ? canvasList[currentCanvasIndex + 3] : canvasList[currentCanvasIndex + 2] : null;
308
- if (newCanvas) {
309
- setCurrentCanvasId(newCanvas);
310
- setVisible(pageCanvas ? [newCanvas, pageCanvas] : [newCanvas]);
311
- }
312
- }
313
- }, [pagingView, canvasList, currentCanvasId, currentCanvasIndex]);
314
- const previousCanvas = useCallback(() => {
315
- if (canvasList.length && currentCanvasId) {
316
- if (currentCanvasIndex === 0 || currentCanvasIndex === -1) {
317
- return;
318
- }
319
- const newCanvas = pagingView && currentCanvasIndex !== 1 ? canvasList[currentCanvasIndex - 2] : canvasList[currentCanvasIndex - 1];
320
- const pageCanvas = pagingView && currentCanvasIndex !== 1 ? canvasList[currentCanvasIndex - 1] : null;
321
- if (newCanvas) {
322
- setCurrentCanvasId(newCanvas);
323
- setVisible(pageCanvas ? [newCanvas, pageCanvas] : [newCanvas]);
324
- }
325
- }
326
- }, [pagingView, canvasList, currentCanvasId, currentCanvasIndex]);
327
- const setCurrentCanvasIndex = useCallback((idx) => {
328
- const realIdx = pagingView && idx % 2 === 1 ? idx - 1 : idx;
329
- const newId = canvasList[realIdx];
330
- const newNextId = pagingView && realIdx !== 0 ? canvasList[realIdx + 1] : null;
331
- if (newId) {
332
- setCurrentCanvasId(newId);
333
- setVisible((prevValue) => {
334
- const newValue = newNextId ? [newId, newNextId] : [newId];
335
- if (prevValue.length === prevValue.length) {
336
- for (let i = 0; i < prevValue.length; i++) {
337
- if (prevValue[i] !== newValue[i]) {
338
- return newValue;
339
- }
340
- }
341
- return prevValue;
342
- }
343
- return newValue;
344
- });
345
- }
346
- }, [pagingView, canvasList]);
347
- const internalSetCurrentCanvasId = useCallback((nextId) => {
348
- const idx = canvasList.indexOf(nextId);
349
- if (idx !== -1) {
350
- setCurrentCanvasIndex(idx);
351
- }
352
- }, [canvasList, setCurrentCanvasIndex]);
353
- const ctx = useMemo(() => ({
354
- setCurrentCanvasId: internalSetCurrentCanvasId,
355
- nextCanvas,
356
- previousCanvas,
357
- currentCanvasIndex,
358
- totalCanvases: canvasList.length,
359
- setCurrentCanvasIndex,
360
- pagingView: true
361
- }), [nextCanvas, previousCanvas, currentCanvasIndex, canvasList, setCurrentCanvasIndex, internalSetCurrentCanvasId]);
362
- if (!manifest.manifest) {
561
+ if (!manifest) {
363
562
  console.warn("The manifest passed to the provider is not a valid IIIF manifest.");
364
563
  return /* @__PURE__ */ jsx("div", {
365
564
  children: "Sorry, something went wrong."
@@ -370,18 +569,15 @@ function SimpleViewerProvider(props) {
370
569
  children: "Loading..."
371
570
  });
372
571
  }
373
- return /* @__PURE__ */ jsx(SimpleViewerReactContext.Provider, {
374
- value: ctx,
375
- children: /* @__PURE__ */ jsx(VisibleCanvasReactContext.Provider, {
376
- value: visible,
377
- children: /* @__PURE__ */ jsx(ManifestContext, {
378
- manifest: manifest.manifest.id,
379
- children: /* @__PURE__ */ jsx(CanvasContext, {
380
- canvas: currentCanvasId,
381
- children: props.children
382
- })
383
- })
384
- })
572
+ const inner = /* @__PURE__ */ jsx(InnerViewerProvider, __spreadProps(__spreadValues({}, props), {
573
+ children: props.children
574
+ }));
575
+ return /* @__PURE__ */ jsx(ManifestContext, {
576
+ manifest: manifest.id,
577
+ children: props.rangeId ? /* @__PURE__ */ jsx(RangeContext, {
578
+ range: props.rangeId,
579
+ children: inner
580
+ }) : inner
385
581
  });
386
582
  }
387
583
  function useSimpleViewer() {
@@ -591,11 +787,6 @@ function DefaultCanvasFallback({
591
787
  children: "Unknown error"
592
788
  });
593
789
  }
594
- var createRoot;
595
- var m = require$$0;
596
- {
597
- createRoot = m.createRoot;
598
- }
599
790
  const ViewerPresetContext = createContext(null);
600
791
  function useViewerPreset() {
601
792
  return useContext(ViewerPresetContext);
@@ -607,26 +798,16 @@ function CanvasPortal({
607
798
  overlay
608
799
  }) {
609
800
  const htmlElement = useContext(overlay ? OverlayPortalContext : PortalContext);
610
- const rootRef = useRef(null);
611
801
  const preset = useViewerPreset();
612
802
  useLayoutEffect(() => {
613
- if (!rootRef.current) {
614
- rootRef.current = htmlElement ? createRoot(htmlElement) : null;
615
- }
616
- }, []);
617
- useLayoutEffect(() => {
618
- return () => {
619
- var _a;
620
- (_a = rootRef.current) == null ? void 0 : _a.unmount();
621
- rootRef.current = null;
622
- };
623
- }, []);
624
- useLayoutEffect(() => {
625
- if (rootRef.current) {
626
- rootRef.current.render(/* @__PURE__ */ jsx(ViewerPresetContext.Provider, {
627
- value: preset,
628
- children
629
- }));
803
+ if (htmlElement) {
804
+ try {
805
+ htmlElement.render(/* @__PURE__ */ jsx(ViewerPresetContext.Provider, {
806
+ value: preset,
807
+ children
808
+ }));
809
+ } catch (e) {
810
+ }
630
811
  }
631
812
  }, [children, preset]);
632
813
  return null;
@@ -649,8 +830,31 @@ function Viewer(_a) {
649
830
  const bridge = useContextBridge();
650
831
  const ErrorFallback = errorFallback || DefaultCanvasFallback;
651
832
  useLayoutEffect(() => {
652
- setPortalElement(portal.current);
653
- setOverlayPortalElement(overlayPortal.current);
833
+ const roots = {};
834
+ if (portal.current) {
835
+ const $el = document.createElement("div");
836
+ portal.current.appendChild($el);
837
+ roots.portal = createRoot($el);
838
+ setPortalElement(roots.portal);
839
+ }
840
+ if (overlayPortal.current) {
841
+ const $el = document.createElement("div");
842
+ overlayPortal.current.appendChild($el);
843
+ roots.overlayPortal = createRoot($el);
844
+ setOverlayPortalElement(roots.overlayPortal);
845
+ }
846
+ return () => {
847
+ setPortalElement(null);
848
+ setOverlayPortalElement(null);
849
+ setTimeout(() => {
850
+ if (roots.portal) {
851
+ roots.portal.unmount();
852
+ }
853
+ if (roots.overlayPortal) {
854
+ roots.overlayPortal.unmount();
855
+ }
856
+ }, 0);
857
+ };
654
858
  }, []);
655
859
  return /* @__PURE__ */ jsxs(ErrorBoundary, {
656
860
  fallbackRender: () => /* @__PURE__ */ jsx(ErrorFallback, __spreadValues({}, props)),
@@ -773,25 +977,25 @@ function useStyles(resource, scope) {
773
977
  return styles ? scope ? styles[scope] : styles : void 0;
774
978
  }, [resource, scope]);
775
979
  }
776
- var __defProp2 = Object.defineProperty;
777
- var __defProps2 = Object.defineProperties;
778
- var __getOwnPropDescs2 = Object.getOwnPropertyDescriptors;
779
- var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
780
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
781
- var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
782
- var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
783
- var __spreadValues2 = (a, b) => {
980
+ var __defProp$1 = Object.defineProperty;
981
+ var __defProps$1 = Object.defineProperties;
982
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
983
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
984
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
985
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
986
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
987
+ var __spreadValues$1 = (a, b) => {
784
988
  for (var prop in b || (b = {}))
785
- if (__hasOwnProp2.call(b, prop))
786
- __defNormalProp2(a, prop, b[prop]);
787
- if (__getOwnPropSymbols2)
788
- for (var prop of __getOwnPropSymbols2(b)) {
789
- if (__propIsEnum2.call(b, prop))
790
- __defNormalProp2(a, prop, b[prop]);
989
+ if (__hasOwnProp$1.call(b, prop))
990
+ __defNormalProp$1(a, prop, b[prop]);
991
+ if (__getOwnPropSymbols$1)
992
+ for (var prop of __getOwnPropSymbols$1(b)) {
993
+ if (__propIsEnum$1.call(b, prop))
994
+ __defNormalProp$1(a, prop, b[prop]);
791
995
  }
792
996
  return a;
793
997
  };
794
- var __spreadProps2 = (a, b) => __defProps2(a, __getOwnPropDescs2(b));
998
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
795
999
  const BOX_SELECTOR = /&?(xywh=)?(pixel:|percent:|pct:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/;
796
1000
  const TEMPORAL_SELECTOR = /&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;
797
1001
  function parseSelector(source) {
@@ -936,7 +1140,7 @@ function expandTarget(target, options = {}) {
936
1140
  if (!fragment) {
937
1141
  return {
938
1142
  type: "SpecificResource",
939
- source: __spreadProps2(__spreadValues2({}, target), {
1143
+ source: __spreadProps$1(__spreadValues$1({}, target), {
940
1144
  id
941
1145
  }),
942
1146
  selector: null,
@@ -945,7 +1149,7 @@ function expandTarget(target, options = {}) {
945
1149
  }
946
1150
  return expandTarget({
947
1151
  type: "SpecificResource",
948
- source: __spreadProps2(__spreadValues2({}, target), {
1152
+ source: __spreadProps$1(__spreadValues$1({}, target), {
949
1153
  id
950
1154
  }),
951
1155
  selector: {
@@ -1054,20 +1258,21 @@ function RenderImage({
1054
1258
  isStatic,
1055
1259
  x = 0,
1056
1260
  y = 0,
1057
- annotations,
1058
- children
1261
+ children,
1262
+ onClick
1059
1263
  }) {
1060
1264
  var _a, _b, _c, _d;
1061
1265
  return /* @__PURE__ */ jsx(Fragment, {
1062
1266
  children: !image.service ? /* @__PURE__ */ jsxs(Fragment, {
1063
1267
  children: [/* @__PURE__ */ jsx("world-image", {
1268
+ onClick,
1064
1269
  uri: image.id,
1065
1270
  target: image.target.spatial,
1066
1271
  display: image.width && image.height ? {
1067
1272
  width: image.width,
1068
1273
  height: image.height
1069
1274
  } : void 0
1070
- }), annotations, children]
1275
+ }), children]
1071
1276
  }, "no-service") : /* @__PURE__ */ jsxs(Fragment, {
1072
1277
  children: [/* @__PURE__ */ jsx(TileSet, {
1073
1278
  tiles: {
@@ -1080,8 +1285,9 @@ function RenderImage({
1080
1285
  x: ((_a = image.target) == null ? void 0 : _a.spatial.x) + x,
1081
1286
  y: ((_b = image.target) == null ? void 0 : _b.spatial.y) + y,
1082
1287
  width: (_c = image.target) == null ? void 0 : _c.spatial.width,
1083
- height: (_d = image.target) == null ? void 0 : _d.spatial.height
1084
- }), annotations, children]
1288
+ height: (_d = image.target) == null ? void 0 : _d.spatial.height,
1289
+ onClick
1290
+ }), children]
1085
1291
  }, "service")
1086
1292
  }, id);
1087
1293
  }
@@ -1122,6 +1328,7 @@ function getPaintables(vault, paintingAnnotations, enabledChoices) {
1122
1328
  types.push(type);
1123
1329
  }
1124
1330
  items.push({
1331
+ annotationId: annotation.id,
1125
1332
  type,
1126
1333
  resource: body,
1127
1334
  target: annotation.target,
@@ -1135,6 +1342,29 @@ function getPaintables(vault, paintingAnnotations, enabledChoices) {
1135
1342
  choice
1136
1343
  };
1137
1344
  }
1345
+ function getParsedTargetSelector(canvas, target) {
1346
+ const { selector: imageTarget, source } = expandTarget$1(target);
1347
+ if (source.id !== canvas.id) {
1348
+ return [null, source];
1349
+ }
1350
+ const defaultTarget = {
1351
+ type: "BoxSelector",
1352
+ spatial: {
1353
+ x: 0,
1354
+ y: 0,
1355
+ width: canvas.width,
1356
+ height: canvas.height
1357
+ }
1358
+ };
1359
+ return [
1360
+ imageTarget ? imageTarget.type === "TemporalSelector" ? {
1361
+ type: "TemporalBoxSelector",
1362
+ temporal: imageTarget.temporal,
1363
+ spatial: defaultTarget.spatial
1364
+ } : imageTarget : null,
1365
+ source
1366
+ ];
1367
+ }
1138
1368
  const emptyActions = {
1139
1369
  makeChoice: () => {
1140
1370
  }
@@ -1143,22 +1373,9 @@ const unknownResponse = { type: "unknown" };
1143
1373
  const unsupportedStrategy = (reason) => {
1144
1374
  return { type: "unknown", reason, annotations: { pages: [] } };
1145
1375
  };
1146
- function useManifest(options = {}, deps = []) {
1147
- const { id, selector } = options;
1148
- const ctx = useResourceContext();
1149
- useVault();
1150
- const manifestId = id ? id : ctx.manifest;
1151
- const manifest = useVaultSelector((s) => manifestId ? s.iiif.entities.Manifest[manifestId] : void 0, [manifestId]);
1152
- return useMemo(() => {
1153
- if (!manifest) {
1154
- return void 0;
1155
- }
1156
- if (selector) {
1157
- return selector(manifest);
1158
- }
1159
- return manifest;
1160
- }, [manifest, selector, ...deps]);
1161
- }
1376
+ const emptyStrategy = (width, height) => {
1377
+ return { type: "empty", width, height, annotations: { pages: [] }, image: null, images: [] };
1378
+ };
1162
1379
  function getMeta$1(state, resourceId) {
1163
1380
  var _a;
1164
1381
  const resourceMeta = (_a = state == null ? void 0 : state.iiif) == null ? void 0 : _a.meta[resourceId];
@@ -1412,10 +1629,6 @@ function getImageStrategy(canvas, paintables, loadImageService) {
1412
1629
  imageService = loadImageService(imageServices[0], canvas);
1413
1630
  }
1414
1631
  }
1415
- const { selector: imageTarget, source } = expandTarget(singleImage.target);
1416
- if (source.id !== canvas.id) {
1417
- continue;
1418
- }
1419
1632
  const defaultTarget = {
1420
1633
  type: "BoxSelector",
1421
1634
  spatial: {
@@ -1425,11 +1638,10 @@ function getImageStrategy(canvas, paintables, loadImageService) {
1425
1638
  height: canvas.height
1426
1639
  }
1427
1640
  };
1428
- const target = imageTarget ? imageTarget.type === "TemporalSelector" ? {
1429
- type: "TemporalBoxSelector",
1430
- temporal: imageTarget.temporal,
1431
- spatial: defaultTarget.spatial
1432
- } : imageTarget : null;
1641
+ const [target, source] = getParsedTargetSelector(canvas, singleImage.target);
1642
+ if (source.id !== canvas.id) {
1643
+ continue;
1644
+ }
1433
1645
  const defaultImageSelector = {
1434
1646
  type: "BoxSelector",
1435
1647
  spatial: {
@@ -1455,6 +1667,7 @@ function getImageStrategy(canvas, paintables, loadImageService) {
1455
1667
  const imageType = {
1456
1668
  id: resource.id,
1457
1669
  type: "Image",
1670
+ annotationId: singleImage.annotationId,
1458
1671
  width: target ? resource.width : canvas.width,
1459
1672
  height: target ? resource.height : canvas.height,
1460
1673
  service: imageService,
@@ -1504,6 +1717,7 @@ function getAudioStrategy(canvas, paintables) {
1504
1717
  return {
1505
1718
  type: "media",
1506
1719
  media: {
1720
+ annotationId: paintables.items[0].annotationId,
1507
1721
  duration: canvas.duration,
1508
1722
  url: audioResource.id,
1509
1723
  type: "Sound",
@@ -1547,6 +1761,7 @@ function getVideoStrategy(canvas, paintables) {
1547
1761
  return {
1548
1762
  type: "media",
1549
1763
  media: {
1764
+ annotationId: paintables.items[0].annotationId,
1550
1765
  duration: canvas.duration,
1551
1766
  url: audioResource.id,
1552
1767
  type: "Video",
@@ -1572,6 +1787,38 @@ function getVideoStrategy(canvas, paintables) {
1572
1787
  }
1573
1788
  };
1574
1789
  }
1790
+ function parseType(item, languageMap = {}, lang) {
1791
+ const language = item.language || lang || "none";
1792
+ switch (item.type) {
1793
+ case "TextualBody": {
1794
+ if (typeof item.value !== "undefined") {
1795
+ languageMap[language] = item.value;
1796
+ }
1797
+ break;
1798
+ }
1799
+ case "List":
1800
+ case "Composite":
1801
+ case "Choice": {
1802
+ if (item.items) {
1803
+ item.items.forEach((inner) => parseType(inner, languageMap, language));
1804
+ }
1805
+ }
1806
+ }
1807
+ return languageMap;
1808
+ }
1809
+ function getTextualContentStrategy(canvas, paintables) {
1810
+ const items = [];
1811
+ paintables.items.forEach((item) => {
1812
+ if (item.resource) {
1813
+ const [target] = getParsedTargetSelector(canvas, item.target);
1814
+ items.push({ annotationId: item.annotationId, text: parseType(item.resource), target });
1815
+ }
1816
+ });
1817
+ return {
1818
+ type: "textual-content",
1819
+ items
1820
+ };
1821
+ }
1575
1822
  function useRenderingStrategy(options) {
1576
1823
  const manifest = useManifest();
1577
1824
  const canvas = useCanvas();
@@ -1581,10 +1828,22 @@ function useRenderingStrategy(options) {
1581
1828
  all: false
1582
1829
  });
1583
1830
  const enabledPages = useResources(enabledPageIds, "AnnotationPage");
1584
- const supports = (options == null ? void 0 : options.strategies) || ["images", "media", "complex-timeline"];
1831
+ const supports = (options == null ? void 0 : options.strategies) || [
1832
+ "empty",
1833
+ "images",
1834
+ "media",
1835
+ "textual-content",
1836
+ "complex-timeline"
1837
+ ];
1585
1838
  const [paintables, actions] = usePaintables(options, [imageServiceStatus]);
1586
1839
  const strategy = useMemo(() => {
1587
- if (!canvas || paintables.types.length === 0) {
1840
+ if (!canvas) {
1841
+ return unknownResponse;
1842
+ }
1843
+ if (paintables.types.length === 0) {
1844
+ if (supports.indexOf("empty") !== -1) {
1845
+ return emptyStrategy(canvas.width, canvas.height);
1846
+ }
1588
1847
  return unknownResponse;
1589
1848
  }
1590
1849
  if (paintables.types.length !== 1) {
@@ -1610,6 +1869,12 @@ function useRenderingStrategy(options) {
1610
1869
  }
1611
1870
  return get3dStrategy(canvas, paintables);
1612
1871
  }
1872
+ if (mainType === "textualbody") {
1873
+ if (supports.indexOf("textual-content") === -1) {
1874
+ return unsupportedStrategy("Textual content not supported");
1875
+ }
1876
+ return getTextualContentStrategy(canvas, paintables);
1877
+ }
1613
1878
  if (mainType === "sound" || mainType === "audio") {
1614
1879
  if (supports.indexOf("media") === -1) {
1615
1880
  return unsupportedStrategy("Media not supported");
@@ -1729,6 +1994,7 @@ function useThumbnail(request, dereference, { canvasId, manifestId } = {}) {
1729
1994
  const subject = canvas ? canvas : manifest;
1730
1995
  const didUnmount = useRef(false);
1731
1996
  useEffect(() => {
1997
+ didUnmount.current = false;
1732
1998
  return () => {
1733
1999
  didUnmount.current = true;
1734
2000
  };
@@ -2049,6 +2315,533 @@ function Model({
2049
2315
  })]
2050
2316
  });
2051
2317
  }
2318
+ function CanvasBackground({
2319
+ style
2320
+ }) {
2321
+ const canvas = useCanvas();
2322
+ if (!canvas || !canvas.height || !canvas.width) {
2323
+ return null;
2324
+ }
2325
+ return /* @__PURE__ */ jsx("box", {
2326
+ interactive: false,
2327
+ target: {
2328
+ x: 0,
2329
+ y: 0,
2330
+ width: canvas.width,
2331
+ height: canvas.height
2332
+ },
2333
+ style
2334
+ });
2335
+ }
2336
+ var __defProp2 = Object.defineProperty;
2337
+ var __defProps2 = Object.defineProperties;
2338
+ var __getOwnPropDescs2 = Object.getOwnPropertyDescriptors;
2339
+ var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
2340
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
2341
+ var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
2342
+ var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, {
2343
+ enumerable: true,
2344
+ configurable: true,
2345
+ writable: true,
2346
+ value
2347
+ }) : obj[key] = value;
2348
+ var __spreadValues2 = (a, b) => {
2349
+ for (var prop in b || (b = {}))
2350
+ if (__hasOwnProp2.call(b, prop))
2351
+ __defNormalProp2(a, prop, b[prop]);
2352
+ if (__getOwnPropSymbols2)
2353
+ for (var prop of __getOwnPropSymbols2(b)) {
2354
+ if (__propIsEnum2.call(b, prop))
2355
+ __defNormalProp2(a, prop, b[prop]);
2356
+ }
2357
+ return a;
2358
+ };
2359
+ var __spreadProps2 = (a, b) => __defProps2(a, __getOwnPropDescs2(b));
2360
+ var __objRest2 = (source, exclude) => {
2361
+ var target = {};
2362
+ for (var prop in source)
2363
+ if (__hasOwnProp2.call(source, prop) && exclude.indexOf(prop) < 0)
2364
+ target[prop] = source[prop];
2365
+ if (source != null && __getOwnPropSymbols2)
2366
+ for (var prop of __getOwnPropSymbols2(source)) {
2367
+ if (exclude.indexOf(prop) < 0 && __propIsEnum2.call(source, prop))
2368
+ target[prop] = source[prop];
2369
+ }
2370
+ return target;
2371
+ };
2372
+ function _defineProperty(obj, key, value) {
2373
+ if (key in obj) {
2374
+ Object.defineProperty(obj, key, {
2375
+ value,
2376
+ enumerable: true,
2377
+ configurable: true,
2378
+ writable: true
2379
+ });
2380
+ } else {
2381
+ obj[key] = value;
2382
+ }
2383
+ return obj;
2384
+ }
2385
+ function _classCallCheck(instance, Constructor) {
2386
+ if (!(instance instanceof Constructor)) {
2387
+ throw new TypeError("Cannot call a class as a function");
2388
+ }
2389
+ }
2390
+ function _defineProperties(target, props) {
2391
+ for (var i = 0; i < props.length; i++) {
2392
+ var descriptor = props[i];
2393
+ descriptor.enumerable = descriptor.enumerable || false;
2394
+ descriptor.configurable = true;
2395
+ if ("value" in descriptor)
2396
+ descriptor.writable = true;
2397
+ Object.defineProperty(target, descriptor.key, descriptor);
2398
+ }
2399
+ }
2400
+ function _createClass(Constructor, protoProps, staticProps) {
2401
+ if (protoProps)
2402
+ _defineProperties(Constructor.prototype, protoProps);
2403
+ if (staticProps)
2404
+ _defineProperties(Constructor, staticProps);
2405
+ Object.defineProperty(Constructor, "prototype", {
2406
+ writable: false
2407
+ });
2408
+ return Constructor;
2409
+ }
2410
+ var defaultOptions = {
2411
+ bindI18n: "languageChanged",
2412
+ bindI18nStore: "",
2413
+ transEmptyNodeValue: "",
2414
+ transSupportBasicHtmlNodes: true,
2415
+ transWrapTextNodes: "",
2416
+ transKeepBasicHtmlNodesFor: ["br", "strong", "i", "p"],
2417
+ useSuspense: true
2418
+ };
2419
+ var i18nInstance;
2420
+ var I18nContext = React__default.createContext();
2421
+ function getDefaults() {
2422
+ return defaultOptions;
2423
+ }
2424
+ var ReportNamespaces = function() {
2425
+ function ReportNamespaces2() {
2426
+ _classCallCheck(this, ReportNamespaces2);
2427
+ this.usedNamespaces = {};
2428
+ }
2429
+ _createClass(ReportNamespaces2, [{
2430
+ key: "addUsedNamespaces",
2431
+ value: function addUsedNamespaces(namespaces) {
2432
+ var _this = this;
2433
+ namespaces.forEach(function(ns) {
2434
+ if (!_this.usedNamespaces[ns])
2435
+ _this.usedNamespaces[ns] = true;
2436
+ });
2437
+ }
2438
+ }, {
2439
+ key: "getUsedNamespaces",
2440
+ value: function getUsedNamespaces() {
2441
+ return Object.keys(this.usedNamespaces);
2442
+ }
2443
+ }]);
2444
+ return ReportNamespaces2;
2445
+ }();
2446
+ function getI18n() {
2447
+ return i18nInstance;
2448
+ }
2449
+ function warn() {
2450
+ if (console && console.warn) {
2451
+ var _console;
2452
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2453
+ args[_key] = arguments[_key];
2454
+ }
2455
+ if (typeof args[0] === "string")
2456
+ args[0] = "react-i18next:: ".concat(args[0]);
2457
+ (_console = console).warn.apply(_console, args);
2458
+ }
2459
+ }
2460
+ var alreadyWarned = {};
2461
+ function warnOnce() {
2462
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
2463
+ args[_key2] = arguments[_key2];
2464
+ }
2465
+ if (typeof args[0] === "string" && alreadyWarned[args[0]])
2466
+ return;
2467
+ if (typeof args[0] === "string")
2468
+ alreadyWarned[args[0]] = new Date();
2469
+ warn.apply(void 0, args);
2470
+ }
2471
+ function loadNamespaces(i18n, ns, cb) {
2472
+ i18n.loadNamespaces(ns, function() {
2473
+ if (i18n.isInitialized) {
2474
+ cb();
2475
+ } else {
2476
+ var initialized = function initialized2() {
2477
+ setTimeout(function() {
2478
+ i18n.off("initialized", initialized2);
2479
+ }, 0);
2480
+ cb();
2481
+ };
2482
+ i18n.on("initialized", initialized);
2483
+ }
2484
+ });
2485
+ }
2486
+ function hasLoadedNamespace(ns, i18n) {
2487
+ var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
2488
+ if (!i18n.languages || !i18n.languages.length) {
2489
+ warnOnce("i18n.languages were undefined or empty", i18n.languages);
2490
+ return true;
2491
+ }
2492
+ var lng = i18n.languages[0];
2493
+ var fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
2494
+ var lastLng = i18n.languages[i18n.languages.length - 1];
2495
+ if (lng.toLowerCase() === "cimode")
2496
+ return true;
2497
+ var loadNotPending = function loadNotPending2(l, n) {
2498
+ var loadState = i18n.services.backendConnector.state["".concat(l, "|").concat(n)];
2499
+ return loadState === -1 || loadState === 2;
2500
+ };
2501
+ if (options.bindI18n && options.bindI18n.indexOf("languageChanging") > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns))
2502
+ return false;
2503
+ if (i18n.hasResourceBundle(lng, ns))
2504
+ return true;
2505
+ if (!i18n.services.backendConnector.backend)
2506
+ return true;
2507
+ if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns)))
2508
+ return true;
2509
+ return false;
2510
+ }
2511
+ function _arrayWithHoles(arr) {
2512
+ if (Array.isArray(arr))
2513
+ return arr;
2514
+ }
2515
+ function _iterableToArrayLimit(arr, i) {
2516
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
2517
+ if (_i == null)
2518
+ return;
2519
+ var _arr = [];
2520
+ var _n = true;
2521
+ var _d = false;
2522
+ var _s, _e;
2523
+ try {
2524
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
2525
+ _arr.push(_s.value);
2526
+ if (i && _arr.length === i)
2527
+ break;
2528
+ }
2529
+ } catch (err) {
2530
+ _d = true;
2531
+ _e = err;
2532
+ } finally {
2533
+ try {
2534
+ if (!_n && _i["return"] != null)
2535
+ _i["return"]();
2536
+ } finally {
2537
+ if (_d)
2538
+ throw _e;
2539
+ }
2540
+ }
2541
+ return _arr;
2542
+ }
2543
+ function _arrayLikeToArray(arr, len) {
2544
+ if (len == null || len > arr.length)
2545
+ len = arr.length;
2546
+ for (var i = 0, arr2 = new Array(len); i < len; i++) {
2547
+ arr2[i] = arr[i];
2548
+ }
2549
+ return arr2;
2550
+ }
2551
+ function _unsupportedIterableToArray(o, minLen) {
2552
+ if (!o)
2553
+ return;
2554
+ if (typeof o === "string")
2555
+ return _arrayLikeToArray(o, minLen);
2556
+ var n = Object.prototype.toString.call(o).slice(8, -1);
2557
+ if (n === "Object" && o.constructor)
2558
+ n = o.constructor.name;
2559
+ if (n === "Map" || n === "Set")
2560
+ return Array.from(o);
2561
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
2562
+ return _arrayLikeToArray(o, minLen);
2563
+ }
2564
+ function _nonIterableRest() {
2565
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
2566
+ }
2567
+ function _slicedToArray(arr, i) {
2568
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
2569
+ }
2570
+ function ownKeys(object, enumerableOnly) {
2571
+ var keys = Object.keys(object);
2572
+ if (Object.getOwnPropertySymbols) {
2573
+ var symbols = Object.getOwnPropertySymbols(object);
2574
+ if (enumerableOnly) {
2575
+ symbols = symbols.filter(function(sym) {
2576
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
2577
+ });
2578
+ }
2579
+ keys.push.apply(keys, symbols);
2580
+ }
2581
+ return keys;
2582
+ }
2583
+ function _objectSpread(target) {
2584
+ for (var i = 1; i < arguments.length; i++) {
2585
+ var source = arguments[i] != null ? arguments[i] : {};
2586
+ if (i % 2) {
2587
+ ownKeys(Object(source), true).forEach(function(key) {
2588
+ _defineProperty(target, key, source[key]);
2589
+ });
2590
+ } else if (Object.getOwnPropertyDescriptors) {
2591
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
2592
+ } else {
2593
+ ownKeys(Object(source)).forEach(function(key) {
2594
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
2595
+ });
2596
+ }
2597
+ }
2598
+ return target;
2599
+ }
2600
+ function useTranslation(ns) {
2601
+ var props = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
2602
+ var i18nFromProps = props.i18n;
2603
+ var _ref = useContext(I18nContext) || {}, i18nFromContext = _ref.i18n, defaultNSFromContext = _ref.defaultNS;
2604
+ var i18n = i18nFromProps || i18nFromContext || getI18n();
2605
+ if (i18n && !i18n.reportNamespaces)
2606
+ i18n.reportNamespaces = new ReportNamespaces();
2607
+ if (!i18n) {
2608
+ warnOnce("You will need to pass in an i18next instance by using initReactI18next");
2609
+ var notReadyT = function notReadyT2(k) {
2610
+ return Array.isArray(k) ? k[k.length - 1] : k;
2611
+ };
2612
+ var retNotReady = [notReadyT, {}, false];
2613
+ retNotReady.t = notReadyT;
2614
+ retNotReady.i18n = {};
2615
+ retNotReady.ready = false;
2616
+ return retNotReady;
2617
+ }
2618
+ if (i18n.options.react && i18n.options.react.wait !== void 0)
2619
+ warnOnce("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");
2620
+ var i18nOptions = _objectSpread(_objectSpread(_objectSpread({}, getDefaults()), i18n.options.react), props);
2621
+ var useSuspense = i18nOptions.useSuspense, keyPrefix = i18nOptions.keyPrefix;
2622
+ var namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
2623
+ namespaces = typeof namespaces === "string" ? [namespaces] : namespaces || ["translation"];
2624
+ if (i18n.reportNamespaces.addUsedNamespaces)
2625
+ i18n.reportNamespaces.addUsedNamespaces(namespaces);
2626
+ var ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(function(n) {
2627
+ return hasLoadedNamespace(n, i18n, i18nOptions);
2628
+ });
2629
+ function getT() {
2630
+ return i18n.getFixedT(null, i18nOptions.nsMode === "fallback" ? namespaces : namespaces[0], keyPrefix);
2631
+ }
2632
+ var _useState = useState(getT), _useState2 = _slicedToArray(_useState, 2), t = _useState2[0], setT = _useState2[1];
2633
+ var isMounted = useRef(true);
2634
+ useEffect(function() {
2635
+ var bindI18n = i18nOptions.bindI18n, bindI18nStore = i18nOptions.bindI18nStore;
2636
+ isMounted.current = true;
2637
+ if (!ready && !useSuspense) {
2638
+ loadNamespaces(i18n, namespaces, function() {
2639
+ if (isMounted.current)
2640
+ setT(getT);
2641
+ });
2642
+ }
2643
+ function boundReset() {
2644
+ if (isMounted.current)
2645
+ setT(getT);
2646
+ }
2647
+ if (bindI18n && i18n)
2648
+ i18n.on(bindI18n, boundReset);
2649
+ if (bindI18nStore && i18n)
2650
+ i18n.store.on(bindI18nStore, boundReset);
2651
+ return function() {
2652
+ isMounted.current = false;
2653
+ if (bindI18n && i18n)
2654
+ bindI18n.split(" ").forEach(function(e) {
2655
+ return i18n.off(e, boundReset);
2656
+ });
2657
+ if (bindI18nStore && i18n)
2658
+ bindI18nStore.split(" ").forEach(function(e) {
2659
+ return i18n.store.off(e, boundReset);
2660
+ });
2661
+ };
2662
+ }, [i18n, namespaces.join()]);
2663
+ var isInitial = useRef(true);
2664
+ useEffect(function() {
2665
+ if (isMounted.current && !isInitial.current) {
2666
+ setT(getT);
2667
+ }
2668
+ isInitial.current = false;
2669
+ }, [i18n]);
2670
+ var ret = [t, i18n, ready];
2671
+ ret.t = t;
2672
+ ret.i18n = i18n;
2673
+ ret.ready = ready;
2674
+ if (ready)
2675
+ return ret;
2676
+ if (!ready && !useSuspense)
2677
+ return ret;
2678
+ throw new Promise(function(resolve) {
2679
+ loadNamespaces(i18n, namespaces, function() {
2680
+ resolve();
2681
+ });
2682
+ });
2683
+ }
2684
+ function LanguageString(_a) {
2685
+ var _b = _a, {
2686
+ as: Component,
2687
+ language,
2688
+ children
2689
+ } = _b, props = __objRest2(_b, ["as", "language", "children"]);
2690
+ const {
2691
+ i18n
2692
+ } = useTranslation();
2693
+ const viewingDirection = useMemo(() => i18n.dir ? i18n.dir(language) : "ltr", [language]);
2694
+ const isSame = useMemo(() => {
2695
+ if (!i18n.services) {
2696
+ return false;
2697
+ }
2698
+ return i18n.services.languageUtils.getLanguagePartFromCode(i18n.language) === i18n.services.languageUtils.getLanguagePartFromCode(language);
2699
+ }, [i18n.language, language]);
2700
+ if (isSame) {
2701
+ if (Component) {
2702
+ return /* @__PURE__ */ jsx(Component, __spreadProps(__spreadValues({}, __spreadValues2({}, props)), {
2703
+ children
2704
+ }));
2705
+ }
2706
+ return /* @__PURE__ */ jsx("span", __spreadProps(__spreadValues({}, __spreadValues2({}, props)), {
2707
+ children
2708
+ }));
2709
+ }
2710
+ if (Component) {
2711
+ return /* @__PURE__ */ jsx(Component, __spreadProps(__spreadValues({}, __spreadProps2(__spreadValues2({}, props), {
2712
+ lang: language,
2713
+ dir: viewingDirection
2714
+ })), {
2715
+ children
2716
+ }));
2717
+ }
2718
+ return /* @__PURE__ */ jsx("span", __spreadProps(__spreadValues({}, __spreadProps2(__spreadValues2({}, props), {
2719
+ lang: language,
2720
+ dir: viewingDirection
2721
+ })), {
2722
+ children
2723
+ }));
2724
+ }
2725
+ function getClosestLanguage(i18nLanguage, languages, i18nLanguages = [], strictFallback = false) {
2726
+ if (!i18nLanguage || !languages || languages.length === 0) {
2727
+ return void 0;
2728
+ }
2729
+ if (languages.length === 1) {
2730
+ return languages[0];
2731
+ }
2732
+ if (languages.indexOf(i18nLanguage) !== -1) {
2733
+ return i18nLanguage;
2734
+ }
2735
+ const root = i18nLanguage.indexOf("-") !== -1 ? i18nLanguage.slice(0, i18nLanguage.indexOf("-")) : null;
2736
+ if (root && languages.indexOf(root) !== -1) {
2737
+ return root;
2738
+ }
2739
+ for (const lang of i18nLanguages) {
2740
+ if (languages.indexOf(lang) !== -1) {
2741
+ return lang;
2742
+ }
2743
+ }
2744
+ if (!strictFallback) {
2745
+ const inverseRoot = languages.map((l) => l.indexOf("-") !== -1 ? l.slice(0, l.indexOf("-")) : null);
2746
+ const inverseIdx = inverseRoot.indexOf(i18nLanguage);
2747
+ if (inverseIdx !== -1) {
2748
+ return languages[inverseIdx];
2749
+ }
2750
+ for (const lang of i18nLanguages) {
2751
+ const root2 = lang.indexOf("-") !== -1 ? lang.slice(0, lang.indexOf("-")) : null;
2752
+ const inverseIdx2 = root2 ? languages.indexOf(root2) : -1;
2753
+ if (inverseIdx2 !== -1) {
2754
+ return languages[inverseIdx2];
2755
+ }
2756
+ }
2757
+ }
2758
+ if (languages.indexOf("none") !== -1) {
2759
+ return "none";
2760
+ }
2761
+ if (languages.indexOf("@none") !== -1) {
2762
+ return "@none";
2763
+ }
2764
+ return languages[0];
2765
+ }
2766
+ function buildLocaleString(inputText, i18nLanguage, options = {}) {
2767
+ const {
2768
+ strictFallback = false,
2769
+ defaultText = "",
2770
+ separator = "\n",
2771
+ fallbackLanguages = [],
2772
+ closest
2773
+ } = options;
2774
+ const languages = Object.keys(inputText || {});
2775
+ const language = closest ? i18nLanguage : getClosestLanguage(i18nLanguage, languages, fallbackLanguages, strictFallback);
2776
+ if (!inputText) {
2777
+ return defaultText;
2778
+ }
2779
+ if (typeof inputText === "string") {
2780
+ return inputText;
2781
+ }
2782
+ const candidateText = language ? inputText[language] : void 0;
2783
+ if (candidateText) {
2784
+ if (typeof candidateText === "string") {
2785
+ return candidateText;
2786
+ }
2787
+ return candidateText.join(separator);
2788
+ }
2789
+ return "";
2790
+ }
2791
+ function useClosestLanguage(getLanguages, deps = []) {
2792
+ const {
2793
+ i18n
2794
+ } = useTranslation();
2795
+ const i18nLanguages = i18n && i18n.languages ? i18n.languages : [];
2796
+ const i18nLanguage = i18n && i18n.language ? i18n.language : "en";
2797
+ return useMemo(() => {
2798
+ const languages = getLanguages();
2799
+ return getClosestLanguage(i18nLanguage, languages, i18nLanguages);
2800
+ }, [i18nLanguages, i18nLanguage, ...deps]);
2801
+ }
2802
+ function useLocaleString(inputText, defaultText) {
2803
+ const language = useClosestLanguage(() => Object.keys(inputText || {}), [inputText]);
2804
+ return [useMemo(() => {
2805
+ return buildLocaleString(inputText, language, {
2806
+ defaultText,
2807
+ closest: true
2808
+ });
2809
+ }, [language, defaultText, inputText]), language];
2810
+ }
2811
+ const LocaleString = (_c) => {
2812
+ var _d = _c, {
2813
+ as: Component,
2814
+ defaultText,
2815
+ enableDangerouslySetInnerHTML,
2816
+ children
2817
+ } = _d, props = __objRest2(_d, ["as", "defaultText", "enableDangerouslySetInnerHTML", "children"]);
2818
+ const [text, language] = useLocaleString(children, defaultText);
2819
+ if (language) {
2820
+ return /* @__PURE__ */ jsx(LanguageString, __spreadProps(__spreadValues({}, __spreadProps2(__spreadValues2({}, props), {
2821
+ as: Component,
2822
+ language,
2823
+ title: enableDangerouslySetInnerHTML ? void 0 : text,
2824
+ dangerouslySetInnerHTML: enableDangerouslySetInnerHTML ? {
2825
+ __html: text
2826
+ } : void 0
2827
+ })), {
2828
+ children: enableDangerouslySetInnerHTML ? void 0 : text
2829
+ }));
2830
+ }
2831
+ if (Component) {
2832
+ return /* @__PURE__ */ jsx(Component, __spreadProps(__spreadValues({}, __spreadValues2({}, props)), {
2833
+ children: text
2834
+ }));
2835
+ }
2836
+ return /* @__PURE__ */ jsx("span", __spreadProps(__spreadValues({}, __spreadProps2(__spreadValues2({}, props), {
2837
+ title: enableDangerouslySetInnerHTML ? void 0 : text,
2838
+ dangerouslySetInnerHTML: enableDangerouslySetInnerHTML ? {
2839
+ __html: text
2840
+ } : void 0
2841
+ })), {
2842
+ children: enableDangerouslySetInnerHTML ? void 0 : text
2843
+ }));
2844
+ };
2052
2845
  function RenderCanvas({
2053
2846
  x,
2054
2847
  y,
@@ -2059,6 +2852,9 @@ function RenderCanvas({
2059
2852
  renderViewerControls,
2060
2853
  renderMediaControls,
2061
2854
  strategies,
2855
+ backgroundStyle,
2856
+ alwaysShowBackground,
2857
+ onClickPaintingAnnotation,
2062
2858
  children
2063
2859
  }) {
2064
2860
  const canvas = useCanvas();
@@ -2145,19 +2941,35 @@ function RenderCanvas({
2145
2941
  x,
2146
2942
  y
2147
2943
  }, elementProps), {
2148
- children: [strategy.type === "images" ? /* @__PURE__ */ jsxs(Fragment$1, {
2149
- children: [strategy.images.map((image, idx) => {
2150
- return /* @__PURE__ */ jsx(RenderImage, {
2151
- isStatic,
2152
- image,
2153
- id: image.id,
2154
- thumbnail: idx === 0 ? thumbnail : void 0,
2155
- annotations
2156
- }, image.id);
2157
- }), renderViewerControls ? /* @__PURE__ */ jsx(CanvasPortal, {
2158
- overlay: true,
2159
- children: renderViewerControls(strategy)
2160
- }) : null]
2944
+ children: [strategy.type === "empty" || alwaysShowBackground ? /* @__PURE__ */ jsx(CanvasBackground, {
2945
+ style: backgroundStyle
2946
+ }) : null, strategy.type === "textual-content" ? strategy.items.map((item, n) => {
2947
+ return /* @__PURE__ */ jsxs(Fragment$1, {
2948
+ children: [/* @__PURE__ */ jsx(HTMLPortal, {
2949
+ onClick: onClickPaintingAnnotation ? (e) => {
2950
+ e.stopPropagation();
2951
+ onClickPaintingAnnotation(item.annotationId, item, e);
2952
+ } : void 0,
2953
+ target: item.target.spatial || void 0,
2954
+ children: /* @__PURE__ */ jsx(LocaleString, {
2955
+ children: item.text
2956
+ })
2957
+ }, n), annotations]
2958
+ });
2959
+ }) : null, strategy.type === "images" ? /* @__PURE__ */ jsxs(Fragment$1, {
2960
+ children: [strategy.images.map((image, idx) => /* @__PURE__ */ jsx(RenderImage, {
2961
+ isStatic,
2962
+ image,
2963
+ id: image.id,
2964
+ thumbnail: idx === 0 ? thumbnail : void 0,
2965
+ onClick: onClickPaintingAnnotation ? (e) => {
2966
+ e.stopPropagation();
2967
+ onClickPaintingAnnotation(image.annotationId, image, e);
2968
+ } : void 0
2969
+ }, image.id)), annotations]
2970
+ }) : null, (strategy.type === "images" || strategy.type === "empty" || strategy.type === "textual-content") && renderViewerControls ? /* @__PURE__ */ jsx(CanvasPortal, {
2971
+ overlay: true,
2972
+ children: renderViewerControls(strategy)
2161
2973
  }) : null, strategy.type === "3d-model" ? /* @__PURE__ */ jsx(Model, {
2162
2974
  model: strategy.model
2163
2975
  }) : null, strategy.type === "media" ? /* @__PURE__ */ jsx(Fragment$1, {
@@ -2169,7 +2981,7 @@ function RenderCanvas({
2169
2981
  children: [thumbnailFallbackImage, renderMediaControls ? renderMediaControls(strategy) : null]
2170
2982
  }) : null
2171
2983
  }) : null]
2172
- }), strategy.type), strategy.type === "media" && strategy.media.type === "Sound" && accompanyingCanvas ? /* @__PURE__ */ jsx(CanvasContext, {
2984
+ }), `${canvas.id}/${strategy.type}`), strategy.type === "media" && strategy.media.type === "Sound" && accompanyingCanvas ? /* @__PURE__ */ jsx(CanvasContext, {
2173
2985
  canvas: accompanyingCanvas.id,
2174
2986
  children: /* @__PURE__ */ jsx(RenderCanvas, {
2175
2987
  renderViewerControls
@@ -2182,7 +2994,8 @@ const CanvasPanel = {
2182
2994
  RenderCanvas,
2183
2995
  RenderAnnotationPage,
2184
2996
  RenderAnnotation,
2185
- Viewer
2997
+ Viewer,
2998
+ CanvasBackground
2186
2999
  };
2187
3000
  function AnnotationContext({
2188
3001
  annotation,
@@ -2206,23 +3019,31 @@ function CollectionContext({
2206
3019
  children
2207
3020
  });
2208
3021
  }
2209
- function RangeContext({
2210
- range,
2211
- children
2212
- }) {
2213
- return /* @__PURE__ */ jsx(ResourceProvider, {
2214
- value: {
2215
- range
2216
- },
2217
- children
2218
- });
2219
- }
2220
3022
  function useAnnotationsAtTime(time, options = {}) {
2221
3023
  const allAnnotations = usePaintingAnnotations(options);
2222
3024
  return allAnnotations;
2223
3025
  }
2224
3026
  function useCanvasClock(canvasId, autoplay = false) {
2225
3027
  }
3028
+ function useCanvasSubset(idsOrRefs) {
3029
+ const ctx = useResourceContext();
3030
+ const manifestId = ctx.manifest;
3031
+ const refs = idsOrRefs ? idsOrRefs.map((item) => typeof item === "string" ? item : item == null ? void 0 : item.id) : [];
3032
+ return useVaultSelector((s) => {
3033
+ const manifest = manifestId ? s.iiif.entities.Manifest[manifestId] : void 0;
3034
+ const items = (manifest == null ? void 0 : manifest.items) || [];
3035
+ if (typeof idsOrRefs === "undefined") {
3036
+ return items;
3037
+ }
3038
+ const newItems = [];
3039
+ for (const item of (manifest == null ? void 0 : manifest.items) || []) {
3040
+ if (refs.indexOf(item.id) !== -1) {
3041
+ newItems.push(item);
3042
+ }
3043
+ }
3044
+ return newItems;
3045
+ }, [refs.join("/")]);
3046
+ }
2226
3047
  function useCollection(options, deps = []) {
2227
3048
  const { id, selector } = options;
2228
3049
  const ctx = useResourceContext();
@@ -2348,21 +3169,6 @@ function useImageTile() {
2348
3169
  } : null
2349
3170
  };
2350
3171
  }
2351
- function useRange(options = {}, deps = []) {
2352
- const { id, selector } = options;
2353
- const ctx = useResourceContext();
2354
- const rangeId = id ? id : ctx.range;
2355
- const range = useVaultSelector((s) => rangeId ? s.iiif.entities.Range[rangeId] : void 0, [rangeId]);
2356
- return useMemo(() => {
2357
- if (!range) {
2358
- return void 0;
2359
- }
2360
- if (selector) {
2361
- return selector(range);
2362
- }
2363
- return range;
2364
- }, [range, selector, ...deps]);
2365
- }
2366
3172
  function useSearchService() {
2367
3173
  const manifest = useManifest();
2368
3174
  return manifest ? manifest.service.find((service) => service.profile === "SearchService1" || service.profile === "http://iiif.io/api/search/1/search") : void 0;
@@ -2371,5 +3177,5 @@ function useStyleHelper() {
2371
3177
  const vault = useVault();
2372
3178
  return useMemo(() => createStylesHelper(vault), [vault]);
2373
3179
  }
2374
- export { AnnotationContext, CanvasContext, CanvasPanel, CanvasPortal, CollectionContext, ContextBridge, ImageServiceLoaderContext, ManifestContext, MediaPlayerProvider, OverlayPortalContext, PortalContext, RangeContext, ReactVaultContext, ResourceProvider, ResourceReactContext, SimpleViewerProvider, SimpleViewerReactContext, VaultProvider, ViewerPresetContext, VirtualAnnotationProvider, VisibleCanvasReactContext, emptyActions, expandTarget, flattenAnnotationPageIds, formatTime, getImageStrategy, getPaintables, parseSelector, parseSpecificResource, unknownResponse, unsupportedStrategy, useAnnotation, useAnnotationPageManager, useAnnotationsAtTime, useCanvas, useCanvasClock, useCollection, useContextBridge, useDispatch, useEventListener, useExistingVault, useExternalCollection, useExternalManifest, useExternalResource, useImageService, useImageServiceLoader, useImageTile, useLoadImageService, useManifest, useMediaActions, useMediaElements, useMediaState, usePaintables, usePaintingAnnotations, useRange, useRenderingStrategy, useResourceContext, useResourceEvents, useResources, useSearchService, useSimpleMediaPlayer, useSimpleViewer, useStyleHelper, useStyles, useThumbnail, useVault, useVaultEffect, useVaultSelector, useViewerPreset, useVirtualAnnotationPage, useVirtualAnnotationPageContext, useVisibleCanvases };
3180
+ export { AnnotationContext, CanvasContext, CanvasPanel, CanvasPortal, CollectionContext, ContextBridge, ImageServiceLoaderContext, InnerViewerProvider, ManifestContext, MediaPlayerProvider, OverlayPortalContext, PortalContext, RangeContext, ReactVaultContext, ResourceProvider, ResourceReactContext, SimpleViewerProvider, SimpleViewerReactContext, VaultProvider, ViewerPresetContext, VirtualAnnotationProvider, VisibleCanvasReactContext, emptyActions, emptyStrategy, expandTarget, findAllCanvasesInRange, findFirstCanvasFromRange, findManifestSelectedRange, findSelectedRange, flattenAnnotationPageIds, formatTime, getImageStrategy, getManifestSequence, getPaintables, getParsedTargetSelector, getVisibleCanvasesFromCanvasId, parseSelector, parseSpecificResource, unknownResponse, unsupportedStrategy, useAnnotation, useAnnotationPageManager, useAnnotationsAtTime, useCanvas, useCanvasClock, useCanvasSequence, useCanvasSubset, useCollection, useContextBridge, useDispatch, useEventListener, useExistingVault, useExternalCollection, useExternalManifest, useExternalResource, useImageService, useImageServiceLoader, useImageTile, useLoadImageService, useManifest, useMediaActions, useMediaElements, useMediaState, usePaintables, usePaintingAnnotations, useRange, useRenderingStrategy, useResourceContext, useResourceEvents, useResources, useSearchService, useSimpleMediaPlayer, useSimpleViewer, useStyleHelper, useStyles, useThumbnail, useVault, useVaultEffect, useVaultSelector, useViewerPreset, useVirtualAnnotationPage, useVirtualAnnotationPageContext, useVisibleCanvases };
2375
3181
  //# sourceMappingURL=index.mjs.map