@ctrl/dom 0.1.4 → 0.1.5
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/aria/_chunks/roles-list-BXCvPLJT.cjs +4 -0
- package/dist/aria/_chunks/roles-list-rVVxaIPs.js +4 -0
- package/dist/aria/index.cjs +1 -232
- package/dist/aria/index.js +1 -198
- package/dist/aria/internal.cjs +1 -69
- package/dist/aria/internal.js +1 -30
- package/dist/cli/_chunks/report-z52LF7nA.js +12 -0
- package/dist/cli/_chunks/rolldown-runtime-H3fMLYWS.js +1 -0
- package/dist/cli/ctrl-dom.js +2 -181
- package/dist/cli/jest-reporter.js +2 -54
- package/dist/cli/vitest-reporter.js +2 -81
- package/dist/dom/_chunks/src-sZY6a2LC.js +49 -0
- package/dist/dom/index.js +1 -3
- package/dist/dom/internal.js +1 -434
- package/dist/dom/types/window/clock.d.ts +2 -2
- package/dist/jest-dom/_chunks/matchers-CGTk9GX9.cjs +31 -0
- package/dist/jest-dom/_chunks/matchers-Chf0yHoo.js +31 -0
- package/dist/jest-dom/index.cjs +1 -5
- package/dist/jest-dom/index.js +1 -6
- package/dist/jest-dom/jest-globals.cjs +1 -6
- package/dist/jest-dom/jest-globals.js +1 -7
- package/dist/jest-dom/matchers.cjs +1 -53
- package/dist/jest-dom/matchers.js +1 -3
- package/dist/jest-dom/vitest.cjs +1 -6
- package/dist/jest-dom/vitest.js +1 -7
- package/dist/react/_chunks/pure-CCeTO5Mk.js +1 -0
- package/dist/react/_chunks/pure-DQzwul4s.cjs +1 -0
- package/dist/react/dont-cleanup-after-each.cjs +1 -3
- package/dist/react/dont-cleanup-after-each.js +1 -4
- package/dist/react/index.cjs +1 -47
- package/dist/react/index.js +1 -35
- package/dist/react/pure.cjs +1 -17
- package/dist/react/pure.js +1 -5
- package/dist/register/index.js +1 -11
- package/dist/register/pure.js +1 -147
- package/dist/testing-library/_chunks/aria-snapshot-diff-80G4meO2.cjs +14 -0
- package/dist/testing-library/_chunks/aria-snapshot-diff-B1L8s_sM.js +14 -0
- package/dist/testing-library/agent.cjs +10 -720
- package/dist/testing-library/agent.js +10 -712
- package/dist/testing-library/index.cjs +19 -2459
- package/dist/testing-library/index.js +19 -2380
- package/dist/user-event/index.cjs +33 -3924
- package/dist/user-event/index.js +33 -3899
- package/dist/user-event/types/ctrl-dom.d.ts +1 -1
- package/dist/vitest-environment/_chunks/rolldown-runtime-BhWHdk3m.js +1 -0
- package/dist/vitest-environment/failure-snapshot.js +1 -42
- package/dist/vitest-environment/index.js +1 -185
- package/dist/vitest-environment/plugin.js +1 -90
- package/package.json +1 -1
- package/dist/aria/_chunks/roles-list-CYZF-l9K.js +0 -1503
- package/dist/aria/_chunks/roles-list-D4WCyRO_.cjs +0 -1754
- package/dist/cli/_chunks/report-DdncYfuJ.js +0 -93
- package/dist/dom/_chunks/src-Cp3oLry4.js +0 -47610
- package/dist/jest-dom/_chunks/matchers-CDnnXUfG.js +0 -2211
- package/dist/jest-dom/_chunks/matchers-D988Ducb.cjs +0 -2516
- package/dist/react/_chunks/pure-DZ97z2oT.cjs +0 -498
- package/dist/react/_chunks/pure-PtE2hivW.js +0 -420
- package/dist/testing-library/_chunks/aria-snapshot-diff-D7PzpXew.cjs +0 -1170
- package/dist/testing-library/_chunks/aria-snapshot-diff-Q8Wj33K0.js +0 -985
package/dist/user-event/index.js
CHANGED
|
@@ -1,3902 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
defaultInit: {
|
|
28
|
-
bubbles: true,
|
|
29
|
-
cancelable: true,
|
|
30
|
-
composed: true
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
beforeinput: {
|
|
34
|
-
EventType: "InputEvent",
|
|
35
|
-
defaultInit: {
|
|
36
|
-
bubbles: true,
|
|
37
|
-
cancelable: true,
|
|
38
|
-
composed: true
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
blur: {
|
|
42
|
-
EventType: "FocusEvent",
|
|
43
|
-
defaultInit: {
|
|
44
|
-
bubbles: false,
|
|
45
|
-
cancelable: false,
|
|
46
|
-
composed: true
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
click: {
|
|
50
|
-
EventType: "PointerEvent",
|
|
51
|
-
defaultInit: {
|
|
52
|
-
bubbles: true,
|
|
53
|
-
cancelable: true,
|
|
54
|
-
composed: true
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
contextmenu: {
|
|
58
|
-
EventType: "PointerEvent",
|
|
59
|
-
defaultInit: {
|
|
60
|
-
bubbles: true,
|
|
61
|
-
cancelable: true,
|
|
62
|
-
composed: true
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
copy: {
|
|
66
|
-
EventType: "ClipboardEvent",
|
|
67
|
-
defaultInit: {
|
|
68
|
-
bubbles: true,
|
|
69
|
-
cancelable: true,
|
|
70
|
-
composed: true
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
change: {
|
|
74
|
-
EventType: "Event",
|
|
75
|
-
defaultInit: {
|
|
76
|
-
bubbles: true,
|
|
77
|
-
cancelable: false
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
cut: {
|
|
81
|
-
EventType: "ClipboardEvent",
|
|
82
|
-
defaultInit: {
|
|
83
|
-
bubbles: true,
|
|
84
|
-
cancelable: true,
|
|
85
|
-
composed: true
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
dblclick: {
|
|
89
|
-
EventType: "MouseEvent",
|
|
90
|
-
defaultInit: {
|
|
91
|
-
bubbles: true,
|
|
92
|
-
cancelable: true,
|
|
93
|
-
composed: true
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
focus: {
|
|
97
|
-
EventType: "FocusEvent",
|
|
98
|
-
defaultInit: {
|
|
99
|
-
bubbles: false,
|
|
100
|
-
cancelable: false,
|
|
101
|
-
composed: true
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
focusin: {
|
|
105
|
-
EventType: "FocusEvent",
|
|
106
|
-
defaultInit: {
|
|
107
|
-
bubbles: true,
|
|
108
|
-
cancelable: false,
|
|
109
|
-
composed: true
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
focusout: {
|
|
113
|
-
EventType: "FocusEvent",
|
|
114
|
-
defaultInit: {
|
|
115
|
-
bubbles: true,
|
|
116
|
-
cancelable: false,
|
|
117
|
-
composed: true
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
keydown: {
|
|
121
|
-
EventType: "KeyboardEvent",
|
|
122
|
-
defaultInit: {
|
|
123
|
-
bubbles: true,
|
|
124
|
-
cancelable: true,
|
|
125
|
-
composed: true
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
keypress: {
|
|
129
|
-
EventType: "KeyboardEvent",
|
|
130
|
-
defaultInit: {
|
|
131
|
-
bubbles: true,
|
|
132
|
-
cancelable: true,
|
|
133
|
-
composed: true
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
keyup: {
|
|
137
|
-
EventType: "KeyboardEvent",
|
|
138
|
-
defaultInit: {
|
|
139
|
-
bubbles: true,
|
|
140
|
-
cancelable: true,
|
|
141
|
-
composed: true
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
paste: {
|
|
145
|
-
EventType: "ClipboardEvent",
|
|
146
|
-
defaultInit: {
|
|
147
|
-
bubbles: true,
|
|
148
|
-
cancelable: true,
|
|
149
|
-
composed: true
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
input: {
|
|
153
|
-
EventType: "InputEvent",
|
|
154
|
-
defaultInit: {
|
|
155
|
-
bubbles: true,
|
|
156
|
-
cancelable: false,
|
|
157
|
-
composed: true
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
mousedown: {
|
|
161
|
-
EventType: "MouseEvent",
|
|
162
|
-
defaultInit: {
|
|
163
|
-
bubbles: true,
|
|
164
|
-
cancelable: true,
|
|
165
|
-
composed: true
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
mouseenter: {
|
|
169
|
-
EventType: "MouseEvent",
|
|
170
|
-
defaultInit: {
|
|
171
|
-
bubbles: false,
|
|
172
|
-
cancelable: false,
|
|
173
|
-
composed: true
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
mouseleave: {
|
|
177
|
-
EventType: "MouseEvent",
|
|
178
|
-
defaultInit: {
|
|
179
|
-
bubbles: false,
|
|
180
|
-
cancelable: false,
|
|
181
|
-
composed: true
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
mousemove: {
|
|
185
|
-
EventType: "MouseEvent",
|
|
186
|
-
defaultInit: {
|
|
187
|
-
bubbles: true,
|
|
188
|
-
cancelable: true,
|
|
189
|
-
composed: true
|
|
190
|
-
}
|
|
191
|
-
},
|
|
192
|
-
mouseout: {
|
|
193
|
-
EventType: "MouseEvent",
|
|
194
|
-
defaultInit: {
|
|
195
|
-
bubbles: true,
|
|
196
|
-
cancelable: true,
|
|
197
|
-
composed: true
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
mouseover: {
|
|
201
|
-
EventType: "MouseEvent",
|
|
202
|
-
defaultInit: {
|
|
203
|
-
bubbles: true,
|
|
204
|
-
cancelable: true,
|
|
205
|
-
composed: true
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
mouseup: {
|
|
209
|
-
EventType: "MouseEvent",
|
|
210
|
-
defaultInit: {
|
|
211
|
-
bubbles: true,
|
|
212
|
-
cancelable: true,
|
|
213
|
-
composed: true
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
pointerover: {
|
|
217
|
-
EventType: "PointerEvent",
|
|
218
|
-
defaultInit: {
|
|
219
|
-
bubbles: true,
|
|
220
|
-
cancelable: true,
|
|
221
|
-
composed: true
|
|
222
|
-
}
|
|
223
|
-
},
|
|
224
|
-
pointerenter: {
|
|
225
|
-
EventType: "PointerEvent",
|
|
226
|
-
defaultInit: {
|
|
227
|
-
bubbles: false,
|
|
228
|
-
cancelable: false
|
|
229
|
-
}
|
|
230
|
-
},
|
|
231
|
-
pointerdown: {
|
|
232
|
-
EventType: "PointerEvent",
|
|
233
|
-
defaultInit: {
|
|
234
|
-
bubbles: true,
|
|
235
|
-
cancelable: true,
|
|
236
|
-
composed: true
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
pointermove: {
|
|
240
|
-
EventType: "PointerEvent",
|
|
241
|
-
defaultInit: {
|
|
242
|
-
bubbles: true,
|
|
243
|
-
cancelable: true,
|
|
244
|
-
composed: true
|
|
245
|
-
}
|
|
246
|
-
},
|
|
247
|
-
pointerup: {
|
|
248
|
-
EventType: "PointerEvent",
|
|
249
|
-
defaultInit: {
|
|
250
|
-
bubbles: true,
|
|
251
|
-
cancelable: true,
|
|
252
|
-
composed: true
|
|
253
|
-
}
|
|
254
|
-
},
|
|
255
|
-
pointercancel: {
|
|
256
|
-
EventType: "PointerEvent",
|
|
257
|
-
defaultInit: {
|
|
258
|
-
bubbles: true,
|
|
259
|
-
cancelable: false,
|
|
260
|
-
composed: true
|
|
261
|
-
}
|
|
262
|
-
},
|
|
263
|
-
pointerout: {
|
|
264
|
-
EventType: "PointerEvent",
|
|
265
|
-
defaultInit: {
|
|
266
|
-
bubbles: true,
|
|
267
|
-
cancelable: true,
|
|
268
|
-
composed: true
|
|
269
|
-
}
|
|
270
|
-
},
|
|
271
|
-
pointerleave: {
|
|
272
|
-
EventType: "PointerEvent",
|
|
273
|
-
defaultInit: {
|
|
274
|
-
bubbles: false,
|
|
275
|
-
cancelable: false
|
|
276
|
-
}
|
|
277
|
-
},
|
|
278
|
-
submit: {
|
|
279
|
-
EventType: "Event",
|
|
280
|
-
defaultInit: {
|
|
281
|
-
bubbles: true,
|
|
282
|
-
cancelable: true
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
};
|
|
286
|
-
function getEventClass(type) {
|
|
287
|
-
return eventMap[type].EventType;
|
|
288
|
-
}
|
|
289
|
-
const mouseEvents = ["MouseEvent", "PointerEvent"];
|
|
290
|
-
function isMouseEvent(type) {
|
|
291
|
-
return mouseEvents.includes(getEventClass(type));
|
|
292
|
-
}
|
|
293
|
-
function isKeyboardEvent(type) {
|
|
294
|
-
return getEventClass(type) === "KeyboardEvent";
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// src/utils/misc/isElementType.ts
|
|
298
|
-
const XHTML_NS = "http://www.w3.org/1999/xhtml";
|
|
299
|
-
const UPPERCASE = /[A-Z]/;
|
|
300
|
-
/**
|
|
301
|
-
* `element.tagName.toLowerCase()` without allocating a string per call: the tag name is the
|
|
302
|
-
* (in HTML documents uppercased) qualified name, which lowercases to `localName` unless the
|
|
303
|
-
* element has a prefix or a mixed-case local name.
|
|
304
|
-
*/
|
|
305
|
-
function lowerTagName(element) {
|
|
306
|
-
const localName = element.localName;
|
|
307
|
-
if (element.prefix == null && typeof localName === "string" && !UPPERCASE.test(localName)) return localName;
|
|
308
|
-
return element.tagName.toLowerCase();
|
|
309
|
-
}
|
|
310
|
-
function isElementType(element, tag, props) {
|
|
311
|
-
if (element.namespaceURI && element.namespaceURI !== XHTML_NS) return false;
|
|
312
|
-
const name = lowerTagName(element);
|
|
313
|
-
if (typeof tag === "string" ? name !== tag : !tag.includes(name)) return false;
|
|
314
|
-
if (props) {
|
|
315
|
-
for (const k in props) if (Object.hasOwn(props, k) && element[k] !== props[k]) return false;
|
|
316
|
-
}
|
|
317
|
-
return true;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
// src/utils/click/isClickableInput.ts
|
|
321
|
-
const clickableInputTypes = {
|
|
322
|
-
button: "button",
|
|
323
|
-
color: "color",
|
|
324
|
-
file: "file",
|
|
325
|
-
image: "image",
|
|
326
|
-
reset: "reset",
|
|
327
|
-
submit: "submit",
|
|
328
|
-
checkbox: "checkbox",
|
|
329
|
-
radio: "radio"
|
|
330
|
-
};
|
|
331
|
-
function isClickableInput(element) {
|
|
332
|
-
return isElementType(element, "button") || isElementType(element, "input") && element.type in clickableInputTypes;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// src/utils/dataTransfer/Blob.ts
|
|
336
|
-
function readBlobText(blob, FileReader) {
|
|
337
|
-
return new Promise((res, rej) => {
|
|
338
|
-
const fr = new FileReader();
|
|
339
|
-
fr.onerror = rej;
|
|
340
|
-
fr.onabort = rej;
|
|
341
|
-
fr.onload = () => {
|
|
342
|
-
res(String(fr.result));
|
|
343
|
-
};
|
|
344
|
-
fr.readAsText(blob);
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// src/utils/dataTransfer/FileList.ts
|
|
349
|
-
function createFileList(window, files) {
|
|
350
|
-
const list = {
|
|
351
|
-
...files,
|
|
352
|
-
length: files.length,
|
|
353
|
-
item: (index) => list[index],
|
|
354
|
-
[Symbol.iterator]: function* nextFile() {
|
|
355
|
-
for (let i = 0; i < list.length; i++) yield list[i];
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
list.constructor = window.FileList;
|
|
359
|
-
/* istanbul ignore else */
|
|
360
|
-
if (window.FileList) Object.setPrototypeOf(list, window.FileList.prototype);
|
|
361
|
-
Object.freeze(list);
|
|
362
|
-
return list;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// src/utils/dataTransfer/DataTransfer.ts
|
|
366
|
-
var DataTransferItemStub = class {
|
|
367
|
-
kind;
|
|
368
|
-
type;
|
|
369
|
-
file = null;
|
|
370
|
-
data = void 0;
|
|
371
|
-
constructor(dataOrFile, type) {
|
|
372
|
-
if (typeof dataOrFile === "string") {
|
|
373
|
-
this.kind = "string";
|
|
374
|
-
this.type = String(type);
|
|
375
|
-
this.data = dataOrFile;
|
|
376
|
-
} else {
|
|
377
|
-
this.kind = "file";
|
|
378
|
-
this.type = dataOrFile.type;
|
|
379
|
-
this.file = dataOrFile;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
getAsFile() {
|
|
383
|
-
return this.file;
|
|
384
|
-
}
|
|
385
|
-
getAsString(callback) {
|
|
386
|
-
if (typeof this.data === "string") callback(this.data);
|
|
387
|
-
}
|
|
388
|
-
/* istanbul ignore next */
|
|
389
|
-
webkitGetAsEntry() {
|
|
390
|
-
throw new Error("not implemented");
|
|
391
|
-
}
|
|
392
|
-
};
|
|
393
|
-
function toAsciiLowercase(value) {
|
|
394
|
-
return value.replace(/[A-Z]/g, (char) => char.toLowerCase());
|
|
395
|
-
}
|
|
396
|
-
var DataTransferItemListStub = class extends Array {
|
|
397
|
-
add(...args) {
|
|
398
|
-
const item = typeof args[0] === "string" ? new DataTransferItemStub(args[0], toAsciiLowercase(args[1])) : new DataTransferItemStub(args[0]);
|
|
399
|
-
this.push(item);
|
|
400
|
-
return item;
|
|
401
|
-
}
|
|
402
|
-
clear() {
|
|
403
|
-
this.splice(0, this.length);
|
|
404
|
-
}
|
|
405
|
-
remove(index) {
|
|
406
|
-
this.splice(index, 1);
|
|
407
|
-
}
|
|
408
|
-
};
|
|
409
|
-
function normalizeFormat(format) {
|
|
410
|
-
const type = toAsciiLowercase(format);
|
|
411
|
-
return type === "text" ? "text/plain" : type === "url" ? "text/uri-list" : type;
|
|
412
|
-
}
|
|
413
|
-
function getTypeMatcher(type, exact) {
|
|
414
|
-
const [group, sub] = type.split("/");
|
|
415
|
-
const isGroup = !sub || sub === "*";
|
|
416
|
-
return (item) => {
|
|
417
|
-
return exact ? item.type === (isGroup ? group : type) : isGroup ? item.type.startsWith(`${group}/`) : item.type === group;
|
|
418
|
-
};
|
|
419
|
-
}
|
|
420
|
-
function createDataTransferStub(window) {
|
|
421
|
-
return new class DataTransferStub {
|
|
422
|
-
getData(format) {
|
|
423
|
-
const type = normalizeFormat(format);
|
|
424
|
-
const match = this.items.find(getTypeMatcher(type, true)) ?? this.items.find(getTypeMatcher(type, false));
|
|
425
|
-
let text = "";
|
|
426
|
-
match?.getAsString((t) => {
|
|
427
|
-
text = t;
|
|
428
|
-
});
|
|
429
|
-
return text;
|
|
430
|
-
}
|
|
431
|
-
setData(format, data) {
|
|
432
|
-
const type = normalizeFormat(format);
|
|
433
|
-
const matchIndex = this.items.findIndex(getTypeMatcher(type, true));
|
|
434
|
-
const item = new DataTransferItemStub(data, type);
|
|
435
|
-
if (matchIndex >= 0) this.items.splice(matchIndex, 1, item);
|
|
436
|
-
else this.items.push(item);
|
|
437
|
-
}
|
|
438
|
-
clearData(format) {
|
|
439
|
-
if (format) {
|
|
440
|
-
const type = normalizeFormat(format);
|
|
441
|
-
const matchIndex = this.items.findIndex(getTypeMatcher(type, true));
|
|
442
|
-
if (matchIndex >= 0) this.items.remove(matchIndex);
|
|
443
|
-
} else this.items.clear();
|
|
444
|
-
}
|
|
445
|
-
dropEffect = "none";
|
|
446
|
-
effectAllowed = "uninitialized";
|
|
447
|
-
items = new DataTransferItemListStub();
|
|
448
|
-
files = createFileList(window, []);
|
|
449
|
-
get types() {
|
|
450
|
-
const t = [];
|
|
451
|
-
if (this.files.length) t.push("Files");
|
|
452
|
-
this.items.forEach((i) => t.push(i.type));
|
|
453
|
-
Object.freeze(t);
|
|
454
|
-
return t;
|
|
455
|
-
}
|
|
456
|
-
/* istanbul ignore next */
|
|
457
|
-
setDragImage() {}
|
|
458
|
-
}();
|
|
459
|
-
}
|
|
460
|
-
function createDataTransfer(window, files = []) {
|
|
461
|
-
const dt = typeof window.DataTransfer === "undefined" ? createDataTransferStub(window) : /* istanbul ignore next */ new window.DataTransfer();
|
|
462
|
-
Object.defineProperty(dt, "files", { get: () => createFileList(window, files) });
|
|
463
|
-
return dt;
|
|
464
|
-
}
|
|
465
|
-
async function getBlobFromDataTransferItem(window, item) {
|
|
466
|
-
if (item.kind === "file") return item.getAsFile();
|
|
467
|
-
return new window.Blob([await new Promise((r) => item.getAsString(r))], { type: item.type });
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
// src/utils/misc/getWindow.ts
|
|
471
|
-
function getWindow(node) {
|
|
472
|
-
if (isDocument$1(node) && node.defaultView) return node.defaultView;
|
|
473
|
-
else if (node.ownerDocument?.defaultView) return node.ownerDocument.defaultView;
|
|
474
|
-
throw new Error(`Could not determine window of node. Node was ${describe(node)}`);
|
|
475
|
-
}
|
|
476
|
-
function isDocument$1(node) {
|
|
477
|
-
return node.nodeType === 9;
|
|
478
|
-
}
|
|
479
|
-
function describe(val) {
|
|
480
|
-
return typeof val === "function" ? `function ${val.name}` : val === null ? "null" : String(val);
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
// src/utils/dataTransfer/Clipboard.ts
|
|
484
|
-
function createClipboardItem(window, ...blobs) {
|
|
485
|
-
const dataMap = Object.fromEntries(blobs.map((b) => [typeof b === "string" ? "text/plain" : b.type, Promise.resolve(b)]));
|
|
486
|
-
/* istanbul ignore if */
|
|
487
|
-
if (typeof window.ClipboardItem !== "undefined") return new window.ClipboardItem(dataMap);
|
|
488
|
-
return new class ClipboardItem {
|
|
489
|
-
data;
|
|
490
|
-
constructor(d) {
|
|
491
|
-
this.data = d;
|
|
492
|
-
}
|
|
493
|
-
get types() {
|
|
494
|
-
return Array.from(Object.keys(this.data));
|
|
495
|
-
}
|
|
496
|
-
async getType(type) {
|
|
497
|
-
const value = await this.data[type];
|
|
498
|
-
if (!value) throw new Error(`${type} is not one of the available MIME types on this item.`);
|
|
499
|
-
return value instanceof window.Blob ? value : new window.Blob([value], { type });
|
|
500
|
-
}
|
|
501
|
-
}(dataMap);
|
|
502
|
-
}
|
|
503
|
-
const ClipboardStubControl = Symbol("Manage ClipboardSub");
|
|
504
|
-
function createClipboardStub(window, control) {
|
|
505
|
-
return Object.assign(new class Clipboard extends window.EventTarget {
|
|
506
|
-
items = [];
|
|
507
|
-
async read() {
|
|
508
|
-
return Array.from(this.items);
|
|
509
|
-
}
|
|
510
|
-
async readText() {
|
|
511
|
-
let text = "";
|
|
512
|
-
for (const item of this.items) {
|
|
513
|
-
const type = item.types.includes("text/plain") ? "text/plain" : item.types.find((t) => t.startsWith("text/"));
|
|
514
|
-
if (type) text += await item.getType(type).then((b) => readBlobText(b, window.FileReader));
|
|
515
|
-
}
|
|
516
|
-
return text;
|
|
517
|
-
}
|
|
518
|
-
async write(data) {
|
|
519
|
-
this.items = data;
|
|
520
|
-
}
|
|
521
|
-
async writeText(text) {
|
|
522
|
-
this.items = [createClipboardItem(window, text)];
|
|
523
|
-
}
|
|
524
|
-
}(), { [ClipboardStubControl]: control });
|
|
525
|
-
}
|
|
526
|
-
function isClipboardStub(clipboard) {
|
|
527
|
-
return !!clipboard?.[ClipboardStubControl];
|
|
528
|
-
}
|
|
529
|
-
function attachClipboardStubToView(window) {
|
|
530
|
-
if (isClipboardStub(window.navigator.clipboard)) return window.navigator.clipboard[ClipboardStubControl];
|
|
531
|
-
const realClipboard = Object.getOwnPropertyDescriptor(window.navigator, "clipboard");
|
|
532
|
-
let stub;
|
|
533
|
-
const control = {
|
|
534
|
-
resetClipboardStub: () => {
|
|
535
|
-
stub = createClipboardStub(window, control);
|
|
536
|
-
},
|
|
537
|
-
detachClipboardStub: () => {
|
|
538
|
-
/* istanbul ignore if */
|
|
539
|
-
if (realClipboard) Object.defineProperty(window.navigator, "clipboard", realClipboard);
|
|
540
|
-
else Object.defineProperty(window.navigator, "clipboard", {
|
|
541
|
-
value: void 0,
|
|
542
|
-
configurable: true
|
|
543
|
-
});
|
|
544
|
-
}
|
|
545
|
-
};
|
|
546
|
-
stub = createClipboardStub(window, control);
|
|
547
|
-
Object.defineProperty(window.navigator, "clipboard", {
|
|
548
|
-
get: () => stub,
|
|
549
|
-
configurable: true
|
|
550
|
-
});
|
|
551
|
-
return stub[ClipboardStubControl];
|
|
552
|
-
}
|
|
553
|
-
function resetClipboardStubOnView(window) {
|
|
554
|
-
if (isClipboardStub(window.navigator.clipboard)) window.navigator.clipboard[ClipboardStubControl].resetClipboardStub();
|
|
555
|
-
}
|
|
556
|
-
function detachClipboardStubFromView(window) {
|
|
557
|
-
if (isClipboardStub(window.navigator.clipboard)) window.navigator.clipboard[ClipboardStubControl].detachClipboardStub();
|
|
558
|
-
}
|
|
559
|
-
async function readDataTransferFromClipboard(document) {
|
|
560
|
-
const window = document.defaultView;
|
|
561
|
-
const clipboard = window?.navigator.clipboard;
|
|
562
|
-
const items = clipboard && await clipboard.read();
|
|
563
|
-
if (!items) throw new Error("The Clipboard API is unavailable.");
|
|
564
|
-
const dt = createDataTransfer(window);
|
|
565
|
-
for (const item of items) for (const type of item.types) dt.setData(type, await item.getType(type).then((b) => readBlobText(b, window.FileReader)));
|
|
566
|
-
return dt;
|
|
567
|
-
}
|
|
568
|
-
async function writeDataTransferToClipboard(document, clipboardData) {
|
|
569
|
-
const window = getWindow(document);
|
|
570
|
-
const clipboard = window.navigator.clipboard;
|
|
571
|
-
const items = [];
|
|
572
|
-
for (let i = 0; i < clipboardData.items.length; i++) {
|
|
573
|
-
const dtItem = clipboardData.items[i];
|
|
574
|
-
const blob = await getBlobFromDataTransferItem(window, dtItem);
|
|
575
|
-
items.push(createClipboardItem(window, blob));
|
|
576
|
-
}
|
|
577
|
-
if (!(clipboard && await clipboard.write(items).then(
|
|
578
|
-
() => true,
|
|
579
|
-
/* istanbul ignore next */
|
|
580
|
-
() => false
|
|
581
|
-
))) throw new Error("The Clipboard API is unavailable.");
|
|
582
|
-
}
|
|
583
|
-
const g = globalThis;
|
|
1
|
+
import{createRequire as e}from"node:module";import*as t from"@ctrl/dom/internal";import{$impl as n,describeCall as r,tracePromise as i,tracing as a}from"@ctrl/dom/internal";import*as o from"@ctrl/dom/testing-library";var s=Object.defineProperty,__name=(e,t)=>s(e,`name`,{value:t,configurable:!0}),__exportAll=(e,t)=>{let n={};for(var r in e)s(n,r,{get:e[r],enumerable:!0});return t||s(n,Symbol.toStringTag,{value:`Module`}),n},c=/* @__PURE__ */ e(import.meta.url);const l={auxclick:{EventType:`PointerEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},beforeinput:{EventType:`InputEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},blur:{EventType:`FocusEvent`,defaultInit:{bubbles:!1,cancelable:!1,composed:!0}},click:{EventType:`PointerEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},contextmenu:{EventType:`PointerEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},copy:{EventType:`ClipboardEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},change:{EventType:`Event`,defaultInit:{bubbles:!0,cancelable:!1}},cut:{EventType:`ClipboardEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},dblclick:{EventType:`MouseEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},focus:{EventType:`FocusEvent`,defaultInit:{bubbles:!1,cancelable:!1,composed:!0}},focusin:{EventType:`FocusEvent`,defaultInit:{bubbles:!0,cancelable:!1,composed:!0}},focusout:{EventType:`FocusEvent`,defaultInit:{bubbles:!0,cancelable:!1,composed:!0}},keydown:{EventType:`KeyboardEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},keypress:{EventType:`KeyboardEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},keyup:{EventType:`KeyboardEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},paste:{EventType:`ClipboardEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},input:{EventType:`InputEvent`,defaultInit:{bubbles:!0,cancelable:!1,composed:!0}},mousedown:{EventType:`MouseEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},mouseenter:{EventType:`MouseEvent`,defaultInit:{bubbles:!1,cancelable:!1,composed:!0}},mouseleave:{EventType:`MouseEvent`,defaultInit:{bubbles:!1,cancelable:!1,composed:!0}},mousemove:{EventType:`MouseEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},mouseout:{EventType:`MouseEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},mouseover:{EventType:`MouseEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},mouseup:{EventType:`MouseEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},pointerover:{EventType:`PointerEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},pointerenter:{EventType:`PointerEvent`,defaultInit:{bubbles:!1,cancelable:!1}},pointerdown:{EventType:`PointerEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},pointermove:{EventType:`PointerEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},pointerup:{EventType:`PointerEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},pointercancel:{EventType:`PointerEvent`,defaultInit:{bubbles:!0,cancelable:!1,composed:!0}},pointerout:{EventType:`PointerEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},pointerleave:{EventType:`PointerEvent`,defaultInit:{bubbles:!1,cancelable:!1}},submit:{EventType:`Event`,defaultInit:{bubbles:!0,cancelable:!0}}};function getEventClass(e){return l[e].EventType}const u=[`MouseEvent`,`PointerEvent`];function isMouseEvent(e){return u.includes(getEventClass(e))}function isKeyboardEvent(e){return getEventClass(e)===`KeyboardEvent`}const d=/[A-Z]/;function lowerTagName(e){let t=e.localName;return e.prefix==null&&typeof t==`string`&&!d.test(t)?t:e.tagName.toLowerCase()}function isElementType(e,t,n){if(e.namespaceURI&&e.namespaceURI!==`http://www.w3.org/1999/xhtml`)return!1;let r=lowerTagName(e);if(typeof t==`string`?r!==t:!t.includes(r))return!1;if(n){for(let t in n)if(Object.hasOwn(n,t)&&e[t]!==n[t])return!1}return!0}const f={button:`button`,color:`color`,file:`file`,image:`image`,reset:`reset`,submit:`submit`,checkbox:`checkbox`,radio:`radio`};function isClickableInput(e){return isElementType(e,`button`)||isElementType(e,`input`)&&e.type in f}function readBlobText(e,t){return new Promise((n,r)=>{let i=new t;i.onerror=r,i.onabort=r,i.onload=()=>{n(String(i.result))},i.readAsText(e)})}function createFileList(e,t){let n={...t,length:t.length,item:e=>n[e],[Symbol.iterator]:function*nextFile(){for(let e=0;e<n.length;e++)yield n[e]}};return n.constructor=e.FileList,e.FileList&&Object.setPrototypeOf(n,e.FileList.prototype),Object.freeze(n),n}var DataTransferItemStub=class{kind;type;file=null;data=void 0;constructor(e,t){typeof e==`string`?(this.kind=`string`,this.type=String(t),this.data=e):(this.kind=`file`,this.type=e.type,this.file=e)}getAsFile(){return this.file}getAsString(e){typeof this.data==`string`&&e(this.data)}
|
|
2
|
+
/* istanbul ignore next */
|
|
3
|
+
webkitGetAsEntry(){throw Error(`not implemented`)}};function toAsciiLowercase(e){return e.replace(/[A-Z]/g,e=>e.toLowerCase())}var DataTransferItemListStub=class extends Array{add(...e){let t=typeof e[0]==`string`?new DataTransferItemStub(e[0],toAsciiLowercase(e[1])):new DataTransferItemStub(e[0]);return this.push(t),t}clear(){this.splice(0,this.length)}remove(e){this.splice(e,1)}};function normalizeFormat(e){let t=toAsciiLowercase(e);return t===`text`?`text/plain`:t===`url`?`text/uri-list`:t}function getTypeMatcher(e,t){let[n,r]=e.split(`/`),i=!r||r===`*`;return r=>t?r.type===(i?n:e):i?r.type.startsWith(`${n}/`):r.type===n}function createDataTransferStub(e){return new class DataTransferStub{getData(e){let t=normalizeFormat(e),n=this.items.find(getTypeMatcher(t,!0))??this.items.find(getTypeMatcher(t,!1)),r=``;return n?.getAsString(e=>{r=e}),r}setData(e,t){let n=normalizeFormat(e),r=this.items.findIndex(getTypeMatcher(n,!0)),i=new DataTransferItemStub(t,n);r>=0?this.items.splice(r,1,i):this.items.push(i)}clearData(e){if(e){let t=normalizeFormat(e),n=this.items.findIndex(getTypeMatcher(t,!0));n>=0&&this.items.remove(n)}else this.items.clear()}dropEffect=`none`;effectAllowed=`uninitialized`;items=new DataTransferItemListStub;files=createFileList(e,[]);get types(){let e=[];return this.files.length&&e.push(`Files`),this.items.forEach(t=>e.push(t.type)),Object.freeze(e),e}
|
|
4
|
+
/* istanbul ignore next */
|
|
5
|
+
setDragImage(){}}}function createDataTransfer(e,t=[]){let n=e.DataTransfer===void 0?createDataTransferStub(e):/* istanbul ignore next */new e.DataTransfer;return Object.defineProperty(n,"files",{get:()=>createFileList(e,t)}),n}async function getBlobFromDataTransferItem(e,t){return t.kind===`file`?t.getAsFile():new e.Blob([await new Promise(e=>t.getAsString(e))],{type:t.type})}function getWindow(e){if(isDocument$1(e)&&e.defaultView)return e.defaultView;if(e.ownerDocument?.defaultView)return e.ownerDocument.defaultView;throw Error(`Could not determine window of node. Node was ${describe(e)}`)}function isDocument$1(e){return e.nodeType===9}__name(isDocument$1,`isDocument`);function describe(e){return typeof e==`function`?`function ${e.name}`:e===null?`null`:String(e)}function createClipboardItem(e,...t){let n=Object.fromEntries(t.map(e=>[typeof e==`string`?`text/plain`:e.type,Promise.resolve(e)]));return e.ClipboardItem===void 0?new class ClipboardItem{data;constructor(e){this.data=e}get types(){return Array.from(Object.keys(this.data))}async getType(t){let n=await this.data[t];if(!n)throw Error(`${t} is not one of the available MIME types on this item.`);return n instanceof e.Blob?n:new e.Blob([n],{type:t})}}(n):new e.ClipboardItem(n)}const p=Symbol(`Manage ClipboardSub`);function createClipboardStub(e,t){return Object.assign(new class Clipboard extends e.EventTarget{items=[];async read(){return Array.from(this.items)}async readText(){let t=``;for(let n of this.items){let r=n.types.includes(`text/plain`)?`text/plain`:n.types.find(e=>e.startsWith(`text/`));r&&(t+=await n.getType(r).then(t=>readBlobText(t,e.FileReader)))}return t}async write(e){this.items=e}async writeText(t){this.items=[createClipboardItem(e,t)]}},{[p]:t})}function isClipboardStub(e){return!!e?.[p]}function attachClipboardStubToView(e){if(isClipboardStub(e.navigator.clipboard))return e.navigator.clipboard[p];let t=Object.getOwnPropertyDescriptor(e.navigator,`clipboard`),n,r={resetClipboardStub:()=>{n=createClipboardStub(e,r)},detachClipboardStub:()=>{
|
|
6
|
+
/* istanbul ignore if */
|
|
7
|
+
t?Object.defineProperty(e.navigator,"clipboard",t):Object.defineProperty(e.navigator,"clipboard",{value:void 0,configurable:!0})}};return n=createClipboardStub(e,r),Object.defineProperty(e.navigator,"clipboard",{get:()=>n,configurable:!0}),n[p]}function resetClipboardStubOnView(e){isClipboardStub(e.navigator.clipboard)&&e.navigator.clipboard[p].resetClipboardStub()}function detachClipboardStubFromView(e){isClipboardStub(e.navigator.clipboard)&&e.navigator.clipboard[p].detachClipboardStub()}async function readDataTransferFromClipboard(e){let t=e.defaultView,n=t?.navigator.clipboard,r=n&&await n.read();if(!r)throw Error(`The Clipboard API is unavailable.`);let i=createDataTransfer(t);for(let e of r)for(let n of e.types)i.setData(n,await e.getType(n).then(e=>readBlobText(e,t.FileReader)));return i}async function writeDataTransferToClipboard(e,t){let n=getWindow(e),r=n.navigator.clipboard,i=[];for(let e=0;e<t.items.length;e++){let r=t.items[e],a=await getBlobFromDataTransferItem(n,r);i.push(createClipboardItem(n,a))}if(!(r&&await r.write(i).then(()=>!0,
|
|
8
|
+
/* istanbul ignore next */
|
|
9
|
+
()=>!1)))throw Error(`The Clipboard API is unavailable.`)}const m=globalThis;
|
|
10
|
+
/* istanbul ignore else */
|
|
11
|
+
typeof m.afterEach==`function`&&m.afterEach(()=>{m.window!==void 0&&resetClipboardStubOnView(m.window)}),typeof m.afterAll==`function`&&m.afterAll(()=>{m.window!==void 0&&detachClipboardStubFromView(m.window)});const h=globalThis.parseInt;function buildTimeValue(e){let t=e.replace(/\D/g,``);if(t.length<2)return e;let n=h(t[0],10),r=h(t[1],10);if(n>=3||n===2&&r>=4){let e;return e=n>=3?1:2,build(t,e)}return e.length===2?e:build(t,2)}function build(e,t){let n=e.slice(0,t),r=Math.min(h(n,10),23),i=e.slice(t),a=h(i,10),o=Math.min(a,59);return`${r.toString().padStart(2,`0`)}:${o.toString().padStart(2,`0`)}`}function isValidDateOrTimeValue(e,t){let n=e.cloneNode();return n.value=t,n.value===t}function isContentEditable(e){return e.hasAttribute(`contenteditable`)&&(e.getAttribute(`contenteditable`)==`true`||e.getAttribute(`contenteditable`)==``)}function getContentEditable(e){let t=getElement$1(e);return t&&(t.closest(`[contenteditable=""]`)||t.closest(`[contenteditable="true"]`))}function getElement$1(e){return e.nodeType===1?e:e.parentElement}__name(getElement$1,`getElement`);function isEditable(e){return isEditableInputOrTextArea(e)&&!e.readOnly||isContentEditable(e)}const g={text:`text`,date:`date`,"datetime-local":`datetime-local`,email:`email`,month:`month`,number:`number`,password:`password`,search:`search`,tel:`tel`,time:`time`,url:`url`,week:`week`};function isEditableInputOrTextArea(e){return isElementType(e,`textarea`)||isElementType(e,`input`)&&e.type in g}const ee={email:`email`,password:`password`,search:`search`,telephone:`telephone`,text:`text`,url:`url`};function getMaxLength(e){let t=e.getAttribute(`maxlength`)??``;return/^\d+$/.test(t)&&Number(t)>=0?Number(t):void 0}function supportsMaxLength(e){return isElementType(e,`textarea`)||isElementType(e,`input`)&&e.type in ee}const _=Symbol(`files and value properties are mocked`);function restoreProperty(e,t,n){n?Object.defineProperty(e,t,n):delete e[t]}function setFiles(e,t){e[_]?.restore();let n=Object.getOwnPropertyDescriptor(e,`type`),r=Object.getOwnPropertyDescriptor(e,`value`),i=Object.getOwnPropertyDescriptor(e,`files`);function restore(){restoreProperty(e,`type`,n),restoreProperty(e,`value`,r),restoreProperty(e,`files`,i)}e[_]={restore},Object.defineProperties(e,{files:{configurable:!0,get:()=>t},value:{configurable:!0,get:()=>t.length?`C:\\fakepath\\${t[0].name}`:``,set(t){t===``?restore():r?.set?.call(e,t)}},type:{configurable:!0,get:()=>`file`,set(t){t!==`file`&&(restore(),e.type=t)}}})}function getNextCursorPosition(e,t,n,r){if(isTextNode(e)&&t+n>=0&&t+n<=e.nodeValue.length)return{node:e,offset:t+n};let i=getNextCharacterContentNode(e,t,n);if(i){if(isTextNode(i))return{node:i,offset:n>0?Math.min(1,i.nodeValue.length):Math.max(i.nodeValue.length-1,0)};if(isElementType(i,`br`)){let e=getNextCharacterContentNode(i,void 0,n);return e?isTextNode(e)?{node:e,offset:n>0?0:e.nodeValue.length}:n<0&&isElementType(e,`br`)?{node:i.parentNode,offset:getOffset(i)}:{node:e.parentNode,offset:getOffset(e)+(n>0?0:1)}:n<0&&r===`deleteContentBackward`?{node:i.parentNode,offset:getOffset(i)}:void 0}return{node:i.parentNode,offset:getOffset(i)+ +(n>0)}}}function getNextCharacterContentNode(e,t,n){let r=Number(t)+(n<0?-1:0);return t!==void 0&&isElement$1(e)&&r>=0&&r<e.children.length&&(e=e.children[r]),walkNodes(e,n===1?`next`:`previous`,isTreatedAsCharacterContent)}function isTreatedAsCharacterContent(e){if(isTextNode(e))return!0;if(isElement$1(e)){if(isElementType(e,[`input`,`textarea`]))return e.type!==`hidden`;if(isElementType(e,`br`))return!0}return!1}function getOffset(e){let t=0;for(;e.previousSibling;)t++,e=e.previousSibling;return t}function isElement$1(e){return e.nodeType===1}__name(isElement$1,`isElement`);function isTextNode(e){return e.nodeType===3}function walkNodes(e,t,n){for(;;){let r=e[`${t}Sibling`];if(r){if(e=getDescendant(r,t===`next`?`first`:`last`),n(e))return e}else if(e.parentNode&&(!isElement$1(e.parentNode)||!isContentEditable(e.parentNode)&&e.parentNode!==e.ownerDocument?.body))e=e.parentNode;else break}}function getDescendant(e,t){for(;e.hasChildNodes();)e=e[`${t}Child`];return e}const te=[`button`,`input`,`select`,`textarea`,`optgroup`,`option`];function isDisabled(e){for(let t=e;t;t=t.parentElement)if(isElementType(t,te)){if(t.hasAttribute(`disabled`))return!0}else if(isElementType(t,`fieldset`)){if(t.hasAttribute(`disabled`)&&!t.querySelector(`:scope > legend`)?.contains(e))return!0}else if(t.tagName.includes(`-`)&&t.constructor.formAssociated&&t.hasAttribute(`disabled`))return!0;return!1}function getActiveElement(e){let t=e.activeElement;if(t?.shadowRoot){let e=getActiveElement(t.shadowRoot);if(e)return e}else if(t&&isElementType(t,`iframe`)){let e=t.contentDocument;if(e)return getActiveElement(e)}return isDisabled(t)?e.ownerDocument?
|
|
12
|
+
/* istanbul ignore next */e.ownerDocument.body:e.body:t}function getActiveElementOrBody(e){return getActiveElement(e)??/* istanbul ignore next */e.body}function isVisible(e){let t=getWindow(e);for(let n=e;n?.ownerDocument;n=n.parentElement){let{display:e,visibility:r}=t.getComputedStyle(n);if(e===`none`||r===`hidden`)return!1}return!0}const v=`input:not([type=hidden]):not([disabled]), button:not([disabled]), select:not([disabled]), textarea:not([disabled]), [contenteditable=""], [contenteditable="true"], a[href], [tabindex]:not([disabled]), details > summary`;function getTabDestination(e,t){let n=e.ownerDocument,r=n.querySelectorAll(v),i=Array.from(r).filter(t=>t===e||!(Number(t.getAttribute(`tabindex`))<0||isDisabled(t)));Number(e.getAttribute(`tabindex`))>=0&&i.sort((e,t)=>{let n=Number(e.getAttribute(`tabindex`)),r=Number(t.getAttribute(`tabindex`));return n===r?0:n===0?1:r===0?-1:n-r});let a={},o=[n.body],s=isElementType(e,`input`,{type:`radio`})?e.name:void 0;i.forEach(t=>{let n=t;if(isElementType(n,`input`,{type:`radio`})&&n.name){if(n===e){o.push(n);return}if(n.name===s)return;if(n.checked){o=o.filter(e=>!isElementType(e,`input`,{type:`radio`,name:n.name})),o.push(n),a[n.name]=n;return}if(a[n.name]!==void 0)return}o.push(n)});for(let r=o.findIndex(t=>t===e);;)if(r+=t?-1:1,r===o.length?r=0:r===-1&&(r=o.length-1),o[r]===e||o[r]===n.body||isVisible(o[r]))return o[r]}function isFocusable(e){return e.matches(v)}function hasOwnSelection(e){return isElement(e)&&isEditableInputOrTextArea(e)}function hasNoSelection(e){return isElement(e)&&isClickableInput(e)}function isElement(e){return e.nodeType===1}const y={"{":`}`,"[":`]`};function readNextDescriptor(e,t){let n=0,r=e[n]in y?e[n]:``;n+=r.length;let i=RegExp(`^\\${r}{2}`).test(e)?``:r;return{type:i,...i===``?readPrintableChar(e,n,t):readTag(e,n,i,t)}}function readPrintableChar(e,t,n){let r=e[t];return assertDescriptor(r,e,t,n),t+=r.length,{consumedLength:t,descriptor:r,releasePrevious:!1,releaseSelf:!0,repeat:1}}function readTag(e,t,n,r){let i=e[t]===`/`?`/`:``;t+=i.length;let a=n===`{`&&e[t]===`\\`;t+=Number(a);let o=a?e[t]:e.slice(t).match(n===`{`?/^\w+|^[^}>/]/:/^\w+/)?.[0];assertDescriptor(o,e,t,r),t+=o.length;let s=e.slice(t).match(/^>\d+/)?.[0]??``;t+=s.length;let c=e[t]===`/`||!s&&e[t]===`>`?e[t]:``;t+=c.length;let l=y[n],u=e[t]===l?l:``;if(!u)throw Error(getErrorMessage([!s&&`repeat modifier`,!c&&`release modifier`,`"${l}"`].filter(Boolean).join(` or `),e[t],e,r));return t+=u.length,{consumedLength:t,descriptor:o,releasePrevious:!!i,repeat:s?Math.max(Number(s.substr(1)),1):1,releaseSelf:hasReleaseSelf(c,s)}}function assertDescriptor(e,t,n,r){if(!e)throw Error(getErrorMessage(`key descriptor`,t[n],t,r))}function hasReleaseSelf(e,t){if(e)return e===`/`;if(t)return!1}function getErrorMessage(e,t,n,r){return`Expected ${e} but found "${t??``}" in "${n}"
|
|
13
|
+
See ${r===`pointer`?`https://testing-library.com/docs/user-event/pointer#pressing-a-button-or-touching-the-screen`:`https://testing-library.com/docs/user-event/keyboard`}
|
|
14
|
+
for more information about how userEvent parses your input.`}function cloneEvent(e){return new e.constructor(e.type,e)}function findClosest(e,t){let n=e;do{if(t(n))return n;n=n.parentElement}while(n&&n!==e.ownerDocument.body)}function getDocumentFromNode(e){return isDocument(e)?e:e.ownerDocument}function isDocument(e){return e.nodeType===9}function getTreeDiff(e,t){let n=[];for(let t=e;t;t=t.parentElement)n.push(t);let r=[];for(let e=t;e;e=e.parentElement)r.push(e);let i=0;for(;!(i>=n.length||i>=r.length||n[n.length-1-i]!==r[r.length-1-i]);i++);return[n.slice(0,n.length-i),r.slice(0,r.length-i),r.slice(r.length-i)]}const b={Trigger:2,Call:1};function setLevelRef(e,t){e.levelRefs[t]={}}function getLevelRef(e,t){return e.levelRefs[t]}const x=t;function pick(e){if(x===null)return null;let t={};for(let n of e){let e=x[n];if(typeof e!=`function`)return null;t[n]=e}return t}const S=pick([`getUIValue`,`setUIValue`,`clearUIValue`,`getUISelection`,`setUISelection`]);pick([`computedValue`,`isDisplayNone`,`isVisibilityHidden`]);const C=x?.skipIdleTime;function skipIdleTime(e){return C===void 0||C(e)}const w=x?.foreignImmediatesPending;function immediatesPending(){return w===void 0?process.getActiveResourcesInfo().includes(`Immediate`):w()}const T=x?.NodeImpl??null;function implOf(e){if(T===null||e==null)return null;let t=e[n];return t instanceof T?t:null}function hasCtrlDomUI(e){return S!==null&&implOf(e)!==null}function isFaked(e){return e!==void 0&&(e._isMockFunction===!0||Object.hasOwn(e,`clock`))}function defaultAdvanceTimers(){return Promise.resolve()}function wait(e){let t=e.delay;if(typeof t==`number`)return Promise.all([new Promise(e=>globalThis.setTimeout(()=>e(),t)),e.advanceTimers(t)])}function resolveOnImmediate(e){globalThis.setImmediate(e)}function countTimeouts(){let e=process.getActiveResourcesInfo(),t=0;for(let n=0;n<e.length;n++)e[n]===`Timeout`&&t++;return t}const E=/* @__PURE__ */ new Set,D=/* @__PURE__ */ new Map,O={};function copyProps(e,t){Object.defineProperties(e,Object.getOwnPropertyDescriptors(t))}function wrapSchedule(e){let t=globalThis,n=t[e];if(n===O[e]||typeof n!=`function`||isFaked(n))return;let r=n,i=e===`setInterval`,wrapper=function(e,t,...n){if(typeof e!=`function`)return r.call(this,e,t,...n);let a=Math.max(1,Number(t)||0),o={due:performance.now()+a,interval:i?a:0,handle:void 0};E.add(o);let s,run=function(...t){return i?o.due=performance.now()+o.interval:(E.delete(o),D.delete(s)),e.apply(this,t)};return s=r.call(this,run,t,...n),o.handle=s,D.set(s,o),s};copyProps(wrapper,r),O[e]=wrapper,t[e]=wrapper}function wrapClear(e){let t=globalThis,n=t[e];if(n===O[e]||typeof n!=`function`||isFaked(n))return;let r=n,wrapper=function(e){let t=D.get(e);return t!==void 0&&(E.delete(t),D.delete(e)),r.call(this,e)};copyProps(wrapper,r),O[e]=wrapper,t[e]=wrapper}function observeTimerGlobals(){wrapSchedule(`setTimeout`),wrapSchedule(`setInterval`),wrapClear(`clearTimeout`),wrapClear(`clearInterval`)}function timerGlobalsObserved(){let e=globalThis;return O.setTimeout!==void 0&&e.setTimeout===O.setTimeout&&e.setInterval===O.setInterval&&e.clearTimeout===O.clearTimeout&&e.clearInterval===O.clearInterval}function trackedTimerDueSoon(){let e=performance.now();for(let t of E)if(t.due<=e+4){if(t.interval===0&&t.due<e-50){E.delete(t),D.delete(t.handle);continue}return!0}return!1}let k=-1;function untrackedTimeouts(){let e=countTimeouts(),t=0;for(let e of D.keys())typeof e==`object`&&e&&e.hasRef?.()===!1||t++;return e-t}typeof globalThis.setImmediate==`function`&&observeTimerGlobals();function markTimers(e){e.delay===0&&e.advanceTimers===defaultAdvanceTimers&&observeTimerGlobals()}function realTimersAtZeroDelay(e){if(e.delay!==0||e.advanceTimers!==defaultAdvanceTimers)return!1;let t=globalThis.setImmediate;return typeof t==`function`&&!isFaked(t)&&timerGlobalsObserved()}function canYieldWithImmediate(e){if(!realTimersAtZeroDelay(e)||trackedTimerDueSoon())return!1;let t=untrackedTimeouts();return k===-1||t>k||!skipIdleTime(1)?!1:(k=t,!0)}async function yieldBetweenActions(e){if(canYieldWithImmediate(e)?await new Promise(resolveOnImmediate):(await wait(e),timerGlobalsObserved()&&(k=untrackedTimeouts())),realTimersAtZeroDelay(e))for(let e=0;e<20&&immediatesPending();e++)await new Promise(resolveOnImmediate)}function isDifferentPointerPosition(e,t){return e.target!==t.target||e.coords?.x!==t.coords?.x||e.coords?.y!==t.coords?.y||e.coords?.clientX!==t.coords?.clientX||e.coords?.clientY!==t.coords?.clientY||e.coords?.offsetX!==t.coords?.offsetX||e.coords?.offsetY!==t.coords?.offsetY||e.coords?.pageX!==t.coords?.pageX||e.coords?.pageY!==t.coords?.pageY||e.coords?.screenX!==t.coords?.screenX||e.coords?.screenY!==t.coords?.screenY||e.caret?.node!==t.caret?.node||e.caret?.offset!==t.caret?.offset}var Buttons=class{pressed={};mask=0;getButtons(){return this.mask}down(e){let t=getMouseButtonId(e.button);if(t in this.pressed)this.pressed[t].push(e);else return this.pressed[t]=[e],this.mask|=2**t,t}up(e){let t=getMouseButtonId(e.button);if(t in this.pressed&&(this.pressed[t]=this.pressed[t].filter(t=>t.name!==e.name),this.pressed[t].length===0))return delete this.pressed[t],this.mask&=~(2**t),t}};const A={primary:0,secondary:1,auxiliary:2,back:3,X1:3,forward:4,X2:4};function getMouseButtonId(e=0){return e in A?A[e]:Number(e)}const j={1:2,2:1};function getMouseEventButton(e){return e=getMouseButtonId(e),e in j?j[e]:e}var Device=class{pressedKeys=/* @__PURE__ */ new Set;get countPressed(){return this.pressedKeys.size}isPressed(e){return this.pressedKeys.has(e.name)}addPressed(e){return this.pressedKeys.add(e.name)}removePressed(e){return this.pressedKeys.delete(e.name)}},Mouse=class{position={};buttons=new Buttons;selecting;buttonDownTarget={};clickCount=new class{down={};count={};incOnClick(e){let t=this.down[e]===void 0?void 0:Number(this.down[e])+1;return this.count=this.count[e]===void 0?{}:{[e]:Number(this.count[e])+1},t}getOnDown(e){return this.down={[e]:this.count[e]??0},this.count={[e]:this.count[e]??0},Number(this.count[e])+1}getOnUp(e){return this.down[e]===void 0?void 0:Number(this.down[e])+1}reset(){this.count={}}};move(e,t,n){let r=this.position,i=this.getTarget(e);if(this.position=t,!isDifferentPointerPosition(r,t))return;let a=this.getTarget(e),o=this.getEventInit(`mousemove`),[s,c]=getTreeDiff(i,a);return{leave:()=>{i!==a&&(e.dispatchUIEvent(i,`mouseout`,o),s.forEach(t=>e.dispatchUIEvent(t,`mouseleave`,o)))},enter:()=>{i!==a&&(e.dispatchUIEvent(a,`mouseover`,o),c.forEach(t=>e.dispatchUIEvent(t,`mouseenter`,o)))},move:()=>{n||(e.dispatchUIEvent(a,`mousemove`,o),this.modifySelecting(e))}}}down(e,t,n){let r=this.buttons.down(t);if(r===void 0)return;let i=this.getTarget(e);this.buttonDownTarget[r]=i;let a=this.getEventInit(`mousedown`,t.button),o=isDisabled(i);!n&&(o||e.dispatchUIEvent(i,`mousedown`,a))&&(this.startSelecting(e,a.detail),focusElement(i)),!o&&getMouseEventButton(t.button)===2&&e.dispatchUIEvent(i,`contextmenu`,this.getEventInit(`contextmenu`,t.button))}up(e,t,n){let r=this.buttons.up(t);if(r===void 0)return;let i=this.getTarget(e);if(!isDisabled(i)){if(!n){let n=this.getEventInit(`mouseup`,t.button);e.dispatchUIEvent(i,`mouseup`,n),this.endSelecting()}let a=getTreeDiff(this.buttonDownTarget[r],i)[2][0];if(a){let n=this.getEventInit(`click`,t.button);n.detail&&(e.dispatchUIEvent(a,n.button===0?`click`:`auxclick`,n),n.button===0&&n.detail===2&&e.dispatchUIEvent(a,`dblclick`,{...this.getEventInit(`dblclick`,t.button),detail:n.detail}))}}}resetClickCount(){this.clickCount.reset()}getEventInit(e,t){let n={...this.position.coords};return n.button=getMouseEventButton(t),n.buttons=this.buttons.getButtons(),e===`mousedown`?n.detail=this.clickCount.getOnDown(n.button):e===`mouseup`?n.detail=this.clickCount.getOnUp(n.button):(e===`click`||e===`auxclick`)&&(n.detail=this.clickCount.incOnClick(n.button)),n}getTarget(e){return this.position.target??e.config.document.body}startSelecting(e,t){this.selecting=setSelectionPerMouseDown({document:e.config.document,target:this.getTarget(e),node:this.position.caret?.node,offset:this.position.caret?.offset,clickCount:t})}modifySelecting(e){this.selecting&&modifySelectionPerMouseMove(this.selecting,{document:e.config.document,target:this.getTarget(e),node:this.position.caret?.node,offset:this.position.caret?.offset})}endSelecting(){this.selecting=void 0}},Pointer=class{constructor({pointerId:e,pointerType:t,isPrimary:n},r){this.pointerId=e,this.pointerType=t,this.isPrimary=n,this.isMultitouch=!n,this.buttons=r}pointerId;pointerType;isPrimary;buttons;isMultitouch=!1;isCancelled=!1;isDown=!1;isPrevented=!1;position={};init(e){let t=this.getTarget(e),[,n]=getTreeDiff(null,t),r=this.getEventInit();return assertPointerEvents(e,t),e.dispatchUIEvent(t,`pointerover`,r),n.forEach(t=>e.dispatchUIEvent(t,`pointerenter`,r)),this}move(e,t){let n=this.position,r=this.getTarget(e);if(this.position=t,!isDifferentPointerPosition(n,t))return;let i=this.getTarget(e),a=this.getEventInit(-1),[o,s]=getTreeDiff(r,i);return{leave:()=>{hasPointerEvents(e,r)&&r!==i&&(e.dispatchUIEvent(r,`pointerout`,a),o.forEach(t=>e.dispatchUIEvent(t,`pointerleave`,a)))},enter:()=>{assertPointerEvents(e,i),r!==i&&(e.dispatchUIEvent(i,`pointerover`,a),s.forEach(t=>e.dispatchUIEvent(t,`pointerenter`,a)))},move:()=>{e.dispatchUIEvent(i,`pointermove`,a)}}}down(e,t=0){if(this.isDown)return;let n=this.getTarget(e);assertPointerEvents(e,n),this.isDown=!0,this.isPrevented=!e.dispatchUIEvent(n,`pointerdown`,this.getEventInit(t))}up(e,t=0){if(!this.isDown)return;let n=this.getTarget(e);assertPointerEvents(e,n),this.isPrevented=!1,this.isDown=!1,e.dispatchUIEvent(n,`pointerup`,this.getEventInit(t))}release(e){let t=this.getTarget(e),[n]=getTreeDiff(t,null),r=this.getEventInit();hasPointerEvents(e,t)&&(e.dispatchUIEvent(t,`pointerout`,r),n.forEach(t=>e.dispatchUIEvent(t,`pointerleave`,r))),this.isCancelled=!0}getTarget(e){return this.position.target??e.config.document.body}getEventInit(e){return{...this.position.coords,pointerId:this.pointerId,pointerType:this.pointerType,isPrimary:this.isPrimary,button:getMouseEventButton(e),buttons:this.buttons.getButtons()}}},PointerHost=class{system;constructor(e){this.system=e,this.buttons=new Buttons,this.mouse=new Mouse,this.pointers.new(`mouse`,`mouse`,this.buttons)}mouse;buttons;devices=new class{registry={};get(e){return this.registry[e]??=new Device}};pointers=new class{registry={};nextId=1;new(e,t,n){let r=t!==`touch`||!Object.values(this.registry).some(e=>e.pointerType===`touch`&&!e.isCancelled);return r||Object.values(this.registry).forEach(e=>{e.pointerType===t&&!e.isCancelled&&(e.isMultitouch=!0)}),this.registry[e]=new Pointer({pointerId:this.nextId++,pointerType:t,isPrimary:r},n),this.registry[e]}get(e){if(!this.has(e))throw Error(`Trying to access pointer "${e}" which does not exist.`);return this.registry[e]}has(e){return e in this.registry}};isKeyPressed(e){return this.devices.get(e.pointerType).isPressed(e)}async press(e,t,n){this.devices.get(t.pointerType).addPressed(t),this.buttons.down(t);let r=this.getPointerName(t),i=t.pointerType===`touch`?this.pointers.new(r,t.pointerType,this.buttons):this.pointers.get(r);i.position=n,i.pointerType!==`touch`&&(this.mouse.position=n),i.pointerType===`touch`&&i.init(e),i.down(e,t.button),i.pointerType!==`touch`&&this.mouse.down(e,t,i.isPrevented)}async move(e,t,n){let r=this.pointers.get(t),i=r.move(e,n),a=r.pointerType===`touch`?void 0:this.mouse.move(e,n,r.isPrevented);i?.leave(),a?.leave(),i?.enter(),a?.enter(),i?.move(),a?.move()}async release(e,t,n){let r=this.devices.get(t.pointerType);r.removePressed(t),this.buttons.up(t);let i=this.pointers.get(this.getPointerName(t)),a=i.isPrevented;if(i.position=n,i.pointerType!==`touch`&&(this.mouse.position=n),r.countPressed===0&&i.up(e,t.button),i.pointerType===`touch`&&i.release(e),i.pointerType===`touch`&&!i.isMultitouch){let r=this.mouse.move(e,n,a);r?.leave(),r?.enter(),r?.move(),this.mouse.down(e,t,a)}if(!i.isMultitouch){let r=this.mouse.move(e,n,a);r?.leave(),r?.enter(),r?.move(),this.mouse.up(e,t,a)}}getPointerName(e){return e.pointerType===`touch`?e.name:e.pointerType}getPreviousPosition(e){return this.pointers.has(e)?this.pointers.get(e).position:void 0}resetClickCount(){this.mouse.resetClickCount()}getMouseTarget(e){return this.mouse.position.target??e.config.document.body}setMousePosition(e){this.mouse.position=e,this.pointers.get(`mouse`).position=e}},System=class{keyboard=new KeyboardHost(this);pointer=new PointerHost(this);assignUIEventModifiers(e){let t=this.keyboard.modifiers;e.altKey=t.Alt,e.ctrlKey=t.Control,e.metaKey=t.Meta,e.shiftKey=t.Shift,e.modifierAltGraph=t.AltGraph,e.modifierCapsLock=t.CapsLock,e.modifierFn=t.Fn,e.modifierFnLock=t.FnLock,e.modifierNumLock=t.NumLock,e.modifierScrollLock=t.ScrollLock,e.modifierSymbol=t.Symbol,e.modifierSymbolLock=t.SymbolLock}getUIEventModifiers(){return{altKey:this.keyboard.modifiers.Alt,ctrlKey:this.keyboard.modifiers.Control,metaKey:this.keyboard.modifiers.Meta,shiftKey:this.keyboard.modifiers.Shift,modifierAltGraph:this.keyboard.modifiers.AltGraph,modifierCapsLock:this.keyboard.modifiers.CapsLock,modifierFn:this.keyboard.modifiers.Fn,modifierFnLock:this.keyboard.modifiers.FnLock,modifierNumLock:this.keyboard.modifiers.NumLock,modifierScrollLock:this.keyboard.modifiers.ScrollLock,modifierSymbol:this.keyboard.modifiers.Symbol,modifierSymbolLock:this.keyboard.modifiers.SymbolLock}}};const M=Object.freeze({STANDARD:0,LEFT:1,RIGHT:2,NUMPAD:3,0:`STANDARD`,1:`LEFT`,2:`RIGHT`,3:`NUMPAD`}),ne=[`Alt`,`AltGraph`,`Control`,`Fn`,`Meta`,`Shift`,`Symbol`];function isModifierKey(e){return ne.includes(e)}const re=[`CapsLock`,`FnLock`,`NumLock`,`ScrollLock`,`SymbolLock`];function isModifierLock(e){return re.includes(e)}var KeyboardHost=class{system;constructor(e){this.system=e}modifiers={Alt:!1,AltGraph:!1,CapsLock:!1,Control:!1,Fn:!1,FnLock:!1,Meta:!1,NumLock:!1,ScrollLock:!1,Shift:!1,Symbol:!1,SymbolLock:!1};pressed=new class{registry={};add(e,t){this.registry[e]??={keyDef:t,unpreventedDefault:!1}}has(e){return!!this.registry[e]}setUnprevented(e){let t=this.registry[e];t&&(t.unpreventedDefault=!0)}isUnprevented(e){return!!this.registry[e]?.unpreventedDefault}delete(e){delete this.registry[e]}values(){return Object.values(this.registry)}};carryChar=``;lastKeydownTarget=void 0;modifierLockStart={};isKeyPressed(e){return this.pressed.has(String(e.code))}getPressedKeys(){return this.pressed.values().map(e=>e.keyDef)}async keydown(e,t,n=!1){let r=String(t.key),i=String(t.code),a=getActiveElementOrBody(e.config.document);this.setKeydownTarget(a),this.pressed.add(i,t),isModifierKey(r)&&(this.modifiers[r]=!0);let o=e.dispatchUIEvent(a,`keydown`,{key:r,code:i,repeat:n});isModifierLock(r)&&!this.modifiers[r]&&(this.modifiers[r]=!0,this.modifierLockStart[r]=!0),o&&this.pressed.setUnprevented(i),o&&this.hasKeyPress(r)&&e.dispatchUIEvent(getActiveElementOrBody(e.config.document),`keypress`,{key:r,code:i,charCode:t.key===`Enter`?13:String(t.key).charCodeAt(0)})}async keyup(e,t){let n=String(t.key),r=String(t.code),i=this.pressed.isUnprevented(r);this.pressed.delete(r),isModifierKey(n)&&!this.pressed.values().find(e=>e.keyDef.key===n)&&(this.modifiers[n]=!1),e.dispatchUIEvent(getActiveElementOrBody(e.config.document),`keyup`,{key:n,code:r},!i),isModifierLock(n)&&this.modifiers[n]&&(this.modifierLockStart[n]?this.modifierLockStart[n]=!1:this.modifiers[n]=!1)}setKeydownTarget(e){e!==this.lastKeydownTarget&&(this.carryChar=``),this.lastKeydownTarget=e}hasKeyPress(e){return(e.length===1||e===`Enter`)&&!this.modifiers.Control&&!this.modifiers.Alt}};const N=Object.freeze({EachTrigger:4,EachApiCall:2,EachTarget:1,Never:0,4:`EachTrigger`,2:`EachApiCall`,1:`EachTarget`,0:`Never`});function hasPointerEvents(e,t){return checkPointerEvents(e,t)?.pointerEvents!==`none`}function closestPointerEventsDeclaration(e){let t=getWindow(e);for(let n=e,r=[];n?.ownerDocument;n=n.parentElement){r.push(n);let e=t.getComputedStyle(n).pointerEvents;if(e&&![`inherit`,`unset`].includes(e))return{pointerEvents:e,tree:r}}}const P=Symbol(`Last check for pointer-events`);function checkPointerEvents(e,t){let n=t[P];if(!(e.config.pointerEventsCheck!==N.Never&&(!n||hasBitFlag(e.config.pointerEventsCheck,N.EachApiCall)&&n[b.Call]!==getLevelRef(e,b.Call)||hasBitFlag(e.config.pointerEventsCheck,N.EachTrigger)&&n[b.Trigger]!==getLevelRef(e,b.Trigger))))return n?.result;let r=closestPointerEventsDeclaration(t);return t[P]={[b.Call]:getLevelRef(e,b.Call),[b.Trigger]:getLevelRef(e,b.Trigger),result:r},r}function assertPointerEvents(e,t){let n=checkPointerEvents(e,t);if(n?.pointerEvents===`none`)throw Error([`Unable to perform pointer interaction as the element ${n.tree.length>1?`inherits`:`has`} \`pointer-events: none\`:`,``,printTree(n.tree)].join(`
|
|
15
|
+
`))}function printTree(e){return e.reverse().map((t,n)=>[``.padEnd(n),t.tagName,t.id&&`#${t.id}`,t.hasAttribute(`data-testid`)&&`(testId=${t.getAttribute(`data-testid`)})`,getLabelDescr(t),e.length>1&&n===0&&" <-- This element declared `pointer-events: none`",e.length>1&&n===e.length-1&&` <-- Asserted pointer events here`].filter(Boolean).join(``)).join(`
|
|
16
|
+
`)}function getLabelDescr(e){let t;return e.hasAttribute(`aria-label`)?t=e.getAttribute(`aria-label`):e.hasAttribute(`aria-labelledby`)?t=e.ownerDocument.getElementById(e.getAttribute(`aria-labelledby`))?.textContent?.trim():isElementType(e,[`button`,`input`,`meter`,`output`,`progress`,`select`,`textarea`])&&e.labels?.length?t=Array.from(e.labels).map(e=>e.textContent?.trim()).join(`|`):isElementType(e,`button`)&&(t=e.textContent?.trim()),t=t?.replace(/\n/g,` `),Number(t?.length)>30&&(t=`${t?.substring(0,29)}…`),t?`(label=${t})`:``}function hasBitFlag(e,t){return(e&t)>0}const F=Symbol(`Displayed value in UI`),I=Symbol(`Displayed selection in UI`),L=Symbol(`Initial value to compare on blur`);function isUIValue(e){return typeof e==`object`&&F in e}function isUISelectionStart(e){return!!e&&typeof e==`object`&&I in e}function setUIValue(e,t){let n=e;n[L]===void 0&&(n[L]=n.value),hasCtrlDomUI(n)?S.setUIValue(n,t):(n[F]=t,n.value=Object.assign(new String(t),{[F]:!0}))}function getUIValue(e){let t=e;return hasCtrlDomUI(t)?S.getUIValue(t):t[F]===void 0?t.value:String(t[F])}function setUIValueClean(e){hasCtrlDomUI(e)?S.clearUIValue(e):e[F]=void 0}function clearInitialValue(e){e[L]=void 0}function getInitialValue(e){return e[L]}function setUISelectionRaw(e,t){e[I]=t}function setUISelection(e,{focusOffset:t,anchorOffset:n=t},r=`replace`){let i=e,a=getUIValue(i).length,sanitizeOffset=e=>Math.max(0,Math.min(a,e));if(hasCtrlDomUI(i)){let e=r===`replace`?sanitizeOffset(n):getUISelection(i).anchorOffset,a=sanitizeOffset(t);i[I]={anchorOffset:e,focusOffset:a},S.setUISelection(i,Math.min(e,a),Math.max(e,a),`none`);return}let o=r===`replace`||i[I]===void 0?sanitizeOffset(n):i[I].anchorOffset,s=sanitizeOffset(t),c=Math.min(o,s),l=Math.max(o,s);if(i[I]={anchorOffset:o,focusOffset:s},i.selectionStart===c&&i.selectionEnd===l)return;let u=Object.assign(new Number(c),{[I]:!0});try{i.setSelectionRange(u,l)}catch{}}function getUISelection(e){let t=e,n;if(hasCtrlDomUI(t)){let{start:e,end:r}=S.getUISelection(t),i=t[I];n=i!==void 0&&Math.min(i.anchorOffset,i.focusOffset)===e&&Math.max(i.anchorOffset,i.focusOffset)===r?i:{anchorOffset:e,focusOffset:r}}else n=t[I]??{anchorOffset:t.selectionStart??0,focusOffset:t.selectionEnd??0};return{anchorOffset:n.anchorOffset,focusOffset:n.focusOffset,startOffset:Math.min(n.anchorOffset,n.focusOffset),endOffset:Math.max(n.anchorOffset,n.focusOffset)}}function hasUISelection(e){return hasCtrlDomUI(e)||!!e[I]}function setUISelectionClean(e){e[I]=void 0}function getValueOrTextContent(e){return e?isContentEditable(e)?e.textContent:getUIValue(e):null}function copySelection(e){let t=hasOwnSelection(e)?{"text/plain":readSelectedValueFromInput(e)}:{"text/plain":String(e.ownerDocument.getSelection())},n=createDataTransfer(getWindow(e));for(let e in t)t[e]&&n.setData(e,t[e]);return n}function readSelectedValueFromInput(e){let t=getUISelection(e);return getUIValue(e).substring(t.startOffset,t.endOffset)}const R=Symbol(`Track programmatic changes for React workaround`);function isReact17Element(e){return Object.getOwnPropertyNames(e).some(e=>e.startsWith(`__react`))&&getWindow(e).REACT_VERSION===17}function startTrackValue(e){isReact17Element(e)&&(e[R]={previousValue:String(e.value),tracked:[]})}function trackOrSetValue(e,t){e[R]?.tracked?.push(t),e[R]||(setUIValueClean(e),setUISelection(e,{focusOffset:t.length}))}function commitValueAfterInput(e,t){let n=e[R];if(e[R]=void 0,!n?.tracked?.length)return;let r=n.tracked.length===2&&n.tracked[0]===n.previousValue&&n.tracked[1]===e.value;r||setUIValueClean(e),hasUISelection(e)&&setUISelection(e,{focusOffset:r?t:e.value.length})}function getTargetTypeAndSelection(e){let t=getElement(e);if(t&&hasOwnSelection(t))return{type:`input`,selection:getUISelection(t)};let n=t?.ownerDocument.getSelection();return{type:getContentEditable(e)&&n?.anchorNode&&getContentEditable(n.anchorNode)?`contenteditable`:`default`,selection:n}}function getElement(e){return e.nodeType===1?e:e.parentElement}function getInputRange(e){let t=getTargetTypeAndSelection(e);if(t.type===`input`)return t.selection;if(t.type===`contenteditable`)return t.selection?.getRangeAt(0)}function setSelection({focusNode:e,focusOffset:t,anchorNode:n=e,anchorOffset:r=t}){if(getTargetTypeAndSelection(e).type===`input`)return setUISelection(e,{anchorOffset:r,focusOffset:t});n.ownerDocument?.getSelection()?.setBaseAndExtent(n,r,e,t)}function moveSelection(e,t){if(hasOwnSelection(e)){let n=getUISelection(e);setSelection({focusNode:e,focusOffset:n.startOffset===n.endOffset?n.focusOffset+t:t<0?n.startOffset:n.endOffset})}else{let n=e.ownerDocument.getSelection();if(!n?.focusNode)return;if(n.isCollapsed){let e=getNextCursorPosition(n.focusNode,n.focusOffset,t);e&&setSelection({focusNode:e.node,focusOffset:e.offset})}else n[t<0?`collapseToStart`:`collapseToEnd`]()}}function resolveCaretPosition({target:e,node:t,offset:n}){return hasOwnSelection(e)?{node:e,offset:n??getUIValue(e).length}:t?{node:t,offset:n??(t.nodeType===3?t.nodeValue.length:t.childNodes.length)}:findNodeAtTextOffset(e,n)}function findNodeAtTextOffset(e,t,n=!0){let r=t===void 0?e.childNodes.length-1:0,i=t===void 0?-1:1;for(;t===void 0?r>=(n?Math.max(e.childNodes.length-1,0):0):r<=e.childNodes.length;){if(t&&r===e.childNodes.length)throw Error(`The given offset is out of bounds.`);let n=e.childNodes.item(r),a=String(n.textContent);if(a.length){if(t!==void 0&&a.length<t)t-=a.length;else if(n.nodeType===1)return findNodeAtTextOffset(n,t,!1);else if(n.nodeType===3)return{node:n,offset:t??n.nodeValue.length}}r+=i}return{node:e,offset:e.childNodes.length}}function setSelectionPerMouseDown({document:e,target:t,clickCount:n,node:r,offset:i}){if(hasNoSelection(t))return;let a=hasOwnSelection(t),o=String(a?getUIValue(t):t.textContent),[s,c]=r?[i,i]:getTextRange(o,i,n);if(a)return setUISelection(t,{anchorOffset:s??o.length,focusOffset:c??o.length}),{node:t,start:s??0,end:c??o.length};{let{node:n,offset:i}=resolveCaretPosition({target:t,node:r,offset:s}),{node:a,offset:o}=resolveCaretPosition({target:t,node:r,offset:c}),l=t.ownerDocument.createRange();try{l.setStart(n,i),l.setEnd(a,o)}catch{throw Error(`The given offset is out of bounds.`)}let u=e.getSelection();return u?.removeAllRanges(),u?.addRange(l.cloneRange()),l}}function getTextRange(e,t,n){if(n%3==1||e.length===0)return[t,t];let r=t??e.length;return n%3==2?[r-e.substr(0,t).match(/(\w+|\s+|\W)?$/)[0].length,t===void 0?t:t+e.substr(t).match(/^(\w+|\s+|\W)?/)[0].length]:[r-e.substr(0,t).match(/[^\r\n]*$/)[0].length,t===void 0?t:t+e.substr(t).match(/^[^\r\n]*/)[0].length]}function modifySelectionPerMouseMove(e,{document:t,target:n,node:r,offset:i}){let a=resolveCaretPosition({target:n,node:r,offset:i});if(`node`in e){
|
|
17
|
+
/* istanbul ignore else */
|
|
18
|
+
if(a.node===e.node){let t=a.offset<e.start?e.end:e.start,n=a.offset>e.end||a.offset<e.start?a.offset:e.end;setUISelection(e.node,{anchorOffset:t,focusOffset:n})}}else{let n=e.cloneRange(),r=n.comparePoint(a.node,a.offset);r<0?n.setStart(a.node,a.offset):r>0&&n.setEnd(a.node,a.offset);let i=t.getSelection();i?.removeAllRanges(),i?.addRange(n.cloneRange())}}function selectAll(e){if(hasOwnSelection(e))return setSelection({focusNode:e,anchorOffset:0,focusOffset:getUIValue(e).length});let t=getContentEditable(e)??e.ownerDocument.body;setSelection({focusNode:t,anchorOffset:0,focusOffset:t.childNodes.length})}function isAllSelected(e){if(hasOwnSelection(e))return getUISelection(e).startOffset===0&&getUISelection(e).endOffset===getUIValue(e).length;let t=getContentEditable(e)??e.ownerDocument.body,n=e.ownerDocument.getSelection();return n?.anchorNode===t&&n.focusNode===t&&n.anchorOffset===0&&n.focusOffset===t.childNodes.length}function setSelectionRange(e,t,n){if(hasOwnSelection(e))return setSelection({focusNode:e,anchorOffset:t,focusOffset:n});
|
|
19
|
+
/* istanbul ignore else */
|
|
20
|
+
if(isContentEditable(e)&&e.firstChild?.nodeType===3)return setSelection({focusNode:e.firstChild,anchorOffset:t,focusOffset:n});
|
|
21
|
+
/* istanbul ignore next */
|
|
22
|
+
throw Error(`Not implemented. The result of this interaction is unreliable.`)}function updateSelectionOnFocus(e){let t=e.ownerDocument.getSelection();
|
|
23
|
+
/* istanbul ignore if */
|
|
24
|
+
if(t?.focusNode&&hasOwnSelection(e)){let n=getContentEditable(t.focusNode);if(n){if(!t.isCollapsed){let e=n.firstChild?.nodeType===3?n.firstChild:n;t.setBaseAndExtent(e,0,e,0)}}else t.setBaseAndExtent(e,0,e,0)}}const ie={asyncWrapper:async e=>e(),eventWrapper:e=>e(),getElementError(e){let t=Error(e??``);return t.name=`TestingLibraryElementError`,t}};function load(e){let t=e.getConfig??e.default?.getConfig,n=e.configure??e.default?.configure;return typeof t==`function`&&typeof n==`function`?{getConfig:t,configure:n}:null}const z=load(o);let B=null,V=null,H=!1,U=null,W=!1;function isDefaultWrapper(e){return e===U||(U=e,W=typeof e==`function`&&/^\(?(\w+)\)?=>\1\(\)$/.test(String(e).replace(/\s/g,``))),W}function ownConfigured(){return z===null||!isDefaultWrapper(z.getConfig().asyncWrapper)}function reactActEnvironment(){return globalThis.IS_REACT_ACT_ENVIRONMENT===!0}function resolveFromProject(e){try{let t=typeof process==`object`?process.cwd():`.`,n=t;try{let e=c.resolve(`@testing-library/react`,{paths:[t]});n=e.slice(0,Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`)))}catch{}return c.resolve(e,{paths:[n]})}catch{return e}}function loadFallback(){let e=`@testing-library/dom`;return(typeof c==`function`?new Promise(t=>t(c(resolveFromProject(e)))):import(e)).then(e=>{let t=load(e);t!==null&&t.getConfig!==z?.getConfig&&(B=t)},()=>{}).finally(()=>{H=!0})}function resolveConfigSource(){if(!(H||ownConfigured()||!reactActEnvironment()))return V??=loadFallback(),V}const ae=z?z.getConfig:()=>ie;function getConfig(){return B!==null&&!ownConfigured()?B.getConfig():ae()}function wrapEvent(e,t){return getConfig().eventWrapper(e)}function focusElement(e){let t=findClosest(e,isFocusable),n=getActiveElement(e.ownerDocument);(t??e.ownerDocument.body)!==n&&(wrapEvent(t?()=>t.focus():()=>n?.blur(),e),updateSelectionOnFocus(t??e.ownerDocument.body))}function blurElement(e){isFocusable(e)&&getActiveElement(e.ownerDocument)===e&&wrapEvent(()=>e.blur(),e)}const G={};G.click=(e,t,n)=>{let r=t.closest(`button,input,label,select,textarea`),i=r&&isElementType(r,`label`)&&r.control;if(i&&i!==t)return()=>{isFocusable(i)&&(focusElement(i),n.dispatchEvent(i,cloneEvent(e)))};if(isElementType(t,`input`,{type:`file`}))return()=>{blurElement(t),t.dispatchEvent(new(getWindow(t)).Event(`fileDialog`)),focusElement(t)}};function isDateOrTime(e){return isElementType(e,`input`)&&[`date`,`time`].includes(e.type)}function input(e,t,n,r=`insertText`){let i=getInputRange(t);
|
|
25
|
+
/* istanbul ignore if */
|
|
26
|
+
i&&(isDateOrTime(t)||e.dispatchUIEvent(t,`beforeinput`,{inputType:r,data:n}))&&(`startContainer`in i?editContenteditable(e,t,i,n,r):editInputElement(e,t,i,n,r))}function editContenteditable(e,t,n,r,i){let a=!1;if(!n.collapsed)a=!0,n.deleteContents();else if([`deleteContentBackward`,`deleteContentForward`].includes(i)){let e=getNextCursorPosition(n.startContainer,n.startOffset,i===`deleteContentBackward`?-1:1,i);if(e){a=!0;let t=n.cloneRange();t.comparePoint(e.node,e.offset)<0?t.setStart(e.node,e.offset):t.setEnd(e.node,e.offset),t.deleteContents()}}if(r){if(n.endContainer.nodeType===3){let e=n.endOffset;n.endContainer.insertData(e,r),n.setStart(n.endContainer,e+r.length),n.setEnd(n.endContainer,e+r.length)}else{let e=t.ownerDocument.createTextNode(r);n.insertNode(e),n.setStart(e,r.length),n.setEnd(e,r.length)}}(a||r)&&e.dispatchUIEvent(t,`input`,{inputType:i})}function editInputElement(e,t,n,r,i){let a=r;if(supportsMaxLength(t)){let e=getMaxLength(t);if(e!==void 0&&r.length>0){let i=n.endOffset-n.startOffset,o=e-t.value.length+i;if(o>0)a=r.substring(0,o);else return}}let{newValue:o,newOffset:s,oldValue:c}=calculateNewValue(a,t,n,i);o===c&&s===n.startOffset&&s===n.endOffset||isElementType(t,`input`,{type:`number`})&&!isValidNumberInput(o)||(setUIValue(t,o),setSelection({focusNode:t,anchorOffset:s,focusOffset:s}),isDateOrTime(t)?isValidDateOrTimeValue(t,o)&&(commitInput(e,t,s,{}),e.dispatchUIEvent(t,`change`),clearInitialValue(t)):commitInput(e,t,s,{data:r,inputType:i}))}function calculateNewValue(e,t,{startOffset:n,endOffset:r},i){let a=getUIValue(t),o=Math.max(0,n===r&&i===`deleteContentBackward`?n-1:n),s=a.substring(0,o),c=Math.min(a.length,n===r&&i===`deleteContentForward`?n+1:r),l=`${s}${e}${a.substring(c,a.length)}`,u=o+e.length;if(isElementType(t,`input`,{type:`time`})){let e=buildTimeValue(l);e!==``&&isValidDateOrTimeValue(t,e)&&(l=e,u=e.length)}return{oldValue:a,newValue:l,newOffset:u}}function commitInput(e,t,n,r){e.dispatchUIEvent(t,`input`,r),commitValueAfterInput(t,n)}function isValidNumberInput(e){let t=e.split(`e`,2);return!(/[^\d.\-e]/.test(e)||Number(e.match(/-/g)?.length)>2||Number(e.match(/\./g)?.length)>1||t[1]&&!/^-?\d*$/.test(t[1]))}G.cut=(e,t,n)=>()=>{isEditable(t)&&input(n,t,``,`deleteByCut`)};function walkRadio(e,t,n){let r=getWindow(t),i=Array.from(t.ownerDocument.querySelectorAll(t.name?`input[type="radio"][name="${cssEscape(r,t.name)}"]`:`input[type="radio"][name=""], input[type="radio"]:not([name])`));for(let r=i.findIndex(e=>e===t)+n;;r+=n){if(i[r]||(r=n>0?0:i.length-1),i[r]===t)return;if(!isDisabled(i[r])){focusElement(i[r]),e.dispatchUIEvent(i[r],`click`);return}}}function cssEscape(e,t){if(typeof e.CSS?.escape==`function`)return e.CSS.escape(t);let n=``;for(let e=0;e<t.length;e++){let r=t.charCodeAt(e);r===0?n+=`�`:r>=1&&r<=31||r===127||e===0&&r>=48&&r<=57||e===1&&r>=48&&r<=57&&t.charCodeAt(0)===45?n+=`\\${r.toString(16)} `:e===0&&r===45&&t.length===1?n+=`\\-`:n+=r>=128||r===45||r===95||r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122?t[e]:`\\${t[e]}`}return n}G.keydown=(e,t,n)=>oe[e.key]?.(e,t,n)??combinationBehavior(e,t,n);const oe={ArrowDown:(e,t,n)=>{
|
|
584
27
|
/* istanbul ignore else */
|
|
585
|
-
if
|
|
586
|
-
if (typeof g.window !== "undefined") resetClipboardStubOnView(g.window);
|
|
587
|
-
});
|
|
28
|
+
if(isElementType(t,`input`,{type:`radio`}))return()=>walkRadio(n,t,1)},ArrowLeft:(e,t,n)=>isElementType(t,`input`,{type:`radio`})?()=>walkRadio(n,t,-1):()=>moveSelection(t,-1),ArrowRight:(e,t,n)=>isElementType(t,`input`,{type:`radio`})?()=>walkRadio(n,t,1):()=>moveSelection(t,1),ArrowUp:(e,t,n)=>{
|
|
588
29
|
/* istanbul ignore else */
|
|
589
|
-
if (
|
|
590
|
-
|
|
591
|
-
});
|
|
592
|
-
|
|
593
|
-
// src/utils/edit/timeValue.ts
|
|
594
|
-
const parseInt = globalThis.parseInt;
|
|
595
|
-
function buildTimeValue(value) {
|
|
596
|
-
const onlyDigitsValue = value.replace(/\D/g, "");
|
|
597
|
-
if (onlyDigitsValue.length < 2) return value;
|
|
598
|
-
const firstDigit = parseInt(onlyDigitsValue[0], 10);
|
|
599
|
-
const secondDigit = parseInt(onlyDigitsValue[1], 10);
|
|
600
|
-
if (firstDigit >= 3 || firstDigit === 2 && secondDigit >= 4) {
|
|
601
|
-
let index;
|
|
602
|
-
if (firstDigit >= 3) index = 1;
|
|
603
|
-
else index = 2;
|
|
604
|
-
return build(onlyDigitsValue, index);
|
|
605
|
-
}
|
|
606
|
-
if (value.length === 2) return value;
|
|
607
|
-
return build(onlyDigitsValue, 2);
|
|
608
|
-
}
|
|
609
|
-
function build(onlyDigitsValue, index) {
|
|
610
|
-
const hours = onlyDigitsValue.slice(0, index);
|
|
611
|
-
const validHours = Math.min(parseInt(hours, 10), 23);
|
|
612
|
-
const minuteCharacters = onlyDigitsValue.slice(index);
|
|
613
|
-
const parsedMinutes = parseInt(minuteCharacters, 10);
|
|
614
|
-
const validMinutes = Math.min(parsedMinutes, 59);
|
|
615
|
-
return `${validHours.toString().padStart(2, "0")}:${validMinutes.toString().padStart(2, "0")}`;
|
|
616
|
-
}
|
|
617
|
-
function isValidDateOrTimeValue(element, value) {
|
|
618
|
-
const clone = element.cloneNode();
|
|
619
|
-
clone.value = value;
|
|
620
|
-
return clone.value === value;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
// src/utils/edit/isContentEditable.ts
|
|
624
|
-
function isContentEditable(element) {
|
|
625
|
-
return element.hasAttribute("contenteditable") && (element.getAttribute("contenteditable") == "true" || element.getAttribute("contenteditable") == "");
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* If a node is a contenteditable or inside one, return that element.
|
|
629
|
-
*/
|
|
630
|
-
function getContentEditable(node) {
|
|
631
|
-
const element = getElement$1(node);
|
|
632
|
-
return element && (element.closest("[contenteditable=\"\"]") || element.closest("[contenteditable=\"true\"]"));
|
|
633
|
-
}
|
|
634
|
-
function getElement$1(node) {
|
|
635
|
-
return node.nodeType === 1 ? node : node.parentElement;
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
// src/utils/edit/isEditable.ts
|
|
639
|
-
function isEditable(element) {
|
|
640
|
-
return isEditableInputOrTextArea(element) && !element.readOnly || isContentEditable(element);
|
|
641
|
-
}
|
|
642
|
-
const editableInputTypes = {
|
|
643
|
-
text: "text",
|
|
644
|
-
date: "date",
|
|
645
|
-
"datetime-local": "datetime-local",
|
|
646
|
-
email: "email",
|
|
647
|
-
month: "month",
|
|
648
|
-
number: "number",
|
|
649
|
-
password: "password",
|
|
650
|
-
search: "search",
|
|
651
|
-
tel: "tel",
|
|
652
|
-
time: "time",
|
|
653
|
-
url: "url",
|
|
654
|
-
week: "week"
|
|
655
|
-
};
|
|
656
|
-
function isEditableInputOrTextArea(element) {
|
|
657
|
-
return isElementType(element, "textarea") || isElementType(element, "input") && element.type in editableInputTypes;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
// src/utils/edit/maxLength.ts
|
|
661
|
-
const maxLengthSupportedTypes = {
|
|
662
|
-
email: "email",
|
|
663
|
-
password: "password",
|
|
664
|
-
search: "search",
|
|
665
|
-
telephone: "telephone",
|
|
666
|
-
text: "text",
|
|
667
|
-
url: "url"
|
|
668
|
-
};
|
|
669
|
-
function getMaxLength(element) {
|
|
670
|
-
const attr = element.getAttribute("maxlength") ?? "";
|
|
671
|
-
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
|
|
672
|
-
}
|
|
673
|
-
function supportsMaxLength(element) {
|
|
674
|
-
return isElementType(element, "textarea") || isElementType(element, "input") && element.type in maxLengthSupportedTypes;
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
// src/utils/edit/setFiles.ts
|
|
678
|
-
const fakeFiles = Symbol("files and value properties are mocked");
|
|
679
|
-
function restoreProperty(obj, prop, descriptor) {
|
|
680
|
-
if (descriptor) Object.defineProperty(obj, prop, descriptor);
|
|
681
|
-
else delete obj[prop];
|
|
682
|
-
}
|
|
683
|
-
function setFiles(el, files) {
|
|
684
|
-
el[fakeFiles]?.restore();
|
|
685
|
-
const typeDescr = Object.getOwnPropertyDescriptor(el, "type");
|
|
686
|
-
const valueDescr = Object.getOwnPropertyDescriptor(el, "value");
|
|
687
|
-
const filesDescr = Object.getOwnPropertyDescriptor(el, "files");
|
|
688
|
-
function restore() {
|
|
689
|
-
restoreProperty(el, "type", typeDescr);
|
|
690
|
-
restoreProperty(el, "value", valueDescr);
|
|
691
|
-
restoreProperty(el, "files", filesDescr);
|
|
692
|
-
}
|
|
693
|
-
el[fakeFiles] = { restore };
|
|
694
|
-
Object.defineProperties(el, {
|
|
695
|
-
files: {
|
|
696
|
-
configurable: true,
|
|
697
|
-
get: () => files
|
|
698
|
-
},
|
|
699
|
-
value: {
|
|
700
|
-
configurable: true,
|
|
701
|
-
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
702
|
-
set(v) {
|
|
703
|
-
if (v === "") restore();
|
|
704
|
-
else valueDescr?.set?.call(el, v);
|
|
705
|
-
}
|
|
706
|
-
},
|
|
707
|
-
type: {
|
|
708
|
-
configurable: true,
|
|
709
|
-
get: () => "file",
|
|
710
|
-
set(v) {
|
|
711
|
-
if (v !== "file") {
|
|
712
|
-
restore();
|
|
713
|
-
el.type = v;
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
});
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
// src/utils/focus/cursor.ts
|
|
721
|
-
function getNextCursorPosition(node, offset, direction, inputType) {
|
|
722
|
-
if (isTextNode(node) && offset + direction >= 0 && offset + direction <= node.nodeValue.length) return {
|
|
723
|
-
node,
|
|
724
|
-
offset: offset + direction
|
|
725
|
-
};
|
|
726
|
-
const nextNode = getNextCharacterContentNode(node, offset, direction);
|
|
727
|
-
if (nextNode) {
|
|
728
|
-
if (isTextNode(nextNode)) return {
|
|
729
|
-
node: nextNode,
|
|
730
|
-
offset: direction > 0 ? Math.min(1, nextNode.nodeValue.length) : Math.max(nextNode.nodeValue.length - 1, 0)
|
|
731
|
-
};
|
|
732
|
-
else if (isElementType(nextNode, "br")) {
|
|
733
|
-
const nextPlusOne = getNextCharacterContentNode(nextNode, void 0, direction);
|
|
734
|
-
if (!nextPlusOne) {
|
|
735
|
-
if (direction < 0 && inputType === "deleteContentBackward") return {
|
|
736
|
-
node: nextNode.parentNode,
|
|
737
|
-
offset: getOffset(nextNode)
|
|
738
|
-
};
|
|
739
|
-
return;
|
|
740
|
-
} else if (isTextNode(nextPlusOne)) return {
|
|
741
|
-
node: nextPlusOne,
|
|
742
|
-
offset: direction > 0 ? 0 : nextPlusOne.nodeValue.length
|
|
743
|
-
};
|
|
744
|
-
else if (direction < 0 && isElementType(nextPlusOne, "br")) return {
|
|
745
|
-
node: nextNode.parentNode,
|
|
746
|
-
offset: getOffset(nextNode)
|
|
747
|
-
};
|
|
748
|
-
else return {
|
|
749
|
-
node: nextPlusOne.parentNode,
|
|
750
|
-
offset: getOffset(nextPlusOne) + (direction > 0 ? 0 : 1)
|
|
751
|
-
};
|
|
752
|
-
} else return {
|
|
753
|
-
node: nextNode.parentNode,
|
|
754
|
-
offset: getOffset(nextNode) + (direction > 0 ? 1 : 0)
|
|
755
|
-
};
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
function getNextCharacterContentNode(node, offset, direction) {
|
|
759
|
-
const nextOffset = Number(offset) + (direction < 0 ? -1 : 0);
|
|
760
|
-
if (offset !== void 0 && isElement$1(node) && nextOffset >= 0 && nextOffset < node.children.length) node = node.children[nextOffset];
|
|
761
|
-
return walkNodes(node, direction === 1 ? "next" : "previous", isTreatedAsCharacterContent);
|
|
762
|
-
}
|
|
763
|
-
function isTreatedAsCharacterContent(node) {
|
|
764
|
-
if (isTextNode(node)) return true;
|
|
765
|
-
if (isElement$1(node)) {
|
|
766
|
-
if (isElementType(node, ["input", "textarea"])) return node.type !== "hidden";
|
|
767
|
-
else if (isElementType(node, "br")) return true;
|
|
768
|
-
}
|
|
769
|
-
return false;
|
|
770
|
-
}
|
|
771
|
-
function getOffset(node) {
|
|
772
|
-
let i = 0;
|
|
773
|
-
while (node.previousSibling) {
|
|
774
|
-
i++;
|
|
775
|
-
node = node.previousSibling;
|
|
776
|
-
}
|
|
777
|
-
return i;
|
|
778
|
-
}
|
|
779
|
-
function isElement$1(node) {
|
|
780
|
-
return node.nodeType === 1;
|
|
781
|
-
}
|
|
782
|
-
function isTextNode(node) {
|
|
783
|
-
return node.nodeType === 3;
|
|
784
|
-
}
|
|
785
|
-
function walkNodes(node, direction, callback) {
|
|
786
|
-
for (;;) {
|
|
787
|
-
const sibling = node[`${direction}Sibling`];
|
|
788
|
-
if (sibling) {
|
|
789
|
-
node = getDescendant(sibling, direction === "next" ? "first" : "last");
|
|
790
|
-
if (callback(node)) return node;
|
|
791
|
-
} else if (node.parentNode && (!isElement$1(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== node.ownerDocument?.body)) node = node.parentNode;
|
|
792
|
-
else break;
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
function getDescendant(node, direction) {
|
|
796
|
-
while (node.hasChildNodes()) node = node[`${direction}Child`];
|
|
797
|
-
return node;
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
// src/utils/misc/isDisabled.ts
|
|
801
|
-
const DISABLEABLE = [
|
|
802
|
-
"button",
|
|
803
|
-
"input",
|
|
804
|
-
"select",
|
|
805
|
-
"textarea",
|
|
806
|
-
"optgroup",
|
|
807
|
-
"option"
|
|
808
|
-
];
|
|
809
|
-
function isDisabled(element) {
|
|
810
|
-
for (let el = element; el; el = el.parentElement) if (isElementType(el, DISABLEABLE)) {
|
|
811
|
-
if (el.hasAttribute("disabled")) return true;
|
|
812
|
-
} else if (isElementType(el, "fieldset")) {
|
|
813
|
-
if (el.hasAttribute("disabled") && !el.querySelector(":scope > legend")?.contains(element)) return true;
|
|
814
|
-
} else if (el.tagName.includes("-")) {
|
|
815
|
-
if (el.constructor.formAssociated && el.hasAttribute("disabled")) return true;
|
|
816
|
-
}
|
|
817
|
-
return false;
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
// src/utils/focus/getActiveElement.ts
|
|
821
|
-
function getActiveElement(document) {
|
|
822
|
-
const activeElement = document.activeElement;
|
|
823
|
-
if (activeElement?.shadowRoot) {
|
|
824
|
-
const activeElementInShadowTree = getActiveElement(activeElement.shadowRoot);
|
|
825
|
-
if (activeElementInShadowTree) return activeElementInShadowTree;
|
|
826
|
-
} else if (activeElement && isElementType(activeElement, "iframe")) {
|
|
827
|
-
const contentDocument = activeElement.contentDocument;
|
|
828
|
-
if (contentDocument) return getActiveElement(contentDocument);
|
|
829
|
-
}
|
|
830
|
-
if (isDisabled(activeElement)) return document.ownerDocument ?
|
|
831
|
-
/* istanbul ignore next */ document.ownerDocument.body : document.body;
|
|
832
|
-
return activeElement;
|
|
833
|
-
}
|
|
834
|
-
function getActiveElementOrBody(document) {
|
|
835
|
-
return getActiveElement(document) ?? /* istanbul ignore next */ document.body;
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
// src/utils/misc/isVisible.ts
|
|
839
|
-
function isVisible(element) {
|
|
840
|
-
const window = getWindow(element);
|
|
841
|
-
for (let el = element; el?.ownerDocument; el = el.parentElement) {
|
|
842
|
-
const { display, visibility } = window.getComputedStyle(el);
|
|
843
|
-
if (display === "none") return false;
|
|
844
|
-
if (visibility === "hidden") return false;
|
|
845
|
-
}
|
|
846
|
-
return true;
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
// src/utils/focus/selector.ts
|
|
850
|
-
const FOCUSABLE_SELECTOR = [
|
|
851
|
-
"input:not([type=hidden]):not([disabled])",
|
|
852
|
-
"button:not([disabled])",
|
|
853
|
-
"select:not([disabled])",
|
|
854
|
-
"textarea:not([disabled])",
|
|
855
|
-
"[contenteditable=\"\"]",
|
|
856
|
-
"[contenteditable=\"true\"]",
|
|
857
|
-
"a[href]",
|
|
858
|
-
"[tabindex]:not([disabled])",
|
|
859
|
-
"details > summary"
|
|
860
|
-
].join(", ");
|
|
861
|
-
|
|
862
|
-
// src/utils/focus/getTabDestination.ts
|
|
863
|
-
function getTabDestination(activeElement, shift) {
|
|
864
|
-
const document = activeElement.ownerDocument;
|
|
865
|
-
const focusableElements = document.querySelectorAll(FOCUSABLE_SELECTOR);
|
|
866
|
-
const enabledElements = Array.from(focusableElements).filter((el) => el === activeElement || !(Number(el.getAttribute("tabindex")) < 0 || isDisabled(el)));
|
|
867
|
-
if (Number(activeElement.getAttribute("tabindex")) >= 0) enabledElements.sort((a, b) => {
|
|
868
|
-
const i = Number(a.getAttribute("tabindex"));
|
|
869
|
-
const j = Number(b.getAttribute("tabindex"));
|
|
870
|
-
if (i === j) return 0;
|
|
871
|
-
else if (i === 0) return 1;
|
|
872
|
-
else if (j === 0) return -1;
|
|
873
|
-
return i - j;
|
|
874
|
-
});
|
|
875
|
-
const checkedRadio = {};
|
|
876
|
-
let prunedElements = [document.body];
|
|
877
|
-
const activeRadioGroup = isElementType(activeElement, "input", { type: "radio" }) ? activeElement.name : void 0;
|
|
878
|
-
enabledElements.forEach((currentElement) => {
|
|
879
|
-
const el = currentElement;
|
|
880
|
-
if (isElementType(el, "input", { type: "radio" }) && el.name) {
|
|
881
|
-
if (el === activeElement) {
|
|
882
|
-
prunedElements.push(el);
|
|
883
|
-
return;
|
|
884
|
-
} else if (el.name === activeRadioGroup) return;
|
|
885
|
-
if (el.checked) {
|
|
886
|
-
prunedElements = prunedElements.filter((e) => !isElementType(e, "input", {
|
|
887
|
-
type: "radio",
|
|
888
|
-
name: el.name
|
|
889
|
-
}));
|
|
890
|
-
prunedElements.push(el);
|
|
891
|
-
checkedRadio[el.name] = el;
|
|
892
|
-
return;
|
|
893
|
-
}
|
|
894
|
-
if (typeof checkedRadio[el.name] !== "undefined") return;
|
|
895
|
-
}
|
|
896
|
-
prunedElements.push(el);
|
|
897
|
-
});
|
|
898
|
-
for (let index = prunedElements.findIndex((el) => el === activeElement);;) {
|
|
899
|
-
index += shift ? -1 : 1;
|
|
900
|
-
if (index === prunedElements.length) index = 0;
|
|
901
|
-
else if (index === -1) index = prunedElements.length - 1;
|
|
902
|
-
if (prunedElements[index] === activeElement || prunedElements[index] === document.body || isVisible(prunedElements[index])) return prunedElements[index];
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
// src/utils/focus/isFocusable.ts
|
|
907
|
-
function isFocusable(element) {
|
|
908
|
-
return element.matches(FOCUSABLE_SELECTOR);
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
// src/utils/focus/selection.ts
|
|
912
|
-
/**
|
|
913
|
-
* Determine if the element has its own selection implementation
|
|
914
|
-
* and does not interact with the Document Selection API.
|
|
915
|
-
*/
|
|
916
|
-
function hasOwnSelection(node) {
|
|
917
|
-
return isElement(node) && isEditableInputOrTextArea(node);
|
|
918
|
-
}
|
|
919
|
-
function hasNoSelection(node) {
|
|
920
|
-
return isElement(node) && isClickableInput(node);
|
|
921
|
-
}
|
|
922
|
-
function isElement(node) {
|
|
923
|
-
return node.nodeType === 1;
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
// src/utils/keyDef/readNextDescriptor.ts
|
|
927
|
-
const bracketDict = {
|
|
928
|
-
"{": "}",
|
|
929
|
-
"[": "]"
|
|
930
|
-
};
|
|
931
|
-
/**
|
|
932
|
-
* Read the next key definition from user input
|
|
933
|
-
*
|
|
934
|
-
* Describe key per `{descriptor}` or `[descriptor]`.
|
|
935
|
-
* Everything else will be interpreted as a single character as descriptor - e.g. `a`.
|
|
936
|
-
* Brackets `{` and `[` can be escaped by doubling - e.g. `foo[[bar` translates to `foo[bar`.
|
|
937
|
-
* A previously pressed key can be released per `{/descriptor}`.
|
|
938
|
-
* Keeping the key pressed can be written as `{descriptor>}`.
|
|
939
|
-
* When keeping the key pressed you can choose how long the key is pressed `{descriptor>3}`.
|
|
940
|
-
* You can then release the key per `{descriptor>3/}` or keep it pressed and continue with the next key.
|
|
941
|
-
*/
|
|
942
|
-
function readNextDescriptor(text, context) {
|
|
943
|
-
let pos = 0;
|
|
944
|
-
const startBracket = text[pos] in bracketDict ? text[pos] : "";
|
|
945
|
-
pos += startBracket.length;
|
|
946
|
-
const type = new RegExp(`^\\${startBracket}{2}`).test(text) ? "" : startBracket;
|
|
947
|
-
return {
|
|
948
|
-
type,
|
|
949
|
-
...type === "" ? readPrintableChar(text, pos, context) : readTag(text, pos, type, context)
|
|
950
|
-
};
|
|
951
|
-
}
|
|
952
|
-
function readPrintableChar(text, pos, context) {
|
|
953
|
-
const descriptor = text[pos];
|
|
954
|
-
assertDescriptor(descriptor, text, pos, context);
|
|
955
|
-
pos += descriptor.length;
|
|
956
|
-
return {
|
|
957
|
-
consumedLength: pos,
|
|
958
|
-
descriptor,
|
|
959
|
-
releasePrevious: false,
|
|
960
|
-
releaseSelf: true,
|
|
961
|
-
repeat: 1
|
|
962
|
-
};
|
|
963
|
-
}
|
|
964
|
-
function readTag(text, pos, startBracket, context) {
|
|
965
|
-
const releasePreviousModifier = text[pos] === "/" ? "/" : "";
|
|
966
|
-
pos += releasePreviousModifier.length;
|
|
967
|
-
const escapedDescriptor = startBracket === "{" && text[pos] === "\\";
|
|
968
|
-
pos += Number(escapedDescriptor);
|
|
969
|
-
const descriptor = escapedDescriptor ? text[pos] : text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)?.[0];
|
|
970
|
-
assertDescriptor(descriptor, text, pos, context);
|
|
971
|
-
pos += descriptor.length;
|
|
972
|
-
const repeatModifier = text.slice(pos).match(/^>\d+/)?.[0] ?? "";
|
|
973
|
-
pos += repeatModifier.length;
|
|
974
|
-
const releaseSelfModifier = text[pos] === "/" || !repeatModifier && text[pos] === ">" ? text[pos] : "";
|
|
975
|
-
pos += releaseSelfModifier.length;
|
|
976
|
-
const expectedEndBracket = bracketDict[startBracket];
|
|
977
|
-
const endBracket = text[pos] === expectedEndBracket ? expectedEndBracket : "";
|
|
978
|
-
if (!endBracket) throw new Error(getErrorMessage([
|
|
979
|
-
!repeatModifier && "repeat modifier",
|
|
980
|
-
!releaseSelfModifier && "release modifier",
|
|
981
|
-
`"${expectedEndBracket}"`
|
|
982
|
-
].filter(Boolean).join(" or "), text[pos], text, context));
|
|
983
|
-
pos += endBracket.length;
|
|
984
|
-
return {
|
|
985
|
-
consumedLength: pos,
|
|
986
|
-
descriptor,
|
|
987
|
-
releasePrevious: !!releasePreviousModifier,
|
|
988
|
-
repeat: repeatModifier ? Math.max(Number(repeatModifier.substr(1)), 1) : 1,
|
|
989
|
-
releaseSelf: hasReleaseSelf(releaseSelfModifier, repeatModifier)
|
|
990
|
-
};
|
|
991
|
-
}
|
|
992
|
-
function assertDescriptor(descriptor, text, pos, context) {
|
|
993
|
-
if (!descriptor) throw new Error(getErrorMessage("key descriptor", text[pos], text, context));
|
|
994
|
-
}
|
|
995
|
-
function hasReleaseSelf(releaseSelfModifier, repeatModifier) {
|
|
996
|
-
if (releaseSelfModifier) return releaseSelfModifier === "/";
|
|
997
|
-
if (repeatModifier) return false;
|
|
998
|
-
}
|
|
999
|
-
function getErrorMessage(expected, found, text, context) {
|
|
1000
|
-
return `Expected ${expected} but found "${found ?? ""}" in "${text}"
|
|
1001
|
-
See ${context === "pointer" ? `https://testing-library.com/docs/user-event/pointer#pressing-a-button-or-touching-the-screen` : `https://testing-library.com/docs/user-event/keyboard`}
|
|
1002
|
-
for more information about how userEvent parses your input.`;
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
// src/utils/misc/cloneEvent.ts
|
|
1006
|
-
function cloneEvent(event) {
|
|
1007
|
-
return new event.constructor(event.type, event);
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
// src/utils/misc/findClosest.ts
|
|
1011
|
-
function findClosest(element, callback) {
|
|
1012
|
-
let el = element;
|
|
1013
|
-
do {
|
|
1014
|
-
if (callback(el)) return el;
|
|
1015
|
-
el = el.parentElement;
|
|
1016
|
-
} while (el && el !== element.ownerDocument.body);
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
// src/utils/misc/getDocumentFromNode.ts
|
|
1020
|
-
function getDocumentFromNode(el) {
|
|
1021
|
-
return isDocument(el) ? el : el.ownerDocument;
|
|
1022
|
-
}
|
|
1023
|
-
function isDocument(node) {
|
|
1024
|
-
return node.nodeType === 9;
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
// src/utils/misc/getTreeDiff.ts
|
|
1028
|
-
function getTreeDiff(a, b) {
|
|
1029
|
-
const treeA = [];
|
|
1030
|
-
for (let el = a; el; el = el.parentElement) treeA.push(el);
|
|
1031
|
-
const treeB = [];
|
|
1032
|
-
for (let el = b; el; el = el.parentElement) treeB.push(el);
|
|
1033
|
-
let i = 0;
|
|
1034
|
-
for (;; i++) if (i >= treeA.length || i >= treeB.length || treeA[treeA.length - 1 - i] !== treeB[treeB.length - 1 - i]) break;
|
|
1035
|
-
return [
|
|
1036
|
-
treeA.slice(0, treeA.length - i),
|
|
1037
|
-
treeB.slice(0, treeB.length - i),
|
|
1038
|
-
treeB.slice(treeB.length - i)
|
|
1039
|
-
];
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
// src/utils/misc/level.ts
|
|
1043
|
-
const ApiLevel = {
|
|
1044
|
-
Trigger: 2,
|
|
1045
|
-
Call: 1
|
|
1046
|
-
};
|
|
1047
|
-
function setLevelRef(instance, level) {
|
|
1048
|
-
instance.levelRefs[level] = {};
|
|
1049
|
-
}
|
|
1050
|
-
function getLevelRef(instance, level) {
|
|
1051
|
-
return instance.levelRefs[level];
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
// src/ctrl-dom.ts
|
|
1055
|
-
const internal = ctrlDomInternal;
|
|
1056
|
-
function pick(names) {
|
|
1057
|
-
if (internal === null) return null;
|
|
1058
|
-
const out = {};
|
|
1059
|
-
for (const name of names) {
|
|
1060
|
-
const fn = internal[name];
|
|
1061
|
-
if (typeof fn !== "function") return null;
|
|
1062
|
-
out[name] = fn;
|
|
1063
|
-
}
|
|
1064
|
-
return out;
|
|
1065
|
-
}
|
|
1066
|
-
/** @ctrl/dom UI value/selection hooks, or null while html-forms does not provide them. */
|
|
1067
|
-
const ctrlDomUI = pick([
|
|
1068
|
-
"getUIValue",
|
|
1069
|
-
"setUIValue",
|
|
1070
|
-
"clearUIValue",
|
|
1071
|
-
"getUISelection",
|
|
1072
|
-
"setUISelection"
|
|
1073
|
-
]);
|
|
1074
|
-
/** @ctrl/dom computed-style fast reads, or null while css does not provide them. */
|
|
1075
|
-
const ctrlDomCss = pick([
|
|
1076
|
-
"computedValue",
|
|
1077
|
-
"isDisplayNone",
|
|
1078
|
-
"isVisibilityHidden"
|
|
1079
|
-
]);
|
|
1080
|
-
const skipIdle = internal?.skipIdleTime;
|
|
1081
|
-
/**
|
|
1082
|
-
* Let `ms` of idle time pass on @ctrl/dom's idle-skipping clock (src/window/clock.ts), as a real
|
|
1083
|
-
* wait would there; false when a timer falls due in that time. True without such a clock.
|
|
1084
|
-
*/
|
|
1085
|
-
function skipIdleTime(ms) {
|
|
1086
|
-
return skipIdle === void 0 || skipIdle(ms);
|
|
1087
|
-
}
|
|
1088
|
-
const foreignImmediates = internal?.foreignImmediatesPending;
|
|
1089
|
-
/**
|
|
1090
|
-
* Whether immediates other than @ctrl/dom's clock's own are queued (src/window/clock.ts); on
|
|
1091
|
-
* another DOM, any queued immediate. False when Node cannot tell.
|
|
1092
|
-
*/
|
|
1093
|
-
function immediatesPending() {
|
|
1094
|
-
if (foreignImmediates !== void 0) return foreignImmediates() === true;
|
|
1095
|
-
if (typeof process !== "object" || typeof process.getActiveResourcesInfo !== "function") return false;
|
|
1096
|
-
return process.getActiveResourcesInfo().includes("Immediate");
|
|
1097
|
-
}
|
|
1098
|
-
const NodeImplClass = internal?.NodeImpl ?? null;
|
|
1099
|
-
/** The NodeImpl behind an @ctrl/dom wrapper, or null for nodes of other DOM implementations. */
|
|
1100
|
-
function implOf(node) {
|
|
1101
|
-
if (NodeImplClass === null || node == null) return null;
|
|
1102
|
-
const impl = node[$impl];
|
|
1103
|
-
return impl instanceof NodeImplClass ? impl : null;
|
|
1104
|
-
}
|
|
1105
|
-
/** Whether `el` is an @ctrl/dom element and the html-forms UI hooks are available. */
|
|
1106
|
-
function hasCtrlDomUI(el) {
|
|
1107
|
-
return ctrlDomUI !== null && implOf(el) !== null;
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
// src/utils/misc/wait.ts
|
|
1111
|
-
/** Same detection as @testing-library/dom's `jestFakeTimersAreEnabled`; also matches sinon/vitest (`clock`) and spies. */
|
|
1112
|
-
function isFaked(fn) {
|
|
1113
|
-
return fn !== void 0 && (fn._isMockFunction === true || Object.hasOwn(fn, "clock"));
|
|
1114
|
-
}
|
|
1115
|
-
function defaultAdvanceTimers() {
|
|
1116
|
-
return Promise.resolve();
|
|
1117
|
-
}
|
|
1118
|
-
function wait(config) {
|
|
1119
|
-
const delay = config.delay;
|
|
1120
|
-
if (typeof delay !== "number") return;
|
|
1121
|
-
return Promise.all([new Promise((resolve) => globalThis.setTimeout(() => resolve(), delay)), config.advanceTimers(delay)]);
|
|
1122
|
-
}
|
|
1123
|
-
function resolveOnImmediate(resolve) {
|
|
1124
|
-
globalThis.setImmediate(resolve);
|
|
1125
|
-
}
|
|
1126
|
-
const getActiveResourcesInfo = typeof process === "object" && typeof process.getActiveResourcesInfo === "function" ? process.getActiveResourcesInfo.bind(process) : null;
|
|
1127
|
-
/** Active (ref'ed) timeouts and intervals in this process, or -1 when unknown (not Node). */
|
|
1128
|
-
function countTimeouts() {
|
|
1129
|
-
if (getActiveResourcesInfo === null) return -1;
|
|
1130
|
-
const resources = getActiveResourcesInfo();
|
|
1131
|
-
let n = 0;
|
|
1132
|
-
for (let i = 0; i < resources.length; i++) if (resources[i] === "Timeout") n++;
|
|
1133
|
-
return n;
|
|
1134
|
-
}
|
|
1135
|
-
/** Timers due within this many ms of now count as "would run during upstream's wait". */
|
|
1136
|
-
const DUE_SOON_MS = 4;
|
|
1137
|
-
/** A tracked timer this overdue has been cleared by a means we do not observe (e.g. numeric id). */
|
|
1138
|
-
const STALE_MS = 50;
|
|
1139
|
-
const pendingTimers = /* @__PURE__ */ new Set();
|
|
1140
|
-
const timerByHandle = /* @__PURE__ */ new Map();
|
|
1141
|
-
const wrappers = {};
|
|
1142
|
-
function copyProps(wrapper, original) {
|
|
1143
|
-
Object.defineProperties(wrapper, Object.getOwnPropertyDescriptors(original));
|
|
1144
|
-
}
|
|
1145
|
-
function wrapSchedule(name) {
|
|
1146
|
-
const g = globalThis;
|
|
1147
|
-
const current = g[name];
|
|
1148
|
-
if (current === wrappers[name] || typeof current !== "function" || isFaked(current)) return;
|
|
1149
|
-
const original = current;
|
|
1150
|
-
const isInterval = name === "setInterval";
|
|
1151
|
-
const wrapper = function(callback, delay, ...args) {
|
|
1152
|
-
if (typeof callback !== "function") return original.call(this, callback, delay, ...args);
|
|
1153
|
-
const ms = Math.max(1, Number(delay) || 0);
|
|
1154
|
-
const timer = {
|
|
1155
|
-
due: performance.now() + ms,
|
|
1156
|
-
interval: isInterval ? ms : 0,
|
|
1157
|
-
handle: void 0
|
|
1158
|
-
};
|
|
1159
|
-
pendingTimers.add(timer);
|
|
1160
|
-
let handle;
|
|
1161
|
-
const run = function(...runArgs) {
|
|
1162
|
-
if (isInterval) timer.due = performance.now() + timer.interval;
|
|
1163
|
-
else {
|
|
1164
|
-
pendingTimers.delete(timer);
|
|
1165
|
-
timerByHandle.delete(handle);
|
|
1166
|
-
}
|
|
1167
|
-
return callback.apply(this, runArgs);
|
|
1168
|
-
};
|
|
1169
|
-
handle = original.call(this, run, delay, ...args);
|
|
1170
|
-
timer.handle = handle;
|
|
1171
|
-
timerByHandle.set(handle, timer);
|
|
1172
|
-
return handle;
|
|
1173
|
-
};
|
|
1174
|
-
copyProps(wrapper, original);
|
|
1175
|
-
wrappers[name] = wrapper;
|
|
1176
|
-
g[name] = wrapper;
|
|
1177
|
-
}
|
|
1178
|
-
function wrapClear(name) {
|
|
1179
|
-
const g = globalThis;
|
|
1180
|
-
const current = g[name];
|
|
1181
|
-
if (current === wrappers[name] || typeof current !== "function" || isFaked(current)) return;
|
|
1182
|
-
const original = current;
|
|
1183
|
-
const wrapper = function(handle) {
|
|
1184
|
-
const timer = timerByHandle.get(handle);
|
|
1185
|
-
if (timer !== void 0) {
|
|
1186
|
-
pendingTimers.delete(timer);
|
|
1187
|
-
timerByHandle.delete(handle);
|
|
1188
|
-
}
|
|
1189
|
-
return original.call(this, handle);
|
|
1190
|
-
};
|
|
1191
|
-
copyProps(wrapper, original);
|
|
1192
|
-
wrappers[name] = wrapper;
|
|
1193
|
-
g[name] = wrapper;
|
|
1194
|
-
}
|
|
1195
|
-
function observeTimerGlobals() {
|
|
1196
|
-
wrapSchedule("setTimeout");
|
|
1197
|
-
wrapSchedule("setInterval");
|
|
1198
|
-
wrapClear("clearTimeout");
|
|
1199
|
-
wrapClear("clearInterval");
|
|
1200
|
-
}
|
|
1201
|
-
function timerGlobalsObserved() {
|
|
1202
|
-
const g = globalThis;
|
|
1203
|
-
return wrappers.setTimeout !== void 0 && g.setTimeout === wrappers.setTimeout && g.setInterval === wrappers.setInterval && g.clearTimeout === wrappers.clearTimeout && g.clearInterval === wrappers.clearInterval;
|
|
1204
|
-
}
|
|
1205
|
-
/** Whether a timer created through the wrappers may be due within upstream's wait. */
|
|
1206
|
-
function trackedTimerDueSoon() {
|
|
1207
|
-
const now = performance.now();
|
|
1208
|
-
for (const timer of pendingTimers) if (timer.due <= now + DUE_SOON_MS) {
|
|
1209
|
-
if (timer.interval === 0 && timer.due < now - STALE_MS) {
|
|
1210
|
-
pendingTimers.delete(timer);
|
|
1211
|
-
timerByHandle.delete(timer.handle);
|
|
1212
|
-
continue;
|
|
1213
|
-
}
|
|
1214
|
-
return true;
|
|
1215
|
-
}
|
|
1216
|
-
return false;
|
|
1217
|
-
}
|
|
1218
|
-
/**
|
|
1219
|
-
* Live timeouts not created through the wrappers (created before user-event was imported, or
|
|
1220
|
-
* through a reference captured earlier) as of the last full wait. Their deadlines are unknown;
|
|
1221
|
-
* any short one was flushed by that wait, so only an increase is suspicious.
|
|
1222
|
-
*/
|
|
1223
|
-
let untrackedBaseline = -1;
|
|
1224
|
-
function untrackedTimeouts() {
|
|
1225
|
-
const live = countTimeouts();
|
|
1226
|
-
if (live === -1) return -1;
|
|
1227
|
-
let trackedRefed = 0;
|
|
1228
|
-
for (const handle of timerByHandle.keys()) if (typeof handle !== "object" || handle === null || handle.hasRef?.() !== false) trackedRefed++;
|
|
1229
|
-
return live - trackedRefed;
|
|
1230
|
-
}
|
|
1231
|
-
if (typeof globalThis.setImmediate === "function") observeTimerGlobals();
|
|
1232
|
-
/** Start of an API call: re-install the observers if something replaced the timer globals. */
|
|
1233
|
-
function markTimers(config) {
|
|
1234
|
-
if (config.delay === 0 && config.advanceTimers === defaultAdvanceTimers) observeTimerGlobals();
|
|
1235
|
-
}
|
|
1236
|
-
/** `delay: 0`, the default `advanceTimers`, and real timers: nothing replaced or faked. */
|
|
1237
|
-
function realTimersAtZeroDelay(config) {
|
|
1238
|
-
if (config.delay !== 0 || config.advanceTimers !== defaultAdvanceTimers) return false;
|
|
1239
|
-
const setImmediate = globalThis.setImmediate;
|
|
1240
|
-
return typeof setImmediate === "function" && !isFaked(setImmediate) && timerGlobalsObserved();
|
|
1241
|
-
}
|
|
1242
|
-
function canYieldWithImmediate(config) {
|
|
1243
|
-
if (!realTimersAtZeroDelay(config)) return false;
|
|
1244
|
-
if (trackedTimerDueSoon()) return false;
|
|
1245
|
-
const untracked = untrackedTimeouts();
|
|
1246
|
-
if (untracked === -1 || untrackedBaseline === -1 || untracked > untrackedBaseline) return false;
|
|
1247
|
-
if (!skipIdleTime(1)) return false;
|
|
1248
|
-
untrackedBaseline = untracked;
|
|
1249
|
-
return true;
|
|
1250
|
-
}
|
|
1251
|
-
/** Bound on repeated yields while other immediates are queued (a self-rescheduling immediate never settles). */
|
|
1252
|
-
const MAX_YIELD_HOPS = 20;
|
|
1253
|
-
async function yieldBetweenActions(config) {
|
|
1254
|
-
if (canYieldWithImmediate(config)) await new Promise(resolveOnImmediate);
|
|
1255
|
-
else {
|
|
1256
|
-
await wait(config);
|
|
1257
|
-
if (timerGlobalsObserved()) untrackedBaseline = untrackedTimeouts();
|
|
1258
|
-
}
|
|
1259
|
-
if (realTimersAtZeroDelay(config)) for (let hop = 0; hop < MAX_YIELD_HOPS && immediatesPending(); hop++) await new Promise(resolveOnImmediate);
|
|
1260
|
-
}
|
|
1261
|
-
|
|
1262
|
-
// src/system/pointer/shared.ts
|
|
1263
|
-
function isDifferentPointerPosition(positionA, positionB) {
|
|
1264
|
-
return positionA.target !== positionB.target || positionA.coords?.x !== positionB.coords?.x || positionA.coords?.y !== positionB.coords?.y || positionA.coords?.clientX !== positionB.coords?.clientX || positionA.coords?.clientY !== positionB.coords?.clientY || positionA.coords?.offsetX !== positionB.coords?.offsetX || positionA.coords?.offsetY !== positionB.coords?.offsetY || positionA.coords?.pageX !== positionB.coords?.pageX || positionA.coords?.pageY !== positionB.coords?.pageY || positionA.coords?.screenX !== positionB.coords?.screenX || positionA.coords?.screenY !== positionB.coords?.screenY || positionA.caret?.node !== positionB.caret?.node || positionA.caret?.offset !== positionB.caret?.offset;
|
|
1265
|
-
}
|
|
1266
|
-
|
|
1267
|
-
// src/system/pointer/buttons.ts
|
|
1268
|
-
var Buttons = class {
|
|
1269
|
-
pressed = {};
|
|
1270
|
-
/** `MouseEvent.buttons` of `pressed`, kept up to date instead of recomputed per event. */
|
|
1271
|
-
mask = 0;
|
|
1272
|
-
getButtons() {
|
|
1273
|
-
return this.mask;
|
|
1274
|
-
}
|
|
1275
|
-
down(keyDef) {
|
|
1276
|
-
const button = getMouseButtonId(keyDef.button);
|
|
1277
|
-
if (button in this.pressed) {
|
|
1278
|
-
this.pressed[button].push(keyDef);
|
|
1279
|
-
return;
|
|
1280
|
-
}
|
|
1281
|
-
this.pressed[button] = [keyDef];
|
|
1282
|
-
this.mask |= 2 ** button;
|
|
1283
|
-
return button;
|
|
1284
|
-
}
|
|
1285
|
-
up(keyDef) {
|
|
1286
|
-
const button = getMouseButtonId(keyDef.button);
|
|
1287
|
-
if (button in this.pressed) {
|
|
1288
|
-
this.pressed[button] = this.pressed[button].filter((k) => k.name !== keyDef.name);
|
|
1289
|
-
if (this.pressed[button].length === 0) {
|
|
1290
|
-
delete this.pressed[button];
|
|
1291
|
-
this.mask &= ~(2 ** button);
|
|
1292
|
-
return button;
|
|
1293
|
-
}
|
|
1294
|
-
}
|
|
1295
|
-
}
|
|
1296
|
-
};
|
|
1297
|
-
const MouseButton = {
|
|
1298
|
-
primary: 0,
|
|
1299
|
-
secondary: 1,
|
|
1300
|
-
auxiliary: 2,
|
|
1301
|
-
back: 3,
|
|
1302
|
-
X1: 3,
|
|
1303
|
-
forward: 4,
|
|
1304
|
-
X2: 4
|
|
1305
|
-
};
|
|
1306
|
-
function getMouseButtonId(button = 0) {
|
|
1307
|
-
if (button in MouseButton) return MouseButton[button];
|
|
1308
|
-
return Number(button);
|
|
1309
|
-
}
|
|
1310
|
-
const MouseButtonFlip = {
|
|
1311
|
-
1: 2,
|
|
1312
|
-
2: 1
|
|
1313
|
-
};
|
|
1314
|
-
function getMouseEventButton(button) {
|
|
1315
|
-
button = getMouseButtonId(button);
|
|
1316
|
-
if (button in MouseButtonFlip) return MouseButtonFlip[button];
|
|
1317
|
-
return button;
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
// src/system/pointer/device.ts
|
|
1321
|
-
var Device = class {
|
|
1322
|
-
pressedKeys = /* @__PURE__ */ new Set();
|
|
1323
|
-
get countPressed() {
|
|
1324
|
-
return this.pressedKeys.size;
|
|
1325
|
-
}
|
|
1326
|
-
isPressed(keyDef) {
|
|
1327
|
-
return this.pressedKeys.has(keyDef.name);
|
|
1328
|
-
}
|
|
1329
|
-
addPressed(keyDef) {
|
|
1330
|
-
return this.pressedKeys.add(keyDef.name);
|
|
1331
|
-
}
|
|
1332
|
-
removePressed(keyDef) {
|
|
1333
|
-
return this.pressedKeys.delete(keyDef.name);
|
|
1334
|
-
}
|
|
1335
|
-
};
|
|
1336
|
-
|
|
1337
|
-
// src/system/pointer/mouse.ts
|
|
1338
|
-
/**
|
|
1339
|
-
* This object is the single "virtual" mouse that might be controlled by multiple different pointer devices.
|
|
1340
|
-
*/
|
|
1341
|
-
var Mouse = class {
|
|
1342
|
-
position = {};
|
|
1343
|
-
buttons = new Buttons();
|
|
1344
|
-
selecting;
|
|
1345
|
-
buttonDownTarget = {};
|
|
1346
|
-
clickCount = new class {
|
|
1347
|
-
down = {};
|
|
1348
|
-
count = {};
|
|
1349
|
-
incOnClick(button) {
|
|
1350
|
-
const current = this.down[button] === void 0 ? void 0 : Number(this.down[button]) + 1;
|
|
1351
|
-
this.count = this.count[button] === void 0 ? {} : { [button]: Number(this.count[button]) + 1 };
|
|
1352
|
-
return current;
|
|
1353
|
-
}
|
|
1354
|
-
getOnDown(button) {
|
|
1355
|
-
this.down = { [button]: this.count[button] ?? 0 };
|
|
1356
|
-
this.count = { [button]: this.count[button] ?? 0 };
|
|
1357
|
-
return Number(this.count[button]) + 1;
|
|
1358
|
-
}
|
|
1359
|
-
getOnUp(button) {
|
|
1360
|
-
return this.down[button] === void 0 ? void 0 : Number(this.down[button]) + 1;
|
|
1361
|
-
}
|
|
1362
|
-
reset() {
|
|
1363
|
-
this.count = {};
|
|
1364
|
-
}
|
|
1365
|
-
}();
|
|
1366
|
-
move(instance, position, isPrevented) {
|
|
1367
|
-
const prevPosition = this.position;
|
|
1368
|
-
const prevTarget = this.getTarget(instance);
|
|
1369
|
-
this.position = position;
|
|
1370
|
-
if (!isDifferentPointerPosition(prevPosition, position)) return;
|
|
1371
|
-
const nextTarget = this.getTarget(instance);
|
|
1372
|
-
const init = this.getEventInit("mousemove");
|
|
1373
|
-
const [leave, enter] = getTreeDiff(prevTarget, nextTarget);
|
|
1374
|
-
return {
|
|
1375
|
-
leave: () => {
|
|
1376
|
-
if (prevTarget !== nextTarget) {
|
|
1377
|
-
instance.dispatchUIEvent(prevTarget, "mouseout", init);
|
|
1378
|
-
leave.forEach((el) => instance.dispatchUIEvent(el, "mouseleave", init));
|
|
1379
|
-
}
|
|
1380
|
-
},
|
|
1381
|
-
enter: () => {
|
|
1382
|
-
if (prevTarget !== nextTarget) {
|
|
1383
|
-
instance.dispatchUIEvent(nextTarget, "mouseover", init);
|
|
1384
|
-
enter.forEach((el) => instance.dispatchUIEvent(el, "mouseenter", init));
|
|
1385
|
-
}
|
|
1386
|
-
},
|
|
1387
|
-
move: () => {
|
|
1388
|
-
if (isPrevented) return;
|
|
1389
|
-
instance.dispatchUIEvent(nextTarget, "mousemove", init);
|
|
1390
|
-
this.modifySelecting(instance);
|
|
1391
|
-
}
|
|
1392
|
-
};
|
|
1393
|
-
}
|
|
1394
|
-
down(instance, keyDef, isPrevented) {
|
|
1395
|
-
const button = this.buttons.down(keyDef);
|
|
1396
|
-
if (button === void 0) return;
|
|
1397
|
-
const target = this.getTarget(instance);
|
|
1398
|
-
this.buttonDownTarget[button] = target;
|
|
1399
|
-
const init = this.getEventInit("mousedown", keyDef.button);
|
|
1400
|
-
const disabled = isDisabled(target);
|
|
1401
|
-
if (!isPrevented && (disabled || instance.dispatchUIEvent(target, "mousedown", init))) {
|
|
1402
|
-
this.startSelecting(instance, init.detail);
|
|
1403
|
-
focusElement(target);
|
|
1404
|
-
}
|
|
1405
|
-
if (!disabled && getMouseEventButton(keyDef.button) === 2) instance.dispatchUIEvent(target, "contextmenu", this.getEventInit("contextmenu", keyDef.button));
|
|
1406
|
-
}
|
|
1407
|
-
up(instance, keyDef, isPrevented) {
|
|
1408
|
-
const button = this.buttons.up(keyDef);
|
|
1409
|
-
if (button === void 0) return;
|
|
1410
|
-
const target = this.getTarget(instance);
|
|
1411
|
-
if (!isDisabled(target)) {
|
|
1412
|
-
if (!isPrevented) {
|
|
1413
|
-
const mouseUpInit = this.getEventInit("mouseup", keyDef.button);
|
|
1414
|
-
instance.dispatchUIEvent(target, "mouseup", mouseUpInit);
|
|
1415
|
-
this.endSelecting();
|
|
1416
|
-
}
|
|
1417
|
-
const clickTarget = getTreeDiff(this.buttonDownTarget[button], target)[2][0];
|
|
1418
|
-
if (clickTarget) {
|
|
1419
|
-
const init = this.getEventInit("click", keyDef.button);
|
|
1420
|
-
if (init.detail) {
|
|
1421
|
-
instance.dispatchUIEvent(clickTarget, init.button === 0 ? "click" : "auxclick", init);
|
|
1422
|
-
if (init.button === 0 && init.detail === 2) instance.dispatchUIEvent(clickTarget, "dblclick", {
|
|
1423
|
-
...this.getEventInit("dblclick", keyDef.button),
|
|
1424
|
-
detail: init.detail
|
|
1425
|
-
});
|
|
1426
|
-
}
|
|
1427
|
-
}
|
|
1428
|
-
}
|
|
1429
|
-
}
|
|
1430
|
-
resetClickCount() {
|
|
1431
|
-
this.clickCount.reset();
|
|
1432
|
-
}
|
|
1433
|
-
getEventInit(type, button) {
|
|
1434
|
-
const init = { ...this.position.coords };
|
|
1435
|
-
init.button = getMouseEventButton(button);
|
|
1436
|
-
init.buttons = this.buttons.getButtons();
|
|
1437
|
-
if (type === "mousedown") init.detail = this.clickCount.getOnDown(init.button);
|
|
1438
|
-
else if (type === "mouseup") init.detail = this.clickCount.getOnUp(init.button);
|
|
1439
|
-
else if (type === "click" || type === "auxclick") init.detail = this.clickCount.incOnClick(init.button);
|
|
1440
|
-
return init;
|
|
1441
|
-
}
|
|
1442
|
-
getTarget(instance) {
|
|
1443
|
-
return this.position.target ?? instance.config.document.body;
|
|
1444
|
-
}
|
|
1445
|
-
startSelecting(instance, clickCount) {
|
|
1446
|
-
this.selecting = setSelectionPerMouseDown({
|
|
1447
|
-
document: instance.config.document,
|
|
1448
|
-
target: this.getTarget(instance),
|
|
1449
|
-
node: this.position.caret?.node,
|
|
1450
|
-
offset: this.position.caret?.offset,
|
|
1451
|
-
clickCount
|
|
1452
|
-
});
|
|
1453
|
-
}
|
|
1454
|
-
modifySelecting(instance) {
|
|
1455
|
-
if (!this.selecting) return;
|
|
1456
|
-
modifySelectionPerMouseMove(this.selecting, {
|
|
1457
|
-
document: instance.config.document,
|
|
1458
|
-
target: this.getTarget(instance),
|
|
1459
|
-
node: this.position.caret?.node,
|
|
1460
|
-
offset: this.position.caret?.offset
|
|
1461
|
-
});
|
|
1462
|
-
}
|
|
1463
|
-
endSelecting() {
|
|
1464
|
-
this.selecting = void 0;
|
|
1465
|
-
}
|
|
1466
|
-
};
|
|
1467
|
-
|
|
1468
|
-
// src/system/pointer/pointer.ts
|
|
1469
|
-
var Pointer = class {
|
|
1470
|
-
constructor({ pointerId, pointerType, isPrimary }, buttons) {
|
|
1471
|
-
this.pointerId = pointerId;
|
|
1472
|
-
this.pointerType = pointerType;
|
|
1473
|
-
this.isPrimary = isPrimary;
|
|
1474
|
-
this.isMultitouch = !isPrimary;
|
|
1475
|
-
this.buttons = buttons;
|
|
1476
|
-
}
|
|
1477
|
-
pointerId;
|
|
1478
|
-
pointerType;
|
|
1479
|
-
isPrimary;
|
|
1480
|
-
buttons;
|
|
1481
|
-
isMultitouch = false;
|
|
1482
|
-
isCancelled = false;
|
|
1483
|
-
isDown = false;
|
|
1484
|
-
isPrevented = false;
|
|
1485
|
-
position = {};
|
|
1486
|
-
init(instance) {
|
|
1487
|
-
const target = this.getTarget(instance);
|
|
1488
|
-
const [, enter] = getTreeDiff(null, target);
|
|
1489
|
-
const init = this.getEventInit();
|
|
1490
|
-
assertPointerEvents(instance, target);
|
|
1491
|
-
instance.dispatchUIEvent(target, "pointerover", init);
|
|
1492
|
-
enter.forEach((el) => instance.dispatchUIEvent(el, "pointerenter", init));
|
|
1493
|
-
return this;
|
|
1494
|
-
}
|
|
1495
|
-
move(instance, position) {
|
|
1496
|
-
const prevPosition = this.position;
|
|
1497
|
-
const prevTarget = this.getTarget(instance);
|
|
1498
|
-
this.position = position;
|
|
1499
|
-
if (!isDifferentPointerPosition(prevPosition, position)) return;
|
|
1500
|
-
const nextTarget = this.getTarget(instance);
|
|
1501
|
-
const init = this.getEventInit(-1);
|
|
1502
|
-
const [leave, enter] = getTreeDiff(prevTarget, nextTarget);
|
|
1503
|
-
return {
|
|
1504
|
-
leave: () => {
|
|
1505
|
-
if (hasPointerEvents(instance, prevTarget)) {
|
|
1506
|
-
if (prevTarget !== nextTarget) {
|
|
1507
|
-
instance.dispatchUIEvent(prevTarget, "pointerout", init);
|
|
1508
|
-
leave.forEach((el) => instance.dispatchUIEvent(el, "pointerleave", init));
|
|
1509
|
-
}
|
|
1510
|
-
}
|
|
1511
|
-
},
|
|
1512
|
-
enter: () => {
|
|
1513
|
-
assertPointerEvents(instance, nextTarget);
|
|
1514
|
-
if (prevTarget !== nextTarget) {
|
|
1515
|
-
instance.dispatchUIEvent(nextTarget, "pointerover", init);
|
|
1516
|
-
enter.forEach((el) => instance.dispatchUIEvent(el, "pointerenter", init));
|
|
1517
|
-
}
|
|
1518
|
-
},
|
|
1519
|
-
move: () => {
|
|
1520
|
-
instance.dispatchUIEvent(nextTarget, "pointermove", init);
|
|
1521
|
-
}
|
|
1522
|
-
};
|
|
1523
|
-
}
|
|
1524
|
-
down(instance, button = 0) {
|
|
1525
|
-
if (this.isDown) return;
|
|
1526
|
-
const target = this.getTarget(instance);
|
|
1527
|
-
assertPointerEvents(instance, target);
|
|
1528
|
-
this.isDown = true;
|
|
1529
|
-
this.isPrevented = !instance.dispatchUIEvent(target, "pointerdown", this.getEventInit(button));
|
|
1530
|
-
}
|
|
1531
|
-
up(instance, button = 0) {
|
|
1532
|
-
if (!this.isDown) return;
|
|
1533
|
-
const target = this.getTarget(instance);
|
|
1534
|
-
assertPointerEvents(instance, target);
|
|
1535
|
-
this.isPrevented = false;
|
|
1536
|
-
this.isDown = false;
|
|
1537
|
-
instance.dispatchUIEvent(target, "pointerup", this.getEventInit(button));
|
|
1538
|
-
}
|
|
1539
|
-
release(instance) {
|
|
1540
|
-
const target = this.getTarget(instance);
|
|
1541
|
-
const [leave] = getTreeDiff(target, null);
|
|
1542
|
-
const init = this.getEventInit();
|
|
1543
|
-
/* istanbul ignore else */
|
|
1544
|
-
if (hasPointerEvents(instance, target)) {
|
|
1545
|
-
instance.dispatchUIEvent(target, "pointerout", init);
|
|
1546
|
-
leave.forEach((el) => instance.dispatchUIEvent(el, "pointerleave", init));
|
|
1547
|
-
}
|
|
1548
|
-
this.isCancelled = true;
|
|
1549
|
-
}
|
|
1550
|
-
getTarget(instance) {
|
|
1551
|
-
return this.position.target ?? instance.config.document.body;
|
|
1552
|
-
}
|
|
1553
|
-
getEventInit(button) {
|
|
1554
|
-
return {
|
|
1555
|
-
...this.position.coords,
|
|
1556
|
-
pointerId: this.pointerId,
|
|
1557
|
-
pointerType: this.pointerType,
|
|
1558
|
-
isPrimary: this.isPrimary,
|
|
1559
|
-
button: getMouseEventButton(button),
|
|
1560
|
-
buttons: this.buttons.getButtons()
|
|
1561
|
-
};
|
|
1562
|
-
}
|
|
1563
|
-
};
|
|
1564
|
-
|
|
1565
|
-
// src/system/pointer/index.ts
|
|
1566
|
-
var PointerHost = class {
|
|
1567
|
-
system;
|
|
1568
|
-
constructor(system) {
|
|
1569
|
-
this.system = system;
|
|
1570
|
-
this.buttons = new Buttons();
|
|
1571
|
-
this.mouse = new Mouse();
|
|
1572
|
-
this.pointers.new("mouse", "mouse", this.buttons);
|
|
1573
|
-
}
|
|
1574
|
-
mouse;
|
|
1575
|
-
buttons;
|
|
1576
|
-
devices = new class {
|
|
1577
|
-
registry = {};
|
|
1578
|
-
get(k) {
|
|
1579
|
-
return this.registry[k] ??= new Device();
|
|
1580
|
-
}
|
|
1581
|
-
}();
|
|
1582
|
-
pointers = new class {
|
|
1583
|
-
registry = {};
|
|
1584
|
-
nextId = 1;
|
|
1585
|
-
new(pointerName, pointerType, buttons) {
|
|
1586
|
-
const isPrimary = pointerType !== "touch" || !Object.values(this.registry).some((p) => p.pointerType === "touch" && !p.isCancelled);
|
|
1587
|
-
if (!isPrimary) Object.values(this.registry).forEach((p) => {
|
|
1588
|
-
if (p.pointerType === pointerType && !p.isCancelled) p.isMultitouch = true;
|
|
1589
|
-
});
|
|
1590
|
-
this.registry[pointerName] = new Pointer({
|
|
1591
|
-
pointerId: this.nextId++,
|
|
1592
|
-
pointerType,
|
|
1593
|
-
isPrimary
|
|
1594
|
-
}, buttons);
|
|
1595
|
-
return this.registry[pointerName];
|
|
1596
|
-
}
|
|
1597
|
-
get(pointerName) {
|
|
1598
|
-
if (!this.has(pointerName)) throw new Error(`Trying to access pointer "${pointerName}" which does not exist.`);
|
|
1599
|
-
return this.registry[pointerName];
|
|
1600
|
-
}
|
|
1601
|
-
has(pointerName) {
|
|
1602
|
-
return pointerName in this.registry;
|
|
1603
|
-
}
|
|
1604
|
-
}();
|
|
1605
|
-
isKeyPressed(keyDef) {
|
|
1606
|
-
return this.devices.get(keyDef.pointerType).isPressed(keyDef);
|
|
1607
|
-
}
|
|
1608
|
-
async press(instance, keyDef, position) {
|
|
1609
|
-
this.devices.get(keyDef.pointerType).addPressed(keyDef);
|
|
1610
|
-
this.buttons.down(keyDef);
|
|
1611
|
-
const pointerName = this.getPointerName(keyDef);
|
|
1612
|
-
const pointer = keyDef.pointerType === "touch" ? this.pointers.new(pointerName, keyDef.pointerType, this.buttons) : this.pointers.get(pointerName);
|
|
1613
|
-
pointer.position = position;
|
|
1614
|
-
if (pointer.pointerType !== "touch") this.mouse.position = position;
|
|
1615
|
-
if (pointer.pointerType === "touch") pointer.init(instance);
|
|
1616
|
-
pointer.down(instance, keyDef.button);
|
|
1617
|
-
if (pointer.pointerType !== "touch") this.mouse.down(instance, keyDef, pointer.isPrevented);
|
|
1618
|
-
}
|
|
1619
|
-
async move(instance, pointerName, position) {
|
|
1620
|
-
const pointer = this.pointers.get(pointerName);
|
|
1621
|
-
const pointermove = pointer.move(instance, position);
|
|
1622
|
-
const mousemove = pointer.pointerType === "touch" ? void 0 : this.mouse.move(instance, position, pointer.isPrevented);
|
|
1623
|
-
pointermove?.leave();
|
|
1624
|
-
mousemove?.leave();
|
|
1625
|
-
pointermove?.enter();
|
|
1626
|
-
mousemove?.enter();
|
|
1627
|
-
pointermove?.move();
|
|
1628
|
-
mousemove?.move();
|
|
1629
|
-
}
|
|
1630
|
-
async release(instance, keyDef, position) {
|
|
1631
|
-
const device = this.devices.get(keyDef.pointerType);
|
|
1632
|
-
device.removePressed(keyDef);
|
|
1633
|
-
this.buttons.up(keyDef);
|
|
1634
|
-
const pointer = this.pointers.get(this.getPointerName(keyDef));
|
|
1635
|
-
const isPrevented = pointer.isPrevented;
|
|
1636
|
-
pointer.position = position;
|
|
1637
|
-
if (pointer.pointerType !== "touch") this.mouse.position = position;
|
|
1638
|
-
if (device.countPressed === 0) pointer.up(instance, keyDef.button);
|
|
1639
|
-
if (pointer.pointerType === "touch") pointer.release(instance);
|
|
1640
|
-
if (pointer.pointerType === "touch" && !pointer.isMultitouch) {
|
|
1641
|
-
const mousemove = this.mouse.move(instance, position, isPrevented);
|
|
1642
|
-
mousemove?.leave();
|
|
1643
|
-
mousemove?.enter();
|
|
1644
|
-
mousemove?.move();
|
|
1645
|
-
this.mouse.down(instance, keyDef, isPrevented);
|
|
1646
|
-
}
|
|
1647
|
-
if (!pointer.isMultitouch) {
|
|
1648
|
-
const mousemove = this.mouse.move(instance, position, isPrevented);
|
|
1649
|
-
mousemove?.leave();
|
|
1650
|
-
mousemove?.enter();
|
|
1651
|
-
mousemove?.move();
|
|
1652
|
-
this.mouse.up(instance, keyDef, isPrevented);
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
getPointerName(keyDef) {
|
|
1656
|
-
return keyDef.pointerType === "touch" ? keyDef.name : keyDef.pointerType;
|
|
1657
|
-
}
|
|
1658
|
-
getPreviousPosition(pointerName) {
|
|
1659
|
-
return this.pointers.has(pointerName) ? this.pointers.get(pointerName).position : void 0;
|
|
1660
|
-
}
|
|
1661
|
-
resetClickCount() {
|
|
1662
|
-
this.mouse.resetClickCount();
|
|
1663
|
-
}
|
|
1664
|
-
getMouseTarget(instance) {
|
|
1665
|
-
return this.mouse.position.target ?? instance.config.document.body;
|
|
1666
|
-
}
|
|
1667
|
-
setMousePosition(position) {
|
|
1668
|
-
this.mouse.position = position;
|
|
1669
|
-
this.pointers.get("mouse").position = position;
|
|
1670
|
-
}
|
|
1671
|
-
};
|
|
1672
|
-
|
|
1673
|
-
// src/system/index.ts
|
|
1674
|
-
/**
|
|
1675
|
-
* @internal Do not create/alter this by yourself as this type might be subject to changes.
|
|
1676
|
-
*/
|
|
1677
|
-
var System = class {
|
|
1678
|
-
keyboard = new KeyboardHost(this);
|
|
1679
|
-
pointer = new PointerHost(this);
|
|
1680
|
-
/** Write the modifier members into `init` (no intermediate object; see createEvent). */
|
|
1681
|
-
assignUIEventModifiers(init) {
|
|
1682
|
-
const m = this.keyboard.modifiers;
|
|
1683
|
-
init.altKey = m.Alt;
|
|
1684
|
-
init.ctrlKey = m.Control;
|
|
1685
|
-
init.metaKey = m.Meta;
|
|
1686
|
-
init.shiftKey = m.Shift;
|
|
1687
|
-
init.modifierAltGraph = m.AltGraph;
|
|
1688
|
-
init.modifierCapsLock = m.CapsLock;
|
|
1689
|
-
init.modifierFn = m.Fn;
|
|
1690
|
-
init.modifierFnLock = m.FnLock;
|
|
1691
|
-
init.modifierNumLock = m.NumLock;
|
|
1692
|
-
init.modifierScrollLock = m.ScrollLock;
|
|
1693
|
-
init.modifierSymbol = m.Symbol;
|
|
1694
|
-
init.modifierSymbolLock = m.SymbolLock;
|
|
1695
|
-
}
|
|
1696
|
-
getUIEventModifiers() {
|
|
1697
|
-
return {
|
|
1698
|
-
altKey: this.keyboard.modifiers.Alt,
|
|
1699
|
-
ctrlKey: this.keyboard.modifiers.Control,
|
|
1700
|
-
metaKey: this.keyboard.modifiers.Meta,
|
|
1701
|
-
shiftKey: this.keyboard.modifiers.Shift,
|
|
1702
|
-
modifierAltGraph: this.keyboard.modifiers.AltGraph,
|
|
1703
|
-
modifierCapsLock: this.keyboard.modifiers.CapsLock,
|
|
1704
|
-
modifierFn: this.keyboard.modifiers.Fn,
|
|
1705
|
-
modifierFnLock: this.keyboard.modifiers.FnLock,
|
|
1706
|
-
modifierNumLock: this.keyboard.modifiers.NumLock,
|
|
1707
|
-
modifierScrollLock: this.keyboard.modifiers.ScrollLock,
|
|
1708
|
-
modifierSymbol: this.keyboard.modifiers.Symbol,
|
|
1709
|
-
modifierSymbolLock: this.keyboard.modifiers.SymbolLock
|
|
1710
|
-
};
|
|
1711
|
-
}
|
|
1712
|
-
};
|
|
1713
|
-
|
|
1714
|
-
// src/system/keyLocation.ts
|
|
1715
|
-
const DOM_KEY_LOCATION = Object.freeze({
|
|
1716
|
-
STANDARD: 0,
|
|
1717
|
-
LEFT: 1,
|
|
1718
|
-
RIGHT: 2,
|
|
1719
|
-
NUMPAD: 3,
|
|
1720
|
-
0: "STANDARD",
|
|
1721
|
-
1: "LEFT",
|
|
1722
|
-
2: "RIGHT",
|
|
1723
|
-
3: "NUMPAD"
|
|
1724
|
-
});
|
|
1725
|
-
|
|
1726
|
-
// src/system/keyboard.ts
|
|
1727
|
-
const modifierKeys = [
|
|
1728
|
-
"Alt",
|
|
1729
|
-
"AltGraph",
|
|
1730
|
-
"Control",
|
|
1731
|
-
"Fn",
|
|
1732
|
-
"Meta",
|
|
1733
|
-
"Shift",
|
|
1734
|
-
"Symbol"
|
|
1735
|
-
];
|
|
1736
|
-
function isModifierKey(key) {
|
|
1737
|
-
return modifierKeys.includes(key);
|
|
1738
|
-
}
|
|
1739
|
-
const modifierLocks = [
|
|
1740
|
-
"CapsLock",
|
|
1741
|
-
"FnLock",
|
|
1742
|
-
"NumLock",
|
|
1743
|
-
"ScrollLock",
|
|
1744
|
-
"SymbolLock"
|
|
1745
|
-
];
|
|
1746
|
-
function isModifierLock(key) {
|
|
1747
|
-
return modifierLocks.includes(key);
|
|
1748
|
-
}
|
|
1749
|
-
var KeyboardHost = class {
|
|
1750
|
-
system;
|
|
1751
|
-
constructor(system) {
|
|
1752
|
-
this.system = system;
|
|
1753
|
-
}
|
|
1754
|
-
modifiers = {
|
|
1755
|
-
Alt: false,
|
|
1756
|
-
AltGraph: false,
|
|
1757
|
-
CapsLock: false,
|
|
1758
|
-
Control: false,
|
|
1759
|
-
Fn: false,
|
|
1760
|
-
FnLock: false,
|
|
1761
|
-
Meta: false,
|
|
1762
|
-
NumLock: false,
|
|
1763
|
-
ScrollLock: false,
|
|
1764
|
-
Shift: false,
|
|
1765
|
-
Symbol: false,
|
|
1766
|
-
SymbolLock: false
|
|
1767
|
-
};
|
|
1768
|
-
pressed = new class {
|
|
1769
|
-
registry = {};
|
|
1770
|
-
add(code, keyDef) {
|
|
1771
|
-
this.registry[code] ??= {
|
|
1772
|
-
keyDef,
|
|
1773
|
-
unpreventedDefault: false
|
|
1774
|
-
};
|
|
1775
|
-
}
|
|
1776
|
-
has(code) {
|
|
1777
|
-
return !!this.registry[code];
|
|
1778
|
-
}
|
|
1779
|
-
setUnprevented(code) {
|
|
1780
|
-
const o = this.registry[code];
|
|
1781
|
-
if (o) o.unpreventedDefault = true;
|
|
1782
|
-
}
|
|
1783
|
-
isUnprevented(code) {
|
|
1784
|
-
return !!this.registry[code]?.unpreventedDefault;
|
|
1785
|
-
}
|
|
1786
|
-
delete(code) {
|
|
1787
|
-
delete this.registry[code];
|
|
1788
|
-
}
|
|
1789
|
-
values() {
|
|
1790
|
-
return Object.values(this.registry);
|
|
1791
|
-
}
|
|
1792
|
-
}();
|
|
1793
|
-
carryChar = "";
|
|
1794
|
-
lastKeydownTarget = void 0;
|
|
1795
|
-
modifierLockStart = {};
|
|
1796
|
-
isKeyPressed(keyDef) {
|
|
1797
|
-
return this.pressed.has(String(keyDef.code));
|
|
1798
|
-
}
|
|
1799
|
-
getPressedKeys() {
|
|
1800
|
-
return this.pressed.values().map((p) => p.keyDef);
|
|
1801
|
-
}
|
|
1802
|
-
/** Press a key */
|
|
1803
|
-
async keydown(instance, keyDef, repeat = false) {
|
|
1804
|
-
const key = String(keyDef.key);
|
|
1805
|
-
const code = String(keyDef.code);
|
|
1806
|
-
const target = getActiveElementOrBody(instance.config.document);
|
|
1807
|
-
this.setKeydownTarget(target);
|
|
1808
|
-
this.pressed.add(code, keyDef);
|
|
1809
|
-
if (isModifierKey(key)) this.modifiers[key] = true;
|
|
1810
|
-
const unprevented = instance.dispatchUIEvent(target, "keydown", {
|
|
1811
|
-
key,
|
|
1812
|
-
code,
|
|
1813
|
-
repeat
|
|
1814
|
-
});
|
|
1815
|
-
if (isModifierLock(key) && !this.modifiers[key]) {
|
|
1816
|
-
this.modifiers[key] = true;
|
|
1817
|
-
this.modifierLockStart[key] = true;
|
|
1818
|
-
}
|
|
1819
|
-
if (unprevented) this.pressed.setUnprevented(code);
|
|
1820
|
-
if (unprevented && this.hasKeyPress(key)) instance.dispatchUIEvent(getActiveElementOrBody(instance.config.document), "keypress", {
|
|
1821
|
-
key,
|
|
1822
|
-
code,
|
|
1823
|
-
charCode: keyDef.key === "Enter" ? 13 : String(keyDef.key).charCodeAt(0)
|
|
1824
|
-
});
|
|
1825
|
-
}
|
|
1826
|
-
/** Release a key */
|
|
1827
|
-
async keyup(instance, keyDef) {
|
|
1828
|
-
const key = String(keyDef.key);
|
|
1829
|
-
const code = String(keyDef.code);
|
|
1830
|
-
const unprevented = this.pressed.isUnprevented(code);
|
|
1831
|
-
this.pressed.delete(code);
|
|
1832
|
-
if (isModifierKey(key) && !this.pressed.values().find((p) => p.keyDef.key === key)) this.modifiers[key] = false;
|
|
1833
|
-
instance.dispatchUIEvent(getActiveElementOrBody(instance.config.document), "keyup", {
|
|
1834
|
-
key,
|
|
1835
|
-
code
|
|
1836
|
-
}, !unprevented);
|
|
1837
|
-
if (isModifierLock(key) && this.modifiers[key]) {
|
|
1838
|
-
if (this.modifierLockStart[key]) this.modifierLockStart[key] = false;
|
|
1839
|
-
else this.modifiers[key] = false;
|
|
1840
|
-
}
|
|
1841
|
-
}
|
|
1842
|
-
setKeydownTarget(target) {
|
|
1843
|
-
if (target !== this.lastKeydownTarget) this.carryChar = "";
|
|
1844
|
-
this.lastKeydownTarget = target;
|
|
1845
|
-
}
|
|
1846
|
-
hasKeyPress(key) {
|
|
1847
|
-
return (key.length === 1 || key === "Enter") && !this.modifiers.Control && !this.modifiers.Alt;
|
|
1848
|
-
}
|
|
1849
|
-
};
|
|
1850
|
-
|
|
1851
|
-
// src/options.ts
|
|
1852
|
-
const PointerEventsCheckLevel = Object.freeze({
|
|
1853
|
-
/**
|
|
1854
|
-
* Check pointer events on every user interaction that triggers a bunch of events.
|
|
1855
|
-
* E.g. once for releasing a mouse button even though this triggers `pointerup`, `mouseup`, `click`, etc...
|
|
1856
|
-
*/
|
|
1857
|
-
EachTrigger: 4,
|
|
1858
|
-
/** Check each target once per call to pointer (related) API */
|
|
1859
|
-
EachApiCall: 2,
|
|
1860
|
-
/** Check each event target once */
|
|
1861
|
-
EachTarget: 1,
|
|
1862
|
-
/** No pointer events check */
|
|
1863
|
-
Never: 0,
|
|
1864
|
-
4: "EachTrigger",
|
|
1865
|
-
2: "EachApiCall",
|
|
1866
|
-
1: "EachTarget",
|
|
1867
|
-
0: "Never"
|
|
1868
|
-
});
|
|
1869
|
-
|
|
1870
|
-
// src/utils/pointer/cssPointerEvents.ts
|
|
1871
|
-
function hasPointerEvents(instance, element) {
|
|
1872
|
-
return checkPointerEvents(instance, element)?.pointerEvents !== "none";
|
|
1873
|
-
}
|
|
1874
|
-
function closestPointerEventsDeclaration(element) {
|
|
1875
|
-
const window = getWindow(element);
|
|
1876
|
-
for (let el = element, tree = []; el?.ownerDocument; el = el.parentElement) {
|
|
1877
|
-
tree.push(el);
|
|
1878
|
-
const pointerEvents = window.getComputedStyle(el).pointerEvents;
|
|
1879
|
-
if (pointerEvents && !["inherit", "unset"].includes(pointerEvents)) return {
|
|
1880
|
-
pointerEvents,
|
|
1881
|
-
tree
|
|
1882
|
-
};
|
|
1883
|
-
}
|
|
1884
|
-
}
|
|
1885
|
-
const PointerEventsCheck = Symbol("Last check for pointer-events");
|
|
1886
|
-
function checkPointerEvents(instance, element) {
|
|
1887
|
-
const lastCheck = element[PointerEventsCheck];
|
|
1888
|
-
if (!(instance.config.pointerEventsCheck !== PointerEventsCheckLevel.Never && (!lastCheck || hasBitFlag(instance.config.pointerEventsCheck, PointerEventsCheckLevel.EachApiCall) && lastCheck[ApiLevel.Call] !== getLevelRef(instance, ApiLevel.Call) || hasBitFlag(instance.config.pointerEventsCheck, PointerEventsCheckLevel.EachTrigger) && lastCheck[ApiLevel.Trigger] !== getLevelRef(instance, ApiLevel.Trigger)))) return lastCheck?.result;
|
|
1889
|
-
const declaration = closestPointerEventsDeclaration(element);
|
|
1890
|
-
element[PointerEventsCheck] = {
|
|
1891
|
-
[ApiLevel.Call]: getLevelRef(instance, ApiLevel.Call),
|
|
1892
|
-
[ApiLevel.Trigger]: getLevelRef(instance, ApiLevel.Trigger),
|
|
1893
|
-
result: declaration
|
|
1894
|
-
};
|
|
1895
|
-
return declaration;
|
|
1896
|
-
}
|
|
1897
|
-
function assertPointerEvents(instance, element) {
|
|
1898
|
-
const declaration = checkPointerEvents(instance, element);
|
|
1899
|
-
if (declaration?.pointerEvents === "none") throw new Error([
|
|
1900
|
-
`Unable to perform pointer interaction as the element ${declaration.tree.length > 1 ? "inherits" : "has"} \`pointer-events: none\`:`,
|
|
1901
|
-
"",
|
|
1902
|
-
printTree(declaration.tree)
|
|
1903
|
-
].join("\n"));
|
|
1904
|
-
}
|
|
1905
|
-
function printTree(tree) {
|
|
1906
|
-
return tree.reverse().map((el, i) => [
|
|
1907
|
-
"".padEnd(i),
|
|
1908
|
-
el.tagName,
|
|
1909
|
-
el.id && `#${el.id}`,
|
|
1910
|
-
el.hasAttribute("data-testid") && `(testId=${el.getAttribute("data-testid")})`,
|
|
1911
|
-
getLabelDescr(el),
|
|
1912
|
-
tree.length > 1 && i === 0 && " <-- This element declared `pointer-events: none`",
|
|
1913
|
-
tree.length > 1 && i === tree.length - 1 && " <-- Asserted pointer events here"
|
|
1914
|
-
].filter(Boolean).join("")).join("\n");
|
|
1915
|
-
}
|
|
1916
|
-
function getLabelDescr(element) {
|
|
1917
|
-
let label;
|
|
1918
|
-
if (element.hasAttribute("aria-label")) label = element.getAttribute("aria-label");
|
|
1919
|
-
else if (element.hasAttribute("aria-labelledby")) label = element.ownerDocument.getElementById(element.getAttribute("aria-labelledby"))?.textContent?.trim();
|
|
1920
|
-
else if (isElementType(element, [
|
|
1921
|
-
"button",
|
|
1922
|
-
"input",
|
|
1923
|
-
"meter",
|
|
1924
|
-
"output",
|
|
1925
|
-
"progress",
|
|
1926
|
-
"select",
|
|
1927
|
-
"textarea"
|
|
1928
|
-
]) && element.labels?.length) label = Array.from(element.labels).map((el) => el.textContent?.trim()).join("|");
|
|
1929
|
-
else if (isElementType(element, "button")) label = element.textContent?.trim();
|
|
1930
|
-
label = label?.replace(/\n/g, " ");
|
|
1931
|
-
if (Number(label?.length) > 30) label = `${label?.substring(0, 29)}…`;
|
|
1932
|
-
return label ? `(label=${label})` : "";
|
|
1933
|
-
}
|
|
1934
|
-
function hasBitFlag(conf, flag) {
|
|
1935
|
-
return (conf & flag) > 0;
|
|
1936
|
-
}
|
|
1937
|
-
|
|
1938
|
-
// src/document/UI.ts
|
|
1939
|
-
const UIValue = Symbol("Displayed value in UI");
|
|
1940
|
-
const UISelection = Symbol("Displayed selection in UI");
|
|
1941
|
-
const InitialValue = Symbol("Initial value to compare on blur");
|
|
1942
|
-
function isUIValue(value) {
|
|
1943
|
-
return typeof value === "object" && UIValue in value;
|
|
1944
|
-
}
|
|
1945
|
-
function isUISelectionStart(start) {
|
|
1946
|
-
return !!start && typeof start === "object" && UISelection in start;
|
|
1947
|
-
}
|
|
1948
|
-
function setUIValue(element, value) {
|
|
1949
|
-
const el = element;
|
|
1950
|
-
if (el[InitialValue] === void 0) el[InitialValue] = el.value;
|
|
1951
|
-
if (hasCtrlDomUI(el)) {
|
|
1952
|
-
ctrlDomUI.setUIValue(el, value);
|
|
1953
|
-
return;
|
|
1954
|
-
}
|
|
1955
|
-
el[UIValue] = value;
|
|
1956
|
-
el.value = Object.assign(new String(value), { [UIValue]: true });
|
|
1957
|
-
}
|
|
1958
|
-
function getUIValue(element) {
|
|
1959
|
-
const el = element;
|
|
1960
|
-
if (hasCtrlDomUI(el)) return ctrlDomUI.getUIValue(el);
|
|
1961
|
-
return el[UIValue] === void 0 ? el.value : String(el[UIValue]);
|
|
1962
|
-
}
|
|
1963
|
-
/** Flag the IDL value as clean. This does not change the value. */
|
|
1964
|
-
function setUIValueClean(element) {
|
|
1965
|
-
if (hasCtrlDomUI(element)) {
|
|
1966
|
-
ctrlDomUI.clearUIValue(element);
|
|
1967
|
-
return;
|
|
1968
|
-
}
|
|
1969
|
-
element[UIValue] = void 0;
|
|
1970
|
-
}
|
|
1971
|
-
function clearInitialValue(element) {
|
|
1972
|
-
element[InitialValue] = void 0;
|
|
1973
|
-
}
|
|
1974
|
-
function getInitialValue(element) {
|
|
1975
|
-
return element[InitialValue];
|
|
1976
|
-
}
|
|
1977
|
-
function setUISelectionRaw(element, selection) {
|
|
1978
|
-
element[UISelection] = selection;
|
|
1979
|
-
}
|
|
1980
|
-
function setUISelection(element, { focusOffset: focusOffsetParam, anchorOffset: anchorOffsetParam = focusOffsetParam }, mode = "replace") {
|
|
1981
|
-
const el = element;
|
|
1982
|
-
const valueLength = getUIValue(el).length;
|
|
1983
|
-
const sanitizeOffset = (o) => Math.max(0, Math.min(valueLength, o));
|
|
1984
|
-
if (hasCtrlDomUI(el)) {
|
|
1985
|
-
const anchorOffset = mode === "replace" ? sanitizeOffset(anchorOffsetParam) : getUISelection(el).anchorOffset;
|
|
1986
|
-
const focusOffset = sanitizeOffset(focusOffsetParam);
|
|
1987
|
-
el[UISelection] = {
|
|
1988
|
-
anchorOffset,
|
|
1989
|
-
focusOffset
|
|
1990
|
-
};
|
|
1991
|
-
ctrlDomUI.setUISelection(el, Math.min(anchorOffset, focusOffset), Math.max(anchorOffset, focusOffset), "none");
|
|
1992
|
-
return;
|
|
1993
|
-
}
|
|
1994
|
-
const anchorOffset = mode === "replace" || el[UISelection] === void 0 ? sanitizeOffset(anchorOffsetParam) : el[UISelection].anchorOffset;
|
|
1995
|
-
const focusOffset = sanitizeOffset(focusOffsetParam);
|
|
1996
|
-
const startOffset = Math.min(anchorOffset, focusOffset);
|
|
1997
|
-
const endOffset = Math.max(anchorOffset, focusOffset);
|
|
1998
|
-
el[UISelection] = {
|
|
1999
|
-
anchorOffset,
|
|
2000
|
-
focusOffset
|
|
2001
|
-
};
|
|
2002
|
-
if (el.selectionStart === startOffset && el.selectionEnd === endOffset) return;
|
|
2003
|
-
const startObj = Object.assign(new Number(startOffset), { [UISelection]: true });
|
|
2004
|
-
try {
|
|
2005
|
-
el.setSelectionRange(startObj, endOffset);
|
|
2006
|
-
} catch {}
|
|
2007
|
-
}
|
|
2008
|
-
function getUISelection(element) {
|
|
2009
|
-
const el = element;
|
|
2010
|
-
let sel;
|
|
2011
|
-
if (hasCtrlDomUI(el)) {
|
|
2012
|
-
const { start, end } = ctrlDomUI.getUISelection(el);
|
|
2013
|
-
const remembered = el[UISelection];
|
|
2014
|
-
sel = remembered !== void 0 && Math.min(remembered.anchorOffset, remembered.focusOffset) === start && Math.max(remembered.anchorOffset, remembered.focusOffset) === end ? remembered : {
|
|
2015
|
-
anchorOffset: start,
|
|
2016
|
-
focusOffset: end
|
|
2017
|
-
};
|
|
2018
|
-
} else sel = el[UISelection] ?? {
|
|
2019
|
-
anchorOffset: el.selectionStart ?? 0,
|
|
2020
|
-
focusOffset: el.selectionEnd ?? 0
|
|
2021
|
-
};
|
|
2022
|
-
return {
|
|
2023
|
-
anchorOffset: sel.anchorOffset,
|
|
2024
|
-
focusOffset: sel.focusOffset,
|
|
2025
|
-
startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
|
|
2026
|
-
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
2027
|
-
};
|
|
2028
|
-
}
|
|
2029
|
-
function hasUISelection(element) {
|
|
2030
|
-
return hasCtrlDomUI(element) || !!element[UISelection];
|
|
2031
|
-
}
|
|
2032
|
-
/** Flag the IDL selection as clean. This does not change the selection. */
|
|
2033
|
-
function setUISelectionClean(element) {
|
|
2034
|
-
element[UISelection] = void 0;
|
|
2035
|
-
}
|
|
2036
|
-
|
|
2037
|
-
// src/document/getValueOrTextContent.ts
|
|
2038
|
-
function getValueOrTextContent(element) {
|
|
2039
|
-
// istanbul ignore if
|
|
2040
|
-
if (!element) return null;
|
|
2041
|
-
if (isContentEditable(element)) return element.textContent;
|
|
2042
|
-
return getUIValue(element);
|
|
2043
|
-
}
|
|
2044
|
-
|
|
2045
|
-
// src/document/copySelection.ts
|
|
2046
|
-
function copySelection(target) {
|
|
2047
|
-
const data = hasOwnSelection(target) ? { "text/plain": readSelectedValueFromInput(target) } : { "text/plain": String(target.ownerDocument.getSelection()) };
|
|
2048
|
-
const dt = createDataTransfer(getWindow(target));
|
|
2049
|
-
for (const type in data) if (data[type]) dt.setData(type, data[type]);
|
|
2050
|
-
return dt;
|
|
2051
|
-
}
|
|
2052
|
-
function readSelectedValueFromInput(target) {
|
|
2053
|
-
const sel = getUISelection(target);
|
|
2054
|
-
return getUIValue(target).substring(sel.startOffset, sel.endOffset);
|
|
2055
|
-
}
|
|
2056
|
-
|
|
2057
|
-
// src/document/trackValue.ts
|
|
2058
|
-
const TrackChanges = Symbol("Track programmatic changes for React workaround");
|
|
2059
|
-
function isReact17Element(element) {
|
|
2060
|
-
return Object.getOwnPropertyNames(element).some((k) => k.startsWith("__react")) && getWindow(element).REACT_VERSION === 17;
|
|
2061
|
-
}
|
|
2062
|
-
function startTrackValue(element) {
|
|
2063
|
-
if (!isReact17Element(element)) return;
|
|
2064
|
-
element[TrackChanges] = {
|
|
2065
|
-
previousValue: String(element.value),
|
|
2066
|
-
tracked: []
|
|
2067
|
-
};
|
|
2068
|
-
}
|
|
2069
|
-
function trackOrSetValue(element, v) {
|
|
2070
|
-
element[TrackChanges]?.tracked?.push(v);
|
|
2071
|
-
if (!element[TrackChanges]) {
|
|
2072
|
-
setUIValueClean(element);
|
|
2073
|
-
setUISelection(element, { focusOffset: v.length });
|
|
2074
|
-
}
|
|
2075
|
-
}
|
|
2076
|
-
function commitValueAfterInput(element, cursorOffset) {
|
|
2077
|
-
const changes = element[TrackChanges];
|
|
2078
|
-
element[TrackChanges] = void 0;
|
|
2079
|
-
if (!changes?.tracked?.length) return;
|
|
2080
|
-
const isJustReactStateUpdate = changes.tracked.length === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === element.value;
|
|
2081
|
-
if (!isJustReactStateUpdate) setUIValueClean(element);
|
|
2082
|
-
if (hasUISelection(element)) setUISelection(element, { focusOffset: isJustReactStateUpdate ? cursorOffset : element.value.length });
|
|
2083
|
-
}
|
|
2084
|
-
|
|
2085
|
-
// src/event/selection/getTargetTypeAndSelection.ts
|
|
2086
|
-
/**
|
|
2087
|
-
* Determine which selection logic and selection ranges to consider.
|
|
2088
|
-
*/
|
|
2089
|
-
function getTargetTypeAndSelection(node) {
|
|
2090
|
-
const element = getElement(node);
|
|
2091
|
-
if (element && hasOwnSelection(element)) return {
|
|
2092
|
-
type: "input",
|
|
2093
|
-
selection: getUISelection(element)
|
|
2094
|
-
};
|
|
2095
|
-
const selection = element?.ownerDocument.getSelection();
|
|
2096
|
-
return {
|
|
2097
|
-
type: getContentEditable(node) && selection?.anchorNode && getContentEditable(selection.anchorNode) ? "contenteditable" : "default",
|
|
2098
|
-
selection
|
|
2099
|
-
};
|
|
2100
|
-
}
|
|
2101
|
-
function getElement(node) {
|
|
2102
|
-
return node.nodeType === 1 ? node : node.parentElement;
|
|
2103
|
-
}
|
|
2104
|
-
|
|
2105
|
-
// src/event/selection/getInputRange.ts
|
|
2106
|
-
/**
|
|
2107
|
-
* Get the range that would be overwritten by input.
|
|
2108
|
-
*/
|
|
2109
|
-
function getInputRange(focusNode) {
|
|
2110
|
-
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
2111
|
-
if (typeAndSelection.type === "input") return typeAndSelection.selection;
|
|
2112
|
-
else if (typeAndSelection.type === "contenteditable") return typeAndSelection.selection?.getRangeAt(0);
|
|
2113
|
-
}
|
|
2114
|
-
|
|
2115
|
-
// src/event/selection/setSelection.ts
|
|
2116
|
-
/**
|
|
2117
|
-
* Set the selection
|
|
2118
|
-
*/
|
|
2119
|
-
function setSelection({ focusNode, focusOffset, anchorNode = focusNode, anchorOffset = focusOffset }) {
|
|
2120
|
-
if (getTargetTypeAndSelection(focusNode).type === "input") return setUISelection(focusNode, {
|
|
2121
|
-
anchorOffset,
|
|
2122
|
-
focusOffset
|
|
2123
|
-
});
|
|
2124
|
-
anchorNode.ownerDocument?.getSelection()?.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
2125
|
-
}
|
|
2126
|
-
|
|
2127
|
-
// src/event/selection/moveSelection.ts
|
|
2128
|
-
/**
|
|
2129
|
-
* Move the selection
|
|
2130
|
-
*/
|
|
2131
|
-
function moveSelection(node, direction) {
|
|
2132
|
-
if (hasOwnSelection(node)) {
|
|
2133
|
-
const selection = getUISelection(node);
|
|
2134
|
-
setSelection({
|
|
2135
|
-
focusNode: node,
|
|
2136
|
-
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + direction : direction < 0 ? selection.startOffset : selection.endOffset
|
|
2137
|
-
});
|
|
2138
|
-
} else {
|
|
2139
|
-
const selection = node.ownerDocument.getSelection();
|
|
2140
|
-
if (!selection?.focusNode) return;
|
|
2141
|
-
if (selection.isCollapsed) {
|
|
2142
|
-
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, direction);
|
|
2143
|
-
if (nextPosition) setSelection({
|
|
2144
|
-
focusNode: nextPosition.node,
|
|
2145
|
-
focusOffset: nextPosition.offset
|
|
2146
|
-
});
|
|
2147
|
-
} else selection[direction < 0 ? "collapseToStart" : "collapseToEnd"]();
|
|
2148
|
-
}
|
|
2149
|
-
}
|
|
2150
|
-
|
|
2151
|
-
// src/event/selection/resolveCaretPosition.ts
|
|
2152
|
-
function resolveCaretPosition({ target, node, offset }) {
|
|
2153
|
-
if (hasOwnSelection(target)) return {
|
|
2154
|
-
node: target,
|
|
2155
|
-
offset: offset ?? getUIValue(target).length
|
|
2156
|
-
};
|
|
2157
|
-
else if (node) return {
|
|
2158
|
-
node,
|
|
2159
|
-
offset: offset ?? (node.nodeType === 3 ? node.nodeValue.length : node.childNodes.length)
|
|
2160
|
-
};
|
|
2161
|
-
return findNodeAtTextOffset(target, offset);
|
|
2162
|
-
}
|
|
2163
|
-
function findNodeAtTextOffset(node, offset, isRoot = true) {
|
|
2164
|
-
let i = offset === void 0 ? node.childNodes.length - 1 : 0;
|
|
2165
|
-
const step = offset === void 0 ? -1 : 1;
|
|
2166
|
-
while (offset === void 0 ? i >= (isRoot ? Math.max(node.childNodes.length - 1, 0) : 0) : i <= node.childNodes.length) {
|
|
2167
|
-
if (offset && i === node.childNodes.length) throw new Error("The given offset is out of bounds.");
|
|
2168
|
-
const c = node.childNodes.item(i);
|
|
2169
|
-
const text = String(c.textContent);
|
|
2170
|
-
if (text.length) {
|
|
2171
|
-
if (offset !== void 0 && text.length < offset) offset -= text.length;
|
|
2172
|
-
else if (c.nodeType === 1) return findNodeAtTextOffset(c, offset, false);
|
|
2173
|
-
else if (c.nodeType === 3) return {
|
|
2174
|
-
node: c,
|
|
2175
|
-
offset: offset ?? c.nodeValue.length
|
|
2176
|
-
};
|
|
2177
|
-
}
|
|
2178
|
-
i += step;
|
|
2179
|
-
}
|
|
2180
|
-
return {
|
|
2181
|
-
node,
|
|
2182
|
-
offset: node.childNodes.length
|
|
2183
|
-
};
|
|
2184
|
-
}
|
|
2185
|
-
|
|
2186
|
-
// src/event/selection/setSelectionPerMouse.ts
|
|
2187
|
-
function setSelectionPerMouseDown({ document, target, clickCount, node, offset }) {
|
|
2188
|
-
if (hasNoSelection(target)) return;
|
|
2189
|
-
const targetHasOwnSelection = hasOwnSelection(target);
|
|
2190
|
-
const text = String(targetHasOwnSelection ? getUIValue(target) : target.textContent);
|
|
2191
|
-
const [start, end] = node ? [offset, offset] : getTextRange(text, offset, clickCount);
|
|
2192
|
-
if (targetHasOwnSelection) {
|
|
2193
|
-
setUISelection(target, {
|
|
2194
|
-
anchorOffset: start ?? text.length,
|
|
2195
|
-
focusOffset: end ?? text.length
|
|
2196
|
-
});
|
|
2197
|
-
return {
|
|
2198
|
-
node: target,
|
|
2199
|
-
start: start ?? 0,
|
|
2200
|
-
end: end ?? text.length
|
|
2201
|
-
};
|
|
2202
|
-
} else {
|
|
2203
|
-
const { node: startNode, offset: startOffset } = resolveCaretPosition({
|
|
2204
|
-
target,
|
|
2205
|
-
node,
|
|
2206
|
-
offset: start
|
|
2207
|
-
});
|
|
2208
|
-
const { node: endNode, offset: endOffset } = resolveCaretPosition({
|
|
2209
|
-
target,
|
|
2210
|
-
node,
|
|
2211
|
-
offset: end
|
|
2212
|
-
});
|
|
2213
|
-
const range = target.ownerDocument.createRange();
|
|
2214
|
-
try {
|
|
2215
|
-
range.setStart(startNode, startOffset);
|
|
2216
|
-
range.setEnd(endNode, endOffset);
|
|
2217
|
-
} catch {
|
|
2218
|
-
throw new Error("The given offset is out of bounds.");
|
|
2219
|
-
}
|
|
2220
|
-
const selection = document.getSelection();
|
|
2221
|
-
selection?.removeAllRanges();
|
|
2222
|
-
selection?.addRange(range.cloneRange());
|
|
2223
|
-
return range;
|
|
2224
|
-
}
|
|
2225
|
-
}
|
|
2226
|
-
function getTextRange(text, pos, clickCount) {
|
|
2227
|
-
if (clickCount % 3 === 1 || text.length === 0) return [pos, pos];
|
|
2228
|
-
const textPos = pos ?? text.length;
|
|
2229
|
-
if (clickCount % 3 === 2) return [textPos - text.substr(0, pos).match(/(\w+|\s+|\W)?$/)[0].length, pos === void 0 ? pos : pos + text.substr(pos).match(/^(\w+|\s+|\W)?/)[0].length];
|
|
2230
|
-
return [textPos - text.substr(0, pos).match(/[^\r\n]*$/)[0].length, pos === void 0 ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length];
|
|
2231
|
-
}
|
|
2232
|
-
|
|
2233
|
-
// src/event/selection/modifySelectionPerMouse.ts
|
|
2234
|
-
function modifySelectionPerMouseMove(selectionRange, { document, target, node, offset }) {
|
|
2235
|
-
const selectionFocus = resolveCaretPosition({
|
|
2236
|
-
target,
|
|
2237
|
-
node,
|
|
2238
|
-
offset
|
|
2239
|
-
});
|
|
2240
|
-
if ("node" in selectionRange) {
|
|
2241
|
-
/* istanbul ignore else */
|
|
2242
|
-
if (selectionFocus.node === selectionRange.node) {
|
|
2243
|
-
const anchorOffset = selectionFocus.offset < selectionRange.start ? selectionRange.end : selectionRange.start;
|
|
2244
|
-
const focusOffset = selectionFocus.offset > selectionRange.end || selectionFocus.offset < selectionRange.start ? selectionFocus.offset : selectionRange.end;
|
|
2245
|
-
setUISelection(selectionRange.node, {
|
|
2246
|
-
anchorOffset,
|
|
2247
|
-
focusOffset
|
|
2248
|
-
});
|
|
2249
|
-
}
|
|
2250
|
-
} else {
|
|
2251
|
-
const range = selectionRange.cloneRange();
|
|
2252
|
-
const cmp = range.comparePoint(selectionFocus.node, selectionFocus.offset);
|
|
2253
|
-
if (cmp < 0) range.setStart(selectionFocus.node, selectionFocus.offset);
|
|
2254
|
-
else if (cmp > 0) range.setEnd(selectionFocus.node, selectionFocus.offset);
|
|
2255
|
-
const selection = document.getSelection();
|
|
2256
|
-
selection?.removeAllRanges();
|
|
2257
|
-
selection?.addRange(range.cloneRange());
|
|
2258
|
-
}
|
|
2259
|
-
}
|
|
2260
|
-
|
|
2261
|
-
// src/event/selection/selectAll.ts
|
|
2262
|
-
/**
|
|
2263
|
-
* Expand a selection like the browser does when pressing Ctrl+A.
|
|
2264
|
-
*/
|
|
2265
|
-
function selectAll(target) {
|
|
2266
|
-
if (hasOwnSelection(target)) return setSelection({
|
|
2267
|
-
focusNode: target,
|
|
2268
|
-
anchorOffset: 0,
|
|
2269
|
-
focusOffset: getUIValue(target).length
|
|
2270
|
-
});
|
|
2271
|
-
const focusNode = getContentEditable(target) ?? target.ownerDocument.body;
|
|
2272
|
-
setSelection({
|
|
2273
|
-
focusNode,
|
|
2274
|
-
anchorOffset: 0,
|
|
2275
|
-
focusOffset: focusNode.childNodes.length
|
|
2276
|
-
});
|
|
2277
|
-
}
|
|
2278
|
-
function isAllSelected(target) {
|
|
2279
|
-
if (hasOwnSelection(target)) return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
|
|
2280
|
-
const focusNode = getContentEditable(target) ?? target.ownerDocument.body;
|
|
2281
|
-
const selection = target.ownerDocument.getSelection();
|
|
2282
|
-
return selection?.anchorNode === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
2283
|
-
}
|
|
2284
|
-
|
|
2285
|
-
// src/event/selection/setSelectionRange.ts
|
|
2286
|
-
/**
|
|
2287
|
-
* Backward-compatible selection.
|
|
2288
|
-
*
|
|
2289
|
-
* Handles input elements and contenteditable if it only contains a single text node.
|
|
2290
|
-
*/
|
|
2291
|
-
function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
2292
|
-
if (hasOwnSelection(element)) return setSelection({
|
|
2293
|
-
focusNode: element,
|
|
2294
|
-
anchorOffset,
|
|
2295
|
-
focusOffset
|
|
2296
|
-
});
|
|
2297
|
-
/* istanbul ignore else */
|
|
2298
|
-
if (isContentEditable(element) && element.firstChild?.nodeType === 3) return setSelection({
|
|
2299
|
-
focusNode: element.firstChild,
|
|
2300
|
-
anchorOffset,
|
|
2301
|
-
focusOffset
|
|
2302
|
-
});
|
|
2303
|
-
/* istanbul ignore next */
|
|
2304
|
-
throw new Error("Not implemented. The result of this interaction is unreliable.");
|
|
2305
|
-
}
|
|
2306
|
-
|
|
2307
|
-
// src/event/selection/updateSelectionOnFocus.ts
|
|
2308
|
-
/**
|
|
2309
|
-
* Reset the Document Selection when moving focus into an element
|
|
2310
|
-
* with own selection implementation.
|
|
2311
|
-
*/
|
|
2312
|
-
function updateSelectionOnFocus(element) {
|
|
2313
|
-
const selection = element.ownerDocument.getSelection();
|
|
2314
|
-
/* istanbul ignore if */
|
|
2315
|
-
if (!selection?.focusNode) return;
|
|
2316
|
-
if (hasOwnSelection(element)) {
|
|
2317
|
-
const contenteditable = getContentEditable(selection.focusNode);
|
|
2318
|
-
if (contenteditable) {
|
|
2319
|
-
if (!selection.isCollapsed) {
|
|
2320
|
-
const focusNode = contenteditable.firstChild?.nodeType === 3 ? contenteditable.firstChild : contenteditable;
|
|
2321
|
-
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
2322
|
-
}
|
|
2323
|
-
} else selection.setBaseAndExtent(element, 0, element, 0);
|
|
2324
|
-
}
|
|
2325
|
-
}
|
|
2326
|
-
|
|
2327
|
-
// src/setup/dtl.ts
|
|
2328
|
-
const defaultConfig = {
|
|
2329
|
-
asyncWrapper: async (cb) => cb(),
|
|
2330
|
-
eventWrapper: (cb) => cb(),
|
|
2331
|
-
getElementError(message) {
|
|
2332
|
-
const error = new Error(message ?? "");
|
|
2333
|
-
error.name = "TestingLibraryElementError";
|
|
2334
|
-
return error;
|
|
2335
|
-
}
|
|
2336
|
-
};
|
|
2337
|
-
function load(mod) {
|
|
2338
|
-
const getConfig = mod.getConfig ?? mod.default?.getConfig;
|
|
2339
|
-
const configure = mod.configure ?? mod.default?.configure;
|
|
2340
|
-
return typeof getConfig === "function" && typeof configure === "function" ? {
|
|
2341
|
-
getConfig,
|
|
2342
|
-
configure
|
|
2343
|
-
} : null;
|
|
2344
|
-
}
|
|
2345
|
-
const dtl = load(ctrlDomTestingLibrary);
|
|
2346
|
-
/**
|
|
2347
|
-
* Mixed setups: stock `@testing-library/react` configures stock `@testing-library/dom`, not
|
|
2348
|
-
* ours. When a React act environment is active (`IS_REACT_ACT_ENVIRONMENT`, which RTL sets),
|
|
2349
|
-
* @ctrl/dom/testing-library's `asyncWrapper` is still its default (no @ctrl/dom adapter configured it)
|
|
2350
|
-
* and a *different* `@testing-library/dom` instance is importable, user-event reads that
|
|
2351
|
-
* one's config instead, so stock RTL's `act()` wrapping applies. The import is dynamic (no
|
|
2352
|
-
* top-level await: the package must stay loadable with `require()`), triggered at the first
|
|
2353
|
-
* API call; when `@testing-library/dom` is aliased to @ctrl/dom/testing-library it resolves to the
|
|
2354
|
-
* same module and nothing changes. Plain DOM tests never load anything.
|
|
2355
|
-
*/
|
|
2356
|
-
let fallback = null;
|
|
2357
|
-
let fallbackLoad = null;
|
|
2358
|
-
let fallbackSettled = false;
|
|
2359
|
-
let lastWrapper = null;
|
|
2360
|
-
let lastWrapperIsDefault = false;
|
|
2361
|
-
/**
|
|
2362
|
-
* DTL's default `asyncWrapper` is `(cb) => cb()`; adapters replace it with an act() wrapper.
|
|
2363
|
-
* Checked at every API call, so the answer for the current function is memoized (it is
|
|
2364
|
-
* replaced only by `configure()`).
|
|
2365
|
-
*/
|
|
2366
|
-
function isDefaultWrapper(fn) {
|
|
2367
|
-
if (fn === lastWrapper) return lastWrapperIsDefault;
|
|
2368
|
-
lastWrapper = fn;
|
|
2369
|
-
lastWrapperIsDefault = typeof fn === "function" && /^\(?(\w+)\)?=>\1\(\)$/.test(String(fn).replace(/\s/g, ""));
|
|
2370
|
-
return lastWrapperIsDefault;
|
|
2371
|
-
}
|
|
2372
|
-
function ownConfigured() {
|
|
2373
|
-
return dtl === null || !isDefaultWrapper(dtl.getConfig().asyncWrapper);
|
|
2374
|
-
}
|
|
2375
|
-
function reactActEnvironment() {
|
|
2376
|
-
return globalThis.IS_REACT_ACT_ENVIRONMENT === true;
|
|
2377
|
-
}
|
|
2378
|
-
/**
|
|
2379
|
-
* The `@testing-library/dom` that the project's `@testing-library/react` uses (resolved from the
|
|
2380
|
-
* working directory), not one next to this package: a different copy has a different config.
|
|
2381
|
-
*/
|
|
2382
|
-
function resolveFromProject(specifier) {
|
|
2383
|
-
try {
|
|
2384
|
-
const cwd = typeof process === "object" ? process.cwd() : ".";
|
|
2385
|
-
let base = cwd;
|
|
2386
|
-
try {
|
|
2387
|
-
const rtl = __require.resolve("@testing-library/react", { paths: [cwd] });
|
|
2388
|
-
base = rtl.slice(0, Math.max(rtl.lastIndexOf("/"), rtl.lastIndexOf("\\")));
|
|
2389
|
-
} catch {}
|
|
2390
|
-
return __require.resolve(specifier, { paths: [base] });
|
|
2391
|
-
} catch {
|
|
2392
|
-
return specifier;
|
|
2393
|
-
}
|
|
2394
|
-
}
|
|
2395
|
-
function loadFallback() {
|
|
2396
|
-
const specifier = "@testing-library/dom";
|
|
2397
|
-
return (typeof __require === "function" ? new Promise((resolve) => resolve(__require(resolveFromProject(specifier)))) : import(specifier)).then((m) => {
|
|
2398
|
-
const other = load(m);
|
|
2399
|
-
if (other !== null && other.getConfig !== dtl?.getConfig) fallback = other;
|
|
2400
|
-
}, () => {}).finally(() => {
|
|
2401
|
-
fallbackSettled = true;
|
|
2402
|
-
});
|
|
2403
|
-
}
|
|
2404
|
-
/**
|
|
2405
|
-
* A promise to await before the first API call of a mixed setup; undefined otherwise (and on
|
|
2406
|
-
* every later call, so calls stay synchronous up to their first await, like upstream).
|
|
2407
|
-
*/
|
|
2408
|
-
function resolveConfigSource() {
|
|
2409
|
-
if (fallbackSettled || ownConfigured() || !reactActEnvironment()) return void 0;
|
|
2410
|
-
fallbackLoad ??= loadFallback();
|
|
2411
|
-
return fallbackLoad;
|
|
2412
|
-
}
|
|
2413
|
-
const ownGetConfig = dtl ? dtl.getConfig : () => defaultConfig;
|
|
2414
|
-
function getConfig() {
|
|
2415
|
-
if (fallback !== null && !ownConfigured()) return fallback.getConfig();
|
|
2416
|
-
return ownGetConfig();
|
|
2417
|
-
}
|
|
2418
|
-
|
|
2419
|
-
// src/event/wrapEvent.ts
|
|
2420
|
-
function wrapEvent(cb, _element) {
|
|
2421
|
-
return getConfig().eventWrapper(cb);
|
|
2422
|
-
}
|
|
2423
|
-
|
|
2424
|
-
// src/event/focus.ts
|
|
2425
|
-
/**
|
|
2426
|
-
* Focus closest focusable element.
|
|
2427
|
-
*/
|
|
2428
|
-
function focusElement(element) {
|
|
2429
|
-
const target = findClosest(element, isFocusable);
|
|
2430
|
-
const activeElement = getActiveElement(element.ownerDocument);
|
|
2431
|
-
if ((target ?? element.ownerDocument.body) === activeElement) return;
|
|
2432
|
-
else if (target) wrapEvent(() => target.focus(), element);
|
|
2433
|
-
else wrapEvent(() => activeElement?.blur(), element);
|
|
2434
|
-
updateSelectionOnFocus(target ?? element.ownerDocument.body);
|
|
2435
|
-
}
|
|
2436
|
-
function blurElement(element) {
|
|
2437
|
-
if (!isFocusable(element)) return;
|
|
2438
|
-
if (!(getActiveElement(element.ownerDocument) === element)) return;
|
|
2439
|
-
wrapEvent(() => element.blur(), element);
|
|
2440
|
-
}
|
|
2441
|
-
|
|
2442
|
-
// src/event/behavior/registry.ts
|
|
2443
|
-
const behavior = {};
|
|
2444
|
-
|
|
2445
|
-
// src/event/behavior/click.ts
|
|
2446
|
-
behavior.click = (event, target, instance) => {
|
|
2447
|
-
const context = target.closest("button,input,label,select,textarea");
|
|
2448
|
-
const control = context && isElementType(context, "label") && context.control;
|
|
2449
|
-
if (control && control !== target) return () => {
|
|
2450
|
-
if (isFocusable(control)) {
|
|
2451
|
-
focusElement(control);
|
|
2452
|
-
instance.dispatchEvent(control, cloneEvent(event));
|
|
2453
|
-
}
|
|
2454
|
-
};
|
|
2455
|
-
else if (isElementType(target, "input", { type: "file" })) return () => {
|
|
2456
|
-
blurElement(target);
|
|
2457
|
-
target.dispatchEvent(new (getWindow(target)).Event("fileDialog"));
|
|
2458
|
-
focusElement(target);
|
|
2459
|
-
};
|
|
2460
|
-
};
|
|
2461
|
-
|
|
2462
|
-
// src/event/input.ts
|
|
2463
|
-
function isDateOrTime(element) {
|
|
2464
|
-
return isElementType(element, "input") && ["date", "time"].includes(element.type);
|
|
2465
|
-
}
|
|
2466
|
-
function input(instance, element, data, inputType = "insertText") {
|
|
2467
|
-
const inputRange = getInputRange(element);
|
|
2468
|
-
/* istanbul ignore if */
|
|
2469
|
-
if (!inputRange) return;
|
|
2470
|
-
if (!isDateOrTime(element)) {
|
|
2471
|
-
if (!instance.dispatchUIEvent(element, "beforeinput", {
|
|
2472
|
-
inputType,
|
|
2473
|
-
data
|
|
2474
|
-
})) return;
|
|
2475
|
-
}
|
|
2476
|
-
if ("startContainer" in inputRange) editContenteditable(instance, element, inputRange, data, inputType);
|
|
2477
|
-
else editInputElement(instance, element, inputRange, data, inputType);
|
|
2478
|
-
}
|
|
2479
|
-
function editContenteditable(instance, element, inputRange, data, inputType) {
|
|
2480
|
-
let del = false;
|
|
2481
|
-
if (!inputRange.collapsed) {
|
|
2482
|
-
del = true;
|
|
2483
|
-
inputRange.deleteContents();
|
|
2484
|
-
} else if (["deleteContentBackward", "deleteContentForward"].includes(inputType)) {
|
|
2485
|
-
const nextPosition = getNextCursorPosition(inputRange.startContainer, inputRange.startOffset, inputType === "deleteContentBackward" ? -1 : 1, inputType);
|
|
2486
|
-
if (nextPosition) {
|
|
2487
|
-
del = true;
|
|
2488
|
-
const delRange = inputRange.cloneRange();
|
|
2489
|
-
if (delRange.comparePoint(nextPosition.node, nextPosition.offset) < 0) delRange.setStart(nextPosition.node, nextPosition.offset);
|
|
2490
|
-
else delRange.setEnd(nextPosition.node, nextPosition.offset);
|
|
2491
|
-
delRange.deleteContents();
|
|
2492
|
-
}
|
|
2493
|
-
}
|
|
2494
|
-
if (data) {
|
|
2495
|
-
if (inputRange.endContainer.nodeType === 3) {
|
|
2496
|
-
const offset = inputRange.endOffset;
|
|
2497
|
-
inputRange.endContainer.insertData(offset, data);
|
|
2498
|
-
inputRange.setStart(inputRange.endContainer, offset + data.length);
|
|
2499
|
-
inputRange.setEnd(inputRange.endContainer, offset + data.length);
|
|
2500
|
-
} else {
|
|
2501
|
-
const text = element.ownerDocument.createTextNode(data);
|
|
2502
|
-
inputRange.insertNode(text);
|
|
2503
|
-
inputRange.setStart(text, data.length);
|
|
2504
|
-
inputRange.setEnd(text, data.length);
|
|
2505
|
-
}
|
|
2506
|
-
}
|
|
2507
|
-
if (del || data) instance.dispatchUIEvent(element, "input", { inputType });
|
|
2508
|
-
}
|
|
2509
|
-
function editInputElement(instance, element, inputRange, data, inputType) {
|
|
2510
|
-
let dataToInsert = data;
|
|
2511
|
-
if (supportsMaxLength(element)) {
|
|
2512
|
-
const maxLength = getMaxLength(element);
|
|
2513
|
-
if (maxLength !== void 0 && data.length > 0) {
|
|
2514
|
-
const selectionLength = inputRange.endOffset - inputRange.startOffset;
|
|
2515
|
-
const spaceUntilMaxLength = maxLength - element.value.length + selectionLength;
|
|
2516
|
-
if (spaceUntilMaxLength > 0) dataToInsert = data.substring(0, spaceUntilMaxLength);
|
|
2517
|
-
else return;
|
|
2518
|
-
}
|
|
2519
|
-
}
|
|
2520
|
-
const { newValue, newOffset, oldValue } = calculateNewValue(dataToInsert, element, inputRange, inputType);
|
|
2521
|
-
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) return;
|
|
2522
|
-
if (isElementType(element, "input", { type: "number" }) && !isValidNumberInput(newValue)) return;
|
|
2523
|
-
setUIValue(element, newValue);
|
|
2524
|
-
setSelection({
|
|
2525
|
-
focusNode: element,
|
|
2526
|
-
anchorOffset: newOffset,
|
|
2527
|
-
focusOffset: newOffset
|
|
2528
|
-
});
|
|
2529
|
-
if (isDateOrTime(element)) {
|
|
2530
|
-
if (isValidDateOrTimeValue(element, newValue)) {
|
|
2531
|
-
commitInput(instance, element, newOffset, {});
|
|
2532
|
-
instance.dispatchUIEvent(element, "change");
|
|
2533
|
-
clearInitialValue(element);
|
|
2534
|
-
}
|
|
2535
|
-
} else commitInput(instance, element, newOffset, {
|
|
2536
|
-
data,
|
|
2537
|
-
inputType
|
|
2538
|
-
});
|
|
2539
|
-
}
|
|
2540
|
-
function calculateNewValue(inputData, node, { startOffset, endOffset }, inputType) {
|
|
2541
|
-
const value = getUIValue(node);
|
|
2542
|
-
const prologEnd = Math.max(0, startOffset === endOffset && inputType === "deleteContentBackward" ? startOffset - 1 : startOffset);
|
|
2543
|
-
const prolog = value.substring(0, prologEnd);
|
|
2544
|
-
const epilogStart = Math.min(value.length, startOffset === endOffset && inputType === "deleteContentForward" ? startOffset + 1 : endOffset);
|
|
2545
|
-
let newValue = `${prolog}${inputData}${value.substring(epilogStart, value.length)}`;
|
|
2546
|
-
let newOffset = prologEnd + inputData.length;
|
|
2547
|
-
if (isElementType(node, "input", { type: "time" })) {
|
|
2548
|
-
const builtValue = buildTimeValue(newValue);
|
|
2549
|
-
if (builtValue !== "" && isValidDateOrTimeValue(node, builtValue)) {
|
|
2550
|
-
newValue = builtValue;
|
|
2551
|
-
newOffset = builtValue.length;
|
|
2552
|
-
}
|
|
2553
|
-
}
|
|
2554
|
-
return {
|
|
2555
|
-
oldValue: value,
|
|
2556
|
-
newValue,
|
|
2557
|
-
newOffset
|
|
2558
|
-
};
|
|
2559
|
-
}
|
|
2560
|
-
function commitInput(instance, element, newOffset, inputInit) {
|
|
2561
|
-
instance.dispatchUIEvent(element, "input", inputInit);
|
|
2562
|
-
commitValueAfterInput(element, newOffset);
|
|
2563
|
-
}
|
|
2564
|
-
function isValidNumberInput(value) {
|
|
2565
|
-
const valueParts = value.split("e", 2);
|
|
2566
|
-
return !(/[^\d.\-e]/.test(value) || Number(value.match(/-/g)?.length) > 2 || Number(value.match(/\./g)?.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1]));
|
|
2567
|
-
}
|
|
2568
|
-
|
|
2569
|
-
// src/event/behavior/cut.ts
|
|
2570
|
-
behavior.cut = (event, target, instance) => {
|
|
2571
|
-
return () => {
|
|
2572
|
-
if (isEditable(target)) input(instance, target, "", "deleteByCut");
|
|
2573
|
-
};
|
|
2574
|
-
};
|
|
2575
|
-
|
|
2576
|
-
// src/event/radio.ts
|
|
2577
|
-
function walkRadio(instance, el, direction) {
|
|
2578
|
-
const window = getWindow(el);
|
|
2579
|
-
const group = Array.from(el.ownerDocument.querySelectorAll(el.name ? `input[type="radio"][name="${cssEscape(window, el.name)}"]` : `input[type="radio"][name=""], input[type="radio"]:not([name])`));
|
|
2580
|
-
for (let i = group.findIndex((e) => e === el) + direction;; i += direction) {
|
|
2581
|
-
if (!group[i]) i = direction > 0 ? 0 : group.length - 1;
|
|
2582
|
-
if (group[i] === el) return;
|
|
2583
|
-
if (isDisabled(group[i])) continue;
|
|
2584
|
-
focusElement(group[i]);
|
|
2585
|
-
instance.dispatchUIEvent(group[i], "click");
|
|
2586
|
-
return;
|
|
2587
|
-
}
|
|
2588
|
-
}
|
|
2589
|
-
/**
|
|
2590
|
-
* `CSS.escape` when the window provides it (upstream relies on it unconditionally; its test
|
|
2591
|
-
* environment polyfills it for jsdom), otherwise https://drafts.csswg.org/cssom/#serialize-an-identifier.
|
|
2592
|
-
*/
|
|
2593
|
-
function cssEscape(window, ident) {
|
|
2594
|
-
if (typeof window.CSS?.escape === "function") return window.CSS.escape(ident);
|
|
2595
|
-
let out = "";
|
|
2596
|
-
for (let i = 0; i < ident.length; i++) {
|
|
2597
|
-
const c = ident.charCodeAt(i);
|
|
2598
|
-
if (c === 0) out += "�";
|
|
2599
|
-
else if (c >= 1 && c <= 31 || c === 127 || i === 0 && c >= 48 && c <= 57 || i === 1 && c >= 48 && c <= 57 && ident.charCodeAt(0) === 45) out += `\\${c.toString(16)} `;
|
|
2600
|
-
else if (i === 0 && c === 45 && ident.length === 1) out += "\\-";
|
|
2601
|
-
else if (c >= 128 || c === 45 || c === 95 || c >= 48 && c <= 57 || c >= 65 && c <= 90 || c >= 97 && c <= 122) out += ident[i];
|
|
2602
|
-
else out += `\\${ident[i]}`;
|
|
2603
|
-
}
|
|
2604
|
-
return out;
|
|
2605
|
-
}
|
|
2606
|
-
|
|
2607
|
-
// src/event/behavior/keydown.ts
|
|
2608
|
-
behavior.keydown = (event, target, instance) => {
|
|
2609
|
-
return keydownBehavior[event.key]?.(event, target, instance) ?? combinationBehavior(event, target, instance);
|
|
2610
|
-
};
|
|
2611
|
-
const keydownBehavior = {
|
|
2612
|
-
ArrowDown: (event, target, instance) => {
|
|
2613
|
-
/* istanbul ignore else */
|
|
2614
|
-
if (isElementType(target, "input", { type: "radio" })) return () => walkRadio(instance, target, 1);
|
|
2615
|
-
},
|
|
2616
|
-
ArrowLeft: (event, target, instance) => {
|
|
2617
|
-
if (isElementType(target, "input", { type: "radio" })) return () => walkRadio(instance, target, -1);
|
|
2618
|
-
return () => moveSelection(target, -1);
|
|
2619
|
-
},
|
|
2620
|
-
ArrowRight: (event, target, instance) => {
|
|
2621
|
-
if (isElementType(target, "input", { type: "radio" })) return () => walkRadio(instance, target, 1);
|
|
2622
|
-
return () => moveSelection(target, 1);
|
|
2623
|
-
},
|
|
2624
|
-
ArrowUp: (event, target, instance) => {
|
|
2625
|
-
/* istanbul ignore else */
|
|
2626
|
-
if (isElementType(target, "input", { type: "radio" })) return () => walkRadio(instance, target, -1);
|
|
2627
|
-
},
|
|
2628
|
-
Backspace: (event, target, instance) => {
|
|
2629
|
-
if (isEditable(target)) return () => {
|
|
2630
|
-
input(instance, target, "", "deleteContentBackward");
|
|
2631
|
-
};
|
|
2632
|
-
},
|
|
2633
|
-
Delete: (event, target, instance) => {
|
|
2634
|
-
if (isEditable(target)) return () => {
|
|
2635
|
-
input(instance, target, "", "deleteContentForward");
|
|
2636
|
-
};
|
|
2637
|
-
},
|
|
2638
|
-
End: (event, target) => {
|
|
2639
|
-
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) return () => {
|
|
2640
|
-
const newPos = getValueOrTextContent(target)?.length ?? /* istanbul ignore next */ 0;
|
|
2641
|
-
setSelectionRange(target, newPos, newPos);
|
|
2642
|
-
};
|
|
2643
|
-
},
|
|
2644
|
-
Home: (event, target) => {
|
|
2645
|
-
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) return () => {
|
|
2646
|
-
setSelectionRange(target, 0, 0);
|
|
2647
|
-
};
|
|
2648
|
-
},
|
|
2649
|
-
PageDown: (event, target) => {
|
|
2650
|
-
if (isElementType(target, ["input"])) return () => {
|
|
2651
|
-
const newPos = getUIValue(target).length;
|
|
2652
|
-
setSelectionRange(target, newPos, newPos);
|
|
2653
|
-
};
|
|
2654
|
-
},
|
|
2655
|
-
PageUp: (event, target) => {
|
|
2656
|
-
if (isElementType(target, ["input"])) return () => {
|
|
2657
|
-
setSelectionRange(target, 0, 0);
|
|
2658
|
-
};
|
|
2659
|
-
},
|
|
2660
|
-
Tab: (event, target, instance) => {
|
|
2661
|
-
return () => {
|
|
2662
|
-
const dest = getTabDestination(getActiveElementOrBody(instance.config.document), instance.system.keyboard.modifiers.Shift);
|
|
2663
|
-
focusElement(dest);
|
|
2664
|
-
if (hasOwnSelection(dest)) setUISelection(dest, {
|
|
2665
|
-
anchorOffset: 0,
|
|
2666
|
-
focusOffset: dest.value.length
|
|
2667
|
-
});
|
|
2668
|
-
};
|
|
2669
|
-
}
|
|
2670
|
-
};
|
|
2671
|
-
const combinationBehavior = (event, target, instance) => {
|
|
2672
|
-
if (event.code === "KeyA" && instance.system.keyboard.modifiers.Control) return () => selectAll(target);
|
|
2673
|
-
};
|
|
2674
|
-
|
|
2675
|
-
// src/event/behavior/keypress.ts
|
|
2676
|
-
behavior.keypress = (event, target, instance) => {
|
|
2677
|
-
if (event.key === "Enter") {
|
|
2678
|
-
if (isElementType(target, "button") || isElementType(target, "input") && ClickInputOnEnter.includes(target.type) || isElementType(target, "a") && Boolean(target.href)) return () => {
|
|
2679
|
-
instance.dispatchUIEvent(target, "click");
|
|
2680
|
-
};
|
|
2681
|
-
else if (isElementType(target, "input")) {
|
|
2682
|
-
const form = target.form;
|
|
2683
|
-
const submit = form?.querySelector("input[type=\"submit\"], button:not([type]), button[type=\"submit\"]");
|
|
2684
|
-
if (submit) return () => instance.dispatchUIEvent(submit, "click");
|
|
2685
|
-
else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll("input").length === 1) return () => instance.dispatchUIEvent(form, "submit");
|
|
2686
|
-
else return;
|
|
2687
|
-
}
|
|
2688
|
-
}
|
|
2689
|
-
if (isEditable(target)) {
|
|
2690
|
-
const inputType = event.key === "Enter" ? isContentEditable(target) && !instance.system.keyboard.modifiers.Shift ? "insertParagraph" : "insertLineBreak" : "insertText";
|
|
2691
|
-
const inputData = event.key === "Enter" ? "\n" : event.key;
|
|
2692
|
-
return () => input(instance, target, inputData, inputType);
|
|
2693
|
-
}
|
|
2694
|
-
};
|
|
2695
|
-
const ClickInputOnEnter = [
|
|
2696
|
-
"button",
|
|
2697
|
-
"color",
|
|
2698
|
-
"file",
|
|
2699
|
-
"image",
|
|
2700
|
-
"reset",
|
|
2701
|
-
"submit"
|
|
2702
|
-
];
|
|
2703
|
-
const SubmitSingleInputOnEnter = [
|
|
2704
|
-
"email",
|
|
2705
|
-
"month",
|
|
2706
|
-
"password",
|
|
2707
|
-
"search",
|
|
2708
|
-
"tel",
|
|
2709
|
-
"text",
|
|
2710
|
-
"url",
|
|
2711
|
-
"week"
|
|
2712
|
-
];
|
|
2713
|
-
|
|
2714
|
-
// src/event/behavior/keyup.ts
|
|
2715
|
-
behavior.keyup = (event, target, instance) => {
|
|
2716
|
-
return keyupBehavior[event.key]?.(event, target, instance);
|
|
2717
|
-
};
|
|
2718
|
-
const keyupBehavior = { " ": (event, target, instance) => {
|
|
2719
|
-
if (isClickableInput(target)) return () => instance.dispatchUIEvent(target, "click");
|
|
2720
|
-
} };
|
|
2721
|
-
|
|
2722
|
-
// src/event/behavior/paste.ts
|
|
2723
|
-
behavior.paste = (event, target, instance) => {
|
|
2724
|
-
if (isEditable(target)) return () => {
|
|
2725
|
-
const insertData = event.clipboardData?.getData("text");
|
|
2726
|
-
if (insertData) input(instance, target, insertData, "insertFromPaste");
|
|
2727
|
-
};
|
|
2728
|
-
};
|
|
2729
|
-
|
|
2730
|
-
// src/event/createEvent.ts
|
|
2731
|
-
const eventInitializer = {
|
|
2732
|
-
ClipboardEvent: [initClipboardEvent],
|
|
2733
|
-
Event: [],
|
|
2734
|
-
FocusEvent: [initUIEvent, initFocusEvent],
|
|
2735
|
-
InputEvent: [initUIEvent, initInputEvent],
|
|
2736
|
-
MouseEvent: [
|
|
2737
|
-
initUIEvent,
|
|
2738
|
-
initUIEventModifiers,
|
|
2739
|
-
initMouseEvent
|
|
2740
|
-
],
|
|
2741
|
-
PointerEvent: [
|
|
2742
|
-
initUIEvent,
|
|
2743
|
-
initUIEventModifiers,
|
|
2744
|
-
initMouseEvent,
|
|
2745
|
-
initPointerEvent
|
|
2746
|
-
],
|
|
2747
|
-
KeyboardEvent: [
|
|
2748
|
-
initUIEvent,
|
|
2749
|
-
initUIEventModifiers,
|
|
2750
|
-
initKeyboardEvent
|
|
2751
|
-
]
|
|
2752
|
-
};
|
|
2753
|
-
function createEvent(type, target, init, modifiers) {
|
|
2754
|
-
const window = getWindow(target);
|
|
2755
|
-
const { EventType, defaultInit } = eventMap[type];
|
|
2756
|
-
const constructors = getEventConstructors(window);
|
|
2757
|
-
if (modifiers !== void 0 && (implOf(target) === null || constructors.fallbacks.has(EventType))) {
|
|
2758
|
-
const merged = { ...init };
|
|
2759
|
-
modifiers.assignUIEventModifiers(merged);
|
|
2760
|
-
init = merged;
|
|
2761
|
-
modifiers = void 0;
|
|
2762
|
-
}
|
|
2763
|
-
if (implOf(target) !== null && !constructors.fallbacks.has(EventType)) return createNativeEvent(constructors[EventType], EventType, type, defaultInit, init, modifiers);
|
|
2764
|
-
const event = new constructors[EventType](type, defaultInit);
|
|
2765
|
-
const initializers = eventInitializer[EventType];
|
|
2766
|
-
for (let i = 0; i < initializers.length; i++) initializers[i](event, init ?? {});
|
|
2767
|
-
return event;
|
|
2768
|
-
}
|
|
2769
|
-
/**
|
|
2770
|
-
* @ctrl/dom path: its event constructors implement the full UI Events / Pointer Events /
|
|
2771
|
-
* Input Events / Clipboard API init dictionaries, so the event is created in one constructor
|
|
2772
|
-
* call instead of upstream's ~20 `Object.defineProperty` overrides per event (which also turn
|
|
2773
|
-
* every event into a dictionary-mode object).
|
|
2774
|
-
*
|
|
2775
|
-
* Observable parity with upstream's `assignProps`:
|
|
2776
|
-
* - `bubbles`/`cancelable`/`composed` always come from the event map, never from `init`.
|
|
2777
|
-
* - Missing numeric members are 0, `pointerType` defaults to '', `width`/`height` to 1,
|
|
2778
|
-
* `pressure` to 0.5 while a button is pressed and 0 otherwise; a missing `inputType`,
|
|
2779
|
-
* `key` or `code` is the string "undefined" (upstream uses `String(value)`).
|
|
2780
|
-
* - `x`/`y` are aliases of `clientX`/`clientY` (natively so); the layout-dependent
|
|
2781
|
-
* `offsetX/offsetY/pageX/pageY` (not part of MouseEventInit) are set as own properties when
|
|
2782
|
-
* given, exactly like upstream; otherwise they keep the native values (0 without layout).
|
|
2783
|
-
*
|
|
2784
|
-
* TODO(user-event): re-verify against the events agent's final constructors (charCode on
|
|
2785
|
-
* KeyboardEventInit, modifier* members on EventModifierInit, clipboardData on ClipboardEventInit).
|
|
2786
|
-
*/
|
|
2787
|
-
function createNativeEvent(Ctor, eventInterface, type, defaultInit, init, modifiers) {
|
|
2788
|
-
const i = init ?? {};
|
|
2789
|
-
const dict = { ...i };
|
|
2790
|
-
modifiers?.assignUIEventModifiers(dict);
|
|
2791
|
-
dict.bubbles = defaultInit.bubbles;
|
|
2792
|
-
dict.cancelable = defaultInit.cancelable;
|
|
2793
|
-
dict.composed = defaultInit.composed;
|
|
2794
|
-
if (i.clientX === void 0 && i.x !== void 0) dict.clientX = i.x;
|
|
2795
|
-
if (i.clientY === void 0 && i.y !== void 0) dict.clientY = i.y;
|
|
2796
|
-
if (i.pressure === void 0) dict.pressure = i.buttons ? .5 : 0;
|
|
2797
|
-
if (eventInterface === "InputEvent" && i.inputType === void 0) dict.inputType = "undefined";
|
|
2798
|
-
if (eventInterface === "KeyboardEvent") {
|
|
2799
|
-
if (i.key === void 0) dict.key = "undefined";
|
|
2800
|
-
if (i.code === void 0) dict.code = "undefined";
|
|
2801
|
-
}
|
|
2802
|
-
const event = new Ctor(type, dict);
|
|
2803
|
-
if (i.offsetX !== void 0) Object.defineProperty(event, "offsetX", { value: Number(i.offsetX) });
|
|
2804
|
-
if (i.offsetY !== void 0) Object.defineProperty(event, "offsetY", { value: Number(i.offsetY) });
|
|
2805
|
-
if (i.pageX !== void 0) Object.defineProperty(event, "pageX", { value: Number(i.pageX) });
|
|
2806
|
-
if (i.pageY !== void 0) Object.defineProperty(event, "pageY", { value: Number(i.pageY) });
|
|
2807
|
-
return event;
|
|
2808
|
-
}
|
|
2809
|
-
const constructorCache = /* @__PURE__ */ new WeakMap();
|
|
2810
|
-
function getEventConstructors(window) {
|
|
2811
|
-
let constructors = constructorCache.get(window);
|
|
2812
|
-
if (constructors === void 0) {
|
|
2813
|
-
constructors = buildEventConstructors(window);
|
|
2814
|
-
constructorCache.set(window, constructors);
|
|
2815
|
-
}
|
|
2816
|
-
return constructors;
|
|
2817
|
-
}
|
|
30
|
+
if(isElementType(t,`input`,{type:`radio`}))return()=>walkRadio(n,t,-1)},Backspace:(e,t,n)=>{if(isEditable(t))return()=>{input(n,t,``,`deleteContentBackward`)}},Delete:(e,t,n)=>{if(isEditable(t))return()=>{input(n,t,``,`deleteContentForward`)}},End:(e,t)=>{if(isElementType(t,[`input`,`textarea`])||isContentEditable(t))return()=>{let e=getValueOrTextContent(t)?.length??/* istanbul ignore next */0;setSelectionRange(t,e,e)}},Home:(e,t)=>{if(isElementType(t,[`input`,`textarea`])||isContentEditable(t))return()=>{setSelectionRange(t,0,0)}},PageDown:(e,t)=>{if(isElementType(t,[`input`]))return()=>{let e=getUIValue(t).length;setSelectionRange(t,e,e)}},PageUp:(e,t)=>{if(isElementType(t,[`input`]))return()=>{setSelectionRange(t,0,0)}},Tab:(e,t,n)=>()=>{let e=getTabDestination(getActiveElementOrBody(n.config.document),n.system.keyboard.modifiers.Shift);focusElement(e),hasOwnSelection(e)&&setUISelection(e,{anchorOffset:0,focusOffset:e.value.length})}},combinationBehavior=(e,t,n)=>{if(e.code===`KeyA`&&n.system.keyboard.modifiers.Control)return()=>selectAll(t)};G.keypress=(e,t,n)=>{if(e.key===`Enter`){if(isElementType(t,`button`)||isElementType(t,`input`)&&se.includes(t.type)||isElementType(t,`a`)&&t.href)return()=>{n.dispatchUIEvent(t,`click`)};if(isElementType(t,`input`)){let e=t.form,r=e?.querySelector(`input[type="submit"], button:not([type]), button[type="submit"]`);return r?()=>n.dispatchUIEvent(r,`click`):e&&ce.includes(t.type)&&e.querySelectorAll(`input`).length===1?()=>n.dispatchUIEvent(e,`submit`):void 0}}if(isEditable(t)){let r=e.key===`Enter`?isContentEditable(t)&&!n.system.keyboard.modifiers.Shift?`insertParagraph`:`insertLineBreak`:`insertText`,i=e.key===`Enter`?`
|
|
31
|
+
`:e.key;return()=>input(n,t,i,r)}};const se=[`button`,`color`,`file`,`image`,`reset`,`submit`],ce=[`email`,`month`,`password`,`search`,`tel`,`text`,`url`,`week`];G.keyup=(e,t,n)=>le[e.key]?.(e,t,n);const le={" ":(e,t,n)=>{if(isClickableInput(t))return()=>n.dispatchUIEvent(t,`click`)}};G.paste=(e,t,n)=>{if(isEditable(t))return()=>{let r=e.clipboardData?.getData(`text`);r&&input(n,t,r,`insertFromPaste`)}};const ue={ClipboardEvent:[initClipboardEvent],Event:[],FocusEvent:[initUIEvent,initFocusEvent],InputEvent:[initUIEvent,initInputEvent],MouseEvent:[initUIEvent,initUIEventModifiers,initMouseEvent],PointerEvent:[initUIEvent,initUIEventModifiers,initMouseEvent,initPointerEvent],KeyboardEvent:[initUIEvent,initUIEventModifiers,initKeyboardEvent]};function createEvent(e,t,n,r){let i=getWindow(t),{EventType:a,defaultInit:o}=l[e],s=getEventConstructors(i);if(r!==void 0&&(implOf(t)===null||s.fallbacks.has(a))){let e={...n};r.assignUIEventModifiers(e),n=e,r=void 0}if(implOf(t)!==null&&!s.fallbacks.has(a))return createNativeEvent(s[a],a,e,o,n,r);let c=new s[a](e,o),u=ue[a];for(let e=0;e<u.length;e++)u[e](c,n??{});return c}function createNativeEvent(e,t,n,r,i,a){let o=i??{},s={...o};a?.assignUIEventModifiers(s),s.bubbles=r.bubbles,s.cancelable=r.cancelable,s.composed=r.composed,o.clientX===void 0&&o.x!==void 0&&(s.clientX=o.x),o.clientY===void 0&&o.y!==void 0&&(s.clientY=o.y),o.pressure===void 0&&(s.pressure=o.buttons?.5:0),t===`InputEvent`&&o.inputType===void 0&&(s.inputType=`undefined`),t===`KeyboardEvent`&&(o.key===void 0&&(s.key=`undefined`),o.code===void 0&&(s.code=`undefined`));let c=new e(n,s);return o.offsetX!==void 0&&Object.defineProperty(c,"offsetX",{value:Number(o.offsetX)}),o.offsetY!==void 0&&Object.defineProperty(c,"offsetY",{value:Number(o.offsetY)}),o.pageX!==void 0&&Object.defineProperty(c,"pageX",{value:Number(o.pageX)}),o.pageY!==void 0&&Object.defineProperty(c,"pageY",{value:Number(o.pageY)}),c}const K=/* @__PURE__ */ new WeakMap;function getEventConstructors(e){let t=K.get(e);return t===void 0&&(t=buildEventConstructors(e),K.set(e,t)),t}
|
|
2818
32
|
/* istanbul ignore next */
|
|
2819
|
-
function buildEventConstructors(
|
|
2820
|
-
|
|
2821
|
-
for (const name of [
|
|
2822
|
-
|
|
2823
|
-
"AnimationEvent",
|
|
2824
|
-
"ClipboardEvent",
|
|
2825
|
-
"PopStateEvent",
|
|
2826
|
-
"ProgressEvent",
|
|
2827
|
-
"TransitionEvent",
|
|
2828
|
-
"UIEvent",
|
|
2829
|
-
"CompositionEvent",
|
|
2830
|
-
"FocusEvent",
|
|
2831
|
-
"InputEvent",
|
|
2832
|
-
"KeyboardEvent",
|
|
2833
|
-
"MouseEvent",
|
|
2834
|
-
"DragEvent",
|
|
2835
|
-
"PointerEvent",
|
|
2836
|
-
"TouchEvent"
|
|
2837
|
-
]) if (window[name] === void 0) fallbacks.add(name);
|
|
2838
|
-
const Event = window.Event ?? class Event {};
|
|
2839
|
-
const AnimationEvent = window.AnimationEvent ?? class AnimationEvent extends Event {};
|
|
2840
|
-
const ClipboardEvent = window.ClipboardEvent ?? class ClipboardEvent extends Event {};
|
|
2841
|
-
const PopStateEvent = window.PopStateEvent ?? class PopStateEvent extends Event {};
|
|
2842
|
-
const ProgressEvent = window.ProgressEvent ?? class ProgressEvent extends Event {};
|
|
2843
|
-
const TransitionEvent = window.TransitionEvent ?? class TransitionEvent extends Event {};
|
|
2844
|
-
const UIEvent = window.UIEvent ?? class UIEvent extends Event {};
|
|
2845
|
-
const CompositionEvent = window.CompositionEvent ?? class CompositionEvent extends UIEvent {};
|
|
2846
|
-
const FocusEvent = window.FocusEvent ?? class FocusEvent extends UIEvent {};
|
|
2847
|
-
const InputEvent = window.InputEvent ?? class InputEvent extends UIEvent {};
|
|
2848
|
-
const KeyboardEvent = window.KeyboardEvent ?? class KeyboardEvent extends UIEvent {};
|
|
2849
|
-
const MouseEvent = window.MouseEvent ?? class MouseEvent extends UIEvent {};
|
|
2850
|
-
return {
|
|
2851
|
-
fallbacks,
|
|
2852
|
-
Event,
|
|
2853
|
-
AnimationEvent,
|
|
2854
|
-
ClipboardEvent,
|
|
2855
|
-
PopStateEvent,
|
|
2856
|
-
ProgressEvent,
|
|
2857
|
-
TransitionEvent,
|
|
2858
|
-
UIEvent,
|
|
2859
|
-
CompositionEvent,
|
|
2860
|
-
FocusEvent,
|
|
2861
|
-
InputEvent,
|
|
2862
|
-
KeyboardEvent,
|
|
2863
|
-
MouseEvent,
|
|
2864
|
-
DragEvent: window.DragEvent ?? class DragEvent extends MouseEvent {},
|
|
2865
|
-
PointerEvent: window.PointerEvent ?? class PointerEvent extends MouseEvent {},
|
|
2866
|
-
TouchEvent: window.TouchEvent ?? class TouchEvent extends UIEvent {}
|
|
2867
|
-
};
|
|
2868
|
-
}
|
|
2869
|
-
function assignProps(obj, props) {
|
|
2870
|
-
for (const [key, value] of Object.entries(props)) Object.defineProperty(obj, key, { get: () => value ?? null });
|
|
2871
|
-
}
|
|
2872
|
-
function sanitizeNumber(n) {
|
|
2873
|
-
return Number(n ?? 0);
|
|
2874
|
-
}
|
|
2875
|
-
function initClipboardEvent(event, { clipboardData }) {
|
|
2876
|
-
assignProps(event, { clipboardData });
|
|
2877
|
-
}
|
|
2878
|
-
function initFocusEvent(event, { relatedTarget }) {
|
|
2879
|
-
assignProps(event, { relatedTarget });
|
|
2880
|
-
}
|
|
2881
|
-
function initInputEvent(event, { data, inputType, isComposing }) {
|
|
2882
|
-
assignProps(event, {
|
|
2883
|
-
data,
|
|
2884
|
-
isComposing: Boolean(isComposing),
|
|
2885
|
-
inputType: String(inputType)
|
|
2886
|
-
});
|
|
2887
|
-
}
|
|
2888
|
-
function initUIEvent(event, { view, detail }) {
|
|
2889
|
-
assignProps(event, {
|
|
2890
|
-
view,
|
|
2891
|
-
detail: sanitizeNumber(detail ?? 0)
|
|
2892
|
-
});
|
|
2893
|
-
}
|
|
2894
|
-
function initUIEventModifiers(event, { altKey, ctrlKey, metaKey, shiftKey, modifierAltGraph, modifierCapsLock, modifierFn, modifierFnLock, modifierNumLock, modifierScrollLock, modifierSymbol, modifierSymbolLock }) {
|
|
2895
|
-
assignProps(event, {
|
|
2896
|
-
altKey: Boolean(altKey),
|
|
2897
|
-
ctrlKey: Boolean(ctrlKey),
|
|
2898
|
-
metaKey: Boolean(metaKey),
|
|
2899
|
-
shiftKey: Boolean(shiftKey),
|
|
2900
|
-
getModifierState(k) {
|
|
2901
|
-
return Boolean({
|
|
2902
|
-
Alt: altKey,
|
|
2903
|
-
AltGraph: modifierAltGraph,
|
|
2904
|
-
CapsLock: modifierCapsLock,
|
|
2905
|
-
Control: ctrlKey,
|
|
2906
|
-
Fn: modifierFn,
|
|
2907
|
-
FnLock: modifierFnLock,
|
|
2908
|
-
Meta: metaKey,
|
|
2909
|
-
NumLock: modifierNumLock,
|
|
2910
|
-
ScrollLock: modifierScrollLock,
|
|
2911
|
-
Shift: shiftKey,
|
|
2912
|
-
Symbol: modifierSymbol,
|
|
2913
|
-
SymbolLock: modifierSymbolLock
|
|
2914
|
-
}[k]);
|
|
2915
|
-
}
|
|
2916
|
-
});
|
|
2917
|
-
}
|
|
2918
|
-
function initKeyboardEvent(event, { key, code, location, repeat, isComposing, charCode }) {
|
|
2919
|
-
assignProps(event, {
|
|
2920
|
-
key: String(key),
|
|
2921
|
-
code: String(code),
|
|
2922
|
-
location: sanitizeNumber(location),
|
|
2923
|
-
repeat: Boolean(repeat),
|
|
2924
|
-
isComposing: Boolean(isComposing),
|
|
2925
|
-
charCode
|
|
2926
|
-
});
|
|
2927
|
-
}
|
|
2928
|
-
function initMouseEvent(event, { x, y, screenX, screenY, clientX = x, clientY = y, button, buttons, relatedTarget, offsetX, offsetY, pageX, pageY }) {
|
|
2929
|
-
assignProps(event, {
|
|
2930
|
-
screenX: sanitizeNumber(screenX),
|
|
2931
|
-
screenY: sanitizeNumber(screenY),
|
|
2932
|
-
clientX: sanitizeNumber(clientX),
|
|
2933
|
-
x: sanitizeNumber(clientX),
|
|
2934
|
-
clientY: sanitizeNumber(clientY),
|
|
2935
|
-
y: sanitizeNumber(clientY),
|
|
2936
|
-
button: sanitizeNumber(button),
|
|
2937
|
-
buttons: sanitizeNumber(buttons),
|
|
2938
|
-
relatedTarget,
|
|
2939
|
-
offsetX: sanitizeNumber(offsetX),
|
|
2940
|
-
offsetY: sanitizeNumber(offsetY),
|
|
2941
|
-
pageX: sanitizeNumber(pageX),
|
|
2942
|
-
pageY: sanitizeNumber(pageY)
|
|
2943
|
-
});
|
|
2944
|
-
}
|
|
2945
|
-
function initPointerEvent(event, { pointerId, width, height, pressure, tangentialPressure, tiltX, tiltY, twist, pointerType, isPrimary, buttons }) {
|
|
2946
|
-
assignProps(event, {
|
|
2947
|
-
pointerId: sanitizeNumber(pointerId),
|
|
2948
|
-
width: sanitizeNumber(width ?? 1),
|
|
2949
|
-
height: sanitizeNumber(height ?? 1),
|
|
2950
|
-
pressure: sanitizeNumber(pressure ?? (buttons ? .5 : 0)),
|
|
2951
|
-
tangentialPressure: sanitizeNumber(tangentialPressure),
|
|
2952
|
-
tiltX: sanitizeNumber(tiltX),
|
|
2953
|
-
tiltY: sanitizeNumber(tiltY),
|
|
2954
|
-
twist: sanitizeNumber(twist),
|
|
2955
|
-
pointerType: String(pointerType ?? ""),
|
|
2956
|
-
isPrimary: Boolean(isPrimary)
|
|
2957
|
-
});
|
|
2958
|
-
}
|
|
2959
|
-
|
|
2960
|
-
// src/event/dispatchEvent.ts
|
|
2961
|
-
function dispatchUIEvent(target, type, init, preventDefault = false) {
|
|
2962
|
-
const modifiers = isMouseEvent(type) || isKeyboardEvent(type) ? this.system : void 0;
|
|
2963
|
-
const event = createEvent(type, target, init, modifiers);
|
|
2964
|
-
return dispatchEvent.call(this, target, event, preventDefault);
|
|
2965
|
-
}
|
|
2966
|
-
function dispatchEvent(target, event, preventDefault = false) {
|
|
2967
|
-
const type = event.type;
|
|
2968
|
-
const behaviorImplementation = preventDefault ? () => {} : behavior[type]?.(event, target, this);
|
|
2969
|
-
if (behaviorImplementation) {
|
|
2970
|
-
event.preventDefault();
|
|
2971
|
-
let defaultPrevented = false;
|
|
2972
|
-
Object.defineProperty(event, "defaultPrevented", { get: () => defaultPrevented });
|
|
2973
|
-
Object.defineProperty(event, "preventDefault", { value: () => {
|
|
2974
|
-
defaultPrevented = event.cancelable;
|
|
2975
|
-
} });
|
|
2976
|
-
wrapEvent(() => target.dispatchEvent(event), target);
|
|
2977
|
-
if (!defaultPrevented) behaviorImplementation();
|
|
2978
|
-
return !defaultPrevented;
|
|
2979
|
-
}
|
|
2980
|
-
return wrapEvent(() => target.dispatchEvent(event), target);
|
|
2981
|
-
}
|
|
2982
|
-
function dispatchDOMEvent(target, type, init) {
|
|
2983
|
-
const event = createEvent(type, target, init);
|
|
2984
|
-
wrapEvent(() => target.dispatchEvent(event), target);
|
|
2985
|
-
}
|
|
2986
|
-
|
|
2987
|
-
// src/document/patchFocus.ts
|
|
2988
|
-
const patched = Symbol("patched focus/blur methods");
|
|
2989
|
-
function patchFocus(HTMLElement) {
|
|
2990
|
-
const proto = HTMLElement.prototype;
|
|
2991
|
-
if (proto[patched]) return;
|
|
2992
|
-
const { focus, blur } = proto;
|
|
2993
|
-
Object.defineProperties(HTMLElement.prototype, {
|
|
2994
|
-
focus: {
|
|
2995
|
-
configurable: true,
|
|
2996
|
-
value: patchedFocus,
|
|
2997
|
-
writable: true
|
|
2998
|
-
},
|
|
2999
|
-
blur: {
|
|
3000
|
-
configurable: true,
|
|
3001
|
-
value: patchedBlur,
|
|
3002
|
-
writable: true
|
|
3003
|
-
},
|
|
3004
|
-
[patched]: {
|
|
3005
|
-
configurable: true,
|
|
3006
|
-
get: () => ({
|
|
3007
|
-
focus,
|
|
3008
|
-
blur
|
|
3009
|
-
})
|
|
3010
|
-
}
|
|
3011
|
-
});
|
|
3012
|
-
let activeCall;
|
|
3013
|
-
function patchedFocus(options) {
|
|
3014
|
-
if (this.ownerDocument.visibilityState !== "hidden") return focus.call(this, options);
|
|
3015
|
-
const blurred = getActiveTarget(this.ownerDocument);
|
|
3016
|
-
if (blurred === this) return;
|
|
3017
|
-
const thisCall = Symbol("focus call");
|
|
3018
|
-
activeCall = thisCall;
|
|
3019
|
-
if (blurred) {
|
|
3020
|
-
blur.call(blurred);
|
|
3021
|
-
dispatchDOMEvent(blurred, "blur", { relatedTarget: this });
|
|
3022
|
-
dispatchDOMEvent(blurred, "focusout", { relatedTarget: activeCall === thisCall ? this : null });
|
|
3023
|
-
}
|
|
3024
|
-
if (activeCall === thisCall) {
|
|
3025
|
-
focus.call(this, options);
|
|
3026
|
-
dispatchDOMEvent(this, "focus", { relatedTarget: blurred });
|
|
3027
|
-
}
|
|
3028
|
-
if (activeCall === thisCall) dispatchDOMEvent(this, "focusin", { relatedTarget: blurred });
|
|
3029
|
-
}
|
|
3030
|
-
function patchedBlur() {
|
|
3031
|
-
if (this.ownerDocument.visibilityState !== "hidden") return blur.call(this);
|
|
3032
|
-
const blurred = getActiveTarget(this.ownerDocument);
|
|
3033
|
-
if (blurred !== this) return;
|
|
3034
|
-
activeCall = Symbol("blur call");
|
|
3035
|
-
blur.call(this);
|
|
3036
|
-
dispatchDOMEvent(blurred, "blur", { relatedTarget: null });
|
|
3037
|
-
dispatchDOMEvent(blurred, "focusout", { relatedTarget: null });
|
|
3038
|
-
}
|
|
3039
|
-
}
|
|
3040
|
-
function getActiveTarget(document) {
|
|
3041
|
-
const active = getActiveElement(document);
|
|
3042
|
-
return active?.tagName === "BODY" ? null : active;
|
|
3043
|
-
}
|
|
3044
|
-
|
|
3045
|
-
// src/document/interceptor.ts
|
|
3046
|
-
const Interceptor = Symbol("Interceptor for programmatical calls");
|
|
3047
|
-
function prepareInterceptor(element, propName, interceptorImpl) {
|
|
3048
|
-
const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
3049
|
-
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
3050
|
-
const target = prototypeDescriptor?.set ? "set" : "value";
|
|
3051
|
-
/* istanbul ignore if */
|
|
3052
|
-
if (typeof prototypeDescriptor?.[target] !== "function" || prototypeDescriptor[target][Interceptor]) throw new Error(`Element ${element.tagName} does not implement "${String(propName)}".`);
|
|
3053
|
-
function intercept(...args) {
|
|
3054
|
-
const { applyNative = false, realArgs, then } = interceptorImpl.call(this, ...args);
|
|
3055
|
-
const realFunc = (!applyNative && objectDescriptor ? objectDescriptor : prototypeDescriptor)?.[target];
|
|
3056
|
-
if (target === "set") realFunc.call(this, realArgs);
|
|
3057
|
-
else realFunc.call(this, ...realArgs);
|
|
3058
|
-
then?.();
|
|
3059
|
-
}
|
|
3060
|
-
intercept[Interceptor] = Interceptor;
|
|
3061
|
-
Object.defineProperty(element, propName, {
|
|
3062
|
-
...objectDescriptor ?? prototypeDescriptor,
|
|
3063
|
-
[target]: intercept
|
|
3064
|
-
});
|
|
3065
|
-
}
|
|
3066
|
-
function prepareValueInterceptor(element) {
|
|
3067
|
-
prepareInterceptor(element, "value", function interceptorImpl(v) {
|
|
3068
|
-
const value = v === null ? "" : v;
|
|
3069
|
-
const isUI = isUIValue(value);
|
|
3070
|
-
if (isUI) startTrackValue(this);
|
|
3071
|
-
return {
|
|
3072
|
-
applyNative: !!isUI,
|
|
3073
|
-
realArgs: sanitizeValue(this, value),
|
|
3074
|
-
then: isUI ? void 0 : () => trackOrSetValue(this, String(value))
|
|
3075
|
-
};
|
|
3076
|
-
});
|
|
3077
|
-
}
|
|
3078
|
-
function sanitizeValue(element, v) {
|
|
3079
|
-
if (isElementType(element, "input", { type: "number" }) && String(v) !== "" && !Number.isNaN(Number(v))) return String(Number(v));
|
|
3080
|
-
return String(v);
|
|
3081
|
-
}
|
|
3082
|
-
function prepareSelectionInterceptor(element) {
|
|
3083
|
-
prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, ...others) {
|
|
3084
|
-
const isUI = isUISelectionStart(start);
|
|
3085
|
-
return {
|
|
3086
|
-
applyNative: !!isUI,
|
|
3087
|
-
realArgs: [Number(start), ...others],
|
|
3088
|
-
then: () => isUI ? void 0 : setUISelectionClean(element)
|
|
3089
|
-
};
|
|
3090
|
-
});
|
|
3091
|
-
prepareInterceptor(element, "selectionStart", function interceptorImpl(v) {
|
|
3092
|
-
return {
|
|
3093
|
-
realArgs: v,
|
|
3094
|
-
then: () => setUISelectionClean(element)
|
|
3095
|
-
};
|
|
3096
|
-
});
|
|
3097
|
-
prepareInterceptor(element, "selectionEnd", function interceptorImpl(v) {
|
|
3098
|
-
return {
|
|
3099
|
-
realArgs: v,
|
|
3100
|
-
then: () => setUISelectionClean(element)
|
|
3101
|
-
};
|
|
3102
|
-
});
|
|
3103
|
-
prepareInterceptor(element, "select", function interceptorImpl() {
|
|
3104
|
-
return {
|
|
3105
|
-
realArgs: [],
|
|
3106
|
-
then: () => setUISelectionRaw(element, {
|
|
3107
|
-
anchorOffset: 0,
|
|
3108
|
-
focusOffset: getUIValue(element).length
|
|
3109
|
-
})
|
|
3110
|
-
};
|
|
3111
|
-
});
|
|
3112
|
-
}
|
|
3113
|
-
function prepareRangeTextInterceptor(element) {
|
|
3114
|
-
prepareInterceptor(element, "setRangeText", function interceptorImpl(...realArgs) {
|
|
3115
|
-
return {
|
|
3116
|
-
realArgs,
|
|
3117
|
-
then: () => {
|
|
3118
|
-
setUIValueClean(element);
|
|
3119
|
-
setUISelectionClean(element);
|
|
3120
|
-
}
|
|
3121
|
-
};
|
|
3122
|
-
});
|
|
3123
|
-
}
|
|
3124
|
-
|
|
3125
|
-
// src/document/prepareDocument.ts
|
|
3126
|
-
const isPrepared = Symbol("Node prepared with document state workarounds");
|
|
3127
|
-
function prepareDocument(document) {
|
|
3128
|
-
if (document[isPrepared]) return;
|
|
3129
|
-
document.addEventListener("focus", (e) => {
|
|
3130
|
-
const el = e.target;
|
|
3131
|
-
prepareElement(el);
|
|
3132
|
-
}, {
|
|
3133
|
-
capture: true,
|
|
3134
|
-
passive: true
|
|
3135
|
-
});
|
|
3136
|
-
// istanbul ignore else
|
|
3137
|
-
if (document.activeElement) prepareElement(document.activeElement);
|
|
3138
|
-
document.addEventListener("blur", (e) => {
|
|
3139
|
-
const el = e.target;
|
|
3140
|
-
const initialValue = getInitialValue(el);
|
|
3141
|
-
if (initialValue !== void 0) {
|
|
3142
|
-
if (el.value !== initialValue) dispatchDOMEvent(el, "change");
|
|
3143
|
-
clearInitialValue(el);
|
|
3144
|
-
}
|
|
3145
|
-
}, {
|
|
3146
|
-
capture: true,
|
|
3147
|
-
passive: true
|
|
3148
|
-
});
|
|
3149
|
-
document[isPrepared] = isPrepared;
|
|
3150
|
-
}
|
|
3151
|
-
function prepareElement(el) {
|
|
3152
|
-
if (el[isPrepared]) return;
|
|
3153
|
-
if (isElementType(el, ["input", "textarea"]) && !hasCtrlDomUI(el)) {
|
|
3154
|
-
prepareValueInterceptor(el);
|
|
3155
|
-
prepareSelectionInterceptor(el);
|
|
3156
|
-
prepareRangeTextInterceptor(el);
|
|
3157
|
-
}
|
|
3158
|
-
el[isPrepared] = isPrepared;
|
|
3159
|
-
}
|
|
3160
|
-
|
|
3161
|
-
// src/keyboard/keyMap.ts
|
|
3162
|
-
/**
|
|
3163
|
-
* Mapping for a default US-104-QWERTY keyboard
|
|
3164
|
-
*/
|
|
3165
|
-
const defaultKeyMap$1 = [
|
|
3166
|
-
..."0123456789".split("").map((c) => ({
|
|
3167
|
-
code: `Digit${c}`,
|
|
3168
|
-
key: c
|
|
3169
|
-
})),
|
|
3170
|
-
...")!@#$%^&*(".split("").map((c, i) => ({
|
|
3171
|
-
code: `Digit${i}`,
|
|
3172
|
-
key: c,
|
|
3173
|
-
shiftKey: true
|
|
3174
|
-
})),
|
|
3175
|
-
..."abcdefghijklmnopqrstuvwxyz".split("").map((c) => ({
|
|
3176
|
-
code: `Key${c.toUpperCase()}`,
|
|
3177
|
-
key: c
|
|
3178
|
-
})),
|
|
3179
|
-
..."ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("").map((c) => ({
|
|
3180
|
-
code: `Key${c}`,
|
|
3181
|
-
key: c,
|
|
3182
|
-
shiftKey: true
|
|
3183
|
-
})),
|
|
3184
|
-
{
|
|
3185
|
-
code: "BracketLeft",
|
|
3186
|
-
key: "["
|
|
3187
|
-
},
|
|
3188
|
-
{
|
|
3189
|
-
code: "BracketLeft",
|
|
3190
|
-
key: "{",
|
|
3191
|
-
shiftKey: true
|
|
3192
|
-
},
|
|
3193
|
-
{
|
|
3194
|
-
code: "BracketRight",
|
|
3195
|
-
key: "]"
|
|
3196
|
-
},
|
|
3197
|
-
{
|
|
3198
|
-
code: "BracketRight",
|
|
3199
|
-
key: "}",
|
|
3200
|
-
shiftKey: true
|
|
3201
|
-
},
|
|
3202
|
-
{
|
|
3203
|
-
code: "Space",
|
|
3204
|
-
key: " "
|
|
3205
|
-
},
|
|
3206
|
-
{
|
|
3207
|
-
code: "AltLeft",
|
|
3208
|
-
key: "Alt",
|
|
3209
|
-
location: DOM_KEY_LOCATION.LEFT
|
|
3210
|
-
},
|
|
3211
|
-
{
|
|
3212
|
-
code: "AltRight",
|
|
3213
|
-
key: "Alt",
|
|
3214
|
-
location: DOM_KEY_LOCATION.RIGHT
|
|
3215
|
-
},
|
|
3216
|
-
{
|
|
3217
|
-
code: "ShiftLeft",
|
|
3218
|
-
key: "Shift",
|
|
3219
|
-
location: DOM_KEY_LOCATION.LEFT
|
|
3220
|
-
},
|
|
3221
|
-
{
|
|
3222
|
-
code: "ShiftRight",
|
|
3223
|
-
key: "Shift",
|
|
3224
|
-
location: DOM_KEY_LOCATION.RIGHT
|
|
3225
|
-
},
|
|
3226
|
-
{
|
|
3227
|
-
code: "ControlLeft",
|
|
3228
|
-
key: "Control",
|
|
3229
|
-
location: DOM_KEY_LOCATION.LEFT
|
|
3230
|
-
},
|
|
3231
|
-
{
|
|
3232
|
-
code: "ControlRight",
|
|
3233
|
-
key: "Control",
|
|
3234
|
-
location: DOM_KEY_LOCATION.RIGHT
|
|
3235
|
-
},
|
|
3236
|
-
{
|
|
3237
|
-
code: "MetaLeft",
|
|
3238
|
-
key: "Meta",
|
|
3239
|
-
location: DOM_KEY_LOCATION.LEFT
|
|
3240
|
-
},
|
|
3241
|
-
{
|
|
3242
|
-
code: "MetaRight",
|
|
3243
|
-
key: "Meta",
|
|
3244
|
-
location: DOM_KEY_LOCATION.RIGHT
|
|
3245
|
-
},
|
|
3246
|
-
{
|
|
3247
|
-
code: "OSLeft",
|
|
3248
|
-
key: "OS",
|
|
3249
|
-
location: DOM_KEY_LOCATION.LEFT
|
|
3250
|
-
},
|
|
3251
|
-
{
|
|
3252
|
-
code: "OSRight",
|
|
3253
|
-
key: "OS",
|
|
3254
|
-
location: DOM_KEY_LOCATION.RIGHT
|
|
3255
|
-
},
|
|
3256
|
-
{
|
|
3257
|
-
code: "ContextMenu",
|
|
3258
|
-
key: "ContextMenu"
|
|
3259
|
-
},
|
|
3260
|
-
{
|
|
3261
|
-
code: "Tab",
|
|
3262
|
-
key: "Tab"
|
|
3263
|
-
},
|
|
3264
|
-
{
|
|
3265
|
-
code: "CapsLock",
|
|
3266
|
-
key: "CapsLock"
|
|
3267
|
-
},
|
|
3268
|
-
{
|
|
3269
|
-
code: "Backspace",
|
|
3270
|
-
key: "Backspace"
|
|
3271
|
-
},
|
|
3272
|
-
{
|
|
3273
|
-
code: "Enter",
|
|
3274
|
-
key: "Enter"
|
|
3275
|
-
},
|
|
3276
|
-
{
|
|
3277
|
-
code: "Escape",
|
|
3278
|
-
key: "Escape"
|
|
3279
|
-
},
|
|
3280
|
-
{
|
|
3281
|
-
code: "ArrowUp",
|
|
3282
|
-
key: "ArrowUp"
|
|
3283
|
-
},
|
|
3284
|
-
{
|
|
3285
|
-
code: "ArrowDown",
|
|
3286
|
-
key: "ArrowDown"
|
|
3287
|
-
},
|
|
3288
|
-
{
|
|
3289
|
-
code: "ArrowLeft",
|
|
3290
|
-
key: "ArrowLeft"
|
|
3291
|
-
},
|
|
3292
|
-
{
|
|
3293
|
-
code: "ArrowRight",
|
|
3294
|
-
key: "ArrowRight"
|
|
3295
|
-
},
|
|
3296
|
-
{
|
|
3297
|
-
code: "Home",
|
|
3298
|
-
key: "Home"
|
|
3299
|
-
},
|
|
3300
|
-
{
|
|
3301
|
-
code: "End",
|
|
3302
|
-
key: "End"
|
|
3303
|
-
},
|
|
3304
|
-
{
|
|
3305
|
-
code: "Delete",
|
|
3306
|
-
key: "Delete"
|
|
3307
|
-
},
|
|
3308
|
-
{
|
|
3309
|
-
code: "PageUp",
|
|
3310
|
-
key: "PageUp"
|
|
3311
|
-
},
|
|
3312
|
-
{
|
|
3313
|
-
code: "PageDown",
|
|
3314
|
-
key: "PageDown"
|
|
3315
|
-
},
|
|
3316
|
-
{
|
|
3317
|
-
code: "Fn",
|
|
3318
|
-
key: "Fn"
|
|
3319
|
-
},
|
|
3320
|
-
{
|
|
3321
|
-
code: "Symbol",
|
|
3322
|
-
key: "Symbol"
|
|
3323
|
-
},
|
|
3324
|
-
{
|
|
3325
|
-
code: "AltRight",
|
|
3326
|
-
key: "AltGraph"
|
|
3327
|
-
}
|
|
3328
|
-
];
|
|
3329
|
-
|
|
3330
|
-
// src/pointer/keyMap.ts
|
|
3331
|
-
const defaultKeyMap = [
|
|
3332
|
-
{
|
|
3333
|
-
name: "MouseLeft",
|
|
3334
|
-
pointerType: "mouse",
|
|
3335
|
-
button: "primary"
|
|
3336
|
-
},
|
|
3337
|
-
{
|
|
3338
|
-
name: "MouseRight",
|
|
3339
|
-
pointerType: "mouse",
|
|
3340
|
-
button: "secondary"
|
|
3341
|
-
},
|
|
3342
|
-
{
|
|
3343
|
-
name: "MouseMiddle",
|
|
3344
|
-
pointerType: "mouse",
|
|
3345
|
-
button: "auxiliary"
|
|
3346
|
-
},
|
|
3347
|
-
{
|
|
3348
|
-
name: "TouchA",
|
|
3349
|
-
pointerType: "touch"
|
|
3350
|
-
},
|
|
3351
|
-
{
|
|
3352
|
-
name: "TouchB",
|
|
3353
|
-
pointerType: "touch"
|
|
3354
|
-
},
|
|
3355
|
-
{
|
|
3356
|
-
name: "TouchC",
|
|
3357
|
-
pointerType: "touch"
|
|
3358
|
-
}
|
|
3359
|
-
];
|
|
3360
|
-
|
|
3361
|
-
// src/pointer/parseKeyDef.ts
|
|
3362
|
-
function parseKeyDef$1(pointerMap, keys) {
|
|
3363
|
-
const defs = [];
|
|
3364
|
-
do {
|
|
3365
|
-
const { descriptor, consumedLength, releasePrevious, releaseSelf = true } = readNextDescriptor(keys, "pointer");
|
|
3366
|
-
const keyDef = pointerMap.find((p) => p.name === descriptor);
|
|
3367
|
-
if (keyDef) defs.push({
|
|
3368
|
-
keyDef,
|
|
3369
|
-
releasePrevious,
|
|
3370
|
-
releaseSelf
|
|
3371
|
-
});
|
|
3372
|
-
keys = keys.slice(consumedLength);
|
|
3373
|
-
} while (keys);
|
|
3374
|
-
return defs;
|
|
3375
|
-
}
|
|
3376
|
-
|
|
3377
|
-
// src/pointer/index.ts
|
|
3378
|
-
async function pointer$1(input) {
|
|
3379
|
-
const { pointerMap } = this.config;
|
|
3380
|
-
const actions = [];
|
|
3381
|
-
(Array.isArray(input) ? input : [input]).forEach((actionInput) => {
|
|
3382
|
-
if (typeof actionInput === "string") actions.push(...parseKeyDef$1(pointerMap, actionInput));
|
|
3383
|
-
else if ("keys" in actionInput) actions.push(...parseKeyDef$1(pointerMap, actionInput.keys).map((i) => ({
|
|
3384
|
-
...actionInput,
|
|
3385
|
-
...i
|
|
3386
|
-
})));
|
|
3387
|
-
else actions.push(actionInput);
|
|
3388
|
-
});
|
|
3389
|
-
for (let i = 0; i < actions.length; i++) {
|
|
3390
|
-
await yieldBetweenActions(this.config);
|
|
3391
|
-
await pointerAction(this, actions[i]);
|
|
3392
|
-
}
|
|
3393
|
-
this.system.pointer.resetClickCount();
|
|
3394
|
-
}
|
|
3395
|
-
async function pointerAction(instance, action) {
|
|
3396
|
-
const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? instance.system.pointer.getPointerName(action.keyDef) : "mouse";
|
|
3397
|
-
const previousPosition = instance.system.pointer.getPreviousPosition(pointerName);
|
|
3398
|
-
const position = {
|
|
3399
|
-
target: action.target ?? getPrevTarget(instance, previousPosition),
|
|
3400
|
-
coords: action.coords ?? previousPosition?.coords,
|
|
3401
|
-
caret: {
|
|
3402
|
-
node: action.node ?? (hasCaretPosition(action) ? void 0 : previousPosition?.caret?.node),
|
|
3403
|
-
offset: action.offset ?? (hasCaretPosition(action) ? void 0 : previousPosition?.caret?.offset)
|
|
3404
|
-
}
|
|
3405
|
-
};
|
|
3406
|
-
if ("keyDef" in action) {
|
|
3407
|
-
if (instance.system.pointer.isKeyPressed(action.keyDef)) {
|
|
3408
|
-
setLevelRef(instance, ApiLevel.Trigger);
|
|
3409
|
-
await instance.system.pointer.release(instance, action.keyDef, position);
|
|
3410
|
-
}
|
|
3411
|
-
if (!action.releasePrevious) {
|
|
3412
|
-
setLevelRef(instance, ApiLevel.Trigger);
|
|
3413
|
-
await instance.system.pointer.press(instance, action.keyDef, position);
|
|
3414
|
-
if (action.releaseSelf) {
|
|
3415
|
-
setLevelRef(instance, ApiLevel.Trigger);
|
|
3416
|
-
await instance.system.pointer.release(instance, action.keyDef, position);
|
|
3417
|
-
}
|
|
3418
|
-
}
|
|
3419
|
-
} else {
|
|
3420
|
-
setLevelRef(instance, ApiLevel.Trigger);
|
|
3421
|
-
await instance.system.pointer.move(instance, pointerName, position);
|
|
3422
|
-
}
|
|
3423
|
-
}
|
|
3424
|
-
function hasCaretPosition(action) {
|
|
3425
|
-
return !!(action.target ?? action.node ?? action.offset !== void 0);
|
|
3426
|
-
}
|
|
3427
|
-
function getPrevTarget(instance, position) {
|
|
3428
|
-
if (!position) throw new Error("This pointer has no previous position. Provide a target property!");
|
|
3429
|
-
return position.target ?? instance.config.document.body;
|
|
3430
|
-
}
|
|
3431
|
-
|
|
3432
|
-
// src/convenience/click.ts
|
|
3433
|
-
async function click$1(element) {
|
|
3434
|
-
const pointerIn = [];
|
|
3435
|
-
if (!this.config.skipHover) pointerIn.push({ target: element });
|
|
3436
|
-
pointerIn.push({
|
|
3437
|
-
keys: "[MouseLeft]",
|
|
3438
|
-
target: element
|
|
3439
|
-
});
|
|
3440
|
-
return this.pointer(pointerIn);
|
|
3441
|
-
}
|
|
3442
|
-
async function dblClick$1(element) {
|
|
3443
|
-
return this.pointer([{ target: element }, "[MouseLeft][MouseLeft]"]);
|
|
3444
|
-
}
|
|
3445
|
-
async function tripleClick$1(element) {
|
|
3446
|
-
return this.pointer([{ target: element }, "[MouseLeft][MouseLeft][MouseLeft]"]);
|
|
3447
|
-
}
|
|
3448
|
-
|
|
3449
|
-
// src/convenience/hover.ts
|
|
3450
|
-
async function hover$1(element) {
|
|
3451
|
-
return this.pointer({ target: element });
|
|
3452
|
-
}
|
|
3453
|
-
async function unhover$1(element) {
|
|
3454
|
-
assertPointerEvents(this, this.system.pointer.getMouseTarget(this));
|
|
3455
|
-
return this.pointer({ target: element.ownerDocument.body });
|
|
3456
|
-
}
|
|
3457
|
-
|
|
3458
|
-
// src/convenience/tab.ts
|
|
3459
|
-
async function tab$1({ shift } = {}) {
|
|
3460
|
-
return this.keyboard(shift === true ? "{Shift>}{Tab}{/Shift}" : shift === false ? "[/ShiftLeft][/ShiftRight]{Tab}" : "{Tab}");
|
|
3461
|
-
}
|
|
3462
|
-
|
|
3463
|
-
// src/keyboard/parseKeyDef.ts
|
|
3464
|
-
/**
|
|
3465
|
-
* Parse key definitions per `keyboardMap`
|
|
3466
|
-
*
|
|
3467
|
-
* Keys can be referenced by `{key}` or `{special}` as well as physical locations per `[code]`.
|
|
3468
|
-
* Everything else will be interpreted as a typed character - e.g. `a`.
|
|
3469
|
-
* Brackets `{` and `[` can be escaped by doubling - e.g. `foo[[bar` translates to `foo[bar`.
|
|
3470
|
-
* Keeping the key pressed can be written as `{key>}`.
|
|
3471
|
-
* When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`.
|
|
3472
|
-
* You can then release the key per `{key>3/}` or keep it pressed and continue with the next key.
|
|
3473
|
-
*/
|
|
3474
|
-
function parseKeyDef(keyboardMap, text) {
|
|
3475
|
-
const defs = [];
|
|
3476
|
-
do {
|
|
3477
|
-
const { type, descriptor, consumedLength, releasePrevious, releaseSelf = true, repeat } = readNextDescriptor(text, "keyboard");
|
|
3478
|
-
const keyDef = keyboardMap.find((def) => {
|
|
3479
|
-
if (type === "[") return def.code?.toLowerCase() === descriptor.toLowerCase();
|
|
3480
|
-
else if (type === "{") return def.key?.toLowerCase() === descriptor.toLowerCase();
|
|
3481
|
-
return def.key === descriptor;
|
|
3482
|
-
}) ?? {
|
|
3483
|
-
key: "Unknown",
|
|
3484
|
-
code: "Unknown",
|
|
3485
|
-
[type === "[" ? "code" : "key"]: descriptor
|
|
3486
|
-
};
|
|
3487
|
-
defs.push({
|
|
3488
|
-
keyDef,
|
|
3489
|
-
releasePrevious,
|
|
3490
|
-
releaseSelf,
|
|
3491
|
-
repeat
|
|
3492
|
-
});
|
|
3493
|
-
text = text.slice(consumedLength);
|
|
3494
|
-
} while (text);
|
|
3495
|
-
return defs;
|
|
3496
|
-
}
|
|
3497
|
-
|
|
3498
|
-
// src/keyboard/index.ts
|
|
3499
|
-
async function keyboard$1(text) {
|
|
3500
|
-
const actions = parseKeyDef(this.config.keyboardMap, text);
|
|
3501
|
-
for (let i = 0; i < actions.length; i++) {
|
|
3502
|
-
await yieldBetweenActions(this.config);
|
|
3503
|
-
await keyboardAction(this, actions[i]);
|
|
3504
|
-
}
|
|
3505
|
-
}
|
|
3506
|
-
async function keyboardAction(instance, { keyDef, releasePrevious, releaseSelf, repeat }) {
|
|
3507
|
-
const { system } = instance;
|
|
3508
|
-
if (system.keyboard.isKeyPressed(keyDef)) await system.keyboard.keyup(instance, keyDef);
|
|
3509
|
-
if (!releasePrevious) {
|
|
3510
|
-
for (let i = 1; i <= repeat; i++) {
|
|
3511
|
-
await system.keyboard.keydown(instance, keyDef, i > 1);
|
|
3512
|
-
if (i < repeat) await yieldBetweenActions(instance.config);
|
|
3513
|
-
}
|
|
3514
|
-
if (releaseSelf) await system.keyboard.keyup(instance, keyDef);
|
|
3515
|
-
}
|
|
3516
|
-
}
|
|
3517
|
-
async function releaseAllKeys(instance) {
|
|
3518
|
-
for (const k of instance.system.keyboard.getPressedKeys()) await instance.system.keyboard.keyup(instance, k);
|
|
3519
|
-
}
|
|
3520
|
-
|
|
3521
|
-
// src/clipboard/copy.ts
|
|
3522
|
-
async function copy$1() {
|
|
3523
|
-
const doc = this.config.document;
|
|
3524
|
-
const target = doc.activeElement ?? /* istanbul ignore next */ doc.body;
|
|
3525
|
-
const clipboardData = copySelection(target);
|
|
3526
|
-
if (clipboardData.items.length === 0) return;
|
|
3527
|
-
if (this.dispatchUIEvent(target, "copy", { clipboardData }) && this.config.writeToClipboard) await writeDataTransferToClipboard(doc, clipboardData);
|
|
3528
|
-
return clipboardData;
|
|
3529
|
-
}
|
|
3530
|
-
|
|
3531
|
-
// src/clipboard/cut.ts
|
|
3532
|
-
async function cut$1() {
|
|
3533
|
-
const doc = this.config.document;
|
|
3534
|
-
const target = doc.activeElement ?? /* istanbul ignore next */ doc.body;
|
|
3535
|
-
const clipboardData = copySelection(target);
|
|
3536
|
-
if (clipboardData.items.length === 0) return;
|
|
3537
|
-
if (this.dispatchUIEvent(target, "cut", { clipboardData }) && this.config.writeToClipboard) await writeDataTransferToClipboard(target.ownerDocument, clipboardData);
|
|
3538
|
-
return clipboardData;
|
|
3539
|
-
}
|
|
3540
|
-
|
|
3541
|
-
// src/clipboard/paste.ts
|
|
3542
|
-
async function paste$1(clipboardData) {
|
|
3543
|
-
const doc = this.config.document;
|
|
3544
|
-
const target = doc.activeElement ?? /* istanbul ignore next */ doc.body;
|
|
3545
|
-
const dataTransfer = (typeof clipboardData === "string" ? getClipboardDataFromString(doc, clipboardData) : clipboardData) ?? await readDataTransferFromClipboard(doc).catch(() => {
|
|
3546
|
-
throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
|
|
3547
|
-
});
|
|
3548
|
-
this.dispatchUIEvent(target, "paste", { clipboardData: dataTransfer });
|
|
3549
|
-
}
|
|
3550
|
-
function getClipboardDataFromString(doc, text) {
|
|
3551
|
-
const dt = createDataTransfer(getWindow(doc));
|
|
3552
|
-
dt.setData("text", text);
|
|
3553
|
-
return dt;
|
|
3554
|
-
}
|
|
3555
|
-
|
|
3556
|
-
// src/utility/clear.ts
|
|
3557
|
-
async function clear$1(element) {
|
|
3558
|
-
if (!isEditable(element) || isDisabled(element)) throw new Error("clear()` is only supported on editable elements.");
|
|
3559
|
-
focusElement(element);
|
|
3560
|
-
if (element.ownerDocument.activeElement !== element) throw new Error("The element to be cleared could not be focused.");
|
|
3561
|
-
selectAll(element);
|
|
3562
|
-
if (!isAllSelected(element)) throw new Error("The element content to be cleared could not be selected.");
|
|
3563
|
-
input(this, element, "", "deleteContentBackward");
|
|
3564
|
-
}
|
|
3565
|
-
|
|
3566
|
-
// src/utility/selectOptions.ts
|
|
3567
|
-
async function selectOptions$1(select, values) {
|
|
3568
|
-
return selectOptionsBase.call(this, true, select, values);
|
|
3569
|
-
}
|
|
3570
|
-
async function deselectOptions$1(select, values) {
|
|
3571
|
-
return selectOptionsBase.call(this, false, select, values);
|
|
3572
|
-
}
|
|
3573
|
-
async function selectOptionsBase(newValue, select, values) {
|
|
3574
|
-
if (!newValue && !select.multiple) throw getConfig().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`, select);
|
|
3575
|
-
const valArray = Array.isArray(values) ? values : [values];
|
|
3576
|
-
const allOptions = Array.from(select.querySelectorAll("option, [role=\"option\"]"));
|
|
3577
|
-
const selectedOptions = valArray.map((val) => {
|
|
3578
|
-
if (typeof val !== "string" && allOptions.includes(val)) return val;
|
|
3579
|
-
else {
|
|
3580
|
-
const matchingOption = allOptions.find((o) => o.value === val || o.innerHTML === val);
|
|
3581
|
-
if (matchingOption) return matchingOption;
|
|
3582
|
-
else throw getConfig().getElementError(`Value "${String(val)}" not found in options`, select);
|
|
3583
|
-
}
|
|
3584
|
-
}).filter((option) => !isDisabled(option));
|
|
3585
|
-
if (isDisabled(select) || !selectedOptions.length) return;
|
|
3586
|
-
const selectOption = (option) => {
|
|
3587
|
-
option.selected = newValue;
|
|
3588
|
-
this.dispatchUIEvent(select, "input", {
|
|
3589
|
-
bubbles: true,
|
|
3590
|
-
cancelable: false,
|
|
3591
|
-
composed: true
|
|
3592
|
-
});
|
|
3593
|
-
this.dispatchUIEvent(select, "change");
|
|
3594
|
-
};
|
|
3595
|
-
if (isElementType(select, "select")) {
|
|
3596
|
-
if (select.multiple) for (const option of selectedOptions) {
|
|
3597
|
-
const withPointerEvents = this.config.pointerEventsCheck === 0 ? true : hasPointerEvents(this, option);
|
|
3598
|
-
if (withPointerEvents) {
|
|
3599
|
-
this.dispatchUIEvent(option, "pointerover");
|
|
3600
|
-
this.dispatchUIEvent(select, "pointerenter");
|
|
3601
|
-
this.dispatchUIEvent(option, "mouseover");
|
|
3602
|
-
this.dispatchUIEvent(select, "mouseenter");
|
|
3603
|
-
this.dispatchUIEvent(option, "pointermove");
|
|
3604
|
-
this.dispatchUIEvent(option, "mousemove");
|
|
3605
|
-
this.dispatchUIEvent(option, "pointerdown");
|
|
3606
|
-
this.dispatchUIEvent(option, "mousedown");
|
|
3607
|
-
}
|
|
3608
|
-
focusElement(select);
|
|
3609
|
-
if (withPointerEvents) {
|
|
3610
|
-
this.dispatchUIEvent(option, "pointerup");
|
|
3611
|
-
this.dispatchUIEvent(option, "mouseup");
|
|
3612
|
-
}
|
|
3613
|
-
selectOption(option);
|
|
3614
|
-
if (withPointerEvents) this.dispatchUIEvent(option, "click");
|
|
3615
|
-
await yieldBetweenActions(this.config);
|
|
3616
|
-
}
|
|
3617
|
-
else if (selectedOptions.length === 1) {
|
|
3618
|
-
const withPointerEvents = this.config.pointerEventsCheck === 0 ? true : hasPointerEvents(this, select);
|
|
3619
|
-
if (withPointerEvents) await this.click(select);
|
|
3620
|
-
else focusElement(select);
|
|
3621
|
-
selectOption(selectedOptions[0]);
|
|
3622
|
-
if (withPointerEvents) {
|
|
3623
|
-
this.dispatchUIEvent(select, "pointerover");
|
|
3624
|
-
this.dispatchUIEvent(select, "pointerenter");
|
|
3625
|
-
this.dispatchUIEvent(select, "mouseover");
|
|
3626
|
-
this.dispatchUIEvent(select, "mouseenter");
|
|
3627
|
-
this.dispatchUIEvent(select, "pointerup");
|
|
3628
|
-
this.dispatchUIEvent(select, "mouseup");
|
|
3629
|
-
this.dispatchUIEvent(select, "click");
|
|
3630
|
-
}
|
|
3631
|
-
await yieldBetweenActions(this.config);
|
|
3632
|
-
} else throw getConfig().getElementError(`Cannot select multiple options on a non-multiple select`, select);
|
|
3633
|
-
} else if (select.getAttribute("role") === "listbox") for (const option of selectedOptions) {
|
|
3634
|
-
await this.click(option);
|
|
3635
|
-
await this.unhover(option);
|
|
3636
|
-
}
|
|
3637
|
-
else throw getConfig().getElementError(`Cannot select options on elements that are neither select nor listbox elements`, select);
|
|
3638
|
-
}
|
|
3639
|
-
|
|
3640
|
-
// src/utility/type.ts
|
|
3641
|
-
async function type$1(element, text, { skipClick = this.config.skipClick, skipAutoClose = this.config.skipAutoClose, initialSelectionStart, initialSelectionEnd } = {}) {
|
|
3642
|
-
if (element.disabled) return;
|
|
3643
|
-
if (!skipClick) await this.click(element);
|
|
3644
|
-
if (initialSelectionStart !== void 0) setSelectionRange(element, initialSelectionStart, initialSelectionEnd ?? initialSelectionStart);
|
|
3645
|
-
await this.keyboard(text);
|
|
3646
|
-
if (!skipAutoClose) await releaseAllKeys(this);
|
|
3647
|
-
}
|
|
3648
|
-
|
|
3649
|
-
// src/utility/upload.ts
|
|
3650
|
-
async function upload$1(element, fileOrFiles) {
|
|
3651
|
-
const input = isElementType(element, "label") ? element.control : element;
|
|
3652
|
-
if (!input || !isElementType(input, "input", { type: "file" })) throw new TypeError(`The ${input === element ? "given" : "associated"} ${input?.tagName} element does not accept file uploads`);
|
|
3653
|
-
if (isDisabled(element)) return;
|
|
3654
|
-
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this.config.applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? void 0 : 1);
|
|
3655
|
-
const fileDialog = () => {
|
|
3656
|
-
if (files.length === input.files?.length && files.every((f, i) => f === input.files?.item(i))) return;
|
|
3657
|
-
setFiles(input, createFileList(getWindow(element), files));
|
|
3658
|
-
this.dispatchUIEvent(input, "input");
|
|
3659
|
-
this.dispatchUIEvent(input, "change");
|
|
3660
|
-
};
|
|
3661
|
-
input.addEventListener("fileDialog", fileDialog);
|
|
3662
|
-
await this.click(element);
|
|
3663
|
-
input.removeEventListener("fileDialog", fileDialog);
|
|
3664
|
-
}
|
|
3665
|
-
function normalize(nameOrType) {
|
|
3666
|
-
return nameOrType.toLowerCase().replace(/(\.|\/)jpg\b/g, "$1jpeg");
|
|
3667
|
-
}
|
|
3668
|
-
function isAcceptableFile(file, accept) {
|
|
3669
|
-
if (!accept) return true;
|
|
3670
|
-
const wildcards = [
|
|
3671
|
-
"audio/*",
|
|
3672
|
-
"image/*",
|
|
3673
|
-
"video/*"
|
|
3674
|
-
];
|
|
3675
|
-
return normalize(accept).trim().split(/\s*,\s*/).some((acceptToken) => {
|
|
3676
|
-
if (acceptToken.startsWith(".")) return normalize(file.name).endsWith(acceptToken);
|
|
3677
|
-
else if (wildcards.includes(acceptToken)) return normalize(file.type).startsWith(acceptToken.replace("*", ""));
|
|
3678
|
-
return normalize(file.type) === acceptToken;
|
|
3679
|
-
});
|
|
3680
|
-
}
|
|
3681
|
-
|
|
3682
|
-
// src/setup/api.ts
|
|
3683
|
-
const userEventApi = {
|
|
3684
|
-
click: click$1,
|
|
3685
|
-
dblClick: dblClick$1,
|
|
3686
|
-
tripleClick: tripleClick$1,
|
|
3687
|
-
hover: hover$1,
|
|
3688
|
-
unhover: unhover$1,
|
|
3689
|
-
tab: tab$1,
|
|
3690
|
-
keyboard: keyboard$1,
|
|
3691
|
-
copy: copy$1,
|
|
3692
|
-
cut: cut$1,
|
|
3693
|
-
paste: paste$1,
|
|
3694
|
-
pointer: pointer$1,
|
|
3695
|
-
clear: clear$1,
|
|
3696
|
-
deselectOptions: deselectOptions$1,
|
|
3697
|
-
selectOptions: selectOptions$1,
|
|
3698
|
-
type: type$1,
|
|
3699
|
-
upload: upload$1
|
|
3700
|
-
};
|
|
3701
|
-
|
|
3702
|
-
// src/setup/wrapAsync.ts
|
|
3703
|
-
/**
|
|
3704
|
-
* Wrap an internal Promise
|
|
3705
|
-
*/
|
|
3706
|
-
function wrapAsync(implementation) {
|
|
3707
|
-
return getConfig().asyncWrapper(implementation);
|
|
3708
|
-
}
|
|
3709
|
-
|
|
3710
|
-
// src/setup/directApi.ts
|
|
3711
|
-
var directApi_exports = /* @__PURE__ */ __exportAll({
|
|
3712
|
-
clear: () => clear,
|
|
3713
|
-
click: () => click,
|
|
3714
|
-
copy: () => copy,
|
|
3715
|
-
cut: () => cut,
|
|
3716
|
-
dblClick: () => dblClick,
|
|
3717
|
-
deselectOptions: () => deselectOptions,
|
|
3718
|
-
hover: () => hover,
|
|
3719
|
-
keyboard: () => keyboard,
|
|
3720
|
-
paste: () => paste,
|
|
3721
|
-
pointer: () => pointer,
|
|
3722
|
-
selectOptions: () => selectOptions,
|
|
3723
|
-
tab: () => tab,
|
|
3724
|
-
tripleClick: () => tripleClick,
|
|
3725
|
-
type: () => type,
|
|
3726
|
-
unhover: () => unhover,
|
|
3727
|
-
upload: () => upload
|
|
3728
|
-
});
|
|
3729
|
-
function clear(element) {
|
|
3730
|
-
return setupDirect().api.clear(element);
|
|
3731
|
-
}
|
|
3732
|
-
function click(element, options = {}) {
|
|
3733
|
-
return setupDirect(options, element).api.click(element);
|
|
3734
|
-
}
|
|
3735
|
-
function copy(options = {}) {
|
|
3736
|
-
return setupDirect(options).api.copy();
|
|
3737
|
-
}
|
|
3738
|
-
function cut(options = {}) {
|
|
3739
|
-
return setupDirect(options).api.cut();
|
|
3740
|
-
}
|
|
3741
|
-
function dblClick(element, options = {}) {
|
|
3742
|
-
return setupDirect(options).api.dblClick(element);
|
|
3743
|
-
}
|
|
3744
|
-
function deselectOptions(select, values, options = {}) {
|
|
3745
|
-
return setupDirect(options).api.deselectOptions(select, values);
|
|
3746
|
-
}
|
|
3747
|
-
function hover(element, options = {}) {
|
|
3748
|
-
return setupDirect(options).api.hover(element);
|
|
3749
|
-
}
|
|
3750
|
-
async function keyboard(text, options = {}) {
|
|
3751
|
-
const { api, system } = setupDirect(options);
|
|
3752
|
-
return api.keyboard(text).then(() => system);
|
|
3753
|
-
}
|
|
3754
|
-
async function pointer(input, options = {}) {
|
|
3755
|
-
const { api, system } = setupDirect(options);
|
|
3756
|
-
return api.pointer(input).then(() => system);
|
|
3757
|
-
}
|
|
3758
|
-
function paste(clipboardData, options) {
|
|
3759
|
-
return setupDirect(options).api.paste(clipboardData);
|
|
3760
|
-
}
|
|
3761
|
-
function selectOptions(select, values, options = {}) {
|
|
3762
|
-
return setupDirect(options).api.selectOptions(select, values);
|
|
3763
|
-
}
|
|
3764
|
-
function tripleClick(element, options = {}) {
|
|
3765
|
-
return setupDirect(options).api.tripleClick(element);
|
|
3766
|
-
}
|
|
3767
|
-
function type(element, text, options = {}) {
|
|
3768
|
-
return setupDirect(options, element).api.type(element, text, options);
|
|
3769
|
-
}
|
|
3770
|
-
function unhover(element, options = {}) {
|
|
3771
|
-
const { api, system } = setupDirect(options);
|
|
3772
|
-
system.pointer.setMousePosition({ target: element });
|
|
3773
|
-
return api.unhover(element);
|
|
3774
|
-
}
|
|
3775
|
-
function upload(element, fileOrFiles, options = {}) {
|
|
3776
|
-
return setupDirect(options).api.upload(element, fileOrFiles);
|
|
3777
|
-
}
|
|
3778
|
-
function tab(options = {}) {
|
|
3779
|
-
return setupDirect().api.tab(options);
|
|
3780
|
-
}
|
|
3781
|
-
|
|
3782
|
-
// src/setup/setup.ts
|
|
3783
|
-
/**
|
|
3784
|
-
* Default options applied when API is called per `userEvent.anyApi()`
|
|
3785
|
-
*/
|
|
3786
|
-
const defaultOptionsDirect = {
|
|
3787
|
-
applyAccept: true,
|
|
3788
|
-
autoModify: true,
|
|
3789
|
-
delay: 0,
|
|
3790
|
-
get document() {
|
|
3791
|
-
return globalThis.document;
|
|
3792
|
-
},
|
|
3793
|
-
keyboardMap: defaultKeyMap$1,
|
|
3794
|
-
pointerMap: defaultKeyMap,
|
|
3795
|
-
pointerEventsCheck: PointerEventsCheckLevel.EachApiCall,
|
|
3796
|
-
skipAutoClose: false,
|
|
3797
|
-
skipClick: false,
|
|
3798
|
-
skipHover: false,
|
|
3799
|
-
writeToClipboard: false,
|
|
3800
|
-
advanceTimers: defaultAdvanceTimers
|
|
3801
|
-
};
|
|
3802
|
-
/**
|
|
3803
|
-
* Default options applied when API is called per `userEvent().anyApi()`
|
|
3804
|
-
*/
|
|
3805
|
-
const defaultOptionsSetup = {
|
|
3806
|
-
...defaultOptionsDirect,
|
|
3807
|
-
writeToClipboard: true
|
|
3808
|
-
};
|
|
3809
|
-
Object.defineProperty(defaultOptionsSetup, "document", {
|
|
3810
|
-
get: () => globalThis.document,
|
|
3811
|
-
enumerable: true
|
|
3812
|
-
});
|
|
3813
|
-
function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
|
|
3814
|
-
const document = getDocument(options, node, defaults);
|
|
3815
|
-
return {
|
|
3816
|
-
...defaults,
|
|
3817
|
-
...options,
|
|
3818
|
-
document
|
|
3819
|
-
};
|
|
3820
|
-
}
|
|
3821
|
-
/**
|
|
3822
|
-
* Start a "session" with userEvent.
|
|
3823
|
-
* All APIs returned by this function share an input device state and a default configuration.
|
|
3824
|
-
*/
|
|
3825
|
-
function setupMain(options = {}) {
|
|
3826
|
-
const config = createConfig(options);
|
|
3827
|
-
prepareDocument(config.document);
|
|
3828
|
-
patchFocus(getWindow(config.document).HTMLElement);
|
|
3829
|
-
const view = config.document.defaultView ??
|
|
3830
|
-
/* istanbul ignore next */ globalThis.window;
|
|
3831
|
-
attachClipboardStubToView(view);
|
|
3832
|
-
return createInstance(config).api;
|
|
3833
|
-
}
|
|
3834
|
-
/**
|
|
3835
|
-
* Setup in direct call per `userEvent.anyApi()`
|
|
3836
|
-
*/
|
|
3837
|
-
function setupDirect({ keyboardState, pointerState, ...options } = {}, node) {
|
|
3838
|
-
const config = createConfig(options, defaultOptionsDirect, node);
|
|
3839
|
-
prepareDocument(config.document);
|
|
3840
|
-
patchFocus(getWindow(config.document).HTMLElement);
|
|
3841
|
-
const system = pointerState ?? keyboardState ?? new System();
|
|
3842
|
-
return {
|
|
3843
|
-
api: createInstance(config, system).api,
|
|
3844
|
-
system
|
|
3845
|
-
};
|
|
3846
|
-
}
|
|
3847
|
-
/**
|
|
3848
|
-
* Create a set of callbacks with different default settings but the same state.
|
|
3849
|
-
*/
|
|
3850
|
-
function setupSub(options) {
|
|
3851
|
-
return createInstance({
|
|
3852
|
-
...this.config,
|
|
3853
|
-
...options
|
|
3854
|
-
}, this.system).api;
|
|
3855
|
-
}
|
|
3856
|
-
function wrapAndBindImpl(instance, impl, name = impl.name) {
|
|
3857
|
-
function method(...args) {
|
|
3858
|
-
setLevelRef(instance, ApiLevel.Call);
|
|
3859
|
-
const run = () => wrapAsync(() => {
|
|
3860
|
-
markTimers(instance.config);
|
|
3861
|
-
return impl.apply(instance, args).then(async (ret) => {
|
|
3862
|
-
await yieldBetweenActions(instance.config);
|
|
3863
|
-
return ret;
|
|
3864
|
-
});
|
|
3865
|
-
});
|
|
3866
|
-
const pending = resolveConfigSource();
|
|
3867
|
-
const go = () => pending === void 0 ? run() : pending.then(run);
|
|
3868
|
-
if (!tracing()) return go();
|
|
3869
|
-
return tracePromise(`user-event.${name}`, describeCall(`user.${name}`, args), go);
|
|
3870
|
-
}
|
|
3871
|
-
Object.defineProperty(method, "name", { get: () => impl.name });
|
|
3872
|
-
return method;
|
|
3873
|
-
}
|
|
3874
|
-
function createInstance(config, system = new System()) {
|
|
3875
|
-
const instance = {};
|
|
3876
|
-
Object.assign(instance, {
|
|
3877
|
-
config,
|
|
3878
|
-
dispatchEvent: dispatchEvent.bind(instance),
|
|
3879
|
-
dispatchUIEvent: dispatchUIEvent.bind(instance),
|
|
3880
|
-
system,
|
|
3881
|
-
levelRefs: {},
|
|
3882
|
-
...userEventApi
|
|
3883
|
-
});
|
|
3884
|
-
return {
|
|
3885
|
-
instance,
|
|
3886
|
-
api: {
|
|
3887
|
-
...Object.fromEntries(Object.entries(userEventApi).map(([name, api]) => [name, wrapAndBindImpl(instance, api, name)])),
|
|
3888
|
-
setup: setupSub.bind(instance)
|
|
3889
|
-
}
|
|
3890
|
-
};
|
|
3891
|
-
}
|
|
3892
|
-
function getDocument(options, node, defaults) {
|
|
3893
|
-
return options.document ?? (node && getDocumentFromNode(node)) ?? defaults.document;
|
|
3894
|
-
}
|
|
3895
|
-
|
|
3896
|
-
// src/setup/index.ts
|
|
3897
|
-
const userEvent = {
|
|
3898
|
-
...directApi_exports,
|
|
3899
|
-
setup: setupMain
|
|
3900
|
-
};
|
|
3901
|
-
|
|
3902
|
-
export { PointerEventsCheckLevel, userEvent as default, userEvent };
|
|
33
|
+
function buildEventConstructors(e){let t=/* @__PURE__ */ new Set;for(let n of[`Event`,`AnimationEvent`,`ClipboardEvent`,`PopStateEvent`,`ProgressEvent`,`TransitionEvent`,`UIEvent`,`CompositionEvent`,`FocusEvent`,`InputEvent`,`KeyboardEvent`,`MouseEvent`,`DragEvent`,`PointerEvent`,`TouchEvent`])e[n]===void 0&&t.add(n);let n=e.Event??class Event{},r=e.AnimationEvent??class AnimationEvent extends n{},i=e.ClipboardEvent??class ClipboardEvent extends n{},a=e.PopStateEvent??class PopStateEvent extends n{},o=e.ProgressEvent??class ProgressEvent extends n{},s=e.TransitionEvent??class TransitionEvent extends n{},c=e.UIEvent??class UIEvent extends n{},l=e.CompositionEvent??class CompositionEvent extends c{},u=e.FocusEvent??class FocusEvent extends c{},d=e.InputEvent??class InputEvent extends c{},f=e.KeyboardEvent??class KeyboardEvent extends c{},p=e.MouseEvent??class MouseEvent extends c{};return{fallbacks:t,Event:n,AnimationEvent:r,ClipboardEvent:i,PopStateEvent:a,ProgressEvent:o,TransitionEvent:s,UIEvent:c,CompositionEvent:l,FocusEvent:u,InputEvent:d,KeyboardEvent:f,MouseEvent:p,DragEvent:e.DragEvent??class DragEvent extends p{},PointerEvent:e.PointerEvent??class PointerEvent extends p{},TouchEvent:e.TouchEvent??class TouchEvent extends c{}}}function assignProps(e,t){for(let[n,r]of Object.entries(t))Object.defineProperty(e,n,{get:()=>r??null})}function sanitizeNumber(e){return Number(e??0)}function initClipboardEvent(e,{clipboardData:t}){assignProps(e,{clipboardData:t})}function initFocusEvent(e,{relatedTarget:t}){assignProps(e,{relatedTarget:t})}function initInputEvent(e,{data:t,inputType:n,isComposing:r}){assignProps(e,{data:t,isComposing:!!r,inputType:String(n)})}function initUIEvent(e,{view:t,detail:n}){assignProps(e,{view:t,detail:sanitizeNumber(n??0)})}function initUIEventModifiers(e,{altKey:t,ctrlKey:n,metaKey:r,shiftKey:i,modifierAltGraph:a,modifierCapsLock:o,modifierFn:s,modifierFnLock:c,modifierNumLock:l,modifierScrollLock:u,modifierSymbol:d,modifierSymbolLock:f}){assignProps(e,{altKey:!!t,ctrlKey:!!n,metaKey:!!r,shiftKey:!!i,getModifierState(e){return!!{Alt:t,AltGraph:a,CapsLock:o,Control:n,Fn:s,FnLock:c,Meta:r,NumLock:l,ScrollLock:u,Shift:i,Symbol:d,SymbolLock:f}[e]}})}function initKeyboardEvent(e,{key:t,code:n,location:r,repeat:i,isComposing:a,charCode:o}){assignProps(e,{key:String(t),code:String(n),location:sanitizeNumber(r),repeat:!!i,isComposing:!!a,charCode:o})}function initMouseEvent(e,{x:t,y:n,screenX:r,screenY:i,clientX:a=t,clientY:o=n,button:s,buttons:c,relatedTarget:l,offsetX:u,offsetY:d,pageX:f,pageY:p}){assignProps(e,{screenX:sanitizeNumber(r),screenY:sanitizeNumber(i),clientX:sanitizeNumber(a),x:sanitizeNumber(a),clientY:sanitizeNumber(o),y:sanitizeNumber(o),button:sanitizeNumber(s),buttons:sanitizeNumber(c),relatedTarget:l,offsetX:sanitizeNumber(u),offsetY:sanitizeNumber(d),pageX:sanitizeNumber(f),pageY:sanitizeNumber(p)})}function initPointerEvent(e,{pointerId:t,width:n,height:r,pressure:i,tangentialPressure:a,tiltX:o,tiltY:s,twist:c,pointerType:l,isPrimary:u,buttons:d}){assignProps(e,{pointerId:sanitizeNumber(t),width:sanitizeNumber(n??1),height:sanitizeNumber(r??1),pressure:sanitizeNumber(i??(d?.5:0)),tangentialPressure:sanitizeNumber(a),tiltX:sanitizeNumber(o),tiltY:sanitizeNumber(s),twist:sanitizeNumber(c),pointerType:String(l??``),isPrimary:!!u})}function dispatchUIEvent(e,t,n,r=!1){let i=createEvent(t,e,n,isMouseEvent(t)||isKeyboardEvent(t)?this.system:void 0);return dispatchEvent.call(this,e,i,r)}function dispatchEvent(e,t,n=!1){let r=t.type,i=n?()=>{}:G[r]?.(t,e,this);if(i){t.preventDefault();let n=!1;return Object.defineProperty(t,"defaultPrevented",{get:()=>n}),Object.defineProperty(t,"preventDefault",{value:()=>{n=t.cancelable}}),wrapEvent(()=>e.dispatchEvent(t),e),n||i(),!n}return wrapEvent(()=>e.dispatchEvent(t),e)}function dispatchDOMEvent(e,t,n){let r=createEvent(t,e,n);wrapEvent(()=>e.dispatchEvent(r),e)}const q=Symbol(`patched focus/blur methods`);function patchFocus(e){let t=e.prototype;if(t[q])return;let{focus:n,blur:r}=t;Object.defineProperties(e.prototype,{focus:{configurable:!0,value:patchedFocus,writable:!0},blur:{configurable:!0,value:patchedBlur,writable:!0},[q]:{configurable:!0,get:()=>({focus:n,blur:r})}});let i;function patchedFocus(e){if(this.ownerDocument.visibilityState!==`hidden`)return n.call(this,e);let t=getActiveTarget(this.ownerDocument);if(t===this)return;let a=Symbol(`focus call`);i=a,t&&(r.call(t),dispatchDOMEvent(t,`blur`,{relatedTarget:this}),dispatchDOMEvent(t,`focusout`,{relatedTarget:i===a?this:null})),i===a&&(n.call(this,e),dispatchDOMEvent(this,`focus`,{relatedTarget:t})),i===a&&dispatchDOMEvent(this,`focusin`,{relatedTarget:t})}function patchedBlur(){if(this.ownerDocument.visibilityState!==`hidden`)return r.call(this);let e=getActiveTarget(this.ownerDocument);e===this&&(i=Symbol(`blur call`),r.call(this),dispatchDOMEvent(e,`blur`,{relatedTarget:null}),dispatchDOMEvent(e,`focusout`,{relatedTarget:null}))}}function getActiveTarget(e){let t=getActiveElement(e);return t?.tagName===`BODY`?null:t}const J=Symbol(`Interceptor for programmatical calls`);function prepareInterceptor(e,t,n){let r=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),i=Object.getOwnPropertyDescriptor(e,t),a=r?.set?`set`:`value`;
|
|
34
|
+
/* istanbul ignore if */
|
|
35
|
+
if(typeof r?.[a]!=`function`||r[a][J])throw Error(`Element ${e.tagName} does not implement "${String(t)}".`);function intercept(...e){let{applyNative:t=!1,realArgs:o,then:s}=n.call(this,...e),c=(!t&&i?i:r)?.[a];a===`set`?c.call(this,o):c.call(this,...o),s?.()}intercept[J]=J,Object.defineProperty(e,t,{...i??r,[a]:intercept})}function prepareValueInterceptor(e){prepareInterceptor(e,`value`,function interceptorImpl(e){let t=e===null?``:e,n=isUIValue(t);return n&&startTrackValue(this),{applyNative:!!n,realArgs:sanitizeValue(this,t),then:n?void 0:()=>trackOrSetValue(this,String(t))}})}function sanitizeValue(e,t){return isElementType(e,`input`,{type:`number`})&&String(t)!==``&&!Number.isNaN(Number(t))?String(Number(t)):String(t)}function prepareSelectionInterceptor(e){prepareInterceptor(e,`setSelectionRange`,function interceptorImpl(t,...n){let r=isUISelectionStart(t);return{applyNative:!!r,realArgs:[Number(t),...n],then:()=>r?void 0:setUISelectionClean(e)}}),prepareInterceptor(e,`selectionStart`,function interceptorImpl(t){return{realArgs:t,then:()=>setUISelectionClean(e)}}),prepareInterceptor(e,`selectionEnd`,function interceptorImpl(t){return{realArgs:t,then:()=>setUISelectionClean(e)}}),prepareInterceptor(e,`select`,function interceptorImpl(){return{realArgs:[],then:()=>setUISelectionRaw(e,{anchorOffset:0,focusOffset:getUIValue(e).length})}})}function prepareRangeTextInterceptor(e){prepareInterceptor(e,`setRangeText`,function interceptorImpl(...t){return{realArgs:t,then:()=>{setUIValueClean(e),setUISelectionClean(e)}}})}const Y=Symbol(`Node prepared with document state workarounds`);function prepareDocument(e){e[Y]||(e.addEventListener(`focus`,e=>{let t=e.target;prepareElement(t)},{capture:!0,passive:!0}),e.activeElement&&prepareElement(e.activeElement),e.addEventListener(`blur`,e=>{let t=e.target,n=getInitialValue(t);n!==void 0&&(t.value!==n&&dispatchDOMEvent(t,`change`),clearInitialValue(t))},{capture:!0,passive:!0}),e[Y]=Y)}function prepareElement(e){e[Y]||(isElementType(e,[`input`,`textarea`])&&!hasCtrlDomUI(e)&&(prepareValueInterceptor(e),prepareSelectionInterceptor(e),prepareRangeTextInterceptor(e)),e[Y]=Y)}const de=[...`0123456789`.split(``).map(e=>({code:`Digit${e}`,key:e})),...`)!@#$%^&*(`.split(``).map((e,t)=>({code:`Digit${t}`,key:e,shiftKey:!0})),...`abcdefghijklmnopqrstuvwxyz`.split(``).map(e=>({code:`Key${e.toUpperCase()}`,key:e})),...`ABCDEFGHIJKLMNOPQRSTUVWXYZ`.split(``).map(e=>({code:`Key${e}`,key:e,shiftKey:!0})),{code:`BracketLeft`,key:`[`},{code:`BracketLeft`,key:`{`,shiftKey:!0},{code:`BracketRight`,key:`]`},{code:`BracketRight`,key:`}`,shiftKey:!0},{code:`Space`,key:` `},{code:`AltLeft`,key:`Alt`,location:M.LEFT},{code:`AltRight`,key:`Alt`,location:M.RIGHT},{code:`ShiftLeft`,key:`Shift`,location:M.LEFT},{code:`ShiftRight`,key:`Shift`,location:M.RIGHT},{code:`ControlLeft`,key:`Control`,location:M.LEFT},{code:`ControlRight`,key:`Control`,location:M.RIGHT},{code:`MetaLeft`,key:`Meta`,location:M.LEFT},{code:`MetaRight`,key:`Meta`,location:M.RIGHT},{code:`OSLeft`,key:`OS`,location:M.LEFT},{code:`OSRight`,key:`OS`,location:M.RIGHT},{code:`ContextMenu`,key:`ContextMenu`},{code:`Tab`,key:`Tab`},{code:`CapsLock`,key:`CapsLock`},{code:`Backspace`,key:`Backspace`},{code:`Enter`,key:`Enter`},{code:`Escape`,key:`Escape`},{code:`ArrowUp`,key:`ArrowUp`},{code:`ArrowDown`,key:`ArrowDown`},{code:`ArrowLeft`,key:`ArrowLeft`},{code:`ArrowRight`,key:`ArrowRight`},{code:`Home`,key:`Home`},{code:`End`,key:`End`},{code:`Delete`,key:`Delete`},{code:`PageUp`,key:`PageUp`},{code:`PageDown`,key:`PageDown`},{code:`Fn`,key:`Fn`},{code:`Symbol`,key:`Symbol`},{code:`AltRight`,key:`AltGraph`}],fe=[{name:`MouseLeft`,pointerType:`mouse`,button:`primary`},{name:`MouseRight`,pointerType:`mouse`,button:`secondary`},{name:`MouseMiddle`,pointerType:`mouse`,button:`auxiliary`},{name:`TouchA`,pointerType:`touch`},{name:`TouchB`,pointerType:`touch`},{name:`TouchC`,pointerType:`touch`}];function parseKeyDef$1(e,t){let n=[];do{let{descriptor:r,consumedLength:i,releasePrevious:a,releaseSelf:o=!0}=readNextDescriptor(t,`pointer`),s=e.find(e=>e.name===r);s&&n.push({keyDef:s,releasePrevious:a,releaseSelf:o}),t=t.slice(i)}while(t);return n}__name(parseKeyDef$1,`parseKeyDef`);async function pointer$1(e){let{pointerMap:t}=this.config,n=[];(Array.isArray(e)?e:[e]).forEach(e=>{typeof e==`string`?n.push(...parseKeyDef$1(t,e)):`keys`in e?n.push(...parseKeyDef$1(t,e.keys).map(t=>({...e,...t}))):n.push(e)});for(let e=0;e<n.length;e++)await yieldBetweenActions(this.config),await pointerAction(this,n[e]);this.system.pointer.resetClickCount()}__name(pointer$1,`pointer`);async function pointerAction(e,t){let n=`pointerName`in t&&t.pointerName?t.pointerName:`keyDef`in t?e.system.pointer.getPointerName(t.keyDef):`mouse`,r=e.system.pointer.getPreviousPosition(n),i={target:t.target??getPrevTarget(e,r),coords:t.coords??r?.coords,caret:{node:t.node??(hasCaretPosition(t)?void 0:r?.caret?.node),offset:t.offset??(hasCaretPosition(t)?void 0:r?.caret?.offset)}};`keyDef`in t?(e.system.pointer.isKeyPressed(t.keyDef)&&(setLevelRef(e,b.Trigger),await e.system.pointer.release(e,t.keyDef,i)),t.releasePrevious||(setLevelRef(e,b.Trigger),await e.system.pointer.press(e,t.keyDef,i),t.releaseSelf&&(setLevelRef(e,b.Trigger),await e.system.pointer.release(e,t.keyDef,i)))):(setLevelRef(e,b.Trigger),await e.system.pointer.move(e,n,i))}function hasCaretPosition(e){return!!(e.target??e.node??e.offset!==void 0)}function getPrevTarget(e,t){if(!t)throw Error(`This pointer has no previous position. Provide a target property!`);return t.target??e.config.document.body}async function click$1(e){let t=[];return this.config.skipHover||t.push({target:e}),t.push({keys:`[MouseLeft]`,target:e}),this.pointer(t)}__name(click$1,`click`);async function dblClick$1(e){return this.pointer([{target:e},`[MouseLeft][MouseLeft]`])}__name(dblClick$1,`dblClick`);async function tripleClick$1(e){return this.pointer([{target:e},`[MouseLeft][MouseLeft][MouseLeft]`])}__name(tripleClick$1,`tripleClick`);async function hover$1(e){return this.pointer({target:e})}__name(hover$1,`hover`);async function unhover$1(e){return assertPointerEvents(this,this.system.pointer.getMouseTarget(this)),this.pointer({target:e.ownerDocument.body})}__name(unhover$1,`unhover`);async function tab$1({shift:e}={}){return this.keyboard(e===!0?`{Shift>}{Tab}{/Shift}`:e===!1?`[/ShiftLeft][/ShiftRight]{Tab}`:`{Tab}`)}__name(tab$1,`tab`);function parseKeyDef(e,t){let n=[];do{let{type:r,descriptor:i,consumedLength:a,releasePrevious:o,releaseSelf:s=!0,repeat:c}=readNextDescriptor(t,`keyboard`),l=e.find(e=>r===`[`?e.code?.toLowerCase()===i.toLowerCase():r===`{`?e.key?.toLowerCase()===i.toLowerCase():e.key===i)??{key:`Unknown`,code:`Unknown`,[r===`[`?`code`:`key`]:i};n.push({keyDef:l,releasePrevious:o,releaseSelf:s,repeat:c}),t=t.slice(a)}while(t);return n}async function keyboard$1(e){let t=parseKeyDef(this.config.keyboardMap,e);for(let e=0;e<t.length;e++)await yieldBetweenActions(this.config),await keyboardAction(this,t[e])}__name(keyboard$1,`keyboard`);async function keyboardAction(e,{keyDef:t,releasePrevious:n,releaseSelf:r,repeat:i}){let{system:a}=e;if(a.keyboard.isKeyPressed(t)&&await a.keyboard.keyup(e,t),!n){for(let n=1;n<=i;n++)await a.keyboard.keydown(e,t,n>1),n<i&&await yieldBetweenActions(e.config);r&&await a.keyboard.keyup(e,t)}}async function releaseAllKeys(e){for(let t of e.system.keyboard.getPressedKeys())await e.system.keyboard.keyup(e,t)}async function copy$1(){let e=this.config.document,t=e.activeElement??/* istanbul ignore next */e.body,n=copySelection(t);if(n.items.length!==0)return this.dispatchUIEvent(t,`copy`,{clipboardData:n})&&this.config.writeToClipboard&&await writeDataTransferToClipboard(e,n),n}__name(copy$1,`copy`);async function cut$1(){let e=this.config.document,t=e.activeElement??/* istanbul ignore next */e.body,n=copySelection(t);if(n.items.length!==0)return this.dispatchUIEvent(t,`cut`,{clipboardData:n})&&this.config.writeToClipboard&&await writeDataTransferToClipboard(t.ownerDocument,n),n}__name(cut$1,`cut`);async function paste$1(e){let t=this.config.document,n=t.activeElement??/* istanbul ignore next */t.body,r=(typeof e==`string`?getClipboardDataFromString(t,e):e)??await readDataTransferFromClipboard(t).catch(()=>{throw Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.")});this.dispatchUIEvent(n,`paste`,{clipboardData:r})}__name(paste$1,`paste`);function getClipboardDataFromString(e,t){let n=createDataTransfer(getWindow(e));return n.setData(`text`,t),n}async function clear$1(e){if(!isEditable(e)||isDisabled(e))throw Error("clear()` is only supported on editable elements.");if(focusElement(e),e.ownerDocument.activeElement!==e)throw Error(`The element to be cleared could not be focused.`);if(selectAll(e),!isAllSelected(e))throw Error(`The element content to be cleared could not be selected.`);input(this,e,``,`deleteContentBackward`)}__name(clear$1,`clear`);async function selectOptions$1(e,t){return selectOptionsBase.call(this,!0,e,t)}__name(selectOptions$1,`selectOptions`);async function deselectOptions$1(e,t){return selectOptionsBase.call(this,!1,e,t)}__name(deselectOptions$1,`deselectOptions`);async function selectOptionsBase(e,t,n){if(!e&&!t.multiple)throw getConfig().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`,t);let r=Array.isArray(n)?n:[n],i=Array.from(t.querySelectorAll(`option, [role="option"]`)),a=r.map(e=>{if(typeof e!=`string`&&i.includes(e))return e;{let n=i.find(t=>t.value===e||t.innerHTML===e);if(n)return n;throw getConfig().getElementError(`Value "${String(e)}" not found in options`,t)}}).filter(e=>!isDisabled(e));if(isDisabled(t)||!a.length)return;let selectOption=n=>{n.selected=e,this.dispatchUIEvent(t,`input`,{bubbles:!0,cancelable:!1,composed:!0}),this.dispatchUIEvent(t,`change`)};if(isElementType(t,`select`)){if(t.multiple)for(let e of a){let n=this.config.pointerEventsCheck===0||hasPointerEvents(this,e);n&&(this.dispatchUIEvent(e,`pointerover`),this.dispatchUIEvent(t,`pointerenter`),this.dispatchUIEvent(e,`mouseover`),this.dispatchUIEvent(t,`mouseenter`),this.dispatchUIEvent(e,`pointermove`),this.dispatchUIEvent(e,`mousemove`),this.dispatchUIEvent(e,`pointerdown`),this.dispatchUIEvent(e,`mousedown`)),focusElement(t),n&&(this.dispatchUIEvent(e,`pointerup`),this.dispatchUIEvent(e,`mouseup`)),selectOption(e),n&&this.dispatchUIEvent(e,`click`),await yieldBetweenActions(this.config)}else if(a.length===1){let e=this.config.pointerEventsCheck===0||hasPointerEvents(this,t);e?await this.click(t):focusElement(t),selectOption(a[0]),e&&(this.dispatchUIEvent(t,`pointerover`),this.dispatchUIEvent(t,`pointerenter`),this.dispatchUIEvent(t,`mouseover`),this.dispatchUIEvent(t,`mouseenter`),this.dispatchUIEvent(t,`pointerup`),this.dispatchUIEvent(t,`mouseup`),this.dispatchUIEvent(t,`click`)),await yieldBetweenActions(this.config)}else throw getConfig().getElementError(`Cannot select multiple options on a non-multiple select`,t)}else if(t.getAttribute(`role`)===`listbox`)for(let e of a)await this.click(e),await this.unhover(e);else throw getConfig().getElementError(`Cannot select options on elements that are neither select nor listbox elements`,t)}async function type$1(e,t,{skipClick:n=this.config.skipClick,skipAutoClose:r=this.config.skipAutoClose,initialSelectionStart:i,initialSelectionEnd:a}={}){e.disabled||(n||await this.click(e),i!==void 0&&setSelectionRange(e,i,a??i),await this.keyboard(t),r||await releaseAllKeys(this))}__name(type$1,`type`);async function upload$1(e,t){let n=isElementType(e,`label`)?e.control:e;if(!n||!isElementType(n,`input`,{type:`file`}))throw TypeError(`The ${n===e?`given`:`associated`} ${n?.tagName} element does not accept file uploads`);if(isDisabled(e))return;let r=(Array.isArray(t)?t:[t]).filter(e=>!this.config.applyAccept||isAcceptableFile(e,n.accept)).slice(0,n.multiple?void 0:1),fileDialog=()=>{r.length===n.files?.length&&r.every((e,t)=>e===n.files?.item(t))||(setFiles(n,createFileList(getWindow(e),r)),this.dispatchUIEvent(n,`input`),this.dispatchUIEvent(n,`change`))};n.addEventListener(`fileDialog`,fileDialog),await this.click(e),n.removeEventListener(`fileDialog`,fileDialog)}__name(upload$1,`upload`);function normalize(e){return e.toLowerCase().replace(/(\.|\/)jpg\b/g,`$1jpeg`)}function isAcceptableFile(e,t){if(!t)return!0;let n=[`audio/*`,`image/*`,`video/*`];return normalize(t).trim().split(/\s*,\s*/).some(t=>t.startsWith(`.`)?normalize(e.name).endsWith(t):n.includes(t)?normalize(e.type).startsWith(t.replace(`*`,``)):normalize(e.type)===t)}const X={click:click$1,dblClick:dblClick$1,tripleClick:tripleClick$1,hover:hover$1,unhover:unhover$1,tab:tab$1,keyboard:keyboard$1,copy:copy$1,cut:cut$1,paste:paste$1,pointer:pointer$1,clear:clear$1,deselectOptions:deselectOptions$1,selectOptions:selectOptions$1,type:type$1,upload:upload$1};function wrapAsync(e){return getConfig().asyncWrapper(e)}var pe=/* @__PURE__ */ __exportAll({clear:()=>clear,click:()=>click,copy:()=>copy,cut:()=>cut,dblClick:()=>dblClick,deselectOptions:()=>deselectOptions,hover:()=>hover,keyboard:()=>keyboard,paste:()=>paste,pointer:()=>pointer,selectOptions:()=>selectOptions,tab:()=>tab,tripleClick:()=>tripleClick,type:()=>type,unhover:()=>unhover,upload:()=>upload});function clear(e){return setupDirect().api.clear(e)}function click(e,t={}){return setupDirect(t,e).api.click(e)}function copy(e={}){return setupDirect(e).api.copy()}function cut(e={}){return setupDirect(e).api.cut()}function dblClick(e,t={}){return setupDirect(t).api.dblClick(e)}function deselectOptions(e,t,n={}){return setupDirect(n).api.deselectOptions(e,t)}function hover(e,t={}){return setupDirect(t).api.hover(e)}async function keyboard(e,t={}){let{api:n,system:r}=setupDirect(t);return n.keyboard(e).then(()=>r)}async function pointer(e,t={}){let{api:n,system:r}=setupDirect(t);return n.pointer(e).then(()=>r)}function paste(e,t){return setupDirect(t).api.paste(e)}function selectOptions(e,t,n={}){return setupDirect(n).api.selectOptions(e,t)}function tripleClick(e,t={}){return setupDirect(t).api.tripleClick(e)}function type(e,t,n={}){return setupDirect(n,e).api.type(e,t,n)}function unhover(e,t={}){let{api:n,system:r}=setupDirect(t);return r.pointer.setMousePosition({target:e}),n.unhover(e)}function upload(e,t,n={}){return setupDirect(n).api.upload(e,t)}function tab(e={}){return setupDirect().api.tab(e)}const Z={applyAccept:!0,autoModify:!0,delay:0,get document(){return globalThis.document},keyboardMap:de,pointerMap:fe,pointerEventsCheck:N.EachApiCall,skipAutoClose:!1,skipClick:!1,skipHover:!1,writeToClipboard:!1,advanceTimers:defaultAdvanceTimers},Q={...Z,writeToClipboard:!0};Object.defineProperty(Q,"document",{get:()=>globalThis.document,enumerable:!0});function createConfig(e={},t=Q,n){let r=getDocument(e,n,t);return{...t,...e,document:r}}function setupMain(e={}){let t=createConfig(e);return prepareDocument(t.document),patchFocus(getWindow(t.document).HTMLElement),attachClipboardStubToView(t.document.defaultView??
|
|
36
|
+
/* istanbul ignore next */globalThis.window),createInstance(t).api}function setupDirect({keyboardState:e,pointerState:t,...n}={},r){let i=createConfig(n,Z,r);prepareDocument(i.document),patchFocus(getWindow(i.document).HTMLElement);let a=t??e??new System;return{api:createInstance(i,a).api,system:a}}function setupSub(e){return createInstance({...this.config,...e},this.system).api}function wrapAndBindImpl(e,t,n=t.name){function method(...o){setLevelRef(e,b.Call);let run=()=>wrapAsync(()=>(markTimers(e.config),t.apply(e,o).then(async t=>(await yieldBetweenActions(e.config),t)))),s=resolveConfigSource(),go=()=>s===void 0?run():s.then(run);return a()?i(`user-event.${n}`,r(`user.${n}`,o),go):go()}return Object.defineProperty(method,"name",{get:()=>t.name}),method}function createInstance(e,t=new System){let n={};return Object.assign(n,{config:e,dispatchEvent:dispatchEvent.bind(n),dispatchUIEvent:dispatchUIEvent.bind(n),system:t,levelRefs:{},...X}),{instance:n,api:{...Object.fromEntries(Object.entries(X).map(([e,t])=>[e,wrapAndBindImpl(n,t,e)])),setup:setupSub.bind(n)}}}function getDocument(e,t,n){return e.document??(t&&getDocumentFromNode(t))??n.document}const $={...pe,setup:setupMain};export{N as PointerEventsCheckLevel,$ as default,$ as userEvent};
|