cozy-iiif 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import { g as f, a as M, b as w } from "./resource-DS2brz47.js";
1
+ import { g as f, a as M, b as I } from "./resource-DS2brz47.js";
2
2
  import { c as Ft } from "./resource-DS2brz47.js";
3
3
  var ce = "http://library.stanford.edu/iiif/image-api/compliance.html#level0", le = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", V = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", pe = "http://library.stanford.edu/iiif/image-api/conformance.html#level0", ve = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", F = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", he = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0", ue = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", W = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", fe = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0", me = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", B = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", ge = "http://iiif.io/api/image/1/level0.json", de = "http://iiif.io/api/image/1/profiles/level0.json", ye = "http://iiif.io/api/image/1/level1.json", Ae = "http://iiif.io/api/image/1/profiles/level1.json", H = "http://iiif.io/api/image/1/level2.json", J = "http://iiif.io/api/image/1/profiles/level2.json", Ce = "http://iiif.io/api/image/2/level0.json", be = "http://iiif.io/api/image/2/profiles/level0.json", Re = "http://iiif.io/api/image/2/level1.json", Le = "http://iiif.io/api/image/2/profiles/level1.json", G = "http://iiif.io/api/image/2/level2.json", z = "http://iiif.io/api/image/2/profiles/level2.json", we = "level0", Ie = "level1", K = "level2", Se = "http://iiif.io/api/image/2/level0", Te = "http://iiif.io/api/image/2/level1", Q = "http://iiif.io/api/image/2/level2", xe = [Q, V, F, W, B, H, J, G, z, K], $e = [Se, Te, Q, ce, le, V, pe, ve, F, he, ue, W, fe, me, B, ge, de, ye, Ae, H, J, Ce, be, Re, Le, G, z, we, Ie, K], Me = $e;
4
4
  function m(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 b(t) {
8
+ function R(t) {
9
9
  return Array.isArray(t) ? t : t ? [t] : [];
10
10
  }
11
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"];
@@ -166,7 +166,7 @@ function rt(t) {
166
166
  }
167
167
  return r;
168
168
  }
169
- function R(t, e = "none") {
169
+ function L(t, e = "none") {
170
170
  if (!t) return { none: [""] };
171
171
  let r = rt(t), i = {};
172
172
  for (let s of r) {
@@ -300,7 +300,7 @@ function pt(t) {
300
300
  }
301
301
  }
302
302
  function vt(t) {
303
- return t ? t.map((e) => ({ label: R(e.label), value: R(e.value) })) : [];
303
+ return t ? t.map((e) => ({ label: L(e.label), value: L(e.value) })) : [];
304
304
  }
305
305
  var E = 0;
306
306
  function Z(t, e) {
@@ -315,7 +315,7 @@ function d(t) {
315
315
  }
316
316
  function y(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 ? R(t.label) : void 0, requiredStatement: t.attribution ? { label: R(j.attributionLabel), value: R(t.attribution) } : void 0, navDate: t.navDate, summary: t.description ? R(t.description) : void 0, thumbnail: ht(t.thumbnail) };
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) };
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));
@@ -334,7 +334,7 @@ function ut(t) {
334
334
  }
335
335
  function C(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: R(j.providerName) }] : void 0, partOf: ut(t), rendering: t.rendering, seeAlso: t.seeAlso, start: t.startCanvas, service: t.service ? b(t.service) : void 0, supplementary: r ? [r] : void 0 };
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 };
338
338
  }
