@readium/shared 2.1.5 → 2.2.0-alpha.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/LICENSE +28 -0
- package/dist/index.js +59 -57
- package/dist/index.umd.cjs +3 -3
- package/package.json +11 -11
- package/src/fetcher/HttpFetcher.ts +2 -2
- package/src/fetcher/Resource.ts +4 -4
- package/src/publication/Manifest.ts +13 -11
- package/src/publication/html/Locations.ts +14 -0
- package/types/src/fetcher/HttpFetcher.d.ts +1 -1
- package/types/src/fetcher/Resource.d.ts +1 -1
- package/types/src/publication/Manifest.d.ts +1 -1
- package/types/src/publication/html/Locations.d.ts +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@readium/shared",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0-alpha.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Shared models to be used across other Readium projects and implementations in Typescript",
|
|
6
6
|
"author": "readium",
|
|
@@ -44,15 +44,6 @@
|
|
|
44
44
|
"engines": {
|
|
45
45
|
"node": ">=18"
|
|
46
46
|
},
|
|
47
|
-
"scripts": {
|
|
48
|
-
"dev": "vite",
|
|
49
|
-
"clean": "rimraf types dist",
|
|
50
|
-
"build": "pnpm clean && tsc && vite build",
|
|
51
|
-
"test": "jest",
|
|
52
|
-
"size": "size-limit",
|
|
53
|
-
"check-locales": "node scripts/check-locales.mjs",
|
|
54
|
-
"update-locales": "pnpm remove @edrlab/thorium-locales && pnpm add @edrlab/thorium-locales@github:edrlab/thorium-locales && pnpm check-locales"
|
|
55
|
-
},
|
|
56
47
|
"size-limit": [
|
|
57
48
|
{
|
|
58
49
|
"path": "dist/index.js",
|
|
@@ -77,5 +68,14 @@
|
|
|
77
68
|
"tslib": "^2.8.1",
|
|
78
69
|
"typescript": "^5.9.3",
|
|
79
70
|
"vite": "^7.3.1"
|
|
71
|
+
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"dev": "vite",
|
|
74
|
+
"clean": "rimraf types dist",
|
|
75
|
+
"build": "pnpm clean && tsc && vite build",
|
|
76
|
+
"test": "jest",
|
|
77
|
+
"size": "size-limit",
|
|
78
|
+
"check-locales": "node scripts/check-locales.mjs",
|
|
79
|
+
"update-locales": "pnpm remove @edrlab/thorium-locales && pnpm add @edrlab/thorium-locales@github:edrlab/thorium-locales && pnpm check-locales"
|
|
80
80
|
}
|
|
81
|
-
}
|
|
81
|
+
}
|
|
@@ -108,7 +108,7 @@ export class HttpResource implements Resource {
|
|
|
108
108
|
return await resp.text();
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
async readAsXML(): Promise<
|
|
111
|
+
async readAsXML(): Promise<Document> {
|
|
112
112
|
const resp = await this.client(this.url);
|
|
113
113
|
if (!resp.ok)
|
|
114
114
|
throw new Error(
|
|
@@ -116,7 +116,7 @@ export class HttpResource implements Resource {
|
|
|
116
116
|
); // TODO
|
|
117
117
|
return new DOMParser().parseFromString(
|
|
118
118
|
await resp.text(),
|
|
119
|
-
'application/xml'
|
|
119
|
+
this._link.mediaType.isHTML ? (this._link.mediaType.string as 'application/xhtml+xml' | 'text/html') : 'text/xml'
|
|
120
120
|
);
|
|
121
121
|
}
|
|
122
122
|
}
|
package/src/fetcher/Resource.ts
CHANGED
|
@@ -27,11 +27,11 @@ export abstract class Resource {
|
|
|
27
27
|
return JSON.parse(str);
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
|
-
readAsXML(): Promise<
|
|
31
|
-
return this.readAsString().then(str => {
|
|
30
|
+
readAsXML(): Promise<Document | undefined> {
|
|
31
|
+
return this.link().then(l => this.readAsString().then(str => {
|
|
32
32
|
if (str === undefined) return str;
|
|
33
|
-
return new DOMParser().parseFromString(str, 'text/xml');
|
|
34
|
-
});
|
|
33
|
+
return new DOMParser().parseFromString(str, l.mediaType.isHTML ? (l.mediaType.string as 'application/xhtml+xml' | 'text/html') : 'text/xml');
|
|
34
|
+
}));
|
|
35
35
|
}
|
|
36
36
|
abstract close(): void;
|
|
37
37
|
}
|
|
@@ -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;
|
|
@@ -43,7 +43,7 @@ export class Manifest {
|
|
|
43
43
|
}) {
|
|
44
44
|
this.context = values.context;
|
|
45
45
|
this.metadata = values.metadata;
|
|
46
|
-
this.links = values.links;
|
|
46
|
+
this.links = values.links || new Links([]);
|
|
47
47
|
this.readingOrder = values.readingOrder;
|
|
48
48
|
this.resources = values.resources;
|
|
49
49
|
this.toc = values.toc;
|
|
@@ -63,10 +63,6 @@ export class Manifest {
|
|
|
63
63
|
|
|
64
64
|
if (!metadata) return;
|
|
65
65
|
|
|
66
|
-
const links = Links.deserialize(json.links);
|
|
67
|
-
|
|
68
|
-
if (!links) return;
|
|
69
|
-
|
|
70
66
|
const readingOrder = Links.deserialize(
|
|
71
67
|
json.readingOrder ? json.readingOrder : json.spine
|
|
72
68
|
);
|
|
@@ -76,7 +72,7 @@ export class Manifest {
|
|
|
76
72
|
return new Manifest({
|
|
77
73
|
context: arrayfromJSONorString(json['@context']),
|
|
78
74
|
metadata,
|
|
79
|
-
links,
|
|
75
|
+
links: Links.deserialize(json.links),
|
|
80
76
|
readingOrder,
|
|
81
77
|
resources: Links.deserialize(json.resources),
|
|
82
78
|
toc: Links.deserialize(json.toc),
|
|
@@ -93,7 +89,7 @@ export class Manifest {
|
|
|
93
89
|
const json: any = {};
|
|
94
90
|
if (this.context !== undefined) json['@context'] = this.context;
|
|
95
91
|
json.metadata = this.metadata.serialize();
|
|
96
|
-
json.links = this.links.serialize();
|
|
92
|
+
if (this.links?.items.length > 0) json.links = this.links.serialize();
|
|
97
93
|
json.readingOrder = this.readingOrder.serialize();
|
|
98
94
|
if (this.resources) json.resources = this.resources.serialize();
|
|
99
95
|
if (this.toc) json.toc = this.toc.serialize();
|
|
@@ -108,7 +104,9 @@ export class Manifest {
|
|
|
108
104
|
if (this.resources) {
|
|
109
105
|
links.push(this.resources);
|
|
110
106
|
}
|
|
111
|
-
|
|
107
|
+
if(this.links) {
|
|
108
|
+
links.push(this.links);
|
|
109
|
+
}
|
|
112
110
|
|
|
113
111
|
let result: Link | undefined;
|
|
114
112
|
|
|
@@ -129,7 +127,9 @@ export class Manifest {
|
|
|
129
127
|
if (this.resources) {
|
|
130
128
|
result.push(this.resources.filterByRel(rel));
|
|
131
129
|
}
|
|
132
|
-
|
|
130
|
+
if(this.links) {
|
|
131
|
+
result.push(this.links.filterByRel(rel));
|
|
132
|
+
}
|
|
133
133
|
|
|
134
134
|
return result.reduce((acc, val) => acc.concat(val), []);
|
|
135
135
|
}
|
|
@@ -197,7 +197,9 @@ export class Manifest {
|
|
|
197
197
|
if (this.resources) {
|
|
198
198
|
links.push(this.resources);
|
|
199
199
|
}
|
|
200
|
-
|
|
200
|
+
if(this.links) {
|
|
201
|
+
links.push(this.links);
|
|
202
|
+
}
|
|
201
203
|
|
|
202
204
|
const link = find(links);
|
|
203
205
|
|
|
@@ -53,6 +53,13 @@ declare module '../Locator' {
|
|
|
53
53
|
* https://www.w3.org/TR/media-frags/
|
|
54
54
|
*/
|
|
55
55
|
space(): [number, number, number, number] | undefined;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Text fragments, used by browsers to jump to/highlight text.
|
|
59
|
+
*
|
|
60
|
+
* https://developer.mozilla.org/en-US/docs/Web/URI/Fragment/Text_fragments
|
|
61
|
+
*/
|
|
62
|
+
text(): string | undefined;
|
|
56
63
|
}
|
|
57
64
|
}
|
|
58
65
|
|
|
@@ -126,4 +133,11 @@ LocatorLocations.prototype.space = function(): [number, number, number, number]
|
|
|
126
133
|
if(xywh.length !== 4) return; // Must have four parts
|
|
127
134
|
if(xywh.some(isNaN)) return; // All parts must be numbers
|
|
128
135
|
return xywh as [number, number, number, number];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
LocatorLocations.prototype.text = function(): string | undefined {
|
|
139
|
+
const fp = this.fragmentParameters();
|
|
140
|
+
console.log(fp);
|
|
141
|
+
// :~:
|
|
142
|
+
return undefined;
|
|
129
143
|
}
|
|
@@ -10,6 +10,6 @@ export declare abstract class Resource {
|
|
|
10
10
|
abstract read(range?: NumberRange): Promise<Uint8Array | undefined>;
|
|
11
11
|
readAsString(): Promise<string | undefined>;
|
|
12
12
|
readAsJSON(): Promise<unknown | undefined>;
|
|
13
|
-
readAsXML(): Promise<
|
|
13
|
+
readAsXML(): Promise<Document | undefined>;
|
|
14
14
|
abstract close(): void;
|
|
15
15
|
}
|
|
@@ -41,5 +41,11 @@ declare module '../Locator' {
|
|
|
41
41
|
* https://www.w3.org/TR/media-frags/
|
|
42
42
|
*/
|
|
43
43
|
space(): [number, number, number, number] | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Text fragments, used by browsers to jump to/highlight text.
|
|
46
|
+
*
|
|
47
|
+
* https://developer.mozilla.org/en-US/docs/Web/URI/Fragment/Text_fragments
|
|
48
|
+
*/
|
|
49
|
+
text(): string | undefined;
|
|
44
50
|
}
|
|
45
51
|
}
|