@absolutejs/beacon 0.6.1 → 0.6.3
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 +85 -21
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -673,6 +673,7 @@ var createBeacon = (options) => {
|
|
|
673
673
|
const KEYBOARD_VIEWPORT_HEIGHT_RATIO_MAX = 0.8;
|
|
674
674
|
const SCROLL_JAIL_EVENT_COUNT = 8;
|
|
675
675
|
const SCROLL_JAIL_WINDOW_MS = 2000;
|
|
676
|
+
const SCROLL_JAIL_SETTLE_MS = 50;
|
|
676
677
|
const SCROLL_JAIL_BOUNDARY_TOLERANCE_PX = 2;
|
|
677
678
|
const AUTH_FAILURE_STORM_DEFAULT_COUNT = 4;
|
|
678
679
|
const AUTH_FAILURE_STORM_DEFAULT_WINDOW_MS = 30000;
|
|
@@ -2581,6 +2582,7 @@ var createBeacon = (options) => {
|
|
|
2581
2582
|
};
|
|
2582
2583
|
let jailBurst = [];
|
|
2583
2584
|
let jailScroller = null;
|
|
2585
|
+
let jailSettleTimer;
|
|
2584
2586
|
const reportedScrollers = new Set;
|
|
2585
2587
|
const onWheel = (event) => {
|
|
2586
2588
|
if (event.ctrlKey || event.defaultPrevented || event.deltaY === 0) {
|
|
@@ -2613,16 +2615,31 @@ var createBeacon = (options) => {
|
|
|
2613
2615
|
jailBurst = [];
|
|
2614
2616
|
if (moved)
|
|
2615
2617
|
return;
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2618
|
+
const startingPosition = first.position;
|
|
2619
|
+
if (jailSettleTimer !== undefined)
|
|
2620
|
+
clearTimeout(jailSettleTimer);
|
|
2621
|
+
jailSettleTimer = setTimeout(() => {
|
|
2622
|
+
jailSettleTimer = undefined;
|
|
2623
|
+
if (!scroller.isConnected || scroller.scrollTop !== startingPosition)
|
|
2624
|
+
return;
|
|
2625
|
+
const canStillMove = scrollingDown ? scroller.scrollTop + scroller.clientHeight < scroller.scrollHeight - SCROLL_JAIL_BOUNDARY_TOLERANCE_PX : scroller.scrollTop > SCROLL_JAIL_BOUNDARY_TOLERANCE_PX;
|
|
2626
|
+
if (!canStillMove)
|
|
2627
|
+
return;
|
|
2628
|
+
if (viewportCoveredByOverlay())
|
|
2629
|
+
return;
|
|
2630
|
+
const descriptor = describeElement(scroller);
|
|
2631
|
+
if (reportedScrollers.has(descriptor))
|
|
2632
|
+
return;
|
|
2633
|
+
reportedScrollers.add(descriptor);
|
|
2634
|
+
emitSignal(`Scroll jail — ${descriptor} has scrollable content but never moves — ${shortUrl(location.href)}`, { signal: BEACON_SIGNAL.SCROLL_JAIL, target: descriptor });
|
|
2635
|
+
}, SCROLL_JAIL_SETTLE_MS);
|
|
2623
2636
|
};
|
|
2624
2637
|
document.addEventListener("wheel", onWheel, { passive: true });
|
|
2625
|
-
cleanups.push(() =>
|
|
2638
|
+
cleanups.push(() => {
|
|
2639
|
+
document.removeEventListener("wheel", onWheel);
|
|
2640
|
+
if (jailSettleTimer !== undefined)
|
|
2641
|
+
clearTimeout(jailSettleTimer);
|
|
2642
|
+
});
|
|
2626
2643
|
}
|
|
2627
2644
|
if (signals.thrashedCursors !== false) {
|
|
2628
2645
|
const reversalThreshold = signals.thrashedCursorReversals ?? THRASHED_CURSOR_DEFAULT_REVERSALS;
|
|
@@ -2673,6 +2690,24 @@ var createBeacon = (options) => {
|
|
|
2673
2690
|
const reportedFocusLoss = new Set;
|
|
2674
2691
|
const reportedModalEscapes = new WeakSet;
|
|
2675
2692
|
const modalTimers = new Set;
|
|
2693
|
+
const modalVisibility = new WeakMap;
|
|
2694
|
+
const knownModals = new Set;
|
|
2695
|
+
const isRenderedModal = (modal) => {
|
|
2696
|
+
if (!modal.isConnected || !modal.matches(MODAL_SELECTOR))
|
|
2697
|
+
return false;
|
|
2698
|
+
let current = modal;
|
|
2699
|
+
while (current !== null) {
|
|
2700
|
+
if (current.hasAttribute("hidden") || current.hasAttribute("inert") || current.getAttribute("aria-hidden")?.toLowerCase() === "true") {
|
|
2701
|
+
return false;
|
|
2702
|
+
}
|
|
2703
|
+
const style = getComputedStyle(current);
|
|
2704
|
+
if (style.display === "none" || style.visibility === "hidden" || style.visibility === "collapse" || style.contentVisibility === "hidden") {
|
|
2705
|
+
return false;
|
|
2706
|
+
}
|
|
2707
|
+
current = current.parentElement;
|
|
2708
|
+
}
|
|
2709
|
+
return true;
|
|
2710
|
+
};
|
|
2676
2711
|
const reportModalEscape = (modal, active, reason) => {
|
|
2677
2712
|
if (signals.modalFocusEscape === false || reportedModalEscapes.has(modal) || document.visibilityState === "hidden") {
|
|
2678
2713
|
return;
|
|
@@ -2686,11 +2721,11 @@ var createBeacon = (options) => {
|
|
|
2686
2721
|
target: active === null ? "none" : describeElement(active)
|
|
2687
2722
|
});
|
|
2688
2723
|
};
|
|
2689
|
-
const openModals = () => Array.from(document.querySelectorAll(MODAL_SELECTOR));
|
|
2724
|
+
const openModals = () => Array.from(document.querySelectorAll(MODAL_SELECTOR)).filter(isRenderedModal);
|
|
2690
2725
|
const checkInitialModalFocus = (modal) => {
|
|
2691
2726
|
const timer2 = setTimeout(() => {
|
|
2692
2727
|
modalTimers.delete(timer2);
|
|
2693
|
-
if (!modal
|
|
2728
|
+
if (!isRenderedModal(modal))
|
|
2694
2729
|
return;
|
|
2695
2730
|
const active = document.activeElement instanceof Element ? document.activeElement : null;
|
|
2696
2731
|
if (active !== null && modal.contains(active))
|
|
@@ -2699,6 +2734,21 @@ var createBeacon = (options) => {
|
|
|
2699
2734
|
}, MODAL_FOCUS_SETTLE_MS);
|
|
2700
2735
|
modalTimers.add(timer2);
|
|
2701
2736
|
};
|
|
2737
|
+
const updateModalVisibility = (modal) => {
|
|
2738
|
+
knownModals.add(modal);
|
|
2739
|
+
const visible = isRenderedModal(modal);
|
|
2740
|
+
const wasVisible = modalVisibility.get(modal) === true;
|
|
2741
|
+
modalVisibility.set(modal, visible);
|
|
2742
|
+
if (visible && !wasVisible)
|
|
2743
|
+
checkInitialModalFocus(modal);
|
|
2744
|
+
};
|
|
2745
|
+
const registerModals = (root) => {
|
|
2746
|
+
if (root.matches(MODAL_SELECTOR))
|
|
2747
|
+
updateModalVisibility(root);
|
|
2748
|
+
for (const modal of Array.from(root.querySelectorAll(MODAL_SELECTOR))) {
|
|
2749
|
+
updateModalVisibility(modal);
|
|
2750
|
+
}
|
|
2751
|
+
};
|
|
2702
2752
|
const onFocusIn = (event) => {
|
|
2703
2753
|
const target = event.target;
|
|
2704
2754
|
if (signals.modalFocusEscape !== false && target instanceof Element) {
|
|
@@ -2729,26 +2779,39 @@ var createBeacon = (options) => {
|
|
|
2729
2779
|
document.addEventListener("focusout", onFocusOut, true);
|
|
2730
2780
|
let modalObserver;
|
|
2731
2781
|
if (signals.modalFocusEscape !== false && typeof MutationObserver !== "undefined") {
|
|
2732
|
-
for (const modal of
|
|
2733
|
-
|
|
2782
|
+
for (const modal of Array.from(document.querySelectorAll(MODAL_SELECTOR))) {
|
|
2783
|
+
updateModalVisibility(modal);
|
|
2784
|
+
}
|
|
2734
2785
|
modalObserver = new MutationObserver((records) => {
|
|
2735
2786
|
for (const record of records) {
|
|
2736
|
-
if (record.type === "attributes" && record.target instanceof Element
|
|
2737
|
-
|
|
2787
|
+
if (record.type === "attributes" && record.target instanceof Element) {
|
|
2788
|
+
const target = record.target;
|
|
2789
|
+
if (knownModals.has(target) || target.matches(MODAL_SELECTOR)) {
|
|
2790
|
+
updateModalVisibility(target);
|
|
2791
|
+
}
|
|
2792
|
+
for (const modal of knownModals) {
|
|
2793
|
+
if (modal !== target && target.contains(modal)) {
|
|
2794
|
+
updateModalVisibility(modal);
|
|
2795
|
+
}
|
|
2796
|
+
}
|
|
2738
2797
|
}
|
|
2739
2798
|
for (const added of Array.from(record.addedNodes)) {
|
|
2740
2799
|
if (!(added instanceof Element))
|
|
2741
2800
|
continue;
|
|
2742
|
-
|
|
2743
|
-
checkInitialModalFocus(added);
|
|
2744
|
-
for (const modal of Array.from(added.querySelectorAll(MODAL_SELECTOR))) {
|
|
2745
|
-
checkInitialModalFocus(modal);
|
|
2746
|
-
}
|
|
2801
|
+
registerModals(added);
|
|
2747
2802
|
}
|
|
2748
2803
|
}
|
|
2749
2804
|
});
|
|
2750
2805
|
modalObserver.observe(document.documentElement, {
|
|
2751
|
-
attributeFilter: [
|
|
2806
|
+
attributeFilter: [
|
|
2807
|
+
"aria-hidden",
|
|
2808
|
+
"aria-modal",
|
|
2809
|
+
"class",
|
|
2810
|
+
"hidden",
|
|
2811
|
+
"inert",
|
|
2812
|
+
"open",
|
|
2813
|
+
"style"
|
|
2814
|
+
],
|
|
2752
2815
|
attributes: true,
|
|
2753
2816
|
childList: true,
|
|
2754
2817
|
subtree: true
|
|
@@ -2761,6 +2824,7 @@ var createBeacon = (options) => {
|
|
|
2761
2824
|
for (const timer2 of modalTimers)
|
|
2762
2825
|
clearTimeout(timer2);
|
|
2763
2826
|
modalTimers.clear();
|
|
2827
|
+
knownModals.clear();
|
|
2764
2828
|
});
|
|
2765
2829
|
}
|
|
2766
2830
|
if (signals.formFrustration !== false) {
|
|
@@ -3502,5 +3566,5 @@ export {
|
|
|
3502
3566
|
BEACON_ATTRIBUTE
|
|
3503
3567
|
};
|
|
3504
3568
|
|
|
3505
|
-
//# debugId=
|
|
3569
|
+
//# debugId=92AD5D46269906F564756E2164756E21
|
|
3506
3570
|
//# sourceMappingURL=index.js.map
|