cozy-iiif 0.2.3 → 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 +61 -61
- package/dist/level-0/index.js +39 -39
- package/package.json +2 -2
- package/src/core/canvas.ts +0 -1
- package/src/core/image-service.ts +1 -2
- package/src/level-0/throttled-loader.ts +0 -1
package/dist/index.js
CHANGED
@@ -8,14 +8,14 @@ function m(t) {
|
|
8
8
|
function R(t) {
|
9
9
|
return Array.isArray(t) ? t : t ? [t] : [];
|
10
10
|
}
|
11
|
-
var je = Object.defineProperty, ke = (t, e, r) => e in t ? je(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, A = (t, e, r) => (ke(t, typeof e != "symbol" ? e + "" : e, r), r),
|
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"];
|
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 =
|
18
|
-
if (e !== -1) return
|
17
|
+
let e = U.indexOf(t["@type"]);
|
18
|
+
if (e !== -1) return U[e];
|
19
19
|
}
|
20
20
|
if (t.profile) return "Service";
|
21
21
|
if (t.format || t["@type"]) return "ContentResource";
|
@@ -152,7 +152,7 @@ var Oe = class X {
|
|
152
152
|
return typeof n > "u" && !this.options.allowUndefinedReturn ? i : n;
|
153
153
|
}, e);
|
154
154
|
}
|
155
|
-
},
|
155
|
+
}, Ue = "http://library.stanford.edu/iiif/image-api/compliance.html#level1", De = "http://library.stanford.edu/iiif/image-api/compliance.html#level2", Ee = "http://library.stanford.edu/iiif/image-api/conformance.html#level1", Ne = "http://library.stanford.edu/iiif/image-api/conformance.html#level2", qe = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", _e = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2", Ve = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1", Fe = "http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2", We = "http://iiif.io/api/image/1/level1.json", Be = "http://iiif.io/api/image/1/profiles/level1.json", He = "http://iiif.io/api/image/1/level2.json", Je = "http://iiif.io/api/image/1/profiles/level2.json", Ge = "http://iiif.io/api/image/2/level1.json", ze = "http://iiif.io/api/image/2/profiles/level1.json", Ke = "http://iiif.io/api/image/2/level2.json", Qe = "http://iiif.io/api/image/2/profiles/level2.json", Xe = "level1", Ye = "level2", Ze = "http://iiif.io/api/image/2/level1", et = "http://iiif.io/api/image/2/level2", tt = [Ze, et, Ue, De, Ee, Ne, qe, _e, Ve, Fe, We, Be, He, Je, Ge, ze, Ke, Qe, Xe, Ye], j = { attributionLabel: "Attribution", providerId: "http://example.org/provider", providerName: "Unknown" };
|
156
156
|
function rt(t) {
|
157
157
|
if (typeof t == "string") return [t];
|
158
158
|
if (!t) return [];
|
@@ -232,7 +232,7 @@ function st(t) {
|
|
232
232
|
return "AutoCompleteService1";
|
233
233
|
}
|
234
234
|
}
|
235
|
-
function
|
235
|
+
function D(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
|
}
|
@@ -281,13 +281,13 @@ function ot(t) {
|
|
281
281
|
}
|
282
282
|
function ct(t, e = "Rights/License", r = "none") {
|
283
283
|
let i = null, s = [], n = Array.isArray(t) ? t : [t];
|
284
|
-
for (let
|
285
|
-
let
|
286
|
-
if (
|
287
|
-
|
284
|
+
for (let o of n) {
|
285
|
+
let a = o ? ot(o) : void 0;
|
286
|
+
if (a && (a.indexOf("creativecommons.org") !== -1 || a.indexOf("rightsstatements.org") !== -1)) {
|
287
|
+
a.startsWith("https://") ? i = `http://${a.slice(8)}` : i = a;
|
288
288
|
continue;
|
289
289
|
}
|
290
|
-
|
290
|
+
a && s.push({ label: { [r]: [e] }, value: { [r]: [a] } });
|
291
291
|
}
|
292
292
|
return [i, s];
|
293
293
|
}
|
@@ -311,7 +311,7 @@ function d(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(
|
314
|
+
return Array.isArray(t.motivation) ? r = t.motivation.map(D) : t.motivation && (r = D(t.motivation)), { "@context": t["@context"] ? pt(t["@context"]) : void 0, id: (t["@id"] || Z(t)).trim(), type: P(t), behavior: e.length ? e : void 0, height: t.height ? t.height : void 0, width: t.width ? t.width : void 0, motivation: r, viewingDirection: t.viewingDirection, profile: t.profile, format: t.format ? t.format : void 0, duration: void 0, timeMode: void 0 };
|
315
315
|
}
|
316
316
|
function y(t) {
|
317
317
|
let [e, r] = ct(t.license), i = [...t.metadata ? vt(t.metadata) : [], ...r];
|
@@ -343,10 +343,10 @@ function mt(t) {
|
|
343
343
|
return m({ ...d(t), ...y(t), ...C(t), items: t.members });
|
344
344
|
}
|
345
345
|
function gt(t) {
|
346
|
-
let e = [], r = [], i
|
347
|
-
for (let
|
348
|
-
let
|
349
|
-
return r.length && (
|
346
|
+
let e = [], r = [], i;
|
347
|
+
for (let n of t.sequences || []) n.canvases.length && e.push(...n.canvases), n.behavior && r.push(...n.behavior), n.startCanvas && (i = n.startCanvas);
|
348
|
+
let s = d(t);
|
349
|
+
return r.length && (s.behavior ? s.behavior.push(...r) : s.behavior = r), m({ ...s, ...y(t), ...C(t), start: i, items: e, structures: dt(t.structures) });
|
350
350
|
}
|
351
351
|
function dt(t) {
|
352
352
|
if (!t) return t;
|
@@ -366,7 +366,7 @@ function At(t) {
|
|
366
366
|
return m({ ...d(t), ...y(t), ...C(t), items: t.resources && t.resources.length ? t.resources : void 0 });
|
367
367
|
}
|
368
368
|
function Ct(t) {
|
369
|
-
return !t.canvases || t.canvases.length === 0 ? { canvases: [], behavior: [] } : { canvases: t.canvases, behavior: t.viewingHint ? [t.viewingHint] : [],
|
369
|
+
return !t.canvases || t.canvases.length === 0 ? { canvases: [], behavior: [] } : { canvases: t.canvases, behavior: t.viewingHint ? [t.viewingHint] : [], startCanvas: t.startCanvas };
|
370
370
|
}
|
371
371
|
function bt(t) {
|
372
372
|
function e(r) {
|
@@ -401,8 +401,8 @@ function Lt(t) {
|
|
401
401
|
return m({ ...d(t), ...y(t), ...C(t), items: t.members });
|
402
402
|
}
|
403
403
|
function wt(t) {
|
404
|
-
let { "@id": e, "@type": r, "@context": i, profile: s, ...n } = t,
|
405
|
-
return e && (
|
404
|
+
let { "@id": e, "@type": r, "@context": i, profile: s, ...n } = t, o = {};
|
405
|
+
return e && (o["@id"] = e), o["@type"] = P(t), o["@type"] === "unknown" && (i && i.length && (o["@context"] = i), o["@type"] = "Service"), s && (o.profile = Y(s)), m({ ...o, ...n });
|
406
406
|
}
|
407
407
|
function It(t) {
|
408
408
|
return m({ ...d(t), ...y(t), ...C(t) });
|
@@ -518,8 +518,8 @@ var O = class re {
|
|
518
518
|
}
|
519
519
|
traverseType(e, r, i) {
|
520
520
|
return i.reduce((s, n) => {
|
521
|
-
let
|
522
|
-
return typeof
|
521
|
+
let o = n(s, r);
|
522
|
+
return typeof o > "u" && !this.options.allowUndefinedReturn ? s : o;
|
523
523
|
}, e);
|
524
524
|
}
|
525
525
|
traverseService(e, r) {
|
@@ -556,16 +556,16 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
556
556
|
const e = f(t, "type"), r = f(t, "context");
|
557
557
|
if (e === "ImageService2" || r != null && r.includes("image/2")) {
|
558
558
|
const i = t, s = ["level0", "level1", "level2"];
|
559
|
-
return { majorVersion: 2, profileLevel: (Array.isArray(i.profile) ? i.profile : [i.profile]).map((
|
559
|
+
return { majorVersion: 2, profileLevel: (Array.isArray(i.profile) ? i.profile : [i.profile]).map((a) => s.findIndex((c) => a.toString().includes(c))).filter((a) => a > -1).sort((a, c) => c - a)[0] };
|
560
560
|
} else if (e || r)
|
561
561
|
return { majorVersion: 3, profileLevel: parseInt(t.profile) };
|
562
562
|
}, _ = (t, e, r) => {
|
563
563
|
const i = f(t, "id"), s = t.profile || "";
|
564
564
|
if (typeof s == "string" && (s.includes("level0") || s.includes("level:0"))) {
|
565
565
|
if ("sizes" in t && Array.isArray(t.sizes)) {
|
566
|
-
const
|
567
|
-
if (
|
568
|
-
return `${i}/full/${
|
566
|
+
const o = t.sizes.sort((a, c) => c.width * c.height - a.width * a.height).filter((a) => a.width * a.height >= e * r)[0];
|
567
|
+
if (o)
|
568
|
+
return `${i}/full/${o.width},${o.height}/0/default.jpg`;
|
569
569
|
}
|
570
570
|
return `${i}/full/full/0/default.jpg`;
|
571
571
|
}
|
@@ -573,46 +573,46 @@ 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:
|
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
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:
|
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;
|
585
|
-
const n = i / s,
|
585
|
+
const n = i / s, o = n < 1, a = Math.ceil(o ? r / n : r), c = Math.ceil(o ? r : r / n);
|
586
586
|
if (t.thumbnail && t.thumbnail.length > 0) {
|
587
587
|
const h = t.thumbnail[0];
|
588
588
|
if ("service" in h && Array.isArray(h.service)) {
|
589
589
|
const p = h.service.find((u) => ie(u));
|
590
590
|
if (p)
|
591
|
-
return _(p, c,
|
591
|
+
return _(p, c, a);
|
592
592
|
}
|
593
593
|
if ("id" in h) return h.id;
|
594
594
|
}
|
595
595
|
for (const h of e) {
|
596
596
|
if (h.type === "dynamic" || h.type === "level0")
|
597
|
-
return _(h.service, c,
|
597
|
+
return _(h.service, c, a);
|
598
598
|
if (h.type === "static")
|
599
599
|
return h.url;
|
600
600
|
}
|
601
601
|
}, ne = (t) => t.endsWith("/info.json") ? t : `${t.endsWith("/") ? t : `${t}/`}info.json`, jt = (t) => {
|
602
|
-
const { format: e, height: r, width: i } = t, s = f(t, "id"), n = (t.service || []).find(ie),
|
603
|
-
if (
|
604
|
-
const
|
602
|
+
const { format: e, height: r, width: i } = t, s = f(t, "id"), n = (t.service || []).find(ie), o = n ? se(n) : void 0;
|
603
|
+
if (o) {
|
604
|
+
const a = {
|
605
605
|
source: t,
|
606
|
-
type:
|
606
|
+
type: o.profileLevel === 0 ? "level0" : "dynamic",
|
607
607
|
service: n,
|
608
608
|
width: i,
|
609
609
|
height: r,
|
610
|
-
majorVersion:
|
610
|
+
majorVersion: o.majorVersion,
|
611
611
|
serviceUrl: ne(f(n, "id"))
|
612
612
|
};
|
613
|
-
return
|
614
|
-
...
|
615
|
-
getRegionURL: $t(
|
613
|
+
return o.profileLevel === 0 ? a : {
|
614
|
+
...a,
|
615
|
+
getRegionURL: $t(a)
|
616
616
|
};
|
617
617
|
} else
|
618
618
|
return {
|
@@ -628,25 +628,25 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
628
628
|
return new O({
|
629
629
|
annotation: [(i) => {
|
630
630
|
if (i.motivation === "painting" || !i.motivation) {
|
631
|
-
const n = (i.body ? Array.isArray(i.body) ? i.body : [i.body] : []).filter((
|
632
|
-
e.push(...n.map((
|
631
|
+
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)));
|
633
633
|
}
|
634
634
|
}]
|
635
635
|
}).traverseCanvas(t), e;
|
636
636
|
}, Pt = (t) => () => {
|
637
|
-
const e = /* @__PURE__ */ new Map(), r = (
|
637
|
+
const e = /* @__PURE__ */ new Map(), r = (a, c, h = 0) => {
|
638
638
|
const p = {
|
639
|
-
id:
|
639
|
+
id: a.id,
|
640
640
|
type: "range",
|
641
|
-
source:
|
641
|
+
source: a,
|
642
642
|
children: [],
|
643
643
|
navItems: [],
|
644
644
|
navSections: [],
|
645
645
|
parent: c,
|
646
646
|
level: h,
|
647
|
-
getLabel:
|
647
|
+
getLabel: a.getLabel
|
648
648
|
};
|
649
|
-
|
649
|
+
a.items && a.items.length > 0 && a.items.forEach((v) => {
|
650
650
|
if (v.source.type === "Range") {
|
651
651
|
const S = r(v, p, h + 1);
|
652
652
|
p.children.push(S);
|
@@ -668,15 +668,15 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
668
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
669
|
return p.navItems.push(...w), p.navSections.push(...l), e.set(p.id, p), p;
|
670
670
|
};
|
671
|
-
return { root: t.filter((
|
671
|
+
return { root: t.filter((a) => {
|
672
672
|
var c;
|
673
|
-
return (c =
|
674
|
-
}).map((
|
675
|
-
const c = e.get(
|
673
|
+
return (c = a.source.behavior) == null ? void 0 : c.includes("top");
|
674
|
+
}).map((a) => r(a, void 0)), getBreadcrumbs: (a) => {
|
675
|
+
const c = e.get(a);
|
676
676
|
if (!c) return [];
|
677
677
|
const h = (p, u = []) => p.parent ? h(p.parent, [p, ...u]) : [p, ...u];
|
678
678
|
return h(c);
|
679
|
-
}, getNode: (
|
679
|
+
}, getNode: (a) => e.get(a) };
|
680
680
|
}, Ot = async (t) => {
|
681
681
|
try {
|
682
682
|
new URL(t);
|
@@ -743,11 +743,11 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
743
743
|
return f(t, "type").includes("Collection") ? {
|
744
744
|
type: "collection",
|
745
745
|
url: e || i,
|
746
|
-
resource:
|
746
|
+
resource: Ut(t, s)
|
747
747
|
} : {
|
748
748
|
type: "manifest",
|
749
749
|
url: e || i,
|
750
|
-
resource:
|
750
|
+
resource: Dt(t, s)
|
751
751
|
};
|
752
752
|
}
|
753
753
|
if (r.includes("image/2") || r.includes("image/3")) {
|
@@ -767,12 +767,12 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
767
767
|
code: "INVALID_MANIFEST",
|
768
768
|
message: "JSON resource is not a recognized IIIF format"
|
769
769
|
};
|
770
|
-
},
|
770
|
+
}, Ut = (t, e) => {
|
771
771
|
const r = (n) => {
|
772
|
-
const
|
772
|
+
const o = [];
|
773
773
|
return new O({
|
774
|
-
manifest: [(c) =>
|
775
|
-
}).traverseCollection(n),
|
774
|
+
manifest: [(c) => o.push(c)]
|
775
|
+
}).traverseCollection(n), o.map((c) => ({
|
776
776
|
id: c.id,
|
777
777
|
type: c.type,
|
778
778
|
getLabel: I(c),
|
@@ -787,18 +787,18 @@ const ie = (t) => f(t, "type").startsWith("ImageService") || t.profile && t.prof
|
|
787
787
|
getLabel: I(i),
|
788
788
|
getMetadata: M(i)
|
789
789
|
};
|
790
|
-
},
|
791
|
-
const r = (
|
792
|
-
const
|
790
|
+
}, Dt = (t, e) => {
|
791
|
+
const r = (o) => {
|
792
|
+
const a = [], c = [];
|
793
793
|
new O({
|
794
794
|
canvas: [(l) => {
|
795
|
-
l.items &&
|
795
|
+
l.items && a.push(l);
|
796
796
|
}],
|
797
797
|
range: [(l) => {
|
798
798
|
l.type === "Range" && c.push(l);
|
799
799
|
}]
|
800
|
-
}).traverseManifest(
|
801
|
-
const p =
|
800
|
+
}).traverseManifest(o);
|
801
|
+
const p = a.map((l) => {
|
802
802
|
const v = kt(l);
|
803
803
|
return {
|
804
804
|
source: l,
|
package/dist/level-0/index.js
CHANGED
@@ -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:
|
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
|
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)),
|
32
|
+
v(h.apply(this, u)), n.delete(f);
|
33
33
|
}, p = g();
|
34
|
-
p > 0 ? (f = setTimeout(y, p),
|
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
|
38
|
-
clearTimeout(u),
|
39
|
-
|
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
|
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: (
|
57
|
-
t = { ...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) &&
|
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((
|
72
|
+
return { loadImage: x.getInstance()((i) => new Promise((r, n) => {
|
73
73
|
const o = new Image();
|
74
|
-
o.crossOrigin = "anonymous", o.onload = () =>
|
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:
|
78
|
-
return `${t.id}/${c * o},${i * a},${
|
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,
|
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 >=
|
83
|
+
if (h * c >= r || g * i >= n)
|
84
84
|
continue;
|
85
|
-
const w = Math.min(c,
|
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),
|
97
|
-
if (!
|
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
|
-
|
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
|
-
|
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
|
-
|
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,
|
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 <=
|
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),
|
141
|
+
let i = Math.ceil(t.width / c), r = Math.ceil(t.height / c);
|
142
142
|
if (e) {
|
143
|
-
const
|
144
|
-
e.width && i < e.width && (i = e.width,
|
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:
|
146
|
+
return { width: i, height: r };
|
147
147
|
}, k = (t, e) => {
|
148
|
-
const c = I(t, e), i = t.tiles[0].width,
|
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 <
|
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
|
-
|
156
|
-
(t.height - l *
|
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 *
|
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 *
|
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),
|
169
|
-
|
170
|
-
const o =
|
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
|
-
|
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.
|
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",
|
@@ -33,7 +33,7 @@
|
|
33
33
|
"vitest": "^3.1.4"
|
34
34
|
},
|
35
35
|
"dependencies": {
|
36
|
-
"@iiif/parser": "
|
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"
|
package/src/core/canvas.ts
CHANGED
@@ -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
|
-
|
104
|
-
console.error('Level 0 or static image canvas: unspported');
|
103
|
+
console.error('Level 0 or static image canvas: unsupported');
|
105
104
|
}
|
106
105
|
}
|
@@ -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
|
}
|