339
339
  function ft(t) {
340
340
  return { chars: t.chars, format: t.format ? t.format : void 0, language: t.language };
@@ -421,7 +421,7 @@ function k(t) {
421
421
  function $(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
- function S(...t) {
424
+ function T(...t) {
425
425
  return (e) => t.reduce((r, i) => i(r), e);
426
426
  }
427
427
  var q = ["Collection", "Manifest", "Canvas", "AnnotationPage", "AnnotationCollection", "Annotation", "ContentResource", "Range", "Service", "Selector", "Agent"];
@@ -441,16 +441,16 @@ function Tt(t, e) {
441
441
  }
442
442
  var O = class re {
443
443
  constructor(e, r = {}) {
444
- A(this, "traversals"), A(this, "options"), A(this, "_traverseManifest", S(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", S(this.traverseCanvasItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this), this.traverseLinkedCanvases.bind(this), this.traverseInlineAnnotationPages.bind(this))), A(this, "_traverseAnnotationPage", S(this.traverseAnnotationPageItems.bind(this), this.traverseLinking.bind(this), this.traverseDescriptive.bind(this))), A(this, "_traverseRange", S(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
+ 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 };
445
445
  }
446
446
  static all(e) {
447
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] });
448
448
  }
449
449
  traverseDescriptive(e) {
450
- return e.thumbnail && (e.thumbnail = b(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 = 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;
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 = b(e.service).map((r) => this.traverseService(r))), e.services && (e.services = b(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 = b(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 = 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;
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,7 +498,7 @@ 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 = b(e.service || []).map((r) => this.traverseService(r, e))), e;
501
+ return typeof e == "string" || !e || e && e.service && (e.service = R(e.service || []).map((r) => this.traverseService(r, e))), e;
502
502
  }
503
503
  traverseContentResource(e, r) {
504
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);
@@ -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 = b(i.service).map((s) => this.traverseService(s))), this.traverseType(i, { parent: r }, this.traversals.service);
527
+ return i && i.service && (i.service = R(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);
@@ -573,12 +573,12 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
573
573
  }, xt = (t, e, r) => {
574
574
  const i = f(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, L = 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},${L}/0/default.jpg`;
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`;
578
578
  }, $t = (t) => (e, r = 400) => {
579
579
  if (t.type === "dynamic")
580
580
  return xt(t.service, e, r);
581
- console.error("Level 0 or static image canvas: unspported");
581
+ console.error("Level 0 or static image canvas: unsupported");
582
582
  }, Mt = (t, e = []) => (r = 400) => {
583
583
  const { width: i, height: s } = t;
584
584
  if (!i || !s) return;
@@ -648,10 +648,10 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
648
648
  };
649
649
  a.items && a.items.length > 0 && a.items.forEach((v) => {
650
650
  if (v.source.type === "Range") {
651
- const I = r(v, p, h + 1);
652
- p.children.push(I);
653
- } else
654
- p.children.push({
651
+ const S = r(v, p, h + 1);
652
+ p.children.push(S);
653
+ } else {
654
+ const b = {
655
655
  id: v.id,
656
656
  type: "canvas",
657
657
  source: v,
@@ -661,10 +661,12 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
661
661
  parent: p,
662
662
  level: h + 1,
663
663
  getLabel: v.getLabel
664
- });
664
+ };
665
+ p.children.push(b), e.set(b.id, b);
666
+ }
665
667
  });
666
- 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), L = u.filter((v) => v.source.type === "Canvas"), l = u.filter((v) => v.source.type === "Range");
667
- return p.navItems.push(...L), p.navSections.push(...l), e.set(p.id, p), p;
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;
668
670
  };
669
671
  return { root: t.filter((a) => {
670
672
  var c;
@@ -773,7 +775,7 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
773
775
  }).traverseCollection(n), o.map((c) => ({
774
776
  id: c.id,
775
777
  type: c.type,
776
- getLabel: w(c),
778
+ getLabel: I(c),
777
779
  source: c
778
780
  }));
779
781
  }, i = e === 2 ? te(t) : t, s = r(i);
@@ -782,7 +784,7 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
782
784
  id: i.id,
783
785
  majorVersion: e,
784
786
  items: s,
785
- getLabel: w(i),
787
+ getLabel: I(i),
786
788
  getMetadata: M(i)
787
789
  };
788
790
  }, Dt = (t, e) => {
@@ -805,23 +807,23 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
805
807
  height: l.height,
806
808
  images: v,
807
809
  annotations: l.annotations || [],
808
- getLabel: w(l),
810
+ getLabel: I(l),
809
811
  getMetadata: M(l),
810
812
  getThumbnailURL: Mt(l, v)
811
813
  };
