cozy-iiif 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,11 +11,11 @@ export declare const getStaticImagePixelSize: (url: string) => () => Promise<{
11
11
  width: number;
12
12
  height: number;
13
13
  }>;
14
- export declare const getImageURLFromService: (service: Service, width: number, height: number) => string;
14
+ export declare const getImageURLFromService: (service: Service, width: number, height: number, rotation?: number) => string;
15
15
  export declare const getRegionURLFromService: (service: Service, bounds: Bounds, rotation?: number, // 0, 90, 180, 270
16
16
  opts?: GetRegionURLOpts) => string | undefined;
17
17
  export declare const getRegionURL: (image: CozyImageResource) => (bounds: Bounds, rotation?: number, opts?: GetRegionURLOpts) => string | undefined;
18
- export declare const getImageURL: (width: number | undefined, height: number | undefined, service: Service) => (minSize?: number) => string | undefined;
18
+ export declare const getImageURL: (width: number | undefined, height: number | undefined, service: Service) => (minSize?: number, rotation?: number) => string | undefined;
19
19
  export declare const getPixelSizeFromServiceUrl: (serviceUrl: string) => () => Promise<{
20
20
  width: number;
21
21
  height: number;
package/dist/index.js CHANGED
@@ -119,8 +119,8 @@ var N = class F {
119
119
  return t.type === "Choice" && (t.items = t.items.map((i) => this.traverseContentResource(i, t))), j(t) ? this.traverseSpecificResource(t, "ContentResource") : this.traverseType(this.traverseInlineAnnotationPages(this.traverseContentResourceLinking(t)), { parent: r }, this.traversals.contentResource);
120
120
  }
121
121
  traverseSpecificResource(t, r, i) {
122
- let n = t.source;
123
- return typeof t.source == "string" && (n = { id: t.source, type: r || "unknown" }), this.traverseType({ ...t, source: r === "Canvas" || n.type === "Canvas" ? this.traverseType(n, { parent: i }, this.traversals.canvas) : r === "ContentResource" ? this.traverseContentResource(n, { parent: i }) : this.traverseUnknown(n, { parent: i, typeHint: r }) }, { parent: i }, this.traversals.specificResource);
122
+ let s = t.source;
123
+ return typeof t.source == "string" && (s = { id: t.source, type: r || "unknown" }), this.traverseType({ ...t, source: r === "Canvas" || s.type === "Canvas" ? this.traverseType(s, { parent: i }, this.traversals.canvas) : r === "ContentResource" ? this.traverseContentResource(s, { parent: i }) : this.traverseUnknown(s, { parent: i, typeHint: r }) }, { parent: i }, this.traversals.specificResource);
124
124
  }
125
125
  traverseRangeRanges(t) {
126
126
  return t.items &&= t.items.map((r) => typeof r == "string" ? this.traverseCanvas({ id: r, type: "Canvas" }, t) : j(r) ? this.traverseSpecificResource(r, "Canvas", t) : r.type === "Manifest" ? this.traverseManifest(r, t) : this.traverseRange(r, t)), t;
@@ -132,18 +132,18 @@ var N = class F {
132
132
  return this.traverseType(this.traverseDescriptive(this.traverseLinking(t)), { parent: r }, this.traversals.agent);
133
133
  }
134
134
  traverseType(t, r, i) {
135
- return i.reduce((n, s) => {
136
- let a = s(n, r);
137
- return a === void 0 && !this.options.allowUndefinedReturn ? n : a;
135
+ return i.reduce((s, n) => {
136
+ let a = n(s, r);
137
+ return a === void 0 && !this.options.allowUndefinedReturn ? s : a;
138
138
  }, t);
139
139
  }
140
140
  traverseService(t, r) {
141
141
  let i = Object.assign({}, t);
142
- return i && i.service && (i.service = A(i.service).map((n) => this.traverseService(n))), this.traverseType(i, { parent: r }, this.traversals.service);
142
+ return i && i.service && (i.service = A(i.service).map((s) => this.traverseService(s))), this.traverseType(i, { parent: r }, this.traversals.service);
143
143
  }
144
144
  traverseUnknown(t, { parent: r, typeHint: i } = {}) {
145
- let n = dt(t, i);
146
- switch (n) {
145
+ let s = dt(t, i);
146
+ switch (s) {
147
147
  case "Collection":
148
148
  return this.traverseCollection(t, r);
149
149
  case "Manifest":
@@ -163,7 +163,7 @@ var N = class F {
163
163
  case "Agent":
164
164
  return this.traverseAgent(t, r);
165
165
  default:
166
- throw Error(`Unknown or unsupported resource type of ${n}`);
166
+ throw Error(`Unknown or unsupported resource type of ${s}`);
167
167
  }
168
168
  }
169
169
  };
@@ -192,8 +192,8 @@ var zt = class et {
192
192
  }
193
193
  traverseCollectionItems(t) {
194
194
  if (this.options.mergeMemberProperties) {
195
- let r = [...(t.manifests || []).map((s) => typeof s == "string" ? { "@id": s, "@type": "sc:Manifest" } : s), ...(t.collections || []).map((s) => typeof s == "string" ? { "@id": s, "@type": "sc:Collection" } : s), ...t.members || []], i = [], n = r.filter((s) => i.includes(s["@id"]) ? !1 : (i.push(s["@id"]), !0));
196
- delete t.collections, delete t.manifests, t.members = n;
195
+ let r = [...(t.manifests || []).map((n) => typeof n == "string" ? { "@id": n, "@type": "sc:Manifest" } : n), ...(t.collections || []).map((n) => typeof n == "string" ? { "@id": n, "@type": "sc:Collection" } : n), ...t.members || []], i = [], s = r.filter((n) => i.includes(n["@id"]) ? !1 : (i.push(n["@id"]), !0));
196
+ delete t.collections, delete t.manifests, t.members = s;
197
197
  }
198
198
  return t.manifests &&= t.manifests.map((r) => this.traverseManifest(typeof r == "string" ? { "@id": r, "@type": "sc:Manifest" } : r)), t.collections &&= t.collections.map((r) => this.traverseCollection(typeof r == "string" ? { "@id": r, "@type": "sc:Collection" } : r)), t.members &&= t.members.map((r) => typeof r == "string" ? r : r["@type"] === "sc:Collection" ? this.traverseCollection(r) : r["@type"] === "sc:Manifest" ? this.traverseManifest(r) : this.traverseUnknown(r)), t;
199
199
  }
@@ -285,17 +285,17 @@ var zt = class et {
285
285
  return t.profile ? this.traverseService(t) : t;
286
286
  }
287
287
  traverseImageResource(t) {
288
- let r = Array.isArray(t), i = Array.isArray(t) ? t : [t], n = [];
289
- for (let s of i) typeof s == "string" ? n.push(this.traverseContentResource({ "@id": s, "@type": "dctypes:Image" })) : n.push(this.traverseContentResource(s));
290
- return !r && !this.options.convertPropsToArray ? n[0] : n;
288
+ let r = Array.isArray(t), i = Array.isArray(t) ? t : [t], s = [];
289
+ for (let n of i) typeof n == "string" ? s.push(this.traverseContentResource({ "@id": n, "@type": "dctypes:Image" })) : s.push(this.traverseContentResource(n));
290
+ return !r && !this.options.convertPropsToArray ? s[0] : s;
291
291
  }
292
292
  traverseDescriptive(t) {
293
293
  return t.thumbnail &&= this.traverseImageResource(t.thumbnail), t.logo &&= this.traverseImageResource(t.logo), t;
294
294
  }
295
295
  traverseOneOrMoreServices(t) {
296
- let r = Array.isArray(t), i = Array.isArray(t) ? t : [t], n = [];
297
- for (let s of i) n.push(this.traverseService(s));
298
- return !r && !this.options.convertPropsToArray ? n[0] : n;
296
+ let r = Array.isArray(t), i = Array.isArray(t) ? t : [t], s = [];
297
+ for (let n of i) s.push(this.traverseService(n));
298
+ return !r && !this.options.convertPropsToArray ? s[0] : s;
299
299
  }
300
300
  traverseLinking(t) {
301
301
  return t.related &&= this.traverseOneOrManyType(t.related, this.traversals.contentResource), t.rendering &&= this.traverseOneOrManyType(t.rendering, this.traversals.contentResource), t.service &&= this.traverseOneOrMoreServices(t.service), t.seeAlso &&= this.traverseOneOrManyType(t.seeAlso, this.traversals.contentResource), t.within && (typeof t.within == "string" || (t.within = this.traverseOneOrManyType(t.within, this.traversals.contentResource))), t.startCanvas && (typeof t.startCanvas == "string" ? t.startCanvas = this.traverseType({ "@id": t.startCanvas, "@type": "sc:Canvas" }, this.traversals.canvas) : t.startCanvas && this.traverseType(t.startCanvas, this.traversals.canvas)), t.contentLayer && (typeof t.contentLayer == "string" ? t.contentLayer = this.traverseLayer({ "@id": t.contentLayer, "@type": "sc:Layer" }) : t.contentLayer = this.traverseLayer(t.contentLayer)), t;
@@ -306,9 +306,9 @@ var zt = class et {
306
306
  return t.map((i) => this.traverseType(i, r));
307
307
  }
308
308
  traverseType(t, r) {
309
- return r.reduce((i, n) => {
310
- let s = n(i);
311
- return s === void 0 && !this.options.allowUndefinedReturn ? i : s;
309
+ return r.reduce((i, s) => {
310
+ let n = s(i);
311
+ return n === void 0 && !this.options.allowUndefinedReturn ? i : n;
312
312
  }, t);
313
313
  }
314
314
  };
@@ -329,17 +329,17 @@ function Ft(e) {
329
329
  function I(e, t = "none") {
330
330
  if (!e) return { none: [""] };
331
331
  let r = Ft(e), i = {};
332
- for (let n of r) {
333
- if (typeof n == "string") {
334
- i[t] = i[t] ? i[t] : [], i[t].push(n || "");
332
+ for (let s of r) {
333
+ if (typeof s == "string") {
334
+ i[t] = i[t] ? i[t] : [], i[t].push(s || "");
335
335
  continue;
336
336
  }
337
- if (!n["@language"]) {
338
- i[t] = i[t] ? i[t] : [], i[t].push(n["@value"] || "");
337
+ if (!s["@language"]) {
338
+ i[t] = i[t] ? i[t] : [], i[t].push(s["@value"] || "");
339
339
  continue;
340
340
  }
341
- let s = n["@language"];
342
- i[s] = i[s] ? i[s] : [], i[s].push(n["@value"] || "");
341
+ let n = s["@language"];
342
+ i[n] = i[n] ? i[n] : [], i[n].push(s["@value"] || "");
343
343
  }
344
344
  return Object.keys(i).length === 0 ? { none: [""] } : i;
345
345
  }
@@ -398,14 +398,14 @@ function V(e) {
398
398
  }
399
399
  const Jt = ["Collection", "Manifest", "Annotation", "AnnotationPage", "Range", "Service"];
400
400
  function E(e) {
401
- let t = e["@id"] || e.id, r = e["@type"] || e.type, i = e.profile || void 0, n = e["@context"] || void 0;
401
+ let t = e["@id"] || e.id, r = e["@type"] || e.type, i = e.profile || void 0, s = e["@context"] || void 0;
402
402
  if (i) {
403
- let s = Ht(i);
404
- if (s) return s;
403
+ let n = Ht(i);
404
+ if (n) return n;
405
405
  }
406
- if (n) {
407
- let s = Wt(n);
408
- if (s) return s;
406
+ if (s) {
407
+ let n = Wt(s);
408
+ if (n) return n;
409
409
  }
410
410
  if (r) {
411
411
  if (Array.isArray(r)) {
@@ -413,8 +413,8 @@ function E(e) {
413
413
  if (r.indexOf("cnt:ContentAsText") !== -1) return "TextualBody";
414
414
  r = r[0];
415
415
  }
416
- for (let s of ["sc", "oa", "dcterms", "dctypes", "iiif"]) if (r.startsWith(`${s}:`)) {
417
- r = r.slice(s.length + 1);
416
+ for (let n of ["sc", "oa", "dcterms", "dctypes", "iiif"]) if (r.startsWith(`${n}:`)) {
417
+ r = r.slice(n.length + 1);
418
418
  break;
419
419
  }
420
420
  switch (r) {
@@ -440,16 +440,16 @@ function Kt(e) {
440
440
  return t ? t[0] : e;
441
441
  }
442
442
  function Xt(e, t = "Rights/License", r = "none") {
443
- let i = null, n = [], s = Array.isArray(e) ? e : [e];
444
- for (let a of s) {
445
- let c = a ? Kt(a) : void 0;
446
- if (c && (c.indexOf("creativecommons.org") !== -1 || c.indexOf("rightsstatements.org") !== -1)) {
447
- i = c.startsWith("https://") ? `http://${c.slice(8)}` : c;
443
+ let i = null, s = [], n = Array.isArray(e) ? e : [e];
444
+ for (let a of n) {
445
+ let l = a ? Kt(a) : void 0;
446
+ if (l && (l.indexOf("creativecommons.org") !== -1 || l.indexOf("rightsstatements.org") !== -1)) {
447
+ i = l.startsWith("https://") ? `http://${l.slice(8)}` : l;
448
448
  continue;
449
449
  }
450
- c && n.push({ label: { [r]: [t] }, value: { [r]: [c] } });
450
+ l && s.push({ label: { [r]: [t] }, value: { [r]: [l] } });
451
451
  }
452
- return [i, n];
452
+ return [i, s];
453
453
  }
454
454
  const Yt = ["http://iiif.io/api/presentation/2/context.json", "http://iiif.io/api/image/2/context.json", "http://iiif.io/api/image/1/context.json", "http://library.stanford.edu/iiif/image-api/1.1/context.json", "http://iiif.io/api/search/1/context.json", "http://iiif.io/api/search/0/context.json", "http://iiif.io/api/auth/1/context.json", "http://iiif.io/api/auth/0/context.json", "http://iiif.io/api/annex/openannotation/context.json"];
455
455
  function Qt(e) {
@@ -525,10 +525,10 @@ function se(e) {
525
525
  return y({ ...C(e), ...b(e), ...S(e), ...ie(e), items: ne(e.members) });
526
526
  }
527
527
  function ae(e) {
528
- let t = [], r = [], i, n;
529
- for (let a of e.sequences || []) a.canvases.length && t.push(...a.canvases), a.behavior && r.push(...a.behavior), a.viewingDirection && (n = a.viewingDirection), a.startCanvas && (i = a.startCanvas);
530
- let s = C(e);
531
- return r.length && (s.behavior ? s.behavior.push(...r) : s.behavior = r), y({ ...s, ...b(e), ...S(e), viewingDirection: n, start: i, items: t, structures: oe(e.structures) });
528
+ let t = [], r = [], i, s;
529
+ for (let a of e.sequences || []) a.canvases.length && t.push(...a.canvases), a.behavior && r.push(...a.behavior), a.viewingDirection && (s = a.viewingDirection), a.startCanvas && (i = a.startCanvas);
530
+ let n = C(e);
531
+ return r.length && (n.behavior ? n.behavior.push(...r) : n.behavior = r), y({ ...n, ...b(e), ...S(e), viewingDirection: s, start: i, items: t, structures: oe(e.structures) });
532
532
  }
533
533
  function oe(e) {
534
534
  if (!e) return e;
@@ -536,8 +536,8 @@ function oe(e) {
536
536
  for (let i of e) t.set(i.id, i);
537
537
  let r = [];
538
538
  for (let i of e) if (i.items) {
539
- let n = i.items.map((s) => typeof s == "string" ? (r.push(s), t.get(s) || s) : s && s.id ? (r.push(s.id), t.get(s.id) || s) : s);
540
- i.items = n;
539
+ let s = i.items.map((n) => typeof n == "string" ? (r.push(n), t.get(n) || n) : n && n.id ? (r.push(n.id), t.get(n.id) || n) : n);
540
+ i.items = s;
541
541
  }
542
542
  return e.filter((i) => r.indexOf(i.id) === -1);
543
543
  }
@@ -583,8 +583,8 @@ function he(e) {
583
583
  return y({ ...C(e), ...b(e), ...S(e), items: e.members });
584
584
  }
585
585
  function fe(e) {
586
- let { "@id": t, "@type": r, "@context": i, profile: n, ...s } = e, a = {};
587
- return t && (a["@id"] = t), a["@type"] = E(e), a["@type"] === "unknown" && (i && i.length && (a["@context"] = i), a["@type"] = "Service"), n && (a.profile = rt(n)), y({ ...a, ...s });
586
+ let { "@id": t, "@type": r, "@context": i, profile: s, ...n } = e, a = {};
587
+ return t && (a["@id"] = t), a["@type"] = E(e), a["@type"] === "unknown" && (i && i.length && (a["@context"] = i), a["@type"] = "Service"), s && (a.profile = rt(s)), y({ ...a, ...n });
588
588
  }
589
589
  function ge(e) {
590
590
  return y({ ...C(e), ...b(e), ...S(e) });
@@ -603,82 +603,82 @@ function O(e) {
603
603
  const at = (e) => e.endsWith("/info.json") ? e : `${e.endsWith("/") ? e : `${e}/`}info.json`, ot = (e) => d(e, "type").startsWith("ImageService") || e.profile?.toString().includes("iiif.io/api/image/"), ct = (e) => {
604
604
  const t = d(e, "type"), r = d(e, "context");
605
605
  if (t === "ImageService2" || r?.includes("image/2")) {
606
- const n = d(e, "profile"), s = ["level0", "level1", "level2"];
607
- return { majorVersion: 2, profileLevel: (Array.isArray(n) ? n : n ? [n] : []).map((p) => s.findIndex((o) => p.toString().includes(o))).filter((p) => p > -1).sort((p, o) => o - p)[0] };
606
+ const s = d(e, "profile"), n = ["level0", "level1", "level2"];
607
+ return { majorVersion: 2, profileLevel: (Array.isArray(s) ? s : s ? [s] : []).map((c) => n.findIndex((o) => c.toString().includes(o))).filter((c) => c > -1).sort((c, o) => o - c)[0] };
608
608
  } else if (t || r)
609
609
  return { majorVersion: 3, profileLevel: parseInt(e.profile) };
610
610
  }, lt = (e) => () => {
611
611
  const t = typeof window < "u";
612
612
  return fetch(e).then((r) => r.blob()).then((r) => t ? createImageBitmap(r).then((i) => {
613
- const { width: n, height: s } = i;
614
- return i.close(), { width: n, height: s };
613
+ const { width: s, height: n } = i;
614
+ return i.close(), { width: s, height: n };
615
615
  }) : r.arrayBuffer().then((i) => ft(new Uint8Array(i))));
616
- }, D = (e, t, r) => {
617
- const i = d(e, "id"), n = e.profile || "";
616
+ }, D = (e, t, r, i = 0) => {
617
+ const s = d(e, "id"), n = e.profile || "";
618
618
  if (typeof n == "string" && (n.includes("level0") || n.includes("level:0"))) {
619
619
  if ("sizes" in e && Array.isArray(e.sizes)) {
620
- const a = e.sizes.sort((c, p) => p.width * p.height - c.width * c.height).filter((c) => c.width * c.height >= t * r)[0];
621
- if (a)
622
- return `${i}/full/${a.width},${a.height}/0/default.jpg`;
620
+ const l = e.sizes.sort((c, o) => o.width * o.height - c.width * c.height).filter((c) => c.width * c.height >= t * r)[0];
621
+ if (l)
622
+ return `${s}/full/${l.width},${l.height}/0/default.jpg`;
623
623
  }
624
- return `${i}/full/full/0/default.jpg`;
624
+ return `${s}/full/full/0/default.jpg`;
625
625
  }
626
- return `${i}/full/!${t},${r}/0/default.jpg`;
626
+ return `${s}/full/!${t},${r}/${i}/default.jpg`;
627
627
  }, de = (e, t, r = 0, i = { minSize: 400 }) => {
628
- const n = d(e, "id"), s = e.profile || "";
629
- if (typeof s == "string" && (s.includes("level0") || s.includes("level:0"))) {
630
- console.warn(`Level 0 image service does not support custom region URLs: ${n}`);
628
+ const s = d(e, "id"), n = e.profile || "";
629
+ if (typeof n == "string" && (n.includes("level0") || n.includes("level:0"))) {
630
+ console.warn(`Level 0 image service does not support custom region URLs: ${s}`);
631
631
  return;
632
632
  }
633
- const { x: c, y: p, w: o, h: v } = t, { minSize: u = 400, maxSize: f } = i, l = u / Math.min(o, v), g = f ? Math.max(l, f / Math.max(o, v)) : l, w = Math.round(o * g), h = Math.round(v * g), R = (r % 360 + 360) % 360, m = `${Math.round(c)},${Math.round(p)},${Math.round(o)},${Math.round(v)}`;
634
- return `${n}/${m}/!${w},${h}/${R}/default.jpg`;
633
+ const { x: l, y: c, w: o, h: v } = t, { minSize: u = 400, maxSize: f } = i, p = u / Math.min(o, v), g = f ? Math.max(p, f / Math.max(o, v)) : p, w = Math.round(o * g), h = Math.round(v * g), R = (r % 360 + 360) % 360, m = `${Math.round(l)},${Math.round(c)},${Math.round(o)},${Math.round(v)}`;
634
+ return `${s}/${m}/!${w},${h}/${R}/default.jpg`;
635
635
  }, pt = (e) => (t, r = 0, i = { minSize: 400 }) => {
636
636
  if (e.type === "dynamic")
637
637
  return de(e.service, t, r, i);
638
638
  console.error("Level 0 or static image canvas: unsupported");
639
- }, vt = (e, t, r) => (i = 800) => {
639
+ }, vt = (e, t, r) => (i = 800, s = 0) => {
640
640
  if (!e || !t) return;
641
- const n = e / t, s = n < 1, a = Math.ceil(s ? i / n : i), c = Math.ceil(s ? i : i / n);
642
- return D(r, c, a);
641
+ const n = e / t, a = n < 1, l = Math.ceil(a ? i / n : i), c = Math.ceil(a ? i : i / n);
642
+ return D(r, c, l, s);
643
643
  }, ut = (e) => () => fetch(e).then((t) => t.json()).then((t) => {
644
644
  const r = t.width, i = t.height;
645
645
  return r !== void 0 && i !== void 0 ? { width: r, height: i } : void 0;
646
646
  }), ye = (e, t = []) => (r = 400) => {
647
- const { width: i, height: n } = e;
648
- if (!i || !n) return;
649
- const s = i / n, a = s < 1, c = Math.ceil(a ? r / s : r), p = Math.ceil(a ? r : r / s);
647
+ const { width: i, height: s } = e;
648
+ if (!i || !s) return;
649
+ const n = i / s, a = n < 1, l = Math.ceil(a ? r / n : r), c = Math.ceil(a ? r : r / n);
650
650
  if (e.thumbnail && e.thumbnail.length > 0) {
651
651
  const o = e.thumbnail[0];
652
652
  if ("service" in o && Array.isArray(o.service)) {
653
653
  const v = o.service.find((u) => ot(u));
654
654
  if (v)
655
- return D(v, p, c);
655
+ return D(v, c, l);
656
656
  }
657
657
  if ("id" in o) return o.id;
658
658
  }
659
659
  for (const o of t) {
660
660
  if (o.type === "dynamic" || o.type === "level0")
661
- return D(o.service, p, c);
661
+ return D(o.service, c, l);
662
662
  if (o.type === "static")
663
663
  return o.url;
664
664
  }
665
665
  }, Ae = (e) => {
666
- const { format: t, height: r, width: i } = e, n = d(e, "id"), s = (e.service || []).find(ot), a = s ? ct(s) : void 0;
667
- if (s && a) {
668
- const c = at(d(s, "id")), p = {
666
+ const { format: t, height: r, width: i } = e, s = d(e, "id"), n = (e.service || []).find(ot), a = n ? ct(n) : void 0;
667
+ if (n && a) {
668
+ const l = at(d(n, "id")), c = {
669
669
  source: e,
670
670
  type: a.profileLevel === 0 ? "level0" : "dynamic",
671
- service: s,
671
+ service: n,
672
672
  width: i,
673
673
  height: r,
674
674
  majorVersion: a.majorVersion,
675
- serviceUrl: c,
676
- getImageURL: vt(i, r, s),
677
- getPixelSize: ut(c)
675
+ serviceUrl: l,
676
+ getImageURL: vt(i, r, n),
677
+ getPixelSize: ut(l)
678
678
  };
679
- return a.profileLevel === 0 ? p : {
680
- ...p,
681
- getRegionURL: pt(p)
679
+ return a.profileLevel === 0 ? c : {
680
+ ...c,
681
+ getRegionURL: pt(c)
682
682
  };
683
683
  } else
684
684
  return {
@@ -686,18 +686,18 @@ const at = (e) => e.endsWith("/info.json") ? e : `${e.endsWith("/") ? e : `${e}/
686
686
  type: "static",
687
687
  width: i,
688
688
  height: r,
689
- url: n,
689
+ url: s,
690
690
  format: t,
691
- getImageURL: () => n,
692
- getPixelSize: lt(n)
691
+ getImageURL: () => s,
692
+ getPixelSize: lt(s)
693
693
  };
694
694
  }, Ce = (e) => {
695
695
  const t = [];
696
696
  return new N({
697
697
  annotation: [(i) => {
698
698
  if (i.motivation === "painting" || !i.motivation) {
699
- const s = (i.body ? Array.isArray(i.body) ? i.body : [i.body] : []).filter((a) => a.type === "Image");
700
- t.push(...s.map((a) => Ae(a)));
699
+ const n = (i.body ? Array.isArray(i.body) ? i.body : [i.body] : []).filter((a) => a.type === "Image");
700
+ t.push(...n.map((a) => Ae(a)));
701
701
  }
702
702
  }]
703
703
  }).traverseCanvas(e), t;
@@ -733,7 +733,7 @@ const at = (e) => e.endsWith("/info.json") ? e : `${e.endsWith("/") ? e : `${e}/
733
733
  f.children.push(R), t.set(R.id, R);
734
734
  }
735
735
  });
736
- const l = f.children.map((h) => h.type === "canvas" ? h.source : h.children.length === 1 && h.children[0].type === "canvas" ? h.children[0].source : h.source), g = l.filter((h) => h.source.type === "Canvas"), w = l.filter((h) => h.source.type === "Range");
736
+ const p = f.children.map((h) => h.type === "canvas" ? h.source : h.children.length === 1 && h.children[0].type === "canvas" ? h.children[0].source : h.source), g = p.filter((h) => h.source.type === "Canvas"), w = p.filter((h) => h.source.type === "Range");
737
737
  return f.navItems.push(...g), f.navSections.push(...w), t.set(f.id, f), f;
738
738
  };
739
739
  return { root: e.filter((o) => o.source.behavior?.includes("top")).map((o) => r(o, void 0)), enumerateNodes: (o) => {
@@ -742,7 +742,7 @@ const at = (e) => e.endsWith("/info.json") ? e : `${e.endsWith("/") ? e : `${e}/
742
742
  }, getBreadcrumbs: (o) => {
743
743
  const v = t.get(o);
744
744
  if (!v) return [];
745
- const u = (f, l = []) => f.parent ? u(f.parent, [f, ...l]) : [f, ...l];
745
+ const u = (f, p = []) => f.parent ? u(f.parent, [f, ...p]) : [f, ...p];
746
746
  return u(v);
747
747
  }, getNavParent: (o) => {
748
748
  const v = t.get(o);
@@ -797,7 +797,7 @@ const at = (e) => e.endsWith("/info.json") ? e : `${e.endsWith("/") ? e : `${e}/
797
797
  };
798
798
  }
799
799
  }, ht = (e, t) => {
800
- const r = Array.isArray(e["@context"]) ? e["@context"].find((n) => n.includes("iiif.io/api/presentation") || n.includes("iiif.io/api/image") || n.includes("shared-canvas")) : e["@context"];
800
+ const r = Array.isArray(e["@context"]) ? e["@context"].find((s) => s.includes("iiif.io/api/presentation") || s.includes("iiif.io/api/image") || s.includes("shared-canvas")) : e["@context"];
801
801
  if (!r)
802
802
  return {
803
803
  type: "error",
@@ -812,23 +812,23 @@ const at = (e) => e.endsWith("/info.json") ? e : `${e.endsWith("/") ? e : `${e}/
812
812
  message: "Missing id property"
813
813
  };
814
814
  if (r.includes("presentation/2") || r.includes("presentation/3") || r.includes("shared-canvas")) {
815
- const n = r.includes("presentation/3") ? 3 : 2;
815
+ const s = r.includes("presentation/3") ? 3 : 2;
816
816
  return d(e, "type").includes("Collection") ? {
817
817
  type: "collection",
818
818
  url: t || i,
819
- resource: Le(e, n)
819
+ resource: Le(e, s)
820
820
  } : {
821
821
  type: "manifest",
822
822
  url: t || i,
823
- resource: Se(e, n)
823
+ resource: Se(e, s)
824
824
  };
825
825
  }
826
826
  if (r.includes("image/2") || r.includes("image/3")) {
827
- const n = Ie(e);
828
- return n ? {
827
+ const s = Ie(e);
828
+ return s ? {
829
829
  type: "iiif-image",
830
830
  url: t || i,
831
- resource: n
831
+ resource: s
832
832
  } : {
833
833
  type: "error",
834
834
  code: "INVALID_MANIFEST",
@@ -841,92 +841,92 @@ const at = (e) => e.endsWith("/info.json") ? e : `${e.endsWith("/") ? e : `${e}/
841
841
  message: "JSON resource is not a recognized IIIF format"
842
842
  };
843
843
  }, Le = (e, t) => {
844
- const r = (s) => {
844
+ const r = (n) => {
845
845
  const a = [];
846
846
  return new N({
847
- manifest: [(p) => a.push(p)]
848
- }).traverseCollection(s), a.map((p) => ({
849
- id: p.id,
850
- type: p.type,
851
- getLabel: x(p),
852
- source: p
847
+ manifest: [(c) => a.push(c)]
848
+ }).traverseCollection(n), a.map((c) => ({
849
+ id: c.id,
850
+ type: c.type,
851
+ getLabel: x(c),
852
+ source: c
853
853
  }));
854
- }, i = t === 2 ? st(e) : e, n = r(i);
854
+ }, i = t === 2 ? st(e) : e, s = r(i);
855
855
  return {
856
856
  source: i,
857
857
  id: i.id,
858
858
  majorVersion: t,
859
- items: n,
859
+ items: s,
860
860
  getLabel: x(i),
861
861
  getMetadata: k(i)
862
862
  };
863
863
  }, Se = (e, t) => {
864
864
  const r = (a) => {
865
- const c = [], p = [];
865
+ const l = [], c = [];
866
866
  new N({
867
- canvas: [(l) => {
868
- l.items && c.push(l);
867
+ canvas: [(p) => {
868
+ p.items && l.push(p);
869
869
  }],
870
- range: [(l) => {
871
- l.type === "Range" && p.push(l);
870
+ range: [(p) => {
871
+ p.type === "Range" && c.push(p);
872
872
  }]
873
873
  }).traverseManifest(a);
874
- const v = c.map((l) => {
875
- const g = Ce(l);
874
+ const v = l.map((p) => {
875
+ const g = Ce(p);
876
876
  return {
877
- source: l,
878
- id: l.id,
879
- width: l.width,
880
- height: l.height,
877
+ source: p,
878
+ id: p.id,
879
+ width: p.width,
880
+ height: p.height,
881
881
  images: g,
882
- annotations: l.annotations || [],
882
+ annotations: p.annotations || [],
883
883
  getImageURL: g.length > 0 ? g[0].getImageURL : () => {
884
884
  },
885
- getLabel: x(l),
886
- getMetadata: k(l),
887
- getThumbnailURL: ye(l, g)
885
+ getLabel: x(p),
886
+ getMetadata: k(p),
887
+ getThumbnailURL: ye(p, g)
888
888
  };
889
- }), u = (l) => {
890
- const g = l.items || [], w = g.filter((m) => m.type === "Canvas").map((m) => v.find((M) => M.id === m.id)).filter(Boolean), h = g.filter((m) => m.type === "Range").map((m) => u(m)), R = [...w, ...h];
889
+ }), u = (p) => {
890
+ const g = p.items || [], w = g.filter((m) => m.type === "Canvas").map((m) => v.find((M) => M.id === m.id)).filter(Boolean), h = g.filter((m) => m.type === "Range").map((m) => u(m)), R = [...w, ...h];
891
891
  return {
892
- source: l,
893
- id: l.id,
892
+ source: p,
893
+ id: p.id,
894
894
  // Maintain original order
895
895
  items: g.map((m) => R.find((M) => M.id === m.id)),
896
896
  canvases: w,
897
897
  ranges: h,
898
- getLabel: x(l)
898
+ getLabel: x(p)
899
899
  };
900
- }, f = p.map((l) => u(l));
900
+ }, f = c.map((p) => u(p));
901
901
  return { canvases: v, ranges: f };
902
- }, i = t === 2 ? st(e) : e, { canvases: n, ranges: s } = r(i);
902
+ }, i = t === 2 ? st(e) : e, { canvases: s, ranges: n } = r(i);
903
903
  return {
904
904
  source: i,
905
905
  id: i.id,
906
906
  majorVersion: t,
907
- canvases: n,
908
- structure: s,
907
+ canvases: s,
908
+ structure: n,
909
909
  getLabel: x(i),
910
910
  getMetadata: k(i),
911
- getTableOfContents: be(s)
911
+ getTableOfContents: be(n)
912
912
  };
913
913
  }, Ie = (e) => {
914
- const { width: t, height: r, format: i } = e, n = d(e, "id"), s = ct(e);
915
- if (s) {
916
- const a = at(d(e, "id")), c = {
914
+ const { width: t, height: r, format: i } = e, s = d(e, "id"), n = ct(e);
915
+ if (n) {
916
+ const a = at(d(e, "id")), l = {
917
917
  source: e,
918
- type: s.profileLevel === 0 ? "level0" : "dynamic",
918
+ type: n.profileLevel === 0 ? "level0" : "dynamic",
919
919
  service: e,
920
920
  width: t,
921
921
  height: r,
922
- majorVersion: s.majorVersion,
922
+ majorVersion: n.majorVersion,
923
923
  serviceUrl: a,
924
924
  getImageURL: vt(t, r, e),
925
925
  getPixelSize: ut(a)
926
926
  };
927
- return s.profileLevel === 0 ? c : {
928
- ...c,
929
- getRegionURL: pt(c)
927
+ return n.profileLevel === 0 ? l : {
928
+ ...l,
929
+ getRegionURL: pt(l)
930
930
  };
931
931
  } else
932
932
  return {
@@ -934,10 +934,10 @@ const at = (e) => e.endsWith("/info.json") ? e : `${e.endsWith("/") ? e : `${e}/
934
934
  type: "static",
935
935
  width: t,
936
936
  height: r,
937
- url: n,
937
+ url: s,
938
938
  format: i,
939
- getImageURL: () => n,
940
- getPixelSize: lt(n)
939
+ getImageURL: () => s,
940
+ getPixelSize: lt(s)
941
941
  };
942
942
  }, Te = { parse: ht, parseURL: Re };
943
943
  export {
package/dist/types.d.ts CHANGED
@@ -61,7 +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
+ getImageURL(minSize?: number, rotation?: number): string;
65
65
  getLabel(locale?: string): string;
66
66
  getMetadata(locale?: string): CozyMetadata[];
67
67
  getThumbnailURL(minSize?: number): string;
@@ -95,7 +95,7 @@ interface BaseImageResource {
95
95
  readonly type: 'static' | 'dynamic' | 'level0';
96
96
  readonly width: number;
97
97
  readonly height: number;
98
- getImageURL(minSize?: number): string;
98
+ getImageURL(minSize?: number, rotation?: number): string;
99
99
  getPixelSize(): Promise<{
100
100
  width: number;
101
101
  height: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-iiif",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "A developer-friendly collection of abstractions and utilities built on top of @iiif/presentation-3 and @iiif/parser",
5
5
  "license": "MIT",
6
6
  "author": "Rainer Simon",
@@ -60,7 +60,8 @@ export const getStaticImagePixelSize = (url: string) => () => {
60
60
  export const getImageURLFromService = (
61
61
  service: Service,
62
62
  width: number,
63
- height: number
63
+ height: number,
64
+ rotation: number = 0
64
65
  ): string => {
65
66
  const id = getPropertyValue(service, 'id');
66
67
 
@@ -84,7 +85,7 @@ export const getImageURLFromService = (
84
85
  return `${id}/full/full/0/default.jpg`;
85
86
  }
86
87
 
87
- return `${id}/full/!${width},${height}/0/default.jpg`;
88
+ return `${id}/full/!${width},${height}/${rotation}/default.jpg`;
88
89
  }
89
90
 
90
91
  export const getRegionURLFromService = (
@@ -141,7 +142,7 @@ export const getImageURL = (
141
142
  width: number | undefined,
142
143
  height: number | undefined,
143
144
  service: Service
144
- ) => (minSize = 800) => {
145
+ ) => (minSize = 800, rotation = 0) => {
145
146
  if (!width || !height) return;
146
147
 
147
148
  const aspect = width / height;
@@ -150,7 +151,7 @@ export const getImageURL = (
150
151
  const h = Math.ceil(isPortrait ? minSize / aspect : minSize);
151
152
  const w = Math.ceil(isPortrait ? minSize : minSize / aspect);
152
153
 
153
- return getImageURLFromService(service!, w, h);
154
+ return getImageURLFromService(service!, w, h, rotation);
154
155
  }
155
156
 
156
157
  export const getPixelSizeFromServiceUrl = (serviceUrl: string) => () =>
package/src/types.ts CHANGED
@@ -98,7 +98,7 @@ export interface CozyCanvas {
98
98
 
99
99
  readonly annotations: AnnotationPage[];
100
100
 
101
- getImageURL(minSize?: number): string;
101
+ getImageURL(minSize?: number, rotation?: number): string;
102
102
 
103
103
  getLabel(locale?: string): string;
104
104
 
@@ -170,7 +170,7 @@ interface BaseImageResource {
170
170
 
171
171
  readonly height: number;
172
172
 
173
- getImageURL(minSize?: number): string;
173
+ getImageURL(minSize?: number, rotation?: number): string;
174
174
 
175
175
  getPixelSize(): Promise<{ width: number, height: number }>;
176
176