@readium/navigator-html-injectables 2.5.0 → 2.6.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/Loader.js +1 -0
- package/dist/comms/comms.js +1 -0
- package/dist/comms/mid.js +1 -0
- package/dist/helpers/animation.js +1 -0
- package/dist/helpers/css.js +1 -0
- package/dist/helpers/document.js +1 -0
- package/dist/helpers/dom.js +1 -0
- package/dist/helpers/locator.js +1 -0
- package/dist/helpers/rect.js +1 -0
- package/dist/helpers/sanitize.js +1 -0
- package/dist/index.js +1 -4601
- package/dist/keyboard/KeyCombinationManager.js +1 -0
- package/dist/keyboard/KeyboardCombinations.js +1 -0
- package/dist/modules/Decorator.js +24 -0
- package/dist/modules/Module.js +1 -0
- package/dist/modules/ModuleLibrary.js +1 -0
- package/dist/modules/Peripherals.js +1 -0
- package/dist/modules/setup/FixedSetup.js +13 -0
- package/dist/modules/setup/ReflowableSetup.js +1 -0
- package/dist/modules/setup/Setup.js +1 -0
- package/dist/modules/setup/WebPubSetup.js +1 -0
- package/dist/modules/snapper/CJKVerticalSnapper.js +12 -0
- package/dist/modules/snapper/ColumnSnapper.js +35 -0
- package/dist/modules/snapper/ScrollSnapper.js +9 -0
- package/dist/modules/snapper/Snapper.js +5 -0
- package/dist/modules/snapper/WebPubSnapper.js +1 -0
- package/dist/protection/BulkCopyProtector.js +1 -0
- package/dist/protection/PatternAnalyzer.js +1 -0
- package/dist/protection/PrintProtector.js +15 -0
- package/dist/protection/SelectionAnalyzer.js +1 -0
- package/dist/protection/config.js +1 -0
- package/dist/vendor/approx-string-match/index.js +1 -0
- package/dist/vendor/hypothesis/anchoring/match-quote.js +1 -0
- package/dist/vendor/hypothesis/anchoring/text-range.js +1 -0
- package/dist/vendor/hypothesis/anchoring/trim-range.js +1 -0
- package/dist/vendor/hypothesis/anchoring/types.js +1 -0
- package/package.json +9 -8
- package/src/comms/comms.ts +11 -1
- package/src/comms/keys.ts +6 -2
- package/src/helpers/css.ts +1 -1
- package/src/helpers/document.ts +5 -5
- package/src/helpers/locator.ts +5 -5
- package/src/helpers/rect.ts +79 -18
- package/src/index.ts +1 -1
- package/src/modules/Decorator.ts +404 -107
- package/src/modules/snapper/CJKVerticalSnapper.ts +34 -7
- package/src/modules/snapper/ColumnSnapper.ts +54 -6
- package/src/modules/snapper/ScrollSnapper.ts +30 -7
- package/src/modules/snapper/Snapper.ts +144 -0
- package/src/modules/snapper/WebPubSnapper.ts +31 -7
- package/types/src/comms/comms.d.ts +10 -1
- package/types/src/comms/keys.d.ts +2 -2
- package/types/src/helpers/css.d.ts +1 -1
- package/types/src/helpers/document.d.ts +5 -5
- package/types/src/helpers/rect.d.ts +2 -1
- package/types/src/index.d.ts +1 -1
- package/types/src/modules/Decorator.d.ts +33 -7
- package/types/src/modules/snapper/CJKVerticalSnapper.d.ts +1 -0
- package/types/src/modules/snapper/ColumnSnapper.d.ts +14 -1
- package/types/src/modules/snapper/ScrollSnapper.d.ts +1 -0
- package/types/src/modules/snapper/Snapper.d.ts +58 -0
- package/types/src/modules/snapper/WebPubSnapper.d.ts +1 -0
- package/dist/ar-DyHX_uy2.js +0 -7
- package/dist/da-Dct0PS3E.js +0 -7
- package/dist/fr-C5HEel98.js +0 -7
- package/dist/index.umd.cjs +0 -96
- package/dist/it-DFOBoXGy.js +0 -7
- package/dist/pt_PT-Di3sVjze.js +0 -7
- package/dist/sv-BfzAFsVN.js +0 -7
- package/src/helpers/color.ts +0 -268
- package/src/helpers/sML.ts +0 -143
- package/types/src/helpers/color.d.ts +0 -27
- package/types/src/helpers/sML.d.ts +0 -56
package/src/helpers/rect.ts
CHANGED
|
@@ -10,29 +10,90 @@ export interface Rect {
|
|
|
10
10
|
width: number;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export function getTextClientRects(range: Range, skipTags: string[]): Rect[] {
|
|
14
|
+
const upperTags = skipTags.map(t => t.toUpperCase());
|
|
15
|
+
const rects: Rect[] = [];
|
|
16
|
+
|
|
17
|
+
const ancestor = range.commonAncestorContainer;
|
|
18
|
+
// TreeWalker only visits descendants, never the root itself. If the common
|
|
19
|
+
// ancestor is already a text node (single-node selection), walk from its
|
|
20
|
+
// parent so the text node itself is included in the traversal.
|
|
21
|
+
const walkerRoot = ancestor.nodeType === Node.TEXT_NODE ? ancestor.parentNode! : ancestor;
|
|
22
|
+
const walker = range.startContainer.ownerDocument!.createTreeWalker(
|
|
23
|
+
walkerRoot,
|
|
24
|
+
NodeFilter.SHOW_TEXT
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
let node = walker.nextNode();
|
|
28
|
+
while (node) {
|
|
29
|
+
if (range.intersectsNode(node)) {
|
|
30
|
+
let ancestor = node.parentNode;
|
|
31
|
+
let skip = false;
|
|
32
|
+
while (ancestor) {
|
|
33
|
+
if (ancestor.nodeType === Node.ELEMENT_NODE && upperTags.includes((ancestor as Element).tagName.toUpperCase())) {
|
|
34
|
+
skip = true;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
ancestor = ancestor.parentNode;
|
|
38
|
+
}
|
|
39
|
+
if (!skip) {
|
|
40
|
+
const textRange = range.cloneRange();
|
|
41
|
+
textRange.selectNode(node);
|
|
42
|
+
if (textRange.compareBoundaryPoints(Range.START_TO_START, range) < 0)
|
|
43
|
+
textRange.setStart(range.startContainer, range.startOffset);
|
|
44
|
+
if (textRange.compareBoundaryPoints(Range.END_TO_END, range) > 0)
|
|
45
|
+
textRange.setEnd(range.endContainer, range.endOffset);
|
|
46
|
+
for (const r of textRange.getClientRects()) {
|
|
47
|
+
rects.push({ left: r.left, right: r.right, top: r.top, bottom: r.bottom, width: r.width, height: r.height });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
node = walker.nextNode();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return rects;
|
|
55
|
+
}
|
|
56
|
+
|
|
13
57
|
export function getClientRectsNoOverlap(
|
|
14
|
-
|
|
58
|
+
source: Range | Rect[],
|
|
15
59
|
doNotMergeHorizontallyAlignedRects: boolean,
|
|
16
|
-
doNotMergeVerticallyAlignedRects: boolean = false
|
|
60
|
+
doNotMergeVerticallyAlignedRects: boolean = false,
|
|
61
|
+
expand: number = 0
|
|
17
62
|
) {
|
|
18
|
-
|
|
63
|
+
const tolerance = 1;
|
|
64
|
+
let originalRects: Rect[];
|
|
19
65
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
66
|
+
if (Array.isArray(source)) {
|
|
67
|
+
originalRects = source;
|
|
68
|
+
} else {
|
|
69
|
+
let clientRects = source.getClientRects();
|
|
24
70
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
71
|
+
// Try falling back to the client rects of the common ancestor of the range if it's an HTML Element
|
|
72
|
+
if(!clientRects.length)
|
|
73
|
+
if(source.commonAncestorContainer.nodeType === Node.ELEMENT_NODE)
|
|
74
|
+
clientRects = (source.commonAncestorContainer as HTMLElement).getClientRects();
|
|
75
|
+
|
|
76
|
+
originalRects = [];
|
|
77
|
+
for (const rangeClientRect of clientRects) {
|
|
78
|
+
originalRects.push({
|
|
79
|
+
bottom: rangeClientRect.bottom,
|
|
80
|
+
height: rangeClientRect.height,
|
|
81
|
+
left: rangeClientRect.left,
|
|
82
|
+
right: rangeClientRect.right,
|
|
83
|
+
top: rangeClientRect.top,
|
|
84
|
+
width: rangeClientRect.width,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (expand) {
|
|
89
|
+
for (const rect of originalRects) {
|
|
90
|
+
rect.left -= expand;
|
|
91
|
+
rect.top -= expand;
|
|
92
|
+
rect.right += expand;
|
|
93
|
+
rect.bottom += expand;
|
|
94
|
+
rect.width += expand * 2;
|
|
95
|
+
rect.height += expand * 2;
|
|
96
|
+
}
|
|
36
97
|
}
|
|
37
98
|
const mergedRects = mergeTouchingRects(
|
|
38
99
|
originalRects,
|
package/src/index.ts
CHANGED
|
@@ -2,5 +2,5 @@ export * from './comms/index.ts';
|
|
|
2
2
|
export * from './modules/index.ts';
|
|
3
3
|
export * from './Loader.ts';
|
|
4
4
|
export * from './protection/index.ts';
|
|
5
|
-
export
|
|
5
|
+
export type { ReadiumWindow } from './helpers/dom.ts';
|
|
6
6
|
export * from './keyboard/index.ts'
|