cozy-iiif 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { g as p, a as I, b as S } from "./resource-DS2brz47.js";
2
- import { c as Pt } from "./resource-DS2brz47.js";
3
- var te = "http://library.stanford.edu/iiif/image-api/compliance.html#level0", re = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", P = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", ie = "http://library.stanford.edu/iiif/image-api/conformance.html#level0", se = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", O = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", ne = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0", ae = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", U = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", oe = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0", ce = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", D = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", le = "http://iiif.io/api/image/1/level0.json", ve = "http://iiif.io/api/image/1/profiles/level0.json", pe = "http://iiif.io/api/image/1/level1.json", he = "http://iiif.io/api/image/1/profiles/level1.json", E = "http://iiif.io/api/image/1/level2.json", N = "http://iiif.io/api/image/1/profiles/level2.json", ue = "http://iiif.io/api/image/2/level0.json", fe = "http://iiif.io/api/image/2/profiles/level0.json", me = "http://iiif.io/api/image/2/level1.json", ge = "http://iiif.io/api/image/2/profiles/level1.json", q = "http://iiif.io/api/image/2/level2.json", _ = "http://iiif.io/api/image/2/profiles/level2.json", de = "level0", ye = "level1", V = "level2", Ae = "http://iiif.io/api/image/2/level0", Ce = "http://iiif.io/api/image/2/level1", F = "http://iiif.io/api/image/2/level2", be = [F, P, O, U, D, E, N, q, _, V], Re = [Ae, Ce, F, te, re, P, ie, se, O, ne, ae, U, oe, ce, D, le, ve, pe, he, E, N, ue, fe, me, ge, q, _, de, ye, V], Le = Re;
1
+ import { g as p, a as L, b } from "./resource-DS2brz47.js";
2
+ import { c as Ot } from "./resource-DS2brz47.js";
3
+ var re = "http://library.stanford.edu/iiif/image-api/compliance.html#level0", ie = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", O = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", se = "http://library.stanford.edu/iiif/image-api/conformance.html#level0", ne = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", U = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", ae = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0", oe = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", D = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", ce = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0", le = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", E = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", pe = "http://iiif.io/api/image/1/level0.json", ve = "http://iiif.io/api/image/1/profiles/level0.json", he = "http://iiif.io/api/image/1/level1.json", ue = "http://iiif.io/api/image/1/profiles/level1.json", N = "http://iiif.io/api/image/1/level2.json", q = "http://iiif.io/api/image/1/profiles/level2.json", fe = "http://iiif.io/api/image/2/level0.json", me = "http://iiif.io/api/image/2/profiles/level0.json", ge = "http://iiif.io/api/image/2/level1.json", de = "http://iiif.io/api/image/2/profiles/level1.json", _ = "http://iiif.io/api/image/2/level2.json", V = "http://iiif.io/api/image/2/profiles/level2.json", ye = "level0", Ae = "level1", F = "level2", Ce = "http://iiif.io/api/image/2/level0", be = "http://iiif.io/api/image/2/level1", W = "http://iiif.io/api/image/2/level2", Re = [W, O, U, D, E, N, q, _, V, F], Le = [Ce, be, W, re, ie, O, se, ne, U, ae, oe, D, ce, le, E, pe, ve, he, ue, N, q, fe, me, ge, de, _, V, ye, Ae, F], we = Le;
4
4
  function v(t) {
5
5
  for (let e in t) (typeof t[e] > "u" || t[e] === null) && delete t[e];
6
6
  return t;
@@ -8,25 +8,25 @@ function v(t) {
8
8
  function g(t) {
9
9
  return Array.isArray(t) ? t : t ? [t] : [];
10
10
  }
11
- var we = Object.defineProperty, Ie = (t, e, r) => e in t ? we(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, f = (t, e, r) => (Ie(t, typeof e != "symbol" ? e + "" : e, r), r), T = ["sc:Collection", "sc:Manifest", "sc:Canvas", "sc:AnnotationList", "oa:Annotation", "sc:Range", "sc:Layer", "sc:Sequence", "oa:Choice", "Service", "ContentResource"];
12
- function Se(t) {
11
+ var Ie = Object.defineProperty, Se = (t, e, r) => e in t ? Ie(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, f = (t, e, r) => (Se(t, typeof e != "symbol" ? e + "" : e, r), r), x = ["sc:Collection", "sc:Manifest", "sc:Canvas", "sc:AnnotationList", "oa:Annotation", "sc:Range", "sc:Layer", "sc:Sequence", "oa:Choice", "Service", "ContentResource"];
12
+ function Te(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 = T.indexOf(t["@type"]);
18
- if (e !== -1) return T[e];
17
+ let e = x.indexOf(t["@type"]);
18
+ if (e !== -1) return x[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 Te = class W {
24
+ var xe = class B {
25
25
  constructor(e, r = {}) {
26
26
  f(this, "traversals"), f(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 W({ collection: [e], manifest: [e], canvas: [e], annotationList: [e], sequence: [e], annotation: [e], contentResource: [e], choice: [e], range: [e], service: [e], layer: [e] });
29
+ return new B({ 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 (Se(e)) {
102
+ switch (Te(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
- }, xe = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", $e = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", je = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", Me = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", ke = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", Pe = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", Oe = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", Ue = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", De = "http://iiif.io/api/image/1/level1.json", Ee = "http://iiif.io/api/image/1/profiles/level1.json", Ne = "http://iiif.io/api/image/1/level2.json", qe = "http://iiif.io/api/image/1/profiles/level2.json", _e = "http://iiif.io/api/image/2/level1.json", Ve = "http://iiif.io/api/image/2/profiles/level1.json", Fe = "http://iiif.io/api/image/2/level2.json", We = "http://iiif.io/api/image/2/profiles/level2.json", He = "level1", Be = "level2", Je = "http://iiif.io/api/image/2/level1", Ge = "http://iiif.io/api/image/2/level2", ze = [Je, Ge, xe, $e, je, Me, ke, Pe, Oe, Ue, De, Ee, Ne, qe, _e, Ve, Fe, We, He, Be], R = { attributionLabel: "Attribution", providerId: "http://example.org/provider", providerName: "Unknown" };
156
- function Ke(t) {
155
+ }, $e = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", je = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", Me = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", ke = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", Pe = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", Oe = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", Ue = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", De = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", Ee = "http://iiif.io/api/image/1/level1.json", Ne = "http://iiif.io/api/image/1/profiles/level1.json", qe = "http://iiif.io/api/image/1/level2.json", _e = "http://iiif.io/api/image/1/profiles/level2.json", Ve = "http://iiif.io/api/image/2/level1.json", Fe = "http://iiif.io/api/image/2/profiles/level1.json", We = "http://iiif.io/api/image/2/level2.json", Be = "http://iiif.io/api/image/2/profiles/level2.json", He = "level1", Je = "level2", Ge = "http://iiif.io/api/image/2/level1", ze = "http://iiif.io/api/image/2/level2", Ke = [Ge, ze, $e, je, Me, ke, Pe, Oe, Ue, De, Ee, Ne, qe, _e, Ve, Fe, We, Be, He, Je], w = { attributionLabel: "Attribution", providerId: "http://example.org/provider", providerName: "Unknown" };
156
+ function Qe(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 Ke(t) {
168
168
  }
169
169
  function d(t, e = "none") {
170
170
  if (!t) return { none: [""] };
171
- let r = Ke(t), i = {};
171
+ let r = Qe(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 d(t, e = "none") {
185
185
  }
186
186
  function H(t) {
187
187
  if (Array.isArray(t)) return H(t.find((e) => typeof e == "string"));
188
- if (be.indexOf(t) !== -1) return "level2";
189
- if (ze.indexOf(t) !== -1) return "level1";
190
- if (Le.indexOf(t) !== -1) return "level0";
188
+ if (Re.indexOf(t) !== -1) return "level2";
189
+ if (Ke.indexOf(t) !== -1) return "level1";
190
+ if (we.indexOf(t) !== -1) return "level0";
191
191
  if (typeof t == "string") return t;
192
192
  }
193
- function Qe(t) {
193
+ function Xe(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 Xe(t) {
206
+ function Ye(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 x(t) {
235
+ function $(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 Ye = ["Collection", "Manifest", "Annotation", "AnnotationPage", "Range", "Service"];
240
- function w(t) {
239
+ var Ze = ["Collection", "Manifest", "Annotation", "AnnotationPage", "Range", "Service"];
240
+ function S(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 = Xe(i);
243
+ let n = Ye(i);
244
244
  if (n) return n;
245
245
  }
246
246
  if (s) {
247
- let n = Qe(s);
247
+ let n = Xe(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 && Ye.indexOf(r) !== -1) return r;
269
+ if (r && Ze.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 Ze = /http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;
278
- function et(t) {
279
- let e = t.match(Ze);
277
+ var et = /http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;
278
+ function tt(t) {
279
+ let e = t.match(et);
280
280
  return e ? e[0] : t;
281
281
  }
282
- function tt(t, e = "Rights/License", r = "none") {
282
+ function rt(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 ? et(a) : void 0;
285
+ let o = a ? tt(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 rt = ["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 it(t) {
294
+ var it = ["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 st(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"), rt.indexOf(i) === -1 && r.push(i);
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"), it.indexOf(i) === -1 && r.push(i);
299
299
  if (e.length) return r.length === 1 ? r[0] : r;
300
300
  }
301
301
  }
302
- function st(t) {
302
+ function nt(t) {
303
303
  return t ? t.map((e) => ({ label: d(e.label), value: d(e.value) })) : [];
304
304
  }
305
- var $ = 0;
306
- function B(t, e) {
305
+ var j = 0;
306
+ function J(t, e) {
307
307
  let r = encodeURI(t.id || t["@id"] || "").trim();
308
- return r && e ? `${r}/${e}` : r || ($++, `http://example.org/${t["@type"]}${e ? `/${e}` : ""}/${$}`);
308
+ return r && e ? `${r}/${e}` : r || (j++, `http://example.org/${t["@type"]}${e ? `/${e}` : ""}/${j}`);
309
309
  }
310
310
  function h(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(x) : t.motivation && (r = x(t.motivation)), { "@context": t["@context"] ? it(t["@context"]) : void 0, id: (t["@id"] || B(t)).trim(), type: w(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 };
314
+ return Array.isArray(t.motivation) ? r = t.motivation.map($) : t.motivation && (r = $(t.motivation)), { "@context": t["@context"] ? st(t["@context"]) : void 0, id: (t["@id"] || J(t)).trim(), type: S(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 u(t) {
317
- let [e, r] = tt(t.license), i = [...t.metadata ? st(t.metadata) : [], ...r];
318
- return { rights: e, metadata: i.length ? i : void 0, label: t.label ? d(t.label) : void 0, requiredStatement: t.attribution ? { label: d(R.attributionLabel), value: d(t.attribution) } : void 0, navDate: t.navDate, summary: t.description ? d(t.description) : void 0, thumbnail: nt(t.thumbnail) };
317
+ let [e, r] = rt(t.license), i = [...t.metadata ? nt(t.metadata) : [], ...r];
318
+ return { rights: e, metadata: i.length ? i : void 0, label: t.label ? d(t.label) : void 0, requiredStatement: t.attribution ? { label: d(w.attributionLabel), value: d(t.attribution) } : void 0, navDate: t.navDate, summary: t.description ? d(t.description) : void 0, thumbnail: at(t.thumbnail) };
319
319
  }
320
- function nt(t) {
320
+ function at(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 at(t) {
323
+ function ot(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,20 +329,20 @@ 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: w(i) });
332
+ } else i["@id"] && r.push({ id: i["@id"], type: S(i) });
333
333
  return r.length ? r : void 0;
334
334
  }
335
335
  function m(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: R.providerId, type: "Agent", homepage: e.length ? [e[0]] : void 0, logo: t.logo ? Array.isArray(t.logo) ? t.logo : [t.logo] : void 0, label: d(R.providerName) }] : void 0, partOf: at(t), rendering: t.rendering, seeAlso: t.seeAlso, start: t.startCanvas, service: t.service ? g(t.service) : void 0, supplementary: r ? [r] : void 0 };
337
+ return { provider: t.logo || e.length ? [{ id: w.providerId, type: "Agent", homepage: e.length ? [e[0]] : void 0, logo: t.logo ? Array.isArray(t.logo) ? t.logo : [t.logo] : void 0, label: d(w.providerName) }] : void 0, partOf: ot(t), rendering: t.rendering, seeAlso: t.seeAlso, start: t.startCanvas, service: t.service ? g(t.service) : void 0, supplementary: r ? [r] : void 0 };
338
338
  }
339
- function ot(t) {
339
+ function ct(t) {
340
340
  return { chars: t.chars, format: t.format ? t.format : void 0, language: t.language };
341
341
  }
342
- function ct(t) {
342
+ function lt(t) {
343
343
  return v({ ...h(t), ...u(t), ...m(t), items: t.members });
344
344
  }
345
- function lt(t) {
345
+ function pt(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 = h(t);
@@ -359,16 +359,16 @@ function vt(t) {
359
359
  }
360
360
  return t.filter((i) => r.indexOf(i.id) === -1);
361
361
  }
362
- function pt(t) {
363
- return v({ ...h(t), ...u(t), ...m(t), annotations: t.otherContent && t.otherContent.length ? t.otherContent : void 0, items: t.images && t.images.length ? [{ id: B(t, "annotation-page"), type: "AnnotationPage", items: t.images }] : void 0 });
364
- }
365
362
  function ht(t) {
366
- return v({ ...h(t), ...u(t), ...m(t), items: t.resources && t.resources.length ? t.resources : void 0 });
363
+ return v({ ...h(t), ...u(t), ...m(t), annotations: t.otherContent && t.otherContent.length ? t.otherContent : void 0, items: t.images && t.images.length ? [{ id: J(t, "annotation-page"), type: "AnnotationPage", items: t.images }] : void 0 });
367
364
  }
368
365
  function ut(t) {
369
- return !t.canvases || t.canvases.length === 0 ? { canvases: [], behavior: [] } : { canvases: t.canvases, behavior: t.viewingHint ? [t.viewingHint] : [], startCanvas: t.startCanvas };
366
+ return v({ ...h(t), ...u(t), ...m(t), items: t.resources && t.resources.length ? t.resources : void 0 });
370
367
  }
371
368
  function ft(t) {
369
+ return !t.canvases || t.canvases.length === 0 ? { canvases: [], behavior: [] } : { canvases: t.canvases, behavior: t.viewingHint ? [t.viewingHint] : [], startCanvas: t.startCanvas };
370
+ }
371
+ function mt(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,50 +381,50 @@ 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: L(r.selector) };
384
+ return { type: "SpecificResource", source: i, selector: I(r.selector) };
385
385
  } else return encodeURI(r["@id"]).trim();
386
386
  }
387
- return v({ ...h(t), ...u(t), ...m(t), target: e(t.on), body: Array.isArray(t.resource) ? t.resource.map(j) : j(t.resource) });
387
+ return v({ ...h(t), ...u(t), ...m(t), target: e(t.on), body: Array.isArray(t.resource) ? t.resource.map(M) : M(t.resource) });
388
388
  }
389
- function j(t) {
390
- return t.type === "Choice" ? t : J(t);
389
+ function M(t) {
390
+ return t.type === "Choice" ? t : G(t);
391
391
  }
392
- function J(t) {
392
+ function G(t) {
393
393
  let e = t;
394
- return v({ ...h(e), ...u(e), ...m(e), ...ot(e) });
394
+ return v({ ...h(e), ...u(e), ...m(e), ...ct(e) });
395
395
  }
396
- function mt(t) {
396
+ function gt(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), v({ ...h(t), ...u(t), items: e });
399
399
  }
400
- function gt(t) {
400
+ function dt(t) {
401
401
  return v({ ...h(t), ...u(t), ...m(t), items: t.members });
402
402
  }
403
- function dt(t) {
403
+ function yt(t) {
404
404
  let { "@id": e, "@type": r, "@context": i, profile: s, ...n } = t, a = {};
405
- return e && (a["@id"] = e), a["@type"] = w(t), a["@type"] === "unknown" && (i && i.length && (a["@context"] = i), a["@type"] = "Service"), s && (a.profile = H(s)), v({ ...a, ...n });
405
+ return e && (a["@id"] = e), a["@type"] = S(t), a["@type"] === "unknown" && (i && i.length && (a["@context"] = i), a["@type"] = "Service"), s && (a.profile = H(s)), v({ ...a, ...n });
406
406
  }
407
- function yt(t) {
407
+ function At(t) {
408
408
  return v({ ...h(t), ...u(t), ...m(t) });
409
409
  }
410
- var At = new Te({ collection: [ct], manifest: [lt], canvas: [pt], annotationList: [ht], sequence: [ut], annotation: [ft], contentResource: [J], choice: [mt], range: [gt], service: [dt], layer: [yt] });
411
- function Ct(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" ? At.traverseUnknown(t) : t;
410
+ var Ct = new xe({ collection: [lt], manifest: [pt], canvas: [ht], annotationList: [ut], sequence: [ft], annotation: [mt], contentResource: [G], choice: [gt], range: [dt], service: [yt], layer: [At] });
411
+ function z(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" ? Ct.traverseUnknown(t) : t;
413
413
  }
414
- function L(t) {
414
+ function I(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 [L(t.default), ...(Array.isArray(t.item) ? t.item : [t.item]).map(L)];
417
+ if (t["@type"] === "oa:Choice") return [I(t.default), ...(Array.isArray(t.item) ? t.item : [t.item]).map(I)];
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 b(t) {
421
+ function R(t) {
422
422
  return typeof t == "string" ? !1 : t && !t.type && "source" in t ? (t.type = "SpecificResource", !0) : !!t && t.type === "SpecificResource";
423
423
  }
424
424
  function C(...t) {
425
425
  return (e) => t.reduce((r, i) => i(r), e);
426
426
  }
427
- var M = ["Collection", "Manifest", "Canvas", "AnnotationPage", "AnnotationCollection", "Annotation", "ContentResource", "Range", "Service", "Selector", "Agent"];
427
+ var k = ["Collection", "Manifest", "Canvas", "AnnotationPage", "AnnotationCollection", "Annotation", "ContentResource", "Range", "Service", "Selector", "Agent"];
428
428
  function bt(t, e) {
429
429
  if (typeof t > "u" || t === null) throw new Error("Null or undefined is not a valid entity.");
430
430
  if (Array.isArray(t)) throw new Error("Array is not a valid entity");
@@ -433,24 +433,24 @@ function 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 = M.indexOf(t.type);
437
- if (r !== -1) return M[r];
436
+ let r = k.indexOf(t.type);
437
+ if (r !== -1) return k[r];
438
438
  }
439
439
  if (t.profile) return "Service";
440
440
  throw new Error("Resource type is not known");
441
441
  }
442
- var G = class z {
442
+ var T = class K {
443
443
  constructor(e, r = {}) {
444
444
  f(this, "traversals"), f(this, "options"), f(this, "_traverseManifest", C(this.traverseManifestItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseManifestStructures.bind(this), this.traverseInlineAnnotationPages.bind(this))), f(this, "_traverseCanvas", C(this.traverseCanvasItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseInlineAnnotationPages.bind(this))), f(this, "_traverseAnnotationPage", C(this.traverseAnnotationPageItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this))), f(this, "_traverseRange", C(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 z({ 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] });
447
+ return new K({ 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
450
  return e.thumbnail && (e.thumbnail = g(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 = g(e.service).map((r) => this.traverseService(r))), e.services && (e.services = g(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 = g(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 && (b(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;
453
+ return e.seeAlso && (e.seeAlso = e.seeAlso.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.service && (e.service = g(e.service).map((r) => this.traverseService(r))), e.services && (e.services = g(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 = g(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 && (R(e.start) ? e.start = this.traverseSpecificResource(e.start, "Canvas", e) : e.start = this.traverseType(e.start, { parent: e }, this.traversals.canvas)), e.rendering && (e.rendering = e.rendering.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.supplementary && (e.supplementary = e.supplementary.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e;
454
454
  }
455
455
  traverseCollectionItems(e) {
456
456
  return e.items && e.items.map((r) => r.type === "Collection" ? this.traverseCollection(r) : this.traverseManifest(r)), e;
@@ -501,14 +501,14 @@ var G = class z {
501
501
  return typeof e == "string" || !e || e && e.service && (e.service = g(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))), b(e) ? this.traverseSpecificResource(e, "ContentResource") : this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)), { parent: r }, this.traversals.contentResource);
504
+ return e.type === "Choice" && (e.items = e.items.map((i) => this.traverseContentResource(i, e))), R(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) : b(r) ? this.traverseSpecificResource(r, "Canvas", e) : r.type === "Manifest" ? this.traverseManifest(r, e) : this.traverseRange(r, e))), e;
511
+ return e.items && (e.items = e.items.map((r) => typeof r == "string" ? this.traverseCanvas({ id: r, type: "Canvas" }, e) : R(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);
@@ -552,14 +552,14 @@ var G = class z {
552
552
  }
553
553
  }
554
554
  };
555
- const K = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profile.toString().includes("iiif.io/api/image/"), Q = (t) => {
555
+ const Q = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profile.toString().includes("iiif.io/api/image/"), X = (t) => {
556
556
  const e = p(t, "type"), r = p(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
- }, k = (t, e, r) => {
562
+ }, P = (t, e, r) => {
563
563
  const i = p(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)) {
@@ -573,8 +573,8 @@ const K = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profi
573
573
  }, Rt = (t, e, r) => {
574
574
  const i = p(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: l } = e, y = c / l, A = y < 1, Y = Math.ceil(A ? r / y : r), Z = Math.ceil(A ? r : r / y), ee = `${Math.round(a)},${Math.round(o)},${Math.round(c)},${Math.round(l)}`;
577
- return `${i}/${ee}/!${Z},${Y}/0/default.jpg`;
576
+ const { x: a, y: o, w: c, h: l } = e, y = c / l, A = y < 1, Z = Math.ceil(A ? r / y : r), ee = Math.ceil(A ? r : r / y), te = `${Math.round(a)},${Math.round(o)},${Math.round(c)},${Math.round(l)}`;
577
+ return `${i}/${te}/!${ee},${Z}/0/default.jpg`;
578
578
  }, Lt = (t) => (e, r = 400) => {
579
579
  if (t.type === "dynamic")
580
580
  return Rt(t.service, e, r);
@@ -586,20 +586,20 @@ const K = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profi
586
586
  if (t.thumbnail && t.thumbnail.length > 0) {
587
587
  const l = t.thumbnail[0];
588
588
  if ("service" in l && Array.isArray(l.service)) {
589
- const y = l.service.find((A) => K(A));
589
+ const y = l.service.find((A) => Q(A));
590
590
  if (y)
591
- return k(y, c, o);
591
+ return P(y, c, o);
592
592
  }
593
593
  if ("id" in l) return l.id;
594
594
  }
595
595
  for (const l of e) {
596
596
  if (l.type === "dynamic" || l.type === "level0")
597
- return k(l.service, c, o);
597
+ return P(l.service, c, o);
598
598
  if (l.type === "static")
599
599
  return l.url;
600
600
  }
601
- }, X = (t) => t.endsWith("/info.json") ? t : `${t.endsWith("/") ? t : `${t}/`}info.json`, It = (t) => {
602
- const { format: e, height: r, width: i } = t, s = p(t, "id"), n = (t.service || []).find(K), a = n ? Q(n) : void 0;
601
+ }, Y = (t) => t.endsWith("/info.json") ? t : `${t.endsWith("/") ? t : `${t}/`}info.json`, It = (t) => {
602
+ const { format: e, height: r, width: i } = t, s = p(t, "id"), n = (t.service || []).find(Q), a = n ? X(n) : void 0;
603
603
  if (a) {
604
604
  const o = {
605
605
  source: t,
@@ -608,7 +608,7 @@ 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: X(p(n, "id"))
611
+ serviceUrl: Y(p(n, "id"))
612
612
  };
613
613
  return a.profileLevel === 0 ? o : {
614
614
  ...o,
@@ -625,7 +625,7 @@ const K = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profi
625
625
  };
626
626
  }, St = (t) => {
627
627
  const e = [];
628
- return new G({
628
+ return new T({
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");
@@ -633,7 +633,7 @@ const K = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profi
633
633
  }
634
634
  }]
635
635
  }).traverseCanvas(t), e;
636
- }, jt = {
636
+ }, Mt = {
637
637
  parseURL: async (t) => {
638
638
  try {
639
639
  new URL(t);
@@ -686,14 +686,18 @@ const K = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profi
686
686
  };
687
687
  if (s.includes("presentation/2") || s.includes("presentation/3")) {
688
688
  const a = s.includes("presentation/2") ? 2 : 3;
689
- return {
690
- type: "manifest",
689
+ return p(i, "type").includes("Collection") ? {
690
+ type: "collection",
691
691
  url: t,
692
692
  resource: Tt(i, a)
693
+ } : {
694
+ type: "manifest",
695
+ url: t,
696
+ resource: xt(i, a)
693
697
  };
694
698
  }
695
699
  if (s.includes("image/2") || s.includes("image/3")) {
696
- const a = xt(i);
700
+ const a = $t(i);
697
701
  return a ? {
698
702
  type: "iiif-image",
699
703
  url: t,
@@ -720,7 +724,27 @@ const K = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profi
720
724
  }, Tt = (t, e) => {
721
725
  const r = (n) => {
722
726
  const a = [];
723
- return new G({
727
+ return new T({
728
+ manifest: [(c) => a.push(c)]
729
+ }).traverseCollection(n), a.map((c) => ({
730
+ id: c.id,
731
+ type: c.type,
732
+ getLabel: b(c),
733
+ source: c
734
+ }));
735
+ }, i = e === 2 ? z(t) : t, s = r(i);
736
+ return {
737
+ source: i,
738
+ id: i.id,
739
+ majorVersion: e,
740
+ items: s,
741
+ getLabel: b(i),
742
+ getMetadata: L(i)
743
+ };
744
+ }, xt = (t, e) => {
745
+ const r = (n) => {
746
+ const a = [];
747
+ return new T({
724
748
  canvas: [(c) => {
725
749
  c.items && a.push(c);
726
750
  }]
@@ -732,22 +756,22 @@ const K = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profi
732
756
  width: c.width,
733
757
  height: c.height,
734
758
  images: l,
735
- getLabel: S(c),
736
- getMetadata: I(c),
759
+ getLabel: b(c),
760
+ getMetadata: L(c),
737
761
  getThumbnailURL: wt(c, l)
738
762
  };
739
763
  });
740
- }, i = e === 2 ? Ct(t) : t, s = r(i);
764
+ }, i = e === 2 ? z(t) : t, s = r(i);
741
765
  return {
742
766
  source: i,
743
767
  id: i.id,
744
768
  majorVersion: e,
745
769
  canvases: s,
746
- getLabel: S(i),
747
- getMetadata: I(i)
770
+ getLabel: b(i),
771
+ getMetadata: L(i)
748
772
  };
749
- }, xt = (t) => {
750
- const { width: e, height: r } = t, i = Q(t);
773
+ }, $t = (t) => {
774
+ const { width: e, height: r } = t, i = X(t);
751
775
  if (i)
752
776
  return {
753
777
  type: i.profileLevel === 0 ? "level0" : "dynamic",
@@ -755,21 +779,21 @@ const K = (t) => p(t, "type").startsWith("ImageService") || t.profile && t.profi
755
779
  width: e,
756
780
  height: r,
757
781
  majorVersion: i.majorVersion,
758
- serviceUrl: X(p(t, "id"))
782
+ serviceUrl: Y(p(t, "id"))
759
783
  };
760
784
  };
761
785
  export {
762
- jt as Cozy,
763
- k as getImageURLFromService,
786
+ Mt as Cozy,
787
+ P as getImageURLFromService,
764
788
  St as getImages,
765
- S as getLabel,
766
- I as getMetadata,
789
+ b as getLabel,
790
+ L as getMetadata,
767
791
  p as getPropertyValue,
768
792
  Lt as getRegionURL,
769
793
  Rt as getRegionURLFromService,
770
- Pt as getStringValue,
794
+ Ot as getStringValue,
771
795
  wt as getThumbnailURL,
772
- K as isImageService,
773
- X as normalizeServiceUrl,
774
- Q as parseImageService
796
+ Q as isImageService,
797
+ Y as normalizeServiceUrl,
798
+ X as parseImageService
775
799
  };
package/dist/types.d.ts CHANGED
@@ -1,5 +1,9 @@
1
- import { Manifest, Canvas, ImageService2, ImageService3, IIIFExternalWebResource } from '@iiif/presentation-3';
1
+ import { Manifest, Canvas, ImageService2, ImageService3, IIIFExternalWebResource, Collection } from '@iiif/presentation-3';
2
2
  export type CozyParseResult = {
3
+ type: 'collection';
4
+ url: string;
5
+ resource: CozyCollection;
6
+ } | {
3
7
  type: 'manifest';
4
8
  url: string;
5
9
  resource: CozyManifest;
@@ -18,6 +22,20 @@ export type CozyParseResult = {
18
22
  code: 'INVALID_URL' | 'INVALID_HTTP_RESPONSE' | 'FETCH_ERROR' | 'INVALID_MANIFEST' | 'UNSUPPORTED_FORMAT';
19
23
  message: string;
20
24
  };
25
+ export interface CozyCollection {
26
+ readonly majorVersion: number;
27
+ readonly source: Collection;
28
+ readonly id: string;
29
+ readonly items: CozyCollectionItem[];
30
+ getLabel(locale?: string): string | undefined;
31
+ getMetadata(locale?: string): CozyMetadata[];
32
+ }
33
+ export interface CozyCollectionItem {
34
+ readonly id: string;
35
+ readonly type: string;
36
+ readonly source: any;
37
+ getLabel(locale?: string): string | undefined;
38
+ }
21
39
  export interface CozyManifest {
22
40
  readonly majorVersion: number;
23
41
  readonly source: Manifest;
@@ -37,45 +55,45 @@ export interface CozyCanvas {
37
55
  getThumbnailURL(minSize?: number): string;
38
56
  }
39
57
  export interface CozyMetadata {
40
- label: string;
41
- value: string;
58
+ readonly label: string;
59
+ readonly value: string;
42
60
  }
43
61
  export type CozyImageResource = StaticImageResource | ImageServiceResource;
44
62
  export type ImageServiceResource = DynamicImageServiceResource | Level0ImageServiceResource;
45
63
  interface BaseImageResource {
46
64
  readonly source: IIIFExternalWebResource;
47
- type: 'static' | 'dynamic' | 'level0';
48
- width: number;
49
- height: number;
65
+ readonly type: 'static' | 'dynamic' | 'level0';
66
+ readonly width: number;
67
+ readonly height: number;
50
68
  }
51
69
  export interface StaticImageResource extends BaseImageResource {
52
- type: 'static';
53
- url: string;
70
+ readonly type: 'static';
71
+ readonly url: string;
54
72
  }
55
73
  export interface DynamicImageServiceResource extends BaseImageResource {
56
- type: 'dynamic';
57
- service: ImageService2 | ImageService3;
58
- serviceUrl: string;
59
- majorVersion: number;
74
+ readonly type: 'dynamic';
75
+ readonly service: ImageService2 | ImageService3;
76
+ readonly serviceUrl: string;
77
+ readonly majorVersion: number;
60
78
  getRegionURL(bounds: Bounds, minSize?: number): string;
61
79
  }
62
80
  export interface Level0ImageServiceResource extends BaseImageResource {
63
- type: 'level0';
64
- majorVersion: number;
65
- service: ImageService2 | ImageService3;
66
- serviceUrl: string;
81
+ readonly type: 'level0';
82
+ readonly majorVersion: number;
83
+ readonly service: ImageService2 | ImageService3;
84
+ readonly serviceUrl: string;
67
85
  }
68
86
  export interface ImageRequestOptions {
69
- width?: number;
70
- height?: number;
71
- region?: 'full' | 'square' | {
87
+ readonly width?: number;
88
+ readonly height?: number;
89
+ readonly region?: 'full' | 'square' | {
72
90
  x: number;
73
91
  y: number;
74
92
  width: number;
75
93
  height: number;
76
94
  };
77
- quality?: 'default' | 'color' | 'gray' | 'bitonal';
78
- format?: 'jpg' | 'png' | 'gif' | 'webp';
95
+ readonly quality?: 'default' | 'color' | 'gray' | 'bitonal';
96
+ readonly format?: 'jpg' | 'png' | 'gif' | 'webp';
79
97
  }
80
98
  export interface Bounds {
81
99
  x: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-iiif",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
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",
@@ -19,7 +19,8 @@
19
19
  "main": "dist/index.js",
20
20
  "types": "dist/index.d.ts",
21
21
  "scripts": {
22
- "build": "vite build"
22
+ "build": "vite build",
23
+ "test": "vitest"
23
24
  },
24
25
  "exports": {
25
26
  ".": "./dist/index.js",
@@ -27,7 +28,8 @@
27
28
  },
28
29
  "devDependencies": {
29
30
  "vite": "^6.2.2",
30
- "vite-plugin-dts": "^4.5.3"
31
+ "vite-plugin-dts": "^4.5.3",
32
+ "vitest": "^3.0.8"
31
33
  },
32
34
  "dependencies": {
33
35
  "@iiif/parser": "^2.1.7",
package/src/Cozy.ts CHANGED
@@ -1,7 +1,6 @@
1
- import type { Canvas, Manifest } from '@iiif/presentation-3';
1
+ import type { Canvas, Collection, Manifest } from '@iiif/presentation-3';
2
2
  import { convertPresentation2 } from '@iiif/parser/presentation-2';
3
3
  import { Traverse } from '@iiif/parser';
4
- import type { CozyCanvas, CozyManifest, CozyParseResult, ImageServiceResource } from './types';
5
4
  import {
6
5
  getImages,
7
6
  getLabel,
@@ -11,6 +10,14 @@ import {
11
10
  normalizeServiceUrl,
12
11
  parseImageService
13
12
  } from './core';
13
+ import type {
14
+ CozyCanvas,
15
+ CozyCollection,
16
+ CozyCollectionItem,
17
+ CozyManifest,
18
+ CozyParseResult,
19
+ ImageServiceResource
20
+ } from './types';
14
21
 
15
22
  export const Cozy = {
16
23
 
@@ -88,7 +95,13 @@ export const Cozy = {
88
95
  if (context.includes('presentation/2') || context.includes('presentation/3')) {
89
96
  const majorVersion = context.includes('presentation/2') ? 2 : 3;
90
97
 
91
- return {
98
+ const type = getPropertyValue(json, 'type');
99
+
100
+ return type.includes('Collection') ? {
101
+ type: 'collection',
102
+ url: input,
103
+ resource: parseCollectionResource(json, majorVersion)
104
+ } : {
92
105
  type: 'manifest',
93
106
  url: input,
94
107
  resource: parseManifestResource(json, majorVersion)
@@ -125,6 +138,39 @@ export const Cozy = {
125
138
 
126
139
  }
127
140
 
141
+ const parseCollectionResource = (resource: any, majorVersion: number): CozyCollection => {
142
+
143
+ const parseV3 = (collection: Collection) => {
144
+ const items: any[] = [];
145
+
146
+ const modelBuilder = new Traverse({
147
+ manifest: [item => items.push(item)]
148
+ });
149
+
150
+ modelBuilder.traverseCollection(collection);
151
+
152
+ return items.map(source => ({
153
+ id: source.id,
154
+ type: source.type,
155
+ getLabel: getLabel(source),
156
+ source
157
+ }) as CozyCollectionItem);
158
+ }
159
+
160
+ const v3: Collection = majorVersion === 2 ? convertPresentation2(resource) : resource;
161
+
162
+ const items = parseV3(v3);
163
+
164
+ return {
165
+ source: v3,
166
+ id: v3.id,
167
+ majorVersion,
168
+ items,
169
+ getLabel: getLabel(v3),
170
+ getMetadata: getMetadata(v3)
171
+ };
172
+ }
173
+
128
174
  const parseManifestResource = (resource: any, majorVersion: number): CozyManifest => {
129
175
 
130
176
  const parseV3 = (manifest: Manifest) => {
package/src/types.ts CHANGED
@@ -1,6 +1,7 @@
1
- import type { Manifest, Canvas, ImageService2, ImageService3, IIIFExternalWebResource } from '@iiif/presentation-3';
1
+ import type { Manifest, Canvas, ImageService2, ImageService3, IIIFExternalWebResource, Collection } from '@iiif/presentation-3';
2
2
 
3
3
  export type CozyParseResult =
4
+ | { type: 'collection', url: string, resource: CozyCollection }
4
5
  | { type: 'manifest'; url: string, resource: CozyManifest }
5
6
  | { type: 'iiif-image'; url: string, resource: CozyImageResource }
6
7
  | { type: 'plain-image'; url: string }
@@ -11,6 +12,34 @@ export type CozyParseResult =
11
12
  message: string;
12
13
  };
13
14
 
15
+ export interface CozyCollection {
16
+
17
+ readonly majorVersion: number;
18
+
19
+ readonly source: Collection;
20
+
21
+ readonly id: string;
22
+
23
+ readonly items: CozyCollectionItem[];
24
+
25
+ getLabel(locale?: string): string | undefined;
26
+
27
+ getMetadata(locale?: string): CozyMetadata[];
28
+
29
+ }
30
+
31
+ export interface CozyCollectionItem {
32
+
33
+ readonly id: string;
34
+
35
+ readonly type: string;
36
+
37
+ readonly source: any;
38
+
39
+ getLabel(locale?: string): string | undefined;
40
+
41
+ }
42
+
14
43
  export interface CozyManifest {
15
44
 
16
45
  readonly majorVersion: number;
@@ -49,9 +78,9 @@ export interface CozyCanvas {
49
78
 
50
79
  export interface CozyMetadata {
51
80
 
52
- label: string;
81
+ readonly label: string;
53
82
 
54
- value: string;
83
+ readonly value: string;
55
84
 
56
85
  }
57
86
 
@@ -67,31 +96,31 @@ interface BaseImageResource {
67
96
 
68
97
  readonly source: IIIFExternalWebResource;
69
98
 
70
- type: 'static' | 'dynamic' | 'level0';
99
+ readonly type: 'static' | 'dynamic' | 'level0';
71
100
 
72
- width: number;
101
+ readonly width: number;
73
102
 
74
- height: number;
103
+ readonly height: number;
75
104
 
76
105
  }
77
106
 
78
107
  export interface StaticImageResource extends BaseImageResource {
79
108
 
80
- type: 'static';
109
+ readonly type: 'static';
81
110
 
82
- url: string;
111
+ readonly url: string;
83
112
 
84
113
  }
85
114
 
86
115
  export interface DynamicImageServiceResource extends BaseImageResource {
87
116
 
88
- type: 'dynamic';
117
+ readonly type: 'dynamic';
89
118
 
90
- service: ImageService2 | ImageService3;
119
+ readonly service: ImageService2 | ImageService3;
91
120
 
92
- serviceUrl: string;
121
+ readonly serviceUrl: string;
93
122
 
94
- majorVersion: number;
123
+ readonly majorVersion: number;
95
124
 
96
125
  getRegionURL(bounds: Bounds, minSize?: number): string;
97
126
 
@@ -99,28 +128,28 @@ export interface DynamicImageServiceResource extends BaseImageResource {
99
128
 
100
129
  export interface Level0ImageServiceResource extends BaseImageResource {
101
130
 
102
- type: 'level0';
131
+ readonly type: 'level0';
103
132
 
104
- majorVersion: number;
133
+ readonly majorVersion: number;
105
134
 
106
- service: ImageService2 | ImageService3;
135
+ readonly service: ImageService2 | ImageService3;
107
136
 
108
- serviceUrl: string;
137
+ readonly serviceUrl: string;
109
138
 
110
139
  }
111
140
 
112
141
 
113
142
  export interface ImageRequestOptions {
114
143
 
115
- width?: number;
144
+ readonly width?: number;
116
145
 
117
- height?: number;
146
+ readonly height?: number;
118
147
 
119
- region?: 'full' | 'square' | { x: number; y: number; width: number; height: number };
148
+ readonly region?: 'full' | 'square' | { x: number; y: number; width: number; height: number };
120
149
 
121
- quality?: 'default' | 'color' | 'gray' | 'bitonal';
150
+ readonly quality?: 'default' | 'color' | 'gray' | 'bitonal';
122
151
 
123
- format?: 'jpg' | 'png' | 'gif' | 'webp';
152
+ readonly format?: 'jpg' | 'png' | 'gif' | 'webp';
124
153
 
125
154
  }
126
155
 
@@ -0,0 +1,13 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { Cozy } from '../src';
3
+
4
+ import { COLLECTION } from './fixtures';
5
+
6
+ describe('Cozy', () => {
7
+
8
+ it('should parse collection manifests correctly', async () => {
9
+ const result = await Cozy.parseURL(COLLECTION)
10
+ expect(result.type).toBe('collection');
11
+ })
12
+
13
+ });
@@ -0,0 +1,2 @@
1
+ export const COLLECTION =
2
+ 'https://www.davidrumsey.com/luna/servlet/iiif/collection/s/1k986a';
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ watch: false
6
+ }
7
+ });