@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.
Files changed (73) hide show
  1. package/dist/Loader.js +1 -0
  2. package/dist/comms/comms.js +1 -0
  3. package/dist/comms/mid.js +1 -0
  4. package/dist/helpers/animation.js +1 -0
  5. package/dist/helpers/css.js +1 -0
  6. package/dist/helpers/document.js +1 -0
  7. package/dist/helpers/dom.js +1 -0
  8. package/dist/helpers/locator.js +1 -0
  9. package/dist/helpers/rect.js +1 -0
  10. package/dist/helpers/sanitize.js +1 -0
  11. package/dist/index.js +1 -4601
  12. package/dist/keyboard/KeyCombinationManager.js +1 -0
  13. package/dist/keyboard/KeyboardCombinations.js +1 -0
  14. package/dist/modules/Decorator.js +24 -0
  15. package/dist/modules/Module.js +1 -0
  16. package/dist/modules/ModuleLibrary.js +1 -0
  17. package/dist/modules/Peripherals.js +1 -0
  18. package/dist/modules/setup/FixedSetup.js +13 -0
  19. package/dist/modules/setup/ReflowableSetup.js +1 -0
  20. package/dist/modules/setup/Setup.js +1 -0
  21. package/dist/modules/setup/WebPubSetup.js +1 -0
  22. package/dist/modules/snapper/CJKVerticalSnapper.js +12 -0
  23. package/dist/modules/snapper/ColumnSnapper.js +35 -0
  24. package/dist/modules/snapper/ScrollSnapper.js +9 -0
  25. package/dist/modules/snapper/Snapper.js +5 -0
  26. package/dist/modules/snapper/WebPubSnapper.js +1 -0
  27. package/dist/protection/BulkCopyProtector.js +1 -0
  28. package/dist/protection/PatternAnalyzer.js +1 -0
  29. package/dist/protection/PrintProtector.js +15 -0
  30. package/dist/protection/SelectionAnalyzer.js +1 -0
  31. package/dist/protection/config.js +1 -0
  32. package/dist/vendor/approx-string-match/index.js +1 -0
  33. package/dist/vendor/hypothesis/anchoring/match-quote.js +1 -0
  34. package/dist/vendor/hypothesis/anchoring/text-range.js +1 -0
  35. package/dist/vendor/hypothesis/anchoring/trim-range.js +1 -0
  36. package/dist/vendor/hypothesis/anchoring/types.js +1 -0
  37. package/package.json +9 -8
  38. package/src/comms/comms.ts +11 -1
  39. package/src/comms/keys.ts +6 -2
  40. package/src/helpers/css.ts +1 -1
  41. package/src/helpers/document.ts +5 -5
  42. package/src/helpers/locator.ts +5 -5
  43. package/src/helpers/rect.ts +79 -18
  44. package/src/index.ts +1 -1
  45. package/src/modules/Decorator.ts +404 -107
  46. package/src/modules/snapper/CJKVerticalSnapper.ts +34 -7
  47. package/src/modules/snapper/ColumnSnapper.ts +54 -6
  48. package/src/modules/snapper/ScrollSnapper.ts +30 -7
  49. package/src/modules/snapper/Snapper.ts +144 -0
  50. package/src/modules/snapper/WebPubSnapper.ts +31 -7
  51. package/types/src/comms/comms.d.ts +10 -1
  52. package/types/src/comms/keys.d.ts +2 -2
  53. package/types/src/helpers/css.d.ts +1 -1
  54. package/types/src/helpers/document.d.ts +5 -5
  55. package/types/src/helpers/rect.d.ts +2 -1
  56. package/types/src/index.d.ts +1 -1
  57. package/types/src/modules/Decorator.d.ts +33 -7
  58. package/types/src/modules/snapper/CJKVerticalSnapper.d.ts +1 -0
  59. package/types/src/modules/snapper/ColumnSnapper.d.ts +14 -1
  60. package/types/src/modules/snapper/ScrollSnapper.d.ts +1 -0
  61. package/types/src/modules/snapper/Snapper.d.ts +58 -0
  62. package/types/src/modules/snapper/WebPubSnapper.d.ts +1 -0
  63. package/dist/ar-DyHX_uy2.js +0 -7
  64. package/dist/da-Dct0PS3E.js +0 -7
  65. package/dist/fr-C5HEel98.js +0 -7
  66. package/dist/index.umd.cjs +0 -96
  67. package/dist/it-DFOBoXGy.js +0 -7
  68. package/dist/pt_PT-Di3sVjze.js +0 -7
  69. package/dist/sv-BfzAFsVN.js +0 -7
  70. package/src/helpers/color.ts +0 -268
  71. package/src/helpers/sML.ts +0 -143
  72. package/types/src/helpers/color.d.ts +0 -27
  73. package/types/src/helpers/sML.d.ts +0 -56
@@ -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
- range: Range,
58
+ source: Range | Rect[],
15
59
  doNotMergeHorizontallyAlignedRects: boolean,
16
- doNotMergeVerticallyAlignedRects: boolean = false
60
+ doNotMergeVerticallyAlignedRects: boolean = false,
61
+ expand: number = 0
17
62
  ) {
18
- let clientRects = range.getClientRects();
63
+ const tolerance = 1;
64
+ let originalRects: Rect[];
19
65
 
20
- // Try falling back to the client rects of the common ancestor of the range if it's an HTML Element
21
- if(!clientRects.length)
22
- if(range.commonAncestorContainer.nodeType === Node.ELEMENT_NODE)
23
- clientRects = (range.commonAncestorContainer as HTMLElement).getClientRects();
66
+ if (Array.isArray(source)) {
67
+ originalRects = source;
68
+ } else {
69
+ let clientRects = source.getClientRects();
24
70
 
25
- const tolerance = 1;
26
- const originalRects: Rect[] = [];
27
- for (const rangeClientRect of clientRects) {
28
- originalRects.push({
29
- bottom: rangeClientRect.bottom,
30
- height: rangeClientRect.height,
31
- left: rangeClientRect.left,
32
- right: rangeClientRect.right,
33
- top: rangeClientRect.top,
34
- width: rangeClientRect.width,
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 * from './helpers/sML.ts';
5
+ export type { ReadiumWindow } from './helpers/dom.ts';
6
6
  export * from './keyboard/index.ts'