cozy-iiif 0.2.4 → 0.2.6
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/core/canvas.d.ts +1 -0
- package/dist/index.js +199 -184
- package/dist/types.d.ts +1 -0
- package/package.json +2 -2
- package/src/Cozy.ts +2 -0
- package/src/core/canvas.ts +20 -0
- package/src/core/manifest.ts +6 -2
- package/src/types.ts +2 -0
package/dist/core/canvas.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
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;
|
4
5
|
export declare const normalizeServiceUrl: (url: string) => string;
|
5
6
|
export declare const getImages: (canvas: Canvas) => CozyImageResource[];
|
package/dist/index.js
CHANGED
@@ -1,32 +1,32 @@
|
|
1
|
-
import { g as
|
2
|
-
import { c as
|
3
|
-
var ce = "http://library.stanford.edu/iiif/image-api/compliance.html#level0", le = "http://library.stanford.edu/iiif/image-api/compliance.html#level1",
|
4
|
-
function
|
1
|
+
import { g as m, a as j, b as S } from "./resource-DS2brz47.js";
|
2
|
+
import { c as Wt } from "./resource-DS2brz47.js";
|
3
|
+
var ce = "http://library.stanford.edu/iiif/image-api/compliance.html#level0", le = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", F = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", pe = "http://library.stanford.edu/iiif/image-api/conformance.html#level0", ve = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", W = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", he = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0", ue = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", B = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", fe = "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", ge = "http://iiif.io/api/image/1/level0.json", de = "http://iiif.io/api/image/1/profiles/level0.json", ye = "http://iiif.io/api/image/1/level1.json", Ae = "http://iiif.io/api/image/1/profiles/level1.json", J = "http://iiif.io/api/image/1/level2.json", G = "http://iiif.io/api/image/1/profiles/level2.json", Ce = "http://iiif.io/api/image/2/level0.json", be = "http://iiif.io/api/image/2/profiles/level0.json", Re = "http://iiif.io/api/image/2/level1.json", Le = "http://iiif.io/api/image/2/profiles/level1.json", K = "http://iiif.io/api/image/2/level2.json", Q = "http://iiif.io/api/image/2/profiles/level2.json", we = "level0", Ie = "level1", X = "level2", Se = "http://iiif.io/api/image/2/level0", Te = "http://iiif.io/api/image/2/level1", Y = "http://iiif.io/api/image/2/level2", xe = [Y, F, W, B, H, J, G, K, Q, X], $e = [Se, Te, Y, ce, le, F, pe, ve, W, he, ue, B, fe, me, H, ge, de, ye, Ae, J, G, Ce, be, Re, Le, K, Q, we, Ie, X], Me = $e;
|
4
|
+
function g(t) {
|
5
5
|
for (let e in t) (typeof t[e] > "u" || t[e] === null) && delete t[e];
|
6
6
|
return t;
|
7
7
|
}
|
8
|
-
function
|
8
|
+
function w(t) {
|
9
9
|
return Array.isArray(t) ? t : t ? [t] : [];
|
10
10
|
}
|
11
|
-
var je = Object.defineProperty, ke = (t, e, r) => e in t ? je(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r,
|
11
|
+
var je = Object.defineProperty, ke = (t, e, r) => e in t ? je(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, b = (t, e, r) => (ke(t, typeof e != "symbol" ? e + "" : e, r), r), N = ["sc:Collection", "sc:Manifest", "sc:Canvas", "sc:AnnotationList", "oa:Annotation", "sc:Range", "sc:Layer", "sc:Sequence", "oa:Choice", "Service", "ContentResource"];
|
12
12
|
function Pe(t) {
|
13
13
|
if (typeof t > "u" || t === null) throw new Error("Null or undefined is not a valid entity.");
|
14
14
|
if (Array.isArray(t)) throw new Error("Array is not a valid entity");
|
15
15
|
if (typeof t != "object") throw new Error(`${typeof t} is not a valid entity`);
|
16
16
|
if (typeof t["@type"] == "string") {
|
17
|
-
let e =
|
18
|
-
if (e !== -1) return
|
17
|
+
let e = N.indexOf(t["@type"]);
|
18
|
+
if (e !== -1) return N[e];
|
19
19
|
}
|
20
20
|
if (t.profile) return "Service";
|
21
21
|
if (t.format || t["@type"]) return "ContentResource";
|
22
22
|
throw new Error("Resource type is not known");
|
23
23
|
}
|
24
|
-
var Oe = class
|
24
|
+
var Oe = class Z {
|
25
25
|
constructor(e, r = {}) {
|
26
|
-
|
26
|
+
b(this, "traversals"), b(this, "options"), this.traversals = { collection: [], manifest: [], canvas: [], annotationList: [], sequence: [], annotation: [], contentResource: [], choice: [], range: [], service: [], layer: [], ...e }, this.options = { convertPropsToArray: !0, mergeMemberProperties: !0, allowUndefinedReturn: !1, ...r };
|
27
27
|
}
|
28
28
|
static all(e) {
|
29
|
-
return new
|
29
|
+
return new Z({ collection: [e], manifest: [e], canvas: [e], annotationList: [e], sequence: [e], annotation: [e], contentResource: [e], choice: [e], range: [e], service: [e], layer: [e] });
|
30
30
|
}
|
31
31
|
traverseCollection(e) {
|
32
32
|
return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))), this.traversals.collection);
|
@@ -152,7 +152,7 @@ var Oe = class X {
|
|
152
152
|
return typeof n > "u" && !this.options.allowUndefinedReturn ? i : n;
|
153
153
|
}, e);
|
154
154
|
}
|
155
|
-
}, Ue = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", De = "http://library.stanford.edu/iiif/image-api/compliance.html#level2",
|
155
|
+
}, Ue = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", De = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", Ne = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", Ee = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", qe = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", _e = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", Ve = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", Fe = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", We = "http://iiif.io/api/image/1/level1.json", Be = "http://iiif.io/api/image/1/profiles/level1.json", He = "http://iiif.io/api/image/1/level2.json", Je = "http://iiif.io/api/image/1/profiles/level2.json", Ge = "http://iiif.io/api/image/2/level1.json", Ke = "http://iiif.io/api/image/2/profiles/level1.json", Qe = "http://iiif.io/api/image/2/level2.json", Xe = "http://iiif.io/api/image/2/profiles/level2.json", Ye = "level1", Ze = "level2", ze = "http://iiif.io/api/image/2/level1", et = "http://iiif.io/api/image/2/level2", tt = [ze, et, Ue, De, Ne, Ee, qe, _e, Ve, Fe, We, Be, He, Je, Ge, Ke, Qe, Xe, Ye, Ze], k = { attributionLabel: "Attribution", providerId: "http://example.org/provider", providerName: "Unknown" };
|
156
156
|
function rt(t) {
|
157
157
|
if (typeof t == "string") return [t];
|
158
158
|
if (!t) return [];
|
@@ -166,7 +166,7 @@ function rt(t) {
|
|
166
166
|
}
|
167
167
|
return r;
|
168
168
|
}
|
169
|
-
function
|
169
|
+
function I(t, e = "none") {
|
170
170
|
if (!t) return { none: [""] };
|
171
171
|
let r = rt(t), i = {};
|
172
172
|
for (let s of r) {
|
@@ -183,8 +183,8 @@ function L(t, e = "none") {
|
|
183
183
|
}
|
184
184
|
return Object.keys(i).length === 0 ? { none: [""] } : i;
|
185
185
|
}
|
186
|
-
function
|
187
|
-
if (Array.isArray(t)) return
|
186
|
+
function z(t) {
|
187
|
+
if (Array.isArray(t)) return z(t.find((e) => typeof e == "string"));
|
188
188
|
if (xe.indexOf(t) !== -1) return "level2";
|
189
189
|
if (tt.indexOf(t) !== -1) return "level1";
|
190
190
|
if (Me.indexOf(t) !== -1) return "level0";
|
@@ -232,12 +232,12 @@ function st(t) {
|
|
232
232
|
return "AutoCompleteService1";
|
233
233
|
}
|
234
234
|
}
|
235
|
-
function
|
235
|
+
function E(t) {
|
236
236
|
for (let e of ["sc", "oa", "dcterms", "dctypes", "iiif"]) if (t.startsWith(`${e}:`)) return t.slice(e.length + 1);
|
237
237
|
return t;
|
238
238
|
}
|
239
239
|
var nt = ["Collection", "Manifest", "Annotation", "AnnotationPage", "Range", "Service"];
|
240
|
-
function
|
240
|
+
function U(t) {
|
241
241
|
let e = t["@id"] || t.id, r = t["@type"] || t.type, i = t.profile || void 0, s = t["@context"] || void 0;
|
242
242
|
if (i) {
|
243
243
|
let n = st(i);
|
@@ -282,12 +282,12 @@ function ot(t) {
|
|
282
282
|
function ct(t, e = "Rights/License", r = "none") {
|
283
283
|
let i = null, s = [], n = Array.isArray(t) ? t : [t];
|
284
284
|
for (let o of n) {
|
285
|
-
let
|
286
|
-
if (
|
287
|
-
|
285
|
+
let c = o ? ot(o) : void 0;
|
286
|
+
if (c && (c.indexOf("creativecommons.org") !== -1 || c.indexOf("rightsstatements.org") !== -1)) {
|
287
|
+
c.startsWith("https://") ? i = `http://${c.slice(8)}` : i = c;
|
288
288
|
continue;
|
289
289
|
}
|
290
|
-
|
290
|
+
c && s.push({ label: { [r]: [e] }, value: { [r]: [c] } });
|
291
291
|
}
|
292
292
|
return [i, s];
|
293
293
|
}
|
@@ -300,22 +300,22 @@ function pt(t) {
|
|
300
300
|
}
|
301
301
|
}
|
302
302
|
function vt(t) {
|
303
|
-
return t ? t.map((e) => ({ label:
|
303
|
+
return t ? t.map((e) => ({ label: I(e.label), value: I(e.value) })) : [];
|
304
304
|
}
|
305
|
-
var
|
306
|
-
function
|
305
|
+
var q = 0;
|
306
|
+
function ee(t, e) {
|
307
307
|
let r = encodeURI(t.id || t["@id"] || "").trim();
|
308
|
-
return r && e ? `${r}/${e}` : r || (
|
308
|
+
return r && e ? `${r}/${e}` : r || (q++, `http://example.org/${t["@type"]}${e ? `/${e}` : ""}/${q}`);
|
309
309
|
}
|
310
|
-
function
|
310
|
+
function A(t) {
|
311
311
|
let e = [...t.behavior || []];
|
312
312
|
t.viewingHint && e.push(t.viewingHint);
|
313
313
|
let r;
|
314
|
-
return Array.isArray(t.motivation) ? r = t.motivation.map(
|
314
|
+
return Array.isArray(t.motivation) ? r = t.motivation.map(E) : t.motivation && (r = E(t.motivation)), { "@context": t["@context"] ? pt(t["@context"]) : void 0, id: (t["@id"] || ee(t)).trim(), type: U(t), behavior: e.length ? e : void 0, height: t.height ? t.height : void 0, width: t.width ? t.width : void 0, motivation: r, viewingDirection: t.viewingDirection, profile: t.profile, format: t.format ? t.format : void 0, duration: void 0, timeMode: void 0 };
|
315
315
|
}
|
316
|
-
function
|
316
|
+
function C(t) {
|
317
317
|
let [e, r] = ct(t.license), i = [...t.metadata ? vt(t.metadata) : [], ...r];
|
318
|
-
return { rights: e, metadata: i.length ? i : void 0, label: t.label ?
|
318
|
+
return { rights: e, metadata: i.length ? i : void 0, label: t.label ? I(t.label) : void 0, requiredStatement: t.attribution ? { label: I(k.attributionLabel), value: I(t.attribution) } : void 0, navDate: t.navDate, summary: t.description ? I(t.description) : void 0, thumbnail: ht(t.thumbnail) };
|
319
319
|
}
|
320
320
|
function ht(t) {
|
321
321
|
return t && (Array.isArray(t) ? t : [t]).map((e) => typeof e == "string" ? { id: e, type: "Image" } : (e.type === "unknown" && (e.type = "Image"), e));
|
@@ -329,24 +329,24 @@ function ut(t) {
|
|
329
329
|
r.push({ id: i, type: "Collection" });
|
330
330
|
break;
|
331
331
|
}
|
332
|
-
} else i["@id"] && r.push({ id: i["@id"], type:
|
332
|
+
} else i["@id"] && r.push({ id: i["@id"], type: U(i) });
|
333
333
|
return r.length ? r : void 0;
|
334
334
|
}
|
335
|
-
function
|
335
|
+
function R(t) {
|
336
336
|
let e = t.related ? Array.isArray(t.related) ? t.related : [t.related] : [], r = t.contentLayer;
|
337
|
-
return { provider: t.logo || e.length ? [{ id:
|
337
|
+
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: ut(t), rendering: t.rendering, seeAlso: t.seeAlso, start: t.startCanvas, service: t.service ? w(t.service) : void 0, supplementary: r ? [r] : void 0 };
|
338
338
|
}
|
339
339
|
function ft(t) {
|
340
340
|
return { chars: t.chars, format: t.format ? t.format : void 0, language: t.language };
|
341
341
|
}
|
342
342
|
function mt(t) {
|
343
|
-
return
|
343
|
+
return g({ ...A(t), ...C(t), ...R(t), items: t.members });
|
344
344
|
}
|
345
345
|
function gt(t) {
|
346
346
|
let e = [], r = [], i;
|
347
347
|
for (let n of t.sequences || []) n.canvases.length && e.push(...n.canvases), n.behavior && r.push(...n.behavior), n.startCanvas && (i = n.startCanvas);
|
348
|
-
let s =
|
349
|
-
return r.length && (s.behavior ? s.behavior.push(...r) : s.behavior = r),
|
348
|
+
let s = A(t);
|
349
|
+
return r.length && (s.behavior ? s.behavior.push(...r) : s.behavior = r), g({ ...s, ...C(t), ...R(t), start: i, items: e, structures: dt(t.structures) });
|
350
350
|
}
|
351
351
|
function dt(t) {
|
352
352
|
if (!t) return t;
|
@@ -360,10 +360,10 @@ function dt(t) {
|
|
360
360
|
return t.filter((i) => r.indexOf(i.id) === -1);
|
361
361
|
}
|
362
362
|
function yt(t) {
|
363
|
-
return
|
363
|
+
return g({ ...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 });
|
364
364
|
}
|
365
365
|
function At(t) {
|
366
|
-
return
|
366
|
+
return g({ ...A(t), ...C(t), ...R(t), items: t.resources && t.resources.length ? t.resources : void 0 });
|
367
367
|
}
|
368
368
|
function Ct(t) {
|
369
369
|
return !t.canvases || t.canvases.length === 0 ? { canvases: [], behavior: [] } : { canvases: t.canvases, behavior: t.viewingHint ? [t.viewingHint] : [], startCanvas: t.startCanvas };
|
@@ -381,50 +381,50 @@ function bt(t) {
|
|
381
381
|
else if (r.full["@type"] === "dctypes:Image") i = { id: r.full["@id"], type: "Image" };
|
382
382
|
else if (r.full["@type"] === "sc:Canvas") i = { id: r.full["@id"], type: "Canvas" };
|
383
383
|
else throw new Error(`Unsupported source type on annotation: ${r.full["@type"]}`);
|
384
|
-
return { type: "SpecificResource", source: i, selector:
|
384
|
+
return { type: "SpecificResource", source: i, selector: P(r.selector) };
|
385
385
|
} else return encodeURI(r["@id"]).trim();
|
386
386
|
}
|
387
|
-
return
|
387
|
+
return g({ ...A(t), ...C(t), ...R(t), target: e(t.on), body: Array.isArray(t.resource) ? t.resource.map(_) : _(t.resource) });
|
388
388
|
}
|
389
|
-
function
|
390
|
-
return t.type === "Choice" ? t :
|
389
|
+
function _(t) {
|
390
|
+
return t.type === "Choice" ? t : te(t);
|
391
391
|
}
|
392
|
-
function
|
392
|
+
function te(t) {
|
393
393
|
let e = t;
|
394
|
-
return
|
394
|
+
return g({ ...A(e), ...C(e), ...R(e), ...ft(e) });
|
395
395
|
}
|
396
396
|
function Rt(t) {
|
397
397
|
let e = [];
|
398
|
-
return t.default && t.default !== "rdf:nil" && e.push(t.default), t.item && t.item !== "rdf:nil" && e.push(...t.item),
|
398
|
+
return t.default && t.default !== "rdf:nil" && e.push(t.default), t.item && t.item !== "rdf:nil" && e.push(...t.item), g({ ...A(t), ...C(t), items: e });
|
399
399
|
}
|
400
400
|
function Lt(t) {
|
401
|
-
return
|
401
|
+
return g({ ...A(t), ...C(t), ...R(t), items: t.members });
|
402
402
|
}
|
403
403
|
function wt(t) {
|
404
404
|
let { "@id": e, "@type": r, "@context": i, profile: s, ...n } = t, o = {};
|
405
|
-
return e && (o["@id"] = e), o["@type"] =
|
405
|
+
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)), g({ ...o, ...n });
|
406
406
|
}
|
407
407
|
function It(t) {
|
408
|
-
return
|
408
|
+
return g({ ...A(t), ...C(t), ...R(t) });
|
409
409
|
}
|
410
|
-
var St = new Oe({ collection: [mt], manifest: [gt], canvas: [yt], annotationList: [At], sequence: [Ct], annotation: [bt], contentResource: [
|
411
|
-
function
|
410
|
+
var St = new Oe({ collection: [mt], manifest: [gt], canvas: [yt], annotationList: [At], sequence: [Ct], annotation: [bt], contentResource: [te], choice: [Rt], range: [Lt], service: [wt], layer: [It] });
|
411
|
+
function re(t) {
|
412
412
|
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" ? St.traverseUnknown(t) : t;
|
413
413
|
}
|
414
|
-
function
|
414
|
+
function P(t) {
|
415
415
|
if ((Array.isArray(t["@type"]) && t["@type"].includes("oa:SvgSelector") || t["@type"] == "oa:SvgSelector") && ("chars" in t || "value" in t)) return { type: "SvgSelector", value: "chars" in t ? t.chars : t.value };
|
416
416
|
if (t["@type"] === "oa:FragmentSelector") return { type: "FragmentSelector", value: t.value };
|
417
|
-
if (t["@type"] === "oa:Choice") return [
|
417
|
+
if (t["@type"] === "oa:Choice") return [P(t.default), ...(Array.isArray(t.item) ? t.item : [t.item]).map(P)];
|
418
418
|
if (t["@type"] == "iiif:ImageApiSelector") return { type: "ImageApiSelector", region: "region" in t ? t.region : void 0, rotation: "rotation" in t ? t.rotation : void 0 };
|
419
419
|
throw new Error(`Unsupported selector type: ${t["@type"]}`);
|
420
420
|
}
|
421
|
-
function
|
421
|
+
function M(t) {
|
422
422
|
return typeof t == "string" ? !1 : t && !t.type && "source" in t ? (t.type = "SpecificResource", !0) : !!t && t.type === "SpecificResource";
|
423
423
|
}
|
424
424
|
function T(...t) {
|
425
425
|
return (e) => t.reduce((r, i) => i(r), e);
|
426
426
|
}
|
427
|
-
var
|
427
|
+
var V = ["Collection", "Manifest", "Canvas", "AnnotationPage", "AnnotationCollection", "Annotation", "ContentResource", "Range", "Service", "Selector", "Agent"];
|
428
428
|
function Tt(t, e) {
|
429
429
|
if (typeof t > "u" || t === null) throw new Error("Null or undefined is not a valid entity.");
|
430
430
|
if (Array.isArray(t)) throw new Error("Array is not a valid entity");
|
@@ -433,24 +433,24 @@ function Tt(t, e) {
|
|
433
433
|
throw new Error(`${typeof t} is not a valid entity`);
|
434
434
|
}
|
435
435
|
if (typeof t.type == "string") {
|
436
|
-
let r =
|
437
|
-
if (r !== -1) return
|
436
|
+
let r = V.indexOf(t.type);
|
437
|
+
if (r !== -1) return V[r];
|
438
438
|
}
|
439
439
|
if (t.profile) return "Service";
|
440
440
|
throw new Error("Resource type is not known");
|
441
441
|
}
|
442
|
-
var
|
442
|
+
var D = class ie {
|
443
443
|
constructor(e, r = {}) {
|
444
|
-
|
444
|
+
b(this, "traversals"), b(this, "options"), b(this, "_traverseManifest", T(this.traverseManifestItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseManifestStructures.bind(this), this.traverseInlineAnnotationPages.bind(this))), b(this, "_traverseCanvas", T(this.traverseCanvasItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseInlineAnnotationPages.bind(this))), b(this, "_traverseAnnotationPage", T(this.traverseAnnotationPageItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this))), b(this, "_traverseRange", T(this.traverseRangeRanges.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this))), this.traversals = { collection: [], manifest: [], canvas: [], annotationCollection: [], annotationPage: [], annotation: [], contentResource: [], choice: [], range: [], service: [], agent: [], specificResource: [], geoJson: [], ...e }, this.options = { allowUndefinedReturn: !1, ...r };
|
445
445
|
}
|
446
446
|
static all(e) {
|
447
|
-
return new
|
447
|
+
return new ie({ collection: [e], manifest: [e], canvas: [e], annotationCollection: [e], annotationPage: [e], annotation: [e], contentResource: [e], choice: [e], range: [e], service: [e], geoJson: [e], specificResource: [e], agent: [e] });
|
448
448
|
}
|
449
449
|
traverseDescriptive(e) {
|
450
|
-
return e.thumbnail && (e.thumbnail =
|
450
|
+
return e.thumbnail && (e.thumbnail = w(e.thumbnail).map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.provider && (e.provider = e.provider.map((r) => this.traverseAgent(r, e))), e;
|
451
451
|
}
|
452
452
|
traverseLinking(e) {
|
453
|
-
return e.seeAlso && (e.seeAlso = e.seeAlso.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.service && (e.service =
|
453
|
+
return e.seeAlso && (e.seeAlso = e.seeAlso.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.service && (e.service = w(e.service).map((r) => this.traverseService(r))), e.services && (e.services = w(e.services).map((r) => this.traverseService(r, e))), e.logo && (e.logo = e.logo.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.homepage && (e.homepage = w(e.homepage).map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.partOf && (e.partOf = e.partOf.map((r) => typeof r == "string" || !r.type ? this.traverseType(r, { parent: e }, this.traversals.contentResource) : r.type === "Canvas" ? this.traverseType(r, { parent: e }, this.traversals.canvas) : r.type === "AnnotationCollection" ? this.traverseType(r, { parent: e }, this.traversals.annotationCollection) : r.type === "Collection" ? this.traverseType(r, { parent: e }, this.traversals.collection) : this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.start && (M(e.start) ? e.start = this.traverseSpecificResource(e.start, "Canvas", e) : e.start = this.traverseType(e.start, { parent: e }, this.traversals.canvas)), e.rendering && (e.rendering = e.rendering.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.supplementary && (e.supplementary = e.supplementary.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e;
|
454
454
|
}
|
455
455
|
traverseCollectionItems(e) {
|
456
456
|
return e.items && e.items.map((r) => r.type === "Collection" ? this.traverseCollection(r) : this.traverseManifest(r)), e;
|
@@ -498,17 +498,17 @@ var O = class re {
|
|
498
498
|
return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(this.traverseDescriptive(e))), { parent: r }, this.traversals.annotation);
|
499
499
|
}
|
500
500
|
traverseContentResourceLinking(e) {
|
501
|
-
return typeof e == "string" || !e || e && e.service && (e.service =
|
501
|
+
return typeof e == "string" || !e || e && e.service && (e.service = w(e.service || []).map((r) => this.traverseService(r, e))), e;
|
502
502
|
}
|
503
503
|
traverseContentResource(e, r) {
|
504
|
-
return e.type === "Choice" && (e.items = e.items.map((i) => this.traverseContentResource(i, e))),
|
504
|
+
return e.type === "Choice" && (e.items = e.items.map((i) => this.traverseContentResource(i, e))), M(e) ? this.traverseSpecificResource(e, "ContentResource") : this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)), { parent: r }, this.traversals.contentResource);
|
505
505
|
}
|
506
506
|
traverseSpecificResource(e, r, i) {
|
507
507
|
let s = e.source;
|
508
508
|
return typeof e.source == "string" && (s = { id: e.source, type: r || "unknown" }), this.traverseType({ ...e, source: r === "Canvas" || s.type === "Canvas" ? this.traverseType(s, { parent: i }, this.traversals.canvas) : r === "ContentResource" ? this.traverseContentResource(s, { parent: i }) : this.traverseUnknown(s, { parent: i, typeHint: r }) }, { parent: i }, this.traversals.specificResource);
|
509
509
|
}
|
510
510
|
traverseRangeRanges(e) {
|
511
|
-
return e.items && (e.items = e.items.map((r) => typeof r == "string" ? this.traverseCanvas({ id: r, type: "Canvas" }, e) :
|
511
|
+
return e.items && (e.items = e.items.map((r) => typeof r == "string" ? this.traverseCanvas({ id: r, type: "Canvas" }, e) : M(r) ? this.traverseSpecificResource(r, "Canvas", e) : r.type === "Manifest" ? this.traverseManifest(r, e) : this.traverseRange(r, e))), e;
|
512
512
|
}
|
513
513
|
traverseRange(e, r) {
|
514
514
|
return this.traverseType(this._traverseRange(e), { parent: r }, this.traversals.range);
|
@@ -524,7 +524,7 @@ var O = class re {
|
|
524
524
|
}
|
525
525
|
traverseService(e, r) {
|
526
526
|
let i = Object.assign({}, e);
|
527
|
-
return i && i.service && (i.service =
|
527
|
+
return i && i.service && (i.service = w(i.service).map((s) => this.traverseService(s))), this.traverseType(i, { parent: r }, this.traversals.service);
|
528
528
|
}
|
529
529
|
traverseUnknown(e, { parent: r, typeHint: i } = {}) {
|
530
530
|
let s = Tt(e, i);
|
@@ -552,18 +552,18 @@ var O = class re {
|
|
552
552
|
}
|
553
553
|
}
|
554
554
|
};
|
555
|
-
const
|
556
|
-
const e =
|
555
|
+
const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.profile.toString().includes("iiif.io/api/image/"), ne = (t) => {
|
556
|
+
const e = m(t, "type"), r = m(t, "context");
|
557
557
|
if (e === "ImageService2" || r != null && r.includes("image/2")) {
|
558
558
|
const i = t, s = ["level0", "level1", "level2"];
|
559
|
-
return { majorVersion: 2, profileLevel: (Array.isArray(i.profile) ? i.profile : [i.profile]).map((
|
559
|
+
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] };
|
560
560
|
} else if (e || r)
|
561
561
|
return { majorVersion: 3, profileLevel: parseInt(t.profile) };
|
562
|
-
},
|
563
|
-
const i =
|
562
|
+
}, O = (t, e, r) => {
|
563
|
+
const i = m(t, "id"), s = t.profile || "";
|
564
564
|
if (typeof s == "string" && (s.includes("level0") || s.includes("level:0"))) {
|
565
565
|
if ("sizes" in t && Array.isArray(t.sizes)) {
|
566
|
-
const o = t.sizes.sort((
|
566
|
+
const o = t.sizes.sort((c, a) => a.width * a.height - c.width * c.height).filter((c) => c.width * c.height >= e * r)[0];
|
567
567
|
if (o)
|
568
568
|
return `${i}/full/${o.width},${o.height}/0/default.jpg`;
|
569
569
|
}
|
@@ -571,10 +571,10 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
571
571
|
}
|
572
572
|
return `${i}/full/!${e},${r}/0/default.jpg`;
|
573
573
|
}, xt = (t, e, r) => {
|
574
|
-
const i =
|
574
|
+
const i = m(t, "id"), s = t.profile || "";
|
575
575
|
if (typeof s == "string" && (s.includes("level0") || s.includes("level:0"))) return;
|
576
|
-
const { x: o, y:
|
577
|
-
return `${i}/${
|
576
|
+
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)}`;
|
577
|
+
return `${i}/${f}/!${p},${d}/0/default.jpg`;
|
578
578
|
}, $t = (t) => (e, r = 400) => {
|
579
579
|
if (t.type === "dynamic")
|
580
580
|
return xt(t.service, e, r);
|
@@ -582,37 +582,47 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
582
582
|
}, Mt = (t, e = []) => (r = 400) => {
|
583
583
|
const { width: i, height: s } = t;
|
584
584
|
if (!i || !s) return;
|
585
|
-
const n = i / s, o = n < 1,
|
585
|
+
const n = i / s, o = n < 1, c = Math.ceil(o ? r / n : r), a = Math.ceil(o ? r : r / n);
|
586
586
|
if (t.thumbnail && t.thumbnail.length > 0) {
|
587
|
-
const
|
588
|
-
if ("service" in
|
589
|
-
const
|
590
|
-
if (
|
591
|
-
return
|
587
|
+
const l = t.thumbnail[0];
|
588
|
+
if ("service" in l && Array.isArray(l.service)) {
|
589
|
+
const u = l.service.find((v) => se(v));
|
590
|
+
if (u)
|
591
|
+
return O(u, a, c);
|
592
592
|
}
|
593
|
-
if ("id" in
|
593
|
+
if ("id" in l) return l.id;
|
594
594
|
}
|
595
|
-
for (const
|
596
|
-
if (
|
597
|
-
return
|
598
|
-
if (
|
599
|
-
return
|
595
|
+
for (const l of e) {
|
596
|
+
if (l.type === "dynamic" || l.type === "level0")
|
597
|
+
return O(l.service, a, c);
|
598
|
+
if (l.type === "static")
|
599
|
+
return l.url;
|
600
600
|
}
|
601
|
-
},
|
602
|
-
const {
|
601
|
+
}, jt = (t, e = []) => (r = 800) => {
|
602
|
+
const { width: i, height: s } = t;
|
603
|
+
if (!i || !s) return;
|
604
|
+
const n = i / s, o = n < 1, c = Math.ceil(o ? r / n : r), a = Math.ceil(o ? r : r / n);
|
605
|
+
for (const l of e) {
|
606
|
+
if (l.type === "dynamic" || l.type === "level0")
|
607
|
+
return O(l.service, a, c);
|
608
|
+
if (l.type === "static")
|
609
|
+
return l.url;
|
610
|
+
}
|
611
|
+
}, ae = (t) => t.endsWith("/info.json") ? t : `${t.endsWith("/") ? t : `${t}/`}info.json`, kt = (t) => {
|
612
|
+
const { format: e, height: r, width: i } = t, s = m(t, "id"), n = (t.service || []).find(se), o = n ? ne(n) : void 0;
|
603
613
|
if (o) {
|
604
|
-
const
|
614
|
+
const c = {
|
605
615
|
source: t,
|
606
616
|
type: o.profileLevel === 0 ? "level0" : "dynamic",
|
607
617
|
service: n,
|
608
618
|
width: i,
|
609
619
|
height: r,
|
610
620
|
majorVersion: o.majorVersion,
|
611
|
-
serviceUrl:
|
621
|
+
serviceUrl: ae(m(n, "id"))
|
612
622
|
};
|
613
|
-
return o.profileLevel === 0 ?
|
614
|
-
...
|
615
|
-
getRegionURL: $t(
|
623
|
+
return o.profileLevel === 0 ? c : {
|
624
|
+
...c,
|
625
|
+
getRegionURL: $t(c)
|
616
626
|
};
|
617
627
|
} else
|
618
628
|
return {
|
@@ -623,61 +633,64 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
623
633
|
url: s,
|
624
634
|
format: e
|
625
635
|
};
|
626
|
-
},
|
636
|
+
}, Pt = (t) => {
|
627
637
|
const e = [];
|
628
|
-
return new
|
638
|
+
return new D({
|
629
639
|
annotation: [(i) => {
|
630
640
|
if (i.motivation === "painting" || !i.motivation) {
|
631
641
|
const n = (i.body ? Array.isArray(i.body) ? i.body : [i.body] : []).filter((o) => o.type === "Image");
|
632
|
-
e.push(...n.map((o) =>
|
642
|
+
e.push(...n.map((o) => kt(o)));
|
633
643
|
}
|
634
644
|
}]
|
635
645
|
}).traverseCanvas(t), e;
|
636
|
-
},
|
637
|
-
const e = /* @__PURE__ */ new Map(), r = (a,
|
638
|
-
const
|
646
|
+
}, Ot = (t) => () => {
|
647
|
+
const e = /* @__PURE__ */ new Map(), r = (a, l, u = 0) => {
|
648
|
+
const v = {
|
639
649
|
id: a.id,
|
640
650
|
type: "range",
|
641
651
|
source: a,
|
642
652
|
children: [],
|
643
653
|
navItems: [],
|
644
654
|
navSections: [],
|
645
|
-
parent:
|
646
|
-
level:
|
655
|
+
parent: l,
|
656
|
+
level: u,
|
647
657
|
getLabel: a.getLabel
|
648
658
|
};
|
649
|
-
a.items && a.items.length > 0 && a.items.forEach((
|
650
|
-
if (
|
651
|
-
const
|
652
|
-
|
659
|
+
a.items && a.items.length > 0 && a.items.forEach((h) => {
|
660
|
+
if (h.source.type === "Range") {
|
661
|
+
const x = r(h, v, u + 1);
|
662
|
+
v.children.push(x);
|
653
663
|
} else {
|
654
|
-
const
|
655
|
-
id:
|
664
|
+
const L = {
|
665
|
+
id: h.id,
|
656
666
|
type: "canvas",
|
657
|
-
source:
|
667
|
+
source: h,
|
658
668
|
children: [],
|
659
669
|
navItems: [],
|
660
670
|
navSections: [],
|
661
|
-
parent:
|
662
|
-
level:
|
663
|
-
getLabel:
|
671
|
+
parent: v,
|
672
|
+
level: u + 1,
|
673
|
+
getLabel: h.getLabel
|
664
674
|
};
|
665
|
-
|
675
|
+
v.children.push(L), e.set(L.id, L);
|
666
676
|
}
|
667
677
|
});
|
668
|
-
const
|
669
|
-
return
|
678
|
+
const d = v.children.map((h) => h.type === "canvas" ? h.source : h.children.length === 1 && h.children[0].type === "canvas" ? h.children[0].source : h.source), p = d.filter((h) => h.source.type === "Canvas"), f = d.filter((h) => h.source.type === "Range");
|
679
|
+
return v.navItems.push(...p), v.navSections.push(...f), e.set(v.id, v), v;
|
670
680
|
};
|
671
681
|
return { root: t.filter((a) => {
|
672
|
-
var
|
673
|
-
return (
|
674
|
-
}).map((a) => r(a, void 0)),
|
675
|
-
const
|
676
|
-
|
677
|
-
|
678
|
-
|
682
|
+
var l;
|
683
|
+
return (l = a.source.behavior) == null ? void 0 : l.includes("top");
|
684
|
+
}).map((a) => r(a, void 0)), enumerateNodes: (a) => {
|
685
|
+
const l = Array.from(e.values());
|
686
|
+
return a ? l.filter((u) => u.type === a) : l;
|
687
|
+
}, getBreadcrumbs: (a) => {
|
688
|
+
const l = e.get(a);
|
689
|
+
if (!l) return [];
|
690
|
+
const u = (v, d = []) => v.parent ? u(v.parent, [v, ...d]) : [v, ...d];
|
691
|
+
return u(l);
|
679
692
|
}, getNode: (a) => e.get(a) };
|
680
|
-
},
|
693
|
+
}, Ut = async (t) => {
|
681
694
|
try {
|
682
695
|
new URL(t);
|
683
696
|
} catch {
|
@@ -715,7 +728,7 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
715
728
|
};
|
716
729
|
try {
|
717
730
|
const i = await e.json();
|
718
|
-
return
|
731
|
+
return oe(i, t);
|
719
732
|
} catch {
|
720
733
|
return {
|
721
734
|
type: "error",
|
@@ -723,7 +736,7 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
723
736
|
message: "Could not parse resource"
|
724
737
|
};
|
725
738
|
}
|
726
|
-
},
|
739
|
+
}, oe = (t, e) => {
|
727
740
|
const r = Array.isArray(t["@context"]) ? t["@context"].find((s) => s.includes("iiif.io/api/")) : t["@context"];
|
728
741
|
if (!r)
|
729
742
|
return {
|
@@ -731,7 +744,7 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
731
744
|
code: "INVALID_MANIFEST",
|
732
745
|
message: "Missing @context"
|
733
746
|
};
|
734
|
-
const i =
|
747
|
+
const i = m(t, "id");
|
735
748
|
if (!i)
|
736
749
|
return {
|
737
750
|
type: "error",
|
@@ -740,14 +753,14 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
740
753
|
};
|
741
754
|
if (r.includes("presentation/2") || r.includes("presentation/3")) {
|
742
755
|
const s = r.includes("presentation/2") ? 2 : 3;
|
743
|
-
return
|
756
|
+
return m(t, "type").includes("Collection") ? {
|
744
757
|
type: "collection",
|
745
758
|
url: e || i,
|
746
|
-
resource:
|
759
|
+
resource: Dt(t, s)
|
747
760
|
} : {
|
748
761
|
type: "manifest",
|
749
762
|
url: e || i,
|
750
|
-
resource:
|
763
|
+
resource: Nt(t, s)
|
751
764
|
};
|
752
765
|
}
|
753
766
|
if (r.includes("image/2") || r.includes("image/3")) {
|
@@ -767,76 +780,77 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
767
780
|
code: "INVALID_MANIFEST",
|
768
781
|
message: "JSON resource is not a recognized IIIF format"
|
769
782
|
};
|
770
|
-
},
|
783
|
+
}, Dt = (t, e) => {
|
771
784
|
const r = (n) => {
|
772
785
|
const o = [];
|
773
|
-
return new
|
774
|
-
manifest: [(
|
775
|
-
}).traverseCollection(n), o.map((
|
776
|
-
id:
|
777
|
-
type:
|
778
|
-
getLabel:
|
779
|
-
source:
|
786
|
+
return new D({
|
787
|
+
manifest: [(a) => o.push(a)]
|
788
|
+
}).traverseCollection(n), o.map((a) => ({
|
789
|
+
id: a.id,
|
790
|
+
type: a.type,
|
791
|
+
getLabel: S(a),
|
792
|
+
source: a
|
780
793
|
}));
|
781
|
-
}, i = e === 2 ?
|
794
|
+
}, i = e === 2 ? re(t) : t, s = r(i);
|
782
795
|
return {
|
783
796
|
source: i,
|
784
797
|
id: i.id,
|
785
798
|
majorVersion: e,
|
786
799
|
items: s,
|
787
|
-
getLabel:
|
788
|
-
getMetadata:
|
800
|
+
getLabel: S(i),
|
801
|
+
getMetadata: j(i)
|
789
802
|
};
|
790
|
-
},
|
803
|
+
}, Nt = (t, e) => {
|
791
804
|
const r = (o) => {
|
792
|
-
const
|
793
|
-
new
|
794
|
-
canvas: [(
|
795
|
-
|
805
|
+
const c = [], a = [];
|
806
|
+
new D({
|
807
|
+
canvas: [(p) => {
|
808
|
+
p.items && c.push(p);
|
796
809
|
}],
|
797
|
-
range: [(
|
798
|
-
|
810
|
+
range: [(p) => {
|
811
|
+
p.type === "Range" && a.push(p);
|
799
812
|
}]
|
800
813
|
}).traverseManifest(o);
|
801
|
-
const
|
802
|
-
const
|
814
|
+
const u = c.map((p) => {
|
815
|
+
const f = Pt(p);
|
803
816
|
return {
|
804
|
-
source:
|
805
|
-
id:
|
806
|
-
width:
|
807
|
-
height:
|
808
|
-
images:
|
809
|
-
annotations:
|
810
|
-
|
811
|
-
|
812
|
-
|
817
|
+
source: p,
|
818
|
+
id: p.id,
|
819
|
+
width: p.width,
|
820
|
+
height: p.height,
|
821
|
+
images: f,
|
822
|
+
annotations: p.annotations || [],
|
823
|
+
getImageURL: jt(p, f),
|
824
|
+
getLabel: S(p),
|
825
|
+
getMetadata: j(p),
|
826
|
+
getThumbnailURL: Mt(p, f)
|
813
827
|
};
|
814
|
-
}),
|
815
|
-
const
|
828
|
+
}), v = (p) => {
|
829
|
+
const f = p.items || [], h = f.filter((y) => y.type === "Canvas").map((y) => u.find(($) => $.id === y.id)).filter(Boolean), L = f.filter((y) => y.type === "Range").map((y) => v(y)), x = [...h, ...L];
|
816
830
|
return {
|
817
|
-
source:
|
818
|
-
id:
|
831
|
+
source: p,
|
832
|
+
id: p.id,
|
819
833
|
// Maintain original order
|
820
|
-
items:
|
821
|
-
canvases:
|
822
|
-
ranges:
|
823
|
-
getLabel:
|
834
|
+
items: f.map((y) => x.find(($) => $.id === y.id)),
|
835
|
+
canvases: h,
|
836
|
+
ranges: L,
|
837
|
+
getLabel: S(p)
|
824
838
|
};
|
825
|
-
},
|
826
|
-
return { canvases:
|
827
|
-
}, i = e === 2 ?
|
839
|
+
}, d = a.map((p) => v(p));
|
840
|
+
return { canvases: u, ranges: d };
|
841
|
+
}, i = e === 2 ? re(t) : t, { canvases: s, ranges: n } = r(i);
|
828
842
|
return {
|
829
843
|
source: i,
|
830
844
|
id: i.id,
|
831
845
|
majorVersion: e,
|
832
846
|
canvases: s,
|
833
847
|
structure: n,
|
834
|
-
getLabel:
|
835
|
-
getMetadata:
|
836
|
-
getTableOfContents:
|
848
|
+
getLabel: S(i),
|
849
|
+
getMetadata: j(i),
|
850
|
+
getTableOfContents: Ot(n)
|
837
851
|
};
|
838
852
|
}, Et = (t) => {
|
839
|
-
const { width: e, height: r } = t, i =
|
853
|
+
const { width: e, height: r } = t, i = ne(t);
|
840
854
|
if (i)
|
841
855
|
return {
|
842
856
|
type: i.profileLevel === 0 ? "level0" : "dynamic",
|
@@ -844,22 +858,23 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
844
858
|
width: e,
|
845
859
|
height: r,
|
846
860
|
majorVersion: i.majorVersion,
|
847
|
-
serviceUrl:
|
861
|
+
serviceUrl: ae(m(t, "id"))
|
848
862
|
};
|
849
|
-
},
|
863
|
+
}, _t = { parse: oe, parseURL: Ut };
|
850
864
|
export {
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
865
|
+
_t as Cozy,
|
866
|
+
jt as getImageURL,
|
867
|
+
O as getImageURLFromService,
|
868
|
+
Pt as getImages,
|
869
|
+
S as getLabel,
|
870
|
+
j as getMetadata,
|
871
|
+
m as getPropertyValue,
|
857
872
|
$t as getRegionURL,
|
858
873
|
xt as getRegionURLFromService,
|
859
|
-
|
860
|
-
|
874
|
+
Wt as getStringValue,
|
875
|
+
Ot as getTableOfContents,
|
861
876
|
Mt as getThumbnailURL,
|
862
|
-
|
863
|
-
|
864
|
-
|
877
|
+
se as isImageService,
|
878
|
+
ae as normalizeServiceUrl,
|
879
|
+
ne as parseImageService
|
865
880
|
};
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "cozy-iiif",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.6",
|
4
4
|
"description": "A developer-friendly collection of abstractions and utilities built on top of @iiif/presentation-3 and @iiif/parser",
|
5
5
|
"license": "MIT",
|
6
6
|
"author": "Rainer Simon",
|
@@ -30,7 +30,7 @@
|
|
30
30
|
"devDependencies": {
|
31
31
|
"vite": "^6.3.5",
|
32
32
|
"vite-plugin-dts": "^4.5.4",
|
33
|
-
"vitest": "^3.
|
33
|
+
"vitest": "^3.2.2"
|
34
34
|
},
|
35
35
|
"dependencies": {
|
36
36
|
"@iiif/parser": "2.1.7",
|
package/src/Cozy.ts
CHANGED
@@ -3,6 +3,7 @@ import { convertPresentation2 } from '@iiif/parser/presentation-2';
|
|
3
3
|
import { Traverse } from '@iiif/parser';
|
4
4
|
import {
|
5
5
|
getImages,
|
6
|
+
getImageURL,
|
6
7
|
getLabel,
|
7
8
|
getMetadata,
|
8
9
|
getPropertyValue,
|
@@ -193,6 +194,7 @@ const parseManifestResource = (resource: any, majorVersion: number): CozyManifes
|
|
193
194
|
height: c.height,
|
194
195
|
images,
|
195
196
|
annotations: (c.annotations || []),
|
197
|
+
getImageURL: getImageURL(c, images),
|
196
198
|
getLabel: getLabel(c),
|
197
199
|
getMetadata: getMetadata(c),
|
198
200
|
getThumbnailURL: getThumbnailURL(c, images)
|
package/src/core/canvas.ts
CHANGED
@@ -42,6 +42,26 @@ export const getThumbnailURL = (canvas: Canvas, images: CozyImageResource[] = []
|
|
42
42
|
}
|
43
43
|
}
|
44
44
|
|
45
|
+
export const getImageURL = (canvas: Canvas, images: CozyImageResource[] = []) => (minSize = 800) => {
|
46
|
+
const { width, height } = canvas;
|
47
|
+
|
48
|
+
if (!width || !height) return;
|
49
|
+
|
50
|
+
const aspect = width / height;
|
51
|
+
const isPortrait = aspect < 1;
|
52
|
+
|
53
|
+
const h = Math.ceil(isPortrait ? minSize / aspect : minSize);
|
54
|
+
const w = Math.ceil(isPortrait ? minSize : minSize / aspect);
|
55
|
+
|
56
|
+
for (const image of images) {
|
57
|
+
if (image.type === 'dynamic' || image.type === 'level0') {
|
58
|
+
return getImageURLFromService(image.service, w, h);
|
59
|
+
} else if (image.type === 'static') {
|
60
|
+
return image.url;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
45
65
|
export const normalizeServiceUrl = (url: string) =>
|
46
66
|
url.endsWith('/info.json') ? url : `${url.endsWith('/') ? url : `${url}/`}info.json`;
|
47
67
|
|
package/src/core/manifest.ts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import type { CozyCanvas, CozyRange, CozyTOC, CozyTOCNode } from '../types';
|
2
2
|
|
3
3
|
export const getTableOfContents = (ranges: CozyRange[]) => (): CozyTOC => {
|
4
|
-
|
5
4
|
const index = new Map<string, CozyTOCNode>();
|
6
5
|
|
7
6
|
const buildTree = (range: CozyRange, parent: CozyTOCNode | undefined, level: number = 0): CozyTOCNode => {
|
@@ -90,5 +89,10 @@ export const getTableOfContents = (ranges: CozyRange[]) => (): CozyTOC => {
|
|
90
89
|
return addParent(thisNode);
|
91
90
|
}
|
92
91
|
|
93
|
-
|
92
|
+
const enumerateNodes = (type?: 'range' | 'canvas'): CozyTOCNode[] => {
|
93
|
+
const all = Array.from(index.values());
|
94
|
+
return type ? all.filter(n => n.type === type) : all;
|
95
|
+
}
|
96
|
+
|
97
|
+
return { root, enumerateNodes, getBreadcrumbs, getNode };
|
94
98
|
}
|
package/src/types.ts
CHANGED