cozy-iiif 0.2.5 → 0.2.7

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,6 +1,6 @@
1
1
  import { g as m, a as j, b as S } 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", 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", z = "http://iiif.io/api/image/2/level2.json", K = "http://iiif.io/api/image/2/profiles/level2.json", we = "level0", Ie = "level1", Q = "level2", Se = "http://iiif.io/api/image/2/level0", Te = "http://iiif.io/api/image/2/level1", X = "http://iiif.io/api/image/2/level2", xe = [X, F, W, B, H, J, G, z, K, Q], $e = [Se, Te, X, ce, le, F, pe, ve, W, he, ue, B, fe, me, H, ge, de, ye, Ae, J, G, Ce, be, Re, Le, z, K, we, Ie, Q], Me = $e;
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
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;
@@ -8,25 +8,25 @@ function g(t) {
8
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, b = (t, e, r) => (ke(t, typeof e != "symbol" ? e + "" : e, r), r), D = ["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 = D.indexOf(t["@type"]);
18
- if (e !== -1) return D[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 Y {
24
+ var Oe = class Z {
25
25
  constructor(e, r = {}) {
26
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 Y({ 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 Y {
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", 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", 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, Ne, Ee, qe, _e, Ve, Fe, We, Be, He, Je, Ge, ze, Ke, Qe, Xe, Ye], k = { 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 [];
@@ -183,8 +183,8 @@ function I(t, e = "none") {
183
183
  }
184
184
  return Object.keys(i).length === 0 ? { none: [""] } : i;
185
185
  }
186
- function Z(t) {
187
- if (Array.isArray(t)) return Z(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 N(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 O(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);
@@ -302,16 +302,16 @@ function pt(t) {
302
302
  function vt(t) {
303
303
  return t ? t.map((e) => ({ label: I(e.label), value: I(e.value) })) : [];
304
304
  }
305
- var E = 0;
305
+ var q = 0;
306
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
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(N) : t.motivation && (r = N(t.motivation)), { "@context": t["@context"] ? pt(t["@context"]) : void 0, id: (t["@id"] || ee(t)).trim(), type: O(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
316
  function C(t) {
317
317
  let [e, r] = ct(t.license), i = [...t.metadata ? vt(t.metadata) : [], ...r];
@@ -329,7 +329,7 @@ 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: O(i) });
332
+ } else i["@id"] && r.push({ id: i["@id"], type: U(i) });
333
333
  return r.length ? r : void 0;
334
334
  }
335
335
  function R(t) {
@@ -384,9 +384,9 @@ function bt(t) {
384
384
  return { type: "SpecificResource", source: i, selector: P(r.selector) };
385
385
  } else return encodeURI(r["@id"]).trim();
386
386
  }
387
- return g({ ...A(t), ...C(t), ...R(t), target: e(t.on), body: Array.isArray(t.resource) ? t.resource.map(q) : q(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 q(t) {
389
+ function _(t) {
390
390
  return t.type === "Choice" ? t : te(t);
391
391
  }
392
392
  function te(t) {
@@ -402,7 +402,7 @@ function Lt(t) {
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"] = O(t), o["@type"] === "unknown" && (i && i.length && (o["@context"] = i), o["@type"] = "Service"), s && (o.profile = Z(s)), g({ ...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
408
  return g({ ...A(t), ...C(t), ...R(t) });
@@ -424,7 +424,7 @@ function M(t) {
424
424
  function T(...t) {
425
425
  return (e) => t.reduce((r, i) => i(r), e);
426
426
  }
427
- var _ = ["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,13 +433,13 @@ 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 = _.indexOf(t.type);
437
- if (r !== -1) return _[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 U = class ie {
442
+ var D = class ie {
443
443
  constructor(e, r = {}) {
444
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
  }
@@ -559,7 +559,7 @@ const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.prof
559
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
- }, V = (t, e, r) => {
562
+ }, O = (t, e, r) => {
563
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)) {
@@ -588,17 +588,27 @@ const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.prof
588
588
  if ("service" in l && Array.isArray(l.service)) {
589
589
  const u = l.service.find((v) => se(v));
590
590
  if (u)
591
- return V(u, a, c);
591
+ return O(u, a, c);
592
592
  }
593
593
  if ("id" in l) return l.id;
594
594
  }
595
595
  for (const l of e) {
596
596
  if (l.type === "dynamic" || l.type === "level0")
597
- return V(l.service, a, c);
597
+ return O(l.service, a, c);
598
598
  if (l.type === "static")
599
599
  return l.url;
600
600
  }
601
- }, ae = (t) => t.endsWith("/info.json") ? t : `${t.endsWith("/") ? t : `${t}/`}info.json`, jt = (t) => {
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) => {
602
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
614
  const c = {
@@ -623,17 +633,17 @@ const se = (t) => m(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 U({
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) => () => {
646
+ }, Ot = (t) => () => {
637
647
  const e = /* @__PURE__ */ new Map(), r = (a, l, u = 0) => {
638
648
  const v = {
639
649
  id: a.id,
@@ -680,7 +690,7 @@ const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.prof
680
690
  const u = (v, d = []) => v.parent ? u(v.parent, [v, ...d]) : [v, ...d];
681
691
  return u(l);
682
692
  }, getNode: (a) => e.get(a) };
683
- }, Ot = async (t) => {
693
+ }, Ut = async (t) => {
684
694
  try {
685
695
  new URL(t);
686
696
  } catch {
@@ -746,15 +756,15 @@ const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.prof
746
756
  return m(t, "type").includes("Collection") ? {
747
757
  type: "collection",
748
758
  url: e || i,
749
- resource: Ut(t, s)
759
+ resource: Dt(t, s)
750
760
  } : {
751
761
  type: "manifest",
752
762
  url: e || i,
753
- resource: Dt(t, s)
763
+ resource: Nt(t, s)
754
764
  };
755
765
  }
756
766
  if (r.includes("image/2") || r.includes("image/3")) {
757
- const s = Nt(t);
767
+ const s = Et(t);
758
768
  return s ? {
759
769
  type: "iiif-image",
760
770
  url: e || i,
@@ -770,10 +780,10 @@ const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.prof
770
780
  code: "INVALID_MANIFEST",
771
781
  message: "JSON resource is not a recognized IIIF format"
772
782
  };
773
- }, Ut = (t, e) => {
783
+ }, Dt = (t, e) => {
774
784
  const r = (n) => {
775
785
  const o = [];
776
- return new U({
786
+ return new D({
777
787
  manifest: [(a) => o.push(a)]
778
788
  }).traverseCollection(n), o.map((a) => ({
779
789
  id: a.id,
@@ -790,10 +800,10 @@ const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.prof
790
800
  getLabel: S(i),
791
801
  getMetadata: j(i)
792
802
  };
793
- }, Dt = (t, e) => {
803
+ }, Nt = (t, e) => {
794
804
  const r = (o) => {
795
805
  const c = [], a = [];
796
- new U({
806
+ new D({
797
807
  canvas: [(p) => {
798
808
  p.items && c.push(p);
799
809
  }],
@@ -802,7 +812,7 @@ const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.prof
802
812
  }]
803
813
  }).traverseManifest(o);
804
814
  const u = c.map((p) => {
805
- const f = kt(p);
815
+ const f = Pt(p);
806
816
  return {
807
817
  source: p,
808
818
  id: p.id,
@@ -810,6 +820,7 @@ const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.prof
810
820
  height: p.height,
811
821
  images: f,
812
822
  annotations: p.annotations || [],
823
+ getImageURL: jt(p, f),
813
824
  getLabel: S(p),
814
825
  getMetadata: j(p),
815
826
  getThumbnailURL: Mt(p, f)
@@ -836,9 +847,9 @@ const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.prof
836
847
  structure: n,
837
848
  getLabel: S(i),
838
849
  getMetadata: j(i),
839
- getTableOfContents: Pt(n)
850
+ getTableOfContents: Ot(n)
840
851
  };
841
- }, Nt = (t) => {
852
+ }, Et = (t) => {
842
853
  const { width: e, height: r } = t, i = ne(t);
843
854
  if (i)
844
855
  return {
@@ -849,18 +860,19 @@ const se = (t) => m(t, "type").startsWith("ImageService") || t.profile && t.prof
849
860
  majorVersion: i.majorVersion,
850
861
  serviceUrl: ae(m(t, "id"))
851
862
  };
852
- }, qt = { parse: oe, parseURL: Ot };
863
+ }, _t = { parse: oe, parseURL: Ut };
853
864
  export {
854
- qt as Cozy,
855
- V as getImageURLFromService,
856
- kt as getImages,
865
+ _t as Cozy,
866
+ jt as getImageURL,
867
+ O as getImageURLFromService,
868
+ Pt as getImages,
857
869
  S as getLabel,
858
870
  j as getMetadata,
859
871
  m as getPropertyValue,
860
872
  $t as getRegionURL,
861
873
  xt as getRegionURLFromService,
862
- Ft as getStringValue,
863
- Pt as getTableOfContents,
874
+ Wt as getStringValue,
875
+ Ot as getTableOfContents,
864
876
  Mt as getThumbnailURL,
865
877
  se as isImageService,
866
878
  ae as normalizeServiceUrl,
package/dist/types.d.ts CHANGED
@@ -61,6 +61,7 @@ export interface CozyCanvas {
61
61
  readonly height: number;
62
62
  readonly images: CozyImageResource[];
63
63
  readonly annotations: AnnotationPage[];
64
+ getImageURL(minSize?: number): string;
64
65
  getLabel(locale?: string): string;
65
66
  getMetadata(locale?: string): CozyMetadata[];
66
67
  getThumbnailURL(minSize?: number): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-iiif",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
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
 
package/src/types.ts CHANGED
@@ -99,6 +99,8 @@ export interface CozyCanvas {
99
99
 
100
100
  readonly annotations: AnnotationPage[];
101
101
 
102
+ getImageURL(minSize?: number): string;
103
+
102
104
  getLabel(locale?: string): string;
103
105
 
104
106
  getMetadata(locale?: string): CozyMetadata[];