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.
@@ -0,0 +1,3 @@
1
+ import { Level0ImageServiceResource } from '../types';
2
+ import { ImageInfo } from './types';
3
+ export declare const fetchImageInfo: (resource: Level0ImageServiceResource) => Promise<ImageInfo>;
@@ -1,6 +1,186 @@
1
- import { cropRegion as e } from "../src/level-0/crop-region.js";
2
- import { getThumbnail as p } from "../src/level-0/get-thumbnail.js";
1
+ import { g as $ } from "../resource-DS2brz47.js";
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
+ t == null || t.removeEventListener("abort", e);
4
+ });
5
+ function M({ limit: t, interval: e, strict: c, signal: i, onDelay: n }) {
6
+ if (!Number.isFinite(t))
7
+ throw new TypeError("Expected `limit` to be a finite number");
8
+ if (!Number.isFinite(e))
9
+ throw new TypeError("Expected `interval` to be a finite number");
10
+ const r = /* @__PURE__ */ new Map();
11
+ let o = 0, a = 0;
12
+ function l() {
13
+ const h = Date.now();
14
+ return h - o > e ? (a = 1, o = h, 0) : (a < t ? a++ : (o += e, a = 1), o - h);
15
+ }
16
+ const s = [];
17
+ function d() {
18
+ const h = Date.now();
19
+ if (s.length > 0 && h - s.at(-1) > e && (s.length = 0), s.length < t)
20
+ return s.push(h), 0;
21
+ const w = s[0] + e;
22
+ return s.shift(), s.push(w), Math.max(0, w - h);
23
+ }
24
+ const g = c ? d : l;
25
+ return (h) => {
26
+ const w = function(...u) {
27
+ if (!w.isEnabled)
28
+ return (async () => h.apply(this, u))();
29
+ let f;
30
+ return new Promise((v, C) => {
31
+ const y = () => {
32
+ v(h.apply(this, u)), r.delete(f);
33
+ }, p = g();
34
+ p > 0 ? (f = setTimeout(y, p), r.set(f, C), n == null || n(...u)) : y();
35
+ });
36
+ }, m = () => {
37
+ for (const u of r.keys())
38
+ clearTimeout(u), r.get(u)(i.reason);
39
+ r.clear(), s.splice(0, s.length);
40
+ };
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
+ get() {
43
+ return r.size;
44
+ }
45
+ }), w;
46
+ };
47
+ }
48
+ const H = () => {
49
+ let t = {
50
+ limit: 5,
51
+ interval: 1e3
52
+ }, e = M(t);
53
+ return {
54
+ getInstance: () => e,
55
+ getConfig: () => ({ ...t }),
56
+ setConfig: (r) => {
57
+ t = { ...t, ...r }, e = M(t);
58
+ }
59
+ };
60
+ }, x = H(), W = (t) => {
61
+ if (!t) return;
62
+ const e = x.getConfig();
63
+ (t.limit && t.limit !== e.limit || t.interval && t.interval !== e.interval) && (console.log("updating throttle config!"), x.setConfig({ ...e, ...t }));
64
+ }, E = (t) => {
65
+ if (t) {
66
+ const i = {
67
+ limit: t.callsPerSecond || 5,
68
+ interval: 1e3
69
+ };
70
+ W(i);
71
+ }
72
+ return { loadImage: x.getInstance()((i) => new Promise((n, r) => {
73
+ const o = new Image();
74
+ o.crossOrigin = "anonymous", o.onload = () => n(o), o.onerror = r, o.src = i;
75
+ })) };
76
+ }, j = (t, e) => {
77
+ const { x: c, y: i, w: n, h: r } = e, o = t.tiles[0].width, a = t.tiles[0].height || t.tiles[0].width;
78
+ return `${t.id}/${c * o},${i * a},${n},${r}/${o},/0/default.jpg`;
79
+ }, R = (t, e) => {
80
+ const c = t.tiles[0].width, i = t.tiles[0].height || t.tiles[0].width, n = t.width, r = 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
+ for (let g = a; g < s; g++)
82
+ for (let h = o; h < l; h++) {
83
+ if (h * c >= n || g * i >= r)
84
+ continue;
85
+ const w = Math.min(c, n - h * c), m = Math.min(i, r - g * i);
86
+ d.push({
87
+ x: h,
88
+ y: g,
89
+ width: w,
90
+ height: m,
91
+ url: j(t, { x: h, y: g, w, h: m })
92
+ });
93
+ }
94
+ return d;
95
+ }, L = async (t, e) => {
96
+ const c = await T(t), i = R(c, e), n = document.createElement("canvas"), r = n.getContext("2d");
97
+ if (!r)
98
+ throw new Error("Error initializing canvas context");
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
+ n.width = l, n.height = s;
101
+ const d = E({ callsPerSecond: 20 });
102
+ await Promise.all(i.map(async (w) => {
103
+ const m = await d.loadImage(w.url), u = w.x * o - e.x, f = w.y * a - e.y;
104
+ r.drawImage(m, u, f);
105
+ }));
106
+ const g = document.createElement("canvas");
107
+ g.width = e.w, g.height = e.h;
108
+ const h = g.getContext("2d");
109
+ if (!h)
110
+ throw new Error("Error initializing canvas context");
111
+ return h.drawImage(
112
+ n,
113
+ 0,
114
+ 0,
115
+ e.w,
116
+ e.h,
117
+ 0,
118
+ 0,
119
+ e.w,
120
+ e.h
121
+ ), new Promise((w, m) => {
122
+ g.toBlob(
123
+ (u) => {
124
+ u ? w(u) : m(new Error("Failed to create blob"));
125
+ },
126
+ "image/jpeg",
127
+ 0.95
128
+ );
129
+ });
130
+ }, I = (t, e) => {
131
+ const c = t.tiles[0].scaleFactors.sort((o, a) => a - o);
132
+ if (!e)
133
+ return c[0];
134
+ const i = e.width ? t.width / e.width : 1 / 0, n = e.height ? t.height / e.height : 1 / 0, r = Math.min(i, n);
135
+ for (const o of c)
136
+ if (o <= r)
137
+ return o;
138
+ return c[c.length - 1];
139
+ }, b = (t, e) => {
140
+ const c = I(t, e);
141
+ let i = Math.ceil(t.width / c), n = Math.ceil(t.height / c);
142
+ if (e) {
143
+ const r = t.width / t.height;
144
+ e.width && i < e.width && (i = e.width, n = Math.ceil(i / r)), e.height && n < e.height && (n = e.height, i = Math.ceil(n * r));
145
+ }
146
+ return { width: i, height: n };
147
+ }, k = (t, e) => {
148
+ const c = I(t, e), i = t.tiles[0].width, n = t.tiles[0].height || t.tiles[0].width, r = Math.ceil(t.width / (i * c)), o = Math.ceil(t.height / (n * c)), a = [];
149
+ for (let l = 0; l < o; l++)
150
+ for (let s = 0; s < r; s++) {
151
+ const d = Math.min(
152
+ i,
153
+ (t.width - s * i * c) / c
154
+ ), g = Math.min(
155
+ n,
156
+ (t.height - l * n * c) / c
157
+ );
158
+ d <= 0 || g <= 0 || a.push({
159
+ url: `${t.id}/${s * i * c},${l * n * c},${d * c},${g * c}/${Math.ceil(d)},/0/default.jpg`,
160
+ width: Math.ceil(d),
161
+ height: Math.ceil(g),
162
+ x: s * i,
163
+ y: l * n
164
+ });
165
+ }
166
+ return a;
167
+ }, O = async (t, e) => {
168
+ const c = await T(t), i = k(c, e), n = b(c, e), r = document.createElement("canvas");
169
+ r.width = n.width, r.height = n.height;
170
+ const o = r.getContext("2d");
171
+ if (!o)
172
+ throw new Error("Error creating canvas context");
173
+ const a = E();
174
+ return await Promise.all(i.map(async (l) => {
175
+ const s = await a.loadImage(l.url);
176
+ o.drawImage(s, l.x, l.y);
177
+ })), new Promise((l, s) => {
178
+ r.toBlob((d) => {
179
+ d ? l(d) : s(new Error("Failed to create blob"));
180
+ }, "image/jpeg", 0.85);
181
+ });
182
+ };
3
183
  export {
4
- e as cropRegion,
5
- p as getThumbnail
184
+ L as cropRegion,
185
+ O as getThumbnail
6
186
  };
