cozy-iiif 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import { imageSize as le } from "image-size";
2
- import { g, a as k, b as S } from "./resource-DS2brz47.js";
2
+ import { g as y, a as P, b as x } from "./resource-DS2brz47.js";
3
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
- function d(t) {
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", ge = "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", me = "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, ge, z, me, de, H, ye, Ae, Ce, be, J, G, Re, Le, we, Ie, K, Q, Se, xe, X], Pe = je;
5
+ function A(t) {
6
6
  for (let e in t) (typeof t[e] > "u" || t[e] === null) && delete t[e];
7
7
  return t;
8
8
  }
9
9
  function w(t) {
10
10
  return Array.isArray(t) ? t : t ? [t] : [];
11
11
  }
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"];
12
+ var ke = Object.defineProperty, Oe = (t, e, r) => e in t ? ke(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
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");
@@ -153,7 +153,7 @@ var De = class Z {
153
153
  return typeof n > "u" && !this.options.allowUndefinedReturn ? i : n;
154
154
  }, e);
155
155
  }
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: "" };
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], k = { attributionLabel: "Attribution", providerId: "http://example.org/provider", providerName: "" };
157
157
  function st(t) {
158
158
  if (typeof t == "string") return [t];
159
159
  if (!t) return [];
@@ -188,7 +188,7 @@ function ee(t) {
188
188
  if (Array.isArray(t)) return ee(t.find((e) => typeof e == "string"));
189
189
  if ($e.indexOf(t) !== -1) return "level2";
190
190
  if (it.indexOf(t) !== -1) return "level1";
191
- if (ke.indexOf(t) !== -1) return "level0";
191
+ if (Pe.indexOf(t) !== -1) return "level0";
192
192
  if (typeof t == "string") return t;
193
193
  }
194
194
  function nt(t) {
@@ -283,12 +283,12 @@ function lt(t) {
283
283
  function pt(t, e = "Rights/License", r = "none") {
284
284
  let i = null, s = [], n = Array.isArray(t) ? t : [t];
285
285
  for (let a of n) {
286
- let c = a ? lt(a) : void 0;
287
- if (c && (c.indexOf("creativecommons.org") !== -1 || c.indexOf("rightsstatements.org") !== -1)) {
288
- c.startsWith("https://") ? i = `http://${c.slice(8)}` : i = c;
286
+ let o = a ? lt(a) : void 0;
287
+ if (o && (o.indexOf("creativecommons.org") !== -1 || o.indexOf("rightsstatements.org") !== -1)) {
288
+ o.startsWith("https://") ? i = `http://${o.slice(8)}` : i = o;
289
289
  continue;
290
290
  }
291
- c && s.push({ label: { [r]: [e] }, value: { [r]: [c] } });
291
+ o && s.push({ label: { [r]: [e] }, value: { [r]: [o] } });
292
292
  }
293
293
  return [i, s];
294
294
  }
@@ -316,12 +316,12 @@ function C(t) {
316
316
  }
317
317
  function b(t) {
318
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) };
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: ft(t.thumbnail) };
320
320
  }
321
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 mt(t) {
324
+ function gt(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") {
@@ -335,9 +335,9 @@ function mt(t) {
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: 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 };
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: gt(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 gt(t) {
340
+ function mt(t) {
341
341
  return { chars: t.chars, format: t.format ? t.format : void 0, language: t.language };
342
342
  }
343
343
  function $(t, e) {
@@ -368,13 +368,13 @@ function yt(t) {
368
368
  return e;
369
369
  }
370
370
  function At(t) {
371
- return d({ ...C(t), ...b(t), ...L(t), ...dt(t), items: yt(t.members) });
371
+ return A({ ...C(t), ...b(t), ...L(t), ...dt(t), items: yt(t.members) });
372
372
  }
373
373
  function Ct(t) {
374
374
  let e = [], r = [], i, s;
375
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
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) });
377
+ return r.length && (n.behavior ? n.behavior.push(...r) : n.behavior = r), A({ ...n, ...b(t), ...L(t), viewingDirection: s, start: i, items: e, structures: bt(t.structures) });
378
378
  }
379
379
  function bt(t) {
380
380
  if (!t) return t;
@@ -388,10 +388,10 @@ function bt(t) {
388
388
  return t.filter((i) => r.indexOf(i.id) === -1);
389
389
  }
390
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 });
391
+ return A({ ...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 });
392
392
  }
393
393
  function Lt(t) {
394
- return d({ ...C(t), ...b(t), ...L(t), items: t.resources && t.resources.length ? t.resources : void 0 });
394
+ return A({ ...C(t), ...b(t), ...L(t), items: t.resources && t.resources.length ? t.resources : void 0 });
395
395
  }
396
396
  function wt(t) {
397
397
  return !t.canvases || t.canvases.length === 0 ? { canvases: [], behavior: [] } : { canvases: t.canvases, behavior: t.viewingHint ? [t.viewingHint] : [], viewingDirection: t.viewingDirection, startCanvas: t.startCanvas };
@@ -412,28 +412,28 @@ function It(t) {
412
412
  return { type: "SpecificResource", source: i, selector: O(r.selector) };
413
413
  } else return encodeURI(r["@id"]).trim();
414
414
  }
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) });
415
+ return A({ ...C(t), ...b(t), ...L(t), target: e(t.on), body: Array.isArray(t.resource) ? t.resource.map(B) : B(t.resource) });
416
416
  }
