cozy-iiif 0.1.4 → 0.1.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/core/index.d.ts +1 -0
- package/dist/core/manifest.d.ts +2 -0
- package/dist/index.js +226 -178
- package/dist/types.d.ts +19 -1
- package/package.json +3 -3
- package/src/Cozy.ts +40 -6
- package/src/core/index.ts +1 -0
- package/src/core/manifest.ts +38 -0
- package/src/types.ts +37 -1
- package/test/Cozy.test.ts +17 -3
- package/test/fixtures.ts +4 -1
package/dist/core/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -1,32 +1,32 @@
|
|
1
|
-
import { g as
|
2
|
-
import { c as
|
3
|
-
var
|
4
|
-
function
|
1
|
+
import { g as v, a as x, b as L } from "./resource-DS2brz47.js";
|
2
|
+
import { c as _t } from "./resource-DS2brz47.js";
|
3
|
+
var oe = "http://library.stanford.edu/iiif/image-api/compliance.html#level0", ce = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", V = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", le = "http://library.stanford.edu/iiif/image-api/conformance.html#level0", pe = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", F = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", ve = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0", he = "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", ue = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0", fe = "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", me = "http://iiif.io/api/image/1/level0.json", ge = "http://iiif.io/api/image/1/profiles/level0.json", de = "http://iiif.io/api/image/1/level1.json", ye = "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", Ae = "http://iiif.io/api/image/2/level0.json", Ce = "http://iiif.io/api/image/2/profiles/level0.json", be = "http://iiif.io/api/image/2/level1.json", Re = "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", Le = "level0", we = "level1", K = "level2", Ie = "http://iiif.io/api/image/2/level0", Se = "http://iiif.io/api/image/2/level1", Q = "http://iiif.io/api/image/2/level2", Te = [Q, V, F, W, B, H, J, G, z, K], xe = [Ie, Se, Q, oe, ce, V, le, pe, F, ve, he, W, ue, fe, B, me, ge, de, ye, H, J, Ae, Ce, be, Re, G, z, Le, we, K], $e = xe;
|
4
|
+
function h(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 b(t) {
|
9
9
|
return Array.isArray(t) ? t : t ? [t] : [];
|
10
10
|
}
|
11
|
-
var
|
12
|
-
function
|
11
|
+
var je = Object.defineProperty, Me = (t, e, r) => e in t ? je(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, y = (t, e, r) => (Me(t, typeof e != "symbol" ? e + "" : e, r), r), U = ["sc:Collection", "sc:Manifest", "sc:Canvas", "sc:AnnotationList", "oa:Annotation", "sc:Range", "sc:Layer", "sc:Sequence", "oa:Choice", "Service", "ContentResource"];
|
12
|
+
function ke(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 = U.indexOf(t["@type"]);
|
18
|
+
if (e !== -1) return U[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
|
24
|
+
var Pe = class X {
|
25
25
|
constructor(e, r = {}) {
|
26
|
-
|
26
|
+
y(this, "traversals"), y(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 X({ 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);
|
@@ -99,7 +99,7 @@ var xe = class B {
|
|
99
99
|
}
|
100
100
|
traverseUnknown(e) {
|
101
101
|
if (!e["@type"] || typeof e == "string") return e;
|
102
|
-
switch (
|
102
|
+
switch (ke(e)) {
|
103
103
|
case "sc:Collection":
|
104
104
|
return this.traverseCollection(e);
|
105
105
|
case "sc:Manifest":
|
@@ -152,8 +152,8 @@ var xe = class B {
|
|
152
152
|
return typeof n > "u" && !this.options.allowUndefinedReturn ? i : n;
|
153
153
|
}, e);
|
154
154
|
}
|
155
|
-
},
|
156
|
-
function
|
155
|
+
}, Oe = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", Ue = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", De = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", Ee = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", Ne = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", qe = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", _e = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", Ve = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", Fe = "http://iiif.io/api/image/1/level1.json", We = "http://iiif.io/api/image/1/profiles/level1.json", Be = "http://iiif.io/api/image/1/level2.json", He = "http://iiif.io/api/image/1/profiles/level2.json", Je = "http://iiif.io/api/image/2/level1.json", Ge = "http://iiif.io/api/image/2/profiles/level1.json", ze = "http://iiif.io/api/image/2/level2.json", Ke = "http://iiif.io/api/image/2/profiles/level2.json", Qe = "level1", Xe = "level2", Ye = "http://iiif.io/api/image/2/level1", Ze = "http://iiif.io/api/image/2/level2", et = [Ye, Ze, Oe, Ue, De, Ee, Ne, qe, _e, Ve, Fe, We, Be, He, Je, Ge, ze, Ke, Qe, Xe], $ = { attributionLabel: "Attribution", providerId: "http://example.org/provider", providerName: "Unknown" };
|
156
|
+
function tt(t) {
|
157
157
|
if (typeof t == "string") return [t];
|
158
158
|
if (!t) return [];
|
159
159
|
let e = Array.isArray(t) ? t : [t], r = [];
|
@@ -166,9 +166,9 @@ function Qe(t) {
|
|
166
166
|
}
|
167
167
|
return r;
|
168
168
|
}
|
169
|
-
function
|
169
|
+
function R(t, e = "none") {
|
170
170
|
if (!t) return { none: [""] };
|
171
|
-
let r =
|
171
|
+
let r = tt(t), i = {};
|
172
172
|
for (let s of r) {
|
173
173
|
if (typeof s == "string") {
|
174
174
|
i[e] = i[e] ? i[e] : [], i[e].push(s || "");
|
@@ -183,14 +183,14 @@ function d(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
|
188
|
-
if (
|
189
|
-
if (
|
190
|
-
if (
|
186
|
+
function Y(t) {
|
187
|
+
if (Array.isArray(t)) return Y(t.find((e) => typeof e == "string"));
|
188
|
+
if (Te.indexOf(t) !== -1) return "level2";
|
189
|
+
if (et.indexOf(t) !== -1) return "level1";
|
190
|
+
if ($e.indexOf(t) !== -1) return "level0";
|
191
191
|
if (typeof t == "string") return t;
|
192
192
|
}
|
193
|
-
function
|
193
|
+
function rt(t) {
|
194
194
|
let e = Array.isArray(t) ? t : [t];
|
195
195
|
for (let r of e) switch (r) {
|
196
196
|
case "http://iiif.io/api/image/2/context.json":
|
@@ -203,7 +203,7 @@ function Xe(t) {
|
|
203
203
|
return "ImageApiSelector";
|
204
204
|
}
|
205
205
|
}
|
206
|
-
function
|
206
|
+
function it(t) {
|
207
207
|
switch (t) {
|
208
208
|
case "http://iiif.io/api/image/2/level0.json":
|
209
209
|
case "http://iiif.io/api/image/2/level1.json":
|
@@ -232,19 +232,19 @@ function Ye(t) {
|
|
232
232
|
return "AutoCompleteService1";
|
233
233
|
}
|
234
234
|
}
|
235
|
-
function
|
235
|
+
function D(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
|
-
var
|
240
|
-
function
|
239
|
+
var st = ["Collection", "Manifest", "Annotation", "AnnotationPage", "Range", "Service"];
|
240
|
+
function M(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
|
-
let n =
|
243
|
+
let n = it(i);
|
244
244
|
if (n) return n;
|
245
245
|
}
|
246
246
|
if (s) {
|
247
|
-
let n =
|
247
|
+
let n = rt(s);
|
248
248
|
if (n) return n;
|
249
249
|
}
|
250
250
|
if (r) {
|
@@ -266,7 +266,7 @@ function S(t) {
|
|
266
266
|
return "TextualBody";
|
267
267
|
}
|
268
268
|
}
|
269
|
-
if (r &&
|
269
|
+
if (r && st.indexOf(r) !== -1) return r;
|
270
270
|
if (t.format) {
|
271
271
|
if (t.format.startsWith("image/")) return "Image";
|
272
272
|
if (t.format.startsWith("text/") || t.format === "application/pdf") return "Text";
|
@@ -274,15 +274,15 @@ function S(t) {
|
|
274
274
|
}
|
275
275
|
return e && (e.endsWith(".jpg") || e.endsWith(".png") || e.endsWith(".jpeg")) ? "Image" : r || "unknown";
|
276
276
|
}
|
277
|
-
var
|
278
|
-
function
|
279
|
-
let e = t.match(
|
277
|
+
var nt = /http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;
|
278
|
+
function at(t) {
|
279
|
+
let e = t.match(nt);
|
280
280
|
return e ? e[0] : t;
|
281
281
|
}
|
282
|
-
function
|
282
|
+
function ot(t, e = "Rights/License", r = "none") {
|
283
283
|
let i = null, s = [], n = Array.isArray(t) ? t : [t];
|
284
284
|
for (let a of n) {
|
285
|
-
let o = a ?
|
285
|
+
let o = a ? at(a) : void 0;
|
286
286
|
if (o && (o.indexOf("creativecommons.org") !== -1 || o.indexOf("rightsstatements.org") !== -1)) {
|
287
287
|
o.startsWith("https://") ? i = `http://${o.slice(8)}` : i = o;
|
288
288
|
continue;
|
@@ -291,36 +291,36 @@ function rt(t, e = "Rights/License", r = "none") {
|
|
291
291
|
}
|
292
292
|
return [i, s];
|
293
293
|
}
|
294
|
-
var
|
295
|
-
function
|
294
|
+
var ct = ["http://iiif.io/api/presentation/2/context.json", "http://iiif.io/api/image/2/context.json", "http://iiif.io/api/image/1/context.json", "http://library.stanford.edu/iiif/image-api/1.1/context.json", "http://iiif.io/api/search/1/context.json", "http://iiif.io/api/search/0/context.json", "http://iiif.io/api/auth/1/context.json", "http://iiif.io/api/auth/0/context.json", "http://iiif.io/api/annex/openannotation/context.json"];
|
295
|
+
function lt(t) {
|
296
296
|
if (t) {
|
297
297
|
let e = Array.isArray(t) ? t : [t], r = [];
|
298
|
-
for (let i of e) i === "http://iiif.io/api/presentation/2/context.json" && r.push("http://iiif.io/api/presentation/3/context.json"),
|
298
|
+
for (let i of e) i === "http://iiif.io/api/presentation/2/context.json" && r.push("http://iiif.io/api/presentation/3/context.json"), ct.indexOf(i) === -1 && r.push(i);
|
299
299
|
if (e.length) return r.length === 1 ? r[0] : r;
|
300
300
|
}
|
301
301
|
}
|
302
|
-
function
|
303
|
-
return t ? t.map((e) => ({ label:
|
302
|
+
function pt(t) {
|
303
|
+
return t ? t.map((e) => ({ label: R(e.label), value: R(e.value) })) : [];
|
304
304
|
}
|
305
|
-
var
|
306
|
-
function
|
305
|
+
var E = 0;
|
306
|
+
function Z(t, e) {
|
307
307
|
let r = encodeURI(t.id || t["@id"] || "").trim();
|
308
|
-
return r && e ? `${r}/${e}` : r || (
|
308
|
+
return r && e ? `${r}/${e}` : r || (E++, `http://example.org/${t["@type"]}${e ? `/${e}` : ""}/${E}`);
|
309
309
|
}
|
310
|
-
function
|
310
|
+
function m(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(D) : t.motivation && (r = D(t.motivation)), { "@context": t["@context"] ? lt(t["@context"]) : void 0, id: (t["@id"] || Z(t)).trim(), type: M(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
|
317
|
-
let [e, r] =
|
318
|
-
return { rights: e, metadata: i.length ? i : void 0, label: t.label ?
|
316
|
+
function g(t) {
|
317
|
+
let [e, r] = ot(t.license), i = [...t.metadata ? pt(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($.attributionLabel), value: R(t.attribution) } : void 0, navDate: t.navDate, summary: t.description ? R(t.description) : void 0, thumbnail: vt(t.thumbnail) };
|
319
319
|
}
|
320
|
-
function
|
320
|
+
function vt(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));
|
322
322
|
}
|
323
|
-
function
|
323
|
+
function ht(t) {
|
324
324
|
if (!t.within) return;
|
325
325
|
let e = Array.isArray(t.within) ? t.within : [t.within], r = [];
|
326
326
|
for (let i of e) if (typeof i == "string") {
|
@@ -329,26 +329,26 @@ function ot(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: M(i) });
|
333
333
|
return r.length ? r : void 0;
|
334
334
|
}
|
335
|
-
function
|
335
|
+
function A(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: $.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($.providerName) }] : void 0, partOf: ht(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
|
-
function
|
339
|
+
function ut(t) {
|
340
340
|
return { chars: t.chars, format: t.format ? t.format : void 0, language: t.language };
|
341
341
|
}
|
342
|
-
function
|
343
|
-
return
|
342
|
+
function ft(t) {
|
343
|
+
return h({ ...m(t), ...g(t), ...A(t), items: t.members });
|
344
344
|
}
|
345
|
-
function
|
345
|
+
function mt(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 = m(t);
|
349
|
+
return r.length && (s.behavior ? s.behavior.push(...r) : s.behavior = r), h({ ...s, ...g(t), ...A(t), start: i, items: e, structures: gt(t.structures) });
|
350
350
|
}
|
351
|
-
function
|
351
|
+
function gt(t) {
|
352
352
|
if (!t) return t;
|
353
353
|
let e = /* @__PURE__ */ new Map();
|
354
354
|
for (let i of t) e.set(i.id, i);
|
@@ -359,16 +359,16 @@ function vt(t) {
|
|
359
359
|
}
|
360
360
|
return t.filter((i) => r.indexOf(i.id) === -1);
|
361
361
|
}
|
362
|
-
function
|
363
|
-
return
|
362
|
+
function dt(t) {
|
363
|
+
return h({ ...m(t), ...g(t), ...A(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
|
-
function
|
366
|
-
return
|
365
|
+
function yt(t) {
|
366
|
+
return h({ ...m(t), ...g(t), ...A(t), items: t.resources && t.resources.length ? t.resources : void 0 });
|
367
367
|
}
|
368
|
-
function
|
368
|
+
function At(t) {
|
369
369
|
return !t.canvases || t.canvases.length === 0 ? { canvases: [], behavior: [] } : { canvases: t.canvases, behavior: t.viewingHint ? [t.viewingHint] : [], startCanvas: t.startCanvas };
|
370
370
|
}
|
371
|
-
function
|
371
|
+
function Ct(t) {
|
372
372
|
function e(r) {
|
373
373
|
if (Array.isArray(r)) {
|
374
374
|
if (r.length > 1) return { type: "List", items: r.map(e) };
|
@@ -381,51 +381,51 @@ function mt(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: j(r.selector) };
|
385
385
|
} else return encodeURI(r["@id"]).trim();
|
386
386
|
}
|
387
|
-
return
|
387
|
+
return h({ ...m(t), ...g(t), ...A(t), target: e(t.on), body: Array.isArray(t.resource) ? t.resource.map(N) : N(t.resource) });
|
388
388
|
}
|
389
|
-
function
|
390
|
-
return t.type === "Choice" ? t :
|
389
|
+
function N(t) {
|
390
|
+
return t.type === "Choice" ? t : ee(t);
|
391
391
|
}
|
392
|
-
function
|
392
|
+
function ee(t) {
|
393
393
|
let e = t;
|
394
|
-
return
|
394
|
+
return h({ ...m(e), ...g(e), ...A(e), ...ut(e) });
|
395
395
|
}
|
396
|
-
function
|
396
|
+
function bt(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), h({ ...m(t), ...g(t), items: e });
|
399
399
|
}
|
400
|
-
function
|
401
|
-
return
|
400
|
+
function Rt(t) {
|
401
|
+
return h({ ...m(t), ...g(t), ...A(t), items: t.members });
|
402
402
|
}
|
403
|
-
function
|
403
|
+
function Lt(t) {
|
404
404
|
let { "@id": e, "@type": r, "@context": i, profile: s, ...n } = t, a = {};
|
405
|
-
return e && (a["@id"] = e), a["@type"] =
|
405
|
+
return e && (a["@id"] = e), a["@type"] = M(t), a["@type"] === "unknown" && (i && i.length && (a["@context"] = i), a["@type"] = "Service"), s && (a.profile = Y(s)), h({ ...a, ...n });
|
406
406
|
}
|
407
|
-
function
|
408
|
-
return
|
407
|
+
function wt(t) {
|
408
|
+
return h({ ...m(t), ...g(t), ...A(t) });
|
409
409
|
}
|
410
|
-
var
|
411
|
-
function
|
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" ?
|
410
|
+
var It = new Pe({ collection: [ft], manifest: [mt], canvas: [dt], annotationList: [yt], sequence: [At], annotation: [Ct], contentResource: [ee], choice: [bt], range: [Rt], service: [Lt], layer: [wt] });
|
411
|
+
function te(t) {
|
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" ? It.traverseUnknown(t) : t;
|
413
413
|
}
|
414
|
-
function
|
414
|
+
function j(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 [j(t.default), ...(Array.isArray(t.item) ? t.item : [t.item]).map(j)];
|
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(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 w(...t) {
|
425
425
|
return (e) => t.reduce((r, i) => i(r), e);
|
426
426
|
}
|
427
|
-
var
|
428
|
-
function
|
427
|
+
var q = ["Collection", "Manifest", "Canvas", "AnnotationPage", "AnnotationCollection", "Annotation", "ContentResource", "Range", "Service", "Selector", "Agent"];
|
428
|
+
function St(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");
|
431
431
|
if (typeof t != "object") {
|
@@ -433,24 +433,24 @@ function bt(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 = q.indexOf(t.type);
|
437
|
+
if (r !== -1) return q[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 k = class re {
|
443
443
|
constructor(e, r = {}) {
|
444
|
-
|
444
|
+
y(this, "traversals"), y(this, "options"), y(this, "_traverseManifest", w(this.traverseManifestItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseManifestStructures.bind(this), this.traverseInlineAnnotationPages.bind(this))), y(this, "_traverseCanvas", w(this.traverseCanvasItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseInlineAnnotationPages.bind(this))), y(this, "_traverseAnnotationPage", w(this.traverseAnnotationPageItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this))), y(this, "_traverseRange", w(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 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 = 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 =
|
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 && (T(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 T = class K {
|
|
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 = 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))), T(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) : T(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,10 +524,10 @@ var T = class K {
|
|
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 = b(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
|
-
let s =
|
530
|
+
let s = St(e, i);
|
531
531
|
switch (s) {
|
532
532
|
case "Collection":
|
533
533
|
return this.traverseCollection(e, r);
|
@@ -552,15 +552,15 @@ var T = class K {
|
|
552
552
|
}
|
553
553
|
}
|
554
554
|
};
|
555
|
-
const
|
556
|
-
const e =
|
555
|
+
const ie = (t) => v(t, "type").startsWith("ImageService") || t.profile && t.profile.toString().includes("iiif.io/api/image/"), se = (t) => {
|
556
|
+
const e = v(t, "type"), r = v(t, "context");
|
557
557
|
if (e === "ImageService2" || r != null && r.includes("image/2")) {
|
558
558
|
const i = t, s = ["level0", "level1", "level2"];
|
559
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
|
-
},
|
563
|
-
const i =
|
562
|
+
}, _ = (t, e, r) => {
|
563
|
+
const i = v(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
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];
|
@@ -570,36 +570,36 @@ const Q = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profi
|
|
570
570
|
return `${i}/full/full/0/default.jpg`;
|
571
571
|
}
|
572
572
|
return `${i}/full/!${e},${r}/0/default.jpg`;
|
573
|
-
},
|
574
|
-
const i =
|
573
|
+
}, Tt = (t, e, r) => {
|
574
|
+
const i = v(t, "id"), s = t.profile || "";
|
575
575
|
if (typeof s == "string" && (s.includes("level0") || s.includes("level:0"))) return;
|
576
|
-
const { x: a, y: o, w: c, h:
|
577
|
-
return `${i}/${
|
578
|
-
},
|
576
|
+
const { x: a, y: o, w: c, h: p } = e, u = c / p, C = u < 1, I = Math.ceil(C ? r / u : r), l = Math.ceil(C ? r : r / u), d = `${Math.round(a)},${Math.round(o)},${Math.round(c)},${Math.round(p)}`;
|
577
|
+
return `${i}/${d}/!${l},${I}/0/default.jpg`;
|
578
|
+
}, xt = (t) => (e, r = 400) => {
|
579
579
|
if (t.type === "dynamic")
|
580
|
-
return
|
580
|
+
return Tt(t.service, e, r);
|
581
581
|
console.error("Level 0 or static image canvas: unspported");
|
582
|
-
},
|
582
|
+
}, $t = (t, e = []) => (r = 400) => {
|
583
583
|
const { width: i, height: s } = t;
|
584
584
|
if (!i || !s) return;
|
585
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
|
-
const
|
588
|
-
if ("service" in
|
589
|
-
const
|
590
|
-
if (
|
591
|
-
return
|
587
|
+
const p = t.thumbnail[0];
|
588
|
+
if ("service" in p && Array.isArray(p.service)) {
|
589
|
+
const u = p.service.find((C) => ie(C));
|
590
|
+
if (u)
|
591
|
+
return _(u, c, o);
|
592
592
|
}
|
593
|
-
if ("id" in
|
593
|
+
if ("id" in p) return p.id;
|
594
594
|
}
|
595
|
-
for (const
|
596
|
-
if (
|
597
|
-
return
|
598
|
-
if (
|
599
|
-
return
|
595
|
+
for (const p of e) {
|
596
|
+
if (p.type === "dynamic" || p.type === "level0")
|
597
|
+
return _(p.service, c, o);
|
598
|
+
if (p.type === "static")
|
599
|
+
return p.url;
|
600
600
|
}
|
601
|
-
},
|
602
|
-
const { format: e, height: r, width: i } = t, s =
|
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 = v(t, "id"), n = (t.service || []).find(ie), a = n ? se(n) : void 0;
|
603
603
|
if (a) {
|
604
604
|
const o = {
|
605
605
|
source: t,
|
@@ -608,11 +608,11 @@ const Q = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profi
|
|
608
608
|
width: i,
|
609
609
|
height: r,
|
610
610
|
majorVersion: a.majorVersion,
|
611
|
-
serviceUrl:
|
611
|
+
serviceUrl: ne(v(n, "id"))
|
612
612
|
};
|
613
613
|
return a.profileLevel === 0 ? o : {
|
614
614
|
...o,
|
615
|
-
getRegionURL:
|
615
|
+
getRegionURL: xt(o)
|
616
616
|
};
|
617
617
|
} else
|
618
618
|
return {
|
@@ -623,17 +623,46 @@ const Q = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profi
|
|
623
623
|
url: s,
|
624
624
|
format: e
|
625
625
|
};
|
626
|
-
},
|
626
|
+
}, Mt = (t) => {
|
627
627
|
const e = [];
|
628
|
-
return new
|
628
|
+
return new k({
|
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((a) => a.type === "Image");
|
632
|
-
e.push(...n.map((a) =>
|
632
|
+
e.push(...n.map((a) => jt(a)));
|
633
633
|
}
|
634
634
|
}]
|
635
635
|
}).traverseCanvas(t), e;
|
636
|
-
},
|
636
|
+
}, kt = (t) => () => {
|
637
|
+
const e = (i, s, n = 0) => {
|
638
|
+
const a = {
|
639
|
+
id: i.id,
|
640
|
+
type: "range",
|
641
|
+
getLabel: i.getLabel,
|
642
|
+
children: [],
|
643
|
+
parent: s,
|
644
|
+
level: n
|
645
|
+
};
|
646
|
+
return i.items && i.items.length > 0 && i.items.forEach((o) => {
|
647
|
+
if (o.source.type === "Range") {
|
648
|
+
const c = e(o, a, n + 1);
|
649
|
+
a.children.push(c);
|
650
|
+
} else
|
651
|
+
a.children.push({
|
652
|
+
id: o.id,
|
653
|
+
type: "canvas",
|
654
|
+
getLabel: o.getLabel,
|
655
|
+
children: [],
|
656
|
+
parent: a,
|
657
|
+
level: n + 1
|
658
|
+
});
|
659
|
+
}), a;
|
660
|
+
};
|
661
|
+
return t.filter((i) => {
|
662
|
+
var s;
|
663
|
+
return (s = i.source.behavior) == null ? void 0 : s.includes("top");
|
664
|
+
}).map((i) => e(i, void 0));
|
665
|
+
}, Et = {
|
637
666
|
parseURL: async (t) => {
|
638
667
|
try {
|
639
668
|
new URL(t);
|
@@ -678,7 +707,7 @@ const Q = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profi
|
|
678
707
|
code: "INVALID_MANIFEST",
|
679
708
|
message: "Missing @context"
|
680
709
|
};
|
681
|
-
if (!
|
710
|
+
if (!v(i, "id"))
|
682
711
|
return {
|
683
712
|
type: "error",
|
684
713
|
code: "INVALID_MANIFEST",
|
@@ -686,18 +715,18 @@ const Q = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profi
|
|
686
715
|
};
|
687
716
|
if (s.includes("presentation/2") || s.includes("presentation/3")) {
|
688
717
|
const a = s.includes("presentation/2") ? 2 : 3;
|
689
|
-
return
|
718
|
+
return v(i, "type").includes("Collection") ? {
|
690
719
|
type: "collection",
|
691
720
|
url: t,
|
692
|
-
resource:
|
721
|
+
resource: Pt(i, a)
|
693
722
|
} : {
|
694
723
|
type: "manifest",
|
695
724
|
url: t,
|
696
|
-
resource:
|
725
|
+
resource: Ot(i, a)
|
697
726
|
};
|
698
727
|
}
|
699
728
|
if (s.includes("image/2") || s.includes("image/3")) {
|
700
|
-
const a =
|
729
|
+
const a = Ut(i);
|
701
730
|
return a ? {
|
702
731
|
type: "iiif-image",
|
703
732
|
url: t,
|
@@ -721,57 +750,75 @@ const Q = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profi
|
|
721
750
|
};
|
722
751
|
}
|
723
752
|
}
|
724
|
-
},
|
753
|
+
}, Pt = (t, e) => {
|
725
754
|
const r = (n) => {
|
726
755
|
const a = [];
|
727
|
-
return new
|
756
|
+
return new k({
|
728
757
|
manifest: [(c) => a.push(c)]
|
729
758
|
}).traverseCollection(n), a.map((c) => ({
|
730
759
|
id: c.id,
|
731
760
|
type: c.type,
|
732
|
-
getLabel:
|
761
|
+
getLabel: L(c),
|
733
762
|
source: c
|
734
763
|
}));
|
735
|
-
}, i = e === 2 ?
|
764
|
+
}, i = e === 2 ? te(t) : t, s = r(i);
|
736
765
|
return {
|
737
766
|
source: i,
|
738
767
|
id: i.id,
|
739
768
|
majorVersion: e,
|
740
769
|
items: s,
|
741
|
-
getLabel:
|
742
|
-
getMetadata:
|
770
|
+
getLabel: L(i),
|
771
|
+
getMetadata: x(i)
|
743
772
|
};
|
744
|
-
},
|
745
|
-
const r = (
|
746
|
-
const
|
747
|
-
|
748
|
-
canvas: [(
|
749
|
-
|
773
|
+
}, Ot = (t, e) => {
|
774
|
+
const r = (a) => {
|
775
|
+
const o = [], c = [];
|
776
|
+
new k({
|
777
|
+
canvas: [(l) => {
|
778
|
+
l.items && o.push(l);
|
779
|
+
}],
|
780
|
+
range: [(l) => {
|
781
|
+
l.type === "Range" && c.push(l);
|
750
782
|
}]
|
751
|
-
}).traverseManifest(
|
752
|
-
|
783
|
+
}).traverseManifest(a);
|
784
|
+
const u = o.map((l) => {
|
785
|
+
const d = Mt(l);
|
786
|
+
return {
|
787
|
+
source: l,
|
788
|
+
id: l.id,
|
789
|
+
width: l.width,
|
790
|
+
height: l.height,
|
791
|
+
images: d,
|
792
|
+
getLabel: L(l),
|
793
|
+
getMetadata: x(l),
|
794
|
+
getThumbnailURL: $t(l, d)
|
795
|
+
};
|
796
|
+
}), C = (l) => {
|
797
|
+
const d = l.items || [], P = d.filter((f) => f.type === "Canvas").map((f) => u.find((S) => S.id === f.id)).filter(Boolean), O = d.filter((f) => f.type === "Range").map((f) => C(f)), ae = [...P, ...O];
|
753
798
|
return {
|
754
|
-
source:
|
755
|
-
id:
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
getThumbnailURL: wt(c, l)
|
799
|
+
source: l,
|
800
|
+
id: l.id,
|
801
|
+
// Maintain original order
|
802
|
+
items: d.map((f) => ae.find((S) => S.id === f.id)),
|
803
|
+
canvases: P,
|
804
|
+
ranges: O,
|
805
|
+
getLabel: L(l)
|
762
806
|
};
|
763
|
-
});
|
764
|
-
|
807
|
+
}, I = c.map((l) => C(l));
|
808
|
+
return { canvases: u, ranges: I };
|
809
|
+
}, i = e === 2 ? te(t) : t, { canvases: s, ranges: n } = r(i);
|
765
810
|
return {
|
766
811
|
source: i,
|
767
812
|
id: i.id,
|
768
813
|
majorVersion: e,
|
769
814
|
canvases: s,
|
770
|
-
|
771
|
-
|
815
|
+
structure: n,
|
816
|
+
getLabel: L(i),
|
817
|
+
getMetadata: x(i),
|
818
|
+
getTableOfContents: kt(n)
|
772
819
|
};
|
773
|
-
},
|
774
|
-
const { width: e, height: r } = t, i =
|
820
|
+
}, Ut = (t) => {
|
821
|
+
const { width: e, height: r } = t, i = se(t);
|
775
822
|
if (i)
|
776
823
|
return {
|
777
824
|
type: i.profileLevel === 0 ? "level0" : "dynamic",
|
@@ -779,21 +826,22 @@ const Q = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profi
|
|
779
826
|
width: e,
|
780
827
|
height: r,
|
781
828
|
majorVersion: i.majorVersion,
|
782
|
-
serviceUrl:
|
829
|
+
serviceUrl: ne(v(t, "id"))
|
783
830
|
};
|
784
831
|
};
|
785
832
|
export {
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
833
|
+
Et as Cozy,
|
834
|
+
_ as getImageURLFromService,
|
835
|
+
Mt as getImages,
|
836
|
+
L as getLabel,
|
837
|
+
x as getMetadata,
|
838
|
+
v as getPropertyValue,
|
839
|
+
xt as getRegionURL,
|
840
|
+
Tt as getRegionURLFromService,
|
841
|
+
_t as getStringValue,
|
842
|
+
kt as getTableOfContents,
|
843
|
+
$t as getThumbnailURL,
|
844
|
+
ie as isImageService,
|
845
|
+
ne as normalizeServiceUrl,
|
846
|
+
se as parseImageService
|
799
847
|
};
|
package/dist/types.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Manifest, Canvas, ImageService2, ImageService3, IIIFExternalWebResource, Collection } from '@iiif/presentation-3';
|
1
|
+
import { Manifest, Canvas, ImageService2, ImageService3, IIIFExternalWebResource, Collection, Range } from '@iiif/presentation-3';
|
2
2
|
export type CozyParseResult = {
|
3
3
|
type: 'collection';
|
4
4
|
url: string;
|
@@ -41,9 +41,19 @@ export interface CozyManifest {
|
|
41
41
|
readonly source: Manifest;
|
42
42
|
readonly id: string;
|
43
43
|
readonly canvases: CozyCanvas[];
|
44
|
+
readonly structure: CozyRange[];
|
44
45
|
getLabel(locale?: string): string | undefined;
|
46
|
+
getTableOfContents(): CozyTOCNode[];
|
45
47
|
getMetadata(locale?: string): CozyMetadata[];
|
46
48
|
}
|
49
|
+
export interface CozyRange {
|
50
|
+
readonly source: Range;
|
51
|
+
readonly id: string;
|
52
|
+
readonly items: (CozyCanvas | CozyRange)[];
|
53
|
+
readonly canvases: CozyCanvas[];
|
54
|
+
readonly ranges: CozyRange[];
|
55
|
+
getLabel(locale?: string): string | undefined;
|
56
|
+
}
|
47
57
|
export interface CozyCanvas {
|
48
58
|
readonly source: Canvas;
|
49
59
|
readonly id: string;
|
@@ -58,6 +68,14 @@ export interface CozyMetadata {
|
|
58
68
|
readonly label: string;
|
59
69
|
readonly value: string;
|
60
70
|
}
|
71
|
+
export interface CozyTOCNode {
|
72
|
+
readonly id: string;
|
73
|
+
readonly type: 'range' | 'canvas';
|
74
|
+
getLabel(locale?: string): string | undefined;
|
75
|
+
children: CozyTOCNode[];
|
76
|
+
parent?: CozyTOCNode;
|
77
|
+
level: number;
|
78
|
+
}
|
61
79
|
export type CozyImageResource = StaticImageResource | ImageServiceResource;
|
62
80
|
export type ImageServiceResource = DynamicImageServiceResource | Level0ImageServiceResource;
|
63
81
|
interface BaseImageResource {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "cozy-iiif",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.5",
|
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",
|
@@ -27,9 +27,9 @@
|
|
27
27
|
"./level-0": "./dist/level-0/index.js"
|
28
28
|
},
|
29
29
|
"devDependencies": {
|
30
|
-
"vite": "^6.2.
|
30
|
+
"vite": "^6.2.5",
|
31
31
|
"vite-plugin-dts": "^4.5.3",
|
32
|
-
"vitest": "^3.
|
32
|
+
"vitest": "^3.1.1"
|
33
33
|
},
|
34
34
|
"dependencies": {
|
35
35
|
"@iiif/parser": "^2.1.7",
|
package/src/Cozy.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { Canvas, Collection, Manifest } from '@iiif/presentation-3';
|
1
|
+
import type { Canvas, Collection, Manifest, Range } from '@iiif/presentation-3';
|
2
2
|
import { convertPresentation2 } from '@iiif/parser/presentation-2';
|
3
3
|
import { Traverse } from '@iiif/parser';
|
4
4
|
import {
|
@@ -6,6 +6,7 @@ import {
|
|
6
6
|
getLabel,
|
7
7
|
getMetadata,
|
8
8
|
getPropertyValue,
|
9
|
+
getTableOfContents,
|
9
10
|
getThumbnailURL,
|
10
11
|
normalizeServiceUrl,
|
11
12
|
parseImageService
|
@@ -16,6 +17,7 @@ import type {
|
|
16
17
|
CozyCollectionItem,
|
17
18
|
CozyManifest,
|
18
19
|
CozyParseResult,
|
20
|
+
CozyRange,
|
19
21
|
ImageServiceResource
|
20
22
|
} from './types';
|
21
23
|
|
@@ -174,15 +176,17 @@ const parseCollectionResource = (resource: any, majorVersion: number): CozyColle
|
|
174
176
|
const parseManifestResource = (resource: any, majorVersion: number): CozyManifest => {
|
175
177
|
|
176
178
|
const parseV3 = (manifest: Manifest) => {
|
177
|
-
const
|
179
|
+
const sourceCanvases: Canvas[] = [];
|
180
|
+
const sourceRanges: Range[] = [];
|
178
181
|
|
179
182
|
const modelBuilder = new Traverse({
|
180
|
-
canvas: [canvas => { if (canvas.items)
|
183
|
+
canvas: [canvas => { if (canvas.items) sourceCanvases.push(canvas) }],
|
184
|
+
range: [range => { if (range.type === 'Range') sourceRanges.push(range) }]
|
181
185
|
});
|
182
186
|
|
183
187
|
modelBuilder.traverseManifest(manifest);
|
184
188
|
|
185
|
-
|
189
|
+
const canvases = sourceCanvases.map((c: Canvas) => {
|
186
190
|
const images = getImages(c);
|
187
191
|
return {
|
188
192
|
source: c,
|
@@ -195,19 +199,49 @@ const parseManifestResource = (resource: any, majorVersion: number): CozyManifes
|
|
195
199
|
getThumbnailURL: getThumbnailURL(c, images)
|
196
200
|
} as CozyCanvas;
|
197
201
|
});
|
202
|
+
|
203
|
+
const toRange = (source: Range): CozyRange => {
|
204
|
+
const items = source.items || [];
|
205
|
+
|
206
|
+
const nestedCanvases: CozyCanvas[] = items
|
207
|
+
.filter((item: any) => item.type === 'Canvas')
|
208
|
+
.map((item: any) => canvases.find(c => c.id === item.id)!)
|
209
|
+
.filter(Boolean);
|
210
|
+
|
211
|
+
const nestedRanges = items
|
212
|
+
.filter((item: any) => item.type === 'Range')
|
213
|
+
.map((item: any) => toRange(item));
|
214
|
+
|
215
|
+
const nestedItems = [...nestedCanvases, ...nestedRanges];
|
216
|
+
|
217
|
+
return {
|
218
|
+
source,
|
219
|
+
id: source.id,
|
220
|
+
// Maintain original order
|
221
|
+
items: items.map((i: any) => nestedItems.find(cozy => cozy.id === i.id)),
|
222
|
+
canvases: nestedCanvases,
|
223
|
+
ranges: nestedRanges,
|
224
|
+
getLabel: getLabel(source)
|
225
|
+
} as CozyRange;
|
226
|
+
}
|
227
|
+
|
228
|
+
const ranges = sourceRanges.map((source: Range) => toRange(source));
|
229
|
+
return { canvases, ranges };
|
198
230
|
}
|
199
231
|
|
200
232
|
const v3: Manifest = majorVersion === 2 ? convertPresentation2(resource) : resource;
|
201
233
|
|
202
|
-
const canvases = parseV3(v3);
|
234
|
+
const { canvases, ranges } = parseV3(v3);
|
203
235
|
|
204
236
|
return {
|
205
237
|
source: v3,
|
206
238
|
id: v3.id,
|
207
239
|
majorVersion,
|
208
240
|
canvases,
|
241
|
+
structure: ranges,
|
209
242
|
getLabel: getLabel(v3),
|
210
|
-
getMetadata: getMetadata(v3)
|
243
|
+
getMetadata: getMetadata(v3),
|
244
|
+
getTableOfContents: getTableOfContents(ranges)
|
211
245
|
}
|
212
246
|
}
|
213
247
|
|
package/src/core/index.ts
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
import type { CozyRange, CozyTOCNode } from '../types';
|
2
|
+
|
3
|
+
export const getTableOfContents = (ranges: CozyRange[]) => () => {
|
4
|
+
|
5
|
+
const buildTree = (range: CozyRange, parent: CozyTOCNode | undefined, level: number = 0): CozyTOCNode => {
|
6
|
+
const node: CozyTOCNode = {
|
7
|
+
id: range.id,
|
8
|
+
type: 'range',
|
9
|
+
getLabel: range.getLabel,
|
10
|
+
children: [],
|
11
|
+
parent,
|
12
|
+
level
|
13
|
+
};
|
14
|
+
|
15
|
+
if (range.items && range.items.length > 0) {
|
16
|
+
range.items.forEach(item => {
|
17
|
+
if (item.source.type === 'Range') {
|
18
|
+
const childNode = buildTree(item as CozyRange, node, level + 1);
|
19
|
+
node.children.push(childNode);
|
20
|
+
} else {
|
21
|
+
node.children.push({
|
22
|
+
id: item.id,
|
23
|
+
type: 'canvas',
|
24
|
+
getLabel: item.getLabel,
|
25
|
+
children: [],
|
26
|
+
parent: node,
|
27
|
+
level: level + 1
|
28
|
+
});
|
29
|
+
}
|
30
|
+
});
|
31
|
+
}
|
32
|
+
|
33
|
+
return node;
|
34
|
+
};
|
35
|
+
|
36
|
+
const topRanges = ranges.filter(range => range.source.behavior?.includes('top'));
|
37
|
+
return topRanges.map(range => buildTree(range, undefined));
|
38
|
+
}
|
package/src/types.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { Manifest, Canvas, ImageService2, ImageService3, IIIFExternalWebResource, Collection } from '@iiif/presentation-3';
|
1
|
+
import type { Manifest, Canvas, ImageService2, ImageService3, IIIFExternalWebResource, Collection, Range } from '@iiif/presentation-3';
|
2
2
|
|
3
3
|
export type CozyParseResult =
|
4
4
|
| { type: 'collection', url: string, resource: CozyCollection }
|
@@ -50,12 +50,32 @@ export interface CozyManifest {
|
|
50
50
|
|
51
51
|
readonly canvases: CozyCanvas[];
|
52
52
|
|
53
|
+
readonly structure: CozyRange[];
|
54
|
+
|
53
55
|
getLabel(locale?: string): string | undefined;
|
54
56
|
|
57
|
+
getTableOfContents(): CozyTOCNode[];
|
58
|
+
|
55
59
|
getMetadata(locale?: string): CozyMetadata[];
|
56
60
|
|
57
61
|
}
|
58
62
|
|
63
|
+
export interface CozyRange {
|
64
|
+
|
65
|
+
readonly source: Range;
|
66
|
+
|
67
|
+
readonly id: string;
|
68
|
+
|
69
|
+
readonly items: (CozyCanvas | CozyRange)[];
|
70
|
+
|
71
|
+
readonly canvases: CozyCanvas[];
|
72
|
+
|
73
|
+
readonly ranges: CozyRange[];
|
74
|
+
|
75
|
+
getLabel(locale?: string): string | undefined;
|
76
|
+
|
77
|
+
}
|
78
|
+
|
59
79
|
export interface CozyCanvas {
|
60
80
|
|
61
81
|
readonly source: Canvas;
|
@@ -84,6 +104,22 @@ export interface CozyMetadata {
|
|
84
104
|
|
85
105
|
}
|
86
106
|
|
107
|
+
export interface CozyTOCNode {
|
108
|
+
|
109
|
+
readonly id: string;
|
110
|
+
|
111
|
+
readonly type: 'range' | 'canvas';
|
112
|
+
|
113
|
+
getLabel(locale?: string): string | undefined;
|
114
|
+
|
115
|
+
children: CozyTOCNode[];
|
116
|
+
|
117
|
+
parent?: CozyTOCNode;
|
118
|
+
|
119
|
+
level: number;
|
120
|
+
|
121
|
+
}
|
122
|
+
|
87
123
|
export type CozyImageResource =
|
88
124
|
| StaticImageResource
|
89
125
|
| ImageServiceResource;
|
package/test/Cozy.test.ts
CHANGED
@@ -1,13 +1,27 @@
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
2
|
-
import { Cozy } from '../src';
|
2
|
+
import { Cozy, CozyManifest } from '../src';
|
3
3
|
|
4
|
-
import { COLLECTION } from './fixtures';
|
4
|
+
import { COLLECTION, WITH_STRUCTURES } from './fixtures';
|
5
5
|
|
6
6
|
describe('Cozy', () => {
|
7
7
|
|
8
8
|
it('should parse collection manifests correctly', async () => {
|
9
|
-
const result = await Cozy.parseURL(COLLECTION)
|
9
|
+
const result = await Cozy.parseURL(COLLECTION);
|
10
10
|
expect(result.type).toBe('collection');
|
11
|
+
});
|
12
|
+
|
13
|
+
it('should parse strctures in presentation manifests', async () => {
|
14
|
+
const result = await Cozy.parseURL(WITH_STRUCTURES);
|
15
|
+
expect(result.type).toBe('manifest');
|
16
|
+
expect('resource' in result).toBeTruthy();
|
17
|
+
|
18
|
+
const manifest = (result as any).resource as CozyManifest;
|
19
|
+
expect(manifest.structure.length > 0).toBeTruthy();
|
20
|
+
|
21
|
+
const tableOfContents = manifest.getTableOfContents();
|
22
|
+
expect(tableOfContents.length).toBe(1);
|
23
|
+
expect(tableOfContents[0].children.length).toBe(14);
|
11
24
|
})
|
12
25
|
|
13
26
|
});
|
27
|
+
|
package/test/fixtures.ts
CHANGED