@@ -7,7 +7,7 @@ const c = (e, r) => {
7
7
  if (t)
8
8
  return t[0];
9
9
  {
10
- const n = Object.values(e).reduce((s, a) => Array.isArray(a) ? [...s, ...a] : [...s, a], []);
10
+ const n = Object.values(e).reduce((a, s) => Array.isArray(s) ? [...a, ...s] : [...a, s], []);
11
11
  return n.length > 0 ? n[0] : void 0;
12
12
  }
13
13
  }, i = (e) => (r = "en") => {
@@ -15,14 +15,14 @@ const c = (e, r) => {
15
15
  return t ? o(t, r) : void 0;
16
16
  }, u = (e) => (r) => {
17
17
  const t = c(e, "metadata");
18
- return t ? t.map(({ label: n, value: s }) => ({
18
+ return t ? t.map(({ label: n, value: a }) => ({
19
19
  label: o(n, r),
20
- value: o(s, r)
20
+ value: o(a, r)
21
21
  })) : [];
22
22
  };
23
23
  export {
24
- i as getLabel,
25
- u as getMetadata,
26
- c as getPropertyValue,
27
- o as getStringValue
24
+ u as a,
25
+ i as b,
26
+ o as c,
27
+ c as g
28
28
  };
package/dist/types.d.ts CHANGED
@@ -23,7 +23,7 @@ export interface CozyManifest {
23
23
  readonly source: Manifest;
24
24
  readonly id: string;
25
25
  readonly canvases: CozyCanvas[];
26
- getLabel(locale?: string): string;
26
+ getLabel(locale?: string): string | undefined;
27
27
  getMetadata(locale?: string): CozyMetadata[];
28
28
  }
29
29
  export interface CozyCanvas {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-iiif",
3
- "version": "0.1.0",
3
+ "version": "0.1.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",
@@ -26,8 +26,8 @@
26
26
  "./level-0": "./dist/level-0/index.js"
27
27
  },
28
28
  "devDependencies": {
29
- "vite": "^6.1.0",
30
- "vite-plugin-dts": "^4.5.0"
29
+ "vite": "^6.2.0",
30
+ "vite-plugin-dts": "^4.5.3"
31
31
  },
32
32
  "dependencies": {
33
33
  "@iiif/parser": "^2.1.7",
package/src/Cozy.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { Canvas, Manifest } from '@iiif/presentation-3';
1
+ import type { Canvas, Manifest } from '@iiif/presentation-3';
2
2
  import { convertPresentation2 } from '@iiif/parser/presentation-2';
3
3
  import { Traverse } from '@iiif/parser';
4
- import { CozyCanvas, CozyManifest, CozyParseResult, ImageServiceResource } from './types';
4
+ import type { CozyCanvas, CozyManifest, CozyParseResult, ImageServiceResource } from './types';
5
5
  import {
6
6
  getImages,
7
7
  getLabel,
@@ -1,8 +1,8 @@
1
- import { Canvas, IIIFExternalWebResource } from '@iiif/presentation-3';
1
+ import type { Canvas, IIIFExternalWebResource } from '@iiif/presentation-3';
2
2
  import { Traverse } from '@iiif/parser';
3
3
  import { getPropertyValue } from './resource';
4
4
  import { getImageURLFromService, getRegionURL, isImageService, parseImageService } from './image-service';
5
- import {
5
+ import type {
6
6
  CozyImageResource,
7
7
  DynamicImageServiceResource,
8
8
  ImageServiceResource,
@@ -54,6 +54,7 @@ const toCozyImageResource = (resource: IIIFExternalWebResource) => {
54
54
  const imageService = (resource.service || []).find(isImageService);
55
55
 
56
56
  const service = imageService ? parseImageService(imageService) : undefined;
57
+
57
58
  if (service) {
58
59
  const image = {
59
60
  source: resource,
@@ -96,7 +97,7 @@ export const getImages = (canvas: Canvas): CozyImageResource[] => {
96
97
  : [];
97
98
 
98
99
  const imageResources = bodies.filter(b => (b as IIIFExternalWebResource).type === 'Image');
99
- images.push(...imageResources.map(toCozyImageResource));
100
+ images.push(...imageResources.map(body => toCozyImageResource(body as IIIFExternalWebResource)));
100
101
  }
101
102
  }]
102
103
  });
@@ -1,12 +1,15 @@
1
- import { ImageService2, ImageService3, Service } from '@iiif/presentation-3';
1
+ import type { ImageService2, ImageService3, Service } from '@iiif/presentation-3';
2
2
  import { getPropertyValue } from './resource';
3
- import { Bounds, CozyImageResource } from '../types';
3
+ import type { Bounds, CozyImageResource } from '../types';
4
4
 
5
5
  type ImageService = ImageService2 | ImageService3;
6
6
 
7
7
  export const isImageService = (data: any): data is ImageService => {
8
8
  const t = getPropertyValue<string>(data, 'type');
9
- return t.startsWith('ImageService');
9
+
10
+ return t.startsWith('ImageService') || (
11
+ data.profile && data.profile.toString().includes('iiif.io/api/image/')
12
+ );
10
13
  }
11
14
 
12
15
  export const parseImageService = (service: Service) => {
@@ -66,7 +69,7 @@ export const getRegionURLFromService = (
66
69
  service: ImageService2 | ImageService3,
67
70
  bounds: Bounds,
68
71
  minSize: number
69
- ): string => {
72
+ ): string | undefined => {
70
73
  const id = getPropertyValue(service, 'id');
71
74
  const compliance = service.profile || '';
72
75
 
@@ -1,5 +1,5 @@
1
- import { InternationalString, MetadataItem } from '@iiif/presentation-3';
2
- import { CozyMetadata } from '../types';
1
+ import type { InternationalString, MetadataItem } from '@iiif/presentation-3';
2
+ import type { CozyMetadata } from '../types';
3
3
 
4
4
  export const getPropertyValue = <T extends unknown = any>(data: any, name: string) => {
5
5
  let prop: any = data[name];
@@ -18,7 +18,7 @@ export const getStringValue = (propertyValue: string | InternationalString, loca
18
18
  return localized[0];
19
19
  } else {
20
20
  const values = Object.values(propertyValue).reduce<string[]>((flattened, value) => {
21
- return Array.isArray(value) ? [...flattened, ...value] : [...flattened, value]
21
+ return Array.isArray(value) ? [...flattened, ...value] : [...flattened, value as unknown as string]
22
22
  }, []);
23
23
 
24
24
  return values.length > 0 ? values[0] : undefined;
@@ -37,5 +37,5 @@ export const getMetadata = (data: any) => (locale?: string): CozyMetadata[] => {
37
37
  return metadata.map(({ label, value }) => ({
38
38
  label: getStringValue(label, locale),
39
39
  value: getStringValue(value, locale)
40
- }));
40
+ } as CozyMetadata));
41
41
  }
@@ -1,12 +1,13 @@
1
- import { Bounds, Level0ImageServiceResource } from '../types';
1
+ import type { Bounds, Level0ImageServiceResource } from '../types';
2
+ import { fetchImageInfo } from './fetch-image-info';
2
3
  import { getThrottledLoader } from './throttled-loader';
3
- import { ImageInfo, Tile } from './types';
4
+ import type { ImageInfo, Tile } from './types';
4
5
 
5
6
  const getTileUrl = (info: ImageInfo, bounds: Bounds): string => {
6
7
  const { x, y, w, h } = bounds;
7
8
  const tileWidth = info.tiles[0].width;
8
9
  const tileHeight = info.tiles[0].height|| info.tiles[0].width;
9
- return `${info['@id']}/${x * tileWidth},${y * tileHeight},${w},${h}/${tileWidth},/0/default.jpg`;
10
+ return `${info.id}/${x * tileWidth},${y * tileHeight},${w},${h}/${tileWidth},/0/default.jpg`;
10
11
  }
11
12
 
12
13
  const getTilesForRegion = (info: ImageInfo, bounds: Bounds): Tile[] => {
@@ -38,7 +39,7 @@ const getTilesForRegion = (info: ImageInfo, bounds: Bounds): Tile[] => {
38
39
  y,
39
40
  width: effectiveWidth,
40
41
  height: effectiveHeight,
41
- url: getTileUrl(info, { x, y, w: effectiveWidth, h: effectiveHeight })
42
+ url: getTileUrl(info, { x, y, w: effectiveWidth, h: effectiveHeight })
42
43
  });
43
44
  }
44
45
  }
@@ -47,7 +48,7 @@ const getTilesForRegion = (info: ImageInfo, bounds: Bounds): Tile[] => {
47
48
  }
48
49
 
49
50
  export const cropRegion = async (resource: Level0ImageServiceResource, bounds: Bounds): Promise<Blob> => {
50
- const info = await fetch(resource.serviceUrl).then(res => res.json());
51
+ const info = await fetchImageInfo(resource);
51
52
 
52
53
  const tiles = getTilesForRegion(info, bounds);
53
54
 
@@ -0,0 +1,11 @@
1
+ import { getPropertyValue } from '../core';
2
+ import type { Level0ImageServiceResource } from '../types';
3
+ import type { ImageInfo } from './types';
4
+
5
+ const toImageInfo = (resource: any) => {
6
+ const id = getPropertyValue(resource, 'id');
7
+ return { id, ...resource };
8
+ }
9
+
10
+ export const fetchImageInfo = (resource: Level0ImageServiceResource): Promise<ImageInfo> =>
11
+ fetch(resource.serviceUrl).then(res => res.json()).then(toImageInfo);
@@ -1,6 +1,7 @@
1
- import { Level0ImageServiceResource } from '../types';
1
+ import type { Level0ImageServiceResource } from '../types';
2
+ import { fetchImageInfo } from './fetch-image-info';
2
3
  import { getThrottledLoader } from './throttled-loader';
3
- import { ImageInfo, Size, Tile } from './types';
4
+ import type { ImageInfo, Size, Tile } from './types';
4
5
 
5
6
  const getBestScaleFactor = (info: ImageInfo, minSize?: Partial<Size>): number => {
6
7
  // Sort descending
@@ -70,7 +71,7 @@ const getThumbnailTiles = (info: ImageInfo, minSize?: Partial<Size>): Tile[] =>
70
71
  if (actualWidth <= 0 || actualHeight <= 0) continue;
71
72
 
72
73
  tiles.push({
73
- url: `${info['@id']}/${x * tileWidth * scaleFactor},${y * tileHeight * scaleFactor},${actualWidth * scaleFactor},${actualHeight * scaleFactor}/${Math.ceil(actualWidth)},/0/default.jpg`,
74
+ url: `${info.id}/${x * tileWidth * scaleFactor},${y * tileHeight * scaleFactor},${actualWidth * scaleFactor},${actualHeight * scaleFactor}/${Math.ceil(actualWidth)},/0/default.jpg`,
74
75
  width: Math.ceil(actualWidth),
75
76
  height: Math.ceil(actualHeight),
76
77
  x: x * tileWidth,
@@ -83,7 +84,7 @@ const getThumbnailTiles = (info: ImageInfo, minSize?: Partial<Size>): Tile[] =>
83
84
  }
84
85
 
85
86
  export const getThumbnail = async (resource: Level0ImageServiceResource, minSize?: Partial<Size>): Promise<Blob> => {
86
- const info = await fetch(resource.serviceUrl).then(res => res.json());
87
+ const info = await fetchImageInfo(resource);
87
88
 
88
89
  const tiles = getThumbnailTiles(info, minSize);
89
90
  const dimensions = getThumbnailDimensions(info, minSize);
package/src/types.ts CHANGED
@@ -21,7 +21,7 @@ export interface CozyManifest {
21
21
 
22
22
  readonly canvases: CozyCanvas[];
23
23
 
24
- getLabel(locale?: string): string;
24
+ getLabel(locale?: string): string | undefined;
25
25
 
26
26
  getMetadata(locale?: string): CozyMetadata[];
27
27
 
package/tsconfig.json CHANGED
@@ -1,20 +1,19 @@
1
1
  {
2
2
  "compilerOptions": {
3
+ "allowJs": true,
3
4
  "allowSyntheticDefaultImports": true,
4
- "baseUrl": ".",
5
- "isolatedModules": true,
6
- "lib": ["ES2021", "DOM", "DOM.Iterable"],
5
+ "esModuleInterop": true,
7
6
  "module": "ESNext",
8
7
  "moduleResolution": "Bundler",
9
- "noEmit": true,
10
8
  "noFallthroughCasesInSwitch": true,
11
9
  "noUnusedLocals": false,
12
10
  "noUnusedParameters": false,
13
- "resolveJsonModule": true,
14
11
  "skipLibCheck": true,
15
- "strict": false,
16
- "target": "ES6",
12
+ "strict": true,
13
+ "target": "ES2020",
14
+ "verbatimModuleSyntax": true,
17
15
  "useDefineForClassFields": true
18
16
  },
19
- "include": ["src"]
17
+ "include": ["src/**/*"],
18
+ "exclude": ["node_modules", "dist"]
20
19
  }
package/vite.config.ts CHANGED
@@ -11,11 +11,6 @@ export default defineConfig({
11
11
  'level-0/index': resolve(__dirname, 'src/level-0/index.ts'),
12
12
  },
13
13
  formats: ['es']
14
- },
15
- rollupOptions: {
16
- output: {
17
- preserveModules: true
18
- }
19
14
  }
20
15
  }
21
16
  });
package/dist/src/Cozy.js DELETED
@@ -1,133 +0,0 @@
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
- };
@@ -1,63 +0,0 @@
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
- };