@testing-library/user-event 14.0.0-beta.4 → 14.0.0-beta.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.
Files changed (93) hide show
  1. package/dist/index.cjs +2760 -0
  2. package/dist/{index.js → index.mjs} +0 -0
  3. package/dist/types/clipboard/copy.d.ts +2 -0
  4. package/dist/types/clipboard/cut.d.ts +2 -0
  5. package/dist/types/clipboard/index.d.ts +3 -0
  6. package/dist/types/clipboard/paste.d.ts +2 -0
  7. package/dist/types/convenience/click.d.ts +4 -0
  8. package/dist/types/convenience/hover.d.ts +3 -0
  9. package/dist/types/convenience/index.d.ts +3 -0
  10. package/dist/types/convenience/tab.d.ts +4 -0
  11. package/dist/types/document/index.d.ts +10 -0
  12. package/dist/types/document/interceptor.d.ts +15 -0
  13. package/dist/types/document/selection.d.ts +27 -0
  14. package/dist/types/document/value.d.ts +18 -0
  15. package/dist/types/index.d.ts +3 -0
  16. package/dist/types/keyboard/index.d.ts +7 -0
  17. package/dist/types/keyboard/keyMap.d.ts +5 -0
  18. package/dist/types/keyboard/keyboardAction.d.ts +10 -0
  19. package/dist/types/keyboard/parseKeyDef.d.ts +17 -0
  20. package/dist/types/keyboard/plugins/arrow.d.ts +6 -0
  21. package/dist/types/keyboard/plugins/character.d.ts +5 -0
  22. package/dist/types/keyboard/plugins/combination.d.ts +5 -0
  23. package/dist/types/keyboard/plugins/control.d.ts +6 -0
  24. package/dist/types/keyboard/plugins/functional.d.ts +8 -0
  25. package/dist/types/keyboard/plugins/index.d.ts +7 -0
  26. package/dist/types/keyboard/plugins/modifiers.d.ts +8 -0
  27. package/dist/types/keyboard/shared/fireChangeForInputTimeIfValid.d.ts +3 -0
  28. package/dist/types/keyboard/shared/index.d.ts +1 -0
  29. package/dist/types/keyboard/types.d.ts +78 -0
  30. package/dist/types/options.d.ts +102 -0
  31. package/dist/types/pointer/index.d.ts +10 -0
  32. package/dist/types/pointer/keyMap.d.ts +2 -0
  33. package/dist/types/pointer/parseKeyDef.d.ts +6 -0
  34. package/dist/types/pointer/pointerAction.d.ts +7 -0
  35. package/dist/types/pointer/pointerMove.d.ts +6 -0
  36. package/dist/types/pointer/pointerPress.d.ts +8 -0
  37. package/dist/types/pointer/resolveSelectionTarget.d.ts +5 -0
  38. package/dist/types/pointer/types.d.ts +61 -0
  39. package/dist/types/setup/api.d.ts +5 -0
  40. package/dist/types/setup/config.d.ts +10 -0
  41. package/dist/types/setup/directApi.d.ts +20 -0
  42. package/dist/types/setup/index.d.ts +30 -0
  43. package/dist/types/setup/setup.d.ts +74 -0
  44. package/dist/types/setup/wrapAsync.d.ts +4 -0
  45. package/dist/types/utility/clear.d.ts +2 -0
  46. package/dist/types/utility/index.d.ts +4 -0
  47. package/dist/types/utility/selectOptions.d.ts +3 -0
  48. package/dist/types/utility/type.d.ts +9 -0
  49. package/dist/types/utility/upload.d.ts +5 -0
  50. package/dist/types/utils/click/isClickableInput.d.ts +1 -0
  51. package/dist/types/utils/dataTransfer/Blob.d.ts +1 -0
  52. package/dist/types/utils/dataTransfer/Clipboard.d.ts +9 -0
  53. package/dist/types/utils/dataTransfer/DataTransfer.d.ts +2 -0
  54. package/dist/types/utils/dataTransfer/FileList.d.ts +1 -0
  55. package/dist/types/utils/edit/buildTimeValue.d.ts +1 -0
  56. package/dist/types/utils/edit/calculateNewValue.d.ts +14 -0
  57. package/dist/types/utils/edit/editInputElement.d.ts +16 -0
  58. package/dist/types/utils/edit/getValue.d.ts +1 -0
  59. package/dist/types/utils/edit/isContentEditable.d.ts +7 -0
  60. package/dist/types/utils/edit/isEditable.d.ts +25 -0
  61. package/dist/types/utils/edit/isValidDateValue.d.ts +3 -0
  62. package/dist/types/utils/edit/isValidInputTimeValue.d.ts +3 -0
  63. package/dist/types/utils/edit/maxLength.d.ts +1 -0
  64. package/dist/types/utils/edit/prepareInput.d.ts +7 -0
  65. package/dist/types/utils/edit/setFiles.d.ts +12 -0
  66. package/dist/types/utils/focus/blur.d.ts +2 -0
  67. package/dist/types/utils/focus/copySelection.d.ts +1 -0
  68. package/dist/types/utils/focus/focus.d.ts +2 -0
  69. package/dist/types/utils/focus/getActiveElement.d.ts +1 -0
  70. package/dist/types/utils/focus/getTabDestination.d.ts +1 -0
  71. package/dist/types/utils/focus/isFocusable.d.ts +1 -0
  72. package/dist/types/utils/focus/selectAll.d.ts +5 -0
  73. package/dist/types/utils/focus/selection.d.ts +42 -0
  74. package/dist/types/utils/focus/selector.d.ts +1 -0
  75. package/dist/types/utils/index.d.ts +40 -0
  76. package/dist/types/utils/keyDef/readNextDescriptor.d.ts +19 -0
  77. package/dist/types/utils/keyboard/getKeyEventProps.d.ts +17 -0
  78. package/dist/types/utils/keyboard/getUIEventModifiers.d.ts +15 -0
  79. package/dist/types/utils/misc/eventWrapper.d.ts +1 -0
  80. package/dist/types/utils/misc/findClosest.d.ts +1 -0
  81. package/dist/types/utils/misc/getDocumentFromNode.d.ts +1 -0
  82. package/dist/types/utils/misc/hasFormSubmit.d.ts +1 -0
  83. package/dist/types/utils/misc/hasPointerEvents.d.ts +15 -0
  84. package/dist/types/utils/misc/isDescendantOrSelf.d.ts +1 -0
  85. package/dist/types/utils/misc/isDisabled.d.ts +1 -0
  86. package/dist/types/utils/misc/isElementType.d.ts +5 -0
  87. package/dist/types/utils/misc/isVisible.d.ts +1 -0
  88. package/dist/types/utils/misc/wait.d.ts +1 -0
  89. package/dist/types/utils/pointer/firePointerEvents.d.ts +25 -0
  90. package/dist/types/utils/pointer/mouseButtons.d.ts +12 -0
  91. package/package.json +10 -3
  92. package/dist/index.d.ts +0 -1110
  93. package/dist/package.json +0 -1
