cozy-iiif 0.2.4 → 0.2.5
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 +173 -170
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/core/manifest.ts +6 -2
- package/src/types.ts +2 -0
package/dist/index.js
CHANGED
@@ -1,32 +1,32 @@
|
|
1
|
-
import { g as
|
1
|
+
import { g as m, a as j, b as S } from "./resource-DS2brz47.js";
|
2
2
|
import { c as Ft } 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",
|
4
|
-
function
|
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", z = "http://iiif.io/api/image/2/level2.json", K = "http://iiif.io/api/image/2/profiles/level2.json", we = "level0", Ie = "level1", Q = "level2", Se = "http://iiif.io/api/image/2/level0", Te = "http://iiif.io/api/image/2/level1", X = "http://iiif.io/api/image/2/level2", xe = [X, F, W, B, H, J, G, z, K, Q], $e = [Se, Te, X, ce, le, F, pe, ve, W, he, ue, B, fe, me, H, ge, de, ye, Ae, J, G, Ce, be, Re, Le, z, K, we, Ie, Q], 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), 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";
|
22
22
|
throw new Error("Resource type is not known");
|
23
23
|
}
|
24
|
-
var Oe = class
|
24
|
+
var Oe = class Y {
|
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 Y({ 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", 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, Ne, Ee, qe, _e, Ve, Fe, We, Be, He, Je, Ge, ze, Ke, Qe, Xe, Ye], 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 N(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 O(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
305
|
var E = 0;
|
306
|
-
function
|
306
|
+
function ee(t, e) {
|
307
307
|
let r = encodeURI(t.id || t["@id"] || "").trim();
|
308
308
|
return r && e ? `${r}/${e}` : r || (E++, `http://example.org/${t["@type"]}${e ? `/${e}` : ""}/${E}`);
|
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(N) : t.motivation && (r = N(t.motivation)), { "@context": t["@context"] ? pt(t["@context"]) : void 0, id: (t["@id"] || ee(t)).trim(), type: O(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: O(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(q) : q(t.resource) });
|
388
388
|
}
|
389
|
-
function
|
390
|
-
return t.type === "Choice" ? t :
|
389
|
+
function q(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"] = O(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 _ = ["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 = _.indexOf(t.type);
|
437
|
+
if (r !== -1) return _[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 U = 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
|
+
}, V = (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,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, 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 V(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 V(l.service, a, c);
|
598
|
+
if (l.type === "static")
|
599
|
+
return l.url;
|
600
600
|
}
|
601
|
-
},
|
602
|
-
const { format: e, height: r, width: i } = t, s =
|
601
|
+
}, ae = (t) => t.endsWith("/info.json") ? t : `${t.endsWith("/") ? t : `${t}/`}info.json`, jt = (t) => {
|
602
|
+
const { format: e, height: r, width: i } = t, s = m(t, "id"), n = (t.service || []).find(se), o = n ? ne(n) : void 0;
|
603
603
|
if (o) {
|
604
|
-
const
|
604
|
+
const c = {
|
605
605
|
source: t,
|
606
606
|
type: o.profileLevel === 0 ? "level0" : "dynamic",
|
607
607
|
service: n,
|
608
608
|
width: i,
|
609
609
|
height: r,
|
610
610
|
majorVersion: o.majorVersion,
|
611
|
-
serviceUrl:
|
611
|
+
serviceUrl: ae(m(n, "id"))
|
612
612
|
};
|
613
|
-
return o.profileLevel === 0 ?
|
614
|
-
...
|
615
|
-
getRegionURL: $t(
|
613
|
+
return o.profileLevel === 0 ? c : {
|
614
|
+
...c,
|
615
|
+
getRegionURL: $t(c)
|
616
616
|
};
|
617
617
|
} else
|
618
618
|
return {
|
@@ -625,7 +625,7 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
625
625
|
};
|
626
626
|
}, kt = (t) => {
|
627
627
|
const e = [];
|
628
|
-
return new
|
628
|
+
return new U({
|
629
629
|
annotation: [(i) => {
|
630
630
|
if (i.motivation === "painting" || !i.motivation) {
|
631
631
|
const n = (i.body ? Array.isArray(i.body) ? i.body : [i.body] : []).filter((o) => o.type === "Image");
|
@@ -634,48 +634,51 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
634
634
|
}]
|
635
635
|
}).traverseCanvas(t), e;
|
636
636
|
}, Pt = (t) => () => {
|
637
|
-
const e = /* @__PURE__ */ new Map(), r = (a,
|
638
|
-
const
|
637
|
+
const e = /* @__PURE__ */ new Map(), r = (a, l, u = 0) => {
|
638
|
+
const v = {
|
639
639
|
id: a.id,
|
640
640
|
type: "range",
|
641
641
|
source: a,
|
642
642
|
children: [],
|
643
643
|
navItems: [],
|
644
644
|
navSections: [],
|
645
|
-
parent:
|
646
|
-
level:
|
645
|
+
parent: l,
|
646
|
+
level: u,
|
647
647
|
getLabel: a.getLabel
|
648
648
|
};
|
649
|
-
a.items && a.items.length > 0 && a.items.forEach((
|
650
|
-
if (
|
651
|
-
const
|
652
|
-
|
649
|
+
a.items && a.items.length > 0 && a.items.forEach((h) => {
|
650
|
+
if (h.source.type === "Range") {
|
651
|
+
const x = r(h, v, u + 1);
|
652
|
+
v.children.push(x);
|
653
653
|
} else {
|
654
|
-
const
|
655
|
-
id:
|
654
|
+
const L = {
|
655
|
+
id: h.id,
|
656
656
|
type: "canvas",
|
657
|
-
source:
|
657
|
+
source: h,
|
658
658
|
children: [],
|
659
659
|
navItems: [],
|
660
660
|
navSections: [],
|
661
|
-
parent:
|
662
|
-
level:
|
663
|
-
getLabel:
|
661
|
+
parent: v,
|
662
|
+
level: u + 1,
|
663
|
+
getLabel: h.getLabel
|
664
664
|
};
|
665
|
-
|
665
|
+
v.children.push(L), e.set(L.id, L);
|
666
666
|
}
|
667
667
|
});
|
668
|
-
const
|
669
|
-
return
|
668
|
+
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");
|
669
|
+
return v.navItems.push(...p), v.navSections.push(...f), e.set(v.id, v), v;
|
670
670
|
};
|
671
671
|
return { root: t.filter((a) => {
|
672
|
-
var
|
673
|
-
return (
|
674
|
-
}).map((a) => r(a, void 0)),
|
675
|
-
const
|
676
|
-
|
677
|
-
|
678
|
-
|
672
|
+
var l;
|
673
|
+
return (l = a.source.behavior) == null ? void 0 : l.includes("top");
|
674
|
+
}).map((a) => r(a, void 0)), enumerateNodes: (a) => {
|
675
|
+
const l = Array.from(e.values());
|
676
|
+
return a ? l.filter((u) => u.type === a) : l;
|
677
|
+
}, getBreadcrumbs: (a) => {
|
678
|
+
const l = e.get(a);
|
679
|
+
if (!l) return [];
|
680
|
+
const u = (v, d = []) => v.parent ? u(v.parent, [v, ...d]) : [v, ...d];
|
681
|
+
return u(l);
|
679
682
|
}, getNode: (a) => e.get(a) };
|
680
683
|
}, Ot = async (t) => {
|
681
684
|
try {
|
@@ -715,7 +718,7 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
715
718
|
};
|
716
719
|
try {
|
717
720
|
const i = await e.json();
|
718
|
-
return
|
721
|
+
return oe(i, t);
|
719
722
|
} catch {
|
720
723
|
return {
|
721
724
|
type: "error",
|
@@ -723,7 +726,7 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
723
726
|
message: "Could not parse resource"
|
724
727
|
};
|
725
728
|
}
|
726
|
-
},
|
729
|
+
}, oe = (t, e) => {
|
727
730
|
const r = Array.isArray(t["@context"]) ? t["@context"].find((s) => s.includes("iiif.io/api/")) : t["@context"];
|
728
731
|
if (!r)
|
729
732
|
return {
|
@@ -731,7 +734,7 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
731
734
|
code: "INVALID_MANIFEST",
|
732
735
|
message: "Missing @context"
|
733
736
|
};
|
734
|
-
const i =
|
737
|
+
const i = m(t, "id");
|
735
738
|
if (!i)
|
736
739
|
return {
|
737
740
|
type: "error",
|
@@ -740,7 +743,7 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
740
743
|
};
|
741
744
|
if (r.includes("presentation/2") || r.includes("presentation/3")) {
|
742
745
|
const s = r.includes("presentation/2") ? 2 : 3;
|
743
|
-
return
|
746
|
+
return m(t, "type").includes("Collection") ? {
|
744
747
|
type: "collection",
|
745
748
|
url: e || i,
|
746
749
|
resource: Ut(t, s)
|
@@ -751,7 +754,7 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
751
754
|
};
|
752
755
|
}
|
753
756
|
if (r.includes("image/2") || r.includes("image/3")) {
|
754
|
-
const s =
|
757
|
+
const s = Nt(t);
|
755
758
|
return s ? {
|
756
759
|
type: "iiif-image",
|
757
760
|
url: e || i,
|
@@ -770,73 +773,73 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
770
773
|
}, Ut = (t, e) => {
|
771
774
|
const r = (n) => {
|
772
775
|
const o = [];
|
773
|
-
return new
|
774
|
-
manifest: [(
|
775
|
-
}).traverseCollection(n), o.map((
|
776
|
-
id:
|
777
|
-
type:
|
778
|
-
getLabel:
|
779
|
-
source:
|
776
|
+
return new U({
|
777
|
+
manifest: [(a) => o.push(a)]
|
778
|
+
}).traverseCollection(n), o.map((a) => ({
|
779
|
+
id: a.id,
|
780
|
+
type: a.type,
|
781
|
+
getLabel: S(a),
|
782
|
+
source: a
|
780
783
|
}));
|
781
|
-
}, i = e === 2 ?
|
784
|
+
}, i = e === 2 ? re(t) : t, s = r(i);
|
782
785
|
return {
|
783
786
|
source: i,
|
784
787
|
id: i.id,
|
785
788
|
majorVersion: e,
|
786
789
|
items: s,
|
787
|
-
getLabel:
|
788
|
-
getMetadata:
|
790
|
+
getLabel: S(i),
|
791
|
+
getMetadata: j(i)
|
789
792
|
};
|
790
793
|
}, Dt = (t, e) => {
|
791
794
|
const r = (o) => {
|
792
|
-
const
|
793
|
-
new
|
794
|
-
canvas: [(
|
795
|
-
|
795
|
+
const c = [], a = [];
|
796
|
+
new U({
|
797
|
+
canvas: [(p) => {
|
798
|
+
p.items && c.push(p);
|
796
799
|
}],
|
797
|
-
range: [(
|
798
|
-
|
800
|
+
range: [(p) => {
|
801
|
+
p.type === "Range" && a.push(p);
|
799
802
|
}]
|
800
803
|
}).traverseManifest(o);
|
801
|
-
const
|
802
|
-
const
|
804
|
+
const u = c.map((p) => {
|
805
|
+
const f = kt(p);
|
803
806
|
return {
|
804
|
-
source:
|
805
|
-
id:
|
806
|
-
width:
|
807
|
-
height:
|
808
|
-
images:
|
809
|
-
annotations:
|
810
|
-
getLabel:
|
811
|
-
getMetadata:
|
812
|
-
getThumbnailURL: Mt(
|
807
|
+
source: p,
|
808
|
+
id: p.id,
|
809
|
+
width: p.width,
|
810
|
+
height: p.height,
|
811
|
+
images: f,
|
812
|
+
annotations: p.annotations || [],
|
813
|
+
getLabel: S(p),
|
814
|
+
getMetadata: j(p),
|
815
|
+
getThumbnailURL: Mt(p, f)
|
813
816
|
};
|
814
|
-
}),
|
815
|
-
const
|
817
|
+
}), v = (p) => {
|
818
|
+
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
819
|
return {
|
817
|
-
source:
|
818
|
-
id:
|
820
|
+
source: p,
|
821
|
+
id: p.id,
|
819
822
|
// Maintain original order
|
820
|
-
items:
|
821
|
-
canvases:
|
822
|
-
ranges:
|
823
|
-
getLabel:
|
823
|
+
items: f.map((y) => x.find(($) => $.id === y.id)),
|
824
|
+
canvases: h,
|
825
|
+
ranges: L,
|
826
|
+
getLabel: S(p)
|
824
827
|
};
|
825
|
-
},
|
826
|
-
return { canvases:
|
827
|
-
}, i = e === 2 ?
|
828
|
+
}, d = a.map((p) => v(p));
|
829
|
+
return { canvases: u, ranges: d };
|
830
|
+
}, i = e === 2 ? re(t) : t, { canvases: s, ranges: n } = r(i);
|
828
831
|
return {
|
829
832
|
source: i,
|
830
833
|
id: i.id,
|
831
834
|
majorVersion: e,
|
832
835
|
canvases: s,
|
833
836
|
structure: n,
|
834
|
-
getLabel:
|
835
|
-
getMetadata:
|
837
|
+
getLabel: S(i),
|
838
|
+
getMetadata: j(i),
|
836
839
|
getTableOfContents: Pt(n)
|
837
840
|
};
|
838
|
-
},
|
839
|
-
const { width: e, height: r } = t, i =
|
841
|
+
}, Nt = (t) => {
|
842
|
+
const { width: e, height: r } = t, i = ne(t);
|
840
843
|
if (i)
|
841
844
|
return {
|
842
845
|
type: i.profileLevel === 0 ? "level0" : "dynamic",
|
@@ -844,22 +847,22 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
844
847
|
width: e,
|
845
848
|
height: r,
|
846
849
|
majorVersion: i.majorVersion,
|
847
|
-
serviceUrl:
|
850
|
+
serviceUrl: ae(m(t, "id"))
|
848
851
|
};
|
849
|
-
}, qt = { parse:
|
852
|
+
}, qt = { parse: oe, parseURL: Ot };
|
850
853
|
export {
|
851
854
|
qt as Cozy,
|
852
|
-
|
855
|
+
V as getImageURLFromService,
|
853
856
|
kt as getImages,
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
+
S as getLabel,
|
858
|
+
j as getMetadata,
|
859
|
+
m as getPropertyValue,
|
857
860
|
$t as getRegionURL,
|
858
861
|
xt as getRegionURLFromService,
|
859
862
|
Ft as getStringValue,
|
860
863
|
Pt as getTableOfContents,
|
861
864
|
Mt as getThumbnailURL,
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
+
se as isImageService,
|
866
|
+
ae as normalizeServiceUrl,
|
867
|
+
ne as parseImageService
|
865
868
|
};
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
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