cozy-iiif 0.8.0 → 0.8.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.
@@ -35,20 +35,18 @@ function d(e, t = 0) {
35
35
  }
36
36
  //#endregion
37
37
  //#region node_modules/uuid/dist/rng.js
38
- var f, p = new Uint8Array(16);
39
- function m() {
40
- if (!f) {
41
- if (typeof crypto > "u" || !crypto.getRandomValues) throw Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
42
- f = crypto.getRandomValues.bind(crypto);
43
- }
44
- return f(p);
38
+ var f = new Uint8Array(16);
39
+ function p() {
40
+ return crypto.getRandomValues(f);
45
41
  }
46
- var h = { randomUUID: typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto) };
47
42
  //#endregion
48
43
  //#region node_modules/uuid/dist/v4.js
49
- function g(e, t, n) {
44
+ function m(e, t, n) {
45
+ return !t && !e && crypto.randomUUID ? crypto.randomUUID() : h(e, t, n);
46
+ }
47
+ function h(e, t, n) {
50
48
  e ||= {};
51
- let r = e.random ?? e.rng?.() ?? m();
49
+ let r = e.random ?? e.rng?.() ?? p();
52
50
  if (r.length < 16) throw Error("Random bytes length must be >= 16");
53
51
  if (r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, t) {
54
52
  if (n ||= 0, n < 0 || n + 16 > t.length) throw RangeError(`UUID byte range ${n}:${n + 15} is out of buffer bounds`);
@@ -57,16 +55,13 @@ function g(e, t, n) {
57
55
  }
58
56
  return d(r);
59
57
  }
60
- function _(e, t, n) {
61
- return h.randomUUID && !t && !e ? h.randomUUID() : g(e, t, n);
62
- }
63
58
  //#endregion
64
59
  //#region src/helpers/import-annotations.ts
65
- var v = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), y = (e, t) => {
60
+ var g = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), _ = (e, t) => {
66
61
  if (t) {
67
62
  let n = e.annotations;
68
63
  if (n.length > 0) {
69
- let r = RegExp(`${v(e.id)}/${v(t)}/page/p(\\d+)$`), i = n.reduce((e, t) => {
64
+ let r = RegExp(`${g(e.id)}/${g(t)}/page/p(\\d+)$`), i = n.reduce((e, t) => {
70
65
  let n = t.id.match(r);
71
66
  if (n && n[1]) {
72
67
  let t = parseInt(n[1]);
@@ -75,10 +70,10 @@ var v = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), y = (e, t) => {
75
70
  }, 1);
76
71
  return `${e.id}/${t}/annotations/page/p${i}`;
77
72
  } else return `${e.id}/${t}/annotations/page/p1`;
78
- } else return `${e.id}/annotations/page/${_()}`;
79
- }, b = (e, t, n) => {
73
+ } else return `${e.id}/annotations/page/${m()}`;
74
+ }, v = (e, t, n) => {
80
75
  let r = {
81
- id: y(e, n),
76
+ id: _(e, n),
82
77
  type: "AnnotationPage",
83
78
  items: t
84
79
  };
@@ -96,7 +91,7 @@ var v = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), y = (e, t) => {
96
91
  getMetadata: e.getMetadata,
97
92
  getThumbnailURL: e.getThumbnailURL
98
93
  };
99
- }, x = (e, t, n) => {
94
+ }, y = (e, t, n) => {
100
95
  let r = (e) => {
101
96
  let t = e.target;
102
97
  if (t) return typeof t == "string" ? t.substring(0, t.indexOf("#")) : t.source;
@@ -105,7 +100,7 @@ var v = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), y = (e, t) => {
105
100
  return n ? (e[n] || (e[n] = []), e[n].push(t), e) : e;
106
101
  }, {}), a = e.canvases.map((e) => {
107
102
  let t = i[e.id] || [];
108
- return t.length > 0 ? b(e, t, n) : e;
103
+ return t.length > 0 ? v(e, t, n) : e;
109
104
  });
110
105
  return {
111
106
  source: {
@@ -120,7 +115,7 @@ var v = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), y = (e, t) => {
120
115
  getMetadata: e.getMetadata,
121
116
  getTableOfContents: e.getTableOfContents
122
117
  };
123
- }, S = (e, t, n) => e.source.type === "Canvas" ? b(e, t, n) : x(e, t, n), C = (e) => {
118
+ }, b = (e, t, n) => e.source.type === "Canvas" ? v(e, t, n) : y(e, t, n), x = (e) => {
124
119
  let t = e.images[0];
125
120
  if (!t) return Promise.resolve(!1);
126
121
  let n;
@@ -134,4 +129,4 @@ var v = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), y = (e, t) => {
134
129
  });
135
130
  };
