@readium/navigator 2.4.0-alpha.6 → 2.4.0-alpha.8

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.6",
3
+ "version": "2.4.0-alpha.8",
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/shared": "2.1.5",
59
- "@readium/navigator-html-injectables": "2.3.0"
58
+ "@readium/navigator-html-injectables": "2.3.0",
59
+ "@readium/shared": "2.1.5"
60
60
  },
61
61
  "scripts": {
62
62
  "clean": "rimraf types dist",
@@ -76,14 +76,8 @@ export default class FrameBlobBuilder {
76
76
 
77
77
  // Load the HTML resource
78
78
  const link = await this.currentResource.link();
79
- const txt = await this.currentResource.readAsString();
80
- if(!txt) throw new Error(`Failed reading item ${link.href}`);
81
-
82
- const doc = new DOMParser().parseFromString(
83
- txt,
84
- link.mediaType.string as DOMParserSupportedType
85
- );
86
-
79
+ const doc = await this.currentResource.readAsXML() as HTMLDocument;
80
+ if(!doc) throw new Error(`Failed reading item ${link.href}`);
87
81
  const perror = doc.querySelector("parsererror");
88
82
  if (perror) {
89
83
  const details = perror.querySelector("div");
@@ -21,6 +21,7 @@ export class FXLFrameManager {
21
21
  public debugHref: string;
22
22
  private loadPromise: Promise<Window> | undefined;
23
23
  private showPromise: Promise<void> | undefined;
24
+ private viewportSize: { width: number, height: number } | undefined = undefined;
24
25
 
25
26
  constructor(
26
27
  peripherals: FXLPeripherals,
@@ -107,6 +108,7 @@ export class FXLFrameManager {
107
108
 
108
109
  // Parses the page size from the viewport meta tag of the loaded resource.
109
110
  loadPageSize(): { width: number, height: number } {
111
+ if(this.viewportSize) return this.viewportSize;
110
112
  const wnd = this.frame.contentWindow!;
111
113
 
112
114
  // Try to get the page size from the viewport meta tag
@@ -123,8 +125,10 @@ export class FXLFrameManager {
123
125
  else if(match[1] === "height")
124
126
  height = Number.parseFloat(match[2]);
125
127
  }
126
- if(width > 0 && height > 0)
127
- return { width, height };
128
+ if(width > 0 && height > 0) {
129
+ this.viewportSize = { width, height };
130
+ return this.viewportSize;
131
+ }
128
132
  }
129
133
 
130
134
  // Otherwise get it from the size of the loaded content
@@ -91,7 +91,6 @@ export class FXLFramePoolManager {
91
91
  // Create <iframe>
92
92
  const fm = new FXLFrameManager(this.peripherals, this.pub.metadata.effectiveReadingProgression, link.href, this.contentProtectionConfig, this.keyboardPeripheralsConfig);
93
93
 
94
- // this.pages.push(fm);
95
94
  this.pool.set(link.href, fm);
96
95
  fm.width = 100 / this.length * (link.properties?.otherProperties["orientation"] === Orientation.landscape || link.properties?.otherProperties["addBlank"] ? this.perPage : 1);
97
96
  fm.height = this.height;
@@ -137,15 +136,18 @@ export class FXLFramePoolManager {
137
136
 
138
137
  clearTimeout(this.resizeTimeout);
139
138
  this.resizeTimeout = window.setTimeout(() => {
140
- // TODO optimize this expensive set of loops and operations
139
+ const baseWidthFactor = 100 / this.length;
140
+ const itemLookup = new Map(this.pub.readingOrder.items.map(item => [item.href, item]));
141
141
  this.pool.forEach((frm, linkHref) => {
142
- let i = this.pub.readingOrder.items.findIndex(l => l.href === linkHref);
143
- const link = this.pub.readingOrder.items[i];
144
- frm.width = 100 / this.length * (link.properties?.otherProperties["orientation"] === Orientation.landscape || link.properties?.otherProperties["addBlank"] ? this.perPage : 1);
145
- frm.height = this.height;
146
- if(!frm.loaded) return;
147
- const spread = this.spreader.findByLink(link)!;
148
- frm.update(this.spreadPosition(spread, link));
142
+ const link = itemLookup.get(linkHref);
143
+ if(!link) return;
144
+ requestAnimationFrame(() => {
145
+ frm.width = baseWidthFactor * (link.properties?.otherProperties["orientation"] === Orientation.landscape || link.properties?.otherProperties["addBlank"] ? this.perPage : 1);
146
+ frm.height = this.height;
147
+ if(!frm.loaded) return;
148
+ const spread = this.spreader.findByLink(link)!;
149
+ frm.update(this.spreadPosition(spread, link));
150
+ });
149
151
  });
150
152
  }, RESIZE_UPDATE_TIMEOUT);
151
153
  }
@@ -17,6 +17,7 @@ export declare class FXLFrameManager {
17
17
  debugHref: string;
18
18
  private loadPromise;
19
19
  private showPromise;
20
+ private viewportSize;
20
21
  constructor(peripherals: FXLPeripherals, direction: ReadingProgression, debugHref: string, contentProtectionConfig?: IContentProtectionConfig, keyboardPeripheralsConfig?: IKeyboardPeripheralsConfig);
21
22
  load(modules: ModuleName[], source: string): Promise<Window>;
22
23
  loadPageSize(): {