@readium/navigator-html-injectables 1.2.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/README.MD +13 -0
- package/dist/index.js +3144 -0
- package/dist/index.umd.cjs +69 -0
- package/package.json +58 -0
- package/src/Loader.ts +85 -0
- package/src/comms/comms.ts +168 -0
- package/src/comms/index.ts +3 -0
- package/src/comms/keys.ts +42 -0
- package/src/comms/mid.ts +5 -0
- package/src/helpers/animation.ts +5 -0
- package/src/helpers/css.ts +16 -0
- package/src/helpers/document.ts +43 -0
- package/src/helpers/dom.ts +126 -0
- package/src/helpers/locator.ts +67 -0
- package/src/helpers/rect.ts +301 -0
- package/src/helpers/scrollSnapperHelper.ts +43 -0
- package/src/index.ts +3 -0
- package/src/modules/Decorator.ts +462 -0
- package/src/modules/Module.ts +23 -0
- package/src/modules/ModuleLibrary.ts +44 -0
- package/src/modules/Peripherals.ts +148 -0
- package/src/modules/index.ts +3 -0
- package/src/modules/setup/FixedSetup.ts +73 -0
- package/src/modules/setup/ReflowableSetup.ts +65 -0
- package/src/modules/setup/Setup.ts +131 -0
- package/src/modules/snapper/ColumnSnapper.ts +468 -0
- package/src/modules/snapper/ScrollSnapper.ts +168 -0
- package/src/modules/snapper/Snapper.ts +49 -0
- package/src/vendor/approx-string-match/LICENSE +21 -0
- package/src/vendor/approx-string-match/README.MD +1 -0
- package/src/vendor/approx-string-match/index.ts +362 -0
- package/src/vendor/hypothesis/README.MD +1 -0
- package/src/vendor/hypothesis/anchoring/api-types.ts +309 -0
- package/src/vendor/hypothesis/anchoring/html.ts +134 -0
- package/src/vendor/hypothesis/anchoring/match-quote.ts +163 -0
- package/src/vendor/hypothesis/anchoring/placeholder.ts +59 -0
- package/src/vendor/hypothesis/anchoring/text-range.ts +327 -0
- package/src/vendor/hypothesis/anchoring/trim-range.ts +220 -0
- package/src/vendor/hypothesis/anchoring/types.ts +377 -0
- package/src/vendor/hypothesis/anchoring/xpath.ts +164 -0
- package/src/vendor/hypothesis/tsconfig.json +33 -0
- package/src/vendor/hypothesis/types/shared.ts +40 -0
- package/types/src/Loader.d.ts +33 -0
- package/types/src/comms/comms.d.ts +40 -0
- package/types/src/comms/index.d.ts +3 -0
- package/types/src/comms/keys.d.ts +2 -0
- package/types/src/comms/mid.d.ts +1 -0
- package/types/src/helpers/animation.d.ts +1 -0
- package/types/src/helpers/css.d.ts +4 -0
- package/types/src/helpers/document.d.ts +8 -0
- package/types/src/helpers/dom.d.ts +15 -0
- package/types/src/helpers/locator.d.ts +2 -0
- package/types/src/helpers/rect.d.ts +10 -0
- package/types/src/helpers/scrollSnapperHelper.d.ts +5 -0
- package/types/src/index.d.ts +3 -0
- package/types/src/modules/Decorator.d.ts +43 -0
- package/types/src/modules/Module.d.ts +11 -0
- package/types/src/modules/ModuleLibrary.d.ts +5 -0
- package/types/src/modules/Peripherals.d.ts +39 -0
- package/types/src/modules/ReflowablePeripherals.d.ts +37 -0
- package/types/src/modules/index.d.ts +3 -0
- package/types/src/modules/setup/FixedSetup.d.ts +9 -0
- package/types/src/modules/setup/ReflowableSetup.d.ts +9 -0
- package/types/src/modules/setup/Setup.d.ts +17 -0
- package/types/src/modules/snapper/ColumnSnapper.d.ts +41 -0
- package/types/src/modules/snapper/ScrollSnapper.d.ts +16 -0
- package/types/src/modules/snapper/Snapper.d.ts +11 -0
- package/types/src/vendor/approx-string-match/index.d.ts +54 -0
- package/types/src/vendor/hypothesis/anchoring/api-types.d.ts +266 -0
- package/types/src/vendor/hypothesis/anchoring/html.d.ts +17 -0
- package/types/src/vendor/hypothesis/anchoring/match-quote.d.ts +30 -0
- package/types/src/vendor/hypothesis/anchoring/placeholder.d.ts +32 -0
- package/types/src/vendor/hypothesis/anchoring/text-range.d.ts +103 -0
- package/types/src/vendor/hypothesis/anchoring/trim-range.d.ts +17 -0
- package/types/src/vendor/hypothesis/anchoring/types.d.ts +102 -0
- package/types/src/vendor/hypothesis/anchoring/xpath.d.ts +15 -0
- package/types/src/vendor/hypothesis/types/shared.d.ts +32 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the node name for use in generating an xpath expression.
|
|
3
|
+
*/
|
|
4
|
+
function getNodeName(node: Node): string {
|
|
5
|
+
const nodeName = node.nodeName.toLowerCase();
|
|
6
|
+
return nodeName === '#text' ? 'text()' : nodeName;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get the index of the node as it appears in its parent's child list
|
|
11
|
+
*/
|
|
12
|
+
function getNodePosition(node: Node): number {
|
|
13
|
+
let pos = 0;
|
|
14
|
+
let tmp: Node | null = node;
|
|
15
|
+
while (tmp) {
|
|
16
|
+
if (tmp.nodeName === node.nodeName) {
|
|
17
|
+
pos += 1;
|
|
18
|
+
}
|
|
19
|
+
tmp = tmp.previousSibling;
|
|
20
|
+
}
|
|
21
|
+
return pos;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getPathSegment(node: Node): string {
|
|
25
|
+
const name = getNodeName(node);
|
|
26
|
+
const pos = getNodePosition(node);
|
|
27
|
+
return `${name}[${pos}]`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A simple XPath generator which can generate XPaths of the form
|
|
32
|
+
* /tag[index]/tag[index].
|
|
33
|
+
*
|
|
34
|
+
* @param node - The node to generate a path to
|
|
35
|
+
* @param root - Root node to which the returned path is relative
|
|
36
|
+
*/
|
|
37
|
+
export function xpathFromNode(node: Node, root: Node) {
|
|
38
|
+
let xpath = '';
|
|
39
|
+
|
|
40
|
+
let elem: Node | null = node;
|
|
41
|
+
while (elem !== root) {
|
|
42
|
+
if (!elem) {
|
|
43
|
+
throw new Error('Node is not a descendant of root');
|
|
44
|
+
}
|
|
45
|
+
xpath = getPathSegment(elem) + '/' + xpath;
|
|
46
|
+
elem = elem.parentNode;
|
|
47
|
+
}
|
|
48
|
+
xpath = '/' + xpath;
|
|
49
|
+
xpath = xpath.replace(/\/$/, ''); // Remove trailing slash
|
|
50
|
+
|
|
51
|
+
return xpath;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Return the `index`'th immediate child of `element` whose tag name is
|
|
56
|
+
* `nodeName` (case insensitive).
|
|
57
|
+
*/
|
|
58
|
+
function nthChildOfType(
|
|
59
|
+
element: Element,
|
|
60
|
+
nodeName: string,
|
|
61
|
+
index: number
|
|
62
|
+
): Element | null {
|
|
63
|
+
nodeName = nodeName.toUpperCase();
|
|
64
|
+
|
|
65
|
+
let matchIndex = -1;
|
|
66
|
+
for (let i = 0; i < element.children.length; i++) {
|
|
67
|
+
const child = element.children[i];
|
|
68
|
+
if (child.nodeName.toUpperCase() === nodeName) {
|
|
69
|
+
++matchIndex;
|
|
70
|
+
if (matchIndex === index) {
|
|
71
|
+
return child;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Evaluate a _simple XPath_ relative to a `root` element and return the
|
|
81
|
+
* matching element.
|
|
82
|
+
*
|
|
83
|
+
* A _simple XPath_ is a sequence of one or more `/tagName[index]` strings.
|
|
84
|
+
*
|
|
85
|
+
* Unlike `document.evaluate` this function:
|
|
86
|
+
*
|
|
87
|
+
* - Only supports simple XPaths
|
|
88
|
+
* - Is not affected by the document's _type_ (HTML or XML/XHTML)
|
|
89
|
+
* - Ignores element namespaces when matching element names in the XPath against
|
|
90
|
+
* elements in the DOM tree
|
|
91
|
+
* - Is case-insensitive for all elements, not just HTML elements
|
|
92
|
+
*
|
|
93
|
+
* The matching element is returned or `null` if no such element is found.
|
|
94
|
+
* An error is thrown if `xpath` is not a simple XPath.
|
|
95
|
+
*/
|
|
96
|
+
function evaluateSimpleXPath(xpath: string, root: Element): Element | null {
|
|
97
|
+
const isSimpleXPath =
|
|
98
|
+
xpath.match(/^(\/[A-Za-z0-9-]+(\[[0-9]+\])?)+$/) !== null;
|
|
99
|
+
if (!isSimpleXPath) {
|
|
100
|
+
throw new Error('Expression is not a simple XPath');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const segments = xpath.split('/');
|
|
104
|
+
let element = root;
|
|
105
|
+
|
|
106
|
+
// Remove leading empty segment. The regex above validates that the XPath
|
|
107
|
+
// has at least two segments, with the first being empty and the others non-empty.
|
|
108
|
+
segments.shift();
|
|
109
|
+
|
|
110
|
+
for (const segment of segments) {
|
|
111
|
+
let elementName;
|
|
112
|
+
let elementIndex;
|
|
113
|
+
|
|
114
|
+
const separatorPos = segment.indexOf('[');
|
|
115
|
+
if (separatorPos !== -1) {
|
|
116
|
+
elementName = segment.slice(0, separatorPos);
|
|
117
|
+
|
|
118
|
+
const indexStr = segment.slice(separatorPos + 1, segment.indexOf(']'));
|
|
119
|
+
elementIndex = parseInt(indexStr) - 1;
|
|
120
|
+
if (elementIndex < 0) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
elementName = segment;
|
|
125
|
+
elementIndex = 0;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const child = nthChildOfType(element, elementName, elementIndex);
|
|
129
|
+
if (!child) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
element = child;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return element;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Finds an element node using an XPath relative to `root`
|
|
141
|
+
*
|
|
142
|
+
* Example:
|
|
143
|
+
* node = nodeFromXPath('/main/article[1]/p[3]', document.body)
|
|
144
|
+
*/
|
|
145
|
+
export function nodeFromXPath(
|
|
146
|
+
xpath: string,
|
|
147
|
+
/* istanbul ignore next */
|
|
148
|
+
root: Element = document.body
|
|
149
|
+
): Node | null {
|
|
150
|
+
try {
|
|
151
|
+
return evaluateSimpleXPath(xpath, root);
|
|
152
|
+
} catch (err) {
|
|
153
|
+
return document.evaluate(
|
|
154
|
+
'.' + xpath,
|
|
155
|
+
root,
|
|
156
|
+
|
|
157
|
+
// nb. The `namespaceResolver` and `result` arguments are optional in the spec
|
|
158
|
+
// but required in Edge Legacy.
|
|
159
|
+
null /* namespaceResolver */,
|
|
160
|
+
XPathResult.FIRST_ORDERED_NODE_TYPE,
|
|
161
|
+
null /* result */
|
|
162
|
+
).singleNodeValue;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
|
|
5
|
+
// Needed for some npm packages
|
|
6
|
+
"allowSyntheticDefaultImports": true,
|
|
7
|
+
|
|
8
|
+
"checkJs": true,
|
|
9
|
+
"lib": ["es2020", "dom", "dom.iterable"],
|
|
10
|
+
"jsx": "react-jsx",
|
|
11
|
+
"jsxImportSource": "preact",
|
|
12
|
+
"module": "es2020",
|
|
13
|
+
"moduleResolution": "node",
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"strict": true,
|
|
16
|
+
"target": "ES2020",
|
|
17
|
+
|
|
18
|
+
// Let argument to catch statement be `any` rather than `unknown`.
|
|
19
|
+
"useUnknownInCatchVariables": false,
|
|
20
|
+
|
|
21
|
+
// Prevent automatic inclusion of global variables defined in `@types/<name>` packages.
|
|
22
|
+
// This prevents eg. Node globals from `@types/node` being included when writing
|
|
23
|
+
// code for the browser.
|
|
24
|
+
// "types": ["redux-thunk/extend-redux"]
|
|
25
|
+
},
|
|
26
|
+
"include": ["**/*.js", "**/*.ts", "**/*.tsx", "types/*.d.ts"],
|
|
27
|
+
"exclude": [
|
|
28
|
+
// Tests are not checked.
|
|
29
|
+
"**/test/**/*.js",
|
|
30
|
+
"test-util/**/*.js",
|
|
31
|
+
"karma.config.js"
|
|
32
|
+
]
|
|
33
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clusters provide the client application a mechanism for categorizing
|
|
3
|
+
* annotations so that their drawn anchor highlights may be styled distinctively
|
|
4
|
+
* in the annotated document. An annotation can only belong to one cluster.
|
|
5
|
+
*/
|
|
6
|
+
export type HighlightCluster =
|
|
7
|
+
| 'other-content' // default cluster: content not belonging to the current user
|
|
8
|
+
| 'user-annotations' // An annotation belonging to the current user
|
|
9
|
+
| 'user-highlights'; // A highlight (highlights are private; they always belong to the current user)
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Annotation properties not present on API objects, but added by the client
|
|
13
|
+
*/
|
|
14
|
+
export type ClientAnnotationData = {
|
|
15
|
+
$cluster?: HighlightCluster;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Client-side identifier: set even if annotation does not have a
|
|
19
|
+
* server-provided `id` (i.e. is unsaved)
|
|
20
|
+
*/
|
|
21
|
+
$tag: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Flag indicating whether waiting for the annotation to anchor timed out
|
|
25
|
+
*/
|
|
26
|
+
$anchorTimeout?: boolean;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Flag indicating that this annotation was created using the "Highlight" button,
|
|
30
|
+
* as opposed to "Annotate".
|
|
31
|
+
*/
|
|
32
|
+
$highlight?: boolean;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Flag indicating that this annotation was not found in the document.
|
|
36
|
+
* It is initially `undefined` while anchoring is in progress and then set to
|
|
37
|
+
* `true` if anchoring failed or `false` if it succeeded.
|
|
38
|
+
*/
|
|
39
|
+
$orphan?: boolean;
|
|
40
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ReadiumWindow } from "./helpers/dom";
|
|
2
|
+
import { ModuleName } from "./modules";
|
|
3
|
+
/**
|
|
4
|
+
* The Module loader. Handles initialization of the HTML injectables
|
|
5
|
+
* in the target Window, which could be an IFrame, or the current window).
|
|
6
|
+
*/
|
|
7
|
+
export declare class Loader<T extends string = ModuleName> {
|
|
8
|
+
private loadedModules;
|
|
9
|
+
private readonly wnd;
|
|
10
|
+
private readonly comms;
|
|
11
|
+
/**
|
|
12
|
+
* @param wnd Window instance to operate on
|
|
13
|
+
* @param initialModules List of initial modules to load
|
|
14
|
+
*/
|
|
15
|
+
constructor(wnd?: ReadiumWindow, initialModules?: string[]);
|
|
16
|
+
private loadModule;
|
|
17
|
+
/**
|
|
18
|
+
* Add a module by name
|
|
19
|
+
* @param moduleName Module name
|
|
20
|
+
* @returns Success
|
|
21
|
+
*/
|
|
22
|
+
addModule(moduleName: T): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Remove a module by name
|
|
25
|
+
* @param moduleName Module name
|
|
26
|
+
* @returns Success
|
|
27
|
+
*/
|
|
28
|
+
removeModule(moduleName: T): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Unmount and remove all modules
|
|
31
|
+
*/
|
|
32
|
+
destroy(): void;
|
|
33
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ReadiumWindow } from "../helpers/dom";
|
|
2
|
+
import { CommsEventKey, CommsCommandKey } from "./keys";
|
|
3
|
+
export declare const COMMS_VERSION = 1;
|
|
4
|
+
export interface CommsMessage {
|
|
5
|
+
_readium: number;
|
|
6
|
+
_channel: string;
|
|
7
|
+
id?: string;
|
|
8
|
+
strict?: boolean;
|
|
9
|
+
key: CommsEventKey | CommsCommandKey;
|
|
10
|
+
data: unknown;
|
|
11
|
+
}
|
|
12
|
+
export interface Registrant {
|
|
13
|
+
module: string;
|
|
14
|
+
cb: CommsCallback;
|
|
15
|
+
}
|
|
16
|
+
export type CommsAck = (ok: boolean) => void;
|
|
17
|
+
export type CommsCallback = (data: unknown, ack: CommsAck) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Comms is basically a wrapper around window.postMessage that
|
|
20
|
+
* adds structure to the messages and lets modules register callbacks.
|
|
21
|
+
*/
|
|
22
|
+
export declare class Comms {
|
|
23
|
+
private readonly wnd;
|
|
24
|
+
private destination;
|
|
25
|
+
private registrar;
|
|
26
|
+
private origin;
|
|
27
|
+
private channelId;
|
|
28
|
+
constructor(wnd: ReadiumWindow);
|
|
29
|
+
private receive;
|
|
30
|
+
private receiver;
|
|
31
|
+
private handle;
|
|
32
|
+
register(key: CommsCommandKey | CommsCommandKey[], module: string, callback: CommsCallback): void;
|
|
33
|
+
unregister(key: CommsCommandKey | CommsCommandKey[], module: string): void;
|
|
34
|
+
unregisterAll(module: string): void;
|
|
35
|
+
private preLog;
|
|
36
|
+
log(...data: any[]): void;
|
|
37
|
+
get ready(): boolean;
|
|
38
|
+
destroy(): void;
|
|
39
|
+
send(key: CommsEventKey, data: unknown, id?: unknown, transfer?: Transferable[]): void;
|
|
40
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export type CommsEventKey = "_pong" | "_unhandled" | "_ack" | "log" | "error" | "click" | "tap" | "tap_more" | "no_more" | "no_less" | "swipe" | "progress" | "first_visible_locator" | "text_selected" | "media_play" | "media_pause";
|
|
2
|
+
export type CommsCommandKey = "_ping" | "go_prev" | "go_next" | "go_id" | "go_text" | "go_end" | "go_start" | "go_progression" | "set_property" | "remove_property" | "first_visible_locator" | "decorate" | "protect" | "unprotect" | "unfocus" | "focus" | "activate" | "shake";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const mid: () => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function easeInOutQuad(t: number): number;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ReadiumWindow } from "./dom";
|
|
2
|
+
export declare function getProperty(wnd: ReadiumWindow, key: string): string;
|
|
3
|
+
export declare function setProperty(wnd: ReadiumWindow, key: string, value: string): void;
|
|
4
|
+
export declare function removeProperty(wnd: ReadiumWindow, key: string): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReadiumWindow } from "./dom";
|
|
2
|
+
export declare function isRTL(wnd: ReadiumWindow): boolean;
|
|
3
|
+
export declare function getColumnCountPerScreen(wnd: ReadiumWindow): number;
|
|
4
|
+
/**
|
|
5
|
+
* Having an odd number of columns when displaying two columns per screen causes snapping and page
|
|
6
|
+
* turning issues. To fix this, we insert a blank virtual column at the end of the resource.
|
|
7
|
+
*/
|
|
8
|
+
export declare function appendVirtualColumnIfNeeded(wnd: ReadiumWindow): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Locator } from "@readium/shared";
|
|
2
|
+
import type { getCssSelector } from "css-selector-generator";
|
|
3
|
+
type BlockedEventData = [0, Function, any[], any[]] | [1, Event, EventTarget];
|
|
4
|
+
export interface ReadiumWindow extends Window {
|
|
5
|
+
_readium_blockEvents: boolean;
|
|
6
|
+
_readium_blockedEvents: BlockedEventData[];
|
|
7
|
+
_readium_eventBlocker: EventListenerOrEventListenerObject;
|
|
8
|
+
_readium_cssSelectorGenerator: {
|
|
9
|
+
getCssSelector: typeof getCssSelector;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export declare function deselect(wnd: ReadiumWindow): void;
|
|
13
|
+
export declare function nearestInteractiveElement(element: Element): Element | null;
|
|
14
|
+
export declare function findFirstVisibleLocator(wnd: ReadiumWindow, scrolling: boolean): Locator;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface Rect {
|
|
2
|
+
bottom: number;
|
|
3
|
+
height: number;
|
|
4
|
+
left: number;
|
|
5
|
+
right: number;
|
|
6
|
+
top: number;
|
|
7
|
+
width: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function getClientRectsNoOverlap(range: Range, doNotMergeHorizontallyAlignedRects: boolean): Rect[];
|
|
10
|
+
export declare function rectContainsPoint(rect: Rect, x: number, y: number, tolerance: number): boolean;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Locator } from "@readium/shared";
|
|
2
|
+
import { Comms } from "../comms/comms";
|
|
3
|
+
import { Module } from "./Module";
|
|
4
|
+
import { ModuleName } from "./ModuleLibrary";
|
|
5
|
+
import { ReadiumWindow } from "../helpers/dom";
|
|
6
|
+
export declare enum Width {
|
|
7
|
+
Wrap = "wrap",// Smallest width fitting the CSS border box.
|
|
8
|
+
Viewport = "viewport",// Fills the whole viewport.
|
|
9
|
+
Bounds = "bounds",// Fills the anchor page, useful for dual page.
|
|
10
|
+
Page = "page"
|
|
11
|
+
}
|
|
12
|
+
export declare enum Layout {
|
|
13
|
+
Boxes = "boxes",// One HTML element for each CSS border box (e.g. line of text).
|
|
14
|
+
Bounds = "bounds"
|
|
15
|
+
}
|
|
16
|
+
export interface Style {
|
|
17
|
+
tint: string;
|
|
18
|
+
layout: Layout;
|
|
19
|
+
width: Width;
|
|
20
|
+
}
|
|
21
|
+
export interface Decoration {
|
|
22
|
+
id: string;
|
|
23
|
+
locator: Locator;
|
|
24
|
+
style: Style;
|
|
25
|
+
}
|
|
26
|
+
export interface DecoratorRequest {
|
|
27
|
+
group: string;
|
|
28
|
+
action: "add" | "remove" | "clear" | "update";
|
|
29
|
+
decoration: Decoration | undefined;
|
|
30
|
+
}
|
|
31
|
+
export declare class Decorator extends Module {
|
|
32
|
+
static readonly moduleName: ModuleName;
|
|
33
|
+
private resizeObserver;
|
|
34
|
+
private wnd;
|
|
35
|
+
private resizeFrame;
|
|
36
|
+
private lastGroupId;
|
|
37
|
+
private groups;
|
|
38
|
+
private cleanup;
|
|
39
|
+
private handleResize;
|
|
40
|
+
private readonly handleResizer;
|
|
41
|
+
mount(wnd: ReadiumWindow, comms: Comms): boolean;
|
|
42
|
+
unmount(wnd: ReadiumWindow, comms: Comms): boolean;
|
|
43
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Comms } from "../comms";
|
|
2
|
+
import { ReadiumWindow } from "../helpers/dom";
|
|
3
|
+
import { ModuleName } from "./ModuleLibrary";
|
|
4
|
+
export declare abstract class Module {
|
|
5
|
+
static readonly moduleName: ModuleName;
|
|
6
|
+
abstract mount(wnd: ReadiumWindow, comms: Comms): boolean;
|
|
7
|
+
abstract unmount(wnd: ReadiumWindow, comms: Comms): boolean;
|
|
8
|
+
}
|
|
9
|
+
export type ModuleDerived = {
|
|
10
|
+
new (): Module;
|
|
11
|
+
} & typeof Module;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ModuleDerived } from "./Module";
|
|
2
|
+
export type ModuleName = "setup" | "snapper" | "column_snapper" | "scroll_snapper" | "fixed_setup" | "decorator" | "reflowable_setup" | "peripherals";
|
|
3
|
+
export declare const FXLModules: ModuleName[];
|
|
4
|
+
export declare const ReflowableModules: ModuleName[];
|
|
5
|
+
export declare const ModuleLibrary: Map<string, ModuleDerived>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Comms } from "../comms/comms";
|
|
2
|
+
import { Module } from "./Module";
|
|
3
|
+
import { ReadiumWindow } from "../helpers/dom";
|
|
4
|
+
export interface FrameClickEvent {
|
|
5
|
+
defaultPrevented: boolean;
|
|
6
|
+
doNotDisturb: boolean;
|
|
7
|
+
interactiveElement: string | undefined;
|
|
8
|
+
cssSelector: string | undefined;
|
|
9
|
+
targetElement: string;
|
|
10
|
+
targetFrameSrc: string;
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
}
|
|
14
|
+
export interface BasicTextSelection {
|
|
15
|
+
text: string;
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
targetFrameSrc: string;
|
|
21
|
+
}
|
|
22
|
+
export declare class Peripherals extends Module {
|
|
23
|
+
static readonly moduleName = "peripherals";
|
|
24
|
+
private wnd;
|
|
25
|
+
private comms;
|
|
26
|
+
private pointerMoved;
|
|
27
|
+
onPointUp(event: PointerEvent): void;
|
|
28
|
+
private readonly onPointerUp;
|
|
29
|
+
onPointMove(event: PointerEvent): void;
|
|
30
|
+
private readonly onPointerMove;
|
|
31
|
+
onPointDown(): void;
|
|
32
|
+
private readonly onPointerDown;
|
|
33
|
+
onContext(event: MouseEvent): void;
|
|
34
|
+
private readonly onContextMenu;
|
|
35
|
+
onClick(event: MouseEvent): void;
|
|
36
|
+
private readonly onClicker;
|
|
37
|
+
mount(wnd: ReadiumWindow, comms: Comms): boolean;
|
|
38
|
+
unmount(wnd: ReadiumWindow, comms: Comms): boolean;
|
|
39
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Comms } from "../comms/comms";
|
|
2
|
+
import { Module } from "./Module";
|
|
3
|
+
export interface FrameClickEvent {
|
|
4
|
+
defaultPrevented: boolean;
|
|
5
|
+
doNotDisturb: boolean;
|
|
6
|
+
interactiveElement: string | undefined;
|
|
7
|
+
targetElement: string;
|
|
8
|
+
targetFrameSrc: string;
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
}
|
|
12
|
+
export interface BasicTextSelection {
|
|
13
|
+
text: string;
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
targetFrameSrc: string;
|
|
19
|
+
}
|
|
20
|
+
export declare class ReflowablePeripherals extends Module {
|
|
21
|
+
static readonly moduleName = "reflowable_peripherals";
|
|
22
|
+
private wnd;
|
|
23
|
+
private comms;
|
|
24
|
+
private pointerMoved;
|
|
25
|
+
onPointUp(event: PointerEvent): void;
|
|
26
|
+
private readonly onPointerUp;
|
|
27
|
+
onPointMove(event: PointerEvent): void;
|
|
28
|
+
private readonly onPointerMove;
|
|
29
|
+
onPointDown(): void;
|
|
30
|
+
private readonly onPointerDown;
|
|
31
|
+
onContext(event: MouseEvent): void;
|
|
32
|
+
private readonly onContextMenu;
|
|
33
|
+
onClick(event: MouseEvent): void;
|
|
34
|
+
private readonly onClicker;
|
|
35
|
+
mount(wnd: Window, comms: Comms): boolean;
|
|
36
|
+
unmount(wnd: Window, comms: Comms): boolean;
|
|
37
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Comms } from "../../comms/comms";
|
|
2
|
+
import { Setup } from "./Setup";
|
|
3
|
+
import { ModuleName } from "../ModuleLibrary";
|
|
4
|
+
import { ReadiumWindow } from "../../helpers/dom";
|
|
5
|
+
export declare class FixedSetup extends Setup {
|
|
6
|
+
static readonly moduleName: ModuleName;
|
|
7
|
+
mount(wnd: ReadiumWindow, comms: Comms): boolean;
|
|
8
|
+
unmount(wnd: ReadiumWindow, comms: Comms): boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Comms } from "../../comms/comms";
|
|
2
|
+
import { Setup } from "./Setup";
|
|
3
|
+
import { ReadiumWindow } from "../../helpers/dom";
|
|
4
|
+
export declare class ReflowableSetup extends Setup {
|
|
5
|
+
static readonly moduleName = "reflowable_setup";
|
|
6
|
+
onViewportWidthChanged(event: Event): void;
|
|
7
|
+
mount(wnd: ReadiumWindow, comms: Comms): boolean;
|
|
8
|
+
unmount(wnd: ReadiumWindow, comms: Comms): boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Comms } from "../../comms/comms";
|
|
2
|
+
import { ReadiumWindow } from "../../helpers/dom";
|
|
3
|
+
import { Module } from "../Module";
|
|
4
|
+
import { ModuleName } from "../ModuleLibrary";
|
|
5
|
+
export declare abstract class Setup extends Module {
|
|
6
|
+
static readonly moduleName: ModuleName;
|
|
7
|
+
private comms;
|
|
8
|
+
wndOnErr(event: ErrorEvent): void;
|
|
9
|
+
protected unblock(wnd: ReadiumWindow): void;
|
|
10
|
+
private mediaPlayingCount;
|
|
11
|
+
private onMediaPlayEvent;
|
|
12
|
+
private onMediaPauseEvent;
|
|
13
|
+
private pauseAllMedia;
|
|
14
|
+
private allAnimations;
|
|
15
|
+
mount(wnd: ReadiumWindow, comms: Comms): boolean;
|
|
16
|
+
unmount(wnd: ReadiumWindow, comms: Comms): boolean;
|
|
17
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Comms } from "../../comms";
|
|
2
|
+
import { Snapper } from "./Snapper";
|
|
3
|
+
import { ModuleName } from "../ModuleLibrary";
|
|
4
|
+
import { ReadiumWindow } from "../../helpers/dom";
|
|
5
|
+
/**
|
|
6
|
+
* A {Snapper} for reflowable resources using a column-based layout
|
|
7
|
+
*/
|
|
8
|
+
export declare class ColumnSnapper extends Snapper {
|
|
9
|
+
static readonly moduleName: ModuleName;
|
|
10
|
+
private resizeObserver;
|
|
11
|
+
private mutationObserver;
|
|
12
|
+
private wnd;
|
|
13
|
+
private comms;
|
|
14
|
+
private doc;
|
|
15
|
+
private scrollOffset;
|
|
16
|
+
snapOffset(offset: number): number;
|
|
17
|
+
reportProgress(): void;
|
|
18
|
+
private shakeTimeout;
|
|
19
|
+
shake(): void;
|
|
20
|
+
private snappingCancelled;
|
|
21
|
+
private alreadyScrollLeft;
|
|
22
|
+
private overscroll;
|
|
23
|
+
private cachedScrollWidth;
|
|
24
|
+
private takeOverSnap;
|
|
25
|
+
snapCurrentOffset(smooth?: boolean, noprogress?: boolean): void;
|
|
26
|
+
private touchState;
|
|
27
|
+
private startingX;
|
|
28
|
+
private endingX;
|
|
29
|
+
private dragOffset;
|
|
30
|
+
private clearTouches;
|
|
31
|
+
onTouchStart(e: TouchEvent): void;
|
|
32
|
+
private readonly onTouchStarter;
|
|
33
|
+
onTouchEnd(_: TouchEvent): void;
|
|
34
|
+
private readonly onTouchEnder;
|
|
35
|
+
private onWidthChange;
|
|
36
|
+
private readonly onWidthChanger;
|
|
37
|
+
onTouchMove(e: TouchEvent): void;
|
|
38
|
+
private readonly onTouchMover;
|
|
39
|
+
mount(wnd: ReadiumWindow, comms: Comms): boolean;
|
|
40
|
+
unmount(wnd: ReadiumWindow, comms: Comms): boolean;
|
|
41
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Comms } from "../../comms";
|
|
2
|
+
import { ReadiumWindow } from "../../helpers/dom";
|
|
3
|
+
import { ModuleName } from "../ModuleLibrary";
|
|
4
|
+
import { Snapper } from "./Snapper";
|
|
5
|
+
export declare class ScrollSnapper extends Snapper {
|
|
6
|
+
static readonly moduleName: ModuleName;
|
|
7
|
+
private wnd;
|
|
8
|
+
private comms;
|
|
9
|
+
private doc;
|
|
10
|
+
private createAnchorElements;
|
|
11
|
+
private removeAnchorElements;
|
|
12
|
+
private createCustomElement;
|
|
13
|
+
private reportProgress;
|
|
14
|
+
mount(wnd: ReadiumWindow, comms: Comms): boolean;
|
|
15
|
+
unmount(wnd: ReadiumWindow, comms: Comms): boolean;
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Comms } from "../../comms";
|
|
2
|
+
import { ReadiumWindow } from "../../helpers/dom";
|
|
3
|
+
import { Module } from "../Module";
|
|
4
|
+
import { ModuleName } from "../ModuleLibrary";
|
|
5
|
+
export declare abstract class Snapper extends Module {
|
|
6
|
+
static readonly moduleName: ModuleName;
|
|
7
|
+
private protected;
|
|
8
|
+
buildStyles(): string;
|
|
9
|
+
mount(wnd: ReadiumWindow, comms: Comms): boolean;
|
|
10
|
+
unmount(wnd: ReadiumWindow, comms: Comms): boolean;
|
|
11
|
+
}
|