@readium/shared 2.2.0-alpha.1 → 2.2.0-beta.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/dist/index.js +140 -118
- 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/Publication.ts +31 -0
- package/src/publication/html/Locations.ts +0 -14
- package/src/util/mediatype/MediaType.ts +4 -0
- package/types/src/fetcher/HttpFetcher.d.ts +1 -1
- package/types/src/fetcher/Resource.d.ts +1 -1
- package/types/src/publication/Publication.d.ts +6 -0
- package/types/src/publication/html/Locations.d.ts +0 -6
- package/types/src/util/mediatype/MediaType.d.ts +1 -0
- package/LICENSE +0 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@readium/shared",
|
|
3
|
-
"version": "2.2.0-
|
|
3
|
+
"version": "2.2.0-beta.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,6 +44,15 @@
|
|
|
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
|
+
},
|
|
47
56
|
"size-limit": [
|
|
48
57
|
{
|
|
49
58
|
"path": "dist/index.js",
|
|
@@ -68,14 +77,5 @@
|
|
|
68
77
|
"tslib": "^2.8.1",
|
|
69
78
|
"typescript": "^5.9.3",
|
|
70
79
|
"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<XMLDocument> {
|
|
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
|
-
|
|
119
|
+
'application/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.
|
|
30
|
+
readAsXML(): Promise<XMLDocument | undefined> {
|
|
31
|
+
return this.readAsString().then(str => {
|
|
32
32
|
if (str === undefined) return str;
|
|
33
|
-
return new DOMParser().parseFromString(str,
|
|
34
|
-
})
|
|
33
|
+
return new DOMParser().parseFromString(str, 'text/xml');
|
|
34
|
+
});
|
|
35
35
|
}
|
|
36
36
|
abstract close(): void;
|
|
37
37
|
}
|
|
@@ -12,6 +12,7 @@ import { PublicationCollection } from './PublicationCollection';
|
|
|
12
12
|
import { Resource } from '../fetcher/Resource';
|
|
13
13
|
import { GuidedNavigationDocument } from "./GuidedNavigation";
|
|
14
14
|
import { URITemplate } from "../util";
|
|
15
|
+
import { MediaType } from "../util/mediatype/MediaType";
|
|
15
16
|
|
|
16
17
|
export type ServiceFactory = () => null;
|
|
17
18
|
|
|
@@ -79,6 +80,36 @@ export class Publication {
|
|
|
79
80
|
return this.manifest.linkWithRel(rel);
|
|
80
81
|
}
|
|
81
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Gets the cover image for the publication.
|
|
85
|
+
* First looks for rel='cover' in links/resources/readingOrder,
|
|
86
|
+
* then falls back to any image (JPEG, PNG, GIF, AVIF, SVG) as bitmap fallback.
|
|
87
|
+
*/
|
|
88
|
+
public getCover(): Link | undefined {
|
|
89
|
+
const locations = [
|
|
90
|
+
this.links,
|
|
91
|
+
this.resources,
|
|
92
|
+
this.readingOrder
|
|
93
|
+
].filter(Boolean) as Links[];
|
|
94
|
+
|
|
95
|
+
// First, look for explicit cover relationship
|
|
96
|
+
for (const location of locations) {
|
|
97
|
+
const cover = location.items.find(link => link.rels?.has('cover'));
|
|
98
|
+
if (cover) return cover;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Fallback to any image (including SVG which is not bitmap)
|
|
102
|
+
for (const location of locations) {
|
|
103
|
+
const image = location.items.find(link =>
|
|
104
|
+
link.mediaType.isBitmap ||
|
|
105
|
+
link.mediaType.matches(MediaType.SVG)
|
|
106
|
+
);
|
|
107
|
+
if (image) return image;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
|
|
82
113
|
public async positionsFromManifest(): Promise<Locator[]> {
|
|
83
114
|
const positionListLink = this.manifest.links.findWithMediaType(
|
|
84
115
|
'application/vnd.readium.position-list+json'
|
|
@@ -53,13 +53,6 @@ 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;
|
|
63
56
|
}
|
|
64
57
|
}
|
|
65
58
|
|
|
@@ -133,11 +126,4 @@ LocatorLocations.prototype.space = function(): [number, number, number, number]
|
|
|
133
126
|
if(xywh.length !== 4) return; // Must have four parts
|
|
134
127
|
if(xywh.some(isNaN)) return; // All parts must be numbers
|
|
135
128
|
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;
|
|
143
129
|
}
|
|
@@ -224,6 +224,7 @@ export class MediaType {
|
|
|
224
224
|
/** Returns whether this media type is of a bitmap image, so excluding vectorial formats. */
|
|
225
225
|
public get isBitmap(): boolean {
|
|
226
226
|
return this.matchesAny(
|
|
227
|
+
MediaType.AVIF,
|
|
227
228
|
MediaType.BMP,
|
|
228
229
|
MediaType.GIF,
|
|
229
230
|
MediaType.JPEG,
|
|
@@ -292,6 +293,9 @@ export class MediaType {
|
|
|
292
293
|
fileExtension: 'avi',
|
|
293
294
|
});
|
|
294
295
|
}
|
|
296
|
+
public static get AVIF(): MediaType {
|
|
297
|
+
return MediaType.parse({ mediaType: 'image/avif', fileExtension: 'avif' });
|
|
298
|
+
}
|
|
295
299
|
public static get BINARY(): MediaType {
|
|
296
300
|
return MediaType.parse({ mediaType: 'application/octet-stream' });
|
|
297
301
|
}
|
|
@@ -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<XMLDocument | undefined>;
|
|
14
14
|
abstract close(): void;
|
|
15
15
|
}
|
|
@@ -44,6 +44,12 @@ export declare class Publication {
|
|
|
44
44
|
* Finds the first [Link] having the given [rel] in the publications's links.
|
|
45
45
|
*/
|
|
46
46
|
linkWithRel(rel: string): Link | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Gets the cover image for the publication.
|
|
49
|
+
* First looks for rel='cover' in links/resources/readingOrder,
|
|
50
|
+
* then falls back to any image (JPEG, PNG, GIF, AVIF, SVG) as bitmap fallback.
|
|
51
|
+
*/
|
|
52
|
+
getCover(): Link | undefined;
|
|
47
53
|
positionsFromManifest(): Promise<Locator[]>;
|
|
48
54
|
guideForLink(link: Link): Promise<GuidedNavigationDocument | undefined>;
|
|
49
55
|
/**
|
|
@@ -41,11 +41,5 @@ 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;
|
|
50
44
|
}
|
|
51
45
|
}
|
|
@@ -89,6 +89,7 @@ export declare class MediaType {
|
|
|
89
89
|
static get ACSM(): MediaType;
|
|
90
90
|
static get AIFF(): MediaType;
|
|
91
91
|
static get AVI(): MediaType;
|
|
92
|
+
static get AVIF(): MediaType;
|
|
92
93
|
static get BINARY(): MediaType;
|
|
93
94
|
static get BMP(): MediaType;
|
|
94
95
|
static get CBZ(): MediaType;
|
package/LICENSE
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
BSD 3-Clause License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022, Readium Foundation
|
|
4
|
-
|
|
5
|
-
Redistribution and use in source and binary forms, with or without
|
|
6
|
-
modification, are permitted provided that the following conditions are met:
|
|
7
|
-
|
|
8
|
-
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
-
list of conditions and the following disclaimer.
|
|
10
|
-
|
|
11
|
-
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
-
this list of conditions and the following disclaimer in the documentation
|
|
13
|
-
and/or other materials provided with the distribution.
|
|
14
|
-
|
|
15
|
-
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
-
contributors may be used to endorse or promote products derived from
|
|
17
|
-
this software without specific prior written permission.
|
|
18
|
-
|
|
19
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|