@empiricalrun/test-gen 0.35.3 → 0.35.4
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/CHANGELOG.md
CHANGED
|
@@ -22,20 +22,56 @@ window.annotateClickableElements = function annotateClickableElements(
|
|
|
22
22
|
let annotationsContainer = null;
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* Checks if
|
|
26
|
-
*
|
|
25
|
+
* Checks if the provided DOM element is clickable by ensuring that
|
|
26
|
+
* no other elements are covering it, regardless of its current
|
|
27
|
+
* viewport visibility.
|
|
28
|
+
*
|
|
27
29
|
* @param {Element} element - The DOM element to check.
|
|
28
|
-
* @returns {boolean}
|
|
30
|
+
* @returns {boolean} - Returns true if the element is clickable; otherwise, false.
|
|
29
31
|
*/
|
|
30
|
-
|
|
32
|
+
|
|
33
|
+
function isElementClickNotBlocked(element) {
|
|
31
34
|
const rect = element.getBoundingClientRect();
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
|
|
36
|
+
// Calculate the center point of the element
|
|
37
|
+
const centerX = rect.left + rect.width / 2;
|
|
38
|
+
const centerY = rect.top + rect.height / 2;
|
|
39
|
+
|
|
40
|
+
// check if element is within the viewport
|
|
41
|
+
if (
|
|
42
|
+
centerX < 0 ||
|
|
43
|
+
centerY < 0 ||
|
|
44
|
+
centerX > (window.innerWidth || document.documentElement.clientWidth) ||
|
|
45
|
+
centerY > (window.innerHeight || document.documentElement.clientHeight)
|
|
46
|
+
) {
|
|
47
|
+
// Determine the viewport dimensions
|
|
48
|
+
const viewportWidth =
|
|
49
|
+
window.innerWidth || document.documentElement.clientWidth;
|
|
50
|
+
const viewportHeight =
|
|
51
|
+
window.innerHeight || document.documentElement.clientHeight;
|
|
52
|
+
|
|
53
|
+
// Calculate the new scroll positions to bring the element into the center of the viewport
|
|
54
|
+
const newScrollX = centerX - viewportWidth / 2;
|
|
55
|
+
const newScrollY = centerY - viewportHeight / 2;
|
|
56
|
+
|
|
57
|
+
// Scroll the window to the new positions
|
|
58
|
+
window.scrollTo({
|
|
59
|
+
top: newScrollY,
|
|
60
|
+
left: newScrollX,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const newRect = element.getBoundingClientRect();
|
|
64
|
+
const newCenterX = newRect.left + newRect.width / 2;
|
|
65
|
+
const newCenterY = newRect.top + newRect.height / 2;
|
|
66
|
+
const topElement = document.elementFromPoint(newCenterX, newCenterY);
|
|
67
|
+
return element.contains(topElement);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Retrieve the topmost element at the center point
|
|
71
|
+
const topElement = document.elementFromPoint(centerX, centerY);
|
|
72
|
+
|
|
73
|
+
// Check if the topmost element is the target element or one of its descendants
|
|
74
|
+
return element.contains(topElement);
|
|
39
75
|
}
|
|
40
76
|
|
|
41
77
|
/**
|
|
@@ -408,7 +444,18 @@ window.annotateClickableElements = function annotateClickableElements(
|
|
|
408
444
|
document.body.appendChild(annotationsContainer);
|
|
409
445
|
|
|
410
446
|
const clickableElements = Array.from(document.querySelectorAll("*")).filter(
|
|
411
|
-
(el) =>
|
|
447
|
+
(el) => {
|
|
448
|
+
const isClickable = isElementClickable(el);
|
|
449
|
+
|
|
450
|
+
const originalScrollX = window.scrollX;
|
|
451
|
+
const originalScrollY = window.scrollY;
|
|
452
|
+
|
|
453
|
+
const isClickNotBlocked = isElementClickNotBlocked(el);
|
|
454
|
+
// Restore the original scroll positions
|
|
455
|
+
window.scrollTo(originalScrollX, originalScrollY);
|
|
456
|
+
|
|
457
|
+
return isClickable && isClickNotBlocked;
|
|
458
|
+
},
|
|
412
459
|
);
|
|
413
460
|
const hints = generateHintStrings(
|
|
414
461
|
hintCharacterSet,
|
|
@@ -22,20 +22,56 @@ window.annotateClickableElements = function annotateClickableElements(
|
|
|
22
22
|
let annotationsContainer = null;
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* Checks if
|
|
26
|
-
*
|
|
25
|
+
* Checks if the provided DOM element is clickable by ensuring that
|
|
26
|
+
* no other elements are covering it, regardless of its current
|
|
27
|
+
* viewport visibility.
|
|
28
|
+
*
|
|
27
29
|
* @param {Element} element - The DOM element to check.
|
|
28
|
-
* @returns {boolean}
|
|
30
|
+
* @returns {boolean} - Returns true if the element is clickable; otherwise, false.
|
|
29
31
|
*/
|
|
30
|
-
|
|
32
|
+
|
|
33
|
+
function isElementClickNotBlocked(element) {
|
|
31
34
|
const rect = element.getBoundingClientRect();
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
|
|
36
|
+
// Calculate the center point of the element
|
|
37
|
+
const centerX = rect.left + rect.width / 2;
|
|
38
|
+
const centerY = rect.top + rect.height / 2;
|
|
39
|
+
|
|
40
|
+
// check if element is within the viewport
|
|
41
|
+
if (
|
|
42
|
+
centerX < 0 ||
|
|
43
|
+
centerY < 0 ||
|
|
44
|
+
centerX > (window.innerWidth || document.documentElement.clientWidth) ||
|
|
45
|
+
centerY > (window.innerHeight || document.documentElement.clientHeight)
|
|
46
|
+
) {
|
|
47
|
+
// Determine the viewport dimensions
|
|
48
|
+
const viewportWidth =
|
|
49
|
+
window.innerWidth || document.documentElement.clientWidth;
|
|
50
|
+
const viewportHeight =
|
|
51
|
+
window.innerHeight || document.documentElement.clientHeight;
|
|
52
|
+
|
|
53
|
+
// Calculate the new scroll positions to bring the element into the center of the viewport
|
|
54
|
+
const newScrollX = centerX - viewportWidth / 2;
|
|
55
|
+
const newScrollY = centerY - viewportHeight / 2;
|
|
56
|
+
|
|
57
|
+
// Scroll the window to the new positions
|
|
58
|
+
window.scrollTo({
|
|
59
|
+
top: newScrollY,
|
|
60
|
+
left: newScrollX,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const newRect = element.getBoundingClientRect();
|
|
64
|
+
const newCenterX = newRect.left + newRect.width / 2;
|
|
65
|
+
const newCenterY = newRect.top + newRect.height / 2;
|
|
66
|
+
const topElement = document.elementFromPoint(newCenterX, newCenterY);
|
|
67
|
+
return element.contains(topElement);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Retrieve the topmost element at the center point
|
|
71
|
+
const topElement = document.elementFromPoint(centerX, centerY);
|
|
72
|
+
|
|
73
|
+
// Check if the topmost element is the target element or one of its descendants
|
|
74
|
+
return element.contains(topElement);
|
|
39
75
|
}
|
|
40
76
|
|
|
41
77
|
/**
|
|
@@ -408,7 +444,18 @@ window.annotateClickableElements = function annotateClickableElements(
|
|
|
408
444
|
document.body.appendChild(annotationsContainer);
|
|
409
445
|
|
|
410
446
|
const clickableElements = Array.from(document.querySelectorAll("*")).filter(
|
|
411
|
-
(el) =>
|
|
447
|
+
(el) => {
|
|
448
|
+
const isClickable = isElementClickable(el);
|
|
449
|
+
|
|
450
|
+
const originalScrollX = window.scrollX;
|
|
451
|
+
const originalScrollY = window.scrollY;
|
|
452
|
+
|
|
453
|
+
const isClickNotBlocked = isElementClickNotBlocked(el);
|
|
454
|
+
// Restore the original scroll positions
|
|
455
|
+
window.scrollTo(originalScrollX, originalScrollY);
|
|
456
|
+
|
|
457
|
+
return isClickable && isClickNotBlocked;
|
|
458
|
+
},
|
|
412
459
|
);
|
|
413
460
|
const hints = generateHintStrings(
|
|
414
461
|
hintCharacterSet,
|