cozy-iiif 0.1.4 → 0.1.6
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/Cozy.d.ts +3 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/manifest.d.ts +2 -0
- package/dist/helpers/import-annotations.d.ts +3 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/index.js +451 -308
- package/dist/types.d.ts +20 -1
- package/package.json +5 -4
- package/src/Cozy.ts +144 -108
- package/src/core/index.ts +1 -0
- package/src/core/manifest.ts +38 -0
- package/src/helpers/import-annotations.ts +115 -0
- package/src/helpers/index.ts +1 -0
- package/src/types.ts +39 -1
- package/test/Cozy.test.ts +18 -4
- package/test/annotations/fixtures.ts +135 -0
- package/test/annotations/import-annotations.test.ts +46 -0
- package/test/fixtures.ts +4 -1
@@ -0,0 +1,135 @@
|
|
1
|
+
// Modified from https://iiif.io/api/cookbook/recipe/0021-tagging/
|
2
|
+
export const ANNOTATIONS = [{
|
3
|
+
id: 'https://iiif.io/api/cookbook/recipe/0021-tagging/annotation/p0001',
|
4
|
+
type: 'Annotation',
|
5
|
+
motivation: 'tagging',
|
6
|
+
body: {
|
7
|
+
type: 'TextualBody',
|
8
|
+
value: 'Test Annotation 1',
|
9
|
+
format: 'text/plain'
|
10
|
+
},
|
11
|
+
target: 'https://iiif.io/api/cookbook/recipe/0001-mvm-image/canvas/p1#xywh=265,661,1260,1239'
|
12
|
+
},{
|
13
|
+
id: 'https://iiif.io/api/cookbook/recipe/0021-tagging/annotation/p0002',
|
14
|
+
type: 'Annotation',
|
15
|
+
motivation: 'tagging',
|
16
|
+
body: {
|
17
|
+
type: 'TextualBody',
|
18
|
+
value: 'Test Annotation 2',
|
19
|
+
format: 'text/plain'
|
20
|
+
},
|
21
|
+
target: {
|
22
|
+
source: 'https://iiif.io/api/cookbook/recipe/0001-mvm-image/canvas/p2',
|
23
|
+
selector: {
|
24
|
+
type: 'FragmentSelector',
|
25
|
+
value: 'xywh=265,661,1260,1239'
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}]
|
29
|
+
|
30
|
+
// https://iiif.io/api/cookbook/recipe/0001-mvm-image/
|
31
|
+
export const SINGLE_CANVAS_NO_ANNOTATIONS = {
|
32
|
+
'@context': 'http://iiif.io/api/presentation/3/context.json',
|
33
|
+
id: 'https://iiif.io/api/cookbook/recipe/0001-mvm-image/manifest.json',
|
34
|
+
type: 'Manifest',
|
35
|
+
label: {
|
36
|
+
en: [
|
37
|
+
'Single Image Example'
|
38
|
+
]
|
39
|
+
},
|
40
|
+
items: [
|
41
|
+
{
|
42
|
+
id: 'https://iiif.io/api/cookbook/recipe/0001-mvm-image/canvas/p1',
|
43
|
+
type: 'Canvas',
|
44
|
+
height: 1800,
|
45
|
+
width: 1200,
|
46
|
+
items: [
|
47
|
+
{
|
48
|
+
id: 'https://iiif.io/api/cookbook/recipe/0001-mvm-image/page/p1/1',
|
49
|
+
type: 'AnnotationPage',
|
50
|
+
items: [
|
51
|
+
{
|
52
|
+
id: 'https://iiif.io/api/cookbook/recipe/0001-mvm-image/annotation/p0001-image',
|
53
|
+
type: 'Annotation',
|
54
|
+
motivation: 'painting',
|
55
|
+
body: {
|
56
|
+
id: 'http://iiif.io/api/presentation/2.1/example/fixtures/resources/page1-full.png',
|
57
|
+
type: 'Image',
|
58
|
+
format: 'image/png',
|
59
|
+
height: 1800,
|
60
|
+
width: 1200
|
61
|
+
},
|
62
|
+
target: 'https://iiif.io/api/cookbook/recipe/0001-mvm-image/canvas/p1'
|
63
|
+
}
|
64
|
+
]
|
65
|
+
}
|
66
|
+
]
|
67
|
+
}
|
68
|
+
]
|
69
|
+
}
|
70
|
+
|
71
|
+
export const TWO_CANVASES_NO_ANNOTATIONS = {
|
72
|
+
'@context': 'http://iiif.io/api/presentation/3/context.json',
|
73
|
+
id: 'https://iiif.io/api/cookbook/recipe/0001-mvm-image/manifest.json',
|
74
|
+
type: 'Manifest',
|
75
|
+
label: {
|
76
|
+
en: [
|
77
|
+
'Single Image Example'
|
78
|
+
]
|
79
|
+
},
|
80
|
+
items: [
|
81
|
+
{
|
82
|
+
id: 'https://iiif.io/api/cookbook/recipe/0001-mvm-image/canvas/p1',
|
83
|
+
type: 'Canvas',
|
84
|
+
height: 1800,
|
85
|
+
width: 1200,
|
86
|
+
items: [
|
87
|
+
{
|
88
|
+
id: 'https://iiif.io/api/cookbook/recipe/0001-mvm-image/page/p1/1',
|
89
|
+
type: 'AnnotationPage',
|
90
|
+
items: [
|
91
|
+
{
|
92
|
+
id: 'https://iiif.io/api/cookbook/recipe/0001-mvm-image/annotation/p0001-image',
|
93
|
+
type: 'Annotation',
|
94
|
+
motivation: 'painting',
|
95
|
+
body: {
|
96
|
+
id: 'http://iiif.io/api/presentation/2.1/example/fixtures/resources/page1-full.png',
|
97
|
+
type: 'Image',
|
98
|
+
format: 'image/png',
|
99
|
+
height: 1800,
|
100
|
+
width: 1200
|
101
|
+
},
|
102
|
+
target: 'https://iiif.io/api/cookbook/recipe/0001-mvm-image/canvas/p1'
|
103
|
+
}
|
104
|
+
]
|
105
|
+
}
|
106
|
+
]
|
107
|
+
}, {
|
108
|
+
id: 'https://iiif.io/api/cookbook/recipe/0001-mvm-image/canvas/p2',
|
109
|
+
type: 'Canvas',
|
110
|
+
height: 1800,
|
111
|
+
width: 1200,
|
112
|
+
items: [
|
113
|
+
{
|
114
|
+
id: 'https://iiif.io/api/cookbook/recipe/0001-mvm-image/page/p1/1',
|
115
|
+
type: 'AnnotationPage',
|
116
|
+
items: [
|
117
|
+
{
|
118
|
+
id: 'https://iiif.io/api/cookbook/recipe/0001-mvm-image/annotation/p0001-image',
|
119
|
+
type: 'Annotation',
|
120
|
+
motivation: 'painting',
|
121
|
+
body: {
|
122
|
+
id: 'http://iiif.io/api/presentation/2.1/example/fixtures/resources/page1-full.png',
|
123
|
+
type: 'Image',
|
124
|
+
format: 'image/png',
|
125
|
+
height: 1800,
|
126
|
+
width: 1200
|
127
|
+
},
|
128
|
+
target: 'https://iiif.io/api/cookbook/recipe/0001-mvm-image/canvas/p1'
|
129
|
+
}
|
130
|
+
]
|
131
|
+
}
|
132
|
+
]
|
133
|
+
}
|
134
|
+
]
|
135
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
2
|
+
import { Annotation } from '@iiif/presentation-3';
|
3
|
+
import { Cozy, CozyManifest } from '../../src';
|
4
|
+
|
5
|
+
import {
|
6
|
+
ANNOTATIONS,
|
7
|
+
SINGLE_CANVAS_NO_ANNOTATIONS,
|
8
|
+
TWO_CANVASES_NO_ANNOTATIONS
|
9
|
+
} from './fixtures';
|
10
|
+
|
11
|
+
describe('import-annotations', () => {
|
12
|
+
|
13
|
+
it('should insert a new page into a canvas with no annotatinos', () => {
|
14
|
+
const result = Cozy.parse(SINGLE_CANVAS_NO_ANNOTATIONS);
|
15
|
+
|
16
|
+
expect(result.type).toBe('manifest');
|
17
|
+
const manifest = (result as any).resource as CozyManifest;
|
18
|
+
|
19
|
+
expect(manifest.canvases.length).toBe(1);
|
20
|
+
const firstCanvas = manifest.canvases[0];
|
21
|
+
|
22
|
+
const annotations = ANNOTATIONS as Annotation[];
|
23
|
+
|
24
|
+
const modified = Cozy.Helpers.importAnnotations(firstCanvas, annotations)
|
25
|
+
expect(modified.annotations.length).toBe(1);
|
26
|
+
});
|
27
|
+
|
28
|
+
it('should correctly insert annotation pages into the test manifest', () => {
|
29
|
+
const result = Cozy.parse(TWO_CANVASES_NO_ANNOTATIONS);
|
30
|
+
|
31
|
+
expect(result.type).toBe('manifest');
|
32
|
+
const manifest = (result as any).resource as CozyManifest;
|
33
|
+
|
34
|
+
expect(manifest.canvases.length).toBe(2);
|
35
|
+
expect(manifest.canvases[0].annotations.length).toBe(0);
|
36
|
+
expect(manifest.canvases[1].annotations.length).toBe(0);
|
37
|
+
|
38
|
+
const annotations = ANNOTATIONS as Annotation[];
|
39
|
+
|
40
|
+
const modified = Cozy.Helpers.importAnnotations(manifest, annotations, 'cozy');
|
41
|
+
expect(modified.canvases[0].annotations.length).toBe(1);
|
42
|
+
expect(modified.canvases[1].annotations.length).toBe(1);
|
43
|
+
});
|
44
|
+
|
45
|
+
});
|
46
|
+
|
package/test/fixtures.ts
CHANGED