@readium/navigator 2.4.0-alpha.1 → 2.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readium/navigator",
3
- "version": "2.4.0-alpha.1",
3
+ "version": "2.4.0-alpha.2",
4
4
  "type": "module",
5
5
  "description": "Next generation SDK for publications in Web Apps",
6
6
  "author": "readium",
@@ -55,8 +55,8 @@
55
55
  "typescript-plugin-css-modules": "^5.2.0",
56
56
  "user-agent-data-types": "^0.4.2",
57
57
  "vite": "^7.3.1",
58
- "@readium/navigator-html-injectables": "2.3.0",
59
- "@readium/shared": "2.1.5"
58
+ "@readium/shared": "2.1.5",
59
+ "@readium/navigator-html-injectables": "2.3.0"
60
60
  },
61
61
  "scripts": {
62
62
  "clean": "rimraf types dist",
@@ -39,11 +39,12 @@ export default class FrameBlobBuider {
39
39
  }
40
40
 
41
41
  public async build(fxl = false): Promise<string> {
42
- if(!this.item.mediaType.isHTML) {
43
- if(this.item.mediaType.isBitmap || this.item.mediaType.equals(MediaType.SVG)) {
42
+ const link = await this.pub.get(this.item).link();
43
+ if(!link.mediaType.isHTML) {
44
+ if(link.mediaType.isBitmap || link.mediaType.equals(MediaType.SVG)) {
44
45
  return await this.buildImageFrame();
45
46
  } else
46
- throw Error("Unsupported frame mediatype " + this.item.mediaType.string);
47
+ throw Error("Unsupported frame mediatype " + link.mediaType.string);
47
48
  } else {
48
49
  return await this.buildHtmlFrame(fxl);
49
50
  }
@@ -51,26 +52,28 @@ export default class FrameBlobBuider {
51
52
 
52
53
  private async buildHtmlFrame(fxl = false): Promise<string> {
53
54
  // Load the HTML resource
54
- const txt = await this.pub.get(this.item).readAsString();
55
- if(!txt) throw new Error(`Failed reading item ${this.item.href}`);
55
+ const resource = this.pub.get(this.item);
56
+ const link = await resource.link();
57
+ const txt = await resource.readAsString();
58
+ if(!txt) throw new Error(`Failed reading item ${link.href}`);
56
59
 
57
60
  const doc = new DOMParser().parseFromString(
58
61
  txt,
59
- this.item.mediaType.string as DOMParserSupportedType
62
+ link.mediaType.string as DOMParserSupportedType
60
63
  );
61
64
 
62
65
  const perror = doc.querySelector("parsererror");
63
66
  if (perror) {
64
67
  const details = perror.querySelector("div");
65
- throw new Error(`Failed parsing item ${this.item.href}: ${details?.textContent || perror.textContent}`);
68
+ throw new Error(`Failed parsing item ${link.href}: ${details?.textContent || perror.textContent}`);
66
69
  }
67
70
 
68
71
  // Apply resource injections if injection service is provided
69
72
  if (this.injector) {
70
- await this.injector.injectForDocument(doc, this.item);
73
+ await this.injector.injectForDocument(doc, link);
71
74
  }
72
75
 
73
- return this.finalizeDOM(doc, this.pub.baseURL, (await this.pub.get(this.item).link()).toURL(this.baseURL) || "", this.item.mediaType, fxl, this.cssProperties);
76
+ return this.finalizeDOM(doc, this.pub.baseURL, link.toURL(this.baseURL) || "", link.mediaType, fxl, this.cssProperties);
74
77
  }
75
78
 
76
79
  private async buildImageFrame(): Promise<string> {
@@ -78,7 +81,7 @@ export default class FrameBlobBuider {
78
81
  const burl = link.toURL(this.baseURL) || ""
79
82
 
80
83
  // Rudimentary image display in an HTML doc
81
- const doc = document.implementation.createHTMLDocument(this.item.title || this.item.href);
84
+ const doc = document.implementation.createHTMLDocument(link.title || link.href);
82
85
 
83
86
  // Add viewport if available
84
87
  if((link?.height || 0) > 0 && (link?.width || 0) > 0) {
@@ -91,13 +94,18 @@ export default class FrameBlobBuider {
91
94
 
92
95
  const simg = document.createElement("img");
93
96
  simg.src = burl || "";
94
- simg.alt = this.item.title || "";
97
+ simg.alt = link.title || "";
95
98
  simg.decoding = "async";
96
99
  doc.body.appendChild(simg);
97
100
 
98
101
  // Apply resource injections if injection service is provided
99
102
  if (this.injector) {
100
- await this.injector.injectForDocument(doc, this.item);
103
+ await this.injector.injectForDocument(doc, new Link({
104
+ // Temporary solution to address injector only expecting (X)HTML
105
+ // documents for injection, which we are technically providing
106
+ href: "readium-image-frame.xhtml",
107
+ type: MediaType.XHTML.string
108
+ }));
101
109
  }
102
110
 
103
111
  // Add image style
@@ -108,7 +116,7 @@ export default class FrameBlobBuider {
108
116
  img { margin: 0; padding: 0; border: 0; }`;
109
117
  doc.head.appendChild(sstyle);
110
118
 
111
- return this.finalizeDOM(doc, this.pub.baseURL, burl, this.item.mediaType, true);
119
+ return this.finalizeDOM(doc, this.pub.baseURL, burl, link.mediaType, true);
112
120
  }
113
121
 
114
122
  private setProperties(cssProperties: { [key: string]: string }, doc: Document) {