812
814
  }), u = (l) => {
813
- const v = l.items || [], T = v.filter((g) => g.type === "Canvas").map((g) => p.find((x) => x.id === g.id)).filter(Boolean), I = v.filter((g) => g.type === "Range").map((g) => u(g)), oe = [...T, ...I];
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];
814
816
  return {
815
817
  source: l,
816
818
  id: l.id,
817
819
  // Maintain original order
818
820
  items: v.map((g) => oe.find((x) => x.id === g.id)),
819
- canvases: T,
820
- ranges: I,
821
- getLabel: w(l)
821
+ canvases: b,
822
+ ranges: S,
823
+ getLabel: I(l)
822
824
  };
823
- }, L = c.map((l) => u(l));
824
- return { canvases: p, ranges: L };
825
+ }, w = c.map((l) => u(l));
826
+ return { canvases: p, ranges: w };
825
827
  }, i = e === 2 ? te(t) : t, { canvases: s, ranges: n } = r(i);
826
828
  return {
827
829
  source: i,
@@ -829,7 +831,7 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
829
831
  majorVersion: e,
830
832
  canvases: s,
831
833
  structure: n,
832
- getLabel: w(i),
834
+ getLabel: I(i),
833
835
  getMetadata: M(i),
834
836
  getTableOfContents: Pt(n)
835
837
  };