417
417
  function B(t) {
418
418
  return t.type === "Choice" ? t : re(t);
419
419
  }
420
420
  function re(t) {
421
421
  let e = t;
422
- return d({ ...C(e), ...b(e), ...L(e), ...gt(e) });
422
+ return A({ ...C(e), ...b(e), ...L(e), ...mt(e) });
423
423
  }
424
424
  function St(t) {
425
425
  let e = [];
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 });
426
+ return t.default && t.default !== "rdf:nil" && e.push(t.default), t.item && t.item !== "rdf:nil" && e.push(...t.item), A({ ...C(t), ...b(t), items: e });
427
427
  }
428
428
  function xt(t) {
429
- return d({ ...C(t), ...b(t), ...L(t), items: t.members });
429
+ return A({ ...C(t), ...b(t), ...L(t), items: t.members });
430
430
  }
431
431
  function Tt(t) {
432
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 });
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)), A({ ...a, ...n });
434
434
  }
435
435
  function Mt(t) {
436
- return d({ ...C(t), ...b(t), ...L(t) });
436
+ return A({ ...C(t), ...b(t), ...L(t) });
437
437
  }
438
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
439
  function ie(t) {
@@ -449,7 +449,7 @@ function O(t) {
449
449
  function j(t) {
450
450
  return typeof t == "string" ? !1 : t && !t.type && "source" in t ? (t.type = "SpecificResource", !0) : !!t && t.type === "SpecificResource";
451
451
  }
452
- function x(...t) {
452
+ function T(...t) {
453
453
  return (e) => t.reduce((r, i) => i(r), e);
454
454
  }
455
455
  var V = ["Collection", "Manifest", "Canvas", "AnnotationPage", "AnnotationCollection", "Annotation", "ContentResource", "Range", "Service", "Selector", "Agent"];
@@ -469,7 +469,7 @@ function jt(t, e) {
469
469
  }
470
470
  var N = class se {
471
471
  constructor(e, 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 };
472
+ R(this, "traversals"), R(this, "options"), R(this, "_traverseManifest", T(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", T(this.traverseCanvasItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseInlineAnnotationPages.bind(this))), R(this, "_traverseAnnotationPage", T(this.traverseAnnotationPageItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this))), R(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 };
473
473
  }
474
474
  static all(e) {
475
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] });
@@ -580,62 +580,62 @@ var N = class se {
580
580
  }
581
581
  }
582
582
  };
583
- const ne = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.profile.toString().includes("iiif.io/api/image/"), ae = (t) => {
584
- const e = g(t, "type"), r = g(t, "context");
583
+ const ne = (t) => y(t, "type").startsWith("ImageService") || t.profile && t.profile.toString().includes("iiif.io/api/image/"), ae = (t) => {
584
+ const e = y(t, "type"), r = y(t, "context");
585
585
  if (e === "ImageService2" || r != null && r.includes("image/2")) {
586
586
  const i = t, s = ["level0", "level1", "level2"];
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] };
587
+ return { majorVersion: 2, profileLevel: (Array.isArray(i.profile) ? i.profile : [i.profile]).map((o) => s.findIndex((p) => o.toString().includes(p))).filter((o) => o > -1).sort((o, p) => p - o)[0] };
588
588
  } else if (e || r)
589
589
  return { majorVersion: 3, profileLevel: parseInt(t.profile) };
590
590
  }, U = (t, e, r) => {
591
- const i = g(t, "id"), s = t.profile || "";
591
+ const i = y(t, "id"), s = t.profile || "";
592
592
  if (typeof s == "string" && (s.includes("level0") || s.includes("level:0"))) {
593
593
  if ("sizes" in t && Array.isArray(t.sizes)) {
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];
594
+ const a = t.sizes.sort((o, p) => p.width * p.height - o.width * o.height).filter((o) => o.width * o.height >= e * r)[0];
595
595
  if (a)
596
596
  return `${i}/full/${a.width},${a.height}/0/default.jpg`;
597
597
  }
598
598
  return `${i}/full/full/0/default.jpg`;
599
599
  }
