@readium/navigator-html-injectables 2.2.5 → 2.3.1-alpha.1

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.
Files changed (37) hide show
  1. package/dist/index.js +1133 -563
  2. package/dist/index.umd.cjs +23 -9
  3. package/package.json +8 -8
  4. package/src/comms/keys.ts +22 -3
  5. package/src/helpers/css.ts +2 -0
  6. package/src/index.ts +2 -1
  7. package/src/modules/ModuleLibrary.ts +10 -4
  8. package/src/modules/Peripherals.ts +458 -13
  9. package/src/modules/snapper/ColumnSnapper.ts +85 -5
  10. package/src/modules/snapper/ScrollSnapper.ts +59 -1
  11. package/src/modules/snapper/WebPubSnapper.ts +57 -3
  12. package/src/protection/BulkCopyProtector.ts +134 -0
  13. package/src/protection/KeyCombinationManager.ts +139 -0
  14. package/src/protection/KeyboardCombinations.ts +60 -0
  15. package/src/protection/PatternAnalyzer.ts +117 -0
  16. package/src/protection/PrintProtector.ts +87 -0
  17. package/src/protection/SelectionAnalyzer.ts +133 -0
  18. package/src/protection/config.ts +33 -0
  19. package/src/protection/index.ts +6 -0
  20. package/types/src/comms/keys.d.ts +3 -2
  21. package/types/src/helpers/css.d.ts +1 -0
  22. package/types/src/index.d.ts +1 -0
  23. package/types/src/modules/ModuleLibrary.d.ts +1 -1
  24. package/types/src/modules/Peripherals.d.ts +102 -2
  25. package/types/src/modules/snapper/ColumnSnapper.d.ts +10 -0
  26. package/types/src/modules/snapper/ScrollSnapper.d.ts +13 -0
  27. package/types/src/modules/snapper/WebPubSnapper.d.ts +6 -0
  28. package/types/src/protection/BulkCopyProtector.d.ts +20 -0
  29. package/types/src/protection/KeyCombinationManager.d.ts +33 -0
  30. package/types/src/protection/KeyboardCombinations.d.ts +15 -0
  31. package/types/src/protection/PatternAnalyzer.d.ts +18 -0
  32. package/types/src/protection/PrintProtector.d.ts +20 -0
  33. package/types/src/protection/SelectionAnalyzer.d.ts +20 -0
  34. package/types/src/protection/config.d.ts +7 -0
  35. package/types/src/protection/index.d.ts +6 -0
  36. package/src/types/protection.ts +0 -16
  37. package/types/src/types/protection.d.ts +0 -7
@@ -2,11 +2,16 @@ import { Comms } from "../../comms/comms";
2
2
  import { ReadiumWindow } from "../../helpers/dom";
3
3
  import { ModuleName } from "../ModuleLibrary";
4
4
  import { Snapper } from "./Snapper";
