cozy-iiif 0.2.4 → 0.2.6

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.
@@ -1,5 +1,6 @@
1
1
  import { Canvas } from '@iiif/presentation-3';
2
2
  import { CozyImageResource } from '../types';
3
3
  export declare const getThumbnailURL: (canvas: Canvas, images?: CozyImageResource[]) => (minSize?: number) => string | undefined;
4
+ export declare const getImageURL: (canvas: Canvas, images?: CozyImageResource[]) => (minSize?: number) => string | undefined;
4
5
  export declare const normalizeServiceUrl: (url: string) => string;
5
6
  export declare const getImages: (canvas: Canvas) => CozyImageResource[];
package/dist/index.js CHANGED
@@ -1,32 +1,32 @@
1
- import { g as f, a as M, b as I } from "./resource-DS2brz47.js";
2
- import { c as Ft } from "./resource-DS2brz47.js";
3
- var ce = "http://library.stanford.edu/iiif/image-api/compliance.html#level0", le = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", V = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", pe = "http://library.stanford.edu/iiif/image-api/conformance.html#level0", ve = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", F = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", he = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0", ue = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", W = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", fe = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0", me = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", B = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", ge = "http://iiif.io/api/image/1/level0.json", de = "http://iiif.io/api/image/1/profiles/level0.json", ye = "http://iiif.io/api/image/1/level1.json", Ae = "http://iiif.io/api/image/1/profiles/level1.json", H = "http://iiif.io/api/image/1/level2.json", J = "http://iiif.io/api/image/1/profiles/level2.json", Ce = "http://iiif.io/api/image/2/level0.json", be = "http://iiif.io/api/image/2/profiles/level0.json", Re = "http://iiif.io/api/image/2/level1.json", Le = "http://iiif.io/api/image/2/profiles/level1.json", G = "http://iiif.io/api/image/2/level2.json", z = "http://iiif.io/api/image/2/profiles/level2.json", we = "level0", Ie = "level1", K = "level2", Se = "http://iiif.io/api/image/2/level0", Te = "http://iiif.io/api/image/2/level1", Q = "http://iiif.io/api/image/2/level2", xe = [Q, V, F, W, B, H, J, G, z, K], $e = [Se, Te, Q, ce, le, V, pe, ve, F, he, ue, W, fe, me, B, ge, de, ye, Ae, H, J, Ce, be, Re, Le, G, z, we, Ie, K], Me = $e;
4
- function m(t) {
1
+ import { g as m, a as j, b as S } from "./resource-DS2brz47.js";
2
+ import { c as Wt } from "./resource-DS2brz47.js";
3
+ var ce = "http://library.stanford.edu/iiif/image-api/compliance.html#level0", le = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", F = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", pe = "http://library.stanford.edu/iiif/image-api/conformance.html#level0", ve = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", W = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", he = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0", ue = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", B = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", fe = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0", me = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", H = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", ge = "http://iiif.io/api/image/1/level0.json", de = "http://iiif.io/api/image/1/profiles/level0.json", ye = "http://iiif.io/api/image/1/level1.json", Ae = "http://iiif.io/api/image/1/profiles/level1.json", J = "http://iiif.io/api/image/1/level2.json", G = "http://iiif.io/api/image/1/profiles/level2.json", Ce = "http://iiif.io/api/image/2/level0.json", be = "http://iiif.io/api/image/2/profiles/level0.json", Re = "http://iiif.io/api/image/2/level1.json", Le = "http://iiif.io/api/image/2/profiles/level1.json", K = "http://iiif.io/api/image/2/level2.json", Q = "http://iiif.io/api/image/2/profiles/level2.json", we = "level0", Ie = "level1", X = "level2", Se = "http://iiif.io/api/image/2/level0", Te = "http://iiif.io/api/image/2/level1", Y = "http://iiif.io/api/image/2/level2", xe = [Y, F, W, B, H, J, G, K, Q, X], $e = [Se, Te, Y, ce, le, F, pe, ve, W, he, ue, B, fe, me, H, ge, de, ye, Ae, J, G, Ce, be, Re, Le, K, Q, we, Ie, X], Me = $e;
4
+ function g(t) {
5
5
  for (let e in t) (typeof t[e] > "u" || t[e] === null) && delete t[e];
6
6
  return t;
7
7
  }
8
- function R(t) {
8
+ function w(t) {
9
9
  return Array.isArray(t) ? t : t ? [t] : [];
10
10
  }
11
- var je = Object.defineProperty, ke = (t, e, r) => e in t ? je(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, A = (t, e, r) => (ke(t, typeof e != "symbol" ? e + "" : e, r), r), U = ["sc:Collection", "sc:Manifest", "sc:Canvas", "sc:AnnotationList", "oa:Annotation", "sc:Range", "sc:Layer", "sc:Sequence", "oa:Choice", "Service", "ContentResource"];
11
+ var je = Object.defineProperty, ke = (t, e, r) => e in t ? je(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, b = (t, e, r) => (ke(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"];
12
12
  function Pe(t) {
13
13
  if (typeof t > "u" || t === null) throw new Error("Null or undefined is not a valid entity.");
14
14
  if (Array.isArray(t)) throw new Error("Array is not a valid entity");
15
15
  if (typeof t != "object") throw new Error(`${typeof t} is not a valid entity`);
16
16
  if (typeof t["@type"] == "string") {
17
- let e = U.indexOf(t["@type"]);
18
- if (e !== -1) return U[e];
17
+ let e = N.indexOf(t["@type"]);
18
+ if (e !== -1) return N[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 Oe = class X {
24
+ var Oe = class Z {
25
25
  constructor(e, r = {}) {
26
- A(this, "traversals"), A(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 };
26
+ b(this, "traversals"), b(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 X({ 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 Z({ 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);
@@ -152,7 +152,7 @@ var Oe = class X {
152
152
  return typeof n > "u" && !this.options.allowUndefinedReturn ? i : n;
153
153
  }, e);
154
154
  }
155
- }, Ue = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", De = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", Ee = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", Ne = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", qe = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", _e = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", Ve = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", Fe = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", We = "http://iiif.io/api/image/1/level1.json", Be = "http://iiif.io/api/image/1/profiles/level1.json", He = "http://iiif.io/api/image/1/level2.json", Je = "http://iiif.io/api/image/1/profiles/level2.json", Ge = "http://iiif.io/api/image/2/level1.json", ze = "http://iiif.io/api/image/2/profiles/level1.json", Ke = "http://iiif.io/api/image/2/level2.json", Qe = "http://iiif.io/api/image/2/profiles/level2.json", Xe = "level1", Ye = "level2", Ze = "http://iiif.io/api/image/2/level1", et = "http://iiif.io/api/image/2/level2", tt = [Ze, et, Ue, De, Ee, Ne, qe, _e, Ve, Fe, We, Be, He, Je, Ge, ze, Ke, Qe, Xe, Ye], j = { attributionLabel: "Attribution", providerId: "http://example.org/provider", providerName: "Unknown" };
155
+ }, Ue = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", De = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", Ne = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", Ee = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", qe = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", _e = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", Ve = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", Fe = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", We = "http://iiif.io/api/image/1/level1.json", Be = "http://iiif.io/api/image/1/profiles/level1.json", He = "http://iiif.io/api/image/1/level2.json", Je = "http://iiif.io/api/image/1/profiles/level2.json", Ge = "http://iiif.io/api/image/2/level1.json", 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", ze = "http://iiif.io/api/image/2/level1", et = "http://iiif.io/api/image/2/level2", tt = [ze, et, Ue, De, Ne, Ee, qe, _e, Ve, Fe, We, Be, He, Je, Ge, Ke, Qe, Xe, Ye, Ze], k = { attributionLabel: "Attribution", providerId: "http://example.org/provider", providerName: "Unknown" };
156
156
  function rt(t) {
157
157
  if (typeof t == "string") return [t];
158
158
  if (!t) return [];
@@ -166,7 +166,7 @@ function rt(t) {
166
166
  }
167
167
  return r;
168
168
  }
169
- function L(t, e = "none") {
169
+ function I(t, e = "none") {
170
170
  if (!t) return { none: [""] };
171
171
  let r = rt(t), i = {};
172
172
  for (let s of r) {
@@ -183,8 +183,8 @@ function L(t, e = "none") {
183
183
  }
184
184
  return Object.keys(i).length === 0 ? { none: [""] } : i;
185
185
  }
186
- function Y(t) {
187
- if (Array.isArray(t)) return Y(t.find((e) => typeof e == "string"));
186
+ function z(t) {
187
+ if (Array.isArray(t)) return z(t.find((e) => typeof e == "string"));
188
188
  if (xe.indexOf(t) !== -1) return "level2";
189
189
  if (tt.indexOf(t) !== -1) return "level1";
190
190
  if (Me.indexOf(t) !== -1) return "level0";
@@ -232,12 +232,12 @@ function st(t) {
232
232
  return "AutoCompleteService1";
233
233
  }
234
234
  }
235
- function D(t) {
235
+ function E(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
239
  var nt = ["Collection", "Manifest", "Annotation", "AnnotationPage", "Range", "Service"];
240
- function P(t) {
240
+ function U(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
243
  let n = st(i);
@@ -282,12 +282,12 @@ function ot(t) {
282
282
  function ct(t, e = "Rights/License", r = "none") {
283
283
  let i = null, s = [], n = Array.isArray(t) ? t : [t];
284
284
  for (let o of n) {
285
- let a = o ? ot(o) : void 0;
286
- if (a && (a.indexOf("creativecommons.org") !== -1 || a.indexOf("rightsstatements.org") !== -1)) {
287
- a.startsWith("https://") ? i = `http://${a.slice(8)}` : i = a;
285
+ let c = o ? ot(o) : void 0;
286
+ if (c && (c.indexOf("creativecommons.org") !== -1 || c.indexOf("rightsstatements.org") !== -1)) {
287
+ c.startsWith("https://") ? i = `http://${c.slice(8)}` : i = c;
288
288
  continue;
289
289
  }
290
- a && s.push({ label: { [r]: [e] }, value: { [r]: [a] } });
290
+ c && s.push({ label: { [r]: [e] }, value: { [r]: [c] } });
291
291
  }
292
292
  return [i, s];
293
293
  }
@@ -300,22 +300,22 @@ function pt(t) {
300
300
  }
301
301
  }
302
302
  function vt(t) {
303
- return t ? t.map((e) => ({ label: L(e.label), value: L(e.value) })) : [];
303
+ return t ? t.map((e) => ({ label: I(e.label), value: I(e.value) })) : [];
304
304
  }
305
- var E = 0;
306
- function Z(t, e) {
305
+ var q = 0;
306
+ function ee(t, e) {
307
307
  let r = encodeURI(t.id || t["@id"] || "").trim();
308
- return r && e ? `${r}/${e}` : r || (E++, `http://example.org/${t["@type"]}${e ? `/${e}` : ""}/${E}`);
308
+ return r && e ? `${r}/${e}` : r || (q++, `http://example.org/${t["@type"]}${e ? `/${e}` : ""}/${q}`);
309
309
  }
310
- function d(t) {
310
+ function A(t) {
311
311
  let e = [...t.behavior || []];
312
312
  t.viewingHint && e.push(t.viewingHint);
313
313
  let r;
314
- return Array.isArray(t.motivation) ? r = t.motivation.map(D) : t.motivation && (r = D(t.motivation)), { "@context": t["@context"] ? pt(t["@context"]) : void 0, id: (t["@id"] || Z(t)).trim(), type: P(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(E) : t.motivation && (r = E(t.motivation)), { "@context": t["@context"] ? pt(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
315
  }
316
- function y(t) {
316
+ function C(t) {
317
317
  let [e, r] = ct(t.license), i = [...t.metadata ? vt(t.metadata) : [], ...r];
318
- return { rights: e, metadata: i.length ? i : void 0, label: t.label ? L(t.label) : void 0, requiredStatement: t.attribution ? { label: L(j.attributionLabel), value: L(t.attribution) } : void 0, navDate: t.navDate, summary: t.description ? L(t.description) : void 0, thumbnail: ht(t.thumbnail) };
318
+ 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: ht(t.thumbnail) };
319
319
  }
320
320
  function ht(t) {
321
321
  return t && (Array.isArray(t) ? t : [t]).map((e) => typeof e == "string" ? { id: e, type: "Image" } : (e.type === "unknown" && (e.type = "Image"), e));
@@ -329,24 +329,24 @@ function ut(t) {
329
329
  r.push({ id: i, type: "Collection" });
330
330
  break;
331
331
  }
332
- } else i["@id"] && r.push({ id: i["@id"], type: P(i) });
332
+ } else i["@id"] && r.push({ id: i["@id"], type: U(i) });
333
333
  return r.length ? r : void 0;
334
334
  }
335
- function C(t) {
335
+ function R(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: j.providerId, type: "Agent", homepage: e.length ? [e[0]] : void 0, logo: t.logo ? Array.isArray(t.logo) ? t.logo : [t.logo] : void 0, label: L(j.providerName) }] : void 0, partOf: ut(t), rendering: t.rendering, seeAlso: t.seeAlso, start: t.startCanvas, service: t.service ? R(t.service) : void 0, supplementary: r ? [r] : void 0 };
337
+ 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: ut(t), rendering: t.rendering, seeAlso: t.seeAlso, start: t.startCanvas, service: t.service ? w(t.service) : void 0, supplementary: r ? [r] : void 0 };
338
338
  }
339
339
  function ft(t) {
340
340
  return { chars: t.chars, format: t.format ? t.format : void 0, language: t.language };
341
341
  }
342
342
  function mt(t) {
343
- return m({ ...d(t), ...y(t), ...C(t), items: t.members });
343
+ return g({ ...A(t), ...C(t), ...R(t), items: t.members });
344
344
  }
345
345
  function gt(t) {
346
346
  let e = [], r = [], i;
347
347
  for (let n of t.sequences || []) n.canvases.length && e.push(...n.canvases), n.behavior && r.push(...n.behavior), n.startCanvas && (i = n.startCanvas);
348
- let s = d(t);
349
- return r.length && (s.behavior ? s.behavior.push(...r) : s.behavior = r), m({ ...s, ...y(t), ...C(t), start: i, items: e, structures: dt(t.structures) });
348
+ let s = A(t);
349
+ return r.length && (s.behavior ? s.behavior.push(...r) : s.behavior = r), g({ ...s, ...C(t), ...R(t), start: i, items: e, structures: dt(t.structures) });
350
350
  }
351
351
  function dt(t) {
352
352
  if (!t) return t;
@@ -360,10 +360,10 @@ function dt(t) {
360
360
  return t.filter((i) => r.indexOf(i.id) === -1);
361
361
  }
362
362
  function yt(t) {
363
- return m({ ...d(t), ...y(t), ...C(t), annotations: t.otherContent && t.otherContent.length ? t.otherContent : void 0, items: t.images && t.images.length ? [{ id: Z(t, "annotation-page"), type: "AnnotationPage", items: t.images }] : void 0 });
363
+ return g({ ...A(t), ...C(t), ...R(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 });
364
364
  }
365
365
  function At(t) {
366
- return m({ ...d(t), ...y(t), ...C(t), items: t.resources && t.resources.length ? t.resources : void 0 });
366
+ return g({ ...A(t), ...C(t), ...R(t), items: t.resources && t.resources.length ? t.resources : void 0 });
367
367
  }
368
368
  function Ct(t) {
369
369
  return !t.canvases || t.canvases.length === 0 ? { canvases: [], behavior: [] } : { canvases: t.canvases, behavior: t.viewingHint ? [t.viewingHint] : [], startCanvas: t.startCanvas };
@@ -381,50 +381,50 @@ function bt(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: k(r.selector) };
384
+ return { type: "SpecificResource", source: i, selector: P(r.selector) };
385
385
  } else return encodeURI(r["@id"]).trim();
386
386
  }
387
- return m({ ...d(t), ...y(t), ...C(t), target: e(t.on), body: Array.isArray(t.resource) ? t.resource.map(N) : N(t.resource) });
387
+ return g({ ...A(t), ...C(t), ...R(t), target: e(t.on), body: Array.isArray(t.resource) ? t.resource.map(_) : _(t.resource) });
388
388
  }
389
- function N(t) {
390
- return t.type === "Choice" ? t : ee(t);
389
+ function _(t) {
390
+ return t.type === "Choice" ? t : te(t);
391
391
  }
392
- function ee(t) {
392
+ function te(t) {
393
393
  let e = t;
394
- return m({ ...d(e), ...y(e), ...C(e), ...ft(e) });
394
+ return g({ ...A(e), ...C(e), ...R(e), ...ft(e) });
395
395
  }
396
396
  function Rt(t) {
397
397
  let e = [];
398
- return t.default && t.default !== "rdf:nil" && e.push(t.default), t.item && t.item !== "rdf:nil" && e.push(...t.item), m({ ...d(t), ...y(t), items: e });
398
+ return t.default && t.default !== "rdf:nil" && e.push(t.default), t.item && t.item !== "rdf:nil" && e.push(...t.item), g({ ...A(t), ...C(t), items: e });
399
399
  }
400
400
  function Lt(t) {
401
- return m({ ...d(t), ...y(t), ...C(t), items: t.members });
401
+ return g({ ...A(t), ...C(t), ...R(t), items: t.members });
402
402
  }
403
403
  function wt(t) {
404
404
  let { "@id": e, "@type": r, "@context": i, profile: s, ...n } = t, o = {};
405
- return e && (o["@id"] = e), o["@type"] = P(t), o["@type"] === "unknown" && (i && i.length && (o["@context"] = i), o["@type"] = "Service"), s && (o.profile = Y(s)), m({ ...o, ...n });
405
+ 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)), g({ ...o, ...n });
406
406
  }
407
407
  function It(t) {
408
- return m({ ...d(t), ...y(t), ...C(t) });
408
+ return g({ ...A(t), ...C(t), ...R(t) });
409
409
  }
410
- var St = new Oe({ collection: [mt], manifest: [gt], canvas: [yt], annotationList: [At], sequence: [Ct], annotation: [bt], contentResource: [ee], choice: [Rt], range: [Lt], service: [wt], layer: [It] });
411
- function te(t) {
410
+ var St = new Oe({ collection: [mt], manifest: [gt], canvas: [yt], annotationList: [At], sequence: [Ct], annotation: [bt], contentResource: [te], choice: [Rt], range: [Lt], service: [wt], layer: [It] });
411
+ function re(t) {
412
412
  return t && t["@context"] && (t["@context"] === "http://iiif.io/api/presentation/2/context.json" || t["@context"].indexOf("http://iiif.io/api/presentation/2/context.json") !== -1 || t["@context"] === "http://www.shared-canvas.org/ns/context.json") || t["@context"] === "http://iiif.io/api/image/2/context.json" ? St.traverseUnknown(t) : t;
413
413
  }
414
- function k(t) {
414
+ function P(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 [k(t.default), ...(Array.isArray(t.item) ? t.item : [t.item]).map(k)];
417
+ if (t["@type"] === "oa:Choice") return [P(t.default), ...(Array.isArray(t.item) ? t.item : [t.item]).map(P)];
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 $(t) {
421
+ function M(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 T(...t) {
425
425
  return (e) => t.reduce((r, i) => i(r), e);
426
426
  }
427
- var q = ["Collection", "Manifest", "Canvas", "AnnotationPage", "AnnotationCollection", "Annotation", "ContentResource", "Range", "Service", "Selector", "Agent"];
427
+ var V = ["Collection", "Manifest", "Canvas", "AnnotationPage", "AnnotationCollection", "Annotation", "ContentResource", "Range", "Service", "Selector", "Agent"];
428
428
  function Tt(t, e) {
429
429
  if (typeof t > "u" || t === null) throw new Error("Null or undefined is not a valid entity.");
430
430
  if (Array.isArray(t)) throw new Error("Array is not a valid entity");
@@ -433,24 +433,24 @@ function Tt(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 = q.indexOf(t.type);
437
- if (r !== -1) return q[r];
436
+ let r = V.indexOf(t.type);
437
+ if (r !== -1) return V[r];
438
438
  }
439
439
  if (t.profile) return "Service";
440
440
  throw new Error("Resource type is not known");
441
441
  }
442
- var O = class re {
442
+ var D = class ie {
443
443
  constructor(e, r = {}) {
444
- A(this, "traversals"), A(this, "options"), A(this, "_traverseManifest", T(this.traverseManifestItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseManifestStructures.bind(this), this.traverseInlineAnnotationPages.bind(this))), A(this, "_traverseCanvas", T(this.traverseCanvasItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseInlineAnnotationPages.bind(this))), A(this, "_traverseAnnotationPage", T(this.traverseAnnotationPageItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this))), A(this, "_traverseRange", T(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 };
444
+ b(this, "traversals"), b(this, "options"), b(this, "_traverseManifest", T(this.traverseManifestItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseManifestStructures.bind(this), this.traverseInlineAnnotationPages.bind(this))), b(this, "_traverseCanvas", T(this.traverseCanvasItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseInlineAnnotationPages.bind(this))), b(this, "_traverseAnnotationPage", T(this.traverseAnnotationPageItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this))), b(this, "_traverseRange", T(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 re({ collection: [e], manifest: [e], canvas: [e], annotationCollection: [e], annotationPage: [e], annotation: [e], contentResource: [e], choice: [e], range: [e], service: [e], geoJson: [e], specificResource: [e], agent: [e] });
447
+ 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] });
448
448
  }
449
449
  traverseDescriptive(e) {
450
- return e.thumbnail && (e.thumbnail = R(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;
450
+ 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;
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 = R(e.service).map((r) => this.traverseService(r))), e.services && (e.services = R(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 = R(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 && ($(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 = 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;
454
454
  }
455
455
  traverseCollectionItems(e) {
456
456
  return e.items && e.items.map((r) => r.type === "Collection" ? this.traverseCollection(r) : this.traverseManifest(r)), e;
@@ -498,17 +498,17 @@ var O = class re {
498
498
  return this.traverseType(this.traverseLinking(this.traverseAnnotationBody(this.traverseDescriptive(e))), { parent: r }, this.traversals.annotation);
499
499
  }
500
500
  traverseContentResourceLinking(e) {
501
- return typeof e == "string" || !e || e && e.service && (e.service = R(e.service || []).map((r) => this.traverseService(r, e))), e;
501
+ return typeof e == "string" || !e || e && e.service && (e.service = w(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))), $(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))), M(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) : $(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) : M(r) ? this.traverseSpecificResource(r, "Canvas", e) : r.type === "Manifest" ? this.traverseManifest(r, e) : this.traverseRange(r, e))), e;
512
512
  }
513
513
  traverseRange(e, r) {
514
514
  return this.traverseType(this._traverseRange(e), { parent: r }, this.traversals.range);
@@ -524,7 +524,7 @@ var O = class re {
524
524
  }
525
525
  traverseService(e, r) {
526
526
  let i = Object.assign({}, e);
527
- return i && i.service && (i.service = R(i.service).map((s) => this.traverseService(s))), this.traverseType(i, { parent: r }, this.traversals.service);
527
+ return i && i.service && (i.service = w(i.service).map((s) => this.traverseService(s))), this.traverseType(i, { parent: r }, this.traversals.service);
528
528
  }
529
529
  traverseUnknown(e, { parent: r, typeHint: i } = {}) {
530
530
  let s = Tt(e, i);
@@ -552,18 +552,18 @@ var O = class re {
552
552
  }
553
553
  }
554
554
  };
555
- const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.profile.toString().includes("iiif.io/api/image/"), se = (t) => {
556
- const e = f(t, "type"), r = f(t, "context");
555
+ const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.profile.toString().includes("iiif.io/api/image/"), ne = (t) => {
556
+ const e = m(t, "type"), r = m(t, "context");
557
557
  if (e === "ImageService2" || r != null && r.includes("image/2")) {
558
558
  const i = t, s = ["level0", "level1", "level2"];
559
- return { majorVersion: 2, profileLevel: (Array.isArray(i.profile) ? i.profile : [i.profile]).map((a) => s.findIndex((c) => a.toString().includes(c))).filter((a) => a > -1).sort((a, c) => c - a)[0] };
559
+ 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] };
560
560
  } else if (e || r)
561
561
  return { majorVersion: 3, profileLevel: parseInt(t.profile) };
562
- }, _ = (t, e, r) => {
563
- const i = f(t, "id"), s = t.profile || "";
562
+ }, O = (t, e, r) => {
563
+ const i = m(t, "id"), s = t.profile || "";
564
564
  if (typeof s == "string" && (s.includes("level0") || s.includes("level:0"))) {
565
565
  if ("sizes" in t && Array.isArray(t.sizes)) {
566
- const o = t.sizes.sort((a, c) => c.width * c.height - a.width * a.height).filter((a) => a.width * a.height >= e * r)[0];
566
+ const o = t.sizes.sort((c, a) => a.width * a.height - c.width * c.height).filter((c) => c.width * c.height >= e * r)[0];
567
567
  if (o)
568
568
  return `${i}/full/${o.width},${o.height}/0/default.jpg`;
569
569
  }
@@ -571,10 +571,10 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
571
571
  }
572
572
  return `${i}/full/!${e},${r}/0/default.jpg`;
573
573
  }, xt = (t, e, r) => {
574
- const i = f(t, "id"), s = t.profile || "";
574
+ const i = m(t, "id"), s = t.profile || "";
575
575
  if (typeof s == "string" && (s.includes("level0") || s.includes("level:0"))) return;
576
- const { x: o, y: a, w: c, h } = e, p = c / h, u = p < 1, w = Math.ceil(u ? r / p : r), l = Math.ceil(u ? r : r / p), v = `${Math.round(o)},${Math.round(a)},${Math.round(c)},${Math.round(h)}`;
577
- return `${i}/${v}/!${l},${w}/0/default.jpg`;
576
+ const { x: o, y: c, w: a, h: l } = e, u = a / l, v = u < 1, d = Math.ceil(v ? r / u : r), p = Math.ceil(v ? r : r / u), f = `${Math.round(o)},${Math.round(c)},${Math.round(a)},${Math.round(l)}`;
577
+ return `${i}/${f}/!${p},${d}/0/default.jpg`;
578
578
  }, $t = (t) => (e, r = 400) => {
579
579
  if (t.type === "dynamic")
580
580
  return xt(t.service, e, r);
@@ -582,37 +582,47 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
582
582
  }, Mt = (t, e = []) => (r = 400) => {
583
583
  const { width: i, height: s } = t;
584
584
  if (!i || !s) return;
585
- const n = i / s, o = n < 1, a = Math.ceil(o ? r / n : r), c = Math.ceil(o ? r : r / n);
585
+ const n = i / s, o = n < 1, c = Math.ceil(o ? r / n : r), a = Math.ceil(o ? r : r / n);
586
586
  if (t.thumbnail && t.thumbnail.length > 0) {
587
- const h = t.thumbnail[0];
588
- if ("service" in h && Array.isArray(h.service)) {
589
- const p = h.service.find((u) => ie(u));
590
- if (p)
591
- return _(p, c, a);
587
+ const l = t.thumbnail[0];
588
+ if ("service" in l && Array.isArray(l.service)) {
589
+ const u = l.service.find((v) => se(v));
590
+ if (u)
591
+ return O(u, a, c);
592
592
  }
593
- if ("id" in h) return h.id;
593
+ if ("id" in l) return l.id;
594
594
  }
595
- for (const h of e) {
596
- if (h.type === "dynamic" || h.type === "level0")
597
- return _(h.service, c, a);
598
- if (h.type === "static")
599
- return h.url;
595
+ for (const l of e) {
596
+ if (l.type === "dynamic" || l.type === "level0")
597
+ return O(l.service, a, c);
598
+ if (l.type === "static")
599
+ return l.url;
600
600
  }
601
- }, ne = (t) => t.endsWith("/info.json") ? t : `${t.endsWith("/") ? t : `${t}/`}info.json`, jt = (t) => {
602
- const { format: e, height: r, width: i } = t, s = f(t, "id"), n = (t.service || []).find(ie), o = n ? se(n) : void 0;
601
+ }, jt = (t, e = []) => (r = 800) => {
602
+ const { width: i, height: s } = t;
603
+ if (!i || !s) return;
604
+ const n = i / s, o = n < 1, c = Math.ceil(o ? r / n : r), a = Math.ceil(o ? r : r / n);
605
+ for (const l of e) {
606
+ if (l.type === "dynamic" || l.type === "level0")
607
+ return O(l.service, a, c);
608
+ if (l.type === "static")
609
+ return l.url;
610
+ }
611
+ }, ae = (t) => t.endsWith("/info.json") ? t : `${t.endsWith("/") ? t : `${t}/`}info.json`, kt = (t) => {
612
+ const { format: e, height: r, width: i } = t, s = m(t, "id"), n = (t.service || []).find(se), o = n ? ne(n) : void 0;
603
613
  if (o) {
604
- const a = {
614
+ const c = {
605
615
  source: t,
606
616
  type: o.profileLevel === 0 ? "level0" : "dynamic",
607
617
  service: n,
608
618
  width: i,
609
619
  height: r,
610
620
  majorVersion: o.majorVersion,
611
- serviceUrl: ne(f(n, "id"))
621
+ serviceUrl: ae(m(n, "id"))
612
622
  };
613
- return o.profileLevel === 0 ? a : {
614
- ...a,
615
- getRegionURL: $t(a)
623
+ return o.profileLevel === 0 ? c : {
624
+ ...c,
625
+ getRegionURL: $t(c)
616
626
  };
617
627
  } else
618
628
  return {
@@ -623,61 +633,64 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
623
633
  url: s,
624
634
  format: e
625
635
  };
626
- }, kt = (t) => {
636
+ }, Pt = (t) => {
627
637
  const e = [];
628
- return new O({
638
+ return new D({
629
639
  annotation: [(i) => {
630
640
  if (i.motivation === "painting" || !i.motivation) {
631
641
  const n = (i.body ? Array.isArray(i.body) ? i.body : [i.body] : []).filter((o) => o.type === "Image");
632
- e.push(...n.map((o) => jt(o)));
642
+ e.push(...n.map((o) => kt(o)));
633
643
  }
634
644
  }]
635
645
  }).traverseCanvas(t), e;
636
- }, Pt = (t) => () => {
637
- const e = /* @__PURE__ */ new Map(), r = (a, c, h = 0) => {
638
- const p = {
646
+ }, Ot = (t) => () => {
647
+ const e = /* @__PURE__ */ new Map(), r = (a, l, u = 0) => {
648
+ const v = {
639
649
  id: a.id,
640
650
  type: "range",
641
651
  source: a,
642
652
  children: [],
643
653
  navItems: [],
644
654
  navSections: [],
645
- parent: c,
646
- level: h,
655
+ parent: l,
656
+ level: u,
647
657
  getLabel: a.getLabel
648
658
  };
649
- a.items && a.items.length > 0 && a.items.forEach((v) => {
650
- if (v.source.type === "Range") {
651
- const S = r(v, p, h + 1);
652
- p.children.push(S);
659
+ a.items && a.items.length > 0 && a.items.forEach((h) => {
660
+ if (h.source.type === "Range") {
661
+ const x = r(h, v, u + 1);
662
+ v.children.push(x);
653
663
  } else {
654
- const b = {
655
- id: v.id,
664
+ const L = {
665
+ id: h.id,
656
666
  type: "canvas",
657
- source: v,
667
+ source: h,
658
668
  children: [],
659
669
  navItems: [],
660
670
  navSections: [],
661
- parent: p,
662
- level: h + 1,
663
- getLabel: v.getLabel
671
+ parent: v,
672
+ level: u + 1,
673
+ getLabel: h.getLabel
664
674
  };
665
- p.children.push(b), e.set(b.id, b);
675
+ v.children.push(L), e.set(L.id, L);
666
676
  }
667
677
  });
668
- const u = p.children.map((v) => v.type === "canvas" ? v.source : v.children.length === 1 && v.children[0].type === "canvas" ? v.children[0].source : v.source), w = u.filter((v) => v.source.type === "Canvas"), l = u.filter((v) => v.source.type === "Range");
669
- return p.navItems.push(...w), p.navSections.push(...l), e.set(p.id, p), p;
678
+ const d = v.children.map((h) => h.type === "canvas" ? h.source : h.children.length === 1 && h.children[0].type === "canvas" ? h.children[0].source : h.source), p = d.filter((h) => h.source.type === "Canvas"), f = d.filter((h) => h.source.type === "Range");
679
+ return v.navItems.push(...p), v.navSections.push(...f), e.set(v.id, v), v;
670
680
  };
671
681
  return { root: t.filter((a) => {
672
- var c;
673
- return (c = a.source.behavior) == null ? void 0 : c.includes("top");
674
- }).map((a) => r(a, void 0)), getBreadcrumbs: (a) => {
675
- const c = e.get(a);
676
- if (!c) return [];
677
- const h = (p, u = []) => p.parent ? h(p.parent, [p, ...u]) : [p, ...u];
678
- return h(c);
682
+ var l;
683
+ return (l = a.source.behavior) == null ? void 0 : l.includes("top");
684
+ }).map((a) => r(a, void 0)), enumerateNodes: (a) => {
685
+ const l = Array.from(e.values());
686
+ return a ? l.filter((u) => u.type === a) : l;
687
+ }, getBreadcrumbs: (a) => {
688
+ const l = e.get(a);
689
+ if (!l) return [];
690
+ const u = (v, d = []) => v.parent ? u(v.parent, [v, ...d]) : [v, ...d];
691
+ return u(l);
679
692
  }, getNode: (a) => e.get(a) };
680
- }, Ot = async (t) => {
693
+ }, Ut = async (t) => {
681
694
  try {
682
695
  new URL(t);
683
696
  } catch {
@@ -715,7 +728,7 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
715
728
  };
716
729
  try {
717
730
  const i = await e.json();
718
- return ae(i, t);
731
+ return oe(i, t);
719
732
  } catch {
720
733
  return {
721
734
  type: "error",
@@ -723,7 +736,7 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
723
736
  message: "Could not parse resource"
724
737
  };
725
738
  }
726
- }, ae = (t, e) => {
739
+ }, oe = (t, e) => {
727
740
  const r = Array.isArray(t["@context"]) ? t["@context"].find((s) => s.includes("iiif.io/api/")) : t["@context"];
728
741
  if (!r)
729
742
  return {
@@ -731,7 +744,7 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
731
744
  code: "INVALID_MANIFEST",
732
745
  message: "Missing @context"
733
746
  };
734
- const i = f(t, "id");
747
+ const i = m(t, "id");
735
748
  if (!i)
736
749
  return {
737
750
  type: "error",
@@ -740,14 +753,14 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
740
753
  };
741
754
  if (r.includes("presentation/2") || r.includes("presentation/3")) {
742
755
  const s = r.includes("presentation/2") ? 2 : 3;
743
- return f(t, "type").includes("Collection") ? {
756
+ return m(t, "type").includes("Collection") ? {
744
757
  type: "collection",
745
758
  url: e || i,
746
- resource: Ut(t, s)
759
+ resource: Dt(t, s)
747
760
  } : {
748
761
  type: "manifest",
749
762
  url: e || i,
750
- resource: Dt(t, s)
763
+ resource: Nt(t, s)
751
764
  };
752
765
  }
753
766
  if (r.includes("image/2") || r.includes("image/3")) {
@@ -767,76 +780,77 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
767
780
  code: "INVALID_MANIFEST",
768
781
  message: "JSON resource is not a recognized IIIF format"
769
782
  };
770
- }, Ut = (t, e) => {
783
+ }, Dt = (t, e) => {
771
784
  const r = (n) => {
772
785
  const o = [];
773
- return new O({
774
- manifest: [(c) => o.push(c)]
775
- }).traverseCollection(n), o.map((c) => ({
776
- id: c.id,
777
- type: c.type,
778
- getLabel: I(c),
779
- source: c
786
+ return new D({
787
+ manifest: [(a) => o.push(a)]
788
+ }).traverseCollection(n), o.map((a) => ({
789
+ id: a.id,
790
+ type: a.type,
791
+ getLabel: S(a),
792
+ source: a
780
793
  }));
781
- }, i = e === 2 ? te(t) : t, s = r(i);
794
+ }, i = e === 2 ? re(t) : t, s = r(i);
782
795
  return {
783
796
  source: i,
784
797
  id: i.id,
785
798
  majorVersion: e,
786
799
  items: s,
787
- getLabel: I(i),
788
- getMetadata: M(i)
800
+ getLabel: S(i),
801
+ getMetadata: j(i)
789
802
  };
790
- }, Dt = (t, e) => {
803
+ }, Nt = (t, e) => {
791
804
  const r = (o) => {
792
- const a = [], c = [];
793
- new O({
794
- canvas: [(l) => {
795
- l.items && a.push(l);
805
+ const c = [], a = [];
806
+ new D({
807
+ canvas: [(p) => {
808
+ p.items && c.push(p);
796
809
  }],
797
- range: [(l) => {
798
- l.type === "Range" && c.push(l);
810
+ range: [(p) => {
811
+ p.type === "Range" && a.push(p);
799
812
  }]
800
813
  }).traverseManifest(o);
801
- const p = a.map((l) => {
802
- const v = kt(l);
814
+ const u = c.map((p) => {
815
+ const f = Pt(p);
803
816
  return {
804
- source: l,
805
- id: l.id,
806
- width: l.width,
807
- height: l.height,
808
- images: v,
809
- annotations: l.annotations || [],
810
- getLabel: I(l),
811
- getMetadata: M(l),
812
- getThumbnailURL: Mt(l, v)
817
+ source: p,
818
+ id: p.id,
819
+ width: p.width,
820
+ height: p.height,
821
+ images: f,
822
+ annotations: p.annotations || [],
823
+ getImageURL: jt(p, f),
824
+ getLabel: S(p),
825
+ getMetadata: j(p),
826
+ getThumbnailURL: Mt(p, f)
813
827
  };
814
- }), u = (l) => {
815
- const v = l.items || [], b = v.filter((g) => g.type === "Canvas").map((g) => p.find((x) => x.id === g.id)).filter(Boolean), S = v.filter((g) => g.type === "Range").map((g) => u(g)), oe = [...b, ...S];
828
+ }), v = (p) => {
829
+ const f = p.items || [], h = f.filter((y) => y.type === "Canvas").map((y) => u.find(($) => $.id === y.id)).filter(Boolean), L = f.filter((y) => y.type === "Range").map((y) => v(y)), x = [...h, ...L];
816
830
  return {
817
- source: l,
818
- id: l.id,
831
+ source: p,
832
+ id: p.id,
819
833
  // Maintain original order
820
- items: v.map((g) => oe.find((x) => x.id === g.id)),
821
- canvases: b,
822
- ranges: S,
823
- getLabel: I(l)
834
+ items: f.map((y) => x.find(($) => $.id === y.id)),
835
+ canvases: h,
836
+ ranges: L,
837
+ getLabel: S(p)
824
838
  };
825
- }, w = c.map((l) => u(l));
826
- return { canvases: p, ranges: w };
827
- }, i = e === 2 ? te(t) : t, { canvases: s, ranges: n } = r(i);
839
+ }, d = a.map((p) => v(p));
840
+ return { canvases: u, ranges: d };
841
+ }, i = e === 2 ? re(t) : t, { canvases: s, ranges: n } = r(i);
828
842
  return {
829
843
  source: i,
830
844
  id: i.id,
831
845
  majorVersion: e,
832
846
  canvases: s,
833
847
  structure: n,
834
- getLabel: I(i),
835
- getMetadata: M(i),
836
- getTableOfContents: Pt(n)
848
+ getLabel: S(i),
849
+ getMetadata: j(i),
850
+ getTableOfContents: Ot(n)
837
851
  };
838
852
  }, Et = (t) => {
839
- const { width: e, height: r } = t, i = se(t);
853
+ const { width: e, height: r } = t, i = ne(t);
840
854
  if (i)
841
855
  return {
842
856
  type: i.profileLevel === 0 ? "level0" : "dynamic",
@@ -844,22 +858,23 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
844
858
  width: e,
845
859
  height: r,
846
860
  majorVersion: i.majorVersion,
847
- serviceUrl: ne(f(t, "id"))
861
+ serviceUrl: ae(m(t, "id"))
848
862
  };
849
- }, qt = { parse: ae, parseURL: Ot };
863
+ }, _t = { parse: oe, parseURL: Ut };
850
864
  export {
851
- qt as Cozy,
852
- _ as getImageURLFromService,
853
- kt as getImages,
854
- I as getLabel,
855
- M as getMetadata,
856
- f as getPropertyValue,
865
+ _t as Cozy,
866
+ jt as getImageURL,
867
+ O as getImageURLFromService,
868
+ Pt as getImages,
869
+ S as getLabel,
870
+ j as getMetadata,
871
+ m as getPropertyValue,
857
872
  $t as getRegionURL,
858
873
  xt as getRegionURLFromService,
859
- Ft as getStringValue,
860
- Pt as getTableOfContents,
874
+ Wt as getStringValue,
875
+ Ot as getTableOfContents,
861
876
  Mt as getThumbnailURL,
862
- ie as isImageService,
863
- ne as normalizeServiceUrl,
864
- se as parseImageService
877
+ se as isImageService,
878
+ ae as normalizeServiceUrl,
879
+ ne as parseImageService
865
880
  };
package/dist/types.d.ts CHANGED
@@ -71,6 +71,7 @@ export interface CozyMetadata {
71
71
  }
72
72
  export interface CozyTOC {
73
73
  root: CozyTOCNode[];
74
+ enumerateNodes(type?: 'range' | 'canvas'): CozyTOCNode[];
74
75
  getBreadcrumbs(id: string): CozyTOCNode[];
75
76
  getNode(id: string): CozyTOCNode | undefined;
76
77
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-iiif",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
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",
@@ -30,7 +30,7 @@
30
30
  "devDependencies": {
31
31
  "vite": "^6.3.5",
32
32
  "vite-plugin-dts": "^4.5.4",
33
- "vitest": "^3.1.4"
33
+ "vitest": "^3.2.2"
34
34
  },
35
35
  "dependencies": {
36
36
  "@iiif/parser": "2.1.7",
package/src/Cozy.ts CHANGED
@@ -3,6 +3,7 @@ import { convertPresentation2 } from '@iiif/parser/presentation-2';
3
3
  import { Traverse } from '@iiif/parser';
4
4
  import {
5
5
  getImages,
6
+ getImageURL,
6
7
  getLabel,
7
8
  getMetadata,
8
9
  getPropertyValue,
@@ -193,6 +194,7 @@ const parseManifestResource = (resource: any, majorVersion: number): CozyManifes
193
194
  height: c.height,
194
195
  images,
195
196
  annotations: (c.annotations || []),
197
+ getImageURL: getImageURL(c, images),
196
198
  getLabel: getLabel(c),
197
199
  getMetadata: getMetadata(c),
198
200
  getThumbnailURL: getThumbnailURL(c, images)
@@ -42,6 +42,26 @@ export const getThumbnailURL = (canvas: Canvas, images: CozyImageResource[] = []
42
42
  }
43
43
  }
44
44
 
45
+ export const getImageURL = (canvas: Canvas, images: CozyImageResource[] = []) => (minSize = 800) => {
46
+ const { width, height } = canvas;
47
+
48
+ if (!width || !height) return;
49
+
50
+ const aspect = width / height;
51
+ const isPortrait = aspect < 1;
52
+
53
+ const h = Math.ceil(isPortrait ? minSize / aspect : minSize);
54
+ const w = Math.ceil(isPortrait ? minSize : minSize / aspect);
55
+
56
+ for (const image of images) {
57
+ if (image.type === 'dynamic' || image.type === 'level0') {
58
+ return getImageURLFromService(image.service, w, h);
59
+ } else if (image.type === 'static') {
60
+ return image.url;
61
+ }
62
+ }
63
+ }
64
+
45
65
  export const normalizeServiceUrl = (url: string) =>
46
66
  url.endsWith('/info.json') ? url : `${url.endsWith('/') ? url : `${url}/`}info.json`;
47
67
 
@@ -1,7 +1,6 @@
1
1
  import type { CozyCanvas, CozyRange, CozyTOC, CozyTOCNode } from '../types';
2
2
 
3
3
  export const getTableOfContents = (ranges: CozyRange[]) => (): CozyTOC => {
4
-
5
4
  const index = new Map<string, CozyTOCNode>();
6
5
 
7
6
  const buildTree = (range: CozyRange, parent: CozyTOCNode | undefined, level: number = 0): CozyTOCNode => {
@@ -90,5 +89,10 @@ export const getTableOfContents = (ranges: CozyRange[]) => (): CozyTOC => {
90
89
  return addParent(thisNode);
91
90
  }
92
91
 
93
- return { root, getBreadcrumbs, getNode };
92
+ const enumerateNodes = (type?: 'range' | 'canvas'): CozyTOCNode[] => {
93
+ const all = Array.from(index.values());
94
+ return type ? all.filter(n => n.type === type) : all;
95
+ }
96
+
97
+ return { root, enumerateNodes, getBreadcrumbs, getNode };
94
98
  }
package/src/types.ts CHANGED
@@ -119,6 +119,8 @@ export interface CozyTOC {
119
119
 
120
120
  root: CozyTOCNode[];
121
121
 
122
+ enumerateNodes(type?: 'range' | 'canvas'): CozyTOCNode[];
123
+
122
124
  getBreadcrumbs(id: string): CozyTOCNode[];
123
125
 
124
126
  getNode(id: string): CozyTOCNode | undefined;