cozy-iiif 0.1.0 → 0.1.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.
- package/README.md +3 -1
- package/dist/core/canvas.d.ts +1 -1
- package/dist/core/image-service.d.ts +2 -2
- package/dist/core/resource.d.ts +2 -2
- package/dist/index.js +773 -17
- package/dist/level-0/fetch-image-info.d.ts +3 -0
- package/dist/level-0/index.js +184 -4
- package/dist/{src/core/resource.js → resource-DS2brz47.js} +7 -7
- package/dist/types.d.ts +1 -1
- package/package.json +3 -3
- package/src/Cozy.ts +2 -2
- package/src/core/canvas.ts +4 -3
- package/src/core/image-service.ts +7 -4
- package/src/core/resource.ts +4 -4
- package/src/level-0/crop-region.ts +6 -5
- package/src/level-0/fetch-image-info.ts +11 -0
- package/src/level-0/get-thumbnail.ts +5 -4
- package/src/types.ts +1 -1
- package/tsconfig.json +7 -8
- package/vite.config.ts +0 -5
- package/dist/src/Cozy.js +0 -133
- package/dist/src/core/canvas.js +0 -63
- package/dist/src/core/image-service.js +0 -36
- package/dist/src/level-0/crop-region.js +0 -59
- package/dist/src/level-0/get-thumbnail.js +0 -57
- package/dist/src/level-0/throttled-loader.js +0 -33
@@ -1,36 +0,0 @@
|
|
1
|
-
import { getPropertyValue as c } from "./resource.js";
|
2
|
-
const m = (e) => c(e, "type").startsWith("ImageService"), y = (e) => {
|
3
|
-
const i = c(e, "type"), t = c(e, "context");
|
4
|
-
if (i === "ImageService2" || t != null && t.includes("image/2")) {
|
5
|
-
const l = e, o = ["level0", "level1", "level2"];
|
6
|
-
return { majorVersion: 2, profileLevel: (Array.isArray(l.profile) ? l.profile : [l.profile]).map((r) => o.findIndex((s) => r.toString().includes(s))).filter((r) => r > -1).sort((r, s) => s - r)[0] };
|
7
|
-
} else if (i || t)
|
8
|
-
return { majorVersion: 3, profileLevel: parseInt(e.profile) };
|
9
|
-
}, L = (e, i, t) => {
|
10
|
-
const l = c(e, "id"), o = e.profile || "";
|
11
|
-
if (typeof o == "string" && (o.includes("level0") || o.includes("level:0"))) {
|
12
|
-
if ("sizes" in e && Array.isArray(e.sizes)) {
|
13
|
-
const n = e.sizes.sort((r, s) => s.width * s.height - r.width * r.height).filter((r) => r.width * r.height >= i * t)[0];
|
14
|
-
if (n)
|
15
|
-
return `${l}/full/${n.width},${n.height}/0/default.jpg`;
|
16
|
-
}
|
17
|
-
return `${l}/full/full/0/default.jpg`;
|
18
|
-
}
|
19
|
-
return `${l}/full/!${i},${t}/0/default.jpg`;
|
20
|
-
}, v = (e, i, t) => {
|
21
|
-
const l = c(e, "id"), o = e.profile || "";
|
22
|
-
if (typeof o == "string" && (o.includes("level0") || o.includes("level:0"))) return;
|
23
|
-
const { x: n, y: r, w: s, h: p } = i, a = s / p, u = a < 1, d = Math.ceil(u ? t / a : t), g = Math.ceil(u ? t : t / a), h = `${Math.round(n)},${Math.round(r)},${Math.round(s)},${Math.round(p)}`;
|
24
|
-
return `${l}/${h}/!${g},${d}/0/default.jpg`;
|
25
|
-
}, I = (e) => (i, t = 400) => {
|
26
|
-
if (e.type === "dynamic")
|
27
|
-
return v(e.service, i, t);
|
28
|
-
console.error("Level 0 or static image canvas: unspported");
|
29
|
-
};
|
30
|
-
export {
|
31
|
-
L as getImageURLFromService,
|
32
|
-
I as getRegionURL,
|
33
|
-
v as getRegionURLFromService,
|
34
|
-
m as isImageService,
|
35
|
-
y as parseImageService
|
36
|
-
};
|
@@ -1,59 +0,0 @@
|
|
1
|
-
import { getThrottledLoader as v } from "./throttled-loader.js";
|
2
|
-
const y = (e, t) => {
|
3
|
-
const { x: i, y: r, w: a, h: n } = t, o = e.tiles[0].width, s = e.tiles[0].height || e.tiles[0].width;
|
4
|
-
return `${e["@id"]}/${i * o},${r * s},${a},${n}/${o},/0/default.jpg`;
|
5
|
-
}, f = (e, t) => {
|
6
|
-
const i = e.tiles[0].width, r = e.tiles[0].height || e.tiles[0].width, a = e.width, n = e.height, o = Math.floor(t.x / i), s = Math.floor(t.y / r), d = Math.ceil((t.x + t.w) / i), x = Math.ceil((t.y + t.h) / r), w = [];
|
7
|
-
for (let c = s; c < x; c++)
|
8
|
-
for (let l = o; l < d; l++) {
|
9
|
-
if (l * i >= a || c * r >= n)
|
10
|
-
continue;
|
11
|
-
const h = Math.min(i, a - l * i), g = Math.min(r, n - c * r);
|
12
|
-
w.push({
|
13
|
-
x: l,
|
14
|
-
y: c,
|
15
|
-
width: h,
|
16
|
-
height: g,
|
17
|
-
url: y(e, { x: l, y: c, w: h, h: g })
|
18
|
-
});
|
19
|
-
}
|
20
|
-
return w;
|
21
|
-
}, E = async (e, t) => {
|
22
|
-
const i = await fetch(e.serviceUrl).then((h) => h.json()), r = f(i, t), a = document.createElement("canvas"), n = a.getContext("2d");
|
23
|
-
if (!n)
|
24
|
-
throw new Error("Error initializing canvas context");
|
25
|
-
const o = i.tiles[0].width, s = i.tiles[0].height || i.tiles[0].width, d = (Math.ceil(t.w / o) + 1) * o, x = (Math.ceil(t.h / s) + 1) * s;
|
26
|
-
a.width = d, a.height = x;
|
27
|
-
const w = v({ callsPerSecond: 20 });
|
28
|
-
await Promise.all(r.map(async (h) => {
|
29
|
-
const g = await w.loadImage(h.url), m = h.x * o - t.x, p = h.y * s - t.y;
|
30
|
-
n.drawImage(g, m, p);
|
31
|
-
}));
|
32
|
-
const c = document.createElement("canvas");
|
33
|
-
c.width = t.w, c.height = t.h;
|
34
|
-
const l = c.getContext("2d");
|
35
|
-
if (!l)
|
36
|
-
throw new Error("Error initializing canvas context");
|
37
|
-
return l.drawImage(
|
38
|
-
a,
|
39
|
-
0,
|
40
|
-
0,
|
41
|
-
t.w,
|
42
|
-
t.h,
|
43
|
-
0,
|
44
|
-
0,
|
45
|
-
t.w,
|
46
|
-
t.h
|
47
|
-
), new Promise((h, g) => {
|
48
|
-
c.toBlob(
|
49
|
-
(m) => {
|
50
|
-
m ? h(m) : g(new Error("Failed to create blob"));
|
51
|
-
},
|
52
|
-
"image/jpeg",
|
53
|
-
0.95
|
54
|
-
);
|
55
|
-
});
|
56
|
-
};
|
57
|
-
export {
|
58
|
-
E as cropRegion
|
59
|
-
};
|
@@ -1,57 +0,0 @@
|
|
1
|
-
import { getThrottledLoader as w } from "./throttled-loader.js";
|
2
|
-
const d = (t, h) => {
|
3
|
-
const e = t.tiles[0].scaleFactors.sort((o, n) => n - o);
|
4
|
-
if (!h)
|
5
|
-
return e[0];
|
6
|
-
const a = h.width ? t.width / h.width : 1 / 0, c = h.height ? t.height / h.height : 1 / 0, i = Math.min(a, c);
|
7
|
-
for (const o of e)
|
8
|
-
if (o <= i)
|
9
|
-
return o;
|
10
|
-
return e[e.length - 1];
|
11
|
-
}, u = (t, h) => {
|
12
|
-
const e = d(t, h);
|
13
|
-
let a = Math.ceil(t.width / e), c = Math.ceil(t.height / e);
|
14
|
-
if (h) {
|
15
|
-
const i = t.width / t.height;
|
16
|
-
h.width && a < h.width && (a = h.width, c = Math.ceil(a / i)), h.height && c < h.height && (c = h.height, a = Math.ceil(c * i));
|
17
|
-
}
|
18
|
-
return { width: a, height: c };
|
19
|
-
}, M = (t, h) => {
|
20
|
-
const e = d(t, h), a = t.tiles[0].width, c = t.tiles[0].height || t.tiles[0].width, i = Math.ceil(t.width / (a * e)), o = Math.ceil(t.height / (c * e)), n = [];
|
21
|
-
for (let s = 0; s < o; s++)
|
22
|
-
for (let r = 0; r < i; r++) {
|
23
|
-
const l = Math.min(
|
24
|
-
a,
|
25
|
-
(t.width - r * a * e) / e
|
26
|
-
), g = Math.min(
|
27
|
-
c,
|
28
|
-
(t.height - s * c * e) / e
|
29
|
-
);
|
30
|
-
l <= 0 || g <= 0 || n.push({
|
31
|
-
url: `${t["@id"]}/${r * a * e},${s * c * e},${l * e},${g * e}/${Math.ceil(l)},/0/default.jpg`,
|
32
|
-
width: Math.ceil(l),
|
33
|
-
height: Math.ceil(g),
|
34
|
-
x: r * a,
|
35
|
-
y: s * c
|
36
|
-
});
|
37
|
-
}
|
38
|
-
return n;
|
39
|
-
}, p = async (t, h) => {
|
40
|
-
const e = await fetch(t.serviceUrl).then((s) => s.json()), a = M(e, h), c = u(e, h), i = document.createElement("canvas");
|
41
|
-
i.width = c.width, i.height = c.height;
|
42
|
-
const o = i.getContext("2d");
|
43
|
-
if (!o)
|
44
|
-
throw new Error("Error creating canvas context");
|
45
|
-
const n = w();
|
46
|
-
return await Promise.all(a.map(async (s) => {
|
47
|
-
const r = await n.loadImage(s.url);
|
48
|
-
o.drawImage(r, s.x, s.y);
|
49
|
-
})), new Promise((s, r) => {
|
50
|
-
i.toBlob((l) => {
|
51
|
-
l ? s(l) : r(new Error("Failed to create blob"));
|
52
|
-
}, "image/jpeg", 0.85);
|
53
|
-
});
|
54
|
-
};
|
55
|
-
export {
|
56
|
-
p as getThumbnail
|
57
|
-
};
|
@@ -1,33 +0,0 @@
|
|
1
|
-
import a from "../../node_modules/p-throttle/index.js";
|
2
|
-
const g = () => {
|
3
|
-
let t = {
|
4
|
-
limit: 5,
|
5
|
-
interval: 1e3
|
6
|
-
}, e = a(t);
|
7
|
-
return {
|
8
|
-
getInstance: () => e,
|
9
|
-
getConfig: () => ({ ...t }),
|
10
|
-
setConfig: (r) => {
|
11
|
-
t = { ...t, ...r }, e = a(t);
|
12
|
-
}
|
13
|
-
};
|
14
|
-
}, i = g(), s = (t) => {
|
15
|
-
if (!t) return;
|
16
|
-
const e = i.getConfig();
|
17
|
-
(t.limit && t.limit !== e.limit || t.interval && t.interval !== e.interval) && (console.log("updating throttle config!"), i.setConfig({ ...e, ...t }));
|
18
|
-
}, m = (t) => {
|
19
|
-
if (t) {
|
20
|
-
const o = {
|
21
|
-
limit: t.callsPerSecond || 5,
|
22
|
-
interval: 1e3
|
23
|
-
};
|
24
|
-
s(o);
|
25
|
-
}
|
26
|
-
return { loadImage: i.getInstance()((o) => new Promise((l, r) => {
|
27
|
-
const n = new Image();
|
28
|
-
n.crossOrigin = "anonymous", n.onload = () => l(n), n.onerror = r, n.src = o;
|
29
|
-
})) };
|
30
|
-
};
|
31
|
-
export {
|
32
|
-
m as getThrottledLoader
|
33
|
-
};
|