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