cozy-iiif 0.1.5 → 0.2.0
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/README.md +189 -9
- package/dist/Cozy.d.ts +1 -0
- package/dist/helpers/import-annotations.d.ts +3 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +93 -0
- package/dist/index.js +167 -164
- package/dist/types.d.ts +2 -1
- package/package.json +4 -2
- package/src/Cozy.ts +103 -102
- package/src/helpers/import-annotations.ts +115 -0
- package/src/helpers/index.ts +1 -0
- package/src/types.ts +3 -1
- package/test/Cozy.test.ts +1 -1
- package/test/annotations/fixtures.ts +135 -0
- package/test/annotations/import-annotations.test.ts +46 -0
- package/vite.config.ts +1 -0
package/dist/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { g as v, a as x, b as L } from "./resource-DS2brz47.js";
|
2
|
-
import { c as
|
3
|
-
var
|
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", V = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", pe = "http://library.stanford.edu/iiif/image-api/conformance.html#level0", ve = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", F = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", he = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0", ue = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", W = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", fe = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0", me = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", B = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", ge = "http://iiif.io/api/image/1/level0.json", de = "http://iiif.io/api/image/1/profiles/level0.json", ye = "http://iiif.io/api/image/1/level1.json", Ae = "http://iiif.io/api/image/1/profiles/level1.json", H = "http://iiif.io/api/image/1/level2.json", J = "http://iiif.io/api/image/1/profiles/level2.json", Ce = "http://iiif.io/api/image/2/level0.json", be = "http://iiif.io/api/image/2/profiles/level0.json", Re = "http://iiif.io/api/image/2/level1.json", Le = "http://iiif.io/api/image/2/profiles/level1.json", G = "http://iiif.io/api/image/2/level2.json", z = "http://iiif.io/api/image/2/profiles/level2.json", we = "level0", Ie = "level1", K = "level2", Se = "http://iiif.io/api/image/2/level0", Te = "http://iiif.io/api/image/2/level1", Q = "http://iiif.io/api/image/2/level2", xe = [Q, V, F, W, B, H, J, G, z, K], $e = [Se, Te, Q, ce, le, V, pe, ve, F, he, ue, W, fe, me, B, ge, de, ye, Ae, H, J, Ce, be, Re, Le, G, z, we, Ie, K], Me = $e;
|
4
4
|
function h(t) {
|
5
5
|
for (let e in t) (typeof t[e] > "u" || t[e] === null) && delete t[e];
|
6
6
|
return t;
|
@@ -8,8 +8,8 @@ function h(t) {
|
|
8
8
|
function b(t) {
|
9
9
|
return Array.isArray(t) ? t : t ? [t] : [];
|
10
10
|
}
|
11
|
-
var je = Object.defineProperty,
|
12
|
-
function
|
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, y = (t, e, r) => (ke(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 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`);
|
@@ -21,7 +21,7 @@ function ke(t) {
|
|
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 Oe = 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
|
}
|
@@ -99,7 +99,7 @@ var Pe = class X {
|
|
99
99
|
}
|
100
100
|
traverseUnknown(e) {
|
101
101
|
if (!e["@type"] || typeof e == "string") return e;
|
102
|
-
switch (
|
102
|
+
switch (Pe(e)) {
|
103
103
|
case "sc:Collection":
|
104
104
|
return this.traverseCollection(e);
|
105
105
|
case "sc:Manifest":
|
@@ -152,8 +152,8 @@ var Pe = class X {
|
|
152
152
|
return typeof n > "u" && !this.options.allowUndefinedReturn ? i : n;
|
153
153
|
}, e);
|
154
154
|
}
|
155
|
-
},
|
156
|
-
function
|
155
|
+
}, Ue = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", De = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", Ee = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", Ne = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", qe = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", _e = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", Ve = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", Fe = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", We = "http://iiif.io/api/image/1/level1.json", Be = "http://iiif.io/api/image/1/profiles/level1.json", He = "http://iiif.io/api/image/1/level2.json", Je = "http://iiif.io/api/image/1/profiles/level2.json", Ge = "http://iiif.io/api/image/2/level1.json", ze = "http://iiif.io/api/image/2/profiles/level1.json", Ke = "http://iiif.io/api/image/2/level2.json", Qe = "http://iiif.io/api/image/2/profiles/level2.json", Xe = "level1", Ye = "level2", Ze = "http://iiif.io/api/image/2/level1", et = "http://iiif.io/api/image/2/level2", tt = [Ze, et, Ue, De, Ee, Ne, qe, _e, Ve, Fe, We, Be, He, Je, Ge, ze, Ke, Qe, Xe, Ye], $ = { attributionLabel: "Attribution", providerId: "http://example.org/provider", providerName: "Unknown" };
|
156
|
+
function rt(t) {
|
157
157
|
if (typeof t == "string") return [t];
|
158
158
|
if (!t) return [];
|
159
159
|
let e = Array.isArray(t) ? t : [t], r = [];
|
@@ -168,7 +168,7 @@ function tt(t) {
|
|
168
168
|
}
|
169
169
|
function R(t, e = "none") {
|
170
170
|
if (!t) return { none: [""] };
|
171
|
-
let r =
|
171
|
+
let r = rt(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 || "");
|
@@ -185,12 +185,12 @@ function R(t, e = "none") {
|
|
185
185
|
}
|
186
186
|
function Y(t) {
|
187
187
|
if (Array.isArray(t)) return Y(t.find((e) => typeof e == "string"));
|
188
|
-
if (
|
189
|
-
if (
|
190
|
-
if (
|
188
|
+
if (xe.indexOf(t) !== -1) return "level2";
|
189
|
+
if (tt.indexOf(t) !== -1) return "level1";
|
190
|
+
if (Me.indexOf(t) !== -1) return "level0";
|
191
191
|
if (typeof t == "string") return t;
|
192
192
|
}
|
193
|
-
function
|
193
|
+
function it(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 rt(t) {
|
|
203
203
|
return "ImageApiSelector";
|
204
204
|
}
|
205
205
|
}
|
206
|
-
function
|
206
|
+
function st(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":
|
@@ -236,15 +236,15 @@ 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 nt = ["Collection", "Manifest", "Annotation", "AnnotationPage", "Range", "Service"];
|
240
|
+
function j(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 = st(i);
|
244
244
|
if (n) return n;
|
245
245
|
}
|
246
246
|
if (s) {
|
247
|
-
let n =
|
247
|
+
let n = it(s);
|
248
248
|
if (n) return n;
|
249
249
|
}
|
250
250
|
if (r) {
|
@@ -266,7 +266,7 @@ function M(t) {
|
|
266
266
|
return "TextualBody";
|
267
267
|
}
|
268
268
|
}
|
269
|
-
if (r &&
|
269
|
+
if (r && nt.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 M(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 at = /http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;
|
278
|
+
function ot(t) {
|
279
|
+
let e = t.match(at);
|
280
280
|
return e ? e[0] : t;
|
281
281
|
}
|
282
|
-
function
|
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 a of n) {
|
285
|
-
let o = a ?
|
285
|
+
let o = a ? ot(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,15 +291,15 @@ function ot(t, e = "Rights/License", r = "none") {
|
|
291
291
|
}
|
292
292
|
return [i, s];
|
293
293
|
}
|
294
|
-
var
|
295
|
-
function
|
294
|
+
var lt = ["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 pt(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"), lt.indexOf(i) === -1 && r.push(i);
|
299
299
|
if (e.length) return r.length === 1 ? r[0] : r;
|
300
300
|
}
|
301
301
|
}
|
302
|
-
function
|
302
|
+
function vt(t) {
|
303
303
|
return t ? t.map((e) => ({ label: R(e.label), value: R(e.value) })) : [];
|
304
304
|
}
|
305
305
|
var E = 0;
|
@@ -311,16 +311,16 @@ 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(D) : t.motivation && (r = D(t.motivation)), { "@context": t["@context"] ?
|
314
|
+
return Array.isArray(t.motivation) ? r = t.motivation.map(D) : t.motivation && (r = D(t.motivation)), { "@context": t["@context"] ? pt(t["@context"]) : void 0, id: (t["@id"] || Z(t)).trim(), type: j(t), behavior: e.length ? e : void 0, height: t.height ? t.height : void 0, width: t.width ? t.width : void 0, motivation: r, viewingDirection: t.viewingDirection, profile: t.profile, format: t.format ? t.format : void 0, duration: void 0, timeMode: void 0 };
|
315
315
|
}
|
316
316
|
function g(t) {
|
317
|
-
let [e, 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:
|
317
|
+
let [e, r] = ct(t.license), i = [...t.metadata ? vt(t.metadata) : [], ...r];
|
318
|
+
return { rights: e, metadata: i.length ? i : void 0, label: t.label ? R(t.label) : void 0, requiredStatement: t.attribution ? { label: R($.attributionLabel), value: R(t.attribution) } : void 0, navDate: t.navDate, summary: t.description ? R(t.description) : void 0, thumbnail: ht(t.thumbnail) };
|
319
319
|
}
|
320
|
-
function
|
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));
|
322
322
|
}
|
323
|
-
function
|
323
|
+
function ut(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 ht(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: j(i) });
|
333
333
|
return r.length ? r : void 0;
|
334
334
|
}
|
335
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: $.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:
|
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: ut(t), rendering: t.rendering, seeAlso: t.seeAlso, start: t.startCanvas, service: t.service ? b(t.service) : void 0, supplementary: r ? [r] : void 0 };
|
338
338
|
}
|
339
|
-
function
|
339
|
+
function ft(t) {
|
340
340
|
return { chars: t.chars, format: t.format ? t.format : void 0, language: t.language };
|
341
341
|
}
|
342
|
-
function
|
342
|
+
function mt(t) {
|
343
343
|
return h({ ...m(t), ...g(t), ...A(t), items: t.members });
|
344
344
|
}
|
345
|
-
function
|
345
|
+
function gt(t) {
|
346
346
|
let e = [], r = [], i;
|
347
347
|
for (let n of t.sequences || []) n.canvases.length && e.push(...n.canvases), n.behavior && r.push(...n.behavior), n.startCanvas && (i = n.startCanvas);
|
348
348
|
let s = 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:
|
349
|
+
return r.length && (s.behavior ? s.behavior.push(...r) : s.behavior = r), h({ ...s, ...g(t), ...A(t), start: i, items: e, structures: dt(t.structures) });
|
350
350
|
}
|
351
|
-
function
|
351
|
+
function dt(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 gt(t) {
|
|
359
359
|
}
|
360
360
|
return t.filter((i) => r.indexOf(i.id) === -1);
|
361
361
|
}
|
362
|
-
function
|
362
|
+
function yt(t) {
|
363
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
|
365
|
+
function At(t) {
|
366
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 Ct(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 bt(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,7 +381,7 @@ function Ct(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: M(r.selector) };
|
385
385
|
} else return encodeURI(r["@id"]).trim();
|
386
386
|
}
|
387
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) });
|
@@ -391,30 +391,30 @@ function N(t) {
|
|
391
391
|
}
|
392
392
|
function ee(t) {
|
393
393
|
let e = t;
|
394
|
-
return h({ ...m(e), ...g(e), ...A(e), ...
|
394
|
+
return h({ ...m(e), ...g(e), ...A(e), ...ft(e) });
|
395
395
|
}
|
396
|
-
function
|
396
|
+
function Rt(t) {
|
397
397
|
let e = [];
|
398
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
|
400
|
+
function Lt(t) {
|
401
401
|
return h({ ...m(t), ...g(t), ...A(t), items: t.members });
|
402
402
|
}
|
403
|
-
function
|
403
|
+
function wt(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"] = j(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
|
407
|
+
function It(t) {
|
408
408
|
return h({ ...m(t), ...g(t), ...A(t) });
|
409
409
|
}
|
410
|
-
var
|
410
|
+
var St = new Oe({ collection: [mt], manifest: [gt], canvas: [yt], annotationList: [At], sequence: [Ct], annotation: [bt], contentResource: [ee], choice: [Rt], range: [Lt], service: [wt], layer: [It] });
|
411
411
|
function te(t) {
|
412
|
-
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" ?
|
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 M(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 [M(t.default), ...(Array.isArray(t.item) ? t.item : [t.item]).map(M)];
|
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
|
}
|
@@ -425,7 +425,7 @@ function w(...t) {
|
|
425
425
|
return (e) => t.reduce((r, i) => i(r), e);
|
426
426
|
}
|
427
427
|
var q = ["Collection", "Manifest", "Canvas", "AnnotationPage", "AnnotationCollection", "Annotation", "ContentResource", "Range", "Service", "Selector", "Agent"];
|
428
|
-
function
|
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");
|
431
431
|
if (typeof t != "object") {
|
@@ -527,7 +527,7 @@ var k = class re {
|
|
527
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 = Tt(e, i);
|
531
531
|
switch (s) {
|
532
532
|
case "Collection":
|
533
533
|
return this.traverseCollection(e, r);
|
@@ -570,16 +570,16 @@ const ie = (t) => v(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
570
570
|
return `${i}/full/full/0/default.jpg`;
|
571
571
|
}
|
572
572
|
return `${i}/full/!${e},${r}/0/default.jpg`;
|
573
|
-
},
|
573
|
+
}, xt = (t, e, r) => {
|
574
574
|
const i = v(t, "id"), s = t.profile || "";
|
575
575
|
if (typeof s == "string" && (s.includes("level0") || s.includes("level:0"))) return;
|
576
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
577
|
return `${i}/${d}/!${l},${I}/0/default.jpg`;
|
578
|
-
},
|
578
|
+
}, $t = (t) => (e, r = 400) => {
|
579
579
|
if (t.type === "dynamic")
|
580
|
-
return
|
580
|
+
return xt(t.service, e, r);
|
581
581
|
console.error("Level 0 or static image canvas: unspported");
|
582
|
-
},
|
582
|
+
}, Mt = (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);
|
@@ -612,7 +612,7 @@ const ie = (t) => v(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
612
612
|
};
|
613
613
|
return a.profileLevel === 0 ? o : {
|
614
614
|
...o,
|
615
|
-
getRegionURL:
|
615
|
+
getRegionURL: $t(o)
|
616
616
|
};
|
617
617
|
} else
|
618
618
|
return {
|
@@ -623,7 +623,7 @@ const ie = (t) => v(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
623
623
|
url: s,
|
624
624
|
format: e
|
625
625
|
};
|
626
|
-
},
|
626
|
+
}, kt = (t) => {
|
627
627
|
const e = [];
|
628
628
|
return new k({
|
629
629
|
annotation: [(i) => {
|
@@ -633,7 +633,7 @@ const ie = (t) => v(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
633
633
|
}
|
634
634
|
}]
|
635
635
|
}).traverseCanvas(t), e;
|
636
|
-
},
|
636
|
+
}, Pt = (t) => () => {
|
637
637
|
const e = (i, s, n = 0) => {
|
638
638
|
const a = {
|
639
639
|
id: i.id,
|
@@ -662,95 +662,97 @@ const ie = (t) => v(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
662
662
|
var s;
|
663
663
|
return (s = i.source.behavior) == null ? void 0 : s.includes("top");
|
664
664
|
}).map((i) => e(i, void 0));
|
665
|
-
},
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
if (e = await fetch(t), !e.ok)
|
679
|
-
return {
|
680
|
-
type: "error",
|
681
|
-
code: "INVALID_HTTP_RESPONSE",
|
682
|
-
message: `Server responded: HTTP ${e.status} ${e.statusText ? `(${e.statusText})` : ""}`
|
683
|
-
};
|
684
|
-
} catch (i) {
|
685
|
-
return {
|
686
|
-
type: "error",
|
687
|
-
code: "FETCH_ERROR",
|
688
|
-
message: i instanceof Error ? i.message : "Failed to fetch resource"
|
689
|
-
};
|
690
|
-
}
|
691
|
-
const r = e.headers.get("content-type");
|
692
|
-
if (r != null && r.startsWith("image/"))
|
693
|
-
return {
|
694
|
-
type: "plain-image",
|
695
|
-
url: t
|
696
|
-
};
|
697
|
-
if (r != null && r.includes("text/html"))
|
698
|
-
return {
|
699
|
-
type: "webpage",
|
700
|
-
url: t
|
701
|
-
};
|
702
|
-
try {
|
703
|
-
const i = await e.json(), s = Array.isArray(i["@context"]) ? i["@context"].find((a) => a.includes("iiif.io/api/")) : i["@context"];
|
704
|
-
if (!s)
|
705
|
-
return {
|
706
|
-
type: "error",
|
707
|
-
code: "INVALID_MANIFEST",
|
708
|
-
message: "Missing @context"
|
709
|
-
};
|
710
|
-
if (!v(i, "id"))
|
711
|
-
return {
|
712
|
-
type: "error",
|
713
|
-
code: "INVALID_MANIFEST",
|
714
|
-
message: "Missing id property"
|
715
|
-
};
|
716
|
-
if (s.includes("presentation/2") || s.includes("presentation/3")) {
|
717
|
-
const a = s.includes("presentation/2") ? 2 : 3;
|
718
|
-
return v(i, "type").includes("Collection") ? {
|
719
|
-
type: "collection",
|
720
|
-
url: t,
|
721
|
-
resource: Pt(i, a)
|
722
|
-
} : {
|
723
|
-
type: "manifest",
|
724
|
-
url: t,
|
725
|
-
resource: Ot(i, a)
|
726
|
-
};
|
727
|
-
}
|
728
|
-
if (s.includes("image/2") || s.includes("image/3")) {
|
729
|
-
const a = Ut(i);
|
730
|
-
return a ? {
|
731
|
-
type: "iiif-image",
|
732
|
-
url: t,
|
733
|
-
resource: a
|
734
|
-
} : {
|
735
|
-
type: "error",
|
736
|
-
code: "INVALID_MANIFEST",
|
737
|
-
message: "Invalid image service definition"
|
738
|
-
};
|
739
|
-
}
|
740
|
-
return {
|
741
|
-
type: "error",
|
742
|
-
code: "INVALID_MANIFEST",
|
743
|
-
message: "JSON resource is not a recognized IIIF format"
|
744
|
-
};
|
745
|
-
} catch {
|
665
|
+
}, Ot = async (t) => {
|
666
|
+
try {
|
667
|
+
new URL(t);
|
668
|
+
} catch {
|
669
|
+
return {
|
670
|
+
type: "error",
|
671
|
+
code: "INVALID_URL",
|
672
|
+
message: "The provided input is not a valid URL"
|
673
|
+
};
|
674
|
+
}
|
675
|
+
let e;
|
676
|
+
try {
|
677
|
+
if (e = await fetch(t), !e.ok)
|
746
678
|
return {
|
747
679
|
type: "error",
|
748
|
-
code: "
|
749
|
-
message:
|
680
|
+
code: "INVALID_HTTP_RESPONSE",
|
681
|
+
message: `Server responded: HTTP ${e.status} ${e.statusText ? `(${e.statusText})` : ""}`
|
750
682
|
};
|
751
|
-
|
683
|
+
} catch (i) {
|
684
|
+
return {
|
685
|
+
type: "error",
|
686
|
+
code: "FETCH_ERROR",
|
687
|
+
message: i instanceof Error ? i.message : "Failed to fetch resource"
|
688
|
+
};
|
689
|
+
}
|
690
|
+
const r = e.headers.get("content-type");
|
691
|
+
if (r != null && r.startsWith("image/"))
|
692
|
+
return {
|
693
|
+
type: "plain-image",
|
694
|
+
url: t
|
695
|
+
};
|
696
|
+
if (r != null && r.includes("text/html"))
|
697
|
+
return {
|
698
|
+
type: "webpage",
|
699
|
+
url: t
|
700
|
+
};
|
701
|
+
try {
|
702
|
+
const i = await e.json();
|
703
|
+
return ae(i, t);
|
704
|
+
} catch {
|
705
|
+
return {
|
706
|
+
type: "error",
|
707
|
+
code: "UNSUPPORTED_FORMAT",
|
708
|
+
message: "Could not parse resource"
|
709
|
+
};
|
752
710
|
}
|
753
|
-
},
|
711
|
+
}, ae = (t, e) => {
|
712
|
+
const r = Array.isArray(t["@context"]) ? t["@context"].find((s) => s.includes("iiif.io/api/")) : t["@context"];
|
713
|
+
if (!r)
|
714
|
+
return {
|
715
|
+
type: "error",
|
716
|
+
code: "INVALID_MANIFEST",
|
717
|
+
message: "Missing @context"
|
718
|
+
};
|
719
|
+
const i = v(t, "id");
|
720
|
+
if (!i)
|
721
|
+
return {
|
722
|
+
type: "error",
|
723
|
+
code: "INVALID_MANIFEST",
|
724
|
+
message: "Missing id property"
|
725
|
+
};
|
726
|
+
if (r.includes("presentation/2") || r.includes("presentation/3")) {
|
727
|
+
const s = r.includes("presentation/2") ? 2 : 3;
|
728
|
+
return v(t, "type").includes("Collection") ? {
|
729
|
+
type: "collection",
|
730
|
+
url: e || i,
|
731
|
+
resource: Ut(t, s)
|
732
|
+
} : {
|
733
|
+
type: "manifest",
|
734
|
+
url: e || i,
|
735
|
+
resource: Dt(t, s)
|
736
|
+
};
|
737
|
+
}
|
738
|
+
if (r.includes("image/2") || r.includes("image/3")) {
|
739
|
+
const s = Et(t);
|
740
|
+
return s ? {
|
741
|
+
type: "iiif-image",
|
742
|
+
url: e || i,
|
743
|
+
resource: s
|
744
|
+
} : {
|
745
|
+
type: "error",
|
746
|
+
code: "INVALID_MANIFEST",
|
747
|
+
message: "Invalid image service definition"
|
748
|
+
};
|
749
|
+
}
|
750
|
+
return {
|
751
|
+
type: "error",
|
752
|
+
code: "INVALID_MANIFEST",
|
753
|
+
message: "JSON resource is not a recognized IIIF format"
|
754
|
+
};
|
755
|
+
}, Ut = (t, e) => {
|
754
756
|
const r = (n) => {
|
755
757
|
const a = [];
|
756
758
|
return new k({
|
@@ -770,7 +772,7 @@ const ie = (t) => v(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
770
772
|
getLabel: L(i),
|
771
773
|
getMetadata: x(i)
|
772
774
|
};
|
773
|
-
},
|
775
|
+
}, Dt = (t, e) => {
|
774
776
|
const r = (a) => {
|
775
777
|
const o = [], c = [];
|
776
778
|
new k({
|
@@ -782,24 +784,25 @@ const ie = (t) => v(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
782
784
|
}]
|
783
785
|
}).traverseManifest(a);
|
784
786
|
const u = o.map((l) => {
|
785
|
-
const d =
|
787
|
+
const d = kt(l);
|
786
788
|
return {
|
787
789
|
source: l,
|
788
790
|
id: l.id,
|
789
791
|
width: l.width,
|
790
792
|
height: l.height,
|
791
793
|
images: d,
|
794
|
+
annotations: l.annotations || [],
|
792
795
|
getLabel: L(l),
|
793
796
|
getMetadata: x(l),
|
794
|
-
getThumbnailURL:
|
797
|
+
getThumbnailURL: Mt(l, d)
|
795
798
|
};
|
796
799
|
}), 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)),
|
800
|
+
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)), oe = [...P, ...O];
|
798
801
|
return {
|
799
802
|
source: l,
|
800
803
|
id: l.id,
|
801
804
|
// Maintain original order
|
802
|
-
items: d.map((f) =>
|
805
|
+
items: d.map((f) => oe.find((S) => S.id === f.id)),
|
803
806
|
canvases: P,
|
804
807
|
ranges: O,
|
805
808
|
getLabel: L(l)
|
@@ -815,9 +818,9 @@ const ie = (t) => v(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
815
818
|
structure: n,
|
816
819
|
getLabel: L(i),
|
817
820
|
getMetadata: x(i),
|
818
|
-
getTableOfContents:
|
821
|
+
getTableOfContents: Pt(n)
|
819
822
|
};
|
820
|
-
},
|
823
|
+
}, Et = (t) => {
|
821
824
|
const { width: e, height: r } = t, i = se(t);
|
822
825
|
if (i)
|
823
826
|
return {
|
@@ -828,19 +831,19 @@ const ie = (t) => v(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
828
831
|
majorVersion: i.majorVersion,
|
829
832
|
serviceUrl: ne(v(t, "id"))
|
830
833
|
};
|
831
|
-
};
|
834
|
+
}, qt = { parse: ae, parseURL: Ot };
|
832
835
|
export {
|
833
|
-
|
836
|
+
qt as Cozy,
|
834
837
|
_ as getImageURLFromService,
|
835
|
-
|
838
|
+
kt as getImages,
|
836
839
|
L as getLabel,
|
837
840
|
x as getMetadata,
|
838
841
|
v as getPropertyValue,
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
842
|
+
$t as getRegionURL,
|
843
|
+
xt as getRegionURLFromService,
|
844
|
+
Ft as getStringValue,
|
845
|
+
Pt as getTableOfContents,
|
846
|
+
Mt as getThumbnailURL,
|
844
847
|
ie as isImageService,
|
845
848
|
ne as normalizeServiceUrl,
|
846
849
|
se as parseImageService
|
package/dist/types.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Manifest, Canvas, ImageService2, ImageService3, IIIFExternalWebResource, Collection, Range } from '@iiif/presentation-3';
|
1
|
+
import { Manifest, Canvas, ImageService2, ImageService3, IIIFExternalWebResource, Collection, Range, AnnotationPage } from '@iiif/presentation-3';
|
2
2
|
export type CozyParseResult = {
|
3
3
|
type: 'collection';
|
4
4
|
url: string;
|
@@ -60,6 +60,7 @@ export interface CozyCanvas {
|
|
60
60
|
readonly width: number;
|
61
61
|
readonly height: number;
|
62
62
|
readonly images: CozyImageResource[];
|
63
|
+
readonly annotations: AnnotationPage[];
|
63
64
|
getLabel(locale?: string): string;
|
64
65
|
getMetadata(locale?: string): CozyMetadata[];
|
65
66
|
getThumbnailURL(minSize?: number): string;
|