cozy-iiif 0.2.1 → 0.2.2
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 +129 -124
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/core/manifest.ts +16 -1
- package/src/types.ts +2 -0
- package/test/Cozy.test.ts +3 -3
- package/test/core/fixtures.ts +2 -0
- package/test/core/manifest.test.ts +26 -0
- package/test/{annotations → helpers}/import-annotations.test.ts +3 -2
- /package/test/{annotations → helpers}/fixtures.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { g as
|
|
1
|
+
import { g as f, a as M, b as w } 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
|
-
function
|
|
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
|
}
|
|
@@ -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", 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, Ue, De, Ee, Ne, qe, _e, Ve, Fe, We, Be, He, Je, Ge, ze, Ke, Qe, Xe, Ye],
|
|
155
|
+
}, Ue = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", De = "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, Ue, De, 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 [];
|
|
@@ -237,7 +237,7 @@ function D(t) {
|
|
|
237
237
|
return t;
|
|
238
238
|
}
|
|
239
239
|
var nt = ["Collection", "Manifest", "Annotation", "AnnotationPage", "Range", "Service"];
|
|
240
|
-
function
|
|
240
|
+
function P(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);
|
|
@@ -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 o of n) {
|
|
285
|
+
let a = o ? ot(o) : void 0;
|
|
286
|
+
if (a && (a.indexOf("creativecommons.org") !== -1 || a.indexOf("rightsstatements.org") !== -1)) {
|
|
287
|
+
a.startsWith("https://") ? i = `http://${a.slice(8)}` : i = a;
|
|
288
288
|
continue;
|
|
289
289
|
}
|
|
290
|
-
|
|
290
|
+
a && s.push({ label: { [r]: [e] }, value: { [r]: [a] } });
|
|
291
291
|
}
|
|
292
292
|
return [i, s];
|
|
293
293
|
}
|
|
@@ -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(D) : t.motivation && (r = D(t.motivation)), { "@context": t["@context"] ? pt(t["@context"]) : void 0, id: (t["@id"] || Z(t)).trim(), type:
|
|
314
|
+
return Array.isArray(t.motivation) ? r = t.motivation.map(D) : t.motivation && (r = D(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 ? R(t.label) : void 0, requiredStatement: t.attribution ? { label: R(
|
|
318
|
+
return { rights: e, metadata: i.length ? i : void 0, label: t.label ? R(t.label) : void 0, requiredStatement: t.attribution ? { label: R(j.attributionLabel), value: R(t.attribution) } : void 0, navDate: t.navDate, summary: t.description ? R(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: P(i) });
|
|
333
333
|
return r.length ? r : void 0;
|
|
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:
|
|
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: R(j.providerName) }] : void 0, partOf: ut(t), rendering: t.rendering, seeAlso: t.seeAlso, start: t.startCanvas, service: t.service ? b(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 m({ ...d(t), ...y(t), ...C(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
348
|
let s = d(t);
|
|
349
|
-
return r.length && (s.behavior ? s.behavior.push(...r) : s.behavior = r),
|
|
349
|
+
return r.length && (s.behavior ? s.behavior.push(...r) : s.behavior = r), m({ ...s, ...y(t), ...C(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 m({ ...d(t), ...y(t), ...C(t), annotations: t.otherContent && t.otherContent.length ? t.otherContent : void 0, items: t.images && t.images.length ? [{ id: Z(t, "annotation-page"), type: "AnnotationPage", items: t.images }] : void 0 });
|
|
364
364
|
}
|
|
365
365
|
function At(t) {
|
|
366
|
-
return
|
|
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
369
|
return !t.canvases || t.canvases.length === 0 ? { canvases: [], behavior: [] } : { canvases: t.canvases, behavior: t.viewingHint ? [t.viewingHint] : [], startCanvas: t.startCanvas };
|
|
@@ -381,44 +381,44 @@ 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: k(r.selector) };
|
|
385
385
|
} else return encodeURI(r["@id"]).trim();
|
|
386
386
|
}
|
|
387
|
-
return
|
|
387
|
+
return m({ ...d(t), ...y(t), ...C(t), target: e(t.on), body: Array.isArray(t.resource) ? t.resource.map(N) : N(t.resource) });
|
|
388
388
|
}
|
|
389
389
|
function N(t) {
|
|
390
390
|
return t.type === "Choice" ? t : ee(t);
|
|
391
391
|
}
|
|
392
392
|
function ee(t) {
|
|
393
393
|
let e = t;
|
|
394
|
-
return
|
|
394
|
+
return m({ ...d(e), ...y(e), ...C(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), m({ ...d(t), ...y(t), items: e });
|
|
399
399
|
}
|
|
400
400
|
function Lt(t) {
|
|
401
|
-
return
|
|
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, o = {};
|
|
405
|
+
return e && (o["@id"] = e), o["@type"] = P(t), o["@type"] === "unknown" && (i && i.length && (o["@context"] = i), o["@type"] = "Service"), s && (o.profile = Y(s)), m({ ...o, ...n });
|
|
406
406
|
}
|
|
407
407
|
function It(t) {
|
|
408
|
-
return
|
|
408
|
+
return m({ ...d(t), ...y(t), ...C(t) });
|
|
409
409
|
}
|
|
410
410
|
var St = new Oe({ collection: [mt], manifest: [gt], canvas: [yt], annotationList: [At], sequence: [Ct], annotation: [bt], contentResource: [ee], choice: [Rt], range: [Lt], service: [wt], layer: [It] });
|
|
411
411
|
function te(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 k(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 [k(t.default), ...(Array.isArray(t.item) ? t.item : [t.item]).map(k)];
|
|
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 $(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 S(...t) {
|
|
@@ -439,7 +439,7 @@ function Tt(t, e) {
|
|
|
439
439
|
if (t.profile) return "Service";
|
|
440
440
|
throw new Error("Resource type is not known");
|
|
441
441
|
}
|
|
442
|
-
var
|
|
442
|
+
var O = class re {
|
|
443
443
|
constructor(e, r = {}) {
|
|
444
444
|
A(this, "traversals"), A(this, "options"), A(this, "_traverseManifest", S(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", S(this.traverseCanvasItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseInlineAnnotationPages.bind(this))), A(this, "_traverseAnnotationPage", S(this.traverseAnnotationPageItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this))), A(this, "_traverseRange", S(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
|
}
|
|
@@ -450,7 +450,7 @@ var P = class re {
|
|
|
450
450
|
return e.thumbnail && (e.thumbnail = b(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 = b(e.service).map((r) => this.traverseService(r))), e.services && (e.services = b(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 = b(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 && (
|
|
453
|
+
return e.seeAlso && (e.seeAlso = e.seeAlso.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.service && (e.service = b(e.service).map((r) => this.traverseService(r))), e.services && (e.services = b(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 = b(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;
|
|
@@ -501,14 +501,14 @@ var P = class re {
|
|
|
501
501
|
return typeof e == "string" || !e || e && e.service && (e.service = b(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))), $(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) : $(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);
|
|
@@ -518,8 +518,8 @@ var P = class re {
|
|
|
518
518
|
}
|
|
519
519
|
traverseType(e, r, i) {
|
|
520
520
|
return i.reduce((s, n) => {
|
|
521
|
-
let
|
|
522
|
-
return typeof
|
|
521
|
+
let o = n(s, r);
|
|
522
|
+
return typeof o > "u" && !this.options.allowUndefinedReturn ? s : o;
|
|
523
523
|
}, e);
|
|
524
524
|
}
|
|
525
525
|
traverseService(e, r) {
|
|
@@ -552,29 +552,29 @@ var P = class re {
|
|
|
552
552
|
}
|
|
553
553
|
}
|
|
554
554
|
};
|
|
555
|
-
const ie = (t) =>
|
|
556
|
-
const e =
|
|
555
|
+
const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.profile.toString().includes("iiif.io/api/image/"), se = (t) => {
|
|
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((a) => s.findIndex((c) => a.toString().includes(c))).filter((a) => a > -1).sort((a, c) => c - a)[0] };
|
|
560
560
|
} else if (e || r)
|
|
561
561
|
return { majorVersion: 3, profileLevel: parseInt(t.profile) };
|
|
562
562
|
}, _ = (t, e, r) => {
|
|
563
|
-
const i =
|
|
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 o = t.sizes.sort((a, c) => c.width * c.height - a.width * a.height).filter((a) => a.width * a.height >= e * r)[0];
|
|
567
|
+
if (o)
|
|
568
|
+
return `${i}/full/${o.width},${o.height}/0/default.jpg`;
|
|
569
569
|
}
|
|
570
570
|
return `${i}/full/full/0/default.jpg`;
|
|
571
571
|
}
|
|
572
572
|
return `${i}/full/!${e},${r}/0/default.jpg`;
|
|
573
573
|
}, xt = (t, e, r) => {
|
|
574
|
-
const i =
|
|
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}/${
|
|
576
|
+
const { x: o, y: a, w: c, h } = e, p = c / h, u = p < 1, L = Math.ceil(u ? r / p : r), l = Math.ceil(u ? r : r / p), v = `${Math.round(o)},${Math.round(a)},${Math.round(c)},${Math.round(h)}`;
|
|
577
|
+
return `${i}/${v}/!${l},${L}/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) => h(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, o = n < 1, a = Math.ceil(o ? r / n : r), c = 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 h = t.thumbnail[0];
|
|
588
|
+
if ("service" in h && Array.isArray(h.service)) {
|
|
589
|
+
const p = h.service.find((u) => ie(u));
|
|
590
|
+
if (p)
|
|
591
|
+
return _(p, c, a);
|
|
592
592
|
}
|
|
593
|
-
if ("id" in
|
|
593
|
+
if ("id" in h) return h.id;
|
|
594
594
|
}
|
|
595
|
-
for (const
|
|
596
|
-
if (
|
|
597
|
-
return _(
|
|
598
|
-
if (
|
|
599
|
-
return
|
|
595
|
+
for (const h of e) {
|
|
596
|
+
if (h.type === "dynamic" || h.type === "level0")
|
|
597
|
+
return _(h.service, c, a);
|
|
598
|
+
if (h.type === "static")
|
|
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 =
|
|
603
|
-
if (
|
|
604
|
-
const
|
|
602
|
+
const { format: e, height: r, width: i } = t, s = f(t, "id"), n = (t.service || []).find(ie), o = n ? se(n) : void 0;
|
|
603
|
+
if (o) {
|
|
604
|
+
const a = {
|
|
605
605
|
source: t,
|
|
606
|
-
type:
|
|
606
|
+
type: o.profileLevel === 0 ? "level0" : "dynamic",
|
|
607
607
|
service: n,
|
|
608
608
|
width: i,
|
|
609
609
|
height: r,
|
|
610
|
-
majorVersion:
|
|
611
|
-
serviceUrl: ne(
|
|
610
|
+
majorVersion: o.majorVersion,
|
|
611
|
+
serviceUrl: ne(f(n, "id"))
|
|
612
612
|
};
|
|
613
|
-
return
|
|
614
|
-
...
|
|
615
|
-
getRegionURL: $t(
|
|
613
|
+
return o.profileLevel === 0 ? a : {
|
|
614
|
+
...a,
|
|
615
|
+
getRegionURL: $t(a)
|
|
616
616
|
};
|
|
617
617
|
} else
|
|
618
618
|
return {
|
|
@@ -625,16 +625,16 @@ const ie = (t) => h(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
|
625
625
|
};
|
|
626
626
|
}, kt = (t) => {
|
|
627
627
|
const e = [];
|
|
628
|
-
return new
|
|
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((o) => o.type === "Image");
|
|
632
|
+
e.push(...n.map((o) => jt(o)));
|
|
633
633
|
}
|
|
634
634
|
}]
|
|
635
635
|
}).traverseCanvas(t), e;
|
|
636
636
|
}, Pt = (t) => () => {
|
|
637
|
-
const e = /* @__PURE__ */ new Map(), r = (a, c,
|
|
637
|
+
const e = /* @__PURE__ */ new Map(), r = (a, c, h = 0) => {
|
|
638
638
|
const p = {
|
|
639
639
|
id: a.id,
|
|
640
640
|
type: "range",
|
|
@@ -643,33 +643,38 @@ const ie = (t) => h(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
|
643
643
|
navItems: [],
|
|
644
644
|
navSections: [],
|
|
645
645
|
parent: c,
|
|
646
|
-
level:
|
|
646
|
+
level: h,
|
|
647
647
|
getLabel: a.getLabel
|
|
648
648
|
};
|
|
649
|
-
a.items && a.items.length > 0 && a.items.forEach((
|
|
650
|
-
if (
|
|
651
|
-
const I = r(
|
|
649
|
+
a.items && a.items.length > 0 && a.items.forEach((v) => {
|
|
650
|
+
if (v.source.type === "Range") {
|
|
651
|
+
const I = r(v, p, h + 1);
|
|
652
652
|
p.children.push(I);
|
|
653
653
|
} else
|
|
654
654
|
p.children.push({
|
|
655
|
-
id:
|
|
655
|
+
id: v.id,
|
|
656
656
|
type: "canvas",
|
|
657
|
-
source:
|
|
657
|
+
source: v,
|
|
658
658
|
children: [],
|
|
659
659
|
navItems: [],
|
|
660
660
|
navSections: [],
|
|
661
661
|
parent: p,
|
|
662
|
-
level:
|
|
663
|
-
getLabel:
|
|
662
|
+
level: h + 1,
|
|
663
|
+
getLabel: v.getLabel
|
|
664
664
|
});
|
|
665
665
|
});
|
|
666
|
-
const
|
|
667
|
-
return p.navItems.push(...
|
|
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), L = u.filter((v) => v.source.type === "Canvas"), l = u.filter((v) => v.source.type === "Range");
|
|
667
|
+
return p.navItems.push(...L), p.navSections.push(...l), e.set(p.id, p), p;
|
|
668
668
|
};
|
|
669
669
|
return { root: t.filter((a) => {
|
|
670
670
|
var c;
|
|
671
671
|
return (c = a.source.behavior) == null ? void 0 : c.includes("top");
|
|
672
|
-
}).map((a) => r(a, void 0)),
|
|
672
|
+
}).map((a) => r(a, void 0)), getBreadcrumbs: (a) => {
|
|
673
|
+
const c = e.get(a);
|
|
674
|
+
if (!c) return [];
|
|
675
|
+
const h = (p, u = []) => p.parent ? h(p.parent, [p, ...u]) : [p, ...u];
|
|
676
|
+
return h(c);
|
|
677
|
+
}, getNode: (a) => e.get(a) };
|
|
673
678
|
}, Ot = async (t) => {
|
|
674
679
|
try {
|
|
675
680
|
new URL(t);
|
|
@@ -724,7 +729,7 @@ const ie = (t) => h(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
|
724
729
|
code: "INVALID_MANIFEST",
|
|
725
730
|
message: "Missing @context"
|
|
726
731
|
};
|
|
727
|
-
const i =
|
|
732
|
+
const i = f(t, "id");
|
|
728
733
|
if (!i)
|
|
729
734
|
return {
|
|
730
735
|
type: "error",
|
|
@@ -733,7 +738,7 @@ const ie = (t) => h(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
|
733
738
|
};
|
|
734
739
|
if (r.includes("presentation/2") || r.includes("presentation/3")) {
|
|
735
740
|
const s = r.includes("presentation/2") ? 2 : 3;
|
|
736
|
-
return
|
|
741
|
+
return f(t, "type").includes("Collection") ? {
|
|
737
742
|
type: "collection",
|
|
738
743
|
url: e || i,
|
|
739
744
|
resource: Ut(t, s)
|
|
@@ -762,14 +767,14 @@ const ie = (t) => h(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
|
762
767
|
};
|
|
763
768
|
}, Ut = (t, e) => {
|
|
764
769
|
const r = (n) => {
|
|
765
|
-
const
|
|
766
|
-
return new
|
|
767
|
-
manifest: [(
|
|
768
|
-
}).traverseCollection(n),
|
|
769
|
-
id:
|
|
770
|
-
type:
|
|
771
|
-
getLabel: w(
|
|
772
|
-
source:
|
|
770
|
+
const o = [];
|
|
771
|
+
return new O({
|
|
772
|
+
manifest: [(c) => o.push(c)]
|
|
773
|
+
}).traverseCollection(n), o.map((c) => ({
|
|
774
|
+
id: c.id,
|
|
775
|
+
type: c.type,
|
|
776
|
+
getLabel: w(c),
|
|
777
|
+
source: c
|
|
773
778
|
}));
|
|
774
779
|
}, i = e === 2 ? te(t) : t, s = r(i);
|
|
775
780
|
return {
|
|
@@ -778,45 +783,45 @@ const ie = (t) => h(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
|
778
783
|
majorVersion: e,
|
|
779
784
|
items: s,
|
|
780
785
|
getLabel: w(i),
|
|
781
|
-
getMetadata:
|
|
786
|
+
getMetadata: M(i)
|
|
782
787
|
};
|
|
783
788
|
}, Dt = (t, e) => {
|
|
784
|
-
const r = (
|
|
785
|
-
const
|
|
786
|
-
new
|
|
787
|
-
canvas: [(
|
|
788
|
-
|
|
789
|
+
const r = (o) => {
|
|
790
|
+
const a = [], c = [];
|
|
791
|
+
new O({
|
|
792
|
+
canvas: [(l) => {
|
|
793
|
+
l.items && a.push(l);
|
|
789
794
|
}],
|
|
790
|
-
range: [(
|
|
791
|
-
|
|
795
|
+
range: [(l) => {
|
|
796
|
+
l.type === "Range" && c.push(l);
|
|
792
797
|
}]
|
|
793
|
-
}).traverseManifest(
|
|
794
|
-
const
|
|
795
|
-
const
|
|
798
|
+
}).traverseManifest(o);
|
|
799
|
+
const p = a.map((l) => {
|
|
800
|
+
const v = kt(l);
|
|
796
801
|
return {
|
|
797
|
-
source:
|
|
798
|
-
id:
|
|
799
|
-
width:
|
|
800
|
-
height:
|
|
801
|
-
images:
|
|
802
|
-
annotations:
|
|
803
|
-
getLabel: w(
|
|
804
|
-
getMetadata:
|
|
805
|
-
getThumbnailURL: Mt(
|
|
802
|
+
source: l,
|
|
803
|
+
id: l.id,
|
|
804
|
+
width: l.width,
|
|
805
|
+
height: l.height,
|
|
806
|
+
images: v,
|
|
807
|
+
annotations: l.annotations || [],
|
|
808
|
+
getLabel: w(l),
|
|
809
|
+
getMetadata: M(l),
|
|
810
|
+
getThumbnailURL: Mt(l, v)
|
|
806
811
|
};
|
|
807
|
-
}),
|
|
808
|
-
const
|
|
812
|
+
}), u = (l) => {
|
|
813
|
+
const v = l.items || [], T = v.filter((g) => g.type === "Canvas").map((g) => p.find((x) => x.id === g.id)).filter(Boolean), I = v.filter((g) => g.type === "Range").map((g) => u(g)), oe = [...T, ...I];
|
|
809
814
|
return {
|
|
810
|
-
source:
|
|
811
|
-
id:
|
|
815
|
+
source: l,
|
|
816
|
+
id: l.id,
|
|
812
817
|
// Maintain original order
|
|
813
|
-
items:
|
|
814
|
-
canvases:
|
|
815
|
-
ranges:
|
|
816
|
-
getLabel: w(
|
|
818
|
+
items: v.map((g) => oe.find((x) => x.id === g.id)),
|
|
819
|
+
canvases: T,
|
|
820
|
+
ranges: I,
|
|
821
|
+
getLabel: w(l)
|
|
817
822
|
};
|
|
818
|
-
}, L =
|
|
819
|
-
return { canvases:
|
|
823
|
+
}, L = c.map((l) => u(l));
|
|
824
|
+
return { canvases: p, ranges: L };
|
|
820
825
|
}, i = e === 2 ? te(t) : t, { canvases: s, ranges: n } = r(i);
|
|
821
826
|
return {
|
|
822
827
|
source: i,
|
|
@@ -825,7 +830,7 @@ const ie = (t) => h(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
|
825
830
|
canvases: s,
|
|
826
831
|
structure: n,
|
|
827
832
|
getLabel: w(i),
|
|
828
|
-
getMetadata:
|
|
833
|
+
getMetadata: M(i),
|
|
829
834
|
getTableOfContents: Pt(n)
|
|
830
835
|
};
|
|
831
836
|
}, Et = (t) => {
|
|
@@ -837,7 +842,7 @@ const ie = (t) => h(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
|
837
842
|
width: e,
|
|
838
843
|
height: r,
|
|
839
844
|
majorVersion: i.majorVersion,
|
|
840
|
-
serviceUrl: ne(
|
|
845
|
+
serviceUrl: ne(f(t, "id"))
|
|
841
846
|
};
|
|
842
847
|
}, qt = { parse: ae, parseURL: Ot };
|
|
843
848
|
export {
|
|
@@ -845,8 +850,8 @@ export {
|
|
|
845
850
|
_ as getImageURLFromService,
|
|
846
851
|
kt as getImages,
|
|
847
852
|
w as getLabel,
|
|
848
|
-
|
|
849
|
-
|
|
853
|
+
M as getMetadata,
|
|
854
|
+
f as getPropertyValue,
|
|
850
855
|
$t as getRegionURL,
|
|
851
856
|
xt as getRegionURLFromService,
|
|
852
857
|
Ft as getStringValue,
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
package/src/core/manifest.ts
CHANGED
|
@@ -71,5 +71,20 @@ export const getTableOfContents = (ranges: CozyRange[]) => (): CozyTOC => {
|
|
|
71
71
|
|
|
72
72
|
const getNode = (id: string) => index.get(id);
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
const getBreadcrumbs = (id: string) => {
|
|
75
|
+
const thisNode = index.get(id);
|
|
76
|
+
if (!thisNode) return [];
|
|
77
|
+
|
|
78
|
+
const addParent = (node: CozyTOCNode, breadcrumbs: CozyTOCNode[] = []) => {
|
|
79
|
+
if (node.parent) {
|
|
80
|
+
return addParent(node.parent, [node, ...breadcrumbs]);
|
|
81
|
+
} else {
|
|
82
|
+
return [node, ...breadcrumbs];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return addParent(thisNode);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return { root, getBreadcrumbs, getNode };
|
|
75
90
|
}
|
package/src/types.ts
CHANGED
package/test/Cozy.test.ts
CHANGED
|
@@ -10,7 +10,7 @@ describe('Cozy', () => {
|
|
|
10
10
|
expect(result.type).toBe('collection');
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
it('should parse
|
|
13
|
+
it('should parse structures in presentation manifests', async () => {
|
|
14
14
|
const result = await Cozy.parseURL(WITH_STRUCTURES);
|
|
15
15
|
expect(result.type).toBe('manifest');
|
|
16
16
|
expect('resource' in result).toBeTruthy();
|
|
@@ -19,8 +19,8 @@ describe('Cozy', () => {
|
|
|
19
19
|
expect(manifest.structure.length > 0).toBeTruthy();
|
|
20
20
|
|
|
21
21
|
const tableOfContents = manifest.getTableOfContents();
|
|
22
|
-
expect(tableOfContents.length).toBe(1);
|
|
23
|
-
expect(tableOfContents[0].children.length).toBe(14);
|
|
22
|
+
expect(tableOfContents.root.length).toBe(1);
|
|
23
|
+
expect(tableOfContents.root[0].children.length).toBe(14);
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { Cozy, CozyManifest } from '../../src';
|
|
3
|
+
|
|
4
|
+
import { WITH_STRUCTURES } from './fixtures';
|
|
5
|
+
|
|
6
|
+
describe('manifest', () => {
|
|
7
|
+
|
|
8
|
+
it('should generate proper ToC breadcrumbs', async () => {
|
|
9
|
+
const result = await Cozy.parseURL(WITH_STRUCTURES);
|
|
10
|
+
expect(result.type).toBe('manifest');
|
|
11
|
+
expect('resource' in result).toBeTruthy();
|
|
12
|
+
|
|
13
|
+
const manifest = (result as any).resource as CozyManifest;
|
|
14
|
+
expect(manifest.structure.length > 0).toBeTruthy();
|
|
15
|
+
|
|
16
|
+
const toc = manifest.getTableOfContents();
|
|
17
|
+
|
|
18
|
+
const breadcrumbs = toc.getBreadcrumbs('https://lib.is/IE19255085/range/range-0-12-0.json');
|
|
19
|
+
|
|
20
|
+
expect(breadcrumbs.length).toBe(3);
|
|
21
|
+
expect(breadcrumbs[0].getLabel()).toBe('Table of Contents');
|
|
22
|
+
expect(breadcrumbs[1].getLabel()).toBe('Woodcuts full');
|
|
23
|
+
expect(breadcrumbs[2].getLabel()).toBe('f. X2v-f. X3r: woodcut full ')
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
2
|
import { Annotation } from '@iiif/presentation-3';
|
|
3
3
|
import { Cozy, CozyManifest } from '../../src';
|
|
4
|
+
import { importAnnotations } from '../../src/helpers';
|
|
4
5
|
|
|
5
6
|
import {
|
|
6
7
|
ANNOTATIONS,
|
|
@@ -21,7 +22,7 @@ describe('import-annotations', () => {
|
|
|
21
22
|
|
|
22
23
|
const annotations = ANNOTATIONS as Annotation[];
|
|
23
24
|
|
|
24
|
-
const modified =
|
|
25
|
+
const modified = importAnnotations(firstCanvas, annotations)
|
|
25
26
|
expect(modified.annotations.length).toBe(1);
|
|
26
27
|
});
|
|
27
28
|
|
|
@@ -37,7 +38,7 @@ describe('import-annotations', () => {
|
|
|
37
38
|
|
|
38
39
|
const annotations = ANNOTATIONS as Annotation[];
|
|
39
40
|
|
|
40
|
-
const modified =
|
|
41
|
+
const modified = importAnnotations(manifest, annotations, 'cozy');
|
|
41
42
|
expect(modified.canvases[0].annotations.length).toBe(1);
|
|
42
43
|
expect(modified.canvases[1].annotations.length).toBe(1);
|
|
43
44
|
});
|
|
File without changes
|