cozy-iiif 0.2.2 → 0.2.3
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 +93 -91
- package/package.json +5 -5
- package/src/core/manifest.ts +6 -2
package/dist/index.js
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
import { g as f, a as M, b as
|
1
|
+
import { g as f, a as M, b as I } from "./resource-DS2brz47.js";
|
2
2
|
import { c as Ft } from "./resource-DS2brz47.js";
|
3
3
|
var ce = "http://library.stanford.edu/iiif/image-api/compliance.html#level0", le = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", V = "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", F = "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", W = "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", B = "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", H = "http://iiif.io/api/image/1/level2.json", J = "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", G = "http://iiif.io/api/image/2/level2.json", z = "http://iiif.io/api/image/2/profiles/level2.json", we = "level0", Ie = "level1", K = "level2", Se = "http://iiif.io/api/image/2/level0", Te = "http://iiif.io/api/image/2/level1", Q = "http://iiif.io/api/image/2/level2", xe = [Q, V, F, W, B, H, J, G, z, K], $e = [Se, Te, Q, ce, le, V, pe, ve, F, he, ue, W, fe, me, B, ge, de, ye, Ae, H, J, Ce, be, Re, Le, G, z, we, Ie, K], Me = $e;
|
4
4
|
function m(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 R(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, A = (t, e, r) => (ke(t, typeof e != "symbol" ? e + "" : e, r), 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, A = (t, e, r) => (ke(t, typeof e != "symbol" ? e + "" : e, r), r), D = ["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 = D.indexOf(t["@type"]);
|
18
|
+
if (e !== -1) return D[e];
|
19
19
|
}
|
20
20
|
if (t.profile) return "Service";
|
21
21
|
if (t.format || t["@type"]) return "ContentResource";
|
@@ -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
|
-
},
|
155
|
+
}, De = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", Ue = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", Ee = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", Ne = "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", ze = "http://iiif.io/api/image/2/profiles/level1.json", Ke = "http://iiif.io/api/image/2/level2.json", Qe = "http://iiif.io/api/image/2/profiles/level2.json", Xe = "level1", Ye = "level2", Ze = "http://iiif.io/api/image/2/level1", et = "http://iiif.io/api/image/2/level2", tt = [Ze, et, De, Ue, Ee, Ne, qe, _e, Ve, Fe, We, Be, He, Je, Ge, ze, Ke, Qe, Xe, Ye], j = { 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 L(t, e = "none") {
|
170
170
|
if (!t) return { none: [""] };
|
171
171
|
let r = rt(t), i = {};
|
172
172
|
for (let s of r) {
|
@@ -232,7 +232,7 @@ function st(t) {
|
|
232
232
|
return "AutoCompleteService1";
|
233
233
|
}
|
234
234
|
}
|
235
|
-
function
|
235
|
+
function U(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
|
}
|
@@ -281,13 +281,13 @@ function ot(t) {
|
|
281
281
|
}
|
282
282
|
function ct(t, e = "Rights/License", r = "none") {
|
283
283
|
let i = null, s = [], n = Array.isArray(t) ? t : [t];
|
284
|
-
for (let
|
285
|
-
let
|
286
|
-
if (
|
287
|
-
|
284
|
+
for (let a of n) {
|
285
|
+
let o = a ? ot(a) : void 0;
|
286
|
+
if (o && (o.indexOf("creativecommons.org") !== -1 || o.indexOf("rightsstatements.org") !== -1)) {
|
287
|
+
o.startsWith("https://") ? i = `http://${o.slice(8)}` : i = o;
|
288
288
|
continue;
|
289
289
|
}
|
290
|
-
|
290
|
+
o && s.push({ label: { [r]: [e] }, value: { [r]: [o] } });
|
291
291
|
}
|
292
292
|
return [i, s];
|
293
293
|
}
|
@@ -300,7 +300,7 @@ 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: L(e.label), value: L(e.value) })) : [];
|
304
304
|
}
|
305
305
|
var E = 0;
|
306
306
|
function Z(t, e) {
|
@@ -311,11 +311,11 @@ function d(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(U) : t.motivation && (r = U(t.motivation)), { "@context": t["@context"] ? pt(t["@context"]) : void 0, id: (t["@id"] || Z(t)).trim(), type: P(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
316
|
function y(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 ? L(t.label) : void 0, requiredStatement: t.attribution ? { label: L(j.attributionLabel), value: L(t.attribution) } : void 0, navDate: t.navDate, summary: t.description ? L(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));
|
@@ -334,7 +334,7 @@ function ut(t) {
|
|
334
334
|
}
|
335
335
|
function C(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: j.providerId, type: "Agent", homepage: e.length ? [e[0]] : void 0, logo: t.logo ? Array.isArray(t.logo) ? t.logo : [t.logo] : void 0, label:
|
337
|
+
return { provider: t.logo || e.length ? [{ id: j.providerId, type: "Agent", homepage: e.length ? [e[0]] : void 0, logo: t.logo ? Array.isArray(t.logo) ? t.logo : [t.logo] : void 0, label: L(j.providerName) }] : void 0, partOf: ut(t), rendering: t.rendering, seeAlso: t.seeAlso, start: t.startCanvas, service: t.service ? R(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 };
|
@@ -343,10 +343,10 @@ function mt(t) {
|
|
343
343
|
return m({ ...d(t), ...y(t), ...C(t), items: t.members });
|
344
344
|
}
|
345
345
|
function gt(t) {
|
346
|
-
let e = [], r = [], i;
|
347
|
-
for (let
|
348
|
-
let
|
349
|
-
return r.length && (
|
346
|
+
let e = [], r = [], i, s;
|
347
|
+
for (let a of t.sequences || []) console.log(a), a.canvases.length && e.push(...a.canvases), a.behavior && r.push(...a.behavior), a.viewingDirection && (s = a.viewingDirection), a.startCanvas && (i = a.startCanvas);
|
348
|
+
let n = d(t);
|
349
|
+
return r.length && (n.behavior ? n.behavior.push(...r) : n.behavior = r), m({ ...n, ...y(t), ...C(t), viewingDirection: s, start: i, items: e, structures: dt(t.structures) });
|
350
350
|
}
|
351
351
|
function dt(t) {
|
352
352
|
if (!t) return t;
|
@@ -366,7 +366,7 @@ function At(t) {
|
|
366
366
|
return m({ ...d(t), ...y(t), ...C(t), items: t.resources && t.resources.length ? t.resources : void 0 });
|
367
367
|
}
|
368
368
|
function Ct(t) {
|
369
|
-
return !t.canvases || t.canvases.length === 0 ? { canvases: [], behavior: [] } : { canvases: t.canvases, behavior: t.viewingHint ? [t.viewingHint] : [], startCanvas: t.startCanvas };
|
369
|
+
return !t.canvases || t.canvases.length === 0 ? { canvases: [], behavior: [] } : { canvases: t.canvases, behavior: t.viewingHint ? [t.viewingHint] : [], viewingDirection: t.viewingDirection, startCanvas: t.startCanvas };
|
370
370
|
}
|
371
371
|
function bt(t) {
|
372
372
|
function e(r) {
|
@@ -401,8 +401,8 @@ function Lt(t) {
|
|
401
401
|
return m({ ...d(t), ...y(t), ...C(t), items: t.members });
|
402
402
|
}
|
403
403
|
function wt(t) {
|
404
|
-
let { "@id": e, "@type": r, "@context": i, profile: s, ...n } = t,
|
405
|
-
return e && (
|
404
|
+
let { "@id": e, "@type": r, "@context": i, profile: s, ...n } = t, a = {};
|
405
|
+
return e && (a["@id"] = e), a["@type"] = P(t), a["@type"] === "unknown" && (i && i.length && (a["@context"] = i), a["@type"] = "Service"), s && (a.profile = Y(s)), m({ ...a, ...n });
|
406
406
|
}
|
407
407
|
function It(t) {
|
408
408
|
return m({ ...d(t), ...y(t), ...C(t) });
|
@@ -421,7 +421,7 @@ function k(t) {
|
|
421
421
|
function $(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
|
-
function
|
424
|
+
function T(...t) {
|
425
425
|
return (e) => t.reduce((r, i) => i(r), e);
|
426
426
|
}
|
427
427
|
var q = ["Collection", "Manifest", "Canvas", "AnnotationPage", "AnnotationCollection", "Annotation", "ContentResource", "Range", "Service", "Selector", "Agent"];
|
@@ -441,16 +441,16 @@ function Tt(t, e) {
|
|
441
441
|
}
|
442
442
|
var O = class re {
|
443
443
|
constructor(e, r = {}) {
|
444
|
-
A(this, "traversals"), A(this, "options"), A(this, "_traverseManifest",
|
444
|
+
A(this, "traversals"), A(this, "options"), A(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))), A(this, "_traverseCanvas", T(this.traverseCanvasItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseInlineAnnotationPages.bind(this))), A(this, "_traverseAnnotationPage", T(this.traverseAnnotationPageItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this))), A(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
447
|
return new re({ 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 = R(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 = R(e.service).map((r) => this.traverseService(r))), e.services && (e.services = R(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 = R(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 && ($(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,7 +498,7 @@ 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 = R(e.service || []).map((r) => this.traverseService(r, e))), e;
|
502
502
|
}
|
503
503
|
traverseContentResource(e, r) {
|
504
504
|
return e.type === "Choice" && (e.items = e.items.map((i) => this.traverseContentResource(i, e))), $(e) ? this.traverseSpecificResource(e, "ContentResource") : this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)), { parent: r }, this.traversals.contentResource);
|
@@ -518,13 +518,13 @@ var O = class re {
|
|
518
518
|
}
|
519
519
|
traverseType(e, r, i) {
|
520
520
|
return i.reduce((s, n) => {
|
521
|
-
let
|
522
|
-
return typeof
|
521
|
+
let a = n(s, r);
|
522
|
+
return typeof a > "u" && !this.options.allowUndefinedReturn ? s : a;
|
523
523
|
}, e);
|
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 = R(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);
|
@@ -556,16 +556,16 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
556
556
|
const e = f(t, "type"), r = f(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((o) => s.findIndex((c) => o.toString().includes(c))).filter((o) => o > -1).sort((o, c) => c - o)[0] };
|
560
560
|
} else if (e || r)
|
561
561
|
return { majorVersion: 3, profileLevel: parseInt(t.profile) };
|
562
562
|
}, _ = (t, e, r) => {
|
563
563
|
const i = f(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
|
567
|
-
if (
|
568
|
-
return `${i}/full/${
|
566
|
+
const a = t.sizes.sort((o, c) => c.width * c.height - o.width * o.height).filter((o) => o.width * o.height >= e * r)[0];
|
567
|
+
if (a)
|
568
|
+
return `${i}/full/${a.width},${a.height}/0/default.jpg`;
|
569
569
|
}
|
570
570
|
return `${i}/full/full/0/default.jpg`;
|
571
571
|
}
|
@@ -573,8 +573,8 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
573
573
|
}, xt = (t, e, r) => {
|
574
574
|
const i = f(t, "id"), s = t.profile || "";
|
575
575
|
if (typeof s == "string" && (s.includes("level0") || s.includes("level:0"))) return;
|
576
|
-
const { x:
|
577
|
-
return `${i}/${v}/!${l},${
|
576
|
+
const { x: a, y: o, w: c, h } = e, p = c / h, u = p < 1, w = Math.ceil(u ? r / p : r), l = Math.ceil(u ? r : r / p), v = `${Math.round(a)},${Math.round(o)},${Math.round(c)},${Math.round(h)}`;
|
577
|
+
return `${i}/${v}/!${l},${w}/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,37 @@ 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,
|
585
|
+
const n = i / s, a = n < 1, o = Math.ceil(a ? r / n : r), c = Math.ceil(a ? r : r / n);
|
586
586
|
if (t.thumbnail && t.thumbnail.length > 0) {
|
587
587
|
const h = t.thumbnail[0];
|
588
588
|
if ("service" in h && Array.isArray(h.service)) {
|
589
589
|
const p = h.service.find((u) => ie(u));
|
590
590
|
if (p)
|
591
|
-
return _(p, c,
|
591
|
+
return _(p, c, o);
|
592
592
|
}
|
593
593
|
if ("id" in h) return h.id;
|
594
594
|
}
|
595
595
|
for (const h of e) {
|
596
596
|
if (h.type === "dynamic" || h.type === "level0")
|
597
|
-
return _(h.service, c,
|
597
|
+
return _(h.service, c, o);
|
598
598
|
if (h.type === "static")
|
599
599
|
return h.url;
|
600
600
|
}
|
601
601
|
}, ne = (t) => t.endsWith("/info.json") ? t : `${t.endsWith("/") ? t : `${t}/`}info.json`, jt = (t) => {
|
602
|
-
const { format: e, height: r, width: i } = t, s = f(t, "id"), n = (t.service || []).find(ie),
|
603
|
-
if (
|
604
|
-
const
|
602
|
+
const { format: e, height: r, width: i } = t, s = f(t, "id"), n = (t.service || []).find(ie), a = n ? se(n) : void 0;
|
603
|
+
if (a) {
|
604
|
+
const o = {
|
605
605
|
source: t,
|
606
|
-
type:
|
606
|
+
type: a.profileLevel === 0 ? "level0" : "dynamic",
|
607
607
|
service: n,
|
608
608
|
width: i,
|
609
609
|
height: r,
|
610
|
-
majorVersion:
|
610
|
+
majorVersion: a.majorVersion,
|
611
611
|
serviceUrl: ne(f(n, "id"))
|
612
612
|
};
|
613
|
-
return
|
614
|
-
...
|
615
|
-
getRegionURL: $t(
|
613
|
+
return a.profileLevel === 0 ? o : {
|
614
|
+
...o,
|
615
|
+
getRegionURL: $t(o)
|
616
616
|
};
|
617
617
|
} else
|
618
618
|
return {
|
@@ -628,30 +628,30 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
628
628
|
return new O({
|
629
629
|
annotation: [(i) => {
|
630
630
|
if (i.motivation === "painting" || !i.motivation) {
|
631
|
-
const n = (i.body ? Array.isArray(i.body) ? i.body : [i.body] : []).filter((
|
632
|
-
e.push(...n.map((
|
631
|
+
const n = (i.body ? Array.isArray(i.body) ? i.body : [i.body] : []).filter((a) => a.type === "Image");
|
632
|
+
e.push(...n.map((a) => jt(a)));
|
633
633
|
}
|
634
634
|
}]
|
635
635
|
}).traverseCanvas(t), e;
|
636
636
|
}, Pt = (t) => () => {
|
637
|
-
const e = /* @__PURE__ */ new Map(), r = (
|
637
|
+
const e = /* @__PURE__ */ new Map(), r = (o, c, h = 0) => {
|
638
638
|
const p = {
|
639
|
-
id:
|
639
|
+
id: o.id,
|
640
640
|
type: "range",
|
641
|
-
source:
|
641
|
+
source: o,
|
642
642
|
children: [],
|
643
643
|
navItems: [],
|
644
644
|
navSections: [],
|
645
645
|
parent: c,
|
646
646
|
level: h,
|
647
|
-
getLabel:
|
647
|
+
getLabel: o.getLabel
|
648
648
|
};
|
649
|
-
|
649
|
+
o.items && o.items.length > 0 && o.items.forEach((v) => {
|
650
650
|
if (v.source.type === "Range") {
|
651
|
-
const
|
652
|
-
p.children.push(
|
653
|
-
} else
|
654
|
-
|
651
|
+
const S = r(v, p, h + 1);
|
652
|
+
p.children.push(S);
|
653
|
+
} else {
|
654
|
+
const b = {
|
655
655
|
id: v.id,
|
656
656
|
type: "canvas",
|
657
657
|
source: v,
|
@@ -661,20 +661,22 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
661
661
|
parent: p,
|
662
662
|
level: h + 1,
|
663
663
|
getLabel: v.getLabel
|
664
|
-
}
|
664
|
+
};
|
665
|
+
p.children.push(b), e.set(b.id, b);
|
666
|
+
}
|
665
667
|
});
|
666
|
-
const u = p.children.map((v) => v.type === "canvas" ? v.source : v.children.length === 1 && v.children[0].type === "canvas" ? v.children[0].source : v.source),
|
667
|
-
return p.navItems.push(...
|
668
|
+
const u = p.children.map((v) => v.type === "canvas" ? v.source : v.children.length === 1 && v.children[0].type === "canvas" ? v.children[0].source : v.source), w = u.filter((v) => v.source.type === "Canvas"), l = u.filter((v) => v.source.type === "Range");
|
669
|
+
return p.navItems.push(...w), p.navSections.push(...l), e.set(p.id, p), p;
|
668
670
|
};
|
669
|
-
return { root: t.filter((
|
671
|
+
return { root: t.filter((o) => {
|
670
672
|
var c;
|
671
|
-
return (c =
|
672
|
-
}).map((
|
673
|
-
const c = e.get(
|
673
|
+
return (c = o.source.behavior) == null ? void 0 : c.includes("top");
|
674
|
+
}).map((o) => r(o, void 0)), getBreadcrumbs: (o) => {
|
675
|
+
const c = e.get(o);
|
674
676
|
if (!c) return [];
|
675
677
|
const h = (p, u = []) => p.parent ? h(p.parent, [p, ...u]) : [p, ...u];
|
676
678
|
return h(c);
|
677
|
-
}, getNode: (
|
679
|
+
}, getNode: (o) => e.get(o) };
|
678
680
|
}, Ot = async (t) => {
|
679
681
|
try {
|
680
682
|
new URL(t);
|
@@ -741,11 +743,11 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
741
743
|
return f(t, "type").includes("Collection") ? {
|
742
744
|
type: "collection",
|
743
745
|
url: e || i,
|
744
|
-
resource:
|
746
|
+
resource: Dt(t, s)
|
745
747
|
} : {
|
746
748
|
type: "manifest",
|
747
749
|
url: e || i,
|
748
|
-
resource:
|
750
|
+
resource: Ut(t, s)
|
749
751
|
};
|
750
752
|
}
|
751
753
|
if (r.includes("image/2") || r.includes("image/3")) {
|
@@ -765,15 +767,15 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
765
767
|
code: "INVALID_MANIFEST",
|
766
768
|
message: "JSON resource is not a recognized IIIF format"
|
767
769
|
};
|
768
|
-
},
|
770
|
+
}, Dt = (t, e) => {
|
769
771
|
const r = (n) => {
|
770
|
-
const
|
772
|
+
const a = [];
|
771
773
|
return new O({
|
772
|
-
manifest: [(c) =>
|
773
|
-
}).traverseCollection(n),
|
774
|
+
manifest: [(c) => a.push(c)]
|
775
|
+
}).traverseCollection(n), a.map((c) => ({
|
774
776
|
id: c.id,
|
775
777
|
type: c.type,
|
776
|
-
getLabel:
|
778
|
+
getLabel: I(c),
|
777
779
|
source: c
|
778
780
|
}));
|
779
781
|
}, i = e === 2 ? te(t) : t, s = r(i);
|
@@ -782,21 +784,21 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
782
784
|
id: i.id,
|
783
785
|
majorVersion: e,
|
784
786
|
items: s,
|
785
|
-
getLabel:
|
787
|
+
getLabel: I(i),
|
786
788
|
getMetadata: M(i)
|
787
789
|
};
|
788
|
-
},
|
789
|
-
const r = (
|
790
|
-
const
|
790
|
+
}, Ut = (t, e) => {
|
791
|
+
const r = (a) => {
|
792
|
+
const o = [], c = [];
|
791
793
|
new O({
|
792
794
|
canvas: [(l) => {
|
793
|
-
l.items &&
|
795
|
+
l.items && o.push(l);
|
794
796
|
}],
|
795
797
|
range: [(l) => {
|
796
798
|
l.type === "Range" && c.push(l);
|
797
799
|
}]
|
798
|
-
}).traverseManifest(
|
799
|
-
const p =
|
800
|
+
}).traverseManifest(a);
|
801
|
+
const p = o.map((l) => {
|
800
802
|
const v = kt(l);
|
801
803
|
return {
|
802
804
|
source: l,
|
@@ -805,23 +807,23 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
805
807
|
height: l.height,
|
806
808
|
images: v,
|
807
809
|
annotations: l.annotations || [],
|
808
|
-
getLabel:
|
810
|
+
getLabel: I(l),
|
809
811
|
getMetadata: M(l),
|
810
812
|
getThumbnailURL: Mt(l, v)
|
811
813
|
};
|
812
814
|
}), u = (l) => {
|
813
|
-
const v = l.items || [],
|
815
|
+
const v = l.items || [], b = v.filter((g) => g.type === "Canvas").map((g) => p.find((x) => x.id === g.id)).filter(Boolean), S = v.filter((g) => g.type === "Range").map((g) => u(g)), oe = [...b, ...S];
|
814
816
|
return {
|
815
817
|
source: l,
|
816
818
|
id: l.id,
|
817
819
|
// Maintain original order
|
818
820
|
items: v.map((g) => oe.find((x) => x.id === g.id)),
|
819
|
-
canvases:
|
820
|
-
ranges:
|
821
|
-
getLabel:
|
821
|
+
canvases: b,
|
822
|
+
ranges: S,
|
823
|
+
getLabel: I(l)
|
822
824
|
};
|
823
|
-
},
|
824
|
-
return { canvases: p, ranges:
|
825
|
+
}, w = c.map((l) => u(l));
|
826
|
+
return { canvases: p, ranges: w };
|
825
827
|
}, i = e === 2 ? te(t) : t, { canvases: s, ranges: n } = r(i);
|
826
828
|
return {
|
827
829
|
source: i,
|
@@ -829,7 +831,7 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
829
831
|
majorVersion: e,
|
830
832
|
canvases: s,
|
831
833
|
structure: n,
|
832
|
-
getLabel:
|
834
|
+
getLabel: I(i),
|
833
835
|
getMetadata: M(i),
|
834
836
|
getTableOfContents: Pt(n)
|
835
837
|
};
|
@@ -849,7 +851,7 @@ export {
|
|
849
851
|
qt as Cozy,
|
850
852
|
_ as getImageURLFromService,
|
851
853
|
kt as getImages,
|
852
|
-
|
854
|
+
I as getLabel,
|
853
855
|
M as getMetadata,
|
854
856
|
f as getPropertyValue,
|
855
857
|
$t as getRegionURL,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "cozy-iiif",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.3",
|
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",
|
@@ -28,12 +28,12 @@
|
|
28
28
|
"./level-0": "./dist/level-0/index.js"
|
29
29
|
},
|
30
30
|
"devDependencies": {
|
31
|
-
"vite": "^6.
|
32
|
-
"vite-plugin-dts": "^4.5.
|
33
|
-
"vitest": "^3.1.
|
31
|
+
"vite": "^6.3.5",
|
32
|
+
"vite-plugin-dts": "^4.5.4",
|
33
|
+
"vitest": "^3.1.4"
|
34
34
|
},
|
35
35
|
"dependencies": {
|
36
|
-
"@iiif/parser": "^2.1.
|
36
|
+
"@iiif/parser": "^2.1.8",
|
37
37
|
"@iiif/presentation-3": "^2.2.3",
|
38
38
|
"p-throttle": "^7.0.0",
|
39
39
|
"uuid": "^11.1.0"
|
package/src/core/manifest.ts
CHANGED
@@ -26,7 +26,7 @@ export const getTableOfContents = (ranges: CozyRange[]) => (): CozyTOC => {
|
|
26
26
|
} else {
|
27
27
|
// This child is Canvas, i.e. a TOCNode with
|
28
28
|
// no further children.
|
29
|
-
|
29
|
+
const canvasChild: CozyTOCNode = {
|
30
30
|
id: item.id,
|
31
31
|
type: 'canvas',
|
32
32
|
source: item as CozyCanvas,
|
@@ -36,7 +36,11 @@ export const getTableOfContents = (ranges: CozyRange[]) => (): CozyTOC => {
|
|
36
36
|
parent: node,
|
37
37
|
level: level + 1,
|
38
38
|
getLabel: item.getLabel
|
39
|
-
}
|
39
|
+
};
|
40
|
+
|
41
|
+
// Add leaf node to children & lookup index
|
42
|
+
node.children.push(canvasChild);
|
43
|
+
index.set(canvasChild.id, canvasChild);
|
40
44
|
}
|
41
45
|
});
|
42
46
|
}
|