cozy-iiif 0.3.0 → 0.3.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/README.md +3 -0
- package/dist/core/canvas.d.ts +0 -1
- package/dist/core/image-service.d.ts +2 -2
- package/dist/index.js +36 -40
- package/dist/types.d.ts +4 -3
- package/package.json +1 -1
- package/src/Cozy.ts +3 -4
- package/src/core/canvas.ts +13 -16
- package/src/core/image-service.ts +2 -2
- package/src/types.ts +7 -6
package/README.md
CHANGED
@@ -135,6 +135,9 @@ console.log(image.getRegionURL(bounds));
|
|
135
135
|
// With custom minimum shorted dimension
|
136
136
|
console.log(image.getRegionURL(bounds, 800));
|
137
137
|
|
138
|
+
// Full image with custom minimum shorted dimension
|
139
|
+
console.log(image.getImageURL(800));
|
140
|
+
|
138
141
|
// Resolves the actual image pixel size from the info.json
|
139
142
|
// or the image file (which may **differ**) from the canvas size!
|
140
143
|
console.log(image.getPixelSize());
|
package/dist/core/canvas.d.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import { Canvas } from '@iiif/presentation-3';
|
2
2
|
import { CozyImageResource } from '../types';
|
3
3
|
export declare const getThumbnailURL: (canvas: Canvas, images?: CozyImageResource[]) => (minSize?: number) => string | undefined;
|
4
|
-
export declare const getImageURL: (canvas: Canvas, images?: CozyImageResource[]) => (minSize?: number) => string | undefined;
|
5
4
|
export declare const normalizeServiceUrl: (url: string) => string;
|
6
5
|
export declare const getImages: (canvas: Canvas) => CozyImageResource[];
|
@@ -6,7 +6,7 @@ export declare const parseImageService: (service: Service) => {
|
|
6
6
|
majorVersion: number;
|
7
7
|
profileLevel: number;
|
8
8
|
} | undefined;
|
9
|
-
export declare const getImageURLFromService: (service:
|
10
|
-
export declare const getRegionURLFromService: (service:
|
9
|
+
export declare const getImageURLFromService: (service: Service, width: number, height: number) => string;
|
10
|
+
export declare const getRegionURLFromService: (service: Service, bounds: Bounds, minSize: number) => string | undefined;
|
11
11
|
export declare const getRegionURL: (image: CozyImageResource) => (bounds: Bounds, minSize?: number) => string | undefined;
|
12
12
|
export {};
|
package/dist/index.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import { imageSize as ce } from "image-size";
|
2
|
-
import { g
|
2
|
+
import { g, a as j, b as S } from "./resource-DS2brz47.js";
|
3
3
|
import { c as zt } from "./resource-DS2brz47.js";
|
4
|
-
var le = "http://library.stanford.edu/iiif/image-api/compliance.html#level0", pe = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", V = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", ve = "http://library.stanford.edu/iiif/image-api/conformance.html#level0", he = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", F = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", ue = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0", fe = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", W = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",
|
5
|
-
function
|
4
|
+
var le = "http://library.stanford.edu/iiif/image-api/compliance.html#level0", pe = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", V = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", ve = "http://library.stanford.edu/iiif/image-api/conformance.html#level0", he = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", F = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", ue = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0", fe = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", W = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", ge = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0", me = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", H = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", de = "http://iiif.io/api/image/1/level0.json", ye = "http://iiif.io/api/image/1/profiles/level0.json", Ae = "http://iiif.io/api/image/1/level1.json", Ce = "http://iiif.io/api/image/1/profiles/level1.json", J = "http://iiif.io/api/image/1/level2.json", z = "http://iiif.io/api/image/1/profiles/level2.json", be = "http://iiif.io/api/image/2/level0.json", Re = "http://iiif.io/api/image/2/profiles/level0.json", Le = "http://iiif.io/api/image/2/level1.json", we = "http://iiif.io/api/image/2/profiles/level1.json", G = "http://iiif.io/api/image/2/level2.json", K = "http://iiif.io/api/image/2/profiles/level2.json", Ie = "level0", Se = "level1", Q = "level2", xe = "http://iiif.io/api/image/2/level0", Te = "http://iiif.io/api/image/2/level1", X = "http://iiif.io/api/image/2/level2", $e = [X, V, F, W, H, J, z, G, K, Q], Me = [xe, Te, X, le, pe, V, ve, he, F, ue, fe, W, ge, me, H, de, ye, Ae, Ce, J, z, be, Re, Le, we, G, K, Ie, Se, Q], je = Me;
|
5
|
+
function m(t) {
|
6
6
|
for (let e in t) (typeof t[e] > "u" || t[e] === null) && delete t[e];
|
7
7
|
return t;
|
8
8
|
}
|
@@ -337,17 +337,17 @@ function R(t) {
|
|
337
337
|
let e = t.related ? Array.isArray(t.related) ? t.related : [t.related] : [], r = t.contentLayer;
|
338
338
|
return { provider: t.logo || e.length ? [{ id: k.providerId, type: "Agent", homepage: e.length ? [e[0]] : void 0, logo: t.logo ? Array.isArray(t.logo) ? t.logo : [t.logo] : void 0, label: I(k.providerName) }] : void 0, partOf: ft(t), rendering: t.rendering, seeAlso: t.seeAlso, start: t.startCanvas, service: t.service ? w(t.service) : void 0, supplementary: r ? [r] : void 0 };
|
339
339
|
}
|
340
|
-
function
|
340
|
+
function gt(t) {
|
341
341
|
return { chars: t.chars, format: t.format ? t.format : void 0, language: t.language };
|
342
342
|
}
|
343
|
-
function
|
344
|
-
return
|
343
|
+
function mt(t) {
|
344
|
+
return m({ ...A(t), ...C(t), ...R(t), items: t.members });
|
345
345
|
}
|
346
346
|
function dt(t) {
|
347
347
|
let e = [], r = [], i;
|
348
348
|
for (let n of t.sequences || []) n.canvases.length && e.push(...n.canvases), n.behavior && r.push(...n.behavior), n.startCanvas && (i = n.startCanvas);
|
349
349
|
let s = A(t);
|
350
|
-
return r.length && (s.behavior ? s.behavior.push(...r) : s.behavior = r),
|
350
|
+
return r.length && (s.behavior ? s.behavior.push(...r) : s.behavior = r), m({ ...s, ...C(t), ...R(t), start: i, items: e, structures: yt(t.structures) });
|
351
351
|
}
|
352
352
|
function yt(t) {
|
353
353
|
if (!t) return t;
|
@@ -361,10 +361,10 @@ function yt(t) {
|
|
361
361
|
return t.filter((i) => r.indexOf(i.id) === -1);
|
362
362
|
}
|
363
363
|
function At(t) {
|
364
|
-
return
|
364
|
+
return m({ ...A(t), ...C(t), ...R(t), annotations: t.otherContent && t.otherContent.length ? t.otherContent : void 0, items: t.images && t.images.length ? [{ id: ee(t, "annotation-page"), type: "AnnotationPage", items: t.images }] : void 0 });
|
365
365
|
}
|
366
366
|
function Ct(t) {
|
367
|
-
return
|
367
|
+
return m({ ...A(t), ...C(t), ...R(t), items: t.resources && t.resources.length ? t.resources : void 0 });
|
368
368
|
}
|
369
369
|
function bt(t) {
|
370
370
|
return !t.canvases || t.canvases.length === 0 ? { canvases: [], behavior: [] } : { canvases: t.canvases, behavior: t.viewingHint ? [t.viewingHint] : [], startCanvas: t.startCanvas };
|
@@ -385,30 +385,30 @@ function Rt(t) {
|
|
385
385
|
return { type: "SpecificResource", source: i, selector: P(r.selector) };
|
386
386
|
} else return encodeURI(r["@id"]).trim();
|
387
387
|
}
|
388
|
-
return
|
388
|
+
return m({ ...A(t), ...C(t), ...R(t), target: e(t.on), body: Array.isArray(t.resource) ? t.resource.map(_) : _(t.resource) });
|
389
389
|
}
|
390
390
|
function _(t) {
|
391
391
|
return t.type === "Choice" ? t : te(t);
|
392
392
|
}
|
393
393
|
function te(t) {
|
394
394
|
let e = t;
|
395
|
-
return
|
395
|
+
return m({ ...A(e), ...C(e), ...R(e), ...gt(e) });
|
396
396
|
}
|
397
397
|
function Lt(t) {
|
398
398
|
let e = [];
|
399
|
-
return t.default && t.default !== "rdf:nil" && e.push(t.default), t.item && t.item !== "rdf:nil" && e.push(...t.item),
|
399
|
+
return t.default && t.default !== "rdf:nil" && e.push(t.default), t.item && t.item !== "rdf:nil" && e.push(...t.item), m({ ...A(t), ...C(t), items: e });
|
400
400
|
}
|
401
401
|
function wt(t) {
|
402
|
-
return
|
402
|
+
return m({ ...A(t), ...C(t), ...R(t), items: t.members });
|
403
403
|
}
|
404
404
|
function It(t) {
|
405
405
|
let { "@id": e, "@type": r, "@context": i, profile: s, ...n } = t, o = {};
|
406
|
-
return e && (o["@id"] = e), o["@type"] = U(t), o["@type"] === "unknown" && (i && i.length && (o["@context"] = i), o["@type"] = "Service"), s && (o.profile = Z(s)),
|
406
|
+
return e && (o["@id"] = e), o["@type"] = U(t), o["@type"] === "unknown" && (i && i.length && (o["@context"] = i), o["@type"] = "Service"), s && (o.profile = Z(s)), m({ ...o, ...n });
|
407
407
|
}
|
408
408
|
function St(t) {
|
409
|
-
return
|
409
|
+
return m({ ...A(t), ...C(t), ...R(t) });
|
410
410
|
}
|
411
|
-
var xt = new Ue({ collection: [
|
411
|
+
var xt = new Ue({ collection: [mt], manifest: [dt], canvas: [At], annotationList: [Ct], sequence: [bt], annotation: [Rt], contentResource: [te], choice: [Lt], range: [wt], service: [It], layer: [St] });
|
412
412
|
function re(t) {
|
413
413
|
return t && t["@context"] && (t["@context"] === "http://iiif.io/api/presentation/2/context.json" || t["@context"].indexOf("http://iiif.io/api/presentation/2/context.json") !== -1 || t["@context"] === "http://www.shared-canvas.org/ns/context.json") || t["@context"] === "http://iiif.io/api/image/2/context.json" ? xt.traverseUnknown(t) : t;
|
414
414
|
}
|
@@ -553,15 +553,15 @@ var D = class ie {
|
|
553
553
|
}
|
554
554
|
}
|
555
555
|
};
|
556
|
-
const se = (t) =>
|
557
|
-
const e =
|
556
|
+
const se = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.profile.toString().includes("iiif.io/api/image/"), ne = (t) => {
|
557
|
+
const e = g(t, "type"), r = g(t, "context");
|
558
558
|
if (e === "ImageService2" || r != null && r.includes("image/2")) {
|
559
559
|
const i = t, s = ["level0", "level1", "level2"];
|
560
560
|
return { majorVersion: 2, profileLevel: (Array.isArray(i.profile) ? i.profile : [i.profile]).map((c) => s.findIndex((a) => c.toString().includes(a))).filter((c) => c > -1).sort((c, a) => a - c)[0] };
|
561
561
|
} else if (e || r)
|
562
562
|
return { majorVersion: 3, profileLevel: parseInt(t.profile) };
|
563
563
|
}, O = (t, e, r) => {
|
564
|
-
const i =
|
564
|
+
const i = g(t, "id"), s = t.profile || "";
|
565
565
|
if (typeof s == "string" && (s.includes("level0") || s.includes("level:0"))) {
|
566
566
|
if ("sizes" in t && Array.isArray(t.sizes)) {
|
567
567
|
const o = t.sizes.sort((c, a) => a.width * a.height - c.width * c.height).filter((c) => c.width * c.height >= e * r)[0];
|
@@ -572,7 +572,7 @@ const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
572
572
|
}
|
573
573
|
return `${i}/full/!${e},${r}/0/default.jpg`;
|
574
574
|
}, $t = (t, e, r) => {
|
575
|
-
const i =
|
575
|
+
const i = g(t, "id"), s = t.profile || "";
|
576
576
|
if (typeof s == "string" && (s.includes("level0") || s.includes("level:0"))) return;
|
577
577
|
const { x: o, y: c, w: a, h: l } = e, u = a / l, v = u < 1, d = Math.ceil(v ? r / u : r), p = Math.ceil(v ? r : r / u), f = `${Math.round(o)},${Math.round(c)},${Math.round(a)},${Math.round(l)}`;
|
578
578
|
return `${i}/${f}/!${p},${d}/0/default.jpg`;
|
@@ -599,17 +599,11 @@ const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
599
599
|
if (l.type === "static")
|
600
600
|
return l.url;
|
601
601
|
}
|
602
|
-
}, kt = (t, e
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
if (l.type === "dynamic" || l.type === "level0")
|
608
|
-
return O(l.service, a, c);
|
609
|
-
if (l.type === "static")
|
610
|
-
return l.url;
|
611
|
-
}
|
612
|
-
}, ae = (t) => t.endsWith("/info.json") ? t : `${t.endsWith("/") ? t : `${t}/`}info.json`, Pt = (t) => () => fetch(t).then((e) => e.json()).then((e) => {
|
602
|
+
}, ae = (t) => t.endsWith("/info.json") ? t : `${t.endsWith("/") ? t : `${t}/`}info.json`, kt = (t, e, r) => (i = 800) => {
|
603
|
+
if (!t || !e) return;
|
604
|
+
const s = t / e, n = s < 1, o = Math.ceil(n ? i / s : i), c = Math.ceil(n ? i : i / s);
|
605
|
+
return O(r, c, o);
|
606
|
+
}, Pt = (t) => () => fetch(t).then((e) => e.json()).then((e) => {
|
613
607
|
const r = e.width, i = e.height;
|
614
608
|
return r !== void 0 && i !== void 0 ? { width: r, height: i } : void 0;
|
615
609
|
}), Ot = (t) => () => {
|
@@ -619,9 +613,9 @@ const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
619
613
|
return i.close(), { width: s, height: n };
|
620
614
|
}) : r.arrayBuffer().then((i) => ce(new Uint8Array(i))));
|
621
615
|
}, Ut = (t) => {
|
622
|
-
const { format: e, height: r, width: i } = t, s =
|
623
|
-
if (o) {
|
624
|
-
const c = ae(
|
616
|
+
const { format: e, height: r, width: i } = t, s = g(t, "id"), n = (t.service || []).find(se), o = n ? ne(n) : void 0;
|
617
|
+
if (n && o) {
|
618
|
+
const c = ae(g(n, "id")), a = {
|
625
619
|
source: t,
|
626
620
|
type: o.profileLevel === 0 ? "level0" : "dynamic",
|
627
621
|
service: n,
|
@@ -629,6 +623,7 @@ const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
629
623
|
height: r,
|
630
624
|
majorVersion: o.majorVersion,
|
631
625
|
serviceUrl: c,
|
626
|
+
getImageURL: kt(i, r, n),
|
632
627
|
getPixelSize: Pt(c)
|
633
628
|
};
|
634
629
|
return o.profileLevel === 0 ? a : {
|
@@ -643,6 +638,7 @@ const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
643
638
|
height: r,
|
644
639
|
url: s,
|
645
640
|
format: e,
|
641
|
+
getImageURL: () => s,
|
646
642
|
getPixelSize: Ot(s)
|
647
643
|
};
|
648
644
|
}, Dt = (t) => {
|
@@ -756,7 +752,7 @@ const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
756
752
|
code: "INVALID_MANIFEST",
|
757
753
|
message: "Missing @context"
|
758
754
|
};
|
759
|
-
const i =
|
755
|
+
const i = g(t, "id");
|
760
756
|
if (!i)
|
761
757
|
return {
|
762
758
|
type: "error",
|
@@ -765,7 +761,7 @@ const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
765
761
|
};
|
766
762
|
if (r.includes("presentation/2") || r.includes("presentation/3")) {
|
767
763
|
const s = r.includes("presentation/2") ? 2 : 3;
|
768
|
-
return
|
764
|
+
return g(t, "type").includes("Collection") ? {
|
769
765
|
type: "collection",
|
770
766
|
url: e || i,
|
771
767
|
resource: qt(t, s)
|
@@ -832,7 +828,8 @@ const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
832
828
|
height: p.height,
|
833
829
|
images: f,
|
834
830
|
annotations: p.annotations || [],
|
835
|
-
getImageURL:
|
831
|
+
getImageURL: f.length > 0 ? f[0].getImageURL : () => {
|
832
|
+
},
|
836
833
|
getLabel: S(p),
|
837
834
|
getMetadata: j(p),
|
838
835
|
getThumbnailURL: jt(p, f)
|
@@ -870,17 +867,16 @@ const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
870
867
|
width: e,
|
871
868
|
height: r,
|
872
869
|
majorVersion: i.majorVersion,
|
873
|
-
serviceUrl: ae(
|
870
|
+
serviceUrl: ae(g(t, "id"))
|
874
871
|
};
|
875
872
|
}, Wt = { parse: oe, parseURL: Et };
|
876
873
|
export {
|
877
874
|
Wt as Cozy,
|
878
|
-
kt as getImageURL,
|
879
875
|
O as getImageURLFromService,
|
880
876
|
Dt as getImages,
|
881
877
|
S as getLabel,
|
882
878
|
j as getMetadata,
|
883
|
-
|
879
|
+
g as getPropertyValue,
|
884
880
|
Mt as getRegionURL,
|
885
881
|
$t as getRegionURLFromService,
|
886
882
|
zt as getStringValue,
|
package/dist/types.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Manifest, Canvas,
|
1
|
+
import { Manifest, Canvas, IIIFExternalWebResource, Collection, Range, AnnotationPage, Service } from '@iiif/presentation-3';
|
2
2
|
export type CozyParseResult = {
|
3
3
|
type: 'collection';
|
4
4
|
url: string;
|
@@ -94,6 +94,7 @@ interface BaseImageResource {
|
|
94
94
|
readonly type: 'static' | 'dynamic' | 'level0';
|
95
95
|
readonly width: number;
|
96
96
|
readonly height: number;
|
97
|
+
getImageURL(minSize?: number): string;
|
97
98
|
getPixelSize(): Promise<{
|
98
99
|
width: number;
|
99
100
|
height: number;
|
@@ -105,7 +106,7 @@ export interface StaticImageResource extends BaseImageResource {
|
|
105
106
|
}
|
106
107
|
export interface DynamicImageServiceResource extends BaseImageResource {
|
107
108
|
readonly type: 'dynamic';
|
108
|
-
readonly service:
|
109
|
+
readonly service: Service;
|
109
110
|
readonly serviceUrl: string;
|
110
111
|
readonly majorVersion: number;
|
111
112
|
getRegionURL(bounds: Bounds, minSize?: number): string;
|
@@ -113,7 +114,7 @@ export interface DynamicImageServiceResource extends BaseImageResource {
|
|
113
114
|
export interface Level0ImageServiceResource extends BaseImageResource {
|
114
115
|
readonly type: 'level0';
|
115
116
|
readonly majorVersion: number;
|
116
|
-
readonly service:
|
117
|
+
readonly service: Service;
|
117
118
|
readonly serviceUrl: string;
|
118
119
|
}
|
119
120
|
export interface ImageRequestOptions {
|
package/package.json
CHANGED
package/src/Cozy.ts
CHANGED
@@ -2,8 +2,7 @@ import type { Canvas, Collection, Manifest, Range } from '@iiif/presentation-3';
|
|
2
2
|
import { convertPresentation2 } from '@iiif/parser/presentation-2';
|
3
3
|
import { Traverse } from '@iiif/parser';
|
4
4
|
import {
|
5
|
-
getImages,
|
6
|
-
getImageURL,
|
5
|
+
getImages,
|
7
6
|
getLabel,
|
8
7
|
getMetadata,
|
9
8
|
getPropertyValue,
|
@@ -15,7 +14,7 @@ import {
|
|
15
14
|
import type {
|
16
15
|
CozyCanvas,
|
17
16
|
CozyCollection,
|
18
|
-
CozyCollectionItem,
|
17
|
+
CozyCollectionItem,
|
19
18
|
CozyManifest,
|
20
19
|
CozyParseResult,
|
21
20
|
CozyRange,
|
@@ -194,7 +193,7 @@ const parseManifestResource = (resource: any, majorVersion: number): CozyManifes
|
|
194
193
|
height: c.height,
|
195
194
|
images,
|
196
195
|
annotations: (c.annotations || []),
|
197
|
-
getImageURL: getImageURL(
|
196
|
+
getImageURL: images.length > 0 ? images[0].getImageURL : () => undefined,
|
198
197
|
getLabel: getLabel(c),
|
199
198
|
getMetadata: getMetadata(c),
|
200
199
|
getThumbnailURL: getThumbnailURL(c, images)
|
package/src/core/canvas.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { imageSize } from 'image-size';
|
2
|
-
import type { Canvas, IIIFExternalWebResource } from '@iiif/presentation-3';
|
2
|
+
import type { Canvas, IIIFExternalWebResource, Service } from '@iiif/presentation-3';
|
3
3
|
import { Traverse } from '@iiif/parser';
|
4
4
|
import { getPropertyValue } from './resource';
|
5
5
|
import { getImageURLFromService, getRegionURL, isImageService, parseImageService } from './image-service';
|
@@ -43,9 +43,14 @@ export const getThumbnailURL = (canvas: Canvas, images: CozyImageResource[] = []
|
|
43
43
|
}
|
44
44
|
}
|
45
45
|
|
46
|
-
export const
|
47
|
-
|
46
|
+
export const normalizeServiceUrl = (url: string) =>
|
47
|
+
url.endsWith('/info.json') ? url : `${url.endsWith('/') ? url : `${url}/`}info.json`;
|
48
48
|
|
49
|
+
const getImageURL = (
|
50
|
+
width: number | undefined,
|
51
|
+
height: number | undefined,
|
52
|
+
service: Service
|
53
|
+
) => (minSize = 800) => {
|
49
54
|
if (!width || !height) return;
|
50
55
|
|
51
56
|
const aspect = width / height;
|
@@ -54,18 +59,9 @@ export const getImageURL = (canvas: Canvas, images: CozyImageResource[] = []) =>
|
|
54
59
|
const h = Math.ceil(isPortrait ? minSize / aspect : minSize);
|
55
60
|
const w = Math.ceil(isPortrait ? minSize : minSize / aspect);
|
56
61
|
|
57
|
-
|
58
|
-
if (image.type === 'dynamic' || image.type === 'level0') {
|
59
|
-
return getImageURLFromService(image.service, w, h);
|
60
|
-
} else if (image.type === 'static') {
|
61
|
-
return image.url;
|
62
|
-
}
|
63
|
-
}
|
62
|
+
return getImageURLFromService(service!, w, h);
|
64
63
|
}
|
65
64
|
|
66
|
-
export const normalizeServiceUrl = (url: string) =>
|
67
|
-
url.endsWith('/info.json') ? url : `${url.endsWith('/') ? url : `${url}/`}info.json`;
|
68
|
-
|
69
65
|
const getPixelSizeFromServiceUrl = (serviceUrl: string) => () =>
|
70
66
|
fetch(serviceUrl).then(res => res.json()).then(data => {
|
71
67
|
const width: number = data.width;
|
@@ -83,8 +79,7 @@ const getStaticImagePixelSize = (url: string) => () => {
|
|
83
79
|
bitmap.close();
|
84
80
|
return { width, height }
|
85
81
|
});
|
86
|
-
} else {
|
87
|
-
return blob.arrayBuffer().then(buffer =>
|
82
|
+
} else { return blob.arrayBuffer().then(buffer =>
|
88
83
|
imageSize(new Uint8Array(buffer)));
|
89
84
|
}
|
90
85
|
});
|
@@ -99,7 +94,7 @@ const toCozyImageResource = (resource: IIIFExternalWebResource) => {
|
|
99
94
|
|
100
95
|
const service = imageService ? parseImageService(imageService) : undefined;
|
101
96
|
|
102
|
-
if (service) {
|
97
|
+
if (imageService && service) {
|
103
98
|
const serviceUrl = normalizeServiceUrl(getPropertyValue<string>(imageService, 'id'));
|
104
99
|
|
105
100
|
const image = {
|
@@ -110,6 +105,7 @@ const toCozyImageResource = (resource: IIIFExternalWebResource) => {
|
|
110
105
|
height,
|
111
106
|
majorVersion: service.majorVersion,
|
112
107
|
serviceUrl,
|
108
|
+
getImageURL: getImageURL(width, height, imageService),
|
113
109
|
getPixelSize: getPixelSizeFromServiceUrl(serviceUrl)
|
114
110
|
} as ImageServiceResource;
|
115
111
|
|
@@ -129,6 +125,7 @@ const toCozyImageResource = (resource: IIIFExternalWebResource) => {
|
|
129
125
|
height,
|
130
126
|
url: id,
|
131
127
|
format,
|
128
|
+
getImageURL: () => id,
|
132
129
|
getPixelSize: getStaticImagePixelSize(id)
|
133
130
|
} as StaticImageResource;
|
134
131
|
}
|
@@ -36,7 +36,7 @@ export const parseImageService = (service: Service) => {
|
|
36
36
|
}
|
37
37
|
|
38
38
|
export const getImageURLFromService = (
|
39
|
-
service:
|
39
|
+
service: Service,
|
40
40
|
width: number,
|
41
41
|
height: number
|
42
42
|
): string => {
|
@@ -66,7 +66,7 @@ export const getImageURLFromService = (
|
|
66
66
|
}
|
67
67
|
|
68
68
|
export const getRegionURLFromService = (
|
69
|
-
service:
|
69
|
+
service: Service,
|
70
70
|
bounds: Bounds,
|
71
71
|
minSize: number
|
72
72
|
): string | undefined => {
|
package/src/types.ts
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
import type {
|
2
2
|
Manifest,
|
3
|
-
Canvas,
|
4
|
-
ImageService2,
|
5
|
-
ImageService3,
|
3
|
+
Canvas,
|
6
4
|
IIIFExternalWebResource,
|
7
5
|
Collection,
|
8
6
|
Range,
|
9
|
-
AnnotationPage
|
7
|
+
AnnotationPage,
|
8
|
+
Service
|
10
9
|
} from '@iiif/presentation-3';
|
11
10
|
|
12
11
|
export type CozyParseResult =
|
@@ -169,6 +168,8 @@ interface BaseImageResource {
|
|
169
168
|
|
170
169
|
readonly height: number;
|
171
170
|
|
171
|
+
getImageURL(minSize?: number): string;
|
172
|
+
|
172
173
|
getPixelSize(): Promise<{ width: number, height: number }>;
|
173
174
|
|
174
175
|
}
|
@@ -185,7 +186,7 @@ export interface DynamicImageServiceResource extends BaseImageResource {
|
|
185
186
|
|
186
187
|
readonly type: 'dynamic';
|
187
188
|
|
188
|
-
readonly service:
|
189
|
+
readonly service: Service;
|
189
190
|
|
190
191
|
readonly serviceUrl: string;
|
191
192
|
|
@@ -201,7 +202,7 @@ export interface Level0ImageServiceResource extends BaseImageResource {
|
|
201
202
|
|
202
203
|
readonly majorVersion: number;
|
203
204
|
|
204
|
-
readonly service:
|
205
|
+
readonly service: Service;
|
205
206
|
|
206
207
|
readonly serviceUrl: string;
|
207
208
|
|