cozy-iiif 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Rainer Simon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # cozy-iiif
2
+
3
+ **WORK IN PROGRESS**
4
+
5
+ A developer-friendly collection of abstractions and utilities built on top of the IIIF Commons [@iiif/presentation-3](https://github.com/IIIF-Commons/presentation-3-types) and [@iiif/parser](https://github.com/IIIF-Commons/parser) libraries.
6
+
7
+ ## Features
8
+
9
+ - Resource identification for any URL: IIIF manifests, manifest, image services, static image, and more.
10
+ - Developer-friendly TypeScript API for parsing and working with IIIF resources.
11
+ - Seamless upgrade from IIIF Presentation API v2 to v3 using `@iiif/parser/`.
12
+ - Preserves access to underlying `@iiif-presentation/3` types.
13
+ - Provides helpers for stitching thumbnails and cropping regions from IIIF Level 0 tilesets.
14
+
15
+ ## Installation
16
+
17
+ Todo...
18
+
19
+ ## Basic Usage
20
+
21
+ Todo...
22
+
23
+ ## API
24
+
25
+ Todo...
26
+
27
+ ## License
28
+
29
+ MIT License - see the [LICENSE](LICENSE) file for details.
package/dist/Cozy.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { CozyParseResult } from './types';
2
+ export declare const Cozy: {
3
+ parseURL: (input: string) => Promise<CozyParseResult>;
4
+ };
@@ -0,0 +1,5 @@
1
+ import { Canvas } from '@iiif/presentation-3';
2
+ import { CozyImageResource } from '../types';
3
+ export declare const getThumbnailURL: (canvas: Canvas, images?: CozyImageResource[]) => (minSize?: number) => string;
4
+ export declare const normalizeServiceUrl: (url: string) => string;
5
+ export declare const getImages: (canvas: Canvas) => CozyImageResource[];
@@ -0,0 +1,12 @@
1
+ import { ImageService2, ImageService3, Service } from '@iiif/presentation-3';
2
+ import { Bounds, CozyImageResource } from '../types';
3
+ type ImageService = ImageService2 | ImageService3;
4
+ export declare const isImageService: (data: any) => data is ImageService;
5
+ export declare const parseImageService: (service: Service) => {
6
+ majorVersion: number;
7
+ profileLevel: number;
8
+ };
9
+ export declare const getImageURLFromService: (service: ImageService2 | ImageService3, width: number, height: number) => string;
10
+ export declare const getRegionURLFromService: (service: ImageService2 | ImageService3, bounds: Bounds, minSize: number) => string;
11
+ export declare const getRegionURL: (image: CozyImageResource) => (bounds: Bounds, minSize?: number) => string | undefined;
12
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from './canvas';
2
+ export * from './image-service';
3
+ export * from './resource';
@@ -0,0 +1,6 @@
1
+ import { InternationalString } from '@iiif/presentation-3';
2
+ import { CozyMetadata } from '../types';
3
+ export declare const getPropertyValue: <T extends unknown = any>(data: any, name: string) => T;
4
+ export declare const getStringValue: (propertyValue: string | InternationalString, locale?: string) => string;
5
+ export declare const getLabel: (data: any) => (locale?: string) => string;
6
+ export declare const getMetadata: (data: any) => (locale?: string) => CozyMetadata[];
@@ -0,0 +1,3 @@
1
+ export * from './core';
2
+ export * from './types';
3
+ export * from './Cozy';
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ import { getImages as t, getThumbnailURL as g, normalizeServiceUrl as o } from "./src/core/canvas.js";
2
+ import { getImageURLFromService as m, getRegionURL as i, getRegionURLFromService as l, isImageService as p, parseImageService as R } from "./src/core/image-service.js";
3
+ import { getLabel as c, getMetadata as n, getPropertyValue as v, getStringValue as L } from "./src/core/resource.js";
4
+ import { Cozy as f } from "./src/Cozy.js";
5
+ export {
6
+ f as Cozy,
7
+ m as getImageURLFromService,
8
+ t as getImages,
9
+ c as getLabel,
10
+ n as getMetadata,
11
+ v as getPropertyValue,
12
+ i as getRegionURL,
13
+ l as getRegionURLFromService,
14
+ L as getStringValue,
15
+ g as getThumbnailURL,
16
+ p as isImageService,
17
+ o as normalizeServiceUrl,
18
+ R as parseImageService
19
+ };
@@ -0,0 +1,2 @@
1
+ import { Bounds, Level0ImageServiceResource } from '../types';
2
+ export declare const cropRegion: (resource: Level0ImageServiceResource, bounds: Bounds) => Promise<Blob>;
@@ -0,0 +1,3 @@
1
+ import { Level0ImageServiceResource } from '../types';
2
+ import { Size } from './types';
3
+ export declare const getThumbnail: (resource: Level0ImageServiceResource, minSize?: Partial<Size>) => Promise<Blob>;
@@ -0,0 +1,2 @@
1
+ export * from './crop-region';
2
+ export * from './get-thumbnail';
@@ -0,0 +1,6 @@
1
+ import { cropRegion as e } from "../src/level-0/crop-region.js";
2
+ import { getThumbnail as p } from "../src/level-0/get-thumbnail.js";
3
+ export {
4
+ e as cropRegion,
5
+ p as getThumbnail
6
+ };
@@ -0,0 +1,7 @@
1
+ interface ThrottledLoaderOpts {
2
+ callsPerSecond?: number;
3
+ }
4
+ export declare const getThrottledLoader: (opts?: ThrottledLoaderOpts) => {
5
+ loadImage: import('p-throttle').ThrottledFunction<(url: string) => Promise<HTMLImageElement>>;
6
+ };
7
+ export {};
@@ -0,0 +1,22 @@
1
+ export interface ImageInfo {
2
+ id: string;
3
+ width: number;
4
+ height: number;
5
+ tiles: TileInfo[];
6
+ }
7
+ export type Size = {
8
+ width: number;
9
+ height: number;
10
+ };
11
+ export interface TileInfo {
12
+ width: number;
13
+ height?: number;
14
+ scaleFactors: number[];
15
+ }
16
+ export interface Tile {
17
+ x: number;
18
+ y: number;
19
+ width: number;
20
+ height: number;
21
+ url: string;
22
+ }
@@ -0,0 +1,133 @@
1
+ import { h as u } from "../node_modules/@iiif/parser/dist/chunk-BMMVY4QT.js";
2
+ import { d as l } from "../node_modules/@iiif/parser/dist/chunk-W3DWL6UZ.js";
3
+ import { normalizeServiceUrl as p, getImages as f, getThumbnailURL as I } from "./core/canvas.js";
4
+ import { parseImageService as h } from "./core/image-service.js";
5
+ import { getPropertyValue as g, getMetadata as d, getLabel as m } from "./core/resource.js";
6
+ const S = {
7
+ parseURL: async (r) => {
8
+ try {
9
+ new URL(r);
10
+ } catch {
11
+ return {
12
+ type: "error",
13
+ code: "INVALID_URL",
14
+ message: "The provided input is not a valid URL"
15
+ };
16
+ }
17
+ let t;
18
+ try {
19
+ if (t = await fetch(r), !t.ok)
20
+ return {
21
+ type: "error",
22
+ code: "INVALID_HTTP_RESPONSE",
23
+ message: `Server responded: HTTP ${t.status} ${t.statusText ? `(${t.statusText})` : ""}`
24
+ };
25
+ } catch (e) {
26
+ return {
27
+ type: "error",
28
+ code: "FETCH_ERROR",
29
+ message: e instanceof Error ? e.message : "Failed to fetch resource"
30
+ };
31
+ }
32
+ const i = t.headers.get("content-type");
33
+ if (i != null && i.startsWith("image/"))
34
+ return {
35
+ type: "plain-image",
36
+ url: r
37
+ };
38
+ if (i != null && i.includes("text/html"))
39
+ return {
40
+ type: "webpage",
41
+ url: r
42
+ };
43
+ try {
44
+ const e = await t.json(), a = Array.isArray(e["@context"]) ? e["@context"].find((o) => o.includes("iiif.io/api/")) : e["@context"];
45
+ if (!a)
46
+ return {
47
+ type: "error",
48
+ code: "INVALID_MANIFEST",
49
+ message: "Missing @context"
50
+ };
51
+ if (!g(e, "id"))
52
+ return {
53
+ type: "error",
54
+ code: "INVALID_MANIFEST",
55
+ message: "Missing id property"
56
+ };
57
+ if (a.includes("presentation/2") || a.includes("presentation/3")) {
58
+ const o = a.includes("presentation/2") ? 2 : 3;
59
+ return {
60
+ type: "manifest",
61
+ url: r,
62
+ resource: y(e, o)
63
+ };
64
+ }
65
+ if (a.includes("image/2") || a.includes("image/3")) {
66
+ const o = v(e);
67
+ return o ? {
68
+ type: "iiif-image",
69
+ url: r,
70
+ resource: o
71
+ } : {
72
+ type: "error",
73
+ code: "INVALID_MANIFEST",
74
+ message: "Invalid image service definition"
75
+ };
76
+ }
77
+ return {
78
+ type: "error",
79
+ code: "INVALID_MANIFEST",
80
+ message: "JSON resource is not a recognized IIIF format"
81
+ };
82
+ } catch {
83
+ return {
84
+ type: "error",
85
+ code: "UNSUPPORTED_FORMAT",
86
+ message: "Could not parse resource"
87
+ };
88
+ }
89
+ }
90
+ }, y = (r, t) => {
91
+ const i = (n) => {
92
+ const o = [];
93
+ return new l({
94
+ canvas: [(s) => {
95
+ s.items && o.push(s);
96
+ }]
97
+ }).traverseManifest(n), o.map((s) => {
98
+ const c = f(s);
99
+ return {
100
+ source: s,
101
+ id: s.id,
102
+ width: s.width,
103
+ height: s.height,
104
+ images: c,
105
+ getLabel: m(s),
106
+ getMetadata: d(s),
107
+ getThumbnailURL: I(s, c)
108
+ };
109
+ });
110
+ }, e = t === 2 ? u(r) : r, a = i(e);
111
+ return {
112
+ source: e,
113
+ id: e.id,
114
+ majorVersion: t,
115
+ canvases: a,
116
+ getLabel: m(e),
117
+ getMetadata: d(e)
118
+ };
119
+ }, v = (r) => {
120
+ const { width: t, height: i } = r, e = h(r);
121
+ if (e)
122
+ return {
123
+ type: e.profileLevel === 0 ? "level0" : "dynamic",
124
+ service: r,
125
+ width: t,
126
+ height: i,
127
+ majorVersion: e.majorVersion,
128
+ serviceUrl: p(g(r, "id"))
129
+ };
130
+ };
131
+ export {
132
+ S as Cozy
133
+ };
@@ -0,0 +1,63 @@
1
+ import { d as h } from "../../node_modules/@iiif/parser/dist/chunk-W3DWL6UZ.js";
2
+ import { getPropertyValue as d } from "./resource.js";
3
+ import { isImageService as g, getImageURLFromService as f, parseImageService as p, getRegionURL as y } from "./image-service.js";
4
+ const U = (e, n = []) => (s = 400) => {
5
+ const { width: i, height: a } = e;
6
+ if (!i || !a) return;
7
+ const r = i / a, o = r < 1, c = Math.ceil(o ? s / r : s), m = Math.ceil(o ? s : s / r);
8
+ if (e.thumbnail && e.thumbnail.length > 0) {
9
+ const t = e.thumbnail[0];
10
+ if ("service" in t && Array.isArray(t.service)) {
11
+ const l = t.service.find((v) => g(v));
12
+ if (l)
13
+ return f(l, m, c);
14
+ }
15
+ if ("id" in t) return t.id;
16
+ }
17
+ for (const t of n) {
18
+ if (t.type === "dynamic" || t.type === "level0")
19
+ return f(t.service, m, c);
20
+ if (t.type === "static")
21
+ return t.url;
22
+ }
23
+ }, u = (e) => e.endsWith("/info.json") ? e : `${e.endsWith("/") ? e : `${e}/`}info.json`, b = (e) => {
24
+ const { format: n, height: s, width: i } = e, a = d(e, "id"), r = (e.service || []).find(g), o = r ? p(r) : void 0;
25
+ if (o) {
26
+ const c = {
27
+ source: e,
28
+ type: o.profileLevel === 0 ? "level0" : "dynamic",
29
+ service: r,
30
+ width: i,
31
+ height: s,
32
+ majorVersion: o.majorVersion,
33
+ serviceUrl: u(d(r, "id"))
34
+ };
35
+ return o.profileLevel === 0 ? c : {
36
+ ...c,
37
+ getRegionURL: y(c)
38
+ };
39
+ } else
40
+ return {
41
+ source: e,
42
+ type: "static",
43
+ width: i,
44
+ height: s,
45
+ url: a,
46
+ format: n
47
+ };
48
+ }, j = (e) => {
49
+ const n = [];
50
+ return new h({
51
+ annotation: [(i) => {
52
+ if (i.motivation === "painting") {
53
+ const r = (i.body ? Array.isArray(i.body) ? i.body : [i.body] : []).filter((o) => o.type === "Image");
54
+ n.push(...r.map(b));
55
+ }
56
+ }]
57
+ }).traverseCanvas(e), n;
58
+ };
59
+ export {
60
+ j as getImages,
61
+ U as getThumbnailURL,
62
+ u as normalizeServiceUrl
63
+ };
@@ -0,0 +1,36 @@
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
+ };
@@ -0,0 +1,28 @@
1
+ const c = (e, r) => {
2
+ let t = e[r];
3
+ return t || (t = e[`@${r}`]), t;
4
+ }, o = (e, r = "en") => {
5
+ if (typeof e == "string") return e;
6
+ const t = e[r];
7
+ if (t)
8
+ return t[0];
9
+ {
10
+ const n = Object.values(e).reduce((s, a) => Array.isArray(a) ? [...s, ...a] : [...s, a], []);
11
+ return n.length > 0 ? n[0] : void 0;
12
+ }
13
+ }, i = (e) => (r = "en") => {
14
+ const t = c(e, "label");
15
+ return t ? o(t, r) : void 0;
16
+ }, u = (e) => (r) => {
17
+ const t = c(e, "metadata");
18
+ return t ? t.map(({ label: n, value: s }) => ({
19
+ label: o(n, r),
20
+ value: o(s, r)
21
+ })) : [];
22
+ };
23
+ export {
24
+ i as getLabel,
25
+ u as getMetadata,
26
+ c as getPropertyValue,
27
+ o as getStringValue
28
+ };
@@ -0,0 +1,59 @@
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
+ };
@@ -0,0 +1,57 @@
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
+ };
@@ -0,0 +1,33 @@
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
+ };
@@ -0,0 +1,86 @@
1
+ import { Manifest, Canvas, ImageService2, ImageService3, IIIFExternalWebResource } from '@iiif/presentation-3';
2
+ export type CozyParseResult = {
3
+ type: 'manifest';
4
+ url: string;
5
+ resource: CozyManifest;
6
+ } | {
7
+ type: 'iiif-image';
8
+ url: string;
9
+ resource: CozyImageResource;
10
+ } | {
11
+ type: 'plain-image';
12
+ url: string;
13
+ } | {
14
+ type: 'webpage';
15
+ url: string;
16
+ } | {
17
+ type: 'error';
18
+ code: 'INVALID_URL' | 'INVALID_HTTP_RESPONSE' | 'FETCH_ERROR' | 'INVALID_MANIFEST' | 'UNSUPPORTED_FORMAT';
19
+ message: string;
20
+ };
21
+ export interface CozyManifest {
22
+ readonly majorVersion: number;
23
+ readonly source: Manifest;
24
+ readonly id: string;
25
+ readonly canvases: CozyCanvas[];
26
+ getLabel(locale?: string): string;
27
+ getMetadata(locale?: string): CozyMetadata[];
28
+ }
29
+ export interface CozyCanvas {
30
+ readonly source: Canvas;
31
+ readonly id: string;
32
+ readonly width: number;
33
+ readonly height: number;
34
+ readonly images: CozyImageResource[];
35
+ getLabel(locale?: string): string;
36
+ getMetadata(locale?: string): CozyMetadata[];
37
+ getThumbnailURL(minSize?: number): string;
38
+ }
39
+ export interface CozyMetadata {
40
+ label: string;
41
+ value: string;
42
+ }
43
+ export type CozyImageResource = StaticImageResource | ImageServiceResource;
44
+ export type ImageServiceResource = DynamicImageServiceResource | Level0ImageServiceResource;
45
+ interface BaseImageResource {
46
+ readonly source: IIIFExternalWebResource;
47
+ type: 'static' | 'dynamic' | 'level0';
48
+ width: number;
49
+ height: number;
50
+ }
51
+ export interface StaticImageResource extends BaseImageResource {
52
+ type: 'static';
53
+ url: string;
54
+ }
55
+ export interface DynamicImageServiceResource extends BaseImageResource {
56
+ type: 'dynamic';
57
+ service: ImageService2 | ImageService3;
58
+ serviceUrl: string;
59
+ majorVersion: number;
60
+ getRegionURL(bounds: Bounds, minSize?: number): string;
61
+ }
62
+ export interface Level0ImageServiceResource extends BaseImageResource {
63
+ type: 'level0';
64
+ majorVersion: number;
65
+ service: ImageService2 | ImageService3;
66
+ serviceUrl: string;
67
+ }
68
+ export interface ImageRequestOptions {
69
+ width?: number;
70
+ height?: number;
71
+ region?: 'full' | 'square' | {
72
+ x: number;
73
+ y: number;
74
+ width: number;
75
+ height: number;
76
+ };
77
+ quality?: 'default' | 'color' | 'gray' | 'bitonal';
78
+ format?: 'jpg' | 'png' | 'gif' | 'webp';
79
+ }
80
+ export interface Bounds {
81
+ x: number;
82
+ y: number;
83
+ w: number;
84
+ h: number;
85
+ }
86
+ export {};