5
+ import { SuspiciousScrollingEvent } from "./ScrollSnapper";
6
+ export type { SuspiciousScrollingEvent };
5
7
  export declare class WebPubSnapper extends Snapper {
6
8
  static readonly moduleName: ModuleName;
7
9
  private wnd;
8
10
  private comms;
9
11
  private resizeObserver;
12
+ private patternAnalyzer;
13
+ private lastScrollTime;
14
+ private isScrollProtectionEnabled;
10
15
  private initialScrollHandled;
11
16
  private isScrolling;
12
17
  private lastScrollTop;
@@ -15,6 +20,7 @@ export declare class WebPubSnapper extends Snapper {
15
20
  private doc;
16
21
  private reportProgress;
17
22
  private handleScroll;
23
+ private enableScrollProtection;
18
24
  mount(wnd: ReadiumWindow, comms: Comms): boolean;
19
25
  unmount(wnd: ReadiumWindow, comms: Comms): boolean;
20
26
  }
@@ -0,0 +1,20 @@
1
+ import { ReadiumWindow } from "../helpers/dom";
2
+ export interface BulkCopyProtectionOptions {
3
+ enabled: boolean;
4
+ maxSelectionPercent: number;
5
+ absoluteMaxChars: number;
6
+ minThreshold: number;
7
+ historySize: number;
8
+ }
9
+ export declare class BulkCopyProtector {
10
+ private readonly window;
11
+ private options;
12
+ private copyHistory;
13
+ private lastSelectionLength;
14
+ private lastSelectionTime;
15
+ constructor(window: ReadiumWindow, options: BulkCopyProtectionOptions);
16
+ private cleanupOldHistory;
17
+ private isSuspiciousPattern;
18
+ shouldAllowCopy(event: ClipboardEvent): boolean;
19
+ destroy(): void;
20
+ }
@@ -0,0 +1,33 @@
1
+ import { KeyCombo, KeyboardPeripheral } from "./KeyboardCombinations";
2
+ import { BaseKeyboardPeripheralEvent, KeyboardEventData } from "../modules/Peripherals";
3
+ import { ReadiumWindow } from "../helpers/dom";
4
+ export type KeyHandler = (event: KeyboardEvent) => void;
5
+ export type ActivityEventDispatcher = (event: KeyboardPeripheralEvent) => void;
6
+ export interface KeyboardPeripheralEvent extends BaseKeyboardPeripheralEvent, KeyboardEventData {
7
+ type: string;
8
+ }
9
+ export interface KeyComboWithHandler extends KeyCombo {
10
+ handler?: (event: KeyboardEvent) => void;
11
+ }
12
+ export declare class KeyCombinationManager {
13
+ /**
14
+ * Checks if the given keyboard event matches any of the provided key combinations
15
+ */
16
+ match(event: KeyboardEvent, combos: KeyCombo[]): boolean;
17
+ /**
18
+ * Creates an event handler that will call the provided handler when any of the key combinations match
19
+ */
20
+ createKeyHandler(combos: KeyCombo[], handler: KeyHandler): (event: KeyboardEvent) => void;
21
+ /**
22
+ * Creates a standardized activity event for keyboard shortcuts
23
+ */
24
+ private createActivityEvent;
25
+ /**
26
+ * Creates handlers for keyboard shortcuts with centralized activity event dispatch
27
+ */
28
+ createKeyboardHandlers(targetFrameSrc: string, shortcuts: KeyboardPeripheral[], dispatcher: ActivityEventDispatcher, wnd?: ReadiumWindow): KeyComboWithHandler[];
29
+ /**
30
+ * Creates a unified keyboard event handler that processes all shortcuts
31
+ */
32
+ createUnifiedHandler(targetFrameSrc: string, shortcuts: KeyboardPeripheral[], dispatcher: ActivityEventDispatcher, wnd?: ReadiumWindow): (event: KeyboardEvent) => void;
33
+ }
@@ -0,0 +1,15 @@
1
+ export interface KeyCombo {
2
+ keyCode: number;
3
+ ctrl?: boolean;
4
+ shift?: boolean;
5
+ alt?: boolean;
6
+ meta?: boolean;
7
+ }
8
+ export interface KeyboardPeripheral {
9
+ type: string;
10
+ keyCombos: KeyCombo[];
11
+ }
12
+ export declare const DEV_TOOLS: KeyboardPeripheral;
13
+ export declare const SELECT_ALL: KeyboardPeripheral;
14
+ export declare const PRINT: KeyboardPeripheral;
15
+ export declare const SAVE: KeyboardPeripheral;
@@ -0,0 +1,18 @@
1
+ type Direction = "left" | "right" | "up" | "down";
2
+ export interface PatternAnalyzerOptions {
3
+ maxVelocity: number;
4
+ minVariance: number;
5
+ historySize?: number;
6
+ minDirectionChanges?: number;
7
+ maxConsistentScrolls?: number;
8
+ }
9
+ export declare class PatternAnalyzer {
10
+ private options;
11
+ private history;
12
+ private consistentScrollCount;
13
+ constructor(options?: Partial<PatternAnalyzerOptions>);
14
+ analyze(direction: Direction, distance: number, timeDelta: number): boolean;
15
+ private resetAfterDetection;
16
+ clear(): void;
17
+ }
18
+ export {};
@@ -0,0 +1,20 @@
1
+ import { Comms } from "../comms";
2
+ import { ReadiumWindow } from "../helpers/dom";
3
+ import { Module } from "../modules/Module";
4
+ import { ModuleName } from "../modules/ModuleLibrary";
5
+ export interface PrintProtectionConfig {
6
+ disable?: boolean;
7
+ watermark?: string;
8
+ }
9
+ export declare class PrintProtector extends Module {
10
+ static readonly moduleName: ModuleName;
11
+ private comms;
12
+ private wnd;
13
+ private styleElement;
14
+ private beforePrintHandler;
15
+ private configApplied;
16
+ private setupPrintProtection;
17
+ private registerPrintHandlers;
18
+ mount(wnd: ReadiumWindow, comms: Comms): boolean;
19
+ unmount(wnd: ReadiumWindow, _comms: Comms): boolean;
20
+ }
@@ -0,0 +1,20 @@
1
+ export interface SelectionAnalyzerOptions {
2
+ maxSelectionsPerSecond: number;
3
+ minVariance: number;
4
+ historySize: number;
5
+ }
6
+ export declare class SelectionAnalyzer {
7
+ private readonly options;
8
+ private events;
9
+ private selectionStartTime;
10
+ private lastSelectionTime;
11
+ private lastSelectionPosition;
12
+ private selectionPatterns;
13
+ private lastSelectedText;
14
+ constructor(options?: SelectionAnalyzerOptions);
15
+ analyze(selection: Selection | null): boolean;
16
+ private analyzeSelectionPattern;
17
+ private calculateVariance;
18
+ private cleanup;
19
+ clear(): void;
20
+ }
@@ -0,0 +1,7 @@
1
+ import { BulkCopyProtectionOptions } from "./BulkCopyProtector";
2
+ import { PatternAnalyzerOptions } from "./PatternAnalyzer";
3
+ import { SelectionAnalyzerOptions } from "./SelectionAnalyzer";
4
+ export declare const DEFAULT_PATTERN_ANALYZER_CONFIG: PatternAnalyzerOptions;
5
+ export declare const SCROLL_PROTECTION_CONFIG: PatternAnalyzerOptions;
6
+ export declare const SELECTION_ANALYZER_CONFIG: SelectionAnalyzerOptions;
7
+ export declare const BULK_COPY_CONFIG: BulkCopyProtectionOptions;
@@ -0,0 +1,6 @@
1
+ export * from "./BulkCopyProtector";
2
+ export * from "./KeyCombinationManager";
3
+ export * from "./KeyboardCombinations";
4
+ export * from "./PatternAnalyzer";
5
+ export * from "./SelectionAnalyzer";
6
+ export * from "./PrintProtector";
@@ -1,16 +0,0 @@
1
- type SuspiciousActivityType =
2
- | "developer_tools_attempt"
3
- | "select_all_attempt"
4
- | "suspicious_selection"
5
- | "suspicious_copy"
6
- | "suspicious_scrolling"
7
- | "suspicious_snapping"
8
- | "drag_detected"
9
- | "drop_detected"
10
- | "context_menu";
11
-
12
- export interface SuspiciousActivityEvent {
13
- timestamp: number;
14
- type: SuspiciousActivityType;
15
- event?: Event;
16
- }
@@ -1,7 +0,0 @@
1
- type SuspiciousActivityType = "developer_tools_attempt" | "select_all_attempt" | "suspicious_selection" | "suspicious_copy" | "suspicious_scrolling" | "suspicious_snapping" | "drag_detected" | "drop_detected" | "context_menu";
2
- export interface SuspiciousActivityEvent {
3
- timestamp: number;
4
- type: SuspiciousActivityType;
5
- event?: Event;
6
- }
7
- export {};