cozy-iiif 0.4.1 → 0.4.2

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.
Files changed (2) hide show
  1. package/dist/index.js +219 -192
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { imageSize as ce } from "image-size";
2
- import { g, a as j, b as S } from "./resource-DS2brz47.js";
3
- import { c as Jt } from "./resource-DS2brz47.js";
4
- var le = "http://library.stanford.edu/iiif/image-api/compliance.html#level0", pe = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", V = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", ve = "http://library.stanford.edu/iiif/image-api/conformance.html#level0", he = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", F = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", ue = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0", fe = "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", me = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0", ge = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", z = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", de = "http://iiif.io/api/image/1/level0.json", ye = "http://iiif.io/api/image/1/profiles/level0.json", Ae = "http://iiif.io/api/image/1/level1.json", Ce = "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", be = "http://iiif.io/api/image/2/level0.json", Re = "http://iiif.io/api/image/2/profiles/level0.json", Le = "http://iiif.io/api/image/2/level1.json", we = "http://iiif.io/api/image/2/profiles/level1.json", G = "http://iiif.io/api/image/2/level2.json", K = "http://iiif.io/api/image/2/profiles/level2.json", Ie = "level0", Se = "level1", Q = "level2", xe = "http://iiif.io/api/image/2/level0", Te = "http://iiif.io/api/image/2/level1", X = "http://iiif.io/api/image/2/level2", $e = [X, V, F, W, z, H, J, G, K, Q], Me = [xe, Te, X, le, pe, V, ve, he, F, ue, fe, W, me, ge, z, de, ye, Ae, Ce, H, J, be, Re, Le, we, G, K, Ie, Se, Q], je = Me;
1
+ import { imageSize as le } from "image-size";
2
+ import { g, a as k, b as S } from "./resource-DS2brz47.js";
3
+ import { c as Qt } from "./resource-DS2brz47.js";
4
+ var pe = "http://library.stanford.edu/iiif/image-api/compliance.html#level0", ve = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", F = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", he = "http://library.stanford.edu/iiif/image-api/conformance.html#level0", ue = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", W = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", fe = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0", me = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", z = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", ge = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0", de = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", H = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", ye = "http://iiif.io/api/image/1/level0.json", Ae = "http://iiif.io/api/image/1/profiles/level0.json", Ce = "http://iiif.io/api/image/1/level1.json", be = "http://iiif.io/api/image/1/profiles/level1.json", J = "http://iiif.io/api/image/1/level2.json", G = "http://iiif.io/api/image/1/profiles/level2.json", Re = "http://iiif.io/api/image/2/level0.json", Le = "http://iiif.io/api/image/2/profiles/level0.json", we = "http://iiif.io/api/image/2/level1.json", Ie = "http://iiif.io/api/image/2/profiles/level1.json", K = "http://iiif.io/api/image/2/level2.json", Q = "http://iiif.io/api/image/2/profiles/level2.json", Se = "level0", xe = "level1", X = "level2", Te = "http://iiif.io/api/image/2/level0", Me = "http://iiif.io/api/image/2/level1", Y = "http://iiif.io/api/image/2/level2", $e = [Y, F, W, z, H, J, G, K, Q, X], je = [Te, Me, Y, pe, ve, F, he, ue, W, fe, me, z, ge, de, H, ye, Ae, Ce, be, J, G, Re, Le, we, Ie, K, Q, Se, xe, X], ke = je;
5
5
  function d(t) {
6
6
  for (let e in t) (typeof t[e] > "u" || t[e] === null) && delete t[e];
7
7
  return t;
@@ -9,35 +9,35 @@ function d(t) {
9
9
  function w(t) {
10
10
  return Array.isArray(t) ? t : t ? [t] : [];
11
11
  }
12
- var ke = Object.defineProperty, Pe = (t, e, r) => e in t ? ke(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, R = (t, e, r) => (Pe(t, typeof e != "symbol" ? e + "" : e, r), r), N = ["sc:Collection", "sc:Manifest", "sc:Canvas", "sc:AnnotationList", "oa:Annotation", "sc:Range", "sc:Layer", "sc:Sequence", "oa:Choice", "Service", "ContentResource"];
13
- function Oe(t) {
12
+ var Pe = Object.defineProperty, Oe = (t, e, r) => e in t ? Pe(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, R = (t, e, r) => (Oe(t, typeof e != "symbol" ? e + "" : e, r), r), E = ["sc:Collection", "sc:Manifest", "sc:Canvas", "sc:AnnotationList", "oa:Annotation", "sc:Range", "sc:Layer", "sc:Sequence", "oa:Choice", "Service", "ContentResource"];
13
+ function Ue(t) {
14
14
  if (typeof t > "u" || t === null) throw new Error("Null or undefined is not a valid entity.");
15
15
  if (Array.isArray(t)) throw new Error("Array is not a valid entity");
16
16
  if (typeof t != "object") throw new Error(`${typeof t} is not a valid entity`);
17
17
  if (typeof t["@type"] == "string") {
18
- let e = N.indexOf(t["@type"]);
19
- if (e !== -1) return N[e];
18
+ let e = E.indexOf(t["@type"]);
19
+ if (e !== -1) return E[e];
20
20
  }
21
21
  if (t.profile) return "Service";
22
22
  if (t.format || t["@type"]) return "ContentResource";
23
23
  throw new Error("Resource type is not known");
24
24
  }
25
- var Ue = class Y {
25
+ var De = class Z {
26
26
  constructor(e, r = {}) {
27
27
  R(this, "traversals"), R(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 };
28
28
  }
29
29
  static all(e) {
30
- return new Y({ collection: [e], manifest: [e], canvas: [e], annotationList: [e], sequence: [e], annotation: [e], contentResource: [e], choice: [e], range: [e], service: [e], layer: [e] });
30
+ return new Z({ collection: [e], manifest: [e], canvas: [e], annotationList: [e], sequence: [e], annotation: [e], contentResource: [e], choice: [e], range: [e], service: [e], layer: [e] });
31
31
  }
32
32
  traverseCollection(e) {
33
33
  return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseCollectionItems(e))), this.traversals.collection);
34
34
  }
35
35
  traverseCollectionItems(e) {
36
36
  if (this.options.mergeMemberProperties) {
37
- let r = [...(e.manifests || []).map((i) => typeof i == "string" ? { "@id": i, "@type": "sc:Manifest" } : i), ...(e.collections || []).map((i) => typeof i == "string" ? { "@id": i, "@type": "sc:Collection" } : i), ...e.members || []];
38
- delete e.collections, delete e.manifests, e.members = r;
37
+ let r = [...(e.manifests || []).map((n) => typeof n == "string" ? { "@id": n, "@type": "sc:Manifest" } : n), ...(e.collections || []).map((n) => typeof n == "string" ? { "@id": n, "@type": "sc:Collection" } : n), ...e.members || []], i = [], s = r.filter((n) => i.includes(n["@id"]) ? !1 : (i.push(n["@id"]), !0));
38
+ delete e.collections, delete e.manifests, e.members = s;
39
39
  }
40
- return e.manifests && (e.manifests = e.manifests.map((r) => this.traverseManifest(typeof r == "string" ? { "@id": r, "@type": "sc:Manifest" } : r))), e.collections && (e.collections = e.collections.map((r) => this.traverseCollection(typeof r == "string" ? { "@id": r, "@type": "sc:Collection" } : r))), e.members && (e.members = e.members.map((r) => typeof r == "string" ? r : this.traverseUnknown(r))), e;
40
+ return e.manifests && (e.manifests = e.manifests.map((r) => this.traverseManifest(typeof r == "string" ? { "@id": r, "@type": "sc:Manifest" } : r))), e.collections && (e.collections = e.collections.map((r) => this.traverseCollection(typeof r == "string" ? { "@id": r, "@type": "sc:Collection" } : r))), e.members && (e.members = e.members.map((r) => typeof r == "string" ? r : r["@type"] === "sc:Collection" ? this.traverseCollection(r) : r["@type"] === "sc:Manifest" ? this.traverseManifest(r) : this.traverseUnknown(r))), e;
41
41
  }
42
42
  traverseManifest(e) {
43
43
  return this.traverseType(this.traverseDescriptive(this.traverseLinking(this.traverseManifestItems(e))), this.traversals.manifest);
@@ -100,7 +100,7 @@ var Ue = class Y {
100
100
  }
101
101
  traverseUnknown(e) {
102
102
  if (!e["@type"] || typeof e == "string") return e;
103
- switch (Oe(e)) {
103
+ switch (Ue(e)) {
104
104
  case "sc:Collection":
105
105
  return this.traverseCollection(e);
106
106
  case "sc:Manifest":
@@ -153,8 +153,8 @@ var Ue = class Y {
153
153
  return typeof n > "u" && !this.options.allowUndefinedReturn ? i : n;
154
154
  }, e);
155
155
  }
156
- }, De = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", Ne = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", Ee = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", qe = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", _e = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", Be = "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", ze = "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", Ke = "http://iiif.io/api/image/2/profiles/level1.json", Qe = "http://iiif.io/api/image/2/level2.json", Xe = "http://iiif.io/api/image/2/profiles/level2.json", Ye = "level1", Ze = "level2", et = "http://iiif.io/api/image/2/level1", tt = "http://iiif.io/api/image/2/level2", rt = [et, tt, De, Ne, Ee, qe, _e, Be, Ve, Fe, We, ze, He, Je, Ge, Ke, Qe, Xe, Ye, Ze], k = { attributionLabel: "Attribution", providerId: "http://example.org/provider", providerName: "Unknown" };
157
- function it(t) {
156
+ }, Ne = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", Ee = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", _e = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", qe = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", Be = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", Ve = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", Fe = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", We = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", ze = "http://iiif.io/api/image/1/level1.json", He = "http://iiif.io/api/image/1/profiles/level1.json", Je = "http://iiif.io/api/image/1/level2.json", Ge = "http://iiif.io/api/image/1/profiles/level2.json", Ke = "http://iiif.io/api/image/2/level1.json", Qe = "http://iiif.io/api/image/2/profiles/level1.json", Xe = "http://iiif.io/api/image/2/level2.json", Ye = "http://iiif.io/api/image/2/profiles/level2.json", Ze = "level1", et = "level2", tt = "http://iiif.io/api/image/2/level1", rt = "http://iiif.io/api/image/2/level2", it = [tt, rt, Ne, Ee, _e, qe, Be, Ve, Fe, We, ze, He, Je, Ge, Ke, Qe, Xe, Ye, Ze, et], P = { attributionLabel: "Attribution", providerId: "http://example.org/provider", providerName: "" };
157
+ function st(t) {
158
158
  if (typeof t == "string") return [t];
159
159
  if (!t) return [];
160
160
  let e = Array.isArray(t) ? t : [t], r = [];
@@ -169,7 +169,7 @@ function it(t) {
169
169
  }
170
170
  function I(t, e = "none") {
171
171
  if (!t) return { none: [""] };
172
- let r = it(t), i = {};
172
+ let r = st(t), i = {};
173
173
  for (let s of r) {
174
174
  if (typeof s == "string") {
175
175
  i[e] = i[e] ? i[e] : [], i[e].push(s || "");
@@ -184,14 +184,14 @@ function I(t, e = "none") {
184
184
  }
185
185
  return Object.keys(i).length === 0 ? { none: [""] } : i;
186
186
  }
187
- function Z(t) {
188
- if (Array.isArray(t)) return Z(t.find((e) => typeof e == "string"));
187
+ function ee(t) {
188
+ if (Array.isArray(t)) return ee(t.find((e) => typeof e == "string"));
189
189
  if ($e.indexOf(t) !== -1) return "level2";
190
- if (rt.indexOf(t) !== -1) return "level1";
191
- if (je.indexOf(t) !== -1) return "level0";
190
+ if (it.indexOf(t) !== -1) return "level1";
191
+ if (ke.indexOf(t) !== -1) return "level0";
192
192
  if (typeof t == "string") return t;
193
193
  }
194
- function st(t) {
194
+ function nt(t) {
195
195
  let e = Array.isArray(t) ? t : [t];
196
196
  for (let r of e) switch (r) {
197
197
  case "http://iiif.io/api/image/2/context.json":
@@ -204,7 +204,7 @@ function st(t) {
204
204
  return "ImageApiSelector";
205
205
  }
206
206
  }
207
- function nt(t) {
207
+ function at(t) {
208
208
  switch (t) {
209
209
  case "http://iiif.io/api/image/2/level0.json":
210
210
  case "http://iiif.io/api/image/2/level1.json":
@@ -233,19 +233,19 @@ function nt(t) {
233
233
  return "AutoCompleteService1";
234
234
  }
235
235
  }
236
- function E(t) {
236
+ function _(t) {
237
237
  for (let e of ["sc", "oa", "dcterms", "dctypes", "iiif"]) if (t.startsWith(`${e}:`)) return t.slice(e.length + 1);
238
238
  return t;
239
239
  }
240
- var at = ["Collection", "Manifest", "Annotation", "AnnotationPage", "Range", "Service"];
241
- function U(t) {
240
+ var ot = ["Collection", "Manifest", "Annotation", "AnnotationPage", "Range", "Service"];
241
+ function D(t) {
242
242
  let e = t["@id"] || t.id, r = t["@type"] || t.type, i = t.profile || void 0, s = t["@context"] || void 0;
243
243
  if (i) {
244
- let n = nt(i);
244
+ let n = at(i);
245
245
  if (n) return n;
246
246
  }
247
247
  if (s) {
248
- let n = st(s);
248
+ let n = nt(s);
249
249
  if (n) return n;
250
250
  }
251
251
  if (r) {
@@ -267,7 +267,7 @@ function U(t) {
267
267
  return "TextualBody";
268
268
  }
269
269
  }
270
- if (r && at.indexOf(r) !== -1) return r;
270
+ if (r && ot.indexOf(r) !== -1) return r;
271
271
  if (t.format) {
272
272
  if (t.format.startsWith("image/")) return "Image";
273
273
  if (t.format.startsWith("text/") || t.format === "application/pdf") return "Text";
@@ -275,15 +275,15 @@ function U(t) {
275
275
  }
276
276
  return e && (e.endsWith(".jpg") || e.endsWith(".png") || e.endsWith(".jpeg")) ? "Image" : r || "unknown";
277
277
  }
278
- var ot = /http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;
279
- function ct(t) {
280
- let e = t.match(ot);
278
+ var ct = /http(s)?:\/\/(creativecommons.org|rightsstatements.org)[^"'\\<\n]+/gm;
279
+ function lt(t) {
280
+ let e = t.match(ct);
281
281
  return e ? e[0] : t;
282
282
  }
283
- function lt(t, e = "Rights/License", r = "none") {
283
+ function pt(t, e = "Rights/License", r = "none") {
284
284
  let i = null, s = [], n = Array.isArray(t) ? t : [t];
285
- for (let o of n) {
286
- let c = o ? ct(o) : void 0;
285
+ for (let a of n) {
286
+ let c = a ? lt(a) : void 0;
287
287
  if (c && (c.indexOf("creativecommons.org") !== -1 || c.indexOf("rightsstatements.org") !== -1)) {
288
288
  c.startsWith("https://") ? i = `http://${c.slice(8)}` : i = c;
289
289
  continue;
@@ -292,19 +292,19 @@ function lt(t, e = "Rights/License", r = "none") {
292
292
  }
293
293
  return [i, s];
294
294
  }
295
- var pt = ["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"];
296
- function vt(t) {
295
+ var vt = ["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"];
296
+ function ht(t) {
297
297
  if (t) {
298
298
  let e = Array.isArray(t) ? t : [t], r = [];
299
- for (let i of e) i === "http://iiif.io/api/presentation/2/context.json" && r.push("http://iiif.io/api/presentation/3/context.json"), pt.indexOf(i) === -1 && r.push(i);
299
+ for (let i of e) i === "http://iiif.io/api/presentation/2/context.json" && r.push("http://iiif.io/api/presentation/3/context.json"), vt.indexOf(i) === -1 && r.push(i);
300
300
  if (e.length) return r.length === 1 ? r[0] : r;
301
301
  }
302
302
  }
303
- function ht(t) {
303
+ function ut(t) {
304
304
  return t ? t.map((e) => ({ label: I(e.label), value: I(e.value) })) : [];
305
305
  }
306
306
  var q = 0;
307
- function ee(t, e) {
307
+ function te(t, e) {
308
308
  let r = encodeURI(t.id || t["@id"] || "").trim();
309
309
  return r && e ? `${r}/${e}` : r || (q++, `http://example.org/${t["@type"]}${e ? `/${e}` : ""}/${q}`);
310
310
  }
@@ -312,16 +312,16 @@ function C(t) {
312
312
  let e = [...t.behavior || []];
313
313
  t.viewingHint && e.push(t.viewingHint);
314
314
  let r;
315
- return Array.isArray(t.motivation) ? r = t.motivation.map(E) : t.motivation && (r = E(t.motivation)), { "@context": t["@context"] ? vt(t["@context"]) : void 0, id: (t["@id"] || ee(t)).trim(), type: U(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
+ return Array.isArray(t.motivation) ? r = t.motivation.map(_) : t.motivation && (r = _(t.motivation)), { "@context": t["@context"] ? ht(t["@context"]) : void 0, id: (t["@id"] || te(t)).trim(), type: D(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 };
316
316
  }
317
317
  function b(t) {
318
- let [e, r] = lt(t.license), i = [...t.metadata ? ht(t.metadata) : [], ...r];
319
- return { rights: e, metadata: i.length ? i : void 0, label: t.label ? I(t.label) : void 0, requiredStatement: t.attribution ? { label: I(k.attributionLabel), value: I(t.attribution) } : void 0, navDate: t.navDate, summary: t.description ? I(t.description) : void 0, thumbnail: ut(t.thumbnail) };
318
+ let [e, r] = pt(t.license), i = [...t.metadata ? ut(t.metadata) : [], ...r];
319
+ return { rights: e, metadata: i.length ? i : void 0, label: t.label ? I(t.label) : void 0, requiredStatement: t.attribution ? { label: I(P.attributionLabel), value: I(t.attribution) } : void 0, navDate: t.navDate, summary: t.description ? I(t.description) : void 0, thumbnail: ft(t.thumbnail) };
320
320
  }
321
- function ut(t) {
321
+ function ft(t) {
322
322
  return t && (Array.isArray(t) ? t : [t]).map((e) => typeof e == "string" ? { id: e, type: "Image" } : (e.type === "unknown" && (e.type = "Image"), e));
323
323
  }
324
- function ft(t) {
324
+ function mt(t) {
325
325
  if (!t.within) return;
326
326
  let e = Array.isArray(t.within) ? t.within : [t.within], r = [];
327
327
  for (let i of e) if (typeof i == "string") {
@@ -330,26 +330,53 @@ function ft(t) {
330
330
  r.push({ id: i, type: "Collection" });
331
331
  break;
332
332
  }
333
- } else i["@id"] && r.push({ id: i["@id"], type: U(i) });
333
+ } else i["@id"] && r.push({ id: i["@id"], type: D(i) });
334
334
  return r.length ? r : void 0;
335
335
  }
336
336
  function L(t) {
337
337
  let e = t.related ? Array.isArray(t.related) ? t.related : [t.related] : [], r = t.contentLayer;
338
- return { provider: t.logo || e.length ? [{ id: k.providerId, type: "Agent", homepage: e.length ? [e[0]] : void 0, logo: t.logo ? Array.isArray(t.logo) ? t.logo : [t.logo] : void 0, label: I(k.providerName) }] : void 0, partOf: ft(t), rendering: t.rendering, seeAlso: t.seeAlso, start: t.startCanvas, service: t.service ? w(t.service) : void 0, supplementary: r ? [r] : void 0 };
338
+ return { provider: t.logo || e.length ? [{ id: P.providerId, type: "Agent", homepage: e.length ? [e[0]] : void 0, logo: t.logo ? Array.isArray(t.logo) ? t.logo : [t.logo] : void 0, label: I(P.providerName) }] : void 0, partOf: mt(t), rendering: t.rendering, seeAlso: t.seeAlso, start: t.startCanvas, service: t.service ? w(t.service) : void 0, supplementary: r ? [r] : void 0 };
339
339
  }
340
- function mt(t) {
340
+ function gt(t) {
341
341
  return { chars: t.chars, format: t.format ? t.format : void 0, language: t.language };
342
342
  }
343
- function gt(t) {
344
- return d({ ...C(t), ...b(t), ...L(t), items: t.members });
343
+ function $(t, e) {
344
+ return t ? typeof t == "string" ? { id: t, type: e } : typeof (t == null ? void 0 : t["@id"]) == "string" ? { id: t["@id"], type: e } : typeof t.id == "string" ? { id: t.id, type: e } : null : null;
345
345
  }
346
346
  function dt(t) {
347
- let e = [], r = [], i;
348
- for (let n of t.sequences || []) n.canvases.length && e.push(...n.canvases), n.behavior && r.push(...n.behavior), n.startCanvas && (i = n.startCanvas);
349
- let s = C(t);
350
- return r.length && (s.behavior ? s.behavior.push(...r) : s.behavior = r), d({ ...s, ...b(t), ...L(t), start: i, items: e, structures: yt(t.structures) });
347
+ let e = {};
348
+ if (t.first) {
349
+ let r = $(t.first, "Collection");
350
+ r && (e.first = r);
351
+ }
352
+ if ((t.total || t.total === 0) && (e.total = t.total), t.prev) {
353
+ let r = $(t.prev, "Collection");
354
+ r && (e.prev = r);
355
+ }
356
+ if (t.next) {
357
+ let r = $(t.next, "Collection");
358
+ r && (e.next = r);
359
+ }
360
+ return e;
351
361
  }
352
362
  function yt(t) {
363
+ let e = [];
364
+ for (let r of t) {
365
+ let i = { ...r };
366
+ i.items && i.items.length === 0 && delete i.items, e.push(i);
367
+ }
368
+ return e;
369
+ }
370
+ function At(t) {
371
+ return d({ ...C(t), ...b(t), ...L(t), ...dt(t), items: yt(t.members) });
372
+ }
373
+ function Ct(t) {
374
+ let e = [], r = [], i, s;
375
+ for (let a of t.sequences || []) a.canvases.length && e.push(...a.canvases), a.behavior && r.push(...a.behavior), a.viewingDirection && (s = a.viewingDirection), a.startCanvas && (i = a.startCanvas);
376
+ let n = C(t);
377
+ return r.length && (n.behavior ? n.behavior.push(...r) : n.behavior = r), d({ ...n, ...b(t), ...L(t), viewingDirection: s, start: i, items: e, structures: bt(t.structures) });
378
+ }
379
+ function bt(t) {
353
380
  if (!t) return t;
354
381
  let e = /* @__PURE__ */ new Map();
355
382
  for (let i of t) e.set(i.id, i);
@@ -360,16 +387,16 @@ function yt(t) {
360
387
  }
361
388
  return t.filter((i) => r.indexOf(i.id) === -1);
362
389
  }
363
- function At(t) {
364
- return d({ ...C(t), ...b(t), ...L(t), annotations: t.otherContent && t.otherContent.length ? t.otherContent : void 0, items: t.images && t.images.length ? [{ id: ee(t, "annotation-page"), type: "AnnotationPage", items: t.images }] : void 0 });
390
+ function Rt(t) {
391
+ return d({ ...C(t), ...b(t), ...L(t), annotations: t.otherContent && t.otherContent.length ? t.otherContent : void 0, items: t.images && t.images.length ? [{ id: te(t, "annotation-page"), type: "AnnotationPage", items: t.images }] : void 0 });
365
392
  }
366
- function Ct(t) {
393
+ function Lt(t) {
367
394
  return d({ ...C(t), ...b(t), ...L(t), items: t.resources && t.resources.length ? t.resources : void 0 });
368
395
  }
369
- function bt(t) {
370
- return !t.canvases || t.canvases.length === 0 ? { canvases: [], behavior: [] } : { canvases: t.canvases, behavior: t.viewingHint ? [t.viewingHint] : [], startCanvas: t.startCanvas };
396
+ function wt(t) {
397
+ return !t.canvases || t.canvases.length === 0 ? { canvases: [], behavior: [] } : { canvases: t.canvases, behavior: t.viewingHint ? [t.viewingHint] : [], viewingDirection: t.viewingDirection, startCanvas: t.startCanvas };
371
398
  }
372
- function Rt(t) {
399
+ function It(t) {
373
400
  function e(r) {
374
401
  if (Array.isArray(r)) {
375
402
  if (r.length > 1) return { type: "List", items: r.map(e) };
@@ -382,51 +409,51 @@ function Rt(t) {
382
409
  else if (r.full["@type"] === "dctypes:Image") i = { id: r.full["@id"], type: "Image" };
383
410
  else if (r.full["@type"] === "sc:Canvas") i = { id: r.full["@id"], type: "Canvas" };
384
411
  else throw new Error(`Unsupported source type on annotation: ${r.full["@type"]}`);
385
- return { type: "SpecificResource", source: i, selector: P(r.selector) };
412
+ return { type: "SpecificResource", source: i, selector: O(r.selector) };
386
413
  } else return encodeURI(r["@id"]).trim();
387
414
  }
388
- return d({ ...C(t), ...b(t), ...L(t), target: e(t.on), body: Array.isArray(t.resource) ? t.resource.map(_) : _(t.resource) });
415
+ return d({ ...C(t), ...b(t), ...L(t), target: e(t.on), body: Array.isArray(t.resource) ? t.resource.map(B) : B(t.resource) });
389
416
  }
390
- function _(t) {
391
- return t.type === "Choice" ? t : te(t);
417
+ function B(t) {
418
+ return t.type === "Choice" ? t : re(t);
392
419
  }
393
- function te(t) {
420
+ function re(t) {
394
421
  let e = t;
395
- return d({ ...C(e), ...b(e), ...L(e), ...mt(e) });
422
+ return d({ ...C(e), ...b(e), ...L(e), ...gt(e) });
396
423
  }
397
- function Lt(t) {
424
+ function St(t) {
398
425
  let e = [];
399
426
  return t.default && t.default !== "rdf:nil" && e.push(t.default), t.item && t.item !== "rdf:nil" && e.push(...t.item), d({ ...C(t), ...b(t), items: e });
400
427
  }
401
- function wt(t) {
428
+ function xt(t) {
402
429
  return d({ ...C(t), ...b(t), ...L(t), items: t.members });
403
430
  }
404
- function It(t) {
405
- let { "@id": e, "@type": r, "@context": i, profile: s, ...n } = t, o = {};
406
- return e && (o["@id"] = e), o["@type"] = U(t), o["@type"] === "unknown" && (i && i.length && (o["@context"] = i), o["@type"] = "Service"), s && (o.profile = Z(s)), d({ ...o, ...n });
431
+ function Tt(t) {
432
+ let { "@id": e, "@type": r, "@context": i, profile: s, ...n } = t, a = {};
433
+ return e && (a["@id"] = e), a["@type"] = D(t), a["@type"] === "unknown" && (i && i.length && (a["@context"] = i), a["@type"] = "Service"), s && (a.profile = ee(s)), d({ ...a, ...n });
407
434
  }
408
- function St(t) {
435
+ function Mt(t) {
409
436
  return d({ ...C(t), ...b(t), ...L(t) });
410
437
  }
411
- var xt = new Ue({ collection: [gt], manifest: [dt], canvas: [At], annotationList: [Ct], sequence: [bt], annotation: [Rt], contentResource: [te], choice: [Lt], range: [wt], service: [It], layer: [St] });
412
- function re(t) {
413
- 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" ? xt.traverseUnknown(t) : t;
438
+ var $t = new De({ collection: [At], manifest: [Ct], canvas: [Rt], annotationList: [Lt], sequence: [wt], annotation: [It], contentResource: [re], choice: [St], range: [xt], service: [Tt], layer: [Mt] });
439
+ function ie(t) {
440
+ 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" || t["@id"] && t["@type"] === "sc:Collection" || t["@id"] && t["@type"] === "sc:Manifest" ? (t["@context"] || (t["@context"] = "http://iiif.io/api/presentation/2/context.json"), $t.traverseUnknown(t)) : t;
414
441
  }
415
- function P(t) {
442
+ function O(t) {
416
443
  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 };
417
444
  if (t["@type"] === "oa:FragmentSelector") return { type: "FragmentSelector", value: t.value };
418
- if (t["@type"] === "oa:Choice") return [P(t.default), ...(Array.isArray(t.item) ? t.item : [t.item]).map(P)];
445
+ if (t["@type"] === "oa:Choice") return [O(t.default), ...(Array.isArray(t.item) ? t.item : [t.item]).map(O)];
419
446
  if (t["@type"] == "iiif:ImageApiSelector") return { type: "ImageApiSelector", region: "region" in t ? t.region : void 0, rotation: "rotation" in t ? t.rotation : void 0 };
420
447
  throw new Error(`Unsupported selector type: ${t["@type"]}`);
421
448
  }
422
- function M(t) {
449
+ function j(t) {
423
450
  return typeof t == "string" ? !1 : t && !t.type && "source" in t ? (t.type = "SpecificResource", !0) : !!t && t.type === "SpecificResource";
424
451
  }
425
452
  function x(...t) {
426
453
  return (e) => t.reduce((r, i) => i(r), e);
427
454
  }
428
- var B = ["Collection", "Manifest", "Canvas", "AnnotationPage", "AnnotationCollection", "Annotation", "ContentResource", "Range", "Service", "Selector", "Agent"];
429
- function Tt(t, e) {
455
+ var V = ["Collection", "Manifest", "Canvas", "AnnotationPage", "AnnotationCollection", "Annotation", "ContentResource", "Range", "Service", "Selector", "Agent"];
456
+ function jt(t, e) {
430
457
  if (typeof t > "u" || t === null) throw new Error("Null or undefined is not a valid entity.");
431
458
  if (Array.isArray(t)) throw new Error("Array is not a valid entity");
432
459
  if (typeof t != "object") {
@@ -434,30 +461,30 @@ function Tt(t, e) {
434
461
  throw new Error(`${typeof t} is not a valid entity`);
435
462
  }
436
463
  if (typeof t.type == "string") {
437
- let r = B.indexOf(t.type);
438
- if (r !== -1) return B[r];
464
+ let r = V.indexOf(t.type);
465
+ if (r !== -1) return V[r];
439
466
  }
440
467
  if (t.profile) return "Service";
441
468
  throw new Error("Resource type is not known");
442
469
  }
443
- var D = class ie {
470
+ var N = class se {
444
471
  constructor(e, r = {}) {
445
- R(this, "traversals"), R(this, "options"), R(this, "_traverseManifest", x(this.traverseManifestItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseManifestStructures.bind(this), this.traverseInlineAnnotationPages.bind(this))), R(this, "_traverseCanvas", x(this.traverseCanvasItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseInlineAnnotationPages.bind(this))), R(this, "_traverseAnnotationPage", x(this.traverseAnnotationPageItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this))), R(this, "_traverseRange", x(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 };
472
+ R(this, "traversals"), R(this, "options"), R(this, "_traverseManifest", x(this.traverseManifestItems.bind(this), this.traverseNavPlace.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseManifestStructures.bind(this), this.traverseInlineAnnotationPages.bind(this))), R(this, "_traverseCanvas", x(this.traverseCanvasItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseInlineAnnotationPages.bind(this))), R(this, "_traverseAnnotationPage", x(this.traverseAnnotationPageItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this))), R(this, "_traverseRange", x(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 };
446
473
  }
447
474
  static all(e) {
448
- return new ie({ collection: [e], manifest: [e], canvas: [e], annotationCollection: [e], annotationPage: [e], annotation: [e], contentResource: [e], choice: [e], range: [e], service: [e], geoJson: [e], specificResource: [e], agent: [e] });
475
+ return new se({ 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] });
449
476
  }
450
477
  traverseDescriptive(e) {
451
478
  return e.thumbnail && (e.thumbnail = w(e.thumbnail).map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.provider && (e.provider = e.provider.map((r) => this.traverseAgent(r, e))), e;
452
479
  }
453
480
  traverseLinking(e) {
454
- return e.seeAlso && (e.seeAlso = e.seeAlso.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.service && (e.service = w(e.service).map((r) => this.traverseService(r))), e.services && (e.services = w(e.services).map((r) => this.traverseService(r, e))), e.logo && (e.logo = e.logo.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.homepage && (e.homepage = w(e.homepage).map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.partOf && (e.partOf = e.partOf.map((r) => typeof r == "string" || !r.type ? this.traverseType(r, { parent: e }, this.traversals.contentResource) : r.type === "Canvas" ? this.traverseType(r, { parent: e }, this.traversals.canvas) : r.type === "AnnotationCollection" ? this.traverseType(r, { parent: e }, this.traversals.annotationCollection) : r.type === "Collection" ? this.traverseType(r, { parent: e }, this.traversals.collection) : this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.start && (M(e.start) ? e.start = this.traverseSpecificResource(e.start, "Canvas", e) : e.start = this.traverseType(e.start, { parent: e }, this.traversals.canvas)), e.rendering && (e.rendering = e.rendering.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.supplementary && (e.supplementary = e.supplementary.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e;
481
+ return e.seeAlso && (e.seeAlso = e.seeAlso.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.service && (e.service = w(e.service).map((r) => this.traverseService(r))), e.services && (e.services = w(e.services).map((r) => this.traverseService(r, e))), e.logo && (e.logo = e.logo.map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.homepage && (e.homepage = w(e.homepage).map((r) => this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.partOf && (e.partOf = e.partOf.map((r) => typeof r == "string" || !r.type ? this.traverseType(r, { parent: e }, this.traversals.contentResource) : r.type === "Canvas" ? this.traverseType(r, { parent: e }, this.traversals.canvas) : r.type === "AnnotationCollection" ? this.traverseType(r, { parent: e }, this.traversals.annotationCollection) : r.type === "Collection" ? this.traverseType(r, { parent: e }, this.traversals.collection) : this.traverseType(r, { parent: e }, this.traversals.contentResource))), e.start && (j(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;
455
482
  }
456
483
  traverseCollectionItems(e) {
457
484
  return e.items && e.items.map((r) => r.type === "Collection" ? this.traverseCollection(r) : this.traverseManifest(r)), e;
458
485
  }
459
486
  traverseCollection(e, r) {
460
- return this.traverseType(this.traverseDescriptive(this.traverseInlineAnnotationPages(this.traverseLinking(this.traverseLinkedCanvases(this.traverseCollectionItems(e))))), { parent: r }, this.traversals.collection);
487
+ return this.traverseType(this.traverseDescriptive(this.traverseNavPlace(this.traverseInlineAnnotationPages(this.traverseLinking(this.traverseLinkedCanvases(this.traverseCollectionItems(e)))))), { parent: r }, this.traversals.collection);
461
488
  }
462
489
  traverseGeoJson(e, r) {
463
490
  return this.traverseType(e, { parent: r }, this.traversals.geoJson);
@@ -502,14 +529,14 @@ var D = class ie {
502
529
  return typeof e == "string" || !e || e && e.service && (e.service = w(e.service || []).map((r) => this.traverseService(r, e))), e;
503
530
  }
504
531
  traverseContentResource(e, r) {
505
- return e.type === "Choice" && (e.items = e.items.map((i) => this.traverseContentResource(i, e))), M(e) ? this.traverseSpecificResource(e, "ContentResource") : this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)), { parent: r }, this.traversals.contentResource);
532
+ return e.type === "Choice" && (e.items = e.items.map((i) => this.traverseContentResource(i, e))), j(e) ? this.traverseSpecificResource(e, "ContentResource") : this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(e)), { parent: r }, this.traversals.contentResource);
506
533
  }
507
534
  traverseSpecificResource(e, r, i) {
508
535
  let s = e.source;
509
536
  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);
510
537
  }
511
538
  traverseRangeRanges(e) {
512
- return e.items && (e.items = e.items.map((r) => typeof r == "string" ? this.traverseCanvas({ id: r, type: "Canvas" }, e) : M(r) ? this.traverseSpecificResource(r, "Canvas", e) : r.type === "Manifest" ? this.traverseManifest(r, e) : this.traverseRange(r, e))), e;
539
+ return e.items && (e.items = e.items.map((r) => typeof r == "string" ? this.traverseCanvas({ id: r, type: "Canvas" }, e) : j(r) ? this.traverseSpecificResource(r, "Canvas", e) : r.type === "Manifest" ? this.traverseManifest(r, e) : this.traverseRange(r, e))), e;
513
540
  }
514
541
  traverseRange(e, r) {
515
542
  return this.traverseType(this._traverseRange(e), { parent: r }, this.traversals.range);
@@ -519,8 +546,8 @@ var D = class ie {
519
546
  }
520
547
  traverseType(e, r, i) {
521
548
  return i.reduce((s, n) => {
522
- let o = n(s, r);
523
- return typeof o > "u" && !this.options.allowUndefinedReturn ? s : o;
549
+ let a = n(s, r);
550
+ return typeof a > "u" && !this.options.allowUndefinedReturn ? s : a;
524
551
  }, e);
525
552
  }
526
553
  traverseService(e, r) {
@@ -528,7 +555,7 @@ var D = class ie {
528
555
  return i && i.service && (i.service = w(i.service).map((s) => this.traverseService(s))), this.traverseType(i, { parent: r }, this.traversals.service);
529
556
  }
530
557
  traverseUnknown(e, { parent: r, typeHint: i } = {}) {
531
- let s = Tt(e, i);
558
+ let s = jt(e, i);
532
559
  switch (s) {
533
560
  case "Collection":
534
561
  return this.traverseCollection(e, r);
@@ -553,88 +580,88 @@ var D = class ie {
553
580
  }
554
581
  }
555
582
  };
556
- const se = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.profile.toString().includes("iiif.io/api/image/"), ne = (t) => {
583
+ const ne = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.profile.toString().includes("iiif.io/api/image/"), ae = (t) => {
557
584
  const e = g(t, "type"), r = g(t, "context");
558
585
  if (e === "ImageService2" || r != null && r.includes("image/2")) {
559
586
  const i = t, s = ["level0", "level1", "level2"];
560
- return { majorVersion: 2, profileLevel: (Array.isArray(i.profile) ? i.profile : [i.profile]).map((c) => s.findIndex((a) => c.toString().includes(a))).filter((c) => c > -1).sort((c, a) => a - c)[0] };
587
+ return { majorVersion: 2, profileLevel: (Array.isArray(i.profile) ? i.profile : [i.profile]).map((c) => s.findIndex((o) => c.toString().includes(o))).filter((c) => c > -1).sort((c, o) => o - c)[0] };
561
588
  } else if (e || r)
562
589
  return { majorVersion: 3, profileLevel: parseInt(t.profile) };
563
- }, O = (t, e, r) => {
590
+ }, U = (t, e, r) => {
564
591
  const i = g(t, "id"), s = t.profile || "";
565
592
  if (typeof s == "string" && (s.includes("level0") || s.includes("level:0"))) {
566
593
  if ("sizes" in t && Array.isArray(t.sizes)) {
567
- const o = t.sizes.sort((c, a) => a.width * a.height - c.width * c.height).filter((c) => c.width * c.height >= e * r)[0];
568
- if (o)
569
- return `${i}/full/${o.width},${o.height}/0/default.jpg`;
594
+ const a = t.sizes.sort((c, o) => o.width * o.height - c.width * c.height).filter((c) => c.width * c.height >= e * r)[0];
595
+ if (a)
596
+ return `${i}/full/${a.width},${a.height}/0/default.jpg`;
570
597
  }
571
598
  return `${i}/full/full/0/default.jpg`;
572
599
  }
573
600
  return `${i}/full/!${e},${r}/0/default.jpg`;
574
- }, $t = (t, e, r = { minSize: 400 }) => {
601
+ }, kt = (t, e, r = { minSize: 400 }) => {
575
602
  const i = g(t, "id"), s = t.profile || "";
576
603
  if (typeof s == "string" && (s.includes("level0") || s.includes("level:0"))) {
577
604
  console.warn(`Level 0 image service does not support custom region URLs: ${i}`);
578
605
  return;
579
606
  }
580
- const { x: o, y: c, w: a, h: p } = e, { minSize: u = 400, maxSize: v } = r, m = a / p, l = m < 1;
607
+ const { x: a, y: c, w: o, h: p } = e, { minSize: u = 400, maxSize: v } = r, m = o / p, l = m < 1;
581
608
  let f = Math.ceil(l ? u / m : u), h = Math.ceil(l ? u : u / m);
582
609
  v && (h > v || f > v) && (l ? (f = Math.min(f, v), h = Math.ceil(f * m)) : (h = Math.min(h, v), f = Math.ceil(h / m)));
583
- const y = `${Math.round(o)},${Math.round(c)},${Math.round(a)},${Math.round(p)}`;
610
+ const y = `${Math.round(a)},${Math.round(c)},${Math.round(o)},${Math.round(p)}`;
584
611
  return `${i}/${y}/!${h},${f}/0/default.jpg`;
585
- }, Mt = (t) => (e, r = { minSize: 400 }) => {
612
+ }, Pt = (t) => (e, r = { minSize: 400 }) => {
586
613
  if (t.type === "dynamic")
587
- return $t(t.service, e, r);
614
+ return kt(t.service, e, r);
588
615
  console.error("Level 0 or static image canvas: unsupported");
589
- }, jt = (t, e = []) => (r = 400) => {
616
+ }, Ot = (t, e = []) => (r = 400) => {
590
617
  const { width: i, height: s } = t;
591
618
  if (!i || !s) return;
592
- const n = i / s, o = n < 1, c = Math.ceil(o ? r / n : r), a = Math.ceil(o ? r : r / n);
619
+ const n = i / s, a = n < 1, c = Math.ceil(a ? r / n : r), o = Math.ceil(a ? r : r / n);
593
620
  if (t.thumbnail && t.thumbnail.length > 0) {
594
621
  const p = t.thumbnail[0];
595
622
  if ("service" in p && Array.isArray(p.service)) {
596
- const u = p.service.find((v) => se(v));
623
+ const u = p.service.find((v) => ne(v));
597
624
  if (u)
598
- return O(u, a, c);
625
+ return U(u, o, c);
599
626
  }
600
627
  if ("id" in p) return p.id;
601
628
  }
602
629
  for (const p of e) {
603
630
  if (p.type === "dynamic" || p.type === "level0")
604
- return O(p.service, a, c);
631
+ return U(p.service, o, c);
605
632
  if (p.type === "static")
606
633
  return p.url;
607
634
  }
608
- }, ae = (t) => t.endsWith("/info.json") ? t : `${t.endsWith("/") ? t : `${t}/`}info.json`, kt = (t, e, r) => (i = 800) => {
635
+ }, oe = (t) => t.endsWith("/info.json") ? t : `${t.endsWith("/") ? t : `${t}/`}info.json`, Ut = (t, e, r) => (i = 800) => {
609
636
  if (!t || !e) return;
610
- const s = t / e, n = s < 1, o = Math.ceil(n ? i / s : i), c = Math.ceil(n ? i : i / s);
611
- return O(r, c, o);
612
- }, Pt = (t) => () => fetch(t).then((e) => e.json()).then((e) => {
637
+ const s = t / e, n = s < 1, a = Math.ceil(n ? i / s : i), c = Math.ceil(n ? i : i / s);
638
+ return U(r, c, a);
639
+ }, Dt = (t) => () => fetch(t).then((e) => e.json()).then((e) => {
613
640
  const r = e.width, i = e.height;
614
641
  return r !== void 0 && i !== void 0 ? { width: r, height: i } : void 0;
615
- }), Ot = (t) => () => {
642
+ }), Nt = (t) => () => {
616
643
  const e = typeof window < "u";
617
644
  return fetch(t).then((r) => r.blob()).then((r) => e ? createImageBitmap(r).then((i) => {
618
645
  const { width: s, height: n } = i;
619
646
  return i.close(), { width: s, height: n };
620
- }) : r.arrayBuffer().then((i) => ce(new Uint8Array(i))));
621
- }, Ut = (t) => {
622
- const { format: e, height: r, width: i } = t, s = g(t, "id"), n = (t.service || []).find(se), o = n ? ne(n) : void 0;
623
- if (n && o) {
624
- const c = ae(g(n, "id")), a = {
647
+ }) : r.arrayBuffer().then((i) => le(new Uint8Array(i))));
648
+ }, Et = (t) => {
649
+ const { format: e, height: r, width: i } = t, s = g(t, "id"), n = (t.service || []).find(ne), a = n ? ae(n) : void 0;
650
+ if (n && a) {
651
+ const c = oe(g(n, "id")), o = {
625
652
  source: t,
626
- type: o.profileLevel === 0 ? "level0" : "dynamic",
653
+ type: a.profileLevel === 0 ? "level0" : "dynamic",
627
654
  service: n,
628
655
  width: i,
629
656
  height: r,
630
- majorVersion: o.majorVersion,
657
+ majorVersion: a.majorVersion,
631
658
  serviceUrl: c,
632
- getImageURL: kt(i, r, n),
633
- getPixelSize: Pt(c)
659
+ getImageURL: Ut(i, r, n),
660
+ getPixelSize: Dt(c)
634
661
  };
635
- return o.profileLevel === 0 ? a : {
636
- ...a,
637
- getRegionURL: Mt(a)
662
+ return a.profileLevel === 0 ? o : {
663
+ ...o,
664
+ getRegionURL: Pt(o)
638
665
  };
639
666
  } else
640
667
  return {
@@ -645,32 +672,32 @@ const se = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.prof
645
672
  url: s,
646
673
  format: e,
647
674
  getImageURL: () => s,
648
- getPixelSize: Ot(s)
675
+ getPixelSize: Nt(s)
649
676
  };
650
- }, Dt = (t) => {
677
+ }, _t = (t) => {
651
678
  const e = [];
652
- return new D({
679
+ return new N({
653
680
  annotation: [(i) => {
654
681
  if (i.motivation === "painting" || !i.motivation) {
655
- const n = (i.body ? Array.isArray(i.body) ? i.body : [i.body] : []).filter((o) => o.type === "Image");
656
- e.push(...n.map((o) => Ut(o)));
682
+ const n = (i.body ? Array.isArray(i.body) ? i.body : [i.body] : []).filter((a) => a.type === "Image");
683
+ e.push(...n.map((a) => Et(a)));
657
684
  }
658
685
  }]
659
686
  }).traverseCanvas(t), e;
660
- }, Nt = (t) => () => {
661
- const e = /* @__PURE__ */ new Map(), r = (a, p, u = 0) => {
687
+ }, qt = (t) => () => {
688
+ const e = /* @__PURE__ */ new Map(), r = (o, p, u = 0) => {
662
689
  const v = {
663
- id: a.id,
690
+ id: o.id,
664
691
  type: "range",
665
- source: a,
692
+ source: o,
666
693
  children: [],
667
694
  navItems: [],
668
695
  navSections: [],
669
696
  parent: p,
670
697
  level: u,
671
- getLabel: a.getLabel
698
+ getLabel: o.getLabel
672
699
  };
673
- a.items && a.items.length > 0 && a.items.forEach((h) => {
700
+ o.items && o.items.length > 0 && o.items.forEach((h) => {
674
701
  if (h.source.type === "Range") {
675
702
  const T = r(h, v, u + 1);
676
703
  v.children.push(T);
@@ -692,19 +719,19 @@ const se = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.prof
692
719
  const m = v.children.map((h) => h.type === "canvas" ? h.source : h.children.length === 1 && h.children[0].type === "canvas" ? h.children[0].source : h.source), l = m.filter((h) => h.source.type === "Canvas"), f = m.filter((h) => h.source.type === "Range");
693
720
  return v.navItems.push(...l), v.navSections.push(...f), e.set(v.id, v), v;
694
721
  };
695
- return { root: t.filter((a) => {
722
+ return { root: t.filter((o) => {
696
723
  var p;
697
- return (p = a.source.behavior) == null ? void 0 : p.includes("top");
698
- }).map((a) => r(a, void 0)), enumerateNodes: (a) => {
724
+ return (p = o.source.behavior) == null ? void 0 : p.includes("top");
725
+ }).map((o) => r(o, void 0)), enumerateNodes: (o) => {
699
726
  const p = Array.from(e.values());
700
- return a ? p.filter((u) => u.type === a) : p;
701
- }, getBreadcrumbs: (a) => {
702
- const p = e.get(a);
727
+ return o ? p.filter((u) => u.type === o) : p;
728
+ }, getBreadcrumbs: (o) => {
729
+ const p = e.get(o);
703
730
  if (!p) return [];
704
731
  const u = (v, m = []) => v.parent ? u(v.parent, [v, ...m]) : [v, ...m];
705
732
  return u(p);
706
- }, getNode: (a) => e.get(a) };
707
- }, Et = async (t) => {
733
+ }, getNode: (o) => e.get(o) };
734
+ }, Bt = async (t) => {
708
735
  try {
709
736
  new URL(t);
710
737
  } catch {
@@ -742,7 +769,7 @@ const se = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.prof
742
769
  };
743
770
  try {
744
771
  const i = await e.json();
745
- return oe(i, t);
772
+ return ce(i, t);
746
773
  } catch {
747
774
  return {
748
775
  type: "error",
@@ -750,8 +777,8 @@ const se = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.prof
750
777
  message: "Could not parse resource"
751
778
  };
752
779
  }
753
- }, oe = (t, e) => {
754
- const r = Array.isArray(t["@context"]) ? t["@context"].find((s) => s.includes("iiif.io/api/")) : t["@context"];
780
+ }, ce = (t, e) => {
781
+ const r = Array.isArray(t["@context"]) ? t["@context"].find((s) => s.includes("iiif.io/api/presentation") || s.includes("iiif.io/api/image")) : t["@context"];
755
782
  if (!r)
756
783
  return {
757
784
  type: "error",
@@ -770,15 +797,15 @@ const se = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.prof
770
797
  return g(t, "type").includes("Collection") ? {
771
798
  type: "collection",
772
799
  url: e || i,
773
- resource: qt(t, s)
800
+ resource: Vt(t, s)
774
801
  } : {
775
802
  type: "manifest",
776
803
  url: e || i,
777
- resource: _t(t, s)
804
+ resource: Ft(t, s)
778
805
  };
779
806
  }
780
807
  if (r.includes("image/2") || r.includes("image/3")) {
781
- const s = Bt(t);
808
+ const s = Wt(t);
782
809
  return s ? {
783
810
  type: "iiif-image",
784
811
  url: e || i,
@@ -794,39 +821,39 @@ const se = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.prof
794
821
  code: "INVALID_MANIFEST",
795
822
  message: "JSON resource is not a recognized IIIF format"
796
823
  };
797
- }, qt = (t, e) => {
824
+ }, Vt = (t, e) => {
798
825
  const r = (n) => {
799
- const o = [];
800
- return new D({
801
- manifest: [(a) => o.push(a)]
802
- }).traverseCollection(n), o.map((a) => ({
803
- id: a.id,
804
- type: a.type,
805
- getLabel: S(a),
806
- source: a
826
+ const a = [];
827
+ return new N({
828
+ manifest: [(o) => a.push(o)]
829
+ }).traverseCollection(n), a.map((o) => ({
830
+ id: o.id,
831
+ type: o.type,
832
+ getLabel: S(o),
833
+ source: o
807
834
  }));
808
- }, i = e === 2 ? re(t) : t, s = r(i);
835
+ }, i = e === 2 ? ie(t) : t, s = r(i);
809
836
  return {
810
837
  source: i,
811
838
  id: i.id,
812
839
  majorVersion: e,
813
840
  items: s,
814
841
  getLabel: S(i),
815
- getMetadata: j(i)
842
+ getMetadata: k(i)
816
843
  };
817
- }, _t = (t, e) => {
818
- const r = (o) => {
819
- const c = [], a = [];
820
- new D({
844
+ }, Ft = (t, e) => {
845
+ const r = (a) => {
846
+ const c = [], o = [];
847
+ new N({
821
848
  canvas: [(l) => {
822
849
  l.items && c.push(l);
823
850
  }],
824
851
  range: [(l) => {
825
- l.type === "Range" && a.push(l);
852
+ l.type === "Range" && o.push(l);
826
853
  }]
827
- }).traverseManifest(o);
854
+ }).traverseManifest(a);
828
855
  const u = c.map((l) => {
829
- const f = Dt(l);
856
+ const f = _t(l);
830
857
  return {
831
858
  source: l,
832
859
  id: l.id,
@@ -837,23 +864,23 @@ const se = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.prof
837
864
  getImageURL: f.length > 0 ? f[0].getImageURL : () => {
838
865
  },
839
866
  getLabel: S(l),
840
- getMetadata: j(l),
841
- getThumbnailURL: jt(l, f)
867
+ getMetadata: k(l),
868
+ getThumbnailURL: Ot(l, f)
842
869
  };
843
870
  }), v = (l) => {
844
- const f = l.items || [], h = f.filter((A) => A.type === "Canvas").map((A) => u.find(($) => $.id === A.id)).filter(Boolean), y = f.filter((A) => A.type === "Range").map((A) => v(A)), T = [...h, ...y];
871
+ const f = l.items || [], h = f.filter((A) => A.type === "Canvas").map((A) => u.find((M) => M.id === A.id)).filter(Boolean), y = f.filter((A) => A.type === "Range").map((A) => v(A)), T = [...h, ...y];
845
872
  return {
846
873
  source: l,
847
874
  id: l.id,
848
875
  // Maintain original order
849
- items: f.map((A) => T.find(($) => $.id === A.id)),
876
+ items: f.map((A) => T.find((M) => M.id === A.id)),
850
877
  canvases: h,
851
878
  ranges: y,
852
879
  getLabel: S(l)
853
880
  };
854
- }, m = a.map((l) => v(l));
881
+ }, m = o.map((l) => v(l));
855
882
  return { canvases: u, ranges: m };
856
- }, i = e === 2 ? re(t) : t, { canvases: s, ranges: n } = r(i);
883
+ }, i = e === 2 ? ie(t) : t, { canvases: s, ranges: n } = r(i);
857
884
  return {
858
885
  source: i,
859
886
  id: i.id,
@@ -861,11 +888,11 @@ const se = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.prof
861
888
  canvases: s,
862
889
  structure: n,
863
890
  getLabel: S(i),
864
- getMetadata: j(i),
865
- getTableOfContents: Nt(n)
891
+ getMetadata: k(i),
892
+ getTableOfContents: qt(n)
866
893
  };
867
- }, Bt = (t) => {
868
- const { width: e, height: r } = t, i = ne(t);
894
+ }, Wt = (t) => {
895
+ const { width: e, height: r } = t, i = ae(t);
869
896
  if (i)
870
897
  return {
871
898
  type: i.profileLevel === 0 ? "level0" : "dynamic",
@@ -873,22 +900,22 @@ const se = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.prof
873
900
  width: e,
874
901
  height: r,
875
902
  majorVersion: i.majorVersion,
876
- serviceUrl: ae(g(t, "id"))
903
+ serviceUrl: oe(g(t, "id"))
877
904
  };
878
- }, Wt = { parse: oe, parseURL: Et };
905
+ }, Jt = { parse: ce, parseURL: Bt };
879
906
  export {
880
- Wt as Cozy,
881
- O as getImageURLFromService,
882
- Dt as getImages,
907
+ Jt as Cozy,
908
+ U as getImageURLFromService,
909
+ _t as getImages,
883
910
  S as getLabel,
884
- j as getMetadata,
911
+ k as getMetadata,
885
912
  g as getPropertyValue,
886
- Mt as getRegionURL,
887
- $t as getRegionURLFromService,
888
- Jt as getStringValue,
889
- Nt as getTableOfContents,
890
- jt as getThumbnailURL,
891
- se as isImageService,
892
- ae as normalizeServiceUrl,
893
- ne as parseImageService
913
+ Pt as getRegionURL,
914
+ kt as getRegionURLFromService,
915
+ Qt as getStringValue,
916
+ qt as getTableOfContents,
917
+ Ot as getThumbnailURL,
918
+ ne as isImageService,
919
+ oe as normalizeServiceUrl,
920
+ ae as parseImageService
894
921
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-iiif",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
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",