cozy-iiif 0.1.3 → 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 +241 -169
- package/dist/types.d.ts +57 -21
- package/package.json +6 -4
- package/src/Cozy.ts +88 -8
- package/src/core/index.ts +1 -0
- package/src/core/manifest.ts +38 -0
- package/src/types.ts +86 -21
- package/test/Cozy.test.ts +27 -0
- package/test/fixtures.ts +5 -0
- package/vitest.config.ts +7 -0
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 Te = class W {
|
|
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 Te = class W {
|
|
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 Ke(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 Qe(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 Xe(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 w(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 w(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 tt(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 at(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 ft(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 G = class z {
|
|
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 G = class z {
|
|
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 G = class z {
|
|
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 K = (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 K = (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 K = (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 K = (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,14 +715,18 @@ const K = (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") ? {
|
719
|
+
type: "collection",
|
720
|
+
url: t,
|
721
|
+
resource: Pt(i, a)
|
722
|
+
} : {
|
690
723
|
type: "manifest",
|
691
724
|
url: t,
|
692
|
-
resource:
|
725
|
+
resource: Ot(i, a)
|
693
726
|
};
|
694
727
|
}
|
695
728
|
if (s.includes("image/2") || s.includes("image/3")) {
|
696
|
-
const a =
|
729
|
+
const a = Ut(i);
|
697
730
|
return a ? {
|
698
731
|
type: "iiif-image",
|
699
732
|
url: t,
|
@@ -717,37 +750,75 @@ const K = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profi
|
|
717
750
|
};
|
718
751
|
}
|
719
752
|
}
|
720
|
-
},
|
753
|
+
}, Pt = (t, e) => {
|
721
754
|
const r = (n) => {
|
722
755
|
const a = [];
|
723
|
-
return new
|
724
|
-
|
725
|
-
|
756
|
+
return new k({
|
757
|
+
manifest: [(c) => a.push(c)]
|
758
|
+
}).traverseCollection(n), a.map((c) => ({
|
759
|
+
id: c.id,
|
760
|
+
type: c.type,
|
761
|
+
getLabel: L(c),
|
762
|
+
source: c
|
763
|
+
}));
|
764
|
+
}, i = e === 2 ? te(t) : t, s = r(i);
|
765
|
+
return {
|
766
|
+
source: i,
|
767
|
+
id: i.id,
|
768
|
+
majorVersion: e,
|
769
|
+
items: s,
|
770
|
+
getLabel: L(i),
|
771
|
+
getMetadata: x(i)
|
772
|
+
};
|
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);
|
726
782
|
}]
|
727
|
-
}).traverseManifest(
|
728
|
-
|
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];
|
729
798
|
return {
|
730
|
-
source:
|
731
|
-
id:
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
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)
|
738
806
|
};
|
739
|
-
});
|
740
|
-
|
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);
|
741
810
|
return {
|
742
811
|
source: i,
|
743
812
|
id: i.id,
|
744
813
|
majorVersion: e,
|
745
814
|
canvases: s,
|
746
|
-
|
747
|
-
|
815
|
+
structure: n,
|
816
|
+
getLabel: L(i),
|
817
|
+
getMetadata: x(i),
|
818
|
+
getTableOfContents: kt(n)
|
748
819
|
};
|
749
|
-
},
|
750
|
-
const { width: e, height: r } = t, i =
|
820
|
+
}, Ut = (t) => {
|
821
|
+
const { width: e, height: r } = t, i = se(t);
|
751
822
|
if (i)
|
752
823
|
return {
|
753
824
|
type: i.profileLevel === 0 ? "level0" : "dynamic",
|
@@ -755,21 +826,22 @@ const K = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profi
|
|
755
826
|
width: e,
|
756
827
|
height: r,
|
757
828
|
majorVersion: i.majorVersion,
|
758
|
-
serviceUrl:
|
829
|
+
serviceUrl: ne(v(t, "id"))
|
759
830
|
};
|
760
831
|
};
|
761
832
|
export {
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
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
|
775
847
|
};
|