@@ -849,7 +851,7 @@ export {
849
851
  qt as Cozy,
850
852
  _ as getImageURLFromService,
851
853
  kt as getImages,
852
- w as getLabel,
854
+ I as getLabel,
853
855
  M as getMetadata,
854
856
  f as getPropertyValue,
855
857
  $t as getRegionURL,
@@ -2,12 +2,12 @@ import { g as $ } from "../resource-DS2brz47.js";
2
2
  const F = (t) => ({ id: $(t, "id"), ...t }), T = (t) => fetch(t.serviceUrl).then((e) => e.json()).then(F), P = new FinalizationRegistry(({ signal: t, aborted: e }) => {
3
3
  t == null || t.removeEventListener("abort", e);
4
4
  });
5
- function M({ limit: t, interval: e, strict: c, signal: i, onDelay: n }) {
5
+ function M({ limit: t, interval: e, strict: c, signal: i, onDelay: r }) {
6
6
  if (!Number.isFinite(t))
7
7
  throw new TypeError("Expected `limit` to be a finite number");
8
8
  if (!Number.isFinite(e))
9
9
  throw new TypeError("Expected `interval` to be a finite number");
10
- const r = /* @__PURE__ */ new Map();
10
+ const n = /* @__PURE__ */ new Map();
11
11
  let o = 0, a = 0;
12
12
  function l() {
13
13
  const h = Date.now();
@@ -29,18 +29,18 @@ function M({ limit: t, interval: e, strict: c, signal: i, onDelay: n }) {
29
29
  let f;
30
30
  return new Promise((v, C) => {
31
31
  const y = () => {
32
- v(h.apply(this, u)), r.delete(f);
32
+ v(h.apply(this, u)), n.delete(f);
33
33
  }, p = g();
34
- p > 0 ? (f = setTimeout(y, p), r.set(f, C), n == null || n(...u)) : y();
34
+ p > 0 ? (f = setTimeout(y, p), n.set(f, C), r == null || r(...u)) : y();
35
35
  });
36
36
  }, m = () => {
37
- for (const u of r.keys())
38
- clearTimeout(u), r.get(u)(i.reason);
39
- r.clear(), s.splice(0, s.length);
37
+ for (const u of n.keys())
38
+ clearTimeout(u), n.get(u)(i.reason);
39
+ n.clear(), s.splice(0, s.length);
40
40
  };
41
41
  return P.register(w, { signal: i, aborted: m }), i == null || i.throwIfAborted(), i == null || i.addEventListener("abort", m, { once: !0 }), w.isEnabled = !0, Object.defineProperty(w, "queueSize", {
42
42
  get() {
43
- return r.size;
43
+ return n.size;
44
44
  }
45
45
  }), w;
46
46
  };
@@ -53,14 +53,14 @@ const H = () => {
53
53
  return {
54
54
  getInstance: () => e,
55
55
  getConfig: () => ({ ...t }),
56
- setConfig: (r) => {
57
- t = { ...t, ...r }, e = M(t);
56
+ setConfig: (n) => {
57
+ t = { ...t, ...n }, e = M(t);
58
58
  }
59
59
  };
60
60
  }, x = H(), W = (t) => {
61
61
  if (!t) return;
62
62
  const e = x.getConfig();
63
- (t.limit && t.limit !== e.limit || t.interval && t.interval !== e.interval) && (console.log("updating throttle config!"), x.setConfig({ ...e, ...t }));
63
+ (t.limit && t.limit !== e.limit || t.interval && t.interval !== e.interval) && x.setConfig({ ...e, ...t });
64
64
  }, E = (t) => {
65
65
  if (t) {
66
66
  const i = {
@@ -69,20 +69,20 @@ const H = () => {
69
69
  };
70
70
  W(i);
71
71
  }
72
- return { loadImage: x.getInstance()((i) => new Promise((n, r) => {
72
+ return { loadImage: x.getInstance()((i) => new Promise((r, n) => {
73
73
  const o = new Image();
74
- o.crossOrigin = "anonymous", o.onload = () => n(o), o.onerror = r, o.src = i;
74
+ o.crossOrigin = "anonymous", o.onload = () => r(o), o.onerror = n, o.src = i;
75
75
  })) };
76
76
  }, j = (t, e) => {
77
- const { x: c, y: i, w: n, h: r } = e, o = t.tiles[0].width, a = t.tiles[0].height || t.tiles[0].width;
78
- return `${t.id}/${c * o},${i * a},${n},${r}/${o},/0/default.jpg`;
77
+ const { x: c, y: i, w: r, h: n } = e, o = t.tiles[0].width, a = t.tiles[0].height || t.tiles[0].width;
78
+ return `${t.id}/${c * o},${i * a},${r},${n}/${o},/0/default.jpg`;
79
79
  }, R = (t, e) => {
80
- const c = t.tiles[0].width, i = t.tiles[0].height || t.tiles[0].width, n = t.width, r = t.height, o = Math.floor(e.x / c), a = Math.floor(e.y / i), l = Math.ceil((e.x + e.w) / c), s = Math.ceil((e.y + e.h) / i), d = [];
80
+ const c = t.tiles[0].width, i = t.tiles[0].height || t.tiles[0].width, r = t.width, n = t.height, o = Math.floor(e.x / c), a = Math.floor(e.y / i), l = Math.ceil((e.x + e.w) / c), s = Math.ceil((e.y + e.h) / i), d = [];
81
81
  for (let g = a; g < s; g++)
82
82
  for (let h = o; h < l; h++) {
83
- if (h * c >= n || g * i >= r)
83
+ if (h * c >= r || g * i >= n)
84
84
  continue;
85
- const w = Math.min(c, n - h * c), m = Math.min(i, r - g * i);
85
+ const w = Math.min(c, r - h * c), m = Math.min(i, n - g * i);
86
86
  d.push({
87
87
  x: h,
88
88
  y: g,
@@ -93,15 +93,15 @@ const H = () => {
93
93
  }
94
94
  return d;
95
95
  }, L = async (t, e) => {
96
- const c = await T(t), i = R(c, e), n = document.createElement("canvas"), r = n.getContext("2d");
97
- if (!r)
96
+ const c = await T(t), i = R(c, e), r = document.createElement("canvas"), n = r.getContext("2d");
97
+ if (!n)
98
98
  throw new Error("Error initializing canvas context");
99
99
  const o = c.tiles[0].width, a = c.tiles[0].height || c.tiles[0].width, l = (Math.ceil(e.w / o) + 1) * o, s = (Math.ceil(e.h / a) + 1) * a;
100
- n.width = l, n.height = s;
100
+ r.width = l, r.height = s;
101
101
  const d = E({ callsPerSecond: 20 });
102
102
  await Promise.all(i.map(async (w) => {
103
103
  const m = await d.loadImage(w.url), u = w.x * o - e.x, f = w.y * a - e.y;
104
- r.drawImage(m, u, f);
104
+ n.drawImage(m, u, f);
105
105
  }));
106
106
  const g = document.createElement("canvas");
107
107
  g.width = e.w, g.height = e.h;
@@ -109,7 +109,7 @@ const H = () => {
109
109
  if (!h)
110
110
  throw new Error("Error initializing canvas context");
111
111
  return h.drawImage(
112
- n,
112
+ r,
113
113
  0,
114
114
  0,
115
115
  e.w,
@@ -131,43 +131,43 @@ const H = () => {
131
131
  const c = t.tiles[0].scaleFactors.sort((o, a) => a - o);
132
132
  if (!e)
133
133
  return c[0];
134
- const i = e.width ? t.width / e.width : 1 / 0, n = e.height ? t.height / e.height : 1 / 0, r = Math.min(i, n);
134
+ const i = e.width ? t.width / e.width : 1 / 0, r = e.height ? t.height / e.height : 1 / 0, n = Math.min(i, r);
135
135
  for (const o of c)
136
- if (o <= r)
136
+ if (o <= n)
137
137
  return o;
138
138
  return c[c.length - 1];
139
139
  }, b = (t, e) => {
140
140
  const c = I(t, e);
141
- let i = Math.ceil(t.width / c), n = Math.ceil(t.height / c);
141
+ let i = Math.ceil(t.width / c), r = Math.ceil(t.height / c);
142
142
  if (e) {
143
- const r = t.width / t.height;
144
- e.width && i < e.width && (i = e.width, n = Math.ceil(i / r)), e.height && n < e.height && (n = e.height, i = Math.ceil(n * r));
143
+ const n = t.width / t.height;
144
+ e.width && i < e.width && (i = e.width, r = Math.ceil(i / n)), e.height && r < e.height && (r = e.height, i = Math.ceil(r * n));
145
145
  }
146
- return { width: i, height: n };
146
+ return { width: i, height: r };
147
147
  }, k = (t, e) => {
148
- const c = I(t, e), i = t.tiles[0].width, n = t.tiles[0].height || t.tiles[0].width, r = Math.ceil(t.width / (i * c)), o = Math.ceil(t.height / (n * c)), a = [];
148
+ const c = I(t, e), i = t.tiles[0].width, r = t.tiles[0].height || t.tiles[0].width, n = Math.ceil(t.width / (i * c)), o = Math.ceil(t.height / (r * c)), a = [];
149
149
  for (let l = 0; l < o; l++)
150
- for (let s = 0; s < r; s++) {
150
+ for (let s = 0; s < n; s++) {
151
151
  const d = Math.min(
152
152
  i,
153
153
  (t.width - s * i * c) / c
154
154
  ), g = Math.min(
155
- n,
156
- (t.height - l * n * c) / c
155
+ r,
156
+ (t.height - l * r * c) / c
157
157
  );
158
158
  d <= 0 || g <= 0 || a.push({
159
- url: `${t.id}/${s * i * c},${l * n * c},${d * c},${g * c}/${Math.ceil(d)},/0/default.jpg`,
159
+ url: `${t.id}/${s * i * c},${l * r * c},${d * c},${g * c}/${Math.ceil(d)},/0/default.jpg`,
160
160
  width: Math.ceil(d),
161
161
  height: Math.ceil(g),
162
162
  x: s * i,
163
- y: l * n
163
+ y: l * r
164
164
  });
165
165
  }
166
166
  return a;
167
167
  }, O = async (t, e) => {
168
- const c = await T(t), i = k(c, e), n = b(c, e), r = document.createElement("canvas");
169
- r.width = n.width, r.height = n.height;
170
- const o = r.getContext("2d");
168
+ const c = await T(t), i = k(c, e), r = b(c, e), n = document.createElement("canvas");
169
+ n.width = r.width, n.height = r.height;
170
+ const o = n.getContext("2d");
171
171
  if (!o)
172
172
  throw new Error("Error creating canvas context");
173
173
  const a = E();
@@ -175,7 +175,7 @@ const H = () => {
175
175
  const s = await a.loadImage(l.url);
176
176
  o.drawImage(s, l.x, l.y);
177
177
  })), new Promise((l, s) => {
178
- r.toBlob((d) => {
178
+ n.toBlob((d) => {
179
179
  d ? l(d) : s(new Error("Failed to create blob"));
180
180
  }, "image/jpeg", 0.85);
181
181
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-iiif",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "A developer-friendly collection of abstractions and utilities built on top of @iiif/presentation-3 and @iiif/parser",
5
5
  "license": "MIT",
6
6
  "author": "Rainer Simon",
@@ -28,12 +28,12 @@
28
28
  "./level-0": "./dist/level-0/index.js"
29
29
  },
30
30
  "devDependencies": {
31
- "vite": "^6.2.5",
32
- "vite-plugin-dts": "^4.5.3",
33
- "vitest": "^3.1.1"
31
+ "vite": "^6.3.5",
32
+ "vite-plugin-dts": "^4.5.4",
33
+ "vitest": "^3.1.4"
34
34
  },
35
35
  "dependencies": {
36
- "@iiif/parser": "^2.1.7",
36
+ "@iiif/parser": "2.1.7",
37
37
  "@iiif/presentation-3": "^2.2.3",
38
38
  "p-throttle": "^7.0.0",
39
39
  "uuid": "^11.1.0"
@@ -37,7 +37,6 @@ export const getThumbnailURL = (canvas: Canvas, images: CozyImageResource[] = []
37
37
  if (image.type === 'dynamic' || image.type === 'level0') {
38
38
  return getImageURLFromService(image.service, w, h);
39
39
  } else if (image.type === 'static') {
40
- // console.warn('Static image canvas');
41
40
  return image.url;
42
41
  }
43
42
  }
@@ -100,7 +100,6 @@ export const getRegionURL = (
100
100
  if (image.type === 'dynamic') {
101
101
  return getRegionURLFromService(image.service, bounds, minSize);
102
102
  } else {
103
- // TODO
104
- console.error('Level 0 or static image canvas: unspported');
103
+ console.error('Level 0 or static image canvas: unsupported');
105
104
  }
106
105
  }
@@ -26,7 +26,7 @@ export const getTableOfContents = (ranges: CozyRange[]) => (): CozyTOC => {
26
26
  } else {
27
27
  // This child is Canvas, i.e. a TOCNode with
28
28
  // no further children.
29
- node.children.push({
29
+ const canvasChild: CozyTOCNode = {
30
30
  id: item.id,
31
31
  type: 'canvas',
32
32
  source: item as CozyCanvas,
@@ -36,7 +36,11 @@ export const getTableOfContents = (ranges: CozyRange[]) => (): CozyTOC => {
36
36
  parent: node,
37
37
  level: level + 1,
38
38
  getLabel: item.getLabel
39
- });
39
+ };
40
+
41
+ // Add leaf node to children & lookup index
42
+ node.children.push(canvasChild);
43
+ index.set(canvasChild.id, canvasChild);
40
44
  }
41
45
  });
42
46
  }
@@ -53,7 +53,6 @@ const updateThrottleConfig = (opts?: Partial<ThrottleConfig>) => {
53
53
  (opts.limit && opts.limit !== current.limit) ||
54
54
  (opts.interval && opts.interval !== current.interval)
55
55
  ) {
56
- console.log('updating throttle config!');
57
56
  throttleManager.setConfig({ ...current, ...opts });
58
57
  }
59
58
  }