-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcopy_paste.html
243 lines (215 loc) · 5.83 KB
/
copy_paste.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Copy/Paste Test</title>
<style>
/* css reset */
html {
box-sizing: border-box;
font-size: 16px;
}
*, *:before, *:after {
box-sizing: inherit;
}
body, h1, h2, h3, h4, h5, h6, p, ol, ul {
margin: 0;
padding: 0;
font-weight: normal;
}
ol, ul {
list-style: none;
}
img {
max-width: 100%;
height: auto;
}
/* grid */
pre {
margin: 0;
}
body {
height: calc(100svh - 1rem);
display: grid;
gap: 0.5rem;
margin: 0.5rem;
grid-template-rows: repeat(3, min-content) 1fr;
}
div#counts, div#log {
background-color: #eee;
font-size: 10px;
}
body > div:last-of-type {
overflow: scroll;
}
</style>
</head>
<body>
<div>
<img src="https://web-dev.imgix.net/image/admin/urYfROhm806fvOPRMsRg.jpg?auto=format&h=100"></img>
<input type="button" value="Clicky"></input>
<input id="checky" type="checkbox">Enable JS Handlers</input>
<input id="loggy" type="checkbox">Enable Logging</input>
<div>
Use the Image above to drag, or long press for contextmenu.
Or, highlight this text and longpress to drag.
</div>
</div>
<input type=text placeholder="Typey" autofocus></input>
<div id="counts"></div>
<div id="log"></div>
<script type=module>
import { measureResponsiveness, estimateInteractionCountsByEventCounts } from './responsiveness.js';
import { getLCP, getFID, getINP, getCLS } from './web-vitals.js';
getCLS(console.log);
getFID(console.log);
getINP(console.log, true);
getLCP(console.log);
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",
];
let enableLog = true;
function replaceConsole() {
var log = console.log.bind(console);
var group = console.group.bind(console);
console.log = function (...args) {
log(...args);
let el = document.getElementById('log');
if (enableLog) {
el.innerHTML += `<pre>${args.join(' ')}<pre>`;
el.scrollTop = el.scrollHeight;
}
}
console.group = function (...args) {
group(...args);
let el = document.getElementById('log');
// el.innerHTML += `<hr/>`;
}
}
function reportEvents() {
const observer = new PerformanceObserver(list => {
const entries = list.getEntries().filter(entry => EVENTS.includes(entry.name));
if (entries.length == 0) return;
console.group();
for (let entry of entries) {
const renderTime = Math.round((entry.startTime + entry.duration) / 8) * 8;
console.log(`renderTime:${renderTime} ${entry.name} id:${entry.interactionId}`);
}
console.groupEnd();
});
observer.observe({
type: "event",
durationThreshold: 0, // 16 minumum by spec
buffered: true
});
}
replaceConsole();
reportEvents();
let currentINP;
getINP((metric) => {
currentINP = metric;
}, true);
setInterval(() => {
const counts = {
inp: currentINP?.value,
count: currentINP?.entries.length,
...estimateInteractionCountsByEventCounts(),
};
document.getElementById('counts').innerHTML = `<div><pre>${JSON.stringify(counts,null,2)}<pre></div>`;
}, 100);
const HANDLER_BLOCK_TIME = 20; // ms
const RAF_BLOCK_TIME = 20; // 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) {
requestAnimationFrame((time) => {
// console.log('Starting rAF handler');
block(ms);
});
}
function keepBusy(event) {
block(HANDLER_BLOCK_TIME);
blockingRaf(RAF_BLOCK_TIME);
document.body.style['background-color'] = randomColor();
}
// function addPreventDefault(handler) {
// return (...args) => {
// handler(...args);
// event.preventDefault();
// };
// }
const handler = (event) => {
console.log(`timeStamp:${event.timeStamp.toFixed(2)} ${event.type}`);
keepBusy();
}
function addHandlers() {
for (let event of EVENTS) {
document.addEventListener(event, handler);
}
}
function removeHandlers() {
for (let event of EVENTS) {
document.removeEventListener(event, handler);
}
}
const checky = document.getElementById('checky');
checky.addEventListener('change', (event) => {
if (event.target.checked) {
addHandlers();
} else {
removeHandlers();
}
});
checky.click();
const loggy = document.getElementById('loggy');
loggy.addEventListener('change', (event) => {
enableLog = event.target.checked;
event.stopPropagation();
event.preventDefault();
});
loggy.click();
</script>
</body>
</head>