136
131
  //#endregion
137
- export { c as fetchAnnotations, l as hydrateCanvas, S as importAnnotations, C as testCORS };
132
+ export { c as fetchAnnotations, l as hydrateCanvas, b as importAnnotations, x as testCORS };
package/dist/index.js CHANGED
@@ -848,9 +848,12 @@ var Ge = async (e) => {
848
848
  message: "JSON resource is not a recognized IIIF format"
849
849
  };
850
850
  }, Ke = (t, n) => {
851
- let r = (t) => {
852
- let n = [];
853
- return new e({ manifest: [(e) => n.push(e)] }).traverseCollection(t), n.map((e) => ({
851
+ let r = (n) => {
852
+ let r = [];
853
+ return new e({
854
+ collection: [(e) => e.id !== s(t, "id") && r.push(e)],
855
+ manifest: [(e) => r.push(e)]
856
+ }).traverseCollection(n), r.map((e) => ({
854
857
  id: e.id,
855
858
  type: e.type,
856
859
  getLabel: p(e),
@@ -858,6 +861,7 @@ var Ge = async (e) => {
858
861
  }));
859
862
  }, i = n === 2 ? Z(t) : t, a = r(i);
860
863
  return {
864
+ type: "Collection",
861
865
  source: i,
862
866
  id: i.id,
863
867
  majorVersion: n,
package/dist/types.d.ts CHANGED
@@ -26,16 +26,18 @@ export interface CozyCollection {
26
26
  readonly majorVersion: number;
27
27
  readonly source: Collection;
28
28
  readonly id: string;
29
+ readonly type: 'Collection';
29
30
  readonly items: CozyCollectionItem[];
30
31
  getLabel(locale?: string): string | undefined;
31
32
  getMetadata(locale?: string): CozyMetadata[];
32
33
  }
33
- export interface CozyCollectionItem {
34
+ export interface CozyCollectionManifestItem {
34
35
  readonly id: string;
35
- readonly type: string;
36
+ readonly type: 'Manifest';
36
37
  readonly source: any;
37
38
  getLabel(locale?: string): string | undefined;
38
39
  }
40
+ export type CozyCollectionItem = CozyCollectionManifestItem | CozyCollection;
39
41
  export interface CozyManifest {
40
42
  readonly majorVersion: number;
41
43
  readonly source: Manifest;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-iiif",
3
- "version": "0.8.0",
3
+ "version": "0.8.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",
@@ -28,15 +28,15 @@
28
28
  "./level-0": "./dist/level-0/index.js"
29
29
  },
30
30
  "devDependencies": {
31
- "typescript": "^6.0.2",
32
- "vite": "^8.0.8",
33
- "vitest": "^4.1.4"
31
+ "typescript": "^6.0.3",
32
+ "vite": "^8.0.11",
33
+ "vitest": "^4.1.5"
34
34
  },
35
35
  "dependencies": {
36
36
  "@iiif/parser": "^2.2.10",
37
37
  "@iiif/presentation-3": "^2.2.3",
38
38
  "image-size": "^2.0.2",
39
39
  "p-throttle": "^8.1.0",
40
- "uuid": "^13.0.0"
40
+ "uuid": "^14.0.0"
41
41
  }
42
42
  }
package/src/Cozy.ts CHANGED
@@ -158,6 +158,9 @@ const parseCollectionResource = (resource: any, majorVersion: number): CozyColle
158
158
  const items: any[] = [];
159
159
 
160
160
  const modelBuilder = new Traverse({
161
+ // The model builder fires on the collection ITSELF - we don't want that, but want
162
+ // to collect sub-collections
163
+ collection: [item => item.id !== getPropertyValue(resource, 'id') && items.push(item)],
161
164
  manifest: [item => items.push(item)]
162
165
  });
163
166
 
@@ -176,6 +179,7 @@ const parseCollectionResource = (resource: any, majorVersion: number): CozyColle
176
179
  const items = parseV3(v3);
177
180
 
178
181
  return {
182
+ type: 'Collection',
179
183
  source: v3,
180
184
  id: v3.id,
181
185
  majorVersion,
package/src/types.ts CHANGED
@@ -28,6 +28,8 @@ export interface CozyCollection {
28
28
 
29
29
  readonly id: string;
30
30
 
31
+ readonly type: 'Collection';
32
+
31
33
  readonly items: CozyCollectionItem[];
32
34
 
33
35
  getLabel(locale?: string): string | undefined;
@@ -36,11 +38,11 @@ export interface CozyCollection {
36
38
 
37
39
  }
38
40
 
39
- export interface CozyCollectionItem {
41
+ export interface CozyCollectionManifestItem {
40
42
 
41
43
  readonly id: string;
42
44
 
43
- readonly type: string;
45
+ readonly type: 'Manifest';
44
46
 
45
47
  readonly source: any;
46
48
 
@@ -48,6 +50,8 @@ export interface CozyCollectionItem {
48
50
 
49
51
  }
50
52
 
53
+ export type CozyCollectionItem = CozyCollectionManifestItem | CozyCollection;
54
+
51
55
  export interface CozyManifest {
52
56
 
53
57
  readonly majorVersion: number;
package/test/Cozy.test.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { describe, it, expect } from 'vitest';
2
- import { Cozy, CozyManifest, DynamicImageServiceResource } from '../src';
2
+ import { Cozy, CozyCollection, CozyManifest, DynamicImageServiceResource } from '../src';
3
3
 
4
4
  import {
5
5
  COLLECTION,
6
+ NESTED_COLLECTION,
6
7
  INFO_JSON_V3,
7
8
  WITH_MULTI_IMAGE,
8
9
  WITH_STRUCTURES,
@@ -14,6 +15,18 @@ describe('Cozy', () => {
14
15
  it('should parse collection manifests correctly', async () => {
15
16
  const result = await Cozy.parseURL(COLLECTION);
16
17
  expect(result.type).toBe('collection');
18
+
19
+ const collection = (result as any).resource as CozyCollection;
20
+ expect(collection.items.length).toBe(16);
21
+ });
22
+
23
+ it('should parse nested collection manifests correctly', async () => {
24
+ const result = await Cozy.parseURL(NESTED_COLLECTION);
25
+ expect(result.type).toBe('collection');
26
+
27
+ const collection = (result as any).resource as CozyCollection;
28
+ expect(collection.items.length).toBe(7);
29
+ expect(collection.items.every(item => item.type === 'Collection'))
17
30
  });
18
31
 
19
32
  it('should parse structures in presentation manifests', async () => {
package/test/fixtures.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export const COLLECTION =
2
2
  'https://www.davidrumsey.com/luna/servlet/iiif/collection/s/1k986a';
3
3
 
4
+ export const NESTED_COLLECTION =
5
+ 'https://image-ub.bgo1.test.rail.uib.no/iiif/presentation/na/fragmenter/collection.json';
6
+
4
7
  export const WITH_STRUCTURES =
5
8
  'https://lib.is/IE19255085/manifest';
6
9