@expofp/debug 3.6.2 → 3.6.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.
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
const SECRET_PHRASE = 'dbg123';
|
|
2
|
+
// Touch fallback for kiosks/embeds with no keyboard and no search input:
|
|
3
|
+
// quick consecutive taps in the same screen corner trigger the callbacks
|
|
4
|
+
// just like typing the secret phrase.
|
|
5
|
+
const TAP_COUNT = 7;
|
|
6
|
+
const TAP_ZONE_PX = 80;
|
|
7
|
+
const TAP_MAX_GAP_MS = 600;
|
|
2
8
|
const callbacks = [];
|
|
3
9
|
let initialized = false;
|
|
4
10
|
let teardown = null;
|
|
11
|
+
function fireCallbacks() {
|
|
12
|
+
callbacks.forEach((cb) => cb());
|
|
13
|
+
}
|
|
5
14
|
export function addDebugSecretListener(callback) {
|
|
6
15
|
callbacks.push(callback);
|
|
7
16
|
if (!initialized) {
|
|
@@ -16,7 +25,7 @@ export function addDebugSecretListener(callback) {
|
|
|
16
25
|
buffer = (buffer + ch).slice(-SECRET_PHRASE.length);
|
|
17
26
|
if (buffer === SECRET_PHRASE) {
|
|
18
27
|
buffer = '';
|
|
19
|
-
|
|
28
|
+
fireCallbacks();
|
|
20
29
|
return;
|
|
21
30
|
}
|
|
22
31
|
}
|
|
@@ -49,11 +58,46 @@ export function addDebugSecretListener(callback) {
|
|
|
49
58
|
if (ie.data)
|
|
50
59
|
feed(ie.data);
|
|
51
60
|
};
|
|
61
|
+
// Corner-tap gesture state. All taps must land in the same corner zone
|
|
62
|
+
// with no more than TAP_MAX_GAP_MS between them; a tap elsewhere (or a
|
|
63
|
+
// pause) resets the count.
|
|
64
|
+
let tapCorner = null;
|
|
65
|
+
let tapCount = 0;
|
|
66
|
+
let lastTapTime = 0;
|
|
67
|
+
const cornerAt = (x, y) => {
|
|
68
|
+
const horizontal = x <= TAP_ZONE_PX ? 'left' : x >= window.innerWidth - TAP_ZONE_PX ? 'right' : null;
|
|
69
|
+
const vertical = y <= TAP_ZONE_PX ? 'top' : y >= window.innerHeight - TAP_ZONE_PX ? 'bottom' : null;
|
|
70
|
+
return horizontal && vertical ? `${vertical}-${horizontal}` : null;
|
|
71
|
+
};
|
|
72
|
+
// Listen in the capture phase so taps still count when a UI component
|
|
73
|
+
// (or the map canvas) stops propagation. `isPrimary` filters out the
|
|
74
|
+
// extra pointers of multi-touch gestures such as pinch-zoom.
|
|
75
|
+
const onPointerDown = (e) => {
|
|
76
|
+
if (!e.isPrimary)
|
|
77
|
+
return;
|
|
78
|
+
const corner = cornerAt(e.clientX, e.clientY);
|
|
79
|
+
const now = Date.now();
|
|
80
|
+
if (corner && corner === tapCorner && now - lastTapTime <= TAP_MAX_GAP_MS) {
|
|
81
|
+
tapCount += 1;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
tapCorner = corner;
|
|
85
|
+
tapCount = corner ? 1 : 0;
|
|
86
|
+
}
|
|
87
|
+
lastTapTime = now;
|
|
88
|
+
if (tapCount >= TAP_COUNT) {
|
|
89
|
+
tapCorner = null;
|
|
90
|
+
tapCount = 0;
|
|
91
|
+
fireCallbacks();
|
|
92
|
+
}
|
|
93
|
+
};
|
|
52
94
|
document.addEventListener('keydown', onKeyDown);
|
|
53
95
|
document.addEventListener('input', onInput, true);
|
|
96
|
+
document.addEventListener('pointerdown', onPointerDown, true);
|
|
54
97
|
teardown = () => {
|
|
55
98
|
document.removeEventListener('keydown', onKeyDown);
|
|
56
99
|
document.removeEventListener('input', onInput, true);
|
|
100
|
+
document.removeEventListener('pointerdown', onPointerDown, true);
|
|
57
101
|
};
|
|
58
102
|
}
|
|
59
103
|
return () => {
|