@readium/shared 2.1.5 → 2.2.0-alpha.1
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 +6 -2
- 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/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/html/Locations.d.ts +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@readium/shared",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.0-alpha.1",
|
|
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
|
}
|
|
@@ -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
|
}
|