package/dist/index.cjs ADDED
@@ -0,0 +1,2760 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
23
+ var __export = (target, all) => {
24
+ for (var name in all)
25
+ __defProp(target, name, { get: all[name], enumerable: true });
26
+ };
27
+ var __reExport = (target, module2, copyDefault, desc) => {
28
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
29
+ for (let key of __getOwnPropNames(module2))
30
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
31
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
32
+ }
33
+ return target;
34
+ };
35
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
36
+ return (module2, temp) => {
37
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
38
+ };
39
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
40
+
41
+ // src/index.ts
42
+ var src_exports = {};
43
+ __export(src_exports, {
44
+ default: () => userEvent
45
+ });
46
+
47
+ // src/document/index.ts
48
+ var import_dom = require("@testing-library/dom");
49
+
50
+ // src/document/interceptor.ts
51
+ var Interceptor = Symbol("Interceptor for programmatical calls");
52
+ function prepareInterceptor(element, propName, interceptorImpl) {
53
+ const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
54
+ const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
55
+ const target = (prototypeDescriptor == null ? void 0 : prototypeDescriptor.set) ? "set" : "value";
56
+ if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== "function" || prototypeDescriptor[target][Interceptor]) {
57
+ return;
58
+ }
59
+ function intercept(...args) {
60
+ const { applyNative = true, realArgs } = interceptorImpl.call(this, ...args);
61
+ const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
62
+ if (target === "set") {
63
+ realFunc.call(this, realArgs);
64
+ } else {
65
+ realFunc.call(this, ...realArgs);
66
+ }
67
+ }
68
+ ;
69
+ intercept[Interceptor] = Interceptor;
70
+ Object.defineProperty(element, propName, __spreadProps(__spreadValues({}, objectDescriptor != null ? objectDescriptor : prototypeDescriptor), {
71
+ [target]: intercept
72
+ }));
73
+ }
74
+
75
+ // src/document/selection.ts
76
+ var UISelection = Symbol("Displayed selection in UI");
77
+ function prepareSelectionInterceptor(element) {
78
+ prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, end, direction = "none") {
79
+ const isUI = start && typeof start === "object" && start[UISelection];
80
+ if (!isUI) {
81
+ this[UISelection] = void 0;
82
+ }
83
+ return {
84
+ realArgs: [Number(start), end, direction]
85
+ };
86
+ });
87
+ prepareInterceptor(element, "selectionStart", function interceptorImpl(v) {
88
+ this[UISelection] = void 0;
89
+ return { realArgs: v };
90
+ });
91
+ prepareInterceptor(element, "selectionEnd", function interceptorImpl(v) {
92
+ this[UISelection] = void 0;
93
+ return { realArgs: v };
94
+ });
95
+ }
96
+ function setUISelection(element, {
97
+ focusOffset: focusOffsetParam,
98
+ anchorOffset: anchorOffsetParam = focusOffsetParam
99
+ }, mode = "replace") {
100
+ const valueLength = getUIValue(element).length;
101
+ const sanitizeOffset = (o) => Math.max(0, Math.min(valueLength, o));
102
+ const anchorOffset = mode === "replace" || element[UISelection] === void 0 ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
103
+ const focusOffset = sanitizeOffset(focusOffsetParam);
104
+ const startOffset = Math.min(anchorOffset, focusOffset);
105
+ const endOffset = Math.max(anchorOffset, focusOffset);
106
+ element[UISelection] = {
107
+ anchorOffset,
108
+ focusOffset
109
+ };
110
+ if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
111
+ return;
112
+ }
113
+ const startObj = new Number(startOffset);
114
+ startObj[UISelection] = UISelection;
115
+ try {
116
+ element.setSelectionRange(startObj, endOffset);
117
+ } catch {
118
+ }
119
+ }
120
+ function getUISelection(element) {
121
+ var _a, _b, _c;
122
+ const sel = (_c = element[UISelection]) != null ? _c : {
123
+ anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
124
+ focusOffset: (_b = element.selectionEnd) != null ? _b : 0
125
+ };
126
+ return __spreadProps(__spreadValues({}, sel), {
127
+ startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
128
+ endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
129
+ });
130
+ }
131
+ function clearUISelection(element) {
132
+ element[UISelection] = void 0;
133
+ }
134
+
135
+ // src/document/value.ts
136
+ var UIValue = Symbol("Displayed value in UI");
137
+ var InitialValue = Symbol("Initial value to compare on blur");
138
+ var TrackChanges = Symbol("Track programmatic changes for React workaround");
139
+ function valueInterceptor(v) {
140
+ const isUI = typeof v === "object" && v[UIValue];
141
+ this[UIValue] = isUI ? String(v) : void 0;
142
+ if (!isUI) {
143
+ trackValue(this, String(v));
144
+ this[InitialValue] = String(v);
145
+ clearUISelection(this);
146
+ }
147
+ return {
148
+ applyNative: !!isUI,
149
+ realArgs: String(v)
150
+ };
151
+ }
152
+ function prepareValueInterceptor(element) {
153
+ prepareInterceptor(element, "value", valueInterceptor);
154
+ }
155
+ function setUIValue(element, value) {
156
+ element.value = {
157
+ [UIValue]: UIValue,
158
+ toString: () => value
159
+ };
160
+ }
161
+ function getUIValue(element) {
162
+ return element[UIValue] === void 0 ? element.value : String(element[UIValue]);
163
+ }
164
+ function setInitialValue(element) {
165
+ element[InitialValue] = element.value;
166
+ }
167
+ function getInitialValue(element) {
168
+ return element[InitialValue];
169
+ }
170
+ function startTrackValue(element) {
171
+ element[TrackChanges] = [];
172
+ }
173
+ function trackValue(element, v) {
174
+ var _a;
175
+ (_a = element[TrackChanges]) == null ? void 0 : _a.push(v);
176
+ }
177
+ function endTrackValue(element) {
178
+ const tracked = element[TrackChanges];
179
+ element[TrackChanges] = void 0;
180
+ return tracked;
181
+ }
182
+
183
+ // src/document/index.ts
184
+ var isPrepared = Symbol("Node prepared with document state workarounds");
185
+ function prepareDocument(document2) {
186
+ if (document2[isPrepared]) {
187
+ return;
188
+ }
189
+ document2.addEventListener("focus", (e) => {
190
+ const el = e.target;
191
+ prepareElement(el);
192
+ }, {
193
+ capture: true,
194
+ passive: true
195
+ });
196
+ if (document2.activeElement) {
197
+ prepareElement(document2.activeElement);
198
+ }
199
+ document2.addEventListener("blur", (e) => {
200
+ const el = e.target;
201
+ const initialValue = getInitialValue(el);
202
+ if (typeof initialValue === "string" && el.value !== initialValue) {
203
+ import_dom.fireEvent.change(el);
204
+ }
205
+ }, {
206
+ capture: true,
207
+ passive: true
208
+ });
209
+ document2[isPrepared] = isPrepared;
210
+ }
211
+ function prepareElement(el) {
212
+ if ("value" in el) {
213
+ setInitialValue(el);
214
+ }
215
+ if (el[isPrepared]) {
216
+ return;
217
+ }
218
+ if ("value" in el) {
219
+ prepareValueInterceptor(el);
220
+ prepareSelectionInterceptor(el);
221
+ }
222
+ el[isPrepared] = isPrepared;
223
+ }
224
+
225
+ // src/keyboard/keyboardAction.ts
226
+ var import_dom10 = require("@testing-library/dom");
227
+
228
+ // src/utils/misc/isElementType.ts
229
+ function isElementType(element, tag, props) {
230
+ if (element.namespaceURI && element.namespaceURI !== "http://www.w3.org/1999/xhtml") {
231
+ return false;
232
+ }
233
+ tag = Array.isArray(tag) ? tag : [tag];
234
+ if (!tag.includes(element.tagName.toLowerCase())) {
235
+ return false;
236
+ }
237
+ if (props) {
238
+ return Object.entries(props).every(([k, v]) => element[k] === v);
239
+ }
240
+ return true;
241
+ }
242
+
243
+ // src/utils/click/isClickableInput.ts
244
+ var CLICKABLE_INPUT_TYPES = [
245
+ "button",
246
+ "color",
247
+ "file",
248
+ "image",
249
+ "reset",
250
+ "submit",
251
+ "checkbox",
252
+ "radio"
253
+ ];
254
+ function isClickableInput(element) {
255
+ return isElementType(element, "button") || isElementType(element, "input") && CLICKABLE_INPUT_TYPES.includes(element.type);
256
+ }
257
+
258
+ // src/utils/dataTransfer/Blob.ts
259
+ function readBlobText(blob) {
260
+ return new Promise((res, rej) => {
261
+ const fr = new FileReader();
262
+ fr.onerror = rej;
263
+ fr.onabort = rej;
264
+ fr.onload = () => {
265
+ res(String(fr.result));
266
+ };
267
+ fr.readAsText(blob);
268
+ });
269
+ }
270
+
271
+ // src/utils/dataTransfer/FileList.ts
272
+ function createFileList(files) {
273
+ const list = __spreadProps(__spreadValues({}, files), {
274
+ length: files.length,
275
+ item: (index) => list[index],
276
+ [Symbol.iterator]: function* nextFile() {
277
+ for (let i = 0; i < list.length; i++) {
278
+ yield list[i];
279
+ }
280
+ }
281
+ });
282
+ list.constructor = FileList;
283
+ Object.setPrototypeOf(list, FileList.prototype);
284
+ Object.freeze(list);
285
+ return list;
286
+ }
287
+
288
+ // src/utils/dataTransfer/DataTransfer.ts
289
+ var DataTransferItemStub = class {
290
+ constructor(dataOrFile, type3) {
291
+ this.file = null;
292
+ this.data = void 0;
293
+ if (typeof dataOrFile === "string") {
294
+ this.kind = "string";
295
+ this.type = String(type3);
296
+ this.data = dataOrFile;
297
+ } else {
298
+ this.kind = "file";
299
+ this.type = dataOrFile.type;
300
+ this.file = dataOrFile;
301
+ }
302
+ }
303
+ getAsFile() {
304
+ return this.file;
305
+ }
306
+ getAsString(callback) {
307
+ if (typeof this.data === "string") {
308
+ callback(this.data);
309
+ }
310
+ }
311
+ webkitGetAsEntry() {
312
+ throw new Error("not implemented");
313
+ }
314
+ };
315
+ var DataTransferItemListStub = class extends Array {
316
+ add(...args) {
317
+ const item = new DataTransferItemStub(args[0], args[1]);
318
+ this.push(item);
319
+ return item;
320
+ }
321
+ clear() {
322
+ this.splice(0, this.length);
323
+ }
324
+ remove(index) {
325
+ this.splice(index, 1);
326
+ }
327
+ };
328
+ function getTypeMatcher(type3, exact) {
329
+ const [group, sub] = type3.split("/");
330
+ const isGroup = !sub || sub === "*";
331
+ return (item) => {
332
+ return exact ? item.type === (isGroup ? group : type3) : isGroup ? item.type.startsWith(`${group}/`) : item.type === group;
333
+ };
334
+ }
335
+ var DataTransferStub = class {
336
+ constructor() {
337
+ this.dropEffect = "none";
338
+ this.effectAllowed = "uninitialized";
339
+ this.items = new DataTransferItemListStub();
340
+ this.files = createFileList([]);
341
+ }
342
+ getData(format) {
343
+ var _a;
344
+ const match = (_a = this.items.find(getTypeMatcher(format, true))) != null ? _a : this.items.find(getTypeMatcher(format, false));
345
+ let text = "";
346
+ match == null ? void 0 : match.getAsString((t) => {
347
+ text = t;
348
+ });
349
+ return text;
350
+ }
351
+ setData(format, data) {
352
+ const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
353
+ const item = new DataTransferItemStub(data, format);
354
+ if (matchIndex >= 0) {
355
+ this.items.splice(matchIndex, 1, item);
356
+ } else {
357
+ this.items.push(item);
358
+ }
359
+ }
360
+ clearData(format) {
361
+ if (format) {
362
+ const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
363
+ if (matchIndex >= 0) {
364
+ this.items.remove(matchIndex);
365
+ }
366
+ } else {
367
+ this.items.clear();
368
+ }
369
+ }
370
+ get types() {
371
+ const t = [];
372
+ if (this.files.length) {
373
+ t.push("Files");
374
+ }
375
+ this.items.forEach((i) => t.push(i.type));
376
+ Object.freeze(t);
377
+ return t;
378
+ }
379
+ setDragImage() {
380
+ }
381
+ };
382
+ function createDataTransfer(files = []) {
383
+ const dt = typeof DataTransfer === "undefined" ? new DataTransferStub() : new DataTransfer();
384
+ Object.defineProperty(dt, "files", { get: () => createFileList(files) });
385
+ return dt;
386
+ }
387
+ function getBlobFromDataTransferItem(item) {
388
+ if (item.kind === "file") {
389
+ return item.getAsFile();
390
+ }
391
+ let data = "";
392
+ item.getAsString((s) => {
393
+ data = s;
394
+ });
395
+ return new Blob([data], { type: item.type });
396
+ }
397
+
398
+ // src/utils/dataTransfer/Clipboard.ts
399
+ var ClipboardItemStub = class {
400
+ constructor(data) {
401
+ this.data = data;
402
+ }
403
+ get types() {
404
+ return Array.from(Object.keys(this.data));
405
+ }
406
+ async getType(type3) {
407
+ const data = await this.data[type3];
408
+ if (!data) {
409
+ throw new Error(`${type3} is not one of the available MIME types on this item.`);
410
+ }
411
+ return data instanceof Blob ? data : new Blob([data], { type: type3 });
412
+ }
413
+ };
414
+ var ClipboardStubControl = Symbol("Manage ClipboardSub");
415
+ var ClipboardStub = class extends EventTarget {
416
+ constructor() {
417
+ super(...arguments);
418
+ this.items = [];
419
+ }
420
+ async read() {
421
+ return Array.from(this.items);
422
+ }
423
+ async readText() {
424
+ let text = "";
425
+ for (const item of this.items) {
426
+ const type3 = item.types.includes("text/plain") ? "text/plain" : item.types.find((t) => t.startsWith("text/"));
427
+ if (type3) {
428
+ text += await item.getType(type3).then((b) => readBlobText(b));
429
+ }
430
+ }
431
+ return text;
432
+ }
433
+ async write(data) {
434
+ this.items = data;
435
+ }
436
+ async writeText(text) {
437
+ this.items = [createClipboardItem(text)];
438
+ }
439
+ };
440
+ ClipboardStubControl;
441
+ function createClipboardItem(...blobs) {
442
+ const constructor = typeof ClipboardItem === "undefined" ? ClipboardItemStub : ClipboardItem;
443
+ return new constructor(Object.fromEntries(blobs.map((b) => [
444
+ typeof b === "string" ? "text/plain" : b.type,
445
+ Promise.resolve(b)
446
+ ])));
447
+ }
448
+ function attachClipboardStubToView(window2) {
449
+ if (window2.navigator.clipboard instanceof ClipboardStub) {
450
+ return window2.navigator.clipboard[ClipboardStubControl];
451
+ }
452
+ const realClipboard = Object.getOwnPropertyDescriptor(window2.navigator, "clipboard");
453
+ let stub = new ClipboardStub();
454
+ const control = {
455
+ resetClipboardStub: () => {
456
+ stub = new ClipboardStub();
457
+ stub[ClipboardStubControl] = control;
458
+ },
459
+ detachClipboardStub: () => {
460
+ if (realClipboard) {
461
+ Object.defineProperty(window2.navigator, "clipboard", realClipboard);
462
+ } else {
463
+ Object.defineProperty(window2.navigator, "clipboard", {
464
+ value: void 0,
465
+ configurable: true
466
+ });
467
+ }
468
+ }
469
+ };
470
+ stub[ClipboardStubControl] = control;
471
+ Object.defineProperty(window2.navigator, "clipboard", {
472
+ get: () => stub,
473
+ configurable: true
474
+ });
475
+ return stub[ClipboardStubControl];
476
+ }
477
+ function resetClipboardStubOnView(window2) {
478
+ if (window2.navigator.clipboard instanceof ClipboardStub) {
479
+ window2.navigator.clipboard[ClipboardStubControl].resetClipboardStub();
480
+ }
481
+ }
482
+ function detachClipboardStubFromView(window2) {
483
+ if (window2.navigator.clipboard instanceof ClipboardStub) {
484
+ window2.navigator.clipboard[ClipboardStubControl].detachClipboardStub();
485
+ }
486
+ }
487
+ async function readDataTransferFromClipboard(document2) {
488
+ var _a;
489
+ const clipboard = (_a = document2.defaultView) == null ? void 0 : _a.navigator.clipboard;
490
+ const items = clipboard && await clipboard.read();
491
+ if (!items) {
492
+ throw new Error("The Clipboard API is unavailable.");
493
+ }
494
+ const dt = createDataTransfer();
495
+ for (const item of items) {
496
+ for (const type3 of item.types) {
497
+ dt.setData(type3, await item.getType(type3).then((b) => readBlobText(b)));
498
+ }
499
+ }
500
+ return dt;
501
+ }
502
+ async function writeDataTransferToClipboard(document2, clipboardData) {
503
+ var _a;
504
+ const clipboard = (_a = document2.defaultView) == null ? void 0 : _a.navigator.clipboard;
505
+ const items = [];
506
+ for (let i = 0; i < clipboardData.items.length; i++) {
507
+ const dtItem = clipboardData.items[i];
508
+ const blob = getBlobFromDataTransferItem(dtItem);
509
+ items.push(createClipboardItem(blob));
510
+ }
511
+ const written = clipboard && await clipboard.write(items).then(() => true, () => false);
512
+ if (!written) {
513
+ throw new Error("The Clipboard API is unavailable.");
514
+ }
515
+ }
516
+ if (typeof afterEach === "function") {
517
+ afterEach(() => resetClipboardStubOnView(window));
518
+ }
519
+ if (typeof afterAll === "function") {
520
+ afterAll(() => detachClipboardStubFromView(window));
521
+ }
522
+
523
+ // src/utils/edit/buildTimeValue.ts
524
+ function buildTimeValue(value) {
525
+ const onlyDigitsValue = value.replace(/\D/g, "");
526
+ if (onlyDigitsValue.length < 2) {
527
+ return value;
528
+ }
529
+ const firstDigit = parseInt(onlyDigitsValue[0], 10);
530
+ const secondDigit = parseInt(onlyDigitsValue[1], 10);
531
+ if (firstDigit >= 3 || firstDigit === 2 && secondDigit >= 4) {
532
+ let index;
533
+ if (firstDigit >= 3) {
534
+ index = 1;
535
+ } else {
536
+ index = 2;
537
+ }
538
+ return build(onlyDigitsValue, index);
539
+ }
540
+ if (value.length === 2) {
541
+ return value;
542
+ }
543
+ return build(onlyDigitsValue, 2);
544
+ }
545
+ function build(onlyDigitsValue, index) {
546
+ const hours = onlyDigitsValue.slice(0, index);
547
+ const validHours = Math.min(parseInt(hours, 10), 23);
548
+ const minuteCharacters = onlyDigitsValue.slice(index);
549
+ const parsedMinutes = parseInt(minuteCharacters, 10);
550
+ const validMinutes = Math.min(parsedMinutes, 59);
551
+ return `${validHours.toString().padStart(2, "0")}:${validMinutes.toString().padStart(2, "0")}`;
552
+ }
553
+
554
+ // src/utils/edit/isValidDateValue.ts
555
+ function isValidDateValue(element, value) {
556
+ const clone = element.cloneNode();
557
+ clone.value = value;
558
+ return clone.value === value;
559
+ }
560
+
561
+ // src/utils/edit/isValidInputTimeValue.ts
562
+ function isValidInputTimeValue(element, timeValue) {
563
+ const clone = element.cloneNode();
564
+ clone.value = timeValue;
565
+ return clone.value === timeValue;
566
+ }
567
+
568
+ // src/utils/edit/calculateNewValue.ts
569
+ function calculateNewValue(inputData, node, {
570
+ startOffset,
571
+ endOffset
572
+ }, inputType) {
573
+ const value = getUIValue(node);
574
+ const prologEnd = Math.max(0, startOffset === endOffset && inputType === "deleteContentBackward" ? startOffset - 1 : startOffset);
575
+ const prolog = value.substring(0, prologEnd);
576
+ const epilogStart = Math.min(value.length, startOffset === endOffset && inputType === "deleteContentForward" ? startOffset + 1 : endOffset);
577
+ const epilog = value.substring(epilogStart, value.length);
578
+ let newValue = `${prolog}${inputData}${epilog}`;
579
+ const newOffset = prologEnd + inputData.length;
580
+ if (node.type === "date" && !isValidDateValue(node, newValue)) {
581
+ newValue = value;
582
+ }
583
+ if (node.type === "time" && !isValidInputTimeValue(node, newValue)) {
584
+ if (isValidInputTimeValue(node, inputData)) {
585
+ newValue = inputData;
586
+ } else {
587
+ newValue = value;
588
+ }
589
+ }
590
+ return {
591
+ oldValue: value,
592
+ newValue,
593
+ newOffset
594
+ };
595
+ }
596
+
597
+ // src/utils/edit/editInputElement.ts
598
+ var import_dom2 = require("@testing-library/dom");
599
+
600
+ // src/utils/edit/isContentEditable.ts
601
+ function isContentEditable(element) {
602
+ return element.hasAttribute("contenteditable") && (element.getAttribute("contenteditable") == "true" || element.getAttribute("contenteditable") == "");
603
+ }
604
+ function getContentEditable(node) {
605
+ const element = getElement(node);
606
+ return element && (element.closest('[contenteditable=""]') || element.closest('[contenteditable="true"]'));
607
+ }
608
+ function getElement(node) {
609
+ return node.nodeType === 1 ? node : node.parentElement;
610
+ }
611
+
612
+ // src/utils/edit/isEditable.ts
613
+ function isEditable(element) {
614
+ return isEditableInput(element) || isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element);
615
+ }
616
+ var editableInputTypes = /* @__PURE__ */ ((editableInputTypes2) => {
617
+ editableInputTypes2["text"] = "text";
618
+ editableInputTypes2["date"] = "date";
619
+ editableInputTypes2["datetime-local"] = "datetime-local";
620
+ editableInputTypes2["email"] = "email";
621
+ editableInputTypes2["month"] = "month";
622
+ editableInputTypes2["number"] = "number";
623
+ editableInputTypes2["password"] = "password";
624
+ editableInputTypes2["search"] = "search";
625
+ editableInputTypes2["tel"] = "tel";
626
+ editableInputTypes2["time"] = "time";
627
+ editableInputTypes2["url"] = "url";
628
+ editableInputTypes2["week"] = "week";
629
+ return editableInputTypes2;
630
+ })(editableInputTypes || {});
631
+ function isEditableInput(element) {
632
+ return isElementType(element, "input", { readOnly: false }) && Boolean(editableInputTypes[element.type]);
633
+ }
634
+
635
+ // src/utils/focus/selection.ts
636
+ function setSelectionRange(element, anchorOffset, focusOffset) {
637
+ var _a;
638
+ if (hasOwnSelection(element)) {
639
+ return setSelection({
640
+ focusNode: element,
641
+ anchorOffset,
642
+ focusOffset
643
+ });
644
+ }
645
+ if (isContentEditable(element) && ((_a = element.firstChild) == null ? void 0 : _a.nodeType) === 3) {
646
+ return setSelection({
647
+ focusNode: element.firstChild,
648
+ anchorOffset,
649
+ focusOffset
650
+ });
651
+ }
652
+ throw new Error("Not implemented. The result of this interaction is unreliable.");
653
+ }
654
+ function hasOwnSelection(node) {
655
+ return isElement(node) && (isElementType(node, "textarea") || isElementType(node, "input") && node.type in editableInputTypes);
656
+ }
657
+ function isElement(node) {
658
+ return node.nodeType === 1;
659
+ }
660
+ function getTargetTypeAndSelection(node) {
661
+ const element = getElement2(node);
662
+ if (element && hasOwnSelection(element)) {
663
+ return {
664
+ type: "input",
665
+ selection: getUISelection(element)
666
+ };
667
+ }
668
+ const selection = element == null ? void 0 : element.ownerDocument.getSelection();
669
+ const isCE = getContentEditable(node) && (selection == null ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
670
+ return {
671
+ type: isCE ? "contenteditable" : "default",
672
+ selection
673
+ };
674
+ }
675
+ function getElement2(node) {
676
+ return node.nodeType === 1 ? node : node.parentElement;
677
+ }
678
+ function updateSelectionOnFocus(element) {
679
+ var _a;
680
+ const selection = element.ownerDocument.getSelection();
681
+ if (!(selection == null ? void 0 : selection.focusNode)) {
682
+ return;
683
+ }
684
+ if (hasOwnSelection(element)) {
685
+ const contenteditable = getContentEditable(selection.focusNode);
686
+ if (contenteditable) {
687
+ if (!selection.isCollapsed) {
688
+ const focusNode = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
689
+ selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
690
+ }
691
+ } else {
692
+ selection.setBaseAndExtent(element, 0, element, 0);
693
+ }
694
+ }
695
+ }
696
+ function getInputRange(focusNode) {
697
+ var _a;
698
+ const typeAndSelection = getTargetTypeAndSelection(focusNode);
699
+ if (typeAndSelection.type === "input") {
700
+ return typeAndSelection.selection;
701
+ } else if (typeAndSelection.type === "contenteditable") {
702
+ return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
703
+ }
704
+ }
705
+ function setSelection({
706
+ focusNode,
707
+ focusOffset,
708
+ anchorNode = focusNode,
709
+ anchorOffset = focusOffset
710
+ }) {
711
+ var _a, _b;
712
+ const typeAndSelection = getTargetTypeAndSelection(focusNode);
713
+ if (typeAndSelection.type === "input") {
714
+ return setUISelection(focusNode, {
715
+ anchorOffset,
716
+ focusOffset
717
+ });
718
+ }
719
+ (_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
720
+ }
721
+
722
+ // src/utils/edit/editInputElement.ts
723
+ function editInputElement(element, {
724
+ newValue,
725
+ newSelection,
726
+ eventOverrides
727
+ }) {
728
+ const oldValue = element.value;
729
+ setUIValue(element, newValue);
730
+ setSelection({
731
+ focusNode: newSelection.node,
732
+ anchorOffset: newSelection.offset,
733
+ focusOffset: newSelection.offset
734
+ });
735
+ startTrackValue(element);
736
+ import_dom2.fireEvent.input(element, __spreadValues({}, eventOverrides));
737
+ const tracked = endTrackValue(element);
738
+ if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
739
+ setSelection({
740
+ focusNode: newSelection.node,
741
+ anchorOffset: newSelection.offset,
742
+ focusOffset: newSelection.offset
743
+ });
744
+ }
745
+ }
746
+
747
+ // src/utils/edit/getValue.ts
748
+ function getValue(element) {
749
+ if (!element) {
750
+ return null;
751
+ }
752
+ if (isContentEditable(element)) {
753
+ return element.textContent;
754
+ }
755
+ return getUIValue(element);
756
+ }
757
+
758
+ // src/utils/edit/maxLength.ts
759
+ var maxLengthSupportedTypes = /* @__PURE__ */ ((maxLengthSupportedTypes2) => {
760
+ maxLengthSupportedTypes2["email"] = "email";
761
+ maxLengthSupportedTypes2["password"] = "password";
762
+ maxLengthSupportedTypes2["search"] = "search";
763
+ maxLengthSupportedTypes2["telephone"] = "telephone";
764
+ maxLengthSupportedTypes2["text"] = "text";
765
+ maxLengthSupportedTypes2["url"] = "url";
766
+ return maxLengthSupportedTypes2;
767
+ })(maxLengthSupportedTypes || {});
768
+ function getSpaceUntilMaxLength(element) {
769
+ const value = getValue(element);
770
+ if (value === null) {
771
+ return void 0;
772
+ }
773
+ const maxLength = getSanitizedMaxLength(element);
774
+ return maxLength ? maxLength - value.length : void 0;
775
+ }
776
+ function getSanitizedMaxLength(element) {
777
+ var _a;
778
+ if (!supportsMaxLength(element)) {
779
+ return void 0;
780
+ }
781
+ const attr = (_a = element.getAttribute("maxlength")) != null ? _a : "";
782
+ return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
783
+ }
784
+ function supportsMaxLength(element) {
785
+ return isElementType(element, "textarea") || isElementType(element, "input") && Boolean(maxLengthSupportedTypes[element.type]);
786
+ }
787
+
788
+ // src/utils/edit/prepareInput.ts
789
+ var import_dom3 = require("@testing-library/dom");
790
+ function prepareInput(data, element, inputType = "insertText") {
791
+ const inputRange = getInputRange(element);
792
+ if (!inputRange) {
793
+ return;
794
+ }
795
+ if ("startContainer" in inputRange) {
796
+ return {
797
+ commit: () => {
798
+ const del = !inputRange.collapsed;
799
+ if (del) {
800
+ inputRange.deleteContents();
801
+ }
802
+ if (data) {
803
+ if (inputRange.endContainer.nodeType === 3) {
804
+ const offset = inputRange.endOffset;
805
+ inputRange.endContainer.insertData(offset, data);
806
+ inputRange.setStart(inputRange.endContainer, offset + data.length);
807
+ inputRange.setEnd(inputRange.endContainer, offset + data.length);
808
+ } else {
809
+ const text = element.ownerDocument.createTextNode(data);
810
+ inputRange.insertNode(text);
811
+ inputRange.setStart(text, data.length);
812
+ inputRange.setEnd(text, data.length);
813
+ }
814
+ }
815
+ if (del || data) {
816
+ import_dom3.fireEvent.input(element, { inputType });
817
+ }
818
+ }
819
+ };
820
+ } else {
821
+ return {
822
+ getNewValue: () => calculateNewValue(data, element, inputRange, inputType).newValue,
823
+ commit: () => {
824
+ const { newValue, newOffset, oldValue } = calculateNewValue(data, element, inputRange, inputType);
825
+ if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
826
+ return;
827
+ }
828
+ editInputElement(element, {
829
+ newValue,
830
+ newSelection: {
831
+ node: element,
832
+ offset: newOffset
833
+ },
834
+ eventOverrides: {
835
+ inputType
836
+ }
837
+ });
838
+ }
839
+ };
840
+ }
841
+ }
842
+
843
+ // src/utils/edit/setFiles.ts
844
+ var fakeFiles = Symbol("files and value properties are mocked");
845
+ function setFiles(el, files) {
846
+ var _a;
847
+ (_a = el[fakeFiles]) == null ? void 0 : _a.restore();
848
+ const objectDescriptors = Object.getOwnPropertyDescriptors(el);
849
+ const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
850
+ function restore() {
851
+ Object.defineProperties(el, {
852
+ files: __spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files),
853
+ value: __spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value),
854
+ type: __spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type)
855
+ });
856
+ }
857
+ el[fakeFiles] = { restore };
858
+ Object.defineProperties(el, {
859
+ files: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files), {
860
+ get: () => files
861
+ }),
862
+ value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
863
+ get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
864
+ set(v) {
865
+ var _a2;
866
+ if (v === "") {
867
+ restore();
868
+ } else {
869
+ (_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
870
+ }
871
+ }
872
+ }),
873
+ type: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type), {
874
+ set(v) {
875
+ if (v !== "file") {
876
+ restore();
877
+ el.type = v;
878
+ }
879
+ }
880
+ })
881
+ });
882
+ }
883
+
884
+ // src/utils/misc/eventWrapper.ts
885
+ var import_dom4 = require("@testing-library/dom");
886
+ function eventWrapper(cb) {
887
+ let result;
888
+ (0, import_dom4.getConfig)().eventWrapper(() => {
889
+ result = cb();
890
+ });
891
+ return result;
892
+ }
893
+
894
+ // src/utils/misc/isDisabled.ts
895
+ function isDisabled(element) {
896
+ return Boolean(element && element.disabled);
897
+ }
898
+
899
+ // src/utils/focus/getActiveElement.ts
900
+ function getActiveElement(document2) {
901
+ const activeElement = document2.activeElement;
902
+ if (activeElement == null ? void 0 : activeElement.shadowRoot) {
903
+ return getActiveElement(activeElement.shadowRoot);
904
+ } else {
905
+ if (isDisabled(activeElement)) {
906
+ return document2.ownerDocument ? document2.ownerDocument.body : document2.body;
907
+ }
908
+ return activeElement;
909
+ }
910
+ }
911
+
912
+ // src/utils/focus/selector.ts
913
+ var FOCUSABLE_SELECTOR = [
914
+ "input:not([type=hidden]):not([disabled])",
915
+ "button:not([disabled])",
916
+ "select:not([disabled])",
917
+ "textarea:not([disabled])",
918
+ '[contenteditable=""]',
919
+ '[contenteditable="true"]',
920
+ "a[href]",
921
+ "[tabindex]:not([disabled])"
922
+ ].join(", ");
923
+
924
+ // src/utils/focus/isFocusable.ts
925
+ function isFocusable(element) {
926
+ return element.matches(FOCUSABLE_SELECTOR);
927
+ }
928
+
929
+ // src/utils/focus/blur.ts
930
+ function blur(element) {
931
+ if (!isFocusable(element))
932
+ return;
933
+ const wasActive = getActiveElement(element.ownerDocument) === element;
934
+ if (!wasActive)
935
+ return;
936
+ eventWrapper(() => element.blur());
937
+ }
938
+
939
+ // src/utils/focus/copySelection.ts
940
+ function copySelection(target) {
941
+ const data = hasOwnSelection(target) ? { "text/plain": readSelectedValueFromInput(target) } : { "text/plain": String(target.ownerDocument.getSelection()) };
942
+ const dt = createDataTransfer();
943
+ for (const type3 in data) {
944
+ if (data[type3]) {
945
+ dt.setData(type3, data[type3]);
946
+ }
947
+ }
948
+ return dt;
949
+ }
950
+ function readSelectedValueFromInput(target) {
951
+ const sel = getUISelection(target);
952
+ const val = getUIValue(target);
953
+ return val.substring(sel.startOffset, sel.endOffset);
954
+ }
955
+
956
+ // src/utils/focus/focus.ts
957
+ function focus(element) {
958
+ if (!isFocusable(element))
959
+ return;
960
+ const isAlreadyActive = getActiveElement(element.ownerDocument) === element;
961
+ if (isAlreadyActive)
962
+ return;
963
+ eventWrapper(() => element.focus());
964
+ updateSelectionOnFocus(element);
965
+ }
966
+
967
+ // src/utils/misc/isVisible.ts
968
+ var import_helpers = require("@testing-library/dom/dist/helpers.js");
969
+ function isVisible(element) {
970
+ const window2 = (0, import_helpers.getWindowFromNode)(element);
971
+ for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
972
+ const { display, visibility } = window2.getComputedStyle(el);
973
+ if (display === "none") {
974
+ return false;
975
+ }
976
+ if (visibility === "hidden") {
977
+ return false;
978
+ }
979
+ }
980
+ return true;
981
+ }
982
+
983
+ // src/utils/focus/getTabDestination.ts
984
+ function getTabDestination(activeElement, shift) {
985
+ const document2 = activeElement.ownerDocument;
986
+ const focusableElements = document2.querySelectorAll(FOCUSABLE_SELECTOR);
987
+ const enabledElements = Array.from(focusableElements).filter((el) => el === activeElement || el.getAttribute("tabindex") !== "-1" && !isDisabled(el) && isVisible(el));
988
+ if (activeElement.getAttribute("tabindex") !== "-1") {
989
+ enabledElements.sort((a, b) => {
990
+ const i = Number(a.getAttribute("tabindex"));
991
+ const j = Number(b.getAttribute("tabindex"));
992
+ if (i === j) {
993
+ return 0;
994
+ } else if (i === 0) {
995
+ return 1;
996
+ } else if (j === 0) {
997
+ return -1;
998
+ }
999
+ return i - j;
1000
+ });
1001
+ }
1002
+ const checkedRadio = {};
1003
+ let prunedElements = [document2.body];
1004
+ const activeRadioGroup = isElementType(activeElement, "input", {
1005
+ type: "radio"
1006
+ }) ? activeElement.name : void 0;
1007
+ enabledElements.forEach((currentElement) => {
1008
+ const el = currentElement;
1009
+ if (isElementType(el, "input", { type: "radio" }) && el.name) {
1010
+ if (el === activeElement) {
1011
+ prunedElements.push(el);
1012
+ return;
1013
+ } else if (el.name === activeRadioGroup) {
1014
+ return;
1015
+ }
1016
+ if (el.checked) {
1017
+ prunedElements = prunedElements.filter((e) => !isElementType(e, "input", { type: "radio", name: el.name }));
1018
+ prunedElements.push(el);
1019
+ checkedRadio[el.name] = el;
1020
+ return;
1021
+ }
1022
+ if (typeof checkedRadio[el.name] !== "undefined") {
1023
+ return;
1024
+ }
1025
+ }
1026
+ prunedElements.push(el);
1027
+ });
1028
+ const currentIndex = prunedElements.findIndex((el) => el === activeElement);
1029
+ const nextIndex = shift ? currentIndex - 1 : currentIndex + 1;
1030
+ const defaultIndex = shift ? prunedElements.length - 1 : 0;
1031
+ return prunedElements[nextIndex] || prunedElements[defaultIndex];
1032
+ }
1033
+
1034
+ // src/utils/focus/selectAll.ts
1035
+ function selectAll(target) {
1036
+ var _a;
1037
+ if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
1038
+ return setSelection({
1039
+ focusNode: target,
1040
+ anchorOffset: 0,
1041
+ focusOffset: getUIValue(target).length
1042
+ });
1043
+ }
1044
+ const focusNode = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
1045
+ setSelection({
1046
+ focusNode,
1047
+ anchorOffset: 0,
1048
+ focusOffset: focusNode.childNodes.length
1049
+ });
1050
+ }
1051
+ function isAllSelected(target) {
1052
+ var _a;
1053
+ if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
1054
+ return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
1055
+ }
1056
+ const focusNode = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
1057
+ const selection = target.ownerDocument.getSelection();
1058
+ return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
1059
+ }
1060
+
1061
+ // src/utils/keyboard/getUIEventModifiers.ts
1062
+ function getUIEventModifiers(keyboardState) {
1063
+ return {
1064
+ altKey: keyboardState.modifiers.Alt,
1065
+ ctrlKey: keyboardState.modifiers.Control,
1066
+ metaKey: keyboardState.modifiers.Meta,
1067
+ shiftKey: keyboardState.modifiers.Shift,
1068
+ modifierAltGraph: keyboardState.modifiers.AltGraph,
1069
+ modifierCapsLock: keyboardState.modifiers.CapsLock,
1070
+ modifierFn: keyboardState.modifiers.Fn,
1071
+ modifierFnLock: keyboardState.modifiers.FnLock,
1072
+ modifierNumLock: keyboardState.modifiers.NumLock,
1073
+ modifierScrollLock: keyboardState.modifiers.ScrollLock,
1074
+ modifierSymbol: keyboardState.modifiers.Symbol,
1075
+ modifierSymbolLock: keyboardState.modifiers.SymbolLock
1076
+ };
1077
+ }
1078
+
1079
+ // src/utils/keyboard/getKeyEventProps.ts
1080
+ function getKeyEventProps(keyDef, state) {
1081
+ return __spreadValues({
1082
+ key: keyDef.key,
1083
+ code: keyDef.code
1084
+ }, getUIEventModifiers(state));
1085
+ }
1086
+
1087
+ // src/utils/keyDef/readNextDescriptor.ts
1088
+ var bracketDict = /* @__PURE__ */ ((bracketDict2) => {
1089
+ bracketDict2["{"] = "}";
1090
+ bracketDict2["["] = "]";
1091
+ return bracketDict2;
1092
+ })(bracketDict || {});
1093
+ function readNextDescriptor(text) {
1094
+ let pos = 0;
1095
+ const startBracket = text[pos] in bracketDict ? text[pos] : "";
1096
+ pos += startBracket.length;
1097
+ const isEscapedChar = new RegExp(`^\\${startBracket}{2}`).test(text);
1098
+ const type3 = isEscapedChar ? "" : startBracket;
1099
+ return __spreadValues({
1100
+ type: type3
1101
+ }, type3 === "" ? readPrintableChar(text, pos) : readTag(text, pos, type3));
1102
+ }
1103
+ function readPrintableChar(text, pos) {
1104
+ const descriptor = text[pos];
1105
+ assertDescriptor(descriptor, text, pos);
1106
+ pos += descriptor.length;
1107
+ return {
1108
+ consumedLength: pos,
1109
+ descriptor,
1110
+ releasePrevious: false,
1111
+ releaseSelf: true,
1112
+ repeat: 1
1113
+ };
1114
+ }
1115
+ function readTag(text, pos, startBracket) {
1116
+ var _a, _b, _c;
1117
+ const releasePreviousModifier = text[pos] === "/" ? "/" : "";
1118
+ pos += releasePreviousModifier.length;
1119
+ const escapedDescriptor = startBracket === "{" && text[pos] === "\\";
1120
+ pos += Number(escapedDescriptor);
1121
+ const descriptor = escapedDescriptor ? text[pos] : (_a = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a[0];
1122
+ assertDescriptor(descriptor, text, pos);
1123
+ pos += descriptor.length;
1124
+ const repeatModifier = (_c = (_b = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _b[0]) != null ? _c : "";
1125
+ pos += repeatModifier.length;
1126
+ const releaseSelfModifier = text[pos] === "/" || !repeatModifier && text[pos] === ">" ? text[pos] : "";
1127
+ pos += releaseSelfModifier.length;
1128
+ const expectedEndBracket = bracketDict[startBracket];
1129
+ const endBracket = text[pos] === expectedEndBracket ? expectedEndBracket : "";
1130
+ if (!endBracket) {
1131
+ throw new Error(getErrorMessage([
1132
+ !repeatModifier && "repeat modifier",
1133
+ !releaseSelfModifier && "release modifier",
1134
+ `"${expectedEndBracket}"`
1135
+ ].filter(Boolean).join(" or "), text[pos], text));
1136
+ }
1137
+ pos += endBracket.length;
1138
+ return {
1139
+ consumedLength: pos,
1140
+ descriptor,
1141
+ releasePrevious: !!releasePreviousModifier,
1142
+ repeat: repeatModifier ? Math.max(Number(repeatModifier.substr(1)), 1) : 1,
1143
+ releaseSelf: hasReleaseSelf(releaseSelfModifier, repeatModifier)
1144
+ };
1145
+ }
1146
+ function assertDescriptor(descriptor, text, pos) {
1147
+ if (!descriptor) {
1148
+ throw new Error(getErrorMessage("key descriptor", text[pos], text));
1149
+ }
1150
+ }
1151
+ function hasReleaseSelf(releaseSelfModifier, repeatModifier) {
1152
+ if (releaseSelfModifier) {
1153
+ return releaseSelfModifier === "/";
1154
+ }
1155
+ if (repeatModifier) {
1156
+ return false;
1157
+ }
1158
+ }
1159
+ function getErrorMessage(expected, found, text) {
1160
+ return `Expected ${expected} but found "${found != null ? found : ""}" in "${text}"
1161
+ See https://github.com/testing-library/user-event/blob/main/README.md#keyboardtext-options
1162
+ for more information about how userEvent parses your input.`;
1163
+ }
1164
+
1165
+ // src/utils/misc/findClosest.ts
1166
+ function findClosest(element, callback) {
1167
+ let el = element;
1168
+ do {
1169
+ if (callback(el)) {
1170
+ return el;
1171
+ }
1172
+ el = el.parentElement;
1173
+ } while (el && el !== element.ownerDocument.body);
1174
+ return void 0;
1175
+ }
1176
+
1177
+ // src/utils/misc/getDocumentFromNode.ts
1178
+ function getDocumentFromNode(el) {
1179
+ return isDocument(el) ? el : el.ownerDocument;
1180
+ }
1181
+ function isDocument(node) {
1182
+ return node.nodeType === 9;
1183
+ }
1184
+
1185
+ // src/utils/misc/isDescendantOrSelf.ts
1186
+ function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
1187
+ let el = potentialDescendant;
1188
+ do {
1189
+ if (el === potentialAncestor) {
1190
+ return true;
1191
+ }
1192
+ el = el.parentElement;
1193
+ } while (el);
1194
+ return false;
1195
+ }
1196
+
1197
+ // src/utils/misc/wait.ts
1198
+ function wait(time) {
1199
+ return new Promise((resolve) => setTimeout(() => resolve(), time));
1200
+ }
1201
+
1202
+ // src/utils/misc/hasPointerEvents.ts
1203
+ var import_helpers2 = require("@testing-library/dom/dist/helpers.js");
1204
+ function hasPointerEvents(element) {
1205
+ const window2 = (0, import_helpers2.getWindowFromNode)(element);
1206
+ for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
1207
+ const pointerEvents = window2.getComputedStyle(el).pointerEvents;
1208
+ if (pointerEvents && !["inherit", "unset"].includes(pointerEvents)) {
1209
+ return pointerEvents !== "none";
1210
+ }
1211
+ }
1212
+ return true;
1213
+ }
1214
+
1215
+ // src/utils/misc/hasFormSubmit.ts
1216
+ var hasFormSubmit = (form) => !!(form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]'));
1217
+
1218
+ // src/utils/pointer/firePointerEvents.ts
1219
+ var import_dom5 = require("@testing-library/dom");
1220
+ var import_event_map = require("@testing-library/dom/dist/event-map.js");
1221
+
1222
+ // src/utils/pointer/mouseButtons.ts
1223
+ var MouseButton = {
1224
+ primary: 0,
1225
+ secondary: 1,
1226
+ auxiliary: 2,
1227
+ back: 3,
1228
+ X1: 3,
1229
+ forward: 4,
1230
+ X2: 4
1231
+ };
1232
+ var MouseButtonFlip = {
1233
+ auxiliary: 1,
1234
+ secondary: 2,
1235
+ 1: 2,
1236
+ 2: 1
1237
+ };
1238
+ function getMouseButton(button) {
1239
+ if (button in MouseButtonFlip) {
1240
+ return MouseButtonFlip[button];
1241
+ }
1242
+ return typeof button === "number" ? button : MouseButton[button];
1243
+ }
1244
+ function getMouseButtons(...buttons) {
1245
+ let v = 0;
1246
+ for (const t of buttons) {
1247
+ const pos = typeof t === "number" ? t : MouseButton[t];
1248
+ v |= 2 ** pos;
1249
+ }
1250
+ return v;
1251
+ }
1252
+
1253
+ // src/utils/pointer/firePointerEvents.ts
1254
+ function firePointerEvent(target, type3, {
1255
+ pointerState,
1256
+ keyboardState,
1257
+ pointerType,
1258
+ button,
1259
+ coords,
1260
+ pointerId,
1261
+ isPrimary,
1262
+ clickCount
1263
+ }) {
1264
+ const init = __spreadValues(__spreadValues({}, coords), getUIEventModifiers(keyboardState));
1265
+ if (type3 === "click" || type3.startsWith("pointer")) {
1266
+ init.pointerId = pointerId;
1267
+ init.pointerType = pointerType;
1268
+ }
1269
+ if (["pointerdown", "pointerup"].includes(type3)) {
1270
+ init.isPrimary = isPrimary;
1271
+ }
1272
+ init.button = getMouseButton(button != null ? button : 0);
1273
+ init.buttons = getMouseButtons(...pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
1274
+ var _a;
1275
+ return (_a = p.keyDef.button) != null ? _a : 0;
1276
+ }));
1277
+ if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
1278
+ init.detail = clickCount;
1279
+ }
1280
+ const eventKey = Object.keys(import_event_map.eventMap).find((k) => k.toLowerCase() === type3);
1281
+ const event = import_dom5.createEvent[eventKey](target, init);
1282
+ assignPositionInit(event, init);
1283
+ assignPointerInit(event, init);
1284
+ return (0, import_dom5.fireEvent)(target, event);
1285
+ }
1286
+ function assignProps(obj, props) {
1287
+ for (const [key, value] of Object.entries(props)) {
1288
+ Object.defineProperty(obj, key, { get: () => value });
1289
+ }
1290
+ }
1291
+ function assignPositionInit(obj, {
1292
+ x,
1293
+ y,
1294
+ clientX,
1295
+ clientY,
1296
+ offsetX,
1297
+ offsetY,
1298
+ pageX,
1299
+ pageY,
1300
+ screenX,
1301
+ screenY
1302
+ }) {
1303
+ var _a, _b, _c, _d;
1304
+ assignProps(obj, {
1305
+ x: (_a = x != null ? x : clientX) != null ? _a : 0,
1306
+ y: (_b = y != null ? y : clientY) != null ? _b : 0,
1307
+ clientX: (_c = x != null ? x : clientX) != null ? _c : 0,
1308
+ clientY: (_d = y != null ? y : clientY) != null ? _d : 0,
1309
+ offsetX: offsetX != null ? offsetX : 0,
1310
+ offsetY: offsetY != null ? offsetY : 0,
1311
+ pageX: pageX != null ? pageX : 0,
1312
+ pageY: pageY != null ? pageY : 0,
1313
+ screenX: screenX != null ? screenX : 0,
1314
+ screenY: screenY != null ? screenY : 0
1315
+ });
1316
+ }
1317
+ function assignPointerInit(obj, { isPrimary, pointerId, pointerType }) {
1318
+ assignProps(obj, {
1319
+ isPrimary,
1320
+ pointerId,
1321
+ pointerType
1322
+ });
1323
+ }
1324
+
1325
+ // src/keyboard/plugins/arrow.ts
1326
+ var keydownBehavior = [
1327
+ {
1328
+ matches: (keyDef, element) => (keyDef.key === "ArrowLeft" || keyDef.key === "ArrowRight") && isElementType(element, ["input", "textarea"]),
1329
+ handle: (keyDef, element) => {
1330
+ const selection = getUISelection(element);
1331
+ setSelection({
1332
+ focusNode: element,
1333
+ focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + (keyDef.key === "ArrowLeft" ? -1 : 1) : keyDef.key === "ArrowLeft" ? selection.startOffset : selection.endOffset
1334
+ });
1335
+ }
1336
+ }
1337
+ ];
1338
+
1339
+ // src/keyboard/plugins/control.ts
1340
+ var keydownBehavior2 = [
1341
+ {
1342
+ matches: (keyDef, element) => (keyDef.key === "Home" || keyDef.key === "End") && (isElementType(element, ["input", "textarea"]) || isContentEditable(element)),
1343
+ handle: (keyDef, element) => {
1344
+ var _a, _b;
1345
+ if (keyDef.key === "Home") {
1346
+ setSelectionRange(element, 0, 0);
1347
+ } else {
1348
+ const newPos = (_b = (_a = getValue(element)) == null ? void 0 : _a.length) != null ? _b : 0;
1349
+ setSelectionRange(element, newPos, newPos);
1350
+ }
1351
+ }
1352
+ },
1353
+ {
1354
+ matches: (keyDef, element) => (keyDef.key === "PageUp" || keyDef.key === "PageDown") && isElementType(element, ["input"]),
1355
+ handle: (keyDef, element) => {
1356
+ var _a, _b;
1357
+ if (keyDef.key === "PageUp") {
1358
+ setSelectionRange(element, 0, 0);
1359
+ } else {
1360
+ const newPos = (_b = (_a = getValue(element)) == null ? void 0 : _a.length) != null ? _b : 0;
1361
+ setSelectionRange(element, newPos, newPos);
1362
+ }
1363
+ }
1364
+ },
1365
+ {
1366
+ matches: (keyDef, element) => keyDef.key === "Delete" && isEditable(element),
1367
+ handle: (keDef, element) => {
1368
+ var _a;
1369
+ (_a = prepareInput("", element, "deleteContentForward")) == null ? void 0 : _a.commit();
1370
+ }
1371
+ }
1372
+ ];
1373
+
1374
+ // src/keyboard/plugins/character.ts
1375
+ var import_dom7 = require("@testing-library/dom");
1376
+
1377
+ // src/keyboard/shared/fireChangeForInputTimeIfValid.ts
1378
+ var import_dom6 = require("@testing-library/dom");
1379
+ function fireChangeForInputTimeIfValid(el, prevValue, timeNewEntry) {
1380
+ if (isValidInputTimeValue(el, timeNewEntry) && prevValue !== timeNewEntry) {
1381
+ import_dom6.fireEvent.change(el, { target: { value: timeNewEntry } });
1382
+ }
1383
+ }
1384
+
1385
+ // src/keyboard/plugins/character.ts
1386
+ var keypressBehavior = [
1387
+ {
1388
+ matches: (keyDef, element) => {
1389
+ var _a;
1390
+ return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "time", readOnly: false });
1391
+ },
1392
+ handle: (keyDef, element, { keyboardState }) => {
1393
+ var _a;
1394
+ let newEntry = keyDef.key;
1395
+ const textToBeTyped = ((_a = keyboardState.carryValue) != null ? _a : "") + newEntry;
1396
+ const timeNewEntry = buildTimeValue(textToBeTyped);
1397
+ if (isValidInputTimeValue(element, timeNewEntry)) {
1398
+ newEntry = timeNewEntry;
1399
+ }
1400
+ const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
1401
+ const prevValue = getValue(element);
1402
+ if (prevValue !== newValue) {
1403
+ editInputElement(element, {
1404
+ newValue,
1405
+ newSelection: {
1406
+ node: element,
1407
+ offset: newOffset
1408
+ },
1409
+ eventOverrides: {
1410
+ data: keyDef.key,
1411
+ inputType: "insertText"
1412
+ }
1413
+ });
1414
+ }
1415
+ fireChangeForInputTimeIfValid(element, prevValue, timeNewEntry);
1416
+ keyboardState.carryValue = textToBeTyped;
1417
+ }
1418
+ },
1419
+ {
1420
+ matches: (keyDef, element) => {
1421
+ var _a;
1422
+ return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "date", readOnly: false });
1423
+ },
1424
+ handle: (keyDef, element, { keyboardState }) => {
1425
+ var _a;
1426
+ let newEntry = keyDef.key;
1427
+ const textToBeTyped = ((_a = keyboardState.carryValue) != null ? _a : "") + newEntry;
1428
+ const isValidToBeTyped = isValidDateValue(element, textToBeTyped);
1429
+ if (isValidToBeTyped) {
1430
+ newEntry = textToBeTyped;
1431
+ }
1432
+ const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
1433
+ const prevValue = getValue(element);
1434
+ if (prevValue !== newValue) {
1435
+ editInputElement(element, {
1436
+ newValue,
1437
+ newSelection: {
1438
+ node: element,
1439
+ offset: newOffset
1440
+ },
1441
+ eventOverrides: {
1442
+ data: keyDef.key,
1443
+ inputType: "insertText"
1444
+ }
1445
+ });
1446
+ }
1447
+ if (isValidToBeTyped) {
1448
+ import_dom7.fireEvent.change(element, {
1449
+ target: { value: textToBeTyped }
1450
+ });
1451
+ }
1452
+ keyboardState.carryValue = textToBeTyped;
1453
+ }
1454
+ },
1455
+ {
1456
+ matches: (keyDef, element) => {
1457
+ var _a;
1458
+ return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "number", readOnly: false });
1459
+ },
1460
+ handle: (keyDef, element) => {
1461
+ var _a, _b;
1462
+ if (!/[\d.\-e]/.test(keyDef.key)) {
1463
+ return;
1464
+ }
1465
+ const { getNewValue, commit } = prepareInput(keyDef.key, element);
1466
+ const newValue = getNewValue();
1467
+ const valueParts = newValue.split("e", 2);
1468
+ if (Number((_a = newValue.match(/-/g)) == null ? void 0 : _a.length) > 2 || Number((_b = newValue.match(/\./g)) == null ? void 0 : _b.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1])) {
1469
+ return;
1470
+ }
1471
+ commit();
1472
+ }
1473
+ },
1474
+ {
1475
+ matches: (keyDef, element) => {
1476
+ var _a;
1477
+ return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && (isEditableInput(element) || isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0;
1478
+ },
1479
+ handle: (keyDef, element) => {
1480
+ var _a;
1481
+ (_a = prepareInput(keyDef.key, element)) == null ? void 0 : _a.commit();
1482
+ }
1483
+ },
1484
+ {
1485
+ matches: (keyDef, element) => keyDef.key === "Enter" && (isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0,
1486
+ handle: (keyDef, element, { keyboardState }) => {
1487
+ var _a;
1488
+ (_a = prepareInput("\n", element, isContentEditable(element) && !keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak")) == null ? void 0 : _a.commit();
1489
+ }
1490
+ }
1491
+ ];
1492
+
1493
+ // src/keyboard/plugins/functional.ts
1494
+ var import_dom8 = require("@testing-library/dom");
1495
+ var keydownBehavior3 = [
1496
+ {
1497
+ matches: (keyDef, element) => keyDef.key === "Backspace" && isEditable(element),
1498
+ handle: (keyDef, element) => {
1499
+ var _a;
1500
+ (_a = prepareInput("", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
1501
+ }
1502
+ },
1503
+ {
1504
+ matches: (keyDef) => keyDef.key === "Tab",
1505
+ handle: (keyDef, element, { keyboardState }) => {
1506
+ const dest = getTabDestination(element, keyboardState.modifiers.Shift);
1507
+ if (dest === element.ownerDocument.body) {
1508
+ blur(element);
1509
+ } else {
1510
+ focus(dest);
1511
+ if (isElementType(dest, ["input", "textarea"])) {
1512
+ setUISelection(dest, {
1513
+ anchorOffset: 0,
1514
+ focusOffset: dest.value.length
1515
+ });
1516
+ }
1517
+ }
1518
+ }
1519
+ }
1520
+ ];
1521
+ var keypressBehavior2 = [
1522
+ {
1523
+ matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input") && ["checkbox", "radio"].includes(element.type),
1524
+ handle: (keyDef, element) => {
1525
+ const form = element.form;
1526
+ if (hasFormSubmit(form)) {
1527
+ import_dom8.fireEvent.submit(form);
1528
+ }
1529
+ }
1530
+ },
1531
+ {
1532
+ matches: (keyDef, element) => keyDef.key === "Enter" && (isClickableInput(element) || isElementType(element, "a") && Boolean(element.href)),
1533
+ handle: (keyDef, element, { keyboardState }) => {
1534
+ import_dom8.fireEvent.click(element, getUIEventModifiers(keyboardState));
1535
+ }
1536
+ },
1537
+ {
1538
+ matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input"),
1539
+ handle: (keyDef, element) => {
1540
+ const form = element.form;
1541
+ if (form && (form.querySelectorAll("input").length === 1 || hasFormSubmit(form))) {
1542
+ import_dom8.fireEvent.submit(form);
1543
+ }
1544
+ }
1545
+ }
1546
+ ];
1547
+ var keyupBehavior = [
1548
+ {
1549
+ matches: (keyDef, element) => keyDef.key === " " && isClickableInput(element),
1550
+ handle: (keyDef, element, { keyboardState }) => {
1551
+ import_dom8.fireEvent.click(element, getUIEventModifiers(keyboardState));
1552
+ }
1553
+ }
1554
+ ];
1555
+
1556
+ // src/keyboard/plugins/combination.ts
1557
+ var keydownBehavior4 = [
1558
+ {
1559
+ matches: (keyDef, element, { keyboardState }) => keyDef.code === "KeyA" && keyboardState.modifiers.Control,
1560
+ handle: (keyDef, element) => selectAll(element)
1561
+ }
1562
+ ];
1563
+
1564
+ // src/keyboard/plugins/modifiers.ts
1565
+ var import_dom9 = require("@testing-library/dom");
1566
+ var modifierKeys = [
1567
+ "Alt",
1568
+ "AltGraph",
1569
+ "Control",
1570
+ "Fn",
1571
+ "Meta",
1572
+ "Shift",
1573
+ "Symbol"
1574
+ ];
1575
+ var modifierLocks = [
1576
+ "CapsLock",
1577
+ "FnLock",
1578
+ "NumLock",
1579
+ "ScrollLock",
1580
+ "SymbolLock"
1581
+ ];
1582
+ var preKeydownBehavior = [
1583
+ {
1584
+ matches: (keyDef) => modifierKeys.includes(keyDef.key),
1585
+ handle: (keyDef, element, { keyboardMap, keyboardState }) => {
1586
+ var _a;
1587
+ keyboardState.modifiers[keyDef.key] = true;
1588
+ if (keyDef.key === "AltGraph") {
1589
+ const ctrlKeyDef = (_a = keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
1590
+ import_dom9.fireEvent.keyDown(element, getKeyEventProps(ctrlKeyDef, keyboardState));
1591
+ }
1592
+ }
1593
+ },
1594
+ {
1595
+ matches: (keyDef) => modifierLocks.includes(keyDef.key),
1596
+ handle: (keyDef, element, { keyboardState }) => {
1597
+ const key = keyDef.key;
1598
+ keyboardState.modifierPhase[key] = keyboardState.modifiers[key];
1599
+ if (!keyboardState.modifierPhase[key]) {
1600
+ keyboardState.modifiers[key] = true;
1601
+ }
1602
+ }
1603
+ }
1604
+ ];
1605
+ var preKeyupBehavior = [
1606
+ {
1607
+ matches: (keyDef) => modifierKeys.includes(keyDef.key),
1608
+ handle: (keyDef, element, { keyboardState }) => {
1609
+ keyboardState.modifiers[keyDef.key] = false;
1610
+ }
1611
+ },
1612
+ {
1613
+ matches: (keyDef) => modifierLocks.includes(keyDef.key),
1614
+ handle: (keyDef, element, { keyboardState }) => {
1615
+ const key = keyDef.key;
1616
+ if (keyboardState.modifierPhase[key]) {
1617
+ keyboardState.modifiers[key] = false;
1618
+ }
1619
+ }
1620
+ }
1621
+ ];
1622
+ var postKeyupBehavior = [
1623
+ {
1624
+ matches: (keyDef) => keyDef.key === "AltGraph",
1625
+ handle: (keyDef, element, { keyboardMap, keyboardState }) => {
1626
+ var _a;
1627
+ const ctrlKeyDef = (_a = keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
1628
+ import_dom9.fireEvent.keyUp(element, getKeyEventProps(ctrlKeyDef, keyboardState));
1629
+ }
1630
+ }
1631
+ ];
1632
+
1633
+ // src/keyboard/plugins/index.ts
1634
+ var preKeydownBehavior2 = [
1635
+ ...preKeydownBehavior
1636
+ ];
1637
+ var keydownBehavior5 = [
1638
+ ...keydownBehavior,
1639
+ ...keydownBehavior2,
1640
+ ...keydownBehavior3,
1641
+ ...keydownBehavior4
1642
+ ];
1643
+ var keypressBehavior3 = [
1644
+ ...keypressBehavior2,
1645
+ ...keypressBehavior
1646
+ ];
1647
+ var preKeyupBehavior2 = [
1648
+ ...preKeyupBehavior
1649
+ ];
1650
+ var keyupBehavior2 = [...keyupBehavior];
1651
+ var postKeyupBehavior2 = [
1652
+ ...postKeyupBehavior
1653
+ ];
1654
+
1655
+ // src/keyboard/keyboardAction.ts
1656
+ async function keyboardAction(config, actions) {
1657
+ for (let i = 0; i < actions.length; i++) {
1658
+ await keyboardKeyAction(config, actions[i]);
1659
+ if (typeof config.delay === "number" && i < actions.length - 1) {
1660
+ await wait(config.delay);
1661
+ }
1662
+ }
1663
+ }
1664
+ async function keyboardKeyAction(config, { keyDef, releasePrevious, releaseSelf, repeat }) {
1665
+ const { document: document2, keyboardState, delay } = config;
1666
+ const getCurrentElement = () => getActive(document2);
1667
+ const pressed = keyboardState.pressed.find((p) => p.keyDef === keyDef);
1668
+ if (pressed) {
1669
+ await keyup(keyDef, getCurrentElement, config, pressed.unpreventedDefault);
1670
+ }
1671
+ if (!releasePrevious) {
1672
+ let unpreventedDefault = true;
1673
+ for (let i = 1; i <= repeat; i++) {
1674
+ unpreventedDefault = await keydown(keyDef, getCurrentElement, config);
1675
+ if (unpreventedDefault && hasKeyPress(keyDef, config)) {
1676
+ await keypress(keyDef, getCurrentElement, config);
1677
+ }
1678
+ if (typeof delay === "number" && i < repeat) {
1679
+ await wait(delay);
1680
+ }
1681
+ }
1682
+ if (releaseSelf) {
1683
+ await keyup(keyDef, getCurrentElement, config, unpreventedDefault);
1684
+ }
1685
+ }
1686
+ }
1687
+ function getActive(document2) {
1688
+ var _a;
1689
+ return (_a = getActiveElement(document2)) != null ? _a : document2.body;
1690
+ }
1691
+ async function releaseAllKeys(config) {
1692
+ const getCurrentElement = () => getActive(config.document);
1693
+ for (const k of config.keyboardState.pressed) {
1694
+ await keyup(k.keyDef, getCurrentElement, config, k.unpreventedDefault);
1695
+ }
1696
+ }
1697
+ async function keydown(keyDef, getCurrentElement, config) {
1698
+ const element = getCurrentElement();
1699
+ if (element !== config.keyboardState.activeElement) {
1700
+ config.keyboardState.carryValue = void 0;
1701
+ config.keyboardState.carryChar = "";
1702
+ }
1703
+ config.keyboardState.activeElement = element;
1704
+ applyPlugins(preKeydownBehavior2, keyDef, element, config);
1705
+ const unpreventedDefault = import_dom10.fireEvent.keyDown(element, getKeyEventProps(keyDef, config.keyboardState));
1706
+ config.keyboardState.pressed.push({ keyDef, unpreventedDefault });
1707
+ if (unpreventedDefault) {
1708
+ applyPlugins(keydownBehavior5, keyDef, getCurrentElement(), config);
1709
+ }
1710
+ return unpreventedDefault;
1711
+ }
1712
+ async function keypress(keyDef, getCurrentElement, config) {
1713
+ const element = getCurrentElement();
1714
+ const unpreventedDefault = import_dom10.fireEvent.keyPress(element, __spreadProps(__spreadValues({}, getKeyEventProps(keyDef, config.keyboardState)), {
1715
+ charCode: keyDef.key === "Enter" ? 13 : String(keyDef.key).charCodeAt(0)
1716
+ }));
1717
+ if (unpreventedDefault) {
1718
+ applyPlugins(keypressBehavior3, keyDef, getCurrentElement(), config);
1719
+ }
1720
+ }
1721
+ async function keyup(keyDef, getCurrentElement, config, unprevented) {
1722
+ const element = getCurrentElement();
1723
+ applyPlugins(preKeyupBehavior2, keyDef, element, config);
1724
+ const unpreventedDefault = import_dom10.fireEvent.keyUp(element, getKeyEventProps(keyDef, config.keyboardState));
1725
+ if (unprevented && unpreventedDefault) {
1726
+ applyPlugins(keyupBehavior2, keyDef, getCurrentElement(), config);
1727
+ }
1728
+ config.keyboardState.pressed = config.keyboardState.pressed.filter((k) => k.keyDef !== keyDef);
1729
+ applyPlugins(postKeyupBehavior2, keyDef, element, config);
1730
+ }
1731
+ function applyPlugins(pluginCollection, keyDef, element, config) {
1732
+ const plugin = pluginCollection.find((p) => p.matches(keyDef, element, config));
1733
+ if (plugin) {
1734
+ plugin.handle(keyDef, element, config);
1735
+ }
1736
+ return !!plugin;
1737
+ }
1738
+ function hasKeyPress(keyDef, config) {
1739
+ var _a;
1740
+ return (((_a = keyDef.key) == null ? void 0 : _a.length) === 1 || keyDef.key === "Enter") && !config.keyboardState.modifiers.Control && !config.keyboardState.modifiers.Alt;
1741
+ }
1742
+
1743
+ // src/keyboard/parseKeyDef.ts
1744
+ function parseKeyDef(keyboardMap, text) {
1745
+ var _a;
1746
+ const defs = [];
1747
+ do {
1748
+ const {
1749
+ type: type3,
1750
+ descriptor,
1751
+ consumedLength,
1752
+ releasePrevious,
1753
+ releaseSelf = true,
1754
+ repeat
1755
+ } = readNextDescriptor(text);
1756
+ const keyDef = (_a = keyboardMap.find((def) => {
1757
+ var _a2, _b;
1758
+ if (type3 === "[") {
1759
+ return ((_a2 = def.code) == null ? void 0 : _a2.toLowerCase()) === descriptor.toLowerCase();
1760
+ } else if (type3 === "{") {
1761
+ return ((_b = def.key) == null ? void 0 : _b.toLowerCase()) === descriptor.toLowerCase();
1762
+ }
1763
+ return def.key === descriptor;
1764
+ })) != null ? _a : {
1765
+ key: "Unknown",
1766
+ code: "Unknown",
1767
+ [type3 === "[" ? "code" : "key"]: descriptor
1768
+ };
1769
+ defs.push({ keyDef, releasePrevious, releaseSelf, repeat });
1770
+ text = text.slice(consumedLength);
1771
+ } while (text);
1772
+ return defs;
1773
+ }
1774
+
1775
+ // src/keyboard/index.ts
1776
+ async function keyboard(text) {
1777
+ const { keyboardMap } = this[Config];
1778
+ const actions = parseKeyDef(keyboardMap, text);
1779
+ return keyboardAction(this[Config], actions);
1780
+ }
1781
+ function createKeyboardState() {
1782
+ return {
1783
+ activeElement: null,
1784
+ pressed: [],
1785
+ carryChar: "",
1786
+ modifiers: {
1787
+ Alt: false,
1788
+ AltGraph: false,
1789
+ Control: false,
1790
+ CapsLock: false,
1791
+ Fn: false,
1792
+ FnLock: false,
1793
+ Meta: false,
1794
+ NumLock: false,
1795
+ ScrollLock: false,
1796
+ Shift: false,
1797
+ Symbol: false,
1798
+ SymbolLock: false
1799
+ },
1800
+ modifierPhase: {}
1801
+ };
1802
+ }
1803
+
1804
+ // src/pointer/parseKeyDef.ts
1805
+ function parseKeyDef2(pointerMap, keys) {
1806
+ const defs = [];
1807
+ do {
1808
+ const {
1809
+ descriptor,
1810
+ consumedLength,
1811
+ releasePrevious,
1812
+ releaseSelf = true
1813
+ } = readNextDescriptor(keys);
1814
+ const keyDef = pointerMap.find((p) => p.name === descriptor);
1815
+ if (keyDef) {
1816
+ defs.push({ keyDef, releasePrevious, releaseSelf });
1817
+ }
1818
+ keys = keys.slice(consumedLength);
1819
+ } while (keys);
1820
+ return defs;
1821
+ }
1822
+
1823
+ // src/pointer/resolveSelectionTarget.ts
1824
+ function resolveSelectionTarget({
1825
+ target,
1826
+ node,
1827
+ offset
1828
+ }) {
1829
+ if (isElementType(target, ["input", "textarea"])) {
1830
+ return {
1831
+ node: target,
1832
+ offset: offset != null ? offset : getUIValue(target).length
1833
+ };
1834
+ } else if (node) {
1835
+ return {
1836
+ node,
1837
+ offset: offset != null ? offset : node.nodeType === 3 ? node.nodeValue.length : node.childNodes.length
1838
+ };
1839
+ }
1840
+ return findNodeAtTextOffset(target, offset);
1841
+ }
1842
+ function findNodeAtTextOffset(node, offset, isRoot = true) {
1843
+ let i = offset === void 0 ? node.childNodes.length - 1 : 0;
1844
+ const step = offset === void 0 ? -1 : 1;
1845
+ while (offset === void 0 ? i >= (isRoot ? Math.max(node.childNodes.length - 1, 0) : 0) : i <= node.childNodes.length) {
1846
+ const c = node.childNodes.item(i);
1847
+ const text = String(c.textContent);
1848
+ if (text.length) {
1849
+ if (offset !== void 0 && text.length < offset) {
1850
+ offset -= text.length;
1851
+ } else if (c.nodeType === 1) {
1852
+ return findNodeAtTextOffset(c, offset, false);
1853
+ } else {
1854
+ if (c.nodeType === 3) {
1855
+ return {
1856
+ node: c,
1857
+ offset: offset != null ? offset : c.nodeValue.length
1858
+ };
1859
+ }
1860
+ }
1861
+ }
1862
+ i += step;
1863
+ }
1864
+ return { node, offset: node.childNodes.length };
1865
+ }
1866
+
1867
+ // src/pointer/pointerMove.ts
1868
+ async function pointerMove({ pointerName = "mouse", target, coords, node, offset }, { pointerState, keyboardState }) {
1869
+ if (!(pointerName in pointerState.position)) {
1870
+ throw new Error(`Trying to move pointer "${pointerName}" which does not exist.`);
1871
+ }
1872
+ const {
1873
+ pointerId,
1874
+ pointerType,
1875
+ target: prevTarget,
1876
+ coords: prevCoords,
1877
+ selectionRange
1878
+ } = pointerState.position[pointerName];
1879
+ if (prevTarget && prevTarget !== target) {
1880
+ fireMove(prevTarget, prevCoords);
1881
+ if (!isDescendantOrSelf(target, prevTarget)) {
1882
+ fireLeave(prevTarget, prevCoords);
1883
+ }
1884
+ }
1885
+ pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
1886
+ target,
1887
+ coords
1888
+ });
1889
+ if (prevTarget !== target) {
1890
+ if (!prevTarget || !isDescendantOrSelf(prevTarget, target)) {
1891
+ fireEnter(target, coords);
1892
+ }
1893
+ }
1894
+ fireMove(target, coords);
1895
+ if (selectionRange) {
1896
+ const selectionFocus = resolveSelectionTarget({ target, node, offset });
1897
+ if ("node" in selectionRange) {
1898
+ if (selectionFocus.node === selectionRange.node) {
1899
+ const anchorOffset = selectionFocus.offset < selectionRange.start ? selectionRange.end : selectionRange.start;
1900
+ const focusOffset = selectionFocus.offset > selectionRange.end || selectionFocus.offset < selectionRange.start ? selectionFocus.offset : selectionRange.end;
1901
+ setUISelection(selectionRange.node, { anchorOffset, focusOffset });
1902
+ }
1903
+ } else {
1904
+ const range = selectionRange.cloneRange();
1905
+ const cmp = range.comparePoint(selectionFocus.node, selectionFocus.offset);
1906
+ if (cmp < 0) {
1907
+ range.setStart(selectionFocus.node, selectionFocus.offset);
1908
+ } else if (cmp > 0) {
1909
+ range.setEnd(selectionFocus.node, selectionFocus.offset);
1910
+ }
1911
+ const selection = target.ownerDocument.getSelection();
1912
+ selection.removeAllRanges();
1913
+ selection.addRange(range.cloneRange());
1914
+ }
1915
+ }
1916
+ function fireMove(eventTarget, eventCoords) {
1917
+ fire(eventTarget, "pointermove", eventCoords);
1918
+ if (pointerType === "mouse" && !isDisabled(eventTarget)) {
1919
+ fire(eventTarget, "mousemove", eventCoords);
1920
+ }
1921
+ }
1922
+ function fireLeave(eventTarget, eventCoords) {
1923
+ fire(eventTarget, "pointerout", eventCoords);
1924
+ fire(eventTarget, "pointerleave", eventCoords);
1925
+ if (pointerType === "mouse" && !isDisabled(eventTarget)) {
1926
+ fire(eventTarget, "mouseout", eventCoords);
1927
+ fire(eventTarget, "mouseleave", eventCoords);
1928
+ }
1929
+ }
1930
+ function fireEnter(eventTarget, eventCoords) {
1931
+ fire(eventTarget, "pointerover", eventCoords);
1932
+ fire(eventTarget, "pointerenter", eventCoords);
1933
+ if (pointerType === "mouse" && !isDisabled(eventTarget)) {
1934
+ fire(eventTarget, "mouseover", eventCoords);
1935
+ fire(eventTarget, "mouseenter", eventCoords);
1936
+ }
1937
+ }
1938
+ function fire(eventTarget, type3, eventCoords) {
1939
+ return firePointerEvent(eventTarget, type3, {
1940
+ pointerState,
1941
+ keyboardState,
1942
+ coords: eventCoords,
1943
+ pointerId,
1944
+ pointerType
1945
+ });
1946
+ }
1947
+ }
1948
+
1949
+ // src/pointer/pointerPress.ts
1950
+ async function pointerPress(action, state) {
1951
+ const { keyDef, target, releasePrevious, releaseSelf } = action;
1952
+ const previous = state.pointerState.pressed.find((p) => p.keyDef === keyDef);
1953
+ const pointerName = keyDef.pointerType === "touch" ? keyDef.name : keyDef.pointerType;
1954
+ const targetIsDisabled = isDisabled(target);
1955
+ if (previous) {
1956
+ up(state, pointerName, action, previous, targetIsDisabled);
1957
+ }
1958
+ if (!releasePrevious) {
1959
+ const press = down(state, pointerName, action, targetIsDisabled);
1960
+ if (releaseSelf) {
1961
+ up(state, pointerName, action, press, targetIsDisabled);
1962
+ }
1963
+ }
1964
+ }
1965
+ function getNextPointerId(state) {
1966
+ state.pointerId = state.pointerId + 1;
1967
+ return state.pointerId;
1968
+ }
1969
+ function down({ pointerState, keyboardState }, pointerName, { keyDef, node, offset, target, coords }, targetIsDisabled) {
1970
+ var _a, _b, _c;
1971
+ const { name, pointerType, button } = keyDef;
1972
+ const pointerId = pointerType === "mouse" ? 1 : getNextPointerId(pointerState);
1973
+ pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
1974
+ pointerId,
1975
+ pointerType,
1976
+ target,
1977
+ coords
1978
+ });
1979
+ let isMultiTouch = false;
1980
+ let isPrimary = true;
1981
+ if (pointerType !== "mouse") {
1982
+ for (const obj of pointerState.pressed) {
1983
+ if (obj.keyDef.pointerType === pointerType) {
1984
+ obj.isMultiTouch = true;
1985
+ isMultiTouch = true;
1986
+ isPrimary = false;
1987
+ }
1988
+ }
1989
+ }
1990
+ if (((_a = pointerState.activeClickCount) == null ? void 0 : _a[0]) !== name) {
1991
+ delete pointerState.activeClickCount;
1992
+ }
1993
+ const clickCount = Number((_c = (_b = pointerState.activeClickCount) == null ? void 0 : _b[1]) != null ? _c : 0) + 1;
1994
+ pointerState.activeClickCount = [name, clickCount];
1995
+ const pressObj = {
1996
+ keyDef,
1997
+ downTarget: target,
1998
+ pointerId,
1999
+ unpreventedDefault: true,
2000
+ isMultiTouch,
2001
+ isPrimary,
2002
+ clickCount
2003
+ };
2004
+ pointerState.pressed.push(pressObj);
2005
+ if (!targetIsDisabled) {
2006
+ if (pointerType !== "mouse") {
2007
+ fire("pointerover");
2008
+ fire("pointerenter");
2009
+ }
2010
+ if (pointerType !== "mouse" || !pointerState.pressed.some((p) => p.keyDef !== keyDef && p.keyDef.pointerType === pointerType)) {
2011
+ fire("pointerdown");
2012
+ }
2013
+ if (pointerType === "mouse") {
2014
+ pressObj.unpreventedDefault = fire("mousedown");
2015
+ }
2016
+ }
2017
+ if (pointerType === "mouse" && pressObj.unpreventedDefault) {
2018
+ mousedownDefaultBehavior({
2019
+ target,
2020
+ targetIsDisabled,
2021
+ clickCount,
2022
+ position: pointerState.position[pointerName],
2023
+ node,
2024
+ offset
2025
+ });
2026
+ }
2027
+ if (pointerType === "mouse" && button === "secondary") {
2028
+ fire("contextmenu");
2029
+ }
2030
+ return pressObj;
2031
+ function fire(type3) {
2032
+ return firePointerEvent(target, type3, {
2033
+ pointerState,
2034
+ keyboardState,
2035
+ button,
2036
+ clickCount,
2037
+ coords,
2038
+ isPrimary,
2039
+ pointerId,
2040
+ pointerType
2041
+ });
2042
+ }
2043
+ }
2044
+ function up({ pointerState, keyboardState }, pointerName, {
2045
+ keyDef: { pointerType, button },
2046
+ target,
2047
+ coords,
2048
+ node,
2049
+ offset
2050
+ }, pressed, targetIsDisabled) {
2051
+ var _a;
2052
+ pointerState.pressed = pointerState.pressed.filter((p) => p !== pressed);
2053
+ const { isMultiTouch, isPrimary, pointerId, clickCount } = pressed;
2054
+ let { unpreventedDefault } = pressed;
2055
+ pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
2056
+ target,
2057
+ coords
2058
+ });
2059
+ if (!targetIsDisabled) {
2060
+ if (pointerType !== "mouse" || !pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).length) {
2061
+ fire("pointerup");
2062
+ }
2063
+ if (pointerType !== "mouse") {
2064
+ fire("pointerout");
2065
+ fire("pointerleave");
2066
+ }
2067
+ if (pointerType !== "mouse" && !isMultiTouch) {
2068
+ if (clickCount === 1) {
2069
+ fire("mouseover");
2070
+ fire("mouseenter");
2071
+ }
2072
+ fire("mousemove");
2073
+ unpreventedDefault = fire("mousedown") && unpreventedDefault;
2074
+ }
2075
+ }
2076
+ if (unpreventedDefault && pointerType !== "mouse" && !isMultiTouch) {
2077
+ mousedownDefaultBehavior({
2078
+ target,
2079
+ targetIsDisabled,
2080
+ clickCount,
2081
+ position: pointerState.position[pointerName],
2082
+ node,
2083
+ offset
2084
+ });
2085
+ }
2086
+ delete pointerState.position[pointerName].selectionRange;
2087
+ if (!targetIsDisabled) {
2088
+ if (pointerType === "mouse" || !isMultiTouch) {
2089
+ unpreventedDefault = fire("mouseup") && unpreventedDefault;
2090
+ const canClick = pointerType !== "mouse" || button === "primary";
2091
+ if (canClick && target === pressed.downTarget) {
2092
+ const unpreventedClick = fire("click");
2093
+ if (clickCount === 2) {
2094
+ fire("dblclick");
2095
+ }
2096
+ const control = (_a = target.closest("label")) == null ? void 0 : _a.control;
2097
+ if (unpreventedClick && control && isFocusable(control)) {
2098
+ focus(control);
2099
+ }
2100
+ }
2101
+ }
2102
+ }
2103
+ function fire(type3) {
2104
+ return firePointerEvent(target, type3, {
2105
+ pointerState,
2106
+ keyboardState,
2107
+ button,
2108
+ clickCount,
2109
+ coords,
2110
+ isPrimary,
2111
+ pointerId,
2112
+ pointerType
2113
+ });
2114
+ }
2115
+ }
2116
+ function mousedownDefaultBehavior({
2117
+ position,
2118
+ target,
2119
+ targetIsDisabled,
2120
+ clickCount,
2121
+ node,
2122
+ offset
2123
+ }) {
2124
+ var _a;
2125
+ focus((_a = findClosest(target, isFocusable)) != null ? _a : target.ownerDocument.body);
2126
+ if (!targetIsDisabled) {
2127
+ const hasValue = isElementType(target, ["input", "textarea"]);
2128
+ const text = String(hasValue ? getUIValue(target) : target.textContent);
2129
+ const [start, end] = node ? [offset, offset] : getTextRange(text, offset, clickCount);
2130
+ if (hasValue) {
2131
+ setUISelection(target, {
2132
+ anchorOffset: start != null ? start : text.length,
2133
+ focusOffset: end != null ? end : text.length
2134
+ });
2135
+ position.selectionRange = {
2136
+ node: target,
2137
+ start: start != null ? start : 0,
2138
+ end: end != null ? end : text.length
2139
+ };
2140
+ } else {
2141
+ const { node: startNode, offset: startOffset } = resolveSelectionTarget({
2142
+ target,
2143
+ node,
2144
+ offset: start
2145
+ });
2146
+ const { node: endNode, offset: endOffset } = resolveSelectionTarget({
2147
+ target,
2148
+ node,
2149
+ offset: end
2150
+ });
2151
+ const range = new Range();
2152
+ range.setStart(startNode, startOffset);
2153
+ range.setEnd(endNode, endOffset);
2154
+ position.selectionRange = range;
2155
+ const selection = target.ownerDocument.getSelection();
2156
+ selection.removeAllRanges();
2157
+ selection.addRange(range.cloneRange());
2158
+ }
2159
+ }
2160
+ }
2161
+ function getTextRange(text, pos, clickCount) {
2162
+ if (clickCount % 3 === 1 || text.length === 0) {
2163
+ return [pos, pos];
2164
+ }
2165
+ const textPos = pos != null ? pos : text.length;
2166
+ if (clickCount % 3 === 2) {
2167
+ return [
2168
+ textPos - text.substr(0, pos).match(/(\w+|\s+|\W)?$/)[0].length,
2169
+ pos === void 0 ? pos : pos + text.substr(pos).match(/^(\w+|\s+|\W)?/)[0].length
2170
+ ];
2171
+ }
2172
+ return [
2173
+ textPos - text.substr(0, pos).match(/[^\r\n]*$/)[0].length,
2174
+ pos === void 0 ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length
2175
+ ];
2176
+ }
2177
+
2178
+ // src/pointer/pointerAction.ts
2179
+ async function pointerAction(config, actions) {
2180
+ var _a, _b;
2181
+ for (let i = 0; i < actions.length; i++) {
2182
+ const action = actions[i];
2183
+ const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? action.keyDef.pointerType === "touch" ? action.keyDef.name : action.keyDef.pointerType : "mouse";
2184
+ const target = (_a = action.target) != null ? _a : getPrevTarget(pointerName, config.pointerState);
2185
+ const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
2186
+ await ("keyDef" in action ? pointerPress(__spreadProps(__spreadValues({}, action), { target, coords }), config) : pointerMove(__spreadProps(__spreadValues({}, action), { target, coords }), config));
2187
+ if (typeof config.delay === "number") {
2188
+ if (i < actions.length - 1) {
2189
+ await wait(config.delay);
2190
+ }
2191
+ }
2192
+ }
2193
+ delete config.pointerState.activeClickCount;
2194
+ }
2195
+ function getPrevTarget(pointerName, state) {
2196
+ if (!(pointerName in state.position) || !state.position[pointerName].target) {
2197
+ throw new Error("This pointer has no previous position. Provide a target property!");
2198
+ }
2199
+ return state.position[pointerName].target;
2200
+ }
2201
+
2202
+ // src/pointer/index.ts
2203
+ async function pointer(input) {
2204
+ const { pointerMap } = this[Config];
2205
+ const actions = [];
2206
+ (Array.isArray(input) ? input : [input]).forEach((actionInput) => {
2207
+ if (typeof actionInput === "string") {
2208
+ actions.push(...parseKeyDef2(pointerMap, actionInput));
2209
+ } else if ("keys" in actionInput) {
2210
+ actions.push(...parseKeyDef2(pointerMap, actionInput.keys).map((i) => __spreadValues(__spreadValues({}, actionInput), i)));
2211
+ } else {
2212
+ actions.push(actionInput);
2213
+ }
2214
+ });
2215
+ return pointerAction(this[Config], actions).then(() => void 0);
2216
+ }
2217
+ function createPointerState(document2) {
2218
+ return {
2219
+ pointerId: 1,
2220
+ position: {
2221
+ mouse: {
2222
+ pointerType: "mouse",
2223
+ pointerId: 1,
2224
+ target: document2.body,
2225
+ coords: {
2226
+ clientX: 0,
2227
+ clientY: 0,
2228
+ offsetX: 0,
2229
+ offsetY: 0,
2230
+ pageX: 0,
2231
+ pageY: 0,
2232
+ x: 0,
2233
+ y: 0
2234
+ }
2235
+ }
2236
+ },
2237
+ pressed: []
2238
+ };
2239
+ }
2240
+
2241
+ // src/keyboard/keyMap.ts
2242
+ var defaultKeyMap = [
2243
+ ..."0123456789".split("").map((c) => ({ code: `Digit${c}`, key: c })),
2244
+ ...")!@#$%^&*(".split("").map((c, i) => ({ code: `Digit${i}`, key: c, shiftKey: true })),
2245
+ ..."abcdefghijklmnopqrstuvwxyz".split("").map((c) => ({ code: `Key${c.toUpperCase()}`, key: c })),
2246
+ ..."ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("").map((c) => ({ code: `Key${c}`, key: c, shiftKey: true })),
2247
+ { code: "Space", key: " " },
2248
+ { code: "AltLeft", key: "Alt", location: 1 /* LEFT */ },
2249
+ { code: "AltRight", key: "Alt", location: 2 /* RIGHT */ },
2250
+ {
2251
+ code: "ShiftLeft",
2252
+ key: "Shift",
2253
+ location: 1 /* LEFT */
2254
+ },
2255
+ {
2256
+ code: "ShiftRight",
2257
+ key: "Shift",
2258
+ location: 2 /* RIGHT */
2259
+ },
2260
+ {
2261
+ code: "ControlLeft",
2262
+ key: "Control",
2263
+ location: 1 /* LEFT */
2264
+ },
2265
+ {
2266
+ code: "ControlRight",
2267
+ key: "Control",
2268
+ location: 2 /* RIGHT */
2269
+ },
2270
+ { code: "MetaLeft", key: "Meta", location: 1 /* LEFT */ },
2271
+ {
2272
+ code: "MetaRight",
2273
+ key: "Meta",
2274
+ location: 2 /* RIGHT */
2275
+ },
2276
+ { code: "OSLeft", key: "OS", location: 1 /* LEFT */ },
2277
+ { code: "OSRight", key: "OS", location: 2 /* RIGHT */ },
2278
+ { code: "Tab", key: "Tab" },
2279
+ { code: "CapsLock", key: "CapsLock" },
2280
+ { code: "Backspace", key: "Backspace" },
2281
+ { code: "Enter", key: "Enter" },
2282
+ { code: "Escape", key: "Escape" },
2283
+ { code: "ArrowUp", key: "ArrowUp" },
2284
+ { code: "ArrowDown", key: "ArrowDown" },
2285
+ { code: "ArrowLeft", key: "ArrowLeft" },
2286
+ { code: "ArrowRight", key: "ArrowRight" },
2287
+ { code: "Home", key: "Home" },
2288
+ { code: "End", key: "End" },
2289
+ { code: "Delete", key: "Delete" },
2290
+ { code: "PageUp", key: "PageUp" },
2291
+ { code: "PageDown", key: "PageDown" },
2292
+ { code: "Fn", key: "Fn" },
2293
+ { code: "Symbol", key: "Symbol" },
2294
+ { code: "AltRight", key: "AltGraph" }
2295
+ ];
2296
+
2297
+ // src/pointer/keyMap.ts
2298
+ var defaultKeyMap2 = [
2299
+ { name: "MouseLeft", pointerType: "mouse", button: "primary" },
2300
+ { name: "MouseRight", pointerType: "mouse", button: "secondary" },
2301
+ { name: "MouseMiddle", pointerType: "mouse", button: "auxiliary" },
2302
+ { name: "TouchA", pointerType: "touch" },
2303
+ { name: "TouchB", pointerType: "touch" },
2304
+ { name: "TouchC", pointerType: "touch" }
2305
+ ];
2306
+
2307
+ // src/options.ts
2308
+ var defaultOptionsDirect = {
2309
+ applyAccept: true,
2310
+ autoModify: true,
2311
+ delay: 0,
2312
+ document: global.document,
2313
+ keyboardMap: defaultKeyMap,
2314
+ pointerMap: defaultKeyMap2,
2315
+ skipAutoClose: false,
2316
+ skipClick: false,
2317
+ skipHover: false,
2318
+ skipPointerEventsCheck: false,
2319
+ writeToClipboard: false
2320
+ };
2321
+ var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect), {
2322
+ writeToClipboard: true
2323
+ });
2324
+
2325
+ // src/setup/config.ts
2326
+ var Config = Symbol("Config");
2327
+
2328
+ // src/setup/api.ts
2329
+ var api_exports = {};
2330
+ __export(api_exports, {
2331
+ clear: () => clear,
2332
+ click: () => click,
2333
+ copy: () => copy,
2334
+ cut: () => cut,
2335
+ dblClick: () => dblClick,
2336
+ deselectOptions: () => deselectOptions,
2337
+ hover: () => hover,
2338
+ keyboard: () => keyboard,
2339
+ paste: () => paste,
2340
+ pointer: () => pointer,
2341
+ selectOptions: () => selectOptions,
2342
+ tab: () => tab,
2343
+ tripleClick: () => tripleClick,
2344
+ type: () => type,
2345
+ unhover: () => unhover,
2346
+ upload: () => upload
2347
+ });
2348
+
2349
+ // src/convenience/click.ts
2350
+ async function click(element) {
2351
+ if (!this[Config].skipPointerEventsCheck && !hasPointerEvents(element)) {
2352
+ throw new Error('unable to click element as it has or inherits pointer-events set to "none".');
2353
+ }
2354
+ const pointerIn = [];
2355
+ if (!this[Config].skipHover) {
2356
+ pointerIn.push({ target: element });
2357
+ }
2358
+ pointerIn.push({ keys: "[MouseLeft]", target: element });
2359
+ return this.pointer(pointerIn);
2360
+ }
2361
+ async function dblClick(element) {
2362
+ if (!this[Config].skipPointerEventsCheck && !hasPointerEvents(element)) {
2363
+ throw new Error('unable to double-click element as it has or inherits pointer-events set to "none".');
2364
+ }
2365
+ return this.pointer([{ target: element }, "[MouseLeft][MouseLeft]"]);
2366
+ }
2367
+ async function tripleClick(element) {
2368
+ if (!this[Config].skipPointerEventsCheck && !hasPointerEvents(element)) {
2369
+ throw new Error('unable to triple-click element as it has or inherits pointer-events set to "none".');
2370
+ }
2371
+ return this.pointer([{ target: element }, "[MouseLeft][MouseLeft][MouseLeft]"]);
2372
+ }
2373
+
2374
+ // src/convenience/hover.ts
2375
+ async function hover(element) {
2376
+ if (!this[Config].skipPointerEventsCheck && !hasPointerEvents(element)) {
2377
+ throw new Error('unable to hover element as it has or inherits pointer-events set to "none".');
2378
+ }
2379
+ return this.pointer({ target: element });
2380
+ }
2381
+ async function unhover(element) {
2382
+ if (!this[Config].skipPointerEventsCheck && !hasPointerEvents(element)) {
2383
+ throw new Error('unable to unhover element as it has or inherits pointer-events set to "none".');
2384
+ }
2385
+ return this.pointer({ target: element.ownerDocument.body });
2386
+ }
2387
+
2388
+ // src/convenience/tab.ts
2389
+ async function tab({
2390
+ shift
2391
+ } = {}) {
2392
+ return this.keyboard(shift === true ? "{Shift>}{Tab}{/Shift}" : shift === false ? "[/ShiftLeft][/ShiftRight]{Tab}" : "{Tab}");
2393
+ }
2394
+
2395
+ // src/clipboard/copy.ts
2396
+ var import_dom11 = require("@testing-library/dom");
2397
+ async function copy() {
2398
+ var _a;
2399
+ const doc = this[Config].document;
2400
+ const target = (_a = doc.activeElement) != null ? _a : doc.body;
2401
+ const clipboardData = copySelection(target);
2402
+ if (clipboardData.items.length === 0) {
2403
+ return;
2404
+ }
2405
+ import_dom11.fireEvent.copy(target, {
2406
+ clipboardData
2407
+ });
2408
+ if (this[Config].writeToClipboard) {
2409
+ await writeDataTransferToClipboard(doc, clipboardData);
2410
+ }
2411
+ return clipboardData;
2412
+ }
2413
+
2414
+ // src/clipboard/cut.ts
2415
+ var import_dom12 = require("@testing-library/dom");
2416
+ async function cut() {
2417
+ var _a, _b;
2418
+ const doc = this[Config].document;
2419
+ const target = (_a = doc.activeElement) != null ? _a : doc.body;
2420
+ const clipboardData = copySelection(target);
2421
+ if (clipboardData.items.length === 0) {
2422
+ return;
2423
+ }
2424
+ import_dom12.fireEvent.cut(target, {
2425
+ clipboardData
2426
+ });
2427
+ if (isEditable(target)) {
2428
+ (_b = prepareInput("", target, "deleteByCut")) == null ? void 0 : _b.commit();
2429
+ }
2430
+ if (this[Config].writeToClipboard) {
2431
+ await writeDataTransferToClipboard(doc, clipboardData);
2432
+ }
2433
+ return clipboardData;
2434
+ }
2435
+
2436
+ // src/clipboard/paste.ts
2437
+ var import_dom13 = require("@testing-library/dom");
2438
+ async function paste(clipboardData) {
2439
+ var _a, _b;
2440
+ const doc = this[Config].document;
2441
+ const target = (_a = doc.activeElement) != null ? _a : doc.body;
2442
+ const data = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : await readDataTransferFromClipboard(doc).catch(() => {
2443
+ throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
2444
+ });
2445
+ return pasteImpl(target, data);
2446
+ }
2447
+ function pasteImpl(target, clipboardData) {
2448
+ var _a;
2449
+ import_dom13.fireEvent.paste(target, {
2450
+ clipboardData
2451
+ });
2452
+ if (isEditable(target)) {
2453
+ const data = clipboardData.getData("text").substr(0, getSpaceUntilMaxLength(target));
2454
+ if (data) {
2455
+ (_a = prepareInput(data, target, "insertFromPaste")) == null ? void 0 : _a.commit();
2456
+ }
2457
+ }
2458
+ }
2459
+ function getClipboardDataFromString(text) {
2460
+ const dt = createDataTransfer();
2461
+ dt.setData("text", text);
2462
+ return dt;
2463
+ }
2464
+
2465
+ // src/utility/clear.ts
2466
+ async function clear(element) {
2467
+ var _a;
2468
+ if (!isEditable(element) || isDisabled(element)) {
2469
+ throw new Error("clear()` is only supported on editable elements.");
2470
+ }
2471
+ focus(element);
2472
+ if (element.ownerDocument.activeElement !== element) {
2473
+ throw new Error("The element to be cleared could not be focused.");
2474
+ }
2475
+ selectAll(element);
2476
+ if (!isAllSelected(element)) {
2477
+ throw new Error("The element content to be cleared could not be selected.");
2478
+ }
2479
+ (_a = prepareInput("", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
2480
+ }
2481
+
2482
+ // src/utility/selectOptions.ts
2483
+ var import_dom14 = require("@testing-library/dom");
2484
+ async function selectOptions(select, values) {
2485
+ return selectOptionsBase.call(this, true, select, values);
2486
+ }
2487
+ async function deselectOptions(select, values) {
2488
+ return selectOptionsBase.call(this, false, select, values);
2489
+ }
2490
+ async function selectOptionsBase(newValue, select, values) {
2491
+ if (!newValue && !select.multiple) {
2492
+ throw (0, import_dom14.getConfig)().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`, select);
2493
+ }
2494
+ const valArray = Array.isArray(values) ? values : [values];
2495
+ const allOptions = Array.from(select.querySelectorAll('option, [role="option"]'));
2496
+ const selectedOptions = valArray.map((val) => {
2497
+ if (typeof val !== "string" && allOptions.includes(val)) {
2498
+ return val;
2499
+ } else {
2500
+ const matchingOption = allOptions.find((o) => o.value === val || o.innerHTML === val);
2501
+ if (matchingOption) {
2502
+ return matchingOption;
2503
+ } else {
2504
+ throw (0, import_dom14.getConfig)().getElementError(`Value "${String(val)}" not found in options`, select);
2505
+ }
2506
+ }
2507
+ }).filter((option) => !isDisabled(option));
2508
+ if (isDisabled(select) || !selectedOptions.length)
2509
+ return;
2510
+ if (isElementType(select, "select")) {
2511
+ if (select.multiple) {
2512
+ for (const option of selectedOptions) {
2513
+ const withPointerEvents = this[Config].skipPointerEventsCheck ? true : hasPointerEvents(option);
2514
+ if (withPointerEvents) {
2515
+ import_dom14.fireEvent.pointerOver(option);
2516
+ import_dom14.fireEvent.pointerEnter(select);
2517
+ import_dom14.fireEvent.mouseOver(option);
2518
+ import_dom14.fireEvent.mouseEnter(select);
2519
+ import_dom14.fireEvent.pointerMove(option);
2520
+ import_dom14.fireEvent.mouseMove(option);
2521
+ import_dom14.fireEvent.pointerDown(option);
2522
+ import_dom14.fireEvent.mouseDown(option);
2523
+ }
2524
+ focus(select);
2525
+ if (withPointerEvents) {
2526
+ import_dom14.fireEvent.pointerUp(option);
2527
+ import_dom14.fireEvent.mouseUp(option);
2528
+ }
2529
+ selectOption(option);
2530
+ if (withPointerEvents) {
2531
+ import_dom14.fireEvent.click(option);
2532
+ }
2533
+ }
2534
+ } else if (selectedOptions.length === 1) {
2535
+ const withPointerEvents = this[Config].skipPointerEventsCheck ? true : hasPointerEvents(select);
2536
+ if (withPointerEvents) {
2537
+ await this.click(select);
2538
+ } else {
2539
+ focus(select);
2540
+ }
2541
+ selectOption(selectedOptions[0]);
2542
+ if (withPointerEvents) {
2543
+ import_dom14.fireEvent.pointerOver(select);
2544
+ import_dom14.fireEvent.pointerEnter(select);
2545
+ import_dom14.fireEvent.mouseOver(select);
2546
+ import_dom14.fireEvent.mouseEnter(select);
2547
+ import_dom14.fireEvent.pointerUp(select);
2548
+ import_dom14.fireEvent.mouseUp(select);
2549
+ import_dom14.fireEvent.click(select);
2550
+ }
2551
+ } else {
2552
+ throw (0, import_dom14.getConfig)().getElementError(`Cannot select multiple options on a non-multiple select`, select);
2553
+ }
2554
+ } else if (select.getAttribute("role") === "listbox") {
2555
+ for (const option of selectedOptions) {
2556
+ await this.click(option);
2557
+ await this.unhover(option);
2558
+ }
2559
+ } else {
2560
+ throw (0, import_dom14.getConfig)().getElementError(`Cannot select options on elements that are neither select nor listbox elements`, select);
2561
+ }
2562
+ function selectOption(option) {
2563
+ option.selected = newValue;
2564
+ (0, import_dom14.fireEvent)(select, (0, import_dom14.createEvent)("input", select, {
2565
+ bubbles: true,
2566
+ cancelable: false,
2567
+ composed: true
2568
+ }));
2569
+ import_dom14.fireEvent.change(select);
2570
+ }
2571
+ }
2572
+
2573
+ // src/utility/type.ts
2574
+ async function type(element, text, {
2575
+ skipClick = this[Config].skipClick,
2576
+ skipAutoClose = this[Config].skipAutoClose,
2577
+ initialSelectionStart,
2578
+ initialSelectionEnd
2579
+ } = {}) {
2580
+ if (element.disabled)
2581
+ return;
2582
+ if (!skipClick) {
2583
+ await this.click(element);
2584
+ }
2585
+ if (initialSelectionStart !== void 0) {
2586
+ setSelectionRange(element, initialSelectionStart, initialSelectionEnd != null ? initialSelectionEnd : initialSelectionStart);
2587
+ }
2588
+ await this.keyboard(text);
2589
+ if (!skipAutoClose) {
2590
+ await releaseAllKeys(this[Config]);
2591
+ }
2592
+ }
2593
+
2594
+ // src/utility/upload.ts
2595
+ var import_dom15 = require("@testing-library/dom");
2596
+ async function upload(element, fileOrFiles) {
2597
+ var _a;
2598
+ const input = isElementType(element, "label") ? element.control : element;
2599
+ if (!input || !isElementType(input, "input", { type: "file" })) {
2600
+ throw new TypeError(`The ${input === element ? "given" : "associated"} ${input == null ? void 0 : input.tagName} element does not accept file uploads`);
2601
+ }
2602
+ if (isDisabled(element))
2603
+ return;
2604
+ await this.click(element);
2605
+ const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? void 0 : 1);
2606
+ blur(element);
2607
+ focus(element);
2608
+ if (files.length === ((_a = input.files) == null ? void 0 : _a.length) && files.every((f, i) => {
2609
+ var _a2;
2610
+ return f === ((_a2 = input.files) == null ? void 0 : _a2.item(i));
2611
+ })) {
2612
+ return;
2613
+ }
2614
+ setFiles(input, createFileList(files));
2615
+ import_dom15.fireEvent.input(input);
2616
+ import_dom15.fireEvent.change(input);
2617
+ }
2618
+ function isAcceptableFile(file, accept) {
2619
+ if (!accept) {
2620
+ return true;
2621
+ }
2622
+ const wildcards = ["audio/*", "image/*", "video/*"];
2623
+ return accept.split(",").some((acceptToken) => {
2624
+ if (acceptToken.startsWith(".")) {
2625
+ return file.name.endsWith(acceptToken);
2626
+ } else if (wildcards.includes(acceptToken)) {
2627
+ return file.type.startsWith(acceptToken.substr(0, acceptToken.length - 1));
2628
+ }
2629
+ return file.type === acceptToken;
2630
+ });
2631
+ }
2632
+
2633
+ // src/setup/wrapAsync.ts
2634
+ var import_dom16 = require("@testing-library/dom");
2635
+ function wrapAsync(implementation) {
2636
+ return (0, import_dom16.getConfig)().asyncWrapper(implementation);
2637
+ }
2638
+
2639
+ // src/setup/setup.ts
2640
+ function setupMain(options = {}) {
2641
+ var _a;
2642
+ const doc = getDocument(options);
2643
+ prepareDocument(doc);
2644
+ const view = (_a = doc.defaultView) != null ? _a : window;
2645
+ attachClipboardStubToView(view);
2646
+ return doSetup(__spreadProps(__spreadValues({}, defaultOptionsSetup), {
2647
+ keyboardState: createKeyboardState(),
2648
+ pointerState: createPointerState(doc)
2649
+ }));
2650
+ }
2651
+ function setupDirect(options = {}, node) {
2652
+ const doc = getDocument(options, node);
2653
+ prepareDocument(doc);
2654
+ return doSetup(__spreadValues(__spreadValues({
2655
+ keyboardState: createKeyboardState(),
2656
+ pointerState: createPointerState(doc)
2657
+ }, defaultOptionsDirect), options));
2658
+ }
2659
+ function setupSub(options) {
2660
+ return doSetup(__spreadValues(__spreadValues({}, this[Config]), options));
2661
+ }
2662
+ function wrapImpl(impl) {
2663
+ function method(...args) {
2664
+ return wrapAsync(() => impl.apply(this, args));
2665
+ }
2666
+ Object.defineProperty(method, "name", { get: () => impl.name });
2667
+ return method;
2668
+ }
2669
+ var wrappedApis = Object.fromEntries(Object.entries(api_exports).map(([name, impl]) => [name, wrapImpl(impl)]));
2670
+ function doSetup(config) {
2671
+ return __spreadProps(__spreadValues({}, wrappedApis), {
2672
+ setup: setupSub,
2673
+ [Config]: config
2674
+ });
2675
+ }
2676
+ function getDocument(options, node) {
2677
+ var _a, _b;
2678
+ return (_b = (_a = options.document) != null ? _a : node && getDocumentFromNode(node)) != null ? _b : document;
2679
+ }
2680
+
2681
+ // src/setup/directApi.ts
2682
+ var directApi_exports = {};
2683
+ __export(directApi_exports, {
2684
+ clear: () => clear2,
2685
+ click: () => click2,
2686
+ copy: () => copy2,
2687
+ cut: () => cut2,
2688
+ dblClick: () => dblClick2,
2689
+ deselectOptions: () => deselectOptions2,
2690
+ hover: () => hover2,
2691
+ keyboard: () => keyboard2,
2692
+ paste: () => paste2,
2693
+ pointer: () => pointer2,
2694
+ selectOptions: () => selectOptions2,
2695
+ tab: () => tab2,
2696
+ tripleClick: () => tripleClick2,
2697
+ type: () => type2,
2698
+ unhover: () => unhover2,
2699
+ upload: () => upload2
2700
+ });
2701
+ function clear2(element) {
2702
+ return setupDirect().clear(element);
2703
+ }
2704
+ function click2(element, options = {}) {
2705
+ return setupDirect(options, element).click(element);
2706
+ }
2707
+ function copy2(options = {}) {
2708
+ return setupDirect(options).copy();
2709
+ }
2710
+ function cut2(options = {}) {
2711
+ return setupDirect(options).cut();
2712
+ }
2713
+ function dblClick2(element, options = {}) {
2714
+ return setupDirect(options).dblClick(element);
2715
+ }
2716
+ function deselectOptions2(select, values, options = {}) {
2717
+ return setupDirect(options).deselectOptions(select, values);
2718
+ }
2719
+ function hover2(element, options = {}) {
2720
+ return setupDirect(options).hover(element);
2721
+ }
2722
+ async function keyboard2(text, options = {}) {
2723
+ const instance = setupDirect(options);
2724
+ const promise = instance.keyboard(text);
2725
+ return promise.then(() => instance[Config].keyboardState);
2726
+ }
2727
+ async function pointer2(input, options = {}) {
2728
+ const instance = setupDirect(options);
2729
+ const promise = instance.pointer(input);
2730
+ return promise.then(() => instance[Config].pointerState);
2731
+ }
2732
+ function paste2(clipboardData, options) {
2733
+ return setupDirect(options).paste(clipboardData);
2734
+ }
2735
+ function selectOptions2(select, values, options = {}) {
2736
+ return setupDirect(options).selectOptions(select, values);
2737
+ }
2738
+ function tripleClick2(element, options = {}) {
2739
+ return setupDirect(options).tripleClick(element);
2740
+ }
2741
+ function type2(element, text, options = {}) {
2742
+ return setupDirect(options, element).type(element, text, options);
2743
+ }
2744
+ function unhover2(element, options = {}) {
2745
+ const instance = setupDirect(options);
2746
+ instance[Config].pointerState.position.mouse.target = element;
2747
+ return instance.unhover(element);
2748
+ }
2749
+ function upload2(element, fileOrFiles, options = {}) {
2750
+ return setupDirect(options).upload(element, fileOrFiles);
2751
+ }
2752
+ function tab2(options = {}) {
2753
+ return setupDirect().tab(options);
2754
+ }
2755
+
2756
+ // src/setup/index.ts
2757
+ var userEvent = __spreadProps(__spreadValues({}, directApi_exports), {
2758
+ setup: setupMain
2759
+ });
2760
+ module.exports = __toCommonJS(src_exports);