@readium/navigator-html-injectables 1.2.0 → 1.3.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/dist/index.js +1497 -1434
- package/dist/index.umd.cjs +15 -15
- package/package.json +2 -2
- package/src/helpers/dom.ts +8 -0
- package/src/helpers/locator.ts +55 -53
- package/src/modules/index.ts +1 -0
- package/src/modules/setup/FixedSetup.ts +2 -0
- package/src/modules/setup/Setup.ts +30 -1
- package/src/modules/snapper/ColumnSnapper.ts +3 -1
- package/src/modules/snapper/ScrollSnapper.ts +13 -8
- package/types/src/helpers/dom.d.ts +9 -0
- package/types/src/modules/index.d.ts +1 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Comms } from "../../comms/comms";
|
|
2
|
-
import { ReadiumWindow } from "../../helpers/dom";
|
|
2
|
+
import { ReadiumWindow, EPUBReadingSystem } from "../../helpers/dom";
|
|
3
3
|
import { Module } from "../Module";
|
|
4
4
|
import { ModuleName } from "../ModuleLibrary";
|
|
5
5
|
|
|
@@ -72,6 +72,35 @@ export abstract class Setup extends Module {
|
|
|
72
72
|
false
|
|
73
73
|
);
|
|
74
74
|
|
|
75
|
+
// Add reading system property to navigator
|
|
76
|
+
Reflect.defineProperty(wnd.navigator, "epubReadingSystem", {
|
|
77
|
+
value: {
|
|
78
|
+
name: "readium-ts-toolkit",
|
|
79
|
+
version: import.meta.env.PACKAGE_VERSION,
|
|
80
|
+
hasFeature: (feature: string, _version = "") => {
|
|
81
|
+
switch (feature) {
|
|
82
|
+
case "dom-manipulation":
|
|
83
|
+
return true;
|
|
84
|
+
case "layout-changes":
|
|
85
|
+
return true;
|
|
86
|
+
case "touch-events":
|
|
87
|
+
return true;
|
|
88
|
+
case "mouse-events":
|
|
89
|
+
return true;
|
|
90
|
+
case "keyboard-events":
|
|
91
|
+
return true;
|
|
92
|
+
case "spine-scripting":
|
|
93
|
+
return true;
|
|
94
|
+
case "embedded-web-content":
|
|
95
|
+
return true;
|
|
96
|
+
default:
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
} as EPUBReadingSystem,
|
|
101
|
+
writable: false
|
|
102
|
+
});
|
|
103
|
+
|
|
75
104
|
// Add all currently active animations and cancel them
|
|
76
105
|
if("getAnimations" in wnd.document) {
|
|
77
106
|
wnd.document.getAnimations().forEach((a) => {
|
|
@@ -40,7 +40,7 @@ export class ColumnSnapper extends Snapper {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
reportProgress() {
|
|
43
|
-
this.comms.send("progress", this.wnd.scrollX / this.cachedScrollWidth);
|
|
43
|
+
this.comms.send("progress", { progress: this.wnd.scrollX / this.cachedScrollWidth, reference: this.wnd.innerWidth / this.doc().scrollWidth });
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
private shakeTimeout = 0;
|
|
@@ -229,6 +229,8 @@ export class ColumnSnapper extends Snapper {
|
|
|
229
229
|
this.comms = comms;
|
|
230
230
|
if(!super.mount(wnd, comms)) return false;
|
|
231
231
|
|
|
232
|
+
wnd.navigator.epubReadingSystem.layoutStyle = "paginated";
|
|
233
|
+
|
|
232
234
|
// Add styling to hide the scrollbar
|
|
233
235
|
const d = wnd.document.createElement("style");
|
|
234
236
|
d.dataset.readium = "true";
|
|
@@ -30,14 +30,16 @@ export class ScrollSnapper extends Snapper {
|
|
|
30
30
|
customElements.define("anchor-observer", AnchorObserver);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
private reportProgress(progress: number) {
|
|
34
|
-
this.comms.send("progress",
|
|
33
|
+
private reportProgress(data: { progress: number, reference: number }) {
|
|
34
|
+
this.comms.send("progress", data);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
mount(wnd: ReadiumWindow, comms: Comms): boolean {
|
|
38
38
|
this.wnd = wnd;
|
|
39
39
|
this.comms = comms;
|
|
40
40
|
|
|
41
|
+
wnd.navigator.epubReadingSystem.layoutStyle = "scrolling";
|
|
42
|
+
|
|
41
43
|
// Add styling to hide the scrollbar
|
|
42
44
|
const style = wnd.document.createElement("style");
|
|
43
45
|
style.dataset.readium = "true";
|
|
@@ -66,7 +68,7 @@ export class ScrollSnapper extends Snapper {
|
|
|
66
68
|
|
|
67
69
|
this.wnd.requestAnimationFrame(() => {
|
|
68
70
|
this.doc().scrollTop = this.doc().offsetHeight * position;
|
|
69
|
-
this.reportProgress(position);
|
|
71
|
+
this.reportProgress({ progress: position, reference: this.wnd.innerHeight / this.doc().scrollHeight });
|
|
70
72
|
deselect(this.wnd);
|
|
71
73
|
ack(true);
|
|
72
74
|
});
|
|
@@ -80,7 +82,8 @@ export class ScrollSnapper extends Snapper {
|
|
|
80
82
|
}
|
|
81
83
|
this.wnd.requestAnimationFrame(() => {
|
|
82
84
|
this.doc().scrollTop = element.getBoundingClientRect().top + wnd.scrollY - wnd.innerHeight / 2;
|
|
83
|
-
this.
|
|
85
|
+
const progress = this.doc().scrollTop / this.doc().offsetHeight;
|
|
86
|
+
this.reportProgress({ progress: progress, reference: this.wnd.innerHeight / this.doc().scrollHeight });
|
|
84
87
|
deselect(this.wnd);
|
|
85
88
|
ack(true);
|
|
86
89
|
});
|
|
@@ -111,7 +114,8 @@ export class ScrollSnapper extends Snapper {
|
|
|
111
114
|
}
|
|
112
115
|
this.wnd.requestAnimationFrame(() => {
|
|
113
116
|
this.doc().scrollTop = r.getBoundingClientRect().top + wnd.scrollY - wnd.innerHeight / 2;
|
|
114
|
-
this.
|
|
117
|
+
const progress = this.doc().scrollTop / this.doc().offsetHeight
|
|
118
|
+
this.reportProgress({ progress: progress, reference: this.wnd.innerHeight / this.doc().scrollHeight });
|
|
115
119
|
deselect(this.wnd);
|
|
116
120
|
ack(true);
|
|
117
121
|
});
|
|
@@ -120,14 +124,14 @@ export class ScrollSnapper extends Snapper {
|
|
|
120
124
|
comms.register("go_start", ScrollSnapper.moduleName, (_, ack) => {
|
|
121
125
|
if (this.doc().scrollTop === 0) return ack(false);
|
|
122
126
|
this.doc().scrollTop = 0;
|
|
123
|
-
this.reportProgress(0);
|
|
127
|
+
this.reportProgress({ progress: 0, reference: this.wnd.innerHeight / this.doc().scrollHeight });
|
|
124
128
|
ack(true);
|
|
125
129
|
});
|
|
126
130
|
|
|
127
131
|
comms.register("go_end", ScrollSnapper.moduleName, (_, ack) => {
|
|
128
132
|
if (this.doc().scrollTop === 0) return ack(false);
|
|
129
133
|
this.doc().scrollTop = 0;
|
|
130
|
-
this.reportProgress(0);
|
|
134
|
+
this.reportProgress({ progress: 0, reference: this.wnd.innerHeight / this.doc().scrollHeight });
|
|
131
135
|
ack(true);
|
|
132
136
|
})
|
|
133
137
|
|
|
@@ -142,7 +146,8 @@ export class ScrollSnapper extends Snapper {
|
|
|
142
146
|
], ScrollSnapper.moduleName, (_, ack) => ack(false));
|
|
143
147
|
|
|
144
148
|
comms.register("focus", ScrollSnapper.moduleName, (_, ack) => {
|
|
145
|
-
this.
|
|
149
|
+
const progress = this.doc().scrollTop / this.doc().offsetHeight
|
|
150
|
+
this.reportProgress({ progress: progress, reference: this.wnd.innerHeight / this.doc().scrollHeight });
|
|
146
151
|
ack(true);
|
|
147
152
|
});
|
|
148
153
|
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { Locator } from "@readium/shared";
|
|
2
2
|
import type { getCssSelector } from "css-selector-generator";
|
|
3
3
|
type BlockedEventData = [0, Function, any[], any[]] | [1, Event, EventTarget];
|
|
4
|
+
export interface EPUBReadingSystem {
|
|
5
|
+
name: string;
|
|
6
|
+
version: string;
|
|
7
|
+
layoutStyle: "paginated" | "scrolling";
|
|
8
|
+
hasFeature: (feature: string, version?: string) => boolean;
|
|
9
|
+
}
|
|
4
10
|
export interface ReadiumWindow extends Window {
|
|
5
11
|
_readium_blockEvents: boolean;
|
|
6
12
|
_readium_blockedEvents: BlockedEventData[];
|
|
@@ -8,6 +14,9 @@ export interface ReadiumWindow extends Window {
|
|
|
8
14
|
_readium_cssSelectorGenerator: {
|
|
9
15
|
getCssSelector: typeof getCssSelector;
|
|
10
16
|
};
|
|
17
|
+
navigator: Navigator & {
|
|
18
|
+
epubReadingSystem: EPUBReadingSystem;
|
|
19
|
+
};
|
|
11
20
|
}
|
|
12
21
|
export declare function deselect(wnd: ReadiumWindow): void;
|
|
13
22
|
export declare function nearestInteractiveElement(element: Element): Element | null;
|