600
600
  return `${i}/full/!${e},${r}/0/default.jpg`;
601
- }, kt = (t, e, r = { minSize: 400 }) => {
602
- const i = g(t, "id"), s = t.profile || "";
601
+ }, Pt = (t, e, r = { minSize: 400 }) => {
602
+ const i = y(t, "id"), s = t.profile || "";
603
603
  if (typeof s == "string" && (s.includes("level0") || s.includes("level:0"))) {
604
604
  console.warn(`Level 0 image service does not support custom region URLs: ${i}`);
605
605
  return;
606
606
  }
607
- const { x: a, y: c, w: o, h: p } = e, { minSize: u = 400, maxSize: v } = r, m = o / p, l = m < 1;
608
- let f = Math.ceil(l ? u / m : u), h = Math.ceil(l ? u : u / m);
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)));
610
- const y = `${Math.round(a)},${Math.round(c)},${Math.round(o)},${Math.round(p)}`;
611
- return `${i}/${y}/!${h},${f}/0/default.jpg`;
612
- }, Pt = (t) => (e, r = { minSize: 400 }) => {
607
+ const { x: a, y: o, w: p, h: c } = e, { minSize: v = 400, maxSize: u } = r, h = p / c, l = h < 1;
608
+ let g = Math.ceil(l ? v / h : v), m = Math.ceil(l ? v : v / h);
609
+ u && (m > u || g > u) && (l ? (g = Math.min(g, u), m = Math.ceil(g * h)) : (m = Math.min(m, u), g = Math.ceil(m / h)));
610
+ const f = `${Math.round(a)},${Math.round(o)},${Math.round(p)},${Math.round(c)}`;
611
+ return `${i}/${f}/!${m},${g}/0/default.jpg`;
612
+ }, kt = (t) => (e, r = { minSize: 400 }) => {
613
613
  if (t.type === "dynamic")
614
- return kt(t.service, e, r);
614
+ return Pt(t.service, e, r);
615
615
  console.error("Level 0 or static image canvas: unsupported");
616
616
  }, Ot = (t, e = []) => (r = 400) => {
617
617
  const { width: i, height: s } = t;
618
618
  if (!i || !s) return;
619
- const n = i / s, a = n < 1, c = Math.ceil(a ? r / n : r), o = Math.ceil(a ? r : r / n);
619
+ const n = i / s, a = n < 1, o = Math.ceil(a ? r / n : r), p = Math.ceil(a ? r : r / n);
620
620
  if (t.thumbnail && t.thumbnail.length > 0) {
621
- const p = t.thumbnail[0];
622
- if ("service" in p && Array.isArray(p.service)) {
623
- const u = p.service.find((v) => ne(v));
624
- if (u)
625
- return U(u, o, c);
621
+ const c = t.thumbnail[0];
622
+ if ("service" in c && Array.isArray(c.service)) {
623
+ const v = c.service.find((u) => ne(u));
624
+ if (v)
625
+ return U(v, p, o);
626
626
  }
627
- if ("id" in p) return p.id;
627
+ if ("id" in c) return c.id;
628
628
  }
629
- for (const p of e) {
630
- if (p.type === "dynamic" || p.type === "level0")
631
- return U(p.service, o, c);
632
- if (p.type === "static")
633
- return p.url;
629
+ for (const c of e) {
630
+ if (c.type === "dynamic" || c.type === "level0")
631
+ return U(c.service, p, o);
632
+ if (c.type === "static")
633
+ return c.url;
634
634
  }
635
635
  }, oe = (t) => t.endsWith("/info.json") ? t : `${t.endsWith("/") ? t : `${t}/`}info.json`, Ut = (t, e, r) => (i = 800) => {
636
636
  if (!t || !e) return;
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);
637
+ const s = t / e, n = s < 1, a = Math.ceil(n ? i / s : i), o = Math.ceil(n ? i : i / s);
638
+ return U(r, o, a);
639
639
  }, Dt = (t) => () => fetch(t).then((e) => e.json()).then((e) => {
640
640
  const r = e.width, i = e.height;
641
641
  return r !== void 0 && i !== void 0 ? { width: r, height: i } : void 0;
@@ -646,22 +646,22 @@ const ne = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.prof
646
646
  return i.close(), { width: s, height: n };
647
647
  }) : r.arrayBuffer().then((i) => le(new Uint8Array(i))));
