@readium/navigator 2.2.8 → 2.3.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/dist/index.js +3079 -3225
- package/dist/index.umd.cjs +80 -87
- package/package.json +5 -4
- package/src/Navigator.ts +76 -0
- package/src/epub/EpubNavigator.ts +93 -10
- package/src/epub/css/Properties.ts +8 -8
- package/src/epub/css/ReadiumCSS.ts +7 -5
- package/src/epub/frame/FrameManager.ts +38 -2
- package/src/epub/frame/FramePoolManager.ts +9 -2
- package/src/epub/fxl/FXLFrameManager.ts +31 -2
- package/src/epub/fxl/FXLFramePoolManager.ts +9 -3
- package/src/epub/preferences/EpubDefaults.ts +6 -6
- package/src/epub/preferences/EpubPreferences.ts +6 -6
- package/src/epub/preferences/EpubPreferencesEditor.ts +1 -3
- package/src/epub/preferences/EpubSettings.ts +5 -7
- package/src/helpers/lineLength.ts +4 -6
- package/src/injection/epubInjectables.ts +11 -3
- package/src/injection/webpubInjectables.ts +12 -2
- package/src/peripherals/KeyboardPeripherals.ts +53 -0
- package/src/protection/AutomationDetector.ts +66 -0
- package/src/protection/ContextMenuProtector.ts +46 -0
- package/src/protection/DevToolsDetector.ts +290 -0
- package/src/protection/IframeEmbeddingDetector.ts +73 -0
- package/src/protection/NavigatorProtector.ts +95 -0
- package/src/protection/PrintProtector.ts +58 -0
- package/src/protection/utils/WorkerConsole.ts +84 -0
- package/src/protection/utils/console.ts +16 -0
- package/src/protection/utils/match.ts +18 -0
- package/src/protection/utils/platform.ts +22 -0
- package/src/webpub/WebPubFrameManager.ts +38 -5
- package/src/webpub/WebPubFramePoolManager.ts +9 -2
- package/src/webpub/WebPubNavigator.ts +87 -7
- package/types/src/Navigator.d.ts +14 -0
- package/types/src/epub/EpubNavigator.d.ts +14 -2
- package/types/src/epub/css/Properties.d.ts +4 -0
- package/types/src/epub/frame/FrameManager.d.ts +5 -1
- package/types/src/epub/frame/FramePoolManager.d.ts +4 -1
- package/types/src/epub/fxl/FXLFrameManager.d.ts +5 -1
- package/types/src/epub/fxl/FXLFramePoolManager.d.ts +4 -2
- package/types/src/epub/preferences/EpubDefaults.d.ts +4 -0
- package/types/src/epub/preferences/EpubPreferences.d.ts +4 -0
- package/types/src/epub/preferences/EpubPreferencesEditor.d.ts +2 -0
- package/types/src/epub/preferences/EpubSettings.d.ts +4 -0
- package/types/src/helpers/lineLength.d.ts +2 -3
- package/types/src/injection/epubInjectables.d.ts +2 -2
- package/types/src/injection/webpubInjectables.d.ts +2 -1
- package/types/src/peripherals/KeyboardPeripherals.d.ts +13 -0
- package/types/src/protection/AutomationDetector.d.ts +14 -0
- package/types/src/protection/ContextMenuProtector.d.ts +11 -0
- package/types/src/protection/DevToolsDetector.d.ts +75 -0
- package/types/src/protection/IframeEmbeddingDetector.d.ts +14 -0
- package/types/src/protection/NavigatorProtector.d.ts +12 -0
- package/types/src/protection/PrintProtector.d.ts +13 -0
- package/types/src/protection/utils/WorkerConsole.d.ts +15 -0
- package/types/src/protection/utils/console.d.ts +6 -0
- package/types/src/protection/utils/match.d.ts +8 -0
- package/types/src/protection/utils/platform.d.ts +4 -0
- package/types/src/webpub/WebPubFrameManager.d.ts +5 -1
- package/types/src/webpub/WebPubFramePoolManager.d.ts +4 -1
- package/types/src/webpub/WebPubNavigator.d.ts +13 -1
- package/dist/ar-DyHX_uy2-DyHX_uy2.js +0 -7
- package/dist/assets/AccessibleDfA-Bold.woff2 +0 -0
- package/dist/assets/AccessibleDfA-Italic.woff2 +0 -0
- package/dist/assets/AccessibleDfA-Regular.woff +0 -0
- package/dist/assets/AccessibleDfA-Regular.woff2 +0 -0
- package/dist/assets/iAWriterDuospace-Regular.ttf +0 -0
- package/dist/da-Dct0PS3E-Dct0PS3E.js +0 -7
- package/dist/fr-C5HEel98-C5HEel98.js +0 -7
- package/dist/it-DFOBoXGy-DFOBoXGy.js +0 -7
- package/dist/pt_PT-Di3sVjze-Di3sVjze.js +0 -7
- package/dist/sv-BfzAFsVN-BfzAFsVN.js +0 -7
- package/types/src/epub/preferences/guards.d.ts +0 -9
- package/types/src/web/WebPubBlobBuilder.d.ts +0 -10
- package/types/src/web/WebPubFrameManager.d.ts +0 -20
- package/types/src/web/WebPubNavigator.d.ts +0 -48
- package/types/src/web/index.d.ts +0 -3
- package/types/src/webpub/css/WebPubStylesheet.d.ts +0 -1
- /package/dist/{ar-DyHX_uy2-DyHX_uy2-DyHX_uy2.js → ar-DyHX_uy2.js} +0 -0
- /package/dist/{da-Dct0PS3E-Dct0PS3E-Dct0PS3E.js → da-Dct0PS3E.js} +0 -0
- /package/dist/{fr-C5HEel98-C5HEel98-C5HEel98.js → fr-C5HEel98.js} +0 -0
- /package/dist/{it-DFOBoXGy-DFOBoXGy-DFOBoXGy.js → it-DFOBoXGy.js} +0 -0
- /package/dist/{pt_PT-Di3sVjze-Di3sVjze-Di3sVjze.js → pt_PT-Di3sVjze.js} +0 -0
- /package/dist/{sv-BfzAFsVN-BfzAFsVN-BfzAFsVN.js → sv-BfzAFsVN.js} +0 -0
|
@@ -53,8 +53,8 @@ export interface IEpubDefaults {
|
|
|
53
53
|
scroll?: boolean | null,
|
|
54
54
|
scrollPaddingTop?: number | null,
|
|
55
55
|
scrollPaddingBottom?: number | null,
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
scrollPaddingLeft?: number | null,
|
|
57
|
+
scrollPaddingRight?: number | null,
|
|
58
58
|
selectionBackgroundColor?: string | null,
|
|
59
59
|
selectionTextColor?: string | null,
|
|
60
60
|
textAlign?: TextAlignment | null,
|
|
@@ -97,8 +97,8 @@ export class EpubDefaults {
|
|
|
97
97
|
scroll: boolean | null;
|
|
98
98
|
scrollPaddingTop: number | null;
|
|
99
99
|
scrollPaddingBottom: number | null;
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
scrollPaddingLeft: number | null;
|
|
101
|
+
scrollPaddingRight: number | null;
|
|
102
102
|
selectionBackgroundColor: string | null;
|
|
103
103
|
selectionTextColor: string | null;
|
|
104
104
|
textAlign: TextAlignment | null;
|
|
@@ -144,8 +144,8 @@ export class EpubDefaults {
|
|
|
144
144
|
this.scroll = ensureBoolean(defaults.scroll) ?? false;
|
|
145
145
|
this.scrollPaddingTop = ensureNonNegative(defaults.scrollPaddingTop) ?? null;
|
|
146
146
|
this.scrollPaddingBottom = ensureNonNegative(defaults.scrollPaddingBottom) ?? null;
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
this.scrollPaddingLeft = ensureNonNegative(defaults.scrollPaddingLeft) ?? null;
|
|
148
|
+
this.scrollPaddingRight = ensureNonNegative(defaults.scrollPaddingRight) ?? null;
|
|
149
149
|
this.selectionBackgroundColor = ensureString(defaults.selectionBackgroundColor) || null;
|
|
150
150
|
this.selectionTextColor = ensureString(defaults.selectionTextColor) || null;
|
|
151
151
|
this.textAlign = ensureEnumValue<TextAlignment>(defaults.textAlign, TextAlignment) || null;
|
|
@@ -48,8 +48,8 @@ export interface IEpubPreferences {
|
|
|
48
48
|
scroll?: boolean | null,
|
|
49
49
|
scrollPaddingTop?: number | null,
|
|
50
50
|
scrollPaddingBottom?: number | null,
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
scrollPaddingLeft?: number | null,
|
|
52
|
+
scrollPaddingRight?: number | null,
|
|
53
53
|
selectionBackgroundColor?: string | null,
|
|
54
54
|
selectionTextColor?: string | null,
|
|
55
55
|
textAlign?: TextAlignment | null,
|
|
@@ -91,8 +91,8 @@ export class EpubPreferences implements ConfigurablePreferences {
|
|
|
91
91
|
scroll?: boolean | null;
|
|
92
92
|
scrollPaddingTop?: number | null;
|
|
93
93
|
scrollPaddingBottom?: number | null;
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
scrollPaddingLeft?: number | null;
|
|
95
|
+
scrollPaddingRight?: number | null;
|
|
96
96
|
selectionBackgroundColor?: string | null;
|
|
97
97
|
selectionTextColor?: string | null;
|
|
98
98
|
textAlign?: TextAlignment | null;
|
|
@@ -130,8 +130,8 @@ export class EpubPreferences implements ConfigurablePreferences {
|
|
|
130
130
|
this.scroll = ensureBoolean(preferences.scroll);
|
|
131
131
|
this.scrollPaddingTop = ensureNonNegative(preferences.scrollPaddingTop);
|
|
132
132
|
this.scrollPaddingBottom = ensureNonNegative(preferences.scrollPaddingBottom);
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
this.scrollPaddingLeft = ensureNonNegative(preferences.scrollPaddingLeft);
|
|
134
|
+
this.scrollPaddingRight = ensureNonNegative(preferences.scrollPaddingRight);
|
|
135
135
|
this.selectionBackgroundColor = ensureString(preferences.selectionBackgroundColor);
|
|
136
136
|
this.selectionTextColor = ensureString(preferences.selectionTextColor);
|
|
137
137
|
this.textAlign = ensureEnumValue<TextAlignment>(preferences.textAlign, TextAlignment);
|
|
@@ -364,7 +364,7 @@ export class EpubPreferencesEditor implements IPreferencesEditor {
|
|
|
364
364
|
return new Preference<number>({
|
|
365
365
|
initialValue: this.preferences.pageGutter,
|
|
366
366
|
effectiveValue: this.settings.pageGutter,
|
|
367
|
-
isEffective: this.layout !== Layout.fixed,
|
|
367
|
+
isEffective: this.layout !== Layout.fixed && !this.settings.scroll,
|
|
368
368
|
onChange: (newValue: number | null | undefined) => {
|
|
369
369
|
this.updatePreference("pageGutter", newValue || null);
|
|
370
370
|
}
|
|
@@ -430,7 +430,6 @@ export class EpubPreferencesEditor implements IPreferencesEditor {
|
|
|
430
430
|
});
|
|
431
431
|
}
|
|
432
432
|
|
|
433
|
-
/*
|
|
434
433
|
get scrollPaddingLeft(): Preference<number> {
|
|
435
434
|
return new Preference<number>({
|
|
436
435
|
initialValue: this.preferences.scrollPaddingLeft,
|
|
@@ -452,7 +451,6 @@ export class EpubPreferencesEditor implements IPreferencesEditor {
|
|
|
452
451
|
}
|
|
453
452
|
});
|
|
454
453
|
}
|
|
455
|
-
*/
|
|
456
454
|
|
|
457
455
|
get selectionBackgroundColor(): Preference<string> {
|
|
458
456
|
return new Preference<string>({
|
|
@@ -37,8 +37,8 @@ export interface IEpubSettings {
|
|
|
37
37
|
scroll?: boolean | null,
|
|
38
38
|
scrollPaddingTop?: number | null,
|
|
39
39
|
scrollPaddingBottom?: number | null,
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
scrollPaddingLeft?: number | null,
|
|
41
|
+
scrollPaddingRight?: number | null,
|
|
42
42
|
selectionBackgroundColor?: string | null,
|
|
43
43
|
selectionTextColor?: string | null,
|
|
44
44
|
textAlign?: TextAlignment | null,
|
|
@@ -81,8 +81,8 @@ export class EpubSettings implements ConfigurableSettings {
|
|
|
81
81
|
scroll: boolean | null;
|
|
82
82
|
scrollPaddingTop: number | null;
|
|
83
83
|
scrollPaddingBottom: number | null;
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
scrollPaddingLeft: number | null;
|
|
85
|
+
scrollPaddingRight: number | null;
|
|
86
86
|
selectionBackgroundColor: string | null;
|
|
87
87
|
selectionTextColor: string | null;
|
|
88
88
|
textAlign: TextAlignment | null;
|
|
@@ -205,8 +205,7 @@ export class EpubSettings implements ConfigurableSettings {
|
|
|
205
205
|
? preferences.scrollPaddingBottom
|
|
206
206
|
: defaults.scrollPaddingBottom !== undefined
|
|
207
207
|
? defaults.scrollPaddingBottom
|
|
208
|
-
: null;
|
|
209
|
-
/*
|
|
208
|
+
: null;
|
|
210
209
|
this.scrollPaddingLeft = preferences.scrollPaddingLeft !== undefined
|
|
211
210
|
? preferences.scrollPaddingLeft
|
|
212
211
|
: defaults.scrollPaddingLeft !== undefined
|
|
@@ -217,7 +216,6 @@ export class EpubSettings implements ConfigurableSettings {
|
|
|
217
216
|
: defaults.scrollPaddingRight !== undefined
|
|
218
217
|
? defaults.scrollPaddingRight
|
|
219
218
|
: null;
|
|
220
|
-
*/
|
|
221
219
|
this.selectionBackgroundColor = preferences.selectionBackgroundColor || defaults.selectionBackgroundColor || null;
|
|
222
220
|
this.selectionTextColor = preferences.selectionTextColor || defaults.selectionTextColor || null;
|
|
223
221
|
this.textAlign = preferences.textAlign || defaults.textAlign || null;
|
|
@@ -11,7 +11,7 @@ export interface ILineLengthsConfig {
|
|
|
11
11
|
maxChars?: number | null;
|
|
12
12
|
baseFontSize?: number | null;
|
|
13
13
|
sample?: string | null;
|
|
14
|
-
|
|
14
|
+
padding?: number | null;
|
|
15
15
|
fontFace?: string | ICustomFontFace | null;
|
|
16
16
|
letterSpacing?: number | null;
|
|
17
17
|
wordSpacing?: number | null;
|
|
@@ -51,13 +51,12 @@ export class LineLengths {
|
|
|
51
51
|
private _baseFontSize: number;
|
|
52
52
|
private _fontFace: string | ICustomFontFace;
|
|
53
53
|
private _sample: string | null;
|
|
54
|
-
private
|
|
54
|
+
private _padding: number;
|
|
55
55
|
private _letterSpacing: number;
|
|
56
56
|
private _wordSpacing: number;
|
|
57
57
|
private _isCJK: boolean;
|
|
58
58
|
private _getRelative: boolean;
|
|
59
59
|
|
|
60
|
-
private _padding: number;
|
|
61
60
|
private _minDivider: number | null;
|
|
62
61
|
private _maxMultiplier: number | null;
|
|
63
62
|
private _approximatedWordSpaces: number;
|
|
@@ -72,7 +71,7 @@ export class LineLengths {
|
|
|
72
71
|
this._baseFontSize = config.baseFontSize || DEFAULT_FONT_SIZE;
|
|
73
72
|
this._fontFace = config.fontFace || DEFAULT_FONT_FACE;
|
|
74
73
|
this._sample = config.sample || null;
|
|
75
|
-
this.
|
|
74
|
+
this._padding = config.padding ?? 0;
|
|
76
75
|
this._letterSpacing = config.letterSpacing
|
|
77
76
|
? Math.round(config.letterSpacing * this._baseFontSize)
|
|
78
77
|
: 0;
|
|
@@ -81,7 +80,6 @@ export class LineLengths {
|
|
|
81
80
|
: 0;
|
|
82
81
|
this._isCJK = config.isCJK || false;
|
|
83
82
|
this._getRelative = config.getRelative || false;
|
|
84
|
-
this._padding = this._pageGutter * 2;
|
|
85
83
|
this._minDivider = this._minChars && this._minChars < this._optimalChars
|
|
86
84
|
? this._optimalChars / this._minChars
|
|
87
85
|
: this._minChars === null
|
|
@@ -121,7 +119,7 @@ export class LineLengths {
|
|
|
121
119
|
if (props.letterSpacing) this._letterSpacing = props.letterSpacing;
|
|
122
120
|
if (props.wordSpacing) this._wordSpacing = props.wordSpacing;
|
|
123
121
|
if (props.isCJK != null) this._isCJK = props.isCJK;
|
|
124
|
-
if (props.
|
|
122
|
+
if (props.padding !== undefined) this._padding = props.padding ?? 0;
|
|
125
123
|
if (props.getRelative) this._getRelative = props.getRelative;
|
|
126
124
|
|
|
127
125
|
if (props.sample) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IInjectableRule, IInjectable } from "../injection/Injectable";
|
|
2
2
|
import { stripJS, stripCSS } from "../helpers/minify";
|
|
3
|
-
import { Metadata, Layout } from "@readium/shared";
|
|
3
|
+
import { Metadata, Layout, Link } from "@readium/shared";
|
|
4
4
|
|
|
5
5
|
import readiumCSSAfter from "@readium/css/css/dist/ReadiumCSS-after.css?raw";
|
|
6
6
|
import readiumCSSBefore from "@readium/css/css/dist/ReadiumCSS-before.css?raw";
|
|
@@ -13,9 +13,17 @@ import onloadProxyContent from "../dom/_readium_executionCleanup.js?raw";
|
|
|
13
13
|
/**
|
|
14
14
|
* Creates injectable rules for EPUB content documents
|
|
15
15
|
*/
|
|
16
|
-
export function createReadiumEpubRules(metadata: Metadata): IInjectableRule[] {
|
|
16
|
+
export function createReadiumEpubRules(metadata: Metadata, readingOrderItems: Link[]): IInjectableRule[] {
|
|
17
17
|
const isFixedLayout = metadata.effectiveLayout === Layout.fixed;
|
|
18
18
|
|
|
19
|
+
const htmlHrefs = readingOrderItems
|
|
20
|
+
.filter(item => item.mediaType.isHTML)
|
|
21
|
+
.map(item => item.href);
|
|
22
|
+
|
|
23
|
+
const resources = htmlHrefs.length > 0
|
|
24
|
+
? htmlHrefs
|
|
25
|
+
: [/\.xhtml$/, /\.html$/]; // fallback patterns
|
|
26
|
+
|
|
19
27
|
// Core injectables that should be prepended
|
|
20
28
|
const prependInjectables: IInjectable[] = [
|
|
21
29
|
// CSS Selector Generator - always injected
|
|
@@ -82,7 +90,7 @@ export function createReadiumEpubRules(metadata: Metadata): IInjectableRule[] {
|
|
|
82
90
|
|
|
83
91
|
return [
|
|
84
92
|
{
|
|
85
|
-
resources:
|
|
93
|
+
resources: resources,
|
|
86
94
|
prepend: prependInjectables,
|
|
87
95
|
append: appendInjectables
|
|
88
96
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IInjectableRule, IInjectable } from "../injection/Injectable";
|
|
2
2
|
import { stripJS, stripCSS } from "../helpers/minify";
|
|
3
|
+
import { Link } from "@readium/shared";
|
|
3
4
|
|
|
4
5
|
import readiumCSSWebPub from "@readium/css/css/dist/webPub/ReadiumCSS-webPub.css?raw";
|
|
5
6
|
|
|
@@ -10,7 +11,16 @@ import onloadProxyContent from "../dom/_readium_executionCleanup.js?raw";
|
|
|
10
11
|
/**
|
|
11
12
|
* Creates injectable rules for WebPub content documents
|
|
12
13
|
*/
|
|
13
|
-
export function createReadiumWebPubRules(): IInjectableRule[] {
|
|
14
|
+
export function createReadiumWebPubRules(readingOrderItems: Link[]): IInjectableRule[] {
|
|
15
|
+
// Create exact match patterns for manifest hrefs
|
|
16
|
+
const htmlHrefs = readingOrderItems
|
|
17
|
+
.filter(item => item.mediaType.isHTML)
|
|
18
|
+
.map(item => item.href);
|
|
19
|
+
|
|
20
|
+
const resources = htmlHrefs.length > 0
|
|
21
|
+
? htmlHrefs
|
|
22
|
+
: [/\.html$/, /\.xhtml$/, /\/$/]; // fallback patterns
|
|
23
|
+
|
|
14
24
|
// Core injectables that should be prepended
|
|
15
25
|
const prependInjectables: IInjectable[] = [
|
|
16
26
|
// CSS Selector Generator - always injected
|
|
@@ -51,7 +61,7 @@ export function createReadiumWebPubRules(): IInjectableRule[] {
|
|
|
51
61
|
|
|
52
62
|
return [
|
|
53
63
|
{
|
|
54
|
-
resources:
|
|
64
|
+
resources: resources,
|
|
55
65
|
prepend: prependInjectables,
|
|
56
66
|
append: appendInjectables
|
|
57
67
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
KeyCombinationManager,
|
|
3
|
+
ActivityEventDispatcher,
|
|
4
|
+
KeyboardPeripheral
|
|
5
|
+
} from "@readium/navigator-html-injectables";
|
|
6
|
+
|
|
7
|
+
export const NAVIGATOR_KEYBOARD_PERIPHERAL_EVENT = "readium:navigator:keyboardPeripheral";
|
|
8
|
+
|
|
9
|
+
export interface KeyboardPeripheralOptions {
|
|
10
|
+
/** Array of keyboard peripherals to configure */
|
|
11
|
+
keyboardPeripherals?: KeyboardPeripheral[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class KeyboardPeripherals {
|
|
15
|
+
private keydownHandler?: (event: KeyboardEvent) => void;
|
|
16
|
+
private keyManager = new KeyCombinationManager();
|
|
17
|
+
|
|
18
|
+
constructor(options: KeyboardPeripheralOptions = {}) {
|
|
19
|
+
this.setupKeyboardPeripherals(options.keyboardPeripherals || []);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private setupKeyboardPeripherals(keyboardPeripherals: KeyboardPeripheral[]) {
|
|
23
|
+
if (keyboardPeripherals.length > 0) {
|
|
24
|
+
// Create activity event dispatcher
|
|
25
|
+
const dispatcher: ActivityEventDispatcher = (activityEvent) => {
|
|
26
|
+
const customEvent = new CustomEvent(NAVIGATOR_KEYBOARD_PERIPHERAL_EVENT, {
|
|
27
|
+
detail: activityEvent
|
|
28
|
+
});
|
|
29
|
+
window.dispatchEvent(customEvent);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Create unified handler using the provided keyboard peripherals
|
|
33
|
+
this.keydownHandler = this.keyManager.createUnifiedHandler(
|
|
34
|
+
"", // Empty string as target frame source for main window
|
|
35
|
+
keyboardPeripherals,
|
|
36
|
+
dispatcher
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
if (this.keydownHandler) {
|
|
40
|
+
document.addEventListener("keydown", this.keydownHandler, true);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
window.addEventListener("unload", () => this.destroy());
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public destroy() {
|
|
48
|
+
if (this.keydownHandler) {
|
|
49
|
+
document.removeEventListener("keydown", this.keydownHandler, true);
|
|
50
|
+
this.keydownHandler = undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export interface AutomationDetectorOptions {
|
|
2
|
+
/** Callback when an automation tool is detected */
|
|
3
|
+
onDetected?: (tool: string) => void;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export class AutomationDetector {
|
|
7
|
+
private options: AutomationDetectorOptions;
|
|
8
|
+
private detectedTools = new Set<string>();
|
|
9
|
+
private observer?: MutationObserver;
|
|
10
|
+
|
|
11
|
+
constructor(options: AutomationDetectorOptions) {
|
|
12
|
+
if (!options.onDetected) {
|
|
13
|
+
throw new Error('onDetected callback is required');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
this.options = options;
|
|
17
|
+
this.setupDetection();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
private isAutomationToolPresent(): string | null {
|
|
21
|
+
const win = window as any;
|
|
22
|
+
|
|
23
|
+
if (win.domAutomation || win.domAutomationController) return "Selenium";
|
|
24
|
+
if (navigator.webdriver === true) return "Puppeteer/Playwright";
|
|
25
|
+
if (win.__webdriver_evaluate || win.__selenium_evaluate) return "Chrome Automation";
|
|
26
|
+
if (win.callPhantom || win._phantom) return "PhantomJS";
|
|
27
|
+
if (win.__nightmare) return "Nightmare";
|
|
28
|
+
if (win.$testCafe) return "TestCafe";
|
|
29
|
+
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private setupDetection() {
|
|
34
|
+
const tool = this.isAutomationToolPresent();
|
|
35
|
+
if (tool) {
|
|
36
|
+
this.handleDetected(tool);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
this.observer = new MutationObserver(() => {
|
|
41
|
+
const tool = this.isAutomationToolPresent();
|
|
42
|
+
if (tool && !this.detectedTools.has(tool)) {
|
|
43
|
+
this.handleDetected(tool);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
this.observer.observe(document.documentElement, {
|
|
48
|
+
childList: true,
|
|
49
|
+
subtree: true,
|
|
50
|
+
attributes: true
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
window.addEventListener("unload", () => this.destroy());
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private handleDetected(tool: string) {
|
|
57
|
+
this.detectedTools.add(tool);
|
|
58
|
+
this.options.onDetected?.(tool);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public destroy() {
|
|
62
|
+
this.observer?.disconnect();
|
|
63
|
+
this.observer = undefined;
|
|
64
|
+
this.detectedTools.clear();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ContextMenuEvent } from "@readium/navigator-html-injectables";
|
|
2
|
+
|
|
3
|
+
export interface ContextMenuProtectionOptions {
|
|
4
|
+
onContextMenuBlocked?: (event: ContextMenuEvent) => void;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export class ContextMenuProtector {
|
|
8
|
+
private contextMenuHandler?: (event: MouseEvent) => void;
|
|
9
|
+
private onContextMenuBlocked?: (event: ContextMenuEvent) => void;
|
|
10
|
+
|
|
11
|
+
constructor(options: ContextMenuProtectionOptions = {}) {
|
|
12
|
+
this.onContextMenuBlocked = options.onContextMenuBlocked;
|
|
13
|
+
this.contextMenuHandler = this.handleContextMenu.bind(this);
|
|
14
|
+
document.addEventListener("contextmenu", this.contextMenuHandler, true);
|
|
15
|
+
|
|
16
|
+
window.addEventListener("unload", () => this.destroy());
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
private handleContextMenu(event: MouseEvent) {
|
|
20
|
+
event.preventDefault();
|
|
21
|
+
event.stopPropagation();
|
|
22
|
+
|
|
23
|
+
// Create context menu event
|
|
24
|
+
const activityEvent: ContextMenuEvent & { type: "context_menu" } = {
|
|
25
|
+
type: "context_menu",
|
|
26
|
+
timestamp: Date.now(),
|
|
27
|
+
clientX: event.clientX,
|
|
28
|
+
clientY: event.clientY,
|
|
29
|
+
targetFrameSrc: ''
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Call the callback if provided
|
|
33
|
+
if (this.onContextMenuBlocked) {
|
|
34
|
+
this.onContextMenuBlocked(activityEvent);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public destroy() {
|
|
41
|
+
if (this.contextMenuHandler) {
|
|
42
|
+
document.removeEventListener("contextmenu", this.contextMenuHandler, true);
|
|
43
|
+
this.contextMenuHandler = undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|