@testing-library/user-event 14.0.4 → 14.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -158,8 +158,8 @@ var DataTransferStub = class {
158
158
  this.files = createFileList([]);
159
159
  }
160
160
  getData(format) {
161
- var _a3;
162
- const match = (_a3 = this.items.find(getTypeMatcher(format, true))) != null ? _a3 : this.items.find(getTypeMatcher(format, false));
161
+ var _a;
162
+ const match = (_a = this.items.find(getTypeMatcher(format, true))) != null ? _a : this.items.find(getTypeMatcher(format, false));
163
163
  let text = "";
164
164
  match == null ? void 0 : match.getAsString((t) => {
165
165
  text = t;
@@ -197,12 +197,12 @@ var DataTransferStub = class {
197
197
  setDragImage() {
198
198
  }
199
199
  };
200
- function createDataTransfer(window2, files = []) {
201
- const dt = typeof window2.DataTransfer === "undefined" ? new DataTransferStub() : new window2.DataTransfer();
200
+ function createDataTransfer(window, files = []) {
201
+ const dt = typeof window.DataTransfer === "undefined" ? new DataTransferStub() : new window.DataTransfer();
202
202
  Object.defineProperty(dt, "files", { get: () => createFileList(files) });
203
203
  return dt;
204
204
  }
205
- function getBlobFromDataTransferItem(window2, item) {
205
+ function getBlobFromDataTransferItem(window, item) {
206
206
  if (item.kind === "file") {
207
207
  return item.getAsFile();
208
208
  }
@@ -210,7 +210,7 @@ function getBlobFromDataTransferItem(window2, item) {
210
210
  item.getAsString((s) => {
211
211
  data = s;
212
212
  });
213
- return new window2.Blob([data], { type: item.type });
213
+ return new window.Blob([data], { type: item.type });
214
214
  }
215
215
 
216
216
  // src/utils/misc/getWindow.ts
@@ -220,95 +220,88 @@ function getWindow(node) {
220
220
  }
221
221
 
222
222
  // src/utils/dataTransfer/Clipboard.ts
223
- var Window = Symbol("Window reference");
224
- var _a;
225
- var ClipboardItemStub = class {
226
- constructor(data) {
227
- this[_a] = window;
228
- this.data = data;
229
- }
230
- get types() {
231
- return Array.from(Object.keys(this.data));
232
- }
233
- getType(type3) {
234
- return __async(this, null, function* () {
235
- const data = yield this.data[type3];
236
- if (!data) {
237
- throw new Error(`${type3} is not one of the available MIME types on this item.`);
238
- }
239
- return data instanceof this[Window].Blob ? data : new this[Window].Blob([data], { type: type3 });
240
- });
241
- }
242
- };
243
- _a = Window;
244
- var ClipboardStubControl = Symbol("Manage ClipboardSub");
245
- var _a2;
246
- var ClipboardStub = class extends window.EventTarget {
247
- constructor() {
248
- super(...arguments);
249
- this.items = [];
250
- this[_a2] = window;
251
- }
252
- read() {
253
- return __async(this, null, function* () {
254
- return Array.from(this.items);
255
- });
256
- }
257
- readText() {
258
- return __async(this, null, function* () {
259
- let text = "";
260
- for (const item of this.items) {
261
- const type3 = item.types.includes("text/plain") ? "text/plain" : item.types.find((t) => t.startsWith("text/"));
262
- if (type3) {
263
- text += yield item.getType(type3).then((b) => readBlobText(b, this[Window].FileReader));
264
- }
265
- }
266
- return text;
267
- });
268
- }
269
- write(data) {
270
- return __async(this, null, function* () {
271
- this.items = data;
272
- });
273
- }
274
- writeText(text) {
275
- return __async(this, null, function* () {
276
- this.items = [createClipboardItem(this[Window], text)];
277
- });
278
- }
279
- };
280
- _a2 = Window, ClipboardStubControl;
281
- function createClipboardItem(window2, ...blobs) {
282
- const data = Object.fromEntries(blobs.map((b) => [
223
+ function createClipboardItem(window, ...blobs) {
224
+ const dataMap = Object.fromEntries(blobs.map((b) => [
283
225
  typeof b === "string" ? "text/plain" : b.type,
284
226
  Promise.resolve(b)
285
227
  ]));
286
- if (typeof window2.ClipboardItem === "undefined") {
287
- const item = new ClipboardItemStub(data);
288
- item[Window] = window2;
289
- return item;
290
- } else {
291
- return new window2.ClipboardItem(data);
228
+ if (typeof window.ClipboardItem !== "undefined") {
229
+ return new window.ClipboardItem(dataMap);
292
230
  }
231
+ return new class ClipboardItem {
232
+ constructor(d) {
233
+ this.data = d;
234
+ }
235
+ get types() {
236
+ return Array.from(Object.keys(this.data));
237
+ }
238
+ getType(type3) {
239
+ return __async(this, null, function* () {
240
+ const value = yield this.data[type3];
241
+ if (!value) {
242
+ throw new Error(`${type3} is not one of the available MIME types on this item.`);
243
+ }
244
+ return value instanceof window.Blob ? value : new window.Blob([value], { type: type3 });
245
+ });
246
+ }
247
+ }(dataMap);
248
+ }
249
+ var ClipboardStubControl = Symbol("Manage ClipboardSub");
250
+ function createClipboardStub(window) {
251
+ var _a;
252
+ return new (_a = class extends window.EventTarget {
253
+ constructor() {
254
+ super(...arguments);
255
+ this.items = [];
256
+ }
257
+ read() {
258
+ return __async(this, null, function* () {
259
+ return Array.from(this.items);
260
+ });
261
+ }
262
+ readText() {
263
+ return __async(this, null, function* () {
264
+ let text = "";
265
+ for (const item of this.items) {
266
+ const type3 = item.types.includes("text/plain") ? "text/plain" : item.types.find((t) => t.startsWith("text/"));
267
+ if (type3) {
268
+ text += yield item.getType(type3).then((b) => readBlobText(b, window.FileReader));
269
+ }
270
+ }
271
+ return text;
272
+ });
273
+ }
274
+ write(data) {
275
+ return __async(this, null, function* () {
276
+ this.items = data;
277
+ });
278
+ }
279
+ writeText(text) {
280
+ return __async(this, null, function* () {
281
+ this.items = [createClipboardItem(window, text)];
282
+ });
283
+ }
284
+ }, ClipboardStubControl, _a)();
285
+ }
286
+ function isClipboardStub(clipboard) {
287
+ return !!(clipboard == null ? void 0 : clipboard[ClipboardStubControl]);
293
288
  }
294
- function attachClipboardStubToView(window2) {
295
- if (window2.navigator.clipboard instanceof ClipboardStub) {
296
- return window2.navigator.clipboard[ClipboardStubControl];
289
+ function attachClipboardStubToView(window) {
290
+ if (isClipboardStub(window.navigator.clipboard)) {
291
+ return window.navigator.clipboard[ClipboardStubControl];
297
292
  }
298
- const realClipboard = Object.getOwnPropertyDescriptor(window2.navigator, "clipboard");
299
- let stub = new ClipboardStub();
300
- stub[Window] = window2;
293
+ const realClipboard = Object.getOwnPropertyDescriptor(window.navigator, "clipboard");
294
+ let stub = createClipboardStub(window);
301
295
  const control = {
302
296
  resetClipboardStub: () => {
303
- stub = new ClipboardStub();
304
- stub[Window] = window2;
297
+ stub = createClipboardStub(window);
305
298
  stub[ClipboardStubControl] = control;
306
299
  },
307
300
  detachClipboardStub: () => {
308
301
  if (realClipboard) {
309
- Object.defineProperty(window2.navigator, "clipboard", realClipboard);
302
+ Object.defineProperty(window.navigator, "clipboard", realClipboard);
310
303
  } else {
311
- Object.defineProperty(window2.navigator, "clipboard", {
304
+ Object.defineProperty(window.navigator, "clipboard", {
312
305
  value: void 0,
313
306
  configurable: true
314
307
  });
@@ -316,48 +309,48 @@ function attachClipboardStubToView(window2) {
316
309
  }
317
310
  };
318
311
  stub[ClipboardStubControl] = control;
319
- Object.defineProperty(window2.navigator, "clipboard", {
312
+ Object.defineProperty(window.navigator, "clipboard", {
320
313
  get: () => stub,
321
314
  configurable: true
322
315
  });
323
316
  return stub[ClipboardStubControl];
324
317
  }
325
- function resetClipboardStubOnView(window2) {
326
- if (window2.navigator.clipboard instanceof ClipboardStub) {
327
- window2.navigator.clipboard[ClipboardStubControl].resetClipboardStub();
318
+ function resetClipboardStubOnView(window) {
319
+ if (isClipboardStub(window.navigator.clipboard)) {
320
+ window.navigator.clipboard[ClipboardStubControl].resetClipboardStub();
328
321
  }
329
322
  }
330
- function detachClipboardStubFromView(window2) {
331
- if (window2.navigator.clipboard instanceof ClipboardStub) {
332
- window2.navigator.clipboard[ClipboardStubControl].detachClipboardStub();
323
+ function detachClipboardStubFromView(window) {
324
+ if (isClipboardStub(window.navigator.clipboard)) {
325
+ window.navigator.clipboard[ClipboardStubControl].detachClipboardStub();
333
326
  }
334
327
  }
335
- function readDataTransferFromClipboard(document2) {
328
+ function readDataTransferFromClipboard(document) {
336
329
  return __async(this, null, function* () {
337
- const window2 = document2.defaultView;
338
- const clipboard = window2 == null ? void 0 : window2.navigator.clipboard;
330
+ const window = document.defaultView;
331
+ const clipboard = window == null ? void 0 : window.navigator.clipboard;
339
332
  const items = clipboard && (yield clipboard.read());
340
333
  if (!items) {
341
334
  throw new Error("The Clipboard API is unavailable.");
342
335
  }
343
- const dt = createDataTransfer(window2);
336
+ const dt = createDataTransfer(window);
344
337
  for (const item of items) {
345
338
  for (const type3 of item.types) {
346
- dt.setData(type3, yield item.getType(type3).then((b) => readBlobText(b, window2.FileReader)));
339
+ dt.setData(type3, yield item.getType(type3).then((b) => readBlobText(b, window.FileReader)));
347
340
  }
348
341
  }
349
342
  return dt;
350
343
  });
351
344
  }
352
- function writeDataTransferToClipboard(document2, clipboardData) {
345
+ function writeDataTransferToClipboard(document, clipboardData) {
353
346
  return __async(this, null, function* () {
354
- const window2 = getWindow(document2);
355
- const clipboard = window2.navigator.clipboard;
347
+ const window = getWindow(document);
348
+ const clipboard = window.navigator.clipboard;
356
349
  const items = [];
357
350
  for (let i = 0; i < clipboardData.items.length; i++) {
358
351
  const dtItem = clipboardData.items[i];
359
- const blob = getBlobFromDataTransferItem(window2, dtItem);
360
- items.push(createClipboardItem(window2, blob));
352
+ const blob = getBlobFromDataTransferItem(window, dtItem);
353
+ items.push(createClipboardItem(window, blob));
361
354
  }
362
355
  const written = clipboard && (yield clipboard.write(items).then(() => true, () => false));
363
356
  if (!written) {
@@ -365,11 +358,11 @@ function writeDataTransferToClipboard(document2, clipboardData) {
365
358
  }
366
359
  });
367
360
  }
368
- if (typeof afterEach === "function") {
369
- afterEach(() => resetClipboardStubOnView(window));
361
+ if (typeof globalThis.afterEach === "function") {
362
+ globalThis.afterEach(() => resetClipboardStubOnView(globalThis.window));
370
363
  }
371
- if (typeof afterAll === "function") {
372
- afterAll(() => detachClipboardStubFromView(window));
364
+ if (typeof globalThis.afterAll === "function") {
365
+ globalThis.afterAll(() => detachClipboardStubFromView(globalThis.window));
373
366
  }
374
367
 
375
368
  // src/utils/edit/isContentEditable.ts
@@ -396,6 +389,7 @@ function getValue(element) {
396
389
  }
397
390
 
398
391
  // src/utils/edit/buildTimeValue.ts
392
+ var parseInt = globalThis.parseInt;
399
393
  function buildTimeValue(value) {
400
394
  const onlyDigitsValue = value.replace(/\D/g, "");
401
395
  if (onlyDigitsValue.length < 2) {
@@ -452,11 +446,11 @@ function getSpaceUntilMaxLength(element) {
452
446
  return maxLength ? maxLength - value.length : void 0;
453
447
  }
454
448
  function getSanitizedMaxLength(element) {
455
- var _a3;
449
+ var _a;
456
450
  if (!supportsMaxLength(element)) {
457
451
  return void 0;
458
452
  }
459
- const attr = (_a3 = element.getAttribute("maxlength")) != null ? _a3 : "";
453
+ const attr = (_a = element.getAttribute("maxlength")) != null ? _a : "";
460
454
  return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
461
455
  }
462
456
  function supportsMaxLength(element) {
@@ -525,7 +519,7 @@ function editContenteditable(config, element, inputRange, data, inputType) {
525
519
  function editInputElement(config, element, inputRange, data, inputType) {
526
520
  let dataToInsert = data;
527
521
  const spaceUntilMaxLength = getSpaceUntilMaxLength(element);
528
- if (spaceUntilMaxLength !== void 0) {
522
+ if (spaceUntilMaxLength !== void 0 && data.length > 0) {
529
523
  if (spaceUntilMaxLength > 0) {
530
524
  dataToInsert = data.substring(0, spaceUntilMaxLength);
531
525
  } else {
@@ -549,6 +543,7 @@ function editInputElement(config, element, inputRange, data, inputType) {
549
543
  if (isValidDateOrTimeValue(element, newValue)) {
550
544
  commitInput(config, element, newOffset, {});
551
545
  dispatchUIEvent(config, element, "change");
546
+ clearInitialValue(element);
552
547
  }
553
548
  } else {
554
549
  commitInput(config, element, newOffset, {
@@ -593,9 +588,9 @@ function commitInput(config, element, newOffset, inputInit) {
593
588
  }
594
589
  }
595
590
  function isValidNumberInput(value) {
596
- var _a3, _b;
591
+ var _a, _b;
597
592
  const valueParts = value.split("e", 2);
598
- return !(/[^\d.\-e]/.test(value) || Number((_a3 = value.match(/-/g)) == null ? void 0 : _a3.length) > 2 || Number((_b = value.match(/\./g)) == null ? void 0 : _b.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1]));
593
+ return !(/[^\d.\-e]/.test(value) || Number((_a = value.match(/-/g)) == null ? void 0 : _a.length) > 2 || Number((_b = value.match(/\./g)) == null ? void 0 : _b.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1]));
599
594
  }
600
595
 
601
596
  // src/utils/edit/isEditable.ts
@@ -624,8 +619,8 @@ function isEditableInput(element) {
624
619
  // src/utils/edit/setFiles.ts
625
620
  var fakeFiles = Symbol("files and value properties are mocked");
626
621
  function setFiles(el, files) {
627
- var _a3;
628
- (_a3 = el[fakeFiles]) == null ? void 0 : _a3.restore();
622
+ var _a;
623
+ (_a = el[fakeFiles]) == null ? void 0 : _a.restore();
629
624
  const objectDescriptors = Object.getOwnPropertyDescriptors(el);
630
625
  const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
631
626
  function restore() {
@@ -643,11 +638,11 @@ function setFiles(el, files) {
643
638
  value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
644
639
  get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
645
640
  set(v) {
646
- var _a4;
641
+ var _a2;
647
642
  if (v === "") {
648
643
  restore();
649
644
  } else {
650
- (_a4 = objectDescriptors.value.set) == null ? void 0 : _a4.call(el, v);
645
+ (_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
651
646
  }
652
647
  }
653
648
  }),
@@ -674,7 +669,7 @@ function eventWrapper(cb) {
674
669
 
675
670
  // src/utils/misc/isDisabled.ts
676
671
  function isDisabled(element) {
677
- var _a3;
672
+ var _a;
678
673
  for (let el = element; el; el = el.parentElement) {
679
674
  if (isElementType(el, [
680
675
  "button",
@@ -688,7 +683,7 @@ function isDisabled(element) {
688
683
  return true;
689
684
  }
690
685
  } else if (isElementType(el, "fieldset")) {
691
- if (el.hasAttribute("disabled") && !((_a3 = el.querySelector(":scope > legend")) == null ? void 0 : _a3.contains(element))) {
686
+ if (el.hasAttribute("disabled") && !((_a = el.querySelector(":scope > legend")) == null ? void 0 : _a.contains(element))) {
692
687
  return true;
693
688
  }
694
689
  } else if (el.tagName.includes("-")) {
@@ -701,13 +696,13 @@ function isDisabled(element) {
701
696
  }
702
697
 
703
698
  // src/utils/focus/getActiveElement.ts
704
- function getActiveElement(document2) {
705
- const activeElement = document2.activeElement;
699
+ function getActiveElement(document) {
700
+ const activeElement = document.activeElement;
706
701
  if (activeElement == null ? void 0 : activeElement.shadowRoot) {
707
702
  return getActiveElement(activeElement.shadowRoot);
708
703
  } else {
709
704
  if (isDisabled(activeElement)) {
710
- return document2.ownerDocument ? document2.ownerDocument.body : document2.body;
705
+ return document.ownerDocument ? document.ownerDocument.body : document.body;
711
706
  }
712
707
  return activeElement;
713
708
  }
@@ -821,7 +816,7 @@ function isTextNode(node) {
821
816
  return node.nodeType === 3;
822
817
  }
823
818
  function walkNodes(node, direction, callback) {
824
- var _a3;
819
+ var _a;
825
820
  for (; ; ) {
826
821
  const sibling = node[`${direction}Sibling`];
827
822
  if (sibling) {
@@ -829,7 +824,7 @@ function walkNodes(node, direction, callback) {
829
824
  if (callback(node)) {
830
825
  return node;
831
826
  }
832
- } else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a3 = node.ownerDocument) == null ? void 0 : _a3.body))) {
827
+ } else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a = node.ownerDocument) == null ? void 0 : _a.body))) {
833
828
  node = node.parentNode;
834
829
  } else {
835
830
  break;
@@ -845,7 +840,7 @@ function getDescendant(node, direction) {
845
840
 
846
841
  // src/utils/focus/selection.ts
847
842
  function setSelectionRange(element, anchorOffset, focusOffset) {
848
- var _a3;
843
+ var _a;
849
844
  if (hasOwnSelection(element)) {
850
845
  return setSelection({
851
846
  focusNode: element,
@@ -853,7 +848,7 @@ function setSelectionRange(element, anchorOffset, focusOffset) {
853
848
  focusOffset
854
849
  });
855
850
  }
856
- if (isContentEditable(element) && ((_a3 = element.firstChild) == null ? void 0 : _a3.nodeType) === 3) {
851
+ if (isContentEditable(element) && ((_a = element.firstChild) == null ? void 0 : _a.nodeType) === 3) {
857
852
  return setSelection({
858
853
  focusNode: element.firstChild,
859
854
  anchorOffset,
@@ -887,7 +882,7 @@ function getElement2(node) {
887
882
  return node.nodeType === 1 ? node : node.parentElement;
888
883
  }
889
884
  function updateSelectionOnFocus(element) {
890
- var _a3;
885
+ var _a;
891
886
  const selection = element.ownerDocument.getSelection();
892
887
  if (!(selection == null ? void 0 : selection.focusNode)) {
893
888
  return;
@@ -896,7 +891,7 @@ function updateSelectionOnFocus(element) {
896
891
  const contenteditable = getContentEditable(selection.focusNode);
897
892
  if (contenteditable) {
898
893
  if (!selection.isCollapsed) {
899
- const focusNode = ((_a3 = contenteditable.firstChild) == null ? void 0 : _a3.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
894
+ const focusNode = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
900
895
  selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
901
896
  }
902
897
  } else {
@@ -905,12 +900,12 @@ function updateSelectionOnFocus(element) {
905
900
  }
906
901
  }
907
902
  function getInputRange(focusNode) {
908
- var _a3;
903
+ var _a;
909
904
  const typeAndSelection = getTargetTypeAndSelection(focusNode);
910
905
  if (typeAndSelection.type === "input") {
911
906
  return typeAndSelection.selection;
912
907
  } else if (typeAndSelection.type === "contenteditable") {
913
- return (_a3 = typeAndSelection.selection) == null ? void 0 : _a3.getRangeAt(0);
908
+ return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
914
909
  }
915
910
  }
916
911
  function setSelection({
@@ -919,7 +914,7 @@ function setSelection({
919
914
  anchorNode = focusNode,
920
915
  anchorOffset = focusOffset
921
916
  }) {
922
- var _a3, _b;
917
+ var _a, _b;
923
918
  const typeAndSelection = getTargetTypeAndSelection(focusNode);
924
919
  if (typeAndSelection.type === "input") {
925
920
  return setUISelection(focusNode, {
@@ -927,7 +922,7 @@ function setSelection({
927
922
  focusOffset
928
923
  });
929
924
  }
930
- (_b = (_a3 = anchorNode.ownerDocument) == null ? void 0 : _a3.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
925
+ (_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
931
926
  }
932
927
  function moveSelection(node, direction) {
933
928
  if (hasOwnSelection(node)) {
@@ -938,7 +933,7 @@ function moveSelection(node, direction) {
938
933
  });
939
934
  } else {
940
935
  const selection = node.ownerDocument.getSelection();
941
- if (!selection) {
936
+ if (!(selection == null ? void 0 : selection.focusNode)) {
942
937
  return;
943
938
  }
944
939
  if (selection.isCollapsed) {
@@ -1000,9 +995,9 @@ function focus(element) {
1000
995
 
1001
996
  // src/utils/misc/isVisible.ts
1002
997
  function isVisible(element) {
1003
- const window2 = getWindow(element);
998
+ const window = getWindow(element);
1004
999
  for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
1005
- const { display, visibility } = window2.getComputedStyle(el);
1000
+ const { display, visibility } = window.getComputedStyle(el);
1006
1001
  if (display === "none") {
1007
1002
  return false;
1008
1003
  }
@@ -1015,8 +1010,8 @@ function isVisible(element) {
1015
1010
 
1016
1011
  // src/utils/focus/getTabDestination.ts
1017
1012
  function getTabDestination(activeElement, shift) {
1018
- const document2 = activeElement.ownerDocument;
1019
- const focusableElements = document2.querySelectorAll(FOCUSABLE_SELECTOR);
1013
+ const document = activeElement.ownerDocument;
1014
+ const focusableElements = document.querySelectorAll(FOCUSABLE_SELECTOR);
1020
1015
  const enabledElements = Array.from(focusableElements).filter((el) => el === activeElement || el.getAttribute("tabindex") !== "-1" && !isDisabled(el) && isVisible(el));
1021
1016
  if (activeElement.getAttribute("tabindex") !== "-1") {
1022
1017
  enabledElements.sort((a, b) => {
@@ -1033,7 +1028,7 @@ function getTabDestination(activeElement, shift) {
1033
1028
  });
1034
1029
  }
1035
1030
  const checkedRadio = {};
1036
- let prunedElements = [document2.body];
1031
+ let prunedElements = [document.body];
1037
1032
  const activeRadioGroup = isElementType(activeElement, "input", {
1038
1033
  type: "radio"
1039
1034
  }) ? activeElement.name : void 0;
@@ -1066,7 +1061,7 @@ function getTabDestination(activeElement, shift) {
1066
1061
 
1067
1062
  // src/utils/focus/selectAll.ts
1068
1063
  function selectAll(target) {
1069
- var _a3;
1064
+ var _a;
1070
1065
  if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
1071
1066
  return setSelection({
1072
1067
  focusNode: target,
@@ -1074,7 +1069,7 @@ function selectAll(target) {
1074
1069
  focusOffset: getUIValue(target).length
1075
1070
  });
1076
1071
  }
1077
- const focusNode = (_a3 = getContentEditable(target)) != null ? _a3 : target.ownerDocument.body;
1072
+ const focusNode = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
1078
1073
  setSelection({
1079
1074
  focusNode,
1080
1075
  anchorOffset: 0,
@@ -1082,11 +1077,11 @@ function selectAll(target) {
1082
1077
  });
1083
1078
  }
1084
1079
  function isAllSelected(target) {
1085
- var _a3;
1080
+ var _a;
1086
1081
  if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
1087
1082
  return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
1088
1083
  }
1089
- const focusNode = (_a3 = getContentEditable(target)) != null ? _a3 : target.ownerDocument.body;
1084
+ const focusNode = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
1090
1085
  const selection = target.ownerDocument.getSelection();
1091
1086
  return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
1092
1087
  }
@@ -1146,12 +1141,12 @@ function readPrintableChar(text, pos, context) {
1146
1141
  };
1147
1142
  }
1148
1143
  function readTag(text, pos, startBracket, context) {
1149
- var _a3, _b, _c;
1144
+ var _a, _b, _c;
1150
1145
  const releasePreviousModifier = text[pos] === "/" ? "/" : "";
1151
1146
  pos += releasePreviousModifier.length;
1152
1147
  const escapedDescriptor = startBracket === "{" && text[pos] === "\\";
1153
1148
  pos += Number(escapedDescriptor);
1154
- const descriptor = escapedDescriptor ? text[pos] : (_a3 = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a3[0];
1149
+ const descriptor = escapedDescriptor ? text[pos] : (_a = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a[0];
1155
1150
  assertDescriptor(descriptor, text, pos, context);
1156
1151
  pos += descriptor.length;
1157
1152
  const repeatModifier = (_c = (_b = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _b[0]) != null ? _c : "";
@@ -1223,18 +1218,25 @@ function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
1223
1218
  // src/utils/misc/level.ts
1224
1219
  var Level = Symbol("Api level refs");
1225
1220
  function setLevelRef(config, level) {
1226
- var _a3;
1227
- (_a3 = config[Level]) != null ? _a3 : config[Level] = {};
1221
+ var _a;
1222
+ (_a = config[Level]) != null ? _a : config[Level] = {};
1228
1223
  config[Level][level] = {};
1229
1224
  }
1230
1225
  function getLevelRef(config, level) {
1231
- var _a3;
1232
- return (_a3 = config[Level]) == null ? void 0 : _a3[level];
1226
+ var _a;
1227
+ return (_a = config[Level]) == null ? void 0 : _a[level];
1233
1228
  }
1234
1229
 
1235
1230
  // src/utils/misc/wait.ts
1236
- function wait(time) {
1237
- return new Promise((resolve) => setTimeout(() => resolve(), time));
1231
+ function wait(config) {
1232
+ const delay = config.delay;
1233
+ if (typeof delay !== "number") {
1234
+ return;
1235
+ }
1236
+ return Promise.all([
1237
+ new Promise((resolve) => globalThis.setTimeout(() => resolve(), delay)),
1238
+ config.advanceTimers(delay)
1239
+ ]);
1238
1240
  }
1239
1241
 
1240
1242
  // src/keyboard/keyMap.ts
@@ -1315,14 +1317,15 @@ var defaultOptionsDirect = {
1315
1317
  applyAccept: true,
1316
1318
  autoModify: true,
1317
1319
  delay: 0,
1318
- document: global.document,
1320
+ document: globalThis.document,
1319
1321
  keyboardMap: defaultKeyMap,
1320
1322
  pointerMap: defaultKeyMap2,
1321
1323
  pointerEventsCheck: 2 /* EachApiCall */,
1322
1324
  skipAutoClose: false,
1323
1325
  skipClick: false,
1324
1326
  skipHover: false,
1325
- writeToClipboard: false
1327
+ writeToClipboard: false,
1328
+ advanceTimers: () => Promise.resolve()
1326
1329
  };
1327
1330
  var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect), {
1328
1331
  writeToClipboard: true
@@ -1330,14 +1333,19 @@ var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect)
1330
1333
 
1331
1334
  // src/utils/pointer/cssPointerEvents.ts
1332
1335
  function hasPointerEvents(element) {
1333
- const window2 = getWindow(element);
1334
- for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
1335
- const pointerEvents = window2.getComputedStyle(el).pointerEvents;
1336
+ var _a;
1337
+ return ((_a = closestPointerEventsDeclaration(element)) == null ? void 0 : _a.pointerEvents) !== "none";
1338
+ }
1339
+ function closestPointerEventsDeclaration(element) {
1340
+ const window = getWindow(element);
1341
+ for (let el = element, tree = []; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
1342
+ tree.push(el);
1343
+ const pointerEvents = window.getComputedStyle(el).pointerEvents;
1336
1344
  if (pointerEvents && !["inherit", "unset"].includes(pointerEvents)) {
1337
- return pointerEvents !== "none";
1345
+ return { pointerEvents, tree };
1338
1346
  }
1339
1347
  }
1340
- return true;
1348
+ return void 0;
1341
1349
  }
1342
1350
  var PointerEventsCheck = Symbol("Last check for pointer-events");
1343
1351
  function assertPointerEvents(config, element) {
@@ -1346,15 +1354,59 @@ function assertPointerEvents(config, element) {
1346
1354
  if (!needsCheck) {
1347
1355
  return;
1348
1356
  }
1349
- const result = hasPointerEvents(element);
1357
+ const declaration = closestPointerEventsDeclaration(element);
1350
1358
  element[PointerEventsCheck] = {
1351
1359
  [1 /* Call */]: getLevelRef(config, 1 /* Call */),
1352
1360
  [2 /* Trigger */]: getLevelRef(config, 2 /* Trigger */),
1353
- result
1361
+ result: (declaration == null ? void 0 : declaration.pointerEvents) !== "none"
1354
1362
  };
1355
- if (!result) {
1356
- throw new Error('Unable to perform pointer interaction as the element has or inherits pointer-events set to "none".');
1357
- }
1363
+ if ((declaration == null ? void 0 : declaration.pointerEvents) === "none") {
1364
+ throw new Error([
1365
+ `Unable to perform pointer interaction as the element ${declaration.tree.length > 1 ? "inherits" : "has"} \`pointer-events: none\`:`,
1366
+ "",
1367
+ printTree(declaration.tree)
1368
+ ].join("\n"));
1369
+ }
1370
+ }
1371
+ function printTree(tree) {
1372
+ return tree.reverse().map((el, i) => [
1373
+ "".padEnd(i),
1374
+ el.tagName,
1375
+ el.id && `#${el.id}`,
1376
+ el.hasAttribute("data-testid") && `(testId=${el.getAttribute("data-testid")})`,
1377
+ getLabelDescr(el),
1378
+ tree.length > 1 && i === 0 && " <-- This element declared `pointer-events: none`",
1379
+ tree.length > 1 && i === tree.length - 1 && " <-- Asserted pointer events here"
1380
+ ].filter(Boolean).join("")).join("\n");
1381
+ }
1382
+ function getLabelDescr(element) {
1383
+ var _a, _b, _c, _d;
1384
+ let label;
1385
+ if (element.hasAttribute("aria-label")) {
1386
+ label = element.getAttribute("aria-label");
1387
+ } else if (element.hasAttribute("aria-labelledby")) {
1388
+ label = (_b = (_a = element.ownerDocument.getElementById(element.getAttribute("aria-labelledby"))) == null ? void 0 : _a.textContent) == null ? void 0 : _b.trim();
1389
+ } else if (isElementType(element, [
1390
+ "button",
1391
+ "input",
1392
+ "meter",
1393
+ "output",
1394
+ "progress",
1395
+ "select",
1396
+ "textarea"
1397
+ ]) && ((_c = element.labels) == null ? void 0 : _c.length)) {
1398
+ label = Array.from(element.labels).map((el) => {
1399
+ var _a2;
1400
+ return (_a2 = el.textContent) == null ? void 0 : _a2.trim();
1401
+ }).join("|");
1402
+ } else if (isElementType(element, "button")) {
1403
+ label = (_d = element.textContent) == null ? void 0 : _d.trim();
1404
+ }
1405
+ label = label == null ? void 0 : label.replace(/\n/g, " ");
1406
+ if (Number(label == null ? void 0 : label.length) > 30) {
1407
+ label = `${label == null ? void 0 : label.substring(0, 29)}\u2026`;
1408
+ }
1409
+ return label ? `(label=${label})` : "";
1358
1410
  }
1359
1411
  function hasBitFlag(conf, flag) {
1360
1412
  return (conf & flag) > 0;
@@ -1444,9 +1496,9 @@ function assignPositionInit(obj, {
1444
1496
  screenX,
1445
1497
  screenY
1446
1498
  }) {
1447
- var _a3, _b, _c, _d;
1499
+ var _a, _b, _c, _d;
1448
1500
  assignProps(obj, {
1449
- x: (_a3 = x != null ? x : clientX) != null ? _a3 : 0,
1501
+ x: (_a = x != null ? x : clientX) != null ? _a : 0,
1450
1502
  y: (_b = y != null ? y : clientY) != null ? _b : 0,
1451
1503
  clientX: (_c = x != null ? x : clientX) != null ? _c : 0,
1452
1504
  clientY: (_d = y != null ? y : clientY) != null ? _d : 0,
@@ -1500,8 +1552,8 @@ behavior.cut = (event, target, config) => {
1500
1552
 
1501
1553
  // src/event/behavior/keydown.ts
1502
1554
  behavior.keydown = (event, target, config) => {
1503
- var _a3, _b;
1504
- return (_b = (_a3 = keydownBehavior[event.key]) == null ? void 0 : _a3.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
1555
+ var _a, _b;
1556
+ return (_b = (_a = keydownBehavior[event.key]) == null ? void 0 : _a.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
1505
1557
  };
1506
1558
  var keydownBehavior = {
1507
1559
  ArrowLeft: (event, target) => () => moveSelection(target, -1),
@@ -1523,8 +1575,8 @@ var keydownBehavior = {
1523
1575
  End: (event, target) => {
1524
1576
  if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
1525
1577
  return () => {
1526
- var _a3, _b;
1527
- const newPos = (_b = (_a3 = getValue(target)) == null ? void 0 : _a3.length) != null ? _b : 0;
1578
+ var _a, _b;
1579
+ const newPos = (_b = (_a = getValue(target)) == null ? void 0 : _a.length) != null ? _b : 0;
1528
1580
  setSelectionRange(target, newPos, newPos);
1529
1581
  };
1530
1582
  }
@@ -1616,8 +1668,8 @@ var SubmitSingleInputOnEnter = [
1616
1668
 
1617
1669
  // src/event/behavior/keyup.ts
1618
1670
  behavior.keyup = (event, target, config) => {
1619
- var _a3;
1620
- return (_a3 = keyupBehavior[event.key]) == null ? void 0 : _a3.call(keyupBehavior, event, target, config);
1671
+ var _a;
1672
+ return (_a = keyupBehavior[event.key]) == null ? void 0 : _a.call(keyupBehavior, event, target, config);
1621
1673
  };
1622
1674
  var keyupBehavior = {
1623
1675
  " ": (event, target, config) => {
@@ -1631,8 +1683,8 @@ var keyupBehavior = {
1631
1683
  behavior.paste = (event, target, config) => {
1632
1684
  if (isEditable(target)) {
1633
1685
  return () => {
1634
- var _a3;
1635
- const insertData = (_a3 = event.clipboardData) == null ? void 0 : _a3.getData("text");
1686
+ var _a;
1687
+ const insertData = (_a = event.clipboardData) == null ? void 0 : _a.getData("text");
1636
1688
  if (insertData) {
1637
1689
  input(config, target, insertData, "insertFromPaste");
1638
1690
  }
@@ -1648,10 +1700,10 @@ function wrapEvent(cb, _element) {
1648
1700
 
1649
1701
  // src/event/dispatchEvent.ts
1650
1702
  function dispatchEvent(config, target, event, preventDefault = false) {
1651
- var _a3, _b;
1703
+ var _a, _b;
1652
1704
  const type3 = event.type;
1653
1705
  const behaviorImplementation = preventDefault ? () => {
1654
- } : (_b = (_a3 = behavior)[type3]) == null ? void 0 : _b.call(_a3, event, target, config);
1706
+ } : (_b = (_a = behavior)[type3]) == null ? void 0 : _b.call(_a, event, target, config);
1655
1707
  if (behaviorImplementation) {
1656
1708
  event.preventDefault();
1657
1709
  let defaultPrevented = false;
@@ -1694,13 +1746,18 @@ function prepareInterceptor(element, propName, interceptorImpl) {
1694
1746
  return;
1695
1747
  }
1696
1748
  function intercept(...args) {
1697
- const { applyNative = true, realArgs } = interceptorImpl.call(this, ...args);
1749
+ const {
1750
+ applyNative = true,
1751
+ realArgs,
1752
+ then
1753
+ } = interceptorImpl.call(this, ...args);
1698
1754
  const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
1699
1755
  if (target === "set") {
1700
1756
  realFunc.call(this, realArgs);
1701
1757
  } else {
1702
1758
  realFunc.call(this, ...realArgs);
1703
1759
  }
1760
+ then == null ? void 0 : then();
1704
1761
  }
1705
1762
  ;
1706
1763
  intercept[Interceptor] = Interceptor;
@@ -1762,9 +1819,9 @@ function setUISelection(element, {
1762
1819
  }
1763
1820
  }
1764
1821
  function getUISelection(element) {
1765
- var _a3, _b, _c;
1822
+ var _a, _b, _c;
1766
1823
  const sel = (_c = element[UISelection]) != null ? _c : {
1767
- anchorOffset: (_a3 = element.selectionStart) != null ? _a3 : 0,
1824
+ anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
1768
1825
  focusOffset: (_b = element.selectionEnd) != null ? _b : 0
1769
1826
  };
1770
1827
  return __spreadProps(__spreadValues({}, sel), {
@@ -1782,12 +1839,11 @@ function valueInterceptor(v) {
1782
1839
  if (isUI) {
1783
1840
  this[UIValue] = String(v);
1784
1841
  setPreviousValue(this, String(this.value));
1785
- } else {
1786
- trackOrSetValue(this, String(v));
1787
1842
  }
1788
1843
  return {
1789
1844
  applyNative: !!isUI,
1790
- realArgs: sanitizeValue(this, v)
1845
+ realArgs: sanitizeValue(this, v),
1846
+ then: isUI ? void 0 : () => trackOrSetValue(this, String(v))
1791
1847
  };
1792
1848
  }
1793
1849
  function sanitizeValue(element, v) {
@@ -1800,6 +1856,9 @@ function prepareValueInterceptor(element) {
1800
1856
  prepareInterceptor(element, "value", valueInterceptor);
1801
1857
  }
1802
1858
  function setUIValue(element, value) {
1859
+ if (element[InitialValue] === void 0) {
1860
+ element[InitialValue] = element.value;
1861
+ }
1803
1862
  element.value = {
1804
1863
  [UIValue]: UIValue,
1805
1864
  toString: () => value
@@ -1808,8 +1867,8 @@ function setUIValue(element, value) {
1808
1867
  function getUIValue(element) {
1809
1868
  return element[UIValue] === void 0 ? element.value : String(element[UIValue]);
1810
1869
  }
1811
- function setInitialValue(element) {
1812
- element[InitialValue] = element.value;
1870
+ function clearInitialValue(element) {
1871
+ element[InitialValue] = void 0;
1813
1872
  }
1814
1873
  function getInitialValue(element) {
1815
1874
  return element[InitialValue];
@@ -1824,22 +1883,21 @@ function startTrackValue(element) {
1824
1883
  });
1825
1884
  }
1826
1885
  function trackOrSetValue(element, v) {
1827
- var _a3, _b, _c;
1828
- (_b = (_a3 = element[TrackChanges]) == null ? void 0 : _a3.tracked) == null ? void 0 : _b.push(v);
1886
+ var _a, _b, _c;
1887
+ (_b = (_a = element[TrackChanges]) == null ? void 0 : _a.tracked) == null ? void 0 : _b.push(v);
1829
1888
  if (!((_c = element[TrackChanges]) == null ? void 0 : _c.tracked)) {
1830
1889
  setCleanValue(element, v);
1831
1890
  }
1832
1891
  }
1833
1892
  function setCleanValue(element, v) {
1834
1893
  element[UIValue] = void 0;
1835
- element[InitialValue] = v;
1836
1894
  setUISelection(element, { focusOffset: v.length });
1837
1895
  }
1838
1896
  function endTrackValue(element) {
1839
- var _a3, _b;
1897
+ var _a, _b;
1840
1898
  const changes = element[TrackChanges];
1841
1899
  element[TrackChanges] = void 0;
1842
- const isJustReactStateUpdate = ((_a3 = changes == null ? void 0 : changes.tracked) == null ? void 0 : _a3.length) === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === changes.nextValue;
1900
+ const isJustReactStateUpdate = ((_a = changes == null ? void 0 : changes.tracked) == null ? void 0 : _a.length) === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === changes.nextValue;
1843
1901
  if (((_b = changes == null ? void 0 : changes.tracked) == null ? void 0 : _b.length) && !isJustReactStateUpdate) {
1844
1902
  setCleanValue(element, changes.tracked[changes.tracked.length - 1]);
1845
1903
  }
@@ -1848,36 +1906,36 @@ function endTrackValue(element) {
1848
1906
 
1849
1907
  // src/document/index.ts
1850
1908
  var isPrepared = Symbol("Node prepared with document state workarounds");
1851
- function prepareDocument(document2) {
1852
- if (document2[isPrepared]) {
1909
+ function prepareDocument(document) {
1910
+ if (document[isPrepared]) {
1853
1911
  return;
1854
1912
  }
1855
- document2.addEventListener("focus", (e) => {
1913
+ document.addEventListener("focus", (e) => {
1856
1914
  const el = e.target;
1857
1915
  prepareElement(el);
1858
1916
  }, {
1859
1917
  capture: true,
1860
1918
  passive: true
1861
1919
  });
1862
- if (document2.activeElement) {
1863
- prepareElement(document2.activeElement);
1920
+ if (document.activeElement) {
1921
+ prepareElement(document.activeElement);
1864
1922
  }
1865
- document2.addEventListener("blur", (e) => {
1923
+ document.addEventListener("blur", (e) => {
1866
1924
  const el = e.target;
1867
1925
  const initialValue = getInitialValue(el);
1868
- if (typeof initialValue === "string" && el.value !== initialValue) {
1869
- dispatchUIEvent({}, el, "change");
1926
+ if (initialValue !== void 0) {
1927
+ if (el.value !== initialValue) {
1928
+ dispatchUIEvent({}, el, "change");
1929
+ }
1930
+ clearInitialValue(el);
1870
1931
  }
1871
1932
  }, {
1872
1933
  capture: true,
1873
1934
  passive: true
1874
1935
  });
1875
- document2[isPrepared] = isPrepared;
1936
+ document[isPrepared] = isPrepared;
1876
1937
  }
1877
1938
  function prepareElement(el) {
1878
- if ("value" in el) {
1879
- setInitialValue(el);
1880
- }
1881
1939
  if (el[isPrepared]) {
1882
1940
  return;
1883
1941
  }
@@ -1912,11 +1970,11 @@ function isModifierLock(key) {
1912
1970
  return modifierLocks.includes(key);
1913
1971
  }
1914
1972
  function preKeydownBehavior(config, { key }, element) {
1915
- var _a3;
1973
+ var _a;
1916
1974
  if (isModifierKey(key)) {
1917
1975
  config.keyboardState.modifiers[key] = true;
1918
1976
  if (key === "AltGraph") {
1919
- const ctrlKeyDef = (_a3 = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a3 : { key: "Control", code: "Control" };
1977
+ const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
1920
1978
  dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
1921
1979
  }
1922
1980
  } else if (isModifierLock(key)) {
@@ -1936,9 +1994,9 @@ function preKeyupBehavior(config, { key }) {
1936
1994
  }
1937
1995
  }
1938
1996
  function postKeyupBehavior(config, { key }, element) {
1939
- var _a3;
1997
+ var _a;
1940
1998
  if (key === "AltGraph") {
1941
- const ctrlKeyDef = (_a3 = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a3 : { key: "Control", code: "Control" };
1999
+ const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
1942
2000
  dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
1943
2001
  }
1944
2002
  }
@@ -1948,16 +2006,16 @@ function keyboardAction(config, actions) {
1948
2006
  return __async(this, null, function* () {
1949
2007
  for (let i = 0; i < actions.length; i++) {
1950
2008
  yield keyboardKeyAction(config, actions[i]);
1951
- if (typeof config.delay === "number" && i < actions.length - 1) {
1952
- yield wait(config.delay);
2009
+ if (i < actions.length - 1) {
2010
+ yield wait(config);
1953
2011
  }
1954
2012
  }
1955
2013
  });
1956
2014
  }
1957
2015
  function keyboardKeyAction(_0, _1) {
1958
2016
  return __async(this, arguments, function* (config, { keyDef, releasePrevious, releaseSelf, repeat }) {
1959
- const { document: document2, keyboardState, delay } = config;
1960
- const getCurrentElement = () => getActive(document2);
2017
+ const { document, keyboardState } = config;
2018
+ const getCurrentElement = () => getActive(document);
1961
2019
  const pressed = keyboardState.pressed.find((p) => p.keyDef === keyDef);
1962
2020
  if (pressed) {
1963
2021
  yield keyup(keyDef, getCurrentElement, config, pressed.unpreventedDefault);
@@ -1969,8 +2027,8 @@ function keyboardKeyAction(_0, _1) {
1969
2027
  if (unpreventedDefault && hasKeyPress(keyDef, config)) {
1970
2028
  yield keypress(keyDef, getCurrentElement, config);
1971
2029
  }
1972
- if (typeof delay === "number" && i < repeat) {
1973
- yield wait(delay);
2030
+ if (i < repeat) {
2031
+ yield wait(config);
1974
2032
  }
1975
2033
  }
1976
2034
  if (releaseSelf) {
@@ -1979,9 +2037,9 @@ function keyboardKeyAction(_0, _1) {
1979
2037
  }
1980
2038
  });
1981
2039
  }
1982
- function getActive(document2) {
1983
- var _a3;
1984
- return (_a3 = getActiveElement(document2)) != null ? _a3 : document2.body;
2040
+ function getActive(document) {
2041
+ var _a;
2042
+ return (_a = getActiveElement(document)) != null ? _a : document.body;
1985
2043
  }
1986
2044
  function releaseAllKeys(config) {
1987
2045
  return __async(this, null, function* () {
@@ -2023,13 +2081,13 @@ function keyup(keyDef, getCurrentElement, config, unprevented) {
2023
2081
  });
2024
2082
  }
2025
2083
  function hasKeyPress(keyDef, config) {
2026
- var _a3;
2027
- return (((_a3 = keyDef.key) == null ? void 0 : _a3.length) === 1 || keyDef.key === "Enter") && !config.keyboardState.modifiers.Control && !config.keyboardState.modifiers.Alt;
2084
+ var _a;
2085
+ return (((_a = keyDef.key) == null ? void 0 : _a.length) === 1 || keyDef.key === "Enter") && !config.keyboardState.modifiers.Control && !config.keyboardState.modifiers.Alt;
2028
2086
  }
2029
2087
 
2030
2088
  // src/keyboard/parseKeyDef.ts
2031
2089
  function parseKeyDef(keyboardMap, text) {
2032
- var _a3;
2090
+ var _a;
2033
2091
  const defs = [];
2034
2092
  do {
2035
2093
  const {
@@ -2040,15 +2098,15 @@ function parseKeyDef(keyboardMap, text) {
2040
2098
  releaseSelf = true,
2041
2099
  repeat
2042
2100
  } = readNextDescriptor(text, "keyboard");
2043
- const keyDef = (_a3 = keyboardMap.find((def) => {
2044
- var _a4, _b;
2101
+ const keyDef = (_a = keyboardMap.find((def) => {
2102
+ var _a2, _b;
2045
2103
  if (type3 === "[") {
2046
- return ((_a4 = def.code) == null ? void 0 : _a4.toLowerCase()) === descriptor.toLowerCase();
2104
+ return ((_a2 = def.code) == null ? void 0 : _a2.toLowerCase()) === descriptor.toLowerCase();
2047
2105
  } else if (type3 === "{") {
2048
2106
  return ((_b = def.key) == null ? void 0 : _b.toLowerCase()) === descriptor.toLowerCase();
2049
2107
  }
2050
2108
  return def.key === descriptor;
2051
- })) != null ? _a3 : {
2109
+ })) != null ? _a : {
2052
2110
  key: "Unknown",
2053
2111
  code: "Unknown",
2054
2112
  [type3 === "[" ? "code" : "key"]: descriptor
@@ -2127,8 +2185,8 @@ function firePointerEvent(config, target, type3, {
2127
2185
  }
2128
2186
  init.button = getMouseButton(button != null ? button : 0);
2129
2187
  init.buttons = getMouseButtons(...config.pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
2130
- var _a3;
2131
- return (_a3 = p.keyDef.button) != null ? _a3 : 0;
2188
+ var _a;
2189
+ return (_a = p.keyDef.button) != null ? _a : 0;
2132
2190
  }));
2133
2191
  if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
2134
2192
  init.detail = clickCount;
@@ -2290,7 +2348,7 @@ function getNextPointerId(state) {
2290
2348
  return state.pointerId;
2291
2349
  }
2292
2350
  function down(config, pointerName, { keyDef, node, offset, target, coords }, targetIsDisabled) {
2293
- var _a3, _b, _c;
2351
+ var _a, _b, _c;
2294
2352
  setLevelRef(config, 2 /* Trigger */);
2295
2353
  assertPointerEvents(config, target);
2296
2354
  const { pointerState } = config;
@@ -2313,7 +2371,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
2313
2371
  }
2314
2372
  }
2315
2373
  }
2316
- if (((_a3 = pointerState.activeClickCount) == null ? void 0 : _a3[0]) !== name) {
2374
+ if (((_a = pointerState.activeClickCount) == null ? void 0 : _a[0]) !== name) {
2317
2375
  delete pointerState.activeClickCount;
2318
2376
  }
2319
2377
  const clickCount = Number((_c = (_b = pointerState.activeClickCount) == null ? void 0 : _b[1]) != null ? _c : 0) + 1;
@@ -2497,17 +2555,15 @@ function getTextRange(text, pos, clickCount) {
2497
2555
  // src/pointer/pointerAction.ts
2498
2556
  function pointerAction(config, actions) {
2499
2557
  return __async(this, null, function* () {
2500
- var _a3, _b;
2558
+ var _a, _b;
2501
2559
  for (let i = 0; i < actions.length; i++) {
2502
2560
  const action = actions[i];
2503
2561
  const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? action.keyDef.pointerType === "touch" ? action.keyDef.name : action.keyDef.pointerType : "mouse";
2504
- const target = (_a3 = action.target) != null ? _a3 : getPrevTarget(pointerName, config.pointerState);
2562
+ const target = (_a = action.target) != null ? _a : getPrevTarget(pointerName, config.pointerState);
2505
2563
  const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
2506
2564
  yield "keyDef" in action ? pointerPress(config, __spreadProps(__spreadValues({}, action), { target, coords })) : pointerMove(config, __spreadProps(__spreadValues({}, action), { target, coords }));
2507
- if (typeof config.delay === "number") {
2508
- if (i < actions.length - 1) {
2509
- yield wait(config.delay);
2510
- }
2565
+ if (i < actions.length - 1) {
2566
+ yield wait(config);
2511
2567
  }
2512
2568
  }
2513
2569
  delete config.pointerState.activeClickCount;
@@ -2537,14 +2593,14 @@ function pointer(input2) {
2537
2593
  return pointerAction(this[Config], actions).then(() => void 0);
2538
2594
  });
2539
2595
  }
2540
- function createPointerState(document2) {
2596
+ function createPointerState(document) {
2541
2597
  return {
2542
2598
  pointerId: 1,
2543
2599
  position: {
2544
2600
  mouse: {
2545
2601
  pointerType: "mouse",
2546
2602
  pointerId: 1,
2547
- target: document2.body,
2603
+ target: document.body,
2548
2604
  coords: {
2549
2605
  clientX: 0,
2550
2606
  clientY: 0,
@@ -2631,9 +2687,9 @@ function tab() {
2631
2687
  // src/clipboard/copy.ts
2632
2688
  function copy() {
2633
2689
  return __async(this, null, function* () {
2634
- var _a3;
2690
+ var _a;
2635
2691
  const doc = this[Config].document;
2636
- const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
2692
+ const target = (_a = doc.activeElement) != null ? _a : doc.body;
2637
2693
  const clipboardData = copySelection(target);
2638
2694
  if (clipboardData.items.length === 0) {
2639
2695
  return;
@@ -2650,9 +2706,9 @@ function copy() {
2650
2706
  // src/clipboard/cut.ts
2651
2707
  function cut() {
2652
2708
  return __async(this, null, function* () {
2653
- var _a3;
2709
+ var _a;
2654
2710
  const doc = this[Config].document;
2655
- const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
2711
+ const target = (_a = doc.activeElement) != null ? _a : doc.body;
2656
2712
  const clipboardData = copySelection(target);
2657
2713
  if (clipboardData.items.length === 0) {
2658
2714
  return;
@@ -2669,9 +2725,9 @@ function cut() {
2669
2725
  // src/clipboard/paste.ts
2670
2726
  function paste(clipboardData) {
2671
2727
  return __async(this, null, function* () {
2672
- var _a3, _b;
2728
+ var _a, _b;
2673
2729
  const doc = this[Config].document;
2674
- const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
2730
+ const target = (_a = doc.activeElement) != null ? _a : doc.body;
2675
2731
  const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(doc, clipboardData) : clipboardData) != null ? _b : yield readDataTransferFromClipboard(doc).catch(() => {
2676
2732
  throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
2677
2733
  });
@@ -2769,6 +2825,7 @@ function selectOptionsBase(newValue, select, values) {
2769
2825
  if (withPointerEvents) {
2770
2826
  this.dispatchUIEvent(option, "click");
2771
2827
  }
2828
+ yield wait(this[Config]);
2772
2829
  }
2773
2830
  } else if (selectedOptions.length === 1) {
2774
2831
  const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(select);
@@ -2787,6 +2844,7 @@ function selectOptionsBase(newValue, select, values) {
2787
2844
  this.dispatchUIEvent(select, "mouseup");
2788
2845
  this.dispatchUIEvent(select, "click");
2789
2846
  }
2847
+ yield wait(this[Config]);
2790
2848
  } else {
2791
2849
  throw getConfig3().getElementError(`Cannot select multiple options on a non-multiple select`, select);
2792
2850
  }
@@ -2835,10 +2893,10 @@ function upload(element, fileOrFiles) {
2835
2893
  return;
2836
2894
  const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input2.accept)).slice(0, input2.multiple ? void 0 : 1);
2837
2895
  const fileDialog = () => {
2838
- var _a3;
2839
- if (files.length === ((_a3 = input2.files) == null ? void 0 : _a3.length) && files.every((f, i) => {
2840
- var _a4;
2841
- return f === ((_a4 = input2.files) == null ? void 0 : _a4.item(i));
2896
+ var _a;
2897
+ if (files.length === ((_a = input2.files) == null ? void 0 : _a.length) && files.every((f, i) => {
2898
+ var _a2;
2899
+ return f === ((_a2 = input2.files) == null ? void 0 : _a2.item(i));
2842
2900
  })) {
2843
2901
  return;
2844
2902
  }
@@ -2874,22 +2932,22 @@ function wrapAsync(implementation) {
2874
2932
 
2875
2933
  // src/setup/setup.ts
2876
2934
  function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
2877
- const document2 = getDocument(options, node);
2935
+ const document = getDocument(options, node, defaults);
2878
2936
  const {
2879
2937
  keyboardState = createKeyboardState(),
2880
- pointerState = createPointerState(document2)
2938
+ pointerState = createPointerState(document)
2881
2939
  } = options;
2882
2940
  return __spreadProps(__spreadValues(__spreadValues({}, defaults), options), {
2883
- document: document2,
2941
+ document,
2884
2942
  keyboardState,
2885
2943
  pointerState
2886
2944
  });
2887
2945
  }
2888
2946
  function setupMain(options = {}) {
2889
- var _a3;
2947
+ var _a;
2890
2948
  const config = createConfig(options);
2891
2949
  prepareDocument(config.document);
2892
- const view = (_a3 = config.document.defaultView) != null ? _a3 : window;
2950
+ const view = (_a = config.document.defaultView) != null ? _a : globalThis.window;
2893
2951
  attachClipboardStubToView(view);
2894
2952
  return doSetup(config);
2895
2953
  }
@@ -2907,7 +2965,10 @@ function setupSub(options) {
2907
2965
  function wrapAndBindImpl(instance, impl) {
2908
2966
  function method(...args) {
2909
2967
  setLevelRef(instance[Config], 1 /* Call */);
2910
- return wrapAsync(() => impl.apply(instance, args));
2968
+ return wrapAsync(() => impl.apply(instance, args).then((ret) => __async(this, null, function* () {
2969
+ yield wait(instance[Config]);
2970
+ return ret;
2971
+ })));
2911
2972
  }
2912
2973
  Object.defineProperty(method, "name", { get: () => impl.name });
2913
2974
  return method;
@@ -2924,9 +2985,9 @@ function doSetup(config) {
2924
2985
  setup: setupSub.bind(instance)
2925
2986
  });
2926
2987
  }
2927
- function getDocument(options, node) {
2928
- var _a3, _b;
2929
- return (_b = (_a3 = options.document) != null ? _a3 : node && getDocumentFromNode(node)) != null ? _b : document;
2988
+ function getDocument(options, node, defaults) {
2989
+ var _a, _b;
2990
+ return (_b = (_a = options.document) != null ? _a : node && getDocumentFromNode(node)) != null ? _b : defaults.document;
2930
2991
  }
2931
2992
 
2932
2993
  // src/setup/directApi.ts