@knaw-huc/osd-iiif-viewer 0.2.0 → 0.2.1
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/dist/index.js
CHANGED
|
@@ -1796,7 +1796,11 @@ const defaultState$1 = {
|
|
|
1796
1796
|
setIsFullPage: (isFullPage) => set({ isFullPage }),
|
|
1797
1797
|
setRotation: (rotation) => set({ rotation }),
|
|
1798
1798
|
reset: () => set(defaultState)
|
|
1799
|
-
})
|
|
1799
|
+
});
|
|
1800
|
+
function findCanvasIndex(vault, manifestUrl, canvasId) {
|
|
1801
|
+
return vault.get({ id: manifestUrl, type: "Manifest" }).items.findIndex((item) => vault.get(item).id === canvasId);
|
|
1802
|
+
}
|
|
1803
|
+
const defaultManifest = {
|
|
1800
1804
|
url: null,
|
|
1801
1805
|
isLoading: !1,
|
|
1802
1806
|
isReady: !1,
|
|
@@ -1804,10 +1808,16 @@ const defaultState$1 = {
|
|
|
1804
1808
|
}, createManifestSlice = (vault) => (set) => ({
|
|
1805
1809
|
vault,
|
|
1806
1810
|
...defaultManifest,
|
|
1807
|
-
loadManifest: async (url) => {
|
|
1811
|
+
loadManifest: async (url, initialCanvasId) => {
|
|
1808
1812
|
set({ url, isLoading: !0, error: null });
|
|
1809
1813
|
try {
|
|
1810
|
-
await vault.loadManifest(url)
|
|
1814
|
+
await vault.loadManifest(url);
|
|
1815
|
+
const updates = { isLoading: !1, error: null };
|
|
1816
|
+
if (initialCanvasId) {
|
|
1817
|
+
const index = findCanvasIndex(vault, url, initialCanvasId);
|
|
1818
|
+
index !== -1 && (updates.currentIndex = index);
|
|
1819
|
+
}
|
|
1820
|
+
set(updates);
|
|
1811
1821
|
} catch (e2) {
|
|
1812
1822
|
const error = e2 instanceof Error ? e2.message : "Unknown error";
|
|
1813
1823
|
set({ isLoading: !1, error });
|
|
@@ -1825,6 +1835,17 @@ const defaultState$1 = {
|
|
|
1825
1835
|
const manifest = vault.get({ id: url, type: "Manifest" }), clamped = Math.max(0, Math.min(index, manifest.items.length - 1));
|
|
1826
1836
|
set({ currentIndex: clamped });
|
|
1827
1837
|
},
|
|
1838
|
+
goToCanvasById: (id) => {
|
|
1839
|
+
const { vault, url, goToCanvas } = get();
|
|
1840
|
+
if (!url)
|
|
1841
|
+
return;
|
|
1842
|
+
const index = findCanvasIndex(vault, url, id);
|
|
1843
|
+
if (index === -1) {
|
|
1844
|
+
console.warn(`Canvas not found: ${id}`);
|
|
1845
|
+
return;
|
|
1846
|
+
}
|
|
1847
|
+
goToCanvas(index);
|
|
1848
|
+
},
|
|
1828
1849
|
nextCanvas: () => {
|
|
1829
1850
|
const { currentIndex, goToCanvas } = get();
|
|
1830
1851
|
goToCanvas(currentIndex + 1);
|
|
@@ -1926,7 +1947,14 @@ function getImageServiceId(vault, canvas) {
|
|
|
1926
1947
|
if (!isExternalWebResource(resource))
|
|
1927
1948
|
return null;
|
|
1928
1949
|
const services = de(resource);
|
|
1929
|
-
return services.length ? H(services[0]) ?? null :
|
|
1950
|
+
return services.length ? H(services[0]) ?? null : getImageServiceIdWithoutProfileCheck(resource);
|
|
1951
|
+
}
|
|
1952
|
+
function getImageServiceIdWithoutProfileCheck(resource) {
|
|
1953
|
+
const service = resource.service;
|
|
1954
|
+
if (!Array.isArray(service) || !service.length)
|
|
1955
|
+
return null;
|
|
1956
|
+
const first = service[0];
|
|
1957
|
+
return typeof first == "object" && first && "id" in first ? first.id : null;
|
|
1930
1958
|
}
|
|
1931
1959
|
function isExternalWebResource(resource) {
|
|
1932
1960
|
return resource.type !== "SpecificResource";
|
|
@@ -1940,13 +1968,22 @@ function useViewerStoreSelector(selector) {
|
|
|
1940
1968
|
return useStore(store, selector);
|
|
1941
1969
|
}
|
|
1942
1970
|
function useCanvas() {
|
|
1943
|
-
const vault = useViewerStoreSelector((s2) => s2.vault), url = useViewerStoreSelector((s2) => s2.url), isLoading = useViewerStoreSelector((s2) => s2.isLoading), currentIndex = useViewerStoreSelector((s2) => s2.currentIndex), goTo = useViewerStoreSelector((s2) => s2.goToCanvas), next = useViewerStoreSelector((s2) => s2.nextCanvas), prev = useViewerStoreSelector((s2) => s2.prevCanvas), { current, total } = useMemo(() => {
|
|
1971
|
+
const vault = useViewerStoreSelector((s2) => s2.vault), url = useViewerStoreSelector((s2) => s2.url), isLoading = useViewerStoreSelector((s2) => s2.isLoading), currentIndex = useViewerStoreSelector((s2) => s2.currentIndex), goTo = useViewerStoreSelector((s2) => s2.goToCanvas), goToById = useViewerStoreSelector((s2) => s2.goToCanvasById), next = useViewerStoreSelector((s2) => s2.nextCanvas), prev = useViewerStoreSelector((s2) => s2.prevCanvas), { current, total } = useMemo(() => {
|
|
1944
1972
|
if (!url || isLoading)
|
|
1945
1973
|
return { current: null, total: 0 };
|
|
1946
1974
|
const manifest = vault.get({ id: url, type: "Manifest" }), canvasRef = manifest.items[currentIndex] ?? orThrow("No canvas ref for " + currentIndex), current2 = vault.get(canvasRef), total2 = manifest.items.length;
|
|
1947
1975
|
return { current: current2, total: total2 };
|
|
1948
|
-
}, [vault, url, isLoading, currentIndex]);
|
|
1949
|
-
return {
|
|
1976
|
+
}, [vault, url, isLoading, currentIndex]), currentCanvasId = current?.id ?? null;
|
|
1977
|
+
return {
|
|
1978
|
+
currentIndex,
|
|
1979
|
+
currentCanvasId,
|
|
1980
|
+
current,
|
|
1981
|
+
total,
|
|
1982
|
+
goTo,
|
|
1983
|
+
goToById,
|
|
1984
|
+
next,
|
|
1985
|
+
prev
|
|
1986
|
+
};
|
|
1950
1987
|
}
|
|
1951
1988
|
function useManifest() {
|
|
1952
1989
|
const vault = useViewerStoreSelector((s2) => s2.vault), url = useViewerStoreSelector((s2) => s2.url), isLoading = useViewerStoreSelector((s2) => s2.isLoading), error = useViewerStoreSelector((s2) => s2.error), loadManifest = useViewerStoreSelector((s2) => s2.loadManifest);
|
|
@@ -10,6 +10,6 @@ export type ManifestState = {
|
|
|
10
10
|
};
|
|
11
11
|
export type ManifestSlice = Resettable & ManifestState & {
|
|
12
12
|
vault: Vault;
|
|
13
|
-
loadManifest: (url: string) => Promise<void>;
|
|
13
|
+
loadManifest: (url: string, initialCanvasId?: string) => Promise<void>;
|
|
14
14
|
};
|
|
15
15
|
export declare const createManifestSlice: (vault: Vault) => StateCreator<ViewerStore, [], [], ManifestSlice>;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { CanvasNormalized } from '@iiif/presentation-3-normalized';
|
|
2
2
|
export declare function useCanvas(): {
|
|
3
3
|
currentIndex: number;
|
|
4
|
+
currentCanvasId: string | null;
|
|
4
5
|
current: CanvasNormalized | null;
|
|
5
6
|
total: number;
|
|
6
7
|
goTo: (index: number) => void;
|
|
8
|
+
goToById: (id: string) => void;
|
|
7
9
|
next: () => void;
|
|
8
10
|
prev: () => void;
|
|
9
11
|
};
|
|
@@ -4,6 +4,6 @@ export declare function useManifest(): {
|
|
|
4
4
|
isLoading: boolean;
|
|
5
5
|
error: string | null;
|
|
6
6
|
isReady: boolean;
|
|
7
|
-
loadManifest: (url: string) => Promise<void>;
|
|
7
|
+
loadManifest: (url: string, initialCanvasId?: string) => Promise<void>;
|
|
8
8
|
};
|
|
9
|
-
export declare function useLoadManifest(): (url: string) => Promise<void>;
|
|
9
|
+
export declare function useLoadManifest(): (url: string, initialCanvasId?: string) => Promise<void>;
|