@readium/navigator 2.3.0 → 2.4.0-alpha.0
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 +227 -221
- package/dist/index.umd.cjs +11 -11
- package/package.json +10 -10
- package/src/divina/DivinaNavigator.ts +0 -0
- package/src/divina/index.ts +0 -0
- package/src/epub/frame/FrameBlobBuilder.ts +15 -14
- package/types/src/divina/DivinaNavigator.d.ts +0 -0
- package/types/src/divina/index.d.ts +0 -0
- package/types/src/epub/frame/FrameBlobBuilder.d.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@readium/navigator",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0-alpha.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Next generation SDK for publications in Web Apps",
|
|
6
6
|
"author": "readium",
|
|
@@ -44,15 +44,8 @@
|
|
|
44
44
|
"engines": {
|
|
45
45
|
"node": ">=18"
|
|
46
46
|
},
|
|
47
|
-
"scripts": {
|
|
48
|
-
"clean": "rimraf types dist",
|
|
49
|
-
"build": "pnpm clean && node scripts/generate-css-selector.js && tsc && vite build",
|
|
50
|
-
"generate:css-selector": "node scripts/generate-css-selector.js"
|
|
51
|
-
},
|
|
52
47
|
"devDependencies": {
|
|
53
48
|
"@readium/css": "^2.0.0",
|
|
54
|
-
"@readium/navigator-html-injectables": "workspace:*",
|
|
55
|
-
"@readium/shared": "workspace:*",
|
|
56
49
|
"@types/path-browserify": "^1.0.3",
|
|
57
50
|
"css-selector-generator": "^3.8.0",
|
|
58
51
|
"path-browserify": "^1.0.1",
|
|
@@ -61,6 +54,13 @@
|
|
|
61
54
|
"typescript": "^5.9.3",
|
|
62
55
|
"typescript-plugin-css-modules": "^5.2.0",
|
|
63
56
|
"user-agent-data-types": "^0.4.2",
|
|
64
|
-
"vite": "^7.3.1"
|
|
57
|
+
"vite": "^7.3.1",
|
|
58
|
+
"@readium/shared": "2.1.5",
|
|
59
|
+
"@readium/navigator-html-injectables": "2.3.0"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"clean": "rimraf types dist",
|
|
63
|
+
"build": "pnpm clean && node scripts/generate-css-selector.js && tsc && vite build",
|
|
64
|
+
"generate:css-selector": "node scripts/generate-css-selector.js"
|
|
65
65
|
}
|
|
66
|
-
}
|
|
66
|
+
}
|
|
File without changes
|
|
File without changes
|
|
@@ -21,24 +21,19 @@ const csp = (domains: string[]) => {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export default class FrameBlobBuider {
|
|
24
|
-
private readonly item: Link;
|
|
25
|
-
private readonly burl: string;
|
|
26
|
-
private readonly pub: Publication;
|
|
27
24
|
private readonly cssProperties?: { [key: string]: string };
|
|
28
25
|
private readonly injector: Injector | null = null;
|
|
29
26
|
|
|
30
27
|
constructor(
|
|
31
|
-
pub: Publication,
|
|
32
|
-
baseURL: string,
|
|
33
|
-
item: Link,
|
|
28
|
+
private readonly pub: Publication,
|
|
29
|
+
private readonly baseURL: string,
|
|
30
|
+
private readonly item: Link,
|
|
34
31
|
options: {
|
|
35
32
|
cssProperties?: { [key: string]: string };
|
|
36
33
|
injector?: Injector | null;
|
|
37
34
|
}
|
|
38
35
|
) {
|
|
39
|
-
this.pub = pub;
|
|
40
36
|
this.item = item;
|
|
41
|
-
this.burl = item.toURL(baseURL) || "";
|
|
42
37
|
this.cssProperties = options.cssProperties;
|
|
43
38
|
this.injector = options.injector ?? null;
|
|
44
39
|
}
|
|
@@ -46,7 +41,7 @@ export default class FrameBlobBuider {
|
|
|
46
41
|
public async build(fxl = false): Promise<string> {
|
|
47
42
|
if(!this.item.mediaType.isHTML) {
|
|
48
43
|
if(this.item.mediaType.isBitmap || this.item.mediaType.equals(MediaType.SVG)) {
|
|
49
|
-
return this.buildImageFrame();
|
|
44
|
+
return await this.buildImageFrame();
|
|
50
45
|
} else
|
|
51
46
|
throw Error("Unsupported frame mediatype " + this.item.mediaType.string);
|
|
52
47
|
} else {
|
|
@@ -75,18 +70,20 @@ export default class FrameBlobBuider {
|
|
|
75
70
|
await this.injector.injectForDocument(doc, this.item);
|
|
76
71
|
}
|
|
77
72
|
|
|
78
|
-
return this.finalizeDOM(doc, this.pub.baseURL, this.
|
|
73
|
+
return this.finalizeDOM(doc, this.pub.baseURL, (await this.pub.get(this.item).link()).toURL(this.baseURL) || "", this.item.mediaType, fxl, this.cssProperties);
|
|
79
74
|
}
|
|
80
75
|
|
|
81
|
-
private buildImageFrame(): string {
|
|
76
|
+
private async buildImageFrame(): Promise<string> {
|
|
77
|
+
const burl = (await this.pub.get(this.item).link()).toURL(this.baseURL) || ""
|
|
78
|
+
|
|
82
79
|
// Rudimentary image display
|
|
83
80
|
const doc = document.implementation.createHTMLDocument(this.item.title || this.item.href);
|
|
84
81
|
const simg = document.createElement("img");
|
|
85
|
-
simg.src =
|
|
82
|
+
simg.src = burl || "";
|
|
86
83
|
simg.alt = this.item.title || "";
|
|
87
84
|
simg.decoding = "async";
|
|
88
85
|
doc.body.appendChild(simg);
|
|
89
|
-
return this.finalizeDOM(doc, this.pub.baseURL,
|
|
86
|
+
return this.finalizeDOM(doc, this.pub.baseURL, burl, this.item.mediaType, true);
|
|
90
87
|
}
|
|
91
88
|
|
|
92
89
|
private setProperties(cssProperties: { [key: string]: string }, doc: Document) {
|
|
@@ -101,7 +98,10 @@ export default class FrameBlobBuider {
|
|
|
101
98
|
|
|
102
99
|
// Get allowed domains from injector if it exists
|
|
103
100
|
const allowedDomains = this.injector?.getAllowedDomains?.() || [];
|
|
104
|
-
|
|
101
|
+
|
|
102
|
+
// Remove query from root if present, as CSP doesn't allow them
|
|
103
|
+
root = root?.split("?")[0];
|
|
104
|
+
|
|
105
105
|
// Always include the root domain if provided
|
|
106
106
|
const domains = [...new Set([
|
|
107
107
|
...(root ? [root] : []),
|
|
@@ -124,6 +124,7 @@ export default class FrameBlobBuider {
|
|
|
124
124
|
// loaded in parallel, greatly increasing overall speed.
|
|
125
125
|
doc.body.querySelectorAll("img").forEach((img) => {
|
|
126
126
|
img.setAttribute("fetchpriority", "high");
|
|
127
|
+
img.setAttribute("referrerpolicy", "origin");
|
|
127
128
|
});
|
|
128
129
|
|
|
129
130
|
// We need to ensure that lang is set on the root element
|
|
File without changes
|
|
File without changes
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Link, Publication } from "@readium/shared";
|
|
2
2
|
import { Injector } from "../../injection/Injector";
|
|
3
3
|
export default class FrameBlobBuider {
|
|
4
|
-
private readonly item;
|
|
5
|
-
private readonly burl;
|
|
6
4
|
private readonly pub;
|
|
5
|
+
private readonly baseURL;
|
|
6
|
+
private readonly item;
|
|
7
7
|
private readonly cssProperties?;
|
|
8
8
|
private readonly injector;
|
|
9
9
|
constructor(pub: Publication, baseURL: string, item: Link, options: {
|