@readium/shared 2.2.0 → 2.2.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/dist/index.js +259 -250
- package/dist/index.umd.cjs +3 -3
- package/package.json +1 -1
- package/src/publication/Manifest.ts +23 -14
- package/src/publication/Publication.ts +3 -5
- package/src/publication/services/content/iterators/PublicationContentIterator.ts +1 -1
- package/types/src/publication/Manifest.d.ts +2 -2
- package/types/src/publication/Publication.d.ts +1 -2
package/package.json
CHANGED
|
@@ -19,7 +19,7 @@ export class Manifest {
|
|
|
19
19
|
|
|
20
20
|
public readonly metadata: Metadata;
|
|
21
21
|
|
|
22
|
-
public readonly links
|
|
22
|
+
public readonly links?: Links;
|
|
23
23
|
|
|
24
24
|
/** Identifies a list of resources in reading order for the publication. */
|
|
25
25
|
public readonly readingOrder: Links;
|
|
@@ -35,7 +35,7 @@ export class Manifest {
|
|
|
35
35
|
constructor(values: {
|
|
36
36
|
context?: Array<string>;
|
|
37
37
|
metadata: Metadata;
|
|
38
|
-
links
|
|
38
|
+
links?: Links;
|
|
39
39
|
readingOrder: Links;
|
|
40
40
|
resources?: Links;
|
|
41
41
|
toc?: Links;
|
|
@@ -65,14 +65,18 @@ export class Manifest {
|
|
|
65
65
|
|
|
66
66
|
const links = Links.deserialize(json.links);
|
|
67
67
|
|
|
68
|
-
if (!links) return;
|
|
69
|
-
|
|
70
68
|
const readingOrder = Links.deserialize(
|
|
71
69
|
json.readingOrder ? json.readingOrder : json.spine
|
|
72
70
|
);
|
|
73
71
|
|
|
74
72
|
if (!readingOrder) return;
|
|
75
73
|
|
|
74
|
+
const knownKeys = new Set(['@context', 'metadata', 'links', 'readingOrder', 'spine', 'resources', 'toc']);
|
|
75
|
+
const remaining: Record<string, unknown> = {};
|
|
76
|
+
Object.keys(json).forEach(key => {
|
|
77
|
+
if (!knownKeys.has(key)) remaining[key] = json[key];
|
|
78
|
+
});
|
|
79
|
+
|
|
76
80
|
return new Manifest({
|
|
77
81
|
context: arrayfromJSONorString(json['@context']),
|
|
78
82
|
metadata,
|
|
@@ -80,9 +84,7 @@ export class Manifest {
|
|
|
80
84
|
readingOrder,
|
|
81
85
|
resources: Links.deserialize(json.resources),
|
|
82
86
|
toc: Links.deserialize(json.toc),
|
|
83
|
-
subcollections: PublicationCollection.deserializeCollections(
|
|
84
|
-
sub: json.sub,
|
|
85
|
-
}),
|
|
87
|
+
subcollections: PublicationCollection.deserializeCollections(remaining),
|
|
86
88
|
});
|
|
87
89
|
}
|
|
88
90
|
|
|
@@ -93,7 +95,7 @@ export class Manifest {
|
|
|
93
95
|
const json: any = {};
|
|
94
96
|
if (this.context !== undefined) json['@context'] = this.context;
|
|
95
97
|
json.metadata = this.metadata.serialize();
|
|
96
|
-
json.links = this.links.serialize();
|
|
98
|
+
if (this.links !== undefined) json.links = this.links.serialize();
|
|
97
99
|
json.readingOrder = this.readingOrder.serialize();
|
|
98
100
|
if (this.resources) json.resources = this.resources.serialize();
|
|
99
101
|
if (this.toc) json.toc = this.toc.serialize();
|
|
@@ -108,7 +110,9 @@ export class Manifest {
|
|
|
108
110
|
if (this.resources) {
|
|
109
111
|
links.push(this.resources);
|
|
110
112
|
}
|
|
111
|
-
|
|
113
|
+
if (this.links) {
|
|
114
|
+
links.push(this.links);
|
|
115
|
+
}
|
|
112
116
|
|
|
113
117
|
let result: Link | undefined;
|
|
114
118
|
|
|
@@ -129,7 +133,9 @@ export class Manifest {
|
|
|
129
133
|
if (this.resources) {
|
|
130
134
|
result.push(this.resources.filterByRel(rel));
|
|
131
135
|
}
|
|
132
|
-
|
|
136
|
+
if (this.links) {
|
|
137
|
+
result.push(this.links.filterByRel(rel));
|
|
138
|
+
}
|
|
133
139
|
|
|
134
140
|
return result.reduce((acc, val) => acc.concat(val), []);
|
|
135
141
|
}
|
|
@@ -197,7 +203,9 @@ export class Manifest {
|
|
|
197
203
|
if (this.resources) {
|
|
198
204
|
links.push(this.resources);
|
|
199
205
|
}
|
|
200
|
-
|
|
206
|
+
if (this.links) {
|
|
207
|
+
links.push(this.links);
|
|
208
|
+
}
|
|
201
209
|
|
|
202
210
|
const link = find(links);
|
|
203
211
|
|
|
@@ -218,7 +226,7 @@ export class Manifest {
|
|
|
218
226
|
* e.g. https://provider.com/pub1293/manifest.json gives https://provider.com/pub1293/
|
|
219
227
|
*/
|
|
220
228
|
public get baseURL(): string | undefined {
|
|
221
|
-
const selfLink = this.links
|
|
229
|
+
const selfLink = this.links?.items.find(
|
|
222
230
|
el => el.rels && el.rels.has('self')
|
|
223
231
|
);
|
|
224
232
|
if (selfLink) {
|
|
@@ -242,10 +250,11 @@ export class Manifest {
|
|
|
242
250
|
* Sets the URL where this [Publication]'s RWPM manifest is served.
|
|
243
251
|
*/
|
|
244
252
|
public setSelfLink(href: string): void {
|
|
245
|
-
this.links.
|
|
253
|
+
if (!this.links) (this as any).links = new Links([]);
|
|
254
|
+
this.links!.items = this.links!.items.filter(
|
|
246
255
|
x => x.rels === undefined || !x.rels?.has('self')
|
|
247
256
|
);
|
|
248
|
-
this.links
|
|
257
|
+
this.links!.items.push(
|
|
249
258
|
new Link({
|
|
250
259
|
href,
|
|
251
260
|
type: MediaType.READIUM_WEBPUB_MANIFEST.string,
|
|
@@ -14,8 +14,6 @@ import { GuidedNavigationDocument } from "./GuidedNavigation.ts";
|
|
|
14
14
|
import { MediaType, URITemplate } from "../util/index.ts";
|
|
15
15
|
import { Timeline } from './services/timeline/Timeline.ts';
|
|
16
16
|
|
|
17
|
-
export type ServiceFactory = () => null;
|
|
18
|
-
|
|
19
17
|
/** Shared model for a Readium Publication. */
|
|
20
18
|
export class Publication {
|
|
21
19
|
/** The manifest holding the publication metadata extracted from the publication file */
|
|
@@ -26,7 +24,7 @@ export class Publication {
|
|
|
26
24
|
// Shortcuts to manifest properties
|
|
27
25
|
public readonly context?: Array<string>;
|
|
28
26
|
public readonly metadata: Metadata;
|
|
29
|
-
public readonly links
|
|
27
|
+
public readonly links?: Links;
|
|
30
28
|
/** Identifies a list of resources in reading order for the publication. */
|
|
31
29
|
public readonly readingOrder: Links;
|
|
32
30
|
/** Identifies resources that are necessary for rendering the publication. */
|
|
@@ -121,7 +119,7 @@ export class Publication {
|
|
|
121
119
|
}
|
|
122
120
|
|
|
123
121
|
public async positionsFromManifest(): Promise<Locator[]> {
|
|
124
|
-
const positionListLink = this.manifest.links
|
|
122
|
+
const positionListLink = this.manifest.links?.findWithMediaType(
|
|
125
123
|
'application/vnd.readium.position-list+json'
|
|
126
124
|
);
|
|
127
125
|
if (positionListLink === undefined) return [];
|
|
@@ -152,7 +150,7 @@ export class Publication {
|
|
|
152
150
|
|
|
153
151
|
if(!guidedNavigationLink) {
|
|
154
152
|
// Still unable to find a guided navigation link, try to use the manifest's global document
|
|
155
|
-
guidedNavigationLink = this.manifest.links
|
|
153
|
+
guidedNavigationLink = this.manifest.links?.findWithMediaType(
|
|
156
154
|
'application/guided-navigation+json'
|
|
157
155
|
);
|
|
158
156
|
}
|
|
@@ -136,7 +136,7 @@ export class PublicationContentIterator extends Iterator {
|
|
|
136
136
|
|
|
137
137
|
for (const factory of this.resourceContentIteratorFactories) {
|
|
138
138
|
const res = factory(resource, locator);
|
|
139
|
-
if(res) new IndexedIterator(index, res);
|
|
139
|
+
if(res) return new IndexedIterator(index, res);
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
return null;
|
|
@@ -9,7 +9,7 @@ import { Locator } from "./Locator.ts";
|
|
|
9
9
|
export declare class Manifest {
|
|
10
10
|
readonly context?: Array<string>;
|
|
11
11
|
readonly metadata: Metadata;
|
|
12
|
-
readonly links
|
|
12
|
+
readonly links?: Links;
|
|
13
13
|
/** Identifies a list of resources in reading order for the publication. */
|
|
14
14
|
readonly readingOrder: Links;
|
|
15
15
|
/** Identifies resources that are necessary for rendering the publication. */
|
|
@@ -20,7 +20,7 @@ export declare class Manifest {
|
|
|
20
20
|
constructor(values: {
|
|
21
21
|
context?: Array<string>;
|
|
22
22
|
metadata: Metadata;
|
|
23
|
-
links
|
|
23
|
+
links?: Links;
|
|
24
24
|
readingOrder: Links;
|
|
25
25
|
resources?: Links;
|
|
26
26
|
toc?: Links;
|
|
@@ -7,7 +7,6 @@ import { PublicationCollection } from './PublicationCollection.ts';
|
|
|
7
7
|
import { Resource } from '../fetcher/Resource.ts';
|
|
8
8
|
import { GuidedNavigationDocument } from "./GuidedNavigation.ts";
|
|
9
9
|
import { Timeline } from './services/timeline/Timeline.ts';
|
|
10
|
-
export type ServiceFactory = () => null;
|
|
11
10
|
/** Shared model for a Readium Publication. */
|
|
12
11
|
export declare class Publication {
|
|
13
12
|
/** The manifest holding the publication metadata extracted from the publication file */
|
|
@@ -16,7 +15,7 @@ export declare class Publication {
|
|
|
16
15
|
private _timeline;
|
|
17
16
|
readonly context?: Array<string>;
|
|
18
17
|
readonly metadata: Metadata;
|
|
19
|
-
readonly links
|
|
18
|
+
readonly links?: Links;
|
|
20
19
|
/** Identifies a list of resources in reading order for the publication. */
|
|
21
20
|
readonly readingOrder: Links;
|
|
22
21
|
/** Identifies resources that are necessary for rendering the publication. */
|