-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresponsiveness.html
128 lines (111 loc) · 3.07 KB
/
responsiveness.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
<title>Responsiveness Test</title>
</head>
<body>
<input type=button value="Clicky"></input>
<input type=text placeholder="Typey"></input>
<input type=checkbox valye="Selecty"></input>
<script type=module>
import { measureResponsiveness, measureEvents } from './responsiveness.js';
measureResponsiveness();
// measureEvents();
const HANDLER_BLOCK_TIME = 1; // ms
const RAF_BLOCK_TIME = 1; // ms
const BGTASK_BLOCK_TIME = 2; // ms
function randomColor() {
return `#${Math.floor(Math.random()*16777215).toString(16)}`;
}
function block(ms) {
// console.log(`Starting to sync block for ${ms}ms`);
const end = performance.now() + ms;
while (performance.now() < end);
}
function blockingRaf(ms, cb) {
requestAnimationFrame((time) => {
// console.log('Starting rAF handler');
block(ms);
cb();
});
}
function keepBusy(event) {
block(HANDLER_BLOCK_TIME);
button.style['background-color'] = randomColor();
blockingRaf(RAF_BLOCK_TIME, () => document.body.style['background-color'] = randomColor());
}
function addPreventDefault(handler) {
return (...args) => {
handler(...args);
event.preventDefault();
};
}
function on(element, event, handler) {
element.addEventListener(event, handler);
}
function onAll(element, handler, events) {
for (let event of events) {
on(element, event, (...args) => handler(...args)); // wrap with lambda so handlers are referentially equal
}
}
const EVENTS = [
"keydown",
"keyup",
"keypress",
"pointerdown",
"pointerup",
"pointercancel",
"touchstart",
"touchend",
"touchcancel",
"mousedown",
"mouseup",
"gotpointercapture",
"lostpointercapture",
"click",
"dblclick",
"auxclick",
"contextmenu",
"pointerleave",
"pointerout",
"pointerover",
"pointerenter",
"mouseout",
"mouseover",
"mouseleave",
"mouseenter",
"lostpointercapture",
"dragstart",
"dragend",
"dragenter",
"dragleave",
"dragover",
"drop",
"beforeinput",
"input",
"compositionstart",
"compositionupdate",
"compositionend",
];
const handler = keepBusy;
// const handler = addPreventDefault(keepBusy);
const button = document.querySelector('input[type="button"]');
for (let i = 0; i < 10; i++) {
onAll(button, handler, EVENTS)
}
const text = document.querySelector('input[type="text"]');
for (let i = 0; i < 10; i++) {
onAll(text, handler, EVENTS);
}
const checkbox = document.querySelector('input[type="checkbox"]');
for (let i = 0; i < 10; i++) {
onAll(checkbox, handler, EVENTS);
}
setInterval(() => {
block(BGTASK_BLOCK_TIME);
button.style['background-color'] = randomColor();
});
</script>
</body>
</head>