Skip to content

Commit 7f26c2b

Browse files
committed
inital work
1 parent e06f096 commit 7f26c2b

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

src/UI/page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const PAGE_TEMPLATE = `
88
<div class="canvasWrapper">
99
<canvas></canvas>
1010
</div>
11-
<div class="` + config.textLayerName + `"></div>
1211
<svg class="` + config.annotationLayerName + `"></svg>
12+
<div class="` + config.textLayerName + `"></div>
1313
</div>
1414
`;
1515

src/UI/pen.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ function saveToStorage(x, y) {
6464
* @param {PointerEvent} e The DOM event to be handled
6565
*/
6666
function handleDocumentPointermove(e) {
67-
if (!e.srcElement.classList.contains('annotationLayer')) {
68-
return;
69-
}
7067
if (_candraw) {
7168
savePoint(e.clientX, e.clientY);
7269
}

src/UI/text.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ function handleDocumentMouseup(e) {
2121
if (input || !findSVGAtPoint(e.clientX, e.clientY)) {
2222
return;
2323
}
24-
if (!e.srcElement.classList.contains('annotationLayer')) {
25-
return;
26-
}
24+
2725
input = document.createElement('input');
2826
input.setAttribute('id', 'pdf-annotate-text-input');
2927
input.setAttribute('placeholder', 'Enter text');

src/UI/utils.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,25 @@ export function findSVGAtPoint(x, y) {
6666
/**
6767
* Find an Element that represents an annotation at a given point.
6868
*
69-
* IMPORTANT: Requires the annotation layer to be the top most element so
70-
* either use z-ordering or make it the leaf container.
71-
*
7269
* @param {Number} x The x coordinate of the point
7370
* @param {Number} y The y coordinate of the point
74-
* @return {Element} The annotation element or null if one can't be found
71+
* @return {Element|null} The annotation element or null if one can't be found
7572
*/
7673
export function findAnnotationAtPoint(x, y) {
77-
let el = null;
78-
let candidate = document.elementFromPoint(x, y);
79-
while (!el && candidate && candidate !== document) {
80-
let type = candidate.getAttribute('data-pdf-annotate-type');
81-
if (type) {
82-
el = candidate;
74+
let svg = findSVGAtPoint(x, y);
75+
76+
if (!svg) {
77+
return;
78+
}
79+
80+
let elements = svg.querySelectorAll('[data-pdf-annotate-type]');
81+
for (let element of elements) {
82+
if (pointIntersectsRect(x, y, element.getBoundingClientRect())) {
83+
return element;
8384
}
84-
candidate = candidate.parentNode;
8585
}
86-
return el;
86+
87+
return null;
8788
}
8889

8990
/**

0 commit comments

Comments
 (0)