@readium/navigator-html-injectables 2.4.3 → 2.5.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 +1610 -1181
- package/dist/index.umd.cjs +19 -18
- package/package.json +2 -1
- package/src/comms/keys.ts +3 -2
- package/src/helpers/color.ts +63 -0
- package/src/helpers/css.ts +29 -0
- package/src/helpers/document.ts +120 -0
- package/src/helpers/rect.ts +10 -5
- package/src/helpers/sML.ts +143 -0
- package/src/helpers/sanitize.ts +77 -0
- package/src/index.ts +2 -1
- package/src/keyboard/KeyCombinationManager.ts +1 -0
- package/src/modules/Decorator.ts +600 -151
- package/src/modules/Peripherals.ts +3 -0
- package/src/modules/snapper/ColumnSnapper.ts +2 -1
- package/types/src/comms/keys.d.ts +2 -2
- package/types/src/helpers/color.d.ts +1 -0
- package/types/src/helpers/css.d.ts +6 -0
- package/types/src/helpers/document.d.ts +66 -0
- package/types/src/helpers/rect.d.ts +1 -1
- package/types/src/helpers/sML.d.ts +56 -0
- package/types/src/helpers/sanitize.d.ts +13 -0
- package/types/src/index.d.ts +1 -0
- package/types/src/modules/Decorator.d.ts +62 -13
- package/types/src/modules/Peripherals.d.ts +3 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Locator } from "@readium/shared";
|
|
1
2
|
import { Comms } from "../comms/comms.ts";
|
|
2
3
|
import { Module } from "./Module.ts";
|
|
3
4
|
import { ReadiumWindow, nearestInteractiveElement } from "../helpers/dom.ts";
|
|
@@ -28,6 +29,8 @@ export interface BasicTextSelection {
|
|
|
28
29
|
width: number;
|
|
29
30
|
height: number;
|
|
30
31
|
targetFrameSrc: string;
|
|
32
|
+
/** Locator for the frame the selection originated from. Populated by the navigator. */
|
|
33
|
+
locator?: Locator;
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
export interface BaseSuspiciousActivityEvent {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Comms } from "../../comms/index.ts";
|
|
2
2
|
import { Snapper } from "./Snapper.ts";
|
|
3
3
|
import { getColumnCountPerScreen, isRTL, appendVirtualColumnIfNeeded } from "../../helpers/document.ts";
|
|
4
|
+
import { styleChangeAffectsLayout } from "../../helpers/css.ts";
|
|
4
5
|
import { easeInOutQuad } from "../../helpers/animation.ts";
|
|
5
6
|
import { ModuleName } from "../ModuleLibrary.ts";
|
|
6
7
|
import { Locator, LocatorLocations, LocatorText } from "@readium/shared";
|
|
@@ -392,7 +393,7 @@ export class ColumnSnapper extends Snapper {
|
|
|
392
393
|
const oldValueTransform = oldValue?.match(transformRegex);
|
|
393
394
|
const newValueTransform = newValue?.match(transformRegex);
|
|
394
395
|
if (
|
|
395
|
-
(!oldValueTransform && !newValueTransform) ||
|
|
396
|
+
(!oldValueTransform && !newValueTransform && styleChangeAffectsLayout(oldValue, newValue)) ||
|
|
396
397
|
(oldValueTransform && !newValueTransform) ||
|
|
397
398
|
(oldValueTransform && newValueTransform && oldValueTransform[1] !== newValueTransform[1])
|
|
398
399
|
) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type CommsEventKey = "_pong" | "_unhandled" | "_ack" | "log" | "error" | "click" | "tap" | "tap_more" | "no_more" | "no_less" | "swipe" | "scroll" | "progress" | "first_visible_locator" | "text_selected" | "context_menu" | "media_play" | "media_pause" | "content_protection" | "keyboard_peripherals";
|
|
2
|
-
export type CommsCommandKey = "_ping" | "go_prev" | "go_next" | "go_id" | "go_text" | "go_end" | "go_start" | "go_progression" | "get_properties" | "update_properties" | "set_property" | "remove_property" | "first_visible_locator" | "decorate" | "protect" | "unprotect" | "unfocus" | "focus" | "activate" | "shake" | "force_webkit_recalc" | "peripherals_protection" | "keyboard_peripherals" | "scroll_protection" | "print_protection";
|
|
1
|
+
export type CommsEventKey = "_pong" | "_unhandled" | "_ack" | "log" | "error" | "click" | "tap" | "tap_more" | "no_more" | "no_less" | "swipe" | "scroll" | "progress" | "first_visible_locator" | "text_selected" | "context_menu" | "media_play" | "media_pause" | "content_protection" | "keyboard_peripherals" | "decoration_activated";
|
|
2
|
+
export type CommsCommandKey = "_ping" | "go_prev" | "go_next" | "go_id" | "go_text" | "go_end" | "go_start" | "go_progression" | "get_properties" | "update_properties" | "set_property" | "remove_property" | "first_visible_locator" | "decorate" | "decoration_activatable" | "protect" | "unprotect" | "unfocus" | "focus" | "activate" | "shake" | "force_webkit_recalc" | "peripherals_protection" | "keyboard_peripherals" | "scroll_protection" | "print_protection";
|
|
3
3
|
export type SuspiciousActivityType = "developer_tools" | "select_all" | "save" | "suspicious_selection" | "bulk_copy" | "suspicious_scrolling" | "suspicious_snapping" | "drag_detected" | "drop_detected" | "print";
|
|
@@ -24,3 +24,4 @@ export declare const checkContrast: (color1: string | {
|
|
|
24
24
|
export declare const isDarkColor: (color: string, blendedWith?: string | null) => boolean;
|
|
25
25
|
export declare const isLightColor: (color: string, blendedWith?: string | null) => boolean;
|
|
26
26
|
export declare const getContrastingTextColor: (color: string, blendedWith?: string | null) => "black" | "white";
|
|
27
|
+
export declare const adjustColorForContrast: (baseColor: string, backgroundColor?: string | null, targetContrast?: number) => string;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { ReadiumWindow } from "./dom.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Returns true if the style attribute change between oldValue and newValue
|
|
4
|
+
* includes at least one ReadiumCSS property that affects document layout/geometry.
|
|
5
|
+
* Pure appearance changes (colors, filters) return false.
|
|
6
|
+
*/
|
|
7
|
+
export declare function styleChangeAffectsLayout(oldValue: string | null, newValue: string | null): boolean;
|
|
2
8
|
export declare function getProperties(wnd: ReadiumWindow): {
|
|
3
9
|
[key: string]: string;
|
|
4
10
|
};
|
|
@@ -1,6 +1,72 @@
|
|
|
1
1
|
import { ReadiumWindow } from "./dom.ts";
|
|
2
2
|
export declare function isRTL(wnd: ReadiumWindow): boolean;
|
|
3
3
|
export declare function isVerticalLR(wnd: ReadiumWindow): boolean;
|
|
4
|
+
export declare function isVerticalWriting(wnd: ReadiumWindow): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Axis-normalizing context for decoration layout.
|
|
7
|
+
*
|
|
8
|
+
* Translates CSS physical properties into logical inline/block terms so that
|
|
9
|
+
* callers can position elements identically regardless of writing mode:
|
|
10
|
+
*
|
|
11
|
+
* horizontal writing → inline = horizontal, block = vertical
|
|
12
|
+
* vertical writing → inline = vertical, block = horizontal
|
|
13
|
+
*/
|
|
14
|
+
export interface WritingContext {
|
|
15
|
+
isVertical: boolean;
|
|
16
|
+
isVertLR: boolean;
|
|
17
|
+
/** Viewport size along the inline axis (innerWidth / innerHeight). */
|
|
18
|
+
viewportInlineSize: number;
|
|
19
|
+
/** Viewport size along the block axis (innerHeight / innerWidth). */
|
|
20
|
+
viewportBlockSize: number;
|
|
21
|
+
/**
|
|
22
|
+
* Size of a single page along the inline axis.
|
|
23
|
+
* Horizontal: viewportWidth / columnCount.
|
|
24
|
+
* Vertical: viewportHeight (no columns).
|
|
25
|
+
*/
|
|
26
|
+
pageInlineSize: number;
|
|
27
|
+
/**
|
|
28
|
+
* Physical x offset to add to a client-space x coordinate to get document space.
|
|
29
|
+
* Horizontal: scrollLeft (non-negative).
|
|
30
|
+
* Vertical-rl: scrollWidth − viewportWidth + scrollLeft (scrollLeft is negative,
|
|
31
|
+
* so this normalises it to the viewport's left edge in document coordinates).
|
|
32
|
+
* Vertical-lr: scrollLeft (non-negative, same as horizontal).
|
|
33
|
+
*/
|
|
34
|
+
xDocOffset: number;
|
|
35
|
+
/** Physical y offset to add to a client-space y coordinate to get document space (scrollTop). */
|
|
36
|
+
yDocOffset: number;
|
|
37
|
+
/** Scroll offset along the inline axis, derived from xDocOffset / yDocOffset. */
|
|
38
|
+
inlineScrollOffset: number;
|
|
39
|
+
/** Scroll offset along the block axis, derived from xDocOffset / yDocOffset. */
|
|
40
|
+
blockScrollOffset: number;
|
|
41
|
+
/** Logical inline start of a rect (left / top). */
|
|
42
|
+
inlineStart(r: DOMRect | {
|
|
43
|
+
top: number;
|
|
44
|
+
left: number;
|
|
45
|
+
}): number;
|
|
46
|
+
/** Logical block start of a rect (top / left). */
|
|
47
|
+
blockStart(r: DOMRect | {
|
|
48
|
+
top: number;
|
|
49
|
+
left: number;
|
|
50
|
+
}): number;
|
|
51
|
+
/** Logical inline size of a rect (width / height). */
|
|
52
|
+
inlineSize(r: DOMRect | {
|
|
53
|
+
width: number;
|
|
54
|
+
height: number;
|
|
55
|
+
}): number;
|
|
56
|
+
/** Logical block size of a rect (height / width). */
|
|
57
|
+
blockSize(r: DOMRect | {
|
|
58
|
+
width: number;
|
|
59
|
+
height: number;
|
|
60
|
+
}): number;
|
|
61
|
+
/**
|
|
62
|
+
* Set absolute position on an element using logical coordinates.
|
|
63
|
+
* `iz` is the inverse zoom factor (1 in non-Blink, 1/zoom in Blink).
|
|
64
|
+
*/
|
|
65
|
+
applyPosition(el: HTMLElement, inlineStart: number, blockStart: number, inlineSize: number, blockSize: number, iz: number): void;
|
|
66
|
+
/** Convert logical coordinates back to a physical DOMRect. */
|
|
67
|
+
toRect(inlineStart: number, blockStart: number, inlineSize: number, blockSize: number): DOMRect;
|
|
68
|
+
}
|
|
69
|
+
export declare function makeWritingContext(wnd: ReadiumWindow): WritingContext;
|
|
4
70
|
export declare function getColumnCountPerScreen(wnd: ReadiumWindow): number;
|
|
5
71
|
/**
|
|
6
72
|
* Returns the "content height" of an element, which is its clientHeight
|
|
@@ -6,5 +6,5 @@ export interface Rect {
|
|
|
6
6
|
top: number;
|
|
7
7
|
width: number;
|
|
8
8
|
}
|
|
9
|
-
export declare function getClientRectsNoOverlap(range: Range, doNotMergeHorizontallyAlignedRects: boolean): Rect[];
|
|
9
|
+
export declare function getClientRectsNoOverlap(range: Range, doNotMergeHorizontallyAlignedRects: boolean, doNotMergeVerticallyAlignedRects?: boolean): Rect[];
|
|
10
10
|
export declare function rectContainsPoint(rect: Rect, x: number, y: number, tolerance: number): boolean;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* (℠)
|
|
3
|
+
* # sML.js | I'm a Simple and Middling Library.
|
|
4
|
+
*
|
|
5
|
+
* * Copyright (c) Satoru MATSUSHIMA - https://github.com/satorumurmur/sML
|
|
6
|
+
* * Licensed under the MIT license. - http://www.opensource.org/licenses/mit-license.php
|
|
7
|
+
*
|
|
8
|
+
* Portions of this code come from the sML library
|
|
9
|
+
* Current version: 1.0.36
|
|
10
|
+
*/
|
|
11
|
+
declare interface OSFlags {
|
|
12
|
+
iOS: number[];
|
|
13
|
+
macOS: number[];
|
|
14
|
+
iPadOS: number[];
|
|
15
|
+
WindowsPhone: number[];
|
|
16
|
+
ChromeOS: number[];
|
|
17
|
+
Windows: number[];
|
|
18
|
+
Android: number[];
|
|
19
|
+
Linux: number[];
|
|
20
|
+
Firefox: boolean;
|
|
21
|
+
}
|
|
22
|
+
declare interface UAFlags {
|
|
23
|
+
Gecko: number[];
|
|
24
|
+
Firefox: number[];
|
|
25
|
+
Waterfox: number[];
|
|
26
|
+
Opera: number[];
|
|
27
|
+
Silk: number[];
|
|
28
|
+
Blink: number[];
|
|
29
|
+
EdgeHTML: number[];
|
|
30
|
+
Chrome: number[];
|
|
31
|
+
Chromium: number[];
|
|
32
|
+
Phoebe: number[];
|
|
33
|
+
UCBrowser: number[];
|
|
34
|
+
Vivaldi: number[];
|
|
35
|
+
Safari: number[];
|
|
36
|
+
Edge: number[];
|
|
37
|
+
WebKit: number[];
|
|
38
|
+
Trident: number[];
|
|
39
|
+
InternetExplorer: number[];
|
|
40
|
+
Flash: number[];
|
|
41
|
+
Facebook: number[];
|
|
42
|
+
LINE: number[];
|
|
43
|
+
}
|
|
44
|
+
declare type iOSRequest = "mobile" | "desktop" | undefined;
|
|
45
|
+
declare class sMLFactory {
|
|
46
|
+
OS: OSFlags;
|
|
47
|
+
UA: UAFlags;
|
|
48
|
+
Env: string[];
|
|
49
|
+
constructor();
|
|
50
|
+
}
|
|
51
|
+
declare class sMLFactoryWithRequest extends sMLFactory {
|
|
52
|
+
get iOSRequest(): iOSRequest;
|
|
53
|
+
}
|
|
54
|
+
declare const sML: sMLFactory;
|
|
55
|
+
declare const sMLWithRequest: sMLFactoryWithRequest;
|
|
56
|
+
export { sML, sMLWithRequest };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses `html` and returns its first element child with all executable
|
|
3
|
+
* content removed. Uses the Sanitizer API when available, falls back to a
|
|
4
|
+
* manual DOMParser scrub otherwise.
|
|
5
|
+
*
|
|
6
|
+
* The allowlist approach is intentional: unknown or future elements are
|
|
7
|
+
* stripped by default rather than permitted by oversight.
|
|
8
|
+
*
|
|
9
|
+
* @param wnd Window whose document is used when adopting nodes.
|
|
10
|
+
* @param html Raw HTML string supplied by the caller.
|
|
11
|
+
* @returns The sanitized first element child, or `null` for empty input.
|
|
12
|
+
*/
|
|
13
|
+
export declare function sanitizeHTML(wnd: Window, html: string): Element | null;
|
package/types/src/index.d.ts
CHANGED
|
@@ -3,42 +3,91 @@ import { Comms } from "../comms/comms.ts";
|
|
|
3
3
|
import { Module } from "./Module.ts";
|
|
4
4
|
import { ModuleName } from "./ModuleLibrary.ts";
|
|
5
5
|
import { ReadiumWindow } from "../helpers/dom.ts";
|
|
6
|
-
export declare
|
|
6
|
+
export declare const DecorationStyleType: {
|
|
7
|
+
readonly Highlight: "highlight";
|
|
8
|
+
readonly Underline: "underline";
|
|
9
|
+
readonly Outline: "outline";
|
|
10
|
+
readonly TextColor: "textColor";
|
|
11
|
+
readonly Mask: "mask";
|
|
12
|
+
readonly Template: "template";
|
|
13
|
+
};
|
|
14
|
+
export type DecorationStyleType = typeof DecorationStyleType[keyof typeof DecorationStyleType];
|
|
15
|
+
export declare enum DecorationWidth {
|
|
7
16
|
Wrap = "wrap",// Smallest width fitting the CSS border box.
|
|
8
17
|
Viewport = "viewport",// Fills the whole viewport.
|
|
9
|
-
Bounds = "bounds",// Fills the
|
|
18
|
+
Bounds = "bounds",// Fills the bounding region of all CSS border boxes.
|
|
10
19
|
Page = "page"
|
|
11
20
|
}
|
|
12
|
-
export declare enum
|
|
21
|
+
export declare enum DecorationLayout {
|
|
13
22
|
Boxes = "boxes",// One HTML element for each CSS border box (e.g. line of text).
|
|
14
23
|
Bounds = "bounds"
|
|
15
24
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
/** Built-in decoration styles. layout/width are optional overrides; defaults are Boxes/Wrap. */
|
|
26
|
+
export interface BuiltinDecorationStyle {
|
|
27
|
+
type?: Exclude<DecorationStyleType, "template">;
|
|
28
|
+
tint?: string;
|
|
29
|
+
layout?: DecorationLayout;
|
|
30
|
+
width?: DecorationWidth;
|
|
31
|
+
isActive?: boolean;
|
|
32
|
+
enforceContrast?: boolean;
|
|
20
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Custom decoration style backed by caller-supplied HTML.
|
|
36
|
+
* Matches the HTMLDecorationTemplate class from the Readium spec.
|
|
37
|
+
* The element string is sanitized before injection.
|
|
38
|
+
* --readium-tint is injected as a CSS custom property on each created element.
|
|
39
|
+
*/
|
|
40
|
+
export interface HTMLDecorationTemplate {
|
|
41
|
+
type: "template";
|
|
42
|
+
layout: DecorationLayout;
|
|
43
|
+
width: DecorationWidth;
|
|
44
|
+
element: string;
|
|
45
|
+
stylesheet?: string;
|
|
46
|
+
isActive?: boolean;
|
|
47
|
+
}
|
|
48
|
+
export type DecorationStyle = BuiltinDecorationStyle | HTMLDecorationTemplate;
|
|
21
49
|
export interface Decoration {
|
|
22
50
|
id: string;
|
|
23
51
|
locator: Locator;
|
|
24
|
-
style:
|
|
52
|
+
style: DecorationStyle;
|
|
53
|
+
extras?: Record<string, unknown>;
|
|
25
54
|
}
|
|
26
|
-
export interface
|
|
55
|
+
export interface DecorationActivatedEvent {
|
|
56
|
+
decorationId: string;
|
|
27
57
|
group: string;
|
|
28
|
-
|
|
29
|
-
|
|
58
|
+
rect: {
|
|
59
|
+
top: number;
|
|
60
|
+
left: number;
|
|
61
|
+
width: number;
|
|
62
|
+
height: number;
|
|
63
|
+
};
|
|
64
|
+
point: {
|
|
65
|
+
x: number;
|
|
66
|
+
y: number;
|
|
67
|
+
};
|
|
30
68
|
}
|
|
69
|
+
export type DecoratorRequest = {
|
|
70
|
+
group: string;
|
|
71
|
+
action: "add" | "update";
|
|
72
|
+
decoration: Decoration;
|
|
73
|
+
} | {
|
|
74
|
+
group: string;
|
|
75
|
+
action: "remove";
|
|
76
|
+
decoration: Pick<Decoration, "id">;
|
|
77
|
+
} | {
|
|
78
|
+
group: string;
|
|
79
|
+
action: "clear";
|
|
80
|
+
};
|
|
31
81
|
export declare class Decorator extends Module {
|
|
32
82
|
static readonly moduleName: ModuleName;
|
|
33
83
|
private resizeObserver;
|
|
34
|
-
private
|
|
84
|
+
private styleObserver;
|
|
35
85
|
private wnd;
|
|
36
86
|
private resizeFrame;
|
|
37
87
|
private lastGroupId;
|
|
38
88
|
private groups;
|
|
39
89
|
private cleanup;
|
|
40
90
|
private updateHighlightStyles;
|
|
41
|
-
private extractCustomProperty;
|
|
42
91
|
private handleResize;
|
|
43
92
|
private readonly handleResizer;
|
|
44
93
|
mount(wnd: ReadiumWindow, comms: Comms): boolean;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Locator } from "@readium/shared";
|
|
1
2
|
import { Comms } from "../comms/comms.ts";
|
|
2
3
|
import { Module } from "./Module.ts";
|
|
3
4
|
import { ReadiumWindow } from "../helpers/dom.ts";
|
|
@@ -24,6 +25,8 @@ export interface BasicTextSelection {
|
|
|
24
25
|
width: number;
|
|
25
26
|
height: number;
|
|
26
27
|
targetFrameSrc: string;
|
|
28
|
+
/** Locator for the frame the selection originated from. Populated by the navigator. */
|
|
29
|
+
locator?: Locator;
|
|
27
30
|
}
|
|
28
31
|
export interface BaseSuspiciousActivityEvent {
|
|
29
32
|
type: SuspiciousActivityType;
|