@testing-library/user-event 14.0.0-beta.4 → 14.0.0-beta.8

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