648
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;
649
+ const { format: e, height: r, width: i } = t, s = y(t, "id"), n = (t.service || []).find(ne), a = n ? ae(n) : void 0;
650
650
  if (n && a) {
651
- const c = oe(g(n, "id")), o = {
651
+ const o = oe(y(n, "id")), p = {
652
652
  source: t,
653
653
  type: a.profileLevel === 0 ? "level0" : "dynamic",
654
654
  service: n,
655
655
  width: i,
656
656
  height: r,
657
657
  majorVersion: a.majorVersion,
658
- serviceUrl: c,
658
+ serviceUrl: o,
659
659
  getImageURL: Ut(i, r, n),
660
- getPixelSize: Dt(c)
660
+ getPixelSize: Dt(o)
661
661
  };
662
- return a.profileLevel === 0 ? o : {
663
- ...o,
664
- getRegionURL: Pt(o)
662
+ return a.profileLevel === 0 ? p : {
663
+ ...p,
664
+ getRegionURL: kt(p)
665
665
  };
666
666
  } else
667
667
  return {
@@ -685,52 +685,58 @@ const ne = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.prof
685
685
  }]
686
686
  }).traverseCanvas(t), e;
687
687
  }, qt = (t) => () => {
688
- const e = /* @__PURE__ */ new Map(), r = (o, p, u = 0) => {
689
- const v = {
690
- id: o.id,
688
+ const e = /* @__PURE__ */ new Map(), r = (c, v, u = 0) => {
689
+ const h = {
690
+ id: c.id,
691
691
  type: "range",
692
- source: o,
692
+ source: c,
693
693
  children: [],
694
694
  navItems: [],
695
695
  navSections: [],
696
- parent: p,
696
+ parent: v,
697
697
  level: u,
698
- getLabel: o.getLabel
698
+ getLabel: c.getLabel
699
699
  };
700
- o.items && o.items.length > 0 && o.items.forEach((h) => {
701
- if (h.source.type === "Range") {
702
- const T = r(h, v, u + 1);
703
- v.children.push(T);
700
+ c.items && c.items.length > 0 && c.items.forEach((f) => {
701
+ if (f.source.type === "Range") {
702
+ const d = r(f, h, u + 1);
703
+ h.children.push(d);
704
704
  } else {
705
- const y = {
706
- id: h.id,
705
+ const S = {
706
+ id: f.id,
707
707
  type: "canvas",
708
- source: h,
708
+ source: f,
709
709
  children: [],
710
710
  navItems: [],
711
711
  navSections: [],
712
- parent: v,
712
+ parent: h,
713
713
  level: u + 1,
714
- getLabel: h.getLabel
714
+ getLabel: f.getLabel
715
715
  };
716
- v.children.push(y), e.set(y.id, y);
716
+ h.children.push(S), e.set(S.id, S);
717
717
  }
718
718
  });
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");
720
- return v.navItems.push(...l), v.navSections.push(...f), e.set(v.id, v), v;
719
+ const l = h.children.map((f) => f.type === "canvas" ? f.source : f.children.length === 1 && f.children[0].type === "canvas" ? f.children[0].source : f.source), g = l.filter((f) => f.source.type === "Canvas"), m = l.filter((f) => f.source.type === "Range");
720
+ return h.navItems.push(...g), h.navSections.push(...m), e.set(h.id, h), h;
721
721
  };
722
- return { root: t.filter((o) => {
723
- var p;
724
- return (p = o.source.behavior) == null ? void 0 : p.includes("top");
725
- }).map((o) => r(o, void 0)), enumerateNodes: (o) => {
726
- const p = Array.from(e.values());
727
- return o ? p.filter((u) => u.type === o) : p;
728
- }, getBreadcrumbs: (o) => {
729
- const p = e.get(o);
730
- if (!p) return [];
731
- const u = (v, m = []) => v.parent ? u(v.parent, [v, ...m]) : [v, ...m];
732
- return u(p);
733
- }, getNode: (o) => e.get(o) };
722
+ return { root: t.filter((c) => {
723
+ var v;
724
+ return (v = c.source.behavior) == null ? void 0 : v.includes("top");
725
+ }).map((c) => r(c, void 0)), enumerateNodes: (c) => {
726
+ const v = Array.from(e.values());
727
+ return c ? v.filter((u) => u.type === c) : v;
728
+ }, getBreadcrumbs: (c) => {
729
+ const v = e.get(c);
730
+ if (!v) return [];
731
+ const u = (h, l = []) => h.parent ? u(h.parent, [h, ...l]) : [h, ...l];
732
+ return u(v);
733
+ }, getNavParent: (c) => {
734
+ var h, l;
735
+ const v = e.get(c);
736
+ if (!v || v.type !== "canvas" || ((h = v.parent) == null ? void 0 : h.type) !== "range") return;
737
+ const { parent: u } = v;
738
+ return u.children.length === 1 && u.children[0].type === "canvas" ? ((l = u.parent) == null ? void 0 : l.type) === "range" ? u.parent.source : void 0 : u.source;
739
+ }, getNode: (c) => e.get(c) };
734
740
  }, Bt = async (t) => {
735
741
  try {
736
742
  new URL(t);
@@ -785,7 +791,7 @@ const ne = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.prof
785
791
  code: "INVALID_MANIFEST",
786
792
  message: "Missing @context"
787
793
  };
788
- const i = g(t, "id");
794
+ const i = y(t, "id");
789
795
  if (!i)
790
796
  return {
791
797
  type: "error",
@@ -794,7 +800,7 @@ const ne = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.prof
794
800
  };
795
801
  if (r.includes("presentation/2") || r.includes("presentation/3")) {
796
802
  const s = r.includes("presentation/2") ? 2 : 3;
797
- return g(t, "type").includes("Collection") ? {
803
+ return y(t, "type").includes("Collection") ? {
798
804
  type: "collection",
799
805
  url: e || i,
800
806
  resource: Vt(t, s)
@@ -825,12 +831,12 @@ const ne = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.prof
825
831
  const r = (n) => {
826
832
  const a = [];
827
833
  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
834
+ manifest: [(p) => a.push(p)]
835
+ }).traverseCollection(n), a.map((p) => ({
836
+ id: p.id,
837
+ type: p.type,
838
+ getLabel: x(p),
839
+ source: p
834
840
  }));
835
841
  }, i = e === 2 ? ie(t) : t, s = r(i);
836
842
  return {
@@ -838,48 +844,48 @@ const ne = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.prof
838
844
  id: i.id,
839
845
  majorVersion: e,
840
846
  items: s,
841
- getLabel: S(i),
842
- getMetadata: k(i)
847
+ getLabel: x(i),
848
+ getMetadata: P(i)
843
849
  };
844
850
  }, Ft = (t, e) => {
845
851
  const r = (a) => {
846
- const c = [], o = [];
852
+ const o = [], p = [];
847
853
  new N({
848
854
  canvas: [(l) => {
849
- l.items && c.push(l);
855
+ l.items && o.push(l);
850
856
  }],
851
857
  range: [(l) => {
852
- l.type === "Range" && o.push(l);
858
+ l.type === "Range" && p.push(l);
853
859
  }]
854
860
  }).traverseManifest(a);
855
- const u = c.map((l) => {
856
- const f = _t(l);
861
+ const v = o.map((l) => {
862
+ const g = _t(l);
857
863
  return {
858
864
  source: l,
859
865
  id: l.id,
860
866
  width: l.width,
861
867
  height: l.height,
862
- images: f,
868
+ images: g,
863
869
  annotations: l.annotations || [],
864
- getImageURL: f.length > 0 ? f[0].getImageURL : () => {
870
+ getImageURL: g.length > 0 ? g[0].getImageURL : () => {
865
871
  },
866
- getLabel: S(l),
867
- getMetadata: k(l),
868
- getThumbnailURL: Ot(l, f)
872
+ getLabel: x(l),
873
+ getMetadata: P(l),
874
+ getThumbnailURL: Ot(l, g)
869
875
  };
870
- }), v = (l) => {
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];
876
+ }), u = (l) => {
877
+ const g = l.items || [], m = g.filter((d) => d.type === "Canvas").map((d) => v.find((M) => M.id === d.id)).filter(Boolean), f = g.filter((d) => d.type === "Range").map((d) => u(d)), S = [...m, ...f];
872
878
  return {
873
879
  source: l,
874
880
  id: l.id,
875
881
  // Maintain original order
876
- items: f.map((A) => T.find((M) => M.id === A.id)),
877
- canvases: h,
878
- ranges: y,
879
- getLabel: S(l)
882
+ items: g.map((d) => S.find((M) => M.id === d.id)),
883
+ canvases: m,
884
+ ranges: f,
885
+ getLabel: x(l)
880
886
  };
881
- }, m = o.map((l) => v(l));
882
- return { canvases: u, ranges: m };
887
+ }, h = p.map((l) => u(l));
888
+ return { canvases: v, ranges: h };
883
889
  }, i = e === 2 ? ie(t) : t, { canvases: s, ranges: n } = r(i);
884
890
  return {
885
891
  source: i,
@@ -887,8 +893,8 @@ const ne = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.prof
887
893
  majorVersion: e,
888
894
  canvases: s,
889
895
  structure: n,
890
- getLabel: S(i),
891
- getMetadata: k(i),
896
+ getLabel: x(i),
897
+ getMetadata: P(i),
892
898
  getTableOfContents: qt(n)
893
899
  };
894
900
  }, Wt = (t) => {
@@ -900,18 +906,18 @@ const ne = (t) => g(t, "type").startsWith("ImageService") || t.profile && t.prof
900
906
  width: e,
901
907
  height: r,
902
908
  majorVersion: i.majorVersion,
903
- serviceUrl: oe(g(t, "id"))
909
+ serviceUrl: oe(y(t, "id"))
904
910
  };
905
911
  }, Jt = { parse: ce, parseURL: Bt };
906
912
  export {
907
913
  Jt as Cozy,
908
914
  U as getImageURLFromService,
909
915
  _t as getImages,
910
- S as getLabel,
911
- k as getMetadata,
912
- g as getPropertyValue,
913
- Pt as getRegionURL,
914
- kt as getRegionURLFromService,
916
+ x as getLabel,
917
+ P as getMetadata,
918
+ y as getPropertyValue,
919
+ kt as getRegionURL,
920
+ Pt as getRegionURLFromService,
915
921
  Qt as getStringValue,
916
922
  qt as getTableOfContents,
917
923
  Ot as getThumbnailURL,
package/dist/types.d.ts CHANGED
@@ -74,6 +74,7 @@ export interface CozyTOC {
74
74
  root: CozyTOCNode[];
75
75
  enumerateNodes(type?: 'range' | 'canvas'): CozyTOCNode[];
76
76
  getBreadcrumbs(id: string): CozyTOCNode[];
77
+ getNavParent(canvasId: string): CozyRange | undefined;
77
78
  getNode(id: string): CozyTOCNode | undefined;
78
79
  }
79
80
  export interface CozyTOCNode {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-iiif",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
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",
@@ -23,7 +23,7 @@ export const getTableOfContents = (ranges: CozyRange[]) => (): CozyTOC => {
23
23
  const childNode = buildTree(r, node, level + 1);
24
24
  node.children.push(childNode);
25
25
  } else {
26
- // This child is Canvas, i.e. a TOCNode with
26
+ // This child is a Canvas, i.e. a TOCNode with
27
27
  // no further children.
28
28
  const canvasChild: CozyTOCNode = {
29
29
  id: item.id,
@@ -89,10 +89,33 @@ export const getTableOfContents = (ranges: CozyRange[]) => (): CozyTOC => {
89
89
  return addParent(thisNode);
90
90
  }
91
91
 
92
+ const getNavParent = (canvasId: string) => {
93
+ const node = index.get(canvasId);
94
+
95
+ // Canvas node doesn't exist
96
+ if (!node || node.type !== 'canvas') return;
97
+
98
+ // Canvas node doesn't have a range parent
99
+ if (!(node.parent?.type === 'range')) return;
100
+
101
+ const { parent } = node;
102
+
103
+ if (parent.children.length === 1 && parent.children[0].type === 'canvas') {
104
+ // A range with a single canvas child - logical leaf node!
105
+ if (parent.parent?.type === 'range') {
106
+ return parent.parent.source as CozyRange;
107
+ } else {
108
+ return;
109
+ }
110
+ } else {
111
+ return parent.source as CozyRange;
112
+ }
113
+ }
114
+
92
115
  const enumerateNodes = (type?: 'range' | 'canvas'): CozyTOCNode[] => {
93
116
  const all = Array.from(index.values());
94
117
  return type ? all.filter(n => n.type === type) : all;
95
118
  }
96
119
 
97
- return { root, enumerateNodes, getBreadcrumbs, getNode };
120
+ return { root, enumerateNodes, getBreadcrumbs, getNavParent, getNode };
98
121
  }
package/src/types.ts CHANGED
@@ -124,6 +124,8 @@ export interface CozyTOC {
124
124
 
125
125
  getBreadcrumbs(id: string): CozyTOCNode[];
126
126
 
127
+ getNavParent(canvasId: string): CozyRange | undefined;
128
+
127
129
  getNode(id: string): CozyTOCNode | undefined;
128
130
 
129
131
  }